blob: ad4f60bb5a62c9b88922d7fc2870856d80b6d0aa [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"
14#include "cc/layers/heads_up_display_layer_impl.h"
15#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5916#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5217#include "cc/layers/layer_impl.h"
[email protected]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]556fd292013-03-18 08:03:0427#include "cc/trees/layer_tree_impl.h"
28#include "cc/trees/proxy.h"
29#include "cc/trees/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:1830#include "testing/gmock/include/gmock/gmock.h"
31#include "testing/gtest/include/gtest/gtest.h"
[email protected]93698c12012-12-07 00:43:5632#include "ui/gfx/quad_f.h"
33#include "ui/gfx/size_conversions.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]989386c2013-07-18 21:37:2339class LayerTreeHostCommonTestBase {
40 protected:
41 template <typename LayerType>
42 void SetLayerPropertiesForTestingInternal(
43 LayerType* layer,
44 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:4745 const gfx::PointF& anchor,
46 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:2647 const gfx::Size& bounds,
[email protected]56fffdd2014-02-11 19:50:5748 bool flatten_transform,
49 bool is_3d_sorted) {
[email protected]989386c2013-07-18 21:37:2350 layer->SetTransform(transform);
[email protected]989386c2013-07-18 21:37:2351 layer->SetAnchorPoint(anchor);
52 layer->SetPosition(position);
53 layer->SetBounds(bounds);
[email protected]56fffdd2014-02-11 19:50:5754 layer->SetShouldFlattenTransform(flatten_transform);
55 layer->SetIs3dSorted(is_3d_sorted);
[email protected]989386c2013-07-18 21:37:2356 }
[email protected]94f206c12012-08-25 00:09:1457
[email protected]989386c2013-07-18 21:37:2358 void SetLayerPropertiesForTesting(Layer* layer,
59 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:4760 const gfx::PointF& anchor,
61 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:2662 const gfx::Size& bounds,
[email protected]56fffdd2014-02-11 19:50:5763 bool flatten_transform,
64 bool is_3d_sorted) {
[email protected]989386c2013-07-18 21:37:2365 SetLayerPropertiesForTestingInternal<Layer>(layer,
66 transform,
[email protected]989386c2013-07-18 21:37:2367 anchor,
68 position,
69 bounds,
[email protected]56fffdd2014-02-11 19:50:5770 flatten_transform,
71 is_3d_sorted);
[email protected]989386c2013-07-18 21:37:2372 }
[email protected]94f206c12012-08-25 00:09:1473
[email protected]989386c2013-07-18 21:37:2374 void SetLayerPropertiesForTesting(LayerImpl* layer,
75 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:4776 const gfx::PointF& anchor,
77 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:2678 const gfx::Size& bounds,
[email protected]56fffdd2014-02-11 19:50:5779 bool flatten_transform,
80 bool is_3d_sorted) {
[email protected]989386c2013-07-18 21:37:2381 SetLayerPropertiesForTestingInternal<LayerImpl>(layer,
82 transform,
[email protected]989386c2013-07-18 21:37:2383 anchor,
84 position,
85 bounds,
[email protected]56fffdd2014-02-11 19:50:5786 flatten_transform,
87 is_3d_sorted);
[email protected]989386c2013-07-18 21:37:2388 layer->SetContentBounds(bounds);
89 }
[email protected]94f206c12012-08-25 00:09:1490
[email protected]989386c2013-07-18 21:37:2391 void ExecuteCalculateDrawProperties(Layer* root_layer,
92 float device_scale_factor,
93 float page_scale_factor,
94 Layer* page_scale_application_layer,
95 bool can_use_lcd_text) {
96 EXPECT_TRUE(page_scale_application_layer || (page_scale_factor == 1.f));
97 gfx::Transform identity_matrix;
[email protected]989386c2013-07-18 21:37:2398 gfx::Size device_viewport_size =
99 gfx::Size(root_layer->bounds().width() * device_scale_factor,
100 root_layer->bounds().height() * device_scale_factor);
[email protected]94f206c12012-08-25 00:09:14101
[email protected]989386c2013-07-18 21:37:23102 render_surface_layer_list_.reset(new RenderSurfaceLayerList);
[email protected]94f206c12012-08-25 00:09:14103
[email protected]989386c2013-07-18 21:37:23104 // We are probably not testing what is intended if the root_layer bounds are
105 // empty.
106 DCHECK(!root_layer->bounds().IsEmpty());
[email protected]7aad55f2013-07-26 11:25:53107 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
108 root_layer, device_viewport_size, render_surface_layer_list_.get());
109 inputs.device_scale_factor = device_scale_factor;
110 inputs.page_scale_factor = page_scale_factor;
111 inputs.page_scale_application_layer = page_scale_application_layer;
112 inputs.can_use_lcd_text = can_use_lcd_text;
113 inputs.can_adjust_raster_scales = true;
114 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:23115 }
[email protected]94f206c12012-08-25 00:09:14116
[email protected]989386c2013-07-18 21:37:23117 void ExecuteCalculateDrawProperties(LayerImpl* root_layer,
118 float device_scale_factor,
119 float page_scale_factor,
120 LayerImpl* page_scale_application_layer,
121 bool can_use_lcd_text) {
122 gfx::Transform identity_matrix;
123 LayerImplList dummy_render_surface_layer_list;
[email protected]989386c2013-07-18 21:37:23124 gfx::Size device_viewport_size =
125 gfx::Size(root_layer->bounds().width() * device_scale_factor,
126 root_layer->bounds().height() * device_scale_factor);
[email protected]94f206c12012-08-25 00:09:14127
[email protected]989386c2013-07-18 21:37:23128 // We are probably not testing what is intended if the root_layer bounds are
129 // empty.
130 DCHECK(!root_layer->bounds().IsEmpty());
[email protected]7aad55f2013-07-26 11:25:53131 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
132 root_layer, device_viewport_size, &dummy_render_surface_layer_list);
133 inputs.device_scale_factor = device_scale_factor;
134 inputs.page_scale_factor = page_scale_factor;
135 inputs.page_scale_application_layer = page_scale_application_layer;
136 inputs.can_use_lcd_text = can_use_lcd_text;
137 inputs.can_adjust_raster_scales = true;
138 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:23139 }
[email protected]94f206c12012-08-25 00:09:14140
[email protected]989386c2013-07-18 21:37:23141 template <class LayerType>
142 void ExecuteCalculateDrawProperties(LayerType* root_layer) {
143 LayerType* page_scale_application_layer = NULL;
144 ExecuteCalculateDrawProperties(
145 root_layer, 1.f, 1.f, page_scale_application_layer, false);
146 }
[email protected]94f206c12012-08-25 00:09:14147
[email protected]989386c2013-07-18 21:37:23148 template <class LayerType>
149 void ExecuteCalculateDrawProperties(LayerType* root_layer,
150 float device_scale_factor) {
151 LayerType* page_scale_application_layer = NULL;
152 ExecuteCalculateDrawProperties(root_layer,
153 device_scale_factor,
154 1.f,
155 page_scale_application_layer,
156 false);
157 }
158
159 template <class LayerType>
160 void ExecuteCalculateDrawProperties(LayerType* root_layer,
161 float device_scale_factor,
162 float page_scale_factor,
163 LayerType* page_scale_application_layer) {
164 ExecuteCalculateDrawProperties(root_layer,
165 device_scale_factor,
166 page_scale_factor,
167 page_scale_application_layer,
168 false);
169 }
170
[email protected]a9aa60a82013-08-29 04:28:26171 RenderSurfaceLayerList* render_surface_layer_list() const {
172 return render_surface_layer_list_.get();
173 }
174
[email protected]989386c2013-07-18 21:37:23175 private:
176 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
177};
178
179class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
180 public testing::Test {
181};
[email protected]94f206c12012-08-25 00:09:14182
[email protected]96baf3e2012-10-22 23:09:55183class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:32184 public:
[email protected]d5754282014-04-09 00:43:29185 LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {}
[email protected]94f206c12012-08-25 00:09:14186
[email protected]fb661802013-03-25 01:59:32187 virtual bool DrawsContent() const OVERRIDE;
[email protected]d5754282014-04-09 00:43:29188 virtual void CalculateContentsScale(float ideal_contents_scale,
189 float device_scale_factor,
190 float page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:22191 float maximum_animation_contents_scale,
[email protected]d5754282014-04-09 00:43:29192 bool animating_transform_to_screen,
193 float* contents_scale_x,
194 float* contents_scale_y,
195 gfx::Size* content_bounds) OVERRIDE;
196
197 float last_device_scale_factor() const { return last_device_scale_factor_; }
[email protected]d58499a2012-10-09 22:27:47198
[email protected]fb661802013-03-25 01:59:32199 private:
200 virtual ~LayerWithForcedDrawsContent() {}
[email protected]d5754282014-04-09 00:43:29201
202 // Parameters from last CalculateContentsScale.
203 float last_device_scale_factor_;
[email protected]94f206c12012-08-25 00:09:14204};
205
[email protected]fb661802013-03-25 01:59:32206bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:44207
[email protected]d5754282014-04-09 00:43:29208void LayerWithForcedDrawsContent::CalculateContentsScale(
209 float ideal_contents_scale,
210 float device_scale_factor,
211 float page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:22212 float maximum_animation_contents_scale,
[email protected]d5754282014-04-09 00:43:29213 bool animating_transform_to_screen,
214 float* contents_scale_x,
215 float* contents_scale_y,
216 gfx::Size* content_bounds) {
217 last_device_scale_factor_ = device_scale_factor;
218 Layer::CalculateContentsScale(ideal_contents_scale,
219 device_scale_factor,
220 page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:22221 maximum_animation_contents_scale,
[email protected]d5754282014-04-09 00:43:29222 animating_transform_to_screen,
223 contents_scale_x,
224 contents_scale_y,
225 content_bounds);
226}
227
[email protected]96baf3e2012-10-22 23:09:55228class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:32229 public:
230 MockContentLayerClient() {}
231 virtual ~MockContentLayerClient() {}
232 virtual void PaintContents(SkCanvas* canvas,
[email protected]0023fc72014-01-10 20:05:06233 const gfx::Rect& clip,
[email protected]fb661802013-03-25 01:59:32234 gfx::RectF* opaque) OVERRIDE {}
235 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
[email protected]1d96e032014-03-25 05:59:08236 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
[email protected]f34a24232012-09-20 22:59:55237};
238
[email protected]fb661802013-03-25 01:59:32239scoped_refptr<ContentLayer> CreateDrawableContentLayer(
240 ContentLayerClient* delegate) {
241 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate);
242 to_return->SetIsDrawable(true);
243 return to_return;
[email protected]f34a24232012-09-20 22:59:55244}
245
[email protected]989386c2013-07-18 21:37:23246#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
247 do { \
248 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
249 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:47250 } while (false)
251
[email protected]989386c2013-07-18 21:37:23252TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32253 // Sanity check: For layers positioned at zero, with zero size,
254 // and with identity transforms, then the draw transform,
255 // screen space transform, and the hierarchy passed on to children
256 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14257
[email protected]fb661802013-03-25 01:59:32258 scoped_refptr<Layer> parent = Layer::Create();
259 scoped_refptr<Layer> child = Layer::Create();
260 scoped_refptr<Layer> grand_child = Layer::Create();
261 parent->AddChild(child);
262 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14263
[email protected]d600df7d2013-08-03 02:34:28264 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
265 host->SetRootLayer(parent);
266
[email protected]fb661802013-03-25 01:59:32267 gfx::Transform identity_matrix;
268 SetLayerPropertiesForTesting(parent.get(),
269 identity_matrix,
[email protected]fb661802013-03-25 01:59:32270 gfx::PointF(),
271 gfx::PointF(),
272 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:57273 true,
[email protected]fb661802013-03-25 01:59:32274 false);
275 SetLayerPropertiesForTesting(child.get(),
276 identity_matrix,
[email protected]fb661802013-03-25 01:59:32277 gfx::PointF(),
278 gfx::PointF(),
279 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57280 true,
[email protected]fb661802013-03-25 01:59:32281 false);
282 SetLayerPropertiesForTesting(grand_child.get(),
283 identity_matrix,
[email protected]fb661802013-03-25 01:59:32284 gfx::PointF(),
285 gfx::PointF(),
286 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57287 true,
[email protected]fb661802013-03-25 01:59:32288 false);
[email protected]94f206c12012-08-25 00:09:14289
[email protected]fb661802013-03-25 01:59:32290 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14291
[email protected]fb661802013-03-25 01:59:32292 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
293 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
294 child->screen_space_transform());
295 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
296 grand_child->draw_transform());
297 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
298 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14299}
300
[email protected]989386c2013-07-18 21:37:23301TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32302 gfx::Transform identity_matrix;
303 scoped_refptr<Layer> layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:14304
[email protected]fb661802013-03-25 01:59:32305 scoped_refptr<Layer> root = Layer::Create();
306 SetLayerPropertiesForTesting(root.get(),
307 identity_matrix,
[email protected]fb661802013-03-25 01:59:32308 gfx::PointF(),
309 gfx::PointF(),
310 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57311 true,
[email protected]fb661802013-03-25 01:59:32312 false);
313 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42314
[email protected]d600df7d2013-08-03 02:34:28315 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
316 host->SetRootLayer(root);
317
[email protected]fb661802013-03-25 01:59:32318 // Case 2: Setting the bounds of the layer should not affect either the draw
319 // transform or the screenspace transform.
320 gfx::Transform translation_to_center;
321 translation_to_center.Translate(5.0, 6.0);
322 SetLayerPropertiesForTesting(layer.get(),
323 identity_matrix,
[email protected]fb661802013-03-25 01:59:32324 gfx::PointF(),
325 gfx::PointF(),
326 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57327 true,
[email protected]fb661802013-03-25 01:59:32328 false);
329 ExecuteCalculateDrawProperties(root.get());
330 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
331 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
332 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14333
[email protected]fb661802013-03-25 01:59:32334 // Case 3: The anchor point by itself (without a layer transform) should have
335 // no effect on the transforms.
336 SetLayerPropertiesForTesting(layer.get(),
337 identity_matrix,
[email protected]fb661802013-03-25 01:59:32338 gfx::PointF(0.25f, 0.25f),
339 gfx::PointF(),
340 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57341 true,
[email protected]fb661802013-03-25 01:59:32342 false);
343 ExecuteCalculateDrawProperties(root.get());
344 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
345 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
346 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14347
[email protected]fb661802013-03-25 01:59:32348 // Case 4: A change in actual position affects both the draw transform and
349 // screen space transform.
350 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05351 position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32352 SetLayerPropertiesForTesting(layer.get(),
353 identity_matrix,
[email protected]fb661802013-03-25 01:59:32354 gfx::PointF(0.25f, 0.25f),
355 gfx::PointF(0.f, 1.2f),
356 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57357 true,
[email protected]fb661802013-03-25 01:59:32358 false);
359 ExecuteCalculateDrawProperties(root.get());
360 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
361 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
362 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14363
[email protected]fb661802013-03-25 01:59:32364 // Case 5: In the correct sequence of transforms, the layer transform should
365 // pre-multiply the translation_to_center. This is easily tested by using a
366 // scale transform, because scale and translation are not commutative.
367 gfx::Transform layer_transform;
368 layer_transform.Scale3d(2.0, 2.0, 1.0);
369 SetLayerPropertiesForTesting(layer.get(),
370 layer_transform,
[email protected]fb661802013-03-25 01:59:32371 gfx::PointF(),
372 gfx::PointF(),
373 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57374 true,
[email protected]fb661802013-03-25 01:59:32375 false);
376 ExecuteCalculateDrawProperties(root.get());
377 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
378 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
379 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14380
[email protected]fb661802013-03-25 01:59:32381 // Case 6: The layer transform should occur with respect to the anchor point.
382 gfx::Transform translation_to_anchor;
383 translation_to_anchor.Translate(5.0, 0.0);
384 gfx::Transform expected_result =
385 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
386 SetLayerPropertiesForTesting(layer.get(),
387 layer_transform,
[email protected]fb661802013-03-25 01:59:32388 gfx::PointF(0.5f, 0.f),
389 gfx::PointF(),
390 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57391 true,
[email protected]fb661802013-03-25 01:59:32392 false);
393 ExecuteCalculateDrawProperties(root.get());
394 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
395 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
396 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14397
[email protected]fb661802013-03-25 01:59:32398 // Case 7: Verify that position pre-multiplies the layer transform. The
399 // current implementation of CalculateDrawProperties does this implicitly, but
400 // it is still worth testing to detect accidental regressions.
401 expected_result = position_transform * translation_to_anchor *
402 layer_transform * Inverse(translation_to_anchor);
403 SetLayerPropertiesForTesting(layer.get(),
404 layer_transform,
[email protected]fb661802013-03-25 01:59:32405 gfx::PointF(0.5f, 0.f),
406 gfx::PointF(0.f, 1.2f),
407 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57408 true,
[email protected]fb661802013-03-25 01:59:32409 false);
410 ExecuteCalculateDrawProperties(root.get());
411 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
412 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
413 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14414}
415
[email protected]989386c2013-07-18 21:37:23416TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
[email protected]fb661802013-03-25 01:59:32417 const gfx::Vector2d kScrollOffset(50, 100);
418 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01419 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32420 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
421 -kScrollOffset.y());
422 const float kPageScale = 0.888f;
423 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20424
[email protected]fb661802013-03-25 01:59:32425 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:45426 TestSharedBitmapManager shared_bitmap_manager;
427 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]657b24c2013-03-06 09:01:20428
[email protected]fb661802013-03-25 01:59:32429 gfx::Transform identity_matrix;
430 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
431 LayerImpl::Create(host_impl.active_tree(), 1));
432 LayerImpl* sublayer = sublayer_scoped_ptr.get();
433 sublayer->SetContentsScale(kPageScale * kDeviceScale,
434 kPageScale * kDeviceScale);
435 SetLayerPropertiesForTesting(sublayer,
436 identity_matrix,
[email protected]fb661802013-03-25 01:59:32437 gfx::Point(),
438 gfx::PointF(),
439 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:57440 true,
[email protected]fb661802013-03-25 01:59:32441 false);
[email protected]657b24c2013-03-06 09:01:20442
[email protected]adeda572014-01-31 00:49:47443 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32444 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47445 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
[email protected]fb661802013-03-25 01:59:32446 SetLayerPropertiesForTesting(scroll_layer,
447 identity_matrix,
[email protected]fb661802013-03-25 01:59:32448 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47449 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32450 gfx::Size(10, 20),
[email protected]56fffdd2014-02-11 19:50:57451 true,
[email protected]fb661802013-03-25 01:59:32452 false);
[email protected]adeda572014-01-31 00:49:47453 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
454 LayerImpl::Create(host_impl.active_tree(), 4));
455 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
456
457 scroll_layer->SetScrollClipLayer(clip_layer->id());
458 clip_layer->SetBounds(
459 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
460 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
461 scroll_layer->SetScrollClipLayer(clip_layer->id());
[email protected]fb661802013-03-25 01:59:32462 scroll_layer->SetScrollDelta(kScrollDelta);
463 gfx::Transform impl_transform;
[email protected]fb661802013-03-25 01:59:32464 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
[email protected]adeda572014-01-31 00:49:47465 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
466 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
467 scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20468
[email protected]fb661802013-03-25 01:59:32469 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
470 SetLayerPropertiesForTesting(root.get(),
471 identity_matrix,
[email protected]fb661802013-03-25 01:59:32472 gfx::PointF(),
473 gfx::PointF(),
474 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:57475 true,
[email protected]fb661802013-03-25 01:59:32476 false);
[email protected]adeda572014-01-31 00:49:47477 root->AddChild(clip_layer_scoped_ptr.Pass());
[email protected]657b24c2013-03-06 09:01:20478
[email protected]f2136262013-04-26 21:10:19479 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32480 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32481 gfx::Transform expected_transform = identity_matrix;
482 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
483 sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
484 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
485 MathUtil::Round(sub_layer_screen_position.y()));
486 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
487 sublayer->draw_transform());
488 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
489 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20490
[email protected]fb661802013-03-25 01:59:32491 gfx::Transform arbitrary_translate;
492 const float kTranslateX = 10.6f;
493 const float kTranslateY = 20.6f;
494 arbitrary_translate.Translate(kTranslateX, kTranslateY);
495 SetLayerPropertiesForTesting(scroll_layer,
496 arbitrary_translate,
[email protected]fb661802013-03-25 01:59:32497 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47498 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32499 gfx::Size(10, 20),
[email protected]56fffdd2014-02-11 19:50:57500 true,
[email protected]fb661802013-03-25 01:59:32501 false);
[email protected]f2136262013-04-26 21:10:19502 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32503 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32504 expected_transform.MakeIdentity();
505 expected_transform.Translate(
506 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
507 sub_layer_screen_position.x()),
508 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
509 sub_layer_screen_position.y()));
510 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
511 sublayer->draw_transform());
[email protected]657b24c2013-03-06 09:01:20512}
513
[email protected]989386c2013-07-18 21:37:23514TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32515 gfx::Transform identity_matrix;
516 scoped_refptr<Layer> root = Layer::Create();
517 scoped_refptr<Layer> parent = Layer::Create();
518 scoped_refptr<Layer> child = Layer::Create();
519 scoped_refptr<Layer> grand_child = Layer::Create();
520 root->AddChild(parent);
521 parent->AddChild(child);
522 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14523
[email protected]d600df7d2013-08-03 02:34:28524 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
525 host->SetRootLayer(root);
526
[email protected]fb661802013-03-25 01:59:32527 // One-time setup of root layer
528 SetLayerPropertiesForTesting(root.get(),
529 identity_matrix,
[email protected]fb661802013-03-25 01:59:32530 gfx::PointF(),
531 gfx::PointF(),
532 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57533 true,
[email protected]fb661802013-03-25 01:59:32534 false);
[email protected]ecc12622012-10-30 20:45:42535
[email protected]fb661802013-03-25 01:59:32536 // Case 1: parent's anchor point should not affect child or grand_child.
537 SetLayerPropertiesForTesting(parent.get(),
538 identity_matrix,
[email protected]fb661802013-03-25 01:59:32539 gfx::PointF(0.25f, 0.25f),
540 gfx::PointF(),
541 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57542 true,
[email protected]fb661802013-03-25 01:59:32543 false);
544 SetLayerPropertiesForTesting(child.get(),
545 identity_matrix,
[email protected]fb661802013-03-25 01:59:32546 gfx::PointF(),
547 gfx::PointF(),
548 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57549 true,
[email protected]fb661802013-03-25 01:59:32550 false);
551 SetLayerPropertiesForTesting(grand_child.get(),
552 identity_matrix,
[email protected]fb661802013-03-25 01:59:32553 gfx::PointF(),
554 gfx::PointF(),
555 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57556 true,
[email protected]fb661802013-03-25 01:59:32557 false);
558 ExecuteCalculateDrawProperties(root.get());
559 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
560 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
561 child->screen_space_transform());
562 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
563 grand_child->draw_transform());
564 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
565 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14566
[email protected]fb661802013-03-25 01:59:32567 // Case 2: parent's position affects child and grand_child.
568 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05569 parent_position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32570 SetLayerPropertiesForTesting(parent.get(),
571 identity_matrix,
[email protected]fb661802013-03-25 01:59:32572 gfx::PointF(0.25f, 0.25f),
573 gfx::PointF(0.f, 1.2f),
574 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57575 true,
[email protected]fb661802013-03-25 01:59:32576 false);
577 SetLayerPropertiesForTesting(child.get(),
578 identity_matrix,
[email protected]fb661802013-03-25 01:59:32579 gfx::PointF(),
580 gfx::PointF(),
581 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57582 true,
[email protected]fb661802013-03-25 01:59:32583 false);
584 SetLayerPropertiesForTesting(grand_child.get(),
585 identity_matrix,
[email protected]fb661802013-03-25 01:59:32586 gfx::PointF(),
587 gfx::PointF(),
588 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57589 true,
[email protected]fb661802013-03-25 01:59:32590 false);
591 ExecuteCalculateDrawProperties(root.get());
592 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
593 child->draw_transform());
594 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
595 child->screen_space_transform());
596 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
597 grand_child->draw_transform());
598 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
599 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14600
[email protected]fb661802013-03-25 01:59:32601 // Case 3: parent's local transform affects child and grandchild
602 gfx::Transform parent_layer_transform;
603 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
604 gfx::Transform parent_translation_to_anchor;
605 parent_translation_to_anchor.Translate(2.5, 3.0);
606 gfx::Transform parent_composite_transform =
607 parent_translation_to_anchor * parent_layer_transform *
608 Inverse(parent_translation_to_anchor);
609 SetLayerPropertiesForTesting(parent.get(),
610 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32611 gfx::PointF(0.25f, 0.25f),
612 gfx::PointF(),
613 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57614 true,
[email protected]fb661802013-03-25 01:59:32615 false);
616 SetLayerPropertiesForTesting(child.get(),
617 identity_matrix,
[email protected]fb661802013-03-25 01:59:32618 gfx::PointF(),
619 gfx::PointF(),
620 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57621 true,
[email protected]fb661802013-03-25 01:59:32622 false);
623 SetLayerPropertiesForTesting(grand_child.get(),
624 identity_matrix,
[email protected]fb661802013-03-25 01:59:32625 gfx::PointF(),
626 gfx::PointF(),
627 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57628 true,
[email protected]fb661802013-03-25 01:59:32629 false);
630 ExecuteCalculateDrawProperties(root.get());
631 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
632 child->draw_transform());
633 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
634 child->screen_space_transform());
635 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
636 grand_child->draw_transform());
637 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
638 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14639}
640
[email protected]989386c2013-07-18 21:37:23641TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
[email protected]fb661802013-03-25 01:59:32642 scoped_refptr<Layer> root = Layer::Create();
643 scoped_refptr<Layer> parent = Layer::Create();
644 scoped_refptr<Layer> child = 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);
[email protected]94f206c12012-08-25 00:09:14650
[email protected]d600df7d2013-08-03 02:34:28651 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
652 host->SetRootLayer(root);
653
[email protected]fb661802013-03-25 01:59:32654 // One-time setup of root layer
655 gfx::Transform identity_matrix;
656 SetLayerPropertiesForTesting(root.get(),
657 identity_matrix,
[email protected]fb661802013-03-25 01:59:32658 gfx::PointF(),
659 gfx::PointF(),
660 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57661 true,
[email protected]fb661802013-03-25 01:59:32662 false);
[email protected]ecc12622012-10-30 20:45:42663
[email protected]fb661802013-03-25 01:59:32664 // Child is set up so that a new render surface should be created.
665 child->SetOpacity(0.5f);
666 child->SetForceRenderSurface(true);
[email protected]94f206c12012-08-25 00:09:14667
[email protected]fb661802013-03-25 01:59:32668 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05669 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32670 gfx::Transform parent_translation_to_anchor;
671 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44672
[email protected]fb661802013-03-25 01:59:32673 gfx::Transform parent_composite_transform =
674 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39675 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32676 gfx::Vector2dF parent_composite_scale =
677 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
678 1.f);
679 gfx::Transform surface_sublayer_transform;
680 surface_sublayer_transform.Scale(parent_composite_scale.x(),
681 parent_composite_scale.y());
682 gfx::Transform surface_sublayer_composite_transform =
683 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14684
[email protected]fb661802013-03-25 01:59:32685 // Child's render surface should not exist yet.
686 ASSERT_FALSE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:14687
[email protected]fb661802013-03-25 01:59:32688 SetLayerPropertiesForTesting(parent.get(),
689 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32690 gfx::PointF(0.25f, 0.25f),
691 gfx::PointF(),
692 gfx::Size(100, 120),
[email protected]56fffdd2014-02-11 19:50:57693 true,
[email protected]fb661802013-03-25 01:59:32694 false);
695 SetLayerPropertiesForTesting(child.get(),
696 identity_matrix,
[email protected]fb661802013-03-25 01:59:32697 gfx::PointF(),
698 gfx::PointF(),
699 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57700 true,
[email protected]fb661802013-03-25 01:59:32701 false);
702 SetLayerPropertiesForTesting(grand_child.get(),
703 identity_matrix,
[email protected]fb661802013-03-25 01:59:32704 gfx::PointF(),
705 gfx::PointF(),
706 gfx::Size(8, 10),
[email protected]56fffdd2014-02-11 19:50:57707 true,
[email protected]fb661802013-03-25 01:59:32708 false);
709 ExecuteCalculateDrawProperties(root.get());
[email protected]94f206c12012-08-25 00:09:14710
[email protected]fb661802013-03-25 01:59:32711 // Render surface should have been created now.
712 ASSERT_TRUE(child->render_surface());
713 ASSERT_EQ(child, child->render_target());
[email protected]94f206c12012-08-25 00:09:14714
[email protected]fb661802013-03-25 01:59:32715 // The child layer's draw transform should refer to its new render surface.
716 // The screen-space transform, however, should still refer to the root.
717 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
718 child->draw_transform());
719 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
720 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14721
[email protected]fb661802013-03-25 01:59:32722 // Because the grand_child is the only drawable content, the child's render
723 // surface will tighten its bounds to the grand_child. The scale at which the
724 // surface's subtree is drawn must be removed from the composite transform.
725 EXPECT_TRANSFORMATION_MATRIX_EQ(
726 surface_sublayer_composite_transform,
727 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14728
[email protected]fb661802013-03-25 01:59:32729 // The screen space is the same as the target since the child surface draws
730 // into the root.
731 EXPECT_TRANSFORMATION_MATRIX_EQ(
732 surface_sublayer_composite_transform,
733 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14734}
735
[email protected]989386c2013-07-18 21:37:23736TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
[email protected]fb661802013-03-25 01:59:32737 scoped_refptr<Layer> root = Layer::Create();
738 scoped_refptr<Layer> parent = Layer::Create();
739 scoped_refptr<Layer> child = Layer::Create();
740 scoped_refptr<Layer> child_replica = Layer::Create();
741 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
742 make_scoped_refptr(new LayerWithForcedDrawsContent());
743 root->AddChild(parent);
744 parent->AddChild(child);
745 child->AddChild(grand_child);
746 child->SetReplicaLayer(child_replica.get());
747
[email protected]d600df7d2013-08-03 02:34:28748 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
749 host->SetRootLayer(root);
750
[email protected]fb661802013-03-25 01:59:32751 // One-time setup of root layer
752 gfx::Transform identity_matrix;
753 SetLayerPropertiesForTesting(root.get(),
754 identity_matrix,
[email protected]fb661802013-03-25 01:59:32755 gfx::PointF(),
756 gfx::PointF(),
757 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57758 true,
[email protected]fb661802013-03-25 01:59:32759 false);
760
761 // Child is set up so that a new render surface should be created.
762 child->SetOpacity(0.5f);
763
764 gfx::Transform parent_layer_transform;
765 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
766 gfx::Transform parent_translation_to_anchor;
767 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32768 gfx::Transform parent_composite_transform =
769 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39770 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32771 gfx::Transform replica_layer_transform;
772 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
773 gfx::Vector2dF parent_composite_scale =
774 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
775 1.f);
776 gfx::Transform surface_sublayer_transform;
777 surface_sublayer_transform.Scale(parent_composite_scale.x(),
778 parent_composite_scale.y());
779 gfx::Transform replica_composite_transform =
780 parent_composite_transform * replica_layer_transform *
781 Inverse(surface_sublayer_transform);
782
783 // Child's render surface should not exist yet.
784 ASSERT_FALSE(child->render_surface());
785
786 SetLayerPropertiesForTesting(parent.get(),
787 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32788 gfx::PointF(0.25f, 0.25f),
789 gfx::PointF(),
790 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57791 true,
[email protected]fb661802013-03-25 01:59:32792 false);
793 SetLayerPropertiesForTesting(child.get(),
794 identity_matrix,
[email protected]fb661802013-03-25 01:59:32795 gfx::PointF(),
796 gfx::PointF(),
797 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57798 true,
[email protected]fb661802013-03-25 01:59:32799 false);
800 SetLayerPropertiesForTesting(grand_child.get(),
801 identity_matrix,
[email protected]fb661802013-03-25 01:59:32802 gfx::PointF(),
803 gfx::PointF(-0.5f, -0.5f),
804 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:57805 true,
[email protected]fb661802013-03-25 01:59:32806 false);
807 SetLayerPropertiesForTesting(child_replica.get(),
808 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:32809 gfx::PointF(),
810 gfx::PointF(),
811 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57812 true,
[email protected]fb661802013-03-25 01:59:32813 false);
814 ExecuteCalculateDrawProperties(root.get());
815
816 // Render surface should have been created now.
817 ASSERT_TRUE(child->render_surface());
818 ASSERT_EQ(child, child->render_target());
819
820 EXPECT_TRANSFORMATION_MATRIX_EQ(
821 replica_composite_transform,
822 child->render_target()->render_surface()->replica_draw_transform());
823 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57824 child->render_target()
825 ->render_surface()
[email protected]fb661802013-03-25 01:59:32826 ->replica_screen_space_transform());
827}
828
[email protected]989386c2013-07-18 21:37:23829TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32830 // This test creates a more complex tree and verifies it all at once. This
831 // covers the following cases:
832 // - layers that are described w.r.t. a render surface: should have draw
833 // transforms described w.r.t. that surface
834 // - A render surface described w.r.t. an ancestor render surface: should
835 // have a draw transform described w.r.t. that ancestor surface
836 // - Replicas of a render surface are described w.r.t. the replica's
837 // transform around its anchor, along with the surface itself.
838 // - Sanity check on recursion: verify transforms of layers described w.r.t.
839 // a render surface that is described w.r.t. an ancestor render surface.
840 // - verifying that each layer has a reference to the correct render surface
841 // and render target values.
842
843 scoped_refptr<Layer> root = Layer::Create();
844 scoped_refptr<Layer> parent = Layer::Create();
845 scoped_refptr<Layer> render_surface1 = Layer::Create();
846 scoped_refptr<Layer> render_surface2 = Layer::Create();
847 scoped_refptr<Layer> child_of_root = Layer::Create();
848 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
849 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
850 scoped_refptr<Layer> replica_of_rs1 = Layer::Create();
851 scoped_refptr<Layer> replica_of_rs2 = Layer::Create();
852 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
853 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
854 make_scoped_refptr(new LayerWithForcedDrawsContent());
855 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
856 make_scoped_refptr(new LayerWithForcedDrawsContent());
857 root->AddChild(parent);
858 parent->AddChild(render_surface1);
859 parent->AddChild(child_of_root);
860 render_surface1->AddChild(child_of_rs1);
861 render_surface1->AddChild(render_surface2);
862 render_surface2->AddChild(child_of_rs2);
863 child_of_root->AddChild(grand_child_of_root);
864 child_of_rs1->AddChild(grand_child_of_rs1);
865 child_of_rs2->AddChild(grand_child_of_rs2);
866 render_surface1->SetReplicaLayer(replica_of_rs1.get());
867 render_surface2->SetReplicaLayer(replica_of_rs2.get());
868
[email protected]d600df7d2013-08-03 02:34:28869 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
870 host->SetRootLayer(root);
871
[email protected]fb661802013-03-25 01:59:32872 // In combination with descendant draws content, opacity != 1 forces the layer
873 // to have a new render surface.
874 render_surface1->SetOpacity(0.5f);
875 render_surface2->SetOpacity(0.33f);
876
877 // One-time setup of root layer
878 gfx::Transform identity_matrix;
879 SetLayerPropertiesForTesting(root.get(),
880 identity_matrix,
[email protected]fb661802013-03-25 01:59:32881 gfx::PointF(),
882 gfx::PointF(),
883 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57884 true,
[email protected]fb661802013-03-25 01:59:32885 false);
886
887 // All layers in the tree are initialized with an anchor at .25 and a size of
888 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39889 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32890 gfx::Transform translation_to_anchor;
891 translation_to_anchor.Translate(2.5, 0.0);
892 gfx::Transform layer_transform;
893 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32894 gfx::Transform replica_layer_transform;
895 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
896
897 gfx::Transform A =
898 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32899 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
900 Inverse(translation_to_anchor);
901
902 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39903 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32904 gfx::Transform surface1_sublayer_transform;
905 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
906 surface1_parent_transform_scale.y());
907
908 // SS1 = transform given to the subtree of render_surface1
909 gfx::Transform SS1 = surface1_sublayer_transform;
910 // S1 = transform to move from render_surface1 pixels to the layer space of
911 // the owning layer
912 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
913
914 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39915 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32916 gfx::Transform surface2_sublayer_transform;
917 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
918 surface2_parent_transform_scale.y());
919
920 // SS2 = transform given to the subtree of render_surface2
921 gfx::Transform SS2 = surface2_sublayer_transform;
922 // S2 = transform to move from render_surface2 pixels to the layer space of
923 // the owning layer
924 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
925
926 SetLayerPropertiesForTesting(parent.get(),
927 layer_transform,
[email protected]fb661802013-03-25 01:59:32928 gfx::PointF(0.25f, 0.f),
929 gfx::PointF(),
930 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57931 true,
[email protected]fb661802013-03-25 01:59:32932 false);
933 SetLayerPropertiesForTesting(render_surface1.get(),
934 layer_transform,
[email protected]fb661802013-03-25 01:59:32935 gfx::PointF(0.25f, 0.f),
936 gfx::PointF(),
937 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57938 true,
[email protected]fb661802013-03-25 01:59:32939 false);
940 SetLayerPropertiesForTesting(render_surface2.get(),
941 layer_transform,
[email protected]fb661802013-03-25 01:59:32942 gfx::PointF(0.25f, 0.f),
943 gfx::PointF(),
944 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57945 true,
[email protected]fb661802013-03-25 01:59:32946 false);
947 SetLayerPropertiesForTesting(child_of_root.get(),
948 layer_transform,
[email protected]fb661802013-03-25 01:59:32949 gfx::PointF(0.25f, 0.f),
950 gfx::PointF(),
951 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57952 true,
[email protected]fb661802013-03-25 01:59:32953 false);
954 SetLayerPropertiesForTesting(child_of_rs1.get(),
955 layer_transform,
[email protected]fb661802013-03-25 01:59:32956 gfx::PointF(0.25f, 0.f),
957 gfx::PointF(),
958 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57959 true,
[email protected]fb661802013-03-25 01:59:32960 false);
961 SetLayerPropertiesForTesting(child_of_rs2.get(),
962 layer_transform,
[email protected]fb661802013-03-25 01:59:32963 gfx::PointF(0.25f, 0.f),
964 gfx::PointF(),
965 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57966 true,
[email protected]fb661802013-03-25 01:59:32967 false);
968 SetLayerPropertiesForTesting(grand_child_of_root.get(),
969 layer_transform,
[email protected]fb661802013-03-25 01:59:32970 gfx::PointF(0.25f, 0.f),
971 gfx::PointF(),
972 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57973 true,
[email protected]fb661802013-03-25 01:59:32974 false);
975 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
976 layer_transform,
[email protected]fb661802013-03-25 01:59:32977 gfx::PointF(0.25f, 0.f),
978 gfx::PointF(),
979 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57980 true,
[email protected]fb661802013-03-25 01:59:32981 false);
982 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
983 layer_transform,
[email protected]fb661802013-03-25 01:59:32984 gfx::PointF(0.25f, 0.f),
985 gfx::PointF(),
986 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57987 true,
[email protected]fb661802013-03-25 01:59:32988 false);
989 SetLayerPropertiesForTesting(replica_of_rs1.get(),
990 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:32991 gfx::PointF(0.25f, 0.f),
992 gfx::PointF(),
993 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57994 true,
[email protected]fb661802013-03-25 01:59:32995 false);
996 SetLayerPropertiesForTesting(replica_of_rs2.get(),
997 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:32998 gfx::PointF(0.25f, 0.f),
999 gfx::PointF(),
1000 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:571001 true,
[email protected]fb661802013-03-25 01:59:321002 false);
1003
1004 ExecuteCalculateDrawProperties(root.get());
1005
1006 // Only layers that are associated with render surfaces should have an actual
1007 // RenderSurface() value.
1008 ASSERT_TRUE(root->render_surface());
1009 ASSERT_FALSE(child_of_root->render_surface());
1010 ASSERT_FALSE(grand_child_of_root->render_surface());
1011
1012 ASSERT_TRUE(render_surface1->render_surface());
1013 ASSERT_FALSE(child_of_rs1->render_surface());
1014 ASSERT_FALSE(grand_child_of_rs1->render_surface());
1015
1016 ASSERT_TRUE(render_surface2->render_surface());
1017 ASSERT_FALSE(child_of_rs2->render_surface());
1018 ASSERT_FALSE(grand_child_of_rs2->render_surface());
1019
1020 // Verify all render target accessors
1021 EXPECT_EQ(root, parent->render_target());
1022 EXPECT_EQ(root, child_of_root->render_target());
1023 EXPECT_EQ(root, grand_child_of_root->render_target());
1024
1025 EXPECT_EQ(render_surface1, render_surface1->render_target());
1026 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
1027 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
1028
1029 EXPECT_EQ(render_surface2, render_surface2->render_target());
1030 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
1031 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
1032
1033 // Verify layer draw transforms note that draw transforms are described with
1034 // respect to the nearest ancestor render surface but screen space transforms
1035 // are described with respect to the root.
1036 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
[email protected]baf64d062014-02-16 22:10:391037 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform());
1038 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321039 grand_child_of_root->draw_transform());
1040
1041 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
[email protected]baf64d062014-02-16 22:10:391042 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform());
1043 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
[email protected]fb661802013-03-25 01:59:321044 grand_child_of_rs1->draw_transform());
1045
1046 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
[email protected]baf64d062014-02-16 22:10:391047 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform());
1048 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
[email protected]fb661802013-03-25 01:59:321049 grand_child_of_rs2->draw_transform());
1050
1051 // Verify layer screen-space transforms
1052 //
1053 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391054 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:321055 child_of_root->screen_space_transform());
1056 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391057 A * A * A, grand_child_of_root->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321058
[email protected]baf64d062014-02-16 22:10:391059 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:321060 render_surface1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391061 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321062 child_of_rs1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391063 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:321064 grand_child_of_rs1->screen_space_transform());
1065
[email protected]baf64d062014-02-16 22:10:391066 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321067 render_surface2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391068 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:321069 child_of_rs2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391070 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
[email protected]fb661802013-03-25 01:59:321071 grand_child_of_rs2->screen_space_transform());
1072
1073 // Verify render surface transforms.
1074 //
1075 // Draw transform of render surface 1 is described with respect to root.
1076 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391077 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321078 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391079 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:321080 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391081 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321082 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391083 A * R * S1,
[email protected]fb661802013-03-25 01:59:321084 render_surface1->render_surface()->replica_screen_space_transform());
1085 // Draw transform of render surface 2 is described with respect to render
1086 // surface 1.
1087 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391088 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321089 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391090 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:321091 render_surface2->render_surface()->replica_draw_transform());
1092 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391093 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:321094 render_surface2->render_surface()->screen_space_transform());
1095 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391096 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:321097 render_surface2->render_surface()->replica_screen_space_transform());
1098
1099 // Sanity check. If these fail there is probably a bug in the test itself. It
1100 // is expected that we correctly set up transforms so that the y-component of
1101 // the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:261102 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
1103 EXPECT_FLOAT_EQ(2.0,
1104 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321105 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261106 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321107
[email protected]803f6b52013-09-12 00:51:261108 EXPECT_FLOAT_EQ(2.0,
1109 render_surface1->screen_space_transform().matrix().get(1, 3));
1110 EXPECT_FLOAT_EQ(3.0,
1111 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321112 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261113 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321114
[email protected]803f6b52013-09-12 00:51:261115 EXPECT_FLOAT_EQ(3.0,
1116 render_surface2->screen_space_transform().matrix().get(1, 3));
1117 EXPECT_FLOAT_EQ(4.0,
1118 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321119 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261120 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321121}
1122
[email protected]989386c2013-07-18 21:37:231123TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321124 // For layers that flatten their subtree, there should be an orthographic
1125 // projection (for x and y values) in the middle of the transform sequence.
1126 // Note that the way the code is currently implemented, it is not expected to
1127 // use a canonical orthographic projection.
1128
1129 scoped_refptr<Layer> root = Layer::Create();
1130 scoped_refptr<Layer> child = Layer::Create();
1131 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1132 make_scoped_refptr(new LayerWithForcedDrawsContent());
1133
1134 gfx::Transform rotation_about_y_axis;
1135 rotation_about_y_axis.RotateAboutYAxis(30.0);
1136
1137 const gfx::Transform identity_matrix;
1138 SetLayerPropertiesForTesting(root.get(),
1139 identity_matrix,
[email protected]fb661802013-03-25 01:59:321140 gfx::PointF(),
1141 gfx::PointF(),
1142 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571143 true,
[email protected]fb661802013-03-25 01:59:321144 false);
1145 SetLayerPropertiesForTesting(child.get(),
1146 rotation_about_y_axis,
[email protected]fb661802013-03-25 01:59:321147 gfx::PointF(),
1148 gfx::PointF(),
1149 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571150 true,
[email protected]fb661802013-03-25 01:59:321151 false);
1152 SetLayerPropertiesForTesting(grand_child.get(),
1153 rotation_about_y_axis,
[email protected]fb661802013-03-25 01:59:321154 gfx::PointF(),
1155 gfx::PointF(),
1156 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571157 true,
[email protected]fb661802013-03-25 01:59:321158 false);
1159
1160 root->AddChild(child);
1161 child->AddChild(grand_child);
1162 child->SetForceRenderSurface(true);
1163
[email protected]d600df7d2013-08-03 02:34:281164 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1165 host->SetRootLayer(root);
1166
[email protected]fb661802013-03-25 01:59:321167 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:571168 ASSERT_TRUE(root->should_flatten_transform());
1169 ASSERT_TRUE(child->should_flatten_transform());
1170 ASSERT_TRUE(grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:321171
1172 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1173 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1174 gfx::Transform expected_grand_child_draw_transform =
1175 rotation_about_y_axis; // draws onto child's render surface
1176 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1177 flattened_rotation_about_y.FlattenTo2d();
1178 gfx::Transform expected_grand_child_screen_space_transform =
1179 flattened_rotation_about_y * rotation_about_y_axis;
1180
1181 ExecuteCalculateDrawProperties(root.get());
1182
1183 // The child's draw transform should have been taken by its surface.
1184 ASSERT_TRUE(child->render_surface());
1185 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1186 child->render_surface()->draw_transform());
1187 EXPECT_TRANSFORMATION_MATRIX_EQ(
1188 expected_child_screen_space_transform,
1189 child->render_surface()->screen_space_transform());
1190 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1191 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1192 child->screen_space_transform());
1193 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1194 grand_child->draw_transform());
1195 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1196 grand_child->screen_space_transform());
1197}
1198
[email protected]989386c2013-07-18 21:37:231199TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321200 // A layer that is empty in one axis, but not the other, was accidentally
1201 // skipping a necessary translation. Without that translation, the coordinate
1202 // space of the layer's draw transform is incorrect.
1203 //
1204 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1205 // but if that layer becomes a render surface, then its draw transform is
1206 // implicitly inherited by the rest of the subtree, which then is positioned
1207 // incorrectly as a result.
1208
1209 scoped_refptr<Layer> root = Layer::Create();
1210 scoped_refptr<Layer> child = Layer::Create();
1211 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1212 make_scoped_refptr(new LayerWithForcedDrawsContent());
1213
1214 // The child height is zero, but has non-zero width that should be accounted
1215 // for while computing draw transforms.
1216 const gfx::Transform identity_matrix;
1217 SetLayerPropertiesForTesting(root.get(),
1218 identity_matrix,
[email protected]fb661802013-03-25 01:59:321219 gfx::PointF(),
1220 gfx::PointF(),
1221 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571222 true,
[email protected]fb661802013-03-25 01:59:321223 false);
1224 SetLayerPropertiesForTesting(child.get(),
1225 identity_matrix,
[email protected]fb661802013-03-25 01:59:321226 gfx::PointF(),
1227 gfx::PointF(),
1228 gfx::Size(10, 0),
[email protected]56fffdd2014-02-11 19:50:571229 true,
[email protected]fb661802013-03-25 01:59:321230 false);
1231 SetLayerPropertiesForTesting(grand_child.get(),
1232 identity_matrix,
[email protected]fb661802013-03-25 01:59:321233 gfx::PointF(),
1234 gfx::PointF(),
1235 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571236 true,
[email protected]fb661802013-03-25 01:59:321237 false);
1238
1239 root->AddChild(child);
1240 child->AddChild(grand_child);
1241 child->SetForceRenderSurface(true);
1242
[email protected]d600df7d2013-08-03 02:34:281243 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1244 host->SetRootLayer(root);
1245
[email protected]fb661802013-03-25 01:59:321246 ExecuteCalculateDrawProperties(root.get());
1247
1248 ASSERT_TRUE(child->render_surface());
1249 // This is the real test, the rest are sanity checks.
1250 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1251 child->render_surface()->draw_transform());
1252 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1253 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1254 grand_child->draw_transform());
1255}
1256
[email protected]989386c2013-07-18 21:37:231257TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321258 // Transformations applied at the root of the tree should be forwarded
1259 // to child layers instead of applied to the root RenderSurface.
1260 const gfx::Transform identity_matrix;
[email protected]d5754282014-04-09 00:43:291261 scoped_refptr<LayerWithForcedDrawsContent> root =
1262 new LayerWithForcedDrawsContent;
1263 scoped_refptr<LayerWithForcedDrawsContent> child =
1264 new LayerWithForcedDrawsContent;
[email protected]adeda572014-01-31 00:49:471265 child->SetScrollClipLayerId(root->id());
[email protected]f224cc92013-06-06 23:23:321266 root->AddChild(child);
1267
[email protected]d600df7d2013-08-03 02:34:281268 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1269 host->SetRootLayer(root);
1270
[email protected]f224cc92013-06-06 23:23:321271 SetLayerPropertiesForTesting(root.get(),
1272 identity_matrix,
[email protected]f224cc92013-06-06 23:23:321273 gfx::PointF(),
1274 gfx::PointF(),
1275 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571276 true,
[email protected]f224cc92013-06-06 23:23:321277 false);
1278 SetLayerPropertiesForTesting(child.get(),
1279 identity_matrix,
[email protected]f224cc92013-06-06 23:23:321280 gfx::PointF(),
1281 gfx::PointF(),
1282 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571283 true,
[email protected]f224cc92013-06-06 23:23:321284 false);
1285
[email protected]f224cc92013-06-06 23:23:321286 gfx::Transform translate;
1287 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231288 {
1289 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531290 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1291 root.get(), root->bounds(), translate, &render_surface_layer_list);
1292 inputs.can_adjust_raster_scales = true;
1293 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231294 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1295 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1296 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291297 EXPECT_EQ(1.f, root->last_device_scale_factor());
1298 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231299 }
[email protected]f224cc92013-06-06 23:23:321300
1301 gfx::Transform scale;
1302 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231303 {
1304 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531305 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1306 root.get(), root->bounds(), scale, &render_surface_layer_list);
1307 inputs.can_adjust_raster_scales = true;
1308 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231309 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1310 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1311 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291312 EXPECT_EQ(2.f, root->last_device_scale_factor());
1313 EXPECT_EQ(2.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231314 }
[email protected]f224cc92013-06-06 23:23:321315
1316 gfx::Transform rotate;
1317 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231318 {
1319 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531320 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1321 root.get(), root->bounds(), rotate, &render_surface_layer_list);
1322 inputs.can_adjust_raster_scales = true;
1323 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231324 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1325 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1326 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291327 EXPECT_EQ(1.f, root->last_device_scale_factor());
1328 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231329 }
[email protected]f224cc92013-06-06 23:23:321330
1331 gfx::Transform composite;
1332 composite.ConcatTransform(translate);
1333 composite.ConcatTransform(scale);
1334 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231335 {
1336 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531337 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1338 root.get(), root->bounds(), composite, &render_surface_layer_list);
1339 inputs.can_adjust_raster_scales = true;
1340 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231341 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1342 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1343 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1344 }
[email protected]f224cc92013-06-06 23:23:321345
[email protected]9781afa2013-07-17 23:15:321346 // Verify it composes correctly with device scale.
1347 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231348
1349 {
1350 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531351 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1352 root.get(), root->bounds(), translate, &render_surface_layer_list);
1353 inputs.device_scale_factor = device_scale_factor;
1354 inputs.can_adjust_raster_scales = true;
1355 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231356 gfx::Transform device_scaled_translate = translate;
1357 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1358 EXPECT_EQ(device_scaled_translate,
1359 root->draw_properties().target_space_transform);
1360 EXPECT_EQ(device_scaled_translate,
1361 child->draw_properties().target_space_transform);
1362 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291363 EXPECT_EQ(device_scale_factor, root->last_device_scale_factor());
1364 EXPECT_EQ(device_scale_factor, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231365 }
[email protected]9781afa2013-07-17 23:15:321366
1367 // Verify it composes correctly with page scale.
1368 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231369
1370 {
1371 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531372 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1373 root.get(), root->bounds(), translate, &render_surface_layer_list);
1374 inputs.page_scale_factor = page_scale_factor;
1375 inputs.page_scale_application_layer = root.get();
1376 inputs.can_adjust_raster_scales = true;
1377 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231378 gfx::Transform page_scaled_translate = translate;
1379 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1380 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1381 EXPECT_EQ(page_scaled_translate,
1382 child->draw_properties().target_space_transform);
1383 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291384 EXPECT_EQ(1.f, root->last_device_scale_factor());
1385 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231386 }
[email protected]9781afa2013-07-17 23:15:321387
[email protected]f224cc92013-06-06 23:23:321388 // Verify that it composes correctly with transforms directly on root layer.
1389 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231390
1391 {
1392 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531393 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1394 root.get(), root->bounds(), composite, &render_surface_layer_list);
1395 inputs.can_adjust_raster_scales = true;
1396 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231397 gfx::Transform compositeSquared = composite;
1398 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261399 EXPECT_TRANSFORMATION_MATRIX_EQ(
1400 compositeSquared, root->draw_properties().target_space_transform);
1401 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391402 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231403 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1404 }
[email protected]f224cc92013-06-06 23:23:321405}
1406
[email protected]989386c2013-07-18 21:37:231407TEST_F(LayerTreeHostCommonTest,
1408 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321409 scoped_refptr<Layer> parent = Layer::Create();
1410 scoped_refptr<Layer> render_surface1 = Layer::Create();
1411 scoped_refptr<LayerWithForcedDrawsContent> child =
1412 make_scoped_refptr(new LayerWithForcedDrawsContent());
1413
[email protected]d600df7d2013-08-03 02:34:281414 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1415 host->SetRootLayer(parent);
1416
[email protected]fb661802013-03-25 01:59:321417 const gfx::Transform identity_matrix;
1418 SetLayerPropertiesForTesting(parent.get(),
1419 identity_matrix,
[email protected]fb661802013-03-25 01:59:321420 gfx::PointF(),
1421 gfx::PointF(),
1422 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571423 true,
[email protected]fb661802013-03-25 01:59:321424 false);
1425 SetLayerPropertiesForTesting(render_surface1.get(),
1426 identity_matrix,
[email protected]fb661802013-03-25 01:59:321427 gfx::PointF(),
1428 gfx::PointF(),
1429 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571430 true,
[email protected]fb661802013-03-25 01:59:321431 false);
1432 SetLayerPropertiesForTesting(child.get(),
1433 identity_matrix,
[email protected]fb661802013-03-25 01:59:321434 gfx::PointF(),
1435 gfx::PointF(30.f, 30.f),
1436 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571437 true,
[email protected]fb661802013-03-25 01:59:321438 false);
1439
1440 parent->AddChild(render_surface1);
1441 parent->SetMasksToBounds(true);
1442 render_surface1->AddChild(child);
1443 render_surface1->SetForceRenderSurface(true);
1444
[email protected]989386c2013-07-18 21:37:231445 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531446 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1447 parent.get(),
1448 parent->bounds(),
1449 gfx::Transform(),
1450 &render_surface_layer_list);
1451 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321452
1453 // The child layer's content is entirely outside the parent's clip rect, so
1454 // the intermediate render surface should not be listed here, even if it was
1455 // forced to be created. Render surfaces without children or visible content
1456 // are unexpected at draw time (e.g. we might try to create a content texture
1457 // of size 0).
1458 ASSERT_TRUE(parent->render_surface());
[email protected]fb661802013-03-25 01:59:321459 EXPECT_EQ(1U, render_surface_layer_list.size());
1460}
1461
[email protected]989386c2013-07-18 21:37:231462TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321463 scoped_refptr<Layer> parent = Layer::Create();
1464 scoped_refptr<Layer> render_surface1 = Layer::Create();
1465 scoped_refptr<LayerWithForcedDrawsContent> child =
1466 make_scoped_refptr(new LayerWithForcedDrawsContent());
1467
[email protected]d600df7d2013-08-03 02:34:281468 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1469 host->SetRootLayer(parent);
1470
[email protected]fb661802013-03-25 01:59:321471 const gfx::Transform identity_matrix;
1472 SetLayerPropertiesForTesting(render_surface1.get(),
1473 identity_matrix,
[email protected]fb661802013-03-25 01:59:321474 gfx::PointF(),
1475 gfx::PointF(),
1476 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571477 true,
[email protected]fb661802013-03-25 01:59:321478 false);
1479 SetLayerPropertiesForTesting(child.get(),
1480 identity_matrix,
[email protected]fb661802013-03-25 01:59:321481 gfx::PointF(),
1482 gfx::PointF(),
1483 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571484 true,
[email protected]fb661802013-03-25 01:59:321485 false);
1486
1487 parent->AddChild(render_surface1);
1488 render_surface1->AddChild(child);
1489 render_surface1->SetForceRenderSurface(true);
1490 render_surface1->SetOpacity(0.f);
1491
[email protected]989386c2013-07-18 21:37:231492 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531493 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1494 parent.get(), parent->bounds(), &render_surface_layer_list);
1495 inputs.can_adjust_raster_scales = true;
1496 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321497
1498 // Since the layer is transparent, render_surface1->render_surface() should
1499 // not have gotten added anywhere. Also, the drawable content rect should not
1500 // have been extended by the children.
1501 ASSERT_TRUE(parent->render_surface());
1502 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1503 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231504 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321505 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1506}
1507
[email protected]989386c2013-07-18 21:37:231508TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321509 scoped_refptr<Layer> parent = Layer::Create();
1510 scoped_refptr<Layer> render_surface1 = Layer::Create();
1511 scoped_refptr<LayerWithForcedDrawsContent> child =
1512 make_scoped_refptr(new LayerWithForcedDrawsContent());
1513 render_surface1->SetForceRenderSurface(true);
1514
[email protected]d600df7d2013-08-03 02:34:281515 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1516 host->SetRootLayer(parent);
1517
[email protected]fb661802013-03-25 01:59:321518 const gfx::Transform identity_matrix;
1519 SetLayerPropertiesForTesting(parent.get(),
1520 identity_matrix,
[email protected]fb661802013-03-25 01:59:321521 gfx::PointF(),
1522 gfx::PointF(),
1523 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571524 true,
[email protected]fb661802013-03-25 01:59:321525 false);
1526 SetLayerPropertiesForTesting(render_surface1.get(),
1527 identity_matrix,
[email protected]fb661802013-03-25 01:59:321528 gfx::PointF(),
1529 gfx::PointF(),
1530 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571531 true,
[email protected]fb661802013-03-25 01:59:321532 false);
1533 SetLayerPropertiesForTesting(child.get(),
1534 identity_matrix,
[email protected]fb661802013-03-25 01:59:321535 gfx::PointF(),
1536 gfx::PointF(),
1537 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571538 true,
[email protected]fb661802013-03-25 01:59:321539 false);
1540
1541 parent->AddChild(render_surface1);
1542 render_surface1->AddChild(child);
1543
1544 // Sanity check before the actual test
1545 EXPECT_FALSE(parent->render_surface());
1546 EXPECT_FALSE(render_surface1->render_surface());
1547
[email protected]989386c2013-07-18 21:37:231548 {
1549 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531550 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1551 parent.get(), parent->bounds(), &render_surface_layer_list);
1552 inputs.can_adjust_raster_scales = true;
1553 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321554
[email protected]989386c2013-07-18 21:37:231555 // The root layer always creates a render surface
1556 EXPECT_TRUE(parent->render_surface());
1557 EXPECT_TRUE(render_surface1->render_surface());
1558 EXPECT_EQ(2U, render_surface_layer_list.size());
1559 }
[email protected]fb661802013-03-25 01:59:321560
[email protected]989386c2013-07-18 21:37:231561 {
1562 RenderSurfaceLayerList render_surface_layer_list;
1563 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531564 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1565 parent.get(), parent->bounds(), &render_surface_layer_list);
1566 inputs.can_adjust_raster_scales = true;
1567 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231568 EXPECT_TRUE(parent->render_surface());
1569 EXPECT_FALSE(render_surface1->render_surface());
1570 EXPECT_EQ(1U, render_surface_layer_list.size());
1571 }
[email protected]fb661802013-03-25 01:59:321572}
1573
[email protected]989386c2013-07-18 21:37:231574TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321575 // The entire subtree of layers that are outside the clip rect should be
1576 // culled away, and should not affect the render_surface_layer_list.
1577 //
1578 // The test tree is set up as follows:
1579 // - all layers except the leaf_nodes are forced to be a new render surface
1580 // that have something to draw.
1581 // - parent is a large container layer.
1582 // - child has masksToBounds=true to cause clipping.
1583 // - grand_child is positioned outside of the child's bounds
1584 // - great_grand_child is also kept outside child's bounds.
1585 //
1586 // In this configuration, grand_child and great_grand_child are completely
1587 // outside the clip rect, and they should never get scheduled on the list of
1588 // render surfaces.
1589 //
1590
1591 const gfx::Transform identity_matrix;
1592 scoped_refptr<Layer> parent = Layer::Create();
1593 scoped_refptr<Layer> child = Layer::Create();
1594 scoped_refptr<Layer> grand_child = Layer::Create();
1595 scoped_refptr<Layer> great_grand_child = Layer::Create();
1596 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1597 make_scoped_refptr(new LayerWithForcedDrawsContent());
1598 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1599 make_scoped_refptr(new LayerWithForcedDrawsContent());
1600 parent->AddChild(child);
1601 child->AddChild(grand_child);
1602 grand_child->AddChild(great_grand_child);
1603
[email protected]d600df7d2013-08-03 02:34:281604 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1605 host->SetRootLayer(parent);
1606
[email protected]fb661802013-03-25 01:59:321607 // leaf_node1 ensures that parent and child are kept on the
1608 // render_surface_layer_list, even though grand_child and great_grand_child
1609 // should be clipped.
1610 child->AddChild(leaf_node1);
1611 great_grand_child->AddChild(leaf_node2);
1612
1613 SetLayerPropertiesForTesting(parent.get(),
1614 identity_matrix,
[email protected]fb661802013-03-25 01:59:321615 gfx::PointF(),
1616 gfx::PointF(),
1617 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571618 true,
[email protected]fb661802013-03-25 01:59:321619 false);
1620 SetLayerPropertiesForTesting(child.get(),
1621 identity_matrix,
[email protected]fb661802013-03-25 01:59:321622 gfx::PointF(),
1623 gfx::PointF(),
1624 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571625 true,
[email protected]fb661802013-03-25 01:59:321626 false);
1627 SetLayerPropertiesForTesting(grand_child.get(),
1628 identity_matrix,
[email protected]fb661802013-03-25 01:59:321629 gfx::PointF(),
1630 gfx::PointF(45.f, 45.f),
1631 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571632 true,
[email protected]fb661802013-03-25 01:59:321633 false);
1634 SetLayerPropertiesForTesting(great_grand_child.get(),
1635 identity_matrix,
[email protected]fb661802013-03-25 01:59:321636 gfx::PointF(),
1637 gfx::PointF(),
1638 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571639 true,
[email protected]fb661802013-03-25 01:59:321640 false);
1641 SetLayerPropertiesForTesting(leaf_node1.get(),
1642 identity_matrix,
[email protected]fb661802013-03-25 01:59:321643 gfx::PointF(),
1644 gfx::PointF(),
1645 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571646 true,
[email protected]fb661802013-03-25 01:59:321647 false);
1648 SetLayerPropertiesForTesting(leaf_node2.get(),
1649 identity_matrix,
[email protected]fb661802013-03-25 01:59:321650 gfx::PointF(),
1651 gfx::PointF(),
1652 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571653 true,
[email protected]fb661802013-03-25 01:59:321654 false);
1655
1656 child->SetMasksToBounds(true);
1657 child->SetOpacity(0.4f);
1658 child->SetForceRenderSurface(true);
1659 grand_child->SetOpacity(0.5f);
1660 great_grand_child->SetOpacity(0.4f);
1661
[email protected]989386c2013-07-18 21:37:231662 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
1668 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231669 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1670 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321671}
1672
[email protected]989386c2013-07-18 21:37:231673TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321674 // When a render surface has a clip rect, it is used to clip the content rect
1675 // of the surface. When the render surface is animating its transforms, then
1676 // the content rect's position in the clip rect is not defined on the main
1677 // thread, and its content rect should not be clipped.
1678
1679 // The test tree is set up as follows:
1680 // - parent is a container layer that masksToBounds=true to cause clipping.
1681 // - child is a render surface, which has a clip rect set to the bounds of
1682 // the parent.
1683 // - grand_child is a render surface, and the only visible content in child.
1684 // It is positioned outside of the clip rect from parent.
1685
1686 // In this configuration, grand_child should be outside the clipped
1687 // content rect of the child, making grand_child not appear in the
1688 // render_surface_layer_list. However, when we place an animation on the
1689 // child, this clipping should be avoided and we should keep the grand_child
1690 // in the render_surface_layer_list.
1691
1692 const gfx::Transform identity_matrix;
1693 scoped_refptr<Layer> parent = Layer::Create();
1694 scoped_refptr<Layer> child = Layer::Create();
1695 scoped_refptr<Layer> grand_child = Layer::Create();
1696 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1697 make_scoped_refptr(new LayerWithForcedDrawsContent());
1698 parent->AddChild(child);
1699 child->AddChild(grand_child);
1700 grand_child->AddChild(leaf_node);
1701
[email protected]d600df7d2013-08-03 02:34:281702 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1703 host->SetRootLayer(parent);
1704
[email protected]fb661802013-03-25 01:59:321705 SetLayerPropertiesForTesting(parent.get(),
1706 identity_matrix,
[email protected]fb661802013-03-25 01:59:321707 gfx::PointF(),
1708 gfx::PointF(),
1709 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571710 true,
[email protected]fb661802013-03-25 01:59:321711 false);
1712 SetLayerPropertiesForTesting(child.get(),
1713 identity_matrix,
[email protected]fb661802013-03-25 01:59:321714 gfx::PointF(),
1715 gfx::PointF(),
1716 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571717 true,
[email protected]fb661802013-03-25 01:59:321718 false);
1719 SetLayerPropertiesForTesting(grand_child.get(),
1720 identity_matrix,
[email protected]fb661802013-03-25 01:59:321721 gfx::PointF(),
1722 gfx::PointF(200.f, 200.f),
1723 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571724 true,
[email protected]fb661802013-03-25 01:59:321725 false);
1726 SetLayerPropertiesForTesting(leaf_node.get(),
1727 identity_matrix,
[email protected]fb661802013-03-25 01:59:321728 gfx::PointF(),
1729 gfx::PointF(),
1730 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571731 true,
[email protected]fb661802013-03-25 01:59:321732 false);
1733
1734 parent->SetMasksToBounds(true);
1735 child->SetOpacity(0.4f);
1736 child->SetForceRenderSurface(true);
1737 grand_child->SetOpacity(0.4f);
1738 grand_child->SetForceRenderSurface(true);
1739
[email protected]989386c2013-07-18 21:37:231740 {
1741 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531742 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1743 parent.get(), parent->bounds(), &render_surface_layer_list);
1744 inputs.can_adjust_raster_scales = true;
1745 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321746
[email protected]989386c2013-07-18 21:37:231747 // Without an animation, we should cull child and grand_child from the
1748 // render_surface_layer_list.
1749 ASSERT_EQ(1U, render_surface_layer_list.size());
1750 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1751 }
[email protected]fb661802013-03-25 01:59:321752
1753 // Now put an animating transform on child.
1754 AddAnimatedTransformToController(
1755 child->layer_animation_controller(), 10.0, 30, 0);
1756
[email protected]989386c2013-07-18 21:37:231757 {
1758 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531759 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1760 parent.get(), parent->bounds(), &render_surface_layer_list);
1761 inputs.can_adjust_raster_scales = true;
1762 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321763
[email protected]989386c2013-07-18 21:37:231764 // With an animating transform, we should keep child and grand_child in the
1765 // render_surface_layer_list.
1766 ASSERT_EQ(3U, render_surface_layer_list.size());
1767 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1768 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1769 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1770 }
[email protected]fb661802013-03-25 01:59:321771}
1772
[email protected]989386c2013-07-18 21:37:231773TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:321774 // Layer's IsClipped() property is set to true when:
1775 // - the layer clips its subtree, e.g. masks to bounds,
1776 // - the layer is clipped by an ancestor that contributes to the same
1777 // render target,
1778 // - a surface is clipped by an ancestor that contributes to the same
1779 // render target.
1780 //
1781 // In particular, for a layer that owns a render surface:
1782 // - the render surface inherits any clip from ancestors, and does NOT
1783 // pass that clipped status to the layer itself.
1784 // - but if the layer itself masks to bounds, it is considered clipped
1785 // and propagates the clip to the subtree.
1786
1787 const gfx::Transform identity_matrix;
1788 scoped_refptr<Layer> root = Layer::Create();
1789 scoped_refptr<Layer> parent = Layer::Create();
1790 scoped_refptr<Layer> child1 = Layer::Create();
1791 scoped_refptr<Layer> child2 = Layer::Create();
1792 scoped_refptr<Layer> grand_child = Layer::Create();
1793 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1794 make_scoped_refptr(new LayerWithForcedDrawsContent());
1795 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1796 make_scoped_refptr(new LayerWithForcedDrawsContent());
1797 root->AddChild(parent);
1798 parent->AddChild(child1);
1799 parent->AddChild(child2);
1800 child1->AddChild(grand_child);
1801 child2->AddChild(leaf_node2);
1802 grand_child->AddChild(leaf_node1);
1803
[email protected]d600df7d2013-08-03 02:34:281804 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1805 host->SetRootLayer(root);
1806
[email protected]fb661802013-03-25 01:59:321807 child2->SetForceRenderSurface(true);
1808
1809 SetLayerPropertiesForTesting(root.get(),
1810 identity_matrix,
[email protected]fb661802013-03-25 01:59:321811 gfx::PointF(),
1812 gfx::PointF(),
1813 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571814 true,
[email protected]fb661802013-03-25 01:59:321815 false);
1816 SetLayerPropertiesForTesting(parent.get(),
1817 identity_matrix,
[email protected]fb661802013-03-25 01:59:321818 gfx::PointF(),
1819 gfx::PointF(),
1820 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571821 true,
[email protected]fb661802013-03-25 01:59:321822 false);
1823 SetLayerPropertiesForTesting(child1.get(),
1824 identity_matrix,
[email protected]fb661802013-03-25 01:59:321825 gfx::PointF(),
1826 gfx::PointF(),
1827 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571828 true,
[email protected]fb661802013-03-25 01:59:321829 false);
1830 SetLayerPropertiesForTesting(child2.get(),
1831 identity_matrix,
[email protected]fb661802013-03-25 01:59:321832 gfx::PointF(),
1833 gfx::PointF(),
1834 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571835 true,
[email protected]fb661802013-03-25 01:59:321836 false);
1837 SetLayerPropertiesForTesting(grand_child.get(),
1838 identity_matrix,
[email protected]fb661802013-03-25 01:59:321839 gfx::PointF(),
1840 gfx::PointF(),
1841 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571842 true,
[email protected]fb661802013-03-25 01:59:321843 false);
1844 SetLayerPropertiesForTesting(leaf_node1.get(),
1845 identity_matrix,
[email protected]fb661802013-03-25 01:59:321846 gfx::PointF(),
1847 gfx::PointF(),
1848 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571849 true,
[email protected]fb661802013-03-25 01:59:321850 false);
1851 SetLayerPropertiesForTesting(leaf_node2.get(),
1852 identity_matrix,
[email protected]fb661802013-03-25 01:59:321853 gfx::PointF(),
1854 gfx::PointF(),
1855 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571856 true,
[email protected]fb661802013-03-25 01:59:321857 false);
1858
[email protected]989386c2013-07-18 21:37:231859 // Case 1: nothing is clipped except the root render surface.
1860 {
1861 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531862 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1863 root.get(), parent->bounds(), &render_surface_layer_list);
1864 inputs.can_adjust_raster_scales = true;
1865 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321866
[email protected]989386c2013-07-18 21:37:231867 ASSERT_TRUE(root->render_surface());
1868 ASSERT_TRUE(child2->render_surface());
1869
1870 EXPECT_FALSE(root->is_clipped());
1871 EXPECT_TRUE(root->render_surface()->is_clipped());
1872 EXPECT_FALSE(parent->is_clipped());
1873 EXPECT_FALSE(child1->is_clipped());
1874 EXPECT_FALSE(child2->is_clipped());
1875 EXPECT_FALSE(child2->render_surface()->is_clipped());
1876 EXPECT_FALSE(grand_child->is_clipped());
1877 EXPECT_FALSE(leaf_node1->is_clipped());
1878 EXPECT_FALSE(leaf_node2->is_clipped());
1879 }
[email protected]fb661802013-03-25 01:59:321880
1881 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1882 // surface are clipped. But layers that contribute to child2's surface are
1883 // not clipped explicitly because child2's surface already accounts for
1884 // that clip.
[email protected]989386c2013-07-18 21:37:231885 {
1886 RenderSurfaceLayerList render_surface_layer_list;
1887 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531888 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1889 root.get(), parent->bounds(), &render_surface_layer_list);
1890 inputs.can_adjust_raster_scales = true;
1891 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321892
[email protected]989386c2013-07-18 21:37:231893 ASSERT_TRUE(root->render_surface());
1894 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321895
[email protected]989386c2013-07-18 21:37:231896 EXPECT_FALSE(root->is_clipped());
1897 EXPECT_TRUE(root->render_surface()->is_clipped());
1898 EXPECT_TRUE(parent->is_clipped());
1899 EXPECT_TRUE(child1->is_clipped());
1900 EXPECT_FALSE(child2->is_clipped());
1901 EXPECT_TRUE(child2->render_surface()->is_clipped());
1902 EXPECT_TRUE(grand_child->is_clipped());
1903 EXPECT_TRUE(leaf_node1->is_clipped());
1904 EXPECT_FALSE(leaf_node2->is_clipped());
1905 }
[email protected]fb661802013-03-25 01:59:321906
1907 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1908 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:231909 {
1910 RenderSurfaceLayerList render_surface_layer_list;
1911 parent->SetMasksToBounds(false);
1912 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531913 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1914 root.get(), parent->bounds(), &render_surface_layer_list);
1915 inputs.can_adjust_raster_scales = true;
1916 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321917
[email protected]989386c2013-07-18 21:37:231918 ASSERT_TRUE(root->render_surface());
1919 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321920
[email protected]989386c2013-07-18 21:37:231921 EXPECT_FALSE(root->is_clipped());
1922 EXPECT_TRUE(root->render_surface()->is_clipped());
1923 EXPECT_FALSE(parent->is_clipped());
1924 EXPECT_FALSE(child1->is_clipped());
1925 EXPECT_TRUE(child2->is_clipped());
1926 EXPECT_FALSE(child2->render_surface()->is_clipped());
1927 EXPECT_FALSE(grand_child->is_clipped());
1928 EXPECT_FALSE(leaf_node1->is_clipped());
1929 EXPECT_TRUE(leaf_node2->is_clipped());
1930 }
[email protected]fb661802013-03-25 01:59:321931}
1932
[email protected]fd9a3b6d2013-08-03 00:46:171933TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321934 // Verify that layers get the appropriate DrawableContentRect when their
1935 // parent masksToBounds is true.
1936 //
1937 // grand_child1 - completely inside the region; DrawableContentRect should
1938 // be the layer rect expressed in target space.
1939 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1940 // will be the intersection of layer bounds and the mask region.
1941 // grand_child3 - partially clipped and masksToBounds; the
1942 // DrawableContentRect will still be the intersection of layer bounds and
1943 // the mask region.
1944 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1945 // be empty.
1946 //
1947
1948 const gfx::Transform identity_matrix;
1949 scoped_refptr<Layer> parent = Layer::Create();
1950 scoped_refptr<Layer> child = Layer::Create();
1951 scoped_refptr<Layer> grand_child1 = Layer::Create();
1952 scoped_refptr<Layer> grand_child2 = Layer::Create();
1953 scoped_refptr<Layer> grand_child3 = Layer::Create();
1954 scoped_refptr<Layer> grand_child4 = Layer::Create();
1955
1956 parent->AddChild(child);
1957 child->AddChild(grand_child1);
1958 child->AddChild(grand_child2);
1959 child->AddChild(grand_child3);
1960 child->AddChild(grand_child4);
1961
[email protected]d600df7d2013-08-03 02:34:281962 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1963 host->SetRootLayer(parent);
1964
[email protected]fb661802013-03-25 01:59:321965 SetLayerPropertiesForTesting(parent.get(),
1966 identity_matrix,
[email protected]fb661802013-03-25 01:59:321967 gfx::PointF(),
1968 gfx::PointF(),
1969 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571970 true,
[email protected]fb661802013-03-25 01:59:321971 false);
1972 SetLayerPropertiesForTesting(child.get(),
1973 identity_matrix,
[email protected]fb661802013-03-25 01:59:321974 gfx::PointF(),
1975 gfx::PointF(),
1976 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571977 true,
[email protected]fb661802013-03-25 01:59:321978 false);
1979 SetLayerPropertiesForTesting(grand_child1.get(),
1980 identity_matrix,
[email protected]fb661802013-03-25 01:59:321981 gfx::PointF(),
1982 gfx::PointF(5.f, 5.f),
1983 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571984 true,
[email protected]fb661802013-03-25 01:59:321985 false);
1986 SetLayerPropertiesForTesting(grand_child2.get(),
1987 identity_matrix,
[email protected]fb661802013-03-25 01:59:321988 gfx::PointF(),
1989 gfx::PointF(15.f, 15.f),
1990 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571991 true,
[email protected]fb661802013-03-25 01:59:321992 false);
1993 SetLayerPropertiesForTesting(grand_child3.get(),
1994 identity_matrix,
[email protected]fb661802013-03-25 01:59:321995 gfx::PointF(),
1996 gfx::PointF(15.f, 15.f),
1997 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571998 true,
[email protected]fb661802013-03-25 01:59:321999 false);
2000 SetLayerPropertiesForTesting(grand_child4.get(),
2001 identity_matrix,
[email protected]fb661802013-03-25 01:59:322002 gfx::PointF(),
2003 gfx::PointF(45.f, 45.f),
2004 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572005 true,
[email protected]fb661802013-03-25 01:59:322006 false);
2007
2008 child->SetMasksToBounds(true);
2009 grand_child3->SetMasksToBounds(true);
2010
2011 // Force everyone to be a render surface.
2012 child->SetOpacity(0.4f);
2013 grand_child1->SetOpacity(0.5f);
2014 grand_child2->SetOpacity(0.5f);
2015 grand_child3->SetOpacity(0.5f);
2016 grand_child4->SetOpacity(0.5f);
2017
[email protected]989386c2013-07-18 21:37:232018 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532019 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2020 parent.get(), parent->bounds(), &render_surface_layer_list);
2021 inputs.can_adjust_raster_scales = true;
2022 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322023
[email protected]2c7c6702013-03-26 03:14:052024 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
[email protected]fb661802013-03-25 01:59:322025 grand_child1->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:052026 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:322027 grand_child3->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:052028 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:322029 grand_child3->drawable_content_rect());
2030 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2031}
2032
[email protected]989386c2013-07-18 21:37:232033TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322034 // Verify that render surfaces (and their layers) get the appropriate
2035 // clip rects when their parent masksToBounds is true.
2036 //
2037 // Layers that own render surfaces (at least for now) do not inherit any
2038 // clipping; instead the surface will enforce the clip for the entire subtree.
2039 // They may still have a clip rect of their own layer bounds, however, if
2040 // masksToBounds was true.
2041 const gfx::Transform identity_matrix;
2042 scoped_refptr<Layer> parent = Layer::Create();
2043 scoped_refptr<Layer> child = Layer::Create();
2044 scoped_refptr<Layer> grand_child1 = Layer::Create();
2045 scoped_refptr<Layer> grand_child2 = Layer::Create();
2046 scoped_refptr<Layer> grand_child3 = Layer::Create();
2047 scoped_refptr<Layer> grand_child4 = Layer::Create();
2048 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2049 make_scoped_refptr(new LayerWithForcedDrawsContent());
2050 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2051 make_scoped_refptr(new LayerWithForcedDrawsContent());
2052 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
2053 make_scoped_refptr(new LayerWithForcedDrawsContent());
2054 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
2055 make_scoped_refptr(new LayerWithForcedDrawsContent());
2056
2057 parent->AddChild(child);
2058 child->AddChild(grand_child1);
2059 child->AddChild(grand_child2);
2060 child->AddChild(grand_child3);
2061 child->AddChild(grand_child4);
2062
[email protected]d600df7d2013-08-03 02:34:282063 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2064 host->SetRootLayer(parent);
2065
[email protected]fb661802013-03-25 01:59:322066 // the leaf nodes ensure that these grand_children become render surfaces for
2067 // this test.
2068 grand_child1->AddChild(leaf_node1);
2069 grand_child2->AddChild(leaf_node2);
2070 grand_child3->AddChild(leaf_node3);
2071 grand_child4->AddChild(leaf_node4);
2072
2073 SetLayerPropertiesForTesting(parent.get(),
2074 identity_matrix,
[email protected]fb661802013-03-25 01:59:322075 gfx::PointF(),
2076 gfx::PointF(),
2077 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:572078 true,
[email protected]fb661802013-03-25 01:59:322079 false);
2080 SetLayerPropertiesForTesting(child.get(),
2081 identity_matrix,
[email protected]fb661802013-03-25 01:59:322082 gfx::PointF(),
2083 gfx::PointF(),
2084 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:572085 true,
[email protected]fb661802013-03-25 01:59:322086 false);
2087 SetLayerPropertiesForTesting(grand_child1.get(),
2088 identity_matrix,
[email protected]fb661802013-03-25 01:59:322089 gfx::PointF(),
2090 gfx::PointF(5.f, 5.f),
2091 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572092 true,
[email protected]fb661802013-03-25 01:59:322093 false);
2094 SetLayerPropertiesForTesting(grand_child2.get(),
2095 identity_matrix,
[email protected]fb661802013-03-25 01:59:322096 gfx::PointF(),
2097 gfx::PointF(15.f, 15.f),
2098 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572099 true,
[email protected]fb661802013-03-25 01:59:322100 false);
2101 SetLayerPropertiesForTesting(grand_child3.get(),
2102 identity_matrix,
[email protected]fb661802013-03-25 01:59:322103 gfx::PointF(),
2104 gfx::PointF(15.f, 15.f),
2105 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572106 true,
[email protected]fb661802013-03-25 01:59:322107 false);
2108 SetLayerPropertiesForTesting(grand_child4.get(),
2109 identity_matrix,
[email protected]fb661802013-03-25 01:59:322110 gfx::PointF(),
2111 gfx::PointF(45.f, 45.f),
2112 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572113 true,
[email protected]fb661802013-03-25 01:59:322114 false);
2115 SetLayerPropertiesForTesting(leaf_node1.get(),
2116 identity_matrix,
[email protected]fb661802013-03-25 01:59:322117 gfx::PointF(),
2118 gfx::PointF(),
2119 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572120 true,
[email protected]fb661802013-03-25 01:59:322121 false);
2122 SetLayerPropertiesForTesting(leaf_node2.get(),
2123 identity_matrix,
[email protected]fb661802013-03-25 01:59:322124 gfx::PointF(),
2125 gfx::PointF(),
2126 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572127 true,
[email protected]fb661802013-03-25 01:59:322128 false);
2129 SetLayerPropertiesForTesting(leaf_node3.get(),
2130 identity_matrix,
[email protected]fb661802013-03-25 01:59:322131 gfx::PointF(),
2132 gfx::PointF(),
2133 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572134 true,
[email protected]fb661802013-03-25 01:59:322135 false);
2136 SetLayerPropertiesForTesting(leaf_node4.get(),
2137 identity_matrix,
[email protected]fb661802013-03-25 01:59:322138 gfx::PointF(),
2139 gfx::PointF(),
2140 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572141 true,
[email protected]fb661802013-03-25 01:59:322142 false);
2143
2144 child->SetMasksToBounds(true);
2145 grand_child3->SetMasksToBounds(true);
2146 grand_child4->SetMasksToBounds(true);
2147
2148 // Force everyone to be a render surface.
2149 child->SetOpacity(0.4f);
2150 child->SetForceRenderSurface(true);
2151 grand_child1->SetOpacity(0.5f);
2152 grand_child1->SetForceRenderSurface(true);
2153 grand_child2->SetOpacity(0.5f);
2154 grand_child2->SetForceRenderSurface(true);
2155 grand_child3->SetOpacity(0.5f);
2156 grand_child3->SetForceRenderSurface(true);
2157 grand_child4->SetOpacity(0.5f);
2158 grand_child4->SetForceRenderSurface(true);
2159
[email protected]989386c2013-07-18 21:37:232160 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532161 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2162 parent.get(), parent->bounds(), &render_surface_layer_list);
2163 inputs.can_adjust_raster_scales = true;
2164 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322165 ASSERT_TRUE(grand_child1->render_surface());
2166 ASSERT_TRUE(grand_child2->render_surface());
2167 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322168
2169 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2170 // masksToBounds.
[email protected]2c7c6702013-03-26 03:14:052171 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322172 grand_child1->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052173 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322174 grand_child2->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052175 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322176 grand_child3->render_surface()->clip_rect());
2177}
2178
[email protected]989386c2013-07-18 21:37:232179TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322180 scoped_refptr<Layer> parent = Layer::Create();
2181 scoped_refptr<Layer> render_surface1 = Layer::Create();
2182 scoped_refptr<Layer> render_surface2 = Layer::Create();
2183 scoped_refptr<Layer> child_of_root = Layer::Create();
2184 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2185 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2186 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2187 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2188 make_scoped_refptr(new LayerWithForcedDrawsContent());
2189 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2190 make_scoped_refptr(new LayerWithForcedDrawsContent());
2191 parent->AddChild(render_surface1);
2192 parent->AddChild(child_of_root);
2193 render_surface1->AddChild(child_of_rs1);
2194 render_surface1->AddChild(render_surface2);
2195 render_surface2->AddChild(child_of_rs2);
2196 child_of_root->AddChild(grand_child_of_root);
2197 child_of_rs1->AddChild(grand_child_of_rs1);
2198 child_of_rs2->AddChild(grand_child_of_rs2);
2199
[email protected]d600df7d2013-08-03 02:34:282200 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2201 host->SetRootLayer(parent);
2202
[email protected]fb661802013-03-25 01:59:322203 // Make our render surfaces.
2204 render_surface1->SetForceRenderSurface(true);
2205 render_surface2->SetForceRenderSurface(true);
2206
2207 gfx::Transform layer_transform;
2208 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322209
2210 SetLayerPropertiesForTesting(parent.get(),
2211 layer_transform,
[email protected]fb661802013-03-25 01:59:322212 gfx::PointF(0.25f, 0.f),
2213 gfx::PointF(2.5f, 0.f),
2214 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572215 true,
[email protected]fb661802013-03-25 01:59:322216 false);
2217 SetLayerPropertiesForTesting(render_surface1.get(),
2218 layer_transform,
[email protected]fb661802013-03-25 01:59:322219 gfx::PointF(0.25f, 0.f),
2220 gfx::PointF(2.5f, 0.f),
2221 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572222 true,
[email protected]fb661802013-03-25 01:59:322223 false);
2224 SetLayerPropertiesForTesting(render_surface2.get(),
2225 layer_transform,
[email protected]fb661802013-03-25 01:59:322226 gfx::PointF(0.25f, 0.f),
2227 gfx::PointF(2.5f, 0.f),
2228 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572229 true,
[email protected]fb661802013-03-25 01:59:322230 false);
2231 SetLayerPropertiesForTesting(child_of_root.get(),
2232 layer_transform,
[email protected]fb661802013-03-25 01:59:322233 gfx::PointF(0.25f, 0.f),
2234 gfx::PointF(2.5f, 0.f),
2235 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572236 true,
[email protected]fb661802013-03-25 01:59:322237 false);
2238 SetLayerPropertiesForTesting(child_of_rs1.get(),
2239 layer_transform,
[email protected]fb661802013-03-25 01:59:322240 gfx::PointF(0.25f, 0.f),
2241 gfx::PointF(2.5f, 0.f),
2242 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572243 true,
[email protected]fb661802013-03-25 01:59:322244 false);
2245 SetLayerPropertiesForTesting(child_of_rs2.get(),
2246 layer_transform,
[email protected]fb661802013-03-25 01:59:322247 gfx::PointF(0.25f, 0.f),
2248 gfx::PointF(2.5f, 0.f),
2249 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572250 true,
[email protected]fb661802013-03-25 01:59:322251 false);
2252 SetLayerPropertiesForTesting(grand_child_of_root.get(),
2253 layer_transform,
[email protected]fb661802013-03-25 01:59:322254 gfx::PointF(0.25f, 0.f),
2255 gfx::PointF(2.5f, 0.f),
2256 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572257 true,
[email protected]fb661802013-03-25 01:59:322258 false);
2259 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
2260 layer_transform,
[email protected]fb661802013-03-25 01:59:322261 gfx::PointF(0.25f, 0.f),
2262 gfx::PointF(2.5f, 0.f),
2263 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572264 true,
[email protected]fb661802013-03-25 01:59:322265 false);
2266 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
2267 layer_transform,
[email protected]fb661802013-03-25 01:59:322268 gfx::PointF(0.25f, 0.f),
2269 gfx::PointF(2.5f, 0.f),
2270 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572271 true,
[email protected]fb661802013-03-25 01:59:322272 false);
2273
2274 // Put an animated opacity on the render surface.
2275 AddOpacityTransitionToController(
2276 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2277
2278 // Also put an animated opacity on a layer without descendants.
2279 AddOpacityTransitionToController(
2280 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2281
2282 // Put a transform animation on the render surface.
2283 AddAnimatedTransformToController(
2284 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2285
2286 // Also put transform animations on grand_child_of_root, and
2287 // grand_child_of_rs2
2288 AddAnimatedTransformToController(
2289 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2290 AddAnimatedTransformToController(
2291 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2292
2293 ExecuteCalculateDrawProperties(parent.get());
2294
2295 // Only layers that are associated with render surfaces should have an actual
2296 // RenderSurface() value.
2297 ASSERT_TRUE(parent->render_surface());
2298 ASSERT_FALSE(child_of_root->render_surface());
2299 ASSERT_FALSE(grand_child_of_root->render_surface());
2300
2301 ASSERT_TRUE(render_surface1->render_surface());
2302 ASSERT_FALSE(child_of_rs1->render_surface());
2303 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2304
2305 ASSERT_TRUE(render_surface2->render_surface());
2306 ASSERT_FALSE(child_of_rs2->render_surface());
2307 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2308
2309 // Verify all render target accessors
2310 EXPECT_EQ(parent, parent->render_target());
2311 EXPECT_EQ(parent, child_of_root->render_target());
2312 EXPECT_EQ(parent, grand_child_of_root->render_target());
2313
2314 EXPECT_EQ(render_surface1, render_surface1->render_target());
2315 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2316 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
2317
2318 EXPECT_EQ(render_surface2, render_surface2->render_target());
2319 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2320 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
2321
2322 // Verify draw_opacity_is_animating values
2323 EXPECT_FALSE(parent->draw_opacity_is_animating());
2324 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2325 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2326 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2327 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2328 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2329 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2330 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2331 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2332 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2333 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2334
2335 // Verify draw_transform_is_animating values
2336 EXPECT_FALSE(parent->draw_transform_is_animating());
2337 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2338 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2339 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2340 EXPECT_FALSE(render_surface1->render_surface()
2341 ->target_surface_transforms_are_animating());
2342 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2343 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2344 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2345 EXPECT_TRUE(render_surface2->render_surface()
2346 ->target_surface_transforms_are_animating());
2347 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2348 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2349
2350 // Verify screen_space_transform_is_animating values
2351 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2352 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2353 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2354 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2355 EXPECT_FALSE(render_surface1->render_surface()
2356 ->screen_space_transforms_are_animating());
2357 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2358 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2359 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2360 EXPECT_TRUE(render_surface2->render_surface()
2361 ->screen_space_transforms_are_animating());
2362 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2363 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2364
2365 // Sanity check. If these fail there is probably a bug in the test itself.
2366 // It is expected that we correctly set up transforms so that the y-component
2367 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262368 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2369 EXPECT_FLOAT_EQ(2.0,
2370 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322371 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262372 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322373
[email protected]803f6b52013-09-12 00:51:262374 EXPECT_FLOAT_EQ(2.0,
2375 render_surface1->screen_space_transform().matrix().get(1, 3));
2376 EXPECT_FLOAT_EQ(3.0,
2377 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322378 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262379 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322380
[email protected]803f6b52013-09-12 00:51:262381 EXPECT_FLOAT_EQ(3.0,
2382 render_surface2->screen_space_transform().matrix().get(1, 3));
2383 EXPECT_FLOAT_EQ(4.0,
2384 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322385 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262386 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322387}
2388
[email protected]989386c2013-07-18 21:37:232389TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322390 // Test the calculateVisibleRect() function works correctly for identity
2391 // transforms.
2392
[email protected]2c7c6702013-03-26 03:14:052393 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322394 gfx::Transform layer_to_surface_transform;
2395
2396 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232397 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052398 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322399 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2400 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2401 EXPECT_RECT_EQ(expected, actual);
2402
2403 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052404 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322405 actual = LayerTreeHostCommon::CalculateVisibleRect(
2406 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2407 EXPECT_TRUE(actual.IsEmpty());
2408
2409 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052410 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2411 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322412 actual = LayerTreeHostCommon::CalculateVisibleRect(
2413 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2414 EXPECT_RECT_EQ(expected, actual);
2415}
2416
[email protected]989386c2013-07-18 21:37:232417TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322418 // Test the calculateVisibleRect() function works correctly for scaling
2419 // transforms.
2420
[email protected]2c7c6702013-03-26 03:14:052421 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2422 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322423 gfx::Transform layer_to_surface_transform;
2424
2425 // Case 1: Layer is contained within the surface.
2426 layer_to_surface_transform.MakeIdentity();
2427 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052428 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322429 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2430 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2431 EXPECT_RECT_EQ(expected, actual);
2432
2433 // Case 2: Layer is outside the surface rect.
2434 layer_to_surface_transform.MakeIdentity();
2435 layer_to_surface_transform.Translate(120.0, 120.0);
2436 actual = LayerTreeHostCommon::CalculateVisibleRect(
2437 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2438 EXPECT_TRUE(actual.IsEmpty());
2439
2440 // Case 3: Layer is partially overlapping the surface rect.
2441 layer_to_surface_transform.MakeIdentity();
2442 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052443 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322444 actual = LayerTreeHostCommon::CalculateVisibleRect(
2445 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2446 EXPECT_RECT_EQ(expected, actual);
2447}
2448
[email protected]989386c2013-07-18 21:37:232449TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322450 // Test the calculateVisibleRect() function works correctly for rotations
2451 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2452 // should return the g in the layer's space.
2453
[email protected]2c7c6702013-03-26 03:14:052454 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2455 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322456 gfx::Transform layer_to_surface_transform;
2457
2458 // Case 1: Layer is contained within the surface.
2459 layer_to_surface_transform.MakeIdentity();
2460 layer_to_surface_transform.Translate(50.0, 50.0);
2461 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052462 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322463 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2464 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2465 EXPECT_RECT_EQ(expected, actual);
2466
2467 // Case 2: Layer is outside the surface rect.
2468 layer_to_surface_transform.MakeIdentity();
2469 layer_to_surface_transform.Translate(-50.0, 0.0);
2470 layer_to_surface_transform.Rotate(45.0);
2471 actual = LayerTreeHostCommon::CalculateVisibleRect(
2472 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2473 EXPECT_TRUE(actual.IsEmpty());
2474
2475 // Case 3: The layer is rotated about its top-left corner. In surface space,
2476 // the layer is oriented diagonally, with the left half outside of the render
2477 // surface. In this case, the g should still be the entire layer
2478 // (remember the g is computed in layer space); both the top-left
2479 // and bottom-right corners of the layer are still visible.
2480 layer_to_surface_transform.MakeIdentity();
2481 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052482 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322483 actual = LayerTreeHostCommon::CalculateVisibleRect(
2484 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2485 EXPECT_RECT_EQ(expected, actual);
2486
2487 // Case 4: The layer is rotated about its top-left corner, and translated
2488 // upwards. In surface space, the layer is oriented diagonally, with only the
2489 // top corner of the surface overlapping the layer. In layer space, the render
2490 // surface overlaps the right side of the layer. The g should be
2491 // the layer's right half.
2492 layer_to_surface_transform.MakeIdentity();
2493 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2494 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052495 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322496 actual = LayerTreeHostCommon::CalculateVisibleRect(
2497 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2498 EXPECT_RECT_EQ(expected, actual);
2499}
2500
[email protected]989386c2013-07-18 21:37:232501TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322502 // Test that the calculateVisibleRect() function works correctly for 3d
2503 // transforms.
2504
[email protected]2c7c6702013-03-26 03:14:052505 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2506 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322507 gfx::Transform layer_to_surface_transform;
2508
2509 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2510 // degrees, should be fully contained in the render surface.
2511 layer_to_surface_transform.MakeIdentity();
2512 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052513 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322514 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2515 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2516 EXPECT_RECT_EQ(expected, actual);
2517
2518 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2519 // degrees, but shifted to the side so only the right-half the layer would be
2520 // visible on the surface.
2521 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262522 SkMScalar half_width_of_rotated_layer =
2523 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322524 layer_to_surface_transform.MakeIdentity();
2525 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232526 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2527 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052528 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322529 actual = LayerTreeHostCommon::CalculateVisibleRect(
2530 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2531 EXPECT_RECT_EQ(expected, actual);
2532}
2533
[email protected]989386c2013-07-18 21:37:232534TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322535 // Test the calculateVisibleRect() function works correctly when the layer has
2536 // a perspective projection onto the target surface.
2537
[email protected]2c7c6702013-03-26 03:14:052538 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2539 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322540 gfx::Transform layer_to_surface_transform;
2541
2542 // Case 1: Even though the layer is twice as large as the surface, due to
2543 // perspective foreshortening, the layer will fit fully in the surface when
2544 // its translated more than the perspective amount.
2545 layer_to_surface_transform.MakeIdentity();
2546
2547 // The following sequence of transforms applies the perspective about the
2548 // center of the surface.
2549 layer_to_surface_transform.Translate(50.0, 50.0);
2550 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2551 layer_to_surface_transform.Translate(-50.0, -50.0);
2552
2553 // This translate places the layer in front of the surface's projection plane.
2554 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2555
[email protected]2c7c6702013-03-26 03:14:052556 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322557 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2558 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2559 EXPECT_RECT_EQ(expected, actual);
2560
2561 // Case 2: same projection as before, except that the layer is also translated
2562 // to the side, so that only the right half of the layer should be visible.
2563 //
2564 // Explanation of expected result: The perspective ratio is (z distance
2565 // between layer and camera origin) / (z distance between projection plane and
2566 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2567 // move a layer by translating -50 units in projected surface units (so that
2568 // only half of it is visible), then we would need to translate by (-36 / 9) *
2569 // -50 == -200 in the layer's units.
2570 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232571 expected = gfx::Rect(gfx::Point(50, -50),
2572 gfx::Size(100, 200)); // The right half of the layer's
2573 // bounding rect.
[email protected]fb661802013-03-25 01:59:322574 actual = LayerTreeHostCommon::CalculateVisibleRect(
2575 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2576 EXPECT_RECT_EQ(expected, actual);
2577}
2578
[email protected]989386c2013-07-18 21:37:232579TEST_F(LayerTreeHostCommonTest,
2580 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322581 // There is currently no explicit concept of an orthographic projection plane
2582 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2583 // are technically behind the surface in an orthographic world should not be
2584 // clipped when they are flattened to the surface.
2585
[email protected]2c7c6702013-03-26 03:14:052586 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2587 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322588 gfx::Transform layer_to_surface_transform;
2589
2590 // This sequence of transforms effectively rotates the layer about the y-axis
2591 // at the center of the layer.
2592 layer_to_surface_transform.MakeIdentity();
2593 layer_to_surface_transform.Translate(50.0, 0.0);
2594 layer_to_surface_transform.RotateAboutYAxis(45.0);
2595 layer_to_surface_transform.Translate(-50.0, 0.0);
2596
[email protected]2c7c6702013-03-26 03:14:052597 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322598 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2599 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2600 EXPECT_RECT_EQ(expected, actual);
2601}
2602
[email protected]989386c2013-07-18 21:37:232603TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322604 // Test the calculateVisibleRect() function works correctly when projecting a
2605 // surface onto a layer, but the layer is partially behind the camera (not
2606 // just behind the projection plane). In this case, the cartesian coordinates
2607 // may seem to be valid, but actually they are not. The visible rect needs to
2608 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2609 // converting to cartesian coordinates.
2610
[email protected]2c7c6702013-03-26 03:14:052611 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232612 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322613 gfx::Transform layer_to_surface_transform;
2614
2615 // The layer is positioned so that the right half of the layer should be in
2616 // front of the camera, while the other half is behind the surface's
2617 // projection plane. The following sequence of transforms applies the
2618 // perspective and rotation about the center of the layer.
2619 layer_to_surface_transform.MakeIdentity();
2620 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2621 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2622 layer_to_surface_transform.RotateAboutYAxis(45.0);
2623
2624 // Sanity check that this transform does indeed cause w < 0 when applying the
2625 // transform, otherwise this code is not testing the intended scenario.
2626 bool clipped;
2627 MathUtil::MapQuad(layer_to_surface_transform,
2628 gfx::QuadF(gfx::RectF(layer_content_rect)),
2629 &clipped);
2630 ASSERT_TRUE(clipped);
2631
2632 int expected_x_position = 0;
2633 int expected_width = 10;
2634 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2635 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2636 EXPECT_EQ(expected_x_position, actual.x());
2637 EXPECT_EQ(expected_width, actual.width());
2638}
2639
[email protected]989386c2013-07-18 21:37:232640TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322641 // To determine visible rect in layer space, there needs to be an
2642 // un-projection from surface space to layer space. When the original
2643 // transform was a perspective projection that was clipped, it returns a rect
2644 // that encloses the clipped bounds. Un-projecting this new rect may require
2645 // clipping again.
2646
2647 // This sequence of transforms causes one corner of the layer to protrude
2648 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232649 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2650 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322651 gfx::Transform layer_to_surface_transform;
2652 layer_to_surface_transform.MakeIdentity();
2653 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2654 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2655 layer_to_surface_transform.RotateAboutYAxis(45.0);
2656 layer_to_surface_transform.RotateAboutXAxis(80.0);
2657
2658 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2659 // code is not testing the intended scenario.
2660 bool clipped;
2661 gfx::RectF clipped_rect =
2662 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2663 MathUtil::ProjectQuad(
2664 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2665 ASSERT_TRUE(clipped);
2666
2667 // Only the corner of the layer is not visible on the surface because of being
2668 // clipped. But, the net result of rounding visible region to an axis-aligned
2669 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052670 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322671 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2672 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2673 EXPECT_RECT_EQ(expected, actual);
2674}
2675
[email protected]989386c2013-07-18 21:37:232676TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322677 scoped_refptr<Layer> root = Layer::Create();
2678 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2679 make_scoped_refptr(new LayerWithForcedDrawsContent());
2680 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2681 make_scoped_refptr(new LayerWithForcedDrawsContent());
2682 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2683 make_scoped_refptr(new LayerWithForcedDrawsContent());
2684 root->AddChild(child1);
2685 root->AddChild(child2);
2686 root->AddChild(child3);
2687
[email protected]d600df7d2013-08-03 02:34:282688 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2689 host->SetRootLayer(root);
2690
[email protected]fb661802013-03-25 01:59:322691 gfx::Transform identity_matrix;
2692 SetLayerPropertiesForTesting(root.get(),
2693 identity_matrix,
[email protected]fb661802013-03-25 01:59:322694 gfx::PointF(),
2695 gfx::PointF(),
2696 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572697 true,
[email protected]fb661802013-03-25 01:59:322698 false);
2699 SetLayerPropertiesForTesting(child1.get(),
2700 identity_matrix,
[email protected]fb661802013-03-25 01:59:322701 gfx::PointF(),
2702 gfx::PointF(),
2703 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572704 true,
[email protected]fb661802013-03-25 01:59:322705 false);
2706 SetLayerPropertiesForTesting(child2.get(),
2707 identity_matrix,
[email protected]fb661802013-03-25 01:59:322708 gfx::PointF(),
2709 gfx::PointF(75.f, 75.f),
2710 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572711 true,
[email protected]fb661802013-03-25 01:59:322712 false);
2713 SetLayerPropertiesForTesting(child3.get(),
2714 identity_matrix,
[email protected]fb661802013-03-25 01:59:322715 gfx::PointF(),
2716 gfx::PointF(125.f, 125.f),
2717 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572718 true,
[email protected]fb661802013-03-25 01:59:322719 false);
2720
2721 ExecuteCalculateDrawProperties(root.get());
2722
2723 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2724 root->render_surface()->DrawableContentRect());
2725 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2726
2727 // Layers that do not draw content should have empty visible_content_rects.
2728 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2729
2730 // layer visible_content_rects are clipped by their target surface.
2731 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2732 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
2733 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
2734
2735 // layer drawable_content_rects are not clipped.
2736 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2737 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2738 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2739}
2740
[email protected]989386c2013-07-18 21:37:232741TEST_F(LayerTreeHostCommonTest,
2742 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:322743 scoped_refptr<Layer> root = Layer::Create();
2744 scoped_refptr<Layer> child = Layer::Create();
2745 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
2746 make_scoped_refptr(new LayerWithForcedDrawsContent());
2747 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
2748 make_scoped_refptr(new LayerWithForcedDrawsContent());
2749 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
2750 make_scoped_refptr(new LayerWithForcedDrawsContent());
2751 root->AddChild(child);
2752 child->AddChild(grand_child1);
2753 child->AddChild(grand_child2);
2754 child->AddChild(grand_child3);
2755
[email protected]d600df7d2013-08-03 02:34:282756 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2757 host->SetRootLayer(root);
2758
[email protected]fb661802013-03-25 01:59:322759 gfx::Transform identity_matrix;
2760 SetLayerPropertiesForTesting(root.get(),
2761 identity_matrix,
[email protected]fb661802013-03-25 01:59:322762 gfx::PointF(),
2763 gfx::PointF(),
2764 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572765 true,
[email protected]fb661802013-03-25 01:59:322766 false);
2767 SetLayerPropertiesForTesting(child.get(),
2768 identity_matrix,
[email protected]fb661802013-03-25 01:59:322769 gfx::PointF(),
2770 gfx::PointF(),
2771 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572772 true,
[email protected]fb661802013-03-25 01:59:322773 false);
2774 SetLayerPropertiesForTesting(grand_child1.get(),
2775 identity_matrix,
[email protected]fb661802013-03-25 01:59:322776 gfx::PointF(),
2777 gfx::PointF(5.f, 5.f),
2778 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572779 true,
[email protected]fb661802013-03-25 01:59:322780 false);
2781 SetLayerPropertiesForTesting(grand_child2.get(),
2782 identity_matrix,
[email protected]fb661802013-03-25 01:59:322783 gfx::PointF(),
2784 gfx::PointF(75.f, 75.f),
2785 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572786 true,
[email protected]fb661802013-03-25 01:59:322787 false);
2788 SetLayerPropertiesForTesting(grand_child3.get(),
2789 identity_matrix,
[email protected]fb661802013-03-25 01:59:322790 gfx::PointF(),
2791 gfx::PointF(125.f, 125.f),
2792 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572793 true,
[email protected]fb661802013-03-25 01:59:322794 false);
2795
2796 child->SetMasksToBounds(true);
2797 ExecuteCalculateDrawProperties(root.get());
2798
2799 ASSERT_FALSE(child->render_surface());
2800
2801 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2802 root->render_surface()->DrawableContentRect());
2803 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2804
2805 // Layers that do not draw content should have empty visible content rects.
2806 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2807 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
2808
2809 // All grandchild visible content rects should be clipped by child.
2810 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
2811 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
2812 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
2813
2814 // All grandchild DrawableContentRects should also be clipped by child.
2815 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
2816 grand_child1->drawable_content_rect());
2817 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
2818 grand_child2->drawable_content_rect());
2819 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2820}
2821
[email protected]989386c2013-07-18 21:37:232822TEST_F(LayerTreeHostCommonTest,
2823 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322824 scoped_refptr<Layer> root = Layer::Create();
2825 scoped_refptr<Layer> render_surface1 = Layer::Create();
2826 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2827 make_scoped_refptr(new LayerWithForcedDrawsContent());
2828 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2829 make_scoped_refptr(new LayerWithForcedDrawsContent());
2830 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2831 make_scoped_refptr(new LayerWithForcedDrawsContent());
2832 root->AddChild(render_surface1);
2833 render_surface1->AddChild(child1);
2834 render_surface1->AddChild(child2);
2835 render_surface1->AddChild(child3);
2836
[email protected]d600df7d2013-08-03 02:34:282837 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2838 host->SetRootLayer(root);
2839
[email protected]fb661802013-03-25 01:59:322840 gfx::Transform identity_matrix;
2841 SetLayerPropertiesForTesting(root.get(),
2842 identity_matrix,
[email protected]fb661802013-03-25 01:59:322843 gfx::PointF(),
2844 gfx::PointF(),
2845 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572846 true,
[email protected]fb661802013-03-25 01:59:322847 false);
2848 SetLayerPropertiesForTesting(render_surface1.get(),
2849 identity_matrix,
[email protected]fb661802013-03-25 01:59:322850 gfx::PointF(),
2851 gfx::PointF(),
2852 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572853 true,
[email protected]fb661802013-03-25 01:59:322854 false);
2855 SetLayerPropertiesForTesting(child1.get(),
2856 identity_matrix,
[email protected]fb661802013-03-25 01:59:322857 gfx::PointF(),
2858 gfx::PointF(5.f, 5.f),
2859 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572860 true,
[email protected]fb661802013-03-25 01:59:322861 false);
2862 SetLayerPropertiesForTesting(child2.get(),
2863 identity_matrix,
[email protected]fb661802013-03-25 01:59:322864 gfx::PointF(),
2865 gfx::PointF(75.f, 75.f),
2866 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572867 true,
[email protected]fb661802013-03-25 01:59:322868 false);
2869 SetLayerPropertiesForTesting(child3.get(),
2870 identity_matrix,
[email protected]fb661802013-03-25 01:59:322871 gfx::PointF(),
2872 gfx::PointF(125.f, 125.f),
2873 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572874 true,
[email protected]fb661802013-03-25 01:59:322875 false);
2876
2877 render_surface1->SetForceRenderSurface(true);
2878 ExecuteCalculateDrawProperties(root.get());
2879
2880 ASSERT_TRUE(render_surface1->render_surface());
2881
2882 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2883 root->render_surface()->DrawableContentRect());
2884 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2885
2886 // Layers that do not draw content should have empty visible content rects.
2887 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2888 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2889 render_surface1->visible_content_rect());
2890
2891 // An unclipped surface grows its DrawableContentRect to include all drawable
2892 // regions of the subtree.
2893 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
2894 render_surface1->render_surface()->DrawableContentRect());
2895
2896 // All layers that draw content into the unclipped surface are also unclipped.
2897 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2898 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
2899 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
2900
2901 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2902 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2903 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2904}
2905
[email protected]989386c2013-07-18 21:37:232906TEST_F(LayerTreeHostCommonTest,
2907 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:472908 scoped_refptr<Layer> root = Layer::Create();
2909 scoped_refptr<LayerWithForcedDrawsContent> child =
2910 make_scoped_refptr(new LayerWithForcedDrawsContent());
2911 root->AddChild(child);
2912
[email protected]d600df7d2013-08-03 02:34:282913 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2914 host->SetRootLayer(root);
2915
[email protected]630ddad2013-08-16 03:01:322916 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:472917 gfx::Transform identity_matrix;
2918 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:322919 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:472920
2921 SetLayerPropertiesForTesting(root.get(),
2922 identity_matrix,
[email protected]451107a32013-04-10 05:12:472923 gfx::PointF(),
2924 gfx::PointF(),
2925 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572926 true,
[email protected]451107a32013-04-10 05:12:472927 false);
2928 SetLayerPropertiesForTesting(child.get(),
2929 uninvertible_matrix,
[email protected]451107a32013-04-10 05:12:472930 gfx::PointF(),
2931 gfx::PointF(5.f, 5.f),
2932 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572933 true,
[email protected]451107a32013-04-10 05:12:472934 false);
2935
2936 ExecuteCalculateDrawProperties(root.get());
2937
2938 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2939 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322940
[email protected]08bdf1b2014-04-16 23:23:292941 // Case 2: a matrix with flattened z, uninvertible and not visible according
2942 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:322943 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:262944 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322945 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2946
2947 SetLayerPropertiesForTesting(child.get(),
2948 uninvertible_matrix,
[email protected]630ddad2013-08-16 03:01:322949 gfx::PointF(),
2950 gfx::PointF(5.f, 5.f),
2951 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572952 true,
[email protected]630ddad2013-08-16 03:01:322953 false);
2954
2955 ExecuteCalculateDrawProperties(root.get());
2956
[email protected]08bdf1b2014-04-16 23:23:292957 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2958 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322959
[email protected]08bdf1b2014-04-16 23:23:292960 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:322961 uninvertible_matrix.MakeIdentity();
2962 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:262963 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322964 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2965
2966 SetLayerPropertiesForTesting(child.get(),
2967 uninvertible_matrix,
[email protected]630ddad2013-08-16 03:01:322968 gfx::PointF(),
2969 gfx::PointF(5.f, 5.f),
2970 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572971 true,
[email protected]630ddad2013-08-16 03:01:322972 false);
2973
2974 ExecuteCalculateDrawProperties(root.get());
2975
2976 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:292977 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:472978}
2979
[email protected]989386c2013-07-18 21:37:232980TEST_F(LayerTreeHostCommonTest,
[email protected]e43c68b2014-05-01 05:10:362981 SingularTransformDoesNotPreventClearingDrawProperties) {
2982 scoped_refptr<Layer> root = Layer::Create();
2983 scoped_refptr<LayerWithForcedDrawsContent> child =
2984 make_scoped_refptr(new LayerWithForcedDrawsContent());
2985 root->AddChild(child);
2986
2987 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2988 host->SetRootLayer(root);
2989
2990 gfx::Transform identity_matrix;
2991 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2992 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2993
2994 SetLayerPropertiesForTesting(root.get(),
2995 uninvertible_matrix,
2996 gfx::PointF(),
2997 gfx::PointF(),
2998 gfx::Size(100, 100),
2999 true,
3000 false);
3001 SetLayerPropertiesForTesting(child.get(),
3002 identity_matrix,
3003 gfx::PointF(),
3004 gfx::PointF(5.f, 5.f),
3005 gfx::Size(50, 50),
3006 true,
3007 false);
3008
3009 child->draw_properties().sorted_for_recursion = true;
3010
3011 TransformOperations start_transform_operations;
3012 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
3013
3014 TransformOperations end_transform_operations;
3015 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
3016
3017 AddAnimatedTransformToLayer(
3018 root.get(), 10.0, start_transform_operations, end_transform_operations);
3019
3020 EXPECT_TRUE(root->TransformIsAnimating());
3021
3022 ExecuteCalculateDrawProperties(root.get());
3023
3024 EXPECT_FALSE(child->draw_properties().sorted_for_recursion);
3025}
3026
3027TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233028 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:323029 scoped_refptr<Layer> root = Layer::Create();
3030 scoped_refptr<Layer> render_surface1 = Layer::Create();
3031 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3032 make_scoped_refptr(new LayerWithForcedDrawsContent());
3033 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3034 make_scoped_refptr(new LayerWithForcedDrawsContent());
3035 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3036 make_scoped_refptr(new LayerWithForcedDrawsContent());
3037 root->AddChild(render_surface1);
3038 render_surface1->AddChild(child1);
3039 render_surface1->AddChild(child2);
3040 render_surface1->AddChild(child3);
3041
[email protected]d600df7d2013-08-03 02:34:283042 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3043 host->SetRootLayer(root);
3044
[email protected]fb661802013-03-25 01:59:323045 gfx::Transform identity_matrix;
3046 SetLayerPropertiesForTesting(root.get(),
3047 identity_matrix,
[email protected]fb661802013-03-25 01:59:323048 gfx::PointF(),
3049 gfx::PointF(),
3050 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573051 true,
[email protected]fb661802013-03-25 01:59:323052 false);
3053 SetLayerPropertiesForTesting(render_surface1.get(),
3054 identity_matrix,
[email protected]fb661802013-03-25 01:59:323055 gfx::PointF(),
3056 gfx::PointF(),
3057 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573058 true,
[email protected]fb661802013-03-25 01:59:323059 false);
3060 SetLayerPropertiesForTesting(child1.get(),
3061 identity_matrix,
[email protected]fb661802013-03-25 01:59:323062 gfx::PointF(),
3063 gfx::PointF(5.f, 5.f),
3064 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573065 true,
[email protected]fb661802013-03-25 01:59:323066 false);
3067 SetLayerPropertiesForTesting(child2.get(),
3068 identity_matrix,
[email protected]fb661802013-03-25 01:59:323069 gfx::PointF(),
3070 gfx::PointF(75.f, 75.f),
3071 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573072 true,
[email protected]fb661802013-03-25 01:59:323073 false);
3074 SetLayerPropertiesForTesting(child3.get(),
3075 identity_matrix,
[email protected]fb661802013-03-25 01:59:323076 gfx::PointF(),
3077 gfx::PointF(125.f, 125.f),
3078 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573079 true,
[email protected]fb661802013-03-25 01:59:323080 false);
3081
3082 root->SetMasksToBounds(true);
3083 render_surface1->SetForceRenderSurface(true);
3084 ExecuteCalculateDrawProperties(root.get());
3085
3086 ASSERT_TRUE(render_surface1->render_surface());
3087
3088 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3089 root->render_surface()->DrawableContentRect());
3090 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3091
3092 // Layers that do not draw content should have empty visible content rects.
3093 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3094 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3095 render_surface1->visible_content_rect());
3096
3097 // A clipped surface grows its DrawableContentRect to include all drawable
3098 // regions of the subtree, but also gets clamped by the ancestor's clip.
3099 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3100 render_surface1->render_surface()->DrawableContentRect());
3101
3102 // All layers that draw content into the surface have their visible content
3103 // rect clipped by the surface clip rect.
3104 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3105 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
3106 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3107
3108 // But the DrawableContentRects are unclipped.
3109 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3110 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3111 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3112}
3113
[email protected]989386c2013-07-18 21:37:233114TEST_F(LayerTreeHostCommonTest,
3115 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323116 // Check that clipping does not propagate down surfaces.
3117 scoped_refptr<Layer> root = Layer::Create();
3118 scoped_refptr<Layer> render_surface1 = Layer::Create();
3119 scoped_refptr<Layer> render_surface2 = Layer::Create();
3120 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3121 make_scoped_refptr(new LayerWithForcedDrawsContent());
3122 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3123 make_scoped_refptr(new LayerWithForcedDrawsContent());
3124 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3125 make_scoped_refptr(new LayerWithForcedDrawsContent());
3126 root->AddChild(render_surface1);
3127 render_surface1->AddChild(render_surface2);
3128 render_surface2->AddChild(child1);
3129 render_surface2->AddChild(child2);
3130 render_surface2->AddChild(child3);
3131
[email protected]d600df7d2013-08-03 02:34:283132 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3133 host->SetRootLayer(root);
3134
[email protected]fb661802013-03-25 01:59:323135 gfx::Transform identity_matrix;
3136 SetLayerPropertiesForTesting(root.get(),
3137 identity_matrix,
[email protected]fb661802013-03-25 01:59:323138 gfx::PointF(),
3139 gfx::PointF(),
3140 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573141 true,
[email protected]fb661802013-03-25 01:59:323142 false);
3143 SetLayerPropertiesForTesting(render_surface1.get(),
3144 identity_matrix,
[email protected]fb661802013-03-25 01:59:323145 gfx::PointF(),
3146 gfx::PointF(),
3147 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573148 true,
[email protected]fb661802013-03-25 01:59:323149 false);
3150 SetLayerPropertiesForTesting(render_surface2.get(),
3151 identity_matrix,
[email protected]fb661802013-03-25 01:59:323152 gfx::PointF(),
3153 gfx::PointF(),
3154 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573155 true,
[email protected]fb661802013-03-25 01:59:323156 false);
3157 SetLayerPropertiesForTesting(child1.get(),
3158 identity_matrix,
[email protected]fb661802013-03-25 01:59:323159 gfx::PointF(),
3160 gfx::PointF(5.f, 5.f),
3161 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573162 true,
[email protected]fb661802013-03-25 01:59:323163 false);
3164 SetLayerPropertiesForTesting(child2.get(),
3165 identity_matrix,
[email protected]fb661802013-03-25 01:59:323166 gfx::PointF(),
3167 gfx::PointF(75.f, 75.f),
3168 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573169 true,
[email protected]fb661802013-03-25 01:59:323170 false);
3171 SetLayerPropertiesForTesting(child3.get(),
3172 identity_matrix,
[email protected]fb661802013-03-25 01:59:323173 gfx::PointF(),
3174 gfx::PointF(125.f, 125.f),
3175 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573176 true,
[email protected]fb661802013-03-25 01:59:323177 false);
3178
3179 root->SetMasksToBounds(true);
3180 render_surface1->SetForceRenderSurface(true);
3181 render_surface2->SetForceRenderSurface(true);
3182 ExecuteCalculateDrawProperties(root.get());
3183
3184 ASSERT_TRUE(render_surface1->render_surface());
3185 ASSERT_TRUE(render_surface2->render_surface());
3186
3187 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3188 root->render_surface()->DrawableContentRect());
3189 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3190
3191 // Layers that do not draw content should have empty visible content rects.
3192 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3193 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3194 render_surface1->visible_content_rect());
3195 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3196 render_surface2->visible_content_rect());
3197
3198 // A clipped surface grows its DrawableContentRect to include all drawable
3199 // regions of the subtree, but also gets clamped by the ancestor's clip.
3200 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3201 render_surface1->render_surface()->DrawableContentRect());
3202
3203 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3204 // is only implicitly clipped by render_surface1's content rect. So,
3205 // render_surface2 grows to enclose all drawable content of its subtree.
3206 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3207 render_surface2->render_surface()->DrawableContentRect());
3208
3209 // All layers that draw content into render_surface2 think they are unclipped.
3210 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3211 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3212 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
3213
3214 // DrawableContentRects are also unclipped.
3215 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3216 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3217 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3218}
3219
[email protected]989386c2013-07-18 21:37:233220TEST_F(LayerTreeHostCommonTest,
3221 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323222 // Layers that have non-axis aligned bounds (due to transforms) have an
3223 // expanded, axis-aligned DrawableContentRect and visible content rect.
3224
3225 scoped_refptr<Layer> root = Layer::Create();
3226 scoped_refptr<Layer> render_surface1 = Layer::Create();
3227 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3228 make_scoped_refptr(new LayerWithForcedDrawsContent());
3229 root->AddChild(render_surface1);
3230 render_surface1->AddChild(child1);
3231
[email protected]d600df7d2013-08-03 02:34:283232 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3233 host->SetRootLayer(root);
3234
[email protected]fb661802013-03-25 01:59:323235 gfx::Transform identity_matrix;
3236 gfx::Transform child_rotation;
3237 child_rotation.Rotate(45.0);
3238 SetLayerPropertiesForTesting(root.get(),
3239 identity_matrix,
[email protected]fb661802013-03-25 01:59:323240 gfx::PointF(),
3241 gfx::PointF(),
3242 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573243 true,
[email protected]fb661802013-03-25 01:59:323244 false);
3245 SetLayerPropertiesForTesting(render_surface1.get(),
3246 identity_matrix,
[email protected]fb661802013-03-25 01:59:323247 gfx::PointF(),
3248 gfx::PointF(),
3249 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573250 true,
[email protected]fb661802013-03-25 01:59:323251 false);
3252 SetLayerPropertiesForTesting(child1.get(),
3253 child_rotation,
[email protected]fb661802013-03-25 01:59:323254 gfx::PointF(0.5f, 0.5f),
3255 gfx::PointF(25.f, 25.f),
3256 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573257 true,
[email protected]fb661802013-03-25 01:59:323258 false);
3259
3260 render_surface1->SetForceRenderSurface(true);
3261 ExecuteCalculateDrawProperties(root.get());
3262
3263 ASSERT_TRUE(render_surface1->render_surface());
3264
3265 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3266 root->render_surface()->DrawableContentRect());
3267 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3268
3269 // Layers that do not draw content should have empty visible content rects.
3270 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3271 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3272 render_surface1->visible_content_rect());
3273
3274 // The unclipped surface grows its DrawableContentRect to include all drawable
3275 // regions of the subtree.
3276 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3277 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263278 gfx::Rect(50 - diagonal_radius,
3279 50 - diagonal_radius,
3280 diagonal_radius * 2,
3281 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323282 EXPECT_RECT_EQ(expected_surface_drawable_content,
3283 render_surface1->render_surface()->DrawableContentRect());
3284
3285 // All layers that draw content into the unclipped surface are also unclipped.
3286 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3287 EXPECT_RECT_EQ(expected_surface_drawable_content,
3288 child1->drawable_content_rect());
3289}
3290
[email protected]989386c2013-07-18 21:37:233291TEST_F(LayerTreeHostCommonTest,
3292 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323293 // Layers that have non-axis aligned bounds (due to transforms) have an
3294 // expanded, axis-aligned DrawableContentRect and visible content rect.
3295
3296 scoped_refptr<Layer> root = Layer::Create();
3297 scoped_refptr<Layer> render_surface1 = Layer::Create();
3298 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3299 make_scoped_refptr(new LayerWithForcedDrawsContent());
3300 root->AddChild(render_surface1);
3301 render_surface1->AddChild(child1);
3302
[email protected]d600df7d2013-08-03 02:34:283303 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3304 host->SetRootLayer(root);
3305
[email protected]fb661802013-03-25 01:59:323306 gfx::Transform identity_matrix;
3307 gfx::Transform child_rotation;
3308 child_rotation.Rotate(45.0);
3309 SetLayerPropertiesForTesting(root.get(),
3310 identity_matrix,
[email protected]fb661802013-03-25 01:59:323311 gfx::PointF(),
3312 gfx::PointF(),
3313 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573314 true,
[email protected]fb661802013-03-25 01:59:323315 false);
3316 SetLayerPropertiesForTesting(render_surface1.get(),
3317 identity_matrix,
[email protected]fb661802013-03-25 01:59:323318 gfx::PointF(),
3319 gfx::PointF(),
3320 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573321 true,
[email protected]fb661802013-03-25 01:59:323322 false);
3323 SetLayerPropertiesForTesting(child1.get(),
3324 child_rotation,
[email protected]fb661802013-03-25 01:59:323325 gfx::PointF(0.5f, 0.5f),
3326 gfx::PointF(25.f, 25.f),
3327 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573328 true,
[email protected]fb661802013-03-25 01:59:323329 false);
3330
3331 root->SetMasksToBounds(true);
3332 render_surface1->SetForceRenderSurface(true);
3333 ExecuteCalculateDrawProperties(root.get());
3334
3335 ASSERT_TRUE(render_surface1->render_surface());
3336
3337 // The clipped surface clamps the DrawableContentRect that encloses the
3338 // rotated layer.
3339 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263340 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3341 50 - diagonal_radius,
3342 diagonal_radius * 2,
3343 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323344 gfx::Rect expected_surface_drawable_content =
3345 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
3346 EXPECT_RECT_EQ(expected_surface_drawable_content,
3347 render_surface1->render_surface()->DrawableContentRect());
3348
3349 // On the clipped surface, only a quarter of the child1 is visible, but when
3350 // rotating it back to child1's content space, the actual enclosing rect ends
3351 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263352 //
3353 // Given the floating point math, this number is a little bit fuzzy.
[email protected]fb661802013-03-25 01:59:323354 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
3355
3356 // The child's DrawableContentRect is unclipped.
3357 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3358}
3359
[email protected]989386c2013-07-18 21:37:233360TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323361 MockContentLayerClient client;
3362
3363 scoped_refptr<Layer> root = Layer::Create();
3364 scoped_refptr<ContentLayer> render_surface1 =
3365 CreateDrawableContentLayer(&client);
3366 scoped_refptr<ContentLayer> render_surface2 =
3367 CreateDrawableContentLayer(&client);
3368 scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client);
3369 scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client);
3370 scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client);
3371 root->AddChild(render_surface1);
3372 render_surface1->AddChild(render_surface2);
3373 render_surface2->AddChild(child1);
3374 render_surface2->AddChild(child2);
3375 render_surface2->AddChild(child3);
3376
[email protected]d600df7d2013-08-03 02:34:283377 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3378 host->SetRootLayer(root);
3379
[email protected]fb661802013-03-25 01:59:323380 gfx::Transform identity_matrix;
3381 SetLayerPropertiesForTesting(root.get(),
3382 identity_matrix,
[email protected]fb661802013-03-25 01:59:323383 gfx::PointF(),
3384 gfx::PointF(),
3385 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573386 true,
[email protected]fb661802013-03-25 01:59:323387 false);
3388 SetLayerPropertiesForTesting(render_surface1.get(),
3389 identity_matrix,
[email protected]fb661802013-03-25 01:59:323390 gfx::PointF(),
3391 gfx::PointF(5.f, 5.f),
3392 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573393 true,
[email protected]fb661802013-03-25 01:59:323394 false);
3395 SetLayerPropertiesForTesting(render_surface2.get(),
3396 identity_matrix,
[email protected]fb661802013-03-25 01:59:323397 gfx::PointF(),
3398 gfx::PointF(5.f, 5.f),
3399 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573400 true,
[email protected]fb661802013-03-25 01:59:323401 false);
3402 SetLayerPropertiesForTesting(child1.get(),
3403 identity_matrix,
[email protected]fb661802013-03-25 01:59:323404 gfx::PointF(),
3405 gfx::PointF(5.f, 5.f),
3406 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573407 true,
[email protected]fb661802013-03-25 01:59:323408 false);
3409 SetLayerPropertiesForTesting(child2.get(),
3410 identity_matrix,
[email protected]fb661802013-03-25 01:59:323411 gfx::PointF(),
3412 gfx::PointF(75.f, 75.f),
3413 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573414 true,
[email protected]fb661802013-03-25 01:59:323415 false);
3416 SetLayerPropertiesForTesting(child3.get(),
3417 identity_matrix,
[email protected]fb661802013-03-25 01:59:323418 gfx::PointF(),
3419 gfx::PointF(125.f, 125.f),
3420 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573421 true,
[email protected]fb661802013-03-25 01:59:323422 false);
3423
3424 float device_scale_factor = 2.f;
3425
3426 root->SetMasksToBounds(true);
3427 render_surface1->SetForceRenderSurface(true);
3428 render_surface2->SetForceRenderSurface(true);
3429 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3430
3431 ASSERT_TRUE(render_surface1->render_surface());
3432 ASSERT_TRUE(render_surface2->render_surface());
3433
3434 // drawable_content_rects for all layers and surfaces are scaled by
3435 // device_scale_factor.
3436 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3437 root->render_surface()->DrawableContentRect());
3438 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3439 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3440 render_surface1->render_surface()->DrawableContentRect());
3441
3442 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3443 // is only implicitly clipped by render_surface1.
3444 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3445 render_surface2->render_surface()->DrawableContentRect());
3446
3447 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3448 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3449 child2->drawable_content_rect());
3450 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3451 child3->drawable_content_rect());
3452
3453 // The root layer does not actually draw content of its own.
3454 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3455
3456 // All layer visible content rects are expressed in content space of each
3457 // layer, so they are also scaled by the device_scale_factor.
3458 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8),
3459 render_surface1->visible_content_rect());
3460 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26),
3461 render_surface2->visible_content_rect());
3462 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect());
3463 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect());
3464 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect());
3465}
3466
[email protected]989386c2013-07-18 21:37:233467TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323468 // Verify the behavior of back-face culling when there are no preserve-3d
3469 // layers. Note that 3d transforms still apply in this case, but they are
3470 // "flattened" to each parent layer according to current W3C spec.
3471
3472 const gfx::Transform identity_matrix;
3473 scoped_refptr<Layer> parent = Layer::Create();
3474 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3475 make_scoped_refptr(new LayerWithForcedDrawsContent());
3476 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3477 make_scoped_refptr(new LayerWithForcedDrawsContent());
3478 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3479 make_scoped_refptr(new LayerWithForcedDrawsContent());
3480 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3481 make_scoped_refptr(new LayerWithForcedDrawsContent());
3482 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233483 front_facing_child_of_front_facing_surface =
3484 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323485 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233486 back_facing_child_of_front_facing_surface =
3487 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323488 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233489 front_facing_child_of_back_facing_surface =
3490 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323491 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233492 back_facing_child_of_back_facing_surface =
3493 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323494
3495 parent->AddChild(front_facing_child);
3496 parent->AddChild(back_facing_child);
3497 parent->AddChild(front_facing_surface);
3498 parent->AddChild(back_facing_surface);
3499 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3500 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3501 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3502 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3503
[email protected]d600df7d2013-08-03 02:34:283504 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3505 host->SetRootLayer(parent);
3506
[email protected]fb661802013-03-25 01:59:323507 // Nothing is double-sided
3508 front_facing_child->SetDoubleSided(false);
3509 back_facing_child->SetDoubleSided(false);
3510 front_facing_surface->SetDoubleSided(false);
3511 back_facing_surface->SetDoubleSided(false);
3512 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3513 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3514 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3515 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3516
3517 gfx::Transform backface_matrix;
3518 backface_matrix.Translate(50.0, 50.0);
3519 backface_matrix.RotateAboutYAxis(180.0);
3520 backface_matrix.Translate(-50.0, -50.0);
3521
3522 // Having a descendant and opacity will force these to have render surfaces.
3523 front_facing_surface->SetOpacity(0.5f);
3524 back_facing_surface->SetOpacity(0.5f);
3525
3526 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3527 // these layers should blindly use their own local transforms to determine
3528 // back-face culling.
3529 SetLayerPropertiesForTesting(parent.get(),
3530 identity_matrix,
[email protected]fb661802013-03-25 01:59:323531 gfx::PointF(),
3532 gfx::PointF(),
3533 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573534 true,
[email protected]fb661802013-03-25 01:59:323535 false);
3536 SetLayerPropertiesForTesting(front_facing_child.get(),
3537 identity_matrix,
[email protected]fb661802013-03-25 01:59:323538 gfx::PointF(),
3539 gfx::PointF(),
3540 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573541 true,
[email protected]fb661802013-03-25 01:59:323542 false);
3543 SetLayerPropertiesForTesting(back_facing_child.get(),
3544 backface_matrix,
[email protected]fb661802013-03-25 01:59:323545 gfx::PointF(),
3546 gfx::PointF(),
3547 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573548 true,
[email protected]fb661802013-03-25 01:59:323549 false);
3550 SetLayerPropertiesForTesting(front_facing_surface.get(),
3551 identity_matrix,
[email protected]fb661802013-03-25 01:59:323552 gfx::PointF(),
3553 gfx::PointF(),
3554 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573555 true,
[email protected]fb661802013-03-25 01:59:323556 false);
3557 SetLayerPropertiesForTesting(back_facing_surface.get(),
3558 backface_matrix,
[email protected]fb661802013-03-25 01:59:323559 gfx::PointF(),
3560 gfx::PointF(),
3561 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573562 true,
[email protected]fb661802013-03-25 01:59:323563 false);
3564 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3565 identity_matrix,
[email protected]fb661802013-03-25 01:59:323566 gfx::PointF(),
3567 gfx::PointF(),
3568 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573569 true,
[email protected]fb661802013-03-25 01:59:323570 false);
3571 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3572 backface_matrix,
[email protected]fb661802013-03-25 01:59:323573 gfx::PointF(),
3574 gfx::PointF(),
3575 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573576 true,
[email protected]fb661802013-03-25 01:59:323577 false);
3578 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3579 identity_matrix,
[email protected]fb661802013-03-25 01:59:323580 gfx::PointF(),
3581 gfx::PointF(),
3582 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573583 true,
[email protected]fb661802013-03-25 01:59:323584 false);
3585 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3586 backface_matrix,
[email protected]fb661802013-03-25 01:59:323587 gfx::PointF(),
3588 gfx::PointF(),
3589 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573590 true,
[email protected]fb661802013-03-25 01:59:323591 false);
3592
[email protected]989386c2013-07-18 21:37:233593 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533594 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3595 parent.get(), parent->bounds(), &render_surface_layer_list);
3596 inputs.can_adjust_raster_scales = true;
3597 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323598
3599 // Verify which render surfaces were created.
3600 EXPECT_FALSE(front_facing_child->render_surface());
3601 EXPECT_FALSE(back_facing_child->render_surface());
3602 EXPECT_TRUE(front_facing_surface->render_surface());
3603 EXPECT_TRUE(back_facing_surface->render_surface());
3604 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3605 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3606 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3607 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3608
3609 // Verify the render_surface_layer_list.
3610 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233611 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3612 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323613 // Even though the back facing surface LAYER gets culled, the other
3614 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233615 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323616
3617 // Verify root surface's layer list.
3618 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233619 3u,
3620 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3621 EXPECT_EQ(front_facing_child->id(),
3622 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573623 ->render_surface()
3624 ->layer_list()
3625 .at(0)
3626 ->id());
[email protected]989386c2013-07-18 21:37:233627 EXPECT_EQ(front_facing_surface->id(),
3628 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573629 ->render_surface()
3630 ->layer_list()
3631 .at(1)
3632 ->id());
[email protected]989386c2013-07-18 21:37:233633 EXPECT_EQ(back_facing_surface->id(),
3634 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573635 ->render_surface()
3636 ->layer_list()
3637 .at(2)
3638 ->id());
[email protected]fb661802013-03-25 01:59:323639
3640 // Verify front_facing_surface's layer list.
3641 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233642 2u,
3643 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3644 EXPECT_EQ(front_facing_surface->id(),
3645 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573646 ->render_surface()
3647 ->layer_list()
3648 .at(0)
3649 ->id());
[email protected]989386c2013-07-18 21:37:233650 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3651 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573652 ->render_surface()
3653 ->layer_list()
3654 .at(1)
3655 ->id());
[email protected]fb661802013-03-25 01:59:323656
3657 // Verify back_facing_surface's layer list; its own layer should be culled
3658 // from the surface list.
3659 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233660 1u,
3661 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3662 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3663 render_surface_layer_list.at(2)
[email protected]56fffdd2014-02-11 19:50:573664 ->render_surface()
3665 ->layer_list()
3666 .at(0)
3667 ->id());
[email protected]fb661802013-03-25 01:59:323668}
3669
[email protected]989386c2013-07-18 21:37:233670TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323671 // Verify the behavior of back-face culling when preserves-3d transform style
3672 // is used.
3673
3674 const gfx::Transform identity_matrix;
3675 scoped_refptr<Layer> parent = Layer::Create();
3676 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3677 make_scoped_refptr(new LayerWithForcedDrawsContent());
3678 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3679 make_scoped_refptr(new LayerWithForcedDrawsContent());
3680 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3681 make_scoped_refptr(new LayerWithForcedDrawsContent());
3682 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3683 make_scoped_refptr(new LayerWithForcedDrawsContent());
3684 scoped_refptr<LayerWithForcedDrawsContent>
3685 front_facing_child_of_front_facing_surface =
3686 make_scoped_refptr(new LayerWithForcedDrawsContent());
3687 scoped_refptr<LayerWithForcedDrawsContent>
3688 back_facing_child_of_front_facing_surface =
3689 make_scoped_refptr(new LayerWithForcedDrawsContent());
3690 scoped_refptr<LayerWithForcedDrawsContent>
3691 front_facing_child_of_back_facing_surface =
3692 make_scoped_refptr(new LayerWithForcedDrawsContent());
3693 scoped_refptr<LayerWithForcedDrawsContent>
3694 back_facing_child_of_back_facing_surface =
3695 make_scoped_refptr(new LayerWithForcedDrawsContent());
3696 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3697 make_scoped_refptr(new LayerWithForcedDrawsContent());
3698 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3699 make_scoped_refptr(new LayerWithForcedDrawsContent());
3700
3701 parent->AddChild(front_facing_child);
3702 parent->AddChild(back_facing_child);
3703 parent->AddChild(front_facing_surface);
3704 parent->AddChild(back_facing_surface);
3705 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3706 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3707 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3708 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3709
[email protected]d600df7d2013-08-03 02:34:283710 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3711 host->SetRootLayer(parent);
3712
[email protected]fb661802013-03-25 01:59:323713 // Nothing is double-sided
3714 front_facing_child->SetDoubleSided(false);
3715 back_facing_child->SetDoubleSided(false);
3716 front_facing_surface->SetDoubleSided(false);
3717 back_facing_surface->SetDoubleSided(false);
3718 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3719 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3720 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3721 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3722
3723 gfx::Transform backface_matrix;
3724 backface_matrix.Translate(50.0, 50.0);
3725 backface_matrix.RotateAboutYAxis(180.0);
3726 backface_matrix.Translate(-50.0, -50.0);
3727
3728 // Opacity will not force creation of render surfaces in this case because of
3729 // the preserve-3d transform style. Instead, an example of when a surface
3730 // would be created with preserve-3d is when there is a replica layer.
3731 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3732 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3733
3734 // Each surface creates its own new 3d rendering context (as defined by W3C
3735 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3736 // rendering context should use the transform with respect to that context.
3737 // This 3d rendering context occurs when (a) parent's transform style is flat
3738 // and (b) the layer's transform style is preserve-3d.
3739 SetLayerPropertiesForTesting(parent.get(),
3740 identity_matrix,
[email protected]fb661802013-03-25 01:59:323741 gfx::PointF(),
3742 gfx::PointF(),
3743 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573744 true,
[email protected]fb661802013-03-25 01:59:323745 false); // parent transform style is flat.
3746 SetLayerPropertiesForTesting(front_facing_child.get(),
3747 identity_matrix,
[email protected]fb661802013-03-25 01:59:323748 gfx::PointF(),
3749 gfx::PointF(),
3750 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573751 true,
[email protected]fb661802013-03-25 01:59:323752 false);
3753 SetLayerPropertiesForTesting(back_facing_child.get(),
3754 backface_matrix,
[email protected]fb661802013-03-25 01:59:323755 gfx::PointF(),
3756 gfx::PointF(),
3757 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573758 true,
[email protected]fb661802013-03-25 01:59:323759 false);
[email protected]56fffdd2014-02-11 19:50:573760 // surface transform style is preserve-3d.
3761 SetLayerPropertiesForTesting(front_facing_surface.get(),
3762 identity_matrix,
[email protected]56fffdd2014-02-11 19:50:573763 gfx::PointF(),
3764 gfx::PointF(),
3765 gfx::Size(100, 100),
3766 false,
3767 true);
3768 // surface transform style is preserve-3d.
3769 SetLayerPropertiesForTesting(back_facing_surface.get(),
3770 backface_matrix,
[email protected]56fffdd2014-02-11 19:50:573771 gfx::PointF(),
3772 gfx::PointF(),
3773 gfx::Size(100, 100),
3774 false,
3775 true);
[email protected]fb661802013-03-25 01:59:323776 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3777 identity_matrix,
[email protected]fb661802013-03-25 01:59:323778 gfx::PointF(),
3779 gfx::PointF(),
3780 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573781 true,
3782 true);
[email protected]fb661802013-03-25 01:59:323783 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3784 backface_matrix,
[email protected]fb661802013-03-25 01:59:323785 gfx::PointF(),
3786 gfx::PointF(),
3787 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573788 true,
3789 true);
[email protected]fb661802013-03-25 01:59:323790 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3791 identity_matrix,
[email protected]fb661802013-03-25 01:59:323792 gfx::PointF(),
3793 gfx::PointF(),
3794 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573795 true,
3796 true);
[email protected]fb661802013-03-25 01:59:323797 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3798 backface_matrix,
[email protected]fb661802013-03-25 01:59:323799 gfx::PointF(),
3800 gfx::PointF(),
3801 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573802 true,
3803 true);
[email protected]fb661802013-03-25 01:59:323804
[email protected]989386c2013-07-18 21:37:233805 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533806 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3807 parent.get(), parent->bounds(), &render_surface_layer_list);
3808 inputs.can_adjust_raster_scales = true;
3809 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323810
3811 // Verify which render surfaces were created.
3812 EXPECT_FALSE(front_facing_child->render_surface());
3813 EXPECT_FALSE(back_facing_child->render_surface());
3814 EXPECT_TRUE(front_facing_surface->render_surface());
3815 EXPECT_FALSE(back_facing_surface->render_surface());
3816 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3817 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3818 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3819 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3820
3821 // Verify the render_surface_layer_list. The back-facing surface should be
3822 // culled.
3823 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233824 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3825 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323826
3827 // Verify root surface's layer list.
3828 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233829 2u,
3830 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3831 EXPECT_EQ(front_facing_child->id(),
3832 render_surface_layer_list.at(0)
3833 ->render_surface()->layer_list().at(0)->id());
3834 EXPECT_EQ(front_facing_surface->id(),
3835 render_surface_layer_list.at(0)
3836 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323837
3838 // Verify front_facing_surface's layer list.
3839 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233840 2u,
3841 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3842 EXPECT_EQ(front_facing_surface->id(),
3843 render_surface_layer_list.at(1)
3844 ->render_surface()->layer_list().at(0)->id());
3845 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3846 render_surface_layer_list.at(1)
3847 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323848}
3849
[email protected]989386c2013-07-18 21:37:233850TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323851 // Verify that layers are appropriately culled when their back face is showing
3852 // and they are not double sided, while animations are going on.
3853 //
3854 // Layers that are animating do not get culled on the main thread, as their
3855 // transforms should be treated as "unknown" so we can not be sure that their
3856 // back face is really showing.
3857 const gfx::Transform identity_matrix;
3858 scoped_refptr<Layer> parent = Layer::Create();
3859 scoped_refptr<LayerWithForcedDrawsContent> child =
3860 make_scoped_refptr(new LayerWithForcedDrawsContent());
3861 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3862 make_scoped_refptr(new LayerWithForcedDrawsContent());
3863 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3864 make_scoped_refptr(new LayerWithForcedDrawsContent());
3865 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3866 make_scoped_refptr(new LayerWithForcedDrawsContent());
3867 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3868 make_scoped_refptr(new LayerWithForcedDrawsContent());
3869
3870 parent->AddChild(child);
3871 parent->AddChild(animating_surface);
3872 animating_surface->AddChild(child_of_animating_surface);
3873 parent->AddChild(animating_child);
3874 parent->AddChild(child2);
3875
[email protected]d600df7d2013-08-03 02:34:283876 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3877 host->SetRootLayer(parent);
3878
[email protected]fb661802013-03-25 01:59:323879 // Nothing is double-sided
3880 child->SetDoubleSided(false);
3881 child2->SetDoubleSided(false);
3882 animating_surface->SetDoubleSided(false);
3883 child_of_animating_surface->SetDoubleSided(false);
3884 animating_child->SetDoubleSided(false);
3885
3886 gfx::Transform backface_matrix;
3887 backface_matrix.Translate(50.0, 50.0);
3888 backface_matrix.RotateAboutYAxis(180.0);
3889 backface_matrix.Translate(-50.0, -50.0);
3890
3891 // Make our render surface.
3892 animating_surface->SetForceRenderSurface(true);
3893
3894 // Animate the transform on the render surface.
3895 AddAnimatedTransformToController(
3896 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3897 // This is just an animating layer, not a surface.
3898 AddAnimatedTransformToController(
3899 animating_child->layer_animation_controller(), 10.0, 30, 0);
3900
3901 SetLayerPropertiesForTesting(parent.get(),
3902 identity_matrix,
[email protected]fb661802013-03-25 01:59:323903 gfx::PointF(),
3904 gfx::PointF(),
3905 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573906 true,
[email protected]fb661802013-03-25 01:59:323907 false);
3908 SetLayerPropertiesForTesting(child.get(),
3909 backface_matrix,
[email protected]fb661802013-03-25 01:59:323910 gfx::PointF(),
3911 gfx::PointF(),
3912 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573913 true,
[email protected]fb661802013-03-25 01:59:323914 false);
3915 SetLayerPropertiesForTesting(animating_surface.get(),
3916 backface_matrix,
[email protected]fb661802013-03-25 01:59:323917 gfx::PointF(),
3918 gfx::PointF(),
3919 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573920 true,
[email protected]fb661802013-03-25 01:59:323921 false);
3922 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3923 backface_matrix,
[email protected]fb661802013-03-25 01:59:323924 gfx::PointF(),
3925 gfx::PointF(),
3926 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573927 true,
[email protected]fb661802013-03-25 01:59:323928 false);
3929 SetLayerPropertiesForTesting(animating_child.get(),
3930 backface_matrix,
[email protected]fb661802013-03-25 01:59:323931 gfx::PointF(),
3932 gfx::PointF(),
3933 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573934 true,
[email protected]fb661802013-03-25 01:59:323935 false);
3936 SetLayerPropertiesForTesting(child2.get(),
3937 identity_matrix,
[email protected]fb661802013-03-25 01:59:323938 gfx::PointF(),
3939 gfx::PointF(),
3940 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573941 true,
[email protected]fb661802013-03-25 01:59:323942 false);
3943
[email protected]989386c2013-07-18 21:37:233944 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533945 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3946 parent.get(), parent->bounds(), &render_surface_layer_list);
3947 inputs.can_adjust_raster_scales = true;
3948 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323949
3950 EXPECT_FALSE(child->render_surface());
3951 EXPECT_TRUE(animating_surface->render_surface());
3952 EXPECT_FALSE(child_of_animating_surface->render_surface());
3953 EXPECT_FALSE(animating_child->render_surface());
3954 EXPECT_FALSE(child2->render_surface());
3955
3956 // Verify that the animating_child and child_of_animating_surface were not
3957 // culled, but that child was.
3958 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233959 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3960 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323961
3962 // The non-animating child be culled from the layer list for the parent render
3963 // surface.
3964 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233965 3u,
3966 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3967 EXPECT_EQ(animating_surface->id(),
3968 render_surface_layer_list.at(0)
3969 ->render_surface()->layer_list().at(0)->id());
3970 EXPECT_EQ(animating_child->id(),
3971 render_surface_layer_list.at(0)
3972 ->render_surface()->layer_list().at(1)->id());
3973 EXPECT_EQ(child2->id(),
3974 render_surface_layer_list.at(0)
3975 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:323976
3977 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233978 2u,
3979 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3980 EXPECT_EQ(animating_surface->id(),
3981 render_surface_layer_list.at(1)
3982 ->render_surface()->layer_list().at(0)->id());
3983 EXPECT_EQ(child_of_animating_surface->id(),
3984 render_surface_layer_list.at(1)
3985 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323986
3987 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
3988
3989 // The animating layers should have a visible content rect that represents the
3990 // area of the front face that is within the viewport.
3991 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053992 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:323993 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053994 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:323995 // And layers in the subtree of the animating layer should have valid visible
3996 // content rects also.
[email protected]989386c2013-07-18 21:37:233997 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
3998 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:323999}
4000
[email protected]989386c2013-07-18 21:37:234001TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324002 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4003 // Verify the behavior of back-face culling for a render surface that is
4004 // created when it flattens its subtree, and its parent has preserves-3d.
4005
4006 const gfx::Transform identity_matrix;
4007 scoped_refptr<Layer> parent = Layer::Create();
4008 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
4009 make_scoped_refptr(new LayerWithForcedDrawsContent());
4010 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
4011 make_scoped_refptr(new LayerWithForcedDrawsContent());
4012 scoped_refptr<LayerWithForcedDrawsContent> child1 =
4013 make_scoped_refptr(new LayerWithForcedDrawsContent());
4014 scoped_refptr<LayerWithForcedDrawsContent> child2 =
4015 make_scoped_refptr(new LayerWithForcedDrawsContent());
4016
4017 parent->AddChild(front_facing_surface);
4018 parent->AddChild(back_facing_surface);
4019 front_facing_surface->AddChild(child1);
4020 back_facing_surface->AddChild(child2);
4021
[email protected]d600df7d2013-08-03 02:34:284022 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4023 host->SetRootLayer(parent);
4024
[email protected]fb661802013-03-25 01:59:324025 // RenderSurfaces are not double-sided
4026 front_facing_surface->SetDoubleSided(false);
4027 back_facing_surface->SetDoubleSided(false);
4028
4029 gfx::Transform backface_matrix;
4030 backface_matrix.Translate(50.0, 50.0);
4031 backface_matrix.RotateAboutYAxis(180.0);
4032 backface_matrix.Translate(-50.0, -50.0);
4033
4034 SetLayerPropertiesForTesting(parent.get(),
4035 identity_matrix,
[email protected]fb661802013-03-25 01:59:324036 gfx::PointF(),
4037 gfx::PointF(),
4038 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574039 false,
4040 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:324041 SetLayerPropertiesForTesting(front_facing_surface.get(),
4042 identity_matrix,
[email protected]fb661802013-03-25 01:59:324043 gfx::PointF(),
4044 gfx::PointF(),
4045 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574046 true,
4047 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324048 SetLayerPropertiesForTesting(back_facing_surface.get(),
4049 backface_matrix,
[email protected]fb661802013-03-25 01:59:324050 gfx::PointF(),
4051 gfx::PointF(),
4052 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574053 true,
4054 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324055 SetLayerPropertiesForTesting(child1.get(),
4056 identity_matrix,
[email protected]fb661802013-03-25 01:59:324057 gfx::PointF(),
4058 gfx::PointF(),
4059 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574060 true,
[email protected]fb661802013-03-25 01:59:324061 false);
4062 SetLayerPropertiesForTesting(child2.get(),
4063 identity_matrix,
[email protected]fb661802013-03-25 01:59:324064 gfx::PointF(),
4065 gfx::PointF(),
4066 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574067 true,
[email protected]fb661802013-03-25 01:59:324068 false);
4069
[email protected]56fffdd2014-02-11 19:50:574070 front_facing_surface->SetIs3dSorted(true);
4071 back_facing_surface->SetIs3dSorted(true);
4072
[email protected]989386c2013-07-18 21:37:234073 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534074 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4075 parent.get(), parent->bounds(), &render_surface_layer_list);
4076 inputs.can_adjust_raster_scales = true;
4077 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324078
4079 // Verify which render surfaces were created.
4080 EXPECT_TRUE(front_facing_surface->render_surface());
4081 EXPECT_FALSE(
4082 back_facing_surface->render_surface()); // because it should be culled
4083 EXPECT_FALSE(child1->render_surface());
4084 EXPECT_FALSE(child2->render_surface());
4085
4086 // Verify the render_surface_layer_list. The back-facing surface should be
4087 // culled.
4088 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234089 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4090 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324091
4092 // Verify root surface's layer list.
4093 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234094 1u,
4095 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4096 EXPECT_EQ(front_facing_surface->id(),
4097 render_surface_layer_list.at(0)
4098 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324099
4100 // Verify front_facing_surface's layer list.
4101 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234102 2u,
4103 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4104 EXPECT_EQ(front_facing_surface->id(),
4105 render_surface_layer_list.at(1)
4106 ->render_surface()->layer_list().at(0)->id());
4107 EXPECT_EQ(child1->id(),
4108 render_surface_layer_list.at(1)
4109 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324110}
4111
[email protected]989386c2013-07-18 21:37:234112
4113TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:324114 // Hit testing on an empty render_surface_layer_list should return a null
4115 // pointer.
[email protected]50761e92013-03-29 20:51:284116 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:324117
4118 gfx::Point test_point(0, 0);
4119 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4120 test_point, render_surface_layer_list);
4121 EXPECT_FALSE(result_layer);
4122
4123 test_point = gfx::Point(10, 20);
4124 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4125 test_point, render_surface_layer_list);
4126 EXPECT_FALSE(result_layer);
4127}
4128
[email protected]989386c2013-07-18 21:37:234129TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayer) {
[email protected]fb661802013-03-25 01:59:324130 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454131 TestSharedBitmapManager shared_bitmap_manager;
4132 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324133 scoped_ptr<LayerImpl> root =
4134 LayerImpl::Create(host_impl.active_tree(), 12345);
4135
4136 gfx::Transform identity_matrix;
4137 gfx::PointF anchor;
4138 gfx::PointF position;
4139 gfx::Size bounds(100, 100);
4140 SetLayerPropertiesForTesting(root.get(),
4141 identity_matrix,
[email protected]fb661802013-03-25 01:59:324142 anchor,
4143 position,
4144 bounds,
[email protected]56fffdd2014-02-11 19:50:574145 true,
[email protected]fb661802013-03-25 01:59:324146 false);
4147 root->SetDrawsContent(true);
4148
[email protected]50761e92013-03-29 20:51:284149 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534150 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4151 root.get(), root->bounds(), &render_surface_layer_list);
4152 inputs.can_adjust_raster_scales = true;
4153 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324154
4155 // Sanity check the scenario we just created.
4156 ASSERT_EQ(1u, render_surface_layer_list.size());
4157 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4158
4159 // Hit testing for a point outside the layer should return a null pointer.
4160 gfx::Point test_point(101, 101);
4161 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4162 test_point, render_surface_layer_list);
4163 EXPECT_FALSE(result_layer);
4164
4165 test_point = gfx::Point(-1, -1);
4166 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4167 test_point, render_surface_layer_list);
4168 EXPECT_FALSE(result_layer);
4169
4170 // Hit testing for a point inside should return the root layer.
4171 test_point = gfx::Point(1, 1);
4172 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4173 test_point, render_surface_layer_list);
4174 ASSERT_TRUE(result_layer);
4175 EXPECT_EQ(12345, result_layer->id());
4176
4177 test_point = gfx::Point(99, 99);
4178 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4179 test_point, render_surface_layer_list);
4180 ASSERT_TRUE(result_layer);
4181 EXPECT_EQ(12345, result_layer->id());
4182}
4183
[email protected]989386c2013-07-18 21:37:234184TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) {
[email protected]fb661802013-03-25 01:59:324185 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454186 TestSharedBitmapManager shared_bitmap_manager;
4187 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324188 scoped_ptr<LayerImpl> root =
4189 LayerImpl::Create(host_impl.active_tree(), 12345);
4190 scoped_ptr<HeadsUpDisplayLayerImpl> hud =
4191 HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111);
4192
4193 gfx::Transform identity_matrix;
4194 gfx::PointF anchor;
4195 gfx::PointF position;
4196 gfx::Size bounds(100, 100);
4197 SetLayerPropertiesForTesting(root.get(),
4198 identity_matrix,
[email protected]fb661802013-03-25 01:59:324199 anchor,
4200 position,
4201 bounds,
[email protected]56fffdd2014-02-11 19:50:574202 true,
[email protected]fb661802013-03-25 01:59:324203 false);
4204 root->SetDrawsContent(true);
4205
4206 // Create hud and add it as a child of root.
4207 gfx::Size hud_bounds(200, 200);
4208 SetLayerPropertiesForTesting(hud.get(),
4209 identity_matrix,
[email protected]fb661802013-03-25 01:59:324210 anchor,
4211 position,
4212 hud_bounds,
[email protected]56fffdd2014-02-11 19:50:574213 true,
[email protected]fb661802013-03-25 01:59:324214 false);
4215 hud->SetDrawsContent(true);
4216
4217 host_impl.active_tree()->set_hud_layer(hud.get());
4218 root->AddChild(hud.PassAs<LayerImpl>());
4219
[email protected]50761e92013-03-29 20:51:284220 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534221 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4222 root.get(), hud_bounds, &render_surface_layer_list);
4223 inputs.can_adjust_raster_scales = true;
4224 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324225
4226 // Sanity check the scenario we just created.
4227 ASSERT_EQ(1u, render_surface_layer_list.size());
4228 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4229
4230 // Hit testing for a point inside HUD, but outside root should return null
4231 gfx::Point test_point(101, 101);
4232 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4233 test_point, render_surface_layer_list);
4234 EXPECT_FALSE(result_layer);
4235
4236 test_point = gfx::Point(-1, -1);
4237 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4238 test_point, render_surface_layer_list);
4239 EXPECT_FALSE(result_layer);
4240
4241 // Hit testing for a point inside should return the root layer, never the HUD
4242 // layer.
4243 test_point = gfx::Point(1, 1);
4244 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4245 test_point, render_surface_layer_list);
4246 ASSERT_TRUE(result_layer);
4247 EXPECT_EQ(12345, result_layer->id());
4248
4249 test_point = gfx::Point(99, 99);
4250 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4251 test_point, render_surface_layer_list);
4252 ASSERT_TRUE(result_layer);
4253 EXPECT_EQ(12345, result_layer->id());
4254}
4255
[email protected]989386c2013-07-18 21:37:234256TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) {
[email protected]fb661802013-03-25 01:59:324257 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454258 TestSharedBitmapManager shared_bitmap_manager;
4259 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324260 scoped_ptr<LayerImpl> root =
4261 LayerImpl::Create(host_impl.active_tree(), 12345);
4262
4263 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:264264 uninvertible_transform.matrix().set(0, 0, 0.0);
4265 uninvertible_transform.matrix().set(1, 1, 0.0);
4266 uninvertible_transform.matrix().set(2, 2, 0.0);
4267 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:324268 ASSERT_FALSE(uninvertible_transform.IsInvertible());
4269
4270 gfx::Transform identity_matrix;
4271 gfx::PointF anchor;
4272 gfx::PointF position;
4273 gfx::Size bounds(100, 100);
4274 SetLayerPropertiesForTesting(root.get(),
4275 uninvertible_transform,
[email protected]fb661802013-03-25 01:59:324276 anchor,
4277 position,
4278 bounds,
[email protected]56fffdd2014-02-11 19:50:574279 true,
[email protected]fb661802013-03-25 01:59:324280 false);
4281 root->SetDrawsContent(true);
4282
[email protected]50761e92013-03-29 20:51:284283 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534284 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4285 root.get(), root->bounds(), &render_surface_layer_list);
4286 inputs.can_adjust_raster_scales = true;
4287 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324288
4289 // Sanity check the scenario we just created.
4290 ASSERT_EQ(1u, render_surface_layer_list.size());
4291 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4292 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
4293
4294 // Hit testing any point should not hit the layer. If the invertible matrix is
4295 // accidentally ignored and treated like an identity, then the hit testing
4296 // will incorrectly hit the layer when it shouldn't.
4297 gfx::Point test_point(1, 1);
4298 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4299 test_point, render_surface_layer_list);
4300 EXPECT_FALSE(result_layer);
4301
4302 test_point = gfx::Point(10, 10);
4303 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4304 test_point, render_surface_layer_list);
4305 EXPECT_FALSE(result_layer);
4306
4307 test_point = gfx::Point(10, 30);
4308 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4309 test_point, render_surface_layer_list);
4310 EXPECT_FALSE(result_layer);
4311
4312 test_point = gfx::Point(50, 50);
4313 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4314 test_point, render_surface_layer_list);
4315 EXPECT_FALSE(result_layer);
4316
4317 test_point = gfx::Point(67, 48);
4318 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4319 test_point, render_surface_layer_list);
4320 EXPECT_FALSE(result_layer);
4321
4322 test_point = gfx::Point(99, 99);
4323 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4324 test_point, render_surface_layer_list);
4325 EXPECT_FALSE(result_layer);
4326
4327 test_point = gfx::Point(-1, -1);
4328 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4329 test_point, render_surface_layer_list);
4330 EXPECT_FALSE(result_layer);
4331}
4332
[email protected]989386c2013-07-18 21:37:234333TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) {
[email protected]fb661802013-03-25 01:59:324334 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454335 TestSharedBitmapManager shared_bitmap_manager;
4336 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324337 scoped_ptr<LayerImpl> root =
4338 LayerImpl::Create(host_impl.active_tree(), 12345);
4339
4340 gfx::Transform identity_matrix;
4341 gfx::PointF anchor;
4342 // this layer is positioned, and hit testing should correctly know where the
4343 // layer is located.
4344 gfx::PointF position(50.f, 50.f);
4345 gfx::Size bounds(100, 100);
4346 SetLayerPropertiesForTesting(root.get(),
4347 identity_matrix,
[email protected]fb661802013-03-25 01:59:324348 anchor,
4349 position,
4350 bounds,
[email protected]56fffdd2014-02-11 19:50:574351 true,
[email protected]fb661802013-03-25 01:59:324352 false);
4353 root->SetDrawsContent(true);
4354
[email protected]50761e92013-03-29 20:51:284355 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534356 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4357 root.get(), root->bounds(), &render_surface_layer_list);
4358 inputs.can_adjust_raster_scales = true;
4359 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324360
4361 // Sanity check the scenario we just created.
4362 ASSERT_EQ(1u, render_surface_layer_list.size());
4363 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4364
4365 // Hit testing for a point outside the layer should return a null pointer.
4366 gfx::Point test_point(49, 49);
4367 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4368 test_point, render_surface_layer_list);
4369 EXPECT_FALSE(result_layer);
4370
4371 // Even though the layer exists at (101, 101), it should not be visible there
4372 // since the root render surface would clamp it.
4373 test_point = gfx::Point(101, 101);
4374 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4375 test_point, render_surface_layer_list);
4376 EXPECT_FALSE(result_layer);
4377
4378 // Hit testing for a point inside should return the root layer.
4379 test_point = gfx::Point(51, 51);
4380 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4381 test_point, render_surface_layer_list);
4382 ASSERT_TRUE(result_layer);
4383 EXPECT_EQ(12345, result_layer->id());
4384
4385 test_point = gfx::Point(99, 99);
4386 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4387 test_point, render_surface_layer_list);
4388 ASSERT_TRUE(result_layer);
4389 EXPECT_EQ(12345, result_layer->id());
4390}
4391
[email protected]989386c2013-07-18 21:37:234392TEST_F(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324393 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454394 TestSharedBitmapManager shared_bitmap_manager;
4395 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324396 scoped_ptr<LayerImpl> root =
4397 LayerImpl::Create(host_impl.active_tree(), 12345);
4398
4399 gfx::Transform identity_matrix;
4400 gfx::Transform rotation45_degrees_about_center;
4401 rotation45_degrees_about_center.Translate(50.0, 50.0);
4402 rotation45_degrees_about_center.RotateAboutZAxis(45.0);
4403 rotation45_degrees_about_center.Translate(-50.0, -50.0);
4404 gfx::PointF anchor;
4405 gfx::PointF position;
4406 gfx::Size bounds(100, 100);
4407 SetLayerPropertiesForTesting(root.get(),
4408 rotation45_degrees_about_center,
[email protected]fb661802013-03-25 01:59:324409 anchor,
4410 position,
4411 bounds,
[email protected]56fffdd2014-02-11 19:50:574412 true,
[email protected]fb661802013-03-25 01:59:324413 false);
4414 root->SetDrawsContent(true);
4415
[email protected]50761e92013-03-29 20:51:284416 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534417 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4418 root.get(), root->bounds(), &render_surface_layer_list);
4419 inputs.can_adjust_raster_scales = true;
4420 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324421
4422 // Sanity check the scenario we just created.
4423 ASSERT_EQ(1u, render_surface_layer_list.size());
4424 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4425
4426 // Hit testing for points outside the layer.
4427 // These corners would have been inside the un-transformed layer, but they
4428 // should not hit the correctly transformed layer.
4429 gfx::Point test_point(99, 99);
4430 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4431 test_point, render_surface_layer_list);
4432 EXPECT_FALSE(result_layer);
4433
4434 test_point = gfx::Point(1, 1);
4435 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4436 test_point, render_surface_layer_list);
4437 EXPECT_FALSE(result_layer);
4438
4439 // Hit testing for a point inside should return the root layer.
4440 test_point = gfx::Point(1, 50);
4441 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4442 test_point, render_surface_layer_list);
4443 ASSERT_TRUE(result_layer);
4444 EXPECT_EQ(12345, result_layer->id());
4445
4446 // Hit testing the corners that would overlap the unclipped layer, but are
4447 // outside the clipped region.
4448 test_point = gfx::Point(50, -1);
4449 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4450 test_point, render_surface_layer_list);
4451 ASSERT_FALSE(result_layer);
4452
4453 test_point = gfx::Point(-1, 50);
4454 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4455 test_point, render_surface_layer_list);
4456 ASSERT_FALSE(result_layer);
4457}
4458
[email protected]989386c2013-07-18 21:37:234459TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) {
[email protected]fb661802013-03-25 01:59:324460 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454461 TestSharedBitmapManager shared_bitmap_manager;
4462 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324463 scoped_ptr<LayerImpl> root =
4464 LayerImpl::Create(host_impl.active_tree(), 12345);
4465
4466 gfx::Transform identity_matrix;
4467
4468 // perspective_projection_about_center * translation_by_z is designed so that
4469 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
4470 gfx::Transform perspective_projection_about_center;
4471 perspective_projection_about_center.Translate(50.0, 50.0);
4472 perspective_projection_about_center.ApplyPerspectiveDepth(1.0);
4473 perspective_projection_about_center.Translate(-50.0, -50.0);
4474 gfx::Transform translation_by_z;
4475 translation_by_z.Translate3d(0.0, 0.0, -1.0);
4476
4477 gfx::PointF anchor;
4478 gfx::PointF position;
4479 gfx::Size bounds(100, 100);
4480 SetLayerPropertiesForTesting(
4481 root.get(),
4482 perspective_projection_about_center * translation_by_z,
[email protected]fb661802013-03-25 01:59:324483 anchor,
4484 position,
4485 bounds,
[email protected]56fffdd2014-02-11 19:50:574486 true,
[email protected]fb661802013-03-25 01:59:324487 false);
4488 root->SetDrawsContent(true);
4489
[email protected]50761e92013-03-29 20:51:284490 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534491 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4492 root.get(), root->bounds(), &render_surface_layer_list);
4493 inputs.can_adjust_raster_scales = true;
4494 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324495
4496 // Sanity check the scenario we just created.
4497 ASSERT_EQ(1u, render_surface_layer_list.size());
4498 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4499
4500 // Hit testing for points outside the layer.
4501 // These corners would have been inside the un-transformed layer, but they
4502 // should not hit the correctly transformed layer.
4503 gfx::Point test_point(24, 24);
4504 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4505 test_point, render_surface_layer_list);
4506 EXPECT_FALSE(result_layer);
4507
4508 test_point = gfx::Point(76, 76);
4509 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4510 test_point, render_surface_layer_list);
4511 EXPECT_FALSE(result_layer);
4512
4513 // Hit testing for a point inside should return the root layer.
4514 test_point = gfx::Point(26, 26);
4515 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4516 test_point, render_surface_layer_list);
4517 ASSERT_TRUE(result_layer);
4518 EXPECT_EQ(12345, result_layer->id());
4519
4520 test_point = gfx::Point(74, 74);
4521 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4522 test_point, render_surface_layer_list);
4523 ASSERT_TRUE(result_layer);
4524 EXPECT_EQ(12345, result_layer->id());
4525}
4526
[email protected]989386c2013-07-18 21:37:234527TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) {
[email protected]fb661802013-03-25 01:59:324528 // A layer's visible content rect is actually in the layer's content space.
4529 // The screen space transform converts from the layer's origin space to screen
4530 // space. This test makes sure that hit testing works correctly accounts for
4531 // the contents scale. A contents scale that is not 1 effectively forces a
4532 // non-identity transform between layer's content space and layer's origin
4533 // space. The hit testing code must take this into account.
4534 //
4535 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
4536 // contents scale is ignored, then hit testing will mis-interpret the visible
4537 // content rect as being larger than the actual bounds of the layer.
4538 //
4539 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454540 TestSharedBitmapManager shared_bitmap_manager;
4541 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324542 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4543
4544 gfx::Transform identity_matrix;
4545 gfx::PointF anchor;
4546
4547 SetLayerPropertiesForTesting(root.get(),
4548 identity_matrix,
[email protected]fb661802013-03-25 01:59:324549 anchor,
4550 gfx::PointF(),
4551 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574552 true,
[email protected]fb661802013-03-25 01:59:324553 false);
4554 {
4555 gfx::PointF position(25.f, 25.f);
4556 gfx::Size bounds(50, 50);
4557 scoped_ptr<LayerImpl> test_layer =
4558 LayerImpl::Create(host_impl.active_tree(), 12345);
4559 SetLayerPropertiesForTesting(test_layer.get(),
4560 identity_matrix,
[email protected]fb661802013-03-25 01:59:324561 anchor,
4562 position,
4563 bounds,
[email protected]56fffdd2014-02-11 19:50:574564 true,
[email protected]fb661802013-03-25 01:59:324565 false);
4566
4567 // override content bounds and contents scale
4568 test_layer->SetContentBounds(gfx::Size(100, 100));
4569 test_layer->SetContentsScale(2, 2);
4570
4571 test_layer->SetDrawsContent(true);
4572 root->AddChild(test_layer.Pass());
4573 }
4574
[email protected]50761e92013-03-29 20:51:284575 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534576 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4577 root.get(), root->bounds(), &render_surface_layer_list);
4578 inputs.can_adjust_raster_scales = true;
4579 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324580
4581 // Sanity check the scenario we just created.
4582 // The visible content rect for test_layer is actually 100x100, even though
4583 // its layout size is 50x50, positioned at 25x25.
4584 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:054585 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
[email protected]fb661802013-03-25 01:59:324586 test_layer->visible_content_rect());
4587 ASSERT_EQ(1u, render_surface_layer_list.size());
4588 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4589
4590 // Hit testing for a point outside the layer should return a null pointer (the
4591 // root layer does not draw content, so it will not be hit tested either).
4592 gfx::Point test_point(101, 101);
4593 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4594 test_point, render_surface_layer_list);
4595 EXPECT_FALSE(result_layer);
4596
4597 test_point = gfx::Point(24, 24);
4598 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4599 test_point, render_surface_layer_list);
4600 EXPECT_FALSE(result_layer);
4601
4602 test_point = gfx::Point(76, 76);
4603 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4604 test_point, render_surface_layer_list);
4605 EXPECT_FALSE(result_layer);
4606
4607 // Hit testing for a point inside should return the test layer.
4608 test_point = gfx::Point(26, 26);
4609 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4610 test_point, render_surface_layer_list);
4611 ASSERT_TRUE(result_layer);
4612 EXPECT_EQ(12345, result_layer->id());
4613
4614 test_point = gfx::Point(74, 74);
4615 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4616 test_point, render_surface_layer_list);
4617 ASSERT_TRUE(result_layer);
4618 EXPECT_EQ(12345, result_layer->id());
4619}
4620
[email protected]989386c2013-07-18 21:37:234621TEST_F(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) {
[email protected]fb661802013-03-25 01:59:324622 // Test that hit-testing will only work for the visible portion of a layer,
4623 // and not the entire layer bounds. Here we just test the simple axis-aligned
4624 // case.
4625 gfx::Transform identity_matrix;
4626 gfx::PointF anchor;
4627
4628 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454629 TestSharedBitmapManager shared_bitmap_manager;
4630 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324631 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4632 SetLayerPropertiesForTesting(root.get(),
4633 identity_matrix,
[email protected]fb661802013-03-25 01:59:324634 anchor,
4635 gfx::PointF(),
4636 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574637 true,
[email protected]fb661802013-03-25 01:59:324638 false);
4639 {
4640 scoped_ptr<LayerImpl> clipping_layer =
4641 LayerImpl::Create(host_impl.active_tree(), 123);
4642 // this layer is positioned, and hit testing should correctly know where the
4643 // layer is located.
[email protected]ca2902e92013-03-28 01:45:354644 gfx::PointF position(25.f, 25.f);
[email protected]fb661802013-03-25 01:59:324645 gfx::Size bounds(50, 50);
4646 SetLayerPropertiesForTesting(clipping_layer.get(),
4647 identity_matrix,
[email protected]fb661802013-03-25 01:59:324648 anchor,
4649 position,
4650 bounds,
[email protected]56fffdd2014-02-11 19:50:574651 true,
[email protected]fb661802013-03-25 01:59:324652 false);
4653 clipping_layer->SetMasksToBounds(true);
4654
4655 scoped_ptr<LayerImpl> child =
4656 LayerImpl::Create(host_impl.active_tree(), 456);
4657 position = gfx::PointF(-50.f, -50.f);
4658 bounds = gfx::Size(300, 300);
4659 SetLayerPropertiesForTesting(child.get(),
4660 identity_matrix,
[email protected]fb661802013-03-25 01:59:324661 anchor,
4662 position,
4663 bounds,
[email protected]56fffdd2014-02-11 19:50:574664 true,
[email protected]fb661802013-03-25 01:59:324665 false);
4666 child->SetDrawsContent(true);
4667 clipping_layer->AddChild(child.Pass());
4668 root->AddChild(clipping_layer.Pass());
4669 }
4670
[email protected]50761e92013-03-29 20:51:284671 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534672 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4673 root.get(), root->bounds(), &render_surface_layer_list);
4674 inputs.can_adjust_raster_scales = true;
4675 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324676
4677 // Sanity check the scenario we just created.
4678 ASSERT_EQ(1u, render_surface_layer_list.size());
4679 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234680 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324681
4682 // Hit testing for a point outside the layer should return a null pointer.
4683 // Despite the child layer being very large, it should be clipped to the root
4684 // layer's bounds.
4685 gfx::Point test_point(24, 24);
4686 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4687 test_point, render_surface_layer_list);
4688 EXPECT_FALSE(result_layer);
4689
4690 // Even though the layer exists at (101, 101), it should not be visible there
4691 // since the clipping_layer would clamp it.
4692 test_point = gfx::Point(76, 76);
4693 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4694 test_point, render_surface_layer_list);
4695 EXPECT_FALSE(result_layer);
4696
4697 // Hit testing for a point inside should return the child layer.
4698 test_point = gfx::Point(26, 26);
4699 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4700 test_point, render_surface_layer_list);
4701 ASSERT_TRUE(result_layer);
4702 EXPECT_EQ(456, result_layer->id());
4703
4704 test_point = gfx::Point(74, 74);
4705 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4706 test_point, render_surface_layer_list);
4707 ASSERT_TRUE(result_layer);
4708 EXPECT_EQ(456, result_layer->id());
4709}
4710
[email protected]989386c2013-07-18 21:37:234711TEST_F(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324712 // This test checks whether hit testing correctly avoids hit testing with
4713 // multiple ancestors that clip in non axis-aligned ways. To pass this test,
4714 // the hit testing algorithm needs to recognize that multiple parent layers
4715 // may clip the layer, and should not actually hit those clipped areas.
4716 //
4717 // The child and grand_child layers are both initialized to clip the
4718 // rotated_leaf. The child layer is rotated about the top-left corner, so that
4719 // the root + child clips combined create a triangle. The rotated_leaf will
4720 // only be visible where it overlaps this triangle.
4721 //
4722 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454723 TestSharedBitmapManager shared_bitmap_manager;
4724 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324725 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123);
4726
4727 gfx::Transform identity_matrix;
4728 gfx::PointF anchor;
4729 gfx::PointF position;
4730 gfx::Size bounds(100, 100);
4731 SetLayerPropertiesForTesting(root.get(),
4732 identity_matrix,
[email protected]fb661802013-03-25 01:59:324733 anchor,
4734 position,
4735 bounds,
[email protected]56fffdd2014-02-11 19:50:574736 true,
[email protected]fb661802013-03-25 01:59:324737 false);
4738 root->SetMasksToBounds(true);
4739 {
4740 scoped_ptr<LayerImpl> child =
4741 LayerImpl::Create(host_impl.active_tree(), 456);
4742 scoped_ptr<LayerImpl> grand_child =
4743 LayerImpl::Create(host_impl.active_tree(), 789);
4744 scoped_ptr<LayerImpl> rotated_leaf =
4745 LayerImpl::Create(host_impl.active_tree(), 2468);
4746
4747 position = gfx::PointF(10.f, 10.f);
4748 bounds = gfx::Size(80, 80);
4749 SetLayerPropertiesForTesting(child.get(),
4750 identity_matrix,
[email protected]fb661802013-03-25 01:59:324751 anchor,
4752 position,
4753 bounds,
[email protected]56fffdd2014-02-11 19:50:574754 true,
[email protected]fb661802013-03-25 01:59:324755 false);
[email protected]7aba6662013-03-12 10:17:344756 child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444757
[email protected]fb661802013-03-25 01:59:324758 gfx::Transform rotation45_degrees_about_corner;
4759 rotation45_degrees_about_corner.RotateAboutZAxis(45.0);
[email protected]aedf4e52013-01-09 23:24:444760
[email protected]fb661802013-03-25 01:59:324761 // remember, positioned with respect to its parent which is already at 10,
4762 // 10
4763 position = gfx::PointF();
4764 bounds =
4765 gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
4766 SetLayerPropertiesForTesting(grand_child.get(),
4767 rotation45_degrees_about_corner,
[email protected]fb661802013-03-25 01:59:324768 anchor,
4769 position,
4770 bounds,
[email protected]56fffdd2014-02-11 19:50:574771 true,
[email protected]fb661802013-03-25 01:59:324772 false);
4773 grand_child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444774
[email protected]fb661802013-03-25 01:59:324775 // Rotates about the center of the layer
4776 gfx::Transform rotated_leaf_transform;
4777 rotated_leaf_transform.Translate(
4778 -10.0, -10.0); // cancel out the grand_parent's position
4779 rotated_leaf_transform.RotateAboutZAxis(
4780 -45.0); // cancel out the corner 45-degree rotation of the parent.
4781 rotated_leaf_transform.Translate(50.0, 50.0);
4782 rotated_leaf_transform.RotateAboutZAxis(45.0);
4783 rotated_leaf_transform.Translate(-50.0, -50.0);
4784 position = gfx::PointF();
4785 bounds = gfx::Size(100, 100);
4786 SetLayerPropertiesForTesting(rotated_leaf.get(),
4787 rotated_leaf_transform,
[email protected]fb661802013-03-25 01:59:324788 anchor,
4789 position,
4790 bounds,
[email protected]56fffdd2014-02-11 19:50:574791 true,
[email protected]fb661802013-03-25 01:59:324792 false);
4793 rotated_leaf->SetDrawsContent(true);
[email protected]aedf4e52013-01-09 23:24:444794
[email protected]fb661802013-03-25 01:59:324795 grand_child->AddChild(rotated_leaf.Pass());
4796 child->AddChild(grand_child.Pass());
4797 root->AddChild(child.Pass());
4798 }
[email protected]aedf4e52013-01-09 23:24:444799
[email protected]50761e92013-03-29 20:51:284800 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534801 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4802 root.get(), root->bounds(), &render_surface_layer_list);
4803 inputs.can_adjust_raster_scales = true;
4804 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:444805
[email protected]fb661802013-03-25 01:59:324806 // Sanity check the scenario we just created.
4807 // The grand_child is expected to create a render surface because it
[email protected]989386c2013-07-18 21:37:234808 // MasksToBounds and is not axis aligned.
[email protected]fb661802013-03-25 01:59:324809 ASSERT_EQ(2u, render_surface_layer_list.size());
4810 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234811 1u,
4812 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324813 ASSERT_EQ(789,
[email protected]989386c2013-07-18 21:37:234814 render_surface_layer_list.at(0)->render_surface()->layer_list().at(
4815 0)->id()); // grand_child's surface.
[email protected]fb661802013-03-25 01:59:324816 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234817 1u,
4818 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324819 ASSERT_EQ(
4820 2468,
[email protected]989386c2013-07-18 21:37:234821 render_surface_layer_list[1]->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324822
4823 // (11, 89) is close to the the bottom left corner within the clip, but it is
4824 // not inside the layer.
4825 gfx::Point test_point(11, 89);
4826 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4827 test_point, render_surface_layer_list);
4828 EXPECT_FALSE(result_layer);
4829
4830 // Closer inwards from the bottom left will overlap the layer.
4831 test_point = gfx::Point(25, 75);
4832 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4833 test_point, render_surface_layer_list);
4834 ASSERT_TRUE(result_layer);
4835 EXPECT_EQ(2468, result_layer->id());
4836
4837 // (4, 50) is inside the unclipped layer, but that corner of the layer should
4838 // be clipped away by the grandparent and should not get hit. If hit testing
4839 // blindly uses visible content rect without considering how parent may clip
4840 // the layer, then hit testing would accidentally think that the point
4841 // successfully hits the layer.
4842 test_point = gfx::Point(4, 50);
4843 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4844 test_point, render_surface_layer_list);
4845 EXPECT_FALSE(result_layer);
4846
4847 // (11, 50) is inside the layer and within the clipped area.
4848 test_point = gfx::Point(11, 50);
4849 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4850 test_point, render_surface_layer_list);
4851 ASSERT_TRUE(result_layer);
4852 EXPECT_EQ(2468, result_layer->id());
4853
4854 // Around the middle, just to the right and up, would have hit the layer
4855 // except that that area should be clipped away by the parent.
[email protected]803f6b52013-09-12 00:51:264856 test_point = gfx::Point(51, 49);
[email protected]fb661802013-03-25 01:59:324857 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4858 test_point, render_surface_layer_list);
4859 EXPECT_FALSE(result_layer);
4860
4861 // Around the middle, just to the left and down, should successfully hit the
4862 // layer.
4863 test_point = gfx::Point(49, 51);
4864 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4865 test_point, render_surface_layer_list);
4866 ASSERT_TRUE(result_layer);
4867 EXPECT_EQ(2468, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:444868}
4869
[email protected]989386c2013-07-18 21:37:234870TEST_F(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:324871 // This test checks that hit testing code does not accidentally clip to layer
4872 // bounds for a layer that actually does not clip.
4873 gfx::Transform identity_matrix;
4874 gfx::PointF anchor;
[email protected]aedf4e52013-01-09 23:24:444875
[email protected]fb661802013-03-25 01:59:324876 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454877 TestSharedBitmapManager shared_bitmap_manager;
4878 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324879 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4880 SetLayerPropertiesForTesting(root.get(),
4881 identity_matrix,
[email protected]fb661802013-03-25 01:59:324882 anchor,
4883 gfx::PointF(),
4884 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574885 true,
[email protected]fb661802013-03-25 01:59:324886 false);
4887 {
4888 scoped_ptr<LayerImpl> intermediate_layer =
4889 LayerImpl::Create(host_impl.active_tree(), 123);
4890 // this layer is positioned, and hit testing should correctly know where the
4891 // layer is located.
4892 gfx::PointF position(10.f, 10.f);
4893 gfx::Size bounds(50, 50);
4894 SetLayerPropertiesForTesting(intermediate_layer.get(),
4895 identity_matrix,
[email protected]fb661802013-03-25 01:59:324896 anchor,
4897 position,
4898 bounds,
[email protected]56fffdd2014-02-11 19:50:574899 true,
[email protected]fb661802013-03-25 01:59:324900 false);
4901 // Sanity check the intermediate layer should not clip.
4902 ASSERT_FALSE(intermediate_layer->masks_to_bounds());
4903 ASSERT_FALSE(intermediate_layer->mask_layer());
[email protected]aedf4e52013-01-09 23:24:444904
[email protected]fb661802013-03-25 01:59:324905 // The child of the intermediate_layer is translated so that it does not
4906 // overlap intermediate_layer at all. If child is incorrectly clipped, we
4907 // would not be able to hit it successfully.
4908 scoped_ptr<LayerImpl> child =
4909 LayerImpl::Create(host_impl.active_tree(), 456);
4910 position = gfx::PointF(60.f, 60.f); // 70, 70 in screen space
4911 bounds = gfx::Size(20, 20);
4912 SetLayerPropertiesForTesting(child.get(),
4913 identity_matrix,
[email protected]fb661802013-03-25 01:59:324914 anchor,
4915 position,
4916 bounds,
[email protected]56fffdd2014-02-11 19:50:574917 true,
[email protected]fb661802013-03-25 01:59:324918 false);
4919 child->SetDrawsContent(true);
4920 intermediate_layer->AddChild(child.Pass());
4921 root->AddChild(intermediate_layer.Pass());
4922 }
[email protected]aedf4e52013-01-09 23:24:444923
[email protected]50761e92013-03-29 20:51:284924 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534925 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4926 root.get(), root->bounds(), &render_surface_layer_list);
4927 inputs.can_adjust_raster_scales = true;
4928 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:444929
[email protected]fb661802013-03-25 01:59:324930 // Sanity check the scenario we just created.
4931 ASSERT_EQ(1u, render_surface_layer_list.size());
4932 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234933 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]aedf4e52013-01-09 23:24:444934
[email protected]fb661802013-03-25 01:59:324935 // Hit testing for a point outside the layer should return a null pointer.
4936 gfx::Point test_point(69, 69);
4937 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4938 test_point, render_surface_layer_list);
4939 EXPECT_FALSE(result_layer);
[email protected]aedf4e52013-01-09 23:24:444940
[email protected]fb661802013-03-25 01:59:324941 test_point = gfx::Point(91, 91);
4942 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4943 test_point, render_surface_layer_list);
4944 EXPECT_FALSE(result_layer);
4945
4946 // Hit testing for a point inside should return the child layer.
4947 test_point = gfx::Point(71, 71);
4948 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4949 test_point, render_surface_layer_list);
4950 ASSERT_TRUE(result_layer);
4951 EXPECT_EQ(456, result_layer->id());
4952
4953 test_point = gfx::Point(89, 89);
4954 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4955 test_point, render_surface_layer_list);
4956 ASSERT_TRUE(result_layer);
4957 EXPECT_EQ(456, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:444958}
4959
[email protected]989386c2013-07-18 21:37:234960TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayers) {
[email protected]fb661802013-03-25 01:59:324961 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454962 TestSharedBitmapManager shared_bitmap_manager;
4963 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324964 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:144965
[email protected]fb661802013-03-25 01:59:324966 gfx::Transform identity_matrix;
4967 gfx::PointF anchor;
4968 gfx::PointF position;
4969 gfx::Size bounds(100, 100);
4970 SetLayerPropertiesForTesting(root.get(),
4971 identity_matrix,
[email protected]fb661802013-03-25 01:59:324972 anchor,
4973 position,
4974 bounds,
[email protected]56fffdd2014-02-11 19:50:574975 true,
[email protected]fb661802013-03-25 01:59:324976 false);
4977 root->SetDrawsContent(true);
4978 {
4979 // child 1 and child2 are initialized to overlap between x=50 and x=60.
4980 // grand_child is set to overlap both child1 and child2 between y=50 and
4981 // y=60. The expected stacking order is: (front) child2, (second)
4982 // grand_child, (third) child1, and (back) the root layer behind all other
4983 // layers.
[email protected]ecc12622012-10-30 20:45:424984
[email protected]fb661802013-03-25 01:59:324985 scoped_ptr<LayerImpl> child1 =
4986 LayerImpl::Create(host_impl.active_tree(), 2);
4987 scoped_ptr<LayerImpl> child2 =
4988 LayerImpl::Create(host_impl.active_tree(), 3);
4989 scoped_ptr<LayerImpl> grand_child1 =
4990 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:144991
[email protected]fb661802013-03-25 01:59:324992 position = gfx::PointF(10.f, 10.f);
4993 bounds = gfx::Size(50, 50);
4994 SetLayerPropertiesForTesting(child1.get(),
4995 identity_matrix,
[email protected]fb661802013-03-25 01:59:324996 anchor,
4997 position,
4998 bounds,
[email protected]56fffdd2014-02-11 19:50:574999 true,
[email protected]fb661802013-03-25 01:59:325000 false);
5001 child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145002
[email protected]fb661802013-03-25 01:59:325003 position = gfx::PointF(50.f, 10.f);
5004 bounds = gfx::Size(50, 50);
5005 SetLayerPropertiesForTesting(child2.get(),
5006 identity_matrix,
[email protected]fb661802013-03-25 01:59:325007 anchor,
5008 position,
5009 bounds,
[email protected]56fffdd2014-02-11 19:50:575010 true,
[email protected]fb661802013-03-25 01:59:325011 false);
5012 child2->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145013
[email protected]fb661802013-03-25 01:59:325014 // Remember that grand_child is positioned with respect to its parent (i.e.
5015 // child1). In screen space, the intended position is (10, 50), with size
5016 // 100 x 50.
5017 position = gfx::PointF(0.f, 40.f);
5018 bounds = gfx::Size(100, 50);
5019 SetLayerPropertiesForTesting(grand_child1.get(),
5020 identity_matrix,
[email protected]fb661802013-03-25 01:59:325021 anchor,
5022 position,
5023 bounds,
[email protected]56fffdd2014-02-11 19:50:575024 true,
[email protected]fb661802013-03-25 01:59:325025 false);
5026 grand_child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145027
[email protected]fb661802013-03-25 01:59:325028 child1->AddChild(grand_child1.Pass());
5029 root->AddChild(child1.Pass());
5030 root->AddChild(child2.Pass());
5031 }
[email protected]94f206c12012-08-25 00:09:145032
[email protected]fb661802013-03-25 01:59:325033 LayerImpl* child1 = root->children()[0];
5034 LayerImpl* child2 = root->children()[1];
5035 LayerImpl* grand_child1 = child1->children()[0];
5036
[email protected]50761e92013-03-29 20:51:285037 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535038 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5039 root.get(), root->bounds(), &render_surface_layer_list);
5040 inputs.can_adjust_raster_scales = true;
5041 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325042
5043 // Sanity check the scenario we just created.
5044 ASSERT_TRUE(child1);
5045 ASSERT_TRUE(child2);
5046 ASSERT_TRUE(grand_child1);
5047 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:235048
5049 RenderSurfaceImpl* root_render_surface = root->render_surface();
5050 ASSERT_EQ(4u, root_render_surface->layer_list().size());
5051 ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer
5052 ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1
5053 ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1
5054 ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2
[email protected]fb661802013-03-25 01:59:325055
5056 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5057 // the root layer.
5058 gfx::Point test_point = gfx::Point(1, 1);
5059 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5060 test_point, render_surface_layer_list);
5061 ASSERT_TRUE(result_layer);
5062 EXPECT_EQ(1, result_layer->id());
5063
5064 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5065 // on top.
5066 test_point = gfx::Point(15, 15);
5067 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5068 test_point, render_surface_layer_list);
5069 ASSERT_TRUE(result_layer);
5070 EXPECT_EQ(2, result_layer->id());
5071
5072 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5073 test_point = gfx::Point(51, 20);
5074 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5075 test_point, render_surface_layer_list);
5076 ASSERT_TRUE(result_layer);
5077 EXPECT_EQ(3, result_layer->id());
5078
5079 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5080 // top.
5081 test_point = gfx::Point(80, 51);
5082 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5083 test_point, render_surface_layer_list);
5084 ASSERT_TRUE(result_layer);
5085 EXPECT_EQ(3, result_layer->id());
5086
5087 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5088 // of all other layers.
5089 test_point = gfx::Point(51, 51);
5090 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5091 test_point, render_surface_layer_list);
5092 ASSERT_TRUE(result_layer);
5093 EXPECT_EQ(3, result_layer->id());
5094
5095 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5096 // be on top.
5097 test_point = gfx::Point(20, 51);
5098 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5099 test_point, render_surface_layer_list);
5100 ASSERT_TRUE(result_layer);
5101 EXPECT_EQ(4, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145102}
5103
[email protected]989386c2013-07-18 21:37:235104TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) {
[email protected]fb661802013-03-25 01:59:325105 //
5106 // The geometry is set up similarly to the previous case, but
5107 // all layers are forced to be render surfaces now.
5108 //
5109 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455110 TestSharedBitmapManager shared_bitmap_manager;
5111 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325112 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145113
[email protected]fb661802013-03-25 01:59:325114 gfx::Transform identity_matrix;
5115 gfx::PointF anchor;
5116 gfx::PointF position;
5117 gfx::Size bounds(100, 100);
5118 SetLayerPropertiesForTesting(root.get(),
5119 identity_matrix,
[email protected]fb661802013-03-25 01:59:325120 anchor,
5121 position,
5122 bounds,
[email protected]56fffdd2014-02-11 19:50:575123 true,
[email protected]fb661802013-03-25 01:59:325124 false);
5125 root->SetDrawsContent(true);
5126 {
5127 // child 1 and child2 are initialized to overlap between x=50 and x=60.
5128 // grand_child is set to overlap both child1 and child2 between y=50 and
5129 // y=60. The expected stacking order is: (front) child2, (second)
5130 // grand_child, (third) child1, and (back) the root layer behind all other
5131 // layers.
[email protected]94f206c12012-08-25 00:09:145132
[email protected]fb661802013-03-25 01:59:325133 scoped_ptr<LayerImpl> child1 =
5134 LayerImpl::Create(host_impl.active_tree(), 2);
5135 scoped_ptr<LayerImpl> child2 =
5136 LayerImpl::Create(host_impl.active_tree(), 3);
5137 scoped_ptr<LayerImpl> grand_child1 =
5138 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:145139
[email protected]fb661802013-03-25 01:59:325140 position = gfx::PointF(10.f, 10.f);
5141 bounds = gfx::Size(50, 50);
5142 SetLayerPropertiesForTesting(child1.get(),
5143 identity_matrix,
[email protected]fb661802013-03-25 01:59:325144 anchor,
5145 position,
5146 bounds,
[email protected]56fffdd2014-02-11 19:50:575147 true,
[email protected]fb661802013-03-25 01:59:325148 false);
5149 child1->SetDrawsContent(true);
5150 child1->SetForceRenderSurface(true);
[email protected]ecc12622012-10-30 20:45:425151
[email protected]fb661802013-03-25 01:59:325152 position = gfx::PointF(50.f, 10.f);
5153 bounds = gfx::Size(50, 50);
5154 SetLayerPropertiesForTesting(child2.get(),
5155 identity_matrix,
[email protected]fb661802013-03-25 01:59:325156 anchor,
5157 position,
5158 bounds,
[email protected]56fffdd2014-02-11 19:50:575159 true,
[email protected]fb661802013-03-25 01:59:325160 false);
5161 child2->SetDrawsContent(true);
[email protected]7aba6662013-03-12 10:17:345162 child2->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015163
[email protected]fb661802013-03-25 01:59:325164 // Remember that grand_child is positioned with respect to its parent (i.e.
5165 // child1). In screen space, the intended position is (10, 50), with size
5166 // 100 x 50.
5167 position = gfx::PointF(0.f, 40.f);
5168 bounds = gfx::Size(100, 50);
5169 SetLayerPropertiesForTesting(grand_child1.get(),
5170 identity_matrix,
[email protected]fb661802013-03-25 01:59:325171 anchor,
5172 position,
5173 bounds,
[email protected]56fffdd2014-02-11 19:50:575174 true,
[email protected]fb661802013-03-25 01:59:325175 false);
5176 grand_child1->SetDrawsContent(true);
5177 grand_child1->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015178
[email protected]fb661802013-03-25 01:59:325179 child1->AddChild(grand_child1.Pass());
5180 root->AddChild(child1.Pass());
5181 root->AddChild(child2.Pass());
5182 }
[email protected]dc462d782012-11-21 21:43:015183
[email protected]fb661802013-03-25 01:59:325184 LayerImpl* child1 = root->children()[0];
5185 LayerImpl* child2 = root->children()[1];
5186 LayerImpl* grand_child1 = child1->children()[0];
[email protected]dc462d782012-11-21 21:43:015187
[email protected]50761e92013-03-29 20:51:285188 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535189 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5190 root.get(), root->bounds(), &render_surface_layer_list);
5191 inputs.can_adjust_raster_scales = true;
5192 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]dc462d782012-11-21 21:43:015193
[email protected]fb661802013-03-25 01:59:325194 // Sanity check the scenario we just created.
5195 ASSERT_TRUE(child1);
5196 ASSERT_TRUE(child2);
5197 ASSERT_TRUE(grand_child1);
5198 ASSERT_TRUE(child1->render_surface());
5199 ASSERT_TRUE(child2->render_surface());
5200 ASSERT_TRUE(grand_child1->render_surface());
5201 ASSERT_EQ(4u, render_surface_layer_list.size());
5202 // The root surface has the root layer, and child1's and child2's render
5203 // surfaces.
5204 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
5205 // The child1 surface has the child1 layer and grand_child1's render surface.
5206 ASSERT_EQ(2u, child1->render_surface()->layer_list().size());
5207 ASSERT_EQ(1u, child2->render_surface()->layer_list().size());
5208 ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235209 ASSERT_EQ(1, render_surface_layer_list.at(0)->id()); // root layer
[email protected]fb661802013-03-25 01:59:325210 ASSERT_EQ(2, render_surface_layer_list[1]->id()); // child1
[email protected]989386c2013-07-18 21:37:235211 ASSERT_EQ(4, render_surface_layer_list.at(2)->id()); // grand_child1
[email protected]fb661802013-03-25 01:59:325212 ASSERT_EQ(3, render_surface_layer_list[3]->id()); // child2
[email protected]dc462d782012-11-21 21:43:015213
[email protected]fb661802013-03-25 01:59:325214 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5215 // the root layer.
5216 gfx::Point test_point = gfx::Point(1, 1);
5217 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5218 test_point, render_surface_layer_list);
5219 ASSERT_TRUE(result_layer);
5220 EXPECT_EQ(1, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015221
[email protected]fb661802013-03-25 01:59:325222 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5223 // on top.
5224 test_point = gfx::Point(15, 15);
5225 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5226 test_point, render_surface_layer_list);
5227 ASSERT_TRUE(result_layer);
5228 EXPECT_EQ(2, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015229
[email protected]fb661802013-03-25 01:59:325230 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5231 test_point = gfx::Point(51, 20);
5232 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5233 test_point, render_surface_layer_list);
5234 ASSERT_TRUE(result_layer);
5235 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015236
[email protected]fb661802013-03-25 01:59:325237 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5238 // top.
5239 test_point = gfx::Point(80, 51);
5240 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5241 test_point, render_surface_layer_list);
5242 ASSERT_TRUE(result_layer);
5243 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015244
[email protected]fb661802013-03-25 01:59:325245 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5246 // of all other layers.
5247 test_point = gfx::Point(51, 51);
5248 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5249 test_point, render_surface_layer_list);
5250 ASSERT_TRUE(result_layer);
5251 EXPECT_EQ(3, result_layer->id());
5252
5253 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5254 // be on top.
5255 test_point = gfx::Point(20, 51);
5256 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5257 test_point, render_surface_layer_list);
5258 ASSERT_TRUE(result_layer);
5259 EXPECT_EQ(4, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015260}
5261
[email protected]afc4f262013-10-05 01:14:105262TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayers) {
5263 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455264 TestSharedBitmapManager shared_bitmap_manager;
5265 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]afc4f262013-10-05 01:14:105266
5267 // Layer 1 - root
5268 scoped_ptr<LayerImpl> root =
5269 LayerImpl::Create(host_impl.active_tree(), 1);
5270 gfx::Transform identity_matrix;
5271 gfx::PointF anchor;
5272 gfx::PointF position;
5273 gfx::Size bounds(100, 100);
5274 SetLayerPropertiesForTesting(root.get(),
5275 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105276 anchor,
5277 position,
5278 bounds,
[email protected]56fffdd2014-02-11 19:50:575279 true,
[email protected]afc4f262013-10-05 01:14:105280 false);
5281 root->SetDrawsContent(true);
5282
5283 {
5284 // Layer 2 - empty: drawsContent=false
5285 gfx::PointF position(10.f, 10.f);
5286 gfx::Size bounds(30, 30);
5287 scoped_ptr<LayerImpl> empty_layer =
5288 LayerImpl::Create(host_impl.active_tree(), 2);
5289 SetLayerPropertiesForTesting(empty_layer.get(),
5290 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105291 anchor,
5292 position,
5293 bounds,
[email protected]56fffdd2014-02-11 19:50:575294 true,
[email protected]afc4f262013-10-05 01:14:105295 false);
5296
5297 empty_layer->SetDrawsContent(false);
5298 root->AddChild(empty_layer.Pass());
5299 }
5300
5301 {
5302 // Layer 3 - empty, but has touch handler
5303 gfx::PointF position(10.f, 60.f);
5304 gfx::Size bounds(30, 30);
5305 scoped_ptr<LayerImpl> test_layer =
5306 LayerImpl::Create(host_impl.active_tree(), 3);
5307 SetLayerPropertiesForTesting(test_layer.get(),
5308 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105309 anchor,
5310 position,
5311 bounds,
[email protected]56fffdd2014-02-11 19:50:575312 true,
[email protected]afc4f262013-10-05 01:14:105313 false);
5314
5315 test_layer->SetDrawsContent(false);
5316 Region touch_handler_region(gfx::Rect(10, 10, 10, 10));
5317 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5318 root->AddChild(test_layer.Pass());
5319 }
5320
5321 {
5322 // Layer 4 - empty, but has mousewheel handler
5323 gfx::PointF position(60.f, 60.f);
5324 gfx::Size bounds(30, 30);
5325 scoped_ptr<LayerImpl> test_layer =
5326 LayerImpl::Create(host_impl.active_tree(), 4);
5327 SetLayerPropertiesForTesting(test_layer.get(),
5328 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105329 anchor,
5330 position,
5331 bounds,
[email protected]56fffdd2014-02-11 19:50:575332 true,
[email protected]afc4f262013-10-05 01:14:105333 false);
5334
5335 test_layer->SetDrawsContent(false);
5336 test_layer->SetHaveWheelEventHandlers(true);
5337 root->AddChild(test_layer.Pass());
5338 }
5339
5340 LayerImplList render_surface_layer_list;
5341 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5342 root.get(), root->bounds(), &render_surface_layer_list);
5343 inputs.can_adjust_raster_scales = true;
5344 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5345
5346 // Verify that the root layer and empty layers with touch/wheel handlers
5347 // (but not the empty layer without a touch handler) are in the RSSL.
5348 ASSERT_EQ(1u, render_surface_layer_list.size());
5349 EXPECT_EQ(1, render_surface_layer_list[0]->id());
[email protected]22538a2d2013-11-12 11:24:455350 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
[email protected]afc4f262013-10-05 01:14:105351 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]22538a2d2013-11-12 11:24:455352 EXPECT_EQ(3, root->render_surface()->layer_list().at(1)->id());
5353 EXPECT_EQ(4, root->render_surface()->layer_list().at(2)->id());
[email protected]afc4f262013-10-05 01:14:105354
5355 // Hit testing for a point inside the empty no-handlers layer should return
5356 // the root layer.
5357 gfx::Point test_point = gfx::Point(15, 15);
5358 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5359 test_point, render_surface_layer_list);
5360 ASSERT_TRUE(result_layer);
[email protected]22538a2d2013-11-12 11:24:455361 EXPECT_EQ(1, result_layer->id());
[email protected]afc4f262013-10-05 01:14:105362
5363 // Hit testing for a point inside the touch handler layer should return it.
5364 test_point = gfx::Point(15, 75);
5365 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5366 test_point, render_surface_layer_list);
5367 ASSERT_TRUE(result_layer);
5368 EXPECT_EQ(3, result_layer->id());
5369
5370 // Hit testing for a point inside the mousewheel layer should return it.
5371 test_point = gfx::Point(75, 75);
5372 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5373 test_point, render_surface_layer_list);
5374 ASSERT_TRUE(result_layer);
5375 EXPECT_EQ(4, result_layer->id());
5376}
5377
[email protected]989386c2013-07-18 21:37:235378TEST_F(LayerTreeHostCommonTest,
5379 HitCheckingTouchHandlerRegionsForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:325380 // Hit checking on an empty render_surface_layer_list should return a null
5381 // pointer.
[email protected]50761e92013-03-29 20:51:285382 LayerImplList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145383
[email protected]fb661802013-03-25 01:59:325384 gfx::Point test_point(0, 0);
5385 LayerImpl* result_layer =
5386 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5387 test_point, render_surface_layer_list);
5388 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145389
[email protected]fb661802013-03-25 01:59:325390 test_point = gfx::Point(10, 20);
5391 result_layer =
5392 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5393 test_point, render_surface_layer_list);
5394 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145395}
5396
[email protected]989386c2013-07-18 21:37:235397TEST_F(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:325398 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455399 TestSharedBitmapManager shared_bitmap_manager;
5400 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325401 scoped_ptr<LayerImpl> root =
5402 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145403
[email protected]fb661802013-03-25 01:59:325404 gfx::Transform identity_matrix;
5405 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5406 gfx::PointF anchor;
5407 gfx::PointF position;
5408 gfx::Size bounds(100, 100);
5409 SetLayerPropertiesForTesting(root.get(),
5410 identity_matrix,
[email protected]fb661802013-03-25 01:59:325411 anchor,
5412 position,
5413 bounds,
[email protected]56fffdd2014-02-11 19:50:575414 true,
[email protected]fb661802013-03-25 01:59:325415 false);
5416 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145417
[email protected]50761e92013-03-29 20:51:285418 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535419 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5420 root.get(), root->bounds(), &render_surface_layer_list);
5421 inputs.can_adjust_raster_scales = true;
5422 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145423
[email protected]fb661802013-03-25 01:59:325424 // Sanity check the scenario we just created.
5425 ASSERT_EQ(1u, render_surface_layer_list.size());
5426 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145427
[email protected]fb661802013-03-25 01:59:325428 // Hit checking for any point should return a null pointer for a layer without
5429 // any touch event handler regions.
5430 gfx::Point test_point(11, 11);
5431 LayerImpl* result_layer =
5432 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5433 test_point, render_surface_layer_list);
5434 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145435
[email protected]fb661802013-03-25 01:59:325436 root->SetTouchEventHandlerRegion(touch_handler_region);
5437 // Hit checking for a point outside the layer should return a null pointer.
5438 test_point = gfx::Point(101, 101);
5439 result_layer =
5440 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5441 test_point, render_surface_layer_list);
5442 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145443
[email protected]fb661802013-03-25 01:59:325444 test_point = gfx::Point(-1, -1);
5445 result_layer =
5446 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5447 test_point, render_surface_layer_list);
5448 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145449
[email protected]fb661802013-03-25 01:59:325450 // Hit checking for a point inside the layer, but outside the touch handler
5451 // region should return a null pointer.
5452 test_point = gfx::Point(1, 1);
5453 result_layer =
5454 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5455 test_point, render_surface_layer_list);
5456 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145457
[email protected]fb661802013-03-25 01:59:325458 test_point = gfx::Point(99, 99);
5459 result_layer =
5460 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5461 test_point, render_surface_layer_list);
5462 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145463
[email protected]fb661802013-03-25 01:59:325464 // Hit checking for a point inside the touch event handler region should
5465 // return the root layer.
5466 test_point = gfx::Point(11, 11);
5467 result_layer =
5468 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5469 test_point, render_surface_layer_list);
5470 ASSERT_TRUE(result_layer);
5471 EXPECT_EQ(12345, result_layer->id());
5472
5473 test_point = gfx::Point(59, 59);
5474 result_layer =
5475 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5476 test_point, render_surface_layer_list);
5477 ASSERT_TRUE(result_layer);
5478 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145479}
5480
[email protected]989386c2013-07-18 21:37:235481TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325482 HitCheckingTouchHandlerRegionsForUninvertibleTransform) {
5483 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455484 TestSharedBitmapManager shared_bitmap_manager;
5485 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325486 scoped_ptr<LayerImpl> root =
5487 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145488
[email protected]fb661802013-03-25 01:59:325489 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:265490 uninvertible_transform.matrix().set(0, 0, 0.0);
5491 uninvertible_transform.matrix().set(1, 1, 0.0);
5492 uninvertible_transform.matrix().set(2, 2, 0.0);
5493 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:325494 ASSERT_FALSE(uninvertible_transform.IsInvertible());
[email protected]94f206c12012-08-25 00:09:145495
[email protected]fb661802013-03-25 01:59:325496 gfx::Transform identity_matrix;
5497 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5498 gfx::PointF anchor;
5499 gfx::PointF position;
5500 gfx::Size bounds(100, 100);
5501 SetLayerPropertiesForTesting(root.get(),
5502 uninvertible_transform,
[email protected]fb661802013-03-25 01:59:325503 anchor,
5504 position,
5505 bounds,
[email protected]56fffdd2014-02-11 19:50:575506 true,
[email protected]fb661802013-03-25 01:59:325507 false);
5508 root->SetDrawsContent(true);
5509 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145510
[email protected]50761e92013-03-29 20:51:285511 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535512 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5513 root.get(), root->bounds(), &render_surface_layer_list);
5514 inputs.can_adjust_raster_scales = true;
5515 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145516
[email protected]fb661802013-03-25 01:59:325517 // Sanity check the scenario we just created.
5518 ASSERT_EQ(1u, render_surface_layer_list.size());
5519 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5520 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
[email protected]de4afb5e2012-12-20 00:11:345521
[email protected]fb661802013-03-25 01:59:325522 // Hit checking any point should not hit the touch handler region on the
5523 // layer. If the invertible matrix is accidentally ignored and treated like an
5524 // identity, then the hit testing will incorrectly hit the layer when it
5525 // shouldn't.
5526 gfx::Point test_point(1, 1);
5527 LayerImpl* result_layer =
5528 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5529 test_point, render_surface_layer_list);
5530 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345531
[email protected]fb661802013-03-25 01:59:325532 test_point = gfx::Point(10, 10);
5533 result_layer =
5534 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5535 test_point, render_surface_layer_list);
5536 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345537
[email protected]fb661802013-03-25 01:59:325538 test_point = gfx::Point(10, 30);
5539 result_layer =
5540 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5541 test_point, render_surface_layer_list);
5542 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345543
[email protected]fb661802013-03-25 01:59:325544 test_point = gfx::Point(50, 50);
5545 result_layer =
5546 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5547 test_point, render_surface_layer_list);
5548 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145549
[email protected]fb661802013-03-25 01:59:325550 test_point = gfx::Point(67, 48);
5551 result_layer =
5552 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5553 test_point, render_surface_layer_list);
5554 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145555
[email protected]fb661802013-03-25 01:59:325556 test_point = gfx::Point(99, 99);
5557 result_layer =
5558 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5559 test_point, render_surface_layer_list);
5560 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145561
[email protected]fb661802013-03-25 01:59:325562 test_point = gfx::Point(-1, -1);
5563 result_layer =
5564 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5565 test_point, render_surface_layer_list);
5566 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145567}
5568
[email protected]989386c2013-07-18 21:37:235569TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325570 HitCheckingTouchHandlerRegionsForSinglePositionedLayer) {
5571 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455572 TestSharedBitmapManager shared_bitmap_manager;
5573 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325574 scoped_ptr<LayerImpl> root =
5575 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145576
[email protected]fb661802013-03-25 01:59:325577 gfx::Transform identity_matrix;
5578 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5579 gfx::PointF anchor;
5580 // this layer is positioned, and hit testing should correctly know where the
5581 // layer is located.
5582 gfx::PointF position(50.f, 50.f);
5583 gfx::Size bounds(100, 100);
5584 SetLayerPropertiesForTesting(root.get(),
5585 identity_matrix,
[email protected]fb661802013-03-25 01:59:325586 anchor,
5587 position,
5588 bounds,
[email protected]56fffdd2014-02-11 19:50:575589 true,
[email protected]fb661802013-03-25 01:59:325590 false);
5591 root->SetDrawsContent(true);
5592 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145593
[email protected]50761e92013-03-29 20:51:285594 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535595 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5596 root.get(), root->bounds(), &render_surface_layer_list);
5597 inputs.can_adjust_raster_scales = true;
5598 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145599
[email protected]fb661802013-03-25 01:59:325600 // Sanity check the scenario we just created.
5601 ASSERT_EQ(1u, render_surface_layer_list.size());
5602 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145603
[email protected]fb661802013-03-25 01:59:325604 // Hit checking for a point outside the layer should return a null pointer.
5605 gfx::Point test_point(49, 49);
5606 LayerImpl* result_layer =
5607 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5608 test_point, render_surface_layer_list);
5609 EXPECT_FALSE(result_layer);
5610
5611 // Even though the layer has a touch handler region containing (101, 101), it
5612 // should not be visible there since the root render surface would clamp it.
5613 test_point = gfx::Point(101, 101);
5614 result_layer =
5615 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5616 test_point, render_surface_layer_list);
5617 EXPECT_FALSE(result_layer);
5618
5619 // Hit checking for a point inside the layer, but outside the touch handler
5620 // region should return a null pointer.
5621 test_point = gfx::Point(51, 51);
5622 result_layer =
5623 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5624 test_point, render_surface_layer_list);
5625 EXPECT_FALSE(result_layer);
5626
5627 // Hit checking for a point inside the touch event handler region should
5628 // return the root layer.
5629 test_point = gfx::Point(61, 61);
5630 result_layer =
5631 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5632 test_point, render_surface_layer_list);
5633 ASSERT_TRUE(result_layer);
5634 EXPECT_EQ(12345, result_layer->id());
5635
5636 test_point = gfx::Point(99, 99);
5637 result_layer =
5638 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5639 test_point, render_surface_layer_list);
5640 ASSERT_TRUE(result_layer);
5641 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145642}
5643
[email protected]989386c2013-07-18 21:37:235644TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325645 HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) {
5646 // A layer's visible content rect is actually in the layer's content space.
5647 // The screen space transform converts from the layer's origin space to screen
5648 // space. This test makes sure that hit testing works correctly accounts for
5649 // the contents scale. A contents scale that is not 1 effectively forces a
5650 // non-identity transform between layer's content space and layer's origin
5651 // space. The hit testing code must take this into account.
5652 //
5653 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
5654 // contents scale is ignored, then hit checking will mis-interpret the visible
5655 // content rect as being larger than the actual bounds of the layer.
5656 //
5657 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455658 TestSharedBitmapManager shared_bitmap_manager;
5659 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325660 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145661
[email protected]fb661802013-03-25 01:59:325662 gfx::Transform identity_matrix;
5663 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145664
[email protected]fb661802013-03-25 01:59:325665 SetLayerPropertiesForTesting(root.get(),
5666 identity_matrix,
[email protected]fb661802013-03-25 01:59:325667 anchor,
5668 gfx::PointF(),
5669 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575670 true,
[email protected]fb661802013-03-25 01:59:325671 false);
5672 {
5673 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5674 gfx::PointF position(25.f, 25.f);
5675 gfx::Size bounds(50, 50);
5676 scoped_ptr<LayerImpl> test_layer =
5677 LayerImpl::Create(host_impl.active_tree(), 12345);
5678 SetLayerPropertiesForTesting(test_layer.get(),
5679 identity_matrix,
[email protected]fb661802013-03-25 01:59:325680 anchor,
5681 position,
5682 bounds,
[email protected]56fffdd2014-02-11 19:50:575683 true,
[email protected]fb661802013-03-25 01:59:325684 false);
[email protected]94f206c12012-08-25 00:09:145685
[email protected]fb661802013-03-25 01:59:325686 // override content bounds and contents scale
5687 test_layer->SetContentBounds(gfx::Size(100, 100));
5688 test_layer->SetContentsScale(2, 2);
[email protected]94f206c12012-08-25 00:09:145689
[email protected]fb661802013-03-25 01:59:325690 test_layer->SetDrawsContent(true);
5691 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5692 root->AddChild(test_layer.Pass());
5693 }
5694
[email protected]50761e92013-03-29 20:51:285695 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535696 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5697 root.get(), root->bounds(), &render_surface_layer_list);
5698 inputs.can_adjust_raster_scales = true;
5699 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325700
5701 // Sanity check the scenario we just created.
5702 // The visible content rect for test_layer is actually 100x100, even though
5703 // its layout size is 50x50, positioned at 25x25.
5704 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:055705 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect());
[email protected]fb661802013-03-25 01:59:325706 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455707 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:325708
5709 // Hit checking for a point outside the layer should return a null pointer
5710 // (the root layer does not draw content, so it will not be tested either).
5711 gfx::Point test_point(76, 76);
5712 LayerImpl* result_layer =
5713 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5714 test_point, render_surface_layer_list);
5715 EXPECT_FALSE(result_layer);
5716
5717 // Hit checking for a point inside the layer, but outside the touch handler
5718 // region should return a null pointer.
5719 test_point = gfx::Point(26, 26);
5720 result_layer =
5721 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5722 test_point, render_surface_layer_list);
5723 EXPECT_FALSE(result_layer);
5724
5725 test_point = gfx::Point(34, 34);
5726 result_layer =
5727 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5728 test_point, render_surface_layer_list);
5729 EXPECT_FALSE(result_layer);
5730
5731 test_point = gfx::Point(65, 65);
5732 result_layer =
5733 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5734 test_point, render_surface_layer_list);
5735 EXPECT_FALSE(result_layer);
5736
5737 test_point = gfx::Point(74, 74);
5738 result_layer =
5739 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5740 test_point, render_surface_layer_list);
5741 EXPECT_FALSE(result_layer);
5742
5743 // Hit checking for a point inside the touch event handler region should
5744 // return the root layer.
5745 test_point = gfx::Point(35, 35);
5746 result_layer =
5747 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5748 test_point, render_surface_layer_list);
5749 ASSERT_TRUE(result_layer);
5750 EXPECT_EQ(12345, result_layer->id());
5751
5752 test_point = gfx::Point(64, 64);
5753 result_layer =
5754 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5755 test_point, render_surface_layer_list);
5756 ASSERT_TRUE(result_layer);
5757 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145758}
5759
[email protected]989386c2013-07-18 21:37:235760TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325761 HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) {
5762 // The layer's device_scale_factor and page_scale_factor should scale the
5763 // content rect and we should be able to hit the touch handler region by
5764 // scaling the points accordingly.
5765 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455766 TestSharedBitmapManager shared_bitmap_manager;
5767 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325768 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145769
[email protected]fb661802013-03-25 01:59:325770 gfx::Transform identity_matrix;
5771 gfx::PointF anchor;
5772 // Set the bounds of the root layer big enough to fit the child when scaled.
5773 SetLayerPropertiesForTesting(root.get(),
5774 identity_matrix,
[email protected]fb661802013-03-25 01:59:325775 anchor,
5776 gfx::PointF(),
5777 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575778 true,
[email protected]fb661802013-03-25 01:59:325779 false);
5780 {
5781 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5782 gfx::PointF position(25.f, 25.f);
5783 gfx::Size bounds(50, 50);
5784 scoped_ptr<LayerImpl> test_layer =
5785 LayerImpl::Create(host_impl.active_tree(), 12345);
5786 SetLayerPropertiesForTesting(test_layer.get(),
5787 identity_matrix,
[email protected]fb661802013-03-25 01:59:325788 anchor,
5789 position,
5790 bounds,
[email protected]56fffdd2014-02-11 19:50:575791 true,
[email protected]fb661802013-03-25 01:59:325792 false);
[email protected]94f206c12012-08-25 00:09:145793
[email protected]fb661802013-03-25 01:59:325794 test_layer->SetDrawsContent(true);
5795 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5796 root->AddChild(test_layer.Pass());
5797 }
[email protected]94f206c12012-08-25 00:09:145798
[email protected]50761e92013-03-29 20:51:285799 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:325800 float device_scale_factor = 3.f;
5801 float page_scale_factor = 5.f;
[email protected]fb661802013-03-25 01:59:325802 gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize(
5803 gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor));
[email protected]7aad55f2013-07-26 11:25:535804
5805 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5806 root.get(), scaled_bounds_for_root, &render_surface_layer_list);
5807 inputs.device_scale_factor = device_scale_factor;
5808 inputs.page_scale_factor = page_scale_factor;
5809 inputs.page_scale_application_layer = root.get();
5810 inputs.can_adjust_raster_scales = true;
5811 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145812
[email protected]fb661802013-03-25 01:59:325813 // Sanity check the scenario we just created.
5814 // The visible content rect for test_layer is actually 100x100, even though
5815 // its layout size is 50x50, positioned at 25x25.
5816 LayerImpl* test_layer = root->children()[0];
5817 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455818 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145819
[email protected]fb661802013-03-25 01:59:325820 // Check whether the child layer fits into the root after scaled.
5821 EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()),
5822 test_layer->visible_content_rect());
5823
5824 // Hit checking for a point outside the layer should return a null pointer
5825 // (the root layer does not draw content, so it will not be tested either).
5826 gfx::PointF test_point(76.f, 76.f);
5827 test_point =
5828 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5829 LayerImpl* result_layer =
5830 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5831 test_point, render_surface_layer_list);
5832 EXPECT_FALSE(result_layer);
5833
5834 // Hit checking for a point inside the layer, but outside the touch handler
5835 // region should return a null pointer.
5836 test_point = gfx::Point(26, 26);
5837 test_point =
5838 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5839 result_layer =
5840 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5841 test_point, render_surface_layer_list);
5842 EXPECT_FALSE(result_layer);
5843
5844 test_point = gfx::Point(34, 34);
5845 test_point =
5846 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5847 result_layer =
5848 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5849 test_point, render_surface_layer_list);
5850 EXPECT_FALSE(result_layer);
5851
5852 test_point = gfx::Point(65, 65);
5853 test_point =
5854 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5855 result_layer =
5856 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5857 test_point, render_surface_layer_list);
5858 EXPECT_FALSE(result_layer);
5859
5860 test_point = gfx::Point(74, 74);
5861 test_point =
5862 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5863 result_layer =
5864 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5865 test_point, render_surface_layer_list);
5866 EXPECT_FALSE(result_layer);
5867
5868 // Hit checking for a point inside the touch event handler region should
5869 // return the root layer.
5870 test_point = gfx::Point(35, 35);
5871 test_point =
5872 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5873 result_layer =
5874 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5875 test_point, render_surface_layer_list);
5876 ASSERT_TRUE(result_layer);
5877 EXPECT_EQ(12345, result_layer->id());
5878
5879 test_point = gfx::Point(64, 64);
5880 test_point =
5881 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5882 result_layer =
5883 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5884 test_point, render_surface_layer_list);
5885 ASSERT_TRUE(result_layer);
5886 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145887}
5888
[email protected]989386c2013-07-18 21:37:235889TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325890 HitCheckingTouchHandlerRegionsForSimpleClippedLayer) {
5891 // Test that hit-checking will only work for the visible portion of a layer,
5892 // and not the entire layer bounds. Here we just test the simple axis-aligned
5893 // case.
5894 gfx::Transform identity_matrix;
5895 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145896
[email protected]fb661802013-03-25 01:59:325897 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455898 TestSharedBitmapManager shared_bitmap_manager;
5899 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325900 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5901 SetLayerPropertiesForTesting(root.get(),
5902 identity_matrix,
[email protected]fb661802013-03-25 01:59:325903 anchor,
5904 gfx::PointF(),
5905 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575906 true,
[email protected]fb661802013-03-25 01:59:325907 false);
5908 {
5909 scoped_ptr<LayerImpl> clipping_layer =
5910 LayerImpl::Create(host_impl.active_tree(), 123);
5911 // this layer is positioned, and hit testing should correctly know where the
5912 // layer is located.
5913 gfx::PointF position(25.f, 25.f);
5914 gfx::Size bounds(50, 50);
5915 SetLayerPropertiesForTesting(clipping_layer.get(),
5916 identity_matrix,
[email protected]fb661802013-03-25 01:59:325917 anchor,
5918 position,
5919 bounds,
[email protected]56fffdd2014-02-11 19:50:575920 true,
[email protected]fb661802013-03-25 01:59:325921 false);
5922 clipping_layer->SetMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:145923
[email protected]fb661802013-03-25 01:59:325924 scoped_ptr<LayerImpl> child =
5925 LayerImpl::Create(host_impl.active_tree(), 456);
5926 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5927 position = gfx::PointF(-50.f, -50.f);
5928 bounds = gfx::Size(300, 300);
5929 SetLayerPropertiesForTesting(child.get(),
5930 identity_matrix,
[email protected]fb661802013-03-25 01:59:325931 anchor,
5932 position,
5933 bounds,
[email protected]56fffdd2014-02-11 19:50:575934 true,
[email protected]fb661802013-03-25 01:59:325935 false);
5936 child->SetDrawsContent(true);
5937 child->SetTouchEventHandlerRegion(touch_handler_region);
5938 clipping_layer->AddChild(child.Pass());
5939 root->AddChild(clipping_layer.Pass());
5940 }
[email protected]94f206c12012-08-25 00:09:145941
[email protected]50761e92013-03-29 20:51:285942 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535943 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5944 root.get(), root->bounds(), &render_surface_layer_list);
5945 inputs.can_adjust_raster_scales = true;
5946 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325947
5948 // Sanity check the scenario we just created.
5949 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455950 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5951 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:325952
5953 // Hit checking for a point outside the layer should return a null pointer.
5954 // Despite the child layer being very large, it should be clipped to the root
5955 // layer's bounds.
5956 gfx::Point test_point(24, 24);
5957 LayerImpl* result_layer =
5958 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5959 test_point, render_surface_layer_list);
5960 EXPECT_FALSE(result_layer);
5961
5962 // Hit checking for a point inside the layer, but outside the touch handler
5963 // region should return a null pointer.
5964 test_point = gfx::Point(35, 35);
5965 result_layer =
5966 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5967 test_point, render_surface_layer_list);
5968 EXPECT_FALSE(result_layer);
5969
5970 test_point = gfx::Point(74, 74);
5971 result_layer =
5972 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5973 test_point, render_surface_layer_list);
5974 EXPECT_FALSE(result_layer);
5975
5976 // Hit checking for a point inside the touch event handler region should
5977 // return the root layer.
5978 test_point = gfx::Point(25, 25);
5979 result_layer =
5980 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5981 test_point, render_surface_layer_list);
5982 ASSERT_TRUE(result_layer);
5983 EXPECT_EQ(456, result_layer->id());
5984
5985 test_point = gfx::Point(34, 34);
5986 result_layer =
5987 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5988 test_point, render_surface_layer_list);
5989 ASSERT_TRUE(result_layer);
5990 EXPECT_EQ(456, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145991}
5992
[email protected]c974d5d2013-10-24 01:02:485993TEST_F(LayerTreeHostCommonTest,
5994 HitCheckingTouchHandlerOverlappingRegions) {
5995 gfx::Transform identity_matrix;
5996 gfx::PointF anchor;
5997
5998 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455999 TestSharedBitmapManager shared_bitmap_manager;
6000 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c974d5d2013-10-24 01:02:486001 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
6002 SetLayerPropertiesForTesting(root.get(),
6003 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:486004 anchor,
6005 gfx::PointF(),
6006 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576007 true,
[email protected]c974d5d2013-10-24 01:02:486008 false);
6009 {
6010 scoped_ptr<LayerImpl> touch_layer =
6011 LayerImpl::Create(host_impl.active_tree(), 123);
6012 // this layer is positioned, and hit testing should correctly know where the
6013 // layer is located.
6014 gfx::PointF position;
6015 gfx::Size bounds(50, 50);
6016 SetLayerPropertiesForTesting(touch_layer.get(),
6017 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:486018 anchor,
6019 position,
6020 bounds,
[email protected]56fffdd2014-02-11 19:50:576021 true,
[email protected]c974d5d2013-10-24 01:02:486022 false);
6023 touch_layer->SetDrawsContent(true);
6024 touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50));
6025 root->AddChild(touch_layer.Pass());
6026 }
6027
6028 {
6029 scoped_ptr<LayerImpl> notouch_layer =
6030 LayerImpl::Create(host_impl.active_tree(), 1234);
6031 // this layer is positioned, and hit testing should correctly know where the
6032 // layer is located.
6033 gfx::PointF position(0, 25);
6034 gfx::Size bounds(50, 50);
6035 SetLayerPropertiesForTesting(notouch_layer.get(),
6036 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:486037 anchor,
6038 position,
6039 bounds,
[email protected]56fffdd2014-02-11 19:50:576040 true,
[email protected]c974d5d2013-10-24 01:02:486041 false);
6042 notouch_layer->SetDrawsContent(true);
6043 root->AddChild(notouch_layer.Pass());
6044 }
6045
6046 LayerImplList render_surface_layer_list;
6047 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6048 root.get(), root->bounds(), &render_surface_layer_list);
6049 inputs.can_adjust_raster_scales = true;
6050 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6051
6052 // Sanity check the scenario we just created.
6053 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:456054 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
6055 ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id());
6056 ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id());
[email protected]c974d5d2013-10-24 01:02:486057
6058 gfx::Point test_point(35, 35);
6059 LayerImpl* result_layer =
6060 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6061 test_point, render_surface_layer_list);
[email protected]5183605e2014-04-17 03:57:186062
6063 // We should have passed through the no-touch layer and found the layer
6064 // behind it.
6065 EXPECT_TRUE(result_layer);
6066
6067 host_impl.active_tree()->LayerById(1234)->SetContentsOpaque(true);
6068 result_layer =
6069 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6070 test_point, render_surface_layer_list);
6071
[email protected]489eb99892014-04-27 00:27:346072 // Even with an opaque layer in the middle, we should still find the layer
6073 // with
6074 // the touch handler behind it (since we can't assume that opaque layers are
6075 // opaque to hit testing).
6076 EXPECT_TRUE(result_layer);
[email protected]c974d5d2013-10-24 01:02:486077
6078 test_point = gfx::Point(35, 15);
6079 result_layer =
6080 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6081 test_point, render_surface_layer_list);
6082 ASSERT_TRUE(result_layer);
6083 EXPECT_EQ(123, result_layer->id());
6084
6085 test_point = gfx::Point(35, 65);
6086 result_layer =
6087 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6088 test_point, render_surface_layer_list);
6089 EXPECT_FALSE(result_layer);
6090}
6091
[email protected]fb661802013-03-25 01:59:326092class NoScaleContentLayer : public ContentLayer {
6093 public:
6094 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
6095 return make_scoped_refptr(new NoScaleContentLayer(client));
6096 }
[email protected]94f206c12012-08-25 00:09:146097
[email protected]fb661802013-03-25 01:59:326098 virtual void CalculateContentsScale(float ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066099 float device_scale_factor,
6100 float page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:226101 float maximum_animation_contents_scale,
[email protected]fb661802013-03-25 01:59:326102 bool animating_transform_to_screen,
6103 float* contents_scale_x,
6104 float* contents_scale_y,
6105 gfx::Size* content_bounds) OVERRIDE {
6106 // Skip over the ContentLayer to the base Layer class.
6107 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066108 device_scale_factor,
6109 page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:226110 maximum_animation_contents_scale,
[email protected]fb661802013-03-25 01:59:326111 animating_transform_to_screen,
6112 contents_scale_x,
6113 contents_scale_y,
6114 content_bounds);
6115 }
[email protected]94f206c12012-08-25 00:09:146116
[email protected]fb661802013-03-25 01:59:326117 protected:
6118 explicit NoScaleContentLayer(ContentLayerClient* client)
6119 : ContentLayer(client) {}
6120 virtual ~NoScaleContentLayer() {}
[email protected]518ee582012-10-24 18:29:446121};
6122
[email protected]fb661802013-03-25 01:59:326123scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
6124 ContentLayerClient* delegate) {
6125 scoped_refptr<NoScaleContentLayer> to_return =
6126 NoScaleContentLayer::Create(delegate);
6127 to_return->SetIsDrawable(true);
6128 return to_return;
[email protected]518ee582012-10-24 18:29:446129}
6130
[email protected]989386c2013-07-18 21:37:236131TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326132 // Verify draw and screen space transforms of layers not in a surface.
6133 MockContentLayerClient delegate;
6134 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:146135
[email protected]fb661802013-03-25 01:59:326136 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6137 SetLayerPropertiesForTesting(parent.get(),
6138 identity_matrix,
[email protected]fb661802013-03-25 01:59:326139 gfx::PointF(),
6140 gfx::PointF(),
6141 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576142 false,
[email protected]fb661802013-03-25 01:59:326143 true);
[email protected]94f206c12012-08-25 00:09:146144
[email protected]fb661802013-03-25 01:59:326145 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6146 SetLayerPropertiesForTesting(child.get(),
6147 identity_matrix,
[email protected]fb661802013-03-25 01:59:326148 gfx::PointF(),
6149 gfx::PointF(2.f, 2.f),
6150 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576151 false,
[email protected]fb661802013-03-25 01:59:326152 true);
[email protected]94f206c12012-08-25 00:09:146153
[email protected]fb661802013-03-25 01:59:326154 scoped_refptr<ContentLayer> child_empty =
6155 CreateDrawableContentLayer(&delegate);
6156 SetLayerPropertiesForTesting(child_empty.get(),
6157 identity_matrix,
[email protected]fb661802013-03-25 01:59:326158 gfx::PointF(),
6159 gfx::PointF(2.f, 2.f),
6160 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576161 false,
[email protected]fb661802013-03-25 01:59:326162 true);
[email protected]f89f5632012-11-14 23:34:456163
[email protected]fb661802013-03-25 01:59:326164 scoped_refptr<NoScaleContentLayer> child_no_scale =
6165 CreateNoScaleDrawableContentLayer(&delegate);
6166 SetLayerPropertiesForTesting(child_no_scale.get(),
6167 identity_matrix,
[email protected]fb661802013-03-25 01:59:326168 gfx::PointF(),
6169 gfx::PointF(2.f, 2.f),
6170 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576171 false,
[email protected]fb661802013-03-25 01:59:326172 true);
[email protected]94f206c12012-08-25 00:09:146173
[email protected]fb661802013-03-25 01:59:326174 parent->AddChild(child);
6175 parent->AddChild(child_empty);
6176 parent->AddChild(child_no_scale);
[email protected]94f206c12012-08-25 00:09:146177
[email protected]d600df7d2013-08-03 02:34:286178 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6179 host->SetRootLayer(parent);
6180
[email protected]fb661802013-03-25 01:59:326181 float device_scale_factor = 2.5f;
6182 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:146183
[email protected]7aad55f2013-07-26 11:25:536184 RenderSurfaceLayerList render_surface_layer_list;
6185 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6186 parent.get(), parent->bounds(), &render_surface_layer_list);
6187 inputs.device_scale_factor = device_scale_factor;
6188 inputs.page_scale_factor = page_scale_factor;
6189 inputs.can_adjust_raster_scales = true;
6190 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446191
[email protected]fb661802013-03-25 01:59:326192 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6193 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6194 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6195 child_empty);
6196 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]94f206c12012-08-25 00:09:146197
[email protected]fb661802013-03-25 01:59:326198 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:146199
[email protected]fb661802013-03-25 01:59:326200 // Verify parent transforms
6201 gfx::Transform expected_parent_transform;
6202 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6203 parent->screen_space_transform());
6204 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6205 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:146206
[email protected]fb661802013-03-25 01:59:326207 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056208 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:146209
[email protected]fb661802013-03-25 01:59:326210 gfx::RectF parent_draw_rect =
6211 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6212 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6213 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:146214
[email protected]2c7c6702013-03-26 03:14:056215 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326216 expected_parent_draw_rect.Scale(device_scale_factor);
6217 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6218 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146219
[email protected]fb661802013-03-25 01:59:326220 // Verify child and child_empty transforms. They should match.
6221 gfx::Transform expected_child_transform;
6222 expected_child_transform.Translate(
6223 device_scale_factor * child->position().x(),
6224 device_scale_factor * child->position().y());
6225 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6226 child->draw_transform());
6227 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6228 child->screen_space_transform());
6229 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6230 child_empty->draw_transform());
6231 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6232 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146233
[email protected]fb661802013-03-25 01:59:326234 // Verify results of transformed child and child_empty rects. They should
6235 // match.
[email protected]2c7c6702013-03-26 03:14:056236 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:146237
[email protected]fb661802013-03-25 01:59:326238 gfx::RectF child_draw_rect =
6239 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6240 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6241 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:146242
[email protected]fb661802013-03-25 01:59:326243 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
6244 child_empty->draw_transform(), child_content_bounds);
6245 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
6246 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:456247
[email protected]fb661802013-03-25 01:59:326248 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
6249 expected_child_draw_rect.Scale(device_scale_factor);
6250 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6251 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
6252 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
6253 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146254
[email protected]fb661802013-03-25 01:59:326255 // Verify child_no_scale transforms
6256 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6257 // All transforms operate on content rects. The child's content rect
6258 // incorporates device scale, but the child_no_scale does not; add it here.
6259 expected_child_no_scale_transform.Scale(device_scale_factor,
6260 device_scale_factor);
6261 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6262 child_no_scale->draw_transform());
6263 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6264 child_no_scale->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146265}
6266
[email protected]989386c2013-07-18 21:37:236267TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326268 // Verify draw and screen space transforms of layers in a surface.
6269 MockContentLayerClient delegate;
6270 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:096271
[email protected]fb661802013-03-25 01:59:326272 gfx::Transform perspective_matrix;
6273 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:096274
[email protected]fb661802013-03-25 01:59:326275 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:056276 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:096277
[email protected]9781afa2013-07-17 23:15:326278 scoped_refptr<Layer> root = Layer::Create();
6279
[email protected]fb661802013-03-25 01:59:326280 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6281 SetLayerPropertiesForTesting(parent.get(),
6282 identity_matrix,
[email protected]fb661802013-03-25 01:59:326283 gfx::PointF(),
6284 gfx::PointF(),
6285 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576286 false,
[email protected]fb661802013-03-25 01:59:326287 true);
[email protected]1b30e8e2012-12-21 02:59:096288
[email protected]fb661802013-03-25 01:59:326289 scoped_refptr<ContentLayer> perspective_surface =
6290 CreateDrawableContentLayer(&delegate);
6291 SetLayerPropertiesForTesting(perspective_surface.get(),
6292 perspective_matrix * scale_small_matrix,
[email protected]fb661802013-03-25 01:59:326293 gfx::PointF(),
6294 gfx::PointF(2.f, 2.f),
6295 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576296 false,
[email protected]fb661802013-03-25 01:59:326297 true);
[email protected]1b30e8e2012-12-21 02:59:096298
[email protected]fb661802013-03-25 01:59:326299 scoped_refptr<ContentLayer> scale_surface =
6300 CreateDrawableContentLayer(&delegate);
6301 SetLayerPropertiesForTesting(scale_surface.get(),
6302 scale_small_matrix,
[email protected]fb661802013-03-25 01:59:326303 gfx::PointF(),
6304 gfx::PointF(2.f, 2.f),
6305 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576306 false,
[email protected]fb661802013-03-25 01:59:326307 true);
[email protected]1b30e8e2012-12-21 02:59:096308
[email protected]fb661802013-03-25 01:59:326309 perspective_surface->SetForceRenderSurface(true);
6310 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:096311
[email protected]fb661802013-03-25 01:59:326312 parent->AddChild(perspective_surface);
6313 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:326314 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:096315
[email protected]d600df7d2013-08-03 02:34:286316 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6317 host->SetRootLayer(root);
6318
[email protected]fb661802013-03-25 01:59:326319 float device_scale_factor = 2.5f;
6320 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:096321
[email protected]7aad55f2013-07-26 11:25:536322 RenderSurfaceLayerList render_surface_layer_list;
6323 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6324 root.get(), parent->bounds(), &render_surface_layer_list);
6325 inputs.device_scale_factor = device_scale_factor;
6326 inputs.page_scale_factor = page_scale_factor;
6327 inputs.page_scale_application_layer = root;
6328 inputs.can_adjust_raster_scales = true;
6329 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:096330
[email protected]fb661802013-03-25 01:59:326331 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6332 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6333 perspective_surface);
6334 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6335 scale_surface);
[email protected]1b30e8e2012-12-21 02:59:096336
[email protected]fb661802013-03-25 01:59:326337 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:096338
[email protected]fb661802013-03-25 01:59:326339 gfx::Transform expected_parent_draw_transform;
6340 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
6341 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096342
[email protected]fb661802013-03-25 01:59:326343 // The scaled surface is rendered at its appropriate scale, and drawn 1:1
6344 // into its target.
6345 gfx::Transform expected_scale_surface_draw_transform;
6346 expected_scale_surface_draw_transform.Translate(
6347 device_scale_factor * page_scale_factor * scale_surface->position().x(),
6348 device_scale_factor * page_scale_factor * scale_surface->position().y());
[email protected]fb661802013-03-25 01:59:326349 EXPECT_TRANSFORMATION_MATRIX_EQ(
6350 expected_scale_surface_draw_transform,
6351 scale_surface->render_surface()->draw_transform());
[email protected]a52c6ff2013-05-04 05:33:156352 gfx::Transform expected_scale_surface_layer_draw_transform =
6353 scale_small_matrix;
[email protected]fb661802013-03-25 01:59:326354 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform,
6355 scale_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096356
[email protected]fb661802013-03-25 01:59:326357 // The scale for the perspective surface is not known, so it is rendered 1:1
6358 // with the screen, and then scaled during drawing.
6359 gfx::Transform expected_perspective_surface_draw_transform;
6360 expected_perspective_surface_draw_transform.Translate(
6361 device_scale_factor * page_scale_factor *
6362 perspective_surface->position().x(),
6363 device_scale_factor * page_scale_factor *
6364 perspective_surface->position().y());
6365 expected_perspective_surface_draw_transform.PreconcatTransform(
6366 perspective_matrix);
6367 expected_perspective_surface_draw_transform.PreconcatTransform(
6368 scale_small_matrix);
6369 gfx::Transform expected_perspective_surface_layer_draw_transform;
6370 EXPECT_TRANSFORMATION_MATRIX_EQ(
6371 expected_perspective_surface_draw_transform,
6372 perspective_surface->render_surface()->draw_transform());
6373 EXPECT_TRANSFORMATION_MATRIX_EQ(
6374 expected_perspective_surface_layer_draw_transform,
6375 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096376}
6377
[email protected]989386c2013-07-18 21:37:236378TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:326379 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
6380 // Verify draw and screen space transforms of layers not in a surface.
6381 MockContentLayerClient delegate;
6382 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:476383
[email protected]fb661802013-03-25 01:59:326384 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6385 SetLayerPropertiesForTesting(parent.get(),
6386 identity_matrix,
[email protected]fb661802013-03-25 01:59:326387 gfx::PointF(),
6388 gfx::PointF(),
6389 gfx::Size(133, 133),
[email protected]56fffdd2014-02-11 19:50:576390 false,
[email protected]fb661802013-03-25 01:59:326391 true);
[email protected]904e9132012-11-01 00:12:476392
[email protected]fb661802013-03-25 01:59:326393 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6394 SetLayerPropertiesForTesting(child.get(),
6395 identity_matrix,
[email protected]fb661802013-03-25 01:59:326396 gfx::PointF(),
6397 gfx::PointF(),
6398 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:576399 false,
[email protected]fb661802013-03-25 01:59:326400 true);
[email protected]904e9132012-11-01 00:12:476401
[email protected]fb661802013-03-25 01:59:326402 scoped_refptr<NoScaleContentLayer> child_no_scale =
6403 CreateNoScaleDrawableContentLayer(&delegate);
6404 SetLayerPropertiesForTesting(child_no_scale.get(),
6405 identity_matrix,
[email protected]fb661802013-03-25 01:59:326406 gfx::PointF(),
6407 gfx::PointF(),
6408 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:576409 false,
[email protected]fb661802013-03-25 01:59:326410 true);
[email protected]904e9132012-11-01 00:12:476411
[email protected]fb661802013-03-25 01:59:326412 parent->AddChild(child);
6413 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:476414
[email protected]d600df7d2013-08-03 02:34:286415 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6416 host->SetRootLayer(parent);
6417
[email protected]fb661802013-03-25 01:59:326418 float device_scale_factor = 1.7f;
6419 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:476420
[email protected]7aad55f2013-07-26 11:25:536421 RenderSurfaceLayerList render_surface_layer_list;
6422 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6423 parent.get(), parent->bounds(), &render_surface_layer_list);
6424 inputs.device_scale_factor = device_scale_factor;
6425 inputs.page_scale_factor = page_scale_factor;
6426 inputs.page_scale_application_layer = parent.get();
6427 inputs.can_adjust_raster_scales = true;
6428 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:476429
[email protected]fb661802013-03-25 01:59:326430 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6431 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6432 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:476433
[email protected]fb661802013-03-25 01:59:326434 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:476435
[email protected]fb661802013-03-25 01:59:326436 // Verify parent transforms
6437 gfx::Transform expected_parent_transform;
6438 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6439 parent->screen_space_transform());
6440 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6441 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:476442
[email protected]fb661802013-03-25 01:59:326443 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056444 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:476445
[email protected]fb661802013-03-25 01:59:326446 gfx::RectF parent_draw_rect =
6447 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6448 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6449 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:476450
[email protected]2c7c6702013-03-26 03:14:056451 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326452 expected_parent_draw_rect.Scale(device_scale_factor);
6453 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
6454 expected_parent_draw_rect.set_height(
6455 ceil(expected_parent_draw_rect.height()));
6456 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6457 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476458
[email protected]fb661802013-03-25 01:59:326459 // Verify child transforms
6460 gfx::Transform expected_child_transform;
6461 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6462 child->draw_transform());
6463 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6464 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476465
[email protected]fb661802013-03-25 01:59:326466 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:056467 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:476468
[email protected]fb661802013-03-25 01:59:326469 gfx::RectF child_draw_rect =
6470 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6471 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6472 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:476473
[email protected]2c7c6702013-03-26 03:14:056474 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:326475 expected_child_draw_rect.Scale(device_scale_factor);
6476 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
6477 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
6478 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6479 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476480
[email protected]fb661802013-03-25 01:59:326481 // Verify child_no_scale transforms
6482 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6483 // All transforms operate on content rects. The child's content rect
6484 // incorporates device scale, but the child_no_scale does not; add it here.
6485 expected_child_no_scale_transform.Scale(device_scale_factor,
6486 device_scale_factor);
6487 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6488 child_no_scale->draw_transform());
6489 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6490 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476491}
6492
[email protected]989386c2013-07-18 21:37:236493TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:326494 MockContentLayerClient delegate;
6495 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446496
[email protected]fb661802013-03-25 01:59:326497 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266498 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326499 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446500
[email protected]fb661802013-03-25 01:59:326501 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266502 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326503 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446504
[email protected]35a99a12013-05-09 23:52:296505 scoped_refptr<Layer> root = Layer::Create();
6506 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446507
[email protected]fb661802013-03-25 01:59:326508 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6509 SetLayerPropertiesForTesting(parent.get(),
6510 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326511 gfx::PointF(),
6512 gfx::PointF(),
6513 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576514 false,
[email protected]fb661802013-03-25 01:59:326515 true);
[email protected]518ee582012-10-24 18:29:446516
[email protected]fb661802013-03-25 01:59:326517 scoped_refptr<ContentLayer> child_scale =
6518 CreateDrawableContentLayer(&delegate);
6519 SetLayerPropertiesForTesting(child_scale.get(),
6520 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326521 gfx::PointF(),
6522 gfx::PointF(2.f, 2.f),
6523 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576524 false,
[email protected]fb661802013-03-25 01:59:326525 true);
[email protected]518ee582012-10-24 18:29:446526
[email protected]fb661802013-03-25 01:59:326527 scoped_refptr<ContentLayer> child_empty =
6528 CreateDrawableContentLayer(&delegate);
6529 SetLayerPropertiesForTesting(child_empty.get(),
6530 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326531 gfx::PointF(),
6532 gfx::PointF(2.f, 2.f),
6533 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576534 false,
[email protected]fb661802013-03-25 01:59:326535 true);
[email protected]f89f5632012-11-14 23:34:456536
[email protected]fb661802013-03-25 01:59:326537 scoped_refptr<NoScaleContentLayer> child_no_scale =
6538 CreateNoScaleDrawableContentLayer(&delegate);
6539 SetLayerPropertiesForTesting(child_no_scale.get(),
6540 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326541 gfx::PointF(),
6542 gfx::PointF(12.f, 12.f),
6543 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576544 false,
[email protected]fb661802013-03-25 01:59:326545 true);
[email protected]518ee582012-10-24 18:29:446546
[email protected]35a99a12013-05-09 23:52:296547 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446548
[email protected]fb661802013-03-25 01:59:326549 parent->AddChild(child_scale);
6550 parent->AddChild(child_empty);
6551 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:446552
[email protected]d600df7d2013-08-03 02:34:286553 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6554 host->SetRootLayer(root);
6555
[email protected]fb661802013-03-25 01:59:326556 float device_scale_factor = 2.5f;
6557 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:446558
[email protected]989386c2013-07-18 21:37:236559 {
6560 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536561 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6562 root.get(), root->bounds(), &render_surface_layer_list);
6563 inputs.device_scale_factor = device_scale_factor;
6564 inputs.page_scale_factor = page_scale_factor;
6565 inputs.page_scale_application_layer = root.get();
6566 inputs.can_adjust_raster_scales = true;
6567 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446568
[email protected]989386c2013-07-18 21:37:236569 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6570 initial_parent_scale, parent);
6571 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6572 initial_parent_scale * initial_child_scale,
6573 child_scale);
6574 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6575 initial_parent_scale * initial_child_scale,
6576 child_empty);
6577 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:446578
[email protected]989386c2013-07-18 21:37:236579 // The parent is scaled up and shouldn't need to scale during draw. The
6580 // child that can scale its contents should also not need to scale during
6581 // draw. This shouldn't change if the child has empty bounds. The other
6582 // children should.
[email protected]803f6b52013-09-12 00:51:266583 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
6584 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
6585 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
6586 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
6587 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
6588 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236589 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6590 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266591 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:236592 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266593 initial_parent_scale * initial_child_scale,
6594 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236595 }
[email protected]518ee582012-10-24 18:29:446596
[email protected]fb661802013-03-25 01:59:326597 // If the device_scale_factor or page_scale_factor changes, then it should be
6598 // updated using the initial transform as the raster scale.
6599 device_scale_factor = 2.25f;
6600 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:446601
[email protected]989386c2013-07-18 21:37:236602 {
6603 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536604 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6605 root.get(), root->bounds(), &render_surface_layer_list);
6606 inputs.device_scale_factor = device_scale_factor;
6607 inputs.page_scale_factor = page_scale_factor;
6608 inputs.page_scale_application_layer = root.get();
6609 inputs.can_adjust_raster_scales = true;
6610 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6611
6612 EXPECT_CONTENTS_SCALE_EQ(
6613 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:236614 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536615 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:236616 child_scale);
6617 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6618 initial_parent_scale * initial_child_scale,
6619 child_empty);
6620 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6621 }
[email protected]d0518202013-02-08 02:06:496622
[email protected]fb661802013-03-25 01:59:326623 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:266624 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326625 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
6626 second_child_scale / initial_child_scale);
6627 child_scale->SetTransform(child_scale_matrix);
6628 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:496629
[email protected]989386c2013-07-18 21:37:236630 {
6631 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536632 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6633 root.get(), root->bounds(), &render_surface_layer_list);
6634 inputs.device_scale_factor = device_scale_factor;
6635 inputs.page_scale_factor = page_scale_factor;
6636 inputs.page_scale_application_layer = root.get();
6637 inputs.can_adjust_raster_scales = true;
6638 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496639
[email protected]989386c2013-07-18 21:37:236640 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6641 initial_parent_scale,
6642 parent);
6643 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6644 child_scale);
6645 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6646 child_empty);
6647 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6648 }
[email protected]d0518202013-02-08 02:06:496649
[email protected]fb661802013-03-25 01:59:326650 // If the device_scale_factor or page_scale_factor changes, then it should be
6651 // updated, but still using 1.0 as the raster scale.
6652 device_scale_factor = 2.75f;
6653 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:496654
[email protected]989386c2013-07-18 21:37:236655 {
6656 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536657 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6658 root.get(), root->bounds(), &render_surface_layer_list);
6659 inputs.device_scale_factor = device_scale_factor;
6660 inputs.page_scale_factor = page_scale_factor;
6661 inputs.page_scale_application_layer = root.get();
6662 inputs.can_adjust_raster_scales = true;
6663 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496664
[email protected]989386c2013-07-18 21:37:236665 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6666 initial_parent_scale,
6667 parent);
6668 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6669 child_scale);
6670 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6671 child_empty);
6672 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6673 }
[email protected]518ee582012-10-24 18:29:446674}
6675
[email protected]989386c2013-07-18 21:37:236676TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:296677 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:326678 MockContentLayerClient delegate;
6679 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:216680
[email protected]fb661802013-03-25 01:59:326681 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266682 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326683 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:216684
[email protected]fb661802013-03-25 01:59:326685 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266686 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326687 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:216688
[email protected]35a99a12013-05-09 23:52:296689 scoped_refptr<Layer> root = Layer::Create();
6690 root->SetBounds(gfx::Size(100, 100));
6691
[email protected]fb661802013-03-25 01:59:326692 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6693 SetLayerPropertiesForTesting(parent.get(),
6694 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326695 gfx::PointF(),
6696 gfx::PointF(),
6697 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576698 false,
[email protected]fb661802013-03-25 01:59:326699 true);
[email protected]11ec92972012-11-10 03:06:216700
[email protected]fb661802013-03-25 01:59:326701 scoped_refptr<ContentLayer> child_scale =
6702 CreateDrawableContentLayer(&delegate);
6703 SetLayerPropertiesForTesting(child_scale.get(),
6704 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326705 gfx::PointF(),
6706 gfx::PointF(2.f, 2.f),
6707 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576708 false,
[email protected]fb661802013-03-25 01:59:326709 true);
[email protected]11ec92972012-11-10 03:06:216710
[email protected]35a99a12013-05-09 23:52:296711 scoped_refptr<ContentLayer> child_empty =
6712 CreateDrawableContentLayer(&delegate);
6713 SetLayerPropertiesForTesting(child_empty.get(),
6714 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296715 gfx::PointF(),
6716 gfx::PointF(2.f, 2.f),
6717 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576718 false,
[email protected]35a99a12013-05-09 23:52:296719 true);
6720
6721 scoped_refptr<NoScaleContentLayer> child_no_scale =
6722 CreateNoScaleDrawableContentLayer(&delegate);
6723 SetLayerPropertiesForTesting(child_no_scale.get(),
6724 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296725 gfx::PointF(),
6726 gfx::PointF(12.f, 12.f),
6727 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576728 false,
[email protected]35a99a12013-05-09 23:52:296729 true);
6730
6731 root->AddChild(parent);
6732
6733 parent->AddChild(child_scale);
6734 parent->AddChild(child_empty);
6735 parent->AddChild(child_no_scale);
6736
[email protected]d600df7d2013-08-03 02:34:286737 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6738 host->SetRootLayer(root);
6739
[email protected]989386c2013-07-18 21:37:236740 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:296741
6742 float device_scale_factor = 2.5f;
6743 float page_scale_factor = 1.f;
6744
[email protected]7aad55f2013-07-26 11:25:536745 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6746 root.get(), root->bounds(), &render_surface_layer_list);
6747 inputs.device_scale_factor = device_scale_factor;
6748 inputs.page_scale_factor = page_scale_factor;
6749 inputs.page_scale_application_layer = root.get(),
6750 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:296751
6752 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6753 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6754 child_scale);
6755 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6756 child_empty);
6757 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6758
6759 // Since the transform scale does not affect contents scale, it should affect
6760 // the draw transform instead.
6761 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266762 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296763 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266764 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296765 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266766 child_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296767 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266768 child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296769 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266770 child_empty->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296771 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266772 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296773 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266774 initial_parent_scale * initial_child_scale,
6775 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296776 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266777 initial_parent_scale * initial_child_scale,
6778 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296779}
6780
[email protected]989386c2013-07-18 21:37:236781TEST_F(LayerTreeHostCommonTest, SmallContentsScale) {
[email protected]35a99a12013-05-09 23:52:296782 MockContentLayerClient delegate;
6783 gfx::Transform identity_matrix;
6784
6785 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266786 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:296787 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6788
6789 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266790 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:296791 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6792
6793 scoped_refptr<Layer> root = Layer::Create();
6794 root->SetBounds(gfx::Size(100, 100));
6795
6796 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6797 SetLayerPropertiesForTesting(parent.get(),
6798 parent_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296799 gfx::PointF(),
6800 gfx::PointF(),
6801 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576802 false,
[email protected]35a99a12013-05-09 23:52:296803 true);
6804
6805 scoped_refptr<ContentLayer> child_scale =
6806 CreateDrawableContentLayer(&delegate);
6807 SetLayerPropertiesForTesting(child_scale.get(),
6808 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296809 gfx::PointF(),
6810 gfx::PointF(2.f, 2.f),
6811 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576812 false,
[email protected]35a99a12013-05-09 23:52:296813 true);
6814
6815 root->AddChild(parent);
6816
[email protected]fb661802013-03-25 01:59:326817 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:216818
[email protected]d600df7d2013-08-03 02:34:286819 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6820 host->SetRootLayer(root);
6821
[email protected]fb661802013-03-25 01:59:326822 float device_scale_factor = 2.5f;
6823 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:216824
[email protected]989386c2013-07-18 21:37:236825 {
6826 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536827 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6828 root.get(), root->bounds(), &render_surface_layer_list);
6829 inputs.device_scale_factor = device_scale_factor;
6830 inputs.page_scale_factor = page_scale_factor;
6831 inputs.page_scale_application_layer = root.get();
6832 inputs.can_adjust_raster_scales = true;
6833 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216834
[email protected]989386c2013-07-18 21:37:236835 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6836 initial_parent_scale,
6837 parent);
6838 // The child's scale is < 1, so we should not save and use that scale
6839 // factor.
6840 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1,
6841 child_scale);
6842 }
[email protected]11ec92972012-11-10 03:06:216843
[email protected]fb661802013-03-25 01:59:326844 // When chilld's total scale becomes >= 1, we should save and use that scale
6845 // factor.
6846 child_scale_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:266847 SkMScalar final_child_scale = 0.75;
[email protected]fb661802013-03-25 01:59:326848 child_scale_matrix.Scale(final_child_scale, final_child_scale);
6849 child_scale->SetTransform(child_scale_matrix);
[email protected]11ec92972012-11-10 03:06:216850
[email protected]989386c2013-07-18 21:37:236851 {
6852 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536853 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6854 root.get(), root->bounds(), &render_surface_layer_list);
6855 inputs.device_scale_factor = device_scale_factor;
6856 inputs.page_scale_factor = page_scale_factor;
6857 inputs.page_scale_application_layer = root.get();
6858 inputs.can_adjust_raster_scales = true;
6859 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216860
[email protected]989386c2013-07-18 21:37:236861 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6862 initial_parent_scale,
6863 parent);
6864 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6865 initial_parent_scale * final_child_scale,
6866 child_scale);
6867 }
[email protected]11ec92972012-11-10 03:06:216868}
6869
[email protected]989386c2013-07-18 21:37:236870TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:326871 MockContentLayerClient delegate;
6872 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446873
[email protected]fb661802013-03-25 01:59:326874 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266875 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:326876 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446877
[email protected]fb661802013-03-25 01:59:326878 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266879 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:326880 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446881
[email protected]35a99a12013-05-09 23:52:296882 scoped_refptr<Layer> root = Layer::Create();
6883 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446884
[email protected]fb661802013-03-25 01:59:326885 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6886 SetLayerPropertiesForTesting(parent.get(),
6887 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326888 gfx::PointF(),
6889 gfx::PointF(),
6890 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576891 false,
[email protected]fb661802013-03-25 01:59:326892 true);
[email protected]518ee582012-10-24 18:29:446893
[email protected]fb661802013-03-25 01:59:326894 scoped_refptr<ContentLayer> surface_scale =
6895 CreateDrawableContentLayer(&delegate);
6896 SetLayerPropertiesForTesting(surface_scale.get(),
6897 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326898 gfx::PointF(),
6899 gfx::PointF(2.f, 2.f),
6900 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576901 false,
[email protected]fb661802013-03-25 01:59:326902 true);
[email protected]518ee582012-10-24 18:29:446903
[email protected]fb661802013-03-25 01:59:326904 scoped_refptr<ContentLayer> surface_scale_child_scale =
6905 CreateDrawableContentLayer(&delegate);
6906 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
6907 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326908 gfx::PointF(),
6909 gfx::PointF(),
6910 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576911 false,
[email protected]fb661802013-03-25 01:59:326912 true);
[email protected]518ee582012-10-24 18:29:446913
[email protected]fb661802013-03-25 01:59:326914 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
6915 CreateNoScaleDrawableContentLayer(&delegate);
6916 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
6917 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326918 gfx::PointF(),
6919 gfx::PointF(),
6920 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576921 false,
[email protected]fb661802013-03-25 01:59:326922 true);
[email protected]518ee582012-10-24 18:29:446923
[email protected]fb661802013-03-25 01:59:326924 scoped_refptr<NoScaleContentLayer> surface_no_scale =
6925 CreateNoScaleDrawableContentLayer(&delegate);
6926 SetLayerPropertiesForTesting(surface_no_scale.get(),
6927 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326928 gfx::PointF(),
6929 gfx::PointF(12.f, 12.f),
6930 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576931 false,
[email protected]fb661802013-03-25 01:59:326932 true);
[email protected]518ee582012-10-24 18:29:446933
[email protected]fb661802013-03-25 01:59:326934 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
6935 CreateDrawableContentLayer(&delegate);
6936 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
6937 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326938 gfx::PointF(),
6939 gfx::PointF(),
6940 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576941 false,
[email protected]fb661802013-03-25 01:59:326942 true);
[email protected]518ee582012-10-24 18:29:446943
[email protected]fb661802013-03-25 01:59:326944 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
6945 CreateNoScaleDrawableContentLayer(&delegate);
6946 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
6947 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326948 gfx::PointF(),
6949 gfx::PointF(),
6950 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576951 false,
[email protected]fb661802013-03-25 01:59:326952 true);
[email protected]518ee582012-10-24 18:29:446953
[email protected]35a99a12013-05-09 23:52:296954 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446955
[email protected]fb661802013-03-25 01:59:326956 parent->AddChild(surface_scale);
6957 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:446958
[email protected]fb661802013-03-25 01:59:326959 surface_scale->SetForceRenderSurface(true);
6960 surface_scale->AddChild(surface_scale_child_scale);
6961 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446962
[email protected]fb661802013-03-25 01:59:326963 surface_no_scale->SetForceRenderSurface(true);
6964 surface_no_scale->AddChild(surface_no_scale_child_scale);
6965 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446966
[email protected]d600df7d2013-08-03 02:34:286967 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6968 host->SetRootLayer(root);
6969
[email protected]803f6b52013-09-12 00:51:266970 SkMScalar device_scale_factor = 5;
6971 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:446972
[email protected]7aad55f2013-07-26 11:25:536973 RenderSurfaceLayerList render_surface_layer_list;
6974 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6975 root.get(), root->bounds(), &render_surface_layer_list);
6976 inputs.device_scale_factor = device_scale_factor;
6977 inputs.page_scale_factor = page_scale_factor;
6978 inputs.page_scale_application_layer = root.get();
6979 inputs.can_adjust_raster_scales = true;
6980 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6981
6982 EXPECT_CONTENTS_SCALE_EQ(
6983 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:196984 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536985 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:326986 surface_scale);
6987 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
6988 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:326989 device_scale_factor * page_scale_factor * initial_parent_scale *
6990 initial_child_scale * initial_child_scale,
6991 surface_scale_child_scale);
6992 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
6993 EXPECT_CONTENTS_SCALE_EQ(
6994 device_scale_factor * page_scale_factor * initial_parent_scale *
6995 initial_child_scale * initial_child_scale,
6996 surface_no_scale_child_scale);
6997 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446998
[email protected]fb661802013-03-25 01:59:326999 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:267000 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
7001 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447002
[email protected]fb661802013-03-25 01:59:327003 // RenderSurfaces should always be 1:1 with their target.
7004 EXPECT_FLOAT_EQ(
7005 1.0,
[email protected]803f6b52013-09-12 00:51:267006 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327007 EXPECT_FLOAT_EQ(
7008 1.0,
[email protected]803f6b52013-09-12 00:51:267009 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447010
[email protected]fb661802013-03-25 01:59:327011 // The surface_scale can apply contents scale so the layer shouldn't need to
7012 // scale during draw.
[email protected]803f6b52013-09-12 00:51:267013 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
7014 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447015
[email protected]fb661802013-03-25 01:59:327016 // The surface_scale_child_scale can apply contents scale so it shouldn't need
7017 // to scale during draw.
7018 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267019 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327020 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267021 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447022
[email protected]fb661802013-03-25 01:59:327023 // The surface_scale_child_no_scale can not apply contents scale, so it needs
7024 // to be scaled during draw.
7025 EXPECT_FLOAT_EQ(
7026 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267027 initial_child_scale * initial_child_scale,
7028 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327029 EXPECT_FLOAT_EQ(
7030 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267031 initial_child_scale * initial_child_scale,
7032 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447033
[email protected]fb661802013-03-25 01:59:327034 // RenderSurfaces should always be 1:1 with their target.
7035 EXPECT_FLOAT_EQ(
7036 1.0,
[email protected]803f6b52013-09-12 00:51:267037 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327038 EXPECT_FLOAT_EQ(
7039 1.0,
[email protected]803f6b52013-09-12 00:51:267040 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447041
[email protected]fb661802013-03-25 01:59:327042 // The surface_no_scale layer can not apply contents scale, so it needs to be
7043 // scaled during draw.
7044 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:267045 initial_parent_scale * initial_child_scale,
7046 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327047 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:267048 initial_parent_scale * initial_child_scale,
7049 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447050
[email protected]fb661802013-03-25 01:59:327051 // The surface_scale_child_scale can apply contents scale so it shouldn't need
7052 // to scale during draw.
7053 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267054 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327055 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267056 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447057
[email protected]fb661802013-03-25 01:59:327058 // The surface_scale_child_no_scale can not apply contents scale, so it needs
7059 // to be scaled during draw.
7060 EXPECT_FLOAT_EQ(
7061 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267062 initial_child_scale * initial_child_scale,
7063 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327064 EXPECT_FLOAT_EQ(
7065 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267066 initial_child_scale * initial_child_scale,
7067 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297068}
[email protected]518ee582012-10-24 18:29:447069
[email protected]989386c2013-07-18 21:37:237070TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:297071 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
7072 MockContentLayerClient delegate;
7073 gfx::Transform identity_matrix;
7074
7075 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267076 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:297077 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
7078
7079 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267080 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:297081 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
7082
7083 scoped_refptr<Layer> root = Layer::Create();
7084 root->SetBounds(gfx::Size(100, 100));
7085
7086 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7087 SetLayerPropertiesForTesting(parent.get(),
7088 parent_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297089 gfx::PointF(),
7090 gfx::PointF(),
7091 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577092 false,
[email protected]35a99a12013-05-09 23:52:297093 true);
7094
7095 scoped_refptr<ContentLayer> surface_scale =
7096 CreateDrawableContentLayer(&delegate);
7097 SetLayerPropertiesForTesting(surface_scale.get(),
7098 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297099 gfx::PointF(),
7100 gfx::PointF(2.f, 2.f),
7101 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577102 false,
[email protected]35a99a12013-05-09 23:52:297103 true);
7104
7105 scoped_refptr<ContentLayer> surface_scale_child_scale =
7106 CreateDrawableContentLayer(&delegate);
7107 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
7108 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297109 gfx::PointF(),
7110 gfx::PointF(),
7111 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577112 false,
[email protected]35a99a12013-05-09 23:52:297113 true);
7114
7115 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
7116 CreateNoScaleDrawableContentLayer(&delegate);
7117 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
7118 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297119 gfx::PointF(),
7120 gfx::PointF(),
7121 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577122 false,
[email protected]35a99a12013-05-09 23:52:297123 true);
7124
7125 scoped_refptr<NoScaleContentLayer> surface_no_scale =
7126 CreateNoScaleDrawableContentLayer(&delegate);
7127 SetLayerPropertiesForTesting(surface_no_scale.get(),
7128 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297129 gfx::PointF(),
7130 gfx::PointF(12.f, 12.f),
7131 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577132 false,
[email protected]35a99a12013-05-09 23:52:297133 true);
7134
7135 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
7136 CreateDrawableContentLayer(&delegate);
7137 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
7138 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297139 gfx::PointF(),
7140 gfx::PointF(),
7141 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577142 false,
[email protected]35a99a12013-05-09 23:52:297143 true);
7144
7145 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
7146 CreateNoScaleDrawableContentLayer(&delegate);
7147 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
7148 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297149 gfx::PointF(),
7150 gfx::PointF(),
7151 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577152 false,
[email protected]35a99a12013-05-09 23:52:297153 true);
7154
7155 root->AddChild(parent);
7156
7157 parent->AddChild(surface_scale);
7158 parent->AddChild(surface_no_scale);
7159
7160 surface_scale->SetForceRenderSurface(true);
7161 surface_scale->AddChild(surface_scale_child_scale);
7162 surface_scale->AddChild(surface_scale_child_no_scale);
7163
7164 surface_no_scale->SetForceRenderSurface(true);
7165 surface_no_scale->AddChild(surface_no_scale_child_scale);
7166 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
7167
[email protected]d600df7d2013-08-03 02:34:287168 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7169 host->SetRootLayer(root);
7170
[email protected]989386c2013-07-18 21:37:237171 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:297172
[email protected]803f6b52013-09-12 00:51:267173 SkMScalar device_scale_factor = 5.0;
7174 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:537175 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7176 root.get(), root->bounds(), &render_surface_layer_list);
7177 inputs.device_scale_factor = device_scale_factor;
7178 inputs.page_scale_factor = page_scale_factor;
7179 inputs.page_scale_application_layer = root.get();
7180 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:297181
[email protected]35a99a12013-05-09 23:52:297182 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7183 parent);
7184 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7185 surface_scale);
7186 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
7187 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7188 surface_scale_child_scale);
7189 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
7190 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7191 surface_no_scale_child_scale);
7192 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
7193
7194 // The parent is scaled up during draw, since its contents are not scaled by
7195 // the transform hierarchy.
7196 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267197 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297198 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267199 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297200
7201 // The child surface is scaled up during draw since its subtree is not scaled
7202 // by the transform hierarchy.
7203 EXPECT_FLOAT_EQ(
7204 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267205 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297206 EXPECT_FLOAT_EQ(
7207 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267208 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297209
7210 // The surface_scale's RenderSurface is scaled during draw, so the layer does
7211 // not need to be scaled when drawing into its surface.
[email protected]803f6b52013-09-12 00:51:267212 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
7213 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447214
[email protected]35a99a12013-05-09 23:52:297215 // The surface_scale_child_scale is scaled when drawing into its surface,
7216 // since its content bounds are not scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:327217 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297218 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267219 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327220 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297221 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267222 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447223
[email protected]35a99a12013-05-09 23:52:297224 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
7225 // needs to be scaled by the device and page scale factors, along with the
7226 // transform hierarchy.
[email protected]fb661802013-03-25 01:59:327227 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297228 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267229 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297230 EXPECT_FLOAT_EQ(
7231 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267232 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297233
7234 // The child surface is scaled up during draw since its subtree is not scaled
7235 // by the transform hierarchy.
7236 EXPECT_FLOAT_EQ(
7237 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267238 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327239 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297240 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267241 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447242
[email protected]35a99a12013-05-09 23:52:297243 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
7244 // be scaled by the device and page scale factors. Its surface is already
7245 // scaled by the transform hierarchy so those don't need to scale the layer's
7246 // drawing.
7247 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267248 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297249 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267250 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297251
7252 // The surface_no_scale_child_scale has its contents scaled by the page and
7253 // device scale factors, but needs to be scaled by the transform hierarchy
7254 // when drawing.
[email protected]fb661802013-03-25 01:59:327255 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297256 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267257 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327258 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297259 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267260 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297261
7262 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
7263 // needs to be scaled by the device and page scale factors. It also needs to
7264 // be scaled by any transform heirarchy below its target surface.
7265 EXPECT_FLOAT_EQ(
7266 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267267 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297268 EXPECT_FLOAT_EQ(
7269 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267270 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447271}
7272
[email protected]989386c2013-07-18 21:37:237273TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:327274 MockContentLayerClient delegate;
7275 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267276
[email protected]fb661802013-03-25 01:59:327277 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267278 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:327279 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:267280
[email protected]fb661802013-03-25 01:59:327281 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267282 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:327283 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:267284
[email protected]35a99a12013-05-09 23:52:297285 scoped_refptr<Layer> root = Layer::Create();
7286 root->SetBounds(gfx::Size(100, 100));
7287
[email protected]fb661802013-03-25 01:59:327288 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7289 SetLayerPropertiesForTesting(parent.get(),
7290 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:327291 gfx::PointF(),
7292 gfx::PointF(),
7293 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577294 false,
[email protected]fb661802013-03-25 01:59:327295 true);
[email protected]6a9cff92012-11-08 11:53:267296
[email protected]fb661802013-03-25 01:59:327297 scoped_refptr<ContentLayer> child_scale =
7298 CreateDrawableContentLayer(&delegate);
7299 SetLayerPropertiesForTesting(child_scale.get(),
7300 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:327301 gfx::PointF(),
7302 gfx::PointF(2.f, 2.f),
7303 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577304 false,
[email protected]fb661802013-03-25 01:59:327305 true);
[email protected]6a9cff92012-11-08 11:53:267306
[email protected]35a99a12013-05-09 23:52:297307 root->AddChild(parent);
7308
[email protected]fb661802013-03-25 01:59:327309 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:267310
[email protected]d600df7d2013-08-03 02:34:287311 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7312 host->SetRootLayer(root);
7313
[email protected]fb661802013-03-25 01:59:327314 // Now put an animating transform on child.
7315 int animation_id = AddAnimatedTransformToController(
7316 child_scale->layer_animation_controller(), 10.0, 30, 0);
[email protected]6a9cff92012-11-08 11:53:267317
[email protected]989386c2013-07-18 21:37:237318 {
7319 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537320 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7321 root.get(), root->bounds(), &render_surface_layer_list);
7322 inputs.can_adjust_raster_scales = true;
7323 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267324
[email protected]989386c2013-07-18 21:37:237325 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7326 // The layers with animating transforms should not compute a contents scale
7327 // other than 1 until they finish animating.
7328 EXPECT_CONTENTS_SCALE_EQ(1, child_scale);
7329 }
[email protected]6a9cff92012-11-08 11:53:267330
[email protected]fb661802013-03-25 01:59:327331 // Remove the animation, now it can save a raster scale.
7332 child_scale->layer_animation_controller()->RemoveAnimation(animation_id);
[email protected]6a9cff92012-11-08 11:53:267333
[email protected]989386c2013-07-18 21:37:237334 {
7335 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537336 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7337 root.get(), root->bounds(), &render_surface_layer_list);
7338 inputs.can_adjust_raster_scales = true;
7339 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267340
[email protected]989386c2013-07-18 21:37:237341 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7342 // The layers with animating transforms should not compute a contents scale
7343 // other than 1 until they finish animating.
7344 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale,
7345 child_scale);
7346 }
[email protected]6a9cff92012-11-08 11:53:267347}
7348
[email protected]7a5a9322014-02-25 12:54:577349TEST_F(LayerTreeHostCommonTest,
7350 ChangeInContentBoundsOrScaleTriggersPushProperties) {
7351 MockContentLayerClient delegate;
7352 scoped_refptr<Layer> root = Layer::Create();
7353 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate);
7354 root->AddChild(child);
7355
7356 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7357 host->SetRootLayer(root);
7358
7359 gfx::Transform identity_matrix;
7360 SetLayerPropertiesForTesting(root.get(),
7361 identity_matrix,
7362 gfx::PointF(),
7363 gfx::PointF(),
7364 gfx::Size(100, 100),
7365 true,
7366 false);
7367 SetLayerPropertiesForTesting(child.get(),
7368 identity_matrix,
7369 gfx::PointF(),
7370 gfx::PointF(),
7371 gfx::Size(100, 100),
7372 true,
7373 false);
7374
7375 root->reset_needs_push_properties_for_testing();
7376 child->reset_needs_push_properties_for_testing();
7377
7378 // This will change both layers' content bounds.
7379 ExecuteCalculateDrawProperties(root.get());
7380 EXPECT_TRUE(root->needs_push_properties());
7381 EXPECT_TRUE(child->needs_push_properties());
7382
7383 root->reset_needs_push_properties_for_testing();
7384 child->reset_needs_push_properties_for_testing();
7385
7386 // This will change only the child layer's contents scale and content bounds,
7387 // since the root layer is not a ContentsScalingLayer.
7388 ExecuteCalculateDrawProperties(root.get(), 2.f);
7389 EXPECT_FALSE(root->needs_push_properties());
7390 EXPECT_TRUE(child->needs_push_properties());
7391
7392 root->reset_needs_push_properties_for_testing();
7393 child->reset_needs_push_properties_for_testing();
7394
7395 // This will not change either layer's contents scale or content bounds.
7396 ExecuteCalculateDrawProperties(root.get(), 2.f);
7397 EXPECT_FALSE(root->needs_push_properties());
7398 EXPECT_FALSE(child->needs_push_properties());
7399}
7400
[email protected]989386c2013-07-18 21:37:237401TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:327402 MockContentLayerClient delegate;
7403 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267404
[email protected]fb661802013-03-25 01:59:327405 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7406 SetLayerPropertiesForTesting(parent.get(),
7407 identity_matrix,
[email protected]fb661802013-03-25 01:59:327408 gfx::PointF(),
7409 gfx::PointF(),
7410 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577411 false,
[email protected]fb661802013-03-25 01:59:327412 true);
[email protected]94f206c12012-08-25 00:09:147413
[email protected]fb661802013-03-25 01:59:327414 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7415 SetLayerPropertiesForTesting(child.get(),
7416 identity_matrix,
[email protected]fb661802013-03-25 01:59:327417 gfx::PointF(),
7418 gfx::PointF(2.f, 2.f),
7419 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577420 false,
[email protected]fb661802013-03-25 01:59:327421 true);
[email protected]94f206c12012-08-25 00:09:147422
[email protected]fb661802013-03-25 01:59:327423 gfx::Transform replica_transform;
7424 replica_transform.Scale(1.0, -1.0);
7425 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7426 SetLayerPropertiesForTesting(replica.get(),
7427 replica_transform,
[email protected]fb661802013-03-25 01:59:327428 gfx::PointF(),
7429 gfx::PointF(2.f, 2.f),
7430 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577431 false,
[email protected]fb661802013-03-25 01:59:327432 true);
[email protected]94f206c12012-08-25 00:09:147433
[email protected]fb661802013-03-25 01:59:327434 // This layer should end up in the same surface as child, with the same draw
7435 // and screen space transforms.
7436 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7437 CreateDrawableContentLayer(&delegate);
7438 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7439 identity_matrix,
[email protected]fb661802013-03-25 01:59:327440 gfx::PointF(),
7441 gfx::PointF(),
7442 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577443 false,
[email protected]fb661802013-03-25 01:59:327444 true);
[email protected]94f206c12012-08-25 00:09:147445
[email protected]fb661802013-03-25 01:59:327446 parent->AddChild(child);
7447 child->AddChild(duplicate_child_non_owner);
7448 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:147449
[email protected]d600df7d2013-08-03 02:34:287450 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7451 host->SetRootLayer(parent);
7452
[email protected]989386c2013-07-18 21:37:237453 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:147454
[email protected]fb661802013-03-25 01:59:327455 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:537456 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7457 parent.get(), parent->bounds(), &render_surface_layer_list);
7458 inputs.device_scale_factor = device_scale_factor;
7459 inputs.can_adjust_raster_scales = true;
7460 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:147461
[email protected]fb661802013-03-25 01:59:327462 // We should have two render surfaces. The root's render surface and child's
7463 // render surface (it needs one because it has a replica layer).
7464 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:147465
[email protected]fb661802013-03-25 01:59:327466 gfx::Transform expected_parent_transform;
7467 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7468 parent->screen_space_transform());
7469 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7470 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:147471
[email protected]fb661802013-03-25 01:59:327472 gfx::Transform expected_draw_transform;
7473 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
7474 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:147475
[email protected]fb661802013-03-25 01:59:327476 gfx::Transform expected_screen_space_transform;
7477 expected_screen_space_transform.Translate(
7478 device_scale_factor * child->position().x(),
7479 device_scale_factor * child->position().y());
7480 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
7481 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147482
[email protected]fb661802013-03-25 01:59:327483 gfx::Transform expected_duplicate_child_draw_transform =
7484 child->draw_transform();
7485 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
7486 duplicate_child_non_owner->draw_transform());
7487 EXPECT_TRANSFORMATION_MATRIX_EQ(
7488 child->screen_space_transform(),
7489 duplicate_child_non_owner->screen_space_transform());
7490 EXPECT_RECT_EQ(child->drawable_content_rect(),
7491 duplicate_child_non_owner->drawable_content_rect());
7492 EXPECT_EQ(child->content_bounds(),
7493 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:147494
[email protected]fb661802013-03-25 01:59:327495 gfx::Transform expected_render_surface_draw_transform;
7496 expected_render_surface_draw_transform.Translate(
7497 device_scale_factor * child->position().x(),
7498 device_scale_factor * child->position().y());
7499 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
7500 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147501
[email protected]fb661802013-03-25 01:59:327502 gfx::Transform expected_surface_draw_transform;
7503 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
7504 device_scale_factor * 2.f);
7505 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
7506 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147507
[email protected]fb661802013-03-25 01:59:327508 gfx::Transform expected_surface_screen_space_transform;
7509 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
7510 device_scale_factor * 2.f);
7511 EXPECT_TRANSFORMATION_MATRIX_EQ(
7512 expected_surface_screen_space_transform,
7513 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147514
[email protected]fb661802013-03-25 01:59:327515 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267516 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
7517 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
7518 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327519 EXPECT_TRANSFORMATION_MATRIX_EQ(
7520 expected_replica_draw_transform,
7521 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:147522
[email protected]fb661802013-03-25 01:59:327523 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267524 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
7525 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
7526 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327527 EXPECT_TRANSFORMATION_MATRIX_EQ(
7528 expected_replica_screen_space_transform,
7529 child->render_surface()->replica_screen_space_transform());
7530 EXPECT_TRANSFORMATION_MATRIX_EQ(
7531 expected_replica_screen_space_transform,
7532 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:477533}
7534
[email protected]989386c2013-07-18 21:37:237535TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:327536 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
7537 MockContentLayerClient delegate;
7538 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:477539
[email protected]fb661802013-03-25 01:59:327540 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7541 SetLayerPropertiesForTesting(parent.get(),
7542 identity_matrix,
[email protected]fb661802013-03-25 01:59:327543 gfx::PointF(),
7544 gfx::PointF(),
7545 gfx::Size(33, 31),
[email protected]56fffdd2014-02-11 19:50:577546 false,
[email protected]fb661802013-03-25 01:59:327547 true);
[email protected]904e9132012-11-01 00:12:477548
[email protected]fb661802013-03-25 01:59:327549 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7550 SetLayerPropertiesForTesting(child.get(),
7551 identity_matrix,
[email protected]fb661802013-03-25 01:59:327552 gfx::PointF(),
7553 gfx::PointF(),
7554 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577555 false,
[email protected]fb661802013-03-25 01:59:327556 true);
[email protected]904e9132012-11-01 00:12:477557
[email protected]fb661802013-03-25 01:59:327558 gfx::Transform replica_transform;
7559 replica_transform.Scale(1.0, -1.0);
7560 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7561 SetLayerPropertiesForTesting(replica.get(),
7562 replica_transform,
[email protected]fb661802013-03-25 01:59:327563 gfx::PointF(),
7564 gfx::PointF(),
7565 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577566 false,
[email protected]fb661802013-03-25 01:59:327567 true);
[email protected]904e9132012-11-01 00:12:477568
[email protected]fb661802013-03-25 01:59:327569 // This layer should end up in the same surface as child, with the same draw
7570 // and screen space transforms.
7571 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7572 CreateDrawableContentLayer(&delegate);
7573 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7574 identity_matrix,
[email protected]fb661802013-03-25 01:59:327575 gfx::PointF(),
7576 gfx::PointF(),
7577 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577578 false,
[email protected]fb661802013-03-25 01:59:327579 true);
[email protected]904e9132012-11-01 00:12:477580
[email protected]fb661802013-03-25 01:59:327581 parent->AddChild(child);
7582 child->AddChild(duplicate_child_non_owner);
7583 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:477584
[email protected]d600df7d2013-08-03 02:34:287585 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7586 host->SetRootLayer(parent);
7587
[email protected]873639e2013-07-24 19:56:317588 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:537589
7590 RenderSurfaceLayerList render_surface_layer_list;
7591 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7592 parent.get(), parent->bounds(), &render_surface_layer_list);
7593 inputs.device_scale_factor = device_scale_factor;
7594 inputs.can_adjust_raster_scales = true;
7595 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:477596
[email protected]fb661802013-03-25 01:59:327597 // We should have two render surfaces. The root's render surface and child's
7598 // render surface (it needs one because it has a replica layer).
7599 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:477600
[email protected]fb661802013-03-25 01:59:327601 gfx::Transform identity_transform;
[email protected]904e9132012-11-01 00:12:477602
[email protected]fb661802013-03-25 01:59:327603 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7604 parent->screen_space_transform());
7605 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform());
7606 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform());
7607 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7608 child->screen_space_transform());
7609 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7610 duplicate_child_non_owner->draw_transform());
7611 EXPECT_TRANSFORMATION_MATRIX_EQ(
7612 identity_transform, duplicate_child_non_owner->screen_space_transform());
7613 EXPECT_RECT_EQ(child->drawable_content_rect(),
7614 duplicate_child_non_owner->drawable_content_rect());
7615 EXPECT_EQ(child->content_bounds(),
7616 duplicate_child_non_owner->content_bounds());
[email protected]904e9132012-11-01 00:12:477617
[email protected]fb661802013-03-25 01:59:327618 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7619 child->render_surface()->draw_transform());
7620 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7621 child->render_surface()->draw_transform());
7622 EXPECT_TRANSFORMATION_MATRIX_EQ(
7623 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:477624
[email protected]fb661802013-03-25 01:59:327625 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267626 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327627 EXPECT_TRANSFORMATION_MATRIX_EQ(
7628 expected_replica_draw_transform,
7629 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:477630
[email protected]fb661802013-03-25 01:59:327631 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267632 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327633 EXPECT_TRANSFORMATION_MATRIX_EQ(
7634 expected_replica_screen_space_transform,
7635 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147636}
7637
[email protected]989386c2013-07-18 21:37:237638TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:327639 scoped_refptr<Layer> root = Layer::Create();
7640 scoped_refptr<Layer> child = Layer::Create();
7641 scoped_refptr<Layer> grand_child = Layer::Create();
7642 scoped_refptr<Layer> mask_layer = Layer::Create();
7643 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:147644
[email protected]fb661802013-03-25 01:59:327645 grand_child->SetReplicaLayer(replica_layer.get());
7646 child->AddChild(grand_child.get());
7647 child->SetMaskLayer(mask_layer.get());
7648 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:147649
[email protected]d600df7d2013-08-03 02:34:287650 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7651 host->SetRootLayer(root);
7652
[email protected]fb661802013-03-25 01:59:327653 int nonexistent_id = -1;
7654 EXPECT_EQ(root,
7655 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
7656 EXPECT_EQ(child,
7657 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
7658 EXPECT_EQ(
7659 grand_child,
7660 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
7661 EXPECT_EQ(
7662 mask_layer,
7663 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
7664 EXPECT_EQ(
7665 replica_layer,
7666 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
7667 EXPECT_EQ(
7668 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:147669}
7670
[email protected]989386c2013-07-18 21:37:237671TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:327672 scoped_refptr<Layer> root = Layer::Create();
7673 scoped_refptr<Layer> child = Layer::Create();
7674 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
7675 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:577676
[email protected]fb661802013-03-25 01:59:327677 const gfx::Transform identity_matrix;
7678 SetLayerPropertiesForTesting(root.get(),
7679 identity_matrix,
[email protected]fb661802013-03-25 01:59:327680 gfx::PointF(),
7681 gfx::PointF(),
7682 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577683 true,
[email protected]fb661802013-03-25 01:59:327684 false);
7685 SetLayerPropertiesForTesting(child.get(),
7686 identity_matrix,
[email protected]fb661802013-03-25 01:59:327687 gfx::PointF(),
7688 gfx::PointF(),
7689 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577690 true,
[email protected]fb661802013-03-25 01:59:327691 false);
7692 SetLayerPropertiesForTesting(grand_child.get(),
7693 identity_matrix,
[email protected]fb661802013-03-25 01:59:327694 gfx::PointF(),
7695 gfx::PointF(),
7696 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577697 true,
[email protected]fb661802013-03-25 01:59:327698 false);
[email protected]498ec6e0e2012-11-30 18:24:577699
[email protected]fb661802013-03-25 01:59:327700 root->AddChild(child);
7701 child->AddChild(grand_child);
7702 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:577703
[email protected]d600df7d2013-08-03 02:34:287704 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7705 host->SetRootLayer(root);
7706
[email protected]fb661802013-03-25 01:59:327707 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:577708
[email protected]fb661802013-03-25 01:59:327709 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:577710}
7711
[email protected]989386c2013-07-18 21:37:237712TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:167713 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457714 TestSharedBitmapManager shared_bitmap_manager;
7715 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]f90fc412013-03-30 20:13:167716 host_impl.CreatePendingTree();
7717 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7718
7719 const gfx::Transform identity_matrix;
7720 SetLayerPropertiesForTesting(root.get(),
7721 identity_matrix,
[email protected]f90fc412013-03-30 20:13:167722 gfx::PointF(),
7723 gfx::PointF(),
7724 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577725 true,
[email protected]f90fc412013-03-30 20:13:167726 false);
7727 root->SetDrawsContent(true);
7728
7729 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7730 SetLayerPropertiesForTesting(child.get(),
7731 identity_matrix,
[email protected]f90fc412013-03-30 20:13:167732 gfx::PointF(),
7733 gfx::PointF(),
7734 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577735 true,
[email protected]f90fc412013-03-30 20:13:167736 false);
7737 child->SetDrawsContent(true);
7738 child->SetOpacity(0.0f);
7739
7740 // Add opacity animation.
7741 AddOpacityTransitionToController(
7742 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
7743
7744 root->AddChild(child.Pass());
7745
[email protected]c0ae06c12013-06-24 18:32:197746 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537747 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7748 root.get(), root->bounds(), &render_surface_layer_list);
7749 inputs.can_adjust_raster_scales = true;
7750 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:167751
7752 // We should have one render surface and two layers. The child
7753 // layer should be included even though it is transparent.
7754 ASSERT_EQ(1u, render_surface_layer_list.size());
7755 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
7756}
7757
[email protected]10aabcc32012-12-13 09:18:597758typedef std::tr1::tuple<bool, bool> LCDTextTestParam;
[email protected]989386c2013-07-18 21:37:237759class LCDTextTest
7760 : public LayerTreeHostCommonTestBase,
7761 public testing::TestWithParam<LCDTextTestParam> {
[email protected]fb661802013-03-25 01:59:327762 protected:
7763 virtual void SetUp() {
7764 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
[email protected]10aabcc32012-12-13 09:18:597765
[email protected]fb661802013-03-25 01:59:327766 root_ = Layer::Create();
7767 child_ = Layer::Create();
7768 grand_child_ = Layer::Create();
7769 child_->AddChild(grand_child_.get());
7770 root_->AddChild(child_.get());
[email protected]10aabcc32012-12-13 09:18:597771
[email protected]fb661802013-03-25 01:59:327772 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307773 SetLayerPropertiesForTesting(root_.get(),
[email protected]fb661802013-03-25 01:59:327774 identity_matrix,
[email protected]fb661802013-03-25 01:59:327775 gfx::PointF(),
7776 gfx::PointF(),
7777 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577778 true,
[email protected]fb661802013-03-25 01:59:327779 false);
[email protected]22898ed2013-06-01 04:52:307780 SetLayerPropertiesForTesting(child_.get(),
[email protected]fb661802013-03-25 01:59:327781 identity_matrix,
[email protected]fb661802013-03-25 01:59:327782 gfx::PointF(),
7783 gfx::PointF(),
7784 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577785 true,
[email protected]fb661802013-03-25 01:59:327786 false);
[email protected]22898ed2013-06-01 04:52:307787 SetLayerPropertiesForTesting(grand_child_.get(),
[email protected]fb661802013-03-25 01:59:327788 identity_matrix,
[email protected]fb661802013-03-25 01:59:327789 gfx::PointF(),
7790 gfx::PointF(),
7791 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577792 true,
[email protected]fb661802013-03-25 01:59:327793 false);
[email protected]10aabcc32012-12-13 09:18:597794
[email protected]fb661802013-03-25 01:59:327795 child_->SetForceRenderSurface(std::tr1::get<1>(GetParam()));
[email protected]d600df7d2013-08-03 02:34:287796
7797 host_ = FakeLayerTreeHost::Create();
7798 host_->SetRootLayer(root_);
[email protected]fb661802013-03-25 01:59:327799 }
[email protected]10aabcc32012-12-13 09:18:597800
[email protected]fb661802013-03-25 01:59:327801 bool can_use_lcd_text_;
[email protected]d600df7d2013-08-03 02:34:287802 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]fb661802013-03-25 01:59:327803 scoped_refptr<Layer> root_;
7804 scoped_refptr<Layer> child_;
7805 scoped_refptr<Layer> grand_child_;
[email protected]10aabcc32012-12-13 09:18:597806};
7807
[email protected]fb661802013-03-25 01:59:327808TEST_P(LCDTextTest, CanUseLCDText) {
7809 // Case 1: Identity transform.
7810 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307811 ExecuteCalculateDrawProperties(
7812 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327813 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7814 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7815 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597816
[email protected]fb661802013-03-25 01:59:327817 // Case 2: Integral translation.
7818 gfx::Transform integral_translation;
7819 integral_translation.Translate(1.0, 2.0);
7820 child_->SetTransform(integral_translation);
[email protected]22898ed2013-06-01 04:52:307821 ExecuteCalculateDrawProperties(
7822 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327823 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7824 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7825 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597826
[email protected]fb661802013-03-25 01:59:327827 // Case 3: Non-integral translation.
7828 gfx::Transform non_integral_translation;
7829 non_integral_translation.Translate(1.5, 2.5);
7830 child_->SetTransform(non_integral_translation);
[email protected]22898ed2013-06-01 04:52:307831 ExecuteCalculateDrawProperties(
7832 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327833 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7834 EXPECT_FALSE(child_->can_use_lcd_text());
7835 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597836
[email protected]fb661802013-03-25 01:59:327837 // Case 4: Rotation.
7838 gfx::Transform rotation;
7839 rotation.Rotate(10.0);
7840 child_->SetTransform(rotation);
[email protected]22898ed2013-06-01 04:52:307841 ExecuteCalculateDrawProperties(
7842 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327843 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7844 EXPECT_FALSE(child_->can_use_lcd_text());
7845 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597846
[email protected]fb661802013-03-25 01:59:327847 // Case 5: Scale.
7848 gfx::Transform scale;
7849 scale.Scale(2.0, 2.0);
7850 child_->SetTransform(scale);
[email protected]22898ed2013-06-01 04:52:307851 ExecuteCalculateDrawProperties(
7852 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327853 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7854 EXPECT_FALSE(child_->can_use_lcd_text());
7855 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597856
[email protected]fb661802013-03-25 01:59:327857 // Case 6: Skew.
7858 gfx::Transform skew;
7859 skew.SkewX(10.0);
7860 child_->SetTransform(skew);
[email protected]22898ed2013-06-01 04:52:307861 ExecuteCalculateDrawProperties(
7862 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327863 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7864 EXPECT_FALSE(child_->can_use_lcd_text());
7865 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597866
[email protected]fb661802013-03-25 01:59:327867 // Case 7: Translucent.
7868 child_->SetTransform(identity_matrix);
7869 child_->SetOpacity(0.5f);
[email protected]22898ed2013-06-01 04:52:307870 ExecuteCalculateDrawProperties(
7871 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327872 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7873 EXPECT_FALSE(child_->can_use_lcd_text());
7874 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597875
[email protected]fb661802013-03-25 01:59:327876 // Case 8: Sanity check: restore transform and opacity.
7877 child_->SetTransform(identity_matrix);
7878 child_->SetOpacity(1.f);
[email protected]22898ed2013-06-01 04:52:307879 ExecuteCalculateDrawProperties(
7880 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327881 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7882 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7883 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597884}
7885
[email protected]fd9a3b6d2013-08-03 00:46:177886TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
[email protected]fb661802013-03-25 01:59:327887 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
[email protected]22898ed2013-06-01 04:52:307888 ExecuteCalculateDrawProperties(
7889 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327890 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7891 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7892 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597893
[email protected]fb661802013-03-25 01:59:327894 // Add opacity animation.
7895 child_->SetOpacity(0.9f);
7896 AddOpacityTransitionToController(
7897 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:597898
[email protected]22898ed2013-06-01 04:52:307899 ExecuteCalculateDrawProperties(
7900 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327901 // Text AA should not be adjusted while animation is active.
7902 // Make sure LCD text AA setting remains unchanged.
7903 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7904 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7905 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597906}
7907
7908INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
7909 LCDTextTest,
[email protected]fb661802013-03-25 01:59:327910 testing::Combine(testing::Bool(), testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:597911
[email protected]989386c2013-07-18 21:37:237912TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:197913 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457914 TestSharedBitmapManager shared_bitmap_manager;
7915 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:197916 host_impl.CreatePendingTree();
7917 const gfx::Transform identity_matrix;
7918
7919 scoped_refptr<Layer> root = Layer::Create();
7920 SetLayerPropertiesForTesting(root.get(),
7921 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197922 gfx::PointF(),
7923 gfx::PointF(),
7924 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577925 true,
[email protected]c0ae06c12013-06-24 18:32:197926 false);
7927 root->SetIsDrawable(true);
7928
7929 scoped_refptr<Layer> child = Layer::Create();
7930 SetLayerPropertiesForTesting(child.get(),
7931 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197932 gfx::PointF(),
7933 gfx::PointF(),
7934 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577935 true,
[email protected]c0ae06c12013-06-24 18:32:197936 false);
7937 child->SetIsDrawable(true);
7938
7939 scoped_refptr<Layer> grand_child = Layer::Create();
7940 SetLayerPropertiesForTesting(grand_child.get(),
7941 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197942 gfx::PointF(),
7943 gfx::PointF(),
7944 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577945 true,
[email protected]c0ae06c12013-06-24 18:32:197946 false);
7947 grand_child->SetIsDrawable(true);
7948 grand_child->SetHideLayerAndSubtree(true);
7949
7950 child->AddChild(grand_child);
7951 root->AddChild(child);
7952
[email protected]d600df7d2013-08-03 02:34:287953 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7954 host->SetRootLayer(root);
7955
[email protected]989386c2013-07-18 21:37:237956 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537957 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7958 root.get(), root->bounds(), &render_surface_layer_list);
7959 inputs.can_adjust_raster_scales = true;
7960 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197961
7962 // We should have one render surface and two layers. The grand child has
7963 // hidden itself.
7964 ASSERT_EQ(1u, render_surface_layer_list.size());
7965 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237966 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
7967 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197968}
7969
[email protected]989386c2013-07-18 21:37:237970TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:197971 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457972 TestSharedBitmapManager shared_bitmap_manager;
7973 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:197974 host_impl.CreatePendingTree();
7975 const gfx::Transform identity_matrix;
7976
7977 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7978 SetLayerPropertiesForTesting(root.get(),
7979 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197980 gfx::PointF(),
7981 gfx::PointF(),
7982 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577983 true,
[email protected]c0ae06c12013-06-24 18:32:197984 false);
7985 root->SetDrawsContent(true);
7986
7987 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7988 SetLayerPropertiesForTesting(child.get(),
7989 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197990 gfx::PointF(),
7991 gfx::PointF(),
7992 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577993 true,
[email protected]c0ae06c12013-06-24 18:32:197994 false);
7995 child->SetDrawsContent(true);
7996
7997 scoped_ptr<LayerImpl> grand_child =
7998 LayerImpl::Create(host_impl.pending_tree(), 3);
7999 SetLayerPropertiesForTesting(grand_child.get(),
8000 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198001 gfx::PointF(),
8002 gfx::PointF(),
8003 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578004 true,
[email protected]c0ae06c12013-06-24 18:32:198005 false);
8006 grand_child->SetDrawsContent(true);
8007 grand_child->SetHideLayerAndSubtree(true);
8008
8009 child->AddChild(grand_child.Pass());
8010 root->AddChild(child.Pass());
8011
8012 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538013 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8014 root.get(), root->bounds(), &render_surface_layer_list);
8015 inputs.can_adjust_raster_scales = true;
8016 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198017
8018 // We should have one render surface and two layers. The grand child has
8019 // hidden itself.
8020 ASSERT_EQ(1u, render_surface_layer_list.size());
8021 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238022 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
8023 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:198024}
8025
[email protected]989386c2013-07-18 21:37:238026TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:198027 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458028 TestSharedBitmapManager shared_bitmap_manager;
8029 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:198030 host_impl.CreatePendingTree();
8031 const gfx::Transform identity_matrix;
8032
8033 scoped_refptr<Layer> root = Layer::Create();
8034 SetLayerPropertiesForTesting(root.get(),
8035 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198036 gfx::PointF(),
8037 gfx::PointF(),
8038 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578039 true,
[email protected]c0ae06c12013-06-24 18:32:198040 false);
8041 root->SetIsDrawable(true);
8042
8043 scoped_refptr<Layer> child = Layer::Create();
8044 SetLayerPropertiesForTesting(child.get(),
8045 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198046 gfx::PointF(),
8047 gfx::PointF(),
8048 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578049 true,
[email protected]c0ae06c12013-06-24 18:32:198050 false);
8051 child->SetIsDrawable(true);
8052 child->SetHideLayerAndSubtree(true);
8053
8054 scoped_refptr<Layer> grand_child = Layer::Create();
8055 SetLayerPropertiesForTesting(grand_child.get(),
8056 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198057 gfx::PointF(),
8058 gfx::PointF(),
8059 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578060 true,
[email protected]c0ae06c12013-06-24 18:32:198061 false);
8062 grand_child->SetIsDrawable(true);
8063
8064 child->AddChild(grand_child);
8065 root->AddChild(child);
8066
[email protected]d600df7d2013-08-03 02:34:288067 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8068 host->SetRootLayer(root);
8069
[email protected]989386c2013-07-18 21:37:238070 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538071 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8072 root.get(), root->bounds(), &render_surface_layer_list);
8073 inputs.can_adjust_raster_scales = true;
8074 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198075
8076 // We should have one render surface and one layers. The child has
8077 // hidden itself and the grand child.
8078 ASSERT_EQ(1u, render_surface_layer_list.size());
8079 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238080 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:198081}
8082
[email protected]989386c2013-07-18 21:37:238083TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:198084 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458085 TestSharedBitmapManager shared_bitmap_manager;
8086 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:198087 host_impl.CreatePendingTree();
8088 const gfx::Transform identity_matrix;
8089
8090 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
8091 SetLayerPropertiesForTesting(root.get(),
8092 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198093 gfx::PointF(),
8094 gfx::PointF(),
8095 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578096 true,
[email protected]c0ae06c12013-06-24 18:32:198097 false);
8098 root->SetDrawsContent(true);
8099
8100 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
8101 SetLayerPropertiesForTesting(child.get(),
8102 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198103 gfx::PointF(),
8104 gfx::PointF(),
8105 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578106 true,
[email protected]c0ae06c12013-06-24 18:32:198107 false);
8108 child->SetDrawsContent(true);
8109 child->SetHideLayerAndSubtree(true);
8110
8111 scoped_ptr<LayerImpl> grand_child =
8112 LayerImpl::Create(host_impl.pending_tree(), 3);
8113 SetLayerPropertiesForTesting(grand_child.get(),
8114 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198115 gfx::PointF(),
8116 gfx::PointF(),
8117 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578118 true,
[email protected]c0ae06c12013-06-24 18:32:198119 false);
8120 grand_child->SetDrawsContent(true);
8121
8122 child->AddChild(grand_child.Pass());
8123 root->AddChild(child.Pass());
8124
8125 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538126 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8127 root.get(), root->bounds(), &render_surface_layer_list);
8128 inputs.can_adjust_raster_scales = true;
8129 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198130
8131 // We should have one render surface and one layers. The child has
8132 // hidden itself and the grand child.
8133 ASSERT_EQ(1u, render_surface_layer_list.size());
8134 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238135 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:198136}
8137
[email protected]30fe19ff2013-07-04 00:54:458138void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
8139
[email protected]989386c2013-07-18 21:37:238140TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458141 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458142 TestSharedBitmapManager shared_bitmap_manager;
8143 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:458144 host_impl.CreatePendingTree();
8145 const gfx::Transform identity_matrix;
8146
8147 scoped_refptr<Layer> root = Layer::Create();
8148 SetLayerPropertiesForTesting(root.get(),
8149 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458150 gfx::PointF(),
8151 gfx::PointF(),
8152 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578153 true,
[email protected]30fe19ff2013-07-04 00:54:458154 false);
8155 root->SetIsDrawable(true);
8156
8157 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
8158 SetLayerPropertiesForTesting(copy_grand_parent.get(),
8159 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458160 gfx::PointF(),
8161 gfx::PointF(),
8162 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578163 true,
[email protected]30fe19ff2013-07-04 00:54:458164 false);
8165 copy_grand_parent->SetIsDrawable(true);
8166
8167 scoped_refptr<Layer> copy_parent = Layer::Create();
8168 SetLayerPropertiesForTesting(copy_parent.get(),
8169 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458170 gfx::PointF(),
8171 gfx::PointF(),
8172 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578173 true,
[email protected]30fe19ff2013-07-04 00:54:458174 false);
8175 copy_parent->SetIsDrawable(true);
8176 copy_parent->SetForceRenderSurface(true);
8177
8178 scoped_refptr<Layer> copy_layer = Layer::Create();
8179 SetLayerPropertiesForTesting(copy_layer.get(),
8180 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458181 gfx::PointF(),
8182 gfx::PointF(),
8183 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578184 true,
[email protected]30fe19ff2013-07-04 00:54:458185 false);
8186 copy_layer->SetIsDrawable(true);
8187
8188 scoped_refptr<Layer> copy_child = Layer::Create();
8189 SetLayerPropertiesForTesting(copy_child.get(),
8190 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458191 gfx::PointF(),
8192 gfx::PointF(),
8193 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578194 true,
[email protected]30fe19ff2013-07-04 00:54:458195 false);
8196 copy_child->SetIsDrawable(true);
8197
[email protected]ac020122013-07-12 23:45:538198 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
8199 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
8200 identity_matrix,
[email protected]ac020122013-07-12 23:45:538201 gfx::PointF(),
8202 gfx::PointF(),
8203 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578204 true,
[email protected]ac020122013-07-12 23:45:538205 false);
8206 copy_grand_parent_sibling_before->SetIsDrawable(true);
8207
8208 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
8209 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
8210 identity_matrix,
[email protected]ac020122013-07-12 23:45:538211 gfx::PointF(),
8212 gfx::PointF(),
8213 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578214 true,
[email protected]ac020122013-07-12 23:45:538215 false);
8216 copy_grand_parent_sibling_after->SetIsDrawable(true);
8217
[email protected]30fe19ff2013-07-04 00:54:458218 copy_layer->AddChild(copy_child);
8219 copy_parent->AddChild(copy_layer);
8220 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:538221 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:458222 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:538223 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:458224
[email protected]d600df7d2013-08-03 02:34:288225 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8226 host->SetRootLayer(root);
8227
[email protected]30fe19ff2013-07-04 00:54:458228 // Hide the copy_grand_parent and its subtree. But make a copy request in that
8229 // hidden subtree on copy_layer.
8230 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:538231 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
8232 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:458233 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8234 base::Bind(&EmptyCopyOutputCallback)));
8235 EXPECT_TRUE(copy_layer->HasCopyRequest());
8236
[email protected]989386c2013-07-18 21:37:238237 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538238 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8239 root.get(), root->bounds(), &render_surface_layer_list);
8240 inputs.can_adjust_raster_scales = true;
8241 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458242
[email protected]ac020122013-07-12 23:45:538243 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
8244 EXPECT_TRUE(copy_grand_parent->draw_properties().
8245 layer_or_descendant_has_copy_request);
8246 EXPECT_TRUE(copy_parent->draw_properties().
8247 layer_or_descendant_has_copy_request);
8248 EXPECT_TRUE(copy_layer->draw_properties().
8249 layer_or_descendant_has_copy_request);
8250 EXPECT_FALSE(copy_child->draw_properties().
8251 layer_or_descendant_has_copy_request);
8252 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
8253 layer_or_descendant_has_copy_request);
8254 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
8255 layer_or_descendant_has_copy_request);
8256
[email protected]30fe19ff2013-07-04 00:54:458257 // We should have three render surfaces, one for the root, one for the parent
8258 // since it owns a surface, and one for the copy_layer.
8259 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238260 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
8261 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
8262 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:458263
8264 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:538265 // copy_grand_parent is hidden along with its siblings, but the copy_parent
8266 // will appear since something in its subtree needs to be drawn for a copy
8267 // request.
[email protected]30fe19ff2013-07-04 00:54:458268 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238269 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
8270 EXPECT_EQ(copy_parent->id(),
8271 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458272
[email protected]7392c7b2014-02-07 08:28:288273 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:458274 // appear in its list, since it needs to be drawn for the copy request.
8275 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
8276 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238277 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458278
8279 // The copy_layer's render surface should have two contributing layers.
8280 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
8281 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238282 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458283 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:238284 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458285}
8286
[email protected]989386c2013-07-18 21:37:238287TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458288 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458289 TestSharedBitmapManager shared_bitmap_manager;
8290 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:458291 host_impl.CreatePendingTree();
8292 const gfx::Transform identity_matrix;
8293
8294 scoped_refptr<Layer> root = Layer::Create();
8295 SetLayerPropertiesForTesting(root.get(),
8296 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458297 gfx::PointF(),
8298 gfx::PointF(),
8299 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578300 true,
[email protected]30fe19ff2013-07-04 00:54:458301 false);
8302 root->SetIsDrawable(true);
8303
8304 scoped_refptr<Layer> copy_parent = Layer::Create();
8305 SetLayerPropertiesForTesting(copy_parent.get(),
8306 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458307 gfx::PointF(),
8308 gfx::PointF(),
8309 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:578310 true,
[email protected]30fe19ff2013-07-04 00:54:458311 false);
8312 copy_parent->SetIsDrawable(true);
8313 copy_parent->SetMasksToBounds(true);
8314
8315 scoped_refptr<Layer> copy_layer = Layer::Create();
8316 SetLayerPropertiesForTesting(copy_layer.get(),
8317 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458318 gfx::PointF(),
8319 gfx::PointF(),
8320 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578321 true,
[email protected]30fe19ff2013-07-04 00:54:458322 false);
8323 copy_layer->SetIsDrawable(true);
8324
8325 scoped_refptr<Layer> copy_child = Layer::Create();
8326 SetLayerPropertiesForTesting(copy_child.get(),
8327 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458328 gfx::PointF(),
8329 gfx::PointF(),
8330 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578331 true,
[email protected]30fe19ff2013-07-04 00:54:458332 false);
8333 copy_child->SetIsDrawable(true);
8334
8335 copy_layer->AddChild(copy_child);
8336 copy_parent->AddChild(copy_layer);
8337 root->AddChild(copy_parent);
8338
[email protected]d600df7d2013-08-03 02:34:288339 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8340 host->SetRootLayer(root);
8341
[email protected]30fe19ff2013-07-04 00:54:458342 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8343 base::Bind(&EmptyCopyOutputCallback)));
8344 EXPECT_TRUE(copy_layer->HasCopyRequest());
8345
[email protected]989386c2013-07-18 21:37:238346 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538347 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8348 root.get(), root->bounds(), &render_surface_layer_list);
8349 inputs.can_adjust_raster_scales = true;
8350 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458351
8352 // We should have one render surface, as the others are clipped out.
8353 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238354 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458355
8356 // The root render surface should only have 1 contributing layer, since the
8357 // other layers are empty/clipped away.
8358 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238359 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458360}
8361
[email protected]11a07b102013-07-24 17:33:198362TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
8363 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458364 TestSharedBitmapManager shared_bitmap_manager;
8365 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]11a07b102013-07-24 17:33:198366 host_impl.CreatePendingTree();
8367 const gfx::Transform identity_matrix;
8368
8369 scoped_refptr<Layer> root = Layer::Create();
8370 SetLayerPropertiesForTesting(root.get(),
8371 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198372 gfx::PointF(),
8373 gfx::PointF(),
8374 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578375 true,
[email protected]11a07b102013-07-24 17:33:198376 false);
8377 root->SetIsDrawable(true);
8378
8379 // The surface is moved slightly outside of the viewport.
8380 scoped_refptr<Layer> surface = Layer::Create();
8381 SetLayerPropertiesForTesting(surface.get(),
8382 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198383 gfx::PointF(),
8384 gfx::PointF(-10, -20),
8385 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:578386 true,
[email protected]11a07b102013-07-24 17:33:198387 false);
8388 surface->SetForceRenderSurface(true);
8389
8390 scoped_refptr<Layer> surface_child = Layer::Create();
8391 SetLayerPropertiesForTesting(surface_child.get(),
8392 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198393 gfx::PointF(),
8394 gfx::PointF(),
8395 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578396 true,
[email protected]11a07b102013-07-24 17:33:198397 false);
8398 surface_child->SetIsDrawable(true);
8399
8400 surface->AddChild(surface_child);
8401 root->AddChild(surface);
8402
[email protected]d600df7d2013-08-03 02:34:288403 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8404 host->SetRootLayer(root);
8405
[email protected]11a07b102013-07-24 17:33:198406 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538407 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8408 root.get(), root->bounds(), &render_surface_layer_list);
8409 inputs.can_adjust_raster_scales = true;
8410 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:198411
8412 // The visible_content_rect for the |surface_child| should not be clipped by
8413 // the viewport.
8414 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
8415 surface_child->visible_content_rect().ToString());
8416}
8417
[email protected]420fdf6e2013-08-26 20:36:388418TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
8419 // Ensure that a transform between the layer and its render surface is not a
8420 // problem. Constructs the following layer tree.
8421 //
8422 // root (a render surface)
8423 // + render_surface
8424 // + clip_parent (scaled)
8425 // + intervening_clipping_layer
8426 // + clip_child
8427 //
8428 // The render surface should be resized correctly and the clip child should
8429 // inherit the right clip rect.
8430 scoped_refptr<Layer> root = Layer::Create();
8431 scoped_refptr<Layer> render_surface = Layer::Create();
8432 scoped_refptr<Layer> clip_parent = Layer::Create();
8433 scoped_refptr<Layer> intervening = Layer::Create();
8434 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8435 make_scoped_refptr(new LayerWithForcedDrawsContent);
8436
8437 root->AddChild(render_surface);
8438 render_surface->AddChild(clip_parent);
8439 clip_parent->AddChild(intervening);
8440 intervening->AddChild(clip_child);
8441
8442 clip_child->SetClipParent(clip_parent.get());
8443
8444 intervening->SetMasksToBounds(true);
8445 clip_parent->SetMasksToBounds(true);
8446
8447 render_surface->SetForceRenderSurface(true);
8448
8449 gfx::Transform scale_transform;
8450 scale_transform.Scale(2, 2);
8451
8452 gfx::Transform identity_transform;
8453
8454 SetLayerPropertiesForTesting(root.get(),
8455 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388456 gfx::PointF(),
8457 gfx::PointF(),
8458 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578459 true,
[email protected]420fdf6e2013-08-26 20:36:388460 false);
8461 SetLayerPropertiesForTesting(render_surface.get(),
8462 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388463 gfx::PointF(),
8464 gfx::PointF(),
8465 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578466 true,
[email protected]420fdf6e2013-08-26 20:36:388467 false);
8468 SetLayerPropertiesForTesting(clip_parent.get(),
8469 scale_transform,
[email protected]420fdf6e2013-08-26 20:36:388470 gfx::PointF(),
8471 gfx::PointF(1.f, 1.f),
8472 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578473 true,
[email protected]420fdf6e2013-08-26 20:36:388474 false);
8475 SetLayerPropertiesForTesting(intervening.get(),
8476 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388477 gfx::PointF(),
8478 gfx::PointF(1.f, 1.f),
8479 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578480 true,
[email protected]420fdf6e2013-08-26 20:36:388481 false);
8482 SetLayerPropertiesForTesting(clip_child.get(),
8483 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388484 gfx::PointF(),
8485 gfx::PointF(1.f, 1.f),
8486 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578487 true,
[email protected]420fdf6e2013-08-26 20:36:388488 false);
8489
8490 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8491 host->SetRootLayer(root);
8492
8493 ExecuteCalculateDrawProperties(root.get());
8494
8495 ASSERT_TRUE(root->render_surface());
8496 ASSERT_TRUE(render_surface->render_surface());
8497
8498 // Ensure that we've inherited our clip parent's clip and weren't affected
8499 // by the intervening clip layer.
8500 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
8501 clip_parent->clip_rect().ToString());
8502 ASSERT_EQ(clip_parent->clip_rect().ToString(),
8503 clip_child->clip_rect().ToString());
8504 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
8505 intervening->clip_rect().ToString());
8506
8507 // Ensure that the render surface reports a content rect that has been grown
8508 // to accomodate for the clip child.
8509 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
8510 render_surface->render_surface()->content_rect().ToString());
8511
8512 // The above check implies the two below, but they nicely demonstrate that
8513 // we've grown, despite the intervening layer's clip.
8514 ASSERT_TRUE(clip_parent->clip_rect().Contains(
8515 render_surface->render_surface()->content_rect()));
8516 ASSERT_FALSE(intervening->clip_rect().Contains(
8517 render_surface->render_surface()->content_rect()));
8518}
8519
8520TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
8521 // Ensure that intervening render surfaces are not a problem in the basic
8522 // case. In the following tree, both render surfaces should be resized to
8523 // accomodate for the clip child, despite an intervening clip.
8524 //
8525 // root (a render surface)
8526 // + clip_parent (masks to bounds)
8527 // + render_surface1 (sets opacity)
8528 // + intervening (masks to bounds)
8529 // + render_surface2 (also sets opacity)
8530 // + clip_child
8531 //
8532 scoped_refptr<Layer> root = Layer::Create();
8533 scoped_refptr<Layer> clip_parent = Layer::Create();
8534 scoped_refptr<Layer> render_surface1 = Layer::Create();
8535 scoped_refptr<Layer> intervening = Layer::Create();
8536 scoped_refptr<Layer> render_surface2 = Layer::Create();
8537 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8538 make_scoped_refptr(new LayerWithForcedDrawsContent);
8539
8540 root->AddChild(clip_parent);
8541 clip_parent->AddChild(render_surface1);
8542 render_surface1->AddChild(intervening);
8543 intervening->AddChild(render_surface2);
8544 render_surface2->AddChild(clip_child);
8545
8546 clip_child->SetClipParent(clip_parent.get());
8547
8548 intervening->SetMasksToBounds(true);
8549 clip_parent->SetMasksToBounds(true);
8550
8551 render_surface1->SetForceRenderSurface(true);
8552 render_surface2->SetForceRenderSurface(true);
8553
8554 gfx::Transform translation_transform;
8555 translation_transform.Translate(2, 2);
8556
8557 gfx::Transform identity_transform;
8558 SetLayerPropertiesForTesting(root.get(),
8559 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388560 gfx::PointF(),
8561 gfx::PointF(),
8562 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578563 true,
[email protected]420fdf6e2013-08-26 20:36:388564 false);
8565 SetLayerPropertiesForTesting(clip_parent.get(),
8566 translation_transform,
[email protected]420fdf6e2013-08-26 20:36:388567 gfx::PointF(),
8568 gfx::PointF(1.f, 1.f),
8569 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578570 true,
[email protected]420fdf6e2013-08-26 20:36:388571 false);
8572 SetLayerPropertiesForTesting(render_surface1.get(),
8573 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388574 gfx::PointF(),
8575 gfx::PointF(),
8576 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578577 true,
[email protected]420fdf6e2013-08-26 20:36:388578 false);
8579 SetLayerPropertiesForTesting(intervening.get(),
8580 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388581 gfx::PointF(),
8582 gfx::PointF(1.f, 1.f),
8583 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578584 true,
[email protected]420fdf6e2013-08-26 20:36:388585 false);
8586 SetLayerPropertiesForTesting(render_surface2.get(),
8587 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388588 gfx::PointF(),
8589 gfx::PointF(),
8590 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578591 true,
[email protected]420fdf6e2013-08-26 20:36:388592 false);
8593 SetLayerPropertiesForTesting(clip_child.get(),
8594 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388595 gfx::PointF(),
8596 gfx::PointF(-10.f, -10.f),
8597 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578598 true,
[email protected]420fdf6e2013-08-26 20:36:388599 false);
8600
8601 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8602 host->SetRootLayer(root);
8603
8604 ExecuteCalculateDrawProperties(root.get());
8605
8606 EXPECT_TRUE(root->render_surface());
8607 EXPECT_TRUE(render_surface1->render_surface());
8608 EXPECT_TRUE(render_surface2->render_surface());
8609
8610 // Since the render surfaces could have expanded, they should not clip (their
8611 // bounds would no longer be reliable). We should resort to layer clipping
8612 // in this case.
8613 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8614 render_surface1->render_surface()->clip_rect().ToString());
8615 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8616 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8617 render_surface2->render_surface()->clip_rect().ToString());
8618 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8619
8620 // NB: clip rects are in target space.
8621 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8622 render_surface1->clip_rect().ToString());
8623 EXPECT_TRUE(render_surface1->is_clipped());
8624
8625 // This value is inherited from the clipping ancestor layer, 'intervening'.
8626 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8627 render_surface2->clip_rect().ToString());
8628 EXPECT_TRUE(render_surface2->is_clipped());
8629
8630 // The content rects of both render surfaces should both have expanded to
8631 // contain the clip child.
8632 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8633 render_surface1->render_surface()->content_rect().ToString());
8634 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8635 render_surface2->render_surface()->content_rect().ToString());
8636
8637 // The clip child should have inherited the clip parent's clip (projected to
8638 // the right space, of course), and should have the correctly sized visible
8639 // content rect.
8640 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8641 clip_child->clip_rect().ToString());
8642 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
8643 clip_child->visible_content_rect().ToString());
8644 EXPECT_TRUE(clip_child->is_clipped());
8645}
8646
8647TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
8648 // Ensure that intervening render surfaces are not a problem, even if there
8649 // is a scroll involved. Note, we do _not_ have to consider any other sort
8650 // of transform.
8651 //
8652 // root (a render surface)
8653 // + clip_parent (masks to bounds)
8654 // + render_surface1 (sets opacity)
8655 // + intervening (masks to bounds AND scrolls)
8656 // + render_surface2 (also sets opacity)
8657 // + clip_child
8658 //
8659 scoped_refptr<Layer> root = Layer::Create();
8660 scoped_refptr<Layer> clip_parent = Layer::Create();
8661 scoped_refptr<Layer> render_surface1 = Layer::Create();
8662 scoped_refptr<Layer> intervening = Layer::Create();
8663 scoped_refptr<Layer> render_surface2 = Layer::Create();
8664 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8665 make_scoped_refptr(new LayerWithForcedDrawsContent);
8666
8667 root->AddChild(clip_parent);
8668 clip_parent->AddChild(render_surface1);
8669 render_surface1->AddChild(intervening);
8670 intervening->AddChild(render_surface2);
8671 render_surface2->AddChild(clip_child);
8672
8673 clip_child->SetClipParent(clip_parent.get());
8674
8675 intervening->SetMasksToBounds(true);
8676 clip_parent->SetMasksToBounds(true);
[email protected]adeda572014-01-31 00:49:478677 intervening->SetScrollClipLayerId(clip_parent->id());
[email protected]420fdf6e2013-08-26 20:36:388678 intervening->SetScrollOffset(gfx::Vector2d(3, 3));
8679
8680 render_surface1->SetForceRenderSurface(true);
8681 render_surface2->SetForceRenderSurface(true);
8682
8683 gfx::Transform translation_transform;
8684 translation_transform.Translate(2, 2);
8685
8686 gfx::Transform identity_transform;
8687 SetLayerPropertiesForTesting(root.get(),
8688 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388689 gfx::PointF(),
8690 gfx::PointF(),
8691 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578692 true,
[email protected]420fdf6e2013-08-26 20:36:388693 false);
8694 SetLayerPropertiesForTesting(clip_parent.get(),
8695 translation_transform,
[email protected]420fdf6e2013-08-26 20:36:388696 gfx::PointF(),
8697 gfx::PointF(1.f, 1.f),
8698 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578699 true,
[email protected]420fdf6e2013-08-26 20:36:388700 false);
8701 SetLayerPropertiesForTesting(render_surface1.get(),
8702 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388703 gfx::PointF(),
8704 gfx::PointF(),
8705 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578706 true,
[email protected]420fdf6e2013-08-26 20:36:388707 false);
8708 SetLayerPropertiesForTesting(intervening.get(),
8709 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388710 gfx::PointF(),
8711 gfx::PointF(1.f, 1.f),
8712 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578713 true,
[email protected]420fdf6e2013-08-26 20:36:388714 false);
8715 SetLayerPropertiesForTesting(render_surface2.get(),
8716 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388717 gfx::PointF(),
8718 gfx::PointF(),
8719 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578720 true,
[email protected]420fdf6e2013-08-26 20:36:388721 false);
8722 SetLayerPropertiesForTesting(clip_child.get(),
8723 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388724 gfx::PointF(),
8725 gfx::PointF(-10.f, -10.f),
8726 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578727 true,
[email protected]420fdf6e2013-08-26 20:36:388728 false);
8729
8730 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8731 host->SetRootLayer(root);
8732
8733 ExecuteCalculateDrawProperties(root.get());
8734
8735 EXPECT_TRUE(root->render_surface());
8736 EXPECT_TRUE(render_surface1->render_surface());
8737 EXPECT_TRUE(render_surface2->render_surface());
8738
8739 // Since the render surfaces could have expanded, they should not clip (their
8740 // bounds would no longer be reliable). We should resort to layer clipping
8741 // in this case.
8742 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8743 render_surface1->render_surface()->clip_rect().ToString());
8744 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8745 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8746 render_surface2->render_surface()->clip_rect().ToString());
8747 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8748
8749 // NB: clip rects are in target space.
8750 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8751 render_surface1->clip_rect().ToString());
8752 EXPECT_TRUE(render_surface1->is_clipped());
8753
8754 // This value is inherited from the clipping ancestor layer, 'intervening'.
8755 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
8756 render_surface2->clip_rect().ToString());
8757 EXPECT_TRUE(render_surface2->is_clipped());
8758
8759 // The content rects of both render surfaces should both have expanded to
8760 // contain the clip child.
8761 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8762 render_surface1->render_surface()->content_rect().ToString());
8763 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8764 render_surface2->render_surface()->content_rect().ToString());
8765
8766 // The clip child should have inherited the clip parent's clip (projected to
8767 // the right space, of course), and should have the correctly sized visible
8768 // content rect.
8769 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8770 clip_child->clip_rect().ToString());
8771 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
8772 clip_child->visible_content_rect().ToString());
8773 EXPECT_TRUE(clip_child->is_clipped());
8774}
8775
8776TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
8777 // Ensures that descendants of the clip child inherit the correct clip.
8778 //
8779 // root (a render surface)
8780 // + clip_parent (masks to bounds)
8781 // + intervening (masks to bounds)
8782 // + clip_child
8783 // + child
8784 //
8785 scoped_refptr<Layer> root = Layer::Create();
8786 scoped_refptr<Layer> clip_parent = Layer::Create();
8787 scoped_refptr<Layer> intervening = Layer::Create();
8788 scoped_refptr<Layer> clip_child = Layer::Create();
8789 scoped_refptr<LayerWithForcedDrawsContent> child =
8790 make_scoped_refptr(new LayerWithForcedDrawsContent);
8791
8792 root->AddChild(clip_parent);
8793 clip_parent->AddChild(intervening);
8794 intervening->AddChild(clip_child);
8795 clip_child->AddChild(child);
8796
8797 clip_child->SetClipParent(clip_parent.get());
8798
8799 intervening->SetMasksToBounds(true);
8800 clip_parent->SetMasksToBounds(true);
8801
8802 gfx::Transform identity_transform;
8803 SetLayerPropertiesForTesting(root.get(),
8804 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388805 gfx::PointF(),
8806 gfx::PointF(),
8807 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578808 true,
[email protected]420fdf6e2013-08-26 20:36:388809 false);
8810 SetLayerPropertiesForTesting(clip_parent.get(),
8811 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388812 gfx::PointF(),
8813 gfx::PointF(),
8814 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578815 true,
[email protected]420fdf6e2013-08-26 20:36:388816 false);
8817 SetLayerPropertiesForTesting(intervening.get(),
8818 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388819 gfx::PointF(),
8820 gfx::PointF(),
8821 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578822 true,
[email protected]420fdf6e2013-08-26 20:36:388823 false);
8824 SetLayerPropertiesForTesting(clip_child.get(),
8825 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388826 gfx::PointF(),
8827 gfx::PointF(),
8828 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578829 true,
[email protected]420fdf6e2013-08-26 20:36:388830 false);
8831 SetLayerPropertiesForTesting(child.get(),
8832 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388833 gfx::PointF(),
8834 gfx::PointF(),
8835 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578836 true,
[email protected]420fdf6e2013-08-26 20:36:388837 false);
8838
8839 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8840 host->SetRootLayer(root);
8841
8842 ExecuteCalculateDrawProperties(root.get());
8843
8844 EXPECT_TRUE(root->render_surface());
8845
8846 // Neither the clip child nor its descendant should have inherited the clip
8847 // from |intervening|.
8848 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8849 clip_child->clip_rect().ToString());
8850 EXPECT_TRUE(clip_child->is_clipped());
8851 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8852 child->visible_content_rect().ToString());
8853 EXPECT_TRUE(child->is_clipped());
8854}
8855
8856TEST_F(LayerTreeHostCommonTest,
8857 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
8858 // Ensures that non-descendant clip children in the tree do not affect
8859 // render surfaces.
8860 //
8861 // root (a render surface)
8862 // + clip_parent (masks to bounds)
8863 // + render_surface1
8864 // + clip_child
8865 // + render_surface2
8866 // + non_clip_child
8867 //
8868 // In this example render_surface2 should be unaffected by clip_child.
8869 scoped_refptr<Layer> root = Layer::Create();
8870 scoped_refptr<Layer> clip_parent = Layer::Create();
8871 scoped_refptr<Layer> render_surface1 = Layer::Create();
8872 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8873 make_scoped_refptr(new LayerWithForcedDrawsContent);
8874 scoped_refptr<Layer> render_surface2 = Layer::Create();
8875 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
8876 make_scoped_refptr(new LayerWithForcedDrawsContent);
8877
8878 root->AddChild(clip_parent);
8879 clip_parent->AddChild(render_surface1);
8880 render_surface1->AddChild(clip_child);
8881 clip_parent->AddChild(render_surface2);
8882 render_surface2->AddChild(non_clip_child);
8883
8884 clip_child->SetClipParent(clip_parent.get());
8885
8886 clip_parent->SetMasksToBounds(true);
8887 render_surface1->SetMasksToBounds(true);
8888
8889 gfx::Transform identity_transform;
8890 SetLayerPropertiesForTesting(root.get(),
8891 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388892 gfx::PointF(),
8893 gfx::PointF(),
8894 gfx::Size(15, 15),
[email protected]56fffdd2014-02-11 19:50:578895 true,
[email protected]420fdf6e2013-08-26 20:36:388896 false);
8897 SetLayerPropertiesForTesting(clip_parent.get(),
8898 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388899 gfx::PointF(),
8900 gfx::PointF(),
8901 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578902 true,
[email protected]420fdf6e2013-08-26 20:36:388903 false);
8904 SetLayerPropertiesForTesting(render_surface1.get(),
8905 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388906 gfx::PointF(),
8907 gfx::PointF(5, 5),
8908 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578909 true,
[email protected]420fdf6e2013-08-26 20:36:388910 false);
8911 SetLayerPropertiesForTesting(render_surface2.get(),
8912 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388913 gfx::PointF(),
8914 gfx::PointF(),
8915 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578916 true,
[email protected]420fdf6e2013-08-26 20:36:388917 false);
8918 SetLayerPropertiesForTesting(clip_child.get(),
8919 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388920 gfx::PointF(),
8921 gfx::PointF(-1, 1),
8922 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578923 true,
[email protected]420fdf6e2013-08-26 20:36:388924 false);
8925 SetLayerPropertiesForTesting(non_clip_child.get(),
8926 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388927 gfx::PointF(),
8928 gfx::PointF(),
8929 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578930 true,
[email protected]420fdf6e2013-08-26 20:36:388931 false);
8932
8933 render_surface1->SetForceRenderSurface(true);
8934 render_surface2->SetForceRenderSurface(true);
8935
8936 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8937 host->SetRootLayer(root);
8938
8939 ExecuteCalculateDrawProperties(root.get());
8940
8941 EXPECT_TRUE(root->render_surface());
8942 EXPECT_TRUE(render_surface1->render_surface());
8943 EXPECT_TRUE(render_surface2->render_surface());
8944
8945 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8946 render_surface1->clip_rect().ToString());
8947 EXPECT_TRUE(render_surface1->is_clipped());
8948
8949 // The render surface should not clip (it has unclipped descendants), instead
8950 // it should rely on layer clipping.
8951 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8952 render_surface1->render_surface()->clip_rect().ToString());
8953 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8954
8955 // That said, it should have grown to accomodate the unclipped descendant.
8956 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
8957 render_surface1->render_surface()->content_rect().ToString());
8958
8959 // This render surface should clip. It has no unclipped descendants.
8960 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8961 render_surface2->clip_rect().ToString());
8962 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
8963
8964 // It also shouldn't have grown to accomodate the clip child.
8965 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8966 render_surface2->render_surface()->content_rect().ToString());
8967
8968 // Sanity check our num_unclipped_descendants values.
8969 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
8970 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
8971}
8972
[email protected]45948712013-09-27 02:46:488973TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
8974 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458975 TestSharedBitmapManager shared_bitmap_manager;
8976 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]45948712013-09-27 02:46:488977 scoped_ptr<LayerImpl> root =
8978 LayerImpl::Create(host_impl.active_tree(), 12345);
8979 scoped_ptr<LayerImpl> child1 =
8980 LayerImpl::Create(host_impl.active_tree(), 123456);
8981 scoped_ptr<LayerImpl> child2 =
8982 LayerImpl::Create(host_impl.active_tree(), 1234567);
8983 scoped_ptr<LayerImpl> child3 =
8984 LayerImpl::Create(host_impl.active_tree(), 12345678);
8985
8986 gfx::Transform identity_matrix;
8987 gfx::PointF anchor;
8988 gfx::PointF position;
8989 gfx::Size bounds(100, 100);
8990 SetLayerPropertiesForTesting(root.get(),
8991 identity_matrix,
[email protected]45948712013-09-27 02:46:488992 anchor,
8993 position,
8994 bounds,
[email protected]56fffdd2014-02-11 19:50:578995 true,
[email protected]45948712013-09-27 02:46:488996 false);
8997 root->SetDrawsContent(true);
8998
8999 // This layer structure normally forces render surface due to preserves3d
9000 // behavior.
[email protected]45948712013-09-27 02:46:489001 SetLayerPropertiesForTesting(child1.get(),
9002 identity_matrix,
[email protected]45948712013-09-27 02:46:489003 anchor,
9004 position,
9005 bounds,
[email protected]56fffdd2014-02-11 19:50:579006 false,
9007 true);
[email protected]45948712013-09-27 02:46:489008 child1->SetDrawsContent(true);
9009 SetLayerPropertiesForTesting(child2.get(),
9010 identity_matrix,
[email protected]45948712013-09-27 02:46:489011 anchor,
9012 position,
9013 bounds,
[email protected]56fffdd2014-02-11 19:50:579014 true,
[email protected]45948712013-09-27 02:46:489015 false);
9016 child2->SetDrawsContent(true);
9017 SetLayerPropertiesForTesting(child3.get(),
9018 identity_matrix,
[email protected]45948712013-09-27 02:46:489019 anchor,
9020 position,
9021 bounds,
[email protected]56fffdd2014-02-11 19:50:579022 true,
[email protected]45948712013-09-27 02:46:489023 false);
9024 child3->SetDrawsContent(true);
9025
[email protected]56fffdd2014-02-11 19:50:579026 child2->SetIs3dSorted(true);
9027 child3->SetIs3dSorted(true);
9028
[email protected]45948712013-09-27 02:46:489029 child2->AddChild(child3.Pass());
9030 child1->AddChild(child2.Pass());
9031 root->AddChild(child1.Pass());
9032
9033 {
9034 LayerImplList render_surface_layer_list;
9035 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9036 root.get(), root->bounds(), &render_surface_layer_list);
9037 inputs.can_render_to_separate_surface = true;
9038 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9039
9040 EXPECT_EQ(2u, render_surface_layer_list.size());
9041 }
9042
9043 {
9044 LayerImplList render_surface_layer_list;
9045 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9046 root.get(), root->bounds(), &render_surface_layer_list);
9047 inputs.can_render_to_separate_surface = false;
9048 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9049
9050 EXPECT_EQ(1u, render_surface_layer_list.size());
9051 }
9052}
9053
[email protected]a9aa60a82013-08-29 04:28:269054TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
9055 scoped_refptr<Layer> root = Layer::Create();
9056 scoped_refptr<Layer> render_surface = Layer::Create();
9057 scoped_refptr<LayerWithForcedDrawsContent> child =
9058 make_scoped_refptr(new LayerWithForcedDrawsContent);
9059
9060 root->AddChild(render_surface);
9061 render_surface->AddChild(child);
9062
9063 gfx::Transform identity_transform;
9064 SetLayerPropertiesForTesting(root.get(),
9065 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:269066 gfx::PointF(),
9067 gfx::PointF(),
9068 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579069 true,
[email protected]a9aa60a82013-08-29 04:28:269070 false);
9071 SetLayerPropertiesForTesting(render_surface.get(),
9072 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:269073 gfx::PointF(),
9074 gfx::PointF(),
9075 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579076 false,
9077 true);
[email protected]a9aa60a82013-08-29 04:28:269078 SetLayerPropertiesForTesting(child.get(),
9079 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:269080 gfx::PointF(),
9081 gfx::PointF(),
9082 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:579083 true,
[email protected]a9aa60a82013-08-29 04:28:269084 false);
9085
[email protected]56fffdd2014-02-11 19:50:579086 root->SetShouldFlattenTransform(false);
9087 root->SetIs3dSorted(true);
[email protected]a9aa60a82013-08-29 04:28:269088 render_surface->SetDoubleSided(false);
9089 render_surface->SetForceRenderSurface(true);
9090
9091 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9092 host->SetRootLayer(root);
9093
9094 ExecuteCalculateDrawProperties(root.get());
9095
9096 EXPECT_EQ(2u, render_surface_layer_list()->size());
9097 EXPECT_EQ(1u,
9098 render_surface_layer_list()->at(0)
9099 ->render_surface()->layer_list().size());
9100 EXPECT_EQ(1u,
9101 render_surface_layer_list()->at(1)
9102 ->render_surface()->layer_list().size());
9103
9104 gfx::Transform rotation_transform = identity_transform;
9105 rotation_transform.RotateAboutXAxis(180.0);
9106
9107 render_surface->SetTransform(rotation_transform);
9108
9109 ExecuteCalculateDrawProperties(root.get());
9110
9111 EXPECT_EQ(1u, render_surface_layer_list()->size());
9112 EXPECT_EQ(0u,
9113 render_surface_layer_list()->at(0)
9114 ->render_surface()->layer_list().size());
9115}
9116
[email protected]995708c52013-10-17 20:52:599117TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
9118 // Checks that the simple case (being clipped by a scroll parent that would
9119 // have been processed before you anyhow) results in the right clips.
9120 //
9121 // + root
9122 // + scroll_parent_border
9123 // | + scroll_parent_clip
9124 // | + scroll_parent
9125 // + scroll_child
9126 //
9127 scoped_refptr<Layer> root = Layer::Create();
9128 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9129 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9130 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9131 make_scoped_refptr(new LayerWithForcedDrawsContent);
9132 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9133 make_scoped_refptr(new LayerWithForcedDrawsContent);
9134
9135 root->AddChild(scroll_child);
9136
9137 root->AddChild(scroll_parent_border);
9138 scroll_parent_border->AddChild(scroll_parent_clip);
9139 scroll_parent_clip->AddChild(scroll_parent);
9140
9141 scroll_parent_clip->SetMasksToBounds(true);
9142
9143 scroll_child->SetScrollParent(scroll_parent.get());
9144
9145 gfx::Transform identity_transform;
9146 SetLayerPropertiesForTesting(root.get(),
9147 identity_transform,
[email protected]995708c52013-10-17 20:52:599148 gfx::PointF(),
9149 gfx::PointF(),
9150 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579151 true,
[email protected]995708c52013-10-17 20:52:599152 false);
9153 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9154 identity_transform,
[email protected]995708c52013-10-17 20:52:599155 gfx::PointF(),
9156 gfx::PointF(),
9157 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579158 true,
[email protected]995708c52013-10-17 20:52:599159 false);
9160 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9161 identity_transform,
[email protected]995708c52013-10-17 20:52:599162 gfx::PointF(),
9163 gfx::PointF(),
9164 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579165 true,
[email protected]995708c52013-10-17 20:52:599166 false);
9167 SetLayerPropertiesForTesting(scroll_parent.get(),
9168 identity_transform,
[email protected]995708c52013-10-17 20:52:599169 gfx::PointF(),
9170 gfx::PointF(),
9171 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579172 true,
[email protected]995708c52013-10-17 20:52:599173 false);
9174 SetLayerPropertiesForTesting(scroll_child.get(),
9175 identity_transform,
[email protected]995708c52013-10-17 20:52:599176 gfx::PointF(),
9177 gfx::PointF(),
9178 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579179 true,
[email protected]995708c52013-10-17 20:52:599180 false);
9181
9182 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9183 host->SetRootLayer(root);
9184
9185 ExecuteCalculateDrawProperties(root.get());
9186
9187 EXPECT_TRUE(root->render_surface());
9188
9189 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
9190 scroll_child->clip_rect().ToString());
9191 EXPECT_TRUE(scroll_child->is_clipped());
9192}
9193
[email protected]08bdf1b2014-04-16 23:23:299194TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
9195 scoped_refptr<LayerWithForcedDrawsContent> root =
9196 make_scoped_refptr(new LayerWithForcedDrawsContent);
9197 scoped_refptr<LayerWithForcedDrawsContent> parent =
9198 make_scoped_refptr(new LayerWithForcedDrawsContent);
9199 scoped_refptr<LayerWithForcedDrawsContent> child =
9200 make_scoped_refptr(new LayerWithForcedDrawsContent);
9201
9202 root->AddChild(parent);
9203 parent->AddChild(child);
9204
9205 gfx::Transform identity_transform;
9206 SetLayerPropertiesForTesting(root.get(),
9207 identity_transform,
9208 gfx::PointF(),
9209 gfx::PointF(),
9210 gfx::Size(50, 50),
9211 true,
9212 true);
9213 root->SetForceRenderSurface(true);
9214 SetLayerPropertiesForTesting(parent.get(),
9215 identity_transform,
9216 gfx::PointF(),
9217 gfx::PointF(),
9218 gfx::Size(30, 30),
9219 true,
9220 true);
9221 parent->SetForceRenderSurface(true);
9222 SetLayerPropertiesForTesting(child.get(),
9223 identity_transform,
9224 gfx::PointF(),
9225 gfx::PointF(),
9226 gfx::Size(20, 20),
9227 true,
9228 true);
9229 child->SetForceRenderSurface(true);
9230
9231 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9232 host->SetRootLayer(root);
9233
9234 ExecuteCalculateDrawProperties(root.get());
9235
9236 EXPECT_EQ(3u, render_surface_layer_list()->size());
9237
9238 gfx::Transform singular_transform;
9239 singular_transform.Scale3d(
9240 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
9241
9242 child->SetTransform(singular_transform);
9243
9244 ExecuteCalculateDrawProperties(root.get());
9245
9246 EXPECT_EQ(2u, render_surface_layer_list()->size());
9247
9248 // Ensure that the entire subtree under a layer with singular transform does
9249 // not get rendered.
9250 parent->SetTransform(singular_transform);
9251 child->SetTransform(identity_transform);
9252
9253 ExecuteCalculateDrawProperties(root.get());
9254
9255 EXPECT_EQ(1u, render_surface_layer_list()->size());
9256}
9257
[email protected]995708c52013-10-17 20:52:599258TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
9259 // Checks that clipping by a scroll parent that follows you in paint order
9260 // still results in correct clipping.
9261 //
9262 // + root
9263 // + scroll_child
9264 // + scroll_parent_border
9265 // + scroll_parent_clip
9266 // + scroll_parent
9267 //
9268 scoped_refptr<Layer> root = Layer::Create();
9269 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9270 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9271 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9272 make_scoped_refptr(new LayerWithForcedDrawsContent);
9273 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9274 make_scoped_refptr(new LayerWithForcedDrawsContent);
9275
9276 root->AddChild(scroll_parent_border);
9277 scroll_parent_border->AddChild(scroll_parent_clip);
9278 scroll_parent_clip->AddChild(scroll_parent);
9279
9280 root->AddChild(scroll_child);
9281
9282 scroll_parent_clip->SetMasksToBounds(true);
9283
9284 scroll_child->SetScrollParent(scroll_parent.get());
9285
9286 gfx::Transform identity_transform;
9287 SetLayerPropertiesForTesting(root.get(),
9288 identity_transform,
[email protected]995708c52013-10-17 20:52:599289 gfx::PointF(),
9290 gfx::PointF(),
9291 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579292 true,
[email protected]995708c52013-10-17 20:52:599293 false);
9294 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9295 identity_transform,
[email protected]995708c52013-10-17 20:52:599296 gfx::PointF(),
9297 gfx::PointF(),
9298 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579299 true,
[email protected]995708c52013-10-17 20:52:599300 false);
9301 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9302 identity_transform,
[email protected]995708c52013-10-17 20:52:599303 gfx::PointF(),
9304 gfx::PointF(),
9305 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579306 true,
[email protected]995708c52013-10-17 20:52:599307 false);
9308 SetLayerPropertiesForTesting(scroll_parent.get(),
9309 identity_transform,
[email protected]995708c52013-10-17 20:52:599310 gfx::PointF(),
9311 gfx::PointF(),
9312 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579313 true,
[email protected]995708c52013-10-17 20:52:599314 false);
9315 SetLayerPropertiesForTesting(scroll_child.get(),
9316 identity_transform,
[email protected]995708c52013-10-17 20:52:599317 gfx::PointF(),
9318 gfx::PointF(),
9319 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579320 true,
[email protected]995708c52013-10-17 20:52:599321 false);
9322
9323 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9324 host->SetRootLayer(root);
9325
9326 ExecuteCalculateDrawProperties(root.get());
9327
9328 EXPECT_TRUE(root->render_surface());
9329
9330 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
9331 scroll_child->clip_rect().ToString());
9332 EXPECT_TRUE(scroll_child->is_clipped());
9333}
9334
9335TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
9336 // Checks that clipping by a scroll parent and scroll grandparent that follow
9337 // you in paint order still results in correct clipping.
9338 //
9339 // + root
9340 // + scroll_child
9341 // + scroll_parent_border
9342 // | + scroll_parent_clip
9343 // | + scroll_parent
9344 // + scroll_grandparent_border
9345 // + scroll_grandparent_clip
9346 // + scroll_grandparent
9347 //
9348 scoped_refptr<Layer> root = Layer::Create();
9349 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9350 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9351 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9352 make_scoped_refptr(new LayerWithForcedDrawsContent);
9353
9354 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
9355 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
9356 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
9357 make_scoped_refptr(new LayerWithForcedDrawsContent);
9358
9359 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9360 make_scoped_refptr(new LayerWithForcedDrawsContent);
9361
9362 root->AddChild(scroll_child);
9363
9364 root->AddChild(scroll_parent_border);
9365 scroll_parent_border->AddChild(scroll_parent_clip);
9366 scroll_parent_clip->AddChild(scroll_parent);
9367
9368 root->AddChild(scroll_grandparent_border);
9369 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
9370 scroll_grandparent_clip->AddChild(scroll_grandparent);
9371
9372 scroll_parent_clip->SetMasksToBounds(true);
9373 scroll_grandparent_clip->SetMasksToBounds(true);
9374
9375 scroll_child->SetScrollParent(scroll_parent.get());
9376 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
9377
9378 gfx::Transform identity_transform;
9379 SetLayerPropertiesForTesting(root.get(),
9380 identity_transform,
[email protected]995708c52013-10-17 20:52:599381 gfx::PointF(),
9382 gfx::PointF(),
9383 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579384 true,
[email protected]995708c52013-10-17 20:52:599385 false);
9386 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
9387 identity_transform,
[email protected]995708c52013-10-17 20:52:599388 gfx::PointF(),
9389 gfx::PointF(),
9390 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579391 true,
[email protected]995708c52013-10-17 20:52:599392 false);
9393 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
9394 identity_transform,
[email protected]995708c52013-10-17 20:52:599395 gfx::PointF(),
9396 gfx::PointF(),
9397 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:579398 true,
[email protected]995708c52013-10-17 20:52:599399 false);
9400 SetLayerPropertiesForTesting(scroll_grandparent.get(),
9401 identity_transform,
[email protected]995708c52013-10-17 20:52:599402 gfx::PointF(),
9403 gfx::PointF(),
9404 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579405 true,
[email protected]995708c52013-10-17 20:52:599406 false);
9407 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9408 identity_transform,
[email protected]995708c52013-10-17 20:52:599409 gfx::PointF(),
9410 gfx::PointF(),
9411 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579412 true,
[email protected]995708c52013-10-17 20:52:599413 false);
9414 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9415 identity_transform,
[email protected]995708c52013-10-17 20:52:599416 gfx::PointF(),
9417 gfx::PointF(),
9418 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579419 true,
[email protected]995708c52013-10-17 20:52:599420 false);
9421 SetLayerPropertiesForTesting(scroll_parent.get(),
9422 identity_transform,
[email protected]995708c52013-10-17 20:52:599423 gfx::PointF(),
9424 gfx::PointF(),
9425 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579426 true,
[email protected]995708c52013-10-17 20:52:599427 false);
9428 SetLayerPropertiesForTesting(scroll_child.get(),
9429 identity_transform,
[email protected]995708c52013-10-17 20:52:599430 gfx::PointF(),
9431 gfx::PointF(),
9432 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579433 true,
[email protected]995708c52013-10-17 20:52:599434 false);
9435
9436 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9437 host->SetRootLayer(root);
9438
9439 ExecuteCalculateDrawProperties(root.get());
9440
9441 EXPECT_TRUE(root->render_surface());
9442
9443 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
9444 scroll_child->clip_rect().ToString());
9445 EXPECT_TRUE(scroll_child->is_clipped());
9446
9447 // Despite the fact that we visited the above layers out of order to get the
9448 // correct clip, the layer lists should be unaffected.
9449 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
9450 EXPECT_EQ(scroll_child.get(),
9451 root->render_surface()->layer_list().at(0));
9452 EXPECT_EQ(scroll_parent.get(),
9453 root->render_surface()->layer_list().at(1));
9454 EXPECT_EQ(scroll_grandparent.get(),
9455 root->render_surface()->layer_list().at(2));
9456}
9457
9458TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
9459 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:229460 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:599461 // + root
9462 // + scroll_child
9463 // + scroll_parent_border
9464 // + scroll_parent_clip
9465 // + scroll_parent
9466 // + render_surface1
9467 // + scroll_grandparent_border
9468 // + scroll_grandparent_clip
9469 // + scroll_grandparent
9470 // + render_surface2
9471 //
[email protected]44d8e84c2013-10-19 19:13:229472 scoped_refptr<LayerWithForcedDrawsContent> root =
9473 make_scoped_refptr(new LayerWithForcedDrawsContent);
[email protected]995708c52013-10-17 20:52:599474
9475 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9476 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9477 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9478 make_scoped_refptr(new LayerWithForcedDrawsContent);
9479 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
9480 make_scoped_refptr(new LayerWithForcedDrawsContent);
9481
9482 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
9483 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
9484 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
9485 make_scoped_refptr(new LayerWithForcedDrawsContent);
9486 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
9487 make_scoped_refptr(new LayerWithForcedDrawsContent);
9488
9489 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9490 make_scoped_refptr(new LayerWithForcedDrawsContent);
9491
9492 root->AddChild(scroll_child);
9493
9494 root->AddChild(scroll_parent_border);
9495 scroll_parent_border->AddChild(scroll_parent_clip);
9496 scroll_parent_clip->AddChild(scroll_parent);
9497 scroll_parent->AddChild(render_surface2);
9498
9499 root->AddChild(scroll_grandparent_border);
9500 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
9501 scroll_grandparent_clip->AddChild(scroll_grandparent);
9502 scroll_grandparent->AddChild(render_surface1);
9503
9504 scroll_parent_clip->SetMasksToBounds(true);
9505 scroll_grandparent_clip->SetMasksToBounds(true);
9506
9507 scroll_child->SetScrollParent(scroll_parent.get());
9508 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
9509
9510 render_surface1->SetForceRenderSurface(true);
9511 render_surface2->SetForceRenderSurface(true);
9512
9513 gfx::Transform identity_transform;
9514 SetLayerPropertiesForTesting(root.get(),
9515 identity_transform,
[email protected]995708c52013-10-17 20:52:599516 gfx::PointF(),
9517 gfx::PointF(),
9518 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579519 true,
[email protected]995708c52013-10-17 20:52:599520 false);
9521 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
9522 identity_transform,
[email protected]995708c52013-10-17 20:52:599523 gfx::PointF(),
9524 gfx::PointF(),
9525 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579526 true,
[email protected]995708c52013-10-17 20:52:599527 false);
9528 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
9529 identity_transform,
[email protected]995708c52013-10-17 20:52:599530 gfx::PointF(),
9531 gfx::PointF(),
9532 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:579533 true,
[email protected]995708c52013-10-17 20:52:599534 false);
9535 SetLayerPropertiesForTesting(scroll_grandparent.get(),
9536 identity_transform,
[email protected]995708c52013-10-17 20:52:599537 gfx::PointF(),
9538 gfx::PointF(),
9539 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579540 true,
[email protected]995708c52013-10-17 20:52:599541 false);
9542 SetLayerPropertiesForTesting(render_surface1.get(),
9543 identity_transform,
[email protected]995708c52013-10-17 20:52:599544 gfx::PointF(),
9545 gfx::PointF(),
9546 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579547 true,
[email protected]995708c52013-10-17 20:52:599548 false);
9549 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9550 identity_transform,
[email protected]995708c52013-10-17 20:52:599551 gfx::PointF(),
9552 gfx::PointF(),
9553 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579554 true,
[email protected]995708c52013-10-17 20:52:599555 false);
9556 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9557 identity_transform,
[email protected]995708c52013-10-17 20:52:599558 gfx::PointF(),
9559 gfx::PointF(),
9560 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579561 true,
[email protected]995708c52013-10-17 20:52:599562 false);
9563 SetLayerPropertiesForTesting(scroll_parent.get(),
9564 identity_transform,
[email protected]995708c52013-10-17 20:52:599565 gfx::PointF(),
9566 gfx::PointF(),
9567 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579568 true,
[email protected]995708c52013-10-17 20:52:599569 false);
9570 SetLayerPropertiesForTesting(render_surface2.get(),
9571 identity_transform,
[email protected]995708c52013-10-17 20:52:599572 gfx::PointF(),
9573 gfx::PointF(),
9574 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579575 true,
[email protected]995708c52013-10-17 20:52:599576 false);
9577 SetLayerPropertiesForTesting(scroll_child.get(),
9578 identity_transform,
[email protected]995708c52013-10-17 20:52:599579 gfx::PointF(),
9580 gfx::PointF(),
9581 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579582 true,
[email protected]995708c52013-10-17 20:52:599583 false);
9584
9585 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9586 host->SetRootLayer(root);
9587
9588 RenderSurfaceLayerList render_surface_layer_list;
9589 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
9590 root.get(),
9591 root->bounds(),
9592 identity_transform,
9593 &render_surface_layer_list);
9594
9595 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9596
9597 EXPECT_TRUE(root->render_surface());
9598
9599 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
9600 scroll_child->clip_rect().ToString());
9601 EXPECT_TRUE(scroll_child->is_clipped());
9602
9603 // Despite the fact that we had to process the layers out of order to get the
9604 // right clip, our render_surface_layer_list's order should be unaffected.
9605 EXPECT_EQ(3u, render_surface_layer_list.size());
9606 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
9607 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
9608 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
[email protected]44d8e84c2013-10-19 19:13:229609 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
9610 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
9611 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:599612}
9613
9614TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) {
9615 // We rearrange layer list contributions if we have to visit children out of
9616 // order, but it should be a 'stable' rearrangement. That is, the layer list
9617 // additions for a single layer should not be reordered, though their position
9618 // wrt to the contributions due to a sibling may vary.
9619 //
9620 // + root
9621 // + scroll_child
9622 // + top_content
9623 // + bottom_content
9624 // + scroll_parent_border
9625 // + scroll_parent_clip
9626 // + scroll_parent
9627 //
9628 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:459629 TestSharedBitmapManager shared_bitmap_manager;
9630 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]995708c52013-10-17 20:52:599631 host_impl.CreatePendingTree();
9632 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9633 scoped_ptr<LayerImpl> scroll_parent_border =
9634 LayerImpl::Create(host_impl.active_tree(), 2);
9635 scoped_ptr<LayerImpl> scroll_parent_clip =
9636 LayerImpl::Create(host_impl.active_tree(), 3);
9637 scoped_ptr<LayerImpl> scroll_parent =
9638 LayerImpl::Create(host_impl.active_tree(), 4);
9639 scoped_ptr<LayerImpl> scroll_child =
9640 LayerImpl::Create(host_impl.active_tree(), 5);
9641 scoped_ptr<LayerImpl> bottom_content =
9642 LayerImpl::Create(host_impl.active_tree(), 6);
9643 scoped_ptr<LayerImpl> top_content =
9644 LayerImpl::Create(host_impl.active_tree(), 7);
9645
9646 scroll_parent_clip->SetMasksToBounds(true);
9647
9648 scroll_child->SetScrollParent(scroll_parent.get());
9649 scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>);
9650 scroll_children->insert(scroll_child.get());
9651 scroll_parent->SetScrollChildren(scroll_children.release());
9652
9653 scroll_child->SetDrawsContent(true);
9654 scroll_parent->SetDrawsContent(true);
9655 top_content->SetDrawsContent(true);
9656 bottom_content->SetDrawsContent(true);
9657
9658 gfx::Transform identity_transform;
9659 gfx::Transform top_transform;
9660 top_transform.Translate3d(0.0, 0.0, 5.0);
9661 gfx::Transform bottom_transform;
9662 bottom_transform.Translate3d(0.0, 0.0, 3.0);
9663
9664 SetLayerPropertiesForTesting(root.get(),
9665 identity_transform,
[email protected]995708c52013-10-17 20:52:599666 gfx::PointF(),
9667 gfx::PointF(),
9668 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579669 true,
[email protected]995708c52013-10-17 20:52:599670 false);
9671 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9672 identity_transform,
[email protected]995708c52013-10-17 20:52:599673 gfx::PointF(),
9674 gfx::PointF(),
9675 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579676 true,
[email protected]995708c52013-10-17 20:52:599677 false);
9678 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9679 identity_transform,
[email protected]995708c52013-10-17 20:52:599680 gfx::PointF(),
9681 gfx::PointF(),
9682 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579683 true,
[email protected]995708c52013-10-17 20:52:599684 false);
9685 SetLayerPropertiesForTesting(scroll_parent.get(),
9686 identity_transform,
[email protected]995708c52013-10-17 20:52:599687 gfx::PointF(),
9688 gfx::PointF(),
9689 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579690 true,
[email protected]995708c52013-10-17 20:52:599691 false);
9692 SetLayerPropertiesForTesting(scroll_child.get(),
9693 identity_transform,
[email protected]995708c52013-10-17 20:52:599694 gfx::PointF(),
9695 gfx::PointF(),
9696 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579697 true,
[email protected]995708c52013-10-17 20:52:599698 false);
9699 SetLayerPropertiesForTesting(top_content.get(),
9700 top_transform,
[email protected]995708c52013-10-17 20:52:599701 gfx::PointF(),
9702 gfx::PointF(),
9703 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579704 false,
9705 true);
[email protected]995708c52013-10-17 20:52:599706 SetLayerPropertiesForTesting(bottom_content.get(),
9707 bottom_transform,
[email protected]995708c52013-10-17 20:52:599708 gfx::PointF(),
9709 gfx::PointF(),
9710 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579711 false,
9712 true);
[email protected]995708c52013-10-17 20:52:599713
[email protected]56fffdd2014-02-11 19:50:579714 scroll_child->SetShouldFlattenTransform(false);
9715 scroll_child->SetIs3dSorted(true);
[email protected]995708c52013-10-17 20:52:599716
9717 scroll_child->AddChild(top_content.Pass());
9718 scroll_child->AddChild(bottom_content.Pass());
9719 root->AddChild(scroll_child.Pass());
9720
9721 scroll_parent_clip->AddChild(scroll_parent.Pass());
9722 scroll_parent_border->AddChild(scroll_parent_clip.Pass());
9723 root->AddChild(scroll_parent_border.Pass());
9724
9725 LayerImplList render_surface_layer_list;
9726 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9727 root.get(), root->bounds(), &render_surface_layer_list);
9728
9729 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9730
9731 EXPECT_TRUE(root->render_surface());
9732
9733 // If we don't sort by depth and let the layers get added in the order they
9734 // would normally be visited in, then layers 6 and 7 will be out of order. In
9735 // other words, although we've had to shift 5, 6, and 7 to appear before 4
9736 // in the list (because of the scroll parent relationship), this should not
9737 // have an effect on the the order of 5, 6, and 7 (which had been reordered
9738 // due to layer sorting).
9739 EXPECT_EQ(4u, root->render_surface()->layer_list().size());
9740 EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id());
9741 EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id());
9742 EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id());
9743 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
9744}
9745
[email protected]d81752b2013-10-25 08:32:239746TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
9747 // This test verifies that a scrolling layer that gets snapped to
9748 // integer coordinates doesn't move a fixed position child.
9749 //
9750 // + root
9751 // + container
9752 // + scroller
9753 // + fixed
9754 //
9755 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:459756 TestSharedBitmapManager shared_bitmap_manager;
9757 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]d81752b2013-10-25 08:32:239758 host_impl.CreatePendingTree();
9759 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9760 scoped_ptr<LayerImpl> container =
9761 LayerImpl::Create(host_impl.active_tree(), 2);
9762 LayerImpl* container_layer = container.get();
9763 scoped_ptr<LayerImpl> scroller =
9764 LayerImpl::Create(host_impl.active_tree(), 3);
9765 LayerImpl* scroll_layer = scroller.get();
9766 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
9767 LayerImpl* fixed_layer = fixed.get();
9768
9769 container->SetIsContainerForFixedPositionLayers(true);
9770
9771 LayerPositionConstraint constraint;
9772 constraint.set_is_fixed_position(true);
9773 fixed->SetPositionConstraint(constraint);
9774
[email protected]adeda572014-01-31 00:49:479775 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:239776
9777 gfx::Transform identity_transform;
9778 gfx::Transform container_transform;
9779 container_transform.Translate3d(10.0, 20.0, 0.0);
9780 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
9781
9782 SetLayerPropertiesForTesting(root.get(),
9783 identity_transform,
[email protected]d81752b2013-10-25 08:32:239784 gfx::PointF(),
9785 gfx::PointF(),
9786 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579787 true,
[email protected]d81752b2013-10-25 08:32:239788 false);
9789 SetLayerPropertiesForTesting(container.get(),
9790 container_transform,
[email protected]d81752b2013-10-25 08:32:239791 gfx::PointF(),
9792 gfx::PointF(),
9793 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579794 true,
[email protected]d81752b2013-10-25 08:32:239795 false);
9796 SetLayerPropertiesForTesting(scroller.get(),
9797 identity_transform,
[email protected]d81752b2013-10-25 08:32:239798 gfx::PointF(),
9799 gfx::PointF(),
9800 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579801 true,
[email protected]d81752b2013-10-25 08:32:239802 false);
9803 SetLayerPropertiesForTesting(fixed.get(),
9804 identity_transform,
[email protected]d81752b2013-10-25 08:32:239805 gfx::PointF(),
9806 gfx::PointF(),
9807 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579808 true,
[email protected]d81752b2013-10-25 08:32:239809 false);
9810
9811 scroller->AddChild(fixed.Pass());
9812 container->AddChild(scroller.Pass());
9813 root->AddChild(container.Pass());
9814
9815 // Rounded to integers already.
9816 {
9817 gfx::Vector2dF scroll_delta(3.0, 5.0);
9818 scroll_layer->SetScrollDelta(scroll_delta);
9819
9820 LayerImplList render_surface_layer_list;
9821 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9822 root.get(), root->bounds(), &render_surface_layer_list);
9823 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9824
9825 EXPECT_TRANSFORMATION_MATRIX_EQ(
9826 container_layer->draw_properties().screen_space_transform,
9827 fixed_layer->draw_properties().screen_space_transform);
9828 EXPECT_VECTOR_EQ(
9829 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9830 container_offset);
9831 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
9832 .screen_space_transform.To2dTranslation(),
9833 container_offset - scroll_delta);
9834 }
9835
9836 // Scroll delta requiring rounding.
9837 {
9838 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
9839 scroll_layer->SetScrollDelta(scroll_delta);
9840
9841 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
9842
9843 LayerImplList render_surface_layer_list;
9844 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9845 root.get(), root->bounds(), &render_surface_layer_list);
9846 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9847
9848 EXPECT_TRANSFORMATION_MATRIX_EQ(
9849 container_layer->draw_properties().screen_space_transform,
9850 fixed_layer->draw_properties().screen_space_transform);
9851 EXPECT_VECTOR_EQ(
9852 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9853 container_offset);
9854 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
9855 .screen_space_transform.To2dTranslation(),
9856 container_offset - rounded_scroll_delta);
9857 }
[email protected]cf15ad7b2014-04-02 03:59:269858
9859 // Scale is applied earlier in the tree.
9860 {
9861 gfx::Transform scaled_container_transform = container_transform;
9862 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
9863 container_layer->SetTransform(scaled_container_transform);
9864
9865 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
9866 scroll_layer->SetScrollDelta(scroll_delta);
9867
9868 LayerImplList render_surface_layer_list;
9869 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9870 root.get(), root->bounds(), &render_surface_layer_list);
9871 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9872
9873 EXPECT_TRANSFORMATION_MATRIX_EQ(
9874 container_layer->draw_properties().screen_space_transform,
9875 fixed_layer->draw_properties().screen_space_transform);
9876 EXPECT_VECTOR_EQ(
9877 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9878 container_offset);
9879
9880 container_layer->SetTransform(container_transform);
9881 }
9882
9883 // Scale is applied on the scroll layer itself.
9884 {
9885 gfx::Transform scale_transform;
9886 scale_transform.Scale3d(3.0, 3.0, 1.0);
9887 scroll_layer->SetTransform(scale_transform);
9888
9889 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
9890 scroll_layer->SetScrollDelta(scroll_delta);
9891
9892 LayerImplList render_surface_layer_list;
9893 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9894 root.get(), root->bounds(), &render_surface_layer_list);
9895 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9896
9897 EXPECT_VECTOR_EQ(
9898 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9899 container_offset);
9900
9901 scroll_layer->SetTransform(identity_transform);
9902 }
[email protected]d81752b2013-10-25 08:32:239903}
9904
[email protected]1c3626e2014-04-09 17:49:229905class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
9906 public:
9907 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
9908 LayerTreeImpl* tree_impl,
9909 int id) {
9910 return make_scoped_ptr(
9911 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
9912 }
9913
9914 virtual ~AnimationScaleFactorTrackingLayerImpl() {}
9915
9916 virtual void CalculateContentsScale(float ideal_contents_scale,
9917 float device_scale_factor,
9918 float page_scale_factor,
9919 float maximum_animation_contents_scale,
9920 bool animating_transform_to_screen,
9921 float* contents_scale_x,
9922 float* contents_scale_y,
9923 gfx::Size* content_bounds) OVERRIDE {
9924 last_maximum_animation_contents_scale_ = maximum_animation_contents_scale;
9925 LayerImpl::CalculateContentsScale(ideal_contents_scale,
9926 device_scale_factor,
9927 page_scale_factor,
9928 maximum_animation_contents_scale,
9929 animating_transform_to_screen,
9930 contents_scale_x,
9931 contents_scale_y,
9932 content_bounds);
9933 }
9934
9935 float last_maximum_animation_contents_scale() {
9936 return last_maximum_animation_contents_scale_;
9937 }
9938
9939 private:
9940 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
9941 int id)
9942 : LayerImpl(tree_impl, id), last_maximum_animation_contents_scale_(0.f) {
9943 SetDrawsContent(true);
9944 }
9945
9946 float last_maximum_animation_contents_scale_;
9947};
9948
9949TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
9950 FakeImplProxy proxy;
9951 TestSharedBitmapManager shared_bitmap_manager;
9952 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
9953 gfx::Transform identity_matrix;
9954 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
9955 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
9956 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
9957 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
9958 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
9959 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
9960 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
9961 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
9962
9963 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
9964 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
9965 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
9966
9967 child->AddChild(grand_child.PassAs<LayerImpl>());
9968 parent->AddChild(child.PassAs<LayerImpl>());
9969 grand_parent->AddChild(parent.PassAs<LayerImpl>());
9970
9971 SetLayerPropertiesForTesting(grand_parent.get(),
9972 identity_matrix,
9973 gfx::PointF(),
9974 gfx::PointF(),
9975 gfx::Size(1, 2),
9976 true,
9977 false);
9978 SetLayerPropertiesForTesting(parent_raw,
9979 identity_matrix,
9980 gfx::PointF(),
9981 gfx::PointF(),
9982 gfx::Size(1, 2),
9983 true,
9984 false);
9985 SetLayerPropertiesForTesting(child_raw,
9986 identity_matrix,
9987 gfx::PointF(),
9988 gfx::PointF(),
9989 gfx::Size(1, 2),
9990 true,
9991 false);
9992 SetLayerPropertiesForTesting(grand_child_raw,
9993 identity_matrix,
9994 gfx::PointF(),
9995 gfx::PointF(),
9996 gfx::Size(1, 2),
9997 true,
9998 false);
9999
10000 ExecuteCalculateDrawProperties(grand_parent.get());
10001
10002 // No layers have animations.
10003 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10004 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10005 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10006 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10007
10008 TransformOperations translation;
10009 translation.AppendTranslate(1.f, 2.f, 3.f);
10010
10011 AddAnimatedTransformToLayer(
10012 parent_raw, 1.0, TransformOperations(), translation);
10013
10014 // No layers have scale-affecting animations.
10015 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10016 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10017 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10018 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10019
10020 TransformOperations scale;
10021 scale.AppendScale(5.f, 4.f, 3.f);
10022
10023 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
10024 ExecuteCalculateDrawProperties(grand_parent.get());
10025
10026 // Only |child| has a scale-affecting animation.
10027 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10028 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10029 EXPECT_EQ(5.f, child_raw->last_maximum_animation_contents_scale());
10030 EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_contents_scale());
10031
10032 AddAnimatedTransformToLayer(
10033 grand_parent.get(), 1.0, TransformOperations(), scale);
10034 ExecuteCalculateDrawProperties(grand_parent.get());
10035
10036 // |grand_parent| and |child| have scale-affecting animations.
10037 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale());
10038 EXPECT_EQ(5.f, parent_raw->last_maximum_animation_contents_scale());
10039 // We don't support combining animated scales from two nodes; 0.f means
10040 // that the maximum scale could not be computed.
10041 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10042 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10043
10044 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
10045 ExecuteCalculateDrawProperties(grand_parent.get());
10046
10047 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
10048 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale());
10049 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10050 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10051 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10052
10053 grand_parent->layer_animation_controller()->AbortAnimations(
10054 Animation::Transform);
10055 parent_raw->layer_animation_controller()->AbortAnimations(
10056 Animation::Transform);
10057 child_raw->layer_animation_controller()->AbortAnimations(
10058 Animation::Transform);
10059
10060 TransformOperations perspective;
10061 perspective.AppendPerspective(10.f);
10062
10063 AddAnimatedTransformToLayer(
10064 child_raw, 1.0, TransformOperations(), perspective);
10065 ExecuteCalculateDrawProperties(grand_parent.get());
10066
10067 // |child| has a scale-affecting animation but computing the maximum of this
10068 // animation is not supported.
10069 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10070 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10071 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10072 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10073
10074 child_raw->layer_animation_controller()->AbortAnimations(
10075 Animation::Transform);
10076
10077 gfx::Transform scale_matrix;
10078 scale_matrix.Scale(1.f, 2.f);
10079 grand_parent->SetTransform(scale_matrix);
10080 parent_raw->SetTransform(scale_matrix);
10081 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
10082 ExecuteCalculateDrawProperties(grand_parent.get());
10083
10084 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
10085 // animation with maximum scale 5.f.
10086 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10087 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale());
10088 EXPECT_EQ(10.f, child_raw->last_maximum_animation_contents_scale());
10089 EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_contents_scale());
10090
10091 gfx::Transform perspective_matrix;
10092 perspective_matrix.ApplyPerspectiveDepth(2.f);
10093 child_raw->SetTransform(perspective_matrix);
10094 ExecuteCalculateDrawProperties(grand_parent.get());
10095
10096 // |child| has a transform that's neither a translation nor a scale.
10097 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10098 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale());
10099 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10100 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10101
10102 parent_raw->SetTransform(perspective_matrix);
10103 ExecuteCalculateDrawProperties(grand_parent.get());
10104
10105 // |parent| and |child| have transforms that are neither translations nor
10106 // scales.
10107 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10108 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10109 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10110 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10111
10112 parent_raw->SetTransform(identity_matrix);
10113 child_raw->SetTransform(identity_matrix);
10114 grand_parent->SetTransform(perspective_matrix);
10115
10116 ExecuteCalculateDrawProperties(grand_parent.get());
10117
10118 // |grand_parent| has a transform that's neither a translation nor a scale.
10119 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10120 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10121 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10122 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10123}
10124
[email protected]ba565742012-11-10 09:29:4810125} // namespace
10126} // namespace cc