blob: 377dc868edb081bc5435c4e1aa22a79802e1238e [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:
184 LayerWithForcedDrawsContent() : Layer() {}
[email protected]94f206c12012-08-25 00:09:14185
[email protected]fb661802013-03-25 01:59:32186 virtual bool DrawsContent() const OVERRIDE;
[email protected]d58499a2012-10-09 22:27:47187
[email protected]fb661802013-03-25 01:59:32188 private:
189 virtual ~LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:14190};
191
[email protected]fb661802013-03-25 01:59:32192bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:44193
[email protected]96baf3e2012-10-22 23:09:55194class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:32195 public:
196 MockContentLayerClient() {}
197 virtual ~MockContentLayerClient() {}
198 virtual void PaintContents(SkCanvas* canvas,
[email protected]0023fc72014-01-10 20:05:06199 const gfx::Rect& clip,
[email protected]fb661802013-03-25 01:59:32200 gfx::RectF* opaque) OVERRIDE {}
201 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
[email protected]1d96e032014-03-25 05:59:08202 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
[email protected]f34a24232012-09-20 22:59:55203};
204
[email protected]fb661802013-03-25 01:59:32205scoped_refptr<ContentLayer> CreateDrawableContentLayer(
206 ContentLayerClient* delegate) {
207 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate);
208 to_return->SetIsDrawable(true);
209 return to_return;
[email protected]f34a24232012-09-20 22:59:55210}
211
[email protected]989386c2013-07-18 21:37:23212#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
213 do { \
214 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
215 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:47216 } while (false)
217
[email protected]989386c2013-07-18 21:37:23218TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32219 // Sanity check: For layers positioned at zero, with zero size,
220 // and with identity transforms, then the draw transform,
221 // screen space transform, and the hierarchy passed on to children
222 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14223
[email protected]fb661802013-03-25 01:59:32224 scoped_refptr<Layer> parent = Layer::Create();
225 scoped_refptr<Layer> child = Layer::Create();
226 scoped_refptr<Layer> grand_child = Layer::Create();
227 parent->AddChild(child);
228 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14229
[email protected]d600df7d2013-08-03 02:34:28230 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
231 host->SetRootLayer(parent);
232
[email protected]fb661802013-03-25 01:59:32233 gfx::Transform identity_matrix;
234 SetLayerPropertiesForTesting(parent.get(),
235 identity_matrix,
[email protected]fb661802013-03-25 01:59:32236 gfx::PointF(),
237 gfx::PointF(),
238 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:57239 true,
[email protected]fb661802013-03-25 01:59:32240 false);
241 SetLayerPropertiesForTesting(child.get(),
242 identity_matrix,
[email protected]fb661802013-03-25 01:59:32243 gfx::PointF(),
244 gfx::PointF(),
245 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57246 true,
[email protected]fb661802013-03-25 01:59:32247 false);
248 SetLayerPropertiesForTesting(grand_child.get(),
249 identity_matrix,
[email protected]fb661802013-03-25 01:59:32250 gfx::PointF(),
251 gfx::PointF(),
252 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57253 true,
[email protected]fb661802013-03-25 01:59:32254 false);
[email protected]94f206c12012-08-25 00:09:14255
[email protected]fb661802013-03-25 01:59:32256 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14257
[email protected]fb661802013-03-25 01:59:32258 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
259 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
260 child->screen_space_transform());
261 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
262 grand_child->draw_transform());
263 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
264 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14265}
266
[email protected]989386c2013-07-18 21:37:23267TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32268 gfx::Transform identity_matrix;
269 scoped_refptr<Layer> layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:14270
[email protected]fb661802013-03-25 01:59:32271 scoped_refptr<Layer> root = Layer::Create();
272 SetLayerPropertiesForTesting(root.get(),
273 identity_matrix,
[email protected]fb661802013-03-25 01:59:32274 gfx::PointF(),
275 gfx::PointF(),
276 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57277 true,
[email protected]fb661802013-03-25 01:59:32278 false);
279 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42280
[email protected]d600df7d2013-08-03 02:34:28281 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
282 host->SetRootLayer(root);
283
[email protected]fb661802013-03-25 01:59:32284 // Case 2: Setting the bounds of the layer should not affect either the draw
285 // transform or the screenspace transform.
286 gfx::Transform translation_to_center;
287 translation_to_center.Translate(5.0, 6.0);
288 SetLayerPropertiesForTesting(layer.get(),
289 identity_matrix,
[email protected]fb661802013-03-25 01:59:32290 gfx::PointF(),
291 gfx::PointF(),
292 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57293 true,
[email protected]fb661802013-03-25 01:59:32294 false);
295 ExecuteCalculateDrawProperties(root.get());
296 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
297 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
298 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14299
[email protected]fb661802013-03-25 01:59:32300 // Case 3: The anchor point by itself (without a layer transform) should have
301 // no effect on the transforms.
302 SetLayerPropertiesForTesting(layer.get(),
303 identity_matrix,
[email protected]fb661802013-03-25 01:59:32304 gfx::PointF(0.25f, 0.25f),
305 gfx::PointF(),
306 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57307 true,
[email protected]fb661802013-03-25 01:59:32308 false);
309 ExecuteCalculateDrawProperties(root.get());
310 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
311 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
312 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14313
[email protected]fb661802013-03-25 01:59:32314 // Case 4: A change in actual position affects both the draw transform and
315 // screen space transform.
316 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05317 position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32318 SetLayerPropertiesForTesting(layer.get(),
319 identity_matrix,
[email protected]fb661802013-03-25 01:59:32320 gfx::PointF(0.25f, 0.25f),
321 gfx::PointF(0.f, 1.2f),
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(position_transform, layer->draw_transform());
327 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
328 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14329
[email protected]fb661802013-03-25 01:59:32330 // Case 5: In the correct sequence of transforms, the layer transform should
331 // pre-multiply the translation_to_center. This is easily tested by using a
332 // scale transform, because scale and translation are not commutative.
333 gfx::Transform layer_transform;
334 layer_transform.Scale3d(2.0, 2.0, 1.0);
335 SetLayerPropertiesForTesting(layer.get(),
336 layer_transform,
[email protected]fb661802013-03-25 01:59:32337 gfx::PointF(),
338 gfx::PointF(),
339 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57340 true,
[email protected]fb661802013-03-25 01:59:32341 false);
342 ExecuteCalculateDrawProperties(root.get());
343 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
344 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
345 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14346
[email protected]fb661802013-03-25 01:59:32347 // Case 6: The layer transform should occur with respect to the anchor point.
348 gfx::Transform translation_to_anchor;
349 translation_to_anchor.Translate(5.0, 0.0);
350 gfx::Transform expected_result =
351 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
352 SetLayerPropertiesForTesting(layer.get(),
353 layer_transform,
[email protected]fb661802013-03-25 01:59:32354 gfx::PointF(0.5f, 0.f),
355 gfx::PointF(),
356 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57357 true,
[email protected]fb661802013-03-25 01:59:32358 false);
359 ExecuteCalculateDrawProperties(root.get());
360 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
361 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
362 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14363
[email protected]fb661802013-03-25 01:59:32364 // Case 7: Verify that position pre-multiplies the layer transform. The
365 // current implementation of CalculateDrawProperties does this implicitly, but
366 // it is still worth testing to detect accidental regressions.
367 expected_result = position_transform * translation_to_anchor *
368 layer_transform * Inverse(translation_to_anchor);
369 SetLayerPropertiesForTesting(layer.get(),
370 layer_transform,
[email protected]fb661802013-03-25 01:59:32371 gfx::PointF(0.5f, 0.f),
372 gfx::PointF(0.f, 1.2f),
373 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57374 true,
[email protected]fb661802013-03-25 01:59:32375 false);
376 ExecuteCalculateDrawProperties(root.get());
377 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
378 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
379 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14380}
381
[email protected]989386c2013-07-18 21:37:23382TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
[email protected]fb661802013-03-25 01:59:32383 const gfx::Vector2d kScrollOffset(50, 100);
384 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01385 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32386 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
387 -kScrollOffset.y());
388 const float kPageScale = 0.888f;
389 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20390
[email protected]fb661802013-03-25 01:59:32391 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:45392 TestSharedBitmapManager shared_bitmap_manager;
393 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]657b24c2013-03-06 09:01:20394
[email protected]fb661802013-03-25 01:59:32395 gfx::Transform identity_matrix;
396 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
397 LayerImpl::Create(host_impl.active_tree(), 1));
398 LayerImpl* sublayer = sublayer_scoped_ptr.get();
399 sublayer->SetContentsScale(kPageScale * kDeviceScale,
400 kPageScale * kDeviceScale);
401 SetLayerPropertiesForTesting(sublayer,
402 identity_matrix,
[email protected]fb661802013-03-25 01:59:32403 gfx::Point(),
404 gfx::PointF(),
405 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:57406 true,
[email protected]fb661802013-03-25 01:59:32407 false);
[email protected]657b24c2013-03-06 09:01:20408
[email protected]adeda572014-01-31 00:49:47409 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32410 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47411 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
[email protected]fb661802013-03-25 01:59:32412 SetLayerPropertiesForTesting(scroll_layer,
413 identity_matrix,
[email protected]fb661802013-03-25 01:59:32414 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47415 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32416 gfx::Size(10, 20),
[email protected]56fffdd2014-02-11 19:50:57417 true,
[email protected]fb661802013-03-25 01:59:32418 false);
[email protected]adeda572014-01-31 00:49:47419 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
420 LayerImpl::Create(host_impl.active_tree(), 4));
421 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
422
423 scroll_layer->SetScrollClipLayer(clip_layer->id());
424 clip_layer->SetBounds(
425 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
426 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
427 scroll_layer->SetScrollClipLayer(clip_layer->id());
[email protected]fb661802013-03-25 01:59:32428 scroll_layer->SetScrollDelta(kScrollDelta);
429 gfx::Transform impl_transform;
[email protected]fb661802013-03-25 01:59:32430 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
[email protected]adeda572014-01-31 00:49:47431 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
432 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
433 scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20434
[email protected]fb661802013-03-25 01:59:32435 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
436 SetLayerPropertiesForTesting(root.get(),
437 identity_matrix,
[email protected]fb661802013-03-25 01:59:32438 gfx::PointF(),
439 gfx::PointF(),
440 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:57441 true,
[email protected]fb661802013-03-25 01:59:32442 false);
[email protected]adeda572014-01-31 00:49:47443 root->AddChild(clip_layer_scoped_ptr.Pass());
[email protected]657b24c2013-03-06 09:01:20444
[email protected]f2136262013-04-26 21:10:19445 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32446 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32447 gfx::Transform expected_transform = identity_matrix;
448 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
449 sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
450 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
451 MathUtil::Round(sub_layer_screen_position.y()));
452 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
453 sublayer->draw_transform());
454 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
455 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20456
[email protected]fb661802013-03-25 01:59:32457 gfx::Transform arbitrary_translate;
458 const float kTranslateX = 10.6f;
459 const float kTranslateY = 20.6f;
460 arbitrary_translate.Translate(kTranslateX, kTranslateY);
461 SetLayerPropertiesForTesting(scroll_layer,
462 arbitrary_translate,
[email protected]fb661802013-03-25 01:59:32463 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47464 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32465 gfx::Size(10, 20),
[email protected]56fffdd2014-02-11 19:50:57466 true,
[email protected]fb661802013-03-25 01:59:32467 false);
[email protected]f2136262013-04-26 21:10:19468 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32469 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32470 expected_transform.MakeIdentity();
471 expected_transform.Translate(
472 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
473 sub_layer_screen_position.x()),
474 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
475 sub_layer_screen_position.y()));
476 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
477 sublayer->draw_transform());
[email protected]657b24c2013-03-06 09:01:20478}
479
[email protected]989386c2013-07-18 21:37:23480TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32481 gfx::Transform identity_matrix;
482 scoped_refptr<Layer> root = Layer::Create();
483 scoped_refptr<Layer> parent = Layer::Create();
484 scoped_refptr<Layer> child = Layer::Create();
485 scoped_refptr<Layer> grand_child = Layer::Create();
486 root->AddChild(parent);
487 parent->AddChild(child);
488 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14489
[email protected]d600df7d2013-08-03 02:34:28490 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
491 host->SetRootLayer(root);
492
[email protected]fb661802013-03-25 01:59:32493 // One-time setup of root layer
494 SetLayerPropertiesForTesting(root.get(),
495 identity_matrix,
[email protected]fb661802013-03-25 01:59:32496 gfx::PointF(),
497 gfx::PointF(),
498 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57499 true,
[email protected]fb661802013-03-25 01:59:32500 false);
[email protected]ecc12622012-10-30 20:45:42501
[email protected]fb661802013-03-25 01:59:32502 // Case 1: parent's anchor point should not affect child or grand_child.
503 SetLayerPropertiesForTesting(parent.get(),
504 identity_matrix,
[email protected]fb661802013-03-25 01:59:32505 gfx::PointF(0.25f, 0.25f),
506 gfx::PointF(),
507 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57508 true,
[email protected]fb661802013-03-25 01:59:32509 false);
510 SetLayerPropertiesForTesting(child.get(),
511 identity_matrix,
[email protected]fb661802013-03-25 01:59:32512 gfx::PointF(),
513 gfx::PointF(),
514 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57515 true,
[email protected]fb661802013-03-25 01:59:32516 false);
517 SetLayerPropertiesForTesting(grand_child.get(),
518 identity_matrix,
[email protected]fb661802013-03-25 01:59:32519 gfx::PointF(),
520 gfx::PointF(),
521 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57522 true,
[email protected]fb661802013-03-25 01:59:32523 false);
524 ExecuteCalculateDrawProperties(root.get());
525 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
526 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
527 child->screen_space_transform());
528 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
529 grand_child->draw_transform());
530 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
531 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14532
[email protected]fb661802013-03-25 01:59:32533 // Case 2: parent's position affects child and grand_child.
534 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05535 parent_position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32536 SetLayerPropertiesForTesting(parent.get(),
537 identity_matrix,
[email protected]fb661802013-03-25 01:59:32538 gfx::PointF(0.25f, 0.25f),
539 gfx::PointF(0.f, 1.2f),
540 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57541 true,
[email protected]fb661802013-03-25 01:59:32542 false);
543 SetLayerPropertiesForTesting(child.get(),
544 identity_matrix,
[email protected]fb661802013-03-25 01:59:32545 gfx::PointF(),
546 gfx::PointF(),
547 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57548 true,
[email protected]fb661802013-03-25 01:59:32549 false);
550 SetLayerPropertiesForTesting(grand_child.get(),
551 identity_matrix,
[email protected]fb661802013-03-25 01:59:32552 gfx::PointF(),
553 gfx::PointF(),
554 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57555 true,
[email protected]fb661802013-03-25 01:59:32556 false);
557 ExecuteCalculateDrawProperties(root.get());
558 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
559 child->draw_transform());
560 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
561 child->screen_space_transform());
562 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
563 grand_child->draw_transform());
564 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
565 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14566
[email protected]fb661802013-03-25 01:59:32567 // Case 3: parent's local transform affects child and grandchild
568 gfx::Transform parent_layer_transform;
569 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
570 gfx::Transform parent_translation_to_anchor;
571 parent_translation_to_anchor.Translate(2.5, 3.0);
572 gfx::Transform parent_composite_transform =
573 parent_translation_to_anchor * parent_layer_transform *
574 Inverse(parent_translation_to_anchor);
575 SetLayerPropertiesForTesting(parent.get(),
576 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32577 gfx::PointF(0.25f, 0.25f),
578 gfx::PointF(),
579 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57580 true,
[email protected]fb661802013-03-25 01:59:32581 false);
582 SetLayerPropertiesForTesting(child.get(),
583 identity_matrix,
[email protected]fb661802013-03-25 01:59:32584 gfx::PointF(),
585 gfx::PointF(),
586 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57587 true,
[email protected]fb661802013-03-25 01:59:32588 false);
589 SetLayerPropertiesForTesting(grand_child.get(),
590 identity_matrix,
[email protected]fb661802013-03-25 01:59:32591 gfx::PointF(),
592 gfx::PointF(),
593 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57594 true,
[email protected]fb661802013-03-25 01:59:32595 false);
596 ExecuteCalculateDrawProperties(root.get());
597 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
598 child->draw_transform());
599 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
600 child->screen_space_transform());
601 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
602 grand_child->draw_transform());
603 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
604 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14605}
606
[email protected]989386c2013-07-18 21:37:23607TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
[email protected]fb661802013-03-25 01:59:32608 scoped_refptr<Layer> root = Layer::Create();
609 scoped_refptr<Layer> parent = Layer::Create();
610 scoped_refptr<Layer> child = Layer::Create();
611 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
612 make_scoped_refptr(new LayerWithForcedDrawsContent());
613 root->AddChild(parent);
614 parent->AddChild(child);
615 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14616
[email protected]d600df7d2013-08-03 02:34:28617 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
618 host->SetRootLayer(root);
619
[email protected]fb661802013-03-25 01:59:32620 // One-time setup of root layer
621 gfx::Transform identity_matrix;
622 SetLayerPropertiesForTesting(root.get(),
623 identity_matrix,
[email protected]fb661802013-03-25 01:59:32624 gfx::PointF(),
625 gfx::PointF(),
626 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57627 true,
[email protected]fb661802013-03-25 01:59:32628 false);
[email protected]ecc12622012-10-30 20:45:42629
[email protected]fb661802013-03-25 01:59:32630 // Child is set up so that a new render surface should be created.
631 child->SetOpacity(0.5f);
632 child->SetForceRenderSurface(true);
[email protected]94f206c12012-08-25 00:09:14633
[email protected]fb661802013-03-25 01:59:32634 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05635 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32636 gfx::Transform parent_translation_to_anchor;
637 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44638
[email protected]fb661802013-03-25 01:59:32639 gfx::Transform parent_composite_transform =
640 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39641 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32642 gfx::Vector2dF parent_composite_scale =
643 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
644 1.f);
645 gfx::Transform surface_sublayer_transform;
646 surface_sublayer_transform.Scale(parent_composite_scale.x(),
647 parent_composite_scale.y());
648 gfx::Transform surface_sublayer_composite_transform =
649 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14650
[email protected]fb661802013-03-25 01:59:32651 // Child's render surface should not exist yet.
652 ASSERT_FALSE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:14653
[email protected]fb661802013-03-25 01:59:32654 SetLayerPropertiesForTesting(parent.get(),
655 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32656 gfx::PointF(0.25f, 0.25f),
657 gfx::PointF(),
658 gfx::Size(100, 120),
[email protected]56fffdd2014-02-11 19:50:57659 true,
[email protected]fb661802013-03-25 01:59:32660 false);
661 SetLayerPropertiesForTesting(child.get(),
662 identity_matrix,
[email protected]fb661802013-03-25 01:59:32663 gfx::PointF(),
664 gfx::PointF(),
665 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57666 true,
[email protected]fb661802013-03-25 01:59:32667 false);
668 SetLayerPropertiesForTesting(grand_child.get(),
669 identity_matrix,
[email protected]fb661802013-03-25 01:59:32670 gfx::PointF(),
671 gfx::PointF(),
672 gfx::Size(8, 10),
[email protected]56fffdd2014-02-11 19:50:57673 true,
[email protected]fb661802013-03-25 01:59:32674 false);
675 ExecuteCalculateDrawProperties(root.get());
[email protected]94f206c12012-08-25 00:09:14676
[email protected]fb661802013-03-25 01:59:32677 // Render surface should have been created now.
678 ASSERT_TRUE(child->render_surface());
679 ASSERT_EQ(child, child->render_target());
[email protected]94f206c12012-08-25 00:09:14680
[email protected]fb661802013-03-25 01:59:32681 // The child layer's draw transform should refer to its new render surface.
682 // The screen-space transform, however, should still refer to the root.
683 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
684 child->draw_transform());
685 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
686 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14687
[email protected]fb661802013-03-25 01:59:32688 // Because the grand_child is the only drawable content, the child's render
689 // surface will tighten its bounds to the grand_child. The scale at which the
690 // surface's subtree is drawn must be removed from the composite transform.
691 EXPECT_TRANSFORMATION_MATRIX_EQ(
692 surface_sublayer_composite_transform,
693 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14694
[email protected]fb661802013-03-25 01:59:32695 // The screen space is the same as the target since the child surface draws
696 // into the root.
697 EXPECT_TRANSFORMATION_MATRIX_EQ(
698 surface_sublayer_composite_transform,
699 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14700}
701
[email protected]989386c2013-07-18 21:37:23702TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
[email protected]fb661802013-03-25 01:59:32703 scoped_refptr<Layer> root = Layer::Create();
704 scoped_refptr<Layer> parent = Layer::Create();
705 scoped_refptr<Layer> child = Layer::Create();
706 scoped_refptr<Layer> child_replica = Layer::Create();
707 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
708 make_scoped_refptr(new LayerWithForcedDrawsContent());
709 root->AddChild(parent);
710 parent->AddChild(child);
711 child->AddChild(grand_child);
712 child->SetReplicaLayer(child_replica.get());
713
[email protected]d600df7d2013-08-03 02:34:28714 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
715 host->SetRootLayer(root);
716
[email protected]fb661802013-03-25 01:59:32717 // One-time setup of root layer
718 gfx::Transform identity_matrix;
719 SetLayerPropertiesForTesting(root.get(),
720 identity_matrix,
[email protected]fb661802013-03-25 01:59:32721 gfx::PointF(),
722 gfx::PointF(),
723 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57724 true,
[email protected]fb661802013-03-25 01:59:32725 false);
726
727 // Child is set up so that a new render surface should be created.
728 child->SetOpacity(0.5f);
729
730 gfx::Transform parent_layer_transform;
731 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
732 gfx::Transform parent_translation_to_anchor;
733 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32734 gfx::Transform parent_composite_transform =
735 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39736 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32737 gfx::Transform replica_layer_transform;
738 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
739 gfx::Vector2dF parent_composite_scale =
740 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
741 1.f);
742 gfx::Transform surface_sublayer_transform;
743 surface_sublayer_transform.Scale(parent_composite_scale.x(),
744 parent_composite_scale.y());
745 gfx::Transform replica_composite_transform =
746 parent_composite_transform * replica_layer_transform *
747 Inverse(surface_sublayer_transform);
748
749 // Child's render surface should not exist yet.
750 ASSERT_FALSE(child->render_surface());
751
752 SetLayerPropertiesForTesting(parent.get(),
753 parent_layer_transform,
[email protected]fb661802013-03-25 01:59:32754 gfx::PointF(0.25f, 0.25f),
755 gfx::PointF(),
756 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57757 true,
[email protected]fb661802013-03-25 01:59:32758 false);
759 SetLayerPropertiesForTesting(child.get(),
760 identity_matrix,
[email protected]fb661802013-03-25 01:59:32761 gfx::PointF(),
762 gfx::PointF(),
763 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57764 true,
[email protected]fb661802013-03-25 01:59:32765 false);
766 SetLayerPropertiesForTesting(grand_child.get(),
767 identity_matrix,
[email protected]fb661802013-03-25 01:59:32768 gfx::PointF(),
769 gfx::PointF(-0.5f, -0.5f),
770 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:57771 true,
[email protected]fb661802013-03-25 01:59:32772 false);
773 SetLayerPropertiesForTesting(child_replica.get(),
774 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:32775 gfx::PointF(),
776 gfx::PointF(),
777 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57778 true,
[email protected]fb661802013-03-25 01:59:32779 false);
780 ExecuteCalculateDrawProperties(root.get());
781
782 // Render surface should have been created now.
783 ASSERT_TRUE(child->render_surface());
784 ASSERT_EQ(child, child->render_target());
785
786 EXPECT_TRANSFORMATION_MATRIX_EQ(
787 replica_composite_transform,
788 child->render_target()->render_surface()->replica_draw_transform());
789 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57790 child->render_target()
791 ->render_surface()
[email protected]fb661802013-03-25 01:59:32792 ->replica_screen_space_transform());
793}
794
[email protected]989386c2013-07-18 21:37:23795TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32796 // This test creates a more complex tree and verifies it all at once. This
797 // covers the following cases:
798 // - layers that are described w.r.t. a render surface: should have draw
799 // transforms described w.r.t. that surface
800 // - A render surface described w.r.t. an ancestor render surface: should
801 // have a draw transform described w.r.t. that ancestor surface
802 // - Replicas of a render surface are described w.r.t. the replica's
803 // transform around its anchor, along with the surface itself.
804 // - Sanity check on recursion: verify transforms of layers described w.r.t.
805 // a render surface that is described w.r.t. an ancestor render surface.
806 // - verifying that each layer has a reference to the correct render surface
807 // and render target values.
808
809 scoped_refptr<Layer> root = Layer::Create();
810 scoped_refptr<Layer> parent = Layer::Create();
811 scoped_refptr<Layer> render_surface1 = Layer::Create();
812 scoped_refptr<Layer> render_surface2 = Layer::Create();
813 scoped_refptr<Layer> child_of_root = Layer::Create();
814 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
815 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
816 scoped_refptr<Layer> replica_of_rs1 = Layer::Create();
817 scoped_refptr<Layer> replica_of_rs2 = Layer::Create();
818 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
819 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
820 make_scoped_refptr(new LayerWithForcedDrawsContent());
821 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
822 make_scoped_refptr(new LayerWithForcedDrawsContent());
823 root->AddChild(parent);
824 parent->AddChild(render_surface1);
825 parent->AddChild(child_of_root);
826 render_surface1->AddChild(child_of_rs1);
827 render_surface1->AddChild(render_surface2);
828 render_surface2->AddChild(child_of_rs2);
829 child_of_root->AddChild(grand_child_of_root);
830 child_of_rs1->AddChild(grand_child_of_rs1);
831 child_of_rs2->AddChild(grand_child_of_rs2);
832 render_surface1->SetReplicaLayer(replica_of_rs1.get());
833 render_surface2->SetReplicaLayer(replica_of_rs2.get());
834
[email protected]d600df7d2013-08-03 02:34:28835 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
836 host->SetRootLayer(root);
837
[email protected]fb661802013-03-25 01:59:32838 // In combination with descendant draws content, opacity != 1 forces the layer
839 // to have a new render surface.
840 render_surface1->SetOpacity(0.5f);
841 render_surface2->SetOpacity(0.33f);
842
843 // One-time setup of root layer
844 gfx::Transform identity_matrix;
845 SetLayerPropertiesForTesting(root.get(),
846 identity_matrix,
[email protected]fb661802013-03-25 01:59:32847 gfx::PointF(),
848 gfx::PointF(),
849 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57850 true,
[email protected]fb661802013-03-25 01:59:32851 false);
852
853 // All layers in the tree are initialized with an anchor at .25 and a size of
854 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39855 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32856 gfx::Transform translation_to_anchor;
857 translation_to_anchor.Translate(2.5, 0.0);
858 gfx::Transform layer_transform;
859 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32860 gfx::Transform replica_layer_transform;
861 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
862
863 gfx::Transform A =
864 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32865 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
866 Inverse(translation_to_anchor);
867
868 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39869 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32870 gfx::Transform surface1_sublayer_transform;
871 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
872 surface1_parent_transform_scale.y());
873
874 // SS1 = transform given to the subtree of render_surface1
875 gfx::Transform SS1 = surface1_sublayer_transform;
876 // S1 = transform to move from render_surface1 pixels to the layer space of
877 // the owning layer
878 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
879
880 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39881 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32882 gfx::Transform surface2_sublayer_transform;
883 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
884 surface2_parent_transform_scale.y());
885
886 // SS2 = transform given to the subtree of render_surface2
887 gfx::Transform SS2 = surface2_sublayer_transform;
888 // S2 = transform to move from render_surface2 pixels to the layer space of
889 // the owning layer
890 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
891
892 SetLayerPropertiesForTesting(parent.get(),
893 layer_transform,
[email protected]fb661802013-03-25 01:59:32894 gfx::PointF(0.25f, 0.f),
895 gfx::PointF(),
896 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57897 true,
[email protected]fb661802013-03-25 01:59:32898 false);
899 SetLayerPropertiesForTesting(render_surface1.get(),
900 layer_transform,
[email protected]fb661802013-03-25 01:59:32901 gfx::PointF(0.25f, 0.f),
902 gfx::PointF(),
903 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57904 true,
[email protected]fb661802013-03-25 01:59:32905 false);
906 SetLayerPropertiesForTesting(render_surface2.get(),
907 layer_transform,
[email protected]fb661802013-03-25 01:59:32908 gfx::PointF(0.25f, 0.f),
909 gfx::PointF(),
910 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57911 true,
[email protected]fb661802013-03-25 01:59:32912 false);
913 SetLayerPropertiesForTesting(child_of_root.get(),
914 layer_transform,
[email protected]fb661802013-03-25 01:59:32915 gfx::PointF(0.25f, 0.f),
916 gfx::PointF(),
917 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57918 true,
[email protected]fb661802013-03-25 01:59:32919 false);
920 SetLayerPropertiesForTesting(child_of_rs1.get(),
921 layer_transform,
[email protected]fb661802013-03-25 01:59:32922 gfx::PointF(0.25f, 0.f),
923 gfx::PointF(),
924 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57925 true,
[email protected]fb661802013-03-25 01:59:32926 false);
927 SetLayerPropertiesForTesting(child_of_rs2.get(),
928 layer_transform,
[email protected]fb661802013-03-25 01:59:32929 gfx::PointF(0.25f, 0.f),
930 gfx::PointF(),
931 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57932 true,
[email protected]fb661802013-03-25 01:59:32933 false);
934 SetLayerPropertiesForTesting(grand_child_of_root.get(),
935 layer_transform,
[email protected]fb661802013-03-25 01:59:32936 gfx::PointF(0.25f, 0.f),
937 gfx::PointF(),
938 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57939 true,
[email protected]fb661802013-03-25 01:59:32940 false);
941 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
942 layer_transform,
[email protected]fb661802013-03-25 01:59:32943 gfx::PointF(0.25f, 0.f),
944 gfx::PointF(),
945 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57946 true,
[email protected]fb661802013-03-25 01:59:32947 false);
948 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
949 layer_transform,
[email protected]fb661802013-03-25 01:59:32950 gfx::PointF(0.25f, 0.f),
951 gfx::PointF(),
952 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57953 true,
[email protected]fb661802013-03-25 01:59:32954 false);
955 SetLayerPropertiesForTesting(replica_of_rs1.get(),
956 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:32957 gfx::PointF(0.25f, 0.f),
958 gfx::PointF(),
959 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57960 true,
[email protected]fb661802013-03-25 01:59:32961 false);
962 SetLayerPropertiesForTesting(replica_of_rs2.get(),
963 replica_layer_transform,
[email protected]fb661802013-03-25 01:59:32964 gfx::PointF(0.25f, 0.f),
965 gfx::PointF(),
966 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57967 true,
[email protected]fb661802013-03-25 01:59:32968 false);
969
970 ExecuteCalculateDrawProperties(root.get());
971
972 // Only layers that are associated with render surfaces should have an actual
973 // RenderSurface() value.
974 ASSERT_TRUE(root->render_surface());
975 ASSERT_FALSE(child_of_root->render_surface());
976 ASSERT_FALSE(grand_child_of_root->render_surface());
977
978 ASSERT_TRUE(render_surface1->render_surface());
979 ASSERT_FALSE(child_of_rs1->render_surface());
980 ASSERT_FALSE(grand_child_of_rs1->render_surface());
981
982 ASSERT_TRUE(render_surface2->render_surface());
983 ASSERT_FALSE(child_of_rs2->render_surface());
984 ASSERT_FALSE(grand_child_of_rs2->render_surface());
985
986 // Verify all render target accessors
987 EXPECT_EQ(root, parent->render_target());
988 EXPECT_EQ(root, child_of_root->render_target());
989 EXPECT_EQ(root, grand_child_of_root->render_target());
990
991 EXPECT_EQ(render_surface1, render_surface1->render_target());
992 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
993 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
994
995 EXPECT_EQ(render_surface2, render_surface2->render_target());
996 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
997 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
998
999 // Verify layer draw transforms note that draw transforms are described with
1000 // respect to the nearest ancestor render surface but screen space transforms
1001 // are described with respect to the root.
1002 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
[email protected]baf64d062014-02-16 22:10:391003 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform());
1004 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321005 grand_child_of_root->draw_transform());
1006
1007 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
[email protected]baf64d062014-02-16 22:10:391008 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform());
1009 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
[email protected]fb661802013-03-25 01:59:321010 grand_child_of_rs1->draw_transform());
1011
1012 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
[email protected]baf64d062014-02-16 22:10:391013 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform());
1014 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
[email protected]fb661802013-03-25 01:59:321015 grand_child_of_rs2->draw_transform());
1016
1017 // Verify layer screen-space transforms
1018 //
1019 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391020 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:321021 child_of_root->screen_space_transform());
1022 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391023 A * A * A, grand_child_of_root->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321024
[email protected]baf64d062014-02-16 22:10:391025 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:321026 render_surface1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391027 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321028 child_of_rs1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391029 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:321030 grand_child_of_rs1->screen_space_transform());
1031
[email protected]baf64d062014-02-16 22:10:391032 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:321033 render_surface2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391034 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:321035 child_of_rs2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:391036 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
[email protected]fb661802013-03-25 01:59:321037 grand_child_of_rs2->screen_space_transform());
1038
1039 // Verify render surface transforms.
1040 //
1041 // Draw transform of render surface 1 is described with respect to root.
1042 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391043 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321044 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391045 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:321046 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391047 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321048 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391049 A * R * S1,
[email protected]fb661802013-03-25 01:59:321050 render_surface1->render_surface()->replica_screen_space_transform());
1051 // Draw transform of render surface 2 is described with respect to render
1052 // surface 1.
1053 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391054 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321055 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391056 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:321057 render_surface2->render_surface()->replica_draw_transform());
1058 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391059 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:321060 render_surface2->render_surface()->screen_space_transform());
1061 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391062 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:321063 render_surface2->render_surface()->replica_screen_space_transform());
1064
1065 // Sanity check. If these fail there is probably a bug in the test itself. It
1066 // is expected that we correctly set up transforms so that the y-component of
1067 // the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:261068 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
1069 EXPECT_FLOAT_EQ(2.0,
1070 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321071 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261072 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321073
[email protected]803f6b52013-09-12 00:51:261074 EXPECT_FLOAT_EQ(2.0,
1075 render_surface1->screen_space_transform().matrix().get(1, 3));
1076 EXPECT_FLOAT_EQ(3.0,
1077 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321078 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261079 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321080
[email protected]803f6b52013-09-12 00:51:261081 EXPECT_FLOAT_EQ(3.0,
1082 render_surface2->screen_space_transform().matrix().get(1, 3));
1083 EXPECT_FLOAT_EQ(4.0,
1084 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321085 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261086 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321087}
1088
[email protected]989386c2013-07-18 21:37:231089TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321090 // For layers that flatten their subtree, there should be an orthographic
1091 // projection (for x and y values) in the middle of the transform sequence.
1092 // Note that the way the code is currently implemented, it is not expected to
1093 // use a canonical orthographic projection.
1094
1095 scoped_refptr<Layer> root = Layer::Create();
1096 scoped_refptr<Layer> child = Layer::Create();
1097 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1098 make_scoped_refptr(new LayerWithForcedDrawsContent());
1099
1100 gfx::Transform rotation_about_y_axis;
1101 rotation_about_y_axis.RotateAboutYAxis(30.0);
1102
1103 const gfx::Transform identity_matrix;
1104 SetLayerPropertiesForTesting(root.get(),
1105 identity_matrix,
[email protected]fb661802013-03-25 01:59:321106 gfx::PointF(),
1107 gfx::PointF(),
1108 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571109 true,
[email protected]fb661802013-03-25 01:59:321110 false);
1111 SetLayerPropertiesForTesting(child.get(),
1112 rotation_about_y_axis,
[email protected]fb661802013-03-25 01:59:321113 gfx::PointF(),
1114 gfx::PointF(),
1115 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571116 true,
[email protected]fb661802013-03-25 01:59:321117 false);
1118 SetLayerPropertiesForTesting(grand_child.get(),
1119 rotation_about_y_axis,
[email protected]fb661802013-03-25 01:59:321120 gfx::PointF(),
1121 gfx::PointF(),
1122 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571123 true,
[email protected]fb661802013-03-25 01:59:321124 false);
1125
1126 root->AddChild(child);
1127 child->AddChild(grand_child);
1128 child->SetForceRenderSurface(true);
1129
[email protected]d600df7d2013-08-03 02:34:281130 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1131 host->SetRootLayer(root);
1132
[email protected]fb661802013-03-25 01:59:321133 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:571134 ASSERT_TRUE(root->should_flatten_transform());
1135 ASSERT_TRUE(child->should_flatten_transform());
1136 ASSERT_TRUE(grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:321137
1138 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1139 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1140 gfx::Transform expected_grand_child_draw_transform =
1141 rotation_about_y_axis; // draws onto child's render surface
1142 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1143 flattened_rotation_about_y.FlattenTo2d();
1144 gfx::Transform expected_grand_child_screen_space_transform =
1145 flattened_rotation_about_y * rotation_about_y_axis;
1146
1147 ExecuteCalculateDrawProperties(root.get());
1148
1149 // The child's draw transform should have been taken by its surface.
1150 ASSERT_TRUE(child->render_surface());
1151 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1152 child->render_surface()->draw_transform());
1153 EXPECT_TRANSFORMATION_MATRIX_EQ(
1154 expected_child_screen_space_transform,
1155 child->render_surface()->screen_space_transform());
1156 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1157 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1158 child->screen_space_transform());
1159 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1160 grand_child->draw_transform());
1161 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1162 grand_child->screen_space_transform());
1163}
1164
[email protected]989386c2013-07-18 21:37:231165TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321166 // A layer that is empty in one axis, but not the other, was accidentally
1167 // skipping a necessary translation. Without that translation, the coordinate
1168 // space of the layer's draw transform is incorrect.
1169 //
1170 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1171 // but if that layer becomes a render surface, then its draw transform is
1172 // implicitly inherited by the rest of the subtree, which then is positioned
1173 // incorrectly as a result.
1174
1175 scoped_refptr<Layer> root = Layer::Create();
1176 scoped_refptr<Layer> child = Layer::Create();
1177 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1178 make_scoped_refptr(new LayerWithForcedDrawsContent());
1179
1180 // The child height is zero, but has non-zero width that should be accounted
1181 // for while computing draw transforms.
1182 const gfx::Transform identity_matrix;
1183 SetLayerPropertiesForTesting(root.get(),
1184 identity_matrix,
[email protected]fb661802013-03-25 01:59:321185 gfx::PointF(),
1186 gfx::PointF(),
1187 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571188 true,
[email protected]fb661802013-03-25 01:59:321189 false);
1190 SetLayerPropertiesForTesting(child.get(),
1191 identity_matrix,
[email protected]fb661802013-03-25 01:59:321192 gfx::PointF(),
1193 gfx::PointF(),
1194 gfx::Size(10, 0),
[email protected]56fffdd2014-02-11 19:50:571195 true,
[email protected]fb661802013-03-25 01:59:321196 false);
1197 SetLayerPropertiesForTesting(grand_child.get(),
1198 identity_matrix,
[email protected]fb661802013-03-25 01:59:321199 gfx::PointF(),
1200 gfx::PointF(),
1201 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571202 true,
[email protected]fb661802013-03-25 01:59:321203 false);
1204
1205 root->AddChild(child);
1206 child->AddChild(grand_child);
1207 child->SetForceRenderSurface(true);
1208
[email protected]d600df7d2013-08-03 02:34:281209 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1210 host->SetRootLayer(root);
1211
[email protected]fb661802013-03-25 01:59:321212 ExecuteCalculateDrawProperties(root.get());
1213
1214 ASSERT_TRUE(child->render_surface());
1215 // This is the real test, the rest are sanity checks.
1216 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1217 child->render_surface()->draw_transform());
1218 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1219 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1220 grand_child->draw_transform());
1221}
1222
[email protected]989386c2013-07-18 21:37:231223TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321224 // Transformations applied at the root of the tree should be forwarded
1225 // to child layers instead of applied to the root RenderSurface.
1226 const gfx::Transform identity_matrix;
1227 scoped_refptr<Layer> root = Layer::Create();
1228 scoped_refptr<Layer> child = Layer::Create();
[email protected]adeda572014-01-31 00:49:471229 child->SetScrollClipLayerId(root->id());
[email protected]f224cc92013-06-06 23:23:321230 root->AddChild(child);
1231
[email protected]d600df7d2013-08-03 02:34:281232 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1233 host->SetRootLayer(root);
1234
[email protected]f224cc92013-06-06 23:23:321235 SetLayerPropertiesForTesting(root.get(),
1236 identity_matrix,
[email protected]f224cc92013-06-06 23:23:321237 gfx::PointF(),
1238 gfx::PointF(),
1239 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571240 true,
[email protected]f224cc92013-06-06 23:23:321241 false);
1242 SetLayerPropertiesForTesting(child.get(),
1243 identity_matrix,
[email protected]f224cc92013-06-06 23:23:321244 gfx::PointF(),
1245 gfx::PointF(),
1246 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571247 true,
[email protected]f224cc92013-06-06 23:23:321248 false);
1249
[email protected]f224cc92013-06-06 23:23:321250 gfx::Transform translate;
1251 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231252 {
1253 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531254 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1255 root.get(), root->bounds(), translate, &render_surface_layer_list);
1256 inputs.can_adjust_raster_scales = true;
1257 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231258 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1259 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1260 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1261 }
[email protected]f224cc92013-06-06 23:23:321262
1263 gfx::Transform scale;
1264 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231265 {
1266 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531267 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1268 root.get(), root->bounds(), scale, &render_surface_layer_list);
1269 inputs.can_adjust_raster_scales = true;
1270 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231271 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1272 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1273 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1274 }
[email protected]f224cc92013-06-06 23:23:321275
1276 gfx::Transform rotate;
1277 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231278 {
1279 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531280 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1281 root.get(), root->bounds(), rotate, &render_surface_layer_list);
1282 inputs.can_adjust_raster_scales = true;
1283 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231284 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1285 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1286 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1287 }
[email protected]f224cc92013-06-06 23:23:321288
1289 gfx::Transform composite;
1290 composite.ConcatTransform(translate);
1291 composite.ConcatTransform(scale);
1292 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231293 {
1294 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531295 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1296 root.get(), root->bounds(), composite, &render_surface_layer_list);
1297 inputs.can_adjust_raster_scales = true;
1298 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231299 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1300 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1301 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1302 }
[email protected]f224cc92013-06-06 23:23:321303
[email protected]9781afa2013-07-17 23:15:321304 // Verify it composes correctly with device scale.
1305 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231306
1307 {
1308 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531309 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1310 root.get(), root->bounds(), translate, &render_surface_layer_list);
1311 inputs.device_scale_factor = device_scale_factor;
1312 inputs.can_adjust_raster_scales = true;
1313 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231314 gfx::Transform device_scaled_translate = translate;
1315 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1316 EXPECT_EQ(device_scaled_translate,
1317 root->draw_properties().target_space_transform);
1318 EXPECT_EQ(device_scaled_translate,
1319 child->draw_properties().target_space_transform);
1320 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1321 }
[email protected]9781afa2013-07-17 23:15:321322
1323 // Verify it composes correctly with page scale.
1324 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231325
1326 {
1327 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531328 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1329 root.get(), root->bounds(), translate, &render_surface_layer_list);
1330 inputs.page_scale_factor = page_scale_factor;
1331 inputs.page_scale_application_layer = root.get();
1332 inputs.can_adjust_raster_scales = true;
1333 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231334 gfx::Transform page_scaled_translate = translate;
1335 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1336 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1337 EXPECT_EQ(page_scaled_translate,
1338 child->draw_properties().target_space_transform);
1339 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1340 }
[email protected]9781afa2013-07-17 23:15:321341
[email protected]f224cc92013-06-06 23:23:321342 // Verify that it composes correctly with transforms directly on root layer.
1343 root->SetTransform(composite);
[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(), composite, &render_surface_layer_list);
1349 inputs.can_adjust_raster_scales = true;
1350 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231351 gfx::Transform compositeSquared = composite;
1352 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261353 EXPECT_TRANSFORMATION_MATRIX_EQ(
1354 compositeSquared, root->draw_properties().target_space_transform);
1355 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391356 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231357 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1358 }
[email protected]f224cc92013-06-06 23:23:321359}
1360
[email protected]989386c2013-07-18 21:37:231361TEST_F(LayerTreeHostCommonTest,
1362 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321363 scoped_refptr<Layer> parent = Layer::Create();
1364 scoped_refptr<Layer> render_surface1 = Layer::Create();
1365 scoped_refptr<LayerWithForcedDrawsContent> child =
1366 make_scoped_refptr(new LayerWithForcedDrawsContent());
1367
[email protected]d600df7d2013-08-03 02:34:281368 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1369 host->SetRootLayer(parent);
1370
[email protected]fb661802013-03-25 01:59:321371 const gfx::Transform identity_matrix;
1372 SetLayerPropertiesForTesting(parent.get(),
1373 identity_matrix,
[email protected]fb661802013-03-25 01:59:321374 gfx::PointF(),
1375 gfx::PointF(),
1376 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571377 true,
[email protected]fb661802013-03-25 01:59:321378 false);
1379 SetLayerPropertiesForTesting(render_surface1.get(),
1380 identity_matrix,
[email protected]fb661802013-03-25 01:59:321381 gfx::PointF(),
1382 gfx::PointF(),
1383 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571384 true,
[email protected]fb661802013-03-25 01:59:321385 false);
1386 SetLayerPropertiesForTesting(child.get(),
1387 identity_matrix,
[email protected]fb661802013-03-25 01:59:321388 gfx::PointF(),
1389 gfx::PointF(30.f, 30.f),
1390 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571391 true,
[email protected]fb661802013-03-25 01:59:321392 false);
1393
1394 parent->AddChild(render_surface1);
1395 parent->SetMasksToBounds(true);
1396 render_surface1->AddChild(child);
1397 render_surface1->SetForceRenderSurface(true);
1398
[email protected]989386c2013-07-18 21:37:231399 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531400 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1401 parent.get(),
1402 parent->bounds(),
1403 gfx::Transform(),
1404 &render_surface_layer_list);
1405 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321406
1407 // The child layer's content is entirely outside the parent's clip rect, so
1408 // the intermediate render surface should not be listed here, even if it was
1409 // forced to be created. Render surfaces without children or visible content
1410 // are unexpected at draw time (e.g. we might try to create a content texture
1411 // of size 0).
1412 ASSERT_TRUE(parent->render_surface());
1413 ASSERT_FALSE(render_surface1->render_surface());
1414 EXPECT_EQ(1U, render_surface_layer_list.size());
1415}
1416
[email protected]989386c2013-07-18 21:37:231417TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321418 scoped_refptr<Layer> parent = Layer::Create();
1419 scoped_refptr<Layer> render_surface1 = Layer::Create();
1420 scoped_refptr<LayerWithForcedDrawsContent> child =
1421 make_scoped_refptr(new LayerWithForcedDrawsContent());
1422
[email protected]d600df7d2013-08-03 02:34:281423 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1424 host->SetRootLayer(parent);
1425
[email protected]fb661802013-03-25 01:59:321426 const gfx::Transform identity_matrix;
1427 SetLayerPropertiesForTesting(render_surface1.get(),
1428 identity_matrix,
[email protected]fb661802013-03-25 01:59:321429 gfx::PointF(),
1430 gfx::PointF(),
1431 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571432 true,
[email protected]fb661802013-03-25 01:59:321433 false);
1434 SetLayerPropertiesForTesting(child.get(),
1435 identity_matrix,
[email protected]fb661802013-03-25 01:59:321436 gfx::PointF(),
1437 gfx::PointF(),
1438 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571439 true,
[email protected]fb661802013-03-25 01:59:321440 false);
1441
1442 parent->AddChild(render_surface1);
1443 render_surface1->AddChild(child);
1444 render_surface1->SetForceRenderSurface(true);
1445 render_surface1->SetOpacity(0.f);
1446
[email protected]989386c2013-07-18 21:37:231447 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531448 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1449 parent.get(), parent->bounds(), &render_surface_layer_list);
1450 inputs.can_adjust_raster_scales = true;
1451 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321452
1453 // Since the layer is transparent, render_surface1->render_surface() should
1454 // not have gotten added anywhere. Also, the drawable content rect should not
1455 // have been extended by the children.
1456 ASSERT_TRUE(parent->render_surface());
1457 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1458 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231459 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321460 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1461}
1462
[email protected]989386c2013-07-18 21:37:231463TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321464 scoped_refptr<Layer> parent = Layer::Create();
1465 scoped_refptr<Layer> render_surface1 = Layer::Create();
1466 scoped_refptr<LayerWithForcedDrawsContent> child =
1467 make_scoped_refptr(new LayerWithForcedDrawsContent());
1468 render_surface1->SetForceRenderSurface(true);
1469
[email protected]d600df7d2013-08-03 02:34:281470 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1471 host->SetRootLayer(parent);
1472
[email protected]fb661802013-03-25 01:59:321473 const gfx::Transform identity_matrix;
1474 SetLayerPropertiesForTesting(parent.get(),
1475 identity_matrix,
[email protected]fb661802013-03-25 01:59:321476 gfx::PointF(),
1477 gfx::PointF(),
1478 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571479 true,
[email protected]fb661802013-03-25 01:59:321480 false);
1481 SetLayerPropertiesForTesting(render_surface1.get(),
1482 identity_matrix,
[email protected]fb661802013-03-25 01:59:321483 gfx::PointF(),
1484 gfx::PointF(),
1485 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571486 true,
[email protected]fb661802013-03-25 01:59:321487 false);
1488 SetLayerPropertiesForTesting(child.get(),
1489 identity_matrix,
[email protected]fb661802013-03-25 01:59:321490 gfx::PointF(),
1491 gfx::PointF(),
1492 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571493 true,
[email protected]fb661802013-03-25 01:59:321494 false);
1495
1496 parent->AddChild(render_surface1);
1497 render_surface1->AddChild(child);
1498
1499 // Sanity check before the actual test
1500 EXPECT_FALSE(parent->render_surface());
1501 EXPECT_FALSE(render_surface1->render_surface());
1502
[email protected]989386c2013-07-18 21:37:231503 {
1504 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531505 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1506 parent.get(), parent->bounds(), &render_surface_layer_list);
1507 inputs.can_adjust_raster_scales = true;
1508 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321509
[email protected]989386c2013-07-18 21:37:231510 // The root layer always creates a render surface
1511 EXPECT_TRUE(parent->render_surface());
1512 EXPECT_TRUE(render_surface1->render_surface());
1513 EXPECT_EQ(2U, render_surface_layer_list.size());
1514 }
[email protected]fb661802013-03-25 01:59:321515
[email protected]989386c2013-07-18 21:37:231516 {
1517 RenderSurfaceLayerList render_surface_layer_list;
1518 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531519 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1520 parent.get(), parent->bounds(), &render_surface_layer_list);
1521 inputs.can_adjust_raster_scales = true;
1522 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231523 EXPECT_TRUE(parent->render_surface());
1524 EXPECT_FALSE(render_surface1->render_surface());
1525 EXPECT_EQ(1U, render_surface_layer_list.size());
1526 }
[email protected]fb661802013-03-25 01:59:321527}
1528
[email protected]989386c2013-07-18 21:37:231529TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321530 // The entire subtree of layers that are outside the clip rect should be
1531 // culled away, and should not affect the render_surface_layer_list.
1532 //
1533 // The test tree is set up as follows:
1534 // - all layers except the leaf_nodes are forced to be a new render surface
1535 // that have something to draw.
1536 // - parent is a large container layer.
1537 // - child has masksToBounds=true to cause clipping.
1538 // - grand_child is positioned outside of the child's bounds
1539 // - great_grand_child is also kept outside child's bounds.
1540 //
1541 // In this configuration, grand_child and great_grand_child are completely
1542 // outside the clip rect, and they should never get scheduled on the list of
1543 // render surfaces.
1544 //
1545
1546 const gfx::Transform identity_matrix;
1547 scoped_refptr<Layer> parent = Layer::Create();
1548 scoped_refptr<Layer> child = Layer::Create();
1549 scoped_refptr<Layer> grand_child = Layer::Create();
1550 scoped_refptr<Layer> great_grand_child = Layer::Create();
1551 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1552 make_scoped_refptr(new LayerWithForcedDrawsContent());
1553 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1554 make_scoped_refptr(new LayerWithForcedDrawsContent());
1555 parent->AddChild(child);
1556 child->AddChild(grand_child);
1557 grand_child->AddChild(great_grand_child);
1558
[email protected]d600df7d2013-08-03 02:34:281559 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1560 host->SetRootLayer(parent);
1561
[email protected]fb661802013-03-25 01:59:321562 // leaf_node1 ensures that parent and child are kept on the
1563 // render_surface_layer_list, even though grand_child and great_grand_child
1564 // should be clipped.
1565 child->AddChild(leaf_node1);
1566 great_grand_child->AddChild(leaf_node2);
1567
1568 SetLayerPropertiesForTesting(parent.get(),
1569 identity_matrix,
[email protected]fb661802013-03-25 01:59:321570 gfx::PointF(),
1571 gfx::PointF(),
1572 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571573 true,
[email protected]fb661802013-03-25 01:59:321574 false);
1575 SetLayerPropertiesForTesting(child.get(),
1576 identity_matrix,
[email protected]fb661802013-03-25 01:59:321577 gfx::PointF(),
1578 gfx::PointF(),
1579 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571580 true,
[email protected]fb661802013-03-25 01:59:321581 false);
1582 SetLayerPropertiesForTesting(grand_child.get(),
1583 identity_matrix,
[email protected]fb661802013-03-25 01:59:321584 gfx::PointF(),
1585 gfx::PointF(45.f, 45.f),
1586 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571587 true,
[email protected]fb661802013-03-25 01:59:321588 false);
1589 SetLayerPropertiesForTesting(great_grand_child.get(),
1590 identity_matrix,
[email protected]fb661802013-03-25 01:59:321591 gfx::PointF(),
1592 gfx::PointF(),
1593 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571594 true,
[email protected]fb661802013-03-25 01:59:321595 false);
1596 SetLayerPropertiesForTesting(leaf_node1.get(),
1597 identity_matrix,
[email protected]fb661802013-03-25 01:59:321598 gfx::PointF(),
1599 gfx::PointF(),
1600 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571601 true,
[email protected]fb661802013-03-25 01:59:321602 false);
1603 SetLayerPropertiesForTesting(leaf_node2.get(),
1604 identity_matrix,
[email protected]fb661802013-03-25 01:59:321605 gfx::PointF(),
1606 gfx::PointF(),
1607 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571608 true,
[email protected]fb661802013-03-25 01:59:321609 false);
1610
1611 child->SetMasksToBounds(true);
1612 child->SetOpacity(0.4f);
1613 child->SetForceRenderSurface(true);
1614 grand_child->SetOpacity(0.5f);
1615 great_grand_child->SetOpacity(0.4f);
1616
[email protected]989386c2013-07-18 21:37:231617 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531618 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1619 parent.get(), parent->bounds(), &render_surface_layer_list);
1620 inputs.can_adjust_raster_scales = true;
1621 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321622
1623 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231624 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1625 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321626}
1627
[email protected]989386c2013-07-18 21:37:231628TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321629 // When a render surface has a clip rect, it is used to clip the content rect
1630 // of the surface. When the render surface is animating its transforms, then
1631 // the content rect's position in the clip rect is not defined on the main
1632 // thread, and its content rect should not be clipped.
1633
1634 // The test tree is set up as follows:
1635 // - parent is a container layer that masksToBounds=true to cause clipping.
1636 // - child is a render surface, which has a clip rect set to the bounds of
1637 // the parent.
1638 // - grand_child is a render surface, and the only visible content in child.
1639 // It is positioned outside of the clip rect from parent.
1640
1641 // In this configuration, grand_child should be outside the clipped
1642 // content rect of the child, making grand_child not appear in the
1643 // render_surface_layer_list. However, when we place an animation on the
1644 // child, this clipping should be avoided and we should keep the grand_child
1645 // in the render_surface_layer_list.
1646
1647 const gfx::Transform identity_matrix;
1648 scoped_refptr<Layer> parent = Layer::Create();
1649 scoped_refptr<Layer> child = Layer::Create();
1650 scoped_refptr<Layer> grand_child = Layer::Create();
1651 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1652 make_scoped_refptr(new LayerWithForcedDrawsContent());
1653 parent->AddChild(child);
1654 child->AddChild(grand_child);
1655 grand_child->AddChild(leaf_node);
1656
[email protected]d600df7d2013-08-03 02:34:281657 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1658 host->SetRootLayer(parent);
1659
[email protected]fb661802013-03-25 01:59:321660 SetLayerPropertiesForTesting(parent.get(),
1661 identity_matrix,
[email protected]fb661802013-03-25 01:59:321662 gfx::PointF(),
1663 gfx::PointF(),
1664 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571665 true,
[email protected]fb661802013-03-25 01:59:321666 false);
1667 SetLayerPropertiesForTesting(child.get(),
1668 identity_matrix,
[email protected]fb661802013-03-25 01:59:321669 gfx::PointF(),
1670 gfx::PointF(),
1671 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571672 true,
[email protected]fb661802013-03-25 01:59:321673 false);
1674 SetLayerPropertiesForTesting(grand_child.get(),
1675 identity_matrix,
[email protected]fb661802013-03-25 01:59:321676 gfx::PointF(),
1677 gfx::PointF(200.f, 200.f),
1678 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571679 true,
[email protected]fb661802013-03-25 01:59:321680 false);
1681 SetLayerPropertiesForTesting(leaf_node.get(),
1682 identity_matrix,
[email protected]fb661802013-03-25 01:59:321683 gfx::PointF(),
1684 gfx::PointF(),
1685 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571686 true,
[email protected]fb661802013-03-25 01:59:321687 false);
1688
1689 parent->SetMasksToBounds(true);
1690 child->SetOpacity(0.4f);
1691 child->SetForceRenderSurface(true);
1692 grand_child->SetOpacity(0.4f);
1693 grand_child->SetForceRenderSurface(true);
1694
[email protected]989386c2013-07-18 21:37:231695 {
1696 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531697 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1698 parent.get(), parent->bounds(), &render_surface_layer_list);
1699 inputs.can_adjust_raster_scales = true;
1700 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321701
[email protected]989386c2013-07-18 21:37:231702 // Without an animation, we should cull child and grand_child from the
1703 // render_surface_layer_list.
1704 ASSERT_EQ(1U, render_surface_layer_list.size());
1705 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1706 }
[email protected]fb661802013-03-25 01:59:321707
1708 // Now put an animating transform on child.
1709 AddAnimatedTransformToController(
1710 child->layer_animation_controller(), 10.0, 30, 0);
1711
[email protected]989386c2013-07-18 21:37:231712 {
1713 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531714 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1715 parent.get(), parent->bounds(), &render_surface_layer_list);
1716 inputs.can_adjust_raster_scales = true;
1717 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321718
[email protected]989386c2013-07-18 21:37:231719 // With an animating transform, we should keep child and grand_child in the
1720 // render_surface_layer_list.
1721 ASSERT_EQ(3U, render_surface_layer_list.size());
1722 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1723 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1724 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1725 }
[email protected]fb661802013-03-25 01:59:321726}
1727
[email protected]989386c2013-07-18 21:37:231728TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:321729 // Layer's IsClipped() property is set to true when:
1730 // - the layer clips its subtree, e.g. masks to bounds,
1731 // - the layer is clipped by an ancestor that contributes to the same
1732 // render target,
1733 // - a surface is clipped by an ancestor that contributes to the same
1734 // render target.
1735 //
1736 // In particular, for a layer that owns a render surface:
1737 // - the render surface inherits any clip from ancestors, and does NOT
1738 // pass that clipped status to the layer itself.
1739 // - but if the layer itself masks to bounds, it is considered clipped
1740 // and propagates the clip to the subtree.
1741
1742 const gfx::Transform identity_matrix;
1743 scoped_refptr<Layer> root = Layer::Create();
1744 scoped_refptr<Layer> parent = Layer::Create();
1745 scoped_refptr<Layer> child1 = Layer::Create();
1746 scoped_refptr<Layer> child2 = Layer::Create();
1747 scoped_refptr<Layer> grand_child = Layer::Create();
1748 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1749 make_scoped_refptr(new LayerWithForcedDrawsContent());
1750 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1751 make_scoped_refptr(new LayerWithForcedDrawsContent());
1752 root->AddChild(parent);
1753 parent->AddChild(child1);
1754 parent->AddChild(child2);
1755 child1->AddChild(grand_child);
1756 child2->AddChild(leaf_node2);
1757 grand_child->AddChild(leaf_node1);
1758
[email protected]d600df7d2013-08-03 02:34:281759 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1760 host->SetRootLayer(root);
1761
[email protected]fb661802013-03-25 01:59:321762 child2->SetForceRenderSurface(true);
1763
1764 SetLayerPropertiesForTesting(root.get(),
1765 identity_matrix,
[email protected]fb661802013-03-25 01:59:321766 gfx::PointF(),
1767 gfx::PointF(),
1768 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571769 true,
[email protected]fb661802013-03-25 01:59:321770 false);
1771 SetLayerPropertiesForTesting(parent.get(),
1772 identity_matrix,
[email protected]fb661802013-03-25 01:59:321773 gfx::PointF(),
1774 gfx::PointF(),
1775 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571776 true,
[email protected]fb661802013-03-25 01:59:321777 false);
1778 SetLayerPropertiesForTesting(child1.get(),
1779 identity_matrix,
[email protected]fb661802013-03-25 01:59:321780 gfx::PointF(),
1781 gfx::PointF(),
1782 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571783 true,
[email protected]fb661802013-03-25 01:59:321784 false);
1785 SetLayerPropertiesForTesting(child2.get(),
1786 identity_matrix,
[email protected]fb661802013-03-25 01:59:321787 gfx::PointF(),
1788 gfx::PointF(),
1789 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571790 true,
[email protected]fb661802013-03-25 01:59:321791 false);
1792 SetLayerPropertiesForTesting(grand_child.get(),
1793 identity_matrix,
[email protected]fb661802013-03-25 01:59:321794 gfx::PointF(),
1795 gfx::PointF(),
1796 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571797 true,
[email protected]fb661802013-03-25 01:59:321798 false);
1799 SetLayerPropertiesForTesting(leaf_node1.get(),
1800 identity_matrix,
[email protected]fb661802013-03-25 01:59:321801 gfx::PointF(),
1802 gfx::PointF(),
1803 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571804 true,
[email protected]fb661802013-03-25 01:59:321805 false);
1806 SetLayerPropertiesForTesting(leaf_node2.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
[email protected]989386c2013-07-18 21:37:231814 // Case 1: nothing is clipped except the root render surface.
1815 {
1816 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531817 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1818 root.get(), parent->bounds(), &render_surface_layer_list);
1819 inputs.can_adjust_raster_scales = true;
1820 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321821
[email protected]989386c2013-07-18 21:37:231822 ASSERT_TRUE(root->render_surface());
1823 ASSERT_TRUE(child2->render_surface());
1824
1825 EXPECT_FALSE(root->is_clipped());
1826 EXPECT_TRUE(root->render_surface()->is_clipped());
1827 EXPECT_FALSE(parent->is_clipped());
1828 EXPECT_FALSE(child1->is_clipped());
1829 EXPECT_FALSE(child2->is_clipped());
1830 EXPECT_FALSE(child2->render_surface()->is_clipped());
1831 EXPECT_FALSE(grand_child->is_clipped());
1832 EXPECT_FALSE(leaf_node1->is_clipped());
1833 EXPECT_FALSE(leaf_node2->is_clipped());
1834 }
[email protected]fb661802013-03-25 01:59:321835
1836 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1837 // surface are clipped. But layers that contribute to child2's surface are
1838 // not clipped explicitly because child2's surface already accounts for
1839 // that clip.
[email protected]989386c2013-07-18 21:37:231840 {
1841 RenderSurfaceLayerList render_surface_layer_list;
1842 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531843 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1844 root.get(), parent->bounds(), &render_surface_layer_list);
1845 inputs.can_adjust_raster_scales = true;
1846 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321847
[email protected]989386c2013-07-18 21:37:231848 ASSERT_TRUE(root->render_surface());
1849 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321850
[email protected]989386c2013-07-18 21:37:231851 EXPECT_FALSE(root->is_clipped());
1852 EXPECT_TRUE(root->render_surface()->is_clipped());
1853 EXPECT_TRUE(parent->is_clipped());
1854 EXPECT_TRUE(child1->is_clipped());
1855 EXPECT_FALSE(child2->is_clipped());
1856 EXPECT_TRUE(child2->render_surface()->is_clipped());
1857 EXPECT_TRUE(grand_child->is_clipped());
1858 EXPECT_TRUE(leaf_node1->is_clipped());
1859 EXPECT_FALSE(leaf_node2->is_clipped());
1860 }
[email protected]fb661802013-03-25 01:59:321861
1862 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1863 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:231864 {
1865 RenderSurfaceLayerList render_surface_layer_list;
1866 parent->SetMasksToBounds(false);
1867 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531868 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1869 root.get(), parent->bounds(), &render_surface_layer_list);
1870 inputs.can_adjust_raster_scales = true;
1871 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321872
[email protected]989386c2013-07-18 21:37:231873 ASSERT_TRUE(root->render_surface());
1874 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321875
[email protected]989386c2013-07-18 21:37:231876 EXPECT_FALSE(root->is_clipped());
1877 EXPECT_TRUE(root->render_surface()->is_clipped());
1878 EXPECT_FALSE(parent->is_clipped());
1879 EXPECT_FALSE(child1->is_clipped());
1880 EXPECT_TRUE(child2->is_clipped());
1881 EXPECT_FALSE(child2->render_surface()->is_clipped());
1882 EXPECT_FALSE(grand_child->is_clipped());
1883 EXPECT_FALSE(leaf_node1->is_clipped());
1884 EXPECT_TRUE(leaf_node2->is_clipped());
1885 }
[email protected]fb661802013-03-25 01:59:321886}
1887
[email protected]fd9a3b6d2013-08-03 00:46:171888TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321889 // Verify that layers get the appropriate DrawableContentRect when their
1890 // parent masksToBounds is true.
1891 //
1892 // grand_child1 - completely inside the region; DrawableContentRect should
1893 // be the layer rect expressed in target space.
1894 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1895 // will be the intersection of layer bounds and the mask region.
1896 // grand_child3 - partially clipped and masksToBounds; the
1897 // DrawableContentRect will still be the intersection of layer bounds and
1898 // the mask region.
1899 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1900 // be empty.
1901 //
1902
1903 const gfx::Transform identity_matrix;
1904 scoped_refptr<Layer> parent = Layer::Create();
1905 scoped_refptr<Layer> child = Layer::Create();
1906 scoped_refptr<Layer> grand_child1 = Layer::Create();
1907 scoped_refptr<Layer> grand_child2 = Layer::Create();
1908 scoped_refptr<Layer> grand_child3 = Layer::Create();
1909 scoped_refptr<Layer> grand_child4 = Layer::Create();
1910
1911 parent->AddChild(child);
1912 child->AddChild(grand_child1);
1913 child->AddChild(grand_child2);
1914 child->AddChild(grand_child3);
1915 child->AddChild(grand_child4);
1916
[email protected]d600df7d2013-08-03 02:34:281917 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1918 host->SetRootLayer(parent);
1919
[email protected]fb661802013-03-25 01:59:321920 SetLayerPropertiesForTesting(parent.get(),
1921 identity_matrix,
[email protected]fb661802013-03-25 01:59:321922 gfx::PointF(),
1923 gfx::PointF(),
1924 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571925 true,
[email protected]fb661802013-03-25 01:59:321926 false);
1927 SetLayerPropertiesForTesting(child.get(),
1928 identity_matrix,
[email protected]fb661802013-03-25 01:59:321929 gfx::PointF(),
1930 gfx::PointF(),
1931 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571932 true,
[email protected]fb661802013-03-25 01:59:321933 false);
1934 SetLayerPropertiesForTesting(grand_child1.get(),
1935 identity_matrix,
[email protected]fb661802013-03-25 01:59:321936 gfx::PointF(),
1937 gfx::PointF(5.f, 5.f),
1938 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571939 true,
[email protected]fb661802013-03-25 01:59:321940 false);
1941 SetLayerPropertiesForTesting(grand_child2.get(),
1942 identity_matrix,
[email protected]fb661802013-03-25 01:59:321943 gfx::PointF(),
1944 gfx::PointF(15.f, 15.f),
1945 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571946 true,
[email protected]fb661802013-03-25 01:59:321947 false);
1948 SetLayerPropertiesForTesting(grand_child3.get(),
1949 identity_matrix,
[email protected]fb661802013-03-25 01:59:321950 gfx::PointF(),
1951 gfx::PointF(15.f, 15.f),
1952 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571953 true,
[email protected]fb661802013-03-25 01:59:321954 false);
1955 SetLayerPropertiesForTesting(grand_child4.get(),
1956 identity_matrix,
[email protected]fb661802013-03-25 01:59:321957 gfx::PointF(),
1958 gfx::PointF(45.f, 45.f),
1959 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571960 true,
[email protected]fb661802013-03-25 01:59:321961 false);
1962
1963 child->SetMasksToBounds(true);
1964 grand_child3->SetMasksToBounds(true);
1965
1966 // Force everyone to be a render surface.
1967 child->SetOpacity(0.4f);
1968 grand_child1->SetOpacity(0.5f);
1969 grand_child2->SetOpacity(0.5f);
1970 grand_child3->SetOpacity(0.5f);
1971 grand_child4->SetOpacity(0.5f);
1972
[email protected]989386c2013-07-18 21:37:231973 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531974 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1975 parent.get(), parent->bounds(), &render_surface_layer_list);
1976 inputs.can_adjust_raster_scales = true;
1977 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321978
[email protected]2c7c6702013-03-26 03:14:051979 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
[email protected]fb661802013-03-25 01:59:321980 grand_child1->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:051981 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:321982 grand_child3->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:051983 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:321984 grand_child3->drawable_content_rect());
1985 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
1986}
1987
[email protected]989386c2013-07-18 21:37:231988TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:321989 // Verify that render surfaces (and their layers) get the appropriate
1990 // clip rects when their parent masksToBounds is true.
1991 //
1992 // Layers that own render surfaces (at least for now) do not inherit any
1993 // clipping; instead the surface will enforce the clip for the entire subtree.
1994 // They may still have a clip rect of their own layer bounds, however, if
1995 // masksToBounds was true.
1996 const gfx::Transform identity_matrix;
1997 scoped_refptr<Layer> parent = Layer::Create();
1998 scoped_refptr<Layer> child = Layer::Create();
1999 scoped_refptr<Layer> grand_child1 = Layer::Create();
2000 scoped_refptr<Layer> grand_child2 = Layer::Create();
2001 scoped_refptr<Layer> grand_child3 = Layer::Create();
2002 scoped_refptr<Layer> grand_child4 = Layer::Create();
2003 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2004 make_scoped_refptr(new LayerWithForcedDrawsContent());
2005 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2006 make_scoped_refptr(new LayerWithForcedDrawsContent());
2007 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
2008 make_scoped_refptr(new LayerWithForcedDrawsContent());
2009 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
2010 make_scoped_refptr(new LayerWithForcedDrawsContent());
2011
2012 parent->AddChild(child);
2013 child->AddChild(grand_child1);
2014 child->AddChild(grand_child2);
2015 child->AddChild(grand_child3);
2016 child->AddChild(grand_child4);
2017
[email protected]d600df7d2013-08-03 02:34:282018 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2019 host->SetRootLayer(parent);
2020
[email protected]fb661802013-03-25 01:59:322021 // the leaf nodes ensure that these grand_children become render surfaces for
2022 // this test.
2023 grand_child1->AddChild(leaf_node1);
2024 grand_child2->AddChild(leaf_node2);
2025 grand_child3->AddChild(leaf_node3);
2026 grand_child4->AddChild(leaf_node4);
2027
2028 SetLayerPropertiesForTesting(parent.get(),
2029 identity_matrix,
[email protected]fb661802013-03-25 01:59:322030 gfx::PointF(),
2031 gfx::PointF(),
2032 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:572033 true,
[email protected]fb661802013-03-25 01:59:322034 false);
2035 SetLayerPropertiesForTesting(child.get(),
2036 identity_matrix,
[email protected]fb661802013-03-25 01:59:322037 gfx::PointF(),
2038 gfx::PointF(),
2039 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:572040 true,
[email protected]fb661802013-03-25 01:59:322041 false);
2042 SetLayerPropertiesForTesting(grand_child1.get(),
2043 identity_matrix,
[email protected]fb661802013-03-25 01:59:322044 gfx::PointF(),
2045 gfx::PointF(5.f, 5.f),
2046 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572047 true,
[email protected]fb661802013-03-25 01:59:322048 false);
2049 SetLayerPropertiesForTesting(grand_child2.get(),
2050 identity_matrix,
[email protected]fb661802013-03-25 01:59:322051 gfx::PointF(),
2052 gfx::PointF(15.f, 15.f),
2053 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572054 true,
[email protected]fb661802013-03-25 01:59:322055 false);
2056 SetLayerPropertiesForTesting(grand_child3.get(),
2057 identity_matrix,
[email protected]fb661802013-03-25 01:59:322058 gfx::PointF(),
2059 gfx::PointF(15.f, 15.f),
2060 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572061 true,
[email protected]fb661802013-03-25 01:59:322062 false);
2063 SetLayerPropertiesForTesting(grand_child4.get(),
2064 identity_matrix,
[email protected]fb661802013-03-25 01:59:322065 gfx::PointF(),
2066 gfx::PointF(45.f, 45.f),
2067 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572068 true,
[email protected]fb661802013-03-25 01:59:322069 false);
2070 SetLayerPropertiesForTesting(leaf_node1.get(),
2071 identity_matrix,
[email protected]fb661802013-03-25 01:59:322072 gfx::PointF(),
2073 gfx::PointF(),
2074 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572075 true,
[email protected]fb661802013-03-25 01:59:322076 false);
2077 SetLayerPropertiesForTesting(leaf_node2.get(),
2078 identity_matrix,
[email protected]fb661802013-03-25 01:59:322079 gfx::PointF(),
2080 gfx::PointF(),
2081 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572082 true,
[email protected]fb661802013-03-25 01:59:322083 false);
2084 SetLayerPropertiesForTesting(leaf_node3.get(),
2085 identity_matrix,
[email protected]fb661802013-03-25 01:59:322086 gfx::PointF(),
2087 gfx::PointF(),
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(leaf_node4.get(),
2092 identity_matrix,
[email protected]fb661802013-03-25 01:59:322093 gfx::PointF(),
2094 gfx::PointF(),
2095 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572096 true,
[email protected]fb661802013-03-25 01:59:322097 false);
2098
2099 child->SetMasksToBounds(true);
2100 grand_child3->SetMasksToBounds(true);
2101 grand_child4->SetMasksToBounds(true);
2102
2103 // Force everyone to be a render surface.
2104 child->SetOpacity(0.4f);
2105 child->SetForceRenderSurface(true);
2106 grand_child1->SetOpacity(0.5f);
2107 grand_child1->SetForceRenderSurface(true);
2108 grand_child2->SetOpacity(0.5f);
2109 grand_child2->SetForceRenderSurface(true);
2110 grand_child3->SetOpacity(0.5f);
2111 grand_child3->SetForceRenderSurface(true);
2112 grand_child4->SetOpacity(0.5f);
2113 grand_child4->SetForceRenderSurface(true);
2114
[email protected]989386c2013-07-18 21:37:232115 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532116 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2117 parent.get(), parent->bounds(), &render_surface_layer_list);
2118 inputs.can_adjust_raster_scales = true;
2119 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322120 ASSERT_TRUE(grand_child1->render_surface());
2121 ASSERT_TRUE(grand_child2->render_surface());
2122 ASSERT_TRUE(grand_child3->render_surface());
2123 // Because grand_child4 is entirely clipped, it is expected to not have a
2124 // render surface.
2125 EXPECT_FALSE(grand_child4->render_surface());
2126
2127 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2128 // masksToBounds.
[email protected]2c7c6702013-03-26 03:14:052129 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322130 grand_child1->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052131 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322132 grand_child2->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052133 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322134 grand_child3->render_surface()->clip_rect());
2135}
2136
[email protected]989386c2013-07-18 21:37:232137TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322138 scoped_refptr<Layer> parent = Layer::Create();
2139 scoped_refptr<Layer> render_surface1 = Layer::Create();
2140 scoped_refptr<Layer> render_surface2 = Layer::Create();
2141 scoped_refptr<Layer> child_of_root = Layer::Create();
2142 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2143 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2144 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2145 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2146 make_scoped_refptr(new LayerWithForcedDrawsContent());
2147 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2148 make_scoped_refptr(new LayerWithForcedDrawsContent());
2149 parent->AddChild(render_surface1);
2150 parent->AddChild(child_of_root);
2151 render_surface1->AddChild(child_of_rs1);
2152 render_surface1->AddChild(render_surface2);
2153 render_surface2->AddChild(child_of_rs2);
2154 child_of_root->AddChild(grand_child_of_root);
2155 child_of_rs1->AddChild(grand_child_of_rs1);
2156 child_of_rs2->AddChild(grand_child_of_rs2);
2157
[email protected]d600df7d2013-08-03 02:34:282158 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2159 host->SetRootLayer(parent);
2160
[email protected]fb661802013-03-25 01:59:322161 // Make our render surfaces.
2162 render_surface1->SetForceRenderSurface(true);
2163 render_surface2->SetForceRenderSurface(true);
2164
2165 gfx::Transform layer_transform;
2166 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322167
2168 SetLayerPropertiesForTesting(parent.get(),
2169 layer_transform,
[email protected]fb661802013-03-25 01:59:322170 gfx::PointF(0.25f, 0.f),
2171 gfx::PointF(2.5f, 0.f),
2172 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572173 true,
[email protected]fb661802013-03-25 01:59:322174 false);
2175 SetLayerPropertiesForTesting(render_surface1.get(),
2176 layer_transform,
[email protected]fb661802013-03-25 01:59:322177 gfx::PointF(0.25f, 0.f),
2178 gfx::PointF(2.5f, 0.f),
2179 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572180 true,
[email protected]fb661802013-03-25 01:59:322181 false);
2182 SetLayerPropertiesForTesting(render_surface2.get(),
2183 layer_transform,
[email protected]fb661802013-03-25 01:59:322184 gfx::PointF(0.25f, 0.f),
2185 gfx::PointF(2.5f, 0.f),
2186 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572187 true,
[email protected]fb661802013-03-25 01:59:322188 false);
2189 SetLayerPropertiesForTesting(child_of_root.get(),
2190 layer_transform,
[email protected]fb661802013-03-25 01:59:322191 gfx::PointF(0.25f, 0.f),
2192 gfx::PointF(2.5f, 0.f),
2193 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572194 true,
[email protected]fb661802013-03-25 01:59:322195 false);
2196 SetLayerPropertiesForTesting(child_of_rs1.get(),
2197 layer_transform,
[email protected]fb661802013-03-25 01:59:322198 gfx::PointF(0.25f, 0.f),
2199 gfx::PointF(2.5f, 0.f),
2200 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572201 true,
[email protected]fb661802013-03-25 01:59:322202 false);
2203 SetLayerPropertiesForTesting(child_of_rs2.get(),
2204 layer_transform,
[email protected]fb661802013-03-25 01:59:322205 gfx::PointF(0.25f, 0.f),
2206 gfx::PointF(2.5f, 0.f),
2207 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572208 true,
[email protected]fb661802013-03-25 01:59:322209 false);
2210 SetLayerPropertiesForTesting(grand_child_of_root.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(grand_child_of_rs1.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(grand_child_of_rs2.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
2232 // Put an animated opacity on the render surface.
2233 AddOpacityTransitionToController(
2234 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2235
2236 // Also put an animated opacity on a layer without descendants.
2237 AddOpacityTransitionToController(
2238 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2239
2240 // Put a transform animation on the render surface.
2241 AddAnimatedTransformToController(
2242 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2243
2244 // Also put transform animations on grand_child_of_root, and
2245 // grand_child_of_rs2
2246 AddAnimatedTransformToController(
2247 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2248 AddAnimatedTransformToController(
2249 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2250
2251 ExecuteCalculateDrawProperties(parent.get());
2252
2253 // Only layers that are associated with render surfaces should have an actual
2254 // RenderSurface() value.
2255 ASSERT_TRUE(parent->render_surface());
2256 ASSERT_FALSE(child_of_root->render_surface());
2257 ASSERT_FALSE(grand_child_of_root->render_surface());
2258
2259 ASSERT_TRUE(render_surface1->render_surface());
2260 ASSERT_FALSE(child_of_rs1->render_surface());
2261 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2262
2263 ASSERT_TRUE(render_surface2->render_surface());
2264 ASSERT_FALSE(child_of_rs2->render_surface());
2265 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2266
2267 // Verify all render target accessors
2268 EXPECT_EQ(parent, parent->render_target());
2269 EXPECT_EQ(parent, child_of_root->render_target());
2270 EXPECT_EQ(parent, grand_child_of_root->render_target());
2271
2272 EXPECT_EQ(render_surface1, render_surface1->render_target());
2273 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2274 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
2275
2276 EXPECT_EQ(render_surface2, render_surface2->render_target());
2277 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2278 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
2279
2280 // Verify draw_opacity_is_animating values
2281 EXPECT_FALSE(parent->draw_opacity_is_animating());
2282 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2283 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2284 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2285 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2286 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2287 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2288 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2289 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2290 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2291 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2292
2293 // Verify draw_transform_is_animating values
2294 EXPECT_FALSE(parent->draw_transform_is_animating());
2295 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2296 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2297 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2298 EXPECT_FALSE(render_surface1->render_surface()
2299 ->target_surface_transforms_are_animating());
2300 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2301 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2302 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2303 EXPECT_TRUE(render_surface2->render_surface()
2304 ->target_surface_transforms_are_animating());
2305 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2306 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2307
2308 // Verify screen_space_transform_is_animating values
2309 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2310 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2311 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2312 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2313 EXPECT_FALSE(render_surface1->render_surface()
2314 ->screen_space_transforms_are_animating());
2315 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2316 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2317 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2318 EXPECT_TRUE(render_surface2->render_surface()
2319 ->screen_space_transforms_are_animating());
2320 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2321 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2322
2323 // Sanity check. If these fail there is probably a bug in the test itself.
2324 // It is expected that we correctly set up transforms so that the y-component
2325 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262326 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2327 EXPECT_FLOAT_EQ(2.0,
2328 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322329 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262330 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322331
[email protected]803f6b52013-09-12 00:51:262332 EXPECT_FLOAT_EQ(2.0,
2333 render_surface1->screen_space_transform().matrix().get(1, 3));
2334 EXPECT_FLOAT_EQ(3.0,
2335 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322336 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262337 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322338
[email protected]803f6b52013-09-12 00:51:262339 EXPECT_FLOAT_EQ(3.0,
2340 render_surface2->screen_space_transform().matrix().get(1, 3));
2341 EXPECT_FLOAT_EQ(4.0,
2342 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322343 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262344 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322345}
2346
[email protected]989386c2013-07-18 21:37:232347TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322348 // Test the calculateVisibleRect() function works correctly for identity
2349 // transforms.
2350
[email protected]2c7c6702013-03-26 03:14:052351 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322352 gfx::Transform layer_to_surface_transform;
2353
2354 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232355 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052356 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322357 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2358 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2359 EXPECT_RECT_EQ(expected, actual);
2360
2361 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052362 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322363 actual = LayerTreeHostCommon::CalculateVisibleRect(
2364 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2365 EXPECT_TRUE(actual.IsEmpty());
2366
2367 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052368 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2369 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322370 actual = LayerTreeHostCommon::CalculateVisibleRect(
2371 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2372 EXPECT_RECT_EQ(expected, actual);
2373}
2374
[email protected]989386c2013-07-18 21:37:232375TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322376 // Test the calculateVisibleRect() function works correctly for scaling
2377 // transforms.
2378
[email protected]2c7c6702013-03-26 03:14:052379 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2380 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322381 gfx::Transform layer_to_surface_transform;
2382
2383 // Case 1: Layer is contained within the surface.
2384 layer_to_surface_transform.MakeIdentity();
2385 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052386 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322387 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2388 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2389 EXPECT_RECT_EQ(expected, actual);
2390
2391 // Case 2: Layer is outside the surface rect.
2392 layer_to_surface_transform.MakeIdentity();
2393 layer_to_surface_transform.Translate(120.0, 120.0);
2394 actual = LayerTreeHostCommon::CalculateVisibleRect(
2395 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2396 EXPECT_TRUE(actual.IsEmpty());
2397
2398 // Case 3: Layer is partially overlapping the surface rect.
2399 layer_to_surface_transform.MakeIdentity();
2400 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052401 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322402 actual = LayerTreeHostCommon::CalculateVisibleRect(
2403 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2404 EXPECT_RECT_EQ(expected, actual);
2405}
2406
[email protected]989386c2013-07-18 21:37:232407TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322408 // Test the calculateVisibleRect() function works correctly for rotations
2409 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2410 // should return the g in the layer's space.
2411
[email protected]2c7c6702013-03-26 03:14:052412 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2413 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322414 gfx::Transform layer_to_surface_transform;
2415
2416 // Case 1: Layer is contained within the surface.
2417 layer_to_surface_transform.MakeIdentity();
2418 layer_to_surface_transform.Translate(50.0, 50.0);
2419 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052420 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322421 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2422 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2423 EXPECT_RECT_EQ(expected, actual);
2424
2425 // Case 2: Layer is outside the surface rect.
2426 layer_to_surface_transform.MakeIdentity();
2427 layer_to_surface_transform.Translate(-50.0, 0.0);
2428 layer_to_surface_transform.Rotate(45.0);
2429 actual = LayerTreeHostCommon::CalculateVisibleRect(
2430 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2431 EXPECT_TRUE(actual.IsEmpty());
2432
2433 // Case 3: The layer is rotated about its top-left corner. In surface space,
2434 // the layer is oriented diagonally, with the left half outside of the render
2435 // surface. In this case, the g should still be the entire layer
2436 // (remember the g is computed in layer space); both the top-left
2437 // and bottom-right corners of the layer are still visible.
2438 layer_to_surface_transform.MakeIdentity();
2439 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052440 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322441 actual = LayerTreeHostCommon::CalculateVisibleRect(
2442 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2443 EXPECT_RECT_EQ(expected, actual);
2444
2445 // Case 4: The layer is rotated about its top-left corner, and translated
2446 // upwards. In surface space, the layer is oriented diagonally, with only the
2447 // top corner of the surface overlapping the layer. In layer space, the render
2448 // surface overlaps the right side of the layer. The g should be
2449 // the layer's right half.
2450 layer_to_surface_transform.MakeIdentity();
2451 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2452 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052453 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322454 actual = LayerTreeHostCommon::CalculateVisibleRect(
2455 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2456 EXPECT_RECT_EQ(expected, actual);
2457}
2458
[email protected]989386c2013-07-18 21:37:232459TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322460 // Test that the calculateVisibleRect() function works correctly for 3d
2461 // transforms.
2462
[email protected]2c7c6702013-03-26 03:14:052463 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2464 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322465 gfx::Transform layer_to_surface_transform;
2466
2467 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2468 // degrees, should be fully contained in the render surface.
2469 layer_to_surface_transform.MakeIdentity();
2470 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052471 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322472 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2473 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2474 EXPECT_RECT_EQ(expected, actual);
2475
2476 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2477 // degrees, but shifted to the side so only the right-half the layer would be
2478 // visible on the surface.
2479 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262480 SkMScalar half_width_of_rotated_layer =
2481 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322482 layer_to_surface_transform.MakeIdentity();
2483 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232484 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2485 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052486 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322487 actual = LayerTreeHostCommon::CalculateVisibleRect(
2488 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2489 EXPECT_RECT_EQ(expected, actual);
2490}
2491
[email protected]989386c2013-07-18 21:37:232492TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322493 // Test the calculateVisibleRect() function works correctly when the layer has
2494 // a perspective projection onto the target surface.
2495
[email protected]2c7c6702013-03-26 03:14:052496 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2497 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322498 gfx::Transform layer_to_surface_transform;
2499
2500 // Case 1: Even though the layer is twice as large as the surface, due to
2501 // perspective foreshortening, the layer will fit fully in the surface when
2502 // its translated more than the perspective amount.
2503 layer_to_surface_transform.MakeIdentity();
2504
2505 // The following sequence of transforms applies the perspective about the
2506 // center of the surface.
2507 layer_to_surface_transform.Translate(50.0, 50.0);
2508 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2509 layer_to_surface_transform.Translate(-50.0, -50.0);
2510
2511 // This translate places the layer in front of the surface's projection plane.
2512 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2513
[email protected]2c7c6702013-03-26 03:14:052514 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322515 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2516 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2517 EXPECT_RECT_EQ(expected, actual);
2518
2519 // Case 2: same projection as before, except that the layer is also translated
2520 // to the side, so that only the right half of the layer should be visible.
2521 //
2522 // Explanation of expected result: The perspective ratio is (z distance
2523 // between layer and camera origin) / (z distance between projection plane and
2524 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2525 // move a layer by translating -50 units in projected surface units (so that
2526 // only half of it is visible), then we would need to translate by (-36 / 9) *
2527 // -50 == -200 in the layer's units.
2528 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232529 expected = gfx::Rect(gfx::Point(50, -50),
2530 gfx::Size(100, 200)); // The right half of the layer's
2531 // bounding rect.
[email protected]fb661802013-03-25 01:59:322532 actual = LayerTreeHostCommon::CalculateVisibleRect(
2533 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2534 EXPECT_RECT_EQ(expected, actual);
2535}
2536
[email protected]989386c2013-07-18 21:37:232537TEST_F(LayerTreeHostCommonTest,
2538 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322539 // There is currently no explicit concept of an orthographic projection plane
2540 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2541 // are technically behind the surface in an orthographic world should not be
2542 // clipped when they are flattened to the surface.
2543
[email protected]2c7c6702013-03-26 03:14:052544 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2545 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322546 gfx::Transform layer_to_surface_transform;
2547
2548 // This sequence of transforms effectively rotates the layer about the y-axis
2549 // at the center of the layer.
2550 layer_to_surface_transform.MakeIdentity();
2551 layer_to_surface_transform.Translate(50.0, 0.0);
2552 layer_to_surface_transform.RotateAboutYAxis(45.0);
2553 layer_to_surface_transform.Translate(-50.0, 0.0);
2554
[email protected]2c7c6702013-03-26 03:14:052555 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322556 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2557 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2558 EXPECT_RECT_EQ(expected, actual);
2559}
2560
[email protected]989386c2013-07-18 21:37:232561TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322562 // Test the calculateVisibleRect() function works correctly when projecting a
2563 // surface onto a layer, but the layer is partially behind the camera (not
2564 // just behind the projection plane). In this case, the cartesian coordinates
2565 // may seem to be valid, but actually they are not. The visible rect needs to
2566 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2567 // converting to cartesian coordinates.
2568
[email protected]2c7c6702013-03-26 03:14:052569 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232570 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322571 gfx::Transform layer_to_surface_transform;
2572
2573 // The layer is positioned so that the right half of the layer should be in
2574 // front of the camera, while the other half is behind the surface's
2575 // projection plane. The following sequence of transforms applies the
2576 // perspective and rotation about the center of the layer.
2577 layer_to_surface_transform.MakeIdentity();
2578 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2579 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2580 layer_to_surface_transform.RotateAboutYAxis(45.0);
2581
2582 // Sanity check that this transform does indeed cause w < 0 when applying the
2583 // transform, otherwise this code is not testing the intended scenario.
2584 bool clipped;
2585 MathUtil::MapQuad(layer_to_surface_transform,
2586 gfx::QuadF(gfx::RectF(layer_content_rect)),
2587 &clipped);
2588 ASSERT_TRUE(clipped);
2589
2590 int expected_x_position = 0;
2591 int expected_width = 10;
2592 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2593 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2594 EXPECT_EQ(expected_x_position, actual.x());
2595 EXPECT_EQ(expected_width, actual.width());
2596}
2597
[email protected]989386c2013-07-18 21:37:232598TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322599 // To determine visible rect in layer space, there needs to be an
2600 // un-projection from surface space to layer space. When the original
2601 // transform was a perspective projection that was clipped, it returns a rect
2602 // that encloses the clipped bounds. Un-projecting this new rect may require
2603 // clipping again.
2604
2605 // This sequence of transforms causes one corner of the layer to protrude
2606 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232607 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2608 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322609 gfx::Transform layer_to_surface_transform;
2610 layer_to_surface_transform.MakeIdentity();
2611 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2612 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2613 layer_to_surface_transform.RotateAboutYAxis(45.0);
2614 layer_to_surface_transform.RotateAboutXAxis(80.0);
2615
2616 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2617 // code is not testing the intended scenario.
2618 bool clipped;
2619 gfx::RectF clipped_rect =
2620 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2621 MathUtil::ProjectQuad(
2622 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2623 ASSERT_TRUE(clipped);
2624
2625 // Only the corner of the layer is not visible on the surface because of being
2626 // clipped. But, the net result of rounding visible region to an axis-aligned
2627 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052628 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322629 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2630 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2631 EXPECT_RECT_EQ(expected, actual);
2632}
2633
[email protected]989386c2013-07-18 21:37:232634TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322635 scoped_refptr<Layer> root = Layer::Create();
2636 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2637 make_scoped_refptr(new LayerWithForcedDrawsContent());
2638 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2639 make_scoped_refptr(new LayerWithForcedDrawsContent());
2640 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2641 make_scoped_refptr(new LayerWithForcedDrawsContent());
2642 root->AddChild(child1);
2643 root->AddChild(child2);
2644 root->AddChild(child3);
2645
[email protected]d600df7d2013-08-03 02:34:282646 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2647 host->SetRootLayer(root);
2648
[email protected]fb661802013-03-25 01:59:322649 gfx::Transform identity_matrix;
2650 SetLayerPropertiesForTesting(root.get(),
2651 identity_matrix,
[email protected]fb661802013-03-25 01:59:322652 gfx::PointF(),
2653 gfx::PointF(),
2654 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572655 true,
[email protected]fb661802013-03-25 01:59:322656 false);
2657 SetLayerPropertiesForTesting(child1.get(),
2658 identity_matrix,
[email protected]fb661802013-03-25 01:59:322659 gfx::PointF(),
2660 gfx::PointF(),
2661 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572662 true,
[email protected]fb661802013-03-25 01:59:322663 false);
2664 SetLayerPropertiesForTesting(child2.get(),
2665 identity_matrix,
[email protected]fb661802013-03-25 01:59:322666 gfx::PointF(),
2667 gfx::PointF(75.f, 75.f),
2668 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572669 true,
[email protected]fb661802013-03-25 01:59:322670 false);
2671 SetLayerPropertiesForTesting(child3.get(),
2672 identity_matrix,
[email protected]fb661802013-03-25 01:59:322673 gfx::PointF(),
2674 gfx::PointF(125.f, 125.f),
2675 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572676 true,
[email protected]fb661802013-03-25 01:59:322677 false);
2678
2679 ExecuteCalculateDrawProperties(root.get());
2680
2681 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2682 root->render_surface()->DrawableContentRect());
2683 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2684
2685 // Layers that do not draw content should have empty visible_content_rects.
2686 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2687
2688 // layer visible_content_rects are clipped by their target surface.
2689 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2690 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
2691 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
2692
2693 // layer drawable_content_rects are not clipped.
2694 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2695 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2696 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2697}
2698
[email protected]989386c2013-07-18 21:37:232699TEST_F(LayerTreeHostCommonTest,
2700 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:322701 scoped_refptr<Layer> root = Layer::Create();
2702 scoped_refptr<Layer> child = Layer::Create();
2703 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
2704 make_scoped_refptr(new LayerWithForcedDrawsContent());
2705 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
2706 make_scoped_refptr(new LayerWithForcedDrawsContent());
2707 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
2708 make_scoped_refptr(new LayerWithForcedDrawsContent());
2709 root->AddChild(child);
2710 child->AddChild(grand_child1);
2711 child->AddChild(grand_child2);
2712 child->AddChild(grand_child3);
2713
[email protected]d600df7d2013-08-03 02:34:282714 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2715 host->SetRootLayer(root);
2716
[email protected]fb661802013-03-25 01:59:322717 gfx::Transform identity_matrix;
2718 SetLayerPropertiesForTesting(root.get(),
2719 identity_matrix,
[email protected]fb661802013-03-25 01:59:322720 gfx::PointF(),
2721 gfx::PointF(),
2722 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572723 true,
[email protected]fb661802013-03-25 01:59:322724 false);
2725 SetLayerPropertiesForTesting(child.get(),
2726 identity_matrix,
[email protected]fb661802013-03-25 01:59:322727 gfx::PointF(),
2728 gfx::PointF(),
2729 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572730 true,
[email protected]fb661802013-03-25 01:59:322731 false);
2732 SetLayerPropertiesForTesting(grand_child1.get(),
2733 identity_matrix,
[email protected]fb661802013-03-25 01:59:322734 gfx::PointF(),
2735 gfx::PointF(5.f, 5.f),
2736 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572737 true,
[email protected]fb661802013-03-25 01:59:322738 false);
2739 SetLayerPropertiesForTesting(grand_child2.get(),
2740 identity_matrix,
[email protected]fb661802013-03-25 01:59:322741 gfx::PointF(),
2742 gfx::PointF(75.f, 75.f),
2743 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572744 true,
[email protected]fb661802013-03-25 01:59:322745 false);
2746 SetLayerPropertiesForTesting(grand_child3.get(),
2747 identity_matrix,
[email protected]fb661802013-03-25 01:59:322748 gfx::PointF(),
2749 gfx::PointF(125.f, 125.f),
2750 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572751 true,
[email protected]fb661802013-03-25 01:59:322752 false);
2753
2754 child->SetMasksToBounds(true);
2755 ExecuteCalculateDrawProperties(root.get());
2756
2757 ASSERT_FALSE(child->render_surface());
2758
2759 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2760 root->render_surface()->DrawableContentRect());
2761 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2762
2763 // Layers that do not draw content should have empty visible content rects.
2764 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2765 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
2766
2767 // All grandchild visible content rects should be clipped by child.
2768 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
2769 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
2770 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
2771
2772 // All grandchild DrawableContentRects should also be clipped by child.
2773 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
2774 grand_child1->drawable_content_rect());
2775 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
2776 grand_child2->drawable_content_rect());
2777 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2778}
2779
[email protected]989386c2013-07-18 21:37:232780TEST_F(LayerTreeHostCommonTest,
2781 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322782 scoped_refptr<Layer> root = Layer::Create();
2783 scoped_refptr<Layer> render_surface1 = Layer::Create();
2784 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2785 make_scoped_refptr(new LayerWithForcedDrawsContent());
2786 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2787 make_scoped_refptr(new LayerWithForcedDrawsContent());
2788 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2789 make_scoped_refptr(new LayerWithForcedDrawsContent());
2790 root->AddChild(render_surface1);
2791 render_surface1->AddChild(child1);
2792 render_surface1->AddChild(child2);
2793 render_surface1->AddChild(child3);
2794
[email protected]d600df7d2013-08-03 02:34:282795 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2796 host->SetRootLayer(root);
2797
[email protected]fb661802013-03-25 01:59:322798 gfx::Transform identity_matrix;
2799 SetLayerPropertiesForTesting(root.get(),
2800 identity_matrix,
[email protected]fb661802013-03-25 01:59:322801 gfx::PointF(),
2802 gfx::PointF(),
2803 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572804 true,
[email protected]fb661802013-03-25 01:59:322805 false);
2806 SetLayerPropertiesForTesting(render_surface1.get(),
2807 identity_matrix,
[email protected]fb661802013-03-25 01:59:322808 gfx::PointF(),
2809 gfx::PointF(),
2810 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572811 true,
[email protected]fb661802013-03-25 01:59:322812 false);
2813 SetLayerPropertiesForTesting(child1.get(),
2814 identity_matrix,
[email protected]fb661802013-03-25 01:59:322815 gfx::PointF(),
2816 gfx::PointF(5.f, 5.f),
2817 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572818 true,
[email protected]fb661802013-03-25 01:59:322819 false);
2820 SetLayerPropertiesForTesting(child2.get(),
2821 identity_matrix,
[email protected]fb661802013-03-25 01:59:322822 gfx::PointF(),
2823 gfx::PointF(75.f, 75.f),
2824 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572825 true,
[email protected]fb661802013-03-25 01:59:322826 false);
2827 SetLayerPropertiesForTesting(child3.get(),
2828 identity_matrix,
[email protected]fb661802013-03-25 01:59:322829 gfx::PointF(),
2830 gfx::PointF(125.f, 125.f),
2831 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572832 true,
[email protected]fb661802013-03-25 01:59:322833 false);
2834
2835 render_surface1->SetForceRenderSurface(true);
2836 ExecuteCalculateDrawProperties(root.get());
2837
2838 ASSERT_TRUE(render_surface1->render_surface());
2839
2840 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2841 root->render_surface()->DrawableContentRect());
2842 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2843
2844 // Layers that do not draw content should have empty visible content rects.
2845 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2846 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2847 render_surface1->visible_content_rect());
2848
2849 // An unclipped surface grows its DrawableContentRect to include all drawable
2850 // regions of the subtree.
2851 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
2852 render_surface1->render_surface()->DrawableContentRect());
2853
2854 // All layers that draw content into the unclipped surface are also unclipped.
2855 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2856 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
2857 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
2858
2859 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2860 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2861 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2862}
2863
[email protected]989386c2013-07-18 21:37:232864TEST_F(LayerTreeHostCommonTest,
2865 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:472866 scoped_refptr<Layer> root = Layer::Create();
2867 scoped_refptr<LayerWithForcedDrawsContent> child =
2868 make_scoped_refptr(new LayerWithForcedDrawsContent());
2869 root->AddChild(child);
2870
[email protected]d600df7d2013-08-03 02:34:282871 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2872 host->SetRootLayer(root);
2873
[email protected]630ddad2013-08-16 03:01:322874 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:472875 gfx::Transform identity_matrix;
2876 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:322877 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:472878
2879 SetLayerPropertiesForTesting(root.get(),
2880 identity_matrix,
[email protected]451107a32013-04-10 05:12:472881 gfx::PointF(),
2882 gfx::PointF(),
2883 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572884 true,
[email protected]451107a32013-04-10 05:12:472885 false);
2886 SetLayerPropertiesForTesting(child.get(),
2887 uninvertible_matrix,
[email protected]451107a32013-04-10 05:12:472888 gfx::PointF(),
2889 gfx::PointF(5.f, 5.f),
2890 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572891 true,
[email protected]451107a32013-04-10 05:12:472892 false);
2893
2894 ExecuteCalculateDrawProperties(root.get());
2895
2896 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2897 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322898
2899 // Case 2: a matrix with flattened z, technically uninvertible but still
2900 // drawable and visible. In this case, we must assume that the entire layer
2901 // bounds are visible since there is no way to inverse-project the surface
2902 // bounds to intersect.
2903 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:262904 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322905 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2906
2907 SetLayerPropertiesForTesting(child.get(),
2908 uninvertible_matrix,
[email protected]630ddad2013-08-16 03:01:322909 gfx::PointF(),
2910 gfx::PointF(5.f, 5.f),
2911 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572912 true,
[email protected]630ddad2013-08-16 03:01:322913 false);
2914
2915 ExecuteCalculateDrawProperties(root.get());
2916
2917 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child->visible_content_rect());
2918 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child->drawable_content_rect());
2919
2920 // Case 3: a matrix with flattened z, technically uninvertible but still
2921 // drawable, but not visible. In this case, we don't need to conservatively
2922 // assume that the whole layer is visible.
2923 uninvertible_matrix.MakeIdentity();
2924 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:262925 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322926 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2927
2928 SetLayerPropertiesForTesting(child.get(),
2929 uninvertible_matrix,
[email protected]630ddad2013-08-16 03:01:322930 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]630ddad2013-08-16 03:01:322934 false);
2935
2936 ExecuteCalculateDrawProperties(root.get());
2937
2938 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2939 EXPECT_RECT_EQ(gfx::Rect(505, 5, 50, 50), child->drawable_content_rect());
[email protected]451107a32013-04-10 05:12:472940}
2941
[email protected]989386c2013-07-18 21:37:232942TEST_F(LayerTreeHostCommonTest,
2943 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322944 scoped_refptr<Layer> root = Layer::Create();
2945 scoped_refptr<Layer> render_surface1 = Layer::Create();
2946 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2947 make_scoped_refptr(new LayerWithForcedDrawsContent());
2948 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2949 make_scoped_refptr(new LayerWithForcedDrawsContent());
2950 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2951 make_scoped_refptr(new LayerWithForcedDrawsContent());
2952 root->AddChild(render_surface1);
2953 render_surface1->AddChild(child1);
2954 render_surface1->AddChild(child2);
2955 render_surface1->AddChild(child3);
2956
[email protected]d600df7d2013-08-03 02:34:282957 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2958 host->SetRootLayer(root);
2959
[email protected]fb661802013-03-25 01:59:322960 gfx::Transform identity_matrix;
2961 SetLayerPropertiesForTesting(root.get(),
2962 identity_matrix,
[email protected]fb661802013-03-25 01:59:322963 gfx::PointF(),
2964 gfx::PointF(),
2965 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572966 true,
[email protected]fb661802013-03-25 01:59:322967 false);
2968 SetLayerPropertiesForTesting(render_surface1.get(),
2969 identity_matrix,
[email protected]fb661802013-03-25 01:59:322970 gfx::PointF(),
2971 gfx::PointF(),
2972 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572973 true,
[email protected]fb661802013-03-25 01:59:322974 false);
2975 SetLayerPropertiesForTesting(child1.get(),
2976 identity_matrix,
[email protected]fb661802013-03-25 01:59:322977 gfx::PointF(),
2978 gfx::PointF(5.f, 5.f),
2979 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572980 true,
[email protected]fb661802013-03-25 01:59:322981 false);
2982 SetLayerPropertiesForTesting(child2.get(),
2983 identity_matrix,
[email protected]fb661802013-03-25 01:59:322984 gfx::PointF(),
2985 gfx::PointF(75.f, 75.f),
2986 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572987 true,
[email protected]fb661802013-03-25 01:59:322988 false);
2989 SetLayerPropertiesForTesting(child3.get(),
2990 identity_matrix,
[email protected]fb661802013-03-25 01:59:322991 gfx::PointF(),
2992 gfx::PointF(125.f, 125.f),
2993 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572994 true,
[email protected]fb661802013-03-25 01:59:322995 false);
2996
2997 root->SetMasksToBounds(true);
2998 render_surface1->SetForceRenderSurface(true);
2999 ExecuteCalculateDrawProperties(root.get());
3000
3001 ASSERT_TRUE(render_surface1->render_surface());
3002
3003 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3004 root->render_surface()->DrawableContentRect());
3005 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3006
3007 // Layers that do not draw content should have empty visible content rects.
3008 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3009 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3010 render_surface1->visible_content_rect());
3011
3012 // A clipped surface grows its DrawableContentRect to include all drawable
3013 // regions of the subtree, but also gets clamped by the ancestor's clip.
3014 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3015 render_surface1->render_surface()->DrawableContentRect());
3016
3017 // All layers that draw content into the surface have their visible content
3018 // rect clipped by the surface clip rect.
3019 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3020 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
3021 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3022
3023 // But the DrawableContentRects are unclipped.
3024 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3025 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3026 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3027}
3028
[email protected]989386c2013-07-18 21:37:233029TEST_F(LayerTreeHostCommonTest,
3030 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323031 // Check that clipping does not propagate down surfaces.
3032 scoped_refptr<Layer> root = Layer::Create();
3033 scoped_refptr<Layer> render_surface1 = Layer::Create();
3034 scoped_refptr<Layer> render_surface2 = Layer::Create();
3035 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3036 make_scoped_refptr(new LayerWithForcedDrawsContent());
3037 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3038 make_scoped_refptr(new LayerWithForcedDrawsContent());
3039 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3040 make_scoped_refptr(new LayerWithForcedDrawsContent());
3041 root->AddChild(render_surface1);
3042 render_surface1->AddChild(render_surface2);
3043 render_surface2->AddChild(child1);
3044 render_surface2->AddChild(child2);
3045 render_surface2->AddChild(child3);
3046
[email protected]d600df7d2013-08-03 02:34:283047 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3048 host->SetRootLayer(root);
3049
[email protected]fb661802013-03-25 01:59:323050 gfx::Transform identity_matrix;
3051 SetLayerPropertiesForTesting(root.get(),
3052 identity_matrix,
[email protected]fb661802013-03-25 01:59:323053 gfx::PointF(),
3054 gfx::PointF(),
3055 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573056 true,
[email protected]fb661802013-03-25 01:59:323057 false);
3058 SetLayerPropertiesForTesting(render_surface1.get(),
3059 identity_matrix,
[email protected]fb661802013-03-25 01:59:323060 gfx::PointF(),
3061 gfx::PointF(),
3062 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573063 true,
[email protected]fb661802013-03-25 01:59:323064 false);
3065 SetLayerPropertiesForTesting(render_surface2.get(),
3066 identity_matrix,
[email protected]fb661802013-03-25 01:59:323067 gfx::PointF(),
3068 gfx::PointF(),
3069 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573070 true,
[email protected]fb661802013-03-25 01:59:323071 false);
3072 SetLayerPropertiesForTesting(child1.get(),
3073 identity_matrix,
[email protected]fb661802013-03-25 01:59:323074 gfx::PointF(),
3075 gfx::PointF(5.f, 5.f),
3076 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573077 true,
[email protected]fb661802013-03-25 01:59:323078 false);
3079 SetLayerPropertiesForTesting(child2.get(),
3080 identity_matrix,
[email protected]fb661802013-03-25 01:59:323081 gfx::PointF(),
3082 gfx::PointF(75.f, 75.f),
3083 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573084 true,
[email protected]fb661802013-03-25 01:59:323085 false);
3086 SetLayerPropertiesForTesting(child3.get(),
3087 identity_matrix,
[email protected]fb661802013-03-25 01:59:323088 gfx::PointF(),
3089 gfx::PointF(125.f, 125.f),
3090 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573091 true,
[email protected]fb661802013-03-25 01:59:323092 false);
3093
3094 root->SetMasksToBounds(true);
3095 render_surface1->SetForceRenderSurface(true);
3096 render_surface2->SetForceRenderSurface(true);
3097 ExecuteCalculateDrawProperties(root.get());
3098
3099 ASSERT_TRUE(render_surface1->render_surface());
3100 ASSERT_TRUE(render_surface2->render_surface());
3101
3102 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3103 root->render_surface()->DrawableContentRect());
3104 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3105
3106 // Layers that do not draw content should have empty visible content rects.
3107 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3108 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3109 render_surface1->visible_content_rect());
3110 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3111 render_surface2->visible_content_rect());
3112
3113 // A clipped surface grows its DrawableContentRect to include all drawable
3114 // regions of the subtree, but also gets clamped by the ancestor's clip.
3115 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3116 render_surface1->render_surface()->DrawableContentRect());
3117
3118 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3119 // is only implicitly clipped by render_surface1's content rect. So,
3120 // render_surface2 grows to enclose all drawable content of its subtree.
3121 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3122 render_surface2->render_surface()->DrawableContentRect());
3123
3124 // All layers that draw content into render_surface2 think they are unclipped.
3125 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3126 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3127 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
3128
3129 // DrawableContentRects are also unclipped.
3130 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3131 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3132 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3133}
3134
[email protected]989386c2013-07-18 21:37:233135TEST_F(LayerTreeHostCommonTest,
3136 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323137 // Layers that have non-axis aligned bounds (due to transforms) have an
3138 // expanded, axis-aligned DrawableContentRect and visible content rect.
3139
3140 scoped_refptr<Layer> root = Layer::Create();
3141 scoped_refptr<Layer> render_surface1 = Layer::Create();
3142 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3143 make_scoped_refptr(new LayerWithForcedDrawsContent());
3144 root->AddChild(render_surface1);
3145 render_surface1->AddChild(child1);
3146
[email protected]d600df7d2013-08-03 02:34:283147 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3148 host->SetRootLayer(root);
3149
[email protected]fb661802013-03-25 01:59:323150 gfx::Transform identity_matrix;
3151 gfx::Transform child_rotation;
3152 child_rotation.Rotate(45.0);
3153 SetLayerPropertiesForTesting(root.get(),
3154 identity_matrix,
[email protected]fb661802013-03-25 01:59:323155 gfx::PointF(),
3156 gfx::PointF(),
3157 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573158 true,
[email protected]fb661802013-03-25 01:59:323159 false);
3160 SetLayerPropertiesForTesting(render_surface1.get(),
3161 identity_matrix,
[email protected]fb661802013-03-25 01:59:323162 gfx::PointF(),
3163 gfx::PointF(),
3164 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573165 true,
[email protected]fb661802013-03-25 01:59:323166 false);
3167 SetLayerPropertiesForTesting(child1.get(),
3168 child_rotation,
[email protected]fb661802013-03-25 01:59:323169 gfx::PointF(0.5f, 0.5f),
3170 gfx::PointF(25.f, 25.f),
3171 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573172 true,
[email protected]fb661802013-03-25 01:59:323173 false);
3174
3175 render_surface1->SetForceRenderSurface(true);
3176 ExecuteCalculateDrawProperties(root.get());
3177
3178 ASSERT_TRUE(render_surface1->render_surface());
3179
3180 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3181 root->render_surface()->DrawableContentRect());
3182 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3183
3184 // Layers that do not draw content should have empty visible content rects.
3185 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3186 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3187 render_surface1->visible_content_rect());
3188
3189 // The unclipped surface grows its DrawableContentRect to include all drawable
3190 // regions of the subtree.
3191 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3192 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263193 gfx::Rect(50 - diagonal_radius,
3194 50 - diagonal_radius,
3195 diagonal_radius * 2,
3196 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323197 EXPECT_RECT_EQ(expected_surface_drawable_content,
3198 render_surface1->render_surface()->DrawableContentRect());
3199
3200 // All layers that draw content into the unclipped surface are also unclipped.
3201 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3202 EXPECT_RECT_EQ(expected_surface_drawable_content,
3203 child1->drawable_content_rect());
3204}
3205
[email protected]989386c2013-07-18 21:37:233206TEST_F(LayerTreeHostCommonTest,
3207 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323208 // Layers that have non-axis aligned bounds (due to transforms) have an
3209 // expanded, axis-aligned DrawableContentRect and visible content rect.
3210
3211 scoped_refptr<Layer> root = Layer::Create();
3212 scoped_refptr<Layer> render_surface1 = Layer::Create();
3213 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3214 make_scoped_refptr(new LayerWithForcedDrawsContent());
3215 root->AddChild(render_surface1);
3216 render_surface1->AddChild(child1);
3217
[email protected]d600df7d2013-08-03 02:34:283218 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3219 host->SetRootLayer(root);
3220
[email protected]fb661802013-03-25 01:59:323221 gfx::Transform identity_matrix;
3222 gfx::Transform child_rotation;
3223 child_rotation.Rotate(45.0);
3224 SetLayerPropertiesForTesting(root.get(),
3225 identity_matrix,
[email protected]fb661802013-03-25 01:59:323226 gfx::PointF(),
3227 gfx::PointF(),
3228 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573229 true,
[email protected]fb661802013-03-25 01:59:323230 false);
3231 SetLayerPropertiesForTesting(render_surface1.get(),
3232 identity_matrix,
[email protected]fb661802013-03-25 01:59:323233 gfx::PointF(),
3234 gfx::PointF(),
3235 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573236 true,
[email protected]fb661802013-03-25 01:59:323237 false);
3238 SetLayerPropertiesForTesting(child1.get(),
3239 child_rotation,
[email protected]fb661802013-03-25 01:59:323240 gfx::PointF(0.5f, 0.5f),
3241 gfx::PointF(25.f, 25.f),
3242 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573243 true,
[email protected]fb661802013-03-25 01:59:323244 false);
3245
3246 root->SetMasksToBounds(true);
3247 render_surface1->SetForceRenderSurface(true);
3248 ExecuteCalculateDrawProperties(root.get());
3249
3250 ASSERT_TRUE(render_surface1->render_surface());
3251
3252 // The clipped surface clamps the DrawableContentRect that encloses the
3253 // rotated layer.
3254 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263255 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3256 50 - diagonal_radius,
3257 diagonal_radius * 2,
3258 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323259 gfx::Rect expected_surface_drawable_content =
3260 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
3261 EXPECT_RECT_EQ(expected_surface_drawable_content,
3262 render_surface1->render_surface()->DrawableContentRect());
3263
3264 // On the clipped surface, only a quarter of the child1 is visible, but when
3265 // rotating it back to child1's content space, the actual enclosing rect ends
3266 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263267 //
3268 // Given the floating point math, this number is a little bit fuzzy.
[email protected]fb661802013-03-25 01:59:323269 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
3270
3271 // The child's DrawableContentRect is unclipped.
3272 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3273}
3274
[email protected]989386c2013-07-18 21:37:233275TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323276 MockContentLayerClient client;
3277
3278 scoped_refptr<Layer> root = Layer::Create();
3279 scoped_refptr<ContentLayer> render_surface1 =
3280 CreateDrawableContentLayer(&client);
3281 scoped_refptr<ContentLayer> render_surface2 =
3282 CreateDrawableContentLayer(&client);
3283 scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client);
3284 scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client);
3285 scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client);
3286 root->AddChild(render_surface1);
3287 render_surface1->AddChild(render_surface2);
3288 render_surface2->AddChild(child1);
3289 render_surface2->AddChild(child2);
3290 render_surface2->AddChild(child3);
3291
[email protected]d600df7d2013-08-03 02:34:283292 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3293 host->SetRootLayer(root);
3294
[email protected]fb661802013-03-25 01:59:323295 gfx::Transform identity_matrix;
3296 SetLayerPropertiesForTesting(root.get(),
3297 identity_matrix,
[email protected]fb661802013-03-25 01:59:323298 gfx::PointF(),
3299 gfx::PointF(),
3300 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573301 true,
[email protected]fb661802013-03-25 01:59:323302 false);
3303 SetLayerPropertiesForTesting(render_surface1.get(),
3304 identity_matrix,
[email protected]fb661802013-03-25 01:59:323305 gfx::PointF(),
3306 gfx::PointF(5.f, 5.f),
3307 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573308 true,
[email protected]fb661802013-03-25 01:59:323309 false);
3310 SetLayerPropertiesForTesting(render_surface2.get(),
3311 identity_matrix,
[email protected]fb661802013-03-25 01:59:323312 gfx::PointF(),
3313 gfx::PointF(5.f, 5.f),
3314 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573315 true,
[email protected]fb661802013-03-25 01:59:323316 false);
3317 SetLayerPropertiesForTesting(child1.get(),
3318 identity_matrix,
[email protected]fb661802013-03-25 01:59:323319 gfx::PointF(),
3320 gfx::PointF(5.f, 5.f),
3321 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573322 true,
[email protected]fb661802013-03-25 01:59:323323 false);
3324 SetLayerPropertiesForTesting(child2.get(),
3325 identity_matrix,
[email protected]fb661802013-03-25 01:59:323326 gfx::PointF(),
3327 gfx::PointF(75.f, 75.f),
3328 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573329 true,
[email protected]fb661802013-03-25 01:59:323330 false);
3331 SetLayerPropertiesForTesting(child3.get(),
3332 identity_matrix,
[email protected]fb661802013-03-25 01:59:323333 gfx::PointF(),
3334 gfx::PointF(125.f, 125.f),
3335 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573336 true,
[email protected]fb661802013-03-25 01:59:323337 false);
3338
3339 float device_scale_factor = 2.f;
3340
3341 root->SetMasksToBounds(true);
3342 render_surface1->SetForceRenderSurface(true);
3343 render_surface2->SetForceRenderSurface(true);
3344 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3345
3346 ASSERT_TRUE(render_surface1->render_surface());
3347 ASSERT_TRUE(render_surface2->render_surface());
3348
3349 // drawable_content_rects for all layers and surfaces are scaled by
3350 // device_scale_factor.
3351 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3352 root->render_surface()->DrawableContentRect());
3353 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3354 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3355 render_surface1->render_surface()->DrawableContentRect());
3356
3357 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3358 // is only implicitly clipped by render_surface1.
3359 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3360 render_surface2->render_surface()->DrawableContentRect());
3361
3362 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3363 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3364 child2->drawable_content_rect());
3365 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3366 child3->drawable_content_rect());
3367
3368 // The root layer does not actually draw content of its own.
3369 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3370
3371 // All layer visible content rects are expressed in content space of each
3372 // layer, so they are also scaled by the device_scale_factor.
3373 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8),
3374 render_surface1->visible_content_rect());
3375 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26),
3376 render_surface2->visible_content_rect());
3377 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect());
3378 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect());
3379 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect());
3380}
3381
[email protected]989386c2013-07-18 21:37:233382TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323383 // Verify the behavior of back-face culling when there are no preserve-3d
3384 // layers. Note that 3d transforms still apply in this case, but they are
3385 // "flattened" to each parent layer according to current W3C spec.
3386
3387 const gfx::Transform identity_matrix;
3388 scoped_refptr<Layer> parent = Layer::Create();
3389 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3390 make_scoped_refptr(new LayerWithForcedDrawsContent());
3391 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3392 make_scoped_refptr(new LayerWithForcedDrawsContent());
3393 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3394 make_scoped_refptr(new LayerWithForcedDrawsContent());
3395 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3396 make_scoped_refptr(new LayerWithForcedDrawsContent());
3397 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233398 front_facing_child_of_front_facing_surface =
3399 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323400 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233401 back_facing_child_of_front_facing_surface =
3402 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323403 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233404 front_facing_child_of_back_facing_surface =
3405 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323406 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233407 back_facing_child_of_back_facing_surface =
3408 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323409
3410 parent->AddChild(front_facing_child);
3411 parent->AddChild(back_facing_child);
3412 parent->AddChild(front_facing_surface);
3413 parent->AddChild(back_facing_surface);
3414 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3415 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3416 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3417 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3418
[email protected]d600df7d2013-08-03 02:34:283419 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3420 host->SetRootLayer(parent);
3421
[email protected]fb661802013-03-25 01:59:323422 // Nothing is double-sided
3423 front_facing_child->SetDoubleSided(false);
3424 back_facing_child->SetDoubleSided(false);
3425 front_facing_surface->SetDoubleSided(false);
3426 back_facing_surface->SetDoubleSided(false);
3427 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3428 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3429 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3430 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3431
3432 gfx::Transform backface_matrix;
3433 backface_matrix.Translate(50.0, 50.0);
3434 backface_matrix.RotateAboutYAxis(180.0);
3435 backface_matrix.Translate(-50.0, -50.0);
3436
3437 // Having a descendant and opacity will force these to have render surfaces.
3438 front_facing_surface->SetOpacity(0.5f);
3439 back_facing_surface->SetOpacity(0.5f);
3440
3441 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3442 // these layers should blindly use their own local transforms to determine
3443 // back-face culling.
3444 SetLayerPropertiesForTesting(parent.get(),
3445 identity_matrix,
[email protected]fb661802013-03-25 01:59:323446 gfx::PointF(),
3447 gfx::PointF(),
3448 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573449 true,
[email protected]fb661802013-03-25 01:59:323450 false);
3451 SetLayerPropertiesForTesting(front_facing_child.get(),
3452 identity_matrix,
[email protected]fb661802013-03-25 01:59:323453 gfx::PointF(),
3454 gfx::PointF(),
3455 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573456 true,
[email protected]fb661802013-03-25 01:59:323457 false);
3458 SetLayerPropertiesForTesting(back_facing_child.get(),
3459 backface_matrix,
[email protected]fb661802013-03-25 01:59:323460 gfx::PointF(),
3461 gfx::PointF(),
3462 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573463 true,
[email protected]fb661802013-03-25 01:59:323464 false);
3465 SetLayerPropertiesForTesting(front_facing_surface.get(),
3466 identity_matrix,
[email protected]fb661802013-03-25 01:59:323467 gfx::PointF(),
3468 gfx::PointF(),
3469 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573470 true,
[email protected]fb661802013-03-25 01:59:323471 false);
3472 SetLayerPropertiesForTesting(back_facing_surface.get(),
3473 backface_matrix,
[email protected]fb661802013-03-25 01:59:323474 gfx::PointF(),
3475 gfx::PointF(),
3476 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573477 true,
[email protected]fb661802013-03-25 01:59:323478 false);
3479 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3480 identity_matrix,
[email protected]fb661802013-03-25 01:59:323481 gfx::PointF(),
3482 gfx::PointF(),
3483 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573484 true,
[email protected]fb661802013-03-25 01:59:323485 false);
3486 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3487 backface_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_of_back_facing_surface.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_of_back_facing_surface.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
[email protected]989386c2013-07-18 21:37:233508 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533509 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3510 parent.get(), parent->bounds(), &render_surface_layer_list);
3511 inputs.can_adjust_raster_scales = true;
3512 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323513
3514 // Verify which render surfaces were created.
3515 EXPECT_FALSE(front_facing_child->render_surface());
3516 EXPECT_FALSE(back_facing_child->render_surface());
3517 EXPECT_TRUE(front_facing_surface->render_surface());
3518 EXPECT_TRUE(back_facing_surface->render_surface());
3519 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3520 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3521 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3522 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3523
3524 // Verify the render_surface_layer_list.
3525 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233526 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3527 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323528 // Even though the back facing surface LAYER gets culled, the other
3529 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233530 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323531
3532 // Verify root surface's layer list.
3533 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233534 3u,
3535 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3536 EXPECT_EQ(front_facing_child->id(),
3537 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573538 ->render_surface()
3539 ->layer_list()
3540 .at(0)
3541 ->id());
[email protected]989386c2013-07-18 21:37:233542 EXPECT_EQ(front_facing_surface->id(),
3543 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573544 ->render_surface()
3545 ->layer_list()
3546 .at(1)
3547 ->id());
[email protected]989386c2013-07-18 21:37:233548 EXPECT_EQ(back_facing_surface->id(),
3549 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573550 ->render_surface()
3551 ->layer_list()
3552 .at(2)
3553 ->id());
[email protected]fb661802013-03-25 01:59:323554
3555 // Verify front_facing_surface's layer list.
3556 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233557 2u,
3558 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3559 EXPECT_EQ(front_facing_surface->id(),
3560 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573561 ->render_surface()
3562 ->layer_list()
3563 .at(0)
3564 ->id());
[email protected]989386c2013-07-18 21:37:233565 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3566 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573567 ->render_surface()
3568 ->layer_list()
3569 .at(1)
3570 ->id());
[email protected]fb661802013-03-25 01:59:323571
3572 // Verify back_facing_surface's layer list; its own layer should be culled
3573 // from the surface list.
3574 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233575 1u,
3576 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3577 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3578 render_surface_layer_list.at(2)
[email protected]56fffdd2014-02-11 19:50:573579 ->render_surface()
3580 ->layer_list()
3581 .at(0)
3582 ->id());
[email protected]fb661802013-03-25 01:59:323583}
3584
[email protected]989386c2013-07-18 21:37:233585TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323586 // Verify the behavior of back-face culling when preserves-3d transform style
3587 // is used.
3588
3589 const gfx::Transform identity_matrix;
3590 scoped_refptr<Layer> parent = Layer::Create();
3591 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3592 make_scoped_refptr(new LayerWithForcedDrawsContent());
3593 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3594 make_scoped_refptr(new LayerWithForcedDrawsContent());
3595 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3596 make_scoped_refptr(new LayerWithForcedDrawsContent());
3597 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3598 make_scoped_refptr(new LayerWithForcedDrawsContent());
3599 scoped_refptr<LayerWithForcedDrawsContent>
3600 front_facing_child_of_front_facing_surface =
3601 make_scoped_refptr(new LayerWithForcedDrawsContent());
3602 scoped_refptr<LayerWithForcedDrawsContent>
3603 back_facing_child_of_front_facing_surface =
3604 make_scoped_refptr(new LayerWithForcedDrawsContent());
3605 scoped_refptr<LayerWithForcedDrawsContent>
3606 front_facing_child_of_back_facing_surface =
3607 make_scoped_refptr(new LayerWithForcedDrawsContent());
3608 scoped_refptr<LayerWithForcedDrawsContent>
3609 back_facing_child_of_back_facing_surface =
3610 make_scoped_refptr(new LayerWithForcedDrawsContent());
3611 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3612 make_scoped_refptr(new LayerWithForcedDrawsContent());
3613 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3614 make_scoped_refptr(new LayerWithForcedDrawsContent());
3615
3616 parent->AddChild(front_facing_child);
3617 parent->AddChild(back_facing_child);
3618 parent->AddChild(front_facing_surface);
3619 parent->AddChild(back_facing_surface);
3620 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3621 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3622 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3623 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3624
[email protected]d600df7d2013-08-03 02:34:283625 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3626 host->SetRootLayer(parent);
3627
[email protected]fb661802013-03-25 01:59:323628 // Nothing is double-sided
3629 front_facing_child->SetDoubleSided(false);
3630 back_facing_child->SetDoubleSided(false);
3631 front_facing_surface->SetDoubleSided(false);
3632 back_facing_surface->SetDoubleSided(false);
3633 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3634 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3635 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3636 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3637
3638 gfx::Transform backface_matrix;
3639 backface_matrix.Translate(50.0, 50.0);
3640 backface_matrix.RotateAboutYAxis(180.0);
3641 backface_matrix.Translate(-50.0, -50.0);
3642
3643 // Opacity will not force creation of render surfaces in this case because of
3644 // the preserve-3d transform style. Instead, an example of when a surface
3645 // would be created with preserve-3d is when there is a replica layer.
3646 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3647 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3648
3649 // Each surface creates its own new 3d rendering context (as defined by W3C
3650 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3651 // rendering context should use the transform with respect to that context.
3652 // This 3d rendering context occurs when (a) parent's transform style is flat
3653 // and (b) the layer's transform style is preserve-3d.
3654 SetLayerPropertiesForTesting(parent.get(),
3655 identity_matrix,
[email protected]fb661802013-03-25 01:59:323656 gfx::PointF(),
3657 gfx::PointF(),
3658 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573659 true,
[email protected]fb661802013-03-25 01:59:323660 false); // parent transform style is flat.
3661 SetLayerPropertiesForTesting(front_facing_child.get(),
3662 identity_matrix,
[email protected]fb661802013-03-25 01:59:323663 gfx::PointF(),
3664 gfx::PointF(),
3665 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573666 true,
[email protected]fb661802013-03-25 01:59:323667 false);
3668 SetLayerPropertiesForTesting(back_facing_child.get(),
3669 backface_matrix,
[email protected]fb661802013-03-25 01:59:323670 gfx::PointF(),
3671 gfx::PointF(),
3672 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573673 true,
[email protected]fb661802013-03-25 01:59:323674 false);
[email protected]56fffdd2014-02-11 19:50:573675 // surface transform style is preserve-3d.
3676 SetLayerPropertiesForTesting(front_facing_surface.get(),
3677 identity_matrix,
[email protected]56fffdd2014-02-11 19:50:573678 gfx::PointF(),
3679 gfx::PointF(),
3680 gfx::Size(100, 100),
3681 false,
3682 true);
3683 // surface transform style is preserve-3d.
3684 SetLayerPropertiesForTesting(back_facing_surface.get(),
3685 backface_matrix,
[email protected]56fffdd2014-02-11 19:50:573686 gfx::PointF(),
3687 gfx::PointF(),
3688 gfx::Size(100, 100),
3689 false,
3690 true);
[email protected]fb661802013-03-25 01:59:323691 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3692 identity_matrix,
[email protected]fb661802013-03-25 01:59:323693 gfx::PointF(),
3694 gfx::PointF(),
3695 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573696 true,
3697 true);
[email protected]fb661802013-03-25 01:59:323698 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3699 backface_matrix,
[email protected]fb661802013-03-25 01:59:323700 gfx::PointF(),
3701 gfx::PointF(),
3702 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573703 true,
3704 true);
[email protected]fb661802013-03-25 01:59:323705 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3706 identity_matrix,
[email protected]fb661802013-03-25 01:59:323707 gfx::PointF(),
3708 gfx::PointF(),
3709 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573710 true,
3711 true);
[email protected]fb661802013-03-25 01:59:323712 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3713 backface_matrix,
[email protected]fb661802013-03-25 01:59:323714 gfx::PointF(),
3715 gfx::PointF(),
3716 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573717 true,
3718 true);
[email protected]fb661802013-03-25 01:59:323719
[email protected]989386c2013-07-18 21:37:233720 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533721 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3722 parent.get(), parent->bounds(), &render_surface_layer_list);
3723 inputs.can_adjust_raster_scales = true;
3724 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323725
3726 // Verify which render surfaces were created.
3727 EXPECT_FALSE(front_facing_child->render_surface());
3728 EXPECT_FALSE(back_facing_child->render_surface());
3729 EXPECT_TRUE(front_facing_surface->render_surface());
3730 EXPECT_FALSE(back_facing_surface->render_surface());
3731 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3732 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3733 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3734 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3735
3736 // Verify the render_surface_layer_list. The back-facing surface should be
3737 // culled.
3738 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233739 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3740 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323741
3742 // Verify root surface's layer list.
3743 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233744 2u,
3745 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3746 EXPECT_EQ(front_facing_child->id(),
3747 render_surface_layer_list.at(0)
3748 ->render_surface()->layer_list().at(0)->id());
3749 EXPECT_EQ(front_facing_surface->id(),
3750 render_surface_layer_list.at(0)
3751 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323752
3753 // Verify front_facing_surface's layer list.
3754 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233755 2u,
3756 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3757 EXPECT_EQ(front_facing_surface->id(),
3758 render_surface_layer_list.at(1)
3759 ->render_surface()->layer_list().at(0)->id());
3760 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3761 render_surface_layer_list.at(1)
3762 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323763}
3764
[email protected]989386c2013-07-18 21:37:233765TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323766 // Verify that layers are appropriately culled when their back face is showing
3767 // and they are not double sided, while animations are going on.
3768 //
3769 // Layers that are animating do not get culled on the main thread, as their
3770 // transforms should be treated as "unknown" so we can not be sure that their
3771 // back face is really showing.
3772 const gfx::Transform identity_matrix;
3773 scoped_refptr<Layer> parent = Layer::Create();
3774 scoped_refptr<LayerWithForcedDrawsContent> child =
3775 make_scoped_refptr(new LayerWithForcedDrawsContent());
3776 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3777 make_scoped_refptr(new LayerWithForcedDrawsContent());
3778 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3779 make_scoped_refptr(new LayerWithForcedDrawsContent());
3780 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3781 make_scoped_refptr(new LayerWithForcedDrawsContent());
3782 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3783 make_scoped_refptr(new LayerWithForcedDrawsContent());
3784
3785 parent->AddChild(child);
3786 parent->AddChild(animating_surface);
3787 animating_surface->AddChild(child_of_animating_surface);
3788 parent->AddChild(animating_child);
3789 parent->AddChild(child2);
3790
[email protected]d600df7d2013-08-03 02:34:283791 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3792 host->SetRootLayer(parent);
3793
[email protected]fb661802013-03-25 01:59:323794 // Nothing is double-sided
3795 child->SetDoubleSided(false);
3796 child2->SetDoubleSided(false);
3797 animating_surface->SetDoubleSided(false);
3798 child_of_animating_surface->SetDoubleSided(false);
3799 animating_child->SetDoubleSided(false);
3800
3801 gfx::Transform backface_matrix;
3802 backface_matrix.Translate(50.0, 50.0);
3803 backface_matrix.RotateAboutYAxis(180.0);
3804 backface_matrix.Translate(-50.0, -50.0);
3805
3806 // Make our render surface.
3807 animating_surface->SetForceRenderSurface(true);
3808
3809 // Animate the transform on the render surface.
3810 AddAnimatedTransformToController(
3811 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3812 // This is just an animating layer, not a surface.
3813 AddAnimatedTransformToController(
3814 animating_child->layer_animation_controller(), 10.0, 30, 0);
3815
3816 SetLayerPropertiesForTesting(parent.get(),
3817 identity_matrix,
[email protected]fb661802013-03-25 01:59:323818 gfx::PointF(),
3819 gfx::PointF(),
3820 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573821 true,
[email protected]fb661802013-03-25 01:59:323822 false);
3823 SetLayerPropertiesForTesting(child.get(),
3824 backface_matrix,
[email protected]fb661802013-03-25 01:59:323825 gfx::PointF(),
3826 gfx::PointF(),
3827 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573828 true,
[email protected]fb661802013-03-25 01:59:323829 false);
3830 SetLayerPropertiesForTesting(animating_surface.get(),
3831 backface_matrix,
[email protected]fb661802013-03-25 01:59:323832 gfx::PointF(),
3833 gfx::PointF(),
3834 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573835 true,
[email protected]fb661802013-03-25 01:59:323836 false);
3837 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3838 backface_matrix,
[email protected]fb661802013-03-25 01:59:323839 gfx::PointF(),
3840 gfx::PointF(),
3841 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573842 true,
[email protected]fb661802013-03-25 01:59:323843 false);
3844 SetLayerPropertiesForTesting(animating_child.get(),
3845 backface_matrix,
[email protected]fb661802013-03-25 01:59:323846 gfx::PointF(),
3847 gfx::PointF(),
3848 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573849 true,
[email protected]fb661802013-03-25 01:59:323850 false);
3851 SetLayerPropertiesForTesting(child2.get(),
3852 identity_matrix,
[email protected]fb661802013-03-25 01:59:323853 gfx::PointF(),
3854 gfx::PointF(),
3855 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573856 true,
[email protected]fb661802013-03-25 01:59:323857 false);
3858
[email protected]989386c2013-07-18 21:37:233859 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533860 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3861 parent.get(), parent->bounds(), &render_surface_layer_list);
3862 inputs.can_adjust_raster_scales = true;
3863 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323864
3865 EXPECT_FALSE(child->render_surface());
3866 EXPECT_TRUE(animating_surface->render_surface());
3867 EXPECT_FALSE(child_of_animating_surface->render_surface());
3868 EXPECT_FALSE(animating_child->render_surface());
3869 EXPECT_FALSE(child2->render_surface());
3870
3871 // Verify that the animating_child and child_of_animating_surface were not
3872 // culled, but that child was.
3873 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233874 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3875 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323876
3877 // The non-animating child be culled from the layer list for the parent render
3878 // surface.
3879 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233880 3u,
3881 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3882 EXPECT_EQ(animating_surface->id(),
3883 render_surface_layer_list.at(0)
3884 ->render_surface()->layer_list().at(0)->id());
3885 EXPECT_EQ(animating_child->id(),
3886 render_surface_layer_list.at(0)
3887 ->render_surface()->layer_list().at(1)->id());
3888 EXPECT_EQ(child2->id(),
3889 render_surface_layer_list.at(0)
3890 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:323891
3892 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233893 2u,
3894 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3895 EXPECT_EQ(animating_surface->id(),
3896 render_surface_layer_list.at(1)
3897 ->render_surface()->layer_list().at(0)->id());
3898 EXPECT_EQ(child_of_animating_surface->id(),
3899 render_surface_layer_list.at(1)
3900 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323901
3902 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
3903
3904 // The animating layers should have a visible content rect that represents the
3905 // area of the front face that is within the viewport.
3906 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053907 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:323908 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053909 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:323910 // And layers in the subtree of the animating layer should have valid visible
3911 // content rects also.
[email protected]989386c2013-07-18 21:37:233912 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
3913 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:323914}
3915
[email protected]989386c2013-07-18 21:37:233916TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:323917 BackFaceCullingWithPreserves3dForFlatteningSurface) {
3918 // Verify the behavior of back-face culling for a render surface that is
3919 // created when it flattens its subtree, and its parent has preserves-3d.
3920
3921 const gfx::Transform identity_matrix;
3922 scoped_refptr<Layer> parent = Layer::Create();
3923 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3924 make_scoped_refptr(new LayerWithForcedDrawsContent());
3925 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3926 make_scoped_refptr(new LayerWithForcedDrawsContent());
3927 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3928 make_scoped_refptr(new LayerWithForcedDrawsContent());
3929 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3930 make_scoped_refptr(new LayerWithForcedDrawsContent());
3931
3932 parent->AddChild(front_facing_surface);
3933 parent->AddChild(back_facing_surface);
3934 front_facing_surface->AddChild(child1);
3935 back_facing_surface->AddChild(child2);
3936
[email protected]d600df7d2013-08-03 02:34:283937 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3938 host->SetRootLayer(parent);
3939
[email protected]fb661802013-03-25 01:59:323940 // RenderSurfaces are not double-sided
3941 front_facing_surface->SetDoubleSided(false);
3942 back_facing_surface->SetDoubleSided(false);
3943
3944 gfx::Transform backface_matrix;
3945 backface_matrix.Translate(50.0, 50.0);
3946 backface_matrix.RotateAboutYAxis(180.0);
3947 backface_matrix.Translate(-50.0, -50.0);
3948
3949 SetLayerPropertiesForTesting(parent.get(),
3950 identity_matrix,
[email protected]fb661802013-03-25 01:59:323951 gfx::PointF(),
3952 gfx::PointF(),
3953 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573954 false,
3955 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:323956 SetLayerPropertiesForTesting(front_facing_surface.get(),
3957 identity_matrix,
[email protected]fb661802013-03-25 01:59:323958 gfx::PointF(),
3959 gfx::PointF(),
3960 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573961 true,
3962 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:323963 SetLayerPropertiesForTesting(back_facing_surface.get(),
3964 backface_matrix,
[email protected]fb661802013-03-25 01:59:323965 gfx::PointF(),
3966 gfx::PointF(),
3967 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573968 true,
3969 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:323970 SetLayerPropertiesForTesting(child1.get(),
3971 identity_matrix,
[email protected]fb661802013-03-25 01:59:323972 gfx::PointF(),
3973 gfx::PointF(),
3974 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573975 true,
[email protected]fb661802013-03-25 01:59:323976 false);
3977 SetLayerPropertiesForTesting(child2.get(),
3978 identity_matrix,
[email protected]fb661802013-03-25 01:59:323979 gfx::PointF(),
3980 gfx::PointF(),
3981 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573982 true,
[email protected]fb661802013-03-25 01:59:323983 false);
3984
[email protected]56fffdd2014-02-11 19:50:573985 front_facing_surface->SetIs3dSorted(true);
3986 back_facing_surface->SetIs3dSorted(true);
3987
[email protected]989386c2013-07-18 21:37:233988 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533989 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3990 parent.get(), parent->bounds(), &render_surface_layer_list);
3991 inputs.can_adjust_raster_scales = true;
3992 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323993
3994 // Verify which render surfaces were created.
3995 EXPECT_TRUE(front_facing_surface->render_surface());
3996 EXPECT_FALSE(
3997 back_facing_surface->render_surface()); // because it should be culled
3998 EXPECT_FALSE(child1->render_surface());
3999 EXPECT_FALSE(child2->render_surface());
4000
4001 // Verify the render_surface_layer_list. The back-facing surface should be
4002 // culled.
4003 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234004 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4005 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324006
4007 // Verify root surface's layer list.
4008 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234009 1u,
4010 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4011 EXPECT_EQ(front_facing_surface->id(),
4012 render_surface_layer_list.at(0)
4013 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324014
4015 // Verify front_facing_surface's layer list.
4016 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234017 2u,
4018 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4019 EXPECT_EQ(front_facing_surface->id(),
4020 render_surface_layer_list.at(1)
4021 ->render_surface()->layer_list().at(0)->id());
4022 EXPECT_EQ(child1->id(),
4023 render_surface_layer_list.at(1)
4024 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324025}
4026
[email protected]989386c2013-07-18 21:37:234027
4028TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:324029 // Hit testing on an empty render_surface_layer_list should return a null
4030 // pointer.
[email protected]50761e92013-03-29 20:51:284031 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:324032
4033 gfx::Point test_point(0, 0);
4034 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4035 test_point, render_surface_layer_list);
4036 EXPECT_FALSE(result_layer);
4037
4038 test_point = gfx::Point(10, 20);
4039 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4040 test_point, render_surface_layer_list);
4041 EXPECT_FALSE(result_layer);
4042}
4043
[email protected]989386c2013-07-18 21:37:234044TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayer) {
[email protected]fb661802013-03-25 01:59:324045 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454046 TestSharedBitmapManager shared_bitmap_manager;
4047 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324048 scoped_ptr<LayerImpl> root =
4049 LayerImpl::Create(host_impl.active_tree(), 12345);
4050
4051 gfx::Transform identity_matrix;
4052 gfx::PointF anchor;
4053 gfx::PointF position;
4054 gfx::Size bounds(100, 100);
4055 SetLayerPropertiesForTesting(root.get(),
4056 identity_matrix,
[email protected]fb661802013-03-25 01:59:324057 anchor,
4058 position,
4059 bounds,
[email protected]56fffdd2014-02-11 19:50:574060 true,
[email protected]fb661802013-03-25 01:59:324061 false);
4062 root->SetDrawsContent(true);
4063
[email protected]50761e92013-03-29 20:51:284064 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534065 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4066 root.get(), root->bounds(), &render_surface_layer_list);
4067 inputs.can_adjust_raster_scales = true;
4068 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324069
4070 // Sanity check the scenario we just created.
4071 ASSERT_EQ(1u, render_surface_layer_list.size());
4072 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4073
4074 // Hit testing for a point outside the layer should return a null pointer.
4075 gfx::Point test_point(101, 101);
4076 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4077 test_point, render_surface_layer_list);
4078 EXPECT_FALSE(result_layer);
4079
4080 test_point = gfx::Point(-1, -1);
4081 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4082 test_point, render_surface_layer_list);
4083 EXPECT_FALSE(result_layer);
4084
4085 // Hit testing for a point inside should return the root layer.
4086 test_point = gfx::Point(1, 1);
4087 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4088 test_point, render_surface_layer_list);
4089 ASSERT_TRUE(result_layer);
4090 EXPECT_EQ(12345, result_layer->id());
4091
4092 test_point = gfx::Point(99, 99);
4093 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4094 test_point, render_surface_layer_list);
4095 ASSERT_TRUE(result_layer);
4096 EXPECT_EQ(12345, result_layer->id());
4097}
4098
[email protected]989386c2013-07-18 21:37:234099TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) {
[email protected]fb661802013-03-25 01:59:324100 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454101 TestSharedBitmapManager shared_bitmap_manager;
4102 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324103 scoped_ptr<LayerImpl> root =
4104 LayerImpl::Create(host_impl.active_tree(), 12345);
4105 scoped_ptr<HeadsUpDisplayLayerImpl> hud =
4106 HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111);
4107
4108 gfx::Transform identity_matrix;
4109 gfx::PointF anchor;
4110 gfx::PointF position;
4111 gfx::Size bounds(100, 100);
4112 SetLayerPropertiesForTesting(root.get(),
4113 identity_matrix,
[email protected]fb661802013-03-25 01:59:324114 anchor,
4115 position,
4116 bounds,
[email protected]56fffdd2014-02-11 19:50:574117 true,
[email protected]fb661802013-03-25 01:59:324118 false);
4119 root->SetDrawsContent(true);
4120
4121 // Create hud and add it as a child of root.
4122 gfx::Size hud_bounds(200, 200);
4123 SetLayerPropertiesForTesting(hud.get(),
4124 identity_matrix,
[email protected]fb661802013-03-25 01:59:324125 anchor,
4126 position,
4127 hud_bounds,
[email protected]56fffdd2014-02-11 19:50:574128 true,
[email protected]fb661802013-03-25 01:59:324129 false);
4130 hud->SetDrawsContent(true);
4131
4132 host_impl.active_tree()->set_hud_layer(hud.get());
4133 root->AddChild(hud.PassAs<LayerImpl>());
4134
[email protected]50761e92013-03-29 20:51:284135 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534136 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4137 root.get(), hud_bounds, &render_surface_layer_list);
4138 inputs.can_adjust_raster_scales = true;
4139 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324140
4141 // Sanity check the scenario we just created.
4142 ASSERT_EQ(1u, render_surface_layer_list.size());
4143 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4144
4145 // Hit testing for a point inside HUD, but outside root should return null
4146 gfx::Point test_point(101, 101);
4147 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4148 test_point, render_surface_layer_list);
4149 EXPECT_FALSE(result_layer);
4150
4151 test_point = gfx::Point(-1, -1);
4152 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4153 test_point, render_surface_layer_list);
4154 EXPECT_FALSE(result_layer);
4155
4156 // Hit testing for a point inside should return the root layer, never the HUD
4157 // layer.
4158 test_point = gfx::Point(1, 1);
4159 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4160 test_point, render_surface_layer_list);
4161 ASSERT_TRUE(result_layer);
4162 EXPECT_EQ(12345, result_layer->id());
4163
4164 test_point = gfx::Point(99, 99);
4165 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4166 test_point, render_surface_layer_list);
4167 ASSERT_TRUE(result_layer);
4168 EXPECT_EQ(12345, result_layer->id());
4169}
4170
[email protected]989386c2013-07-18 21:37:234171TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) {
[email protected]fb661802013-03-25 01:59:324172 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454173 TestSharedBitmapManager shared_bitmap_manager;
4174 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324175 scoped_ptr<LayerImpl> root =
4176 LayerImpl::Create(host_impl.active_tree(), 12345);
4177
4178 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:264179 uninvertible_transform.matrix().set(0, 0, 0.0);
4180 uninvertible_transform.matrix().set(1, 1, 0.0);
4181 uninvertible_transform.matrix().set(2, 2, 0.0);
4182 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:324183 ASSERT_FALSE(uninvertible_transform.IsInvertible());
4184
4185 gfx::Transform identity_matrix;
4186 gfx::PointF anchor;
4187 gfx::PointF position;
4188 gfx::Size bounds(100, 100);
4189 SetLayerPropertiesForTesting(root.get(),
4190 uninvertible_transform,
[email protected]fb661802013-03-25 01:59:324191 anchor,
4192 position,
4193 bounds,
[email protected]56fffdd2014-02-11 19:50:574194 true,
[email protected]fb661802013-03-25 01:59:324195 false);
4196 root->SetDrawsContent(true);
4197
[email protected]50761e92013-03-29 20:51:284198 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534199 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4200 root.get(), root->bounds(), &render_surface_layer_list);
4201 inputs.can_adjust_raster_scales = true;
4202 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324203
4204 // Sanity check the scenario we just created.
4205 ASSERT_EQ(1u, render_surface_layer_list.size());
4206 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4207 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
4208
4209 // Hit testing any point should not hit the layer. If the invertible matrix is
4210 // accidentally ignored and treated like an identity, then the hit testing
4211 // will incorrectly hit the layer when it shouldn't.
4212 gfx::Point test_point(1, 1);
4213 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4214 test_point, render_surface_layer_list);
4215 EXPECT_FALSE(result_layer);
4216
4217 test_point = gfx::Point(10, 10);
4218 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4219 test_point, render_surface_layer_list);
4220 EXPECT_FALSE(result_layer);
4221
4222 test_point = gfx::Point(10, 30);
4223 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4224 test_point, render_surface_layer_list);
4225 EXPECT_FALSE(result_layer);
4226
4227 test_point = gfx::Point(50, 50);
4228 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4229 test_point, render_surface_layer_list);
4230 EXPECT_FALSE(result_layer);
4231
4232 test_point = gfx::Point(67, 48);
4233 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4234 test_point, render_surface_layer_list);
4235 EXPECT_FALSE(result_layer);
4236
4237 test_point = gfx::Point(99, 99);
4238 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4239 test_point, render_surface_layer_list);
4240 EXPECT_FALSE(result_layer);
4241
4242 test_point = gfx::Point(-1, -1);
4243 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4244 test_point, render_surface_layer_list);
4245 EXPECT_FALSE(result_layer);
4246}
4247
[email protected]989386c2013-07-18 21:37:234248TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) {
[email protected]fb661802013-03-25 01:59:324249 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454250 TestSharedBitmapManager shared_bitmap_manager;
4251 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324252 scoped_ptr<LayerImpl> root =
4253 LayerImpl::Create(host_impl.active_tree(), 12345);
4254
4255 gfx::Transform identity_matrix;
4256 gfx::PointF anchor;
4257 // this layer is positioned, and hit testing should correctly know where the
4258 // layer is located.
4259 gfx::PointF position(50.f, 50.f);
4260 gfx::Size bounds(100, 100);
4261 SetLayerPropertiesForTesting(root.get(),
4262 identity_matrix,
[email protected]fb661802013-03-25 01:59:324263 anchor,
4264 position,
4265 bounds,
[email protected]56fffdd2014-02-11 19:50:574266 true,
[email protected]fb661802013-03-25 01:59:324267 false);
4268 root->SetDrawsContent(true);
4269
[email protected]50761e92013-03-29 20:51:284270 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534271 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4272 root.get(), root->bounds(), &render_surface_layer_list);
4273 inputs.can_adjust_raster_scales = true;
4274 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324275
4276 // Sanity check the scenario we just created.
4277 ASSERT_EQ(1u, render_surface_layer_list.size());
4278 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4279
4280 // Hit testing for a point outside the layer should return a null pointer.
4281 gfx::Point test_point(49, 49);
4282 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4283 test_point, render_surface_layer_list);
4284 EXPECT_FALSE(result_layer);
4285
4286 // Even though the layer exists at (101, 101), it should not be visible there
4287 // since the root render surface would clamp it.
4288 test_point = gfx::Point(101, 101);
4289 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4290 test_point, render_surface_layer_list);
4291 EXPECT_FALSE(result_layer);
4292
4293 // Hit testing for a point inside should return the root layer.
4294 test_point = gfx::Point(51, 51);
4295 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4296 test_point, render_surface_layer_list);
4297 ASSERT_TRUE(result_layer);
4298 EXPECT_EQ(12345, result_layer->id());
4299
4300 test_point = gfx::Point(99, 99);
4301 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4302 test_point, render_surface_layer_list);
4303 ASSERT_TRUE(result_layer);
4304 EXPECT_EQ(12345, result_layer->id());
4305}
4306
[email protected]989386c2013-07-18 21:37:234307TEST_F(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324308 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454309 TestSharedBitmapManager shared_bitmap_manager;
4310 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324311 scoped_ptr<LayerImpl> root =
4312 LayerImpl::Create(host_impl.active_tree(), 12345);
4313
4314 gfx::Transform identity_matrix;
4315 gfx::Transform rotation45_degrees_about_center;
4316 rotation45_degrees_about_center.Translate(50.0, 50.0);
4317 rotation45_degrees_about_center.RotateAboutZAxis(45.0);
4318 rotation45_degrees_about_center.Translate(-50.0, -50.0);
4319 gfx::PointF anchor;
4320 gfx::PointF position;
4321 gfx::Size bounds(100, 100);
4322 SetLayerPropertiesForTesting(root.get(),
4323 rotation45_degrees_about_center,
[email protected]fb661802013-03-25 01:59:324324 anchor,
4325 position,
4326 bounds,
[email protected]56fffdd2014-02-11 19:50:574327 true,
[email protected]fb661802013-03-25 01:59:324328 false);
4329 root->SetDrawsContent(true);
4330
[email protected]50761e92013-03-29 20:51:284331 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534332 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4333 root.get(), root->bounds(), &render_surface_layer_list);
4334 inputs.can_adjust_raster_scales = true;
4335 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324336
4337 // Sanity check the scenario we just created.
4338 ASSERT_EQ(1u, render_surface_layer_list.size());
4339 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4340
4341 // Hit testing for points outside the layer.
4342 // These corners would have been inside the un-transformed layer, but they
4343 // should not hit the correctly transformed layer.
4344 gfx::Point test_point(99, 99);
4345 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4346 test_point, render_surface_layer_list);
4347 EXPECT_FALSE(result_layer);
4348
4349 test_point = gfx::Point(1, 1);
4350 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4351 test_point, render_surface_layer_list);
4352 EXPECT_FALSE(result_layer);
4353
4354 // Hit testing for a point inside should return the root layer.
4355 test_point = gfx::Point(1, 50);
4356 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4357 test_point, render_surface_layer_list);
4358 ASSERT_TRUE(result_layer);
4359 EXPECT_EQ(12345, result_layer->id());
4360
4361 // Hit testing the corners that would overlap the unclipped layer, but are
4362 // outside the clipped region.
4363 test_point = gfx::Point(50, -1);
4364 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4365 test_point, render_surface_layer_list);
4366 ASSERT_FALSE(result_layer);
4367
4368 test_point = gfx::Point(-1, 50);
4369 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4370 test_point, render_surface_layer_list);
4371 ASSERT_FALSE(result_layer);
4372}
4373
[email protected]989386c2013-07-18 21:37:234374TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) {
[email protected]fb661802013-03-25 01:59:324375 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454376 TestSharedBitmapManager shared_bitmap_manager;
4377 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324378 scoped_ptr<LayerImpl> root =
4379 LayerImpl::Create(host_impl.active_tree(), 12345);
4380
4381 gfx::Transform identity_matrix;
4382
4383 // perspective_projection_about_center * translation_by_z is designed so that
4384 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
4385 gfx::Transform perspective_projection_about_center;
4386 perspective_projection_about_center.Translate(50.0, 50.0);
4387 perspective_projection_about_center.ApplyPerspectiveDepth(1.0);
4388 perspective_projection_about_center.Translate(-50.0, -50.0);
4389 gfx::Transform translation_by_z;
4390 translation_by_z.Translate3d(0.0, 0.0, -1.0);
4391
4392 gfx::PointF anchor;
4393 gfx::PointF position;
4394 gfx::Size bounds(100, 100);
4395 SetLayerPropertiesForTesting(
4396 root.get(),
4397 perspective_projection_about_center * translation_by_z,
[email protected]fb661802013-03-25 01:59:324398 anchor,
4399 position,
4400 bounds,
[email protected]56fffdd2014-02-11 19:50:574401 true,
[email protected]fb661802013-03-25 01:59:324402 false);
4403 root->SetDrawsContent(true);
4404
[email protected]50761e92013-03-29 20:51:284405 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534406 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4407 root.get(), root->bounds(), &render_surface_layer_list);
4408 inputs.can_adjust_raster_scales = true;
4409 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324410
4411 // Sanity check the scenario we just created.
4412 ASSERT_EQ(1u, render_surface_layer_list.size());
4413 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4414
4415 // Hit testing for points outside the layer.
4416 // These corners would have been inside the un-transformed layer, but they
4417 // should not hit the correctly transformed layer.
4418 gfx::Point test_point(24, 24);
4419 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4420 test_point, render_surface_layer_list);
4421 EXPECT_FALSE(result_layer);
4422
4423 test_point = gfx::Point(76, 76);
4424 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4425 test_point, render_surface_layer_list);
4426 EXPECT_FALSE(result_layer);
4427
4428 // Hit testing for a point inside should return the root layer.
4429 test_point = gfx::Point(26, 26);
4430 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4431 test_point, render_surface_layer_list);
4432 ASSERT_TRUE(result_layer);
4433 EXPECT_EQ(12345, result_layer->id());
4434
4435 test_point = gfx::Point(74, 74);
4436 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4437 test_point, render_surface_layer_list);
4438 ASSERT_TRUE(result_layer);
4439 EXPECT_EQ(12345, result_layer->id());
4440}
4441
[email protected]989386c2013-07-18 21:37:234442TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) {
[email protected]fb661802013-03-25 01:59:324443 // A layer's visible content rect is actually in the layer's content space.
4444 // The screen space transform converts from the layer's origin space to screen
4445 // space. This test makes sure that hit testing works correctly accounts for
4446 // the contents scale. A contents scale that is not 1 effectively forces a
4447 // non-identity transform between layer's content space and layer's origin
4448 // space. The hit testing code must take this into account.
4449 //
4450 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
4451 // contents scale is ignored, then hit testing will mis-interpret the visible
4452 // content rect as being larger than the actual bounds of the layer.
4453 //
4454 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454455 TestSharedBitmapManager shared_bitmap_manager;
4456 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324457 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4458
4459 gfx::Transform identity_matrix;
4460 gfx::PointF anchor;
4461
4462 SetLayerPropertiesForTesting(root.get(),
4463 identity_matrix,
[email protected]fb661802013-03-25 01:59:324464 anchor,
4465 gfx::PointF(),
4466 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574467 true,
[email protected]fb661802013-03-25 01:59:324468 false);
4469 {
4470 gfx::PointF position(25.f, 25.f);
4471 gfx::Size bounds(50, 50);
4472 scoped_ptr<LayerImpl> test_layer =
4473 LayerImpl::Create(host_impl.active_tree(), 12345);
4474 SetLayerPropertiesForTesting(test_layer.get(),
4475 identity_matrix,
[email protected]fb661802013-03-25 01:59:324476 anchor,
4477 position,
4478 bounds,
[email protected]56fffdd2014-02-11 19:50:574479 true,
[email protected]fb661802013-03-25 01:59:324480 false);
4481
4482 // override content bounds and contents scale
4483 test_layer->SetContentBounds(gfx::Size(100, 100));
4484 test_layer->SetContentsScale(2, 2);
4485
4486 test_layer->SetDrawsContent(true);
4487 root->AddChild(test_layer.Pass());
4488 }
4489
[email protected]50761e92013-03-29 20:51:284490 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534491 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4492 root.get(), root->bounds(), &render_surface_layer_list);
4493 inputs.can_adjust_raster_scales = true;
4494 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324495
4496 // Sanity check the scenario we just created.
4497 // The visible content rect for test_layer is actually 100x100, even though
4498 // its layout size is 50x50, positioned at 25x25.
4499 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:054500 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
[email protected]fb661802013-03-25 01:59:324501 test_layer->visible_content_rect());
4502 ASSERT_EQ(1u, render_surface_layer_list.size());
4503 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4504
4505 // Hit testing for a point outside the layer should return a null pointer (the
4506 // root layer does not draw content, so it will not be hit tested either).
4507 gfx::Point test_point(101, 101);
4508 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4509 test_point, render_surface_layer_list);
4510 EXPECT_FALSE(result_layer);
4511
4512 test_point = gfx::Point(24, 24);
4513 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4514 test_point, render_surface_layer_list);
4515 EXPECT_FALSE(result_layer);
4516
4517 test_point = gfx::Point(76, 76);
4518 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4519 test_point, render_surface_layer_list);
4520 EXPECT_FALSE(result_layer);
4521
4522 // Hit testing for a point inside should return the test layer.
4523 test_point = gfx::Point(26, 26);
4524 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4525 test_point, render_surface_layer_list);
4526 ASSERT_TRUE(result_layer);
4527 EXPECT_EQ(12345, result_layer->id());
4528
4529 test_point = gfx::Point(74, 74);
4530 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4531 test_point, render_surface_layer_list);
4532 ASSERT_TRUE(result_layer);
4533 EXPECT_EQ(12345, result_layer->id());
4534}
4535
[email protected]989386c2013-07-18 21:37:234536TEST_F(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) {
[email protected]fb661802013-03-25 01:59:324537 // Test that hit-testing will only work for the visible portion of a layer,
4538 // and not the entire layer bounds. Here we just test the simple axis-aligned
4539 // case.
4540 gfx::Transform identity_matrix;
4541 gfx::PointF anchor;
4542
4543 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454544 TestSharedBitmapManager shared_bitmap_manager;
4545 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324546 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4547 SetLayerPropertiesForTesting(root.get(),
4548 identity_matrix,
[email protected]fb661802013-03-25 01:59:324549 anchor,
4550 gfx::PointF(),
4551 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574552 true,
[email protected]fb661802013-03-25 01:59:324553 false);
4554 {
4555 scoped_ptr<LayerImpl> clipping_layer =
4556 LayerImpl::Create(host_impl.active_tree(), 123);
4557 // this layer is positioned, and hit testing should correctly know where the
4558 // layer is located.
[email protected]ca2902e92013-03-28 01:45:354559 gfx::PointF position(25.f, 25.f);
[email protected]fb661802013-03-25 01:59:324560 gfx::Size bounds(50, 50);
4561 SetLayerPropertiesForTesting(clipping_layer.get(),
4562 identity_matrix,
[email protected]fb661802013-03-25 01:59:324563 anchor,
4564 position,
4565 bounds,
[email protected]56fffdd2014-02-11 19:50:574566 true,
[email protected]fb661802013-03-25 01:59:324567 false);
4568 clipping_layer->SetMasksToBounds(true);
4569
4570 scoped_ptr<LayerImpl> child =
4571 LayerImpl::Create(host_impl.active_tree(), 456);
4572 position = gfx::PointF(-50.f, -50.f);
4573 bounds = gfx::Size(300, 300);
4574 SetLayerPropertiesForTesting(child.get(),
4575 identity_matrix,
[email protected]fb661802013-03-25 01:59:324576 anchor,
4577 position,
4578 bounds,
[email protected]56fffdd2014-02-11 19:50:574579 true,
[email protected]fb661802013-03-25 01:59:324580 false);
4581 child->SetDrawsContent(true);
4582 clipping_layer->AddChild(child.Pass());
4583 root->AddChild(clipping_layer.Pass());
4584 }
4585
[email protected]50761e92013-03-29 20:51:284586 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534587 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4588 root.get(), root->bounds(), &render_surface_layer_list);
4589 inputs.can_adjust_raster_scales = true;
4590 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324591
4592 // Sanity check the scenario we just created.
4593 ASSERT_EQ(1u, render_surface_layer_list.size());
4594 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234595 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324596
4597 // Hit testing for a point outside the layer should return a null pointer.
4598 // Despite the child layer being very large, it should be clipped to the root
4599 // layer's bounds.
4600 gfx::Point test_point(24, 24);
4601 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4602 test_point, render_surface_layer_list);
4603 EXPECT_FALSE(result_layer);
4604
4605 // Even though the layer exists at (101, 101), it should not be visible there
4606 // since the clipping_layer would clamp it.
4607 test_point = gfx::Point(76, 76);
4608 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4609 test_point, render_surface_layer_list);
4610 EXPECT_FALSE(result_layer);
4611
4612 // Hit testing for a point inside should return the child layer.
4613 test_point = gfx::Point(26, 26);
4614 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4615 test_point, render_surface_layer_list);
4616 ASSERT_TRUE(result_layer);
4617 EXPECT_EQ(456, result_layer->id());
4618
4619 test_point = gfx::Point(74, 74);
4620 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4621 test_point, render_surface_layer_list);
4622 ASSERT_TRUE(result_layer);
4623 EXPECT_EQ(456, result_layer->id());
4624}
4625
[email protected]989386c2013-07-18 21:37:234626TEST_F(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324627 // This test checks whether hit testing correctly avoids hit testing with
4628 // multiple ancestors that clip in non axis-aligned ways. To pass this test,
4629 // the hit testing algorithm needs to recognize that multiple parent layers
4630 // may clip the layer, and should not actually hit those clipped areas.
4631 //
4632 // The child and grand_child layers are both initialized to clip the
4633 // rotated_leaf. The child layer is rotated about the top-left corner, so that
4634 // the root + child clips combined create a triangle. The rotated_leaf will
4635 // only be visible where it overlaps this triangle.
4636 //
4637 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454638 TestSharedBitmapManager shared_bitmap_manager;
4639 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324640 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123);
4641
4642 gfx::Transform identity_matrix;
4643 gfx::PointF anchor;
4644 gfx::PointF position;
4645 gfx::Size bounds(100, 100);
4646 SetLayerPropertiesForTesting(root.get(),
4647 identity_matrix,
[email protected]fb661802013-03-25 01:59:324648 anchor,
4649 position,
4650 bounds,
[email protected]56fffdd2014-02-11 19:50:574651 true,
[email protected]fb661802013-03-25 01:59:324652 false);
4653 root->SetMasksToBounds(true);
4654 {
4655 scoped_ptr<LayerImpl> child =
4656 LayerImpl::Create(host_impl.active_tree(), 456);
4657 scoped_ptr<LayerImpl> grand_child =
4658 LayerImpl::Create(host_impl.active_tree(), 789);
4659 scoped_ptr<LayerImpl> rotated_leaf =
4660 LayerImpl::Create(host_impl.active_tree(), 2468);
4661
4662 position = gfx::PointF(10.f, 10.f);
4663 bounds = gfx::Size(80, 80);
4664 SetLayerPropertiesForTesting(child.get(),
4665 identity_matrix,
[email protected]fb661802013-03-25 01:59:324666 anchor,
4667 position,
4668 bounds,
[email protected]56fffdd2014-02-11 19:50:574669 true,
[email protected]fb661802013-03-25 01:59:324670 false);
[email protected]7aba6662013-03-12 10:17:344671 child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444672
[email protected]fb661802013-03-25 01:59:324673 gfx::Transform rotation45_degrees_about_corner;
4674 rotation45_degrees_about_corner.RotateAboutZAxis(45.0);
[email protected]aedf4e52013-01-09 23:24:444675
[email protected]fb661802013-03-25 01:59:324676 // remember, positioned with respect to its parent which is already at 10,
4677 // 10
4678 position = gfx::PointF();
4679 bounds =
4680 gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
4681 SetLayerPropertiesForTesting(grand_child.get(),
4682 rotation45_degrees_about_corner,
[email protected]fb661802013-03-25 01:59:324683 anchor,
4684 position,
4685 bounds,
[email protected]56fffdd2014-02-11 19:50:574686 true,
[email protected]fb661802013-03-25 01:59:324687 false);
4688 grand_child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444689
[email protected]fb661802013-03-25 01:59:324690 // Rotates about the center of the layer
4691 gfx::Transform rotated_leaf_transform;
4692 rotated_leaf_transform.Translate(
4693 -10.0, -10.0); // cancel out the grand_parent's position
4694 rotated_leaf_transform.RotateAboutZAxis(
4695 -45.0); // cancel out the corner 45-degree rotation of the parent.
4696 rotated_leaf_transform.Translate(50.0, 50.0);
4697 rotated_leaf_transform.RotateAboutZAxis(45.0);
4698 rotated_leaf_transform.Translate(-50.0, -50.0);
4699 position = gfx::PointF();
4700 bounds = gfx::Size(100, 100);
4701 SetLayerPropertiesForTesting(rotated_leaf.get(),
4702 rotated_leaf_transform,
[email protected]fb661802013-03-25 01:59:324703 anchor,
4704 position,
4705 bounds,
[email protected]56fffdd2014-02-11 19:50:574706 true,
[email protected]fb661802013-03-25 01:59:324707 false);
4708 rotated_leaf->SetDrawsContent(true);
[email protected]aedf4e52013-01-09 23:24:444709
[email protected]fb661802013-03-25 01:59:324710 grand_child->AddChild(rotated_leaf.Pass());
4711 child->AddChild(grand_child.Pass());
4712 root->AddChild(child.Pass());
4713 }
[email protected]aedf4e52013-01-09 23:24:444714
[email protected]50761e92013-03-29 20:51:284715 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534716 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4717 root.get(), root->bounds(), &render_surface_layer_list);
4718 inputs.can_adjust_raster_scales = true;
4719 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:444720
[email protected]fb661802013-03-25 01:59:324721 // Sanity check the scenario we just created.
4722 // The grand_child is expected to create a render surface because it
[email protected]989386c2013-07-18 21:37:234723 // MasksToBounds and is not axis aligned.
[email protected]fb661802013-03-25 01:59:324724 ASSERT_EQ(2u, render_surface_layer_list.size());
4725 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234726 1u,
4727 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324728 ASSERT_EQ(789,
[email protected]989386c2013-07-18 21:37:234729 render_surface_layer_list.at(0)->render_surface()->layer_list().at(
4730 0)->id()); // grand_child's surface.
[email protected]fb661802013-03-25 01:59:324731 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234732 1u,
4733 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324734 ASSERT_EQ(
4735 2468,
[email protected]989386c2013-07-18 21:37:234736 render_surface_layer_list[1]->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324737
4738 // (11, 89) is close to the the bottom left corner within the clip, but it is
4739 // not inside the layer.
4740 gfx::Point test_point(11, 89);
4741 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4742 test_point, render_surface_layer_list);
4743 EXPECT_FALSE(result_layer);
4744
4745 // Closer inwards from the bottom left will overlap the layer.
4746 test_point = gfx::Point(25, 75);
4747 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4748 test_point, render_surface_layer_list);
4749 ASSERT_TRUE(result_layer);
4750 EXPECT_EQ(2468, result_layer->id());
4751
4752 // (4, 50) is inside the unclipped layer, but that corner of the layer should
4753 // be clipped away by the grandparent and should not get hit. If hit testing
4754 // blindly uses visible content rect without considering how parent may clip
4755 // the layer, then hit testing would accidentally think that the point
4756 // successfully hits the layer.
4757 test_point = gfx::Point(4, 50);
4758 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4759 test_point, render_surface_layer_list);
4760 EXPECT_FALSE(result_layer);
4761
4762 // (11, 50) is inside the layer and within the clipped area.
4763 test_point = gfx::Point(11, 50);
4764 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4765 test_point, render_surface_layer_list);
4766 ASSERT_TRUE(result_layer);
4767 EXPECT_EQ(2468, result_layer->id());
4768
4769 // Around the middle, just to the right and up, would have hit the layer
4770 // except that that area should be clipped away by the parent.
[email protected]803f6b52013-09-12 00:51:264771 test_point = gfx::Point(51, 49);
[email protected]fb661802013-03-25 01:59:324772 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4773 test_point, render_surface_layer_list);
4774 EXPECT_FALSE(result_layer);
4775
4776 // Around the middle, just to the left and down, should successfully hit the
4777 // layer.
4778 test_point = gfx::Point(49, 51);
4779 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4780 test_point, render_surface_layer_list);
4781 ASSERT_TRUE(result_layer);
4782 EXPECT_EQ(2468, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:444783}
4784
[email protected]989386c2013-07-18 21:37:234785TEST_F(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:324786 // This test checks that hit testing code does not accidentally clip to layer
4787 // bounds for a layer that actually does not clip.
4788 gfx::Transform identity_matrix;
4789 gfx::PointF anchor;
[email protected]aedf4e52013-01-09 23:24:444790
[email protected]fb661802013-03-25 01:59:324791 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454792 TestSharedBitmapManager shared_bitmap_manager;
4793 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324794 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4795 SetLayerPropertiesForTesting(root.get(),
4796 identity_matrix,
[email protected]fb661802013-03-25 01:59:324797 anchor,
4798 gfx::PointF(),
4799 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574800 true,
[email protected]fb661802013-03-25 01:59:324801 false);
4802 {
4803 scoped_ptr<LayerImpl> intermediate_layer =
4804 LayerImpl::Create(host_impl.active_tree(), 123);
4805 // this layer is positioned, and hit testing should correctly know where the
4806 // layer is located.
4807 gfx::PointF position(10.f, 10.f);
4808 gfx::Size bounds(50, 50);
4809 SetLayerPropertiesForTesting(intermediate_layer.get(),
4810 identity_matrix,
[email protected]fb661802013-03-25 01:59:324811 anchor,
4812 position,
4813 bounds,
[email protected]56fffdd2014-02-11 19:50:574814 true,
[email protected]fb661802013-03-25 01:59:324815 false);
4816 // Sanity check the intermediate layer should not clip.
4817 ASSERT_FALSE(intermediate_layer->masks_to_bounds());
4818 ASSERT_FALSE(intermediate_layer->mask_layer());
[email protected]aedf4e52013-01-09 23:24:444819
[email protected]fb661802013-03-25 01:59:324820 // The child of the intermediate_layer is translated so that it does not
4821 // overlap intermediate_layer at all. If child is incorrectly clipped, we
4822 // would not be able to hit it successfully.
4823 scoped_ptr<LayerImpl> child =
4824 LayerImpl::Create(host_impl.active_tree(), 456);
4825 position = gfx::PointF(60.f, 60.f); // 70, 70 in screen space
4826 bounds = gfx::Size(20, 20);
4827 SetLayerPropertiesForTesting(child.get(),
4828 identity_matrix,
[email protected]fb661802013-03-25 01:59:324829 anchor,
4830 position,
4831 bounds,
[email protected]56fffdd2014-02-11 19:50:574832 true,
[email protected]fb661802013-03-25 01:59:324833 false);
4834 child->SetDrawsContent(true);
4835 intermediate_layer->AddChild(child.Pass());
4836 root->AddChild(intermediate_layer.Pass());
4837 }
[email protected]aedf4e52013-01-09 23:24:444838
[email protected]50761e92013-03-29 20:51:284839 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534840 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4841 root.get(), root->bounds(), &render_surface_layer_list);
4842 inputs.can_adjust_raster_scales = true;
4843 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:444844
[email protected]fb661802013-03-25 01:59:324845 // Sanity check the scenario we just created.
4846 ASSERT_EQ(1u, render_surface_layer_list.size());
4847 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234848 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]aedf4e52013-01-09 23:24:444849
[email protected]fb661802013-03-25 01:59:324850 // Hit testing for a point outside the layer should return a null pointer.
4851 gfx::Point test_point(69, 69);
4852 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4853 test_point, render_surface_layer_list);
4854 EXPECT_FALSE(result_layer);
[email protected]aedf4e52013-01-09 23:24:444855
[email protected]fb661802013-03-25 01:59:324856 test_point = gfx::Point(91, 91);
4857 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4858 test_point, render_surface_layer_list);
4859 EXPECT_FALSE(result_layer);
4860
4861 // Hit testing for a point inside should return the child layer.
4862 test_point = gfx::Point(71, 71);
4863 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4864 test_point, render_surface_layer_list);
4865 ASSERT_TRUE(result_layer);
4866 EXPECT_EQ(456, result_layer->id());
4867
4868 test_point = gfx::Point(89, 89);
4869 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4870 test_point, render_surface_layer_list);
4871 ASSERT_TRUE(result_layer);
4872 EXPECT_EQ(456, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:444873}
4874
[email protected]989386c2013-07-18 21:37:234875TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayers) {
[email protected]fb661802013-03-25 01:59:324876 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:454877 TestSharedBitmapManager shared_bitmap_manager;
4878 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:324879 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:144880
[email protected]fb661802013-03-25 01:59:324881 gfx::Transform identity_matrix;
4882 gfx::PointF anchor;
4883 gfx::PointF position;
4884 gfx::Size bounds(100, 100);
4885 SetLayerPropertiesForTesting(root.get(),
4886 identity_matrix,
[email protected]fb661802013-03-25 01:59:324887 anchor,
4888 position,
4889 bounds,
[email protected]56fffdd2014-02-11 19:50:574890 true,
[email protected]fb661802013-03-25 01:59:324891 false);
4892 root->SetDrawsContent(true);
4893 {
4894 // child 1 and child2 are initialized to overlap between x=50 and x=60.
4895 // grand_child is set to overlap both child1 and child2 between y=50 and
4896 // y=60. The expected stacking order is: (front) child2, (second)
4897 // grand_child, (third) child1, and (back) the root layer behind all other
4898 // layers.
[email protected]ecc12622012-10-30 20:45:424899
[email protected]fb661802013-03-25 01:59:324900 scoped_ptr<LayerImpl> child1 =
4901 LayerImpl::Create(host_impl.active_tree(), 2);
4902 scoped_ptr<LayerImpl> child2 =
4903 LayerImpl::Create(host_impl.active_tree(), 3);
4904 scoped_ptr<LayerImpl> grand_child1 =
4905 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:144906
[email protected]fb661802013-03-25 01:59:324907 position = gfx::PointF(10.f, 10.f);
4908 bounds = gfx::Size(50, 50);
4909 SetLayerPropertiesForTesting(child1.get(),
4910 identity_matrix,
[email protected]fb661802013-03-25 01:59:324911 anchor,
4912 position,
4913 bounds,
[email protected]56fffdd2014-02-11 19:50:574914 true,
[email protected]fb661802013-03-25 01:59:324915 false);
4916 child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144917
[email protected]fb661802013-03-25 01:59:324918 position = gfx::PointF(50.f, 10.f);
4919 bounds = gfx::Size(50, 50);
4920 SetLayerPropertiesForTesting(child2.get(),
4921 identity_matrix,
[email protected]fb661802013-03-25 01:59:324922 anchor,
4923 position,
4924 bounds,
[email protected]56fffdd2014-02-11 19:50:574925 true,
[email protected]fb661802013-03-25 01:59:324926 false);
4927 child2->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144928
[email protected]fb661802013-03-25 01:59:324929 // Remember that grand_child is positioned with respect to its parent (i.e.
4930 // child1). In screen space, the intended position is (10, 50), with size
4931 // 100 x 50.
4932 position = gfx::PointF(0.f, 40.f);
4933 bounds = gfx::Size(100, 50);
4934 SetLayerPropertiesForTesting(grand_child1.get(),
4935 identity_matrix,
[email protected]fb661802013-03-25 01:59:324936 anchor,
4937 position,
4938 bounds,
[email protected]56fffdd2014-02-11 19:50:574939 true,
[email protected]fb661802013-03-25 01:59:324940 false);
4941 grand_child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144942
[email protected]fb661802013-03-25 01:59:324943 child1->AddChild(grand_child1.Pass());
4944 root->AddChild(child1.Pass());
4945 root->AddChild(child2.Pass());
4946 }
[email protected]94f206c12012-08-25 00:09:144947
[email protected]fb661802013-03-25 01:59:324948 LayerImpl* child1 = root->children()[0];
4949 LayerImpl* child2 = root->children()[1];
4950 LayerImpl* grand_child1 = child1->children()[0];
4951
[email protected]50761e92013-03-29 20:51:284952 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534953 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4954 root.get(), root->bounds(), &render_surface_layer_list);
4955 inputs.can_adjust_raster_scales = true;
4956 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324957
4958 // Sanity check the scenario we just created.
4959 ASSERT_TRUE(child1);
4960 ASSERT_TRUE(child2);
4961 ASSERT_TRUE(grand_child1);
4962 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234963
4964 RenderSurfaceImpl* root_render_surface = root->render_surface();
4965 ASSERT_EQ(4u, root_render_surface->layer_list().size());
4966 ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer
4967 ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1
4968 ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1
4969 ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2
[email protected]fb661802013-03-25 01:59:324970
4971 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
4972 // the root layer.
4973 gfx::Point test_point = gfx::Point(1, 1);
4974 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4975 test_point, render_surface_layer_list);
4976 ASSERT_TRUE(result_layer);
4977 EXPECT_EQ(1, result_layer->id());
4978
4979 // At (15, 15), child1 and root are the only layers. child1 is expected to be
4980 // on top.
4981 test_point = gfx::Point(15, 15);
4982 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4983 test_point, render_surface_layer_list);
4984 ASSERT_TRUE(result_layer);
4985 EXPECT_EQ(2, result_layer->id());
4986
4987 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
4988 test_point = gfx::Point(51, 20);
4989 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4990 test_point, render_surface_layer_list);
4991 ASSERT_TRUE(result_layer);
4992 EXPECT_EQ(3, result_layer->id());
4993
4994 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
4995 // top.
4996 test_point = gfx::Point(80, 51);
4997 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4998 test_point, render_surface_layer_list);
4999 ASSERT_TRUE(result_layer);
5000 EXPECT_EQ(3, result_layer->id());
5001
5002 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5003 // of all other layers.
5004 test_point = gfx::Point(51, 51);
5005 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5006 test_point, render_surface_layer_list);
5007 ASSERT_TRUE(result_layer);
5008 EXPECT_EQ(3, result_layer->id());
5009
5010 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5011 // be on top.
5012 test_point = gfx::Point(20, 51);
5013 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5014 test_point, render_surface_layer_list);
5015 ASSERT_TRUE(result_layer);
5016 EXPECT_EQ(4, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145017}
5018
[email protected]989386c2013-07-18 21:37:235019TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) {
[email protected]fb661802013-03-25 01:59:325020 //
5021 // The geometry is set up similarly to the previous case, but
5022 // all layers are forced to be render surfaces now.
5023 //
5024 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455025 TestSharedBitmapManager shared_bitmap_manager;
5026 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325027 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145028
[email protected]fb661802013-03-25 01:59:325029 gfx::Transform identity_matrix;
5030 gfx::PointF anchor;
5031 gfx::PointF position;
5032 gfx::Size bounds(100, 100);
5033 SetLayerPropertiesForTesting(root.get(),
5034 identity_matrix,
[email protected]fb661802013-03-25 01:59:325035 anchor,
5036 position,
5037 bounds,
[email protected]56fffdd2014-02-11 19:50:575038 true,
[email protected]fb661802013-03-25 01:59:325039 false);
5040 root->SetDrawsContent(true);
5041 {
5042 // child 1 and child2 are initialized to overlap between x=50 and x=60.
5043 // grand_child is set to overlap both child1 and child2 between y=50 and
5044 // y=60. The expected stacking order is: (front) child2, (second)
5045 // grand_child, (third) child1, and (back) the root layer behind all other
5046 // layers.
[email protected]94f206c12012-08-25 00:09:145047
[email protected]fb661802013-03-25 01:59:325048 scoped_ptr<LayerImpl> child1 =
5049 LayerImpl::Create(host_impl.active_tree(), 2);
5050 scoped_ptr<LayerImpl> child2 =
5051 LayerImpl::Create(host_impl.active_tree(), 3);
5052 scoped_ptr<LayerImpl> grand_child1 =
5053 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:145054
[email protected]fb661802013-03-25 01:59:325055 position = gfx::PointF(10.f, 10.f);
5056 bounds = gfx::Size(50, 50);
5057 SetLayerPropertiesForTesting(child1.get(),
5058 identity_matrix,
[email protected]fb661802013-03-25 01:59:325059 anchor,
5060 position,
5061 bounds,
[email protected]56fffdd2014-02-11 19:50:575062 true,
[email protected]fb661802013-03-25 01:59:325063 false);
5064 child1->SetDrawsContent(true);
5065 child1->SetForceRenderSurface(true);
[email protected]ecc12622012-10-30 20:45:425066
[email protected]fb661802013-03-25 01:59:325067 position = gfx::PointF(50.f, 10.f);
5068 bounds = gfx::Size(50, 50);
5069 SetLayerPropertiesForTesting(child2.get(),
5070 identity_matrix,
[email protected]fb661802013-03-25 01:59:325071 anchor,
5072 position,
5073 bounds,
[email protected]56fffdd2014-02-11 19:50:575074 true,
[email protected]fb661802013-03-25 01:59:325075 false);
5076 child2->SetDrawsContent(true);
[email protected]7aba6662013-03-12 10:17:345077 child2->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015078
[email protected]fb661802013-03-25 01:59:325079 // Remember that grand_child is positioned with respect to its parent (i.e.
5080 // child1). In screen space, the intended position is (10, 50), with size
5081 // 100 x 50.
5082 position = gfx::PointF(0.f, 40.f);
5083 bounds = gfx::Size(100, 50);
5084 SetLayerPropertiesForTesting(grand_child1.get(),
5085 identity_matrix,
[email protected]fb661802013-03-25 01:59:325086 anchor,
5087 position,
5088 bounds,
[email protected]56fffdd2014-02-11 19:50:575089 true,
[email protected]fb661802013-03-25 01:59:325090 false);
5091 grand_child1->SetDrawsContent(true);
5092 grand_child1->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015093
[email protected]fb661802013-03-25 01:59:325094 child1->AddChild(grand_child1.Pass());
5095 root->AddChild(child1.Pass());
5096 root->AddChild(child2.Pass());
5097 }
[email protected]dc462d782012-11-21 21:43:015098
[email protected]fb661802013-03-25 01:59:325099 LayerImpl* child1 = root->children()[0];
5100 LayerImpl* child2 = root->children()[1];
5101 LayerImpl* grand_child1 = child1->children()[0];
[email protected]dc462d782012-11-21 21:43:015102
[email protected]50761e92013-03-29 20:51:285103 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535104 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5105 root.get(), root->bounds(), &render_surface_layer_list);
5106 inputs.can_adjust_raster_scales = true;
5107 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]dc462d782012-11-21 21:43:015108
[email protected]fb661802013-03-25 01:59:325109 // Sanity check the scenario we just created.
5110 ASSERT_TRUE(child1);
5111 ASSERT_TRUE(child2);
5112 ASSERT_TRUE(grand_child1);
5113 ASSERT_TRUE(child1->render_surface());
5114 ASSERT_TRUE(child2->render_surface());
5115 ASSERT_TRUE(grand_child1->render_surface());
5116 ASSERT_EQ(4u, render_surface_layer_list.size());
5117 // The root surface has the root layer, and child1's and child2's render
5118 // surfaces.
5119 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
5120 // The child1 surface has the child1 layer and grand_child1's render surface.
5121 ASSERT_EQ(2u, child1->render_surface()->layer_list().size());
5122 ASSERT_EQ(1u, child2->render_surface()->layer_list().size());
5123 ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235124 ASSERT_EQ(1, render_surface_layer_list.at(0)->id()); // root layer
[email protected]fb661802013-03-25 01:59:325125 ASSERT_EQ(2, render_surface_layer_list[1]->id()); // child1
[email protected]989386c2013-07-18 21:37:235126 ASSERT_EQ(4, render_surface_layer_list.at(2)->id()); // grand_child1
[email protected]fb661802013-03-25 01:59:325127 ASSERT_EQ(3, render_surface_layer_list[3]->id()); // child2
[email protected]dc462d782012-11-21 21:43:015128
[email protected]fb661802013-03-25 01:59:325129 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5130 // the root layer.
5131 gfx::Point test_point = gfx::Point(1, 1);
5132 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5133 test_point, render_surface_layer_list);
5134 ASSERT_TRUE(result_layer);
5135 EXPECT_EQ(1, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015136
[email protected]fb661802013-03-25 01:59:325137 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5138 // on top.
5139 test_point = gfx::Point(15, 15);
5140 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5141 test_point, render_surface_layer_list);
5142 ASSERT_TRUE(result_layer);
5143 EXPECT_EQ(2, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015144
[email protected]fb661802013-03-25 01:59:325145 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5146 test_point = gfx::Point(51, 20);
5147 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5148 test_point, render_surface_layer_list);
5149 ASSERT_TRUE(result_layer);
5150 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015151
[email protected]fb661802013-03-25 01:59:325152 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5153 // top.
5154 test_point = gfx::Point(80, 51);
5155 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5156 test_point, render_surface_layer_list);
5157 ASSERT_TRUE(result_layer);
5158 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015159
[email protected]fb661802013-03-25 01:59:325160 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5161 // of all other layers.
5162 test_point = gfx::Point(51, 51);
5163 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5164 test_point, render_surface_layer_list);
5165 ASSERT_TRUE(result_layer);
5166 EXPECT_EQ(3, result_layer->id());
5167
5168 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5169 // be on top.
5170 test_point = gfx::Point(20, 51);
5171 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5172 test_point, render_surface_layer_list);
5173 ASSERT_TRUE(result_layer);
5174 EXPECT_EQ(4, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015175}
5176
[email protected]afc4f262013-10-05 01:14:105177TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayers) {
5178 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455179 TestSharedBitmapManager shared_bitmap_manager;
5180 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]afc4f262013-10-05 01:14:105181
5182 // Layer 1 - root
5183 scoped_ptr<LayerImpl> root =
5184 LayerImpl::Create(host_impl.active_tree(), 1);
5185 gfx::Transform identity_matrix;
5186 gfx::PointF anchor;
5187 gfx::PointF position;
5188 gfx::Size bounds(100, 100);
5189 SetLayerPropertiesForTesting(root.get(),
5190 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105191 anchor,
5192 position,
5193 bounds,
[email protected]56fffdd2014-02-11 19:50:575194 true,
[email protected]afc4f262013-10-05 01:14:105195 false);
5196 root->SetDrawsContent(true);
5197
5198 {
5199 // Layer 2 - empty: drawsContent=false
5200 gfx::PointF position(10.f, 10.f);
5201 gfx::Size bounds(30, 30);
5202 scoped_ptr<LayerImpl> empty_layer =
5203 LayerImpl::Create(host_impl.active_tree(), 2);
5204 SetLayerPropertiesForTesting(empty_layer.get(),
5205 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105206 anchor,
5207 position,
5208 bounds,
[email protected]56fffdd2014-02-11 19:50:575209 true,
[email protected]afc4f262013-10-05 01:14:105210 false);
5211
5212 empty_layer->SetDrawsContent(false);
5213 root->AddChild(empty_layer.Pass());
5214 }
5215
5216 {
5217 // Layer 3 - empty, but has touch handler
5218 gfx::PointF position(10.f, 60.f);
5219 gfx::Size bounds(30, 30);
5220 scoped_ptr<LayerImpl> test_layer =
5221 LayerImpl::Create(host_impl.active_tree(), 3);
5222 SetLayerPropertiesForTesting(test_layer.get(),
5223 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105224 anchor,
5225 position,
5226 bounds,
[email protected]56fffdd2014-02-11 19:50:575227 true,
[email protected]afc4f262013-10-05 01:14:105228 false);
5229
5230 test_layer->SetDrawsContent(false);
5231 Region touch_handler_region(gfx::Rect(10, 10, 10, 10));
5232 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5233 root->AddChild(test_layer.Pass());
5234 }
5235
5236 {
5237 // Layer 4 - empty, but has mousewheel handler
5238 gfx::PointF position(60.f, 60.f);
5239 gfx::Size bounds(30, 30);
5240 scoped_ptr<LayerImpl> test_layer =
5241 LayerImpl::Create(host_impl.active_tree(), 4);
5242 SetLayerPropertiesForTesting(test_layer.get(),
5243 identity_matrix,
[email protected]afc4f262013-10-05 01:14:105244 anchor,
5245 position,
5246 bounds,
[email protected]56fffdd2014-02-11 19:50:575247 true,
[email protected]afc4f262013-10-05 01:14:105248 false);
5249
5250 test_layer->SetDrawsContent(false);
5251 test_layer->SetHaveWheelEventHandlers(true);
5252 root->AddChild(test_layer.Pass());
5253 }
5254
5255 LayerImplList render_surface_layer_list;
5256 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5257 root.get(), root->bounds(), &render_surface_layer_list);
5258 inputs.can_adjust_raster_scales = true;
5259 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5260
5261 // Verify that the root layer and empty layers with touch/wheel handlers
5262 // (but not the empty layer without a touch handler) are in the RSSL.
5263 ASSERT_EQ(1u, render_surface_layer_list.size());
5264 EXPECT_EQ(1, render_surface_layer_list[0]->id());
[email protected]22538a2d2013-11-12 11:24:455265 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
[email protected]afc4f262013-10-05 01:14:105266 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]22538a2d2013-11-12 11:24:455267 EXPECT_EQ(3, root->render_surface()->layer_list().at(1)->id());
5268 EXPECT_EQ(4, root->render_surface()->layer_list().at(2)->id());
[email protected]afc4f262013-10-05 01:14:105269
5270 // Hit testing for a point inside the empty no-handlers layer should return
5271 // the root layer.
5272 gfx::Point test_point = gfx::Point(15, 15);
5273 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5274 test_point, render_surface_layer_list);
5275 ASSERT_TRUE(result_layer);
[email protected]22538a2d2013-11-12 11:24:455276 EXPECT_EQ(1, result_layer->id());
[email protected]afc4f262013-10-05 01:14:105277
5278 // Hit testing for a point inside the touch handler layer should return it.
5279 test_point = gfx::Point(15, 75);
5280 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5281 test_point, render_surface_layer_list);
5282 ASSERT_TRUE(result_layer);
5283 EXPECT_EQ(3, result_layer->id());
5284
5285 // Hit testing for a point inside the mousewheel layer should return it.
5286 test_point = gfx::Point(75, 75);
5287 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5288 test_point, render_surface_layer_list);
5289 ASSERT_TRUE(result_layer);
5290 EXPECT_EQ(4, result_layer->id());
5291}
5292
[email protected]989386c2013-07-18 21:37:235293TEST_F(LayerTreeHostCommonTest,
5294 HitCheckingTouchHandlerRegionsForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:325295 // Hit checking on an empty render_surface_layer_list should return a null
5296 // pointer.
[email protected]50761e92013-03-29 20:51:285297 LayerImplList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145298
[email protected]fb661802013-03-25 01:59:325299 gfx::Point test_point(0, 0);
5300 LayerImpl* result_layer =
5301 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5302 test_point, render_surface_layer_list);
5303 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145304
[email protected]fb661802013-03-25 01:59:325305 test_point = gfx::Point(10, 20);
5306 result_layer =
5307 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5308 test_point, render_surface_layer_list);
5309 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145310}
5311
[email protected]989386c2013-07-18 21:37:235312TEST_F(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:325313 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455314 TestSharedBitmapManager shared_bitmap_manager;
5315 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325316 scoped_ptr<LayerImpl> root =
5317 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145318
[email protected]fb661802013-03-25 01:59:325319 gfx::Transform identity_matrix;
5320 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5321 gfx::PointF anchor;
5322 gfx::PointF position;
5323 gfx::Size bounds(100, 100);
5324 SetLayerPropertiesForTesting(root.get(),
5325 identity_matrix,
[email protected]fb661802013-03-25 01:59:325326 anchor,
5327 position,
5328 bounds,
[email protected]56fffdd2014-02-11 19:50:575329 true,
[email protected]fb661802013-03-25 01:59:325330 false);
5331 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145332
[email protected]50761e92013-03-29 20:51:285333 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535334 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5335 root.get(), root->bounds(), &render_surface_layer_list);
5336 inputs.can_adjust_raster_scales = true;
5337 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145338
[email protected]fb661802013-03-25 01:59:325339 // Sanity check the scenario we just created.
5340 ASSERT_EQ(1u, render_surface_layer_list.size());
5341 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145342
[email protected]fb661802013-03-25 01:59:325343 // Hit checking for any point should return a null pointer for a layer without
5344 // any touch event handler regions.
5345 gfx::Point test_point(11, 11);
5346 LayerImpl* result_layer =
5347 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5348 test_point, render_surface_layer_list);
5349 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145350
[email protected]fb661802013-03-25 01:59:325351 root->SetTouchEventHandlerRegion(touch_handler_region);
5352 // Hit checking for a point outside the layer should return a null pointer.
5353 test_point = gfx::Point(101, 101);
5354 result_layer =
5355 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5356 test_point, render_surface_layer_list);
5357 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145358
[email protected]fb661802013-03-25 01:59:325359 test_point = gfx::Point(-1, -1);
5360 result_layer =
5361 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5362 test_point, render_surface_layer_list);
5363 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145364
[email protected]fb661802013-03-25 01:59:325365 // Hit checking for a point inside the layer, but outside the touch handler
5366 // region should return a null pointer.
5367 test_point = gfx::Point(1, 1);
5368 result_layer =
5369 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5370 test_point, render_surface_layer_list);
5371 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145372
[email protected]fb661802013-03-25 01:59:325373 test_point = gfx::Point(99, 99);
5374 result_layer =
5375 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5376 test_point, render_surface_layer_list);
5377 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145378
[email protected]fb661802013-03-25 01:59:325379 // Hit checking for a point inside the touch event handler region should
5380 // return the root layer.
5381 test_point = gfx::Point(11, 11);
5382 result_layer =
5383 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5384 test_point, render_surface_layer_list);
5385 ASSERT_TRUE(result_layer);
5386 EXPECT_EQ(12345, result_layer->id());
5387
5388 test_point = gfx::Point(59, 59);
5389 result_layer =
5390 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5391 test_point, render_surface_layer_list);
5392 ASSERT_TRUE(result_layer);
5393 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145394}
5395
[email protected]989386c2013-07-18 21:37:235396TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325397 HitCheckingTouchHandlerRegionsForUninvertibleTransform) {
5398 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455399 TestSharedBitmapManager shared_bitmap_manager;
5400 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325401 scoped_ptr<LayerImpl> root =
5402 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145403
[email protected]fb661802013-03-25 01:59:325404 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:265405 uninvertible_transform.matrix().set(0, 0, 0.0);
5406 uninvertible_transform.matrix().set(1, 1, 0.0);
5407 uninvertible_transform.matrix().set(2, 2, 0.0);
5408 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:325409 ASSERT_FALSE(uninvertible_transform.IsInvertible());
[email protected]94f206c12012-08-25 00:09:145410
[email protected]fb661802013-03-25 01:59:325411 gfx::Transform identity_matrix;
5412 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5413 gfx::PointF anchor;
5414 gfx::PointF position;
5415 gfx::Size bounds(100, 100);
5416 SetLayerPropertiesForTesting(root.get(),
5417 uninvertible_transform,
[email protected]fb661802013-03-25 01:59:325418 anchor,
5419 position,
5420 bounds,
[email protected]56fffdd2014-02-11 19:50:575421 true,
[email protected]fb661802013-03-25 01:59:325422 false);
5423 root->SetDrawsContent(true);
5424 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145425
[email protected]50761e92013-03-29 20:51:285426 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535427 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5428 root.get(), root->bounds(), &render_surface_layer_list);
5429 inputs.can_adjust_raster_scales = true;
5430 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145431
[email protected]fb661802013-03-25 01:59:325432 // Sanity check the scenario we just created.
5433 ASSERT_EQ(1u, render_surface_layer_list.size());
5434 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5435 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
[email protected]de4afb5e2012-12-20 00:11:345436
[email protected]fb661802013-03-25 01:59:325437 // Hit checking any point should not hit the touch handler region on the
5438 // layer. If the invertible matrix is accidentally ignored and treated like an
5439 // identity, then the hit testing will incorrectly hit the layer when it
5440 // shouldn't.
5441 gfx::Point test_point(1, 1);
5442 LayerImpl* result_layer =
5443 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5444 test_point, render_surface_layer_list);
5445 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345446
[email protected]fb661802013-03-25 01:59:325447 test_point = gfx::Point(10, 10);
5448 result_layer =
5449 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5450 test_point, render_surface_layer_list);
5451 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345452
[email protected]fb661802013-03-25 01:59:325453 test_point = gfx::Point(10, 30);
5454 result_layer =
5455 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5456 test_point, render_surface_layer_list);
5457 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345458
[email protected]fb661802013-03-25 01:59:325459 test_point = gfx::Point(50, 50);
5460 result_layer =
5461 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5462 test_point, render_surface_layer_list);
5463 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145464
[email protected]fb661802013-03-25 01:59:325465 test_point = gfx::Point(67, 48);
5466 result_layer =
5467 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5468 test_point, render_surface_layer_list);
5469 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145470
[email protected]fb661802013-03-25 01:59:325471 test_point = gfx::Point(99, 99);
5472 result_layer =
5473 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5474 test_point, render_surface_layer_list);
5475 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145476
[email protected]fb661802013-03-25 01:59:325477 test_point = gfx::Point(-1, -1);
5478 result_layer =
5479 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5480 test_point, render_surface_layer_list);
5481 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145482}
5483
[email protected]989386c2013-07-18 21:37:235484TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325485 HitCheckingTouchHandlerRegionsForSinglePositionedLayer) {
5486 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455487 TestSharedBitmapManager shared_bitmap_manager;
5488 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325489 scoped_ptr<LayerImpl> root =
5490 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145491
[email protected]fb661802013-03-25 01:59:325492 gfx::Transform identity_matrix;
5493 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5494 gfx::PointF anchor;
5495 // this layer is positioned, and hit testing should correctly know where the
5496 // layer is located.
5497 gfx::PointF position(50.f, 50.f);
5498 gfx::Size bounds(100, 100);
5499 SetLayerPropertiesForTesting(root.get(),
5500 identity_matrix,
[email protected]fb661802013-03-25 01:59:325501 anchor,
5502 position,
5503 bounds,
[email protected]56fffdd2014-02-11 19:50:575504 true,
[email protected]fb661802013-03-25 01:59:325505 false);
5506 root->SetDrawsContent(true);
5507 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145508
[email protected]50761e92013-03-29 20:51:285509 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535510 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5511 root.get(), root->bounds(), &render_surface_layer_list);
5512 inputs.can_adjust_raster_scales = true;
5513 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145514
[email protected]fb661802013-03-25 01:59:325515 // Sanity check the scenario we just created.
5516 ASSERT_EQ(1u, render_surface_layer_list.size());
5517 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145518
[email protected]fb661802013-03-25 01:59:325519 // Hit checking for a point outside the layer should return a null pointer.
5520 gfx::Point test_point(49, 49);
5521 LayerImpl* result_layer =
5522 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5523 test_point, render_surface_layer_list);
5524 EXPECT_FALSE(result_layer);
5525
5526 // Even though the layer has a touch handler region containing (101, 101), it
5527 // should not be visible there since the root render surface would clamp it.
5528 test_point = gfx::Point(101, 101);
5529 result_layer =
5530 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5531 test_point, render_surface_layer_list);
5532 EXPECT_FALSE(result_layer);
5533
5534 // Hit checking for a point inside the layer, but outside the touch handler
5535 // region should return a null pointer.
5536 test_point = gfx::Point(51, 51);
5537 result_layer =
5538 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5539 test_point, render_surface_layer_list);
5540 EXPECT_FALSE(result_layer);
5541
5542 // Hit checking for a point inside the touch event handler region should
5543 // return the root layer.
5544 test_point = gfx::Point(61, 61);
5545 result_layer =
5546 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5547 test_point, render_surface_layer_list);
5548 ASSERT_TRUE(result_layer);
5549 EXPECT_EQ(12345, result_layer->id());
5550
5551 test_point = gfx::Point(99, 99);
5552 result_layer =
5553 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5554 test_point, render_surface_layer_list);
5555 ASSERT_TRUE(result_layer);
5556 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145557}
5558
[email protected]989386c2013-07-18 21:37:235559TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325560 HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) {
5561 // A layer's visible content rect is actually in the layer's content space.
5562 // The screen space transform converts from the layer's origin space to screen
5563 // space. This test makes sure that hit testing works correctly accounts for
5564 // the contents scale. A contents scale that is not 1 effectively forces a
5565 // non-identity transform between layer's content space and layer's origin
5566 // space. The hit testing code must take this into account.
5567 //
5568 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
5569 // contents scale is ignored, then hit checking will mis-interpret the visible
5570 // content rect as being larger than the actual bounds of the layer.
5571 //
5572 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455573 TestSharedBitmapManager shared_bitmap_manager;
5574 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325575 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145576
[email protected]fb661802013-03-25 01:59:325577 gfx::Transform identity_matrix;
5578 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145579
[email protected]fb661802013-03-25 01:59:325580 SetLayerPropertiesForTesting(root.get(),
5581 identity_matrix,
[email protected]fb661802013-03-25 01:59:325582 anchor,
5583 gfx::PointF(),
5584 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575585 true,
[email protected]fb661802013-03-25 01:59:325586 false);
5587 {
5588 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5589 gfx::PointF position(25.f, 25.f);
5590 gfx::Size bounds(50, 50);
5591 scoped_ptr<LayerImpl> test_layer =
5592 LayerImpl::Create(host_impl.active_tree(), 12345);
5593 SetLayerPropertiesForTesting(test_layer.get(),
5594 identity_matrix,
[email protected]fb661802013-03-25 01:59:325595 anchor,
5596 position,
5597 bounds,
[email protected]56fffdd2014-02-11 19:50:575598 true,
[email protected]fb661802013-03-25 01:59:325599 false);
[email protected]94f206c12012-08-25 00:09:145600
[email protected]fb661802013-03-25 01:59:325601 // override content bounds and contents scale
5602 test_layer->SetContentBounds(gfx::Size(100, 100));
5603 test_layer->SetContentsScale(2, 2);
[email protected]94f206c12012-08-25 00:09:145604
[email protected]fb661802013-03-25 01:59:325605 test_layer->SetDrawsContent(true);
5606 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5607 root->AddChild(test_layer.Pass());
5608 }
5609
[email protected]50761e92013-03-29 20:51:285610 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535611 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5612 root.get(), root->bounds(), &render_surface_layer_list);
5613 inputs.can_adjust_raster_scales = true;
5614 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325615
5616 // Sanity check the scenario we just created.
5617 // The visible content rect for test_layer is actually 100x100, even though
5618 // its layout size is 50x50, positioned at 25x25.
5619 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:055620 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect());
[email protected]fb661802013-03-25 01:59:325621 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455622 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:325623
5624 // Hit checking for a point outside the layer should return a null pointer
5625 // (the root layer does not draw content, so it will not be tested either).
5626 gfx::Point test_point(76, 76);
5627 LayerImpl* result_layer =
5628 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5629 test_point, render_surface_layer_list);
5630 EXPECT_FALSE(result_layer);
5631
5632 // Hit checking for a point inside the layer, but outside the touch handler
5633 // region should return a null pointer.
5634 test_point = gfx::Point(26, 26);
5635 result_layer =
5636 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5637 test_point, render_surface_layer_list);
5638 EXPECT_FALSE(result_layer);
5639
5640 test_point = gfx::Point(34, 34);
5641 result_layer =
5642 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5643 test_point, render_surface_layer_list);
5644 EXPECT_FALSE(result_layer);
5645
5646 test_point = gfx::Point(65, 65);
5647 result_layer =
5648 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5649 test_point, render_surface_layer_list);
5650 EXPECT_FALSE(result_layer);
5651
5652 test_point = gfx::Point(74, 74);
5653 result_layer =
5654 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5655 test_point, render_surface_layer_list);
5656 EXPECT_FALSE(result_layer);
5657
5658 // Hit checking for a point inside the touch event handler region should
5659 // return the root layer.
5660 test_point = gfx::Point(35, 35);
5661 result_layer =
5662 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5663 test_point, render_surface_layer_list);
5664 ASSERT_TRUE(result_layer);
5665 EXPECT_EQ(12345, result_layer->id());
5666
5667 test_point = gfx::Point(64, 64);
5668 result_layer =
5669 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5670 test_point, render_surface_layer_list);
5671 ASSERT_TRUE(result_layer);
5672 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145673}
5674
[email protected]989386c2013-07-18 21:37:235675TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325676 HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) {
5677 // The layer's device_scale_factor and page_scale_factor should scale the
5678 // content rect and we should be able to hit the touch handler region by
5679 // scaling the points accordingly.
5680 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455681 TestSharedBitmapManager shared_bitmap_manager;
5682 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325683 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145684
[email protected]fb661802013-03-25 01:59:325685 gfx::Transform identity_matrix;
5686 gfx::PointF anchor;
5687 // Set the bounds of the root layer big enough to fit the child when scaled.
5688 SetLayerPropertiesForTesting(root.get(),
5689 identity_matrix,
[email protected]fb661802013-03-25 01:59:325690 anchor,
5691 gfx::PointF(),
5692 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575693 true,
[email protected]fb661802013-03-25 01:59:325694 false);
5695 {
5696 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5697 gfx::PointF position(25.f, 25.f);
5698 gfx::Size bounds(50, 50);
5699 scoped_ptr<LayerImpl> test_layer =
5700 LayerImpl::Create(host_impl.active_tree(), 12345);
5701 SetLayerPropertiesForTesting(test_layer.get(),
5702 identity_matrix,
[email protected]fb661802013-03-25 01:59:325703 anchor,
5704 position,
5705 bounds,
[email protected]56fffdd2014-02-11 19:50:575706 true,
[email protected]fb661802013-03-25 01:59:325707 false);
[email protected]94f206c12012-08-25 00:09:145708
[email protected]fb661802013-03-25 01:59:325709 test_layer->SetDrawsContent(true);
5710 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5711 root->AddChild(test_layer.Pass());
5712 }
[email protected]94f206c12012-08-25 00:09:145713
[email protected]50761e92013-03-29 20:51:285714 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:325715 float device_scale_factor = 3.f;
5716 float page_scale_factor = 5.f;
[email protected]fb661802013-03-25 01:59:325717 gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize(
5718 gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor));
[email protected]7aad55f2013-07-26 11:25:535719
5720 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5721 root.get(), scaled_bounds_for_root, &render_surface_layer_list);
5722 inputs.device_scale_factor = device_scale_factor;
5723 inputs.page_scale_factor = page_scale_factor;
5724 inputs.page_scale_application_layer = root.get();
5725 inputs.can_adjust_raster_scales = true;
5726 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145727
[email protected]fb661802013-03-25 01:59:325728 // Sanity check the scenario we just created.
5729 // The visible content rect for test_layer is actually 100x100, even though
5730 // its layout size is 50x50, positioned at 25x25.
5731 LayerImpl* test_layer = root->children()[0];
5732 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455733 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145734
[email protected]fb661802013-03-25 01:59:325735 // Check whether the child layer fits into the root after scaled.
5736 EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()),
5737 test_layer->visible_content_rect());
5738
5739 // Hit checking for a point outside the layer should return a null pointer
5740 // (the root layer does not draw content, so it will not be tested either).
5741 gfx::PointF test_point(76.f, 76.f);
5742 test_point =
5743 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5744 LayerImpl* result_layer =
5745 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5746 test_point, render_surface_layer_list);
5747 EXPECT_FALSE(result_layer);
5748
5749 // Hit checking for a point inside the layer, but outside the touch handler
5750 // region should return a null pointer.
5751 test_point = gfx::Point(26, 26);
5752 test_point =
5753 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5754 result_layer =
5755 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5756 test_point, render_surface_layer_list);
5757 EXPECT_FALSE(result_layer);
5758
5759 test_point = gfx::Point(34, 34);
5760 test_point =
5761 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5762 result_layer =
5763 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5764 test_point, render_surface_layer_list);
5765 EXPECT_FALSE(result_layer);
5766
5767 test_point = gfx::Point(65, 65);
5768 test_point =
5769 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5770 result_layer =
5771 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5772 test_point, render_surface_layer_list);
5773 EXPECT_FALSE(result_layer);
5774
5775 test_point = gfx::Point(74, 74);
5776 test_point =
5777 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5778 result_layer =
5779 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5780 test_point, render_surface_layer_list);
5781 EXPECT_FALSE(result_layer);
5782
5783 // Hit checking for a point inside the touch event handler region should
5784 // return the root layer.
5785 test_point = gfx::Point(35, 35);
5786 test_point =
5787 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5788 result_layer =
5789 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5790 test_point, render_surface_layer_list);
5791 ASSERT_TRUE(result_layer);
5792 EXPECT_EQ(12345, result_layer->id());
5793
5794 test_point = gfx::Point(64, 64);
5795 test_point =
5796 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5797 result_layer =
5798 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5799 test_point, render_surface_layer_list);
5800 ASSERT_TRUE(result_layer);
5801 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145802}
5803
[email protected]989386c2013-07-18 21:37:235804TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325805 HitCheckingTouchHandlerRegionsForSimpleClippedLayer) {
5806 // Test that hit-checking will only work for the visible portion of a layer,
5807 // and not the entire layer bounds. Here we just test the simple axis-aligned
5808 // case.
5809 gfx::Transform identity_matrix;
5810 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145811
[email protected]fb661802013-03-25 01:59:325812 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455813 TestSharedBitmapManager shared_bitmap_manager;
5814 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]fb661802013-03-25 01:59:325815 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5816 SetLayerPropertiesForTesting(root.get(),
5817 identity_matrix,
[email protected]fb661802013-03-25 01:59:325818 anchor,
5819 gfx::PointF(),
5820 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575821 true,
[email protected]fb661802013-03-25 01:59:325822 false);
5823 {
5824 scoped_ptr<LayerImpl> clipping_layer =
5825 LayerImpl::Create(host_impl.active_tree(), 123);
5826 // this layer is positioned, and hit testing should correctly know where the
5827 // layer is located.
5828 gfx::PointF position(25.f, 25.f);
5829 gfx::Size bounds(50, 50);
5830 SetLayerPropertiesForTesting(clipping_layer.get(),
5831 identity_matrix,
[email protected]fb661802013-03-25 01:59:325832 anchor,
5833 position,
5834 bounds,
[email protected]56fffdd2014-02-11 19:50:575835 true,
[email protected]fb661802013-03-25 01:59:325836 false);
5837 clipping_layer->SetMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:145838
[email protected]fb661802013-03-25 01:59:325839 scoped_ptr<LayerImpl> child =
5840 LayerImpl::Create(host_impl.active_tree(), 456);
5841 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5842 position = gfx::PointF(-50.f, -50.f);
5843 bounds = gfx::Size(300, 300);
5844 SetLayerPropertiesForTesting(child.get(),
5845 identity_matrix,
[email protected]fb661802013-03-25 01:59:325846 anchor,
5847 position,
5848 bounds,
[email protected]56fffdd2014-02-11 19:50:575849 true,
[email protected]fb661802013-03-25 01:59:325850 false);
5851 child->SetDrawsContent(true);
5852 child->SetTouchEventHandlerRegion(touch_handler_region);
5853 clipping_layer->AddChild(child.Pass());
5854 root->AddChild(clipping_layer.Pass());
5855 }
[email protected]94f206c12012-08-25 00:09:145856
[email protected]50761e92013-03-29 20:51:285857 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535858 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5859 root.get(), root->bounds(), &render_surface_layer_list);
5860 inputs.can_adjust_raster_scales = true;
5861 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325862
5863 // Sanity check the scenario we just created.
5864 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455865 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5866 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:325867
5868 // Hit checking for a point outside the layer should return a null pointer.
5869 // Despite the child layer being very large, it should be clipped to the root
5870 // layer's bounds.
5871 gfx::Point test_point(24, 24);
5872 LayerImpl* result_layer =
5873 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5874 test_point, render_surface_layer_list);
5875 EXPECT_FALSE(result_layer);
5876
5877 // Hit checking for a point inside the layer, but outside the touch handler
5878 // region should return a null pointer.
5879 test_point = gfx::Point(35, 35);
5880 result_layer =
5881 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5882 test_point, render_surface_layer_list);
5883 EXPECT_FALSE(result_layer);
5884
5885 test_point = gfx::Point(74, 74);
5886 result_layer =
5887 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5888 test_point, render_surface_layer_list);
5889 EXPECT_FALSE(result_layer);
5890
5891 // Hit checking for a point inside the touch event handler region should
5892 // return the root layer.
5893 test_point = gfx::Point(25, 25);
5894 result_layer =
5895 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5896 test_point, render_surface_layer_list);
5897 ASSERT_TRUE(result_layer);
5898 EXPECT_EQ(456, result_layer->id());
5899
5900 test_point = gfx::Point(34, 34);
5901 result_layer =
5902 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5903 test_point, render_surface_layer_list);
5904 ASSERT_TRUE(result_layer);
5905 EXPECT_EQ(456, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145906}
5907
[email protected]c974d5d2013-10-24 01:02:485908TEST_F(LayerTreeHostCommonTest,
5909 HitCheckingTouchHandlerOverlappingRegions) {
5910 gfx::Transform identity_matrix;
5911 gfx::PointF anchor;
5912
5913 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455914 TestSharedBitmapManager shared_bitmap_manager;
5915 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c974d5d2013-10-24 01:02:485916 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5917 SetLayerPropertiesForTesting(root.get(),
5918 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:485919 anchor,
5920 gfx::PointF(),
5921 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575922 true,
[email protected]c974d5d2013-10-24 01:02:485923 false);
5924 {
5925 scoped_ptr<LayerImpl> touch_layer =
5926 LayerImpl::Create(host_impl.active_tree(), 123);
5927 // this layer is positioned, and hit testing should correctly know where the
5928 // layer is located.
5929 gfx::PointF position;
5930 gfx::Size bounds(50, 50);
5931 SetLayerPropertiesForTesting(touch_layer.get(),
5932 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:485933 anchor,
5934 position,
5935 bounds,
[email protected]56fffdd2014-02-11 19:50:575936 true,
[email protected]c974d5d2013-10-24 01:02:485937 false);
5938 touch_layer->SetDrawsContent(true);
5939 touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50));
5940 root->AddChild(touch_layer.Pass());
5941 }
5942
5943 {
5944 scoped_ptr<LayerImpl> notouch_layer =
5945 LayerImpl::Create(host_impl.active_tree(), 1234);
5946 // this layer is positioned, and hit testing should correctly know where the
5947 // layer is located.
5948 gfx::PointF position(0, 25);
5949 gfx::Size bounds(50, 50);
5950 SetLayerPropertiesForTesting(notouch_layer.get(),
5951 identity_matrix,
[email protected]c974d5d2013-10-24 01:02:485952 anchor,
5953 position,
5954 bounds,
[email protected]56fffdd2014-02-11 19:50:575955 true,
[email protected]c974d5d2013-10-24 01:02:485956 false);
5957 notouch_layer->SetDrawsContent(true);
5958 root->AddChild(notouch_layer.Pass());
5959 }
5960
5961 LayerImplList render_surface_layer_list;
5962 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5963 root.get(), root->bounds(), &render_surface_layer_list);
5964 inputs.can_adjust_raster_scales = true;
5965 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5966
5967 // Sanity check the scenario we just created.
5968 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455969 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5970 ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id());
5971 ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id());
[email protected]c974d5d2013-10-24 01:02:485972
5973 gfx::Point test_point(35, 35);
5974 LayerImpl* result_layer =
5975 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5976 test_point, render_surface_layer_list);
5977 EXPECT_FALSE(result_layer);
5978
5979 test_point = gfx::Point(35, 15);
5980 result_layer =
5981 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5982 test_point, render_surface_layer_list);
5983 ASSERT_TRUE(result_layer);
5984 EXPECT_EQ(123, result_layer->id());
5985
5986 test_point = gfx::Point(35, 65);
5987 result_layer =
5988 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5989 test_point, render_surface_layer_list);
5990 EXPECT_FALSE(result_layer);
5991}
5992
[email protected]fb661802013-03-25 01:59:325993class NoScaleContentLayer : public ContentLayer {
5994 public:
5995 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
5996 return make_scoped_refptr(new NoScaleContentLayer(client));
5997 }
[email protected]94f206c12012-08-25 00:09:145998
[email protected]fb661802013-03-25 01:59:325999 virtual void CalculateContentsScale(float ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066000 float device_scale_factor,
6001 float page_scale_factor,
[email protected]fb661802013-03-25 01:59:326002 bool animating_transform_to_screen,
6003 float* contents_scale_x,
6004 float* contents_scale_y,
6005 gfx::Size* content_bounds) OVERRIDE {
6006 // Skip over the ContentLayer to the base Layer class.
6007 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066008 device_scale_factor,
6009 page_scale_factor,
[email protected]fb661802013-03-25 01:59:326010 animating_transform_to_screen,
6011 contents_scale_x,
6012 contents_scale_y,
6013 content_bounds);
6014 }
[email protected]94f206c12012-08-25 00:09:146015
[email protected]fb661802013-03-25 01:59:326016 protected:
6017 explicit NoScaleContentLayer(ContentLayerClient* client)
6018 : ContentLayer(client) {}
6019 virtual ~NoScaleContentLayer() {}
[email protected]518ee582012-10-24 18:29:446020};
6021
[email protected]fb661802013-03-25 01:59:326022scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
6023 ContentLayerClient* delegate) {
6024 scoped_refptr<NoScaleContentLayer> to_return =
6025 NoScaleContentLayer::Create(delegate);
6026 to_return->SetIsDrawable(true);
6027 return to_return;
[email protected]518ee582012-10-24 18:29:446028}
6029
[email protected]989386c2013-07-18 21:37:236030TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326031 // Verify draw and screen space transforms of layers not in a surface.
6032 MockContentLayerClient delegate;
6033 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:146034
[email protected]fb661802013-03-25 01:59:326035 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6036 SetLayerPropertiesForTesting(parent.get(),
6037 identity_matrix,
[email protected]fb661802013-03-25 01:59:326038 gfx::PointF(),
6039 gfx::PointF(),
6040 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576041 false,
[email protected]fb661802013-03-25 01:59:326042 true);
[email protected]94f206c12012-08-25 00:09:146043
[email protected]fb661802013-03-25 01:59:326044 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6045 SetLayerPropertiesForTesting(child.get(),
6046 identity_matrix,
[email protected]fb661802013-03-25 01:59:326047 gfx::PointF(),
6048 gfx::PointF(2.f, 2.f),
6049 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576050 false,
[email protected]fb661802013-03-25 01:59:326051 true);
[email protected]94f206c12012-08-25 00:09:146052
[email protected]fb661802013-03-25 01:59:326053 scoped_refptr<ContentLayer> child_empty =
6054 CreateDrawableContentLayer(&delegate);
6055 SetLayerPropertiesForTesting(child_empty.get(),
6056 identity_matrix,
[email protected]fb661802013-03-25 01:59:326057 gfx::PointF(),
6058 gfx::PointF(2.f, 2.f),
6059 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576060 false,
[email protected]fb661802013-03-25 01:59:326061 true);
[email protected]f89f5632012-11-14 23:34:456062
[email protected]fb661802013-03-25 01:59:326063 scoped_refptr<NoScaleContentLayer> child_no_scale =
6064 CreateNoScaleDrawableContentLayer(&delegate);
6065 SetLayerPropertiesForTesting(child_no_scale.get(),
6066 identity_matrix,
[email protected]fb661802013-03-25 01:59:326067 gfx::PointF(),
6068 gfx::PointF(2.f, 2.f),
6069 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576070 false,
[email protected]fb661802013-03-25 01:59:326071 true);
[email protected]94f206c12012-08-25 00:09:146072
[email protected]fb661802013-03-25 01:59:326073 parent->AddChild(child);
6074 parent->AddChild(child_empty);
6075 parent->AddChild(child_no_scale);
[email protected]94f206c12012-08-25 00:09:146076
[email protected]d600df7d2013-08-03 02:34:286077 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6078 host->SetRootLayer(parent);
6079
[email protected]fb661802013-03-25 01:59:326080 float device_scale_factor = 2.5f;
6081 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:146082
[email protected]7aad55f2013-07-26 11:25:536083 RenderSurfaceLayerList render_surface_layer_list;
6084 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6085 parent.get(), parent->bounds(), &render_surface_layer_list);
6086 inputs.device_scale_factor = device_scale_factor;
6087 inputs.page_scale_factor = page_scale_factor;
6088 inputs.can_adjust_raster_scales = true;
6089 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446090
[email protected]fb661802013-03-25 01:59:326091 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6092 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6093 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6094 child_empty);
6095 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]94f206c12012-08-25 00:09:146096
[email protected]fb661802013-03-25 01:59:326097 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:146098
[email protected]fb661802013-03-25 01:59:326099 // Verify parent transforms
6100 gfx::Transform expected_parent_transform;
6101 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6102 parent->screen_space_transform());
6103 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6104 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:146105
[email protected]fb661802013-03-25 01:59:326106 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056107 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:146108
[email protected]fb661802013-03-25 01:59:326109 gfx::RectF parent_draw_rect =
6110 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6111 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6112 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:146113
[email protected]2c7c6702013-03-26 03:14:056114 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326115 expected_parent_draw_rect.Scale(device_scale_factor);
6116 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6117 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146118
[email protected]fb661802013-03-25 01:59:326119 // Verify child and child_empty transforms. They should match.
6120 gfx::Transform expected_child_transform;
6121 expected_child_transform.Translate(
6122 device_scale_factor * child->position().x(),
6123 device_scale_factor * child->position().y());
6124 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6125 child->draw_transform());
6126 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6127 child->screen_space_transform());
6128 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6129 child_empty->draw_transform());
6130 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6131 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146132
[email protected]fb661802013-03-25 01:59:326133 // Verify results of transformed child and child_empty rects. They should
6134 // match.
[email protected]2c7c6702013-03-26 03:14:056135 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:146136
[email protected]fb661802013-03-25 01:59:326137 gfx::RectF child_draw_rect =
6138 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6139 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6140 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:146141
[email protected]fb661802013-03-25 01:59:326142 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
6143 child_empty->draw_transform(), child_content_bounds);
6144 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
6145 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:456146
[email protected]fb661802013-03-25 01:59:326147 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
6148 expected_child_draw_rect.Scale(device_scale_factor);
6149 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6150 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
6151 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
6152 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146153
[email protected]fb661802013-03-25 01:59:326154 // Verify child_no_scale transforms
6155 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6156 // All transforms operate on content rects. The child's content rect
6157 // incorporates device scale, but the child_no_scale does not; add it here.
6158 expected_child_no_scale_transform.Scale(device_scale_factor,
6159 device_scale_factor);
6160 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6161 child_no_scale->draw_transform());
6162 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6163 child_no_scale->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146164}
6165
[email protected]989386c2013-07-18 21:37:236166TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326167 // Verify draw and screen space transforms of layers in a surface.
6168 MockContentLayerClient delegate;
6169 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:096170
[email protected]fb661802013-03-25 01:59:326171 gfx::Transform perspective_matrix;
6172 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:096173
[email protected]fb661802013-03-25 01:59:326174 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:056175 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:096176
[email protected]9781afa2013-07-17 23:15:326177 scoped_refptr<Layer> root = Layer::Create();
6178
[email protected]fb661802013-03-25 01:59:326179 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6180 SetLayerPropertiesForTesting(parent.get(),
6181 identity_matrix,
[email protected]fb661802013-03-25 01:59:326182 gfx::PointF(),
6183 gfx::PointF(),
6184 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576185 false,
[email protected]fb661802013-03-25 01:59:326186 true);
[email protected]1b30e8e2012-12-21 02:59:096187
[email protected]fb661802013-03-25 01:59:326188 scoped_refptr<ContentLayer> perspective_surface =
6189 CreateDrawableContentLayer(&delegate);
6190 SetLayerPropertiesForTesting(perspective_surface.get(),
6191 perspective_matrix * scale_small_matrix,
[email protected]fb661802013-03-25 01:59:326192 gfx::PointF(),
6193 gfx::PointF(2.f, 2.f),
6194 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576195 false,
[email protected]fb661802013-03-25 01:59:326196 true);
[email protected]1b30e8e2012-12-21 02:59:096197
[email protected]fb661802013-03-25 01:59:326198 scoped_refptr<ContentLayer> scale_surface =
6199 CreateDrawableContentLayer(&delegate);
6200 SetLayerPropertiesForTesting(scale_surface.get(),
6201 scale_small_matrix,
[email protected]fb661802013-03-25 01:59:326202 gfx::PointF(),
6203 gfx::PointF(2.f, 2.f),
6204 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576205 false,
[email protected]fb661802013-03-25 01:59:326206 true);
[email protected]1b30e8e2012-12-21 02:59:096207
[email protected]fb661802013-03-25 01:59:326208 perspective_surface->SetForceRenderSurface(true);
6209 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:096210
[email protected]fb661802013-03-25 01:59:326211 parent->AddChild(perspective_surface);
6212 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:326213 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:096214
[email protected]d600df7d2013-08-03 02:34:286215 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6216 host->SetRootLayer(root);
6217
[email protected]fb661802013-03-25 01:59:326218 float device_scale_factor = 2.5f;
6219 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:096220
[email protected]7aad55f2013-07-26 11:25:536221 RenderSurfaceLayerList render_surface_layer_list;
6222 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6223 root.get(), parent->bounds(), &render_surface_layer_list);
6224 inputs.device_scale_factor = device_scale_factor;
6225 inputs.page_scale_factor = page_scale_factor;
6226 inputs.page_scale_application_layer = root;
6227 inputs.can_adjust_raster_scales = true;
6228 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:096229
[email protected]fb661802013-03-25 01:59:326230 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6231 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6232 perspective_surface);
6233 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6234 scale_surface);
[email protected]1b30e8e2012-12-21 02:59:096235
[email protected]fb661802013-03-25 01:59:326236 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:096237
[email protected]fb661802013-03-25 01:59:326238 gfx::Transform expected_parent_draw_transform;
6239 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
6240 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096241
[email protected]fb661802013-03-25 01:59:326242 // The scaled surface is rendered at its appropriate scale, and drawn 1:1
6243 // into its target.
6244 gfx::Transform expected_scale_surface_draw_transform;
6245 expected_scale_surface_draw_transform.Translate(
6246 device_scale_factor * page_scale_factor * scale_surface->position().x(),
6247 device_scale_factor * page_scale_factor * scale_surface->position().y());
[email protected]fb661802013-03-25 01:59:326248 EXPECT_TRANSFORMATION_MATRIX_EQ(
6249 expected_scale_surface_draw_transform,
6250 scale_surface->render_surface()->draw_transform());
[email protected]a52c6ff2013-05-04 05:33:156251 gfx::Transform expected_scale_surface_layer_draw_transform =
6252 scale_small_matrix;
[email protected]fb661802013-03-25 01:59:326253 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform,
6254 scale_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096255
[email protected]fb661802013-03-25 01:59:326256 // The scale for the perspective surface is not known, so it is rendered 1:1
6257 // with the screen, and then scaled during drawing.
6258 gfx::Transform expected_perspective_surface_draw_transform;
6259 expected_perspective_surface_draw_transform.Translate(
6260 device_scale_factor * page_scale_factor *
6261 perspective_surface->position().x(),
6262 device_scale_factor * page_scale_factor *
6263 perspective_surface->position().y());
6264 expected_perspective_surface_draw_transform.PreconcatTransform(
6265 perspective_matrix);
6266 expected_perspective_surface_draw_transform.PreconcatTransform(
6267 scale_small_matrix);
6268 gfx::Transform expected_perspective_surface_layer_draw_transform;
6269 EXPECT_TRANSFORMATION_MATRIX_EQ(
6270 expected_perspective_surface_draw_transform,
6271 perspective_surface->render_surface()->draw_transform());
6272 EXPECT_TRANSFORMATION_MATRIX_EQ(
6273 expected_perspective_surface_layer_draw_transform,
6274 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096275}
6276
[email protected]989386c2013-07-18 21:37:236277TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:326278 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
6279 // Verify draw and screen space transforms of layers not in a surface.
6280 MockContentLayerClient delegate;
6281 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:476282
[email protected]fb661802013-03-25 01:59:326283 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6284 SetLayerPropertiesForTesting(parent.get(),
6285 identity_matrix,
[email protected]fb661802013-03-25 01:59:326286 gfx::PointF(),
6287 gfx::PointF(),
6288 gfx::Size(133, 133),
[email protected]56fffdd2014-02-11 19:50:576289 false,
[email protected]fb661802013-03-25 01:59:326290 true);
[email protected]904e9132012-11-01 00:12:476291
[email protected]fb661802013-03-25 01:59:326292 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6293 SetLayerPropertiesForTesting(child.get(),
6294 identity_matrix,
[email protected]fb661802013-03-25 01:59:326295 gfx::PointF(),
6296 gfx::PointF(),
6297 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:576298 false,
[email protected]fb661802013-03-25 01:59:326299 true);
[email protected]904e9132012-11-01 00:12:476300
[email protected]fb661802013-03-25 01:59:326301 scoped_refptr<NoScaleContentLayer> child_no_scale =
6302 CreateNoScaleDrawableContentLayer(&delegate);
6303 SetLayerPropertiesForTesting(child_no_scale.get(),
6304 identity_matrix,
[email protected]fb661802013-03-25 01:59:326305 gfx::PointF(),
6306 gfx::PointF(),
6307 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:576308 false,
[email protected]fb661802013-03-25 01:59:326309 true);
[email protected]904e9132012-11-01 00:12:476310
[email protected]fb661802013-03-25 01:59:326311 parent->AddChild(child);
6312 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:476313
[email protected]d600df7d2013-08-03 02:34:286314 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6315 host->SetRootLayer(parent);
6316
[email protected]fb661802013-03-25 01:59:326317 float device_scale_factor = 1.7f;
6318 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:476319
[email protected]7aad55f2013-07-26 11:25:536320 RenderSurfaceLayerList render_surface_layer_list;
6321 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6322 parent.get(), parent->bounds(), &render_surface_layer_list);
6323 inputs.device_scale_factor = device_scale_factor;
6324 inputs.page_scale_factor = page_scale_factor;
6325 inputs.page_scale_application_layer = parent.get();
6326 inputs.can_adjust_raster_scales = true;
6327 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:476328
[email protected]fb661802013-03-25 01:59:326329 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6330 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6331 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:476332
[email protected]fb661802013-03-25 01:59:326333 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:476334
[email protected]fb661802013-03-25 01:59:326335 // Verify parent transforms
6336 gfx::Transform expected_parent_transform;
6337 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6338 parent->screen_space_transform());
6339 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6340 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:476341
[email protected]fb661802013-03-25 01:59:326342 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056343 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:476344
[email protected]fb661802013-03-25 01:59:326345 gfx::RectF parent_draw_rect =
6346 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6347 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6348 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:476349
[email protected]2c7c6702013-03-26 03:14:056350 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326351 expected_parent_draw_rect.Scale(device_scale_factor);
6352 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
6353 expected_parent_draw_rect.set_height(
6354 ceil(expected_parent_draw_rect.height()));
6355 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6356 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476357
[email protected]fb661802013-03-25 01:59:326358 // Verify child transforms
6359 gfx::Transform expected_child_transform;
6360 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6361 child->draw_transform());
6362 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6363 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476364
[email protected]fb661802013-03-25 01:59:326365 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:056366 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:476367
[email protected]fb661802013-03-25 01:59:326368 gfx::RectF child_draw_rect =
6369 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6370 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6371 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:476372
[email protected]2c7c6702013-03-26 03:14:056373 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:326374 expected_child_draw_rect.Scale(device_scale_factor);
6375 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
6376 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
6377 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6378 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476379
[email protected]fb661802013-03-25 01:59:326380 // Verify child_no_scale transforms
6381 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6382 // All transforms operate on content rects. The child's content rect
6383 // incorporates device scale, but the child_no_scale does not; add it here.
6384 expected_child_no_scale_transform.Scale(device_scale_factor,
6385 device_scale_factor);
6386 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6387 child_no_scale->draw_transform());
6388 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6389 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476390}
6391
[email protected]989386c2013-07-18 21:37:236392TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:326393 MockContentLayerClient delegate;
6394 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446395
[email protected]fb661802013-03-25 01:59:326396 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266397 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326398 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446399
[email protected]fb661802013-03-25 01:59:326400 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266401 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326402 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446403
[email protected]35a99a12013-05-09 23:52:296404 scoped_refptr<Layer> root = Layer::Create();
6405 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446406
[email protected]fb661802013-03-25 01:59:326407 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6408 SetLayerPropertiesForTesting(parent.get(),
6409 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326410 gfx::PointF(),
6411 gfx::PointF(),
6412 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576413 false,
[email protected]fb661802013-03-25 01:59:326414 true);
[email protected]518ee582012-10-24 18:29:446415
[email protected]fb661802013-03-25 01:59:326416 scoped_refptr<ContentLayer> child_scale =
6417 CreateDrawableContentLayer(&delegate);
6418 SetLayerPropertiesForTesting(child_scale.get(),
6419 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326420 gfx::PointF(),
6421 gfx::PointF(2.f, 2.f),
6422 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576423 false,
[email protected]fb661802013-03-25 01:59:326424 true);
[email protected]518ee582012-10-24 18:29:446425
[email protected]fb661802013-03-25 01:59:326426 scoped_refptr<ContentLayer> child_empty =
6427 CreateDrawableContentLayer(&delegate);
6428 SetLayerPropertiesForTesting(child_empty.get(),
6429 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326430 gfx::PointF(),
6431 gfx::PointF(2.f, 2.f),
6432 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576433 false,
[email protected]fb661802013-03-25 01:59:326434 true);
[email protected]f89f5632012-11-14 23:34:456435
[email protected]fb661802013-03-25 01:59:326436 scoped_refptr<NoScaleContentLayer> child_no_scale =
6437 CreateNoScaleDrawableContentLayer(&delegate);
6438 SetLayerPropertiesForTesting(child_no_scale.get(),
6439 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326440 gfx::PointF(),
6441 gfx::PointF(12.f, 12.f),
6442 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576443 false,
[email protected]fb661802013-03-25 01:59:326444 true);
[email protected]518ee582012-10-24 18:29:446445
[email protected]35a99a12013-05-09 23:52:296446 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446447
[email protected]fb661802013-03-25 01:59:326448 parent->AddChild(child_scale);
6449 parent->AddChild(child_empty);
6450 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:446451
[email protected]d600df7d2013-08-03 02:34:286452 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6453 host->SetRootLayer(root);
6454
[email protected]fb661802013-03-25 01:59:326455 float device_scale_factor = 2.5f;
6456 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:446457
[email protected]989386c2013-07-18 21:37:236458 {
6459 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536460 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6461 root.get(), root->bounds(), &render_surface_layer_list);
6462 inputs.device_scale_factor = device_scale_factor;
6463 inputs.page_scale_factor = page_scale_factor;
6464 inputs.page_scale_application_layer = root.get();
6465 inputs.can_adjust_raster_scales = true;
6466 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446467
[email protected]989386c2013-07-18 21:37:236468 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6469 initial_parent_scale, parent);
6470 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6471 initial_parent_scale * initial_child_scale,
6472 child_scale);
6473 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6474 initial_parent_scale * initial_child_scale,
6475 child_empty);
6476 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:446477
[email protected]989386c2013-07-18 21:37:236478 // The parent is scaled up and shouldn't need to scale during draw. The
6479 // child that can scale its contents should also not need to scale during
6480 // draw. This shouldn't change if the child has empty bounds. The other
6481 // children should.
[email protected]803f6b52013-09-12 00:51:266482 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
6483 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
6484 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
6485 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
6486 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
6487 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236488 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6489 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266490 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:236491 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266492 initial_parent_scale * initial_child_scale,
6493 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236494 }
[email protected]518ee582012-10-24 18:29:446495
[email protected]fb661802013-03-25 01:59:326496 // If the device_scale_factor or page_scale_factor changes, then it should be
6497 // updated using the initial transform as the raster scale.
6498 device_scale_factor = 2.25f;
6499 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:446500
[email protected]989386c2013-07-18 21:37:236501 {
6502 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536503 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6504 root.get(), root->bounds(), &render_surface_layer_list);
6505 inputs.device_scale_factor = device_scale_factor;
6506 inputs.page_scale_factor = page_scale_factor;
6507 inputs.page_scale_application_layer = root.get();
6508 inputs.can_adjust_raster_scales = true;
6509 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6510
6511 EXPECT_CONTENTS_SCALE_EQ(
6512 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:236513 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536514 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:236515 child_scale);
6516 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6517 initial_parent_scale * initial_child_scale,
6518 child_empty);
6519 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6520 }
[email protected]d0518202013-02-08 02:06:496521
[email protected]fb661802013-03-25 01:59:326522 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:266523 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326524 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
6525 second_child_scale / initial_child_scale);
6526 child_scale->SetTransform(child_scale_matrix);
6527 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:496528
[email protected]989386c2013-07-18 21:37:236529 {
6530 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536531 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6532 root.get(), root->bounds(), &render_surface_layer_list);
6533 inputs.device_scale_factor = device_scale_factor;
6534 inputs.page_scale_factor = page_scale_factor;
6535 inputs.page_scale_application_layer = root.get();
6536 inputs.can_adjust_raster_scales = true;
6537 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496538
[email protected]989386c2013-07-18 21:37:236539 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6540 initial_parent_scale,
6541 parent);
6542 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6543 child_scale);
6544 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6545 child_empty);
6546 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6547 }
[email protected]d0518202013-02-08 02:06:496548
[email protected]fb661802013-03-25 01:59:326549 // If the device_scale_factor or page_scale_factor changes, then it should be
6550 // updated, but still using 1.0 as the raster scale.
6551 device_scale_factor = 2.75f;
6552 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:496553
[email protected]989386c2013-07-18 21:37:236554 {
6555 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536556 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6557 root.get(), root->bounds(), &render_surface_layer_list);
6558 inputs.device_scale_factor = device_scale_factor;
6559 inputs.page_scale_factor = page_scale_factor;
6560 inputs.page_scale_application_layer = root.get();
6561 inputs.can_adjust_raster_scales = true;
6562 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496563
[email protected]989386c2013-07-18 21:37:236564 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6565 initial_parent_scale,
6566 parent);
6567 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6568 child_scale);
6569 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6570 child_empty);
6571 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6572 }
[email protected]518ee582012-10-24 18:29:446573}
6574
[email protected]989386c2013-07-18 21:37:236575TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:296576 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:326577 MockContentLayerClient delegate;
6578 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:216579
[email protected]fb661802013-03-25 01:59:326580 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266581 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326582 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:216583
[email protected]fb661802013-03-25 01:59:326584 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266585 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326586 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:216587
[email protected]35a99a12013-05-09 23:52:296588 scoped_refptr<Layer> root = Layer::Create();
6589 root->SetBounds(gfx::Size(100, 100));
6590
[email protected]fb661802013-03-25 01:59:326591 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6592 SetLayerPropertiesForTesting(parent.get(),
6593 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326594 gfx::PointF(),
6595 gfx::PointF(),
6596 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576597 false,
[email protected]fb661802013-03-25 01:59:326598 true);
[email protected]11ec92972012-11-10 03:06:216599
[email protected]fb661802013-03-25 01:59:326600 scoped_refptr<ContentLayer> child_scale =
6601 CreateDrawableContentLayer(&delegate);
6602 SetLayerPropertiesForTesting(child_scale.get(),
6603 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326604 gfx::PointF(),
6605 gfx::PointF(2.f, 2.f),
6606 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576607 false,
[email protected]fb661802013-03-25 01:59:326608 true);
[email protected]11ec92972012-11-10 03:06:216609
[email protected]35a99a12013-05-09 23:52:296610 scoped_refptr<ContentLayer> child_empty =
6611 CreateDrawableContentLayer(&delegate);
6612 SetLayerPropertiesForTesting(child_empty.get(),
6613 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296614 gfx::PointF(),
6615 gfx::PointF(2.f, 2.f),
6616 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576617 false,
[email protected]35a99a12013-05-09 23:52:296618 true);
6619
6620 scoped_refptr<NoScaleContentLayer> child_no_scale =
6621 CreateNoScaleDrawableContentLayer(&delegate);
6622 SetLayerPropertiesForTesting(child_no_scale.get(),
6623 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296624 gfx::PointF(),
6625 gfx::PointF(12.f, 12.f),
6626 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576627 false,
[email protected]35a99a12013-05-09 23:52:296628 true);
6629
6630 root->AddChild(parent);
6631
6632 parent->AddChild(child_scale);
6633 parent->AddChild(child_empty);
6634 parent->AddChild(child_no_scale);
6635
[email protected]d600df7d2013-08-03 02:34:286636 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6637 host->SetRootLayer(root);
6638
[email protected]989386c2013-07-18 21:37:236639 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:296640
6641 float device_scale_factor = 2.5f;
6642 float page_scale_factor = 1.f;
6643
[email protected]7aad55f2013-07-26 11:25:536644 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6645 root.get(), root->bounds(), &render_surface_layer_list);
6646 inputs.device_scale_factor = device_scale_factor;
6647 inputs.page_scale_factor = page_scale_factor;
6648 inputs.page_scale_application_layer = root.get(),
6649 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:296650
6651 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6652 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6653 child_scale);
6654 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6655 child_empty);
6656 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6657
6658 // Since the transform scale does not affect contents scale, it should affect
6659 // the draw transform instead.
6660 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266661 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296662 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266663 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296664 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266665 child_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296666 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266667 child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296668 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266669 child_empty->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296670 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266671 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296672 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266673 initial_parent_scale * initial_child_scale,
6674 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296675 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266676 initial_parent_scale * initial_child_scale,
6677 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296678}
6679
[email protected]989386c2013-07-18 21:37:236680TEST_F(LayerTreeHostCommonTest, SmallContentsScale) {
[email protected]35a99a12013-05-09 23:52:296681 MockContentLayerClient delegate;
6682 gfx::Transform identity_matrix;
6683
6684 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266685 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:296686 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6687
6688 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266689 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:296690 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6691
6692 scoped_refptr<Layer> root = Layer::Create();
6693 root->SetBounds(gfx::Size(100, 100));
6694
6695 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6696 SetLayerPropertiesForTesting(parent.get(),
6697 parent_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296698 gfx::PointF(),
6699 gfx::PointF(),
6700 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576701 false,
[email protected]35a99a12013-05-09 23:52:296702 true);
6703
6704 scoped_refptr<ContentLayer> child_scale =
6705 CreateDrawableContentLayer(&delegate);
6706 SetLayerPropertiesForTesting(child_scale.get(),
6707 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296708 gfx::PointF(),
6709 gfx::PointF(2.f, 2.f),
6710 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576711 false,
[email protected]35a99a12013-05-09 23:52:296712 true);
6713
6714 root->AddChild(parent);
6715
[email protected]fb661802013-03-25 01:59:326716 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:216717
[email protected]d600df7d2013-08-03 02:34:286718 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6719 host->SetRootLayer(root);
6720
[email protected]fb661802013-03-25 01:59:326721 float device_scale_factor = 2.5f;
6722 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:216723
[email protected]989386c2013-07-18 21:37:236724 {
6725 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536726 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6727 root.get(), root->bounds(), &render_surface_layer_list);
6728 inputs.device_scale_factor = device_scale_factor;
6729 inputs.page_scale_factor = page_scale_factor;
6730 inputs.page_scale_application_layer = root.get();
6731 inputs.can_adjust_raster_scales = true;
6732 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216733
[email protected]989386c2013-07-18 21:37:236734 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6735 initial_parent_scale,
6736 parent);
6737 // The child's scale is < 1, so we should not save and use that scale
6738 // factor.
6739 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1,
6740 child_scale);
6741 }
[email protected]11ec92972012-11-10 03:06:216742
[email protected]fb661802013-03-25 01:59:326743 // When chilld's total scale becomes >= 1, we should save and use that scale
6744 // factor.
6745 child_scale_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:266746 SkMScalar final_child_scale = 0.75;
[email protected]fb661802013-03-25 01:59:326747 child_scale_matrix.Scale(final_child_scale, final_child_scale);
6748 child_scale->SetTransform(child_scale_matrix);
[email protected]11ec92972012-11-10 03:06:216749
[email protected]989386c2013-07-18 21:37:236750 {
6751 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536752 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6753 root.get(), root->bounds(), &render_surface_layer_list);
6754 inputs.device_scale_factor = device_scale_factor;
6755 inputs.page_scale_factor = page_scale_factor;
6756 inputs.page_scale_application_layer = root.get();
6757 inputs.can_adjust_raster_scales = true;
6758 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216759
[email protected]989386c2013-07-18 21:37:236760 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6761 initial_parent_scale,
6762 parent);
6763 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6764 initial_parent_scale * final_child_scale,
6765 child_scale);
6766 }
[email protected]11ec92972012-11-10 03:06:216767}
6768
[email protected]989386c2013-07-18 21:37:236769TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:326770 MockContentLayerClient delegate;
6771 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446772
[email protected]fb661802013-03-25 01:59:326773 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266774 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:326775 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446776
[email protected]fb661802013-03-25 01:59:326777 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266778 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:326779 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446780
[email protected]35a99a12013-05-09 23:52:296781 scoped_refptr<Layer> root = Layer::Create();
6782 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446783
[email protected]fb661802013-03-25 01:59:326784 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6785 SetLayerPropertiesForTesting(parent.get(),
6786 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:326787 gfx::PointF(),
6788 gfx::PointF(),
6789 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576790 false,
[email protected]fb661802013-03-25 01:59:326791 true);
[email protected]518ee582012-10-24 18:29:446792
[email protected]fb661802013-03-25 01:59:326793 scoped_refptr<ContentLayer> surface_scale =
6794 CreateDrawableContentLayer(&delegate);
6795 SetLayerPropertiesForTesting(surface_scale.get(),
6796 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326797 gfx::PointF(),
6798 gfx::PointF(2.f, 2.f),
6799 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576800 false,
[email protected]fb661802013-03-25 01:59:326801 true);
[email protected]518ee582012-10-24 18:29:446802
[email protected]fb661802013-03-25 01:59:326803 scoped_refptr<ContentLayer> surface_scale_child_scale =
6804 CreateDrawableContentLayer(&delegate);
6805 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
6806 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326807 gfx::PointF(),
6808 gfx::PointF(),
6809 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576810 false,
[email protected]fb661802013-03-25 01:59:326811 true);
[email protected]518ee582012-10-24 18:29:446812
[email protected]fb661802013-03-25 01:59:326813 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
6814 CreateNoScaleDrawableContentLayer(&delegate);
6815 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
6816 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326817 gfx::PointF(),
6818 gfx::PointF(),
6819 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576820 false,
[email protected]fb661802013-03-25 01:59:326821 true);
[email protected]518ee582012-10-24 18:29:446822
[email protected]fb661802013-03-25 01:59:326823 scoped_refptr<NoScaleContentLayer> surface_no_scale =
6824 CreateNoScaleDrawableContentLayer(&delegate);
6825 SetLayerPropertiesForTesting(surface_no_scale.get(),
6826 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326827 gfx::PointF(),
6828 gfx::PointF(12.f, 12.f),
6829 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576830 false,
[email protected]fb661802013-03-25 01:59:326831 true);
[email protected]518ee582012-10-24 18:29:446832
[email protected]fb661802013-03-25 01:59:326833 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
6834 CreateDrawableContentLayer(&delegate);
6835 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
6836 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326837 gfx::PointF(),
6838 gfx::PointF(),
6839 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576840 false,
[email protected]fb661802013-03-25 01:59:326841 true);
[email protected]518ee582012-10-24 18:29:446842
[email protected]fb661802013-03-25 01:59:326843 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
6844 CreateNoScaleDrawableContentLayer(&delegate);
6845 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
6846 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:326847 gfx::PointF(),
6848 gfx::PointF(),
6849 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576850 false,
[email protected]fb661802013-03-25 01:59:326851 true);
[email protected]518ee582012-10-24 18:29:446852
[email protected]35a99a12013-05-09 23:52:296853 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446854
[email protected]fb661802013-03-25 01:59:326855 parent->AddChild(surface_scale);
6856 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:446857
[email protected]fb661802013-03-25 01:59:326858 surface_scale->SetForceRenderSurface(true);
6859 surface_scale->AddChild(surface_scale_child_scale);
6860 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446861
[email protected]fb661802013-03-25 01:59:326862 surface_no_scale->SetForceRenderSurface(true);
6863 surface_no_scale->AddChild(surface_no_scale_child_scale);
6864 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446865
[email protected]d600df7d2013-08-03 02:34:286866 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6867 host->SetRootLayer(root);
6868
[email protected]803f6b52013-09-12 00:51:266869 SkMScalar device_scale_factor = 5;
6870 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:446871
[email protected]7aad55f2013-07-26 11:25:536872 RenderSurfaceLayerList render_surface_layer_list;
6873 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6874 root.get(), root->bounds(), &render_surface_layer_list);
6875 inputs.device_scale_factor = device_scale_factor;
6876 inputs.page_scale_factor = page_scale_factor;
6877 inputs.page_scale_application_layer = root.get();
6878 inputs.can_adjust_raster_scales = true;
6879 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6880
6881 EXPECT_CONTENTS_SCALE_EQ(
6882 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:196883 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536884 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:326885 surface_scale);
6886 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
6887 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:326888 device_scale_factor * page_scale_factor * initial_parent_scale *
6889 initial_child_scale * initial_child_scale,
6890 surface_scale_child_scale);
6891 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
6892 EXPECT_CONTENTS_SCALE_EQ(
6893 device_scale_factor * page_scale_factor * initial_parent_scale *
6894 initial_child_scale * initial_child_scale,
6895 surface_no_scale_child_scale);
6896 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446897
[email protected]fb661802013-03-25 01:59:326898 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:266899 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
6900 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446901
[email protected]fb661802013-03-25 01:59:326902 // RenderSurfaces should always be 1:1 with their target.
6903 EXPECT_FLOAT_EQ(
6904 1.0,
[email protected]803f6b52013-09-12 00:51:266905 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326906 EXPECT_FLOAT_EQ(
6907 1.0,
[email protected]803f6b52013-09-12 00:51:266908 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446909
[email protected]fb661802013-03-25 01:59:326910 // The surface_scale can apply contents scale so the layer shouldn't need to
6911 // scale during draw.
[email protected]803f6b52013-09-12 00:51:266912 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
6913 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446914
[email protected]fb661802013-03-25 01:59:326915 // The surface_scale_child_scale can apply contents scale so it shouldn't need
6916 // to scale during draw.
6917 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:266918 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326919 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:266920 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446921
[email protected]fb661802013-03-25 01:59:326922 // The surface_scale_child_no_scale can not apply contents scale, so it needs
6923 // to be scaled during draw.
6924 EXPECT_FLOAT_EQ(
6925 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:266926 initial_child_scale * initial_child_scale,
6927 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326928 EXPECT_FLOAT_EQ(
6929 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:266930 initial_child_scale * initial_child_scale,
6931 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446932
[email protected]fb661802013-03-25 01:59:326933 // RenderSurfaces should always be 1:1 with their target.
6934 EXPECT_FLOAT_EQ(
6935 1.0,
[email protected]803f6b52013-09-12 00:51:266936 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326937 EXPECT_FLOAT_EQ(
6938 1.0,
[email protected]803f6b52013-09-12 00:51:266939 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446940
[email protected]fb661802013-03-25 01:59:326941 // The surface_no_scale layer can not apply contents scale, so it needs to be
6942 // scaled during draw.
6943 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266944 initial_parent_scale * initial_child_scale,
6945 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326946 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266947 initial_parent_scale * initial_child_scale,
6948 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446949
[email protected]fb661802013-03-25 01:59:326950 // The surface_scale_child_scale can apply contents scale so it shouldn't need
6951 // to scale during draw.
6952 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:266953 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326954 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:266955 1.0, surface_no_scale_child_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_no_scale can not apply contents scale, so it needs
6958 // to be scaled during draw.
6959 EXPECT_FLOAT_EQ(
6960 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:266961 initial_child_scale * initial_child_scale,
6962 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326963 EXPECT_FLOAT_EQ(
6964 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:266965 initial_child_scale * initial_child_scale,
6966 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296967}
[email protected]518ee582012-10-24 18:29:446968
[email protected]989386c2013-07-18 21:37:236969TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:296970 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
6971 MockContentLayerClient delegate;
6972 gfx::Transform identity_matrix;
6973
6974 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266975 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:296976 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6977
6978 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266979 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:296980 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6981
6982 scoped_refptr<Layer> root = Layer::Create();
6983 root->SetBounds(gfx::Size(100, 100));
6984
6985 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6986 SetLayerPropertiesForTesting(parent.get(),
6987 parent_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296988 gfx::PointF(),
6989 gfx::PointF(),
6990 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:576991 false,
[email protected]35a99a12013-05-09 23:52:296992 true);
6993
6994 scoped_refptr<ContentLayer> surface_scale =
6995 CreateDrawableContentLayer(&delegate);
6996 SetLayerPropertiesForTesting(surface_scale.get(),
6997 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:296998 gfx::PointF(),
6999 gfx::PointF(2.f, 2.f),
7000 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577001 false,
[email protected]35a99a12013-05-09 23:52:297002 true);
7003
7004 scoped_refptr<ContentLayer> surface_scale_child_scale =
7005 CreateDrawableContentLayer(&delegate);
7006 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
7007 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297008 gfx::PointF(),
7009 gfx::PointF(),
7010 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577011 false,
[email protected]35a99a12013-05-09 23:52:297012 true);
7013
7014 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
7015 CreateNoScaleDrawableContentLayer(&delegate);
7016 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
7017 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297018 gfx::PointF(),
7019 gfx::PointF(),
7020 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577021 false,
[email protected]35a99a12013-05-09 23:52:297022 true);
7023
7024 scoped_refptr<NoScaleContentLayer> surface_no_scale =
7025 CreateNoScaleDrawableContentLayer(&delegate);
7026 SetLayerPropertiesForTesting(surface_no_scale.get(),
7027 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297028 gfx::PointF(),
7029 gfx::PointF(12.f, 12.f),
7030 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577031 false,
[email protected]35a99a12013-05-09 23:52:297032 true);
7033
7034 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
7035 CreateDrawableContentLayer(&delegate);
7036 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
7037 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297038 gfx::PointF(),
7039 gfx::PointF(),
7040 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577041 false,
[email protected]35a99a12013-05-09 23:52:297042 true);
7043
7044 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
7045 CreateNoScaleDrawableContentLayer(&delegate);
7046 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
7047 child_scale_matrix,
[email protected]35a99a12013-05-09 23:52:297048 gfx::PointF(),
7049 gfx::PointF(),
7050 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577051 false,
[email protected]35a99a12013-05-09 23:52:297052 true);
7053
7054 root->AddChild(parent);
7055
7056 parent->AddChild(surface_scale);
7057 parent->AddChild(surface_no_scale);
7058
7059 surface_scale->SetForceRenderSurface(true);
7060 surface_scale->AddChild(surface_scale_child_scale);
7061 surface_scale->AddChild(surface_scale_child_no_scale);
7062
7063 surface_no_scale->SetForceRenderSurface(true);
7064 surface_no_scale->AddChild(surface_no_scale_child_scale);
7065 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
7066
[email protected]d600df7d2013-08-03 02:34:287067 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7068 host->SetRootLayer(root);
7069
[email protected]989386c2013-07-18 21:37:237070 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:297071
[email protected]803f6b52013-09-12 00:51:267072 SkMScalar device_scale_factor = 5.0;
7073 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:537074 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7075 root.get(), root->bounds(), &render_surface_layer_list);
7076 inputs.device_scale_factor = device_scale_factor;
7077 inputs.page_scale_factor = page_scale_factor;
7078 inputs.page_scale_application_layer = root.get();
7079 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:297080
[email protected]35a99a12013-05-09 23:52:297081 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7082 parent);
7083 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7084 surface_scale);
7085 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
7086 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7087 surface_scale_child_scale);
7088 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
7089 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7090 surface_no_scale_child_scale);
7091 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
7092
7093 // The parent is scaled up during draw, since its contents are not scaled by
7094 // the transform hierarchy.
7095 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267096 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297097 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267098 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297099
7100 // The child surface is scaled up during draw since its subtree is not scaled
7101 // by the transform hierarchy.
7102 EXPECT_FLOAT_EQ(
7103 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267104 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297105 EXPECT_FLOAT_EQ(
7106 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267107 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297108
7109 // The surface_scale's RenderSurface is scaled during draw, so the layer does
7110 // not need to be scaled when drawing into its surface.
[email protected]803f6b52013-09-12 00:51:267111 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
7112 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447113
[email protected]35a99a12013-05-09 23:52:297114 // The surface_scale_child_scale is scaled when drawing into its surface,
7115 // since its content bounds are not scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:327116 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297117 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267118 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327119 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297120 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267121 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447122
[email protected]35a99a12013-05-09 23:52:297123 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
7124 // needs to be scaled by the device and page scale factors, along with the
7125 // transform hierarchy.
[email protected]fb661802013-03-25 01:59:327126 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297127 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267128 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297129 EXPECT_FLOAT_EQ(
7130 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267131 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297132
7133 // The child surface is scaled up during draw since its subtree is not scaled
7134 // by the transform hierarchy.
7135 EXPECT_FLOAT_EQ(
7136 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267137 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327138 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297139 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267140 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447141
[email protected]35a99a12013-05-09 23:52:297142 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
7143 // be scaled by the device and page scale factors. Its surface is already
7144 // scaled by the transform hierarchy so those don't need to scale the layer's
7145 // drawing.
7146 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267147 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297148 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267149 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297150
7151 // The surface_no_scale_child_scale has its contents scaled by the page and
7152 // device scale factors, but needs to be scaled by the transform hierarchy
7153 // when drawing.
[email protected]fb661802013-03-25 01:59:327154 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297155 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267156 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327157 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297158 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267159 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297160
7161 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
7162 // needs to be scaled by the device and page scale factors. It also needs to
7163 // be scaled by any transform heirarchy below its target surface.
7164 EXPECT_FLOAT_EQ(
7165 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267166 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297167 EXPECT_FLOAT_EQ(
7168 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267169 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447170}
7171
[email protected]989386c2013-07-18 21:37:237172TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:327173 MockContentLayerClient delegate;
7174 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267175
[email protected]fb661802013-03-25 01:59:327176 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267177 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:327178 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:267179
[email protected]fb661802013-03-25 01:59:327180 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267181 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:327182 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:267183
[email protected]35a99a12013-05-09 23:52:297184 scoped_refptr<Layer> root = Layer::Create();
7185 root->SetBounds(gfx::Size(100, 100));
7186
[email protected]fb661802013-03-25 01:59:327187 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7188 SetLayerPropertiesForTesting(parent.get(),
7189 parent_scale_matrix,
[email protected]fb661802013-03-25 01:59:327190 gfx::PointF(),
7191 gfx::PointF(),
7192 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577193 false,
[email protected]fb661802013-03-25 01:59:327194 true);
[email protected]6a9cff92012-11-08 11:53:267195
[email protected]fb661802013-03-25 01:59:327196 scoped_refptr<ContentLayer> child_scale =
7197 CreateDrawableContentLayer(&delegate);
7198 SetLayerPropertiesForTesting(child_scale.get(),
7199 child_scale_matrix,
[email protected]fb661802013-03-25 01:59:327200 gfx::PointF(),
7201 gfx::PointF(2.f, 2.f),
7202 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577203 false,
[email protected]fb661802013-03-25 01:59:327204 true);
[email protected]6a9cff92012-11-08 11:53:267205
[email protected]35a99a12013-05-09 23:52:297206 root->AddChild(parent);
7207
[email protected]fb661802013-03-25 01:59:327208 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:267209
[email protected]d600df7d2013-08-03 02:34:287210 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7211 host->SetRootLayer(root);
7212
[email protected]fb661802013-03-25 01:59:327213 // Now put an animating transform on child.
7214 int animation_id = AddAnimatedTransformToController(
7215 child_scale->layer_animation_controller(), 10.0, 30, 0);
[email protected]6a9cff92012-11-08 11:53:267216
[email protected]989386c2013-07-18 21:37:237217 {
7218 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537219 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7220 root.get(), root->bounds(), &render_surface_layer_list);
7221 inputs.can_adjust_raster_scales = true;
7222 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267223
[email protected]989386c2013-07-18 21:37:237224 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7225 // The layers with animating transforms should not compute a contents scale
7226 // other than 1 until they finish animating.
7227 EXPECT_CONTENTS_SCALE_EQ(1, child_scale);
7228 }
[email protected]6a9cff92012-11-08 11:53:267229
[email protected]fb661802013-03-25 01:59:327230 // Remove the animation, now it can save a raster scale.
7231 child_scale->layer_animation_controller()->RemoveAnimation(animation_id);
[email protected]6a9cff92012-11-08 11:53:267232
[email protected]989386c2013-07-18 21:37:237233 {
7234 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537235 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7236 root.get(), root->bounds(), &render_surface_layer_list);
7237 inputs.can_adjust_raster_scales = true;
7238 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267239
[email protected]989386c2013-07-18 21:37:237240 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7241 // The layers with animating transforms should not compute a contents scale
7242 // other than 1 until they finish animating.
7243 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale,
7244 child_scale);
7245 }
[email protected]6a9cff92012-11-08 11:53:267246}
7247
[email protected]7a5a9322014-02-25 12:54:577248TEST_F(LayerTreeHostCommonTest,
7249 ChangeInContentBoundsOrScaleTriggersPushProperties) {
7250 MockContentLayerClient delegate;
7251 scoped_refptr<Layer> root = Layer::Create();
7252 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate);
7253 root->AddChild(child);
7254
7255 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7256 host->SetRootLayer(root);
7257
7258 gfx::Transform identity_matrix;
7259 SetLayerPropertiesForTesting(root.get(),
7260 identity_matrix,
7261 gfx::PointF(),
7262 gfx::PointF(),
7263 gfx::Size(100, 100),
7264 true,
7265 false);
7266 SetLayerPropertiesForTesting(child.get(),
7267 identity_matrix,
7268 gfx::PointF(),
7269 gfx::PointF(),
7270 gfx::Size(100, 100),
7271 true,
7272 false);
7273
7274 root->reset_needs_push_properties_for_testing();
7275 child->reset_needs_push_properties_for_testing();
7276
7277 // This will change both layers' content bounds.
7278 ExecuteCalculateDrawProperties(root.get());
7279 EXPECT_TRUE(root->needs_push_properties());
7280 EXPECT_TRUE(child->needs_push_properties());
7281
7282 root->reset_needs_push_properties_for_testing();
7283 child->reset_needs_push_properties_for_testing();
7284
7285 // This will change only the child layer's contents scale and content bounds,
7286 // since the root layer is not a ContentsScalingLayer.
7287 ExecuteCalculateDrawProperties(root.get(), 2.f);
7288 EXPECT_FALSE(root->needs_push_properties());
7289 EXPECT_TRUE(child->needs_push_properties());
7290
7291 root->reset_needs_push_properties_for_testing();
7292 child->reset_needs_push_properties_for_testing();
7293
7294 // This will not change either layer's contents scale or content bounds.
7295 ExecuteCalculateDrawProperties(root.get(), 2.f);
7296 EXPECT_FALSE(root->needs_push_properties());
7297 EXPECT_FALSE(child->needs_push_properties());
7298}
7299
[email protected]989386c2013-07-18 21:37:237300TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:327301 MockContentLayerClient delegate;
7302 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267303
[email protected]fb661802013-03-25 01:59:327304 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7305 SetLayerPropertiesForTesting(parent.get(),
7306 identity_matrix,
[email protected]fb661802013-03-25 01:59:327307 gfx::PointF(),
7308 gfx::PointF(),
7309 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577310 false,
[email protected]fb661802013-03-25 01:59:327311 true);
[email protected]94f206c12012-08-25 00:09:147312
[email protected]fb661802013-03-25 01:59:327313 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7314 SetLayerPropertiesForTesting(child.get(),
7315 identity_matrix,
[email protected]fb661802013-03-25 01:59:327316 gfx::PointF(),
7317 gfx::PointF(2.f, 2.f),
7318 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577319 false,
[email protected]fb661802013-03-25 01:59:327320 true);
[email protected]94f206c12012-08-25 00:09:147321
[email protected]fb661802013-03-25 01:59:327322 gfx::Transform replica_transform;
7323 replica_transform.Scale(1.0, -1.0);
7324 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7325 SetLayerPropertiesForTesting(replica.get(),
7326 replica_transform,
[email protected]fb661802013-03-25 01:59:327327 gfx::PointF(),
7328 gfx::PointF(2.f, 2.f),
7329 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577330 false,
[email protected]fb661802013-03-25 01:59:327331 true);
[email protected]94f206c12012-08-25 00:09:147332
[email protected]fb661802013-03-25 01:59:327333 // This layer should end up in the same surface as child, with the same draw
7334 // and screen space transforms.
7335 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7336 CreateDrawableContentLayer(&delegate);
7337 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7338 identity_matrix,
[email protected]fb661802013-03-25 01:59:327339 gfx::PointF(),
7340 gfx::PointF(),
7341 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577342 false,
[email protected]fb661802013-03-25 01:59:327343 true);
[email protected]94f206c12012-08-25 00:09:147344
[email protected]fb661802013-03-25 01:59:327345 parent->AddChild(child);
7346 child->AddChild(duplicate_child_non_owner);
7347 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:147348
[email protected]d600df7d2013-08-03 02:34:287349 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7350 host->SetRootLayer(parent);
7351
[email protected]989386c2013-07-18 21:37:237352 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:147353
[email protected]fb661802013-03-25 01:59:327354 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:537355 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7356 parent.get(), parent->bounds(), &render_surface_layer_list);
7357 inputs.device_scale_factor = device_scale_factor;
7358 inputs.can_adjust_raster_scales = true;
7359 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:147360
[email protected]fb661802013-03-25 01:59:327361 // We should have two render surfaces. The root's render surface and child's
7362 // render surface (it needs one because it has a replica layer).
7363 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:147364
[email protected]fb661802013-03-25 01:59:327365 gfx::Transform expected_parent_transform;
7366 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7367 parent->screen_space_transform());
7368 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7369 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:147370
[email protected]fb661802013-03-25 01:59:327371 gfx::Transform expected_draw_transform;
7372 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
7373 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:147374
[email protected]fb661802013-03-25 01:59:327375 gfx::Transform expected_screen_space_transform;
7376 expected_screen_space_transform.Translate(
7377 device_scale_factor * child->position().x(),
7378 device_scale_factor * child->position().y());
7379 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
7380 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147381
[email protected]fb661802013-03-25 01:59:327382 gfx::Transform expected_duplicate_child_draw_transform =
7383 child->draw_transform();
7384 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
7385 duplicate_child_non_owner->draw_transform());
7386 EXPECT_TRANSFORMATION_MATRIX_EQ(
7387 child->screen_space_transform(),
7388 duplicate_child_non_owner->screen_space_transform());
7389 EXPECT_RECT_EQ(child->drawable_content_rect(),
7390 duplicate_child_non_owner->drawable_content_rect());
7391 EXPECT_EQ(child->content_bounds(),
7392 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:147393
[email protected]fb661802013-03-25 01:59:327394 gfx::Transform expected_render_surface_draw_transform;
7395 expected_render_surface_draw_transform.Translate(
7396 device_scale_factor * child->position().x(),
7397 device_scale_factor * child->position().y());
7398 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
7399 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147400
[email protected]fb661802013-03-25 01:59:327401 gfx::Transform expected_surface_draw_transform;
7402 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
7403 device_scale_factor * 2.f);
7404 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
7405 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147406
[email protected]fb661802013-03-25 01:59:327407 gfx::Transform expected_surface_screen_space_transform;
7408 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
7409 device_scale_factor * 2.f);
7410 EXPECT_TRANSFORMATION_MATRIX_EQ(
7411 expected_surface_screen_space_transform,
7412 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147413
[email protected]fb661802013-03-25 01:59:327414 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267415 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
7416 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
7417 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327418 EXPECT_TRANSFORMATION_MATRIX_EQ(
7419 expected_replica_draw_transform,
7420 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:147421
[email protected]fb661802013-03-25 01:59:327422 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267423 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
7424 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
7425 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327426 EXPECT_TRANSFORMATION_MATRIX_EQ(
7427 expected_replica_screen_space_transform,
7428 child->render_surface()->replica_screen_space_transform());
7429 EXPECT_TRANSFORMATION_MATRIX_EQ(
7430 expected_replica_screen_space_transform,
7431 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:477432}
7433
[email protected]989386c2013-07-18 21:37:237434TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:327435 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
7436 MockContentLayerClient delegate;
7437 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:477438
[email protected]fb661802013-03-25 01:59:327439 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7440 SetLayerPropertiesForTesting(parent.get(),
7441 identity_matrix,
[email protected]fb661802013-03-25 01:59:327442 gfx::PointF(),
7443 gfx::PointF(),
7444 gfx::Size(33, 31),
[email protected]56fffdd2014-02-11 19:50:577445 false,
[email protected]fb661802013-03-25 01:59:327446 true);
[email protected]904e9132012-11-01 00:12:477447
[email protected]fb661802013-03-25 01:59:327448 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7449 SetLayerPropertiesForTesting(child.get(),
7450 identity_matrix,
[email protected]fb661802013-03-25 01:59:327451 gfx::PointF(),
7452 gfx::PointF(),
7453 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577454 false,
[email protected]fb661802013-03-25 01:59:327455 true);
[email protected]904e9132012-11-01 00:12:477456
[email protected]fb661802013-03-25 01:59:327457 gfx::Transform replica_transform;
7458 replica_transform.Scale(1.0, -1.0);
7459 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7460 SetLayerPropertiesForTesting(replica.get(),
7461 replica_transform,
[email protected]fb661802013-03-25 01:59:327462 gfx::PointF(),
7463 gfx::PointF(),
7464 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577465 false,
[email protected]fb661802013-03-25 01:59:327466 true);
[email protected]904e9132012-11-01 00:12:477467
[email protected]fb661802013-03-25 01:59:327468 // This layer should end up in the same surface as child, with the same draw
7469 // and screen space transforms.
7470 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7471 CreateDrawableContentLayer(&delegate);
7472 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7473 identity_matrix,
[email protected]fb661802013-03-25 01:59:327474 gfx::PointF(),
7475 gfx::PointF(),
7476 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:577477 false,
[email protected]fb661802013-03-25 01:59:327478 true);
[email protected]904e9132012-11-01 00:12:477479
[email protected]fb661802013-03-25 01:59:327480 parent->AddChild(child);
7481 child->AddChild(duplicate_child_non_owner);
7482 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:477483
[email protected]d600df7d2013-08-03 02:34:287484 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7485 host->SetRootLayer(parent);
7486
[email protected]873639e2013-07-24 19:56:317487 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:537488
7489 RenderSurfaceLayerList render_surface_layer_list;
7490 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7491 parent.get(), parent->bounds(), &render_surface_layer_list);
7492 inputs.device_scale_factor = device_scale_factor;
7493 inputs.can_adjust_raster_scales = true;
7494 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:477495
[email protected]fb661802013-03-25 01:59:327496 // We should have two render surfaces. The root's render surface and child's
7497 // render surface (it needs one because it has a replica layer).
7498 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:477499
[email protected]fb661802013-03-25 01:59:327500 gfx::Transform identity_transform;
[email protected]904e9132012-11-01 00:12:477501
[email protected]fb661802013-03-25 01:59:327502 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7503 parent->screen_space_transform());
7504 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform());
7505 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform());
7506 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7507 child->screen_space_transform());
7508 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7509 duplicate_child_non_owner->draw_transform());
7510 EXPECT_TRANSFORMATION_MATRIX_EQ(
7511 identity_transform, duplicate_child_non_owner->screen_space_transform());
7512 EXPECT_RECT_EQ(child->drawable_content_rect(),
7513 duplicate_child_non_owner->drawable_content_rect());
7514 EXPECT_EQ(child->content_bounds(),
7515 duplicate_child_non_owner->content_bounds());
[email protected]904e9132012-11-01 00:12:477516
[email protected]fb661802013-03-25 01:59:327517 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7518 child->render_surface()->draw_transform());
7519 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7520 child->render_surface()->draw_transform());
7521 EXPECT_TRANSFORMATION_MATRIX_EQ(
7522 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:477523
[email protected]fb661802013-03-25 01:59:327524 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267525 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327526 EXPECT_TRANSFORMATION_MATRIX_EQ(
7527 expected_replica_draw_transform,
7528 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:477529
[email protected]fb661802013-03-25 01:59:327530 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267531 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327532 EXPECT_TRANSFORMATION_MATRIX_EQ(
7533 expected_replica_screen_space_transform,
7534 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147535}
7536
[email protected]989386c2013-07-18 21:37:237537TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:327538 scoped_refptr<Layer> root = Layer::Create();
7539 scoped_refptr<Layer> child = Layer::Create();
7540 scoped_refptr<Layer> grand_child = Layer::Create();
7541 scoped_refptr<Layer> mask_layer = Layer::Create();
7542 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:147543
[email protected]fb661802013-03-25 01:59:327544 grand_child->SetReplicaLayer(replica_layer.get());
7545 child->AddChild(grand_child.get());
7546 child->SetMaskLayer(mask_layer.get());
7547 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:147548
[email protected]d600df7d2013-08-03 02:34:287549 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7550 host->SetRootLayer(root);
7551
[email protected]fb661802013-03-25 01:59:327552 int nonexistent_id = -1;
7553 EXPECT_EQ(root,
7554 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
7555 EXPECT_EQ(child,
7556 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
7557 EXPECT_EQ(
7558 grand_child,
7559 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
7560 EXPECT_EQ(
7561 mask_layer,
7562 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
7563 EXPECT_EQ(
7564 replica_layer,
7565 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
7566 EXPECT_EQ(
7567 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:147568}
7569
[email protected]989386c2013-07-18 21:37:237570TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:327571 scoped_refptr<Layer> root = Layer::Create();
7572 scoped_refptr<Layer> child = Layer::Create();
7573 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
7574 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:577575
[email protected]fb661802013-03-25 01:59:327576 const gfx::Transform identity_matrix;
7577 SetLayerPropertiesForTesting(root.get(),
7578 identity_matrix,
[email protected]fb661802013-03-25 01:59:327579 gfx::PointF(),
7580 gfx::PointF(),
7581 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577582 true,
[email protected]fb661802013-03-25 01:59:327583 false);
7584 SetLayerPropertiesForTesting(child.get(),
7585 identity_matrix,
[email protected]fb661802013-03-25 01:59:327586 gfx::PointF(),
7587 gfx::PointF(),
7588 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577589 true,
[email protected]fb661802013-03-25 01:59:327590 false);
7591 SetLayerPropertiesForTesting(grand_child.get(),
7592 identity_matrix,
[email protected]fb661802013-03-25 01:59:327593 gfx::PointF(),
7594 gfx::PointF(),
7595 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577596 true,
[email protected]fb661802013-03-25 01:59:327597 false);
[email protected]498ec6e0e2012-11-30 18:24:577598
[email protected]fb661802013-03-25 01:59:327599 root->AddChild(child);
7600 child->AddChild(grand_child);
7601 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:577602
[email protected]d600df7d2013-08-03 02:34:287603 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7604 host->SetRootLayer(root);
7605
[email protected]fb661802013-03-25 01:59:327606 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:577607
[email protected]fb661802013-03-25 01:59:327608 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:577609}
7610
[email protected]989386c2013-07-18 21:37:237611TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:167612 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457613 TestSharedBitmapManager shared_bitmap_manager;
7614 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]f90fc412013-03-30 20:13:167615 host_impl.CreatePendingTree();
7616 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7617
7618 const gfx::Transform identity_matrix;
7619 SetLayerPropertiesForTesting(root.get(),
7620 identity_matrix,
[email protected]f90fc412013-03-30 20:13:167621 gfx::PointF(),
7622 gfx::PointF(),
7623 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:577624 true,
[email protected]f90fc412013-03-30 20:13:167625 false);
7626 root->SetDrawsContent(true);
7627
7628 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7629 SetLayerPropertiesForTesting(child.get(),
7630 identity_matrix,
[email protected]f90fc412013-03-30 20:13:167631 gfx::PointF(),
7632 gfx::PointF(),
7633 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577634 true,
[email protected]f90fc412013-03-30 20:13:167635 false);
7636 child->SetDrawsContent(true);
7637 child->SetOpacity(0.0f);
7638
7639 // Add opacity animation.
7640 AddOpacityTransitionToController(
7641 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
7642
7643 root->AddChild(child.Pass());
7644
[email protected]c0ae06c12013-06-24 18:32:197645 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537646 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7647 root.get(), root->bounds(), &render_surface_layer_list);
7648 inputs.can_adjust_raster_scales = true;
7649 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:167650
7651 // We should have one render surface and two layers. The child
7652 // layer should be included even though it is transparent.
7653 ASSERT_EQ(1u, render_surface_layer_list.size());
7654 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
7655}
7656
[email protected]10aabcc32012-12-13 09:18:597657typedef std::tr1::tuple<bool, bool> LCDTextTestParam;
[email protected]989386c2013-07-18 21:37:237658class LCDTextTest
7659 : public LayerTreeHostCommonTestBase,
7660 public testing::TestWithParam<LCDTextTestParam> {
[email protected]fb661802013-03-25 01:59:327661 protected:
7662 virtual void SetUp() {
7663 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
[email protected]10aabcc32012-12-13 09:18:597664
[email protected]fb661802013-03-25 01:59:327665 root_ = Layer::Create();
7666 child_ = Layer::Create();
7667 grand_child_ = Layer::Create();
7668 child_->AddChild(grand_child_.get());
7669 root_->AddChild(child_.get());
[email protected]10aabcc32012-12-13 09:18:597670
[email protected]fb661802013-03-25 01:59:327671 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307672 SetLayerPropertiesForTesting(root_.get(),
[email protected]fb661802013-03-25 01:59:327673 identity_matrix,
[email protected]fb661802013-03-25 01:59:327674 gfx::PointF(),
7675 gfx::PointF(),
7676 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577677 true,
[email protected]fb661802013-03-25 01:59:327678 false);
[email protected]22898ed2013-06-01 04:52:307679 SetLayerPropertiesForTesting(child_.get(),
[email protected]fb661802013-03-25 01:59:327680 identity_matrix,
[email protected]fb661802013-03-25 01:59:327681 gfx::PointF(),
7682 gfx::PointF(),
7683 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577684 true,
[email protected]fb661802013-03-25 01:59:327685 false);
[email protected]22898ed2013-06-01 04:52:307686 SetLayerPropertiesForTesting(grand_child_.get(),
[email protected]fb661802013-03-25 01:59:327687 identity_matrix,
[email protected]fb661802013-03-25 01:59:327688 gfx::PointF(),
7689 gfx::PointF(),
7690 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:577691 true,
[email protected]fb661802013-03-25 01:59:327692 false);
[email protected]10aabcc32012-12-13 09:18:597693
[email protected]fb661802013-03-25 01:59:327694 child_->SetForceRenderSurface(std::tr1::get<1>(GetParam()));
[email protected]d600df7d2013-08-03 02:34:287695
7696 host_ = FakeLayerTreeHost::Create();
7697 host_->SetRootLayer(root_);
[email protected]fb661802013-03-25 01:59:327698 }
[email protected]10aabcc32012-12-13 09:18:597699
[email protected]fb661802013-03-25 01:59:327700 bool can_use_lcd_text_;
[email protected]d600df7d2013-08-03 02:34:287701 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]fb661802013-03-25 01:59:327702 scoped_refptr<Layer> root_;
7703 scoped_refptr<Layer> child_;
7704 scoped_refptr<Layer> grand_child_;
[email protected]10aabcc32012-12-13 09:18:597705};
7706
[email protected]fb661802013-03-25 01:59:327707TEST_P(LCDTextTest, CanUseLCDText) {
7708 // Case 1: Identity transform.
7709 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307710 ExecuteCalculateDrawProperties(
7711 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327712 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7713 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7714 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597715
[email protected]fb661802013-03-25 01:59:327716 // Case 2: Integral translation.
7717 gfx::Transform integral_translation;
7718 integral_translation.Translate(1.0, 2.0);
7719 child_->SetTransform(integral_translation);
[email protected]22898ed2013-06-01 04:52:307720 ExecuteCalculateDrawProperties(
7721 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327722 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7723 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7724 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597725
[email protected]fb661802013-03-25 01:59:327726 // Case 3: Non-integral translation.
7727 gfx::Transform non_integral_translation;
7728 non_integral_translation.Translate(1.5, 2.5);
7729 child_->SetTransform(non_integral_translation);
[email protected]22898ed2013-06-01 04:52:307730 ExecuteCalculateDrawProperties(
7731 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327732 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7733 EXPECT_FALSE(child_->can_use_lcd_text());
7734 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597735
[email protected]fb661802013-03-25 01:59:327736 // Case 4: Rotation.
7737 gfx::Transform rotation;
7738 rotation.Rotate(10.0);
7739 child_->SetTransform(rotation);
[email protected]22898ed2013-06-01 04:52:307740 ExecuteCalculateDrawProperties(
7741 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327742 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7743 EXPECT_FALSE(child_->can_use_lcd_text());
7744 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597745
[email protected]fb661802013-03-25 01:59:327746 // Case 5: Scale.
7747 gfx::Transform scale;
7748 scale.Scale(2.0, 2.0);
7749 child_->SetTransform(scale);
[email protected]22898ed2013-06-01 04:52:307750 ExecuteCalculateDrawProperties(
7751 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327752 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7753 EXPECT_FALSE(child_->can_use_lcd_text());
7754 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597755
[email protected]fb661802013-03-25 01:59:327756 // Case 6: Skew.
7757 gfx::Transform skew;
7758 skew.SkewX(10.0);
7759 child_->SetTransform(skew);
[email protected]22898ed2013-06-01 04:52:307760 ExecuteCalculateDrawProperties(
7761 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327762 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7763 EXPECT_FALSE(child_->can_use_lcd_text());
7764 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597765
[email protected]fb661802013-03-25 01:59:327766 // Case 7: Translucent.
7767 child_->SetTransform(identity_matrix);
7768 child_->SetOpacity(0.5f);
[email protected]22898ed2013-06-01 04:52:307769 ExecuteCalculateDrawProperties(
7770 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327771 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7772 EXPECT_FALSE(child_->can_use_lcd_text());
7773 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597774
[email protected]fb661802013-03-25 01:59:327775 // Case 8: Sanity check: restore transform and opacity.
7776 child_->SetTransform(identity_matrix);
7777 child_->SetOpacity(1.f);
[email protected]22898ed2013-06-01 04:52:307778 ExecuteCalculateDrawProperties(
7779 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327780 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7781 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7782 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597783}
7784
[email protected]fd9a3b6d2013-08-03 00:46:177785TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
[email protected]fb661802013-03-25 01:59:327786 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
[email protected]22898ed2013-06-01 04:52:307787 ExecuteCalculateDrawProperties(
7788 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327789 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7790 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7791 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597792
[email protected]fb661802013-03-25 01:59:327793 // Add opacity animation.
7794 child_->SetOpacity(0.9f);
7795 AddOpacityTransitionToController(
7796 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:597797
[email protected]22898ed2013-06-01 04:52:307798 ExecuteCalculateDrawProperties(
7799 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327800 // Text AA should not be adjusted while animation is active.
7801 // Make sure LCD text AA setting remains unchanged.
7802 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7803 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7804 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597805}
7806
7807INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
7808 LCDTextTest,
[email protected]fb661802013-03-25 01:59:327809 testing::Combine(testing::Bool(), testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:597810
[email protected]989386c2013-07-18 21:37:237811TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:197812 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457813 TestSharedBitmapManager shared_bitmap_manager;
7814 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:197815 host_impl.CreatePendingTree();
7816 const gfx::Transform identity_matrix;
7817
7818 scoped_refptr<Layer> root = Layer::Create();
7819 SetLayerPropertiesForTesting(root.get(),
7820 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197821 gfx::PointF(),
7822 gfx::PointF(),
7823 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577824 true,
[email protected]c0ae06c12013-06-24 18:32:197825 false);
7826 root->SetIsDrawable(true);
7827
7828 scoped_refptr<Layer> child = Layer::Create();
7829 SetLayerPropertiesForTesting(child.get(),
7830 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197831 gfx::PointF(),
7832 gfx::PointF(),
7833 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577834 true,
[email protected]c0ae06c12013-06-24 18:32:197835 false);
7836 child->SetIsDrawable(true);
7837
7838 scoped_refptr<Layer> grand_child = Layer::Create();
7839 SetLayerPropertiesForTesting(grand_child.get(),
7840 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197841 gfx::PointF(),
7842 gfx::PointF(),
7843 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577844 true,
[email protected]c0ae06c12013-06-24 18:32:197845 false);
7846 grand_child->SetIsDrawable(true);
7847 grand_child->SetHideLayerAndSubtree(true);
7848
7849 child->AddChild(grand_child);
7850 root->AddChild(child);
7851
[email protected]d600df7d2013-08-03 02:34:287852 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7853 host->SetRootLayer(root);
7854
[email protected]989386c2013-07-18 21:37:237855 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537856 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7857 root.get(), root->bounds(), &render_surface_layer_list);
7858 inputs.can_adjust_raster_scales = true;
7859 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197860
7861 // We should have one render surface and two layers. The grand child has
7862 // hidden itself.
7863 ASSERT_EQ(1u, render_surface_layer_list.size());
7864 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237865 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
7866 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197867}
7868
[email protected]989386c2013-07-18 21:37:237869TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:197870 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457871 TestSharedBitmapManager shared_bitmap_manager;
7872 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:197873 host_impl.CreatePendingTree();
7874 const gfx::Transform identity_matrix;
7875
7876 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7877 SetLayerPropertiesForTesting(root.get(),
7878 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197879 gfx::PointF(),
7880 gfx::PointF(),
7881 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577882 true,
[email protected]c0ae06c12013-06-24 18:32:197883 false);
7884 root->SetDrawsContent(true);
7885
7886 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7887 SetLayerPropertiesForTesting(child.get(),
7888 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197889 gfx::PointF(),
7890 gfx::PointF(),
7891 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577892 true,
[email protected]c0ae06c12013-06-24 18:32:197893 false);
7894 child->SetDrawsContent(true);
7895
7896 scoped_ptr<LayerImpl> grand_child =
7897 LayerImpl::Create(host_impl.pending_tree(), 3);
7898 SetLayerPropertiesForTesting(grand_child.get(),
7899 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197900 gfx::PointF(),
7901 gfx::PointF(),
7902 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577903 true,
[email protected]c0ae06c12013-06-24 18:32:197904 false);
7905 grand_child->SetDrawsContent(true);
7906 grand_child->SetHideLayerAndSubtree(true);
7907
7908 child->AddChild(grand_child.Pass());
7909 root->AddChild(child.Pass());
7910
7911 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537912 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7913 root.get(), root->bounds(), &render_surface_layer_list);
7914 inputs.can_adjust_raster_scales = true;
7915 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197916
7917 // We should have one render surface and two layers. The grand child has
7918 // hidden itself.
7919 ASSERT_EQ(1u, render_surface_layer_list.size());
7920 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237921 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
7922 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197923}
7924
[email protected]989386c2013-07-18 21:37:237925TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:197926 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457927 TestSharedBitmapManager shared_bitmap_manager;
7928 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:197929 host_impl.CreatePendingTree();
7930 const gfx::Transform identity_matrix;
7931
7932 scoped_refptr<Layer> root = Layer::Create();
7933 SetLayerPropertiesForTesting(root.get(),
7934 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197935 gfx::PointF(),
7936 gfx::PointF(),
7937 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577938 true,
[email protected]c0ae06c12013-06-24 18:32:197939 false);
7940 root->SetIsDrawable(true);
7941
7942 scoped_refptr<Layer> child = Layer::Create();
7943 SetLayerPropertiesForTesting(child.get(),
7944 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197945 gfx::PointF(),
7946 gfx::PointF(),
7947 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577948 true,
[email protected]c0ae06c12013-06-24 18:32:197949 false);
7950 child->SetIsDrawable(true);
7951 child->SetHideLayerAndSubtree(true);
7952
7953 scoped_refptr<Layer> grand_child = Layer::Create();
7954 SetLayerPropertiesForTesting(grand_child.get(),
7955 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197956 gfx::PointF(),
7957 gfx::PointF(),
7958 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577959 true,
[email protected]c0ae06c12013-06-24 18:32:197960 false);
7961 grand_child->SetIsDrawable(true);
7962
7963 child->AddChild(grand_child);
7964 root->AddChild(child);
7965
[email protected]d600df7d2013-08-03 02:34:287966 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7967 host->SetRootLayer(root);
7968
[email protected]989386c2013-07-18 21:37:237969 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537970 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7971 root.get(), root->bounds(), &render_surface_layer_list);
7972 inputs.can_adjust_raster_scales = true;
7973 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197974
7975 // We should have one render surface and one layers. The child has
7976 // hidden itself and the grand child.
7977 ASSERT_EQ(1u, render_surface_layer_list.size());
7978 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237979 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:197980}
7981
[email protected]989386c2013-07-18 21:37:237982TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:197983 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457984 TestSharedBitmapManager shared_bitmap_manager;
7985 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:197986 host_impl.CreatePendingTree();
7987 const gfx::Transform identity_matrix;
7988
7989 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7990 SetLayerPropertiesForTesting(root.get(),
7991 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:197992 gfx::PointF(),
7993 gfx::PointF(),
7994 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577995 true,
[email protected]c0ae06c12013-06-24 18:32:197996 false);
7997 root->SetDrawsContent(true);
7998
7999 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
8000 SetLayerPropertiesForTesting(child.get(),
8001 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198002 gfx::PointF(),
8003 gfx::PointF(),
8004 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578005 true,
[email protected]c0ae06c12013-06-24 18:32:198006 false);
8007 child->SetDrawsContent(true);
8008 child->SetHideLayerAndSubtree(true);
8009
8010 scoped_ptr<LayerImpl> grand_child =
8011 LayerImpl::Create(host_impl.pending_tree(), 3);
8012 SetLayerPropertiesForTesting(grand_child.get(),
8013 identity_matrix,
[email protected]c0ae06c12013-06-24 18:32:198014 gfx::PointF(),
8015 gfx::PointF(),
8016 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578017 true,
[email protected]c0ae06c12013-06-24 18:32:198018 false);
8019 grand_child->SetDrawsContent(true);
8020
8021 child->AddChild(grand_child.Pass());
8022 root->AddChild(child.Pass());
8023
8024 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538025 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8026 root.get(), root->bounds(), &render_surface_layer_list);
8027 inputs.can_adjust_raster_scales = true;
8028 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198029
8030 // We should have one render surface and one layers. The child has
8031 // hidden itself and the grand child.
8032 ASSERT_EQ(1u, render_surface_layer_list.size());
8033 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238034 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:198035}
8036
[email protected]30fe19ff2013-07-04 00:54:458037void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
8038
[email protected]989386c2013-07-18 21:37:238039TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458040 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458041 TestSharedBitmapManager shared_bitmap_manager;
8042 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:458043 host_impl.CreatePendingTree();
8044 const gfx::Transform identity_matrix;
8045
8046 scoped_refptr<Layer> root = Layer::Create();
8047 SetLayerPropertiesForTesting(root.get(),
8048 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458049 gfx::PointF(),
8050 gfx::PointF(),
8051 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578052 true,
[email protected]30fe19ff2013-07-04 00:54:458053 false);
8054 root->SetIsDrawable(true);
8055
8056 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
8057 SetLayerPropertiesForTesting(copy_grand_parent.get(),
8058 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458059 gfx::PointF(),
8060 gfx::PointF(),
8061 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578062 true,
[email protected]30fe19ff2013-07-04 00:54:458063 false);
8064 copy_grand_parent->SetIsDrawable(true);
8065
8066 scoped_refptr<Layer> copy_parent = Layer::Create();
8067 SetLayerPropertiesForTesting(copy_parent.get(),
8068 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458069 gfx::PointF(),
8070 gfx::PointF(),
8071 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578072 true,
[email protected]30fe19ff2013-07-04 00:54:458073 false);
8074 copy_parent->SetIsDrawable(true);
8075 copy_parent->SetForceRenderSurface(true);
8076
8077 scoped_refptr<Layer> copy_layer = Layer::Create();
8078 SetLayerPropertiesForTesting(copy_layer.get(),
8079 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458080 gfx::PointF(),
8081 gfx::PointF(),
8082 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578083 true,
[email protected]30fe19ff2013-07-04 00:54:458084 false);
8085 copy_layer->SetIsDrawable(true);
8086
8087 scoped_refptr<Layer> copy_child = Layer::Create();
8088 SetLayerPropertiesForTesting(copy_child.get(),
8089 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458090 gfx::PointF(),
8091 gfx::PointF(),
8092 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578093 true,
[email protected]30fe19ff2013-07-04 00:54:458094 false);
8095 copy_child->SetIsDrawable(true);
8096
[email protected]ac020122013-07-12 23:45:538097 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
8098 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
8099 identity_matrix,
[email protected]ac020122013-07-12 23:45:538100 gfx::PointF(),
8101 gfx::PointF(),
8102 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578103 true,
[email protected]ac020122013-07-12 23:45:538104 false);
8105 copy_grand_parent_sibling_before->SetIsDrawable(true);
8106
8107 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
8108 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
8109 identity_matrix,
[email protected]ac020122013-07-12 23:45:538110 gfx::PointF(),
8111 gfx::PointF(),
8112 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578113 true,
[email protected]ac020122013-07-12 23:45:538114 false);
8115 copy_grand_parent_sibling_after->SetIsDrawable(true);
8116
[email protected]30fe19ff2013-07-04 00:54:458117 copy_layer->AddChild(copy_child);
8118 copy_parent->AddChild(copy_layer);
8119 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:538120 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:458121 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:538122 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:458123
[email protected]d600df7d2013-08-03 02:34:288124 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8125 host->SetRootLayer(root);
8126
[email protected]30fe19ff2013-07-04 00:54:458127 // Hide the copy_grand_parent and its subtree. But make a copy request in that
8128 // hidden subtree on copy_layer.
8129 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:538130 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
8131 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:458132 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8133 base::Bind(&EmptyCopyOutputCallback)));
8134 EXPECT_TRUE(copy_layer->HasCopyRequest());
8135
[email protected]989386c2013-07-18 21:37:238136 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538137 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8138 root.get(), root->bounds(), &render_surface_layer_list);
8139 inputs.can_adjust_raster_scales = true;
8140 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458141
[email protected]ac020122013-07-12 23:45:538142 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
8143 EXPECT_TRUE(copy_grand_parent->draw_properties().
8144 layer_or_descendant_has_copy_request);
8145 EXPECT_TRUE(copy_parent->draw_properties().
8146 layer_or_descendant_has_copy_request);
8147 EXPECT_TRUE(copy_layer->draw_properties().
8148 layer_or_descendant_has_copy_request);
8149 EXPECT_FALSE(copy_child->draw_properties().
8150 layer_or_descendant_has_copy_request);
8151 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
8152 layer_or_descendant_has_copy_request);
8153 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
8154 layer_or_descendant_has_copy_request);
8155
[email protected]30fe19ff2013-07-04 00:54:458156 // We should have three render surfaces, one for the root, one for the parent
8157 // since it owns a surface, and one for the copy_layer.
8158 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238159 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
8160 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
8161 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:458162
8163 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:538164 // copy_grand_parent is hidden along with its siblings, but the copy_parent
8165 // will appear since something in its subtree needs to be drawn for a copy
8166 // request.
[email protected]30fe19ff2013-07-04 00:54:458167 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238168 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
8169 EXPECT_EQ(copy_parent->id(),
8170 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458171
[email protected]7392c7b2014-02-07 08:28:288172 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:458173 // appear in its list, since it needs to be drawn for the copy request.
8174 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
8175 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238176 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458177
8178 // The copy_layer's render surface should have two contributing layers.
8179 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
8180 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238181 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458182 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:238183 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458184}
8185
[email protected]989386c2013-07-18 21:37:238186TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458187 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458188 TestSharedBitmapManager shared_bitmap_manager;
8189 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:458190 host_impl.CreatePendingTree();
8191 const gfx::Transform identity_matrix;
8192
8193 scoped_refptr<Layer> root = Layer::Create();
8194 SetLayerPropertiesForTesting(root.get(),
8195 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458196 gfx::PointF(),
8197 gfx::PointF(),
8198 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578199 true,
[email protected]30fe19ff2013-07-04 00:54:458200 false);
8201 root->SetIsDrawable(true);
8202
8203 scoped_refptr<Layer> copy_parent = Layer::Create();
8204 SetLayerPropertiesForTesting(copy_parent.get(),
8205 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458206 gfx::PointF(),
8207 gfx::PointF(),
8208 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:578209 true,
[email protected]30fe19ff2013-07-04 00:54:458210 false);
8211 copy_parent->SetIsDrawable(true);
8212 copy_parent->SetMasksToBounds(true);
8213
8214 scoped_refptr<Layer> copy_layer = Layer::Create();
8215 SetLayerPropertiesForTesting(copy_layer.get(),
8216 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458217 gfx::PointF(),
8218 gfx::PointF(),
8219 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578220 true,
[email protected]30fe19ff2013-07-04 00:54:458221 false);
8222 copy_layer->SetIsDrawable(true);
8223
8224 scoped_refptr<Layer> copy_child = Layer::Create();
8225 SetLayerPropertiesForTesting(copy_child.get(),
8226 identity_matrix,
[email protected]30fe19ff2013-07-04 00:54:458227 gfx::PointF(),
8228 gfx::PointF(),
8229 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578230 true,
[email protected]30fe19ff2013-07-04 00:54:458231 false);
8232 copy_child->SetIsDrawable(true);
8233
8234 copy_layer->AddChild(copy_child);
8235 copy_parent->AddChild(copy_layer);
8236 root->AddChild(copy_parent);
8237
[email protected]d600df7d2013-08-03 02:34:288238 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8239 host->SetRootLayer(root);
8240
[email protected]30fe19ff2013-07-04 00:54:458241 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8242 base::Bind(&EmptyCopyOutputCallback)));
8243 EXPECT_TRUE(copy_layer->HasCopyRequest());
8244
[email protected]989386c2013-07-18 21:37:238245 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538246 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8247 root.get(), root->bounds(), &render_surface_layer_list);
8248 inputs.can_adjust_raster_scales = true;
8249 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458250
8251 // We should have one render surface, as the others are clipped out.
8252 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238253 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458254
8255 // The root render surface should only have 1 contributing layer, since the
8256 // other layers are empty/clipped away.
8257 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238258 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458259}
8260
[email protected]11a07b102013-07-24 17:33:198261TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
8262 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458263 TestSharedBitmapManager shared_bitmap_manager;
8264 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]11a07b102013-07-24 17:33:198265 host_impl.CreatePendingTree();
8266 const gfx::Transform identity_matrix;
8267
8268 scoped_refptr<Layer> root = Layer::Create();
8269 SetLayerPropertiesForTesting(root.get(),
8270 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198271 gfx::PointF(),
8272 gfx::PointF(),
8273 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578274 true,
[email protected]11a07b102013-07-24 17:33:198275 false);
8276 root->SetIsDrawable(true);
8277
8278 // The surface is moved slightly outside of the viewport.
8279 scoped_refptr<Layer> surface = Layer::Create();
8280 SetLayerPropertiesForTesting(surface.get(),
8281 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198282 gfx::PointF(),
8283 gfx::PointF(-10, -20),
8284 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:578285 true,
[email protected]11a07b102013-07-24 17:33:198286 false);
8287 surface->SetForceRenderSurface(true);
8288
8289 scoped_refptr<Layer> surface_child = Layer::Create();
8290 SetLayerPropertiesForTesting(surface_child.get(),
8291 identity_matrix,
[email protected]11a07b102013-07-24 17:33:198292 gfx::PointF(),
8293 gfx::PointF(),
8294 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578295 true,
[email protected]11a07b102013-07-24 17:33:198296 false);
8297 surface_child->SetIsDrawable(true);
8298
8299 surface->AddChild(surface_child);
8300 root->AddChild(surface);
8301
[email protected]d600df7d2013-08-03 02:34:288302 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8303 host->SetRootLayer(root);
8304
[email protected]11a07b102013-07-24 17:33:198305 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538306 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8307 root.get(), root->bounds(), &render_surface_layer_list);
8308 inputs.can_adjust_raster_scales = true;
8309 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:198310
8311 // The visible_content_rect for the |surface_child| should not be clipped by
8312 // the viewport.
8313 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
8314 surface_child->visible_content_rect().ToString());
8315}
8316
[email protected]420fdf6e2013-08-26 20:36:388317TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
8318 // Ensure that a transform between the layer and its render surface is not a
8319 // problem. Constructs the following layer tree.
8320 //
8321 // root (a render surface)
8322 // + render_surface
8323 // + clip_parent (scaled)
8324 // + intervening_clipping_layer
8325 // + clip_child
8326 //
8327 // The render surface should be resized correctly and the clip child should
8328 // inherit the right clip rect.
8329 scoped_refptr<Layer> root = Layer::Create();
8330 scoped_refptr<Layer> render_surface = Layer::Create();
8331 scoped_refptr<Layer> clip_parent = Layer::Create();
8332 scoped_refptr<Layer> intervening = Layer::Create();
8333 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8334 make_scoped_refptr(new LayerWithForcedDrawsContent);
8335
8336 root->AddChild(render_surface);
8337 render_surface->AddChild(clip_parent);
8338 clip_parent->AddChild(intervening);
8339 intervening->AddChild(clip_child);
8340
8341 clip_child->SetClipParent(clip_parent.get());
8342
8343 intervening->SetMasksToBounds(true);
8344 clip_parent->SetMasksToBounds(true);
8345
8346 render_surface->SetForceRenderSurface(true);
8347
8348 gfx::Transform scale_transform;
8349 scale_transform.Scale(2, 2);
8350
8351 gfx::Transform identity_transform;
8352
8353 SetLayerPropertiesForTesting(root.get(),
8354 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388355 gfx::PointF(),
8356 gfx::PointF(),
8357 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578358 true,
[email protected]420fdf6e2013-08-26 20:36:388359 false);
8360 SetLayerPropertiesForTesting(render_surface.get(),
8361 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388362 gfx::PointF(),
8363 gfx::PointF(),
8364 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578365 true,
[email protected]420fdf6e2013-08-26 20:36:388366 false);
8367 SetLayerPropertiesForTesting(clip_parent.get(),
8368 scale_transform,
[email protected]420fdf6e2013-08-26 20:36:388369 gfx::PointF(),
8370 gfx::PointF(1.f, 1.f),
8371 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578372 true,
[email protected]420fdf6e2013-08-26 20:36:388373 false);
8374 SetLayerPropertiesForTesting(intervening.get(),
8375 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388376 gfx::PointF(),
8377 gfx::PointF(1.f, 1.f),
8378 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578379 true,
[email protected]420fdf6e2013-08-26 20:36:388380 false);
8381 SetLayerPropertiesForTesting(clip_child.get(),
8382 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388383 gfx::PointF(),
8384 gfx::PointF(1.f, 1.f),
8385 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578386 true,
[email protected]420fdf6e2013-08-26 20:36:388387 false);
8388
8389 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8390 host->SetRootLayer(root);
8391
8392 ExecuteCalculateDrawProperties(root.get());
8393
8394 ASSERT_TRUE(root->render_surface());
8395 ASSERT_TRUE(render_surface->render_surface());
8396
8397 // Ensure that we've inherited our clip parent's clip and weren't affected
8398 // by the intervening clip layer.
8399 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
8400 clip_parent->clip_rect().ToString());
8401 ASSERT_EQ(clip_parent->clip_rect().ToString(),
8402 clip_child->clip_rect().ToString());
8403 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
8404 intervening->clip_rect().ToString());
8405
8406 // Ensure that the render surface reports a content rect that has been grown
8407 // to accomodate for the clip child.
8408 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
8409 render_surface->render_surface()->content_rect().ToString());
8410
8411 // The above check implies the two below, but they nicely demonstrate that
8412 // we've grown, despite the intervening layer's clip.
8413 ASSERT_TRUE(clip_parent->clip_rect().Contains(
8414 render_surface->render_surface()->content_rect()));
8415 ASSERT_FALSE(intervening->clip_rect().Contains(
8416 render_surface->render_surface()->content_rect()));
8417}
8418
8419TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
8420 // Ensure that intervening render surfaces are not a problem in the basic
8421 // case. In the following tree, both render surfaces should be resized to
8422 // accomodate for the clip child, despite an intervening clip.
8423 //
8424 // root (a render surface)
8425 // + clip_parent (masks to bounds)
8426 // + render_surface1 (sets opacity)
8427 // + intervening (masks to bounds)
8428 // + render_surface2 (also sets opacity)
8429 // + clip_child
8430 //
8431 scoped_refptr<Layer> root = Layer::Create();
8432 scoped_refptr<Layer> clip_parent = Layer::Create();
8433 scoped_refptr<Layer> render_surface1 = Layer::Create();
8434 scoped_refptr<Layer> intervening = Layer::Create();
8435 scoped_refptr<Layer> render_surface2 = Layer::Create();
8436 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8437 make_scoped_refptr(new LayerWithForcedDrawsContent);
8438
8439 root->AddChild(clip_parent);
8440 clip_parent->AddChild(render_surface1);
8441 render_surface1->AddChild(intervening);
8442 intervening->AddChild(render_surface2);
8443 render_surface2->AddChild(clip_child);
8444
8445 clip_child->SetClipParent(clip_parent.get());
8446
8447 intervening->SetMasksToBounds(true);
8448 clip_parent->SetMasksToBounds(true);
8449
8450 render_surface1->SetForceRenderSurface(true);
8451 render_surface2->SetForceRenderSurface(true);
8452
8453 gfx::Transform translation_transform;
8454 translation_transform.Translate(2, 2);
8455
8456 gfx::Transform identity_transform;
8457 SetLayerPropertiesForTesting(root.get(),
8458 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388459 gfx::PointF(),
8460 gfx::PointF(),
8461 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578462 true,
[email protected]420fdf6e2013-08-26 20:36:388463 false);
8464 SetLayerPropertiesForTesting(clip_parent.get(),
8465 translation_transform,
[email protected]420fdf6e2013-08-26 20:36:388466 gfx::PointF(),
8467 gfx::PointF(1.f, 1.f),
8468 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578469 true,
[email protected]420fdf6e2013-08-26 20:36:388470 false);
8471 SetLayerPropertiesForTesting(render_surface1.get(),
8472 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388473 gfx::PointF(),
8474 gfx::PointF(),
8475 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578476 true,
[email protected]420fdf6e2013-08-26 20:36:388477 false);
8478 SetLayerPropertiesForTesting(intervening.get(),
8479 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388480 gfx::PointF(),
8481 gfx::PointF(1.f, 1.f),
8482 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578483 true,
[email protected]420fdf6e2013-08-26 20:36:388484 false);
8485 SetLayerPropertiesForTesting(render_surface2.get(),
8486 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388487 gfx::PointF(),
8488 gfx::PointF(),
8489 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578490 true,
[email protected]420fdf6e2013-08-26 20:36:388491 false);
8492 SetLayerPropertiesForTesting(clip_child.get(),
8493 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388494 gfx::PointF(),
8495 gfx::PointF(-10.f, -10.f),
8496 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578497 true,
[email protected]420fdf6e2013-08-26 20:36:388498 false);
8499
8500 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8501 host->SetRootLayer(root);
8502
8503 ExecuteCalculateDrawProperties(root.get());
8504
8505 EXPECT_TRUE(root->render_surface());
8506 EXPECT_TRUE(render_surface1->render_surface());
8507 EXPECT_TRUE(render_surface2->render_surface());
8508
8509 // Since the render surfaces could have expanded, they should not clip (their
8510 // bounds would no longer be reliable). We should resort to layer clipping
8511 // in this case.
8512 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8513 render_surface1->render_surface()->clip_rect().ToString());
8514 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8515 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8516 render_surface2->render_surface()->clip_rect().ToString());
8517 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8518
8519 // NB: clip rects are in target space.
8520 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8521 render_surface1->clip_rect().ToString());
8522 EXPECT_TRUE(render_surface1->is_clipped());
8523
8524 // This value is inherited from the clipping ancestor layer, 'intervening'.
8525 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8526 render_surface2->clip_rect().ToString());
8527 EXPECT_TRUE(render_surface2->is_clipped());
8528
8529 // The content rects of both render surfaces should both have expanded to
8530 // contain the clip child.
8531 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8532 render_surface1->render_surface()->content_rect().ToString());
8533 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8534 render_surface2->render_surface()->content_rect().ToString());
8535
8536 // The clip child should have inherited the clip parent's clip (projected to
8537 // the right space, of course), and should have the correctly sized visible
8538 // content rect.
8539 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8540 clip_child->clip_rect().ToString());
8541 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
8542 clip_child->visible_content_rect().ToString());
8543 EXPECT_TRUE(clip_child->is_clipped());
8544}
8545
8546TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
8547 // Ensure that intervening render surfaces are not a problem, even if there
8548 // is a scroll involved. Note, we do _not_ have to consider any other sort
8549 // of transform.
8550 //
8551 // root (a render surface)
8552 // + clip_parent (masks to bounds)
8553 // + render_surface1 (sets opacity)
8554 // + intervening (masks to bounds AND scrolls)
8555 // + render_surface2 (also sets opacity)
8556 // + clip_child
8557 //
8558 scoped_refptr<Layer> root = Layer::Create();
8559 scoped_refptr<Layer> clip_parent = Layer::Create();
8560 scoped_refptr<Layer> render_surface1 = Layer::Create();
8561 scoped_refptr<Layer> intervening = Layer::Create();
8562 scoped_refptr<Layer> render_surface2 = Layer::Create();
8563 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8564 make_scoped_refptr(new LayerWithForcedDrawsContent);
8565
8566 root->AddChild(clip_parent);
8567 clip_parent->AddChild(render_surface1);
8568 render_surface1->AddChild(intervening);
8569 intervening->AddChild(render_surface2);
8570 render_surface2->AddChild(clip_child);
8571
8572 clip_child->SetClipParent(clip_parent.get());
8573
8574 intervening->SetMasksToBounds(true);
8575 clip_parent->SetMasksToBounds(true);
[email protected]adeda572014-01-31 00:49:478576 intervening->SetScrollClipLayerId(clip_parent->id());
[email protected]420fdf6e2013-08-26 20:36:388577 intervening->SetScrollOffset(gfx::Vector2d(3, 3));
8578
8579 render_surface1->SetForceRenderSurface(true);
8580 render_surface2->SetForceRenderSurface(true);
8581
8582 gfx::Transform translation_transform;
8583 translation_transform.Translate(2, 2);
8584
8585 gfx::Transform identity_transform;
8586 SetLayerPropertiesForTesting(root.get(),
8587 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388588 gfx::PointF(),
8589 gfx::PointF(),
8590 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578591 true,
[email protected]420fdf6e2013-08-26 20:36:388592 false);
8593 SetLayerPropertiesForTesting(clip_parent.get(),
8594 translation_transform,
[email protected]420fdf6e2013-08-26 20:36:388595 gfx::PointF(),
8596 gfx::PointF(1.f, 1.f),
8597 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578598 true,
[email protected]420fdf6e2013-08-26 20:36:388599 false);
8600 SetLayerPropertiesForTesting(render_surface1.get(),
8601 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388602 gfx::PointF(),
8603 gfx::PointF(),
8604 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578605 true,
[email protected]420fdf6e2013-08-26 20:36:388606 false);
8607 SetLayerPropertiesForTesting(intervening.get(),
8608 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388609 gfx::PointF(),
8610 gfx::PointF(1.f, 1.f),
8611 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578612 true,
[email protected]420fdf6e2013-08-26 20:36:388613 false);
8614 SetLayerPropertiesForTesting(render_surface2.get(),
8615 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388616 gfx::PointF(),
8617 gfx::PointF(),
8618 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578619 true,
[email protected]420fdf6e2013-08-26 20:36:388620 false);
8621 SetLayerPropertiesForTesting(clip_child.get(),
8622 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388623 gfx::PointF(),
8624 gfx::PointF(-10.f, -10.f),
8625 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578626 true,
[email protected]420fdf6e2013-08-26 20:36:388627 false);
8628
8629 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8630 host->SetRootLayer(root);
8631
8632 ExecuteCalculateDrawProperties(root.get());
8633
8634 EXPECT_TRUE(root->render_surface());
8635 EXPECT_TRUE(render_surface1->render_surface());
8636 EXPECT_TRUE(render_surface2->render_surface());
8637
8638 // Since the render surfaces could have expanded, they should not clip (their
8639 // bounds would no longer be reliable). We should resort to layer clipping
8640 // in this case.
8641 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8642 render_surface1->render_surface()->clip_rect().ToString());
8643 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8644 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8645 render_surface2->render_surface()->clip_rect().ToString());
8646 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8647
8648 // NB: clip rects are in target space.
8649 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8650 render_surface1->clip_rect().ToString());
8651 EXPECT_TRUE(render_surface1->is_clipped());
8652
8653 // This value is inherited from the clipping ancestor layer, 'intervening'.
8654 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
8655 render_surface2->clip_rect().ToString());
8656 EXPECT_TRUE(render_surface2->is_clipped());
8657
8658 // The content rects of both render surfaces should both have expanded to
8659 // contain the clip child.
8660 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8661 render_surface1->render_surface()->content_rect().ToString());
8662 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8663 render_surface2->render_surface()->content_rect().ToString());
8664
8665 // The clip child should have inherited the clip parent's clip (projected to
8666 // the right space, of course), and should have the correctly sized visible
8667 // content rect.
8668 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8669 clip_child->clip_rect().ToString());
8670 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
8671 clip_child->visible_content_rect().ToString());
8672 EXPECT_TRUE(clip_child->is_clipped());
8673}
8674
8675TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
8676 // Ensures that descendants of the clip child inherit the correct clip.
8677 //
8678 // root (a render surface)
8679 // + clip_parent (masks to bounds)
8680 // + intervening (masks to bounds)
8681 // + clip_child
8682 // + child
8683 //
8684 scoped_refptr<Layer> root = Layer::Create();
8685 scoped_refptr<Layer> clip_parent = Layer::Create();
8686 scoped_refptr<Layer> intervening = Layer::Create();
8687 scoped_refptr<Layer> clip_child = Layer::Create();
8688 scoped_refptr<LayerWithForcedDrawsContent> child =
8689 make_scoped_refptr(new LayerWithForcedDrawsContent);
8690
8691 root->AddChild(clip_parent);
8692 clip_parent->AddChild(intervening);
8693 intervening->AddChild(clip_child);
8694 clip_child->AddChild(child);
8695
8696 clip_child->SetClipParent(clip_parent.get());
8697
8698 intervening->SetMasksToBounds(true);
8699 clip_parent->SetMasksToBounds(true);
8700
8701 gfx::Transform identity_transform;
8702 SetLayerPropertiesForTesting(root.get(),
8703 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388704 gfx::PointF(),
8705 gfx::PointF(),
8706 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578707 true,
[email protected]420fdf6e2013-08-26 20:36:388708 false);
8709 SetLayerPropertiesForTesting(clip_parent.get(),
8710 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388711 gfx::PointF(),
8712 gfx::PointF(),
8713 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:578714 true,
[email protected]420fdf6e2013-08-26 20:36:388715 false);
8716 SetLayerPropertiesForTesting(intervening.get(),
8717 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388718 gfx::PointF(),
8719 gfx::PointF(),
8720 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578721 true,
[email protected]420fdf6e2013-08-26 20:36:388722 false);
8723 SetLayerPropertiesForTesting(clip_child.get(),
8724 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388725 gfx::PointF(),
8726 gfx::PointF(),
8727 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578728 true,
[email protected]420fdf6e2013-08-26 20:36:388729 false);
8730 SetLayerPropertiesForTesting(child.get(),
8731 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388732 gfx::PointF(),
8733 gfx::PointF(),
8734 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:578735 true,
[email protected]420fdf6e2013-08-26 20:36:388736 false);
8737
8738 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8739 host->SetRootLayer(root);
8740
8741 ExecuteCalculateDrawProperties(root.get());
8742
8743 EXPECT_TRUE(root->render_surface());
8744
8745 // Neither the clip child nor its descendant should have inherited the clip
8746 // from |intervening|.
8747 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8748 clip_child->clip_rect().ToString());
8749 EXPECT_TRUE(clip_child->is_clipped());
8750 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8751 child->visible_content_rect().ToString());
8752 EXPECT_TRUE(child->is_clipped());
8753}
8754
8755TEST_F(LayerTreeHostCommonTest,
8756 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
8757 // Ensures that non-descendant clip children in the tree do not affect
8758 // render surfaces.
8759 //
8760 // root (a render surface)
8761 // + clip_parent (masks to bounds)
8762 // + render_surface1
8763 // + clip_child
8764 // + render_surface2
8765 // + non_clip_child
8766 //
8767 // In this example render_surface2 should be unaffected by clip_child.
8768 scoped_refptr<Layer> root = Layer::Create();
8769 scoped_refptr<Layer> clip_parent = Layer::Create();
8770 scoped_refptr<Layer> render_surface1 = Layer::Create();
8771 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8772 make_scoped_refptr(new LayerWithForcedDrawsContent);
8773 scoped_refptr<Layer> render_surface2 = Layer::Create();
8774 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
8775 make_scoped_refptr(new LayerWithForcedDrawsContent);
8776
8777 root->AddChild(clip_parent);
8778 clip_parent->AddChild(render_surface1);
8779 render_surface1->AddChild(clip_child);
8780 clip_parent->AddChild(render_surface2);
8781 render_surface2->AddChild(non_clip_child);
8782
8783 clip_child->SetClipParent(clip_parent.get());
8784
8785 clip_parent->SetMasksToBounds(true);
8786 render_surface1->SetMasksToBounds(true);
8787
8788 gfx::Transform identity_transform;
8789 SetLayerPropertiesForTesting(root.get(),
8790 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388791 gfx::PointF(),
8792 gfx::PointF(),
8793 gfx::Size(15, 15),
[email protected]56fffdd2014-02-11 19:50:578794 true,
[email protected]420fdf6e2013-08-26 20:36:388795 false);
8796 SetLayerPropertiesForTesting(clip_parent.get(),
8797 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388798 gfx::PointF(),
8799 gfx::PointF(),
8800 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578801 true,
[email protected]420fdf6e2013-08-26 20:36:388802 false);
8803 SetLayerPropertiesForTesting(render_surface1.get(),
8804 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388805 gfx::PointF(),
8806 gfx::PointF(5, 5),
8807 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578808 true,
[email protected]420fdf6e2013-08-26 20:36:388809 false);
8810 SetLayerPropertiesForTesting(render_surface2.get(),
8811 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388812 gfx::PointF(),
8813 gfx::PointF(),
8814 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578815 true,
[email protected]420fdf6e2013-08-26 20:36:388816 false);
8817 SetLayerPropertiesForTesting(clip_child.get(),
8818 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388819 gfx::PointF(),
8820 gfx::PointF(-1, 1),
8821 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:578822 true,
[email protected]420fdf6e2013-08-26 20:36:388823 false);
8824 SetLayerPropertiesForTesting(non_clip_child.get(),
8825 identity_transform,
[email protected]420fdf6e2013-08-26 20:36:388826 gfx::PointF(),
8827 gfx::PointF(),
8828 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:578829 true,
[email protected]420fdf6e2013-08-26 20:36:388830 false);
8831
8832 render_surface1->SetForceRenderSurface(true);
8833 render_surface2->SetForceRenderSurface(true);
8834
8835 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8836 host->SetRootLayer(root);
8837
8838 ExecuteCalculateDrawProperties(root.get());
8839
8840 EXPECT_TRUE(root->render_surface());
8841 EXPECT_TRUE(render_surface1->render_surface());
8842 EXPECT_TRUE(render_surface2->render_surface());
8843
8844 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8845 render_surface1->clip_rect().ToString());
8846 EXPECT_TRUE(render_surface1->is_clipped());
8847
8848 // The render surface should not clip (it has unclipped descendants), instead
8849 // it should rely on layer clipping.
8850 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8851 render_surface1->render_surface()->clip_rect().ToString());
8852 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8853
8854 // That said, it should have grown to accomodate the unclipped descendant.
8855 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
8856 render_surface1->render_surface()->content_rect().ToString());
8857
8858 // This render surface should clip. It has no unclipped descendants.
8859 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8860 render_surface2->clip_rect().ToString());
8861 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
8862
8863 // It also shouldn't have grown to accomodate the clip child.
8864 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8865 render_surface2->render_surface()->content_rect().ToString());
8866
8867 // Sanity check our num_unclipped_descendants values.
8868 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
8869 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
8870}
8871
[email protected]45948712013-09-27 02:46:488872TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
8873 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:458874 TestSharedBitmapManager shared_bitmap_manager;
8875 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]45948712013-09-27 02:46:488876 scoped_ptr<LayerImpl> root =
8877 LayerImpl::Create(host_impl.active_tree(), 12345);
8878 scoped_ptr<LayerImpl> child1 =
8879 LayerImpl::Create(host_impl.active_tree(), 123456);
8880 scoped_ptr<LayerImpl> child2 =
8881 LayerImpl::Create(host_impl.active_tree(), 1234567);
8882 scoped_ptr<LayerImpl> child3 =
8883 LayerImpl::Create(host_impl.active_tree(), 12345678);
8884
8885 gfx::Transform identity_matrix;
8886 gfx::PointF anchor;
8887 gfx::PointF position;
8888 gfx::Size bounds(100, 100);
8889 SetLayerPropertiesForTesting(root.get(),
8890 identity_matrix,
[email protected]45948712013-09-27 02:46:488891 anchor,
8892 position,
8893 bounds,
[email protected]56fffdd2014-02-11 19:50:578894 true,
[email protected]45948712013-09-27 02:46:488895 false);
8896 root->SetDrawsContent(true);
8897
8898 // This layer structure normally forces render surface due to preserves3d
8899 // behavior.
[email protected]45948712013-09-27 02:46:488900 SetLayerPropertiesForTesting(child1.get(),
8901 identity_matrix,
[email protected]45948712013-09-27 02:46:488902 anchor,
8903 position,
8904 bounds,
[email protected]56fffdd2014-02-11 19:50:578905 false,
8906 true);
[email protected]45948712013-09-27 02:46:488907 child1->SetDrawsContent(true);
8908 SetLayerPropertiesForTesting(child2.get(),
8909 identity_matrix,
[email protected]45948712013-09-27 02:46:488910 anchor,
8911 position,
8912 bounds,
[email protected]56fffdd2014-02-11 19:50:578913 true,
[email protected]45948712013-09-27 02:46:488914 false);
8915 child2->SetDrawsContent(true);
8916 SetLayerPropertiesForTesting(child3.get(),
8917 identity_matrix,
[email protected]45948712013-09-27 02:46:488918 anchor,
8919 position,
8920 bounds,
[email protected]56fffdd2014-02-11 19:50:578921 true,
[email protected]45948712013-09-27 02:46:488922 false);
8923 child3->SetDrawsContent(true);
8924
[email protected]56fffdd2014-02-11 19:50:578925 child2->SetIs3dSorted(true);
8926 child3->SetIs3dSorted(true);
8927
[email protected]45948712013-09-27 02:46:488928 child2->AddChild(child3.Pass());
8929 child1->AddChild(child2.Pass());
8930 root->AddChild(child1.Pass());
8931
8932 {
8933 LayerImplList render_surface_layer_list;
8934 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8935 root.get(), root->bounds(), &render_surface_layer_list);
8936 inputs.can_render_to_separate_surface = true;
8937 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8938
8939 EXPECT_EQ(2u, render_surface_layer_list.size());
8940 }
8941
8942 {
8943 LayerImplList render_surface_layer_list;
8944 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8945 root.get(), root->bounds(), &render_surface_layer_list);
8946 inputs.can_render_to_separate_surface = false;
8947 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8948
8949 EXPECT_EQ(1u, render_surface_layer_list.size());
8950 }
8951}
8952
[email protected]a9aa60a82013-08-29 04:28:268953TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
8954 scoped_refptr<Layer> root = Layer::Create();
8955 scoped_refptr<Layer> render_surface = Layer::Create();
8956 scoped_refptr<LayerWithForcedDrawsContent> child =
8957 make_scoped_refptr(new LayerWithForcedDrawsContent);
8958
8959 root->AddChild(render_surface);
8960 render_surface->AddChild(child);
8961
8962 gfx::Transform identity_transform;
8963 SetLayerPropertiesForTesting(root.get(),
8964 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:268965 gfx::PointF(),
8966 gfx::PointF(),
8967 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:578968 true,
[email protected]a9aa60a82013-08-29 04:28:268969 false);
8970 SetLayerPropertiesForTesting(render_surface.get(),
8971 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:268972 gfx::PointF(),
8973 gfx::PointF(),
8974 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:578975 false,
8976 true);
[email protected]a9aa60a82013-08-29 04:28:268977 SetLayerPropertiesForTesting(child.get(),
8978 identity_transform,
[email protected]a9aa60a82013-08-29 04:28:268979 gfx::PointF(),
8980 gfx::PointF(),
8981 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:578982 true,
[email protected]a9aa60a82013-08-29 04:28:268983 false);
8984
[email protected]56fffdd2014-02-11 19:50:578985 root->SetShouldFlattenTransform(false);
8986 root->SetIs3dSorted(true);
[email protected]a9aa60a82013-08-29 04:28:268987 render_surface->SetDoubleSided(false);
8988 render_surface->SetForceRenderSurface(true);
8989
8990 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8991 host->SetRootLayer(root);
8992
8993 ExecuteCalculateDrawProperties(root.get());
8994
8995 EXPECT_EQ(2u, render_surface_layer_list()->size());
8996 EXPECT_EQ(1u,
8997 render_surface_layer_list()->at(0)
8998 ->render_surface()->layer_list().size());
8999 EXPECT_EQ(1u,
9000 render_surface_layer_list()->at(1)
9001 ->render_surface()->layer_list().size());
9002
9003 gfx::Transform rotation_transform = identity_transform;
9004 rotation_transform.RotateAboutXAxis(180.0);
9005
9006 render_surface->SetTransform(rotation_transform);
9007
9008 ExecuteCalculateDrawProperties(root.get());
9009
9010 EXPECT_EQ(1u, render_surface_layer_list()->size());
9011 EXPECT_EQ(0u,
9012 render_surface_layer_list()->at(0)
9013 ->render_surface()->layer_list().size());
9014}
9015
[email protected]995708c52013-10-17 20:52:599016TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
9017 // Checks that the simple case (being clipped by a scroll parent that would
9018 // have been processed before you anyhow) results in the right clips.
9019 //
9020 // + root
9021 // + scroll_parent_border
9022 // | + scroll_parent_clip
9023 // | + scroll_parent
9024 // + scroll_child
9025 //
9026 scoped_refptr<Layer> root = Layer::Create();
9027 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9028 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9029 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9030 make_scoped_refptr(new LayerWithForcedDrawsContent);
9031 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9032 make_scoped_refptr(new LayerWithForcedDrawsContent);
9033
9034 root->AddChild(scroll_child);
9035
9036 root->AddChild(scroll_parent_border);
9037 scroll_parent_border->AddChild(scroll_parent_clip);
9038 scroll_parent_clip->AddChild(scroll_parent);
9039
9040 scroll_parent_clip->SetMasksToBounds(true);
9041
9042 scroll_child->SetScrollParent(scroll_parent.get());
9043
9044 gfx::Transform identity_transform;
9045 SetLayerPropertiesForTesting(root.get(),
9046 identity_transform,
[email protected]995708c52013-10-17 20:52:599047 gfx::PointF(),
9048 gfx::PointF(),
9049 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579050 true,
[email protected]995708c52013-10-17 20:52:599051 false);
9052 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9053 identity_transform,
[email protected]995708c52013-10-17 20:52:599054 gfx::PointF(),
9055 gfx::PointF(),
9056 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579057 true,
[email protected]995708c52013-10-17 20:52:599058 false);
9059 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9060 identity_transform,
[email protected]995708c52013-10-17 20:52:599061 gfx::PointF(),
9062 gfx::PointF(),
9063 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579064 true,
[email protected]995708c52013-10-17 20:52:599065 false);
9066 SetLayerPropertiesForTesting(scroll_parent.get(),
9067 identity_transform,
[email protected]995708c52013-10-17 20:52:599068 gfx::PointF(),
9069 gfx::PointF(),
9070 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579071 true,
[email protected]995708c52013-10-17 20:52:599072 false);
9073 SetLayerPropertiesForTesting(scroll_child.get(),
9074 identity_transform,
[email protected]995708c52013-10-17 20:52:599075 gfx::PointF(),
9076 gfx::PointF(),
9077 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579078 true,
[email protected]995708c52013-10-17 20:52:599079 false);
9080
9081 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9082 host->SetRootLayer(root);
9083
9084 ExecuteCalculateDrawProperties(root.get());
9085
9086 EXPECT_TRUE(root->render_surface());
9087
9088 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
9089 scroll_child->clip_rect().ToString());
9090 EXPECT_TRUE(scroll_child->is_clipped());
9091}
9092
9093TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
9094 // Checks that clipping by a scroll parent that follows you in paint order
9095 // still results in correct clipping.
9096 //
9097 // + root
9098 // + scroll_child
9099 // + scroll_parent_border
9100 // + scroll_parent_clip
9101 // + scroll_parent
9102 //
9103 scoped_refptr<Layer> root = Layer::Create();
9104 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9105 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9106 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9107 make_scoped_refptr(new LayerWithForcedDrawsContent);
9108 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9109 make_scoped_refptr(new LayerWithForcedDrawsContent);
9110
9111 root->AddChild(scroll_parent_border);
9112 scroll_parent_border->AddChild(scroll_parent_clip);
9113 scroll_parent_clip->AddChild(scroll_parent);
9114
9115 root->AddChild(scroll_child);
9116
9117 scroll_parent_clip->SetMasksToBounds(true);
9118
9119 scroll_child->SetScrollParent(scroll_parent.get());
9120
9121 gfx::Transform identity_transform;
9122 SetLayerPropertiesForTesting(root.get(),
9123 identity_transform,
[email protected]995708c52013-10-17 20:52:599124 gfx::PointF(),
9125 gfx::PointF(),
9126 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579127 true,
[email protected]995708c52013-10-17 20:52:599128 false);
9129 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9130 identity_transform,
[email protected]995708c52013-10-17 20:52:599131 gfx::PointF(),
9132 gfx::PointF(),
9133 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579134 true,
[email protected]995708c52013-10-17 20:52:599135 false);
9136 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9137 identity_transform,
[email protected]995708c52013-10-17 20:52:599138 gfx::PointF(),
9139 gfx::PointF(),
9140 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579141 true,
[email protected]995708c52013-10-17 20:52:599142 false);
9143 SetLayerPropertiesForTesting(scroll_parent.get(),
9144 identity_transform,
[email protected]995708c52013-10-17 20:52:599145 gfx::PointF(),
9146 gfx::PointF(),
9147 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579148 true,
[email protected]995708c52013-10-17 20:52:599149 false);
9150 SetLayerPropertiesForTesting(scroll_child.get(),
9151 identity_transform,
[email protected]995708c52013-10-17 20:52:599152 gfx::PointF(),
9153 gfx::PointF(),
9154 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579155 true,
[email protected]995708c52013-10-17 20:52:599156 false);
9157
9158 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9159 host->SetRootLayer(root);
9160
9161 ExecuteCalculateDrawProperties(root.get());
9162
9163 EXPECT_TRUE(root->render_surface());
9164
9165 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
9166 scroll_child->clip_rect().ToString());
9167 EXPECT_TRUE(scroll_child->is_clipped());
9168}
9169
9170TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
9171 // Checks that clipping by a scroll parent and scroll grandparent that follow
9172 // you in paint order still results in correct clipping.
9173 //
9174 // + root
9175 // + scroll_child
9176 // + scroll_parent_border
9177 // | + scroll_parent_clip
9178 // | + scroll_parent
9179 // + scroll_grandparent_border
9180 // + scroll_grandparent_clip
9181 // + scroll_grandparent
9182 //
9183 scoped_refptr<Layer> root = Layer::Create();
9184 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9185 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9186 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9187 make_scoped_refptr(new LayerWithForcedDrawsContent);
9188
9189 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
9190 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
9191 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
9192 make_scoped_refptr(new LayerWithForcedDrawsContent);
9193
9194 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9195 make_scoped_refptr(new LayerWithForcedDrawsContent);
9196
9197 root->AddChild(scroll_child);
9198
9199 root->AddChild(scroll_parent_border);
9200 scroll_parent_border->AddChild(scroll_parent_clip);
9201 scroll_parent_clip->AddChild(scroll_parent);
9202
9203 root->AddChild(scroll_grandparent_border);
9204 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
9205 scroll_grandparent_clip->AddChild(scroll_grandparent);
9206
9207 scroll_parent_clip->SetMasksToBounds(true);
9208 scroll_grandparent_clip->SetMasksToBounds(true);
9209
9210 scroll_child->SetScrollParent(scroll_parent.get());
9211 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
9212
9213 gfx::Transform identity_transform;
9214 SetLayerPropertiesForTesting(root.get(),
9215 identity_transform,
[email protected]995708c52013-10-17 20:52:599216 gfx::PointF(),
9217 gfx::PointF(),
9218 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579219 true,
[email protected]995708c52013-10-17 20:52:599220 false);
9221 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
9222 identity_transform,
[email protected]995708c52013-10-17 20:52:599223 gfx::PointF(),
9224 gfx::PointF(),
9225 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579226 true,
[email protected]995708c52013-10-17 20:52:599227 false);
9228 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
9229 identity_transform,
[email protected]995708c52013-10-17 20:52:599230 gfx::PointF(),
9231 gfx::PointF(),
9232 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:579233 true,
[email protected]995708c52013-10-17 20:52:599234 false);
9235 SetLayerPropertiesForTesting(scroll_grandparent.get(),
9236 identity_transform,
[email protected]995708c52013-10-17 20:52:599237 gfx::PointF(),
9238 gfx::PointF(),
9239 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579240 true,
[email protected]995708c52013-10-17 20:52:599241 false);
9242 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9243 identity_transform,
[email protected]995708c52013-10-17 20:52:599244 gfx::PointF(),
9245 gfx::PointF(),
9246 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579247 true,
[email protected]995708c52013-10-17 20:52:599248 false);
9249 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9250 identity_transform,
[email protected]995708c52013-10-17 20:52:599251 gfx::PointF(),
9252 gfx::PointF(),
9253 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579254 true,
[email protected]995708c52013-10-17 20:52:599255 false);
9256 SetLayerPropertiesForTesting(scroll_parent.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_child.get(),
9264 identity_transform,
[email protected]995708c52013-10-17 20:52:599265 gfx::PointF(),
9266 gfx::PointF(),
9267 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579268 true,
[email protected]995708c52013-10-17 20:52:599269 false);
9270
9271 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9272 host->SetRootLayer(root);
9273
9274 ExecuteCalculateDrawProperties(root.get());
9275
9276 EXPECT_TRUE(root->render_surface());
9277
9278 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
9279 scroll_child->clip_rect().ToString());
9280 EXPECT_TRUE(scroll_child->is_clipped());
9281
9282 // Despite the fact that we visited the above layers out of order to get the
9283 // correct clip, the layer lists should be unaffected.
9284 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
9285 EXPECT_EQ(scroll_child.get(),
9286 root->render_surface()->layer_list().at(0));
9287 EXPECT_EQ(scroll_parent.get(),
9288 root->render_surface()->layer_list().at(1));
9289 EXPECT_EQ(scroll_grandparent.get(),
9290 root->render_surface()->layer_list().at(2));
9291}
9292
9293TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
9294 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:229295 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:599296 // + root
9297 // + scroll_child
9298 // + scroll_parent_border
9299 // + scroll_parent_clip
9300 // + scroll_parent
9301 // + render_surface1
9302 // + scroll_grandparent_border
9303 // + scroll_grandparent_clip
9304 // + scroll_grandparent
9305 // + render_surface2
9306 //
[email protected]44d8e84c2013-10-19 19:13:229307 scoped_refptr<LayerWithForcedDrawsContent> root =
9308 make_scoped_refptr(new LayerWithForcedDrawsContent);
[email protected]995708c52013-10-17 20:52:599309
9310 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9311 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9312 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9313 make_scoped_refptr(new LayerWithForcedDrawsContent);
9314 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
9315 make_scoped_refptr(new LayerWithForcedDrawsContent);
9316
9317 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
9318 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
9319 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
9320 make_scoped_refptr(new LayerWithForcedDrawsContent);
9321 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
9322 make_scoped_refptr(new LayerWithForcedDrawsContent);
9323
9324 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9325 make_scoped_refptr(new LayerWithForcedDrawsContent);
9326
9327 root->AddChild(scroll_child);
9328
9329 root->AddChild(scroll_parent_border);
9330 scroll_parent_border->AddChild(scroll_parent_clip);
9331 scroll_parent_clip->AddChild(scroll_parent);
9332 scroll_parent->AddChild(render_surface2);
9333
9334 root->AddChild(scroll_grandparent_border);
9335 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
9336 scroll_grandparent_clip->AddChild(scroll_grandparent);
9337 scroll_grandparent->AddChild(render_surface1);
9338
9339 scroll_parent_clip->SetMasksToBounds(true);
9340 scroll_grandparent_clip->SetMasksToBounds(true);
9341
9342 scroll_child->SetScrollParent(scroll_parent.get());
9343 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
9344
9345 render_surface1->SetForceRenderSurface(true);
9346 render_surface2->SetForceRenderSurface(true);
9347
9348 gfx::Transform identity_transform;
9349 SetLayerPropertiesForTesting(root.get(),
9350 identity_transform,
[email protected]995708c52013-10-17 20:52:599351 gfx::PointF(),
9352 gfx::PointF(),
9353 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579354 true,
[email protected]995708c52013-10-17 20:52:599355 false);
9356 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
9357 identity_transform,
[email protected]995708c52013-10-17 20:52:599358 gfx::PointF(),
9359 gfx::PointF(),
9360 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579361 true,
[email protected]995708c52013-10-17 20:52:599362 false);
9363 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
9364 identity_transform,
[email protected]995708c52013-10-17 20:52:599365 gfx::PointF(),
9366 gfx::PointF(),
9367 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:579368 true,
[email protected]995708c52013-10-17 20:52:599369 false);
9370 SetLayerPropertiesForTesting(scroll_grandparent.get(),
9371 identity_transform,
[email protected]995708c52013-10-17 20:52:599372 gfx::PointF(),
9373 gfx::PointF(),
9374 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579375 true,
[email protected]995708c52013-10-17 20:52:599376 false);
9377 SetLayerPropertiesForTesting(render_surface1.get(),
9378 identity_transform,
[email protected]995708c52013-10-17 20:52:599379 gfx::PointF(),
9380 gfx::PointF(),
9381 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579382 true,
[email protected]995708c52013-10-17 20:52:599383 false);
9384 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9385 identity_transform,
[email protected]995708c52013-10-17 20:52:599386 gfx::PointF(),
9387 gfx::PointF(),
9388 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579389 true,
[email protected]995708c52013-10-17 20:52:599390 false);
9391 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9392 identity_transform,
[email protected]995708c52013-10-17 20:52:599393 gfx::PointF(),
9394 gfx::PointF(),
9395 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579396 true,
[email protected]995708c52013-10-17 20:52:599397 false);
9398 SetLayerPropertiesForTesting(scroll_parent.get(),
9399 identity_transform,
[email protected]995708c52013-10-17 20:52:599400 gfx::PointF(),
9401 gfx::PointF(),
9402 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579403 true,
[email protected]995708c52013-10-17 20:52:599404 false);
9405 SetLayerPropertiesForTesting(render_surface2.get(),
9406 identity_transform,
[email protected]995708c52013-10-17 20:52:599407 gfx::PointF(),
9408 gfx::PointF(),
9409 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579410 true,
[email protected]995708c52013-10-17 20:52:599411 false);
9412 SetLayerPropertiesForTesting(scroll_child.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
9420 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9421 host->SetRootLayer(root);
9422
9423 RenderSurfaceLayerList render_surface_layer_list;
9424 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
9425 root.get(),
9426 root->bounds(),
9427 identity_transform,
9428 &render_surface_layer_list);
9429
9430 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9431
9432 EXPECT_TRUE(root->render_surface());
9433
9434 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
9435 scroll_child->clip_rect().ToString());
9436 EXPECT_TRUE(scroll_child->is_clipped());
9437
9438 // Despite the fact that we had to process the layers out of order to get the
9439 // right clip, our render_surface_layer_list's order should be unaffected.
9440 EXPECT_EQ(3u, render_surface_layer_list.size());
9441 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
9442 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
9443 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
[email protected]44d8e84c2013-10-19 19:13:229444 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
9445 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
9446 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:599447}
9448
9449TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) {
9450 // We rearrange layer list contributions if we have to visit children out of
9451 // order, but it should be a 'stable' rearrangement. That is, the layer list
9452 // additions for a single layer should not be reordered, though their position
9453 // wrt to the contributions due to a sibling may vary.
9454 //
9455 // + root
9456 // + scroll_child
9457 // + top_content
9458 // + bottom_content
9459 // + scroll_parent_border
9460 // + scroll_parent_clip
9461 // + scroll_parent
9462 //
9463 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:459464 TestSharedBitmapManager shared_bitmap_manager;
9465 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]995708c52013-10-17 20:52:599466 host_impl.CreatePendingTree();
9467 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9468 scoped_ptr<LayerImpl> scroll_parent_border =
9469 LayerImpl::Create(host_impl.active_tree(), 2);
9470 scoped_ptr<LayerImpl> scroll_parent_clip =
9471 LayerImpl::Create(host_impl.active_tree(), 3);
9472 scoped_ptr<LayerImpl> scroll_parent =
9473 LayerImpl::Create(host_impl.active_tree(), 4);
9474 scoped_ptr<LayerImpl> scroll_child =
9475 LayerImpl::Create(host_impl.active_tree(), 5);
9476 scoped_ptr<LayerImpl> bottom_content =
9477 LayerImpl::Create(host_impl.active_tree(), 6);
9478 scoped_ptr<LayerImpl> top_content =
9479 LayerImpl::Create(host_impl.active_tree(), 7);
9480
9481 scroll_parent_clip->SetMasksToBounds(true);
9482
9483 scroll_child->SetScrollParent(scroll_parent.get());
9484 scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>);
9485 scroll_children->insert(scroll_child.get());
9486 scroll_parent->SetScrollChildren(scroll_children.release());
9487
9488 scroll_child->SetDrawsContent(true);
9489 scroll_parent->SetDrawsContent(true);
9490 top_content->SetDrawsContent(true);
9491 bottom_content->SetDrawsContent(true);
9492
9493 gfx::Transform identity_transform;
9494 gfx::Transform top_transform;
9495 top_transform.Translate3d(0.0, 0.0, 5.0);
9496 gfx::Transform bottom_transform;
9497 bottom_transform.Translate3d(0.0, 0.0, 3.0);
9498
9499 SetLayerPropertiesForTesting(root.get(),
9500 identity_transform,
[email protected]995708c52013-10-17 20:52:599501 gfx::PointF(),
9502 gfx::PointF(),
9503 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579504 true,
[email protected]995708c52013-10-17 20:52:599505 false);
9506 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9507 identity_transform,
[email protected]995708c52013-10-17 20:52:599508 gfx::PointF(),
9509 gfx::PointF(),
9510 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579511 true,
[email protected]995708c52013-10-17 20:52:599512 false);
9513 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9514 identity_transform,
[email protected]995708c52013-10-17 20:52:599515 gfx::PointF(),
9516 gfx::PointF(),
9517 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579518 true,
[email protected]995708c52013-10-17 20:52:599519 false);
9520 SetLayerPropertiesForTesting(scroll_parent.get(),
9521 identity_transform,
[email protected]995708c52013-10-17 20:52:599522 gfx::PointF(),
9523 gfx::PointF(),
9524 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579525 true,
[email protected]995708c52013-10-17 20:52:599526 false);
9527 SetLayerPropertiesForTesting(scroll_child.get(),
9528 identity_transform,
[email protected]995708c52013-10-17 20:52:599529 gfx::PointF(),
9530 gfx::PointF(),
9531 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579532 true,
[email protected]995708c52013-10-17 20:52:599533 false);
9534 SetLayerPropertiesForTesting(top_content.get(),
9535 top_transform,
[email protected]995708c52013-10-17 20:52:599536 gfx::PointF(),
9537 gfx::PointF(),
9538 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579539 false,
9540 true);
[email protected]995708c52013-10-17 20:52:599541 SetLayerPropertiesForTesting(bottom_content.get(),
9542 bottom_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 false,
9547 true);
[email protected]995708c52013-10-17 20:52:599548
[email protected]56fffdd2014-02-11 19:50:579549 scroll_child->SetShouldFlattenTransform(false);
9550 scroll_child->SetIs3dSorted(true);
[email protected]995708c52013-10-17 20:52:599551
9552 scroll_child->AddChild(top_content.Pass());
9553 scroll_child->AddChild(bottom_content.Pass());
9554 root->AddChild(scroll_child.Pass());
9555
9556 scroll_parent_clip->AddChild(scroll_parent.Pass());
9557 scroll_parent_border->AddChild(scroll_parent_clip.Pass());
9558 root->AddChild(scroll_parent_border.Pass());
9559
9560 LayerImplList render_surface_layer_list;
9561 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9562 root.get(), root->bounds(), &render_surface_layer_list);
9563
9564 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9565
9566 EXPECT_TRUE(root->render_surface());
9567
9568 // If we don't sort by depth and let the layers get added in the order they
9569 // would normally be visited in, then layers 6 and 7 will be out of order. In
9570 // other words, although we've had to shift 5, 6, and 7 to appear before 4
9571 // in the list (because of the scroll parent relationship), this should not
9572 // have an effect on the the order of 5, 6, and 7 (which had been reordered
9573 // due to layer sorting).
9574 EXPECT_EQ(4u, root->render_surface()->layer_list().size());
9575 EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id());
9576 EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id());
9577 EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id());
9578 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
9579}
9580
[email protected]d81752b2013-10-25 08:32:239581TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
9582 // This test verifies that a scrolling layer that gets snapped to
9583 // integer coordinates doesn't move a fixed position child.
9584 //
9585 // + root
9586 // + container
9587 // + scroller
9588 // + fixed
9589 //
9590 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:459591 TestSharedBitmapManager shared_bitmap_manager;
9592 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]d81752b2013-10-25 08:32:239593 host_impl.CreatePendingTree();
9594 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9595 scoped_ptr<LayerImpl> container =
9596 LayerImpl::Create(host_impl.active_tree(), 2);
9597 LayerImpl* container_layer = container.get();
9598 scoped_ptr<LayerImpl> scroller =
9599 LayerImpl::Create(host_impl.active_tree(), 3);
9600 LayerImpl* scroll_layer = scroller.get();
9601 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
9602 LayerImpl* fixed_layer = fixed.get();
9603
9604 container->SetIsContainerForFixedPositionLayers(true);
9605
9606 LayerPositionConstraint constraint;
9607 constraint.set_is_fixed_position(true);
9608 fixed->SetPositionConstraint(constraint);
9609
[email protected]adeda572014-01-31 00:49:479610 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:239611
9612 gfx::Transform identity_transform;
9613 gfx::Transform container_transform;
9614 container_transform.Translate3d(10.0, 20.0, 0.0);
9615 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
9616
9617 SetLayerPropertiesForTesting(root.get(),
9618 identity_transform,
[email protected]d81752b2013-10-25 08:32:239619 gfx::PointF(),
9620 gfx::PointF(),
9621 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579622 true,
[email protected]d81752b2013-10-25 08:32:239623 false);
9624 SetLayerPropertiesForTesting(container.get(),
9625 container_transform,
[email protected]d81752b2013-10-25 08:32:239626 gfx::PointF(),
9627 gfx::PointF(),
9628 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:579629 true,
[email protected]d81752b2013-10-25 08:32:239630 false);
9631 SetLayerPropertiesForTesting(scroller.get(),
9632 identity_transform,
[email protected]d81752b2013-10-25 08:32:239633 gfx::PointF(),
9634 gfx::PointF(),
9635 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:579636 true,
[email protected]d81752b2013-10-25 08:32:239637 false);
9638 SetLayerPropertiesForTesting(fixed.get(),
9639 identity_transform,
[email protected]d81752b2013-10-25 08:32:239640 gfx::PointF(),
9641 gfx::PointF(),
9642 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:579643 true,
[email protected]d81752b2013-10-25 08:32:239644 false);
9645
9646 scroller->AddChild(fixed.Pass());
9647 container->AddChild(scroller.Pass());
9648 root->AddChild(container.Pass());
9649
9650 // Rounded to integers already.
9651 {
9652 gfx::Vector2dF scroll_delta(3.0, 5.0);
9653 scroll_layer->SetScrollDelta(scroll_delta);
9654
9655 LayerImplList render_surface_layer_list;
9656 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9657 root.get(), root->bounds(), &render_surface_layer_list);
9658 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9659
9660 EXPECT_TRANSFORMATION_MATRIX_EQ(
9661 container_layer->draw_properties().screen_space_transform,
9662 fixed_layer->draw_properties().screen_space_transform);
9663 EXPECT_VECTOR_EQ(
9664 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9665 container_offset);
9666 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
9667 .screen_space_transform.To2dTranslation(),
9668 container_offset - scroll_delta);
9669 }
9670
9671 // Scroll delta requiring rounding.
9672 {
9673 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
9674 scroll_layer->SetScrollDelta(scroll_delta);
9675
9676 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
9677
9678 LayerImplList render_surface_layer_list;
9679 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9680 root.get(), root->bounds(), &render_surface_layer_list);
9681 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9682
9683 EXPECT_TRANSFORMATION_MATRIX_EQ(
9684 container_layer->draw_properties().screen_space_transform,
9685 fixed_layer->draw_properties().screen_space_transform);
9686 EXPECT_VECTOR_EQ(
9687 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9688 container_offset);
9689 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
9690 .screen_space_transform.To2dTranslation(),
9691 container_offset - rounded_scroll_delta);
9692 }
9693}
9694
[email protected]ba565742012-11-10 09:29:489695} // namespace
9696} // namespace cc