blob: c7ac012d9633c078d2618666ee8ab1cde185e954 [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,
44 const gfx::Transform& sublayer_transform,
[email protected]14bc5d682014-01-17 07:26:4745 const gfx::PointF& anchor,
46 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:2647 const gfx::Size& bounds,
[email protected]989386c2013-07-18 21:37:2348 bool preserves3d) {
49 layer->SetTransform(transform);
50 layer->SetSublayerTransform(sublayer_transform);
51 layer->SetAnchorPoint(anchor);
52 layer->SetPosition(position);
53 layer->SetBounds(bounds);
54 layer->SetPreserves3d(preserves3d);
55 }
[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,
59 const gfx::Transform& sublayer_transform,
[email protected]14bc5d682014-01-17 07:26:4760 const gfx::PointF& anchor,
61 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:2662 const gfx::Size& bounds,
[email protected]989386c2013-07-18 21:37:2363 bool preserves3d) {
64 SetLayerPropertiesForTestingInternal<Layer>(layer,
65 transform,
66 sublayer_transform,
67 anchor,
68 position,
69 bounds,
70 preserves3d);
71 }
[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,
75 const gfx::Transform& sublayer_transform,
[email protected]14bc5d682014-01-17 07:26:4776 const gfx::PointF& anchor,
77 const gfx::PointF& position,
[email protected]64348ea2014-01-29 22:58:2678 const gfx::Size& bounds,
[email protected]989386c2013-07-18 21:37:2379 bool preserves3d) {
80 SetLayerPropertiesForTestingInternal<LayerImpl>(layer,
81 transform,
82 sublayer_transform,
83 anchor,
84 position,
85 bounds,
86 preserves3d);
87 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]f34a24232012-09-20 22:59:55202};
203
[email protected]fb661802013-03-25 01:59:32204scoped_refptr<ContentLayer> CreateDrawableContentLayer(
205 ContentLayerClient* delegate) {
206 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate);
207 to_return->SetIsDrawable(true);
208 return to_return;
[email protected]f34a24232012-09-20 22:59:55209}
210
[email protected]989386c2013-07-18 21:37:23211#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
212 do { \
213 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
214 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:47215 } while (false)
216
[email protected]989386c2013-07-18 21:37:23217TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32218 // Sanity check: For layers positioned at zero, with zero size,
219 // and with identity transforms, then the draw transform,
220 // screen space transform, and the hierarchy passed on to children
221 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14222
[email protected]fb661802013-03-25 01:59:32223 scoped_refptr<Layer> parent = Layer::Create();
224 scoped_refptr<Layer> child = Layer::Create();
225 scoped_refptr<Layer> grand_child = Layer::Create();
226 parent->AddChild(child);
227 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14228
[email protected]d600df7d2013-08-03 02:34:28229 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
230 host->SetRootLayer(parent);
231
[email protected]fb661802013-03-25 01:59:32232 gfx::Transform identity_matrix;
233 SetLayerPropertiesForTesting(parent.get(),
234 identity_matrix,
235 identity_matrix,
236 gfx::PointF(),
237 gfx::PointF(),
238 gfx::Size(100, 100),
239 false);
240 SetLayerPropertiesForTesting(child.get(),
241 identity_matrix,
242 identity_matrix,
243 gfx::PointF(),
244 gfx::PointF(),
245 gfx::Size(),
246 false);
247 SetLayerPropertiesForTesting(grand_child.get(),
248 identity_matrix,
249 identity_matrix,
250 gfx::PointF(),
251 gfx::PointF(),
252 gfx::Size(),
253 false);
[email protected]94f206c12012-08-25 00:09:14254
[email protected]fb661802013-03-25 01:59:32255 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14256
[email protected]fb661802013-03-25 01:59:32257 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
258 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
259 child->screen_space_transform());
260 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
261 grand_child->draw_transform());
262 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
263 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14264}
265
[email protected]989386c2013-07-18 21:37:23266TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32267 gfx::Transform identity_matrix;
268 scoped_refptr<Layer> layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:14269
[email protected]fb661802013-03-25 01:59:32270 scoped_refptr<Layer> root = Layer::Create();
271 SetLayerPropertiesForTesting(root.get(),
272 identity_matrix,
273 identity_matrix,
274 gfx::PointF(),
275 gfx::PointF(),
276 gfx::Size(1, 2),
277 false);
278 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42279
[email protected]d600df7d2013-08-03 02:34:28280 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
281 host->SetRootLayer(root);
282
[email protected]fb661802013-03-25 01:59:32283 // Case 1: setting the sublayer transform should not affect this layer's draw
284 // transform or screen-space transform.
285 gfx::Transform arbitrary_translation;
286 arbitrary_translation.Translate(10.0, 20.0);
287 SetLayerPropertiesForTesting(layer.get(),
288 identity_matrix,
289 arbitrary_translation,
290 gfx::PointF(),
291 gfx::PointF(),
292 gfx::Size(100, 100),
293 false);
294 ExecuteCalculateDrawProperties(root.get());
295 gfx::Transform expected_draw_transform = identity_matrix;
296 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
297 layer->draw_transform());
298 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
299 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14300
[email protected]fb661802013-03-25 01:59:32301 // Case 2: Setting the bounds of the layer should not affect either the draw
302 // transform or the screenspace transform.
303 gfx::Transform translation_to_center;
304 translation_to_center.Translate(5.0, 6.0);
305 SetLayerPropertiesForTesting(layer.get(),
306 identity_matrix,
307 identity_matrix,
308 gfx::PointF(),
309 gfx::PointF(),
310 gfx::Size(10, 12),
311 false);
312 ExecuteCalculateDrawProperties(root.get());
313 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
314 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
315 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14316
[email protected]fb661802013-03-25 01:59:32317 // Case 3: The anchor point by itself (without a layer transform) should have
318 // no effect on the transforms.
319 SetLayerPropertiesForTesting(layer.get(),
320 identity_matrix,
321 identity_matrix,
322 gfx::PointF(0.25f, 0.25f),
323 gfx::PointF(),
324 gfx::Size(10, 12),
325 false);
326 ExecuteCalculateDrawProperties(root.get());
327 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
328 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
329 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14330
[email protected]fb661802013-03-25 01:59:32331 // Case 4: A change in actual position affects both the draw transform and
332 // screen space transform.
333 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05334 position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32335 SetLayerPropertiesForTesting(layer.get(),
336 identity_matrix,
337 identity_matrix,
338 gfx::PointF(0.25f, 0.25f),
339 gfx::PointF(0.f, 1.2f),
340 gfx::Size(10, 12),
341 false);
342 ExecuteCalculateDrawProperties(root.get());
343 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
344 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
345 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14346
[email protected]fb661802013-03-25 01:59:32347 // Case 5: In the correct sequence of transforms, the layer transform should
348 // pre-multiply the translation_to_center. This is easily tested by using a
349 // scale transform, because scale and translation are not commutative.
350 gfx::Transform layer_transform;
351 layer_transform.Scale3d(2.0, 2.0, 1.0);
352 SetLayerPropertiesForTesting(layer.get(),
353 layer_transform,
354 identity_matrix,
355 gfx::PointF(),
356 gfx::PointF(),
357 gfx::Size(10, 12),
358 false);
359 ExecuteCalculateDrawProperties(root.get());
360 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
361 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
362 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14363
[email protected]fb661802013-03-25 01:59:32364 // Case 6: The layer transform should occur with respect to the anchor point.
365 gfx::Transform translation_to_anchor;
366 translation_to_anchor.Translate(5.0, 0.0);
367 gfx::Transform expected_result =
368 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
369 SetLayerPropertiesForTesting(layer.get(),
370 layer_transform,
371 identity_matrix,
372 gfx::PointF(0.5f, 0.f),
373 gfx::PointF(),
374 gfx::Size(10, 12),
375 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
[email protected]fb661802013-03-25 01:59:32381 // Case 7: Verify that position pre-multiplies the layer transform. The
382 // current implementation of CalculateDrawProperties does this implicitly, but
383 // it is still worth testing to detect accidental regressions.
384 expected_result = position_transform * translation_to_anchor *
385 layer_transform * Inverse(translation_to_anchor);
386 SetLayerPropertiesForTesting(layer.get(),
387 layer_transform,
388 identity_matrix,
389 gfx::PointF(0.5f, 0.f),
390 gfx::PointF(0.f, 1.2f),
391 gfx::Size(10, 12),
392 false);
393 ExecuteCalculateDrawProperties(root.get());
394 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
395 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
396 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14397}
398
[email protected]989386c2013-07-18 21:37:23399TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
[email protected]fb661802013-03-25 01:59:32400 const gfx::Vector2d kScrollOffset(50, 100);
401 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01402 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32403 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
404 -kScrollOffset.y());
405 const float kPageScale = 0.888f;
406 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20407
[email protected]fb661802013-03-25 01:59:32408 FakeImplProxy proxy;
409 FakeLayerTreeHostImpl host_impl(&proxy);
[email protected]657b24c2013-03-06 09:01:20410
[email protected]fb661802013-03-25 01:59:32411 gfx::Transform identity_matrix;
412 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
413 LayerImpl::Create(host_impl.active_tree(), 1));
414 LayerImpl* sublayer = sublayer_scoped_ptr.get();
415 sublayer->SetContentsScale(kPageScale * kDeviceScale,
416 kPageScale * kDeviceScale);
417 SetLayerPropertiesForTesting(sublayer,
418 identity_matrix,
419 identity_matrix,
420 gfx::Point(),
421 gfx::PointF(),
422 gfx::Size(500, 500),
423 false);
[email protected]657b24c2013-03-06 09:01:20424
[email protected]adeda572014-01-31 00:49:47425 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32426 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47427 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
[email protected]fb661802013-03-25 01:59:32428 SetLayerPropertiesForTesting(scroll_layer,
429 identity_matrix,
430 identity_matrix,
431 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47432 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32433 gfx::Size(10, 20),
434 false);
[email protected]adeda572014-01-31 00:49:47435
436 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
437 LayerImpl::Create(host_impl.active_tree(), 4));
438 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
439
440 scroll_layer->SetScrollClipLayer(clip_layer->id());
441 clip_layer->SetBounds(
442 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
443 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
444 scroll_layer->SetScrollClipLayer(clip_layer->id());
[email protected]fb661802013-03-25 01:59:32445 scroll_layer->SetScrollDelta(kScrollDelta);
446 gfx::Transform impl_transform;
[email protected]fb661802013-03-25 01:59:32447 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
[email protected]adeda572014-01-31 00:49:47448 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
449 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
450 scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20451
[email protected]fb661802013-03-25 01:59:32452 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
453 SetLayerPropertiesForTesting(root.get(),
454 identity_matrix,
455 identity_matrix,
456 gfx::PointF(),
457 gfx::PointF(),
458 gfx::Size(3, 4),
459 false);
[email protected]adeda572014-01-31 00:49:47460 root->AddChild(clip_layer_scoped_ptr.Pass());
[email protected]657b24c2013-03-06 09:01:20461
[email protected]f2136262013-04-26 21:10:19462 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32463 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32464 gfx::Transform expected_transform = identity_matrix;
465 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
466 sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
467 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
468 MathUtil::Round(sub_layer_screen_position.y()));
469 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
470 sublayer->draw_transform());
471 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
472 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20473
[email protected]fb661802013-03-25 01:59:32474 gfx::Transform arbitrary_translate;
475 const float kTranslateX = 10.6f;
476 const float kTranslateY = 20.6f;
477 arbitrary_translate.Translate(kTranslateX, kTranslateY);
478 SetLayerPropertiesForTesting(scroll_layer,
479 arbitrary_translate,
480 identity_matrix,
481 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47482 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32483 gfx::Size(10, 20),
484 false);
[email protected]f2136262013-04-26 21:10:19485 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32486 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32487 expected_transform.MakeIdentity();
488 expected_transform.Translate(
489 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
490 sub_layer_screen_position.x()),
491 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
492 sub_layer_screen_position.y()));
493 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
494 sublayer->draw_transform());
[email protected]657b24c2013-03-06 09:01:20495}
496
[email protected]989386c2013-07-18 21:37:23497TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32498 gfx::Transform identity_matrix;
499 scoped_refptr<Layer> root = Layer::Create();
500 scoped_refptr<Layer> parent = Layer::Create();
501 scoped_refptr<Layer> child = Layer::Create();
502 scoped_refptr<Layer> grand_child = Layer::Create();
503 root->AddChild(parent);
504 parent->AddChild(child);
505 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14506
[email protected]d600df7d2013-08-03 02:34:28507 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
508 host->SetRootLayer(root);
509
[email protected]fb661802013-03-25 01:59:32510 // One-time setup of root layer
511 SetLayerPropertiesForTesting(root.get(),
512 identity_matrix,
513 identity_matrix,
514 gfx::PointF(),
515 gfx::PointF(),
516 gfx::Size(1, 2),
517 false);
[email protected]ecc12622012-10-30 20:45:42518
[email protected]fb661802013-03-25 01:59:32519 // Case 1: parent's anchor point should not affect child or grand_child.
520 SetLayerPropertiesForTesting(parent.get(),
521 identity_matrix,
522 identity_matrix,
523 gfx::PointF(0.25f, 0.25f),
524 gfx::PointF(),
525 gfx::Size(10, 12),
526 false);
527 SetLayerPropertiesForTesting(child.get(),
528 identity_matrix,
529 identity_matrix,
530 gfx::PointF(),
531 gfx::PointF(),
532 gfx::Size(16, 18),
533 false);
534 SetLayerPropertiesForTesting(grand_child.get(),
535 identity_matrix,
536 identity_matrix,
537 gfx::PointF(),
538 gfx::PointF(),
539 gfx::Size(76, 78),
540 false);
541 ExecuteCalculateDrawProperties(root.get());
542 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
543 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
544 child->screen_space_transform());
545 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
546 grand_child->draw_transform());
547 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
548 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14549
[email protected]fb661802013-03-25 01:59:32550 // Case 2: parent's position affects child and grand_child.
551 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05552 parent_position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32553 SetLayerPropertiesForTesting(parent.get(),
554 identity_matrix,
555 identity_matrix,
556 gfx::PointF(0.25f, 0.25f),
557 gfx::PointF(0.f, 1.2f),
558 gfx::Size(10, 12),
559 false);
560 SetLayerPropertiesForTesting(child.get(),
561 identity_matrix,
562 identity_matrix,
563 gfx::PointF(),
564 gfx::PointF(),
565 gfx::Size(16, 18),
566 false);
567 SetLayerPropertiesForTesting(grand_child.get(),
568 identity_matrix,
569 identity_matrix,
570 gfx::PointF(),
571 gfx::PointF(),
572 gfx::Size(76, 78),
573 false);
574 ExecuteCalculateDrawProperties(root.get());
575 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
576 child->draw_transform());
577 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
578 child->screen_space_transform());
579 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
580 grand_child->draw_transform());
581 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
582 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14583
[email protected]fb661802013-03-25 01:59:32584 // Case 3: parent's local transform affects child and grandchild
585 gfx::Transform parent_layer_transform;
586 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
587 gfx::Transform parent_translation_to_anchor;
588 parent_translation_to_anchor.Translate(2.5, 3.0);
589 gfx::Transform parent_composite_transform =
590 parent_translation_to_anchor * parent_layer_transform *
591 Inverse(parent_translation_to_anchor);
592 SetLayerPropertiesForTesting(parent.get(),
593 parent_layer_transform,
594 identity_matrix,
595 gfx::PointF(0.25f, 0.25f),
596 gfx::PointF(),
597 gfx::Size(10, 12),
598 false);
599 SetLayerPropertiesForTesting(child.get(),
600 identity_matrix,
601 identity_matrix,
602 gfx::PointF(),
603 gfx::PointF(),
604 gfx::Size(16, 18),
605 false);
606 SetLayerPropertiesForTesting(grand_child.get(),
607 identity_matrix,
608 identity_matrix,
609 gfx::PointF(),
610 gfx::PointF(),
611 gfx::Size(76, 78),
612 false);
613 ExecuteCalculateDrawProperties(root.get());
614 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
615 child->draw_transform());
616 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
617 child->screen_space_transform());
618 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
619 grand_child->draw_transform());
620 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
621 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14622
[email protected]fb661802013-03-25 01:59:32623 // Case 4: parent's sublayer matrix affects child and grandchild scaling is
624 // used here again so that the correct sequence of transforms is properly
625 // tested. Note that preserves3d is false, but the sublayer matrix should
626 // retain its 3D properties when given to child. But then, the child also
627 // does not preserve3D. When it gives its hierarchy to the grand_child, it
628 // should be flattened to 2D.
629 gfx::Transform parent_sublayer_matrix;
[email protected]6138db702013-09-25 03:25:05630 parent_sublayer_matrix.Scale3d(10.f, 10.f, 3.3f);
[email protected]fb661802013-03-25 01:59:32631 // Sublayer matrix is applied to the anchor point of the parent layer.
632 parent_composite_transform =
633 parent_translation_to_anchor * parent_layer_transform *
634 Inverse(parent_translation_to_anchor) * parent_translation_to_anchor *
635 parent_sublayer_matrix * Inverse(parent_translation_to_anchor);
636 gfx::Transform flattened_composite_transform = parent_composite_transform;
637 flattened_composite_transform.FlattenTo2d();
638 SetLayerPropertiesForTesting(parent.get(),
639 parent_layer_transform,
640 parent_sublayer_matrix,
641 gfx::PointF(0.25f, 0.25f),
642 gfx::PointF(),
643 gfx::Size(10, 12),
644 false);
645 SetLayerPropertiesForTesting(child.get(),
646 identity_matrix,
647 identity_matrix,
648 gfx::PointF(),
649 gfx::PointF(),
650 gfx::Size(16, 18),
651 false);
652 SetLayerPropertiesForTesting(grand_child.get(),
653 identity_matrix,
654 identity_matrix,
655 gfx::PointF(),
656 gfx::PointF(),
657 gfx::Size(76, 78),
658 false);
659 ExecuteCalculateDrawProperties(root.get());
660 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
661 child->draw_transform());
662 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
663 child->screen_space_transform());
664 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_composite_transform,
665 grand_child->draw_transform());
666 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_composite_transform,
667 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14668
[email protected]fb661802013-03-25 01:59:32669 // Case 5: same as Case 4, except that child does preserve 3D, so the
670 // grand_child should receive the non-flattened composite transform.
671 SetLayerPropertiesForTesting(parent.get(),
672 parent_layer_transform,
673 parent_sublayer_matrix,
674 gfx::PointF(0.25f, 0.25f),
675 gfx::PointF(),
676 gfx::Size(10, 12),
677 false);
678 SetLayerPropertiesForTesting(child.get(),
679 identity_matrix,
680 identity_matrix,
681 gfx::PointF(),
682 gfx::PointF(),
683 gfx::Size(16, 18),
684 true);
685 SetLayerPropertiesForTesting(grand_child.get(),
686 identity_matrix,
687 identity_matrix,
688 gfx::PointF(),
689 gfx::PointF(),
690 gfx::Size(76, 78),
691 false);
692 ExecuteCalculateDrawProperties(root.get());
693 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
694 child->draw_transform());
695 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
696 child->screen_space_transform());
697 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
698 grand_child->draw_transform());
699 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
700 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14701}
702
[email protected]989386c2013-07-18 21:37:23703TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
[email protected]fb661802013-03-25 01:59:32704 scoped_refptr<Layer> root = Layer::Create();
705 scoped_refptr<Layer> parent = Layer::Create();
706 scoped_refptr<Layer> child = 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);
[email protected]94f206c12012-08-25 00:09:14712
[email protected]d600df7d2013-08-03 02:34:28713 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
714 host->SetRootLayer(root);
715
[email protected]fb661802013-03-25 01:59:32716 // One-time setup of root layer
717 gfx::Transform identity_matrix;
718 SetLayerPropertiesForTesting(root.get(),
719 identity_matrix,
720 identity_matrix,
721 gfx::PointF(),
722 gfx::PointF(),
723 gfx::Size(1, 2),
724 false);
[email protected]ecc12622012-10-30 20:45:42725
[email protected]fb661802013-03-25 01:59:32726 // Child is set up so that a new render surface should be created.
727 child->SetOpacity(0.5f);
728 child->SetForceRenderSurface(true);
[email protected]94f206c12012-08-25 00:09:14729
[email protected]fb661802013-03-25 01:59:32730 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05731 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32732 gfx::Transform parent_translation_to_anchor;
733 parent_translation_to_anchor.Translate(25.0, 30.0);
734 gfx::Transform parent_sublayer_matrix;
[email protected]6138db702013-09-25 03:25:05735 parent_sublayer_matrix.Scale3d(0.9f, 1.f, 3.3f);
[email protected]aedf4e52013-01-09 23:24:44736
[email protected]fb661802013-03-25 01:59:32737 gfx::Transform parent_composite_transform =
738 parent_translation_to_anchor * parent_layer_transform *
739 Inverse(parent_translation_to_anchor) * parent_translation_to_anchor *
740 parent_sublayer_matrix * Inverse(parent_translation_to_anchor);
741 gfx::Vector2dF parent_composite_scale =
742 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
743 1.f);
744 gfx::Transform surface_sublayer_transform;
745 surface_sublayer_transform.Scale(parent_composite_scale.x(),
746 parent_composite_scale.y());
747 gfx::Transform surface_sublayer_composite_transform =
748 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14749
[email protected]fb661802013-03-25 01:59:32750 // Child's render surface should not exist yet.
751 ASSERT_FALSE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:14752
[email protected]fb661802013-03-25 01:59:32753 SetLayerPropertiesForTesting(parent.get(),
754 parent_layer_transform,
755 parent_sublayer_matrix,
756 gfx::PointF(0.25f, 0.25f),
757 gfx::PointF(),
758 gfx::Size(100, 120),
759 false);
760 SetLayerPropertiesForTesting(child.get(),
761 identity_matrix,
762 identity_matrix,
763 gfx::PointF(),
764 gfx::PointF(),
765 gfx::Size(16, 18),
766 false);
767 SetLayerPropertiesForTesting(grand_child.get(),
768 identity_matrix,
769 identity_matrix,
770 gfx::PointF(),
771 gfx::PointF(),
772 gfx::Size(8, 10),
773 false);
774 ExecuteCalculateDrawProperties(root.get());
[email protected]94f206c12012-08-25 00:09:14775
[email protected]fb661802013-03-25 01:59:32776 // Render surface should have been created now.
777 ASSERT_TRUE(child->render_surface());
778 ASSERT_EQ(child, child->render_target());
[email protected]94f206c12012-08-25 00:09:14779
[email protected]fb661802013-03-25 01:59:32780 // The child layer's draw transform should refer to its new render surface.
781 // The screen-space transform, however, should still refer to the root.
782 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
783 child->draw_transform());
784 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
785 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14786
[email protected]fb661802013-03-25 01:59:32787 // Because the grand_child is the only drawable content, the child's render
788 // surface will tighten its bounds to the grand_child. The scale at which the
789 // surface's subtree is drawn must be removed from the composite transform.
790 EXPECT_TRANSFORMATION_MATRIX_EQ(
791 surface_sublayer_composite_transform,
792 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14793
[email protected]fb661802013-03-25 01:59:32794 // The screen space is the same as the target since the child surface draws
795 // into the root.
796 EXPECT_TRANSFORMATION_MATRIX_EQ(
797 surface_sublayer_composite_transform,
798 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14799}
800
[email protected]989386c2013-07-18 21:37:23801TEST_F(LayerTreeHostCommonTest, SublayerTransformWithAnchorPoint) {
[email protected]fb661802013-03-25 01:59:32802 // crbug.com/157961 - we were always applying the sublayer transform about
803 // the center of the layer, rather than the anchor point.
[email protected]9a3e6b72013-02-12 18:31:21804
[email protected]fb661802013-03-25 01:59:32805 scoped_refptr<Layer> root = Layer::Create();
806 scoped_refptr<Layer> parent = Layer::Create();
807 scoped_refptr<LayerWithForcedDrawsContent> child =
808 make_scoped_refptr(new LayerWithForcedDrawsContent());
809 root->AddChild(parent);
810 parent->AddChild(child);
[email protected]9a3e6b72013-02-12 18:31:21811
[email protected]d600df7d2013-08-03 02:34:28812 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
813 host->SetRootLayer(root);
814
[email protected]fb661802013-03-25 01:59:32815 gfx::Transform identity_matrix;
816 gfx::Transform parent_sublayer_matrix;
817 parent_sublayer_matrix.ApplyPerspectiveDepth(2.0);
818 gfx::PointF parent_anchor_point(0.2f, 0.8f);
[email protected]9a3e6b72013-02-12 18:31:21819
[email protected]fb661802013-03-25 01:59:32820 SetLayerPropertiesForTesting(root.get(),
821 identity_matrix,
822 identity_matrix,
823 gfx::PointF(),
824 gfx::PointF(),
825 gfx::Size(1, 2),
826 false);
827 SetLayerPropertiesForTesting(parent.get(),
828 identity_matrix,
829 parent_sublayer_matrix,
830 parent_anchor_point,
831 gfx::PointF(),
832 gfx::Size(100, 100),
833 false);
834 SetLayerPropertiesForTesting(child.get(),
835 identity_matrix,
836 identity_matrix,
837 gfx::PointF(),
838 gfx::PointF(),
839 gfx::Size(10, 10),
840 false);
841 ExecuteCalculateDrawProperties(root.get());
[email protected]9a3e6b72013-02-12 18:31:21842
[email protected]fb661802013-03-25 01:59:32843 gfx::Transform expected_child_draw_transform;
844 expected_child_draw_transform.Translate(20.0, 80.0);
845 expected_child_draw_transform.ApplyPerspectiveDepth(2.0);
846 expected_child_draw_transform.Translate(-20.0, -80.0);
847 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
848 child->draw_transform());
[email protected]9a3e6b72013-02-12 18:31:21849}
850
[email protected]989386c2013-07-18 21:37:23851TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
[email protected]fb661802013-03-25 01:59:32852 scoped_refptr<Layer> root = Layer::Create();
853 scoped_refptr<Layer> parent = Layer::Create();
854 scoped_refptr<Layer> child = Layer::Create();
855 scoped_refptr<Layer> child_replica = Layer::Create();
856 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
857 make_scoped_refptr(new LayerWithForcedDrawsContent());
858 root->AddChild(parent);
859 parent->AddChild(child);
860 child->AddChild(grand_child);
861 child->SetReplicaLayer(child_replica.get());
862
[email protected]d600df7d2013-08-03 02:34:28863 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
864 host->SetRootLayer(root);
865
[email protected]fb661802013-03-25 01:59:32866 // One-time setup of root layer
867 gfx::Transform identity_matrix;
868 SetLayerPropertiesForTesting(root.get(),
869 identity_matrix,
870 identity_matrix,
871 gfx::PointF(),
872 gfx::PointF(),
873 gfx::Size(1, 2),
874 false);
875
876 // Child is set up so that a new render surface should be created.
877 child->SetOpacity(0.5f);
878
879 gfx::Transform parent_layer_transform;
880 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
881 gfx::Transform parent_translation_to_anchor;
882 parent_translation_to_anchor.Translate(2.5, 3.0);
883 gfx::Transform parent_sublayer_matrix;
[email protected]6138db702013-09-25 03:25:05884 parent_sublayer_matrix.Scale3d(10.f, 10.f, 3.3f);
[email protected]fb661802013-03-25 01:59:32885 gfx::Transform parent_composite_transform =
886 parent_translation_to_anchor * parent_layer_transform *
887 Inverse(parent_translation_to_anchor) * parent_translation_to_anchor *
888 parent_sublayer_matrix * Inverse(parent_translation_to_anchor);
889 gfx::Transform replica_layer_transform;
890 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
891 gfx::Vector2dF parent_composite_scale =
892 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
893 1.f);
894 gfx::Transform surface_sublayer_transform;
895 surface_sublayer_transform.Scale(parent_composite_scale.x(),
896 parent_composite_scale.y());
897 gfx::Transform replica_composite_transform =
898 parent_composite_transform * replica_layer_transform *
899 Inverse(surface_sublayer_transform);
900
901 // Child's render surface should not exist yet.
902 ASSERT_FALSE(child->render_surface());
903
904 SetLayerPropertiesForTesting(parent.get(),
905 parent_layer_transform,
906 parent_sublayer_matrix,
907 gfx::PointF(0.25f, 0.25f),
908 gfx::PointF(),
909 gfx::Size(10, 12),
910 false);
911 SetLayerPropertiesForTesting(child.get(),
912 identity_matrix,
913 identity_matrix,
914 gfx::PointF(),
915 gfx::PointF(),
916 gfx::Size(16, 18),
917 false);
918 SetLayerPropertiesForTesting(grand_child.get(),
919 identity_matrix,
920 identity_matrix,
921 gfx::PointF(),
922 gfx::PointF(-0.5f, -0.5f),
923 gfx::Size(1, 1),
924 false);
925 SetLayerPropertiesForTesting(child_replica.get(),
926 replica_layer_transform,
927 identity_matrix,
928 gfx::PointF(),
929 gfx::PointF(),
930 gfx::Size(),
931 false);
932 ExecuteCalculateDrawProperties(root.get());
933
934 // Render surface should have been created now.
935 ASSERT_TRUE(child->render_surface());
936 ASSERT_EQ(child, child->render_target());
937
938 EXPECT_TRANSFORMATION_MATRIX_EQ(
939 replica_composite_transform,
940 child->render_target()->render_surface()->replica_draw_transform());
941 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
942 child->render_target()->render_surface()
943 ->replica_screen_space_transform());
944}
945
[email protected]989386c2013-07-18 21:37:23946TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32947 // This test creates a more complex tree and verifies it all at once. This
948 // covers the following cases:
949 // - layers that are described w.r.t. a render surface: should have draw
950 // transforms described w.r.t. that surface
951 // - A render surface described w.r.t. an ancestor render surface: should
952 // have a draw transform described w.r.t. that ancestor surface
953 // - Replicas of a render surface are described w.r.t. the replica's
954 // transform around its anchor, along with the surface itself.
955 // - Sanity check on recursion: verify transforms of layers described w.r.t.
956 // a render surface that is described w.r.t. an ancestor render surface.
957 // - verifying that each layer has a reference to the correct render surface
958 // and render target values.
959
960 scoped_refptr<Layer> root = Layer::Create();
961 scoped_refptr<Layer> parent = Layer::Create();
962 scoped_refptr<Layer> render_surface1 = Layer::Create();
963 scoped_refptr<Layer> render_surface2 = Layer::Create();
964 scoped_refptr<Layer> child_of_root = Layer::Create();
965 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
966 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
967 scoped_refptr<Layer> replica_of_rs1 = Layer::Create();
968 scoped_refptr<Layer> replica_of_rs2 = Layer::Create();
969 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
970 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
971 make_scoped_refptr(new LayerWithForcedDrawsContent());
972 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
973 make_scoped_refptr(new LayerWithForcedDrawsContent());
974 root->AddChild(parent);
975 parent->AddChild(render_surface1);
976 parent->AddChild(child_of_root);
977 render_surface1->AddChild(child_of_rs1);
978 render_surface1->AddChild(render_surface2);
979 render_surface2->AddChild(child_of_rs2);
980 child_of_root->AddChild(grand_child_of_root);
981 child_of_rs1->AddChild(grand_child_of_rs1);
982 child_of_rs2->AddChild(grand_child_of_rs2);
983 render_surface1->SetReplicaLayer(replica_of_rs1.get());
984 render_surface2->SetReplicaLayer(replica_of_rs2.get());
985
[email protected]d600df7d2013-08-03 02:34:28986 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
987 host->SetRootLayer(root);
988
[email protected]fb661802013-03-25 01:59:32989 // In combination with descendant draws content, opacity != 1 forces the layer
990 // to have a new render surface.
991 render_surface1->SetOpacity(0.5f);
992 render_surface2->SetOpacity(0.33f);
993
994 // One-time setup of root layer
995 gfx::Transform identity_matrix;
996 SetLayerPropertiesForTesting(root.get(),
997 identity_matrix,
998 identity_matrix,
999 gfx::PointF(),
1000 gfx::PointF(),
1001 gfx::Size(1, 2),
1002 false);
1003
1004 // All layers in the tree are initialized with an anchor at .25 and a size of
1005 // (10,10). matrix "A" is the composite layer transform used in all layers,
1006 // centered about the anchor point. matrix "B" is the sublayer transform used
1007 // in all layers, centered about the center position of the layer. matrix "R"
1008 // is the composite replica transform used in all replica layers.
1009 //
1010 // x component tests that layer_transform and sublayer_transform are done in
1011 // the right order (translation and scale are noncommutative). y component
1012 // has a translation by 1 for every ancestor, which indicates the "depth" of
1013 // the layer in the hierarchy.
1014 gfx::Transform translation_to_anchor;
1015 translation_to_anchor.Translate(2.5, 0.0);
1016 gfx::Transform layer_transform;
1017 layer_transform.Translate(1.0, 1.0);
1018 gfx::Transform sublayer_transform;
1019 sublayer_transform.Scale3d(10.0, 1.0, 1.0);
1020 gfx::Transform replica_layer_transform;
1021 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
1022
1023 gfx::Transform A =
1024 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
1025 gfx::Transform B = translation_to_anchor * sublayer_transform *
1026 Inverse(translation_to_anchor);
1027 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
1028 Inverse(translation_to_anchor);
1029
1030 gfx::Vector2dF surface1_parent_transform_scale =
1031 MathUtil::ComputeTransform2dScaleComponents(A * B, 1.f);
1032 gfx::Transform surface1_sublayer_transform;
1033 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
1034 surface1_parent_transform_scale.y());
1035
1036 // SS1 = transform given to the subtree of render_surface1
1037 gfx::Transform SS1 = surface1_sublayer_transform;
1038 // S1 = transform to move from render_surface1 pixels to the layer space of
1039 // the owning layer
1040 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
1041
1042 gfx::Vector2dF surface2_parent_transform_scale =
1043 MathUtil::ComputeTransform2dScaleComponents(SS1 * A * B, 1.f);
1044 gfx::Transform surface2_sublayer_transform;
1045 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
1046 surface2_parent_transform_scale.y());
1047
1048 // SS2 = transform given to the subtree of render_surface2
1049 gfx::Transform SS2 = surface2_sublayer_transform;
1050 // S2 = transform to move from render_surface2 pixels to the layer space of
1051 // the owning layer
1052 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
1053
1054 SetLayerPropertiesForTesting(parent.get(),
1055 layer_transform,
1056 sublayer_transform,
1057 gfx::PointF(0.25f, 0.f),
1058 gfx::PointF(),
1059 gfx::Size(10, 10),
1060 false);
1061 SetLayerPropertiesForTesting(render_surface1.get(),
1062 layer_transform,
1063 sublayer_transform,
1064 gfx::PointF(0.25f, 0.f),
1065 gfx::PointF(),
1066 gfx::Size(10, 10),
1067 false);
1068 SetLayerPropertiesForTesting(render_surface2.get(),
1069 layer_transform,
1070 sublayer_transform,
1071 gfx::PointF(0.25f, 0.f),
1072 gfx::PointF(),
1073 gfx::Size(10, 10),
1074 false);
1075 SetLayerPropertiesForTesting(child_of_root.get(),
1076 layer_transform,
1077 sublayer_transform,
1078 gfx::PointF(0.25f, 0.f),
1079 gfx::PointF(),
1080 gfx::Size(10, 10),
1081 false);
1082 SetLayerPropertiesForTesting(child_of_rs1.get(),
1083 layer_transform,
1084 sublayer_transform,
1085 gfx::PointF(0.25f, 0.f),
1086 gfx::PointF(),
1087 gfx::Size(10, 10),
1088 false);
1089 SetLayerPropertiesForTesting(child_of_rs2.get(),
1090 layer_transform,
1091 sublayer_transform,
1092 gfx::PointF(0.25f, 0.f),
1093 gfx::PointF(),
1094 gfx::Size(10, 10),
1095 false);
1096 SetLayerPropertiesForTesting(grand_child_of_root.get(),
1097 layer_transform,
1098 sublayer_transform,
1099 gfx::PointF(0.25f, 0.f),
1100 gfx::PointF(),
1101 gfx::Size(10, 10),
1102 false);
1103 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
1104 layer_transform,
1105 sublayer_transform,
1106 gfx::PointF(0.25f, 0.f),
1107 gfx::PointF(),
1108 gfx::Size(10, 10),
1109 false);
1110 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
1111 layer_transform,
1112 sublayer_transform,
1113 gfx::PointF(0.25f, 0.f),
1114 gfx::PointF(),
1115 gfx::Size(10, 10),
1116 false);
1117 SetLayerPropertiesForTesting(replica_of_rs1.get(),
1118 replica_layer_transform,
1119 sublayer_transform,
1120 gfx::PointF(0.25f, 0.f),
1121 gfx::PointF(),
1122 gfx::Size(),
1123 false);
1124 SetLayerPropertiesForTesting(replica_of_rs2.get(),
1125 replica_layer_transform,
1126 sublayer_transform,
1127 gfx::PointF(0.25f, 0.f),
1128 gfx::PointF(),
1129 gfx::Size(),
1130 false);
1131
1132 ExecuteCalculateDrawProperties(root.get());
1133
1134 // Only layers that are associated with render surfaces should have an actual
1135 // RenderSurface() value.
1136 ASSERT_TRUE(root->render_surface());
1137 ASSERT_FALSE(child_of_root->render_surface());
1138 ASSERT_FALSE(grand_child_of_root->render_surface());
1139
1140 ASSERT_TRUE(render_surface1->render_surface());
1141 ASSERT_FALSE(child_of_rs1->render_surface());
1142 ASSERT_FALSE(grand_child_of_rs1->render_surface());
1143
1144 ASSERT_TRUE(render_surface2->render_surface());
1145 ASSERT_FALSE(child_of_rs2->render_surface());
1146 ASSERT_FALSE(grand_child_of_rs2->render_surface());
1147
1148 // Verify all render target accessors
1149 EXPECT_EQ(root, parent->render_target());
1150 EXPECT_EQ(root, child_of_root->render_target());
1151 EXPECT_EQ(root, grand_child_of_root->render_target());
1152
1153 EXPECT_EQ(render_surface1, render_surface1->render_target());
1154 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
1155 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
1156
1157 EXPECT_EQ(render_surface2, render_surface2->render_target());
1158 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
1159 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
1160
1161 // Verify layer draw transforms note that draw transforms are described with
1162 // respect to the nearest ancestor render surface but screen space transforms
1163 // are described with respect to the root.
1164 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
1165 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, child_of_root->draw_transform());
1166 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A,
1167 grand_child_of_root->draw_transform());
1168
1169 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
1170 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A, child_of_rs1->draw_transform());
1171 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A * B * A,
1172 grand_child_of_rs1->draw_transform());
1173
1174 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
1175 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * B * A, child_of_rs2->draw_transform());
1176 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * B * A * B * A,
1177 grand_child_of_rs2->draw_transform());
1178
1179 // Verify layer screen-space transforms
1180 //
1181 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
1182 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A,
1183 child_of_root->screen_space_transform());
1184 EXPECT_TRANSFORMATION_MATRIX_EQ(
1185 A * B * A * B * A, grand_child_of_root->screen_space_transform());
1186
1187 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A,
1188 render_surface1->screen_space_transform());
1189 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A,
1190 child_of_rs1->screen_space_transform());
1191 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A,
1192 grand_child_of_rs1->screen_space_transform());
1193
1194 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A,
1195 render_surface2->screen_space_transform());
1196 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A,
1197 child_of_rs2->screen_space_transform());
1198 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A * B * A,
1199 grand_child_of_rs2->screen_space_transform());
1200
1201 // Verify render surface transforms.
1202 //
1203 // Draw transform of render surface 1 is described with respect to root.
1204 EXPECT_TRANSFORMATION_MATRIX_EQ(
1205 A * B * A * S1, render_surface1->render_surface()->draw_transform());
1206 EXPECT_TRANSFORMATION_MATRIX_EQ(
1207 A * B * R * S1,
1208 render_surface1->render_surface()->replica_draw_transform());
1209 EXPECT_TRANSFORMATION_MATRIX_EQ(
1210 A * B * A * S1,
1211 render_surface1->render_surface()->screen_space_transform());
1212 EXPECT_TRANSFORMATION_MATRIX_EQ(
1213 A * B * R * S1,
1214 render_surface1->render_surface()->replica_screen_space_transform());
1215 // Draw transform of render surface 2 is described with respect to render
1216 // surface 1.
1217 EXPECT_TRANSFORMATION_MATRIX_EQ(
1218 SS1 * B * A * S2, render_surface2->render_surface()->draw_transform());
1219 EXPECT_TRANSFORMATION_MATRIX_EQ(
1220 SS1 * B * R * S2,
1221 render_surface2->render_surface()->replica_draw_transform());
1222 EXPECT_TRANSFORMATION_MATRIX_EQ(
1223 A * B * A * B * A * S2,
1224 render_surface2->render_surface()->screen_space_transform());
1225 EXPECT_TRANSFORMATION_MATRIX_EQ(
1226 A * B * A * B * R * S2,
1227 render_surface2->render_surface()->replica_screen_space_transform());
1228
1229 // Sanity check. If these fail there is probably a bug in the test itself. It
1230 // is expected that we correctly set up transforms so that the y-component of
1231 // the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:261232 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
1233 EXPECT_FLOAT_EQ(2.0,
1234 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321235 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261236 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321237
[email protected]803f6b52013-09-12 00:51:261238 EXPECT_FLOAT_EQ(2.0,
1239 render_surface1->screen_space_transform().matrix().get(1, 3));
1240 EXPECT_FLOAT_EQ(3.0,
1241 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321242 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261243 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321244
[email protected]803f6b52013-09-12 00:51:261245 EXPECT_FLOAT_EQ(3.0,
1246 render_surface2->screen_space_transform().matrix().get(1, 3));
1247 EXPECT_FLOAT_EQ(4.0,
1248 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321249 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261250 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321251}
1252
[email protected]989386c2013-07-18 21:37:231253TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321254 // For layers that flatten their subtree, there should be an orthographic
1255 // projection (for x and y values) in the middle of the transform sequence.
1256 // Note that the way the code is currently implemented, it is not expected to
1257 // use a canonical orthographic projection.
1258
1259 scoped_refptr<Layer> root = Layer::Create();
1260 scoped_refptr<Layer> child = Layer::Create();
1261 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1262 make_scoped_refptr(new LayerWithForcedDrawsContent());
1263
1264 gfx::Transform rotation_about_y_axis;
1265 rotation_about_y_axis.RotateAboutYAxis(30.0);
1266
1267 const gfx::Transform identity_matrix;
1268 SetLayerPropertiesForTesting(root.get(),
1269 identity_matrix,
1270 identity_matrix,
1271 gfx::PointF(),
1272 gfx::PointF(),
1273 gfx::Size(100, 100),
1274 false);
1275 SetLayerPropertiesForTesting(child.get(),
1276 rotation_about_y_axis,
1277 identity_matrix,
1278 gfx::PointF(),
1279 gfx::PointF(),
1280 gfx::Size(10, 10),
1281 false);
1282 SetLayerPropertiesForTesting(grand_child.get(),
1283 rotation_about_y_axis,
1284 identity_matrix,
1285 gfx::PointF(),
1286 gfx::PointF(),
1287 gfx::Size(10, 10),
1288 false);
1289
1290 root->AddChild(child);
1291 child->AddChild(grand_child);
1292 child->SetForceRenderSurface(true);
1293
[email protected]d600df7d2013-08-03 02:34:281294 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1295 host->SetRootLayer(root);
1296
[email protected]fb661802013-03-25 01:59:321297 // No layers in this test should preserve 3d.
1298 ASSERT_FALSE(root->preserves_3d());
1299 ASSERT_FALSE(child->preserves_3d());
1300 ASSERT_FALSE(grand_child->preserves_3d());
1301
1302 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1303 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1304 gfx::Transform expected_grand_child_draw_transform =
1305 rotation_about_y_axis; // draws onto child's render surface
1306 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1307 flattened_rotation_about_y.FlattenTo2d();
1308 gfx::Transform expected_grand_child_screen_space_transform =
1309 flattened_rotation_about_y * rotation_about_y_axis;
1310
1311 ExecuteCalculateDrawProperties(root.get());
1312
1313 // The child's draw transform should have been taken by its surface.
1314 ASSERT_TRUE(child->render_surface());
1315 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1316 child->render_surface()->draw_transform());
1317 EXPECT_TRANSFORMATION_MATRIX_EQ(
1318 expected_child_screen_space_transform,
1319 child->render_surface()->screen_space_transform());
1320 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1321 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1322 child->screen_space_transform());
1323 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1324 grand_child->draw_transform());
1325 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1326 grand_child->screen_space_transform());
1327}
1328
[email protected]989386c2013-07-18 21:37:231329TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321330 // A layer that is empty in one axis, but not the other, was accidentally
1331 // skipping a necessary translation. Without that translation, the coordinate
1332 // space of the layer's draw transform is incorrect.
1333 //
1334 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1335 // but if that layer becomes a render surface, then its draw transform is
1336 // implicitly inherited by the rest of the subtree, which then is positioned
1337 // incorrectly as a result.
1338
1339 scoped_refptr<Layer> root = Layer::Create();
1340 scoped_refptr<Layer> child = Layer::Create();
1341 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1342 make_scoped_refptr(new LayerWithForcedDrawsContent());
1343
1344 // The child height is zero, but has non-zero width that should be accounted
1345 // for while computing draw transforms.
1346 const gfx::Transform identity_matrix;
1347 SetLayerPropertiesForTesting(root.get(),
1348 identity_matrix,
1349 identity_matrix,
1350 gfx::PointF(),
1351 gfx::PointF(),
1352 gfx::Size(100, 100),
1353 false);
1354 SetLayerPropertiesForTesting(child.get(),
1355 identity_matrix,
1356 identity_matrix,
1357 gfx::PointF(),
1358 gfx::PointF(),
1359 gfx::Size(10, 0),
1360 false);
1361 SetLayerPropertiesForTesting(grand_child.get(),
1362 identity_matrix,
1363 identity_matrix,
1364 gfx::PointF(),
1365 gfx::PointF(),
1366 gfx::Size(10, 10),
1367 false);
1368
1369 root->AddChild(child);
1370 child->AddChild(grand_child);
1371 child->SetForceRenderSurface(true);
1372
[email protected]d600df7d2013-08-03 02:34:281373 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1374 host->SetRootLayer(root);
1375
[email protected]fb661802013-03-25 01:59:321376 ExecuteCalculateDrawProperties(root.get());
1377
1378 ASSERT_TRUE(child->render_surface());
1379 // This is the real test, the rest are sanity checks.
1380 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1381 child->render_surface()->draw_transform());
1382 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1383 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1384 grand_child->draw_transform());
1385}
1386
[email protected]989386c2013-07-18 21:37:231387TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321388 // Transformations applied at the root of the tree should be forwarded
1389 // to child layers instead of applied to the root RenderSurface.
1390 const gfx::Transform identity_matrix;
1391 scoped_refptr<Layer> root = Layer::Create();
1392 scoped_refptr<Layer> child = Layer::Create();
[email protected]adeda572014-01-31 00:49:471393 child->SetScrollClipLayerId(root->id());
[email protected]f224cc92013-06-06 23:23:321394 root->AddChild(child);
1395
[email protected]d600df7d2013-08-03 02:34:281396 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1397 host->SetRootLayer(root);
1398
[email protected]f224cc92013-06-06 23:23:321399 SetLayerPropertiesForTesting(root.get(),
1400 identity_matrix,
1401 identity_matrix,
1402 gfx::PointF(),
1403 gfx::PointF(),
1404 gfx::Size(20, 20),
1405 false);
1406 SetLayerPropertiesForTesting(child.get(),
1407 identity_matrix,
1408 identity_matrix,
1409 gfx::PointF(),
1410 gfx::PointF(),
1411 gfx::Size(20, 20),
1412 false);
1413
[email protected]f224cc92013-06-06 23:23:321414 gfx::Transform translate;
1415 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231416 {
1417 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531418 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1419 root.get(), root->bounds(), translate, &render_surface_layer_list);
1420 inputs.can_adjust_raster_scales = true;
1421 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231422 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1423 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1424 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1425 }
[email protected]f224cc92013-06-06 23:23:321426
1427 gfx::Transform scale;
1428 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231429 {
1430 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531431 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1432 root.get(), root->bounds(), scale, &render_surface_layer_list);
1433 inputs.can_adjust_raster_scales = true;
1434 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231435 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1436 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1437 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1438 }
[email protected]f224cc92013-06-06 23:23:321439
1440 gfx::Transform rotate;
1441 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231442 {
1443 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531444 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1445 root.get(), root->bounds(), rotate, &render_surface_layer_list);
1446 inputs.can_adjust_raster_scales = true;
1447 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231448 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1449 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1450 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1451 }
[email protected]f224cc92013-06-06 23:23:321452
1453 gfx::Transform composite;
1454 composite.ConcatTransform(translate);
1455 composite.ConcatTransform(scale);
1456 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231457 {
1458 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531459 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1460 root.get(), root->bounds(), composite, &render_surface_layer_list);
1461 inputs.can_adjust_raster_scales = true;
1462 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231463 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1464 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1465 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1466 }
[email protected]f224cc92013-06-06 23:23:321467
[email protected]9781afa2013-07-17 23:15:321468 // Verify it composes correctly with device scale.
1469 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231470
1471 {
1472 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531473 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1474 root.get(), root->bounds(), translate, &render_surface_layer_list);
1475 inputs.device_scale_factor = device_scale_factor;
1476 inputs.can_adjust_raster_scales = true;
1477 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231478 gfx::Transform device_scaled_translate = translate;
1479 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1480 EXPECT_EQ(device_scaled_translate,
1481 root->draw_properties().target_space_transform);
1482 EXPECT_EQ(device_scaled_translate,
1483 child->draw_properties().target_space_transform);
1484 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1485 }
[email protected]9781afa2013-07-17 23:15:321486
1487 // Verify it composes correctly with page scale.
1488 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231489
1490 {
1491 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531492 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1493 root.get(), root->bounds(), translate, &render_surface_layer_list);
1494 inputs.page_scale_factor = page_scale_factor;
1495 inputs.page_scale_application_layer = root.get();
1496 inputs.can_adjust_raster_scales = true;
1497 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231498 gfx::Transform page_scaled_translate = translate;
1499 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1500 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1501 EXPECT_EQ(page_scaled_translate,
1502 child->draw_properties().target_space_transform);
1503 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1504 }
[email protected]9781afa2013-07-17 23:15:321505
[email protected]f224cc92013-06-06 23:23:321506 // Verify that it composes correctly with transforms directly on root layer.
1507 root->SetTransform(composite);
1508 root->SetSublayerTransform(composite);
[email protected]989386c2013-07-18 21:37:231509
1510 {
1511 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531512 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1513 root.get(), root->bounds(), composite, &render_surface_layer_list);
1514 inputs.can_adjust_raster_scales = true;
1515 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231516 gfx::Transform compositeSquared = composite;
1517 compositeSquared.ConcatTransform(composite);
1518 gfx::Transform compositeCubed = compositeSquared;
1519 compositeCubed.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261520 EXPECT_TRANSFORMATION_MATRIX_EQ(
1521 compositeSquared, root->draw_properties().target_space_transform);
1522 EXPECT_TRANSFORMATION_MATRIX_EQ(
1523 compositeCubed, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231524 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1525 }
[email protected]f224cc92013-06-06 23:23:321526}
1527
[email protected]989386c2013-07-18 21:37:231528TEST_F(LayerTreeHostCommonTest,
1529 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321530 scoped_refptr<Layer> parent = Layer::Create();
1531 scoped_refptr<Layer> render_surface1 = Layer::Create();
1532 scoped_refptr<LayerWithForcedDrawsContent> child =
1533 make_scoped_refptr(new LayerWithForcedDrawsContent());
1534
[email protected]d600df7d2013-08-03 02:34:281535 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1536 host->SetRootLayer(parent);
1537
1538
[email protected]fb661802013-03-25 01:59:321539 const gfx::Transform identity_matrix;
1540 SetLayerPropertiesForTesting(parent.get(),
1541 identity_matrix,
1542 identity_matrix,
1543 gfx::PointF(),
1544 gfx::PointF(),
1545 gfx::Size(10, 10),
1546 false);
1547 SetLayerPropertiesForTesting(render_surface1.get(),
1548 identity_matrix,
1549 identity_matrix,
1550 gfx::PointF(),
1551 gfx::PointF(),
1552 gfx::Size(10, 10),
1553 false);
1554 SetLayerPropertiesForTesting(child.get(),
1555 identity_matrix,
1556 identity_matrix,
1557 gfx::PointF(),
1558 gfx::PointF(30.f, 30.f),
1559 gfx::Size(10, 10),
1560 false);
1561
1562 parent->AddChild(render_surface1);
1563 parent->SetMasksToBounds(true);
1564 render_surface1->AddChild(child);
1565 render_surface1->SetForceRenderSurface(true);
1566
[email protected]989386c2013-07-18 21:37:231567 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531568 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1569 parent.get(),
1570 parent->bounds(),
1571 gfx::Transform(),
1572 &render_surface_layer_list);
1573 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321574
1575 // The child layer's content is entirely outside the parent's clip rect, so
1576 // the intermediate render surface should not be listed here, even if it was
1577 // forced to be created. Render surfaces without children or visible content
1578 // are unexpected at draw time (e.g. we might try to create a content texture
1579 // of size 0).
1580 ASSERT_TRUE(parent->render_surface());
1581 ASSERT_FALSE(render_surface1->render_surface());
1582 EXPECT_EQ(1U, render_surface_layer_list.size());
1583}
1584
[email protected]989386c2013-07-18 21:37:231585TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321586 scoped_refptr<Layer> parent = Layer::Create();
1587 scoped_refptr<Layer> render_surface1 = Layer::Create();
1588 scoped_refptr<LayerWithForcedDrawsContent> child =
1589 make_scoped_refptr(new LayerWithForcedDrawsContent());
1590
[email protected]d600df7d2013-08-03 02:34:281591 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1592 host->SetRootLayer(parent);
1593
[email protected]fb661802013-03-25 01:59:321594 const gfx::Transform identity_matrix;
1595 SetLayerPropertiesForTesting(render_surface1.get(),
1596 identity_matrix,
1597 identity_matrix,
1598 gfx::PointF(),
1599 gfx::PointF(),
1600 gfx::Size(10, 10),
1601 false);
1602 SetLayerPropertiesForTesting(child.get(),
1603 identity_matrix,
1604 identity_matrix,
1605 gfx::PointF(),
1606 gfx::PointF(),
1607 gfx::Size(10, 10),
1608 false);
1609
1610 parent->AddChild(render_surface1);
1611 render_surface1->AddChild(child);
1612 render_surface1->SetForceRenderSurface(true);
1613 render_surface1->SetOpacity(0.f);
1614
[email protected]989386c2013-07-18 21:37:231615 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531616 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1617 parent.get(), parent->bounds(), &render_surface_layer_list);
1618 inputs.can_adjust_raster_scales = true;
1619 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321620
1621 // Since the layer is transparent, render_surface1->render_surface() should
1622 // not have gotten added anywhere. Also, the drawable content rect should not
1623 // have been extended by the children.
1624 ASSERT_TRUE(parent->render_surface());
1625 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1626 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231627 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321628 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1629}
1630
[email protected]989386c2013-07-18 21:37:231631TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321632 scoped_refptr<Layer> parent = Layer::Create();
1633 scoped_refptr<Layer> render_surface1 = Layer::Create();
1634 scoped_refptr<LayerWithForcedDrawsContent> child =
1635 make_scoped_refptr(new LayerWithForcedDrawsContent());
1636 render_surface1->SetForceRenderSurface(true);
1637
[email protected]d600df7d2013-08-03 02:34:281638 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1639 host->SetRootLayer(parent);
1640
[email protected]fb661802013-03-25 01:59:321641 const gfx::Transform identity_matrix;
1642 SetLayerPropertiesForTesting(parent.get(),
1643 identity_matrix,
1644 identity_matrix,
1645 gfx::PointF(),
1646 gfx::PointF(),
1647 gfx::Size(10, 10),
1648 false);
1649 SetLayerPropertiesForTesting(render_surface1.get(),
1650 identity_matrix,
1651 identity_matrix,
1652 gfx::PointF(),
1653 gfx::PointF(),
1654 gfx::Size(10, 10),
1655 false);
1656 SetLayerPropertiesForTesting(child.get(),
1657 identity_matrix,
1658 identity_matrix,
1659 gfx::PointF(),
1660 gfx::PointF(),
1661 gfx::Size(10, 10),
1662 false);
1663
1664 parent->AddChild(render_surface1);
1665 render_surface1->AddChild(child);
1666
1667 // Sanity check before the actual test
1668 EXPECT_FALSE(parent->render_surface());
1669 EXPECT_FALSE(render_surface1->render_surface());
1670
[email protected]989386c2013-07-18 21:37:231671 {
1672 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531673 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1674 parent.get(), parent->bounds(), &render_surface_layer_list);
1675 inputs.can_adjust_raster_scales = true;
1676 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321677
[email protected]989386c2013-07-18 21:37:231678 // The root layer always creates a render surface
1679 EXPECT_TRUE(parent->render_surface());
1680 EXPECT_TRUE(render_surface1->render_surface());
1681 EXPECT_EQ(2U, render_surface_layer_list.size());
1682 }
[email protected]fb661802013-03-25 01:59:321683
[email protected]989386c2013-07-18 21:37:231684 {
1685 RenderSurfaceLayerList render_surface_layer_list;
1686 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531687 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1688 parent.get(), parent->bounds(), &render_surface_layer_list);
1689 inputs.can_adjust_raster_scales = true;
1690 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231691 EXPECT_TRUE(parent->render_surface());
1692 EXPECT_FALSE(render_surface1->render_surface());
1693 EXPECT_EQ(1U, render_surface_layer_list.size());
1694 }
[email protected]fb661802013-03-25 01:59:321695}
1696
[email protected]989386c2013-07-18 21:37:231697TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321698 // The entire subtree of layers that are outside the clip rect should be
1699 // culled away, and should not affect the render_surface_layer_list.
1700 //
1701 // The test tree is set up as follows:
1702 // - all layers except the leaf_nodes are forced to be a new render surface
1703 // that have something to draw.
1704 // - parent is a large container layer.
1705 // - child has masksToBounds=true to cause clipping.
1706 // - grand_child is positioned outside of the child's bounds
1707 // - great_grand_child is also kept outside child's bounds.
1708 //
1709 // In this configuration, grand_child and great_grand_child are completely
1710 // outside the clip rect, and they should never get scheduled on the list of
1711 // render surfaces.
1712 //
1713
1714 const gfx::Transform identity_matrix;
1715 scoped_refptr<Layer> parent = Layer::Create();
1716 scoped_refptr<Layer> child = Layer::Create();
1717 scoped_refptr<Layer> grand_child = Layer::Create();
1718 scoped_refptr<Layer> great_grand_child = Layer::Create();
1719 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1720 make_scoped_refptr(new LayerWithForcedDrawsContent());
1721 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1722 make_scoped_refptr(new LayerWithForcedDrawsContent());
1723 parent->AddChild(child);
1724 child->AddChild(grand_child);
1725 grand_child->AddChild(great_grand_child);
1726
[email protected]d600df7d2013-08-03 02:34:281727 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1728 host->SetRootLayer(parent);
1729
[email protected]fb661802013-03-25 01:59:321730 // leaf_node1 ensures that parent and child are kept on the
1731 // render_surface_layer_list, even though grand_child and great_grand_child
1732 // should be clipped.
1733 child->AddChild(leaf_node1);
1734 great_grand_child->AddChild(leaf_node2);
1735
1736 SetLayerPropertiesForTesting(parent.get(),
1737 identity_matrix,
1738 identity_matrix,
1739 gfx::PointF(),
1740 gfx::PointF(),
1741 gfx::Size(500, 500),
1742 false);
1743 SetLayerPropertiesForTesting(child.get(),
1744 identity_matrix,
1745 identity_matrix,
1746 gfx::PointF(),
1747 gfx::PointF(),
1748 gfx::Size(20, 20),
1749 false);
1750 SetLayerPropertiesForTesting(grand_child.get(),
1751 identity_matrix,
1752 identity_matrix,
1753 gfx::PointF(),
1754 gfx::PointF(45.f, 45.f),
1755 gfx::Size(10, 10),
1756 false);
1757 SetLayerPropertiesForTesting(great_grand_child.get(),
1758 identity_matrix,
1759 identity_matrix,
1760 gfx::PointF(),
1761 gfx::PointF(),
1762 gfx::Size(10, 10),
1763 false);
1764 SetLayerPropertiesForTesting(leaf_node1.get(),
1765 identity_matrix,
1766 identity_matrix,
1767 gfx::PointF(),
1768 gfx::PointF(),
1769 gfx::Size(500, 500),
1770 false);
1771 SetLayerPropertiesForTesting(leaf_node2.get(),
1772 identity_matrix,
1773 identity_matrix,
1774 gfx::PointF(),
1775 gfx::PointF(),
1776 gfx::Size(20, 20),
1777 false);
1778
1779 child->SetMasksToBounds(true);
1780 child->SetOpacity(0.4f);
1781 child->SetForceRenderSurface(true);
1782 grand_child->SetOpacity(0.5f);
1783 great_grand_child->SetOpacity(0.4f);
1784
[email protected]989386c2013-07-18 21:37:231785 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531786 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1787 parent.get(), parent->bounds(), &render_surface_layer_list);
1788 inputs.can_adjust_raster_scales = true;
1789 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321790
1791 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231792 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1793 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321794}
1795
[email protected]989386c2013-07-18 21:37:231796TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321797 // When a render surface has a clip rect, it is used to clip the content rect
1798 // of the surface. When the render surface is animating its transforms, then
1799 // the content rect's position in the clip rect is not defined on the main
1800 // thread, and its content rect should not be clipped.
1801
1802 // The test tree is set up as follows:
1803 // - parent is a container layer that masksToBounds=true to cause clipping.
1804 // - child is a render surface, which has a clip rect set to the bounds of
1805 // the parent.
1806 // - grand_child is a render surface, and the only visible content in child.
1807 // It is positioned outside of the clip rect from parent.
1808
1809 // In this configuration, grand_child should be outside the clipped
1810 // content rect of the child, making grand_child not appear in the
1811 // render_surface_layer_list. However, when we place an animation on the
1812 // child, this clipping should be avoided and we should keep the grand_child
1813 // in the render_surface_layer_list.
1814
1815 const gfx::Transform identity_matrix;
1816 scoped_refptr<Layer> parent = Layer::Create();
1817 scoped_refptr<Layer> child = Layer::Create();
1818 scoped_refptr<Layer> grand_child = Layer::Create();
1819 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1820 make_scoped_refptr(new LayerWithForcedDrawsContent());
1821 parent->AddChild(child);
1822 child->AddChild(grand_child);
1823 grand_child->AddChild(leaf_node);
1824
[email protected]d600df7d2013-08-03 02:34:281825 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1826 host->SetRootLayer(parent);
1827
[email protected]fb661802013-03-25 01:59:321828 SetLayerPropertiesForTesting(parent.get(),
1829 identity_matrix,
1830 identity_matrix,
1831 gfx::PointF(),
1832 gfx::PointF(),
1833 gfx::Size(100, 100),
1834 false);
1835 SetLayerPropertiesForTesting(child.get(),
1836 identity_matrix,
1837 identity_matrix,
1838 gfx::PointF(),
1839 gfx::PointF(),
1840 gfx::Size(20, 20),
1841 false);
1842 SetLayerPropertiesForTesting(grand_child.get(),
1843 identity_matrix,
1844 identity_matrix,
1845 gfx::PointF(),
1846 gfx::PointF(200.f, 200.f),
1847 gfx::Size(10, 10),
1848 false);
1849 SetLayerPropertiesForTesting(leaf_node.get(),
1850 identity_matrix,
1851 identity_matrix,
1852 gfx::PointF(),
1853 gfx::PointF(),
1854 gfx::Size(10, 10),
1855 false);
1856
1857 parent->SetMasksToBounds(true);
1858 child->SetOpacity(0.4f);
1859 child->SetForceRenderSurface(true);
1860 grand_child->SetOpacity(0.4f);
1861 grand_child->SetForceRenderSurface(true);
1862
[email protected]989386c2013-07-18 21:37:231863 {
1864 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531865 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1866 parent.get(), parent->bounds(), &render_surface_layer_list);
1867 inputs.can_adjust_raster_scales = true;
1868 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321869
[email protected]989386c2013-07-18 21:37:231870 // Without an animation, we should cull child and grand_child from the
1871 // render_surface_layer_list.
1872 ASSERT_EQ(1U, render_surface_layer_list.size());
1873 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1874 }
[email protected]fb661802013-03-25 01:59:321875
1876 // Now put an animating transform on child.
1877 AddAnimatedTransformToController(
1878 child->layer_animation_controller(), 10.0, 30, 0);
1879
[email protected]989386c2013-07-18 21:37:231880 {
1881 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531882 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1883 parent.get(), parent->bounds(), &render_surface_layer_list);
1884 inputs.can_adjust_raster_scales = true;
1885 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321886
[email protected]989386c2013-07-18 21:37:231887 // With an animating transform, we should keep child and grand_child in the
1888 // render_surface_layer_list.
1889 ASSERT_EQ(3U, render_surface_layer_list.size());
1890 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1891 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1892 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1893 }
[email protected]fb661802013-03-25 01:59:321894}
1895
[email protected]989386c2013-07-18 21:37:231896TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:321897 // Layer's IsClipped() property is set to true when:
1898 // - the layer clips its subtree, e.g. masks to bounds,
1899 // - the layer is clipped by an ancestor that contributes to the same
1900 // render target,
1901 // - a surface is clipped by an ancestor that contributes to the same
1902 // render target.
1903 //
1904 // In particular, for a layer that owns a render surface:
1905 // - the render surface inherits any clip from ancestors, and does NOT
1906 // pass that clipped status to the layer itself.
1907 // - but if the layer itself masks to bounds, it is considered clipped
1908 // and propagates the clip to the subtree.
1909
1910 const gfx::Transform identity_matrix;
1911 scoped_refptr<Layer> root = Layer::Create();
1912 scoped_refptr<Layer> parent = Layer::Create();
1913 scoped_refptr<Layer> child1 = Layer::Create();
1914 scoped_refptr<Layer> child2 = Layer::Create();
1915 scoped_refptr<Layer> grand_child = Layer::Create();
1916 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1917 make_scoped_refptr(new LayerWithForcedDrawsContent());
1918 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1919 make_scoped_refptr(new LayerWithForcedDrawsContent());
1920 root->AddChild(parent);
1921 parent->AddChild(child1);
1922 parent->AddChild(child2);
1923 child1->AddChild(grand_child);
1924 child2->AddChild(leaf_node2);
1925 grand_child->AddChild(leaf_node1);
1926
[email protected]d600df7d2013-08-03 02:34:281927 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1928 host->SetRootLayer(root);
1929
[email protected]fb661802013-03-25 01:59:321930 child2->SetForceRenderSurface(true);
1931
1932 SetLayerPropertiesForTesting(root.get(),
1933 identity_matrix,
1934 identity_matrix,
1935 gfx::PointF(),
1936 gfx::PointF(),
1937 gfx::Size(100, 100),
1938 false);
1939 SetLayerPropertiesForTesting(parent.get(),
1940 identity_matrix,
1941 identity_matrix,
1942 gfx::PointF(),
1943 gfx::PointF(),
1944 gfx::Size(100, 100),
1945 false);
1946 SetLayerPropertiesForTesting(child1.get(),
1947 identity_matrix,
1948 identity_matrix,
1949 gfx::PointF(),
1950 gfx::PointF(),
1951 gfx::Size(100, 100),
1952 false);
1953 SetLayerPropertiesForTesting(child2.get(),
1954 identity_matrix,
1955 identity_matrix,
1956 gfx::PointF(),
1957 gfx::PointF(),
1958 gfx::Size(100, 100),
1959 false);
1960 SetLayerPropertiesForTesting(grand_child.get(),
1961 identity_matrix,
1962 identity_matrix,
1963 gfx::PointF(),
1964 gfx::PointF(),
1965 gfx::Size(100, 100),
1966 false);
1967 SetLayerPropertiesForTesting(leaf_node1.get(),
1968 identity_matrix,
1969 identity_matrix,
1970 gfx::PointF(),
1971 gfx::PointF(),
1972 gfx::Size(100, 100),
1973 false);
1974 SetLayerPropertiesForTesting(leaf_node2.get(),
1975 identity_matrix,
1976 identity_matrix,
1977 gfx::PointF(),
1978 gfx::PointF(),
1979 gfx::Size(100, 100),
1980 false);
1981
[email protected]989386c2013-07-18 21:37:231982 // Case 1: nothing is clipped except the root render surface.
1983 {
1984 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531985 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1986 root.get(), parent->bounds(), &render_surface_layer_list);
1987 inputs.can_adjust_raster_scales = true;
1988 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321989
[email protected]989386c2013-07-18 21:37:231990 ASSERT_TRUE(root->render_surface());
1991 ASSERT_TRUE(child2->render_surface());
1992
1993 EXPECT_FALSE(root->is_clipped());
1994 EXPECT_TRUE(root->render_surface()->is_clipped());
1995 EXPECT_FALSE(parent->is_clipped());
1996 EXPECT_FALSE(child1->is_clipped());
1997 EXPECT_FALSE(child2->is_clipped());
1998 EXPECT_FALSE(child2->render_surface()->is_clipped());
1999 EXPECT_FALSE(grand_child->is_clipped());
2000 EXPECT_FALSE(leaf_node1->is_clipped());
2001 EXPECT_FALSE(leaf_node2->is_clipped());
2002 }
[email protected]fb661802013-03-25 01:59:322003
2004 // Case 2: parent masksToBounds, so the parent, child1, and child2's
2005 // surface are clipped. But layers that contribute to child2's surface are
2006 // not clipped explicitly because child2's surface already accounts for
2007 // that clip.
[email protected]989386c2013-07-18 21:37:232008 {
2009 RenderSurfaceLayerList render_surface_layer_list;
2010 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:532011 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2012 root.get(), parent->bounds(), &render_surface_layer_list);
2013 inputs.can_adjust_raster_scales = true;
2014 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322015
[email protected]989386c2013-07-18 21:37:232016 ASSERT_TRUE(root->render_surface());
2017 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:322018
[email protected]989386c2013-07-18 21:37:232019 EXPECT_FALSE(root->is_clipped());
2020 EXPECT_TRUE(root->render_surface()->is_clipped());
2021 EXPECT_TRUE(parent->is_clipped());
2022 EXPECT_TRUE(child1->is_clipped());
2023 EXPECT_FALSE(child2->is_clipped());
2024 EXPECT_TRUE(child2->render_surface()->is_clipped());
2025 EXPECT_TRUE(grand_child->is_clipped());
2026 EXPECT_TRUE(leaf_node1->is_clipped());
2027 EXPECT_FALSE(leaf_node2->is_clipped());
2028 }
[email protected]fb661802013-03-25 01:59:322029
2030 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
2031 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:232032 {
2033 RenderSurfaceLayerList render_surface_layer_list;
2034 parent->SetMasksToBounds(false);
2035 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:532036 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2037 root.get(), parent->bounds(), &render_surface_layer_list);
2038 inputs.can_adjust_raster_scales = true;
2039 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322040
[email protected]989386c2013-07-18 21:37:232041 ASSERT_TRUE(root->render_surface());
2042 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:322043
[email protected]989386c2013-07-18 21:37:232044 EXPECT_FALSE(root->is_clipped());
2045 EXPECT_TRUE(root->render_surface()->is_clipped());
2046 EXPECT_FALSE(parent->is_clipped());
2047 EXPECT_FALSE(child1->is_clipped());
2048 EXPECT_TRUE(child2->is_clipped());
2049 EXPECT_FALSE(child2->render_surface()->is_clipped());
2050 EXPECT_FALSE(grand_child->is_clipped());
2051 EXPECT_FALSE(leaf_node1->is_clipped());
2052 EXPECT_TRUE(leaf_node2->is_clipped());
2053 }
[email protected]fb661802013-03-25 01:59:322054}
2055
[email protected]fd9a3b6d2013-08-03 00:46:172056TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322057 // Verify that layers get the appropriate DrawableContentRect when their
2058 // parent masksToBounds is true.
2059 //
2060 // grand_child1 - completely inside the region; DrawableContentRect should
2061 // be the layer rect expressed in target space.
2062 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
2063 // will be the intersection of layer bounds and the mask region.
2064 // grand_child3 - partially clipped and masksToBounds; the
2065 // DrawableContentRect will still be the intersection of layer bounds and
2066 // the mask region.
2067 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2068 // be empty.
2069 //
2070
2071 const gfx::Transform identity_matrix;
2072 scoped_refptr<Layer> parent = Layer::Create();
2073 scoped_refptr<Layer> child = Layer::Create();
2074 scoped_refptr<Layer> grand_child1 = Layer::Create();
2075 scoped_refptr<Layer> grand_child2 = Layer::Create();
2076 scoped_refptr<Layer> grand_child3 = Layer::Create();
2077 scoped_refptr<Layer> grand_child4 = Layer::Create();
2078
2079 parent->AddChild(child);
2080 child->AddChild(grand_child1);
2081 child->AddChild(grand_child2);
2082 child->AddChild(grand_child3);
2083 child->AddChild(grand_child4);
2084
[email protected]d600df7d2013-08-03 02:34:282085 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2086 host->SetRootLayer(parent);
2087
[email protected]fb661802013-03-25 01:59:322088 SetLayerPropertiesForTesting(parent.get(),
2089 identity_matrix,
2090 identity_matrix,
2091 gfx::PointF(),
2092 gfx::PointF(),
2093 gfx::Size(500, 500),
2094 false);
2095 SetLayerPropertiesForTesting(child.get(),
2096 identity_matrix,
2097 identity_matrix,
2098 gfx::PointF(),
2099 gfx::PointF(),
2100 gfx::Size(20, 20),
2101 false);
2102 SetLayerPropertiesForTesting(grand_child1.get(),
2103 identity_matrix,
2104 identity_matrix,
2105 gfx::PointF(),
2106 gfx::PointF(5.f, 5.f),
2107 gfx::Size(10, 10),
2108 false);
2109 SetLayerPropertiesForTesting(grand_child2.get(),
2110 identity_matrix,
2111 identity_matrix,
2112 gfx::PointF(),
2113 gfx::PointF(15.f, 15.f),
2114 gfx::Size(10, 10),
2115 false);
2116 SetLayerPropertiesForTesting(grand_child3.get(),
2117 identity_matrix,
2118 identity_matrix,
2119 gfx::PointF(),
2120 gfx::PointF(15.f, 15.f),
2121 gfx::Size(10, 10),
2122 false);
2123 SetLayerPropertiesForTesting(grand_child4.get(),
2124 identity_matrix,
2125 identity_matrix,
2126 gfx::PointF(),
2127 gfx::PointF(45.f, 45.f),
2128 gfx::Size(10, 10),
2129 false);
2130
2131 child->SetMasksToBounds(true);
2132 grand_child3->SetMasksToBounds(true);
2133
2134 // Force everyone to be a render surface.
2135 child->SetOpacity(0.4f);
2136 grand_child1->SetOpacity(0.5f);
2137 grand_child2->SetOpacity(0.5f);
2138 grand_child3->SetOpacity(0.5f);
2139 grand_child4->SetOpacity(0.5f);
2140
[email protected]989386c2013-07-18 21:37:232141 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532142 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2143 parent.get(), parent->bounds(), &render_surface_layer_list);
2144 inputs.can_adjust_raster_scales = true;
2145 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322146
[email protected]2c7c6702013-03-26 03:14:052147 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
[email protected]fb661802013-03-25 01:59:322148 grand_child1->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:052149 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:322150 grand_child3->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:052151 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:322152 grand_child3->drawable_content_rect());
2153 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2154}
2155
[email protected]989386c2013-07-18 21:37:232156TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322157 // Verify that render surfaces (and their layers) get the appropriate
2158 // clip rects when their parent masksToBounds is true.
2159 //
2160 // Layers that own render surfaces (at least for now) do not inherit any
2161 // clipping; instead the surface will enforce the clip for the entire subtree.
2162 // They may still have a clip rect of their own layer bounds, however, if
2163 // masksToBounds was true.
2164 const gfx::Transform identity_matrix;
2165 scoped_refptr<Layer> parent = Layer::Create();
2166 scoped_refptr<Layer> child = Layer::Create();
2167 scoped_refptr<Layer> grand_child1 = Layer::Create();
2168 scoped_refptr<Layer> grand_child2 = Layer::Create();
2169 scoped_refptr<Layer> grand_child3 = Layer::Create();
2170 scoped_refptr<Layer> grand_child4 = Layer::Create();
2171 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2172 make_scoped_refptr(new LayerWithForcedDrawsContent());
2173 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2174 make_scoped_refptr(new LayerWithForcedDrawsContent());
2175 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
2176 make_scoped_refptr(new LayerWithForcedDrawsContent());
2177 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
2178 make_scoped_refptr(new LayerWithForcedDrawsContent());
2179
2180 parent->AddChild(child);
2181 child->AddChild(grand_child1);
2182 child->AddChild(grand_child2);
2183 child->AddChild(grand_child3);
2184 child->AddChild(grand_child4);
2185
[email protected]d600df7d2013-08-03 02:34:282186 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2187 host->SetRootLayer(parent);
2188
[email protected]fb661802013-03-25 01:59:322189 // the leaf nodes ensure that these grand_children become render surfaces for
2190 // this test.
2191 grand_child1->AddChild(leaf_node1);
2192 grand_child2->AddChild(leaf_node2);
2193 grand_child3->AddChild(leaf_node3);
2194 grand_child4->AddChild(leaf_node4);
2195
2196 SetLayerPropertiesForTesting(parent.get(),
2197 identity_matrix,
2198 identity_matrix,
2199 gfx::PointF(),
2200 gfx::PointF(),
2201 gfx::Size(500, 500),
2202 false);
2203 SetLayerPropertiesForTesting(child.get(),
2204 identity_matrix,
2205 identity_matrix,
2206 gfx::PointF(),
2207 gfx::PointF(),
2208 gfx::Size(20, 20),
2209 false);
2210 SetLayerPropertiesForTesting(grand_child1.get(),
2211 identity_matrix,
2212 identity_matrix,
2213 gfx::PointF(),
2214 gfx::PointF(5.f, 5.f),
2215 gfx::Size(10, 10),
2216 false);
2217 SetLayerPropertiesForTesting(grand_child2.get(),
2218 identity_matrix,
2219 identity_matrix,
2220 gfx::PointF(),
2221 gfx::PointF(15.f, 15.f),
2222 gfx::Size(10, 10),
2223 false);
2224 SetLayerPropertiesForTesting(grand_child3.get(),
2225 identity_matrix,
2226 identity_matrix,
2227 gfx::PointF(),
2228 gfx::PointF(15.f, 15.f),
2229 gfx::Size(10, 10),
2230 false);
2231 SetLayerPropertiesForTesting(grand_child4.get(),
2232 identity_matrix,
2233 identity_matrix,
2234 gfx::PointF(),
2235 gfx::PointF(45.f, 45.f),
2236 gfx::Size(10, 10),
2237 false);
2238 SetLayerPropertiesForTesting(leaf_node1.get(),
2239 identity_matrix,
2240 identity_matrix,
2241 gfx::PointF(),
2242 gfx::PointF(),
2243 gfx::Size(10, 10),
2244 false);
2245 SetLayerPropertiesForTesting(leaf_node2.get(),
2246 identity_matrix,
2247 identity_matrix,
2248 gfx::PointF(),
2249 gfx::PointF(),
2250 gfx::Size(10, 10),
2251 false);
2252 SetLayerPropertiesForTesting(leaf_node3.get(),
2253 identity_matrix,
2254 identity_matrix,
2255 gfx::PointF(),
2256 gfx::PointF(),
2257 gfx::Size(10, 10),
2258 false);
2259 SetLayerPropertiesForTesting(leaf_node4.get(),
2260 identity_matrix,
2261 identity_matrix,
2262 gfx::PointF(),
2263 gfx::PointF(),
2264 gfx::Size(10, 10),
2265 false);
2266
2267 child->SetMasksToBounds(true);
2268 grand_child3->SetMasksToBounds(true);
2269 grand_child4->SetMasksToBounds(true);
2270
2271 // Force everyone to be a render surface.
2272 child->SetOpacity(0.4f);
2273 child->SetForceRenderSurface(true);
2274 grand_child1->SetOpacity(0.5f);
2275 grand_child1->SetForceRenderSurface(true);
2276 grand_child2->SetOpacity(0.5f);
2277 grand_child2->SetForceRenderSurface(true);
2278 grand_child3->SetOpacity(0.5f);
2279 grand_child3->SetForceRenderSurface(true);
2280 grand_child4->SetOpacity(0.5f);
2281 grand_child4->SetForceRenderSurface(true);
2282
[email protected]989386c2013-07-18 21:37:232283 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532284 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2285 parent.get(), parent->bounds(), &render_surface_layer_list);
2286 inputs.can_adjust_raster_scales = true;
2287 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322288 ASSERT_TRUE(grand_child1->render_surface());
2289 ASSERT_TRUE(grand_child2->render_surface());
2290 ASSERT_TRUE(grand_child3->render_surface());
2291 // Because grand_child4 is entirely clipped, it is expected to not have a
2292 // render surface.
2293 EXPECT_FALSE(grand_child4->render_surface());
2294
2295 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2296 // masksToBounds.
[email protected]2c7c6702013-03-26 03:14:052297 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322298 grand_child1->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052299 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322300 grand_child2->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052301 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322302 grand_child3->render_surface()->clip_rect());
2303}
2304
[email protected]989386c2013-07-18 21:37:232305TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322306 scoped_refptr<Layer> parent = Layer::Create();
2307 scoped_refptr<Layer> render_surface1 = Layer::Create();
2308 scoped_refptr<Layer> render_surface2 = Layer::Create();
2309 scoped_refptr<Layer> child_of_root = Layer::Create();
2310 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2311 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2312 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2313 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2314 make_scoped_refptr(new LayerWithForcedDrawsContent());
2315 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2316 make_scoped_refptr(new LayerWithForcedDrawsContent());
2317 parent->AddChild(render_surface1);
2318 parent->AddChild(child_of_root);
2319 render_surface1->AddChild(child_of_rs1);
2320 render_surface1->AddChild(render_surface2);
2321 render_surface2->AddChild(child_of_rs2);
2322 child_of_root->AddChild(grand_child_of_root);
2323 child_of_rs1->AddChild(grand_child_of_rs1);
2324 child_of_rs2->AddChild(grand_child_of_rs2);
2325
[email protected]d600df7d2013-08-03 02:34:282326 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2327 host->SetRootLayer(parent);
2328
[email protected]fb661802013-03-25 01:59:322329 // Make our render surfaces.
2330 render_surface1->SetForceRenderSurface(true);
2331 render_surface2->SetForceRenderSurface(true);
2332
2333 gfx::Transform layer_transform;
2334 layer_transform.Translate(1.0, 1.0);
2335 gfx::Transform sublayer_transform;
2336 sublayer_transform.Scale3d(10.0, 1.0, 1.0);
2337
2338 SetLayerPropertiesForTesting(parent.get(),
2339 layer_transform,
2340 sublayer_transform,
2341 gfx::PointF(0.25f, 0.f),
2342 gfx::PointF(2.5f, 0.f),
2343 gfx::Size(10, 10),
2344 false);
2345 SetLayerPropertiesForTesting(render_surface1.get(),
2346 layer_transform,
2347 sublayer_transform,
2348 gfx::PointF(0.25f, 0.f),
2349 gfx::PointF(2.5f, 0.f),
2350 gfx::Size(10, 10),
2351 false);
2352 SetLayerPropertiesForTesting(render_surface2.get(),
2353 layer_transform,
2354 sublayer_transform,
2355 gfx::PointF(0.25f, 0.f),
2356 gfx::PointF(2.5f, 0.f),
2357 gfx::Size(10, 10),
2358 false);
2359 SetLayerPropertiesForTesting(child_of_root.get(),
2360 layer_transform,
2361 sublayer_transform,
2362 gfx::PointF(0.25f, 0.f),
2363 gfx::PointF(2.5f, 0.f),
2364 gfx::Size(10, 10),
2365 false);
2366 SetLayerPropertiesForTesting(child_of_rs1.get(),
2367 layer_transform,
2368 sublayer_transform,
2369 gfx::PointF(0.25f, 0.f),
2370 gfx::PointF(2.5f, 0.f),
2371 gfx::Size(10, 10),
2372 false);
2373 SetLayerPropertiesForTesting(child_of_rs2.get(),
2374 layer_transform,
2375 sublayer_transform,
2376 gfx::PointF(0.25f, 0.f),
2377 gfx::PointF(2.5f, 0.f),
2378 gfx::Size(10, 10),
2379 false);
2380 SetLayerPropertiesForTesting(grand_child_of_root.get(),
2381 layer_transform,
2382 sublayer_transform,
2383 gfx::PointF(0.25f, 0.f),
2384 gfx::PointF(2.5f, 0.f),
2385 gfx::Size(10, 10),
2386 false);
2387 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
2388 layer_transform,
2389 sublayer_transform,
2390 gfx::PointF(0.25f, 0.f),
2391 gfx::PointF(2.5f, 0.f),
2392 gfx::Size(10, 10),
2393 false);
2394 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
2395 layer_transform,
2396 sublayer_transform,
2397 gfx::PointF(0.25f, 0.f),
2398 gfx::PointF(2.5f, 0.f),
2399 gfx::Size(10, 10),
2400 false);
2401
2402 // Put an animated opacity on the render surface.
2403 AddOpacityTransitionToController(
2404 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2405
2406 // Also put an animated opacity on a layer without descendants.
2407 AddOpacityTransitionToController(
2408 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2409
2410 // Put a transform animation on the render surface.
2411 AddAnimatedTransformToController(
2412 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2413
2414 // Also put transform animations on grand_child_of_root, and
2415 // grand_child_of_rs2
2416 AddAnimatedTransformToController(
2417 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2418 AddAnimatedTransformToController(
2419 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2420
2421 ExecuteCalculateDrawProperties(parent.get());
2422
2423 // Only layers that are associated with render surfaces should have an actual
2424 // RenderSurface() value.
2425 ASSERT_TRUE(parent->render_surface());
2426 ASSERT_FALSE(child_of_root->render_surface());
2427 ASSERT_FALSE(grand_child_of_root->render_surface());
2428
2429 ASSERT_TRUE(render_surface1->render_surface());
2430 ASSERT_FALSE(child_of_rs1->render_surface());
2431 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2432
2433 ASSERT_TRUE(render_surface2->render_surface());
2434 ASSERT_FALSE(child_of_rs2->render_surface());
2435 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2436
2437 // Verify all render target accessors
2438 EXPECT_EQ(parent, parent->render_target());
2439 EXPECT_EQ(parent, child_of_root->render_target());
2440 EXPECT_EQ(parent, grand_child_of_root->render_target());
2441
2442 EXPECT_EQ(render_surface1, render_surface1->render_target());
2443 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2444 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
2445
2446 EXPECT_EQ(render_surface2, render_surface2->render_target());
2447 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2448 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
2449
2450 // Verify draw_opacity_is_animating values
2451 EXPECT_FALSE(parent->draw_opacity_is_animating());
2452 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2453 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2454 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2455 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2456 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2457 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2458 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2459 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2460 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2461 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2462
2463 // Verify draw_transform_is_animating values
2464 EXPECT_FALSE(parent->draw_transform_is_animating());
2465 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2466 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2467 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2468 EXPECT_FALSE(render_surface1->render_surface()
2469 ->target_surface_transforms_are_animating());
2470 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2471 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2472 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2473 EXPECT_TRUE(render_surface2->render_surface()
2474 ->target_surface_transforms_are_animating());
2475 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2476 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2477
2478 // Verify screen_space_transform_is_animating values
2479 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2480 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2481 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2482 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2483 EXPECT_FALSE(render_surface1->render_surface()
2484 ->screen_space_transforms_are_animating());
2485 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2486 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2487 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2488 EXPECT_TRUE(render_surface2->render_surface()
2489 ->screen_space_transforms_are_animating());
2490 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2491 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2492
2493 // Sanity check. If these fail there is probably a bug in the test itself.
2494 // It is expected that we correctly set up transforms so that the y-component
2495 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262496 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2497 EXPECT_FLOAT_EQ(2.0,
2498 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322499 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262500 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322501
[email protected]803f6b52013-09-12 00:51:262502 EXPECT_FLOAT_EQ(2.0,
2503 render_surface1->screen_space_transform().matrix().get(1, 3));
2504 EXPECT_FLOAT_EQ(3.0,
2505 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322506 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262507 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322508
[email protected]803f6b52013-09-12 00:51:262509 EXPECT_FLOAT_EQ(3.0,
2510 render_surface2->screen_space_transform().matrix().get(1, 3));
2511 EXPECT_FLOAT_EQ(4.0,
2512 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322513 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262514 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322515}
2516
[email protected]989386c2013-07-18 21:37:232517TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322518 // Test the calculateVisibleRect() function works correctly for identity
2519 // transforms.
2520
[email protected]2c7c6702013-03-26 03:14:052521 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322522 gfx::Transform layer_to_surface_transform;
2523
2524 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232525 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052526 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322527 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2528 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2529 EXPECT_RECT_EQ(expected, actual);
2530
2531 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052532 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322533 actual = LayerTreeHostCommon::CalculateVisibleRect(
2534 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2535 EXPECT_TRUE(actual.IsEmpty());
2536
2537 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052538 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2539 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322540 actual = LayerTreeHostCommon::CalculateVisibleRect(
2541 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2542 EXPECT_RECT_EQ(expected, actual);
2543}
2544
[email protected]989386c2013-07-18 21:37:232545TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322546 // Test the calculateVisibleRect() function works correctly for scaling
2547 // transforms.
2548
[email protected]2c7c6702013-03-26 03:14:052549 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2550 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322551 gfx::Transform layer_to_surface_transform;
2552
2553 // Case 1: Layer is contained within the surface.
2554 layer_to_surface_transform.MakeIdentity();
2555 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052556 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322557 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2558 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2559 EXPECT_RECT_EQ(expected, actual);
2560
2561 // Case 2: Layer is outside the surface rect.
2562 layer_to_surface_transform.MakeIdentity();
2563 layer_to_surface_transform.Translate(120.0, 120.0);
2564 actual = LayerTreeHostCommon::CalculateVisibleRect(
2565 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2566 EXPECT_TRUE(actual.IsEmpty());
2567
2568 // Case 3: Layer is partially overlapping the surface rect.
2569 layer_to_surface_transform.MakeIdentity();
2570 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052571 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322572 actual = LayerTreeHostCommon::CalculateVisibleRect(
2573 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2574 EXPECT_RECT_EQ(expected, actual);
2575}
2576
[email protected]989386c2013-07-18 21:37:232577TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322578 // Test the calculateVisibleRect() function works correctly for rotations
2579 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2580 // should return the g in the layer's space.
2581
[email protected]2c7c6702013-03-26 03:14:052582 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2583 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322584 gfx::Transform layer_to_surface_transform;
2585
2586 // Case 1: Layer is contained within the surface.
2587 layer_to_surface_transform.MakeIdentity();
2588 layer_to_surface_transform.Translate(50.0, 50.0);
2589 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052590 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322591 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2592 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2593 EXPECT_RECT_EQ(expected, actual);
2594
2595 // Case 2: Layer is outside the surface rect.
2596 layer_to_surface_transform.MakeIdentity();
2597 layer_to_surface_transform.Translate(-50.0, 0.0);
2598 layer_to_surface_transform.Rotate(45.0);
2599 actual = LayerTreeHostCommon::CalculateVisibleRect(
2600 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2601 EXPECT_TRUE(actual.IsEmpty());
2602
2603 // Case 3: The layer is rotated about its top-left corner. In surface space,
2604 // the layer is oriented diagonally, with the left half outside of the render
2605 // surface. In this case, the g should still be the entire layer
2606 // (remember the g is computed in layer space); both the top-left
2607 // and bottom-right corners of the layer are still visible.
2608 layer_to_surface_transform.MakeIdentity();
2609 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052610 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322611 actual = LayerTreeHostCommon::CalculateVisibleRect(
2612 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2613 EXPECT_RECT_EQ(expected, actual);
2614
2615 // Case 4: The layer is rotated about its top-left corner, and translated
2616 // upwards. In surface space, the layer is oriented diagonally, with only the
2617 // top corner of the surface overlapping the layer. In layer space, the render
2618 // surface overlaps the right side of the layer. The g should be
2619 // the layer's right half.
2620 layer_to_surface_transform.MakeIdentity();
2621 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2622 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052623 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322624 actual = LayerTreeHostCommon::CalculateVisibleRect(
2625 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2626 EXPECT_RECT_EQ(expected, actual);
2627}
2628
[email protected]989386c2013-07-18 21:37:232629TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322630 // Test that the calculateVisibleRect() function works correctly for 3d
2631 // transforms.
2632
[email protected]2c7c6702013-03-26 03:14:052633 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2634 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322635 gfx::Transform layer_to_surface_transform;
2636
2637 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2638 // degrees, should be fully contained in the render surface.
2639 layer_to_surface_transform.MakeIdentity();
2640 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052641 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322642 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2643 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2644 EXPECT_RECT_EQ(expected, actual);
2645
2646 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2647 // degrees, but shifted to the side so only the right-half the layer would be
2648 // visible on the surface.
2649 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262650 SkMScalar half_width_of_rotated_layer =
2651 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322652 layer_to_surface_transform.MakeIdentity();
2653 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232654 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2655 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052656 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322657 actual = LayerTreeHostCommon::CalculateVisibleRect(
2658 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2659 EXPECT_RECT_EQ(expected, actual);
2660}
2661
[email protected]989386c2013-07-18 21:37:232662TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322663 // Test the calculateVisibleRect() function works correctly when the layer has
2664 // a perspective projection onto the target surface.
2665
[email protected]2c7c6702013-03-26 03:14:052666 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2667 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322668 gfx::Transform layer_to_surface_transform;
2669
2670 // Case 1: Even though the layer is twice as large as the surface, due to
2671 // perspective foreshortening, the layer will fit fully in the surface when
2672 // its translated more than the perspective amount.
2673 layer_to_surface_transform.MakeIdentity();
2674
2675 // The following sequence of transforms applies the perspective about the
2676 // center of the surface.
2677 layer_to_surface_transform.Translate(50.0, 50.0);
2678 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2679 layer_to_surface_transform.Translate(-50.0, -50.0);
2680
2681 // This translate places the layer in front of the surface's projection plane.
2682 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2683
[email protected]2c7c6702013-03-26 03:14:052684 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322685 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2686 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2687 EXPECT_RECT_EQ(expected, actual);
2688
2689 // Case 2: same projection as before, except that the layer is also translated
2690 // to the side, so that only the right half of the layer should be visible.
2691 //
2692 // Explanation of expected result: The perspective ratio is (z distance
2693 // between layer and camera origin) / (z distance between projection plane and
2694 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2695 // move a layer by translating -50 units in projected surface units (so that
2696 // only half of it is visible), then we would need to translate by (-36 / 9) *
2697 // -50 == -200 in the layer's units.
2698 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232699 expected = gfx::Rect(gfx::Point(50, -50),
2700 gfx::Size(100, 200)); // The right half of the layer's
2701 // bounding rect.
[email protected]fb661802013-03-25 01:59:322702 actual = LayerTreeHostCommon::CalculateVisibleRect(
2703 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2704 EXPECT_RECT_EQ(expected, actual);
2705}
2706
[email protected]989386c2013-07-18 21:37:232707TEST_F(LayerTreeHostCommonTest,
2708 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322709 // There is currently no explicit concept of an orthographic projection plane
2710 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2711 // are technically behind the surface in an orthographic world should not be
2712 // clipped when they are flattened to the surface.
2713
[email protected]2c7c6702013-03-26 03:14:052714 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2715 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322716 gfx::Transform layer_to_surface_transform;
2717
2718 // This sequence of transforms effectively rotates the layer about the y-axis
2719 // at the center of the layer.
2720 layer_to_surface_transform.MakeIdentity();
2721 layer_to_surface_transform.Translate(50.0, 0.0);
2722 layer_to_surface_transform.RotateAboutYAxis(45.0);
2723 layer_to_surface_transform.Translate(-50.0, 0.0);
2724
[email protected]2c7c6702013-03-26 03:14:052725 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322726 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2727 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2728 EXPECT_RECT_EQ(expected, actual);
2729}
2730
[email protected]989386c2013-07-18 21:37:232731TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322732 // Test the calculateVisibleRect() function works correctly when projecting a
2733 // surface onto a layer, but the layer is partially behind the camera (not
2734 // just behind the projection plane). In this case, the cartesian coordinates
2735 // may seem to be valid, but actually they are not. The visible rect needs to
2736 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2737 // converting to cartesian coordinates.
2738
[email protected]2c7c6702013-03-26 03:14:052739 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232740 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322741 gfx::Transform layer_to_surface_transform;
2742
2743 // The layer is positioned so that the right half of the layer should be in
2744 // front of the camera, while the other half is behind the surface's
2745 // projection plane. The following sequence of transforms applies the
2746 // perspective and rotation about the center of the layer.
2747 layer_to_surface_transform.MakeIdentity();
2748 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2749 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2750 layer_to_surface_transform.RotateAboutYAxis(45.0);
2751
2752 // Sanity check that this transform does indeed cause w < 0 when applying the
2753 // transform, otherwise this code is not testing the intended scenario.
2754 bool clipped;
2755 MathUtil::MapQuad(layer_to_surface_transform,
2756 gfx::QuadF(gfx::RectF(layer_content_rect)),
2757 &clipped);
2758 ASSERT_TRUE(clipped);
2759
2760 int expected_x_position = 0;
2761 int expected_width = 10;
2762 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2763 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2764 EXPECT_EQ(expected_x_position, actual.x());
2765 EXPECT_EQ(expected_width, actual.width());
2766}
2767
[email protected]989386c2013-07-18 21:37:232768TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322769 // To determine visible rect in layer space, there needs to be an
2770 // un-projection from surface space to layer space. When the original
2771 // transform was a perspective projection that was clipped, it returns a rect
2772 // that encloses the clipped bounds. Un-projecting this new rect may require
2773 // clipping again.
2774
2775 // This sequence of transforms causes one corner of the layer to protrude
2776 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232777 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2778 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322779 gfx::Transform layer_to_surface_transform;
2780 layer_to_surface_transform.MakeIdentity();
2781 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2782 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2783 layer_to_surface_transform.RotateAboutYAxis(45.0);
2784 layer_to_surface_transform.RotateAboutXAxis(80.0);
2785
2786 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2787 // code is not testing the intended scenario.
2788 bool clipped;
2789 gfx::RectF clipped_rect =
2790 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2791 MathUtil::ProjectQuad(
2792 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2793 ASSERT_TRUE(clipped);
2794
2795 // Only the corner of the layer is not visible on the surface because of being
2796 // clipped. But, the net result of rounding visible region to an axis-aligned
2797 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052798 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322799 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2800 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2801 EXPECT_RECT_EQ(expected, actual);
2802}
2803
[email protected]989386c2013-07-18 21:37:232804TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322805 scoped_refptr<Layer> root = Layer::Create();
2806 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2807 make_scoped_refptr(new LayerWithForcedDrawsContent());
2808 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2809 make_scoped_refptr(new LayerWithForcedDrawsContent());
2810 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2811 make_scoped_refptr(new LayerWithForcedDrawsContent());
2812 root->AddChild(child1);
2813 root->AddChild(child2);
2814 root->AddChild(child3);
2815
[email protected]d600df7d2013-08-03 02:34:282816 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2817 host->SetRootLayer(root);
2818
[email protected]fb661802013-03-25 01:59:322819 gfx::Transform identity_matrix;
2820 SetLayerPropertiesForTesting(root.get(),
2821 identity_matrix,
2822 identity_matrix,
2823 gfx::PointF(),
2824 gfx::PointF(),
2825 gfx::Size(100, 100),
2826 false);
2827 SetLayerPropertiesForTesting(child1.get(),
2828 identity_matrix,
2829 identity_matrix,
2830 gfx::PointF(),
2831 gfx::PointF(),
2832 gfx::Size(50, 50),
2833 false);
2834 SetLayerPropertiesForTesting(child2.get(),
2835 identity_matrix,
2836 identity_matrix,
2837 gfx::PointF(),
2838 gfx::PointF(75.f, 75.f),
2839 gfx::Size(50, 50),
2840 false);
2841 SetLayerPropertiesForTesting(child3.get(),
2842 identity_matrix,
2843 identity_matrix,
2844 gfx::PointF(),
2845 gfx::PointF(125.f, 125.f),
2846 gfx::Size(50, 50),
2847 false);
2848
2849 ExecuteCalculateDrawProperties(root.get());
2850
2851 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2852 root->render_surface()->DrawableContentRect());
2853 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2854
2855 // Layers that do not draw content should have empty visible_content_rects.
2856 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2857
2858 // layer visible_content_rects are clipped by their target surface.
2859 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2860 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
2861 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
2862
2863 // layer drawable_content_rects are not clipped.
2864 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2865 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2866 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2867}
2868
[email protected]989386c2013-07-18 21:37:232869TEST_F(LayerTreeHostCommonTest,
2870 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:322871 scoped_refptr<Layer> root = Layer::Create();
2872 scoped_refptr<Layer> child = Layer::Create();
2873 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
2874 make_scoped_refptr(new LayerWithForcedDrawsContent());
2875 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
2876 make_scoped_refptr(new LayerWithForcedDrawsContent());
2877 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
2878 make_scoped_refptr(new LayerWithForcedDrawsContent());
2879 root->AddChild(child);
2880 child->AddChild(grand_child1);
2881 child->AddChild(grand_child2);
2882 child->AddChild(grand_child3);
2883
[email protected]d600df7d2013-08-03 02:34:282884 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2885 host->SetRootLayer(root);
2886
[email protected]fb661802013-03-25 01:59:322887 gfx::Transform identity_matrix;
2888 SetLayerPropertiesForTesting(root.get(),
2889 identity_matrix,
2890 identity_matrix,
2891 gfx::PointF(),
2892 gfx::PointF(),
2893 gfx::Size(100, 100),
2894 false);
2895 SetLayerPropertiesForTesting(child.get(),
2896 identity_matrix,
2897 identity_matrix,
2898 gfx::PointF(),
2899 gfx::PointF(),
2900 gfx::Size(100, 100),
2901 false);
2902 SetLayerPropertiesForTesting(grand_child1.get(),
2903 identity_matrix,
2904 identity_matrix,
2905 gfx::PointF(),
2906 gfx::PointF(5.f, 5.f),
2907 gfx::Size(50, 50),
2908 false);
2909 SetLayerPropertiesForTesting(grand_child2.get(),
2910 identity_matrix,
2911 identity_matrix,
2912 gfx::PointF(),
2913 gfx::PointF(75.f, 75.f),
2914 gfx::Size(50, 50),
2915 false);
2916 SetLayerPropertiesForTesting(grand_child3.get(),
2917 identity_matrix,
2918 identity_matrix,
2919 gfx::PointF(),
2920 gfx::PointF(125.f, 125.f),
2921 gfx::Size(50, 50),
2922 false);
2923
2924 child->SetMasksToBounds(true);
2925 ExecuteCalculateDrawProperties(root.get());
2926
2927 ASSERT_FALSE(child->render_surface());
2928
2929 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2930 root->render_surface()->DrawableContentRect());
2931 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2932
2933 // Layers that do not draw content should have empty visible content rects.
2934 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2935 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
2936
2937 // All grandchild visible content rects should be clipped by child.
2938 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
2939 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
2940 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
2941
2942 // All grandchild DrawableContentRects should also be clipped by child.
2943 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
2944 grand_child1->drawable_content_rect());
2945 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
2946 grand_child2->drawable_content_rect());
2947 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2948}
2949
[email protected]989386c2013-07-18 21:37:232950TEST_F(LayerTreeHostCommonTest,
2951 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322952 scoped_refptr<Layer> root = Layer::Create();
2953 scoped_refptr<Layer> render_surface1 = Layer::Create();
2954 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2955 make_scoped_refptr(new LayerWithForcedDrawsContent());
2956 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2957 make_scoped_refptr(new LayerWithForcedDrawsContent());
2958 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2959 make_scoped_refptr(new LayerWithForcedDrawsContent());
2960 root->AddChild(render_surface1);
2961 render_surface1->AddChild(child1);
2962 render_surface1->AddChild(child2);
2963 render_surface1->AddChild(child3);
2964
[email protected]d600df7d2013-08-03 02:34:282965 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2966 host->SetRootLayer(root);
2967
[email protected]fb661802013-03-25 01:59:322968 gfx::Transform identity_matrix;
2969 SetLayerPropertiesForTesting(root.get(),
2970 identity_matrix,
2971 identity_matrix,
2972 gfx::PointF(),
2973 gfx::PointF(),
2974 gfx::Size(100, 100),
2975 false);
2976 SetLayerPropertiesForTesting(render_surface1.get(),
2977 identity_matrix,
2978 identity_matrix,
2979 gfx::PointF(),
2980 gfx::PointF(),
2981 gfx::Size(3, 4),
2982 false);
2983 SetLayerPropertiesForTesting(child1.get(),
2984 identity_matrix,
2985 identity_matrix,
2986 gfx::PointF(),
2987 gfx::PointF(5.f, 5.f),
2988 gfx::Size(50, 50),
2989 false);
2990 SetLayerPropertiesForTesting(child2.get(),
2991 identity_matrix,
2992 identity_matrix,
2993 gfx::PointF(),
2994 gfx::PointF(75.f, 75.f),
2995 gfx::Size(50, 50),
2996 false);
2997 SetLayerPropertiesForTesting(child3.get(),
2998 identity_matrix,
2999 identity_matrix,
3000 gfx::PointF(),
3001 gfx::PointF(125.f, 125.f),
3002 gfx::Size(50, 50),
3003 false);
3004
3005 render_surface1->SetForceRenderSurface(true);
3006 ExecuteCalculateDrawProperties(root.get());
3007
3008 ASSERT_TRUE(render_surface1->render_surface());
3009
3010 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3011 root->render_surface()->DrawableContentRect());
3012 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3013
3014 // Layers that do not draw content should have empty visible content rects.
3015 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3016 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3017 render_surface1->visible_content_rect());
3018
3019 // An unclipped surface grows its DrawableContentRect to include all drawable
3020 // regions of the subtree.
3021 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3022 render_surface1->render_surface()->DrawableContentRect());
3023
3024 // All layers that draw content into the unclipped surface are also unclipped.
3025 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3026 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3027 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
3028
3029 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3030 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3031 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3032}
3033
[email protected]989386c2013-07-18 21:37:233034TEST_F(LayerTreeHostCommonTest,
3035 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:473036 scoped_refptr<Layer> root = Layer::Create();
3037 scoped_refptr<LayerWithForcedDrawsContent> child =
3038 make_scoped_refptr(new LayerWithForcedDrawsContent());
3039 root->AddChild(child);
3040
[email protected]d600df7d2013-08-03 02:34:283041 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3042 host->SetRootLayer(root);
3043
[email protected]630ddad2013-08-16 03:01:323044 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473045 gfx::Transform identity_matrix;
3046 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323047 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473048
3049 SetLayerPropertiesForTesting(root.get(),
3050 identity_matrix,
3051 identity_matrix,
3052 gfx::PointF(),
3053 gfx::PointF(),
3054 gfx::Size(100, 100),
3055 false);
3056 SetLayerPropertiesForTesting(child.get(),
3057 uninvertible_matrix,
3058 identity_matrix,
3059 gfx::PointF(),
3060 gfx::PointF(5.f, 5.f),
3061 gfx::Size(50, 50),
3062 false);
3063
3064 ExecuteCalculateDrawProperties(root.get());
3065
3066 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
3067 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323068
3069 // Case 2: a matrix with flattened z, technically uninvertible but still
3070 // drawable and visible. In this case, we must assume that the entire layer
3071 // bounds are visible since there is no way to inverse-project the surface
3072 // bounds to intersect.
3073 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263074 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323075 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3076
3077 SetLayerPropertiesForTesting(child.get(),
3078 uninvertible_matrix,
3079 identity_matrix,
3080 gfx::PointF(),
3081 gfx::PointF(5.f, 5.f),
3082 gfx::Size(50, 50),
3083 false);
3084
3085 ExecuteCalculateDrawProperties(root.get());
3086
3087 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child->visible_content_rect());
3088 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child->drawable_content_rect());
3089
3090 // Case 3: a matrix with flattened z, technically uninvertible but still
3091 // drawable, but not visible. In this case, we don't need to conservatively
3092 // assume that the whole layer is visible.
3093 uninvertible_matrix.MakeIdentity();
3094 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263095 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323096 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3097
3098 SetLayerPropertiesForTesting(child.get(),
3099 uninvertible_matrix,
3100 identity_matrix,
3101 gfx::PointF(),
3102 gfx::PointF(5.f, 5.f),
3103 gfx::Size(50, 50),
3104 false);
3105
3106 ExecuteCalculateDrawProperties(root.get());
3107
3108 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
3109 EXPECT_RECT_EQ(gfx::Rect(505, 5, 50, 50), child->drawable_content_rect());
[email protected]451107a32013-04-10 05:12:473110}
3111
[email protected]989386c2013-07-18 21:37:233112TEST_F(LayerTreeHostCommonTest,
3113 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:323114 scoped_refptr<Layer> root = Layer::Create();
3115 scoped_refptr<Layer> render_surface1 = Layer::Create();
3116 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3117 make_scoped_refptr(new LayerWithForcedDrawsContent());
3118 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3119 make_scoped_refptr(new LayerWithForcedDrawsContent());
3120 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3121 make_scoped_refptr(new LayerWithForcedDrawsContent());
3122 root->AddChild(render_surface1);
3123 render_surface1->AddChild(child1);
3124 render_surface1->AddChild(child2);
3125 render_surface1->AddChild(child3);
3126
[email protected]d600df7d2013-08-03 02:34:283127 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3128 host->SetRootLayer(root);
3129
[email protected]fb661802013-03-25 01:59:323130 gfx::Transform identity_matrix;
3131 SetLayerPropertiesForTesting(root.get(),
3132 identity_matrix,
3133 identity_matrix,
3134 gfx::PointF(),
3135 gfx::PointF(),
3136 gfx::Size(100, 100),
3137 false);
3138 SetLayerPropertiesForTesting(render_surface1.get(),
3139 identity_matrix,
3140 identity_matrix,
3141 gfx::PointF(),
3142 gfx::PointF(),
3143 gfx::Size(3, 4),
3144 false);
3145 SetLayerPropertiesForTesting(child1.get(),
3146 identity_matrix,
3147 identity_matrix,
3148 gfx::PointF(),
3149 gfx::PointF(5.f, 5.f),
3150 gfx::Size(50, 50),
3151 false);
3152 SetLayerPropertiesForTesting(child2.get(),
3153 identity_matrix,
3154 identity_matrix,
3155 gfx::PointF(),
3156 gfx::PointF(75.f, 75.f),
3157 gfx::Size(50, 50),
3158 false);
3159 SetLayerPropertiesForTesting(child3.get(),
3160 identity_matrix,
3161 identity_matrix,
3162 gfx::PointF(),
3163 gfx::PointF(125.f, 125.f),
3164 gfx::Size(50, 50),
3165 false);
3166
3167 root->SetMasksToBounds(true);
3168 render_surface1->SetForceRenderSurface(true);
3169 ExecuteCalculateDrawProperties(root.get());
3170
3171 ASSERT_TRUE(render_surface1->render_surface());
3172
3173 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3174 root->render_surface()->DrawableContentRect());
3175 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3176
3177 // Layers that do not draw content should have empty visible content rects.
3178 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3179 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3180 render_surface1->visible_content_rect());
3181
3182 // A clipped surface grows its DrawableContentRect to include all drawable
3183 // regions of the subtree, but also gets clamped by the ancestor's clip.
3184 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3185 render_surface1->render_surface()->DrawableContentRect());
3186
3187 // All layers that draw content into the surface have their visible content
3188 // rect clipped by the surface clip rect.
3189 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3190 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
3191 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3192
3193 // But the DrawableContentRects are unclipped.
3194 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3195 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3196 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3197}
3198
[email protected]989386c2013-07-18 21:37:233199TEST_F(LayerTreeHostCommonTest,
3200 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323201 // Check that clipping does not propagate down surfaces.
3202 scoped_refptr<Layer> root = Layer::Create();
3203 scoped_refptr<Layer> render_surface1 = Layer::Create();
3204 scoped_refptr<Layer> render_surface2 = Layer::Create();
3205 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3206 make_scoped_refptr(new LayerWithForcedDrawsContent());
3207 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3208 make_scoped_refptr(new LayerWithForcedDrawsContent());
3209 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3210 make_scoped_refptr(new LayerWithForcedDrawsContent());
3211 root->AddChild(render_surface1);
3212 render_surface1->AddChild(render_surface2);
3213 render_surface2->AddChild(child1);
3214 render_surface2->AddChild(child2);
3215 render_surface2->AddChild(child3);
3216
[email protected]d600df7d2013-08-03 02:34:283217 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3218 host->SetRootLayer(root);
3219
[email protected]fb661802013-03-25 01:59:323220 gfx::Transform identity_matrix;
3221 SetLayerPropertiesForTesting(root.get(),
3222 identity_matrix,
3223 identity_matrix,
3224 gfx::PointF(),
3225 gfx::PointF(),
3226 gfx::Size(100, 100),
3227 false);
3228 SetLayerPropertiesForTesting(render_surface1.get(),
3229 identity_matrix,
3230 identity_matrix,
3231 gfx::PointF(),
3232 gfx::PointF(),
3233 gfx::Size(3, 4),
3234 false);
3235 SetLayerPropertiesForTesting(render_surface2.get(),
3236 identity_matrix,
3237 identity_matrix,
3238 gfx::PointF(),
3239 gfx::PointF(),
3240 gfx::Size(7, 13),
3241 false);
3242 SetLayerPropertiesForTesting(child1.get(),
3243 identity_matrix,
3244 identity_matrix,
3245 gfx::PointF(),
3246 gfx::PointF(5.f, 5.f),
3247 gfx::Size(50, 50),
3248 false);
3249 SetLayerPropertiesForTesting(child2.get(),
3250 identity_matrix,
3251 identity_matrix,
3252 gfx::PointF(),
3253 gfx::PointF(75.f, 75.f),
3254 gfx::Size(50, 50),
3255 false);
3256 SetLayerPropertiesForTesting(child3.get(),
3257 identity_matrix,
3258 identity_matrix,
3259 gfx::PointF(),
3260 gfx::PointF(125.f, 125.f),
3261 gfx::Size(50, 50),
3262 false);
3263
3264 root->SetMasksToBounds(true);
3265 render_surface1->SetForceRenderSurface(true);
3266 render_surface2->SetForceRenderSurface(true);
3267 ExecuteCalculateDrawProperties(root.get());
3268
3269 ASSERT_TRUE(render_surface1->render_surface());
3270 ASSERT_TRUE(render_surface2->render_surface());
3271
3272 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3273 root->render_surface()->DrawableContentRect());
3274 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3275
3276 // Layers that do not draw content should have empty visible content rects.
3277 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3278 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3279 render_surface1->visible_content_rect());
3280 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3281 render_surface2->visible_content_rect());
3282
3283 // A clipped surface grows its DrawableContentRect to include all drawable
3284 // regions of the subtree, but also gets clamped by the ancestor's clip.
3285 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3286 render_surface1->render_surface()->DrawableContentRect());
3287
3288 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3289 // is only implicitly clipped by render_surface1's content rect. So,
3290 // render_surface2 grows to enclose all drawable content of its subtree.
3291 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3292 render_surface2->render_surface()->DrawableContentRect());
3293
3294 // All layers that draw content into render_surface2 think they are unclipped.
3295 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3296 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3297 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
3298
3299 // DrawableContentRects are also unclipped.
3300 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3301 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3302 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3303}
3304
[email protected]989386c2013-07-18 21:37:233305TEST_F(LayerTreeHostCommonTest,
3306 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323307 // Layers that have non-axis aligned bounds (due to transforms) have an
3308 // expanded, axis-aligned DrawableContentRect and visible content rect.
3309
3310 scoped_refptr<Layer> root = Layer::Create();
3311 scoped_refptr<Layer> render_surface1 = Layer::Create();
3312 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3313 make_scoped_refptr(new LayerWithForcedDrawsContent());
3314 root->AddChild(render_surface1);
3315 render_surface1->AddChild(child1);
3316
[email protected]d600df7d2013-08-03 02:34:283317 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3318 host->SetRootLayer(root);
3319
[email protected]fb661802013-03-25 01:59:323320 gfx::Transform identity_matrix;
3321 gfx::Transform child_rotation;
3322 child_rotation.Rotate(45.0);
3323 SetLayerPropertiesForTesting(root.get(),
3324 identity_matrix,
3325 identity_matrix,
3326 gfx::PointF(),
3327 gfx::PointF(),
3328 gfx::Size(100, 100),
3329 false);
3330 SetLayerPropertiesForTesting(render_surface1.get(),
3331 identity_matrix,
3332 identity_matrix,
3333 gfx::PointF(),
3334 gfx::PointF(),
3335 gfx::Size(3, 4),
3336 false);
3337 SetLayerPropertiesForTesting(child1.get(),
3338 child_rotation,
3339 identity_matrix,
3340 gfx::PointF(0.5f, 0.5f),
3341 gfx::PointF(25.f, 25.f),
3342 gfx::Size(50, 50),
3343 false);
3344
3345 render_surface1->SetForceRenderSurface(true);
3346 ExecuteCalculateDrawProperties(root.get());
3347
3348 ASSERT_TRUE(render_surface1->render_surface());
3349
3350 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3351 root->render_surface()->DrawableContentRect());
3352 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3353
3354 // Layers that do not draw content should have empty visible content rects.
3355 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3356 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3357 render_surface1->visible_content_rect());
3358
3359 // The unclipped surface grows its DrawableContentRect to include all drawable
3360 // regions of the subtree.
3361 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3362 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263363 gfx::Rect(50 - diagonal_radius,
3364 50 - diagonal_radius,
3365 diagonal_radius * 2,
3366 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323367 EXPECT_RECT_EQ(expected_surface_drawable_content,
3368 render_surface1->render_surface()->DrawableContentRect());
3369
3370 // All layers that draw content into the unclipped surface are also unclipped.
3371 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3372 EXPECT_RECT_EQ(expected_surface_drawable_content,
3373 child1->drawable_content_rect());
3374}
3375
[email protected]989386c2013-07-18 21:37:233376TEST_F(LayerTreeHostCommonTest,
3377 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323378 // Layers that have non-axis aligned bounds (due to transforms) have an
3379 // expanded, axis-aligned DrawableContentRect and visible content rect.
3380
3381 scoped_refptr<Layer> root = Layer::Create();
3382 scoped_refptr<Layer> render_surface1 = Layer::Create();
3383 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3384 make_scoped_refptr(new LayerWithForcedDrawsContent());
3385 root->AddChild(render_surface1);
3386 render_surface1->AddChild(child1);
3387
[email protected]d600df7d2013-08-03 02:34:283388 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3389 host->SetRootLayer(root);
3390
[email protected]fb661802013-03-25 01:59:323391 gfx::Transform identity_matrix;
3392 gfx::Transform child_rotation;
3393 child_rotation.Rotate(45.0);
3394 SetLayerPropertiesForTesting(root.get(),
3395 identity_matrix,
3396 identity_matrix,
3397 gfx::PointF(),
3398 gfx::PointF(),
3399 gfx::Size(50, 50),
3400 false);
3401 SetLayerPropertiesForTesting(render_surface1.get(),
3402 identity_matrix,
3403 identity_matrix,
3404 gfx::PointF(),
3405 gfx::PointF(),
3406 gfx::Size(3, 4),
3407 false);
3408 SetLayerPropertiesForTesting(child1.get(),
3409 child_rotation,
3410 identity_matrix,
3411 gfx::PointF(0.5f, 0.5f),
3412 gfx::PointF(25.f, 25.f),
3413 gfx::Size(50, 50),
3414 false);
3415
3416 root->SetMasksToBounds(true);
3417 render_surface1->SetForceRenderSurface(true);
3418 ExecuteCalculateDrawProperties(root.get());
3419
3420 ASSERT_TRUE(render_surface1->render_surface());
3421
3422 // The clipped surface clamps the DrawableContentRect that encloses the
3423 // rotated layer.
3424 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263425 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3426 50 - diagonal_radius,
3427 diagonal_radius * 2,
3428 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323429 gfx::Rect expected_surface_drawable_content =
3430 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
3431 EXPECT_RECT_EQ(expected_surface_drawable_content,
3432 render_surface1->render_surface()->DrawableContentRect());
3433
3434 // On the clipped surface, only a quarter of the child1 is visible, but when
3435 // rotating it back to child1's content space, the actual enclosing rect ends
3436 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263437 //
3438 // Given the floating point math, this number is a little bit fuzzy.
[email protected]fb661802013-03-25 01:59:323439 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
3440
3441 // The child's DrawableContentRect is unclipped.
3442 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3443}
3444
[email protected]989386c2013-07-18 21:37:233445TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323446 MockContentLayerClient client;
3447
3448 scoped_refptr<Layer> root = Layer::Create();
3449 scoped_refptr<ContentLayer> render_surface1 =
3450 CreateDrawableContentLayer(&client);
3451 scoped_refptr<ContentLayer> render_surface2 =
3452 CreateDrawableContentLayer(&client);
3453 scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client);
3454 scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client);
3455 scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client);
3456 root->AddChild(render_surface1);
3457 render_surface1->AddChild(render_surface2);
3458 render_surface2->AddChild(child1);
3459 render_surface2->AddChild(child2);
3460 render_surface2->AddChild(child3);
3461
[email protected]d600df7d2013-08-03 02:34:283462 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3463 host->SetRootLayer(root);
3464
[email protected]fb661802013-03-25 01:59:323465 gfx::Transform identity_matrix;
3466 SetLayerPropertiesForTesting(root.get(),
3467 identity_matrix,
3468 identity_matrix,
3469 gfx::PointF(),
3470 gfx::PointF(),
3471 gfx::Size(100, 100),
3472 false);
3473 SetLayerPropertiesForTesting(render_surface1.get(),
3474 identity_matrix,
3475 identity_matrix,
3476 gfx::PointF(),
3477 gfx::PointF(5.f, 5.f),
3478 gfx::Size(3, 4),
3479 false);
3480 SetLayerPropertiesForTesting(render_surface2.get(),
3481 identity_matrix,
3482 identity_matrix,
3483 gfx::PointF(),
3484 gfx::PointF(5.f, 5.f),
3485 gfx::Size(7, 13),
3486 false);
3487 SetLayerPropertiesForTesting(child1.get(),
3488 identity_matrix,
3489 identity_matrix,
3490 gfx::PointF(),
3491 gfx::PointF(5.f, 5.f),
3492 gfx::Size(50, 50),
3493 false);
3494 SetLayerPropertiesForTesting(child2.get(),
3495 identity_matrix,
3496 identity_matrix,
3497 gfx::PointF(),
3498 gfx::PointF(75.f, 75.f),
3499 gfx::Size(50, 50),
3500 false);
3501 SetLayerPropertiesForTesting(child3.get(),
3502 identity_matrix,
3503 identity_matrix,
3504 gfx::PointF(),
3505 gfx::PointF(125.f, 125.f),
3506 gfx::Size(50, 50),
3507 false);
3508
3509 float device_scale_factor = 2.f;
3510
3511 root->SetMasksToBounds(true);
3512 render_surface1->SetForceRenderSurface(true);
3513 render_surface2->SetForceRenderSurface(true);
3514 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3515
3516 ASSERT_TRUE(render_surface1->render_surface());
3517 ASSERT_TRUE(render_surface2->render_surface());
3518
3519 // drawable_content_rects for all layers and surfaces are scaled by
3520 // device_scale_factor.
3521 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3522 root->render_surface()->DrawableContentRect());
3523 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3524 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3525 render_surface1->render_surface()->DrawableContentRect());
3526
3527 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3528 // is only implicitly clipped by render_surface1.
3529 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3530 render_surface2->render_surface()->DrawableContentRect());
3531
3532 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3533 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3534 child2->drawable_content_rect());
3535 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3536 child3->drawable_content_rect());
3537
3538 // The root layer does not actually draw content of its own.
3539 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3540
3541 // All layer visible content rects are expressed in content space of each
3542 // layer, so they are also scaled by the device_scale_factor.
3543 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8),
3544 render_surface1->visible_content_rect());
3545 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26),
3546 render_surface2->visible_content_rect());
3547 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect());
3548 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect());
3549 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect());
3550}
3551
[email protected]989386c2013-07-18 21:37:233552TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323553 // Verify the behavior of back-face culling when there are no preserve-3d
3554 // layers. Note that 3d transforms still apply in this case, but they are
3555 // "flattened" to each parent layer according to current W3C spec.
3556
3557 const gfx::Transform identity_matrix;
3558 scoped_refptr<Layer> parent = Layer::Create();
3559 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3560 make_scoped_refptr(new LayerWithForcedDrawsContent());
3561 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3562 make_scoped_refptr(new LayerWithForcedDrawsContent());
3563 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3564 make_scoped_refptr(new LayerWithForcedDrawsContent());
3565 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3566 make_scoped_refptr(new LayerWithForcedDrawsContent());
3567 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233568 front_facing_child_of_front_facing_surface =
3569 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323570 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233571 back_facing_child_of_front_facing_surface =
3572 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323573 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233574 front_facing_child_of_back_facing_surface =
3575 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323576 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233577 back_facing_child_of_back_facing_surface =
3578 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323579
3580 parent->AddChild(front_facing_child);
3581 parent->AddChild(back_facing_child);
3582 parent->AddChild(front_facing_surface);
3583 parent->AddChild(back_facing_surface);
3584 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3585 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3586 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3587 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3588
[email protected]d600df7d2013-08-03 02:34:283589 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3590 host->SetRootLayer(parent);
3591
[email protected]fb661802013-03-25 01:59:323592 // Nothing is double-sided
3593 front_facing_child->SetDoubleSided(false);
3594 back_facing_child->SetDoubleSided(false);
3595 front_facing_surface->SetDoubleSided(false);
3596 back_facing_surface->SetDoubleSided(false);
3597 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3598 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3599 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3600 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3601
3602 gfx::Transform backface_matrix;
3603 backface_matrix.Translate(50.0, 50.0);
3604 backface_matrix.RotateAboutYAxis(180.0);
3605 backface_matrix.Translate(-50.0, -50.0);
3606
3607 // Having a descendant and opacity will force these to have render surfaces.
3608 front_facing_surface->SetOpacity(0.5f);
3609 back_facing_surface->SetOpacity(0.5f);
3610
3611 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3612 // these layers should blindly use their own local transforms to determine
3613 // back-face culling.
3614 SetLayerPropertiesForTesting(parent.get(),
3615 identity_matrix,
3616 identity_matrix,
3617 gfx::PointF(),
3618 gfx::PointF(),
3619 gfx::Size(100, 100),
3620 false);
3621 SetLayerPropertiesForTesting(front_facing_child.get(),
3622 identity_matrix,
3623 identity_matrix,
3624 gfx::PointF(),
3625 gfx::PointF(),
3626 gfx::Size(100, 100),
3627 false);
3628 SetLayerPropertiesForTesting(back_facing_child.get(),
3629 backface_matrix,
3630 identity_matrix,
3631 gfx::PointF(),
3632 gfx::PointF(),
3633 gfx::Size(100, 100),
3634 false);
3635 SetLayerPropertiesForTesting(front_facing_surface.get(),
3636 identity_matrix,
3637 identity_matrix,
3638 gfx::PointF(),
3639 gfx::PointF(),
3640 gfx::Size(100, 100),
3641 false);
3642 SetLayerPropertiesForTesting(back_facing_surface.get(),
3643 backface_matrix,
3644 identity_matrix,
3645 gfx::PointF(),
3646 gfx::PointF(),
3647 gfx::Size(100, 100),
3648 false);
3649 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3650 identity_matrix,
3651 identity_matrix,
3652 gfx::PointF(),
3653 gfx::PointF(),
3654 gfx::Size(100, 100),
3655 false);
3656 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3657 backface_matrix,
3658 identity_matrix,
3659 gfx::PointF(),
3660 gfx::PointF(),
3661 gfx::Size(100, 100),
3662 false);
3663 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3664 identity_matrix,
3665 identity_matrix,
3666 gfx::PointF(),
3667 gfx::PointF(),
3668 gfx::Size(100, 100),
3669 false);
3670 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3671 backface_matrix,
3672 identity_matrix,
3673 gfx::PointF(),
3674 gfx::PointF(),
3675 gfx::Size(100, 100),
3676 false);
3677
[email protected]989386c2013-07-18 21:37:233678 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533679 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3680 parent.get(), parent->bounds(), &render_surface_layer_list);
3681 inputs.can_adjust_raster_scales = true;
3682 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323683
3684 // Verify which render surfaces were created.
3685 EXPECT_FALSE(front_facing_child->render_surface());
3686 EXPECT_FALSE(back_facing_child->render_surface());
3687 EXPECT_TRUE(front_facing_surface->render_surface());
3688 EXPECT_TRUE(back_facing_surface->render_surface());
3689 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3690 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3691 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3692 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3693
3694 // Verify the render_surface_layer_list.
3695 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233696 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3697 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323698 // Even though the back facing surface LAYER gets culled, the other
3699 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233700 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323701
3702 // Verify root surface's layer list.
3703 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233704 3u,
3705 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3706 EXPECT_EQ(front_facing_child->id(),
3707 render_surface_layer_list.at(0)
3708 ->render_surface()->layer_list().at(0)->id());
3709 EXPECT_EQ(front_facing_surface->id(),
3710 render_surface_layer_list.at(0)
3711 ->render_surface()->layer_list().at(1)->id());
3712 EXPECT_EQ(back_facing_surface->id(),
3713 render_surface_layer_list.at(0)
3714 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:323715
3716 // Verify front_facing_surface's layer list.
3717 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233718 2u,
3719 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3720 EXPECT_EQ(front_facing_surface->id(),
3721 render_surface_layer_list.at(1)
3722 ->render_surface()->layer_list().at(0)->id());
3723 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3724 render_surface_layer_list.at(1)
3725 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323726
3727 // Verify back_facing_surface's layer list; its own layer should be culled
3728 // from the surface list.
3729 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233730 1u,
3731 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3732 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3733 render_surface_layer_list.at(2)
3734 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:323735}
3736
[email protected]989386c2013-07-18 21:37:233737TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323738 // Verify the behavior of back-face culling when preserves-3d transform style
3739 // is used.
3740
3741 const gfx::Transform identity_matrix;
3742 scoped_refptr<Layer> parent = Layer::Create();
3743 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3744 make_scoped_refptr(new LayerWithForcedDrawsContent());
3745 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3746 make_scoped_refptr(new LayerWithForcedDrawsContent());
3747 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3748 make_scoped_refptr(new LayerWithForcedDrawsContent());
3749 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3750 make_scoped_refptr(new LayerWithForcedDrawsContent());
3751 scoped_refptr<LayerWithForcedDrawsContent>
3752 front_facing_child_of_front_facing_surface =
3753 make_scoped_refptr(new LayerWithForcedDrawsContent());
3754 scoped_refptr<LayerWithForcedDrawsContent>
3755 back_facing_child_of_front_facing_surface =
3756 make_scoped_refptr(new LayerWithForcedDrawsContent());
3757 scoped_refptr<LayerWithForcedDrawsContent>
3758 front_facing_child_of_back_facing_surface =
3759 make_scoped_refptr(new LayerWithForcedDrawsContent());
3760 scoped_refptr<LayerWithForcedDrawsContent>
3761 back_facing_child_of_back_facing_surface =
3762 make_scoped_refptr(new LayerWithForcedDrawsContent());
3763 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3764 make_scoped_refptr(new LayerWithForcedDrawsContent());
3765 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3766 make_scoped_refptr(new LayerWithForcedDrawsContent());
3767
3768 parent->AddChild(front_facing_child);
3769 parent->AddChild(back_facing_child);
3770 parent->AddChild(front_facing_surface);
3771 parent->AddChild(back_facing_surface);
3772 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3773 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3774 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3775 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3776
[email protected]d600df7d2013-08-03 02:34:283777 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3778 host->SetRootLayer(parent);
3779
[email protected]fb661802013-03-25 01:59:323780 // Nothing is double-sided
3781 front_facing_child->SetDoubleSided(false);
3782 back_facing_child->SetDoubleSided(false);
3783 front_facing_surface->SetDoubleSided(false);
3784 back_facing_surface->SetDoubleSided(false);
3785 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3786 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3787 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3788 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3789
3790 gfx::Transform backface_matrix;
3791 backface_matrix.Translate(50.0, 50.0);
3792 backface_matrix.RotateAboutYAxis(180.0);
3793 backface_matrix.Translate(-50.0, -50.0);
3794
3795 // Opacity will not force creation of render surfaces in this case because of
3796 // the preserve-3d transform style. Instead, an example of when a surface
3797 // would be created with preserve-3d is when there is a replica layer.
3798 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3799 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3800
3801 // Each surface creates its own new 3d rendering context (as defined by W3C
3802 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3803 // rendering context should use the transform with respect to that context.
3804 // This 3d rendering context occurs when (a) parent's transform style is flat
3805 // and (b) the layer's transform style is preserve-3d.
3806 SetLayerPropertiesForTesting(parent.get(),
3807 identity_matrix,
3808 identity_matrix,
3809 gfx::PointF(),
3810 gfx::PointF(),
3811 gfx::Size(100, 100),
3812 false); // parent transform style is flat.
3813 SetLayerPropertiesForTesting(front_facing_child.get(),
3814 identity_matrix,
3815 identity_matrix,
3816 gfx::PointF(),
3817 gfx::PointF(),
3818 gfx::Size(100, 100),
3819 false);
3820 SetLayerPropertiesForTesting(back_facing_child.get(),
3821 backface_matrix,
3822 identity_matrix,
3823 gfx::PointF(),
3824 gfx::PointF(),
3825 gfx::Size(100, 100),
3826 false);
3827 SetLayerPropertiesForTesting(
3828 front_facing_surface.get(),
3829 identity_matrix,
3830 identity_matrix,
3831 gfx::PointF(),
3832 gfx::PointF(),
3833 gfx::Size(100, 100),
3834 true); // surface transform style is preserve-3d.
3835 SetLayerPropertiesForTesting(
3836 back_facing_surface.get(),
3837 backface_matrix,
3838 identity_matrix,
3839 gfx::PointF(),
3840 gfx::PointF(),
3841 gfx::Size(100, 100),
3842 true); // surface transform style is preserve-3d.
3843 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3844 identity_matrix,
3845 identity_matrix,
3846 gfx::PointF(),
3847 gfx::PointF(),
3848 gfx::Size(100, 100),
3849 false);
3850 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3851 backface_matrix,
3852 identity_matrix,
3853 gfx::PointF(),
3854 gfx::PointF(),
3855 gfx::Size(100, 100),
3856 false);
3857 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3858 identity_matrix,
3859 identity_matrix,
3860 gfx::PointF(),
3861 gfx::PointF(),
3862 gfx::Size(100, 100),
3863 false);
3864 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3865 backface_matrix,
3866 identity_matrix,
3867 gfx::PointF(),
3868 gfx::PointF(),
3869 gfx::Size(100, 100),
3870 false);
3871
[email protected]989386c2013-07-18 21:37:233872 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533873 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3874 parent.get(), parent->bounds(), &render_surface_layer_list);
3875 inputs.can_adjust_raster_scales = true;
3876 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323877
3878 // Verify which render surfaces were created.
3879 EXPECT_FALSE(front_facing_child->render_surface());
3880 EXPECT_FALSE(back_facing_child->render_surface());
3881 EXPECT_TRUE(front_facing_surface->render_surface());
3882 EXPECT_FALSE(back_facing_surface->render_surface());
3883 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3884 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3885 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3886 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3887
3888 // Verify the render_surface_layer_list. The back-facing surface should be
3889 // culled.
3890 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233891 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3892 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323893
3894 // Verify root surface's layer list.
3895 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233896 2u,
3897 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3898 EXPECT_EQ(front_facing_child->id(),
3899 render_surface_layer_list.at(0)
3900 ->render_surface()->layer_list().at(0)->id());
3901 EXPECT_EQ(front_facing_surface->id(),
3902 render_surface_layer_list.at(0)
3903 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323904
3905 // Verify front_facing_surface's layer list.
3906 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233907 2u,
3908 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3909 EXPECT_EQ(front_facing_surface->id(),
3910 render_surface_layer_list.at(1)
3911 ->render_surface()->layer_list().at(0)->id());
3912 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3913 render_surface_layer_list.at(1)
3914 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323915}
3916
[email protected]989386c2013-07-18 21:37:233917TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323918 // Verify that layers are appropriately culled when their back face is showing
3919 // and they are not double sided, while animations are going on.
3920 //
3921 // Layers that are animating do not get culled on the main thread, as their
3922 // transforms should be treated as "unknown" so we can not be sure that their
3923 // back face is really showing.
3924 const gfx::Transform identity_matrix;
3925 scoped_refptr<Layer> parent = Layer::Create();
3926 scoped_refptr<LayerWithForcedDrawsContent> child =
3927 make_scoped_refptr(new LayerWithForcedDrawsContent());
3928 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3929 make_scoped_refptr(new LayerWithForcedDrawsContent());
3930 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3931 make_scoped_refptr(new LayerWithForcedDrawsContent());
3932 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3933 make_scoped_refptr(new LayerWithForcedDrawsContent());
3934 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3935 make_scoped_refptr(new LayerWithForcedDrawsContent());
3936
3937 parent->AddChild(child);
3938 parent->AddChild(animating_surface);
3939 animating_surface->AddChild(child_of_animating_surface);
3940 parent->AddChild(animating_child);
3941 parent->AddChild(child2);
3942
[email protected]d600df7d2013-08-03 02:34:283943 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3944 host->SetRootLayer(parent);
3945
[email protected]fb661802013-03-25 01:59:323946 // Nothing is double-sided
3947 child->SetDoubleSided(false);
3948 child2->SetDoubleSided(false);
3949 animating_surface->SetDoubleSided(false);
3950 child_of_animating_surface->SetDoubleSided(false);
3951 animating_child->SetDoubleSided(false);
3952
3953 gfx::Transform backface_matrix;
3954 backface_matrix.Translate(50.0, 50.0);
3955 backface_matrix.RotateAboutYAxis(180.0);
3956 backface_matrix.Translate(-50.0, -50.0);
3957
3958 // Make our render surface.
3959 animating_surface->SetForceRenderSurface(true);
3960
3961 // Animate the transform on the render surface.
3962 AddAnimatedTransformToController(
3963 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3964 // This is just an animating layer, not a surface.
3965 AddAnimatedTransformToController(
3966 animating_child->layer_animation_controller(), 10.0, 30, 0);
3967
3968 SetLayerPropertiesForTesting(parent.get(),
3969 identity_matrix,
3970 identity_matrix,
3971 gfx::PointF(),
3972 gfx::PointF(),
3973 gfx::Size(100, 100),
3974 false);
3975 SetLayerPropertiesForTesting(child.get(),
3976 backface_matrix,
3977 identity_matrix,
3978 gfx::PointF(),
3979 gfx::PointF(),
3980 gfx::Size(100, 100),
3981 false);
3982 SetLayerPropertiesForTesting(animating_surface.get(),
3983 backface_matrix,
3984 identity_matrix,
3985 gfx::PointF(),
3986 gfx::PointF(),
3987 gfx::Size(100, 100),
3988 false);
3989 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3990 backface_matrix,
3991 identity_matrix,
3992 gfx::PointF(),
3993 gfx::PointF(),
3994 gfx::Size(100, 100),
3995 false);
3996 SetLayerPropertiesForTesting(animating_child.get(),
3997 backface_matrix,
3998 identity_matrix,
3999 gfx::PointF(),
4000 gfx::PointF(),
4001 gfx::Size(100, 100),
4002 false);
4003 SetLayerPropertiesForTesting(child2.get(),
4004 identity_matrix,
4005 identity_matrix,
4006 gfx::PointF(),
4007 gfx::PointF(),
4008 gfx::Size(100, 100),
4009 false);
4010
[email protected]989386c2013-07-18 21:37:234011 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534012 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4013 parent.get(), parent->bounds(), &render_surface_layer_list);
4014 inputs.can_adjust_raster_scales = true;
4015 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324016
4017 EXPECT_FALSE(child->render_surface());
4018 EXPECT_TRUE(animating_surface->render_surface());
4019 EXPECT_FALSE(child_of_animating_surface->render_surface());
4020 EXPECT_FALSE(animating_child->render_surface());
4021 EXPECT_FALSE(child2->render_surface());
4022
4023 // Verify that the animating_child and child_of_animating_surface were not
4024 // culled, but that child was.
4025 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234026 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4027 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324028
4029 // The non-animating child be culled from the layer list for the parent render
4030 // surface.
4031 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234032 3u,
4033 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4034 EXPECT_EQ(animating_surface->id(),
4035 render_surface_layer_list.at(0)
4036 ->render_surface()->layer_list().at(0)->id());
4037 EXPECT_EQ(animating_child->id(),
4038 render_surface_layer_list.at(0)
4039 ->render_surface()->layer_list().at(1)->id());
4040 EXPECT_EQ(child2->id(),
4041 render_surface_layer_list.at(0)
4042 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:324043
4044 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234045 2u,
4046 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4047 EXPECT_EQ(animating_surface->id(),
4048 render_surface_layer_list.at(1)
4049 ->render_surface()->layer_list().at(0)->id());
4050 EXPECT_EQ(child_of_animating_surface->id(),
4051 render_surface_layer_list.at(1)
4052 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324053
4054 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
4055
4056 // The animating layers should have a visible content rect that represents the
4057 // area of the front face that is within the viewport.
4058 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054059 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:324060 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054061 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324062 // And layers in the subtree of the animating layer should have valid visible
4063 // content rects also.
[email protected]989386c2013-07-18 21:37:234064 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
4065 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324066}
4067
[email protected]989386c2013-07-18 21:37:234068TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324069 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4070 // Verify the behavior of back-face culling for a render surface that is
4071 // created when it flattens its subtree, and its parent has preserves-3d.
4072
4073 const gfx::Transform identity_matrix;
4074 scoped_refptr<Layer> parent = Layer::Create();
4075 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
4076 make_scoped_refptr(new LayerWithForcedDrawsContent());
4077 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
4078 make_scoped_refptr(new LayerWithForcedDrawsContent());
4079 scoped_refptr<LayerWithForcedDrawsContent> child1 =
4080 make_scoped_refptr(new LayerWithForcedDrawsContent());
4081 scoped_refptr<LayerWithForcedDrawsContent> child2 =
4082 make_scoped_refptr(new LayerWithForcedDrawsContent());
4083
4084 parent->AddChild(front_facing_surface);
4085 parent->AddChild(back_facing_surface);
4086 front_facing_surface->AddChild(child1);
4087 back_facing_surface->AddChild(child2);
4088
[email protected]d600df7d2013-08-03 02:34:284089 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4090 host->SetRootLayer(parent);
4091
[email protected]fb661802013-03-25 01:59:324092 // RenderSurfaces are not double-sided
4093 front_facing_surface->SetDoubleSided(false);
4094 back_facing_surface->SetDoubleSided(false);
4095
4096 gfx::Transform backface_matrix;
4097 backface_matrix.Translate(50.0, 50.0);
4098 backface_matrix.RotateAboutYAxis(180.0);
4099 backface_matrix.Translate(-50.0, -50.0);
4100
4101 SetLayerPropertiesForTesting(parent.get(),
4102 identity_matrix,
4103 identity_matrix,
4104 gfx::PointF(),
4105 gfx::PointF(),
4106 gfx::Size(100, 100),
4107 true); // parent transform style is preserve3d.
4108 SetLayerPropertiesForTesting(front_facing_surface.get(),
4109 identity_matrix,
4110 identity_matrix,
4111 gfx::PointF(),
4112 gfx::PointF(),
4113 gfx::Size(100, 100),
4114 false); // surface transform style is flat.
4115 SetLayerPropertiesForTesting(back_facing_surface.get(),
4116 backface_matrix,
4117 identity_matrix,
4118 gfx::PointF(),
4119 gfx::PointF(),
4120 gfx::Size(100, 100),
4121 false); // surface transform style is flat.
4122 SetLayerPropertiesForTesting(child1.get(),
4123 identity_matrix,
4124 identity_matrix,
4125 gfx::PointF(),
4126 gfx::PointF(),
4127 gfx::Size(100, 100),
4128 false);
4129 SetLayerPropertiesForTesting(child2.get(),
4130 identity_matrix,
4131 identity_matrix,
4132 gfx::PointF(),
4133 gfx::PointF(),
4134 gfx::Size(100, 100),
4135 false);
4136
[email protected]989386c2013-07-18 21:37:234137 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534138 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4139 parent.get(), parent->bounds(), &render_surface_layer_list);
4140 inputs.can_adjust_raster_scales = true;
4141 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324142
4143 // Verify which render surfaces were created.
4144 EXPECT_TRUE(front_facing_surface->render_surface());
4145 EXPECT_FALSE(
4146 back_facing_surface->render_surface()); // because it should be culled
4147 EXPECT_FALSE(child1->render_surface());
4148 EXPECT_FALSE(child2->render_surface());
4149
4150 // Verify the render_surface_layer_list. The back-facing surface should be
4151 // culled.
4152 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234153 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4154 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324155
4156 // Verify root surface's layer list.
4157 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234158 1u,
4159 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4160 EXPECT_EQ(front_facing_surface->id(),
4161 render_surface_layer_list.at(0)
4162 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324163
4164 // Verify front_facing_surface's layer list.
4165 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234166 2u,
4167 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4168 EXPECT_EQ(front_facing_surface->id(),
4169 render_surface_layer_list.at(1)
4170 ->render_surface()->layer_list().at(0)->id());
4171 EXPECT_EQ(child1->id(),
4172 render_surface_layer_list.at(1)
4173 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324174}
4175
[email protected]989386c2013-07-18 21:37:234176
4177TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:324178 // Hit testing on an empty render_surface_layer_list should return a null
4179 // pointer.
[email protected]50761e92013-03-29 20:51:284180 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:324181
4182 gfx::Point test_point(0, 0);
4183 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4184 test_point, render_surface_layer_list);
4185 EXPECT_FALSE(result_layer);
4186
4187 test_point = gfx::Point(10, 20);
4188 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4189 test_point, render_surface_layer_list);
4190 EXPECT_FALSE(result_layer);
4191}
4192
[email protected]989386c2013-07-18 21:37:234193TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayer) {
[email protected]fb661802013-03-25 01:59:324194 FakeImplProxy proxy;
4195 FakeLayerTreeHostImpl host_impl(&proxy);
4196 scoped_ptr<LayerImpl> root =
4197 LayerImpl::Create(host_impl.active_tree(), 12345);
4198
4199 gfx::Transform identity_matrix;
4200 gfx::PointF anchor;
4201 gfx::PointF position;
4202 gfx::Size bounds(100, 100);
4203 SetLayerPropertiesForTesting(root.get(),
4204 identity_matrix,
4205 identity_matrix,
4206 anchor,
4207 position,
4208 bounds,
4209 false);
4210 root->SetDrawsContent(true);
4211
[email protected]50761e92013-03-29 20:51:284212 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534213 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4214 root.get(), root->bounds(), &render_surface_layer_list);
4215 inputs.can_adjust_raster_scales = true;
4216 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324217
4218 // Sanity check the scenario we just created.
4219 ASSERT_EQ(1u, render_surface_layer_list.size());
4220 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4221
4222 // Hit testing for a point outside the layer should return a null pointer.
4223 gfx::Point test_point(101, 101);
4224 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4225 test_point, render_surface_layer_list);
4226 EXPECT_FALSE(result_layer);
4227
4228 test_point = gfx::Point(-1, -1);
4229 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4230 test_point, render_surface_layer_list);
4231 EXPECT_FALSE(result_layer);
4232
4233 // Hit testing for a point inside should return the root layer.
4234 test_point = gfx::Point(1, 1);
4235 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4236 test_point, render_surface_layer_list);
4237 ASSERT_TRUE(result_layer);
4238 EXPECT_EQ(12345, result_layer->id());
4239
4240 test_point = gfx::Point(99, 99);
4241 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4242 test_point, render_surface_layer_list);
4243 ASSERT_TRUE(result_layer);
4244 EXPECT_EQ(12345, result_layer->id());
4245}
4246
[email protected]989386c2013-07-18 21:37:234247TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) {
[email protected]fb661802013-03-25 01:59:324248 FakeImplProxy proxy;
4249 FakeLayerTreeHostImpl host_impl(&proxy);
4250 scoped_ptr<LayerImpl> root =
4251 LayerImpl::Create(host_impl.active_tree(), 12345);
4252 scoped_ptr<HeadsUpDisplayLayerImpl> hud =
4253 HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111);
4254
4255 gfx::Transform identity_matrix;
4256 gfx::PointF anchor;
4257 gfx::PointF position;
4258 gfx::Size bounds(100, 100);
4259 SetLayerPropertiesForTesting(root.get(),
4260 identity_matrix,
4261 identity_matrix,
4262 anchor,
4263 position,
4264 bounds,
4265 false);
4266 root->SetDrawsContent(true);
4267
4268 // Create hud and add it as a child of root.
4269 gfx::Size hud_bounds(200, 200);
4270 SetLayerPropertiesForTesting(hud.get(),
4271 identity_matrix,
4272 identity_matrix,
4273 anchor,
4274 position,
4275 hud_bounds,
4276 false);
4277 hud->SetDrawsContent(true);
4278
4279 host_impl.active_tree()->set_hud_layer(hud.get());
4280 root->AddChild(hud.PassAs<LayerImpl>());
4281
[email protected]50761e92013-03-29 20:51:284282 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534283 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4284 root.get(), hud_bounds, &render_surface_layer_list);
4285 inputs.can_adjust_raster_scales = true;
4286 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324287
4288 // Sanity check the scenario we just created.
4289 ASSERT_EQ(1u, render_surface_layer_list.size());
4290 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4291
4292 // Hit testing for a point inside HUD, but outside root should return null
4293 gfx::Point test_point(101, 101);
4294 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4295 test_point, render_surface_layer_list);
4296 EXPECT_FALSE(result_layer);
4297
4298 test_point = gfx::Point(-1, -1);
4299 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4300 test_point, render_surface_layer_list);
4301 EXPECT_FALSE(result_layer);
4302
4303 // Hit testing for a point inside should return the root layer, never the HUD
4304 // layer.
4305 test_point = gfx::Point(1, 1);
4306 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4307 test_point, render_surface_layer_list);
4308 ASSERT_TRUE(result_layer);
4309 EXPECT_EQ(12345, result_layer->id());
4310
4311 test_point = gfx::Point(99, 99);
4312 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4313 test_point, render_surface_layer_list);
4314 ASSERT_TRUE(result_layer);
4315 EXPECT_EQ(12345, result_layer->id());
4316}
4317
[email protected]989386c2013-07-18 21:37:234318TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) {
[email protected]fb661802013-03-25 01:59:324319 FakeImplProxy proxy;
4320 FakeLayerTreeHostImpl host_impl(&proxy);
4321 scoped_ptr<LayerImpl> root =
4322 LayerImpl::Create(host_impl.active_tree(), 12345);
4323
4324 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:264325 uninvertible_transform.matrix().set(0, 0, 0.0);
4326 uninvertible_transform.matrix().set(1, 1, 0.0);
4327 uninvertible_transform.matrix().set(2, 2, 0.0);
4328 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:324329 ASSERT_FALSE(uninvertible_transform.IsInvertible());
4330
4331 gfx::Transform identity_matrix;
4332 gfx::PointF anchor;
4333 gfx::PointF position;
4334 gfx::Size bounds(100, 100);
4335 SetLayerPropertiesForTesting(root.get(),
4336 uninvertible_transform,
4337 identity_matrix,
4338 anchor,
4339 position,
4340 bounds,
4341 false);
4342 root->SetDrawsContent(true);
4343
[email protected]50761e92013-03-29 20:51:284344 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534345 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4346 root.get(), root->bounds(), &render_surface_layer_list);
4347 inputs.can_adjust_raster_scales = true;
4348 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324349
4350 // Sanity check the scenario we just created.
4351 ASSERT_EQ(1u, render_surface_layer_list.size());
4352 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4353 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
4354
4355 // Hit testing any point should not hit the layer. If the invertible matrix is
4356 // accidentally ignored and treated like an identity, then the hit testing
4357 // will incorrectly hit the layer when it shouldn't.
4358 gfx::Point test_point(1, 1);
4359 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4360 test_point, render_surface_layer_list);
4361 EXPECT_FALSE(result_layer);
4362
4363 test_point = gfx::Point(10, 10);
4364 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4365 test_point, render_surface_layer_list);
4366 EXPECT_FALSE(result_layer);
4367
4368 test_point = gfx::Point(10, 30);
4369 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4370 test_point, render_surface_layer_list);
4371 EXPECT_FALSE(result_layer);
4372
4373 test_point = gfx::Point(50, 50);
4374 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4375 test_point, render_surface_layer_list);
4376 EXPECT_FALSE(result_layer);
4377
4378 test_point = gfx::Point(67, 48);
4379 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4380 test_point, render_surface_layer_list);
4381 EXPECT_FALSE(result_layer);
4382
4383 test_point = gfx::Point(99, 99);
4384 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4385 test_point, render_surface_layer_list);
4386 EXPECT_FALSE(result_layer);
4387
4388 test_point = gfx::Point(-1, -1);
4389 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4390 test_point, render_surface_layer_list);
4391 EXPECT_FALSE(result_layer);
4392}
4393
[email protected]989386c2013-07-18 21:37:234394TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) {
[email protected]fb661802013-03-25 01:59:324395 FakeImplProxy proxy;
4396 FakeLayerTreeHostImpl host_impl(&proxy);
4397 scoped_ptr<LayerImpl> root =
4398 LayerImpl::Create(host_impl.active_tree(), 12345);
4399
4400 gfx::Transform identity_matrix;
4401 gfx::PointF anchor;
4402 // this layer is positioned, and hit testing should correctly know where the
4403 // layer is located.
4404 gfx::PointF position(50.f, 50.f);
4405 gfx::Size bounds(100, 100);
4406 SetLayerPropertiesForTesting(root.get(),
4407 identity_matrix,
4408 identity_matrix,
4409 anchor,
4410 position,
4411 bounds,
4412 false);
4413 root->SetDrawsContent(true);
4414
[email protected]50761e92013-03-29 20:51:284415 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534416 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4417 root.get(), root->bounds(), &render_surface_layer_list);
4418 inputs.can_adjust_raster_scales = true;
4419 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324420
4421 // Sanity check the scenario we just created.
4422 ASSERT_EQ(1u, render_surface_layer_list.size());
4423 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4424
4425 // Hit testing for a point outside the layer should return a null pointer.
4426 gfx::Point test_point(49, 49);
4427 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4428 test_point, render_surface_layer_list);
4429 EXPECT_FALSE(result_layer);
4430
4431 // Even though the layer exists at (101, 101), it should not be visible there
4432 // since the root render surface would clamp it.
4433 test_point = gfx::Point(101, 101);
4434 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4435 test_point, render_surface_layer_list);
4436 EXPECT_FALSE(result_layer);
4437
4438 // Hit testing for a point inside should return the root layer.
4439 test_point = gfx::Point(51, 51);
4440 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4441 test_point, render_surface_layer_list);
4442 ASSERT_TRUE(result_layer);
4443 EXPECT_EQ(12345, result_layer->id());
4444
4445 test_point = gfx::Point(99, 99);
4446 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4447 test_point, render_surface_layer_list);
4448 ASSERT_TRUE(result_layer);
4449 EXPECT_EQ(12345, result_layer->id());
4450}
4451
[email protected]989386c2013-07-18 21:37:234452TEST_F(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324453 FakeImplProxy proxy;
4454 FakeLayerTreeHostImpl host_impl(&proxy);
4455 scoped_ptr<LayerImpl> root =
4456 LayerImpl::Create(host_impl.active_tree(), 12345);
4457
4458 gfx::Transform identity_matrix;
4459 gfx::Transform rotation45_degrees_about_center;
4460 rotation45_degrees_about_center.Translate(50.0, 50.0);
4461 rotation45_degrees_about_center.RotateAboutZAxis(45.0);
4462 rotation45_degrees_about_center.Translate(-50.0, -50.0);
4463 gfx::PointF anchor;
4464 gfx::PointF position;
4465 gfx::Size bounds(100, 100);
4466 SetLayerPropertiesForTesting(root.get(),
4467 rotation45_degrees_about_center,
4468 identity_matrix,
4469 anchor,
4470 position,
4471 bounds,
4472 false);
4473 root->SetDrawsContent(true);
4474
[email protected]50761e92013-03-29 20:51:284475 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534476 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4477 root.get(), root->bounds(), &render_surface_layer_list);
4478 inputs.can_adjust_raster_scales = true;
4479 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324480
4481 // Sanity check the scenario we just created.
4482 ASSERT_EQ(1u, render_surface_layer_list.size());
4483 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4484
4485 // Hit testing for points outside the layer.
4486 // These corners would have been inside the un-transformed layer, but they
4487 // should not hit the correctly transformed layer.
4488 gfx::Point test_point(99, 99);
4489 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4490 test_point, render_surface_layer_list);
4491 EXPECT_FALSE(result_layer);
4492
4493 test_point = gfx::Point(1, 1);
4494 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4495 test_point, render_surface_layer_list);
4496 EXPECT_FALSE(result_layer);
4497
4498 // Hit testing for a point inside should return the root layer.
4499 test_point = gfx::Point(1, 50);
4500 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4501 test_point, render_surface_layer_list);
4502 ASSERT_TRUE(result_layer);
4503 EXPECT_EQ(12345, result_layer->id());
4504
4505 // Hit testing the corners that would overlap the unclipped layer, but are
4506 // outside the clipped region.
4507 test_point = gfx::Point(50, -1);
4508 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4509 test_point, render_surface_layer_list);
4510 ASSERT_FALSE(result_layer);
4511
4512 test_point = gfx::Point(-1, 50);
4513 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4514 test_point, render_surface_layer_list);
4515 ASSERT_FALSE(result_layer);
4516}
4517
[email protected]989386c2013-07-18 21:37:234518TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) {
[email protected]fb661802013-03-25 01:59:324519 FakeImplProxy proxy;
4520 FakeLayerTreeHostImpl host_impl(&proxy);
4521 scoped_ptr<LayerImpl> root =
4522 LayerImpl::Create(host_impl.active_tree(), 12345);
4523
4524 gfx::Transform identity_matrix;
4525
4526 // perspective_projection_about_center * translation_by_z is designed so that
4527 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
4528 gfx::Transform perspective_projection_about_center;
4529 perspective_projection_about_center.Translate(50.0, 50.0);
4530 perspective_projection_about_center.ApplyPerspectiveDepth(1.0);
4531 perspective_projection_about_center.Translate(-50.0, -50.0);
4532 gfx::Transform translation_by_z;
4533 translation_by_z.Translate3d(0.0, 0.0, -1.0);
4534
4535 gfx::PointF anchor;
4536 gfx::PointF position;
4537 gfx::Size bounds(100, 100);
4538 SetLayerPropertiesForTesting(
4539 root.get(),
4540 perspective_projection_about_center * translation_by_z,
4541 identity_matrix,
4542 anchor,
4543 position,
4544 bounds,
4545 false);
4546 root->SetDrawsContent(true);
4547
[email protected]50761e92013-03-29 20:51:284548 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534549 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4550 root.get(), root->bounds(), &render_surface_layer_list);
4551 inputs.can_adjust_raster_scales = true;
4552 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324553
4554 // Sanity check the scenario we just created.
4555 ASSERT_EQ(1u, render_surface_layer_list.size());
4556 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4557
4558 // Hit testing for points outside the layer.
4559 // These corners would have been inside the un-transformed layer, but they
4560 // should not hit the correctly transformed layer.
4561 gfx::Point test_point(24, 24);
4562 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4563 test_point, render_surface_layer_list);
4564 EXPECT_FALSE(result_layer);
4565
4566 test_point = gfx::Point(76, 76);
4567 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4568 test_point, render_surface_layer_list);
4569 EXPECT_FALSE(result_layer);
4570
4571 // Hit testing for a point inside should return the root layer.
4572 test_point = gfx::Point(26, 26);
4573 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4574 test_point, render_surface_layer_list);
4575 ASSERT_TRUE(result_layer);
4576 EXPECT_EQ(12345, result_layer->id());
4577
4578 test_point = gfx::Point(74, 74);
4579 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4580 test_point, render_surface_layer_list);
4581 ASSERT_TRUE(result_layer);
4582 EXPECT_EQ(12345, result_layer->id());
4583}
4584
[email protected]989386c2013-07-18 21:37:234585TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) {
[email protected]fb661802013-03-25 01:59:324586 // A layer's visible content rect is actually in the layer's content space.
4587 // The screen space transform converts from the layer's origin space to screen
4588 // space. This test makes sure that hit testing works correctly accounts for
4589 // the contents scale. A contents scale that is not 1 effectively forces a
4590 // non-identity transform between layer's content space and layer's origin
4591 // space. The hit testing code must take this into account.
4592 //
4593 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
4594 // contents scale is ignored, then hit testing will mis-interpret the visible
4595 // content rect as being larger than the actual bounds of the layer.
4596 //
4597 FakeImplProxy proxy;
4598 FakeLayerTreeHostImpl host_impl(&proxy);
4599 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4600
4601 gfx::Transform identity_matrix;
4602 gfx::PointF anchor;
4603
4604 SetLayerPropertiesForTesting(root.get(),
4605 identity_matrix,
4606 identity_matrix,
4607 anchor,
4608 gfx::PointF(),
4609 gfx::Size(100, 100),
4610 false);
4611 {
4612 gfx::PointF position(25.f, 25.f);
4613 gfx::Size bounds(50, 50);
4614 scoped_ptr<LayerImpl> test_layer =
4615 LayerImpl::Create(host_impl.active_tree(), 12345);
4616 SetLayerPropertiesForTesting(test_layer.get(),
4617 identity_matrix,
4618 identity_matrix,
4619 anchor,
4620 position,
4621 bounds,
4622 false);
4623
4624 // override content bounds and contents scale
4625 test_layer->SetContentBounds(gfx::Size(100, 100));
4626 test_layer->SetContentsScale(2, 2);
4627
4628 test_layer->SetDrawsContent(true);
4629 root->AddChild(test_layer.Pass());
4630 }
4631
[email protected]50761e92013-03-29 20:51:284632 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534633 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4634 root.get(), root->bounds(), &render_surface_layer_list);
4635 inputs.can_adjust_raster_scales = true;
4636 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324637
4638 // Sanity check the scenario we just created.
4639 // The visible content rect for test_layer is actually 100x100, even though
4640 // its layout size is 50x50, positioned at 25x25.
4641 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:054642 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
[email protected]fb661802013-03-25 01:59:324643 test_layer->visible_content_rect());
4644 ASSERT_EQ(1u, render_surface_layer_list.size());
4645 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4646
4647 // Hit testing for a point outside the layer should return a null pointer (the
4648 // root layer does not draw content, so it will not be hit tested either).
4649 gfx::Point test_point(101, 101);
4650 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4651 test_point, render_surface_layer_list);
4652 EXPECT_FALSE(result_layer);
4653
4654 test_point = gfx::Point(24, 24);
4655 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4656 test_point, render_surface_layer_list);
4657 EXPECT_FALSE(result_layer);
4658
4659 test_point = gfx::Point(76, 76);
4660 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4661 test_point, render_surface_layer_list);
4662 EXPECT_FALSE(result_layer);
4663
4664 // Hit testing for a point inside should return the test layer.
4665 test_point = gfx::Point(26, 26);
4666 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4667 test_point, render_surface_layer_list);
4668 ASSERT_TRUE(result_layer);
4669 EXPECT_EQ(12345, result_layer->id());
4670
4671 test_point = gfx::Point(74, 74);
4672 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4673 test_point, render_surface_layer_list);
4674 ASSERT_TRUE(result_layer);
4675 EXPECT_EQ(12345, result_layer->id());
4676}
4677
[email protected]989386c2013-07-18 21:37:234678TEST_F(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) {
[email protected]fb661802013-03-25 01:59:324679 // Test that hit-testing will only work for the visible portion of a layer,
4680 // and not the entire layer bounds. Here we just test the simple axis-aligned
4681 // case.
4682 gfx::Transform identity_matrix;
4683 gfx::PointF anchor;
4684
4685 FakeImplProxy proxy;
4686 FakeLayerTreeHostImpl host_impl(&proxy);
4687 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4688 SetLayerPropertiesForTesting(root.get(),
4689 identity_matrix,
4690 identity_matrix,
4691 anchor,
4692 gfx::PointF(),
4693 gfx::Size(100, 100),
4694 false);
4695 {
4696 scoped_ptr<LayerImpl> clipping_layer =
4697 LayerImpl::Create(host_impl.active_tree(), 123);
4698 // this layer is positioned, and hit testing should correctly know where the
4699 // layer is located.
[email protected]ca2902e92013-03-28 01:45:354700 gfx::PointF position(25.f, 25.f);
[email protected]fb661802013-03-25 01:59:324701 gfx::Size bounds(50, 50);
4702 SetLayerPropertiesForTesting(clipping_layer.get(),
4703 identity_matrix,
4704 identity_matrix,
4705 anchor,
4706 position,
4707 bounds,
4708 false);
4709 clipping_layer->SetMasksToBounds(true);
4710
4711 scoped_ptr<LayerImpl> child =
4712 LayerImpl::Create(host_impl.active_tree(), 456);
4713 position = gfx::PointF(-50.f, -50.f);
4714 bounds = gfx::Size(300, 300);
4715 SetLayerPropertiesForTesting(child.get(),
4716 identity_matrix,
4717 identity_matrix,
4718 anchor,
4719 position,
4720 bounds,
4721 false);
4722 child->SetDrawsContent(true);
4723 clipping_layer->AddChild(child.Pass());
4724 root->AddChild(clipping_layer.Pass());
4725 }
4726
[email protected]50761e92013-03-29 20:51:284727 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534728 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4729 root.get(), root->bounds(), &render_surface_layer_list);
4730 inputs.can_adjust_raster_scales = true;
4731 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324732
4733 // Sanity check the scenario we just created.
4734 ASSERT_EQ(1u, render_surface_layer_list.size());
4735 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234736 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324737
4738 // Hit testing for a point outside the layer should return a null pointer.
4739 // Despite the child layer being very large, it should be clipped to the root
4740 // layer's bounds.
4741 gfx::Point test_point(24, 24);
4742 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4743 test_point, render_surface_layer_list);
4744 EXPECT_FALSE(result_layer);
4745
4746 // Even though the layer exists at (101, 101), it should not be visible there
4747 // since the clipping_layer would clamp it.
4748 test_point = gfx::Point(76, 76);
4749 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4750 test_point, render_surface_layer_list);
4751 EXPECT_FALSE(result_layer);
4752
4753 // Hit testing for a point inside should return the child layer.
4754 test_point = gfx::Point(26, 26);
4755 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4756 test_point, render_surface_layer_list);
4757 ASSERT_TRUE(result_layer);
4758 EXPECT_EQ(456, result_layer->id());
4759
4760 test_point = gfx::Point(74, 74);
4761 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4762 test_point, render_surface_layer_list);
4763 ASSERT_TRUE(result_layer);
4764 EXPECT_EQ(456, result_layer->id());
4765}
4766
[email protected]989386c2013-07-18 21:37:234767TEST_F(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324768 // This test checks whether hit testing correctly avoids hit testing with
4769 // multiple ancestors that clip in non axis-aligned ways. To pass this test,
4770 // the hit testing algorithm needs to recognize that multiple parent layers
4771 // may clip the layer, and should not actually hit those clipped areas.
4772 //
4773 // The child and grand_child layers are both initialized to clip the
4774 // rotated_leaf. The child layer is rotated about the top-left corner, so that
4775 // the root + child clips combined create a triangle. The rotated_leaf will
4776 // only be visible where it overlaps this triangle.
4777 //
4778 FakeImplProxy proxy;
4779 FakeLayerTreeHostImpl host_impl(&proxy);
4780 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123);
4781
4782 gfx::Transform identity_matrix;
4783 gfx::PointF anchor;
4784 gfx::PointF position;
4785 gfx::Size bounds(100, 100);
4786 SetLayerPropertiesForTesting(root.get(),
4787 identity_matrix,
4788 identity_matrix,
4789 anchor,
4790 position,
4791 bounds,
4792 false);
4793 root->SetMasksToBounds(true);
4794 {
4795 scoped_ptr<LayerImpl> child =
4796 LayerImpl::Create(host_impl.active_tree(), 456);
4797 scoped_ptr<LayerImpl> grand_child =
4798 LayerImpl::Create(host_impl.active_tree(), 789);
4799 scoped_ptr<LayerImpl> rotated_leaf =
4800 LayerImpl::Create(host_impl.active_tree(), 2468);
4801
4802 position = gfx::PointF(10.f, 10.f);
4803 bounds = gfx::Size(80, 80);
4804 SetLayerPropertiesForTesting(child.get(),
4805 identity_matrix,
4806 identity_matrix,
4807 anchor,
4808 position,
4809 bounds,
4810 false);
[email protected]7aba6662013-03-12 10:17:344811 child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444812
[email protected]fb661802013-03-25 01:59:324813 gfx::Transform rotation45_degrees_about_corner;
4814 rotation45_degrees_about_corner.RotateAboutZAxis(45.0);
[email protected]aedf4e52013-01-09 23:24:444815
[email protected]fb661802013-03-25 01:59:324816 // remember, positioned with respect to its parent which is already at 10,
4817 // 10
4818 position = gfx::PointF();
4819 bounds =
4820 gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
4821 SetLayerPropertiesForTesting(grand_child.get(),
4822 rotation45_degrees_about_corner,
4823 identity_matrix,
4824 anchor,
4825 position,
4826 bounds,
4827 false);
4828 grand_child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444829
[email protected]fb661802013-03-25 01:59:324830 // Rotates about the center of the layer
4831 gfx::Transform rotated_leaf_transform;
4832 rotated_leaf_transform.Translate(
4833 -10.0, -10.0); // cancel out the grand_parent's position
4834 rotated_leaf_transform.RotateAboutZAxis(
4835 -45.0); // cancel out the corner 45-degree rotation of the parent.
4836 rotated_leaf_transform.Translate(50.0, 50.0);
4837 rotated_leaf_transform.RotateAboutZAxis(45.0);
4838 rotated_leaf_transform.Translate(-50.0, -50.0);
4839 position = gfx::PointF();
4840 bounds = gfx::Size(100, 100);
4841 SetLayerPropertiesForTesting(rotated_leaf.get(),
4842 rotated_leaf_transform,
4843 identity_matrix,
4844 anchor,
4845 position,
4846 bounds,
4847 false);
4848 rotated_leaf->SetDrawsContent(true);
[email protected]aedf4e52013-01-09 23:24:444849
[email protected]fb661802013-03-25 01:59:324850 grand_child->AddChild(rotated_leaf.Pass());
4851 child->AddChild(grand_child.Pass());
4852 root->AddChild(child.Pass());
4853 }
[email protected]aedf4e52013-01-09 23:24:444854
[email protected]50761e92013-03-29 20:51:284855 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534856 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4857 root.get(), root->bounds(), &render_surface_layer_list);
4858 inputs.can_adjust_raster_scales = true;
4859 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:444860
[email protected]fb661802013-03-25 01:59:324861 // Sanity check the scenario we just created.
4862 // The grand_child is expected to create a render surface because it
[email protected]989386c2013-07-18 21:37:234863 // MasksToBounds and is not axis aligned.
[email protected]fb661802013-03-25 01:59:324864 ASSERT_EQ(2u, render_surface_layer_list.size());
4865 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234866 1u,
4867 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324868 ASSERT_EQ(789,
[email protected]989386c2013-07-18 21:37:234869 render_surface_layer_list.at(0)->render_surface()->layer_list().at(
4870 0)->id()); // grand_child's surface.
[email protected]fb661802013-03-25 01:59:324871 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234872 1u,
4873 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324874 ASSERT_EQ(
4875 2468,
[email protected]989386c2013-07-18 21:37:234876 render_surface_layer_list[1]->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324877
4878 // (11, 89) is close to the the bottom left corner within the clip, but it is
4879 // not inside the layer.
4880 gfx::Point test_point(11, 89);
4881 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4882 test_point, render_surface_layer_list);
4883 EXPECT_FALSE(result_layer);
4884
4885 // Closer inwards from the bottom left will overlap the layer.
4886 test_point = gfx::Point(25, 75);
4887 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4888 test_point, render_surface_layer_list);
4889 ASSERT_TRUE(result_layer);
4890 EXPECT_EQ(2468, result_layer->id());
4891
4892 // (4, 50) is inside the unclipped layer, but that corner of the layer should
4893 // be clipped away by the grandparent and should not get hit. If hit testing
4894 // blindly uses visible content rect without considering how parent may clip
4895 // the layer, then hit testing would accidentally think that the point
4896 // successfully hits the layer.
4897 test_point = gfx::Point(4, 50);
4898 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4899 test_point, render_surface_layer_list);
4900 EXPECT_FALSE(result_layer);
4901
4902 // (11, 50) is inside the layer and within the clipped area.
4903 test_point = gfx::Point(11, 50);
4904 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4905 test_point, render_surface_layer_list);
4906 ASSERT_TRUE(result_layer);
4907 EXPECT_EQ(2468, result_layer->id());
4908
4909 // Around the middle, just to the right and up, would have hit the layer
4910 // except that that area should be clipped away by the parent.
[email protected]803f6b52013-09-12 00:51:264911 test_point = gfx::Point(51, 49);
[email protected]fb661802013-03-25 01:59:324912 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4913 test_point, render_surface_layer_list);
4914 EXPECT_FALSE(result_layer);
4915
4916 // Around the middle, just to the left and down, should successfully hit the
4917 // layer.
4918 test_point = gfx::Point(49, 51);
4919 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4920 test_point, render_surface_layer_list);
4921 ASSERT_TRUE(result_layer);
4922 EXPECT_EQ(2468, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:444923}
4924
[email protected]989386c2013-07-18 21:37:234925TEST_F(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:324926 // This test checks that hit testing code does not accidentally clip to layer
4927 // bounds for a layer that actually does not clip.
4928 gfx::Transform identity_matrix;
4929 gfx::PointF anchor;
[email protected]aedf4e52013-01-09 23:24:444930
[email protected]fb661802013-03-25 01:59:324931 FakeImplProxy proxy;
4932 FakeLayerTreeHostImpl host_impl(&proxy);
4933 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4934 SetLayerPropertiesForTesting(root.get(),
4935 identity_matrix,
4936 identity_matrix,
4937 anchor,
4938 gfx::PointF(),
4939 gfx::Size(100, 100),
4940 false);
4941 {
4942 scoped_ptr<LayerImpl> intermediate_layer =
4943 LayerImpl::Create(host_impl.active_tree(), 123);
4944 // this layer is positioned, and hit testing should correctly know where the
4945 // layer is located.
4946 gfx::PointF position(10.f, 10.f);
4947 gfx::Size bounds(50, 50);
4948 SetLayerPropertiesForTesting(intermediate_layer.get(),
4949 identity_matrix,
4950 identity_matrix,
4951 anchor,
4952 position,
4953 bounds,
4954 false);
4955 // Sanity check the intermediate layer should not clip.
4956 ASSERT_FALSE(intermediate_layer->masks_to_bounds());
4957 ASSERT_FALSE(intermediate_layer->mask_layer());
[email protected]aedf4e52013-01-09 23:24:444958
[email protected]fb661802013-03-25 01:59:324959 // The child of the intermediate_layer is translated so that it does not
4960 // overlap intermediate_layer at all. If child is incorrectly clipped, we
4961 // would not be able to hit it successfully.
4962 scoped_ptr<LayerImpl> child =
4963 LayerImpl::Create(host_impl.active_tree(), 456);
4964 position = gfx::PointF(60.f, 60.f); // 70, 70 in screen space
4965 bounds = gfx::Size(20, 20);
4966 SetLayerPropertiesForTesting(child.get(),
4967 identity_matrix,
4968 identity_matrix,
4969 anchor,
4970 position,
4971 bounds,
4972 false);
4973 child->SetDrawsContent(true);
4974 intermediate_layer->AddChild(child.Pass());
4975 root->AddChild(intermediate_layer.Pass());
4976 }
[email protected]aedf4e52013-01-09 23:24:444977
[email protected]50761e92013-03-29 20:51:284978 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534979 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4980 root.get(), root->bounds(), &render_surface_layer_list);
4981 inputs.can_adjust_raster_scales = true;
4982 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:444983
[email protected]fb661802013-03-25 01:59:324984 // Sanity check the scenario we just created.
4985 ASSERT_EQ(1u, render_surface_layer_list.size());
4986 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234987 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]aedf4e52013-01-09 23:24:444988
[email protected]fb661802013-03-25 01:59:324989 // Hit testing for a point outside the layer should return a null pointer.
4990 gfx::Point test_point(69, 69);
4991 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4992 test_point, render_surface_layer_list);
4993 EXPECT_FALSE(result_layer);
[email protected]aedf4e52013-01-09 23:24:444994
[email protected]fb661802013-03-25 01:59:324995 test_point = gfx::Point(91, 91);
4996 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4997 test_point, render_surface_layer_list);
4998 EXPECT_FALSE(result_layer);
4999
5000 // Hit testing for a point inside should return the child layer.
5001 test_point = gfx::Point(71, 71);
5002 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5003 test_point, render_surface_layer_list);
5004 ASSERT_TRUE(result_layer);
5005 EXPECT_EQ(456, result_layer->id());
5006
5007 test_point = gfx::Point(89, 89);
5008 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5009 test_point, render_surface_layer_list);
5010 ASSERT_TRUE(result_layer);
5011 EXPECT_EQ(456, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:445012}
5013
[email protected]989386c2013-07-18 21:37:235014TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayers) {
[email protected]fb661802013-03-25 01:59:325015 FakeImplProxy proxy;
5016 FakeLayerTreeHostImpl host_impl(&proxy);
5017 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145018
[email protected]fb661802013-03-25 01:59:325019 gfx::Transform identity_matrix;
5020 gfx::PointF anchor;
5021 gfx::PointF position;
5022 gfx::Size bounds(100, 100);
5023 SetLayerPropertiesForTesting(root.get(),
5024 identity_matrix,
5025 identity_matrix,
5026 anchor,
5027 position,
5028 bounds,
5029 false);
5030 root->SetDrawsContent(true);
5031 {
5032 // child 1 and child2 are initialized to overlap between x=50 and x=60.
5033 // grand_child is set to overlap both child1 and child2 between y=50 and
5034 // y=60. The expected stacking order is: (front) child2, (second)
5035 // grand_child, (third) child1, and (back) the root layer behind all other
5036 // layers.
[email protected]ecc12622012-10-30 20:45:425037
[email protected]fb661802013-03-25 01:59:325038 scoped_ptr<LayerImpl> child1 =
5039 LayerImpl::Create(host_impl.active_tree(), 2);
5040 scoped_ptr<LayerImpl> child2 =
5041 LayerImpl::Create(host_impl.active_tree(), 3);
5042 scoped_ptr<LayerImpl> grand_child1 =
5043 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:145044
[email protected]fb661802013-03-25 01:59:325045 position = gfx::PointF(10.f, 10.f);
5046 bounds = gfx::Size(50, 50);
5047 SetLayerPropertiesForTesting(child1.get(),
5048 identity_matrix,
5049 identity_matrix,
5050 anchor,
5051 position,
5052 bounds,
5053 false);
5054 child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145055
[email protected]fb661802013-03-25 01:59:325056 position = gfx::PointF(50.f, 10.f);
5057 bounds = gfx::Size(50, 50);
5058 SetLayerPropertiesForTesting(child2.get(),
5059 identity_matrix,
5060 identity_matrix,
5061 anchor,
5062 position,
5063 bounds,
5064 false);
5065 child2->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145066
[email protected]fb661802013-03-25 01:59:325067 // Remember that grand_child is positioned with respect to its parent (i.e.
5068 // child1). In screen space, the intended position is (10, 50), with size
5069 // 100 x 50.
5070 position = gfx::PointF(0.f, 40.f);
5071 bounds = gfx::Size(100, 50);
5072 SetLayerPropertiesForTesting(grand_child1.get(),
5073 identity_matrix,
5074 identity_matrix,
5075 anchor,
5076 position,
5077 bounds,
5078 false);
5079 grand_child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145080
[email protected]fb661802013-03-25 01:59:325081 child1->AddChild(grand_child1.Pass());
5082 root->AddChild(child1.Pass());
5083 root->AddChild(child2.Pass());
5084 }
[email protected]94f206c12012-08-25 00:09:145085
[email protected]fb661802013-03-25 01:59:325086 LayerImpl* child1 = root->children()[0];
5087 LayerImpl* child2 = root->children()[1];
5088 LayerImpl* grand_child1 = child1->children()[0];
5089
[email protected]50761e92013-03-29 20:51:285090 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535091 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5092 root.get(), root->bounds(), &render_surface_layer_list);
5093 inputs.can_adjust_raster_scales = true;
5094 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325095
5096 // Sanity check the scenario we just created.
5097 ASSERT_TRUE(child1);
5098 ASSERT_TRUE(child2);
5099 ASSERT_TRUE(grand_child1);
5100 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:235101
5102 RenderSurfaceImpl* root_render_surface = root->render_surface();
5103 ASSERT_EQ(4u, root_render_surface->layer_list().size());
5104 ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer
5105 ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1
5106 ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1
5107 ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2
[email protected]fb661802013-03-25 01:59:325108
5109 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5110 // the root layer.
5111 gfx::Point test_point = gfx::Point(1, 1);
5112 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5113 test_point, render_surface_layer_list);
5114 ASSERT_TRUE(result_layer);
5115 EXPECT_EQ(1, result_layer->id());
5116
5117 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5118 // on top.
5119 test_point = gfx::Point(15, 15);
5120 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5121 test_point, render_surface_layer_list);
5122 ASSERT_TRUE(result_layer);
5123 EXPECT_EQ(2, result_layer->id());
5124
5125 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5126 test_point = gfx::Point(51, 20);
5127 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5128 test_point, render_surface_layer_list);
5129 ASSERT_TRUE(result_layer);
5130 EXPECT_EQ(3, result_layer->id());
5131
5132 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5133 // top.
5134 test_point = gfx::Point(80, 51);
5135 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5136 test_point, render_surface_layer_list);
5137 ASSERT_TRUE(result_layer);
5138 EXPECT_EQ(3, result_layer->id());
5139
5140 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5141 // of all other layers.
5142 test_point = gfx::Point(51, 51);
5143 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5144 test_point, render_surface_layer_list);
5145 ASSERT_TRUE(result_layer);
5146 EXPECT_EQ(3, result_layer->id());
5147
5148 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5149 // be on top.
5150 test_point = gfx::Point(20, 51);
5151 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5152 test_point, render_surface_layer_list);
5153 ASSERT_TRUE(result_layer);
5154 EXPECT_EQ(4, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145155}
5156
[email protected]989386c2013-07-18 21:37:235157TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) {
[email protected]fb661802013-03-25 01:59:325158 //
5159 // The geometry is set up similarly to the previous case, but
5160 // all layers are forced to be render surfaces now.
5161 //
5162 FakeImplProxy proxy;
5163 FakeLayerTreeHostImpl host_impl(&proxy);
5164 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145165
[email protected]fb661802013-03-25 01:59:325166 gfx::Transform identity_matrix;
5167 gfx::PointF anchor;
5168 gfx::PointF position;
5169 gfx::Size bounds(100, 100);
5170 SetLayerPropertiesForTesting(root.get(),
5171 identity_matrix,
5172 identity_matrix,
5173 anchor,
5174 position,
5175 bounds,
5176 false);
5177 root->SetDrawsContent(true);
5178 {
5179 // child 1 and child2 are initialized to overlap between x=50 and x=60.
5180 // grand_child is set to overlap both child1 and child2 between y=50 and
5181 // y=60. The expected stacking order is: (front) child2, (second)
5182 // grand_child, (third) child1, and (back) the root layer behind all other
5183 // layers.
[email protected]94f206c12012-08-25 00:09:145184
[email protected]fb661802013-03-25 01:59:325185 scoped_ptr<LayerImpl> child1 =
5186 LayerImpl::Create(host_impl.active_tree(), 2);
5187 scoped_ptr<LayerImpl> child2 =
5188 LayerImpl::Create(host_impl.active_tree(), 3);
5189 scoped_ptr<LayerImpl> grand_child1 =
5190 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:145191
[email protected]fb661802013-03-25 01:59:325192 position = gfx::PointF(10.f, 10.f);
5193 bounds = gfx::Size(50, 50);
5194 SetLayerPropertiesForTesting(child1.get(),
5195 identity_matrix,
5196 identity_matrix,
5197 anchor,
5198 position,
5199 bounds,
5200 false);
5201 child1->SetDrawsContent(true);
5202 child1->SetForceRenderSurface(true);
[email protected]ecc12622012-10-30 20:45:425203
[email protected]fb661802013-03-25 01:59:325204 position = gfx::PointF(50.f, 10.f);
5205 bounds = gfx::Size(50, 50);
5206 SetLayerPropertiesForTesting(child2.get(),
5207 identity_matrix,
5208 identity_matrix,
5209 anchor,
5210 position,
5211 bounds,
5212 false);
5213 child2->SetDrawsContent(true);
[email protected]7aba6662013-03-12 10:17:345214 child2->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015215
[email protected]fb661802013-03-25 01:59:325216 // Remember that grand_child is positioned with respect to its parent (i.e.
5217 // child1). In screen space, the intended position is (10, 50), with size
5218 // 100 x 50.
5219 position = gfx::PointF(0.f, 40.f);
5220 bounds = gfx::Size(100, 50);
5221 SetLayerPropertiesForTesting(grand_child1.get(),
5222 identity_matrix,
5223 identity_matrix,
5224 anchor,
5225 position,
5226 bounds,
5227 false);
5228 grand_child1->SetDrawsContent(true);
5229 grand_child1->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015230
[email protected]fb661802013-03-25 01:59:325231 child1->AddChild(grand_child1.Pass());
5232 root->AddChild(child1.Pass());
5233 root->AddChild(child2.Pass());
5234 }
[email protected]dc462d782012-11-21 21:43:015235
[email protected]fb661802013-03-25 01:59:325236 LayerImpl* child1 = root->children()[0];
5237 LayerImpl* child2 = root->children()[1];
5238 LayerImpl* grand_child1 = child1->children()[0];
[email protected]dc462d782012-11-21 21:43:015239
[email protected]50761e92013-03-29 20:51:285240 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535241 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5242 root.get(), root->bounds(), &render_surface_layer_list);
5243 inputs.can_adjust_raster_scales = true;
5244 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]dc462d782012-11-21 21:43:015245
[email protected]fb661802013-03-25 01:59:325246 // Sanity check the scenario we just created.
5247 ASSERT_TRUE(child1);
5248 ASSERT_TRUE(child2);
5249 ASSERT_TRUE(grand_child1);
5250 ASSERT_TRUE(child1->render_surface());
5251 ASSERT_TRUE(child2->render_surface());
5252 ASSERT_TRUE(grand_child1->render_surface());
5253 ASSERT_EQ(4u, render_surface_layer_list.size());
5254 // The root surface has the root layer, and child1's and child2's render
5255 // surfaces.
5256 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
5257 // The child1 surface has the child1 layer and grand_child1's render surface.
5258 ASSERT_EQ(2u, child1->render_surface()->layer_list().size());
5259 ASSERT_EQ(1u, child2->render_surface()->layer_list().size());
5260 ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235261 ASSERT_EQ(1, render_surface_layer_list.at(0)->id()); // root layer
[email protected]fb661802013-03-25 01:59:325262 ASSERT_EQ(2, render_surface_layer_list[1]->id()); // child1
[email protected]989386c2013-07-18 21:37:235263 ASSERT_EQ(4, render_surface_layer_list.at(2)->id()); // grand_child1
[email protected]fb661802013-03-25 01:59:325264 ASSERT_EQ(3, render_surface_layer_list[3]->id()); // child2
[email protected]dc462d782012-11-21 21:43:015265
[email protected]fb661802013-03-25 01:59:325266 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5267 // the root layer.
5268 gfx::Point test_point = gfx::Point(1, 1);
5269 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5270 test_point, render_surface_layer_list);
5271 ASSERT_TRUE(result_layer);
5272 EXPECT_EQ(1, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015273
[email protected]fb661802013-03-25 01:59:325274 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5275 // on top.
5276 test_point = gfx::Point(15, 15);
5277 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5278 test_point, render_surface_layer_list);
5279 ASSERT_TRUE(result_layer);
5280 EXPECT_EQ(2, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015281
[email protected]fb661802013-03-25 01:59:325282 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5283 test_point = gfx::Point(51, 20);
5284 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5285 test_point, render_surface_layer_list);
5286 ASSERT_TRUE(result_layer);
5287 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015288
[email protected]fb661802013-03-25 01:59:325289 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5290 // top.
5291 test_point = gfx::Point(80, 51);
5292 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5293 test_point, render_surface_layer_list);
5294 ASSERT_TRUE(result_layer);
5295 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015296
[email protected]fb661802013-03-25 01:59:325297 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5298 // of all other layers.
5299 test_point = gfx::Point(51, 51);
5300 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5301 test_point, render_surface_layer_list);
5302 ASSERT_TRUE(result_layer);
5303 EXPECT_EQ(3, result_layer->id());
5304
5305 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5306 // be on top.
5307 test_point = gfx::Point(20, 51);
5308 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5309 test_point, render_surface_layer_list);
5310 ASSERT_TRUE(result_layer);
5311 EXPECT_EQ(4, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015312}
5313
[email protected]afc4f262013-10-05 01:14:105314TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayers) {
5315 FakeImplProxy proxy;
5316 FakeLayerTreeHostImpl host_impl(&proxy);
5317
5318 // Layer 1 - root
5319 scoped_ptr<LayerImpl> root =
5320 LayerImpl::Create(host_impl.active_tree(), 1);
5321 gfx::Transform identity_matrix;
5322 gfx::PointF anchor;
5323 gfx::PointF position;
5324 gfx::Size bounds(100, 100);
5325 SetLayerPropertiesForTesting(root.get(),
5326 identity_matrix,
5327 identity_matrix,
5328 anchor,
5329 position,
5330 bounds,
5331 false);
5332 root->SetDrawsContent(true);
5333
5334 {
5335 // Layer 2 - empty: drawsContent=false
5336 gfx::PointF position(10.f, 10.f);
5337 gfx::Size bounds(30, 30);
5338 scoped_ptr<LayerImpl> empty_layer =
5339 LayerImpl::Create(host_impl.active_tree(), 2);
5340 SetLayerPropertiesForTesting(empty_layer.get(),
5341 identity_matrix,
5342 identity_matrix,
5343 anchor,
5344 position,
5345 bounds,
5346 false);
5347
5348 empty_layer->SetDrawsContent(false);
5349 root->AddChild(empty_layer.Pass());
5350 }
5351
5352 {
5353 // Layer 3 - empty, but has touch handler
5354 gfx::PointF position(10.f, 60.f);
5355 gfx::Size bounds(30, 30);
5356 scoped_ptr<LayerImpl> test_layer =
5357 LayerImpl::Create(host_impl.active_tree(), 3);
5358 SetLayerPropertiesForTesting(test_layer.get(),
5359 identity_matrix,
5360 identity_matrix,
5361 anchor,
5362 position,
5363 bounds,
5364 false);
5365
5366 test_layer->SetDrawsContent(false);
5367 Region touch_handler_region(gfx::Rect(10, 10, 10, 10));
5368 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5369 root->AddChild(test_layer.Pass());
5370 }
5371
5372 {
5373 // Layer 4 - empty, but has mousewheel handler
5374 gfx::PointF position(60.f, 60.f);
5375 gfx::Size bounds(30, 30);
5376 scoped_ptr<LayerImpl> test_layer =
5377 LayerImpl::Create(host_impl.active_tree(), 4);
5378 SetLayerPropertiesForTesting(test_layer.get(),
5379 identity_matrix,
5380 identity_matrix,
5381 anchor,
5382 position,
5383 bounds,
5384 false);
5385
5386 test_layer->SetDrawsContent(false);
5387 test_layer->SetHaveWheelEventHandlers(true);
5388 root->AddChild(test_layer.Pass());
5389 }
5390
5391 LayerImplList render_surface_layer_list;
5392 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5393 root.get(), root->bounds(), &render_surface_layer_list);
5394 inputs.can_adjust_raster_scales = true;
5395 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5396
5397 // Verify that the root layer and empty layers with touch/wheel handlers
5398 // (but not the empty layer without a touch handler) are in the RSSL.
5399 ASSERT_EQ(1u, render_surface_layer_list.size());
5400 EXPECT_EQ(1, render_surface_layer_list[0]->id());
[email protected]22538a2d2013-11-12 11:24:455401 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
[email protected]afc4f262013-10-05 01:14:105402 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]22538a2d2013-11-12 11:24:455403 EXPECT_EQ(3, root->render_surface()->layer_list().at(1)->id());
5404 EXPECT_EQ(4, root->render_surface()->layer_list().at(2)->id());
[email protected]afc4f262013-10-05 01:14:105405
5406 // Hit testing for a point inside the empty no-handlers layer should return
5407 // the root layer.
5408 gfx::Point test_point = gfx::Point(15, 15);
5409 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5410 test_point, render_surface_layer_list);
5411 ASSERT_TRUE(result_layer);
[email protected]22538a2d2013-11-12 11:24:455412 EXPECT_EQ(1, result_layer->id());
[email protected]afc4f262013-10-05 01:14:105413
5414 // Hit testing for a point inside the touch handler layer should return it.
5415 test_point = gfx::Point(15, 75);
5416 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5417 test_point, render_surface_layer_list);
5418 ASSERT_TRUE(result_layer);
5419 EXPECT_EQ(3, result_layer->id());
5420
5421 // Hit testing for a point inside the mousewheel layer should return it.
5422 test_point = gfx::Point(75, 75);
5423 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5424 test_point, render_surface_layer_list);
5425 ASSERT_TRUE(result_layer);
5426 EXPECT_EQ(4, result_layer->id());
5427}
5428
[email protected]989386c2013-07-18 21:37:235429TEST_F(LayerTreeHostCommonTest,
5430 HitCheckingTouchHandlerRegionsForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:325431 // Hit checking on an empty render_surface_layer_list should return a null
5432 // pointer.
[email protected]50761e92013-03-29 20:51:285433 LayerImplList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145434
[email protected]fb661802013-03-25 01:59:325435 gfx::Point test_point(0, 0);
5436 LayerImpl* result_layer =
5437 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5438 test_point, render_surface_layer_list);
5439 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145440
[email protected]fb661802013-03-25 01:59:325441 test_point = gfx::Point(10, 20);
5442 result_layer =
5443 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5444 test_point, render_surface_layer_list);
5445 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145446}
5447
[email protected]989386c2013-07-18 21:37:235448TEST_F(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:325449 FakeImplProxy proxy;
5450 FakeLayerTreeHostImpl host_impl(&proxy);
5451 scoped_ptr<LayerImpl> root =
5452 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145453
[email protected]fb661802013-03-25 01:59:325454 gfx::Transform identity_matrix;
5455 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5456 gfx::PointF anchor;
5457 gfx::PointF position;
5458 gfx::Size bounds(100, 100);
5459 SetLayerPropertiesForTesting(root.get(),
5460 identity_matrix,
5461 identity_matrix,
5462 anchor,
5463 position,
5464 bounds,
5465 false);
5466 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145467
[email protected]50761e92013-03-29 20:51:285468 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535469 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5470 root.get(), root->bounds(), &render_surface_layer_list);
5471 inputs.can_adjust_raster_scales = true;
5472 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145473
[email protected]fb661802013-03-25 01:59:325474 // Sanity check the scenario we just created.
5475 ASSERT_EQ(1u, render_surface_layer_list.size());
5476 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145477
[email protected]fb661802013-03-25 01:59:325478 // Hit checking for any point should return a null pointer for a layer without
5479 // any touch event handler regions.
5480 gfx::Point test_point(11, 11);
5481 LayerImpl* result_layer =
5482 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5483 test_point, render_surface_layer_list);
5484 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145485
[email protected]fb661802013-03-25 01:59:325486 root->SetTouchEventHandlerRegion(touch_handler_region);
5487 // Hit checking for a point outside the layer should return a null pointer.
5488 test_point = gfx::Point(101, 101);
5489 result_layer =
5490 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5491 test_point, render_surface_layer_list);
5492 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145493
[email protected]fb661802013-03-25 01:59:325494 test_point = gfx::Point(-1, -1);
5495 result_layer =
5496 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5497 test_point, render_surface_layer_list);
5498 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145499
[email protected]fb661802013-03-25 01:59:325500 // Hit checking for a point inside the layer, but outside the touch handler
5501 // region should return a null pointer.
5502 test_point = gfx::Point(1, 1);
5503 result_layer =
5504 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5505 test_point, render_surface_layer_list);
5506 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145507
[email protected]fb661802013-03-25 01:59:325508 test_point = gfx::Point(99, 99);
5509 result_layer =
5510 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5511 test_point, render_surface_layer_list);
5512 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145513
[email protected]fb661802013-03-25 01:59:325514 // Hit checking for a point inside the touch event handler region should
5515 // return the root layer.
5516 test_point = gfx::Point(11, 11);
5517 result_layer =
5518 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5519 test_point, render_surface_layer_list);
5520 ASSERT_TRUE(result_layer);
5521 EXPECT_EQ(12345, result_layer->id());
5522
5523 test_point = gfx::Point(59, 59);
5524 result_layer =
5525 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5526 test_point, render_surface_layer_list);
5527 ASSERT_TRUE(result_layer);
5528 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145529}
5530
[email protected]989386c2013-07-18 21:37:235531TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325532 HitCheckingTouchHandlerRegionsForUninvertibleTransform) {
5533 FakeImplProxy proxy;
5534 FakeLayerTreeHostImpl host_impl(&proxy);
5535 scoped_ptr<LayerImpl> root =
5536 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145537
[email protected]fb661802013-03-25 01:59:325538 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:265539 uninvertible_transform.matrix().set(0, 0, 0.0);
5540 uninvertible_transform.matrix().set(1, 1, 0.0);
5541 uninvertible_transform.matrix().set(2, 2, 0.0);
5542 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:325543 ASSERT_FALSE(uninvertible_transform.IsInvertible());
[email protected]94f206c12012-08-25 00:09:145544
[email protected]fb661802013-03-25 01:59:325545 gfx::Transform identity_matrix;
5546 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5547 gfx::PointF anchor;
5548 gfx::PointF position;
5549 gfx::Size bounds(100, 100);
5550 SetLayerPropertiesForTesting(root.get(),
5551 uninvertible_transform,
5552 identity_matrix,
5553 anchor,
5554 position,
5555 bounds,
5556 false);
5557 root->SetDrawsContent(true);
5558 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145559
[email protected]50761e92013-03-29 20:51:285560 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535561 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5562 root.get(), root->bounds(), &render_surface_layer_list);
5563 inputs.can_adjust_raster_scales = true;
5564 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145565
[email protected]fb661802013-03-25 01:59:325566 // Sanity check the scenario we just created.
5567 ASSERT_EQ(1u, render_surface_layer_list.size());
5568 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5569 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
[email protected]de4afb5e2012-12-20 00:11:345570
[email protected]fb661802013-03-25 01:59:325571 // Hit checking any point should not hit the touch handler region on the
5572 // layer. If the invertible matrix is accidentally ignored and treated like an
5573 // identity, then the hit testing will incorrectly hit the layer when it
5574 // shouldn't.
5575 gfx::Point test_point(1, 1);
5576 LayerImpl* result_layer =
5577 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5578 test_point, render_surface_layer_list);
5579 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345580
[email protected]fb661802013-03-25 01:59:325581 test_point = gfx::Point(10, 10);
5582 result_layer =
5583 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5584 test_point, render_surface_layer_list);
5585 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345586
[email protected]fb661802013-03-25 01:59:325587 test_point = gfx::Point(10, 30);
5588 result_layer =
5589 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5590 test_point, render_surface_layer_list);
5591 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345592
[email protected]fb661802013-03-25 01:59:325593 test_point = gfx::Point(50, 50);
5594 result_layer =
5595 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5596 test_point, render_surface_layer_list);
5597 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145598
[email protected]fb661802013-03-25 01:59:325599 test_point = gfx::Point(67, 48);
5600 result_layer =
5601 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5602 test_point, render_surface_layer_list);
5603 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145604
[email protected]fb661802013-03-25 01:59:325605 test_point = gfx::Point(99, 99);
5606 result_layer =
5607 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5608 test_point, render_surface_layer_list);
5609 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145610
[email protected]fb661802013-03-25 01:59:325611 test_point = gfx::Point(-1, -1);
5612 result_layer =
5613 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5614 test_point, render_surface_layer_list);
5615 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145616}
5617
[email protected]989386c2013-07-18 21:37:235618TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325619 HitCheckingTouchHandlerRegionsForSinglePositionedLayer) {
5620 FakeImplProxy proxy;
5621 FakeLayerTreeHostImpl host_impl(&proxy);
5622 scoped_ptr<LayerImpl> root =
5623 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145624
[email protected]fb661802013-03-25 01:59:325625 gfx::Transform identity_matrix;
5626 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5627 gfx::PointF anchor;
5628 // this layer is positioned, and hit testing should correctly know where the
5629 // layer is located.
5630 gfx::PointF position(50.f, 50.f);
5631 gfx::Size bounds(100, 100);
5632 SetLayerPropertiesForTesting(root.get(),
5633 identity_matrix,
5634 identity_matrix,
5635 anchor,
5636 position,
5637 bounds,
5638 false);
5639 root->SetDrawsContent(true);
5640 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145641
[email protected]50761e92013-03-29 20:51:285642 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535643 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5644 root.get(), root->bounds(), &render_surface_layer_list);
5645 inputs.can_adjust_raster_scales = true;
5646 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145647
[email protected]fb661802013-03-25 01:59:325648 // Sanity check the scenario we just created.
5649 ASSERT_EQ(1u, render_surface_layer_list.size());
5650 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145651
[email protected]fb661802013-03-25 01:59:325652 // Hit checking for a point outside the layer should return a null pointer.
5653 gfx::Point test_point(49, 49);
5654 LayerImpl* result_layer =
5655 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5656 test_point, render_surface_layer_list);
5657 EXPECT_FALSE(result_layer);
5658
5659 // Even though the layer has a touch handler region containing (101, 101), it
5660 // should not be visible there since the root render surface would clamp it.
5661 test_point = gfx::Point(101, 101);
5662 result_layer =
5663 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5664 test_point, render_surface_layer_list);
5665 EXPECT_FALSE(result_layer);
5666
5667 // Hit checking for a point inside the layer, but outside the touch handler
5668 // region should return a null pointer.
5669 test_point = gfx::Point(51, 51);
5670 result_layer =
5671 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5672 test_point, render_surface_layer_list);
5673 EXPECT_FALSE(result_layer);
5674
5675 // Hit checking for a point inside the touch event handler region should
5676 // return the root layer.
5677 test_point = gfx::Point(61, 61);
5678 result_layer =
5679 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5680 test_point, render_surface_layer_list);
5681 ASSERT_TRUE(result_layer);
5682 EXPECT_EQ(12345, result_layer->id());
5683
5684 test_point = gfx::Point(99, 99);
5685 result_layer =
5686 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5687 test_point, render_surface_layer_list);
5688 ASSERT_TRUE(result_layer);
5689 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145690}
5691
[email protected]989386c2013-07-18 21:37:235692TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325693 HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) {
5694 // A layer's visible content rect is actually in the layer's content space.
5695 // The screen space transform converts from the layer's origin space to screen
5696 // space. This test makes sure that hit testing works correctly accounts for
5697 // the contents scale. A contents scale that is not 1 effectively forces a
5698 // non-identity transform between layer's content space and layer's origin
5699 // space. The hit testing code must take this into account.
5700 //
5701 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
5702 // contents scale is ignored, then hit checking will mis-interpret the visible
5703 // content rect as being larger than the actual bounds of the layer.
5704 //
5705 FakeImplProxy proxy;
5706 FakeLayerTreeHostImpl host_impl(&proxy);
5707 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145708
[email protected]fb661802013-03-25 01:59:325709 gfx::Transform identity_matrix;
5710 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145711
[email protected]fb661802013-03-25 01:59:325712 SetLayerPropertiesForTesting(root.get(),
5713 identity_matrix,
5714 identity_matrix,
5715 anchor,
5716 gfx::PointF(),
5717 gfx::Size(100, 100),
5718 false);
5719 {
5720 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5721 gfx::PointF position(25.f, 25.f);
5722 gfx::Size bounds(50, 50);
5723 scoped_ptr<LayerImpl> test_layer =
5724 LayerImpl::Create(host_impl.active_tree(), 12345);
5725 SetLayerPropertiesForTesting(test_layer.get(),
5726 identity_matrix,
5727 identity_matrix,
5728 anchor,
5729 position,
5730 bounds,
5731 false);
[email protected]94f206c12012-08-25 00:09:145732
[email protected]fb661802013-03-25 01:59:325733 // override content bounds and contents scale
5734 test_layer->SetContentBounds(gfx::Size(100, 100));
5735 test_layer->SetContentsScale(2, 2);
[email protected]94f206c12012-08-25 00:09:145736
[email protected]fb661802013-03-25 01:59:325737 test_layer->SetDrawsContent(true);
5738 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5739 root->AddChild(test_layer.Pass());
5740 }
5741
[email protected]50761e92013-03-29 20:51:285742 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535743 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5744 root.get(), root->bounds(), &render_surface_layer_list);
5745 inputs.can_adjust_raster_scales = true;
5746 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325747
5748 // Sanity check the scenario we just created.
5749 // The visible content rect for test_layer is actually 100x100, even though
5750 // its layout size is 50x50, positioned at 25x25.
5751 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:055752 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect());
[email protected]fb661802013-03-25 01:59:325753 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455754 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:325755
5756 // Hit checking for a point outside the layer should return a null pointer
5757 // (the root layer does not draw content, so it will not be tested either).
5758 gfx::Point test_point(76, 76);
5759 LayerImpl* result_layer =
5760 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5761 test_point, render_surface_layer_list);
5762 EXPECT_FALSE(result_layer);
5763
5764 // Hit checking for a point inside the layer, but outside the touch handler
5765 // region should return a null pointer.
5766 test_point = gfx::Point(26, 26);
5767 result_layer =
5768 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5769 test_point, render_surface_layer_list);
5770 EXPECT_FALSE(result_layer);
5771
5772 test_point = gfx::Point(34, 34);
5773 result_layer =
5774 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5775 test_point, render_surface_layer_list);
5776 EXPECT_FALSE(result_layer);
5777
5778 test_point = gfx::Point(65, 65);
5779 result_layer =
5780 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5781 test_point, render_surface_layer_list);
5782 EXPECT_FALSE(result_layer);
5783
5784 test_point = gfx::Point(74, 74);
5785 result_layer =
5786 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5787 test_point, render_surface_layer_list);
5788 EXPECT_FALSE(result_layer);
5789
5790 // Hit checking for a point inside the touch event handler region should
5791 // return the root layer.
5792 test_point = gfx::Point(35, 35);
5793 result_layer =
5794 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5795 test_point, render_surface_layer_list);
5796 ASSERT_TRUE(result_layer);
5797 EXPECT_EQ(12345, result_layer->id());
5798
5799 test_point = gfx::Point(64, 64);
5800 result_layer =
5801 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5802 test_point, render_surface_layer_list);
5803 ASSERT_TRUE(result_layer);
5804 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145805}
5806
[email protected]989386c2013-07-18 21:37:235807TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325808 HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) {
5809 // The layer's device_scale_factor and page_scale_factor should scale the
5810 // content rect and we should be able to hit the touch handler region by
5811 // scaling the points accordingly.
5812 FakeImplProxy proxy;
5813 FakeLayerTreeHostImpl host_impl(&proxy);
5814 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145815
[email protected]fb661802013-03-25 01:59:325816 gfx::Transform identity_matrix;
5817 gfx::PointF anchor;
5818 // Set the bounds of the root layer big enough to fit the child when scaled.
5819 SetLayerPropertiesForTesting(root.get(),
5820 identity_matrix,
5821 identity_matrix,
5822 anchor,
5823 gfx::PointF(),
5824 gfx::Size(100, 100),
5825 false);
5826 {
5827 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5828 gfx::PointF position(25.f, 25.f);
5829 gfx::Size bounds(50, 50);
5830 scoped_ptr<LayerImpl> test_layer =
5831 LayerImpl::Create(host_impl.active_tree(), 12345);
5832 SetLayerPropertiesForTesting(test_layer.get(),
5833 identity_matrix,
5834 identity_matrix,
5835 anchor,
5836 position,
5837 bounds,
5838 false);
[email protected]94f206c12012-08-25 00:09:145839
[email protected]fb661802013-03-25 01:59:325840 test_layer->SetDrawsContent(true);
5841 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5842 root->AddChild(test_layer.Pass());
5843 }
[email protected]94f206c12012-08-25 00:09:145844
[email protected]50761e92013-03-29 20:51:285845 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:325846 float device_scale_factor = 3.f;
5847 float page_scale_factor = 5.f;
[email protected]fb661802013-03-25 01:59:325848 gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize(
5849 gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor));
[email protected]7aad55f2013-07-26 11:25:535850
5851 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5852 root.get(), scaled_bounds_for_root, &render_surface_layer_list);
5853 inputs.device_scale_factor = device_scale_factor;
5854 inputs.page_scale_factor = page_scale_factor;
5855 inputs.page_scale_application_layer = root.get();
5856 inputs.can_adjust_raster_scales = true;
5857 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145858
[email protected]fb661802013-03-25 01:59:325859 // Sanity check the scenario we just created.
5860 // The visible content rect for test_layer is actually 100x100, even though
5861 // its layout size is 50x50, positioned at 25x25.
5862 LayerImpl* test_layer = root->children()[0];
5863 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455864 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145865
[email protected]fb661802013-03-25 01:59:325866 // Check whether the child layer fits into the root after scaled.
5867 EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()),
5868 test_layer->visible_content_rect());
5869
5870 // Hit checking for a point outside the layer should return a null pointer
5871 // (the root layer does not draw content, so it will not be tested either).
5872 gfx::PointF test_point(76.f, 76.f);
5873 test_point =
5874 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5875 LayerImpl* result_layer =
5876 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5877 test_point, render_surface_layer_list);
5878 EXPECT_FALSE(result_layer);
5879
5880 // Hit checking for a point inside the layer, but outside the touch handler
5881 // region should return a null pointer.
5882 test_point = gfx::Point(26, 26);
5883 test_point =
5884 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5885 result_layer =
5886 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5887 test_point, render_surface_layer_list);
5888 EXPECT_FALSE(result_layer);
5889
5890 test_point = gfx::Point(34, 34);
5891 test_point =
5892 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5893 result_layer =
5894 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5895 test_point, render_surface_layer_list);
5896 EXPECT_FALSE(result_layer);
5897
5898 test_point = gfx::Point(65, 65);
5899 test_point =
5900 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5901 result_layer =
5902 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5903 test_point, render_surface_layer_list);
5904 EXPECT_FALSE(result_layer);
5905
5906 test_point = gfx::Point(74, 74);
5907 test_point =
5908 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5909 result_layer =
5910 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5911 test_point, render_surface_layer_list);
5912 EXPECT_FALSE(result_layer);
5913
5914 // Hit checking for a point inside the touch event handler region should
5915 // return the root layer.
5916 test_point = gfx::Point(35, 35);
5917 test_point =
5918 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5919 result_layer =
5920 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5921 test_point, render_surface_layer_list);
5922 ASSERT_TRUE(result_layer);
5923 EXPECT_EQ(12345, result_layer->id());
5924
5925 test_point = gfx::Point(64, 64);
5926 test_point =
5927 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5928 result_layer =
5929 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5930 test_point, render_surface_layer_list);
5931 ASSERT_TRUE(result_layer);
5932 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145933}
5934
[email protected]989386c2013-07-18 21:37:235935TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325936 HitCheckingTouchHandlerRegionsForSimpleClippedLayer) {
5937 // Test that hit-checking will only work for the visible portion of a layer,
5938 // and not the entire layer bounds. Here we just test the simple axis-aligned
5939 // case.
5940 gfx::Transform identity_matrix;
5941 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145942
[email protected]fb661802013-03-25 01:59:325943 FakeImplProxy proxy;
5944 FakeLayerTreeHostImpl host_impl(&proxy);
5945 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5946 SetLayerPropertiesForTesting(root.get(),
5947 identity_matrix,
5948 identity_matrix,
5949 anchor,
5950 gfx::PointF(),
5951 gfx::Size(100, 100),
5952 false);
5953 {
5954 scoped_ptr<LayerImpl> clipping_layer =
5955 LayerImpl::Create(host_impl.active_tree(), 123);
5956 // this layer is positioned, and hit testing should correctly know where the
5957 // layer is located.
5958 gfx::PointF position(25.f, 25.f);
5959 gfx::Size bounds(50, 50);
5960 SetLayerPropertiesForTesting(clipping_layer.get(),
5961 identity_matrix,
5962 identity_matrix,
5963 anchor,
5964 position,
5965 bounds,
5966 false);
5967 clipping_layer->SetMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:145968
[email protected]fb661802013-03-25 01:59:325969 scoped_ptr<LayerImpl> child =
5970 LayerImpl::Create(host_impl.active_tree(), 456);
5971 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5972 position = gfx::PointF(-50.f, -50.f);
5973 bounds = gfx::Size(300, 300);
5974 SetLayerPropertiesForTesting(child.get(),
5975 identity_matrix,
5976 identity_matrix,
5977 anchor,
5978 position,
5979 bounds,
5980 false);
5981 child->SetDrawsContent(true);
5982 child->SetTouchEventHandlerRegion(touch_handler_region);
5983 clipping_layer->AddChild(child.Pass());
5984 root->AddChild(clipping_layer.Pass());
5985 }
[email protected]94f206c12012-08-25 00:09:145986
[email protected]50761e92013-03-29 20:51:285987 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535988 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5989 root.get(), root->bounds(), &render_surface_layer_list);
5990 inputs.can_adjust_raster_scales = true;
5991 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325992
5993 // Sanity check the scenario we just created.
5994 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:455995 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5996 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:325997
5998 // Hit checking for a point outside the layer should return a null pointer.
5999 // Despite the child layer being very large, it should be clipped to the root
6000 // layer's bounds.
6001 gfx::Point test_point(24, 24);
6002 LayerImpl* result_layer =
6003 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6004 test_point, render_surface_layer_list);
6005 EXPECT_FALSE(result_layer);
6006
6007 // Hit checking for a point inside the layer, but outside the touch handler
6008 // region should return a null pointer.
6009 test_point = gfx::Point(35, 35);
6010 result_layer =
6011 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6012 test_point, render_surface_layer_list);
6013 EXPECT_FALSE(result_layer);
6014
6015 test_point = gfx::Point(74, 74);
6016 result_layer =
6017 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6018 test_point, render_surface_layer_list);
6019 EXPECT_FALSE(result_layer);
6020
6021 // Hit checking for a point inside the touch event handler region should
6022 // return the root layer.
6023 test_point = gfx::Point(25, 25);
6024 result_layer =
6025 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6026 test_point, render_surface_layer_list);
6027 ASSERT_TRUE(result_layer);
6028 EXPECT_EQ(456, result_layer->id());
6029
6030 test_point = gfx::Point(34, 34);
6031 result_layer =
6032 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6033 test_point, render_surface_layer_list);
6034 ASSERT_TRUE(result_layer);
6035 EXPECT_EQ(456, result_layer->id());
[email protected]94f206c12012-08-25 00:09:146036}
6037
[email protected]c974d5d2013-10-24 01:02:486038TEST_F(LayerTreeHostCommonTest,
6039 HitCheckingTouchHandlerOverlappingRegions) {
6040 gfx::Transform identity_matrix;
6041 gfx::PointF anchor;
6042
6043 FakeImplProxy proxy;
6044 FakeLayerTreeHostImpl host_impl(&proxy);
6045 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
6046 SetLayerPropertiesForTesting(root.get(),
6047 identity_matrix,
6048 identity_matrix,
6049 anchor,
6050 gfx::PointF(),
6051 gfx::Size(100, 100),
6052 false);
6053 {
6054 scoped_ptr<LayerImpl> touch_layer =
6055 LayerImpl::Create(host_impl.active_tree(), 123);
6056 // this layer is positioned, and hit testing should correctly know where the
6057 // layer is located.
6058 gfx::PointF position;
6059 gfx::Size bounds(50, 50);
6060 SetLayerPropertiesForTesting(touch_layer.get(),
6061 identity_matrix,
6062 identity_matrix,
6063 anchor,
6064 position,
6065 bounds,
6066 false);
6067 touch_layer->SetDrawsContent(true);
6068 touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50));
6069 root->AddChild(touch_layer.Pass());
6070 }
6071
6072 {
6073 scoped_ptr<LayerImpl> notouch_layer =
6074 LayerImpl::Create(host_impl.active_tree(), 1234);
6075 // this layer is positioned, and hit testing should correctly know where the
6076 // layer is located.
6077 gfx::PointF position(0, 25);
6078 gfx::Size bounds(50, 50);
6079 SetLayerPropertiesForTesting(notouch_layer.get(),
6080 identity_matrix,
6081 identity_matrix,
6082 anchor,
6083 position,
6084 bounds,
6085 false);
6086 notouch_layer->SetDrawsContent(true);
6087 root->AddChild(notouch_layer.Pass());
6088 }
6089
6090 LayerImplList render_surface_layer_list;
6091 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6092 root.get(), root->bounds(), &render_surface_layer_list);
6093 inputs.can_adjust_raster_scales = true;
6094 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6095
6096 // Sanity check the scenario we just created.
6097 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]22538a2d2013-11-12 11:24:456098 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
6099 ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id());
6100 ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id());
[email protected]c974d5d2013-10-24 01:02:486101
6102 gfx::Point test_point(35, 35);
6103 LayerImpl* result_layer =
6104 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6105 test_point, render_surface_layer_list);
6106 EXPECT_FALSE(result_layer);
6107
6108 test_point = gfx::Point(35, 15);
6109 result_layer =
6110 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6111 test_point, render_surface_layer_list);
6112 ASSERT_TRUE(result_layer);
6113 EXPECT_EQ(123, result_layer->id());
6114
6115 test_point = gfx::Point(35, 65);
6116 result_layer =
6117 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6118 test_point, render_surface_layer_list);
6119 EXPECT_FALSE(result_layer);
6120}
6121
[email protected]fb661802013-03-25 01:59:326122class NoScaleContentLayer : public ContentLayer {
6123 public:
6124 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
6125 return make_scoped_refptr(new NoScaleContentLayer(client));
6126 }
[email protected]94f206c12012-08-25 00:09:146127
[email protected]fb661802013-03-25 01:59:326128 virtual void CalculateContentsScale(float ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066129 float device_scale_factor,
6130 float page_scale_factor,
[email protected]fb661802013-03-25 01:59:326131 bool animating_transform_to_screen,
6132 float* contents_scale_x,
6133 float* contents_scale_y,
6134 gfx::Size* content_bounds) OVERRIDE {
6135 // Skip over the ContentLayer to the base Layer class.
6136 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066137 device_scale_factor,
6138 page_scale_factor,
[email protected]fb661802013-03-25 01:59:326139 animating_transform_to_screen,
6140 contents_scale_x,
6141 contents_scale_y,
6142 content_bounds);
6143 }
[email protected]94f206c12012-08-25 00:09:146144
[email protected]fb661802013-03-25 01:59:326145 protected:
6146 explicit NoScaleContentLayer(ContentLayerClient* client)
6147 : ContentLayer(client) {}
6148 virtual ~NoScaleContentLayer() {}
[email protected]518ee582012-10-24 18:29:446149};
6150
[email protected]fb661802013-03-25 01:59:326151scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
6152 ContentLayerClient* delegate) {
6153 scoped_refptr<NoScaleContentLayer> to_return =
6154 NoScaleContentLayer::Create(delegate);
6155 to_return->SetIsDrawable(true);
6156 return to_return;
[email protected]518ee582012-10-24 18:29:446157}
6158
[email protected]989386c2013-07-18 21:37:236159TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326160 // Verify draw and screen space transforms of layers not in a surface.
6161 MockContentLayerClient delegate;
6162 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:146163
[email protected]fb661802013-03-25 01:59:326164 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6165 SetLayerPropertiesForTesting(parent.get(),
6166 identity_matrix,
6167 identity_matrix,
6168 gfx::PointF(),
6169 gfx::PointF(),
6170 gfx::Size(100, 100),
6171 true);
[email protected]94f206c12012-08-25 00:09:146172
[email protected]fb661802013-03-25 01:59:326173 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6174 SetLayerPropertiesForTesting(child.get(),
6175 identity_matrix,
6176 identity_matrix,
6177 gfx::PointF(),
6178 gfx::PointF(2.f, 2.f),
6179 gfx::Size(10, 10),
6180 true);
[email protected]94f206c12012-08-25 00:09:146181
[email protected]fb661802013-03-25 01:59:326182 scoped_refptr<ContentLayer> child_empty =
6183 CreateDrawableContentLayer(&delegate);
6184 SetLayerPropertiesForTesting(child_empty.get(),
6185 identity_matrix,
6186 identity_matrix,
6187 gfx::PointF(),
6188 gfx::PointF(2.f, 2.f),
6189 gfx::Size(),
6190 true);
[email protected]f89f5632012-11-14 23:34:456191
[email protected]fb661802013-03-25 01:59:326192 scoped_refptr<NoScaleContentLayer> child_no_scale =
6193 CreateNoScaleDrawableContentLayer(&delegate);
6194 SetLayerPropertiesForTesting(child_no_scale.get(),
6195 identity_matrix,
6196 identity_matrix,
6197 gfx::PointF(),
6198 gfx::PointF(2.f, 2.f),
6199 gfx::Size(10, 10),
6200 true);
[email protected]94f206c12012-08-25 00:09:146201
[email protected]fb661802013-03-25 01:59:326202 parent->AddChild(child);
6203 parent->AddChild(child_empty);
6204 parent->AddChild(child_no_scale);
[email protected]94f206c12012-08-25 00:09:146205
[email protected]d600df7d2013-08-03 02:34:286206 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6207 host->SetRootLayer(parent);
6208
[email protected]fb661802013-03-25 01:59:326209 float device_scale_factor = 2.5f;
6210 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:146211
[email protected]7aad55f2013-07-26 11:25:536212 RenderSurfaceLayerList render_surface_layer_list;
6213 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6214 parent.get(), parent->bounds(), &render_surface_layer_list);
6215 inputs.device_scale_factor = device_scale_factor;
6216 inputs.page_scale_factor = page_scale_factor;
6217 inputs.can_adjust_raster_scales = true;
6218 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446219
[email protected]fb661802013-03-25 01:59:326220 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6221 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6222 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6223 child_empty);
6224 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]94f206c12012-08-25 00:09:146225
[email protected]fb661802013-03-25 01:59:326226 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:146227
[email protected]fb661802013-03-25 01:59:326228 // Verify parent transforms
6229 gfx::Transform expected_parent_transform;
6230 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6231 parent->screen_space_transform());
6232 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6233 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:146234
[email protected]fb661802013-03-25 01:59:326235 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056236 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:146237
[email protected]fb661802013-03-25 01:59:326238 gfx::RectF parent_draw_rect =
6239 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6240 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6241 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:146242
[email protected]2c7c6702013-03-26 03:14:056243 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326244 expected_parent_draw_rect.Scale(device_scale_factor);
6245 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6246 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146247
[email protected]fb661802013-03-25 01:59:326248 // Verify child and child_empty transforms. They should match.
6249 gfx::Transform expected_child_transform;
6250 expected_child_transform.Translate(
6251 device_scale_factor * child->position().x(),
6252 device_scale_factor * child->position().y());
6253 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6254 child->draw_transform());
6255 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6256 child->screen_space_transform());
6257 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6258 child_empty->draw_transform());
6259 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6260 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146261
[email protected]fb661802013-03-25 01:59:326262 // Verify results of transformed child and child_empty rects. They should
6263 // match.
[email protected]2c7c6702013-03-26 03:14:056264 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:146265
[email protected]fb661802013-03-25 01:59:326266 gfx::RectF child_draw_rect =
6267 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6268 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6269 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:146270
[email protected]fb661802013-03-25 01:59:326271 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
6272 child_empty->draw_transform(), child_content_bounds);
6273 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
6274 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:456275
[email protected]fb661802013-03-25 01:59:326276 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
6277 expected_child_draw_rect.Scale(device_scale_factor);
6278 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6279 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
6280 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
6281 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146282
[email protected]fb661802013-03-25 01:59:326283 // Verify child_no_scale transforms
6284 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6285 // All transforms operate on content rects. The child's content rect
6286 // incorporates device scale, but the child_no_scale does not; add it here.
6287 expected_child_no_scale_transform.Scale(device_scale_factor,
6288 device_scale_factor);
6289 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6290 child_no_scale->draw_transform());
6291 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6292 child_no_scale->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146293}
6294
[email protected]989386c2013-07-18 21:37:236295TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326296 // Verify draw and screen space transforms of layers in a surface.
6297 MockContentLayerClient delegate;
6298 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:096299
[email protected]fb661802013-03-25 01:59:326300 gfx::Transform perspective_matrix;
6301 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:096302
[email protected]fb661802013-03-25 01:59:326303 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:056304 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:096305
[email protected]9781afa2013-07-17 23:15:326306 scoped_refptr<Layer> root = Layer::Create();
6307
[email protected]fb661802013-03-25 01:59:326308 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6309 SetLayerPropertiesForTesting(parent.get(),
6310 identity_matrix,
6311 identity_matrix,
6312 gfx::PointF(),
6313 gfx::PointF(),
6314 gfx::Size(100, 100),
6315 true);
[email protected]1b30e8e2012-12-21 02:59:096316
[email protected]fb661802013-03-25 01:59:326317 scoped_refptr<ContentLayer> perspective_surface =
6318 CreateDrawableContentLayer(&delegate);
6319 SetLayerPropertiesForTesting(perspective_surface.get(),
6320 perspective_matrix * scale_small_matrix,
6321 identity_matrix,
6322 gfx::PointF(),
6323 gfx::PointF(2.f, 2.f),
6324 gfx::Size(10, 10),
6325 true);
[email protected]1b30e8e2012-12-21 02:59:096326
[email protected]fb661802013-03-25 01:59:326327 scoped_refptr<ContentLayer> scale_surface =
6328 CreateDrawableContentLayer(&delegate);
6329 SetLayerPropertiesForTesting(scale_surface.get(),
6330 scale_small_matrix,
6331 identity_matrix,
6332 gfx::PointF(),
6333 gfx::PointF(2.f, 2.f),
6334 gfx::Size(10, 10),
6335 true);
[email protected]1b30e8e2012-12-21 02:59:096336
[email protected]fb661802013-03-25 01:59:326337 perspective_surface->SetForceRenderSurface(true);
6338 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:096339
[email protected]fb661802013-03-25 01:59:326340 parent->AddChild(perspective_surface);
6341 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:326342 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:096343
[email protected]d600df7d2013-08-03 02:34:286344 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6345 host->SetRootLayer(root);
6346
[email protected]fb661802013-03-25 01:59:326347 float device_scale_factor = 2.5f;
6348 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:096349
[email protected]7aad55f2013-07-26 11:25:536350 RenderSurfaceLayerList render_surface_layer_list;
6351 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6352 root.get(), parent->bounds(), &render_surface_layer_list);
6353 inputs.device_scale_factor = device_scale_factor;
6354 inputs.page_scale_factor = page_scale_factor;
6355 inputs.page_scale_application_layer = root;
6356 inputs.can_adjust_raster_scales = true;
6357 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:096358
[email protected]fb661802013-03-25 01:59:326359 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6360 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6361 perspective_surface);
6362 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6363 scale_surface);
[email protected]1b30e8e2012-12-21 02:59:096364
[email protected]fb661802013-03-25 01:59:326365 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:096366
[email protected]fb661802013-03-25 01:59:326367 gfx::Transform expected_parent_draw_transform;
6368 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
6369 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096370
[email protected]fb661802013-03-25 01:59:326371 // The scaled surface is rendered at its appropriate scale, and drawn 1:1
6372 // into its target.
6373 gfx::Transform expected_scale_surface_draw_transform;
6374 expected_scale_surface_draw_transform.Translate(
6375 device_scale_factor * page_scale_factor * scale_surface->position().x(),
6376 device_scale_factor * page_scale_factor * scale_surface->position().y());
[email protected]fb661802013-03-25 01:59:326377 EXPECT_TRANSFORMATION_MATRIX_EQ(
6378 expected_scale_surface_draw_transform,
6379 scale_surface->render_surface()->draw_transform());
[email protected]a52c6ff2013-05-04 05:33:156380 gfx::Transform expected_scale_surface_layer_draw_transform =
6381 scale_small_matrix;
[email protected]fb661802013-03-25 01:59:326382 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform,
6383 scale_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096384
[email protected]fb661802013-03-25 01:59:326385 // The scale for the perspective surface is not known, so it is rendered 1:1
6386 // with the screen, and then scaled during drawing.
6387 gfx::Transform expected_perspective_surface_draw_transform;
6388 expected_perspective_surface_draw_transform.Translate(
6389 device_scale_factor * page_scale_factor *
6390 perspective_surface->position().x(),
6391 device_scale_factor * page_scale_factor *
6392 perspective_surface->position().y());
6393 expected_perspective_surface_draw_transform.PreconcatTransform(
6394 perspective_matrix);
6395 expected_perspective_surface_draw_transform.PreconcatTransform(
6396 scale_small_matrix);
6397 gfx::Transform expected_perspective_surface_layer_draw_transform;
6398 EXPECT_TRANSFORMATION_MATRIX_EQ(
6399 expected_perspective_surface_draw_transform,
6400 perspective_surface->render_surface()->draw_transform());
6401 EXPECT_TRANSFORMATION_MATRIX_EQ(
6402 expected_perspective_surface_layer_draw_transform,
6403 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096404}
6405
[email protected]989386c2013-07-18 21:37:236406TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:326407 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
6408 // Verify draw and screen space transforms of layers not in a surface.
6409 MockContentLayerClient delegate;
6410 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:476411
[email protected]fb661802013-03-25 01:59:326412 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6413 SetLayerPropertiesForTesting(parent.get(),
6414 identity_matrix,
6415 identity_matrix,
6416 gfx::PointF(),
6417 gfx::PointF(),
6418 gfx::Size(133, 133),
6419 true);
[email protected]904e9132012-11-01 00:12:476420
[email protected]fb661802013-03-25 01:59:326421 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6422 SetLayerPropertiesForTesting(child.get(),
6423 identity_matrix,
6424 identity_matrix,
6425 gfx::PointF(),
6426 gfx::PointF(),
6427 gfx::Size(13, 13),
6428 true);
[email protected]904e9132012-11-01 00:12:476429
[email protected]fb661802013-03-25 01:59:326430 scoped_refptr<NoScaleContentLayer> child_no_scale =
6431 CreateNoScaleDrawableContentLayer(&delegate);
6432 SetLayerPropertiesForTesting(child_no_scale.get(),
6433 identity_matrix,
6434 identity_matrix,
6435 gfx::PointF(),
6436 gfx::PointF(),
6437 gfx::Size(13, 13),
6438 true);
[email protected]904e9132012-11-01 00:12:476439
[email protected]fb661802013-03-25 01:59:326440 parent->AddChild(child);
6441 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:476442
[email protected]d600df7d2013-08-03 02:34:286443 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6444 host->SetRootLayer(parent);
6445
[email protected]fb661802013-03-25 01:59:326446 float device_scale_factor = 1.7f;
6447 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:476448
[email protected]7aad55f2013-07-26 11:25:536449 RenderSurfaceLayerList render_surface_layer_list;
6450 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6451 parent.get(), parent->bounds(), &render_surface_layer_list);
6452 inputs.device_scale_factor = device_scale_factor;
6453 inputs.page_scale_factor = page_scale_factor;
6454 inputs.page_scale_application_layer = parent.get();
6455 inputs.can_adjust_raster_scales = true;
6456 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:476457
[email protected]fb661802013-03-25 01:59:326458 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6459 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6460 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:476461
[email protected]fb661802013-03-25 01:59:326462 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:476463
[email protected]fb661802013-03-25 01:59:326464 // Verify parent transforms
6465 gfx::Transform expected_parent_transform;
6466 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6467 parent->screen_space_transform());
6468 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6469 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:476470
[email protected]fb661802013-03-25 01:59:326471 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056472 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:476473
[email protected]fb661802013-03-25 01:59:326474 gfx::RectF parent_draw_rect =
6475 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6476 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6477 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:476478
[email protected]2c7c6702013-03-26 03:14:056479 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326480 expected_parent_draw_rect.Scale(device_scale_factor);
6481 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
6482 expected_parent_draw_rect.set_height(
6483 ceil(expected_parent_draw_rect.height()));
6484 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6485 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476486
[email protected]fb661802013-03-25 01:59:326487 // Verify child transforms
6488 gfx::Transform expected_child_transform;
6489 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6490 child->draw_transform());
6491 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6492 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476493
[email protected]fb661802013-03-25 01:59:326494 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:056495 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:476496
[email protected]fb661802013-03-25 01:59:326497 gfx::RectF child_draw_rect =
6498 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6499 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6500 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:476501
[email protected]2c7c6702013-03-26 03:14:056502 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:326503 expected_child_draw_rect.Scale(device_scale_factor);
6504 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
6505 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
6506 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6507 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476508
[email protected]fb661802013-03-25 01:59:326509 // Verify child_no_scale transforms
6510 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6511 // All transforms operate on content rects. The child's content rect
6512 // incorporates device scale, but the child_no_scale does not; add it here.
6513 expected_child_no_scale_transform.Scale(device_scale_factor,
6514 device_scale_factor);
6515 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6516 child_no_scale->draw_transform());
6517 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6518 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476519}
6520
[email protected]989386c2013-07-18 21:37:236521TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:326522 MockContentLayerClient delegate;
6523 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446524
[email protected]fb661802013-03-25 01:59:326525 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266526 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326527 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446528
[email protected]fb661802013-03-25 01:59:326529 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266530 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326531 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446532
[email protected]35a99a12013-05-09 23:52:296533 scoped_refptr<Layer> root = Layer::Create();
6534 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446535
[email protected]fb661802013-03-25 01:59:326536 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6537 SetLayerPropertiesForTesting(parent.get(),
6538 parent_scale_matrix,
6539 identity_matrix,
6540 gfx::PointF(),
6541 gfx::PointF(),
6542 gfx::Size(100, 100),
6543 true);
[email protected]518ee582012-10-24 18:29:446544
[email protected]fb661802013-03-25 01:59:326545 scoped_refptr<ContentLayer> child_scale =
6546 CreateDrawableContentLayer(&delegate);
6547 SetLayerPropertiesForTesting(child_scale.get(),
6548 child_scale_matrix,
6549 identity_matrix,
6550 gfx::PointF(),
6551 gfx::PointF(2.f, 2.f),
6552 gfx::Size(10, 10),
6553 true);
[email protected]518ee582012-10-24 18:29:446554
[email protected]fb661802013-03-25 01:59:326555 scoped_refptr<ContentLayer> child_empty =
6556 CreateDrawableContentLayer(&delegate);
6557 SetLayerPropertiesForTesting(child_empty.get(),
6558 child_scale_matrix,
6559 identity_matrix,
6560 gfx::PointF(),
6561 gfx::PointF(2.f, 2.f),
6562 gfx::Size(),
6563 true);
[email protected]f89f5632012-11-14 23:34:456564
[email protected]fb661802013-03-25 01:59:326565 scoped_refptr<NoScaleContentLayer> child_no_scale =
6566 CreateNoScaleDrawableContentLayer(&delegate);
6567 SetLayerPropertiesForTesting(child_no_scale.get(),
6568 child_scale_matrix,
6569 identity_matrix,
6570 gfx::PointF(),
6571 gfx::PointF(12.f, 12.f),
6572 gfx::Size(10, 10),
6573 true);
[email protected]518ee582012-10-24 18:29:446574
[email protected]35a99a12013-05-09 23:52:296575 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446576
[email protected]fb661802013-03-25 01:59:326577 parent->AddChild(child_scale);
6578 parent->AddChild(child_empty);
6579 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:446580
[email protected]d600df7d2013-08-03 02:34:286581 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6582 host->SetRootLayer(root);
6583
[email protected]fb661802013-03-25 01:59:326584 float device_scale_factor = 2.5f;
6585 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:446586
[email protected]989386c2013-07-18 21:37:236587 {
6588 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536589 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6590 root.get(), root->bounds(), &render_surface_layer_list);
6591 inputs.device_scale_factor = device_scale_factor;
6592 inputs.page_scale_factor = page_scale_factor;
6593 inputs.page_scale_application_layer = root.get();
6594 inputs.can_adjust_raster_scales = true;
6595 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446596
[email protected]989386c2013-07-18 21:37:236597 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6598 initial_parent_scale, parent);
6599 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6600 initial_parent_scale * initial_child_scale,
6601 child_scale);
6602 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6603 initial_parent_scale * initial_child_scale,
6604 child_empty);
6605 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:446606
[email protected]989386c2013-07-18 21:37:236607 // The parent is scaled up and shouldn't need to scale during draw. The
6608 // child that can scale its contents should also not need to scale during
6609 // draw. This shouldn't change if the child has empty bounds. The other
6610 // children should.
[email protected]803f6b52013-09-12 00:51:266611 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
6612 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
6613 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
6614 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
6615 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
6616 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236617 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6618 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266619 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:236620 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266621 initial_parent_scale * initial_child_scale,
6622 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236623 }
[email protected]518ee582012-10-24 18:29:446624
[email protected]fb661802013-03-25 01:59:326625 // If the device_scale_factor or page_scale_factor changes, then it should be
6626 // updated using the initial transform as the raster scale.
6627 device_scale_factor = 2.25f;
6628 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:446629
[email protected]989386c2013-07-18 21:37:236630 {
6631 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536632 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6633 root.get(), root->bounds(), &render_surface_layer_list);
6634 inputs.device_scale_factor = device_scale_factor;
6635 inputs.page_scale_factor = page_scale_factor;
6636 inputs.page_scale_application_layer = root.get();
6637 inputs.can_adjust_raster_scales = true;
6638 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6639
6640 EXPECT_CONTENTS_SCALE_EQ(
6641 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:236642 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536643 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:236644 child_scale);
6645 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6646 initial_parent_scale * initial_child_scale,
6647 child_empty);
6648 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6649 }
[email protected]d0518202013-02-08 02:06:496650
[email protected]fb661802013-03-25 01:59:326651 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:266652 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326653 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
6654 second_child_scale / initial_child_scale);
6655 child_scale->SetTransform(child_scale_matrix);
6656 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:496657
[email protected]989386c2013-07-18 21:37:236658 {
6659 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536660 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6661 root.get(), root->bounds(), &render_surface_layer_list);
6662 inputs.device_scale_factor = device_scale_factor;
6663 inputs.page_scale_factor = page_scale_factor;
6664 inputs.page_scale_application_layer = root.get();
6665 inputs.can_adjust_raster_scales = true;
6666 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496667
[email protected]989386c2013-07-18 21:37:236668 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6669 initial_parent_scale,
6670 parent);
6671 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6672 child_scale);
6673 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6674 child_empty);
6675 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6676 }
[email protected]d0518202013-02-08 02:06:496677
[email protected]fb661802013-03-25 01:59:326678 // If the device_scale_factor or page_scale_factor changes, then it should be
6679 // updated, but still using 1.0 as the raster scale.
6680 device_scale_factor = 2.75f;
6681 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:496682
[email protected]989386c2013-07-18 21:37:236683 {
6684 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536685 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6686 root.get(), root->bounds(), &render_surface_layer_list);
6687 inputs.device_scale_factor = device_scale_factor;
6688 inputs.page_scale_factor = page_scale_factor;
6689 inputs.page_scale_application_layer = root.get();
6690 inputs.can_adjust_raster_scales = true;
6691 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496692
[email protected]989386c2013-07-18 21:37:236693 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6694 initial_parent_scale,
6695 parent);
6696 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6697 child_scale);
6698 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6699 child_empty);
6700 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6701 }
[email protected]518ee582012-10-24 18:29:446702}
6703
[email protected]989386c2013-07-18 21:37:236704TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:296705 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:326706 MockContentLayerClient delegate;
6707 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:216708
[email protected]fb661802013-03-25 01:59:326709 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266710 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326711 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:216712
[email protected]fb661802013-03-25 01:59:326713 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266714 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326715 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:216716
[email protected]35a99a12013-05-09 23:52:296717 scoped_refptr<Layer> root = Layer::Create();
6718 root->SetBounds(gfx::Size(100, 100));
6719
[email protected]fb661802013-03-25 01:59:326720 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6721 SetLayerPropertiesForTesting(parent.get(),
6722 parent_scale_matrix,
6723 identity_matrix,
6724 gfx::PointF(),
6725 gfx::PointF(),
6726 gfx::Size(100, 100),
6727 true);
[email protected]11ec92972012-11-10 03:06:216728
[email protected]fb661802013-03-25 01:59:326729 scoped_refptr<ContentLayer> child_scale =
6730 CreateDrawableContentLayer(&delegate);
6731 SetLayerPropertiesForTesting(child_scale.get(),
6732 child_scale_matrix,
6733 identity_matrix,
6734 gfx::PointF(),
6735 gfx::PointF(2.f, 2.f),
6736 gfx::Size(10, 10),
6737 true);
[email protected]11ec92972012-11-10 03:06:216738
[email protected]35a99a12013-05-09 23:52:296739 scoped_refptr<ContentLayer> child_empty =
6740 CreateDrawableContentLayer(&delegate);
6741 SetLayerPropertiesForTesting(child_empty.get(),
6742 child_scale_matrix,
6743 identity_matrix,
6744 gfx::PointF(),
6745 gfx::PointF(2.f, 2.f),
6746 gfx::Size(),
6747 true);
6748
6749 scoped_refptr<NoScaleContentLayer> child_no_scale =
6750 CreateNoScaleDrawableContentLayer(&delegate);
6751 SetLayerPropertiesForTesting(child_no_scale.get(),
6752 child_scale_matrix,
6753 identity_matrix,
6754 gfx::PointF(),
6755 gfx::PointF(12.f, 12.f),
6756 gfx::Size(10, 10),
6757 true);
6758
6759 root->AddChild(parent);
6760
6761 parent->AddChild(child_scale);
6762 parent->AddChild(child_empty);
6763 parent->AddChild(child_no_scale);
6764
[email protected]d600df7d2013-08-03 02:34:286765 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6766 host->SetRootLayer(root);
6767
[email protected]989386c2013-07-18 21:37:236768 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:296769
6770 float device_scale_factor = 2.5f;
6771 float page_scale_factor = 1.f;
6772
[email protected]7aad55f2013-07-26 11:25:536773 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6774 root.get(), root->bounds(), &render_surface_layer_list);
6775 inputs.device_scale_factor = device_scale_factor;
6776 inputs.page_scale_factor = page_scale_factor;
6777 inputs.page_scale_application_layer = root.get(),
6778 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:296779
6780 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6781 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6782 child_scale);
6783 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6784 child_empty);
6785 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6786
6787 // Since the transform scale does not affect contents scale, it should affect
6788 // the draw transform instead.
6789 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266790 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296791 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266792 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296793 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266794 child_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296795 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266796 child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296797 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266798 child_empty->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296799 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266800 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296801 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266802 initial_parent_scale * initial_child_scale,
6803 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296804 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266805 initial_parent_scale * initial_child_scale,
6806 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296807}
6808
[email protected]989386c2013-07-18 21:37:236809TEST_F(LayerTreeHostCommonTest, SmallContentsScale) {
[email protected]35a99a12013-05-09 23:52:296810 MockContentLayerClient delegate;
6811 gfx::Transform identity_matrix;
6812
6813 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266814 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:296815 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6816
6817 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266818 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:296819 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6820
6821 scoped_refptr<Layer> root = Layer::Create();
6822 root->SetBounds(gfx::Size(100, 100));
6823
6824 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6825 SetLayerPropertiesForTesting(parent.get(),
6826 parent_scale_matrix,
6827 identity_matrix,
6828 gfx::PointF(),
6829 gfx::PointF(),
6830 gfx::Size(100, 100),
6831 true);
6832
6833 scoped_refptr<ContentLayer> child_scale =
6834 CreateDrawableContentLayer(&delegate);
6835 SetLayerPropertiesForTesting(child_scale.get(),
6836 child_scale_matrix,
6837 identity_matrix,
6838 gfx::PointF(),
6839 gfx::PointF(2.f, 2.f),
6840 gfx::Size(10, 10),
6841 true);
6842
6843 root->AddChild(parent);
6844
[email protected]fb661802013-03-25 01:59:326845 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:216846
[email protected]d600df7d2013-08-03 02:34:286847 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6848 host->SetRootLayer(root);
6849
[email protected]fb661802013-03-25 01:59:326850 float device_scale_factor = 2.5f;
6851 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:216852
[email protected]989386c2013-07-18 21:37:236853 {
6854 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536855 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6856 root.get(), root->bounds(), &render_surface_layer_list);
6857 inputs.device_scale_factor = device_scale_factor;
6858 inputs.page_scale_factor = page_scale_factor;
6859 inputs.page_scale_application_layer = root.get();
6860 inputs.can_adjust_raster_scales = true;
6861 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216862
[email protected]989386c2013-07-18 21:37:236863 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6864 initial_parent_scale,
6865 parent);
6866 // The child's scale is < 1, so we should not save and use that scale
6867 // factor.
6868 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1,
6869 child_scale);
6870 }
[email protected]11ec92972012-11-10 03:06:216871
[email protected]fb661802013-03-25 01:59:326872 // When chilld's total scale becomes >= 1, we should save and use that scale
6873 // factor.
6874 child_scale_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:266875 SkMScalar final_child_scale = 0.75;
[email protected]fb661802013-03-25 01:59:326876 child_scale_matrix.Scale(final_child_scale, final_child_scale);
6877 child_scale->SetTransform(child_scale_matrix);
[email protected]11ec92972012-11-10 03:06:216878
[email protected]989386c2013-07-18 21:37:236879 {
6880 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536881 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6882 root.get(), root->bounds(), &render_surface_layer_list);
6883 inputs.device_scale_factor = device_scale_factor;
6884 inputs.page_scale_factor = page_scale_factor;
6885 inputs.page_scale_application_layer = root.get();
6886 inputs.can_adjust_raster_scales = true;
6887 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216888
[email protected]989386c2013-07-18 21:37:236889 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6890 initial_parent_scale,
6891 parent);
6892 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6893 initial_parent_scale * final_child_scale,
6894 child_scale);
6895 }
[email protected]11ec92972012-11-10 03:06:216896}
6897
[email protected]989386c2013-07-18 21:37:236898TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:326899 MockContentLayerClient delegate;
6900 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446901
[email protected]fb661802013-03-25 01:59:326902 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266903 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:326904 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446905
[email protected]fb661802013-03-25 01:59:326906 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266907 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:326908 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446909
[email protected]35a99a12013-05-09 23:52:296910 scoped_refptr<Layer> root = Layer::Create();
6911 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446912
[email protected]fb661802013-03-25 01:59:326913 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6914 SetLayerPropertiesForTesting(parent.get(),
6915 parent_scale_matrix,
6916 identity_matrix,
6917 gfx::PointF(),
6918 gfx::PointF(),
6919 gfx::Size(100, 100),
6920 true);
[email protected]518ee582012-10-24 18:29:446921
[email protected]fb661802013-03-25 01:59:326922 scoped_refptr<ContentLayer> surface_scale =
6923 CreateDrawableContentLayer(&delegate);
6924 SetLayerPropertiesForTesting(surface_scale.get(),
6925 child_scale_matrix,
6926 identity_matrix,
6927 gfx::PointF(),
6928 gfx::PointF(2.f, 2.f),
6929 gfx::Size(10, 10),
6930 true);
[email protected]518ee582012-10-24 18:29:446931
[email protected]fb661802013-03-25 01:59:326932 scoped_refptr<ContentLayer> surface_scale_child_scale =
6933 CreateDrawableContentLayer(&delegate);
6934 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
6935 child_scale_matrix,
6936 identity_matrix,
6937 gfx::PointF(),
6938 gfx::PointF(),
6939 gfx::Size(10, 10),
6940 true);
[email protected]518ee582012-10-24 18:29:446941
[email protected]fb661802013-03-25 01:59:326942 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
6943 CreateNoScaleDrawableContentLayer(&delegate);
6944 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
6945 child_scale_matrix,
6946 identity_matrix,
6947 gfx::PointF(),
6948 gfx::PointF(),
6949 gfx::Size(10, 10),
6950 true);
[email protected]518ee582012-10-24 18:29:446951
[email protected]fb661802013-03-25 01:59:326952 scoped_refptr<NoScaleContentLayer> surface_no_scale =
6953 CreateNoScaleDrawableContentLayer(&delegate);
6954 SetLayerPropertiesForTesting(surface_no_scale.get(),
6955 child_scale_matrix,
6956 identity_matrix,
6957 gfx::PointF(),
6958 gfx::PointF(12.f, 12.f),
6959 gfx::Size(10, 10),
6960 true);
[email protected]518ee582012-10-24 18:29:446961
[email protected]fb661802013-03-25 01:59:326962 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
6963 CreateDrawableContentLayer(&delegate);
6964 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
6965 child_scale_matrix,
6966 identity_matrix,
6967 gfx::PointF(),
6968 gfx::PointF(),
6969 gfx::Size(10, 10),
6970 true);
[email protected]518ee582012-10-24 18:29:446971
[email protected]fb661802013-03-25 01:59:326972 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
6973 CreateNoScaleDrawableContentLayer(&delegate);
6974 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
6975 child_scale_matrix,
6976 identity_matrix,
6977 gfx::PointF(),
6978 gfx::PointF(),
6979 gfx::Size(10, 10),
6980 true);
[email protected]518ee582012-10-24 18:29:446981
[email protected]35a99a12013-05-09 23:52:296982 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446983
[email protected]fb661802013-03-25 01:59:326984 parent->AddChild(surface_scale);
6985 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:446986
[email protected]fb661802013-03-25 01:59:326987 surface_scale->SetForceRenderSurface(true);
6988 surface_scale->AddChild(surface_scale_child_scale);
6989 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446990
[email protected]fb661802013-03-25 01:59:326991 surface_no_scale->SetForceRenderSurface(true);
6992 surface_no_scale->AddChild(surface_no_scale_child_scale);
6993 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446994
[email protected]d600df7d2013-08-03 02:34:286995 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6996 host->SetRootLayer(root);
6997
[email protected]803f6b52013-09-12 00:51:266998 SkMScalar device_scale_factor = 5;
6999 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:447000
[email protected]7aad55f2013-07-26 11:25:537001 RenderSurfaceLayerList render_surface_layer_list;
7002 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7003 root.get(), root->bounds(), &render_surface_layer_list);
7004 inputs.device_scale_factor = device_scale_factor;
7005 inputs.page_scale_factor = page_scale_factor;
7006 inputs.page_scale_application_layer = root.get();
7007 inputs.can_adjust_raster_scales = true;
7008 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7009
7010 EXPECT_CONTENTS_SCALE_EQ(
7011 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:197012 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:537013 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:327014 surface_scale);
7015 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
7016 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:327017 device_scale_factor * page_scale_factor * initial_parent_scale *
7018 initial_child_scale * initial_child_scale,
7019 surface_scale_child_scale);
7020 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
7021 EXPECT_CONTENTS_SCALE_EQ(
7022 device_scale_factor * page_scale_factor * initial_parent_scale *
7023 initial_child_scale * initial_child_scale,
7024 surface_no_scale_child_scale);
7025 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:447026
[email protected]fb661802013-03-25 01:59:327027 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:267028 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
7029 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447030
[email protected]fb661802013-03-25 01:59:327031 // RenderSurfaces should always be 1:1 with their target.
7032 EXPECT_FLOAT_EQ(
7033 1.0,
[email protected]803f6b52013-09-12 00:51:267034 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327035 EXPECT_FLOAT_EQ(
7036 1.0,
[email protected]803f6b52013-09-12 00:51:267037 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447038
[email protected]fb661802013-03-25 01:59:327039 // The surface_scale can apply contents scale so the layer shouldn't need to
7040 // scale during draw.
[email protected]803f6b52013-09-12 00:51:267041 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
7042 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447043
[email protected]fb661802013-03-25 01:59:327044 // The surface_scale_child_scale can apply contents scale so it shouldn't need
7045 // to scale during draw.
7046 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267047 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327048 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267049 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447050
[email protected]fb661802013-03-25 01:59:327051 // The surface_scale_child_no_scale can not apply contents scale, so it needs
7052 // to be scaled during draw.
7053 EXPECT_FLOAT_EQ(
7054 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267055 initial_child_scale * initial_child_scale,
7056 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327057 EXPECT_FLOAT_EQ(
7058 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267059 initial_child_scale * initial_child_scale,
7060 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447061
[email protected]fb661802013-03-25 01:59:327062 // RenderSurfaces should always be 1:1 with their target.
7063 EXPECT_FLOAT_EQ(
7064 1.0,
[email protected]803f6b52013-09-12 00:51:267065 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327066 EXPECT_FLOAT_EQ(
7067 1.0,
[email protected]803f6b52013-09-12 00:51:267068 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447069
[email protected]fb661802013-03-25 01:59:327070 // The surface_no_scale layer can not apply contents scale, so it needs to be
7071 // scaled during draw.
7072 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:267073 initial_parent_scale * initial_child_scale,
7074 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327075 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:267076 initial_parent_scale * initial_child_scale,
7077 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447078
[email protected]fb661802013-03-25 01:59:327079 // The surface_scale_child_scale can apply contents scale so it shouldn't need
7080 // to scale during draw.
7081 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267082 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327083 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267084 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447085
[email protected]fb661802013-03-25 01:59:327086 // The surface_scale_child_no_scale can not apply contents scale, so it needs
7087 // to be scaled during draw.
7088 EXPECT_FLOAT_EQ(
7089 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267090 initial_child_scale * initial_child_scale,
7091 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327092 EXPECT_FLOAT_EQ(
7093 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267094 initial_child_scale * initial_child_scale,
7095 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297096}
[email protected]518ee582012-10-24 18:29:447097
[email protected]989386c2013-07-18 21:37:237098TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:297099 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
7100 MockContentLayerClient delegate;
7101 gfx::Transform identity_matrix;
7102
7103 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267104 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:297105 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
7106
7107 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267108 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:297109 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
7110
7111 scoped_refptr<Layer> root = Layer::Create();
7112 root->SetBounds(gfx::Size(100, 100));
7113
7114 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7115 SetLayerPropertiesForTesting(parent.get(),
7116 parent_scale_matrix,
7117 identity_matrix,
7118 gfx::PointF(),
7119 gfx::PointF(),
7120 gfx::Size(100, 100),
7121 true);
7122
7123 scoped_refptr<ContentLayer> surface_scale =
7124 CreateDrawableContentLayer(&delegate);
7125 SetLayerPropertiesForTesting(surface_scale.get(),
7126 child_scale_matrix,
7127 identity_matrix,
7128 gfx::PointF(),
7129 gfx::PointF(2.f, 2.f),
7130 gfx::Size(10, 10),
7131 true);
7132
7133 scoped_refptr<ContentLayer> surface_scale_child_scale =
7134 CreateDrawableContentLayer(&delegate);
7135 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
7136 child_scale_matrix,
7137 identity_matrix,
7138 gfx::PointF(),
7139 gfx::PointF(),
7140 gfx::Size(10, 10),
7141 true);
7142
7143 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
7144 CreateNoScaleDrawableContentLayer(&delegate);
7145 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
7146 child_scale_matrix,
7147 identity_matrix,
7148 gfx::PointF(),
7149 gfx::PointF(),
7150 gfx::Size(10, 10),
7151 true);
7152
7153 scoped_refptr<NoScaleContentLayer> surface_no_scale =
7154 CreateNoScaleDrawableContentLayer(&delegate);
7155 SetLayerPropertiesForTesting(surface_no_scale.get(),
7156 child_scale_matrix,
7157 identity_matrix,
7158 gfx::PointF(),
7159 gfx::PointF(12.f, 12.f),
7160 gfx::Size(10, 10),
7161 true);
7162
7163 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
7164 CreateDrawableContentLayer(&delegate);
7165 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
7166 child_scale_matrix,
7167 identity_matrix,
7168 gfx::PointF(),
7169 gfx::PointF(),
7170 gfx::Size(10, 10),
7171 true);
7172
7173 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
7174 CreateNoScaleDrawableContentLayer(&delegate);
7175 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
7176 child_scale_matrix,
7177 identity_matrix,
7178 gfx::PointF(),
7179 gfx::PointF(),
7180 gfx::Size(10, 10),
7181 true);
7182
7183 root->AddChild(parent);
7184
7185 parent->AddChild(surface_scale);
7186 parent->AddChild(surface_no_scale);
7187
7188 surface_scale->SetForceRenderSurface(true);
7189 surface_scale->AddChild(surface_scale_child_scale);
7190 surface_scale->AddChild(surface_scale_child_no_scale);
7191
7192 surface_no_scale->SetForceRenderSurface(true);
7193 surface_no_scale->AddChild(surface_no_scale_child_scale);
7194 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
7195
[email protected]d600df7d2013-08-03 02:34:287196 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7197 host->SetRootLayer(root);
7198
[email protected]989386c2013-07-18 21:37:237199 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:297200
[email protected]803f6b52013-09-12 00:51:267201 SkMScalar device_scale_factor = 5.0;
7202 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:537203 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7204 root.get(), root->bounds(), &render_surface_layer_list);
7205 inputs.device_scale_factor = device_scale_factor;
7206 inputs.page_scale_factor = page_scale_factor;
7207 inputs.page_scale_application_layer = root.get();
7208 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:297209
[email protected]35a99a12013-05-09 23:52:297210 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7211 parent);
7212 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7213 surface_scale);
7214 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
7215 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7216 surface_scale_child_scale);
7217 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
7218 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7219 surface_no_scale_child_scale);
7220 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
7221
7222 // The parent is scaled up during draw, since its contents are not scaled by
7223 // the transform hierarchy.
7224 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267225 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297226 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267227 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297228
7229 // The child surface is scaled up during draw since its subtree is not scaled
7230 // by the transform hierarchy.
7231 EXPECT_FLOAT_EQ(
7232 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267233 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297234 EXPECT_FLOAT_EQ(
7235 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267236 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297237
7238 // The surface_scale's RenderSurface is scaled during draw, so the layer does
7239 // not need to be scaled when drawing into its surface.
[email protected]803f6b52013-09-12 00:51:267240 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
7241 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447242
[email protected]35a99a12013-05-09 23:52:297243 // The surface_scale_child_scale is scaled when drawing into its surface,
7244 // since its content bounds are not scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:327245 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297246 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267247 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327248 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297249 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267250 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447251
[email protected]35a99a12013-05-09 23:52:297252 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
7253 // needs to be scaled by the device and page scale factors, along with the
7254 // transform hierarchy.
[email protected]fb661802013-03-25 01:59:327255 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297256 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267257 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297258 EXPECT_FLOAT_EQ(
7259 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267260 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297261
7262 // The child surface is scaled up during draw since its subtree is not scaled
7263 // by the transform hierarchy.
7264 EXPECT_FLOAT_EQ(
7265 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267266 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327267 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297268 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267269 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447270
[email protected]35a99a12013-05-09 23:52:297271 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
7272 // be scaled by the device and page scale factors. Its surface is already
7273 // scaled by the transform hierarchy so those don't need to scale the layer's
7274 // drawing.
7275 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267276 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297277 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267278 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297279
7280 // The surface_no_scale_child_scale has its contents scaled by the page and
7281 // device scale factors, but needs to be scaled by the transform hierarchy
7282 // when drawing.
[email protected]fb661802013-03-25 01:59:327283 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297284 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267285 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327286 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297287 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267288 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297289
7290 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
7291 // needs to be scaled by the device and page scale factors. It also needs to
7292 // be scaled by any transform heirarchy below its target surface.
7293 EXPECT_FLOAT_EQ(
7294 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267295 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297296 EXPECT_FLOAT_EQ(
7297 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267298 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447299}
7300
[email protected]989386c2013-07-18 21:37:237301TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:327302 MockContentLayerClient delegate;
7303 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267304
[email protected]fb661802013-03-25 01:59:327305 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267306 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:327307 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:267308
[email protected]fb661802013-03-25 01:59:327309 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267310 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:327311 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:267312
[email protected]35a99a12013-05-09 23:52:297313 scoped_refptr<Layer> root = Layer::Create();
7314 root->SetBounds(gfx::Size(100, 100));
7315
[email protected]fb661802013-03-25 01:59:327316 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7317 SetLayerPropertiesForTesting(parent.get(),
7318 parent_scale_matrix,
7319 identity_matrix,
7320 gfx::PointF(),
7321 gfx::PointF(),
7322 gfx::Size(100, 100),
7323 true);
[email protected]6a9cff92012-11-08 11:53:267324
[email protected]fb661802013-03-25 01:59:327325 scoped_refptr<ContentLayer> child_scale =
7326 CreateDrawableContentLayer(&delegate);
7327 SetLayerPropertiesForTesting(child_scale.get(),
7328 child_scale_matrix,
7329 identity_matrix,
7330 gfx::PointF(),
7331 gfx::PointF(2.f, 2.f),
7332 gfx::Size(10, 10),
7333 true);
[email protected]6a9cff92012-11-08 11:53:267334
[email protected]35a99a12013-05-09 23:52:297335 root->AddChild(parent);
7336
[email protected]fb661802013-03-25 01:59:327337 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:267338
[email protected]d600df7d2013-08-03 02:34:287339 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7340 host->SetRootLayer(root);
7341
[email protected]fb661802013-03-25 01:59:327342 // Now put an animating transform on child.
7343 int animation_id = AddAnimatedTransformToController(
7344 child_scale->layer_animation_controller(), 10.0, 30, 0);
[email protected]6a9cff92012-11-08 11:53:267345
[email protected]989386c2013-07-18 21:37:237346 {
7347 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537348 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7349 root.get(), root->bounds(), &render_surface_layer_list);
7350 inputs.can_adjust_raster_scales = true;
7351 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267352
[email protected]989386c2013-07-18 21:37:237353 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7354 // The layers with animating transforms should not compute a contents scale
7355 // other than 1 until they finish animating.
7356 EXPECT_CONTENTS_SCALE_EQ(1, child_scale);
7357 }
[email protected]6a9cff92012-11-08 11:53:267358
[email protected]fb661802013-03-25 01:59:327359 // Remove the animation, now it can save a raster scale.
7360 child_scale->layer_animation_controller()->RemoveAnimation(animation_id);
[email protected]6a9cff92012-11-08 11:53:267361
[email protected]989386c2013-07-18 21:37:237362 {
7363 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537364 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7365 root.get(), root->bounds(), &render_surface_layer_list);
7366 inputs.can_adjust_raster_scales = true;
7367 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267368
[email protected]989386c2013-07-18 21:37:237369 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7370 // The layers with animating transforms should not compute a contents scale
7371 // other than 1 until they finish animating.
7372 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale,
7373 child_scale);
7374 }
[email protected]6a9cff92012-11-08 11:53:267375}
7376
[email protected]989386c2013-07-18 21:37:237377TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:327378 MockContentLayerClient delegate;
7379 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267380
[email protected]fb661802013-03-25 01:59:327381 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7382 SetLayerPropertiesForTesting(parent.get(),
7383 identity_matrix,
7384 identity_matrix,
7385 gfx::PointF(),
7386 gfx::PointF(),
7387 gfx::Size(30, 30),
7388 true);
[email protected]94f206c12012-08-25 00:09:147389
[email protected]fb661802013-03-25 01:59:327390 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7391 SetLayerPropertiesForTesting(child.get(),
7392 identity_matrix,
7393 identity_matrix,
7394 gfx::PointF(),
7395 gfx::PointF(2.f, 2.f),
7396 gfx::Size(10, 10),
7397 true);
[email protected]94f206c12012-08-25 00:09:147398
[email protected]fb661802013-03-25 01:59:327399 gfx::Transform replica_transform;
7400 replica_transform.Scale(1.0, -1.0);
7401 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7402 SetLayerPropertiesForTesting(replica.get(),
7403 replica_transform,
7404 identity_matrix,
7405 gfx::PointF(),
7406 gfx::PointF(2.f, 2.f),
7407 gfx::Size(10, 10),
7408 true);
[email protected]94f206c12012-08-25 00:09:147409
[email protected]fb661802013-03-25 01:59:327410 // This layer should end up in the same surface as child, with the same draw
7411 // and screen space transforms.
7412 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7413 CreateDrawableContentLayer(&delegate);
7414 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7415 identity_matrix,
7416 identity_matrix,
7417 gfx::PointF(),
7418 gfx::PointF(),
7419 gfx::Size(10, 10),
7420 true);
[email protected]94f206c12012-08-25 00:09:147421
[email protected]fb661802013-03-25 01:59:327422 parent->AddChild(child);
7423 child->AddChild(duplicate_child_non_owner);
7424 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:147425
[email protected]d600df7d2013-08-03 02:34:287426 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7427 host->SetRootLayer(parent);
7428
[email protected]989386c2013-07-18 21:37:237429 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:147430
[email protected]fb661802013-03-25 01:59:327431 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:537432 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7433 parent.get(), parent->bounds(), &render_surface_layer_list);
7434 inputs.device_scale_factor = device_scale_factor;
7435 inputs.can_adjust_raster_scales = true;
7436 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:147437
[email protected]fb661802013-03-25 01:59:327438 // We should have two render surfaces. The root's render surface and child's
7439 // render surface (it needs one because it has a replica layer).
7440 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:147441
[email protected]fb661802013-03-25 01:59:327442 gfx::Transform expected_parent_transform;
7443 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7444 parent->screen_space_transform());
7445 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7446 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:147447
[email protected]fb661802013-03-25 01:59:327448 gfx::Transform expected_draw_transform;
7449 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
7450 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:147451
[email protected]fb661802013-03-25 01:59:327452 gfx::Transform expected_screen_space_transform;
7453 expected_screen_space_transform.Translate(
7454 device_scale_factor * child->position().x(),
7455 device_scale_factor * child->position().y());
7456 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
7457 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147458
[email protected]fb661802013-03-25 01:59:327459 gfx::Transform expected_duplicate_child_draw_transform =
7460 child->draw_transform();
7461 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
7462 duplicate_child_non_owner->draw_transform());
7463 EXPECT_TRANSFORMATION_MATRIX_EQ(
7464 child->screen_space_transform(),
7465 duplicate_child_non_owner->screen_space_transform());
7466 EXPECT_RECT_EQ(child->drawable_content_rect(),
7467 duplicate_child_non_owner->drawable_content_rect());
7468 EXPECT_EQ(child->content_bounds(),
7469 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:147470
[email protected]fb661802013-03-25 01:59:327471 gfx::Transform expected_render_surface_draw_transform;
7472 expected_render_surface_draw_transform.Translate(
7473 device_scale_factor * child->position().x(),
7474 device_scale_factor * child->position().y());
7475 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
7476 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147477
[email protected]fb661802013-03-25 01:59:327478 gfx::Transform expected_surface_draw_transform;
7479 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
7480 device_scale_factor * 2.f);
7481 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
7482 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147483
[email protected]fb661802013-03-25 01:59:327484 gfx::Transform expected_surface_screen_space_transform;
7485 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
7486 device_scale_factor * 2.f);
7487 EXPECT_TRANSFORMATION_MATRIX_EQ(
7488 expected_surface_screen_space_transform,
7489 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147490
[email protected]fb661802013-03-25 01:59:327491 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267492 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
7493 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
7494 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327495 EXPECT_TRANSFORMATION_MATRIX_EQ(
7496 expected_replica_draw_transform,
7497 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:147498
[email protected]fb661802013-03-25 01:59:327499 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267500 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
7501 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
7502 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327503 EXPECT_TRANSFORMATION_MATRIX_EQ(
7504 expected_replica_screen_space_transform,
7505 child->render_surface()->replica_screen_space_transform());
7506 EXPECT_TRANSFORMATION_MATRIX_EQ(
7507 expected_replica_screen_space_transform,
7508 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:477509}
7510
[email protected]989386c2013-07-18 21:37:237511TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:327512 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
7513 MockContentLayerClient delegate;
7514 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:477515
[email protected]fb661802013-03-25 01:59:327516 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7517 SetLayerPropertiesForTesting(parent.get(),
7518 identity_matrix,
7519 identity_matrix,
7520 gfx::PointF(),
7521 gfx::PointF(),
7522 gfx::Size(33, 31),
7523 true);
[email protected]904e9132012-11-01 00:12:477524
[email protected]fb661802013-03-25 01:59:327525 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7526 SetLayerPropertiesForTesting(child.get(),
7527 identity_matrix,
7528 identity_matrix,
7529 gfx::PointF(),
7530 gfx::PointF(),
7531 gfx::Size(13, 11),
7532 true);
[email protected]904e9132012-11-01 00:12:477533
[email protected]fb661802013-03-25 01:59:327534 gfx::Transform replica_transform;
7535 replica_transform.Scale(1.0, -1.0);
7536 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7537 SetLayerPropertiesForTesting(replica.get(),
7538 replica_transform,
7539 identity_matrix,
7540 gfx::PointF(),
7541 gfx::PointF(),
7542 gfx::Size(13, 11),
7543 true);
[email protected]904e9132012-11-01 00:12:477544
[email protected]fb661802013-03-25 01:59:327545 // This layer should end up in the same surface as child, with the same draw
7546 // and screen space transforms.
7547 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7548 CreateDrawableContentLayer(&delegate);
7549 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7550 identity_matrix,
7551 identity_matrix,
7552 gfx::PointF(),
7553 gfx::PointF(),
7554 gfx::Size(13, 11),
7555 true);
[email protected]904e9132012-11-01 00:12:477556
[email protected]fb661802013-03-25 01:59:327557 parent->AddChild(child);
7558 child->AddChild(duplicate_child_non_owner);
7559 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:477560
[email protected]d600df7d2013-08-03 02:34:287561 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7562 host->SetRootLayer(parent);
7563
[email protected]873639e2013-07-24 19:56:317564 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:537565
7566 RenderSurfaceLayerList render_surface_layer_list;
7567 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7568 parent.get(), parent->bounds(), &render_surface_layer_list);
7569 inputs.device_scale_factor = device_scale_factor;
7570 inputs.can_adjust_raster_scales = true;
7571 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:477572
[email protected]fb661802013-03-25 01:59:327573 // We should have two render surfaces. The root's render surface and child's
7574 // render surface (it needs one because it has a replica layer).
7575 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:477576
[email protected]fb661802013-03-25 01:59:327577 gfx::Transform identity_transform;
[email protected]904e9132012-11-01 00:12:477578
[email protected]fb661802013-03-25 01:59:327579 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7580 parent->screen_space_transform());
7581 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform());
7582 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform());
7583 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7584 child->screen_space_transform());
7585 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7586 duplicate_child_non_owner->draw_transform());
7587 EXPECT_TRANSFORMATION_MATRIX_EQ(
7588 identity_transform, duplicate_child_non_owner->screen_space_transform());
7589 EXPECT_RECT_EQ(child->drawable_content_rect(),
7590 duplicate_child_non_owner->drawable_content_rect());
7591 EXPECT_EQ(child->content_bounds(),
7592 duplicate_child_non_owner->content_bounds());
[email protected]904e9132012-11-01 00:12:477593
[email protected]fb661802013-03-25 01:59:327594 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7595 child->render_surface()->draw_transform());
7596 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7597 child->render_surface()->draw_transform());
7598 EXPECT_TRANSFORMATION_MATRIX_EQ(
7599 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:477600
[email protected]fb661802013-03-25 01:59:327601 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267602 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327603 EXPECT_TRANSFORMATION_MATRIX_EQ(
7604 expected_replica_draw_transform,
7605 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:477606
[email protected]fb661802013-03-25 01:59:327607 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267608 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327609 EXPECT_TRANSFORMATION_MATRIX_EQ(
7610 expected_replica_screen_space_transform,
7611 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147612}
7613
[email protected]989386c2013-07-18 21:37:237614TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:327615 scoped_refptr<Layer> root = Layer::Create();
7616 scoped_refptr<Layer> child = Layer::Create();
7617 scoped_refptr<Layer> grand_child = Layer::Create();
7618 scoped_refptr<Layer> mask_layer = Layer::Create();
7619 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:147620
[email protected]fb661802013-03-25 01:59:327621 grand_child->SetReplicaLayer(replica_layer.get());
7622 child->AddChild(grand_child.get());
7623 child->SetMaskLayer(mask_layer.get());
7624 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:147625
[email protected]d600df7d2013-08-03 02:34:287626 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7627 host->SetRootLayer(root);
7628
[email protected]fb661802013-03-25 01:59:327629 int nonexistent_id = -1;
7630 EXPECT_EQ(root,
7631 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
7632 EXPECT_EQ(child,
7633 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
7634 EXPECT_EQ(
7635 grand_child,
7636 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
7637 EXPECT_EQ(
7638 mask_layer,
7639 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
7640 EXPECT_EQ(
7641 replica_layer,
7642 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
7643 EXPECT_EQ(
7644 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:147645}
7646
[email protected]989386c2013-07-18 21:37:237647TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:327648 scoped_refptr<Layer> root = Layer::Create();
7649 scoped_refptr<Layer> child = Layer::Create();
7650 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
7651 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:577652
[email protected]fb661802013-03-25 01:59:327653 const gfx::Transform identity_matrix;
7654 SetLayerPropertiesForTesting(root.get(),
7655 identity_matrix,
7656 identity_matrix,
7657 gfx::PointF(),
7658 gfx::PointF(),
7659 gfx::Size(100, 100),
7660 false);
7661 SetLayerPropertiesForTesting(child.get(),
7662 identity_matrix,
7663 identity_matrix,
7664 gfx::PointF(),
7665 gfx::PointF(),
7666 gfx::Size(10, 10),
7667 false);
7668 SetLayerPropertiesForTesting(grand_child.get(),
7669 identity_matrix,
7670 identity_matrix,
7671 gfx::PointF(),
7672 gfx::PointF(),
7673 gfx::Size(10, 10),
7674 false);
[email protected]498ec6e0e2012-11-30 18:24:577675
[email protected]fb661802013-03-25 01:59:327676 root->AddChild(child);
7677 child->AddChild(grand_child);
7678 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:577679
[email protected]d600df7d2013-08-03 02:34:287680 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7681 host->SetRootLayer(root);
7682
[email protected]fb661802013-03-25 01:59:327683 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:577684
[email protected]fb661802013-03-25 01:59:327685 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:577686}
7687
[email protected]989386c2013-07-18 21:37:237688TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:167689 FakeImplProxy proxy;
7690 FakeLayerTreeHostImpl host_impl(&proxy);
7691 host_impl.CreatePendingTree();
7692 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7693
7694 const gfx::Transform identity_matrix;
7695 SetLayerPropertiesForTesting(root.get(),
7696 identity_matrix,
7697 identity_matrix,
7698 gfx::PointF(),
7699 gfx::PointF(),
7700 gfx::Size(100, 100),
7701 false);
7702 root->SetDrawsContent(true);
7703
7704 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7705 SetLayerPropertiesForTesting(child.get(),
7706 identity_matrix,
7707 identity_matrix,
7708 gfx::PointF(),
7709 gfx::PointF(),
7710 gfx::Size(50, 50),
7711 false);
7712 child->SetDrawsContent(true);
7713 child->SetOpacity(0.0f);
7714
7715 // Add opacity animation.
7716 AddOpacityTransitionToController(
7717 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
7718
7719 root->AddChild(child.Pass());
7720
[email protected]c0ae06c12013-06-24 18:32:197721 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537722 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7723 root.get(), root->bounds(), &render_surface_layer_list);
7724 inputs.can_adjust_raster_scales = true;
7725 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:167726
7727 // We should have one render surface and two layers. The child
7728 // layer should be included even though it is transparent.
7729 ASSERT_EQ(1u, render_surface_layer_list.size());
7730 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
7731}
7732
[email protected]10aabcc32012-12-13 09:18:597733typedef std::tr1::tuple<bool, bool> LCDTextTestParam;
[email protected]989386c2013-07-18 21:37:237734class LCDTextTest
7735 : public LayerTreeHostCommonTestBase,
7736 public testing::TestWithParam<LCDTextTestParam> {
[email protected]fb661802013-03-25 01:59:327737 protected:
7738 virtual void SetUp() {
7739 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
[email protected]10aabcc32012-12-13 09:18:597740
[email protected]fb661802013-03-25 01:59:327741 root_ = Layer::Create();
7742 child_ = Layer::Create();
7743 grand_child_ = Layer::Create();
7744 child_->AddChild(grand_child_.get());
7745 root_->AddChild(child_.get());
[email protected]10aabcc32012-12-13 09:18:597746
[email protected]fb661802013-03-25 01:59:327747 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307748 SetLayerPropertiesForTesting(root_.get(),
[email protected]fb661802013-03-25 01:59:327749 identity_matrix,
7750 identity_matrix,
7751 gfx::PointF(),
7752 gfx::PointF(),
7753 gfx::Size(1, 1),
7754 false);
[email protected]22898ed2013-06-01 04:52:307755 SetLayerPropertiesForTesting(child_.get(),
[email protected]fb661802013-03-25 01:59:327756 identity_matrix,
7757 identity_matrix,
7758 gfx::PointF(),
7759 gfx::PointF(),
7760 gfx::Size(1, 1),
7761 false);
[email protected]22898ed2013-06-01 04:52:307762 SetLayerPropertiesForTesting(grand_child_.get(),
[email protected]fb661802013-03-25 01:59:327763 identity_matrix,
7764 identity_matrix,
7765 gfx::PointF(),
7766 gfx::PointF(),
7767 gfx::Size(1, 1),
7768 false);
[email protected]10aabcc32012-12-13 09:18:597769
[email protected]fb661802013-03-25 01:59:327770 child_->SetForceRenderSurface(std::tr1::get<1>(GetParam()));
[email protected]d600df7d2013-08-03 02:34:287771
7772 host_ = FakeLayerTreeHost::Create();
7773 host_->SetRootLayer(root_);
[email protected]fb661802013-03-25 01:59:327774 }
[email protected]10aabcc32012-12-13 09:18:597775
[email protected]fb661802013-03-25 01:59:327776 bool can_use_lcd_text_;
[email protected]d600df7d2013-08-03 02:34:287777 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]fb661802013-03-25 01:59:327778 scoped_refptr<Layer> root_;
7779 scoped_refptr<Layer> child_;
7780 scoped_refptr<Layer> grand_child_;
[email protected]10aabcc32012-12-13 09:18:597781};
7782
[email protected]fb661802013-03-25 01:59:327783TEST_P(LCDTextTest, CanUseLCDText) {
7784 // Case 1: Identity transform.
7785 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307786 ExecuteCalculateDrawProperties(
7787 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327788 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7789 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7790 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597791
[email protected]fb661802013-03-25 01:59:327792 // Case 2: Integral translation.
7793 gfx::Transform integral_translation;
7794 integral_translation.Translate(1.0, 2.0);
7795 child_->SetTransform(integral_translation);
[email protected]22898ed2013-06-01 04:52:307796 ExecuteCalculateDrawProperties(
7797 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327798 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7799 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7800 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597801
[email protected]fb661802013-03-25 01:59:327802 // Case 3: Non-integral translation.
7803 gfx::Transform non_integral_translation;
7804 non_integral_translation.Translate(1.5, 2.5);
7805 child_->SetTransform(non_integral_translation);
[email protected]22898ed2013-06-01 04:52:307806 ExecuteCalculateDrawProperties(
7807 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327808 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7809 EXPECT_FALSE(child_->can_use_lcd_text());
7810 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597811
[email protected]fb661802013-03-25 01:59:327812 // Case 4: Rotation.
7813 gfx::Transform rotation;
7814 rotation.Rotate(10.0);
7815 child_->SetTransform(rotation);
[email protected]22898ed2013-06-01 04:52:307816 ExecuteCalculateDrawProperties(
7817 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327818 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7819 EXPECT_FALSE(child_->can_use_lcd_text());
7820 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597821
[email protected]fb661802013-03-25 01:59:327822 // Case 5: Scale.
7823 gfx::Transform scale;
7824 scale.Scale(2.0, 2.0);
7825 child_->SetTransform(scale);
[email protected]22898ed2013-06-01 04:52:307826 ExecuteCalculateDrawProperties(
7827 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327828 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7829 EXPECT_FALSE(child_->can_use_lcd_text());
7830 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597831
[email protected]fb661802013-03-25 01:59:327832 // Case 6: Skew.
7833 gfx::Transform skew;
7834 skew.SkewX(10.0);
7835 child_->SetTransform(skew);
[email protected]22898ed2013-06-01 04:52:307836 ExecuteCalculateDrawProperties(
7837 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327838 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7839 EXPECT_FALSE(child_->can_use_lcd_text());
7840 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597841
[email protected]fb661802013-03-25 01:59:327842 // Case 7: Translucent.
7843 child_->SetTransform(identity_matrix);
7844 child_->SetOpacity(0.5f);
[email protected]22898ed2013-06-01 04:52:307845 ExecuteCalculateDrawProperties(
7846 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327847 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7848 EXPECT_FALSE(child_->can_use_lcd_text());
7849 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597850
[email protected]fb661802013-03-25 01:59:327851 // Case 8: Sanity check: restore transform and opacity.
7852 child_->SetTransform(identity_matrix);
7853 child_->SetOpacity(1.f);
[email protected]22898ed2013-06-01 04:52:307854 ExecuteCalculateDrawProperties(
7855 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327856 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7857 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7858 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597859}
7860
[email protected]fd9a3b6d2013-08-03 00:46:177861TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
[email protected]fb661802013-03-25 01:59:327862 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
[email protected]22898ed2013-06-01 04:52:307863 ExecuteCalculateDrawProperties(
7864 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327865 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7866 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7867 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597868
[email protected]fb661802013-03-25 01:59:327869 // Add opacity animation.
7870 child_->SetOpacity(0.9f);
7871 AddOpacityTransitionToController(
7872 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:597873
[email protected]22898ed2013-06-01 04:52:307874 ExecuteCalculateDrawProperties(
7875 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327876 // Text AA should not be adjusted while animation is active.
7877 // Make sure LCD text AA setting remains unchanged.
7878 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7879 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7880 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597881}
7882
7883INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
7884 LCDTextTest,
[email protected]fb661802013-03-25 01:59:327885 testing::Combine(testing::Bool(), testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:597886
[email protected]989386c2013-07-18 21:37:237887TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:197888 FakeImplProxy proxy;
7889 FakeLayerTreeHostImpl host_impl(&proxy);
7890 host_impl.CreatePendingTree();
7891 const gfx::Transform identity_matrix;
7892
7893 scoped_refptr<Layer> root = Layer::Create();
7894 SetLayerPropertiesForTesting(root.get(),
7895 identity_matrix,
7896 identity_matrix,
7897 gfx::PointF(),
7898 gfx::PointF(),
7899 gfx::Size(50, 50),
7900 false);
7901 root->SetIsDrawable(true);
7902
7903 scoped_refptr<Layer> child = Layer::Create();
7904 SetLayerPropertiesForTesting(child.get(),
7905 identity_matrix,
7906 identity_matrix,
7907 gfx::PointF(),
7908 gfx::PointF(),
7909 gfx::Size(40, 40),
7910 false);
7911 child->SetIsDrawable(true);
7912
7913 scoped_refptr<Layer> grand_child = Layer::Create();
7914 SetLayerPropertiesForTesting(grand_child.get(),
7915 identity_matrix,
7916 identity_matrix,
7917 gfx::PointF(),
7918 gfx::PointF(),
7919 gfx::Size(30, 30),
7920 false);
7921 grand_child->SetIsDrawable(true);
7922 grand_child->SetHideLayerAndSubtree(true);
7923
7924 child->AddChild(grand_child);
7925 root->AddChild(child);
7926
[email protected]d600df7d2013-08-03 02:34:287927 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7928 host->SetRootLayer(root);
7929
[email protected]989386c2013-07-18 21:37:237930 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537931 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7932 root.get(), root->bounds(), &render_surface_layer_list);
7933 inputs.can_adjust_raster_scales = true;
7934 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197935
7936 // We should have one render surface and two layers. The grand child has
7937 // hidden itself.
7938 ASSERT_EQ(1u, render_surface_layer_list.size());
7939 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237940 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
7941 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197942}
7943
[email protected]989386c2013-07-18 21:37:237944TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:197945 FakeImplProxy proxy;
7946 FakeLayerTreeHostImpl host_impl(&proxy);
7947 host_impl.CreatePendingTree();
7948 const gfx::Transform identity_matrix;
7949
7950 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7951 SetLayerPropertiesForTesting(root.get(),
7952 identity_matrix,
7953 identity_matrix,
7954 gfx::PointF(),
7955 gfx::PointF(),
7956 gfx::Size(50, 50),
7957 false);
7958 root->SetDrawsContent(true);
7959
7960 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7961 SetLayerPropertiesForTesting(child.get(),
7962 identity_matrix,
7963 identity_matrix,
7964 gfx::PointF(),
7965 gfx::PointF(),
7966 gfx::Size(40, 40),
7967 false);
7968 child->SetDrawsContent(true);
7969
7970 scoped_ptr<LayerImpl> grand_child =
7971 LayerImpl::Create(host_impl.pending_tree(), 3);
7972 SetLayerPropertiesForTesting(grand_child.get(),
7973 identity_matrix,
7974 identity_matrix,
7975 gfx::PointF(),
7976 gfx::PointF(),
7977 gfx::Size(30, 30),
7978 false);
7979 grand_child->SetDrawsContent(true);
7980 grand_child->SetHideLayerAndSubtree(true);
7981
7982 child->AddChild(grand_child.Pass());
7983 root->AddChild(child.Pass());
7984
7985 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537986 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7987 root.get(), root->bounds(), &render_surface_layer_list);
7988 inputs.can_adjust_raster_scales = true;
7989 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197990
7991 // We should have one render surface and two layers. The grand child has
7992 // hidden itself.
7993 ASSERT_EQ(1u, render_surface_layer_list.size());
7994 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237995 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
7996 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197997}
7998
[email protected]989386c2013-07-18 21:37:237999TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:198000 FakeImplProxy proxy;
8001 FakeLayerTreeHostImpl host_impl(&proxy);
8002 host_impl.CreatePendingTree();
8003 const gfx::Transform identity_matrix;
8004
8005 scoped_refptr<Layer> root = Layer::Create();
8006 SetLayerPropertiesForTesting(root.get(),
8007 identity_matrix,
8008 identity_matrix,
8009 gfx::PointF(),
8010 gfx::PointF(),
8011 gfx::Size(50, 50),
8012 false);
8013 root->SetIsDrawable(true);
8014
8015 scoped_refptr<Layer> child = Layer::Create();
8016 SetLayerPropertiesForTesting(child.get(),
8017 identity_matrix,
8018 identity_matrix,
8019 gfx::PointF(),
8020 gfx::PointF(),
8021 gfx::Size(40, 40),
8022 false);
8023 child->SetIsDrawable(true);
8024 child->SetHideLayerAndSubtree(true);
8025
8026 scoped_refptr<Layer> grand_child = Layer::Create();
8027 SetLayerPropertiesForTesting(grand_child.get(),
8028 identity_matrix,
8029 identity_matrix,
8030 gfx::PointF(),
8031 gfx::PointF(),
8032 gfx::Size(30, 30),
8033 false);
8034 grand_child->SetIsDrawable(true);
8035
8036 child->AddChild(grand_child);
8037 root->AddChild(child);
8038
[email protected]d600df7d2013-08-03 02:34:288039 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8040 host->SetRootLayer(root);
8041
[email protected]989386c2013-07-18 21:37:238042 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538043 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8044 root.get(), root->bounds(), &render_surface_layer_list);
8045 inputs.can_adjust_raster_scales = true;
8046 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198047
8048 // We should have one render surface and one layers. The child has
8049 // hidden itself and the grand child.
8050 ASSERT_EQ(1u, render_surface_layer_list.size());
8051 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238052 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:198053}
8054
[email protected]989386c2013-07-18 21:37:238055TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:198056 FakeImplProxy proxy;
8057 FakeLayerTreeHostImpl host_impl(&proxy);
8058 host_impl.CreatePendingTree();
8059 const gfx::Transform identity_matrix;
8060
8061 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
8062 SetLayerPropertiesForTesting(root.get(),
8063 identity_matrix,
8064 identity_matrix,
8065 gfx::PointF(),
8066 gfx::PointF(),
8067 gfx::Size(50, 50),
8068 false);
8069 root->SetDrawsContent(true);
8070
8071 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
8072 SetLayerPropertiesForTesting(child.get(),
8073 identity_matrix,
8074 identity_matrix,
8075 gfx::PointF(),
8076 gfx::PointF(),
8077 gfx::Size(40, 40),
8078 false);
8079 child->SetDrawsContent(true);
8080 child->SetHideLayerAndSubtree(true);
8081
8082 scoped_ptr<LayerImpl> grand_child =
8083 LayerImpl::Create(host_impl.pending_tree(), 3);
8084 SetLayerPropertiesForTesting(grand_child.get(),
8085 identity_matrix,
8086 identity_matrix,
8087 gfx::PointF(),
8088 gfx::PointF(),
8089 gfx::Size(30, 30),
8090 false);
8091 grand_child->SetDrawsContent(true);
8092
8093 child->AddChild(grand_child.Pass());
8094 root->AddChild(child.Pass());
8095
8096 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538097 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8098 root.get(), root->bounds(), &render_surface_layer_list);
8099 inputs.can_adjust_raster_scales = true;
8100 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198101
8102 // We should have one render surface and one layers. The child has
8103 // hidden itself and the grand child.
8104 ASSERT_EQ(1u, render_surface_layer_list.size());
8105 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238106 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:198107}
8108
[email protected]30fe19ff2013-07-04 00:54:458109void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
8110
[email protected]989386c2013-07-18 21:37:238111TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458112 FakeImplProxy proxy;
8113 FakeLayerTreeHostImpl host_impl(&proxy);
8114 host_impl.CreatePendingTree();
8115 const gfx::Transform identity_matrix;
8116
8117 scoped_refptr<Layer> root = Layer::Create();
8118 SetLayerPropertiesForTesting(root.get(),
8119 identity_matrix,
8120 identity_matrix,
8121 gfx::PointF(),
8122 gfx::PointF(),
8123 gfx::Size(50, 50),
8124 false);
8125 root->SetIsDrawable(true);
8126
8127 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
8128 SetLayerPropertiesForTesting(copy_grand_parent.get(),
8129 identity_matrix,
8130 identity_matrix,
8131 gfx::PointF(),
8132 gfx::PointF(),
8133 gfx::Size(40, 40),
8134 false);
8135 copy_grand_parent->SetIsDrawable(true);
8136
8137 scoped_refptr<Layer> copy_parent = Layer::Create();
8138 SetLayerPropertiesForTesting(copy_parent.get(),
8139 identity_matrix,
8140 identity_matrix,
8141 gfx::PointF(),
8142 gfx::PointF(),
8143 gfx::Size(30, 30),
8144 false);
8145 copy_parent->SetIsDrawable(true);
8146 copy_parent->SetForceRenderSurface(true);
8147
8148 scoped_refptr<Layer> copy_layer = Layer::Create();
8149 SetLayerPropertiesForTesting(copy_layer.get(),
8150 identity_matrix,
8151 identity_matrix,
8152 gfx::PointF(),
8153 gfx::PointF(),
8154 gfx::Size(20, 20),
8155 false);
8156 copy_layer->SetIsDrawable(true);
8157
8158 scoped_refptr<Layer> copy_child = Layer::Create();
8159 SetLayerPropertiesForTesting(copy_child.get(),
8160 identity_matrix,
8161 identity_matrix,
8162 gfx::PointF(),
8163 gfx::PointF(),
8164 gfx::Size(20, 20),
8165 false);
8166 copy_child->SetIsDrawable(true);
8167
[email protected]ac020122013-07-12 23:45:538168 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
8169 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
8170 identity_matrix,
8171 identity_matrix,
8172 gfx::PointF(),
8173 gfx::PointF(),
8174 gfx::Size(40, 40),
8175 false);
8176 copy_grand_parent_sibling_before->SetIsDrawable(true);
8177
8178 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
8179 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
8180 identity_matrix,
8181 identity_matrix,
8182 gfx::PointF(),
8183 gfx::PointF(),
8184 gfx::Size(40, 40),
8185 false);
8186 copy_grand_parent_sibling_after->SetIsDrawable(true);
8187
[email protected]30fe19ff2013-07-04 00:54:458188 copy_layer->AddChild(copy_child);
8189 copy_parent->AddChild(copy_layer);
8190 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:538191 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:458192 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:538193 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:458194
[email protected]d600df7d2013-08-03 02:34:288195 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8196 host->SetRootLayer(root);
8197
[email protected]30fe19ff2013-07-04 00:54:458198 // Hide the copy_grand_parent and its subtree. But make a copy request in that
8199 // hidden subtree on copy_layer.
8200 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:538201 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
8202 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:458203 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8204 base::Bind(&EmptyCopyOutputCallback)));
8205 EXPECT_TRUE(copy_layer->HasCopyRequest());
8206
[email protected]989386c2013-07-18 21:37:238207 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538208 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8209 root.get(), root->bounds(), &render_surface_layer_list);
8210 inputs.can_adjust_raster_scales = true;
8211 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458212
[email protected]ac020122013-07-12 23:45:538213 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
8214 EXPECT_TRUE(copy_grand_parent->draw_properties().
8215 layer_or_descendant_has_copy_request);
8216 EXPECT_TRUE(copy_parent->draw_properties().
8217 layer_or_descendant_has_copy_request);
8218 EXPECT_TRUE(copy_layer->draw_properties().
8219 layer_or_descendant_has_copy_request);
8220 EXPECT_FALSE(copy_child->draw_properties().
8221 layer_or_descendant_has_copy_request);
8222 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
8223 layer_or_descendant_has_copy_request);
8224 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
8225 layer_or_descendant_has_copy_request);
8226
[email protected]30fe19ff2013-07-04 00:54:458227 // We should have three render surfaces, one for the root, one for the parent
8228 // since it owns a surface, and one for the copy_layer.
8229 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238230 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
8231 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
8232 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:458233
8234 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:538235 // copy_grand_parent is hidden along with its siblings, but the copy_parent
8236 // will appear since something in its subtree needs to be drawn for a copy
8237 // request.
[email protected]30fe19ff2013-07-04 00:54:458238 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238239 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
8240 EXPECT_EQ(copy_parent->id(),
8241 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458242
8243 // Nothing actually drawns into the copy parent, so only the copy_layer will
8244 // appear in its list, since it needs to be drawn for the copy request.
8245 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
8246 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238247 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458248
8249 // The copy_layer's render surface should have two contributing layers.
8250 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
8251 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238252 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458253 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:238254 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458255}
8256
[email protected]989386c2013-07-18 21:37:238257TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458258 FakeImplProxy proxy;
8259 FakeLayerTreeHostImpl host_impl(&proxy);
8260 host_impl.CreatePendingTree();
8261 const gfx::Transform identity_matrix;
8262
8263 scoped_refptr<Layer> root = Layer::Create();
8264 SetLayerPropertiesForTesting(root.get(),
8265 identity_matrix,
8266 identity_matrix,
8267 gfx::PointF(),
8268 gfx::PointF(),
8269 gfx::Size(50, 50),
8270 false);
8271 root->SetIsDrawable(true);
8272
8273 scoped_refptr<Layer> copy_parent = Layer::Create();
8274 SetLayerPropertiesForTesting(copy_parent.get(),
8275 identity_matrix,
8276 identity_matrix,
8277 gfx::PointF(),
8278 gfx::PointF(),
8279 gfx::Size(),
8280 false);
8281 copy_parent->SetIsDrawable(true);
8282 copy_parent->SetMasksToBounds(true);
8283
8284 scoped_refptr<Layer> copy_layer = Layer::Create();
8285 SetLayerPropertiesForTesting(copy_layer.get(),
8286 identity_matrix,
8287 identity_matrix,
8288 gfx::PointF(),
8289 gfx::PointF(),
8290 gfx::Size(30, 30),
8291 false);
8292 copy_layer->SetIsDrawable(true);
8293
8294 scoped_refptr<Layer> copy_child = Layer::Create();
8295 SetLayerPropertiesForTesting(copy_child.get(),
8296 identity_matrix,
8297 identity_matrix,
8298 gfx::PointF(),
8299 gfx::PointF(),
8300 gfx::Size(20, 20),
8301 false);
8302 copy_child->SetIsDrawable(true);
8303
8304 copy_layer->AddChild(copy_child);
8305 copy_parent->AddChild(copy_layer);
8306 root->AddChild(copy_parent);
8307
[email protected]d600df7d2013-08-03 02:34:288308 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8309 host->SetRootLayer(root);
8310
[email protected]30fe19ff2013-07-04 00:54:458311 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8312 base::Bind(&EmptyCopyOutputCallback)));
8313 EXPECT_TRUE(copy_layer->HasCopyRequest());
8314
[email protected]989386c2013-07-18 21:37:238315 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538316 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8317 root.get(), root->bounds(), &render_surface_layer_list);
8318 inputs.can_adjust_raster_scales = true;
8319 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458320
8321 // We should have one render surface, as the others are clipped out.
8322 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238323 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458324
8325 // The root render surface should only have 1 contributing layer, since the
8326 // other layers are empty/clipped away.
8327 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238328 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458329}
8330
[email protected]11a07b102013-07-24 17:33:198331TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
8332 FakeImplProxy proxy;
8333 FakeLayerTreeHostImpl host_impl(&proxy);
8334 host_impl.CreatePendingTree();
8335 const gfx::Transform identity_matrix;
8336
8337 scoped_refptr<Layer> root = Layer::Create();
8338 SetLayerPropertiesForTesting(root.get(),
8339 identity_matrix,
8340 identity_matrix,
8341 gfx::PointF(),
8342 gfx::PointF(),
8343 gfx::Size(50, 50),
8344 false);
8345 root->SetIsDrawable(true);
8346
8347 // The surface is moved slightly outside of the viewport.
8348 scoped_refptr<Layer> surface = Layer::Create();
8349 SetLayerPropertiesForTesting(surface.get(),
8350 identity_matrix,
8351 identity_matrix,
8352 gfx::PointF(),
8353 gfx::PointF(-10, -20),
8354 gfx::Size(),
8355 false);
8356 surface->SetForceRenderSurface(true);
8357
8358 scoped_refptr<Layer> surface_child = Layer::Create();
8359 SetLayerPropertiesForTesting(surface_child.get(),
8360 identity_matrix,
8361 identity_matrix,
8362 gfx::PointF(),
8363 gfx::PointF(),
8364 gfx::Size(50, 50),
8365 false);
8366 surface_child->SetIsDrawable(true);
8367
8368 surface->AddChild(surface_child);
8369 root->AddChild(surface);
8370
[email protected]d600df7d2013-08-03 02:34:288371 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8372 host->SetRootLayer(root);
8373
[email protected]11a07b102013-07-24 17:33:198374 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538375 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8376 root.get(), root->bounds(), &render_surface_layer_list);
8377 inputs.can_adjust_raster_scales = true;
8378 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:198379
8380 // The visible_content_rect for the |surface_child| should not be clipped by
8381 // the viewport.
8382 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
8383 surface_child->visible_content_rect().ToString());
8384}
8385
[email protected]420fdf6e2013-08-26 20:36:388386TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
8387 // Ensure that a transform between the layer and its render surface is not a
8388 // problem. Constructs the following layer tree.
8389 //
8390 // root (a render surface)
8391 // + render_surface
8392 // + clip_parent (scaled)
8393 // + intervening_clipping_layer
8394 // + clip_child
8395 //
8396 // The render surface should be resized correctly and the clip child should
8397 // inherit the right clip rect.
8398 scoped_refptr<Layer> root = Layer::Create();
8399 scoped_refptr<Layer> render_surface = Layer::Create();
8400 scoped_refptr<Layer> clip_parent = Layer::Create();
8401 scoped_refptr<Layer> intervening = Layer::Create();
8402 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8403 make_scoped_refptr(new LayerWithForcedDrawsContent);
8404
8405 root->AddChild(render_surface);
8406 render_surface->AddChild(clip_parent);
8407 clip_parent->AddChild(intervening);
8408 intervening->AddChild(clip_child);
8409
8410 clip_child->SetClipParent(clip_parent.get());
8411
8412 intervening->SetMasksToBounds(true);
8413 clip_parent->SetMasksToBounds(true);
8414
8415 render_surface->SetForceRenderSurface(true);
8416
8417 gfx::Transform scale_transform;
8418 scale_transform.Scale(2, 2);
8419
8420 gfx::Transform identity_transform;
8421
8422 SetLayerPropertiesForTesting(root.get(),
8423 identity_transform,
8424 identity_transform,
8425 gfx::PointF(),
8426 gfx::PointF(),
8427 gfx::Size(50, 50),
8428 false);
8429 SetLayerPropertiesForTesting(render_surface.get(),
8430 identity_transform,
8431 identity_transform,
8432 gfx::PointF(),
8433 gfx::PointF(),
8434 gfx::Size(10, 10),
8435 false);
8436 SetLayerPropertiesForTesting(clip_parent.get(),
8437 scale_transform,
8438 identity_transform,
8439 gfx::PointF(),
8440 gfx::PointF(1.f, 1.f),
8441 gfx::Size(10, 10),
8442 false);
8443 SetLayerPropertiesForTesting(intervening.get(),
8444 identity_transform,
8445 identity_transform,
8446 gfx::PointF(),
8447 gfx::PointF(1.f, 1.f),
8448 gfx::Size(5, 5),
8449 false);
8450 SetLayerPropertiesForTesting(clip_child.get(),
8451 identity_transform,
8452 identity_transform,
8453 gfx::PointF(),
8454 gfx::PointF(1.f, 1.f),
8455 gfx::Size(10, 10),
8456 false);
8457
8458 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8459 host->SetRootLayer(root);
8460
8461 ExecuteCalculateDrawProperties(root.get());
8462
8463 ASSERT_TRUE(root->render_surface());
8464 ASSERT_TRUE(render_surface->render_surface());
8465
8466 // Ensure that we've inherited our clip parent's clip and weren't affected
8467 // by the intervening clip layer.
8468 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
8469 clip_parent->clip_rect().ToString());
8470 ASSERT_EQ(clip_parent->clip_rect().ToString(),
8471 clip_child->clip_rect().ToString());
8472 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
8473 intervening->clip_rect().ToString());
8474
8475 // Ensure that the render surface reports a content rect that has been grown
8476 // to accomodate for the clip child.
8477 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
8478 render_surface->render_surface()->content_rect().ToString());
8479
8480 // The above check implies the two below, but they nicely demonstrate that
8481 // we've grown, despite the intervening layer's clip.
8482 ASSERT_TRUE(clip_parent->clip_rect().Contains(
8483 render_surface->render_surface()->content_rect()));
8484 ASSERT_FALSE(intervening->clip_rect().Contains(
8485 render_surface->render_surface()->content_rect()));
8486}
8487
8488TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
8489 // Ensure that intervening render surfaces are not a problem in the basic
8490 // case. In the following tree, both render surfaces should be resized to
8491 // accomodate for the clip child, despite an intervening clip.
8492 //
8493 // root (a render surface)
8494 // + clip_parent (masks to bounds)
8495 // + render_surface1 (sets opacity)
8496 // + intervening (masks to bounds)
8497 // + render_surface2 (also sets opacity)
8498 // + clip_child
8499 //
8500 scoped_refptr<Layer> root = Layer::Create();
8501 scoped_refptr<Layer> clip_parent = Layer::Create();
8502 scoped_refptr<Layer> render_surface1 = Layer::Create();
8503 scoped_refptr<Layer> intervening = Layer::Create();
8504 scoped_refptr<Layer> render_surface2 = Layer::Create();
8505 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8506 make_scoped_refptr(new LayerWithForcedDrawsContent);
8507
8508 root->AddChild(clip_parent);
8509 clip_parent->AddChild(render_surface1);
8510 render_surface1->AddChild(intervening);
8511 intervening->AddChild(render_surface2);
8512 render_surface2->AddChild(clip_child);
8513
8514 clip_child->SetClipParent(clip_parent.get());
8515
8516 intervening->SetMasksToBounds(true);
8517 clip_parent->SetMasksToBounds(true);
8518
8519 render_surface1->SetForceRenderSurface(true);
8520 render_surface2->SetForceRenderSurface(true);
8521
8522 gfx::Transform translation_transform;
8523 translation_transform.Translate(2, 2);
8524
8525 gfx::Transform identity_transform;
8526 SetLayerPropertiesForTesting(root.get(),
8527 identity_transform,
8528 identity_transform,
8529 gfx::PointF(),
8530 gfx::PointF(),
8531 gfx::Size(50, 50),
8532 false);
8533 SetLayerPropertiesForTesting(clip_parent.get(),
8534 translation_transform,
8535 identity_transform,
8536 gfx::PointF(),
8537 gfx::PointF(1.f, 1.f),
8538 gfx::Size(40, 40),
8539 false);
8540 SetLayerPropertiesForTesting(render_surface1.get(),
8541 identity_transform,
8542 identity_transform,
8543 gfx::PointF(),
8544 gfx::PointF(),
8545 gfx::Size(10, 10),
8546 false);
8547 SetLayerPropertiesForTesting(intervening.get(),
8548 identity_transform,
8549 identity_transform,
8550 gfx::PointF(),
8551 gfx::PointF(1.f, 1.f),
8552 gfx::Size(5, 5),
8553 false);
8554 SetLayerPropertiesForTesting(render_surface2.get(),
8555 identity_transform,
8556 identity_transform,
8557 gfx::PointF(),
8558 gfx::PointF(),
8559 gfx::Size(10, 10),
8560 false);
8561 SetLayerPropertiesForTesting(clip_child.get(),
8562 identity_transform,
8563 identity_transform,
8564 gfx::PointF(),
8565 gfx::PointF(-10.f, -10.f),
8566 gfx::Size(60, 60),
8567 false);
8568
8569 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8570 host->SetRootLayer(root);
8571
8572 ExecuteCalculateDrawProperties(root.get());
8573
8574 EXPECT_TRUE(root->render_surface());
8575 EXPECT_TRUE(render_surface1->render_surface());
8576 EXPECT_TRUE(render_surface2->render_surface());
8577
8578 // Since the render surfaces could have expanded, they should not clip (their
8579 // bounds would no longer be reliable). We should resort to layer clipping
8580 // in this case.
8581 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8582 render_surface1->render_surface()->clip_rect().ToString());
8583 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8584 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8585 render_surface2->render_surface()->clip_rect().ToString());
8586 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8587
8588 // NB: clip rects are in target space.
8589 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8590 render_surface1->clip_rect().ToString());
8591 EXPECT_TRUE(render_surface1->is_clipped());
8592
8593 // This value is inherited from the clipping ancestor layer, 'intervening'.
8594 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8595 render_surface2->clip_rect().ToString());
8596 EXPECT_TRUE(render_surface2->is_clipped());
8597
8598 // The content rects of both render surfaces should both have expanded to
8599 // contain the clip child.
8600 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8601 render_surface1->render_surface()->content_rect().ToString());
8602 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8603 render_surface2->render_surface()->content_rect().ToString());
8604
8605 // The clip child should have inherited the clip parent's clip (projected to
8606 // the right space, of course), and should have the correctly sized visible
8607 // content rect.
8608 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8609 clip_child->clip_rect().ToString());
8610 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
8611 clip_child->visible_content_rect().ToString());
8612 EXPECT_TRUE(clip_child->is_clipped());
8613}
8614
8615TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
8616 // Ensure that intervening render surfaces are not a problem, even if there
8617 // is a scroll involved. Note, we do _not_ have to consider any other sort
8618 // of transform.
8619 //
8620 // root (a render surface)
8621 // + clip_parent (masks to bounds)
8622 // + render_surface1 (sets opacity)
8623 // + intervening (masks to bounds AND scrolls)
8624 // + render_surface2 (also sets opacity)
8625 // + clip_child
8626 //
8627 scoped_refptr<Layer> root = Layer::Create();
8628 scoped_refptr<Layer> clip_parent = Layer::Create();
8629 scoped_refptr<Layer> render_surface1 = Layer::Create();
8630 scoped_refptr<Layer> intervening = Layer::Create();
8631 scoped_refptr<Layer> render_surface2 = Layer::Create();
8632 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8633 make_scoped_refptr(new LayerWithForcedDrawsContent);
8634
8635 root->AddChild(clip_parent);
8636 clip_parent->AddChild(render_surface1);
8637 render_surface1->AddChild(intervening);
8638 intervening->AddChild(render_surface2);
8639 render_surface2->AddChild(clip_child);
8640
8641 clip_child->SetClipParent(clip_parent.get());
8642
8643 intervening->SetMasksToBounds(true);
8644 clip_parent->SetMasksToBounds(true);
[email protected]adeda572014-01-31 00:49:478645 intervening->SetScrollClipLayerId(clip_parent->id());
[email protected]420fdf6e2013-08-26 20:36:388646 intervening->SetScrollOffset(gfx::Vector2d(3, 3));
8647
8648 render_surface1->SetForceRenderSurface(true);
8649 render_surface2->SetForceRenderSurface(true);
8650
8651 gfx::Transform translation_transform;
8652 translation_transform.Translate(2, 2);
8653
8654 gfx::Transform identity_transform;
8655 SetLayerPropertiesForTesting(root.get(),
8656 identity_transform,
8657 identity_transform,
8658 gfx::PointF(),
8659 gfx::PointF(),
8660 gfx::Size(50, 50),
8661 false);
8662 SetLayerPropertiesForTesting(clip_parent.get(),
8663 translation_transform,
8664 identity_transform,
8665 gfx::PointF(),
8666 gfx::PointF(1.f, 1.f),
8667 gfx::Size(40, 40),
8668 false);
8669 SetLayerPropertiesForTesting(render_surface1.get(),
8670 identity_transform,
8671 identity_transform,
8672 gfx::PointF(),
8673 gfx::PointF(),
8674 gfx::Size(10, 10),
8675 false);
8676 SetLayerPropertiesForTesting(intervening.get(),
8677 identity_transform,
8678 identity_transform,
8679 gfx::PointF(),
8680 gfx::PointF(1.f, 1.f),
8681 gfx::Size(5, 5),
8682 false);
8683 SetLayerPropertiesForTesting(render_surface2.get(),
8684 identity_transform,
8685 identity_transform,
8686 gfx::PointF(),
8687 gfx::PointF(),
8688 gfx::Size(10, 10),
8689 false);
8690 SetLayerPropertiesForTesting(clip_child.get(),
8691 identity_transform,
8692 identity_transform,
8693 gfx::PointF(),
8694 gfx::PointF(-10.f, -10.f),
8695 gfx::Size(60, 60),
8696 false);
8697
8698 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8699 host->SetRootLayer(root);
8700
8701 ExecuteCalculateDrawProperties(root.get());
8702
8703 EXPECT_TRUE(root->render_surface());
8704 EXPECT_TRUE(render_surface1->render_surface());
8705 EXPECT_TRUE(render_surface2->render_surface());
8706
8707 // Since the render surfaces could have expanded, they should not clip (their
8708 // bounds would no longer be reliable). We should resort to layer clipping
8709 // in this case.
8710 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8711 render_surface1->render_surface()->clip_rect().ToString());
8712 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8713 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8714 render_surface2->render_surface()->clip_rect().ToString());
8715 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8716
8717 // NB: clip rects are in target space.
8718 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8719 render_surface1->clip_rect().ToString());
8720 EXPECT_TRUE(render_surface1->is_clipped());
8721
8722 // This value is inherited from the clipping ancestor layer, 'intervening'.
8723 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
8724 render_surface2->clip_rect().ToString());
8725 EXPECT_TRUE(render_surface2->is_clipped());
8726
8727 // The content rects of both render surfaces should both have expanded to
8728 // contain the clip child.
8729 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8730 render_surface1->render_surface()->content_rect().ToString());
8731 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8732 render_surface2->render_surface()->content_rect().ToString());
8733
8734 // The clip child should have inherited the clip parent's clip (projected to
8735 // the right space, of course), and should have the correctly sized visible
8736 // content rect.
8737 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8738 clip_child->clip_rect().ToString());
8739 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
8740 clip_child->visible_content_rect().ToString());
8741 EXPECT_TRUE(clip_child->is_clipped());
8742}
8743
8744TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
8745 // Ensures that descendants of the clip child inherit the correct clip.
8746 //
8747 // root (a render surface)
8748 // + clip_parent (masks to bounds)
8749 // + intervening (masks to bounds)
8750 // + clip_child
8751 // + child
8752 //
8753 scoped_refptr<Layer> root = Layer::Create();
8754 scoped_refptr<Layer> clip_parent = Layer::Create();
8755 scoped_refptr<Layer> intervening = Layer::Create();
8756 scoped_refptr<Layer> clip_child = Layer::Create();
8757 scoped_refptr<LayerWithForcedDrawsContent> child =
8758 make_scoped_refptr(new LayerWithForcedDrawsContent);
8759
8760 root->AddChild(clip_parent);
8761 clip_parent->AddChild(intervening);
8762 intervening->AddChild(clip_child);
8763 clip_child->AddChild(child);
8764
8765 clip_child->SetClipParent(clip_parent.get());
8766
8767 intervening->SetMasksToBounds(true);
8768 clip_parent->SetMasksToBounds(true);
8769
8770 gfx::Transform identity_transform;
8771 SetLayerPropertiesForTesting(root.get(),
8772 identity_transform,
8773 identity_transform,
8774 gfx::PointF(),
8775 gfx::PointF(),
8776 gfx::Size(50, 50),
8777 false);
8778 SetLayerPropertiesForTesting(clip_parent.get(),
8779 identity_transform,
8780 identity_transform,
8781 gfx::PointF(),
8782 gfx::PointF(),
8783 gfx::Size(40, 40),
8784 false);
8785 SetLayerPropertiesForTesting(intervening.get(),
8786 identity_transform,
8787 identity_transform,
8788 gfx::PointF(),
8789 gfx::PointF(),
8790 gfx::Size(5, 5),
8791 false);
8792 SetLayerPropertiesForTesting(clip_child.get(),
8793 identity_transform,
8794 identity_transform,
8795 gfx::PointF(),
8796 gfx::PointF(),
8797 gfx::Size(60, 60),
8798 false);
8799 SetLayerPropertiesForTesting(child.get(),
8800 identity_transform,
8801 identity_transform,
8802 gfx::PointF(),
8803 gfx::PointF(),
8804 gfx::Size(60, 60),
8805 false);
8806
8807 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8808 host->SetRootLayer(root);
8809
8810 ExecuteCalculateDrawProperties(root.get());
8811
8812 EXPECT_TRUE(root->render_surface());
8813
8814 // Neither the clip child nor its descendant should have inherited the clip
8815 // from |intervening|.
8816 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8817 clip_child->clip_rect().ToString());
8818 EXPECT_TRUE(clip_child->is_clipped());
8819 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8820 child->visible_content_rect().ToString());
8821 EXPECT_TRUE(child->is_clipped());
8822}
8823
8824TEST_F(LayerTreeHostCommonTest,
8825 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
8826 // Ensures that non-descendant clip children in the tree do not affect
8827 // render surfaces.
8828 //
8829 // root (a render surface)
8830 // + clip_parent (masks to bounds)
8831 // + render_surface1
8832 // + clip_child
8833 // + render_surface2
8834 // + non_clip_child
8835 //
8836 // In this example render_surface2 should be unaffected by clip_child.
8837 scoped_refptr<Layer> root = Layer::Create();
8838 scoped_refptr<Layer> clip_parent = Layer::Create();
8839 scoped_refptr<Layer> render_surface1 = Layer::Create();
8840 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8841 make_scoped_refptr(new LayerWithForcedDrawsContent);
8842 scoped_refptr<Layer> render_surface2 = Layer::Create();
8843 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
8844 make_scoped_refptr(new LayerWithForcedDrawsContent);
8845
8846 root->AddChild(clip_parent);
8847 clip_parent->AddChild(render_surface1);
8848 render_surface1->AddChild(clip_child);
8849 clip_parent->AddChild(render_surface2);
8850 render_surface2->AddChild(non_clip_child);
8851
8852 clip_child->SetClipParent(clip_parent.get());
8853
8854 clip_parent->SetMasksToBounds(true);
8855 render_surface1->SetMasksToBounds(true);
8856
8857 gfx::Transform identity_transform;
8858 SetLayerPropertiesForTesting(root.get(),
8859 identity_transform,
8860 identity_transform,
8861 gfx::PointF(),
8862 gfx::PointF(),
8863 gfx::Size(15, 15),
8864 false);
8865 SetLayerPropertiesForTesting(clip_parent.get(),
8866 identity_transform,
8867 identity_transform,
8868 gfx::PointF(),
8869 gfx::PointF(),
8870 gfx::Size(10, 10),
8871 false);
8872 SetLayerPropertiesForTesting(render_surface1.get(),
8873 identity_transform,
8874 identity_transform,
8875 gfx::PointF(),
8876 gfx::PointF(5, 5),
8877 gfx::Size(5, 5),
8878 false);
8879 SetLayerPropertiesForTesting(render_surface2.get(),
8880 identity_transform,
8881 identity_transform,
8882 gfx::PointF(),
8883 gfx::PointF(),
8884 gfx::Size(5, 5),
8885 false);
8886 SetLayerPropertiesForTesting(clip_child.get(),
8887 identity_transform,
8888 identity_transform,
8889 gfx::PointF(),
8890 gfx::PointF(-1, 1),
8891 gfx::Size(10, 10),
8892 false);
8893 SetLayerPropertiesForTesting(non_clip_child.get(),
8894 identity_transform,
8895 identity_transform,
8896 gfx::PointF(),
8897 gfx::PointF(),
8898 gfx::Size(5, 5),
8899 false);
8900
8901 render_surface1->SetForceRenderSurface(true);
8902 render_surface2->SetForceRenderSurface(true);
8903
8904 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8905 host->SetRootLayer(root);
8906
8907 ExecuteCalculateDrawProperties(root.get());
8908
8909 EXPECT_TRUE(root->render_surface());
8910 EXPECT_TRUE(render_surface1->render_surface());
8911 EXPECT_TRUE(render_surface2->render_surface());
8912
8913 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8914 render_surface1->clip_rect().ToString());
8915 EXPECT_TRUE(render_surface1->is_clipped());
8916
8917 // The render surface should not clip (it has unclipped descendants), instead
8918 // it should rely on layer clipping.
8919 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8920 render_surface1->render_surface()->clip_rect().ToString());
8921 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8922
8923 // That said, it should have grown to accomodate the unclipped descendant.
8924 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
8925 render_surface1->render_surface()->content_rect().ToString());
8926
8927 // This render surface should clip. It has no unclipped descendants.
8928 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8929 render_surface2->clip_rect().ToString());
8930 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
8931
8932 // It also shouldn't have grown to accomodate the clip child.
8933 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8934 render_surface2->render_surface()->content_rect().ToString());
8935
8936 // Sanity check our num_unclipped_descendants values.
8937 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
8938 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
8939}
8940
[email protected]45948712013-09-27 02:46:488941TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
8942 FakeImplProxy proxy;
8943 FakeLayerTreeHostImpl host_impl(&proxy);
8944 scoped_ptr<LayerImpl> root =
8945 LayerImpl::Create(host_impl.active_tree(), 12345);
8946 scoped_ptr<LayerImpl> child1 =
8947 LayerImpl::Create(host_impl.active_tree(), 123456);
8948 scoped_ptr<LayerImpl> child2 =
8949 LayerImpl::Create(host_impl.active_tree(), 1234567);
8950 scoped_ptr<LayerImpl> child3 =
8951 LayerImpl::Create(host_impl.active_tree(), 12345678);
8952
8953 gfx::Transform identity_matrix;
8954 gfx::PointF anchor;
8955 gfx::PointF position;
8956 gfx::Size bounds(100, 100);
8957 SetLayerPropertiesForTesting(root.get(),
8958 identity_matrix,
8959 identity_matrix,
8960 anchor,
8961 position,
8962 bounds,
8963 false);
8964 root->SetDrawsContent(true);
8965
8966 // This layer structure normally forces render surface due to preserves3d
8967 // behavior.
8968 bool preserves3d = true;
8969 SetLayerPropertiesForTesting(child1.get(),
8970 identity_matrix,
8971 identity_matrix,
8972 anchor,
8973 position,
8974 bounds,
8975 preserves3d);
8976 child1->SetDrawsContent(true);
8977 SetLayerPropertiesForTesting(child2.get(),
8978 identity_matrix,
8979 identity_matrix,
8980 anchor,
8981 position,
8982 bounds,
8983 false);
8984 child2->SetDrawsContent(true);
8985 SetLayerPropertiesForTesting(child3.get(),
8986 identity_matrix,
8987 identity_matrix,
8988 anchor,
8989 position,
8990 bounds,
8991 false);
8992 child3->SetDrawsContent(true);
8993
8994 child2->AddChild(child3.Pass());
8995 child1->AddChild(child2.Pass());
8996 root->AddChild(child1.Pass());
8997
8998 {
8999 LayerImplList render_surface_layer_list;
9000 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9001 root.get(), root->bounds(), &render_surface_layer_list);
9002 inputs.can_render_to_separate_surface = true;
9003 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9004
9005 EXPECT_EQ(2u, render_surface_layer_list.size());
9006 }
9007
9008 {
9009 LayerImplList render_surface_layer_list;
9010 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9011 root.get(), root->bounds(), &render_surface_layer_list);
9012 inputs.can_render_to_separate_surface = false;
9013 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9014
9015 EXPECT_EQ(1u, render_surface_layer_list.size());
9016 }
9017}
9018
[email protected]a9aa60a82013-08-29 04:28:269019TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
9020 scoped_refptr<Layer> root = Layer::Create();
9021 scoped_refptr<Layer> render_surface = Layer::Create();
9022 scoped_refptr<LayerWithForcedDrawsContent> child =
9023 make_scoped_refptr(new LayerWithForcedDrawsContent);
9024
9025 root->AddChild(render_surface);
9026 render_surface->AddChild(child);
9027
9028 gfx::Transform identity_transform;
9029 SetLayerPropertiesForTesting(root.get(),
9030 identity_transform,
9031 identity_transform,
9032 gfx::PointF(),
9033 gfx::PointF(),
9034 gfx::Size(50, 50),
9035 false);
9036 SetLayerPropertiesForTesting(render_surface.get(),
9037 identity_transform,
9038 identity_transform,
9039 gfx::PointF(),
9040 gfx::PointF(),
9041 gfx::Size(30, 30),
9042 false);
9043 SetLayerPropertiesForTesting(child.get(),
9044 identity_transform,
9045 identity_transform,
9046 gfx::PointF(),
9047 gfx::PointF(),
9048 gfx::Size(20, 20),
9049 false);
9050
9051 root->SetPreserves3d(true);
9052 render_surface->SetDoubleSided(false);
9053 render_surface->SetForceRenderSurface(true);
9054
9055 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9056 host->SetRootLayer(root);
9057
9058 ExecuteCalculateDrawProperties(root.get());
9059
9060 EXPECT_EQ(2u, render_surface_layer_list()->size());
9061 EXPECT_EQ(1u,
9062 render_surface_layer_list()->at(0)
9063 ->render_surface()->layer_list().size());
9064 EXPECT_EQ(1u,
9065 render_surface_layer_list()->at(1)
9066 ->render_surface()->layer_list().size());
9067
9068 gfx::Transform rotation_transform = identity_transform;
9069 rotation_transform.RotateAboutXAxis(180.0);
9070
9071 render_surface->SetTransform(rotation_transform);
9072
9073 ExecuteCalculateDrawProperties(root.get());
9074
9075 EXPECT_EQ(1u, render_surface_layer_list()->size());
9076 EXPECT_EQ(0u,
9077 render_surface_layer_list()->at(0)
9078 ->render_surface()->layer_list().size());
9079}
9080
[email protected]995708c52013-10-17 20:52:599081TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
9082 // Checks that the simple case (being clipped by a scroll parent that would
9083 // have been processed before you anyhow) results in the right clips.
9084 //
9085 // + root
9086 // + scroll_parent_border
9087 // | + scroll_parent_clip
9088 // | + scroll_parent
9089 // + scroll_child
9090 //
9091 scoped_refptr<Layer> root = Layer::Create();
9092 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9093 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9094 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9095 make_scoped_refptr(new LayerWithForcedDrawsContent);
9096 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9097 make_scoped_refptr(new LayerWithForcedDrawsContent);
9098
9099 root->AddChild(scroll_child);
9100
9101 root->AddChild(scroll_parent_border);
9102 scroll_parent_border->AddChild(scroll_parent_clip);
9103 scroll_parent_clip->AddChild(scroll_parent);
9104
9105 scroll_parent_clip->SetMasksToBounds(true);
9106
9107 scroll_child->SetScrollParent(scroll_parent.get());
9108
9109 gfx::Transform identity_transform;
9110 SetLayerPropertiesForTesting(root.get(),
9111 identity_transform,
9112 identity_transform,
9113 gfx::PointF(),
9114 gfx::PointF(),
9115 gfx::Size(50, 50),
9116 false);
9117 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9118 identity_transform,
9119 identity_transform,
9120 gfx::PointF(),
9121 gfx::PointF(),
9122 gfx::Size(40, 40),
9123 false);
9124 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9125 identity_transform,
9126 identity_transform,
9127 gfx::PointF(),
9128 gfx::PointF(),
9129 gfx::Size(30, 30),
9130 false);
9131 SetLayerPropertiesForTesting(scroll_parent.get(),
9132 identity_transform,
9133 identity_transform,
9134 gfx::PointF(),
9135 gfx::PointF(),
9136 gfx::Size(50, 50),
9137 false);
9138 SetLayerPropertiesForTesting(scroll_child.get(),
9139 identity_transform,
9140 identity_transform,
9141 gfx::PointF(),
9142 gfx::PointF(),
9143 gfx::Size(50, 50),
9144 false);
9145
9146 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9147 host->SetRootLayer(root);
9148
9149 ExecuteCalculateDrawProperties(root.get());
9150
9151 EXPECT_TRUE(root->render_surface());
9152
9153 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
9154 scroll_child->clip_rect().ToString());
9155 EXPECT_TRUE(scroll_child->is_clipped());
9156}
9157
9158TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
9159 // Checks that clipping by a scroll parent that follows you in paint order
9160 // still results in correct clipping.
9161 //
9162 // + root
9163 // + scroll_child
9164 // + scroll_parent_border
9165 // + scroll_parent_clip
9166 // + scroll_parent
9167 //
9168 scoped_refptr<Layer> root = Layer::Create();
9169 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9170 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9171 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9172 make_scoped_refptr(new LayerWithForcedDrawsContent);
9173 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9174 make_scoped_refptr(new LayerWithForcedDrawsContent);
9175
9176 root->AddChild(scroll_parent_border);
9177 scroll_parent_border->AddChild(scroll_parent_clip);
9178 scroll_parent_clip->AddChild(scroll_parent);
9179
9180 root->AddChild(scroll_child);
9181
9182 scroll_parent_clip->SetMasksToBounds(true);
9183
9184 scroll_child->SetScrollParent(scroll_parent.get());
9185
9186 gfx::Transform identity_transform;
9187 SetLayerPropertiesForTesting(root.get(),
9188 identity_transform,
9189 identity_transform,
9190 gfx::PointF(),
9191 gfx::PointF(),
9192 gfx::Size(50, 50),
9193 false);
9194 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9195 identity_transform,
9196 identity_transform,
9197 gfx::PointF(),
9198 gfx::PointF(),
9199 gfx::Size(40, 40),
9200 false);
9201 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9202 identity_transform,
9203 identity_transform,
9204 gfx::PointF(),
9205 gfx::PointF(),
9206 gfx::Size(30, 30),
9207 false);
9208 SetLayerPropertiesForTesting(scroll_parent.get(),
9209 identity_transform,
9210 identity_transform,
9211 gfx::PointF(),
9212 gfx::PointF(),
9213 gfx::Size(50, 50),
9214 false);
9215 SetLayerPropertiesForTesting(scroll_child.get(),
9216 identity_transform,
9217 identity_transform,
9218 gfx::PointF(),
9219 gfx::PointF(),
9220 gfx::Size(50, 50),
9221 false);
9222
9223 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9224 host->SetRootLayer(root);
9225
9226 ExecuteCalculateDrawProperties(root.get());
9227
9228 EXPECT_TRUE(root->render_surface());
9229
9230 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
9231 scroll_child->clip_rect().ToString());
9232 EXPECT_TRUE(scroll_child->is_clipped());
9233}
9234
9235TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
9236 // Checks that clipping by a scroll parent and scroll grandparent that follow
9237 // you in paint order still results in correct clipping.
9238 //
9239 // + root
9240 // + scroll_child
9241 // + scroll_parent_border
9242 // | + scroll_parent_clip
9243 // | + scroll_parent
9244 // + scroll_grandparent_border
9245 // + scroll_grandparent_clip
9246 // + scroll_grandparent
9247 //
9248 scoped_refptr<Layer> root = Layer::Create();
9249 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9250 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9251 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9252 make_scoped_refptr(new LayerWithForcedDrawsContent);
9253
9254 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
9255 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
9256 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
9257 make_scoped_refptr(new LayerWithForcedDrawsContent);
9258
9259 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9260 make_scoped_refptr(new LayerWithForcedDrawsContent);
9261
9262 root->AddChild(scroll_child);
9263
9264 root->AddChild(scroll_parent_border);
9265 scroll_parent_border->AddChild(scroll_parent_clip);
9266 scroll_parent_clip->AddChild(scroll_parent);
9267
9268 root->AddChild(scroll_grandparent_border);
9269 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
9270 scroll_grandparent_clip->AddChild(scroll_grandparent);
9271
9272 scroll_parent_clip->SetMasksToBounds(true);
9273 scroll_grandparent_clip->SetMasksToBounds(true);
9274
9275 scroll_child->SetScrollParent(scroll_parent.get());
9276 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
9277
9278 gfx::Transform identity_transform;
9279 SetLayerPropertiesForTesting(root.get(),
9280 identity_transform,
9281 identity_transform,
9282 gfx::PointF(),
9283 gfx::PointF(),
9284 gfx::Size(50, 50),
9285 false);
9286 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
9287 identity_transform,
9288 identity_transform,
9289 gfx::PointF(),
9290 gfx::PointF(),
9291 gfx::Size(40, 40),
9292 false);
9293 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
9294 identity_transform,
9295 identity_transform,
9296 gfx::PointF(),
9297 gfx::PointF(),
9298 gfx::Size(20, 20),
9299 false);
9300 SetLayerPropertiesForTesting(scroll_grandparent.get(),
9301 identity_transform,
9302 identity_transform,
9303 gfx::PointF(),
9304 gfx::PointF(),
9305 gfx::Size(50, 50),
9306 false);
9307 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9308 identity_transform,
9309 identity_transform,
9310 gfx::PointF(),
9311 gfx::PointF(),
9312 gfx::Size(40, 40),
9313 false);
9314 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9315 identity_transform,
9316 identity_transform,
9317 gfx::PointF(),
9318 gfx::PointF(),
9319 gfx::Size(30, 30),
9320 false);
9321 SetLayerPropertiesForTesting(scroll_parent.get(),
9322 identity_transform,
9323 identity_transform,
9324 gfx::PointF(),
9325 gfx::PointF(),
9326 gfx::Size(50, 50),
9327 false);
9328 SetLayerPropertiesForTesting(scroll_child.get(),
9329 identity_transform,
9330 identity_transform,
9331 gfx::PointF(),
9332 gfx::PointF(),
9333 gfx::Size(50, 50),
9334 false);
9335
9336 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9337 host->SetRootLayer(root);
9338
9339 ExecuteCalculateDrawProperties(root.get());
9340
9341 EXPECT_TRUE(root->render_surface());
9342
9343 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
9344 scroll_child->clip_rect().ToString());
9345 EXPECT_TRUE(scroll_child->is_clipped());
9346
9347 // Despite the fact that we visited the above layers out of order to get the
9348 // correct clip, the layer lists should be unaffected.
9349 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
9350 EXPECT_EQ(scroll_child.get(),
9351 root->render_surface()->layer_list().at(0));
9352 EXPECT_EQ(scroll_parent.get(),
9353 root->render_surface()->layer_list().at(1));
9354 EXPECT_EQ(scroll_grandparent.get(),
9355 root->render_surface()->layer_list().at(2));
9356}
9357
9358TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
9359 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:229360 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:599361 // + root
9362 // + scroll_child
9363 // + scroll_parent_border
9364 // + scroll_parent_clip
9365 // + scroll_parent
9366 // + render_surface1
9367 // + scroll_grandparent_border
9368 // + scroll_grandparent_clip
9369 // + scroll_grandparent
9370 // + render_surface2
9371 //
[email protected]44d8e84c2013-10-19 19:13:229372 scoped_refptr<LayerWithForcedDrawsContent> root =
9373 make_scoped_refptr(new LayerWithForcedDrawsContent);
[email protected]995708c52013-10-17 20:52:599374
9375 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
9376 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
9377 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
9378 make_scoped_refptr(new LayerWithForcedDrawsContent);
9379 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
9380 make_scoped_refptr(new LayerWithForcedDrawsContent);
9381
9382 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
9383 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
9384 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
9385 make_scoped_refptr(new LayerWithForcedDrawsContent);
9386 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
9387 make_scoped_refptr(new LayerWithForcedDrawsContent);
9388
9389 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
9390 make_scoped_refptr(new LayerWithForcedDrawsContent);
9391
9392 root->AddChild(scroll_child);
9393
9394 root->AddChild(scroll_parent_border);
9395 scroll_parent_border->AddChild(scroll_parent_clip);
9396 scroll_parent_clip->AddChild(scroll_parent);
9397 scroll_parent->AddChild(render_surface2);
9398
9399 root->AddChild(scroll_grandparent_border);
9400 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
9401 scroll_grandparent_clip->AddChild(scroll_grandparent);
9402 scroll_grandparent->AddChild(render_surface1);
9403
9404 scroll_parent_clip->SetMasksToBounds(true);
9405 scroll_grandparent_clip->SetMasksToBounds(true);
9406
9407 scroll_child->SetScrollParent(scroll_parent.get());
9408 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
9409
9410 render_surface1->SetForceRenderSurface(true);
9411 render_surface2->SetForceRenderSurface(true);
9412
9413 gfx::Transform identity_transform;
9414 SetLayerPropertiesForTesting(root.get(),
9415 identity_transform,
9416 identity_transform,
9417 gfx::PointF(),
9418 gfx::PointF(),
9419 gfx::Size(50, 50),
9420 false);
9421 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
9422 identity_transform,
9423 identity_transform,
9424 gfx::PointF(),
9425 gfx::PointF(),
9426 gfx::Size(40, 40),
9427 false);
9428 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
9429 identity_transform,
9430 identity_transform,
9431 gfx::PointF(),
9432 gfx::PointF(),
9433 gfx::Size(20, 20),
9434 false);
9435 SetLayerPropertiesForTesting(scroll_grandparent.get(),
9436 identity_transform,
9437 identity_transform,
9438 gfx::PointF(),
9439 gfx::PointF(),
9440 gfx::Size(50, 50),
9441 false);
9442 SetLayerPropertiesForTesting(render_surface1.get(),
9443 identity_transform,
9444 identity_transform,
9445 gfx::PointF(),
9446 gfx::PointF(),
9447 gfx::Size(50, 50),
9448 false);
9449 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9450 identity_transform,
9451 identity_transform,
9452 gfx::PointF(),
9453 gfx::PointF(),
9454 gfx::Size(40, 40),
9455 false);
9456 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9457 identity_transform,
9458 identity_transform,
9459 gfx::PointF(),
9460 gfx::PointF(),
9461 gfx::Size(30, 30),
9462 false);
9463 SetLayerPropertiesForTesting(scroll_parent.get(),
9464 identity_transform,
9465 identity_transform,
9466 gfx::PointF(),
9467 gfx::PointF(),
9468 gfx::Size(50, 50),
9469 false);
9470 SetLayerPropertiesForTesting(render_surface2.get(),
9471 identity_transform,
9472 identity_transform,
9473 gfx::PointF(),
9474 gfx::PointF(),
9475 gfx::Size(50, 50),
9476 false);
9477 SetLayerPropertiesForTesting(scroll_child.get(),
9478 identity_transform,
9479 identity_transform,
9480 gfx::PointF(),
9481 gfx::PointF(),
9482 gfx::Size(50, 50),
9483 false);
9484
9485 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9486 host->SetRootLayer(root);
9487
9488 RenderSurfaceLayerList render_surface_layer_list;
9489 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
9490 root.get(),
9491 root->bounds(),
9492 identity_transform,
9493 &render_surface_layer_list);
9494
9495 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9496
9497 EXPECT_TRUE(root->render_surface());
9498
9499 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
9500 scroll_child->clip_rect().ToString());
9501 EXPECT_TRUE(scroll_child->is_clipped());
9502
9503 // Despite the fact that we had to process the layers out of order to get the
9504 // right clip, our render_surface_layer_list's order should be unaffected.
9505 EXPECT_EQ(3u, render_surface_layer_list.size());
9506 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
9507 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
9508 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
[email protected]44d8e84c2013-10-19 19:13:229509 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
9510 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
9511 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:599512}
9513
9514TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) {
9515 // We rearrange layer list contributions if we have to visit children out of
9516 // order, but it should be a 'stable' rearrangement. That is, the layer list
9517 // additions for a single layer should not be reordered, though their position
9518 // wrt to the contributions due to a sibling may vary.
9519 //
9520 // + root
9521 // + scroll_child
9522 // + top_content
9523 // + bottom_content
9524 // + scroll_parent_border
9525 // + scroll_parent_clip
9526 // + scroll_parent
9527 //
9528 FakeImplProxy proxy;
9529 FakeLayerTreeHostImpl host_impl(&proxy);
9530 host_impl.CreatePendingTree();
9531 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9532 scoped_ptr<LayerImpl> scroll_parent_border =
9533 LayerImpl::Create(host_impl.active_tree(), 2);
9534 scoped_ptr<LayerImpl> scroll_parent_clip =
9535 LayerImpl::Create(host_impl.active_tree(), 3);
9536 scoped_ptr<LayerImpl> scroll_parent =
9537 LayerImpl::Create(host_impl.active_tree(), 4);
9538 scoped_ptr<LayerImpl> scroll_child =
9539 LayerImpl::Create(host_impl.active_tree(), 5);
9540 scoped_ptr<LayerImpl> bottom_content =
9541 LayerImpl::Create(host_impl.active_tree(), 6);
9542 scoped_ptr<LayerImpl> top_content =
9543 LayerImpl::Create(host_impl.active_tree(), 7);
9544
9545 scroll_parent_clip->SetMasksToBounds(true);
9546
9547 scroll_child->SetScrollParent(scroll_parent.get());
9548 scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>);
9549 scroll_children->insert(scroll_child.get());
9550 scroll_parent->SetScrollChildren(scroll_children.release());
9551
9552 scroll_child->SetDrawsContent(true);
9553 scroll_parent->SetDrawsContent(true);
9554 top_content->SetDrawsContent(true);
9555 bottom_content->SetDrawsContent(true);
9556
9557 gfx::Transform identity_transform;
9558 gfx::Transform top_transform;
9559 top_transform.Translate3d(0.0, 0.0, 5.0);
9560 gfx::Transform bottom_transform;
9561 bottom_transform.Translate3d(0.0, 0.0, 3.0);
9562
9563 SetLayerPropertiesForTesting(root.get(),
9564 identity_transform,
9565 identity_transform,
9566 gfx::PointF(),
9567 gfx::PointF(),
9568 gfx::Size(50, 50),
9569 false);
9570 SetLayerPropertiesForTesting(scroll_parent_border.get(),
9571 identity_transform,
9572 identity_transform,
9573 gfx::PointF(),
9574 gfx::PointF(),
9575 gfx::Size(40, 40),
9576 false);
9577 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
9578 identity_transform,
9579 identity_transform,
9580 gfx::PointF(),
9581 gfx::PointF(),
9582 gfx::Size(30, 30),
9583 false);
9584 SetLayerPropertiesForTesting(scroll_parent.get(),
9585 identity_transform,
9586 identity_transform,
9587 gfx::PointF(),
9588 gfx::PointF(),
9589 gfx::Size(50, 50),
9590 false);
9591 SetLayerPropertiesForTesting(scroll_child.get(),
9592 identity_transform,
9593 identity_transform,
9594 gfx::PointF(),
9595 gfx::PointF(),
9596 gfx::Size(50, 50),
9597 false);
9598 SetLayerPropertiesForTesting(top_content.get(),
9599 top_transform,
9600 top_transform,
9601 gfx::PointF(),
9602 gfx::PointF(),
9603 gfx::Size(50, 50),
9604 false);
9605 SetLayerPropertiesForTesting(bottom_content.get(),
9606 bottom_transform,
9607 bottom_transform,
9608 gfx::PointF(),
9609 gfx::PointF(),
9610 gfx::Size(50, 50),
9611 false);
9612
9613 scroll_child->SetPreserves3d(true);
9614
9615 scroll_child->AddChild(top_content.Pass());
9616 scroll_child->AddChild(bottom_content.Pass());
9617 root->AddChild(scroll_child.Pass());
9618
9619 scroll_parent_clip->AddChild(scroll_parent.Pass());
9620 scroll_parent_border->AddChild(scroll_parent_clip.Pass());
9621 root->AddChild(scroll_parent_border.Pass());
9622
9623 LayerImplList render_surface_layer_list;
9624 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9625 root.get(), root->bounds(), &render_surface_layer_list);
9626
9627 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9628
9629 EXPECT_TRUE(root->render_surface());
9630
9631 // If we don't sort by depth and let the layers get added in the order they
9632 // would normally be visited in, then layers 6 and 7 will be out of order. In
9633 // other words, although we've had to shift 5, 6, and 7 to appear before 4
9634 // in the list (because of the scroll parent relationship), this should not
9635 // have an effect on the the order of 5, 6, and 7 (which had been reordered
9636 // due to layer sorting).
9637 EXPECT_EQ(4u, root->render_surface()->layer_list().size());
9638 EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id());
9639 EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id());
9640 EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id());
9641 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
9642}
9643
[email protected]d81752b2013-10-25 08:32:239644TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
9645 // This test verifies that a scrolling layer that gets snapped to
9646 // integer coordinates doesn't move a fixed position child.
9647 //
9648 // + root
9649 // + container
9650 // + scroller
9651 // + fixed
9652 //
9653 FakeImplProxy proxy;
9654 FakeLayerTreeHostImpl host_impl(&proxy);
9655 host_impl.CreatePendingTree();
9656 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9657 scoped_ptr<LayerImpl> container =
9658 LayerImpl::Create(host_impl.active_tree(), 2);
9659 LayerImpl* container_layer = container.get();
9660 scoped_ptr<LayerImpl> scroller =
9661 LayerImpl::Create(host_impl.active_tree(), 3);
9662 LayerImpl* scroll_layer = scroller.get();
9663 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
9664 LayerImpl* fixed_layer = fixed.get();
9665
9666 container->SetIsContainerForFixedPositionLayers(true);
9667
9668 LayerPositionConstraint constraint;
9669 constraint.set_is_fixed_position(true);
9670 fixed->SetPositionConstraint(constraint);
9671
[email protected]adeda572014-01-31 00:49:479672 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:239673
9674 gfx::Transform identity_transform;
9675 gfx::Transform container_transform;
9676 container_transform.Translate3d(10.0, 20.0, 0.0);
9677 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
9678
9679 SetLayerPropertiesForTesting(root.get(),
9680 identity_transform,
9681 identity_transform,
9682 gfx::PointF(),
9683 gfx::PointF(),
9684 gfx::Size(50, 50),
9685 false);
9686 SetLayerPropertiesForTesting(container.get(),
9687 container_transform,
9688 identity_transform,
9689 gfx::PointF(),
9690 gfx::PointF(),
9691 gfx::Size(40, 40),
9692 false);
9693 SetLayerPropertiesForTesting(scroller.get(),
9694 identity_transform,
9695 identity_transform,
9696 gfx::PointF(),
9697 gfx::PointF(),
9698 gfx::Size(30, 30),
9699 false);
9700 SetLayerPropertiesForTesting(fixed.get(),
9701 identity_transform,
9702 identity_transform,
9703 gfx::PointF(),
9704 gfx::PointF(),
9705 gfx::Size(50, 50),
9706 false);
9707
9708 scroller->AddChild(fixed.Pass());
9709 container->AddChild(scroller.Pass());
9710 root->AddChild(container.Pass());
9711
9712 // Rounded to integers already.
9713 {
9714 gfx::Vector2dF scroll_delta(3.0, 5.0);
9715 scroll_layer->SetScrollDelta(scroll_delta);
9716
9717 LayerImplList render_surface_layer_list;
9718 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9719 root.get(), root->bounds(), &render_surface_layer_list);
9720 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9721
9722 EXPECT_TRANSFORMATION_MATRIX_EQ(
9723 container_layer->draw_properties().screen_space_transform,
9724 fixed_layer->draw_properties().screen_space_transform);
9725 EXPECT_VECTOR_EQ(
9726 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9727 container_offset);
9728 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
9729 .screen_space_transform.To2dTranslation(),
9730 container_offset - scroll_delta);
9731 }
9732
9733 // Scroll delta requiring rounding.
9734 {
9735 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
9736 scroll_layer->SetScrollDelta(scroll_delta);
9737
9738 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
9739
9740 LayerImplList render_surface_layer_list;
9741 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
9742 root.get(), root->bounds(), &render_surface_layer_list);
9743 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
9744
9745 EXPECT_TRANSFORMATION_MATRIX_EQ(
9746 container_layer->draw_properties().screen_space_transform,
9747 fixed_layer->draw_properties().screen_space_transform);
9748 EXPECT_VECTOR_EQ(
9749 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
9750 container_offset);
9751 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
9752 .screen_space_transform.To2dTranslation(),
9753 container_offset - rounded_scroll_delta);
9754 }
9755}
9756
[email protected]ba565742012-11-10 09:29:489757} // namespace
9758} // namespace cc