blob: f4826de7e8bd3c1185e2e78aef33f2d24e8a8fd7 [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() {}
[email protected]276172b2014-05-02 21:03:03232 virtual void PaintContents(
233 SkCanvas* canvas,
234 const gfx::Rect& clip,
235 gfx::RectF* opaque,
236 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {}
[email protected]fb661802013-03-25 01:59:32237 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
[email protected]1d96e032014-03-25 05:59:08238 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
[email protected]f34a24232012-09-20 22:59:55239};
240
[email protected]fb661802013-03-25 01:59:32241scoped_refptr<ContentLayer> CreateDrawableContentLayer(
242 ContentLayerClient* delegate) {
243 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate);
244 to_return->SetIsDrawable(true);
245 return to_return;
[email protected]f34a24232012-09-20 22:59:55246}
247
[email protected]989386c2013-07-18 21:37:23248#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
249 do { \
250 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
251 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:47252 } while (false)
253
[email protected]989386c2013-07-18 21:37:23254TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32255 // Sanity check: For layers positioned at zero, with zero size,
256 // and with identity transforms, then the draw transform,
257 // screen space transform, and the hierarchy passed on to children
258 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14259
[email protected]fb661802013-03-25 01:59:32260 scoped_refptr<Layer> parent = Layer::Create();
261 scoped_refptr<Layer> child = Layer::Create();
262 scoped_refptr<Layer> grand_child = Layer::Create();
263 parent->AddChild(child);
264 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14265
[email protected]d600df7d2013-08-03 02:34:28266 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
267 host->SetRootLayer(parent);
268
[email protected]fb661802013-03-25 01:59:32269 gfx::Transform identity_matrix;
270 SetLayerPropertiesForTesting(parent.get(),
271 identity_matrix,
[email protected]fb661802013-03-25 01:59:32272 gfx::PointF(),
273 gfx::PointF(),
274 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:57275 true,
[email protected]fb661802013-03-25 01:59:32276 false);
277 SetLayerPropertiesForTesting(child.get(),
278 identity_matrix,
[email protected]fb661802013-03-25 01:59:32279 gfx::PointF(),
280 gfx::PointF(),
281 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57282 true,
[email protected]fb661802013-03-25 01:59:32283 false);
284 SetLayerPropertiesForTesting(grand_child.get(),
285 identity_matrix,
[email protected]fb661802013-03-25 01:59:32286 gfx::PointF(),
287 gfx::PointF(),
288 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57289 true,
[email protected]fb661802013-03-25 01:59:32290 false);
[email protected]94f206c12012-08-25 00:09:14291
[email protected]fb661802013-03-25 01:59:32292 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14293
[email protected]fb661802013-03-25 01:59:32294 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
295 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
296 child->screen_space_transform());
297 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
298 grand_child->draw_transform());
299 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
300 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14301}
302
[email protected]989386c2013-07-18 21:37:23303TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32304 gfx::Transform identity_matrix;
305 scoped_refptr<Layer> layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:14306
[email protected]fb661802013-03-25 01:59:32307 scoped_refptr<Layer> root = Layer::Create();
308 SetLayerPropertiesForTesting(root.get(),
309 identity_matrix,
[email protected]fb661802013-03-25 01:59:32310 gfx::PointF(),
311 gfx::PointF(),
312 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57313 true,
[email protected]fb661802013-03-25 01:59:32314 false);
315 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42316
[email protected]d600df7d2013-08-03 02:34:28317 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
318 host->SetRootLayer(root);
319
[email protected]fb661802013-03-25 01:59:32320 // Case 2: Setting the bounds of the layer should not affect either the draw
321 // transform or the screenspace transform.
322 gfx::Transform translation_to_center;
323 translation_to_center.Translate(5.0, 6.0);
324 SetLayerPropertiesForTesting(layer.get(),
325 identity_matrix,
[email protected]fb661802013-03-25 01:59:32326 gfx::PointF(),
327 gfx::PointF(),
328 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57329 true,
[email protected]fb661802013-03-25 01:59:32330 false);
331 ExecuteCalculateDrawProperties(root.get());
332 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
333 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
334 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14335
[email protected]fb661802013-03-25 01:59:32336 // Case 3: The anchor point by itself (without a layer transform) should have
337 // no effect on the transforms.
338 SetLayerPropertiesForTesting(layer.get(),
339 identity_matrix,
[email protected]fb661802013-03-25 01:59:32340 gfx::PointF(0.25f, 0.25f),
341 gfx::PointF(),
342 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57343 true,
[email protected]fb661802013-03-25 01:59:32344 false);
345 ExecuteCalculateDrawProperties(root.get());
346 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
347 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
348 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14349
[email protected]fb661802013-03-25 01:59:32350 // Case 4: A change in actual position affects both the draw transform and
351 // screen space transform.
352 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05353 position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32354 SetLayerPropertiesForTesting(layer.get(),
355 identity_matrix,
[email protected]fb661802013-03-25 01:59:32356 gfx::PointF(0.25f, 0.25f),
357 gfx::PointF(0.f, 1.2f),
358 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57359 true,
[email protected]fb661802013-03-25 01:59:32360 false);
361 ExecuteCalculateDrawProperties(root.get());
362 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
363 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
364 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14365
[email protected]fb661802013-03-25 01:59:32366 // Case 5: In the correct sequence of transforms, the layer transform should
367 // pre-multiply the translation_to_center. This is easily tested by using a
368 // scale transform, because scale and translation are not commutative.
369 gfx::Transform layer_transform;
370 layer_transform.Scale3d(2.0, 2.0, 1.0);
371 SetLayerPropertiesForTesting(layer.get(),
372 layer_transform,
[email protected]fb661802013-03-25 01:59:32373 gfx::PointF(),
374 gfx::PointF(),
375 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57376 true,
[email protected]fb661802013-03-25 01:59:32377 false);
378 ExecuteCalculateDrawProperties(root.get());
379 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
380 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
381 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14382
[email protected]fb661802013-03-25 01:59:32383 // Case 6: The layer transform should occur with respect to the anchor point.
384 gfx::Transform translation_to_anchor;
385 translation_to_anchor.Translate(5.0, 0.0);
386 gfx::Transform expected_result =
387 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
388 SetLayerPropertiesForTesting(layer.get(),
389 layer_transform,
[email protected]fb661802013-03-25 01:59:32390 gfx::PointF(0.5f, 0.f),
391 gfx::PointF(),
392 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57393 true,
[email protected]fb661802013-03-25 01:59:32394 false);
395 ExecuteCalculateDrawProperties(root.get());
396 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
397 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
398 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14399
[email protected]fb661802013-03-25 01:59:32400 // Case 7: Verify that position pre-multiplies the layer transform. The
401 // current implementation of CalculateDrawProperties does this implicitly, but
402 // it is still worth testing to detect accidental regressions.
403 expected_result = position_transform * translation_to_anchor *
404 layer_transform * Inverse(translation_to_anchor);
405 SetLayerPropertiesForTesting(layer.get(),
406 layer_transform,
[email protected]fb661802013-03-25 01:59:32407 gfx::PointF(0.5f, 0.f),
408 gfx::PointF(0.f, 1.2f),
409 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57410 true,
[email protected]fb661802013-03-25 01:59:32411 false);
412 ExecuteCalculateDrawProperties(root.get());
413 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
414 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
415 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14416}
417
[email protected]989386c2013-07-18 21:37:23418TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
[email protected]fb661802013-03-25 01:59:32419 const gfx::Vector2d kScrollOffset(50, 100);
420 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01421 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32422 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
423 -kScrollOffset.y());
424 const float kPageScale = 0.888f;
425 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20426
[email protected]fb661802013-03-25 01:59:32427 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:45428 TestSharedBitmapManager shared_bitmap_manager;
429 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]657b24c2013-03-06 09:01:20430
[email protected]fb661802013-03-25 01:59:32431 gfx::Transform identity_matrix;
432 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
433 LayerImpl::Create(host_impl.active_tree(), 1));
434 LayerImpl* sublayer = sublayer_scoped_ptr.get();
435 sublayer->SetContentsScale(kPageScale * kDeviceScale,
436 kPageScale * kDeviceScale);
437 SetLayerPropertiesForTesting(sublayer,
438 identity_matrix,
[email protected]fb661802013-03-25 01:59:32439 gfx::Point(),
440 gfx::PointF(),
441 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:57442 true,
[email protected]fb661802013-03-25 01:59:32443 false);
[email protected]657b24c2013-03-06 09:01:20444
[email protected]adeda572014-01-31 00:49:47445 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32446 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47447 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
[email protected]fb661802013-03-25 01:59:32448 SetLayerPropertiesForTesting(scroll_layer,
449 identity_matrix,
[email protected]fb661802013-03-25 01:59:32450 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47451 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32452 gfx::Size(10, 20),
[email protected]56fffdd2014-02-11 19:50:57453 true,
[email protected]fb661802013-03-25 01:59:32454 false);
[email protected]adeda572014-01-31 00:49:47455 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
456 LayerImpl::Create(host_impl.active_tree(), 4));
457 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
458
459 scroll_layer->SetScrollClipLayer(clip_layer->id());
460 clip_layer->SetBounds(
461 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
462 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
463 scroll_layer->SetScrollClipLayer(clip_layer->id());
[email protected]fb661802013-03-25 01:59:32464 scroll_layer->SetScrollDelta(kScrollDelta);
465 gfx::Transform impl_transform;
[email protected]fb661802013-03-25 01:59:32466 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
[email protected]adeda572014-01-31 00:49:47467 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
468 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
469 scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20470
[email protected]fb661802013-03-25 01:59:32471 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
472 SetLayerPropertiesForTesting(root.get(),
473 identity_matrix,
[email protected]fb661802013-03-25 01:59:32474 gfx::PointF(),
475 gfx::PointF(),
476 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:57477 true,
[email protected]fb661802013-03-25 01:59:32478 false);
[email protected]adeda572014-01-31 00:49:47479 root->AddChild(clip_layer_scoped_ptr.Pass());
[email protected]657b24c2013-03-06 09:01:20480
[email protected]f2136262013-04-26 21:10:19481 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32482 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32483 gfx::Transform expected_transform = identity_matrix;
484 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
485 sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
486 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
487 MathUtil::Round(sub_layer_screen_position.y()));
488 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
489 sublayer->draw_transform());
490 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
491 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20492
[email protected]fb661802013-03-25 01:59:32493 gfx::Transform arbitrary_translate;
494 const float kTranslateX = 10.6f;
495 const float kTranslateY = 20.6f;
496 arbitrary_translate.Translate(kTranslateX, kTranslateY);
497 SetLayerPropertiesForTesting(scroll_layer,
498 arbitrary_translate,
[email protected]fb661802013-03-25 01:59:32499 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47500 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32501 gfx::Size(10, 20),
[email protected]56fffdd2014-02-11 19:50:57502 true,
[email protected]fb661802013-03-25 01:59:32503 false);
[email protected]f2136262013-04-26 21:10:19504 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32505 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32506 expected_transform.MakeIdentity();
507 expected_transform.Translate(
508 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
509 sub_layer_screen_position.x()),
510 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
511 sub_layer_screen_position.y()));
512 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
513 sublayer->draw_transform());
[email protected]657b24c2013-03-06 09:01:20514}
515
[email protected]989386c2013-07-18 21:37:23516TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32517 gfx::Transform identity_matrix;
518 scoped_refptr<Layer> root = Layer::Create();
519 scoped_refptr<Layer> parent = Layer::Create();
520 scoped_refptr<Layer> child = Layer::Create();
521 scoped_refptr<Layer> grand_child = Layer::Create();
522 root->AddChild(parent);
523 parent->AddChild(child);
524 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14525
[email protected]d600df7d2013-08-03 02:34:28526 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
527 host->SetRootLayer(root);
528
[email protected]fb661802013-03-25 01:59:32529 // One-time setup of root layer
530 SetLayerPropertiesForTesting(root.get(),
531 identity_matrix,
[email protected]fb661802013-03-25 01:59:32532 gfx::PointF(),
533 gfx::PointF(),
534 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57535 true,
[email protected]fb661802013-03-25 01:59:32536 false);
[email protected]ecc12622012-10-30 20:45:42537
[email protected]fb661802013-03-25 01:59:32538 // Case 1: parent's anchor point should not affect child or grand_child.
539 SetLayerPropertiesForTesting(parent.get(),
540 identity_matrix,
[email protected]fb661802013-03-25 01:59:32541 gfx::PointF(0.25f, 0.25f),
542 gfx::PointF(),
543 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57544 true,
[email protected]fb661802013-03-25 01:59:32545 false);
546 SetLayerPropertiesForTesting(child.get(),
547 identity_matrix,
[email protected]fb661802013-03-25 01:59:32548 gfx::PointF(),
549 gfx::PointF(),
550 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57551 true,
[email protected]fb661802013-03-25 01:59:32552 false);
553 SetLayerPropertiesForTesting(grand_child.get(),
554 identity_matrix,
[email protected]fb661802013-03-25 01:59:32555 gfx::PointF(),
556 gfx::PointF(),
557 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57558 true,
[email protected]fb661802013-03-25 01:59:32559 false);
560 ExecuteCalculateDrawProperties(root.get());
561 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
562 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
563 child->screen_space_transform());
564 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
565 grand_child->draw_transform());
566 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
567 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14568
[email protected]fb661802013-03-25 01:59:32569 // Case 2: parent's position affects child and grand_child.
570 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05571 parent_position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32572 SetLayerPropertiesForTesting(parent.get(),
573 identity_matrix,
[email protected]fb661802013-03-25 01:59:32574 gfx::PointF(0.25f, 0.25f),
575 gfx::PointF(0.f, 1.2f),
576 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57577 true,
[email protected]fb661802013-03-25 01:59:32578 false);
579 SetLayerPropertiesForTesting(child.get(),
580 identity_matrix,
[email protected]fb661802013-03-25 01:59:32581 gfx::PointF(),
582 gfx::PointF(),
583 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57584 true,
[email protected]fb661802013-03-25 01:59:32585 false);
586 SetLayerPropertiesForTesting(grand_child.get(),
587 identity_matrix,
[email protected]fb661802013-03-25 01:59:32588 gfx::PointF(),
589 gfx::PointF(),
590 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57591 true,
[email protected]fb661802013-03-25 01:59:32592 false);
593 ExecuteCalculateDrawProperties(root.get());
594 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
595 child->draw_transform());
596 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
597 child->screen_space_transform());
598 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
599 grand_child->draw_transform());
600 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
601 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14602
[email protected]fb661802013-03-25 01:59:32603 // Case 3: parent's local transform affects child and grandchild
604 gfx::Transform parent_layer_transform;
605 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
606 gfx::Transform parent_translation_to_anchor;
607 parent_translation_to_anchor.Translate(2.5, 3.0);
608 gfx::Transform parent_composite_transform =
609 parent_translation_to_anchor * parent_layer_transform *
610 Inverse(parent_translation_to_anchor);
611 SetLayerPropertiesForTesting(parent.get(),
612 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32613 gfx::PointF(0.25f, 0.25f),
614 gfx::PointF(),
615 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57616 true,
[email protected]fb661802013-03-25 01:59:32617 false);
618 SetLayerPropertiesForTesting(child.get(),
619 identity_matrix,
[email protected]fb661802013-03-25 01:59:32620 gfx::PointF(),
621 gfx::PointF(),
622 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57623 true,
[email protected]fb661802013-03-25 01:59:32624 false);
625 SetLayerPropertiesForTesting(grand_child.get(),
626 identity_matrix,
[email protected]fb661802013-03-25 01:59:32627 gfx::PointF(),
628 gfx::PointF(),
629 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57630 true,
[email protected]fb661802013-03-25 01:59:32631 false);
632 ExecuteCalculateDrawProperties(root.get());
633 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
634 child->draw_transform());
635 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
636 child->screen_space_transform());
637 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
638 grand_child->draw_transform());
639 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
640 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14641}
642
[email protected]989386c2013-07-18 21:37:23643TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
[email protected]fb661802013-03-25 01:59:32644 scoped_refptr<Layer> root = Layer::Create();
645 scoped_refptr<Layer> parent = Layer::Create();
646 scoped_refptr<Layer> child = Layer::Create();
647 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
648 make_scoped_refptr(new LayerWithForcedDrawsContent());
649 root->AddChild(parent);
650 parent->AddChild(child);
651 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14652
[email protected]d600df7d2013-08-03 02:34:28653 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
654 host->SetRootLayer(root);
655
[email protected]fb661802013-03-25 01:59:32656 // One-time setup of root layer
657 gfx::Transform identity_matrix;
658 SetLayerPropertiesForTesting(root.get(),
659 identity_matrix,
[email protected]fb661802013-03-25 01:59:32660 gfx::PointF(),
661 gfx::PointF(),
662 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57663 true,
[email protected]fb661802013-03-25 01:59:32664 false);
[email protected]ecc12622012-10-30 20:45:42665
[email protected]fb661802013-03-25 01:59:32666 // Child is set up so that a new render surface should be created.
667 child->SetOpacity(0.5f);
668 child->SetForceRenderSurface(true);
[email protected]94f206c12012-08-25 00:09:14669
[email protected]fb661802013-03-25 01:59:32670 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05671 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32672 gfx::Transform parent_translation_to_anchor;
673 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44674
[email protected]fb661802013-03-25 01:59:32675 gfx::Transform parent_composite_transform =
676 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39677 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32678 gfx::Vector2dF parent_composite_scale =
679 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
680 1.f);
681 gfx::Transform surface_sublayer_transform;
682 surface_sublayer_transform.Scale(parent_composite_scale.x(),
683 parent_composite_scale.y());
684 gfx::Transform surface_sublayer_composite_transform =
685 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14686
[email protected]fb661802013-03-25 01:59:32687 // Child's render surface should not exist yet.
688 ASSERT_FALSE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:14689
[email protected]fb661802013-03-25 01:59:32690 SetLayerPropertiesForTesting(parent.get(),
691 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32692 gfx::PointF(0.25f, 0.25f),
693 gfx::PointF(),
694 gfx::Size(100, 120),
[email protected]56fffdd2014-02-11 19:50:57695 true,
[email protected]fb661802013-03-25 01:59:32696 false);
697 SetLayerPropertiesForTesting(child.get(),
698 identity_matrix,
[email protected]fb661802013-03-25 01:59:32699 gfx::PointF(),
700 gfx::PointF(),
701 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57702 true,
[email protected]fb661802013-03-25 01:59:32703 false);
704 SetLayerPropertiesForTesting(grand_child.get(),
705 identity_matrix,
[email protected]fb661802013-03-25 01:59:32706 gfx::PointF(),
707 gfx::PointF(),
708 gfx::Size(8, 10),
[email protected]56fffdd2014-02-11 19:50:57709 true,
[email protected]fb661802013-03-25 01:59:32710 false);
711 ExecuteCalculateDrawProperties(root.get());
[email protected]94f206c12012-08-25 00:09:14712
[email protected]fb661802013-03-25 01:59:32713 // Render surface should have been created now.
714 ASSERT_TRUE(child->render_surface());
715 ASSERT_EQ(child, child->render_target());
[email protected]94f206c12012-08-25 00:09:14716
[email protected]fb661802013-03-25 01:59:32717 // The child layer's draw transform should refer to its new render surface.
718 // The screen-space transform, however, should still refer to the root.
719 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
720 child->draw_transform());
721 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
722 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14723
[email protected]fb661802013-03-25 01:59:32724 // Because the grand_child is the only drawable content, the child's render
725 // surface will tighten its bounds to the grand_child. The scale at which the
726 // surface's subtree is drawn must be removed from the composite transform.
727 EXPECT_TRANSFORMATION_MATRIX_EQ(
728 surface_sublayer_composite_transform,
729 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14730
[email protected]fb661802013-03-25 01:59:32731 // The screen space is the same as the target since the child surface draws
732 // into the root.
733 EXPECT_TRANSFORMATION_MATRIX_EQ(
734 surface_sublayer_composite_transform,
735 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14736}
737
[email protected]989386c2013-07-18 21:37:23738TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
[email protected]fb661802013-03-25 01:59:32739 scoped_refptr<Layer> root = Layer::Create();
740 scoped_refptr<Layer> parent = Layer::Create();
741 scoped_refptr<Layer> child = Layer::Create();
742 scoped_refptr<Layer> child_replica = Layer::Create();
743 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
744 make_scoped_refptr(new LayerWithForcedDrawsContent());
745 root->AddChild(parent);
746 parent->AddChild(child);
747 child->AddChild(grand_child);
748 child->SetReplicaLayer(child_replica.get());
749
[email protected]d600df7d2013-08-03 02:34:28750 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
751 host->SetRootLayer(root);
752
[email protected]fb661802013-03-25 01:59:32753 // One-time setup of root layer
754 gfx::Transform identity_matrix;
755 SetLayerPropertiesForTesting(root.get(),
756 identity_matrix,
[email protected]fb661802013-03-25 01:59:32757 gfx::PointF(),
758 gfx::PointF(),
759 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57760 true,
[email protected]fb661802013-03-25 01:59:32761 false);
762
763 // Child is set up so that a new render surface should be created.
764 child->SetOpacity(0.5f);
765
766 gfx::Transform parent_layer_transform;
767 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
768 gfx::Transform parent_translation_to_anchor;
769 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32770 gfx::Transform parent_composite_transform =
771 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39772 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32773 gfx::Transform replica_layer_transform;
774 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
775 gfx::Vector2dF parent_composite_scale =
776 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
777 1.f);
778 gfx::Transform surface_sublayer_transform;
779 surface_sublayer_transform.Scale(parent_composite_scale.x(),
780 parent_composite_scale.y());
781 gfx::Transform replica_composite_transform =
782 parent_composite_transform * replica_layer_transform *
783 Inverse(surface_sublayer_transform);
784
785 // Child's render surface should not exist yet.
786 ASSERT_FALSE(child->render_surface());
787
788 SetLayerPropertiesForTesting(parent.get(),
789 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32790 gfx::PointF(0.25f, 0.25f),
791 gfx::PointF(),
792 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57793 true,
[email protected]fb661802013-03-25 01:59:32794 false);
795 SetLayerPropertiesForTesting(child.get(),
796 identity_matrix,
[email protected]fb661802013-03-25 01:59:32797 gfx::PointF(),
798 gfx::PointF(),
799 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57800 true,
[email protected]fb661802013-03-25 01:59:32801 false);
802 SetLayerPropertiesForTesting(grand_child.get(),
803 identity_matrix,
[email protected]fb661802013-03-25 01:59:32804 gfx::PointF(),
805 gfx::PointF(-0.5f, -0.5f),
806 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:57807 true,
[email protected]fb661802013-03-25 01:59:32808 false);
809 SetLayerPropertiesForTesting(child_replica.get(),
810 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:32811 gfx::PointF(),
812 gfx::PointF(),
813 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57814 true,
[email protected]fb661802013-03-25 01:59:32815 false);
816 ExecuteCalculateDrawProperties(root.get());
817
818 // Render surface should have been created now.
819 ASSERT_TRUE(child->render_surface());
820 ASSERT_EQ(child, child->render_target());
821
822 EXPECT_TRANSFORMATION_MATRIX_EQ(
823 replica_composite_transform,
824 child->render_target()->render_surface()->replica_draw_transform());
825 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57826 child->render_target()
827 ->render_surface()
[email protected]fb661802013-03-25 01:59:32828 ->replica_screen_space_transform());
829}
830
[email protected]989386c2013-07-18 21:37:23831TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32832 // This test creates a more complex tree and verifies it all at once. This
833 // covers the following cases:
834 // - layers that are described w.r.t. a render surface: should have draw
835 // transforms described w.r.t. that surface
836 // - A render surface described w.r.t. an ancestor render surface: should
837 // have a draw transform described w.r.t. that ancestor surface
838 // - Replicas of a render surface are described w.r.t. the replica's
839 // transform around its anchor, along with the surface itself.
840 // - Sanity check on recursion: verify transforms of layers described w.r.t.
841 // a render surface that is described w.r.t. an ancestor render surface.
842 // - verifying that each layer has a reference to the correct render surface
843 // and render target values.
844
845 scoped_refptr<Layer> root = Layer::Create();
846 scoped_refptr<Layer> parent = Layer::Create();
847 scoped_refptr<Layer> render_surface1 = Layer::Create();
848 scoped_refptr<Layer> render_surface2 = Layer::Create();
849 scoped_refptr<Layer> child_of_root = Layer::Create();
850 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
851 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
852 scoped_refptr<Layer> replica_of_rs1 = Layer::Create();
853 scoped_refptr<Layer> replica_of_rs2 = Layer::Create();
854 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
855 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
856 make_scoped_refptr(new LayerWithForcedDrawsContent());
857 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
858 make_scoped_refptr(new LayerWithForcedDrawsContent());
859 root->AddChild(parent);
860 parent->AddChild(render_surface1);
861 parent->AddChild(child_of_root);
862 render_surface1->AddChild(child_of_rs1);
863 render_surface1->AddChild(render_surface2);
864 render_surface2->AddChild(child_of_rs2);
865 child_of_root->AddChild(grand_child_of_root);
866 child_of_rs1->AddChild(grand_child_of_rs1);
867 child_of_rs2->AddChild(grand_child_of_rs2);
868 render_surface1->SetReplicaLayer(replica_of_rs1.get());
869 render_surface2->SetReplicaLayer(replica_of_rs2.get());
870
[email protected]d600df7d2013-08-03 02:34:28871 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
872 host->SetRootLayer(root);
873
[email protected]fb661802013-03-25 01:59:32874 // In combination with descendant draws content, opacity != 1 forces the layer
875 // to have a new render surface.
876 render_surface1->SetOpacity(0.5f);
877 render_surface2->SetOpacity(0.33f);
878
879 // One-time setup of root layer
880 gfx::Transform identity_matrix;
881 SetLayerPropertiesForTesting(root.get(),
882 identity_matrix,
[email protected]fb661802013-03-25 01:59:32883 gfx::PointF(),
884 gfx::PointF(),
885 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57886 true,
[email protected]fb661802013-03-25 01:59:32887 false);
888
889 // All layers in the tree are initialized with an anchor at .25 and a size of
890 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39891 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32892 gfx::Transform translation_to_anchor;
893 translation_to_anchor.Translate(2.5, 0.0);
894 gfx::Transform layer_transform;
895 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32896 gfx::Transform replica_layer_transform;
897 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
898
899 gfx::Transform A =
900 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32901 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
902 Inverse(translation_to_anchor);
903
904 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39905 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32906 gfx::Transform surface1_sublayer_transform;
907 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
908 surface1_parent_transform_scale.y());
909
910 // SS1 = transform given to the subtree of render_surface1
911 gfx::Transform SS1 = surface1_sublayer_transform;
912 // S1 = transform to move from render_surface1 pixels to the layer space of
913 // the owning layer
914 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
915
916 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39917 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32918 gfx::Transform surface2_sublayer_transform;
919 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
920 surface2_parent_transform_scale.y());
921
922 // SS2 = transform given to the subtree of render_surface2
923 gfx::Transform SS2 = surface2_sublayer_transform;
924 // S2 = transform to move from render_surface2 pixels to the layer space of
925 // the owning layer
926 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
927
928 SetLayerPropertiesForTesting(parent.get(),
929 layer_transform,
[email protected]fb661802013-03-25 01:59:32930 gfx::PointF(0.25f, 0.f),
931 gfx::PointF(),
932 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57933 true,
[email protected]fb661802013-03-25 01:59:32934 false);
935 SetLayerPropertiesForTesting(render_surface1.get(),
936 layer_transform,
[email protected]fb661802013-03-25 01:59:32937 gfx::PointF(0.25f, 0.f),
938 gfx::PointF(),
939 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57940 true,
[email protected]fb661802013-03-25 01:59:32941 false);
942 SetLayerPropertiesForTesting(render_surface2.get(),
943 layer_transform,
[email protected]fb661802013-03-25 01:59:32944 gfx::PointF(0.25f, 0.f),
945 gfx::PointF(),
946 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57947 true,
[email protected]fb661802013-03-25 01:59:32948 false);
949 SetLayerPropertiesForTesting(child_of_root.get(),
950 layer_transform,
[email protected]fb661802013-03-25 01:59:32951 gfx::PointF(0.25f, 0.f),
952 gfx::PointF(),
953 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57954 true,
[email protected]fb661802013-03-25 01:59:32955 false);
956 SetLayerPropertiesForTesting(child_of_rs1.get(),
957 layer_transform,
[email protected]fb661802013-03-25 01:59:32958 gfx::PointF(0.25f, 0.f),
959 gfx::PointF(),
960 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57961 true,
[email protected]fb661802013-03-25 01:59:32962 false);
963 SetLayerPropertiesForTesting(child_of_rs2.get(),
964 layer_transform,
[email protected]fb661802013-03-25 01:59:32965 gfx::PointF(0.25f, 0.f),
966 gfx::PointF(),
967 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57968 true,
[email protected]fb661802013-03-25 01:59:32969 false);
970 SetLayerPropertiesForTesting(grand_child_of_root.get(),
971 layer_transform,
[email protected]fb661802013-03-25 01:59:32972 gfx::PointF(0.25f, 0.f),
973 gfx::PointF(),
974 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57975 true,
[email protected]fb661802013-03-25 01:59:32976 false);
977 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
978 layer_transform,
[email protected]fb661802013-03-25 01:59:32979 gfx::PointF(0.25f, 0.f),
980 gfx::PointF(),
981 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57982 true,
[email protected]fb661802013-03-25 01:59:32983 false);
984 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
985 layer_transform,
[email protected]fb661802013-03-25 01:59:32986 gfx::PointF(0.25f, 0.f),
987 gfx::PointF(),
988 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57989 true,
[email protected]fb661802013-03-25 01:59:32990 false);
991 SetLayerPropertiesForTesting(replica_of_rs1.get(),
992 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:32993 gfx::PointF(0.25f, 0.f),
994 gfx::PointF(),
995 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57996 true,
[email protected]fb661802013-03-25 01:59:32997 false);
998 SetLayerPropertiesForTesting(replica_of_rs2.get(),
999 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:321000 gfx::PointF(0.25f, 0.f),
1001 gfx::PointF(),
1002 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:571003 true,
[email protected]fb661802013-03-25 01:59:321004 false);
1005
1006 ExecuteCalculateDrawProperties(root.get());
1007
1008 // Only layers that are associated with render surfaces should have an actual
1009 // RenderSurface() value.
1010 ASSERT_TRUE(root->render_surface());
1011 ASSERT_FALSE(child_of_root->render_surface());
1012 ASSERT_FALSE(grand_child_of_root->render_surface());
1013
1014 ASSERT_TRUE(render_surface1->render_surface());
1015 ASSERT_FALSE(child_of_rs1->render_surface());
1016 ASSERT_FALSE(grand_child_of_rs1->render_surface());
1017
1018 ASSERT_TRUE(render_surface2->render_surface());
1019 ASSERT_FALSE(child_of_rs2->render_surface());
1020 ASSERT_FALSE(grand_child_of_rs2->render_surface());
1021
1022 // Verify all render target accessors
1023 EXPECT_EQ(root, parent->render_target());
1024 EXPECT_EQ(root, child_of_root->render_target());
1025 EXPECT_EQ(root, grand_child_of_root->render_target());
1026
1027 EXPECT_EQ(render_surface1, render_surface1->render_target());
1028 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
1029 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
1030
1031 EXPECT_EQ(render_surface2, render_surface2->render_target());
1032 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
1033 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
1034
1035 // Verify layer draw transforms note that draw transforms are described with
1036 // respect to the nearest ancestor render surface but screen space transforms
1037 // are described with respect to the root.
1038 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
[email protected]baf64d062014-02-16 22:10:391039 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform());
1040 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321041 grand_child_of_root->draw_transform());
1042
1043 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
[email protected]baf64d062014-02-16 22:10:391044 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform());
1045 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
[email protected]fb661802013-03-25 01:59:321046 grand_child_of_rs1->draw_transform());
1047
1048 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
[email protected]baf64d062014-02-16 22:10:391049 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform());
1050 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
[email protected]fb661802013-03-25 01:59:321051 grand_child_of_rs2->draw_transform());
1052
1053 // Verify layer screen-space transforms
1054 //
1055 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391056 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:321057 child_of_root->screen_space_transform());
1058 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391059 A * A * A, grand_child_of_root->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321060
[email protected]baf64d062014-02-16 22:10:391061 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:321062 render_surface1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391063 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321064 child_of_rs1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391065 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:321066 grand_child_of_rs1->screen_space_transform());
1067
[email protected]baf64d062014-02-16 22:10:391068 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321069 render_surface2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391070 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:321071 child_of_rs2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391072 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
[email protected]fb661802013-03-25 01:59:321073 grand_child_of_rs2->screen_space_transform());
1074
1075 // Verify render surface transforms.
1076 //
1077 // Draw transform of render surface 1 is described with respect to root.
1078 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391079 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321080 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391081 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:321082 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391083 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321084 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391085 A * R * S1,
[email protected]fb661802013-03-25 01:59:321086 render_surface1->render_surface()->replica_screen_space_transform());
1087 // Draw transform of render surface 2 is described with respect to render
1088 // surface 1.
1089 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391090 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321091 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391092 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:321093 render_surface2->render_surface()->replica_draw_transform());
1094 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391095 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:321096 render_surface2->render_surface()->screen_space_transform());
1097 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391098 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:321099 render_surface2->render_surface()->replica_screen_space_transform());
1100
1101 // Sanity check. If these fail there is probably a bug in the test itself. It
1102 // is expected that we correctly set up transforms so that the y-component of
1103 // the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:261104 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
1105 EXPECT_FLOAT_EQ(2.0,
1106 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321107 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261108 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321109
[email protected]803f6b52013-09-12 00:51:261110 EXPECT_FLOAT_EQ(2.0,
1111 render_surface1->screen_space_transform().matrix().get(1, 3));
1112 EXPECT_FLOAT_EQ(3.0,
1113 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321114 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261115 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321116
[email protected]803f6b52013-09-12 00:51:261117 EXPECT_FLOAT_EQ(3.0,
1118 render_surface2->screen_space_transform().matrix().get(1, 3));
1119 EXPECT_FLOAT_EQ(4.0,
1120 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321121 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261122 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321123}
1124
[email protected]989386c2013-07-18 21:37:231125TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321126 // For layers that flatten their subtree, there should be an orthographic
1127 // projection (for x and y values) in the middle of the transform sequence.
1128 // Note that the way the code is currently implemented, it is not expected to
1129 // use a canonical orthographic projection.
1130
1131 scoped_refptr<Layer> root = Layer::Create();
1132 scoped_refptr<Layer> child = Layer::Create();
1133 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1134 make_scoped_refptr(new LayerWithForcedDrawsContent());
1135
1136 gfx::Transform rotation_about_y_axis;
1137 rotation_about_y_axis.RotateAboutYAxis(30.0);
1138
1139 const gfx::Transform identity_matrix;
1140 SetLayerPropertiesForTesting(root.get(),
1141 identity_matrix,
[email protected]fb661802013-03-25 01:59:321142 gfx::PointF(),
1143 gfx::PointF(),
1144 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571145 true,
[email protected]fb661802013-03-25 01:59:321146 false);
1147 SetLayerPropertiesForTesting(child.get(),
1148 rotation_about_y_axis,
[email protected]fb661802013-03-25 01:59:321149 gfx::PointF(),
1150 gfx::PointF(),
1151 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571152 true,
[email protected]fb661802013-03-25 01:59:321153 false);
1154 SetLayerPropertiesForTesting(grand_child.get(),
1155 rotation_about_y_axis,
[email protected]fb661802013-03-25 01:59:321156 gfx::PointF(),
1157 gfx::PointF(),
1158 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571159 true,
[email protected]fb661802013-03-25 01:59:321160 false);
1161
1162 root->AddChild(child);
1163 child->AddChild(grand_child);
1164 child->SetForceRenderSurface(true);
1165
[email protected]d600df7d2013-08-03 02:34:281166 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1167 host->SetRootLayer(root);
1168
[email protected]fb661802013-03-25 01:59:321169 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:571170 ASSERT_TRUE(root->should_flatten_transform());
1171 ASSERT_TRUE(child->should_flatten_transform());
1172 ASSERT_TRUE(grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:321173
1174 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1175 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1176 gfx::Transform expected_grand_child_draw_transform =
1177 rotation_about_y_axis; // draws onto child's render surface
1178 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1179 flattened_rotation_about_y.FlattenTo2d();
1180 gfx::Transform expected_grand_child_screen_space_transform =
1181 flattened_rotation_about_y * rotation_about_y_axis;
1182
1183 ExecuteCalculateDrawProperties(root.get());
1184
1185 // The child's draw transform should have been taken by its surface.
1186 ASSERT_TRUE(child->render_surface());
1187 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1188 child->render_surface()->draw_transform());
1189 EXPECT_TRANSFORMATION_MATRIX_EQ(
1190 expected_child_screen_space_transform,
1191 child->render_surface()->screen_space_transform());
1192 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1193 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1194 child->screen_space_transform());
1195 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1196 grand_child->draw_transform());
1197 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1198 grand_child->screen_space_transform());
1199}
1200
[email protected]989386c2013-07-18 21:37:231201TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321202 // A layer that is empty in one axis, but not the other, was accidentally
1203 // skipping a necessary translation. Without that translation, the coordinate
1204 // space of the layer's draw transform is incorrect.
1205 //
1206 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1207 // but if that layer becomes a render surface, then its draw transform is
1208 // implicitly inherited by the rest of the subtree, which then is positioned
1209 // incorrectly as a result.
1210
1211 scoped_refptr<Layer> root = Layer::Create();
1212 scoped_refptr<Layer> child = Layer::Create();
1213 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1214 make_scoped_refptr(new LayerWithForcedDrawsContent());
1215
1216 // The child height is zero, but has non-zero width that should be accounted
1217 // for while computing draw transforms.
1218 const gfx::Transform identity_matrix;
1219 SetLayerPropertiesForTesting(root.get(),
1220 identity_matrix,
[email protected]fb661802013-03-25 01:59:321221 gfx::PointF(),
1222 gfx::PointF(),
1223 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571224 true,
[email protected]fb661802013-03-25 01:59:321225 false);
1226 SetLayerPropertiesForTesting(child.get(),
1227 identity_matrix,
[email protected]fb661802013-03-25 01:59:321228 gfx::PointF(),
1229 gfx::PointF(),
1230 gfx::Size(10, 0),
[email protected]56fffdd2014-02-11 19:50:571231 true,
[email protected]fb661802013-03-25 01:59:321232 false);
1233 SetLayerPropertiesForTesting(grand_child.get(),
1234 identity_matrix,
[email protected]fb661802013-03-25 01:59:321235 gfx::PointF(),
1236 gfx::PointF(),
1237 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571238 true,
[email protected]fb661802013-03-25 01:59:321239 false);
1240
1241 root->AddChild(child);
1242 child->AddChild(grand_child);
1243 child->SetForceRenderSurface(true);
1244
[email protected]d600df7d2013-08-03 02:34:281245 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1246 host->SetRootLayer(root);
1247
[email protected]fb661802013-03-25 01:59:321248 ExecuteCalculateDrawProperties(root.get());
1249
1250 ASSERT_TRUE(child->render_surface());
1251 // This is the real test, the rest are sanity checks.
1252 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1253 child->render_surface()->draw_transform());
1254 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1255 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1256 grand_child->draw_transform());
1257}
1258
[email protected]989386c2013-07-18 21:37:231259TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321260 // Transformations applied at the root of the tree should be forwarded
1261 // to child layers instead of applied to the root RenderSurface.
1262 const gfx::Transform identity_matrix;
[email protected]d5754282014-04-09 00:43:291263 scoped_refptr<LayerWithForcedDrawsContent> root =
1264 new LayerWithForcedDrawsContent;
1265 scoped_refptr<LayerWithForcedDrawsContent> child =
1266 new LayerWithForcedDrawsContent;
[email protected]adeda572014-01-31 00:49:471267 child->SetScrollClipLayerId(root->id());
[email protected]f224cc92013-06-06 23:23:321268 root->AddChild(child);
1269
[email protected]d600df7d2013-08-03 02:34:281270 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1271 host->SetRootLayer(root);
1272
[email protected]f224cc92013-06-06 23:23:321273 SetLayerPropertiesForTesting(root.get(),
1274 identity_matrix,
[email protected]f224cc92013-06-06 23:23:321275 gfx::PointF(),
1276 gfx::PointF(),
1277 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571278 true,
[email protected]f224cc92013-06-06 23:23:321279 false);
1280 SetLayerPropertiesForTesting(child.get(),
1281 identity_matrix,
[email protected]f224cc92013-06-06 23:23:321282 gfx::PointF(),
1283 gfx::PointF(),
1284 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571285 true,
[email protected]f224cc92013-06-06 23:23:321286 false);
1287
[email protected]f224cc92013-06-06 23:23:321288 gfx::Transform translate;
1289 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231290 {
1291 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531292 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1293 root.get(), root->bounds(), translate, &render_surface_layer_list);
1294 inputs.can_adjust_raster_scales = true;
1295 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231296 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1297 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1298 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291299 EXPECT_EQ(1.f, root->last_device_scale_factor());
1300 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231301 }
[email protected]f224cc92013-06-06 23:23:321302
1303 gfx::Transform scale;
1304 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231305 {
1306 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531307 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1308 root.get(), root->bounds(), scale, &render_surface_layer_list);
1309 inputs.can_adjust_raster_scales = true;
1310 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231311 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1312 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1313 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291314 EXPECT_EQ(2.f, root->last_device_scale_factor());
1315 EXPECT_EQ(2.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231316 }
[email protected]f224cc92013-06-06 23:23:321317
1318 gfx::Transform rotate;
1319 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231320 {
1321 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531322 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1323 root.get(), root->bounds(), rotate, &render_surface_layer_list);
1324 inputs.can_adjust_raster_scales = true;
1325 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231326 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1327 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1328 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291329 EXPECT_EQ(1.f, root->last_device_scale_factor());
1330 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231331 }
[email protected]f224cc92013-06-06 23:23:321332
1333 gfx::Transform composite;
1334 composite.ConcatTransform(translate);
1335 composite.ConcatTransform(scale);
1336 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231337 {
1338 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531339 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1340 root.get(), root->bounds(), composite, &render_surface_layer_list);
1341 inputs.can_adjust_raster_scales = true;
1342 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231343 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1344 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1345 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1346 }
[email protected]f224cc92013-06-06 23:23:321347
[email protected]9781afa2013-07-17 23:15:321348 // Verify it composes correctly with device scale.
1349 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231350
1351 {
1352 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531353 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1354 root.get(), root->bounds(), translate, &render_surface_layer_list);
1355 inputs.device_scale_factor = device_scale_factor;
1356 inputs.can_adjust_raster_scales = true;
1357 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231358 gfx::Transform device_scaled_translate = translate;
1359 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1360 EXPECT_EQ(device_scaled_translate,
1361 root->draw_properties().target_space_transform);
1362 EXPECT_EQ(device_scaled_translate,
1363 child->draw_properties().target_space_transform);
1364 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291365 EXPECT_EQ(device_scale_factor, root->last_device_scale_factor());
1366 EXPECT_EQ(device_scale_factor, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231367 }
[email protected]9781afa2013-07-17 23:15:321368
1369 // Verify it composes correctly with page scale.
1370 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231371
1372 {
1373 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531374 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1375 root.get(), root->bounds(), translate, &render_surface_layer_list);
1376 inputs.page_scale_factor = page_scale_factor;
1377 inputs.page_scale_application_layer = root.get();
1378 inputs.can_adjust_raster_scales = true;
1379 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231380 gfx::Transform page_scaled_translate = translate;
1381 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1382 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1383 EXPECT_EQ(page_scaled_translate,
1384 child->draw_properties().target_space_transform);
1385 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291386 EXPECT_EQ(1.f, root->last_device_scale_factor());
1387 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231388 }
[email protected]9781afa2013-07-17 23:15:321389
[email protected]f224cc92013-06-06 23:23:321390 // Verify that it composes correctly with transforms directly on root layer.
1391 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231392
1393 {
1394 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531395 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1396 root.get(), root->bounds(), composite, &render_surface_layer_list);
1397 inputs.can_adjust_raster_scales = true;
1398 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231399 gfx::Transform compositeSquared = composite;
1400 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261401 EXPECT_TRANSFORMATION_MATRIX_EQ(
1402 compositeSquared, root->draw_properties().target_space_transform);
1403 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391404 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231405 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1406 }
[email protected]f224cc92013-06-06 23:23:321407}
1408
[email protected]989386c2013-07-18 21:37:231409TEST_F(LayerTreeHostCommonTest,
1410 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321411 scoped_refptr<Layer> parent = Layer::Create();
1412 scoped_refptr<Layer> render_surface1 = Layer::Create();
1413 scoped_refptr<LayerWithForcedDrawsContent> child =
1414 make_scoped_refptr(new LayerWithForcedDrawsContent());
1415
[email protected]d600df7d2013-08-03 02:34:281416 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1417 host->SetRootLayer(parent);
1418
[email protected]fb661802013-03-25 01:59:321419 const gfx::Transform identity_matrix;
1420 SetLayerPropertiesForTesting(parent.get(),
1421 identity_matrix,
[email protected]fb661802013-03-25 01:59:321422 gfx::PointF(),
1423 gfx::PointF(),
1424 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571425 true,
[email protected]fb661802013-03-25 01:59:321426 false);
1427 SetLayerPropertiesForTesting(render_surface1.get(),
1428 identity_matrix,
[email protected]fb661802013-03-25 01:59:321429 gfx::PointF(),
1430 gfx::PointF(),
1431 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571432 true,
[email protected]fb661802013-03-25 01:59:321433 false);
1434 SetLayerPropertiesForTesting(child.get(),
1435 identity_matrix,
[email protected]fb661802013-03-25 01:59:321436 gfx::PointF(),
1437 gfx::PointF(30.f, 30.f),
1438 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571439 true,
[email protected]fb661802013-03-25 01:59:321440 false);
1441
1442 parent->AddChild(render_surface1);
1443 parent->SetMasksToBounds(true);
1444 render_surface1->AddChild(child);
1445 render_surface1->SetForceRenderSurface(true);
1446
[email protected]989386c2013-07-18 21:37:231447 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531448 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1449 parent.get(),
1450 parent->bounds(),
1451 gfx::Transform(),
1452 &render_surface_layer_list);
1453 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321454
1455 // The child layer's content is entirely outside the parent's clip rect, so
1456 // the intermediate render surface should not be listed here, even if it was
1457 // forced to be created. Render surfaces without children or visible content
1458 // are unexpected at draw time (e.g. we might try to create a content texture
1459 // of size 0).
1460 ASSERT_TRUE(parent->render_surface());
[email protected]fb661802013-03-25 01:59:321461 EXPECT_EQ(1U, render_surface_layer_list.size());
1462}
1463
[email protected]989386c2013-07-18 21:37:231464TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321465 scoped_refptr<Layer> parent = Layer::Create();
1466 scoped_refptr<Layer> render_surface1 = Layer::Create();
1467 scoped_refptr<LayerWithForcedDrawsContent> child =
1468 make_scoped_refptr(new LayerWithForcedDrawsContent());
1469
[email protected]d600df7d2013-08-03 02:34:281470 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1471 host->SetRootLayer(parent);
1472
[email protected]fb661802013-03-25 01:59:321473 const gfx::Transform identity_matrix;
1474 SetLayerPropertiesForTesting(render_surface1.get(),
1475 identity_matrix,
[email protected]fb661802013-03-25 01:59:321476 gfx::PointF(),
1477 gfx::PointF(),
1478 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571479 true,
[email protected]fb661802013-03-25 01:59:321480 false);
1481 SetLayerPropertiesForTesting(child.get(),
1482 identity_matrix,
[email protected]fb661802013-03-25 01:59:321483 gfx::PointF(),
1484 gfx::PointF(),
1485 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571486 true,
[email protected]fb661802013-03-25 01:59:321487 false);
1488
1489 parent->AddChild(render_surface1);
1490 render_surface1->AddChild(child);
1491 render_surface1->SetForceRenderSurface(true);
1492 render_surface1->SetOpacity(0.f);
1493
[email protected]989386c2013-07-18 21:37:231494 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531495 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1496 parent.get(), parent->bounds(), &render_surface_layer_list);
1497 inputs.can_adjust_raster_scales = true;
1498 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321499
1500 // Since the layer is transparent, render_surface1->render_surface() should
1501 // not have gotten added anywhere. Also, the drawable content rect should not
1502 // have been extended by the children.
1503 ASSERT_TRUE(parent->render_surface());
1504 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1505 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231506 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321507 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1508}
1509
[email protected]989386c2013-07-18 21:37:231510TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321511 scoped_refptr<Layer> parent = Layer::Create();
1512 scoped_refptr<Layer> render_surface1 = Layer::Create();
1513 scoped_refptr<LayerWithForcedDrawsContent> child =
1514 make_scoped_refptr(new LayerWithForcedDrawsContent());
1515 render_surface1->SetForceRenderSurface(true);
1516
[email protected]d600df7d2013-08-03 02:34:281517 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1518 host->SetRootLayer(parent);
1519
[email protected]fb661802013-03-25 01:59:321520 const gfx::Transform identity_matrix;
1521 SetLayerPropertiesForTesting(parent.get(),
1522 identity_matrix,
[email protected]fb661802013-03-25 01:59:321523 gfx::PointF(),
1524 gfx::PointF(),
1525 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571526 true,
[email protected]fb661802013-03-25 01:59:321527 false);
1528 SetLayerPropertiesForTesting(render_surface1.get(),
1529 identity_matrix,
[email protected]fb661802013-03-25 01:59:321530 gfx::PointF(),
1531 gfx::PointF(),
1532 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571533 true,
[email protected]fb661802013-03-25 01:59:321534 false);
1535 SetLayerPropertiesForTesting(child.get(),
1536 identity_matrix,
[email protected]fb661802013-03-25 01:59:321537 gfx::PointF(),
1538 gfx::PointF(),
1539 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571540 true,
[email protected]fb661802013-03-25 01:59:321541 false);
1542
1543 parent->AddChild(render_surface1);
1544 render_surface1->AddChild(child);
1545
1546 // Sanity check before the actual test
1547 EXPECT_FALSE(parent->render_surface());
1548 EXPECT_FALSE(render_surface1->render_surface());
1549
[email protected]989386c2013-07-18 21:37:231550 {
1551 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531552 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1553 parent.get(), parent->bounds(), &render_surface_layer_list);
1554 inputs.can_adjust_raster_scales = true;
1555 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321556
[email protected]989386c2013-07-18 21:37:231557 // The root layer always creates a render surface
1558 EXPECT_TRUE(parent->render_surface());
1559 EXPECT_TRUE(render_surface1->render_surface());
1560 EXPECT_EQ(2U, render_surface_layer_list.size());
1561 }
[email protected]fb661802013-03-25 01:59:321562
[email protected]989386c2013-07-18 21:37:231563 {
1564 RenderSurfaceLayerList render_surface_layer_list;
1565 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531566 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1567 parent.get(), parent->bounds(), &render_surface_layer_list);
1568 inputs.can_adjust_raster_scales = true;
1569 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231570 EXPECT_TRUE(parent->render_surface());
1571 EXPECT_FALSE(render_surface1->render_surface());
1572 EXPECT_EQ(1U, render_surface_layer_list.size());
1573 }
[email protected]fb661802013-03-25 01:59:321574}
1575
[email protected]989386c2013-07-18 21:37:231576TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321577 // The entire subtree of layers that are outside the clip rect should be
1578 // culled away, and should not affect the render_surface_layer_list.
1579 //
1580 // The test tree is set up as follows:
1581 // - all layers except the leaf_nodes are forced to be a new render surface
1582 // that have something to draw.
1583 // - parent is a large container layer.
1584 // - child has masksToBounds=true to cause clipping.
1585 // - grand_child is positioned outside of the child's bounds
1586 // - great_grand_child is also kept outside child's bounds.
1587 //
1588 // In this configuration, grand_child and great_grand_child are completely
1589 // outside the clip rect, and they should never get scheduled on the list of
1590 // render surfaces.
1591 //
1592
1593 const gfx::Transform identity_matrix;
1594 scoped_refptr<Layer> parent = Layer::Create();
1595 scoped_refptr<Layer> child = Layer::Create();
1596 scoped_refptr<Layer> grand_child = Layer::Create();
1597 scoped_refptr<Layer> great_grand_child = Layer::Create();
1598 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1599 make_scoped_refptr(new LayerWithForcedDrawsContent());
1600 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1601 make_scoped_refptr(new LayerWithForcedDrawsContent());
1602 parent->AddChild(child);
1603 child->AddChild(grand_child);
1604 grand_child->AddChild(great_grand_child);
1605
[email protected]d600df7d2013-08-03 02:34:281606 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1607 host->SetRootLayer(parent);
1608
[email protected]fb661802013-03-25 01:59:321609 // leaf_node1 ensures that parent and child are kept on the
1610 // render_surface_layer_list, even though grand_child and great_grand_child
1611 // should be clipped.
1612 child->AddChild(leaf_node1);
1613 great_grand_child->AddChild(leaf_node2);
1614
1615 SetLayerPropertiesForTesting(parent.get(),
1616 identity_matrix,
[email protected]fb661802013-03-25 01:59:321617 gfx::PointF(),
1618 gfx::PointF(),
1619 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571620 true,
[email protected]fb661802013-03-25 01:59:321621 false);
1622 SetLayerPropertiesForTesting(child.get(),
1623 identity_matrix,
[email protected]fb661802013-03-25 01:59:321624 gfx::PointF(),
1625 gfx::PointF(),
1626 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571627 true,
[email protected]fb661802013-03-25 01:59:321628 false);
1629 SetLayerPropertiesForTesting(grand_child.get(),
1630 identity_matrix,
[email protected]fb661802013-03-25 01:59:321631 gfx::PointF(),
1632 gfx::PointF(45.f, 45.f),
1633 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571634 true,
[email protected]fb661802013-03-25 01:59:321635 false);
1636 SetLayerPropertiesForTesting(great_grand_child.get(),
1637 identity_matrix,
[email protected]fb661802013-03-25 01:59:321638 gfx::PointF(),
1639 gfx::PointF(),
1640 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571641 true,
[email protected]fb661802013-03-25 01:59:321642 false);
1643 SetLayerPropertiesForTesting(leaf_node1.get(),
1644 identity_matrix,
[email protected]fb661802013-03-25 01:59:321645 gfx::PointF(),
1646 gfx::PointF(),
1647 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571648 true,
[email protected]fb661802013-03-25 01:59:321649 false);
1650 SetLayerPropertiesForTesting(leaf_node2.get(),
1651 identity_matrix,
[email protected]fb661802013-03-25 01:59:321652 gfx::PointF(),
1653 gfx::PointF(),
1654 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571655 true,
[email protected]fb661802013-03-25 01:59:321656 false);
1657
1658 child->SetMasksToBounds(true);
1659 child->SetOpacity(0.4f);
1660 child->SetForceRenderSurface(true);
1661 grand_child->SetOpacity(0.5f);
1662 great_grand_child->SetOpacity(0.4f);
1663
[email protected]989386c2013-07-18 21:37:231664 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531665 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1666 parent.get(), parent->bounds(), &render_surface_layer_list);
1667 inputs.can_adjust_raster_scales = true;
1668 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321669
1670 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231671 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1672 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321673}
1674
[email protected]989386c2013-07-18 21:37:231675TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321676 // When a render surface has a clip rect, it is used to clip the content rect
1677 // of the surface. When the render surface is animating its transforms, then
1678 // the content rect's position in the clip rect is not defined on the main
1679 // thread, and its content rect should not be clipped.
1680
1681 // The test tree is set up as follows:
1682 // - parent is a container layer that masksToBounds=true to cause clipping.
1683 // - child is a render surface, which has a clip rect set to the bounds of
1684 // the parent.
1685 // - grand_child is a render surface, and the only visible content in child.
1686 // It is positioned outside of the clip rect from parent.
1687
1688 // In this configuration, grand_child should be outside the clipped
1689 // content rect of the child, making grand_child not appear in the
1690 // render_surface_layer_list. However, when we place an animation on the
1691 // child, this clipping should be avoided and we should keep the grand_child
1692 // in the render_surface_layer_list.
1693
1694 const gfx::Transform identity_matrix;
1695 scoped_refptr<Layer> parent = Layer::Create();
1696 scoped_refptr<Layer> child = Layer::Create();
1697 scoped_refptr<Layer> grand_child = Layer::Create();
1698 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1699 make_scoped_refptr(new LayerWithForcedDrawsContent());
1700 parent->AddChild(child);
1701 child->AddChild(grand_child);
1702 grand_child->AddChild(leaf_node);
1703
[email protected]d600df7d2013-08-03 02:34:281704 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1705 host->SetRootLayer(parent);
1706
[email protected]fb661802013-03-25 01:59:321707 SetLayerPropertiesForTesting(parent.get(),
1708 identity_matrix,
[email protected]fb661802013-03-25 01:59:321709 gfx::PointF(),
1710 gfx::PointF(),
1711 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571712 true,
[email protected]fb661802013-03-25 01:59:321713 false);
1714 SetLayerPropertiesForTesting(child.get(),
1715 identity_matrix,
[email protected]fb661802013-03-25 01:59:321716 gfx::PointF(),
1717 gfx::PointF(),
1718 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571719 true,
[email protected]fb661802013-03-25 01:59:321720 false);
1721 SetLayerPropertiesForTesting(grand_child.get(),
1722 identity_matrix,
[email protected]fb661802013-03-25 01:59:321723 gfx::PointF(),
1724 gfx::PointF(200.f, 200.f),
1725 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571726 true,
[email protected]fb661802013-03-25 01:59:321727 false);
1728 SetLayerPropertiesForTesting(leaf_node.get(),
1729 identity_matrix,
[email protected]fb661802013-03-25 01:59:321730 gfx::PointF(),
1731 gfx::PointF(),
1732 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571733 true,
[email protected]fb661802013-03-25 01:59:321734 false);
1735
1736 parent->SetMasksToBounds(true);
1737 child->SetOpacity(0.4f);
1738 child->SetForceRenderSurface(true);
1739 grand_child->SetOpacity(0.4f);
1740 grand_child->SetForceRenderSurface(true);
1741
[email protected]989386c2013-07-18 21:37:231742 {
1743 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531744 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1745 parent.get(), parent->bounds(), &render_surface_layer_list);
1746 inputs.can_adjust_raster_scales = true;
1747 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321748
[email protected]989386c2013-07-18 21:37:231749 // Without an animation, we should cull child and grand_child from the
1750 // render_surface_layer_list.
1751 ASSERT_EQ(1U, render_surface_layer_list.size());
1752 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1753 }
[email protected]fb661802013-03-25 01:59:321754
1755 // Now put an animating transform on child.
1756 AddAnimatedTransformToController(
1757 child->layer_animation_controller(), 10.0, 30, 0);
1758
[email protected]989386c2013-07-18 21:37:231759 {
1760 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531761 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1762 parent.get(), parent->bounds(), &render_surface_layer_list);
1763 inputs.can_adjust_raster_scales = true;
1764 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321765
[email protected]989386c2013-07-18 21:37:231766 // With an animating transform, we should keep child and grand_child in the
1767 // render_surface_layer_list.
1768 ASSERT_EQ(3U, render_surface_layer_list.size());
1769 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1770 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1771 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1772 }
[email protected]fb661802013-03-25 01:59:321773}
1774
[email protected]989386c2013-07-18 21:37:231775TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:321776 // Layer's IsClipped() property is set to true when:
1777 // - the layer clips its subtree, e.g. masks to bounds,
1778 // - the layer is clipped by an ancestor that contributes to the same
1779 // render target,
1780 // - a surface is clipped by an ancestor that contributes to the same
1781 // render target.
1782 //
1783 // In particular, for a layer that owns a render surface:
1784 // - the render surface inherits any clip from ancestors, and does NOT
1785 // pass that clipped status to the layer itself.
1786 // - but if the layer itself masks to bounds, it is considered clipped
1787 // and propagates the clip to the subtree.
1788
1789 const gfx::Transform identity_matrix;
1790 scoped_refptr<Layer> root = Layer::Create();
1791 scoped_refptr<Layer> parent = Layer::Create();
1792 scoped_refptr<Layer> child1 = Layer::Create();
1793 scoped_refptr<Layer> child2 = Layer::Create();
1794 scoped_refptr<Layer> grand_child = Layer::Create();
1795 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1796 make_scoped_refptr(new LayerWithForcedDrawsContent());
1797 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1798 make_scoped_refptr(new LayerWithForcedDrawsContent());
1799 root->AddChild(parent);
1800 parent->AddChild(child1);
1801 parent->AddChild(child2);
1802 child1->AddChild(grand_child);
1803 child2->AddChild(leaf_node2);
1804 grand_child->AddChild(leaf_node1);
1805
[email protected]d600df7d2013-08-03 02:34:281806 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1807 host->SetRootLayer(root);
1808
[email protected]fb661802013-03-25 01:59:321809 child2->SetForceRenderSurface(true);
1810
1811 SetLayerPropertiesForTesting(root.get(),
1812 identity_matrix,
[email protected]fb661802013-03-25 01:59:321813 gfx::PointF(),
1814 gfx::PointF(),
1815 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571816 true,
[email protected]fb661802013-03-25 01:59:321817 false);
1818 SetLayerPropertiesForTesting(parent.get(),
1819 identity_matrix,
[email protected]fb661802013-03-25 01:59:321820 gfx::PointF(),
1821 gfx::PointF(),
1822 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571823 true,
[email protected]fb661802013-03-25 01:59:321824 false);
1825 SetLayerPropertiesForTesting(child1.get(),
1826 identity_matrix,
[email protected]fb661802013-03-25 01:59:321827 gfx::PointF(),
1828 gfx::PointF(),
1829 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571830 true,
[email protected]fb661802013-03-25 01:59:321831 false);
1832 SetLayerPropertiesForTesting(child2.get(),
1833 identity_matrix,
[email protected]fb661802013-03-25 01:59:321834 gfx::PointF(),
1835 gfx::PointF(),
1836 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571837 true,
[email protected]fb661802013-03-25 01:59:321838 false);
1839 SetLayerPropertiesForTesting(grand_child.get(),
1840 identity_matrix,
[email protected]fb661802013-03-25 01:59:321841 gfx::PointF(),
1842 gfx::PointF(),
1843 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571844 true,
[email protected]fb661802013-03-25 01:59:321845 false);
1846 SetLayerPropertiesForTesting(leaf_node1.get(),
1847 identity_matrix,
[email protected]fb661802013-03-25 01:59:321848 gfx::PointF(),
1849 gfx::PointF(),
1850 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571851 true,
[email protected]fb661802013-03-25 01:59:321852 false);
1853 SetLayerPropertiesForTesting(leaf_node2.get(),
1854 identity_matrix,
[email protected]fb661802013-03-25 01:59:321855 gfx::PointF(),
1856 gfx::PointF(),
1857 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571858 true,
[email protected]fb661802013-03-25 01:59:321859 false);
1860
[email protected]989386c2013-07-18 21:37:231861 // Case 1: nothing is clipped except the root render surface.
1862 {
1863 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531864 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1865 root.get(), parent->bounds(), &render_surface_layer_list);
1866 inputs.can_adjust_raster_scales = true;
1867 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321868
[email protected]989386c2013-07-18 21:37:231869 ASSERT_TRUE(root->render_surface());
1870 ASSERT_TRUE(child2->render_surface());
1871
1872 EXPECT_FALSE(root->is_clipped());
1873 EXPECT_TRUE(root->render_surface()->is_clipped());
1874 EXPECT_FALSE(parent->is_clipped());
1875 EXPECT_FALSE(child1->is_clipped());
1876 EXPECT_FALSE(child2->is_clipped());
1877 EXPECT_FALSE(child2->render_surface()->is_clipped());
1878 EXPECT_FALSE(grand_child->is_clipped());
1879 EXPECT_FALSE(leaf_node1->is_clipped());
1880 EXPECT_FALSE(leaf_node2->is_clipped());
1881 }
[email protected]fb661802013-03-25 01:59:321882
1883 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1884 // surface are clipped. But layers that contribute to child2's surface are
1885 // not clipped explicitly because child2's surface already accounts for
1886 // that clip.
[email protected]989386c2013-07-18 21:37:231887 {
1888 RenderSurfaceLayerList render_surface_layer_list;
1889 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531890 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1891 root.get(), parent->bounds(), &render_surface_layer_list);
1892 inputs.can_adjust_raster_scales = true;
1893 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321894
[email protected]989386c2013-07-18 21:37:231895 ASSERT_TRUE(root->render_surface());
1896 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321897
[email protected]989386c2013-07-18 21:37:231898 EXPECT_FALSE(root->is_clipped());
1899 EXPECT_TRUE(root->render_surface()->is_clipped());
1900 EXPECT_TRUE(parent->is_clipped());
1901 EXPECT_TRUE(child1->is_clipped());
1902 EXPECT_FALSE(child2->is_clipped());
1903 EXPECT_TRUE(child2->render_surface()->is_clipped());
1904 EXPECT_TRUE(grand_child->is_clipped());
1905 EXPECT_TRUE(leaf_node1->is_clipped());
1906 EXPECT_FALSE(leaf_node2->is_clipped());
1907 }
[email protected]fb661802013-03-25 01:59:321908
1909 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1910 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:231911 {
1912 RenderSurfaceLayerList render_surface_layer_list;
1913 parent->SetMasksToBounds(false);
1914 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531915 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1916 root.get(), parent->bounds(), &render_surface_layer_list);
1917 inputs.can_adjust_raster_scales = true;
1918 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321919
[email protected]989386c2013-07-18 21:37:231920 ASSERT_TRUE(root->render_surface());
1921 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321922
[email protected]989386c2013-07-18 21:37:231923 EXPECT_FALSE(root->is_clipped());
1924 EXPECT_TRUE(root->render_surface()->is_clipped());
1925 EXPECT_FALSE(parent->is_clipped());
1926 EXPECT_FALSE(child1->is_clipped());
1927 EXPECT_TRUE(child2->is_clipped());
1928 EXPECT_FALSE(child2->render_surface()->is_clipped());
1929 EXPECT_FALSE(grand_child->is_clipped());
1930 EXPECT_FALSE(leaf_node1->is_clipped());
1931 EXPECT_TRUE(leaf_node2->is_clipped());
1932 }
[email protected]fb661802013-03-25 01:59:321933}
1934
[email protected]fd9a3b6d2013-08-03 00:46:171935TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321936 // Verify that layers get the appropriate DrawableContentRect when their
1937 // parent masksToBounds is true.
1938 //
1939 // grand_child1 - completely inside the region; DrawableContentRect should
1940 // be the layer rect expressed in target space.
1941 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1942 // will be the intersection of layer bounds and the mask region.
1943 // grand_child3 - partially clipped and masksToBounds; the
1944 // DrawableContentRect will still be the intersection of layer bounds and
1945 // the mask region.
1946 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1947 // be empty.
1948 //
1949
1950 const gfx::Transform identity_matrix;
1951 scoped_refptr<Layer> parent = Layer::Create();
1952 scoped_refptr<Layer> child = Layer::Create();
1953 scoped_refptr<Layer> grand_child1 = Layer::Create();
1954 scoped_refptr<Layer> grand_child2 = Layer::Create();
1955 scoped_refptr<Layer> grand_child3 = Layer::Create();
1956 scoped_refptr<Layer> grand_child4 = Layer::Create();
1957
1958 parent->AddChild(child);
1959 child->AddChild(grand_child1);
1960 child->AddChild(grand_child2);
1961 child->AddChild(grand_child3);
1962 child->AddChild(grand_child4);
1963
[email protected]d600df7d2013-08-03 02:34:281964 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1965 host->SetRootLayer(parent);
1966
[email protected]fb661802013-03-25 01:59:321967 SetLayerPropertiesForTesting(parent.get(),
1968 identity_matrix,
[email protected]fb661802013-03-25 01:59:321969 gfx::PointF(),
1970 gfx::PointF(),
1971 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571972 true,
[email protected]fb661802013-03-25 01:59:321973 false);
1974 SetLayerPropertiesForTesting(child.get(),
1975 identity_matrix,
[email protected]fb661802013-03-25 01:59:321976 gfx::PointF(),
1977 gfx::PointF(),
1978 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571979 true,
[email protected]fb661802013-03-25 01:59:321980 false);
1981 SetLayerPropertiesForTesting(grand_child1.get(),
1982 identity_matrix,
[email protected]fb661802013-03-25 01:59:321983 gfx::PointF(),
1984 gfx::PointF(5.f, 5.f),
1985 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571986 true,
[email protected]fb661802013-03-25 01:59:321987 false);
1988 SetLayerPropertiesForTesting(grand_child2.get(),
1989 identity_matrix,
[email protected]fb661802013-03-25 01:59:321990 gfx::PointF(),
1991 gfx::PointF(15.f, 15.f),
1992 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571993 true,
[email protected]fb661802013-03-25 01:59:321994 false);
1995 SetLayerPropertiesForTesting(grand_child3.get(),
1996 identity_matrix,
[email protected]fb661802013-03-25 01:59:321997 gfx::PointF(),
1998 gfx::PointF(15.f, 15.f),
1999 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572000 true,
[email protected]fb661802013-03-25 01:59:322001 false);
2002 SetLayerPropertiesForTesting(grand_child4.get(),
2003 identity_matrix,
[email protected]fb661802013-03-25 01:59:322004 gfx::PointF(),
2005 gfx::PointF(45.f, 45.f),
2006 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572007 true,
[email protected]fb661802013-03-25 01:59:322008 false);
2009
2010 child->SetMasksToBounds(true);
2011 grand_child3->SetMasksToBounds(true);
2012
2013 // Force everyone to be a render surface.
2014 child->SetOpacity(0.4f);
2015 grand_child1->SetOpacity(0.5f);
2016 grand_child2->SetOpacity(0.5f);
2017 grand_child3->SetOpacity(0.5f);
2018 grand_child4->SetOpacity(0.5f);
2019
[email protected]989386c2013-07-18 21:37:232020 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532021 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2022 parent.get(), parent->bounds(), &render_surface_layer_list);
2023 inputs.can_adjust_raster_scales = true;
2024 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322025
[email protected]2c7c6702013-03-26 03:14:052026 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
[email protected]fb661802013-03-25 01:59:322027 grand_child1->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());
[email protected]2c7c6702013-03-26 03:14:052030 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:322031 grand_child3->drawable_content_rect());
2032 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2033}
2034
[email protected]989386c2013-07-18 21:37:232035TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322036 // Verify that render surfaces (and their layers) get the appropriate
2037 // clip rects when their parent masksToBounds is true.
2038 //
2039 // Layers that own render surfaces (at least for now) do not inherit any
2040 // clipping; instead the surface will enforce the clip for the entire subtree.
2041 // They may still have a clip rect of their own layer bounds, however, if
2042 // masksToBounds was true.
2043 const gfx::Transform identity_matrix;
2044 scoped_refptr<Layer> parent = Layer::Create();
2045 scoped_refptr<Layer> child = Layer::Create();
2046 scoped_refptr<Layer> grand_child1 = Layer::Create();
2047 scoped_refptr<Layer> grand_child2 = Layer::Create();
2048 scoped_refptr<Layer> grand_child3 = Layer::Create();
2049 scoped_refptr<Layer> grand_child4 = Layer::Create();
2050 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2051 make_scoped_refptr(new LayerWithForcedDrawsContent());
2052 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2053 make_scoped_refptr(new LayerWithForcedDrawsContent());
2054 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
2055 make_scoped_refptr(new LayerWithForcedDrawsContent());
2056 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
2057 make_scoped_refptr(new LayerWithForcedDrawsContent());
2058
2059 parent->AddChild(child);
2060 child->AddChild(grand_child1);
2061 child->AddChild(grand_child2);
2062 child->AddChild(grand_child3);
2063 child->AddChild(grand_child4);
2064
[email protected]d600df7d2013-08-03 02:34:282065 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2066 host->SetRootLayer(parent);
2067
[email protected]fb661802013-03-25 01:59:322068 // the leaf nodes ensure that these grand_children become render surfaces for
2069 // this test.
2070 grand_child1->AddChild(leaf_node1);
2071 grand_child2->AddChild(leaf_node2);
2072 grand_child3->AddChild(leaf_node3);
2073 grand_child4->AddChild(leaf_node4);
2074
2075 SetLayerPropertiesForTesting(parent.get(),
2076 identity_matrix,
[email protected]fb661802013-03-25 01:59:322077 gfx::PointF(),
2078 gfx::PointF(),
2079 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:572080 true,
[email protected]fb661802013-03-25 01:59:322081 false);
2082 SetLayerPropertiesForTesting(child.get(),
2083 identity_matrix,
[email protected]fb661802013-03-25 01:59:322084 gfx::PointF(),
2085 gfx::PointF(),
2086 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:572087 true,
[email protected]fb661802013-03-25 01:59:322088 false);
2089 SetLayerPropertiesForTesting(grand_child1.get(),
2090 identity_matrix,
[email protected]fb661802013-03-25 01:59:322091 gfx::PointF(),
2092 gfx::PointF(5.f, 5.f),
2093 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572094 true,
[email protected]fb661802013-03-25 01:59:322095 false);
2096 SetLayerPropertiesForTesting(grand_child2.get(),
2097 identity_matrix,
[email protected]fb661802013-03-25 01:59:322098 gfx::PointF(),
2099 gfx::PointF(15.f, 15.f),
2100 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572101 true,
[email protected]fb661802013-03-25 01:59:322102 false);
2103 SetLayerPropertiesForTesting(grand_child3.get(),
2104 identity_matrix,
[email protected]fb661802013-03-25 01:59:322105 gfx::PointF(),
2106 gfx::PointF(15.f, 15.f),
2107 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572108 true,
[email protected]fb661802013-03-25 01:59:322109 false);
2110 SetLayerPropertiesForTesting(grand_child4.get(),
2111 identity_matrix,
[email protected]fb661802013-03-25 01:59:322112 gfx::PointF(),
2113 gfx::PointF(45.f, 45.f),
2114 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572115 true,
[email protected]fb661802013-03-25 01:59:322116 false);
2117 SetLayerPropertiesForTesting(leaf_node1.get(),
2118 identity_matrix,
[email protected]fb661802013-03-25 01:59:322119 gfx::PointF(),
2120 gfx::PointF(),
2121 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572122 true,
[email protected]fb661802013-03-25 01:59:322123 false);
2124 SetLayerPropertiesForTesting(leaf_node2.get(),
2125 identity_matrix,
[email protected]fb661802013-03-25 01:59:322126 gfx::PointF(),
2127 gfx::PointF(),
2128 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572129 true,
[email protected]fb661802013-03-25 01:59:322130 false);
2131 SetLayerPropertiesForTesting(leaf_node3.get(),
2132 identity_matrix,
[email protected]fb661802013-03-25 01:59:322133 gfx::PointF(),
2134 gfx::PointF(),
2135 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572136 true,
[email protected]fb661802013-03-25 01:59:322137 false);
2138 SetLayerPropertiesForTesting(leaf_node4.get(),
2139 identity_matrix,
[email protected]fb661802013-03-25 01:59:322140 gfx::PointF(),
2141 gfx::PointF(),
2142 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572143 true,
[email protected]fb661802013-03-25 01:59:322144 false);
2145
2146 child->SetMasksToBounds(true);
2147 grand_child3->SetMasksToBounds(true);
2148 grand_child4->SetMasksToBounds(true);
2149
2150 // Force everyone to be a render surface.
2151 child->SetOpacity(0.4f);
2152 child->SetForceRenderSurface(true);
2153 grand_child1->SetOpacity(0.5f);
2154 grand_child1->SetForceRenderSurface(true);
2155 grand_child2->SetOpacity(0.5f);
2156 grand_child2->SetForceRenderSurface(true);
2157 grand_child3->SetOpacity(0.5f);
2158 grand_child3->SetForceRenderSurface(true);
2159 grand_child4->SetOpacity(0.5f);
2160 grand_child4->SetForceRenderSurface(true);
2161
[email protected]989386c2013-07-18 21:37:232162 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532163 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2164 parent.get(), parent->bounds(), &render_surface_layer_list);
2165 inputs.can_adjust_raster_scales = true;
2166 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322167 ASSERT_TRUE(grand_child1->render_surface());
2168 ASSERT_TRUE(grand_child2->render_surface());
2169 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322170
2171 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2172 // masksToBounds.
[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_child1->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_child2->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052177 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322178 grand_child3->render_surface()->clip_rect());
2179}
2180
[email protected]989386c2013-07-18 21:37:232181TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322182 scoped_refptr<Layer> parent = Layer::Create();
2183 scoped_refptr<Layer> render_surface1 = Layer::Create();
2184 scoped_refptr<Layer> render_surface2 = Layer::Create();
2185 scoped_refptr<Layer> child_of_root = Layer::Create();
2186 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2187 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2188 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2189 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2190 make_scoped_refptr(new LayerWithForcedDrawsContent());
2191 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2192 make_scoped_refptr(new LayerWithForcedDrawsContent());
2193 parent->AddChild(render_surface1);
2194 parent->AddChild(child_of_root);
2195 render_surface1->AddChild(child_of_rs1);
2196 render_surface1->AddChild(render_surface2);
2197 render_surface2->AddChild(child_of_rs2);
2198 child_of_root->AddChild(grand_child_of_root);
2199 child_of_rs1->AddChild(grand_child_of_rs1);
2200 child_of_rs2->AddChild(grand_child_of_rs2);
2201
[email protected]d600df7d2013-08-03 02:34:282202 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2203 host->SetRootLayer(parent);
2204
[email protected]fb661802013-03-25 01:59:322205 // Make our render surfaces.
2206 render_surface1->SetForceRenderSurface(true);
2207 render_surface2->SetForceRenderSurface(true);
2208
2209 gfx::Transform layer_transform;
2210 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322211
2212 SetLayerPropertiesForTesting(parent.get(),
2213 layer_transform,
[email protected]fb661802013-03-25 01:59:322214 gfx::PointF(0.25f, 0.f),
2215 gfx::PointF(2.5f, 0.f),
2216 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572217 true,
[email protected]fb661802013-03-25 01:59:322218 false);
2219 SetLayerPropertiesForTesting(render_surface1.get(),
2220 layer_transform,
[email protected]fb661802013-03-25 01:59:322221 gfx::PointF(0.25f, 0.f),
2222 gfx::PointF(2.5f, 0.f),
2223 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572224 true,
[email protected]fb661802013-03-25 01:59:322225 false);
2226 SetLayerPropertiesForTesting(render_surface2.get(),
2227 layer_transform,
[email protected]fb661802013-03-25 01:59:322228 gfx::PointF(0.25f, 0.f),
2229 gfx::PointF(2.5f, 0.f),
2230 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572231 true,
[email protected]fb661802013-03-25 01:59:322232 false);
2233 SetLayerPropertiesForTesting(child_of_root.get(),
2234 layer_transform,
[email protected]fb661802013-03-25 01:59:322235 gfx::PointF(0.25f, 0.f),
2236 gfx::PointF(2.5f, 0.f),
2237 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572238 true,
[email protected]fb661802013-03-25 01:59:322239 false);
2240 SetLayerPropertiesForTesting(child_of_rs1.get(),
2241 layer_transform,
[email protected]fb661802013-03-25 01:59:322242 gfx::PointF(0.25f, 0.f),
2243 gfx::PointF(2.5f, 0.f),
2244 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572245 true,
[email protected]fb661802013-03-25 01:59:322246 false);
2247 SetLayerPropertiesForTesting(child_of_rs2.get(),
2248 layer_transform,
[email protected]fb661802013-03-25 01:59:322249 gfx::PointF(0.25f, 0.f),
2250 gfx::PointF(2.5f, 0.f),
2251 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572252 true,
[email protected]fb661802013-03-25 01:59:322253 false);
2254 SetLayerPropertiesForTesting(grand_child_of_root.get(),
2255 layer_transform,
[email protected]fb661802013-03-25 01:59:322256 gfx::PointF(0.25f, 0.f),
2257 gfx::PointF(2.5f, 0.f),
2258 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572259 true,
[email protected]fb661802013-03-25 01:59:322260 false);
2261 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
2262 layer_transform,
[email protected]fb661802013-03-25 01:59:322263 gfx::PointF(0.25f, 0.f),
2264 gfx::PointF(2.5f, 0.f),
2265 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572266 true,
[email protected]fb661802013-03-25 01:59:322267 false);
2268 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
2269 layer_transform,
[email protected]fb661802013-03-25 01:59:322270 gfx::PointF(0.25f, 0.f),
2271 gfx::PointF(2.5f, 0.f),
2272 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572273 true,
[email protected]fb661802013-03-25 01:59:322274 false);
2275
2276 // Put an animated opacity on the render surface.
2277 AddOpacityTransitionToController(
2278 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2279
2280 // Also put an animated opacity on a layer without descendants.
2281 AddOpacityTransitionToController(
2282 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2283
2284 // Put a transform animation on the render surface.
2285 AddAnimatedTransformToController(
2286 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2287
2288 // Also put transform animations on grand_child_of_root, and
2289 // grand_child_of_rs2
2290 AddAnimatedTransformToController(
2291 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2292 AddAnimatedTransformToController(
2293 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2294
2295 ExecuteCalculateDrawProperties(parent.get());
2296
2297 // Only layers that are associated with render surfaces should have an actual
2298 // RenderSurface() value.
2299 ASSERT_TRUE(parent->render_surface());
2300 ASSERT_FALSE(child_of_root->render_surface());
2301 ASSERT_FALSE(grand_child_of_root->render_surface());
2302
2303 ASSERT_TRUE(render_surface1->render_surface());
2304 ASSERT_FALSE(child_of_rs1->render_surface());
2305 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2306
2307 ASSERT_TRUE(render_surface2->render_surface());
2308 ASSERT_FALSE(child_of_rs2->render_surface());
2309 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2310
2311 // Verify all render target accessors
2312 EXPECT_EQ(parent, parent->render_target());
2313 EXPECT_EQ(parent, child_of_root->render_target());
2314 EXPECT_EQ(parent, grand_child_of_root->render_target());
2315
2316 EXPECT_EQ(render_surface1, render_surface1->render_target());
2317 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2318 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
2319
2320 EXPECT_EQ(render_surface2, render_surface2->render_target());
2321 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2322 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
2323
2324 // Verify draw_opacity_is_animating values
2325 EXPECT_FALSE(parent->draw_opacity_is_animating());
2326 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2327 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2328 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2329 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2330 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2331 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2332 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2333 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2334 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2335 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2336
2337 // Verify draw_transform_is_animating values
2338 EXPECT_FALSE(parent->draw_transform_is_animating());
2339 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2340 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2341 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2342 EXPECT_FALSE(render_surface1->render_surface()
2343 ->target_surface_transforms_are_animating());
2344 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2345 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2346 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2347 EXPECT_TRUE(render_surface2->render_surface()
2348 ->target_surface_transforms_are_animating());
2349 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2350 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2351
2352 // Verify screen_space_transform_is_animating values
2353 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2354 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2355 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2356 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2357 EXPECT_FALSE(render_surface1->render_surface()
2358 ->screen_space_transforms_are_animating());
2359 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2360 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2361 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2362 EXPECT_TRUE(render_surface2->render_surface()
2363 ->screen_space_transforms_are_animating());
2364 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2365 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2366
2367 // Sanity check. If these fail there is probably a bug in the test itself.
2368 // It is expected that we correctly set up transforms so that the y-component
2369 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262370 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2371 EXPECT_FLOAT_EQ(2.0,
2372 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322373 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262374 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322375
[email protected]803f6b52013-09-12 00:51:262376 EXPECT_FLOAT_EQ(2.0,
2377 render_surface1->screen_space_transform().matrix().get(1, 3));
2378 EXPECT_FLOAT_EQ(3.0,
2379 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322380 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262381 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322382
[email protected]803f6b52013-09-12 00:51:262383 EXPECT_FLOAT_EQ(3.0,
2384 render_surface2->screen_space_transform().matrix().get(1, 3));
2385 EXPECT_FLOAT_EQ(4.0,
2386 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322387 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262388 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322389}
2390
[email protected]989386c2013-07-18 21:37:232391TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322392 // Test the calculateVisibleRect() function works correctly for identity
2393 // transforms.
2394
[email protected]2c7c6702013-03-26 03:14:052395 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322396 gfx::Transform layer_to_surface_transform;
2397
2398 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232399 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052400 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322401 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2402 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2403 EXPECT_RECT_EQ(expected, actual);
2404
2405 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052406 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322407 actual = LayerTreeHostCommon::CalculateVisibleRect(
2408 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2409 EXPECT_TRUE(actual.IsEmpty());
2410
2411 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052412 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2413 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322414 actual = LayerTreeHostCommon::CalculateVisibleRect(
2415 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2416 EXPECT_RECT_EQ(expected, actual);
2417}
2418
[email protected]989386c2013-07-18 21:37:232419TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322420 // Test the calculateVisibleRect() function works correctly for scaling
2421 // transforms.
2422
[email protected]2c7c6702013-03-26 03:14:052423 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2424 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322425 gfx::Transform layer_to_surface_transform;
2426
2427 // Case 1: Layer is contained within the surface.
2428 layer_to_surface_transform.MakeIdentity();
2429 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052430 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322431 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2432 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2433 EXPECT_RECT_EQ(expected, actual);
2434
2435 // Case 2: Layer is outside the surface rect.
2436 layer_to_surface_transform.MakeIdentity();
2437 layer_to_surface_transform.Translate(120.0, 120.0);
2438 actual = LayerTreeHostCommon::CalculateVisibleRect(
2439 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2440 EXPECT_TRUE(actual.IsEmpty());
2441
2442 // Case 3: Layer is partially overlapping the surface rect.
2443 layer_to_surface_transform.MakeIdentity();
2444 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052445 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322446 actual = LayerTreeHostCommon::CalculateVisibleRect(
2447 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2448 EXPECT_RECT_EQ(expected, actual);
2449}
2450
[email protected]989386c2013-07-18 21:37:232451TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322452 // Test the calculateVisibleRect() function works correctly for rotations
2453 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2454 // should return the g in the layer's space.
2455
[email protected]2c7c6702013-03-26 03:14:052456 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2457 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322458 gfx::Transform layer_to_surface_transform;
2459
2460 // Case 1: Layer is contained within the surface.
2461 layer_to_surface_transform.MakeIdentity();
2462 layer_to_surface_transform.Translate(50.0, 50.0);
2463 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052464 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322465 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2466 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2467 EXPECT_RECT_EQ(expected, actual);
2468
2469 // Case 2: Layer is outside the surface rect.
2470 layer_to_surface_transform.MakeIdentity();
2471 layer_to_surface_transform.Translate(-50.0, 0.0);
2472 layer_to_surface_transform.Rotate(45.0);
2473 actual = LayerTreeHostCommon::CalculateVisibleRect(
2474 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2475 EXPECT_TRUE(actual.IsEmpty());
2476
2477 // Case 3: The layer is rotated about its top-left corner. In surface space,
2478 // the layer is oriented diagonally, with the left half outside of the render
2479 // surface. In this case, the g should still be the entire layer
2480 // (remember the g is computed in layer space); both the top-left
2481 // and bottom-right corners of the layer are still visible.
2482 layer_to_surface_transform.MakeIdentity();
2483 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052484 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322485 actual = LayerTreeHostCommon::CalculateVisibleRect(
2486 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2487 EXPECT_RECT_EQ(expected, actual);
2488
2489 // Case 4: The layer is rotated about its top-left corner, and translated
2490 // upwards. In surface space, the layer is oriented diagonally, with only the
2491 // top corner of the surface overlapping the layer. In layer space, the render
2492 // surface overlaps the right side of the layer. The g should be
2493 // the layer's right half.
2494 layer_to_surface_transform.MakeIdentity();
2495 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2496 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052497 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322498 actual = LayerTreeHostCommon::CalculateVisibleRect(
2499 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2500 EXPECT_RECT_EQ(expected, actual);
2501}
2502
[email protected]989386c2013-07-18 21:37:232503TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322504 // Test that the calculateVisibleRect() function works correctly for 3d
2505 // transforms.
2506
[email protected]2c7c6702013-03-26 03:14:052507 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2508 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322509 gfx::Transform layer_to_surface_transform;
2510
2511 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2512 // degrees, should be fully contained in the render surface.
2513 layer_to_surface_transform.MakeIdentity();
2514 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052515 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322516 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2517 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2518 EXPECT_RECT_EQ(expected, actual);
2519
2520 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2521 // degrees, but shifted to the side so only the right-half the layer would be
2522 // visible on the surface.
2523 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262524 SkMScalar half_width_of_rotated_layer =
2525 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322526 layer_to_surface_transform.MakeIdentity();
2527 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232528 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2529 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052530 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322531 actual = LayerTreeHostCommon::CalculateVisibleRect(
2532 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2533 EXPECT_RECT_EQ(expected, actual);
2534}
2535
[email protected]989386c2013-07-18 21:37:232536TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322537 // Test the calculateVisibleRect() function works correctly when the layer has
2538 // a perspective projection onto the target surface.
2539
[email protected]2c7c6702013-03-26 03:14:052540 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2541 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322542 gfx::Transform layer_to_surface_transform;
2543
2544 // Case 1: Even though the layer is twice as large as the surface, due to
2545 // perspective foreshortening, the layer will fit fully in the surface when
2546 // its translated more than the perspective amount.
2547 layer_to_surface_transform.MakeIdentity();
2548
2549 // The following sequence of transforms applies the perspective about the
2550 // center of the surface.
2551 layer_to_surface_transform.Translate(50.0, 50.0);
2552 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2553 layer_to_surface_transform.Translate(-50.0, -50.0);
2554
2555 // This translate places the layer in front of the surface's projection plane.
2556 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2557
[email protected]2c7c6702013-03-26 03:14:052558 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322559 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2560 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2561 EXPECT_RECT_EQ(expected, actual);
2562
2563 // Case 2: same projection as before, except that the layer is also translated
2564 // to the side, so that only the right half of the layer should be visible.
2565 //
2566 // Explanation of expected result: The perspective ratio is (z distance
2567 // between layer and camera origin) / (z distance between projection plane and
2568 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2569 // move a layer by translating -50 units in projected surface units (so that
2570 // only half of it is visible), then we would need to translate by (-36 / 9) *
2571 // -50 == -200 in the layer's units.
2572 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232573 expected = gfx::Rect(gfx::Point(50, -50),
2574 gfx::Size(100, 200)); // The right half of the layer's
2575 // bounding rect.
[email protected]fb661802013-03-25 01:59:322576 actual = LayerTreeHostCommon::CalculateVisibleRect(
2577 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2578 EXPECT_RECT_EQ(expected, actual);
2579}
2580
[email protected]989386c2013-07-18 21:37:232581TEST_F(LayerTreeHostCommonTest,
2582 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322583 // There is currently no explicit concept of an orthographic projection plane
2584 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2585 // are technically behind the surface in an orthographic world should not be
2586 // clipped when they are flattened to the surface.
2587
[email protected]2c7c6702013-03-26 03:14:052588 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2589 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322590 gfx::Transform layer_to_surface_transform;
2591
2592 // This sequence of transforms effectively rotates the layer about the y-axis
2593 // at the center of the layer.
2594 layer_to_surface_transform.MakeIdentity();
2595 layer_to_surface_transform.Translate(50.0, 0.0);
2596 layer_to_surface_transform.RotateAboutYAxis(45.0);
2597 layer_to_surface_transform.Translate(-50.0, 0.0);
2598
[email protected]2c7c6702013-03-26 03:14:052599 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322600 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2601 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2602 EXPECT_RECT_EQ(expected, actual);
2603}
2604
[email protected]989386c2013-07-18 21:37:232605TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322606 // Test the calculateVisibleRect() function works correctly when projecting a
2607 // surface onto a layer, but the layer is partially behind the camera (not
2608 // just behind the projection plane). In this case, the cartesian coordinates
2609 // may seem to be valid, but actually they are not. The visible rect needs to
2610 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2611 // converting to cartesian coordinates.
2612
[email protected]2c7c6702013-03-26 03:14:052613 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232614 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322615 gfx::Transform layer_to_surface_transform;
2616
2617 // The layer is positioned so that the right half of the layer should be in
2618 // front of the camera, while the other half is behind the surface's
2619 // projection plane. The following sequence of transforms applies the
2620 // perspective and rotation about the center of the layer.
2621 layer_to_surface_transform.MakeIdentity();
2622 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2623 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2624 layer_to_surface_transform.RotateAboutYAxis(45.0);
2625
2626 // Sanity check that this transform does indeed cause w < 0 when applying the
2627 // transform, otherwise this code is not testing the intended scenario.
2628 bool clipped;
2629 MathUtil::MapQuad(layer_to_surface_transform,
2630 gfx::QuadF(gfx::RectF(layer_content_rect)),
2631 &clipped);
2632 ASSERT_TRUE(clipped);
2633
2634 int expected_x_position = 0;
2635 int expected_width = 10;
2636 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2637 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2638 EXPECT_EQ(expected_x_position, actual.x());
2639 EXPECT_EQ(expected_width, actual.width());
2640}
2641
[email protected]989386c2013-07-18 21:37:232642TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322643 // To determine visible rect in layer space, there needs to be an
2644 // un-projection from surface space to layer space. When the original
2645 // transform was a perspective projection that was clipped, it returns a rect
2646 // that encloses the clipped bounds. Un-projecting this new rect may require
2647 // clipping again.
2648
2649 // This sequence of transforms causes one corner of the layer to protrude
2650 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232651 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2652 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322653 gfx::Transform layer_to_surface_transform;
2654 layer_to_surface_transform.MakeIdentity();
2655 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2656 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2657 layer_to_surface_transform.RotateAboutYAxis(45.0);
2658 layer_to_surface_transform.RotateAboutXAxis(80.0);
2659
2660 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2661 // code is not testing the intended scenario.
2662 bool clipped;
2663 gfx::RectF clipped_rect =
2664 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2665 MathUtil::ProjectQuad(
2666 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2667 ASSERT_TRUE(clipped);
2668
2669 // Only the corner of the layer is not visible on the surface because of being
2670 // clipped. But, the net result of rounding visible region to an axis-aligned
2671 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052672 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322673 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2674 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2675 EXPECT_RECT_EQ(expected, actual);
2676}
2677
[email protected]989386c2013-07-18 21:37:232678TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322679 scoped_refptr<Layer> root = Layer::Create();
2680 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2681 make_scoped_refptr(new LayerWithForcedDrawsContent());
2682 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2683 make_scoped_refptr(new LayerWithForcedDrawsContent());
2684 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2685 make_scoped_refptr(new LayerWithForcedDrawsContent());
2686 root->AddChild(child1);
2687 root->AddChild(child2);
2688 root->AddChild(child3);
2689
[email protected]d600df7d2013-08-03 02:34:282690 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2691 host->SetRootLayer(root);
2692
[email protected]fb661802013-03-25 01:59:322693 gfx::Transform identity_matrix;
2694 SetLayerPropertiesForTesting(root.get(),
2695 identity_matrix,
[email protected]fb661802013-03-25 01:59:322696 gfx::PointF(),
2697 gfx::PointF(),
2698 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572699 true,
[email protected]fb661802013-03-25 01:59:322700 false);
2701 SetLayerPropertiesForTesting(child1.get(),
2702 identity_matrix,
[email protected]fb661802013-03-25 01:59:322703 gfx::PointF(),
2704 gfx::PointF(),
2705 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572706 true,
[email protected]fb661802013-03-25 01:59:322707 false);
2708 SetLayerPropertiesForTesting(child2.get(),
2709 identity_matrix,
[email protected]fb661802013-03-25 01:59:322710 gfx::PointF(),
2711 gfx::PointF(75.f, 75.f),
2712 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572713 true,
[email protected]fb661802013-03-25 01:59:322714 false);
2715 SetLayerPropertiesForTesting(child3.get(),
2716 identity_matrix,
[email protected]fb661802013-03-25 01:59:322717 gfx::PointF(),
2718 gfx::PointF(125.f, 125.f),
2719 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572720 true,
[email protected]fb661802013-03-25 01:59:322721 false);
2722
2723 ExecuteCalculateDrawProperties(root.get());
2724
2725 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2726 root->render_surface()->DrawableContentRect());
2727 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2728
2729 // Layers that do not draw content should have empty visible_content_rects.
2730 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2731
2732 // layer visible_content_rects are clipped by their target surface.
2733 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2734 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
2735 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
2736
2737 // layer drawable_content_rects are not clipped.
2738 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2739 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2740 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2741}
2742
[email protected]989386c2013-07-18 21:37:232743TEST_F(LayerTreeHostCommonTest,
2744 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:322745 scoped_refptr<Layer> root = Layer::Create();
2746 scoped_refptr<Layer> child = Layer::Create();
2747 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
2748 make_scoped_refptr(new LayerWithForcedDrawsContent());
2749 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
2750 make_scoped_refptr(new LayerWithForcedDrawsContent());
2751 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
2752 make_scoped_refptr(new LayerWithForcedDrawsContent());
2753 root->AddChild(child);
2754 child->AddChild(grand_child1);
2755 child->AddChild(grand_child2);
2756 child->AddChild(grand_child3);
2757
[email protected]d600df7d2013-08-03 02:34:282758 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2759 host->SetRootLayer(root);
2760
[email protected]fb661802013-03-25 01:59:322761 gfx::Transform identity_matrix;
2762 SetLayerPropertiesForTesting(root.get(),
2763 identity_matrix,
[email protected]fb661802013-03-25 01:59:322764 gfx::PointF(),
2765 gfx::PointF(),
2766 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572767 true,
[email protected]fb661802013-03-25 01:59:322768 false);
2769 SetLayerPropertiesForTesting(child.get(),
2770 identity_matrix,
[email protected]fb661802013-03-25 01:59:322771 gfx::PointF(),
2772 gfx::PointF(),
2773 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572774 true,
[email protected]fb661802013-03-25 01:59:322775 false);
2776 SetLayerPropertiesForTesting(grand_child1.get(),
2777 identity_matrix,
[email protected]fb661802013-03-25 01:59:322778 gfx::PointF(),
2779 gfx::PointF(5.f, 5.f),
2780 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572781 true,
[email protected]fb661802013-03-25 01:59:322782 false);
2783 SetLayerPropertiesForTesting(grand_child2.get(),
2784 identity_matrix,
[email protected]fb661802013-03-25 01:59:322785 gfx::PointF(),
2786 gfx::PointF(75.f, 75.f),
2787 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572788 true,
[email protected]fb661802013-03-25 01:59:322789 false);
2790 SetLayerPropertiesForTesting(grand_child3.get(),
2791 identity_matrix,
[email protected]fb661802013-03-25 01:59:322792 gfx::PointF(),
2793 gfx::PointF(125.f, 125.f),
2794 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572795 true,
[email protected]fb661802013-03-25 01:59:322796 false);
2797
2798 child->SetMasksToBounds(true);
2799 ExecuteCalculateDrawProperties(root.get());
2800
2801 ASSERT_FALSE(child->render_surface());
2802
2803 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2804 root->render_surface()->DrawableContentRect());
2805 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2806
2807 // Layers that do not draw content should have empty visible content rects.
2808 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2809 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
2810
2811 // All grandchild visible content rects should be clipped by child.
2812 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
2813 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
2814 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
2815
2816 // All grandchild DrawableContentRects should also be clipped by child.
2817 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
2818 grand_child1->drawable_content_rect());
2819 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
2820 grand_child2->drawable_content_rect());
2821 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2822}
2823
[email protected]989386c2013-07-18 21:37:232824TEST_F(LayerTreeHostCommonTest,
2825 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322826 scoped_refptr<Layer> root = Layer::Create();
2827 scoped_refptr<Layer> render_surface1 = Layer::Create();
2828 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2829 make_scoped_refptr(new LayerWithForcedDrawsContent());
2830 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2831 make_scoped_refptr(new LayerWithForcedDrawsContent());
2832 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2833 make_scoped_refptr(new LayerWithForcedDrawsContent());
2834 root->AddChild(render_surface1);
2835 render_surface1->AddChild(child1);
2836 render_surface1->AddChild(child2);
2837 render_surface1->AddChild(child3);
2838
[email protected]d600df7d2013-08-03 02:34:282839 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2840 host->SetRootLayer(root);
2841
[email protected]fb661802013-03-25 01:59:322842 gfx::Transform identity_matrix;
2843 SetLayerPropertiesForTesting(root.get(),
2844 identity_matrix,
[email protected]fb661802013-03-25 01:59:322845 gfx::PointF(),
2846 gfx::PointF(),
2847 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572848 true,
[email protected]fb661802013-03-25 01:59:322849 false);
2850 SetLayerPropertiesForTesting(render_surface1.get(),
2851 identity_matrix,
[email protected]fb661802013-03-25 01:59:322852 gfx::PointF(),
2853 gfx::PointF(),
2854 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572855 true,
[email protected]fb661802013-03-25 01:59:322856 false);
2857 SetLayerPropertiesForTesting(child1.get(),
2858 identity_matrix,
[email protected]fb661802013-03-25 01:59:322859 gfx::PointF(),
2860 gfx::PointF(5.f, 5.f),
2861 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572862 true,
[email protected]fb661802013-03-25 01:59:322863 false);
2864 SetLayerPropertiesForTesting(child2.get(),
2865 identity_matrix,
[email protected]fb661802013-03-25 01:59:322866 gfx::PointF(),
2867 gfx::PointF(75.f, 75.f),
2868 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572869 true,
[email protected]fb661802013-03-25 01:59:322870 false);
2871 SetLayerPropertiesForTesting(child3.get(),
2872 identity_matrix,
[email protected]fb661802013-03-25 01:59:322873 gfx::PointF(),
2874 gfx::PointF(125.f, 125.f),
2875 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572876 true,
[email protected]fb661802013-03-25 01:59:322877 false);
2878
2879 render_surface1->SetForceRenderSurface(true);
2880 ExecuteCalculateDrawProperties(root.get());
2881
2882 ASSERT_TRUE(render_surface1->render_surface());
2883
2884 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2885 root->render_surface()->DrawableContentRect());
2886 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2887
2888 // Layers that do not draw content should have empty visible content rects.
2889 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2890 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2891 render_surface1->visible_content_rect());
2892
2893 // An unclipped surface grows its DrawableContentRect to include all drawable
2894 // regions of the subtree.
2895 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
2896 render_surface1->render_surface()->DrawableContentRect());
2897
2898 // All layers that draw content into the unclipped surface are also unclipped.
2899 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2900 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
2901 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
2902
2903 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2904 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2905 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2906}
2907
[email protected]989386c2013-07-18 21:37:232908TEST_F(LayerTreeHostCommonTest,
2909 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:472910 scoped_refptr<Layer> root = Layer::Create();
2911 scoped_refptr<LayerWithForcedDrawsContent> child =
2912 make_scoped_refptr(new LayerWithForcedDrawsContent());
2913 root->AddChild(child);
2914
[email protected]d600df7d2013-08-03 02:34:282915 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2916 host->SetRootLayer(root);
2917
[email protected]630ddad2013-08-16 03:01:322918 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:472919 gfx::Transform identity_matrix;
2920 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:322921 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:472922
2923 SetLayerPropertiesForTesting(root.get(),
2924 identity_matrix,
[email protected]451107a32013-04-10 05:12:472925 gfx::PointF(),
2926 gfx::PointF(),
2927 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572928 true,
[email protected]451107a32013-04-10 05:12:472929 false);
2930 SetLayerPropertiesForTesting(child.get(),
2931 uninvertible_matrix,
[email protected]451107a32013-04-10 05:12:472932 gfx::PointF(),
2933 gfx::PointF(5.f, 5.f),
2934 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572935 true,
[email protected]451107a32013-04-10 05:12:472936 false);
2937
2938 ExecuteCalculateDrawProperties(root.get());
2939
2940 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2941 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322942
[email protected]08bdf1b2014-04-16 23:23:292943 // Case 2: a matrix with flattened z, uninvertible and not visible according
2944 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:322945 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:262946 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322947 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2948
2949 SetLayerPropertiesForTesting(child.get(),
2950 uninvertible_matrix,
[email protected]630ddad2013-08-16 03:01:322951 gfx::PointF(),
2952 gfx::PointF(5.f, 5.f),
2953 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572954 true,
[email protected]630ddad2013-08-16 03:01:322955 false);
2956
2957 ExecuteCalculateDrawProperties(root.get());
2958
[email protected]08bdf1b2014-04-16 23:23:292959 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2960 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322961
[email protected]08bdf1b2014-04-16 23:23:292962 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:322963 uninvertible_matrix.MakeIdentity();
2964 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:262965 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322966 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2967
2968 SetLayerPropertiesForTesting(child.get(),
2969 uninvertible_matrix,
[email protected]630ddad2013-08-16 03:01:322970 gfx::PointF(),
2971 gfx::PointF(5.f, 5.f),
2972 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572973 true,
[email protected]630ddad2013-08-16 03:01:322974 false);
2975
2976 ExecuteCalculateDrawProperties(root.get());
2977
2978 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:292979 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:472980}
2981
[email protected]989386c2013-07-18 21:37:232982TEST_F(LayerTreeHostCommonTest,
[email protected]e43c68b2014-05-01 05:10:362983 SingularTransformDoesNotPreventClearingDrawProperties) {
2984 scoped_refptr<Layer> root = Layer::Create();
2985 scoped_refptr<LayerWithForcedDrawsContent> child =
2986 make_scoped_refptr(new LayerWithForcedDrawsContent());
2987 root->AddChild(child);
2988
2989 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2990 host->SetRootLayer(root);
2991
2992 gfx::Transform identity_matrix;
2993 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2994 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2995
2996 SetLayerPropertiesForTesting(root.get(),
2997 uninvertible_matrix,
2998 gfx::PointF(),
2999 gfx::PointF(),
3000 gfx::Size(100, 100),
3001 true,
3002 false);
3003 SetLayerPropertiesForTesting(child.get(),
3004 identity_matrix,
3005 gfx::PointF(),
3006 gfx::PointF(5.f, 5.f),
3007 gfx::Size(50, 50),
3008 true,
3009 false);
3010
3011 child->draw_properties().sorted_for_recursion = true;
3012
3013 TransformOperations start_transform_operations;
3014 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
3015
3016 TransformOperations end_transform_operations;
3017 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
3018
3019 AddAnimatedTransformToLayer(
3020 root.get(), 10.0, start_transform_operations, end_transform_operations);
3021
3022 EXPECT_TRUE(root->TransformIsAnimating());
3023
3024 ExecuteCalculateDrawProperties(root.get());
3025
3026 EXPECT_FALSE(child->draw_properties().sorted_for_recursion);
3027}
3028
3029TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233030 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:323031 scoped_refptr<Layer> root = Layer::Create();
3032 scoped_refptr<Layer> render_surface1 = Layer::Create();
3033 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3034 make_scoped_refptr(new LayerWithForcedDrawsContent());
3035 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3036 make_scoped_refptr(new LayerWithForcedDrawsContent());
3037 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3038 make_scoped_refptr(new LayerWithForcedDrawsContent());
3039 root->AddChild(render_surface1);
3040 render_surface1->AddChild(child1);
3041 render_surface1->AddChild(child2);
3042 render_surface1->AddChild(child3);
3043
[email protected]d600df7d2013-08-03 02:34:283044 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3045 host->SetRootLayer(root);
3046
[email protected]fb661802013-03-25 01:59:323047 gfx::Transform identity_matrix;
3048 SetLayerPropertiesForTesting(root.get(),
3049 identity_matrix,
[email protected]fb661802013-03-25 01:59:323050 gfx::PointF(),
3051 gfx::PointF(),
3052 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573053 true,
[email protected]fb661802013-03-25 01:59:323054 false);
3055 SetLayerPropertiesForTesting(render_surface1.get(),
3056 identity_matrix,
[email protected]fb661802013-03-25 01:59:323057 gfx::PointF(),
3058 gfx::PointF(),
3059 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573060 true,
[email protected]fb661802013-03-25 01:59:323061 false);
3062 SetLayerPropertiesForTesting(child1.get(),
3063 identity_matrix,
[email protected]fb661802013-03-25 01:59:323064 gfx::PointF(),
3065 gfx::PointF(5.f, 5.f),
3066 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573067 true,
[email protected]fb661802013-03-25 01:59:323068 false);
3069 SetLayerPropertiesForTesting(child2.get(),
3070 identity_matrix,
[email protected]fb661802013-03-25 01:59:323071 gfx::PointF(),
3072 gfx::PointF(75.f, 75.f),
3073 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573074 true,
[email protected]fb661802013-03-25 01:59:323075 false);
3076 SetLayerPropertiesForTesting(child3.get(),
3077 identity_matrix,
[email protected]fb661802013-03-25 01:59:323078 gfx::PointF(),
3079 gfx::PointF(125.f, 125.f),
3080 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573081 true,
[email protected]fb661802013-03-25 01:59:323082 false);
3083
3084 root->SetMasksToBounds(true);
3085 render_surface1->SetForceRenderSurface(true);
3086 ExecuteCalculateDrawProperties(root.get());
3087
3088 ASSERT_TRUE(render_surface1->render_surface());
3089
3090 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3091 root->render_surface()->DrawableContentRect());
3092 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3093
3094 // Layers that do not draw content should have empty visible content rects.
3095 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3096 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3097 render_surface1->visible_content_rect());
3098
3099 // A clipped surface grows its DrawableContentRect to include all drawable
3100 // regions of the subtree, but also gets clamped by the ancestor's clip.
3101 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3102 render_surface1->render_surface()->DrawableContentRect());
3103
3104 // All layers that draw content into the surface have their visible content
3105 // rect clipped by the surface clip rect.
3106 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3107 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
3108 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3109
3110 // But the DrawableContentRects are unclipped.
3111 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3112 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3113 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3114}
3115
[email protected]989386c2013-07-18 21:37:233116TEST_F(LayerTreeHostCommonTest,
3117 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323118 // Check that clipping does not propagate down surfaces.
3119 scoped_refptr<Layer> root = Layer::Create();
3120 scoped_refptr<Layer> render_surface1 = Layer::Create();
3121 scoped_refptr<Layer> render_surface2 = Layer::Create();
3122 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3123 make_scoped_refptr(new LayerWithForcedDrawsContent());
3124 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3125 make_scoped_refptr(new LayerWithForcedDrawsContent());
3126 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3127 make_scoped_refptr(new LayerWithForcedDrawsContent());
3128 root->AddChild(render_surface1);
3129 render_surface1->AddChild(render_surface2);
3130 render_surface2->AddChild(child1);
3131 render_surface2->AddChild(child2);
3132 render_surface2->AddChild(child3);
3133
[email protected]d600df7d2013-08-03 02:34:283134 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3135 host->SetRootLayer(root);
3136
[email protected]fb661802013-03-25 01:59:323137 gfx::Transform identity_matrix;
3138 SetLayerPropertiesForTesting(root.get(),
3139 identity_matrix,
[email protected]fb661802013-03-25 01:59:323140 gfx::PointF(),
3141 gfx::PointF(),
3142 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573143 true,
[email protected]fb661802013-03-25 01:59:323144 false);
3145 SetLayerPropertiesForTesting(render_surface1.get(),
3146 identity_matrix,
[email protected]fb661802013-03-25 01:59:323147 gfx::PointF(),
3148 gfx::PointF(),
3149 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573150 true,
[email protected]fb661802013-03-25 01:59:323151 false);
3152 SetLayerPropertiesForTesting(render_surface2.get(),
3153 identity_matrix,
[email protected]fb661802013-03-25 01:59:323154 gfx::PointF(),
3155 gfx::PointF(),
3156 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573157 true,
[email protected]fb661802013-03-25 01:59:323158 false);
3159 SetLayerPropertiesForTesting(child1.get(),
3160 identity_matrix,
[email protected]fb661802013-03-25 01:59:323161 gfx::PointF(),
3162 gfx::PointF(5.f, 5.f),
3163 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573164 true,
[email protected]fb661802013-03-25 01:59:323165 false);
3166 SetLayerPropertiesForTesting(child2.get(),
3167 identity_matrix,
[email protected]fb661802013-03-25 01:59:323168 gfx::PointF(),
3169 gfx::PointF(75.f, 75.f),
3170 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573171 true,
[email protected]fb661802013-03-25 01:59:323172 false);
3173 SetLayerPropertiesForTesting(child3.get(),
3174 identity_matrix,
[email protected]fb661802013-03-25 01:59:323175 gfx::PointF(),
3176 gfx::PointF(125.f, 125.f),
3177 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573178 true,
[email protected]fb661802013-03-25 01:59:323179 false);
3180
3181 root->SetMasksToBounds(true);
3182 render_surface1->SetForceRenderSurface(true);
3183 render_surface2->SetForceRenderSurface(true);
3184 ExecuteCalculateDrawProperties(root.get());
3185
3186 ASSERT_TRUE(render_surface1->render_surface());
3187 ASSERT_TRUE(render_surface2->render_surface());
3188
3189 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3190 root->render_surface()->DrawableContentRect());
3191 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3192
3193 // Layers that do not draw content should have empty visible content rects.
3194 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3195 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3196 render_surface1->visible_content_rect());
3197 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3198 render_surface2->visible_content_rect());
3199
3200 // A clipped surface grows its DrawableContentRect to include all drawable
3201 // regions of the subtree, but also gets clamped by the ancestor's clip.
3202 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3203 render_surface1->render_surface()->DrawableContentRect());
3204
3205 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3206 // is only implicitly clipped by render_surface1's content rect. So,
3207 // render_surface2 grows to enclose all drawable content of its subtree.
3208 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3209 render_surface2->render_surface()->DrawableContentRect());
3210
3211 // All layers that draw content into render_surface2 think they are unclipped.
3212 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3213 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3214 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
3215
3216 // DrawableContentRects are also unclipped.
3217 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3218 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3219 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3220}
3221
[email protected]989386c2013-07-18 21:37:233222TEST_F(LayerTreeHostCommonTest,
3223 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323224 // Layers that have non-axis aligned bounds (due to transforms) have an
3225 // expanded, axis-aligned DrawableContentRect and visible content rect.
3226
3227 scoped_refptr<Layer> root = Layer::Create();
3228 scoped_refptr<Layer> render_surface1 = Layer::Create();
3229 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3230 make_scoped_refptr(new LayerWithForcedDrawsContent());
3231 root->AddChild(render_surface1);
3232 render_surface1->AddChild(child1);
3233
[email protected]d600df7d2013-08-03 02:34:283234 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3235 host->SetRootLayer(root);
3236
[email protected]fb661802013-03-25 01:59:323237 gfx::Transform identity_matrix;
3238 gfx::Transform child_rotation;
3239 child_rotation.Rotate(45.0);
3240 SetLayerPropertiesForTesting(root.get(),
3241 identity_matrix,
[email protected]fb661802013-03-25 01:59:323242 gfx::PointF(),
3243 gfx::PointF(),
3244 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573245 true,
[email protected]fb661802013-03-25 01:59:323246 false);
3247 SetLayerPropertiesForTesting(render_surface1.get(),
3248 identity_matrix,
[email protected]fb661802013-03-25 01:59:323249 gfx::PointF(),
3250 gfx::PointF(),
3251 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573252 true,
[email protected]fb661802013-03-25 01:59:323253 false);
3254 SetLayerPropertiesForTesting(child1.get(),
3255 child_rotation,
[email protected]fb661802013-03-25 01:59:323256 gfx::PointF(0.5f, 0.5f),
3257 gfx::PointF(25.f, 25.f),
3258 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573259 true,
[email protected]fb661802013-03-25 01:59:323260 false);
3261
3262 render_surface1->SetForceRenderSurface(true);
3263 ExecuteCalculateDrawProperties(root.get());
3264
3265 ASSERT_TRUE(render_surface1->render_surface());
3266
3267 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3268 root->render_surface()->DrawableContentRect());
3269 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3270
3271 // Layers that do not draw content should have empty visible content rects.
3272 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3273 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3274 render_surface1->visible_content_rect());
3275
3276 // The unclipped surface grows its DrawableContentRect to include all drawable
3277 // regions of the subtree.
3278 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3279 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263280 gfx::Rect(50 - diagonal_radius,
3281 50 - diagonal_radius,
3282 diagonal_radius * 2,
3283 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323284 EXPECT_RECT_EQ(expected_surface_drawable_content,
3285 render_surface1->render_surface()->DrawableContentRect());
3286
3287 // All layers that draw content into the unclipped surface are also unclipped.
3288 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3289 EXPECT_RECT_EQ(expected_surface_drawable_content,
3290 child1->drawable_content_rect());
3291}
3292
[email protected]989386c2013-07-18 21:37:233293TEST_F(LayerTreeHostCommonTest,
3294 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323295 // Layers that have non-axis aligned bounds (due to transforms) have an
3296 // expanded, axis-aligned DrawableContentRect and visible content rect.
3297
3298 scoped_refptr<Layer> root = Layer::Create();
3299 scoped_refptr<Layer> render_surface1 = Layer::Create();
3300 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3301 make_scoped_refptr(new LayerWithForcedDrawsContent());
3302 root->AddChild(render_surface1);
3303 render_surface1->AddChild(child1);
3304
[email protected]d600df7d2013-08-03 02:34:283305 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3306 host->SetRootLayer(root);
3307
[email protected]fb661802013-03-25 01:59:323308 gfx::Transform identity_matrix;
3309 gfx::Transform child_rotation;
3310 child_rotation.Rotate(45.0);
3311 SetLayerPropertiesForTesting(root.get(),
3312 identity_matrix,
[email protected]fb661802013-03-25 01:59:323313 gfx::PointF(),
3314 gfx::PointF(),
3315 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573316 true,
[email protected]fb661802013-03-25 01:59:323317 false);
3318 SetLayerPropertiesForTesting(render_surface1.get(),
3319 identity_matrix,
[email protected]fb661802013-03-25 01:59:323320 gfx::PointF(),
3321 gfx::PointF(),
3322 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573323 true,
[email protected]fb661802013-03-25 01:59:323324 false);
3325 SetLayerPropertiesForTesting(child1.get(),
3326 child_rotation,
[email protected]fb661802013-03-25 01:59:323327 gfx::PointF(0.5f, 0.5f),
3328 gfx::PointF(25.f, 25.f),
3329 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573330 true,
[email protected]fb661802013-03-25 01:59:323331 false);
3332
3333 root->SetMasksToBounds(true);
3334 render_surface1->SetForceRenderSurface(true);
3335 ExecuteCalculateDrawProperties(root.get());
3336
3337 ASSERT_TRUE(render_surface1->render_surface());
3338
3339 // The clipped surface clamps the DrawableContentRect that encloses the
3340 // rotated layer.
3341 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263342 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3343 50 - diagonal_radius,
3344 diagonal_radius * 2,
3345 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323346 gfx::Rect expected_surface_drawable_content =
3347 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
3348 EXPECT_RECT_EQ(expected_surface_drawable_content,
3349 render_surface1->render_surface()->DrawableContentRect());
3350
3351 // On the clipped surface, only a quarter of the child1 is visible, but when
3352 // rotating it back to child1's content space, the actual enclosing rect ends
3353 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263354 //
3355 // Given the floating point math, this number is a little bit fuzzy.
[email protected]fb661802013-03-25 01:59:323356 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
3357
3358 // The child's DrawableContentRect is unclipped.
3359 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3360}
3361
[email protected]989386c2013-07-18 21:37:233362TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323363 MockContentLayerClient client;
3364
3365 scoped_refptr<Layer> root = Layer::Create();
3366 scoped_refptr<ContentLayer> render_surface1 =
3367 CreateDrawableContentLayer(&client);
3368 scoped_refptr<ContentLayer> render_surface2 =
3369 CreateDrawableContentLayer(&client);
3370 scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client);
3371 scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client);
3372 scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client);
3373 root->AddChild(render_surface1);
3374 render_surface1->AddChild(render_surface2);
3375 render_surface2->AddChild(child1);
3376 render_surface2->AddChild(child2);
3377 render_surface2->AddChild(child3);
3378
[email protected]d600df7d2013-08-03 02:34:283379 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3380 host->SetRootLayer(root);
3381
[email protected]fb661802013-03-25 01:59:323382 gfx::Transform identity_matrix;
3383 SetLayerPropertiesForTesting(root.get(),
3384 identity_matrix,
[email protected]fb661802013-03-25 01:59:323385 gfx::PointF(),
3386 gfx::PointF(),
3387 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573388 true,
[email protected]fb661802013-03-25 01:59:323389 false);
3390 SetLayerPropertiesForTesting(render_surface1.get(),
3391 identity_matrix,
[email protected]fb661802013-03-25 01:59:323392 gfx::PointF(),
3393 gfx::PointF(5.f, 5.f),
3394 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573395 true,
[email protected]fb661802013-03-25 01:59:323396 false);
3397 SetLayerPropertiesForTesting(render_surface2.get(),
3398 identity_matrix,
[email protected]fb661802013-03-25 01:59:323399 gfx::PointF(),
3400 gfx::PointF(5.f, 5.f),
3401 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573402 true,
[email protected]fb661802013-03-25 01:59:323403 false);
3404 SetLayerPropertiesForTesting(child1.get(),
3405 identity_matrix,
[email protected]fb661802013-03-25 01:59:323406 gfx::PointF(),
3407 gfx::PointF(5.f, 5.f),
3408 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573409 true,
[email protected]fb661802013-03-25 01:59:323410 false);
3411 SetLayerPropertiesForTesting(child2.get(),
3412 identity_matrix,
[email protected]fb661802013-03-25 01:59:323413 gfx::PointF(),
3414 gfx::PointF(75.f, 75.f),
3415 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573416 true,
[email protected]fb661802013-03-25 01:59:323417 false);
3418 SetLayerPropertiesForTesting(child3.get(),
3419 identity_matrix,
[email protected]fb661802013-03-25 01:59:323420 gfx::PointF(),
3421 gfx::PointF(125.f, 125.f),
3422 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573423 true,
[email protected]fb661802013-03-25 01:59:323424 false);
3425
3426 float device_scale_factor = 2.f;
3427
3428 root->SetMasksToBounds(true);
3429 render_surface1->SetForceRenderSurface(true);
3430 render_surface2->SetForceRenderSurface(true);
3431 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3432
3433 ASSERT_TRUE(render_surface1->render_surface());
3434 ASSERT_TRUE(render_surface2->render_surface());
3435
3436 // drawable_content_rects for all layers and surfaces are scaled by
3437 // device_scale_factor.
3438 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3439 root->render_surface()->DrawableContentRect());
3440 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3441 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3442 render_surface1->render_surface()->DrawableContentRect());
3443
3444 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3445 // is only implicitly clipped by render_surface1.
3446 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3447 render_surface2->render_surface()->DrawableContentRect());
3448
3449 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3450 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3451 child2->drawable_content_rect());
3452 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3453 child3->drawable_content_rect());
3454
3455 // The root layer does not actually draw content of its own.
3456 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3457
3458 // All layer visible content rects are expressed in content space of each
3459 // layer, so they are also scaled by the device_scale_factor.
3460 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8),
3461 render_surface1->visible_content_rect());
3462 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26),
3463 render_surface2->visible_content_rect());
3464 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect());
3465 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect());
3466 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect());
3467}
3468
[email protected]989386c2013-07-18 21:37:233469TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323470 // Verify the behavior of back-face culling when there are no preserve-3d
3471 // layers. Note that 3d transforms still apply in this case, but they are
3472 // "flattened" to each parent layer according to current W3C spec.
3473
3474 const gfx::Transform identity_matrix;
3475 scoped_refptr<Layer> parent = Layer::Create();
3476 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3477 make_scoped_refptr(new LayerWithForcedDrawsContent());
3478 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3479 make_scoped_refptr(new LayerWithForcedDrawsContent());
3480 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3481 make_scoped_refptr(new LayerWithForcedDrawsContent());
3482 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3483 make_scoped_refptr(new LayerWithForcedDrawsContent());
3484 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233485 front_facing_child_of_front_facing_surface =
3486 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323487 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233488 back_facing_child_of_front_facing_surface =
3489 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323490 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233491 front_facing_child_of_back_facing_surface =
3492 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323493 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233494 back_facing_child_of_back_facing_surface =
3495 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323496
3497 parent->AddChild(front_facing_child);
3498 parent->AddChild(back_facing_child);
3499 parent->AddChild(front_facing_surface);
3500 parent->AddChild(back_facing_surface);
3501 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3502 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3503 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3504 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3505
[email protected]d600df7d2013-08-03 02:34:283506 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3507 host->SetRootLayer(parent);
3508
[email protected]fb661802013-03-25 01:59:323509 // Nothing is double-sided
3510 front_facing_child->SetDoubleSided(false);
3511 back_facing_child->SetDoubleSided(false);
3512 front_facing_surface->SetDoubleSided(false);
3513 back_facing_surface->SetDoubleSided(false);
3514 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3515 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3516 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3517 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3518
3519 gfx::Transform backface_matrix;
3520 backface_matrix.Translate(50.0, 50.0);
3521 backface_matrix.RotateAboutYAxis(180.0);
3522 backface_matrix.Translate(-50.0, -50.0);
3523
3524 // Having a descendant and opacity will force these to have render surfaces.
3525 front_facing_surface->SetOpacity(0.5f);
3526 back_facing_surface->SetOpacity(0.5f);
3527
3528 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3529 // these layers should blindly use their own local transforms to determine
3530 // back-face culling.
3531 SetLayerPropertiesForTesting(parent.get(),
3532 identity_matrix,
[email protected]fb661802013-03-25 01:59:323533 gfx::PointF(),
3534 gfx::PointF(),
3535 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573536 true,
[email protected]fb661802013-03-25 01:59:323537 false);
3538 SetLayerPropertiesForTesting(front_facing_child.get(),
3539 identity_matrix,
[email protected]fb661802013-03-25 01:59:323540 gfx::PointF(),
3541 gfx::PointF(),
3542 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573543 true,
[email protected]fb661802013-03-25 01:59:323544 false);
3545 SetLayerPropertiesForTesting(back_facing_child.get(),
3546 backface_matrix,
[email protected]fb661802013-03-25 01:59:323547 gfx::PointF(),
3548 gfx::PointF(),
3549 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573550 true,
[email protected]fb661802013-03-25 01:59:323551 false);
3552 SetLayerPropertiesForTesting(front_facing_surface.get(),
3553 identity_matrix,
[email protected]fb661802013-03-25 01:59:323554 gfx::PointF(),
3555 gfx::PointF(),
3556 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573557 true,
[email protected]fb661802013-03-25 01:59:323558 false);
3559 SetLayerPropertiesForTesting(back_facing_surface.get(),
3560 backface_matrix,
[email protected]fb661802013-03-25 01:59:323561 gfx::PointF(),
3562 gfx::PointF(),
3563 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573564 true,
[email protected]fb661802013-03-25 01:59:323565 false);
3566 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3567 identity_matrix,
[email protected]fb661802013-03-25 01:59:323568 gfx::PointF(),
3569 gfx::PointF(),
3570 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573571 true,
[email protected]fb661802013-03-25 01:59:323572 false);
3573 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3574 backface_matrix,
[email protected]fb661802013-03-25 01:59:323575 gfx::PointF(),
3576 gfx::PointF(),
3577 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573578 true,
[email protected]fb661802013-03-25 01:59:323579 false);
3580 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3581 identity_matrix,
[email protected]fb661802013-03-25 01:59:323582 gfx::PointF(),
3583 gfx::PointF(),
3584 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573585 true,
[email protected]fb661802013-03-25 01:59:323586 false);
3587 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3588 backface_matrix,
[email protected]fb661802013-03-25 01:59:323589 gfx::PointF(),
3590 gfx::PointF(),
3591 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573592 true,
[email protected]fb661802013-03-25 01:59:323593 false);
3594
[email protected]989386c2013-07-18 21:37:233595 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533596 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3597 parent.get(), parent->bounds(), &render_surface_layer_list);
3598 inputs.can_adjust_raster_scales = true;
3599 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323600
3601 // Verify which render surfaces were created.
3602 EXPECT_FALSE(front_facing_child->render_surface());
3603 EXPECT_FALSE(back_facing_child->render_surface());
3604 EXPECT_TRUE(front_facing_surface->render_surface());
3605 EXPECT_TRUE(back_facing_surface->render_surface());
3606 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3607 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3608 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3609 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3610
3611 // Verify the render_surface_layer_list.
3612 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233613 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3614 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323615 // Even though the back facing surface LAYER gets culled, the other
3616 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233617 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323618
3619 // Verify root surface's layer list.
3620 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233621 3u,
3622 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3623 EXPECT_EQ(front_facing_child->id(),
3624 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573625 ->render_surface()
3626 ->layer_list()
3627 .at(0)
3628 ->id());
[email protected]989386c2013-07-18 21:37:233629 EXPECT_EQ(front_facing_surface->id(),
3630 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573631 ->render_surface()
3632 ->layer_list()
3633 .at(1)
3634 ->id());
[email protected]989386c2013-07-18 21:37:233635 EXPECT_EQ(back_facing_surface->id(),
3636 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573637 ->render_surface()
3638 ->layer_list()
3639 .at(2)
3640 ->id());
[email protected]fb661802013-03-25 01:59:323641
3642 // Verify front_facing_surface's layer list.
3643 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233644 2u,
3645 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3646 EXPECT_EQ(front_facing_surface->id(),
3647 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573648 ->render_surface()
3649 ->layer_list()
3650 .at(0)
3651 ->id());
[email protected]989386c2013-07-18 21:37:233652 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3653 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573654 ->render_surface()
3655 ->layer_list()
3656 .at(1)
3657 ->id());
[email protected]fb661802013-03-25 01:59:323658
3659 // Verify back_facing_surface's layer list; its own layer should be culled
3660 // from the surface list.
3661 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233662 1u,
3663 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3664 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3665 render_surface_layer_list.at(2)
[email protected]56fffdd2014-02-11 19:50:573666 ->render_surface()
3667 ->layer_list()
3668 .at(0)
3669 ->id());
[email protected]fb661802013-03-25 01:59:323670}
3671
[email protected]989386c2013-07-18 21:37:233672TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323673 // Verify the behavior of back-face culling when preserves-3d transform style
3674 // is used.
3675
3676 const gfx::Transform identity_matrix;
3677 scoped_refptr<Layer> parent = Layer::Create();
3678 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3679 make_scoped_refptr(new LayerWithForcedDrawsContent());
3680 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3681 make_scoped_refptr(new LayerWithForcedDrawsContent());
3682 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3683 make_scoped_refptr(new LayerWithForcedDrawsContent());
3684 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3685 make_scoped_refptr(new LayerWithForcedDrawsContent());
3686 scoped_refptr<LayerWithForcedDrawsContent>
3687 front_facing_child_of_front_facing_surface =
3688 make_scoped_refptr(new LayerWithForcedDrawsContent());
3689 scoped_refptr<LayerWithForcedDrawsContent>
3690 back_facing_child_of_front_facing_surface =
3691 make_scoped_refptr(new LayerWithForcedDrawsContent());
3692 scoped_refptr<LayerWithForcedDrawsContent>
3693 front_facing_child_of_back_facing_surface =
3694 make_scoped_refptr(new LayerWithForcedDrawsContent());
3695 scoped_refptr<LayerWithForcedDrawsContent>
3696 back_facing_child_of_back_facing_surface =
3697 make_scoped_refptr(new LayerWithForcedDrawsContent());
3698 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3699 make_scoped_refptr(new LayerWithForcedDrawsContent());
3700 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3701 make_scoped_refptr(new LayerWithForcedDrawsContent());
3702
3703 parent->AddChild(front_facing_child);
3704 parent->AddChild(back_facing_child);
3705 parent->AddChild(front_facing_surface);
3706 parent->AddChild(back_facing_surface);
3707 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3708 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3709 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3710 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3711
[email protected]d600df7d2013-08-03 02:34:283712 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3713 host->SetRootLayer(parent);
3714
[email protected]fb661802013-03-25 01:59:323715 // Nothing is double-sided
3716 front_facing_child->SetDoubleSided(false);
3717 back_facing_child->SetDoubleSided(false);
3718 front_facing_surface->SetDoubleSided(false);
3719 back_facing_surface->SetDoubleSided(false);
3720 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3721 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3722 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3723 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3724
3725 gfx::Transform backface_matrix;
3726 backface_matrix.Translate(50.0, 50.0);
3727 backface_matrix.RotateAboutYAxis(180.0);
3728 backface_matrix.Translate(-50.0, -50.0);
3729
3730 // Opacity will not force creation of render surfaces in this case because of
3731 // the preserve-3d transform style. Instead, an example of when a surface
3732 // would be created with preserve-3d is when there is a replica layer.
3733 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3734 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3735
3736 // Each surface creates its own new 3d rendering context (as defined by W3C
3737 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3738 // rendering context should use the transform with respect to that context.
3739 // This 3d rendering context occurs when (a) parent's transform style is flat
3740 // and (b) the layer's transform style is preserve-3d.
3741 SetLayerPropertiesForTesting(parent.get(),
3742 identity_matrix,
[email protected]fb661802013-03-25 01:59:323743 gfx::PointF(),
3744 gfx::PointF(),
3745 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573746 true,
[email protected]fb661802013-03-25 01:59:323747 false); // parent transform style is flat.
3748 SetLayerPropertiesForTesting(front_facing_child.get(),
3749 identity_matrix,
[email protected]fb661802013-03-25 01:59:323750 gfx::PointF(),
3751 gfx::PointF(),
3752 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573753 true,
[email protected]fb661802013-03-25 01:59:323754 false);
3755 SetLayerPropertiesForTesting(back_facing_child.get(),
3756 backface_matrix,
[email protected]fb661802013-03-25 01:59:323757 gfx::PointF(),
3758 gfx::PointF(),
3759 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573760 true,
[email protected]fb661802013-03-25 01:59:323761 false);
[email protected]56fffdd2014-02-11 19:50:573762 // surface transform style is preserve-3d.
3763 SetLayerPropertiesForTesting(front_facing_surface.get(),
3764 identity_matrix,
[email protected]56fffdd2014-02-11 19:50:573765 gfx::PointF(),
3766 gfx::PointF(),
3767 gfx::Size(100, 100),
3768 false,
3769 true);
3770 // surface transform style is preserve-3d.
3771 SetLayerPropertiesForTesting(back_facing_surface.get(),
3772 backface_matrix,
[email protected]56fffdd2014-02-11 19:50:573773 gfx::PointF(),
3774 gfx::PointF(),
3775 gfx::Size(100, 100),
3776 false,
3777 true);
[email protected]fb661802013-03-25 01:59:323778 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3779 identity_matrix,
[email protected]fb661802013-03-25 01:59:323780 gfx::PointF(),
3781 gfx::PointF(),
3782 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573783 true,
3784 true);
[email protected]fb661802013-03-25 01:59:323785 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3786 backface_matrix,
[email protected]fb661802013-03-25 01:59:323787 gfx::PointF(),
3788 gfx::PointF(),
3789 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573790 true,
3791 true);
[email protected]fb661802013-03-25 01:59:323792 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3793 identity_matrix,
[email protected]fb661802013-03-25 01:59:323794 gfx::PointF(),
3795 gfx::PointF(),
3796 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573797 true,
3798 true);
[email protected]fb661802013-03-25 01:59:323799 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3800 backface_matrix,
[email protected]fb661802013-03-25 01:59:323801 gfx::PointF(),
3802 gfx::PointF(),
3803 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573804 true,
3805 true);
[email protected]fb661802013-03-25 01:59:323806
[email protected]989386c2013-07-18 21:37:233807 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533808 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3809 parent.get(), parent->bounds(), &render_surface_layer_list);
3810 inputs.can_adjust_raster_scales = true;
3811 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323812
3813 // Verify which render surfaces were created.
3814 EXPECT_FALSE(front_facing_child->render_surface());
3815 EXPECT_FALSE(back_facing_child->render_surface());
3816 EXPECT_TRUE(front_facing_surface->render_surface());
3817 EXPECT_FALSE(back_facing_surface->render_surface());
3818 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3819 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3820 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3821 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3822
3823 // Verify the render_surface_layer_list. The back-facing surface should be
3824 // culled.
3825 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233826 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3827 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323828
3829 // Verify root surface's layer list.
3830 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233831 2u,
3832 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3833 EXPECT_EQ(front_facing_child->id(),
3834 render_surface_layer_list.at(0)
3835 ->render_surface()->layer_list().at(0)->id());
3836 EXPECT_EQ(front_facing_surface->id(),
3837 render_surface_layer_list.at(0)
3838 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323839
3840 // Verify front_facing_surface's layer list.
3841 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233842 2u,
3843 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3844 EXPECT_EQ(front_facing_surface->id(),
3845 render_surface_layer_list.at(1)
3846 ->render_surface()->layer_list().at(0)->id());
3847 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3848 render_surface_layer_list.at(1)
3849 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323850}
3851
[email protected]989386c2013-07-18 21:37:233852TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323853 // Verify that layers are appropriately culled when their back face is showing
3854 // and they are not double sided, while animations are going on.
3855 //
3856 // Layers that are animating do not get culled on the main thread, as their
3857 // transforms should be treated as "unknown" so we can not be sure that their
3858 // back face is really showing.
3859 const gfx::Transform identity_matrix;
3860 scoped_refptr<Layer> parent = Layer::Create();
3861 scoped_refptr<LayerWithForcedDrawsContent> child =
3862 make_scoped_refptr(new LayerWithForcedDrawsContent());
3863 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3864 make_scoped_refptr(new LayerWithForcedDrawsContent());
3865 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3866 make_scoped_refptr(new LayerWithForcedDrawsContent());
3867 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3868 make_scoped_refptr(new LayerWithForcedDrawsContent());
3869 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3870 make_scoped_refptr(new LayerWithForcedDrawsContent());
3871
3872 parent->AddChild(child);
3873 parent->AddChild(animating_surface);
3874 animating_surface->AddChild(child_of_animating_surface);
3875 parent->AddChild(animating_child);
3876 parent->AddChild(child2);
3877
[email protected]d600df7d2013-08-03 02:34:283878 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3879 host->SetRootLayer(parent);
3880
[email protected]fb661802013-03-25 01:59:323881 // Nothing is double-sided
3882 child->SetDoubleSided(false);
3883 child2->SetDoubleSided(false);
3884 animating_surface->SetDoubleSided(false);
3885 child_of_animating_surface->SetDoubleSided(false);
3886 animating_child->SetDoubleSided(false);
3887
3888 gfx::Transform backface_matrix;
3889 backface_matrix.Translate(50.0, 50.0);
3890 backface_matrix.RotateAboutYAxis(180.0);
3891 backface_matrix.Translate(-50.0, -50.0);
3892
3893 // Make our render surface.
3894 animating_surface->SetForceRenderSurface(true);
3895
3896 // Animate the transform on the render surface.
3897 AddAnimatedTransformToController(
3898 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3899 // This is just an animating layer, not a surface.
3900 AddAnimatedTransformToController(
3901 animating_child->layer_animation_controller(), 10.0, 30, 0);
3902
3903 SetLayerPropertiesForTesting(parent.get(),
3904 identity_matrix,
[email protected]fb661802013-03-25 01:59:323905 gfx::PointF(),
3906 gfx::PointF(),
3907 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573908 true,
[email protected]fb661802013-03-25 01:59:323909 false);
3910 SetLayerPropertiesForTesting(child.get(),
3911 backface_matrix,
[email protected]fb661802013-03-25 01:59:323912 gfx::PointF(),
3913 gfx::PointF(),
3914 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573915 true,
[email protected]fb661802013-03-25 01:59:323916 false);
3917 SetLayerPropertiesForTesting(animating_surface.get(),
3918 backface_matrix,
[email protected]fb661802013-03-25 01:59:323919 gfx::PointF(),
3920 gfx::PointF(),
3921 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573922 true,
[email protected]fb661802013-03-25 01:59:323923 false);
3924 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3925 backface_matrix,
[email protected]fb661802013-03-25 01:59:323926 gfx::PointF(),
3927 gfx::PointF(),
3928 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573929 true,
[email protected]fb661802013-03-25 01:59:323930 false);
3931 SetLayerPropertiesForTesting(animating_child.get(),
3932 backface_matrix,
[email protected]fb661802013-03-25 01:59:323933 gfx::PointF(),
3934 gfx::PointF(),
3935 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573936 true,
[email protected]fb661802013-03-25 01:59:323937 false);
3938 SetLayerPropertiesForTesting(child2.get(),
3939 identity_matrix,
[email protected]fb661802013-03-25 01:59:323940 gfx::PointF(),
3941 gfx::PointF(),
3942 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573943 true,
[email protected]fb661802013-03-25 01:59:323944 false);
3945
[email protected]989386c2013-07-18 21:37:233946 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533947 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3948 parent.get(), parent->bounds(), &render_surface_layer_list);
3949 inputs.can_adjust_raster_scales = true;
3950 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323951
3952 EXPECT_FALSE(child->render_surface());
3953 EXPECT_TRUE(animating_surface->render_surface());
3954 EXPECT_FALSE(child_of_animating_surface->render_surface());
3955 EXPECT_FALSE(animating_child->render_surface());
3956 EXPECT_FALSE(child2->render_surface());
3957
3958 // Verify that the animating_child and child_of_animating_surface were not
3959 // culled, but that child was.
3960 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233961 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3962 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323963
3964 // The non-animating child be culled from the layer list for the parent render
3965 // surface.
3966 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233967 3u,
3968 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3969 EXPECT_EQ(animating_surface->id(),
3970 render_surface_layer_list.at(0)
3971 ->render_surface()->layer_list().at(0)->id());
3972 EXPECT_EQ(animating_child->id(),
3973 render_surface_layer_list.at(0)
3974 ->render_surface()->layer_list().at(1)->id());
3975 EXPECT_EQ(child2->id(),
3976 render_surface_layer_list.at(0)
3977 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:323978
3979 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233980 2u,
3981 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3982 EXPECT_EQ(animating_surface->id(),
3983 render_surface_layer_list.at(1)
3984 ->render_surface()->layer_list().at(0)->id());
3985 EXPECT_EQ(child_of_animating_surface->id(),
3986 render_surface_layer_list.at(1)
3987 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323988
3989 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
3990
3991 // The animating layers should have a visible content rect that represents the
3992 // area of the front face that is within the viewport.
3993 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053994 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:323995 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053996 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:323997 // And layers in the subtree of the animating layer should have valid visible
3998 // content rects also.
[email protected]989386c2013-07-18 21:37:233999 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
4000 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324001}
4002
[email protected]989386c2013-07-18 21:37:234003TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324004 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4005 // Verify the behavior of back-face culling for a render surface that is
4006 // created when it flattens its subtree, and its parent has preserves-3d.
4007
4008 const gfx::Transform identity_matrix;
4009 scoped_refptr<Layer> parent = Layer::Create();
4010 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
4011 make_scoped_refptr(new LayerWithForcedDrawsContent());
4012 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
4013 make_scoped_refptr(new LayerWithForcedDrawsContent());
4014 scoped_refptr<LayerWithForcedDrawsContent> child1 =
4015 make_scoped_refptr(new LayerWithForcedDrawsContent());
4016 scoped_refptr<LayerWithForcedDrawsContent> child2 =
4017 make_scoped_refptr(new LayerWithForcedDrawsContent());
4018
4019 parent->AddChild(front_facing_surface);
4020 parent->AddChild(back_facing_surface);
4021 front_facing_surface->AddChild(child1);
4022 back_facing_surface->AddChild(child2);
4023
[email protected]d600df7d2013-08-03 02:34:284024 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4025 host->SetRootLayer(parent);
4026
[email protected]fb661802013-03-25 01:59:324027 // RenderSurfaces are not double-sided
4028 front_facing_surface->SetDoubleSided(false);
4029 back_facing_surface->SetDoubleSided(false);
4030
4031 gfx::Transform backface_matrix;
4032 backface_matrix.Translate(50.0, 50.0);
4033 backface_matrix.RotateAboutYAxis(180.0);
4034 backface_matrix.Translate(-50.0, -50.0);
4035
4036 SetLayerPropertiesForTesting(parent.get(),
4037 identity_matrix,
[email protected]fb661802013-03-25 01:59:324038 gfx::PointF(),
4039 gfx::PointF(),
4040 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574041 false,
4042 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:324043 SetLayerPropertiesForTesting(front_facing_surface.get(),
4044 identity_matrix,
[email protected]fb661802013-03-25 01:59:324045 gfx::PointF(),
4046 gfx::PointF(),
4047 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574048 true,
4049 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324050 SetLayerPropertiesForTesting(back_facing_surface.get(),
4051 backface_matrix,
[email protected]fb661802013-03-25 01:59:324052 gfx::PointF(),
4053 gfx::PointF(),
4054 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574055 true,
4056 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324057 SetLayerPropertiesForTesting(child1.get(),
4058 identity_matrix,
[email protected]fb661802013-03-25 01:59:324059 gfx::PointF(),
4060 gfx::PointF(),
4061 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574062 true,
[email protected]fb661802013-03-25 01:59:324063 false);
4064 SetLayerPropertiesForTesting(child2.get(),
4065 identity_matrix,
[email protected]fb661802013-03-25 01:59:324066 gfx::PointF(),
4067 gfx::PointF(),
4068 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574069 true,
[email protected]fb661802013-03-25 01:59:324070 false);
4071
[email protected]56fffdd2014-02-11 19:50:574072 front_facing_surface->SetIs3dSorted(true);
4073 back_facing_surface->SetIs3dSorted(true);
4074
[email protected]989386c2013-07-18 21:37:234075 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534076 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4077 parent.get(), parent->bounds(), &render_surface_layer_list);
4078 inputs.can_adjust_raster_scales = true;
4079 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324080
4081 // Verify which render surfaces were created.
4082 EXPECT_TRUE(front_facing_surface->render_surface());
4083 EXPECT_FALSE(
4084 back_facing_surface->render_surface()); // because it should be culled
4085 EXPECT_FALSE(child1->render_surface());
4086 EXPECT_FALSE(child2->render_surface());
4087
4088 // Verify the render_surface_layer_list. The back-facing surface should be
4089 // culled.
4090 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234091 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4092 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324093
4094 // Verify root surface's layer list.
4095 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234096 1u,
4097 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4098 EXPECT_EQ(front_facing_surface->id(),
4099 render_surface_layer_list.at(0)
4100 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324101
4102 // Verify front_facing_surface's layer list.
4103 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234104 2u,
4105 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4106 EXPECT_EQ(front_facing_surface->id(),
4107 render_surface_layer_list.at(1)
4108 ->render_surface()->layer_list().at(0)->id());
4109 EXPECT_EQ(child1->id(),
4110 render_surface_layer_list.at(1)
4111 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324112}
4113
[email protected]989386c2013-07-18 21:37:234114
4115TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:324116 // Hit testing on an empty render_surface_layer_list should return a null
4117 // pointer.
[email protected]50761e92013-03-29 20:51:284118 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:324119
4120 gfx::Point test_point(0, 0);
4121 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4122 test_point, render_surface_layer_list);
4123 EXPECT_FALSE(result_layer);
4124
4125 test_point = gfx::Point(10, 20);
4126 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4127 test_point, render_surface_layer_list);
4128 EXPECT_FALSE(result_layer);
4129}
4130
[email protected]989386c2013-07-18 21:37:234131TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayer) {
[email protected]fb661802013-03-25 01:59:324132 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454133 TestSharedBitmapManager shared_bitmap_manager;
4134 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324135 scoped_ptr<LayerImpl> root =
4136 LayerImpl::Create(host_impl.active_tree(), 12345);
4137
4138 gfx::Transform identity_matrix;
4139 gfx::PointF anchor;
4140 gfx::PointF position;
4141 gfx::Size bounds(100, 100);
4142 SetLayerPropertiesForTesting(root.get(),
4143 identity_matrix,
[email protected]fb661802013-03-25 01:59:324144 anchor,
4145 position,
4146 bounds,
[email protected]56fffdd2014-02-11 19:50:574147 true,
[email protected]fb661802013-03-25 01:59:324148 false);
4149 root->SetDrawsContent(true);
4150
[email protected]50761e92013-03-29 20:51:284151 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534152 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4153 root.get(), root->bounds(), &render_surface_layer_list);
4154 inputs.can_adjust_raster_scales = true;
4155 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324156
4157 // Sanity check the scenario we just created.
4158 ASSERT_EQ(1u, render_surface_layer_list.size());
4159 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4160
4161 // Hit testing for a point outside the layer should return a null pointer.
4162 gfx::Point test_point(101, 101);
4163 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4164 test_point, render_surface_layer_list);
4165 EXPECT_FALSE(result_layer);
4166
4167 test_point = gfx::Point(-1, -1);
4168 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4169 test_point, render_surface_layer_list);
4170 EXPECT_FALSE(result_layer);
4171
4172 // Hit testing for a point inside should return the root layer.
4173 test_point = gfx::Point(1, 1);
4174 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4175 test_point, render_surface_layer_list);
4176 ASSERT_TRUE(result_layer);
4177 EXPECT_EQ(12345, result_layer->id());
4178
4179 test_point = gfx::Point(99, 99);
4180 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4181 test_point, render_surface_layer_list);
4182 ASSERT_TRUE(result_layer);
4183 EXPECT_EQ(12345, result_layer->id());
4184}
4185
[email protected]989386c2013-07-18 21:37:234186TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) {
[email protected]fb661802013-03-25 01:59:324187 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454188 TestSharedBitmapManager shared_bitmap_manager;
4189 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324190 scoped_ptr<LayerImpl> root =
4191 LayerImpl::Create(host_impl.active_tree(), 12345);
4192 scoped_ptr<HeadsUpDisplayLayerImpl> hud =
4193 HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111);
4194
4195 gfx::Transform identity_matrix;
4196 gfx::PointF anchor;
4197 gfx::PointF position;
4198 gfx::Size bounds(100, 100);
4199 SetLayerPropertiesForTesting(root.get(),
4200 identity_matrix,
[email protected]fb661802013-03-25 01:59:324201 anchor,
4202 position,
4203 bounds,
[email protected]56fffdd2014-02-11 19:50:574204 true,
[email protected]fb661802013-03-25 01:59:324205 false);
4206 root->SetDrawsContent(true);
4207
4208 // Create hud and add it as a child of root.
4209 gfx::Size hud_bounds(200, 200);
4210 SetLayerPropertiesForTesting(hud.get(),
4211 identity_matrix,
[email protected]fb661802013-03-25 01:59:324212 anchor,
4213 position,
4214 hud_bounds,
[email protected]56fffdd2014-02-11 19:50:574215 true,
[email protected]fb661802013-03-25 01:59:324216 false);
4217 hud->SetDrawsContent(true);
4218
4219 host_impl.active_tree()->set_hud_layer(hud.get());
4220 root->AddChild(hud.PassAs<LayerImpl>());
4221
[email protected]50761e92013-03-29 20:51:284222 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534223 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4224 root.get(), hud_bounds, &render_surface_layer_list);
4225 inputs.can_adjust_raster_scales = true;
4226 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324227
4228 // Sanity check the scenario we just created.
4229 ASSERT_EQ(1u, render_surface_layer_list.size());
4230 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4231
4232 // Hit testing for a point inside HUD, but outside root should return null
4233 gfx::Point test_point(101, 101);
4234 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4235 test_point, render_surface_layer_list);
4236 EXPECT_FALSE(result_layer);
4237
4238 test_point = gfx::Point(-1, -1);
4239 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4240 test_point, render_surface_layer_list);
4241 EXPECT_FALSE(result_layer);
4242
4243 // Hit testing for a point inside should return the root layer, never the HUD
4244 // layer.
4245 test_point = gfx::Point(1, 1);
4246 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4247 test_point, render_surface_layer_list);
4248 ASSERT_TRUE(result_layer);
4249 EXPECT_EQ(12345, result_layer->id());
4250
4251 test_point = gfx::Point(99, 99);
4252 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4253 test_point, render_surface_layer_list);
4254 ASSERT_TRUE(result_layer);
4255 EXPECT_EQ(12345, result_layer->id());
4256}
4257
[email protected]989386c2013-07-18 21:37:234258TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) {
[email protected]fb661802013-03-25 01:59:324259 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454260 TestSharedBitmapManager shared_bitmap_manager;
4261 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324262 scoped_ptr<LayerImpl> root =
4263 LayerImpl::Create(host_impl.active_tree(), 12345);
4264
4265 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:264266 uninvertible_transform.matrix().set(0, 0, 0.0);
4267 uninvertible_transform.matrix().set(1, 1, 0.0);
4268 uninvertible_transform.matrix().set(2, 2, 0.0);
4269 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:324270 ASSERT_FALSE(uninvertible_transform.IsInvertible());
4271
4272 gfx::Transform identity_matrix;
4273 gfx::PointF anchor;
4274 gfx::PointF position;
4275 gfx::Size bounds(100, 100);
4276 SetLayerPropertiesForTesting(root.get(),
4277 uninvertible_transform,
[email protected]fb661802013-03-25 01:59:324278 anchor,
4279 position,
4280 bounds,
[email protected]56fffdd2014-02-11 19:50:574281 true,
[email protected]fb661802013-03-25 01:59:324282 false);
4283 root->SetDrawsContent(true);
4284
[email protected]50761e92013-03-29 20:51:284285 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534286 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4287 root.get(), root->bounds(), &render_surface_layer_list);
4288 inputs.can_adjust_raster_scales = true;
4289 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324290
4291 // Sanity check the scenario we just created.
4292 ASSERT_EQ(1u, render_surface_layer_list.size());
4293 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4294 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
4295
4296 // Hit testing any point should not hit the layer. If the invertible matrix is
4297 // accidentally ignored and treated like an identity, then the hit testing
4298 // will incorrectly hit the layer when it shouldn't.
4299 gfx::Point test_point(1, 1);
4300 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4301 test_point, render_surface_layer_list);
4302 EXPECT_FALSE(result_layer);
4303
4304 test_point = gfx::Point(10, 10);
4305 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4306 test_point, render_surface_layer_list);
4307 EXPECT_FALSE(result_layer);
4308
4309 test_point = gfx::Point(10, 30);
4310 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4311 test_point, render_surface_layer_list);
4312 EXPECT_FALSE(result_layer);
4313
4314 test_point = gfx::Point(50, 50);
4315 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4316 test_point, render_surface_layer_list);
4317 EXPECT_FALSE(result_layer);
4318
4319 test_point = gfx::Point(67, 48);
4320 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4321 test_point, render_surface_layer_list);
4322 EXPECT_FALSE(result_layer);
4323
4324 test_point = gfx::Point(99, 99);
4325 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4326 test_point, render_surface_layer_list);
4327 EXPECT_FALSE(result_layer);
4328
4329 test_point = gfx::Point(-1, -1);
4330 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4331 test_point, render_surface_layer_list);
4332 EXPECT_FALSE(result_layer);
4333}
4334
[email protected]989386c2013-07-18 21:37:234335TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) {
[email protected]fb661802013-03-25 01:59:324336 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454337 TestSharedBitmapManager shared_bitmap_manager;
4338 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324339 scoped_ptr<LayerImpl> root =
4340 LayerImpl::Create(host_impl.active_tree(), 12345);
4341
4342 gfx::Transform identity_matrix;
4343 gfx::PointF anchor;
4344 // this layer is positioned, and hit testing should correctly know where the
4345 // layer is located.
4346 gfx::PointF position(50.f, 50.f);
4347 gfx::Size bounds(100, 100);
4348 SetLayerPropertiesForTesting(root.get(),
4349 identity_matrix,
[email protected]fb661802013-03-25 01:59:324350 anchor,
4351 position,
4352 bounds,
[email protected]56fffdd2014-02-11 19:50:574353 true,
[email protected]fb661802013-03-25 01:59:324354 false);
4355 root->SetDrawsContent(true);
4356
[email protected]50761e92013-03-29 20:51:284357 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534358 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4359 root.get(), root->bounds(), &render_surface_layer_list);
4360 inputs.can_adjust_raster_scales = true;
4361 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324362
4363 // Sanity check the scenario we just created.
4364 ASSERT_EQ(1u, render_surface_layer_list.size());
4365 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4366
4367 // Hit testing for a point outside the layer should return a null pointer.
4368 gfx::Point test_point(49, 49);
4369 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4370 test_point, render_surface_layer_list);
4371 EXPECT_FALSE(result_layer);
4372
4373 // Even though the layer exists at (101, 101), it should not be visible there
4374 // since the root render surface would clamp it.
4375 test_point = gfx::Point(101, 101);
4376 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4377 test_point, render_surface_layer_list);
4378 EXPECT_FALSE(result_layer);
4379
4380 // Hit testing for a point inside should return the root layer.
4381 test_point = gfx::Point(51, 51);
4382 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4383 test_point, render_surface_layer_list);
4384 ASSERT_TRUE(result_layer);
4385 EXPECT_EQ(12345, result_layer->id());
4386
4387 test_point = gfx::Point(99, 99);
4388 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4389 test_point, render_surface_layer_list);
4390 ASSERT_TRUE(result_layer);
4391 EXPECT_EQ(12345, result_layer->id());
4392}
4393
[email protected]989386c2013-07-18 21:37:234394TEST_F(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324395 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454396 TestSharedBitmapManager shared_bitmap_manager;
4397 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324398 scoped_ptr<LayerImpl> root =
4399 LayerImpl::Create(host_impl.active_tree(), 12345);
4400
4401 gfx::Transform identity_matrix;
4402 gfx::Transform rotation45_degrees_about_center;
4403 rotation45_degrees_about_center.Translate(50.0, 50.0);
4404 rotation45_degrees_about_center.RotateAboutZAxis(45.0);
4405 rotation45_degrees_about_center.Translate(-50.0, -50.0);
4406 gfx::PointF anchor;
4407 gfx::PointF position;
4408 gfx::Size bounds(100, 100);
4409 SetLayerPropertiesForTesting(root.get(),
4410 rotation45_degrees_about_center,
[email protected]fb661802013-03-25 01:59:324411 anchor,
4412 position,
4413 bounds,
[email protected]56fffdd2014-02-11 19:50:574414 true,
[email protected]fb661802013-03-25 01:59:324415 false);
4416 root->SetDrawsContent(true);
4417
[email protected]50761e92013-03-29 20:51:284418 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534419 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4420 root.get(), root->bounds(), &render_surface_layer_list);
4421 inputs.can_adjust_raster_scales = true;
4422 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324423
4424 // Sanity check the scenario we just created.
4425 ASSERT_EQ(1u, render_surface_layer_list.size());
4426 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4427
4428 // Hit testing for points outside the layer.
4429 // These corners would have been inside the un-transformed layer, but they
4430 // should not hit the correctly transformed layer.
4431 gfx::Point test_point(99, 99);
4432 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4433 test_point, render_surface_layer_list);
4434 EXPECT_FALSE(result_layer);
4435
4436 test_point = gfx::Point(1, 1);
4437 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4438 test_point, render_surface_layer_list);
4439 EXPECT_FALSE(result_layer);
4440
4441 // Hit testing for a point inside should return the root layer.
4442 test_point = gfx::Point(1, 50);
4443 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4444 test_point, render_surface_layer_list);
4445 ASSERT_TRUE(result_layer);
4446 EXPECT_EQ(12345, result_layer->id());
4447
4448 // Hit testing the corners that would overlap the unclipped layer, but are
4449 // outside the clipped region.
4450 test_point = gfx::Point(50, -1);
4451 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4452 test_point, render_surface_layer_list);
4453 ASSERT_FALSE(result_layer);
4454
4455 test_point = gfx::Point(-1, 50);
4456 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4457 test_point, render_surface_layer_list);
4458 ASSERT_FALSE(result_layer);
4459}
4460
[email protected]989386c2013-07-18 21:37:234461TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) {
[email protected]fb661802013-03-25 01:59:324462 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454463 TestSharedBitmapManager shared_bitmap_manager;
4464 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324465 scoped_ptr<LayerImpl> root =
4466 LayerImpl::Create(host_impl.active_tree(), 12345);
4467
4468 gfx::Transform identity_matrix;
4469
4470 // perspective_projection_about_center * translation_by_z is designed so that
4471 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
4472 gfx::Transform perspective_projection_about_center;
4473 perspective_projection_about_center.Translate(50.0, 50.0);
4474 perspective_projection_about_center.ApplyPerspectiveDepth(1.0);
4475 perspective_projection_about_center.Translate(-50.0, -50.0);
4476 gfx::Transform translation_by_z;
4477 translation_by_z.Translate3d(0.0, 0.0, -1.0);
4478
4479 gfx::PointF anchor;
4480 gfx::PointF position;
4481 gfx::Size bounds(100, 100);
4482 SetLayerPropertiesForTesting(
4483 root.get(),
4484 perspective_projection_about_center * translation_by_z,
[email protected]fb661802013-03-25 01:59:324485 anchor,
4486 position,
4487 bounds,
[email protected]56fffdd2014-02-11 19:50:574488 true,
[email protected]fb661802013-03-25 01:59:324489 false);
4490 root->SetDrawsContent(true);
4491
[email protected]50761e92013-03-29 20:51:284492 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534493 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4494 root.get(), root->bounds(), &render_surface_layer_list);
4495 inputs.can_adjust_raster_scales = true;
4496 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324497
4498 // Sanity check the scenario we just created.
4499 ASSERT_EQ(1u, render_surface_layer_list.size());
4500 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4501
4502 // Hit testing for points outside the layer.
4503 // These corners would have been inside the un-transformed layer, but they
4504 // should not hit the correctly transformed layer.
4505 gfx::Point test_point(24, 24);
4506 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4507 test_point, render_surface_layer_list);
4508 EXPECT_FALSE(result_layer);
4509
4510 test_point = gfx::Point(76, 76);
4511 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4512 test_point, render_surface_layer_list);
4513 EXPECT_FALSE(result_layer);
4514
4515 // Hit testing for a point inside should return the root layer.
4516 test_point = gfx::Point(26, 26);
4517 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4518 test_point, render_surface_layer_list);
4519 ASSERT_TRUE(result_layer);
4520 EXPECT_EQ(12345, result_layer->id());
4521
4522 test_point = gfx::Point(74, 74);
4523 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4524 test_point, render_surface_layer_list);
4525 ASSERT_TRUE(result_layer);
4526 EXPECT_EQ(12345, result_layer->id());
4527}
4528
[email protected]989386c2013-07-18 21:37:234529TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) {
[email protected]fb661802013-03-25 01:59:324530 // A layer's visible content rect is actually in the layer's content space.
4531 // The screen space transform converts from the layer's origin space to screen
4532 // space. This test makes sure that hit testing works correctly accounts for
4533 // the contents scale. A contents scale that is not 1 effectively forces a
4534 // non-identity transform between layer's content space and layer's origin
4535 // space. The hit testing code must take this into account.
4536 //
4537 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
4538 // contents scale is ignored, then hit testing will mis-interpret the visible
4539 // content rect as being larger than the actual bounds of the layer.
4540 //
4541 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454542 TestSharedBitmapManager shared_bitmap_manager;
4543 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324544 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4545
4546 gfx::Transform identity_matrix;
4547 gfx::PointF anchor;
4548
4549 SetLayerPropertiesForTesting(root.get(),
4550 identity_matrix,
[email protected]fb661802013-03-25 01:59:324551 anchor,
4552 gfx::PointF(),
4553 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574554 true,
[email protected]fb661802013-03-25 01:59:324555 false);
4556 {
4557 gfx::PointF position(25.f, 25.f);
4558 gfx::Size bounds(50, 50);
4559 scoped_ptr<LayerImpl> test_layer =
4560 LayerImpl::Create(host_impl.active_tree(), 12345);
4561 SetLayerPropertiesForTesting(test_layer.get(),
4562 identity_matrix,
[email protected]fb661802013-03-25 01:59:324563 anchor,
4564 position,
4565 bounds,
[email protected]56fffdd2014-02-11 19:50:574566 true,
[email protected]fb661802013-03-25 01:59:324567 false);
4568
4569 // override content bounds and contents scale
4570 test_layer->SetContentBounds(gfx::Size(100, 100));
4571 test_layer->SetContentsScale(2, 2);
4572
4573 test_layer->SetDrawsContent(true);
4574 root->AddChild(test_layer.Pass());
4575 }
4576
[email protected]50761e92013-03-29 20:51:284577 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534578 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4579 root.get(), root->bounds(), &render_surface_layer_list);
4580 inputs.can_adjust_raster_scales = true;
4581 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324582
4583 // Sanity check the scenario we just created.
4584 // The visible content rect for test_layer is actually 100x100, even though
4585 // its layout size is 50x50, positioned at 25x25.
4586 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:054587 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
[email protected]fb661802013-03-25 01:59:324588 test_layer->visible_content_rect());
4589 ASSERT_EQ(1u, render_surface_layer_list.size());
4590 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4591
4592 // Hit testing for a point outside the layer should return a null pointer (the
4593 // root layer does not draw content, so it will not be hit tested either).
4594 gfx::Point test_point(101, 101);
4595 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4596 test_point, render_surface_layer_list);
4597 EXPECT_FALSE(result_layer);
4598
4599 test_point = gfx::Point(24, 24);
4600 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4601 test_point, render_surface_layer_list);
4602 EXPECT_FALSE(result_layer);
4603
4604 test_point = gfx::Point(76, 76);
4605 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4606 test_point, render_surface_layer_list);
4607 EXPECT_FALSE(result_layer);
4608
4609 // Hit testing for a point inside should return the test layer.
4610 test_point = gfx::Point(26, 26);
4611 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4612 test_point, render_surface_layer_list);
4613 ASSERT_TRUE(result_layer);
4614 EXPECT_EQ(12345, result_layer->id());
4615
4616 test_point = gfx::Point(74, 74);
4617 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4618 test_point, render_surface_layer_list);
4619 ASSERT_TRUE(result_layer);
4620 EXPECT_EQ(12345, result_layer->id());
4621}
4622
[email protected]989386c2013-07-18 21:37:234623TEST_F(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) {
[email protected]fb661802013-03-25 01:59:324624 // Test that hit-testing will only work for the visible portion of a layer,
4625 // and not the entire layer bounds. Here we just test the simple axis-aligned
4626 // case.
4627 gfx::Transform identity_matrix;
4628 gfx::PointF anchor;
4629
4630 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454631 TestSharedBitmapManager shared_bitmap_manager;
4632 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324633 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4634 SetLayerPropertiesForTesting(root.get(),
4635 identity_matrix,
[email protected]fb661802013-03-25 01:59:324636 anchor,
4637 gfx::PointF(),
4638 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574639 true,
[email protected]fb661802013-03-25 01:59:324640 false);
4641 {
4642 scoped_ptr<LayerImpl> clipping_layer =
4643 LayerImpl::Create(host_impl.active_tree(), 123);
4644 // this layer is positioned, and hit testing should correctly know where the
4645 // layer is located.
[email protected]ca2902e92013-03-28 01:45:354646 gfx::PointF position(25.f, 25.f);
[email protected]fb661802013-03-25 01:59:324647 gfx::Size bounds(50, 50);
4648 SetLayerPropertiesForTesting(clipping_layer.get(),
4649 identity_matrix,
[email protected]fb661802013-03-25 01:59:324650 anchor,
4651 position,
4652 bounds,
[email protected]56fffdd2014-02-11 19:50:574653 true,
[email protected]fb661802013-03-25 01:59:324654 false);
4655 clipping_layer->SetMasksToBounds(true);
4656
4657 scoped_ptr<LayerImpl> child =
4658 LayerImpl::Create(host_impl.active_tree(), 456);
4659 position = gfx::PointF(-50.f, -50.f);
4660 bounds = gfx::Size(300, 300);
4661 SetLayerPropertiesForTesting(child.get(),
4662 identity_matrix,
[email protected]fb661802013-03-25 01:59:324663 anchor,
4664 position,
4665 bounds,
[email protected]56fffdd2014-02-11 19:50:574666 true,
[email protected]fb661802013-03-25 01:59:324667 false);
4668 child->SetDrawsContent(true);
4669 clipping_layer->AddChild(child.Pass());
4670 root->AddChild(clipping_layer.Pass());
4671 }
4672
[email protected]50761e92013-03-29 20:51:284673 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534674 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4675 root.get(), root->bounds(), &render_surface_layer_list);
4676 inputs.can_adjust_raster_scales = true;
4677 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324678
4679 // Sanity check the scenario we just created.
4680 ASSERT_EQ(1u, render_surface_layer_list.size());
4681 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234682 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324683
4684 // Hit testing for a point outside the layer should return a null pointer.
4685 // Despite the child layer being very large, it should be clipped to the root
4686 // layer's bounds.
4687 gfx::Point test_point(24, 24);
4688 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4689 test_point, render_surface_layer_list);
4690 EXPECT_FALSE(result_layer);
4691
4692 // Even though the layer exists at (101, 101), it should not be visible there
4693 // since the clipping_layer would clamp it.
4694 test_point = gfx::Point(76, 76);
4695 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4696 test_point, render_surface_layer_list);
4697 EXPECT_FALSE(result_layer);
4698
4699 // Hit testing for a point inside should return the child layer.
4700 test_point = gfx::Point(26, 26);
4701 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4702 test_point, render_surface_layer_list);
4703 ASSERT_TRUE(result_layer);
4704 EXPECT_EQ(456, result_layer->id());
4705
4706 test_point = gfx::Point(74, 74);
4707 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4708 test_point, render_surface_layer_list);
4709 ASSERT_TRUE(result_layer);
4710 EXPECT_EQ(456, result_layer->id());
4711}
4712
[email protected]989386c2013-07-18 21:37:234713TEST_F(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324714 // This test checks whether hit testing correctly avoids hit testing with
4715 // multiple ancestors that clip in non axis-aligned ways. To pass this test,
4716 // the hit testing algorithm needs to recognize that multiple parent layers
4717 // may clip the layer, and should not actually hit those clipped areas.
4718 //
4719 // The child and grand_child layers are both initialized to clip the
4720 // rotated_leaf. The child layer is rotated about the top-left corner, so that
4721 // the root + child clips combined create a triangle. The rotated_leaf will
4722 // only be visible where it overlaps this triangle.
4723 //
4724 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454725 TestSharedBitmapManager shared_bitmap_manager;
4726 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324727 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123);
4728
4729 gfx::Transform identity_matrix;
4730 gfx::PointF anchor;
4731 gfx::PointF position;
4732 gfx::Size bounds(100, 100);
4733 SetLayerPropertiesForTesting(root.get(),
4734 identity_matrix,
[email protected]fb661802013-03-25 01:59:324735 anchor,
4736 position,
4737 bounds,
[email protected]56fffdd2014-02-11 19:50:574738 true,
[email protected]fb661802013-03-25 01:59:324739 false);
4740 root->SetMasksToBounds(true);
4741 {
4742 scoped_ptr<LayerImpl> child =
4743 LayerImpl::Create(host_impl.active_tree(), 456);
4744 scoped_ptr<LayerImpl> grand_child =
4745 LayerImpl::Create(host_impl.active_tree(), 789);
4746 scoped_ptr<LayerImpl> rotated_leaf =
4747 LayerImpl::Create(host_impl.active_tree(), 2468);
4748
4749 position = gfx::PointF(10.f, 10.f);
4750 bounds = gfx::Size(80, 80);
4751 SetLayerPropertiesForTesting(child.get(),
4752 identity_matrix,
[email protected]fb661802013-03-25 01:59:324753 anchor,
4754 position,
4755 bounds,
[email protected]56fffdd2014-02-11 19:50:574756 true,
[email protected]fb661802013-03-25 01:59:324757 false);
[email protected]7aba6662013-03-12 10:17:344758 child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444759
[email protected]fb661802013-03-25 01:59:324760 gfx::Transform rotation45_degrees_about_corner;
4761 rotation45_degrees_about_corner.RotateAboutZAxis(45.0);
[email protected]aedf4e52013-01-09 23:24:444762
[email protected]fb661802013-03-25 01:59:324763 // remember, positioned with respect to its parent which is already at 10,
4764 // 10
4765 position = gfx::PointF();
4766 bounds =
4767 gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
4768 SetLayerPropertiesForTesting(grand_child.get(),
4769 rotation45_degrees_about_corner,
[email protected]fb661802013-03-25 01:59:324770 anchor,
4771 position,
4772 bounds,
[email protected]56fffdd2014-02-11 19:50:574773 true,
[email protected]fb661802013-03-25 01:59:324774 false);
4775 grand_child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444776
[email protected]fb661802013-03-25 01:59:324777 // Rotates about the center of the layer
4778 gfx::Transform rotated_leaf_transform;
4779 rotated_leaf_transform.Translate(
4780 -10.0, -10.0); // cancel out the grand_parent's position
4781 rotated_leaf_transform.RotateAboutZAxis(
4782 -45.0); // cancel out the corner 45-degree rotation of the parent.
4783 rotated_leaf_transform.Translate(50.0, 50.0);
4784 rotated_leaf_transform.RotateAboutZAxis(45.0);
4785 rotated_leaf_transform.Translate(-50.0, -50.0);
4786 position = gfx::PointF();
4787 bounds = gfx::Size(100, 100);
4788 SetLayerPropertiesForTesting(rotated_leaf.get(),
4789 rotated_leaf_transform,
[email protected]fb661802013-03-25 01:59:324790 anchor,
4791 position,
4792 bounds,
[email protected]56fffdd2014-02-11 19:50:574793 true,
[email protected]fb661802013-03-25 01:59:324794 false);
4795 rotated_leaf->SetDrawsContent(true);
[email protected]aedf4e52013-01-09 23:24:444796
[email protected]fb661802013-03-25 01:59:324797 grand_child->AddChild(rotated_leaf.Pass());
4798 child->AddChild(grand_child.Pass());
4799 root->AddChild(child.Pass());
4800 }
[email protected]aedf4e52013-01-09 23:24:444801
[email protected]50761e92013-03-29 20:51:284802 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534803 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4804 root.get(), root->bounds(), &render_surface_layer_list);
4805 inputs.can_adjust_raster_scales = true;
4806 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:444807
[email protected]fb661802013-03-25 01:59:324808 // Sanity check the scenario we just created.
4809 // The grand_child is expected to create a render surface because it
[email protected]989386c2013-07-18 21:37:234810 // MasksToBounds and is not axis aligned.
[email protected]fb661802013-03-25 01:59:324811 ASSERT_EQ(2u, render_surface_layer_list.size());
4812 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234813 1u,
4814 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324815 ASSERT_EQ(789,
[email protected]989386c2013-07-18 21:37:234816 render_surface_layer_list.at(0)->render_surface()->layer_list().at(
4817 0)->id()); // grand_child's surface.
[email protected]fb661802013-03-25 01:59:324818 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234819 1u,
4820 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324821 ASSERT_EQ(
4822 2468,
[email protected]989386c2013-07-18 21:37:234823 render_surface_layer_list[1]->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324824
4825 // (11, 89) is close to the the bottom left corner within the clip, but it is
4826 // not inside the layer.
4827 gfx::Point test_point(11, 89);
4828 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4829 test_point, render_surface_layer_list);
4830 EXPECT_FALSE(result_layer);
4831
4832 // Closer inwards from the bottom left will overlap the layer.
4833 test_point = gfx::Point(25, 75);
4834 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4835 test_point, render_surface_layer_list);
4836 ASSERT_TRUE(result_layer);
4837 EXPECT_EQ(2468, result_layer->id());
4838
4839 // (4, 50) is inside the unclipped layer, but that corner of the layer should
4840 // be clipped away by the grandparent and should not get hit. If hit testing
4841 // blindly uses visible content rect without considering how parent may clip
4842 // the layer, then hit testing would accidentally think that the point
4843 // successfully hits the layer.
4844 test_point = gfx::Point(4, 50);
4845 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4846 test_point, render_surface_layer_list);
4847 EXPECT_FALSE(result_layer);
4848
4849 // (11, 50) is inside the layer and within the clipped area.
4850 test_point = gfx::Point(11, 50);
4851 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4852 test_point, render_surface_layer_list);
4853 ASSERT_TRUE(result_layer);
4854 EXPECT_EQ(2468, result_layer->id());
4855
4856 // Around the middle, just to the right and up, would have hit the layer
4857 // except that that area should be clipped away by the parent.
[email protected]803f6b52013-09-12 00:51:264858 test_point = gfx::Point(51, 49);
[email protected]fb661802013-03-25 01:59:324859 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4860 test_point, render_surface_layer_list);
4861 EXPECT_FALSE(result_layer);
4862
4863 // Around the middle, just to the left and down, should successfully hit the
4864 // layer.
4865 test_point = gfx::Point(49, 51);
4866 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4867 test_point, render_surface_layer_list);
4868 ASSERT_TRUE(result_layer);
4869 EXPECT_EQ(2468, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:444870}
4871
[email protected]989386c2013-07-18 21:37:234872TEST_F(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:324873 // This test checks that hit testing code does not accidentally clip to layer
4874 // bounds for a layer that actually does not clip.
4875 gfx::Transform identity_matrix;
4876 gfx::PointF anchor;
[email protected]aedf4e52013-01-09 23:24:444877
[email protected]fb661802013-03-25 01:59:324878 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454879 TestSharedBitmapManager shared_bitmap_manager;
4880 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324881 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4882 SetLayerPropertiesForTesting(root.get(),
4883 identity_matrix,
[email protected]fb661802013-03-25 01:59:324884 anchor,
4885 gfx::PointF(),
4886 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574887 true,
[email protected]fb661802013-03-25 01:59:324888 false);
4889 {
4890 scoped_ptr<LayerImpl> intermediate_layer =
4891 LayerImpl::Create(host_impl.active_tree(), 123);
4892 // this layer is positioned, and hit testing should correctly know where the
4893 // layer is located.
4894 gfx::PointF position(10.f, 10.f);
4895 gfx::Size bounds(50, 50);
4896 SetLayerPropertiesForTesting(intermediate_layer.get(),
4897 identity_matrix,
[email protected]fb661802013-03-25 01:59:324898 anchor,
4899 position,
4900 bounds,
[email protected]56fffdd2014-02-11 19:50:574901 true,
[email protected]fb661802013-03-25 01:59:324902 false);
4903 // Sanity check the intermediate layer should not clip.
4904 ASSERT_FALSE(intermediate_layer->masks_to_bounds());
4905 ASSERT_FALSE(intermediate_layer->mask_layer());
[email protected]aedf4e52013-01-09 23:24:444906
[email protected]fb661802013-03-25 01:59:324907 // The child of the intermediate_layer is translated so that it does not
4908 // overlap intermediate_layer at all. If child is incorrectly clipped, we
4909 // would not be able to hit it successfully.
4910 scoped_ptr<LayerImpl> child =
4911 LayerImpl::Create(host_impl.active_tree(), 456);
4912 position = gfx::PointF(60.f, 60.f); // 70, 70 in screen space
4913 bounds = gfx::Size(20, 20);
4914 SetLayerPropertiesForTesting(child.get(),
4915 identity_matrix,
[email protected]fb661802013-03-25 01:59:324916 anchor,
4917 position,
4918 bounds,
[email protected]56fffdd2014-02-11 19:50:574919 true,
[email protected]fb661802013-03-25 01:59:324920 false);
4921 child->SetDrawsContent(true);
4922 intermediate_layer->AddChild(child.Pass());
4923 root->AddChild(intermediate_layer.Pass());
4924 }
[email protected]aedf4e52013-01-09 23:24:444925
[email protected]50761e92013-03-29 20:51:284926 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534927 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4928 root.get(), root->bounds(), &render_surface_layer_list);
4929 inputs.can_adjust_raster_scales = true;
4930 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:444931
[email protected]fb661802013-03-25 01:59:324932 // Sanity check the scenario we just created.
4933 ASSERT_EQ(1u, render_surface_layer_list.size());
4934 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234935 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]aedf4e52013-01-09 23:24:444936
[email protected]fb661802013-03-25 01:59:324937 // Hit testing for a point outside the layer should return a null pointer.
4938 gfx::Point test_point(69, 69);
4939 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4940 test_point, render_surface_layer_list);
4941 EXPECT_FALSE(result_layer);
[email protected]aedf4e52013-01-09 23:24:444942
[email protected]fb661802013-03-25 01:59:324943 test_point = gfx::Point(91, 91);
4944 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4945 test_point, render_surface_layer_list);
4946 EXPECT_FALSE(result_layer);
4947
4948 // Hit testing for a point inside should return the child layer.
4949 test_point = gfx::Point(71, 71);
4950 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4951 test_point, render_surface_layer_list);
4952 ASSERT_TRUE(result_layer);
4953 EXPECT_EQ(456, result_layer->id());
4954
4955 test_point = gfx::Point(89, 89);
4956 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4957 test_point, render_surface_layer_list);
4958 ASSERT_TRUE(result_layer);
4959 EXPECT_EQ(456, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:444960}
4961
[email protected]989386c2013-07-18 21:37:234962TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayers) {
[email protected]fb661802013-03-25 01:59:324963 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454964 TestSharedBitmapManager shared_bitmap_manager;
4965 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324966 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:144967
[email protected]fb661802013-03-25 01:59:324968 gfx::Transform identity_matrix;
4969 gfx::PointF anchor;
4970 gfx::PointF position;
4971 gfx::Size bounds(100, 100);
4972 SetLayerPropertiesForTesting(root.get(),
4973 identity_matrix,
[email protected]fb661802013-03-25 01:59:324974 anchor,
4975 position,
4976 bounds,
[email protected]56fffdd2014-02-11 19:50:574977 true,
[email protected]fb661802013-03-25 01:59:324978 false);
4979 root->SetDrawsContent(true);
4980 {
4981 // child 1 and child2 are initialized to overlap between x=50 and x=60.
4982 // grand_child is set to overlap both child1 and child2 between y=50 and
4983 // y=60. The expected stacking order is: (front) child2, (second)
4984 // grand_child, (third) child1, and (back) the root layer behind all other
4985 // layers.
[email protected]ecc12622012-10-30 20:45:424986
[email protected]fb661802013-03-25 01:59:324987 scoped_ptr<LayerImpl> child1 =
4988 LayerImpl::Create(host_impl.active_tree(), 2);
4989 scoped_ptr<LayerImpl> child2 =
4990 LayerImpl::Create(host_impl.active_tree(), 3);
4991 scoped_ptr<LayerImpl> grand_child1 =
4992 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:144993
[email protected]fb661802013-03-25 01:59:324994 position = gfx::PointF(10.f, 10.f);
4995 bounds = gfx::Size(50, 50);
4996 SetLayerPropertiesForTesting(child1.get(),
4997 identity_matrix,
[email protected]fb661802013-03-25 01:59:324998 anchor,
4999 position,
5000 bounds,
[email protected]56fffdd2014-02-11 19:50:575001 true,
[email protected]fb661802013-03-25 01:59:325002 false);
5003 child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145004
[email protected]fb661802013-03-25 01:59:325005 position = gfx::PointF(50.f, 10.f);
5006 bounds = gfx::Size(50, 50);
5007 SetLayerPropertiesForTesting(child2.get(),
5008 identity_matrix,
[email protected]fb661802013-03-25 01:59:325009 anchor,
5010 position,
5011 bounds,
[email protected]56fffdd2014-02-11 19:50:575012 true,
[email protected]fb661802013-03-25 01:59:325013 false);
5014 child2->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145015
[email protected]fb661802013-03-25 01:59:325016 // Remember that grand_child is positioned with respect to its parent (i.e.
5017 // child1). In screen space, the intended position is (10, 50), with size
5018 // 100 x 50.
5019 position = gfx::PointF(0.f, 40.f);
5020 bounds = gfx::Size(100, 50);
5021 SetLayerPropertiesForTesting(grand_child1.get(),
5022 identity_matrix,
[email protected]fb661802013-03-25 01:59:325023 anchor,
5024 position,
5025 bounds,
[email protected]56fffdd2014-02-11 19:50:575026 true,
[email protected]fb661802013-03-25 01:59:325027 false);
5028 grand_child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145029
[email protected]fb661802013-03-25 01:59:325030 child1->AddChild(grand_child1.Pass());
5031 root->AddChild(child1.Pass());
5032 root->AddChild(child2.Pass());
5033 }
[email protected]94f206c12012-08-25 00:09:145034
[email protected]fb661802013-03-25 01:59:325035 LayerImpl* child1 = root->children()[0];
5036 LayerImpl* child2 = root->children()[1];
5037 LayerImpl* grand_child1 = child1->children()[0];
5038
[email protected]50761e92013-03-29 20:51:285039 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535040 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5041 root.get(), root->bounds(), &render_surface_layer_list);
5042 inputs.can_adjust_raster_scales = true;
5043 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325044
5045 // Sanity check the scenario we just created.
5046 ASSERT_TRUE(child1);
5047 ASSERT_TRUE(child2);
5048 ASSERT_TRUE(grand_child1);
5049 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:235050
5051 RenderSurfaceImpl* root_render_surface = root->render_surface();
5052 ASSERT_EQ(4u, root_render_surface->layer_list().size());
5053 ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer
5054 ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1
5055 ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1
5056 ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2
[email protected]fb661802013-03-25 01:59:325057
5058 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5059 // the root layer.
5060 gfx::Point test_point = gfx::Point(1, 1);
5061 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5062 test_point, render_surface_layer_list);
5063 ASSERT_TRUE(result_layer);
5064 EXPECT_EQ(1, result_layer->id());
5065
5066 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5067 // on top.
5068 test_point = gfx::Point(15, 15);
5069 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5070 test_point, render_surface_layer_list);
5071 ASSERT_TRUE(result_layer);
5072 EXPECT_EQ(2, result_layer->id());
5073
5074 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5075 test_point = gfx::Point(51, 20);
5076 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5077 test_point, render_surface_layer_list);
5078 ASSERT_TRUE(result_layer);
5079 EXPECT_EQ(3, result_layer->id());
5080
5081 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5082 // top.
5083 test_point = gfx::Point(80, 51);
5084 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5085 test_point, render_surface_layer_list);
5086 ASSERT_TRUE(result_layer);
5087 EXPECT_EQ(3, result_layer->id());
5088
5089 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5090 // of all other layers.
5091 test_point = gfx::Point(51, 51);
5092 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5093 test_point, render_surface_layer_list);
5094 ASSERT_TRUE(result_layer);
5095 EXPECT_EQ(3, result_layer->id());
5096
5097 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5098 // be on top.
5099 test_point = gfx::Point(20, 51);
5100 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5101 test_point, render_surface_layer_list);
5102 ASSERT_TRUE(result_layer);
5103 EXPECT_EQ(4, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145104}
5105
[email protected]989386c2013-07-18 21:37:235106TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) {
[email protected]fb661802013-03-25 01:59:325107 //
5108 // The geometry is set up similarly to the previous case, but
5109 // all layers are forced to be render surfaces now.
5110 //
5111 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455112 TestSharedBitmapManager shared_bitmap_manager;
5113 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325114 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145115
[email protected]fb661802013-03-25 01:59:325116 gfx::Transform identity_matrix;
5117 gfx::PointF anchor;
5118 gfx::PointF position;
5119 gfx::Size bounds(100, 100);
5120 SetLayerPropertiesForTesting(root.get(),
5121 identity_matrix,
[email protected]fb661802013-03-25 01:59:325122 anchor,
5123 position,
5124 bounds,
[email protected]56fffdd2014-02-11 19:50:575125 true,
[email protected]fb661802013-03-25 01:59:325126 false);
5127 root->SetDrawsContent(true);
5128 {
5129 // child 1 and child2 are initialized to overlap between x=50 and x=60.
5130 // grand_child is set to overlap both child1 and child2 between y=50 and
5131 // y=60. The expected stacking order is: (front) child2, (second)
5132 // grand_child, (third) child1, and (back) the root layer behind all other
5133 // layers.
[email protected]94f206c12012-08-25 00:09:145134
[email protected]fb661802013-03-25 01:59:325135 scoped_ptr<LayerImpl> child1 =
5136 LayerImpl::Create(host_impl.active_tree(), 2);
5137 scoped_ptr<LayerImpl> child2 =
5138 LayerImpl::Create(host_impl.active_tree(), 3);
5139 scoped_ptr<LayerImpl> grand_child1 =
5140 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:145141
[email protected]fb661802013-03-25 01:59:325142 position = gfx::PointF(10.f, 10.f);
5143 bounds = gfx::Size(50, 50);
5144 SetLayerPropertiesForTesting(child1.get(),
5145 identity_matrix,
[email protected]fb661802013-03-25 01:59:325146 anchor,
5147 position,
5148 bounds,
[email protected]56fffdd2014-02-11 19:50:575149 true,
[email protected]fb661802013-03-25 01:59:325150 false);
5151 child1->SetDrawsContent(true);
5152 child1->SetForceRenderSurface(true);
[email protected]ecc12622012-10-30 20:45:425153
[email protected]fb661802013-03-25 01:59:325154 position = gfx::PointF(50.f, 10.f);
5155 bounds = gfx::Size(50, 50);
5156 SetLayerPropertiesForTesting(child2.get(),
5157 identity_matrix,
[email protected]fb661802013-03-25 01:59:325158 anchor,
5159 position,
5160 bounds,
[email protected]56fffdd2014-02-11 19:50:575161 true,
[email protected]fb661802013-03-25 01:59:325162 false);
5163 child2->SetDrawsContent(true);
[email protected]7aba6662013-03-12 10:17:345164 child2->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015165
[email protected]fb661802013-03-25 01:59:325166 // Remember that grand_child is positioned with respect to its parent (i.e.
5167 // child1). In screen space, the intended position is (10, 50), with size
5168 // 100 x 50.
5169 position = gfx::PointF(0.f, 40.f);
5170 bounds = gfx::Size(100, 50);
5171 SetLayerPropertiesForTesting(grand_child1.get(),
5172 identity_matrix,
[email protected]fb661802013-03-25 01:59:325173 anchor,
5174 position,
5175 bounds,
[email protected]56fffdd2014-02-11 19:50:575176 true,
[email protected]fb661802013-03-25 01:59:325177 false);
5178 grand_child1->SetDrawsContent(true);
5179 grand_child1->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015180
[email protected]fb661802013-03-25 01:59:325181 child1->AddChild(grand_child1.Pass());
5182 root->AddChild(child1.Pass());
5183 root->AddChild(child2.Pass());
5184 }
[email protected]dc462d782012-11-21 21:43:015185
[email protected]fb661802013-03-25 01:59:325186 LayerImpl* child1 = root->children()[0];
5187 LayerImpl* child2 = root->children()[1];
5188 LayerImpl* grand_child1 = child1->children()[0];
[email protected]dc462d782012-11-21 21:43:015189
[email protected]50761e92013-03-29 20:51:285190 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535191 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5192 root.get(), root->bounds(), &render_surface_layer_list);
5193 inputs.can_adjust_raster_scales = true;
5194 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]dc462d782012-11-21 21:43:015195
[email protected]fb661802013-03-25 01:59:325196 // Sanity check the scenario we just created.
5197 ASSERT_TRUE(child1);
5198 ASSERT_TRUE(child2);
5199 ASSERT_TRUE(grand_child1);
5200 ASSERT_TRUE(child1->render_surface());
5201 ASSERT_TRUE(child2->render_surface());
5202 ASSERT_TRUE(grand_child1->render_surface());
5203 ASSERT_EQ(4u, render_surface_layer_list.size());
5204 // The root surface has the root layer, and child1's and child2's render
5205 // surfaces.
5206 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
5207 // The child1 surface has the child1 layer and grand_child1's render surface.
5208 ASSERT_EQ(2u, child1->render_surface()->layer_list().size());
5209 ASSERT_EQ(1u, child2->render_surface()->layer_list().size());
5210 ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235211 ASSERT_EQ(1, render_surface_layer_list.at(0)->id()); // root layer
[email protected]fb661802013-03-25 01:59:325212 ASSERT_EQ(2, render_surface_layer_list[1]->id()); // child1
[email protected]989386c2013-07-18 21:37:235213 ASSERT_EQ(4, render_surface_layer_list.at(2)->id()); // grand_child1
[email protected]fb661802013-03-25 01:59:325214 ASSERT_EQ(3, render_surface_layer_list[3]->id()); // child2
[email protected]dc462d782012-11-21 21:43:015215
[email protected]fb661802013-03-25 01:59:325216 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5217 // the root layer.
5218 gfx::Point test_point = gfx::Point(1, 1);
5219 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5220 test_point, render_surface_layer_list);
5221 ASSERT_TRUE(result_layer);
5222 EXPECT_EQ(1, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015223
[email protected]fb661802013-03-25 01:59:325224 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5225 // on top.
5226 test_point = gfx::Point(15, 15);
5227 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5228 test_point, render_surface_layer_list);
5229 ASSERT_TRUE(result_layer);
5230 EXPECT_EQ(2, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015231
[email protected]fb661802013-03-25 01:59:325232 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5233 test_point = gfx::Point(51, 20);
5234 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5235 test_point, render_surface_layer_list);
5236 ASSERT_TRUE(result_layer);
5237 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015238
[email protected]fb661802013-03-25 01:59:325239 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5240 // top.
5241 test_point = gfx::Point(80, 51);
5242 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5243 test_point, render_surface_layer_list);
5244 ASSERT_TRUE(result_layer);
5245 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015246
[email protected]fb661802013-03-25 01:59:325247 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5248 // of all other layers.
5249 test_point = gfx::Point(51, 51);
5250 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5251 test_point, render_surface_layer_list);
5252 ASSERT_TRUE(result_layer);
5253 EXPECT_EQ(3, result_layer->id());
5254
5255 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5256 // be on top.
5257 test_point = gfx::Point(20, 51);
5258 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5259 test_point, render_surface_layer_list);
5260 ASSERT_TRUE(result_layer);
5261 EXPECT_EQ(4, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015262}
5263
[email protected]afc4f262013-10-05 01:14:105264TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayers) {
5265 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455266 TestSharedBitmapManager shared_bitmap_manager;
5267 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]afc4f262013-10-05 01:14:105268
5269 // Layer 1 - root
5270 scoped_ptr<LayerImpl> root =
5271 LayerImpl::Create(host_impl.active_tree(), 1);
5272 gfx::Transform identity_matrix;
5273 gfx::PointF anchor;
5274 gfx::PointF position;
5275 gfx::Size bounds(100, 100);
5276 SetLayerPropertiesForTesting(root.get(),
5277 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105278 anchor,
5279 position,
5280 bounds,
[email protected]56fffdd2014-02-11 19:50:575281 true,
[email protected]afc4f262013-10-05 01:14:105282 false);
5283 root->SetDrawsContent(true);
5284
5285 {
5286 // Layer 2 - empty: drawsContent=false
5287 gfx::PointF position(10.f, 10.f);
5288 gfx::Size bounds(30, 30);
5289 scoped_ptr<LayerImpl> empty_layer =
5290 LayerImpl::Create(host_impl.active_tree(), 2);
5291 SetLayerPropertiesForTesting(empty_layer.get(),
5292 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105293 anchor,
5294 position,
5295 bounds,
[email protected]56fffdd2014-02-11 19:50:575296 true,
[email protected]afc4f262013-10-05 01:14:105297 false);
5298
5299 empty_layer->SetDrawsContent(false);
5300 root->AddChild(empty_layer.Pass());
5301 }
5302
5303 {
5304 // Layer 3 - empty, but has touch handler
5305 gfx::PointF position(10.f, 60.f);
5306 gfx::Size bounds(30, 30);
5307 scoped_ptr<LayerImpl> test_layer =
5308 LayerImpl::Create(host_impl.active_tree(), 3);
5309 SetLayerPropertiesForTesting(test_layer.get(),
5310 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105311 anchor,
5312 position,
5313 bounds,
[email protected]56fffdd2014-02-11 19:50:575314 true,
[email protected]afc4f262013-10-05 01:14:105315 false);
5316
5317 test_layer->SetDrawsContent(false);
5318 Region touch_handler_region(gfx::Rect(10, 10, 10, 10));
5319 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5320 root->AddChild(test_layer.Pass());
5321 }
5322
5323 {
5324 // Layer 4 - empty, but has mousewheel handler
5325 gfx::PointF position(60.f, 60.f);
5326 gfx::Size bounds(30, 30);
5327 scoped_ptr<LayerImpl> test_layer =
5328 LayerImpl::Create(host_impl.active_tree(), 4);
5329 SetLayerPropertiesForTesting(test_layer.get(),
5330 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105331 anchor,
5332 position,
5333 bounds,
[email protected]56fffdd2014-02-11 19:50:575334 true,
[email protected]afc4f262013-10-05 01:14:105335 false);
5336
5337 test_layer->SetDrawsContent(false);
5338 test_layer->SetHaveWheelEventHandlers(true);
5339 root->AddChild(test_layer.Pass());
5340 }
5341
5342 LayerImplList render_surface_layer_list;
5343 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5344 root.get(), root->bounds(), &render_surface_layer_list);
5345 inputs.can_adjust_raster_scales = true;
5346 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5347
5348 // Verify that the root layer and empty layers with touch/wheel handlers
5349 // (but not the empty layer without a touch handler) are in the RSSL.
5350 ASSERT_EQ(1u, render_surface_layer_list.size());
5351 EXPECT_EQ(1, render_surface_layer_list[0]->id());
[email protected]22538a2d2013-11-12 11:24:455352 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
[email protected]afc4f262013-10-05 01:14:105353 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]22538a2d2013-11-12 11:24:455354 EXPECT_EQ(3, root->render_surface()->layer_list().at(1)->id());
5355 EXPECT_EQ(4, root->render_surface()->layer_list().at(2)->id());
[email protected]afc4f262013-10-05 01:14:105356
5357 // Hit testing for a point inside the empty no-handlers layer should return
5358 // the root layer.
5359 gfx::Point test_point = gfx::Point(15, 15);
5360 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5361 test_point, render_surface_layer_list);
5362 ASSERT_TRUE(result_layer);
[email protected]22538a2d2013-11-12 11:24:455363 EXPECT_EQ(1, result_layer->id());
[email protected]afc4f262013-10-05 01:14:105364
5365 // Hit testing for a point inside the touch handler layer should return it.
5366 test_point = gfx::Point(15, 75);
5367 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5368 test_point, render_surface_layer_list);
5369 ASSERT_TRUE(result_layer);
5370 EXPECT_EQ(3, result_layer->id());
5371
5372 // Hit testing for a point inside the mousewheel layer should return it.
5373 test_point = gfx::Point(75, 75);
5374 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5375 test_point, render_surface_layer_list);
5376 ASSERT_TRUE(result_layer);
5377 EXPECT_EQ(4, result_layer->id());
5378}
5379
[email protected]989386c2013-07-18 21:37:235380TEST_F(LayerTreeHostCommonTest,
5381 HitCheckingTouchHandlerRegionsForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:325382 // Hit checking on an empty render_surface_layer_list should return a null
5383 // pointer.
[email protected]50761e92013-03-29 20:51:285384 LayerImplList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145385
[email protected]fb661802013-03-25 01:59:325386 gfx::Point test_point(0, 0);
5387 LayerImpl* result_layer =
5388 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5389 test_point, render_surface_layer_list);
5390 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145391
[email protected]fb661802013-03-25 01:59:325392 test_point = gfx::Point(10, 20);
5393 result_layer =
5394 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5395 test_point, render_surface_layer_list);
5396 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145397}
5398
[email protected]989386c2013-07-18 21:37:235399TEST_F(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:325400 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455401 TestSharedBitmapManager shared_bitmap_manager;
5402 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325403 scoped_ptr<LayerImpl> root =
5404 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145405
[email protected]fb661802013-03-25 01:59:325406 gfx::Transform identity_matrix;
5407 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5408 gfx::PointF anchor;
5409 gfx::PointF position;
5410 gfx::Size bounds(100, 100);
5411 SetLayerPropertiesForTesting(root.get(),
5412 identity_matrix,
[email protected]fb661802013-03-25 01:59:325413 anchor,
5414 position,
5415 bounds,
[email protected]56fffdd2014-02-11 19:50:575416 true,
[email protected]fb661802013-03-25 01:59:325417 false);
5418 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145419
[email protected]50761e92013-03-29 20:51:285420 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535421 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5422 root.get(), root->bounds(), &render_surface_layer_list);
5423 inputs.can_adjust_raster_scales = true;
5424 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145425
[email protected]fb661802013-03-25 01:59:325426 // Sanity check the scenario we just created.
5427 ASSERT_EQ(1u, render_surface_layer_list.size());
5428 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145429
[email protected]fb661802013-03-25 01:59:325430 // Hit checking for any point should return a null pointer for a layer without
5431 // any touch event handler regions.
5432 gfx::Point test_point(11, 11);
5433 LayerImpl* result_layer =
5434 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5435 test_point, render_surface_layer_list);
5436 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145437
[email protected]fb661802013-03-25 01:59:325438 root->SetTouchEventHandlerRegion(touch_handler_region);
5439 // Hit checking for a point outside the layer should return a null pointer.
5440 test_point = gfx::Point(101, 101);
5441 result_layer =
5442 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5443 test_point, render_surface_layer_list);
5444 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145445
[email protected]fb661802013-03-25 01:59:325446 test_point = gfx::Point(-1, -1);
5447 result_layer =
5448 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5449 test_point, render_surface_layer_list);
5450 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145451
[email protected]fb661802013-03-25 01:59:325452 // Hit checking for a point inside the layer, but outside the touch handler
5453 // region should return a null pointer.
5454 test_point = gfx::Point(1, 1);
5455 result_layer =
5456 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5457 test_point, render_surface_layer_list);
5458 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145459
[email protected]fb661802013-03-25 01:59:325460 test_point = gfx::Point(99, 99);
5461 result_layer =
5462 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5463 test_point, render_surface_layer_list);
5464 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145465
[email protected]fb661802013-03-25 01:59:325466 // Hit checking for a point inside the touch event handler region should
5467 // return the root layer.
5468 test_point = gfx::Point(11, 11);
5469 result_layer =
5470 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5471 test_point, render_surface_layer_list);
5472 ASSERT_TRUE(result_layer);
5473 EXPECT_EQ(12345, result_layer->id());
5474
5475 test_point = gfx::Point(59, 59);
5476 result_layer =
5477 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5478 test_point, render_surface_layer_list);
5479 ASSERT_TRUE(result_layer);
5480 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145481}
5482
[email protected]989386c2013-07-18 21:37:235483TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325484 HitCheckingTouchHandlerRegionsForUninvertibleTransform) {
5485 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455486 TestSharedBitmapManager shared_bitmap_manager;
5487 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325488 scoped_ptr<LayerImpl> root =
5489 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145490
[email protected]fb661802013-03-25 01:59:325491 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:265492 uninvertible_transform.matrix().set(0, 0, 0.0);
5493 uninvertible_transform.matrix().set(1, 1, 0.0);
5494 uninvertible_transform.matrix().set(2, 2, 0.0);
5495 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:325496 ASSERT_FALSE(uninvertible_transform.IsInvertible());
[email protected]94f206c12012-08-25 00:09:145497
[email protected]fb661802013-03-25 01:59:325498 gfx::Transform identity_matrix;
5499 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5500 gfx::PointF anchor;
5501 gfx::PointF position;
5502 gfx::Size bounds(100, 100);
5503 SetLayerPropertiesForTesting(root.get(),
5504 uninvertible_transform,
[email protected]fb661802013-03-25 01:59:325505 anchor,
5506 position,
5507 bounds,
[email protected]56fffdd2014-02-11 19:50:575508 true,
[email protected]fb661802013-03-25 01:59:325509 false);
5510 root->SetDrawsContent(true);
5511 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145512
[email protected]50761e92013-03-29 20:51:285513 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535514 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5515 root.get(), root->bounds(), &render_surface_layer_list);
5516 inputs.can_adjust_raster_scales = true;
5517 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145518
[email protected]fb661802013-03-25 01:59:325519 // Sanity check the scenario we just created.
5520 ASSERT_EQ(1u, render_surface_layer_list.size());
5521 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5522 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
[email protected]de4afb5e2012-12-20 00:11:345523
[email protected]fb661802013-03-25 01:59:325524 // Hit checking any point should not hit the touch handler region on the
5525 // layer. If the invertible matrix is accidentally ignored and treated like an
5526 // identity, then the hit testing will incorrectly hit the layer when it
5527 // shouldn't.
5528 gfx::Point test_point(1, 1);
5529 LayerImpl* result_layer =
5530 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5531 test_point, render_surface_layer_list);
5532 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345533
[email protected]fb661802013-03-25 01:59:325534 test_point = gfx::Point(10, 10);
5535 result_layer =
5536 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5537 test_point, render_surface_layer_list);
5538 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345539
[email protected]fb661802013-03-25 01:59:325540 test_point = gfx::Point(10, 30);
5541 result_layer =
5542 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5543 test_point, render_surface_layer_list);
5544 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345545
[email protected]fb661802013-03-25 01:59:325546 test_point = gfx::Point(50, 50);
5547 result_layer =
5548 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5549 test_point, render_surface_layer_list);
5550 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145551
[email protected]fb661802013-03-25 01:59:325552 test_point = gfx::Point(67, 48);
5553 result_layer =
5554 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5555 test_point, render_surface_layer_list);
5556 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145557
[email protected]fb661802013-03-25 01:59:325558 test_point = gfx::Point(99, 99);
5559 result_layer =
5560 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5561 test_point, render_surface_layer_list);
5562 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145563
[email protected]fb661802013-03-25 01:59:325564 test_point = gfx::Point(-1, -1);
5565 result_layer =
5566 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5567 test_point, render_surface_layer_list);
5568 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145569}
5570
[email protected]989386c2013-07-18 21:37:235571TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325572 HitCheckingTouchHandlerRegionsForSinglePositionedLayer) {
5573 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455574 TestSharedBitmapManager shared_bitmap_manager;
5575 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325576 scoped_ptr<LayerImpl> root =
5577 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145578
[email protected]fb661802013-03-25 01:59:325579 gfx::Transform identity_matrix;
5580 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5581 gfx::PointF anchor;
5582 // this layer is positioned, and hit testing should correctly know where the
5583 // layer is located.
5584 gfx::PointF position(50.f, 50.f);
5585 gfx::Size bounds(100, 100);
5586 SetLayerPropertiesForTesting(root.get(),
5587 identity_matrix,
[email protected]fb661802013-03-25 01:59:325588 anchor,
5589 position,
5590 bounds,
[email protected]56fffdd2014-02-11 19:50:575591 true,
[email protected]fb661802013-03-25 01:59:325592 false);
5593 root->SetDrawsContent(true);
5594 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145595
[email protected]50761e92013-03-29 20:51:285596 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535597 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5598 root.get(), root->bounds(), &render_surface_layer_list);
5599 inputs.can_adjust_raster_scales = true;
5600 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145601
[email protected]fb661802013-03-25 01:59:325602 // Sanity check the scenario we just created.
5603 ASSERT_EQ(1u, render_surface_layer_list.size());
5604 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145605
[email protected]fb661802013-03-25 01:59:325606 // Hit checking for a point outside the layer should return a null pointer.
5607 gfx::Point test_point(49, 49);
5608 LayerImpl* result_layer =
5609 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5610 test_point, render_surface_layer_list);
5611 EXPECT_FALSE(result_layer);
5612
5613 // Even though the layer has a touch handler region containing (101, 101), it
5614 // should not be visible there since the root render surface would clamp it.
5615 test_point = gfx::Point(101, 101);
5616 result_layer =
5617 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5618 test_point, render_surface_layer_list);
5619 EXPECT_FALSE(result_layer);
5620
5621 // Hit checking for a point inside the layer, but outside the touch handler
5622 // region should return a null pointer.
5623 test_point = gfx::Point(51, 51);
5624 result_layer =
5625 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5626 test_point, render_surface_layer_list);
5627 EXPECT_FALSE(result_layer);
5628
5629 // Hit checking for a point inside the touch event handler region should
5630 // return the root layer.
5631 test_point = gfx::Point(61, 61);
5632 result_layer =
5633 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5634 test_point, render_surface_layer_list);
5635 ASSERT_TRUE(result_layer);
5636 EXPECT_EQ(12345, result_layer->id());
5637
5638 test_point = gfx::Point(99, 99);
5639 result_layer =
5640 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5641 test_point, render_surface_layer_list);
5642 ASSERT_TRUE(result_layer);
5643 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145644}
5645
[email protected]989386c2013-07-18 21:37:235646TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325647 HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) {
5648 // A layer's visible content rect is actually in the layer's content space.
5649 // The screen space transform converts from the layer's origin space to screen
5650 // space. This test makes sure that hit testing works correctly accounts for
5651 // the contents scale. A contents scale that is not 1 effectively forces a
5652 // non-identity transform between layer's content space and layer's origin
5653 // space. The hit testing code must take this into account.
5654 //
5655 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
5656 // contents scale is ignored, then hit checking will mis-interpret the visible
5657 // content rect as being larger than the actual bounds of the layer.
5658 //
5659 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455660 TestSharedBitmapManager shared_bitmap_manager;
5661 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325662 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145663
[email protected]fb661802013-03-25 01:59:325664 gfx::Transform identity_matrix;
5665 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145666
[email protected]fb661802013-03-25 01:59:325667 SetLayerPropertiesForTesting(root.get(),
5668 identity_matrix,
[email protected]fb661802013-03-25 01:59:325669 anchor,
5670 gfx::PointF(),
5671 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575672 true,
[email protected]fb661802013-03-25 01:59:325673 false);
5674 {
5675 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5676 gfx::PointF position(25.f, 25.f);
5677 gfx::Size bounds(50, 50);
5678 scoped_ptr<LayerImpl> test_layer =
5679 LayerImpl::Create(host_impl.active_tree(), 12345);
5680 SetLayerPropertiesForTesting(test_layer.get(),
5681 identity_matrix,
[email protected]fb661802013-03-25 01:59:325682 anchor,
5683 position,
5684 bounds,
[email protected]56fffdd2014-02-11 19:50:575685 true,
[email protected]fb661802013-03-25 01:59:325686 false);
[email protected]94f206c12012-08-25 00:09:145687
[email protected]fb661802013-03-25 01:59:325688 // override content bounds and contents scale
5689 test_layer->SetContentBounds(gfx::Size(100, 100));
5690 test_layer->SetContentsScale(2, 2);
[email protected]94f206c12012-08-25 00:09:145691
[email protected]fb661802013-03-25 01:59:325692 test_layer->SetDrawsContent(true);
5693 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5694 root->AddChild(test_layer.Pass());
5695 }
5696
[email protected]50761e92013-03-29 20:51:285697 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535698 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5699 root.get(), root->bounds(), &render_surface_layer_list);
5700 inputs.can_adjust_raster_scales = true;
5701 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325702
5703 // Sanity check the scenario we just created.
5704 // The visible content rect for test_layer is actually 100x100, even though
5705 // its layout size is 50x50, positioned at 25x25.
5706 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:055707 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect());
[email protected]fb661802013-03-25 01:59:325708 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455709 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:325710
5711 // Hit checking for a point outside the layer should return a null pointer
5712 // (the root layer does not draw content, so it will not be tested either).
5713 gfx::Point test_point(76, 76);
5714 LayerImpl* result_layer =
5715 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5716 test_point, render_surface_layer_list);
5717 EXPECT_FALSE(result_layer);
5718
5719 // Hit checking for a point inside the layer, but outside the touch handler
5720 // region should return a null pointer.
5721 test_point = gfx::Point(26, 26);
5722 result_layer =
5723 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5724 test_point, render_surface_layer_list);
5725 EXPECT_FALSE(result_layer);
5726
5727 test_point = gfx::Point(34, 34);
5728 result_layer =
5729 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5730 test_point, render_surface_layer_list);
5731 EXPECT_FALSE(result_layer);
5732
5733 test_point = gfx::Point(65, 65);
5734 result_layer =
5735 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5736 test_point, render_surface_layer_list);
5737 EXPECT_FALSE(result_layer);
5738
5739 test_point = gfx::Point(74, 74);
5740 result_layer =
5741 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5742 test_point, render_surface_layer_list);
5743 EXPECT_FALSE(result_layer);
5744
5745 // Hit checking for a point inside the touch event handler region should
5746 // return the root layer.
5747 test_point = gfx::Point(35, 35);
5748 result_layer =
5749 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5750 test_point, render_surface_layer_list);
5751 ASSERT_TRUE(result_layer);
5752 EXPECT_EQ(12345, result_layer->id());
5753
5754 test_point = gfx::Point(64, 64);
5755 result_layer =
5756 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5757 test_point, render_surface_layer_list);
5758 ASSERT_TRUE(result_layer);
5759 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145760}
5761
[email protected]989386c2013-07-18 21:37:235762TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325763 HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) {
5764 // The layer's device_scale_factor and page_scale_factor should scale the
5765 // content rect and we should be able to hit the touch handler region by
5766 // scaling the points accordingly.
5767 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455768 TestSharedBitmapManager shared_bitmap_manager;
5769 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325770 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145771
[email protected]fb661802013-03-25 01:59:325772 gfx::Transform identity_matrix;
5773 gfx::PointF anchor;
5774 // Set the bounds of the root layer big enough to fit the child when scaled.
5775 SetLayerPropertiesForTesting(root.get(),
5776 identity_matrix,
[email protected]fb661802013-03-25 01:59:325777 anchor,
5778 gfx::PointF(),
5779 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575780 true,
[email protected]fb661802013-03-25 01:59:325781 false);
5782 {
5783 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5784 gfx::PointF position(25.f, 25.f);
5785 gfx::Size bounds(50, 50);
5786 scoped_ptr<LayerImpl> test_layer =
5787 LayerImpl::Create(host_impl.active_tree(), 12345);
5788 SetLayerPropertiesForTesting(test_layer.get(),
5789 identity_matrix,
[email protected]fb661802013-03-25 01:59:325790 anchor,
5791 position,
5792 bounds,
[email protected]56fffdd2014-02-11 19:50:575793 true,
[email protected]fb661802013-03-25 01:59:325794 false);
[email protected]94f206c12012-08-25 00:09:145795
[email protected]fb661802013-03-25 01:59:325796 test_layer->SetDrawsContent(true);
5797 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5798 root->AddChild(test_layer.Pass());
5799 }
[email protected]94f206c12012-08-25 00:09:145800
[email protected]50761e92013-03-29 20:51:285801 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:325802 float device_scale_factor = 3.f;
5803 float page_scale_factor = 5.f;
[email protected]fb661802013-03-25 01:59:325804 gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize(
5805 gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor));
[email protected]7aad55f2013-07-26 11:25:535806
5807 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5808 root.get(), scaled_bounds_for_root, &render_surface_layer_list);
5809 inputs.device_scale_factor = device_scale_factor;
5810 inputs.page_scale_factor = page_scale_factor;
5811 inputs.page_scale_application_layer = root.get();
5812 inputs.can_adjust_raster_scales = true;
5813 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145814
[email protected]fb661802013-03-25 01:59:325815 // Sanity check the scenario we just created.
5816 // The visible content rect for test_layer is actually 100x100, even though
5817 // its layout size is 50x50, positioned at 25x25.
5818 LayerImpl* test_layer = root->children()[0];
5819 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455820 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145821
[email protected]fb661802013-03-25 01:59:325822 // Check whether the child layer fits into the root after scaled.
5823 EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()),
5824 test_layer->visible_content_rect());
5825
5826 // Hit checking for a point outside the layer should return a null pointer
5827 // (the root layer does not draw content, so it will not be tested either).
5828 gfx::PointF test_point(76.f, 76.f);
5829 test_point =
5830 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5831 LayerImpl* result_layer =
5832 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5833 test_point, render_surface_layer_list);
5834 EXPECT_FALSE(result_layer);
5835
5836 // Hit checking for a point inside the layer, but outside the touch handler
5837 // region should return a null pointer.
5838 test_point = gfx::Point(26, 26);
5839 test_point =
5840 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5841 result_layer =
5842 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5843 test_point, render_surface_layer_list);
5844 EXPECT_FALSE(result_layer);
5845
5846 test_point = gfx::Point(34, 34);
5847 test_point =
5848 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5849 result_layer =
5850 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5851 test_point, render_surface_layer_list);
5852 EXPECT_FALSE(result_layer);
5853
5854 test_point = gfx::Point(65, 65);
5855 test_point =
5856 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5857 result_layer =
5858 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5859 test_point, render_surface_layer_list);
5860 EXPECT_FALSE(result_layer);
5861
5862 test_point = gfx::Point(74, 74);
5863 test_point =
5864 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5865 result_layer =
5866 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5867 test_point, render_surface_layer_list);
5868 EXPECT_FALSE(result_layer);
5869
5870 // Hit checking for a point inside the touch event handler region should
5871 // return the root layer.
5872 test_point = gfx::Point(35, 35);
5873 test_point =
5874 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5875 result_layer =
5876 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5877 test_point, render_surface_layer_list);
5878 ASSERT_TRUE(result_layer);
5879 EXPECT_EQ(12345, result_layer->id());
5880
5881 test_point = gfx::Point(64, 64);
5882 test_point =
5883 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5884 result_layer =
5885 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5886 test_point, render_surface_layer_list);
5887 ASSERT_TRUE(result_layer);
5888 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145889}
5890
[email protected]989386c2013-07-18 21:37:235891TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325892 HitCheckingTouchHandlerRegionsForSimpleClippedLayer) {
5893 // Test that hit-checking will only work for the visible portion of a layer,
5894 // and not the entire layer bounds. Here we just test the simple axis-aligned
5895 // case.
5896 gfx::Transform identity_matrix;
5897 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145898
[email protected]fb661802013-03-25 01:59:325899 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455900 TestSharedBitmapManager shared_bitmap_manager;
5901 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325902 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5903 SetLayerPropertiesForTesting(root.get(),
5904 identity_matrix,
[email protected]fb661802013-03-25 01:59:325905 anchor,
5906 gfx::PointF(),
5907 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575908 true,
[email protected]fb661802013-03-25 01:59:325909 false);
5910 {
5911 scoped_ptr<LayerImpl> clipping_layer =
5912 LayerImpl::Create(host_impl.active_tree(), 123);
5913 // this layer is positioned, and hit testing should correctly know where the
5914 // layer is located.
5915 gfx::PointF position(25.f, 25.f);
5916 gfx::Size bounds(50, 50);
5917 SetLayerPropertiesForTesting(clipping_layer.get(),
5918 identity_matrix,
[email protected]fb661802013-03-25 01:59:325919 anchor,
5920 position,
5921 bounds,
[email protected]56fffdd2014-02-11 19:50:575922 true,
[email protected]fb661802013-03-25 01:59:325923 false);
5924 clipping_layer->SetMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:145925
[email protected]fb661802013-03-25 01:59:325926 scoped_ptr<LayerImpl> child =
5927 LayerImpl::Create(host_impl.active_tree(), 456);
5928 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5929 position = gfx::PointF(-50.f, -50.f);
5930 bounds = gfx::Size(300, 300);
5931 SetLayerPropertiesForTesting(child.get(),
5932 identity_matrix,
[email protected]fb661802013-03-25 01:59:325933 anchor,
5934 position,
5935 bounds,
[email protected]56fffdd2014-02-11 19:50:575936 true,
[email protected]fb661802013-03-25 01:59:325937 false);
5938 child->SetDrawsContent(true);
5939 child->SetTouchEventHandlerRegion(touch_handler_region);
5940 clipping_layer->AddChild(child.Pass());
5941 root->AddChild(clipping_layer.Pass());
5942 }
[email protected]94f206c12012-08-25 00:09:145943
[email protected]50761e92013-03-29 20:51:285944 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535945 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5946 root.get(), root->bounds(), &render_surface_layer_list);
5947 inputs.can_adjust_raster_scales = true;
5948 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325949
5950 // Sanity check the scenario we just created.
5951 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455952 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5953 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:325954
5955 // Hit checking for a point outside the layer should return a null pointer.
5956 // Despite the child layer being very large, it should be clipped to the root
5957 // layer's bounds.
5958 gfx::Point test_point(24, 24);
5959 LayerImpl* result_layer =
5960 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5961 test_point, render_surface_layer_list);
5962 EXPECT_FALSE(result_layer);
5963
5964 // Hit checking for a point inside the layer, but outside the touch handler
5965 // region should return a null pointer.
5966 test_point = gfx::Point(35, 35);
5967 result_layer =
5968 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5969 test_point, render_surface_layer_list);
5970 EXPECT_FALSE(result_layer);
5971
5972 test_point = gfx::Point(74, 74);
5973 result_layer =
5974 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5975 test_point, render_surface_layer_list);
5976 EXPECT_FALSE(result_layer);
5977
5978 // Hit checking for a point inside the touch event handler region should
5979 // return the root layer.
5980 test_point = gfx::Point(25, 25);
5981 result_layer =
5982 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5983 test_point, render_surface_layer_list);
5984 ASSERT_TRUE(result_layer);
5985 EXPECT_EQ(456, result_layer->id());
5986
5987 test_point = gfx::Point(34, 34);
5988 result_layer =
5989 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5990 test_point, render_surface_layer_list);
5991 ASSERT_TRUE(result_layer);
5992 EXPECT_EQ(456, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145993}
5994
[email protected]c974d5d2013-10-24 01:02:485995TEST_F(LayerTreeHostCommonTest,
5996 HitCheckingTouchHandlerOverlappingRegions) {
5997 gfx::Transform identity_matrix;
5998 gfx::PointF anchor;
5999
6000 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456001 TestSharedBitmapManager shared_bitmap_manager;
6002 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c974d5d2013-10-24 01:02:486003 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
6004 SetLayerPropertiesForTesting(root.get(),
6005 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:486006 anchor,
6007 gfx::PointF(),
6008 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576009 true,
[email protected]c974d5d2013-10-24 01:02:486010 false);
6011 {
6012 scoped_ptr<LayerImpl> touch_layer =
6013 LayerImpl::Create(host_impl.active_tree(), 123);
6014 // this layer is positioned, and hit testing should correctly know where the
6015 // layer is located.
6016 gfx::PointF position;
6017 gfx::Size bounds(50, 50);
6018 SetLayerPropertiesForTesting(touch_layer.get(),
6019 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:486020 anchor,
6021 position,
6022 bounds,
[email protected]56fffdd2014-02-11 19:50:576023 true,
[email protected]c974d5d2013-10-24 01:02:486024 false);
6025 touch_layer->SetDrawsContent(true);
6026 touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50));
6027 root->AddChild(touch_layer.Pass());
6028 }
6029
6030 {
6031 scoped_ptr<LayerImpl> notouch_layer =
6032 LayerImpl::Create(host_impl.active_tree(), 1234);
6033 // this layer is positioned, and hit testing should correctly know where the
6034 // layer is located.
6035 gfx::PointF position(0, 25);
6036 gfx::Size bounds(50, 50);
6037 SetLayerPropertiesForTesting(notouch_layer.get(),
6038 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:486039 anchor,
6040 position,
6041 bounds,
[email protected]56fffdd2014-02-11 19:50:576042 true,
[email protected]c974d5d2013-10-24 01:02:486043 false);
6044 notouch_layer->SetDrawsContent(true);
6045 root->AddChild(notouch_layer.Pass());
6046 }
6047
6048 LayerImplList render_surface_layer_list;
6049 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6050 root.get(), root->bounds(), &render_surface_layer_list);
6051 inputs.can_adjust_raster_scales = true;
6052 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6053
6054 // Sanity check the scenario we just created.
6055 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:456056 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
6057 ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id());
6058 ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id());
[email protected]c974d5d2013-10-24 01:02:486059
6060 gfx::Point test_point(35, 35);
6061 LayerImpl* result_layer =
6062 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6063 test_point, render_surface_layer_list);
[email protected]5183605e2014-04-17 03:57:186064
6065 // We should have passed through the no-touch layer and found the layer
6066 // behind it.
6067 EXPECT_TRUE(result_layer);
6068
6069 host_impl.active_tree()->LayerById(1234)->SetContentsOpaque(true);
6070 result_layer =
6071 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6072 test_point, render_surface_layer_list);
6073
[email protected]489eb99892014-04-27 00:27:346074 // Even with an opaque layer in the middle, we should still find the layer
6075 // with
6076 // the touch handler behind it (since we can't assume that opaque layers are
6077 // opaque to hit testing).
6078 EXPECT_TRUE(result_layer);
[email protected]c974d5d2013-10-24 01:02:486079
6080 test_point = gfx::Point(35, 15);
6081 result_layer =
6082 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6083 test_point, render_surface_layer_list);
6084 ASSERT_TRUE(result_layer);
6085 EXPECT_EQ(123, result_layer->id());
6086
6087 test_point = gfx::Point(35, 65);
6088 result_layer =
6089 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6090 test_point, render_surface_layer_list);
6091 EXPECT_FALSE(result_layer);
6092}
6093
[email protected]fb661802013-03-25 01:59:326094class NoScaleContentLayer : public ContentLayer {
6095 public:
6096 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
6097 return make_scoped_refptr(new NoScaleContentLayer(client));
6098 }
[email protected]94f206c12012-08-25 00:09:146099
[email protected]fb661802013-03-25 01:59:326100 virtual void CalculateContentsScale(float ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066101 float device_scale_factor,
6102 float page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:226103 float maximum_animation_contents_scale,
[email protected]fb661802013-03-25 01:59:326104 bool animating_transform_to_screen,
6105 float* contents_scale_x,
6106 float* contents_scale_y,
6107 gfx::Size* content_bounds) OVERRIDE {
6108 // Skip over the ContentLayer to the base Layer class.
6109 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066110 device_scale_factor,
6111 page_scale_factor,
[email protected]1c3626e2014-04-09 17:49:226112 maximum_animation_contents_scale,
[email protected]fb661802013-03-25 01:59:326113 animating_transform_to_screen,
6114 contents_scale_x,
6115 contents_scale_y,
6116 content_bounds);
6117 }
[email protected]94f206c12012-08-25 00:09:146118
[email protected]fb661802013-03-25 01:59:326119 protected:
6120 explicit NoScaleContentLayer(ContentLayerClient* client)
6121 : ContentLayer(client) {}
6122 virtual ~NoScaleContentLayer() {}
[email protected]518ee582012-10-24 18:29:446123};
6124
[email protected]fb661802013-03-25 01:59:326125scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
6126 ContentLayerClient* delegate) {
6127 scoped_refptr<NoScaleContentLayer> to_return =
6128 NoScaleContentLayer::Create(delegate);
6129 to_return->SetIsDrawable(true);
6130 return to_return;
[email protected]518ee582012-10-24 18:29:446131}
6132
[email protected]989386c2013-07-18 21:37:236133TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326134 // Verify draw and screen space transforms of layers not in a surface.
6135 MockContentLayerClient delegate;
6136 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:146137
[email protected]fb661802013-03-25 01:59:326138 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6139 SetLayerPropertiesForTesting(parent.get(),
6140 identity_matrix,
[email protected]fb661802013-03-25 01:59:326141 gfx::PointF(),
6142 gfx::PointF(),
6143 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576144 false,
[email protected]fb661802013-03-25 01:59:326145 true);
[email protected]94f206c12012-08-25 00:09:146146
[email protected]fb661802013-03-25 01:59:326147 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6148 SetLayerPropertiesForTesting(child.get(),
6149 identity_matrix,
[email protected]fb661802013-03-25 01:59:326150 gfx::PointF(),
6151 gfx::PointF(2.f, 2.f),
6152 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576153 false,
[email protected]fb661802013-03-25 01:59:326154 true);
[email protected]94f206c12012-08-25 00:09:146155
[email protected]fb661802013-03-25 01:59:326156 scoped_refptr<ContentLayer> child_empty =
6157 CreateDrawableContentLayer(&delegate);
6158 SetLayerPropertiesForTesting(child_empty.get(),
6159 identity_matrix,
[email protected]fb661802013-03-25 01:59:326160 gfx::PointF(),
6161 gfx::PointF(2.f, 2.f),
6162 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576163 false,
[email protected]fb661802013-03-25 01:59:326164 true);
[email protected]f89f5632012-11-14 23:34:456165
[email protected]fb661802013-03-25 01:59:326166 scoped_refptr<NoScaleContentLayer> child_no_scale =
6167 CreateNoScaleDrawableContentLayer(&delegate);
6168 SetLayerPropertiesForTesting(child_no_scale.get(),
6169 identity_matrix,
[email protected]fb661802013-03-25 01:59:326170 gfx::PointF(),
6171 gfx::PointF(2.f, 2.f),
6172 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576173 false,
[email protected]fb661802013-03-25 01:59:326174 true);
[email protected]94f206c12012-08-25 00:09:146175
[email protected]fb661802013-03-25 01:59:326176 parent->AddChild(child);
6177 parent->AddChild(child_empty);
6178 parent->AddChild(child_no_scale);
[email protected]94f206c12012-08-25 00:09:146179
[email protected]d600df7d2013-08-03 02:34:286180 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6181 host->SetRootLayer(parent);
6182
[email protected]fb661802013-03-25 01:59:326183 float device_scale_factor = 2.5f;
6184 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:146185
[email protected]7aad55f2013-07-26 11:25:536186 RenderSurfaceLayerList render_surface_layer_list;
6187 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6188 parent.get(), parent->bounds(), &render_surface_layer_list);
6189 inputs.device_scale_factor = device_scale_factor;
6190 inputs.page_scale_factor = page_scale_factor;
6191 inputs.can_adjust_raster_scales = true;
6192 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446193
[email protected]fb661802013-03-25 01:59:326194 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6195 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6196 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6197 child_empty);
6198 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]94f206c12012-08-25 00:09:146199
[email protected]fb661802013-03-25 01:59:326200 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:146201
[email protected]fb661802013-03-25 01:59:326202 // Verify parent transforms
6203 gfx::Transform expected_parent_transform;
6204 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6205 parent->screen_space_transform());
6206 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6207 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:146208
[email protected]fb661802013-03-25 01:59:326209 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056210 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:146211
[email protected]fb661802013-03-25 01:59:326212 gfx::RectF parent_draw_rect =
6213 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6214 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6215 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:146216
[email protected]2c7c6702013-03-26 03:14:056217 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326218 expected_parent_draw_rect.Scale(device_scale_factor);
6219 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6220 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146221
[email protected]fb661802013-03-25 01:59:326222 // Verify child and child_empty transforms. They should match.
6223 gfx::Transform expected_child_transform;
6224 expected_child_transform.Translate(
6225 device_scale_factor * child->position().x(),
6226 device_scale_factor * child->position().y());
6227 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6228 child->draw_transform());
6229 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6230 child->screen_space_transform());
6231 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6232 child_empty->draw_transform());
6233 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6234 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146235
[email protected]fb661802013-03-25 01:59:326236 // Verify results of transformed child and child_empty rects. They should
6237 // match.
[email protected]2c7c6702013-03-26 03:14:056238 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:146239
[email protected]fb661802013-03-25 01:59:326240 gfx::RectF child_draw_rect =
6241 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6242 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6243 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:146244
[email protected]fb661802013-03-25 01:59:326245 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
6246 child_empty->draw_transform(), child_content_bounds);
6247 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
6248 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:456249
[email protected]fb661802013-03-25 01:59:326250 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
6251 expected_child_draw_rect.Scale(device_scale_factor);
6252 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6253 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
6254 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
6255 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146256
[email protected]fb661802013-03-25 01:59:326257 // Verify child_no_scale transforms
6258 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6259 // All transforms operate on content rects. The child's content rect
6260 // incorporates device scale, but the child_no_scale does not; add it here.
6261 expected_child_no_scale_transform.Scale(device_scale_factor,
6262 device_scale_factor);
6263 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6264 child_no_scale->draw_transform());
6265 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6266 child_no_scale->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146267}
6268
[email protected]989386c2013-07-18 21:37:236269TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326270 // Verify draw and screen space transforms of layers in a surface.
6271 MockContentLayerClient delegate;
6272 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:096273
[email protected]fb661802013-03-25 01:59:326274 gfx::Transform perspective_matrix;
6275 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:096276
[email protected]fb661802013-03-25 01:59:326277 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:056278 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:096279
[email protected]9781afa2013-07-17 23:15:326280 scoped_refptr<Layer> root = Layer::Create();
6281
[email protected]fb661802013-03-25 01:59:326282 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6283 SetLayerPropertiesForTesting(parent.get(),
6284 identity_matrix,
[email protected]fb661802013-03-25 01:59:326285 gfx::PointF(),
6286 gfx::PointF(),
6287 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576288 false,
[email protected]fb661802013-03-25 01:59:326289 true);
[email protected]1b30e8e2012-12-21 02:59:096290
[email protected]fb661802013-03-25 01:59:326291 scoped_refptr<ContentLayer> perspective_surface =
6292 CreateDrawableContentLayer(&delegate);
6293 SetLayerPropertiesForTesting(perspective_surface.get(),
6294 perspective_matrix * scale_small_matrix,
[email protected]fb661802013-03-25 01:59:326295 gfx::PointF(),
6296 gfx::PointF(2.f, 2.f),
6297 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576298 false,
[email protected]fb661802013-03-25 01:59:326299 true);
[email protected]1b30e8e2012-12-21 02:59:096300
[email protected]fb661802013-03-25 01:59:326301 scoped_refptr<ContentLayer> scale_surface =
6302 CreateDrawableContentLayer(&delegate);
6303 SetLayerPropertiesForTesting(scale_surface.get(),
6304 scale_small_matrix,
[email protected]fb661802013-03-25 01:59:326305 gfx::PointF(),
6306 gfx::PointF(2.f, 2.f),
6307 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576308 false,
[email protected]fb661802013-03-25 01:59:326309 true);
[email protected]1b30e8e2012-12-21 02:59:096310
[email protected]fb661802013-03-25 01:59:326311 perspective_surface->SetForceRenderSurface(true);
6312 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:096313
[email protected]fb661802013-03-25 01:59:326314 parent->AddChild(perspective_surface);
6315 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:326316 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:096317
[email protected]d600df7d2013-08-03 02:34:286318 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6319 host->SetRootLayer(root);
6320
[email protected]fb661802013-03-25 01:59:326321 float device_scale_factor = 2.5f;
6322 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:096323
[email protected]7aad55f2013-07-26 11:25:536324 RenderSurfaceLayerList render_surface_layer_list;
6325 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6326 root.get(), parent->bounds(), &render_surface_layer_list);
6327 inputs.device_scale_factor = device_scale_factor;
6328 inputs.page_scale_factor = page_scale_factor;
6329 inputs.page_scale_application_layer = root;
6330 inputs.can_adjust_raster_scales = true;
6331 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:096332
[email protected]fb661802013-03-25 01:59:326333 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6334 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6335 perspective_surface);
6336 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6337 scale_surface);
[email protected]1b30e8e2012-12-21 02:59:096338
[email protected]fb661802013-03-25 01:59:326339 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:096340
[email protected]fb661802013-03-25 01:59:326341 gfx::Transform expected_parent_draw_transform;
6342 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
6343 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096344
[email protected]fb661802013-03-25 01:59:326345 // The scaled surface is rendered at its appropriate scale, and drawn 1:1
6346 // into its target.
6347 gfx::Transform expected_scale_surface_draw_transform;
6348 expected_scale_surface_draw_transform.Translate(
6349 device_scale_factor * page_scale_factor * scale_surface->position().x(),
6350 device_scale_factor * page_scale_factor * scale_surface->position().y());
[email protected]fb661802013-03-25 01:59:326351 EXPECT_TRANSFORMATION_MATRIX_EQ(
6352 expected_scale_surface_draw_transform,
6353 scale_surface->render_surface()->draw_transform());
[email protected]a52c6ff2013-05-04 05:33:156354 gfx::Transform expected_scale_surface_layer_draw_transform =
6355 scale_small_matrix;
[email protected]fb661802013-03-25 01:59:326356 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform,
6357 scale_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096358
[email protected]fb661802013-03-25 01:59:326359 // The scale for the perspective surface is not known, so it is rendered 1:1
6360 // with the screen, and then scaled during drawing.
6361 gfx::Transform expected_perspective_surface_draw_transform;
6362 expected_perspective_surface_draw_transform.Translate(
6363 device_scale_factor * page_scale_factor *
6364 perspective_surface->position().x(),
6365 device_scale_factor * page_scale_factor *
6366 perspective_surface->position().y());
6367 expected_perspective_surface_draw_transform.PreconcatTransform(
6368 perspective_matrix);
6369 expected_perspective_surface_draw_transform.PreconcatTransform(
6370 scale_small_matrix);
6371 gfx::Transform expected_perspective_surface_layer_draw_transform;
6372 EXPECT_TRANSFORMATION_MATRIX_EQ(
6373 expected_perspective_surface_draw_transform,
6374 perspective_surface->render_surface()->draw_transform());
6375 EXPECT_TRANSFORMATION_MATRIX_EQ(
6376 expected_perspective_surface_layer_draw_transform,
6377 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096378}
6379
[email protected]989386c2013-07-18 21:37:236380TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:326381 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
6382 // Verify draw and screen space transforms of layers not in a surface.
6383 MockContentLayerClient delegate;
6384 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:476385
[email protected]fb661802013-03-25 01:59:326386 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6387 SetLayerPropertiesForTesting(parent.get(),
6388 identity_matrix,
[email protected]fb661802013-03-25 01:59:326389 gfx::PointF(),
6390 gfx::PointF(),
6391 gfx::Size(133, 133),
[email protected]56fffdd2014-02-11 19:50:576392 false,
[email protected]fb661802013-03-25 01:59:326393 true);
[email protected]904e9132012-11-01 00:12:476394
[email protected]fb661802013-03-25 01:59:326395 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6396 SetLayerPropertiesForTesting(child.get(),
6397 identity_matrix,
[email protected]fb661802013-03-25 01:59:326398 gfx::PointF(),
6399 gfx::PointF(),
6400 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:576401 false,
[email protected]fb661802013-03-25 01:59:326402 true);
[email protected]904e9132012-11-01 00:12:476403
[email protected]fb661802013-03-25 01:59:326404 scoped_refptr<NoScaleContentLayer> child_no_scale =
6405 CreateNoScaleDrawableContentLayer(&delegate);
6406 SetLayerPropertiesForTesting(child_no_scale.get(),
6407 identity_matrix,
[email protected]fb661802013-03-25 01:59:326408 gfx::PointF(),
6409 gfx::PointF(),
6410 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:576411 false,
[email protected]fb661802013-03-25 01:59:326412 true);
[email protected]904e9132012-11-01 00:12:476413
[email protected]fb661802013-03-25 01:59:326414 parent->AddChild(child);
6415 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:476416
[email protected]d600df7d2013-08-03 02:34:286417 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6418 host->SetRootLayer(parent);
6419
[email protected]fb661802013-03-25 01:59:326420 float device_scale_factor = 1.7f;
6421 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:476422
[email protected]7aad55f2013-07-26 11:25:536423 RenderSurfaceLayerList render_surface_layer_list;
6424 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6425 parent.get(), parent->bounds(), &render_surface_layer_list);
6426 inputs.device_scale_factor = device_scale_factor;
6427 inputs.page_scale_factor = page_scale_factor;
6428 inputs.page_scale_application_layer = parent.get();
6429 inputs.can_adjust_raster_scales = true;
6430 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:476431
[email protected]fb661802013-03-25 01:59:326432 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6433 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6434 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:476435
[email protected]fb661802013-03-25 01:59:326436 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:476437
[email protected]fb661802013-03-25 01:59:326438 // Verify parent transforms
6439 gfx::Transform expected_parent_transform;
6440 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6441 parent->screen_space_transform());
6442 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6443 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:476444
[email protected]fb661802013-03-25 01:59:326445 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056446 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:476447
[email protected]fb661802013-03-25 01:59:326448 gfx::RectF parent_draw_rect =
6449 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6450 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6451 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:476452
[email protected]2c7c6702013-03-26 03:14:056453 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326454 expected_parent_draw_rect.Scale(device_scale_factor);
6455 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
6456 expected_parent_draw_rect.set_height(
6457 ceil(expected_parent_draw_rect.height()));
6458 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6459 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476460
[email protected]fb661802013-03-25 01:59:326461 // Verify child transforms
6462 gfx::Transform expected_child_transform;
6463 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6464 child->draw_transform());
6465 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6466 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476467
[email protected]fb661802013-03-25 01:59:326468 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:056469 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:476470
[email protected]fb661802013-03-25 01:59:326471 gfx::RectF child_draw_rect =
6472 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6473 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6474 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:476475
[email protected]2c7c6702013-03-26 03:14:056476 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:326477 expected_child_draw_rect.Scale(device_scale_factor);
6478 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
6479 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
6480 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6481 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476482
[email protected]fb661802013-03-25 01:59:326483 // Verify child_no_scale transforms
6484 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6485 // All transforms operate on content rects. The child's content rect
6486 // incorporates device scale, but the child_no_scale does not; add it here.
6487 expected_child_no_scale_transform.Scale(device_scale_factor,
6488 device_scale_factor);
6489 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6490 child_no_scale->draw_transform());
6491 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6492 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476493}
6494
[email protected]989386c2013-07-18 21:37:236495TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:326496 MockContentLayerClient delegate;
6497 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446498
[email protected]fb661802013-03-25 01:59:326499 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266500 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326501 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446502
[email protected]fb661802013-03-25 01:59:326503 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266504 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326505 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446506
[email protected]35a99a12013-05-09 23:52:296507 scoped_refptr<Layer> root = Layer::Create();
6508 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446509
[email protected]fb661802013-03-25 01:59:326510 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6511 SetLayerPropertiesForTesting(parent.get(),
6512 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326513 gfx::PointF(),
6514 gfx::PointF(),
6515 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576516 false,
[email protected]fb661802013-03-25 01:59:326517 true);
[email protected]518ee582012-10-24 18:29:446518
[email protected]fb661802013-03-25 01:59:326519 scoped_refptr<ContentLayer> child_scale =
6520 CreateDrawableContentLayer(&delegate);
6521 SetLayerPropertiesForTesting(child_scale.get(),
6522 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326523 gfx::PointF(),
6524 gfx::PointF(2.f, 2.f),
6525 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576526 false,
[email protected]fb661802013-03-25 01:59:326527 true);
[email protected]518ee582012-10-24 18:29:446528
[email protected]fb661802013-03-25 01:59:326529 scoped_refptr<ContentLayer> child_empty =
6530 CreateDrawableContentLayer(&delegate);
6531 SetLayerPropertiesForTesting(child_empty.get(),
6532 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326533 gfx::PointF(),
6534 gfx::PointF(2.f, 2.f),
6535 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576536 false,
[email protected]fb661802013-03-25 01:59:326537 true);
[email protected]f89f5632012-11-14 23:34:456538
[email protected]fb661802013-03-25 01:59:326539 scoped_refptr<NoScaleContentLayer> child_no_scale =
6540 CreateNoScaleDrawableContentLayer(&delegate);
6541 SetLayerPropertiesForTesting(child_no_scale.get(),
6542 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326543 gfx::PointF(),
6544 gfx::PointF(12.f, 12.f),
6545 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576546 false,
[email protected]fb661802013-03-25 01:59:326547 true);
[email protected]518ee582012-10-24 18:29:446548
[email protected]35a99a12013-05-09 23:52:296549 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446550
[email protected]fb661802013-03-25 01:59:326551 parent->AddChild(child_scale);
6552 parent->AddChild(child_empty);
6553 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:446554
[email protected]d600df7d2013-08-03 02:34:286555 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6556 host->SetRootLayer(root);
6557
[email protected]fb661802013-03-25 01:59:326558 float device_scale_factor = 2.5f;
6559 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:446560
[email protected]989386c2013-07-18 21:37:236561 {
6562 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536563 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6564 root.get(), root->bounds(), &render_surface_layer_list);
6565 inputs.device_scale_factor = device_scale_factor;
6566 inputs.page_scale_factor = page_scale_factor;
6567 inputs.page_scale_application_layer = root.get();
6568 inputs.can_adjust_raster_scales = true;
6569 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446570
[email protected]989386c2013-07-18 21:37:236571 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6572 initial_parent_scale, parent);
6573 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6574 initial_parent_scale * initial_child_scale,
6575 child_scale);
6576 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6577 initial_parent_scale * initial_child_scale,
6578 child_empty);
6579 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:446580
[email protected]989386c2013-07-18 21:37:236581 // The parent is scaled up and shouldn't need to scale during draw. The
6582 // child that can scale its contents should also not need to scale during
6583 // draw. This shouldn't change if the child has empty bounds. The other
6584 // children should.
[email protected]803f6b52013-09-12 00:51:266585 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
6586 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
6587 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
6588 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
6589 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
6590 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236591 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6592 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266593 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:236594 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266595 initial_parent_scale * initial_child_scale,
6596 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236597 }
[email protected]518ee582012-10-24 18:29:446598
[email protected]fb661802013-03-25 01:59:326599 // If the device_scale_factor or page_scale_factor changes, then it should be
6600 // updated using the initial transform as the raster scale.
6601 device_scale_factor = 2.25f;
6602 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:446603
[email protected]989386c2013-07-18 21:37:236604 {
6605 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536606 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6607 root.get(), root->bounds(), &render_surface_layer_list);
6608 inputs.device_scale_factor = device_scale_factor;
6609 inputs.page_scale_factor = page_scale_factor;
6610 inputs.page_scale_application_layer = root.get();
6611 inputs.can_adjust_raster_scales = true;
6612 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6613
6614 EXPECT_CONTENTS_SCALE_EQ(
6615 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:236616 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536617 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:236618 child_scale);
6619 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6620 initial_parent_scale * initial_child_scale,
6621 child_empty);
6622 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6623 }
[email protected]d0518202013-02-08 02:06:496624
[email protected]fb661802013-03-25 01:59:326625 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:266626 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326627 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
6628 second_child_scale / initial_child_scale);
6629 child_scale->SetTransform(child_scale_matrix);
6630 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:496631
[email protected]989386c2013-07-18 21:37:236632 {
6633 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536634 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6635 root.get(), root->bounds(), &render_surface_layer_list);
6636 inputs.device_scale_factor = device_scale_factor;
6637 inputs.page_scale_factor = page_scale_factor;
6638 inputs.page_scale_application_layer = root.get();
6639 inputs.can_adjust_raster_scales = true;
6640 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496641
[email protected]989386c2013-07-18 21:37:236642 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6643 initial_parent_scale,
6644 parent);
6645 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6646 child_scale);
6647 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6648 child_empty);
6649 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6650 }
[email protected]d0518202013-02-08 02:06:496651
[email protected]fb661802013-03-25 01:59:326652 // If the device_scale_factor or page_scale_factor changes, then it should be
6653 // updated, but still using 1.0 as the raster scale.
6654 device_scale_factor = 2.75f;
6655 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:496656
[email protected]989386c2013-07-18 21:37:236657 {
6658 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536659 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6660 root.get(), root->bounds(), &render_surface_layer_list);
6661 inputs.device_scale_factor = device_scale_factor;
6662 inputs.page_scale_factor = page_scale_factor;
6663 inputs.page_scale_application_layer = root.get();
6664 inputs.can_adjust_raster_scales = true;
6665 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496666
[email protected]989386c2013-07-18 21:37:236667 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6668 initial_parent_scale,
6669 parent);
6670 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6671 child_scale);
6672 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6673 child_empty);
6674 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6675 }
[email protected]518ee582012-10-24 18:29:446676}
6677
[email protected]989386c2013-07-18 21:37:236678TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:296679 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:326680 MockContentLayerClient delegate;
6681 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:216682
[email protected]fb661802013-03-25 01:59:326683 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266684 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326685 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:216686
[email protected]fb661802013-03-25 01:59:326687 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266688 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326689 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:216690
[email protected]35a99a12013-05-09 23:52:296691 scoped_refptr<Layer> root = Layer::Create();
6692 root->SetBounds(gfx::Size(100, 100));
6693
[email protected]fb661802013-03-25 01:59:326694 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6695 SetLayerPropertiesForTesting(parent.get(),
6696 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326697 gfx::PointF(),
6698 gfx::PointF(),
6699 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576700 false,
[email protected]fb661802013-03-25 01:59:326701 true);
[email protected]11ec92972012-11-10 03:06:216702
[email protected]fb661802013-03-25 01:59:326703 scoped_refptr<ContentLayer> child_scale =
6704 CreateDrawableContentLayer(&delegate);
6705 SetLayerPropertiesForTesting(child_scale.get(),
6706 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326707 gfx::PointF(),
6708 gfx::PointF(2.f, 2.f),
6709 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576710 false,
[email protected]fb661802013-03-25 01:59:326711 true);
[email protected]11ec92972012-11-10 03:06:216712
[email protected]35a99a12013-05-09 23:52:296713 scoped_refptr<ContentLayer> child_empty =
6714 CreateDrawableContentLayer(&delegate);
6715 SetLayerPropertiesForTesting(child_empty.get(),
6716 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296717 gfx::PointF(),
6718 gfx::PointF(2.f, 2.f),
6719 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576720 false,
[email protected]35a99a12013-05-09 23:52:296721 true);
6722
6723 scoped_refptr<NoScaleContentLayer> child_no_scale =
6724 CreateNoScaleDrawableContentLayer(&delegate);
6725 SetLayerPropertiesForTesting(child_no_scale.get(),
6726 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296727 gfx::PointF(),
6728 gfx::PointF(12.f, 12.f),
6729 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576730 false,
[email protected]35a99a12013-05-09 23:52:296731 true);
6732
6733 root->AddChild(parent);
6734
6735 parent->AddChild(child_scale);
6736 parent->AddChild(child_empty);
6737 parent->AddChild(child_no_scale);
6738
[email protected]d600df7d2013-08-03 02:34:286739 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6740 host->SetRootLayer(root);
6741
[email protected]989386c2013-07-18 21:37:236742 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:296743
6744 float device_scale_factor = 2.5f;
6745 float page_scale_factor = 1.f;
6746
[email protected]7aad55f2013-07-26 11:25:536747 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6748 root.get(), root->bounds(), &render_surface_layer_list);
6749 inputs.device_scale_factor = device_scale_factor;
6750 inputs.page_scale_factor = page_scale_factor;
6751 inputs.page_scale_application_layer = root.get(),
6752 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:296753
6754 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6755 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6756 child_scale);
6757 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6758 child_empty);
6759 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6760
6761 // Since the transform scale does not affect contents scale, it should affect
6762 // the draw transform instead.
6763 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266764 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296765 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266766 parent->draw_transform().matrix().get(1, 1));
[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(0, 0));
[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_scale->draw_transform().matrix().get(1, 1));
[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(0, 0));
[email protected]35a99a12013-05-09 23:52:296773 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266774 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296775 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266776 initial_parent_scale * initial_child_scale,
6777 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296778 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266779 initial_parent_scale * initial_child_scale,
6780 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296781}
6782
[email protected]989386c2013-07-18 21:37:236783TEST_F(LayerTreeHostCommonTest, SmallContentsScale) {
[email protected]35a99a12013-05-09 23:52:296784 MockContentLayerClient delegate;
6785 gfx::Transform identity_matrix;
6786
6787 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266788 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:296789 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6790
6791 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266792 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:296793 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6794
6795 scoped_refptr<Layer> root = Layer::Create();
6796 root->SetBounds(gfx::Size(100, 100));
6797
6798 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6799 SetLayerPropertiesForTesting(parent.get(),
6800 parent_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296801 gfx::PointF(),
6802 gfx::PointF(),
6803 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576804 false,
[email protected]35a99a12013-05-09 23:52:296805 true);
6806
6807 scoped_refptr<ContentLayer> child_scale =
6808 CreateDrawableContentLayer(&delegate);
6809 SetLayerPropertiesForTesting(child_scale.get(),
6810 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296811 gfx::PointF(),
6812 gfx::PointF(2.f, 2.f),
6813 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576814 false,
[email protected]35a99a12013-05-09 23:52:296815 true);
6816
6817 root->AddChild(parent);
6818
[email protected]fb661802013-03-25 01:59:326819 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:216820
[email protected]d600df7d2013-08-03 02:34:286821 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6822 host->SetRootLayer(root);
6823
[email protected]fb661802013-03-25 01:59:326824 float device_scale_factor = 2.5f;
6825 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:216826
[email protected]989386c2013-07-18 21:37:236827 {
6828 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536829 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6830 root.get(), root->bounds(), &render_surface_layer_list);
6831 inputs.device_scale_factor = device_scale_factor;
6832 inputs.page_scale_factor = page_scale_factor;
6833 inputs.page_scale_application_layer = root.get();
6834 inputs.can_adjust_raster_scales = true;
6835 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216836
[email protected]989386c2013-07-18 21:37:236837 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6838 initial_parent_scale,
6839 parent);
6840 // The child's scale is < 1, so we should not save and use that scale
6841 // factor.
6842 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1,
6843 child_scale);
6844 }
[email protected]11ec92972012-11-10 03:06:216845
[email protected]fb661802013-03-25 01:59:326846 // When chilld's total scale becomes >= 1, we should save and use that scale
6847 // factor.
6848 child_scale_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:266849 SkMScalar final_child_scale = 0.75;
[email protected]fb661802013-03-25 01:59:326850 child_scale_matrix.Scale(final_child_scale, final_child_scale);
6851 child_scale->SetTransform(child_scale_matrix);
[email protected]11ec92972012-11-10 03:06:216852
[email protected]989386c2013-07-18 21:37:236853 {
6854 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536855 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6856 root.get(), root->bounds(), &render_surface_layer_list);
6857 inputs.device_scale_factor = device_scale_factor;
6858 inputs.page_scale_factor = page_scale_factor;
6859 inputs.page_scale_application_layer = root.get();
6860 inputs.can_adjust_raster_scales = true;
6861 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216862
[email protected]989386c2013-07-18 21:37:236863 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6864 initial_parent_scale,
6865 parent);
6866 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6867 initial_parent_scale * final_child_scale,
6868 child_scale);
6869 }
[email protected]11ec92972012-11-10 03:06:216870}
6871
[email protected]989386c2013-07-18 21:37:236872TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:326873 MockContentLayerClient delegate;
6874 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446875
[email protected]fb661802013-03-25 01:59:326876 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266877 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:326878 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446879
[email protected]fb661802013-03-25 01:59:326880 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266881 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:326882 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446883
[email protected]35a99a12013-05-09 23:52:296884 scoped_refptr<Layer> root = Layer::Create();
6885 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446886
[email protected]fb661802013-03-25 01:59:326887 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6888 SetLayerPropertiesForTesting(parent.get(),
6889 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326890 gfx::PointF(),
6891 gfx::PointF(),
6892 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576893 false,
[email protected]fb661802013-03-25 01:59:326894 true);
[email protected]518ee582012-10-24 18:29:446895
[email protected]fb661802013-03-25 01:59:326896 scoped_refptr<ContentLayer> surface_scale =
6897 CreateDrawableContentLayer(&delegate);
6898 SetLayerPropertiesForTesting(surface_scale.get(),
6899 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326900 gfx::PointF(),
6901 gfx::PointF(2.f, 2.f),
6902 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576903 false,
[email protected]fb661802013-03-25 01:59:326904 true);
[email protected]518ee582012-10-24 18:29:446905
[email protected]fb661802013-03-25 01:59:326906 scoped_refptr<ContentLayer> surface_scale_child_scale =
6907 CreateDrawableContentLayer(&delegate);
6908 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
6909 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326910 gfx::PointF(),
6911 gfx::PointF(),
6912 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576913 false,
[email protected]fb661802013-03-25 01:59:326914 true);
[email protected]518ee582012-10-24 18:29:446915
[email protected]fb661802013-03-25 01:59:326916 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
6917 CreateNoScaleDrawableContentLayer(&delegate);
6918 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
6919 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326920 gfx::PointF(),
6921 gfx::PointF(),
6922 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576923 false,
[email protected]fb661802013-03-25 01:59:326924 true);
[email protected]518ee582012-10-24 18:29:446925
[email protected]fb661802013-03-25 01:59:326926 scoped_refptr<NoScaleContentLayer> surface_no_scale =
6927 CreateNoScaleDrawableContentLayer(&delegate);
6928 SetLayerPropertiesForTesting(surface_no_scale.get(),
6929 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326930 gfx::PointF(),
6931 gfx::PointF(12.f, 12.f),
6932 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576933 false,
[email protected]fb661802013-03-25 01:59:326934 true);
[email protected]518ee582012-10-24 18:29:446935
[email protected]fb661802013-03-25 01:59:326936 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
6937 CreateDrawableContentLayer(&delegate);
6938 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
6939 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326940 gfx::PointF(),
6941 gfx::PointF(),
6942 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576943 false,
[email protected]fb661802013-03-25 01:59:326944 true);
[email protected]518ee582012-10-24 18:29:446945
[email protected]fb661802013-03-25 01:59:326946 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
6947 CreateNoScaleDrawableContentLayer(&delegate);
6948 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
6949 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326950 gfx::PointF(),
6951 gfx::PointF(),
6952 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576953 false,
[email protected]fb661802013-03-25 01:59:326954 true);
[email protected]518ee582012-10-24 18:29:446955
[email protected]35a99a12013-05-09 23:52:296956 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446957
[email protected]fb661802013-03-25 01:59:326958 parent->AddChild(surface_scale);
6959 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:446960
[email protected]fb661802013-03-25 01:59:326961 surface_scale->SetForceRenderSurface(true);
6962 surface_scale->AddChild(surface_scale_child_scale);
6963 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446964
[email protected]fb661802013-03-25 01:59:326965 surface_no_scale->SetForceRenderSurface(true);
6966 surface_no_scale->AddChild(surface_no_scale_child_scale);
6967 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446968
[email protected]d600df7d2013-08-03 02:34:286969 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6970 host->SetRootLayer(root);
6971
[email protected]803f6b52013-09-12 00:51:266972 SkMScalar device_scale_factor = 5;
6973 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:446974
[email protected]7aad55f2013-07-26 11:25:536975 RenderSurfaceLayerList render_surface_layer_list;
6976 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6977 root.get(), root->bounds(), &render_surface_layer_list);
6978 inputs.device_scale_factor = device_scale_factor;
6979 inputs.page_scale_factor = page_scale_factor;
6980 inputs.page_scale_application_layer = root.get();
6981 inputs.can_adjust_raster_scales = true;
6982 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6983
6984 EXPECT_CONTENTS_SCALE_EQ(
6985 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:196986 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536987 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:326988 surface_scale);
6989 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
6990 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:326991 device_scale_factor * page_scale_factor * initial_parent_scale *
6992 initial_child_scale * initial_child_scale,
6993 surface_scale_child_scale);
6994 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
6995 EXPECT_CONTENTS_SCALE_EQ(
6996 device_scale_factor * page_scale_factor * initial_parent_scale *
6997 initial_child_scale * initial_child_scale,
6998 surface_no_scale_child_scale);
6999 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:447000
[email protected]fb661802013-03-25 01:59:327001 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:267002 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
7003 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447004
[email protected]fb661802013-03-25 01:59:327005 // RenderSurfaces should always be 1:1 with their target.
7006 EXPECT_FLOAT_EQ(
7007 1.0,
[email protected]803f6b52013-09-12 00:51:267008 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327009 EXPECT_FLOAT_EQ(
7010 1.0,
[email protected]803f6b52013-09-12 00:51:267011 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447012
[email protected]fb661802013-03-25 01:59:327013 // The surface_scale can apply contents scale so the layer shouldn't need to
7014 // scale during draw.
[email protected]803f6b52013-09-12 00:51:267015 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
7016 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447017
[email protected]fb661802013-03-25 01:59:327018 // The surface_scale_child_scale can apply contents scale so it shouldn't need
7019 // to scale during draw.
7020 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267021 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327022 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267023 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447024
[email protected]fb661802013-03-25 01:59:327025 // The surface_scale_child_no_scale can not apply contents scale, so it needs
7026 // to be scaled during draw.
7027 EXPECT_FLOAT_EQ(
7028 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267029 initial_child_scale * initial_child_scale,
7030 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327031 EXPECT_FLOAT_EQ(
7032 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267033 initial_child_scale * initial_child_scale,
7034 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447035
[email protected]fb661802013-03-25 01:59:327036 // RenderSurfaces should always be 1:1 with their target.
7037 EXPECT_FLOAT_EQ(
7038 1.0,
[email protected]803f6b52013-09-12 00:51:267039 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327040 EXPECT_FLOAT_EQ(
7041 1.0,
[email protected]803f6b52013-09-12 00:51:267042 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447043
[email protected]fb661802013-03-25 01:59:327044 // The surface_no_scale layer can not apply contents scale, so it needs to be
7045 // scaled during draw.
7046 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:267047 initial_parent_scale * initial_child_scale,
7048 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327049 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:267050 initial_parent_scale * initial_child_scale,
7051 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447052
[email protected]fb661802013-03-25 01:59:327053 // The surface_scale_child_scale can apply contents scale so it shouldn't need
7054 // to scale during draw.
7055 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267056 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327057 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267058 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447059
[email protected]fb661802013-03-25 01:59:327060 // The surface_scale_child_no_scale can not apply contents scale, so it needs
7061 // to be scaled during draw.
7062 EXPECT_FLOAT_EQ(
7063 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267064 initial_child_scale * initial_child_scale,
7065 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327066 EXPECT_FLOAT_EQ(
7067 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267068 initial_child_scale * initial_child_scale,
7069 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297070}
[email protected]518ee582012-10-24 18:29:447071
[email protected]989386c2013-07-18 21:37:237072TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:297073 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
7074 MockContentLayerClient delegate;
7075 gfx::Transform identity_matrix;
7076
7077 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267078 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:297079 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
7080
7081 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267082 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:297083 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
7084
7085 scoped_refptr<Layer> root = Layer::Create();
7086 root->SetBounds(gfx::Size(100, 100));
7087
7088 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7089 SetLayerPropertiesForTesting(parent.get(),
7090 parent_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297091 gfx::PointF(),
7092 gfx::PointF(),
7093 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577094 false,
[email protected]35a99a12013-05-09 23:52:297095 true);
7096
7097 scoped_refptr<ContentLayer> surface_scale =
7098 CreateDrawableContentLayer(&delegate);
7099 SetLayerPropertiesForTesting(surface_scale.get(),
7100 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297101 gfx::PointF(),
7102 gfx::PointF(2.f, 2.f),
7103 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577104 false,
[email protected]35a99a12013-05-09 23:52:297105 true);
7106
7107 scoped_refptr<ContentLayer> surface_scale_child_scale =
7108 CreateDrawableContentLayer(&delegate);
7109 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
7110 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297111 gfx::PointF(),
7112 gfx::PointF(),
7113 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577114 false,
[email protected]35a99a12013-05-09 23:52:297115 true);
7116
7117 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
7118 CreateNoScaleDrawableContentLayer(&delegate);
7119 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
7120 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297121 gfx::PointF(),
7122 gfx::PointF(),
7123 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577124 false,
[email protected]35a99a12013-05-09 23:52:297125 true);
7126
7127 scoped_refptr<NoScaleContentLayer> surface_no_scale =
7128 CreateNoScaleDrawableContentLayer(&delegate);
7129 SetLayerPropertiesForTesting(surface_no_scale.get(),
7130 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297131 gfx::PointF(),
7132 gfx::PointF(12.f, 12.f),
7133 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577134 false,
[email protected]35a99a12013-05-09 23:52:297135 true);
7136
7137 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
7138 CreateDrawableContentLayer(&delegate);
7139 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
7140 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297141 gfx::PointF(),
7142 gfx::PointF(),
7143 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577144 false,
[email protected]35a99a12013-05-09 23:52:297145 true);
7146
7147 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
7148 CreateNoScaleDrawableContentLayer(&delegate);
7149 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
7150 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297151 gfx::PointF(),
7152 gfx::PointF(),
7153 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577154 false,
[email protected]35a99a12013-05-09 23:52:297155 true);
7156
7157 root->AddChild(parent);
7158
7159 parent->AddChild(surface_scale);
7160 parent->AddChild(surface_no_scale);
7161
7162 surface_scale->SetForceRenderSurface(true);
7163 surface_scale->AddChild(surface_scale_child_scale);
7164 surface_scale->AddChild(surface_scale_child_no_scale);
7165
7166 surface_no_scale->SetForceRenderSurface(true);
7167 surface_no_scale->AddChild(surface_no_scale_child_scale);
7168 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
7169
[email protected]d600df7d2013-08-03 02:34:287170 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7171 host->SetRootLayer(root);
7172
[email protected]989386c2013-07-18 21:37:237173 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:297174
[email protected]803f6b52013-09-12 00:51:267175 SkMScalar device_scale_factor = 5.0;
7176 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:537177 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7178 root.get(), root->bounds(), &render_surface_layer_list);
7179 inputs.device_scale_factor = device_scale_factor;
7180 inputs.page_scale_factor = page_scale_factor;
7181 inputs.page_scale_application_layer = root.get();
7182 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:297183
[email protected]35a99a12013-05-09 23:52:297184 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7185 parent);
7186 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7187 surface_scale);
7188 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
7189 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7190 surface_scale_child_scale);
7191 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
7192 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7193 surface_no_scale_child_scale);
7194 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
7195
7196 // The parent is scaled up during draw, since its contents are not scaled by
7197 // the transform hierarchy.
7198 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267199 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297200 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267201 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297202
7203 // The child surface is scaled up during draw since its subtree is not scaled
7204 // by the transform hierarchy.
7205 EXPECT_FLOAT_EQ(
7206 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267207 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297208 EXPECT_FLOAT_EQ(
7209 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267210 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297211
7212 // The surface_scale's RenderSurface is scaled during draw, so the layer does
7213 // not need to be scaled when drawing into its surface.
[email protected]803f6b52013-09-12 00:51:267214 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
7215 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447216
[email protected]35a99a12013-05-09 23:52:297217 // The surface_scale_child_scale is scaled when drawing into its surface,
7218 // since its content bounds are not scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:327219 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297220 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267221 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327222 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297223 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267224 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447225
[email protected]35a99a12013-05-09 23:52:297226 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
7227 // needs to be scaled by the device and page scale factors, along with the
7228 // transform hierarchy.
[email protected]fb661802013-03-25 01:59:327229 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297230 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267231 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297232 EXPECT_FLOAT_EQ(
7233 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267234 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297235
7236 // The child surface is scaled up during draw since its subtree is not scaled
7237 // by the transform hierarchy.
7238 EXPECT_FLOAT_EQ(
7239 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267240 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327241 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297242 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267243 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447244
[email protected]35a99a12013-05-09 23:52:297245 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
7246 // be scaled by the device and page scale factors. Its surface is already
7247 // scaled by the transform hierarchy so those don't need to scale the layer's
7248 // drawing.
7249 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267250 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297251 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267252 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297253
7254 // The surface_no_scale_child_scale has its contents scaled by the page and
7255 // device scale factors, but needs to be scaled by the transform hierarchy
7256 // when drawing.
[email protected]fb661802013-03-25 01:59:327257 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297258 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267259 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327260 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297261 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267262 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297263
7264 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
7265 // needs to be scaled by the device and page scale factors. It also needs to
7266 // be scaled by any transform heirarchy below its target surface.
7267 EXPECT_FLOAT_EQ(
7268 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267269 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297270 EXPECT_FLOAT_EQ(
7271 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267272 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447273}
7274
[email protected]989386c2013-07-18 21:37:237275TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:327276 MockContentLayerClient delegate;
7277 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267278
[email protected]fb661802013-03-25 01:59:327279 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267280 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:327281 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:267282
[email protected]fb661802013-03-25 01:59:327283 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267284 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:327285 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:267286
[email protected]35a99a12013-05-09 23:52:297287 scoped_refptr<Layer> root = Layer::Create();
7288 root->SetBounds(gfx::Size(100, 100));
7289
[email protected]fb661802013-03-25 01:59:327290 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7291 SetLayerPropertiesForTesting(parent.get(),
7292 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:327293 gfx::PointF(),
7294 gfx::PointF(),
7295 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577296 false,
[email protected]fb661802013-03-25 01:59:327297 true);
[email protected]6a9cff92012-11-08 11:53:267298
[email protected]fb661802013-03-25 01:59:327299 scoped_refptr<ContentLayer> child_scale =
7300 CreateDrawableContentLayer(&delegate);
7301 SetLayerPropertiesForTesting(child_scale.get(),
7302 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:327303 gfx::PointF(),
7304 gfx::PointF(2.f, 2.f),
7305 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577306 false,
[email protected]fb661802013-03-25 01:59:327307 true);
[email protected]6a9cff92012-11-08 11:53:267308
[email protected]35a99a12013-05-09 23:52:297309 root->AddChild(parent);
7310
[email protected]fb661802013-03-25 01:59:327311 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:267312
[email protected]d600df7d2013-08-03 02:34:287313 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7314 host->SetRootLayer(root);
7315
[email protected]fb661802013-03-25 01:59:327316 // Now put an animating transform on child.
7317 int animation_id = AddAnimatedTransformToController(
7318 child_scale->layer_animation_controller(), 10.0, 30, 0);
[email protected]6a9cff92012-11-08 11:53:267319
[email protected]989386c2013-07-18 21:37:237320 {
7321 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537322 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7323 root.get(), root->bounds(), &render_surface_layer_list);
7324 inputs.can_adjust_raster_scales = true;
7325 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267326
[email protected]989386c2013-07-18 21:37:237327 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7328 // The layers with animating transforms should not compute a contents scale
7329 // other than 1 until they finish animating.
7330 EXPECT_CONTENTS_SCALE_EQ(1, child_scale);
7331 }
[email protected]6a9cff92012-11-08 11:53:267332
[email protected]fb661802013-03-25 01:59:327333 // Remove the animation, now it can save a raster scale.
7334 child_scale->layer_animation_controller()->RemoveAnimation(animation_id);
[email protected]6a9cff92012-11-08 11:53:267335
[email protected]989386c2013-07-18 21:37:237336 {
7337 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537338 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7339 root.get(), root->bounds(), &render_surface_layer_list);
7340 inputs.can_adjust_raster_scales = true;
7341 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267342
[email protected]989386c2013-07-18 21:37:237343 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7344 // The layers with animating transforms should not compute a contents scale
7345 // other than 1 until they finish animating.
7346 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale,
7347 child_scale);
7348 }
[email protected]6a9cff92012-11-08 11:53:267349}
7350
[email protected]7a5a9322014-02-25 12:54:577351TEST_F(LayerTreeHostCommonTest,
7352 ChangeInContentBoundsOrScaleTriggersPushProperties) {
7353 MockContentLayerClient delegate;
7354 scoped_refptr<Layer> root = Layer::Create();
7355 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate);
7356 root->AddChild(child);
7357
7358 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7359 host->SetRootLayer(root);
7360
7361 gfx::Transform identity_matrix;
7362 SetLayerPropertiesForTesting(root.get(),
7363 identity_matrix,
7364 gfx::PointF(),
7365 gfx::PointF(),
7366 gfx::Size(100, 100),
7367 true,
7368 false);
7369 SetLayerPropertiesForTesting(child.get(),
7370 identity_matrix,
7371 gfx::PointF(),
7372 gfx::PointF(),
7373 gfx::Size(100, 100),
7374 true,
7375 false);
7376
7377 root->reset_needs_push_properties_for_testing();
7378 child->reset_needs_push_properties_for_testing();
7379
7380 // This will change both layers' content bounds.
7381 ExecuteCalculateDrawProperties(root.get());
7382 EXPECT_TRUE(root->needs_push_properties());
7383 EXPECT_TRUE(child->needs_push_properties());
7384
7385 root->reset_needs_push_properties_for_testing();
7386 child->reset_needs_push_properties_for_testing();
7387
7388 // This will change only the child layer's contents scale and content bounds,
7389 // since the root layer is not a ContentsScalingLayer.
7390 ExecuteCalculateDrawProperties(root.get(), 2.f);
7391 EXPECT_FALSE(root->needs_push_properties());
7392 EXPECT_TRUE(child->needs_push_properties());
7393
7394 root->reset_needs_push_properties_for_testing();
7395 child->reset_needs_push_properties_for_testing();
7396
7397 // This will not change either layer's contents scale or content bounds.
7398 ExecuteCalculateDrawProperties(root.get(), 2.f);
7399 EXPECT_FALSE(root->needs_push_properties());
7400 EXPECT_FALSE(child->needs_push_properties());
7401}
7402
[email protected]989386c2013-07-18 21:37:237403TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:327404 MockContentLayerClient delegate;
7405 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267406
[email protected]fb661802013-03-25 01:59:327407 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7408 SetLayerPropertiesForTesting(parent.get(),
7409 identity_matrix,
[email protected]fb661802013-03-25 01:59:327410 gfx::PointF(),
7411 gfx::PointF(),
7412 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577413 false,
[email protected]fb661802013-03-25 01:59:327414 true);
[email protected]94f206c12012-08-25 00:09:147415
[email protected]fb661802013-03-25 01:59:327416 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7417 SetLayerPropertiesForTesting(child.get(),
7418 identity_matrix,
[email protected]fb661802013-03-25 01:59:327419 gfx::PointF(),
7420 gfx::PointF(2.f, 2.f),
7421 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577422 false,
[email protected]fb661802013-03-25 01:59:327423 true);
[email protected]94f206c12012-08-25 00:09:147424
[email protected]fb661802013-03-25 01:59:327425 gfx::Transform replica_transform;
7426 replica_transform.Scale(1.0, -1.0);
7427 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7428 SetLayerPropertiesForTesting(replica.get(),
7429 replica_transform,
[email protected]fb661802013-03-25 01:59:327430 gfx::PointF(),
7431 gfx::PointF(2.f, 2.f),
7432 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577433 false,
[email protected]fb661802013-03-25 01:59:327434 true);
[email protected]94f206c12012-08-25 00:09:147435
[email protected]fb661802013-03-25 01:59:327436 // This layer should end up in the same surface as child, with the same draw
7437 // and screen space transforms.
7438 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7439 CreateDrawableContentLayer(&delegate);
7440 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7441 identity_matrix,
[email protected]fb661802013-03-25 01:59:327442 gfx::PointF(),
7443 gfx::PointF(),
7444 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577445 false,
[email protected]fb661802013-03-25 01:59:327446 true);
[email protected]94f206c12012-08-25 00:09:147447
[email protected]fb661802013-03-25 01:59:327448 parent->AddChild(child);
7449 child->AddChild(duplicate_child_non_owner);
7450 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:147451
[email protected]d600df7d2013-08-03 02:34:287452 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7453 host->SetRootLayer(parent);
7454
[email protected]989386c2013-07-18 21:37:237455 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:147456
[email protected]fb661802013-03-25 01:59:327457 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:537458 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7459 parent.get(), parent->bounds(), &render_surface_layer_list);
7460 inputs.device_scale_factor = device_scale_factor;
7461 inputs.can_adjust_raster_scales = true;
7462 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:147463
[email protected]fb661802013-03-25 01:59:327464 // We should have two render surfaces. The root's render surface and child's
7465 // render surface (it needs one because it has a replica layer).
7466 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:147467
[email protected]fb661802013-03-25 01:59:327468 gfx::Transform expected_parent_transform;
7469 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7470 parent->screen_space_transform());
7471 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7472 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:147473
[email protected]fb661802013-03-25 01:59:327474 gfx::Transform expected_draw_transform;
7475 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
7476 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:147477
[email protected]fb661802013-03-25 01:59:327478 gfx::Transform expected_screen_space_transform;
7479 expected_screen_space_transform.Translate(
7480 device_scale_factor * child->position().x(),
7481 device_scale_factor * child->position().y());
7482 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
7483 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147484
[email protected]fb661802013-03-25 01:59:327485 gfx::Transform expected_duplicate_child_draw_transform =
7486 child->draw_transform();
7487 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
7488 duplicate_child_non_owner->draw_transform());
7489 EXPECT_TRANSFORMATION_MATRIX_EQ(
7490 child->screen_space_transform(),
7491 duplicate_child_non_owner->screen_space_transform());
7492 EXPECT_RECT_EQ(child->drawable_content_rect(),
7493 duplicate_child_non_owner->drawable_content_rect());
7494 EXPECT_EQ(child->content_bounds(),
7495 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:147496
[email protected]fb661802013-03-25 01:59:327497 gfx::Transform expected_render_surface_draw_transform;
7498 expected_render_surface_draw_transform.Translate(
7499 device_scale_factor * child->position().x(),
7500 device_scale_factor * child->position().y());
7501 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
7502 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147503
[email protected]fb661802013-03-25 01:59:327504 gfx::Transform expected_surface_draw_transform;
7505 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
7506 device_scale_factor * 2.f);
7507 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
7508 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147509
[email protected]fb661802013-03-25 01:59:327510 gfx::Transform expected_surface_screen_space_transform;
7511 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
7512 device_scale_factor * 2.f);
7513 EXPECT_TRANSFORMATION_MATRIX_EQ(
7514 expected_surface_screen_space_transform,
7515 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147516
[email protected]fb661802013-03-25 01:59:327517 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267518 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
7519 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
7520 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327521 EXPECT_TRANSFORMATION_MATRIX_EQ(
7522 expected_replica_draw_transform,
7523 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:147524
[email protected]fb661802013-03-25 01:59:327525 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267526 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
7527 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
7528 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327529 EXPECT_TRANSFORMATION_MATRIX_EQ(
7530 expected_replica_screen_space_transform,
7531 child->render_surface()->replica_screen_space_transform());
7532 EXPECT_TRANSFORMATION_MATRIX_EQ(
7533 expected_replica_screen_space_transform,
7534 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:477535}
7536
[email protected]989386c2013-07-18 21:37:237537TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:327538 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
7539 MockContentLayerClient delegate;
7540 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:477541
[email protected]fb661802013-03-25 01:59:327542 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7543 SetLayerPropertiesForTesting(parent.get(),
7544 identity_matrix,
[email protected]fb661802013-03-25 01:59:327545 gfx::PointF(),
7546 gfx::PointF(),
7547 gfx::Size(33, 31),
[email protected]56fffdd2014-02-11 19:50:577548 false,
[email protected]fb661802013-03-25 01:59:327549 true);
[email protected]904e9132012-11-01 00:12:477550
[email protected]fb661802013-03-25 01:59:327551 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7552 SetLayerPropertiesForTesting(child.get(),
7553 identity_matrix,
[email protected]fb661802013-03-25 01:59:327554 gfx::PointF(),
7555 gfx::PointF(),
7556 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577557 false,
[email protected]fb661802013-03-25 01:59:327558 true);
[email protected]904e9132012-11-01 00:12:477559
[email protected]fb661802013-03-25 01:59:327560 gfx::Transform replica_transform;
7561 replica_transform.Scale(1.0, -1.0);
7562 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7563 SetLayerPropertiesForTesting(replica.get(),
7564 replica_transform,
[email protected]fb661802013-03-25 01:59:327565 gfx::PointF(),
7566 gfx::PointF(),
7567 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577568 false,
[email protected]fb661802013-03-25 01:59:327569 true);
[email protected]904e9132012-11-01 00:12:477570
[email protected]fb661802013-03-25 01:59:327571 // This layer should end up in the same surface as child, with the same draw
7572 // and screen space transforms.
7573 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7574 CreateDrawableContentLayer(&delegate);
7575 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7576 identity_matrix,
[email protected]fb661802013-03-25 01:59:327577 gfx::PointF(),
7578 gfx::PointF(),
7579 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577580 false,
[email protected]fb661802013-03-25 01:59:327581 true);
[email protected]904e9132012-11-01 00:12:477582
[email protected]fb661802013-03-25 01:59:327583 parent->AddChild(child);
7584 child->AddChild(duplicate_child_non_owner);
7585 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:477586
[email protected]d600df7d2013-08-03 02:34:287587 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7588 host->SetRootLayer(parent);
7589
[email protected]873639e2013-07-24 19:56:317590 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:537591
7592 RenderSurfaceLayerList render_surface_layer_list;
7593 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7594 parent.get(), parent->bounds(), &render_surface_layer_list);
7595 inputs.device_scale_factor = device_scale_factor;
7596 inputs.can_adjust_raster_scales = true;
7597 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:477598
[email protected]fb661802013-03-25 01:59:327599 // We should have two render surfaces. The root's render surface and child's
7600 // render surface (it needs one because it has a replica layer).
7601 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:477602
[email protected]fb661802013-03-25 01:59:327603 gfx::Transform identity_transform;
[email protected]904e9132012-11-01 00:12:477604
[email protected]fb661802013-03-25 01:59:327605 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7606 parent->screen_space_transform());
7607 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform());
7608 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform());
7609 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7610 child->screen_space_transform());
7611 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7612 duplicate_child_non_owner->draw_transform());
7613 EXPECT_TRANSFORMATION_MATRIX_EQ(
7614 identity_transform, duplicate_child_non_owner->screen_space_transform());
7615 EXPECT_RECT_EQ(child->drawable_content_rect(),
7616 duplicate_child_non_owner->drawable_content_rect());
7617 EXPECT_EQ(child->content_bounds(),
7618 duplicate_child_non_owner->content_bounds());
[email protected]904e9132012-11-01 00:12:477619
[email protected]fb661802013-03-25 01:59:327620 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7621 child->render_surface()->draw_transform());
7622 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7623 child->render_surface()->draw_transform());
7624 EXPECT_TRANSFORMATION_MATRIX_EQ(
7625 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:477626
[email protected]fb661802013-03-25 01:59:327627 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267628 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327629 EXPECT_TRANSFORMATION_MATRIX_EQ(
7630 expected_replica_draw_transform,
7631 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:477632
[email protected]fb661802013-03-25 01:59:327633 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267634 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327635 EXPECT_TRANSFORMATION_MATRIX_EQ(
7636 expected_replica_screen_space_transform,
7637 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147638}
7639
[email protected]989386c2013-07-18 21:37:237640TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:327641 scoped_refptr<Layer> root = Layer::Create();
7642 scoped_refptr<Layer> child = Layer::Create();
7643 scoped_refptr<Layer> grand_child = Layer::Create();
7644 scoped_refptr<Layer> mask_layer = Layer::Create();
7645 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:147646
[email protected]fb661802013-03-25 01:59:327647 grand_child->SetReplicaLayer(replica_layer.get());
7648 child->AddChild(grand_child.get());
7649 child->SetMaskLayer(mask_layer.get());
7650 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:147651
[email protected]d600df7d2013-08-03 02:34:287652 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7653 host->SetRootLayer(root);
7654
[email protected]fb661802013-03-25 01:59:327655 int nonexistent_id = -1;
7656 EXPECT_EQ(root,
7657 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
7658 EXPECT_EQ(child,
7659 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
7660 EXPECT_EQ(
7661 grand_child,
7662 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
7663 EXPECT_EQ(
7664 mask_layer,
7665 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
7666 EXPECT_EQ(
7667 replica_layer,
7668 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
7669 EXPECT_EQ(
7670 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:147671}
7672
[email protected]989386c2013-07-18 21:37:237673TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:327674 scoped_refptr<Layer> root = Layer::Create();
7675 scoped_refptr<Layer> child = Layer::Create();
7676 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
7677 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:577678
[email protected]fb661802013-03-25 01:59:327679 const gfx::Transform identity_matrix;
7680 SetLayerPropertiesForTesting(root.get(),
7681 identity_matrix,
[email protected]fb661802013-03-25 01:59:327682 gfx::PointF(),
7683 gfx::PointF(),
7684 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577685 true,
[email protected]fb661802013-03-25 01:59:327686 false);
7687 SetLayerPropertiesForTesting(child.get(),
7688 identity_matrix,
[email protected]fb661802013-03-25 01:59:327689 gfx::PointF(),
7690 gfx::PointF(),
7691 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577692 true,
[email protected]fb661802013-03-25 01:59:327693 false);
7694 SetLayerPropertiesForTesting(grand_child.get(),
7695 identity_matrix,
[email protected]fb661802013-03-25 01:59:327696 gfx::PointF(),
7697 gfx::PointF(),
7698 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577699 true,
[email protected]fb661802013-03-25 01:59:327700 false);
[email protected]498ec6e0e2012-11-30 18:24:577701
[email protected]fb661802013-03-25 01:59:327702 root->AddChild(child);
7703 child->AddChild(grand_child);
7704 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:577705
[email protected]d600df7d2013-08-03 02:34:287706 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7707 host->SetRootLayer(root);
7708
[email protected]fb661802013-03-25 01:59:327709 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:577710
[email protected]fb661802013-03-25 01:59:327711 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:577712}
7713
[email protected]989386c2013-07-18 21:37:237714TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:167715 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457716 TestSharedBitmapManager shared_bitmap_manager;
7717 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]f90fc412013-03-30 20:13:167718 host_impl.CreatePendingTree();
7719 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7720
7721 const gfx::Transform identity_matrix;
7722 SetLayerPropertiesForTesting(root.get(),
7723 identity_matrix,
[email protected]f90fc412013-03-30 20:13:167724 gfx::PointF(),
7725 gfx::PointF(),
7726 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577727 true,
[email protected]f90fc412013-03-30 20:13:167728 false);
7729 root->SetDrawsContent(true);
7730
7731 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7732 SetLayerPropertiesForTesting(child.get(),
7733 identity_matrix,
[email protected]f90fc412013-03-30 20:13:167734 gfx::PointF(),
7735 gfx::PointF(),
7736 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577737 true,
[email protected]f90fc412013-03-30 20:13:167738 false);
7739 child->SetDrawsContent(true);
7740 child->SetOpacity(0.0f);
7741
7742 // Add opacity animation.
7743 AddOpacityTransitionToController(
7744 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
7745
7746 root->AddChild(child.Pass());
7747
[email protected]c0ae06c12013-06-24 18:32:197748 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537749 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7750 root.get(), root->bounds(), &render_surface_layer_list);
7751 inputs.can_adjust_raster_scales = true;
7752 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:167753
7754 // We should have one render surface and two layers. The child
7755 // layer should be included even though it is transparent.
7756 ASSERT_EQ(1u, render_surface_layer_list.size());
7757 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
7758}
7759
[email protected]10aabcc32012-12-13 09:18:597760typedef std::tr1::tuple<bool, bool> LCDTextTestParam;
[email protected]989386c2013-07-18 21:37:237761class LCDTextTest
7762 : public LayerTreeHostCommonTestBase,
7763 public testing::TestWithParam<LCDTextTestParam> {
[email protected]fb661802013-03-25 01:59:327764 protected:
7765 virtual void SetUp() {
7766 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
[email protected]10aabcc32012-12-13 09:18:597767
[email protected]fb661802013-03-25 01:59:327768 root_ = Layer::Create();
7769 child_ = Layer::Create();
7770 grand_child_ = Layer::Create();
7771 child_->AddChild(grand_child_.get());
7772 root_->AddChild(child_.get());
[email protected]10aabcc32012-12-13 09:18:597773
[email protected]fb661802013-03-25 01:59:327774 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307775 SetLayerPropertiesForTesting(root_.get(),
[email protected]fb661802013-03-25 01:59:327776 identity_matrix,
[email protected]fb661802013-03-25 01:59:327777 gfx::PointF(),
7778 gfx::PointF(),
7779 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577780 true,
[email protected]fb661802013-03-25 01:59:327781 false);
[email protected]22898ed2013-06-01 04:52:307782 SetLayerPropertiesForTesting(child_.get(),
[email protected]fb661802013-03-25 01:59:327783 identity_matrix,
[email protected]fb661802013-03-25 01:59:327784 gfx::PointF(),
7785 gfx::PointF(),
7786 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577787 true,
[email protected]fb661802013-03-25 01:59:327788 false);
[email protected]22898ed2013-06-01 04:52:307789 SetLayerPropertiesForTesting(grand_child_.get(),
[email protected]fb661802013-03-25 01:59:327790 identity_matrix,
[email protected]fb661802013-03-25 01:59:327791 gfx::PointF(),
7792 gfx::PointF(),
7793 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577794 true,
[email protected]fb661802013-03-25 01:59:327795 false);
[email protected]10aabcc32012-12-13 09:18:597796
[email protected]fb661802013-03-25 01:59:327797 child_->SetForceRenderSurface(std::tr1::get<1>(GetParam()));
[email protected]d600df7d2013-08-03 02:34:287798
7799 host_ = FakeLayerTreeHost::Create();
7800 host_->SetRootLayer(root_);
[email protected]fb661802013-03-25 01:59:327801 }
[email protected]10aabcc32012-12-13 09:18:597802
[email protected]fb661802013-03-25 01:59:327803 bool can_use_lcd_text_;
[email protected]d600df7d2013-08-03 02:34:287804 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]fb661802013-03-25 01:59:327805 scoped_refptr<Layer> root_;
7806 scoped_refptr<Layer> child_;
7807 scoped_refptr<Layer> grand_child_;
[email protected]10aabcc32012-12-13 09:18:597808};
7809
[email protected]fb661802013-03-25 01:59:327810TEST_P(LCDTextTest, CanUseLCDText) {
7811 // Case 1: Identity transform.
7812 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307813 ExecuteCalculateDrawProperties(
7814 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327815 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7816 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7817 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597818
[email protected]fb661802013-03-25 01:59:327819 // Case 2: Integral translation.
7820 gfx::Transform integral_translation;
7821 integral_translation.Translate(1.0, 2.0);
7822 child_->SetTransform(integral_translation);
[email protected]22898ed2013-06-01 04:52:307823 ExecuteCalculateDrawProperties(
7824 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327825 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7826 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7827 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597828
[email protected]fb661802013-03-25 01:59:327829 // Case 3: Non-integral translation.
7830 gfx::Transform non_integral_translation;
7831 non_integral_translation.Translate(1.5, 2.5);
7832 child_->SetTransform(non_integral_translation);
[email protected]22898ed2013-06-01 04:52:307833 ExecuteCalculateDrawProperties(
7834 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327835 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7836 EXPECT_FALSE(child_->can_use_lcd_text());
7837 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597838
[email protected]fb661802013-03-25 01:59:327839 // Case 4: Rotation.
7840 gfx::Transform rotation;
7841 rotation.Rotate(10.0);
7842 child_->SetTransform(rotation);
[email protected]22898ed2013-06-01 04:52:307843 ExecuteCalculateDrawProperties(
7844 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327845 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7846 EXPECT_FALSE(child_->can_use_lcd_text());
7847 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597848
[email protected]fb661802013-03-25 01:59:327849 // Case 5: Scale.
7850 gfx::Transform scale;
7851 scale.Scale(2.0, 2.0);
7852 child_->SetTransform(scale);
[email protected]22898ed2013-06-01 04:52:307853 ExecuteCalculateDrawProperties(
7854 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327855 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7856 EXPECT_FALSE(child_->can_use_lcd_text());
7857 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597858
[email protected]fb661802013-03-25 01:59:327859 // Case 6: Skew.
7860 gfx::Transform skew;
7861 skew.SkewX(10.0);
7862 child_->SetTransform(skew);
[email protected]22898ed2013-06-01 04:52:307863 ExecuteCalculateDrawProperties(
7864 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327865 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7866 EXPECT_FALSE(child_->can_use_lcd_text());
7867 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597868
[email protected]fb661802013-03-25 01:59:327869 // Case 7: Translucent.
7870 child_->SetTransform(identity_matrix);
7871 child_->SetOpacity(0.5f);
[email protected]22898ed2013-06-01 04:52:307872 ExecuteCalculateDrawProperties(
7873 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327874 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7875 EXPECT_FALSE(child_->can_use_lcd_text());
7876 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597877
[email protected]fb661802013-03-25 01:59:327878 // Case 8: Sanity check: restore transform and opacity.
7879 child_->SetTransform(identity_matrix);
7880 child_->SetOpacity(1.f);
[email protected]22898ed2013-06-01 04:52:307881 ExecuteCalculateDrawProperties(
7882 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327883 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7884 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7885 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597886}
7887
[email protected]fd9a3b6d2013-08-03 00:46:177888TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
[email protected]fb661802013-03-25 01:59:327889 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
[email protected]22898ed2013-06-01 04:52:307890 ExecuteCalculateDrawProperties(
7891 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327892 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7893 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7894 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597895
[email protected]fb661802013-03-25 01:59:327896 // Add opacity animation.
7897 child_->SetOpacity(0.9f);
7898 AddOpacityTransitionToController(
7899 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:597900
[email protected]22898ed2013-06-01 04:52:307901 ExecuteCalculateDrawProperties(
7902 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327903 // Text AA should not be adjusted while animation is active.
7904 // Make sure LCD text AA setting remains unchanged.
7905 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7906 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7907 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597908}
7909
7910INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
7911 LCDTextTest,
[email protected]fb661802013-03-25 01:59:327912 testing::Combine(testing::Bool(), testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:597913
[email protected]989386c2013-07-18 21:37:237914TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:197915 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457916 TestSharedBitmapManager shared_bitmap_manager;
7917 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:197918 host_impl.CreatePendingTree();
7919 const gfx::Transform identity_matrix;
7920
7921 scoped_refptr<Layer> root = Layer::Create();
7922 SetLayerPropertiesForTesting(root.get(),
7923 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197924 gfx::PointF(),
7925 gfx::PointF(),
7926 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577927 true,
[email protected]c0ae06c12013-06-24 18:32:197928 false);
7929 root->SetIsDrawable(true);
7930
7931 scoped_refptr<Layer> child = Layer::Create();
7932 SetLayerPropertiesForTesting(child.get(),
7933 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197934 gfx::PointF(),
7935 gfx::PointF(),
7936 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577937 true,
[email protected]c0ae06c12013-06-24 18:32:197938 false);
7939 child->SetIsDrawable(true);
7940
7941 scoped_refptr<Layer> grand_child = Layer::Create();
7942 SetLayerPropertiesForTesting(grand_child.get(),
7943 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197944 gfx::PointF(),
7945 gfx::PointF(),
7946 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577947 true,
[email protected]c0ae06c12013-06-24 18:32:197948 false);
7949 grand_child->SetIsDrawable(true);
7950 grand_child->SetHideLayerAndSubtree(true);
7951
7952 child->AddChild(grand_child);
7953 root->AddChild(child);
7954
[email protected]d600df7d2013-08-03 02:34:287955 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7956 host->SetRootLayer(root);
7957
[email protected]989386c2013-07-18 21:37:237958 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537959 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7960 root.get(), root->bounds(), &render_surface_layer_list);
7961 inputs.can_adjust_raster_scales = true;
7962 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197963
7964 // We should have one render surface and two layers. The grand child has
7965 // hidden itself.
7966 ASSERT_EQ(1u, render_surface_layer_list.size());
7967 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237968 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
7969 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197970}
7971
[email protected]989386c2013-07-18 21:37:237972TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:197973 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457974 TestSharedBitmapManager shared_bitmap_manager;
7975 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:197976 host_impl.CreatePendingTree();
7977 const gfx::Transform identity_matrix;
7978
7979 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7980 SetLayerPropertiesForTesting(root.get(),
7981 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197982 gfx::PointF(),
7983 gfx::PointF(),
7984 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577985 true,
[email protected]c0ae06c12013-06-24 18:32:197986 false);
7987 root->SetDrawsContent(true);
7988
7989 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7990 SetLayerPropertiesForTesting(child.get(),
7991 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197992 gfx::PointF(),
7993 gfx::PointF(),
7994 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577995 true,
[email protected]c0ae06c12013-06-24 18:32:197996 false);
7997 child->SetDrawsContent(true);
7998
7999 scoped_ptr<LayerImpl> grand_child =
8000 LayerImpl::Create(host_impl.pending_tree(), 3);
8001 SetLayerPropertiesForTesting(grand_child.get(),
8002 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198003 gfx::PointF(),
8004 gfx::PointF(),
8005 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578006 true,
[email protected]c0ae06c12013-06-24 18:32:198007 false);
8008 grand_child->SetDrawsContent(true);
8009 grand_child->SetHideLayerAndSubtree(true);
8010
8011 child->AddChild(grand_child.Pass());
8012 root->AddChild(child.Pass());
8013
8014 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538015 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8016 root.get(), root->bounds(), &render_surface_layer_list);
8017 inputs.can_adjust_raster_scales = true;
8018 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198019
8020 // We should have one render surface and two layers. The grand child has
8021 // hidden itself.
8022 ASSERT_EQ(1u, render_surface_layer_list.size());
8023 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238024 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
8025 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:198026}
8027
[email protected]989386c2013-07-18 21:37:238028TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:198029 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458030 TestSharedBitmapManager shared_bitmap_manager;
8031 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:198032 host_impl.CreatePendingTree();
8033 const gfx::Transform identity_matrix;
8034
8035 scoped_refptr<Layer> root = Layer::Create();
8036 SetLayerPropertiesForTesting(root.get(),
8037 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198038 gfx::PointF(),
8039 gfx::PointF(),
8040 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578041 true,
[email protected]c0ae06c12013-06-24 18:32:198042 false);
8043 root->SetIsDrawable(true);
8044
8045 scoped_refptr<Layer> child = Layer::Create();
8046 SetLayerPropertiesForTesting(child.get(),
8047 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198048 gfx::PointF(),
8049 gfx::PointF(),
8050 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578051 true,
[email protected]c0ae06c12013-06-24 18:32:198052 false);
8053 child->SetIsDrawable(true);
8054 child->SetHideLayerAndSubtree(true);
8055
8056 scoped_refptr<Layer> grand_child = Layer::Create();
8057 SetLayerPropertiesForTesting(grand_child.get(),
8058 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198059 gfx::PointF(),
8060 gfx::PointF(),
8061 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578062 true,
[email protected]c0ae06c12013-06-24 18:32:198063 false);
8064 grand_child->SetIsDrawable(true);
8065
8066 child->AddChild(grand_child);
8067 root->AddChild(child);
8068
[email protected]d600df7d2013-08-03 02:34:288069 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8070 host->SetRootLayer(root);
8071
[email protected]989386c2013-07-18 21:37:238072 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538073 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8074 root.get(), root->bounds(), &render_surface_layer_list);
8075 inputs.can_adjust_raster_scales = true;
8076 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198077
8078 // We should have one render surface and one layers. The child has
8079 // hidden itself and the grand child.
8080 ASSERT_EQ(1u, render_surface_layer_list.size());
8081 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238082 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:198083}
8084
[email protected]989386c2013-07-18 21:37:238085TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:198086 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458087 TestSharedBitmapManager shared_bitmap_manager;
8088 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:198089 host_impl.CreatePendingTree();
8090 const gfx::Transform identity_matrix;
8091
8092 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
8093 SetLayerPropertiesForTesting(root.get(),
8094 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198095 gfx::PointF(),
8096 gfx::PointF(),
8097 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578098 true,
[email protected]c0ae06c12013-06-24 18:32:198099 false);
8100 root->SetDrawsContent(true);
8101
8102 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
8103 SetLayerPropertiesForTesting(child.get(),
8104 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198105 gfx::PointF(),
8106 gfx::PointF(),
8107 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578108 true,
[email protected]c0ae06c12013-06-24 18:32:198109 false);
8110 child->SetDrawsContent(true);
8111 child->SetHideLayerAndSubtree(true);
8112
8113 scoped_ptr<LayerImpl> grand_child =
8114 LayerImpl::Create(host_impl.pending_tree(), 3);
8115 SetLayerPropertiesForTesting(grand_child.get(),
8116 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198117 gfx::PointF(),
8118 gfx::PointF(),
8119 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578120 true,
[email protected]c0ae06c12013-06-24 18:32:198121 false);
8122 grand_child->SetDrawsContent(true);
8123
8124 child->AddChild(grand_child.Pass());
8125 root->AddChild(child.Pass());
8126
8127 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538128 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8129 root.get(), root->bounds(), &render_surface_layer_list);
8130 inputs.can_adjust_raster_scales = true;
8131 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198132
8133 // We should have one render surface and one layers. The child has
8134 // hidden itself and the grand child.
8135 ASSERT_EQ(1u, render_surface_layer_list.size());
8136 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238137 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:198138}
8139
[email protected]30fe19ff2013-07-04 00:54:458140void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
8141
[email protected]989386c2013-07-18 21:37:238142TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458143 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458144 TestSharedBitmapManager shared_bitmap_manager;
8145 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:458146 host_impl.CreatePendingTree();
8147 const gfx::Transform identity_matrix;
8148
8149 scoped_refptr<Layer> root = Layer::Create();
8150 SetLayerPropertiesForTesting(root.get(),
8151 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458152 gfx::PointF(),
8153 gfx::PointF(),
8154 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578155 true,
[email protected]30fe19ff2013-07-04 00:54:458156 false);
8157 root->SetIsDrawable(true);
8158
8159 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
8160 SetLayerPropertiesForTesting(copy_grand_parent.get(),
8161 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458162 gfx::PointF(),
8163 gfx::PointF(),
8164 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578165 true,
[email protected]30fe19ff2013-07-04 00:54:458166 false);
8167 copy_grand_parent->SetIsDrawable(true);
8168
8169 scoped_refptr<Layer> copy_parent = Layer::Create();
8170 SetLayerPropertiesForTesting(copy_parent.get(),
8171 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458172 gfx::PointF(),
8173 gfx::PointF(),
8174 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578175 true,
[email protected]30fe19ff2013-07-04 00:54:458176 false);
8177 copy_parent->SetIsDrawable(true);
8178 copy_parent->SetForceRenderSurface(true);
8179
8180 scoped_refptr<Layer> copy_layer = Layer::Create();
8181 SetLayerPropertiesForTesting(copy_layer.get(),
8182 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458183 gfx::PointF(),
8184 gfx::PointF(),
8185 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578186 true,
[email protected]30fe19ff2013-07-04 00:54:458187 false);
8188 copy_layer->SetIsDrawable(true);
8189
8190 scoped_refptr<Layer> copy_child = Layer::Create();
8191 SetLayerPropertiesForTesting(copy_child.get(),
8192 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458193 gfx::PointF(),
8194 gfx::PointF(),
8195 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578196 true,
[email protected]30fe19ff2013-07-04 00:54:458197 false);
8198 copy_child->SetIsDrawable(true);
8199
[email protected]ac020122013-07-12 23:45:538200 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
8201 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
8202 identity_matrix,
[email protected]ac020122013-07-12 23:45:538203 gfx::PointF(),
8204 gfx::PointF(),
8205 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578206 true,
[email protected]ac020122013-07-12 23:45:538207 false);
8208 copy_grand_parent_sibling_before->SetIsDrawable(true);
8209
8210 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
8211 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
8212 identity_matrix,
[email protected]ac020122013-07-12 23:45:538213 gfx::PointF(),
8214 gfx::PointF(),
8215 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578216 true,
[email protected]ac020122013-07-12 23:45:538217 false);
8218 copy_grand_parent_sibling_after->SetIsDrawable(true);
8219
[email protected]30fe19ff2013-07-04 00:54:458220 copy_layer->AddChild(copy_child);
8221 copy_parent->AddChild(copy_layer);
8222 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:538223 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:458224 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:538225 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:458226
[email protected]d600df7d2013-08-03 02:34:288227 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8228 host->SetRootLayer(root);
8229
[email protected]30fe19ff2013-07-04 00:54:458230 // Hide the copy_grand_parent and its subtree. But make a copy request in that
8231 // hidden subtree on copy_layer.
8232 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:538233 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
8234 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:458235 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8236 base::Bind(&EmptyCopyOutputCallback)));
8237 EXPECT_TRUE(copy_layer->HasCopyRequest());
8238
[email protected]989386c2013-07-18 21:37:238239 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538240 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8241 root.get(), root->bounds(), &render_surface_layer_list);
8242 inputs.can_adjust_raster_scales = true;
8243 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458244
[email protected]ac020122013-07-12 23:45:538245 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
8246 EXPECT_TRUE(copy_grand_parent->draw_properties().
8247 layer_or_descendant_has_copy_request);
8248 EXPECT_TRUE(copy_parent->draw_properties().
8249 layer_or_descendant_has_copy_request);
8250 EXPECT_TRUE(copy_layer->draw_properties().
8251 layer_or_descendant_has_copy_request);
8252 EXPECT_FALSE(copy_child->draw_properties().
8253 layer_or_descendant_has_copy_request);
8254 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
8255 layer_or_descendant_has_copy_request);
8256 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
8257 layer_or_descendant_has_copy_request);
8258
[email protected]30fe19ff2013-07-04 00:54:458259 // We should have three render surfaces, one for the root, one for the parent
8260 // since it owns a surface, and one for the copy_layer.
8261 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238262 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
8263 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
8264 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:458265
8266 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:538267 // copy_grand_parent is hidden along with its siblings, but the copy_parent
8268 // will appear since something in its subtree needs to be drawn for a copy
8269 // request.
[email protected]30fe19ff2013-07-04 00:54:458270 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238271 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
8272 EXPECT_EQ(copy_parent->id(),
8273 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458274
[email protected]7392c7b2014-02-07 08:28:288275 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:458276 // appear in its list, since it needs to be drawn for the copy request.
8277 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
8278 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238279 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458280
8281 // The copy_layer's render surface should have two contributing layers.
8282 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
8283 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238284 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458285 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:238286 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458287}
8288
[email protected]989386c2013-07-18 21:37:238289TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458290 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458291 TestSharedBitmapManager shared_bitmap_manager;
8292 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:458293 host_impl.CreatePendingTree();
8294 const gfx::Transform identity_matrix;
8295
8296 scoped_refptr<Layer> root = Layer::Create();
8297 SetLayerPropertiesForTesting(root.get(),
8298 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458299 gfx::PointF(),
8300 gfx::PointF(),
8301 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578302 true,
[email protected]30fe19ff2013-07-04 00:54:458303 false);
8304 root->SetIsDrawable(true);
8305
8306 scoped_refptr<Layer> copy_parent = Layer::Create();
8307 SetLayerPropertiesForTesting(copy_parent.get(),
8308 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458309 gfx::PointF(),
8310 gfx::PointF(),
8311 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:578312 true,
[email protected]30fe19ff2013-07-04 00:54:458313 false);
8314 copy_parent->SetIsDrawable(true);
8315 copy_parent->SetMasksToBounds(true);
8316
8317 scoped_refptr<Layer> copy_layer = Layer::Create();
8318 SetLayerPropertiesForTesting(copy_layer.get(),
8319 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458320 gfx::PointF(),
8321 gfx::PointF(),
8322 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578323 true,
[email protected]30fe19ff2013-07-04 00:54:458324 false);
8325 copy_layer->SetIsDrawable(true);
8326
8327 scoped_refptr<Layer> copy_child = Layer::Create();
8328 SetLayerPropertiesForTesting(copy_child.get(),
8329 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458330 gfx::PointF(),
8331 gfx::PointF(),
8332 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578333 true,
[email protected]30fe19ff2013-07-04 00:54:458334 false);
8335 copy_child->SetIsDrawable(true);
8336
8337 copy_layer->AddChild(copy_child);
8338 copy_parent->AddChild(copy_layer);
8339 root->AddChild(copy_parent);
8340
[email protected]d600df7d2013-08-03 02:34:288341 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8342 host->SetRootLayer(root);
8343
[email protected]30fe19ff2013-07-04 00:54:458344 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8345 base::Bind(&EmptyCopyOutputCallback)));
8346 EXPECT_TRUE(copy_layer->HasCopyRequest());
8347
[email protected]989386c2013-07-18 21:37:238348 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538349 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8350 root.get(), root->bounds(), &render_surface_layer_list);
8351 inputs.can_adjust_raster_scales = true;
8352 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458353
8354 // We should have one render surface, as the others are clipped out.
8355 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238356 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458357
8358 // The root render surface should only have 1 contributing layer, since the
8359 // other layers are empty/clipped away.
8360 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238361 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458362}
8363
[email protected]11a07b102013-07-24 17:33:198364TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
8365 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458366 TestSharedBitmapManager shared_bitmap_manager;
8367 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]11a07b102013-07-24 17:33:198368 host_impl.CreatePendingTree();
8369 const gfx::Transform identity_matrix;
8370
8371 scoped_refptr<Layer> root = Layer::Create();
8372 SetLayerPropertiesForTesting(root.get(),
8373 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198374 gfx::PointF(),
8375 gfx::PointF(),
8376 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578377 true,
[email protected]11a07b102013-07-24 17:33:198378 false);
8379 root->SetIsDrawable(true);
8380
8381 // The surface is moved slightly outside of the viewport.
8382 scoped_refptr<Layer> surface = Layer::Create();
8383 SetLayerPropertiesForTesting(surface.get(),
8384 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198385 gfx::PointF(),
8386 gfx::PointF(-10, -20),
8387 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:578388 true,
[email protected]11a07b102013-07-24 17:33:198389 false);
8390 surface->SetForceRenderSurface(true);
8391
8392 scoped_refptr<Layer> surface_child = Layer::Create();
8393 SetLayerPropertiesForTesting(surface_child.get(),
8394 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198395 gfx::PointF(),
8396 gfx::PointF(),
8397 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578398 true,
[email protected]11a07b102013-07-24 17:33:198399 false);
8400 surface_child->SetIsDrawable(true);
8401
8402 surface->AddChild(surface_child);
8403 root->AddChild(surface);
8404
[email protected]d600df7d2013-08-03 02:34:288405 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8406 host->SetRootLayer(root);
8407
[email protected]11a07b102013-07-24 17:33:198408 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538409 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8410 root.get(), root->bounds(), &render_surface_layer_list);
8411 inputs.can_adjust_raster_scales = true;
8412 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:198413
8414 // The visible_content_rect for the |surface_child| should not be clipped by
8415 // the viewport.
8416 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
8417 surface_child->visible_content_rect().ToString());
8418}
8419
[email protected]420fdf6e2013-08-26 20:36:388420TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
8421 // Ensure that a transform between the layer and its render surface is not a
8422 // problem. Constructs the following layer tree.
8423 //
8424 // root (a render surface)
8425 // + render_surface
8426 // + clip_parent (scaled)
8427 // + intervening_clipping_layer
8428 // + clip_child
8429 //
8430 // The render surface should be resized correctly and the clip child should
8431 // inherit the right clip rect.
8432 scoped_refptr<Layer> root = Layer::Create();
8433 scoped_refptr<Layer> render_surface = Layer::Create();
8434 scoped_refptr<Layer> clip_parent = Layer::Create();
8435 scoped_refptr<Layer> intervening = Layer::Create();
8436 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8437 make_scoped_refptr(new LayerWithForcedDrawsContent);
8438
8439 root->AddChild(render_surface);
8440 render_surface->AddChild(clip_parent);
8441 clip_parent->AddChild(intervening);
8442 intervening->AddChild(clip_child);
8443
8444 clip_child->SetClipParent(clip_parent.get());
8445
8446 intervening->SetMasksToBounds(true);
8447 clip_parent->SetMasksToBounds(true);
8448
8449 render_surface->SetForceRenderSurface(true);
8450
8451 gfx::Transform scale_transform;
8452 scale_transform.Scale(2, 2);
8453
8454 gfx::Transform identity_transform;
8455
8456 SetLayerPropertiesForTesting(root.get(),
8457 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388458 gfx::PointF(),
8459 gfx::PointF(),
8460 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578461 true,
[email protected]420fdf6e2013-08-26 20:36:388462 false);
8463 SetLayerPropertiesForTesting(render_surface.get(),
8464 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388465 gfx::PointF(),
8466 gfx::PointF(),
8467 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578468 true,
[email protected]420fdf6e2013-08-26 20:36:388469 false);
8470 SetLayerPropertiesForTesting(clip_parent.get(),
8471 scale_transform,
[email protected]420fdf6e2013-08-26 20:36:388472 gfx::PointF(),
8473 gfx::PointF(1.f, 1.f),
8474 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578475 true,
[email protected]420fdf6e2013-08-26 20:36:388476 false);
8477 SetLayerPropertiesForTesting(intervening.get(),
8478 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388479 gfx::PointF(),
8480 gfx::PointF(1.f, 1.f),
8481 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578482 true,
[email protected]420fdf6e2013-08-26 20:36:388483 false);
8484 SetLayerPropertiesForTesting(clip_child.get(),
8485 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388486 gfx::PointF(),
8487 gfx::PointF(1.f, 1.f),
8488 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578489 true,
[email protected]420fdf6e2013-08-26 20:36:388490 false);
8491
8492 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8493 host->SetRootLayer(root);
8494
8495 ExecuteCalculateDrawProperties(root.get());
8496
8497 ASSERT_TRUE(root->render_surface());
8498 ASSERT_TRUE(render_surface->render_surface());
8499
8500 // Ensure that we've inherited our clip parent's clip and weren't affected
8501 // by the intervening clip layer.
8502 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
8503 clip_parent->clip_rect().ToString());
8504 ASSERT_EQ(clip_parent->clip_rect().ToString(),
8505 clip_child->clip_rect().ToString());
8506 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
8507 intervening->clip_rect().ToString());
8508
8509 // Ensure that the render surface reports a content rect that has been grown
8510 // to accomodate for the clip child.
8511 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
8512 render_surface->render_surface()->content_rect().ToString());
8513
8514 // The above check implies the two below, but they nicely demonstrate that
8515 // we've grown, despite the intervening layer's clip.
8516 ASSERT_TRUE(clip_parent->clip_rect().Contains(
8517 render_surface->render_surface()->content_rect()));
8518 ASSERT_FALSE(intervening->clip_rect().Contains(
8519 render_surface->render_surface()->content_rect()));
8520}
8521
8522TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
8523 // Ensure that intervening render surfaces are not a problem in the basic
8524 // case. In the following tree, both render surfaces should be resized to
8525 // accomodate for the clip child, despite an intervening clip.
8526 //
8527 // root (a render surface)
8528 // + clip_parent (masks to bounds)
8529 // + render_surface1 (sets opacity)
8530 // + intervening (masks to bounds)
8531 // + render_surface2 (also sets opacity)
8532 // + clip_child
8533 //
8534 scoped_refptr<Layer> root = Layer::Create();
8535 scoped_refptr<Layer> clip_parent = Layer::Create();
8536 scoped_refptr<Layer> render_surface1 = Layer::Create();
8537 scoped_refptr<Layer> intervening = Layer::Create();
8538 scoped_refptr<Layer> render_surface2 = Layer::Create();
8539 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8540 make_scoped_refptr(new LayerWithForcedDrawsContent);
8541
8542 root->AddChild(clip_parent);
8543 clip_parent->AddChild(render_surface1);
8544 render_surface1->AddChild(intervening);
8545 intervening->AddChild(render_surface2);
8546 render_surface2->AddChild(clip_child);
8547
8548 clip_child->SetClipParent(clip_parent.get());
8549
8550 intervening->SetMasksToBounds(true);
8551 clip_parent->SetMasksToBounds(true);
8552
8553 render_surface1->SetForceRenderSurface(true);
8554 render_surface2->SetForceRenderSurface(true);
8555
8556 gfx::Transform translation_transform;
8557 translation_transform.Translate(2, 2);
8558
8559 gfx::Transform identity_transform;
8560 SetLayerPropertiesForTesting(root.get(),
8561 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388562 gfx::PointF(),
8563 gfx::PointF(),
8564 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578565 true,
[email protected]420fdf6e2013-08-26 20:36:388566 false);
8567 SetLayerPropertiesForTesting(clip_parent.get(),
8568 translation_transform,
[email protected]420fdf6e2013-08-26 20:36:388569 gfx::PointF(),
8570 gfx::PointF(1.f, 1.f),
8571 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578572 true,
[email protected]420fdf6e2013-08-26 20:36:388573 false);
8574 SetLayerPropertiesForTesting(render_surface1.get(),
8575 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388576 gfx::PointF(),
8577 gfx::PointF(),
8578 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578579 true,
[email protected]420fdf6e2013-08-26 20:36:388580 false);
8581 SetLayerPropertiesForTesting(intervening.get(),
8582 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388583 gfx::PointF(),
8584 gfx::PointF(1.f, 1.f),
8585 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578586 true,
[email protected]420fdf6e2013-08-26 20:36:388587 false);
8588 SetLayerPropertiesForTesting(render_surface2.get(),
8589 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388590 gfx::PointF(),
8591 gfx::PointF(),
8592 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578593 true,
[email protected]420fdf6e2013-08-26 20:36:388594 false);
8595 SetLayerPropertiesForTesting(clip_child.get(),
8596 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388597 gfx::PointF(),
8598 gfx::PointF(-10.f, -10.f),
8599 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578600 true,
[email protected]420fdf6e2013-08-26 20:36:388601 false);
8602
8603 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8604 host->SetRootLayer(root);
8605
8606 ExecuteCalculateDrawProperties(root.get());
8607
8608 EXPECT_TRUE(root->render_surface());
8609 EXPECT_TRUE(render_surface1->render_surface());
8610 EXPECT_TRUE(render_surface2->render_surface());
8611
8612 // Since the render surfaces could have expanded, they should not clip (their
8613 // bounds would no longer be reliable). We should resort to layer clipping
8614 // in this case.
8615 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8616 render_surface1->render_surface()->clip_rect().ToString());
8617 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8618 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8619 render_surface2->render_surface()->clip_rect().ToString());
8620 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8621
8622 // NB: clip rects are in target space.
8623 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8624 render_surface1->clip_rect().ToString());
8625 EXPECT_TRUE(render_surface1->is_clipped());
8626
8627 // This value is inherited from the clipping ancestor layer, 'intervening'.
8628 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8629 render_surface2->clip_rect().ToString());
8630 EXPECT_TRUE(render_surface2->is_clipped());
8631
8632 // The content rects of both render surfaces should both have expanded to
8633 // contain the clip child.
8634 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8635 render_surface1->render_surface()->content_rect().ToString());
8636 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8637 render_surface2->render_surface()->content_rect().ToString());
8638
8639 // The clip child should have inherited the clip parent's clip (projected to
8640 // the right space, of course), and should have the correctly sized visible
8641 // content rect.
8642 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8643 clip_child->clip_rect().ToString());
8644 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
8645 clip_child->visible_content_rect().ToString());
8646 EXPECT_TRUE(clip_child->is_clipped());
8647}
8648
8649TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
8650 // Ensure that intervening render surfaces are not a problem, even if there
8651 // is a scroll involved. Note, we do _not_ have to consider any other sort
8652 // of transform.
8653 //
8654 // root (a render surface)
8655 // + clip_parent (masks to bounds)
8656 // + render_surface1 (sets opacity)
8657 // + intervening (masks to bounds AND scrolls)
8658 // + render_surface2 (also sets opacity)
8659 // + clip_child
8660 //
8661 scoped_refptr<Layer> root = Layer::Create();
8662 scoped_refptr<Layer> clip_parent = Layer::Create();
8663 scoped_refptr<Layer> render_surface1 = Layer::Create();
8664 scoped_refptr<Layer> intervening = Layer::Create();
8665 scoped_refptr<Layer> render_surface2 = Layer::Create();
8666 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8667 make_scoped_refptr(new LayerWithForcedDrawsContent);
8668
8669 root->AddChild(clip_parent);
8670 clip_parent->AddChild(render_surface1);
8671 render_surface1->AddChild(intervening);
8672 intervening->AddChild(render_surface2);
8673 render_surface2->AddChild(clip_child);
8674
8675 clip_child->SetClipParent(clip_parent.get());
8676
8677 intervening->SetMasksToBounds(true);
8678 clip_parent->SetMasksToBounds(true);
[email protected]adeda572014-01-31 00:49:478679 intervening->SetScrollClipLayerId(clip_parent->id());
[email protected]420fdf6e2013-08-26 20:36:388680 intervening->SetScrollOffset(gfx::Vector2d(3, 3));
8681
8682 render_surface1->SetForceRenderSurface(true);
8683 render_surface2->SetForceRenderSurface(true);
8684
8685 gfx::Transform translation_transform;
8686 translation_transform.Translate(2, 2);
8687
8688 gfx::Transform identity_transform;
8689 SetLayerPropertiesForTesting(root.get(),
8690 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388691 gfx::PointF(),
8692 gfx::PointF(),
8693 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578694 true,
[email protected]420fdf6e2013-08-26 20:36:388695 false);
8696 SetLayerPropertiesForTesting(clip_parent.get(),
8697 translation_transform,
[email protected]420fdf6e2013-08-26 20:36:388698 gfx::PointF(),
8699 gfx::PointF(1.f, 1.f),
8700 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578701 true,
[email protected]420fdf6e2013-08-26 20:36:388702 false);
8703 SetLayerPropertiesForTesting(render_surface1.get(),
8704 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388705 gfx::PointF(),
8706 gfx::PointF(),
8707 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578708 true,
[email protected]420fdf6e2013-08-26 20:36:388709 false);
8710 SetLayerPropertiesForTesting(intervening.get(),
8711 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388712 gfx::PointF(),
8713 gfx::PointF(1.f, 1.f),
8714 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578715 true,
[email protected]420fdf6e2013-08-26 20:36:388716 false);
8717 SetLayerPropertiesForTesting(render_surface2.get(),
8718 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388719 gfx::PointF(),
8720 gfx::PointF(),
8721 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578722 true,
[email protected]420fdf6e2013-08-26 20:36:388723 false);
8724 SetLayerPropertiesForTesting(clip_child.get(),
8725 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388726 gfx::PointF(),
8727 gfx::PointF(-10.f, -10.f),
8728 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578729 true,
[email protected]420fdf6e2013-08-26 20:36:388730 false);
8731
8732 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8733 host->SetRootLayer(root);
8734
8735 ExecuteCalculateDrawProperties(root.get());
8736
8737 EXPECT_TRUE(root->render_surface());
8738 EXPECT_TRUE(render_surface1->render_surface());
8739 EXPECT_TRUE(render_surface2->render_surface());
8740
8741 // Since the render surfaces could have expanded, they should not clip (their
8742 // bounds would no longer be reliable). We should resort to layer clipping
8743 // in this case.
8744 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8745 render_surface1->render_surface()->clip_rect().ToString());
8746 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8747 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8748 render_surface2->render_surface()->clip_rect().ToString());
8749 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8750
8751 // NB: clip rects are in target space.
8752 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8753 render_surface1->clip_rect().ToString());
8754 EXPECT_TRUE(render_surface1->is_clipped());
8755
8756 // This value is inherited from the clipping ancestor layer, 'intervening'.
8757 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
8758 render_surface2->clip_rect().ToString());
8759 EXPECT_TRUE(render_surface2->is_clipped());
8760
8761 // The content rects of both render surfaces should both have expanded to
8762 // contain the clip child.
8763 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8764 render_surface1->render_surface()->content_rect().ToString());
8765 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8766 render_surface2->render_surface()->content_rect().ToString());
8767
8768 // The clip child should have inherited the clip parent's clip (projected to
8769 // the right space, of course), and should have the correctly sized visible
8770 // content rect.
8771 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8772 clip_child->clip_rect().ToString());
8773 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
8774 clip_child->visible_content_rect().ToString());
8775 EXPECT_TRUE(clip_child->is_clipped());
8776}
8777
8778TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
8779 // Ensures that descendants of the clip child inherit the correct clip.
8780 //
8781 // root (a render surface)
8782 // + clip_parent (masks to bounds)
8783 // + intervening (masks to bounds)
8784 // + clip_child
8785 // + child
8786 //
8787 scoped_refptr<Layer> root = Layer::Create();
8788 scoped_refptr<Layer> clip_parent = Layer::Create();
8789 scoped_refptr<Layer> intervening = Layer::Create();
8790 scoped_refptr<Layer> clip_child = Layer::Create();
8791 scoped_refptr<LayerWithForcedDrawsContent> child =
8792 make_scoped_refptr(new LayerWithForcedDrawsContent);
8793
8794 root->AddChild(clip_parent);
8795 clip_parent->AddChild(intervening);
8796 intervening->AddChild(clip_child);
8797 clip_child->AddChild(child);
8798
8799 clip_child->SetClipParent(clip_parent.get());
8800
8801 intervening->SetMasksToBounds(true);
8802 clip_parent->SetMasksToBounds(true);
8803
8804 gfx::Transform identity_transform;
8805 SetLayerPropertiesForTesting(root.get(),
8806 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388807 gfx::PointF(),
8808 gfx::PointF(),
8809 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578810 true,
[email protected]420fdf6e2013-08-26 20:36:388811 false);
8812 SetLayerPropertiesForTesting(clip_parent.get(),
8813 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388814 gfx::PointF(),
8815 gfx::PointF(),
8816 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578817 true,
[email protected]420fdf6e2013-08-26 20:36:388818 false);
8819 SetLayerPropertiesForTesting(intervening.get(),
8820 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388821 gfx::PointF(),
8822 gfx::PointF(),
8823 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578824 true,
[email protected]420fdf6e2013-08-26 20:36:388825 false);
8826 SetLayerPropertiesForTesting(clip_child.get(),
8827 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388828 gfx::PointF(),
8829 gfx::PointF(),
8830 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578831 true,
[email protected]420fdf6e2013-08-26 20:36:388832 false);
8833 SetLayerPropertiesForTesting(child.get(),
8834 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388835 gfx::PointF(),
8836 gfx::PointF(),
8837 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578838 true,
[email protected]420fdf6e2013-08-26 20:36:388839 false);
8840
8841 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8842 host->SetRootLayer(root);
8843
8844 ExecuteCalculateDrawProperties(root.get());
8845
8846 EXPECT_TRUE(root->render_surface());
8847
8848 // Neither the clip child nor its descendant should have inherited the clip
8849 // from |intervening|.
8850 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8851 clip_child->clip_rect().ToString());
8852 EXPECT_TRUE(clip_child->is_clipped());
8853 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8854 child->visible_content_rect().ToString());
8855 EXPECT_TRUE(child->is_clipped());
8856}
8857
8858TEST_F(LayerTreeHostCommonTest,
8859 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
8860 // Ensures that non-descendant clip children in the tree do not affect
8861 // render surfaces.
8862 //
8863 // root (a render surface)
8864 // + clip_parent (masks to bounds)
8865 // + render_surface1
8866 // + clip_child
8867 // + render_surface2
8868 // + non_clip_child
8869 //
8870 // In this example render_surface2 should be unaffected by clip_child.
8871 scoped_refptr<Layer> root = Layer::Create();
8872 scoped_refptr<Layer> clip_parent = Layer::Create();
8873 scoped_refptr<Layer> render_surface1 = Layer::Create();
8874 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8875 make_scoped_refptr(new LayerWithForcedDrawsContent);
8876 scoped_refptr<Layer> render_surface2 = Layer::Create();
8877 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
8878 make_scoped_refptr(new LayerWithForcedDrawsContent);
8879
8880 root->AddChild(clip_parent);
8881 clip_parent->AddChild(render_surface1);
8882 render_surface1->AddChild(clip_child);
8883 clip_parent->AddChild(render_surface2);
8884 render_surface2->AddChild(non_clip_child);
8885
8886 clip_child->SetClipParent(clip_parent.get());
8887
8888 clip_parent->SetMasksToBounds(true);
8889 render_surface1->SetMasksToBounds(true);
8890
8891 gfx::Transform identity_transform;
8892 SetLayerPropertiesForTesting(root.get(),
8893 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388894 gfx::PointF(),
8895 gfx::PointF(),
8896 gfx::Size(15, 15),
[email protected]56fffdd2014-02-11 19:50:578897 true,
[email protected]420fdf6e2013-08-26 20:36:388898 false);
8899 SetLayerPropertiesForTesting(clip_parent.get(),
8900 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388901 gfx::PointF(),
8902 gfx::PointF(),
8903 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578904 true,
[email protected]420fdf6e2013-08-26 20:36:388905 false);
8906 SetLayerPropertiesForTesting(render_surface1.get(),
8907 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388908 gfx::PointF(),
8909 gfx::PointF(5, 5),
8910 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578911 true,
[email protected]420fdf6e2013-08-26 20:36:388912 false);
8913 SetLayerPropertiesForTesting(render_surface2.get(),
8914 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388915 gfx::PointF(),
8916 gfx::PointF(),
8917 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578918 true,
[email protected]420fdf6e2013-08-26 20:36:388919 false);
8920 SetLayerPropertiesForTesting(clip_child.get(),
8921 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388922 gfx::PointF(),
8923 gfx::PointF(-1, 1),
8924 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578925 true,
[email protected]420fdf6e2013-08-26 20:36:388926 false);
8927 SetLayerPropertiesForTesting(non_clip_child.get(),
8928 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388929 gfx::PointF(),
8930 gfx::PointF(),
8931 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578932 true,
[email protected]420fdf6e2013-08-26 20:36:388933 false);
8934
8935 render_surface1->SetForceRenderSurface(true);
8936 render_surface2->SetForceRenderSurface(true);
8937
8938 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8939 host->SetRootLayer(root);
8940
8941 ExecuteCalculateDrawProperties(root.get());
8942
8943 EXPECT_TRUE(root->render_surface());
8944 EXPECT_TRUE(render_surface1->render_surface());
8945 EXPECT_TRUE(render_surface2->render_surface());
8946
8947 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8948 render_surface1->clip_rect().ToString());
8949 EXPECT_TRUE(render_surface1->is_clipped());
8950
8951 // The render surface should not clip (it has unclipped descendants), instead
8952 // it should rely on layer clipping.
8953 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8954 render_surface1->render_surface()->clip_rect().ToString());
8955 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8956
8957 // That said, it should have grown to accomodate the unclipped descendant.
8958 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
8959 render_surface1->render_surface()->content_rect().ToString());
8960
8961 // This render surface should clip. It has no unclipped descendants.
8962 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8963 render_surface2->clip_rect().ToString());
8964 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
8965
8966 // It also shouldn't have grown to accomodate the clip child.
8967 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8968 render_surface2->render_surface()->content_rect().ToString());
8969
8970 // Sanity check our num_unclipped_descendants values.
8971 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
8972 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
8973}
8974
[email protected]45948712013-09-27 02:46:488975TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
8976 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458977 TestSharedBitmapManager shared_bitmap_manager;
8978 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]45948712013-09-27 02:46:488979 scoped_ptr<LayerImpl> root =
8980 LayerImpl::Create(host_impl.active_tree(), 12345);
8981 scoped_ptr<LayerImpl> child1 =
8982 LayerImpl::Create(host_impl.active_tree(), 123456);
8983 scoped_ptr<LayerImpl> child2 =
8984 LayerImpl::Create(host_impl.active_tree(), 1234567);
8985 scoped_ptr<LayerImpl> child3 =
8986 LayerImpl::Create(host_impl.active_tree(), 12345678);
8987
8988 gfx::Transform identity_matrix;
8989 gfx::PointF anchor;
8990 gfx::PointF position;
8991 gfx::Size bounds(100, 100);
8992 SetLayerPropertiesForTesting(root.get(),
8993 identity_matrix,
[email protected]45948712013-09-27 02:46:488994 anchor,
8995 position,
8996 bounds,
[email protected]56fffdd2014-02-11 19:50:578997 true,
[email protected]45948712013-09-27 02:46:488998 false);
8999 root->SetDrawsContent(true);
9000
9001 // This layer structure normally forces render surface due to preserves3d
9002 // behavior.
[email protected]45948712013-09-27 02:46:489003 SetLayerPropertiesForTesting(child1.get(),
9004 identity_matrix,
[email protected]45948712013-09-27 02:46:489005 anchor,
9006 position,
9007 bounds,
[email protected]56fffdd2014-02-11 19:50:579008 false,
9009 true);
[email protected]45948712013-09-27 02:46:489010 child1->SetDrawsContent(true);
9011 SetLayerPropertiesForTesting(child2.get(),
9012 identity_matrix,
[email protected]45948712013-09-27 02:46:489013 anchor,
9014 position,
9015 bounds,
[email protected]56fffdd2014-02-11 19:50:579016 true,
[email protected]45948712013-09-27 02:46:489017 false);
9018 child2->SetDrawsContent(true);
9019 SetLayerPropertiesForTesting(child3.get(),
9020 identity_matrix,
[email protected]45948712013-09-27 02:46:489021 anchor,
9022 position,
9023 bounds,
[email protected]56fffdd2014-02-11 19:50:579024 true,
[email protected]45948712013-09-27 02:46:489025 false);
9026 child3->SetDrawsContent(true);
9027
[email protected]56fffdd2014-02-11 19:50:579028 child2->SetIs3dSorted(true);
9029 child3->SetIs3dSorted(true);
9030
[email protected]45948712013-09-27 02:46:489031 child2->AddChild(child3.Pass());
9032 child1->AddChild(child2.Pass());
9033 root->AddChild(child1.Pass());
9034
9035 {
9036 LayerImplList render_surface_layer_list;
9037 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9038 root.get(), root->bounds(), &render_surface_layer_list);
9039 inputs.can_render_to_separate_surface = true;
9040 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9041
9042 EXPECT_EQ(2u, render_surface_layer_list.size());
9043 }
9044
9045 {
9046 LayerImplList render_surface_layer_list;
9047 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9048 root.get(), root->bounds(), &render_surface_layer_list);
9049 inputs.can_render_to_separate_surface = false;
9050 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9051
9052 EXPECT_EQ(1u, render_surface_layer_list.size());
9053 }
9054}
9055
[email protected]a9aa60a82013-08-29 04:28:269056TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
9057 scoped_refptr<Layer> root = Layer::Create();
9058 scoped_refptr<Layer> render_surface = Layer::Create();
9059 scoped_refptr<LayerWithForcedDrawsContent> child =
9060 make_scoped_refptr(new LayerWithForcedDrawsContent);
9061
9062 root->AddChild(render_surface);
9063 render_surface->AddChild(child);
9064
9065 gfx::Transform identity_transform;
9066 SetLayerPropertiesForTesting(root.get(),
9067 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:269068 gfx::PointF(),
9069 gfx::PointF(),
9070 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579071 true,
[email protected]a9aa60a82013-08-29 04:28:269072 false);
9073 SetLayerPropertiesForTesting(render_surface.get(),
9074 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:269075 gfx::PointF(),
9076 gfx::PointF(),
9077 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579078 false,
9079 true);
[email protected]a9aa60a82013-08-29 04:28:269080 SetLayerPropertiesForTesting(child.get(),
9081 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:269082 gfx::PointF(),
9083 gfx::PointF(),
9084 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:579085 true,
[email protected]a9aa60a82013-08-29 04:28:269086 false);
9087
[email protected]56fffdd2014-02-11 19:50:579088 root->SetShouldFlattenTransform(false);
9089 root->SetIs3dSorted(true);
[email protected]a9aa60a82013-08-29 04:28:269090 render_surface->SetDoubleSided(false);
9091 render_surface->SetForceRenderSurface(true);
9092
9093 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9094 host->SetRootLayer(root);
9095
9096 ExecuteCalculateDrawProperties(root.get());
9097
9098 EXPECT_EQ(2u, render_surface_layer_list()->size());
9099 EXPECT_EQ(1u,
9100 render_surface_layer_list()->at(0)
9101 ->render_surface()->layer_list().size());
9102 EXPECT_EQ(1u,
9103 render_surface_layer_list()->at(1)
9104 ->render_surface()->layer_list().size());
9105
9106 gfx::Transform rotation_transform = identity_transform;
9107 rotation_transform.RotateAboutXAxis(180.0);
9108
9109 render_surface->SetTransform(rotation_transform);
9110
9111 ExecuteCalculateDrawProperties(root.get());
9112
9113 EXPECT_EQ(1u, render_surface_layer_list()->size());
9114 EXPECT_EQ(0u,
9115 render_surface_layer_list()->at(0)
9116 ->render_surface()->layer_list().size());
9117}
9118
[email protected]995708c52013-10-17 20:52:599119TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
9120 // Checks that the simple case (being clipped by a scroll parent that would
9121 // have been processed before you anyhow) results in the right clips.
9122 //
9123 // + root
9124 // + scroll_parent_border
9125 // | + scroll_parent_clip
9126 // | + scroll_parent
9127 // + scroll_child
9128 //
9129 scoped_refptr<Layer> root = Layer::Create();
9130 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9131 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9132 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9133 make_scoped_refptr(new LayerWithForcedDrawsContent);
9134 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9135 make_scoped_refptr(new LayerWithForcedDrawsContent);
9136
9137 root->AddChild(scroll_child);
9138
9139 root->AddChild(scroll_parent_border);
9140 scroll_parent_border->AddChild(scroll_parent_clip);
9141 scroll_parent_clip->AddChild(scroll_parent);
9142
9143 scroll_parent_clip->SetMasksToBounds(true);
9144
9145 scroll_child->SetScrollParent(scroll_parent.get());
9146
9147 gfx::Transform identity_transform;
9148 SetLayerPropertiesForTesting(root.get(),
9149 identity_transform,
[email protected]995708c52013-10-17 20:52:599150 gfx::PointF(),
9151 gfx::PointF(),
9152 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579153 true,
[email protected]995708c52013-10-17 20:52:599154 false);
9155 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9156 identity_transform,
[email protected]995708c52013-10-17 20:52:599157 gfx::PointF(),
9158 gfx::PointF(),
9159 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579160 true,
[email protected]995708c52013-10-17 20:52:599161 false);
9162 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9163 identity_transform,
[email protected]995708c52013-10-17 20:52:599164 gfx::PointF(),
9165 gfx::PointF(),
9166 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579167 true,
[email protected]995708c52013-10-17 20:52:599168 false);
9169 SetLayerPropertiesForTesting(scroll_parent.get(),
9170 identity_transform,
[email protected]995708c52013-10-17 20:52:599171 gfx::PointF(),
9172 gfx::PointF(),
9173 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579174 true,
[email protected]995708c52013-10-17 20:52:599175 false);
9176 SetLayerPropertiesForTesting(scroll_child.get(),
9177 identity_transform,
[email protected]995708c52013-10-17 20:52:599178 gfx::PointF(),
9179 gfx::PointF(),
9180 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579181 true,
[email protected]995708c52013-10-17 20:52:599182 false);
9183
9184 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9185 host->SetRootLayer(root);
9186
9187 ExecuteCalculateDrawProperties(root.get());
9188
9189 EXPECT_TRUE(root->render_surface());
9190
9191 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
9192 scroll_child->clip_rect().ToString());
9193 EXPECT_TRUE(scroll_child->is_clipped());
9194}
9195
[email protected]08bdf1b2014-04-16 23:23:299196TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
9197 scoped_refptr<LayerWithForcedDrawsContent> root =
9198 make_scoped_refptr(new LayerWithForcedDrawsContent);
9199 scoped_refptr<LayerWithForcedDrawsContent> parent =
9200 make_scoped_refptr(new LayerWithForcedDrawsContent);
9201 scoped_refptr<LayerWithForcedDrawsContent> child =
9202 make_scoped_refptr(new LayerWithForcedDrawsContent);
9203
9204 root->AddChild(parent);
9205 parent->AddChild(child);
9206
9207 gfx::Transform identity_transform;
9208 SetLayerPropertiesForTesting(root.get(),
9209 identity_transform,
9210 gfx::PointF(),
9211 gfx::PointF(),
9212 gfx::Size(50, 50),
9213 true,
9214 true);
9215 root->SetForceRenderSurface(true);
9216 SetLayerPropertiesForTesting(parent.get(),
9217 identity_transform,
9218 gfx::PointF(),
9219 gfx::PointF(),
9220 gfx::Size(30, 30),
9221 true,
9222 true);
9223 parent->SetForceRenderSurface(true);
9224 SetLayerPropertiesForTesting(child.get(),
9225 identity_transform,
9226 gfx::PointF(),
9227 gfx::PointF(),
9228 gfx::Size(20, 20),
9229 true,
9230 true);
9231 child->SetForceRenderSurface(true);
9232
9233 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9234 host->SetRootLayer(root);
9235
9236 ExecuteCalculateDrawProperties(root.get());
9237
9238 EXPECT_EQ(3u, render_surface_layer_list()->size());
9239
9240 gfx::Transform singular_transform;
9241 singular_transform.Scale3d(
9242 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
9243
9244 child->SetTransform(singular_transform);
9245
9246 ExecuteCalculateDrawProperties(root.get());
9247
9248 EXPECT_EQ(2u, render_surface_layer_list()->size());
9249
9250 // Ensure that the entire subtree under a layer with singular transform does
9251 // not get rendered.
9252 parent->SetTransform(singular_transform);
9253 child->SetTransform(identity_transform);
9254
9255 ExecuteCalculateDrawProperties(root.get());
9256
9257 EXPECT_EQ(1u, render_surface_layer_list()->size());
9258}
9259
[email protected]995708c52013-10-17 20:52:599260TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
9261 // Checks that clipping by a scroll parent that follows you in paint order
9262 // still results in correct clipping.
9263 //
9264 // + root
9265 // + scroll_child
9266 // + scroll_parent_border
9267 // + scroll_parent_clip
9268 // + scroll_parent
9269 //
9270 scoped_refptr<Layer> root = Layer::Create();
9271 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9272 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9273 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9274 make_scoped_refptr(new LayerWithForcedDrawsContent);
9275 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9276 make_scoped_refptr(new LayerWithForcedDrawsContent);
9277
9278 root->AddChild(scroll_parent_border);
9279 scroll_parent_border->AddChild(scroll_parent_clip);
9280 scroll_parent_clip->AddChild(scroll_parent);
9281
9282 root->AddChild(scroll_child);
9283
9284 scroll_parent_clip->SetMasksToBounds(true);
9285
9286 scroll_child->SetScrollParent(scroll_parent.get());
9287
9288 gfx::Transform identity_transform;
9289 SetLayerPropertiesForTesting(root.get(),
9290 identity_transform,
[email protected]995708c52013-10-17 20:52:599291 gfx::PointF(),
9292 gfx::PointF(),
9293 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579294 true,
[email protected]995708c52013-10-17 20:52:599295 false);
9296 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9297 identity_transform,
[email protected]995708c52013-10-17 20:52:599298 gfx::PointF(),
9299 gfx::PointF(),
9300 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579301 true,
[email protected]995708c52013-10-17 20:52:599302 false);
9303 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9304 identity_transform,
[email protected]995708c52013-10-17 20:52:599305 gfx::PointF(),
9306 gfx::PointF(),
9307 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579308 true,
[email protected]995708c52013-10-17 20:52:599309 false);
9310 SetLayerPropertiesForTesting(scroll_parent.get(),
9311 identity_transform,
[email protected]995708c52013-10-17 20:52:599312 gfx::PointF(),
9313 gfx::PointF(),
9314 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579315 true,
[email protected]995708c52013-10-17 20:52:599316 false);
9317 SetLayerPropertiesForTesting(scroll_child.get(),
9318 identity_transform,
[email protected]995708c52013-10-17 20:52:599319 gfx::PointF(),
9320 gfx::PointF(),
9321 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579322 true,
[email protected]995708c52013-10-17 20:52:599323 false);
9324
9325 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9326 host->SetRootLayer(root);
9327
9328 ExecuteCalculateDrawProperties(root.get());
9329
9330 EXPECT_TRUE(root->render_surface());
9331
9332 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
9333 scroll_child->clip_rect().ToString());
9334 EXPECT_TRUE(scroll_child->is_clipped());
9335}
9336
9337TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
9338 // Checks that clipping by a scroll parent and scroll grandparent that follow
9339 // you in paint order still results in correct clipping.
9340 //
9341 // + root
9342 // + scroll_child
9343 // + scroll_parent_border
9344 // | + scroll_parent_clip
9345 // | + scroll_parent
9346 // + scroll_grandparent_border
9347 // + scroll_grandparent_clip
9348 // + scroll_grandparent
9349 //
9350 scoped_refptr<Layer> root = Layer::Create();
9351 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9352 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9353 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9354 make_scoped_refptr(new LayerWithForcedDrawsContent);
9355
9356 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
9357 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
9358 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
9359 make_scoped_refptr(new LayerWithForcedDrawsContent);
9360
9361 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9362 make_scoped_refptr(new LayerWithForcedDrawsContent);
9363
9364 root->AddChild(scroll_child);
9365
9366 root->AddChild(scroll_parent_border);
9367 scroll_parent_border->AddChild(scroll_parent_clip);
9368 scroll_parent_clip->AddChild(scroll_parent);
9369
9370 root->AddChild(scroll_grandparent_border);
9371 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
9372 scroll_grandparent_clip->AddChild(scroll_grandparent);
9373
9374 scroll_parent_clip->SetMasksToBounds(true);
9375 scroll_grandparent_clip->SetMasksToBounds(true);
9376
9377 scroll_child->SetScrollParent(scroll_parent.get());
9378 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
9379
9380 gfx::Transform identity_transform;
9381 SetLayerPropertiesForTesting(root.get(),
9382 identity_transform,
[email protected]995708c52013-10-17 20:52:599383 gfx::PointF(),
9384 gfx::PointF(),
9385 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579386 true,
[email protected]995708c52013-10-17 20:52:599387 false);
9388 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
9389 identity_transform,
[email protected]995708c52013-10-17 20:52:599390 gfx::PointF(),
9391 gfx::PointF(),
9392 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579393 true,
[email protected]995708c52013-10-17 20:52:599394 false);
9395 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
9396 identity_transform,
[email protected]995708c52013-10-17 20:52:599397 gfx::PointF(),
9398 gfx::PointF(),
9399 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:579400 true,
[email protected]995708c52013-10-17 20:52:599401 false);
9402 SetLayerPropertiesForTesting(scroll_grandparent.get(),
9403 identity_transform,
[email protected]995708c52013-10-17 20:52:599404 gfx::PointF(),
9405 gfx::PointF(),
9406 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579407 true,
[email protected]995708c52013-10-17 20:52:599408 false);
9409 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9410 identity_transform,
[email protected]995708c52013-10-17 20:52:599411 gfx::PointF(),
9412 gfx::PointF(),
9413 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579414 true,
[email protected]995708c52013-10-17 20:52:599415 false);
9416 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9417 identity_transform,
[email protected]995708c52013-10-17 20:52:599418 gfx::PointF(),
9419 gfx::PointF(),
9420 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579421 true,
[email protected]995708c52013-10-17 20:52:599422 false);
9423 SetLayerPropertiesForTesting(scroll_parent.get(),
9424 identity_transform,
[email protected]995708c52013-10-17 20:52:599425 gfx::PointF(),
9426 gfx::PointF(),
9427 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579428 true,
[email protected]995708c52013-10-17 20:52:599429 false);
9430 SetLayerPropertiesForTesting(scroll_child.get(),
9431 identity_transform,
[email protected]995708c52013-10-17 20:52:599432 gfx::PointF(),
9433 gfx::PointF(),
9434 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579435 true,
[email protected]995708c52013-10-17 20:52:599436 false);
9437
9438 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9439 host->SetRootLayer(root);
9440
9441 ExecuteCalculateDrawProperties(root.get());
9442
9443 EXPECT_TRUE(root->render_surface());
9444
9445 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
9446 scroll_child->clip_rect().ToString());
9447 EXPECT_TRUE(scroll_child->is_clipped());
9448
9449 // Despite the fact that we visited the above layers out of order to get the
9450 // correct clip, the layer lists should be unaffected.
9451 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
9452 EXPECT_EQ(scroll_child.get(),
9453 root->render_surface()->layer_list().at(0));
9454 EXPECT_EQ(scroll_parent.get(),
9455 root->render_surface()->layer_list().at(1));
9456 EXPECT_EQ(scroll_grandparent.get(),
9457 root->render_surface()->layer_list().at(2));
9458}
9459
9460TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
9461 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:229462 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:599463 // + root
9464 // + scroll_child
9465 // + scroll_parent_border
9466 // + scroll_parent_clip
9467 // + scroll_parent
9468 // + render_surface1
9469 // + scroll_grandparent_border
9470 // + scroll_grandparent_clip
9471 // + scroll_grandparent
9472 // + render_surface2
9473 //
[email protected]44d8e84c2013-10-19 19:13:229474 scoped_refptr<LayerWithForcedDrawsContent> root =
9475 make_scoped_refptr(new LayerWithForcedDrawsContent);
[email protected]995708c52013-10-17 20:52:599476
9477 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9478 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9479 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9480 make_scoped_refptr(new LayerWithForcedDrawsContent);
9481 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
9482 make_scoped_refptr(new LayerWithForcedDrawsContent);
9483
9484 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
9485 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
9486 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
9487 make_scoped_refptr(new LayerWithForcedDrawsContent);
9488 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
9489 make_scoped_refptr(new LayerWithForcedDrawsContent);
9490
9491 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9492 make_scoped_refptr(new LayerWithForcedDrawsContent);
9493
9494 root->AddChild(scroll_child);
9495
9496 root->AddChild(scroll_parent_border);
9497 scroll_parent_border->AddChild(scroll_parent_clip);
9498 scroll_parent_clip->AddChild(scroll_parent);
9499 scroll_parent->AddChild(render_surface2);
9500
9501 root->AddChild(scroll_grandparent_border);
9502 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
9503 scroll_grandparent_clip->AddChild(scroll_grandparent);
9504 scroll_grandparent->AddChild(render_surface1);
9505
9506 scroll_parent_clip->SetMasksToBounds(true);
9507 scroll_grandparent_clip->SetMasksToBounds(true);
9508
9509 scroll_child->SetScrollParent(scroll_parent.get());
9510 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
9511
9512 render_surface1->SetForceRenderSurface(true);
9513 render_surface2->SetForceRenderSurface(true);
9514
9515 gfx::Transform identity_transform;
9516 SetLayerPropertiesForTesting(root.get(),
9517 identity_transform,
[email protected]995708c52013-10-17 20:52:599518 gfx::PointF(),
9519 gfx::PointF(),
9520 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579521 true,
[email protected]995708c52013-10-17 20:52:599522 false);
9523 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
9524 identity_transform,
[email protected]995708c52013-10-17 20:52:599525 gfx::PointF(),
9526 gfx::PointF(),
9527 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579528 true,
[email protected]995708c52013-10-17 20:52:599529 false);
9530 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
9531 identity_transform,
[email protected]995708c52013-10-17 20:52:599532 gfx::PointF(),
9533 gfx::PointF(),
9534 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:579535 true,
[email protected]995708c52013-10-17 20:52:599536 false);
9537 SetLayerPropertiesForTesting(scroll_grandparent.get(),
9538 identity_transform,
[email protected]995708c52013-10-17 20:52:599539 gfx::PointF(),
9540 gfx::PointF(),
9541 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579542 true,
[email protected]995708c52013-10-17 20:52:599543 false);
9544 SetLayerPropertiesForTesting(render_surface1.get(),
9545 identity_transform,
[email protected]995708c52013-10-17 20:52:599546 gfx::PointF(),
9547 gfx::PointF(),
9548 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579549 true,
[email protected]995708c52013-10-17 20:52:599550 false);
9551 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9552 identity_transform,
[email protected]995708c52013-10-17 20:52:599553 gfx::PointF(),
9554 gfx::PointF(),
9555 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579556 true,
[email protected]995708c52013-10-17 20:52:599557 false);
9558 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9559 identity_transform,
[email protected]995708c52013-10-17 20:52:599560 gfx::PointF(),
9561 gfx::PointF(),
9562 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579563 true,
[email protected]995708c52013-10-17 20:52:599564 false);
9565 SetLayerPropertiesForTesting(scroll_parent.get(),
9566 identity_transform,
[email protected]995708c52013-10-17 20:52:599567 gfx::PointF(),
9568 gfx::PointF(),
9569 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579570 true,
[email protected]995708c52013-10-17 20:52:599571 false);
9572 SetLayerPropertiesForTesting(render_surface2.get(),
9573 identity_transform,
[email protected]995708c52013-10-17 20:52:599574 gfx::PointF(),
9575 gfx::PointF(),
9576 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579577 true,
[email protected]995708c52013-10-17 20:52:599578 false);
9579 SetLayerPropertiesForTesting(scroll_child.get(),
9580 identity_transform,
[email protected]995708c52013-10-17 20:52:599581 gfx::PointF(),
9582 gfx::PointF(),
9583 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579584 true,
[email protected]995708c52013-10-17 20:52:599585 false);
9586
9587 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9588 host->SetRootLayer(root);
9589
9590 RenderSurfaceLayerList render_surface_layer_list;
9591 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
9592 root.get(),
9593 root->bounds(),
9594 identity_transform,
9595 &render_surface_layer_list);
9596
9597 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9598
9599 EXPECT_TRUE(root->render_surface());
9600
9601 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
9602 scroll_child->clip_rect().ToString());
9603 EXPECT_TRUE(scroll_child->is_clipped());
9604
9605 // Despite the fact that we had to process the layers out of order to get the
9606 // right clip, our render_surface_layer_list's order should be unaffected.
9607 EXPECT_EQ(3u, render_surface_layer_list.size());
9608 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
9609 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
9610 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
[email protected]44d8e84c2013-10-19 19:13:229611 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
9612 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
9613 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:599614}
9615
9616TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) {
9617 // We rearrange layer list contributions if we have to visit children out of
9618 // order, but it should be a 'stable' rearrangement. That is, the layer list
9619 // additions for a single layer should not be reordered, though their position
9620 // wrt to the contributions due to a sibling may vary.
9621 //
9622 // + root
9623 // + scroll_child
9624 // + top_content
9625 // + bottom_content
9626 // + scroll_parent_border
9627 // + scroll_parent_clip
9628 // + scroll_parent
9629 //
9630 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:459631 TestSharedBitmapManager shared_bitmap_manager;
9632 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]995708c52013-10-17 20:52:599633 host_impl.CreatePendingTree();
9634 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9635 scoped_ptr<LayerImpl> scroll_parent_border =
9636 LayerImpl::Create(host_impl.active_tree(), 2);
9637 scoped_ptr<LayerImpl> scroll_parent_clip =
9638 LayerImpl::Create(host_impl.active_tree(), 3);
9639 scoped_ptr<LayerImpl> scroll_parent =
9640 LayerImpl::Create(host_impl.active_tree(), 4);
9641 scoped_ptr<LayerImpl> scroll_child =
9642 LayerImpl::Create(host_impl.active_tree(), 5);
9643 scoped_ptr<LayerImpl> bottom_content =
9644 LayerImpl::Create(host_impl.active_tree(), 6);
9645 scoped_ptr<LayerImpl> top_content =
9646 LayerImpl::Create(host_impl.active_tree(), 7);
9647
9648 scroll_parent_clip->SetMasksToBounds(true);
9649
9650 scroll_child->SetScrollParent(scroll_parent.get());
9651 scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>);
9652 scroll_children->insert(scroll_child.get());
9653 scroll_parent->SetScrollChildren(scroll_children.release());
9654
9655 scroll_child->SetDrawsContent(true);
9656 scroll_parent->SetDrawsContent(true);
9657 top_content->SetDrawsContent(true);
9658 bottom_content->SetDrawsContent(true);
9659
9660 gfx::Transform identity_transform;
9661 gfx::Transform top_transform;
9662 top_transform.Translate3d(0.0, 0.0, 5.0);
9663 gfx::Transform bottom_transform;
9664 bottom_transform.Translate3d(0.0, 0.0, 3.0);
9665
9666 SetLayerPropertiesForTesting(root.get(),
9667 identity_transform,
[email protected]995708c52013-10-17 20:52:599668 gfx::PointF(),
9669 gfx::PointF(),
9670 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579671 true,
[email protected]995708c52013-10-17 20:52:599672 false);
9673 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9674 identity_transform,
[email protected]995708c52013-10-17 20:52:599675 gfx::PointF(),
9676 gfx::PointF(),
9677 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579678 true,
[email protected]995708c52013-10-17 20:52:599679 false);
9680 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9681 identity_transform,
[email protected]995708c52013-10-17 20:52:599682 gfx::PointF(),
9683 gfx::PointF(),
9684 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579685 true,
[email protected]995708c52013-10-17 20:52:599686 false);
9687 SetLayerPropertiesForTesting(scroll_parent.get(),
9688 identity_transform,
[email protected]995708c52013-10-17 20:52:599689 gfx::PointF(),
9690 gfx::PointF(),
9691 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579692 true,
[email protected]995708c52013-10-17 20:52:599693 false);
9694 SetLayerPropertiesForTesting(scroll_child.get(),
9695 identity_transform,
[email protected]995708c52013-10-17 20:52:599696 gfx::PointF(),
9697 gfx::PointF(),
9698 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579699 true,
[email protected]995708c52013-10-17 20:52:599700 false);
9701 SetLayerPropertiesForTesting(top_content.get(),
9702 top_transform,
[email protected]995708c52013-10-17 20:52:599703 gfx::PointF(),
9704 gfx::PointF(),
9705 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579706 false,
9707 true);
[email protected]995708c52013-10-17 20:52:599708 SetLayerPropertiesForTesting(bottom_content.get(),
9709 bottom_transform,
[email protected]995708c52013-10-17 20:52:599710 gfx::PointF(),
9711 gfx::PointF(),
9712 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579713 false,
9714 true);
[email protected]995708c52013-10-17 20:52:599715
[email protected]56fffdd2014-02-11 19:50:579716 scroll_child->SetShouldFlattenTransform(false);
9717 scroll_child->SetIs3dSorted(true);
[email protected]995708c52013-10-17 20:52:599718
9719 scroll_child->AddChild(top_content.Pass());
9720 scroll_child->AddChild(bottom_content.Pass());
9721 root->AddChild(scroll_child.Pass());
9722
9723 scroll_parent_clip->AddChild(scroll_parent.Pass());
9724 scroll_parent_border->AddChild(scroll_parent_clip.Pass());
9725 root->AddChild(scroll_parent_border.Pass());
9726
9727 LayerImplList render_surface_layer_list;
9728 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9729 root.get(), root->bounds(), &render_surface_layer_list);
9730
9731 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9732
9733 EXPECT_TRUE(root->render_surface());
9734
9735 // If we don't sort by depth and let the layers get added in the order they
9736 // would normally be visited in, then layers 6 and 7 will be out of order. In
9737 // other words, although we've had to shift 5, 6, and 7 to appear before 4
9738 // in the list (because of the scroll parent relationship), this should not
9739 // have an effect on the the order of 5, 6, and 7 (which had been reordered
9740 // due to layer sorting).
9741 EXPECT_EQ(4u, root->render_surface()->layer_list().size());
9742 EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id());
9743 EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id());
9744 EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id());
9745 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
9746}
9747
[email protected]d81752b2013-10-25 08:32:239748TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
9749 // This test verifies that a scrolling layer that gets snapped to
9750 // integer coordinates doesn't move a fixed position child.
9751 //
9752 // + root
9753 // + container
9754 // + scroller
9755 // + fixed
9756 //
9757 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:459758 TestSharedBitmapManager shared_bitmap_manager;
9759 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]d81752b2013-10-25 08:32:239760 host_impl.CreatePendingTree();
9761 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9762 scoped_ptr<LayerImpl> container =
9763 LayerImpl::Create(host_impl.active_tree(), 2);
9764 LayerImpl* container_layer = container.get();
9765 scoped_ptr<LayerImpl> scroller =
9766 LayerImpl::Create(host_impl.active_tree(), 3);
9767 LayerImpl* scroll_layer = scroller.get();
9768 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
9769 LayerImpl* fixed_layer = fixed.get();
9770
9771 container->SetIsContainerForFixedPositionLayers(true);
9772
9773 LayerPositionConstraint constraint;
9774 constraint.set_is_fixed_position(true);
9775 fixed->SetPositionConstraint(constraint);
9776
[email protected]adeda572014-01-31 00:49:479777 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:239778
9779 gfx::Transform identity_transform;
9780 gfx::Transform container_transform;
9781 container_transform.Translate3d(10.0, 20.0, 0.0);
9782 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
9783
9784 SetLayerPropertiesForTesting(root.get(),
9785 identity_transform,
[email protected]d81752b2013-10-25 08:32:239786 gfx::PointF(),
9787 gfx::PointF(),
9788 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579789 true,
[email protected]d81752b2013-10-25 08:32:239790 false);
9791 SetLayerPropertiesForTesting(container.get(),
9792 container_transform,
[email protected]d81752b2013-10-25 08:32:239793 gfx::PointF(),
9794 gfx::PointF(),
9795 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579796 true,
[email protected]d81752b2013-10-25 08:32:239797 false);
9798 SetLayerPropertiesForTesting(scroller.get(),
9799 identity_transform,
[email protected]d81752b2013-10-25 08:32:239800 gfx::PointF(),
9801 gfx::PointF(),
9802 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579803 true,
[email protected]d81752b2013-10-25 08:32:239804 false);
9805 SetLayerPropertiesForTesting(fixed.get(),
9806 identity_transform,
[email protected]d81752b2013-10-25 08:32:239807 gfx::PointF(),
9808 gfx::PointF(),
9809 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579810 true,
[email protected]d81752b2013-10-25 08:32:239811 false);
9812
9813 scroller->AddChild(fixed.Pass());
9814 container->AddChild(scroller.Pass());
9815 root->AddChild(container.Pass());
9816
9817 // Rounded to integers already.
9818 {
9819 gfx::Vector2dF scroll_delta(3.0, 5.0);
9820 scroll_layer->SetScrollDelta(scroll_delta);
9821
9822 LayerImplList render_surface_layer_list;
9823 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9824 root.get(), root->bounds(), &render_surface_layer_list);
9825 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9826
9827 EXPECT_TRANSFORMATION_MATRIX_EQ(
9828 container_layer->draw_properties().screen_space_transform,
9829 fixed_layer->draw_properties().screen_space_transform);
9830 EXPECT_VECTOR_EQ(
9831 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9832 container_offset);
9833 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
9834 .screen_space_transform.To2dTranslation(),
9835 container_offset - scroll_delta);
9836 }
9837
9838 // Scroll delta requiring rounding.
9839 {
9840 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
9841 scroll_layer->SetScrollDelta(scroll_delta);
9842
9843 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
9844
9845 LayerImplList render_surface_layer_list;
9846 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9847 root.get(), root->bounds(), &render_surface_layer_list);
9848 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9849
9850 EXPECT_TRANSFORMATION_MATRIX_EQ(
9851 container_layer->draw_properties().screen_space_transform,
9852 fixed_layer->draw_properties().screen_space_transform);
9853 EXPECT_VECTOR_EQ(
9854 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9855 container_offset);
9856 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
9857 .screen_space_transform.To2dTranslation(),
9858 container_offset - rounded_scroll_delta);
9859 }
[email protected]cf15ad7b2014-04-02 03:59:269860
9861 // Scale is applied earlier in the tree.
9862 {
9863 gfx::Transform scaled_container_transform = container_transform;
9864 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
9865 container_layer->SetTransform(scaled_container_transform);
9866
9867 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
9868 scroll_layer->SetScrollDelta(scroll_delta);
9869
9870 LayerImplList render_surface_layer_list;
9871 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9872 root.get(), root->bounds(), &render_surface_layer_list);
9873 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9874
9875 EXPECT_TRANSFORMATION_MATRIX_EQ(
9876 container_layer->draw_properties().screen_space_transform,
9877 fixed_layer->draw_properties().screen_space_transform);
9878 EXPECT_VECTOR_EQ(
9879 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9880 container_offset);
9881
9882 container_layer->SetTransform(container_transform);
9883 }
9884
9885 // Scale is applied on the scroll layer itself.
9886 {
9887 gfx::Transform scale_transform;
9888 scale_transform.Scale3d(3.0, 3.0, 1.0);
9889 scroll_layer->SetTransform(scale_transform);
9890
9891 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
9892 scroll_layer->SetScrollDelta(scroll_delta);
9893
9894 LayerImplList render_surface_layer_list;
9895 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9896 root.get(), root->bounds(), &render_surface_layer_list);
9897 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9898
9899 EXPECT_VECTOR_EQ(
9900 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9901 container_offset);
9902
9903 scroll_layer->SetTransform(identity_transform);
9904 }
[email protected]d81752b2013-10-25 08:32:239905}
9906
[email protected]1c3626e2014-04-09 17:49:229907class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
9908 public:
9909 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
9910 LayerTreeImpl* tree_impl,
9911 int id) {
9912 return make_scoped_ptr(
9913 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
9914 }
9915
9916 virtual ~AnimationScaleFactorTrackingLayerImpl() {}
9917
9918 virtual void CalculateContentsScale(float ideal_contents_scale,
9919 float device_scale_factor,
9920 float page_scale_factor,
9921 float maximum_animation_contents_scale,
9922 bool animating_transform_to_screen,
9923 float* contents_scale_x,
9924 float* contents_scale_y,
9925 gfx::Size* content_bounds) OVERRIDE {
9926 last_maximum_animation_contents_scale_ = maximum_animation_contents_scale;
9927 LayerImpl::CalculateContentsScale(ideal_contents_scale,
9928 device_scale_factor,
9929 page_scale_factor,
9930 maximum_animation_contents_scale,
9931 animating_transform_to_screen,
9932 contents_scale_x,
9933 contents_scale_y,
9934 content_bounds);
9935 }
9936
9937 float last_maximum_animation_contents_scale() {
9938 return last_maximum_animation_contents_scale_;
9939 }
9940
9941 private:
9942 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
9943 int id)
9944 : LayerImpl(tree_impl, id), last_maximum_animation_contents_scale_(0.f) {
9945 SetDrawsContent(true);
9946 }
9947
9948 float last_maximum_animation_contents_scale_;
9949};
9950
9951TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
9952 FakeImplProxy proxy;
9953 TestSharedBitmapManager shared_bitmap_manager;
9954 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
9955 gfx::Transform identity_matrix;
9956 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
9957 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
9958 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
9959 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
9960 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
9961 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
9962 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
9963 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
9964
9965 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
9966 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
9967 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
9968
9969 child->AddChild(grand_child.PassAs<LayerImpl>());
9970 parent->AddChild(child.PassAs<LayerImpl>());
9971 grand_parent->AddChild(parent.PassAs<LayerImpl>());
9972
9973 SetLayerPropertiesForTesting(grand_parent.get(),
9974 identity_matrix,
9975 gfx::PointF(),
9976 gfx::PointF(),
9977 gfx::Size(1, 2),
9978 true,
9979 false);
9980 SetLayerPropertiesForTesting(parent_raw,
9981 identity_matrix,
9982 gfx::PointF(),
9983 gfx::PointF(),
9984 gfx::Size(1, 2),
9985 true,
9986 false);
9987 SetLayerPropertiesForTesting(child_raw,
9988 identity_matrix,
9989 gfx::PointF(),
9990 gfx::PointF(),
9991 gfx::Size(1, 2),
9992 true,
9993 false);
9994 SetLayerPropertiesForTesting(grand_child_raw,
9995 identity_matrix,
9996 gfx::PointF(),
9997 gfx::PointF(),
9998 gfx::Size(1, 2),
9999 true,
10000 false);
10001
10002 ExecuteCalculateDrawProperties(grand_parent.get());
10003
10004 // No layers have animations.
10005 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10006 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10007 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10008 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10009
10010 TransformOperations translation;
10011 translation.AppendTranslate(1.f, 2.f, 3.f);
10012
10013 AddAnimatedTransformToLayer(
10014 parent_raw, 1.0, TransformOperations(), translation);
10015
10016 // No layers have scale-affecting animations.
10017 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10018 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10019 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10020 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10021
10022 TransformOperations scale;
10023 scale.AppendScale(5.f, 4.f, 3.f);
10024
10025 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
10026 ExecuteCalculateDrawProperties(grand_parent.get());
10027
10028 // Only |child| has a scale-affecting animation.
10029 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10030 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10031 EXPECT_EQ(5.f, child_raw->last_maximum_animation_contents_scale());
10032 EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_contents_scale());
10033
10034 AddAnimatedTransformToLayer(
10035 grand_parent.get(), 1.0, TransformOperations(), scale);
10036 ExecuteCalculateDrawProperties(grand_parent.get());
10037
10038 // |grand_parent| and |child| have scale-affecting animations.
10039 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale());
10040 EXPECT_EQ(5.f, parent_raw->last_maximum_animation_contents_scale());
10041 // We don't support combining animated scales from two nodes; 0.f means
10042 // that the maximum scale could not be computed.
10043 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10044 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10045
10046 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
10047 ExecuteCalculateDrawProperties(grand_parent.get());
10048
10049 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
10050 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale());
10051 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10052 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10053 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10054
10055 grand_parent->layer_animation_controller()->AbortAnimations(
10056 Animation::Transform);
10057 parent_raw->layer_animation_controller()->AbortAnimations(
10058 Animation::Transform);
10059 child_raw->layer_animation_controller()->AbortAnimations(
10060 Animation::Transform);
10061
10062 TransformOperations perspective;
10063 perspective.AppendPerspective(10.f);
10064
10065 AddAnimatedTransformToLayer(
10066 child_raw, 1.0, TransformOperations(), perspective);
10067 ExecuteCalculateDrawProperties(grand_parent.get());
10068
10069 // |child| has a scale-affecting animation but computing the maximum of this
10070 // animation is not supported.
10071 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10072 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10073 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10074 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10075
10076 child_raw->layer_animation_controller()->AbortAnimations(
10077 Animation::Transform);
10078
10079 gfx::Transform scale_matrix;
10080 scale_matrix.Scale(1.f, 2.f);
10081 grand_parent->SetTransform(scale_matrix);
10082 parent_raw->SetTransform(scale_matrix);
10083 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
10084 ExecuteCalculateDrawProperties(grand_parent.get());
10085
10086 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
10087 // animation with maximum scale 5.f.
10088 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10089 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale());
10090 EXPECT_EQ(10.f, child_raw->last_maximum_animation_contents_scale());
10091 EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_contents_scale());
10092
10093 gfx::Transform perspective_matrix;
10094 perspective_matrix.ApplyPerspectiveDepth(2.f);
10095 child_raw->SetTransform(perspective_matrix);
10096 ExecuteCalculateDrawProperties(grand_parent.get());
10097
10098 // |child| has a transform that's neither a translation nor a scale.
10099 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10100 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale());
10101 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10102 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10103
10104 parent_raw->SetTransform(perspective_matrix);
10105 ExecuteCalculateDrawProperties(grand_parent.get());
10106
10107 // |parent| and |child| have transforms that are neither translations nor
10108 // scales.
10109 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10110 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10111 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10112 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10113
10114 parent_raw->SetTransform(identity_matrix);
10115 child_raw->SetTransform(identity_matrix);
10116 grand_parent->SetTransform(perspective_matrix);
10117
10118 ExecuteCalculateDrawProperties(grand_parent.get());
10119
10120 // |grand_parent| has a transform that's neither a translation nor a scale.
10121 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
10122 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
10123 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
10124 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
10125}
10126
[email protected]ba565742012-11-10 09:29:4810127} // namespace
10128} // namespace cc