blob: cfc7e5f383ed8dbad2e685e958073c7f99c6f8ab [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
[email protected]995708c52013-10-17 20:52:597#include <set>
8
[email protected]95e4e1a02013-03-18 07:09:099#include "cc/animation/layer_animation_controller.h"
[email protected]1c3626e2014-04-09 17:49:2210#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5211#include "cc/base/math_util.h"
[email protected]cc3cfaa2013-03-18 09:05:5212#include "cc/layers/content_layer.h"
13#include "cc/layers/content_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5214#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5915#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5216#include "cc/layers/layer_impl.h"
[email protected]390bb1ff2014-05-09 17:14:4017#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2818#include "cc/layers/render_surface.h"
19#include "cc/layers/render_surface_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4520#include "cc/output/copy_output_request.h"
21#include "cc/output/copy_output_result.h"
[email protected]101441ce2012-10-16 01:45:0322#include "cc/test/animation_test_common.h"
[email protected]586d51ed2012-12-07 20:31:4523#include "cc/test/fake_impl_proxy.h"
[email protected]d600df7d2013-08-03 02:34:2824#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4525#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]101441ce2012-10-16 01:45:0326#include "cc/test/geometry_test_utils.h"
[email protected]28336d52014-05-12 19:07:2827#include "cc/test/layer_tree_host_common_test.h"
[email protected]556fd292013-03-18 08:03:0428#include "cc/trees/layer_tree_impl.h"
29#include "cc/trees/proxy.h"
30#include "cc/trees/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:1831#include "testing/gmock/include/gmock/gmock.h"
32#include "testing/gtest/include/gtest/gtest.h"
[email protected]93698c12012-12-07 00:43:5633#include "ui/gfx/quad_f.h"
[email protected]c8686a02012-11-27 08:29:0034#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1435
[email protected]ba565742012-11-10 09:29:4836namespace cc {
[email protected]94f206c12012-08-25 00:09:1437namespace {
38
[email protected]96baf3e2012-10-22 23:09:5539class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:3240 public:
[email protected]d5754282014-04-09 00:43:2941 LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {}
[email protected]94f206c12012-08-25 00:09:1442
[email protected]fb661802013-03-25 01:59:3243 virtual bool DrawsContent() const OVERRIDE;
[email protected]d5754282014-04-09 00:43:2944 virtual void CalculateContentsScale(float ideal_contents_scale,
45 float device_scale_factor,
46 float page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:2247 float maximum_animation_contents_scale,
[email protected]d5754282014-04-09 00:43:2948 bool animating_transform_to_screen,
49 float* contents_scale_x,
50 float* contents_scale_y,
51 gfx::Size* content_bounds) OVERRIDE;
52
53 float last_device_scale_factor() const { return last_device_scale_factor_; }
[email protected]d58499a2012-10-09 22:27:4754
[email protected]fb661802013-03-25 01:59:3255 private:
56 virtual ~LayerWithForcedDrawsContent() {}
[email protected]d5754282014-04-09 00:43:2957
58 // Parameters from last CalculateContentsScale.
59 float last_device_scale_factor_;
[email protected]94f206c12012-08-25 00:09:1460};
61
[email protected]fb661802013-03-25 01:59:3262bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:4463
[email protected]d5754282014-04-09 00:43:2964void LayerWithForcedDrawsContent::CalculateContentsScale(
65 float ideal_contents_scale,
66 float device_scale_factor,
67 float page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:2268 float maximum_animation_contents_scale,
[email protected]d5754282014-04-09 00:43:2969 bool animating_transform_to_screen,
70 float* contents_scale_x,
71 float* contents_scale_y,
72 gfx::Size* content_bounds) {
73 last_device_scale_factor_ = device_scale_factor;
74 Layer::CalculateContentsScale(ideal_contents_scale,
75 device_scale_factor,
76 page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:2277 maximum_animation_contents_scale,
[email protected]d5754282014-04-09 00:43:2978 animating_transform_to_screen,
79 contents_scale_x,
80 contents_scale_y,
81 content_bounds);
82}
83
[email protected]96baf3e2012-10-22 23:09:5584class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:3285 public:
86 MockContentLayerClient() {}
87 virtual ~MockContentLayerClient() {}
[email protected]276172b2014-05-02 21:03:0388 virtual void PaintContents(
89 SkCanvas* canvas,
90 const gfx::Rect& clip,
91 gfx::RectF* opaque,
92 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {}
[email protected]fb661802013-03-25 01:59:3293 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
[email protected]1d96e032014-03-25 05:59:0894 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
[email protected]f34a24232012-09-20 22:59:5595};
96
[email protected]fb661802013-03-25 01:59:3297scoped_refptr<ContentLayer> CreateDrawableContentLayer(
98 ContentLayerClient* delegate) {
99 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate);
100 to_return->SetIsDrawable(true);
101 return to_return;
[email protected]f34a24232012-09-20 22:59:55102}
103
[email protected]989386c2013-07-18 21:37:23104#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
105 do { \
106 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
107 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:47108 } while (false)
109
[email protected]989386c2013-07-18 21:37:23110TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32111 // Sanity check: For layers positioned at zero, with zero size,
112 // and with identity transforms, then the draw transform,
113 // screen space transform, and the hierarchy passed on to children
114 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14115
[email protected]fb661802013-03-25 01:59:32116 scoped_refptr<Layer> parent = Layer::Create();
117 scoped_refptr<Layer> child = Layer::Create();
118 scoped_refptr<Layer> grand_child = Layer::Create();
119 parent->AddChild(child);
120 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14121
[email protected]d600df7d2013-08-03 02:34:28122 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
123 host->SetRootLayer(parent);
124
[email protected]fb661802013-03-25 01:59:32125 gfx::Transform identity_matrix;
126 SetLayerPropertiesForTesting(parent.get(),
127 identity_matrix,
[email protected]a2566412014-06-05 03:14:20128 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32129 gfx::PointF(),
130 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:57131 true,
[email protected]fb661802013-03-25 01:59:32132 false);
133 SetLayerPropertiesForTesting(child.get(),
134 identity_matrix,
[email protected]a2566412014-06-05 03:14:20135 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32136 gfx::PointF(),
137 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57138 true,
[email protected]fb661802013-03-25 01:59:32139 false);
140 SetLayerPropertiesForTesting(grand_child.get(),
141 identity_matrix,
[email protected]a2566412014-06-05 03:14:20142 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32143 gfx::PointF(),
144 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57145 true,
[email protected]fb661802013-03-25 01:59:32146 false);
[email protected]94f206c12012-08-25 00:09:14147
[email protected]fb661802013-03-25 01:59:32148 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14149
[email protected]fb661802013-03-25 01:59:32150 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
151 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
152 child->screen_space_transform());
153 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
154 grand_child->draw_transform());
155 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
156 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14157}
158
[email protected]f9e56702014-06-13 01:19:59159TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) {
160 scoped_refptr<Layer> parent = Layer::Create();
161 scoped_refptr<Layer> child = Layer::Create();
162 scoped_refptr<Layer> grand_child = Layer::Create();
163 parent->AddChild(child);
164 child->AddChild(grand_child);
165
166 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
167 host->SetRootLayer(parent);
168
169 gfx::Transform identity_matrix;
170 SetLayerPropertiesForTesting(parent.get(),
171 identity_matrix,
172 gfx::Point3F(),
173 gfx::PointF(),
174 gfx::Size(100, 100),
175 true,
176 false);
177 SetLayerPropertiesForTesting(child.get(),
178 identity_matrix,
179 gfx::Point3F(),
180 gfx::PointF(10, 10),
181 gfx::Size(100, 100),
182 true,
183 false);
184 // This would have previously caused us to skip our subtree, but this would be
185 // wrong; we need up-to-date draw properties to do hit testing on the layers
186 // with handlers.
187 child->SetOpacity(0.f);
188 SetLayerPropertiesForTesting(grand_child.get(),
189 identity_matrix,
190 gfx::Point3F(),
191 gfx::PointF(10, 10),
192 gfx::Size(100, 100),
193 true,
194 false);
195 grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
196
197 ExecuteCalculateDrawProperties(parent.get());
198
199 // Check that we've computed draw properties for the subtree rooted at
200 // |child|.
201 EXPECT_FALSE(child->draw_transform().IsIdentity());
202 EXPECT_FALSE(grand_child->draw_transform().IsIdentity());
203}
204
[email protected]989386c2013-07-18 21:37:23205TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32206 gfx::Transform identity_matrix;
207 scoped_refptr<Layer> layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:14208
[email protected]fb661802013-03-25 01:59:32209 scoped_refptr<Layer> root = Layer::Create();
210 SetLayerPropertiesForTesting(root.get(),
211 identity_matrix,
[email protected]a2566412014-06-05 03:14:20212 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32213 gfx::PointF(),
214 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57215 true,
[email protected]fb661802013-03-25 01:59:32216 false);
217 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42218
[email protected]d600df7d2013-08-03 02:34:28219 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
220 host->SetRootLayer(root);
221
[email protected]fb661802013-03-25 01:59:32222 // Case 2: Setting the bounds of the layer should not affect either the draw
223 // transform or the screenspace transform.
224 gfx::Transform translation_to_center;
225 translation_to_center.Translate(5.0, 6.0);
226 SetLayerPropertiesForTesting(layer.get(),
227 identity_matrix,
[email protected]a2566412014-06-05 03:14:20228 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32229 gfx::PointF(),
230 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57231 true,
[email protected]fb661802013-03-25 01:59:32232 false);
233 ExecuteCalculateDrawProperties(root.get());
234 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
235 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
236 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14237
[email protected]fb661802013-03-25 01:59:32238 // Case 3: The anchor point by itself (without a layer transform) should have
239 // no effect on the transforms.
240 SetLayerPropertiesForTesting(layer.get(),
241 identity_matrix,
[email protected]a2566412014-06-05 03:14:20242 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32243 gfx::PointF(),
244 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57245 true,
[email protected]fb661802013-03-25 01:59:32246 false);
247 ExecuteCalculateDrawProperties(root.get());
248 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
249 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
250 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14251
[email protected]fb661802013-03-25 01:59:32252 // Case 4: A change in actual position affects both the draw transform and
253 // screen space transform.
254 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05255 position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32256 SetLayerPropertiesForTesting(layer.get(),
257 identity_matrix,
[email protected]a2566412014-06-05 03:14:20258 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32259 gfx::PointF(0.f, 1.2f),
260 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57261 true,
[email protected]fb661802013-03-25 01:59:32262 false);
263 ExecuteCalculateDrawProperties(root.get());
264 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
265 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
266 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14267
[email protected]fb661802013-03-25 01:59:32268 // Case 5: In the correct sequence of transforms, the layer transform should
269 // pre-multiply the translation_to_center. This is easily tested by using a
270 // scale transform, because scale and translation are not commutative.
271 gfx::Transform layer_transform;
272 layer_transform.Scale3d(2.0, 2.0, 1.0);
273 SetLayerPropertiesForTesting(layer.get(),
274 layer_transform,
[email protected]a2566412014-06-05 03:14:20275 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32276 gfx::PointF(),
277 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57278 true,
[email protected]fb661802013-03-25 01:59:32279 false);
280 ExecuteCalculateDrawProperties(root.get());
281 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
282 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
283 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14284
[email protected]fb661802013-03-25 01:59:32285 // Case 6: The layer transform should occur with respect to the anchor point.
286 gfx::Transform translation_to_anchor;
287 translation_to_anchor.Translate(5.0, 0.0);
288 gfx::Transform expected_result =
289 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
290 SetLayerPropertiesForTesting(layer.get(),
291 layer_transform,
[email protected]a2566412014-06-05 03:14:20292 gfx::Point3F(5.0f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32293 gfx::PointF(),
294 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57295 true,
[email protected]fb661802013-03-25 01:59:32296 false);
297 ExecuteCalculateDrawProperties(root.get());
298 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
299 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
300 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14301
[email protected]fb661802013-03-25 01:59:32302 // Case 7: Verify that position pre-multiplies the layer transform. The
303 // current implementation of CalculateDrawProperties does this implicitly, but
304 // it is still worth testing to detect accidental regressions.
305 expected_result = position_transform * translation_to_anchor *
306 layer_transform * Inverse(translation_to_anchor);
307 SetLayerPropertiesForTesting(layer.get(),
308 layer_transform,
[email protected]a2566412014-06-05 03:14:20309 gfx::Point3F(5.0f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32310 gfx::PointF(0.f, 1.2f),
311 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57312 true,
[email protected]fb661802013-03-25 01:59:32313 false);
314 ExecuteCalculateDrawProperties(root.get());
315 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
316 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
317 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14318}
319
[email protected]989386c2013-07-18 21:37:23320TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
[email protected]fb661802013-03-25 01:59:32321 const gfx::Vector2d kScrollOffset(50, 100);
322 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01323 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32324 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
325 -kScrollOffset.y());
326 const float kPageScale = 0.888f;
327 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20328
[email protected]fb661802013-03-25 01:59:32329 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:45330 TestSharedBitmapManager shared_bitmap_manager;
331 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]657b24c2013-03-06 09:01:20332
[email protected]fb661802013-03-25 01:59:32333 gfx::Transform identity_matrix;
334 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
335 LayerImpl::Create(host_impl.active_tree(), 1));
336 LayerImpl* sublayer = sublayer_scoped_ptr.get();
337 sublayer->SetContentsScale(kPageScale * kDeviceScale,
338 kPageScale * kDeviceScale);
339 SetLayerPropertiesForTesting(sublayer,
340 identity_matrix,
[email protected]a2566412014-06-05 03:14:20341 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32342 gfx::PointF(),
343 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:57344 true,
[email protected]fb661802013-03-25 01:59:32345 false);
[email protected]657b24c2013-03-06 09:01:20346
[email protected]adeda572014-01-31 00:49:47347 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32348 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47349 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
[email protected]fb661802013-03-25 01:59:32350 SetLayerPropertiesForTesting(scroll_layer,
351 identity_matrix,
[email protected]a2566412014-06-05 03:14:20352 gfx::Point3F(),
[email protected]4ec78f82013-07-11 18:45:47353 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32354 gfx::Size(10, 20),
[email protected]56fffdd2014-02-11 19:50:57355 true,
[email protected]fb661802013-03-25 01:59:32356 false);
[email protected]adeda572014-01-31 00:49:47357 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
358 LayerImpl::Create(host_impl.active_tree(), 4));
359 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
360
361 scroll_layer->SetScrollClipLayer(clip_layer->id());
362 clip_layer->SetBounds(
363 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
364 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
365 scroll_layer->SetScrollClipLayer(clip_layer->id());
[email protected]fb661802013-03-25 01:59:32366 scroll_layer->SetScrollDelta(kScrollDelta);
367 gfx::Transform impl_transform;
[email protected]fb661802013-03-25 01:59:32368 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
[email protected]adeda572014-01-31 00:49:47369 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
370 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
371 scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20372
[email protected]fb661802013-03-25 01:59:32373 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
374 SetLayerPropertiesForTesting(root.get(),
375 identity_matrix,
[email protected]a2566412014-06-05 03:14:20376 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32377 gfx::PointF(),
378 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:57379 true,
[email protected]fb661802013-03-25 01:59:32380 false);
[email protected]adeda572014-01-31 00:49:47381 root->AddChild(clip_layer_scoped_ptr.Pass());
[email protected]657b24c2013-03-06 09:01:20382
[email protected]f2136262013-04-26 21:10:19383 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32384 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32385 gfx::Transform expected_transform = identity_matrix;
386 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
387 sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
388 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
389 MathUtil::Round(sub_layer_screen_position.y()));
390 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
391 sublayer->draw_transform());
392 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
393 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20394
[email protected]fb661802013-03-25 01:59:32395 gfx::Transform arbitrary_translate;
396 const float kTranslateX = 10.6f;
397 const float kTranslateY = 20.6f;
398 arbitrary_translate.Translate(kTranslateX, kTranslateY);
399 SetLayerPropertiesForTesting(scroll_layer,
400 arbitrary_translate,
[email protected]a2566412014-06-05 03:14:20401 gfx::Point3F(),
[email protected]4ec78f82013-07-11 18:45:47402 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32403 gfx::Size(10, 20),
[email protected]56fffdd2014-02-11 19:50:57404 true,
[email protected]fb661802013-03-25 01:59:32405 false);
[email protected]f2136262013-04-26 21:10:19406 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32407 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32408 expected_transform.MakeIdentity();
409 expected_transform.Translate(
410 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
411 sub_layer_screen_position.x()),
412 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
413 sub_layer_screen_position.y()));
414 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
415 sublayer->draw_transform());
[email protected]657b24c2013-03-06 09:01:20416}
417
[email protected]989386c2013-07-18 21:37:23418TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32419 gfx::Transform identity_matrix;
420 scoped_refptr<Layer> root = Layer::Create();
421 scoped_refptr<Layer> parent = Layer::Create();
422 scoped_refptr<Layer> child = Layer::Create();
423 scoped_refptr<Layer> grand_child = Layer::Create();
424 root->AddChild(parent);
425 parent->AddChild(child);
426 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14427
[email protected]d600df7d2013-08-03 02:34:28428 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
429 host->SetRootLayer(root);
430
[email protected]fb661802013-03-25 01:59:32431 // One-time setup of root layer
432 SetLayerPropertiesForTesting(root.get(),
433 identity_matrix,
[email protected]a2566412014-06-05 03:14:20434 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32435 gfx::PointF(),
436 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57437 true,
[email protected]fb661802013-03-25 01:59:32438 false);
[email protected]ecc12622012-10-30 20:45:42439
[email protected]fb661802013-03-25 01:59:32440 // Case 1: parent's anchor point should not affect child or grand_child.
441 SetLayerPropertiesForTesting(parent.get(),
442 identity_matrix,
[email protected]a2566412014-06-05 03:14:20443 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32444 gfx::PointF(),
445 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57446 true,
[email protected]fb661802013-03-25 01:59:32447 false);
448 SetLayerPropertiesForTesting(child.get(),
449 identity_matrix,
[email protected]a2566412014-06-05 03:14:20450 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32451 gfx::PointF(),
452 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57453 true,
[email protected]fb661802013-03-25 01:59:32454 false);
455 SetLayerPropertiesForTesting(grand_child.get(),
456 identity_matrix,
[email protected]a2566412014-06-05 03:14:20457 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32458 gfx::PointF(),
459 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57460 true,
[email protected]fb661802013-03-25 01:59:32461 false);
462 ExecuteCalculateDrawProperties(root.get());
463 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
464 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
465 child->screen_space_transform());
466 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
467 grand_child->draw_transform());
468 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
469 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14470
[email protected]fb661802013-03-25 01:59:32471 // Case 2: parent's position affects child and grand_child.
472 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05473 parent_position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32474 SetLayerPropertiesForTesting(parent.get(),
475 identity_matrix,
[email protected]a2566412014-06-05 03:14:20476 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32477 gfx::PointF(0.f, 1.2f),
478 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57479 true,
[email protected]fb661802013-03-25 01:59:32480 false);
481 SetLayerPropertiesForTesting(child.get(),
482 identity_matrix,
[email protected]a2566412014-06-05 03:14:20483 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32484 gfx::PointF(),
485 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57486 true,
[email protected]fb661802013-03-25 01:59:32487 false);
488 SetLayerPropertiesForTesting(grand_child.get(),
489 identity_matrix,
[email protected]a2566412014-06-05 03:14:20490 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32491 gfx::PointF(),
492 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57493 true,
[email protected]fb661802013-03-25 01:59:32494 false);
495 ExecuteCalculateDrawProperties(root.get());
496 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
497 child->draw_transform());
498 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
499 child->screen_space_transform());
500 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
501 grand_child->draw_transform());
502 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
503 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14504
[email protected]fb661802013-03-25 01:59:32505 // Case 3: parent's local transform affects child and grandchild
506 gfx::Transform parent_layer_transform;
507 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
508 gfx::Transform parent_translation_to_anchor;
509 parent_translation_to_anchor.Translate(2.5, 3.0);
510 gfx::Transform parent_composite_transform =
511 parent_translation_to_anchor * parent_layer_transform *
512 Inverse(parent_translation_to_anchor);
513 SetLayerPropertiesForTesting(parent.get(),
514 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20515 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32516 gfx::PointF(),
517 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57518 true,
[email protected]fb661802013-03-25 01:59:32519 false);
520 SetLayerPropertiesForTesting(child.get(),
521 identity_matrix,
[email protected]a2566412014-06-05 03:14:20522 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32523 gfx::PointF(),
524 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57525 true,
[email protected]fb661802013-03-25 01:59:32526 false);
527 SetLayerPropertiesForTesting(grand_child.get(),
528 identity_matrix,
[email protected]a2566412014-06-05 03:14:20529 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32530 gfx::PointF(),
531 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57532 true,
[email protected]fb661802013-03-25 01:59:32533 false);
534 ExecuteCalculateDrawProperties(root.get());
535 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
536 child->draw_transform());
537 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
538 child->screen_space_transform());
539 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
540 grand_child->draw_transform());
541 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
542 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14543}
544
[email protected]989386c2013-07-18 21:37:23545TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
[email protected]fb661802013-03-25 01:59:32546 scoped_refptr<Layer> root = Layer::Create();
547 scoped_refptr<Layer> parent = Layer::Create();
548 scoped_refptr<Layer> child = Layer::Create();
549 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
550 make_scoped_refptr(new LayerWithForcedDrawsContent());
551 root->AddChild(parent);
552 parent->AddChild(child);
553 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14554
[email protected]d600df7d2013-08-03 02:34:28555 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
556 host->SetRootLayer(root);
557
[email protected]fb661802013-03-25 01:59:32558 // One-time setup of root layer
559 gfx::Transform identity_matrix;
560 SetLayerPropertiesForTesting(root.get(),
561 identity_matrix,
[email protected]a2566412014-06-05 03:14:20562 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32563 gfx::PointF(),
564 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57565 true,
[email protected]fb661802013-03-25 01:59:32566 false);
[email protected]ecc12622012-10-30 20:45:42567
[email protected]fb661802013-03-25 01:59:32568 // Child is set up so that a new render surface should be created.
569 child->SetOpacity(0.5f);
570 child->SetForceRenderSurface(true);
[email protected]94f206c12012-08-25 00:09:14571
[email protected]fb661802013-03-25 01:59:32572 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05573 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32574 gfx::Transform parent_translation_to_anchor;
575 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44576
[email protected]fb661802013-03-25 01:59:32577 gfx::Transform parent_composite_transform =
578 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39579 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32580 gfx::Vector2dF parent_composite_scale =
581 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
582 1.f);
583 gfx::Transform surface_sublayer_transform;
584 surface_sublayer_transform.Scale(parent_composite_scale.x(),
585 parent_composite_scale.y());
586 gfx::Transform surface_sublayer_composite_transform =
587 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14588
[email protected]fb661802013-03-25 01:59:32589 // Child's render surface should not exist yet.
590 ASSERT_FALSE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:14591
[email protected]fb661802013-03-25 01:59:32592 SetLayerPropertiesForTesting(parent.get(),
593 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20594 gfx::Point3F(25.0f, 30.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32595 gfx::PointF(),
596 gfx::Size(100, 120),
[email protected]56fffdd2014-02-11 19:50:57597 true,
[email protected]fb661802013-03-25 01:59:32598 false);
599 SetLayerPropertiesForTesting(child.get(),
600 identity_matrix,
[email protected]a2566412014-06-05 03:14:20601 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32602 gfx::PointF(),
603 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57604 true,
[email protected]fb661802013-03-25 01:59:32605 false);
606 SetLayerPropertiesForTesting(grand_child.get(),
607 identity_matrix,
[email protected]a2566412014-06-05 03:14:20608 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32609 gfx::PointF(),
610 gfx::Size(8, 10),
[email protected]56fffdd2014-02-11 19:50:57611 true,
[email protected]fb661802013-03-25 01:59:32612 false);
613 ExecuteCalculateDrawProperties(root.get());
[email protected]94f206c12012-08-25 00:09:14614
[email protected]fb661802013-03-25 01:59:32615 // Render surface should have been created now.
616 ASSERT_TRUE(child->render_surface());
617 ASSERT_EQ(child, child->render_target());
[email protected]94f206c12012-08-25 00:09:14618
[email protected]fb661802013-03-25 01:59:32619 // The child layer's draw transform should refer to its new render surface.
620 // The screen-space transform, however, should still refer to the root.
621 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
622 child->draw_transform());
623 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
624 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14625
[email protected]fb661802013-03-25 01:59:32626 // Because the grand_child is the only drawable content, the child's render
627 // surface will tighten its bounds to the grand_child. The scale at which the
628 // surface's subtree is drawn must be removed from the composite transform.
629 EXPECT_TRANSFORMATION_MATRIX_EQ(
630 surface_sublayer_composite_transform,
631 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14632
[email protected]fb661802013-03-25 01:59:32633 // The screen space is the same as the target since the child surface draws
634 // into the root.
635 EXPECT_TRANSFORMATION_MATRIX_EQ(
636 surface_sublayer_composite_transform,
637 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14638}
639
[email protected]989386c2013-07-18 21:37:23640TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
[email protected]fb661802013-03-25 01:59:32641 scoped_refptr<Layer> root = Layer::Create();
642 scoped_refptr<Layer> parent = Layer::Create();
643 scoped_refptr<Layer> child = Layer::Create();
644 scoped_refptr<Layer> child_replica = Layer::Create();
645 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
646 make_scoped_refptr(new LayerWithForcedDrawsContent());
647 root->AddChild(parent);
648 parent->AddChild(child);
649 child->AddChild(grand_child);
650 child->SetReplicaLayer(child_replica.get());
651
[email protected]d600df7d2013-08-03 02:34:28652 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
653 host->SetRootLayer(root);
654
[email protected]fb661802013-03-25 01:59:32655 // One-time setup of root layer
656 gfx::Transform identity_matrix;
657 SetLayerPropertiesForTesting(root.get(),
658 identity_matrix,
[email protected]a2566412014-06-05 03:14:20659 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32660 gfx::PointF(),
661 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57662 true,
[email protected]fb661802013-03-25 01:59:32663 false);
664
665 // Child is set up so that a new render surface should be created.
666 child->SetOpacity(0.5f);
667
668 gfx::Transform parent_layer_transform;
669 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
670 gfx::Transform parent_translation_to_anchor;
671 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32672 gfx::Transform parent_composite_transform =
673 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39674 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32675 gfx::Transform replica_layer_transform;
676 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
677 gfx::Vector2dF parent_composite_scale =
678 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
679 1.f);
680 gfx::Transform surface_sublayer_transform;
681 surface_sublayer_transform.Scale(parent_composite_scale.x(),
682 parent_composite_scale.y());
683 gfx::Transform replica_composite_transform =
684 parent_composite_transform * replica_layer_transform *
685 Inverse(surface_sublayer_transform);
686
687 // Child's render surface should not exist yet.
688 ASSERT_FALSE(child->render_surface());
689
690 SetLayerPropertiesForTesting(parent.get(),
691 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20692 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32693 gfx::PointF(),
694 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57695 true,
[email protected]fb661802013-03-25 01:59:32696 false);
697 SetLayerPropertiesForTesting(child.get(),
698 identity_matrix,
[email protected]a2566412014-06-05 03:14:20699 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32700 gfx::PointF(),
701 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57702 true,
[email protected]fb661802013-03-25 01:59:32703 false);
704 SetLayerPropertiesForTesting(grand_child.get(),
705 identity_matrix,
[email protected]a2566412014-06-05 03:14:20706 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32707 gfx::PointF(-0.5f, -0.5f),
708 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:57709 true,
[email protected]fb661802013-03-25 01:59:32710 false);
711 SetLayerPropertiesForTesting(child_replica.get(),
712 replica_layer_transform,
[email protected]a2566412014-06-05 03:14:20713 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32714 gfx::PointF(),
715 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57716 true,
[email protected]fb661802013-03-25 01:59:32717 false);
718 ExecuteCalculateDrawProperties(root.get());
719
720 // Render surface should have been created now.
721 ASSERT_TRUE(child->render_surface());
722 ASSERT_EQ(child, child->render_target());
723
724 EXPECT_TRANSFORMATION_MATRIX_EQ(
725 replica_composite_transform,
726 child->render_target()->render_surface()->replica_draw_transform());
727 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57728 child->render_target()
729 ->render_surface()
[email protected]fb661802013-03-25 01:59:32730 ->replica_screen_space_transform());
731}
732
[email protected]989386c2013-07-18 21:37:23733TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32734 // This test creates a more complex tree and verifies it all at once. This
735 // covers the following cases:
736 // - layers that are described w.r.t. a render surface: should have draw
737 // transforms described w.r.t. that surface
738 // - A render surface described w.r.t. an ancestor render surface: should
739 // have a draw transform described w.r.t. that ancestor surface
740 // - Replicas of a render surface are described w.r.t. the replica's
741 // transform around its anchor, along with the surface itself.
742 // - Sanity check on recursion: verify transforms of layers described w.r.t.
743 // a render surface that is described w.r.t. an ancestor render surface.
744 // - verifying that each layer has a reference to the correct render surface
745 // and render target values.
746
747 scoped_refptr<Layer> root = Layer::Create();
748 scoped_refptr<Layer> parent = Layer::Create();
749 scoped_refptr<Layer> render_surface1 = Layer::Create();
750 scoped_refptr<Layer> render_surface2 = Layer::Create();
751 scoped_refptr<Layer> child_of_root = Layer::Create();
752 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
753 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
754 scoped_refptr<Layer> replica_of_rs1 = Layer::Create();
755 scoped_refptr<Layer> replica_of_rs2 = Layer::Create();
756 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
757 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
758 make_scoped_refptr(new LayerWithForcedDrawsContent());
759 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
760 make_scoped_refptr(new LayerWithForcedDrawsContent());
761 root->AddChild(parent);
762 parent->AddChild(render_surface1);
763 parent->AddChild(child_of_root);
764 render_surface1->AddChild(child_of_rs1);
765 render_surface1->AddChild(render_surface2);
766 render_surface2->AddChild(child_of_rs2);
767 child_of_root->AddChild(grand_child_of_root);
768 child_of_rs1->AddChild(grand_child_of_rs1);
769 child_of_rs2->AddChild(grand_child_of_rs2);
770 render_surface1->SetReplicaLayer(replica_of_rs1.get());
771 render_surface2->SetReplicaLayer(replica_of_rs2.get());
772
[email protected]d600df7d2013-08-03 02:34:28773 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
774 host->SetRootLayer(root);
775
[email protected]fb661802013-03-25 01:59:32776 // In combination with descendant draws content, opacity != 1 forces the layer
777 // to have a new render surface.
778 render_surface1->SetOpacity(0.5f);
779 render_surface2->SetOpacity(0.33f);
780
781 // One-time setup of root layer
782 gfx::Transform identity_matrix;
783 SetLayerPropertiesForTesting(root.get(),
784 identity_matrix,
[email protected]a2566412014-06-05 03:14:20785 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32786 gfx::PointF(),
787 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57788 true,
[email protected]fb661802013-03-25 01:59:32789 false);
790
791 // All layers in the tree are initialized with an anchor at .25 and a size of
792 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39793 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32794 gfx::Transform translation_to_anchor;
795 translation_to_anchor.Translate(2.5, 0.0);
796 gfx::Transform layer_transform;
797 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32798 gfx::Transform replica_layer_transform;
799 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
800
801 gfx::Transform A =
802 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32803 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
804 Inverse(translation_to_anchor);
805
806 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39807 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32808 gfx::Transform surface1_sublayer_transform;
809 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
810 surface1_parent_transform_scale.y());
811
812 // SS1 = transform given to the subtree of render_surface1
813 gfx::Transform SS1 = surface1_sublayer_transform;
814 // S1 = transform to move from render_surface1 pixels to the layer space of
815 // the owning layer
816 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
817
818 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39819 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32820 gfx::Transform surface2_sublayer_transform;
821 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
822 surface2_parent_transform_scale.y());
823
824 // SS2 = transform given to the subtree of render_surface2
825 gfx::Transform SS2 = surface2_sublayer_transform;
826 // S2 = transform to move from render_surface2 pixels to the layer space of
827 // the owning layer
828 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
829
830 SetLayerPropertiesForTesting(parent.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(render_surface1.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(render_surface2.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(child_of_root.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(child_of_rs1.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(child_of_rs2.get(),
866 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(10, 10),
[email protected]56fffdd2014-02-11 19:50:57870 true,
[email protected]fb661802013-03-25 01:59:32871 false);
872 SetLayerPropertiesForTesting(grand_child_of_root.get(),
873 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(10, 10),
[email protected]56fffdd2014-02-11 19:50:57877 true,
[email protected]fb661802013-03-25 01:59:32878 false);
879 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
880 layer_transform,
[email protected]a2566412014-06-05 03:14:20881 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32882 gfx::PointF(),
883 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57884 true,
[email protected]fb661802013-03-25 01:59:32885 false);
886 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
887 layer_transform,
[email protected]a2566412014-06-05 03:14:20888 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32889 gfx::PointF(),
890 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57891 true,
[email protected]fb661802013-03-25 01:59:32892 false);
893 SetLayerPropertiesForTesting(replica_of_rs1.get(),
894 replica_layer_transform,
[email protected]a2566412014-06-05 03:14:20895 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32896 gfx::PointF(),
897 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57898 true,
[email protected]fb661802013-03-25 01:59:32899 false);
900 SetLayerPropertiesForTesting(replica_of_rs2.get(),
901 replica_layer_transform,
[email protected]a2566412014-06-05 03:14:20902 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32903 gfx::PointF(),
904 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57905 true,
[email protected]fb661802013-03-25 01:59:32906 false);
907
908 ExecuteCalculateDrawProperties(root.get());
909
910 // Only layers that are associated with render surfaces should have an actual
911 // RenderSurface() value.
912 ASSERT_TRUE(root->render_surface());
913 ASSERT_FALSE(child_of_root->render_surface());
914 ASSERT_FALSE(grand_child_of_root->render_surface());
915
916 ASSERT_TRUE(render_surface1->render_surface());
917 ASSERT_FALSE(child_of_rs1->render_surface());
918 ASSERT_FALSE(grand_child_of_rs1->render_surface());
919
920 ASSERT_TRUE(render_surface2->render_surface());
921 ASSERT_FALSE(child_of_rs2->render_surface());
922 ASSERT_FALSE(grand_child_of_rs2->render_surface());
923
924 // Verify all render target accessors
925 EXPECT_EQ(root, parent->render_target());
926 EXPECT_EQ(root, child_of_root->render_target());
927 EXPECT_EQ(root, grand_child_of_root->render_target());
928
929 EXPECT_EQ(render_surface1, render_surface1->render_target());
930 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
931 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
932
933 EXPECT_EQ(render_surface2, render_surface2->render_target());
934 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
935 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
936
937 // Verify layer draw transforms note that draw transforms are described with
938 // respect to the nearest ancestor render surface but screen space transforms
939 // are described with respect to the root.
940 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
[email protected]baf64d062014-02-16 22:10:39941 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform());
942 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32943 grand_child_of_root->draw_transform());
944
945 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
[email protected]baf64d062014-02-16 22:10:39946 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform());
947 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
[email protected]fb661802013-03-25 01:59:32948 grand_child_of_rs1->draw_transform());
949
950 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
[email protected]baf64d062014-02-16 22:10:39951 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform());
952 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
[email protected]fb661802013-03-25 01:59:32953 grand_child_of_rs2->draw_transform());
954
955 // Verify layer screen-space transforms
956 //
957 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39958 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:32959 child_of_root->screen_space_transform());
960 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39961 A * A * A, grand_child_of_root->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32962
[email protected]baf64d062014-02-16 22:10:39963 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:32964 render_surface1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39965 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32966 child_of_rs1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39967 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:32968 grand_child_of_rs1->screen_space_transform());
969
[email protected]baf64d062014-02-16 22:10:39970 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32971 render_surface2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39972 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:32973 child_of_rs2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39974 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
[email protected]fb661802013-03-25 01:59:32975 grand_child_of_rs2->screen_space_transform());
976
977 // Verify render surface transforms.
978 //
979 // Draw transform of render surface 1 is described with respect to root.
980 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39981 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32982 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39983 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32984 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39985 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32986 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39987 A * R * S1,
[email protected]fb661802013-03-25 01:59:32988 render_surface1->render_surface()->replica_screen_space_transform());
989 // Draw transform of render surface 2 is described with respect to render
990 // surface 1.
991 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39992 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32993 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39994 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:32995 render_surface2->render_surface()->replica_draw_transform());
996 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39997 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:32998 render_surface2->render_surface()->screen_space_transform());
999 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391000 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:321001 render_surface2->render_surface()->replica_screen_space_transform());
1002
1003 // Sanity check. If these fail there is probably a bug in the test itself. It
1004 // is expected that we correctly set up transforms so that the y-component of
1005 // the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:261006 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
1007 EXPECT_FLOAT_EQ(2.0,
1008 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321009 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261010 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321011
[email protected]803f6b52013-09-12 00:51:261012 EXPECT_FLOAT_EQ(2.0,
1013 render_surface1->screen_space_transform().matrix().get(1, 3));
1014 EXPECT_FLOAT_EQ(3.0,
1015 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321016 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261017 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321018
[email protected]803f6b52013-09-12 00:51:261019 EXPECT_FLOAT_EQ(3.0,
1020 render_surface2->screen_space_transform().matrix().get(1, 3));
1021 EXPECT_FLOAT_EQ(4.0,
1022 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321023 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261024 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321025}
1026
[email protected]989386c2013-07-18 21:37:231027TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321028 // For layers that flatten their subtree, there should be an orthographic
1029 // projection (for x and y values) in the middle of the transform sequence.
1030 // Note that the way the code is currently implemented, it is not expected to
1031 // use a canonical orthographic projection.
1032
1033 scoped_refptr<Layer> root = Layer::Create();
1034 scoped_refptr<Layer> child = Layer::Create();
1035 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1036 make_scoped_refptr(new LayerWithForcedDrawsContent());
1037
1038 gfx::Transform rotation_about_y_axis;
1039 rotation_about_y_axis.RotateAboutYAxis(30.0);
1040
1041 const gfx::Transform identity_matrix;
1042 SetLayerPropertiesForTesting(root.get(),
1043 identity_matrix,
[email protected]a2566412014-06-05 03:14:201044 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321045 gfx::PointF(),
1046 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571047 true,
[email protected]fb661802013-03-25 01:59:321048 false);
1049 SetLayerPropertiesForTesting(child.get(),
1050 rotation_about_y_axis,
[email protected]a2566412014-06-05 03:14:201051 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321052 gfx::PointF(),
1053 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571054 true,
[email protected]fb661802013-03-25 01:59:321055 false);
1056 SetLayerPropertiesForTesting(grand_child.get(),
1057 rotation_about_y_axis,
[email protected]a2566412014-06-05 03:14:201058 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321059 gfx::PointF(),
1060 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571061 true,
[email protected]fb661802013-03-25 01:59:321062 false);
1063
1064 root->AddChild(child);
1065 child->AddChild(grand_child);
1066 child->SetForceRenderSurface(true);
1067
[email protected]d600df7d2013-08-03 02:34:281068 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1069 host->SetRootLayer(root);
1070
[email protected]fb661802013-03-25 01:59:321071 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:571072 ASSERT_TRUE(root->should_flatten_transform());
1073 ASSERT_TRUE(child->should_flatten_transform());
1074 ASSERT_TRUE(grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:321075
1076 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1077 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1078 gfx::Transform expected_grand_child_draw_transform =
1079 rotation_about_y_axis; // draws onto child's render surface
1080 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1081 flattened_rotation_about_y.FlattenTo2d();
1082 gfx::Transform expected_grand_child_screen_space_transform =
1083 flattened_rotation_about_y * rotation_about_y_axis;
1084
1085 ExecuteCalculateDrawProperties(root.get());
1086
1087 // The child's draw transform should have been taken by its surface.
1088 ASSERT_TRUE(child->render_surface());
1089 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1090 child->render_surface()->draw_transform());
1091 EXPECT_TRANSFORMATION_MATRIX_EQ(
1092 expected_child_screen_space_transform,
1093 child->render_surface()->screen_space_transform());
1094 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1095 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1096 child->screen_space_transform());
1097 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1098 grand_child->draw_transform());
1099 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1100 grand_child->screen_space_transform());
1101}
1102
[email protected]989386c2013-07-18 21:37:231103TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321104 // A layer that is empty in one axis, but not the other, was accidentally
1105 // skipping a necessary translation. Without that translation, the coordinate
1106 // space of the layer's draw transform is incorrect.
1107 //
1108 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1109 // but if that layer becomes a render surface, then its draw transform is
1110 // implicitly inherited by the rest of the subtree, which then is positioned
1111 // incorrectly as a result.
1112
1113 scoped_refptr<Layer> root = Layer::Create();
1114 scoped_refptr<Layer> child = Layer::Create();
1115 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1116 make_scoped_refptr(new LayerWithForcedDrawsContent());
1117
1118 // The child height is zero, but has non-zero width that should be accounted
1119 // for while computing draw transforms.
1120 const gfx::Transform identity_matrix;
1121 SetLayerPropertiesForTesting(root.get(),
1122 identity_matrix,
[email protected]a2566412014-06-05 03:14:201123 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321124 gfx::PointF(),
1125 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571126 true,
[email protected]fb661802013-03-25 01:59:321127 false);
1128 SetLayerPropertiesForTesting(child.get(),
1129 identity_matrix,
[email protected]a2566412014-06-05 03:14:201130 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321131 gfx::PointF(),
1132 gfx::Size(10, 0),
[email protected]56fffdd2014-02-11 19:50:571133 true,
[email protected]fb661802013-03-25 01:59:321134 false);
1135 SetLayerPropertiesForTesting(grand_child.get(),
1136 identity_matrix,
[email protected]a2566412014-06-05 03:14:201137 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321138 gfx::PointF(),
1139 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571140 true,
[email protected]fb661802013-03-25 01:59:321141 false);
1142
1143 root->AddChild(child);
1144 child->AddChild(grand_child);
1145 child->SetForceRenderSurface(true);
1146
[email protected]d600df7d2013-08-03 02:34:281147 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1148 host->SetRootLayer(root);
1149
[email protected]fb661802013-03-25 01:59:321150 ExecuteCalculateDrawProperties(root.get());
1151
1152 ASSERT_TRUE(child->render_surface());
1153 // This is the real test, the rest are sanity checks.
1154 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1155 child->render_surface()->draw_transform());
1156 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1157 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1158 grand_child->draw_transform());
1159}
1160
[email protected]989386c2013-07-18 21:37:231161TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321162 // Transformations applied at the root of the tree should be forwarded
1163 // to child layers instead of applied to the root RenderSurface.
1164 const gfx::Transform identity_matrix;
[email protected]d5754282014-04-09 00:43:291165 scoped_refptr<LayerWithForcedDrawsContent> root =
1166 new LayerWithForcedDrawsContent;
1167 scoped_refptr<LayerWithForcedDrawsContent> child =
1168 new LayerWithForcedDrawsContent;
[email protected]adeda572014-01-31 00:49:471169 child->SetScrollClipLayerId(root->id());
[email protected]f224cc92013-06-06 23:23:321170 root->AddChild(child);
1171
[email protected]d600df7d2013-08-03 02:34:281172 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1173 host->SetRootLayer(root);
1174
[email protected]f224cc92013-06-06 23:23:321175 SetLayerPropertiesForTesting(root.get(),
1176 identity_matrix,
[email protected]a2566412014-06-05 03:14:201177 gfx::Point3F(),
[email protected]f224cc92013-06-06 23:23:321178 gfx::PointF(),
1179 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571180 true,
[email protected]f224cc92013-06-06 23:23:321181 false);
1182 SetLayerPropertiesForTesting(child.get(),
1183 identity_matrix,
[email protected]a2566412014-06-05 03:14:201184 gfx::Point3F(),
[email protected]f224cc92013-06-06 23:23:321185 gfx::PointF(),
1186 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571187 true,
[email protected]f224cc92013-06-06 23:23:321188 false);
1189
[email protected]f224cc92013-06-06 23:23:321190 gfx::Transform translate;
1191 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231192 {
1193 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531194 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1195 root.get(), root->bounds(), translate, &render_surface_layer_list);
1196 inputs.can_adjust_raster_scales = true;
1197 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231198 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1199 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1200 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291201 EXPECT_EQ(1.f, root->last_device_scale_factor());
1202 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231203 }
[email protected]f224cc92013-06-06 23:23:321204
1205 gfx::Transform scale;
1206 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231207 {
1208 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531209 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1210 root.get(), root->bounds(), scale, &render_surface_layer_list);
1211 inputs.can_adjust_raster_scales = true;
1212 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231213 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1214 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1215 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291216 EXPECT_EQ(2.f, root->last_device_scale_factor());
1217 EXPECT_EQ(2.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231218 }
[email protected]f224cc92013-06-06 23:23:321219
1220 gfx::Transform rotate;
1221 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231222 {
1223 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531224 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1225 root.get(), root->bounds(), rotate, &render_surface_layer_list);
1226 inputs.can_adjust_raster_scales = true;
1227 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231228 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1229 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1230 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291231 EXPECT_EQ(1.f, root->last_device_scale_factor());
1232 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231233 }
[email protected]f224cc92013-06-06 23:23:321234
1235 gfx::Transform composite;
1236 composite.ConcatTransform(translate);
1237 composite.ConcatTransform(scale);
1238 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231239 {
1240 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531241 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1242 root.get(), root->bounds(), composite, &render_surface_layer_list);
1243 inputs.can_adjust_raster_scales = true;
1244 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231245 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1246 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1247 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1248 }
[email protected]f224cc92013-06-06 23:23:321249
[email protected]9781afa2013-07-17 23:15:321250 // Verify it composes correctly with device scale.
1251 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231252
1253 {
1254 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531255 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1256 root.get(), root->bounds(), translate, &render_surface_layer_list);
1257 inputs.device_scale_factor = device_scale_factor;
1258 inputs.can_adjust_raster_scales = true;
1259 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231260 gfx::Transform device_scaled_translate = translate;
1261 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1262 EXPECT_EQ(device_scaled_translate,
1263 root->draw_properties().target_space_transform);
1264 EXPECT_EQ(device_scaled_translate,
1265 child->draw_properties().target_space_transform);
1266 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291267 EXPECT_EQ(device_scale_factor, root->last_device_scale_factor());
1268 EXPECT_EQ(device_scale_factor, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231269 }
[email protected]9781afa2013-07-17 23:15:321270
1271 // Verify it composes correctly with page scale.
1272 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231273
1274 {
1275 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531276 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1277 root.get(), root->bounds(), translate, &render_surface_layer_list);
1278 inputs.page_scale_factor = page_scale_factor;
1279 inputs.page_scale_application_layer = root.get();
1280 inputs.can_adjust_raster_scales = true;
1281 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231282 gfx::Transform page_scaled_translate = translate;
1283 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1284 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1285 EXPECT_EQ(page_scaled_translate,
1286 child->draw_properties().target_space_transform);
1287 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291288 EXPECT_EQ(1.f, root->last_device_scale_factor());
1289 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231290 }
[email protected]9781afa2013-07-17 23:15:321291
[email protected]f224cc92013-06-06 23:23:321292 // Verify that it composes correctly with transforms directly on root layer.
1293 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231294
1295 {
1296 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531297 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1298 root.get(), root->bounds(), composite, &render_surface_layer_list);
1299 inputs.can_adjust_raster_scales = true;
1300 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231301 gfx::Transform compositeSquared = composite;
1302 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261303 EXPECT_TRANSFORMATION_MATRIX_EQ(
1304 compositeSquared, root->draw_properties().target_space_transform);
1305 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391306 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231307 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1308 }
[email protected]f224cc92013-06-06 23:23:321309}
1310
[email protected]989386c2013-07-18 21:37:231311TEST_F(LayerTreeHostCommonTest,
1312 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321313 scoped_refptr<Layer> parent = Layer::Create();
1314 scoped_refptr<Layer> render_surface1 = Layer::Create();
1315 scoped_refptr<LayerWithForcedDrawsContent> child =
1316 make_scoped_refptr(new LayerWithForcedDrawsContent());
1317
[email protected]d600df7d2013-08-03 02:34:281318 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1319 host->SetRootLayer(parent);
1320
[email protected]fb661802013-03-25 01:59:321321 const gfx::Transform identity_matrix;
1322 SetLayerPropertiesForTesting(parent.get(),
1323 identity_matrix,
[email protected]a2566412014-06-05 03:14:201324 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321325 gfx::PointF(),
1326 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571327 true,
[email protected]fb661802013-03-25 01:59:321328 false);
1329 SetLayerPropertiesForTesting(render_surface1.get(),
1330 identity_matrix,
[email protected]a2566412014-06-05 03:14:201331 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321332 gfx::PointF(),
1333 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571334 true,
[email protected]fb661802013-03-25 01:59:321335 false);
1336 SetLayerPropertiesForTesting(child.get(),
1337 identity_matrix,
[email protected]a2566412014-06-05 03:14:201338 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321339 gfx::PointF(30.f, 30.f),
1340 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571341 true,
[email protected]fb661802013-03-25 01:59:321342 false);
1343
1344 parent->AddChild(render_surface1);
1345 parent->SetMasksToBounds(true);
1346 render_surface1->AddChild(child);
1347 render_surface1->SetForceRenderSurface(true);
1348
[email protected]989386c2013-07-18 21:37:231349 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531350 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1351 parent.get(),
1352 parent->bounds(),
1353 gfx::Transform(),
1354 &render_surface_layer_list);
1355 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321356
1357 // The child layer's content is entirely outside the parent's clip rect, so
1358 // the intermediate render surface should not be listed here, even if it was
1359 // forced to be created. Render surfaces without children or visible content
1360 // are unexpected at draw time (e.g. we might try to create a content texture
1361 // of size 0).
1362 ASSERT_TRUE(parent->render_surface());
[email protected]fb661802013-03-25 01:59:321363 EXPECT_EQ(1U, render_surface_layer_list.size());
1364}
1365
[email protected]989386c2013-07-18 21:37:231366TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321367 scoped_refptr<Layer> parent = Layer::Create();
1368 scoped_refptr<Layer> render_surface1 = Layer::Create();
1369 scoped_refptr<LayerWithForcedDrawsContent> child =
1370 make_scoped_refptr(new LayerWithForcedDrawsContent());
1371
[email protected]d600df7d2013-08-03 02:34:281372 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1373 host->SetRootLayer(parent);
1374
[email protected]fb661802013-03-25 01:59:321375 const gfx::Transform identity_matrix;
1376 SetLayerPropertiesForTesting(render_surface1.get(),
1377 identity_matrix,
[email protected]a2566412014-06-05 03:14:201378 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321379 gfx::PointF(),
1380 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571381 true,
[email protected]fb661802013-03-25 01:59:321382 false);
1383 SetLayerPropertiesForTesting(child.get(),
1384 identity_matrix,
[email protected]a2566412014-06-05 03:14:201385 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321386 gfx::PointF(),
1387 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571388 true,
[email protected]fb661802013-03-25 01:59:321389 false);
1390
1391 parent->AddChild(render_surface1);
1392 render_surface1->AddChild(child);
1393 render_surface1->SetForceRenderSurface(true);
1394 render_surface1->SetOpacity(0.f);
1395
[email protected]989386c2013-07-18 21:37:231396 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531397 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1398 parent.get(), parent->bounds(), &render_surface_layer_list);
1399 inputs.can_adjust_raster_scales = true;
1400 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321401
1402 // Since the layer is transparent, render_surface1->render_surface() should
1403 // not have gotten added anywhere. Also, the drawable content rect should not
1404 // have been extended by the children.
1405 ASSERT_TRUE(parent->render_surface());
1406 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1407 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231408 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321409 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1410}
1411
[email protected]989386c2013-07-18 21:37:231412TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321413 scoped_refptr<Layer> parent = Layer::Create();
1414 scoped_refptr<Layer> render_surface1 = Layer::Create();
1415 scoped_refptr<LayerWithForcedDrawsContent> child =
1416 make_scoped_refptr(new LayerWithForcedDrawsContent());
1417 render_surface1->SetForceRenderSurface(true);
1418
[email protected]d600df7d2013-08-03 02:34:281419 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1420 host->SetRootLayer(parent);
1421
[email protected]fb661802013-03-25 01:59:321422 const gfx::Transform identity_matrix;
1423 SetLayerPropertiesForTesting(parent.get(),
1424 identity_matrix,
[email protected]a2566412014-06-05 03:14:201425 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321426 gfx::PointF(),
1427 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571428 true,
[email protected]fb661802013-03-25 01:59:321429 false);
1430 SetLayerPropertiesForTesting(render_surface1.get(),
1431 identity_matrix,
[email protected]a2566412014-06-05 03:14:201432 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321433 gfx::PointF(),
1434 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571435 true,
[email protected]fb661802013-03-25 01:59:321436 false);
1437 SetLayerPropertiesForTesting(child.get(),
1438 identity_matrix,
[email protected]a2566412014-06-05 03:14:201439 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321440 gfx::PointF(),
1441 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571442 true,
[email protected]fb661802013-03-25 01:59:321443 false);
1444
1445 parent->AddChild(render_surface1);
1446 render_surface1->AddChild(child);
1447
1448 // Sanity check before the actual test
1449 EXPECT_FALSE(parent->render_surface());
1450 EXPECT_FALSE(render_surface1->render_surface());
1451
[email protected]989386c2013-07-18 21:37:231452 {
1453 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531454 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1455 parent.get(), parent->bounds(), &render_surface_layer_list);
1456 inputs.can_adjust_raster_scales = true;
1457 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321458
[email protected]989386c2013-07-18 21:37:231459 // The root layer always creates a render surface
1460 EXPECT_TRUE(parent->render_surface());
1461 EXPECT_TRUE(render_surface1->render_surface());
1462 EXPECT_EQ(2U, render_surface_layer_list.size());
1463 }
[email protected]fb661802013-03-25 01:59:321464
[email protected]989386c2013-07-18 21:37:231465 {
1466 RenderSurfaceLayerList render_surface_layer_list;
1467 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531468 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1469 parent.get(), parent->bounds(), &render_surface_layer_list);
1470 inputs.can_adjust_raster_scales = true;
1471 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231472 EXPECT_TRUE(parent->render_surface());
1473 EXPECT_FALSE(render_surface1->render_surface());
1474 EXPECT_EQ(1U, render_surface_layer_list.size());
1475 }
[email protected]fb661802013-03-25 01:59:321476}
1477
[email protected]989386c2013-07-18 21:37:231478TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321479 // The entire subtree of layers that are outside the clip rect should be
1480 // culled away, and should not affect the render_surface_layer_list.
1481 //
1482 // The test tree is set up as follows:
1483 // - all layers except the leaf_nodes are forced to be a new render surface
1484 // that have something to draw.
1485 // - parent is a large container layer.
1486 // - child has masksToBounds=true to cause clipping.
1487 // - grand_child is positioned outside of the child's bounds
1488 // - great_grand_child is also kept outside child's bounds.
1489 //
1490 // In this configuration, grand_child and great_grand_child are completely
1491 // outside the clip rect, and they should never get scheduled on the list of
1492 // render surfaces.
1493 //
1494
1495 const gfx::Transform identity_matrix;
1496 scoped_refptr<Layer> parent = Layer::Create();
1497 scoped_refptr<Layer> child = Layer::Create();
1498 scoped_refptr<Layer> grand_child = Layer::Create();
1499 scoped_refptr<Layer> great_grand_child = Layer::Create();
1500 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1501 make_scoped_refptr(new LayerWithForcedDrawsContent());
1502 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1503 make_scoped_refptr(new LayerWithForcedDrawsContent());
1504 parent->AddChild(child);
1505 child->AddChild(grand_child);
1506 grand_child->AddChild(great_grand_child);
1507
[email protected]d600df7d2013-08-03 02:34:281508 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1509 host->SetRootLayer(parent);
1510
[email protected]fb661802013-03-25 01:59:321511 // leaf_node1 ensures that parent and child are kept on the
1512 // render_surface_layer_list, even though grand_child and great_grand_child
1513 // should be clipped.
1514 child->AddChild(leaf_node1);
1515 great_grand_child->AddChild(leaf_node2);
1516
1517 SetLayerPropertiesForTesting(parent.get(),
1518 identity_matrix,
[email protected]a2566412014-06-05 03:14:201519 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321520 gfx::PointF(),
1521 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571522 true,
[email protected]fb661802013-03-25 01:59:321523 false);
1524 SetLayerPropertiesForTesting(child.get(),
1525 identity_matrix,
[email protected]a2566412014-06-05 03:14:201526 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321527 gfx::PointF(),
1528 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571529 true,
[email protected]fb661802013-03-25 01:59:321530 false);
1531 SetLayerPropertiesForTesting(grand_child.get(),
1532 identity_matrix,
[email protected]a2566412014-06-05 03:14:201533 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321534 gfx::PointF(45.f, 45.f),
1535 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571536 true,
[email protected]fb661802013-03-25 01:59:321537 false);
1538 SetLayerPropertiesForTesting(great_grand_child.get(),
1539 identity_matrix,
[email protected]a2566412014-06-05 03:14:201540 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321541 gfx::PointF(),
1542 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571543 true,
[email protected]fb661802013-03-25 01:59:321544 false);
1545 SetLayerPropertiesForTesting(leaf_node1.get(),
1546 identity_matrix,
[email protected]a2566412014-06-05 03:14:201547 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321548 gfx::PointF(),
1549 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571550 true,
[email protected]fb661802013-03-25 01:59:321551 false);
1552 SetLayerPropertiesForTesting(leaf_node2.get(),
1553 identity_matrix,
[email protected]a2566412014-06-05 03:14:201554 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321555 gfx::PointF(),
1556 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571557 true,
[email protected]fb661802013-03-25 01:59:321558 false);
1559
1560 child->SetMasksToBounds(true);
1561 child->SetOpacity(0.4f);
1562 child->SetForceRenderSurface(true);
1563 grand_child->SetOpacity(0.5f);
1564 great_grand_child->SetOpacity(0.4f);
1565
[email protected]989386c2013-07-18 21:37:231566 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531567 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1568 parent.get(), parent->bounds(), &render_surface_layer_list);
1569 inputs.can_adjust_raster_scales = true;
1570 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321571
1572 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231573 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1574 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321575}
1576
[email protected]989386c2013-07-18 21:37:231577TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321578 // When a render surface has a clip rect, it is used to clip the content rect
1579 // of the surface. When the render surface is animating its transforms, then
1580 // the content rect's position in the clip rect is not defined on the main
1581 // thread, and its content rect should not be clipped.
1582
1583 // The test tree is set up as follows:
1584 // - parent is a container layer that masksToBounds=true to cause clipping.
1585 // - child is a render surface, which has a clip rect set to the bounds of
1586 // the parent.
1587 // - grand_child is a render surface, and the only visible content in child.
1588 // It is positioned outside of the clip rect from parent.
1589
1590 // In this configuration, grand_child should be outside the clipped
1591 // content rect of the child, making grand_child not appear in the
1592 // render_surface_layer_list. However, when we place an animation on the
1593 // child, this clipping should be avoided and we should keep the grand_child
1594 // in the render_surface_layer_list.
1595
1596 const gfx::Transform identity_matrix;
1597 scoped_refptr<Layer> parent = Layer::Create();
1598 scoped_refptr<Layer> child = Layer::Create();
1599 scoped_refptr<Layer> grand_child = Layer::Create();
1600 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1601 make_scoped_refptr(new LayerWithForcedDrawsContent());
1602 parent->AddChild(child);
1603 child->AddChild(grand_child);
1604 grand_child->AddChild(leaf_node);
1605
[email protected]d600df7d2013-08-03 02:34:281606 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1607 host->SetRootLayer(parent);
1608
[email protected]fb661802013-03-25 01:59:321609 SetLayerPropertiesForTesting(parent.get(),
1610 identity_matrix,
[email protected]a2566412014-06-05 03:14:201611 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321612 gfx::PointF(),
1613 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571614 true,
[email protected]fb661802013-03-25 01:59:321615 false);
1616 SetLayerPropertiesForTesting(child.get(),
1617 identity_matrix,
[email protected]a2566412014-06-05 03:14:201618 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321619 gfx::PointF(),
1620 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571621 true,
[email protected]fb661802013-03-25 01:59:321622 false);
1623 SetLayerPropertiesForTesting(grand_child.get(),
1624 identity_matrix,
[email protected]a2566412014-06-05 03:14:201625 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321626 gfx::PointF(200.f, 200.f),
1627 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571628 true,
[email protected]fb661802013-03-25 01:59:321629 false);
1630 SetLayerPropertiesForTesting(leaf_node.get(),
1631 identity_matrix,
[email protected]a2566412014-06-05 03:14:201632 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321633 gfx::PointF(),
1634 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571635 true,
[email protected]fb661802013-03-25 01:59:321636 false);
1637
1638 parent->SetMasksToBounds(true);
1639 child->SetOpacity(0.4f);
1640 child->SetForceRenderSurface(true);
1641 grand_child->SetOpacity(0.4f);
1642 grand_child->SetForceRenderSurface(true);
1643
[email protected]989386c2013-07-18 21:37:231644 {
1645 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531646 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1647 parent.get(), parent->bounds(), &render_surface_layer_list);
1648 inputs.can_adjust_raster_scales = true;
1649 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321650
[email protected]989386c2013-07-18 21:37:231651 // Without an animation, we should cull child and grand_child from the
1652 // render_surface_layer_list.
1653 ASSERT_EQ(1U, render_surface_layer_list.size());
1654 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1655 }
[email protected]fb661802013-03-25 01:59:321656
1657 // Now put an animating transform on child.
1658 AddAnimatedTransformToController(
1659 child->layer_animation_controller(), 10.0, 30, 0);
1660
[email protected]989386c2013-07-18 21:37:231661 {
1662 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531663 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1664 parent.get(), parent->bounds(), &render_surface_layer_list);
1665 inputs.can_adjust_raster_scales = true;
1666 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321667
[email protected]989386c2013-07-18 21:37:231668 // With an animating transform, we should keep child and grand_child in the
1669 // render_surface_layer_list.
1670 ASSERT_EQ(3U, render_surface_layer_list.size());
1671 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1672 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1673 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1674 }
[email protected]fb661802013-03-25 01:59:321675}
1676
[email protected]989386c2013-07-18 21:37:231677TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:321678 // Layer's IsClipped() property is set to true when:
1679 // - the layer clips its subtree, e.g. masks to bounds,
1680 // - the layer is clipped by an ancestor that contributes to the same
1681 // render target,
1682 // - a surface is clipped by an ancestor that contributes to the same
1683 // render target.
1684 //
1685 // In particular, for a layer that owns a render surface:
1686 // - the render surface inherits any clip from ancestors, and does NOT
1687 // pass that clipped status to the layer itself.
1688 // - but if the layer itself masks to bounds, it is considered clipped
1689 // and propagates the clip to the subtree.
1690
1691 const gfx::Transform identity_matrix;
1692 scoped_refptr<Layer> root = Layer::Create();
1693 scoped_refptr<Layer> parent = Layer::Create();
1694 scoped_refptr<Layer> child1 = Layer::Create();
1695 scoped_refptr<Layer> child2 = Layer::Create();
1696 scoped_refptr<Layer> grand_child = Layer::Create();
1697 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1698 make_scoped_refptr(new LayerWithForcedDrawsContent());
1699 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1700 make_scoped_refptr(new LayerWithForcedDrawsContent());
1701 root->AddChild(parent);
1702 parent->AddChild(child1);
1703 parent->AddChild(child2);
1704 child1->AddChild(grand_child);
1705 child2->AddChild(leaf_node2);
1706 grand_child->AddChild(leaf_node1);
1707
[email protected]d600df7d2013-08-03 02:34:281708 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1709 host->SetRootLayer(root);
1710
[email protected]fb661802013-03-25 01:59:321711 child2->SetForceRenderSurface(true);
1712
1713 SetLayerPropertiesForTesting(root.get(),
1714 identity_matrix,
[email protected]a2566412014-06-05 03:14:201715 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321716 gfx::PointF(),
1717 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571718 true,
[email protected]fb661802013-03-25 01:59:321719 false);
1720 SetLayerPropertiesForTesting(parent.get(),
1721 identity_matrix,
[email protected]a2566412014-06-05 03:14:201722 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321723 gfx::PointF(),
1724 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571725 true,
[email protected]fb661802013-03-25 01:59:321726 false);
1727 SetLayerPropertiesForTesting(child1.get(),
1728 identity_matrix,
[email protected]a2566412014-06-05 03:14:201729 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321730 gfx::PointF(),
1731 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571732 true,
[email protected]fb661802013-03-25 01:59:321733 false);
1734 SetLayerPropertiesForTesting(child2.get(),
1735 identity_matrix,
[email protected]a2566412014-06-05 03:14:201736 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321737 gfx::PointF(),
1738 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571739 true,
[email protected]fb661802013-03-25 01:59:321740 false);
1741 SetLayerPropertiesForTesting(grand_child.get(),
1742 identity_matrix,
[email protected]a2566412014-06-05 03:14:201743 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321744 gfx::PointF(),
1745 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571746 true,
[email protected]fb661802013-03-25 01:59:321747 false);
1748 SetLayerPropertiesForTesting(leaf_node1.get(),
1749 identity_matrix,
[email protected]a2566412014-06-05 03:14:201750 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321751 gfx::PointF(),
1752 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571753 true,
[email protected]fb661802013-03-25 01:59:321754 false);
1755 SetLayerPropertiesForTesting(leaf_node2.get(),
1756 identity_matrix,
[email protected]a2566412014-06-05 03:14:201757 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321758 gfx::PointF(),
1759 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571760 true,
[email protected]fb661802013-03-25 01:59:321761 false);
1762
[email protected]989386c2013-07-18 21:37:231763 // Case 1: nothing is clipped except the root render surface.
1764 {
1765 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531766 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1767 root.get(), parent->bounds(), &render_surface_layer_list);
1768 inputs.can_adjust_raster_scales = true;
1769 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321770
[email protected]989386c2013-07-18 21:37:231771 ASSERT_TRUE(root->render_surface());
1772 ASSERT_TRUE(child2->render_surface());
1773
1774 EXPECT_FALSE(root->is_clipped());
1775 EXPECT_TRUE(root->render_surface()->is_clipped());
1776 EXPECT_FALSE(parent->is_clipped());
1777 EXPECT_FALSE(child1->is_clipped());
1778 EXPECT_FALSE(child2->is_clipped());
1779 EXPECT_FALSE(child2->render_surface()->is_clipped());
1780 EXPECT_FALSE(grand_child->is_clipped());
1781 EXPECT_FALSE(leaf_node1->is_clipped());
1782 EXPECT_FALSE(leaf_node2->is_clipped());
1783 }
[email protected]fb661802013-03-25 01:59:321784
1785 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1786 // surface are clipped. But layers that contribute to child2's surface are
1787 // not clipped explicitly because child2's surface already accounts for
1788 // that clip.
[email protected]989386c2013-07-18 21:37:231789 {
1790 RenderSurfaceLayerList render_surface_layer_list;
1791 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531792 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1793 root.get(), parent->bounds(), &render_surface_layer_list);
1794 inputs.can_adjust_raster_scales = true;
1795 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321796
[email protected]989386c2013-07-18 21:37:231797 ASSERT_TRUE(root->render_surface());
1798 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321799
[email protected]989386c2013-07-18 21:37:231800 EXPECT_FALSE(root->is_clipped());
1801 EXPECT_TRUE(root->render_surface()->is_clipped());
1802 EXPECT_TRUE(parent->is_clipped());
1803 EXPECT_TRUE(child1->is_clipped());
1804 EXPECT_FALSE(child2->is_clipped());
1805 EXPECT_TRUE(child2->render_surface()->is_clipped());
1806 EXPECT_TRUE(grand_child->is_clipped());
1807 EXPECT_TRUE(leaf_node1->is_clipped());
1808 EXPECT_FALSE(leaf_node2->is_clipped());
1809 }
[email protected]fb661802013-03-25 01:59:321810
1811 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1812 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:231813 {
1814 RenderSurfaceLayerList render_surface_layer_list;
1815 parent->SetMasksToBounds(false);
1816 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531817 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1818 root.get(), parent->bounds(), &render_surface_layer_list);
1819 inputs.can_adjust_raster_scales = true;
1820 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321821
[email protected]989386c2013-07-18 21:37:231822 ASSERT_TRUE(root->render_surface());
1823 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321824
[email protected]989386c2013-07-18 21:37:231825 EXPECT_FALSE(root->is_clipped());
1826 EXPECT_TRUE(root->render_surface()->is_clipped());
1827 EXPECT_FALSE(parent->is_clipped());
1828 EXPECT_FALSE(child1->is_clipped());
1829 EXPECT_TRUE(child2->is_clipped());
1830 EXPECT_FALSE(child2->render_surface()->is_clipped());
1831 EXPECT_FALSE(grand_child->is_clipped());
1832 EXPECT_FALSE(leaf_node1->is_clipped());
1833 EXPECT_TRUE(leaf_node2->is_clipped());
1834 }
[email protected]fb661802013-03-25 01:59:321835}
1836
[email protected]fd9a3b6d2013-08-03 00:46:171837TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321838 // Verify that layers get the appropriate DrawableContentRect when their
1839 // parent masksToBounds is true.
1840 //
1841 // grand_child1 - completely inside the region; DrawableContentRect should
1842 // be the layer rect expressed in target space.
1843 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1844 // will be the intersection of layer bounds and the mask region.
1845 // grand_child3 - partially clipped and masksToBounds; the
1846 // DrawableContentRect will still be the intersection of layer bounds and
1847 // the mask region.
1848 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1849 // be empty.
1850 //
1851
1852 const gfx::Transform identity_matrix;
1853 scoped_refptr<Layer> parent = Layer::Create();
1854 scoped_refptr<Layer> child = Layer::Create();
1855 scoped_refptr<Layer> grand_child1 = Layer::Create();
1856 scoped_refptr<Layer> grand_child2 = Layer::Create();
1857 scoped_refptr<Layer> grand_child3 = Layer::Create();
1858 scoped_refptr<Layer> grand_child4 = Layer::Create();
1859
1860 parent->AddChild(child);
1861 child->AddChild(grand_child1);
1862 child->AddChild(grand_child2);
1863 child->AddChild(grand_child3);
1864 child->AddChild(grand_child4);
1865
[email protected]d600df7d2013-08-03 02:34:281866 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1867 host->SetRootLayer(parent);
1868
[email protected]fb661802013-03-25 01:59:321869 SetLayerPropertiesForTesting(parent.get(),
1870 identity_matrix,
[email protected]a2566412014-06-05 03:14:201871 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321872 gfx::PointF(),
1873 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571874 true,
[email protected]fb661802013-03-25 01:59:321875 false);
1876 SetLayerPropertiesForTesting(child.get(),
1877 identity_matrix,
[email protected]a2566412014-06-05 03:14:201878 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321879 gfx::PointF(),
1880 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571881 true,
[email protected]fb661802013-03-25 01:59:321882 false);
1883 SetLayerPropertiesForTesting(grand_child1.get(),
1884 identity_matrix,
[email protected]a2566412014-06-05 03:14:201885 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321886 gfx::PointF(5.f, 5.f),
1887 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571888 true,
[email protected]fb661802013-03-25 01:59:321889 false);
1890 SetLayerPropertiesForTesting(grand_child2.get(),
1891 identity_matrix,
[email protected]a2566412014-06-05 03:14:201892 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321893 gfx::PointF(15.f, 15.f),
1894 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571895 true,
[email protected]fb661802013-03-25 01:59:321896 false);
1897 SetLayerPropertiesForTesting(grand_child3.get(),
1898 identity_matrix,
[email protected]a2566412014-06-05 03:14:201899 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321900 gfx::PointF(15.f, 15.f),
1901 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571902 true,
[email protected]fb661802013-03-25 01:59:321903 false);
1904 SetLayerPropertiesForTesting(grand_child4.get(),
1905 identity_matrix,
[email protected]a2566412014-06-05 03:14:201906 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321907 gfx::PointF(45.f, 45.f),
1908 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571909 true,
[email protected]fb661802013-03-25 01:59:321910 false);
1911
1912 child->SetMasksToBounds(true);
1913 grand_child3->SetMasksToBounds(true);
1914
1915 // Force everyone to be a render surface.
1916 child->SetOpacity(0.4f);
1917 grand_child1->SetOpacity(0.5f);
1918 grand_child2->SetOpacity(0.5f);
1919 grand_child3->SetOpacity(0.5f);
1920 grand_child4->SetOpacity(0.5f);
1921
[email protected]989386c2013-07-18 21:37:231922 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531923 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1924 parent.get(), parent->bounds(), &render_surface_layer_list);
1925 inputs.can_adjust_raster_scales = true;
1926 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321927
[email protected]2c7c6702013-03-26 03:14:051928 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
[email protected]fb661802013-03-25 01:59:321929 grand_child1->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:051930 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:321931 grand_child3->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:051932 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:321933 grand_child3->drawable_content_rect());
1934 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
1935}
1936
[email protected]989386c2013-07-18 21:37:231937TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:321938 // Verify that render surfaces (and their layers) get the appropriate
1939 // clip rects when their parent masksToBounds is true.
1940 //
1941 // Layers that own render surfaces (at least for now) do not inherit any
1942 // clipping; instead the surface will enforce the clip for the entire subtree.
1943 // They may still have a clip rect of their own layer bounds, however, if
1944 // masksToBounds was true.
1945 const gfx::Transform identity_matrix;
1946 scoped_refptr<Layer> parent = Layer::Create();
1947 scoped_refptr<Layer> child = Layer::Create();
1948 scoped_refptr<Layer> grand_child1 = Layer::Create();
1949 scoped_refptr<Layer> grand_child2 = Layer::Create();
1950 scoped_refptr<Layer> grand_child3 = Layer::Create();
1951 scoped_refptr<Layer> grand_child4 = Layer::Create();
1952 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1953 make_scoped_refptr(new LayerWithForcedDrawsContent());
1954 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1955 make_scoped_refptr(new LayerWithForcedDrawsContent());
1956 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
1957 make_scoped_refptr(new LayerWithForcedDrawsContent());
1958 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
1959 make_scoped_refptr(new LayerWithForcedDrawsContent());
1960
1961 parent->AddChild(child);
1962 child->AddChild(grand_child1);
1963 child->AddChild(grand_child2);
1964 child->AddChild(grand_child3);
1965 child->AddChild(grand_child4);
1966
[email protected]d600df7d2013-08-03 02:34:281967 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1968 host->SetRootLayer(parent);
1969
[email protected]fb661802013-03-25 01:59:321970 // the leaf nodes ensure that these grand_children become render surfaces for
1971 // this test.
1972 grand_child1->AddChild(leaf_node1);
1973 grand_child2->AddChild(leaf_node2);
1974 grand_child3->AddChild(leaf_node3);
1975 grand_child4->AddChild(leaf_node4);
1976
1977 SetLayerPropertiesForTesting(parent.get(),
1978 identity_matrix,
[email protected]a2566412014-06-05 03:14:201979 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321980 gfx::PointF(),
1981 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571982 true,
[email protected]fb661802013-03-25 01:59:321983 false);
1984 SetLayerPropertiesForTesting(child.get(),
1985 identity_matrix,
[email protected]a2566412014-06-05 03:14:201986 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321987 gfx::PointF(),
1988 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571989 true,
[email protected]fb661802013-03-25 01:59:321990 false);
1991 SetLayerPropertiesForTesting(grand_child1.get(),
1992 identity_matrix,
[email protected]a2566412014-06-05 03:14:201993 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321994 gfx::PointF(5.f, 5.f),
1995 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571996 true,
[email protected]fb661802013-03-25 01:59:321997 false);
1998 SetLayerPropertiesForTesting(grand_child2.get(),
1999 identity_matrix,
[email protected]a2566412014-06-05 03:14:202000 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322001 gfx::PointF(15.f, 15.f),
2002 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572003 true,
[email protected]fb661802013-03-25 01:59:322004 false);
2005 SetLayerPropertiesForTesting(grand_child3.get(),
2006 identity_matrix,
[email protected]a2566412014-06-05 03:14:202007 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322008 gfx::PointF(15.f, 15.f),
2009 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572010 true,
[email protected]fb661802013-03-25 01:59:322011 false);
2012 SetLayerPropertiesForTesting(grand_child4.get(),
2013 identity_matrix,
[email protected]a2566412014-06-05 03:14:202014 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322015 gfx::PointF(45.f, 45.f),
2016 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572017 true,
[email protected]fb661802013-03-25 01:59:322018 false);
2019 SetLayerPropertiesForTesting(leaf_node1.get(),
2020 identity_matrix,
[email protected]a2566412014-06-05 03:14:202021 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322022 gfx::PointF(),
2023 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572024 true,
[email protected]fb661802013-03-25 01:59:322025 false);
2026 SetLayerPropertiesForTesting(leaf_node2.get(),
2027 identity_matrix,
[email protected]a2566412014-06-05 03:14:202028 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322029 gfx::PointF(),
2030 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572031 true,
[email protected]fb661802013-03-25 01:59:322032 false);
2033 SetLayerPropertiesForTesting(leaf_node3.get(),
2034 identity_matrix,
[email protected]a2566412014-06-05 03:14:202035 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322036 gfx::PointF(),
2037 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572038 true,
[email protected]fb661802013-03-25 01:59:322039 false);
2040 SetLayerPropertiesForTesting(leaf_node4.get(),
2041 identity_matrix,
[email protected]a2566412014-06-05 03:14:202042 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322043 gfx::PointF(),
2044 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572045 true,
[email protected]fb661802013-03-25 01:59:322046 false);
2047
2048 child->SetMasksToBounds(true);
2049 grand_child3->SetMasksToBounds(true);
2050 grand_child4->SetMasksToBounds(true);
2051
2052 // Force everyone to be a render surface.
2053 child->SetOpacity(0.4f);
2054 child->SetForceRenderSurface(true);
2055 grand_child1->SetOpacity(0.5f);
2056 grand_child1->SetForceRenderSurface(true);
2057 grand_child2->SetOpacity(0.5f);
2058 grand_child2->SetForceRenderSurface(true);
2059 grand_child3->SetOpacity(0.5f);
2060 grand_child3->SetForceRenderSurface(true);
2061 grand_child4->SetOpacity(0.5f);
2062 grand_child4->SetForceRenderSurface(true);
2063
[email protected]989386c2013-07-18 21:37:232064 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532065 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2066 parent.get(), parent->bounds(), &render_surface_layer_list);
2067 inputs.can_adjust_raster_scales = true;
2068 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322069 ASSERT_TRUE(grand_child1->render_surface());
2070 ASSERT_TRUE(grand_child2->render_surface());
2071 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322072
2073 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2074 // masksToBounds.
[email protected]2c7c6702013-03-26 03:14:052075 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322076 grand_child1->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052077 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322078 grand_child2->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052079 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322080 grand_child3->render_surface()->clip_rect());
2081}
2082
[email protected]989386c2013-07-18 21:37:232083TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322084 scoped_refptr<Layer> parent = Layer::Create();
2085 scoped_refptr<Layer> render_surface1 = Layer::Create();
2086 scoped_refptr<Layer> render_surface2 = Layer::Create();
2087 scoped_refptr<Layer> child_of_root = Layer::Create();
2088 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2089 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2090 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2091 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2092 make_scoped_refptr(new LayerWithForcedDrawsContent());
2093 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2094 make_scoped_refptr(new LayerWithForcedDrawsContent());
2095 parent->AddChild(render_surface1);
2096 parent->AddChild(child_of_root);
2097 render_surface1->AddChild(child_of_rs1);
2098 render_surface1->AddChild(render_surface2);
2099 render_surface2->AddChild(child_of_rs2);
2100 child_of_root->AddChild(grand_child_of_root);
2101 child_of_rs1->AddChild(grand_child_of_rs1);
2102 child_of_rs2->AddChild(grand_child_of_rs2);
2103
[email protected]d600df7d2013-08-03 02:34:282104 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2105 host->SetRootLayer(parent);
2106
[email protected]fb661802013-03-25 01:59:322107 // Make our render surfaces.
2108 render_surface1->SetForceRenderSurface(true);
2109 render_surface2->SetForceRenderSurface(true);
2110
2111 gfx::Transform layer_transform;
2112 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322113
2114 SetLayerPropertiesForTesting(parent.get(),
2115 layer_transform,
[email protected]a2566412014-06-05 03:14:202116 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322117 gfx::PointF(2.5f, 0.f),
2118 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572119 true,
[email protected]fb661802013-03-25 01:59:322120 false);
2121 SetLayerPropertiesForTesting(render_surface1.get(),
2122 layer_transform,
[email protected]a2566412014-06-05 03:14:202123 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322124 gfx::PointF(2.5f, 0.f),
2125 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572126 true,
[email protected]fb661802013-03-25 01:59:322127 false);
2128 SetLayerPropertiesForTesting(render_surface2.get(),
2129 layer_transform,
[email protected]a2566412014-06-05 03:14:202130 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322131 gfx::PointF(2.5f, 0.f),
2132 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572133 true,
[email protected]fb661802013-03-25 01:59:322134 false);
2135 SetLayerPropertiesForTesting(child_of_root.get(),
2136 layer_transform,
[email protected]a2566412014-06-05 03:14:202137 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322138 gfx::PointF(2.5f, 0.f),
2139 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572140 true,
[email protected]fb661802013-03-25 01:59:322141 false);
2142 SetLayerPropertiesForTesting(child_of_rs1.get(),
2143 layer_transform,
[email protected]a2566412014-06-05 03:14:202144 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322145 gfx::PointF(2.5f, 0.f),
2146 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572147 true,
[email protected]fb661802013-03-25 01:59:322148 false);
2149 SetLayerPropertiesForTesting(child_of_rs2.get(),
2150 layer_transform,
[email protected]a2566412014-06-05 03:14:202151 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322152 gfx::PointF(2.5f, 0.f),
2153 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572154 true,
[email protected]fb661802013-03-25 01:59:322155 false);
2156 SetLayerPropertiesForTesting(grand_child_of_root.get(),
2157 layer_transform,
[email protected]a2566412014-06-05 03:14:202158 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322159 gfx::PointF(2.5f, 0.f),
2160 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572161 true,
[email protected]fb661802013-03-25 01:59:322162 false);
2163 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
2164 layer_transform,
[email protected]a2566412014-06-05 03:14:202165 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322166 gfx::PointF(2.5f, 0.f),
2167 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572168 true,
[email protected]fb661802013-03-25 01:59:322169 false);
2170 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
2171 layer_transform,
[email protected]a2566412014-06-05 03:14:202172 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322173 gfx::PointF(2.5f, 0.f),
2174 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572175 true,
[email protected]fb661802013-03-25 01:59:322176 false);
2177
2178 // Put an animated opacity on the render surface.
2179 AddOpacityTransitionToController(
2180 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2181
2182 // Also put an animated opacity on a layer without descendants.
2183 AddOpacityTransitionToController(
2184 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2185
2186 // Put a transform animation on the render surface.
2187 AddAnimatedTransformToController(
2188 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2189
2190 // Also put transform animations on grand_child_of_root, and
2191 // grand_child_of_rs2
2192 AddAnimatedTransformToController(
2193 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2194 AddAnimatedTransformToController(
2195 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2196
2197 ExecuteCalculateDrawProperties(parent.get());
2198
2199 // Only layers that are associated with render surfaces should have an actual
2200 // RenderSurface() value.
2201 ASSERT_TRUE(parent->render_surface());
2202 ASSERT_FALSE(child_of_root->render_surface());
2203 ASSERT_FALSE(grand_child_of_root->render_surface());
2204
2205 ASSERT_TRUE(render_surface1->render_surface());
2206 ASSERT_FALSE(child_of_rs1->render_surface());
2207 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2208
2209 ASSERT_TRUE(render_surface2->render_surface());
2210 ASSERT_FALSE(child_of_rs2->render_surface());
2211 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2212
2213 // Verify all render target accessors
2214 EXPECT_EQ(parent, parent->render_target());
2215 EXPECT_EQ(parent, child_of_root->render_target());
2216 EXPECT_EQ(parent, grand_child_of_root->render_target());
2217
2218 EXPECT_EQ(render_surface1, render_surface1->render_target());
2219 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2220 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
2221
2222 EXPECT_EQ(render_surface2, render_surface2->render_target());
2223 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2224 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
2225
2226 // Verify draw_opacity_is_animating values
2227 EXPECT_FALSE(parent->draw_opacity_is_animating());
2228 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2229 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2230 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2231 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2232 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2233 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2234 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2235 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2236 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2237 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2238
2239 // Verify draw_transform_is_animating values
2240 EXPECT_FALSE(parent->draw_transform_is_animating());
2241 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2242 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2243 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2244 EXPECT_FALSE(render_surface1->render_surface()
2245 ->target_surface_transforms_are_animating());
2246 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2247 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2248 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2249 EXPECT_TRUE(render_surface2->render_surface()
2250 ->target_surface_transforms_are_animating());
2251 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2252 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2253
2254 // Verify screen_space_transform_is_animating values
2255 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2256 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2257 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2258 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2259 EXPECT_FALSE(render_surface1->render_surface()
2260 ->screen_space_transforms_are_animating());
2261 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2262 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2263 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2264 EXPECT_TRUE(render_surface2->render_surface()
2265 ->screen_space_transforms_are_animating());
2266 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2267 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2268
2269 // Sanity check. If these fail there is probably a bug in the test itself.
2270 // It is expected that we correctly set up transforms so that the y-component
2271 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262272 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2273 EXPECT_FLOAT_EQ(2.0,
2274 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322275 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262276 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322277
[email protected]803f6b52013-09-12 00:51:262278 EXPECT_FLOAT_EQ(2.0,
2279 render_surface1->screen_space_transform().matrix().get(1, 3));
2280 EXPECT_FLOAT_EQ(3.0,
2281 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322282 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262283 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322284
[email protected]803f6b52013-09-12 00:51:262285 EXPECT_FLOAT_EQ(3.0,
2286 render_surface2->screen_space_transform().matrix().get(1, 3));
2287 EXPECT_FLOAT_EQ(4.0,
2288 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322289 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262290 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322291}
2292
[email protected]989386c2013-07-18 21:37:232293TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322294 // Test the calculateVisibleRect() function works correctly for identity
2295 // transforms.
2296
[email protected]2c7c6702013-03-26 03:14:052297 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322298 gfx::Transform layer_to_surface_transform;
2299
2300 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232301 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052302 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322303 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2304 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2305 EXPECT_RECT_EQ(expected, actual);
2306
2307 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052308 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322309 actual = LayerTreeHostCommon::CalculateVisibleRect(
2310 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2311 EXPECT_TRUE(actual.IsEmpty());
2312
2313 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052314 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2315 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322316 actual = LayerTreeHostCommon::CalculateVisibleRect(
2317 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2318 EXPECT_RECT_EQ(expected, actual);
2319}
2320
[email protected]989386c2013-07-18 21:37:232321TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322322 // Test the calculateVisibleRect() function works correctly for scaling
2323 // transforms.
2324
[email protected]2c7c6702013-03-26 03:14:052325 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2326 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322327 gfx::Transform layer_to_surface_transform;
2328
2329 // Case 1: Layer is contained within the surface.
2330 layer_to_surface_transform.MakeIdentity();
2331 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052332 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322333 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2334 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2335 EXPECT_RECT_EQ(expected, actual);
2336
2337 // Case 2: Layer is outside the surface rect.
2338 layer_to_surface_transform.MakeIdentity();
2339 layer_to_surface_transform.Translate(120.0, 120.0);
2340 actual = LayerTreeHostCommon::CalculateVisibleRect(
2341 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2342 EXPECT_TRUE(actual.IsEmpty());
2343
2344 // Case 3: Layer is partially overlapping the surface rect.
2345 layer_to_surface_transform.MakeIdentity();
2346 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052347 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322348 actual = LayerTreeHostCommon::CalculateVisibleRect(
2349 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2350 EXPECT_RECT_EQ(expected, actual);
2351}
2352
[email protected]989386c2013-07-18 21:37:232353TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322354 // Test the calculateVisibleRect() function works correctly for rotations
2355 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2356 // should return the g in the layer's space.
2357
[email protected]2c7c6702013-03-26 03:14:052358 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2359 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322360 gfx::Transform layer_to_surface_transform;
2361
2362 // Case 1: Layer is contained within the surface.
2363 layer_to_surface_transform.MakeIdentity();
2364 layer_to_surface_transform.Translate(50.0, 50.0);
2365 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052366 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322367 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2368 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2369 EXPECT_RECT_EQ(expected, actual);
2370
2371 // Case 2: Layer is outside the surface rect.
2372 layer_to_surface_transform.MakeIdentity();
2373 layer_to_surface_transform.Translate(-50.0, 0.0);
2374 layer_to_surface_transform.Rotate(45.0);
2375 actual = LayerTreeHostCommon::CalculateVisibleRect(
2376 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2377 EXPECT_TRUE(actual.IsEmpty());
2378
2379 // Case 3: The layer is rotated about its top-left corner. In surface space,
2380 // the layer is oriented diagonally, with the left half outside of the render
2381 // surface. In this case, the g should still be the entire layer
2382 // (remember the g is computed in layer space); both the top-left
2383 // and bottom-right corners of the layer are still visible.
2384 layer_to_surface_transform.MakeIdentity();
2385 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052386 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322387 actual = LayerTreeHostCommon::CalculateVisibleRect(
2388 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2389 EXPECT_RECT_EQ(expected, actual);
2390
2391 // Case 4: The layer is rotated about its top-left corner, and translated
2392 // upwards. In surface space, the layer is oriented diagonally, with only the
2393 // top corner of the surface overlapping the layer. In layer space, the render
2394 // surface overlaps the right side of the layer. The g should be
2395 // the layer's right half.
2396 layer_to_surface_transform.MakeIdentity();
2397 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2398 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052399 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322400 actual = LayerTreeHostCommon::CalculateVisibleRect(
2401 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2402 EXPECT_RECT_EQ(expected, actual);
2403}
2404
[email protected]989386c2013-07-18 21:37:232405TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322406 // Test that the calculateVisibleRect() function works correctly for 3d
2407 // transforms.
2408
[email protected]2c7c6702013-03-26 03:14:052409 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2410 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322411 gfx::Transform layer_to_surface_transform;
2412
2413 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2414 // degrees, should be fully contained in the render surface.
2415 layer_to_surface_transform.MakeIdentity();
2416 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052417 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322418 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2419 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2420 EXPECT_RECT_EQ(expected, actual);
2421
2422 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2423 // degrees, but shifted to the side so only the right-half the layer would be
2424 // visible on the surface.
2425 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262426 SkMScalar half_width_of_rotated_layer =
2427 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322428 layer_to_surface_transform.MakeIdentity();
2429 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232430 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2431 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052432 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322433 actual = LayerTreeHostCommon::CalculateVisibleRect(
2434 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2435 EXPECT_RECT_EQ(expected, actual);
2436}
2437
[email protected]989386c2013-07-18 21:37:232438TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322439 // Test the calculateVisibleRect() function works correctly when the layer has
2440 // a perspective projection onto the target surface.
2441
[email protected]2c7c6702013-03-26 03:14:052442 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2443 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322444 gfx::Transform layer_to_surface_transform;
2445
2446 // Case 1: Even though the layer is twice as large as the surface, due to
2447 // perspective foreshortening, the layer will fit fully in the surface when
2448 // its translated more than the perspective amount.
2449 layer_to_surface_transform.MakeIdentity();
2450
2451 // The following sequence of transforms applies the perspective about the
2452 // center of the surface.
2453 layer_to_surface_transform.Translate(50.0, 50.0);
2454 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2455 layer_to_surface_transform.Translate(-50.0, -50.0);
2456
2457 // This translate places the layer in front of the surface's projection plane.
2458 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2459
[email protected]2c7c6702013-03-26 03:14:052460 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322461 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2462 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2463 EXPECT_RECT_EQ(expected, actual);
2464
2465 // Case 2: same projection as before, except that the layer is also translated
2466 // to the side, so that only the right half of the layer should be visible.
2467 //
2468 // Explanation of expected result: The perspective ratio is (z distance
2469 // between layer and camera origin) / (z distance between projection plane and
2470 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2471 // move a layer by translating -50 units in projected surface units (so that
2472 // only half of it is visible), then we would need to translate by (-36 / 9) *
2473 // -50 == -200 in the layer's units.
2474 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232475 expected = gfx::Rect(gfx::Point(50, -50),
2476 gfx::Size(100, 200)); // The right half of the layer's
2477 // bounding rect.
[email protected]fb661802013-03-25 01:59:322478 actual = LayerTreeHostCommon::CalculateVisibleRect(
2479 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2480 EXPECT_RECT_EQ(expected, actual);
2481}
2482
[email protected]989386c2013-07-18 21:37:232483TEST_F(LayerTreeHostCommonTest,
2484 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322485 // There is currently no explicit concept of an orthographic projection plane
2486 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2487 // are technically behind the surface in an orthographic world should not be
2488 // clipped when they are flattened to the surface.
2489
[email protected]2c7c6702013-03-26 03:14:052490 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2491 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322492 gfx::Transform layer_to_surface_transform;
2493
2494 // This sequence of transforms effectively rotates the layer about the y-axis
2495 // at the center of the layer.
2496 layer_to_surface_transform.MakeIdentity();
2497 layer_to_surface_transform.Translate(50.0, 0.0);
2498 layer_to_surface_transform.RotateAboutYAxis(45.0);
2499 layer_to_surface_transform.Translate(-50.0, 0.0);
2500
[email protected]2c7c6702013-03-26 03:14:052501 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322502 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2503 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2504 EXPECT_RECT_EQ(expected, actual);
2505}
2506
[email protected]989386c2013-07-18 21:37:232507TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322508 // Test the calculateVisibleRect() function works correctly when projecting a
2509 // surface onto a layer, but the layer is partially behind the camera (not
2510 // just behind the projection plane). In this case, the cartesian coordinates
2511 // may seem to be valid, but actually they are not. The visible rect needs to
2512 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2513 // converting to cartesian coordinates.
2514
[email protected]2c7c6702013-03-26 03:14:052515 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232516 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322517 gfx::Transform layer_to_surface_transform;
2518
2519 // The layer is positioned so that the right half of the layer should be in
2520 // front of the camera, while the other half is behind the surface's
2521 // projection plane. The following sequence of transforms applies the
2522 // perspective and rotation about the center of the layer.
2523 layer_to_surface_transform.MakeIdentity();
2524 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2525 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2526 layer_to_surface_transform.RotateAboutYAxis(45.0);
2527
2528 // Sanity check that this transform does indeed cause w < 0 when applying the
2529 // transform, otherwise this code is not testing the intended scenario.
2530 bool clipped;
2531 MathUtil::MapQuad(layer_to_surface_transform,
2532 gfx::QuadF(gfx::RectF(layer_content_rect)),
2533 &clipped);
2534 ASSERT_TRUE(clipped);
2535
2536 int expected_x_position = 0;
2537 int expected_width = 10;
2538 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2539 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2540 EXPECT_EQ(expected_x_position, actual.x());
2541 EXPECT_EQ(expected_width, actual.width());
2542}
2543
[email protected]989386c2013-07-18 21:37:232544TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322545 // To determine visible rect in layer space, there needs to be an
2546 // un-projection from surface space to layer space. When the original
2547 // transform was a perspective projection that was clipped, it returns a rect
2548 // that encloses the clipped bounds. Un-projecting this new rect may require
2549 // clipping again.
2550
2551 // This sequence of transforms causes one corner of the layer to protrude
2552 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232553 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2554 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322555 gfx::Transform layer_to_surface_transform;
2556 layer_to_surface_transform.MakeIdentity();
2557 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2558 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2559 layer_to_surface_transform.RotateAboutYAxis(45.0);
2560 layer_to_surface_transform.RotateAboutXAxis(80.0);
2561
2562 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2563 // code is not testing the intended scenario.
2564 bool clipped;
2565 gfx::RectF clipped_rect =
2566 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2567 MathUtil::ProjectQuad(
2568 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2569 ASSERT_TRUE(clipped);
2570
2571 // Only the corner of the layer is not visible on the surface because of being
2572 // clipped. But, the net result of rounding visible region to an axis-aligned
2573 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052574 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322575 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2576 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2577 EXPECT_RECT_EQ(expected, actual);
2578}
2579
[email protected]989386c2013-07-18 21:37:232580TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322581 scoped_refptr<Layer> root = Layer::Create();
2582 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2583 make_scoped_refptr(new LayerWithForcedDrawsContent());
2584 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2585 make_scoped_refptr(new LayerWithForcedDrawsContent());
2586 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2587 make_scoped_refptr(new LayerWithForcedDrawsContent());
2588 root->AddChild(child1);
2589 root->AddChild(child2);
2590 root->AddChild(child3);
2591
[email protected]d600df7d2013-08-03 02:34:282592 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2593 host->SetRootLayer(root);
2594
[email protected]fb661802013-03-25 01:59:322595 gfx::Transform identity_matrix;
2596 SetLayerPropertiesForTesting(root.get(),
2597 identity_matrix,
[email protected]a2566412014-06-05 03:14:202598 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322599 gfx::PointF(),
2600 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572601 true,
[email protected]fb661802013-03-25 01:59:322602 false);
2603 SetLayerPropertiesForTesting(child1.get(),
2604 identity_matrix,
[email protected]a2566412014-06-05 03:14:202605 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322606 gfx::PointF(),
2607 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572608 true,
[email protected]fb661802013-03-25 01:59:322609 false);
2610 SetLayerPropertiesForTesting(child2.get(),
2611 identity_matrix,
[email protected]a2566412014-06-05 03:14:202612 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322613 gfx::PointF(75.f, 75.f),
2614 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572615 true,
[email protected]fb661802013-03-25 01:59:322616 false);
2617 SetLayerPropertiesForTesting(child3.get(),
2618 identity_matrix,
[email protected]a2566412014-06-05 03:14:202619 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322620 gfx::PointF(125.f, 125.f),
2621 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572622 true,
[email protected]fb661802013-03-25 01:59:322623 false);
2624
2625 ExecuteCalculateDrawProperties(root.get());
2626
2627 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2628 root->render_surface()->DrawableContentRect());
2629 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2630
2631 // Layers that do not draw content should have empty visible_content_rects.
2632 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2633
2634 // layer visible_content_rects are clipped by their target surface.
2635 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2636 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
2637 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
2638
2639 // layer drawable_content_rects are not clipped.
2640 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2641 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2642 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2643}
2644
[email protected]989386c2013-07-18 21:37:232645TEST_F(LayerTreeHostCommonTest,
2646 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:322647 scoped_refptr<Layer> root = Layer::Create();
2648 scoped_refptr<Layer> child = Layer::Create();
2649 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
2650 make_scoped_refptr(new LayerWithForcedDrawsContent());
2651 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
2652 make_scoped_refptr(new LayerWithForcedDrawsContent());
2653 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
2654 make_scoped_refptr(new LayerWithForcedDrawsContent());
2655 root->AddChild(child);
2656 child->AddChild(grand_child1);
2657 child->AddChild(grand_child2);
2658 child->AddChild(grand_child3);
2659
[email protected]d600df7d2013-08-03 02:34:282660 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2661 host->SetRootLayer(root);
2662
[email protected]fb661802013-03-25 01:59:322663 gfx::Transform identity_matrix;
2664 SetLayerPropertiesForTesting(root.get(),
2665 identity_matrix,
[email protected]a2566412014-06-05 03:14:202666 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322667 gfx::PointF(),
2668 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572669 true,
[email protected]fb661802013-03-25 01:59:322670 false);
2671 SetLayerPropertiesForTesting(child.get(),
2672 identity_matrix,
[email protected]a2566412014-06-05 03:14:202673 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322674 gfx::PointF(),
2675 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572676 true,
[email protected]fb661802013-03-25 01:59:322677 false);
2678 SetLayerPropertiesForTesting(grand_child1.get(),
2679 identity_matrix,
[email protected]a2566412014-06-05 03:14:202680 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322681 gfx::PointF(5.f, 5.f),
2682 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572683 true,
[email protected]fb661802013-03-25 01:59:322684 false);
2685 SetLayerPropertiesForTesting(grand_child2.get(),
2686 identity_matrix,
[email protected]a2566412014-06-05 03:14:202687 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322688 gfx::PointF(75.f, 75.f),
2689 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572690 true,
[email protected]fb661802013-03-25 01:59:322691 false);
2692 SetLayerPropertiesForTesting(grand_child3.get(),
2693 identity_matrix,
[email protected]a2566412014-06-05 03:14:202694 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322695 gfx::PointF(125.f, 125.f),
2696 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572697 true,
[email protected]fb661802013-03-25 01:59:322698 false);
2699
2700 child->SetMasksToBounds(true);
2701 ExecuteCalculateDrawProperties(root.get());
2702
2703 ASSERT_FALSE(child->render_surface());
2704
2705 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2706 root->render_surface()->DrawableContentRect());
2707 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2708
2709 // Layers that do not draw content should have empty visible content rects.
2710 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2711 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
2712
2713 // All grandchild visible content rects should be clipped by child.
2714 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
2715 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
2716 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
2717
2718 // All grandchild DrawableContentRects should also be clipped by child.
2719 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
2720 grand_child1->drawable_content_rect());
2721 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
2722 grand_child2->drawable_content_rect());
2723 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2724}
2725
[email protected]989386c2013-07-18 21:37:232726TEST_F(LayerTreeHostCommonTest,
2727 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322728 scoped_refptr<Layer> root = Layer::Create();
2729 scoped_refptr<Layer> render_surface1 = Layer::Create();
2730 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2731 make_scoped_refptr(new LayerWithForcedDrawsContent());
2732 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2733 make_scoped_refptr(new LayerWithForcedDrawsContent());
2734 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2735 make_scoped_refptr(new LayerWithForcedDrawsContent());
2736 root->AddChild(render_surface1);
2737 render_surface1->AddChild(child1);
2738 render_surface1->AddChild(child2);
2739 render_surface1->AddChild(child3);
2740
[email protected]d600df7d2013-08-03 02:34:282741 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2742 host->SetRootLayer(root);
2743
[email protected]fb661802013-03-25 01:59:322744 gfx::Transform identity_matrix;
2745 SetLayerPropertiesForTesting(root.get(),
2746 identity_matrix,
[email protected]a2566412014-06-05 03:14:202747 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322748 gfx::PointF(),
2749 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572750 true,
[email protected]fb661802013-03-25 01:59:322751 false);
2752 SetLayerPropertiesForTesting(render_surface1.get(),
2753 identity_matrix,
[email protected]a2566412014-06-05 03:14:202754 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322755 gfx::PointF(),
2756 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572757 true,
[email protected]fb661802013-03-25 01:59:322758 false);
2759 SetLayerPropertiesForTesting(child1.get(),
2760 identity_matrix,
[email protected]a2566412014-06-05 03:14:202761 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322762 gfx::PointF(5.f, 5.f),
2763 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572764 true,
[email protected]fb661802013-03-25 01:59:322765 false);
2766 SetLayerPropertiesForTesting(child2.get(),
2767 identity_matrix,
[email protected]a2566412014-06-05 03:14:202768 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322769 gfx::PointF(75.f, 75.f),
2770 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572771 true,
[email protected]fb661802013-03-25 01:59:322772 false);
2773 SetLayerPropertiesForTesting(child3.get(),
2774 identity_matrix,
[email protected]a2566412014-06-05 03:14:202775 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322776 gfx::PointF(125.f, 125.f),
2777 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572778 true,
[email protected]fb661802013-03-25 01:59:322779 false);
2780
2781 render_surface1->SetForceRenderSurface(true);
2782 ExecuteCalculateDrawProperties(root.get());
2783
2784 ASSERT_TRUE(render_surface1->render_surface());
2785
2786 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2787 root->render_surface()->DrawableContentRect());
2788 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2789
2790 // Layers that do not draw content should have empty visible content rects.
2791 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2792 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2793 render_surface1->visible_content_rect());
2794
2795 // An unclipped surface grows its DrawableContentRect to include all drawable
2796 // regions of the subtree.
2797 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
2798 render_surface1->render_surface()->DrawableContentRect());
2799
2800 // All layers that draw content into the unclipped surface are also unclipped.
2801 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2802 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
2803 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
2804
2805 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2806 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2807 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2808}
2809
[email protected]989386c2013-07-18 21:37:232810TEST_F(LayerTreeHostCommonTest,
2811 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:472812 scoped_refptr<Layer> root = Layer::Create();
2813 scoped_refptr<LayerWithForcedDrawsContent> child =
2814 make_scoped_refptr(new LayerWithForcedDrawsContent());
2815 root->AddChild(child);
2816
[email protected]d600df7d2013-08-03 02:34:282817 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2818 host->SetRootLayer(root);
2819
[email protected]630ddad2013-08-16 03:01:322820 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:472821 gfx::Transform identity_matrix;
2822 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:322823 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:472824
2825 SetLayerPropertiesForTesting(root.get(),
2826 identity_matrix,
[email protected]a2566412014-06-05 03:14:202827 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:472828 gfx::PointF(),
2829 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572830 true,
[email protected]451107a32013-04-10 05:12:472831 false);
2832 SetLayerPropertiesForTesting(child.get(),
2833 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202834 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:472835 gfx::PointF(5.f, 5.f),
2836 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572837 true,
[email protected]451107a32013-04-10 05:12:472838 false);
2839
2840 ExecuteCalculateDrawProperties(root.get());
2841
2842 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2843 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322844
[email protected]08bdf1b2014-04-16 23:23:292845 // Case 2: a matrix with flattened z, uninvertible and not visible according
2846 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:322847 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:262848 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322849 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2850
2851 SetLayerPropertiesForTesting(child.get(),
2852 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202853 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:322854 gfx::PointF(5.f, 5.f),
2855 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572856 true,
[email protected]630ddad2013-08-16 03:01:322857 false);
2858
2859 ExecuteCalculateDrawProperties(root.get());
2860
[email protected]08bdf1b2014-04-16 23:23:292861 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2862 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322863
[email protected]08bdf1b2014-04-16 23:23:292864 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:322865 uninvertible_matrix.MakeIdentity();
2866 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:262867 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322868 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2869
2870 SetLayerPropertiesForTesting(child.get(),
2871 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202872 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:322873 gfx::PointF(5.f, 5.f),
2874 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572875 true,
[email protected]630ddad2013-08-16 03:01:322876 false);
2877
2878 ExecuteCalculateDrawProperties(root.get());
2879
2880 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:292881 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:472882}
2883
[email protected]989386c2013-07-18 21:37:232884TEST_F(LayerTreeHostCommonTest,
[email protected]e43c68b2014-05-01 05:10:362885 SingularTransformDoesNotPreventClearingDrawProperties) {
2886 scoped_refptr<Layer> root = Layer::Create();
2887 scoped_refptr<LayerWithForcedDrawsContent> child =
2888 make_scoped_refptr(new LayerWithForcedDrawsContent());
2889 root->AddChild(child);
2890
2891 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2892 host->SetRootLayer(root);
2893
2894 gfx::Transform identity_matrix;
2895 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2896 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2897
2898 SetLayerPropertiesForTesting(root.get(),
2899 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202900 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:362901 gfx::PointF(),
2902 gfx::Size(100, 100),
2903 true,
2904 false);
2905 SetLayerPropertiesForTesting(child.get(),
2906 identity_matrix,
[email protected]a2566412014-06-05 03:14:202907 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:362908 gfx::PointF(5.f, 5.f),
2909 gfx::Size(50, 50),
2910 true,
2911 false);
2912
2913 child->draw_properties().sorted_for_recursion = true;
2914
2915 TransformOperations start_transform_operations;
2916 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
2917
2918 TransformOperations end_transform_operations;
2919 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
2920
2921 AddAnimatedTransformToLayer(
2922 root.get(), 10.0, start_transform_operations, end_transform_operations);
2923
2924 EXPECT_TRUE(root->TransformIsAnimating());
2925
2926 ExecuteCalculateDrawProperties(root.get());
2927
2928 EXPECT_FALSE(child->draw_properties().sorted_for_recursion);
2929}
2930
2931TEST_F(LayerTreeHostCommonTest,
[email protected]8dbc85c2014-05-03 03:21:062932 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
2933 scoped_refptr<Layer> root = Layer::Create();
2934
2935 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2936 host->SetRootLayer(root);
2937
2938 gfx::Transform identity_matrix;
2939 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2940 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2941
2942 SetLayerPropertiesForTesting(root.get(),
2943 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202944 gfx::Point3F(),
[email protected]8dbc85c2014-05-03 03:21:062945 gfx::PointF(),
2946 gfx::Size(100, 100),
2947 true,
2948 false);
2949
2950 root->draw_properties().sorted_for_recursion = true;
2951
2952 EXPECT_FALSE(root->TransformIsAnimating());
2953
2954 ExecuteCalculateDrawProperties(root.get());
2955
2956 EXPECT_FALSE(root->draw_properties().sorted_for_recursion);
2957}
2958
2959TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:232960 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322961 scoped_refptr<Layer> root = Layer::Create();
2962 scoped_refptr<Layer> render_surface1 = Layer::Create();
2963 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2964 make_scoped_refptr(new LayerWithForcedDrawsContent());
2965 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2966 make_scoped_refptr(new LayerWithForcedDrawsContent());
2967 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2968 make_scoped_refptr(new LayerWithForcedDrawsContent());
2969 root->AddChild(render_surface1);
2970 render_surface1->AddChild(child1);
2971 render_surface1->AddChild(child2);
2972 render_surface1->AddChild(child3);
2973
[email protected]d600df7d2013-08-03 02:34:282974 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2975 host->SetRootLayer(root);
2976
[email protected]fb661802013-03-25 01:59:322977 gfx::Transform identity_matrix;
2978 SetLayerPropertiesForTesting(root.get(),
2979 identity_matrix,
[email protected]a2566412014-06-05 03:14:202980 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322981 gfx::PointF(),
2982 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572983 true,
[email protected]fb661802013-03-25 01:59:322984 false);
2985 SetLayerPropertiesForTesting(render_surface1.get(),
2986 identity_matrix,
[email protected]a2566412014-06-05 03:14:202987 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322988 gfx::PointF(),
2989 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572990 true,
[email protected]fb661802013-03-25 01:59:322991 false);
2992 SetLayerPropertiesForTesting(child1.get(),
2993 identity_matrix,
[email protected]a2566412014-06-05 03:14:202994 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322995 gfx::PointF(5.f, 5.f),
2996 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572997 true,
[email protected]fb661802013-03-25 01:59:322998 false);
2999 SetLayerPropertiesForTesting(child2.get(),
3000 identity_matrix,
[email protected]a2566412014-06-05 03:14:203001 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323002 gfx::PointF(75.f, 75.f),
3003 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573004 true,
[email protected]fb661802013-03-25 01:59:323005 false);
3006 SetLayerPropertiesForTesting(child3.get(),
3007 identity_matrix,
[email protected]a2566412014-06-05 03:14:203008 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323009 gfx::PointF(125.f, 125.f),
3010 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573011 true,
[email protected]fb661802013-03-25 01:59:323012 false);
3013
3014 root->SetMasksToBounds(true);
3015 render_surface1->SetForceRenderSurface(true);
3016 ExecuteCalculateDrawProperties(root.get());
3017
3018 ASSERT_TRUE(render_surface1->render_surface());
3019
3020 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3021 root->render_surface()->DrawableContentRect());
3022 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3023
3024 // Layers that do not draw content should have empty visible content rects.
3025 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3026 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3027 render_surface1->visible_content_rect());
3028
3029 // A clipped surface grows its DrawableContentRect to include all drawable
3030 // regions of the subtree, but also gets clamped by the ancestor's clip.
3031 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3032 render_surface1->render_surface()->DrawableContentRect());
3033
3034 // All layers that draw content into the surface have their visible content
3035 // rect clipped by the surface clip rect.
3036 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3037 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
3038 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3039
3040 // But the DrawableContentRects are unclipped.
3041 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3042 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3043 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3044}
3045
[email protected]989386c2013-07-18 21:37:233046TEST_F(LayerTreeHostCommonTest,
3047 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323048 // Check that clipping does not propagate down surfaces.
3049 scoped_refptr<Layer> root = Layer::Create();
3050 scoped_refptr<Layer> render_surface1 = Layer::Create();
3051 scoped_refptr<Layer> render_surface2 = Layer::Create();
3052 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3053 make_scoped_refptr(new LayerWithForcedDrawsContent());
3054 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3055 make_scoped_refptr(new LayerWithForcedDrawsContent());
3056 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3057 make_scoped_refptr(new LayerWithForcedDrawsContent());
3058 root->AddChild(render_surface1);
3059 render_surface1->AddChild(render_surface2);
3060 render_surface2->AddChild(child1);
3061 render_surface2->AddChild(child2);
3062 render_surface2->AddChild(child3);
3063
[email protected]d600df7d2013-08-03 02:34:283064 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3065 host->SetRootLayer(root);
3066
[email protected]fb661802013-03-25 01:59:323067 gfx::Transform identity_matrix;
3068 SetLayerPropertiesForTesting(root.get(),
3069 identity_matrix,
[email protected]a2566412014-06-05 03:14:203070 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323071 gfx::PointF(),
3072 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573073 true,
[email protected]fb661802013-03-25 01:59:323074 false);
3075 SetLayerPropertiesForTesting(render_surface1.get(),
3076 identity_matrix,
[email protected]a2566412014-06-05 03:14:203077 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323078 gfx::PointF(),
3079 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573080 true,
[email protected]fb661802013-03-25 01:59:323081 false);
3082 SetLayerPropertiesForTesting(render_surface2.get(),
3083 identity_matrix,
[email protected]a2566412014-06-05 03:14:203084 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323085 gfx::PointF(),
3086 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573087 true,
[email protected]fb661802013-03-25 01:59:323088 false);
3089 SetLayerPropertiesForTesting(child1.get(),
3090 identity_matrix,
[email protected]a2566412014-06-05 03:14:203091 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323092 gfx::PointF(5.f, 5.f),
3093 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573094 true,
[email protected]fb661802013-03-25 01:59:323095 false);
3096 SetLayerPropertiesForTesting(child2.get(),
3097 identity_matrix,
[email protected]a2566412014-06-05 03:14:203098 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323099 gfx::PointF(75.f, 75.f),
3100 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573101 true,
[email protected]fb661802013-03-25 01:59:323102 false);
3103 SetLayerPropertiesForTesting(child3.get(),
3104 identity_matrix,
[email protected]a2566412014-06-05 03:14:203105 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323106 gfx::PointF(125.f, 125.f),
3107 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573108 true,
[email protected]fb661802013-03-25 01:59:323109 false);
3110
3111 root->SetMasksToBounds(true);
3112 render_surface1->SetForceRenderSurface(true);
3113 render_surface2->SetForceRenderSurface(true);
3114 ExecuteCalculateDrawProperties(root.get());
3115
3116 ASSERT_TRUE(render_surface1->render_surface());
3117 ASSERT_TRUE(render_surface2->render_surface());
3118
3119 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3120 root->render_surface()->DrawableContentRect());
3121 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3122
3123 // Layers that do not draw content should have empty visible content rects.
3124 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3125 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3126 render_surface1->visible_content_rect());
3127 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3128 render_surface2->visible_content_rect());
3129
3130 // A clipped surface grows its DrawableContentRect to include all drawable
3131 // regions of the subtree, but also gets clamped by the ancestor's clip.
3132 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3133 render_surface1->render_surface()->DrawableContentRect());
3134
3135 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3136 // is only implicitly clipped by render_surface1's content rect. So,
3137 // render_surface2 grows to enclose all drawable content of its subtree.
3138 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3139 render_surface2->render_surface()->DrawableContentRect());
3140
3141 // All layers that draw content into render_surface2 think they are unclipped.
3142 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3143 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3144 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
3145
3146 // DrawableContentRects are also unclipped.
3147 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3148 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3149 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3150}
3151
[email protected]989386c2013-07-18 21:37:233152TEST_F(LayerTreeHostCommonTest,
3153 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323154 // Layers that have non-axis aligned bounds (due to transforms) have an
3155 // expanded, axis-aligned DrawableContentRect and visible content rect.
3156
3157 scoped_refptr<Layer> root = Layer::Create();
3158 scoped_refptr<Layer> render_surface1 = Layer::Create();
3159 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3160 make_scoped_refptr(new LayerWithForcedDrawsContent());
3161 root->AddChild(render_surface1);
3162 render_surface1->AddChild(child1);
3163
[email protected]d600df7d2013-08-03 02:34:283164 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3165 host->SetRootLayer(root);
3166
[email protected]fb661802013-03-25 01:59:323167 gfx::Transform identity_matrix;
3168 gfx::Transform child_rotation;
3169 child_rotation.Rotate(45.0);
3170 SetLayerPropertiesForTesting(root.get(),
3171 identity_matrix,
[email protected]a2566412014-06-05 03:14:203172 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323173 gfx::PointF(),
3174 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573175 true,
[email protected]fb661802013-03-25 01:59:323176 false);
3177 SetLayerPropertiesForTesting(render_surface1.get(),
3178 identity_matrix,
[email protected]a2566412014-06-05 03:14:203179 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323180 gfx::PointF(),
3181 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573182 true,
[email protected]fb661802013-03-25 01:59:323183 false);
3184 SetLayerPropertiesForTesting(child1.get(),
3185 child_rotation,
[email protected]a2566412014-06-05 03:14:203186 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323187 gfx::PointF(25.f, 25.f),
3188 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573189 true,
[email protected]fb661802013-03-25 01:59:323190 false);
3191
3192 render_surface1->SetForceRenderSurface(true);
3193 ExecuteCalculateDrawProperties(root.get());
3194
3195 ASSERT_TRUE(render_surface1->render_surface());
3196
3197 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3198 root->render_surface()->DrawableContentRect());
3199 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3200
3201 // Layers that do not draw content should have empty visible content rects.
3202 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3203 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3204 render_surface1->visible_content_rect());
3205
3206 // The unclipped surface grows its DrawableContentRect to include all drawable
3207 // regions of the subtree.
3208 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3209 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263210 gfx::Rect(50 - diagonal_radius,
3211 50 - diagonal_radius,
3212 diagonal_radius * 2,
3213 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323214 EXPECT_RECT_EQ(expected_surface_drawable_content,
3215 render_surface1->render_surface()->DrawableContentRect());
3216
3217 // All layers that draw content into the unclipped surface are also unclipped.
3218 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3219 EXPECT_RECT_EQ(expected_surface_drawable_content,
3220 child1->drawable_content_rect());
3221}
3222
[email protected]989386c2013-07-18 21:37:233223TEST_F(LayerTreeHostCommonTest,
3224 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323225 // Layers that have non-axis aligned bounds (due to transforms) have an
3226 // expanded, axis-aligned DrawableContentRect and visible content rect.
3227
3228 scoped_refptr<Layer> root = Layer::Create();
3229 scoped_refptr<Layer> render_surface1 = Layer::Create();
3230 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3231 make_scoped_refptr(new LayerWithForcedDrawsContent());
3232 root->AddChild(render_surface1);
3233 render_surface1->AddChild(child1);
3234
[email protected]d600df7d2013-08-03 02:34:283235 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3236 host->SetRootLayer(root);
3237
[email protected]fb661802013-03-25 01:59:323238 gfx::Transform identity_matrix;
3239 gfx::Transform child_rotation;
3240 child_rotation.Rotate(45.0);
3241 SetLayerPropertiesForTesting(root.get(),
3242 identity_matrix,
[email protected]a2566412014-06-05 03:14:203243 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323244 gfx::PointF(),
3245 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573246 true,
[email protected]fb661802013-03-25 01:59:323247 false);
3248 SetLayerPropertiesForTesting(render_surface1.get(),
3249 identity_matrix,
[email protected]a2566412014-06-05 03:14:203250 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323251 gfx::PointF(),
3252 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573253 true,
[email protected]fb661802013-03-25 01:59:323254 false);
[email protected]a2566412014-06-05 03:14:203255
[email protected]fb661802013-03-25 01:59:323256 SetLayerPropertiesForTesting(child1.get(),
3257 child_rotation,
[email protected]a2566412014-06-05 03:14:203258 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323259 gfx::PointF(25.f, 25.f),
3260 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573261 true,
[email protected]fb661802013-03-25 01:59:323262 false);
3263
3264 root->SetMasksToBounds(true);
3265 render_surface1->SetForceRenderSurface(true);
3266 ExecuteCalculateDrawProperties(root.get());
3267
3268 ASSERT_TRUE(render_surface1->render_surface());
3269
3270 // The clipped surface clamps the DrawableContentRect that encloses the
3271 // rotated layer.
3272 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263273 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3274 50 - diagonal_radius,
3275 diagonal_radius * 2,
3276 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323277 gfx::Rect expected_surface_drawable_content =
3278 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
3279 EXPECT_RECT_EQ(expected_surface_drawable_content,
3280 render_surface1->render_surface()->DrawableContentRect());
3281
3282 // On the clipped surface, only a quarter of the child1 is visible, but when
3283 // rotating it back to child1's content space, the actual enclosing rect ends
3284 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263285 //
3286 // Given the floating point math, this number is a little bit fuzzy.
[email protected]fb661802013-03-25 01:59:323287 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
3288
3289 // The child's DrawableContentRect is unclipped.
3290 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3291}
3292
[email protected]989386c2013-07-18 21:37:233293TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323294 MockContentLayerClient client;
3295
3296 scoped_refptr<Layer> root = Layer::Create();
3297 scoped_refptr<ContentLayer> render_surface1 =
3298 CreateDrawableContentLayer(&client);
3299 scoped_refptr<ContentLayer> render_surface2 =
3300 CreateDrawableContentLayer(&client);
3301 scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client);
3302 scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client);
3303 scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client);
3304 root->AddChild(render_surface1);
3305 render_surface1->AddChild(render_surface2);
3306 render_surface2->AddChild(child1);
3307 render_surface2->AddChild(child2);
3308 render_surface2->AddChild(child3);
3309
[email protected]d600df7d2013-08-03 02:34:283310 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3311 host->SetRootLayer(root);
3312
[email protected]fb661802013-03-25 01:59:323313 gfx::Transform identity_matrix;
3314 SetLayerPropertiesForTesting(root.get(),
3315 identity_matrix,
[email protected]a2566412014-06-05 03:14:203316 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323317 gfx::PointF(),
3318 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573319 true,
[email protected]fb661802013-03-25 01:59:323320 false);
3321 SetLayerPropertiesForTesting(render_surface1.get(),
3322 identity_matrix,
[email protected]a2566412014-06-05 03:14:203323 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323324 gfx::PointF(5.f, 5.f),
3325 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573326 true,
[email protected]fb661802013-03-25 01:59:323327 false);
3328 SetLayerPropertiesForTesting(render_surface2.get(),
3329 identity_matrix,
[email protected]a2566412014-06-05 03:14:203330 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323331 gfx::PointF(5.f, 5.f),
3332 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573333 true,
[email protected]fb661802013-03-25 01:59:323334 false);
3335 SetLayerPropertiesForTesting(child1.get(),
3336 identity_matrix,
[email protected]a2566412014-06-05 03:14:203337 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323338 gfx::PointF(5.f, 5.f),
3339 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573340 true,
[email protected]fb661802013-03-25 01:59:323341 false);
3342 SetLayerPropertiesForTesting(child2.get(),
3343 identity_matrix,
[email protected]a2566412014-06-05 03:14:203344 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323345 gfx::PointF(75.f, 75.f),
3346 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573347 true,
[email protected]fb661802013-03-25 01:59:323348 false);
3349 SetLayerPropertiesForTesting(child3.get(),
3350 identity_matrix,
[email protected]a2566412014-06-05 03:14:203351 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323352 gfx::PointF(125.f, 125.f),
3353 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573354 true,
[email protected]fb661802013-03-25 01:59:323355 false);
3356
3357 float device_scale_factor = 2.f;
3358
3359 root->SetMasksToBounds(true);
3360 render_surface1->SetForceRenderSurface(true);
3361 render_surface2->SetForceRenderSurface(true);
3362 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3363
3364 ASSERT_TRUE(render_surface1->render_surface());
3365 ASSERT_TRUE(render_surface2->render_surface());
3366
3367 // drawable_content_rects for all layers and surfaces are scaled by
3368 // device_scale_factor.
3369 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3370 root->render_surface()->DrawableContentRect());
3371 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3372 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3373 render_surface1->render_surface()->DrawableContentRect());
3374
3375 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3376 // is only implicitly clipped by render_surface1.
3377 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3378 render_surface2->render_surface()->DrawableContentRect());
3379
3380 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3381 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3382 child2->drawable_content_rect());
3383 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3384 child3->drawable_content_rect());
3385
3386 // The root layer does not actually draw content of its own.
3387 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3388
3389 // All layer visible content rects are expressed in content space of each
3390 // layer, so they are also scaled by the device_scale_factor.
3391 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8),
3392 render_surface1->visible_content_rect());
3393 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26),
3394 render_surface2->visible_content_rect());
3395 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect());
3396 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect());
3397 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect());
3398}
3399
[email protected]989386c2013-07-18 21:37:233400TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323401 // Verify the behavior of back-face culling when there are no preserve-3d
3402 // layers. Note that 3d transforms still apply in this case, but they are
3403 // "flattened" to each parent layer according to current W3C spec.
3404
3405 const gfx::Transform identity_matrix;
3406 scoped_refptr<Layer> parent = Layer::Create();
3407 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3408 make_scoped_refptr(new LayerWithForcedDrawsContent());
3409 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3410 make_scoped_refptr(new LayerWithForcedDrawsContent());
3411 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3412 make_scoped_refptr(new LayerWithForcedDrawsContent());
3413 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3414 make_scoped_refptr(new LayerWithForcedDrawsContent());
3415 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233416 front_facing_child_of_front_facing_surface =
3417 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323418 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233419 back_facing_child_of_front_facing_surface =
3420 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323421 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233422 front_facing_child_of_back_facing_surface =
3423 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323424 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233425 back_facing_child_of_back_facing_surface =
3426 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323427
3428 parent->AddChild(front_facing_child);
3429 parent->AddChild(back_facing_child);
3430 parent->AddChild(front_facing_surface);
3431 parent->AddChild(back_facing_surface);
3432 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3433 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3434 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3435 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3436
[email protected]d600df7d2013-08-03 02:34:283437 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3438 host->SetRootLayer(parent);
3439
[email protected]fb661802013-03-25 01:59:323440 // Nothing is double-sided
3441 front_facing_child->SetDoubleSided(false);
3442 back_facing_child->SetDoubleSided(false);
3443 front_facing_surface->SetDoubleSided(false);
3444 back_facing_surface->SetDoubleSided(false);
3445 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3446 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3447 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3448 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3449
3450 gfx::Transform backface_matrix;
3451 backface_matrix.Translate(50.0, 50.0);
3452 backface_matrix.RotateAboutYAxis(180.0);
3453 backface_matrix.Translate(-50.0, -50.0);
3454
3455 // Having a descendant and opacity will force these to have render surfaces.
3456 front_facing_surface->SetOpacity(0.5f);
3457 back_facing_surface->SetOpacity(0.5f);
3458
3459 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3460 // these layers should blindly use their own local transforms to determine
3461 // back-face culling.
3462 SetLayerPropertiesForTesting(parent.get(),
3463 identity_matrix,
[email protected]a2566412014-06-05 03:14:203464 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323465 gfx::PointF(),
3466 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573467 true,
[email protected]fb661802013-03-25 01:59:323468 false);
3469 SetLayerPropertiesForTesting(front_facing_child.get(),
3470 identity_matrix,
[email protected]a2566412014-06-05 03:14:203471 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323472 gfx::PointF(),
3473 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573474 true,
[email protected]fb661802013-03-25 01:59:323475 false);
3476 SetLayerPropertiesForTesting(back_facing_child.get(),
3477 backface_matrix,
[email protected]a2566412014-06-05 03:14:203478 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323479 gfx::PointF(),
3480 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573481 true,
[email protected]fb661802013-03-25 01:59:323482 false);
3483 SetLayerPropertiesForTesting(front_facing_surface.get(),
3484 identity_matrix,
[email protected]a2566412014-06-05 03:14:203485 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323486 gfx::PointF(),
3487 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573488 true,
[email protected]fb661802013-03-25 01:59:323489 false);
3490 SetLayerPropertiesForTesting(back_facing_surface.get(),
3491 backface_matrix,
[email protected]a2566412014-06-05 03:14:203492 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323493 gfx::PointF(),
3494 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573495 true,
[email protected]fb661802013-03-25 01:59:323496 false);
3497 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3498 identity_matrix,
[email protected]a2566412014-06-05 03:14:203499 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323500 gfx::PointF(),
3501 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573502 true,
[email protected]fb661802013-03-25 01:59:323503 false);
3504 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3505 backface_matrix,
[email protected]a2566412014-06-05 03:14:203506 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323507 gfx::PointF(),
3508 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573509 true,
[email protected]fb661802013-03-25 01:59:323510 false);
3511 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3512 identity_matrix,
[email protected]a2566412014-06-05 03:14:203513 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323514 gfx::PointF(),
3515 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573516 true,
[email protected]fb661802013-03-25 01:59:323517 false);
3518 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3519 backface_matrix,
[email protected]a2566412014-06-05 03:14:203520 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323521 gfx::PointF(),
3522 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573523 true,
[email protected]fb661802013-03-25 01:59:323524 false);
3525
[email protected]989386c2013-07-18 21:37:233526 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533527 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3528 parent.get(), parent->bounds(), &render_surface_layer_list);
3529 inputs.can_adjust_raster_scales = true;
3530 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323531
3532 // Verify which render surfaces were created.
3533 EXPECT_FALSE(front_facing_child->render_surface());
3534 EXPECT_FALSE(back_facing_child->render_surface());
3535 EXPECT_TRUE(front_facing_surface->render_surface());
3536 EXPECT_TRUE(back_facing_surface->render_surface());
3537 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3538 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3539 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3540 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3541
3542 // Verify the render_surface_layer_list.
3543 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233544 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3545 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323546 // Even though the back facing surface LAYER gets culled, the other
3547 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233548 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323549
3550 // Verify root surface's layer list.
3551 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233552 3u,
3553 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3554 EXPECT_EQ(front_facing_child->id(),
3555 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573556 ->render_surface()
3557 ->layer_list()
3558 .at(0)
3559 ->id());
[email protected]989386c2013-07-18 21:37:233560 EXPECT_EQ(front_facing_surface->id(),
3561 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573562 ->render_surface()
3563 ->layer_list()
3564 .at(1)
3565 ->id());
[email protected]989386c2013-07-18 21:37:233566 EXPECT_EQ(back_facing_surface->id(),
3567 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573568 ->render_surface()
3569 ->layer_list()
3570 .at(2)
3571 ->id());
[email protected]fb661802013-03-25 01:59:323572
3573 // Verify front_facing_surface's layer list.
3574 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233575 2u,
3576 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3577 EXPECT_EQ(front_facing_surface->id(),
3578 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573579 ->render_surface()
3580 ->layer_list()
3581 .at(0)
3582 ->id());
[email protected]989386c2013-07-18 21:37:233583 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3584 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573585 ->render_surface()
3586 ->layer_list()
3587 .at(1)
3588 ->id());
[email protected]fb661802013-03-25 01:59:323589
3590 // Verify back_facing_surface's layer list; its own layer should be culled
3591 // from the surface list.
3592 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233593 1u,
3594 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3595 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3596 render_surface_layer_list.at(2)
[email protected]56fffdd2014-02-11 19:50:573597 ->render_surface()
3598 ->layer_list()
3599 .at(0)
3600 ->id());
[email protected]fb661802013-03-25 01:59:323601}
3602
[email protected]989386c2013-07-18 21:37:233603TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323604 // Verify the behavior of back-face culling when preserves-3d transform style
3605 // is used.
3606
3607 const gfx::Transform identity_matrix;
3608 scoped_refptr<Layer> parent = Layer::Create();
3609 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3610 make_scoped_refptr(new LayerWithForcedDrawsContent());
3611 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3612 make_scoped_refptr(new LayerWithForcedDrawsContent());
3613 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3614 make_scoped_refptr(new LayerWithForcedDrawsContent());
3615 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3616 make_scoped_refptr(new LayerWithForcedDrawsContent());
3617 scoped_refptr<LayerWithForcedDrawsContent>
3618 front_facing_child_of_front_facing_surface =
3619 make_scoped_refptr(new LayerWithForcedDrawsContent());
3620 scoped_refptr<LayerWithForcedDrawsContent>
3621 back_facing_child_of_front_facing_surface =
3622 make_scoped_refptr(new LayerWithForcedDrawsContent());
3623 scoped_refptr<LayerWithForcedDrawsContent>
3624 front_facing_child_of_back_facing_surface =
3625 make_scoped_refptr(new LayerWithForcedDrawsContent());
3626 scoped_refptr<LayerWithForcedDrawsContent>
3627 back_facing_child_of_back_facing_surface =
3628 make_scoped_refptr(new LayerWithForcedDrawsContent());
3629 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3630 make_scoped_refptr(new LayerWithForcedDrawsContent());
3631 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3632 make_scoped_refptr(new LayerWithForcedDrawsContent());
3633
3634 parent->AddChild(front_facing_child);
3635 parent->AddChild(back_facing_child);
3636 parent->AddChild(front_facing_surface);
3637 parent->AddChild(back_facing_surface);
3638 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3639 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3640 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3641 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3642
[email protected]d600df7d2013-08-03 02:34:283643 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3644 host->SetRootLayer(parent);
3645
[email protected]fb661802013-03-25 01:59:323646 // Nothing is double-sided
3647 front_facing_child->SetDoubleSided(false);
3648 back_facing_child->SetDoubleSided(false);
3649 front_facing_surface->SetDoubleSided(false);
3650 back_facing_surface->SetDoubleSided(false);
3651 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3652 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3653 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3654 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3655
3656 gfx::Transform backface_matrix;
3657 backface_matrix.Translate(50.0, 50.0);
3658 backface_matrix.RotateAboutYAxis(180.0);
3659 backface_matrix.Translate(-50.0, -50.0);
3660
3661 // Opacity will not force creation of render surfaces in this case because of
3662 // the preserve-3d transform style. Instead, an example of when a surface
3663 // would be created with preserve-3d is when there is a replica layer.
3664 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3665 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3666
3667 // Each surface creates its own new 3d rendering context (as defined by W3C
3668 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3669 // rendering context should use the transform with respect to that context.
3670 // This 3d rendering context occurs when (a) parent's transform style is flat
3671 // and (b) the layer's transform style is preserve-3d.
3672 SetLayerPropertiesForTesting(parent.get(),
3673 identity_matrix,
[email protected]a2566412014-06-05 03:14:203674 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323675 gfx::PointF(),
3676 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573677 true,
[email protected]fb661802013-03-25 01:59:323678 false); // parent transform style is flat.
3679 SetLayerPropertiesForTesting(front_facing_child.get(),
3680 identity_matrix,
[email protected]a2566412014-06-05 03:14:203681 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323682 gfx::PointF(),
3683 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573684 true,
[email protected]fb661802013-03-25 01:59:323685 false);
3686 SetLayerPropertiesForTesting(back_facing_child.get(),
3687 backface_matrix,
[email protected]a2566412014-06-05 03:14:203688 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323689 gfx::PointF(),
3690 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573691 true,
[email protected]fb661802013-03-25 01:59:323692 false);
[email protected]56fffdd2014-02-11 19:50:573693 // surface transform style is preserve-3d.
3694 SetLayerPropertiesForTesting(front_facing_surface.get(),
3695 identity_matrix,
[email protected]a2566412014-06-05 03:14:203696 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573697 gfx::PointF(),
3698 gfx::Size(100, 100),
3699 false,
3700 true);
3701 // surface transform style is preserve-3d.
3702 SetLayerPropertiesForTesting(back_facing_surface.get(),
3703 backface_matrix,
[email protected]a2566412014-06-05 03:14:203704 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573705 gfx::PointF(),
3706 gfx::Size(100, 100),
3707 false,
3708 true);
[email protected]fb661802013-03-25 01:59:323709 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3710 identity_matrix,
[email protected]a2566412014-06-05 03:14:203711 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323712 gfx::PointF(),
3713 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573714 true,
3715 true);
[email protected]fb661802013-03-25 01:59:323716 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3717 backface_matrix,
[email protected]a2566412014-06-05 03:14:203718 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323719 gfx::PointF(),
3720 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573721 true,
3722 true);
[email protected]fb661802013-03-25 01:59:323723 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3724 identity_matrix,
[email protected]a2566412014-06-05 03:14:203725 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323726 gfx::PointF(),
3727 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573728 true,
3729 true);
[email protected]fb661802013-03-25 01:59:323730 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3731 backface_matrix,
[email protected]a2566412014-06-05 03:14:203732 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323733 gfx::PointF(),
3734 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573735 true,
3736 true);
[email protected]fb661802013-03-25 01:59:323737
[email protected]989386c2013-07-18 21:37:233738 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533739 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3740 parent.get(), parent->bounds(), &render_surface_layer_list);
3741 inputs.can_adjust_raster_scales = true;
3742 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323743
3744 // Verify which render surfaces were created.
3745 EXPECT_FALSE(front_facing_child->render_surface());
3746 EXPECT_FALSE(back_facing_child->render_surface());
3747 EXPECT_TRUE(front_facing_surface->render_surface());
3748 EXPECT_FALSE(back_facing_surface->render_surface());
3749 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3750 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3751 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3752 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3753
3754 // Verify the render_surface_layer_list. The back-facing surface should be
3755 // culled.
3756 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233757 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3758 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323759
3760 // Verify root surface's layer list.
3761 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233762 2u,
3763 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3764 EXPECT_EQ(front_facing_child->id(),
3765 render_surface_layer_list.at(0)
3766 ->render_surface()->layer_list().at(0)->id());
3767 EXPECT_EQ(front_facing_surface->id(),
3768 render_surface_layer_list.at(0)
3769 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323770
3771 // Verify front_facing_surface's layer list.
3772 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233773 2u,
3774 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3775 EXPECT_EQ(front_facing_surface->id(),
3776 render_surface_layer_list.at(1)
3777 ->render_surface()->layer_list().at(0)->id());
3778 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3779 render_surface_layer_list.at(1)
3780 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323781}
3782
[email protected]989386c2013-07-18 21:37:233783TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323784 // Verify that layers are appropriately culled when their back face is showing
3785 // and they are not double sided, while animations are going on.
3786 //
3787 // Layers that are animating do not get culled on the main thread, as their
3788 // transforms should be treated as "unknown" so we can not be sure that their
3789 // back face is really showing.
3790 const gfx::Transform identity_matrix;
3791 scoped_refptr<Layer> parent = Layer::Create();
3792 scoped_refptr<LayerWithForcedDrawsContent> child =
3793 make_scoped_refptr(new LayerWithForcedDrawsContent());
3794 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3795 make_scoped_refptr(new LayerWithForcedDrawsContent());
3796 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3797 make_scoped_refptr(new LayerWithForcedDrawsContent());
3798 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3799 make_scoped_refptr(new LayerWithForcedDrawsContent());
3800 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3801 make_scoped_refptr(new LayerWithForcedDrawsContent());
3802
3803 parent->AddChild(child);
3804 parent->AddChild(animating_surface);
3805 animating_surface->AddChild(child_of_animating_surface);
3806 parent->AddChild(animating_child);
3807 parent->AddChild(child2);
3808
[email protected]d600df7d2013-08-03 02:34:283809 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3810 host->SetRootLayer(parent);
3811
[email protected]fb661802013-03-25 01:59:323812 // Nothing is double-sided
3813 child->SetDoubleSided(false);
3814 child2->SetDoubleSided(false);
3815 animating_surface->SetDoubleSided(false);
3816 child_of_animating_surface->SetDoubleSided(false);
3817 animating_child->SetDoubleSided(false);
3818
3819 gfx::Transform backface_matrix;
3820 backface_matrix.Translate(50.0, 50.0);
3821 backface_matrix.RotateAboutYAxis(180.0);
3822 backface_matrix.Translate(-50.0, -50.0);
3823
3824 // Make our render surface.
3825 animating_surface->SetForceRenderSurface(true);
3826
3827 // Animate the transform on the render surface.
3828 AddAnimatedTransformToController(
3829 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3830 // This is just an animating layer, not a surface.
3831 AddAnimatedTransformToController(
3832 animating_child->layer_animation_controller(), 10.0, 30, 0);
3833
3834 SetLayerPropertiesForTesting(parent.get(),
3835 identity_matrix,
[email protected]a2566412014-06-05 03:14:203836 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323837 gfx::PointF(),
3838 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573839 true,
[email protected]fb661802013-03-25 01:59:323840 false);
3841 SetLayerPropertiesForTesting(child.get(),
3842 backface_matrix,
[email protected]a2566412014-06-05 03:14:203843 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323844 gfx::PointF(),
3845 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573846 true,
[email protected]fb661802013-03-25 01:59:323847 false);
3848 SetLayerPropertiesForTesting(animating_surface.get(),
3849 backface_matrix,
[email protected]a2566412014-06-05 03:14:203850 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323851 gfx::PointF(),
3852 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573853 true,
[email protected]fb661802013-03-25 01:59:323854 false);
3855 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3856 backface_matrix,
[email protected]a2566412014-06-05 03:14:203857 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323858 gfx::PointF(),
3859 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573860 true,
[email protected]fb661802013-03-25 01:59:323861 false);
3862 SetLayerPropertiesForTesting(animating_child.get(),
3863 backface_matrix,
[email protected]a2566412014-06-05 03:14:203864 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323865 gfx::PointF(),
3866 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573867 true,
[email protected]fb661802013-03-25 01:59:323868 false);
3869 SetLayerPropertiesForTesting(child2.get(),
3870 identity_matrix,
[email protected]a2566412014-06-05 03:14:203871 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323872 gfx::PointF(),
3873 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573874 true,
[email protected]fb661802013-03-25 01:59:323875 false);
3876
[email protected]989386c2013-07-18 21:37:233877 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533878 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3879 parent.get(), parent->bounds(), &render_surface_layer_list);
3880 inputs.can_adjust_raster_scales = true;
3881 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323882
3883 EXPECT_FALSE(child->render_surface());
3884 EXPECT_TRUE(animating_surface->render_surface());
3885 EXPECT_FALSE(child_of_animating_surface->render_surface());
3886 EXPECT_FALSE(animating_child->render_surface());
3887 EXPECT_FALSE(child2->render_surface());
3888
3889 // Verify that the animating_child and child_of_animating_surface were not
3890 // culled, but that child was.
3891 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233892 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3893 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323894
3895 // The non-animating child be culled from the layer list for the parent render
3896 // surface.
3897 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233898 3u,
3899 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3900 EXPECT_EQ(animating_surface->id(),
3901 render_surface_layer_list.at(0)
3902 ->render_surface()->layer_list().at(0)->id());
3903 EXPECT_EQ(animating_child->id(),
3904 render_surface_layer_list.at(0)
3905 ->render_surface()->layer_list().at(1)->id());
3906 EXPECT_EQ(child2->id(),
3907 render_surface_layer_list.at(0)
3908 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:323909
3910 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233911 2u,
3912 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3913 EXPECT_EQ(animating_surface->id(),
3914 render_surface_layer_list.at(1)
3915 ->render_surface()->layer_list().at(0)->id());
3916 EXPECT_EQ(child_of_animating_surface->id(),
3917 render_surface_layer_list.at(1)
3918 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323919
3920 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
3921
3922 // The animating layers should have a visible content rect that represents the
3923 // area of the front face that is within the viewport.
3924 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053925 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:323926 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053927 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:323928 // And layers in the subtree of the animating layer should have valid visible
3929 // content rects also.
[email protected]989386c2013-07-18 21:37:233930 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
3931 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:323932}
3933
[email protected]989386c2013-07-18 21:37:233934TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:323935 BackFaceCullingWithPreserves3dForFlatteningSurface) {
3936 // Verify the behavior of back-face culling for a render surface that is
3937 // created when it flattens its subtree, and its parent has preserves-3d.
3938
3939 const gfx::Transform identity_matrix;
3940 scoped_refptr<Layer> parent = Layer::Create();
3941 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3942 make_scoped_refptr(new LayerWithForcedDrawsContent());
3943 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3944 make_scoped_refptr(new LayerWithForcedDrawsContent());
3945 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3946 make_scoped_refptr(new LayerWithForcedDrawsContent());
3947 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3948 make_scoped_refptr(new LayerWithForcedDrawsContent());
3949
3950 parent->AddChild(front_facing_surface);
3951 parent->AddChild(back_facing_surface);
3952 front_facing_surface->AddChild(child1);
3953 back_facing_surface->AddChild(child2);
3954
[email protected]d600df7d2013-08-03 02:34:283955 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3956 host->SetRootLayer(parent);
3957
[email protected]fb661802013-03-25 01:59:323958 // RenderSurfaces are not double-sided
3959 front_facing_surface->SetDoubleSided(false);
3960 back_facing_surface->SetDoubleSided(false);
3961
3962 gfx::Transform backface_matrix;
3963 backface_matrix.Translate(50.0, 50.0);
3964 backface_matrix.RotateAboutYAxis(180.0);
3965 backface_matrix.Translate(-50.0, -50.0);
3966
3967 SetLayerPropertiesForTesting(parent.get(),
3968 identity_matrix,
[email protected]a2566412014-06-05 03:14:203969 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323970 gfx::PointF(),
3971 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573972 false,
3973 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:323974 SetLayerPropertiesForTesting(front_facing_surface.get(),
3975 identity_matrix,
[email protected]a2566412014-06-05 03:14:203976 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323977 gfx::PointF(),
3978 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573979 true,
3980 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:323981 SetLayerPropertiesForTesting(back_facing_surface.get(),
3982 backface_matrix,
[email protected]a2566412014-06-05 03:14:203983 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323984 gfx::PointF(),
3985 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573986 true,
3987 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:323988 SetLayerPropertiesForTesting(child1.get(),
3989 identity_matrix,
[email protected]a2566412014-06-05 03:14:203990 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323991 gfx::PointF(),
3992 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573993 true,
[email protected]fb661802013-03-25 01:59:323994 false);
3995 SetLayerPropertiesForTesting(child2.get(),
3996 identity_matrix,
[email protected]a2566412014-06-05 03:14:203997 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323998 gfx::PointF(),
3999 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574000 true,
[email protected]fb661802013-03-25 01:59:324001 false);
4002
[email protected]56fffdd2014-02-11 19:50:574003 front_facing_surface->SetIs3dSorted(true);
4004 back_facing_surface->SetIs3dSorted(true);
4005
[email protected]989386c2013-07-18 21:37:234006 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534007 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4008 parent.get(), parent->bounds(), &render_surface_layer_list);
4009 inputs.can_adjust_raster_scales = true;
4010 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324011
4012 // Verify which render surfaces were created.
4013 EXPECT_TRUE(front_facing_surface->render_surface());
4014 EXPECT_FALSE(
4015 back_facing_surface->render_surface()); // because it should be culled
4016 EXPECT_FALSE(child1->render_surface());
4017 EXPECT_FALSE(child2->render_surface());
4018
4019 // Verify the render_surface_layer_list. The back-facing surface should be
4020 // culled.
4021 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234022 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4023 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324024
4025 // Verify root surface's layer list.
4026 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234027 1u,
4028 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4029 EXPECT_EQ(front_facing_surface->id(),
4030 render_surface_layer_list.at(0)
4031 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324032
4033 // Verify front_facing_surface's layer list.
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(front_facing_surface->id(),
4038 render_surface_layer_list.at(1)
4039 ->render_surface()->layer_list().at(0)->id());
4040 EXPECT_EQ(child1->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
[email protected]fb661802013-03-25 01:59:324045class NoScaleContentLayer : public ContentLayer {
4046 public:
4047 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
4048 return make_scoped_refptr(new NoScaleContentLayer(client));
4049 }
[email protected]94f206c12012-08-25 00:09:144050
[email protected]fb661802013-03-25 01:59:324051 virtual void CalculateContentsScale(float ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:064052 float device_scale_factor,
4053 float page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:224054 float maximum_animation_contents_scale,
[email protected]fb661802013-03-25 01:59:324055 bool animating_transform_to_screen,
4056 float* contents_scale_x,
4057 float* contents_scale_y,
4058 gfx::Size* content_bounds) OVERRIDE {
4059 // Skip over the ContentLayer to the base Layer class.
4060 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:064061 device_scale_factor,
4062 page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:224063 maximum_animation_contents_scale,
[email protected]fb661802013-03-25 01:59:324064 animating_transform_to_screen,
4065 contents_scale_x,
4066 contents_scale_y,
4067 content_bounds);
4068 }
[email protected]94f206c12012-08-25 00:09:144069
[email protected]fb661802013-03-25 01:59:324070 protected:
4071 explicit NoScaleContentLayer(ContentLayerClient* client)
4072 : ContentLayer(client) {}
4073 virtual ~NoScaleContentLayer() {}
[email protected]518ee582012-10-24 18:29:444074};
4075
[email protected]fb661802013-03-25 01:59:324076scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
4077 ContentLayerClient* delegate) {
4078 scoped_refptr<NoScaleContentLayer> to_return =
4079 NoScaleContentLayer::Create(delegate);
4080 to_return->SetIsDrawable(true);
4081 return to_return;
[email protected]518ee582012-10-24 18:29:444082}
4083
[email protected]989386c2013-07-18 21:37:234084TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324085 // Verify draw and screen space transforms of layers not in a surface.
4086 MockContentLayerClient delegate;
4087 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:144088
[email protected]fb661802013-03-25 01:59:324089 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4090 SetLayerPropertiesForTesting(parent.get(),
4091 identity_matrix,
[email protected]a2566412014-06-05 03:14:204092 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324093 gfx::PointF(),
4094 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574095 false,
[email protected]fb661802013-03-25 01:59:324096 true);
[email protected]94f206c12012-08-25 00:09:144097
[email protected]fb661802013-03-25 01:59:324098 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
4099 SetLayerPropertiesForTesting(child.get(),
4100 identity_matrix,
[email protected]a2566412014-06-05 03:14:204101 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324102 gfx::PointF(2.f, 2.f),
4103 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574104 false,
[email protected]fb661802013-03-25 01:59:324105 true);
[email protected]94f206c12012-08-25 00:09:144106
[email protected]fb661802013-03-25 01:59:324107 scoped_refptr<ContentLayer> child_empty =
4108 CreateDrawableContentLayer(&delegate);
4109 SetLayerPropertiesForTesting(child_empty.get(),
4110 identity_matrix,
[email protected]a2566412014-06-05 03:14:204111 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324112 gfx::PointF(2.f, 2.f),
4113 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574114 false,
[email protected]fb661802013-03-25 01:59:324115 true);
[email protected]f89f5632012-11-14 23:34:454116
[email protected]fb661802013-03-25 01:59:324117 scoped_refptr<NoScaleContentLayer> child_no_scale =
4118 CreateNoScaleDrawableContentLayer(&delegate);
4119 SetLayerPropertiesForTesting(child_no_scale.get(),
4120 identity_matrix,
[email protected]a2566412014-06-05 03:14:204121 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324122 gfx::PointF(2.f, 2.f),
4123 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574124 false,
[email protected]fb661802013-03-25 01:59:324125 true);
[email protected]94f206c12012-08-25 00:09:144126
[email protected]fb661802013-03-25 01:59:324127 parent->AddChild(child);
4128 parent->AddChild(child_empty);
4129 parent->AddChild(child_no_scale);
[email protected]94f206c12012-08-25 00:09:144130
[email protected]d600df7d2013-08-03 02:34:284131 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4132 host->SetRootLayer(parent);
4133
[email protected]fb661802013-03-25 01:59:324134 float device_scale_factor = 2.5f;
4135 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:144136
[email protected]7aad55f2013-07-26 11:25:534137 RenderSurfaceLayerList render_surface_layer_list;
4138 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4139 parent.get(), parent->bounds(), &render_surface_layer_list);
4140 inputs.device_scale_factor = device_scale_factor;
4141 inputs.page_scale_factor = page_scale_factor;
4142 inputs.can_adjust_raster_scales = true;
4143 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444144
[email protected]fb661802013-03-25 01:59:324145 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4146 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4147 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4148 child_empty);
4149 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]94f206c12012-08-25 00:09:144150
[email protected]fb661802013-03-25 01:59:324151 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:144152
[email protected]fb661802013-03-25 01:59:324153 // Verify parent transforms
4154 gfx::Transform expected_parent_transform;
4155 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4156 parent->screen_space_transform());
4157 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4158 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:144159
[email protected]fb661802013-03-25 01:59:324160 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054161 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:144162
[email protected]fb661802013-03-25 01:59:324163 gfx::RectF parent_draw_rect =
4164 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4165 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4166 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:144167
[email protected]2c7c6702013-03-26 03:14:054168 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324169 expected_parent_draw_rect.Scale(device_scale_factor);
4170 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4171 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144172
[email protected]fb661802013-03-25 01:59:324173 // Verify child and child_empty transforms. They should match.
4174 gfx::Transform expected_child_transform;
4175 expected_child_transform.Translate(
4176 device_scale_factor * child->position().x(),
4177 device_scale_factor * child->position().y());
4178 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4179 child->draw_transform());
4180 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4181 child->screen_space_transform());
4182 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4183 child_empty->draw_transform());
4184 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4185 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144186
[email protected]fb661802013-03-25 01:59:324187 // Verify results of transformed child and child_empty rects. They should
4188 // match.
[email protected]2c7c6702013-03-26 03:14:054189 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:144190
[email protected]fb661802013-03-25 01:59:324191 gfx::RectF child_draw_rect =
4192 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4193 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4194 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:144195
[email protected]fb661802013-03-25 01:59:324196 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
4197 child_empty->draw_transform(), child_content_bounds);
4198 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
4199 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:454200
[email protected]fb661802013-03-25 01:59:324201 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
4202 expected_child_draw_rect.Scale(device_scale_factor);
4203 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4204 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
4205 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
4206 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144207
[email protected]fb661802013-03-25 01:59:324208 // Verify child_no_scale transforms
4209 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
4210 // All transforms operate on content rects. The child's content rect
4211 // incorporates device scale, but the child_no_scale does not; add it here.
4212 expected_child_no_scale_transform.Scale(device_scale_factor,
4213 device_scale_factor);
4214 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4215 child_no_scale->draw_transform());
4216 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4217 child_no_scale->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144218}
4219
[email protected]989386c2013-07-18 21:37:234220TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324221 // Verify draw and screen space transforms of layers in a surface.
4222 MockContentLayerClient delegate;
4223 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:094224
[email protected]fb661802013-03-25 01:59:324225 gfx::Transform perspective_matrix;
4226 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094227
[email protected]fb661802013-03-25 01:59:324228 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054229 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094230
[email protected]9781afa2013-07-17 23:15:324231 scoped_refptr<Layer> root = Layer::Create();
4232
[email protected]fb661802013-03-25 01:59:324233 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4234 SetLayerPropertiesForTesting(parent.get(),
4235 identity_matrix,
[email protected]a2566412014-06-05 03:14:204236 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324237 gfx::PointF(),
4238 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574239 false,
[email protected]fb661802013-03-25 01:59:324240 true);
[email protected]1b30e8e2012-12-21 02:59:094241
[email protected]fb661802013-03-25 01:59:324242 scoped_refptr<ContentLayer> perspective_surface =
4243 CreateDrawableContentLayer(&delegate);
4244 SetLayerPropertiesForTesting(perspective_surface.get(),
4245 perspective_matrix * scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204246 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324247 gfx::PointF(2.f, 2.f),
4248 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574249 false,
[email protected]fb661802013-03-25 01:59:324250 true);
[email protected]1b30e8e2012-12-21 02:59:094251
[email protected]fb661802013-03-25 01:59:324252 scoped_refptr<ContentLayer> scale_surface =
4253 CreateDrawableContentLayer(&delegate);
4254 SetLayerPropertiesForTesting(scale_surface.get(),
4255 scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204256 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324257 gfx::PointF(2.f, 2.f),
4258 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574259 false,
[email protected]fb661802013-03-25 01:59:324260 true);
[email protected]1b30e8e2012-12-21 02:59:094261
[email protected]fb661802013-03-25 01:59:324262 perspective_surface->SetForceRenderSurface(true);
4263 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:094264
[email protected]fb661802013-03-25 01:59:324265 parent->AddChild(perspective_surface);
4266 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:324267 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:094268
[email protected]d600df7d2013-08-03 02:34:284269 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4270 host->SetRootLayer(root);
4271
[email protected]fb661802013-03-25 01:59:324272 float device_scale_factor = 2.5f;
4273 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:094274
[email protected]7aad55f2013-07-26 11:25:534275 RenderSurfaceLayerList render_surface_layer_list;
4276 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4277 root.get(), parent->bounds(), &render_surface_layer_list);
4278 inputs.device_scale_factor = device_scale_factor;
4279 inputs.page_scale_factor = page_scale_factor;
4280 inputs.page_scale_application_layer = root;
4281 inputs.can_adjust_raster_scales = true;
4282 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:094283
[email protected]fb661802013-03-25 01:59:324284 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4285 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4286 perspective_surface);
4287 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4288 scale_surface);
[email protected]1b30e8e2012-12-21 02:59:094289
[email protected]fb661802013-03-25 01:59:324290 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:094291
[email protected]fb661802013-03-25 01:59:324292 gfx::Transform expected_parent_draw_transform;
4293 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
4294 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094295
[email protected]fb661802013-03-25 01:59:324296 // The scaled surface is rendered at its appropriate scale, and drawn 1:1
4297 // into its target.
4298 gfx::Transform expected_scale_surface_draw_transform;
4299 expected_scale_surface_draw_transform.Translate(
4300 device_scale_factor * page_scale_factor * scale_surface->position().x(),
4301 device_scale_factor * page_scale_factor * scale_surface->position().y());
[email protected]fb661802013-03-25 01:59:324302 EXPECT_TRANSFORMATION_MATRIX_EQ(
4303 expected_scale_surface_draw_transform,
4304 scale_surface->render_surface()->draw_transform());
[email protected]a52c6ff2013-05-04 05:33:154305 gfx::Transform expected_scale_surface_layer_draw_transform =
4306 scale_small_matrix;
[email protected]fb661802013-03-25 01:59:324307 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform,
4308 scale_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094309
[email protected]fb661802013-03-25 01:59:324310 // The scale for the perspective surface is not known, so it is rendered 1:1
4311 // with the screen, and then scaled during drawing.
4312 gfx::Transform expected_perspective_surface_draw_transform;
4313 expected_perspective_surface_draw_transform.Translate(
4314 device_scale_factor * page_scale_factor *
4315 perspective_surface->position().x(),
4316 device_scale_factor * page_scale_factor *
4317 perspective_surface->position().y());
4318 expected_perspective_surface_draw_transform.PreconcatTransform(
4319 perspective_matrix);
4320 expected_perspective_surface_draw_transform.PreconcatTransform(
4321 scale_small_matrix);
4322 gfx::Transform expected_perspective_surface_layer_draw_transform;
4323 EXPECT_TRANSFORMATION_MATRIX_EQ(
4324 expected_perspective_surface_draw_transform,
4325 perspective_surface->render_surface()->draw_transform());
4326 EXPECT_TRANSFORMATION_MATRIX_EQ(
4327 expected_perspective_surface_layer_draw_transform,
4328 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094329}
4330
[email protected]989386c2013-07-18 21:37:234331TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324332 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
4333 // Verify draw and screen space transforms of layers not in a surface.
4334 MockContentLayerClient delegate;
4335 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:474336
[email protected]fb661802013-03-25 01:59:324337 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4338 SetLayerPropertiesForTesting(parent.get(),
4339 identity_matrix,
[email protected]a2566412014-06-05 03:14:204340 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324341 gfx::PointF(),
4342 gfx::Size(133, 133),
[email protected]56fffdd2014-02-11 19:50:574343 false,
[email protected]fb661802013-03-25 01:59:324344 true);
[email protected]904e9132012-11-01 00:12:474345
[email protected]fb661802013-03-25 01:59:324346 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
4347 SetLayerPropertiesForTesting(child.get(),
4348 identity_matrix,
[email protected]a2566412014-06-05 03:14:204349 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324350 gfx::PointF(),
4351 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574352 false,
[email protected]fb661802013-03-25 01:59:324353 true);
[email protected]904e9132012-11-01 00:12:474354
[email protected]fb661802013-03-25 01:59:324355 scoped_refptr<NoScaleContentLayer> child_no_scale =
4356 CreateNoScaleDrawableContentLayer(&delegate);
4357 SetLayerPropertiesForTesting(child_no_scale.get(),
4358 identity_matrix,
[email protected]a2566412014-06-05 03:14:204359 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324360 gfx::PointF(),
4361 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574362 false,
[email protected]fb661802013-03-25 01:59:324363 true);
[email protected]904e9132012-11-01 00:12:474364
[email protected]fb661802013-03-25 01:59:324365 parent->AddChild(child);
4366 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:474367
[email protected]d600df7d2013-08-03 02:34:284368 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4369 host->SetRootLayer(parent);
4370
[email protected]fb661802013-03-25 01:59:324371 float device_scale_factor = 1.7f;
4372 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:474373
[email protected]7aad55f2013-07-26 11:25:534374 RenderSurfaceLayerList render_surface_layer_list;
4375 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4376 parent.get(), parent->bounds(), &render_surface_layer_list);
4377 inputs.device_scale_factor = device_scale_factor;
4378 inputs.page_scale_factor = page_scale_factor;
4379 inputs.page_scale_application_layer = parent.get();
4380 inputs.can_adjust_raster_scales = true;
4381 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:474382
[email protected]fb661802013-03-25 01:59:324383 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4384 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4385 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:474386
[email protected]fb661802013-03-25 01:59:324387 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:474388
[email protected]fb661802013-03-25 01:59:324389 // Verify parent transforms
4390 gfx::Transform expected_parent_transform;
4391 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4392 parent->screen_space_transform());
4393 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4394 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:474395
[email protected]fb661802013-03-25 01:59:324396 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054397 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:474398
[email protected]fb661802013-03-25 01:59:324399 gfx::RectF parent_draw_rect =
4400 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4401 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4402 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:474403
[email protected]2c7c6702013-03-26 03:14:054404 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324405 expected_parent_draw_rect.Scale(device_scale_factor);
4406 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
4407 expected_parent_draw_rect.set_height(
4408 ceil(expected_parent_draw_rect.height()));
4409 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4410 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474411
[email protected]fb661802013-03-25 01:59:324412 // Verify child transforms
4413 gfx::Transform expected_child_transform;
4414 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4415 child->draw_transform());
4416 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4417 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474418
[email protected]fb661802013-03-25 01:59:324419 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:054420 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:474421
[email protected]fb661802013-03-25 01:59:324422 gfx::RectF child_draw_rect =
4423 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4424 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4425 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:474426
[email protected]2c7c6702013-03-26 03:14:054427 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:324428 expected_child_draw_rect.Scale(device_scale_factor);
4429 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
4430 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
4431 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4432 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474433
[email protected]fb661802013-03-25 01:59:324434 // Verify child_no_scale transforms
4435 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
4436 // All transforms operate on content rects. The child's content rect
4437 // incorporates device scale, but the child_no_scale does not; add it here.
4438 expected_child_no_scale_transform.Scale(device_scale_factor,
4439 device_scale_factor);
4440 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4441 child_no_scale->draw_transform());
4442 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4443 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474444}
4445
[email protected]989386c2013-07-18 21:37:234446TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:324447 MockContentLayerClient delegate;
4448 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:444449
[email protected]fb661802013-03-25 01:59:324450 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264451 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324452 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:444453
[email protected]fb661802013-03-25 01:59:324454 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264455 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324456 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:444457
[email protected]35a99a12013-05-09 23:52:294458 scoped_refptr<Layer> root = Layer::Create();
4459 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:444460
[email protected]fb661802013-03-25 01:59:324461 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4462 SetLayerPropertiesForTesting(parent.get(),
4463 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204464 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324465 gfx::PointF(),
4466 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574467 false,
[email protected]fb661802013-03-25 01:59:324468 true);
[email protected]518ee582012-10-24 18:29:444469
[email protected]fb661802013-03-25 01:59:324470 scoped_refptr<ContentLayer> child_scale =
4471 CreateDrawableContentLayer(&delegate);
4472 SetLayerPropertiesForTesting(child_scale.get(),
4473 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204474 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324475 gfx::PointF(2.f, 2.f),
4476 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574477 false,
[email protected]fb661802013-03-25 01:59:324478 true);
[email protected]518ee582012-10-24 18:29:444479
[email protected]fb661802013-03-25 01:59:324480 scoped_refptr<ContentLayer> child_empty =
4481 CreateDrawableContentLayer(&delegate);
4482 SetLayerPropertiesForTesting(child_empty.get(),
4483 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204484 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324485 gfx::PointF(2.f, 2.f),
4486 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574487 false,
[email protected]fb661802013-03-25 01:59:324488 true);
[email protected]f89f5632012-11-14 23:34:454489
[email protected]fb661802013-03-25 01:59:324490 scoped_refptr<NoScaleContentLayer> child_no_scale =
4491 CreateNoScaleDrawableContentLayer(&delegate);
4492 SetLayerPropertiesForTesting(child_no_scale.get(),
4493 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204494 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324495 gfx::PointF(12.f, 12.f),
4496 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574497 false,
[email protected]fb661802013-03-25 01:59:324498 true);
[email protected]518ee582012-10-24 18:29:444499
[email protected]35a99a12013-05-09 23:52:294500 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:444501
[email protected]fb661802013-03-25 01:59:324502 parent->AddChild(child_scale);
4503 parent->AddChild(child_empty);
4504 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:444505
[email protected]d600df7d2013-08-03 02:34:284506 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4507 host->SetRootLayer(root);
4508
[email protected]fb661802013-03-25 01:59:324509 float device_scale_factor = 2.5f;
4510 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:444511
[email protected]989386c2013-07-18 21:37:234512 {
4513 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534514 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4515 root.get(), root->bounds(), &render_surface_layer_list);
4516 inputs.device_scale_factor = device_scale_factor;
4517 inputs.page_scale_factor = page_scale_factor;
4518 inputs.page_scale_application_layer = root.get();
4519 inputs.can_adjust_raster_scales = true;
4520 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444521
[email protected]989386c2013-07-18 21:37:234522 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4523 initial_parent_scale, parent);
4524 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4525 initial_parent_scale * initial_child_scale,
4526 child_scale);
4527 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4528 initial_parent_scale * initial_child_scale,
4529 child_empty);
4530 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:444531
[email protected]989386c2013-07-18 21:37:234532 // The parent is scaled up and shouldn't need to scale during draw. The
4533 // child that can scale its contents should also not need to scale during
4534 // draw. This shouldn't change if the child has empty bounds. The other
4535 // children should.
[email protected]803f6b52013-09-12 00:51:264536 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
4537 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
4538 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
4539 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
4540 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
4541 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234542 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
4543 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264544 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:234545 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264546 initial_parent_scale * initial_child_scale,
4547 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234548 }
[email protected]518ee582012-10-24 18:29:444549
[email protected]fb661802013-03-25 01:59:324550 // If the device_scale_factor or page_scale_factor changes, then it should be
4551 // updated using the initial transform as the raster scale.
4552 device_scale_factor = 2.25f;
4553 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:444554
[email protected]989386c2013-07-18 21:37:234555 {
4556 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534557 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4558 root.get(), root->bounds(), &render_surface_layer_list);
4559 inputs.device_scale_factor = device_scale_factor;
4560 inputs.page_scale_factor = page_scale_factor;
4561 inputs.page_scale_application_layer = root.get();
4562 inputs.can_adjust_raster_scales = true;
4563 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4564
4565 EXPECT_CONTENTS_SCALE_EQ(
4566 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:234567 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:534568 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:234569 child_scale);
4570 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4571 initial_parent_scale * initial_child_scale,
4572 child_empty);
4573 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4574 }
[email protected]d0518202013-02-08 02:06:494575
[email protected]fb661802013-03-25 01:59:324576 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:264577 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324578 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
4579 second_child_scale / initial_child_scale);
4580 child_scale->SetTransform(child_scale_matrix);
4581 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:494582
[email protected]989386c2013-07-18 21:37:234583 {
4584 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534585 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4586 root.get(), root->bounds(), &render_surface_layer_list);
4587 inputs.device_scale_factor = device_scale_factor;
4588 inputs.page_scale_factor = page_scale_factor;
4589 inputs.page_scale_application_layer = root.get();
4590 inputs.can_adjust_raster_scales = true;
4591 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494592
[email protected]989386c2013-07-18 21:37:234593 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4594 initial_parent_scale,
4595 parent);
4596 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4597 child_scale);
4598 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4599 child_empty);
4600 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4601 }
[email protected]d0518202013-02-08 02:06:494602
[email protected]fb661802013-03-25 01:59:324603 // If the device_scale_factor or page_scale_factor changes, then it should be
4604 // updated, but still using 1.0 as the raster scale.
4605 device_scale_factor = 2.75f;
4606 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:494607
[email protected]989386c2013-07-18 21:37:234608 {
4609 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534610 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4611 root.get(), root->bounds(), &render_surface_layer_list);
4612 inputs.device_scale_factor = device_scale_factor;
4613 inputs.page_scale_factor = page_scale_factor;
4614 inputs.page_scale_application_layer = root.get();
4615 inputs.can_adjust_raster_scales = true;
4616 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494617
[email protected]989386c2013-07-18 21:37:234618 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4619 initial_parent_scale,
4620 parent);
4621 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4622 child_scale);
4623 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4624 child_empty);
4625 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4626 }
[email protected]518ee582012-10-24 18:29:444627}
4628
[email protected]989386c2013-07-18 21:37:234629TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:294630 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:324631 MockContentLayerClient delegate;
4632 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:214633
[email protected]fb661802013-03-25 01:59:324634 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264635 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324636 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:214637
[email protected]fb661802013-03-25 01:59:324638 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264639 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324640 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:214641
[email protected]35a99a12013-05-09 23:52:294642 scoped_refptr<Layer> root = Layer::Create();
4643 root->SetBounds(gfx::Size(100, 100));
4644
[email protected]fb661802013-03-25 01:59:324645 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4646 SetLayerPropertiesForTesting(parent.get(),
4647 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204648 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324649 gfx::PointF(),
4650 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574651 false,
[email protected]fb661802013-03-25 01:59:324652 true);
[email protected]11ec92972012-11-10 03:06:214653
[email protected]fb661802013-03-25 01:59:324654 scoped_refptr<ContentLayer> child_scale =
4655 CreateDrawableContentLayer(&delegate);
4656 SetLayerPropertiesForTesting(child_scale.get(),
4657 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204658 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324659 gfx::PointF(2.f, 2.f),
4660 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574661 false,
[email protected]fb661802013-03-25 01:59:324662 true);
[email protected]11ec92972012-11-10 03:06:214663
[email protected]35a99a12013-05-09 23:52:294664 scoped_refptr<ContentLayer> child_empty =
4665 CreateDrawableContentLayer(&delegate);
4666 SetLayerPropertiesForTesting(child_empty.get(),
4667 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204668 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294669 gfx::PointF(2.f, 2.f),
4670 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574671 false,
[email protected]35a99a12013-05-09 23:52:294672 true);
4673
4674 scoped_refptr<NoScaleContentLayer> child_no_scale =
4675 CreateNoScaleDrawableContentLayer(&delegate);
4676 SetLayerPropertiesForTesting(child_no_scale.get(),
4677 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204678 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294679 gfx::PointF(12.f, 12.f),
4680 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574681 false,
[email protected]35a99a12013-05-09 23:52:294682 true);
4683
4684 root->AddChild(parent);
4685
4686 parent->AddChild(child_scale);
4687 parent->AddChild(child_empty);
4688 parent->AddChild(child_no_scale);
4689
[email protected]d600df7d2013-08-03 02:34:284690 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4691 host->SetRootLayer(root);
4692
[email protected]989386c2013-07-18 21:37:234693 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:294694
4695 float device_scale_factor = 2.5f;
4696 float page_scale_factor = 1.f;
4697
[email protected]7aad55f2013-07-26 11:25:534698 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4699 root.get(), root->bounds(), &render_surface_layer_list);
4700 inputs.device_scale_factor = device_scale_factor;
4701 inputs.page_scale_factor = page_scale_factor;
4702 inputs.page_scale_application_layer = root.get(),
4703 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:294704
4705 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4706 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4707 child_scale);
4708 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4709 child_empty);
4710 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4711
4712 // Since the transform scale does not affect contents scale, it should affect
4713 // the draw transform instead.
4714 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264715 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294716 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264717 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294718 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264719 child_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294720 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264721 child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294722 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264723 child_empty->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294724 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264725 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294726 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264727 initial_parent_scale * initial_child_scale,
4728 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294729 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264730 initial_parent_scale * initial_child_scale,
4731 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294732}
4733
[email protected]989386c2013-07-18 21:37:234734TEST_F(LayerTreeHostCommonTest, SmallContentsScale) {
[email protected]35a99a12013-05-09 23:52:294735 MockContentLayerClient delegate;
4736 gfx::Transform identity_matrix;
4737
4738 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264739 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294740 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4741
4742 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264743 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294744 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4745
4746 scoped_refptr<Layer> root = Layer::Create();
4747 root->SetBounds(gfx::Size(100, 100));
4748
4749 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4750 SetLayerPropertiesForTesting(parent.get(),
4751 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204752 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294753 gfx::PointF(),
4754 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574755 false,
[email protected]35a99a12013-05-09 23:52:294756 true);
4757
4758 scoped_refptr<ContentLayer> child_scale =
4759 CreateDrawableContentLayer(&delegate);
4760 SetLayerPropertiesForTesting(child_scale.get(),
4761 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204762 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294763 gfx::PointF(2.f, 2.f),
4764 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574765 false,
[email protected]35a99a12013-05-09 23:52:294766 true);
4767
4768 root->AddChild(parent);
4769
[email protected]fb661802013-03-25 01:59:324770 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:214771
[email protected]d600df7d2013-08-03 02:34:284772 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4773 host->SetRootLayer(root);
4774
[email protected]fb661802013-03-25 01:59:324775 float device_scale_factor = 2.5f;
4776 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214777
[email protected]989386c2013-07-18 21:37:234778 {
4779 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534780 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4781 root.get(), root->bounds(), &render_surface_layer_list);
4782 inputs.device_scale_factor = device_scale_factor;
4783 inputs.page_scale_factor = page_scale_factor;
4784 inputs.page_scale_application_layer = root.get();
4785 inputs.can_adjust_raster_scales = true;
4786 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:214787
[email protected]989386c2013-07-18 21:37:234788 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4789 initial_parent_scale,
4790 parent);
4791 // The child's scale is < 1, so we should not save and use that scale
4792 // factor.
4793 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1,
4794 child_scale);
4795 }
[email protected]11ec92972012-11-10 03:06:214796
[email protected]fb661802013-03-25 01:59:324797 // When chilld's total scale becomes >= 1, we should save and use that scale
4798 // factor.
4799 child_scale_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:264800 SkMScalar final_child_scale = 0.75;
[email protected]fb661802013-03-25 01:59:324801 child_scale_matrix.Scale(final_child_scale, final_child_scale);
4802 child_scale->SetTransform(child_scale_matrix);
[email protected]11ec92972012-11-10 03:06:214803
[email protected]989386c2013-07-18 21:37:234804 {
4805 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534806 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4807 root.get(), root->bounds(), &render_surface_layer_list);
4808 inputs.device_scale_factor = device_scale_factor;
4809 inputs.page_scale_factor = page_scale_factor;
4810 inputs.page_scale_application_layer = root.get();
4811 inputs.can_adjust_raster_scales = true;
4812 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:214813
[email protected]989386c2013-07-18 21:37:234814 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4815 initial_parent_scale,
4816 parent);
4817 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4818 initial_parent_scale * final_child_scale,
4819 child_scale);
4820 }
[email protected]11ec92972012-11-10 03:06:214821}
4822
[email protected]989386c2013-07-18 21:37:234823TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:324824 MockContentLayerClient delegate;
4825 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:444826
[email protected]fb661802013-03-25 01:59:324827 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264828 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:324829 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:444830
[email protected]fb661802013-03-25 01:59:324831 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264832 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:324833 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:444834
[email protected]35a99a12013-05-09 23:52:294835 scoped_refptr<Layer> root = Layer::Create();
4836 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:444837
[email protected]fb661802013-03-25 01:59:324838 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4839 SetLayerPropertiesForTesting(parent.get(),
4840 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204841 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324842 gfx::PointF(),
4843 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574844 false,
[email protected]fb661802013-03-25 01:59:324845 true);
[email protected]518ee582012-10-24 18:29:444846
[email protected]fb661802013-03-25 01:59:324847 scoped_refptr<ContentLayer> surface_scale =
4848 CreateDrawableContentLayer(&delegate);
4849 SetLayerPropertiesForTesting(surface_scale.get(),
4850 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204851 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324852 gfx::PointF(2.f, 2.f),
4853 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574854 false,
[email protected]fb661802013-03-25 01:59:324855 true);
[email protected]518ee582012-10-24 18:29:444856
[email protected]fb661802013-03-25 01:59:324857 scoped_refptr<ContentLayer> surface_scale_child_scale =
4858 CreateDrawableContentLayer(&delegate);
4859 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
4860 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204861 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324862 gfx::PointF(),
4863 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574864 false,
[email protected]fb661802013-03-25 01:59:324865 true);
[email protected]518ee582012-10-24 18:29:444866
[email protected]fb661802013-03-25 01:59:324867 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
4868 CreateNoScaleDrawableContentLayer(&delegate);
4869 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
4870 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204871 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324872 gfx::PointF(),
4873 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574874 false,
[email protected]fb661802013-03-25 01:59:324875 true);
[email protected]518ee582012-10-24 18:29:444876
[email protected]fb661802013-03-25 01:59:324877 scoped_refptr<NoScaleContentLayer> surface_no_scale =
4878 CreateNoScaleDrawableContentLayer(&delegate);
4879 SetLayerPropertiesForTesting(surface_no_scale.get(),
4880 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204881 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324882 gfx::PointF(12.f, 12.f),
4883 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574884 false,
[email protected]fb661802013-03-25 01:59:324885 true);
[email protected]518ee582012-10-24 18:29:444886
[email protected]fb661802013-03-25 01:59:324887 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
4888 CreateDrawableContentLayer(&delegate);
4889 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
4890 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204891 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324892 gfx::PointF(),
4893 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574894 false,
[email protected]fb661802013-03-25 01:59:324895 true);
[email protected]518ee582012-10-24 18:29:444896
[email protected]fb661802013-03-25 01:59:324897 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
4898 CreateNoScaleDrawableContentLayer(&delegate);
4899 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
4900 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204901 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324902 gfx::PointF(),
4903 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574904 false,
[email protected]fb661802013-03-25 01:59:324905 true);
[email protected]518ee582012-10-24 18:29:444906
[email protected]35a99a12013-05-09 23:52:294907 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:444908
[email protected]fb661802013-03-25 01:59:324909 parent->AddChild(surface_scale);
4910 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:444911
[email protected]fb661802013-03-25 01:59:324912 surface_scale->SetForceRenderSurface(true);
4913 surface_scale->AddChild(surface_scale_child_scale);
4914 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:444915
[email protected]fb661802013-03-25 01:59:324916 surface_no_scale->SetForceRenderSurface(true);
4917 surface_no_scale->AddChild(surface_no_scale_child_scale);
4918 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:444919
[email protected]d600df7d2013-08-03 02:34:284920 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4921 host->SetRootLayer(root);
4922
[email protected]803f6b52013-09-12 00:51:264923 SkMScalar device_scale_factor = 5;
4924 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:444925
[email protected]7aad55f2013-07-26 11:25:534926 RenderSurfaceLayerList render_surface_layer_list;
4927 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4928 root.get(), root->bounds(), &render_surface_layer_list);
4929 inputs.device_scale_factor = device_scale_factor;
4930 inputs.page_scale_factor = page_scale_factor;
4931 inputs.page_scale_application_layer = root.get();
4932 inputs.can_adjust_raster_scales = true;
4933 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4934
4935 EXPECT_CONTENTS_SCALE_EQ(
4936 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:194937 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:534938 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:324939 surface_scale);
4940 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
4941 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:324942 device_scale_factor * page_scale_factor * initial_parent_scale *
4943 initial_child_scale * initial_child_scale,
4944 surface_scale_child_scale);
4945 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
4946 EXPECT_CONTENTS_SCALE_EQ(
4947 device_scale_factor * page_scale_factor * initial_parent_scale *
4948 initial_child_scale * initial_child_scale,
4949 surface_no_scale_child_scale);
4950 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:444951
[email protected]fb661802013-03-25 01:59:324952 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:264953 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
4954 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:444955
[email protected]fb661802013-03-25 01:59:324956 // RenderSurfaces should always be 1:1 with their target.
4957 EXPECT_FLOAT_EQ(
4958 1.0,
[email protected]803f6b52013-09-12 00:51:264959 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:324960 EXPECT_FLOAT_EQ(
4961 1.0,
[email protected]803f6b52013-09-12 00:51:264962 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:444963
[email protected]fb661802013-03-25 01:59:324964 // The surface_scale can apply contents scale so the layer shouldn't need to
4965 // scale during draw.
[email protected]803f6b52013-09-12 00:51:264966 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
4967 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:444968
[email protected]fb661802013-03-25 01:59:324969 // The surface_scale_child_scale can apply contents scale so it shouldn't need
4970 // to scale during draw.
4971 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:264972 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:324973 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:264974 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:444975
[email protected]fb661802013-03-25 01:59:324976 // The surface_scale_child_no_scale can not apply contents scale, so it needs
4977 // to be scaled during draw.
4978 EXPECT_FLOAT_EQ(
4979 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:264980 initial_child_scale * initial_child_scale,
4981 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:324982 EXPECT_FLOAT_EQ(
4983 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:264984 initial_child_scale * initial_child_scale,
4985 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:444986
[email protected]fb661802013-03-25 01:59:324987 // RenderSurfaces should always be 1:1 with their target.
4988 EXPECT_FLOAT_EQ(
4989 1.0,
[email protected]803f6b52013-09-12 00:51:264990 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:324991 EXPECT_FLOAT_EQ(
4992 1.0,
[email protected]803f6b52013-09-12 00:51:264993 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:444994
[email protected]fb661802013-03-25 01:59:324995 // The surface_no_scale layer can not apply contents scale, so it needs to be
4996 // scaled during draw.
4997 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264998 initial_parent_scale * initial_child_scale,
4999 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325000 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:265001 initial_parent_scale * initial_child_scale,
5002 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445003
[email protected]fb661802013-03-25 01:59:325004 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5005 // to scale during draw.
5006 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265007 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325008 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265009 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445010
[email protected]fb661802013-03-25 01:59:325011 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5012 // to be scaled during draw.
5013 EXPECT_FLOAT_EQ(
5014 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265015 initial_child_scale * initial_child_scale,
5016 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325017 EXPECT_FLOAT_EQ(
5018 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265019 initial_child_scale * initial_child_scale,
5020 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295021}
[email protected]518ee582012-10-24 18:29:445022
[email protected]989386c2013-07-18 21:37:235023TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:295024 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
5025 MockContentLayerClient delegate;
5026 gfx::Transform identity_matrix;
5027
5028 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265029 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:295030 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
5031
5032 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265033 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:295034 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
5035
5036 scoped_refptr<Layer> root = Layer::Create();
5037 root->SetBounds(gfx::Size(100, 100));
5038
5039 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
5040 SetLayerPropertiesForTesting(parent.get(),
5041 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205042 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295043 gfx::PointF(),
5044 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575045 false,
[email protected]35a99a12013-05-09 23:52:295046 true);
5047
5048 scoped_refptr<ContentLayer> surface_scale =
5049 CreateDrawableContentLayer(&delegate);
5050 SetLayerPropertiesForTesting(surface_scale.get(),
5051 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205052 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295053 gfx::PointF(2.f, 2.f),
5054 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575055 false,
[email protected]35a99a12013-05-09 23:52:295056 true);
5057
5058 scoped_refptr<ContentLayer> surface_scale_child_scale =
5059 CreateDrawableContentLayer(&delegate);
5060 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
5061 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205062 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295063 gfx::PointF(),
5064 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575065 false,
[email protected]35a99a12013-05-09 23:52:295066 true);
5067
5068 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
5069 CreateNoScaleDrawableContentLayer(&delegate);
5070 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
5071 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205072 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295073 gfx::PointF(),
5074 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575075 false,
[email protected]35a99a12013-05-09 23:52:295076 true);
5077
5078 scoped_refptr<NoScaleContentLayer> surface_no_scale =
5079 CreateNoScaleDrawableContentLayer(&delegate);
5080 SetLayerPropertiesForTesting(surface_no_scale.get(),
5081 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205082 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295083 gfx::PointF(12.f, 12.f),
5084 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575085 false,
[email protected]35a99a12013-05-09 23:52:295086 true);
5087
5088 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
5089 CreateDrawableContentLayer(&delegate);
5090 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
5091 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205092 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295093 gfx::PointF(),
5094 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575095 false,
[email protected]35a99a12013-05-09 23:52:295096 true);
5097
5098 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
5099 CreateNoScaleDrawableContentLayer(&delegate);
5100 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
5101 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205102 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295103 gfx::PointF(),
5104 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575105 false,
[email protected]35a99a12013-05-09 23:52:295106 true);
5107
5108 root->AddChild(parent);
5109
5110 parent->AddChild(surface_scale);
5111 parent->AddChild(surface_no_scale);
5112
5113 surface_scale->SetForceRenderSurface(true);
5114 surface_scale->AddChild(surface_scale_child_scale);
5115 surface_scale->AddChild(surface_scale_child_no_scale);
5116
5117 surface_no_scale->SetForceRenderSurface(true);
5118 surface_no_scale->AddChild(surface_no_scale_child_scale);
5119 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
5120
[email protected]d600df7d2013-08-03 02:34:285121 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
5122 host->SetRootLayer(root);
5123
[email protected]989386c2013-07-18 21:37:235124 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:295125
[email protected]803f6b52013-09-12 00:51:265126 SkMScalar device_scale_factor = 5.0;
5127 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:535128 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5129 root.get(), root->bounds(), &render_surface_layer_list);
5130 inputs.device_scale_factor = device_scale_factor;
5131 inputs.page_scale_factor = page_scale_factor;
5132 inputs.page_scale_application_layer = root.get();
5133 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:295134
[email protected]35a99a12013-05-09 23:52:295135 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5136 parent);
5137 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5138 surface_scale);
5139 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
5140 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5141 surface_scale_child_scale);
5142 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
5143 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5144 surface_no_scale_child_scale);
5145 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
5146
5147 // The parent is scaled up during draw, since its contents are not scaled by
5148 // the transform hierarchy.
5149 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265150 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295151 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265152 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295153
5154 // The child surface is scaled up during draw since its subtree is not scaled
5155 // by the transform hierarchy.
5156 EXPECT_FLOAT_EQ(
5157 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265158 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295159 EXPECT_FLOAT_EQ(
5160 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265161 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295162
5163 // The surface_scale's RenderSurface is scaled during draw, so the layer does
5164 // not need to be scaled when drawing into its surface.
[email protected]803f6b52013-09-12 00:51:265165 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
5166 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445167
[email protected]35a99a12013-05-09 23:52:295168 // The surface_scale_child_scale is scaled when drawing into its surface,
5169 // since its content bounds are not scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:325170 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:295171 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265172 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325173 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:295174 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265175 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445176
[email protected]35a99a12013-05-09 23:52:295177 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
5178 // needs to be scaled by the device and page scale factors, along with the
5179 // transform hierarchy.
[email protected]fb661802013-03-25 01:59:325180 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:295181 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265182 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295183 EXPECT_FLOAT_EQ(
5184 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265185 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295186
5187 // The child surface is scaled up during draw since its subtree is not scaled
5188 // by the transform hierarchy.
5189 EXPECT_FLOAT_EQ(
5190 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265191 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325192 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:295193 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265194 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445195
[email protected]35a99a12013-05-09 23:52:295196 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5197 // be scaled by the device and page scale factors. Its surface is already
5198 // scaled by the transform hierarchy so those don't need to scale the layer's
5199 // drawing.
5200 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265201 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295202 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265203 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295204
5205 // The surface_no_scale_child_scale has its contents scaled by the page and
5206 // device scale factors, but needs to be scaled by the transform hierarchy
5207 // when drawing.
[email protected]fb661802013-03-25 01:59:325208 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:295209 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265210 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325211 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:295212 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265213 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295214
5215 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
5216 // needs to be scaled by the device and page scale factors. It also needs to
5217 // be scaled by any transform heirarchy below its target surface.
5218 EXPECT_FLOAT_EQ(
5219 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265220 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295221 EXPECT_FLOAT_EQ(
5222 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265223 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445224}
5225
[email protected]989386c2013-07-18 21:37:235226TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:325227 MockContentLayerClient delegate;
5228 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265229
[email protected]fb661802013-03-25 01:59:325230 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265231 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:325232 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:265233
[email protected]fb661802013-03-25 01:59:325234 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265235 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:325236 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:265237
[email protected]35a99a12013-05-09 23:52:295238 scoped_refptr<Layer> root = Layer::Create();
5239 root->SetBounds(gfx::Size(100, 100));
5240
[email protected]fb661802013-03-25 01:59:325241 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
5242 SetLayerPropertiesForTesting(parent.get(),
5243 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205244 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325245 gfx::PointF(),
5246 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575247 false,
[email protected]fb661802013-03-25 01:59:325248 true);
[email protected]6a9cff92012-11-08 11:53:265249
[email protected]fb661802013-03-25 01:59:325250 scoped_refptr<ContentLayer> child_scale =
5251 CreateDrawableContentLayer(&delegate);
5252 SetLayerPropertiesForTesting(child_scale.get(),
5253 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205254 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325255 gfx::PointF(2.f, 2.f),
5256 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575257 false,
[email protected]fb661802013-03-25 01:59:325258 true);
[email protected]6a9cff92012-11-08 11:53:265259
[email protected]35a99a12013-05-09 23:52:295260 root->AddChild(parent);
5261
[email protected]fb661802013-03-25 01:59:325262 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:265263
[email protected]d600df7d2013-08-03 02:34:285264 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
5265 host->SetRootLayer(root);
5266
[email protected]fb661802013-03-25 01:59:325267 // Now put an animating transform on child.
5268 int animation_id = AddAnimatedTransformToController(
5269 child_scale->layer_animation_controller(), 10.0, 30, 0);
[email protected]6a9cff92012-11-08 11:53:265270
[email protected]989386c2013-07-18 21:37:235271 {
5272 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535273 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5274 root.get(), root->bounds(), &render_surface_layer_list);
5275 inputs.can_adjust_raster_scales = true;
5276 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:265277
[email protected]989386c2013-07-18 21:37:235278 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
5279 // The layers with animating transforms should not compute a contents scale
5280 // other than 1 until they finish animating.
5281 EXPECT_CONTENTS_SCALE_EQ(1, child_scale);
5282 }
[email protected]6a9cff92012-11-08 11:53:265283
[email protected]fb661802013-03-25 01:59:325284 // Remove the animation, now it can save a raster scale.
5285 child_scale->layer_animation_controller()->RemoveAnimation(animation_id);
[email protected]6a9cff92012-11-08 11:53:265286
[email protected]989386c2013-07-18 21:37:235287 {
5288 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535289 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5290 root.get(), root->bounds(), &render_surface_layer_list);
5291 inputs.can_adjust_raster_scales = true;
5292 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:265293
[email protected]989386c2013-07-18 21:37:235294 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
5295 // The layers with animating transforms should not compute a contents scale
5296 // other than 1 until they finish animating.
5297 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale,
5298 child_scale);
5299 }
[email protected]6a9cff92012-11-08 11:53:265300}
5301
[email protected]7a5a9322014-02-25 12:54:575302TEST_F(LayerTreeHostCommonTest,
5303 ChangeInContentBoundsOrScaleTriggersPushProperties) {
5304 MockContentLayerClient delegate;
5305 scoped_refptr<Layer> root = Layer::Create();
5306 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate);
5307 root->AddChild(child);
5308
5309 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
5310 host->SetRootLayer(root);
5311
5312 gfx::Transform identity_matrix;
5313 SetLayerPropertiesForTesting(root.get(),
5314 identity_matrix,
[email protected]a2566412014-06-05 03:14:205315 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575316 gfx::PointF(),
5317 gfx::Size(100, 100),
5318 true,
5319 false);
5320 SetLayerPropertiesForTesting(child.get(),
5321 identity_matrix,
[email protected]a2566412014-06-05 03:14:205322 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575323 gfx::PointF(),
5324 gfx::Size(100, 100),
5325 true,
5326 false);
5327
5328 root->reset_needs_push_properties_for_testing();
5329 child->reset_needs_push_properties_for_testing();
5330
5331 // This will change both layers' content bounds.
5332 ExecuteCalculateDrawProperties(root.get());
5333 EXPECT_TRUE(root->needs_push_properties());
5334 EXPECT_TRUE(child->needs_push_properties());
5335
5336 root->reset_needs_push_properties_for_testing();
5337 child->reset_needs_push_properties_for_testing();
5338
5339 // This will change only the child layer's contents scale and content bounds,
5340 // since the root layer is not a ContentsScalingLayer.
5341 ExecuteCalculateDrawProperties(root.get(), 2.f);
5342 EXPECT_FALSE(root->needs_push_properties());
5343 EXPECT_TRUE(child->needs_push_properties());
5344
5345 root->reset_needs_push_properties_for_testing();
5346 child->reset_needs_push_properties_for_testing();
5347
5348 // This will not change either layer's contents scale or content bounds.
5349 ExecuteCalculateDrawProperties(root.get(), 2.f);
5350 EXPECT_FALSE(root->needs_push_properties());
5351 EXPECT_FALSE(child->needs_push_properties());
5352}
5353
[email protected]989386c2013-07-18 21:37:235354TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:325355 MockContentLayerClient delegate;
5356 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265357
[email protected]fb661802013-03-25 01:59:325358 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
5359 SetLayerPropertiesForTesting(parent.get(),
5360 identity_matrix,
[email protected]a2566412014-06-05 03:14:205361 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325362 gfx::PointF(),
5363 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575364 false,
[email protected]fb661802013-03-25 01:59:325365 true);
[email protected]94f206c12012-08-25 00:09:145366
[email protected]fb661802013-03-25 01:59:325367 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
5368 SetLayerPropertiesForTesting(child.get(),
5369 identity_matrix,
[email protected]a2566412014-06-05 03:14:205370 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325371 gfx::PointF(2.f, 2.f),
5372 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575373 false,
[email protected]fb661802013-03-25 01:59:325374 true);
[email protected]94f206c12012-08-25 00:09:145375
[email protected]fb661802013-03-25 01:59:325376 gfx::Transform replica_transform;
5377 replica_transform.Scale(1.0, -1.0);
5378 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
5379 SetLayerPropertiesForTesting(replica.get(),
5380 replica_transform,
[email protected]a2566412014-06-05 03:14:205381 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325382 gfx::PointF(2.f, 2.f),
5383 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575384 false,
[email protected]fb661802013-03-25 01:59:325385 true);
[email protected]94f206c12012-08-25 00:09:145386
[email protected]fb661802013-03-25 01:59:325387 // This layer should end up in the same surface as child, with the same draw
5388 // and screen space transforms.
5389 scoped_refptr<ContentLayer> duplicate_child_non_owner =
5390 CreateDrawableContentLayer(&delegate);
5391 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
5392 identity_matrix,
[email protected]a2566412014-06-05 03:14:205393 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325394 gfx::PointF(),
5395 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575396 false,
[email protected]fb661802013-03-25 01:59:325397 true);
[email protected]94f206c12012-08-25 00:09:145398
[email protected]fb661802013-03-25 01:59:325399 parent->AddChild(child);
5400 child->AddChild(duplicate_child_non_owner);
5401 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:145402
[email protected]d600df7d2013-08-03 02:34:285403 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
5404 host->SetRootLayer(parent);
5405
[email protected]989386c2013-07-18 21:37:235406 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145407
[email protected]fb661802013-03-25 01:59:325408 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:535409 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5410 parent.get(), parent->bounds(), &render_surface_layer_list);
5411 inputs.device_scale_factor = device_scale_factor;
5412 inputs.can_adjust_raster_scales = true;
5413 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145414
[email protected]fb661802013-03-25 01:59:325415 // We should have two render surfaces. The root's render surface and child's
5416 // render surface (it needs one because it has a replica layer).
5417 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:145418
[email protected]fb661802013-03-25 01:59:325419 gfx::Transform expected_parent_transform;
5420 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5421 parent->screen_space_transform());
5422 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5423 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:145424
[email protected]fb661802013-03-25 01:59:325425 gfx::Transform expected_draw_transform;
5426 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
5427 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:145428
[email protected]fb661802013-03-25 01:59:325429 gfx::Transform expected_screen_space_transform;
5430 expected_screen_space_transform.Translate(
5431 device_scale_factor * child->position().x(),
5432 device_scale_factor * child->position().y());
5433 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
5434 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145435
[email protected]fb661802013-03-25 01:59:325436 gfx::Transform expected_duplicate_child_draw_transform =
5437 child->draw_transform();
5438 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
5439 duplicate_child_non_owner->draw_transform());
5440 EXPECT_TRANSFORMATION_MATRIX_EQ(
5441 child->screen_space_transform(),
5442 duplicate_child_non_owner->screen_space_transform());
5443 EXPECT_RECT_EQ(child->drawable_content_rect(),
5444 duplicate_child_non_owner->drawable_content_rect());
5445 EXPECT_EQ(child->content_bounds(),
5446 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:145447
[email protected]fb661802013-03-25 01:59:325448 gfx::Transform expected_render_surface_draw_transform;
5449 expected_render_surface_draw_transform.Translate(
5450 device_scale_factor * child->position().x(),
5451 device_scale_factor * child->position().y());
5452 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
5453 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145454
[email protected]fb661802013-03-25 01:59:325455 gfx::Transform expected_surface_draw_transform;
5456 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
5457 device_scale_factor * 2.f);
5458 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
5459 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145460
[email protected]fb661802013-03-25 01:59:325461 gfx::Transform expected_surface_screen_space_transform;
5462 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
5463 device_scale_factor * 2.f);
5464 EXPECT_TRANSFORMATION_MATRIX_EQ(
5465 expected_surface_screen_space_transform,
5466 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145467
[email protected]fb661802013-03-25 01:59:325468 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265469 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
5470 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
5471 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325472 EXPECT_TRANSFORMATION_MATRIX_EQ(
5473 expected_replica_draw_transform,
5474 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:145475
[email protected]fb661802013-03-25 01:59:325476 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265477 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
5478 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
5479 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325480 EXPECT_TRANSFORMATION_MATRIX_EQ(
5481 expected_replica_screen_space_transform,
5482 child->render_surface()->replica_screen_space_transform());
5483 EXPECT_TRANSFORMATION_MATRIX_EQ(
5484 expected_replica_screen_space_transform,
5485 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:475486}
5487
[email protected]989386c2013-07-18 21:37:235488TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325489 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
5490 MockContentLayerClient delegate;
5491 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:475492
[email protected]fb661802013-03-25 01:59:325493 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
5494 SetLayerPropertiesForTesting(parent.get(),
5495 identity_matrix,
[email protected]a2566412014-06-05 03:14:205496 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325497 gfx::PointF(),
5498 gfx::Size(33, 31),
[email protected]56fffdd2014-02-11 19:50:575499 false,
[email protected]fb661802013-03-25 01:59:325500 true);
[email protected]904e9132012-11-01 00:12:475501
[email protected]fb661802013-03-25 01:59:325502 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
5503 SetLayerPropertiesForTesting(child.get(),
5504 identity_matrix,
[email protected]a2566412014-06-05 03:14:205505 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325506 gfx::PointF(),
5507 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575508 false,
[email protected]fb661802013-03-25 01:59:325509 true);
[email protected]904e9132012-11-01 00:12:475510
[email protected]fb661802013-03-25 01:59:325511 gfx::Transform replica_transform;
5512 replica_transform.Scale(1.0, -1.0);
5513 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
5514 SetLayerPropertiesForTesting(replica.get(),
5515 replica_transform,
[email protected]a2566412014-06-05 03:14:205516 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325517 gfx::PointF(),
5518 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575519 false,
[email protected]fb661802013-03-25 01:59:325520 true);
[email protected]904e9132012-11-01 00:12:475521
[email protected]fb661802013-03-25 01:59:325522 // This layer should end up in the same surface as child, with the same draw
5523 // and screen space transforms.
5524 scoped_refptr<ContentLayer> duplicate_child_non_owner =
5525 CreateDrawableContentLayer(&delegate);
5526 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
5527 identity_matrix,
[email protected]a2566412014-06-05 03:14:205528 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325529 gfx::PointF(),
5530 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575531 false,
[email protected]fb661802013-03-25 01:59:325532 true);
[email protected]904e9132012-11-01 00:12:475533
[email protected]fb661802013-03-25 01:59:325534 parent->AddChild(child);
5535 child->AddChild(duplicate_child_non_owner);
5536 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:475537
[email protected]d600df7d2013-08-03 02:34:285538 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
5539 host->SetRootLayer(parent);
5540
[email protected]873639e2013-07-24 19:56:315541 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:535542
5543 RenderSurfaceLayerList render_surface_layer_list;
5544 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5545 parent.get(), parent->bounds(), &render_surface_layer_list);
5546 inputs.device_scale_factor = device_scale_factor;
5547 inputs.can_adjust_raster_scales = true;
5548 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:475549
[email protected]fb661802013-03-25 01:59:325550 // We should have two render surfaces. The root's render surface and child's
5551 // render surface (it needs one because it has a replica layer).
5552 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:475553
[email protected]fb661802013-03-25 01:59:325554 gfx::Transform identity_transform;
[email protected]904e9132012-11-01 00:12:475555
[email protected]fb661802013-03-25 01:59:325556 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5557 parent->screen_space_transform());
5558 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform());
5559 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform());
5560 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5561 child->screen_space_transform());
5562 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5563 duplicate_child_non_owner->draw_transform());
5564 EXPECT_TRANSFORMATION_MATRIX_EQ(
5565 identity_transform, duplicate_child_non_owner->screen_space_transform());
5566 EXPECT_RECT_EQ(child->drawable_content_rect(),
5567 duplicate_child_non_owner->drawable_content_rect());
5568 EXPECT_EQ(child->content_bounds(),
5569 duplicate_child_non_owner->content_bounds());
[email protected]904e9132012-11-01 00:12:475570
[email protected]fb661802013-03-25 01:59:325571 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5572 child->render_surface()->draw_transform());
5573 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5574 child->render_surface()->draw_transform());
5575 EXPECT_TRANSFORMATION_MATRIX_EQ(
5576 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:475577
[email protected]fb661802013-03-25 01:59:325578 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265579 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325580 EXPECT_TRANSFORMATION_MATRIX_EQ(
5581 expected_replica_draw_transform,
5582 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:475583
[email protected]fb661802013-03-25 01:59:325584 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265585 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325586 EXPECT_TRANSFORMATION_MATRIX_EQ(
5587 expected_replica_screen_space_transform,
5588 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145589}
5590
[email protected]989386c2013-07-18 21:37:235591TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:325592 scoped_refptr<Layer> root = Layer::Create();
5593 scoped_refptr<Layer> child = Layer::Create();
5594 scoped_refptr<Layer> grand_child = Layer::Create();
5595 scoped_refptr<Layer> mask_layer = Layer::Create();
5596 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:145597
[email protected]fb661802013-03-25 01:59:325598 grand_child->SetReplicaLayer(replica_layer.get());
5599 child->AddChild(grand_child.get());
5600 child->SetMaskLayer(mask_layer.get());
5601 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:145602
[email protected]d600df7d2013-08-03 02:34:285603 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
5604 host->SetRootLayer(root);
5605
[email protected]fb661802013-03-25 01:59:325606 int nonexistent_id = -1;
5607 EXPECT_EQ(root,
5608 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
5609 EXPECT_EQ(child,
5610 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
5611 EXPECT_EQ(
5612 grand_child,
5613 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
5614 EXPECT_EQ(
5615 mask_layer,
5616 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
5617 EXPECT_EQ(
5618 replica_layer,
5619 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
5620 EXPECT_EQ(
5621 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:145622}
5623
[email protected]989386c2013-07-18 21:37:235624TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:325625 scoped_refptr<Layer> root = Layer::Create();
5626 scoped_refptr<Layer> child = Layer::Create();
5627 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
5628 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:575629
[email protected]fb661802013-03-25 01:59:325630 const gfx::Transform identity_matrix;
5631 SetLayerPropertiesForTesting(root.get(),
5632 identity_matrix,
[email protected]a2566412014-06-05 03:14:205633 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325634 gfx::PointF(),
5635 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575636 true,
[email protected]fb661802013-03-25 01:59:325637 false);
5638 SetLayerPropertiesForTesting(child.get(),
5639 identity_matrix,
[email protected]a2566412014-06-05 03:14:205640 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325641 gfx::PointF(),
5642 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575643 true,
[email protected]fb661802013-03-25 01:59:325644 false);
5645 SetLayerPropertiesForTesting(grand_child.get(),
5646 identity_matrix,
[email protected]a2566412014-06-05 03:14:205647 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325648 gfx::PointF(),
5649 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575650 true,
[email protected]fb661802013-03-25 01:59:325651 false);
[email protected]498ec6e0e2012-11-30 18:24:575652
[email protected]fb661802013-03-25 01:59:325653 root->AddChild(child);
5654 child->AddChild(grand_child);
5655 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:575656
[email protected]d600df7d2013-08-03 02:34:285657 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
5658 host->SetRootLayer(root);
5659
[email protected]fb661802013-03-25 01:59:325660 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:575661
[email protected]fb661802013-03-25 01:59:325662 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:575663}
5664
[email protected]989386c2013-07-18 21:37:235665TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:165666 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455667 TestSharedBitmapManager shared_bitmap_manager;
5668 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]f90fc412013-03-30 20:13:165669 host_impl.CreatePendingTree();
5670 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5671
5672 const gfx::Transform identity_matrix;
5673 SetLayerPropertiesForTesting(root.get(),
5674 identity_matrix,
[email protected]a2566412014-06-05 03:14:205675 gfx::Point3F(),
[email protected]f90fc412013-03-30 20:13:165676 gfx::PointF(),
5677 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575678 true,
[email protected]f90fc412013-03-30 20:13:165679 false);
5680 root->SetDrawsContent(true);
5681
5682 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
5683 SetLayerPropertiesForTesting(child.get(),
5684 identity_matrix,
[email protected]a2566412014-06-05 03:14:205685 gfx::Point3F(),
[email protected]f90fc412013-03-30 20:13:165686 gfx::PointF(),
5687 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575688 true,
[email protected]f90fc412013-03-30 20:13:165689 false);
5690 child->SetDrawsContent(true);
5691 child->SetOpacity(0.0f);
5692
5693 // Add opacity animation.
5694 AddOpacityTransitionToController(
5695 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
5696
5697 root->AddChild(child.Pass());
5698
[email protected]c0ae06c12013-06-24 18:32:195699 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535700 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5701 root.get(), root->bounds(), &render_surface_layer_list);
5702 inputs.can_adjust_raster_scales = true;
5703 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:165704
5705 // We should have one render surface and two layers. The child
5706 // layer should be included even though it is transparent.
5707 ASSERT_EQ(1u, render_surface_layer_list.size());
5708 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5709}
5710
[email protected]10aabcc32012-12-13 09:18:595711typedef std::tr1::tuple<bool, bool> LCDTextTestParam;
[email protected]989386c2013-07-18 21:37:235712class LCDTextTest
5713 : public LayerTreeHostCommonTestBase,
5714 public testing::TestWithParam<LCDTextTestParam> {
[email protected]fb661802013-03-25 01:59:325715 protected:
5716 virtual void SetUp() {
5717 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
[email protected]10aabcc32012-12-13 09:18:595718
[email protected]fb661802013-03-25 01:59:325719 root_ = Layer::Create();
5720 child_ = Layer::Create();
5721 grand_child_ = Layer::Create();
5722 child_->AddChild(grand_child_.get());
5723 root_->AddChild(child_.get());
[email protected]10aabcc32012-12-13 09:18:595724
[email protected]fb661802013-03-25 01:59:325725 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:305726 SetLayerPropertiesForTesting(root_.get(),
[email protected]fb661802013-03-25 01:59:325727 identity_matrix,
[email protected]a2566412014-06-05 03:14:205728 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325729 gfx::PointF(),
5730 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:575731 true,
[email protected]fb661802013-03-25 01:59:325732 false);
[email protected]22898ed2013-06-01 04:52:305733 SetLayerPropertiesForTesting(child_.get(),
[email protected]fb661802013-03-25 01:59:325734 identity_matrix,
[email protected]a2566412014-06-05 03:14:205735 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325736 gfx::PointF(),
5737 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:575738 true,
[email protected]fb661802013-03-25 01:59:325739 false);
[email protected]22898ed2013-06-01 04:52:305740 SetLayerPropertiesForTesting(grand_child_.get(),
[email protected]fb661802013-03-25 01:59:325741 identity_matrix,
[email protected]a2566412014-06-05 03:14:205742 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325743 gfx::PointF(),
5744 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:575745 true,
[email protected]fb661802013-03-25 01:59:325746 false);
[email protected]10aabcc32012-12-13 09:18:595747
[email protected]fb661802013-03-25 01:59:325748 child_->SetForceRenderSurface(std::tr1::get<1>(GetParam()));
[email protected]d600df7d2013-08-03 02:34:285749
5750 host_ = FakeLayerTreeHost::Create();
5751 host_->SetRootLayer(root_);
[email protected]fb661802013-03-25 01:59:325752 }
[email protected]10aabcc32012-12-13 09:18:595753
[email protected]fb661802013-03-25 01:59:325754 bool can_use_lcd_text_;
[email protected]d600df7d2013-08-03 02:34:285755 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]fb661802013-03-25 01:59:325756 scoped_refptr<Layer> root_;
5757 scoped_refptr<Layer> child_;
5758 scoped_refptr<Layer> grand_child_;
[email protected]10aabcc32012-12-13 09:18:595759};
5760
[email protected]fb661802013-03-25 01:59:325761TEST_P(LCDTextTest, CanUseLCDText) {
5762 // Case 1: Identity transform.
5763 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:305764 ExecuteCalculateDrawProperties(
5765 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:325766 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
5767 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
5768 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595769
[email protected]fb661802013-03-25 01:59:325770 // Case 2: Integral translation.
5771 gfx::Transform integral_translation;
5772 integral_translation.Translate(1.0, 2.0);
5773 child_->SetTransform(integral_translation);
[email protected]22898ed2013-06-01 04:52:305774 ExecuteCalculateDrawProperties(
5775 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:325776 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
5777 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
5778 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595779
[email protected]fb661802013-03-25 01:59:325780 // Case 3: Non-integral translation.
5781 gfx::Transform non_integral_translation;
5782 non_integral_translation.Translate(1.5, 2.5);
5783 child_->SetTransform(non_integral_translation);
[email protected]22898ed2013-06-01 04:52:305784 ExecuteCalculateDrawProperties(
5785 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:325786 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
5787 EXPECT_FALSE(child_->can_use_lcd_text());
5788 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595789
[email protected]fb661802013-03-25 01:59:325790 // Case 4: Rotation.
5791 gfx::Transform rotation;
5792 rotation.Rotate(10.0);
5793 child_->SetTransform(rotation);
[email protected]22898ed2013-06-01 04:52:305794 ExecuteCalculateDrawProperties(
5795 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:325796 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
5797 EXPECT_FALSE(child_->can_use_lcd_text());
5798 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595799
[email protected]fb661802013-03-25 01:59:325800 // Case 5: Scale.
5801 gfx::Transform scale;
5802 scale.Scale(2.0, 2.0);
5803 child_->SetTransform(scale);
[email protected]22898ed2013-06-01 04:52:305804 ExecuteCalculateDrawProperties(
5805 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:325806 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
5807 EXPECT_FALSE(child_->can_use_lcd_text());
5808 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595809
[email protected]fb661802013-03-25 01:59:325810 // Case 6: Skew.
5811 gfx::Transform skew;
5812 skew.SkewX(10.0);
5813 child_->SetTransform(skew);
[email protected]22898ed2013-06-01 04:52:305814 ExecuteCalculateDrawProperties(
5815 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:325816 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
5817 EXPECT_FALSE(child_->can_use_lcd_text());
5818 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595819
[email protected]fb661802013-03-25 01:59:325820 // Case 7: Translucent.
5821 child_->SetTransform(identity_matrix);
5822 child_->SetOpacity(0.5f);
[email protected]22898ed2013-06-01 04:52:305823 ExecuteCalculateDrawProperties(
5824 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:325825 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
5826 EXPECT_FALSE(child_->can_use_lcd_text());
5827 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595828
[email protected]fb661802013-03-25 01:59:325829 // Case 8: Sanity check: restore transform and opacity.
5830 child_->SetTransform(identity_matrix);
5831 child_->SetOpacity(1.f);
[email protected]22898ed2013-06-01 04:52:305832 ExecuteCalculateDrawProperties(
5833 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:325834 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
5835 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
5836 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595837}
5838
[email protected]fd9a3b6d2013-08-03 00:46:175839TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
[email protected]fb661802013-03-25 01:59:325840 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
[email protected]22898ed2013-06-01 04:52:305841 ExecuteCalculateDrawProperties(
5842 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:325843 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
5844 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
5845 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595846
[email protected]fb661802013-03-25 01:59:325847 // Add opacity animation.
5848 child_->SetOpacity(0.9f);
5849 AddOpacityTransitionToController(
5850 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:595851
[email protected]22898ed2013-06-01 04:52:305852 ExecuteCalculateDrawProperties(
5853 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:325854 // Text AA should not be adjusted while animation is active.
5855 // Make sure LCD text AA setting remains unchanged.
5856 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
5857 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
5858 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595859}
5860
5861INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5862 LCDTextTest,
[email protected]fb661802013-03-25 01:59:325863 testing::Combine(testing::Bool(), testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595864
[email protected]989386c2013-07-18 21:37:235865TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:195866 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455867 TestSharedBitmapManager shared_bitmap_manager;
5868 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:195869 host_impl.CreatePendingTree();
5870 const gfx::Transform identity_matrix;
5871
5872 scoped_refptr<Layer> root = Layer::Create();
5873 SetLayerPropertiesForTesting(root.get(),
5874 identity_matrix,
[email protected]a2566412014-06-05 03:14:205875 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195876 gfx::PointF(),
5877 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575878 true,
[email protected]c0ae06c12013-06-24 18:32:195879 false);
5880 root->SetIsDrawable(true);
5881
5882 scoped_refptr<Layer> child = Layer::Create();
5883 SetLayerPropertiesForTesting(child.get(),
5884 identity_matrix,
[email protected]a2566412014-06-05 03:14:205885 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195886 gfx::PointF(),
5887 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:575888 true,
[email protected]c0ae06c12013-06-24 18:32:195889 false);
5890 child->SetIsDrawable(true);
5891
5892 scoped_refptr<Layer> grand_child = Layer::Create();
5893 SetLayerPropertiesForTesting(grand_child.get(),
5894 identity_matrix,
[email protected]a2566412014-06-05 03:14:205895 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195896 gfx::PointF(),
5897 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575898 true,
[email protected]c0ae06c12013-06-24 18:32:195899 false);
5900 grand_child->SetIsDrawable(true);
5901 grand_child->SetHideLayerAndSubtree(true);
5902
5903 child->AddChild(grand_child);
5904 root->AddChild(child);
5905
[email protected]d600df7d2013-08-03 02:34:285906 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
5907 host->SetRootLayer(root);
5908
[email protected]989386c2013-07-18 21:37:235909 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535910 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5911 root.get(), root->bounds(), &render_surface_layer_list);
5912 inputs.can_adjust_raster_scales = true;
5913 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195914
5915 // We should have one render surface and two layers. The grand child has
5916 // hidden itself.
5917 ASSERT_EQ(1u, render_surface_layer_list.size());
5918 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235919 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
5920 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195921}
5922
[email protected]989386c2013-07-18 21:37:235923TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:195924 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455925 TestSharedBitmapManager shared_bitmap_manager;
5926 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:195927 host_impl.CreatePendingTree();
5928 const gfx::Transform identity_matrix;
5929
5930 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5931 SetLayerPropertiesForTesting(root.get(),
5932 identity_matrix,
[email protected]a2566412014-06-05 03:14:205933 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195934 gfx::PointF(),
5935 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575936 true,
[email protected]c0ae06c12013-06-24 18:32:195937 false);
5938 root->SetDrawsContent(true);
5939
5940 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
5941 SetLayerPropertiesForTesting(child.get(),
5942 identity_matrix,
[email protected]a2566412014-06-05 03:14:205943 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195944 gfx::PointF(),
5945 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:575946 true,
[email protected]c0ae06c12013-06-24 18:32:195947 false);
5948 child->SetDrawsContent(true);
5949
5950 scoped_ptr<LayerImpl> grand_child =
5951 LayerImpl::Create(host_impl.pending_tree(), 3);
5952 SetLayerPropertiesForTesting(grand_child.get(),
5953 identity_matrix,
[email protected]a2566412014-06-05 03:14:205954 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195955 gfx::PointF(),
5956 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575957 true,
[email protected]c0ae06c12013-06-24 18:32:195958 false);
5959 grand_child->SetDrawsContent(true);
5960 grand_child->SetHideLayerAndSubtree(true);
5961
5962 child->AddChild(grand_child.Pass());
5963 root->AddChild(child.Pass());
5964
5965 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535966 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5967 root.get(), root->bounds(), &render_surface_layer_list);
5968 inputs.can_adjust_raster_scales = true;
5969 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195970
5971 // We should have one render surface and two layers. The grand child has
5972 // hidden itself.
5973 ASSERT_EQ(1u, render_surface_layer_list.size());
5974 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235975 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
5976 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195977}
5978
[email protected]989386c2013-07-18 21:37:235979TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:195980 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455981 TestSharedBitmapManager shared_bitmap_manager;
5982 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:195983 host_impl.CreatePendingTree();
5984 const gfx::Transform identity_matrix;
5985
5986 scoped_refptr<Layer> root = Layer::Create();
5987 SetLayerPropertiesForTesting(root.get(),
5988 identity_matrix,
[email protected]a2566412014-06-05 03:14:205989 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195990 gfx::PointF(),
5991 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575992 true,
[email protected]c0ae06c12013-06-24 18:32:195993 false);
5994 root->SetIsDrawable(true);
5995
5996 scoped_refptr<Layer> child = Layer::Create();
5997 SetLayerPropertiesForTesting(child.get(),
5998 identity_matrix,
[email protected]a2566412014-06-05 03:14:205999 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196000 gfx::PointF(),
6001 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576002 true,
[email protected]c0ae06c12013-06-24 18:32:196003 false);
6004 child->SetIsDrawable(true);
6005 child->SetHideLayerAndSubtree(true);
6006
6007 scoped_refptr<Layer> grand_child = Layer::Create();
6008 SetLayerPropertiesForTesting(grand_child.get(),
6009 identity_matrix,
[email protected]a2566412014-06-05 03:14:206010 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196011 gfx::PointF(),
6012 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576013 true,
[email protected]c0ae06c12013-06-24 18:32:196014 false);
6015 grand_child->SetIsDrawable(true);
6016
6017 child->AddChild(grand_child);
6018 root->AddChild(child);
6019
[email protected]d600df7d2013-08-03 02:34:286020 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6021 host->SetRootLayer(root);
6022
[email protected]989386c2013-07-18 21:37:236023 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536024 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6025 root.get(), root->bounds(), &render_surface_layer_list);
6026 inputs.can_adjust_raster_scales = true;
6027 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196028
6029 // We should have one render surface and one layers. The child has
6030 // hidden itself and the grand child.
6031 ASSERT_EQ(1u, render_surface_layer_list.size());
6032 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236033 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196034}
6035
[email protected]989386c2013-07-18 21:37:236036TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:196037 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456038 TestSharedBitmapManager shared_bitmap_manager;
6039 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:196040 host_impl.CreatePendingTree();
6041 const gfx::Transform identity_matrix;
6042
6043 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
6044 SetLayerPropertiesForTesting(root.get(),
6045 identity_matrix,
[email protected]a2566412014-06-05 03:14:206046 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196047 gfx::PointF(),
6048 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576049 true,
[email protected]c0ae06c12013-06-24 18:32:196050 false);
6051 root->SetDrawsContent(true);
6052
6053 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
6054 SetLayerPropertiesForTesting(child.get(),
6055 identity_matrix,
[email protected]a2566412014-06-05 03:14:206056 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196057 gfx::PointF(),
6058 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576059 true,
[email protected]c0ae06c12013-06-24 18:32:196060 false);
6061 child->SetDrawsContent(true);
6062 child->SetHideLayerAndSubtree(true);
6063
6064 scoped_ptr<LayerImpl> grand_child =
6065 LayerImpl::Create(host_impl.pending_tree(), 3);
6066 SetLayerPropertiesForTesting(grand_child.get(),
6067 identity_matrix,
[email protected]a2566412014-06-05 03:14:206068 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196069 gfx::PointF(),
6070 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576071 true,
[email protected]c0ae06c12013-06-24 18:32:196072 false);
6073 grand_child->SetDrawsContent(true);
6074
6075 child->AddChild(grand_child.Pass());
6076 root->AddChild(child.Pass());
6077
6078 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536079 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6080 root.get(), root->bounds(), &render_surface_layer_list);
6081 inputs.can_adjust_raster_scales = true;
6082 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196083
6084 // We should have one render surface and one layers. The child has
6085 // hidden itself and the grand child.
6086 ASSERT_EQ(1u, render_surface_layer_list.size());
6087 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236088 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196089}
6090
[email protected]30fe19ff2013-07-04 00:54:456091void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
6092
[email protected]989386c2013-07-18 21:37:236093TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456094 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456095 TestSharedBitmapManager shared_bitmap_manager;
6096 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:456097 host_impl.CreatePendingTree();
6098 const gfx::Transform identity_matrix;
6099
6100 scoped_refptr<Layer> root = Layer::Create();
6101 SetLayerPropertiesForTesting(root.get(),
6102 identity_matrix,
[email protected]a2566412014-06-05 03:14:206103 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456104 gfx::PointF(),
6105 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576106 true,
[email protected]30fe19ff2013-07-04 00:54:456107 false);
6108 root->SetIsDrawable(true);
6109
6110 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
6111 SetLayerPropertiesForTesting(copy_grand_parent.get(),
6112 identity_matrix,
[email protected]a2566412014-06-05 03:14:206113 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456114 gfx::PointF(),
6115 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576116 true,
[email protected]30fe19ff2013-07-04 00:54:456117 false);
6118 copy_grand_parent->SetIsDrawable(true);
6119
6120 scoped_refptr<Layer> copy_parent = Layer::Create();
6121 SetLayerPropertiesForTesting(copy_parent.get(),
6122 identity_matrix,
[email protected]a2566412014-06-05 03:14:206123 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456124 gfx::PointF(),
6125 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576126 true,
[email protected]30fe19ff2013-07-04 00:54:456127 false);
6128 copy_parent->SetIsDrawable(true);
6129 copy_parent->SetForceRenderSurface(true);
6130
6131 scoped_refptr<Layer> copy_layer = Layer::Create();
6132 SetLayerPropertiesForTesting(copy_layer.get(),
6133 identity_matrix,
[email protected]a2566412014-06-05 03:14:206134 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456135 gfx::PointF(),
6136 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576137 true,
[email protected]30fe19ff2013-07-04 00:54:456138 false);
6139 copy_layer->SetIsDrawable(true);
6140
6141 scoped_refptr<Layer> copy_child = Layer::Create();
6142 SetLayerPropertiesForTesting(copy_child.get(),
6143 identity_matrix,
[email protected]a2566412014-06-05 03:14:206144 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456145 gfx::PointF(),
6146 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576147 true,
[email protected]30fe19ff2013-07-04 00:54:456148 false);
6149 copy_child->SetIsDrawable(true);
6150
[email protected]ac020122013-07-12 23:45:536151 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
6152 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
6153 identity_matrix,
[email protected]a2566412014-06-05 03:14:206154 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536155 gfx::PointF(),
6156 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576157 true,
[email protected]ac020122013-07-12 23:45:536158 false);
6159 copy_grand_parent_sibling_before->SetIsDrawable(true);
6160
6161 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
6162 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
6163 identity_matrix,
[email protected]a2566412014-06-05 03:14:206164 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536165 gfx::PointF(),
6166 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576167 true,
[email protected]ac020122013-07-12 23:45:536168 false);
6169 copy_grand_parent_sibling_after->SetIsDrawable(true);
6170
[email protected]30fe19ff2013-07-04 00:54:456171 copy_layer->AddChild(copy_child);
6172 copy_parent->AddChild(copy_layer);
6173 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:536174 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:456175 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:536176 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:456177
[email protected]d600df7d2013-08-03 02:34:286178 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6179 host->SetRootLayer(root);
6180
[email protected]30fe19ff2013-07-04 00:54:456181 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6182 // hidden subtree on copy_layer.
6183 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:536184 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
6185 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:456186 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6187 base::Bind(&EmptyCopyOutputCallback)));
6188 EXPECT_TRUE(copy_layer->HasCopyRequest());
6189
[email protected]989386c2013-07-18 21:37:236190 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536191 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6192 root.get(), root->bounds(), &render_surface_layer_list);
6193 inputs.can_adjust_raster_scales = true;
6194 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456195
[email protected]ac020122013-07-12 23:45:536196 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
6197 EXPECT_TRUE(copy_grand_parent->draw_properties().
6198 layer_or_descendant_has_copy_request);
6199 EXPECT_TRUE(copy_parent->draw_properties().
6200 layer_or_descendant_has_copy_request);
6201 EXPECT_TRUE(copy_layer->draw_properties().
6202 layer_or_descendant_has_copy_request);
6203 EXPECT_FALSE(copy_child->draw_properties().
6204 layer_or_descendant_has_copy_request);
6205 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
6206 layer_or_descendant_has_copy_request);
6207 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
6208 layer_or_descendant_has_copy_request);
6209
[email protected]30fe19ff2013-07-04 00:54:456210 // We should have three render surfaces, one for the root, one for the parent
6211 // since it owns a surface, and one for the copy_layer.
6212 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236213 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
6214 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
6215 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:456216
6217 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:536218 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6219 // will appear since something in its subtree needs to be drawn for a copy
6220 // request.
[email protected]30fe19ff2013-07-04 00:54:456221 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236222 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
6223 EXPECT_EQ(copy_parent->id(),
6224 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456225
[email protected]7392c7b2014-02-07 08:28:286226 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:456227 // appear in its list, since it needs to be drawn for the copy request.
6228 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
6229 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236230 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456231
6232 // The copy_layer's render surface should have two contributing layers.
6233 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
6234 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236235 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456236 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:236237 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456238}
6239
[email protected]989386c2013-07-18 21:37:236240TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456241 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456242 TestSharedBitmapManager shared_bitmap_manager;
6243 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:456244 host_impl.CreatePendingTree();
6245 const gfx::Transform identity_matrix;
6246
6247 scoped_refptr<Layer> root = Layer::Create();
6248 SetLayerPropertiesForTesting(root.get(),
6249 identity_matrix,
[email protected]a2566412014-06-05 03:14:206250 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456251 gfx::PointF(),
6252 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576253 true,
[email protected]30fe19ff2013-07-04 00:54:456254 false);
6255 root->SetIsDrawable(true);
6256
6257 scoped_refptr<Layer> copy_parent = Layer::Create();
6258 SetLayerPropertiesForTesting(copy_parent.get(),
6259 identity_matrix,
[email protected]a2566412014-06-05 03:14:206260 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456261 gfx::PointF(),
6262 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576263 true,
[email protected]30fe19ff2013-07-04 00:54:456264 false);
6265 copy_parent->SetIsDrawable(true);
6266 copy_parent->SetMasksToBounds(true);
6267
6268 scoped_refptr<Layer> copy_layer = Layer::Create();
6269 SetLayerPropertiesForTesting(copy_layer.get(),
6270 identity_matrix,
[email protected]a2566412014-06-05 03:14:206271 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456272 gfx::PointF(),
6273 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576274 true,
[email protected]30fe19ff2013-07-04 00:54:456275 false);
6276 copy_layer->SetIsDrawable(true);
6277
6278 scoped_refptr<Layer> copy_child = Layer::Create();
6279 SetLayerPropertiesForTesting(copy_child.get(),
6280 identity_matrix,
[email protected]a2566412014-06-05 03:14:206281 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456282 gfx::PointF(),
6283 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576284 true,
[email protected]30fe19ff2013-07-04 00:54:456285 false);
6286 copy_child->SetIsDrawable(true);
6287
6288 copy_layer->AddChild(copy_child);
6289 copy_parent->AddChild(copy_layer);
6290 root->AddChild(copy_parent);
6291
[email protected]d600df7d2013-08-03 02:34:286292 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6293 host->SetRootLayer(root);
6294
[email protected]30fe19ff2013-07-04 00:54:456295 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6296 base::Bind(&EmptyCopyOutputCallback)));
6297 EXPECT_TRUE(copy_layer->HasCopyRequest());
6298
[email protected]989386c2013-07-18 21:37:236299 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536300 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6301 root.get(), root->bounds(), &render_surface_layer_list);
6302 inputs.can_adjust_raster_scales = true;
6303 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456304
6305 // We should have one render surface, as the others are clipped out.
6306 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236307 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456308
6309 // The root render surface should only have 1 contributing layer, since the
6310 // other layers are empty/clipped away.
6311 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236312 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456313}
6314
[email protected]11a07b102013-07-24 17:33:196315TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
6316 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456317 TestSharedBitmapManager shared_bitmap_manager;
6318 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]11a07b102013-07-24 17:33:196319 host_impl.CreatePendingTree();
6320 const gfx::Transform identity_matrix;
6321
6322 scoped_refptr<Layer> root = Layer::Create();
6323 SetLayerPropertiesForTesting(root.get(),
6324 identity_matrix,
[email protected]a2566412014-06-05 03:14:206325 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196326 gfx::PointF(),
6327 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576328 true,
[email protected]11a07b102013-07-24 17:33:196329 false);
6330 root->SetIsDrawable(true);
6331
6332 // The surface is moved slightly outside of the viewport.
6333 scoped_refptr<Layer> surface = Layer::Create();
6334 SetLayerPropertiesForTesting(surface.get(),
6335 identity_matrix,
[email protected]a2566412014-06-05 03:14:206336 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196337 gfx::PointF(-10, -20),
6338 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576339 true,
[email protected]11a07b102013-07-24 17:33:196340 false);
6341 surface->SetForceRenderSurface(true);
6342
6343 scoped_refptr<Layer> surface_child = Layer::Create();
6344 SetLayerPropertiesForTesting(surface_child.get(),
6345 identity_matrix,
[email protected]a2566412014-06-05 03:14:206346 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196347 gfx::PointF(),
6348 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576349 true,
[email protected]11a07b102013-07-24 17:33:196350 false);
6351 surface_child->SetIsDrawable(true);
6352
6353 surface->AddChild(surface_child);
6354 root->AddChild(surface);
6355
[email protected]d600df7d2013-08-03 02:34:286356 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6357 host->SetRootLayer(root);
6358
[email protected]11a07b102013-07-24 17:33:196359 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536360 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6361 root.get(), root->bounds(), &render_surface_layer_list);
6362 inputs.can_adjust_raster_scales = true;
6363 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:196364
6365 // The visible_content_rect for the |surface_child| should not be clipped by
6366 // the viewport.
6367 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6368 surface_child->visible_content_rect().ToString());
6369}
6370
[email protected]420fdf6e2013-08-26 20:36:386371TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
6372 // Ensure that a transform between the layer and its render surface is not a
6373 // problem. Constructs the following layer tree.
6374 //
6375 // root (a render surface)
6376 // + render_surface
6377 // + clip_parent (scaled)
6378 // + intervening_clipping_layer
6379 // + clip_child
6380 //
6381 // The render surface should be resized correctly and the clip child should
6382 // inherit the right clip rect.
6383 scoped_refptr<Layer> root = Layer::Create();
6384 scoped_refptr<Layer> render_surface = Layer::Create();
6385 scoped_refptr<Layer> clip_parent = Layer::Create();
6386 scoped_refptr<Layer> intervening = Layer::Create();
6387 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6388 make_scoped_refptr(new LayerWithForcedDrawsContent);
6389
6390 root->AddChild(render_surface);
6391 render_surface->AddChild(clip_parent);
6392 clip_parent->AddChild(intervening);
6393 intervening->AddChild(clip_child);
6394
6395 clip_child->SetClipParent(clip_parent.get());
6396
6397 intervening->SetMasksToBounds(true);
6398 clip_parent->SetMasksToBounds(true);
6399
6400 render_surface->SetForceRenderSurface(true);
6401
6402 gfx::Transform scale_transform;
6403 scale_transform.Scale(2, 2);
6404
6405 gfx::Transform identity_transform;
6406
6407 SetLayerPropertiesForTesting(root.get(),
6408 identity_transform,
[email protected]a2566412014-06-05 03:14:206409 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386410 gfx::PointF(),
6411 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576412 true,
[email protected]420fdf6e2013-08-26 20:36:386413 false);
6414 SetLayerPropertiesForTesting(render_surface.get(),
6415 identity_transform,
[email protected]a2566412014-06-05 03:14:206416 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386417 gfx::PointF(),
6418 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576419 true,
[email protected]420fdf6e2013-08-26 20:36:386420 false);
6421 SetLayerPropertiesForTesting(clip_parent.get(),
6422 scale_transform,
[email protected]a2566412014-06-05 03:14:206423 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386424 gfx::PointF(1.f, 1.f),
6425 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576426 true,
[email protected]420fdf6e2013-08-26 20:36:386427 false);
6428 SetLayerPropertiesForTesting(intervening.get(),
6429 identity_transform,
[email protected]a2566412014-06-05 03:14:206430 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386431 gfx::PointF(1.f, 1.f),
6432 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576433 true,
[email protected]420fdf6e2013-08-26 20:36:386434 false);
6435 SetLayerPropertiesForTesting(clip_child.get(),
6436 identity_transform,
[email protected]a2566412014-06-05 03:14:206437 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386438 gfx::PointF(1.f, 1.f),
6439 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576440 true,
[email protected]420fdf6e2013-08-26 20:36:386441 false);
6442
6443 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6444 host->SetRootLayer(root);
6445
6446 ExecuteCalculateDrawProperties(root.get());
6447
6448 ASSERT_TRUE(root->render_surface());
6449 ASSERT_TRUE(render_surface->render_surface());
6450
6451 // Ensure that we've inherited our clip parent's clip and weren't affected
6452 // by the intervening clip layer.
6453 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6454 clip_parent->clip_rect().ToString());
6455 ASSERT_EQ(clip_parent->clip_rect().ToString(),
6456 clip_child->clip_rect().ToString());
6457 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6458 intervening->clip_rect().ToString());
6459
6460 // Ensure that the render surface reports a content rect that has been grown
6461 // to accomodate for the clip child.
6462 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6463 render_surface->render_surface()->content_rect().ToString());
6464
6465 // The above check implies the two below, but they nicely demonstrate that
6466 // we've grown, despite the intervening layer's clip.
6467 ASSERT_TRUE(clip_parent->clip_rect().Contains(
6468 render_surface->render_surface()->content_rect()));
6469 ASSERT_FALSE(intervening->clip_rect().Contains(
6470 render_surface->render_surface()->content_rect()));
6471}
6472
6473TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
6474 // Ensure that intervening render surfaces are not a problem in the basic
6475 // case. In the following tree, both render surfaces should be resized to
6476 // accomodate for the clip child, despite an intervening clip.
6477 //
6478 // root (a render surface)
6479 // + clip_parent (masks to bounds)
6480 // + render_surface1 (sets opacity)
6481 // + intervening (masks to bounds)
6482 // + render_surface2 (also sets opacity)
6483 // + clip_child
6484 //
6485 scoped_refptr<Layer> root = Layer::Create();
6486 scoped_refptr<Layer> clip_parent = Layer::Create();
6487 scoped_refptr<Layer> render_surface1 = Layer::Create();
6488 scoped_refptr<Layer> intervening = Layer::Create();
6489 scoped_refptr<Layer> render_surface2 = Layer::Create();
6490 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6491 make_scoped_refptr(new LayerWithForcedDrawsContent);
6492
6493 root->AddChild(clip_parent);
6494 clip_parent->AddChild(render_surface1);
6495 render_surface1->AddChild(intervening);
6496 intervening->AddChild(render_surface2);
6497 render_surface2->AddChild(clip_child);
6498
6499 clip_child->SetClipParent(clip_parent.get());
6500
6501 intervening->SetMasksToBounds(true);
6502 clip_parent->SetMasksToBounds(true);
6503
6504 render_surface1->SetForceRenderSurface(true);
6505 render_surface2->SetForceRenderSurface(true);
6506
6507 gfx::Transform translation_transform;
6508 translation_transform.Translate(2, 2);
6509
6510 gfx::Transform identity_transform;
6511 SetLayerPropertiesForTesting(root.get(),
6512 identity_transform,
[email protected]a2566412014-06-05 03:14:206513 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386514 gfx::PointF(),
6515 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576516 true,
[email protected]420fdf6e2013-08-26 20:36:386517 false);
6518 SetLayerPropertiesForTesting(clip_parent.get(),
6519 translation_transform,
[email protected]a2566412014-06-05 03:14:206520 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386521 gfx::PointF(1.f, 1.f),
6522 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576523 true,
[email protected]420fdf6e2013-08-26 20:36:386524 false);
6525 SetLayerPropertiesForTesting(render_surface1.get(),
6526 identity_transform,
[email protected]a2566412014-06-05 03:14:206527 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386528 gfx::PointF(),
6529 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576530 true,
[email protected]420fdf6e2013-08-26 20:36:386531 false);
6532 SetLayerPropertiesForTesting(intervening.get(),
6533 identity_transform,
[email protected]a2566412014-06-05 03:14:206534 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386535 gfx::PointF(1.f, 1.f),
6536 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576537 true,
[email protected]420fdf6e2013-08-26 20:36:386538 false);
6539 SetLayerPropertiesForTesting(render_surface2.get(),
6540 identity_transform,
[email protected]a2566412014-06-05 03:14:206541 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386542 gfx::PointF(),
6543 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576544 true,
[email protected]420fdf6e2013-08-26 20:36:386545 false);
6546 SetLayerPropertiesForTesting(clip_child.get(),
6547 identity_transform,
[email protected]a2566412014-06-05 03:14:206548 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386549 gfx::PointF(-10.f, -10.f),
6550 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576551 true,
[email protected]420fdf6e2013-08-26 20:36:386552 false);
6553
6554 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6555 host->SetRootLayer(root);
6556
6557 ExecuteCalculateDrawProperties(root.get());
6558
6559 EXPECT_TRUE(root->render_surface());
6560 EXPECT_TRUE(render_surface1->render_surface());
6561 EXPECT_TRUE(render_surface2->render_surface());
6562
6563 // Since the render surfaces could have expanded, they should not clip (their
6564 // bounds would no longer be reliable). We should resort to layer clipping
6565 // in this case.
6566 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6567 render_surface1->render_surface()->clip_rect().ToString());
6568 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6569 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6570 render_surface2->render_surface()->clip_rect().ToString());
6571 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6572
6573 // NB: clip rects are in target space.
6574 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6575 render_surface1->clip_rect().ToString());
6576 EXPECT_TRUE(render_surface1->is_clipped());
6577
6578 // This value is inherited from the clipping ancestor layer, 'intervening'.
6579 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6580 render_surface2->clip_rect().ToString());
6581 EXPECT_TRUE(render_surface2->is_clipped());
6582
6583 // The content rects of both render surfaces should both have expanded to
6584 // contain the clip child.
6585 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6586 render_surface1->render_surface()->content_rect().ToString());
6587 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6588 render_surface2->render_surface()->content_rect().ToString());
6589
6590 // The clip child should have inherited the clip parent's clip (projected to
6591 // the right space, of course), and should have the correctly sized visible
6592 // content rect.
6593 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6594 clip_child->clip_rect().ToString());
6595 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6596 clip_child->visible_content_rect().ToString());
6597 EXPECT_TRUE(clip_child->is_clipped());
6598}
6599
6600TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
6601 // Ensure that intervening render surfaces are not a problem, even if there
6602 // is a scroll involved. Note, we do _not_ have to consider any other sort
6603 // of transform.
6604 //
6605 // root (a render surface)
6606 // + clip_parent (masks to bounds)
6607 // + render_surface1 (sets opacity)
6608 // + intervening (masks to bounds AND scrolls)
6609 // + render_surface2 (also sets opacity)
6610 // + clip_child
6611 //
6612 scoped_refptr<Layer> root = Layer::Create();
6613 scoped_refptr<Layer> clip_parent = Layer::Create();
6614 scoped_refptr<Layer> render_surface1 = Layer::Create();
6615 scoped_refptr<Layer> intervening = Layer::Create();
6616 scoped_refptr<Layer> render_surface2 = Layer::Create();
6617 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6618 make_scoped_refptr(new LayerWithForcedDrawsContent);
6619
6620 root->AddChild(clip_parent);
6621 clip_parent->AddChild(render_surface1);
6622 render_surface1->AddChild(intervening);
6623 intervening->AddChild(render_surface2);
6624 render_surface2->AddChild(clip_child);
6625
6626 clip_child->SetClipParent(clip_parent.get());
6627
6628 intervening->SetMasksToBounds(true);
6629 clip_parent->SetMasksToBounds(true);
[email protected]adeda572014-01-31 00:49:476630 intervening->SetScrollClipLayerId(clip_parent->id());
[email protected]420fdf6e2013-08-26 20:36:386631 intervening->SetScrollOffset(gfx::Vector2d(3, 3));
6632
6633 render_surface1->SetForceRenderSurface(true);
6634 render_surface2->SetForceRenderSurface(true);
6635
6636 gfx::Transform translation_transform;
6637 translation_transform.Translate(2, 2);
6638
6639 gfx::Transform identity_transform;
6640 SetLayerPropertiesForTesting(root.get(),
6641 identity_transform,
[email protected]a2566412014-06-05 03:14:206642 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386643 gfx::PointF(),
6644 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576645 true,
[email protected]420fdf6e2013-08-26 20:36:386646 false);
6647 SetLayerPropertiesForTesting(clip_parent.get(),
6648 translation_transform,
[email protected]a2566412014-06-05 03:14:206649 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386650 gfx::PointF(1.f, 1.f),
6651 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576652 true,
[email protected]420fdf6e2013-08-26 20:36:386653 false);
6654 SetLayerPropertiesForTesting(render_surface1.get(),
6655 identity_transform,
[email protected]a2566412014-06-05 03:14:206656 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386657 gfx::PointF(),
6658 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576659 true,
[email protected]420fdf6e2013-08-26 20:36:386660 false);
6661 SetLayerPropertiesForTesting(intervening.get(),
6662 identity_transform,
[email protected]a2566412014-06-05 03:14:206663 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386664 gfx::PointF(1.f, 1.f),
6665 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576666 true,
[email protected]420fdf6e2013-08-26 20:36:386667 false);
6668 SetLayerPropertiesForTesting(render_surface2.get(),
6669 identity_transform,
[email protected]a2566412014-06-05 03:14:206670 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386671 gfx::PointF(),
6672 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576673 true,
[email protected]420fdf6e2013-08-26 20:36:386674 false);
6675 SetLayerPropertiesForTesting(clip_child.get(),
6676 identity_transform,
[email protected]a2566412014-06-05 03:14:206677 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386678 gfx::PointF(-10.f, -10.f),
6679 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576680 true,
[email protected]420fdf6e2013-08-26 20:36:386681 false);
6682
6683 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6684 host->SetRootLayer(root);
6685
6686 ExecuteCalculateDrawProperties(root.get());
6687
6688 EXPECT_TRUE(root->render_surface());
6689 EXPECT_TRUE(render_surface1->render_surface());
6690 EXPECT_TRUE(render_surface2->render_surface());
6691
6692 // Since the render surfaces could have expanded, they should not clip (their
6693 // bounds would no longer be reliable). We should resort to layer clipping
6694 // in this case.
6695 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6696 render_surface1->render_surface()->clip_rect().ToString());
6697 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6698 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6699 render_surface2->render_surface()->clip_rect().ToString());
6700 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6701
6702 // NB: clip rects are in target space.
6703 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6704 render_surface1->clip_rect().ToString());
6705 EXPECT_TRUE(render_surface1->is_clipped());
6706
6707 // This value is inherited from the clipping ancestor layer, 'intervening'.
6708 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6709 render_surface2->clip_rect().ToString());
6710 EXPECT_TRUE(render_surface2->is_clipped());
6711
6712 // The content rects of both render surfaces should both have expanded to
6713 // contain the clip child.
6714 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6715 render_surface1->render_surface()->content_rect().ToString());
6716 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6717 render_surface2->render_surface()->content_rect().ToString());
6718
6719 // The clip child should have inherited the clip parent's clip (projected to
6720 // the right space, of course), and should have the correctly sized visible
6721 // content rect.
6722 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6723 clip_child->clip_rect().ToString());
6724 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6725 clip_child->visible_content_rect().ToString());
6726 EXPECT_TRUE(clip_child->is_clipped());
6727}
6728
6729TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
6730 // Ensures that descendants of the clip child inherit the correct clip.
6731 //
6732 // root (a render surface)
6733 // + clip_parent (masks to bounds)
6734 // + intervening (masks to bounds)
6735 // + clip_child
6736 // + child
6737 //
6738 scoped_refptr<Layer> root = Layer::Create();
6739 scoped_refptr<Layer> clip_parent = Layer::Create();
6740 scoped_refptr<Layer> intervening = Layer::Create();
6741 scoped_refptr<Layer> clip_child = Layer::Create();
6742 scoped_refptr<LayerWithForcedDrawsContent> child =
6743 make_scoped_refptr(new LayerWithForcedDrawsContent);
6744
6745 root->AddChild(clip_parent);
6746 clip_parent->AddChild(intervening);
6747 intervening->AddChild(clip_child);
6748 clip_child->AddChild(child);
6749
6750 clip_child->SetClipParent(clip_parent.get());
6751
6752 intervening->SetMasksToBounds(true);
6753 clip_parent->SetMasksToBounds(true);
6754
6755 gfx::Transform identity_transform;
6756 SetLayerPropertiesForTesting(root.get(),
6757 identity_transform,
[email protected]a2566412014-06-05 03:14:206758 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386759 gfx::PointF(),
6760 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576761 true,
[email protected]420fdf6e2013-08-26 20:36:386762 false);
6763 SetLayerPropertiesForTesting(clip_parent.get(),
6764 identity_transform,
[email protected]a2566412014-06-05 03:14:206765 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386766 gfx::PointF(),
6767 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576768 true,
[email protected]420fdf6e2013-08-26 20:36:386769 false);
6770 SetLayerPropertiesForTesting(intervening.get(),
6771 identity_transform,
[email protected]a2566412014-06-05 03:14:206772 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386773 gfx::PointF(),
6774 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576775 true,
[email protected]420fdf6e2013-08-26 20:36:386776 false);
6777 SetLayerPropertiesForTesting(clip_child.get(),
6778 identity_transform,
[email protected]a2566412014-06-05 03:14:206779 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386780 gfx::PointF(),
6781 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576782 true,
[email protected]420fdf6e2013-08-26 20:36:386783 false);
6784 SetLayerPropertiesForTesting(child.get(),
6785 identity_transform,
[email protected]a2566412014-06-05 03:14:206786 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386787 gfx::PointF(),
6788 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576789 true,
[email protected]420fdf6e2013-08-26 20:36:386790 false);
6791
6792 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6793 host->SetRootLayer(root);
6794
6795 ExecuteCalculateDrawProperties(root.get());
6796
6797 EXPECT_TRUE(root->render_surface());
6798
6799 // Neither the clip child nor its descendant should have inherited the clip
6800 // from |intervening|.
6801 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6802 clip_child->clip_rect().ToString());
6803 EXPECT_TRUE(clip_child->is_clipped());
6804 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6805 child->visible_content_rect().ToString());
6806 EXPECT_TRUE(child->is_clipped());
6807}
6808
6809TEST_F(LayerTreeHostCommonTest,
6810 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
6811 // Ensures that non-descendant clip children in the tree do not affect
6812 // render surfaces.
6813 //
6814 // root (a render surface)
6815 // + clip_parent (masks to bounds)
6816 // + render_surface1
6817 // + clip_child
6818 // + render_surface2
6819 // + non_clip_child
6820 //
6821 // In this example render_surface2 should be unaffected by clip_child.
6822 scoped_refptr<Layer> root = Layer::Create();
6823 scoped_refptr<Layer> clip_parent = Layer::Create();
6824 scoped_refptr<Layer> render_surface1 = Layer::Create();
6825 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6826 make_scoped_refptr(new LayerWithForcedDrawsContent);
6827 scoped_refptr<Layer> render_surface2 = Layer::Create();
6828 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
6829 make_scoped_refptr(new LayerWithForcedDrawsContent);
6830
6831 root->AddChild(clip_parent);
6832 clip_parent->AddChild(render_surface1);
6833 render_surface1->AddChild(clip_child);
6834 clip_parent->AddChild(render_surface2);
6835 render_surface2->AddChild(non_clip_child);
6836
6837 clip_child->SetClipParent(clip_parent.get());
6838
6839 clip_parent->SetMasksToBounds(true);
6840 render_surface1->SetMasksToBounds(true);
6841
6842 gfx::Transform identity_transform;
6843 SetLayerPropertiesForTesting(root.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(15, 15),
[email protected]56fffdd2014-02-11 19:50:576848 true,
[email protected]420fdf6e2013-08-26 20:36:386849 false);
6850 SetLayerPropertiesForTesting(clip_parent.get(),
6851 identity_transform,
[email protected]a2566412014-06-05 03:14:206852 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386853 gfx::PointF(),
6854 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576855 true,
[email protected]420fdf6e2013-08-26 20:36:386856 false);
6857 SetLayerPropertiesForTesting(render_surface1.get(),
6858 identity_transform,
[email protected]a2566412014-06-05 03:14:206859 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386860 gfx::PointF(5, 5),
6861 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576862 true,
[email protected]420fdf6e2013-08-26 20:36:386863 false);
6864 SetLayerPropertiesForTesting(render_surface2.get(),
6865 identity_transform,
[email protected]a2566412014-06-05 03:14:206866 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386867 gfx::PointF(),
6868 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576869 true,
[email protected]420fdf6e2013-08-26 20:36:386870 false);
6871 SetLayerPropertiesForTesting(clip_child.get(),
6872 identity_transform,
[email protected]a2566412014-06-05 03:14:206873 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386874 gfx::PointF(-1, 1),
6875 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576876 true,
[email protected]420fdf6e2013-08-26 20:36:386877 false);
6878 SetLayerPropertiesForTesting(non_clip_child.get(),
6879 identity_transform,
[email protected]a2566412014-06-05 03:14:206880 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386881 gfx::PointF(),
6882 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576883 true,
[email protected]420fdf6e2013-08-26 20:36:386884 false);
6885
6886 render_surface1->SetForceRenderSurface(true);
6887 render_surface2->SetForceRenderSurface(true);
6888
6889 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6890 host->SetRootLayer(root);
6891
6892 ExecuteCalculateDrawProperties(root.get());
6893
6894 EXPECT_TRUE(root->render_surface());
6895 EXPECT_TRUE(render_surface1->render_surface());
6896 EXPECT_TRUE(render_surface2->render_surface());
6897
6898 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6899 render_surface1->clip_rect().ToString());
6900 EXPECT_TRUE(render_surface1->is_clipped());
6901
6902 // The render surface should not clip (it has unclipped descendants), instead
6903 // it should rely on layer clipping.
6904 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6905 render_surface1->render_surface()->clip_rect().ToString());
6906 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6907
6908 // That said, it should have grown to accomodate the unclipped descendant.
6909 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
6910 render_surface1->render_surface()->content_rect().ToString());
6911
6912 // This render surface should clip. It has no unclipped descendants.
6913 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6914 render_surface2->clip_rect().ToString());
6915 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
6916
6917 // It also shouldn't have grown to accomodate the clip child.
6918 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6919 render_surface2->render_surface()->content_rect().ToString());
6920
6921 // Sanity check our num_unclipped_descendants values.
6922 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
6923 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
6924}
6925
[email protected]45948712013-09-27 02:46:486926TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
6927 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456928 TestSharedBitmapManager shared_bitmap_manager;
6929 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]45948712013-09-27 02:46:486930 scoped_ptr<LayerImpl> root =
6931 LayerImpl::Create(host_impl.active_tree(), 12345);
6932 scoped_ptr<LayerImpl> child1 =
6933 LayerImpl::Create(host_impl.active_tree(), 123456);
6934 scoped_ptr<LayerImpl> child2 =
6935 LayerImpl::Create(host_impl.active_tree(), 1234567);
6936 scoped_ptr<LayerImpl> child3 =
6937 LayerImpl::Create(host_impl.active_tree(), 12345678);
6938
6939 gfx::Transform identity_matrix;
[email protected]a2566412014-06-05 03:14:206940 gfx::Point3F transform_origin;
[email protected]45948712013-09-27 02:46:486941 gfx::PointF position;
6942 gfx::Size bounds(100, 100);
6943 SetLayerPropertiesForTesting(root.get(),
6944 identity_matrix,
[email protected]a2566412014-06-05 03:14:206945 transform_origin,
[email protected]45948712013-09-27 02:46:486946 position,
6947 bounds,
[email protected]56fffdd2014-02-11 19:50:576948 true,
[email protected]45948712013-09-27 02:46:486949 false);
6950 root->SetDrawsContent(true);
6951
6952 // This layer structure normally forces render surface due to preserves3d
6953 // behavior.
[email protected]45948712013-09-27 02:46:486954 SetLayerPropertiesForTesting(child1.get(),
6955 identity_matrix,
[email protected]a2566412014-06-05 03:14:206956 transform_origin,
[email protected]45948712013-09-27 02:46:486957 position,
6958 bounds,
[email protected]56fffdd2014-02-11 19:50:576959 false,
6960 true);
[email protected]45948712013-09-27 02:46:486961 child1->SetDrawsContent(true);
6962 SetLayerPropertiesForTesting(child2.get(),
6963 identity_matrix,
[email protected]a2566412014-06-05 03:14:206964 transform_origin,
[email protected]45948712013-09-27 02:46:486965 position,
6966 bounds,
[email protected]56fffdd2014-02-11 19:50:576967 true,
[email protected]45948712013-09-27 02:46:486968 false);
6969 child2->SetDrawsContent(true);
6970 SetLayerPropertiesForTesting(child3.get(),
6971 identity_matrix,
[email protected]a2566412014-06-05 03:14:206972 transform_origin,
[email protected]45948712013-09-27 02:46:486973 position,
6974 bounds,
[email protected]56fffdd2014-02-11 19:50:576975 true,
[email protected]45948712013-09-27 02:46:486976 false);
6977 child3->SetDrawsContent(true);
6978
[email protected]56fffdd2014-02-11 19:50:576979 child2->SetIs3dSorted(true);
6980 child3->SetIs3dSorted(true);
6981
[email protected]45948712013-09-27 02:46:486982 child2->AddChild(child3.Pass());
6983 child1->AddChild(child2.Pass());
6984 root->AddChild(child1.Pass());
6985
6986 {
6987 LayerImplList render_surface_layer_list;
6988 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6989 root.get(), root->bounds(), &render_surface_layer_list);
6990 inputs.can_render_to_separate_surface = true;
6991 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6992
6993 EXPECT_EQ(2u, render_surface_layer_list.size());
6994 }
6995
6996 {
6997 LayerImplList render_surface_layer_list;
6998 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6999 root.get(), root->bounds(), &render_surface_layer_list);
7000 inputs.can_render_to_separate_surface = false;
7001 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7002
7003 EXPECT_EQ(1u, render_surface_layer_list.size());
7004 }
7005}
7006
[email protected]a9aa60a82013-08-29 04:28:267007TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
7008 scoped_refptr<Layer> root = Layer::Create();
7009 scoped_refptr<Layer> render_surface = Layer::Create();
7010 scoped_refptr<LayerWithForcedDrawsContent> child =
7011 make_scoped_refptr(new LayerWithForcedDrawsContent);
7012
7013 root->AddChild(render_surface);
7014 render_surface->AddChild(child);
7015
7016 gfx::Transform identity_transform;
7017 SetLayerPropertiesForTesting(root.get(),
7018 identity_transform,
[email protected]a2566412014-06-05 03:14:207019 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267020 gfx::PointF(),
7021 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577022 true,
[email protected]a9aa60a82013-08-29 04:28:267023 false);
7024 SetLayerPropertiesForTesting(render_surface.get(),
7025 identity_transform,
[email protected]a2566412014-06-05 03:14:207026 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267027 gfx::PointF(),
7028 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577029 false,
7030 true);
[email protected]a9aa60a82013-08-29 04:28:267031 SetLayerPropertiesForTesting(child.get(),
7032 identity_transform,
[email protected]a2566412014-06-05 03:14:207033 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267034 gfx::PointF(),
7035 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577036 true,
[email protected]a9aa60a82013-08-29 04:28:267037 false);
7038
[email protected]56fffdd2014-02-11 19:50:577039 root->SetShouldFlattenTransform(false);
7040 root->SetIs3dSorted(true);
[email protected]a9aa60a82013-08-29 04:28:267041 render_surface->SetDoubleSided(false);
7042 render_surface->SetForceRenderSurface(true);
7043
7044 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7045 host->SetRootLayer(root);
7046
7047 ExecuteCalculateDrawProperties(root.get());
7048
7049 EXPECT_EQ(2u, render_surface_layer_list()->size());
7050 EXPECT_EQ(1u,
7051 render_surface_layer_list()->at(0)
7052 ->render_surface()->layer_list().size());
7053 EXPECT_EQ(1u,
7054 render_surface_layer_list()->at(1)
7055 ->render_surface()->layer_list().size());
7056
7057 gfx::Transform rotation_transform = identity_transform;
7058 rotation_transform.RotateAboutXAxis(180.0);
7059
7060 render_surface->SetTransform(rotation_transform);
7061
7062 ExecuteCalculateDrawProperties(root.get());
7063
7064 EXPECT_EQ(1u, render_surface_layer_list()->size());
7065 EXPECT_EQ(0u,
7066 render_surface_layer_list()->at(0)
7067 ->render_surface()->layer_list().size());
7068}
7069
[email protected]995708c52013-10-17 20:52:597070TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
7071 // Checks that the simple case (being clipped by a scroll parent that would
7072 // have been processed before you anyhow) results in the right clips.
7073 //
7074 // + root
7075 // + scroll_parent_border
7076 // | + scroll_parent_clip
7077 // | + scroll_parent
7078 // + scroll_child
7079 //
7080 scoped_refptr<Layer> root = Layer::Create();
7081 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7082 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7083 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7084 make_scoped_refptr(new LayerWithForcedDrawsContent);
7085 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7086 make_scoped_refptr(new LayerWithForcedDrawsContent);
7087
7088 root->AddChild(scroll_child);
7089
7090 root->AddChild(scroll_parent_border);
7091 scroll_parent_border->AddChild(scroll_parent_clip);
7092 scroll_parent_clip->AddChild(scroll_parent);
7093
7094 scroll_parent_clip->SetMasksToBounds(true);
7095
7096 scroll_child->SetScrollParent(scroll_parent.get());
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]995708c52013-10-17 20:52:597102 gfx::PointF(),
7103 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577104 true,
[email protected]995708c52013-10-17 20:52:597105 false);
7106 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7107 identity_transform,
[email protected]a2566412014-06-05 03:14:207108 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597109 gfx::PointF(),
7110 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577111 true,
[email protected]995708c52013-10-17 20:52:597112 false);
7113 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7114 identity_transform,
[email protected]a2566412014-06-05 03:14:207115 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597116 gfx::PointF(),
7117 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577118 true,
[email protected]995708c52013-10-17 20:52:597119 false);
7120 SetLayerPropertiesForTesting(scroll_parent.get(),
7121 identity_transform,
[email protected]a2566412014-06-05 03:14:207122 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597123 gfx::PointF(),
7124 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577125 true,
[email protected]995708c52013-10-17 20:52:597126 false);
7127 SetLayerPropertiesForTesting(scroll_child.get(),
7128 identity_transform,
[email protected]a2566412014-06-05 03:14:207129 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597130 gfx::PointF(),
7131 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577132 true,
[email protected]995708c52013-10-17 20:52:597133 false);
7134
7135 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7136 host->SetRootLayer(root);
7137
7138 ExecuteCalculateDrawProperties(root.get());
7139
7140 EXPECT_TRUE(root->render_surface());
7141
7142 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7143 scroll_child->clip_rect().ToString());
7144 EXPECT_TRUE(scroll_child->is_clipped());
7145}
7146
[email protected]08bdf1b2014-04-16 23:23:297147TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
7148 scoped_refptr<LayerWithForcedDrawsContent> root =
7149 make_scoped_refptr(new LayerWithForcedDrawsContent);
7150 scoped_refptr<LayerWithForcedDrawsContent> parent =
7151 make_scoped_refptr(new LayerWithForcedDrawsContent);
7152 scoped_refptr<LayerWithForcedDrawsContent> child =
7153 make_scoped_refptr(new LayerWithForcedDrawsContent);
7154
7155 root->AddChild(parent);
7156 parent->AddChild(child);
7157
7158 gfx::Transform identity_transform;
7159 SetLayerPropertiesForTesting(root.get(),
7160 identity_transform,
[email protected]a2566412014-06-05 03:14:207161 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297162 gfx::PointF(),
7163 gfx::Size(50, 50),
7164 true,
7165 true);
7166 root->SetForceRenderSurface(true);
7167 SetLayerPropertiesForTesting(parent.get(),
7168 identity_transform,
[email protected]a2566412014-06-05 03:14:207169 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297170 gfx::PointF(),
7171 gfx::Size(30, 30),
7172 true,
7173 true);
7174 parent->SetForceRenderSurface(true);
7175 SetLayerPropertiesForTesting(child.get(),
7176 identity_transform,
[email protected]a2566412014-06-05 03:14:207177 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297178 gfx::PointF(),
7179 gfx::Size(20, 20),
7180 true,
7181 true);
7182 child->SetForceRenderSurface(true);
7183
7184 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7185 host->SetRootLayer(root);
7186
7187 ExecuteCalculateDrawProperties(root.get());
7188
7189 EXPECT_EQ(3u, render_surface_layer_list()->size());
7190
7191 gfx::Transform singular_transform;
7192 singular_transform.Scale3d(
7193 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7194
7195 child->SetTransform(singular_transform);
7196
7197 ExecuteCalculateDrawProperties(root.get());
7198
7199 EXPECT_EQ(2u, render_surface_layer_list()->size());
7200
7201 // Ensure that the entire subtree under a layer with singular transform does
7202 // not get rendered.
7203 parent->SetTransform(singular_transform);
7204 child->SetTransform(identity_transform);
7205
7206 ExecuteCalculateDrawProperties(root.get());
7207
7208 EXPECT_EQ(1u, render_surface_layer_list()->size());
7209}
7210
[email protected]995708c52013-10-17 20:52:597211TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
7212 // Checks that clipping by a scroll parent that follows you in paint order
7213 // still results in correct clipping.
7214 //
7215 // + root
7216 // + scroll_child
7217 // + scroll_parent_border
7218 // + scroll_parent_clip
7219 // + scroll_parent
7220 //
7221 scoped_refptr<Layer> root = Layer::Create();
7222 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7223 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7224 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7225 make_scoped_refptr(new LayerWithForcedDrawsContent);
7226 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7227 make_scoped_refptr(new LayerWithForcedDrawsContent);
7228
7229 root->AddChild(scroll_parent_border);
7230 scroll_parent_border->AddChild(scroll_parent_clip);
7231 scroll_parent_clip->AddChild(scroll_parent);
7232
7233 root->AddChild(scroll_child);
7234
7235 scroll_parent_clip->SetMasksToBounds(true);
7236
7237 scroll_child->SetScrollParent(scroll_parent.get());
7238
7239 gfx::Transform identity_transform;
7240 SetLayerPropertiesForTesting(root.get(),
7241 identity_transform,
[email protected]a2566412014-06-05 03:14:207242 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597243 gfx::PointF(),
7244 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577245 true,
[email protected]995708c52013-10-17 20:52:597246 false);
7247 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7248 identity_transform,
[email protected]a2566412014-06-05 03:14:207249 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597250 gfx::PointF(),
7251 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577252 true,
[email protected]995708c52013-10-17 20:52:597253 false);
7254 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7255 identity_transform,
[email protected]a2566412014-06-05 03:14:207256 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597257 gfx::PointF(),
7258 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577259 true,
[email protected]995708c52013-10-17 20:52:597260 false);
7261 SetLayerPropertiesForTesting(scroll_parent.get(),
7262 identity_transform,
[email protected]a2566412014-06-05 03:14:207263 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597264 gfx::PointF(),
7265 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577266 true,
[email protected]995708c52013-10-17 20:52:597267 false);
7268 SetLayerPropertiesForTesting(scroll_child.get(),
7269 identity_transform,
[email protected]a2566412014-06-05 03:14:207270 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597271 gfx::PointF(),
7272 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577273 true,
[email protected]995708c52013-10-17 20:52:597274 false);
7275
7276 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7277 host->SetRootLayer(root);
7278
7279 ExecuteCalculateDrawProperties(root.get());
7280
7281 EXPECT_TRUE(root->render_surface());
7282
7283 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7284 scroll_child->clip_rect().ToString());
7285 EXPECT_TRUE(scroll_child->is_clipped());
7286}
7287
7288TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
7289 // Checks that clipping by a scroll parent and scroll grandparent that follow
7290 // you in paint order still results in correct clipping.
7291 //
7292 // + root
7293 // + scroll_child
7294 // + scroll_parent_border
7295 // | + scroll_parent_clip
7296 // | + scroll_parent
7297 // + scroll_grandparent_border
7298 // + scroll_grandparent_clip
7299 // + scroll_grandparent
7300 //
7301 scoped_refptr<Layer> root = Layer::Create();
7302 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7303 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7304 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7305 make_scoped_refptr(new LayerWithForcedDrawsContent);
7306
7307 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
7308 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
7309 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
7310 make_scoped_refptr(new LayerWithForcedDrawsContent);
7311
7312 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7313 make_scoped_refptr(new LayerWithForcedDrawsContent);
7314
7315 root->AddChild(scroll_child);
7316
7317 root->AddChild(scroll_parent_border);
7318 scroll_parent_border->AddChild(scroll_parent_clip);
7319 scroll_parent_clip->AddChild(scroll_parent);
7320
7321 root->AddChild(scroll_grandparent_border);
7322 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7323 scroll_grandparent_clip->AddChild(scroll_grandparent);
7324
7325 scroll_parent_clip->SetMasksToBounds(true);
7326 scroll_grandparent_clip->SetMasksToBounds(true);
7327
7328 scroll_child->SetScrollParent(scroll_parent.get());
7329 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7330
7331 gfx::Transform identity_transform;
7332 SetLayerPropertiesForTesting(root.get(),
7333 identity_transform,
[email protected]a2566412014-06-05 03:14:207334 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597335 gfx::PointF(),
7336 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577337 true,
[email protected]995708c52013-10-17 20:52:597338 false);
7339 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7340 identity_transform,
[email protected]a2566412014-06-05 03:14:207341 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597342 gfx::PointF(),
7343 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577344 true,
[email protected]995708c52013-10-17 20:52:597345 false);
7346 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7347 identity_transform,
[email protected]a2566412014-06-05 03:14:207348 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597349 gfx::PointF(),
7350 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577351 true,
[email protected]995708c52013-10-17 20:52:597352 false);
7353 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7354 identity_transform,
[email protected]a2566412014-06-05 03:14:207355 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597356 gfx::PointF(),
7357 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577358 true,
[email protected]995708c52013-10-17 20:52:597359 false);
7360 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7361 identity_transform,
[email protected]a2566412014-06-05 03:14:207362 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597363 gfx::PointF(),
7364 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577365 true,
[email protected]995708c52013-10-17 20:52:597366 false);
7367 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7368 identity_transform,
[email protected]a2566412014-06-05 03:14:207369 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597370 gfx::PointF(),
7371 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577372 true,
[email protected]995708c52013-10-17 20:52:597373 false);
7374 SetLayerPropertiesForTesting(scroll_parent.get(),
7375 identity_transform,
[email protected]a2566412014-06-05 03:14:207376 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597377 gfx::PointF(),
7378 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577379 true,
[email protected]995708c52013-10-17 20:52:597380 false);
7381 SetLayerPropertiesForTesting(scroll_child.get(),
7382 identity_transform,
[email protected]a2566412014-06-05 03:14:207383 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597384 gfx::PointF(),
7385 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577386 true,
[email protected]995708c52013-10-17 20:52:597387 false);
7388
7389 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7390 host->SetRootLayer(root);
7391
7392 ExecuteCalculateDrawProperties(root.get());
7393
7394 EXPECT_TRUE(root->render_surface());
7395
7396 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7397 scroll_child->clip_rect().ToString());
7398 EXPECT_TRUE(scroll_child->is_clipped());
7399
7400 // Despite the fact that we visited the above layers out of order to get the
7401 // correct clip, the layer lists should be unaffected.
7402 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
7403 EXPECT_EQ(scroll_child.get(),
7404 root->render_surface()->layer_list().at(0));
7405 EXPECT_EQ(scroll_parent.get(),
7406 root->render_surface()->layer_list().at(1));
7407 EXPECT_EQ(scroll_grandparent.get(),
7408 root->render_surface()->layer_list().at(2));
7409}
7410
7411TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
7412 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:227413 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:597414 // + root
7415 // + scroll_child
7416 // + scroll_parent_border
7417 // + scroll_parent_clip
7418 // + scroll_parent
7419 // + render_surface1
7420 // + scroll_grandparent_border
7421 // + scroll_grandparent_clip
7422 // + scroll_grandparent
7423 // + render_surface2
7424 //
[email protected]44d8e84c2013-10-19 19:13:227425 scoped_refptr<LayerWithForcedDrawsContent> root =
7426 make_scoped_refptr(new LayerWithForcedDrawsContent);
[email protected]995708c52013-10-17 20:52:597427
7428 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7429 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7430 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7431 make_scoped_refptr(new LayerWithForcedDrawsContent);
7432 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
7433 make_scoped_refptr(new LayerWithForcedDrawsContent);
7434
7435 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
7436 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
7437 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
7438 make_scoped_refptr(new LayerWithForcedDrawsContent);
7439 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
7440 make_scoped_refptr(new LayerWithForcedDrawsContent);
7441
7442 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7443 make_scoped_refptr(new LayerWithForcedDrawsContent);
7444
7445 root->AddChild(scroll_child);
7446
7447 root->AddChild(scroll_parent_border);
7448 scroll_parent_border->AddChild(scroll_parent_clip);
7449 scroll_parent_clip->AddChild(scroll_parent);
7450 scroll_parent->AddChild(render_surface2);
7451
7452 root->AddChild(scroll_grandparent_border);
7453 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7454 scroll_grandparent_clip->AddChild(scroll_grandparent);
7455 scroll_grandparent->AddChild(render_surface1);
7456
7457 scroll_parent_clip->SetMasksToBounds(true);
7458 scroll_grandparent_clip->SetMasksToBounds(true);
7459
7460 scroll_child->SetScrollParent(scroll_parent.get());
7461 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7462
7463 render_surface1->SetForceRenderSurface(true);
7464 render_surface2->SetForceRenderSurface(true);
7465
7466 gfx::Transform identity_transform;
7467 SetLayerPropertiesForTesting(root.get(),
7468 identity_transform,
[email protected]a2566412014-06-05 03:14:207469 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597470 gfx::PointF(),
7471 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577472 true,
[email protected]995708c52013-10-17 20:52:597473 false);
7474 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7475 identity_transform,
[email protected]a2566412014-06-05 03:14:207476 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597477 gfx::PointF(),
7478 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577479 true,
[email protected]995708c52013-10-17 20:52:597480 false);
7481 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7482 identity_transform,
[email protected]a2566412014-06-05 03:14:207483 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597484 gfx::PointF(),
7485 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577486 true,
[email protected]995708c52013-10-17 20:52:597487 false);
7488 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7489 identity_transform,
[email protected]a2566412014-06-05 03:14:207490 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597491 gfx::PointF(),
7492 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577493 true,
[email protected]995708c52013-10-17 20:52:597494 false);
7495 SetLayerPropertiesForTesting(render_surface1.get(),
7496 identity_transform,
[email protected]a2566412014-06-05 03:14:207497 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597498 gfx::PointF(),
7499 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577500 true,
[email protected]995708c52013-10-17 20:52:597501 false);
7502 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7503 identity_transform,
[email protected]a2566412014-06-05 03:14:207504 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597505 gfx::PointF(),
7506 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577507 true,
[email protected]995708c52013-10-17 20:52:597508 false);
7509 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7510 identity_transform,
[email protected]a2566412014-06-05 03:14:207511 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597512 gfx::PointF(),
7513 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577514 true,
[email protected]995708c52013-10-17 20:52:597515 false);
7516 SetLayerPropertiesForTesting(scroll_parent.get(),
7517 identity_transform,
[email protected]a2566412014-06-05 03:14:207518 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597519 gfx::PointF(),
7520 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577521 true,
[email protected]995708c52013-10-17 20:52:597522 false);
7523 SetLayerPropertiesForTesting(render_surface2.get(),
7524 identity_transform,
[email protected]a2566412014-06-05 03:14:207525 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597526 gfx::PointF(),
7527 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577528 true,
[email protected]995708c52013-10-17 20:52:597529 false);
7530 SetLayerPropertiesForTesting(scroll_child.get(),
7531 identity_transform,
[email protected]a2566412014-06-05 03:14:207532 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597533 gfx::PointF(),
7534 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577535 true,
[email protected]995708c52013-10-17 20:52:597536 false);
7537
7538 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7539 host->SetRootLayer(root);
7540
7541 RenderSurfaceLayerList render_surface_layer_list;
7542 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7543 root.get(),
7544 root->bounds(),
7545 identity_transform,
7546 &render_surface_layer_list);
7547
7548 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7549
7550 EXPECT_TRUE(root->render_surface());
7551
7552 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7553 scroll_child->clip_rect().ToString());
7554 EXPECT_TRUE(scroll_child->is_clipped());
7555
7556 // Despite the fact that we had to process the layers out of order to get the
7557 // right clip, our render_surface_layer_list's order should be unaffected.
7558 EXPECT_EQ(3u, render_surface_layer_list.size());
7559 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
7560 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
7561 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
[email protected]44d8e84c2013-10-19 19:13:227562 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
7563 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
7564 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:597565}
7566
7567TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) {
7568 // We rearrange layer list contributions if we have to visit children out of
7569 // order, but it should be a 'stable' rearrangement. That is, the layer list
7570 // additions for a single layer should not be reordered, though their position
7571 // wrt to the contributions due to a sibling may vary.
7572 //
7573 // + root
7574 // + scroll_child
7575 // + top_content
7576 // + bottom_content
7577 // + scroll_parent_border
7578 // + scroll_parent_clip
7579 // + scroll_parent
7580 //
7581 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457582 TestSharedBitmapManager shared_bitmap_manager;
7583 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]995708c52013-10-17 20:52:597584 host_impl.CreatePendingTree();
7585 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7586 scoped_ptr<LayerImpl> scroll_parent_border =
7587 LayerImpl::Create(host_impl.active_tree(), 2);
7588 scoped_ptr<LayerImpl> scroll_parent_clip =
7589 LayerImpl::Create(host_impl.active_tree(), 3);
7590 scoped_ptr<LayerImpl> scroll_parent =
7591 LayerImpl::Create(host_impl.active_tree(), 4);
7592 scoped_ptr<LayerImpl> scroll_child =
7593 LayerImpl::Create(host_impl.active_tree(), 5);
7594 scoped_ptr<LayerImpl> bottom_content =
7595 LayerImpl::Create(host_impl.active_tree(), 6);
7596 scoped_ptr<LayerImpl> top_content =
7597 LayerImpl::Create(host_impl.active_tree(), 7);
7598
7599 scroll_parent_clip->SetMasksToBounds(true);
7600
7601 scroll_child->SetScrollParent(scroll_parent.get());
7602 scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>);
7603 scroll_children->insert(scroll_child.get());
7604 scroll_parent->SetScrollChildren(scroll_children.release());
7605
7606 scroll_child->SetDrawsContent(true);
7607 scroll_parent->SetDrawsContent(true);
7608 top_content->SetDrawsContent(true);
7609 bottom_content->SetDrawsContent(true);
7610
7611 gfx::Transform identity_transform;
7612 gfx::Transform top_transform;
7613 top_transform.Translate3d(0.0, 0.0, 5.0);
7614 gfx::Transform bottom_transform;
7615 bottom_transform.Translate3d(0.0, 0.0, 3.0);
7616
7617 SetLayerPropertiesForTesting(root.get(),
7618 identity_transform,
[email protected]a2566412014-06-05 03:14:207619 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597620 gfx::PointF(),
7621 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577622 true,
[email protected]995708c52013-10-17 20:52:597623 false);
7624 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7625 identity_transform,
[email protected]a2566412014-06-05 03:14:207626 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597627 gfx::PointF(),
7628 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577629 true,
[email protected]995708c52013-10-17 20:52:597630 false);
7631 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7632 identity_transform,
[email protected]a2566412014-06-05 03:14:207633 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597634 gfx::PointF(),
7635 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577636 true,
[email protected]995708c52013-10-17 20:52:597637 false);
7638 SetLayerPropertiesForTesting(scroll_parent.get(),
7639 identity_transform,
[email protected]a2566412014-06-05 03:14:207640 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597641 gfx::PointF(),
7642 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577643 true,
[email protected]995708c52013-10-17 20:52:597644 false);
7645 SetLayerPropertiesForTesting(scroll_child.get(),
7646 identity_transform,
[email protected]a2566412014-06-05 03:14:207647 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597648 gfx::PointF(),
7649 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577650 true,
[email protected]995708c52013-10-17 20:52:597651 false);
7652 SetLayerPropertiesForTesting(top_content.get(),
7653 top_transform,
[email protected]a2566412014-06-05 03:14:207654 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597655 gfx::PointF(),
7656 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577657 false,
7658 true);
[email protected]995708c52013-10-17 20:52:597659 SetLayerPropertiesForTesting(bottom_content.get(),
7660 bottom_transform,
[email protected]a2566412014-06-05 03:14:207661 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597662 gfx::PointF(),
7663 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577664 false,
7665 true);
[email protected]995708c52013-10-17 20:52:597666
[email protected]56fffdd2014-02-11 19:50:577667 scroll_child->SetShouldFlattenTransform(false);
7668 scroll_child->SetIs3dSorted(true);
[email protected]995708c52013-10-17 20:52:597669
7670 scroll_child->AddChild(top_content.Pass());
7671 scroll_child->AddChild(bottom_content.Pass());
7672 root->AddChild(scroll_child.Pass());
7673
7674 scroll_parent_clip->AddChild(scroll_parent.Pass());
7675 scroll_parent_border->AddChild(scroll_parent_clip.Pass());
7676 root->AddChild(scroll_parent_border.Pass());
7677
7678 LayerImplList render_surface_layer_list;
7679 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7680 root.get(), root->bounds(), &render_surface_layer_list);
7681
7682 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7683
7684 EXPECT_TRUE(root->render_surface());
7685
7686 // If we don't sort by depth and let the layers get added in the order they
7687 // would normally be visited in, then layers 6 and 7 will be out of order. In
7688 // other words, although we've had to shift 5, 6, and 7 to appear before 4
7689 // in the list (because of the scroll parent relationship), this should not
7690 // have an effect on the the order of 5, 6, and 7 (which had been reordered
7691 // due to layer sorting).
7692 EXPECT_EQ(4u, root->render_surface()->layer_list().size());
7693 EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id());
7694 EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id());
7695 EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id());
7696 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
7697}
7698
[email protected]d81752b2013-10-25 08:32:237699TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
7700 // This test verifies that a scrolling layer that gets snapped to
7701 // integer coordinates doesn't move a fixed position child.
7702 //
7703 // + root
7704 // + container
7705 // + scroller
7706 // + fixed
7707 //
7708 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457709 TestSharedBitmapManager shared_bitmap_manager;
7710 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]d81752b2013-10-25 08:32:237711 host_impl.CreatePendingTree();
7712 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7713 scoped_ptr<LayerImpl> container =
7714 LayerImpl::Create(host_impl.active_tree(), 2);
7715 LayerImpl* container_layer = container.get();
7716 scoped_ptr<LayerImpl> scroller =
7717 LayerImpl::Create(host_impl.active_tree(), 3);
7718 LayerImpl* scroll_layer = scroller.get();
7719 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7720 LayerImpl* fixed_layer = fixed.get();
7721
7722 container->SetIsContainerForFixedPositionLayers(true);
7723
7724 LayerPositionConstraint constraint;
7725 constraint.set_is_fixed_position(true);
7726 fixed->SetPositionConstraint(constraint);
7727
[email protected]adeda572014-01-31 00:49:477728 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:237729
7730 gfx::Transform identity_transform;
7731 gfx::Transform container_transform;
7732 container_transform.Translate3d(10.0, 20.0, 0.0);
7733 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7734
7735 SetLayerPropertiesForTesting(root.get(),
7736 identity_transform,
[email protected]a2566412014-06-05 03:14:207737 gfx::Point3F(),
[email protected]d81752b2013-10-25 08:32:237738 gfx::PointF(),
7739 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577740 true,
[email protected]d81752b2013-10-25 08:32:237741 false);
7742 SetLayerPropertiesForTesting(container.get(),
7743 container_transform,
[email protected]a2566412014-06-05 03:14:207744 gfx::Point3F(),
[email protected]d81752b2013-10-25 08:32:237745 gfx::PointF(),
7746 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577747 true,
[email protected]d81752b2013-10-25 08:32:237748 false);
7749 SetLayerPropertiesForTesting(scroller.get(),
7750 identity_transform,
[email protected]a2566412014-06-05 03:14:207751 gfx::Point3F(),
[email protected]d81752b2013-10-25 08:32:237752 gfx::PointF(),
7753 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577754 true,
[email protected]d81752b2013-10-25 08:32:237755 false);
7756 SetLayerPropertiesForTesting(fixed.get(),
7757 identity_transform,
[email protected]a2566412014-06-05 03:14:207758 gfx::Point3F(),
[email protected]d81752b2013-10-25 08:32:237759 gfx::PointF(),
7760 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577761 true,
[email protected]d81752b2013-10-25 08:32:237762 false);
7763
7764 scroller->AddChild(fixed.Pass());
7765 container->AddChild(scroller.Pass());
7766 root->AddChild(container.Pass());
7767
7768 // Rounded to integers already.
7769 {
7770 gfx::Vector2dF scroll_delta(3.0, 5.0);
7771 scroll_layer->SetScrollDelta(scroll_delta);
7772
7773 LayerImplList render_surface_layer_list;
7774 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7775 root.get(), root->bounds(), &render_surface_layer_list);
7776 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7777
7778 EXPECT_TRANSFORMATION_MATRIX_EQ(
7779 container_layer->draw_properties().screen_space_transform,
7780 fixed_layer->draw_properties().screen_space_transform);
7781 EXPECT_VECTOR_EQ(
7782 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7783 container_offset);
7784 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7785 .screen_space_transform.To2dTranslation(),
7786 container_offset - scroll_delta);
7787 }
7788
7789 // Scroll delta requiring rounding.
7790 {
7791 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
7792 scroll_layer->SetScrollDelta(scroll_delta);
7793
7794 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
7795
7796 LayerImplList render_surface_layer_list;
7797 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7798 root.get(), root->bounds(), &render_surface_layer_list);
7799 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7800
7801 EXPECT_TRANSFORMATION_MATRIX_EQ(
7802 container_layer->draw_properties().screen_space_transform,
7803 fixed_layer->draw_properties().screen_space_transform);
7804 EXPECT_VECTOR_EQ(
7805 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7806 container_offset);
7807 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7808 .screen_space_transform.To2dTranslation(),
7809 container_offset - rounded_scroll_delta);
7810 }
[email protected]cf15ad7b2014-04-02 03:59:267811
7812 // Scale is applied earlier in the tree.
7813 {
7814 gfx::Transform scaled_container_transform = container_transform;
7815 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
7816 container_layer->SetTransform(scaled_container_transform);
7817
7818 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7819 scroll_layer->SetScrollDelta(scroll_delta);
7820
7821 LayerImplList render_surface_layer_list;
7822 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7823 root.get(), root->bounds(), &render_surface_layer_list);
7824 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7825
7826 EXPECT_TRANSFORMATION_MATRIX_EQ(
7827 container_layer->draw_properties().screen_space_transform,
7828 fixed_layer->draw_properties().screen_space_transform);
7829 EXPECT_VECTOR_EQ(
7830 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7831 container_offset);
7832
7833 container_layer->SetTransform(container_transform);
7834 }
7835
7836 // Scale is applied on the scroll layer itself.
7837 {
7838 gfx::Transform scale_transform;
7839 scale_transform.Scale3d(3.0, 3.0, 1.0);
7840 scroll_layer->SetTransform(scale_transform);
7841
7842 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7843 scroll_layer->SetScrollDelta(scroll_delta);
7844
7845 LayerImplList render_surface_layer_list;
7846 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7847 root.get(), root->bounds(), &render_surface_layer_list);
7848 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7849
7850 EXPECT_VECTOR_EQ(
7851 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7852 container_offset);
7853
7854 scroll_layer->SetTransform(identity_transform);
7855 }
[email protected]d81752b2013-10-25 08:32:237856}
7857
[email protected]1c3626e2014-04-09 17:49:227858class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7859 public:
7860 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
7861 LayerTreeImpl* tree_impl,
7862 int id) {
7863 return make_scoped_ptr(
7864 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7865 }
7866
7867 virtual ~AnimationScaleFactorTrackingLayerImpl() {}
7868
7869 virtual void CalculateContentsScale(float ideal_contents_scale,
7870 float device_scale_factor,
7871 float page_scale_factor,
7872 float maximum_animation_contents_scale,
7873 bool animating_transform_to_screen,
7874 float* contents_scale_x,
7875 float* contents_scale_y,
7876 gfx::Size* content_bounds) OVERRIDE {
7877 last_maximum_animation_contents_scale_ = maximum_animation_contents_scale;
7878 LayerImpl::CalculateContentsScale(ideal_contents_scale,
7879 device_scale_factor,
7880 page_scale_factor,
7881 maximum_animation_contents_scale,
7882 animating_transform_to_screen,
7883 contents_scale_x,
7884 contents_scale_y,
7885 content_bounds);
7886 }
7887
7888 float last_maximum_animation_contents_scale() {
7889 return last_maximum_animation_contents_scale_;
7890 }
7891
7892 private:
7893 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7894 int id)
7895 : LayerImpl(tree_impl, id), last_maximum_animation_contents_scale_(0.f) {
7896 SetDrawsContent(true);
7897 }
7898
7899 float last_maximum_animation_contents_scale_;
7900};
7901
7902TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
7903 FakeImplProxy proxy;
7904 TestSharedBitmapManager shared_bitmap_manager;
7905 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7906 gfx::Transform identity_matrix;
7907 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
7908 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
7909 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
7910 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
7911 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
7912 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
7913 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
7914 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7915
7916 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7917 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7918 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
7919
7920 child->AddChild(grand_child.PassAs<LayerImpl>());
7921 parent->AddChild(child.PassAs<LayerImpl>());
7922 grand_parent->AddChild(parent.PassAs<LayerImpl>());
7923
7924 SetLayerPropertiesForTesting(grand_parent.get(),
7925 identity_matrix,
[email protected]a2566412014-06-05 03:14:207926 gfx::Point3F(),
[email protected]1c3626e2014-04-09 17:49:227927 gfx::PointF(),
7928 gfx::Size(1, 2),
7929 true,
7930 false);
7931 SetLayerPropertiesForTesting(parent_raw,
7932 identity_matrix,
[email protected]a2566412014-06-05 03:14:207933 gfx::Point3F(),
[email protected]1c3626e2014-04-09 17:49:227934 gfx::PointF(),
7935 gfx::Size(1, 2),
7936 true,
7937 false);
7938 SetLayerPropertiesForTesting(child_raw,
7939 identity_matrix,
[email protected]a2566412014-06-05 03:14:207940 gfx::Point3F(),
[email protected]1c3626e2014-04-09 17:49:227941 gfx::PointF(),
7942 gfx::Size(1, 2),
7943 true,
7944 false);
7945 SetLayerPropertiesForTesting(grand_child_raw,
7946 identity_matrix,
[email protected]a2566412014-06-05 03:14:207947 gfx::Point3F(),
[email protected]1c3626e2014-04-09 17:49:227948 gfx::PointF(),
7949 gfx::Size(1, 2),
7950 true,
7951 false);
7952
7953 ExecuteCalculateDrawProperties(grand_parent.get());
7954
7955 // No layers have animations.
7956 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
7957 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
7958 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
7959 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
7960
7961 TransformOperations translation;
7962 translation.AppendTranslate(1.f, 2.f, 3.f);
7963
7964 AddAnimatedTransformToLayer(
7965 parent_raw, 1.0, TransformOperations(), translation);
7966
7967 // No layers have scale-affecting animations.
7968 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
7969 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
7970 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
7971 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
7972
7973 TransformOperations scale;
7974 scale.AppendScale(5.f, 4.f, 3.f);
7975
7976 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
7977 ExecuteCalculateDrawProperties(grand_parent.get());
7978
7979 // Only |child| has a scale-affecting animation.
7980 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
7981 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
7982 EXPECT_EQ(5.f, child_raw->last_maximum_animation_contents_scale());
7983 EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_contents_scale());
7984
7985 AddAnimatedTransformToLayer(
7986 grand_parent.get(), 1.0, TransformOperations(), scale);
7987 ExecuteCalculateDrawProperties(grand_parent.get());
7988
7989 // |grand_parent| and |child| have scale-affecting animations.
7990 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale());
7991 EXPECT_EQ(5.f, parent_raw->last_maximum_animation_contents_scale());
7992 // We don't support combining animated scales from two nodes; 0.f means
7993 // that the maximum scale could not be computed.
7994 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
7995 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
7996
7997 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
7998 ExecuteCalculateDrawProperties(grand_parent.get());
7999
8000 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
8001 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale());
8002 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
8003 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
8004 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
8005
8006 grand_parent->layer_animation_controller()->AbortAnimations(
8007 Animation::Transform);
8008 parent_raw->layer_animation_controller()->AbortAnimations(
8009 Animation::Transform);
8010 child_raw->layer_animation_controller()->AbortAnimations(
8011 Animation::Transform);
8012
8013 TransformOperations perspective;
8014 perspective.AppendPerspective(10.f);
8015
8016 AddAnimatedTransformToLayer(
8017 child_raw, 1.0, TransformOperations(), perspective);
8018 ExecuteCalculateDrawProperties(grand_parent.get());
8019
8020 // |child| has a scale-affecting animation but computing the maximum of this
8021 // animation is not supported.
8022 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
8023 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
8024 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
8025 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
8026
8027 child_raw->layer_animation_controller()->AbortAnimations(
8028 Animation::Transform);
8029
8030 gfx::Transform scale_matrix;
8031 scale_matrix.Scale(1.f, 2.f);
8032 grand_parent->SetTransform(scale_matrix);
8033 parent_raw->SetTransform(scale_matrix);
8034 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
8035 ExecuteCalculateDrawProperties(grand_parent.get());
8036
8037 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
8038 // animation with maximum scale 5.f.
8039 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
8040 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale());
8041 EXPECT_EQ(10.f, child_raw->last_maximum_animation_contents_scale());
8042 EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_contents_scale());
8043
8044 gfx::Transform perspective_matrix;
8045 perspective_matrix.ApplyPerspectiveDepth(2.f);
8046 child_raw->SetTransform(perspective_matrix);
8047 ExecuteCalculateDrawProperties(grand_parent.get());
8048
8049 // |child| has a transform that's neither a translation nor a scale.
8050 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
8051 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale());
8052 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
8053 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
8054
8055 parent_raw->SetTransform(perspective_matrix);
8056 ExecuteCalculateDrawProperties(grand_parent.get());
8057
8058 // |parent| and |child| have transforms that are neither translations nor
8059 // scales.
8060 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
8061 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
8062 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
8063 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
8064
8065 parent_raw->SetTransform(identity_matrix);
8066 child_raw->SetTransform(identity_matrix);
8067 grand_parent->SetTransform(perspective_matrix);
8068
8069 ExecuteCalculateDrawProperties(grand_parent.get());
8070
8071 // |grand_parent| has a transform that's neither a translation nor a scale.
8072 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
8073 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
8074 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
8075 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
8076}
8077
[email protected]390bb1ff2014-05-09 17:14:408078static int membership_id(LayerImpl* layer) {
8079 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
8080}
8081
8082static void GatherDrawnLayers(LayerImplList* rsll,
8083 std::set<LayerImpl*>* drawn_layers) {
8084 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll),
8085 end = LayerIterator<LayerImpl>::End(rsll);
8086 it != end;
8087 ++it) {
8088 LayerImpl* layer = *it;
8089 if (it.represents_itself())
8090 drawn_layers->insert(layer);
8091
8092 if (!it.represents_contributing_render_surface())
8093 continue;
8094
8095 if (layer->mask_layer())
8096 drawn_layers->insert(layer->mask_layer());
8097 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
8098 drawn_layers->insert(layer->replica_layer()->mask_layer());
8099 }
8100}
8101
8102TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
8103 FakeImplProxy proxy;
8104 TestSharedBitmapManager shared_bitmap_manager;
8105 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
8106 gfx::Transform identity_matrix;
8107
8108 scoped_ptr<LayerImpl> grand_parent =
8109 LayerImpl::Create(host_impl.active_tree(), 1);
8110 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
8111 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
8112 scoped_ptr<LayerImpl> grand_child1 =
8113 LayerImpl::Create(host_impl.active_tree(), 7);
8114 scoped_ptr<LayerImpl> grand_child2 =
8115 LayerImpl::Create(host_impl.active_tree(), 9);
8116
8117 LayerImpl* grand_parent_raw = grand_parent.get();
8118 LayerImpl* parent_raw = parent.get();
8119 LayerImpl* child_raw = child.get();
8120 LayerImpl* grand_child1_raw = grand_child1.get();
8121 LayerImpl* grand_child2_raw = grand_child2.get();
8122
8123 child->AddChild(grand_child1.Pass());
8124 child->AddChild(grand_child2.Pass());
8125 parent->AddChild(child.Pass());
8126 grand_parent->AddChild(parent.Pass());
8127
8128 SetLayerPropertiesForTesting(grand_parent_raw,
8129 identity_matrix,
[email protected]a2566412014-06-05 03:14:208130 gfx::Point3F(),
[email protected]390bb1ff2014-05-09 17:14:408131 gfx::PointF(),
8132 gfx::Size(1, 2),
8133 true,
8134 false);
8135 SetLayerPropertiesForTesting(parent_raw,
8136 identity_matrix,
[email protected]a2566412014-06-05 03:14:208137 gfx::Point3F(),
[email protected]390bb1ff2014-05-09 17:14:408138 gfx::PointF(),
8139 gfx::Size(1, 2),
8140 true,
8141 false);
8142 SetLayerPropertiesForTesting(child_raw,
8143 identity_matrix,
[email protected]a2566412014-06-05 03:14:208144 gfx::Point3F(),
[email protected]390bb1ff2014-05-09 17:14:408145 gfx::PointF(),
8146 gfx::Size(1, 2),
8147 true,
8148 false);
8149 SetLayerPropertiesForTesting(grand_child1_raw,
8150 identity_matrix,
[email protected]a2566412014-06-05 03:14:208151 gfx::Point3F(),
[email protected]390bb1ff2014-05-09 17:14:408152 gfx::PointF(),
8153 gfx::Size(1, 2),
8154 true,
8155 false);
8156 SetLayerPropertiesForTesting(grand_child2_raw,
8157 identity_matrix,
[email protected]a2566412014-06-05 03:14:208158 gfx::Point3F(),
[email protected]390bb1ff2014-05-09 17:14:408159 gfx::PointF(),
8160 gfx::Size(1, 2),
8161 true,
8162 false);
8163
8164 // Start with nothing being drawn.
8165 ExecuteCalculateDrawProperties(grand_parent_raw);
8166 int member_id = render_surface_layer_list_count();
8167
8168 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8169 EXPECT_NE(member_id, membership_id(parent_raw));
8170 EXPECT_NE(member_id, membership_id(child_raw));
8171 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8172 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8173
8174 std::set<LayerImpl*> expected;
8175 std::set<LayerImpl*> actual;
8176 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8177 EXPECT_EQ(expected, actual);
8178
8179 // If we force render surface, but none of the layers are in the layer list,
8180 // then this layer should not appear in RSLL.
8181 grand_child1_raw->SetForceRenderSurface(true);
8182
8183 ExecuteCalculateDrawProperties(grand_parent_raw);
8184 member_id = render_surface_layer_list_count();
8185
8186 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8187 EXPECT_NE(member_id, membership_id(parent_raw));
8188 EXPECT_NE(member_id, membership_id(child_raw));
8189 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8190 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8191
8192 expected.clear();
8193 actual.clear();
8194 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8195 EXPECT_EQ(expected, actual);
8196
8197 // However, if we say that this layer also draws content, it will appear in
8198 // RSLL.
8199 grand_child1_raw->SetDrawsContent(true);
8200
8201 ExecuteCalculateDrawProperties(grand_parent_raw);
8202 member_id = render_surface_layer_list_count();
8203
8204 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8205 EXPECT_NE(member_id, membership_id(parent_raw));
8206 EXPECT_NE(member_id, membership_id(child_raw));
8207 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8208 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8209
8210 expected.clear();
8211 expected.insert(grand_child1_raw);
8212
8213 actual.clear();
8214 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8215 EXPECT_EQ(expected, actual);
8216
8217 // Now child is forced to have a render surface, and one if its children draws
8218 // content.
8219 grand_child1_raw->SetDrawsContent(false);
8220 grand_child1_raw->SetForceRenderSurface(false);
8221 child_raw->SetForceRenderSurface(true);
8222 grand_child2_raw->SetDrawsContent(true);
8223
8224 ExecuteCalculateDrawProperties(grand_parent_raw);
8225 member_id = render_surface_layer_list_count();
8226
8227 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8228 EXPECT_NE(member_id, membership_id(parent_raw));
8229 EXPECT_NE(member_id, membership_id(child_raw));
8230 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8231 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8232
8233 expected.clear();
8234 expected.insert(grand_child2_raw);
8235
8236 actual.clear();
8237 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8238 EXPECT_EQ(expected, actual);
8239
8240 // Add a mask layer to child.
8241 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass());
8242
8243 ExecuteCalculateDrawProperties(grand_parent_raw);
8244 member_id = render_surface_layer_list_count();
8245
8246 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8247 EXPECT_NE(member_id, membership_id(parent_raw));
8248 EXPECT_NE(member_id, membership_id(child_raw));
8249 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8250 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8251 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8252
8253 expected.clear();
8254 expected.insert(grand_child2_raw);
8255 expected.insert(child_raw->mask_layer());
8256
8257 expected.clear();
8258 expected.insert(grand_child2_raw);
8259 expected.insert(child_raw->mask_layer());
8260
8261 actual.clear();
8262 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8263 EXPECT_EQ(expected, actual);
8264
8265 // Add replica mask layer.
8266 scoped_ptr<LayerImpl> replica_layer =
8267 LayerImpl::Create(host_impl.active_tree(), 20);
8268 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
8269 child_raw->SetReplicaLayer(replica_layer.Pass());
8270
8271 ExecuteCalculateDrawProperties(grand_parent_raw);
8272 member_id = render_surface_layer_list_count();
8273
8274 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8275 EXPECT_NE(member_id, membership_id(parent_raw));
8276 EXPECT_NE(member_id, membership_id(child_raw));
8277 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8278 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
8279 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8280 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8281
8282 expected.clear();
8283 expected.insert(grand_child2_raw);
8284 expected.insert(child_raw->mask_layer());
8285 expected.insert(child_raw->replica_layer()->mask_layer());
8286
8287 actual.clear();
8288 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8289 EXPECT_EQ(expected, actual);
8290
8291 child_raw->TakeReplicaLayer();
8292
8293 // With nothing drawing, we should have no layers.
8294 grand_child2_raw->SetDrawsContent(false);
8295
8296 ExecuteCalculateDrawProperties(grand_parent_raw);
8297 member_id = render_surface_layer_list_count();
8298
8299 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8300 EXPECT_NE(member_id, membership_id(parent_raw));
8301 EXPECT_NE(member_id, membership_id(child_raw));
8302 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
8303 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8304 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8305
8306 expected.clear();
8307 actual.clear();
8308 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8309 EXPECT_EQ(expected, actual);
8310
8311 // Child itself draws means that we should have the child and the mask in the
8312 // list.
8313 child_raw->SetDrawsContent(true);
8314
8315 ExecuteCalculateDrawProperties(grand_parent_raw);
8316 member_id = render_surface_layer_list_count();
8317
8318 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8319 EXPECT_NE(member_id, membership_id(parent_raw));
8320 EXPECT_EQ(member_id, membership_id(child_raw));
8321 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8322 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8323 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8324
8325 expected.clear();
8326 expected.insert(child_raw);
8327 expected.insert(child_raw->mask_layer());
8328 actual.clear();
8329 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8330 EXPECT_EQ(expected, actual);
8331
8332 child_raw->TakeMaskLayer();
8333
8334 // Now everyone's a member!
8335 grand_parent_raw->SetDrawsContent(true);
8336 parent_raw->SetDrawsContent(true);
8337 child_raw->SetDrawsContent(true);
8338 grand_child1_raw->SetDrawsContent(true);
8339 grand_child2_raw->SetDrawsContent(true);
8340
8341 ExecuteCalculateDrawProperties(grand_parent_raw);
8342 member_id = render_surface_layer_list_count();
8343
8344 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
8345 EXPECT_EQ(member_id, membership_id(parent_raw));
8346 EXPECT_EQ(member_id, membership_id(child_raw));
8347 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8348 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8349
8350 expected.clear();
8351 expected.insert(grand_parent_raw);
8352 expected.insert(parent_raw);
8353 expected.insert(child_raw);
8354 expected.insert(grand_child1_raw);
8355 expected.insert(grand_child2_raw);
8356
8357 actual.clear();
8358 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8359 EXPECT_EQ(expected, actual);
8360}
[email protected]18e69652014-06-13 12:50:588361
8362TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
8363 FakeImplProxy proxy;
8364 TestSharedBitmapManager shared_bitmap_manager;
8365 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
8366
8367 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
8368 LayerImpl* root_layer = root.get();
8369 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
8370 LayerImpl* child1_layer = child1.get();
8371 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
8372 LayerImpl* child2_layer = child2.get();
8373
8374 root->AddChild(child1.Pass());
8375 root->AddChild(child2.Pass());
8376
8377 gfx::Transform identity_matrix, scale_transform_child1,
8378 scale_transform_child2;
8379 scale_transform_child1.Scale(2, 3);
8380 scale_transform_child2.Scale(4, 5);
8381
8382 SetLayerPropertiesForTesting(root_layer,
8383 identity_matrix,
8384 gfx::Point3F(),
8385 gfx::PointF(),
8386 gfx::Size(1, 1),
8387 true,
8388 false);
8389 SetLayerPropertiesForTesting(child1_layer,
8390 scale_transform_child1,
8391 gfx::Point3F(),
8392 gfx::PointF(),
8393 gfx::Size(),
8394 true,
8395 false);
8396
8397 child1_layer->SetMaskLayer(
8398 LayerImpl::Create(host_impl.active_tree(), 4).Pass());
8399
8400 scoped_ptr<LayerImpl> replica_layer =
8401 LayerImpl::Create(host_impl.active_tree(), 5);
8402 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
8403 child1_layer->SetReplicaLayer(replica_layer.Pass());
8404
8405 ExecuteCalculateDrawProperties(root_layer);
8406
8407 TransformOperations scale;
8408 scale.AppendScale(5.f, 8.f, 3.f);
8409
8410 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale);
8411 SetLayerPropertiesForTesting(child2_layer,
8412 scale_transform_child2,
8413 gfx::Point3F(),
8414 gfx::PointF(),
8415 gfx::Size(),
8416 true,
8417 false);
8418
8419 ExecuteCalculateDrawProperties(root_layer);
8420
8421 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8422 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale);
8423 EXPECT_FLOAT_EQ(
8424 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8425 EXPECT_FLOAT_EQ(3.f,
8426 child1_layer->replica_layer()
8427 ->mask_layer()
8428 ->draw_properties()
8429 .ideal_contents_scale);
8430 EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale);
8431
8432 EXPECT_FLOAT_EQ(
8433 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8434 EXPECT_FLOAT_EQ(
8435 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8436 EXPECT_FLOAT_EQ(0.f,
8437 child1_layer->mask_layer()
8438 ->draw_properties()
8439 .maximum_animation_contents_scale);
8440 EXPECT_FLOAT_EQ(0.f,
8441 child1_layer->replica_layer()
8442 ->mask_layer()
8443 ->draw_properties()
8444 .maximum_animation_contents_scale);
8445 EXPECT_FLOAT_EQ(
8446 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8447
8448 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8449 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor);
8450 EXPECT_FLOAT_EQ(
8451 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8452 EXPECT_FLOAT_EQ(1.f,
8453 child1_layer->replica_layer()
8454 ->mask_layer()
8455 ->draw_properties()
8456 .page_scale_factor);
8457 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor);
8458
8459 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8460 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8461 EXPECT_FLOAT_EQ(
8462 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8463 EXPECT_FLOAT_EQ(1.f,
8464 child1_layer->replica_layer()
8465 ->mask_layer()
8466 ->draw_properties()
8467 .device_scale_factor);
8468 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8469
8470 // Changing page-scale would affect ideal_contents_scale and
8471 // maximum_animation_contents_scale.
8472
8473 float page_scale_factor = 3.f;
8474 float device_scale_factor = 1.0f;
8475 std::vector<LayerImpl*> render_surface_layer_list;
8476 gfx::Size device_viewport_size =
8477 gfx::Size(root_layer->bounds().width() * device_scale_factor,
8478 root_layer->bounds().height() * device_scale_factor);
8479 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8480 root_layer, device_viewport_size, &render_surface_layer_list);
8481
8482 inputs.page_scale_factor = page_scale_factor;
8483 inputs.can_adjust_raster_scales = true;
8484 inputs.page_scale_application_layer = root_layer;
8485 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8486
8487 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8488 EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale);
8489 EXPECT_FLOAT_EQ(
8490 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8491 EXPECT_FLOAT_EQ(9.f,
8492 child1_layer->replica_layer()
8493 ->mask_layer()
8494 ->draw_properties()
8495 .ideal_contents_scale);
8496 EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale);
8497
8498 EXPECT_FLOAT_EQ(
8499 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8500 EXPECT_FLOAT_EQ(
8501 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8502 EXPECT_FLOAT_EQ(0.f,
8503 child1_layer->mask_layer()
8504 ->draw_properties()
8505 .maximum_animation_contents_scale);
8506 EXPECT_FLOAT_EQ(0.f,
8507 child1_layer->replica_layer()
8508 ->mask_layer()
8509 ->draw_properties()
8510 .maximum_animation_contents_scale);
8511 EXPECT_FLOAT_EQ(
8512 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8513
8514 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8515 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8516 EXPECT_FLOAT_EQ(
8517 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8518 EXPECT_FLOAT_EQ(3.f,
8519 child1_layer->replica_layer()
8520 ->mask_layer()
8521 ->draw_properties()
8522 .page_scale_factor);
8523 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8524
8525 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8526 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8527 EXPECT_FLOAT_EQ(
8528 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8529 EXPECT_FLOAT_EQ(1.f,
8530 child1_layer->replica_layer()
8531 ->mask_layer()
8532 ->draw_properties()
8533 .device_scale_factor);
8534 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8535
8536 // Changing device-scale would affect ideal_contents_scale and
8537 // maximum_animation_contents_scale.
8538
8539 device_scale_factor = 4.0f;
8540 inputs.device_scale_factor = device_scale_factor;
8541 inputs.can_adjust_raster_scales = true;
8542 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8543
8544 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale);
8545 EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale);
8546 EXPECT_FLOAT_EQ(
8547 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8548 EXPECT_FLOAT_EQ(36.f,
8549 child1_layer->replica_layer()
8550 ->mask_layer()
8551 ->draw_properties()
8552 .ideal_contents_scale);
8553 EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale);
8554
8555 EXPECT_FLOAT_EQ(
8556 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8557 EXPECT_FLOAT_EQ(
8558 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8559 EXPECT_FLOAT_EQ(0.f,
8560 child1_layer->mask_layer()
8561 ->draw_properties()
8562 .maximum_animation_contents_scale);
8563 EXPECT_FLOAT_EQ(0.f,
8564 child1_layer->replica_layer()
8565 ->mask_layer()
8566 ->draw_properties()
8567 .maximum_animation_contents_scale);
8568 EXPECT_FLOAT_EQ(
8569 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8570
8571 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8572 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8573 EXPECT_FLOAT_EQ(
8574 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8575 EXPECT_FLOAT_EQ(3.f,
8576 child1_layer->replica_layer()
8577 ->mask_layer()
8578 ->draw_properties()
8579 .page_scale_factor);
8580 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8581
8582 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor);
8583 EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor);
8584 EXPECT_FLOAT_EQ(
8585 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8586 EXPECT_FLOAT_EQ(4.f,
8587 child1_layer->replica_layer()
8588 ->mask_layer()
8589 ->draw_properties()
8590 .device_scale_factor);
8591 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor);
8592}
8593
[email protected]ba565742012-11-10 09:29:488594} // namespace
8595} // namespace cc