blob: 749560dc1422fa7984008277adb8710c592e35f5 [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]681ccff2013-03-18 06:13:5210#include "cc/base/math_util.h"
[email protected]cc3cfaa2013-03-18 09:05:5211#include "cc/layers/content_layer.h"
12#include "cc/layers/content_layer_client.h"
13#include "cc/layers/heads_up_display_layer_impl.h"
14#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5915#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5216#include "cc/layers/layer_impl.h"
[email protected]50761e92013-03-29 20:51:2817#include "cc/layers/render_surface.h"
18#include "cc/layers/render_surface_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4519#include "cc/output/copy_output_request.h"
20#include "cc/output/copy_output_result.h"
[email protected]101441ce2012-10-16 01:45:0321#include "cc/test/animation_test_common.h"
[email protected]586d51ed2012-12-07 20:31:4522#include "cc/test/fake_impl_proxy.h"
[email protected]d600df7d2013-08-03 02:34:2823#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4524#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]101441ce2012-10-16 01:45:0325#include "cc/test/geometry_test_utils.h"
[email protected]556fd292013-03-18 08:03:0426#include "cc/trees/layer_tree_impl.h"
27#include "cc/trees/proxy.h"
28#include "cc/trees/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:1829#include "testing/gmock/include/gmock/gmock.h"
30#include "testing/gtest/include/gtest/gtest.h"
[email protected]93698c12012-12-07 00:43:5631#include "ui/gfx/quad_f.h"
32#include "ui/gfx/size_conversions.h"
[email protected]c8686a02012-11-27 08:29:0033#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1434
[email protected]ba565742012-11-10 09:29:4835namespace cc {
[email protected]94f206c12012-08-25 00:09:1436namespace {
37
[email protected]989386c2013-07-18 21:37:2338class LayerTreeHostCommonTestBase {
39 protected:
40 template <typename LayerType>
41 void SetLayerPropertiesForTestingInternal(
42 LayerType* layer,
43 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:4744 const gfx::PointF& anchor,
45 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:2646 const gfx::Size& bounds,
[email protected]56fffdd2014-02-11 19:50:5747 bool flatten_transform,
48 bool is_3d_sorted) {
[email protected]989386c2013-07-18 21:37:2349 layer->SetTransform(transform);
[email protected]989386c2013-07-18 21:37:2350 layer->SetAnchorPoint(anchor);
51 layer->SetPosition(position);
52 layer->SetBounds(bounds);
[email protected]56fffdd2014-02-11 19:50:5753 layer->SetShouldFlattenTransform(flatten_transform);
54 layer->SetIs3dSorted(is_3d_sorted);
[email protected]989386c2013-07-18 21:37:2355 }
[email protected]94f206c12012-08-25 00:09:1456
[email protected]989386c2013-07-18 21:37:2357 void SetLayerPropertiesForTesting(Layer* layer,
58 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:4759 const gfx::PointF& anchor,
60 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:2661 const gfx::Size& bounds,
[email protected]56fffdd2014-02-11 19:50:5762 bool flatten_transform,
63 bool is_3d_sorted) {
[email protected]989386c2013-07-18 21:37:2364 SetLayerPropertiesForTestingInternal<Layer>(layer,
65 transform,
[email protected]989386c2013-07-18 21:37:2366 anchor,
67 position,
68 bounds,
[email protected]56fffdd2014-02-11 19:50:5769 flatten_transform,
70 is_3d_sorted);
[email protected]989386c2013-07-18 21:37:2371 }
[email protected]94f206c12012-08-25 00:09:1472
[email protected]989386c2013-07-18 21:37:2373 void SetLayerPropertiesForTesting(LayerImpl* layer,
74 const gfx::Transform& transform,
[email protected]14bc5d682014-01-17 07:26:4775 const gfx::PointF& anchor,
76 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:2677 const gfx::Size& bounds,
[email protected]56fffdd2014-02-11 19:50:5778 bool flatten_transform,
79 bool is_3d_sorted) {
[email protected]989386c2013-07-18 21:37:2380 SetLayerPropertiesForTestingInternal<LayerImpl>(layer,
81 transform,
[email protected]989386c2013-07-18 21:37:2382 anchor,
83 position,
84 bounds,
[email protected]56fffdd2014-02-11 19:50:5785 flatten_transform,
86 is_3d_sorted);
[email protected]989386c2013-07-18 21:37:2387 layer->SetContentBounds(bounds);
88 }
[email protected]94f206c12012-08-25 00:09:1489
[email protected]989386c2013-07-18 21:37:2390 void ExecuteCalculateDrawProperties(Layer* root_layer,
91 float device_scale_factor,
92 float page_scale_factor,
93 Layer* page_scale_application_layer,
94 bool can_use_lcd_text) {
95 EXPECT_TRUE(page_scale_application_layer || (page_scale_factor == 1.f));
96 gfx::Transform identity_matrix;
[email protected]989386c2013-07-18 21:37:2397 gfx::Size device_viewport_size =
98 gfx::Size(root_layer->bounds().width() * device_scale_factor,
99 root_layer->bounds().height() * device_scale_factor);
[email protected]94f206c12012-08-25 00:09:14100
[email protected]989386c2013-07-18 21:37:23101 render_surface_layer_list_.reset(new RenderSurfaceLayerList);
[email protected]94f206c12012-08-25 00:09:14102
[email protected]989386c2013-07-18 21:37:23103 // We are probably not testing what is intended if the root_layer bounds are
104 // empty.
105 DCHECK(!root_layer->bounds().IsEmpty());
[email protected]7aad55f2013-07-26 11:25:53106 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
107 root_layer, device_viewport_size, render_surface_layer_list_.get());
108 inputs.device_scale_factor = device_scale_factor;
109 inputs.page_scale_factor = page_scale_factor;
110 inputs.page_scale_application_layer = page_scale_application_layer;
111 inputs.can_use_lcd_text = can_use_lcd_text;
112 inputs.can_adjust_raster_scales = true;
113 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:23114 }
[email protected]94f206c12012-08-25 00:09:14115
[email protected]989386c2013-07-18 21:37:23116 void ExecuteCalculateDrawProperties(LayerImpl* root_layer,
117 float device_scale_factor,
118 float page_scale_factor,
119 LayerImpl* page_scale_application_layer,
120 bool can_use_lcd_text) {
121 gfx::Transform identity_matrix;
122 LayerImplList dummy_render_surface_layer_list;
[email protected]989386c2013-07-18 21:37:23123 gfx::Size device_viewport_size =
124 gfx::Size(root_layer->bounds().width() * device_scale_factor,
125 root_layer->bounds().height() * device_scale_factor);
[email protected]94f206c12012-08-25 00:09:14126
[email protected]989386c2013-07-18 21:37:23127 // We are probably not testing what is intended if the root_layer bounds are
128 // empty.
129 DCHECK(!root_layer->bounds().IsEmpty());
[email protected]7aad55f2013-07-26 11:25:53130 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
131 root_layer, device_viewport_size, &dummy_render_surface_layer_list);
132 inputs.device_scale_factor = device_scale_factor;
133 inputs.page_scale_factor = page_scale_factor;
134 inputs.page_scale_application_layer = page_scale_application_layer;
135 inputs.can_use_lcd_text = can_use_lcd_text;
136 inputs.can_adjust_raster_scales = true;
137 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:23138 }
[email protected]94f206c12012-08-25 00:09:14139
[email protected]989386c2013-07-18 21:37:23140 template <class LayerType>
141 void ExecuteCalculateDrawProperties(LayerType* root_layer) {
142 LayerType* page_scale_application_layer = NULL;
143 ExecuteCalculateDrawProperties(
144 root_layer, 1.f, 1.f, page_scale_application_layer, false);
145 }
[email protected]94f206c12012-08-25 00:09:14146
[email protected]989386c2013-07-18 21:37:23147 template <class LayerType>
148 void ExecuteCalculateDrawProperties(LayerType* root_layer,
149 float device_scale_factor) {
150 LayerType* page_scale_application_layer = NULL;
151 ExecuteCalculateDrawProperties(root_layer,
152 device_scale_factor,
153 1.f,
154 page_scale_application_layer,
155 false);
156 }
157
158 template <class LayerType>
159 void ExecuteCalculateDrawProperties(LayerType* root_layer,
160 float device_scale_factor,
161 float page_scale_factor,
162 LayerType* page_scale_application_layer) {
163 ExecuteCalculateDrawProperties(root_layer,
164 device_scale_factor,
165 page_scale_factor,
166 page_scale_application_layer,
167 false);
168 }
169
[email protected]a9aa60a82013-08-29 04:28:26170 RenderSurfaceLayerList* render_surface_layer_list() const {
171 return render_surface_layer_list_.get();
172 }
173
[email protected]989386c2013-07-18 21:37:23174 private:
175 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
176};
177
178class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
179 public testing::Test {
180};
[email protected]94f206c12012-08-25 00:09:14181
[email protected]96baf3e2012-10-22 23:09:55182class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:32183 public:
[email protected]d5754282014-04-09 00:43:29184 LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {}
[email protected]94f206c12012-08-25 00:09:14185
[email protected]fb661802013-03-25 01:59:32186 virtual bool DrawsContent() const OVERRIDE;
[email protected]d5754282014-04-09 00:43:29187 virtual void CalculateContentsScale(float ideal_contents_scale,
188 float device_scale_factor,
189 float page_scale_factor,
190 bool animating_transform_to_screen,
191 float* contents_scale_x,
192 float* contents_scale_y,
193 gfx::Size* content_bounds) OVERRIDE;
194
195 float last_device_scale_factor() const { return last_device_scale_factor_; }
[email protected]d58499a2012-10-09 22:27:47196
[email protected]fb661802013-03-25 01:59:32197 private:
198 virtual ~LayerWithForcedDrawsContent() {}
[email protected]d5754282014-04-09 00:43:29199
200 // Parameters from last CalculateContentsScale.
201 float last_device_scale_factor_;
[email protected]94f206c12012-08-25 00:09:14202};
203
[email protected]fb661802013-03-25 01:59:32204bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:44205
[email protected]d5754282014-04-09 00:43:29206void LayerWithForcedDrawsContent::CalculateContentsScale(
207 float ideal_contents_scale,
208 float device_scale_factor,
209 float page_scale_factor,
210 bool animating_transform_to_screen,
211 float* contents_scale_x,
212 float* contents_scale_y,
213 gfx::Size* content_bounds) {
214 last_device_scale_factor_ = device_scale_factor;
215 Layer::CalculateContentsScale(ideal_contents_scale,
216 device_scale_factor,
217 page_scale_factor,
218 animating_transform_to_screen,
219 contents_scale_x,
220 contents_scale_y,
221 content_bounds);
222}
223
[email protected]96baf3e2012-10-22 23:09:55224class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:32225 public:
226 MockContentLayerClient() {}
227 virtual ~MockContentLayerClient() {}
228 virtual void PaintContents(SkCanvas* canvas,
[email protected]0023fc72014-01-10 20:05:06229 const gfx::Rect& clip,
[email protected]fb661802013-03-25 01:59:32230 gfx::RectF* opaque) OVERRIDE {}
231 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
[email protected]1d96e032014-03-25 05:59:08232 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
[email protected]f34a24232012-09-20 22:59:55233};
234
[email protected]fb661802013-03-25 01:59:32235scoped_refptr<ContentLayer> CreateDrawableContentLayer(
236 ContentLayerClient* delegate) {
237 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate);
238 to_return->SetIsDrawable(true);
239 return to_return;
[email protected]f34a24232012-09-20 22:59:55240}
241
[email protected]989386c2013-07-18 21:37:23242#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
243 do { \
244 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
245 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:47246 } while (false)
247
[email protected]989386c2013-07-18 21:37:23248TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32249 // Sanity check: For layers positioned at zero, with zero size,
250 // and with identity transforms, then the draw transform,
251 // screen space transform, and the hierarchy passed on to children
252 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14253
[email protected]fb661802013-03-25 01:59:32254 scoped_refptr<Layer> parent = Layer::Create();
255 scoped_refptr<Layer> child = Layer::Create();
256 scoped_refptr<Layer> grand_child = Layer::Create();
257 parent->AddChild(child);
258 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14259
[email protected]d600df7d2013-08-03 02:34:28260 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
261 host->SetRootLayer(parent);
262
[email protected]fb661802013-03-25 01:59:32263 gfx::Transform identity_matrix;
264 SetLayerPropertiesForTesting(parent.get(),
265 identity_matrix,
[email protected]fb661802013-03-25 01:59:32266 gfx::PointF(),
267 gfx::PointF(),
268 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:57269 true,
[email protected]fb661802013-03-25 01:59:32270 false);
271 SetLayerPropertiesForTesting(child.get(),
272 identity_matrix,
[email protected]fb661802013-03-25 01:59:32273 gfx::PointF(),
274 gfx::PointF(),
275 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57276 true,
[email protected]fb661802013-03-25 01:59:32277 false);
278 SetLayerPropertiesForTesting(grand_child.get(),
279 identity_matrix,
[email protected]fb661802013-03-25 01:59:32280 gfx::PointF(),
281 gfx::PointF(),
282 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57283 true,
[email protected]fb661802013-03-25 01:59:32284 false);
[email protected]94f206c12012-08-25 00:09:14285
[email protected]fb661802013-03-25 01:59:32286 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14287
[email protected]fb661802013-03-25 01:59:32288 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
289 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
290 child->screen_space_transform());
291 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
292 grand_child->draw_transform());
293 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
294 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14295}
296
[email protected]989386c2013-07-18 21:37:23297TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32298 gfx::Transform identity_matrix;
299 scoped_refptr<Layer> layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:14300
[email protected]fb661802013-03-25 01:59:32301 scoped_refptr<Layer> root = Layer::Create();
302 SetLayerPropertiesForTesting(root.get(),
303 identity_matrix,
[email protected]fb661802013-03-25 01:59:32304 gfx::PointF(),
305 gfx::PointF(),
306 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57307 true,
[email protected]fb661802013-03-25 01:59:32308 false);
309 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42310
[email protected]d600df7d2013-08-03 02:34:28311 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
312 host->SetRootLayer(root);
313
[email protected]fb661802013-03-25 01:59:32314 // Case 2: Setting the bounds of the layer should not affect either the draw
315 // transform or the screenspace transform.
316 gfx::Transform translation_to_center;
317 translation_to_center.Translate(5.0, 6.0);
318 SetLayerPropertiesForTesting(layer.get(),
319 identity_matrix,
[email protected]fb661802013-03-25 01:59:32320 gfx::PointF(),
321 gfx::PointF(),
322 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57323 true,
[email protected]fb661802013-03-25 01:59:32324 false);
325 ExecuteCalculateDrawProperties(root.get());
326 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
327 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
328 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14329
[email protected]fb661802013-03-25 01:59:32330 // Case 3: The anchor point by itself (without a layer transform) should have
331 // no effect on the transforms.
332 SetLayerPropertiesForTesting(layer.get(),
333 identity_matrix,
[email protected]fb661802013-03-25 01:59:32334 gfx::PointF(0.25f, 0.25f),
335 gfx::PointF(),
336 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57337 true,
[email protected]fb661802013-03-25 01:59:32338 false);
339 ExecuteCalculateDrawProperties(root.get());
340 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
341 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
342 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14343
[email protected]fb661802013-03-25 01:59:32344 // Case 4: A change in actual position affects both the draw transform and
345 // screen space transform.
346 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05347 position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32348 SetLayerPropertiesForTesting(layer.get(),
349 identity_matrix,
[email protected]fb661802013-03-25 01:59:32350 gfx::PointF(0.25f, 0.25f),
351 gfx::PointF(0.f, 1.2f),
352 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57353 true,
[email protected]fb661802013-03-25 01:59:32354 false);
355 ExecuteCalculateDrawProperties(root.get());
356 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
357 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
358 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14359
[email protected]fb661802013-03-25 01:59:32360 // Case 5: In the correct sequence of transforms, the layer transform should
361 // pre-multiply the translation_to_center. This is easily tested by using a
362 // scale transform, because scale and translation are not commutative.
363 gfx::Transform layer_transform;
364 layer_transform.Scale3d(2.0, 2.0, 1.0);
365 SetLayerPropertiesForTesting(layer.get(),
366 layer_transform,
[email protected]fb661802013-03-25 01:59:32367 gfx::PointF(),
368 gfx::PointF(),
369 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57370 true,
[email protected]fb661802013-03-25 01:59:32371 false);
372 ExecuteCalculateDrawProperties(root.get());
373 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
374 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
375 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14376
[email protected]fb661802013-03-25 01:59:32377 // Case 6: The layer transform should occur with respect to the anchor point.
378 gfx::Transform translation_to_anchor;
379 translation_to_anchor.Translate(5.0, 0.0);
380 gfx::Transform expected_result =
381 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
382 SetLayerPropertiesForTesting(layer.get(),
383 layer_transform,
[email protected]fb661802013-03-25 01:59:32384 gfx::PointF(0.5f, 0.f),
385 gfx::PointF(),
386 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57387 true,
[email protected]fb661802013-03-25 01:59:32388 false);
389 ExecuteCalculateDrawProperties(root.get());
390 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
391 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
392 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14393
[email protected]fb661802013-03-25 01:59:32394 // Case 7: Verify that position pre-multiplies the layer transform. The
395 // current implementation of CalculateDrawProperties does this implicitly, but
396 // it is still worth testing to detect accidental regressions.
397 expected_result = position_transform * translation_to_anchor *
398 layer_transform * Inverse(translation_to_anchor);
399 SetLayerPropertiesForTesting(layer.get(),
400 layer_transform,
[email protected]fb661802013-03-25 01:59:32401 gfx::PointF(0.5f, 0.f),
402 gfx::PointF(0.f, 1.2f),
403 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57404 true,
[email protected]fb661802013-03-25 01:59:32405 false);
406 ExecuteCalculateDrawProperties(root.get());
407 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
408 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
409 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14410}
411
[email protected]989386c2013-07-18 21:37:23412TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
[email protected]fb661802013-03-25 01:59:32413 const gfx::Vector2d kScrollOffset(50, 100);
414 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01415 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32416 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
417 -kScrollOffset.y());
418 const float kPageScale = 0.888f;
419 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20420
[email protected]fb661802013-03-25 01:59:32421 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:45422 TestSharedBitmapManager shared_bitmap_manager;
423 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]657b24c2013-03-06 09:01:20424
[email protected]fb661802013-03-25 01:59:32425 gfx::Transform identity_matrix;
426 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
427 LayerImpl::Create(host_impl.active_tree(), 1));
428 LayerImpl* sublayer = sublayer_scoped_ptr.get();
429 sublayer->SetContentsScale(kPageScale * kDeviceScale,
430 kPageScale * kDeviceScale);
431 SetLayerPropertiesForTesting(sublayer,
432 identity_matrix,
[email protected]fb661802013-03-25 01:59:32433 gfx::Point(),
434 gfx::PointF(),
435 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:57436 true,
[email protected]fb661802013-03-25 01:59:32437 false);
[email protected]657b24c2013-03-06 09:01:20438
[email protected]adeda572014-01-31 00:49:47439 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32440 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47441 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
[email protected]fb661802013-03-25 01:59:32442 SetLayerPropertiesForTesting(scroll_layer,
443 identity_matrix,
[email protected]fb661802013-03-25 01:59:32444 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47445 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32446 gfx::Size(10, 20),
[email protected]56fffdd2014-02-11 19:50:57447 true,
[email protected]fb661802013-03-25 01:59:32448 false);
[email protected]adeda572014-01-31 00:49:47449 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
450 LayerImpl::Create(host_impl.active_tree(), 4));
451 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
452
453 scroll_layer->SetScrollClipLayer(clip_layer->id());
454 clip_layer->SetBounds(
455 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
456 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
457 scroll_layer->SetScrollClipLayer(clip_layer->id());
[email protected]fb661802013-03-25 01:59:32458 scroll_layer->SetScrollDelta(kScrollDelta);
459 gfx::Transform impl_transform;
[email protected]fb661802013-03-25 01:59:32460 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
[email protected]adeda572014-01-31 00:49:47461 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
462 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
463 scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20464
[email protected]fb661802013-03-25 01:59:32465 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
466 SetLayerPropertiesForTesting(root.get(),
467 identity_matrix,
[email protected]fb661802013-03-25 01:59:32468 gfx::PointF(),
469 gfx::PointF(),
470 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:57471 true,
[email protected]fb661802013-03-25 01:59:32472 false);
[email protected]adeda572014-01-31 00:49:47473 root->AddChild(clip_layer_scoped_ptr.Pass());
[email protected]657b24c2013-03-06 09:01:20474
[email protected]f2136262013-04-26 21:10:19475 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32476 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32477 gfx::Transform expected_transform = identity_matrix;
478 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
479 sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
480 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
481 MathUtil::Round(sub_layer_screen_position.y()));
482 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
483 sublayer->draw_transform());
484 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
485 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20486
[email protected]fb661802013-03-25 01:59:32487 gfx::Transform arbitrary_translate;
488 const float kTranslateX = 10.6f;
489 const float kTranslateY = 20.6f;
490 arbitrary_translate.Translate(kTranslateX, kTranslateY);
491 SetLayerPropertiesForTesting(scroll_layer,
492 arbitrary_translate,
[email protected]fb661802013-03-25 01:59:32493 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47494 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32495 gfx::Size(10, 20),
[email protected]56fffdd2014-02-11 19:50:57496 true,
[email protected]fb661802013-03-25 01:59:32497 false);
[email protected]f2136262013-04-26 21:10:19498 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32499 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32500 expected_transform.MakeIdentity();
501 expected_transform.Translate(
502 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
503 sub_layer_screen_position.x()),
504 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
505 sub_layer_screen_position.y()));
506 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
507 sublayer->draw_transform());
[email protected]657b24c2013-03-06 09:01:20508}
509
[email protected]989386c2013-07-18 21:37:23510TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32511 gfx::Transform identity_matrix;
512 scoped_refptr<Layer> root = Layer::Create();
513 scoped_refptr<Layer> parent = Layer::Create();
514 scoped_refptr<Layer> child = Layer::Create();
515 scoped_refptr<Layer> grand_child = Layer::Create();
516 root->AddChild(parent);
517 parent->AddChild(child);
518 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14519
[email protected]d600df7d2013-08-03 02:34:28520 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
521 host->SetRootLayer(root);
522
[email protected]fb661802013-03-25 01:59:32523 // One-time setup of root layer
524 SetLayerPropertiesForTesting(root.get(),
525 identity_matrix,
[email protected]fb661802013-03-25 01:59:32526 gfx::PointF(),
527 gfx::PointF(),
528 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57529 true,
[email protected]fb661802013-03-25 01:59:32530 false);
[email protected]ecc12622012-10-30 20:45:42531
[email protected]fb661802013-03-25 01:59:32532 // Case 1: parent's anchor point should not affect child or grand_child.
533 SetLayerPropertiesForTesting(parent.get(),
534 identity_matrix,
[email protected]fb661802013-03-25 01:59:32535 gfx::PointF(0.25f, 0.25f),
536 gfx::PointF(),
537 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57538 true,
[email protected]fb661802013-03-25 01:59:32539 false);
540 SetLayerPropertiesForTesting(child.get(),
541 identity_matrix,
[email protected]fb661802013-03-25 01:59:32542 gfx::PointF(),
543 gfx::PointF(),
544 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57545 true,
[email protected]fb661802013-03-25 01:59:32546 false);
547 SetLayerPropertiesForTesting(grand_child.get(),
548 identity_matrix,
[email protected]fb661802013-03-25 01:59:32549 gfx::PointF(),
550 gfx::PointF(),
551 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57552 true,
[email protected]fb661802013-03-25 01:59:32553 false);
554 ExecuteCalculateDrawProperties(root.get());
555 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
556 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
557 child->screen_space_transform());
558 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
559 grand_child->draw_transform());
560 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
561 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14562
[email protected]fb661802013-03-25 01:59:32563 // Case 2: parent's position affects child and grand_child.
564 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05565 parent_position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32566 SetLayerPropertiesForTesting(parent.get(),
567 identity_matrix,
[email protected]fb661802013-03-25 01:59:32568 gfx::PointF(0.25f, 0.25f),
569 gfx::PointF(0.f, 1.2f),
570 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57571 true,
[email protected]fb661802013-03-25 01:59:32572 false);
573 SetLayerPropertiesForTesting(child.get(),
574 identity_matrix,
[email protected]fb661802013-03-25 01:59:32575 gfx::PointF(),
576 gfx::PointF(),
577 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57578 true,
[email protected]fb661802013-03-25 01:59:32579 false);
580 SetLayerPropertiesForTesting(grand_child.get(),
581 identity_matrix,
[email protected]fb661802013-03-25 01:59:32582 gfx::PointF(),
583 gfx::PointF(),
584 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57585 true,
[email protected]fb661802013-03-25 01:59:32586 false);
587 ExecuteCalculateDrawProperties(root.get());
588 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
589 child->draw_transform());
590 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
591 child->screen_space_transform());
592 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
593 grand_child->draw_transform());
594 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
595 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14596
[email protected]fb661802013-03-25 01:59:32597 // Case 3: parent's local transform affects child and grandchild
598 gfx::Transform parent_layer_transform;
599 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
600 gfx::Transform parent_translation_to_anchor;
601 parent_translation_to_anchor.Translate(2.5, 3.0);
602 gfx::Transform parent_composite_transform =
603 parent_translation_to_anchor * parent_layer_transform *
604 Inverse(parent_translation_to_anchor);
605 SetLayerPropertiesForTesting(parent.get(),
606 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32607 gfx::PointF(0.25f, 0.25f),
608 gfx::PointF(),
609 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57610 true,
[email protected]fb661802013-03-25 01:59:32611 false);
612 SetLayerPropertiesForTesting(child.get(),
613 identity_matrix,
[email protected]fb661802013-03-25 01:59:32614 gfx::PointF(),
615 gfx::PointF(),
616 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57617 true,
[email protected]fb661802013-03-25 01:59:32618 false);
619 SetLayerPropertiesForTesting(grand_child.get(),
620 identity_matrix,
[email protected]fb661802013-03-25 01:59:32621 gfx::PointF(),
622 gfx::PointF(),
623 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57624 true,
[email protected]fb661802013-03-25 01:59:32625 false);
626 ExecuteCalculateDrawProperties(root.get());
627 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
628 child->draw_transform());
629 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
630 child->screen_space_transform());
631 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
632 grand_child->draw_transform());
633 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
634 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14635}
636
[email protected]989386c2013-07-18 21:37:23637TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
[email protected]fb661802013-03-25 01:59:32638 scoped_refptr<Layer> root = Layer::Create();
639 scoped_refptr<Layer> parent = Layer::Create();
640 scoped_refptr<Layer> child = Layer::Create();
641 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
642 make_scoped_refptr(new LayerWithForcedDrawsContent());
643 root->AddChild(parent);
644 parent->AddChild(child);
645 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14646
[email protected]d600df7d2013-08-03 02:34:28647 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
648 host->SetRootLayer(root);
649
[email protected]fb661802013-03-25 01:59:32650 // One-time setup of root layer
651 gfx::Transform identity_matrix;
652 SetLayerPropertiesForTesting(root.get(),
653 identity_matrix,
[email protected]fb661802013-03-25 01:59:32654 gfx::PointF(),
655 gfx::PointF(),
656 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57657 true,
[email protected]fb661802013-03-25 01:59:32658 false);
[email protected]ecc12622012-10-30 20:45:42659
[email protected]fb661802013-03-25 01:59:32660 // Child is set up so that a new render surface should be created.
661 child->SetOpacity(0.5f);
662 child->SetForceRenderSurface(true);
[email protected]94f206c12012-08-25 00:09:14663
[email protected]fb661802013-03-25 01:59:32664 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05665 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32666 gfx::Transform parent_translation_to_anchor;
667 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44668
[email protected]fb661802013-03-25 01:59:32669 gfx::Transform parent_composite_transform =
670 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39671 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32672 gfx::Vector2dF parent_composite_scale =
673 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
674 1.f);
675 gfx::Transform surface_sublayer_transform;
676 surface_sublayer_transform.Scale(parent_composite_scale.x(),
677 parent_composite_scale.y());
678 gfx::Transform surface_sublayer_composite_transform =
679 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14680
[email protected]fb661802013-03-25 01:59:32681 // Child's render surface should not exist yet.
682 ASSERT_FALSE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:14683
[email protected]fb661802013-03-25 01:59:32684 SetLayerPropertiesForTesting(parent.get(),
685 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32686 gfx::PointF(0.25f, 0.25f),
687 gfx::PointF(),
688 gfx::Size(100, 120),
[email protected]56fffdd2014-02-11 19:50:57689 true,
[email protected]fb661802013-03-25 01:59:32690 false);
691 SetLayerPropertiesForTesting(child.get(),
692 identity_matrix,
[email protected]fb661802013-03-25 01:59:32693 gfx::PointF(),
694 gfx::PointF(),
695 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57696 true,
[email protected]fb661802013-03-25 01:59:32697 false);
698 SetLayerPropertiesForTesting(grand_child.get(),
699 identity_matrix,
[email protected]fb661802013-03-25 01:59:32700 gfx::PointF(),
701 gfx::PointF(),
702 gfx::Size(8, 10),
[email protected]56fffdd2014-02-11 19:50:57703 true,
[email protected]fb661802013-03-25 01:59:32704 false);
705 ExecuteCalculateDrawProperties(root.get());
[email protected]94f206c12012-08-25 00:09:14706
[email protected]fb661802013-03-25 01:59:32707 // Render surface should have been created now.
708 ASSERT_TRUE(child->render_surface());
709 ASSERT_EQ(child, child->render_target());
[email protected]94f206c12012-08-25 00:09:14710
[email protected]fb661802013-03-25 01:59:32711 // The child layer's draw transform should refer to its new render surface.
712 // The screen-space transform, however, should still refer to the root.
713 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
714 child->draw_transform());
715 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
716 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14717
[email protected]fb661802013-03-25 01:59:32718 // Because the grand_child is the only drawable content, the child's render
719 // surface will tighten its bounds to the grand_child. The scale at which the
720 // surface's subtree is drawn must be removed from the composite transform.
721 EXPECT_TRANSFORMATION_MATRIX_EQ(
722 surface_sublayer_composite_transform,
723 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14724
[email protected]fb661802013-03-25 01:59:32725 // The screen space is the same as the target since the child surface draws
726 // into the root.
727 EXPECT_TRANSFORMATION_MATRIX_EQ(
728 surface_sublayer_composite_transform,
729 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14730}
731
[email protected]989386c2013-07-18 21:37:23732TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
[email protected]fb661802013-03-25 01:59:32733 scoped_refptr<Layer> root = Layer::Create();
734 scoped_refptr<Layer> parent = Layer::Create();
735 scoped_refptr<Layer> child = Layer::Create();
736 scoped_refptr<Layer> child_replica = Layer::Create();
737 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
738 make_scoped_refptr(new LayerWithForcedDrawsContent());
739 root->AddChild(parent);
740 parent->AddChild(child);
741 child->AddChild(grand_child);
742 child->SetReplicaLayer(child_replica.get());
743
[email protected]d600df7d2013-08-03 02:34:28744 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
745 host->SetRootLayer(root);
746
[email protected]fb661802013-03-25 01:59:32747 // One-time setup of root layer
748 gfx::Transform identity_matrix;
749 SetLayerPropertiesForTesting(root.get(),
750 identity_matrix,
[email protected]fb661802013-03-25 01:59:32751 gfx::PointF(),
752 gfx::PointF(),
753 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57754 true,
[email protected]fb661802013-03-25 01:59:32755 false);
756
757 // Child is set up so that a new render surface should be created.
758 child->SetOpacity(0.5f);
759
760 gfx::Transform parent_layer_transform;
761 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
762 gfx::Transform parent_translation_to_anchor;
763 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32764 gfx::Transform parent_composite_transform =
765 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39766 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32767 gfx::Transform replica_layer_transform;
768 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
769 gfx::Vector2dF parent_composite_scale =
770 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
771 1.f);
772 gfx::Transform surface_sublayer_transform;
773 surface_sublayer_transform.Scale(parent_composite_scale.x(),
774 parent_composite_scale.y());
775 gfx::Transform replica_composite_transform =
776 parent_composite_transform * replica_layer_transform *
777 Inverse(surface_sublayer_transform);
778
779 // Child's render surface should not exist yet.
780 ASSERT_FALSE(child->render_surface());
781
782 SetLayerPropertiesForTesting(parent.get(),
783 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32784 gfx::PointF(0.25f, 0.25f),
785 gfx::PointF(),
786 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57787 true,
[email protected]fb661802013-03-25 01:59:32788 false);
789 SetLayerPropertiesForTesting(child.get(),
790 identity_matrix,
[email protected]fb661802013-03-25 01:59:32791 gfx::PointF(),
792 gfx::PointF(),
793 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57794 true,
[email protected]fb661802013-03-25 01:59:32795 false);
796 SetLayerPropertiesForTesting(grand_child.get(),
797 identity_matrix,
[email protected]fb661802013-03-25 01:59:32798 gfx::PointF(),
799 gfx::PointF(-0.5f, -0.5f),
800 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:57801 true,
[email protected]fb661802013-03-25 01:59:32802 false);
803 SetLayerPropertiesForTesting(child_replica.get(),
804 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:32805 gfx::PointF(),
806 gfx::PointF(),
807 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57808 true,
[email protected]fb661802013-03-25 01:59:32809 false);
810 ExecuteCalculateDrawProperties(root.get());
811
812 // Render surface should have been created now.
813 ASSERT_TRUE(child->render_surface());
814 ASSERT_EQ(child, child->render_target());
815
816 EXPECT_TRANSFORMATION_MATRIX_EQ(
817 replica_composite_transform,
818 child->render_target()->render_surface()->replica_draw_transform());
819 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57820 child->render_target()
821 ->render_surface()
[email protected]fb661802013-03-25 01:59:32822 ->replica_screen_space_transform());
823}
824
[email protected]989386c2013-07-18 21:37:23825TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32826 // This test creates a more complex tree and verifies it all at once. This
827 // covers the following cases:
828 // - layers that are described w.r.t. a render surface: should have draw
829 // transforms described w.r.t. that surface
830 // - A render surface described w.r.t. an ancestor render surface: should
831 // have a draw transform described w.r.t. that ancestor surface
832 // - Replicas of a render surface are described w.r.t. the replica's
833 // transform around its anchor, along with the surface itself.
834 // - Sanity check on recursion: verify transforms of layers described w.r.t.
835 // a render surface that is described w.r.t. an ancestor render surface.
836 // - verifying that each layer has a reference to the correct render surface
837 // and render target values.
838
839 scoped_refptr<Layer> root = Layer::Create();
840 scoped_refptr<Layer> parent = Layer::Create();
841 scoped_refptr<Layer> render_surface1 = Layer::Create();
842 scoped_refptr<Layer> render_surface2 = Layer::Create();
843 scoped_refptr<Layer> child_of_root = Layer::Create();
844 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
845 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
846 scoped_refptr<Layer> replica_of_rs1 = Layer::Create();
847 scoped_refptr<Layer> replica_of_rs2 = Layer::Create();
848 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
849 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
850 make_scoped_refptr(new LayerWithForcedDrawsContent());
851 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
852 make_scoped_refptr(new LayerWithForcedDrawsContent());
853 root->AddChild(parent);
854 parent->AddChild(render_surface1);
855 parent->AddChild(child_of_root);
856 render_surface1->AddChild(child_of_rs1);
857 render_surface1->AddChild(render_surface2);
858 render_surface2->AddChild(child_of_rs2);
859 child_of_root->AddChild(grand_child_of_root);
860 child_of_rs1->AddChild(grand_child_of_rs1);
861 child_of_rs2->AddChild(grand_child_of_rs2);
862 render_surface1->SetReplicaLayer(replica_of_rs1.get());
863 render_surface2->SetReplicaLayer(replica_of_rs2.get());
864
[email protected]d600df7d2013-08-03 02:34:28865 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
866 host->SetRootLayer(root);
867
[email protected]fb661802013-03-25 01:59:32868 // In combination with descendant draws content, opacity != 1 forces the layer
869 // to have a new render surface.
870 render_surface1->SetOpacity(0.5f);
871 render_surface2->SetOpacity(0.33f);
872
873 // One-time setup of root layer
874 gfx::Transform identity_matrix;
875 SetLayerPropertiesForTesting(root.get(),
876 identity_matrix,
[email protected]fb661802013-03-25 01:59:32877 gfx::PointF(),
878 gfx::PointF(),
879 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57880 true,
[email protected]fb661802013-03-25 01:59:32881 false);
882
883 // All layers in the tree are initialized with an anchor at .25 and a size of
884 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39885 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32886 gfx::Transform translation_to_anchor;
887 translation_to_anchor.Translate(2.5, 0.0);
888 gfx::Transform layer_transform;
889 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32890 gfx::Transform replica_layer_transform;
891 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
892
893 gfx::Transform A =
894 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32895 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
896 Inverse(translation_to_anchor);
897
898 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39899 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32900 gfx::Transform surface1_sublayer_transform;
901 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
902 surface1_parent_transform_scale.y());
903
904 // SS1 = transform given to the subtree of render_surface1
905 gfx::Transform SS1 = surface1_sublayer_transform;
906 // S1 = transform to move from render_surface1 pixels to the layer space of
907 // the owning layer
908 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
909
910 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39911 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32912 gfx::Transform surface2_sublayer_transform;
913 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
914 surface2_parent_transform_scale.y());
915
916 // SS2 = transform given to the subtree of render_surface2
917 gfx::Transform SS2 = surface2_sublayer_transform;
918 // S2 = transform to move from render_surface2 pixels to the layer space of
919 // the owning layer
920 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
921
922 SetLayerPropertiesForTesting(parent.get(),
923 layer_transform,
[email protected]fb661802013-03-25 01:59:32924 gfx::PointF(0.25f, 0.f),
925 gfx::PointF(),
926 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57927 true,
[email protected]fb661802013-03-25 01:59:32928 false);
929 SetLayerPropertiesForTesting(render_surface1.get(),
930 layer_transform,
[email protected]fb661802013-03-25 01:59:32931 gfx::PointF(0.25f, 0.f),
932 gfx::PointF(),
933 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57934 true,
[email protected]fb661802013-03-25 01:59:32935 false);
936 SetLayerPropertiesForTesting(render_surface2.get(),
937 layer_transform,
[email protected]fb661802013-03-25 01:59:32938 gfx::PointF(0.25f, 0.f),
939 gfx::PointF(),
940 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57941 true,
[email protected]fb661802013-03-25 01:59:32942 false);
943 SetLayerPropertiesForTesting(child_of_root.get(),
944 layer_transform,
[email protected]fb661802013-03-25 01:59:32945 gfx::PointF(0.25f, 0.f),
946 gfx::PointF(),
947 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57948 true,
[email protected]fb661802013-03-25 01:59:32949 false);
950 SetLayerPropertiesForTesting(child_of_rs1.get(),
951 layer_transform,
[email protected]fb661802013-03-25 01:59:32952 gfx::PointF(0.25f, 0.f),
953 gfx::PointF(),
954 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57955 true,
[email protected]fb661802013-03-25 01:59:32956 false);
957 SetLayerPropertiesForTesting(child_of_rs2.get(),
958 layer_transform,
[email protected]fb661802013-03-25 01:59:32959 gfx::PointF(0.25f, 0.f),
960 gfx::PointF(),
961 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57962 true,
[email protected]fb661802013-03-25 01:59:32963 false);
964 SetLayerPropertiesForTesting(grand_child_of_root.get(),
965 layer_transform,
[email protected]fb661802013-03-25 01:59:32966 gfx::PointF(0.25f, 0.f),
967 gfx::PointF(),
968 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57969 true,
[email protected]fb661802013-03-25 01:59:32970 false);
971 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
972 layer_transform,
[email protected]fb661802013-03-25 01:59:32973 gfx::PointF(0.25f, 0.f),
974 gfx::PointF(),
975 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57976 true,
[email protected]fb661802013-03-25 01:59:32977 false);
978 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
979 layer_transform,
[email protected]fb661802013-03-25 01:59:32980 gfx::PointF(0.25f, 0.f),
981 gfx::PointF(),
982 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57983 true,
[email protected]fb661802013-03-25 01:59:32984 false);
985 SetLayerPropertiesForTesting(replica_of_rs1.get(),
986 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:32987 gfx::PointF(0.25f, 0.f),
988 gfx::PointF(),
989 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57990 true,
[email protected]fb661802013-03-25 01:59:32991 false);
992 SetLayerPropertiesForTesting(replica_of_rs2.get(),
993 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:32994 gfx::PointF(0.25f, 0.f),
995 gfx::PointF(),
996 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57997 true,
[email protected]fb661802013-03-25 01:59:32998 false);
999
1000 ExecuteCalculateDrawProperties(root.get());
1001
1002 // Only layers that are associated with render surfaces should have an actual
1003 // RenderSurface() value.
1004 ASSERT_TRUE(root->render_surface());
1005 ASSERT_FALSE(child_of_root->render_surface());
1006 ASSERT_FALSE(grand_child_of_root->render_surface());
1007
1008 ASSERT_TRUE(render_surface1->render_surface());
1009 ASSERT_FALSE(child_of_rs1->render_surface());
1010 ASSERT_FALSE(grand_child_of_rs1->render_surface());
1011
1012 ASSERT_TRUE(render_surface2->render_surface());
1013 ASSERT_FALSE(child_of_rs2->render_surface());
1014 ASSERT_FALSE(grand_child_of_rs2->render_surface());
1015
1016 // Verify all render target accessors
1017 EXPECT_EQ(root, parent->render_target());
1018 EXPECT_EQ(root, child_of_root->render_target());
1019 EXPECT_EQ(root, grand_child_of_root->render_target());
1020
1021 EXPECT_EQ(render_surface1, render_surface1->render_target());
1022 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
1023 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
1024
1025 EXPECT_EQ(render_surface2, render_surface2->render_target());
1026 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
1027 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
1028
1029 // Verify layer draw transforms note that draw transforms are described with
1030 // respect to the nearest ancestor render surface but screen space transforms
1031 // are described with respect to the root.
1032 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
[email protected]baf64d062014-02-16 22:10:391033 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform());
1034 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321035 grand_child_of_root->draw_transform());
1036
1037 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
[email protected]baf64d062014-02-16 22:10:391038 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform());
1039 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
[email protected]fb661802013-03-25 01:59:321040 grand_child_of_rs1->draw_transform());
1041
1042 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
[email protected]baf64d062014-02-16 22:10:391043 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform());
1044 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
[email protected]fb661802013-03-25 01:59:321045 grand_child_of_rs2->draw_transform());
1046
1047 // Verify layer screen-space transforms
1048 //
1049 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391050 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:321051 child_of_root->screen_space_transform());
1052 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391053 A * A * A, grand_child_of_root->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321054
[email protected]baf64d062014-02-16 22:10:391055 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:321056 render_surface1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391057 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321058 child_of_rs1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391059 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:321060 grand_child_of_rs1->screen_space_transform());
1061
[email protected]baf64d062014-02-16 22:10:391062 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321063 render_surface2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391064 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:321065 child_of_rs2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391066 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
[email protected]fb661802013-03-25 01:59:321067 grand_child_of_rs2->screen_space_transform());
1068
1069 // Verify render surface transforms.
1070 //
1071 // Draw transform of render surface 1 is described with respect to root.
1072 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391073 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321074 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391075 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:321076 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391077 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321078 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391079 A * R * S1,
[email protected]fb661802013-03-25 01:59:321080 render_surface1->render_surface()->replica_screen_space_transform());
1081 // Draw transform of render surface 2 is described with respect to render
1082 // surface 1.
1083 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391084 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321085 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391086 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:321087 render_surface2->render_surface()->replica_draw_transform());
1088 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391089 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:321090 render_surface2->render_surface()->screen_space_transform());
1091 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391092 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:321093 render_surface2->render_surface()->replica_screen_space_transform());
1094
1095 // Sanity check. If these fail there is probably a bug in the test itself. It
1096 // is expected that we correctly set up transforms so that the y-component of
1097 // the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:261098 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
1099 EXPECT_FLOAT_EQ(2.0,
1100 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321101 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261102 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321103
[email protected]803f6b52013-09-12 00:51:261104 EXPECT_FLOAT_EQ(2.0,
1105 render_surface1->screen_space_transform().matrix().get(1, 3));
1106 EXPECT_FLOAT_EQ(3.0,
1107 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321108 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261109 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321110
[email protected]803f6b52013-09-12 00:51:261111 EXPECT_FLOAT_EQ(3.0,
1112 render_surface2->screen_space_transform().matrix().get(1, 3));
1113 EXPECT_FLOAT_EQ(4.0,
1114 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321115 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261116 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321117}
1118
[email protected]989386c2013-07-18 21:37:231119TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321120 // For layers that flatten their subtree, there should be an orthographic
1121 // projection (for x and y values) in the middle of the transform sequence.
1122 // Note that the way the code is currently implemented, it is not expected to
1123 // use a canonical orthographic projection.
1124
1125 scoped_refptr<Layer> root = Layer::Create();
1126 scoped_refptr<Layer> child = Layer::Create();
1127 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1128 make_scoped_refptr(new LayerWithForcedDrawsContent());
1129
1130 gfx::Transform rotation_about_y_axis;
1131 rotation_about_y_axis.RotateAboutYAxis(30.0);
1132
1133 const gfx::Transform identity_matrix;
1134 SetLayerPropertiesForTesting(root.get(),
1135 identity_matrix,
[email protected]fb661802013-03-25 01:59:321136 gfx::PointF(),
1137 gfx::PointF(),
1138 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571139 true,
[email protected]fb661802013-03-25 01:59:321140 false);
1141 SetLayerPropertiesForTesting(child.get(),
1142 rotation_about_y_axis,
[email protected]fb661802013-03-25 01:59:321143 gfx::PointF(),
1144 gfx::PointF(),
1145 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571146 true,
[email protected]fb661802013-03-25 01:59:321147 false);
1148 SetLayerPropertiesForTesting(grand_child.get(),
1149 rotation_about_y_axis,
[email protected]fb661802013-03-25 01:59:321150 gfx::PointF(),
1151 gfx::PointF(),
1152 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571153 true,
[email protected]fb661802013-03-25 01:59:321154 false);
1155
1156 root->AddChild(child);
1157 child->AddChild(grand_child);
1158 child->SetForceRenderSurface(true);
1159
[email protected]d600df7d2013-08-03 02:34:281160 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1161 host->SetRootLayer(root);
1162
[email protected]fb661802013-03-25 01:59:321163 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:571164 ASSERT_TRUE(root->should_flatten_transform());
1165 ASSERT_TRUE(child->should_flatten_transform());
1166 ASSERT_TRUE(grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:321167
1168 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1169 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1170 gfx::Transform expected_grand_child_draw_transform =
1171 rotation_about_y_axis; // draws onto child's render surface
1172 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1173 flattened_rotation_about_y.FlattenTo2d();
1174 gfx::Transform expected_grand_child_screen_space_transform =
1175 flattened_rotation_about_y * rotation_about_y_axis;
1176
1177 ExecuteCalculateDrawProperties(root.get());
1178
1179 // The child's draw transform should have been taken by its surface.
1180 ASSERT_TRUE(child->render_surface());
1181 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1182 child->render_surface()->draw_transform());
1183 EXPECT_TRANSFORMATION_MATRIX_EQ(
1184 expected_child_screen_space_transform,
1185 child->render_surface()->screen_space_transform());
1186 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1187 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1188 child->screen_space_transform());
1189 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1190 grand_child->draw_transform());
1191 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1192 grand_child->screen_space_transform());
1193}
1194
[email protected]989386c2013-07-18 21:37:231195TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321196 // A layer that is empty in one axis, but not the other, was accidentally
1197 // skipping a necessary translation. Without that translation, the coordinate
1198 // space of the layer's draw transform is incorrect.
1199 //
1200 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1201 // but if that layer becomes a render surface, then its draw transform is
1202 // implicitly inherited by the rest of the subtree, which then is positioned
1203 // incorrectly as a result.
1204
1205 scoped_refptr<Layer> root = Layer::Create();
1206 scoped_refptr<Layer> child = Layer::Create();
1207 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1208 make_scoped_refptr(new LayerWithForcedDrawsContent());
1209
1210 // The child height is zero, but has non-zero width that should be accounted
1211 // for while computing draw transforms.
1212 const gfx::Transform identity_matrix;
1213 SetLayerPropertiesForTesting(root.get(),
1214 identity_matrix,
[email protected]fb661802013-03-25 01:59:321215 gfx::PointF(),
1216 gfx::PointF(),
1217 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571218 true,
[email protected]fb661802013-03-25 01:59:321219 false);
1220 SetLayerPropertiesForTesting(child.get(),
1221 identity_matrix,
[email protected]fb661802013-03-25 01:59:321222 gfx::PointF(),
1223 gfx::PointF(),
1224 gfx::Size(10, 0),
[email protected]56fffdd2014-02-11 19:50:571225 true,
[email protected]fb661802013-03-25 01:59:321226 false);
1227 SetLayerPropertiesForTesting(grand_child.get(),
1228 identity_matrix,
[email protected]fb661802013-03-25 01:59:321229 gfx::PointF(),
1230 gfx::PointF(),
1231 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571232 true,
[email protected]fb661802013-03-25 01:59:321233 false);
1234
1235 root->AddChild(child);
1236 child->AddChild(grand_child);
1237 child->SetForceRenderSurface(true);
1238
[email protected]d600df7d2013-08-03 02:34:281239 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1240 host->SetRootLayer(root);
1241
[email protected]fb661802013-03-25 01:59:321242 ExecuteCalculateDrawProperties(root.get());
1243
1244 ASSERT_TRUE(child->render_surface());
1245 // This is the real test, the rest are sanity checks.
1246 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1247 child->render_surface()->draw_transform());
1248 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1249 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1250 grand_child->draw_transform());
1251}
1252
[email protected]989386c2013-07-18 21:37:231253TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321254 // Transformations applied at the root of the tree should be forwarded
1255 // to child layers instead of applied to the root RenderSurface.
1256 const gfx::Transform identity_matrix;
[email protected]d5754282014-04-09 00:43:291257 scoped_refptr<LayerWithForcedDrawsContent> root =
1258 new LayerWithForcedDrawsContent;
1259 scoped_refptr<LayerWithForcedDrawsContent> child =
1260 new LayerWithForcedDrawsContent;
[email protected]adeda572014-01-31 00:49:471261 child->SetScrollClipLayerId(root->id());
[email protected]f224cc92013-06-06 23:23:321262 root->AddChild(child);
1263
[email protected]d600df7d2013-08-03 02:34:281264 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1265 host->SetRootLayer(root);
1266
[email protected]f224cc92013-06-06 23:23:321267 SetLayerPropertiesForTesting(root.get(),
1268 identity_matrix,
[email protected]f224cc92013-06-06 23:23:321269 gfx::PointF(),
1270 gfx::PointF(),
1271 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571272 true,
[email protected]f224cc92013-06-06 23:23:321273 false);
1274 SetLayerPropertiesForTesting(child.get(),
1275 identity_matrix,
[email protected]f224cc92013-06-06 23:23:321276 gfx::PointF(),
1277 gfx::PointF(),
1278 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571279 true,
[email protected]f224cc92013-06-06 23:23:321280 false);
1281
[email protected]f224cc92013-06-06 23:23:321282 gfx::Transform translate;
1283 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231284 {
1285 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531286 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1287 root.get(), root->bounds(), translate, &render_surface_layer_list);
1288 inputs.can_adjust_raster_scales = true;
1289 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231290 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1291 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1292 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291293 EXPECT_EQ(1.f, root->last_device_scale_factor());
1294 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231295 }
[email protected]f224cc92013-06-06 23:23:321296
1297 gfx::Transform scale;
1298 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231299 {
1300 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531301 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1302 root.get(), root->bounds(), scale, &render_surface_layer_list);
1303 inputs.can_adjust_raster_scales = true;
1304 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231305 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1306 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1307 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291308 EXPECT_EQ(2.f, root->last_device_scale_factor());
1309 EXPECT_EQ(2.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231310 }
[email protected]f224cc92013-06-06 23:23:321311
1312 gfx::Transform rotate;
1313 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231314 {
1315 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531316 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1317 root.get(), root->bounds(), rotate, &render_surface_layer_list);
1318 inputs.can_adjust_raster_scales = true;
1319 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231320 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1321 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1322 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291323 EXPECT_EQ(1.f, root->last_device_scale_factor());
1324 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231325 }
[email protected]f224cc92013-06-06 23:23:321326
1327 gfx::Transform composite;
1328 composite.ConcatTransform(translate);
1329 composite.ConcatTransform(scale);
1330 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231331 {
1332 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531333 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1334 root.get(), root->bounds(), composite, &render_surface_layer_list);
1335 inputs.can_adjust_raster_scales = true;
1336 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231337 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1338 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1339 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1340 }
[email protected]f224cc92013-06-06 23:23:321341
[email protected]9781afa2013-07-17 23:15:321342 // Verify it composes correctly with device scale.
1343 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231344
1345 {
1346 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531347 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1348 root.get(), root->bounds(), translate, &render_surface_layer_list);
1349 inputs.device_scale_factor = device_scale_factor;
1350 inputs.can_adjust_raster_scales = true;
1351 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231352 gfx::Transform device_scaled_translate = translate;
1353 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1354 EXPECT_EQ(device_scaled_translate,
1355 root->draw_properties().target_space_transform);
1356 EXPECT_EQ(device_scaled_translate,
1357 child->draw_properties().target_space_transform);
1358 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291359 EXPECT_EQ(device_scale_factor, root->last_device_scale_factor());
1360 EXPECT_EQ(device_scale_factor, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231361 }
[email protected]9781afa2013-07-17 23:15:321362
1363 // Verify it composes correctly with page scale.
1364 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231365
1366 {
1367 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531368 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1369 root.get(), root->bounds(), translate, &render_surface_layer_list);
1370 inputs.page_scale_factor = page_scale_factor;
1371 inputs.page_scale_application_layer = root.get();
1372 inputs.can_adjust_raster_scales = true;
1373 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231374 gfx::Transform page_scaled_translate = translate;
1375 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1376 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1377 EXPECT_EQ(page_scaled_translate,
1378 child->draw_properties().target_space_transform);
1379 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]d5754282014-04-09 00:43:291380 EXPECT_EQ(1.f, root->last_device_scale_factor());
1381 EXPECT_EQ(1.f, child->last_device_scale_factor());
[email protected]989386c2013-07-18 21:37:231382 }
[email protected]9781afa2013-07-17 23:15:321383
[email protected]f224cc92013-06-06 23:23:321384 // Verify that it composes correctly with transforms directly on root layer.
1385 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231386
1387 {
1388 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531389 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1390 root.get(), root->bounds(), composite, &render_surface_layer_list);
1391 inputs.can_adjust_raster_scales = true;
1392 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231393 gfx::Transform compositeSquared = composite;
1394 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261395 EXPECT_TRANSFORMATION_MATRIX_EQ(
1396 compositeSquared, root->draw_properties().target_space_transform);
1397 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391398 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231399 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1400 }
[email protected]f224cc92013-06-06 23:23:321401}
1402
[email protected]989386c2013-07-18 21:37:231403TEST_F(LayerTreeHostCommonTest,
1404 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321405 scoped_refptr<Layer> parent = Layer::Create();
1406 scoped_refptr<Layer> render_surface1 = Layer::Create();
1407 scoped_refptr<LayerWithForcedDrawsContent> child =
1408 make_scoped_refptr(new LayerWithForcedDrawsContent());
1409
[email protected]d600df7d2013-08-03 02:34:281410 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1411 host->SetRootLayer(parent);
1412
[email protected]fb661802013-03-25 01:59:321413 const gfx::Transform identity_matrix;
1414 SetLayerPropertiesForTesting(parent.get(),
1415 identity_matrix,
[email protected]fb661802013-03-25 01:59:321416 gfx::PointF(),
1417 gfx::PointF(),
1418 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571419 true,
[email protected]fb661802013-03-25 01:59:321420 false);
1421 SetLayerPropertiesForTesting(render_surface1.get(),
1422 identity_matrix,
[email protected]fb661802013-03-25 01:59:321423 gfx::PointF(),
1424 gfx::PointF(),
1425 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571426 true,
[email protected]fb661802013-03-25 01:59:321427 false);
1428 SetLayerPropertiesForTesting(child.get(),
1429 identity_matrix,
[email protected]fb661802013-03-25 01:59:321430 gfx::PointF(),
1431 gfx::PointF(30.f, 30.f),
1432 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571433 true,
[email protected]fb661802013-03-25 01:59:321434 false);
1435
1436 parent->AddChild(render_surface1);
1437 parent->SetMasksToBounds(true);
1438 render_surface1->AddChild(child);
1439 render_surface1->SetForceRenderSurface(true);
1440
[email protected]989386c2013-07-18 21:37:231441 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531442 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1443 parent.get(),
1444 parent->bounds(),
1445 gfx::Transform(),
1446 &render_surface_layer_list);
1447 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321448
1449 // The child layer's content is entirely outside the parent's clip rect, so
1450 // the intermediate render surface should not be listed here, even if it was
1451 // forced to be created. Render surfaces without children or visible content
1452 // are unexpected at draw time (e.g. we might try to create a content texture
1453 // of size 0).
1454 ASSERT_TRUE(parent->render_surface());
1455 ASSERT_FALSE(render_surface1->render_surface());
1456 EXPECT_EQ(1U, render_surface_layer_list.size());
1457}
1458
[email protected]989386c2013-07-18 21:37:231459TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321460 scoped_refptr<Layer> parent = Layer::Create();
1461 scoped_refptr<Layer> render_surface1 = Layer::Create();
1462 scoped_refptr<LayerWithForcedDrawsContent> child =
1463 make_scoped_refptr(new LayerWithForcedDrawsContent());
1464
[email protected]d600df7d2013-08-03 02:34:281465 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1466 host->SetRootLayer(parent);
1467
[email protected]fb661802013-03-25 01:59:321468 const gfx::Transform identity_matrix;
1469 SetLayerPropertiesForTesting(render_surface1.get(),
1470 identity_matrix,
[email protected]fb661802013-03-25 01:59:321471 gfx::PointF(),
1472 gfx::PointF(),
1473 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571474 true,
[email protected]fb661802013-03-25 01:59:321475 false);
1476 SetLayerPropertiesForTesting(child.get(),
1477 identity_matrix,
[email protected]fb661802013-03-25 01:59:321478 gfx::PointF(),
1479 gfx::PointF(),
1480 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571481 true,
[email protected]fb661802013-03-25 01:59:321482 false);
1483
1484 parent->AddChild(render_surface1);
1485 render_surface1->AddChild(child);
1486 render_surface1->SetForceRenderSurface(true);
1487 render_surface1->SetOpacity(0.f);
1488
[email protected]989386c2013-07-18 21:37:231489 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531490 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1491 parent.get(), parent->bounds(), &render_surface_layer_list);
1492 inputs.can_adjust_raster_scales = true;
1493 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321494
1495 // Since the layer is transparent, render_surface1->render_surface() should
1496 // not have gotten added anywhere. Also, the drawable content rect should not
1497 // have been extended by the children.
1498 ASSERT_TRUE(parent->render_surface());
1499 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1500 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231501 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321502 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1503}
1504
[email protected]989386c2013-07-18 21:37:231505TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321506 scoped_refptr<Layer> parent = Layer::Create();
1507 scoped_refptr<Layer> render_surface1 = Layer::Create();
1508 scoped_refptr<LayerWithForcedDrawsContent> child =
1509 make_scoped_refptr(new LayerWithForcedDrawsContent());
1510 render_surface1->SetForceRenderSurface(true);
1511
[email protected]d600df7d2013-08-03 02:34:281512 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1513 host->SetRootLayer(parent);
1514
[email protected]fb661802013-03-25 01:59:321515 const gfx::Transform identity_matrix;
1516 SetLayerPropertiesForTesting(parent.get(),
1517 identity_matrix,
[email protected]fb661802013-03-25 01:59:321518 gfx::PointF(),
1519 gfx::PointF(),
1520 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571521 true,
[email protected]fb661802013-03-25 01:59:321522 false);
1523 SetLayerPropertiesForTesting(render_surface1.get(),
1524 identity_matrix,
[email protected]fb661802013-03-25 01:59:321525 gfx::PointF(),
1526 gfx::PointF(),
1527 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571528 true,
[email protected]fb661802013-03-25 01:59:321529 false);
1530 SetLayerPropertiesForTesting(child.get(),
1531 identity_matrix,
[email protected]fb661802013-03-25 01:59:321532 gfx::PointF(),
1533 gfx::PointF(),
1534 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571535 true,
[email protected]fb661802013-03-25 01:59:321536 false);
1537
1538 parent->AddChild(render_surface1);
1539 render_surface1->AddChild(child);
1540
1541 // Sanity check before the actual test
1542 EXPECT_FALSE(parent->render_surface());
1543 EXPECT_FALSE(render_surface1->render_surface());
1544
[email protected]989386c2013-07-18 21:37:231545 {
1546 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531547 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1548 parent.get(), parent->bounds(), &render_surface_layer_list);
1549 inputs.can_adjust_raster_scales = true;
1550 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321551
[email protected]989386c2013-07-18 21:37:231552 // The root layer always creates a render surface
1553 EXPECT_TRUE(parent->render_surface());
1554 EXPECT_TRUE(render_surface1->render_surface());
1555 EXPECT_EQ(2U, render_surface_layer_list.size());
1556 }
[email protected]fb661802013-03-25 01:59:321557
[email protected]989386c2013-07-18 21:37:231558 {
1559 RenderSurfaceLayerList render_surface_layer_list;
1560 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531561 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1562 parent.get(), parent->bounds(), &render_surface_layer_list);
1563 inputs.can_adjust_raster_scales = true;
1564 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231565 EXPECT_TRUE(parent->render_surface());
1566 EXPECT_FALSE(render_surface1->render_surface());
1567 EXPECT_EQ(1U, render_surface_layer_list.size());
1568 }
[email protected]fb661802013-03-25 01:59:321569}
1570
[email protected]989386c2013-07-18 21:37:231571TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321572 // The entire subtree of layers that are outside the clip rect should be
1573 // culled away, and should not affect the render_surface_layer_list.
1574 //
1575 // The test tree is set up as follows:
1576 // - all layers except the leaf_nodes are forced to be a new render surface
1577 // that have something to draw.
1578 // - parent is a large container layer.
1579 // - child has masksToBounds=true to cause clipping.
1580 // - grand_child is positioned outside of the child's bounds
1581 // - great_grand_child is also kept outside child's bounds.
1582 //
1583 // In this configuration, grand_child and great_grand_child are completely
1584 // outside the clip rect, and they should never get scheduled on the list of
1585 // render surfaces.
1586 //
1587
1588 const gfx::Transform identity_matrix;
1589 scoped_refptr<Layer> parent = Layer::Create();
1590 scoped_refptr<Layer> child = Layer::Create();
1591 scoped_refptr<Layer> grand_child = Layer::Create();
1592 scoped_refptr<Layer> great_grand_child = Layer::Create();
1593 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1594 make_scoped_refptr(new LayerWithForcedDrawsContent());
1595 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1596 make_scoped_refptr(new LayerWithForcedDrawsContent());
1597 parent->AddChild(child);
1598 child->AddChild(grand_child);
1599 grand_child->AddChild(great_grand_child);
1600
[email protected]d600df7d2013-08-03 02:34:281601 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1602 host->SetRootLayer(parent);
1603
[email protected]fb661802013-03-25 01:59:321604 // leaf_node1 ensures that parent and child are kept on the
1605 // render_surface_layer_list, even though grand_child and great_grand_child
1606 // should be clipped.
1607 child->AddChild(leaf_node1);
1608 great_grand_child->AddChild(leaf_node2);
1609
1610 SetLayerPropertiesForTesting(parent.get(),
1611 identity_matrix,
[email protected]fb661802013-03-25 01:59:321612 gfx::PointF(),
1613 gfx::PointF(),
1614 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571615 true,
[email protected]fb661802013-03-25 01:59:321616 false);
1617 SetLayerPropertiesForTesting(child.get(),
1618 identity_matrix,
[email protected]fb661802013-03-25 01:59:321619 gfx::PointF(),
1620 gfx::PointF(),
1621 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571622 true,
[email protected]fb661802013-03-25 01:59:321623 false);
1624 SetLayerPropertiesForTesting(grand_child.get(),
1625 identity_matrix,
[email protected]fb661802013-03-25 01:59:321626 gfx::PointF(),
1627 gfx::PointF(45.f, 45.f),
1628 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571629 true,
[email protected]fb661802013-03-25 01:59:321630 false);
1631 SetLayerPropertiesForTesting(great_grand_child.get(),
1632 identity_matrix,
[email protected]fb661802013-03-25 01:59:321633 gfx::PointF(),
1634 gfx::PointF(),
1635 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571636 true,
[email protected]fb661802013-03-25 01:59:321637 false);
1638 SetLayerPropertiesForTesting(leaf_node1.get(),
1639 identity_matrix,
[email protected]fb661802013-03-25 01:59:321640 gfx::PointF(),
1641 gfx::PointF(),
1642 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571643 true,
[email protected]fb661802013-03-25 01:59:321644 false);
1645 SetLayerPropertiesForTesting(leaf_node2.get(),
1646 identity_matrix,
[email protected]fb661802013-03-25 01:59:321647 gfx::PointF(),
1648 gfx::PointF(),
1649 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571650 true,
[email protected]fb661802013-03-25 01:59:321651 false);
1652
1653 child->SetMasksToBounds(true);
1654 child->SetOpacity(0.4f);
1655 child->SetForceRenderSurface(true);
1656 grand_child->SetOpacity(0.5f);
1657 great_grand_child->SetOpacity(0.4f);
1658
[email protected]989386c2013-07-18 21:37:231659 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531660 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1661 parent.get(), parent->bounds(), &render_surface_layer_list);
1662 inputs.can_adjust_raster_scales = true;
1663 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321664
1665 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231666 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1667 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321668}
1669
[email protected]989386c2013-07-18 21:37:231670TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321671 // When a render surface has a clip rect, it is used to clip the content rect
1672 // of the surface. When the render surface is animating its transforms, then
1673 // the content rect's position in the clip rect is not defined on the main
1674 // thread, and its content rect should not be clipped.
1675
1676 // The test tree is set up as follows:
1677 // - parent is a container layer that masksToBounds=true to cause clipping.
1678 // - child is a render surface, which has a clip rect set to the bounds of
1679 // the parent.
1680 // - grand_child is a render surface, and the only visible content in child.
1681 // It is positioned outside of the clip rect from parent.
1682
1683 // In this configuration, grand_child should be outside the clipped
1684 // content rect of the child, making grand_child not appear in the
1685 // render_surface_layer_list. However, when we place an animation on the
1686 // child, this clipping should be avoided and we should keep the grand_child
1687 // in the render_surface_layer_list.
1688
1689 const gfx::Transform identity_matrix;
1690 scoped_refptr<Layer> parent = Layer::Create();
1691 scoped_refptr<Layer> child = Layer::Create();
1692 scoped_refptr<Layer> grand_child = Layer::Create();
1693 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1694 make_scoped_refptr(new LayerWithForcedDrawsContent());
1695 parent->AddChild(child);
1696 child->AddChild(grand_child);
1697 grand_child->AddChild(leaf_node);
1698
[email protected]d600df7d2013-08-03 02:34:281699 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1700 host->SetRootLayer(parent);
1701
[email protected]fb661802013-03-25 01:59:321702 SetLayerPropertiesForTesting(parent.get(),
1703 identity_matrix,
[email protected]fb661802013-03-25 01:59:321704 gfx::PointF(),
1705 gfx::PointF(),
1706 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571707 true,
[email protected]fb661802013-03-25 01:59:321708 false);
1709 SetLayerPropertiesForTesting(child.get(),
1710 identity_matrix,
[email protected]fb661802013-03-25 01:59:321711 gfx::PointF(),
1712 gfx::PointF(),
1713 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571714 true,
[email protected]fb661802013-03-25 01:59:321715 false);
1716 SetLayerPropertiesForTesting(grand_child.get(),
1717 identity_matrix,
[email protected]fb661802013-03-25 01:59:321718 gfx::PointF(),
1719 gfx::PointF(200.f, 200.f),
1720 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571721 true,
[email protected]fb661802013-03-25 01:59:321722 false);
1723 SetLayerPropertiesForTesting(leaf_node.get(),
1724 identity_matrix,
[email protected]fb661802013-03-25 01:59:321725 gfx::PointF(),
1726 gfx::PointF(),
1727 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571728 true,
[email protected]fb661802013-03-25 01:59:321729 false);
1730
1731 parent->SetMasksToBounds(true);
1732 child->SetOpacity(0.4f);
1733 child->SetForceRenderSurface(true);
1734 grand_child->SetOpacity(0.4f);
1735 grand_child->SetForceRenderSurface(true);
1736
[email protected]989386c2013-07-18 21:37:231737 {
1738 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531739 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1740 parent.get(), parent->bounds(), &render_surface_layer_list);
1741 inputs.can_adjust_raster_scales = true;
1742 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321743
[email protected]989386c2013-07-18 21:37:231744 // Without an animation, we should cull child and grand_child from the
1745 // render_surface_layer_list.
1746 ASSERT_EQ(1U, render_surface_layer_list.size());
1747 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1748 }
[email protected]fb661802013-03-25 01:59:321749
1750 // Now put an animating transform on child.
1751 AddAnimatedTransformToController(
1752 child->layer_animation_controller(), 10.0, 30, 0);
1753
[email protected]989386c2013-07-18 21:37:231754 {
1755 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531756 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1757 parent.get(), parent->bounds(), &render_surface_layer_list);
1758 inputs.can_adjust_raster_scales = true;
1759 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321760
[email protected]989386c2013-07-18 21:37:231761 // With an animating transform, we should keep child and grand_child in the
1762 // render_surface_layer_list.
1763 ASSERT_EQ(3U, render_surface_layer_list.size());
1764 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1765 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1766 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1767 }
[email protected]fb661802013-03-25 01:59:321768}
1769
[email protected]989386c2013-07-18 21:37:231770TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:321771 // Layer's IsClipped() property is set to true when:
1772 // - the layer clips its subtree, e.g. masks to bounds,
1773 // - the layer is clipped by an ancestor that contributes to the same
1774 // render target,
1775 // - a surface is clipped by an ancestor that contributes to the same
1776 // render target.
1777 //
1778 // In particular, for a layer that owns a render surface:
1779 // - the render surface inherits any clip from ancestors, and does NOT
1780 // pass that clipped status to the layer itself.
1781 // - but if the layer itself masks to bounds, it is considered clipped
1782 // and propagates the clip to the subtree.
1783
1784 const gfx::Transform identity_matrix;
1785 scoped_refptr<Layer> root = Layer::Create();
1786 scoped_refptr<Layer> parent = Layer::Create();
1787 scoped_refptr<Layer> child1 = Layer::Create();
1788 scoped_refptr<Layer> child2 = Layer::Create();
1789 scoped_refptr<Layer> grand_child = Layer::Create();
1790 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1791 make_scoped_refptr(new LayerWithForcedDrawsContent());
1792 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1793 make_scoped_refptr(new LayerWithForcedDrawsContent());
1794 root->AddChild(parent);
1795 parent->AddChild(child1);
1796 parent->AddChild(child2);
1797 child1->AddChild(grand_child);
1798 child2->AddChild(leaf_node2);
1799 grand_child->AddChild(leaf_node1);
1800
[email protected]d600df7d2013-08-03 02:34:281801 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1802 host->SetRootLayer(root);
1803
[email protected]fb661802013-03-25 01:59:321804 child2->SetForceRenderSurface(true);
1805
1806 SetLayerPropertiesForTesting(root.get(),
1807 identity_matrix,
[email protected]fb661802013-03-25 01:59:321808 gfx::PointF(),
1809 gfx::PointF(),
1810 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571811 true,
[email protected]fb661802013-03-25 01:59:321812 false);
1813 SetLayerPropertiesForTesting(parent.get(),
1814 identity_matrix,
[email protected]fb661802013-03-25 01:59:321815 gfx::PointF(),
1816 gfx::PointF(),
1817 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571818 true,
[email protected]fb661802013-03-25 01:59:321819 false);
1820 SetLayerPropertiesForTesting(child1.get(),
1821 identity_matrix,
[email protected]fb661802013-03-25 01:59:321822 gfx::PointF(),
1823 gfx::PointF(),
1824 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571825 true,
[email protected]fb661802013-03-25 01:59:321826 false);
1827 SetLayerPropertiesForTesting(child2.get(),
1828 identity_matrix,
[email protected]fb661802013-03-25 01:59:321829 gfx::PointF(),
1830 gfx::PointF(),
1831 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571832 true,
[email protected]fb661802013-03-25 01:59:321833 false);
1834 SetLayerPropertiesForTesting(grand_child.get(),
1835 identity_matrix,
[email protected]fb661802013-03-25 01:59:321836 gfx::PointF(),
1837 gfx::PointF(),
1838 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571839 true,
[email protected]fb661802013-03-25 01:59:321840 false);
1841 SetLayerPropertiesForTesting(leaf_node1.get(),
1842 identity_matrix,
[email protected]fb661802013-03-25 01:59:321843 gfx::PointF(),
1844 gfx::PointF(),
1845 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571846 true,
[email protected]fb661802013-03-25 01:59:321847 false);
1848 SetLayerPropertiesForTesting(leaf_node2.get(),
1849 identity_matrix,
[email protected]fb661802013-03-25 01:59:321850 gfx::PointF(),
1851 gfx::PointF(),
1852 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571853 true,
[email protected]fb661802013-03-25 01:59:321854 false);
1855
[email protected]989386c2013-07-18 21:37:231856 // Case 1: nothing is clipped except the root render surface.
1857 {
1858 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531859 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1860 root.get(), parent->bounds(), &render_surface_layer_list);
1861 inputs.can_adjust_raster_scales = true;
1862 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321863
[email protected]989386c2013-07-18 21:37:231864 ASSERT_TRUE(root->render_surface());
1865 ASSERT_TRUE(child2->render_surface());
1866
1867 EXPECT_FALSE(root->is_clipped());
1868 EXPECT_TRUE(root->render_surface()->is_clipped());
1869 EXPECT_FALSE(parent->is_clipped());
1870 EXPECT_FALSE(child1->is_clipped());
1871 EXPECT_FALSE(child2->is_clipped());
1872 EXPECT_FALSE(child2->render_surface()->is_clipped());
1873 EXPECT_FALSE(grand_child->is_clipped());
1874 EXPECT_FALSE(leaf_node1->is_clipped());
1875 EXPECT_FALSE(leaf_node2->is_clipped());
1876 }
[email protected]fb661802013-03-25 01:59:321877
1878 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1879 // surface are clipped. But layers that contribute to child2's surface are
1880 // not clipped explicitly because child2's surface already accounts for
1881 // that clip.
[email protected]989386c2013-07-18 21:37:231882 {
1883 RenderSurfaceLayerList render_surface_layer_list;
1884 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531885 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1886 root.get(), parent->bounds(), &render_surface_layer_list);
1887 inputs.can_adjust_raster_scales = true;
1888 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321889
[email protected]989386c2013-07-18 21:37:231890 ASSERT_TRUE(root->render_surface());
1891 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321892
[email protected]989386c2013-07-18 21:37:231893 EXPECT_FALSE(root->is_clipped());
1894 EXPECT_TRUE(root->render_surface()->is_clipped());
1895 EXPECT_TRUE(parent->is_clipped());
1896 EXPECT_TRUE(child1->is_clipped());
1897 EXPECT_FALSE(child2->is_clipped());
1898 EXPECT_TRUE(child2->render_surface()->is_clipped());
1899 EXPECT_TRUE(grand_child->is_clipped());
1900 EXPECT_TRUE(leaf_node1->is_clipped());
1901 EXPECT_FALSE(leaf_node2->is_clipped());
1902 }
[email protected]fb661802013-03-25 01:59:321903
1904 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1905 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:231906 {
1907 RenderSurfaceLayerList render_surface_layer_list;
1908 parent->SetMasksToBounds(false);
1909 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531910 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1911 root.get(), parent->bounds(), &render_surface_layer_list);
1912 inputs.can_adjust_raster_scales = true;
1913 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321914
[email protected]989386c2013-07-18 21:37:231915 ASSERT_TRUE(root->render_surface());
1916 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321917
[email protected]989386c2013-07-18 21:37:231918 EXPECT_FALSE(root->is_clipped());
1919 EXPECT_TRUE(root->render_surface()->is_clipped());
1920 EXPECT_FALSE(parent->is_clipped());
1921 EXPECT_FALSE(child1->is_clipped());
1922 EXPECT_TRUE(child2->is_clipped());
1923 EXPECT_FALSE(child2->render_surface()->is_clipped());
1924 EXPECT_FALSE(grand_child->is_clipped());
1925 EXPECT_FALSE(leaf_node1->is_clipped());
1926 EXPECT_TRUE(leaf_node2->is_clipped());
1927 }
[email protected]fb661802013-03-25 01:59:321928}
1929
[email protected]fd9a3b6d2013-08-03 00:46:171930TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321931 // Verify that layers get the appropriate DrawableContentRect when their
1932 // parent masksToBounds is true.
1933 //
1934 // grand_child1 - completely inside the region; DrawableContentRect should
1935 // be the layer rect expressed in target space.
1936 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1937 // will be the intersection of layer bounds and the mask region.
1938 // grand_child3 - partially clipped and masksToBounds; the
1939 // DrawableContentRect will still be the intersection of layer bounds and
1940 // the mask region.
1941 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1942 // be empty.
1943 //
1944
1945 const gfx::Transform identity_matrix;
1946 scoped_refptr<Layer> parent = Layer::Create();
1947 scoped_refptr<Layer> child = Layer::Create();
1948 scoped_refptr<Layer> grand_child1 = Layer::Create();
1949 scoped_refptr<Layer> grand_child2 = Layer::Create();
1950 scoped_refptr<Layer> grand_child3 = Layer::Create();
1951 scoped_refptr<Layer> grand_child4 = Layer::Create();
1952
1953 parent->AddChild(child);
1954 child->AddChild(grand_child1);
1955 child->AddChild(grand_child2);
1956 child->AddChild(grand_child3);
1957 child->AddChild(grand_child4);
1958
[email protected]d600df7d2013-08-03 02:34:281959 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1960 host->SetRootLayer(parent);
1961
[email protected]fb661802013-03-25 01:59:321962 SetLayerPropertiesForTesting(parent.get(),
1963 identity_matrix,
[email protected]fb661802013-03-25 01:59:321964 gfx::PointF(),
1965 gfx::PointF(),
1966 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571967 true,
[email protected]fb661802013-03-25 01:59:321968 false);
1969 SetLayerPropertiesForTesting(child.get(),
1970 identity_matrix,
[email protected]fb661802013-03-25 01:59:321971 gfx::PointF(),
1972 gfx::PointF(),
1973 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571974 true,
[email protected]fb661802013-03-25 01:59:321975 false);
1976 SetLayerPropertiesForTesting(grand_child1.get(),
1977 identity_matrix,
[email protected]fb661802013-03-25 01:59:321978 gfx::PointF(),
1979 gfx::PointF(5.f, 5.f),
1980 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571981 true,
[email protected]fb661802013-03-25 01:59:321982 false);
1983 SetLayerPropertiesForTesting(grand_child2.get(),
1984 identity_matrix,
[email protected]fb661802013-03-25 01:59:321985 gfx::PointF(),
1986 gfx::PointF(15.f, 15.f),
1987 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571988 true,
[email protected]fb661802013-03-25 01:59:321989 false);
1990 SetLayerPropertiesForTesting(grand_child3.get(),
1991 identity_matrix,
[email protected]fb661802013-03-25 01:59:321992 gfx::PointF(),
1993 gfx::PointF(15.f, 15.f),
1994 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571995 true,
[email protected]fb661802013-03-25 01:59:321996 false);
1997 SetLayerPropertiesForTesting(grand_child4.get(),
1998 identity_matrix,
[email protected]fb661802013-03-25 01:59:321999 gfx::PointF(),
2000 gfx::PointF(45.f, 45.f),
2001 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572002 true,
[email protected]fb661802013-03-25 01:59:322003 false);
2004
2005 child->SetMasksToBounds(true);
2006 grand_child3->SetMasksToBounds(true);
2007
2008 // Force everyone to be a render surface.
2009 child->SetOpacity(0.4f);
2010 grand_child1->SetOpacity(0.5f);
2011 grand_child2->SetOpacity(0.5f);
2012 grand_child3->SetOpacity(0.5f);
2013 grand_child4->SetOpacity(0.5f);
2014
[email protected]989386c2013-07-18 21:37:232015 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532016 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2017 parent.get(), parent->bounds(), &render_surface_layer_list);
2018 inputs.can_adjust_raster_scales = true;
2019 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322020
[email protected]2c7c6702013-03-26 03:14:052021 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
[email protected]fb661802013-03-25 01:59:322022 grand_child1->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:052023 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:322024 grand_child3->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:052025 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:322026 grand_child3->drawable_content_rect());
2027 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2028}
2029
[email protected]989386c2013-07-18 21:37:232030TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322031 // Verify that render surfaces (and their layers) get the appropriate
2032 // clip rects when their parent masksToBounds is true.
2033 //
2034 // Layers that own render surfaces (at least for now) do not inherit any
2035 // clipping; instead the surface will enforce the clip for the entire subtree.
2036 // They may still have a clip rect of their own layer bounds, however, if
2037 // masksToBounds was true.
2038 const gfx::Transform identity_matrix;
2039 scoped_refptr<Layer> parent = Layer::Create();
2040 scoped_refptr<Layer> child = Layer::Create();
2041 scoped_refptr<Layer> grand_child1 = Layer::Create();
2042 scoped_refptr<Layer> grand_child2 = Layer::Create();
2043 scoped_refptr<Layer> grand_child3 = Layer::Create();
2044 scoped_refptr<Layer> grand_child4 = Layer::Create();
2045 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2046 make_scoped_refptr(new LayerWithForcedDrawsContent());
2047 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2048 make_scoped_refptr(new LayerWithForcedDrawsContent());
2049 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
2050 make_scoped_refptr(new LayerWithForcedDrawsContent());
2051 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
2052 make_scoped_refptr(new LayerWithForcedDrawsContent());
2053
2054 parent->AddChild(child);
2055 child->AddChild(grand_child1);
2056 child->AddChild(grand_child2);
2057 child->AddChild(grand_child3);
2058 child->AddChild(grand_child4);
2059
[email protected]d600df7d2013-08-03 02:34:282060 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2061 host->SetRootLayer(parent);
2062
[email protected]fb661802013-03-25 01:59:322063 // the leaf nodes ensure that these grand_children become render surfaces for
2064 // this test.
2065 grand_child1->AddChild(leaf_node1);
2066 grand_child2->AddChild(leaf_node2);
2067 grand_child3->AddChild(leaf_node3);
2068 grand_child4->AddChild(leaf_node4);
2069
2070 SetLayerPropertiesForTesting(parent.get(),
2071 identity_matrix,
[email protected]fb661802013-03-25 01:59:322072 gfx::PointF(),
2073 gfx::PointF(),
2074 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:572075 true,
[email protected]fb661802013-03-25 01:59:322076 false);
2077 SetLayerPropertiesForTesting(child.get(),
2078 identity_matrix,
[email protected]fb661802013-03-25 01:59:322079 gfx::PointF(),
2080 gfx::PointF(),
2081 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:572082 true,
[email protected]fb661802013-03-25 01:59:322083 false);
2084 SetLayerPropertiesForTesting(grand_child1.get(),
2085 identity_matrix,
[email protected]fb661802013-03-25 01:59:322086 gfx::PointF(),
2087 gfx::PointF(5.f, 5.f),
2088 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572089 true,
[email protected]fb661802013-03-25 01:59:322090 false);
2091 SetLayerPropertiesForTesting(grand_child2.get(),
2092 identity_matrix,
[email protected]fb661802013-03-25 01:59:322093 gfx::PointF(),
2094 gfx::PointF(15.f, 15.f),
2095 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572096 true,
[email protected]fb661802013-03-25 01:59:322097 false);
2098 SetLayerPropertiesForTesting(grand_child3.get(),
2099 identity_matrix,
[email protected]fb661802013-03-25 01:59:322100 gfx::PointF(),
2101 gfx::PointF(15.f, 15.f),
2102 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572103 true,
[email protected]fb661802013-03-25 01:59:322104 false);
2105 SetLayerPropertiesForTesting(grand_child4.get(),
2106 identity_matrix,
[email protected]fb661802013-03-25 01:59:322107 gfx::PointF(),
2108 gfx::PointF(45.f, 45.f),
2109 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572110 true,
[email protected]fb661802013-03-25 01:59:322111 false);
2112 SetLayerPropertiesForTesting(leaf_node1.get(),
2113 identity_matrix,
[email protected]fb661802013-03-25 01:59:322114 gfx::PointF(),
2115 gfx::PointF(),
2116 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572117 true,
[email protected]fb661802013-03-25 01:59:322118 false);
2119 SetLayerPropertiesForTesting(leaf_node2.get(),
2120 identity_matrix,
[email protected]fb661802013-03-25 01:59:322121 gfx::PointF(),
2122 gfx::PointF(),
2123 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572124 true,
[email protected]fb661802013-03-25 01:59:322125 false);
2126 SetLayerPropertiesForTesting(leaf_node3.get(),
2127 identity_matrix,
[email protected]fb661802013-03-25 01:59:322128 gfx::PointF(),
2129 gfx::PointF(),
2130 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572131 true,
[email protected]fb661802013-03-25 01:59:322132 false);
2133 SetLayerPropertiesForTesting(leaf_node4.get(),
2134 identity_matrix,
[email protected]fb661802013-03-25 01:59:322135 gfx::PointF(),
2136 gfx::PointF(),
2137 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572138 true,
[email protected]fb661802013-03-25 01:59:322139 false);
2140
2141 child->SetMasksToBounds(true);
2142 grand_child3->SetMasksToBounds(true);
2143 grand_child4->SetMasksToBounds(true);
2144
2145 // Force everyone to be a render surface.
2146 child->SetOpacity(0.4f);
2147 child->SetForceRenderSurface(true);
2148 grand_child1->SetOpacity(0.5f);
2149 grand_child1->SetForceRenderSurface(true);
2150 grand_child2->SetOpacity(0.5f);
2151 grand_child2->SetForceRenderSurface(true);
2152 grand_child3->SetOpacity(0.5f);
2153 grand_child3->SetForceRenderSurface(true);
2154 grand_child4->SetOpacity(0.5f);
2155 grand_child4->SetForceRenderSurface(true);
2156
[email protected]989386c2013-07-18 21:37:232157 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532158 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2159 parent.get(), parent->bounds(), &render_surface_layer_list);
2160 inputs.can_adjust_raster_scales = true;
2161 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322162 ASSERT_TRUE(grand_child1->render_surface());
2163 ASSERT_TRUE(grand_child2->render_surface());
2164 ASSERT_TRUE(grand_child3->render_surface());
2165 // Because grand_child4 is entirely clipped, it is expected to not have a
2166 // render surface.
2167 EXPECT_FALSE(grand_child4->render_surface());
2168
2169 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2170 // masksToBounds.
[email protected]2c7c6702013-03-26 03:14:052171 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322172 grand_child1->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052173 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322174 grand_child2->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052175 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322176 grand_child3->render_surface()->clip_rect());
2177}
2178
[email protected]989386c2013-07-18 21:37:232179TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322180 scoped_refptr<Layer> parent = Layer::Create();
2181 scoped_refptr<Layer> render_surface1 = Layer::Create();
2182 scoped_refptr<Layer> render_surface2 = Layer::Create();
2183 scoped_refptr<Layer> child_of_root = Layer::Create();
2184 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2185 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2186 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2187 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2188 make_scoped_refptr(new LayerWithForcedDrawsContent());
2189 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2190 make_scoped_refptr(new LayerWithForcedDrawsContent());
2191 parent->AddChild(render_surface1);
2192 parent->AddChild(child_of_root);
2193 render_surface1->AddChild(child_of_rs1);
2194 render_surface1->AddChild(render_surface2);
2195 render_surface2->AddChild(child_of_rs2);
2196 child_of_root->AddChild(grand_child_of_root);
2197 child_of_rs1->AddChild(grand_child_of_rs1);
2198 child_of_rs2->AddChild(grand_child_of_rs2);
2199
[email protected]d600df7d2013-08-03 02:34:282200 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2201 host->SetRootLayer(parent);
2202
[email protected]fb661802013-03-25 01:59:322203 // Make our render surfaces.
2204 render_surface1->SetForceRenderSurface(true);
2205 render_surface2->SetForceRenderSurface(true);
2206
2207 gfx::Transform layer_transform;
2208 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322209
2210 SetLayerPropertiesForTesting(parent.get(),
2211 layer_transform,
[email protected]fb661802013-03-25 01:59:322212 gfx::PointF(0.25f, 0.f),
2213 gfx::PointF(2.5f, 0.f),
2214 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572215 true,
[email protected]fb661802013-03-25 01:59:322216 false);
2217 SetLayerPropertiesForTesting(render_surface1.get(),
2218 layer_transform,
[email protected]fb661802013-03-25 01:59:322219 gfx::PointF(0.25f, 0.f),
2220 gfx::PointF(2.5f, 0.f),
2221 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572222 true,
[email protected]fb661802013-03-25 01:59:322223 false);
2224 SetLayerPropertiesForTesting(render_surface2.get(),
2225 layer_transform,
[email protected]fb661802013-03-25 01:59:322226 gfx::PointF(0.25f, 0.f),
2227 gfx::PointF(2.5f, 0.f),
2228 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572229 true,
[email protected]fb661802013-03-25 01:59:322230 false);
2231 SetLayerPropertiesForTesting(child_of_root.get(),
2232 layer_transform,
[email protected]fb661802013-03-25 01:59:322233 gfx::PointF(0.25f, 0.f),
2234 gfx::PointF(2.5f, 0.f),
2235 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572236 true,
[email protected]fb661802013-03-25 01:59:322237 false);
2238 SetLayerPropertiesForTesting(child_of_rs1.get(),
2239 layer_transform,
[email protected]fb661802013-03-25 01:59:322240 gfx::PointF(0.25f, 0.f),
2241 gfx::PointF(2.5f, 0.f),
2242 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572243 true,
[email protected]fb661802013-03-25 01:59:322244 false);
2245 SetLayerPropertiesForTesting(child_of_rs2.get(),
2246 layer_transform,
[email protected]fb661802013-03-25 01:59:322247 gfx::PointF(0.25f, 0.f),
2248 gfx::PointF(2.5f, 0.f),
2249 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572250 true,
[email protected]fb661802013-03-25 01:59:322251 false);
2252 SetLayerPropertiesForTesting(grand_child_of_root.get(),
2253 layer_transform,
[email protected]fb661802013-03-25 01:59:322254 gfx::PointF(0.25f, 0.f),
2255 gfx::PointF(2.5f, 0.f),
2256 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572257 true,
[email protected]fb661802013-03-25 01:59:322258 false);
2259 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
2260 layer_transform,
[email protected]fb661802013-03-25 01:59:322261 gfx::PointF(0.25f, 0.f),
2262 gfx::PointF(2.5f, 0.f),
2263 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572264 true,
[email protected]fb661802013-03-25 01:59:322265 false);
2266 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
2267 layer_transform,
[email protected]fb661802013-03-25 01:59:322268 gfx::PointF(0.25f, 0.f),
2269 gfx::PointF(2.5f, 0.f),
2270 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572271 true,
[email protected]fb661802013-03-25 01:59:322272 false);
2273
2274 // Put an animated opacity on the render surface.
2275 AddOpacityTransitionToController(
2276 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2277
2278 // Also put an animated opacity on a layer without descendants.
2279 AddOpacityTransitionToController(
2280 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2281
2282 // Put a transform animation on the render surface.
2283 AddAnimatedTransformToController(
2284 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2285
2286 // Also put transform animations on grand_child_of_root, and
2287 // grand_child_of_rs2
2288 AddAnimatedTransformToController(
2289 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2290 AddAnimatedTransformToController(
2291 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2292
2293 ExecuteCalculateDrawProperties(parent.get());
2294
2295 // Only layers that are associated with render surfaces should have an actual
2296 // RenderSurface() value.
2297 ASSERT_TRUE(parent->render_surface());
2298 ASSERT_FALSE(child_of_root->render_surface());
2299 ASSERT_FALSE(grand_child_of_root->render_surface());
2300
2301 ASSERT_TRUE(render_surface1->render_surface());
2302 ASSERT_FALSE(child_of_rs1->render_surface());
2303 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2304
2305 ASSERT_TRUE(render_surface2->render_surface());
2306 ASSERT_FALSE(child_of_rs2->render_surface());
2307 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2308
2309 // Verify all render target accessors
2310 EXPECT_EQ(parent, parent->render_target());
2311 EXPECT_EQ(parent, child_of_root->render_target());
2312 EXPECT_EQ(parent, grand_child_of_root->render_target());
2313
2314 EXPECT_EQ(render_surface1, render_surface1->render_target());
2315 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2316 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
2317
2318 EXPECT_EQ(render_surface2, render_surface2->render_target());
2319 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2320 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
2321
2322 // Verify draw_opacity_is_animating values
2323 EXPECT_FALSE(parent->draw_opacity_is_animating());
2324 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2325 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2326 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2327 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2328 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2329 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2330 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2331 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2332 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2333 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2334
2335 // Verify draw_transform_is_animating values
2336 EXPECT_FALSE(parent->draw_transform_is_animating());
2337 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2338 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2339 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2340 EXPECT_FALSE(render_surface1->render_surface()
2341 ->target_surface_transforms_are_animating());
2342 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2343 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2344 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2345 EXPECT_TRUE(render_surface2->render_surface()
2346 ->target_surface_transforms_are_animating());
2347 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2348 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2349
2350 // Verify screen_space_transform_is_animating values
2351 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2352 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2353 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2354 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2355 EXPECT_FALSE(render_surface1->render_surface()
2356 ->screen_space_transforms_are_animating());
2357 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2358 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2359 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2360 EXPECT_TRUE(render_surface2->render_surface()
2361 ->screen_space_transforms_are_animating());
2362 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2363 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2364
2365 // Sanity check. If these fail there is probably a bug in the test itself.
2366 // It is expected that we correctly set up transforms so that the y-component
2367 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262368 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2369 EXPECT_FLOAT_EQ(2.0,
2370 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322371 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262372 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322373
[email protected]803f6b52013-09-12 00:51:262374 EXPECT_FLOAT_EQ(2.0,
2375 render_surface1->screen_space_transform().matrix().get(1, 3));
2376 EXPECT_FLOAT_EQ(3.0,
2377 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322378 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262379 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322380
[email protected]803f6b52013-09-12 00:51:262381 EXPECT_FLOAT_EQ(3.0,
2382 render_surface2->screen_space_transform().matrix().get(1, 3));
2383 EXPECT_FLOAT_EQ(4.0,
2384 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322385 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262386 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322387}
2388
[email protected]989386c2013-07-18 21:37:232389TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322390 // Test the calculateVisibleRect() function works correctly for identity
2391 // transforms.
2392
[email protected]2c7c6702013-03-26 03:14:052393 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322394 gfx::Transform layer_to_surface_transform;
2395
2396 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232397 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052398 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322399 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2400 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2401 EXPECT_RECT_EQ(expected, actual);
2402
2403 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052404 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322405 actual = LayerTreeHostCommon::CalculateVisibleRect(
2406 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2407 EXPECT_TRUE(actual.IsEmpty());
2408
2409 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052410 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2411 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322412 actual = LayerTreeHostCommon::CalculateVisibleRect(
2413 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2414 EXPECT_RECT_EQ(expected, actual);
2415}
2416
[email protected]989386c2013-07-18 21:37:232417TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322418 // Test the calculateVisibleRect() function works correctly for scaling
2419 // transforms.
2420
[email protected]2c7c6702013-03-26 03:14:052421 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2422 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322423 gfx::Transform layer_to_surface_transform;
2424
2425 // Case 1: Layer is contained within the surface.
2426 layer_to_surface_transform.MakeIdentity();
2427 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052428 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322429 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2430 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2431 EXPECT_RECT_EQ(expected, actual);
2432
2433 // Case 2: Layer is outside the surface rect.
2434 layer_to_surface_transform.MakeIdentity();
2435 layer_to_surface_transform.Translate(120.0, 120.0);
2436 actual = LayerTreeHostCommon::CalculateVisibleRect(
2437 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2438 EXPECT_TRUE(actual.IsEmpty());
2439
2440 // Case 3: Layer is partially overlapping the surface rect.
2441 layer_to_surface_transform.MakeIdentity();
2442 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052443 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322444 actual = LayerTreeHostCommon::CalculateVisibleRect(
2445 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2446 EXPECT_RECT_EQ(expected, actual);
2447}
2448
[email protected]989386c2013-07-18 21:37:232449TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322450 // Test the calculateVisibleRect() function works correctly for rotations
2451 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2452 // should return the g in the layer's space.
2453
[email protected]2c7c6702013-03-26 03:14:052454 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2455 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322456 gfx::Transform layer_to_surface_transform;
2457
2458 // Case 1: Layer is contained within the surface.
2459 layer_to_surface_transform.MakeIdentity();
2460 layer_to_surface_transform.Translate(50.0, 50.0);
2461 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052462 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322463 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2464 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2465 EXPECT_RECT_EQ(expected, actual);
2466
2467 // Case 2: Layer is outside the surface rect.
2468 layer_to_surface_transform.MakeIdentity();
2469 layer_to_surface_transform.Translate(-50.0, 0.0);
2470 layer_to_surface_transform.Rotate(45.0);
2471 actual = LayerTreeHostCommon::CalculateVisibleRect(
2472 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2473 EXPECT_TRUE(actual.IsEmpty());
2474
2475 // Case 3: The layer is rotated about its top-left corner. In surface space,
2476 // the layer is oriented diagonally, with the left half outside of the render
2477 // surface. In this case, the g should still be the entire layer
2478 // (remember the g is computed in layer space); both the top-left
2479 // and bottom-right corners of the layer are still visible.
2480 layer_to_surface_transform.MakeIdentity();
2481 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052482 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322483 actual = LayerTreeHostCommon::CalculateVisibleRect(
2484 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2485 EXPECT_RECT_EQ(expected, actual);
2486
2487 // Case 4: The layer is rotated about its top-left corner, and translated
2488 // upwards. In surface space, the layer is oriented diagonally, with only the
2489 // top corner of the surface overlapping the layer. In layer space, the render
2490 // surface overlaps the right side of the layer. The g should be
2491 // the layer's right half.
2492 layer_to_surface_transform.MakeIdentity();
2493 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2494 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052495 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322496 actual = LayerTreeHostCommon::CalculateVisibleRect(
2497 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2498 EXPECT_RECT_EQ(expected, actual);
2499}
2500
[email protected]989386c2013-07-18 21:37:232501TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322502 // Test that the calculateVisibleRect() function works correctly for 3d
2503 // transforms.
2504
[email protected]2c7c6702013-03-26 03:14:052505 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2506 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322507 gfx::Transform layer_to_surface_transform;
2508
2509 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2510 // degrees, should be fully contained in the render surface.
2511 layer_to_surface_transform.MakeIdentity();
2512 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052513 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322514 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2515 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2516 EXPECT_RECT_EQ(expected, actual);
2517
2518 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2519 // degrees, but shifted to the side so only the right-half the layer would be
2520 // visible on the surface.
2521 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262522 SkMScalar half_width_of_rotated_layer =
2523 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322524 layer_to_surface_transform.MakeIdentity();
2525 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232526 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2527 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052528 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322529 actual = LayerTreeHostCommon::CalculateVisibleRect(
2530 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2531 EXPECT_RECT_EQ(expected, actual);
2532}
2533
[email protected]989386c2013-07-18 21:37:232534TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322535 // Test the calculateVisibleRect() function works correctly when the layer has
2536 // a perspective projection onto the target surface.
2537
[email protected]2c7c6702013-03-26 03:14:052538 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2539 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322540 gfx::Transform layer_to_surface_transform;
2541
2542 // Case 1: Even though the layer is twice as large as the surface, due to
2543 // perspective foreshortening, the layer will fit fully in the surface when
2544 // its translated more than the perspective amount.
2545 layer_to_surface_transform.MakeIdentity();
2546
2547 // The following sequence of transforms applies the perspective about the
2548 // center of the surface.
2549 layer_to_surface_transform.Translate(50.0, 50.0);
2550 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2551 layer_to_surface_transform.Translate(-50.0, -50.0);
2552
2553 // This translate places the layer in front of the surface's projection plane.
2554 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2555
[email protected]2c7c6702013-03-26 03:14:052556 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322557 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2558 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2559 EXPECT_RECT_EQ(expected, actual);
2560
2561 // Case 2: same projection as before, except that the layer is also translated
2562 // to the side, so that only the right half of the layer should be visible.
2563 //
2564 // Explanation of expected result: The perspective ratio is (z distance
2565 // between layer and camera origin) / (z distance between projection plane and
2566 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2567 // move a layer by translating -50 units in projected surface units (so that
2568 // only half of it is visible), then we would need to translate by (-36 / 9) *
2569 // -50 == -200 in the layer's units.
2570 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232571 expected = gfx::Rect(gfx::Point(50, -50),
2572 gfx::Size(100, 200)); // The right half of the layer's
2573 // bounding rect.
[email protected]fb661802013-03-25 01:59:322574 actual = LayerTreeHostCommon::CalculateVisibleRect(
2575 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2576 EXPECT_RECT_EQ(expected, actual);
2577}
2578
[email protected]989386c2013-07-18 21:37:232579TEST_F(LayerTreeHostCommonTest,
2580 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322581 // There is currently no explicit concept of an orthographic projection plane
2582 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2583 // are technically behind the surface in an orthographic world should not be
2584 // clipped when they are flattened to the surface.
2585
[email protected]2c7c6702013-03-26 03:14:052586 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2587 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322588 gfx::Transform layer_to_surface_transform;
2589
2590 // This sequence of transforms effectively rotates the layer about the y-axis
2591 // at the center of the layer.
2592 layer_to_surface_transform.MakeIdentity();
2593 layer_to_surface_transform.Translate(50.0, 0.0);
2594 layer_to_surface_transform.RotateAboutYAxis(45.0);
2595 layer_to_surface_transform.Translate(-50.0, 0.0);
2596
[email protected]2c7c6702013-03-26 03:14:052597 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322598 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2599 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2600 EXPECT_RECT_EQ(expected, actual);
2601}
2602
[email protected]989386c2013-07-18 21:37:232603TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322604 // Test the calculateVisibleRect() function works correctly when projecting a
2605 // surface onto a layer, but the layer is partially behind the camera (not
2606 // just behind the projection plane). In this case, the cartesian coordinates
2607 // may seem to be valid, but actually they are not. The visible rect needs to
2608 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2609 // converting to cartesian coordinates.
2610
[email protected]2c7c6702013-03-26 03:14:052611 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232612 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322613 gfx::Transform layer_to_surface_transform;
2614
2615 // The layer is positioned so that the right half of the layer should be in
2616 // front of the camera, while the other half is behind the surface's
2617 // projection plane. The following sequence of transforms applies the
2618 // perspective and rotation about the center of the layer.
2619 layer_to_surface_transform.MakeIdentity();
2620 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2621 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2622 layer_to_surface_transform.RotateAboutYAxis(45.0);
2623
2624 // Sanity check that this transform does indeed cause w < 0 when applying the
2625 // transform, otherwise this code is not testing the intended scenario.
2626 bool clipped;
2627 MathUtil::MapQuad(layer_to_surface_transform,
2628 gfx::QuadF(gfx::RectF(layer_content_rect)),
2629 &clipped);
2630 ASSERT_TRUE(clipped);
2631
2632 int expected_x_position = 0;
2633 int expected_width = 10;
2634 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2635 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2636 EXPECT_EQ(expected_x_position, actual.x());
2637 EXPECT_EQ(expected_width, actual.width());
2638}
2639
[email protected]989386c2013-07-18 21:37:232640TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322641 // To determine visible rect in layer space, there needs to be an
2642 // un-projection from surface space to layer space. When the original
2643 // transform was a perspective projection that was clipped, it returns a rect
2644 // that encloses the clipped bounds. Un-projecting this new rect may require
2645 // clipping again.
2646
2647 // This sequence of transforms causes one corner of the layer to protrude
2648 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232649 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2650 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322651 gfx::Transform layer_to_surface_transform;
2652 layer_to_surface_transform.MakeIdentity();
2653 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2654 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2655 layer_to_surface_transform.RotateAboutYAxis(45.0);
2656 layer_to_surface_transform.RotateAboutXAxis(80.0);
2657
2658 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2659 // code is not testing the intended scenario.
2660 bool clipped;
2661 gfx::RectF clipped_rect =
2662 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2663 MathUtil::ProjectQuad(
2664 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2665 ASSERT_TRUE(clipped);
2666
2667 // Only the corner of the layer is not visible on the surface because of being
2668 // clipped. But, the net result of rounding visible region to an axis-aligned
2669 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052670 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322671 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2672 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2673 EXPECT_RECT_EQ(expected, actual);
2674}
2675
[email protected]989386c2013-07-18 21:37:232676TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322677 scoped_refptr<Layer> root = Layer::Create();
2678 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2679 make_scoped_refptr(new LayerWithForcedDrawsContent());
2680 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2681 make_scoped_refptr(new LayerWithForcedDrawsContent());
2682 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2683 make_scoped_refptr(new LayerWithForcedDrawsContent());
2684 root->AddChild(child1);
2685 root->AddChild(child2);
2686 root->AddChild(child3);
2687
[email protected]d600df7d2013-08-03 02:34:282688 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2689 host->SetRootLayer(root);
2690
[email protected]fb661802013-03-25 01:59:322691 gfx::Transform identity_matrix;
2692 SetLayerPropertiesForTesting(root.get(),
2693 identity_matrix,
[email protected]fb661802013-03-25 01:59:322694 gfx::PointF(),
2695 gfx::PointF(),
2696 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572697 true,
[email protected]fb661802013-03-25 01:59:322698 false);
2699 SetLayerPropertiesForTesting(child1.get(),
2700 identity_matrix,
[email protected]fb661802013-03-25 01:59:322701 gfx::PointF(),
2702 gfx::PointF(),
2703 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572704 true,
[email protected]fb661802013-03-25 01:59:322705 false);
2706 SetLayerPropertiesForTesting(child2.get(),
2707 identity_matrix,
[email protected]fb661802013-03-25 01:59:322708 gfx::PointF(),
2709 gfx::PointF(75.f, 75.f),
2710 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572711 true,
[email protected]fb661802013-03-25 01:59:322712 false);
2713 SetLayerPropertiesForTesting(child3.get(),
2714 identity_matrix,
[email protected]fb661802013-03-25 01:59:322715 gfx::PointF(),
2716 gfx::PointF(125.f, 125.f),
2717 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572718 true,
[email protected]fb661802013-03-25 01:59:322719 false);
2720
2721 ExecuteCalculateDrawProperties(root.get());
2722
2723 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2724 root->render_surface()->DrawableContentRect());
2725 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2726
2727 // Layers that do not draw content should have empty visible_content_rects.
2728 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2729
2730 // layer visible_content_rects are clipped by their target surface.
2731 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2732 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
2733 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
2734
2735 // layer drawable_content_rects are not clipped.
2736 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2737 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2738 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2739}
2740
[email protected]989386c2013-07-18 21:37:232741TEST_F(LayerTreeHostCommonTest,
2742 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:322743 scoped_refptr<Layer> root = Layer::Create();
2744 scoped_refptr<Layer> child = Layer::Create();
2745 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
2746 make_scoped_refptr(new LayerWithForcedDrawsContent());
2747 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
2748 make_scoped_refptr(new LayerWithForcedDrawsContent());
2749 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
2750 make_scoped_refptr(new LayerWithForcedDrawsContent());
2751 root->AddChild(child);
2752 child->AddChild(grand_child1);
2753 child->AddChild(grand_child2);
2754 child->AddChild(grand_child3);
2755
[email protected]d600df7d2013-08-03 02:34:282756 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2757 host->SetRootLayer(root);
2758
[email protected]fb661802013-03-25 01:59:322759 gfx::Transform identity_matrix;
2760 SetLayerPropertiesForTesting(root.get(),
2761 identity_matrix,
[email protected]fb661802013-03-25 01:59:322762 gfx::PointF(),
2763 gfx::PointF(),
2764 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572765 true,
[email protected]fb661802013-03-25 01:59:322766 false);
2767 SetLayerPropertiesForTesting(child.get(),
2768 identity_matrix,
[email protected]fb661802013-03-25 01:59:322769 gfx::PointF(),
2770 gfx::PointF(),
2771 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572772 true,
[email protected]fb661802013-03-25 01:59:322773 false);
2774 SetLayerPropertiesForTesting(grand_child1.get(),
2775 identity_matrix,
[email protected]fb661802013-03-25 01:59:322776 gfx::PointF(),
2777 gfx::PointF(5.f, 5.f),
2778 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572779 true,
[email protected]fb661802013-03-25 01:59:322780 false);
2781 SetLayerPropertiesForTesting(grand_child2.get(),
2782 identity_matrix,
[email protected]fb661802013-03-25 01:59:322783 gfx::PointF(),
2784 gfx::PointF(75.f, 75.f),
2785 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572786 true,
[email protected]fb661802013-03-25 01:59:322787 false);
2788 SetLayerPropertiesForTesting(grand_child3.get(),
2789 identity_matrix,
[email protected]fb661802013-03-25 01:59:322790 gfx::PointF(),
2791 gfx::PointF(125.f, 125.f),
2792 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572793 true,
[email protected]fb661802013-03-25 01:59:322794 false);
2795
2796 child->SetMasksToBounds(true);
2797 ExecuteCalculateDrawProperties(root.get());
2798
2799 ASSERT_FALSE(child->render_surface());
2800
2801 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2802 root->render_surface()->DrawableContentRect());
2803 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2804
2805 // Layers that do not draw content should have empty visible content rects.
2806 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2807 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
2808
2809 // All grandchild visible content rects should be clipped by child.
2810 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
2811 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
2812 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
2813
2814 // All grandchild DrawableContentRects should also be clipped by child.
2815 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
2816 grand_child1->drawable_content_rect());
2817 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
2818 grand_child2->drawable_content_rect());
2819 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2820}
2821
[email protected]989386c2013-07-18 21:37:232822TEST_F(LayerTreeHostCommonTest,
2823 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322824 scoped_refptr<Layer> root = Layer::Create();
2825 scoped_refptr<Layer> render_surface1 = Layer::Create();
2826 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2827 make_scoped_refptr(new LayerWithForcedDrawsContent());
2828 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2829 make_scoped_refptr(new LayerWithForcedDrawsContent());
2830 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2831 make_scoped_refptr(new LayerWithForcedDrawsContent());
2832 root->AddChild(render_surface1);
2833 render_surface1->AddChild(child1);
2834 render_surface1->AddChild(child2);
2835 render_surface1->AddChild(child3);
2836
[email protected]d600df7d2013-08-03 02:34:282837 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2838 host->SetRootLayer(root);
2839
[email protected]fb661802013-03-25 01:59:322840 gfx::Transform identity_matrix;
2841 SetLayerPropertiesForTesting(root.get(),
2842 identity_matrix,
[email protected]fb661802013-03-25 01:59:322843 gfx::PointF(),
2844 gfx::PointF(),
2845 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572846 true,
[email protected]fb661802013-03-25 01:59:322847 false);
2848 SetLayerPropertiesForTesting(render_surface1.get(),
2849 identity_matrix,
[email protected]fb661802013-03-25 01:59:322850 gfx::PointF(),
2851 gfx::PointF(),
2852 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572853 true,
[email protected]fb661802013-03-25 01:59:322854 false);
2855 SetLayerPropertiesForTesting(child1.get(),
2856 identity_matrix,
[email protected]fb661802013-03-25 01:59:322857 gfx::PointF(),
2858 gfx::PointF(5.f, 5.f),
2859 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572860 true,
[email protected]fb661802013-03-25 01:59:322861 false);
2862 SetLayerPropertiesForTesting(child2.get(),
2863 identity_matrix,
[email protected]fb661802013-03-25 01:59:322864 gfx::PointF(),
2865 gfx::PointF(75.f, 75.f),
2866 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572867 true,
[email protected]fb661802013-03-25 01:59:322868 false);
2869 SetLayerPropertiesForTesting(child3.get(),
2870 identity_matrix,
[email protected]fb661802013-03-25 01:59:322871 gfx::PointF(),
2872 gfx::PointF(125.f, 125.f),
2873 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572874 true,
[email protected]fb661802013-03-25 01:59:322875 false);
2876
2877 render_surface1->SetForceRenderSurface(true);
2878 ExecuteCalculateDrawProperties(root.get());
2879
2880 ASSERT_TRUE(render_surface1->render_surface());
2881
2882 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2883 root->render_surface()->DrawableContentRect());
2884 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2885
2886 // Layers that do not draw content should have empty visible content rects.
2887 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2888 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2889 render_surface1->visible_content_rect());
2890
2891 // An unclipped surface grows its DrawableContentRect to include all drawable
2892 // regions of the subtree.
2893 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
2894 render_surface1->render_surface()->DrawableContentRect());
2895
2896 // All layers that draw content into the unclipped surface are also unclipped.
2897 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2898 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
2899 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
2900
2901 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2902 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2903 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2904}
2905
[email protected]989386c2013-07-18 21:37:232906TEST_F(LayerTreeHostCommonTest,
2907 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:472908 scoped_refptr<Layer> root = Layer::Create();
2909 scoped_refptr<LayerWithForcedDrawsContent> child =
2910 make_scoped_refptr(new LayerWithForcedDrawsContent());
2911 root->AddChild(child);
2912
[email protected]d600df7d2013-08-03 02:34:282913 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2914 host->SetRootLayer(root);
2915
[email protected]630ddad2013-08-16 03:01:322916 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:472917 gfx::Transform identity_matrix;
2918 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:322919 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:472920
2921 SetLayerPropertiesForTesting(root.get(),
2922 identity_matrix,
[email protected]451107a32013-04-10 05:12:472923 gfx::PointF(),
2924 gfx::PointF(),
2925 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572926 true,
[email protected]451107a32013-04-10 05:12:472927 false);
2928 SetLayerPropertiesForTesting(child.get(),
2929 uninvertible_matrix,
[email protected]451107a32013-04-10 05:12:472930 gfx::PointF(),
2931 gfx::PointF(5.f, 5.f),
2932 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572933 true,
[email protected]451107a32013-04-10 05:12:472934 false);
2935
2936 ExecuteCalculateDrawProperties(root.get());
2937
2938 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2939 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322940
2941 // Case 2: a matrix with flattened z, technically uninvertible but still
2942 // drawable and visible. In this case, we must assume that the entire layer
2943 // bounds are visible since there is no way to inverse-project the surface
2944 // bounds to intersect.
2945 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
2959 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child->visible_content_rect());
2960 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child->drawable_content_rect());
2961
2962 // Case 3: a matrix with flattened z, technically uninvertible but still
2963 // drawable, but not visible. In this case, we don't need to conservatively
2964 // assume that the whole layer is visible.
2965 uninvertible_matrix.MakeIdentity();
2966 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:262967 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322968 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2969
2970 SetLayerPropertiesForTesting(child.get(),
2971 uninvertible_matrix,
[email protected]630ddad2013-08-16 03:01:322972 gfx::PointF(),
2973 gfx::PointF(5.f, 5.f),
2974 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572975 true,
[email protected]630ddad2013-08-16 03:01:322976 false);
2977
2978 ExecuteCalculateDrawProperties(root.get());
2979
2980 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2981 EXPECT_RECT_EQ(gfx::Rect(505, 5, 50, 50), child->drawable_content_rect());
[email protected]451107a32013-04-10 05:12:472982}
2983
[email protected]989386c2013-07-18 21:37:232984TEST_F(LayerTreeHostCommonTest,
2985 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322986 scoped_refptr<Layer> root = Layer::Create();
2987 scoped_refptr<Layer> render_surface1 = Layer::Create();
2988 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2989 make_scoped_refptr(new LayerWithForcedDrawsContent());
2990 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2991 make_scoped_refptr(new LayerWithForcedDrawsContent());
2992 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2993 make_scoped_refptr(new LayerWithForcedDrawsContent());
2994 root->AddChild(render_surface1);
2995 render_surface1->AddChild(child1);
2996 render_surface1->AddChild(child2);
2997 render_surface1->AddChild(child3);
2998
[email protected]d600df7d2013-08-03 02:34:282999 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3000 host->SetRootLayer(root);
3001
[email protected]fb661802013-03-25 01:59:323002 gfx::Transform identity_matrix;
3003 SetLayerPropertiesForTesting(root.get(),
3004 identity_matrix,
[email protected]fb661802013-03-25 01:59:323005 gfx::PointF(),
3006 gfx::PointF(),
3007 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573008 true,
[email protected]fb661802013-03-25 01:59:323009 false);
3010 SetLayerPropertiesForTesting(render_surface1.get(),
3011 identity_matrix,
[email protected]fb661802013-03-25 01:59:323012 gfx::PointF(),
3013 gfx::PointF(),
3014 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573015 true,
[email protected]fb661802013-03-25 01:59:323016 false);
3017 SetLayerPropertiesForTesting(child1.get(),
3018 identity_matrix,
[email protected]fb661802013-03-25 01:59:323019 gfx::PointF(),
3020 gfx::PointF(5.f, 5.f),
3021 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573022 true,
[email protected]fb661802013-03-25 01:59:323023 false);
3024 SetLayerPropertiesForTesting(child2.get(),
3025 identity_matrix,
[email protected]fb661802013-03-25 01:59:323026 gfx::PointF(),
3027 gfx::PointF(75.f, 75.f),
3028 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573029 true,
[email protected]fb661802013-03-25 01:59:323030 false);
3031 SetLayerPropertiesForTesting(child3.get(),
3032 identity_matrix,
[email protected]fb661802013-03-25 01:59:323033 gfx::PointF(),
3034 gfx::PointF(125.f, 125.f),
3035 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573036 true,
[email protected]fb661802013-03-25 01:59:323037 false);
3038
3039 root->SetMasksToBounds(true);
3040 render_surface1->SetForceRenderSurface(true);
3041 ExecuteCalculateDrawProperties(root.get());
3042
3043 ASSERT_TRUE(render_surface1->render_surface());
3044
3045 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3046 root->render_surface()->DrawableContentRect());
3047 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3048
3049 // Layers that do not draw content should have empty visible content rects.
3050 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3051 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3052 render_surface1->visible_content_rect());
3053
3054 // A clipped surface grows its DrawableContentRect to include all drawable
3055 // regions of the subtree, but also gets clamped by the ancestor's clip.
3056 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3057 render_surface1->render_surface()->DrawableContentRect());
3058
3059 // All layers that draw content into the surface have their visible content
3060 // rect clipped by the surface clip rect.
3061 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3062 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
3063 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3064
3065 // But the DrawableContentRects are unclipped.
3066 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3067 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3068 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3069}
3070
[email protected]989386c2013-07-18 21:37:233071TEST_F(LayerTreeHostCommonTest,
3072 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323073 // Check that clipping does not propagate down surfaces.
3074 scoped_refptr<Layer> root = Layer::Create();
3075 scoped_refptr<Layer> render_surface1 = Layer::Create();
3076 scoped_refptr<Layer> render_surface2 = Layer::Create();
3077 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3078 make_scoped_refptr(new LayerWithForcedDrawsContent());
3079 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3080 make_scoped_refptr(new LayerWithForcedDrawsContent());
3081 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3082 make_scoped_refptr(new LayerWithForcedDrawsContent());
3083 root->AddChild(render_surface1);
3084 render_surface1->AddChild(render_surface2);
3085 render_surface2->AddChild(child1);
3086 render_surface2->AddChild(child2);
3087 render_surface2->AddChild(child3);
3088
[email protected]d600df7d2013-08-03 02:34:283089 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3090 host->SetRootLayer(root);
3091
[email protected]fb661802013-03-25 01:59:323092 gfx::Transform identity_matrix;
3093 SetLayerPropertiesForTesting(root.get(),
3094 identity_matrix,
[email protected]fb661802013-03-25 01:59:323095 gfx::PointF(),
3096 gfx::PointF(),
3097 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573098 true,
[email protected]fb661802013-03-25 01:59:323099 false);
3100 SetLayerPropertiesForTesting(render_surface1.get(),
3101 identity_matrix,
[email protected]fb661802013-03-25 01:59:323102 gfx::PointF(),
3103 gfx::PointF(),
3104 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573105 true,
[email protected]fb661802013-03-25 01:59:323106 false);
3107 SetLayerPropertiesForTesting(render_surface2.get(),
3108 identity_matrix,
[email protected]fb661802013-03-25 01:59:323109 gfx::PointF(),
3110 gfx::PointF(),
3111 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573112 true,
[email protected]fb661802013-03-25 01:59:323113 false);
3114 SetLayerPropertiesForTesting(child1.get(),
3115 identity_matrix,
[email protected]fb661802013-03-25 01:59:323116 gfx::PointF(),
3117 gfx::PointF(5.f, 5.f),
3118 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573119 true,
[email protected]fb661802013-03-25 01:59:323120 false);
3121 SetLayerPropertiesForTesting(child2.get(),
3122 identity_matrix,
[email protected]fb661802013-03-25 01:59:323123 gfx::PointF(),
3124 gfx::PointF(75.f, 75.f),
3125 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573126 true,
[email protected]fb661802013-03-25 01:59:323127 false);
3128 SetLayerPropertiesForTesting(child3.get(),
3129 identity_matrix,
[email protected]fb661802013-03-25 01:59:323130 gfx::PointF(),
3131 gfx::PointF(125.f, 125.f),
3132 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573133 true,
[email protected]fb661802013-03-25 01:59:323134 false);
3135
3136 root->SetMasksToBounds(true);
3137 render_surface1->SetForceRenderSurface(true);
3138 render_surface2->SetForceRenderSurface(true);
3139 ExecuteCalculateDrawProperties(root.get());
3140
3141 ASSERT_TRUE(render_surface1->render_surface());
3142 ASSERT_TRUE(render_surface2->render_surface());
3143
3144 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3145 root->render_surface()->DrawableContentRect());
3146 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3147
3148 // Layers that do not draw content should have empty visible content rects.
3149 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3150 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3151 render_surface1->visible_content_rect());
3152 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3153 render_surface2->visible_content_rect());
3154
3155 // A clipped surface grows its DrawableContentRect to include all drawable
3156 // regions of the subtree, but also gets clamped by the ancestor's clip.
3157 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3158 render_surface1->render_surface()->DrawableContentRect());
3159
3160 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3161 // is only implicitly clipped by render_surface1's content rect. So,
3162 // render_surface2 grows to enclose all drawable content of its subtree.
3163 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3164 render_surface2->render_surface()->DrawableContentRect());
3165
3166 // All layers that draw content into render_surface2 think they are unclipped.
3167 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3168 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3169 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
3170
3171 // DrawableContentRects are also unclipped.
3172 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3173 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3174 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3175}
3176
[email protected]989386c2013-07-18 21:37:233177TEST_F(LayerTreeHostCommonTest,
3178 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323179 // Layers that have non-axis aligned bounds (due to transforms) have an
3180 // expanded, axis-aligned DrawableContentRect and visible content rect.
3181
3182 scoped_refptr<Layer> root = Layer::Create();
3183 scoped_refptr<Layer> render_surface1 = Layer::Create();
3184 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3185 make_scoped_refptr(new LayerWithForcedDrawsContent());
3186 root->AddChild(render_surface1);
3187 render_surface1->AddChild(child1);
3188
[email protected]d600df7d2013-08-03 02:34:283189 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3190 host->SetRootLayer(root);
3191
[email protected]fb661802013-03-25 01:59:323192 gfx::Transform identity_matrix;
3193 gfx::Transform child_rotation;
3194 child_rotation.Rotate(45.0);
3195 SetLayerPropertiesForTesting(root.get(),
3196 identity_matrix,
[email protected]fb661802013-03-25 01:59:323197 gfx::PointF(),
3198 gfx::PointF(),
3199 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573200 true,
[email protected]fb661802013-03-25 01:59:323201 false);
3202 SetLayerPropertiesForTesting(render_surface1.get(),
3203 identity_matrix,
[email protected]fb661802013-03-25 01:59:323204 gfx::PointF(),
3205 gfx::PointF(),
3206 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573207 true,
[email protected]fb661802013-03-25 01:59:323208 false);
3209 SetLayerPropertiesForTesting(child1.get(),
3210 child_rotation,
[email protected]fb661802013-03-25 01:59:323211 gfx::PointF(0.5f, 0.5f),
3212 gfx::PointF(25.f, 25.f),
3213 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573214 true,
[email protected]fb661802013-03-25 01:59:323215 false);
3216
3217 render_surface1->SetForceRenderSurface(true);
3218 ExecuteCalculateDrawProperties(root.get());
3219
3220 ASSERT_TRUE(render_surface1->render_surface());
3221
3222 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3223 root->render_surface()->DrawableContentRect());
3224 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3225
3226 // Layers that do not draw content should have empty visible content rects.
3227 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3228 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3229 render_surface1->visible_content_rect());
3230
3231 // The unclipped surface grows its DrawableContentRect to include all drawable
3232 // regions of the subtree.
3233 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3234 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263235 gfx::Rect(50 - diagonal_radius,
3236 50 - diagonal_radius,
3237 diagonal_radius * 2,
3238 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323239 EXPECT_RECT_EQ(expected_surface_drawable_content,
3240 render_surface1->render_surface()->DrawableContentRect());
3241
3242 // All layers that draw content into the unclipped surface are also unclipped.
3243 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3244 EXPECT_RECT_EQ(expected_surface_drawable_content,
3245 child1->drawable_content_rect());
3246}
3247
[email protected]989386c2013-07-18 21:37:233248TEST_F(LayerTreeHostCommonTest,
3249 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323250 // Layers that have non-axis aligned bounds (due to transforms) have an
3251 // expanded, axis-aligned DrawableContentRect and visible content rect.
3252
3253 scoped_refptr<Layer> root = Layer::Create();
3254 scoped_refptr<Layer> render_surface1 = Layer::Create();
3255 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3256 make_scoped_refptr(new LayerWithForcedDrawsContent());
3257 root->AddChild(render_surface1);
3258 render_surface1->AddChild(child1);
3259
[email protected]d600df7d2013-08-03 02:34:283260 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3261 host->SetRootLayer(root);
3262
[email protected]fb661802013-03-25 01:59:323263 gfx::Transform identity_matrix;
3264 gfx::Transform child_rotation;
3265 child_rotation.Rotate(45.0);
3266 SetLayerPropertiesForTesting(root.get(),
3267 identity_matrix,
[email protected]fb661802013-03-25 01:59:323268 gfx::PointF(),
3269 gfx::PointF(),
3270 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573271 true,
[email protected]fb661802013-03-25 01:59:323272 false);
3273 SetLayerPropertiesForTesting(render_surface1.get(),
3274 identity_matrix,
[email protected]fb661802013-03-25 01:59:323275 gfx::PointF(),
3276 gfx::PointF(),
3277 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573278 true,
[email protected]fb661802013-03-25 01:59:323279 false);
3280 SetLayerPropertiesForTesting(child1.get(),
3281 child_rotation,
[email protected]fb661802013-03-25 01:59:323282 gfx::PointF(0.5f, 0.5f),
3283 gfx::PointF(25.f, 25.f),
3284 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573285 true,
[email protected]fb661802013-03-25 01:59:323286 false);
3287
3288 root->SetMasksToBounds(true);
3289 render_surface1->SetForceRenderSurface(true);
3290 ExecuteCalculateDrawProperties(root.get());
3291
3292 ASSERT_TRUE(render_surface1->render_surface());
3293
3294 // The clipped surface clamps the DrawableContentRect that encloses the
3295 // rotated layer.
3296 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263297 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3298 50 - diagonal_radius,
3299 diagonal_radius * 2,
3300 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323301 gfx::Rect expected_surface_drawable_content =
3302 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
3303 EXPECT_RECT_EQ(expected_surface_drawable_content,
3304 render_surface1->render_surface()->DrawableContentRect());
3305
3306 // On the clipped surface, only a quarter of the child1 is visible, but when
3307 // rotating it back to child1's content space, the actual enclosing rect ends
3308 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263309 //
3310 // Given the floating point math, this number is a little bit fuzzy.
[email protected]fb661802013-03-25 01:59:323311 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
3312
3313 // The child's DrawableContentRect is unclipped.
3314 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3315}
3316
[email protected]989386c2013-07-18 21:37:233317TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323318 MockContentLayerClient client;
3319
3320 scoped_refptr<Layer> root = Layer::Create();
3321 scoped_refptr<ContentLayer> render_surface1 =
3322 CreateDrawableContentLayer(&client);
3323 scoped_refptr<ContentLayer> render_surface2 =
3324 CreateDrawableContentLayer(&client);
3325 scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client);
3326 scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client);
3327 scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client);
3328 root->AddChild(render_surface1);
3329 render_surface1->AddChild(render_surface2);
3330 render_surface2->AddChild(child1);
3331 render_surface2->AddChild(child2);
3332 render_surface2->AddChild(child3);
3333
[email protected]d600df7d2013-08-03 02:34:283334 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3335 host->SetRootLayer(root);
3336
[email protected]fb661802013-03-25 01:59:323337 gfx::Transform identity_matrix;
3338 SetLayerPropertiesForTesting(root.get(),
3339 identity_matrix,
[email protected]fb661802013-03-25 01:59:323340 gfx::PointF(),
3341 gfx::PointF(),
3342 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573343 true,
[email protected]fb661802013-03-25 01:59:323344 false);
3345 SetLayerPropertiesForTesting(render_surface1.get(),
3346 identity_matrix,
[email protected]fb661802013-03-25 01:59:323347 gfx::PointF(),
3348 gfx::PointF(5.f, 5.f),
3349 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573350 true,
[email protected]fb661802013-03-25 01:59:323351 false);
3352 SetLayerPropertiesForTesting(render_surface2.get(),
3353 identity_matrix,
[email protected]fb661802013-03-25 01:59:323354 gfx::PointF(),
3355 gfx::PointF(5.f, 5.f),
3356 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573357 true,
[email protected]fb661802013-03-25 01:59:323358 false);
3359 SetLayerPropertiesForTesting(child1.get(),
3360 identity_matrix,
[email protected]fb661802013-03-25 01:59:323361 gfx::PointF(),
3362 gfx::PointF(5.f, 5.f),
3363 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573364 true,
[email protected]fb661802013-03-25 01:59:323365 false);
3366 SetLayerPropertiesForTesting(child2.get(),
3367 identity_matrix,
[email protected]fb661802013-03-25 01:59:323368 gfx::PointF(),
3369 gfx::PointF(75.f, 75.f),
3370 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573371 true,
[email protected]fb661802013-03-25 01:59:323372 false);
3373 SetLayerPropertiesForTesting(child3.get(),
3374 identity_matrix,
[email protected]fb661802013-03-25 01:59:323375 gfx::PointF(),
3376 gfx::PointF(125.f, 125.f),
3377 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573378 true,
[email protected]fb661802013-03-25 01:59:323379 false);
3380
3381 float device_scale_factor = 2.f;
3382
3383 root->SetMasksToBounds(true);
3384 render_surface1->SetForceRenderSurface(true);
3385 render_surface2->SetForceRenderSurface(true);
3386 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3387
3388 ASSERT_TRUE(render_surface1->render_surface());
3389 ASSERT_TRUE(render_surface2->render_surface());
3390
3391 // drawable_content_rects for all layers and surfaces are scaled by
3392 // device_scale_factor.
3393 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3394 root->render_surface()->DrawableContentRect());
3395 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3396 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3397 render_surface1->render_surface()->DrawableContentRect());
3398
3399 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3400 // is only implicitly clipped by render_surface1.
3401 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3402 render_surface2->render_surface()->DrawableContentRect());
3403
3404 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3405 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3406 child2->drawable_content_rect());
3407 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3408 child3->drawable_content_rect());
3409
3410 // The root layer does not actually draw content of its own.
3411 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3412
3413 // All layer visible content rects are expressed in content space of each
3414 // layer, so they are also scaled by the device_scale_factor.
3415 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8),
3416 render_surface1->visible_content_rect());
3417 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26),
3418 render_surface2->visible_content_rect());
3419 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect());
3420 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect());
3421 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect());
3422}
3423
[email protected]989386c2013-07-18 21:37:233424TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323425 // Verify the behavior of back-face culling when there are no preserve-3d
3426 // layers. Note that 3d transforms still apply in this case, but they are
3427 // "flattened" to each parent layer according to current W3C spec.
3428
3429 const gfx::Transform identity_matrix;
3430 scoped_refptr<Layer> parent = Layer::Create();
3431 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3432 make_scoped_refptr(new LayerWithForcedDrawsContent());
3433 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3434 make_scoped_refptr(new LayerWithForcedDrawsContent());
3435 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3436 make_scoped_refptr(new LayerWithForcedDrawsContent());
3437 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3438 make_scoped_refptr(new LayerWithForcedDrawsContent());
3439 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233440 front_facing_child_of_front_facing_surface =
3441 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323442 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233443 back_facing_child_of_front_facing_surface =
3444 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323445 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233446 front_facing_child_of_back_facing_surface =
3447 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323448 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233449 back_facing_child_of_back_facing_surface =
3450 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323451
3452 parent->AddChild(front_facing_child);
3453 parent->AddChild(back_facing_child);
3454 parent->AddChild(front_facing_surface);
3455 parent->AddChild(back_facing_surface);
3456 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3457 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3458 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3459 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3460
[email protected]d600df7d2013-08-03 02:34:283461 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3462 host->SetRootLayer(parent);
3463
[email protected]fb661802013-03-25 01:59:323464 // Nothing is double-sided
3465 front_facing_child->SetDoubleSided(false);
3466 back_facing_child->SetDoubleSided(false);
3467 front_facing_surface->SetDoubleSided(false);
3468 back_facing_surface->SetDoubleSided(false);
3469 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3470 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3471 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3472 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3473
3474 gfx::Transform backface_matrix;
3475 backface_matrix.Translate(50.0, 50.0);
3476 backface_matrix.RotateAboutYAxis(180.0);
3477 backface_matrix.Translate(-50.0, -50.0);
3478
3479 // Having a descendant and opacity will force these to have render surfaces.
3480 front_facing_surface->SetOpacity(0.5f);
3481 back_facing_surface->SetOpacity(0.5f);
3482
3483 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3484 // these layers should blindly use their own local transforms to determine
3485 // back-face culling.
3486 SetLayerPropertiesForTesting(parent.get(),
3487 identity_matrix,
[email protected]fb661802013-03-25 01:59:323488 gfx::PointF(),
3489 gfx::PointF(),
3490 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573491 true,
[email protected]fb661802013-03-25 01:59:323492 false);
3493 SetLayerPropertiesForTesting(front_facing_child.get(),
3494 identity_matrix,
[email protected]fb661802013-03-25 01:59:323495 gfx::PointF(),
3496 gfx::PointF(),
3497 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573498 true,
[email protected]fb661802013-03-25 01:59:323499 false);
3500 SetLayerPropertiesForTesting(back_facing_child.get(),
3501 backface_matrix,
[email protected]fb661802013-03-25 01:59:323502 gfx::PointF(),
3503 gfx::PointF(),
3504 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573505 true,
[email protected]fb661802013-03-25 01:59:323506 false);
3507 SetLayerPropertiesForTesting(front_facing_surface.get(),
3508 identity_matrix,
[email protected]fb661802013-03-25 01:59:323509 gfx::PointF(),
3510 gfx::PointF(),
3511 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573512 true,
[email protected]fb661802013-03-25 01:59:323513 false);
3514 SetLayerPropertiesForTesting(back_facing_surface.get(),
3515 backface_matrix,
[email protected]fb661802013-03-25 01:59:323516 gfx::PointF(),
3517 gfx::PointF(),
3518 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573519 true,
[email protected]fb661802013-03-25 01:59:323520 false);
3521 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3522 identity_matrix,
[email protected]fb661802013-03-25 01:59:323523 gfx::PointF(),
3524 gfx::PointF(),
3525 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573526 true,
[email protected]fb661802013-03-25 01:59:323527 false);
3528 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3529 backface_matrix,
[email protected]fb661802013-03-25 01:59:323530 gfx::PointF(),
3531 gfx::PointF(),
3532 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573533 true,
[email protected]fb661802013-03-25 01:59:323534 false);
3535 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3536 identity_matrix,
[email protected]fb661802013-03-25 01:59:323537 gfx::PointF(),
3538 gfx::PointF(),
3539 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573540 true,
[email protected]fb661802013-03-25 01:59:323541 false);
3542 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3543 backface_matrix,
[email protected]fb661802013-03-25 01:59:323544 gfx::PointF(),
3545 gfx::PointF(),
3546 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573547 true,
[email protected]fb661802013-03-25 01:59:323548 false);
3549
[email protected]989386c2013-07-18 21:37:233550 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533551 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3552 parent.get(), parent->bounds(), &render_surface_layer_list);
3553 inputs.can_adjust_raster_scales = true;
3554 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323555
3556 // Verify which render surfaces were created.
3557 EXPECT_FALSE(front_facing_child->render_surface());
3558 EXPECT_FALSE(back_facing_child->render_surface());
3559 EXPECT_TRUE(front_facing_surface->render_surface());
3560 EXPECT_TRUE(back_facing_surface->render_surface());
3561 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3562 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3563 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3564 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3565
3566 // Verify the render_surface_layer_list.
3567 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233568 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3569 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323570 // Even though the back facing surface LAYER gets culled, the other
3571 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233572 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323573
3574 // Verify root surface's layer list.
3575 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233576 3u,
3577 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3578 EXPECT_EQ(front_facing_child->id(),
3579 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573580 ->render_surface()
3581 ->layer_list()
3582 .at(0)
3583 ->id());
[email protected]989386c2013-07-18 21:37:233584 EXPECT_EQ(front_facing_surface->id(),
3585 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573586 ->render_surface()
3587 ->layer_list()
3588 .at(1)
3589 ->id());
[email protected]989386c2013-07-18 21:37:233590 EXPECT_EQ(back_facing_surface->id(),
3591 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573592 ->render_surface()
3593 ->layer_list()
3594 .at(2)
3595 ->id());
[email protected]fb661802013-03-25 01:59:323596
3597 // Verify front_facing_surface's layer list.
3598 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233599 2u,
3600 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3601 EXPECT_EQ(front_facing_surface->id(),
3602 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573603 ->render_surface()
3604 ->layer_list()
3605 .at(0)
3606 ->id());
[email protected]989386c2013-07-18 21:37:233607 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3608 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573609 ->render_surface()
3610 ->layer_list()
3611 .at(1)
3612 ->id());
[email protected]fb661802013-03-25 01:59:323613
3614 // Verify back_facing_surface's layer list; its own layer should be culled
3615 // from the surface list.
3616 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233617 1u,
3618 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3619 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3620 render_surface_layer_list.at(2)
[email protected]56fffdd2014-02-11 19:50:573621 ->render_surface()
3622 ->layer_list()
3623 .at(0)
3624 ->id());
[email protected]fb661802013-03-25 01:59:323625}
3626
[email protected]989386c2013-07-18 21:37:233627TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323628 // Verify the behavior of back-face culling when preserves-3d transform style
3629 // is used.
3630
3631 const gfx::Transform identity_matrix;
3632 scoped_refptr<Layer> parent = Layer::Create();
3633 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3634 make_scoped_refptr(new LayerWithForcedDrawsContent());
3635 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3636 make_scoped_refptr(new LayerWithForcedDrawsContent());
3637 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3638 make_scoped_refptr(new LayerWithForcedDrawsContent());
3639 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3640 make_scoped_refptr(new LayerWithForcedDrawsContent());
3641 scoped_refptr<LayerWithForcedDrawsContent>
3642 front_facing_child_of_front_facing_surface =
3643 make_scoped_refptr(new LayerWithForcedDrawsContent());
3644 scoped_refptr<LayerWithForcedDrawsContent>
3645 back_facing_child_of_front_facing_surface =
3646 make_scoped_refptr(new LayerWithForcedDrawsContent());
3647 scoped_refptr<LayerWithForcedDrawsContent>
3648 front_facing_child_of_back_facing_surface =
3649 make_scoped_refptr(new LayerWithForcedDrawsContent());
3650 scoped_refptr<LayerWithForcedDrawsContent>
3651 back_facing_child_of_back_facing_surface =
3652 make_scoped_refptr(new LayerWithForcedDrawsContent());
3653 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3654 make_scoped_refptr(new LayerWithForcedDrawsContent());
3655 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3656 make_scoped_refptr(new LayerWithForcedDrawsContent());
3657
3658 parent->AddChild(front_facing_child);
3659 parent->AddChild(back_facing_child);
3660 parent->AddChild(front_facing_surface);
3661 parent->AddChild(back_facing_surface);
3662 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3663 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3664 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3665 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3666
[email protected]d600df7d2013-08-03 02:34:283667 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3668 host->SetRootLayer(parent);
3669
[email protected]fb661802013-03-25 01:59:323670 // Nothing is double-sided
3671 front_facing_child->SetDoubleSided(false);
3672 back_facing_child->SetDoubleSided(false);
3673 front_facing_surface->SetDoubleSided(false);
3674 back_facing_surface->SetDoubleSided(false);
3675 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3676 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3677 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3678 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3679
3680 gfx::Transform backface_matrix;
3681 backface_matrix.Translate(50.0, 50.0);
3682 backface_matrix.RotateAboutYAxis(180.0);
3683 backface_matrix.Translate(-50.0, -50.0);
3684
3685 // Opacity will not force creation of render surfaces in this case because of
3686 // the preserve-3d transform style. Instead, an example of when a surface
3687 // would be created with preserve-3d is when there is a replica layer.
3688 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3689 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3690
3691 // Each surface creates its own new 3d rendering context (as defined by W3C
3692 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3693 // rendering context should use the transform with respect to that context.
3694 // This 3d rendering context occurs when (a) parent's transform style is flat
3695 // and (b) the layer's transform style is preserve-3d.
3696 SetLayerPropertiesForTesting(parent.get(),
3697 identity_matrix,
[email protected]fb661802013-03-25 01:59:323698 gfx::PointF(),
3699 gfx::PointF(),
3700 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573701 true,
[email protected]fb661802013-03-25 01:59:323702 false); // parent transform style is flat.
3703 SetLayerPropertiesForTesting(front_facing_child.get(),
3704 identity_matrix,
[email protected]fb661802013-03-25 01:59:323705 gfx::PointF(),
3706 gfx::PointF(),
3707 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573708 true,
[email protected]fb661802013-03-25 01:59:323709 false);
3710 SetLayerPropertiesForTesting(back_facing_child.get(),
3711 backface_matrix,
[email protected]fb661802013-03-25 01:59:323712 gfx::PointF(),
3713 gfx::PointF(),
3714 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573715 true,
[email protected]fb661802013-03-25 01:59:323716 false);
[email protected]56fffdd2014-02-11 19:50:573717 // surface transform style is preserve-3d.
3718 SetLayerPropertiesForTesting(front_facing_surface.get(),
3719 identity_matrix,
[email protected]56fffdd2014-02-11 19:50:573720 gfx::PointF(),
3721 gfx::PointF(),
3722 gfx::Size(100, 100),
3723 false,
3724 true);
3725 // surface transform style is preserve-3d.
3726 SetLayerPropertiesForTesting(back_facing_surface.get(),
3727 backface_matrix,
[email protected]56fffdd2014-02-11 19:50:573728 gfx::PointF(),
3729 gfx::PointF(),
3730 gfx::Size(100, 100),
3731 false,
3732 true);
[email protected]fb661802013-03-25 01:59:323733 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3734 identity_matrix,
[email protected]fb661802013-03-25 01:59:323735 gfx::PointF(),
3736 gfx::PointF(),
3737 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573738 true,
3739 true);
[email protected]fb661802013-03-25 01:59:323740 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3741 backface_matrix,
[email protected]fb661802013-03-25 01:59:323742 gfx::PointF(),
3743 gfx::PointF(),
3744 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573745 true,
3746 true);
[email protected]fb661802013-03-25 01:59:323747 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3748 identity_matrix,
[email protected]fb661802013-03-25 01:59:323749 gfx::PointF(),
3750 gfx::PointF(),
3751 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573752 true,
3753 true);
[email protected]fb661802013-03-25 01:59:323754 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3755 backface_matrix,
[email protected]fb661802013-03-25 01:59:323756 gfx::PointF(),
3757 gfx::PointF(),
3758 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573759 true,
3760 true);
[email protected]fb661802013-03-25 01:59:323761
[email protected]989386c2013-07-18 21:37:233762 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533763 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3764 parent.get(), parent->bounds(), &render_surface_layer_list);
3765 inputs.can_adjust_raster_scales = true;
3766 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323767
3768 // Verify which render surfaces were created.
3769 EXPECT_FALSE(front_facing_child->render_surface());
3770 EXPECT_FALSE(back_facing_child->render_surface());
3771 EXPECT_TRUE(front_facing_surface->render_surface());
3772 EXPECT_FALSE(back_facing_surface->render_surface());
3773 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3774 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3775 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3776 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3777
3778 // Verify the render_surface_layer_list. The back-facing surface should be
3779 // culled.
3780 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233781 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3782 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323783
3784 // Verify root surface's layer list.
3785 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233786 2u,
3787 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3788 EXPECT_EQ(front_facing_child->id(),
3789 render_surface_layer_list.at(0)
3790 ->render_surface()->layer_list().at(0)->id());
3791 EXPECT_EQ(front_facing_surface->id(),
3792 render_surface_layer_list.at(0)
3793 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323794
3795 // Verify front_facing_surface's layer list.
3796 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233797 2u,
3798 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3799 EXPECT_EQ(front_facing_surface->id(),
3800 render_surface_layer_list.at(1)
3801 ->render_surface()->layer_list().at(0)->id());
3802 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3803 render_surface_layer_list.at(1)
3804 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323805}
3806
[email protected]989386c2013-07-18 21:37:233807TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323808 // Verify that layers are appropriately culled when their back face is showing
3809 // and they are not double sided, while animations are going on.
3810 //
3811 // Layers that are animating do not get culled on the main thread, as their
3812 // transforms should be treated as "unknown" so we can not be sure that their
3813 // back face is really showing.
3814 const gfx::Transform identity_matrix;
3815 scoped_refptr<Layer> parent = Layer::Create();
3816 scoped_refptr<LayerWithForcedDrawsContent> child =
3817 make_scoped_refptr(new LayerWithForcedDrawsContent());
3818 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3819 make_scoped_refptr(new LayerWithForcedDrawsContent());
3820 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3821 make_scoped_refptr(new LayerWithForcedDrawsContent());
3822 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3823 make_scoped_refptr(new LayerWithForcedDrawsContent());
3824 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3825 make_scoped_refptr(new LayerWithForcedDrawsContent());
3826
3827 parent->AddChild(child);
3828 parent->AddChild(animating_surface);
3829 animating_surface->AddChild(child_of_animating_surface);
3830 parent->AddChild(animating_child);
3831 parent->AddChild(child2);
3832
[email protected]d600df7d2013-08-03 02:34:283833 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3834 host->SetRootLayer(parent);
3835
[email protected]fb661802013-03-25 01:59:323836 // Nothing is double-sided
3837 child->SetDoubleSided(false);
3838 child2->SetDoubleSided(false);
3839 animating_surface->SetDoubleSided(false);
3840 child_of_animating_surface->SetDoubleSided(false);
3841 animating_child->SetDoubleSided(false);
3842
3843 gfx::Transform backface_matrix;
3844 backface_matrix.Translate(50.0, 50.0);
3845 backface_matrix.RotateAboutYAxis(180.0);
3846 backface_matrix.Translate(-50.0, -50.0);
3847
3848 // Make our render surface.
3849 animating_surface->SetForceRenderSurface(true);
3850
3851 // Animate the transform on the render surface.
3852 AddAnimatedTransformToController(
3853 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3854 // This is just an animating layer, not a surface.
3855 AddAnimatedTransformToController(
3856 animating_child->layer_animation_controller(), 10.0, 30, 0);
3857
3858 SetLayerPropertiesForTesting(parent.get(),
3859 identity_matrix,
[email protected]fb661802013-03-25 01:59:323860 gfx::PointF(),
3861 gfx::PointF(),
3862 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573863 true,
[email protected]fb661802013-03-25 01:59:323864 false);
3865 SetLayerPropertiesForTesting(child.get(),
3866 backface_matrix,
[email protected]fb661802013-03-25 01:59:323867 gfx::PointF(),
3868 gfx::PointF(),
3869 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573870 true,
[email protected]fb661802013-03-25 01:59:323871 false);
3872 SetLayerPropertiesForTesting(animating_surface.get(),
3873 backface_matrix,
[email protected]fb661802013-03-25 01:59:323874 gfx::PointF(),
3875 gfx::PointF(),
3876 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573877 true,
[email protected]fb661802013-03-25 01:59:323878 false);
3879 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3880 backface_matrix,
[email protected]fb661802013-03-25 01:59:323881 gfx::PointF(),
3882 gfx::PointF(),
3883 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573884 true,
[email protected]fb661802013-03-25 01:59:323885 false);
3886 SetLayerPropertiesForTesting(animating_child.get(),
3887 backface_matrix,
[email protected]fb661802013-03-25 01:59:323888 gfx::PointF(),
3889 gfx::PointF(),
3890 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573891 true,
[email protected]fb661802013-03-25 01:59:323892 false);
3893 SetLayerPropertiesForTesting(child2.get(),
3894 identity_matrix,
[email protected]fb661802013-03-25 01:59:323895 gfx::PointF(),
3896 gfx::PointF(),
3897 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573898 true,
[email protected]fb661802013-03-25 01:59:323899 false);
3900
[email protected]989386c2013-07-18 21:37:233901 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533902 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3903 parent.get(), parent->bounds(), &render_surface_layer_list);
3904 inputs.can_adjust_raster_scales = true;
3905 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323906
3907 EXPECT_FALSE(child->render_surface());
3908 EXPECT_TRUE(animating_surface->render_surface());
3909 EXPECT_FALSE(child_of_animating_surface->render_surface());
3910 EXPECT_FALSE(animating_child->render_surface());
3911 EXPECT_FALSE(child2->render_surface());
3912
3913 // Verify that the animating_child and child_of_animating_surface were not
3914 // culled, but that child was.
3915 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233916 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3917 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323918
3919 // The non-animating child be culled from the layer list for the parent render
3920 // surface.
3921 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233922 3u,
3923 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3924 EXPECT_EQ(animating_surface->id(),
3925 render_surface_layer_list.at(0)
3926 ->render_surface()->layer_list().at(0)->id());
3927 EXPECT_EQ(animating_child->id(),
3928 render_surface_layer_list.at(0)
3929 ->render_surface()->layer_list().at(1)->id());
3930 EXPECT_EQ(child2->id(),
3931 render_surface_layer_list.at(0)
3932 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:323933
3934 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233935 2u,
3936 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3937 EXPECT_EQ(animating_surface->id(),
3938 render_surface_layer_list.at(1)
3939 ->render_surface()->layer_list().at(0)->id());
3940 EXPECT_EQ(child_of_animating_surface->id(),
3941 render_surface_layer_list.at(1)
3942 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323943
3944 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
3945
3946 // The animating layers should have a visible content rect that represents the
3947 // area of the front face that is within the viewport.
3948 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053949 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:323950 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053951 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:323952 // And layers in the subtree of the animating layer should have valid visible
3953 // content rects also.
[email protected]989386c2013-07-18 21:37:233954 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
3955 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:323956}
3957
[email protected]989386c2013-07-18 21:37:233958TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:323959 BackFaceCullingWithPreserves3dForFlatteningSurface) {
3960 // Verify the behavior of back-face culling for a render surface that is
3961 // created when it flattens its subtree, and its parent has preserves-3d.
3962
3963 const gfx::Transform identity_matrix;
3964 scoped_refptr<Layer> parent = Layer::Create();
3965 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3966 make_scoped_refptr(new LayerWithForcedDrawsContent());
3967 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3968 make_scoped_refptr(new LayerWithForcedDrawsContent());
3969 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3970 make_scoped_refptr(new LayerWithForcedDrawsContent());
3971 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3972 make_scoped_refptr(new LayerWithForcedDrawsContent());
3973
3974 parent->AddChild(front_facing_surface);
3975 parent->AddChild(back_facing_surface);
3976 front_facing_surface->AddChild(child1);
3977 back_facing_surface->AddChild(child2);
3978
[email protected]d600df7d2013-08-03 02:34:283979 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3980 host->SetRootLayer(parent);
3981
[email protected]fb661802013-03-25 01:59:323982 // RenderSurfaces are not double-sided
3983 front_facing_surface->SetDoubleSided(false);
3984 back_facing_surface->SetDoubleSided(false);
3985
3986 gfx::Transform backface_matrix;
3987 backface_matrix.Translate(50.0, 50.0);
3988 backface_matrix.RotateAboutYAxis(180.0);
3989 backface_matrix.Translate(-50.0, -50.0);
3990
3991 SetLayerPropertiesForTesting(parent.get(),
3992 identity_matrix,
[email protected]fb661802013-03-25 01:59:323993 gfx::PointF(),
3994 gfx::PointF(),
3995 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573996 false,
3997 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:323998 SetLayerPropertiesForTesting(front_facing_surface.get(),
3999 identity_matrix,
[email protected]fb661802013-03-25 01:59:324000 gfx::PointF(),
4001 gfx::PointF(),
4002 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574003 true,
4004 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324005 SetLayerPropertiesForTesting(back_facing_surface.get(),
4006 backface_matrix,
[email protected]fb661802013-03-25 01:59:324007 gfx::PointF(),
4008 gfx::PointF(),
4009 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574010 true,
4011 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324012 SetLayerPropertiesForTesting(child1.get(),
4013 identity_matrix,
[email protected]fb661802013-03-25 01:59:324014 gfx::PointF(),
4015 gfx::PointF(),
4016 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574017 true,
[email protected]fb661802013-03-25 01:59:324018 false);
4019 SetLayerPropertiesForTesting(child2.get(),
4020 identity_matrix,
[email protected]fb661802013-03-25 01:59:324021 gfx::PointF(),
4022 gfx::PointF(),
4023 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574024 true,
[email protected]fb661802013-03-25 01:59:324025 false);
4026
[email protected]56fffdd2014-02-11 19:50:574027 front_facing_surface->SetIs3dSorted(true);
4028 back_facing_surface->SetIs3dSorted(true);
4029
[email protected]989386c2013-07-18 21:37:234030 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534031 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4032 parent.get(), parent->bounds(), &render_surface_layer_list);
4033 inputs.can_adjust_raster_scales = true;
4034 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324035
4036 // Verify which render surfaces were created.
4037 EXPECT_TRUE(front_facing_surface->render_surface());
4038 EXPECT_FALSE(
4039 back_facing_surface->render_surface()); // because it should be culled
4040 EXPECT_FALSE(child1->render_surface());
4041 EXPECT_FALSE(child2->render_surface());
4042
4043 // Verify the render_surface_layer_list. The back-facing surface should be
4044 // culled.
4045 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234046 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4047 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324048
4049 // Verify root surface's layer list.
4050 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234051 1u,
4052 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4053 EXPECT_EQ(front_facing_surface->id(),
4054 render_surface_layer_list.at(0)
4055 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324056
4057 // Verify front_facing_surface's layer list.
4058 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234059 2u,
4060 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4061 EXPECT_EQ(front_facing_surface->id(),
4062 render_surface_layer_list.at(1)
4063 ->render_surface()->layer_list().at(0)->id());
4064 EXPECT_EQ(child1->id(),
4065 render_surface_layer_list.at(1)
4066 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324067}
4068
[email protected]989386c2013-07-18 21:37:234069
4070TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:324071 // Hit testing on an empty render_surface_layer_list should return a null
4072 // pointer.
[email protected]50761e92013-03-29 20:51:284073 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:324074
4075 gfx::Point test_point(0, 0);
4076 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4077 test_point, render_surface_layer_list);
4078 EXPECT_FALSE(result_layer);
4079
4080 test_point = gfx::Point(10, 20);
4081 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4082 test_point, render_surface_layer_list);
4083 EXPECT_FALSE(result_layer);
4084}
4085
[email protected]989386c2013-07-18 21:37:234086TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayer) {
[email protected]fb661802013-03-25 01:59:324087 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454088 TestSharedBitmapManager shared_bitmap_manager;
4089 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324090 scoped_ptr<LayerImpl> root =
4091 LayerImpl::Create(host_impl.active_tree(), 12345);
4092
4093 gfx::Transform identity_matrix;
4094 gfx::PointF anchor;
4095 gfx::PointF position;
4096 gfx::Size bounds(100, 100);
4097 SetLayerPropertiesForTesting(root.get(),
4098 identity_matrix,
[email protected]fb661802013-03-25 01:59:324099 anchor,
4100 position,
4101 bounds,
[email protected]56fffdd2014-02-11 19:50:574102 true,
[email protected]fb661802013-03-25 01:59:324103 false);
4104 root->SetDrawsContent(true);
4105
[email protected]50761e92013-03-29 20:51:284106 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534107 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4108 root.get(), root->bounds(), &render_surface_layer_list);
4109 inputs.can_adjust_raster_scales = true;
4110 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324111
4112 // Sanity check the scenario we just created.
4113 ASSERT_EQ(1u, render_surface_layer_list.size());
4114 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4115
4116 // Hit testing for a point outside the layer should return a null pointer.
4117 gfx::Point test_point(101, 101);
4118 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4119 test_point, render_surface_layer_list);
4120 EXPECT_FALSE(result_layer);
4121
4122 test_point = gfx::Point(-1, -1);
4123 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4124 test_point, render_surface_layer_list);
4125 EXPECT_FALSE(result_layer);
4126
4127 // Hit testing for a point inside should return the root layer.
4128 test_point = gfx::Point(1, 1);
4129 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4130 test_point, render_surface_layer_list);
4131 ASSERT_TRUE(result_layer);
4132 EXPECT_EQ(12345, result_layer->id());
4133
4134 test_point = gfx::Point(99, 99);
4135 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4136 test_point, render_surface_layer_list);
4137 ASSERT_TRUE(result_layer);
4138 EXPECT_EQ(12345, result_layer->id());
4139}
4140
[email protected]989386c2013-07-18 21:37:234141TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) {
[email protected]fb661802013-03-25 01:59:324142 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454143 TestSharedBitmapManager shared_bitmap_manager;
4144 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324145 scoped_ptr<LayerImpl> root =
4146 LayerImpl::Create(host_impl.active_tree(), 12345);
4147 scoped_ptr<HeadsUpDisplayLayerImpl> hud =
4148 HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111);
4149
4150 gfx::Transform identity_matrix;
4151 gfx::PointF anchor;
4152 gfx::PointF position;
4153 gfx::Size bounds(100, 100);
4154 SetLayerPropertiesForTesting(root.get(),
4155 identity_matrix,
[email protected]fb661802013-03-25 01:59:324156 anchor,
4157 position,
4158 bounds,
[email protected]56fffdd2014-02-11 19:50:574159 true,
[email protected]fb661802013-03-25 01:59:324160 false);
4161 root->SetDrawsContent(true);
4162
4163 // Create hud and add it as a child of root.
4164 gfx::Size hud_bounds(200, 200);
4165 SetLayerPropertiesForTesting(hud.get(),
4166 identity_matrix,
[email protected]fb661802013-03-25 01:59:324167 anchor,
4168 position,
4169 hud_bounds,
[email protected]56fffdd2014-02-11 19:50:574170 true,
[email protected]fb661802013-03-25 01:59:324171 false);
4172 hud->SetDrawsContent(true);
4173
4174 host_impl.active_tree()->set_hud_layer(hud.get());
4175 root->AddChild(hud.PassAs<LayerImpl>());
4176
[email protected]50761e92013-03-29 20:51:284177 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534178 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4179 root.get(), hud_bounds, &render_surface_layer_list);
4180 inputs.can_adjust_raster_scales = true;
4181 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324182
4183 // Sanity check the scenario we just created.
4184 ASSERT_EQ(1u, render_surface_layer_list.size());
4185 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4186
4187 // Hit testing for a point inside HUD, but outside root should return null
4188 gfx::Point test_point(101, 101);
4189 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4190 test_point, render_surface_layer_list);
4191 EXPECT_FALSE(result_layer);
4192
4193 test_point = gfx::Point(-1, -1);
4194 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4195 test_point, render_surface_layer_list);
4196 EXPECT_FALSE(result_layer);
4197
4198 // Hit testing for a point inside should return the root layer, never the HUD
4199 // layer.
4200 test_point = gfx::Point(1, 1);
4201 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4202 test_point, render_surface_layer_list);
4203 ASSERT_TRUE(result_layer);
4204 EXPECT_EQ(12345, result_layer->id());
4205
4206 test_point = gfx::Point(99, 99);
4207 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4208 test_point, render_surface_layer_list);
4209 ASSERT_TRUE(result_layer);
4210 EXPECT_EQ(12345, result_layer->id());
4211}
4212
[email protected]989386c2013-07-18 21:37:234213TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) {
[email protected]fb661802013-03-25 01:59:324214 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454215 TestSharedBitmapManager shared_bitmap_manager;
4216 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324217 scoped_ptr<LayerImpl> root =
4218 LayerImpl::Create(host_impl.active_tree(), 12345);
4219
4220 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:264221 uninvertible_transform.matrix().set(0, 0, 0.0);
4222 uninvertible_transform.matrix().set(1, 1, 0.0);
4223 uninvertible_transform.matrix().set(2, 2, 0.0);
4224 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:324225 ASSERT_FALSE(uninvertible_transform.IsInvertible());
4226
4227 gfx::Transform identity_matrix;
4228 gfx::PointF anchor;
4229 gfx::PointF position;
4230 gfx::Size bounds(100, 100);
4231 SetLayerPropertiesForTesting(root.get(),
4232 uninvertible_transform,
[email protected]fb661802013-03-25 01:59:324233 anchor,
4234 position,
4235 bounds,
[email protected]56fffdd2014-02-11 19:50:574236 true,
[email protected]fb661802013-03-25 01:59:324237 false);
4238 root->SetDrawsContent(true);
4239
[email protected]50761e92013-03-29 20:51:284240 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534241 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4242 root.get(), root->bounds(), &render_surface_layer_list);
4243 inputs.can_adjust_raster_scales = true;
4244 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324245
4246 // Sanity check the scenario we just created.
4247 ASSERT_EQ(1u, render_surface_layer_list.size());
4248 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4249 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
4250
4251 // Hit testing any point should not hit the layer. If the invertible matrix is
4252 // accidentally ignored and treated like an identity, then the hit testing
4253 // will incorrectly hit the layer when it shouldn't.
4254 gfx::Point test_point(1, 1);
4255 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4256 test_point, render_surface_layer_list);
4257 EXPECT_FALSE(result_layer);
4258
4259 test_point = gfx::Point(10, 10);
4260 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4261 test_point, render_surface_layer_list);
4262 EXPECT_FALSE(result_layer);
4263
4264 test_point = gfx::Point(10, 30);
4265 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4266 test_point, render_surface_layer_list);
4267 EXPECT_FALSE(result_layer);
4268
4269 test_point = gfx::Point(50, 50);
4270 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4271 test_point, render_surface_layer_list);
4272 EXPECT_FALSE(result_layer);
4273
4274 test_point = gfx::Point(67, 48);
4275 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4276 test_point, render_surface_layer_list);
4277 EXPECT_FALSE(result_layer);
4278
4279 test_point = gfx::Point(99, 99);
4280 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4281 test_point, render_surface_layer_list);
4282 EXPECT_FALSE(result_layer);
4283
4284 test_point = gfx::Point(-1, -1);
4285 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4286 test_point, render_surface_layer_list);
4287 EXPECT_FALSE(result_layer);
4288}
4289
[email protected]989386c2013-07-18 21:37:234290TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) {
[email protected]fb661802013-03-25 01:59:324291 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454292 TestSharedBitmapManager shared_bitmap_manager;
4293 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324294 scoped_ptr<LayerImpl> root =
4295 LayerImpl::Create(host_impl.active_tree(), 12345);
4296
4297 gfx::Transform identity_matrix;
4298 gfx::PointF anchor;
4299 // this layer is positioned, and hit testing should correctly know where the
4300 // layer is located.
4301 gfx::PointF position(50.f, 50.f);
4302 gfx::Size bounds(100, 100);
4303 SetLayerPropertiesForTesting(root.get(),
4304 identity_matrix,
[email protected]fb661802013-03-25 01:59:324305 anchor,
4306 position,
4307 bounds,
[email protected]56fffdd2014-02-11 19:50:574308 true,
[email protected]fb661802013-03-25 01:59:324309 false);
4310 root->SetDrawsContent(true);
4311
[email protected]50761e92013-03-29 20:51:284312 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534313 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4314 root.get(), root->bounds(), &render_surface_layer_list);
4315 inputs.can_adjust_raster_scales = true;
4316 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324317
4318 // Sanity check the scenario we just created.
4319 ASSERT_EQ(1u, render_surface_layer_list.size());
4320 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4321
4322 // Hit testing for a point outside the layer should return a null pointer.
4323 gfx::Point test_point(49, 49);
4324 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4325 test_point, render_surface_layer_list);
4326 EXPECT_FALSE(result_layer);
4327
4328 // Even though the layer exists at (101, 101), it should not be visible there
4329 // since the root render surface would clamp it.
4330 test_point = gfx::Point(101, 101);
4331 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4332 test_point, render_surface_layer_list);
4333 EXPECT_FALSE(result_layer);
4334
4335 // Hit testing for a point inside should return the root layer.
4336 test_point = gfx::Point(51, 51);
4337 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4338 test_point, render_surface_layer_list);
4339 ASSERT_TRUE(result_layer);
4340 EXPECT_EQ(12345, result_layer->id());
4341
4342 test_point = gfx::Point(99, 99);
4343 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4344 test_point, render_surface_layer_list);
4345 ASSERT_TRUE(result_layer);
4346 EXPECT_EQ(12345, result_layer->id());
4347}
4348
[email protected]989386c2013-07-18 21:37:234349TEST_F(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324350 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454351 TestSharedBitmapManager shared_bitmap_manager;
4352 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324353 scoped_ptr<LayerImpl> root =
4354 LayerImpl::Create(host_impl.active_tree(), 12345);
4355
4356 gfx::Transform identity_matrix;
4357 gfx::Transform rotation45_degrees_about_center;
4358 rotation45_degrees_about_center.Translate(50.0, 50.0);
4359 rotation45_degrees_about_center.RotateAboutZAxis(45.0);
4360 rotation45_degrees_about_center.Translate(-50.0, -50.0);
4361 gfx::PointF anchor;
4362 gfx::PointF position;
4363 gfx::Size bounds(100, 100);
4364 SetLayerPropertiesForTesting(root.get(),
4365 rotation45_degrees_about_center,
[email protected]fb661802013-03-25 01:59:324366 anchor,
4367 position,
4368 bounds,
[email protected]56fffdd2014-02-11 19:50:574369 true,
[email protected]fb661802013-03-25 01:59:324370 false);
4371 root->SetDrawsContent(true);
4372
[email protected]50761e92013-03-29 20:51:284373 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534374 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4375 root.get(), root->bounds(), &render_surface_layer_list);
4376 inputs.can_adjust_raster_scales = true;
4377 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324378
4379 // Sanity check the scenario we just created.
4380 ASSERT_EQ(1u, render_surface_layer_list.size());
4381 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4382
4383 // Hit testing for points outside the layer.
4384 // These corners would have been inside the un-transformed layer, but they
4385 // should not hit the correctly transformed layer.
4386 gfx::Point test_point(99, 99);
4387 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4388 test_point, render_surface_layer_list);
4389 EXPECT_FALSE(result_layer);
4390
4391 test_point = gfx::Point(1, 1);
4392 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4393 test_point, render_surface_layer_list);
4394 EXPECT_FALSE(result_layer);
4395
4396 // Hit testing for a point inside should return the root layer.
4397 test_point = gfx::Point(1, 50);
4398 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4399 test_point, render_surface_layer_list);
4400 ASSERT_TRUE(result_layer);
4401 EXPECT_EQ(12345, result_layer->id());
4402
4403 // Hit testing the corners that would overlap the unclipped layer, but are
4404 // outside the clipped region.
4405 test_point = gfx::Point(50, -1);
4406 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4407 test_point, render_surface_layer_list);
4408 ASSERT_FALSE(result_layer);
4409
4410 test_point = gfx::Point(-1, 50);
4411 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4412 test_point, render_surface_layer_list);
4413 ASSERT_FALSE(result_layer);
4414}
4415
[email protected]989386c2013-07-18 21:37:234416TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) {
[email protected]fb661802013-03-25 01:59:324417 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454418 TestSharedBitmapManager shared_bitmap_manager;
4419 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324420 scoped_ptr<LayerImpl> root =
4421 LayerImpl::Create(host_impl.active_tree(), 12345);
4422
4423 gfx::Transform identity_matrix;
4424
4425 // perspective_projection_about_center * translation_by_z is designed so that
4426 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
4427 gfx::Transform perspective_projection_about_center;
4428 perspective_projection_about_center.Translate(50.0, 50.0);
4429 perspective_projection_about_center.ApplyPerspectiveDepth(1.0);
4430 perspective_projection_about_center.Translate(-50.0, -50.0);
4431 gfx::Transform translation_by_z;
4432 translation_by_z.Translate3d(0.0, 0.0, -1.0);
4433
4434 gfx::PointF anchor;
4435 gfx::PointF position;
4436 gfx::Size bounds(100, 100);
4437 SetLayerPropertiesForTesting(
4438 root.get(),
4439 perspective_projection_about_center * translation_by_z,
[email protected]fb661802013-03-25 01:59:324440 anchor,
4441 position,
4442 bounds,
[email protected]56fffdd2014-02-11 19:50:574443 true,
[email protected]fb661802013-03-25 01:59:324444 false);
4445 root->SetDrawsContent(true);
4446
[email protected]50761e92013-03-29 20:51:284447 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534448 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4449 root.get(), root->bounds(), &render_surface_layer_list);
4450 inputs.can_adjust_raster_scales = true;
4451 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324452
4453 // Sanity check the scenario we just created.
4454 ASSERT_EQ(1u, render_surface_layer_list.size());
4455 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4456
4457 // Hit testing for points outside the layer.
4458 // These corners would have been inside the un-transformed layer, but they
4459 // should not hit the correctly transformed layer.
4460 gfx::Point test_point(24, 24);
4461 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4462 test_point, render_surface_layer_list);
4463 EXPECT_FALSE(result_layer);
4464
4465 test_point = gfx::Point(76, 76);
4466 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4467 test_point, render_surface_layer_list);
4468 EXPECT_FALSE(result_layer);
4469
4470 // Hit testing for a point inside should return the root layer.
4471 test_point = gfx::Point(26, 26);
4472 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4473 test_point, render_surface_layer_list);
4474 ASSERT_TRUE(result_layer);
4475 EXPECT_EQ(12345, result_layer->id());
4476
4477 test_point = gfx::Point(74, 74);
4478 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4479 test_point, render_surface_layer_list);
4480 ASSERT_TRUE(result_layer);
4481 EXPECT_EQ(12345, result_layer->id());
4482}
4483
[email protected]989386c2013-07-18 21:37:234484TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) {
[email protected]fb661802013-03-25 01:59:324485 // A layer's visible content rect is actually in the layer's content space.
4486 // The screen space transform converts from the layer's origin space to screen
4487 // space. This test makes sure that hit testing works correctly accounts for
4488 // the contents scale. A contents scale that is not 1 effectively forces a
4489 // non-identity transform between layer's content space and layer's origin
4490 // space. The hit testing code must take this into account.
4491 //
4492 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
4493 // contents scale is ignored, then hit testing will mis-interpret the visible
4494 // content rect as being larger than the actual bounds of the layer.
4495 //
4496 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454497 TestSharedBitmapManager shared_bitmap_manager;
4498 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324499 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4500
4501 gfx::Transform identity_matrix;
4502 gfx::PointF anchor;
4503
4504 SetLayerPropertiesForTesting(root.get(),
4505 identity_matrix,
[email protected]fb661802013-03-25 01:59:324506 anchor,
4507 gfx::PointF(),
4508 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574509 true,
[email protected]fb661802013-03-25 01:59:324510 false);
4511 {
4512 gfx::PointF position(25.f, 25.f);
4513 gfx::Size bounds(50, 50);
4514 scoped_ptr<LayerImpl> test_layer =
4515 LayerImpl::Create(host_impl.active_tree(), 12345);
4516 SetLayerPropertiesForTesting(test_layer.get(),
4517 identity_matrix,
[email protected]fb661802013-03-25 01:59:324518 anchor,
4519 position,
4520 bounds,
[email protected]56fffdd2014-02-11 19:50:574521 true,
[email protected]fb661802013-03-25 01:59:324522 false);
4523
4524 // override content bounds and contents scale
4525 test_layer->SetContentBounds(gfx::Size(100, 100));
4526 test_layer->SetContentsScale(2, 2);
4527
4528 test_layer->SetDrawsContent(true);
4529 root->AddChild(test_layer.Pass());
4530 }
4531
[email protected]50761e92013-03-29 20:51:284532 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534533 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4534 root.get(), root->bounds(), &render_surface_layer_list);
4535 inputs.can_adjust_raster_scales = true;
4536 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324537
4538 // Sanity check the scenario we just created.
4539 // The visible content rect for test_layer is actually 100x100, even though
4540 // its layout size is 50x50, positioned at 25x25.
4541 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:054542 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
[email protected]fb661802013-03-25 01:59:324543 test_layer->visible_content_rect());
4544 ASSERT_EQ(1u, render_surface_layer_list.size());
4545 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4546
4547 // Hit testing for a point outside the layer should return a null pointer (the
4548 // root layer does not draw content, so it will not be hit tested either).
4549 gfx::Point test_point(101, 101);
4550 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4551 test_point, render_surface_layer_list);
4552 EXPECT_FALSE(result_layer);
4553
4554 test_point = gfx::Point(24, 24);
4555 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4556 test_point, render_surface_layer_list);
4557 EXPECT_FALSE(result_layer);
4558
4559 test_point = gfx::Point(76, 76);
4560 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4561 test_point, render_surface_layer_list);
4562 EXPECT_FALSE(result_layer);
4563
4564 // Hit testing for a point inside should return the test layer.
4565 test_point = gfx::Point(26, 26);
4566 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4567 test_point, render_surface_layer_list);
4568 ASSERT_TRUE(result_layer);
4569 EXPECT_EQ(12345, result_layer->id());
4570
4571 test_point = gfx::Point(74, 74);
4572 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4573 test_point, render_surface_layer_list);
4574 ASSERT_TRUE(result_layer);
4575 EXPECT_EQ(12345, result_layer->id());
4576}
4577
[email protected]989386c2013-07-18 21:37:234578TEST_F(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) {
[email protected]fb661802013-03-25 01:59:324579 // Test that hit-testing will only work for the visible portion of a layer,
4580 // and not the entire layer bounds. Here we just test the simple axis-aligned
4581 // case.
4582 gfx::Transform identity_matrix;
4583 gfx::PointF anchor;
4584
4585 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454586 TestSharedBitmapManager shared_bitmap_manager;
4587 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324588 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4589 SetLayerPropertiesForTesting(root.get(),
4590 identity_matrix,
[email protected]fb661802013-03-25 01:59:324591 anchor,
4592 gfx::PointF(),
4593 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574594 true,
[email protected]fb661802013-03-25 01:59:324595 false);
4596 {
4597 scoped_ptr<LayerImpl> clipping_layer =
4598 LayerImpl::Create(host_impl.active_tree(), 123);
4599 // this layer is positioned, and hit testing should correctly know where the
4600 // layer is located.
[email protected]ca2902e92013-03-28 01:45:354601 gfx::PointF position(25.f, 25.f);
[email protected]fb661802013-03-25 01:59:324602 gfx::Size bounds(50, 50);
4603 SetLayerPropertiesForTesting(clipping_layer.get(),
4604 identity_matrix,
[email protected]fb661802013-03-25 01:59:324605 anchor,
4606 position,
4607 bounds,
[email protected]56fffdd2014-02-11 19:50:574608 true,
[email protected]fb661802013-03-25 01:59:324609 false);
4610 clipping_layer->SetMasksToBounds(true);
4611
4612 scoped_ptr<LayerImpl> child =
4613 LayerImpl::Create(host_impl.active_tree(), 456);
4614 position = gfx::PointF(-50.f, -50.f);
4615 bounds = gfx::Size(300, 300);
4616 SetLayerPropertiesForTesting(child.get(),
4617 identity_matrix,
[email protected]fb661802013-03-25 01:59:324618 anchor,
4619 position,
4620 bounds,
[email protected]56fffdd2014-02-11 19:50:574621 true,
[email protected]fb661802013-03-25 01:59:324622 false);
4623 child->SetDrawsContent(true);
4624 clipping_layer->AddChild(child.Pass());
4625 root->AddChild(clipping_layer.Pass());
4626 }
4627
[email protected]50761e92013-03-29 20:51:284628 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534629 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4630 root.get(), root->bounds(), &render_surface_layer_list);
4631 inputs.can_adjust_raster_scales = true;
4632 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324633
4634 // Sanity check the scenario we just created.
4635 ASSERT_EQ(1u, render_surface_layer_list.size());
4636 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234637 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324638
4639 // Hit testing for a point outside the layer should return a null pointer.
4640 // Despite the child layer being very large, it should be clipped to the root
4641 // layer's bounds.
4642 gfx::Point test_point(24, 24);
4643 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4644 test_point, render_surface_layer_list);
4645 EXPECT_FALSE(result_layer);
4646
4647 // Even though the layer exists at (101, 101), it should not be visible there
4648 // since the clipping_layer would clamp it.
4649 test_point = gfx::Point(76, 76);
4650 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4651 test_point, render_surface_layer_list);
4652 EXPECT_FALSE(result_layer);
4653
4654 // Hit testing for a point inside should return the child layer.
4655 test_point = gfx::Point(26, 26);
4656 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4657 test_point, render_surface_layer_list);
4658 ASSERT_TRUE(result_layer);
4659 EXPECT_EQ(456, result_layer->id());
4660
4661 test_point = gfx::Point(74, 74);
4662 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4663 test_point, render_surface_layer_list);
4664 ASSERT_TRUE(result_layer);
4665 EXPECT_EQ(456, result_layer->id());
4666}
4667
[email protected]989386c2013-07-18 21:37:234668TEST_F(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324669 // This test checks whether hit testing correctly avoids hit testing with
4670 // multiple ancestors that clip in non axis-aligned ways. To pass this test,
4671 // the hit testing algorithm needs to recognize that multiple parent layers
4672 // may clip the layer, and should not actually hit those clipped areas.
4673 //
4674 // The child and grand_child layers are both initialized to clip the
4675 // rotated_leaf. The child layer is rotated about the top-left corner, so that
4676 // the root + child clips combined create a triangle. The rotated_leaf will
4677 // only be visible where it overlaps this triangle.
4678 //
4679 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454680 TestSharedBitmapManager shared_bitmap_manager;
4681 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324682 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123);
4683
4684 gfx::Transform identity_matrix;
4685 gfx::PointF anchor;
4686 gfx::PointF position;
4687 gfx::Size bounds(100, 100);
4688 SetLayerPropertiesForTesting(root.get(),
4689 identity_matrix,
[email protected]fb661802013-03-25 01:59:324690 anchor,
4691 position,
4692 bounds,
[email protected]56fffdd2014-02-11 19:50:574693 true,
[email protected]fb661802013-03-25 01:59:324694 false);
4695 root->SetMasksToBounds(true);
4696 {
4697 scoped_ptr<LayerImpl> child =
4698 LayerImpl::Create(host_impl.active_tree(), 456);
4699 scoped_ptr<LayerImpl> grand_child =
4700 LayerImpl::Create(host_impl.active_tree(), 789);
4701 scoped_ptr<LayerImpl> rotated_leaf =
4702 LayerImpl::Create(host_impl.active_tree(), 2468);
4703
4704 position = gfx::PointF(10.f, 10.f);
4705 bounds = gfx::Size(80, 80);
4706 SetLayerPropertiesForTesting(child.get(),
4707 identity_matrix,
[email protected]fb661802013-03-25 01:59:324708 anchor,
4709 position,
4710 bounds,
[email protected]56fffdd2014-02-11 19:50:574711 true,
[email protected]fb661802013-03-25 01:59:324712 false);
[email protected]7aba6662013-03-12 10:17:344713 child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444714
[email protected]fb661802013-03-25 01:59:324715 gfx::Transform rotation45_degrees_about_corner;
4716 rotation45_degrees_about_corner.RotateAboutZAxis(45.0);
[email protected]aedf4e52013-01-09 23:24:444717
[email protected]fb661802013-03-25 01:59:324718 // remember, positioned with respect to its parent which is already at 10,
4719 // 10
4720 position = gfx::PointF();
4721 bounds =
4722 gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
4723 SetLayerPropertiesForTesting(grand_child.get(),
4724 rotation45_degrees_about_corner,
[email protected]fb661802013-03-25 01:59:324725 anchor,
4726 position,
4727 bounds,
[email protected]56fffdd2014-02-11 19:50:574728 true,
[email protected]fb661802013-03-25 01:59:324729 false);
4730 grand_child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444731
[email protected]fb661802013-03-25 01:59:324732 // Rotates about the center of the layer
4733 gfx::Transform rotated_leaf_transform;
4734 rotated_leaf_transform.Translate(
4735 -10.0, -10.0); // cancel out the grand_parent's position
4736 rotated_leaf_transform.RotateAboutZAxis(
4737 -45.0); // cancel out the corner 45-degree rotation of the parent.
4738 rotated_leaf_transform.Translate(50.0, 50.0);
4739 rotated_leaf_transform.RotateAboutZAxis(45.0);
4740 rotated_leaf_transform.Translate(-50.0, -50.0);
4741 position = gfx::PointF();
4742 bounds = gfx::Size(100, 100);
4743 SetLayerPropertiesForTesting(rotated_leaf.get(),
4744 rotated_leaf_transform,
[email protected]fb661802013-03-25 01:59:324745 anchor,
4746 position,
4747 bounds,
[email protected]56fffdd2014-02-11 19:50:574748 true,
[email protected]fb661802013-03-25 01:59:324749 false);
4750 rotated_leaf->SetDrawsContent(true);
[email protected]aedf4e52013-01-09 23:24:444751
[email protected]fb661802013-03-25 01:59:324752 grand_child->AddChild(rotated_leaf.Pass());
4753 child->AddChild(grand_child.Pass());
4754 root->AddChild(child.Pass());
4755 }
[email protected]aedf4e52013-01-09 23:24:444756
[email protected]50761e92013-03-29 20:51:284757 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534758 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4759 root.get(), root->bounds(), &render_surface_layer_list);
4760 inputs.can_adjust_raster_scales = true;
4761 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:444762
[email protected]fb661802013-03-25 01:59:324763 // Sanity check the scenario we just created.
4764 // The grand_child is expected to create a render surface because it
[email protected]989386c2013-07-18 21:37:234765 // MasksToBounds and is not axis aligned.
[email protected]fb661802013-03-25 01:59:324766 ASSERT_EQ(2u, render_surface_layer_list.size());
4767 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234768 1u,
4769 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324770 ASSERT_EQ(789,
[email protected]989386c2013-07-18 21:37:234771 render_surface_layer_list.at(0)->render_surface()->layer_list().at(
4772 0)->id()); // grand_child's surface.
[email protected]fb661802013-03-25 01:59:324773 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234774 1u,
4775 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324776 ASSERT_EQ(
4777 2468,
[email protected]989386c2013-07-18 21:37:234778 render_surface_layer_list[1]->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324779
4780 // (11, 89) is close to the the bottom left corner within the clip, but it is
4781 // not inside the layer.
4782 gfx::Point test_point(11, 89);
4783 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4784 test_point, render_surface_layer_list);
4785 EXPECT_FALSE(result_layer);
4786
4787 // Closer inwards from the bottom left will overlap the layer.
4788 test_point = gfx::Point(25, 75);
4789 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4790 test_point, render_surface_layer_list);
4791 ASSERT_TRUE(result_layer);
4792 EXPECT_EQ(2468, result_layer->id());
4793
4794 // (4, 50) is inside the unclipped layer, but that corner of the layer should
4795 // be clipped away by the grandparent and should not get hit. If hit testing
4796 // blindly uses visible content rect without considering how parent may clip
4797 // the layer, then hit testing would accidentally think that the point
4798 // successfully hits the layer.
4799 test_point = gfx::Point(4, 50);
4800 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4801 test_point, render_surface_layer_list);
4802 EXPECT_FALSE(result_layer);
4803
4804 // (11, 50) is inside the layer and within the clipped area.
4805 test_point = gfx::Point(11, 50);
4806 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4807 test_point, render_surface_layer_list);
4808 ASSERT_TRUE(result_layer);
4809 EXPECT_EQ(2468, result_layer->id());
4810
4811 // Around the middle, just to the right and up, would have hit the layer
4812 // except that that area should be clipped away by the parent.
[email protected]803f6b52013-09-12 00:51:264813 test_point = gfx::Point(51, 49);
[email protected]fb661802013-03-25 01:59:324814 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4815 test_point, render_surface_layer_list);
4816 EXPECT_FALSE(result_layer);
4817
4818 // Around the middle, just to the left and down, should successfully hit the
4819 // layer.
4820 test_point = gfx::Point(49, 51);
4821 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4822 test_point, render_surface_layer_list);
4823 ASSERT_TRUE(result_layer);
4824 EXPECT_EQ(2468, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:444825}
4826
[email protected]989386c2013-07-18 21:37:234827TEST_F(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:324828 // This test checks that hit testing code does not accidentally clip to layer
4829 // bounds for a layer that actually does not clip.
4830 gfx::Transform identity_matrix;
4831 gfx::PointF anchor;
[email protected]aedf4e52013-01-09 23:24:444832
[email protected]fb661802013-03-25 01:59:324833 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454834 TestSharedBitmapManager shared_bitmap_manager;
4835 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324836 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4837 SetLayerPropertiesForTesting(root.get(),
4838 identity_matrix,
[email protected]fb661802013-03-25 01:59:324839 anchor,
4840 gfx::PointF(),
4841 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574842 true,
[email protected]fb661802013-03-25 01:59:324843 false);
4844 {
4845 scoped_ptr<LayerImpl> intermediate_layer =
4846 LayerImpl::Create(host_impl.active_tree(), 123);
4847 // this layer is positioned, and hit testing should correctly know where the
4848 // layer is located.
4849 gfx::PointF position(10.f, 10.f);
4850 gfx::Size bounds(50, 50);
4851 SetLayerPropertiesForTesting(intermediate_layer.get(),
4852 identity_matrix,
[email protected]fb661802013-03-25 01:59:324853 anchor,
4854 position,
4855 bounds,
[email protected]56fffdd2014-02-11 19:50:574856 true,
[email protected]fb661802013-03-25 01:59:324857 false);
4858 // Sanity check the intermediate layer should not clip.
4859 ASSERT_FALSE(intermediate_layer->masks_to_bounds());
4860 ASSERT_FALSE(intermediate_layer->mask_layer());
[email protected]aedf4e52013-01-09 23:24:444861
[email protected]fb661802013-03-25 01:59:324862 // The child of the intermediate_layer is translated so that it does not
4863 // overlap intermediate_layer at all. If child is incorrectly clipped, we
4864 // would not be able to hit it successfully.
4865 scoped_ptr<LayerImpl> child =
4866 LayerImpl::Create(host_impl.active_tree(), 456);
4867 position = gfx::PointF(60.f, 60.f); // 70, 70 in screen space
4868 bounds = gfx::Size(20, 20);
4869 SetLayerPropertiesForTesting(child.get(),
4870 identity_matrix,
[email protected]fb661802013-03-25 01:59:324871 anchor,
4872 position,
4873 bounds,
[email protected]56fffdd2014-02-11 19:50:574874 true,
[email protected]fb661802013-03-25 01:59:324875 false);
4876 child->SetDrawsContent(true);
4877 intermediate_layer->AddChild(child.Pass());
4878 root->AddChild(intermediate_layer.Pass());
4879 }
[email protected]aedf4e52013-01-09 23:24:444880
[email protected]50761e92013-03-29 20:51:284881 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534882 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4883 root.get(), root->bounds(), &render_surface_layer_list);
4884 inputs.can_adjust_raster_scales = true;
4885 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:444886
[email protected]fb661802013-03-25 01:59:324887 // Sanity check the scenario we just created.
4888 ASSERT_EQ(1u, render_surface_layer_list.size());
4889 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234890 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]aedf4e52013-01-09 23:24:444891
[email protected]fb661802013-03-25 01:59:324892 // Hit testing for a point outside the layer should return a null pointer.
4893 gfx::Point test_point(69, 69);
4894 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4895 test_point, render_surface_layer_list);
4896 EXPECT_FALSE(result_layer);
[email protected]aedf4e52013-01-09 23:24:444897
[email protected]fb661802013-03-25 01:59:324898 test_point = gfx::Point(91, 91);
4899 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4900 test_point, render_surface_layer_list);
4901 EXPECT_FALSE(result_layer);
4902
4903 // Hit testing for a point inside should return the child layer.
4904 test_point = gfx::Point(71, 71);
4905 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4906 test_point, render_surface_layer_list);
4907 ASSERT_TRUE(result_layer);
4908 EXPECT_EQ(456, result_layer->id());
4909
4910 test_point = gfx::Point(89, 89);
4911 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4912 test_point, render_surface_layer_list);
4913 ASSERT_TRUE(result_layer);
4914 EXPECT_EQ(456, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:444915}
4916
[email protected]989386c2013-07-18 21:37:234917TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayers) {
[email protected]fb661802013-03-25 01:59:324918 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454919 TestSharedBitmapManager shared_bitmap_manager;
4920 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324921 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:144922
[email protected]fb661802013-03-25 01:59:324923 gfx::Transform identity_matrix;
4924 gfx::PointF anchor;
4925 gfx::PointF position;
4926 gfx::Size bounds(100, 100);
4927 SetLayerPropertiesForTesting(root.get(),
4928 identity_matrix,
[email protected]fb661802013-03-25 01:59:324929 anchor,
4930 position,
4931 bounds,
[email protected]56fffdd2014-02-11 19:50:574932 true,
[email protected]fb661802013-03-25 01:59:324933 false);
4934 root->SetDrawsContent(true);
4935 {
4936 // child 1 and child2 are initialized to overlap between x=50 and x=60.
4937 // grand_child is set to overlap both child1 and child2 between y=50 and
4938 // y=60. The expected stacking order is: (front) child2, (second)
4939 // grand_child, (third) child1, and (back) the root layer behind all other
4940 // layers.
[email protected]ecc12622012-10-30 20:45:424941
[email protected]fb661802013-03-25 01:59:324942 scoped_ptr<LayerImpl> child1 =
4943 LayerImpl::Create(host_impl.active_tree(), 2);
4944 scoped_ptr<LayerImpl> child2 =
4945 LayerImpl::Create(host_impl.active_tree(), 3);
4946 scoped_ptr<LayerImpl> grand_child1 =
4947 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:144948
[email protected]fb661802013-03-25 01:59:324949 position = gfx::PointF(10.f, 10.f);
4950 bounds = gfx::Size(50, 50);
4951 SetLayerPropertiesForTesting(child1.get(),
4952 identity_matrix,
[email protected]fb661802013-03-25 01:59:324953 anchor,
4954 position,
4955 bounds,
[email protected]56fffdd2014-02-11 19:50:574956 true,
[email protected]fb661802013-03-25 01:59:324957 false);
4958 child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144959
[email protected]fb661802013-03-25 01:59:324960 position = gfx::PointF(50.f, 10.f);
4961 bounds = gfx::Size(50, 50);
4962 SetLayerPropertiesForTesting(child2.get(),
4963 identity_matrix,
[email protected]fb661802013-03-25 01:59:324964 anchor,
4965 position,
4966 bounds,
[email protected]56fffdd2014-02-11 19:50:574967 true,
[email protected]fb661802013-03-25 01:59:324968 false);
4969 child2->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144970
[email protected]fb661802013-03-25 01:59:324971 // Remember that grand_child is positioned with respect to its parent (i.e.
4972 // child1). In screen space, the intended position is (10, 50), with size
4973 // 100 x 50.
4974 position = gfx::PointF(0.f, 40.f);
4975 bounds = gfx::Size(100, 50);
4976 SetLayerPropertiesForTesting(grand_child1.get(),
4977 identity_matrix,
[email protected]fb661802013-03-25 01:59:324978 anchor,
4979 position,
4980 bounds,
[email protected]56fffdd2014-02-11 19:50:574981 true,
[email protected]fb661802013-03-25 01:59:324982 false);
4983 grand_child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144984
[email protected]fb661802013-03-25 01:59:324985 child1->AddChild(grand_child1.Pass());
4986 root->AddChild(child1.Pass());
4987 root->AddChild(child2.Pass());
4988 }
[email protected]94f206c12012-08-25 00:09:144989
[email protected]fb661802013-03-25 01:59:324990 LayerImpl* child1 = root->children()[0];
4991 LayerImpl* child2 = root->children()[1];
4992 LayerImpl* grand_child1 = child1->children()[0];
4993
[email protected]50761e92013-03-29 20:51:284994 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534995 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4996 root.get(), root->bounds(), &render_surface_layer_list);
4997 inputs.can_adjust_raster_scales = true;
4998 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324999
5000 // Sanity check the scenario we just created.
5001 ASSERT_TRUE(child1);
5002 ASSERT_TRUE(child2);
5003 ASSERT_TRUE(grand_child1);
5004 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:235005
5006 RenderSurfaceImpl* root_render_surface = root->render_surface();
5007 ASSERT_EQ(4u, root_render_surface->layer_list().size());
5008 ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer
5009 ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1
5010 ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1
5011 ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2
[email protected]fb661802013-03-25 01:59:325012
5013 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5014 // the root layer.
5015 gfx::Point test_point = gfx::Point(1, 1);
5016 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5017 test_point, render_surface_layer_list);
5018 ASSERT_TRUE(result_layer);
5019 EXPECT_EQ(1, result_layer->id());
5020
5021 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5022 // on top.
5023 test_point = gfx::Point(15, 15);
5024 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5025 test_point, render_surface_layer_list);
5026 ASSERT_TRUE(result_layer);
5027 EXPECT_EQ(2, result_layer->id());
5028
5029 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5030 test_point = gfx::Point(51, 20);
5031 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5032 test_point, render_surface_layer_list);
5033 ASSERT_TRUE(result_layer);
5034 EXPECT_EQ(3, result_layer->id());
5035
5036 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5037 // top.
5038 test_point = gfx::Point(80, 51);
5039 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5040 test_point, render_surface_layer_list);
5041 ASSERT_TRUE(result_layer);
5042 EXPECT_EQ(3, result_layer->id());
5043
5044 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5045 // of all other layers.
5046 test_point = gfx::Point(51, 51);
5047 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5048 test_point, render_surface_layer_list);
5049 ASSERT_TRUE(result_layer);
5050 EXPECT_EQ(3, result_layer->id());
5051
5052 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5053 // be on top.
5054 test_point = gfx::Point(20, 51);
5055 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5056 test_point, render_surface_layer_list);
5057 ASSERT_TRUE(result_layer);
5058 EXPECT_EQ(4, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145059}
5060
[email protected]989386c2013-07-18 21:37:235061TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) {
[email protected]fb661802013-03-25 01:59:325062 //
5063 // The geometry is set up similarly to the previous case, but
5064 // all layers are forced to be render surfaces now.
5065 //
5066 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455067 TestSharedBitmapManager shared_bitmap_manager;
5068 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325069 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145070
[email protected]fb661802013-03-25 01:59:325071 gfx::Transform identity_matrix;
5072 gfx::PointF anchor;
5073 gfx::PointF position;
5074 gfx::Size bounds(100, 100);
5075 SetLayerPropertiesForTesting(root.get(),
5076 identity_matrix,
[email protected]fb661802013-03-25 01:59:325077 anchor,
5078 position,
5079 bounds,
[email protected]56fffdd2014-02-11 19:50:575080 true,
[email protected]fb661802013-03-25 01:59:325081 false);
5082 root->SetDrawsContent(true);
5083 {
5084 // child 1 and child2 are initialized to overlap between x=50 and x=60.
5085 // grand_child is set to overlap both child1 and child2 between y=50 and
5086 // y=60. The expected stacking order is: (front) child2, (second)
5087 // grand_child, (third) child1, and (back) the root layer behind all other
5088 // layers.
[email protected]94f206c12012-08-25 00:09:145089
[email protected]fb661802013-03-25 01:59:325090 scoped_ptr<LayerImpl> child1 =
5091 LayerImpl::Create(host_impl.active_tree(), 2);
5092 scoped_ptr<LayerImpl> child2 =
5093 LayerImpl::Create(host_impl.active_tree(), 3);
5094 scoped_ptr<LayerImpl> grand_child1 =
5095 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:145096
[email protected]fb661802013-03-25 01:59:325097 position = gfx::PointF(10.f, 10.f);
5098 bounds = gfx::Size(50, 50);
5099 SetLayerPropertiesForTesting(child1.get(),
5100 identity_matrix,
[email protected]fb661802013-03-25 01:59:325101 anchor,
5102 position,
5103 bounds,
[email protected]56fffdd2014-02-11 19:50:575104 true,
[email protected]fb661802013-03-25 01:59:325105 false);
5106 child1->SetDrawsContent(true);
5107 child1->SetForceRenderSurface(true);
[email protected]ecc12622012-10-30 20:45:425108
[email protected]fb661802013-03-25 01:59:325109 position = gfx::PointF(50.f, 10.f);
5110 bounds = gfx::Size(50, 50);
5111 SetLayerPropertiesForTesting(child2.get(),
5112 identity_matrix,
[email protected]fb661802013-03-25 01:59:325113 anchor,
5114 position,
5115 bounds,
[email protected]56fffdd2014-02-11 19:50:575116 true,
[email protected]fb661802013-03-25 01:59:325117 false);
5118 child2->SetDrawsContent(true);
[email protected]7aba6662013-03-12 10:17:345119 child2->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015120
[email protected]fb661802013-03-25 01:59:325121 // Remember that grand_child is positioned with respect to its parent (i.e.
5122 // child1). In screen space, the intended position is (10, 50), with size
5123 // 100 x 50.
5124 position = gfx::PointF(0.f, 40.f);
5125 bounds = gfx::Size(100, 50);
5126 SetLayerPropertiesForTesting(grand_child1.get(),
5127 identity_matrix,
[email protected]fb661802013-03-25 01:59:325128 anchor,
5129 position,
5130 bounds,
[email protected]56fffdd2014-02-11 19:50:575131 true,
[email protected]fb661802013-03-25 01:59:325132 false);
5133 grand_child1->SetDrawsContent(true);
5134 grand_child1->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015135
[email protected]fb661802013-03-25 01:59:325136 child1->AddChild(grand_child1.Pass());
5137 root->AddChild(child1.Pass());
5138 root->AddChild(child2.Pass());
5139 }
[email protected]dc462d782012-11-21 21:43:015140
[email protected]fb661802013-03-25 01:59:325141 LayerImpl* child1 = root->children()[0];
5142 LayerImpl* child2 = root->children()[1];
5143 LayerImpl* grand_child1 = child1->children()[0];
[email protected]dc462d782012-11-21 21:43:015144
[email protected]50761e92013-03-29 20:51:285145 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535146 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5147 root.get(), root->bounds(), &render_surface_layer_list);
5148 inputs.can_adjust_raster_scales = true;
5149 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]dc462d782012-11-21 21:43:015150
[email protected]fb661802013-03-25 01:59:325151 // Sanity check the scenario we just created.
5152 ASSERT_TRUE(child1);
5153 ASSERT_TRUE(child2);
5154 ASSERT_TRUE(grand_child1);
5155 ASSERT_TRUE(child1->render_surface());
5156 ASSERT_TRUE(child2->render_surface());
5157 ASSERT_TRUE(grand_child1->render_surface());
5158 ASSERT_EQ(4u, render_surface_layer_list.size());
5159 // The root surface has the root layer, and child1's and child2's render
5160 // surfaces.
5161 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
5162 // The child1 surface has the child1 layer and grand_child1's render surface.
5163 ASSERT_EQ(2u, child1->render_surface()->layer_list().size());
5164 ASSERT_EQ(1u, child2->render_surface()->layer_list().size());
5165 ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235166 ASSERT_EQ(1, render_surface_layer_list.at(0)->id()); // root layer
[email protected]fb661802013-03-25 01:59:325167 ASSERT_EQ(2, render_surface_layer_list[1]->id()); // child1
[email protected]989386c2013-07-18 21:37:235168 ASSERT_EQ(4, render_surface_layer_list.at(2)->id()); // grand_child1
[email protected]fb661802013-03-25 01:59:325169 ASSERT_EQ(3, render_surface_layer_list[3]->id()); // child2
[email protected]dc462d782012-11-21 21:43:015170
[email protected]fb661802013-03-25 01:59:325171 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5172 // the root layer.
5173 gfx::Point test_point = gfx::Point(1, 1);
5174 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5175 test_point, render_surface_layer_list);
5176 ASSERT_TRUE(result_layer);
5177 EXPECT_EQ(1, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015178
[email protected]fb661802013-03-25 01:59:325179 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5180 // on top.
5181 test_point = gfx::Point(15, 15);
5182 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5183 test_point, render_surface_layer_list);
5184 ASSERT_TRUE(result_layer);
5185 EXPECT_EQ(2, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015186
[email protected]fb661802013-03-25 01:59:325187 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5188 test_point = gfx::Point(51, 20);
5189 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5190 test_point, render_surface_layer_list);
5191 ASSERT_TRUE(result_layer);
5192 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015193
[email protected]fb661802013-03-25 01:59:325194 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5195 // top.
5196 test_point = gfx::Point(80, 51);
5197 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5198 test_point, render_surface_layer_list);
5199 ASSERT_TRUE(result_layer);
5200 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015201
[email protected]fb661802013-03-25 01:59:325202 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5203 // of all other layers.
5204 test_point = gfx::Point(51, 51);
5205 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5206 test_point, render_surface_layer_list);
5207 ASSERT_TRUE(result_layer);
5208 EXPECT_EQ(3, result_layer->id());
5209
5210 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5211 // be on top.
5212 test_point = gfx::Point(20, 51);
5213 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5214 test_point, render_surface_layer_list);
5215 ASSERT_TRUE(result_layer);
5216 EXPECT_EQ(4, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015217}
5218
[email protected]afc4f262013-10-05 01:14:105219TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayers) {
5220 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455221 TestSharedBitmapManager shared_bitmap_manager;
5222 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]afc4f262013-10-05 01:14:105223
5224 // Layer 1 - root
5225 scoped_ptr<LayerImpl> root =
5226 LayerImpl::Create(host_impl.active_tree(), 1);
5227 gfx::Transform identity_matrix;
5228 gfx::PointF anchor;
5229 gfx::PointF position;
5230 gfx::Size bounds(100, 100);
5231 SetLayerPropertiesForTesting(root.get(),
5232 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105233 anchor,
5234 position,
5235 bounds,
[email protected]56fffdd2014-02-11 19:50:575236 true,
[email protected]afc4f262013-10-05 01:14:105237 false);
5238 root->SetDrawsContent(true);
5239
5240 {
5241 // Layer 2 - empty: drawsContent=false
5242 gfx::PointF position(10.f, 10.f);
5243 gfx::Size bounds(30, 30);
5244 scoped_ptr<LayerImpl> empty_layer =
5245 LayerImpl::Create(host_impl.active_tree(), 2);
5246 SetLayerPropertiesForTesting(empty_layer.get(),
5247 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105248 anchor,
5249 position,
5250 bounds,
[email protected]56fffdd2014-02-11 19:50:575251 true,
[email protected]afc4f262013-10-05 01:14:105252 false);
5253
5254 empty_layer->SetDrawsContent(false);
5255 root->AddChild(empty_layer.Pass());
5256 }
5257
5258 {
5259 // Layer 3 - empty, but has touch handler
5260 gfx::PointF position(10.f, 60.f);
5261 gfx::Size bounds(30, 30);
5262 scoped_ptr<LayerImpl> test_layer =
5263 LayerImpl::Create(host_impl.active_tree(), 3);
5264 SetLayerPropertiesForTesting(test_layer.get(),
5265 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105266 anchor,
5267 position,
5268 bounds,
[email protected]56fffdd2014-02-11 19:50:575269 true,
[email protected]afc4f262013-10-05 01:14:105270 false);
5271
5272 test_layer->SetDrawsContent(false);
5273 Region touch_handler_region(gfx::Rect(10, 10, 10, 10));
5274 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5275 root->AddChild(test_layer.Pass());
5276 }
5277
5278 {
5279 // Layer 4 - empty, but has mousewheel handler
5280 gfx::PointF position(60.f, 60.f);
5281 gfx::Size bounds(30, 30);
5282 scoped_ptr<LayerImpl> test_layer =
5283 LayerImpl::Create(host_impl.active_tree(), 4);
5284 SetLayerPropertiesForTesting(test_layer.get(),
5285 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105286 anchor,
5287 position,
5288 bounds,
[email protected]56fffdd2014-02-11 19:50:575289 true,
[email protected]afc4f262013-10-05 01:14:105290 false);
5291
5292 test_layer->SetDrawsContent(false);
5293 test_layer->SetHaveWheelEventHandlers(true);
5294 root->AddChild(test_layer.Pass());
5295 }
5296
5297 LayerImplList render_surface_layer_list;
5298 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5299 root.get(), root->bounds(), &render_surface_layer_list);
5300 inputs.can_adjust_raster_scales = true;
5301 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5302
5303 // Verify that the root layer and empty layers with touch/wheel handlers
5304 // (but not the empty layer without a touch handler) are in the RSSL.
5305 ASSERT_EQ(1u, render_surface_layer_list.size());
5306 EXPECT_EQ(1, render_surface_layer_list[0]->id());
[email protected]22538a2d2013-11-12 11:24:455307 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
[email protected]afc4f262013-10-05 01:14:105308 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]22538a2d2013-11-12 11:24:455309 EXPECT_EQ(3, root->render_surface()->layer_list().at(1)->id());
5310 EXPECT_EQ(4, root->render_surface()->layer_list().at(2)->id());
[email protected]afc4f262013-10-05 01:14:105311
5312 // Hit testing for a point inside the empty no-handlers layer should return
5313 // the root layer.
5314 gfx::Point test_point = gfx::Point(15, 15);
5315 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5316 test_point, render_surface_layer_list);
5317 ASSERT_TRUE(result_layer);
[email protected]22538a2d2013-11-12 11:24:455318 EXPECT_EQ(1, result_layer->id());
[email protected]afc4f262013-10-05 01:14:105319
5320 // Hit testing for a point inside the touch handler layer should return it.
5321 test_point = gfx::Point(15, 75);
5322 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5323 test_point, render_surface_layer_list);
5324 ASSERT_TRUE(result_layer);
5325 EXPECT_EQ(3, result_layer->id());
5326
5327 // Hit testing for a point inside the mousewheel layer should return it.
5328 test_point = gfx::Point(75, 75);
5329 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5330 test_point, render_surface_layer_list);
5331 ASSERT_TRUE(result_layer);
5332 EXPECT_EQ(4, result_layer->id());
5333}
5334
[email protected]989386c2013-07-18 21:37:235335TEST_F(LayerTreeHostCommonTest,
5336 HitCheckingTouchHandlerRegionsForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:325337 // Hit checking on an empty render_surface_layer_list should return a null
5338 // pointer.
[email protected]50761e92013-03-29 20:51:285339 LayerImplList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145340
[email protected]fb661802013-03-25 01:59:325341 gfx::Point test_point(0, 0);
5342 LayerImpl* result_layer =
5343 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5344 test_point, render_surface_layer_list);
5345 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145346
[email protected]fb661802013-03-25 01:59:325347 test_point = gfx::Point(10, 20);
5348 result_layer =
5349 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5350 test_point, render_surface_layer_list);
5351 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145352}
5353
[email protected]989386c2013-07-18 21:37:235354TEST_F(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:325355 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455356 TestSharedBitmapManager shared_bitmap_manager;
5357 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325358 scoped_ptr<LayerImpl> root =
5359 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145360
[email protected]fb661802013-03-25 01:59:325361 gfx::Transform identity_matrix;
5362 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5363 gfx::PointF anchor;
5364 gfx::PointF position;
5365 gfx::Size bounds(100, 100);
5366 SetLayerPropertiesForTesting(root.get(),
5367 identity_matrix,
[email protected]fb661802013-03-25 01:59:325368 anchor,
5369 position,
5370 bounds,
[email protected]56fffdd2014-02-11 19:50:575371 true,
[email protected]fb661802013-03-25 01:59:325372 false);
5373 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145374
[email protected]50761e92013-03-29 20:51:285375 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535376 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5377 root.get(), root->bounds(), &render_surface_layer_list);
5378 inputs.can_adjust_raster_scales = true;
5379 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145380
[email protected]fb661802013-03-25 01:59:325381 // Sanity check the scenario we just created.
5382 ASSERT_EQ(1u, render_surface_layer_list.size());
5383 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145384
[email protected]fb661802013-03-25 01:59:325385 // Hit checking for any point should return a null pointer for a layer without
5386 // any touch event handler regions.
5387 gfx::Point test_point(11, 11);
5388 LayerImpl* result_layer =
5389 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5390 test_point, render_surface_layer_list);
5391 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145392
[email protected]fb661802013-03-25 01:59:325393 root->SetTouchEventHandlerRegion(touch_handler_region);
5394 // Hit checking for a point outside the layer should return a null pointer.
5395 test_point = gfx::Point(101, 101);
5396 result_layer =
5397 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5398 test_point, render_surface_layer_list);
5399 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145400
[email protected]fb661802013-03-25 01:59:325401 test_point = gfx::Point(-1, -1);
5402 result_layer =
5403 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5404 test_point, render_surface_layer_list);
5405 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145406
[email protected]fb661802013-03-25 01:59:325407 // Hit checking for a point inside the layer, but outside the touch handler
5408 // region should return a null pointer.
5409 test_point = gfx::Point(1, 1);
5410 result_layer =
5411 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5412 test_point, render_surface_layer_list);
5413 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145414
[email protected]fb661802013-03-25 01:59:325415 test_point = gfx::Point(99, 99);
5416 result_layer =
5417 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5418 test_point, render_surface_layer_list);
5419 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145420
[email protected]fb661802013-03-25 01:59:325421 // Hit checking for a point inside the touch event handler region should
5422 // return the root layer.
5423 test_point = gfx::Point(11, 11);
5424 result_layer =
5425 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5426 test_point, render_surface_layer_list);
5427 ASSERT_TRUE(result_layer);
5428 EXPECT_EQ(12345, result_layer->id());
5429
5430 test_point = gfx::Point(59, 59);
5431 result_layer =
5432 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5433 test_point, render_surface_layer_list);
5434 ASSERT_TRUE(result_layer);
5435 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145436}
5437
[email protected]989386c2013-07-18 21:37:235438TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325439 HitCheckingTouchHandlerRegionsForUninvertibleTransform) {
5440 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455441 TestSharedBitmapManager shared_bitmap_manager;
5442 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325443 scoped_ptr<LayerImpl> root =
5444 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145445
[email protected]fb661802013-03-25 01:59:325446 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:265447 uninvertible_transform.matrix().set(0, 0, 0.0);
5448 uninvertible_transform.matrix().set(1, 1, 0.0);
5449 uninvertible_transform.matrix().set(2, 2, 0.0);
5450 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:325451 ASSERT_FALSE(uninvertible_transform.IsInvertible());
[email protected]94f206c12012-08-25 00:09:145452
[email protected]fb661802013-03-25 01:59:325453 gfx::Transform identity_matrix;
5454 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5455 gfx::PointF anchor;
5456 gfx::PointF position;
5457 gfx::Size bounds(100, 100);
5458 SetLayerPropertiesForTesting(root.get(),
5459 uninvertible_transform,
[email protected]fb661802013-03-25 01:59:325460 anchor,
5461 position,
5462 bounds,
[email protected]56fffdd2014-02-11 19:50:575463 true,
[email protected]fb661802013-03-25 01:59:325464 false);
5465 root->SetDrawsContent(true);
5466 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145467
[email protected]50761e92013-03-29 20:51:285468 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535469 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5470 root.get(), root->bounds(), &render_surface_layer_list);
5471 inputs.can_adjust_raster_scales = true;
5472 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145473
[email protected]fb661802013-03-25 01:59:325474 // Sanity check the scenario we just created.
5475 ASSERT_EQ(1u, render_surface_layer_list.size());
5476 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5477 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
[email protected]de4afb5e2012-12-20 00:11:345478
[email protected]fb661802013-03-25 01:59:325479 // Hit checking any point should not hit the touch handler region on the
5480 // layer. If the invertible matrix is accidentally ignored and treated like an
5481 // identity, then the hit testing will incorrectly hit the layer when it
5482 // shouldn't.
5483 gfx::Point test_point(1, 1);
5484 LayerImpl* result_layer =
5485 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5486 test_point, render_surface_layer_list);
5487 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345488
[email protected]fb661802013-03-25 01:59:325489 test_point = gfx::Point(10, 10);
5490 result_layer =
5491 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5492 test_point, render_surface_layer_list);
5493 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345494
[email protected]fb661802013-03-25 01:59:325495 test_point = gfx::Point(10, 30);
5496 result_layer =
5497 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5498 test_point, render_surface_layer_list);
5499 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345500
[email protected]fb661802013-03-25 01:59:325501 test_point = gfx::Point(50, 50);
5502 result_layer =
5503 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5504 test_point, render_surface_layer_list);
5505 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145506
[email protected]fb661802013-03-25 01:59:325507 test_point = gfx::Point(67, 48);
5508 result_layer =
5509 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5510 test_point, render_surface_layer_list);
5511 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145512
[email protected]fb661802013-03-25 01:59:325513 test_point = gfx::Point(99, 99);
5514 result_layer =
5515 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5516 test_point, render_surface_layer_list);
5517 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145518
[email protected]fb661802013-03-25 01:59:325519 test_point = gfx::Point(-1, -1);
5520 result_layer =
5521 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5522 test_point, render_surface_layer_list);
5523 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145524}
5525
[email protected]989386c2013-07-18 21:37:235526TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325527 HitCheckingTouchHandlerRegionsForSinglePositionedLayer) {
5528 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455529 TestSharedBitmapManager shared_bitmap_manager;
5530 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325531 scoped_ptr<LayerImpl> root =
5532 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145533
[email protected]fb661802013-03-25 01:59:325534 gfx::Transform identity_matrix;
5535 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5536 gfx::PointF anchor;
5537 // this layer is positioned, and hit testing should correctly know where the
5538 // layer is located.
5539 gfx::PointF position(50.f, 50.f);
5540 gfx::Size bounds(100, 100);
5541 SetLayerPropertiesForTesting(root.get(),
5542 identity_matrix,
[email protected]fb661802013-03-25 01:59:325543 anchor,
5544 position,
5545 bounds,
[email protected]56fffdd2014-02-11 19:50:575546 true,
[email protected]fb661802013-03-25 01:59:325547 false);
5548 root->SetDrawsContent(true);
5549 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145550
[email protected]50761e92013-03-29 20:51:285551 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535552 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5553 root.get(), root->bounds(), &render_surface_layer_list);
5554 inputs.can_adjust_raster_scales = true;
5555 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145556
[email protected]fb661802013-03-25 01:59:325557 // Sanity check the scenario we just created.
5558 ASSERT_EQ(1u, render_surface_layer_list.size());
5559 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145560
[email protected]fb661802013-03-25 01:59:325561 // Hit checking for a point outside the layer should return a null pointer.
5562 gfx::Point test_point(49, 49);
5563 LayerImpl* result_layer =
5564 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5565 test_point, render_surface_layer_list);
5566 EXPECT_FALSE(result_layer);
5567
5568 // Even though the layer has a touch handler region containing (101, 101), it
5569 // should not be visible there since the root render surface would clamp it.
5570 test_point = gfx::Point(101, 101);
5571 result_layer =
5572 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5573 test_point, render_surface_layer_list);
5574 EXPECT_FALSE(result_layer);
5575
5576 // Hit checking for a point inside the layer, but outside the touch handler
5577 // region should return a null pointer.
5578 test_point = gfx::Point(51, 51);
5579 result_layer =
5580 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5581 test_point, render_surface_layer_list);
5582 EXPECT_FALSE(result_layer);
5583
5584 // Hit checking for a point inside the touch event handler region should
5585 // return the root layer.
5586 test_point = gfx::Point(61, 61);
5587 result_layer =
5588 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5589 test_point, render_surface_layer_list);
5590 ASSERT_TRUE(result_layer);
5591 EXPECT_EQ(12345, result_layer->id());
5592
5593 test_point = gfx::Point(99, 99);
5594 result_layer =
5595 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5596 test_point, render_surface_layer_list);
5597 ASSERT_TRUE(result_layer);
5598 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145599}
5600
[email protected]989386c2013-07-18 21:37:235601TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325602 HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) {
5603 // A layer's visible content rect is actually in the layer's content space.
5604 // The screen space transform converts from the layer's origin space to screen
5605 // space. This test makes sure that hit testing works correctly accounts for
5606 // the contents scale. A contents scale that is not 1 effectively forces a
5607 // non-identity transform between layer's content space and layer's origin
5608 // space. The hit testing code must take this into account.
5609 //
5610 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
5611 // contents scale is ignored, then hit checking will mis-interpret the visible
5612 // content rect as being larger than the actual bounds of the layer.
5613 //
5614 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455615 TestSharedBitmapManager shared_bitmap_manager;
5616 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325617 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145618
[email protected]fb661802013-03-25 01:59:325619 gfx::Transform identity_matrix;
5620 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145621
[email protected]fb661802013-03-25 01:59:325622 SetLayerPropertiesForTesting(root.get(),
5623 identity_matrix,
[email protected]fb661802013-03-25 01:59:325624 anchor,
5625 gfx::PointF(),
5626 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575627 true,
[email protected]fb661802013-03-25 01:59:325628 false);
5629 {
5630 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5631 gfx::PointF position(25.f, 25.f);
5632 gfx::Size bounds(50, 50);
5633 scoped_ptr<LayerImpl> test_layer =
5634 LayerImpl::Create(host_impl.active_tree(), 12345);
5635 SetLayerPropertiesForTesting(test_layer.get(),
5636 identity_matrix,
[email protected]fb661802013-03-25 01:59:325637 anchor,
5638 position,
5639 bounds,
[email protected]56fffdd2014-02-11 19:50:575640 true,
[email protected]fb661802013-03-25 01:59:325641 false);
[email protected]94f206c12012-08-25 00:09:145642
[email protected]fb661802013-03-25 01:59:325643 // override content bounds and contents scale
5644 test_layer->SetContentBounds(gfx::Size(100, 100));
5645 test_layer->SetContentsScale(2, 2);
[email protected]94f206c12012-08-25 00:09:145646
[email protected]fb661802013-03-25 01:59:325647 test_layer->SetDrawsContent(true);
5648 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5649 root->AddChild(test_layer.Pass());
5650 }
5651
[email protected]50761e92013-03-29 20:51:285652 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535653 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5654 root.get(), root->bounds(), &render_surface_layer_list);
5655 inputs.can_adjust_raster_scales = true;
5656 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325657
5658 // Sanity check the scenario we just created.
5659 // The visible content rect for test_layer is actually 100x100, even though
5660 // its layout size is 50x50, positioned at 25x25.
5661 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:055662 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect());
[email protected]fb661802013-03-25 01:59:325663 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455664 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:325665
5666 // Hit checking for a point outside the layer should return a null pointer
5667 // (the root layer does not draw content, so it will not be tested either).
5668 gfx::Point test_point(76, 76);
5669 LayerImpl* result_layer =
5670 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5671 test_point, render_surface_layer_list);
5672 EXPECT_FALSE(result_layer);
5673
5674 // Hit checking for a point inside the layer, but outside the touch handler
5675 // region should return a null pointer.
5676 test_point = gfx::Point(26, 26);
5677 result_layer =
5678 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5679 test_point, render_surface_layer_list);
5680 EXPECT_FALSE(result_layer);
5681
5682 test_point = gfx::Point(34, 34);
5683 result_layer =
5684 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5685 test_point, render_surface_layer_list);
5686 EXPECT_FALSE(result_layer);
5687
5688 test_point = gfx::Point(65, 65);
5689 result_layer =
5690 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5691 test_point, render_surface_layer_list);
5692 EXPECT_FALSE(result_layer);
5693
5694 test_point = gfx::Point(74, 74);
5695 result_layer =
5696 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5697 test_point, render_surface_layer_list);
5698 EXPECT_FALSE(result_layer);
5699
5700 // Hit checking for a point inside the touch event handler region should
5701 // return the root layer.
5702 test_point = gfx::Point(35, 35);
5703 result_layer =
5704 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5705 test_point, render_surface_layer_list);
5706 ASSERT_TRUE(result_layer);
5707 EXPECT_EQ(12345, result_layer->id());
5708
5709 test_point = gfx::Point(64, 64);
5710 result_layer =
5711 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5712 test_point, render_surface_layer_list);
5713 ASSERT_TRUE(result_layer);
5714 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145715}
5716
[email protected]989386c2013-07-18 21:37:235717TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325718 HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) {
5719 // The layer's device_scale_factor and page_scale_factor should scale the
5720 // content rect and we should be able to hit the touch handler region by
5721 // scaling the points accordingly.
5722 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455723 TestSharedBitmapManager shared_bitmap_manager;
5724 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325725 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145726
[email protected]fb661802013-03-25 01:59:325727 gfx::Transform identity_matrix;
5728 gfx::PointF anchor;
5729 // Set the bounds of the root layer big enough to fit the child when scaled.
5730 SetLayerPropertiesForTesting(root.get(),
5731 identity_matrix,
[email protected]fb661802013-03-25 01:59:325732 anchor,
5733 gfx::PointF(),
5734 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575735 true,
[email protected]fb661802013-03-25 01:59:325736 false);
5737 {
5738 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5739 gfx::PointF position(25.f, 25.f);
5740 gfx::Size bounds(50, 50);
5741 scoped_ptr<LayerImpl> test_layer =
5742 LayerImpl::Create(host_impl.active_tree(), 12345);
5743 SetLayerPropertiesForTesting(test_layer.get(),
5744 identity_matrix,
[email protected]fb661802013-03-25 01:59:325745 anchor,
5746 position,
5747 bounds,
[email protected]56fffdd2014-02-11 19:50:575748 true,
[email protected]fb661802013-03-25 01:59:325749 false);
[email protected]94f206c12012-08-25 00:09:145750
[email protected]fb661802013-03-25 01:59:325751 test_layer->SetDrawsContent(true);
5752 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5753 root->AddChild(test_layer.Pass());
5754 }
[email protected]94f206c12012-08-25 00:09:145755
[email protected]50761e92013-03-29 20:51:285756 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:325757 float device_scale_factor = 3.f;
5758 float page_scale_factor = 5.f;
[email protected]fb661802013-03-25 01:59:325759 gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize(
5760 gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor));
[email protected]7aad55f2013-07-26 11:25:535761
5762 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5763 root.get(), scaled_bounds_for_root, &render_surface_layer_list);
5764 inputs.device_scale_factor = device_scale_factor;
5765 inputs.page_scale_factor = page_scale_factor;
5766 inputs.page_scale_application_layer = root.get();
5767 inputs.can_adjust_raster_scales = true;
5768 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145769
[email protected]fb661802013-03-25 01:59:325770 // Sanity check the scenario we just created.
5771 // The visible content rect for test_layer is actually 100x100, even though
5772 // its layout size is 50x50, positioned at 25x25.
5773 LayerImpl* test_layer = root->children()[0];
5774 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455775 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145776
[email protected]fb661802013-03-25 01:59:325777 // Check whether the child layer fits into the root after scaled.
5778 EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()),
5779 test_layer->visible_content_rect());
5780
5781 // Hit checking for a point outside the layer should return a null pointer
5782 // (the root layer does not draw content, so it will not be tested either).
5783 gfx::PointF test_point(76.f, 76.f);
5784 test_point =
5785 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5786 LayerImpl* result_layer =
5787 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5788 test_point, render_surface_layer_list);
5789 EXPECT_FALSE(result_layer);
5790
5791 // Hit checking for a point inside the layer, but outside the touch handler
5792 // region should return a null pointer.
5793 test_point = gfx::Point(26, 26);
5794 test_point =
5795 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5796 result_layer =
5797 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5798 test_point, render_surface_layer_list);
5799 EXPECT_FALSE(result_layer);
5800
5801 test_point = gfx::Point(34, 34);
5802 test_point =
5803 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5804 result_layer =
5805 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5806 test_point, render_surface_layer_list);
5807 EXPECT_FALSE(result_layer);
5808
5809 test_point = gfx::Point(65, 65);
5810 test_point =
5811 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5812 result_layer =
5813 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5814 test_point, render_surface_layer_list);
5815 EXPECT_FALSE(result_layer);
5816
5817 test_point = gfx::Point(74, 74);
5818 test_point =
5819 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5820 result_layer =
5821 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5822 test_point, render_surface_layer_list);
5823 EXPECT_FALSE(result_layer);
5824
5825 // Hit checking for a point inside the touch event handler region should
5826 // return the root layer.
5827 test_point = gfx::Point(35, 35);
5828 test_point =
5829 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5830 result_layer =
5831 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5832 test_point, render_surface_layer_list);
5833 ASSERT_TRUE(result_layer);
5834 EXPECT_EQ(12345, result_layer->id());
5835
5836 test_point = gfx::Point(64, 64);
5837 test_point =
5838 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5839 result_layer =
5840 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5841 test_point, render_surface_layer_list);
5842 ASSERT_TRUE(result_layer);
5843 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145844}
5845
[email protected]989386c2013-07-18 21:37:235846TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325847 HitCheckingTouchHandlerRegionsForSimpleClippedLayer) {
5848 // Test that hit-checking will only work for the visible portion of a layer,
5849 // and not the entire layer bounds. Here we just test the simple axis-aligned
5850 // case.
5851 gfx::Transform identity_matrix;
5852 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145853
[email protected]fb661802013-03-25 01:59:325854 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455855 TestSharedBitmapManager shared_bitmap_manager;
5856 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325857 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5858 SetLayerPropertiesForTesting(root.get(),
5859 identity_matrix,
[email protected]fb661802013-03-25 01:59:325860 anchor,
5861 gfx::PointF(),
5862 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575863 true,
[email protected]fb661802013-03-25 01:59:325864 false);
5865 {
5866 scoped_ptr<LayerImpl> clipping_layer =
5867 LayerImpl::Create(host_impl.active_tree(), 123);
5868 // this layer is positioned, and hit testing should correctly know where the
5869 // layer is located.
5870 gfx::PointF position(25.f, 25.f);
5871 gfx::Size bounds(50, 50);
5872 SetLayerPropertiesForTesting(clipping_layer.get(),
5873 identity_matrix,
[email protected]fb661802013-03-25 01:59:325874 anchor,
5875 position,
5876 bounds,
[email protected]56fffdd2014-02-11 19:50:575877 true,
[email protected]fb661802013-03-25 01:59:325878 false);
5879 clipping_layer->SetMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:145880
[email protected]fb661802013-03-25 01:59:325881 scoped_ptr<LayerImpl> child =
5882 LayerImpl::Create(host_impl.active_tree(), 456);
5883 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5884 position = gfx::PointF(-50.f, -50.f);
5885 bounds = gfx::Size(300, 300);
5886 SetLayerPropertiesForTesting(child.get(),
5887 identity_matrix,
[email protected]fb661802013-03-25 01:59:325888 anchor,
5889 position,
5890 bounds,
[email protected]56fffdd2014-02-11 19:50:575891 true,
[email protected]fb661802013-03-25 01:59:325892 false);
5893 child->SetDrawsContent(true);
5894 child->SetTouchEventHandlerRegion(touch_handler_region);
5895 clipping_layer->AddChild(child.Pass());
5896 root->AddChild(clipping_layer.Pass());
5897 }
[email protected]94f206c12012-08-25 00:09:145898
[email protected]50761e92013-03-29 20:51:285899 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535900 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5901 root.get(), root->bounds(), &render_surface_layer_list);
5902 inputs.can_adjust_raster_scales = true;
5903 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325904
5905 // Sanity check the scenario we just created.
5906 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455907 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5908 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:325909
5910 // Hit checking for a point outside the layer should return a null pointer.
5911 // Despite the child layer being very large, it should be clipped to the root
5912 // layer's bounds.
5913 gfx::Point test_point(24, 24);
5914 LayerImpl* result_layer =
5915 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5916 test_point, render_surface_layer_list);
5917 EXPECT_FALSE(result_layer);
5918
5919 // Hit checking for a point inside the layer, but outside the touch handler
5920 // region should return a null pointer.
5921 test_point = gfx::Point(35, 35);
5922 result_layer =
5923 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5924 test_point, render_surface_layer_list);
5925 EXPECT_FALSE(result_layer);
5926
5927 test_point = gfx::Point(74, 74);
5928 result_layer =
5929 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5930 test_point, render_surface_layer_list);
5931 EXPECT_FALSE(result_layer);
5932
5933 // Hit checking for a point inside the touch event handler region should
5934 // return the root layer.
5935 test_point = gfx::Point(25, 25);
5936 result_layer =
5937 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5938 test_point, render_surface_layer_list);
5939 ASSERT_TRUE(result_layer);
5940 EXPECT_EQ(456, result_layer->id());
5941
5942 test_point = gfx::Point(34, 34);
5943 result_layer =
5944 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5945 test_point, render_surface_layer_list);
5946 ASSERT_TRUE(result_layer);
5947 EXPECT_EQ(456, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145948}
5949
[email protected]c974d5d2013-10-24 01:02:485950TEST_F(LayerTreeHostCommonTest,
5951 HitCheckingTouchHandlerOverlappingRegions) {
5952 gfx::Transform identity_matrix;
5953 gfx::PointF anchor;
5954
5955 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455956 TestSharedBitmapManager shared_bitmap_manager;
5957 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c974d5d2013-10-24 01:02:485958 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5959 SetLayerPropertiesForTesting(root.get(),
5960 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:485961 anchor,
5962 gfx::PointF(),
5963 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575964 true,
[email protected]c974d5d2013-10-24 01:02:485965 false);
5966 {
5967 scoped_ptr<LayerImpl> touch_layer =
5968 LayerImpl::Create(host_impl.active_tree(), 123);
5969 // this layer is positioned, and hit testing should correctly know where the
5970 // layer is located.
5971 gfx::PointF position;
5972 gfx::Size bounds(50, 50);
5973 SetLayerPropertiesForTesting(touch_layer.get(),
5974 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:485975 anchor,
5976 position,
5977 bounds,
[email protected]56fffdd2014-02-11 19:50:575978 true,
[email protected]c974d5d2013-10-24 01:02:485979 false);
5980 touch_layer->SetDrawsContent(true);
5981 touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50));
5982 root->AddChild(touch_layer.Pass());
5983 }
5984
5985 {
5986 scoped_ptr<LayerImpl> notouch_layer =
5987 LayerImpl::Create(host_impl.active_tree(), 1234);
5988 // this layer is positioned, and hit testing should correctly know where the
5989 // layer is located.
5990 gfx::PointF position(0, 25);
5991 gfx::Size bounds(50, 50);
5992 SetLayerPropertiesForTesting(notouch_layer.get(),
5993 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:485994 anchor,
5995 position,
5996 bounds,
[email protected]56fffdd2014-02-11 19:50:575997 true,
[email protected]c974d5d2013-10-24 01:02:485998 false);
5999 notouch_layer->SetDrawsContent(true);
6000 root->AddChild(notouch_layer.Pass());
6001 }
6002
6003 LayerImplList render_surface_layer_list;
6004 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6005 root.get(), root->bounds(), &render_surface_layer_list);
6006 inputs.can_adjust_raster_scales = true;
6007 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6008
6009 // Sanity check the scenario we just created.
6010 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:456011 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
6012 ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id());
6013 ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id());
[email protected]c974d5d2013-10-24 01:02:486014
6015 gfx::Point test_point(35, 35);
6016 LayerImpl* result_layer =
6017 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6018 test_point, render_surface_layer_list);
6019 EXPECT_FALSE(result_layer);
6020
6021 test_point = gfx::Point(35, 15);
6022 result_layer =
6023 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6024 test_point, render_surface_layer_list);
6025 ASSERT_TRUE(result_layer);
6026 EXPECT_EQ(123, result_layer->id());
6027
6028 test_point = gfx::Point(35, 65);
6029 result_layer =
6030 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6031 test_point, render_surface_layer_list);
6032 EXPECT_FALSE(result_layer);
6033}
6034
[email protected]fb661802013-03-25 01:59:326035class NoScaleContentLayer : public ContentLayer {
6036 public:
6037 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
6038 return make_scoped_refptr(new NoScaleContentLayer(client));
6039 }
[email protected]94f206c12012-08-25 00:09:146040
[email protected]fb661802013-03-25 01:59:326041 virtual void CalculateContentsScale(float ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066042 float device_scale_factor,
6043 float page_scale_factor,
[email protected]fb661802013-03-25 01:59:326044 bool animating_transform_to_screen,
6045 float* contents_scale_x,
6046 float* contents_scale_y,
6047 gfx::Size* content_bounds) OVERRIDE {
6048 // Skip over the ContentLayer to the base Layer class.
6049 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066050 device_scale_factor,
6051 page_scale_factor,
[email protected]fb661802013-03-25 01:59:326052 animating_transform_to_screen,
6053 contents_scale_x,
6054 contents_scale_y,
6055 content_bounds);
6056 }
[email protected]94f206c12012-08-25 00:09:146057
[email protected]fb661802013-03-25 01:59:326058 protected:
6059 explicit NoScaleContentLayer(ContentLayerClient* client)
6060 : ContentLayer(client) {}
6061 virtual ~NoScaleContentLayer() {}
[email protected]518ee582012-10-24 18:29:446062};
6063
[email protected]fb661802013-03-25 01:59:326064scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
6065 ContentLayerClient* delegate) {
6066 scoped_refptr<NoScaleContentLayer> to_return =
6067 NoScaleContentLayer::Create(delegate);
6068 to_return->SetIsDrawable(true);
6069 return to_return;
[email protected]518ee582012-10-24 18:29:446070}
6071
[email protected]989386c2013-07-18 21:37:236072TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326073 // Verify draw and screen space transforms of layers not in a surface.
6074 MockContentLayerClient delegate;
6075 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:146076
[email protected]fb661802013-03-25 01:59:326077 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6078 SetLayerPropertiesForTesting(parent.get(),
6079 identity_matrix,
[email protected]fb661802013-03-25 01:59:326080 gfx::PointF(),
6081 gfx::PointF(),
6082 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576083 false,
[email protected]fb661802013-03-25 01:59:326084 true);
[email protected]94f206c12012-08-25 00:09:146085
[email protected]fb661802013-03-25 01:59:326086 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6087 SetLayerPropertiesForTesting(child.get(),
6088 identity_matrix,
[email protected]fb661802013-03-25 01:59:326089 gfx::PointF(),
6090 gfx::PointF(2.f, 2.f),
6091 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576092 false,
[email protected]fb661802013-03-25 01:59:326093 true);
[email protected]94f206c12012-08-25 00:09:146094
[email protected]fb661802013-03-25 01:59:326095 scoped_refptr<ContentLayer> child_empty =
6096 CreateDrawableContentLayer(&delegate);
6097 SetLayerPropertiesForTesting(child_empty.get(),
6098 identity_matrix,
[email protected]fb661802013-03-25 01:59:326099 gfx::PointF(),
6100 gfx::PointF(2.f, 2.f),
6101 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576102 false,
[email protected]fb661802013-03-25 01:59:326103 true);
[email protected]f89f5632012-11-14 23:34:456104
[email protected]fb661802013-03-25 01:59:326105 scoped_refptr<NoScaleContentLayer> child_no_scale =
6106 CreateNoScaleDrawableContentLayer(&delegate);
6107 SetLayerPropertiesForTesting(child_no_scale.get(),
6108 identity_matrix,
[email protected]fb661802013-03-25 01:59:326109 gfx::PointF(),
6110 gfx::PointF(2.f, 2.f),
6111 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576112 false,
[email protected]fb661802013-03-25 01:59:326113 true);
[email protected]94f206c12012-08-25 00:09:146114
[email protected]fb661802013-03-25 01:59:326115 parent->AddChild(child);
6116 parent->AddChild(child_empty);
6117 parent->AddChild(child_no_scale);
[email protected]94f206c12012-08-25 00:09:146118
[email protected]d600df7d2013-08-03 02:34:286119 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6120 host->SetRootLayer(parent);
6121
[email protected]fb661802013-03-25 01:59:326122 float device_scale_factor = 2.5f;
6123 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:146124
[email protected]7aad55f2013-07-26 11:25:536125 RenderSurfaceLayerList render_surface_layer_list;
6126 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6127 parent.get(), parent->bounds(), &render_surface_layer_list);
6128 inputs.device_scale_factor = device_scale_factor;
6129 inputs.page_scale_factor = page_scale_factor;
6130 inputs.can_adjust_raster_scales = true;
6131 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446132
[email protected]fb661802013-03-25 01:59:326133 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6134 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6135 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6136 child_empty);
6137 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]94f206c12012-08-25 00:09:146138
[email protected]fb661802013-03-25 01:59:326139 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:146140
[email protected]fb661802013-03-25 01:59:326141 // Verify parent transforms
6142 gfx::Transform expected_parent_transform;
6143 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6144 parent->screen_space_transform());
6145 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6146 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:146147
[email protected]fb661802013-03-25 01:59:326148 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056149 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:146150
[email protected]fb661802013-03-25 01:59:326151 gfx::RectF parent_draw_rect =
6152 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6153 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6154 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:146155
[email protected]2c7c6702013-03-26 03:14:056156 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326157 expected_parent_draw_rect.Scale(device_scale_factor);
6158 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6159 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146160
[email protected]fb661802013-03-25 01:59:326161 // Verify child and child_empty transforms. They should match.
6162 gfx::Transform expected_child_transform;
6163 expected_child_transform.Translate(
6164 device_scale_factor * child->position().x(),
6165 device_scale_factor * child->position().y());
6166 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6167 child->draw_transform());
6168 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6169 child->screen_space_transform());
6170 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6171 child_empty->draw_transform());
6172 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6173 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146174
[email protected]fb661802013-03-25 01:59:326175 // Verify results of transformed child and child_empty rects. They should
6176 // match.
[email protected]2c7c6702013-03-26 03:14:056177 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:146178
[email protected]fb661802013-03-25 01:59:326179 gfx::RectF child_draw_rect =
6180 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6181 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6182 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:146183
[email protected]fb661802013-03-25 01:59:326184 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
6185 child_empty->draw_transform(), child_content_bounds);
6186 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
6187 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:456188
[email protected]fb661802013-03-25 01:59:326189 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
6190 expected_child_draw_rect.Scale(device_scale_factor);
6191 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6192 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
6193 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
6194 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146195
[email protected]fb661802013-03-25 01:59:326196 // Verify child_no_scale transforms
6197 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6198 // All transforms operate on content rects. The child's content rect
6199 // incorporates device scale, but the child_no_scale does not; add it here.
6200 expected_child_no_scale_transform.Scale(device_scale_factor,
6201 device_scale_factor);
6202 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6203 child_no_scale->draw_transform());
6204 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6205 child_no_scale->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146206}
6207
[email protected]989386c2013-07-18 21:37:236208TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326209 // Verify draw and screen space transforms of layers in a surface.
6210 MockContentLayerClient delegate;
6211 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:096212
[email protected]fb661802013-03-25 01:59:326213 gfx::Transform perspective_matrix;
6214 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:096215
[email protected]fb661802013-03-25 01:59:326216 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:056217 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:096218
[email protected]9781afa2013-07-17 23:15:326219 scoped_refptr<Layer> root = Layer::Create();
6220
[email protected]fb661802013-03-25 01:59:326221 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6222 SetLayerPropertiesForTesting(parent.get(),
6223 identity_matrix,
[email protected]fb661802013-03-25 01:59:326224 gfx::PointF(),
6225 gfx::PointF(),
6226 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576227 false,
[email protected]fb661802013-03-25 01:59:326228 true);
[email protected]1b30e8e2012-12-21 02:59:096229
[email protected]fb661802013-03-25 01:59:326230 scoped_refptr<ContentLayer> perspective_surface =
6231 CreateDrawableContentLayer(&delegate);
6232 SetLayerPropertiesForTesting(perspective_surface.get(),
6233 perspective_matrix * scale_small_matrix,
[email protected]fb661802013-03-25 01:59:326234 gfx::PointF(),
6235 gfx::PointF(2.f, 2.f),
6236 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576237 false,
[email protected]fb661802013-03-25 01:59:326238 true);
[email protected]1b30e8e2012-12-21 02:59:096239
[email protected]fb661802013-03-25 01:59:326240 scoped_refptr<ContentLayer> scale_surface =
6241 CreateDrawableContentLayer(&delegate);
6242 SetLayerPropertiesForTesting(scale_surface.get(),
6243 scale_small_matrix,
[email protected]fb661802013-03-25 01:59:326244 gfx::PointF(),
6245 gfx::PointF(2.f, 2.f),
6246 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576247 false,
[email protected]fb661802013-03-25 01:59:326248 true);
[email protected]1b30e8e2012-12-21 02:59:096249
[email protected]fb661802013-03-25 01:59:326250 perspective_surface->SetForceRenderSurface(true);
6251 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:096252
[email protected]fb661802013-03-25 01:59:326253 parent->AddChild(perspective_surface);
6254 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:326255 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:096256
[email protected]d600df7d2013-08-03 02:34:286257 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6258 host->SetRootLayer(root);
6259
[email protected]fb661802013-03-25 01:59:326260 float device_scale_factor = 2.5f;
6261 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:096262
[email protected]7aad55f2013-07-26 11:25:536263 RenderSurfaceLayerList render_surface_layer_list;
6264 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6265 root.get(), parent->bounds(), &render_surface_layer_list);
6266 inputs.device_scale_factor = device_scale_factor;
6267 inputs.page_scale_factor = page_scale_factor;
6268 inputs.page_scale_application_layer = root;
6269 inputs.can_adjust_raster_scales = true;
6270 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:096271
[email protected]fb661802013-03-25 01:59:326272 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6273 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6274 perspective_surface);
6275 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6276 scale_surface);
[email protected]1b30e8e2012-12-21 02:59:096277
[email protected]fb661802013-03-25 01:59:326278 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:096279
[email protected]fb661802013-03-25 01:59:326280 gfx::Transform expected_parent_draw_transform;
6281 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
6282 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096283
[email protected]fb661802013-03-25 01:59:326284 // The scaled surface is rendered at its appropriate scale, and drawn 1:1
6285 // into its target.
6286 gfx::Transform expected_scale_surface_draw_transform;
6287 expected_scale_surface_draw_transform.Translate(
6288 device_scale_factor * page_scale_factor * scale_surface->position().x(),
6289 device_scale_factor * page_scale_factor * scale_surface->position().y());
[email protected]fb661802013-03-25 01:59:326290 EXPECT_TRANSFORMATION_MATRIX_EQ(
6291 expected_scale_surface_draw_transform,
6292 scale_surface->render_surface()->draw_transform());
[email protected]a52c6ff2013-05-04 05:33:156293 gfx::Transform expected_scale_surface_layer_draw_transform =
6294 scale_small_matrix;
[email protected]fb661802013-03-25 01:59:326295 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform,
6296 scale_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096297
[email protected]fb661802013-03-25 01:59:326298 // The scale for the perspective surface is not known, so it is rendered 1:1
6299 // with the screen, and then scaled during drawing.
6300 gfx::Transform expected_perspective_surface_draw_transform;
6301 expected_perspective_surface_draw_transform.Translate(
6302 device_scale_factor * page_scale_factor *
6303 perspective_surface->position().x(),
6304 device_scale_factor * page_scale_factor *
6305 perspective_surface->position().y());
6306 expected_perspective_surface_draw_transform.PreconcatTransform(
6307 perspective_matrix);
6308 expected_perspective_surface_draw_transform.PreconcatTransform(
6309 scale_small_matrix);
6310 gfx::Transform expected_perspective_surface_layer_draw_transform;
6311 EXPECT_TRANSFORMATION_MATRIX_EQ(
6312 expected_perspective_surface_draw_transform,
6313 perspective_surface->render_surface()->draw_transform());
6314 EXPECT_TRANSFORMATION_MATRIX_EQ(
6315 expected_perspective_surface_layer_draw_transform,
6316 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096317}
6318
[email protected]989386c2013-07-18 21:37:236319TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:326320 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
6321 // Verify draw and screen space transforms of layers not in a surface.
6322 MockContentLayerClient delegate;
6323 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:476324
[email protected]fb661802013-03-25 01:59:326325 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6326 SetLayerPropertiesForTesting(parent.get(),
6327 identity_matrix,
[email protected]fb661802013-03-25 01:59:326328 gfx::PointF(),
6329 gfx::PointF(),
6330 gfx::Size(133, 133),
[email protected]56fffdd2014-02-11 19:50:576331 false,
[email protected]fb661802013-03-25 01:59:326332 true);
[email protected]904e9132012-11-01 00:12:476333
[email protected]fb661802013-03-25 01:59:326334 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6335 SetLayerPropertiesForTesting(child.get(),
6336 identity_matrix,
[email protected]fb661802013-03-25 01:59:326337 gfx::PointF(),
6338 gfx::PointF(),
6339 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:576340 false,
[email protected]fb661802013-03-25 01:59:326341 true);
[email protected]904e9132012-11-01 00:12:476342
[email protected]fb661802013-03-25 01:59:326343 scoped_refptr<NoScaleContentLayer> child_no_scale =
6344 CreateNoScaleDrawableContentLayer(&delegate);
6345 SetLayerPropertiesForTesting(child_no_scale.get(),
6346 identity_matrix,
[email protected]fb661802013-03-25 01:59:326347 gfx::PointF(),
6348 gfx::PointF(),
6349 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:576350 false,
[email protected]fb661802013-03-25 01:59:326351 true);
[email protected]904e9132012-11-01 00:12:476352
[email protected]fb661802013-03-25 01:59:326353 parent->AddChild(child);
6354 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:476355
[email protected]d600df7d2013-08-03 02:34:286356 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6357 host->SetRootLayer(parent);
6358
[email protected]fb661802013-03-25 01:59:326359 float device_scale_factor = 1.7f;
6360 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:476361
[email protected]7aad55f2013-07-26 11:25:536362 RenderSurfaceLayerList render_surface_layer_list;
6363 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6364 parent.get(), parent->bounds(), &render_surface_layer_list);
6365 inputs.device_scale_factor = device_scale_factor;
6366 inputs.page_scale_factor = page_scale_factor;
6367 inputs.page_scale_application_layer = parent.get();
6368 inputs.can_adjust_raster_scales = true;
6369 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:476370
[email protected]fb661802013-03-25 01:59:326371 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6372 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6373 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:476374
[email protected]fb661802013-03-25 01:59:326375 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:476376
[email protected]fb661802013-03-25 01:59:326377 // Verify parent transforms
6378 gfx::Transform expected_parent_transform;
6379 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6380 parent->screen_space_transform());
6381 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6382 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:476383
[email protected]fb661802013-03-25 01:59:326384 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056385 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:476386
[email protected]fb661802013-03-25 01:59:326387 gfx::RectF parent_draw_rect =
6388 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6389 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6390 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:476391
[email protected]2c7c6702013-03-26 03:14:056392 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326393 expected_parent_draw_rect.Scale(device_scale_factor);
6394 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
6395 expected_parent_draw_rect.set_height(
6396 ceil(expected_parent_draw_rect.height()));
6397 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6398 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476399
[email protected]fb661802013-03-25 01:59:326400 // Verify child transforms
6401 gfx::Transform expected_child_transform;
6402 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6403 child->draw_transform());
6404 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6405 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476406
[email protected]fb661802013-03-25 01:59:326407 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:056408 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:476409
[email protected]fb661802013-03-25 01:59:326410 gfx::RectF child_draw_rect =
6411 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6412 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6413 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:476414
[email protected]2c7c6702013-03-26 03:14:056415 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:326416 expected_child_draw_rect.Scale(device_scale_factor);
6417 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
6418 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
6419 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6420 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476421
[email protected]fb661802013-03-25 01:59:326422 // Verify child_no_scale transforms
6423 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6424 // All transforms operate on content rects. The child's content rect
6425 // incorporates device scale, but the child_no_scale does not; add it here.
6426 expected_child_no_scale_transform.Scale(device_scale_factor,
6427 device_scale_factor);
6428 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6429 child_no_scale->draw_transform());
6430 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6431 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476432}
6433
[email protected]989386c2013-07-18 21:37:236434TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:326435 MockContentLayerClient delegate;
6436 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446437
[email protected]fb661802013-03-25 01:59:326438 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266439 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326440 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446441
[email protected]fb661802013-03-25 01:59:326442 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266443 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326444 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446445
[email protected]35a99a12013-05-09 23:52:296446 scoped_refptr<Layer> root = Layer::Create();
6447 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446448
[email protected]fb661802013-03-25 01:59:326449 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6450 SetLayerPropertiesForTesting(parent.get(),
6451 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326452 gfx::PointF(),
6453 gfx::PointF(),
6454 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576455 false,
[email protected]fb661802013-03-25 01:59:326456 true);
[email protected]518ee582012-10-24 18:29:446457
[email protected]fb661802013-03-25 01:59:326458 scoped_refptr<ContentLayer> child_scale =
6459 CreateDrawableContentLayer(&delegate);
6460 SetLayerPropertiesForTesting(child_scale.get(),
6461 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326462 gfx::PointF(),
6463 gfx::PointF(2.f, 2.f),
6464 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576465 false,
[email protected]fb661802013-03-25 01:59:326466 true);
[email protected]518ee582012-10-24 18:29:446467
[email protected]fb661802013-03-25 01:59:326468 scoped_refptr<ContentLayer> child_empty =
6469 CreateDrawableContentLayer(&delegate);
6470 SetLayerPropertiesForTesting(child_empty.get(),
6471 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326472 gfx::PointF(),
6473 gfx::PointF(2.f, 2.f),
6474 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576475 false,
[email protected]fb661802013-03-25 01:59:326476 true);
[email protected]f89f5632012-11-14 23:34:456477
[email protected]fb661802013-03-25 01:59:326478 scoped_refptr<NoScaleContentLayer> child_no_scale =
6479 CreateNoScaleDrawableContentLayer(&delegate);
6480 SetLayerPropertiesForTesting(child_no_scale.get(),
6481 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326482 gfx::PointF(),
6483 gfx::PointF(12.f, 12.f),
6484 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576485 false,
[email protected]fb661802013-03-25 01:59:326486 true);
[email protected]518ee582012-10-24 18:29:446487
[email protected]35a99a12013-05-09 23:52:296488 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446489
[email protected]fb661802013-03-25 01:59:326490 parent->AddChild(child_scale);
6491 parent->AddChild(child_empty);
6492 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:446493
[email protected]d600df7d2013-08-03 02:34:286494 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6495 host->SetRootLayer(root);
6496
[email protected]fb661802013-03-25 01:59:326497 float device_scale_factor = 2.5f;
6498 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:446499
[email protected]989386c2013-07-18 21:37:236500 {
6501 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536502 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6503 root.get(), root->bounds(), &render_surface_layer_list);
6504 inputs.device_scale_factor = device_scale_factor;
6505 inputs.page_scale_factor = page_scale_factor;
6506 inputs.page_scale_application_layer = root.get();
6507 inputs.can_adjust_raster_scales = true;
6508 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446509
[email protected]989386c2013-07-18 21:37:236510 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6511 initial_parent_scale, parent);
6512 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6513 initial_parent_scale * initial_child_scale,
6514 child_scale);
6515 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6516 initial_parent_scale * initial_child_scale,
6517 child_empty);
6518 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:446519
[email protected]989386c2013-07-18 21:37:236520 // The parent is scaled up and shouldn't need to scale during draw. The
6521 // child that can scale its contents should also not need to scale during
6522 // draw. This shouldn't change if the child has empty bounds. The other
6523 // children should.
[email protected]803f6b52013-09-12 00:51:266524 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
6525 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
6526 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
6527 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
6528 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
6529 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236530 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6531 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266532 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:236533 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266534 initial_parent_scale * initial_child_scale,
6535 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236536 }
[email protected]518ee582012-10-24 18:29:446537
[email protected]fb661802013-03-25 01:59:326538 // If the device_scale_factor or page_scale_factor changes, then it should be
6539 // updated using the initial transform as the raster scale.
6540 device_scale_factor = 2.25f;
6541 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:446542
[email protected]989386c2013-07-18 21:37:236543 {
6544 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536545 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6546 root.get(), root->bounds(), &render_surface_layer_list);
6547 inputs.device_scale_factor = device_scale_factor;
6548 inputs.page_scale_factor = page_scale_factor;
6549 inputs.page_scale_application_layer = root.get();
6550 inputs.can_adjust_raster_scales = true;
6551 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6552
6553 EXPECT_CONTENTS_SCALE_EQ(
6554 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:236555 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536556 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:236557 child_scale);
6558 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6559 initial_parent_scale * initial_child_scale,
6560 child_empty);
6561 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6562 }
[email protected]d0518202013-02-08 02:06:496563
[email protected]fb661802013-03-25 01:59:326564 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:266565 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326566 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
6567 second_child_scale / initial_child_scale);
6568 child_scale->SetTransform(child_scale_matrix);
6569 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:496570
[email protected]989386c2013-07-18 21:37:236571 {
6572 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536573 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6574 root.get(), root->bounds(), &render_surface_layer_list);
6575 inputs.device_scale_factor = device_scale_factor;
6576 inputs.page_scale_factor = page_scale_factor;
6577 inputs.page_scale_application_layer = root.get();
6578 inputs.can_adjust_raster_scales = true;
6579 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496580
[email protected]989386c2013-07-18 21:37:236581 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6582 initial_parent_scale,
6583 parent);
6584 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6585 child_scale);
6586 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6587 child_empty);
6588 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6589 }
[email protected]d0518202013-02-08 02:06:496590
[email protected]fb661802013-03-25 01:59:326591 // If the device_scale_factor or page_scale_factor changes, then it should be
6592 // updated, but still using 1.0 as the raster scale.
6593 device_scale_factor = 2.75f;
6594 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:496595
[email protected]989386c2013-07-18 21:37:236596 {
6597 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536598 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6599 root.get(), root->bounds(), &render_surface_layer_list);
6600 inputs.device_scale_factor = device_scale_factor;
6601 inputs.page_scale_factor = page_scale_factor;
6602 inputs.page_scale_application_layer = root.get();
6603 inputs.can_adjust_raster_scales = true;
6604 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496605
[email protected]989386c2013-07-18 21:37:236606 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6607 initial_parent_scale,
6608 parent);
6609 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6610 child_scale);
6611 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6612 child_empty);
6613 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6614 }
[email protected]518ee582012-10-24 18:29:446615}
6616
[email protected]989386c2013-07-18 21:37:236617TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:296618 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:326619 MockContentLayerClient delegate;
6620 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:216621
[email protected]fb661802013-03-25 01:59:326622 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266623 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326624 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:216625
[email protected]fb661802013-03-25 01:59:326626 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266627 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326628 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:216629
[email protected]35a99a12013-05-09 23:52:296630 scoped_refptr<Layer> root = Layer::Create();
6631 root->SetBounds(gfx::Size(100, 100));
6632
[email protected]fb661802013-03-25 01:59:326633 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6634 SetLayerPropertiesForTesting(parent.get(),
6635 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326636 gfx::PointF(),
6637 gfx::PointF(),
6638 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576639 false,
[email protected]fb661802013-03-25 01:59:326640 true);
[email protected]11ec92972012-11-10 03:06:216641
[email protected]fb661802013-03-25 01:59:326642 scoped_refptr<ContentLayer> child_scale =
6643 CreateDrawableContentLayer(&delegate);
6644 SetLayerPropertiesForTesting(child_scale.get(),
6645 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326646 gfx::PointF(),
6647 gfx::PointF(2.f, 2.f),
6648 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576649 false,
[email protected]fb661802013-03-25 01:59:326650 true);
[email protected]11ec92972012-11-10 03:06:216651
[email protected]35a99a12013-05-09 23:52:296652 scoped_refptr<ContentLayer> child_empty =
6653 CreateDrawableContentLayer(&delegate);
6654 SetLayerPropertiesForTesting(child_empty.get(),
6655 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296656 gfx::PointF(),
6657 gfx::PointF(2.f, 2.f),
6658 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576659 false,
[email protected]35a99a12013-05-09 23:52:296660 true);
6661
6662 scoped_refptr<NoScaleContentLayer> child_no_scale =
6663 CreateNoScaleDrawableContentLayer(&delegate);
6664 SetLayerPropertiesForTesting(child_no_scale.get(),
6665 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296666 gfx::PointF(),
6667 gfx::PointF(12.f, 12.f),
6668 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576669 false,
[email protected]35a99a12013-05-09 23:52:296670 true);
6671
6672 root->AddChild(parent);
6673
6674 parent->AddChild(child_scale);
6675 parent->AddChild(child_empty);
6676 parent->AddChild(child_no_scale);
6677
[email protected]d600df7d2013-08-03 02:34:286678 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6679 host->SetRootLayer(root);
6680
[email protected]989386c2013-07-18 21:37:236681 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:296682
6683 float device_scale_factor = 2.5f;
6684 float page_scale_factor = 1.f;
6685
[email protected]7aad55f2013-07-26 11:25:536686 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6687 root.get(), root->bounds(), &render_surface_layer_list);
6688 inputs.device_scale_factor = device_scale_factor;
6689 inputs.page_scale_factor = page_scale_factor;
6690 inputs.page_scale_application_layer = root.get(),
6691 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:296692
6693 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6694 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6695 child_scale);
6696 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6697 child_empty);
6698 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6699
6700 // Since the transform scale does not affect contents scale, it should affect
6701 // the draw transform instead.
6702 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266703 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296704 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266705 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296706 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266707 child_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296708 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266709 child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296710 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266711 child_empty->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296712 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266713 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296714 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266715 initial_parent_scale * initial_child_scale,
6716 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296717 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266718 initial_parent_scale * initial_child_scale,
6719 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296720}
6721
[email protected]989386c2013-07-18 21:37:236722TEST_F(LayerTreeHostCommonTest, SmallContentsScale) {
[email protected]35a99a12013-05-09 23:52:296723 MockContentLayerClient delegate;
6724 gfx::Transform identity_matrix;
6725
6726 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266727 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:296728 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6729
6730 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266731 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:296732 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6733
6734 scoped_refptr<Layer> root = Layer::Create();
6735 root->SetBounds(gfx::Size(100, 100));
6736
6737 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6738 SetLayerPropertiesForTesting(parent.get(),
6739 parent_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296740 gfx::PointF(),
6741 gfx::PointF(),
6742 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576743 false,
[email protected]35a99a12013-05-09 23:52:296744 true);
6745
6746 scoped_refptr<ContentLayer> child_scale =
6747 CreateDrawableContentLayer(&delegate);
6748 SetLayerPropertiesForTesting(child_scale.get(),
6749 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296750 gfx::PointF(),
6751 gfx::PointF(2.f, 2.f),
6752 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576753 false,
[email protected]35a99a12013-05-09 23:52:296754 true);
6755
6756 root->AddChild(parent);
6757
[email protected]fb661802013-03-25 01:59:326758 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:216759
[email protected]d600df7d2013-08-03 02:34:286760 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6761 host->SetRootLayer(root);
6762
[email protected]fb661802013-03-25 01:59:326763 float device_scale_factor = 2.5f;
6764 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:216765
[email protected]989386c2013-07-18 21:37:236766 {
6767 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536768 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6769 root.get(), root->bounds(), &render_surface_layer_list);
6770 inputs.device_scale_factor = device_scale_factor;
6771 inputs.page_scale_factor = page_scale_factor;
6772 inputs.page_scale_application_layer = root.get();
6773 inputs.can_adjust_raster_scales = true;
6774 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216775
[email protected]989386c2013-07-18 21:37:236776 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6777 initial_parent_scale,
6778 parent);
6779 // The child's scale is < 1, so we should not save and use that scale
6780 // factor.
6781 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1,
6782 child_scale);
6783 }
[email protected]11ec92972012-11-10 03:06:216784
[email protected]fb661802013-03-25 01:59:326785 // When chilld's total scale becomes >= 1, we should save and use that scale
6786 // factor.
6787 child_scale_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:266788 SkMScalar final_child_scale = 0.75;
[email protected]fb661802013-03-25 01:59:326789 child_scale_matrix.Scale(final_child_scale, final_child_scale);
6790 child_scale->SetTransform(child_scale_matrix);
[email protected]11ec92972012-11-10 03:06:216791
[email protected]989386c2013-07-18 21:37:236792 {
6793 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536794 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6795 root.get(), root->bounds(), &render_surface_layer_list);
6796 inputs.device_scale_factor = device_scale_factor;
6797 inputs.page_scale_factor = page_scale_factor;
6798 inputs.page_scale_application_layer = root.get();
6799 inputs.can_adjust_raster_scales = true;
6800 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216801
[email protected]989386c2013-07-18 21:37:236802 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6803 initial_parent_scale,
6804 parent);
6805 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6806 initial_parent_scale * final_child_scale,
6807 child_scale);
6808 }
[email protected]11ec92972012-11-10 03:06:216809}
6810
[email protected]989386c2013-07-18 21:37:236811TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:326812 MockContentLayerClient delegate;
6813 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446814
[email protected]fb661802013-03-25 01:59:326815 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266816 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:326817 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446818
[email protected]fb661802013-03-25 01:59:326819 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266820 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:326821 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446822
[email protected]35a99a12013-05-09 23:52:296823 scoped_refptr<Layer> root = Layer::Create();
6824 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446825
[email protected]fb661802013-03-25 01:59:326826 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6827 SetLayerPropertiesForTesting(parent.get(),
6828 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326829 gfx::PointF(),
6830 gfx::PointF(),
6831 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576832 false,
[email protected]fb661802013-03-25 01:59:326833 true);
[email protected]518ee582012-10-24 18:29:446834
[email protected]fb661802013-03-25 01:59:326835 scoped_refptr<ContentLayer> surface_scale =
6836 CreateDrawableContentLayer(&delegate);
6837 SetLayerPropertiesForTesting(surface_scale.get(),
6838 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326839 gfx::PointF(),
6840 gfx::PointF(2.f, 2.f),
6841 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576842 false,
[email protected]fb661802013-03-25 01:59:326843 true);
[email protected]518ee582012-10-24 18:29:446844
[email protected]fb661802013-03-25 01:59:326845 scoped_refptr<ContentLayer> surface_scale_child_scale =
6846 CreateDrawableContentLayer(&delegate);
6847 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
6848 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326849 gfx::PointF(),
6850 gfx::PointF(),
6851 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576852 false,
[email protected]fb661802013-03-25 01:59:326853 true);
[email protected]518ee582012-10-24 18:29:446854
[email protected]fb661802013-03-25 01:59:326855 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
6856 CreateNoScaleDrawableContentLayer(&delegate);
6857 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
6858 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326859 gfx::PointF(),
6860 gfx::PointF(),
6861 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576862 false,
[email protected]fb661802013-03-25 01:59:326863 true);
[email protected]518ee582012-10-24 18:29:446864
[email protected]fb661802013-03-25 01:59:326865 scoped_refptr<NoScaleContentLayer> surface_no_scale =
6866 CreateNoScaleDrawableContentLayer(&delegate);
6867 SetLayerPropertiesForTesting(surface_no_scale.get(),
6868 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326869 gfx::PointF(),
6870 gfx::PointF(12.f, 12.f),
6871 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576872 false,
[email protected]fb661802013-03-25 01:59:326873 true);
[email protected]518ee582012-10-24 18:29:446874
[email protected]fb661802013-03-25 01:59:326875 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
6876 CreateDrawableContentLayer(&delegate);
6877 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
6878 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326879 gfx::PointF(),
6880 gfx::PointF(),
6881 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576882 false,
[email protected]fb661802013-03-25 01:59:326883 true);
[email protected]518ee582012-10-24 18:29:446884
[email protected]fb661802013-03-25 01:59:326885 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
6886 CreateNoScaleDrawableContentLayer(&delegate);
6887 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
6888 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326889 gfx::PointF(),
6890 gfx::PointF(),
6891 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576892 false,
[email protected]fb661802013-03-25 01:59:326893 true);
[email protected]518ee582012-10-24 18:29:446894
[email protected]35a99a12013-05-09 23:52:296895 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446896
[email protected]fb661802013-03-25 01:59:326897 parent->AddChild(surface_scale);
6898 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:446899
[email protected]fb661802013-03-25 01:59:326900 surface_scale->SetForceRenderSurface(true);
6901 surface_scale->AddChild(surface_scale_child_scale);
6902 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446903
[email protected]fb661802013-03-25 01:59:326904 surface_no_scale->SetForceRenderSurface(true);
6905 surface_no_scale->AddChild(surface_no_scale_child_scale);
6906 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446907
[email protected]d600df7d2013-08-03 02:34:286908 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6909 host->SetRootLayer(root);
6910
[email protected]803f6b52013-09-12 00:51:266911 SkMScalar device_scale_factor = 5;
6912 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:446913
[email protected]7aad55f2013-07-26 11:25:536914 RenderSurfaceLayerList render_surface_layer_list;
6915 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6916 root.get(), root->bounds(), &render_surface_layer_list);
6917 inputs.device_scale_factor = device_scale_factor;
6918 inputs.page_scale_factor = page_scale_factor;
6919 inputs.page_scale_application_layer = root.get();
6920 inputs.can_adjust_raster_scales = true;
6921 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6922
6923 EXPECT_CONTENTS_SCALE_EQ(
6924 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:196925 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536926 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:326927 surface_scale);
6928 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
6929 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:326930 device_scale_factor * page_scale_factor * initial_parent_scale *
6931 initial_child_scale * initial_child_scale,
6932 surface_scale_child_scale);
6933 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
6934 EXPECT_CONTENTS_SCALE_EQ(
6935 device_scale_factor * page_scale_factor * initial_parent_scale *
6936 initial_child_scale * initial_child_scale,
6937 surface_no_scale_child_scale);
6938 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446939
[email protected]fb661802013-03-25 01:59:326940 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:266941 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
6942 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446943
[email protected]fb661802013-03-25 01:59:326944 // RenderSurfaces should always be 1:1 with their target.
6945 EXPECT_FLOAT_EQ(
6946 1.0,
[email protected]803f6b52013-09-12 00:51:266947 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326948 EXPECT_FLOAT_EQ(
6949 1.0,
[email protected]803f6b52013-09-12 00:51:266950 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446951
[email protected]fb661802013-03-25 01:59:326952 // The surface_scale can apply contents scale so the layer shouldn't need to
6953 // scale during draw.
[email protected]803f6b52013-09-12 00:51:266954 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
6955 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446956
[email protected]fb661802013-03-25 01:59:326957 // The surface_scale_child_scale can apply contents scale so it shouldn't need
6958 // to scale during draw.
6959 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:266960 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326961 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:266962 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446963
[email protected]fb661802013-03-25 01:59:326964 // The surface_scale_child_no_scale can not apply contents scale, so it needs
6965 // to be scaled during draw.
6966 EXPECT_FLOAT_EQ(
6967 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:266968 initial_child_scale * initial_child_scale,
6969 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326970 EXPECT_FLOAT_EQ(
6971 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:266972 initial_child_scale * initial_child_scale,
6973 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446974
[email protected]fb661802013-03-25 01:59:326975 // RenderSurfaces should always be 1:1 with their target.
6976 EXPECT_FLOAT_EQ(
6977 1.0,
[email protected]803f6b52013-09-12 00:51:266978 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326979 EXPECT_FLOAT_EQ(
6980 1.0,
[email protected]803f6b52013-09-12 00:51:266981 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446982
[email protected]fb661802013-03-25 01:59:326983 // The surface_no_scale layer can not apply contents scale, so it needs to be
6984 // scaled during draw.
6985 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266986 initial_parent_scale * initial_child_scale,
6987 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326988 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266989 initial_parent_scale * initial_child_scale,
6990 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446991
[email protected]fb661802013-03-25 01:59:326992 // The surface_scale_child_scale can apply contents scale so it shouldn't need
6993 // to scale during draw.
6994 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:266995 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326996 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:266997 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446998
[email protected]fb661802013-03-25 01:59:326999 // The surface_scale_child_no_scale can not apply contents scale, so it needs
7000 // to be scaled during draw.
7001 EXPECT_FLOAT_EQ(
7002 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267003 initial_child_scale * initial_child_scale,
7004 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327005 EXPECT_FLOAT_EQ(
7006 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267007 initial_child_scale * initial_child_scale,
7008 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297009}
[email protected]518ee582012-10-24 18:29:447010
[email protected]989386c2013-07-18 21:37:237011TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:297012 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
7013 MockContentLayerClient delegate;
7014 gfx::Transform identity_matrix;
7015
7016 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267017 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:297018 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
7019
7020 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267021 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:297022 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
7023
7024 scoped_refptr<Layer> root = Layer::Create();
7025 root->SetBounds(gfx::Size(100, 100));
7026
7027 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7028 SetLayerPropertiesForTesting(parent.get(),
7029 parent_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297030 gfx::PointF(),
7031 gfx::PointF(),
7032 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577033 false,
[email protected]35a99a12013-05-09 23:52:297034 true);
7035
7036 scoped_refptr<ContentLayer> surface_scale =
7037 CreateDrawableContentLayer(&delegate);
7038 SetLayerPropertiesForTesting(surface_scale.get(),
7039 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297040 gfx::PointF(),
7041 gfx::PointF(2.f, 2.f),
7042 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577043 false,
[email protected]35a99a12013-05-09 23:52:297044 true);
7045
7046 scoped_refptr<ContentLayer> surface_scale_child_scale =
7047 CreateDrawableContentLayer(&delegate);
7048 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
7049 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297050 gfx::PointF(),
7051 gfx::PointF(),
7052 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577053 false,
[email protected]35a99a12013-05-09 23:52:297054 true);
7055
7056 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
7057 CreateNoScaleDrawableContentLayer(&delegate);
7058 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
7059 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297060 gfx::PointF(),
7061 gfx::PointF(),
7062 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577063 false,
[email protected]35a99a12013-05-09 23:52:297064 true);
7065
7066 scoped_refptr<NoScaleContentLayer> surface_no_scale =
7067 CreateNoScaleDrawableContentLayer(&delegate);
7068 SetLayerPropertiesForTesting(surface_no_scale.get(),
7069 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297070 gfx::PointF(),
7071 gfx::PointF(12.f, 12.f),
7072 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577073 false,
[email protected]35a99a12013-05-09 23:52:297074 true);
7075
7076 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
7077 CreateDrawableContentLayer(&delegate);
7078 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
7079 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297080 gfx::PointF(),
7081 gfx::PointF(),
7082 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577083 false,
[email protected]35a99a12013-05-09 23:52:297084 true);
7085
7086 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
7087 CreateNoScaleDrawableContentLayer(&delegate);
7088 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
7089 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297090 gfx::PointF(),
7091 gfx::PointF(),
7092 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577093 false,
[email protected]35a99a12013-05-09 23:52:297094 true);
7095
7096 root->AddChild(parent);
7097
7098 parent->AddChild(surface_scale);
7099 parent->AddChild(surface_no_scale);
7100
7101 surface_scale->SetForceRenderSurface(true);
7102 surface_scale->AddChild(surface_scale_child_scale);
7103 surface_scale->AddChild(surface_scale_child_no_scale);
7104
7105 surface_no_scale->SetForceRenderSurface(true);
7106 surface_no_scale->AddChild(surface_no_scale_child_scale);
7107 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
7108
[email protected]d600df7d2013-08-03 02:34:287109 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7110 host->SetRootLayer(root);
7111
[email protected]989386c2013-07-18 21:37:237112 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:297113
[email protected]803f6b52013-09-12 00:51:267114 SkMScalar device_scale_factor = 5.0;
7115 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:537116 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7117 root.get(), root->bounds(), &render_surface_layer_list);
7118 inputs.device_scale_factor = device_scale_factor;
7119 inputs.page_scale_factor = page_scale_factor;
7120 inputs.page_scale_application_layer = root.get();
7121 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:297122
[email protected]35a99a12013-05-09 23:52:297123 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7124 parent);
7125 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7126 surface_scale);
7127 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
7128 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7129 surface_scale_child_scale);
7130 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
7131 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7132 surface_no_scale_child_scale);
7133 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
7134
7135 // The parent is scaled up during draw, since its contents are not scaled by
7136 // the transform hierarchy.
7137 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267138 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297139 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267140 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297141
7142 // The child surface is scaled up during draw since its subtree is not scaled
7143 // by the transform hierarchy.
7144 EXPECT_FLOAT_EQ(
7145 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267146 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297147 EXPECT_FLOAT_EQ(
7148 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267149 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297150
7151 // The surface_scale's RenderSurface is scaled during draw, so the layer does
7152 // not need to be scaled when drawing into its surface.
[email protected]803f6b52013-09-12 00:51:267153 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
7154 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447155
[email protected]35a99a12013-05-09 23:52:297156 // The surface_scale_child_scale is scaled when drawing into its surface,
7157 // since its content bounds are not scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:327158 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297159 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267160 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327161 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297162 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267163 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447164
[email protected]35a99a12013-05-09 23:52:297165 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
7166 // needs to be scaled by the device and page scale factors, along with the
7167 // transform hierarchy.
[email protected]fb661802013-03-25 01:59:327168 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297169 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267170 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297171 EXPECT_FLOAT_EQ(
7172 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267173 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297174
7175 // The child surface is scaled up during draw since its subtree is not scaled
7176 // by the transform hierarchy.
7177 EXPECT_FLOAT_EQ(
7178 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267179 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327180 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297181 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267182 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447183
[email protected]35a99a12013-05-09 23:52:297184 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
7185 // be scaled by the device and page scale factors. Its surface is already
7186 // scaled by the transform hierarchy so those don't need to scale the layer's
7187 // drawing.
7188 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267189 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297190 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267191 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297192
7193 // The surface_no_scale_child_scale has its contents scaled by the page and
7194 // device scale factors, but needs to be scaled by the transform hierarchy
7195 // when drawing.
[email protected]fb661802013-03-25 01:59:327196 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297197 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267198 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327199 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297200 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267201 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297202
7203 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
7204 // needs to be scaled by the device and page scale factors. It also needs to
7205 // be scaled by any transform heirarchy below its target surface.
7206 EXPECT_FLOAT_EQ(
7207 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267208 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297209 EXPECT_FLOAT_EQ(
7210 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267211 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447212}
7213
[email protected]989386c2013-07-18 21:37:237214TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:327215 MockContentLayerClient delegate;
7216 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267217
[email protected]fb661802013-03-25 01:59:327218 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267219 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:327220 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:267221
[email protected]fb661802013-03-25 01:59:327222 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267223 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:327224 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:267225
[email protected]35a99a12013-05-09 23:52:297226 scoped_refptr<Layer> root = Layer::Create();
7227 root->SetBounds(gfx::Size(100, 100));
7228
[email protected]fb661802013-03-25 01:59:327229 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7230 SetLayerPropertiesForTesting(parent.get(),
7231 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:327232 gfx::PointF(),
7233 gfx::PointF(),
7234 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577235 false,
[email protected]fb661802013-03-25 01:59:327236 true);
[email protected]6a9cff92012-11-08 11:53:267237
[email protected]fb661802013-03-25 01:59:327238 scoped_refptr<ContentLayer> child_scale =
7239 CreateDrawableContentLayer(&delegate);
7240 SetLayerPropertiesForTesting(child_scale.get(),
7241 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:327242 gfx::PointF(),
7243 gfx::PointF(2.f, 2.f),
7244 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577245 false,
[email protected]fb661802013-03-25 01:59:327246 true);
[email protected]6a9cff92012-11-08 11:53:267247
[email protected]35a99a12013-05-09 23:52:297248 root->AddChild(parent);
7249
[email protected]fb661802013-03-25 01:59:327250 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:267251
[email protected]d600df7d2013-08-03 02:34:287252 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7253 host->SetRootLayer(root);
7254
[email protected]fb661802013-03-25 01:59:327255 // Now put an animating transform on child.
7256 int animation_id = AddAnimatedTransformToController(
7257 child_scale->layer_animation_controller(), 10.0, 30, 0);
[email protected]6a9cff92012-11-08 11:53:267258
[email protected]989386c2013-07-18 21:37:237259 {
7260 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537261 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7262 root.get(), root->bounds(), &render_surface_layer_list);
7263 inputs.can_adjust_raster_scales = true;
7264 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267265
[email protected]989386c2013-07-18 21:37:237266 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7267 // The layers with animating transforms should not compute a contents scale
7268 // other than 1 until they finish animating.
7269 EXPECT_CONTENTS_SCALE_EQ(1, child_scale);
7270 }
[email protected]6a9cff92012-11-08 11:53:267271
[email protected]fb661802013-03-25 01:59:327272 // Remove the animation, now it can save a raster scale.
7273 child_scale->layer_animation_controller()->RemoveAnimation(animation_id);
[email protected]6a9cff92012-11-08 11:53:267274
[email protected]989386c2013-07-18 21:37:237275 {
7276 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537277 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7278 root.get(), root->bounds(), &render_surface_layer_list);
7279 inputs.can_adjust_raster_scales = true;
7280 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267281
[email protected]989386c2013-07-18 21:37:237282 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7283 // The layers with animating transforms should not compute a contents scale
7284 // other than 1 until they finish animating.
7285 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale,
7286 child_scale);
7287 }
[email protected]6a9cff92012-11-08 11:53:267288}
7289
[email protected]7a5a9322014-02-25 12:54:577290TEST_F(LayerTreeHostCommonTest,
7291 ChangeInContentBoundsOrScaleTriggersPushProperties) {
7292 MockContentLayerClient delegate;
7293 scoped_refptr<Layer> root = Layer::Create();
7294 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate);
7295 root->AddChild(child);
7296
7297 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7298 host->SetRootLayer(root);
7299
7300 gfx::Transform identity_matrix;
7301 SetLayerPropertiesForTesting(root.get(),
7302 identity_matrix,
7303 gfx::PointF(),
7304 gfx::PointF(),
7305 gfx::Size(100, 100),
7306 true,
7307 false);
7308 SetLayerPropertiesForTesting(child.get(),
7309 identity_matrix,
7310 gfx::PointF(),
7311 gfx::PointF(),
7312 gfx::Size(100, 100),
7313 true,
7314 false);
7315
7316 root->reset_needs_push_properties_for_testing();
7317 child->reset_needs_push_properties_for_testing();
7318
7319 // This will change both layers' content bounds.
7320 ExecuteCalculateDrawProperties(root.get());
7321 EXPECT_TRUE(root->needs_push_properties());
7322 EXPECT_TRUE(child->needs_push_properties());
7323
7324 root->reset_needs_push_properties_for_testing();
7325 child->reset_needs_push_properties_for_testing();
7326
7327 // This will change only the child layer's contents scale and content bounds,
7328 // since the root layer is not a ContentsScalingLayer.
7329 ExecuteCalculateDrawProperties(root.get(), 2.f);
7330 EXPECT_FALSE(root->needs_push_properties());
7331 EXPECT_TRUE(child->needs_push_properties());
7332
7333 root->reset_needs_push_properties_for_testing();
7334 child->reset_needs_push_properties_for_testing();
7335
7336 // This will not change either layer's contents scale or content bounds.
7337 ExecuteCalculateDrawProperties(root.get(), 2.f);
7338 EXPECT_FALSE(root->needs_push_properties());
7339 EXPECT_FALSE(child->needs_push_properties());
7340}
7341
[email protected]989386c2013-07-18 21:37:237342TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:327343 MockContentLayerClient delegate;
7344 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267345
[email protected]fb661802013-03-25 01:59:327346 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7347 SetLayerPropertiesForTesting(parent.get(),
7348 identity_matrix,
[email protected]fb661802013-03-25 01:59:327349 gfx::PointF(),
7350 gfx::PointF(),
7351 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577352 false,
[email protected]fb661802013-03-25 01:59:327353 true);
[email protected]94f206c12012-08-25 00:09:147354
[email protected]fb661802013-03-25 01:59:327355 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7356 SetLayerPropertiesForTesting(child.get(),
7357 identity_matrix,
[email protected]fb661802013-03-25 01:59:327358 gfx::PointF(),
7359 gfx::PointF(2.f, 2.f),
7360 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577361 false,
[email protected]fb661802013-03-25 01:59:327362 true);
[email protected]94f206c12012-08-25 00:09:147363
[email protected]fb661802013-03-25 01:59:327364 gfx::Transform replica_transform;
7365 replica_transform.Scale(1.0, -1.0);
7366 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7367 SetLayerPropertiesForTesting(replica.get(),
7368 replica_transform,
[email protected]fb661802013-03-25 01:59:327369 gfx::PointF(),
7370 gfx::PointF(2.f, 2.f),
7371 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577372 false,
[email protected]fb661802013-03-25 01:59:327373 true);
[email protected]94f206c12012-08-25 00:09:147374
[email protected]fb661802013-03-25 01:59:327375 // This layer should end up in the same surface as child, with the same draw
7376 // and screen space transforms.
7377 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7378 CreateDrawableContentLayer(&delegate);
7379 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7380 identity_matrix,
[email protected]fb661802013-03-25 01:59:327381 gfx::PointF(),
7382 gfx::PointF(),
7383 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577384 false,
[email protected]fb661802013-03-25 01:59:327385 true);
[email protected]94f206c12012-08-25 00:09:147386
[email protected]fb661802013-03-25 01:59:327387 parent->AddChild(child);
7388 child->AddChild(duplicate_child_non_owner);
7389 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:147390
[email protected]d600df7d2013-08-03 02:34:287391 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7392 host->SetRootLayer(parent);
7393
[email protected]989386c2013-07-18 21:37:237394 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:147395
[email protected]fb661802013-03-25 01:59:327396 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:537397 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7398 parent.get(), parent->bounds(), &render_surface_layer_list);
7399 inputs.device_scale_factor = device_scale_factor;
7400 inputs.can_adjust_raster_scales = true;
7401 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:147402
[email protected]fb661802013-03-25 01:59:327403 // We should have two render surfaces. The root's render surface and child's
7404 // render surface (it needs one because it has a replica layer).
7405 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:147406
[email protected]fb661802013-03-25 01:59:327407 gfx::Transform expected_parent_transform;
7408 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7409 parent->screen_space_transform());
7410 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7411 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:147412
[email protected]fb661802013-03-25 01:59:327413 gfx::Transform expected_draw_transform;
7414 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
7415 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:147416
[email protected]fb661802013-03-25 01:59:327417 gfx::Transform expected_screen_space_transform;
7418 expected_screen_space_transform.Translate(
7419 device_scale_factor * child->position().x(),
7420 device_scale_factor * child->position().y());
7421 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
7422 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147423
[email protected]fb661802013-03-25 01:59:327424 gfx::Transform expected_duplicate_child_draw_transform =
7425 child->draw_transform();
7426 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
7427 duplicate_child_non_owner->draw_transform());
7428 EXPECT_TRANSFORMATION_MATRIX_EQ(
7429 child->screen_space_transform(),
7430 duplicate_child_non_owner->screen_space_transform());
7431 EXPECT_RECT_EQ(child->drawable_content_rect(),
7432 duplicate_child_non_owner->drawable_content_rect());
7433 EXPECT_EQ(child->content_bounds(),
7434 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:147435
[email protected]fb661802013-03-25 01:59:327436 gfx::Transform expected_render_surface_draw_transform;
7437 expected_render_surface_draw_transform.Translate(
7438 device_scale_factor * child->position().x(),
7439 device_scale_factor * child->position().y());
7440 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
7441 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147442
[email protected]fb661802013-03-25 01:59:327443 gfx::Transform expected_surface_draw_transform;
7444 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
7445 device_scale_factor * 2.f);
7446 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
7447 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147448
[email protected]fb661802013-03-25 01:59:327449 gfx::Transform expected_surface_screen_space_transform;
7450 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
7451 device_scale_factor * 2.f);
7452 EXPECT_TRANSFORMATION_MATRIX_EQ(
7453 expected_surface_screen_space_transform,
7454 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147455
[email protected]fb661802013-03-25 01:59:327456 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267457 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
7458 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
7459 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327460 EXPECT_TRANSFORMATION_MATRIX_EQ(
7461 expected_replica_draw_transform,
7462 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:147463
[email protected]fb661802013-03-25 01:59:327464 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267465 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
7466 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
7467 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327468 EXPECT_TRANSFORMATION_MATRIX_EQ(
7469 expected_replica_screen_space_transform,
7470 child->render_surface()->replica_screen_space_transform());
7471 EXPECT_TRANSFORMATION_MATRIX_EQ(
7472 expected_replica_screen_space_transform,
7473 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:477474}
7475
[email protected]989386c2013-07-18 21:37:237476TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:327477 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
7478 MockContentLayerClient delegate;
7479 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:477480
[email protected]fb661802013-03-25 01:59:327481 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7482 SetLayerPropertiesForTesting(parent.get(),
7483 identity_matrix,
[email protected]fb661802013-03-25 01:59:327484 gfx::PointF(),
7485 gfx::PointF(),
7486 gfx::Size(33, 31),
[email protected]56fffdd2014-02-11 19:50:577487 false,
[email protected]fb661802013-03-25 01:59:327488 true);
[email protected]904e9132012-11-01 00:12:477489
[email protected]fb661802013-03-25 01:59:327490 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7491 SetLayerPropertiesForTesting(child.get(),
7492 identity_matrix,
[email protected]fb661802013-03-25 01:59:327493 gfx::PointF(),
7494 gfx::PointF(),
7495 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577496 false,
[email protected]fb661802013-03-25 01:59:327497 true);
[email protected]904e9132012-11-01 00:12:477498
[email protected]fb661802013-03-25 01:59:327499 gfx::Transform replica_transform;
7500 replica_transform.Scale(1.0, -1.0);
7501 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7502 SetLayerPropertiesForTesting(replica.get(),
7503 replica_transform,
[email protected]fb661802013-03-25 01:59:327504 gfx::PointF(),
7505 gfx::PointF(),
7506 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577507 false,
[email protected]fb661802013-03-25 01:59:327508 true);
[email protected]904e9132012-11-01 00:12:477509
[email protected]fb661802013-03-25 01:59:327510 // This layer should end up in the same surface as child, with the same draw
7511 // and screen space transforms.
7512 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7513 CreateDrawableContentLayer(&delegate);
7514 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7515 identity_matrix,
[email protected]fb661802013-03-25 01:59:327516 gfx::PointF(),
7517 gfx::PointF(),
7518 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577519 false,
[email protected]fb661802013-03-25 01:59:327520 true);
[email protected]904e9132012-11-01 00:12:477521
[email protected]fb661802013-03-25 01:59:327522 parent->AddChild(child);
7523 child->AddChild(duplicate_child_non_owner);
7524 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:477525
[email protected]d600df7d2013-08-03 02:34:287526 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7527 host->SetRootLayer(parent);
7528
[email protected]873639e2013-07-24 19:56:317529 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:537530
7531 RenderSurfaceLayerList render_surface_layer_list;
7532 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7533 parent.get(), parent->bounds(), &render_surface_layer_list);
7534 inputs.device_scale_factor = device_scale_factor;
7535 inputs.can_adjust_raster_scales = true;
7536 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:477537
[email protected]fb661802013-03-25 01:59:327538 // We should have two render surfaces. The root's render surface and child's
7539 // render surface (it needs one because it has a replica layer).
7540 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:477541
[email protected]fb661802013-03-25 01:59:327542 gfx::Transform identity_transform;
[email protected]904e9132012-11-01 00:12:477543
[email protected]fb661802013-03-25 01:59:327544 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7545 parent->screen_space_transform());
7546 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform());
7547 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform());
7548 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7549 child->screen_space_transform());
7550 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7551 duplicate_child_non_owner->draw_transform());
7552 EXPECT_TRANSFORMATION_MATRIX_EQ(
7553 identity_transform, duplicate_child_non_owner->screen_space_transform());
7554 EXPECT_RECT_EQ(child->drawable_content_rect(),
7555 duplicate_child_non_owner->drawable_content_rect());
7556 EXPECT_EQ(child->content_bounds(),
7557 duplicate_child_non_owner->content_bounds());
[email protected]904e9132012-11-01 00:12:477558
[email protected]fb661802013-03-25 01:59:327559 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7560 child->render_surface()->draw_transform());
7561 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7562 child->render_surface()->draw_transform());
7563 EXPECT_TRANSFORMATION_MATRIX_EQ(
7564 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:477565
[email protected]fb661802013-03-25 01:59:327566 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267567 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327568 EXPECT_TRANSFORMATION_MATRIX_EQ(
7569 expected_replica_draw_transform,
7570 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:477571
[email protected]fb661802013-03-25 01:59:327572 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267573 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327574 EXPECT_TRANSFORMATION_MATRIX_EQ(
7575 expected_replica_screen_space_transform,
7576 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147577}
7578
[email protected]989386c2013-07-18 21:37:237579TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:327580 scoped_refptr<Layer> root = Layer::Create();
7581 scoped_refptr<Layer> child = Layer::Create();
7582 scoped_refptr<Layer> grand_child = Layer::Create();
7583 scoped_refptr<Layer> mask_layer = Layer::Create();
7584 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:147585
[email protected]fb661802013-03-25 01:59:327586 grand_child->SetReplicaLayer(replica_layer.get());
7587 child->AddChild(grand_child.get());
7588 child->SetMaskLayer(mask_layer.get());
7589 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:147590
[email protected]d600df7d2013-08-03 02:34:287591 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7592 host->SetRootLayer(root);
7593
[email protected]fb661802013-03-25 01:59:327594 int nonexistent_id = -1;
7595 EXPECT_EQ(root,
7596 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
7597 EXPECT_EQ(child,
7598 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
7599 EXPECT_EQ(
7600 grand_child,
7601 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
7602 EXPECT_EQ(
7603 mask_layer,
7604 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
7605 EXPECT_EQ(
7606 replica_layer,
7607 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
7608 EXPECT_EQ(
7609 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:147610}
7611
[email protected]989386c2013-07-18 21:37:237612TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:327613 scoped_refptr<Layer> root = Layer::Create();
7614 scoped_refptr<Layer> child = Layer::Create();
7615 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
7616 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:577617
[email protected]fb661802013-03-25 01:59:327618 const gfx::Transform identity_matrix;
7619 SetLayerPropertiesForTesting(root.get(),
7620 identity_matrix,
[email protected]fb661802013-03-25 01:59:327621 gfx::PointF(),
7622 gfx::PointF(),
7623 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577624 true,
[email protected]fb661802013-03-25 01:59:327625 false);
7626 SetLayerPropertiesForTesting(child.get(),
7627 identity_matrix,
[email protected]fb661802013-03-25 01:59:327628 gfx::PointF(),
7629 gfx::PointF(),
7630 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577631 true,
[email protected]fb661802013-03-25 01:59:327632 false);
7633 SetLayerPropertiesForTesting(grand_child.get(),
7634 identity_matrix,
[email protected]fb661802013-03-25 01:59:327635 gfx::PointF(),
7636 gfx::PointF(),
7637 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577638 true,
[email protected]fb661802013-03-25 01:59:327639 false);
[email protected]498ec6e0e2012-11-30 18:24:577640
[email protected]fb661802013-03-25 01:59:327641 root->AddChild(child);
7642 child->AddChild(grand_child);
7643 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:577644
[email protected]d600df7d2013-08-03 02:34:287645 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7646 host->SetRootLayer(root);
7647
[email protected]fb661802013-03-25 01:59:327648 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:577649
[email protected]fb661802013-03-25 01:59:327650 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:577651}
7652
[email protected]989386c2013-07-18 21:37:237653TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:167654 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457655 TestSharedBitmapManager shared_bitmap_manager;
7656 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]f90fc412013-03-30 20:13:167657 host_impl.CreatePendingTree();
7658 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7659
7660 const gfx::Transform identity_matrix;
7661 SetLayerPropertiesForTesting(root.get(),
7662 identity_matrix,
[email protected]f90fc412013-03-30 20:13:167663 gfx::PointF(),
7664 gfx::PointF(),
7665 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577666 true,
[email protected]f90fc412013-03-30 20:13:167667 false);
7668 root->SetDrawsContent(true);
7669
7670 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7671 SetLayerPropertiesForTesting(child.get(),
7672 identity_matrix,
[email protected]f90fc412013-03-30 20:13:167673 gfx::PointF(),
7674 gfx::PointF(),
7675 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577676 true,
[email protected]f90fc412013-03-30 20:13:167677 false);
7678 child->SetDrawsContent(true);
7679 child->SetOpacity(0.0f);
7680
7681 // Add opacity animation.
7682 AddOpacityTransitionToController(
7683 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
7684
7685 root->AddChild(child.Pass());
7686
[email protected]c0ae06c12013-06-24 18:32:197687 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537688 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7689 root.get(), root->bounds(), &render_surface_layer_list);
7690 inputs.can_adjust_raster_scales = true;
7691 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:167692
7693 // We should have one render surface and two layers. The child
7694 // layer should be included even though it is transparent.
7695 ASSERT_EQ(1u, render_surface_layer_list.size());
7696 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
7697}
7698
[email protected]10aabcc32012-12-13 09:18:597699typedef std::tr1::tuple<bool, bool> LCDTextTestParam;
[email protected]989386c2013-07-18 21:37:237700class LCDTextTest
7701 : public LayerTreeHostCommonTestBase,
7702 public testing::TestWithParam<LCDTextTestParam> {
[email protected]fb661802013-03-25 01:59:327703 protected:
7704 virtual void SetUp() {
7705 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
[email protected]10aabcc32012-12-13 09:18:597706
[email protected]fb661802013-03-25 01:59:327707 root_ = Layer::Create();
7708 child_ = Layer::Create();
7709 grand_child_ = Layer::Create();
7710 child_->AddChild(grand_child_.get());
7711 root_->AddChild(child_.get());
[email protected]10aabcc32012-12-13 09:18:597712
[email protected]fb661802013-03-25 01:59:327713 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307714 SetLayerPropertiesForTesting(root_.get(),
[email protected]fb661802013-03-25 01:59:327715 identity_matrix,
[email protected]fb661802013-03-25 01:59:327716 gfx::PointF(),
7717 gfx::PointF(),
7718 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577719 true,
[email protected]fb661802013-03-25 01:59:327720 false);
[email protected]22898ed2013-06-01 04:52:307721 SetLayerPropertiesForTesting(child_.get(),
[email protected]fb661802013-03-25 01:59:327722 identity_matrix,
[email protected]fb661802013-03-25 01:59:327723 gfx::PointF(),
7724 gfx::PointF(),
7725 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577726 true,
[email protected]fb661802013-03-25 01:59:327727 false);
[email protected]22898ed2013-06-01 04:52:307728 SetLayerPropertiesForTesting(grand_child_.get(),
[email protected]fb661802013-03-25 01:59:327729 identity_matrix,
[email protected]fb661802013-03-25 01:59:327730 gfx::PointF(),
7731 gfx::PointF(),
7732 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577733 true,
[email protected]fb661802013-03-25 01:59:327734 false);
[email protected]10aabcc32012-12-13 09:18:597735
[email protected]fb661802013-03-25 01:59:327736 child_->SetForceRenderSurface(std::tr1::get<1>(GetParam()));
[email protected]d600df7d2013-08-03 02:34:287737
7738 host_ = FakeLayerTreeHost::Create();
7739 host_->SetRootLayer(root_);
[email protected]fb661802013-03-25 01:59:327740 }
[email protected]10aabcc32012-12-13 09:18:597741
[email protected]fb661802013-03-25 01:59:327742 bool can_use_lcd_text_;
[email protected]d600df7d2013-08-03 02:34:287743 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]fb661802013-03-25 01:59:327744 scoped_refptr<Layer> root_;
7745 scoped_refptr<Layer> child_;
7746 scoped_refptr<Layer> grand_child_;
[email protected]10aabcc32012-12-13 09:18:597747};
7748
[email protected]fb661802013-03-25 01:59:327749TEST_P(LCDTextTest, CanUseLCDText) {
7750 // Case 1: Identity transform.
7751 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307752 ExecuteCalculateDrawProperties(
7753 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327754 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7755 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7756 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597757
[email protected]fb661802013-03-25 01:59:327758 // Case 2: Integral translation.
7759 gfx::Transform integral_translation;
7760 integral_translation.Translate(1.0, 2.0);
7761 child_->SetTransform(integral_translation);
[email protected]22898ed2013-06-01 04:52:307762 ExecuteCalculateDrawProperties(
7763 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327764 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7765 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7766 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597767
[email protected]fb661802013-03-25 01:59:327768 // Case 3: Non-integral translation.
7769 gfx::Transform non_integral_translation;
7770 non_integral_translation.Translate(1.5, 2.5);
7771 child_->SetTransform(non_integral_translation);
[email protected]22898ed2013-06-01 04:52:307772 ExecuteCalculateDrawProperties(
7773 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327774 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7775 EXPECT_FALSE(child_->can_use_lcd_text());
7776 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597777
[email protected]fb661802013-03-25 01:59:327778 // Case 4: Rotation.
7779 gfx::Transform rotation;
7780 rotation.Rotate(10.0);
7781 child_->SetTransform(rotation);
[email protected]22898ed2013-06-01 04:52:307782 ExecuteCalculateDrawProperties(
7783 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327784 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7785 EXPECT_FALSE(child_->can_use_lcd_text());
7786 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597787
[email protected]fb661802013-03-25 01:59:327788 // Case 5: Scale.
7789 gfx::Transform scale;
7790 scale.Scale(2.0, 2.0);
7791 child_->SetTransform(scale);
[email protected]22898ed2013-06-01 04:52:307792 ExecuteCalculateDrawProperties(
7793 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327794 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7795 EXPECT_FALSE(child_->can_use_lcd_text());
7796 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597797
[email protected]fb661802013-03-25 01:59:327798 // Case 6: Skew.
7799 gfx::Transform skew;
7800 skew.SkewX(10.0);
7801 child_->SetTransform(skew);
[email protected]22898ed2013-06-01 04:52:307802 ExecuteCalculateDrawProperties(
7803 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327804 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7805 EXPECT_FALSE(child_->can_use_lcd_text());
7806 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597807
[email protected]fb661802013-03-25 01:59:327808 // Case 7: Translucent.
7809 child_->SetTransform(identity_matrix);
7810 child_->SetOpacity(0.5f);
[email protected]22898ed2013-06-01 04:52:307811 ExecuteCalculateDrawProperties(
7812 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327813 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7814 EXPECT_FALSE(child_->can_use_lcd_text());
7815 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597816
[email protected]fb661802013-03-25 01:59:327817 // Case 8: Sanity check: restore transform and opacity.
7818 child_->SetTransform(identity_matrix);
7819 child_->SetOpacity(1.f);
[email protected]22898ed2013-06-01 04:52:307820 ExecuteCalculateDrawProperties(
7821 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327822 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7823 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7824 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597825}
7826
[email protected]fd9a3b6d2013-08-03 00:46:177827TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
[email protected]fb661802013-03-25 01:59:327828 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
[email protected]22898ed2013-06-01 04:52:307829 ExecuteCalculateDrawProperties(
7830 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327831 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7832 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7833 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597834
[email protected]fb661802013-03-25 01:59:327835 // Add opacity animation.
7836 child_->SetOpacity(0.9f);
7837 AddOpacityTransitionToController(
7838 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:597839
[email protected]22898ed2013-06-01 04:52:307840 ExecuteCalculateDrawProperties(
7841 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327842 // Text AA should not be adjusted while animation is active.
7843 // Make sure LCD text AA setting remains unchanged.
7844 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7845 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7846 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597847}
7848
7849INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
7850 LCDTextTest,
[email protected]fb661802013-03-25 01:59:327851 testing::Combine(testing::Bool(), testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:597852
[email protected]989386c2013-07-18 21:37:237853TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:197854 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457855 TestSharedBitmapManager shared_bitmap_manager;
7856 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:197857 host_impl.CreatePendingTree();
7858 const gfx::Transform identity_matrix;
7859
7860 scoped_refptr<Layer> root = Layer::Create();
7861 SetLayerPropertiesForTesting(root.get(),
7862 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197863 gfx::PointF(),
7864 gfx::PointF(),
7865 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577866 true,
[email protected]c0ae06c12013-06-24 18:32:197867 false);
7868 root->SetIsDrawable(true);
7869
7870 scoped_refptr<Layer> child = Layer::Create();
7871 SetLayerPropertiesForTesting(child.get(),
7872 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197873 gfx::PointF(),
7874 gfx::PointF(),
7875 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577876 true,
[email protected]c0ae06c12013-06-24 18:32:197877 false);
7878 child->SetIsDrawable(true);
7879
7880 scoped_refptr<Layer> grand_child = Layer::Create();
7881 SetLayerPropertiesForTesting(grand_child.get(),
7882 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197883 gfx::PointF(),
7884 gfx::PointF(),
7885 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577886 true,
[email protected]c0ae06c12013-06-24 18:32:197887 false);
7888 grand_child->SetIsDrawable(true);
7889 grand_child->SetHideLayerAndSubtree(true);
7890
7891 child->AddChild(grand_child);
7892 root->AddChild(child);
7893
[email protected]d600df7d2013-08-03 02:34:287894 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7895 host->SetRootLayer(root);
7896
[email protected]989386c2013-07-18 21:37:237897 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537898 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7899 root.get(), root->bounds(), &render_surface_layer_list);
7900 inputs.can_adjust_raster_scales = true;
7901 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197902
7903 // We should have one render surface and two layers. The grand child has
7904 // hidden itself.
7905 ASSERT_EQ(1u, render_surface_layer_list.size());
7906 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237907 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
7908 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197909}
7910
[email protected]989386c2013-07-18 21:37:237911TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:197912 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457913 TestSharedBitmapManager shared_bitmap_manager;
7914 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:197915 host_impl.CreatePendingTree();
7916 const gfx::Transform identity_matrix;
7917
7918 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7919 SetLayerPropertiesForTesting(root.get(),
7920 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197921 gfx::PointF(),
7922 gfx::PointF(),
7923 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577924 true,
[email protected]c0ae06c12013-06-24 18:32:197925 false);
7926 root->SetDrawsContent(true);
7927
7928 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7929 SetLayerPropertiesForTesting(child.get(),
7930 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197931 gfx::PointF(),
7932 gfx::PointF(),
7933 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577934 true,
[email protected]c0ae06c12013-06-24 18:32:197935 false);
7936 child->SetDrawsContent(true);
7937
7938 scoped_ptr<LayerImpl> grand_child =
7939 LayerImpl::Create(host_impl.pending_tree(), 3);
7940 SetLayerPropertiesForTesting(grand_child.get(),
7941 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197942 gfx::PointF(),
7943 gfx::PointF(),
7944 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577945 true,
[email protected]c0ae06c12013-06-24 18:32:197946 false);
7947 grand_child->SetDrawsContent(true);
7948 grand_child->SetHideLayerAndSubtree(true);
7949
7950 child->AddChild(grand_child.Pass());
7951 root->AddChild(child.Pass());
7952
7953 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537954 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7955 root.get(), root->bounds(), &render_surface_layer_list);
7956 inputs.can_adjust_raster_scales = true;
7957 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197958
7959 // We should have one render surface and two layers. The grand child has
7960 // hidden itself.
7961 ASSERT_EQ(1u, render_surface_layer_list.size());
7962 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237963 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
7964 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197965}
7966
[email protected]989386c2013-07-18 21:37:237967TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:197968 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457969 TestSharedBitmapManager shared_bitmap_manager;
7970 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:197971 host_impl.CreatePendingTree();
7972 const gfx::Transform identity_matrix;
7973
7974 scoped_refptr<Layer> root = Layer::Create();
7975 SetLayerPropertiesForTesting(root.get(),
7976 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197977 gfx::PointF(),
7978 gfx::PointF(),
7979 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577980 true,
[email protected]c0ae06c12013-06-24 18:32:197981 false);
7982 root->SetIsDrawable(true);
7983
7984 scoped_refptr<Layer> child = Layer::Create();
7985 SetLayerPropertiesForTesting(child.get(),
7986 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197987 gfx::PointF(),
7988 gfx::PointF(),
7989 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577990 true,
[email protected]c0ae06c12013-06-24 18:32:197991 false);
7992 child->SetIsDrawable(true);
7993 child->SetHideLayerAndSubtree(true);
7994
7995 scoped_refptr<Layer> grand_child = Layer::Create();
7996 SetLayerPropertiesForTesting(grand_child.get(),
7997 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197998 gfx::PointF(),
7999 gfx::PointF(),
8000 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578001 true,
[email protected]c0ae06c12013-06-24 18:32:198002 false);
8003 grand_child->SetIsDrawable(true);
8004
8005 child->AddChild(grand_child);
8006 root->AddChild(child);
8007
[email protected]d600df7d2013-08-03 02:34:288008 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8009 host->SetRootLayer(root);
8010
[email protected]989386c2013-07-18 21:37:238011 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538012 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8013 root.get(), root->bounds(), &render_surface_layer_list);
8014 inputs.can_adjust_raster_scales = true;
8015 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198016
8017 // We should have one render surface and one layers. The child has
8018 // hidden itself and the grand child.
8019 ASSERT_EQ(1u, render_surface_layer_list.size());
8020 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238021 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:198022}
8023
[email protected]989386c2013-07-18 21:37:238024TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:198025 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458026 TestSharedBitmapManager shared_bitmap_manager;
8027 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:198028 host_impl.CreatePendingTree();
8029 const gfx::Transform identity_matrix;
8030
8031 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
8032 SetLayerPropertiesForTesting(root.get(),
8033 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198034 gfx::PointF(),
8035 gfx::PointF(),
8036 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578037 true,
[email protected]c0ae06c12013-06-24 18:32:198038 false);
8039 root->SetDrawsContent(true);
8040
8041 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
8042 SetLayerPropertiesForTesting(child.get(),
8043 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198044 gfx::PointF(),
8045 gfx::PointF(),
8046 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578047 true,
[email protected]c0ae06c12013-06-24 18:32:198048 false);
8049 child->SetDrawsContent(true);
8050 child->SetHideLayerAndSubtree(true);
8051
8052 scoped_ptr<LayerImpl> grand_child =
8053 LayerImpl::Create(host_impl.pending_tree(), 3);
8054 SetLayerPropertiesForTesting(grand_child.get(),
8055 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198056 gfx::PointF(),
8057 gfx::PointF(),
8058 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578059 true,
[email protected]c0ae06c12013-06-24 18:32:198060 false);
8061 grand_child->SetDrawsContent(true);
8062
8063 child->AddChild(grand_child.Pass());
8064 root->AddChild(child.Pass());
8065
8066 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538067 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8068 root.get(), root->bounds(), &render_surface_layer_list);
8069 inputs.can_adjust_raster_scales = true;
8070 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198071
8072 // We should have one render surface and one layers. The child has
8073 // hidden itself and the grand child.
8074 ASSERT_EQ(1u, render_surface_layer_list.size());
8075 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238076 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:198077}
8078
[email protected]30fe19ff2013-07-04 00:54:458079void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
8080
[email protected]989386c2013-07-18 21:37:238081TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458082 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458083 TestSharedBitmapManager shared_bitmap_manager;
8084 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:458085 host_impl.CreatePendingTree();
8086 const gfx::Transform identity_matrix;
8087
8088 scoped_refptr<Layer> root = Layer::Create();
8089 SetLayerPropertiesForTesting(root.get(),
8090 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458091 gfx::PointF(),
8092 gfx::PointF(),
8093 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578094 true,
[email protected]30fe19ff2013-07-04 00:54:458095 false);
8096 root->SetIsDrawable(true);
8097
8098 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
8099 SetLayerPropertiesForTesting(copy_grand_parent.get(),
8100 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458101 gfx::PointF(),
8102 gfx::PointF(),
8103 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578104 true,
[email protected]30fe19ff2013-07-04 00:54:458105 false);
8106 copy_grand_parent->SetIsDrawable(true);
8107
8108 scoped_refptr<Layer> copy_parent = Layer::Create();
8109 SetLayerPropertiesForTesting(copy_parent.get(),
8110 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458111 gfx::PointF(),
8112 gfx::PointF(),
8113 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578114 true,
[email protected]30fe19ff2013-07-04 00:54:458115 false);
8116 copy_parent->SetIsDrawable(true);
8117 copy_parent->SetForceRenderSurface(true);
8118
8119 scoped_refptr<Layer> copy_layer = Layer::Create();
8120 SetLayerPropertiesForTesting(copy_layer.get(),
8121 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458122 gfx::PointF(),
8123 gfx::PointF(),
8124 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578125 true,
[email protected]30fe19ff2013-07-04 00:54:458126 false);
8127 copy_layer->SetIsDrawable(true);
8128
8129 scoped_refptr<Layer> copy_child = Layer::Create();
8130 SetLayerPropertiesForTesting(copy_child.get(),
8131 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458132 gfx::PointF(),
8133 gfx::PointF(),
8134 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578135 true,
[email protected]30fe19ff2013-07-04 00:54:458136 false);
8137 copy_child->SetIsDrawable(true);
8138
[email protected]ac020122013-07-12 23:45:538139 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
8140 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
8141 identity_matrix,
[email protected]ac020122013-07-12 23:45:538142 gfx::PointF(),
8143 gfx::PointF(),
8144 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578145 true,
[email protected]ac020122013-07-12 23:45:538146 false);
8147 copy_grand_parent_sibling_before->SetIsDrawable(true);
8148
8149 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
8150 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
8151 identity_matrix,
[email protected]ac020122013-07-12 23:45:538152 gfx::PointF(),
8153 gfx::PointF(),
8154 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578155 true,
[email protected]ac020122013-07-12 23:45:538156 false);
8157 copy_grand_parent_sibling_after->SetIsDrawable(true);
8158
[email protected]30fe19ff2013-07-04 00:54:458159 copy_layer->AddChild(copy_child);
8160 copy_parent->AddChild(copy_layer);
8161 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:538162 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:458163 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:538164 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:458165
[email protected]d600df7d2013-08-03 02:34:288166 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8167 host->SetRootLayer(root);
8168
[email protected]30fe19ff2013-07-04 00:54:458169 // Hide the copy_grand_parent and its subtree. But make a copy request in that
8170 // hidden subtree on copy_layer.
8171 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:538172 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
8173 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:458174 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8175 base::Bind(&EmptyCopyOutputCallback)));
8176 EXPECT_TRUE(copy_layer->HasCopyRequest());
8177
[email protected]989386c2013-07-18 21:37:238178 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538179 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8180 root.get(), root->bounds(), &render_surface_layer_list);
8181 inputs.can_adjust_raster_scales = true;
8182 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458183
[email protected]ac020122013-07-12 23:45:538184 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
8185 EXPECT_TRUE(copy_grand_parent->draw_properties().
8186 layer_or_descendant_has_copy_request);
8187 EXPECT_TRUE(copy_parent->draw_properties().
8188 layer_or_descendant_has_copy_request);
8189 EXPECT_TRUE(copy_layer->draw_properties().
8190 layer_or_descendant_has_copy_request);
8191 EXPECT_FALSE(copy_child->draw_properties().
8192 layer_or_descendant_has_copy_request);
8193 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
8194 layer_or_descendant_has_copy_request);
8195 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
8196 layer_or_descendant_has_copy_request);
8197
[email protected]30fe19ff2013-07-04 00:54:458198 // We should have three render surfaces, one for the root, one for the parent
8199 // since it owns a surface, and one for the copy_layer.
8200 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238201 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
8202 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
8203 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:458204
8205 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:538206 // copy_grand_parent is hidden along with its siblings, but the copy_parent
8207 // will appear since something in its subtree needs to be drawn for a copy
8208 // request.
[email protected]30fe19ff2013-07-04 00:54:458209 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238210 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
8211 EXPECT_EQ(copy_parent->id(),
8212 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458213
[email protected]7392c7b2014-02-07 08:28:288214 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:458215 // appear in its list, since it needs to be drawn for the copy request.
8216 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
8217 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238218 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458219
8220 // The copy_layer's render surface should have two contributing layers.
8221 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
8222 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238223 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458224 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:238225 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458226}
8227
[email protected]989386c2013-07-18 21:37:238228TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458229 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458230 TestSharedBitmapManager shared_bitmap_manager;
8231 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:458232 host_impl.CreatePendingTree();
8233 const gfx::Transform identity_matrix;
8234
8235 scoped_refptr<Layer> root = Layer::Create();
8236 SetLayerPropertiesForTesting(root.get(),
8237 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458238 gfx::PointF(),
8239 gfx::PointF(),
8240 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578241 true,
[email protected]30fe19ff2013-07-04 00:54:458242 false);
8243 root->SetIsDrawable(true);
8244
8245 scoped_refptr<Layer> copy_parent = Layer::Create();
8246 SetLayerPropertiesForTesting(copy_parent.get(),
8247 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458248 gfx::PointF(),
8249 gfx::PointF(),
8250 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:578251 true,
[email protected]30fe19ff2013-07-04 00:54:458252 false);
8253 copy_parent->SetIsDrawable(true);
8254 copy_parent->SetMasksToBounds(true);
8255
8256 scoped_refptr<Layer> copy_layer = Layer::Create();
8257 SetLayerPropertiesForTesting(copy_layer.get(),
8258 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458259 gfx::PointF(),
8260 gfx::PointF(),
8261 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578262 true,
[email protected]30fe19ff2013-07-04 00:54:458263 false);
8264 copy_layer->SetIsDrawable(true);
8265
8266 scoped_refptr<Layer> copy_child = Layer::Create();
8267 SetLayerPropertiesForTesting(copy_child.get(),
8268 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458269 gfx::PointF(),
8270 gfx::PointF(),
8271 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578272 true,
[email protected]30fe19ff2013-07-04 00:54:458273 false);
8274 copy_child->SetIsDrawable(true);
8275
8276 copy_layer->AddChild(copy_child);
8277 copy_parent->AddChild(copy_layer);
8278 root->AddChild(copy_parent);
8279
[email protected]d600df7d2013-08-03 02:34:288280 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8281 host->SetRootLayer(root);
8282
[email protected]30fe19ff2013-07-04 00:54:458283 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8284 base::Bind(&EmptyCopyOutputCallback)));
8285 EXPECT_TRUE(copy_layer->HasCopyRequest());
8286
[email protected]989386c2013-07-18 21:37:238287 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538288 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8289 root.get(), root->bounds(), &render_surface_layer_list);
8290 inputs.can_adjust_raster_scales = true;
8291 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458292
8293 // We should have one render surface, as the others are clipped out.
8294 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238295 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458296
8297 // The root render surface should only have 1 contributing layer, since the
8298 // other layers are empty/clipped away.
8299 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238300 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458301}
8302
[email protected]11a07b102013-07-24 17:33:198303TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
8304 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458305 TestSharedBitmapManager shared_bitmap_manager;
8306 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]11a07b102013-07-24 17:33:198307 host_impl.CreatePendingTree();
8308 const gfx::Transform identity_matrix;
8309
8310 scoped_refptr<Layer> root = Layer::Create();
8311 SetLayerPropertiesForTesting(root.get(),
8312 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198313 gfx::PointF(),
8314 gfx::PointF(),
8315 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578316 true,
[email protected]11a07b102013-07-24 17:33:198317 false);
8318 root->SetIsDrawable(true);
8319
8320 // The surface is moved slightly outside of the viewport.
8321 scoped_refptr<Layer> surface = Layer::Create();
8322 SetLayerPropertiesForTesting(surface.get(),
8323 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198324 gfx::PointF(),
8325 gfx::PointF(-10, -20),
8326 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:578327 true,
[email protected]11a07b102013-07-24 17:33:198328 false);
8329 surface->SetForceRenderSurface(true);
8330
8331 scoped_refptr<Layer> surface_child = Layer::Create();
8332 SetLayerPropertiesForTesting(surface_child.get(),
8333 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198334 gfx::PointF(),
8335 gfx::PointF(),
8336 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578337 true,
[email protected]11a07b102013-07-24 17:33:198338 false);
8339 surface_child->SetIsDrawable(true);
8340
8341 surface->AddChild(surface_child);
8342 root->AddChild(surface);
8343
[email protected]d600df7d2013-08-03 02:34:288344 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8345 host->SetRootLayer(root);
8346
[email protected]11a07b102013-07-24 17:33:198347 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538348 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8349 root.get(), root->bounds(), &render_surface_layer_list);
8350 inputs.can_adjust_raster_scales = true;
8351 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:198352
8353 // The visible_content_rect for the |surface_child| should not be clipped by
8354 // the viewport.
8355 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
8356 surface_child->visible_content_rect().ToString());
8357}
8358
[email protected]420fdf6e2013-08-26 20:36:388359TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
8360 // Ensure that a transform between the layer and its render surface is not a
8361 // problem. Constructs the following layer tree.
8362 //
8363 // root (a render surface)
8364 // + render_surface
8365 // + clip_parent (scaled)
8366 // + intervening_clipping_layer
8367 // + clip_child
8368 //
8369 // The render surface should be resized correctly and the clip child should
8370 // inherit the right clip rect.
8371 scoped_refptr<Layer> root = Layer::Create();
8372 scoped_refptr<Layer> render_surface = Layer::Create();
8373 scoped_refptr<Layer> clip_parent = Layer::Create();
8374 scoped_refptr<Layer> intervening = Layer::Create();
8375 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8376 make_scoped_refptr(new LayerWithForcedDrawsContent);
8377
8378 root->AddChild(render_surface);
8379 render_surface->AddChild(clip_parent);
8380 clip_parent->AddChild(intervening);
8381 intervening->AddChild(clip_child);
8382
8383 clip_child->SetClipParent(clip_parent.get());
8384
8385 intervening->SetMasksToBounds(true);
8386 clip_parent->SetMasksToBounds(true);
8387
8388 render_surface->SetForceRenderSurface(true);
8389
8390 gfx::Transform scale_transform;
8391 scale_transform.Scale(2, 2);
8392
8393 gfx::Transform identity_transform;
8394
8395 SetLayerPropertiesForTesting(root.get(),
8396 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388397 gfx::PointF(),
8398 gfx::PointF(),
8399 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578400 true,
[email protected]420fdf6e2013-08-26 20:36:388401 false);
8402 SetLayerPropertiesForTesting(render_surface.get(),
8403 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388404 gfx::PointF(),
8405 gfx::PointF(),
8406 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578407 true,
[email protected]420fdf6e2013-08-26 20:36:388408 false);
8409 SetLayerPropertiesForTesting(clip_parent.get(),
8410 scale_transform,
[email protected]420fdf6e2013-08-26 20:36:388411 gfx::PointF(),
8412 gfx::PointF(1.f, 1.f),
8413 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578414 true,
[email protected]420fdf6e2013-08-26 20:36:388415 false);
8416 SetLayerPropertiesForTesting(intervening.get(),
8417 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388418 gfx::PointF(),
8419 gfx::PointF(1.f, 1.f),
8420 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578421 true,
[email protected]420fdf6e2013-08-26 20:36:388422 false);
8423 SetLayerPropertiesForTesting(clip_child.get(),
8424 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388425 gfx::PointF(),
8426 gfx::PointF(1.f, 1.f),
8427 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578428 true,
[email protected]420fdf6e2013-08-26 20:36:388429 false);
8430
8431 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8432 host->SetRootLayer(root);
8433
8434 ExecuteCalculateDrawProperties(root.get());
8435
8436 ASSERT_TRUE(root->render_surface());
8437 ASSERT_TRUE(render_surface->render_surface());
8438
8439 // Ensure that we've inherited our clip parent's clip and weren't affected
8440 // by the intervening clip layer.
8441 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
8442 clip_parent->clip_rect().ToString());
8443 ASSERT_EQ(clip_parent->clip_rect().ToString(),
8444 clip_child->clip_rect().ToString());
8445 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
8446 intervening->clip_rect().ToString());
8447
8448 // Ensure that the render surface reports a content rect that has been grown
8449 // to accomodate for the clip child.
8450 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
8451 render_surface->render_surface()->content_rect().ToString());
8452
8453 // The above check implies the two below, but they nicely demonstrate that
8454 // we've grown, despite the intervening layer's clip.
8455 ASSERT_TRUE(clip_parent->clip_rect().Contains(
8456 render_surface->render_surface()->content_rect()));
8457 ASSERT_FALSE(intervening->clip_rect().Contains(
8458 render_surface->render_surface()->content_rect()));
8459}
8460
8461TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
8462 // Ensure that intervening render surfaces are not a problem in the basic
8463 // case. In the following tree, both render surfaces should be resized to
8464 // accomodate for the clip child, despite an intervening clip.
8465 //
8466 // root (a render surface)
8467 // + clip_parent (masks to bounds)
8468 // + render_surface1 (sets opacity)
8469 // + intervening (masks to bounds)
8470 // + render_surface2 (also sets opacity)
8471 // + clip_child
8472 //
8473 scoped_refptr<Layer> root = Layer::Create();
8474 scoped_refptr<Layer> clip_parent = Layer::Create();
8475 scoped_refptr<Layer> render_surface1 = Layer::Create();
8476 scoped_refptr<Layer> intervening = Layer::Create();
8477 scoped_refptr<Layer> render_surface2 = Layer::Create();
8478 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8479 make_scoped_refptr(new LayerWithForcedDrawsContent);
8480
8481 root->AddChild(clip_parent);
8482 clip_parent->AddChild(render_surface1);
8483 render_surface1->AddChild(intervening);
8484 intervening->AddChild(render_surface2);
8485 render_surface2->AddChild(clip_child);
8486
8487 clip_child->SetClipParent(clip_parent.get());
8488
8489 intervening->SetMasksToBounds(true);
8490 clip_parent->SetMasksToBounds(true);
8491
8492 render_surface1->SetForceRenderSurface(true);
8493 render_surface2->SetForceRenderSurface(true);
8494
8495 gfx::Transform translation_transform;
8496 translation_transform.Translate(2, 2);
8497
8498 gfx::Transform identity_transform;
8499 SetLayerPropertiesForTesting(root.get(),
8500 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388501 gfx::PointF(),
8502 gfx::PointF(),
8503 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578504 true,
[email protected]420fdf6e2013-08-26 20:36:388505 false);
8506 SetLayerPropertiesForTesting(clip_parent.get(),
8507 translation_transform,
[email protected]420fdf6e2013-08-26 20:36:388508 gfx::PointF(),
8509 gfx::PointF(1.f, 1.f),
8510 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578511 true,
[email protected]420fdf6e2013-08-26 20:36:388512 false);
8513 SetLayerPropertiesForTesting(render_surface1.get(),
8514 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388515 gfx::PointF(),
8516 gfx::PointF(),
8517 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578518 true,
[email protected]420fdf6e2013-08-26 20:36:388519 false);
8520 SetLayerPropertiesForTesting(intervening.get(),
8521 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388522 gfx::PointF(),
8523 gfx::PointF(1.f, 1.f),
8524 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578525 true,
[email protected]420fdf6e2013-08-26 20:36:388526 false);
8527 SetLayerPropertiesForTesting(render_surface2.get(),
8528 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388529 gfx::PointF(),
8530 gfx::PointF(),
8531 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578532 true,
[email protected]420fdf6e2013-08-26 20:36:388533 false);
8534 SetLayerPropertiesForTesting(clip_child.get(),
8535 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388536 gfx::PointF(),
8537 gfx::PointF(-10.f, -10.f),
8538 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578539 true,
[email protected]420fdf6e2013-08-26 20:36:388540 false);
8541
8542 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8543 host->SetRootLayer(root);
8544
8545 ExecuteCalculateDrawProperties(root.get());
8546
8547 EXPECT_TRUE(root->render_surface());
8548 EXPECT_TRUE(render_surface1->render_surface());
8549 EXPECT_TRUE(render_surface2->render_surface());
8550
8551 // Since the render surfaces could have expanded, they should not clip (their
8552 // bounds would no longer be reliable). We should resort to layer clipping
8553 // in this case.
8554 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8555 render_surface1->render_surface()->clip_rect().ToString());
8556 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8557 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8558 render_surface2->render_surface()->clip_rect().ToString());
8559 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8560
8561 // NB: clip rects are in target space.
8562 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8563 render_surface1->clip_rect().ToString());
8564 EXPECT_TRUE(render_surface1->is_clipped());
8565
8566 // This value is inherited from the clipping ancestor layer, 'intervening'.
8567 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8568 render_surface2->clip_rect().ToString());
8569 EXPECT_TRUE(render_surface2->is_clipped());
8570
8571 // The content rects of both render surfaces should both have expanded to
8572 // contain the clip child.
8573 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8574 render_surface1->render_surface()->content_rect().ToString());
8575 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8576 render_surface2->render_surface()->content_rect().ToString());
8577
8578 // The clip child should have inherited the clip parent's clip (projected to
8579 // the right space, of course), and should have the correctly sized visible
8580 // content rect.
8581 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8582 clip_child->clip_rect().ToString());
8583 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
8584 clip_child->visible_content_rect().ToString());
8585 EXPECT_TRUE(clip_child->is_clipped());
8586}
8587
8588TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
8589 // Ensure that intervening render surfaces are not a problem, even if there
8590 // is a scroll involved. Note, we do _not_ have to consider any other sort
8591 // of transform.
8592 //
8593 // root (a render surface)
8594 // + clip_parent (masks to bounds)
8595 // + render_surface1 (sets opacity)
8596 // + intervening (masks to bounds AND scrolls)
8597 // + render_surface2 (also sets opacity)
8598 // + clip_child
8599 //
8600 scoped_refptr<Layer> root = Layer::Create();
8601 scoped_refptr<Layer> clip_parent = Layer::Create();
8602 scoped_refptr<Layer> render_surface1 = Layer::Create();
8603 scoped_refptr<Layer> intervening = Layer::Create();
8604 scoped_refptr<Layer> render_surface2 = Layer::Create();
8605 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8606 make_scoped_refptr(new LayerWithForcedDrawsContent);
8607
8608 root->AddChild(clip_parent);
8609 clip_parent->AddChild(render_surface1);
8610 render_surface1->AddChild(intervening);
8611 intervening->AddChild(render_surface2);
8612 render_surface2->AddChild(clip_child);
8613
8614 clip_child->SetClipParent(clip_parent.get());
8615
8616 intervening->SetMasksToBounds(true);
8617 clip_parent->SetMasksToBounds(true);
[email protected]adeda572014-01-31 00:49:478618 intervening->SetScrollClipLayerId(clip_parent->id());
[email protected]420fdf6e2013-08-26 20:36:388619 intervening->SetScrollOffset(gfx::Vector2d(3, 3));
8620
8621 render_surface1->SetForceRenderSurface(true);
8622 render_surface2->SetForceRenderSurface(true);
8623
8624 gfx::Transform translation_transform;
8625 translation_transform.Translate(2, 2);
8626
8627 gfx::Transform identity_transform;
8628 SetLayerPropertiesForTesting(root.get(),
8629 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388630 gfx::PointF(),
8631 gfx::PointF(),
8632 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578633 true,
[email protected]420fdf6e2013-08-26 20:36:388634 false);
8635 SetLayerPropertiesForTesting(clip_parent.get(),
8636 translation_transform,
[email protected]420fdf6e2013-08-26 20:36:388637 gfx::PointF(),
8638 gfx::PointF(1.f, 1.f),
8639 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578640 true,
[email protected]420fdf6e2013-08-26 20:36:388641 false);
8642 SetLayerPropertiesForTesting(render_surface1.get(),
8643 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388644 gfx::PointF(),
8645 gfx::PointF(),
8646 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578647 true,
[email protected]420fdf6e2013-08-26 20:36:388648 false);
8649 SetLayerPropertiesForTesting(intervening.get(),
8650 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388651 gfx::PointF(),
8652 gfx::PointF(1.f, 1.f),
8653 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578654 true,
[email protected]420fdf6e2013-08-26 20:36:388655 false);
8656 SetLayerPropertiesForTesting(render_surface2.get(),
8657 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388658 gfx::PointF(),
8659 gfx::PointF(),
8660 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578661 true,
[email protected]420fdf6e2013-08-26 20:36:388662 false);
8663 SetLayerPropertiesForTesting(clip_child.get(),
8664 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388665 gfx::PointF(),
8666 gfx::PointF(-10.f, -10.f),
8667 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578668 true,
[email protected]420fdf6e2013-08-26 20:36:388669 false);
8670
8671 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8672 host->SetRootLayer(root);
8673
8674 ExecuteCalculateDrawProperties(root.get());
8675
8676 EXPECT_TRUE(root->render_surface());
8677 EXPECT_TRUE(render_surface1->render_surface());
8678 EXPECT_TRUE(render_surface2->render_surface());
8679
8680 // Since the render surfaces could have expanded, they should not clip (their
8681 // bounds would no longer be reliable). We should resort to layer clipping
8682 // in this case.
8683 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8684 render_surface1->render_surface()->clip_rect().ToString());
8685 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8686 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8687 render_surface2->render_surface()->clip_rect().ToString());
8688 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8689
8690 // NB: clip rects are in target space.
8691 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8692 render_surface1->clip_rect().ToString());
8693 EXPECT_TRUE(render_surface1->is_clipped());
8694
8695 // This value is inherited from the clipping ancestor layer, 'intervening'.
8696 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
8697 render_surface2->clip_rect().ToString());
8698 EXPECT_TRUE(render_surface2->is_clipped());
8699
8700 // The content rects of both render surfaces should both have expanded to
8701 // contain the clip child.
8702 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8703 render_surface1->render_surface()->content_rect().ToString());
8704 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8705 render_surface2->render_surface()->content_rect().ToString());
8706
8707 // The clip child should have inherited the clip parent's clip (projected to
8708 // the right space, of course), and should have the correctly sized visible
8709 // content rect.
8710 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8711 clip_child->clip_rect().ToString());
8712 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
8713 clip_child->visible_content_rect().ToString());
8714 EXPECT_TRUE(clip_child->is_clipped());
8715}
8716
8717TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
8718 // Ensures that descendants of the clip child inherit the correct clip.
8719 //
8720 // root (a render surface)
8721 // + clip_parent (masks to bounds)
8722 // + intervening (masks to bounds)
8723 // + clip_child
8724 // + child
8725 //
8726 scoped_refptr<Layer> root = Layer::Create();
8727 scoped_refptr<Layer> clip_parent = Layer::Create();
8728 scoped_refptr<Layer> intervening = Layer::Create();
8729 scoped_refptr<Layer> clip_child = Layer::Create();
8730 scoped_refptr<LayerWithForcedDrawsContent> child =
8731 make_scoped_refptr(new LayerWithForcedDrawsContent);
8732
8733 root->AddChild(clip_parent);
8734 clip_parent->AddChild(intervening);
8735 intervening->AddChild(clip_child);
8736 clip_child->AddChild(child);
8737
8738 clip_child->SetClipParent(clip_parent.get());
8739
8740 intervening->SetMasksToBounds(true);
8741 clip_parent->SetMasksToBounds(true);
8742
8743 gfx::Transform identity_transform;
8744 SetLayerPropertiesForTesting(root.get(),
8745 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388746 gfx::PointF(),
8747 gfx::PointF(),
8748 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578749 true,
[email protected]420fdf6e2013-08-26 20:36:388750 false);
8751 SetLayerPropertiesForTesting(clip_parent.get(),
8752 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388753 gfx::PointF(),
8754 gfx::PointF(),
8755 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578756 true,
[email protected]420fdf6e2013-08-26 20:36:388757 false);
8758 SetLayerPropertiesForTesting(intervening.get(),
8759 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388760 gfx::PointF(),
8761 gfx::PointF(),
8762 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578763 true,
[email protected]420fdf6e2013-08-26 20:36:388764 false);
8765 SetLayerPropertiesForTesting(clip_child.get(),
8766 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388767 gfx::PointF(),
8768 gfx::PointF(),
8769 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578770 true,
[email protected]420fdf6e2013-08-26 20:36:388771 false);
8772 SetLayerPropertiesForTesting(child.get(),
8773 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388774 gfx::PointF(),
8775 gfx::PointF(),
8776 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578777 true,
[email protected]420fdf6e2013-08-26 20:36:388778 false);
8779
8780 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8781 host->SetRootLayer(root);
8782
8783 ExecuteCalculateDrawProperties(root.get());
8784
8785 EXPECT_TRUE(root->render_surface());
8786
8787 // Neither the clip child nor its descendant should have inherited the clip
8788 // from |intervening|.
8789 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8790 clip_child->clip_rect().ToString());
8791 EXPECT_TRUE(clip_child->is_clipped());
8792 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8793 child->visible_content_rect().ToString());
8794 EXPECT_TRUE(child->is_clipped());
8795}
8796
8797TEST_F(LayerTreeHostCommonTest,
8798 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
8799 // Ensures that non-descendant clip children in the tree do not affect
8800 // render surfaces.
8801 //
8802 // root (a render surface)
8803 // + clip_parent (masks to bounds)
8804 // + render_surface1
8805 // + clip_child
8806 // + render_surface2
8807 // + non_clip_child
8808 //
8809 // In this example render_surface2 should be unaffected by clip_child.
8810 scoped_refptr<Layer> root = Layer::Create();
8811 scoped_refptr<Layer> clip_parent = Layer::Create();
8812 scoped_refptr<Layer> render_surface1 = Layer::Create();
8813 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8814 make_scoped_refptr(new LayerWithForcedDrawsContent);
8815 scoped_refptr<Layer> render_surface2 = Layer::Create();
8816 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
8817 make_scoped_refptr(new LayerWithForcedDrawsContent);
8818
8819 root->AddChild(clip_parent);
8820 clip_parent->AddChild(render_surface1);
8821 render_surface1->AddChild(clip_child);
8822 clip_parent->AddChild(render_surface2);
8823 render_surface2->AddChild(non_clip_child);
8824
8825 clip_child->SetClipParent(clip_parent.get());
8826
8827 clip_parent->SetMasksToBounds(true);
8828 render_surface1->SetMasksToBounds(true);
8829
8830 gfx::Transform identity_transform;
8831 SetLayerPropertiesForTesting(root.get(),
8832 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388833 gfx::PointF(),
8834 gfx::PointF(),
8835 gfx::Size(15, 15),
[email protected]56fffdd2014-02-11 19:50:578836 true,
[email protected]420fdf6e2013-08-26 20:36:388837 false);
8838 SetLayerPropertiesForTesting(clip_parent.get(),
8839 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388840 gfx::PointF(),
8841 gfx::PointF(),
8842 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578843 true,
[email protected]420fdf6e2013-08-26 20:36:388844 false);
8845 SetLayerPropertiesForTesting(render_surface1.get(),
8846 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388847 gfx::PointF(),
8848 gfx::PointF(5, 5),
8849 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578850 true,
[email protected]420fdf6e2013-08-26 20:36:388851 false);
8852 SetLayerPropertiesForTesting(render_surface2.get(),
8853 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388854 gfx::PointF(),
8855 gfx::PointF(),
8856 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578857 true,
[email protected]420fdf6e2013-08-26 20:36:388858 false);
8859 SetLayerPropertiesForTesting(clip_child.get(),
8860 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388861 gfx::PointF(),
8862 gfx::PointF(-1, 1),
8863 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578864 true,
[email protected]420fdf6e2013-08-26 20:36:388865 false);
8866 SetLayerPropertiesForTesting(non_clip_child.get(),
8867 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388868 gfx::PointF(),
8869 gfx::PointF(),
8870 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578871 true,
[email protected]420fdf6e2013-08-26 20:36:388872 false);
8873
8874 render_surface1->SetForceRenderSurface(true);
8875 render_surface2->SetForceRenderSurface(true);
8876
8877 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8878 host->SetRootLayer(root);
8879
8880 ExecuteCalculateDrawProperties(root.get());
8881
8882 EXPECT_TRUE(root->render_surface());
8883 EXPECT_TRUE(render_surface1->render_surface());
8884 EXPECT_TRUE(render_surface2->render_surface());
8885
8886 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8887 render_surface1->clip_rect().ToString());
8888 EXPECT_TRUE(render_surface1->is_clipped());
8889
8890 // The render surface should not clip (it has unclipped descendants), instead
8891 // it should rely on layer clipping.
8892 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8893 render_surface1->render_surface()->clip_rect().ToString());
8894 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8895
8896 // That said, it should have grown to accomodate the unclipped descendant.
8897 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
8898 render_surface1->render_surface()->content_rect().ToString());
8899
8900 // This render surface should clip. It has no unclipped descendants.
8901 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8902 render_surface2->clip_rect().ToString());
8903 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
8904
8905 // It also shouldn't have grown to accomodate the clip child.
8906 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8907 render_surface2->render_surface()->content_rect().ToString());
8908
8909 // Sanity check our num_unclipped_descendants values.
8910 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
8911 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
8912}
8913
[email protected]45948712013-09-27 02:46:488914TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
8915 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458916 TestSharedBitmapManager shared_bitmap_manager;
8917 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]45948712013-09-27 02:46:488918 scoped_ptr<LayerImpl> root =
8919 LayerImpl::Create(host_impl.active_tree(), 12345);
8920 scoped_ptr<LayerImpl> child1 =
8921 LayerImpl::Create(host_impl.active_tree(), 123456);
8922 scoped_ptr<LayerImpl> child2 =
8923 LayerImpl::Create(host_impl.active_tree(), 1234567);
8924 scoped_ptr<LayerImpl> child3 =
8925 LayerImpl::Create(host_impl.active_tree(), 12345678);
8926
8927 gfx::Transform identity_matrix;
8928 gfx::PointF anchor;
8929 gfx::PointF position;
8930 gfx::Size bounds(100, 100);
8931 SetLayerPropertiesForTesting(root.get(),
8932 identity_matrix,
[email protected]45948712013-09-27 02:46:488933 anchor,
8934 position,
8935 bounds,
[email protected]56fffdd2014-02-11 19:50:578936 true,
[email protected]45948712013-09-27 02:46:488937 false);
8938 root->SetDrawsContent(true);
8939
8940 // This layer structure normally forces render surface due to preserves3d
8941 // behavior.
[email protected]45948712013-09-27 02:46:488942 SetLayerPropertiesForTesting(child1.get(),
8943 identity_matrix,
[email protected]45948712013-09-27 02:46:488944 anchor,
8945 position,
8946 bounds,
[email protected]56fffdd2014-02-11 19:50:578947 false,
8948 true);
[email protected]45948712013-09-27 02:46:488949 child1->SetDrawsContent(true);
8950 SetLayerPropertiesForTesting(child2.get(),
8951 identity_matrix,
[email protected]45948712013-09-27 02:46:488952 anchor,
8953 position,
8954 bounds,
[email protected]56fffdd2014-02-11 19:50:578955 true,
[email protected]45948712013-09-27 02:46:488956 false);
8957 child2->SetDrawsContent(true);
8958 SetLayerPropertiesForTesting(child3.get(),
8959 identity_matrix,
[email protected]45948712013-09-27 02:46:488960 anchor,
8961 position,
8962 bounds,
[email protected]56fffdd2014-02-11 19:50:578963 true,
[email protected]45948712013-09-27 02:46:488964 false);
8965 child3->SetDrawsContent(true);
8966
[email protected]56fffdd2014-02-11 19:50:578967 child2->SetIs3dSorted(true);
8968 child3->SetIs3dSorted(true);
8969
[email protected]45948712013-09-27 02:46:488970 child2->AddChild(child3.Pass());
8971 child1->AddChild(child2.Pass());
8972 root->AddChild(child1.Pass());
8973
8974 {
8975 LayerImplList render_surface_layer_list;
8976 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8977 root.get(), root->bounds(), &render_surface_layer_list);
8978 inputs.can_render_to_separate_surface = true;
8979 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8980
8981 EXPECT_EQ(2u, render_surface_layer_list.size());
8982 }
8983
8984 {
8985 LayerImplList render_surface_layer_list;
8986 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8987 root.get(), root->bounds(), &render_surface_layer_list);
8988 inputs.can_render_to_separate_surface = false;
8989 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8990
8991 EXPECT_EQ(1u, render_surface_layer_list.size());
8992 }
8993}
8994
[email protected]a9aa60a82013-08-29 04:28:268995TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
8996 scoped_refptr<Layer> root = Layer::Create();
8997 scoped_refptr<Layer> render_surface = Layer::Create();
8998 scoped_refptr<LayerWithForcedDrawsContent> child =
8999 make_scoped_refptr(new LayerWithForcedDrawsContent);
9000
9001 root->AddChild(render_surface);
9002 render_surface->AddChild(child);
9003
9004 gfx::Transform identity_transform;
9005 SetLayerPropertiesForTesting(root.get(),
9006 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:269007 gfx::PointF(),
9008 gfx::PointF(),
9009 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579010 true,
[email protected]a9aa60a82013-08-29 04:28:269011 false);
9012 SetLayerPropertiesForTesting(render_surface.get(),
9013 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:269014 gfx::PointF(),
9015 gfx::PointF(),
9016 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579017 false,
9018 true);
[email protected]a9aa60a82013-08-29 04:28:269019 SetLayerPropertiesForTesting(child.get(),
9020 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:269021 gfx::PointF(),
9022 gfx::PointF(),
9023 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:579024 true,
[email protected]a9aa60a82013-08-29 04:28:269025 false);
9026
[email protected]56fffdd2014-02-11 19:50:579027 root->SetShouldFlattenTransform(false);
9028 root->SetIs3dSorted(true);
[email protected]a9aa60a82013-08-29 04:28:269029 render_surface->SetDoubleSided(false);
9030 render_surface->SetForceRenderSurface(true);
9031
9032 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9033 host->SetRootLayer(root);
9034
9035 ExecuteCalculateDrawProperties(root.get());
9036
9037 EXPECT_EQ(2u, render_surface_layer_list()->size());
9038 EXPECT_EQ(1u,
9039 render_surface_layer_list()->at(0)
9040 ->render_surface()->layer_list().size());
9041 EXPECT_EQ(1u,
9042 render_surface_layer_list()->at(1)
9043 ->render_surface()->layer_list().size());
9044
9045 gfx::Transform rotation_transform = identity_transform;
9046 rotation_transform.RotateAboutXAxis(180.0);
9047
9048 render_surface->SetTransform(rotation_transform);
9049
9050 ExecuteCalculateDrawProperties(root.get());
9051
9052 EXPECT_EQ(1u, render_surface_layer_list()->size());
9053 EXPECT_EQ(0u,
9054 render_surface_layer_list()->at(0)
9055 ->render_surface()->layer_list().size());
9056}
9057
[email protected]995708c52013-10-17 20:52:599058TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
9059 // Checks that the simple case (being clipped by a scroll parent that would
9060 // have been processed before you anyhow) results in the right clips.
9061 //
9062 // + root
9063 // + scroll_parent_border
9064 // | + scroll_parent_clip
9065 // | + scroll_parent
9066 // + scroll_child
9067 //
9068 scoped_refptr<Layer> root = Layer::Create();
9069 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9070 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9071 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9072 make_scoped_refptr(new LayerWithForcedDrawsContent);
9073 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9074 make_scoped_refptr(new LayerWithForcedDrawsContent);
9075
9076 root->AddChild(scroll_child);
9077
9078 root->AddChild(scroll_parent_border);
9079 scroll_parent_border->AddChild(scroll_parent_clip);
9080 scroll_parent_clip->AddChild(scroll_parent);
9081
9082 scroll_parent_clip->SetMasksToBounds(true);
9083
9084 scroll_child->SetScrollParent(scroll_parent.get());
9085
9086 gfx::Transform identity_transform;
9087 SetLayerPropertiesForTesting(root.get(),
9088 identity_transform,
[email protected]995708c52013-10-17 20:52:599089 gfx::PointF(),
9090 gfx::PointF(),
9091 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579092 true,
[email protected]995708c52013-10-17 20:52:599093 false);
9094 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9095 identity_transform,
[email protected]995708c52013-10-17 20:52:599096 gfx::PointF(),
9097 gfx::PointF(),
9098 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579099 true,
[email protected]995708c52013-10-17 20:52:599100 false);
9101 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9102 identity_transform,
[email protected]995708c52013-10-17 20:52:599103 gfx::PointF(),
9104 gfx::PointF(),
9105 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579106 true,
[email protected]995708c52013-10-17 20:52:599107 false);
9108 SetLayerPropertiesForTesting(scroll_parent.get(),
9109 identity_transform,
[email protected]995708c52013-10-17 20:52:599110 gfx::PointF(),
9111 gfx::PointF(),
9112 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579113 true,
[email protected]995708c52013-10-17 20:52:599114 false);
9115 SetLayerPropertiesForTesting(scroll_child.get(),
9116 identity_transform,
[email protected]995708c52013-10-17 20:52:599117 gfx::PointF(),
9118 gfx::PointF(),
9119 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579120 true,
[email protected]995708c52013-10-17 20:52:599121 false);
9122
9123 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9124 host->SetRootLayer(root);
9125
9126 ExecuteCalculateDrawProperties(root.get());
9127
9128 EXPECT_TRUE(root->render_surface());
9129
9130 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
9131 scroll_child->clip_rect().ToString());
9132 EXPECT_TRUE(scroll_child->is_clipped());
9133}
9134
9135TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
9136 // Checks that clipping by a scroll parent that follows you in paint order
9137 // still results in correct clipping.
9138 //
9139 // + root
9140 // + scroll_child
9141 // + scroll_parent_border
9142 // + scroll_parent_clip
9143 // + scroll_parent
9144 //
9145 scoped_refptr<Layer> root = Layer::Create();
9146 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9147 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9148 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9149 make_scoped_refptr(new LayerWithForcedDrawsContent);
9150 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9151 make_scoped_refptr(new LayerWithForcedDrawsContent);
9152
9153 root->AddChild(scroll_parent_border);
9154 scroll_parent_border->AddChild(scroll_parent_clip);
9155 scroll_parent_clip->AddChild(scroll_parent);
9156
9157 root->AddChild(scroll_child);
9158
9159 scroll_parent_clip->SetMasksToBounds(true);
9160
9161 scroll_child->SetScrollParent(scroll_parent.get());
9162
9163 gfx::Transform identity_transform;
9164 SetLayerPropertiesForTesting(root.get(),
9165 identity_transform,
[email protected]995708c52013-10-17 20:52:599166 gfx::PointF(),
9167 gfx::PointF(),
9168 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579169 true,
[email protected]995708c52013-10-17 20:52:599170 false);
9171 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9172 identity_transform,
[email protected]995708c52013-10-17 20:52:599173 gfx::PointF(),
9174 gfx::PointF(),
9175 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579176 true,
[email protected]995708c52013-10-17 20:52:599177 false);
9178 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9179 identity_transform,
[email protected]995708c52013-10-17 20:52:599180 gfx::PointF(),
9181 gfx::PointF(),
9182 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579183 true,
[email protected]995708c52013-10-17 20:52:599184 false);
9185 SetLayerPropertiesForTesting(scroll_parent.get(),
9186 identity_transform,
[email protected]995708c52013-10-17 20:52:599187 gfx::PointF(),
9188 gfx::PointF(),
9189 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579190 true,
[email protected]995708c52013-10-17 20:52:599191 false);
9192 SetLayerPropertiesForTesting(scroll_child.get(),
9193 identity_transform,
[email protected]995708c52013-10-17 20:52:599194 gfx::PointF(),
9195 gfx::PointF(),
9196 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579197 true,
[email protected]995708c52013-10-17 20:52:599198 false);
9199
9200 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9201 host->SetRootLayer(root);
9202
9203 ExecuteCalculateDrawProperties(root.get());
9204
9205 EXPECT_TRUE(root->render_surface());
9206
9207 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
9208 scroll_child->clip_rect().ToString());
9209 EXPECT_TRUE(scroll_child->is_clipped());
9210}
9211
9212TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
9213 // Checks that clipping by a scroll parent and scroll grandparent that follow
9214 // you in paint order still results in correct clipping.
9215 //
9216 // + root
9217 // + scroll_child
9218 // + scroll_parent_border
9219 // | + scroll_parent_clip
9220 // | + scroll_parent
9221 // + scroll_grandparent_border
9222 // + scroll_grandparent_clip
9223 // + scroll_grandparent
9224 //
9225 scoped_refptr<Layer> root = Layer::Create();
9226 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9227 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9228 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9229 make_scoped_refptr(new LayerWithForcedDrawsContent);
9230
9231 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
9232 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
9233 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
9234 make_scoped_refptr(new LayerWithForcedDrawsContent);
9235
9236 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9237 make_scoped_refptr(new LayerWithForcedDrawsContent);
9238
9239 root->AddChild(scroll_child);
9240
9241 root->AddChild(scroll_parent_border);
9242 scroll_parent_border->AddChild(scroll_parent_clip);
9243 scroll_parent_clip->AddChild(scroll_parent);
9244
9245 root->AddChild(scroll_grandparent_border);
9246 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
9247 scroll_grandparent_clip->AddChild(scroll_grandparent);
9248
9249 scroll_parent_clip->SetMasksToBounds(true);
9250 scroll_grandparent_clip->SetMasksToBounds(true);
9251
9252 scroll_child->SetScrollParent(scroll_parent.get());
9253 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
9254
9255 gfx::Transform identity_transform;
9256 SetLayerPropertiesForTesting(root.get(),
9257 identity_transform,
[email protected]995708c52013-10-17 20:52:599258 gfx::PointF(),
9259 gfx::PointF(),
9260 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579261 true,
[email protected]995708c52013-10-17 20:52:599262 false);
9263 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
9264 identity_transform,
[email protected]995708c52013-10-17 20:52:599265 gfx::PointF(),
9266 gfx::PointF(),
9267 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579268 true,
[email protected]995708c52013-10-17 20:52:599269 false);
9270 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
9271 identity_transform,
[email protected]995708c52013-10-17 20:52:599272 gfx::PointF(),
9273 gfx::PointF(),
9274 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:579275 true,
[email protected]995708c52013-10-17 20:52:599276 false);
9277 SetLayerPropertiesForTesting(scroll_grandparent.get(),
9278 identity_transform,
[email protected]995708c52013-10-17 20:52:599279 gfx::PointF(),
9280 gfx::PointF(),
9281 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579282 true,
[email protected]995708c52013-10-17 20:52:599283 false);
9284 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9285 identity_transform,
[email protected]995708c52013-10-17 20:52:599286 gfx::PointF(),
9287 gfx::PointF(),
9288 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579289 true,
[email protected]995708c52013-10-17 20:52:599290 false);
9291 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9292 identity_transform,
[email protected]995708c52013-10-17 20:52:599293 gfx::PointF(),
9294 gfx::PointF(),
9295 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579296 true,
[email protected]995708c52013-10-17 20:52:599297 false);
9298 SetLayerPropertiesForTesting(scroll_parent.get(),
9299 identity_transform,
[email protected]995708c52013-10-17 20:52:599300 gfx::PointF(),
9301 gfx::PointF(),
9302 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579303 true,
[email protected]995708c52013-10-17 20:52:599304 false);
9305 SetLayerPropertiesForTesting(scroll_child.get(),
9306 identity_transform,
[email protected]995708c52013-10-17 20:52:599307 gfx::PointF(),
9308 gfx::PointF(),
9309 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579310 true,
[email protected]995708c52013-10-17 20:52:599311 false);
9312
9313 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9314 host->SetRootLayer(root);
9315
9316 ExecuteCalculateDrawProperties(root.get());
9317
9318 EXPECT_TRUE(root->render_surface());
9319
9320 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
9321 scroll_child->clip_rect().ToString());
9322 EXPECT_TRUE(scroll_child->is_clipped());
9323
9324 // Despite the fact that we visited the above layers out of order to get the
9325 // correct clip, the layer lists should be unaffected.
9326 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
9327 EXPECT_EQ(scroll_child.get(),
9328 root->render_surface()->layer_list().at(0));
9329 EXPECT_EQ(scroll_parent.get(),
9330 root->render_surface()->layer_list().at(1));
9331 EXPECT_EQ(scroll_grandparent.get(),
9332 root->render_surface()->layer_list().at(2));
9333}
9334
9335TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
9336 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:229337 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:599338 // + root
9339 // + scroll_child
9340 // + scroll_parent_border
9341 // + scroll_parent_clip
9342 // + scroll_parent
9343 // + render_surface1
9344 // + scroll_grandparent_border
9345 // + scroll_grandparent_clip
9346 // + scroll_grandparent
9347 // + render_surface2
9348 //
[email protected]44d8e84c2013-10-19 19:13:229349 scoped_refptr<LayerWithForcedDrawsContent> root =
9350 make_scoped_refptr(new LayerWithForcedDrawsContent);
[email protected]995708c52013-10-17 20:52:599351
9352 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9353 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9354 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9355 make_scoped_refptr(new LayerWithForcedDrawsContent);
9356 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
9357 make_scoped_refptr(new LayerWithForcedDrawsContent);
9358
9359 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
9360 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
9361 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
9362 make_scoped_refptr(new LayerWithForcedDrawsContent);
9363 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
9364 make_scoped_refptr(new LayerWithForcedDrawsContent);
9365
9366 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9367 make_scoped_refptr(new LayerWithForcedDrawsContent);
9368
9369 root->AddChild(scroll_child);
9370
9371 root->AddChild(scroll_parent_border);
9372 scroll_parent_border->AddChild(scroll_parent_clip);
9373 scroll_parent_clip->AddChild(scroll_parent);
9374 scroll_parent->AddChild(render_surface2);
9375
9376 root->AddChild(scroll_grandparent_border);
9377 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
9378 scroll_grandparent_clip->AddChild(scroll_grandparent);
9379 scroll_grandparent->AddChild(render_surface1);
9380
9381 scroll_parent_clip->SetMasksToBounds(true);
9382 scroll_grandparent_clip->SetMasksToBounds(true);
9383
9384 scroll_child->SetScrollParent(scroll_parent.get());
9385 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
9386
9387 render_surface1->SetForceRenderSurface(true);
9388 render_surface2->SetForceRenderSurface(true);
9389
9390 gfx::Transform identity_transform;
9391 SetLayerPropertiesForTesting(root.get(),
9392 identity_transform,
[email protected]995708c52013-10-17 20:52:599393 gfx::PointF(),
9394 gfx::PointF(),
9395 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579396 true,
[email protected]995708c52013-10-17 20:52:599397 false);
9398 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
9399 identity_transform,
[email protected]995708c52013-10-17 20:52:599400 gfx::PointF(),
9401 gfx::PointF(),
9402 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579403 true,
[email protected]995708c52013-10-17 20:52:599404 false);
9405 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
9406 identity_transform,
[email protected]995708c52013-10-17 20:52:599407 gfx::PointF(),
9408 gfx::PointF(),
9409 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:579410 true,
[email protected]995708c52013-10-17 20:52:599411 false);
9412 SetLayerPropertiesForTesting(scroll_grandparent.get(),
9413 identity_transform,
[email protected]995708c52013-10-17 20:52:599414 gfx::PointF(),
9415 gfx::PointF(),
9416 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579417 true,
[email protected]995708c52013-10-17 20:52:599418 false);
9419 SetLayerPropertiesForTesting(render_surface1.get(),
9420 identity_transform,
[email protected]995708c52013-10-17 20:52:599421 gfx::PointF(),
9422 gfx::PointF(),
9423 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579424 true,
[email protected]995708c52013-10-17 20:52:599425 false);
9426 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9427 identity_transform,
[email protected]995708c52013-10-17 20:52:599428 gfx::PointF(),
9429 gfx::PointF(),
9430 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579431 true,
[email protected]995708c52013-10-17 20:52:599432 false);
9433 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9434 identity_transform,
[email protected]995708c52013-10-17 20:52:599435 gfx::PointF(),
9436 gfx::PointF(),
9437 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579438 true,
[email protected]995708c52013-10-17 20:52:599439 false);
9440 SetLayerPropertiesForTesting(scroll_parent.get(),
9441 identity_transform,
[email protected]995708c52013-10-17 20:52:599442 gfx::PointF(),
9443 gfx::PointF(),
9444 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579445 true,
[email protected]995708c52013-10-17 20:52:599446 false);
9447 SetLayerPropertiesForTesting(render_surface2.get(),
9448 identity_transform,
[email protected]995708c52013-10-17 20:52:599449 gfx::PointF(),
9450 gfx::PointF(),
9451 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579452 true,
[email protected]995708c52013-10-17 20:52:599453 false);
9454 SetLayerPropertiesForTesting(scroll_child.get(),
9455 identity_transform,
[email protected]995708c52013-10-17 20:52:599456 gfx::PointF(),
9457 gfx::PointF(),
9458 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579459 true,
[email protected]995708c52013-10-17 20:52:599460 false);
9461
9462 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9463 host->SetRootLayer(root);
9464
9465 RenderSurfaceLayerList render_surface_layer_list;
9466 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
9467 root.get(),
9468 root->bounds(),
9469 identity_transform,
9470 &render_surface_layer_list);
9471
9472 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9473
9474 EXPECT_TRUE(root->render_surface());
9475
9476 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
9477 scroll_child->clip_rect().ToString());
9478 EXPECT_TRUE(scroll_child->is_clipped());
9479
9480 // Despite the fact that we had to process the layers out of order to get the
9481 // right clip, our render_surface_layer_list's order should be unaffected.
9482 EXPECT_EQ(3u, render_surface_layer_list.size());
9483 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
9484 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
9485 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
[email protected]44d8e84c2013-10-19 19:13:229486 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
9487 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
9488 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:599489}
9490
9491TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) {
9492 // We rearrange layer list contributions if we have to visit children out of
9493 // order, but it should be a 'stable' rearrangement. That is, the layer list
9494 // additions for a single layer should not be reordered, though their position
9495 // wrt to the contributions due to a sibling may vary.
9496 //
9497 // + root
9498 // + scroll_child
9499 // + top_content
9500 // + bottom_content
9501 // + scroll_parent_border
9502 // + scroll_parent_clip
9503 // + scroll_parent
9504 //
9505 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:459506 TestSharedBitmapManager shared_bitmap_manager;
9507 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]995708c52013-10-17 20:52:599508 host_impl.CreatePendingTree();
9509 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9510 scoped_ptr<LayerImpl> scroll_parent_border =
9511 LayerImpl::Create(host_impl.active_tree(), 2);
9512 scoped_ptr<LayerImpl> scroll_parent_clip =
9513 LayerImpl::Create(host_impl.active_tree(), 3);
9514 scoped_ptr<LayerImpl> scroll_parent =
9515 LayerImpl::Create(host_impl.active_tree(), 4);
9516 scoped_ptr<LayerImpl> scroll_child =
9517 LayerImpl::Create(host_impl.active_tree(), 5);
9518 scoped_ptr<LayerImpl> bottom_content =
9519 LayerImpl::Create(host_impl.active_tree(), 6);
9520 scoped_ptr<LayerImpl> top_content =
9521 LayerImpl::Create(host_impl.active_tree(), 7);
9522
9523 scroll_parent_clip->SetMasksToBounds(true);
9524
9525 scroll_child->SetScrollParent(scroll_parent.get());
9526 scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>);
9527 scroll_children->insert(scroll_child.get());
9528 scroll_parent->SetScrollChildren(scroll_children.release());
9529
9530 scroll_child->SetDrawsContent(true);
9531 scroll_parent->SetDrawsContent(true);
9532 top_content->SetDrawsContent(true);
9533 bottom_content->SetDrawsContent(true);
9534
9535 gfx::Transform identity_transform;
9536 gfx::Transform top_transform;
9537 top_transform.Translate3d(0.0, 0.0, 5.0);
9538 gfx::Transform bottom_transform;
9539 bottom_transform.Translate3d(0.0, 0.0, 3.0);
9540
9541 SetLayerPropertiesForTesting(root.get(),
9542 identity_transform,
[email protected]995708c52013-10-17 20:52:599543 gfx::PointF(),
9544 gfx::PointF(),
9545 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579546 true,
[email protected]995708c52013-10-17 20:52:599547 false);
9548 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9549 identity_transform,
[email protected]995708c52013-10-17 20:52:599550 gfx::PointF(),
9551 gfx::PointF(),
9552 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579553 true,
[email protected]995708c52013-10-17 20:52:599554 false);
9555 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9556 identity_transform,
[email protected]995708c52013-10-17 20:52:599557 gfx::PointF(),
9558 gfx::PointF(),
9559 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579560 true,
[email protected]995708c52013-10-17 20:52:599561 false);
9562 SetLayerPropertiesForTesting(scroll_parent.get(),
9563 identity_transform,
[email protected]995708c52013-10-17 20:52:599564 gfx::PointF(),
9565 gfx::PointF(),
9566 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579567 true,
[email protected]995708c52013-10-17 20:52:599568 false);
9569 SetLayerPropertiesForTesting(scroll_child.get(),
9570 identity_transform,
[email protected]995708c52013-10-17 20:52:599571 gfx::PointF(),
9572 gfx::PointF(),
9573 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579574 true,
[email protected]995708c52013-10-17 20:52:599575 false);
9576 SetLayerPropertiesForTesting(top_content.get(),
9577 top_transform,
[email protected]995708c52013-10-17 20:52:599578 gfx::PointF(),
9579 gfx::PointF(),
9580 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579581 false,
9582 true);
[email protected]995708c52013-10-17 20:52:599583 SetLayerPropertiesForTesting(bottom_content.get(),
9584 bottom_transform,
[email protected]995708c52013-10-17 20:52:599585 gfx::PointF(),
9586 gfx::PointF(),
9587 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579588 false,
9589 true);
[email protected]995708c52013-10-17 20:52:599590
[email protected]56fffdd2014-02-11 19:50:579591 scroll_child->SetShouldFlattenTransform(false);
9592 scroll_child->SetIs3dSorted(true);
[email protected]995708c52013-10-17 20:52:599593
9594 scroll_child->AddChild(top_content.Pass());
9595 scroll_child->AddChild(bottom_content.Pass());
9596 root->AddChild(scroll_child.Pass());
9597
9598 scroll_parent_clip->AddChild(scroll_parent.Pass());
9599 scroll_parent_border->AddChild(scroll_parent_clip.Pass());
9600 root->AddChild(scroll_parent_border.Pass());
9601
9602 LayerImplList render_surface_layer_list;
9603 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9604 root.get(), root->bounds(), &render_surface_layer_list);
9605
9606 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9607
9608 EXPECT_TRUE(root->render_surface());
9609
9610 // If we don't sort by depth and let the layers get added in the order they
9611 // would normally be visited in, then layers 6 and 7 will be out of order. In
9612 // other words, although we've had to shift 5, 6, and 7 to appear before 4
9613 // in the list (because of the scroll parent relationship), this should not
9614 // have an effect on the the order of 5, 6, and 7 (which had been reordered
9615 // due to layer sorting).
9616 EXPECT_EQ(4u, root->render_surface()->layer_list().size());
9617 EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id());
9618 EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id());
9619 EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id());
9620 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
9621}
9622
[email protected]d81752b2013-10-25 08:32:239623TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
9624 // This test verifies that a scrolling layer that gets snapped to
9625 // integer coordinates doesn't move a fixed position child.
9626 //
9627 // + root
9628 // + container
9629 // + scroller
9630 // + fixed
9631 //
9632 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:459633 TestSharedBitmapManager shared_bitmap_manager;
9634 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]d81752b2013-10-25 08:32:239635 host_impl.CreatePendingTree();
9636 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9637 scoped_ptr<LayerImpl> container =
9638 LayerImpl::Create(host_impl.active_tree(), 2);
9639 LayerImpl* container_layer = container.get();
9640 scoped_ptr<LayerImpl> scroller =
9641 LayerImpl::Create(host_impl.active_tree(), 3);
9642 LayerImpl* scroll_layer = scroller.get();
9643 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
9644 LayerImpl* fixed_layer = fixed.get();
9645
9646 container->SetIsContainerForFixedPositionLayers(true);
9647
9648 LayerPositionConstraint constraint;
9649 constraint.set_is_fixed_position(true);
9650 fixed->SetPositionConstraint(constraint);
9651
[email protected]adeda572014-01-31 00:49:479652 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:239653
9654 gfx::Transform identity_transform;
9655 gfx::Transform container_transform;
9656 container_transform.Translate3d(10.0, 20.0, 0.0);
9657 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
9658
9659 SetLayerPropertiesForTesting(root.get(),
9660 identity_transform,
[email protected]d81752b2013-10-25 08:32:239661 gfx::PointF(),
9662 gfx::PointF(),
9663 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579664 true,
[email protected]d81752b2013-10-25 08:32:239665 false);
9666 SetLayerPropertiesForTesting(container.get(),
9667 container_transform,
[email protected]d81752b2013-10-25 08:32:239668 gfx::PointF(),
9669 gfx::PointF(),
9670 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579671 true,
[email protected]d81752b2013-10-25 08:32:239672 false);
9673 SetLayerPropertiesForTesting(scroller.get(),
9674 identity_transform,
[email protected]d81752b2013-10-25 08:32:239675 gfx::PointF(),
9676 gfx::PointF(),
9677 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579678 true,
[email protected]d81752b2013-10-25 08:32:239679 false);
9680 SetLayerPropertiesForTesting(fixed.get(),
9681 identity_transform,
[email protected]d81752b2013-10-25 08:32:239682 gfx::PointF(),
9683 gfx::PointF(),
9684 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579685 true,
[email protected]d81752b2013-10-25 08:32:239686 false);
9687
9688 scroller->AddChild(fixed.Pass());
9689 container->AddChild(scroller.Pass());
9690 root->AddChild(container.Pass());
9691
9692 // Rounded to integers already.
9693 {
9694 gfx::Vector2dF scroll_delta(3.0, 5.0);
9695 scroll_layer->SetScrollDelta(scroll_delta);
9696
9697 LayerImplList render_surface_layer_list;
9698 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9699 root.get(), root->bounds(), &render_surface_layer_list);
9700 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9701
9702 EXPECT_TRANSFORMATION_MATRIX_EQ(
9703 container_layer->draw_properties().screen_space_transform,
9704 fixed_layer->draw_properties().screen_space_transform);
9705 EXPECT_VECTOR_EQ(
9706 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9707 container_offset);
9708 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
9709 .screen_space_transform.To2dTranslation(),
9710 container_offset - scroll_delta);
9711 }
9712
9713 // Scroll delta requiring rounding.
9714 {
9715 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
9716 scroll_layer->SetScrollDelta(scroll_delta);
9717
9718 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
9719
9720 LayerImplList render_surface_layer_list;
9721 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9722 root.get(), root->bounds(), &render_surface_layer_list);
9723 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9724
9725 EXPECT_TRANSFORMATION_MATRIX_EQ(
9726 container_layer->draw_properties().screen_space_transform,
9727 fixed_layer->draw_properties().screen_space_transform);
9728 EXPECT_VECTOR_EQ(
9729 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9730 container_offset);
9731 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
9732 .screen_space_transform.To2dTranslation(),
9733 container_offset - rounded_scroll_delta);
9734 }
[email protected]cf15ad7b2014-04-02 03:59:269735
9736 // Scale is applied earlier in the tree.
9737 {
9738 gfx::Transform scaled_container_transform = container_transform;
9739 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
9740 container_layer->SetTransform(scaled_container_transform);
9741
9742 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
9743 scroll_layer->SetScrollDelta(scroll_delta);
9744
9745 LayerImplList render_surface_layer_list;
9746 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9747 root.get(), root->bounds(), &render_surface_layer_list);
9748 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9749
9750 EXPECT_TRANSFORMATION_MATRIX_EQ(
9751 container_layer->draw_properties().screen_space_transform,
9752 fixed_layer->draw_properties().screen_space_transform);
9753 EXPECT_VECTOR_EQ(
9754 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9755 container_offset);
9756
9757 container_layer->SetTransform(container_transform);
9758 }
9759
9760 // Scale is applied on the scroll layer itself.
9761 {
9762 gfx::Transform scale_transform;
9763 scale_transform.Scale3d(3.0, 3.0, 1.0);
9764 scroll_layer->SetTransform(scale_transform);
9765
9766 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
9767 scroll_layer->SetScrollDelta(scroll_delta);
9768
9769 LayerImplList render_surface_layer_list;
9770 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9771 root.get(), root->bounds(), &render_surface_layer_list);
9772 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9773
9774 EXPECT_VECTOR_EQ(
9775 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9776 container_offset);
9777
9778 scroll_layer->SetTransform(identity_transform);
9779 }
[email protected]d81752b2013-10-25 08:32:239780}
9781
[email protected]ba565742012-11-10 09:29:489782} // namespace
9783} // namespace cc