blob: 04ffc328ae58dae861d28058a4bc8740c66c2aa1 [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]95e4e1a02013-03-18 07:09:097#include "cc/animation/layer_animation_controller.h"
[email protected]681ccff2013-03-18 06:13:528#include "cc/base/math_util.h"
[email protected]cc3cfaa2013-03-18 09:05:529#include "cc/layers/content_layer.h"
10#include "cc/layers/content_layer_client.h"
11#include "cc/layers/heads_up_display_layer_impl.h"
12#include "cc/layers/layer.h"
13#include "cc/layers/layer_impl.h"
[email protected]50761e92013-03-29 20:51:2814#include "cc/layers/render_surface.h"
15#include "cc/layers/render_surface_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4516#include "cc/output/copy_output_request.h"
17#include "cc/output/copy_output_result.h"
[email protected]101441ce2012-10-16 01:45:0318#include "cc/test/animation_test_common.h"
[email protected]586d51ed2012-12-07 20:31:4519#include "cc/test/fake_impl_proxy.h"
[email protected]d600df7d2013-08-03 02:34:2820#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4521#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]101441ce2012-10-16 01:45:0322#include "cc/test/geometry_test_utils.h"
[email protected]556fd292013-03-18 08:03:0423#include "cc/trees/layer_tree_impl.h"
24#include "cc/trees/proxy.h"
25#include "cc/trees/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:1826#include "testing/gmock/include/gmock/gmock.h"
27#include "testing/gtest/include/gtest/gtest.h"
[email protected]93698c12012-12-07 00:43:5628#include "ui/gfx/quad_f.h"
29#include "ui/gfx/size_conversions.h"
[email protected]c8686a02012-11-27 08:29:0030#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1431
[email protected]ba565742012-11-10 09:29:4832namespace cc {
[email protected]94f206c12012-08-25 00:09:1433namespace {
34
[email protected]989386c2013-07-18 21:37:2335class LayerTreeHostCommonTestBase {
36 protected:
37 template <typename LayerType>
38 void SetLayerPropertiesForTestingInternal(
39 LayerType* layer,
40 const gfx::Transform& transform,
41 const gfx::Transform& sublayer_transform,
42 gfx::PointF anchor,
43 gfx::PointF position,
44 gfx::Size bounds,
45 bool preserves3d) {
46 layer->SetTransform(transform);
47 layer->SetSublayerTransform(sublayer_transform);
48 layer->SetAnchorPoint(anchor);
49 layer->SetPosition(position);
50 layer->SetBounds(bounds);
51 layer->SetPreserves3d(preserves3d);
52 }
[email protected]94f206c12012-08-25 00:09:1453
[email protected]989386c2013-07-18 21:37:2354 void SetLayerPropertiesForTesting(Layer* layer,
55 const gfx::Transform& transform,
56 const gfx::Transform& sublayer_transform,
57 gfx::PointF anchor,
58 gfx::PointF position,
59 gfx::Size bounds,
60 bool preserves3d) {
61 SetLayerPropertiesForTestingInternal<Layer>(layer,
62 transform,
63 sublayer_transform,
64 anchor,
65 position,
66 bounds,
67 preserves3d);
68 }
[email protected]94f206c12012-08-25 00:09:1469
[email protected]989386c2013-07-18 21:37:2370 void SetLayerPropertiesForTesting(LayerImpl* layer,
71 const gfx::Transform& transform,
72 const gfx::Transform& sublayer_transform,
73 gfx::PointF anchor,
74 gfx::PointF position,
75 gfx::Size bounds,
76 bool preserves3d) {
77 SetLayerPropertiesForTestingInternal<LayerImpl>(layer,
78 transform,
79 sublayer_transform,
80 anchor,
81 position,
82 bounds,
83 preserves3d);
84 layer->SetContentBounds(bounds);
85 }
[email protected]94f206c12012-08-25 00:09:1486
[email protected]989386c2013-07-18 21:37:2387 void ExecuteCalculateDrawProperties(Layer* root_layer,
88 float device_scale_factor,
89 float page_scale_factor,
90 Layer* page_scale_application_layer,
91 bool can_use_lcd_text) {
92 EXPECT_TRUE(page_scale_application_layer || (page_scale_factor == 1.f));
93 gfx::Transform identity_matrix;
[email protected]989386c2013-07-18 21:37:2394 gfx::Size device_viewport_size =
95 gfx::Size(root_layer->bounds().width() * device_scale_factor,
96 root_layer->bounds().height() * device_scale_factor);
[email protected]94f206c12012-08-25 00:09:1497
[email protected]989386c2013-07-18 21:37:2398 render_surface_layer_list_.reset(new RenderSurfaceLayerList);
[email protected]94f206c12012-08-25 00:09:1499
[email protected]989386c2013-07-18 21:37:23100 // We are probably not testing what is intended if the root_layer bounds are
101 // empty.
102 DCHECK(!root_layer->bounds().IsEmpty());
[email protected]7aad55f2013-07-26 11:25:53103 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
104 root_layer, device_viewport_size, render_surface_layer_list_.get());
105 inputs.device_scale_factor = device_scale_factor;
106 inputs.page_scale_factor = page_scale_factor;
107 inputs.page_scale_application_layer = page_scale_application_layer;
108 inputs.can_use_lcd_text = can_use_lcd_text;
109 inputs.can_adjust_raster_scales = true;
110 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:23111 }
[email protected]94f206c12012-08-25 00:09:14112
[email protected]989386c2013-07-18 21:37:23113 void ExecuteCalculateDrawProperties(LayerImpl* root_layer,
114 float device_scale_factor,
115 float page_scale_factor,
116 LayerImpl* page_scale_application_layer,
117 bool can_use_lcd_text) {
118 gfx::Transform identity_matrix;
119 LayerImplList dummy_render_surface_layer_list;
[email protected]989386c2013-07-18 21:37:23120 gfx::Size device_viewport_size =
121 gfx::Size(root_layer->bounds().width() * device_scale_factor,
122 root_layer->bounds().height() * device_scale_factor);
[email protected]94f206c12012-08-25 00:09:14123
[email protected]989386c2013-07-18 21:37:23124 // We are probably not testing what is intended if the root_layer bounds are
125 // empty.
126 DCHECK(!root_layer->bounds().IsEmpty());
[email protected]7aad55f2013-07-26 11:25:53127 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
128 root_layer, device_viewport_size, &dummy_render_surface_layer_list);
129 inputs.device_scale_factor = device_scale_factor;
130 inputs.page_scale_factor = page_scale_factor;
131 inputs.page_scale_application_layer = page_scale_application_layer;
132 inputs.can_use_lcd_text = can_use_lcd_text;
133 inputs.can_adjust_raster_scales = true;
134 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:23135 }
[email protected]94f206c12012-08-25 00:09:14136
[email protected]989386c2013-07-18 21:37:23137 template <class LayerType>
138 void ExecuteCalculateDrawProperties(LayerType* root_layer) {
139 LayerType* page_scale_application_layer = NULL;
140 ExecuteCalculateDrawProperties(
141 root_layer, 1.f, 1.f, page_scale_application_layer, false);
142 }
[email protected]94f206c12012-08-25 00:09:14143
[email protected]989386c2013-07-18 21:37:23144 template <class LayerType>
145 void ExecuteCalculateDrawProperties(LayerType* root_layer,
146 float device_scale_factor) {
147 LayerType* page_scale_application_layer = NULL;
148 ExecuteCalculateDrawProperties(root_layer,
149 device_scale_factor,
150 1.f,
151 page_scale_application_layer,
152 false);
153 }
154
155 template <class LayerType>
156 void ExecuteCalculateDrawProperties(LayerType* root_layer,
157 float device_scale_factor,
158 float page_scale_factor,
159 LayerType* page_scale_application_layer) {
160 ExecuteCalculateDrawProperties(root_layer,
161 device_scale_factor,
162 page_scale_factor,
163 page_scale_application_layer,
164 false);
165 }
166
[email protected]a9aa60a82013-08-29 04:28:26167 RenderSurfaceLayerList* render_surface_layer_list() const {
168 return render_surface_layer_list_.get();
169 }
170
[email protected]989386c2013-07-18 21:37:23171 private:
172 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
173};
174
175class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
176 public testing::Test {
177};
[email protected]94f206c12012-08-25 00:09:14178
[email protected]96baf3e2012-10-22 23:09:55179class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:32180 public:
181 LayerWithForcedDrawsContent() : Layer() {}
[email protected]94f206c12012-08-25 00:09:14182
[email protected]fb661802013-03-25 01:59:32183 virtual bool DrawsContent() const OVERRIDE;
[email protected]d58499a2012-10-09 22:27:47184
[email protected]fb661802013-03-25 01:59:32185 private:
186 virtual ~LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:14187};
188
[email protected]aedf4e52013-01-09 23:24:44189class LayerCanClipSelf : public Layer {
[email protected]fb661802013-03-25 01:59:32190 public:
191 LayerCanClipSelf() : Layer() {}
[email protected]aedf4e52013-01-09 23:24:44192
[email protected]fb661802013-03-25 01:59:32193 virtual bool DrawsContent() const OVERRIDE;
194 virtual bool CanClipSelf() const OVERRIDE;
[email protected]aedf4e52013-01-09 23:24:44195
[email protected]fb661802013-03-25 01:59:32196 private:
197 virtual ~LayerCanClipSelf() {}
[email protected]aedf4e52013-01-09 23:24:44198};
199
[email protected]fb661802013-03-25 01:59:32200bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:44201
[email protected]fb661802013-03-25 01:59:32202bool LayerCanClipSelf::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:44203
[email protected]fb661802013-03-25 01:59:32204bool LayerCanClipSelf::CanClipSelf() const { return true; }
[email protected]aedf4e52013-01-09 23:24:44205
[email protected]96baf3e2012-10-22 23:09:55206class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:32207 public:
208 MockContentLayerClient() {}
209 virtual ~MockContentLayerClient() {}
210 virtual void PaintContents(SkCanvas* canvas,
211 gfx::Rect clip,
212 gfx::RectF* opaque) OVERRIDE {}
213 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
[email protected]f34a24232012-09-20 22:59:55214};
215
[email protected]fb661802013-03-25 01:59:32216scoped_refptr<ContentLayer> CreateDrawableContentLayer(
217 ContentLayerClient* delegate) {
218 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate);
219 to_return->SetIsDrawable(true);
220 return to_return;
[email protected]f34a24232012-09-20 22:59:55221}
222
[email protected]989386c2013-07-18 21:37:23223#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
224 do { \
225 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
226 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:47227 } while (false)
228
[email protected]989386c2013-07-18 21:37:23229TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32230 // Sanity check: For layers positioned at zero, with zero size,
231 // and with identity transforms, then the draw transform,
232 // screen space transform, and the hierarchy passed on to children
233 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14234
[email protected]fb661802013-03-25 01:59:32235 scoped_refptr<Layer> parent = Layer::Create();
236 scoped_refptr<Layer> child = Layer::Create();
237 scoped_refptr<Layer> grand_child = Layer::Create();
238 parent->AddChild(child);
239 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14240
[email protected]d600df7d2013-08-03 02:34:28241 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
242 host->SetRootLayer(parent);
243
[email protected]fb661802013-03-25 01:59:32244 gfx::Transform identity_matrix;
245 SetLayerPropertiesForTesting(parent.get(),
246 identity_matrix,
247 identity_matrix,
248 gfx::PointF(),
249 gfx::PointF(),
250 gfx::Size(100, 100),
251 false);
252 SetLayerPropertiesForTesting(child.get(),
253 identity_matrix,
254 identity_matrix,
255 gfx::PointF(),
256 gfx::PointF(),
257 gfx::Size(),
258 false);
259 SetLayerPropertiesForTesting(grand_child.get(),
260 identity_matrix,
261 identity_matrix,
262 gfx::PointF(),
263 gfx::PointF(),
264 gfx::Size(),
265 false);
[email protected]94f206c12012-08-25 00:09:14266
[email protected]fb661802013-03-25 01:59:32267 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14268
[email protected]fb661802013-03-25 01:59:32269 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
270 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
271 child->screen_space_transform());
272 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
273 grand_child->draw_transform());
274 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
275 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14276}
277
[email protected]989386c2013-07-18 21:37:23278TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32279 gfx::Transform identity_matrix;
280 scoped_refptr<Layer> layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:14281
[email protected]fb661802013-03-25 01:59:32282 scoped_refptr<Layer> root = Layer::Create();
283 SetLayerPropertiesForTesting(root.get(),
284 identity_matrix,
285 identity_matrix,
286 gfx::PointF(),
287 gfx::PointF(),
288 gfx::Size(1, 2),
289 false);
290 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42291
[email protected]d600df7d2013-08-03 02:34:28292 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
293 host->SetRootLayer(root);
294
[email protected]fb661802013-03-25 01:59:32295 // Case 1: setting the sublayer transform should not affect this layer's draw
296 // transform or screen-space transform.
297 gfx::Transform arbitrary_translation;
298 arbitrary_translation.Translate(10.0, 20.0);
299 SetLayerPropertiesForTesting(layer.get(),
300 identity_matrix,
301 arbitrary_translation,
302 gfx::PointF(),
303 gfx::PointF(),
304 gfx::Size(100, 100),
305 false);
306 ExecuteCalculateDrawProperties(root.get());
307 gfx::Transform expected_draw_transform = identity_matrix;
308 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
309 layer->draw_transform());
310 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
311 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14312
[email protected]fb661802013-03-25 01:59:32313 // Case 2: Setting the bounds of the layer should not affect either the draw
314 // transform or the screenspace transform.
315 gfx::Transform translation_to_center;
316 translation_to_center.Translate(5.0, 6.0);
317 SetLayerPropertiesForTesting(layer.get(),
318 identity_matrix,
319 identity_matrix,
320 gfx::PointF(),
321 gfx::PointF(),
322 gfx::Size(10, 12),
323 false);
324 ExecuteCalculateDrawProperties(root.get());
325 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
326 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
327 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14328
[email protected]fb661802013-03-25 01:59:32329 // Case 3: The anchor point by itself (without a layer transform) should have
330 // no effect on the transforms.
331 SetLayerPropertiesForTesting(layer.get(),
332 identity_matrix,
333 identity_matrix,
334 gfx::PointF(0.25f, 0.25f),
335 gfx::PointF(),
336 gfx::Size(10, 12),
337 false);
338 ExecuteCalculateDrawProperties(root.get());
339 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
340 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
341 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14342
[email protected]fb661802013-03-25 01:59:32343 // Case 4: A change in actual position affects both the draw transform and
344 // screen space transform.
345 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05346 position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32347 SetLayerPropertiesForTesting(layer.get(),
348 identity_matrix,
349 identity_matrix,
350 gfx::PointF(0.25f, 0.25f),
351 gfx::PointF(0.f, 1.2f),
352 gfx::Size(10, 12),
353 false);
354 ExecuteCalculateDrawProperties(root.get());
355 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
356 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
357 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14358
[email protected]fb661802013-03-25 01:59:32359 // Case 5: In the correct sequence of transforms, the layer transform should
360 // pre-multiply the translation_to_center. This is easily tested by using a
361 // scale transform, because scale and translation are not commutative.
362 gfx::Transform layer_transform;
363 layer_transform.Scale3d(2.0, 2.0, 1.0);
364 SetLayerPropertiesForTesting(layer.get(),
365 layer_transform,
366 identity_matrix,
367 gfx::PointF(),
368 gfx::PointF(),
369 gfx::Size(10, 12),
370 false);
371 ExecuteCalculateDrawProperties(root.get());
372 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
373 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
374 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14375
[email protected]fb661802013-03-25 01:59:32376 // Case 6: The layer transform should occur with respect to the anchor point.
377 gfx::Transform translation_to_anchor;
378 translation_to_anchor.Translate(5.0, 0.0);
379 gfx::Transform expected_result =
380 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
381 SetLayerPropertiesForTesting(layer.get(),
382 layer_transform,
383 identity_matrix,
384 gfx::PointF(0.5f, 0.f),
385 gfx::PointF(),
386 gfx::Size(10, 12),
387 false);
388 ExecuteCalculateDrawProperties(root.get());
389 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
390 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
391 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14392
[email protected]fb661802013-03-25 01:59:32393 // Case 7: Verify that position pre-multiplies the layer transform. The
394 // current implementation of CalculateDrawProperties does this implicitly, but
395 // it is still worth testing to detect accidental regressions.
396 expected_result = position_transform * translation_to_anchor *
397 layer_transform * Inverse(translation_to_anchor);
398 SetLayerPropertiesForTesting(layer.get(),
399 layer_transform,
400 identity_matrix,
401 gfx::PointF(0.5f, 0.f),
402 gfx::PointF(0.f, 1.2f),
403 gfx::Size(10, 12),
404 false);
405 ExecuteCalculateDrawProperties(root.get());
406 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
407 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
408 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14409}
410
[email protected]989386c2013-07-18 21:37:23411TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
[email protected]fb661802013-03-25 01:59:32412 const gfx::Vector2d kScrollOffset(50, 100);
413 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01414 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32415 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
416 -kScrollOffset.y());
417 const float kPageScale = 0.888f;
418 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20419
[email protected]fb661802013-03-25 01:59:32420 FakeImplProxy proxy;
421 FakeLayerTreeHostImpl host_impl(&proxy);
[email protected]657b24c2013-03-06 09:01:20422
[email protected]fb661802013-03-25 01:59:32423 gfx::Transform identity_matrix;
424 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
425 LayerImpl::Create(host_impl.active_tree(), 1));
426 LayerImpl* sublayer = sublayer_scoped_ptr.get();
427 sublayer->SetContentsScale(kPageScale * kDeviceScale,
428 kPageScale * kDeviceScale);
429 SetLayerPropertiesForTesting(sublayer,
430 identity_matrix,
431 identity_matrix,
432 gfx::Point(),
433 gfx::PointF(),
434 gfx::Size(500, 500),
435 false);
[email protected]657b24c2013-03-06 09:01:20436
[email protected]fb661802013-03-25 01:59:32437 scoped_ptr<LayerImpl> scroll_layerScopedPtr(
438 LayerImpl::Create(host_impl.active_tree(), 2));
439 LayerImpl* scroll_layer = scroll_layerScopedPtr.get();
440 SetLayerPropertiesForTesting(scroll_layer,
441 identity_matrix,
442 identity_matrix,
443 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47444 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32445 gfx::Size(10, 20),
446 false);
447 scroll_layer->SetScrollable(true);
[email protected]d30700f12013-07-31 08:21:01448 scroll_layer->SetMaxScrollOffset(kMaxScrollOffset);
[email protected]fb661802013-03-25 01:59:32449 scroll_layer->SetScrollOffset(kScrollOffset);
450 scroll_layer->SetScrollDelta(kScrollDelta);
451 gfx::Transform impl_transform;
[email protected]fb661802013-03-25 01:59:32452 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
[email protected]657b24c2013-03-06 09:01:20453
[email protected]fb661802013-03-25 01:59:32454 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
455 SetLayerPropertiesForTesting(root.get(),
456 identity_matrix,
457 identity_matrix,
458 gfx::PointF(),
459 gfx::PointF(),
460 gfx::Size(3, 4),
461 false);
462 root->AddChild(scroll_layerScopedPtr.Pass());
[email protected]657b24c2013-03-06 09:01:20463
[email protected]f2136262013-04-26 21:10:19464 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32465 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32466 gfx::Transform expected_transform = identity_matrix;
467 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
468 sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
469 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
470 MathUtil::Round(sub_layer_screen_position.y()));
471 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
472 sublayer->draw_transform());
473 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
474 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20475
[email protected]fb661802013-03-25 01:59:32476 gfx::Transform arbitrary_translate;
477 const float kTranslateX = 10.6f;
478 const float kTranslateY = 20.6f;
479 arbitrary_translate.Translate(kTranslateX, kTranslateY);
480 SetLayerPropertiesForTesting(scroll_layer,
481 arbitrary_translate,
482 identity_matrix,
483 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47484 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32485 gfx::Size(10, 20),
486 false);
[email protected]f2136262013-04-26 21:10:19487 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32488 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32489 expected_transform.MakeIdentity();
490 expected_transform.Translate(
491 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
492 sub_layer_screen_position.x()),
493 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
494 sub_layer_screen_position.y()));
495 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
496 sublayer->draw_transform());
[email protected]657b24c2013-03-06 09:01:20497}
498
[email protected]989386c2013-07-18 21:37:23499TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32500 gfx::Transform identity_matrix;
501 scoped_refptr<Layer> root = Layer::Create();
502 scoped_refptr<Layer> parent = Layer::Create();
503 scoped_refptr<Layer> child = Layer::Create();
504 scoped_refptr<Layer> grand_child = Layer::Create();
505 root->AddChild(parent);
506 parent->AddChild(child);
507 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14508
[email protected]d600df7d2013-08-03 02:34:28509 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
510 host->SetRootLayer(root);
511
[email protected]fb661802013-03-25 01:59:32512 // One-time setup of root layer
513 SetLayerPropertiesForTesting(root.get(),
514 identity_matrix,
515 identity_matrix,
516 gfx::PointF(),
517 gfx::PointF(),
518 gfx::Size(1, 2),
519 false);
[email protected]ecc12622012-10-30 20:45:42520
[email protected]fb661802013-03-25 01:59:32521 // Case 1: parent's anchor point should not affect child or grand_child.
522 SetLayerPropertiesForTesting(parent.get(),
523 identity_matrix,
524 identity_matrix,
525 gfx::PointF(0.25f, 0.25f),
526 gfx::PointF(),
527 gfx::Size(10, 12),
528 false);
529 SetLayerPropertiesForTesting(child.get(),
530 identity_matrix,
531 identity_matrix,
532 gfx::PointF(),
533 gfx::PointF(),
534 gfx::Size(16, 18),
535 false);
536 SetLayerPropertiesForTesting(grand_child.get(),
537 identity_matrix,
538 identity_matrix,
539 gfx::PointF(),
540 gfx::PointF(),
541 gfx::Size(76, 78),
542 false);
543 ExecuteCalculateDrawProperties(root.get());
544 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
545 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
546 child->screen_space_transform());
547 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
548 grand_child->draw_transform());
549 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
550 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14551
[email protected]fb661802013-03-25 01:59:32552 // Case 2: parent's position affects child and grand_child.
553 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05554 parent_position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32555 SetLayerPropertiesForTesting(parent.get(),
556 identity_matrix,
557 identity_matrix,
558 gfx::PointF(0.25f, 0.25f),
559 gfx::PointF(0.f, 1.2f),
560 gfx::Size(10, 12),
561 false);
562 SetLayerPropertiesForTesting(child.get(),
563 identity_matrix,
564 identity_matrix,
565 gfx::PointF(),
566 gfx::PointF(),
567 gfx::Size(16, 18),
568 false);
569 SetLayerPropertiesForTesting(grand_child.get(),
570 identity_matrix,
571 identity_matrix,
572 gfx::PointF(),
573 gfx::PointF(),
574 gfx::Size(76, 78),
575 false);
576 ExecuteCalculateDrawProperties(root.get());
577 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
578 child->draw_transform());
579 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
580 child->screen_space_transform());
581 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
582 grand_child->draw_transform());
583 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
584 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14585
[email protected]fb661802013-03-25 01:59:32586 // Case 3: parent's local transform affects child and grandchild
587 gfx::Transform parent_layer_transform;
588 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
589 gfx::Transform parent_translation_to_anchor;
590 parent_translation_to_anchor.Translate(2.5, 3.0);
591 gfx::Transform parent_composite_transform =
592 parent_translation_to_anchor * parent_layer_transform *
593 Inverse(parent_translation_to_anchor);
594 SetLayerPropertiesForTesting(parent.get(),
595 parent_layer_transform,
596 identity_matrix,
597 gfx::PointF(0.25f, 0.25f),
598 gfx::PointF(),
599 gfx::Size(10, 12),
600 false);
601 SetLayerPropertiesForTesting(child.get(),
602 identity_matrix,
603 identity_matrix,
604 gfx::PointF(),
605 gfx::PointF(),
606 gfx::Size(16, 18),
607 false);
608 SetLayerPropertiesForTesting(grand_child.get(),
609 identity_matrix,
610 identity_matrix,
611 gfx::PointF(),
612 gfx::PointF(),
613 gfx::Size(76, 78),
614 false);
615 ExecuteCalculateDrawProperties(root.get());
616 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
617 child->draw_transform());
618 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
619 child->screen_space_transform());
620 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
621 grand_child->draw_transform());
622 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
623 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14624
[email protected]fb661802013-03-25 01:59:32625 // Case 4: parent's sublayer matrix affects child and grandchild scaling is
626 // used here again so that the correct sequence of transforms is properly
627 // tested. Note that preserves3d is false, but the sublayer matrix should
628 // retain its 3D properties when given to child. But then, the child also
629 // does not preserve3D. When it gives its hierarchy to the grand_child, it
630 // should be flattened to 2D.
631 gfx::Transform parent_sublayer_matrix;
[email protected]6138db702013-09-25 03:25:05632 parent_sublayer_matrix.Scale3d(10.f, 10.f, 3.3f);
[email protected]fb661802013-03-25 01:59:32633 // Sublayer matrix is applied to the anchor point of the parent layer.
634 parent_composite_transform =
635 parent_translation_to_anchor * parent_layer_transform *
636 Inverse(parent_translation_to_anchor) * parent_translation_to_anchor *
637 parent_sublayer_matrix * Inverse(parent_translation_to_anchor);
638 gfx::Transform flattened_composite_transform = parent_composite_transform;
639 flattened_composite_transform.FlattenTo2d();
640 SetLayerPropertiesForTesting(parent.get(),
641 parent_layer_transform,
642 parent_sublayer_matrix,
643 gfx::PointF(0.25f, 0.25f),
644 gfx::PointF(),
645 gfx::Size(10, 12),
646 false);
647 SetLayerPropertiesForTesting(child.get(),
648 identity_matrix,
649 identity_matrix,
650 gfx::PointF(),
651 gfx::PointF(),
652 gfx::Size(16, 18),
653 false);
654 SetLayerPropertiesForTesting(grand_child.get(),
655 identity_matrix,
656 identity_matrix,
657 gfx::PointF(),
658 gfx::PointF(),
659 gfx::Size(76, 78),
660 false);
661 ExecuteCalculateDrawProperties(root.get());
662 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
663 child->draw_transform());
664 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
665 child->screen_space_transform());
666 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_composite_transform,
667 grand_child->draw_transform());
668 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_composite_transform,
669 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14670
[email protected]fb661802013-03-25 01:59:32671 // Case 5: same as Case 4, except that child does preserve 3D, so the
672 // grand_child should receive the non-flattened composite transform.
673 SetLayerPropertiesForTesting(parent.get(),
674 parent_layer_transform,
675 parent_sublayer_matrix,
676 gfx::PointF(0.25f, 0.25f),
677 gfx::PointF(),
678 gfx::Size(10, 12),
679 false);
680 SetLayerPropertiesForTesting(child.get(),
681 identity_matrix,
682 identity_matrix,
683 gfx::PointF(),
684 gfx::PointF(),
685 gfx::Size(16, 18),
686 true);
687 SetLayerPropertiesForTesting(grand_child.get(),
688 identity_matrix,
689 identity_matrix,
690 gfx::PointF(),
691 gfx::PointF(),
692 gfx::Size(76, 78),
693 false);
694 ExecuteCalculateDrawProperties(root.get());
695 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
696 child->draw_transform());
697 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
698 child->screen_space_transform());
699 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
700 grand_child->draw_transform());
701 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
702 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14703}
704
[email protected]989386c2013-07-18 21:37:23705TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
[email protected]fb661802013-03-25 01:59:32706 scoped_refptr<Layer> root = Layer::Create();
707 scoped_refptr<Layer> parent = Layer::Create();
708 scoped_refptr<Layer> child = Layer::Create();
709 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
710 make_scoped_refptr(new LayerWithForcedDrawsContent());
711 root->AddChild(parent);
712 parent->AddChild(child);
713 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14714
[email protected]d600df7d2013-08-03 02:34:28715 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
716 host->SetRootLayer(root);
717
[email protected]fb661802013-03-25 01:59:32718 // One-time setup of root layer
719 gfx::Transform identity_matrix;
720 SetLayerPropertiesForTesting(root.get(),
721 identity_matrix,
722 identity_matrix,
723 gfx::PointF(),
724 gfx::PointF(),
725 gfx::Size(1, 2),
726 false);
[email protected]ecc12622012-10-30 20:45:42727
[email protected]fb661802013-03-25 01:59:32728 // Child is set up so that a new render surface should be created.
729 child->SetOpacity(0.5f);
730 child->SetForceRenderSurface(true);
[email protected]94f206c12012-08-25 00:09:14731
[email protected]fb661802013-03-25 01:59:32732 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05733 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32734 gfx::Transform parent_translation_to_anchor;
735 parent_translation_to_anchor.Translate(25.0, 30.0);
736 gfx::Transform parent_sublayer_matrix;
[email protected]6138db702013-09-25 03:25:05737 parent_sublayer_matrix.Scale3d(0.9f, 1.f, 3.3f);
[email protected]aedf4e52013-01-09 23:24:44738
[email protected]fb661802013-03-25 01:59:32739 gfx::Transform parent_composite_transform =
740 parent_translation_to_anchor * parent_layer_transform *
741 Inverse(parent_translation_to_anchor) * parent_translation_to_anchor *
742 parent_sublayer_matrix * Inverse(parent_translation_to_anchor);
743 gfx::Vector2dF parent_composite_scale =
744 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
745 1.f);
746 gfx::Transform surface_sublayer_transform;
747 surface_sublayer_transform.Scale(parent_composite_scale.x(),
748 parent_composite_scale.y());
749 gfx::Transform surface_sublayer_composite_transform =
750 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14751
[email protected]fb661802013-03-25 01:59:32752 // Child's render surface should not exist yet.
753 ASSERT_FALSE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:14754
[email protected]fb661802013-03-25 01:59:32755 SetLayerPropertiesForTesting(parent.get(),
756 parent_layer_transform,
757 parent_sublayer_matrix,
758 gfx::PointF(0.25f, 0.25f),
759 gfx::PointF(),
760 gfx::Size(100, 120),
761 false);
762 SetLayerPropertiesForTesting(child.get(),
763 identity_matrix,
764 identity_matrix,
765 gfx::PointF(),
766 gfx::PointF(),
767 gfx::Size(16, 18),
768 false);
769 SetLayerPropertiesForTesting(grand_child.get(),
770 identity_matrix,
771 identity_matrix,
772 gfx::PointF(),
773 gfx::PointF(),
774 gfx::Size(8, 10),
775 false);
776 ExecuteCalculateDrawProperties(root.get());
[email protected]94f206c12012-08-25 00:09:14777
[email protected]fb661802013-03-25 01:59:32778 // Render surface should have been created now.
779 ASSERT_TRUE(child->render_surface());
780 ASSERT_EQ(child, child->render_target());
[email protected]94f206c12012-08-25 00:09:14781
[email protected]fb661802013-03-25 01:59:32782 // The child layer's draw transform should refer to its new render surface.
783 // The screen-space transform, however, should still refer to the root.
784 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
785 child->draw_transform());
786 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
787 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14788
[email protected]fb661802013-03-25 01:59:32789 // Because the grand_child is the only drawable content, the child's render
790 // surface will tighten its bounds to the grand_child. The scale at which the
791 // surface's subtree is drawn must be removed from the composite transform.
792 EXPECT_TRANSFORMATION_MATRIX_EQ(
793 surface_sublayer_composite_transform,
794 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14795
[email protected]fb661802013-03-25 01:59:32796 // The screen space is the same as the target since the child surface draws
797 // into the root.
798 EXPECT_TRANSFORMATION_MATRIX_EQ(
799 surface_sublayer_composite_transform,
800 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14801}
802
[email protected]989386c2013-07-18 21:37:23803TEST_F(LayerTreeHostCommonTest, SublayerTransformWithAnchorPoint) {
[email protected]fb661802013-03-25 01:59:32804 // crbug.com/157961 - we were always applying the sublayer transform about
805 // the center of the layer, rather than the anchor point.
[email protected]9a3e6b72013-02-12 18:31:21806
[email protected]fb661802013-03-25 01:59:32807 scoped_refptr<Layer> root = Layer::Create();
808 scoped_refptr<Layer> parent = Layer::Create();
809 scoped_refptr<LayerWithForcedDrawsContent> child =
810 make_scoped_refptr(new LayerWithForcedDrawsContent());
811 root->AddChild(parent);
812 parent->AddChild(child);
[email protected]9a3e6b72013-02-12 18:31:21813
[email protected]d600df7d2013-08-03 02:34:28814 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
815 host->SetRootLayer(root);
816
[email protected]fb661802013-03-25 01:59:32817 gfx::Transform identity_matrix;
818 gfx::Transform parent_sublayer_matrix;
819 parent_sublayer_matrix.ApplyPerspectiveDepth(2.0);
820 gfx::PointF parent_anchor_point(0.2f, 0.8f);
[email protected]9a3e6b72013-02-12 18:31:21821
[email protected]fb661802013-03-25 01:59:32822 SetLayerPropertiesForTesting(root.get(),
823 identity_matrix,
824 identity_matrix,
825 gfx::PointF(),
826 gfx::PointF(),
827 gfx::Size(1, 2),
828 false);
829 SetLayerPropertiesForTesting(parent.get(),
830 identity_matrix,
831 parent_sublayer_matrix,
832 parent_anchor_point,
833 gfx::PointF(),
834 gfx::Size(100, 100),
835 false);
836 SetLayerPropertiesForTesting(child.get(),
837 identity_matrix,
838 identity_matrix,
839 gfx::PointF(),
840 gfx::PointF(),
841 gfx::Size(10, 10),
842 false);
843 ExecuteCalculateDrawProperties(root.get());
[email protected]9a3e6b72013-02-12 18:31:21844
[email protected]fb661802013-03-25 01:59:32845 gfx::Transform expected_child_draw_transform;
846 expected_child_draw_transform.Translate(20.0, 80.0);
847 expected_child_draw_transform.ApplyPerspectiveDepth(2.0);
848 expected_child_draw_transform.Translate(-20.0, -80.0);
849 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
850 child->draw_transform());
[email protected]9a3e6b72013-02-12 18:31:21851}
852
[email protected]989386c2013-07-18 21:37:23853TEST_F(LayerTreeHostCommonTest, SeparateRenderTargetRequirementWithClipping) {
[email protected]fb661802013-03-25 01:59:32854 scoped_refptr<Layer> root = Layer::Create();
855 scoped_refptr<Layer> parent = Layer::Create();
856 scoped_refptr<Layer> child = Layer::Create();
857 scoped_refptr<Layer> grand_child = make_scoped_refptr(new LayerCanClipSelf());
858 root->AddChild(parent);
859 parent->AddChild(child);
860 child->AddChild(grand_child);
861 parent->SetMasksToBounds(true);
862 child->SetMasksToBounds(true);
[email protected]9a3e6b72013-02-12 18:31:21863
[email protected]d600df7d2013-08-03 02:34:28864 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
865 host->SetRootLayer(root);
866
[email protected]fb661802013-03-25 01:59:32867 gfx::Transform identity_matrix;
868 gfx::Transform parent_layer_transform;
869 gfx::Transform parent_sublayer_matrix;
870 gfx::Transform child_layer_matrix;
871
872 // No render surface should exist yet.
873 EXPECT_FALSE(root->render_surface());
874 EXPECT_FALSE(parent->render_surface());
875 EXPECT_FALSE(child->render_surface());
876 EXPECT_FALSE(grand_child->render_surface());
877
878 // One-time setup of root layer
[email protected]6138db702013-09-25 03:25:05879 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
880 parent_sublayer_matrix.Scale3d(0.9f, 1.f, 3.3f);
[email protected]fb661802013-03-25 01:59:32881 child_layer_matrix.Rotate(20.0);
882
883 SetLayerPropertiesForTesting(root.get(),
884 identity_matrix,
885 identity_matrix,
886 gfx::PointF(),
887 gfx::PointF(),
888 gfx::Size(1, 2),
889 false);
890 SetLayerPropertiesForTesting(parent.get(),
891 parent_layer_transform,
892 parent_sublayer_matrix,
893 gfx::PointF(0.25f, 0.25f),
894 gfx::PointF(),
895 gfx::Size(100, 120),
896 false);
897 SetLayerPropertiesForTesting(child.get(),
898 child_layer_matrix,
899 identity_matrix,
900 gfx::PointF(),
901 gfx::PointF(),
902 gfx::Size(16, 18),
903 false);
904 SetLayerPropertiesForTesting(grand_child.get(),
905 identity_matrix,
906 identity_matrix,
907 gfx::PointF(),
908 gfx::PointF(),
909 gfx::Size(8, 10),
910 false);
911
912 ExecuteCalculateDrawProperties(root.get());
913
914 // Render surfaces should have been created according to clipping rules now
915 // (grandchild can clip self).
916 EXPECT_TRUE(root->render_surface());
917 EXPECT_FALSE(parent->render_surface());
918 EXPECT_FALSE(child->render_surface());
919 EXPECT_FALSE(grand_child->render_surface());
920}
921
[email protected]989386c2013-07-18 21:37:23922TEST_F(LayerTreeHostCommonTest,
923 SeparateRenderTargetRequirementWithoutClipping) {
[email protected]fb661802013-03-25 01:59:32924 scoped_refptr<Layer> root = Layer::Create();
925 scoped_refptr<Layer> parent = Layer::Create();
926 scoped_refptr<Layer> child = Layer::Create();
927 // This layer cannot clip itself, a feature we are testing here.
928 scoped_refptr<Layer> grand_child =
929 make_scoped_refptr(new LayerWithForcedDrawsContent());
930 root->AddChild(parent);
931 parent->AddChild(child);
932 child->AddChild(grand_child);
933 parent->SetMasksToBounds(true);
934 child->SetMasksToBounds(true);
935
[email protected]d600df7d2013-08-03 02:34:28936 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
937 host->SetRootLayer(root);
938
[email protected]fb661802013-03-25 01:59:32939 gfx::Transform identity_matrix;
940 gfx::Transform parent_layer_transform;
941 gfx::Transform parent_sublayer_matrix;
942 gfx::Transform child_layer_matrix;
943
944 // No render surface should exist yet.
945 EXPECT_FALSE(root->render_surface());
946 EXPECT_FALSE(parent->render_surface());
947 EXPECT_FALSE(child->render_surface());
948 EXPECT_FALSE(grand_child->render_surface());
949
950 // One-time setup of root layer
[email protected]6138db702013-09-25 03:25:05951 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
952 parent_sublayer_matrix.Scale3d(0.9f, 1.f, 3.3f);
[email protected]fb661802013-03-25 01:59:32953 child_layer_matrix.Rotate(20.0);
954
955 SetLayerPropertiesForTesting(root.get(),
956 identity_matrix,
957 identity_matrix,
958 gfx::PointF(),
959 gfx::PointF(),
960 gfx::Size(1, 2),
961 false);
962 SetLayerPropertiesForTesting(parent.get(),
963 parent_layer_transform,
964 parent_sublayer_matrix,
965 gfx::PointF(0.25f, 0.25f),
966 gfx::PointF(),
967 gfx::Size(100, 120),
968 false);
969 SetLayerPropertiesForTesting(child.get(),
970 child_layer_matrix,
971 identity_matrix,
972 gfx::PointF(),
973 gfx::PointF(),
974 gfx::Size(16, 18),
975 false);
976 SetLayerPropertiesForTesting(grand_child.get(),
977 identity_matrix,
978 identity_matrix,
979 gfx::PointF(),
980 gfx::PointF(),
981 gfx::Size(8, 10),
982 false);
983
984 ExecuteCalculateDrawProperties(root.get());
985
986 // Render surfaces should have been created according to clipping rules now
987 // (grandchild can't clip self).
988 EXPECT_TRUE(root->render_surface());
989 EXPECT_FALSE(parent->render_surface());
990 EXPECT_TRUE(child->render_surface());
991 EXPECT_FALSE(grand_child->render_surface());
992}
993
[email protected]989386c2013-07-18 21:37:23994TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
[email protected]fb661802013-03-25 01:59:32995 scoped_refptr<Layer> root = Layer::Create();
996 scoped_refptr<Layer> parent = Layer::Create();
997 scoped_refptr<Layer> child = Layer::Create();
998 scoped_refptr<Layer> child_replica = Layer::Create();
999 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1000 make_scoped_refptr(new LayerWithForcedDrawsContent());
1001 root->AddChild(parent);
1002 parent->AddChild(child);
1003 child->AddChild(grand_child);
1004 child->SetReplicaLayer(child_replica.get());
1005
[email protected]d600df7d2013-08-03 02:34:281006 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1007 host->SetRootLayer(root);
1008
[email protected]fb661802013-03-25 01:59:321009 // One-time setup of root layer
1010 gfx::Transform identity_matrix;
1011 SetLayerPropertiesForTesting(root.get(),
1012 identity_matrix,
1013 identity_matrix,
1014 gfx::PointF(),
1015 gfx::PointF(),
1016 gfx::Size(1, 2),
1017 false);
1018
1019 // Child is set up so that a new render surface should be created.
1020 child->SetOpacity(0.5f);
1021
1022 gfx::Transform parent_layer_transform;
1023 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
1024 gfx::Transform parent_translation_to_anchor;
1025 parent_translation_to_anchor.Translate(2.5, 3.0);
1026 gfx::Transform parent_sublayer_matrix;
[email protected]6138db702013-09-25 03:25:051027 parent_sublayer_matrix.Scale3d(10.f, 10.f, 3.3f);
[email protected]fb661802013-03-25 01:59:321028 gfx::Transform parent_composite_transform =
1029 parent_translation_to_anchor * parent_layer_transform *
1030 Inverse(parent_translation_to_anchor) * parent_translation_to_anchor *
1031 parent_sublayer_matrix * Inverse(parent_translation_to_anchor);
1032 gfx::Transform replica_layer_transform;
1033 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
1034 gfx::Vector2dF parent_composite_scale =
1035 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
1036 1.f);
1037 gfx::Transform surface_sublayer_transform;
1038 surface_sublayer_transform.Scale(parent_composite_scale.x(),
1039 parent_composite_scale.y());
1040 gfx::Transform replica_composite_transform =
1041 parent_composite_transform * replica_layer_transform *
1042 Inverse(surface_sublayer_transform);
1043
1044 // Child's render surface should not exist yet.
1045 ASSERT_FALSE(child->render_surface());
1046
1047 SetLayerPropertiesForTesting(parent.get(),
1048 parent_layer_transform,
1049 parent_sublayer_matrix,
1050 gfx::PointF(0.25f, 0.25f),
1051 gfx::PointF(),
1052 gfx::Size(10, 12),
1053 false);
1054 SetLayerPropertiesForTesting(child.get(),
1055 identity_matrix,
1056 identity_matrix,
1057 gfx::PointF(),
1058 gfx::PointF(),
1059 gfx::Size(16, 18),
1060 false);
1061 SetLayerPropertiesForTesting(grand_child.get(),
1062 identity_matrix,
1063 identity_matrix,
1064 gfx::PointF(),
1065 gfx::PointF(-0.5f, -0.5f),
1066 gfx::Size(1, 1),
1067 false);
1068 SetLayerPropertiesForTesting(child_replica.get(),
1069 replica_layer_transform,
1070 identity_matrix,
1071 gfx::PointF(),
1072 gfx::PointF(),
1073 gfx::Size(),
1074 false);
1075 ExecuteCalculateDrawProperties(root.get());
1076
1077 // Render surface should have been created now.
1078 ASSERT_TRUE(child->render_surface());
1079 ASSERT_EQ(child, child->render_target());
1080
1081 EXPECT_TRANSFORMATION_MATRIX_EQ(
1082 replica_composite_transform,
1083 child->render_target()->render_surface()->replica_draw_transform());
1084 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
1085 child->render_target()->render_surface()
1086 ->replica_screen_space_transform());
1087}
1088
[email protected]989386c2013-07-18 21:37:231089TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:321090 // This test creates a more complex tree and verifies it all at once. This
1091 // covers the following cases:
1092 // - layers that are described w.r.t. a render surface: should have draw
1093 // transforms described w.r.t. that surface
1094 // - A render surface described w.r.t. an ancestor render surface: should
1095 // have a draw transform described w.r.t. that ancestor surface
1096 // - Replicas of a render surface are described w.r.t. the replica's
1097 // transform around its anchor, along with the surface itself.
1098 // - Sanity check on recursion: verify transforms of layers described w.r.t.
1099 // a render surface that is described w.r.t. an ancestor render surface.
1100 // - verifying that each layer has a reference to the correct render surface
1101 // and render target values.
1102
1103 scoped_refptr<Layer> root = Layer::Create();
1104 scoped_refptr<Layer> parent = Layer::Create();
1105 scoped_refptr<Layer> render_surface1 = Layer::Create();
1106 scoped_refptr<Layer> render_surface2 = Layer::Create();
1107 scoped_refptr<Layer> child_of_root = Layer::Create();
1108 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
1109 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
1110 scoped_refptr<Layer> replica_of_rs1 = Layer::Create();
1111 scoped_refptr<Layer> replica_of_rs2 = Layer::Create();
1112 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
1113 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
1114 make_scoped_refptr(new LayerWithForcedDrawsContent());
1115 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
1116 make_scoped_refptr(new LayerWithForcedDrawsContent());
1117 root->AddChild(parent);
1118 parent->AddChild(render_surface1);
1119 parent->AddChild(child_of_root);
1120 render_surface1->AddChild(child_of_rs1);
1121 render_surface1->AddChild(render_surface2);
1122 render_surface2->AddChild(child_of_rs2);
1123 child_of_root->AddChild(grand_child_of_root);
1124 child_of_rs1->AddChild(grand_child_of_rs1);
1125 child_of_rs2->AddChild(grand_child_of_rs2);
1126 render_surface1->SetReplicaLayer(replica_of_rs1.get());
1127 render_surface2->SetReplicaLayer(replica_of_rs2.get());
1128
[email protected]d600df7d2013-08-03 02:34:281129 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1130 host->SetRootLayer(root);
1131
[email protected]fb661802013-03-25 01:59:321132 // In combination with descendant draws content, opacity != 1 forces the layer
1133 // to have a new render surface.
1134 render_surface1->SetOpacity(0.5f);
1135 render_surface2->SetOpacity(0.33f);
1136
1137 // One-time setup of root layer
1138 gfx::Transform identity_matrix;
1139 SetLayerPropertiesForTesting(root.get(),
1140 identity_matrix,
1141 identity_matrix,
1142 gfx::PointF(),
1143 gfx::PointF(),
1144 gfx::Size(1, 2),
1145 false);
1146
1147 // All layers in the tree are initialized with an anchor at .25 and a size of
1148 // (10,10). matrix "A" is the composite layer transform used in all layers,
1149 // centered about the anchor point. matrix "B" is the sublayer transform used
1150 // in all layers, centered about the center position of the layer. matrix "R"
1151 // is the composite replica transform used in all replica layers.
1152 //
1153 // x component tests that layer_transform and sublayer_transform are done in
1154 // the right order (translation and scale are noncommutative). y component
1155 // has a translation by 1 for every ancestor, which indicates the "depth" of
1156 // the layer in the hierarchy.
1157 gfx::Transform translation_to_anchor;
1158 translation_to_anchor.Translate(2.5, 0.0);
1159 gfx::Transform layer_transform;
1160 layer_transform.Translate(1.0, 1.0);
1161 gfx::Transform sublayer_transform;
1162 sublayer_transform.Scale3d(10.0, 1.0, 1.0);
1163 gfx::Transform replica_layer_transform;
1164 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
1165
1166 gfx::Transform A =
1167 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
1168 gfx::Transform B = translation_to_anchor * sublayer_transform *
1169 Inverse(translation_to_anchor);
1170 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
1171 Inverse(translation_to_anchor);
1172
1173 gfx::Vector2dF surface1_parent_transform_scale =
1174 MathUtil::ComputeTransform2dScaleComponents(A * B, 1.f);
1175 gfx::Transform surface1_sublayer_transform;
1176 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
1177 surface1_parent_transform_scale.y());
1178
1179 // SS1 = transform given to the subtree of render_surface1
1180 gfx::Transform SS1 = surface1_sublayer_transform;
1181 // S1 = transform to move from render_surface1 pixels to the layer space of
1182 // the owning layer
1183 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
1184
1185 gfx::Vector2dF surface2_parent_transform_scale =
1186 MathUtil::ComputeTransform2dScaleComponents(SS1 * A * B, 1.f);
1187 gfx::Transform surface2_sublayer_transform;
1188 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
1189 surface2_parent_transform_scale.y());
1190
1191 // SS2 = transform given to the subtree of render_surface2
1192 gfx::Transform SS2 = surface2_sublayer_transform;
1193 // S2 = transform to move from render_surface2 pixels to the layer space of
1194 // the owning layer
1195 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
1196
1197 SetLayerPropertiesForTesting(parent.get(),
1198 layer_transform,
1199 sublayer_transform,
1200 gfx::PointF(0.25f, 0.f),
1201 gfx::PointF(),
1202 gfx::Size(10, 10),
1203 false);
1204 SetLayerPropertiesForTesting(render_surface1.get(),
1205 layer_transform,
1206 sublayer_transform,
1207 gfx::PointF(0.25f, 0.f),
1208 gfx::PointF(),
1209 gfx::Size(10, 10),
1210 false);
1211 SetLayerPropertiesForTesting(render_surface2.get(),
1212 layer_transform,
1213 sublayer_transform,
1214 gfx::PointF(0.25f, 0.f),
1215 gfx::PointF(),
1216 gfx::Size(10, 10),
1217 false);
1218 SetLayerPropertiesForTesting(child_of_root.get(),
1219 layer_transform,
1220 sublayer_transform,
1221 gfx::PointF(0.25f, 0.f),
1222 gfx::PointF(),
1223 gfx::Size(10, 10),
1224 false);
1225 SetLayerPropertiesForTesting(child_of_rs1.get(),
1226 layer_transform,
1227 sublayer_transform,
1228 gfx::PointF(0.25f, 0.f),
1229 gfx::PointF(),
1230 gfx::Size(10, 10),
1231 false);
1232 SetLayerPropertiesForTesting(child_of_rs2.get(),
1233 layer_transform,
1234 sublayer_transform,
1235 gfx::PointF(0.25f, 0.f),
1236 gfx::PointF(),
1237 gfx::Size(10, 10),
1238 false);
1239 SetLayerPropertiesForTesting(grand_child_of_root.get(),
1240 layer_transform,
1241 sublayer_transform,
1242 gfx::PointF(0.25f, 0.f),
1243 gfx::PointF(),
1244 gfx::Size(10, 10),
1245 false);
1246 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
1247 layer_transform,
1248 sublayer_transform,
1249 gfx::PointF(0.25f, 0.f),
1250 gfx::PointF(),
1251 gfx::Size(10, 10),
1252 false);
1253 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
1254 layer_transform,
1255 sublayer_transform,
1256 gfx::PointF(0.25f, 0.f),
1257 gfx::PointF(),
1258 gfx::Size(10, 10),
1259 false);
1260 SetLayerPropertiesForTesting(replica_of_rs1.get(),
1261 replica_layer_transform,
1262 sublayer_transform,
1263 gfx::PointF(0.25f, 0.f),
1264 gfx::PointF(),
1265 gfx::Size(),
1266 false);
1267 SetLayerPropertiesForTesting(replica_of_rs2.get(),
1268 replica_layer_transform,
1269 sublayer_transform,
1270 gfx::PointF(0.25f, 0.f),
1271 gfx::PointF(),
1272 gfx::Size(),
1273 false);
1274
1275 ExecuteCalculateDrawProperties(root.get());
1276
1277 // Only layers that are associated with render surfaces should have an actual
1278 // RenderSurface() value.
1279 ASSERT_TRUE(root->render_surface());
1280 ASSERT_FALSE(child_of_root->render_surface());
1281 ASSERT_FALSE(grand_child_of_root->render_surface());
1282
1283 ASSERT_TRUE(render_surface1->render_surface());
1284 ASSERT_FALSE(child_of_rs1->render_surface());
1285 ASSERT_FALSE(grand_child_of_rs1->render_surface());
1286
1287 ASSERT_TRUE(render_surface2->render_surface());
1288 ASSERT_FALSE(child_of_rs2->render_surface());
1289 ASSERT_FALSE(grand_child_of_rs2->render_surface());
1290
1291 // Verify all render target accessors
1292 EXPECT_EQ(root, parent->render_target());
1293 EXPECT_EQ(root, child_of_root->render_target());
1294 EXPECT_EQ(root, grand_child_of_root->render_target());
1295
1296 EXPECT_EQ(render_surface1, render_surface1->render_target());
1297 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
1298 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
1299
1300 EXPECT_EQ(render_surface2, render_surface2->render_target());
1301 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
1302 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
1303
1304 // Verify layer draw transforms note that draw transforms are described with
1305 // respect to the nearest ancestor render surface but screen space transforms
1306 // are described with respect to the root.
1307 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
1308 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, child_of_root->draw_transform());
1309 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A,
1310 grand_child_of_root->draw_transform());
1311
1312 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
1313 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A, child_of_rs1->draw_transform());
1314 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A * B * A,
1315 grand_child_of_rs1->draw_transform());
1316
1317 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
1318 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * B * A, child_of_rs2->draw_transform());
1319 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * B * A * B * A,
1320 grand_child_of_rs2->draw_transform());
1321
1322 // Verify layer screen-space transforms
1323 //
1324 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
1325 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A,
1326 child_of_root->screen_space_transform());
1327 EXPECT_TRANSFORMATION_MATRIX_EQ(
1328 A * B * A * B * A, grand_child_of_root->screen_space_transform());
1329
1330 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A,
1331 render_surface1->screen_space_transform());
1332 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A,
1333 child_of_rs1->screen_space_transform());
1334 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A,
1335 grand_child_of_rs1->screen_space_transform());
1336
1337 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A,
1338 render_surface2->screen_space_transform());
1339 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A,
1340 child_of_rs2->screen_space_transform());
1341 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A * B * A,
1342 grand_child_of_rs2->screen_space_transform());
1343
1344 // Verify render surface transforms.
1345 //
1346 // Draw transform of render surface 1 is described with respect to root.
1347 EXPECT_TRANSFORMATION_MATRIX_EQ(
1348 A * B * A * S1, render_surface1->render_surface()->draw_transform());
1349 EXPECT_TRANSFORMATION_MATRIX_EQ(
1350 A * B * R * S1,
1351 render_surface1->render_surface()->replica_draw_transform());
1352 EXPECT_TRANSFORMATION_MATRIX_EQ(
1353 A * B * A * S1,
1354 render_surface1->render_surface()->screen_space_transform());
1355 EXPECT_TRANSFORMATION_MATRIX_EQ(
1356 A * B * R * S1,
1357 render_surface1->render_surface()->replica_screen_space_transform());
1358 // Draw transform of render surface 2 is described with respect to render
1359 // surface 1.
1360 EXPECT_TRANSFORMATION_MATRIX_EQ(
1361 SS1 * B * A * S2, render_surface2->render_surface()->draw_transform());
1362 EXPECT_TRANSFORMATION_MATRIX_EQ(
1363 SS1 * B * R * S2,
1364 render_surface2->render_surface()->replica_draw_transform());
1365 EXPECT_TRANSFORMATION_MATRIX_EQ(
1366 A * B * A * B * A * S2,
1367 render_surface2->render_surface()->screen_space_transform());
1368 EXPECT_TRANSFORMATION_MATRIX_EQ(
1369 A * B * A * B * R * S2,
1370 render_surface2->render_surface()->replica_screen_space_transform());
1371
1372 // Sanity check. If these fail there is probably a bug in the test itself. It
1373 // is expected that we correctly set up transforms so that the y-component of
1374 // the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:261375 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
1376 EXPECT_FLOAT_EQ(2.0,
1377 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321378 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261379 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321380
[email protected]803f6b52013-09-12 00:51:261381 EXPECT_FLOAT_EQ(2.0,
1382 render_surface1->screen_space_transform().matrix().get(1, 3));
1383 EXPECT_FLOAT_EQ(3.0,
1384 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321385 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261386 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321387
[email protected]803f6b52013-09-12 00:51:261388 EXPECT_FLOAT_EQ(3.0,
1389 render_surface2->screen_space_transform().matrix().get(1, 3));
1390 EXPECT_FLOAT_EQ(4.0,
1391 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321392 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261393 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321394}
1395
[email protected]989386c2013-07-18 21:37:231396TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321397 // For layers that flatten their subtree, there should be an orthographic
1398 // projection (for x and y values) in the middle of the transform sequence.
1399 // Note that the way the code is currently implemented, it is not expected to
1400 // use a canonical orthographic projection.
1401
1402 scoped_refptr<Layer> root = Layer::Create();
1403 scoped_refptr<Layer> child = Layer::Create();
1404 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1405 make_scoped_refptr(new LayerWithForcedDrawsContent());
1406
1407 gfx::Transform rotation_about_y_axis;
1408 rotation_about_y_axis.RotateAboutYAxis(30.0);
1409
1410 const gfx::Transform identity_matrix;
1411 SetLayerPropertiesForTesting(root.get(),
1412 identity_matrix,
1413 identity_matrix,
1414 gfx::PointF(),
1415 gfx::PointF(),
1416 gfx::Size(100, 100),
1417 false);
1418 SetLayerPropertiesForTesting(child.get(),
1419 rotation_about_y_axis,
1420 identity_matrix,
1421 gfx::PointF(),
1422 gfx::PointF(),
1423 gfx::Size(10, 10),
1424 false);
1425 SetLayerPropertiesForTesting(grand_child.get(),
1426 rotation_about_y_axis,
1427 identity_matrix,
1428 gfx::PointF(),
1429 gfx::PointF(),
1430 gfx::Size(10, 10),
1431 false);
1432
1433 root->AddChild(child);
1434 child->AddChild(grand_child);
1435 child->SetForceRenderSurface(true);
1436
[email protected]d600df7d2013-08-03 02:34:281437 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1438 host->SetRootLayer(root);
1439
[email protected]fb661802013-03-25 01:59:321440 // No layers in this test should preserve 3d.
1441 ASSERT_FALSE(root->preserves_3d());
1442 ASSERT_FALSE(child->preserves_3d());
1443 ASSERT_FALSE(grand_child->preserves_3d());
1444
1445 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1446 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1447 gfx::Transform expected_grand_child_draw_transform =
1448 rotation_about_y_axis; // draws onto child's render surface
1449 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1450 flattened_rotation_about_y.FlattenTo2d();
1451 gfx::Transform expected_grand_child_screen_space_transform =
1452 flattened_rotation_about_y * rotation_about_y_axis;
1453
1454 ExecuteCalculateDrawProperties(root.get());
1455
1456 // The child's draw transform should have been taken by its surface.
1457 ASSERT_TRUE(child->render_surface());
1458 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1459 child->render_surface()->draw_transform());
1460 EXPECT_TRANSFORMATION_MATRIX_EQ(
1461 expected_child_screen_space_transform,
1462 child->render_surface()->screen_space_transform());
1463 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1464 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1465 child->screen_space_transform());
1466 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1467 grand_child->draw_transform());
1468 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1469 grand_child->screen_space_transform());
1470}
1471
[email protected]989386c2013-07-18 21:37:231472TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321473 // A layer that is empty in one axis, but not the other, was accidentally
1474 // skipping a necessary translation. Without that translation, the coordinate
1475 // space of the layer's draw transform is incorrect.
1476 //
1477 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1478 // but if that layer becomes a render surface, then its draw transform is
1479 // implicitly inherited by the rest of the subtree, which then is positioned
1480 // incorrectly as a result.
1481
1482 scoped_refptr<Layer> root = Layer::Create();
1483 scoped_refptr<Layer> child = Layer::Create();
1484 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1485 make_scoped_refptr(new LayerWithForcedDrawsContent());
1486
1487 // The child height is zero, but has non-zero width that should be accounted
1488 // for while computing draw transforms.
1489 const gfx::Transform identity_matrix;
1490 SetLayerPropertiesForTesting(root.get(),
1491 identity_matrix,
1492 identity_matrix,
1493 gfx::PointF(),
1494 gfx::PointF(),
1495 gfx::Size(100, 100),
1496 false);
1497 SetLayerPropertiesForTesting(child.get(),
1498 identity_matrix,
1499 identity_matrix,
1500 gfx::PointF(),
1501 gfx::PointF(),
1502 gfx::Size(10, 0),
1503 false);
1504 SetLayerPropertiesForTesting(grand_child.get(),
1505 identity_matrix,
1506 identity_matrix,
1507 gfx::PointF(),
1508 gfx::PointF(),
1509 gfx::Size(10, 10),
1510 false);
1511
1512 root->AddChild(child);
1513 child->AddChild(grand_child);
1514 child->SetForceRenderSurface(true);
1515
[email protected]d600df7d2013-08-03 02:34:281516 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1517 host->SetRootLayer(root);
1518
[email protected]fb661802013-03-25 01:59:321519 ExecuteCalculateDrawProperties(root.get());
1520
1521 ASSERT_TRUE(child->render_surface());
1522 // This is the real test, the rest are sanity checks.
1523 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1524 child->render_surface()->draw_transform());
1525 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1526 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1527 grand_child->draw_transform());
1528}
1529
[email protected]989386c2013-07-18 21:37:231530TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321531 // Transformations applied at the root of the tree should be forwarded
1532 // to child layers instead of applied to the root RenderSurface.
1533 const gfx::Transform identity_matrix;
1534 scoped_refptr<Layer> root = Layer::Create();
1535 scoped_refptr<Layer> child = Layer::Create();
[email protected]9781afa2013-07-17 23:15:321536 child->SetScrollable(true);
[email protected]f224cc92013-06-06 23:23:321537 root->AddChild(child);
1538
[email protected]d600df7d2013-08-03 02:34:281539 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1540 host->SetRootLayer(root);
1541
[email protected]f224cc92013-06-06 23:23:321542 SetLayerPropertiesForTesting(root.get(),
1543 identity_matrix,
1544 identity_matrix,
1545 gfx::PointF(),
1546 gfx::PointF(),
1547 gfx::Size(20, 20),
1548 false);
1549 SetLayerPropertiesForTesting(child.get(),
1550 identity_matrix,
1551 identity_matrix,
1552 gfx::PointF(),
1553 gfx::PointF(),
1554 gfx::Size(20, 20),
1555 false);
1556
[email protected]f224cc92013-06-06 23:23:321557 gfx::Transform translate;
1558 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231559 {
1560 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531561 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1562 root.get(), root->bounds(), translate, &render_surface_layer_list);
1563 inputs.can_adjust_raster_scales = true;
1564 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231565 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1566 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1567 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1568 }
[email protected]f224cc92013-06-06 23:23:321569
1570 gfx::Transform scale;
1571 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231572 {
1573 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531574 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1575 root.get(), root->bounds(), scale, &render_surface_layer_list);
1576 inputs.can_adjust_raster_scales = true;
1577 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231578 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1579 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1580 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1581 }
[email protected]f224cc92013-06-06 23:23:321582
1583 gfx::Transform rotate;
1584 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231585 {
1586 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531587 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1588 root.get(), root->bounds(), rotate, &render_surface_layer_list);
1589 inputs.can_adjust_raster_scales = true;
1590 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231591 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1592 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1593 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1594 }
[email protected]f224cc92013-06-06 23:23:321595
1596 gfx::Transform composite;
1597 composite.ConcatTransform(translate);
1598 composite.ConcatTransform(scale);
1599 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231600 {
1601 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531602 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1603 root.get(), root->bounds(), composite, &render_surface_layer_list);
1604 inputs.can_adjust_raster_scales = true;
1605 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231606 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1607 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1608 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1609 }
[email protected]f224cc92013-06-06 23:23:321610
[email protected]9781afa2013-07-17 23:15:321611 // Verify it composes correctly with device scale.
1612 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231613
1614 {
1615 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531616 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1617 root.get(), root->bounds(), translate, &render_surface_layer_list);
1618 inputs.device_scale_factor = device_scale_factor;
1619 inputs.can_adjust_raster_scales = true;
1620 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231621 gfx::Transform device_scaled_translate = translate;
1622 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1623 EXPECT_EQ(device_scaled_translate,
1624 root->draw_properties().target_space_transform);
1625 EXPECT_EQ(device_scaled_translate,
1626 child->draw_properties().target_space_transform);
1627 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1628 }
[email protected]9781afa2013-07-17 23:15:321629
1630 // Verify it composes correctly with page scale.
1631 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231632
1633 {
1634 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531635 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1636 root.get(), root->bounds(), translate, &render_surface_layer_list);
1637 inputs.page_scale_factor = page_scale_factor;
1638 inputs.page_scale_application_layer = root.get();
1639 inputs.can_adjust_raster_scales = true;
1640 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231641 gfx::Transform page_scaled_translate = translate;
1642 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1643 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1644 EXPECT_EQ(page_scaled_translate,
1645 child->draw_properties().target_space_transform);
1646 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1647 }
[email protected]9781afa2013-07-17 23:15:321648
[email protected]f224cc92013-06-06 23:23:321649 // Verify that it composes correctly with transforms directly on root layer.
1650 root->SetTransform(composite);
1651 root->SetSublayerTransform(composite);
[email protected]989386c2013-07-18 21:37:231652
1653 {
1654 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531655 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1656 root.get(), root->bounds(), composite, &render_surface_layer_list);
1657 inputs.can_adjust_raster_scales = true;
1658 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231659 gfx::Transform compositeSquared = composite;
1660 compositeSquared.ConcatTransform(composite);
1661 gfx::Transform compositeCubed = compositeSquared;
1662 compositeCubed.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261663 EXPECT_TRANSFORMATION_MATRIX_EQ(
1664 compositeSquared, root->draw_properties().target_space_transform);
1665 EXPECT_TRANSFORMATION_MATRIX_EQ(
1666 compositeCubed, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231667 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1668 }
[email protected]f224cc92013-06-06 23:23:321669}
1670
[email protected]989386c2013-07-18 21:37:231671TEST_F(LayerTreeHostCommonTest,
1672 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321673 scoped_refptr<Layer> parent = Layer::Create();
1674 scoped_refptr<Layer> render_surface1 = Layer::Create();
1675 scoped_refptr<LayerWithForcedDrawsContent> child =
1676 make_scoped_refptr(new LayerWithForcedDrawsContent());
1677
[email protected]d600df7d2013-08-03 02:34:281678 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1679 host->SetRootLayer(parent);
1680
1681
[email protected]fb661802013-03-25 01:59:321682 const gfx::Transform identity_matrix;
1683 SetLayerPropertiesForTesting(parent.get(),
1684 identity_matrix,
1685 identity_matrix,
1686 gfx::PointF(),
1687 gfx::PointF(),
1688 gfx::Size(10, 10),
1689 false);
1690 SetLayerPropertiesForTesting(render_surface1.get(),
1691 identity_matrix,
1692 identity_matrix,
1693 gfx::PointF(),
1694 gfx::PointF(),
1695 gfx::Size(10, 10),
1696 false);
1697 SetLayerPropertiesForTesting(child.get(),
1698 identity_matrix,
1699 identity_matrix,
1700 gfx::PointF(),
1701 gfx::PointF(30.f, 30.f),
1702 gfx::Size(10, 10),
1703 false);
1704
1705 parent->AddChild(render_surface1);
1706 parent->SetMasksToBounds(true);
1707 render_surface1->AddChild(child);
1708 render_surface1->SetForceRenderSurface(true);
1709
[email protected]989386c2013-07-18 21:37:231710 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531711 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1712 parent.get(),
1713 parent->bounds(),
1714 gfx::Transform(),
1715 &render_surface_layer_list);
1716 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321717
1718 // The child layer's content is entirely outside the parent's clip rect, so
1719 // the intermediate render surface should not be listed here, even if it was
1720 // forced to be created. Render surfaces without children or visible content
1721 // are unexpected at draw time (e.g. we might try to create a content texture
1722 // of size 0).
1723 ASSERT_TRUE(parent->render_surface());
1724 ASSERT_FALSE(render_surface1->render_surface());
1725 EXPECT_EQ(1U, render_surface_layer_list.size());
1726}
1727
[email protected]989386c2013-07-18 21:37:231728TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321729 scoped_refptr<Layer> parent = Layer::Create();
1730 scoped_refptr<Layer> render_surface1 = Layer::Create();
1731 scoped_refptr<LayerWithForcedDrawsContent> child =
1732 make_scoped_refptr(new LayerWithForcedDrawsContent());
1733
[email protected]d600df7d2013-08-03 02:34:281734 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1735 host->SetRootLayer(parent);
1736
[email protected]fb661802013-03-25 01:59:321737 const gfx::Transform identity_matrix;
1738 SetLayerPropertiesForTesting(render_surface1.get(),
1739 identity_matrix,
1740 identity_matrix,
1741 gfx::PointF(),
1742 gfx::PointF(),
1743 gfx::Size(10, 10),
1744 false);
1745 SetLayerPropertiesForTesting(child.get(),
1746 identity_matrix,
1747 identity_matrix,
1748 gfx::PointF(),
1749 gfx::PointF(),
1750 gfx::Size(10, 10),
1751 false);
1752
1753 parent->AddChild(render_surface1);
1754 render_surface1->AddChild(child);
1755 render_surface1->SetForceRenderSurface(true);
1756 render_surface1->SetOpacity(0.f);
1757
[email protected]989386c2013-07-18 21:37:231758 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531759 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1760 parent.get(), parent->bounds(), &render_surface_layer_list);
1761 inputs.can_adjust_raster_scales = true;
1762 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321763
1764 // Since the layer is transparent, render_surface1->render_surface() should
1765 // not have gotten added anywhere. Also, the drawable content rect should not
1766 // have been extended by the children.
1767 ASSERT_TRUE(parent->render_surface());
1768 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1769 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231770 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321771 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1772}
1773
[email protected]989386c2013-07-18 21:37:231774TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321775 scoped_refptr<Layer> parent = Layer::Create();
1776 scoped_refptr<Layer> render_surface1 = Layer::Create();
1777 scoped_refptr<LayerWithForcedDrawsContent> child =
1778 make_scoped_refptr(new LayerWithForcedDrawsContent());
1779 render_surface1->SetForceRenderSurface(true);
1780
[email protected]d600df7d2013-08-03 02:34:281781 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1782 host->SetRootLayer(parent);
1783
[email protected]fb661802013-03-25 01:59:321784 const gfx::Transform identity_matrix;
1785 SetLayerPropertiesForTesting(parent.get(),
1786 identity_matrix,
1787 identity_matrix,
1788 gfx::PointF(),
1789 gfx::PointF(),
1790 gfx::Size(10, 10),
1791 false);
1792 SetLayerPropertiesForTesting(render_surface1.get(),
1793 identity_matrix,
1794 identity_matrix,
1795 gfx::PointF(),
1796 gfx::PointF(),
1797 gfx::Size(10, 10),
1798 false);
1799 SetLayerPropertiesForTesting(child.get(),
1800 identity_matrix,
1801 identity_matrix,
1802 gfx::PointF(),
1803 gfx::PointF(),
1804 gfx::Size(10, 10),
1805 false);
1806
1807 parent->AddChild(render_surface1);
1808 render_surface1->AddChild(child);
1809
1810 // Sanity check before the actual test
1811 EXPECT_FALSE(parent->render_surface());
1812 EXPECT_FALSE(render_surface1->render_surface());
1813
[email protected]989386c2013-07-18 21:37:231814 {
1815 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531816 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1817 parent.get(), parent->bounds(), &render_surface_layer_list);
1818 inputs.can_adjust_raster_scales = true;
1819 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321820
[email protected]989386c2013-07-18 21:37:231821 // The root layer always creates a render surface
1822 EXPECT_TRUE(parent->render_surface());
1823 EXPECT_TRUE(render_surface1->render_surface());
1824 EXPECT_EQ(2U, render_surface_layer_list.size());
1825 }
[email protected]fb661802013-03-25 01:59:321826
[email protected]989386c2013-07-18 21:37:231827 {
1828 RenderSurfaceLayerList render_surface_layer_list;
1829 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531830 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1831 parent.get(), parent->bounds(), &render_surface_layer_list);
1832 inputs.can_adjust_raster_scales = true;
1833 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231834 EXPECT_TRUE(parent->render_surface());
1835 EXPECT_FALSE(render_surface1->render_surface());
1836 EXPECT_EQ(1U, render_surface_layer_list.size());
1837 }
[email protected]fb661802013-03-25 01:59:321838}
1839
[email protected]989386c2013-07-18 21:37:231840TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321841 // The entire subtree of layers that are outside the clip rect should be
1842 // culled away, and should not affect the render_surface_layer_list.
1843 //
1844 // The test tree is set up as follows:
1845 // - all layers except the leaf_nodes are forced to be a new render surface
1846 // that have something to draw.
1847 // - parent is a large container layer.
1848 // - child has masksToBounds=true to cause clipping.
1849 // - grand_child is positioned outside of the child's bounds
1850 // - great_grand_child is also kept outside child's bounds.
1851 //
1852 // In this configuration, grand_child and great_grand_child are completely
1853 // outside the clip rect, and they should never get scheduled on the list of
1854 // render surfaces.
1855 //
1856
1857 const gfx::Transform identity_matrix;
1858 scoped_refptr<Layer> parent = Layer::Create();
1859 scoped_refptr<Layer> child = Layer::Create();
1860 scoped_refptr<Layer> grand_child = Layer::Create();
1861 scoped_refptr<Layer> great_grand_child = Layer::Create();
1862 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1863 make_scoped_refptr(new LayerWithForcedDrawsContent());
1864 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1865 make_scoped_refptr(new LayerWithForcedDrawsContent());
1866 parent->AddChild(child);
1867 child->AddChild(grand_child);
1868 grand_child->AddChild(great_grand_child);
1869
[email protected]d600df7d2013-08-03 02:34:281870 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1871 host->SetRootLayer(parent);
1872
[email protected]fb661802013-03-25 01:59:321873 // leaf_node1 ensures that parent and child are kept on the
1874 // render_surface_layer_list, even though grand_child and great_grand_child
1875 // should be clipped.
1876 child->AddChild(leaf_node1);
1877 great_grand_child->AddChild(leaf_node2);
1878
1879 SetLayerPropertiesForTesting(parent.get(),
1880 identity_matrix,
1881 identity_matrix,
1882 gfx::PointF(),
1883 gfx::PointF(),
1884 gfx::Size(500, 500),
1885 false);
1886 SetLayerPropertiesForTesting(child.get(),
1887 identity_matrix,
1888 identity_matrix,
1889 gfx::PointF(),
1890 gfx::PointF(),
1891 gfx::Size(20, 20),
1892 false);
1893 SetLayerPropertiesForTesting(grand_child.get(),
1894 identity_matrix,
1895 identity_matrix,
1896 gfx::PointF(),
1897 gfx::PointF(45.f, 45.f),
1898 gfx::Size(10, 10),
1899 false);
1900 SetLayerPropertiesForTesting(great_grand_child.get(),
1901 identity_matrix,
1902 identity_matrix,
1903 gfx::PointF(),
1904 gfx::PointF(),
1905 gfx::Size(10, 10),
1906 false);
1907 SetLayerPropertiesForTesting(leaf_node1.get(),
1908 identity_matrix,
1909 identity_matrix,
1910 gfx::PointF(),
1911 gfx::PointF(),
1912 gfx::Size(500, 500),
1913 false);
1914 SetLayerPropertiesForTesting(leaf_node2.get(),
1915 identity_matrix,
1916 identity_matrix,
1917 gfx::PointF(),
1918 gfx::PointF(),
1919 gfx::Size(20, 20),
1920 false);
1921
1922 child->SetMasksToBounds(true);
1923 child->SetOpacity(0.4f);
1924 child->SetForceRenderSurface(true);
1925 grand_child->SetOpacity(0.5f);
1926 great_grand_child->SetOpacity(0.4f);
1927
[email protected]989386c2013-07-18 21:37:231928 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531929 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1930 parent.get(), parent->bounds(), &render_surface_layer_list);
1931 inputs.can_adjust_raster_scales = true;
1932 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321933
1934 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231935 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1936 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321937}
1938
[email protected]989386c2013-07-18 21:37:231939TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321940 // When a render surface has a clip rect, it is used to clip the content rect
1941 // of the surface. When the render surface is animating its transforms, then
1942 // the content rect's position in the clip rect is not defined on the main
1943 // thread, and its content rect should not be clipped.
1944
1945 // The test tree is set up as follows:
1946 // - parent is a container layer that masksToBounds=true to cause clipping.
1947 // - child is a render surface, which has a clip rect set to the bounds of
1948 // the parent.
1949 // - grand_child is a render surface, and the only visible content in child.
1950 // It is positioned outside of the clip rect from parent.
1951
1952 // In this configuration, grand_child should be outside the clipped
1953 // content rect of the child, making grand_child not appear in the
1954 // render_surface_layer_list. However, when we place an animation on the
1955 // child, this clipping should be avoided and we should keep the grand_child
1956 // in the render_surface_layer_list.
1957
1958 const gfx::Transform identity_matrix;
1959 scoped_refptr<Layer> parent = Layer::Create();
1960 scoped_refptr<Layer> child = Layer::Create();
1961 scoped_refptr<Layer> grand_child = Layer::Create();
1962 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1963 make_scoped_refptr(new LayerWithForcedDrawsContent());
1964 parent->AddChild(child);
1965 child->AddChild(grand_child);
1966 grand_child->AddChild(leaf_node);
1967
[email protected]d600df7d2013-08-03 02:34:281968 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1969 host->SetRootLayer(parent);
1970
[email protected]fb661802013-03-25 01:59:321971 SetLayerPropertiesForTesting(parent.get(),
1972 identity_matrix,
1973 identity_matrix,
1974 gfx::PointF(),
1975 gfx::PointF(),
1976 gfx::Size(100, 100),
1977 false);
1978 SetLayerPropertiesForTesting(child.get(),
1979 identity_matrix,
1980 identity_matrix,
1981 gfx::PointF(),
1982 gfx::PointF(),
1983 gfx::Size(20, 20),
1984 false);
1985 SetLayerPropertiesForTesting(grand_child.get(),
1986 identity_matrix,
1987 identity_matrix,
1988 gfx::PointF(),
1989 gfx::PointF(200.f, 200.f),
1990 gfx::Size(10, 10),
1991 false);
1992 SetLayerPropertiesForTesting(leaf_node.get(),
1993 identity_matrix,
1994 identity_matrix,
1995 gfx::PointF(),
1996 gfx::PointF(),
1997 gfx::Size(10, 10),
1998 false);
1999
2000 parent->SetMasksToBounds(true);
2001 child->SetOpacity(0.4f);
2002 child->SetForceRenderSurface(true);
2003 grand_child->SetOpacity(0.4f);
2004 grand_child->SetForceRenderSurface(true);
2005
[email protected]989386c2013-07-18 21:37:232006 {
2007 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532008 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2009 parent.get(), parent->bounds(), &render_surface_layer_list);
2010 inputs.can_adjust_raster_scales = true;
2011 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322012
[email protected]989386c2013-07-18 21:37:232013 // Without an animation, we should cull child and grand_child from the
2014 // render_surface_layer_list.
2015 ASSERT_EQ(1U, render_surface_layer_list.size());
2016 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
2017 }
[email protected]fb661802013-03-25 01:59:322018
2019 // Now put an animating transform on child.
2020 AddAnimatedTransformToController(
2021 child->layer_animation_controller(), 10.0, 30, 0);
2022
[email protected]989386c2013-07-18 21:37:232023 {
2024 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532025 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2026 parent.get(), parent->bounds(), &render_surface_layer_list);
2027 inputs.can_adjust_raster_scales = true;
2028 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322029
[email protected]989386c2013-07-18 21:37:232030 // With an animating transform, we should keep child and grand_child in the
2031 // render_surface_layer_list.
2032 ASSERT_EQ(3U, render_surface_layer_list.size());
2033 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
2034 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
2035 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
2036 }
[email protected]fb661802013-03-25 01:59:322037}
2038
[email protected]989386c2013-07-18 21:37:232039TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:322040 // Layer's IsClipped() property is set to true when:
2041 // - the layer clips its subtree, e.g. masks to bounds,
2042 // - the layer is clipped by an ancestor that contributes to the same
2043 // render target,
2044 // - a surface is clipped by an ancestor that contributes to the same
2045 // render target.
2046 //
2047 // In particular, for a layer that owns a render surface:
2048 // - the render surface inherits any clip from ancestors, and does NOT
2049 // pass that clipped status to the layer itself.
2050 // - but if the layer itself masks to bounds, it is considered clipped
2051 // and propagates the clip to the subtree.
2052
2053 const gfx::Transform identity_matrix;
2054 scoped_refptr<Layer> root = Layer::Create();
2055 scoped_refptr<Layer> parent = Layer::Create();
2056 scoped_refptr<Layer> child1 = Layer::Create();
2057 scoped_refptr<Layer> child2 = Layer::Create();
2058 scoped_refptr<Layer> grand_child = Layer::Create();
2059 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2060 make_scoped_refptr(new LayerWithForcedDrawsContent());
2061 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2062 make_scoped_refptr(new LayerWithForcedDrawsContent());
2063 root->AddChild(parent);
2064 parent->AddChild(child1);
2065 parent->AddChild(child2);
2066 child1->AddChild(grand_child);
2067 child2->AddChild(leaf_node2);
2068 grand_child->AddChild(leaf_node1);
2069
[email protected]d600df7d2013-08-03 02:34:282070 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2071 host->SetRootLayer(root);
2072
[email protected]fb661802013-03-25 01:59:322073 child2->SetForceRenderSurface(true);
2074
2075 SetLayerPropertiesForTesting(root.get(),
2076 identity_matrix,
2077 identity_matrix,
2078 gfx::PointF(),
2079 gfx::PointF(),
2080 gfx::Size(100, 100),
2081 false);
2082 SetLayerPropertiesForTesting(parent.get(),
2083 identity_matrix,
2084 identity_matrix,
2085 gfx::PointF(),
2086 gfx::PointF(),
2087 gfx::Size(100, 100),
2088 false);
2089 SetLayerPropertiesForTesting(child1.get(),
2090 identity_matrix,
2091 identity_matrix,
2092 gfx::PointF(),
2093 gfx::PointF(),
2094 gfx::Size(100, 100),
2095 false);
2096 SetLayerPropertiesForTesting(child2.get(),
2097 identity_matrix,
2098 identity_matrix,
2099 gfx::PointF(),
2100 gfx::PointF(),
2101 gfx::Size(100, 100),
2102 false);
2103 SetLayerPropertiesForTesting(grand_child.get(),
2104 identity_matrix,
2105 identity_matrix,
2106 gfx::PointF(),
2107 gfx::PointF(),
2108 gfx::Size(100, 100),
2109 false);
2110 SetLayerPropertiesForTesting(leaf_node1.get(),
2111 identity_matrix,
2112 identity_matrix,
2113 gfx::PointF(),
2114 gfx::PointF(),
2115 gfx::Size(100, 100),
2116 false);
2117 SetLayerPropertiesForTesting(leaf_node2.get(),
2118 identity_matrix,
2119 identity_matrix,
2120 gfx::PointF(),
2121 gfx::PointF(),
2122 gfx::Size(100, 100),
2123 false);
2124
[email protected]989386c2013-07-18 21:37:232125 // Case 1: nothing is clipped except the root render surface.
2126 {
2127 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532128 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2129 root.get(), parent->bounds(), &render_surface_layer_list);
2130 inputs.can_adjust_raster_scales = true;
2131 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322132
[email protected]989386c2013-07-18 21:37:232133 ASSERT_TRUE(root->render_surface());
2134 ASSERT_TRUE(child2->render_surface());
2135
2136 EXPECT_FALSE(root->is_clipped());
2137 EXPECT_TRUE(root->render_surface()->is_clipped());
2138 EXPECT_FALSE(parent->is_clipped());
2139 EXPECT_FALSE(child1->is_clipped());
2140 EXPECT_FALSE(child2->is_clipped());
2141 EXPECT_FALSE(child2->render_surface()->is_clipped());
2142 EXPECT_FALSE(grand_child->is_clipped());
2143 EXPECT_FALSE(leaf_node1->is_clipped());
2144 EXPECT_FALSE(leaf_node2->is_clipped());
2145 }
[email protected]fb661802013-03-25 01:59:322146
2147 // Case 2: parent masksToBounds, so the parent, child1, and child2's
2148 // surface are clipped. But layers that contribute to child2's surface are
2149 // not clipped explicitly because child2's surface already accounts for
2150 // that clip.
[email protected]989386c2013-07-18 21:37:232151 {
2152 RenderSurfaceLayerList render_surface_layer_list;
2153 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:532154 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2155 root.get(), parent->bounds(), &render_surface_layer_list);
2156 inputs.can_adjust_raster_scales = true;
2157 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322158
[email protected]989386c2013-07-18 21:37:232159 ASSERT_TRUE(root->render_surface());
2160 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:322161
[email protected]989386c2013-07-18 21:37:232162 EXPECT_FALSE(root->is_clipped());
2163 EXPECT_TRUE(root->render_surface()->is_clipped());
2164 EXPECT_TRUE(parent->is_clipped());
2165 EXPECT_TRUE(child1->is_clipped());
2166 EXPECT_FALSE(child2->is_clipped());
2167 EXPECT_TRUE(child2->render_surface()->is_clipped());
2168 EXPECT_TRUE(grand_child->is_clipped());
2169 EXPECT_TRUE(leaf_node1->is_clipped());
2170 EXPECT_FALSE(leaf_node2->is_clipped());
2171 }
[email protected]fb661802013-03-25 01:59:322172
2173 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
2174 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:232175 {
2176 RenderSurfaceLayerList render_surface_layer_list;
2177 parent->SetMasksToBounds(false);
2178 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:532179 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2180 root.get(), parent->bounds(), &render_surface_layer_list);
2181 inputs.can_adjust_raster_scales = true;
2182 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322183
[email protected]989386c2013-07-18 21:37:232184 ASSERT_TRUE(root->render_surface());
2185 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:322186
[email protected]989386c2013-07-18 21:37:232187 EXPECT_FALSE(root->is_clipped());
2188 EXPECT_TRUE(root->render_surface()->is_clipped());
2189 EXPECT_FALSE(parent->is_clipped());
2190 EXPECT_FALSE(child1->is_clipped());
2191 EXPECT_TRUE(child2->is_clipped());
2192 EXPECT_FALSE(child2->render_surface()->is_clipped());
2193 EXPECT_FALSE(grand_child->is_clipped());
2194 EXPECT_FALSE(leaf_node1->is_clipped());
2195 EXPECT_TRUE(leaf_node2->is_clipped());
2196 }
[email protected]fb661802013-03-25 01:59:322197}
2198
[email protected]fd9a3b6d2013-08-03 00:46:172199TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322200 // Verify that layers get the appropriate DrawableContentRect when their
2201 // parent masksToBounds is true.
2202 //
2203 // grand_child1 - completely inside the region; DrawableContentRect should
2204 // be the layer rect expressed in target space.
2205 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
2206 // will be the intersection of layer bounds and the mask region.
2207 // grand_child3 - partially clipped and masksToBounds; the
2208 // DrawableContentRect will still be the intersection of layer bounds and
2209 // the mask region.
2210 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2211 // be empty.
2212 //
2213
2214 const gfx::Transform identity_matrix;
2215 scoped_refptr<Layer> parent = Layer::Create();
2216 scoped_refptr<Layer> child = Layer::Create();
2217 scoped_refptr<Layer> grand_child1 = Layer::Create();
2218 scoped_refptr<Layer> grand_child2 = Layer::Create();
2219 scoped_refptr<Layer> grand_child3 = Layer::Create();
2220 scoped_refptr<Layer> grand_child4 = Layer::Create();
2221
2222 parent->AddChild(child);
2223 child->AddChild(grand_child1);
2224 child->AddChild(grand_child2);
2225 child->AddChild(grand_child3);
2226 child->AddChild(grand_child4);
2227
[email protected]d600df7d2013-08-03 02:34:282228 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2229 host->SetRootLayer(parent);
2230
[email protected]fb661802013-03-25 01:59:322231 SetLayerPropertiesForTesting(parent.get(),
2232 identity_matrix,
2233 identity_matrix,
2234 gfx::PointF(),
2235 gfx::PointF(),
2236 gfx::Size(500, 500),
2237 false);
2238 SetLayerPropertiesForTesting(child.get(),
2239 identity_matrix,
2240 identity_matrix,
2241 gfx::PointF(),
2242 gfx::PointF(),
2243 gfx::Size(20, 20),
2244 false);
2245 SetLayerPropertiesForTesting(grand_child1.get(),
2246 identity_matrix,
2247 identity_matrix,
2248 gfx::PointF(),
2249 gfx::PointF(5.f, 5.f),
2250 gfx::Size(10, 10),
2251 false);
2252 SetLayerPropertiesForTesting(grand_child2.get(),
2253 identity_matrix,
2254 identity_matrix,
2255 gfx::PointF(),
2256 gfx::PointF(15.f, 15.f),
2257 gfx::Size(10, 10),
2258 false);
2259 SetLayerPropertiesForTesting(grand_child3.get(),
2260 identity_matrix,
2261 identity_matrix,
2262 gfx::PointF(),
2263 gfx::PointF(15.f, 15.f),
2264 gfx::Size(10, 10),
2265 false);
2266 SetLayerPropertiesForTesting(grand_child4.get(),
2267 identity_matrix,
2268 identity_matrix,
2269 gfx::PointF(),
2270 gfx::PointF(45.f, 45.f),
2271 gfx::Size(10, 10),
2272 false);
2273
2274 child->SetMasksToBounds(true);
2275 grand_child3->SetMasksToBounds(true);
2276
2277 // Force everyone to be a render surface.
2278 child->SetOpacity(0.4f);
2279 grand_child1->SetOpacity(0.5f);
2280 grand_child2->SetOpacity(0.5f);
2281 grand_child3->SetOpacity(0.5f);
2282 grand_child4->SetOpacity(0.5f);
2283
[email protected]989386c2013-07-18 21:37:232284 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532285 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2286 parent.get(), parent->bounds(), &render_surface_layer_list);
2287 inputs.can_adjust_raster_scales = true;
2288 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322289
[email protected]2c7c6702013-03-26 03:14:052290 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
[email protected]fb661802013-03-25 01:59:322291 grand_child1->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:052292 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:322293 grand_child3->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:052294 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:322295 grand_child3->drawable_content_rect());
2296 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2297}
2298
[email protected]989386c2013-07-18 21:37:232299TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322300 // Verify that render surfaces (and their layers) get the appropriate
2301 // clip rects when their parent masksToBounds is true.
2302 //
2303 // Layers that own render surfaces (at least for now) do not inherit any
2304 // clipping; instead the surface will enforce the clip for the entire subtree.
2305 // They may still have a clip rect of their own layer bounds, however, if
2306 // masksToBounds was true.
2307 const gfx::Transform identity_matrix;
2308 scoped_refptr<Layer> parent = Layer::Create();
2309 scoped_refptr<Layer> child = Layer::Create();
2310 scoped_refptr<Layer> grand_child1 = Layer::Create();
2311 scoped_refptr<Layer> grand_child2 = Layer::Create();
2312 scoped_refptr<Layer> grand_child3 = Layer::Create();
2313 scoped_refptr<Layer> grand_child4 = Layer::Create();
2314 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2315 make_scoped_refptr(new LayerWithForcedDrawsContent());
2316 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2317 make_scoped_refptr(new LayerWithForcedDrawsContent());
2318 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
2319 make_scoped_refptr(new LayerWithForcedDrawsContent());
2320 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
2321 make_scoped_refptr(new LayerWithForcedDrawsContent());
2322
2323 parent->AddChild(child);
2324 child->AddChild(grand_child1);
2325 child->AddChild(grand_child2);
2326 child->AddChild(grand_child3);
2327 child->AddChild(grand_child4);
2328
[email protected]d600df7d2013-08-03 02:34:282329 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2330 host->SetRootLayer(parent);
2331
[email protected]fb661802013-03-25 01:59:322332 // the leaf nodes ensure that these grand_children become render surfaces for
2333 // this test.
2334 grand_child1->AddChild(leaf_node1);
2335 grand_child2->AddChild(leaf_node2);
2336 grand_child3->AddChild(leaf_node3);
2337 grand_child4->AddChild(leaf_node4);
2338
2339 SetLayerPropertiesForTesting(parent.get(),
2340 identity_matrix,
2341 identity_matrix,
2342 gfx::PointF(),
2343 gfx::PointF(),
2344 gfx::Size(500, 500),
2345 false);
2346 SetLayerPropertiesForTesting(child.get(),
2347 identity_matrix,
2348 identity_matrix,
2349 gfx::PointF(),
2350 gfx::PointF(),
2351 gfx::Size(20, 20),
2352 false);
2353 SetLayerPropertiesForTesting(grand_child1.get(),
2354 identity_matrix,
2355 identity_matrix,
2356 gfx::PointF(),
2357 gfx::PointF(5.f, 5.f),
2358 gfx::Size(10, 10),
2359 false);
2360 SetLayerPropertiesForTesting(grand_child2.get(),
2361 identity_matrix,
2362 identity_matrix,
2363 gfx::PointF(),
2364 gfx::PointF(15.f, 15.f),
2365 gfx::Size(10, 10),
2366 false);
2367 SetLayerPropertiesForTesting(grand_child3.get(),
2368 identity_matrix,
2369 identity_matrix,
2370 gfx::PointF(),
2371 gfx::PointF(15.f, 15.f),
2372 gfx::Size(10, 10),
2373 false);
2374 SetLayerPropertiesForTesting(grand_child4.get(),
2375 identity_matrix,
2376 identity_matrix,
2377 gfx::PointF(),
2378 gfx::PointF(45.f, 45.f),
2379 gfx::Size(10, 10),
2380 false);
2381 SetLayerPropertiesForTesting(leaf_node1.get(),
2382 identity_matrix,
2383 identity_matrix,
2384 gfx::PointF(),
2385 gfx::PointF(),
2386 gfx::Size(10, 10),
2387 false);
2388 SetLayerPropertiesForTesting(leaf_node2.get(),
2389 identity_matrix,
2390 identity_matrix,
2391 gfx::PointF(),
2392 gfx::PointF(),
2393 gfx::Size(10, 10),
2394 false);
2395 SetLayerPropertiesForTesting(leaf_node3.get(),
2396 identity_matrix,
2397 identity_matrix,
2398 gfx::PointF(),
2399 gfx::PointF(),
2400 gfx::Size(10, 10),
2401 false);
2402 SetLayerPropertiesForTesting(leaf_node4.get(),
2403 identity_matrix,
2404 identity_matrix,
2405 gfx::PointF(),
2406 gfx::PointF(),
2407 gfx::Size(10, 10),
2408 false);
2409
2410 child->SetMasksToBounds(true);
2411 grand_child3->SetMasksToBounds(true);
2412 grand_child4->SetMasksToBounds(true);
2413
2414 // Force everyone to be a render surface.
2415 child->SetOpacity(0.4f);
2416 child->SetForceRenderSurface(true);
2417 grand_child1->SetOpacity(0.5f);
2418 grand_child1->SetForceRenderSurface(true);
2419 grand_child2->SetOpacity(0.5f);
2420 grand_child2->SetForceRenderSurface(true);
2421 grand_child3->SetOpacity(0.5f);
2422 grand_child3->SetForceRenderSurface(true);
2423 grand_child4->SetOpacity(0.5f);
2424 grand_child4->SetForceRenderSurface(true);
2425
[email protected]989386c2013-07-18 21:37:232426 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532427 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2428 parent.get(), parent->bounds(), &render_surface_layer_list);
2429 inputs.can_adjust_raster_scales = true;
2430 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322431 ASSERT_TRUE(grand_child1->render_surface());
2432 ASSERT_TRUE(grand_child2->render_surface());
2433 ASSERT_TRUE(grand_child3->render_surface());
2434 // Because grand_child4 is entirely clipped, it is expected to not have a
2435 // render surface.
2436 EXPECT_FALSE(grand_child4->render_surface());
2437
2438 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2439 // masksToBounds.
[email protected]2c7c6702013-03-26 03:14:052440 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322441 grand_child1->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052442 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322443 grand_child2->render_surface()->clip_rect());
[email protected]2c7c6702013-03-26 03:14:052444 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322445 grand_child3->render_surface()->clip_rect());
2446}
2447
[email protected]989386c2013-07-18 21:37:232448TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322449 scoped_refptr<Layer> parent = Layer::Create();
2450 scoped_refptr<Layer> render_surface1 = Layer::Create();
2451 scoped_refptr<Layer> render_surface2 = Layer::Create();
2452 scoped_refptr<Layer> child_of_root = Layer::Create();
2453 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2454 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2455 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2456 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2457 make_scoped_refptr(new LayerWithForcedDrawsContent());
2458 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2459 make_scoped_refptr(new LayerWithForcedDrawsContent());
2460 parent->AddChild(render_surface1);
2461 parent->AddChild(child_of_root);
2462 render_surface1->AddChild(child_of_rs1);
2463 render_surface1->AddChild(render_surface2);
2464 render_surface2->AddChild(child_of_rs2);
2465 child_of_root->AddChild(grand_child_of_root);
2466 child_of_rs1->AddChild(grand_child_of_rs1);
2467 child_of_rs2->AddChild(grand_child_of_rs2);
2468
[email protected]d600df7d2013-08-03 02:34:282469 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2470 host->SetRootLayer(parent);
2471
[email protected]fb661802013-03-25 01:59:322472 // Make our render surfaces.
2473 render_surface1->SetForceRenderSurface(true);
2474 render_surface2->SetForceRenderSurface(true);
2475
2476 gfx::Transform layer_transform;
2477 layer_transform.Translate(1.0, 1.0);
2478 gfx::Transform sublayer_transform;
2479 sublayer_transform.Scale3d(10.0, 1.0, 1.0);
2480
2481 SetLayerPropertiesForTesting(parent.get(),
2482 layer_transform,
2483 sublayer_transform,
2484 gfx::PointF(0.25f, 0.f),
2485 gfx::PointF(2.5f, 0.f),
2486 gfx::Size(10, 10),
2487 false);
2488 SetLayerPropertiesForTesting(render_surface1.get(),
2489 layer_transform,
2490 sublayer_transform,
2491 gfx::PointF(0.25f, 0.f),
2492 gfx::PointF(2.5f, 0.f),
2493 gfx::Size(10, 10),
2494 false);
2495 SetLayerPropertiesForTesting(render_surface2.get(),
2496 layer_transform,
2497 sublayer_transform,
2498 gfx::PointF(0.25f, 0.f),
2499 gfx::PointF(2.5f, 0.f),
2500 gfx::Size(10, 10),
2501 false);
2502 SetLayerPropertiesForTesting(child_of_root.get(),
2503 layer_transform,
2504 sublayer_transform,
2505 gfx::PointF(0.25f, 0.f),
2506 gfx::PointF(2.5f, 0.f),
2507 gfx::Size(10, 10),
2508 false);
2509 SetLayerPropertiesForTesting(child_of_rs1.get(),
2510 layer_transform,
2511 sublayer_transform,
2512 gfx::PointF(0.25f, 0.f),
2513 gfx::PointF(2.5f, 0.f),
2514 gfx::Size(10, 10),
2515 false);
2516 SetLayerPropertiesForTesting(child_of_rs2.get(),
2517 layer_transform,
2518 sublayer_transform,
2519 gfx::PointF(0.25f, 0.f),
2520 gfx::PointF(2.5f, 0.f),
2521 gfx::Size(10, 10),
2522 false);
2523 SetLayerPropertiesForTesting(grand_child_of_root.get(),
2524 layer_transform,
2525 sublayer_transform,
2526 gfx::PointF(0.25f, 0.f),
2527 gfx::PointF(2.5f, 0.f),
2528 gfx::Size(10, 10),
2529 false);
2530 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
2531 layer_transform,
2532 sublayer_transform,
2533 gfx::PointF(0.25f, 0.f),
2534 gfx::PointF(2.5f, 0.f),
2535 gfx::Size(10, 10),
2536 false);
2537 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
2538 layer_transform,
2539 sublayer_transform,
2540 gfx::PointF(0.25f, 0.f),
2541 gfx::PointF(2.5f, 0.f),
2542 gfx::Size(10, 10),
2543 false);
2544
2545 // Put an animated opacity on the render surface.
2546 AddOpacityTransitionToController(
2547 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2548
2549 // Also put an animated opacity on a layer without descendants.
2550 AddOpacityTransitionToController(
2551 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2552
2553 // Put a transform animation on the render surface.
2554 AddAnimatedTransformToController(
2555 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2556
2557 // Also put transform animations on grand_child_of_root, and
2558 // grand_child_of_rs2
2559 AddAnimatedTransformToController(
2560 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2561 AddAnimatedTransformToController(
2562 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2563
2564 ExecuteCalculateDrawProperties(parent.get());
2565
2566 // Only layers that are associated with render surfaces should have an actual
2567 // RenderSurface() value.
2568 ASSERT_TRUE(parent->render_surface());
2569 ASSERT_FALSE(child_of_root->render_surface());
2570 ASSERT_FALSE(grand_child_of_root->render_surface());
2571
2572 ASSERT_TRUE(render_surface1->render_surface());
2573 ASSERT_FALSE(child_of_rs1->render_surface());
2574 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2575
2576 ASSERT_TRUE(render_surface2->render_surface());
2577 ASSERT_FALSE(child_of_rs2->render_surface());
2578 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2579
2580 // Verify all render target accessors
2581 EXPECT_EQ(parent, parent->render_target());
2582 EXPECT_EQ(parent, child_of_root->render_target());
2583 EXPECT_EQ(parent, grand_child_of_root->render_target());
2584
2585 EXPECT_EQ(render_surface1, render_surface1->render_target());
2586 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2587 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
2588
2589 EXPECT_EQ(render_surface2, render_surface2->render_target());
2590 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2591 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
2592
2593 // Verify draw_opacity_is_animating values
2594 EXPECT_FALSE(parent->draw_opacity_is_animating());
2595 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2596 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2597 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2598 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2599 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2600 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2601 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2602 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2603 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2604 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2605
2606 // Verify draw_transform_is_animating values
2607 EXPECT_FALSE(parent->draw_transform_is_animating());
2608 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2609 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2610 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2611 EXPECT_FALSE(render_surface1->render_surface()
2612 ->target_surface_transforms_are_animating());
2613 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2614 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2615 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2616 EXPECT_TRUE(render_surface2->render_surface()
2617 ->target_surface_transforms_are_animating());
2618 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2619 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2620
2621 // Verify screen_space_transform_is_animating values
2622 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2623 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2624 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2625 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2626 EXPECT_FALSE(render_surface1->render_surface()
2627 ->screen_space_transforms_are_animating());
2628 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2629 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2630 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2631 EXPECT_TRUE(render_surface2->render_surface()
2632 ->screen_space_transforms_are_animating());
2633 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2634 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2635
2636 // Sanity check. If these fail there is probably a bug in the test itself.
2637 // It is expected that we correctly set up transforms so that the y-component
2638 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262639 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2640 EXPECT_FLOAT_EQ(2.0,
2641 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322642 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262643 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322644
[email protected]803f6b52013-09-12 00:51:262645 EXPECT_FLOAT_EQ(2.0,
2646 render_surface1->screen_space_transform().matrix().get(1, 3));
2647 EXPECT_FLOAT_EQ(3.0,
2648 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322649 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262650 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322651
[email protected]803f6b52013-09-12 00:51:262652 EXPECT_FLOAT_EQ(3.0,
2653 render_surface2->screen_space_transform().matrix().get(1, 3));
2654 EXPECT_FLOAT_EQ(4.0,
2655 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322656 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262657 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322658}
2659
[email protected]989386c2013-07-18 21:37:232660TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322661 // Test the calculateVisibleRect() function works correctly for identity
2662 // transforms.
2663
[email protected]2c7c6702013-03-26 03:14:052664 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322665 gfx::Transform layer_to_surface_transform;
2666
2667 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232668 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052669 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322670 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2671 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2672 EXPECT_RECT_EQ(expected, actual);
2673
2674 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052675 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322676 actual = LayerTreeHostCommon::CalculateVisibleRect(
2677 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2678 EXPECT_TRUE(actual.IsEmpty());
2679
2680 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052681 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2682 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322683 actual = LayerTreeHostCommon::CalculateVisibleRect(
2684 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2685 EXPECT_RECT_EQ(expected, actual);
2686}
2687
[email protected]989386c2013-07-18 21:37:232688TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322689 // Test the calculateVisibleRect() function works correctly for scaling
2690 // transforms.
2691
[email protected]2c7c6702013-03-26 03:14:052692 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2693 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322694 gfx::Transform layer_to_surface_transform;
2695
2696 // Case 1: Layer is contained within the surface.
2697 layer_to_surface_transform.MakeIdentity();
2698 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052699 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322700 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2701 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2702 EXPECT_RECT_EQ(expected, actual);
2703
2704 // Case 2: Layer is outside the surface rect.
2705 layer_to_surface_transform.MakeIdentity();
2706 layer_to_surface_transform.Translate(120.0, 120.0);
2707 actual = LayerTreeHostCommon::CalculateVisibleRect(
2708 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2709 EXPECT_TRUE(actual.IsEmpty());
2710
2711 // Case 3: Layer is partially overlapping the surface rect.
2712 layer_to_surface_transform.MakeIdentity();
2713 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052714 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322715 actual = LayerTreeHostCommon::CalculateVisibleRect(
2716 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2717 EXPECT_RECT_EQ(expected, actual);
2718}
2719
[email protected]989386c2013-07-18 21:37:232720TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322721 // Test the calculateVisibleRect() function works correctly for rotations
2722 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2723 // should return the g in the layer's space.
2724
[email protected]2c7c6702013-03-26 03:14:052725 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2726 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322727 gfx::Transform layer_to_surface_transform;
2728
2729 // Case 1: Layer is contained within the surface.
2730 layer_to_surface_transform.MakeIdentity();
2731 layer_to_surface_transform.Translate(50.0, 50.0);
2732 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052733 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322734 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2735 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2736 EXPECT_RECT_EQ(expected, actual);
2737
2738 // Case 2: Layer is outside the surface rect.
2739 layer_to_surface_transform.MakeIdentity();
2740 layer_to_surface_transform.Translate(-50.0, 0.0);
2741 layer_to_surface_transform.Rotate(45.0);
2742 actual = LayerTreeHostCommon::CalculateVisibleRect(
2743 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2744 EXPECT_TRUE(actual.IsEmpty());
2745
2746 // Case 3: The layer is rotated about its top-left corner. In surface space,
2747 // the layer is oriented diagonally, with the left half outside of the render
2748 // surface. In this case, the g should still be the entire layer
2749 // (remember the g is computed in layer space); both the top-left
2750 // and bottom-right corners of the layer are still visible.
2751 layer_to_surface_transform.MakeIdentity();
2752 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052753 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322754 actual = LayerTreeHostCommon::CalculateVisibleRect(
2755 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2756 EXPECT_RECT_EQ(expected, actual);
2757
2758 // Case 4: The layer is rotated about its top-left corner, and translated
2759 // upwards. In surface space, the layer is oriented diagonally, with only the
2760 // top corner of the surface overlapping the layer. In layer space, the render
2761 // surface overlaps the right side of the layer. The g should be
2762 // the layer's right half.
2763 layer_to_surface_transform.MakeIdentity();
2764 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2765 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052766 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322767 actual = LayerTreeHostCommon::CalculateVisibleRect(
2768 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2769 EXPECT_RECT_EQ(expected, actual);
2770}
2771
[email protected]989386c2013-07-18 21:37:232772TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322773 // Test that the calculateVisibleRect() function works correctly for 3d
2774 // transforms.
2775
[email protected]2c7c6702013-03-26 03:14:052776 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2777 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322778 gfx::Transform layer_to_surface_transform;
2779
2780 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2781 // degrees, should be fully contained in the render surface.
2782 layer_to_surface_transform.MakeIdentity();
2783 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052784 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322785 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2786 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2787 EXPECT_RECT_EQ(expected, actual);
2788
2789 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2790 // degrees, but shifted to the side so only the right-half the layer would be
2791 // visible on the surface.
2792 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262793 SkMScalar half_width_of_rotated_layer =
2794 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322795 layer_to_surface_transform.MakeIdentity();
2796 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232797 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2798 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052799 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322800 actual = LayerTreeHostCommon::CalculateVisibleRect(
2801 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2802 EXPECT_RECT_EQ(expected, actual);
2803}
2804
[email protected]989386c2013-07-18 21:37:232805TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322806 // Test the calculateVisibleRect() function works correctly when the layer has
2807 // a perspective projection onto the target surface.
2808
[email protected]2c7c6702013-03-26 03:14:052809 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2810 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322811 gfx::Transform layer_to_surface_transform;
2812
2813 // Case 1: Even though the layer is twice as large as the surface, due to
2814 // perspective foreshortening, the layer will fit fully in the surface when
2815 // its translated more than the perspective amount.
2816 layer_to_surface_transform.MakeIdentity();
2817
2818 // The following sequence of transforms applies the perspective about the
2819 // center of the surface.
2820 layer_to_surface_transform.Translate(50.0, 50.0);
2821 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2822 layer_to_surface_transform.Translate(-50.0, -50.0);
2823
2824 // This translate places the layer in front of the surface's projection plane.
2825 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2826
[email protected]2c7c6702013-03-26 03:14:052827 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322828 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2829 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2830 EXPECT_RECT_EQ(expected, actual);
2831
2832 // Case 2: same projection as before, except that the layer is also translated
2833 // to the side, so that only the right half of the layer should be visible.
2834 //
2835 // Explanation of expected result: The perspective ratio is (z distance
2836 // between layer and camera origin) / (z distance between projection plane and
2837 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2838 // move a layer by translating -50 units in projected surface units (so that
2839 // only half of it is visible), then we would need to translate by (-36 / 9) *
2840 // -50 == -200 in the layer's units.
2841 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232842 expected = gfx::Rect(gfx::Point(50, -50),
2843 gfx::Size(100, 200)); // The right half of the layer's
2844 // bounding rect.
[email protected]fb661802013-03-25 01:59:322845 actual = LayerTreeHostCommon::CalculateVisibleRect(
2846 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2847 EXPECT_RECT_EQ(expected, actual);
2848}
2849
[email protected]989386c2013-07-18 21:37:232850TEST_F(LayerTreeHostCommonTest,
2851 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322852 // There is currently no explicit concept of an orthographic projection plane
2853 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2854 // are technically behind the surface in an orthographic world should not be
2855 // clipped when they are flattened to the surface.
2856
[email protected]2c7c6702013-03-26 03:14:052857 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2858 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322859 gfx::Transform layer_to_surface_transform;
2860
2861 // This sequence of transforms effectively rotates the layer about the y-axis
2862 // at the center of the layer.
2863 layer_to_surface_transform.MakeIdentity();
2864 layer_to_surface_transform.Translate(50.0, 0.0);
2865 layer_to_surface_transform.RotateAboutYAxis(45.0);
2866 layer_to_surface_transform.Translate(-50.0, 0.0);
2867
[email protected]2c7c6702013-03-26 03:14:052868 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322869 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2870 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2871 EXPECT_RECT_EQ(expected, actual);
2872}
2873
[email protected]989386c2013-07-18 21:37:232874TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322875 // Test the calculateVisibleRect() function works correctly when projecting a
2876 // surface onto a layer, but the layer is partially behind the camera (not
2877 // just behind the projection plane). In this case, the cartesian coordinates
2878 // may seem to be valid, but actually they are not. The visible rect needs to
2879 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2880 // converting to cartesian coordinates.
2881
[email protected]2c7c6702013-03-26 03:14:052882 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232883 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322884 gfx::Transform layer_to_surface_transform;
2885
2886 // The layer is positioned so that the right half of the layer should be in
2887 // front of the camera, while the other half is behind the surface's
2888 // projection plane. The following sequence of transforms applies the
2889 // perspective and rotation about the center of the layer.
2890 layer_to_surface_transform.MakeIdentity();
2891 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2892 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2893 layer_to_surface_transform.RotateAboutYAxis(45.0);
2894
2895 // Sanity check that this transform does indeed cause w < 0 when applying the
2896 // transform, otherwise this code is not testing the intended scenario.
2897 bool clipped;
2898 MathUtil::MapQuad(layer_to_surface_transform,
2899 gfx::QuadF(gfx::RectF(layer_content_rect)),
2900 &clipped);
2901 ASSERT_TRUE(clipped);
2902
2903 int expected_x_position = 0;
2904 int expected_width = 10;
2905 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2906 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2907 EXPECT_EQ(expected_x_position, actual.x());
2908 EXPECT_EQ(expected_width, actual.width());
2909}
2910
[email protected]989386c2013-07-18 21:37:232911TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322912 // To determine visible rect in layer space, there needs to be an
2913 // un-projection from surface space to layer space. When the original
2914 // transform was a perspective projection that was clipped, it returns a rect
2915 // that encloses the clipped bounds. Un-projecting this new rect may require
2916 // clipping again.
2917
2918 // This sequence of transforms causes one corner of the layer to protrude
2919 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232920 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2921 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322922 gfx::Transform layer_to_surface_transform;
2923 layer_to_surface_transform.MakeIdentity();
2924 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2925 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2926 layer_to_surface_transform.RotateAboutYAxis(45.0);
2927 layer_to_surface_transform.RotateAboutXAxis(80.0);
2928
2929 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2930 // code is not testing the intended scenario.
2931 bool clipped;
2932 gfx::RectF clipped_rect =
2933 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2934 MathUtil::ProjectQuad(
2935 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2936 ASSERT_TRUE(clipped);
2937
2938 // Only the corner of the layer is not visible on the surface because of being
2939 // clipped. But, the net result of rounding visible region to an axis-aligned
2940 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052941 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322942 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2943 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2944 EXPECT_RECT_EQ(expected, actual);
2945}
2946
[email protected]989386c2013-07-18 21:37:232947TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322948 scoped_refptr<Layer> root = Layer::Create();
2949 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2950 make_scoped_refptr(new LayerWithForcedDrawsContent());
2951 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2952 make_scoped_refptr(new LayerWithForcedDrawsContent());
2953 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2954 make_scoped_refptr(new LayerWithForcedDrawsContent());
2955 root->AddChild(child1);
2956 root->AddChild(child2);
2957 root->AddChild(child3);
2958
[email protected]d600df7d2013-08-03 02:34:282959 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2960 host->SetRootLayer(root);
2961
[email protected]fb661802013-03-25 01:59:322962 gfx::Transform identity_matrix;
2963 SetLayerPropertiesForTesting(root.get(),
2964 identity_matrix,
2965 identity_matrix,
2966 gfx::PointF(),
2967 gfx::PointF(),
2968 gfx::Size(100, 100),
2969 false);
2970 SetLayerPropertiesForTesting(child1.get(),
2971 identity_matrix,
2972 identity_matrix,
2973 gfx::PointF(),
2974 gfx::PointF(),
2975 gfx::Size(50, 50),
2976 false);
2977 SetLayerPropertiesForTesting(child2.get(),
2978 identity_matrix,
2979 identity_matrix,
2980 gfx::PointF(),
2981 gfx::PointF(75.f, 75.f),
2982 gfx::Size(50, 50),
2983 false);
2984 SetLayerPropertiesForTesting(child3.get(),
2985 identity_matrix,
2986 identity_matrix,
2987 gfx::PointF(),
2988 gfx::PointF(125.f, 125.f),
2989 gfx::Size(50, 50),
2990 false);
2991
2992 ExecuteCalculateDrawProperties(root.get());
2993
2994 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2995 root->render_surface()->DrawableContentRect());
2996 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2997
2998 // Layers that do not draw content should have empty visible_content_rects.
2999 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3000
3001 // layer visible_content_rects are clipped by their target surface.
3002 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3003 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
3004 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3005
3006 // layer drawable_content_rects are not clipped.
3007 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
3008 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3009 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3010}
3011
[email protected]989386c2013-07-18 21:37:233012TEST_F(LayerTreeHostCommonTest,
3013 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:323014 scoped_refptr<Layer> root = Layer::Create();
3015 scoped_refptr<Layer> child = Layer::Create();
3016 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
3017 make_scoped_refptr(new LayerWithForcedDrawsContent());
3018 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
3019 make_scoped_refptr(new LayerWithForcedDrawsContent());
3020 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
3021 make_scoped_refptr(new LayerWithForcedDrawsContent());
3022 root->AddChild(child);
3023 child->AddChild(grand_child1);
3024 child->AddChild(grand_child2);
3025 child->AddChild(grand_child3);
3026
[email protected]d600df7d2013-08-03 02:34:283027 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3028 host->SetRootLayer(root);
3029
[email protected]fb661802013-03-25 01:59:323030 gfx::Transform identity_matrix;
3031 SetLayerPropertiesForTesting(root.get(),
3032 identity_matrix,
3033 identity_matrix,
3034 gfx::PointF(),
3035 gfx::PointF(),
3036 gfx::Size(100, 100),
3037 false);
3038 SetLayerPropertiesForTesting(child.get(),
3039 identity_matrix,
3040 identity_matrix,
3041 gfx::PointF(),
3042 gfx::PointF(),
3043 gfx::Size(100, 100),
3044 false);
3045 SetLayerPropertiesForTesting(grand_child1.get(),
3046 identity_matrix,
3047 identity_matrix,
3048 gfx::PointF(),
3049 gfx::PointF(5.f, 5.f),
3050 gfx::Size(50, 50),
3051 false);
3052 SetLayerPropertiesForTesting(grand_child2.get(),
3053 identity_matrix,
3054 identity_matrix,
3055 gfx::PointF(),
3056 gfx::PointF(75.f, 75.f),
3057 gfx::Size(50, 50),
3058 false);
3059 SetLayerPropertiesForTesting(grand_child3.get(),
3060 identity_matrix,
3061 identity_matrix,
3062 gfx::PointF(),
3063 gfx::PointF(125.f, 125.f),
3064 gfx::Size(50, 50),
3065 false);
3066
3067 child->SetMasksToBounds(true);
3068 ExecuteCalculateDrawProperties(root.get());
3069
3070 ASSERT_FALSE(child->render_surface());
3071
3072 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3073 root->render_surface()->DrawableContentRect());
3074 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3075
3076 // Layers that do not draw content should have empty visible content rects.
3077 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3078 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
3079
3080 // All grandchild visible content rects should be clipped by child.
3081 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
3082 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
3083 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
3084
3085 // All grandchild DrawableContentRects should also be clipped by child.
3086 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
3087 grand_child1->drawable_content_rect());
3088 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
3089 grand_child2->drawable_content_rect());
3090 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
3091}
3092
[email protected]989386c2013-07-18 21:37:233093TEST_F(LayerTreeHostCommonTest,
3094 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:323095 scoped_refptr<Layer> root = Layer::Create();
3096 scoped_refptr<Layer> render_surface1 = Layer::Create();
3097 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3098 make_scoped_refptr(new LayerWithForcedDrawsContent());
3099 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3100 make_scoped_refptr(new LayerWithForcedDrawsContent());
3101 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3102 make_scoped_refptr(new LayerWithForcedDrawsContent());
3103 root->AddChild(render_surface1);
3104 render_surface1->AddChild(child1);
3105 render_surface1->AddChild(child2);
3106 render_surface1->AddChild(child3);
3107
[email protected]d600df7d2013-08-03 02:34:283108 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3109 host->SetRootLayer(root);
3110
[email protected]fb661802013-03-25 01:59:323111 gfx::Transform identity_matrix;
3112 SetLayerPropertiesForTesting(root.get(),
3113 identity_matrix,
3114 identity_matrix,
3115 gfx::PointF(),
3116 gfx::PointF(),
3117 gfx::Size(100, 100),
3118 false);
3119 SetLayerPropertiesForTesting(render_surface1.get(),
3120 identity_matrix,
3121 identity_matrix,
3122 gfx::PointF(),
3123 gfx::PointF(),
3124 gfx::Size(3, 4),
3125 false);
3126 SetLayerPropertiesForTesting(child1.get(),
3127 identity_matrix,
3128 identity_matrix,
3129 gfx::PointF(),
3130 gfx::PointF(5.f, 5.f),
3131 gfx::Size(50, 50),
3132 false);
3133 SetLayerPropertiesForTesting(child2.get(),
3134 identity_matrix,
3135 identity_matrix,
3136 gfx::PointF(),
3137 gfx::PointF(75.f, 75.f),
3138 gfx::Size(50, 50),
3139 false);
3140 SetLayerPropertiesForTesting(child3.get(),
3141 identity_matrix,
3142 identity_matrix,
3143 gfx::PointF(),
3144 gfx::PointF(125.f, 125.f),
3145 gfx::Size(50, 50),
3146 false);
3147
3148 render_surface1->SetForceRenderSurface(true);
3149 ExecuteCalculateDrawProperties(root.get());
3150
3151 ASSERT_TRUE(render_surface1->render_surface());
3152
3153 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3154 root->render_surface()->DrawableContentRect());
3155 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3156
3157 // Layers that do not draw content should have empty visible content rects.
3158 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3159 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3160 render_surface1->visible_content_rect());
3161
3162 // An unclipped surface grows its DrawableContentRect to include all drawable
3163 // regions of the subtree.
3164 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3165 render_surface1->render_surface()->DrawableContentRect());
3166
3167 // All layers that draw content into the unclipped surface are also unclipped.
3168 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3169 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3170 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
3171
3172 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3173 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3174 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3175}
3176
[email protected]989386c2013-07-18 21:37:233177TEST_F(LayerTreeHostCommonTest,
3178 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:473179 scoped_refptr<Layer> root = Layer::Create();
3180 scoped_refptr<LayerWithForcedDrawsContent> child =
3181 make_scoped_refptr(new LayerWithForcedDrawsContent());
3182 root->AddChild(child);
3183
[email protected]d600df7d2013-08-03 02:34:283184 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3185 host->SetRootLayer(root);
3186
[email protected]630ddad2013-08-16 03:01:323187 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473188 gfx::Transform identity_matrix;
3189 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323190 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473191
3192 SetLayerPropertiesForTesting(root.get(),
3193 identity_matrix,
3194 identity_matrix,
3195 gfx::PointF(),
3196 gfx::PointF(),
3197 gfx::Size(100, 100),
3198 false);
3199 SetLayerPropertiesForTesting(child.get(),
3200 uninvertible_matrix,
3201 identity_matrix,
3202 gfx::PointF(),
3203 gfx::PointF(5.f, 5.f),
3204 gfx::Size(50, 50),
3205 false);
3206
3207 ExecuteCalculateDrawProperties(root.get());
3208
3209 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
3210 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323211
3212 // Case 2: a matrix with flattened z, technically uninvertible but still
3213 // drawable and visible. In this case, we must assume that the entire layer
3214 // bounds are visible since there is no way to inverse-project the surface
3215 // bounds to intersect.
3216 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263217 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323218 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3219
3220 SetLayerPropertiesForTesting(child.get(),
3221 uninvertible_matrix,
3222 identity_matrix,
3223 gfx::PointF(),
3224 gfx::PointF(5.f, 5.f),
3225 gfx::Size(50, 50),
3226 false);
3227
3228 ExecuteCalculateDrawProperties(root.get());
3229
3230 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child->visible_content_rect());
3231 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child->drawable_content_rect());
3232
3233 // Case 3: a matrix with flattened z, technically uninvertible but still
3234 // drawable, but not visible. In this case, we don't need to conservatively
3235 // assume that the whole layer is visible.
3236 uninvertible_matrix.MakeIdentity();
3237 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263238 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323239 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3240
3241 SetLayerPropertiesForTesting(child.get(),
3242 uninvertible_matrix,
3243 identity_matrix,
3244 gfx::PointF(),
3245 gfx::PointF(5.f, 5.f),
3246 gfx::Size(50, 50),
3247 false);
3248
3249 ExecuteCalculateDrawProperties(root.get());
3250
3251 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
3252 EXPECT_RECT_EQ(gfx::Rect(505, 5, 50, 50), child->drawable_content_rect());
[email protected]451107a32013-04-10 05:12:473253}
3254
[email protected]989386c2013-07-18 21:37:233255TEST_F(LayerTreeHostCommonTest,
3256 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:323257 scoped_refptr<Layer> root = Layer::Create();
3258 scoped_refptr<Layer> render_surface1 = Layer::Create();
3259 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3260 make_scoped_refptr(new LayerWithForcedDrawsContent());
3261 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3262 make_scoped_refptr(new LayerWithForcedDrawsContent());
3263 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3264 make_scoped_refptr(new LayerWithForcedDrawsContent());
3265 root->AddChild(render_surface1);
3266 render_surface1->AddChild(child1);
3267 render_surface1->AddChild(child2);
3268 render_surface1->AddChild(child3);
3269
[email protected]d600df7d2013-08-03 02:34:283270 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3271 host->SetRootLayer(root);
3272
[email protected]fb661802013-03-25 01:59:323273 gfx::Transform identity_matrix;
3274 SetLayerPropertiesForTesting(root.get(),
3275 identity_matrix,
3276 identity_matrix,
3277 gfx::PointF(),
3278 gfx::PointF(),
3279 gfx::Size(100, 100),
3280 false);
3281 SetLayerPropertiesForTesting(render_surface1.get(),
3282 identity_matrix,
3283 identity_matrix,
3284 gfx::PointF(),
3285 gfx::PointF(),
3286 gfx::Size(3, 4),
3287 false);
3288 SetLayerPropertiesForTesting(child1.get(),
3289 identity_matrix,
3290 identity_matrix,
3291 gfx::PointF(),
3292 gfx::PointF(5.f, 5.f),
3293 gfx::Size(50, 50),
3294 false);
3295 SetLayerPropertiesForTesting(child2.get(),
3296 identity_matrix,
3297 identity_matrix,
3298 gfx::PointF(),
3299 gfx::PointF(75.f, 75.f),
3300 gfx::Size(50, 50),
3301 false);
3302 SetLayerPropertiesForTesting(child3.get(),
3303 identity_matrix,
3304 identity_matrix,
3305 gfx::PointF(),
3306 gfx::PointF(125.f, 125.f),
3307 gfx::Size(50, 50),
3308 false);
3309
3310 root->SetMasksToBounds(true);
3311 render_surface1->SetForceRenderSurface(true);
3312 ExecuteCalculateDrawProperties(root.get());
3313
3314 ASSERT_TRUE(render_surface1->render_surface());
3315
3316 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3317 root->render_surface()->DrawableContentRect());
3318 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3319
3320 // Layers that do not draw content should have empty visible content rects.
3321 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3322 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3323 render_surface1->visible_content_rect());
3324
3325 // A clipped surface grows its DrawableContentRect to include all drawable
3326 // regions of the subtree, but also gets clamped by the ancestor's clip.
3327 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3328 render_surface1->render_surface()->DrawableContentRect());
3329
3330 // All layers that draw content into the surface have their visible content
3331 // rect clipped by the surface clip rect.
3332 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3333 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
3334 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3335
3336 // But the DrawableContentRects are unclipped.
3337 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3338 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3339 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3340}
3341
[email protected]989386c2013-07-18 21:37:233342TEST_F(LayerTreeHostCommonTest,
3343 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323344 // Check that clipping does not propagate down surfaces.
3345 scoped_refptr<Layer> root = Layer::Create();
3346 scoped_refptr<Layer> render_surface1 = Layer::Create();
3347 scoped_refptr<Layer> render_surface2 = Layer::Create();
3348 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3349 make_scoped_refptr(new LayerWithForcedDrawsContent());
3350 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3351 make_scoped_refptr(new LayerWithForcedDrawsContent());
3352 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3353 make_scoped_refptr(new LayerWithForcedDrawsContent());
3354 root->AddChild(render_surface1);
3355 render_surface1->AddChild(render_surface2);
3356 render_surface2->AddChild(child1);
3357 render_surface2->AddChild(child2);
3358 render_surface2->AddChild(child3);
3359
[email protected]d600df7d2013-08-03 02:34:283360 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3361 host->SetRootLayer(root);
3362
[email protected]fb661802013-03-25 01:59:323363 gfx::Transform identity_matrix;
3364 SetLayerPropertiesForTesting(root.get(),
3365 identity_matrix,
3366 identity_matrix,
3367 gfx::PointF(),
3368 gfx::PointF(),
3369 gfx::Size(100, 100),
3370 false);
3371 SetLayerPropertiesForTesting(render_surface1.get(),
3372 identity_matrix,
3373 identity_matrix,
3374 gfx::PointF(),
3375 gfx::PointF(),
3376 gfx::Size(3, 4),
3377 false);
3378 SetLayerPropertiesForTesting(render_surface2.get(),
3379 identity_matrix,
3380 identity_matrix,
3381 gfx::PointF(),
3382 gfx::PointF(),
3383 gfx::Size(7, 13),
3384 false);
3385 SetLayerPropertiesForTesting(child1.get(),
3386 identity_matrix,
3387 identity_matrix,
3388 gfx::PointF(),
3389 gfx::PointF(5.f, 5.f),
3390 gfx::Size(50, 50),
3391 false);
3392 SetLayerPropertiesForTesting(child2.get(),
3393 identity_matrix,
3394 identity_matrix,
3395 gfx::PointF(),
3396 gfx::PointF(75.f, 75.f),
3397 gfx::Size(50, 50),
3398 false);
3399 SetLayerPropertiesForTesting(child3.get(),
3400 identity_matrix,
3401 identity_matrix,
3402 gfx::PointF(),
3403 gfx::PointF(125.f, 125.f),
3404 gfx::Size(50, 50),
3405 false);
3406
3407 root->SetMasksToBounds(true);
3408 render_surface1->SetForceRenderSurface(true);
3409 render_surface2->SetForceRenderSurface(true);
3410 ExecuteCalculateDrawProperties(root.get());
3411
3412 ASSERT_TRUE(render_surface1->render_surface());
3413 ASSERT_TRUE(render_surface2->render_surface());
3414
3415 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3416 root->render_surface()->DrawableContentRect());
3417 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3418
3419 // Layers that do not draw content should have empty visible content rects.
3420 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3421 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3422 render_surface1->visible_content_rect());
3423 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3424 render_surface2->visible_content_rect());
3425
3426 // A clipped surface grows its DrawableContentRect to include all drawable
3427 // regions of the subtree, but also gets clamped by the ancestor's clip.
3428 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3429 render_surface1->render_surface()->DrawableContentRect());
3430
3431 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3432 // is only implicitly clipped by render_surface1's content rect. So,
3433 // render_surface2 grows to enclose all drawable content of its subtree.
3434 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3435 render_surface2->render_surface()->DrawableContentRect());
3436
3437 // All layers that draw content into render_surface2 think they are unclipped.
3438 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3439 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3440 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
3441
3442 // DrawableContentRects are also unclipped.
3443 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3444 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3445 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3446}
3447
[email protected]989386c2013-07-18 21:37:233448TEST_F(LayerTreeHostCommonTest,
3449 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323450 // Layers that have non-axis aligned bounds (due to transforms) have an
3451 // expanded, axis-aligned DrawableContentRect and visible content rect.
3452
3453 scoped_refptr<Layer> root = Layer::Create();
3454 scoped_refptr<Layer> render_surface1 = Layer::Create();
3455 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3456 make_scoped_refptr(new LayerWithForcedDrawsContent());
3457 root->AddChild(render_surface1);
3458 render_surface1->AddChild(child1);
3459
[email protected]d600df7d2013-08-03 02:34:283460 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3461 host->SetRootLayer(root);
3462
[email protected]fb661802013-03-25 01:59:323463 gfx::Transform identity_matrix;
3464 gfx::Transform child_rotation;
3465 child_rotation.Rotate(45.0);
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(),
3478 gfx::Size(3, 4),
3479 false);
3480 SetLayerPropertiesForTesting(child1.get(),
3481 child_rotation,
3482 identity_matrix,
3483 gfx::PointF(0.5f, 0.5f),
3484 gfx::PointF(25.f, 25.f),
3485 gfx::Size(50, 50),
3486 false);
3487
3488 render_surface1->SetForceRenderSurface(true);
3489 ExecuteCalculateDrawProperties(root.get());
3490
3491 ASSERT_TRUE(render_surface1->render_surface());
3492
3493 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3494 root->render_surface()->DrawableContentRect());
3495 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3496
3497 // Layers that do not draw content should have empty visible content rects.
3498 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3499 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3500 render_surface1->visible_content_rect());
3501
3502 // The unclipped surface grows its DrawableContentRect to include all drawable
3503 // regions of the subtree.
3504 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3505 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263506 gfx::Rect(50 - diagonal_radius,
3507 50 - diagonal_radius,
3508 diagonal_radius * 2,
3509 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323510 EXPECT_RECT_EQ(expected_surface_drawable_content,
3511 render_surface1->render_surface()->DrawableContentRect());
3512
3513 // All layers that draw content into the unclipped surface are also unclipped.
3514 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3515 EXPECT_RECT_EQ(expected_surface_drawable_content,
3516 child1->drawable_content_rect());
3517}
3518
[email protected]989386c2013-07-18 21:37:233519TEST_F(LayerTreeHostCommonTest,
3520 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323521 // Layers that have non-axis aligned bounds (due to transforms) have an
3522 // expanded, axis-aligned DrawableContentRect and visible content rect.
3523
3524 scoped_refptr<Layer> root = Layer::Create();
3525 scoped_refptr<Layer> render_surface1 = Layer::Create();
3526 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3527 make_scoped_refptr(new LayerWithForcedDrawsContent());
3528 root->AddChild(render_surface1);
3529 render_surface1->AddChild(child1);
3530
[email protected]d600df7d2013-08-03 02:34:283531 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3532 host->SetRootLayer(root);
3533
[email protected]fb661802013-03-25 01:59:323534 gfx::Transform identity_matrix;
3535 gfx::Transform child_rotation;
3536 child_rotation.Rotate(45.0);
3537 SetLayerPropertiesForTesting(root.get(),
3538 identity_matrix,
3539 identity_matrix,
3540 gfx::PointF(),
3541 gfx::PointF(),
3542 gfx::Size(50, 50),
3543 false);
3544 SetLayerPropertiesForTesting(render_surface1.get(),
3545 identity_matrix,
3546 identity_matrix,
3547 gfx::PointF(),
3548 gfx::PointF(),
3549 gfx::Size(3, 4),
3550 false);
3551 SetLayerPropertiesForTesting(child1.get(),
3552 child_rotation,
3553 identity_matrix,
3554 gfx::PointF(0.5f, 0.5f),
3555 gfx::PointF(25.f, 25.f),
3556 gfx::Size(50, 50),
3557 false);
3558
3559 root->SetMasksToBounds(true);
3560 render_surface1->SetForceRenderSurface(true);
3561 ExecuteCalculateDrawProperties(root.get());
3562
3563 ASSERT_TRUE(render_surface1->render_surface());
3564
3565 // The clipped surface clamps the DrawableContentRect that encloses the
3566 // rotated layer.
3567 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263568 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3569 50 - diagonal_radius,
3570 diagonal_radius * 2,
3571 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323572 gfx::Rect expected_surface_drawable_content =
3573 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
3574 EXPECT_RECT_EQ(expected_surface_drawable_content,
3575 render_surface1->render_surface()->DrawableContentRect());
3576
3577 // On the clipped surface, only a quarter of the child1 is visible, but when
3578 // rotating it back to child1's content space, the actual enclosing rect ends
3579 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263580 //
3581 // Given the floating point math, this number is a little bit fuzzy.
[email protected]fb661802013-03-25 01:59:323582 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
3583
3584 // The child's DrawableContentRect is unclipped.
3585 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3586}
3587
[email protected]989386c2013-07-18 21:37:233588TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323589 MockContentLayerClient client;
3590
3591 scoped_refptr<Layer> root = Layer::Create();
3592 scoped_refptr<ContentLayer> render_surface1 =
3593 CreateDrawableContentLayer(&client);
3594 scoped_refptr<ContentLayer> render_surface2 =
3595 CreateDrawableContentLayer(&client);
3596 scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client);
3597 scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client);
3598 scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client);
3599 root->AddChild(render_surface1);
3600 render_surface1->AddChild(render_surface2);
3601 render_surface2->AddChild(child1);
3602 render_surface2->AddChild(child2);
3603 render_surface2->AddChild(child3);
3604
[email protected]d600df7d2013-08-03 02:34:283605 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3606 host->SetRootLayer(root);
3607
[email protected]fb661802013-03-25 01:59:323608 gfx::Transform identity_matrix;
3609 SetLayerPropertiesForTesting(root.get(),
3610 identity_matrix,
3611 identity_matrix,
3612 gfx::PointF(),
3613 gfx::PointF(),
3614 gfx::Size(100, 100),
3615 false);
3616 SetLayerPropertiesForTesting(render_surface1.get(),
3617 identity_matrix,
3618 identity_matrix,
3619 gfx::PointF(),
3620 gfx::PointF(5.f, 5.f),
3621 gfx::Size(3, 4),
3622 false);
3623 SetLayerPropertiesForTesting(render_surface2.get(),
3624 identity_matrix,
3625 identity_matrix,
3626 gfx::PointF(),
3627 gfx::PointF(5.f, 5.f),
3628 gfx::Size(7, 13),
3629 false);
3630 SetLayerPropertiesForTesting(child1.get(),
3631 identity_matrix,
3632 identity_matrix,
3633 gfx::PointF(),
3634 gfx::PointF(5.f, 5.f),
3635 gfx::Size(50, 50),
3636 false);
3637 SetLayerPropertiesForTesting(child2.get(),
3638 identity_matrix,
3639 identity_matrix,
3640 gfx::PointF(),
3641 gfx::PointF(75.f, 75.f),
3642 gfx::Size(50, 50),
3643 false);
3644 SetLayerPropertiesForTesting(child3.get(),
3645 identity_matrix,
3646 identity_matrix,
3647 gfx::PointF(),
3648 gfx::PointF(125.f, 125.f),
3649 gfx::Size(50, 50),
3650 false);
3651
3652 float device_scale_factor = 2.f;
3653
3654 root->SetMasksToBounds(true);
3655 render_surface1->SetForceRenderSurface(true);
3656 render_surface2->SetForceRenderSurface(true);
3657 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3658
3659 ASSERT_TRUE(render_surface1->render_surface());
3660 ASSERT_TRUE(render_surface2->render_surface());
3661
3662 // drawable_content_rects for all layers and surfaces are scaled by
3663 // device_scale_factor.
3664 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3665 root->render_surface()->DrawableContentRect());
3666 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3667 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3668 render_surface1->render_surface()->DrawableContentRect());
3669
3670 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3671 // is only implicitly clipped by render_surface1.
3672 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3673 render_surface2->render_surface()->DrawableContentRect());
3674
3675 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3676 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3677 child2->drawable_content_rect());
3678 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3679 child3->drawable_content_rect());
3680
3681 // The root layer does not actually draw content of its own.
3682 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3683
3684 // All layer visible content rects are expressed in content space of each
3685 // layer, so they are also scaled by the device_scale_factor.
3686 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8),
3687 render_surface1->visible_content_rect());
3688 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26),
3689 render_surface2->visible_content_rect());
3690 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect());
3691 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect());
3692 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect());
3693}
3694
[email protected]989386c2013-07-18 21:37:233695TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323696 // Verify the behavior of back-face culling when there are no preserve-3d
3697 // layers. Note that 3d transforms still apply in this case, but they are
3698 // "flattened" to each parent layer according to current W3C spec.
3699
3700 const gfx::Transform identity_matrix;
3701 scoped_refptr<Layer> parent = Layer::Create();
3702 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3703 make_scoped_refptr(new LayerWithForcedDrawsContent());
3704 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3705 make_scoped_refptr(new LayerWithForcedDrawsContent());
3706 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3707 make_scoped_refptr(new LayerWithForcedDrawsContent());
3708 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3709 make_scoped_refptr(new LayerWithForcedDrawsContent());
3710 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233711 front_facing_child_of_front_facing_surface =
3712 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323713 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233714 back_facing_child_of_front_facing_surface =
3715 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323716 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233717 front_facing_child_of_back_facing_surface =
3718 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323719 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233720 back_facing_child_of_back_facing_surface =
3721 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323722
3723 parent->AddChild(front_facing_child);
3724 parent->AddChild(back_facing_child);
3725 parent->AddChild(front_facing_surface);
3726 parent->AddChild(back_facing_surface);
3727 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3728 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3729 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3730 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3731
[email protected]d600df7d2013-08-03 02:34:283732 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3733 host->SetRootLayer(parent);
3734
[email protected]fb661802013-03-25 01:59:323735 // Nothing is double-sided
3736 front_facing_child->SetDoubleSided(false);
3737 back_facing_child->SetDoubleSided(false);
3738 front_facing_surface->SetDoubleSided(false);
3739 back_facing_surface->SetDoubleSided(false);
3740 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3741 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3742 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3743 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3744
3745 gfx::Transform backface_matrix;
3746 backface_matrix.Translate(50.0, 50.0);
3747 backface_matrix.RotateAboutYAxis(180.0);
3748 backface_matrix.Translate(-50.0, -50.0);
3749
3750 // Having a descendant and opacity will force these to have render surfaces.
3751 front_facing_surface->SetOpacity(0.5f);
3752 back_facing_surface->SetOpacity(0.5f);
3753
3754 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3755 // these layers should blindly use their own local transforms to determine
3756 // back-face culling.
3757 SetLayerPropertiesForTesting(parent.get(),
3758 identity_matrix,
3759 identity_matrix,
3760 gfx::PointF(),
3761 gfx::PointF(),
3762 gfx::Size(100, 100),
3763 false);
3764 SetLayerPropertiesForTesting(front_facing_child.get(),
3765 identity_matrix,
3766 identity_matrix,
3767 gfx::PointF(),
3768 gfx::PointF(),
3769 gfx::Size(100, 100),
3770 false);
3771 SetLayerPropertiesForTesting(back_facing_child.get(),
3772 backface_matrix,
3773 identity_matrix,
3774 gfx::PointF(),
3775 gfx::PointF(),
3776 gfx::Size(100, 100),
3777 false);
3778 SetLayerPropertiesForTesting(front_facing_surface.get(),
3779 identity_matrix,
3780 identity_matrix,
3781 gfx::PointF(),
3782 gfx::PointF(),
3783 gfx::Size(100, 100),
3784 false);
3785 SetLayerPropertiesForTesting(back_facing_surface.get(),
3786 backface_matrix,
3787 identity_matrix,
3788 gfx::PointF(),
3789 gfx::PointF(),
3790 gfx::Size(100, 100),
3791 false);
3792 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3793 identity_matrix,
3794 identity_matrix,
3795 gfx::PointF(),
3796 gfx::PointF(),
3797 gfx::Size(100, 100),
3798 false);
3799 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3800 backface_matrix,
3801 identity_matrix,
3802 gfx::PointF(),
3803 gfx::PointF(),
3804 gfx::Size(100, 100),
3805 false);
3806 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3807 identity_matrix,
3808 identity_matrix,
3809 gfx::PointF(),
3810 gfx::PointF(),
3811 gfx::Size(100, 100),
3812 false);
3813 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3814 backface_matrix,
3815 identity_matrix,
3816 gfx::PointF(),
3817 gfx::PointF(),
3818 gfx::Size(100, 100),
3819 false);
3820
[email protected]989386c2013-07-18 21:37:233821 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533822 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3823 parent.get(), parent->bounds(), &render_surface_layer_list);
3824 inputs.can_adjust_raster_scales = true;
3825 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323826
3827 // Verify which render surfaces were created.
3828 EXPECT_FALSE(front_facing_child->render_surface());
3829 EXPECT_FALSE(back_facing_child->render_surface());
3830 EXPECT_TRUE(front_facing_surface->render_surface());
3831 EXPECT_TRUE(back_facing_surface->render_surface());
3832 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3833 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3834 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3835 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3836
3837 // Verify the render_surface_layer_list.
3838 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233839 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3840 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323841 // Even though the back facing surface LAYER gets culled, the other
3842 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233843 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323844
3845 // Verify root surface's layer list.
3846 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233847 3u,
3848 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3849 EXPECT_EQ(front_facing_child->id(),
3850 render_surface_layer_list.at(0)
3851 ->render_surface()->layer_list().at(0)->id());
3852 EXPECT_EQ(front_facing_surface->id(),
3853 render_surface_layer_list.at(0)
3854 ->render_surface()->layer_list().at(1)->id());
3855 EXPECT_EQ(back_facing_surface->id(),
3856 render_surface_layer_list.at(0)
3857 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:323858
3859 // Verify front_facing_surface's layer list.
3860 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233861 2u,
3862 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3863 EXPECT_EQ(front_facing_surface->id(),
3864 render_surface_layer_list.at(1)
3865 ->render_surface()->layer_list().at(0)->id());
3866 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3867 render_surface_layer_list.at(1)
3868 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323869
3870 // Verify back_facing_surface's layer list; its own layer should be culled
3871 // from the surface list.
3872 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233873 1u,
3874 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3875 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3876 render_surface_layer_list.at(2)
3877 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:323878}
3879
[email protected]989386c2013-07-18 21:37:233880TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323881 // Verify the behavior of back-face culling when preserves-3d transform style
3882 // is used.
3883
3884 const gfx::Transform identity_matrix;
3885 scoped_refptr<Layer> parent = Layer::Create();
3886 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3887 make_scoped_refptr(new LayerWithForcedDrawsContent());
3888 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3889 make_scoped_refptr(new LayerWithForcedDrawsContent());
3890 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3891 make_scoped_refptr(new LayerWithForcedDrawsContent());
3892 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3893 make_scoped_refptr(new LayerWithForcedDrawsContent());
3894 scoped_refptr<LayerWithForcedDrawsContent>
3895 front_facing_child_of_front_facing_surface =
3896 make_scoped_refptr(new LayerWithForcedDrawsContent());
3897 scoped_refptr<LayerWithForcedDrawsContent>
3898 back_facing_child_of_front_facing_surface =
3899 make_scoped_refptr(new LayerWithForcedDrawsContent());
3900 scoped_refptr<LayerWithForcedDrawsContent>
3901 front_facing_child_of_back_facing_surface =
3902 make_scoped_refptr(new LayerWithForcedDrawsContent());
3903 scoped_refptr<LayerWithForcedDrawsContent>
3904 back_facing_child_of_back_facing_surface =
3905 make_scoped_refptr(new LayerWithForcedDrawsContent());
3906 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3907 make_scoped_refptr(new LayerWithForcedDrawsContent());
3908 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3909 make_scoped_refptr(new LayerWithForcedDrawsContent());
3910
3911 parent->AddChild(front_facing_child);
3912 parent->AddChild(back_facing_child);
3913 parent->AddChild(front_facing_surface);
3914 parent->AddChild(back_facing_surface);
3915 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3916 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3917 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3918 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3919
[email protected]d600df7d2013-08-03 02:34:283920 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3921 host->SetRootLayer(parent);
3922
[email protected]fb661802013-03-25 01:59:323923 // Nothing is double-sided
3924 front_facing_child->SetDoubleSided(false);
3925 back_facing_child->SetDoubleSided(false);
3926 front_facing_surface->SetDoubleSided(false);
3927 back_facing_surface->SetDoubleSided(false);
3928 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3929 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3930 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3931 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3932
3933 gfx::Transform backface_matrix;
3934 backface_matrix.Translate(50.0, 50.0);
3935 backface_matrix.RotateAboutYAxis(180.0);
3936 backface_matrix.Translate(-50.0, -50.0);
3937
3938 // Opacity will not force creation of render surfaces in this case because of
3939 // the preserve-3d transform style. Instead, an example of when a surface
3940 // would be created with preserve-3d is when there is a replica layer.
3941 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3942 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3943
3944 // Each surface creates its own new 3d rendering context (as defined by W3C
3945 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3946 // rendering context should use the transform with respect to that context.
3947 // This 3d rendering context occurs when (a) parent's transform style is flat
3948 // and (b) the layer's transform style is preserve-3d.
3949 SetLayerPropertiesForTesting(parent.get(),
3950 identity_matrix,
3951 identity_matrix,
3952 gfx::PointF(),
3953 gfx::PointF(),
3954 gfx::Size(100, 100),
3955 false); // parent transform style is flat.
3956 SetLayerPropertiesForTesting(front_facing_child.get(),
3957 identity_matrix,
3958 identity_matrix,
3959 gfx::PointF(),
3960 gfx::PointF(),
3961 gfx::Size(100, 100),
3962 false);
3963 SetLayerPropertiesForTesting(back_facing_child.get(),
3964 backface_matrix,
3965 identity_matrix,
3966 gfx::PointF(),
3967 gfx::PointF(),
3968 gfx::Size(100, 100),
3969 false);
3970 SetLayerPropertiesForTesting(
3971 front_facing_surface.get(),
3972 identity_matrix,
3973 identity_matrix,
3974 gfx::PointF(),
3975 gfx::PointF(),
3976 gfx::Size(100, 100),
3977 true); // surface transform style is preserve-3d.
3978 SetLayerPropertiesForTesting(
3979 back_facing_surface.get(),
3980 backface_matrix,
3981 identity_matrix,
3982 gfx::PointF(),
3983 gfx::PointF(),
3984 gfx::Size(100, 100),
3985 true); // surface transform style is preserve-3d.
3986 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3987 identity_matrix,
3988 identity_matrix,
3989 gfx::PointF(),
3990 gfx::PointF(),
3991 gfx::Size(100, 100),
3992 false);
3993 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3994 backface_matrix,
3995 identity_matrix,
3996 gfx::PointF(),
3997 gfx::PointF(),
3998 gfx::Size(100, 100),
3999 false);
4000 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
4001 identity_matrix,
4002 identity_matrix,
4003 gfx::PointF(),
4004 gfx::PointF(),
4005 gfx::Size(100, 100),
4006 false);
4007 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
4008 backface_matrix,
4009 identity_matrix,
4010 gfx::PointF(),
4011 gfx::PointF(),
4012 gfx::Size(100, 100),
4013 false);
4014
[email protected]989386c2013-07-18 21:37:234015 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534016 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4017 parent.get(), parent->bounds(), &render_surface_layer_list);
4018 inputs.can_adjust_raster_scales = true;
4019 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324020
4021 // Verify which render surfaces were created.
4022 EXPECT_FALSE(front_facing_child->render_surface());
4023 EXPECT_FALSE(back_facing_child->render_surface());
4024 EXPECT_TRUE(front_facing_surface->render_surface());
4025 EXPECT_FALSE(back_facing_surface->render_surface());
4026 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
4027 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
4028 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
4029 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
4030
4031 // Verify the render_surface_layer_list. The back-facing surface should be
4032 // culled.
4033 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234034 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4035 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324036
4037 // Verify root surface's layer list.
4038 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234039 2u,
4040 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4041 EXPECT_EQ(front_facing_child->id(),
4042 render_surface_layer_list.at(0)
4043 ->render_surface()->layer_list().at(0)->id());
4044 EXPECT_EQ(front_facing_surface->id(),
4045 render_surface_layer_list.at(0)
4046 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324047
4048 // Verify front_facing_surface's layer list.
4049 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234050 2u,
4051 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4052 EXPECT_EQ(front_facing_surface->id(),
4053 render_surface_layer_list.at(1)
4054 ->render_surface()->layer_list().at(0)->id());
4055 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
4056 render_surface_layer_list.at(1)
4057 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324058}
4059
[email protected]989386c2013-07-18 21:37:234060TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324061 // Verify that layers are appropriately culled when their back face is showing
4062 // and they are not double sided, while animations are going on.
4063 //
4064 // Layers that are animating do not get culled on the main thread, as their
4065 // transforms should be treated as "unknown" so we can not be sure that their
4066 // back face is really showing.
4067 const gfx::Transform identity_matrix;
4068 scoped_refptr<Layer> parent = Layer::Create();
4069 scoped_refptr<LayerWithForcedDrawsContent> child =
4070 make_scoped_refptr(new LayerWithForcedDrawsContent());
4071 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
4072 make_scoped_refptr(new LayerWithForcedDrawsContent());
4073 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
4074 make_scoped_refptr(new LayerWithForcedDrawsContent());
4075 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
4076 make_scoped_refptr(new LayerWithForcedDrawsContent());
4077 scoped_refptr<LayerWithForcedDrawsContent> child2 =
4078 make_scoped_refptr(new LayerWithForcedDrawsContent());
4079
4080 parent->AddChild(child);
4081 parent->AddChild(animating_surface);
4082 animating_surface->AddChild(child_of_animating_surface);
4083 parent->AddChild(animating_child);
4084 parent->AddChild(child2);
4085
[email protected]d600df7d2013-08-03 02:34:284086 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4087 host->SetRootLayer(parent);
4088
[email protected]fb661802013-03-25 01:59:324089 // Nothing is double-sided
4090 child->SetDoubleSided(false);
4091 child2->SetDoubleSided(false);
4092 animating_surface->SetDoubleSided(false);
4093 child_of_animating_surface->SetDoubleSided(false);
4094 animating_child->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 // Make our render surface.
4102 animating_surface->SetForceRenderSurface(true);
4103
4104 // Animate the transform on the render surface.
4105 AddAnimatedTransformToController(
4106 animating_surface->layer_animation_controller(), 10.0, 30, 0);
4107 // This is just an animating layer, not a surface.
4108 AddAnimatedTransformToController(
4109 animating_child->layer_animation_controller(), 10.0, 30, 0);
4110
4111 SetLayerPropertiesForTesting(parent.get(),
4112 identity_matrix,
4113 identity_matrix,
4114 gfx::PointF(),
4115 gfx::PointF(),
4116 gfx::Size(100, 100),
4117 false);
4118 SetLayerPropertiesForTesting(child.get(),
4119 backface_matrix,
4120 identity_matrix,
4121 gfx::PointF(),
4122 gfx::PointF(),
4123 gfx::Size(100, 100),
4124 false);
4125 SetLayerPropertiesForTesting(animating_surface.get(),
4126 backface_matrix,
4127 identity_matrix,
4128 gfx::PointF(),
4129 gfx::PointF(),
4130 gfx::Size(100, 100),
4131 false);
4132 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
4133 backface_matrix,
4134 identity_matrix,
4135 gfx::PointF(),
4136 gfx::PointF(),
4137 gfx::Size(100, 100),
4138 false);
4139 SetLayerPropertiesForTesting(animating_child.get(),
4140 backface_matrix,
4141 identity_matrix,
4142 gfx::PointF(),
4143 gfx::PointF(),
4144 gfx::Size(100, 100),
4145 false);
4146 SetLayerPropertiesForTesting(child2.get(),
4147 identity_matrix,
4148 identity_matrix,
4149 gfx::PointF(),
4150 gfx::PointF(),
4151 gfx::Size(100, 100),
4152 false);
4153
[email protected]989386c2013-07-18 21:37:234154 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534155 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4156 parent.get(), parent->bounds(), &render_surface_layer_list);
4157 inputs.can_adjust_raster_scales = true;
4158 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324159
4160 EXPECT_FALSE(child->render_surface());
4161 EXPECT_TRUE(animating_surface->render_surface());
4162 EXPECT_FALSE(child_of_animating_surface->render_surface());
4163 EXPECT_FALSE(animating_child->render_surface());
4164 EXPECT_FALSE(child2->render_surface());
4165
4166 // Verify that the animating_child and child_of_animating_surface were not
4167 // culled, but that child was.
4168 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234169 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4170 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324171
4172 // The non-animating child be culled from the layer list for the parent render
4173 // surface.
4174 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234175 3u,
4176 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4177 EXPECT_EQ(animating_surface->id(),
4178 render_surface_layer_list.at(0)
4179 ->render_surface()->layer_list().at(0)->id());
4180 EXPECT_EQ(animating_child->id(),
4181 render_surface_layer_list.at(0)
4182 ->render_surface()->layer_list().at(1)->id());
4183 EXPECT_EQ(child2->id(),
4184 render_surface_layer_list.at(0)
4185 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:324186
4187 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234188 2u,
4189 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4190 EXPECT_EQ(animating_surface->id(),
4191 render_surface_layer_list.at(1)
4192 ->render_surface()->layer_list().at(0)->id());
4193 EXPECT_EQ(child_of_animating_surface->id(),
4194 render_surface_layer_list.at(1)
4195 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324196
4197 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
4198
4199 // The animating layers should have a visible content rect that represents the
4200 // area of the front face that is within the viewport.
4201 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054202 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:324203 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054204 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324205 // And layers in the subtree of the animating layer should have valid visible
4206 // content rects also.
[email protected]989386c2013-07-18 21:37:234207 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
4208 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324209}
4210
[email protected]989386c2013-07-18 21:37:234211TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324212 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4213 // Verify the behavior of back-face culling for a render surface that is
4214 // created when it flattens its subtree, and its parent has preserves-3d.
4215
4216 const gfx::Transform identity_matrix;
4217 scoped_refptr<Layer> parent = Layer::Create();
4218 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
4219 make_scoped_refptr(new LayerWithForcedDrawsContent());
4220 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
4221 make_scoped_refptr(new LayerWithForcedDrawsContent());
4222 scoped_refptr<LayerWithForcedDrawsContent> child1 =
4223 make_scoped_refptr(new LayerWithForcedDrawsContent());
4224 scoped_refptr<LayerWithForcedDrawsContent> child2 =
4225 make_scoped_refptr(new LayerWithForcedDrawsContent());
4226
4227 parent->AddChild(front_facing_surface);
4228 parent->AddChild(back_facing_surface);
4229 front_facing_surface->AddChild(child1);
4230 back_facing_surface->AddChild(child2);
4231
[email protected]d600df7d2013-08-03 02:34:284232 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4233 host->SetRootLayer(parent);
4234
[email protected]fb661802013-03-25 01:59:324235 // RenderSurfaces are not double-sided
4236 front_facing_surface->SetDoubleSided(false);
4237 back_facing_surface->SetDoubleSided(false);
4238
4239 gfx::Transform backface_matrix;
4240 backface_matrix.Translate(50.0, 50.0);
4241 backface_matrix.RotateAboutYAxis(180.0);
4242 backface_matrix.Translate(-50.0, -50.0);
4243
4244 SetLayerPropertiesForTesting(parent.get(),
4245 identity_matrix,
4246 identity_matrix,
4247 gfx::PointF(),
4248 gfx::PointF(),
4249 gfx::Size(100, 100),
4250 true); // parent transform style is preserve3d.
4251 SetLayerPropertiesForTesting(front_facing_surface.get(),
4252 identity_matrix,
4253 identity_matrix,
4254 gfx::PointF(),
4255 gfx::PointF(),
4256 gfx::Size(100, 100),
4257 false); // surface transform style is flat.
4258 SetLayerPropertiesForTesting(back_facing_surface.get(),
4259 backface_matrix,
4260 identity_matrix,
4261 gfx::PointF(),
4262 gfx::PointF(),
4263 gfx::Size(100, 100),
4264 false); // surface transform style is flat.
4265 SetLayerPropertiesForTesting(child1.get(),
4266 identity_matrix,
4267 identity_matrix,
4268 gfx::PointF(),
4269 gfx::PointF(),
4270 gfx::Size(100, 100),
4271 false);
4272 SetLayerPropertiesForTesting(child2.get(),
4273 identity_matrix,
4274 identity_matrix,
4275 gfx::PointF(),
4276 gfx::PointF(),
4277 gfx::Size(100, 100),
4278 false);
4279
[email protected]989386c2013-07-18 21:37:234280 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534281 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4282 parent.get(), parent->bounds(), &render_surface_layer_list);
4283 inputs.can_adjust_raster_scales = true;
4284 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324285
4286 // Verify which render surfaces were created.
4287 EXPECT_TRUE(front_facing_surface->render_surface());
4288 EXPECT_FALSE(
4289 back_facing_surface->render_surface()); // because it should be culled
4290 EXPECT_FALSE(child1->render_surface());
4291 EXPECT_FALSE(child2->render_surface());
4292
4293 // Verify the render_surface_layer_list. The back-facing surface should be
4294 // culled.
4295 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234296 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4297 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324298
4299 // Verify root surface's layer list.
4300 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234301 1u,
4302 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4303 EXPECT_EQ(front_facing_surface->id(),
4304 render_surface_layer_list.at(0)
4305 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324306
4307 // Verify front_facing_surface's layer list.
4308 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234309 2u,
4310 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4311 EXPECT_EQ(front_facing_surface->id(),
4312 render_surface_layer_list.at(1)
4313 ->render_surface()->layer_list().at(0)->id());
4314 EXPECT_EQ(child1->id(),
4315 render_surface_layer_list.at(1)
4316 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324317}
4318
[email protected]989386c2013-07-18 21:37:234319
4320TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:324321 // Hit testing on an empty render_surface_layer_list should return a null
4322 // pointer.
[email protected]50761e92013-03-29 20:51:284323 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:324324
4325 gfx::Point test_point(0, 0);
4326 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4327 test_point, render_surface_layer_list);
4328 EXPECT_FALSE(result_layer);
4329
4330 test_point = gfx::Point(10, 20);
4331 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4332 test_point, render_surface_layer_list);
4333 EXPECT_FALSE(result_layer);
4334}
4335
[email protected]989386c2013-07-18 21:37:234336TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayer) {
[email protected]fb661802013-03-25 01:59:324337 FakeImplProxy proxy;
4338 FakeLayerTreeHostImpl host_impl(&proxy);
4339 scoped_ptr<LayerImpl> root =
4340 LayerImpl::Create(host_impl.active_tree(), 12345);
4341
4342 gfx::Transform identity_matrix;
4343 gfx::PointF anchor;
4344 gfx::PointF position;
4345 gfx::Size bounds(100, 100);
4346 SetLayerPropertiesForTesting(root.get(),
4347 identity_matrix,
4348 identity_matrix,
4349 anchor,
4350 position,
4351 bounds,
4352 false);
4353 root->SetDrawsContent(true);
4354
[email protected]50761e92013-03-29 20:51:284355 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534356 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4357 root.get(), root->bounds(), &render_surface_layer_list);
4358 inputs.can_adjust_raster_scales = true;
4359 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324360
4361 // Sanity check the scenario we just created.
4362 ASSERT_EQ(1u, render_surface_layer_list.size());
4363 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4364
4365 // Hit testing for a point outside the layer should return a null pointer.
4366 gfx::Point test_point(101, 101);
4367 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4368 test_point, render_surface_layer_list);
4369 EXPECT_FALSE(result_layer);
4370
4371 test_point = gfx::Point(-1, -1);
4372 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4373 test_point, render_surface_layer_list);
4374 EXPECT_FALSE(result_layer);
4375
4376 // Hit testing for a point inside should return the root layer.
4377 test_point = gfx::Point(1, 1);
4378 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4379 test_point, render_surface_layer_list);
4380 ASSERT_TRUE(result_layer);
4381 EXPECT_EQ(12345, result_layer->id());
4382
4383 test_point = gfx::Point(99, 99);
4384 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4385 test_point, render_surface_layer_list);
4386 ASSERT_TRUE(result_layer);
4387 EXPECT_EQ(12345, result_layer->id());
4388}
4389
[email protected]989386c2013-07-18 21:37:234390TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) {
[email protected]fb661802013-03-25 01:59:324391 FakeImplProxy proxy;
4392 FakeLayerTreeHostImpl host_impl(&proxy);
4393 scoped_ptr<LayerImpl> root =
4394 LayerImpl::Create(host_impl.active_tree(), 12345);
4395 scoped_ptr<HeadsUpDisplayLayerImpl> hud =
4396 HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111);
4397
4398 gfx::Transform identity_matrix;
4399 gfx::PointF anchor;
4400 gfx::PointF position;
4401 gfx::Size bounds(100, 100);
4402 SetLayerPropertiesForTesting(root.get(),
4403 identity_matrix,
4404 identity_matrix,
4405 anchor,
4406 position,
4407 bounds,
4408 false);
4409 root->SetDrawsContent(true);
4410
4411 // Create hud and add it as a child of root.
4412 gfx::Size hud_bounds(200, 200);
4413 SetLayerPropertiesForTesting(hud.get(),
4414 identity_matrix,
4415 identity_matrix,
4416 anchor,
4417 position,
4418 hud_bounds,
4419 false);
4420 hud->SetDrawsContent(true);
4421
4422 host_impl.active_tree()->set_hud_layer(hud.get());
4423 root->AddChild(hud.PassAs<LayerImpl>());
4424
[email protected]50761e92013-03-29 20:51:284425 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534426 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4427 root.get(), hud_bounds, &render_surface_layer_list);
4428 inputs.can_adjust_raster_scales = true;
4429 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324430
4431 // Sanity check the scenario we just created.
4432 ASSERT_EQ(1u, render_surface_layer_list.size());
4433 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4434
4435 // Hit testing for a point inside HUD, but outside root should return null
4436 gfx::Point test_point(101, 101);
4437 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4438 test_point, render_surface_layer_list);
4439 EXPECT_FALSE(result_layer);
4440
4441 test_point = gfx::Point(-1, -1);
4442 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4443 test_point, render_surface_layer_list);
4444 EXPECT_FALSE(result_layer);
4445
4446 // Hit testing for a point inside should return the root layer, never the HUD
4447 // layer.
4448 test_point = gfx::Point(1, 1);
4449 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4450 test_point, render_surface_layer_list);
4451 ASSERT_TRUE(result_layer);
4452 EXPECT_EQ(12345, result_layer->id());
4453
4454 test_point = gfx::Point(99, 99);
4455 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4456 test_point, render_surface_layer_list);
4457 ASSERT_TRUE(result_layer);
4458 EXPECT_EQ(12345, result_layer->id());
4459}
4460
[email protected]989386c2013-07-18 21:37:234461TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) {
[email protected]fb661802013-03-25 01:59:324462 FakeImplProxy proxy;
4463 FakeLayerTreeHostImpl host_impl(&proxy);
4464 scoped_ptr<LayerImpl> root =
4465 LayerImpl::Create(host_impl.active_tree(), 12345);
4466
4467 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:264468 uninvertible_transform.matrix().set(0, 0, 0.0);
4469 uninvertible_transform.matrix().set(1, 1, 0.0);
4470 uninvertible_transform.matrix().set(2, 2, 0.0);
4471 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:324472 ASSERT_FALSE(uninvertible_transform.IsInvertible());
4473
4474 gfx::Transform identity_matrix;
4475 gfx::PointF anchor;
4476 gfx::PointF position;
4477 gfx::Size bounds(100, 100);
4478 SetLayerPropertiesForTesting(root.get(),
4479 uninvertible_transform,
4480 identity_matrix,
4481 anchor,
4482 position,
4483 bounds,
4484 false);
4485 root->SetDrawsContent(true);
4486
[email protected]50761e92013-03-29 20:51:284487 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534488 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4489 root.get(), root->bounds(), &render_surface_layer_list);
4490 inputs.can_adjust_raster_scales = true;
4491 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324492
4493 // Sanity check the scenario we just created.
4494 ASSERT_EQ(1u, render_surface_layer_list.size());
4495 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4496 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
4497
4498 // Hit testing any point should not hit the layer. If the invertible matrix is
4499 // accidentally ignored and treated like an identity, then the hit testing
4500 // will incorrectly hit the layer when it shouldn't.
4501 gfx::Point test_point(1, 1);
4502 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4503 test_point, render_surface_layer_list);
4504 EXPECT_FALSE(result_layer);
4505
4506 test_point = gfx::Point(10, 10);
4507 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4508 test_point, render_surface_layer_list);
4509 EXPECT_FALSE(result_layer);
4510
4511 test_point = gfx::Point(10, 30);
4512 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4513 test_point, render_surface_layer_list);
4514 EXPECT_FALSE(result_layer);
4515
4516 test_point = gfx::Point(50, 50);
4517 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4518 test_point, render_surface_layer_list);
4519 EXPECT_FALSE(result_layer);
4520
4521 test_point = gfx::Point(67, 48);
4522 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4523 test_point, render_surface_layer_list);
4524 EXPECT_FALSE(result_layer);
4525
4526 test_point = gfx::Point(99, 99);
4527 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4528 test_point, render_surface_layer_list);
4529 EXPECT_FALSE(result_layer);
4530
4531 test_point = gfx::Point(-1, -1);
4532 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4533 test_point, render_surface_layer_list);
4534 EXPECT_FALSE(result_layer);
4535}
4536
[email protected]989386c2013-07-18 21:37:234537TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) {
[email protected]fb661802013-03-25 01:59:324538 FakeImplProxy proxy;
4539 FakeLayerTreeHostImpl host_impl(&proxy);
4540 scoped_ptr<LayerImpl> root =
4541 LayerImpl::Create(host_impl.active_tree(), 12345);
4542
4543 gfx::Transform identity_matrix;
4544 gfx::PointF anchor;
4545 // this layer is positioned, and hit testing should correctly know where the
4546 // layer is located.
4547 gfx::PointF position(50.f, 50.f);
4548 gfx::Size bounds(100, 100);
4549 SetLayerPropertiesForTesting(root.get(),
4550 identity_matrix,
4551 identity_matrix,
4552 anchor,
4553 position,
4554 bounds,
4555 false);
4556 root->SetDrawsContent(true);
4557
[email protected]50761e92013-03-29 20:51:284558 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534559 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4560 root.get(), root->bounds(), &render_surface_layer_list);
4561 inputs.can_adjust_raster_scales = true;
4562 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324563
4564 // Sanity check the scenario we just created.
4565 ASSERT_EQ(1u, render_surface_layer_list.size());
4566 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4567
4568 // Hit testing for a point outside the layer should return a null pointer.
4569 gfx::Point test_point(49, 49);
4570 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4571 test_point, render_surface_layer_list);
4572 EXPECT_FALSE(result_layer);
4573
4574 // Even though the layer exists at (101, 101), it should not be visible there
4575 // since the root render surface would clamp it.
4576 test_point = gfx::Point(101, 101);
4577 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4578 test_point, render_surface_layer_list);
4579 EXPECT_FALSE(result_layer);
4580
4581 // Hit testing for a point inside should return the root layer.
4582 test_point = gfx::Point(51, 51);
4583 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4584 test_point, render_surface_layer_list);
4585 ASSERT_TRUE(result_layer);
4586 EXPECT_EQ(12345, result_layer->id());
4587
4588 test_point = gfx::Point(99, 99);
4589 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4590 test_point, render_surface_layer_list);
4591 ASSERT_TRUE(result_layer);
4592 EXPECT_EQ(12345, result_layer->id());
4593}
4594
[email protected]989386c2013-07-18 21:37:234595TEST_F(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324596 FakeImplProxy proxy;
4597 FakeLayerTreeHostImpl host_impl(&proxy);
4598 scoped_ptr<LayerImpl> root =
4599 LayerImpl::Create(host_impl.active_tree(), 12345);
4600
4601 gfx::Transform identity_matrix;
4602 gfx::Transform rotation45_degrees_about_center;
4603 rotation45_degrees_about_center.Translate(50.0, 50.0);
4604 rotation45_degrees_about_center.RotateAboutZAxis(45.0);
4605 rotation45_degrees_about_center.Translate(-50.0, -50.0);
4606 gfx::PointF anchor;
4607 gfx::PointF position;
4608 gfx::Size bounds(100, 100);
4609 SetLayerPropertiesForTesting(root.get(),
4610 rotation45_degrees_about_center,
4611 identity_matrix,
4612 anchor,
4613 position,
4614 bounds,
4615 false);
4616 root->SetDrawsContent(true);
4617
[email protected]50761e92013-03-29 20:51:284618 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534619 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4620 root.get(), root->bounds(), &render_surface_layer_list);
4621 inputs.can_adjust_raster_scales = true;
4622 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324623
4624 // Sanity check the scenario we just created.
4625 ASSERT_EQ(1u, render_surface_layer_list.size());
4626 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4627
4628 // Hit testing for points outside the layer.
4629 // These corners would have been inside the un-transformed layer, but they
4630 // should not hit the correctly transformed layer.
4631 gfx::Point test_point(99, 99);
4632 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4633 test_point, render_surface_layer_list);
4634 EXPECT_FALSE(result_layer);
4635
4636 test_point = gfx::Point(1, 1);
4637 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4638 test_point, render_surface_layer_list);
4639 EXPECT_FALSE(result_layer);
4640
4641 // Hit testing for a point inside should return the root layer.
4642 test_point = gfx::Point(1, 50);
4643 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4644 test_point, render_surface_layer_list);
4645 ASSERT_TRUE(result_layer);
4646 EXPECT_EQ(12345, result_layer->id());
4647
4648 // Hit testing the corners that would overlap the unclipped layer, but are
4649 // outside the clipped region.
4650 test_point = gfx::Point(50, -1);
4651 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4652 test_point, render_surface_layer_list);
4653 ASSERT_FALSE(result_layer);
4654
4655 test_point = gfx::Point(-1, 50);
4656 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4657 test_point, render_surface_layer_list);
4658 ASSERT_FALSE(result_layer);
4659}
4660
[email protected]989386c2013-07-18 21:37:234661TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) {
[email protected]fb661802013-03-25 01:59:324662 FakeImplProxy proxy;
4663 FakeLayerTreeHostImpl host_impl(&proxy);
4664 scoped_ptr<LayerImpl> root =
4665 LayerImpl::Create(host_impl.active_tree(), 12345);
4666
4667 gfx::Transform identity_matrix;
4668
4669 // perspective_projection_about_center * translation_by_z is designed so that
4670 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
4671 gfx::Transform perspective_projection_about_center;
4672 perspective_projection_about_center.Translate(50.0, 50.0);
4673 perspective_projection_about_center.ApplyPerspectiveDepth(1.0);
4674 perspective_projection_about_center.Translate(-50.0, -50.0);
4675 gfx::Transform translation_by_z;
4676 translation_by_z.Translate3d(0.0, 0.0, -1.0);
4677
4678 gfx::PointF anchor;
4679 gfx::PointF position;
4680 gfx::Size bounds(100, 100);
4681 SetLayerPropertiesForTesting(
4682 root.get(),
4683 perspective_projection_about_center * translation_by_z,
4684 identity_matrix,
4685 anchor,
4686 position,
4687 bounds,
4688 false);
4689 root->SetDrawsContent(true);
4690
[email protected]50761e92013-03-29 20:51:284691 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534692 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4693 root.get(), root->bounds(), &render_surface_layer_list);
4694 inputs.can_adjust_raster_scales = true;
4695 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324696
4697 // Sanity check the scenario we just created.
4698 ASSERT_EQ(1u, render_surface_layer_list.size());
4699 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4700
4701 // Hit testing for points outside the layer.
4702 // These corners would have been inside the un-transformed layer, but they
4703 // should not hit the correctly transformed layer.
4704 gfx::Point test_point(24, 24);
4705 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4706 test_point, render_surface_layer_list);
4707 EXPECT_FALSE(result_layer);
4708
4709 test_point = gfx::Point(76, 76);
4710 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4711 test_point, render_surface_layer_list);
4712 EXPECT_FALSE(result_layer);
4713
4714 // Hit testing for a point inside should return the root layer.
4715 test_point = gfx::Point(26, 26);
4716 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4717 test_point, render_surface_layer_list);
4718 ASSERT_TRUE(result_layer);
4719 EXPECT_EQ(12345, result_layer->id());
4720
4721 test_point = gfx::Point(74, 74);
4722 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4723 test_point, render_surface_layer_list);
4724 ASSERT_TRUE(result_layer);
4725 EXPECT_EQ(12345, result_layer->id());
4726}
4727
[email protected]989386c2013-07-18 21:37:234728TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) {
[email protected]fb661802013-03-25 01:59:324729 // A layer's visible content rect is actually in the layer's content space.
4730 // The screen space transform converts from the layer's origin space to screen
4731 // space. This test makes sure that hit testing works correctly accounts for
4732 // the contents scale. A contents scale that is not 1 effectively forces a
4733 // non-identity transform between layer's content space and layer's origin
4734 // space. The hit testing code must take this into account.
4735 //
4736 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
4737 // contents scale is ignored, then hit testing will mis-interpret the visible
4738 // content rect as being larger than the actual bounds of the layer.
4739 //
4740 FakeImplProxy proxy;
4741 FakeLayerTreeHostImpl host_impl(&proxy);
4742 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4743
4744 gfx::Transform identity_matrix;
4745 gfx::PointF anchor;
4746
4747 SetLayerPropertiesForTesting(root.get(),
4748 identity_matrix,
4749 identity_matrix,
4750 anchor,
4751 gfx::PointF(),
4752 gfx::Size(100, 100),
4753 false);
4754 {
4755 gfx::PointF position(25.f, 25.f);
4756 gfx::Size bounds(50, 50);
4757 scoped_ptr<LayerImpl> test_layer =
4758 LayerImpl::Create(host_impl.active_tree(), 12345);
4759 SetLayerPropertiesForTesting(test_layer.get(),
4760 identity_matrix,
4761 identity_matrix,
4762 anchor,
4763 position,
4764 bounds,
4765 false);
4766
4767 // override content bounds and contents scale
4768 test_layer->SetContentBounds(gfx::Size(100, 100));
4769 test_layer->SetContentsScale(2, 2);
4770
4771 test_layer->SetDrawsContent(true);
4772 root->AddChild(test_layer.Pass());
4773 }
4774
[email protected]50761e92013-03-29 20:51:284775 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534776 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4777 root.get(), root->bounds(), &render_surface_layer_list);
4778 inputs.can_adjust_raster_scales = true;
4779 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324780
4781 // Sanity check the scenario we just created.
4782 // The visible content rect for test_layer is actually 100x100, even though
4783 // its layout size is 50x50, positioned at 25x25.
4784 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:054785 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
[email protected]fb661802013-03-25 01:59:324786 test_layer->visible_content_rect());
4787 ASSERT_EQ(1u, render_surface_layer_list.size());
4788 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4789
4790 // Hit testing for a point outside the layer should return a null pointer (the
4791 // root layer does not draw content, so it will not be hit tested either).
4792 gfx::Point test_point(101, 101);
4793 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4794 test_point, render_surface_layer_list);
4795 EXPECT_FALSE(result_layer);
4796
4797 test_point = gfx::Point(24, 24);
4798 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4799 test_point, render_surface_layer_list);
4800 EXPECT_FALSE(result_layer);
4801
4802 test_point = gfx::Point(76, 76);
4803 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4804 test_point, render_surface_layer_list);
4805 EXPECT_FALSE(result_layer);
4806
4807 // Hit testing for a point inside should return the test layer.
4808 test_point = gfx::Point(26, 26);
4809 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4810 test_point, render_surface_layer_list);
4811 ASSERT_TRUE(result_layer);
4812 EXPECT_EQ(12345, result_layer->id());
4813
4814 test_point = gfx::Point(74, 74);
4815 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4816 test_point, render_surface_layer_list);
4817 ASSERT_TRUE(result_layer);
4818 EXPECT_EQ(12345, result_layer->id());
4819}
4820
[email protected]989386c2013-07-18 21:37:234821TEST_F(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) {
[email protected]fb661802013-03-25 01:59:324822 // Test that hit-testing will only work for the visible portion of a layer,
4823 // and not the entire layer bounds. Here we just test the simple axis-aligned
4824 // case.
4825 gfx::Transform identity_matrix;
4826 gfx::PointF anchor;
4827
4828 FakeImplProxy proxy;
4829 FakeLayerTreeHostImpl host_impl(&proxy);
4830 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4831 SetLayerPropertiesForTesting(root.get(),
4832 identity_matrix,
4833 identity_matrix,
4834 anchor,
4835 gfx::PointF(),
4836 gfx::Size(100, 100),
4837 false);
4838 {
4839 scoped_ptr<LayerImpl> clipping_layer =
4840 LayerImpl::Create(host_impl.active_tree(), 123);
4841 // this layer is positioned, and hit testing should correctly know where the
4842 // layer is located.
[email protected]ca2902e92013-03-28 01:45:354843 gfx::PointF position(25.f, 25.f);
[email protected]fb661802013-03-25 01:59:324844 gfx::Size bounds(50, 50);
4845 SetLayerPropertiesForTesting(clipping_layer.get(),
4846 identity_matrix,
4847 identity_matrix,
4848 anchor,
4849 position,
4850 bounds,
4851 false);
4852 clipping_layer->SetMasksToBounds(true);
4853
4854 scoped_ptr<LayerImpl> child =
4855 LayerImpl::Create(host_impl.active_tree(), 456);
4856 position = gfx::PointF(-50.f, -50.f);
4857 bounds = gfx::Size(300, 300);
4858 SetLayerPropertiesForTesting(child.get(),
4859 identity_matrix,
4860 identity_matrix,
4861 anchor,
4862 position,
4863 bounds,
4864 false);
4865 child->SetDrawsContent(true);
4866 clipping_layer->AddChild(child.Pass());
4867 root->AddChild(clipping_layer.Pass());
4868 }
4869
[email protected]50761e92013-03-29 20:51:284870 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534871 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4872 root.get(), root->bounds(), &render_surface_layer_list);
4873 inputs.can_adjust_raster_scales = true;
4874 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324875
4876 // Sanity check the scenario we just created.
4877 ASSERT_EQ(1u, render_surface_layer_list.size());
4878 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234879 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324880
4881 // Hit testing for a point outside the layer should return a null pointer.
4882 // Despite the child layer being very large, it should be clipped to the root
4883 // layer's bounds.
4884 gfx::Point test_point(24, 24);
4885 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4886 test_point, render_surface_layer_list);
4887 EXPECT_FALSE(result_layer);
4888
4889 // Even though the layer exists at (101, 101), it should not be visible there
4890 // since the clipping_layer would clamp it.
4891 test_point = gfx::Point(76, 76);
4892 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4893 test_point, render_surface_layer_list);
4894 EXPECT_FALSE(result_layer);
4895
4896 // Hit testing for a point inside should return the child layer.
4897 test_point = gfx::Point(26, 26);
4898 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4899 test_point, render_surface_layer_list);
4900 ASSERT_TRUE(result_layer);
4901 EXPECT_EQ(456, result_layer->id());
4902
4903 test_point = gfx::Point(74, 74);
4904 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4905 test_point, render_surface_layer_list);
4906 ASSERT_TRUE(result_layer);
4907 EXPECT_EQ(456, result_layer->id());
4908}
4909
[email protected]989386c2013-07-18 21:37:234910TEST_F(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324911 // This test checks whether hit testing correctly avoids hit testing with
4912 // multiple ancestors that clip in non axis-aligned ways. To pass this test,
4913 // the hit testing algorithm needs to recognize that multiple parent layers
4914 // may clip the layer, and should not actually hit those clipped areas.
4915 //
4916 // The child and grand_child layers are both initialized to clip the
4917 // rotated_leaf. The child layer is rotated about the top-left corner, so that
4918 // the root + child clips combined create a triangle. The rotated_leaf will
4919 // only be visible where it overlaps this triangle.
4920 //
4921 FakeImplProxy proxy;
4922 FakeLayerTreeHostImpl host_impl(&proxy);
4923 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123);
4924
4925 gfx::Transform identity_matrix;
4926 gfx::PointF anchor;
4927 gfx::PointF position;
4928 gfx::Size bounds(100, 100);
4929 SetLayerPropertiesForTesting(root.get(),
4930 identity_matrix,
4931 identity_matrix,
4932 anchor,
4933 position,
4934 bounds,
4935 false);
4936 root->SetMasksToBounds(true);
4937 {
4938 scoped_ptr<LayerImpl> child =
4939 LayerImpl::Create(host_impl.active_tree(), 456);
4940 scoped_ptr<LayerImpl> grand_child =
4941 LayerImpl::Create(host_impl.active_tree(), 789);
4942 scoped_ptr<LayerImpl> rotated_leaf =
4943 LayerImpl::Create(host_impl.active_tree(), 2468);
4944
4945 position = gfx::PointF(10.f, 10.f);
4946 bounds = gfx::Size(80, 80);
4947 SetLayerPropertiesForTesting(child.get(),
4948 identity_matrix,
4949 identity_matrix,
4950 anchor,
4951 position,
4952 bounds,
4953 false);
[email protected]7aba6662013-03-12 10:17:344954 child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444955
[email protected]fb661802013-03-25 01:59:324956 gfx::Transform rotation45_degrees_about_corner;
4957 rotation45_degrees_about_corner.RotateAboutZAxis(45.0);
[email protected]aedf4e52013-01-09 23:24:444958
[email protected]fb661802013-03-25 01:59:324959 // remember, positioned with respect to its parent which is already at 10,
4960 // 10
4961 position = gfx::PointF();
4962 bounds =
4963 gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
4964 SetLayerPropertiesForTesting(grand_child.get(),
4965 rotation45_degrees_about_corner,
4966 identity_matrix,
4967 anchor,
4968 position,
4969 bounds,
4970 false);
4971 grand_child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444972
[email protected]fb661802013-03-25 01:59:324973 // Rotates about the center of the layer
4974 gfx::Transform rotated_leaf_transform;
4975 rotated_leaf_transform.Translate(
4976 -10.0, -10.0); // cancel out the grand_parent's position
4977 rotated_leaf_transform.RotateAboutZAxis(
4978 -45.0); // cancel out the corner 45-degree rotation of the parent.
4979 rotated_leaf_transform.Translate(50.0, 50.0);
4980 rotated_leaf_transform.RotateAboutZAxis(45.0);
4981 rotated_leaf_transform.Translate(-50.0, -50.0);
4982 position = gfx::PointF();
4983 bounds = gfx::Size(100, 100);
4984 SetLayerPropertiesForTesting(rotated_leaf.get(),
4985 rotated_leaf_transform,
4986 identity_matrix,
4987 anchor,
4988 position,
4989 bounds,
4990 false);
4991 rotated_leaf->SetDrawsContent(true);
[email protected]aedf4e52013-01-09 23:24:444992
[email protected]fb661802013-03-25 01:59:324993 grand_child->AddChild(rotated_leaf.Pass());
4994 child->AddChild(grand_child.Pass());
4995 root->AddChild(child.Pass());
4996 }
[email protected]aedf4e52013-01-09 23:24:444997
[email protected]50761e92013-03-29 20:51:284998 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534999 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5000 root.get(), root->bounds(), &render_surface_layer_list);
5001 inputs.can_adjust_raster_scales = true;
5002 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:445003
[email protected]fb661802013-03-25 01:59:325004 // Sanity check the scenario we just created.
5005 // The grand_child is expected to create a render surface because it
[email protected]989386c2013-07-18 21:37:235006 // MasksToBounds and is not axis aligned.
[email protected]fb661802013-03-25 01:59:325007 ASSERT_EQ(2u, render_surface_layer_list.size());
5008 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:235009 1u,
5010 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:325011 ASSERT_EQ(789,
[email protected]989386c2013-07-18 21:37:235012 render_surface_layer_list.at(0)->render_surface()->layer_list().at(
5013 0)->id()); // grand_child's surface.
[email protected]fb661802013-03-25 01:59:325014 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:235015 1u,
5016 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:325017 ASSERT_EQ(
5018 2468,
[email protected]989386c2013-07-18 21:37:235019 render_surface_layer_list[1]->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:325020
5021 // (11, 89) is close to the the bottom left corner within the clip, but it is
5022 // not inside the layer.
5023 gfx::Point test_point(11, 89);
5024 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5025 test_point, render_surface_layer_list);
5026 EXPECT_FALSE(result_layer);
5027
5028 // Closer inwards from the bottom left will overlap the layer.
5029 test_point = gfx::Point(25, 75);
5030 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5031 test_point, render_surface_layer_list);
5032 ASSERT_TRUE(result_layer);
5033 EXPECT_EQ(2468, result_layer->id());
5034
5035 // (4, 50) is inside the unclipped layer, but that corner of the layer should
5036 // be clipped away by the grandparent and should not get hit. If hit testing
5037 // blindly uses visible content rect without considering how parent may clip
5038 // the layer, then hit testing would accidentally think that the point
5039 // successfully hits the layer.
5040 test_point = gfx::Point(4, 50);
5041 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5042 test_point, render_surface_layer_list);
5043 EXPECT_FALSE(result_layer);
5044
5045 // (11, 50) is inside the layer and within the clipped area.
5046 test_point = gfx::Point(11, 50);
5047 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5048 test_point, render_surface_layer_list);
5049 ASSERT_TRUE(result_layer);
5050 EXPECT_EQ(2468, result_layer->id());
5051
5052 // Around the middle, just to the right and up, would have hit the layer
5053 // except that that area should be clipped away by the parent.
[email protected]803f6b52013-09-12 00:51:265054 test_point = gfx::Point(51, 49);
[email protected]fb661802013-03-25 01:59:325055 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5056 test_point, render_surface_layer_list);
5057 EXPECT_FALSE(result_layer);
5058
5059 // Around the middle, just to the left and down, should successfully hit the
5060 // layer.
5061 test_point = gfx::Point(49, 51);
5062 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5063 test_point, render_surface_layer_list);
5064 ASSERT_TRUE(result_layer);
5065 EXPECT_EQ(2468, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:445066}
5067
[email protected]989386c2013-07-18 21:37:235068TEST_F(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:325069 // This test checks that hit testing code does not accidentally clip to layer
5070 // bounds for a layer that actually does not clip.
5071 gfx::Transform identity_matrix;
5072 gfx::PointF anchor;
[email protected]aedf4e52013-01-09 23:24:445073
[email protected]fb661802013-03-25 01:59:325074 FakeImplProxy proxy;
5075 FakeLayerTreeHostImpl host_impl(&proxy);
5076 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5077 SetLayerPropertiesForTesting(root.get(),
5078 identity_matrix,
5079 identity_matrix,
5080 anchor,
5081 gfx::PointF(),
5082 gfx::Size(100, 100),
5083 false);
5084 {
5085 scoped_ptr<LayerImpl> intermediate_layer =
5086 LayerImpl::Create(host_impl.active_tree(), 123);
5087 // this layer is positioned, and hit testing should correctly know where the
5088 // layer is located.
5089 gfx::PointF position(10.f, 10.f);
5090 gfx::Size bounds(50, 50);
5091 SetLayerPropertiesForTesting(intermediate_layer.get(),
5092 identity_matrix,
5093 identity_matrix,
5094 anchor,
5095 position,
5096 bounds,
5097 false);
5098 // Sanity check the intermediate layer should not clip.
5099 ASSERT_FALSE(intermediate_layer->masks_to_bounds());
5100 ASSERT_FALSE(intermediate_layer->mask_layer());
[email protected]aedf4e52013-01-09 23:24:445101
[email protected]fb661802013-03-25 01:59:325102 // The child of the intermediate_layer is translated so that it does not
5103 // overlap intermediate_layer at all. If child is incorrectly clipped, we
5104 // would not be able to hit it successfully.
5105 scoped_ptr<LayerImpl> child =
5106 LayerImpl::Create(host_impl.active_tree(), 456);
5107 position = gfx::PointF(60.f, 60.f); // 70, 70 in screen space
5108 bounds = gfx::Size(20, 20);
5109 SetLayerPropertiesForTesting(child.get(),
5110 identity_matrix,
5111 identity_matrix,
5112 anchor,
5113 position,
5114 bounds,
5115 false);
5116 child->SetDrawsContent(true);
5117 intermediate_layer->AddChild(child.Pass());
5118 root->AddChild(intermediate_layer.Pass());
5119 }
[email protected]aedf4e52013-01-09 23:24:445120
[email protected]50761e92013-03-29 20:51:285121 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535122 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5123 root.get(), root->bounds(), &render_surface_layer_list);
5124 inputs.can_adjust_raster_scales = true;
5125 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:445126
[email protected]fb661802013-03-25 01:59:325127 // Sanity check the scenario we just created.
5128 ASSERT_EQ(1u, render_surface_layer_list.size());
5129 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235130 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]aedf4e52013-01-09 23:24:445131
[email protected]fb661802013-03-25 01:59:325132 // Hit testing for a point outside the layer should return a null pointer.
5133 gfx::Point test_point(69, 69);
5134 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5135 test_point, render_surface_layer_list);
5136 EXPECT_FALSE(result_layer);
[email protected]aedf4e52013-01-09 23:24:445137
[email protected]fb661802013-03-25 01:59:325138 test_point = gfx::Point(91, 91);
5139 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5140 test_point, render_surface_layer_list);
5141 EXPECT_FALSE(result_layer);
5142
5143 // Hit testing for a point inside should return the child layer.
5144 test_point = gfx::Point(71, 71);
5145 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5146 test_point, render_surface_layer_list);
5147 ASSERT_TRUE(result_layer);
5148 EXPECT_EQ(456, result_layer->id());
5149
5150 test_point = gfx::Point(89, 89);
5151 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5152 test_point, render_surface_layer_list);
5153 ASSERT_TRUE(result_layer);
5154 EXPECT_EQ(456, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:445155}
5156
[email protected]989386c2013-07-18 21:37:235157TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayers) {
[email protected]fb661802013-03-25 01:59:325158 FakeImplProxy proxy;
5159 FakeLayerTreeHostImpl host_impl(&proxy);
5160 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145161
[email protected]fb661802013-03-25 01:59:325162 gfx::Transform identity_matrix;
5163 gfx::PointF anchor;
5164 gfx::PointF position;
5165 gfx::Size bounds(100, 100);
5166 SetLayerPropertiesForTesting(root.get(),
5167 identity_matrix,
5168 identity_matrix,
5169 anchor,
5170 position,
5171 bounds,
5172 false);
5173 root->SetDrawsContent(true);
5174 {
5175 // child 1 and child2 are initialized to overlap between x=50 and x=60.
5176 // grand_child is set to overlap both child1 and child2 between y=50 and
5177 // y=60. The expected stacking order is: (front) child2, (second)
5178 // grand_child, (third) child1, and (back) the root layer behind all other
5179 // layers.
[email protected]ecc12622012-10-30 20:45:425180
[email protected]fb661802013-03-25 01:59:325181 scoped_ptr<LayerImpl> child1 =
5182 LayerImpl::Create(host_impl.active_tree(), 2);
5183 scoped_ptr<LayerImpl> child2 =
5184 LayerImpl::Create(host_impl.active_tree(), 3);
5185 scoped_ptr<LayerImpl> grand_child1 =
5186 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:145187
[email protected]fb661802013-03-25 01:59:325188 position = gfx::PointF(10.f, 10.f);
5189 bounds = gfx::Size(50, 50);
5190 SetLayerPropertiesForTesting(child1.get(),
5191 identity_matrix,
5192 identity_matrix,
5193 anchor,
5194 position,
5195 bounds,
5196 false);
5197 child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145198
[email protected]fb661802013-03-25 01:59:325199 position = gfx::PointF(50.f, 10.f);
5200 bounds = gfx::Size(50, 50);
5201 SetLayerPropertiesForTesting(child2.get(),
5202 identity_matrix,
5203 identity_matrix,
5204 anchor,
5205 position,
5206 bounds,
5207 false);
5208 child2->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145209
[email protected]fb661802013-03-25 01:59:325210 // Remember that grand_child is positioned with respect to its parent (i.e.
5211 // child1). In screen space, the intended position is (10, 50), with size
5212 // 100 x 50.
5213 position = gfx::PointF(0.f, 40.f);
5214 bounds = gfx::Size(100, 50);
5215 SetLayerPropertiesForTesting(grand_child1.get(),
5216 identity_matrix,
5217 identity_matrix,
5218 anchor,
5219 position,
5220 bounds,
5221 false);
5222 grand_child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145223
[email protected]fb661802013-03-25 01:59:325224 child1->AddChild(grand_child1.Pass());
5225 root->AddChild(child1.Pass());
5226 root->AddChild(child2.Pass());
5227 }
[email protected]94f206c12012-08-25 00:09:145228
[email protected]fb661802013-03-25 01:59:325229 LayerImpl* child1 = root->children()[0];
5230 LayerImpl* child2 = root->children()[1];
5231 LayerImpl* grand_child1 = child1->children()[0];
5232
[email protected]50761e92013-03-29 20:51:285233 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535234 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5235 root.get(), root->bounds(), &render_surface_layer_list);
5236 inputs.can_adjust_raster_scales = true;
5237 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325238
5239 // Sanity check the scenario we just created.
5240 ASSERT_TRUE(child1);
5241 ASSERT_TRUE(child2);
5242 ASSERT_TRUE(grand_child1);
5243 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:235244
5245 RenderSurfaceImpl* root_render_surface = root->render_surface();
5246 ASSERT_EQ(4u, root_render_surface->layer_list().size());
5247 ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer
5248 ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1
5249 ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1
5250 ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2
[email protected]fb661802013-03-25 01:59:325251
5252 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5253 // the root layer.
5254 gfx::Point test_point = gfx::Point(1, 1);
5255 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5256 test_point, render_surface_layer_list);
5257 ASSERT_TRUE(result_layer);
5258 EXPECT_EQ(1, result_layer->id());
5259
5260 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5261 // on top.
5262 test_point = gfx::Point(15, 15);
5263 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5264 test_point, render_surface_layer_list);
5265 ASSERT_TRUE(result_layer);
5266 EXPECT_EQ(2, result_layer->id());
5267
5268 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5269 test_point = gfx::Point(51, 20);
5270 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5271 test_point, render_surface_layer_list);
5272 ASSERT_TRUE(result_layer);
5273 EXPECT_EQ(3, result_layer->id());
5274
5275 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5276 // top.
5277 test_point = gfx::Point(80, 51);
5278 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5279 test_point, render_surface_layer_list);
5280 ASSERT_TRUE(result_layer);
5281 EXPECT_EQ(3, result_layer->id());
5282
5283 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5284 // of all other layers.
5285 test_point = gfx::Point(51, 51);
5286 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5287 test_point, render_surface_layer_list);
5288 ASSERT_TRUE(result_layer);
5289 EXPECT_EQ(3, result_layer->id());
5290
5291 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5292 // be on top.
5293 test_point = gfx::Point(20, 51);
5294 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5295 test_point, render_surface_layer_list);
5296 ASSERT_TRUE(result_layer);
5297 EXPECT_EQ(4, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145298}
5299
[email protected]989386c2013-07-18 21:37:235300TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) {
[email protected]fb661802013-03-25 01:59:325301 //
5302 // The geometry is set up similarly to the previous case, but
5303 // all layers are forced to be render surfaces now.
5304 //
5305 FakeImplProxy proxy;
5306 FakeLayerTreeHostImpl host_impl(&proxy);
5307 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145308
[email protected]fb661802013-03-25 01:59:325309 gfx::Transform identity_matrix;
5310 gfx::PointF anchor;
5311 gfx::PointF position;
5312 gfx::Size bounds(100, 100);
5313 SetLayerPropertiesForTesting(root.get(),
5314 identity_matrix,
5315 identity_matrix,
5316 anchor,
5317 position,
5318 bounds,
5319 false);
5320 root->SetDrawsContent(true);
5321 {
5322 // child 1 and child2 are initialized to overlap between x=50 and x=60.
5323 // grand_child is set to overlap both child1 and child2 between y=50 and
5324 // y=60. The expected stacking order is: (front) child2, (second)
5325 // grand_child, (third) child1, and (back) the root layer behind all other
5326 // layers.
[email protected]94f206c12012-08-25 00:09:145327
[email protected]fb661802013-03-25 01:59:325328 scoped_ptr<LayerImpl> child1 =
5329 LayerImpl::Create(host_impl.active_tree(), 2);
5330 scoped_ptr<LayerImpl> child2 =
5331 LayerImpl::Create(host_impl.active_tree(), 3);
5332 scoped_ptr<LayerImpl> grand_child1 =
5333 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:145334
[email protected]fb661802013-03-25 01:59:325335 position = gfx::PointF(10.f, 10.f);
5336 bounds = gfx::Size(50, 50);
5337 SetLayerPropertiesForTesting(child1.get(),
5338 identity_matrix,
5339 identity_matrix,
5340 anchor,
5341 position,
5342 bounds,
5343 false);
5344 child1->SetDrawsContent(true);
5345 child1->SetForceRenderSurface(true);
[email protected]ecc12622012-10-30 20:45:425346
[email protected]fb661802013-03-25 01:59:325347 position = gfx::PointF(50.f, 10.f);
5348 bounds = gfx::Size(50, 50);
5349 SetLayerPropertiesForTesting(child2.get(),
5350 identity_matrix,
5351 identity_matrix,
5352 anchor,
5353 position,
5354 bounds,
5355 false);
5356 child2->SetDrawsContent(true);
[email protected]7aba6662013-03-12 10:17:345357 child2->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015358
[email protected]fb661802013-03-25 01:59:325359 // Remember that grand_child is positioned with respect to its parent (i.e.
5360 // child1). In screen space, the intended position is (10, 50), with size
5361 // 100 x 50.
5362 position = gfx::PointF(0.f, 40.f);
5363 bounds = gfx::Size(100, 50);
5364 SetLayerPropertiesForTesting(grand_child1.get(),
5365 identity_matrix,
5366 identity_matrix,
5367 anchor,
5368 position,
5369 bounds,
5370 false);
5371 grand_child1->SetDrawsContent(true);
5372 grand_child1->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015373
[email protected]fb661802013-03-25 01:59:325374 child1->AddChild(grand_child1.Pass());
5375 root->AddChild(child1.Pass());
5376 root->AddChild(child2.Pass());
5377 }
[email protected]dc462d782012-11-21 21:43:015378
[email protected]fb661802013-03-25 01:59:325379 LayerImpl* child1 = root->children()[0];
5380 LayerImpl* child2 = root->children()[1];
5381 LayerImpl* grand_child1 = child1->children()[0];
[email protected]dc462d782012-11-21 21:43:015382
[email protected]50761e92013-03-29 20:51:285383 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535384 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5385 root.get(), root->bounds(), &render_surface_layer_list);
5386 inputs.can_adjust_raster_scales = true;
5387 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]dc462d782012-11-21 21:43:015388
[email protected]fb661802013-03-25 01:59:325389 // Sanity check the scenario we just created.
5390 ASSERT_TRUE(child1);
5391 ASSERT_TRUE(child2);
5392 ASSERT_TRUE(grand_child1);
5393 ASSERT_TRUE(child1->render_surface());
5394 ASSERT_TRUE(child2->render_surface());
5395 ASSERT_TRUE(grand_child1->render_surface());
5396 ASSERT_EQ(4u, render_surface_layer_list.size());
5397 // The root surface has the root layer, and child1's and child2's render
5398 // surfaces.
5399 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
5400 // The child1 surface has the child1 layer and grand_child1's render surface.
5401 ASSERT_EQ(2u, child1->render_surface()->layer_list().size());
5402 ASSERT_EQ(1u, child2->render_surface()->layer_list().size());
5403 ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235404 ASSERT_EQ(1, render_surface_layer_list.at(0)->id()); // root layer
[email protected]fb661802013-03-25 01:59:325405 ASSERT_EQ(2, render_surface_layer_list[1]->id()); // child1
[email protected]989386c2013-07-18 21:37:235406 ASSERT_EQ(4, render_surface_layer_list.at(2)->id()); // grand_child1
[email protected]fb661802013-03-25 01:59:325407 ASSERT_EQ(3, render_surface_layer_list[3]->id()); // child2
[email protected]dc462d782012-11-21 21:43:015408
[email protected]fb661802013-03-25 01:59:325409 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5410 // the root layer.
5411 gfx::Point test_point = gfx::Point(1, 1);
5412 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5413 test_point, render_surface_layer_list);
5414 ASSERT_TRUE(result_layer);
5415 EXPECT_EQ(1, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015416
[email protected]fb661802013-03-25 01:59:325417 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5418 // on top.
5419 test_point = gfx::Point(15, 15);
5420 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5421 test_point, render_surface_layer_list);
5422 ASSERT_TRUE(result_layer);
5423 EXPECT_EQ(2, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015424
[email protected]fb661802013-03-25 01:59:325425 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5426 test_point = gfx::Point(51, 20);
5427 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5428 test_point, render_surface_layer_list);
5429 ASSERT_TRUE(result_layer);
5430 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015431
[email protected]fb661802013-03-25 01:59:325432 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5433 // top.
5434 test_point = gfx::Point(80, 51);
5435 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5436 test_point, render_surface_layer_list);
5437 ASSERT_TRUE(result_layer);
5438 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015439
[email protected]fb661802013-03-25 01:59:325440 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5441 // of all other layers.
5442 test_point = gfx::Point(51, 51);
5443 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5444 test_point, render_surface_layer_list);
5445 ASSERT_TRUE(result_layer);
5446 EXPECT_EQ(3, result_layer->id());
5447
5448 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5449 // be on top.
5450 test_point = gfx::Point(20, 51);
5451 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5452 test_point, render_surface_layer_list);
5453 ASSERT_TRUE(result_layer);
5454 EXPECT_EQ(4, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015455}
5456
[email protected]989386c2013-07-18 21:37:235457TEST_F(LayerTreeHostCommonTest,
5458 HitCheckingTouchHandlerRegionsForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:325459 // Hit checking on an empty render_surface_layer_list should return a null
5460 // pointer.
[email protected]50761e92013-03-29 20:51:285461 LayerImplList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145462
[email protected]fb661802013-03-25 01:59:325463 gfx::Point test_point(0, 0);
5464 LayerImpl* result_layer =
5465 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5466 test_point, render_surface_layer_list);
5467 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145468
[email protected]fb661802013-03-25 01:59:325469 test_point = gfx::Point(10, 20);
5470 result_layer =
5471 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5472 test_point, render_surface_layer_list);
5473 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145474}
5475
[email protected]989386c2013-07-18 21:37:235476TEST_F(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:325477 FakeImplProxy proxy;
5478 FakeLayerTreeHostImpl host_impl(&proxy);
5479 scoped_ptr<LayerImpl> root =
5480 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145481
[email protected]fb661802013-03-25 01:59:325482 gfx::Transform identity_matrix;
5483 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5484 gfx::PointF anchor;
5485 gfx::PointF position;
5486 gfx::Size bounds(100, 100);
5487 SetLayerPropertiesForTesting(root.get(),
5488 identity_matrix,
5489 identity_matrix,
5490 anchor,
5491 position,
5492 bounds,
5493 false);
5494 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145495
[email protected]50761e92013-03-29 20:51:285496 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535497 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5498 root.get(), root->bounds(), &render_surface_layer_list);
5499 inputs.can_adjust_raster_scales = true;
5500 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145501
[email protected]fb661802013-03-25 01:59:325502 // Sanity check the scenario we just created.
5503 ASSERT_EQ(1u, render_surface_layer_list.size());
5504 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145505
[email protected]fb661802013-03-25 01:59:325506 // Hit checking for any point should return a null pointer for a layer without
5507 // any touch event handler regions.
5508 gfx::Point test_point(11, 11);
5509 LayerImpl* 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 root->SetTouchEventHandlerRegion(touch_handler_region);
5515 // Hit checking for a point outside the layer should return a null pointer.
5516 test_point = gfx::Point(101, 101);
5517 result_layer =
5518 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5519 test_point, render_surface_layer_list);
5520 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145521
[email protected]fb661802013-03-25 01:59:325522 test_point = gfx::Point(-1, -1);
5523 result_layer =
5524 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5525 test_point, render_surface_layer_list);
5526 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145527
[email protected]fb661802013-03-25 01:59:325528 // Hit checking for a point inside the layer, but outside the touch handler
5529 // region should return a null pointer.
5530 test_point = gfx::Point(1, 1);
5531 result_layer =
5532 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5533 test_point, render_surface_layer_list);
5534 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145535
[email protected]fb661802013-03-25 01:59:325536 test_point = gfx::Point(99, 99);
5537 result_layer =
5538 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5539 test_point, render_surface_layer_list);
5540 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145541
[email protected]fb661802013-03-25 01:59:325542 // Hit checking for a point inside the touch event handler region should
5543 // return the root layer.
5544 test_point = gfx::Point(11, 11);
5545 result_layer =
5546 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5547 test_point, render_surface_layer_list);
5548 ASSERT_TRUE(result_layer);
5549 EXPECT_EQ(12345, result_layer->id());
5550
5551 test_point = gfx::Point(59, 59);
5552 result_layer =
5553 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5554 test_point, render_surface_layer_list);
5555 ASSERT_TRUE(result_layer);
5556 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145557}
5558
[email protected]989386c2013-07-18 21:37:235559TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325560 HitCheckingTouchHandlerRegionsForUninvertibleTransform) {
5561 FakeImplProxy proxy;
5562 FakeLayerTreeHostImpl host_impl(&proxy);
5563 scoped_ptr<LayerImpl> root =
5564 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145565
[email protected]fb661802013-03-25 01:59:325566 gfx::Transform uninvertible_transform;
[email protected]803f6b52013-09-12 00:51:265567 uninvertible_transform.matrix().set(0, 0, 0.0);
5568 uninvertible_transform.matrix().set(1, 1, 0.0);
5569 uninvertible_transform.matrix().set(2, 2, 0.0);
5570 uninvertible_transform.matrix().set(3, 3, 0.0);
[email protected]fb661802013-03-25 01:59:325571 ASSERT_FALSE(uninvertible_transform.IsInvertible());
[email protected]94f206c12012-08-25 00:09:145572
[email protected]fb661802013-03-25 01:59:325573 gfx::Transform identity_matrix;
5574 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5575 gfx::PointF anchor;
5576 gfx::PointF position;
5577 gfx::Size bounds(100, 100);
5578 SetLayerPropertiesForTesting(root.get(),
5579 uninvertible_transform,
5580 identity_matrix,
5581 anchor,
5582 position,
5583 bounds,
5584 false);
5585 root->SetDrawsContent(true);
5586 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145587
[email protected]50761e92013-03-29 20:51:285588 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535589 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5590 root.get(), root->bounds(), &render_surface_layer_list);
5591 inputs.can_adjust_raster_scales = true;
5592 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145593
[email protected]fb661802013-03-25 01:59:325594 // Sanity check the scenario we just created.
5595 ASSERT_EQ(1u, render_surface_layer_list.size());
5596 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5597 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
[email protected]de4afb5e2012-12-20 00:11:345598
[email protected]fb661802013-03-25 01:59:325599 // Hit checking any point should not hit the touch handler region on the
5600 // layer. If the invertible matrix is accidentally ignored and treated like an
5601 // identity, then the hit testing will incorrectly hit the layer when it
5602 // shouldn't.
5603 gfx::Point test_point(1, 1);
5604 LayerImpl* result_layer =
5605 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5606 test_point, render_surface_layer_list);
5607 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345608
[email protected]fb661802013-03-25 01:59:325609 test_point = gfx::Point(10, 10);
5610 result_layer =
5611 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5612 test_point, render_surface_layer_list);
5613 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345614
[email protected]fb661802013-03-25 01:59:325615 test_point = gfx::Point(10, 30);
5616 result_layer =
5617 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5618 test_point, render_surface_layer_list);
5619 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345620
[email protected]fb661802013-03-25 01:59:325621 test_point = gfx::Point(50, 50);
5622 result_layer =
5623 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5624 test_point, render_surface_layer_list);
5625 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145626
[email protected]fb661802013-03-25 01:59:325627 test_point = gfx::Point(67, 48);
5628 result_layer =
5629 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5630 test_point, render_surface_layer_list);
5631 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145632
[email protected]fb661802013-03-25 01:59:325633 test_point = gfx::Point(99, 99);
5634 result_layer =
5635 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5636 test_point, render_surface_layer_list);
5637 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145638
[email protected]fb661802013-03-25 01:59:325639 test_point = gfx::Point(-1, -1);
5640 result_layer =
5641 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5642 test_point, render_surface_layer_list);
5643 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145644}
5645
[email protected]989386c2013-07-18 21:37:235646TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325647 HitCheckingTouchHandlerRegionsForSinglePositionedLayer) {
5648 FakeImplProxy proxy;
5649 FakeLayerTreeHostImpl host_impl(&proxy);
5650 scoped_ptr<LayerImpl> root =
5651 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145652
[email protected]fb661802013-03-25 01:59:325653 gfx::Transform identity_matrix;
5654 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5655 gfx::PointF anchor;
5656 // this layer is positioned, and hit testing should correctly know where the
5657 // layer is located.
5658 gfx::PointF position(50.f, 50.f);
5659 gfx::Size bounds(100, 100);
5660 SetLayerPropertiesForTesting(root.get(),
5661 identity_matrix,
5662 identity_matrix,
5663 anchor,
5664 position,
5665 bounds,
5666 false);
5667 root->SetDrawsContent(true);
5668 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145669
[email protected]50761e92013-03-29 20:51:285670 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535671 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5672 root.get(), root->bounds(), &render_surface_layer_list);
5673 inputs.can_adjust_raster_scales = true;
5674 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145675
[email protected]fb661802013-03-25 01:59:325676 // Sanity check the scenario we just created.
5677 ASSERT_EQ(1u, render_surface_layer_list.size());
5678 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145679
[email protected]fb661802013-03-25 01:59:325680 // Hit checking for a point outside the layer should return a null pointer.
5681 gfx::Point test_point(49, 49);
5682 LayerImpl* result_layer =
5683 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5684 test_point, render_surface_layer_list);
5685 EXPECT_FALSE(result_layer);
5686
5687 // Even though the layer has a touch handler region containing (101, 101), it
5688 // should not be visible there since the root render surface would clamp it.
5689 test_point = gfx::Point(101, 101);
5690 result_layer =
5691 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5692 test_point, render_surface_layer_list);
5693 EXPECT_FALSE(result_layer);
5694
5695 // Hit checking for a point inside the layer, but outside the touch handler
5696 // region should return a null pointer.
5697 test_point = gfx::Point(51, 51);
5698 result_layer =
5699 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5700 test_point, render_surface_layer_list);
5701 EXPECT_FALSE(result_layer);
5702
5703 // Hit checking for a point inside the touch event handler region should
5704 // return the root layer.
5705 test_point = gfx::Point(61, 61);
5706 result_layer =
5707 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5708 test_point, render_surface_layer_list);
5709 ASSERT_TRUE(result_layer);
5710 EXPECT_EQ(12345, result_layer->id());
5711
5712 test_point = gfx::Point(99, 99);
5713 result_layer =
5714 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5715 test_point, render_surface_layer_list);
5716 ASSERT_TRUE(result_layer);
5717 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145718}
5719
[email protected]989386c2013-07-18 21:37:235720TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325721 HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) {
5722 // A layer's visible content rect is actually in the layer's content space.
5723 // The screen space transform converts from the layer's origin space to screen
5724 // space. This test makes sure that hit testing works correctly accounts for
5725 // the contents scale. A contents scale that is not 1 effectively forces a
5726 // non-identity transform between layer's content space and layer's origin
5727 // space. The hit testing code must take this into account.
5728 //
5729 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
5730 // contents scale is ignored, then hit checking will mis-interpret the visible
5731 // content rect as being larger than the actual bounds of the layer.
5732 //
5733 FakeImplProxy proxy;
5734 FakeLayerTreeHostImpl host_impl(&proxy);
5735 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145736
[email protected]fb661802013-03-25 01:59:325737 gfx::Transform identity_matrix;
5738 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145739
[email protected]fb661802013-03-25 01:59:325740 SetLayerPropertiesForTesting(root.get(),
5741 identity_matrix,
5742 identity_matrix,
5743 anchor,
5744 gfx::PointF(),
5745 gfx::Size(100, 100),
5746 false);
5747 {
5748 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5749 gfx::PointF position(25.f, 25.f);
5750 gfx::Size bounds(50, 50);
5751 scoped_ptr<LayerImpl> test_layer =
5752 LayerImpl::Create(host_impl.active_tree(), 12345);
5753 SetLayerPropertiesForTesting(test_layer.get(),
5754 identity_matrix,
5755 identity_matrix,
5756 anchor,
5757 position,
5758 bounds,
5759 false);
[email protected]94f206c12012-08-25 00:09:145760
[email protected]fb661802013-03-25 01:59:325761 // override content bounds and contents scale
5762 test_layer->SetContentBounds(gfx::Size(100, 100));
5763 test_layer->SetContentsScale(2, 2);
[email protected]94f206c12012-08-25 00:09:145764
[email protected]fb661802013-03-25 01:59:325765 test_layer->SetDrawsContent(true);
5766 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5767 root->AddChild(test_layer.Pass());
5768 }
5769
[email protected]50761e92013-03-29 20:51:285770 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535771 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5772 root.get(), root->bounds(), &render_surface_layer_list);
5773 inputs.can_adjust_raster_scales = true;
5774 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325775
5776 // Sanity check the scenario we just created.
5777 // The visible content rect for test_layer is actually 100x100, even though
5778 // its layout size is 50x50, positioned at 25x25.
5779 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:055780 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect());
[email protected]fb661802013-03-25 01:59:325781 ASSERT_EQ(1u, render_surface_layer_list.size());
5782 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5783
5784 // Hit checking for a point outside the layer should return a null pointer
5785 // (the root layer does not draw content, so it will not be tested either).
5786 gfx::Point test_point(76, 76);
5787 LayerImpl* result_layer =
5788 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5789 test_point, render_surface_layer_list);
5790 EXPECT_FALSE(result_layer);
5791
5792 // Hit checking for a point inside the layer, but outside the touch handler
5793 // region should return a null pointer.
5794 test_point = gfx::Point(26, 26);
5795 result_layer =
5796 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5797 test_point, render_surface_layer_list);
5798 EXPECT_FALSE(result_layer);
5799
5800 test_point = gfx::Point(34, 34);
5801 result_layer =
5802 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5803 test_point, render_surface_layer_list);
5804 EXPECT_FALSE(result_layer);
5805
5806 test_point = gfx::Point(65, 65);
5807 result_layer =
5808 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5809 test_point, render_surface_layer_list);
5810 EXPECT_FALSE(result_layer);
5811
5812 test_point = gfx::Point(74, 74);
5813 result_layer =
5814 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5815 test_point, render_surface_layer_list);
5816 EXPECT_FALSE(result_layer);
5817
5818 // Hit checking for a point inside the touch event handler region should
5819 // return the root layer.
5820 test_point = gfx::Point(35, 35);
5821 result_layer =
5822 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5823 test_point, render_surface_layer_list);
5824 ASSERT_TRUE(result_layer);
5825 EXPECT_EQ(12345, result_layer->id());
5826
5827 test_point = gfx::Point(64, 64);
5828 result_layer =
5829 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5830 test_point, render_surface_layer_list);
5831 ASSERT_TRUE(result_layer);
5832 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145833}
5834
[email protected]989386c2013-07-18 21:37:235835TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325836 HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) {
5837 // The layer's device_scale_factor and page_scale_factor should scale the
5838 // content rect and we should be able to hit the touch handler region by
5839 // scaling the points accordingly.
5840 FakeImplProxy proxy;
5841 FakeLayerTreeHostImpl host_impl(&proxy);
5842 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145843
[email protected]fb661802013-03-25 01:59:325844 gfx::Transform identity_matrix;
5845 gfx::PointF anchor;
5846 // Set the bounds of the root layer big enough to fit the child when scaled.
5847 SetLayerPropertiesForTesting(root.get(),
5848 identity_matrix,
5849 identity_matrix,
5850 anchor,
5851 gfx::PointF(),
5852 gfx::Size(100, 100),
5853 false);
5854 {
5855 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5856 gfx::PointF position(25.f, 25.f);
5857 gfx::Size bounds(50, 50);
5858 scoped_ptr<LayerImpl> test_layer =
5859 LayerImpl::Create(host_impl.active_tree(), 12345);
5860 SetLayerPropertiesForTesting(test_layer.get(),
5861 identity_matrix,
5862 identity_matrix,
5863 anchor,
5864 position,
5865 bounds,
5866 false);
[email protected]94f206c12012-08-25 00:09:145867
[email protected]fb661802013-03-25 01:59:325868 test_layer->SetDrawsContent(true);
5869 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5870 root->AddChild(test_layer.Pass());
5871 }
[email protected]94f206c12012-08-25 00:09:145872
[email protected]50761e92013-03-29 20:51:285873 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:325874 float device_scale_factor = 3.f;
5875 float page_scale_factor = 5.f;
[email protected]fb661802013-03-25 01:59:325876 gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize(
5877 gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor));
[email protected]7aad55f2013-07-26 11:25:535878
5879 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5880 root.get(), scaled_bounds_for_root, &render_surface_layer_list);
5881 inputs.device_scale_factor = device_scale_factor;
5882 inputs.page_scale_factor = page_scale_factor;
5883 inputs.page_scale_application_layer = root.get();
5884 inputs.can_adjust_raster_scales = true;
5885 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145886
[email protected]fb661802013-03-25 01:59:325887 // Sanity check the scenario we just created.
5888 // The visible content rect for test_layer is actually 100x100, even though
5889 // its layout size is 50x50, positioned at 25x25.
5890 LayerImpl* test_layer = root->children()[0];
5891 ASSERT_EQ(1u, render_surface_layer_list.size());
5892 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145893
[email protected]fb661802013-03-25 01:59:325894 // Check whether the child layer fits into the root after scaled.
5895 EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()),
5896 test_layer->visible_content_rect());
5897
5898 // Hit checking for a point outside the layer should return a null pointer
5899 // (the root layer does not draw content, so it will not be tested either).
5900 gfx::PointF test_point(76.f, 76.f);
5901 test_point =
5902 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5903 LayerImpl* result_layer =
5904 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5905 test_point, render_surface_layer_list);
5906 EXPECT_FALSE(result_layer);
5907
5908 // Hit checking for a point inside the layer, but outside the touch handler
5909 // region should return a null pointer.
5910 test_point = gfx::Point(26, 26);
5911 test_point =
5912 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5913 result_layer =
5914 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5915 test_point, render_surface_layer_list);
5916 EXPECT_FALSE(result_layer);
5917
5918 test_point = gfx::Point(34, 34);
5919 test_point =
5920 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5921 result_layer =
5922 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5923 test_point, render_surface_layer_list);
5924 EXPECT_FALSE(result_layer);
5925
5926 test_point = gfx::Point(65, 65);
5927 test_point =
5928 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5929 result_layer =
5930 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5931 test_point, render_surface_layer_list);
5932 EXPECT_FALSE(result_layer);
5933
5934 test_point = gfx::Point(74, 74);
5935 test_point =
5936 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5937 result_layer =
5938 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5939 test_point, render_surface_layer_list);
5940 EXPECT_FALSE(result_layer);
5941
5942 // Hit checking for a point inside the touch event handler region should
5943 // return the root layer.
5944 test_point = gfx::Point(35, 35);
5945 test_point =
5946 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5947 result_layer =
5948 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5949 test_point, render_surface_layer_list);
5950 ASSERT_TRUE(result_layer);
5951 EXPECT_EQ(12345, result_layer->id());
5952
5953 test_point = gfx::Point(64, 64);
5954 test_point =
5955 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5956 result_layer =
5957 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5958 test_point, render_surface_layer_list);
5959 ASSERT_TRUE(result_layer);
5960 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145961}
5962
[email protected]989386c2013-07-18 21:37:235963TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325964 HitCheckingTouchHandlerRegionsForSimpleClippedLayer) {
5965 // Test that hit-checking will only work for the visible portion of a layer,
5966 // and not the entire layer bounds. Here we just test the simple axis-aligned
5967 // case.
5968 gfx::Transform identity_matrix;
5969 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145970
[email protected]fb661802013-03-25 01:59:325971 FakeImplProxy proxy;
5972 FakeLayerTreeHostImpl host_impl(&proxy);
5973 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5974 SetLayerPropertiesForTesting(root.get(),
5975 identity_matrix,
5976 identity_matrix,
5977 anchor,
5978 gfx::PointF(),
5979 gfx::Size(100, 100),
5980 false);
5981 {
5982 scoped_ptr<LayerImpl> clipping_layer =
5983 LayerImpl::Create(host_impl.active_tree(), 123);
5984 // this layer is positioned, and hit testing should correctly know where the
5985 // layer is located.
5986 gfx::PointF position(25.f, 25.f);
5987 gfx::Size bounds(50, 50);
5988 SetLayerPropertiesForTesting(clipping_layer.get(),
5989 identity_matrix,
5990 identity_matrix,
5991 anchor,
5992 position,
5993 bounds,
5994 false);
5995 clipping_layer->SetMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:145996
[email protected]fb661802013-03-25 01:59:325997 scoped_ptr<LayerImpl> child =
5998 LayerImpl::Create(host_impl.active_tree(), 456);
5999 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
6000 position = gfx::PointF(-50.f, -50.f);
6001 bounds = gfx::Size(300, 300);
6002 SetLayerPropertiesForTesting(child.get(),
6003 identity_matrix,
6004 identity_matrix,
6005 anchor,
6006 position,
6007 bounds,
6008 false);
6009 child->SetDrawsContent(true);
6010 child->SetTouchEventHandlerRegion(touch_handler_region);
6011 clipping_layer->AddChild(child.Pass());
6012 root->AddChild(clipping_layer.Pass());
6013 }
[email protected]94f206c12012-08-25 00:09:146014
[email protected]50761e92013-03-29 20:51:286015 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536016 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6017 root.get(), root->bounds(), &render_surface_layer_list);
6018 inputs.can_adjust_raster_scales = true;
6019 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:326020
6021 // Sanity check the scenario we just created.
6022 ASSERT_EQ(1u, render_surface_layer_list.size());
6023 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236024 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:326025
6026 // Hit checking for a point outside the layer should return a null pointer.
6027 // Despite the child layer being very large, it should be clipped to the root
6028 // layer's bounds.
6029 gfx::Point test_point(24, 24);
6030 LayerImpl* result_layer =
6031 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6032 test_point, render_surface_layer_list);
6033 EXPECT_FALSE(result_layer);
6034
6035 // Hit checking for a point inside the layer, but outside the touch handler
6036 // region should return a null pointer.
6037 test_point = gfx::Point(35, 35);
6038 result_layer =
6039 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6040 test_point, render_surface_layer_list);
6041 EXPECT_FALSE(result_layer);
6042
6043 test_point = gfx::Point(74, 74);
6044 result_layer =
6045 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6046 test_point, render_surface_layer_list);
6047 EXPECT_FALSE(result_layer);
6048
6049 // Hit checking for a point inside the touch event handler region should
6050 // return the root layer.
6051 test_point = gfx::Point(25, 25);
6052 result_layer =
6053 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6054 test_point, render_surface_layer_list);
6055 ASSERT_TRUE(result_layer);
6056 EXPECT_EQ(456, result_layer->id());
6057
6058 test_point = gfx::Point(34, 34);
6059 result_layer =
6060 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6061 test_point, render_surface_layer_list);
6062 ASSERT_TRUE(result_layer);
6063 EXPECT_EQ(456, result_layer->id());
[email protected]94f206c12012-08-25 00:09:146064}
6065
[email protected]fb661802013-03-25 01:59:326066class NoScaleContentLayer : public ContentLayer {
6067 public:
6068 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
6069 return make_scoped_refptr(new NoScaleContentLayer(client));
6070 }
[email protected]94f206c12012-08-25 00:09:146071
[email protected]fb661802013-03-25 01:59:326072 virtual void CalculateContentsScale(float ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066073 float device_scale_factor,
6074 float page_scale_factor,
[email protected]fb661802013-03-25 01:59:326075 bool animating_transform_to_screen,
6076 float* contents_scale_x,
6077 float* contents_scale_y,
6078 gfx::Size* content_bounds) OVERRIDE {
6079 // Skip over the ContentLayer to the base Layer class.
6080 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066081 device_scale_factor,
6082 page_scale_factor,
[email protected]fb661802013-03-25 01:59:326083 animating_transform_to_screen,
6084 contents_scale_x,
6085 contents_scale_y,
6086 content_bounds);
6087 }
[email protected]94f206c12012-08-25 00:09:146088
[email protected]fb661802013-03-25 01:59:326089 protected:
6090 explicit NoScaleContentLayer(ContentLayerClient* client)
6091 : ContentLayer(client) {}
6092 virtual ~NoScaleContentLayer() {}
[email protected]518ee582012-10-24 18:29:446093};
6094
[email protected]fb661802013-03-25 01:59:326095scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
6096 ContentLayerClient* delegate) {
6097 scoped_refptr<NoScaleContentLayer> to_return =
6098 NoScaleContentLayer::Create(delegate);
6099 to_return->SetIsDrawable(true);
6100 return to_return;
[email protected]518ee582012-10-24 18:29:446101}
6102
[email protected]989386c2013-07-18 21:37:236103TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326104 // Verify draw and screen space transforms of layers not in a surface.
6105 MockContentLayerClient delegate;
6106 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:146107
[email protected]fb661802013-03-25 01:59:326108 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6109 SetLayerPropertiesForTesting(parent.get(),
6110 identity_matrix,
6111 identity_matrix,
6112 gfx::PointF(),
6113 gfx::PointF(),
6114 gfx::Size(100, 100),
6115 true);
[email protected]94f206c12012-08-25 00:09:146116
[email protected]fb661802013-03-25 01:59:326117 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6118 SetLayerPropertiesForTesting(child.get(),
6119 identity_matrix,
6120 identity_matrix,
6121 gfx::PointF(),
6122 gfx::PointF(2.f, 2.f),
6123 gfx::Size(10, 10),
6124 true);
[email protected]94f206c12012-08-25 00:09:146125
[email protected]fb661802013-03-25 01:59:326126 scoped_refptr<ContentLayer> child_empty =
6127 CreateDrawableContentLayer(&delegate);
6128 SetLayerPropertiesForTesting(child_empty.get(),
6129 identity_matrix,
6130 identity_matrix,
6131 gfx::PointF(),
6132 gfx::PointF(2.f, 2.f),
6133 gfx::Size(),
6134 true);
[email protected]f89f5632012-11-14 23:34:456135
[email protected]fb661802013-03-25 01:59:326136 scoped_refptr<NoScaleContentLayer> child_no_scale =
6137 CreateNoScaleDrawableContentLayer(&delegate);
6138 SetLayerPropertiesForTesting(child_no_scale.get(),
6139 identity_matrix,
6140 identity_matrix,
6141 gfx::PointF(),
6142 gfx::PointF(2.f, 2.f),
6143 gfx::Size(10, 10),
6144 true);
[email protected]94f206c12012-08-25 00:09:146145
[email protected]fb661802013-03-25 01:59:326146 parent->AddChild(child);
6147 parent->AddChild(child_empty);
6148 parent->AddChild(child_no_scale);
[email protected]94f206c12012-08-25 00:09:146149
[email protected]d600df7d2013-08-03 02:34:286150 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6151 host->SetRootLayer(parent);
6152
[email protected]fb661802013-03-25 01:59:326153 float device_scale_factor = 2.5f;
6154 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:146155
[email protected]7aad55f2013-07-26 11:25:536156 RenderSurfaceLayerList render_surface_layer_list;
6157 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6158 parent.get(), parent->bounds(), &render_surface_layer_list);
6159 inputs.device_scale_factor = device_scale_factor;
6160 inputs.page_scale_factor = page_scale_factor;
6161 inputs.can_adjust_raster_scales = true;
6162 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446163
[email protected]fb661802013-03-25 01:59:326164 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6165 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6166 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6167 child_empty);
6168 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]94f206c12012-08-25 00:09:146169
[email protected]fb661802013-03-25 01:59:326170 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:146171
[email protected]fb661802013-03-25 01:59:326172 // Verify parent transforms
6173 gfx::Transform expected_parent_transform;
6174 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6175 parent->screen_space_transform());
6176 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6177 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:146178
[email protected]fb661802013-03-25 01:59:326179 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056180 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:146181
[email protected]fb661802013-03-25 01:59:326182 gfx::RectF parent_draw_rect =
6183 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6184 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6185 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:146186
[email protected]2c7c6702013-03-26 03:14:056187 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326188 expected_parent_draw_rect.Scale(device_scale_factor);
6189 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6190 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146191
[email protected]fb661802013-03-25 01:59:326192 // Verify child and child_empty transforms. They should match.
6193 gfx::Transform expected_child_transform;
6194 expected_child_transform.Translate(
6195 device_scale_factor * child->position().x(),
6196 device_scale_factor * child->position().y());
6197 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6198 child->draw_transform());
6199 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6200 child->screen_space_transform());
6201 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6202 child_empty->draw_transform());
6203 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6204 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146205
[email protected]fb661802013-03-25 01:59:326206 // Verify results of transformed child and child_empty rects. They should
6207 // match.
[email protected]2c7c6702013-03-26 03:14:056208 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:146209
[email protected]fb661802013-03-25 01:59:326210 gfx::RectF child_draw_rect =
6211 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6212 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6213 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:146214
[email protected]fb661802013-03-25 01:59:326215 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
6216 child_empty->draw_transform(), child_content_bounds);
6217 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
6218 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:456219
[email protected]fb661802013-03-25 01:59:326220 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
6221 expected_child_draw_rect.Scale(device_scale_factor);
6222 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6223 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
6224 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
6225 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146226
[email protected]fb661802013-03-25 01:59:326227 // Verify child_no_scale transforms
6228 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6229 // All transforms operate on content rects. The child's content rect
6230 // incorporates device scale, but the child_no_scale does not; add it here.
6231 expected_child_no_scale_transform.Scale(device_scale_factor,
6232 device_scale_factor);
6233 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6234 child_no_scale->draw_transform());
6235 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6236 child_no_scale->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146237}
6238
[email protected]989386c2013-07-18 21:37:236239TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326240 // Verify draw and screen space transforms of layers in a surface.
6241 MockContentLayerClient delegate;
6242 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:096243
[email protected]fb661802013-03-25 01:59:326244 gfx::Transform perspective_matrix;
6245 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:096246
[email protected]fb661802013-03-25 01:59:326247 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:056248 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:096249
[email protected]9781afa2013-07-17 23:15:326250 scoped_refptr<Layer> root = Layer::Create();
6251
[email protected]fb661802013-03-25 01:59:326252 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6253 SetLayerPropertiesForTesting(parent.get(),
6254 identity_matrix,
6255 identity_matrix,
6256 gfx::PointF(),
6257 gfx::PointF(),
6258 gfx::Size(100, 100),
6259 true);
[email protected]1b30e8e2012-12-21 02:59:096260
[email protected]fb661802013-03-25 01:59:326261 scoped_refptr<ContentLayer> perspective_surface =
6262 CreateDrawableContentLayer(&delegate);
6263 SetLayerPropertiesForTesting(perspective_surface.get(),
6264 perspective_matrix * scale_small_matrix,
6265 identity_matrix,
6266 gfx::PointF(),
6267 gfx::PointF(2.f, 2.f),
6268 gfx::Size(10, 10),
6269 true);
[email protected]1b30e8e2012-12-21 02:59:096270
[email protected]fb661802013-03-25 01:59:326271 scoped_refptr<ContentLayer> scale_surface =
6272 CreateDrawableContentLayer(&delegate);
6273 SetLayerPropertiesForTesting(scale_surface.get(),
6274 scale_small_matrix,
6275 identity_matrix,
6276 gfx::PointF(),
6277 gfx::PointF(2.f, 2.f),
6278 gfx::Size(10, 10),
6279 true);
[email protected]1b30e8e2012-12-21 02:59:096280
[email protected]fb661802013-03-25 01:59:326281 perspective_surface->SetForceRenderSurface(true);
6282 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:096283
[email protected]fb661802013-03-25 01:59:326284 parent->AddChild(perspective_surface);
6285 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:326286 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:096287
[email protected]d600df7d2013-08-03 02:34:286288 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6289 host->SetRootLayer(root);
6290
[email protected]fb661802013-03-25 01:59:326291 float device_scale_factor = 2.5f;
6292 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:096293
[email protected]7aad55f2013-07-26 11:25:536294 RenderSurfaceLayerList render_surface_layer_list;
6295 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6296 root.get(), parent->bounds(), &render_surface_layer_list);
6297 inputs.device_scale_factor = device_scale_factor;
6298 inputs.page_scale_factor = page_scale_factor;
6299 inputs.page_scale_application_layer = root;
6300 inputs.can_adjust_raster_scales = true;
6301 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:096302
[email protected]fb661802013-03-25 01:59:326303 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6304 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6305 perspective_surface);
6306 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6307 scale_surface);
[email protected]1b30e8e2012-12-21 02:59:096308
[email protected]fb661802013-03-25 01:59:326309 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:096310
[email protected]fb661802013-03-25 01:59:326311 gfx::Transform expected_parent_draw_transform;
6312 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
6313 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096314
[email protected]fb661802013-03-25 01:59:326315 // The scaled surface is rendered at its appropriate scale, and drawn 1:1
6316 // into its target.
6317 gfx::Transform expected_scale_surface_draw_transform;
6318 expected_scale_surface_draw_transform.Translate(
6319 device_scale_factor * page_scale_factor * scale_surface->position().x(),
6320 device_scale_factor * page_scale_factor * scale_surface->position().y());
[email protected]fb661802013-03-25 01:59:326321 EXPECT_TRANSFORMATION_MATRIX_EQ(
6322 expected_scale_surface_draw_transform,
6323 scale_surface->render_surface()->draw_transform());
[email protected]a52c6ff2013-05-04 05:33:156324 gfx::Transform expected_scale_surface_layer_draw_transform =
6325 scale_small_matrix;
[email protected]fb661802013-03-25 01:59:326326 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform,
6327 scale_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096328
[email protected]fb661802013-03-25 01:59:326329 // The scale for the perspective surface is not known, so it is rendered 1:1
6330 // with the screen, and then scaled during drawing.
6331 gfx::Transform expected_perspective_surface_draw_transform;
6332 expected_perspective_surface_draw_transform.Translate(
6333 device_scale_factor * page_scale_factor *
6334 perspective_surface->position().x(),
6335 device_scale_factor * page_scale_factor *
6336 perspective_surface->position().y());
6337 expected_perspective_surface_draw_transform.PreconcatTransform(
6338 perspective_matrix);
6339 expected_perspective_surface_draw_transform.PreconcatTransform(
6340 scale_small_matrix);
6341 gfx::Transform expected_perspective_surface_layer_draw_transform;
6342 EXPECT_TRANSFORMATION_MATRIX_EQ(
6343 expected_perspective_surface_draw_transform,
6344 perspective_surface->render_surface()->draw_transform());
6345 EXPECT_TRANSFORMATION_MATRIX_EQ(
6346 expected_perspective_surface_layer_draw_transform,
6347 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096348}
6349
[email protected]989386c2013-07-18 21:37:236350TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:326351 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
6352 // Verify draw and screen space transforms of layers not in a surface.
6353 MockContentLayerClient delegate;
6354 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:476355
[email protected]fb661802013-03-25 01:59:326356 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6357 SetLayerPropertiesForTesting(parent.get(),
6358 identity_matrix,
6359 identity_matrix,
6360 gfx::PointF(),
6361 gfx::PointF(),
6362 gfx::Size(133, 133),
6363 true);
[email protected]904e9132012-11-01 00:12:476364
[email protected]fb661802013-03-25 01:59:326365 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6366 SetLayerPropertiesForTesting(child.get(),
6367 identity_matrix,
6368 identity_matrix,
6369 gfx::PointF(),
6370 gfx::PointF(),
6371 gfx::Size(13, 13),
6372 true);
[email protected]904e9132012-11-01 00:12:476373
[email protected]fb661802013-03-25 01:59:326374 scoped_refptr<NoScaleContentLayer> child_no_scale =
6375 CreateNoScaleDrawableContentLayer(&delegate);
6376 SetLayerPropertiesForTesting(child_no_scale.get(),
6377 identity_matrix,
6378 identity_matrix,
6379 gfx::PointF(),
6380 gfx::PointF(),
6381 gfx::Size(13, 13),
6382 true);
[email protected]904e9132012-11-01 00:12:476383
[email protected]fb661802013-03-25 01:59:326384 parent->AddChild(child);
6385 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:476386
[email protected]d600df7d2013-08-03 02:34:286387 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6388 host->SetRootLayer(parent);
6389
[email protected]fb661802013-03-25 01:59:326390 float device_scale_factor = 1.7f;
6391 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:476392
[email protected]7aad55f2013-07-26 11:25:536393 RenderSurfaceLayerList render_surface_layer_list;
6394 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6395 parent.get(), parent->bounds(), &render_surface_layer_list);
6396 inputs.device_scale_factor = device_scale_factor;
6397 inputs.page_scale_factor = page_scale_factor;
6398 inputs.page_scale_application_layer = parent.get();
6399 inputs.can_adjust_raster_scales = true;
6400 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:476401
[email protected]fb661802013-03-25 01:59:326402 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6403 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6404 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:476405
[email protected]fb661802013-03-25 01:59:326406 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:476407
[email protected]fb661802013-03-25 01:59:326408 // Verify parent transforms
6409 gfx::Transform expected_parent_transform;
6410 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6411 parent->screen_space_transform());
6412 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6413 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:476414
[email protected]fb661802013-03-25 01:59:326415 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056416 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:476417
[email protected]fb661802013-03-25 01:59:326418 gfx::RectF parent_draw_rect =
6419 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6420 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6421 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:476422
[email protected]2c7c6702013-03-26 03:14:056423 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326424 expected_parent_draw_rect.Scale(device_scale_factor);
6425 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
6426 expected_parent_draw_rect.set_height(
6427 ceil(expected_parent_draw_rect.height()));
6428 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6429 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476430
[email protected]fb661802013-03-25 01:59:326431 // Verify child transforms
6432 gfx::Transform expected_child_transform;
6433 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6434 child->draw_transform());
6435 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6436 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476437
[email protected]fb661802013-03-25 01:59:326438 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:056439 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:476440
[email protected]fb661802013-03-25 01:59:326441 gfx::RectF child_draw_rect =
6442 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6443 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6444 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:476445
[email protected]2c7c6702013-03-26 03:14:056446 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:326447 expected_child_draw_rect.Scale(device_scale_factor);
6448 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
6449 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
6450 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6451 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476452
[email protected]fb661802013-03-25 01:59:326453 // Verify child_no_scale transforms
6454 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6455 // All transforms operate on content rects. The child's content rect
6456 // incorporates device scale, but the child_no_scale does not; add it here.
6457 expected_child_no_scale_transform.Scale(device_scale_factor,
6458 device_scale_factor);
6459 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6460 child_no_scale->draw_transform());
6461 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6462 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476463}
6464
[email protected]989386c2013-07-18 21:37:236465TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:326466 MockContentLayerClient delegate;
6467 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446468
[email protected]fb661802013-03-25 01:59:326469 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266470 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326471 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446472
[email protected]fb661802013-03-25 01:59:326473 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266474 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326475 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446476
[email protected]35a99a12013-05-09 23:52:296477 scoped_refptr<Layer> root = Layer::Create();
6478 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446479
[email protected]fb661802013-03-25 01:59:326480 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6481 SetLayerPropertiesForTesting(parent.get(),
6482 parent_scale_matrix,
6483 identity_matrix,
6484 gfx::PointF(),
6485 gfx::PointF(),
6486 gfx::Size(100, 100),
6487 true);
[email protected]518ee582012-10-24 18:29:446488
[email protected]fb661802013-03-25 01:59:326489 scoped_refptr<ContentLayer> child_scale =
6490 CreateDrawableContentLayer(&delegate);
6491 SetLayerPropertiesForTesting(child_scale.get(),
6492 child_scale_matrix,
6493 identity_matrix,
6494 gfx::PointF(),
6495 gfx::PointF(2.f, 2.f),
6496 gfx::Size(10, 10),
6497 true);
[email protected]518ee582012-10-24 18:29:446498
[email protected]fb661802013-03-25 01:59:326499 scoped_refptr<ContentLayer> child_empty =
6500 CreateDrawableContentLayer(&delegate);
6501 SetLayerPropertiesForTesting(child_empty.get(),
6502 child_scale_matrix,
6503 identity_matrix,
6504 gfx::PointF(),
6505 gfx::PointF(2.f, 2.f),
6506 gfx::Size(),
6507 true);
[email protected]f89f5632012-11-14 23:34:456508
[email protected]fb661802013-03-25 01:59:326509 scoped_refptr<NoScaleContentLayer> child_no_scale =
6510 CreateNoScaleDrawableContentLayer(&delegate);
6511 SetLayerPropertiesForTesting(child_no_scale.get(),
6512 child_scale_matrix,
6513 identity_matrix,
6514 gfx::PointF(),
6515 gfx::PointF(12.f, 12.f),
6516 gfx::Size(10, 10),
6517 true);
[email protected]518ee582012-10-24 18:29:446518
[email protected]35a99a12013-05-09 23:52:296519 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446520
[email protected]fb661802013-03-25 01:59:326521 parent->AddChild(child_scale);
6522 parent->AddChild(child_empty);
6523 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:446524
[email protected]d600df7d2013-08-03 02:34:286525 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6526 host->SetRootLayer(root);
6527
[email protected]fb661802013-03-25 01:59:326528 float device_scale_factor = 2.5f;
6529 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:446530
[email protected]989386c2013-07-18 21:37:236531 {
6532 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536533 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6534 root.get(), root->bounds(), &render_surface_layer_list);
6535 inputs.device_scale_factor = device_scale_factor;
6536 inputs.page_scale_factor = page_scale_factor;
6537 inputs.page_scale_application_layer = root.get();
6538 inputs.can_adjust_raster_scales = true;
6539 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446540
[email protected]989386c2013-07-18 21:37:236541 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6542 initial_parent_scale, parent);
6543 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6544 initial_parent_scale * initial_child_scale,
6545 child_scale);
6546 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6547 initial_parent_scale * initial_child_scale,
6548 child_empty);
6549 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:446550
[email protected]989386c2013-07-18 21:37:236551 // The parent is scaled up and shouldn't need to scale during draw. The
6552 // child that can scale its contents should also not need to scale during
6553 // draw. This shouldn't change if the child has empty bounds. The other
6554 // children should.
[email protected]803f6b52013-09-12 00:51:266555 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
6556 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
6557 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
6558 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
6559 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
6560 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236561 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6562 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266563 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:236564 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266565 initial_parent_scale * initial_child_scale,
6566 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:236567 }
[email protected]518ee582012-10-24 18:29:446568
[email protected]fb661802013-03-25 01:59:326569 // If the device_scale_factor or page_scale_factor changes, then it should be
6570 // updated using the initial transform as the raster scale.
6571 device_scale_factor = 2.25f;
6572 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:446573
[email protected]989386c2013-07-18 21:37:236574 {
6575 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536576 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6577 root.get(), root->bounds(), &render_surface_layer_list);
6578 inputs.device_scale_factor = device_scale_factor;
6579 inputs.page_scale_factor = page_scale_factor;
6580 inputs.page_scale_application_layer = root.get();
6581 inputs.can_adjust_raster_scales = true;
6582 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6583
6584 EXPECT_CONTENTS_SCALE_EQ(
6585 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:236586 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536587 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:236588 child_scale);
6589 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6590 initial_parent_scale * initial_child_scale,
6591 child_empty);
6592 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6593 }
[email protected]d0518202013-02-08 02:06:496594
[email protected]fb661802013-03-25 01:59:326595 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:266596 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326597 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
6598 second_child_scale / initial_child_scale);
6599 child_scale->SetTransform(child_scale_matrix);
6600 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:496601
[email protected]989386c2013-07-18 21:37:236602 {
6603 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536604 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6605 root.get(), root->bounds(), &render_surface_layer_list);
6606 inputs.device_scale_factor = device_scale_factor;
6607 inputs.page_scale_factor = page_scale_factor;
6608 inputs.page_scale_application_layer = root.get();
6609 inputs.can_adjust_raster_scales = true;
6610 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496611
[email protected]989386c2013-07-18 21:37:236612 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6613 initial_parent_scale,
6614 parent);
6615 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6616 child_scale);
6617 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6618 child_empty);
6619 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6620 }
[email protected]d0518202013-02-08 02:06:496621
[email protected]fb661802013-03-25 01:59:326622 // If the device_scale_factor or page_scale_factor changes, then it should be
6623 // updated, but still using 1.0 as the raster scale.
6624 device_scale_factor = 2.75f;
6625 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:496626
[email protected]989386c2013-07-18 21:37:236627 {
6628 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536629 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6630 root.get(), root->bounds(), &render_surface_layer_list);
6631 inputs.device_scale_factor = device_scale_factor;
6632 inputs.page_scale_factor = page_scale_factor;
6633 inputs.page_scale_application_layer = root.get();
6634 inputs.can_adjust_raster_scales = true;
6635 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496636
[email protected]989386c2013-07-18 21:37:236637 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6638 initial_parent_scale,
6639 parent);
6640 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6641 child_scale);
6642 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6643 child_empty);
6644 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6645 }
[email protected]518ee582012-10-24 18:29:446646}
6647
[email protected]989386c2013-07-18 21:37:236648TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:296649 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:326650 MockContentLayerClient delegate;
6651 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:216652
[email protected]fb661802013-03-25 01:59:326653 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266654 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:326655 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:216656
[email protected]fb661802013-03-25 01:59:326657 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266658 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326659 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:216660
[email protected]35a99a12013-05-09 23:52:296661 scoped_refptr<Layer> root = Layer::Create();
6662 root->SetBounds(gfx::Size(100, 100));
6663
[email protected]fb661802013-03-25 01:59:326664 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6665 SetLayerPropertiesForTesting(parent.get(),
6666 parent_scale_matrix,
6667 identity_matrix,
6668 gfx::PointF(),
6669 gfx::PointF(),
6670 gfx::Size(100, 100),
6671 true);
[email protected]11ec92972012-11-10 03:06:216672
[email protected]fb661802013-03-25 01:59:326673 scoped_refptr<ContentLayer> child_scale =
6674 CreateDrawableContentLayer(&delegate);
6675 SetLayerPropertiesForTesting(child_scale.get(),
6676 child_scale_matrix,
6677 identity_matrix,
6678 gfx::PointF(),
6679 gfx::PointF(2.f, 2.f),
6680 gfx::Size(10, 10),
6681 true);
[email protected]11ec92972012-11-10 03:06:216682
[email protected]35a99a12013-05-09 23:52:296683 scoped_refptr<ContentLayer> child_empty =
6684 CreateDrawableContentLayer(&delegate);
6685 SetLayerPropertiesForTesting(child_empty.get(),
6686 child_scale_matrix,
6687 identity_matrix,
6688 gfx::PointF(),
6689 gfx::PointF(2.f, 2.f),
6690 gfx::Size(),
6691 true);
6692
6693 scoped_refptr<NoScaleContentLayer> child_no_scale =
6694 CreateNoScaleDrawableContentLayer(&delegate);
6695 SetLayerPropertiesForTesting(child_no_scale.get(),
6696 child_scale_matrix,
6697 identity_matrix,
6698 gfx::PointF(),
6699 gfx::PointF(12.f, 12.f),
6700 gfx::Size(10, 10),
6701 true);
6702
6703 root->AddChild(parent);
6704
6705 parent->AddChild(child_scale);
6706 parent->AddChild(child_empty);
6707 parent->AddChild(child_no_scale);
6708
[email protected]d600df7d2013-08-03 02:34:286709 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6710 host->SetRootLayer(root);
6711
[email protected]989386c2013-07-18 21:37:236712 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:296713
6714 float device_scale_factor = 2.5f;
6715 float page_scale_factor = 1.f;
6716
[email protected]7aad55f2013-07-26 11:25:536717 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6718 root.get(), root->bounds(), &render_surface_layer_list);
6719 inputs.device_scale_factor = device_scale_factor;
6720 inputs.page_scale_factor = page_scale_factor;
6721 inputs.page_scale_application_layer = root.get(),
6722 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:296723
6724 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6725 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6726 child_scale);
6727 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6728 child_empty);
6729 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6730
6731 // Since the transform scale does not affect contents scale, it should affect
6732 // the draw transform instead.
6733 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266734 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296735 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:266736 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296737 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266738 child_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296739 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266740 child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296741 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266742 child_empty->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296743 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:266744 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296745 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266746 initial_parent_scale * initial_child_scale,
6747 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:296748 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:266749 initial_parent_scale * initial_child_scale,
6750 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:296751}
6752
[email protected]989386c2013-07-18 21:37:236753TEST_F(LayerTreeHostCommonTest, SmallContentsScale) {
[email protected]35a99a12013-05-09 23:52:296754 MockContentLayerClient delegate;
6755 gfx::Transform identity_matrix;
6756
6757 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266758 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:296759 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6760
6761 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266762 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:296763 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6764
6765 scoped_refptr<Layer> root = Layer::Create();
6766 root->SetBounds(gfx::Size(100, 100));
6767
6768 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6769 SetLayerPropertiesForTesting(parent.get(),
6770 parent_scale_matrix,
6771 identity_matrix,
6772 gfx::PointF(),
6773 gfx::PointF(),
6774 gfx::Size(100, 100),
6775 true);
6776
6777 scoped_refptr<ContentLayer> child_scale =
6778 CreateDrawableContentLayer(&delegate);
6779 SetLayerPropertiesForTesting(child_scale.get(),
6780 child_scale_matrix,
6781 identity_matrix,
6782 gfx::PointF(),
6783 gfx::PointF(2.f, 2.f),
6784 gfx::Size(10, 10),
6785 true);
6786
6787 root->AddChild(parent);
6788
[email protected]fb661802013-03-25 01:59:326789 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:216790
[email protected]d600df7d2013-08-03 02:34:286791 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6792 host->SetRootLayer(root);
6793
[email protected]fb661802013-03-25 01:59:326794 float device_scale_factor = 2.5f;
6795 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:216796
[email protected]989386c2013-07-18 21:37:236797 {
6798 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536799 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6800 root.get(), root->bounds(), &render_surface_layer_list);
6801 inputs.device_scale_factor = device_scale_factor;
6802 inputs.page_scale_factor = page_scale_factor;
6803 inputs.page_scale_application_layer = root.get();
6804 inputs.can_adjust_raster_scales = true;
6805 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216806
[email protected]989386c2013-07-18 21:37:236807 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6808 initial_parent_scale,
6809 parent);
6810 // The child's scale is < 1, so we should not save and use that scale
6811 // factor.
6812 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1,
6813 child_scale);
6814 }
[email protected]11ec92972012-11-10 03:06:216815
[email protected]fb661802013-03-25 01:59:326816 // When chilld's total scale becomes >= 1, we should save and use that scale
6817 // factor.
6818 child_scale_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:266819 SkMScalar final_child_scale = 0.75;
[email protected]fb661802013-03-25 01:59:326820 child_scale_matrix.Scale(final_child_scale, final_child_scale);
6821 child_scale->SetTransform(child_scale_matrix);
[email protected]11ec92972012-11-10 03:06:216822
[email protected]989386c2013-07-18 21:37:236823 {
6824 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536825 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6826 root.get(), root->bounds(), &render_surface_layer_list);
6827 inputs.device_scale_factor = device_scale_factor;
6828 inputs.page_scale_factor = page_scale_factor;
6829 inputs.page_scale_application_layer = root.get();
6830 inputs.can_adjust_raster_scales = true;
6831 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216832
[email protected]989386c2013-07-18 21:37:236833 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6834 initial_parent_scale,
6835 parent);
6836 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6837 initial_parent_scale * final_child_scale,
6838 child_scale);
6839 }
[email protected]11ec92972012-11-10 03:06:216840}
6841
[email protected]989386c2013-07-18 21:37:236842TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:326843 MockContentLayerClient delegate;
6844 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446845
[email protected]fb661802013-03-25 01:59:326846 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266847 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:326848 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446849
[email protected]fb661802013-03-25 01:59:326850 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:266851 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:326852 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446853
[email protected]35a99a12013-05-09 23:52:296854 scoped_refptr<Layer> root = Layer::Create();
6855 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446856
[email protected]fb661802013-03-25 01:59:326857 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6858 SetLayerPropertiesForTesting(parent.get(),
6859 parent_scale_matrix,
6860 identity_matrix,
6861 gfx::PointF(),
6862 gfx::PointF(),
6863 gfx::Size(100, 100),
6864 true);
[email protected]518ee582012-10-24 18:29:446865
[email protected]fb661802013-03-25 01:59:326866 scoped_refptr<ContentLayer> surface_scale =
6867 CreateDrawableContentLayer(&delegate);
6868 SetLayerPropertiesForTesting(surface_scale.get(),
6869 child_scale_matrix,
6870 identity_matrix,
6871 gfx::PointF(),
6872 gfx::PointF(2.f, 2.f),
6873 gfx::Size(10, 10),
6874 true);
[email protected]518ee582012-10-24 18:29:446875
[email protected]fb661802013-03-25 01:59:326876 scoped_refptr<ContentLayer> surface_scale_child_scale =
6877 CreateDrawableContentLayer(&delegate);
6878 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
6879 child_scale_matrix,
6880 identity_matrix,
6881 gfx::PointF(),
6882 gfx::PointF(),
6883 gfx::Size(10, 10),
6884 true);
[email protected]518ee582012-10-24 18:29:446885
[email protected]fb661802013-03-25 01:59:326886 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
6887 CreateNoScaleDrawableContentLayer(&delegate);
6888 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
6889 child_scale_matrix,
6890 identity_matrix,
6891 gfx::PointF(),
6892 gfx::PointF(),
6893 gfx::Size(10, 10),
6894 true);
[email protected]518ee582012-10-24 18:29:446895
[email protected]fb661802013-03-25 01:59:326896 scoped_refptr<NoScaleContentLayer> surface_no_scale =
6897 CreateNoScaleDrawableContentLayer(&delegate);
6898 SetLayerPropertiesForTesting(surface_no_scale.get(),
6899 child_scale_matrix,
6900 identity_matrix,
6901 gfx::PointF(),
6902 gfx::PointF(12.f, 12.f),
6903 gfx::Size(10, 10),
6904 true);
[email protected]518ee582012-10-24 18:29:446905
[email protected]fb661802013-03-25 01:59:326906 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
6907 CreateDrawableContentLayer(&delegate);
6908 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
6909 child_scale_matrix,
6910 identity_matrix,
6911 gfx::PointF(),
6912 gfx::PointF(),
6913 gfx::Size(10, 10),
6914 true);
[email protected]518ee582012-10-24 18:29:446915
[email protected]fb661802013-03-25 01:59:326916 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
6917 CreateNoScaleDrawableContentLayer(&delegate);
6918 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
6919 child_scale_matrix,
6920 identity_matrix,
6921 gfx::PointF(),
6922 gfx::PointF(),
6923 gfx::Size(10, 10),
6924 true);
[email protected]518ee582012-10-24 18:29:446925
[email protected]35a99a12013-05-09 23:52:296926 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446927
[email protected]fb661802013-03-25 01:59:326928 parent->AddChild(surface_scale);
6929 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:446930
[email protected]fb661802013-03-25 01:59:326931 surface_scale->SetForceRenderSurface(true);
6932 surface_scale->AddChild(surface_scale_child_scale);
6933 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446934
[email protected]fb661802013-03-25 01:59:326935 surface_no_scale->SetForceRenderSurface(true);
6936 surface_no_scale->AddChild(surface_no_scale_child_scale);
6937 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446938
[email protected]d600df7d2013-08-03 02:34:286939 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6940 host->SetRootLayer(root);
6941
[email protected]803f6b52013-09-12 00:51:266942 SkMScalar device_scale_factor = 5;
6943 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:446944
[email protected]7aad55f2013-07-26 11:25:536945 RenderSurfaceLayerList render_surface_layer_list;
6946 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6947 root.get(), root->bounds(), &render_surface_layer_list);
6948 inputs.device_scale_factor = device_scale_factor;
6949 inputs.page_scale_factor = page_scale_factor;
6950 inputs.page_scale_application_layer = root.get();
6951 inputs.can_adjust_raster_scales = true;
6952 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6953
6954 EXPECT_CONTENTS_SCALE_EQ(
6955 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:196956 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536957 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:326958 surface_scale);
6959 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
6960 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:326961 device_scale_factor * page_scale_factor * initial_parent_scale *
6962 initial_child_scale * initial_child_scale,
6963 surface_scale_child_scale);
6964 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
6965 EXPECT_CONTENTS_SCALE_EQ(
6966 device_scale_factor * page_scale_factor * initial_parent_scale *
6967 initial_child_scale * initial_child_scale,
6968 surface_no_scale_child_scale);
6969 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446970
[email protected]fb661802013-03-25 01:59:326971 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:266972 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
6973 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446974
[email protected]fb661802013-03-25 01:59:326975 // RenderSurfaces should always be 1:1 with their target.
6976 EXPECT_FLOAT_EQ(
6977 1.0,
[email protected]803f6b52013-09-12 00:51:266978 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326979 EXPECT_FLOAT_EQ(
6980 1.0,
[email protected]803f6b52013-09-12 00:51:266981 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446982
[email protected]fb661802013-03-25 01:59:326983 // The surface_scale can apply contents scale so the layer shouldn't need to
6984 // scale during draw.
[email protected]803f6b52013-09-12 00:51:266985 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
6986 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446987
[email protected]fb661802013-03-25 01:59:326988 // The surface_scale_child_scale can apply contents scale so it shouldn't need
6989 // to scale during draw.
6990 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:266991 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:326992 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:266993 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:446994
[email protected]fb661802013-03-25 01:59:326995 // The surface_scale_child_no_scale can not apply contents scale, so it needs
6996 // to be scaled during draw.
6997 EXPECT_FLOAT_EQ(
6998 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:266999 initial_child_scale * initial_child_scale,
7000 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327001 EXPECT_FLOAT_EQ(
7002 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267003 initial_child_scale * initial_child_scale,
7004 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447005
[email protected]fb661802013-03-25 01:59:327006 // RenderSurfaces should always be 1:1 with their target.
7007 EXPECT_FLOAT_EQ(
7008 1.0,
[email protected]803f6b52013-09-12 00:51:267009 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327010 EXPECT_FLOAT_EQ(
7011 1.0,
[email protected]803f6b52013-09-12 00:51:267012 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447013
[email protected]fb661802013-03-25 01:59:327014 // The surface_no_scale layer can not apply contents scale, so it needs to be
7015 // scaled during draw.
7016 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:267017 initial_parent_scale * initial_child_scale,
7018 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327019 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:267020 initial_parent_scale * initial_child_scale,
7021 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447022
[email protected]fb661802013-03-25 01:59:327023 // The surface_scale_child_scale can apply contents scale so it shouldn't need
7024 // to scale during draw.
7025 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267026 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327027 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:267028 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447029
[email protected]fb661802013-03-25 01:59:327030 // The surface_scale_child_no_scale can not apply contents scale, so it needs
7031 // to be scaled during draw.
7032 EXPECT_FLOAT_EQ(
7033 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267034 initial_child_scale * initial_child_scale,
7035 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327036 EXPECT_FLOAT_EQ(
7037 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:267038 initial_child_scale * initial_child_scale,
7039 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297040}
[email protected]518ee582012-10-24 18:29:447041
[email protected]989386c2013-07-18 21:37:237042TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:297043 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
7044 MockContentLayerClient delegate;
7045 gfx::Transform identity_matrix;
7046
7047 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267048 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:297049 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
7050
7051 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267052 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:297053 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
7054
7055 scoped_refptr<Layer> root = Layer::Create();
7056 root->SetBounds(gfx::Size(100, 100));
7057
7058 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7059 SetLayerPropertiesForTesting(parent.get(),
7060 parent_scale_matrix,
7061 identity_matrix,
7062 gfx::PointF(),
7063 gfx::PointF(),
7064 gfx::Size(100, 100),
7065 true);
7066
7067 scoped_refptr<ContentLayer> surface_scale =
7068 CreateDrawableContentLayer(&delegate);
7069 SetLayerPropertiesForTesting(surface_scale.get(),
7070 child_scale_matrix,
7071 identity_matrix,
7072 gfx::PointF(),
7073 gfx::PointF(2.f, 2.f),
7074 gfx::Size(10, 10),
7075 true);
7076
7077 scoped_refptr<ContentLayer> surface_scale_child_scale =
7078 CreateDrawableContentLayer(&delegate);
7079 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
7080 child_scale_matrix,
7081 identity_matrix,
7082 gfx::PointF(),
7083 gfx::PointF(),
7084 gfx::Size(10, 10),
7085 true);
7086
7087 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
7088 CreateNoScaleDrawableContentLayer(&delegate);
7089 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
7090 child_scale_matrix,
7091 identity_matrix,
7092 gfx::PointF(),
7093 gfx::PointF(),
7094 gfx::Size(10, 10),
7095 true);
7096
7097 scoped_refptr<NoScaleContentLayer> surface_no_scale =
7098 CreateNoScaleDrawableContentLayer(&delegate);
7099 SetLayerPropertiesForTesting(surface_no_scale.get(),
7100 child_scale_matrix,
7101 identity_matrix,
7102 gfx::PointF(),
7103 gfx::PointF(12.f, 12.f),
7104 gfx::Size(10, 10),
7105 true);
7106
7107 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
7108 CreateDrawableContentLayer(&delegate);
7109 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
7110 child_scale_matrix,
7111 identity_matrix,
7112 gfx::PointF(),
7113 gfx::PointF(),
7114 gfx::Size(10, 10),
7115 true);
7116
7117 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
7118 CreateNoScaleDrawableContentLayer(&delegate);
7119 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
7120 child_scale_matrix,
7121 identity_matrix,
7122 gfx::PointF(),
7123 gfx::PointF(),
7124 gfx::Size(10, 10),
7125 true);
7126
7127 root->AddChild(parent);
7128
7129 parent->AddChild(surface_scale);
7130 parent->AddChild(surface_no_scale);
7131
7132 surface_scale->SetForceRenderSurface(true);
7133 surface_scale->AddChild(surface_scale_child_scale);
7134 surface_scale->AddChild(surface_scale_child_no_scale);
7135
7136 surface_no_scale->SetForceRenderSurface(true);
7137 surface_no_scale->AddChild(surface_no_scale_child_scale);
7138 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
7139
[email protected]d600df7d2013-08-03 02:34:287140 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7141 host->SetRootLayer(root);
7142
[email protected]989386c2013-07-18 21:37:237143 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:297144
[email protected]803f6b52013-09-12 00:51:267145 SkMScalar device_scale_factor = 5.0;
7146 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:537147 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7148 root.get(), root->bounds(), &render_surface_layer_list);
7149 inputs.device_scale_factor = device_scale_factor;
7150 inputs.page_scale_factor = page_scale_factor;
7151 inputs.page_scale_application_layer = root.get();
7152 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:297153
[email protected]35a99a12013-05-09 23:52:297154 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7155 parent);
7156 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7157 surface_scale);
7158 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
7159 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7160 surface_scale_child_scale);
7161 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
7162 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7163 surface_no_scale_child_scale);
7164 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
7165
7166 // The parent is scaled up during draw, since its contents are not scaled by
7167 // the transform hierarchy.
7168 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267169 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297170 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:267171 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297172
7173 // The child surface is scaled up during draw since its subtree is not scaled
7174 // by the transform hierarchy.
7175 EXPECT_FLOAT_EQ(
7176 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267177 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297178 EXPECT_FLOAT_EQ(
7179 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267180 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297181
7182 // The surface_scale's RenderSurface is scaled during draw, so the layer does
7183 // not need to be scaled when drawing into its surface.
[email protected]803f6b52013-09-12 00:51:267184 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
7185 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447186
[email protected]35a99a12013-05-09 23:52:297187 // The surface_scale_child_scale is scaled when drawing into its surface,
7188 // since its content bounds are not scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:327189 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297190 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267191 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327192 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297193 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267194 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447195
[email protected]35a99a12013-05-09 23:52:297196 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
7197 // needs to be scaled by the device and page scale factors, along with the
7198 // transform hierarchy.
[email protected]fb661802013-03-25 01:59:327199 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297200 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267201 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297202 EXPECT_FLOAT_EQ(
7203 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267204 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297205
7206 // The child surface is scaled up during draw since its subtree is not scaled
7207 // by the transform hierarchy.
7208 EXPECT_FLOAT_EQ(
7209 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267210 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327211 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297212 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267213 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447214
[email protected]35a99a12013-05-09 23:52:297215 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
7216 // be scaled by the device and page scale factors. Its surface is already
7217 // scaled by the transform hierarchy so those don't need to scale the layer's
7218 // drawing.
7219 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267220 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297221 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:267222 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297223
7224 // The surface_no_scale_child_scale has its contents scaled by the page and
7225 // device scale factors, but needs to be scaled by the transform hierarchy
7226 // when drawing.
[email protected]fb661802013-03-25 01:59:327227 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297228 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267229 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:327230 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297231 initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267232 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:297233
7234 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
7235 // needs to be scaled by the device and page scale factors. It also needs to
7236 // be scaled by any transform heirarchy below its target surface.
7237 EXPECT_FLOAT_EQ(
7238 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267239 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:297240 EXPECT_FLOAT_EQ(
7241 device_scale_factor * page_scale_factor * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:267242 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:447243}
7244
[email protected]989386c2013-07-18 21:37:237245TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:327246 MockContentLayerClient delegate;
7247 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267248
[email protected]fb661802013-03-25 01:59:327249 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267250 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:327251 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:267252
[email protected]fb661802013-03-25 01:59:327253 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:267254 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:327255 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:267256
[email protected]35a99a12013-05-09 23:52:297257 scoped_refptr<Layer> root = Layer::Create();
7258 root->SetBounds(gfx::Size(100, 100));
7259
[email protected]fb661802013-03-25 01:59:327260 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7261 SetLayerPropertiesForTesting(parent.get(),
7262 parent_scale_matrix,
7263 identity_matrix,
7264 gfx::PointF(),
7265 gfx::PointF(),
7266 gfx::Size(100, 100),
7267 true);
[email protected]6a9cff92012-11-08 11:53:267268
[email protected]fb661802013-03-25 01:59:327269 scoped_refptr<ContentLayer> child_scale =
7270 CreateDrawableContentLayer(&delegate);
7271 SetLayerPropertiesForTesting(child_scale.get(),
7272 child_scale_matrix,
7273 identity_matrix,
7274 gfx::PointF(),
7275 gfx::PointF(2.f, 2.f),
7276 gfx::Size(10, 10),
7277 true);
[email protected]6a9cff92012-11-08 11:53:267278
[email protected]35a99a12013-05-09 23:52:297279 root->AddChild(parent);
7280
[email protected]fb661802013-03-25 01:59:327281 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:267282
[email protected]d600df7d2013-08-03 02:34:287283 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7284 host->SetRootLayer(root);
7285
[email protected]fb661802013-03-25 01:59:327286 // Now put an animating transform on child.
7287 int animation_id = AddAnimatedTransformToController(
7288 child_scale->layer_animation_controller(), 10.0, 30, 0);
[email protected]6a9cff92012-11-08 11:53:267289
[email protected]989386c2013-07-18 21:37:237290 {
7291 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537292 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7293 root.get(), root->bounds(), &render_surface_layer_list);
7294 inputs.can_adjust_raster_scales = true;
7295 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267296
[email protected]989386c2013-07-18 21:37:237297 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7298 // The layers with animating transforms should not compute a contents scale
7299 // other than 1 until they finish animating.
7300 EXPECT_CONTENTS_SCALE_EQ(1, child_scale);
7301 }
[email protected]6a9cff92012-11-08 11:53:267302
[email protected]fb661802013-03-25 01:59:327303 // Remove the animation, now it can save a raster scale.
7304 child_scale->layer_animation_controller()->RemoveAnimation(animation_id);
[email protected]6a9cff92012-11-08 11:53:267305
[email protected]989386c2013-07-18 21:37:237306 {
7307 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537308 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7309 root.get(), root->bounds(), &render_surface_layer_list);
7310 inputs.can_adjust_raster_scales = true;
7311 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267312
[email protected]989386c2013-07-18 21:37:237313 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7314 // The layers with animating transforms should not compute a contents scale
7315 // other than 1 until they finish animating.
7316 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale,
7317 child_scale);
7318 }
[email protected]6a9cff92012-11-08 11:53:267319}
7320
[email protected]989386c2013-07-18 21:37:237321TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:327322 MockContentLayerClient delegate;
7323 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267324
[email protected]fb661802013-03-25 01:59:327325 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7326 SetLayerPropertiesForTesting(parent.get(),
7327 identity_matrix,
7328 identity_matrix,
7329 gfx::PointF(),
7330 gfx::PointF(),
7331 gfx::Size(30, 30),
7332 true);
[email protected]94f206c12012-08-25 00:09:147333
[email protected]fb661802013-03-25 01:59:327334 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7335 SetLayerPropertiesForTesting(child.get(),
7336 identity_matrix,
7337 identity_matrix,
7338 gfx::PointF(),
7339 gfx::PointF(2.f, 2.f),
7340 gfx::Size(10, 10),
7341 true);
[email protected]94f206c12012-08-25 00:09:147342
[email protected]fb661802013-03-25 01:59:327343 gfx::Transform replica_transform;
7344 replica_transform.Scale(1.0, -1.0);
7345 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7346 SetLayerPropertiesForTesting(replica.get(),
7347 replica_transform,
7348 identity_matrix,
7349 gfx::PointF(),
7350 gfx::PointF(2.f, 2.f),
7351 gfx::Size(10, 10),
7352 true);
[email protected]94f206c12012-08-25 00:09:147353
[email protected]fb661802013-03-25 01:59:327354 // This layer should end up in the same surface as child, with the same draw
7355 // and screen space transforms.
7356 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7357 CreateDrawableContentLayer(&delegate);
7358 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7359 identity_matrix,
7360 identity_matrix,
7361 gfx::PointF(),
7362 gfx::PointF(),
7363 gfx::Size(10, 10),
7364 true);
[email protected]94f206c12012-08-25 00:09:147365
[email protected]fb661802013-03-25 01:59:327366 parent->AddChild(child);
7367 child->AddChild(duplicate_child_non_owner);
7368 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:147369
[email protected]d600df7d2013-08-03 02:34:287370 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7371 host->SetRootLayer(parent);
7372
[email protected]989386c2013-07-18 21:37:237373 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:147374
[email protected]fb661802013-03-25 01:59:327375 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:537376 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7377 parent.get(), parent->bounds(), &render_surface_layer_list);
7378 inputs.device_scale_factor = device_scale_factor;
7379 inputs.can_adjust_raster_scales = true;
7380 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:147381
[email protected]fb661802013-03-25 01:59:327382 // We should have two render surfaces. The root's render surface and child's
7383 // render surface (it needs one because it has a replica layer).
7384 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:147385
[email protected]fb661802013-03-25 01:59:327386 gfx::Transform expected_parent_transform;
7387 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7388 parent->screen_space_transform());
7389 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7390 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:147391
[email protected]fb661802013-03-25 01:59:327392 gfx::Transform expected_draw_transform;
7393 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
7394 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:147395
[email protected]fb661802013-03-25 01:59:327396 gfx::Transform expected_screen_space_transform;
7397 expected_screen_space_transform.Translate(
7398 device_scale_factor * child->position().x(),
7399 device_scale_factor * child->position().y());
7400 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
7401 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147402
[email protected]fb661802013-03-25 01:59:327403 gfx::Transform expected_duplicate_child_draw_transform =
7404 child->draw_transform();
7405 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
7406 duplicate_child_non_owner->draw_transform());
7407 EXPECT_TRANSFORMATION_MATRIX_EQ(
7408 child->screen_space_transform(),
7409 duplicate_child_non_owner->screen_space_transform());
7410 EXPECT_RECT_EQ(child->drawable_content_rect(),
7411 duplicate_child_non_owner->drawable_content_rect());
7412 EXPECT_EQ(child->content_bounds(),
7413 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:147414
[email protected]fb661802013-03-25 01:59:327415 gfx::Transform expected_render_surface_draw_transform;
7416 expected_render_surface_draw_transform.Translate(
7417 device_scale_factor * child->position().x(),
7418 device_scale_factor * child->position().y());
7419 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
7420 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147421
[email protected]fb661802013-03-25 01:59:327422 gfx::Transform expected_surface_draw_transform;
7423 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
7424 device_scale_factor * 2.f);
7425 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
7426 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147427
[email protected]fb661802013-03-25 01:59:327428 gfx::Transform expected_surface_screen_space_transform;
7429 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
7430 device_scale_factor * 2.f);
7431 EXPECT_TRANSFORMATION_MATRIX_EQ(
7432 expected_surface_screen_space_transform,
7433 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147434
[email protected]fb661802013-03-25 01:59:327435 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267436 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
7437 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
7438 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327439 EXPECT_TRANSFORMATION_MATRIX_EQ(
7440 expected_replica_draw_transform,
7441 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:147442
[email protected]fb661802013-03-25 01:59:327443 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267444 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
7445 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
7446 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:327447 EXPECT_TRANSFORMATION_MATRIX_EQ(
7448 expected_replica_screen_space_transform,
7449 child->render_surface()->replica_screen_space_transform());
7450 EXPECT_TRANSFORMATION_MATRIX_EQ(
7451 expected_replica_screen_space_transform,
7452 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:477453}
7454
[email protected]989386c2013-07-18 21:37:237455TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:327456 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
7457 MockContentLayerClient delegate;
7458 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:477459
[email protected]fb661802013-03-25 01:59:327460 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7461 SetLayerPropertiesForTesting(parent.get(),
7462 identity_matrix,
7463 identity_matrix,
7464 gfx::PointF(),
7465 gfx::PointF(),
7466 gfx::Size(33, 31),
7467 true);
[email protected]904e9132012-11-01 00:12:477468
[email protected]fb661802013-03-25 01:59:327469 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7470 SetLayerPropertiesForTesting(child.get(),
7471 identity_matrix,
7472 identity_matrix,
7473 gfx::PointF(),
7474 gfx::PointF(),
7475 gfx::Size(13, 11),
7476 true);
[email protected]904e9132012-11-01 00:12:477477
[email protected]fb661802013-03-25 01:59:327478 gfx::Transform replica_transform;
7479 replica_transform.Scale(1.0, -1.0);
7480 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7481 SetLayerPropertiesForTesting(replica.get(),
7482 replica_transform,
7483 identity_matrix,
7484 gfx::PointF(),
7485 gfx::PointF(),
7486 gfx::Size(13, 11),
7487 true);
[email protected]904e9132012-11-01 00:12:477488
[email protected]fb661802013-03-25 01:59:327489 // This layer should end up in the same surface as child, with the same draw
7490 // and screen space transforms.
7491 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7492 CreateDrawableContentLayer(&delegate);
7493 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7494 identity_matrix,
7495 identity_matrix,
7496 gfx::PointF(),
7497 gfx::PointF(),
7498 gfx::Size(13, 11),
7499 true);
[email protected]904e9132012-11-01 00:12:477500
[email protected]fb661802013-03-25 01:59:327501 parent->AddChild(child);
7502 child->AddChild(duplicate_child_non_owner);
7503 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:477504
[email protected]d600df7d2013-08-03 02:34:287505 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7506 host->SetRootLayer(parent);
7507
[email protected]873639e2013-07-24 19:56:317508 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:537509
7510 RenderSurfaceLayerList render_surface_layer_list;
7511 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7512 parent.get(), parent->bounds(), &render_surface_layer_list);
7513 inputs.device_scale_factor = device_scale_factor;
7514 inputs.can_adjust_raster_scales = true;
7515 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:477516
[email protected]fb661802013-03-25 01:59:327517 // We should have two render surfaces. The root's render surface and child's
7518 // render surface (it needs one because it has a replica layer).
7519 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:477520
[email protected]fb661802013-03-25 01:59:327521 gfx::Transform identity_transform;
[email protected]904e9132012-11-01 00:12:477522
[email protected]fb661802013-03-25 01:59:327523 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7524 parent->screen_space_transform());
7525 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform());
7526 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform());
7527 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7528 child->screen_space_transform());
7529 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7530 duplicate_child_non_owner->draw_transform());
7531 EXPECT_TRANSFORMATION_MATRIX_EQ(
7532 identity_transform, duplicate_child_non_owner->screen_space_transform());
7533 EXPECT_RECT_EQ(child->drawable_content_rect(),
7534 duplicate_child_non_owner->drawable_content_rect());
7535 EXPECT_EQ(child->content_bounds(),
7536 duplicate_child_non_owner->content_bounds());
[email protected]904e9132012-11-01 00:12:477537
[email protected]fb661802013-03-25 01:59:327538 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7539 child->render_surface()->draw_transform());
7540 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7541 child->render_surface()->draw_transform());
7542 EXPECT_TRANSFORMATION_MATRIX_EQ(
7543 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:477544
[email protected]fb661802013-03-25 01:59:327545 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:267546 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327547 EXPECT_TRANSFORMATION_MATRIX_EQ(
7548 expected_replica_draw_transform,
7549 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:477550
[email protected]fb661802013-03-25 01:59:327551 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:267552 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:327553 EXPECT_TRANSFORMATION_MATRIX_EQ(
7554 expected_replica_screen_space_transform,
7555 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147556}
7557
[email protected]989386c2013-07-18 21:37:237558TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:327559 scoped_refptr<Layer> root = Layer::Create();
7560 scoped_refptr<Layer> child = Layer::Create();
7561 scoped_refptr<Layer> grand_child = Layer::Create();
7562 scoped_refptr<Layer> mask_layer = Layer::Create();
7563 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:147564
[email protected]fb661802013-03-25 01:59:327565 grand_child->SetReplicaLayer(replica_layer.get());
7566 child->AddChild(grand_child.get());
7567 child->SetMaskLayer(mask_layer.get());
7568 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:147569
[email protected]d600df7d2013-08-03 02:34:287570 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7571 host->SetRootLayer(root);
7572
[email protected]fb661802013-03-25 01:59:327573 int nonexistent_id = -1;
7574 EXPECT_EQ(root,
7575 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
7576 EXPECT_EQ(child,
7577 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
7578 EXPECT_EQ(
7579 grand_child,
7580 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
7581 EXPECT_EQ(
7582 mask_layer,
7583 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
7584 EXPECT_EQ(
7585 replica_layer,
7586 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
7587 EXPECT_EQ(
7588 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:147589}
7590
[email protected]989386c2013-07-18 21:37:237591TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:327592 scoped_refptr<Layer> root = Layer::Create();
7593 scoped_refptr<Layer> child = Layer::Create();
7594 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
7595 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:577596
[email protected]fb661802013-03-25 01:59:327597 const gfx::Transform identity_matrix;
7598 SetLayerPropertiesForTesting(root.get(),
7599 identity_matrix,
7600 identity_matrix,
7601 gfx::PointF(),
7602 gfx::PointF(),
7603 gfx::Size(100, 100),
7604 false);
7605 SetLayerPropertiesForTesting(child.get(),
7606 identity_matrix,
7607 identity_matrix,
7608 gfx::PointF(),
7609 gfx::PointF(),
7610 gfx::Size(10, 10),
7611 false);
7612 SetLayerPropertiesForTesting(grand_child.get(),
7613 identity_matrix,
7614 identity_matrix,
7615 gfx::PointF(),
7616 gfx::PointF(),
7617 gfx::Size(10, 10),
7618 false);
[email protected]498ec6e0e2012-11-30 18:24:577619
[email protected]fb661802013-03-25 01:59:327620 root->AddChild(child);
7621 child->AddChild(grand_child);
7622 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:577623
[email protected]d600df7d2013-08-03 02:34:287624 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7625 host->SetRootLayer(root);
7626
[email protected]fb661802013-03-25 01:59:327627 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:577628
[email protected]fb661802013-03-25 01:59:327629 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:577630}
7631
[email protected]989386c2013-07-18 21:37:237632TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:167633 FakeImplProxy proxy;
7634 FakeLayerTreeHostImpl host_impl(&proxy);
7635 host_impl.CreatePendingTree();
7636 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7637
7638 const gfx::Transform identity_matrix;
7639 SetLayerPropertiesForTesting(root.get(),
7640 identity_matrix,
7641 identity_matrix,
7642 gfx::PointF(),
7643 gfx::PointF(),
7644 gfx::Size(100, 100),
7645 false);
7646 root->SetDrawsContent(true);
7647
7648 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7649 SetLayerPropertiesForTesting(child.get(),
7650 identity_matrix,
7651 identity_matrix,
7652 gfx::PointF(),
7653 gfx::PointF(),
7654 gfx::Size(50, 50),
7655 false);
7656 child->SetDrawsContent(true);
7657 child->SetOpacity(0.0f);
7658
7659 // Add opacity animation.
7660 AddOpacityTransitionToController(
7661 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
7662
7663 root->AddChild(child.Pass());
7664
[email protected]c0ae06c12013-06-24 18:32:197665 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537666 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7667 root.get(), root->bounds(), &render_surface_layer_list);
7668 inputs.can_adjust_raster_scales = true;
7669 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:167670
7671 // We should have one render surface and two layers. The child
7672 // layer should be included even though it is transparent.
7673 ASSERT_EQ(1u, render_surface_layer_list.size());
7674 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
7675}
7676
[email protected]10aabcc32012-12-13 09:18:597677typedef std::tr1::tuple<bool, bool> LCDTextTestParam;
[email protected]989386c2013-07-18 21:37:237678class LCDTextTest
7679 : public LayerTreeHostCommonTestBase,
7680 public testing::TestWithParam<LCDTextTestParam> {
[email protected]fb661802013-03-25 01:59:327681 protected:
7682 virtual void SetUp() {
7683 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
[email protected]10aabcc32012-12-13 09:18:597684
[email protected]fb661802013-03-25 01:59:327685 root_ = Layer::Create();
7686 child_ = Layer::Create();
7687 grand_child_ = Layer::Create();
7688 child_->AddChild(grand_child_.get());
7689 root_->AddChild(child_.get());
[email protected]10aabcc32012-12-13 09:18:597690
[email protected]fb661802013-03-25 01:59:327691 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307692 SetLayerPropertiesForTesting(root_.get(),
[email protected]fb661802013-03-25 01:59:327693 identity_matrix,
7694 identity_matrix,
7695 gfx::PointF(),
7696 gfx::PointF(),
7697 gfx::Size(1, 1),
7698 false);
[email protected]22898ed2013-06-01 04:52:307699 SetLayerPropertiesForTesting(child_.get(),
[email protected]fb661802013-03-25 01:59:327700 identity_matrix,
7701 identity_matrix,
7702 gfx::PointF(),
7703 gfx::PointF(),
7704 gfx::Size(1, 1),
7705 false);
[email protected]22898ed2013-06-01 04:52:307706 SetLayerPropertiesForTesting(grand_child_.get(),
[email protected]fb661802013-03-25 01:59:327707 identity_matrix,
7708 identity_matrix,
7709 gfx::PointF(),
7710 gfx::PointF(),
7711 gfx::Size(1, 1),
7712 false);
[email protected]10aabcc32012-12-13 09:18:597713
[email protected]fb661802013-03-25 01:59:327714 child_->SetForceRenderSurface(std::tr1::get<1>(GetParam()));
[email protected]d600df7d2013-08-03 02:34:287715
7716 host_ = FakeLayerTreeHost::Create();
7717 host_->SetRootLayer(root_);
[email protected]fb661802013-03-25 01:59:327718 }
[email protected]10aabcc32012-12-13 09:18:597719
[email protected]fb661802013-03-25 01:59:327720 bool can_use_lcd_text_;
[email protected]d600df7d2013-08-03 02:34:287721 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]fb661802013-03-25 01:59:327722 scoped_refptr<Layer> root_;
7723 scoped_refptr<Layer> child_;
7724 scoped_refptr<Layer> grand_child_;
[email protected]10aabcc32012-12-13 09:18:597725};
7726
[email protected]fb661802013-03-25 01:59:327727TEST_P(LCDTextTest, CanUseLCDText) {
7728 // Case 1: Identity transform.
7729 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307730 ExecuteCalculateDrawProperties(
7731 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327732 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7733 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7734 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597735
[email protected]fb661802013-03-25 01:59:327736 // Case 2: Integral translation.
7737 gfx::Transform integral_translation;
7738 integral_translation.Translate(1.0, 2.0);
7739 child_->SetTransform(integral_translation);
[email protected]22898ed2013-06-01 04:52:307740 ExecuteCalculateDrawProperties(
7741 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327742 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7743 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7744 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597745
[email protected]fb661802013-03-25 01:59:327746 // Case 3: Non-integral translation.
7747 gfx::Transform non_integral_translation;
7748 non_integral_translation.Translate(1.5, 2.5);
7749 child_->SetTransform(non_integral_translation);
[email protected]22898ed2013-06-01 04:52:307750 ExecuteCalculateDrawProperties(
7751 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327752 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7753 EXPECT_FALSE(child_->can_use_lcd_text());
7754 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597755
[email protected]fb661802013-03-25 01:59:327756 // Case 4: Rotation.
7757 gfx::Transform rotation;
7758 rotation.Rotate(10.0);
7759 child_->SetTransform(rotation);
[email protected]22898ed2013-06-01 04:52:307760 ExecuteCalculateDrawProperties(
7761 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327762 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7763 EXPECT_FALSE(child_->can_use_lcd_text());
7764 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597765
[email protected]fb661802013-03-25 01:59:327766 // Case 5: Scale.
7767 gfx::Transform scale;
7768 scale.Scale(2.0, 2.0);
7769 child_->SetTransform(scale);
[email protected]22898ed2013-06-01 04:52:307770 ExecuteCalculateDrawProperties(
7771 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327772 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7773 EXPECT_FALSE(child_->can_use_lcd_text());
7774 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597775
[email protected]fb661802013-03-25 01:59:327776 // Case 6: Skew.
7777 gfx::Transform skew;
7778 skew.SkewX(10.0);
7779 child_->SetTransform(skew);
[email protected]22898ed2013-06-01 04:52:307780 ExecuteCalculateDrawProperties(
7781 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327782 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7783 EXPECT_FALSE(child_->can_use_lcd_text());
7784 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597785
[email protected]fb661802013-03-25 01:59:327786 // Case 7: Translucent.
7787 child_->SetTransform(identity_matrix);
7788 child_->SetOpacity(0.5f);
[email protected]22898ed2013-06-01 04:52:307789 ExecuteCalculateDrawProperties(
7790 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327791 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7792 EXPECT_FALSE(child_->can_use_lcd_text());
7793 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597794
[email protected]fb661802013-03-25 01:59:327795 // Case 8: Sanity check: restore transform and opacity.
7796 child_->SetTransform(identity_matrix);
7797 child_->SetOpacity(1.f);
[email protected]22898ed2013-06-01 04:52:307798 ExecuteCalculateDrawProperties(
7799 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327800 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7801 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7802 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597803}
7804
[email protected]fd9a3b6d2013-08-03 00:46:177805TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
[email protected]fb661802013-03-25 01:59:327806 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
[email protected]22898ed2013-06-01 04:52:307807 ExecuteCalculateDrawProperties(
7808 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327809 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7810 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7811 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597812
[email protected]fb661802013-03-25 01:59:327813 // Add opacity animation.
7814 child_->SetOpacity(0.9f);
7815 AddOpacityTransitionToController(
7816 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:597817
[email protected]22898ed2013-06-01 04:52:307818 ExecuteCalculateDrawProperties(
7819 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327820 // Text AA should not be adjusted while animation is active.
7821 // Make sure LCD text AA setting remains unchanged.
7822 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7823 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7824 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597825}
7826
7827INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
7828 LCDTextTest,
[email protected]fb661802013-03-25 01:59:327829 testing::Combine(testing::Bool(), testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:597830
[email protected]989386c2013-07-18 21:37:237831TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:197832 FakeImplProxy proxy;
7833 FakeLayerTreeHostImpl host_impl(&proxy);
7834 host_impl.CreatePendingTree();
7835 const gfx::Transform identity_matrix;
7836
7837 scoped_refptr<Layer> root = Layer::Create();
7838 SetLayerPropertiesForTesting(root.get(),
7839 identity_matrix,
7840 identity_matrix,
7841 gfx::PointF(),
7842 gfx::PointF(),
7843 gfx::Size(50, 50),
7844 false);
7845 root->SetIsDrawable(true);
7846
7847 scoped_refptr<Layer> child = Layer::Create();
7848 SetLayerPropertiesForTesting(child.get(),
7849 identity_matrix,
7850 identity_matrix,
7851 gfx::PointF(),
7852 gfx::PointF(),
7853 gfx::Size(40, 40),
7854 false);
7855 child->SetIsDrawable(true);
7856
7857 scoped_refptr<Layer> grand_child = Layer::Create();
7858 SetLayerPropertiesForTesting(grand_child.get(),
7859 identity_matrix,
7860 identity_matrix,
7861 gfx::PointF(),
7862 gfx::PointF(),
7863 gfx::Size(30, 30),
7864 false);
7865 grand_child->SetIsDrawable(true);
7866 grand_child->SetHideLayerAndSubtree(true);
7867
7868 child->AddChild(grand_child);
7869 root->AddChild(child);
7870
[email protected]d600df7d2013-08-03 02:34:287871 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7872 host->SetRootLayer(root);
7873
[email protected]989386c2013-07-18 21:37:237874 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537875 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7876 root.get(), root->bounds(), &render_surface_layer_list);
7877 inputs.can_adjust_raster_scales = true;
7878 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197879
7880 // We should have one render surface and two layers. The grand child has
7881 // hidden itself.
7882 ASSERT_EQ(1u, render_surface_layer_list.size());
7883 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237884 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
7885 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197886}
7887
[email protected]989386c2013-07-18 21:37:237888TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:197889 FakeImplProxy proxy;
7890 FakeLayerTreeHostImpl host_impl(&proxy);
7891 host_impl.CreatePendingTree();
7892 const gfx::Transform identity_matrix;
7893
7894 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7895 SetLayerPropertiesForTesting(root.get(),
7896 identity_matrix,
7897 identity_matrix,
7898 gfx::PointF(),
7899 gfx::PointF(),
7900 gfx::Size(50, 50),
7901 false);
7902 root->SetDrawsContent(true);
7903
7904 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7905 SetLayerPropertiesForTesting(child.get(),
7906 identity_matrix,
7907 identity_matrix,
7908 gfx::PointF(),
7909 gfx::PointF(),
7910 gfx::Size(40, 40),
7911 false);
7912 child->SetDrawsContent(true);
7913
7914 scoped_ptr<LayerImpl> grand_child =
7915 LayerImpl::Create(host_impl.pending_tree(), 3);
7916 SetLayerPropertiesForTesting(grand_child.get(),
7917 identity_matrix,
7918 identity_matrix,
7919 gfx::PointF(),
7920 gfx::PointF(),
7921 gfx::Size(30, 30),
7922 false);
7923 grand_child->SetDrawsContent(true);
7924 grand_child->SetHideLayerAndSubtree(true);
7925
7926 child->AddChild(grand_child.Pass());
7927 root->AddChild(child.Pass());
7928
7929 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537930 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7931 root.get(), root->bounds(), &render_surface_layer_list);
7932 inputs.can_adjust_raster_scales = true;
7933 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197934
7935 // We should have one render surface and two layers. The grand child has
7936 // hidden itself.
7937 ASSERT_EQ(1u, render_surface_layer_list.size());
7938 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237939 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
7940 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197941}
7942
[email protected]989386c2013-07-18 21:37:237943TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:197944 FakeImplProxy proxy;
7945 FakeLayerTreeHostImpl host_impl(&proxy);
7946 host_impl.CreatePendingTree();
7947 const gfx::Transform identity_matrix;
7948
7949 scoped_refptr<Layer> root = Layer::Create();
7950 SetLayerPropertiesForTesting(root.get(),
7951 identity_matrix,
7952 identity_matrix,
7953 gfx::PointF(),
7954 gfx::PointF(),
7955 gfx::Size(50, 50),
7956 false);
7957 root->SetIsDrawable(true);
7958
7959 scoped_refptr<Layer> child = Layer::Create();
7960 SetLayerPropertiesForTesting(child.get(),
7961 identity_matrix,
7962 identity_matrix,
7963 gfx::PointF(),
7964 gfx::PointF(),
7965 gfx::Size(40, 40),
7966 false);
7967 child->SetIsDrawable(true);
7968 child->SetHideLayerAndSubtree(true);
7969
7970 scoped_refptr<Layer> grand_child = Layer::Create();
7971 SetLayerPropertiesForTesting(grand_child.get(),
7972 identity_matrix,
7973 identity_matrix,
7974 gfx::PointF(),
7975 gfx::PointF(),
7976 gfx::Size(30, 30),
7977 false);
7978 grand_child->SetIsDrawable(true);
7979
7980 child->AddChild(grand_child);
7981 root->AddChild(child);
7982
[email protected]d600df7d2013-08-03 02:34:287983 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7984 host->SetRootLayer(root);
7985
[email protected]989386c2013-07-18 21:37:237986 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537987 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7988 root.get(), root->bounds(), &render_surface_layer_list);
7989 inputs.can_adjust_raster_scales = true;
7990 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197991
7992 // We should have one render surface and one layers. The child has
7993 // hidden itself and the grand child.
7994 ASSERT_EQ(1u, render_surface_layer_list.size());
7995 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237996 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:197997}
7998
[email protected]989386c2013-07-18 21:37:237999TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[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_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
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->SetDrawsContent(true);
8014
8015 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
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->SetDrawsContent(true);
8024 child->SetHideLayerAndSubtree(true);
8025
8026 scoped_ptr<LayerImpl> grand_child =
8027 LayerImpl::Create(host_impl.pending_tree(), 3);
8028 SetLayerPropertiesForTesting(grand_child.get(),
8029 identity_matrix,
8030 identity_matrix,
8031 gfx::PointF(),
8032 gfx::PointF(),
8033 gfx::Size(30, 30),
8034 false);
8035 grand_child->SetDrawsContent(true);
8036
8037 child->AddChild(grand_child.Pass());
8038 root->AddChild(child.Pass());
8039
8040 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538041 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8042 root.get(), root->bounds(), &render_surface_layer_list);
8043 inputs.can_adjust_raster_scales = true;
8044 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198045
8046 // We should have one render surface and one layers. The child has
8047 // hidden itself and the grand child.
8048 ASSERT_EQ(1u, render_surface_layer_list.size());
8049 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238050 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:198051}
8052
[email protected]30fe19ff2013-07-04 00:54:458053void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
8054
[email protected]989386c2013-07-18 21:37:238055TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458056 FakeImplProxy proxy;
8057 FakeLayerTreeHostImpl host_impl(&proxy);
8058 host_impl.CreatePendingTree();
8059 const gfx::Transform identity_matrix;
8060
8061 scoped_refptr<Layer> root = Layer::Create();
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->SetIsDrawable(true);
8070
8071 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
8072 SetLayerPropertiesForTesting(copy_grand_parent.get(),
8073 identity_matrix,
8074 identity_matrix,
8075 gfx::PointF(),
8076 gfx::PointF(),
8077 gfx::Size(40, 40),
8078 false);
8079 copy_grand_parent->SetIsDrawable(true);
8080
8081 scoped_refptr<Layer> copy_parent = Layer::Create();
8082 SetLayerPropertiesForTesting(copy_parent.get(),
8083 identity_matrix,
8084 identity_matrix,
8085 gfx::PointF(),
8086 gfx::PointF(),
8087 gfx::Size(30, 30),
8088 false);
8089 copy_parent->SetIsDrawable(true);
8090 copy_parent->SetForceRenderSurface(true);
8091
8092 scoped_refptr<Layer> copy_layer = Layer::Create();
8093 SetLayerPropertiesForTesting(copy_layer.get(),
8094 identity_matrix,
8095 identity_matrix,
8096 gfx::PointF(),
8097 gfx::PointF(),
8098 gfx::Size(20, 20),
8099 false);
8100 copy_layer->SetIsDrawable(true);
8101
8102 scoped_refptr<Layer> copy_child = Layer::Create();
8103 SetLayerPropertiesForTesting(copy_child.get(),
8104 identity_matrix,
8105 identity_matrix,
8106 gfx::PointF(),
8107 gfx::PointF(),
8108 gfx::Size(20, 20),
8109 false);
8110 copy_child->SetIsDrawable(true);
8111
[email protected]ac020122013-07-12 23:45:538112 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
8113 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
8114 identity_matrix,
8115 identity_matrix,
8116 gfx::PointF(),
8117 gfx::PointF(),
8118 gfx::Size(40, 40),
8119 false);
8120 copy_grand_parent_sibling_before->SetIsDrawable(true);
8121
8122 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
8123 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
8124 identity_matrix,
8125 identity_matrix,
8126 gfx::PointF(),
8127 gfx::PointF(),
8128 gfx::Size(40, 40),
8129 false);
8130 copy_grand_parent_sibling_after->SetIsDrawable(true);
8131
[email protected]30fe19ff2013-07-04 00:54:458132 copy_layer->AddChild(copy_child);
8133 copy_parent->AddChild(copy_layer);
8134 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:538135 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:458136 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:538137 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:458138
[email protected]d600df7d2013-08-03 02:34:288139 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8140 host->SetRootLayer(root);
8141
[email protected]30fe19ff2013-07-04 00:54:458142 // Hide the copy_grand_parent and its subtree. But make a copy request in that
8143 // hidden subtree on copy_layer.
8144 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:538145 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
8146 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:458147 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8148 base::Bind(&EmptyCopyOutputCallback)));
8149 EXPECT_TRUE(copy_layer->HasCopyRequest());
8150
[email protected]989386c2013-07-18 21:37:238151 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538152 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8153 root.get(), root->bounds(), &render_surface_layer_list);
8154 inputs.can_adjust_raster_scales = true;
8155 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458156
[email protected]ac020122013-07-12 23:45:538157 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
8158 EXPECT_TRUE(copy_grand_parent->draw_properties().
8159 layer_or_descendant_has_copy_request);
8160 EXPECT_TRUE(copy_parent->draw_properties().
8161 layer_or_descendant_has_copy_request);
8162 EXPECT_TRUE(copy_layer->draw_properties().
8163 layer_or_descendant_has_copy_request);
8164 EXPECT_FALSE(copy_child->draw_properties().
8165 layer_or_descendant_has_copy_request);
8166 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
8167 layer_or_descendant_has_copy_request);
8168 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
8169 layer_or_descendant_has_copy_request);
8170
[email protected]30fe19ff2013-07-04 00:54:458171 // We should have three render surfaces, one for the root, one for the parent
8172 // since it owns a surface, and one for the copy_layer.
8173 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238174 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
8175 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
8176 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:458177
8178 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:538179 // copy_grand_parent is hidden along with its siblings, but the copy_parent
8180 // will appear since something in its subtree needs to be drawn for a copy
8181 // request.
[email protected]30fe19ff2013-07-04 00:54:458182 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238183 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
8184 EXPECT_EQ(copy_parent->id(),
8185 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458186
8187 // Nothing actually drawns into the copy parent, so only the copy_layer will
8188 // appear in its list, since it needs to be drawn for the copy request.
8189 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
8190 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238191 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458192
8193 // The copy_layer's render surface should have two contributing layers.
8194 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
8195 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238196 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458197 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:238198 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458199}
8200
[email protected]989386c2013-07-18 21:37:238201TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458202 FakeImplProxy proxy;
8203 FakeLayerTreeHostImpl host_impl(&proxy);
8204 host_impl.CreatePendingTree();
8205 const gfx::Transform identity_matrix;
8206
8207 scoped_refptr<Layer> root = Layer::Create();
8208 SetLayerPropertiesForTesting(root.get(),
8209 identity_matrix,
8210 identity_matrix,
8211 gfx::PointF(),
8212 gfx::PointF(),
8213 gfx::Size(50, 50),
8214 false);
8215 root->SetIsDrawable(true);
8216
8217 scoped_refptr<Layer> copy_parent = Layer::Create();
8218 SetLayerPropertiesForTesting(copy_parent.get(),
8219 identity_matrix,
8220 identity_matrix,
8221 gfx::PointF(),
8222 gfx::PointF(),
8223 gfx::Size(),
8224 false);
8225 copy_parent->SetIsDrawable(true);
8226 copy_parent->SetMasksToBounds(true);
8227
8228 scoped_refptr<Layer> copy_layer = Layer::Create();
8229 SetLayerPropertiesForTesting(copy_layer.get(),
8230 identity_matrix,
8231 identity_matrix,
8232 gfx::PointF(),
8233 gfx::PointF(),
8234 gfx::Size(30, 30),
8235 false);
8236 copy_layer->SetIsDrawable(true);
8237
8238 scoped_refptr<Layer> copy_child = Layer::Create();
8239 SetLayerPropertiesForTesting(copy_child.get(),
8240 identity_matrix,
8241 identity_matrix,
8242 gfx::PointF(),
8243 gfx::PointF(),
8244 gfx::Size(20, 20),
8245 false);
8246 copy_child->SetIsDrawable(true);
8247
8248 copy_layer->AddChild(copy_child);
8249 copy_parent->AddChild(copy_layer);
8250 root->AddChild(copy_parent);
8251
[email protected]d600df7d2013-08-03 02:34:288252 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8253 host->SetRootLayer(root);
8254
[email protected]30fe19ff2013-07-04 00:54:458255 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8256 base::Bind(&EmptyCopyOutputCallback)));
8257 EXPECT_TRUE(copy_layer->HasCopyRequest());
8258
[email protected]989386c2013-07-18 21:37:238259 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538260 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8261 root.get(), root->bounds(), &render_surface_layer_list);
8262 inputs.can_adjust_raster_scales = true;
8263 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458264
8265 // We should have one render surface, as the others are clipped out.
8266 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238267 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458268
8269 // The root render surface should only have 1 contributing layer, since the
8270 // other layers are empty/clipped away.
8271 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238272 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458273}
8274
[email protected]11a07b102013-07-24 17:33:198275TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
8276 FakeImplProxy proxy;
8277 FakeLayerTreeHostImpl host_impl(&proxy);
8278 host_impl.CreatePendingTree();
8279 const gfx::Transform identity_matrix;
8280
8281 scoped_refptr<Layer> root = Layer::Create();
8282 SetLayerPropertiesForTesting(root.get(),
8283 identity_matrix,
8284 identity_matrix,
8285 gfx::PointF(),
8286 gfx::PointF(),
8287 gfx::Size(50, 50),
8288 false);
8289 root->SetIsDrawable(true);
8290
8291 // The surface is moved slightly outside of the viewport.
8292 scoped_refptr<Layer> surface = Layer::Create();
8293 SetLayerPropertiesForTesting(surface.get(),
8294 identity_matrix,
8295 identity_matrix,
8296 gfx::PointF(),
8297 gfx::PointF(-10, -20),
8298 gfx::Size(),
8299 false);
8300 surface->SetForceRenderSurface(true);
8301
8302 scoped_refptr<Layer> surface_child = Layer::Create();
8303 SetLayerPropertiesForTesting(surface_child.get(),
8304 identity_matrix,
8305 identity_matrix,
8306 gfx::PointF(),
8307 gfx::PointF(),
8308 gfx::Size(50, 50),
8309 false);
8310 surface_child->SetIsDrawable(true);
8311
8312 surface->AddChild(surface_child);
8313 root->AddChild(surface);
8314
[email protected]d600df7d2013-08-03 02:34:288315 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8316 host->SetRootLayer(root);
8317
[email protected]11a07b102013-07-24 17:33:198318 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538319 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8320 root.get(), root->bounds(), &render_surface_layer_list);
8321 inputs.can_adjust_raster_scales = true;
8322 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:198323
8324 // The visible_content_rect for the |surface_child| should not be clipped by
8325 // the viewport.
8326 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
8327 surface_child->visible_content_rect().ToString());
8328}
8329
[email protected]420fdf6e2013-08-26 20:36:388330TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
8331 // Ensure that a transform between the layer and its render surface is not a
8332 // problem. Constructs the following layer tree.
8333 //
8334 // root (a render surface)
8335 // + render_surface
8336 // + clip_parent (scaled)
8337 // + intervening_clipping_layer
8338 // + clip_child
8339 //
8340 // The render surface should be resized correctly and the clip child should
8341 // inherit the right clip rect.
8342 scoped_refptr<Layer> root = Layer::Create();
8343 scoped_refptr<Layer> render_surface = Layer::Create();
8344 scoped_refptr<Layer> clip_parent = Layer::Create();
8345 scoped_refptr<Layer> intervening = Layer::Create();
8346 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8347 make_scoped_refptr(new LayerWithForcedDrawsContent);
8348
8349 root->AddChild(render_surface);
8350 render_surface->AddChild(clip_parent);
8351 clip_parent->AddChild(intervening);
8352 intervening->AddChild(clip_child);
8353
8354 clip_child->SetClipParent(clip_parent.get());
8355
8356 intervening->SetMasksToBounds(true);
8357 clip_parent->SetMasksToBounds(true);
8358
8359 render_surface->SetForceRenderSurface(true);
8360
8361 gfx::Transform scale_transform;
8362 scale_transform.Scale(2, 2);
8363
8364 gfx::Transform identity_transform;
8365
8366 SetLayerPropertiesForTesting(root.get(),
8367 identity_transform,
8368 identity_transform,
8369 gfx::PointF(),
8370 gfx::PointF(),
8371 gfx::Size(50, 50),
8372 false);
8373 SetLayerPropertiesForTesting(render_surface.get(),
8374 identity_transform,
8375 identity_transform,
8376 gfx::PointF(),
8377 gfx::PointF(),
8378 gfx::Size(10, 10),
8379 false);
8380 SetLayerPropertiesForTesting(clip_parent.get(),
8381 scale_transform,
8382 identity_transform,
8383 gfx::PointF(),
8384 gfx::PointF(1.f, 1.f),
8385 gfx::Size(10, 10),
8386 false);
8387 SetLayerPropertiesForTesting(intervening.get(),
8388 identity_transform,
8389 identity_transform,
8390 gfx::PointF(),
8391 gfx::PointF(1.f, 1.f),
8392 gfx::Size(5, 5),
8393 false);
8394 SetLayerPropertiesForTesting(clip_child.get(),
8395 identity_transform,
8396 identity_transform,
8397 gfx::PointF(),
8398 gfx::PointF(1.f, 1.f),
8399 gfx::Size(10, 10),
8400 false);
8401
8402 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8403 host->SetRootLayer(root);
8404
8405 ExecuteCalculateDrawProperties(root.get());
8406
8407 ASSERT_TRUE(root->render_surface());
8408 ASSERT_TRUE(render_surface->render_surface());
8409
8410 // Ensure that we've inherited our clip parent's clip and weren't affected
8411 // by the intervening clip layer.
8412 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
8413 clip_parent->clip_rect().ToString());
8414 ASSERT_EQ(clip_parent->clip_rect().ToString(),
8415 clip_child->clip_rect().ToString());
8416 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
8417 intervening->clip_rect().ToString());
8418
8419 // Ensure that the render surface reports a content rect that has been grown
8420 // to accomodate for the clip child.
8421 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
8422 render_surface->render_surface()->content_rect().ToString());
8423
8424 // The above check implies the two below, but they nicely demonstrate that
8425 // we've grown, despite the intervening layer's clip.
8426 ASSERT_TRUE(clip_parent->clip_rect().Contains(
8427 render_surface->render_surface()->content_rect()));
8428 ASSERT_FALSE(intervening->clip_rect().Contains(
8429 render_surface->render_surface()->content_rect()));
8430}
8431
8432TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
8433 // Ensure that intervening render surfaces are not a problem in the basic
8434 // case. In the following tree, both render surfaces should be resized to
8435 // accomodate for the clip child, despite an intervening clip.
8436 //
8437 // root (a render surface)
8438 // + clip_parent (masks to bounds)
8439 // + render_surface1 (sets opacity)
8440 // + intervening (masks to bounds)
8441 // + render_surface2 (also sets opacity)
8442 // + clip_child
8443 //
8444 scoped_refptr<Layer> root = Layer::Create();
8445 scoped_refptr<Layer> clip_parent = Layer::Create();
8446 scoped_refptr<Layer> render_surface1 = Layer::Create();
8447 scoped_refptr<Layer> intervening = Layer::Create();
8448 scoped_refptr<Layer> render_surface2 = Layer::Create();
8449 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8450 make_scoped_refptr(new LayerWithForcedDrawsContent);
8451
8452 root->AddChild(clip_parent);
8453 clip_parent->AddChild(render_surface1);
8454 render_surface1->AddChild(intervening);
8455 intervening->AddChild(render_surface2);
8456 render_surface2->AddChild(clip_child);
8457
8458 clip_child->SetClipParent(clip_parent.get());
8459
8460 intervening->SetMasksToBounds(true);
8461 clip_parent->SetMasksToBounds(true);
8462
8463 render_surface1->SetForceRenderSurface(true);
8464 render_surface2->SetForceRenderSurface(true);
8465
8466 gfx::Transform translation_transform;
8467 translation_transform.Translate(2, 2);
8468
8469 gfx::Transform identity_transform;
8470 SetLayerPropertiesForTesting(root.get(),
8471 identity_transform,
8472 identity_transform,
8473 gfx::PointF(),
8474 gfx::PointF(),
8475 gfx::Size(50, 50),
8476 false);
8477 SetLayerPropertiesForTesting(clip_parent.get(),
8478 translation_transform,
8479 identity_transform,
8480 gfx::PointF(),
8481 gfx::PointF(1.f, 1.f),
8482 gfx::Size(40, 40),
8483 false);
8484 SetLayerPropertiesForTesting(render_surface1.get(),
8485 identity_transform,
8486 identity_transform,
8487 gfx::PointF(),
8488 gfx::PointF(),
8489 gfx::Size(10, 10),
8490 false);
8491 SetLayerPropertiesForTesting(intervening.get(),
8492 identity_transform,
8493 identity_transform,
8494 gfx::PointF(),
8495 gfx::PointF(1.f, 1.f),
8496 gfx::Size(5, 5),
8497 false);
8498 SetLayerPropertiesForTesting(render_surface2.get(),
8499 identity_transform,
8500 identity_transform,
8501 gfx::PointF(),
8502 gfx::PointF(),
8503 gfx::Size(10, 10),
8504 false);
8505 SetLayerPropertiesForTesting(clip_child.get(),
8506 identity_transform,
8507 identity_transform,
8508 gfx::PointF(),
8509 gfx::PointF(-10.f, -10.f),
8510 gfx::Size(60, 60),
8511 false);
8512
8513 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8514 host->SetRootLayer(root);
8515
8516 ExecuteCalculateDrawProperties(root.get());
8517
8518 EXPECT_TRUE(root->render_surface());
8519 EXPECT_TRUE(render_surface1->render_surface());
8520 EXPECT_TRUE(render_surface2->render_surface());
8521
8522 // Since the render surfaces could have expanded, they should not clip (their
8523 // bounds would no longer be reliable). We should resort to layer clipping
8524 // in this case.
8525 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8526 render_surface1->render_surface()->clip_rect().ToString());
8527 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8528 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8529 render_surface2->render_surface()->clip_rect().ToString());
8530 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8531
8532 // NB: clip rects are in target space.
8533 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8534 render_surface1->clip_rect().ToString());
8535 EXPECT_TRUE(render_surface1->is_clipped());
8536
8537 // This value is inherited from the clipping ancestor layer, 'intervening'.
8538 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8539 render_surface2->clip_rect().ToString());
8540 EXPECT_TRUE(render_surface2->is_clipped());
8541
8542 // The content rects of both render surfaces should both have expanded to
8543 // contain the clip child.
8544 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8545 render_surface1->render_surface()->content_rect().ToString());
8546 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8547 render_surface2->render_surface()->content_rect().ToString());
8548
8549 // The clip child should have inherited the clip parent's clip (projected to
8550 // the right space, of course), and should have the correctly sized visible
8551 // content rect.
8552 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
8553 clip_child->clip_rect().ToString());
8554 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
8555 clip_child->visible_content_rect().ToString());
8556 EXPECT_TRUE(clip_child->is_clipped());
8557}
8558
8559TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
8560 // Ensure that intervening render surfaces are not a problem, even if there
8561 // is a scroll involved. Note, we do _not_ have to consider any other sort
8562 // of transform.
8563 //
8564 // root (a render surface)
8565 // + clip_parent (masks to bounds)
8566 // + render_surface1 (sets opacity)
8567 // + intervening (masks to bounds AND scrolls)
8568 // + render_surface2 (also sets opacity)
8569 // + clip_child
8570 //
8571 scoped_refptr<Layer> root = Layer::Create();
8572 scoped_refptr<Layer> clip_parent = Layer::Create();
8573 scoped_refptr<Layer> render_surface1 = Layer::Create();
8574 scoped_refptr<Layer> intervening = Layer::Create();
8575 scoped_refptr<Layer> render_surface2 = Layer::Create();
8576 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8577 make_scoped_refptr(new LayerWithForcedDrawsContent);
8578
8579 root->AddChild(clip_parent);
8580 clip_parent->AddChild(render_surface1);
8581 render_surface1->AddChild(intervening);
8582 intervening->AddChild(render_surface2);
8583 render_surface2->AddChild(clip_child);
8584
8585 clip_child->SetClipParent(clip_parent.get());
8586
8587 intervening->SetMasksToBounds(true);
8588 clip_parent->SetMasksToBounds(true);
8589 intervening->SetScrollable(true);
8590 intervening->SetMaxScrollOffset(gfx::Vector2d(50, 50));
8591 intervening->SetScrollOffset(gfx::Vector2d(3, 3));
8592
8593 render_surface1->SetForceRenderSurface(true);
8594 render_surface2->SetForceRenderSurface(true);
8595
8596 gfx::Transform translation_transform;
8597 translation_transform.Translate(2, 2);
8598
8599 gfx::Transform identity_transform;
8600 SetLayerPropertiesForTesting(root.get(),
8601 identity_transform,
8602 identity_transform,
8603 gfx::PointF(),
8604 gfx::PointF(),
8605 gfx::Size(50, 50),
8606 false);
8607 SetLayerPropertiesForTesting(clip_parent.get(),
8608 translation_transform,
8609 identity_transform,
8610 gfx::PointF(),
8611 gfx::PointF(1.f, 1.f),
8612 gfx::Size(40, 40),
8613 false);
8614 SetLayerPropertiesForTesting(render_surface1.get(),
8615 identity_transform,
8616 identity_transform,
8617 gfx::PointF(),
8618 gfx::PointF(),
8619 gfx::Size(10, 10),
8620 false);
8621 SetLayerPropertiesForTesting(intervening.get(),
8622 identity_transform,
8623 identity_transform,
8624 gfx::PointF(),
8625 gfx::PointF(1.f, 1.f),
8626 gfx::Size(5, 5),
8627 false);
8628 SetLayerPropertiesForTesting(render_surface2.get(),
8629 identity_transform,
8630 identity_transform,
8631 gfx::PointF(),
8632 gfx::PointF(),
8633 gfx::Size(10, 10),
8634 false);
8635 SetLayerPropertiesForTesting(clip_child.get(),
8636 identity_transform,
8637 identity_transform,
8638 gfx::PointF(),
8639 gfx::PointF(-10.f, -10.f),
8640 gfx::Size(60, 60),
8641 false);
8642
8643 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8644 host->SetRootLayer(root);
8645
8646 ExecuteCalculateDrawProperties(root.get());
8647
8648 EXPECT_TRUE(root->render_surface());
8649 EXPECT_TRUE(render_surface1->render_surface());
8650 EXPECT_TRUE(render_surface2->render_surface());
8651
8652 // Since the render surfaces could have expanded, they should not clip (their
8653 // bounds would no longer be reliable). We should resort to layer clipping
8654 // in this case.
8655 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8656 render_surface1->render_surface()->clip_rect().ToString());
8657 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8658 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8659 render_surface2->render_surface()->clip_rect().ToString());
8660 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
8661
8662 // NB: clip rects are in target space.
8663 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8664 render_surface1->clip_rect().ToString());
8665 EXPECT_TRUE(render_surface1->is_clipped());
8666
8667 // This value is inherited from the clipping ancestor layer, 'intervening'.
8668 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
8669 render_surface2->clip_rect().ToString());
8670 EXPECT_TRUE(render_surface2->is_clipped());
8671
8672 // The content rects of both render surfaces should both have expanded to
8673 // contain the clip child.
8674 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8675 render_surface1->render_surface()->content_rect().ToString());
8676 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8677 render_surface2->render_surface()->content_rect().ToString());
8678
8679 // The clip child should have inherited the clip parent's clip (projected to
8680 // the right space, of course), and should have the correctly sized visible
8681 // content rect.
8682 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
8683 clip_child->clip_rect().ToString());
8684 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
8685 clip_child->visible_content_rect().ToString());
8686 EXPECT_TRUE(clip_child->is_clipped());
8687}
8688
8689TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
8690 // Ensures that descendants of the clip child inherit the correct clip.
8691 //
8692 // root (a render surface)
8693 // + clip_parent (masks to bounds)
8694 // + intervening (masks to bounds)
8695 // + clip_child
8696 // + child
8697 //
8698 scoped_refptr<Layer> root = Layer::Create();
8699 scoped_refptr<Layer> clip_parent = Layer::Create();
8700 scoped_refptr<Layer> intervening = Layer::Create();
8701 scoped_refptr<Layer> clip_child = Layer::Create();
8702 scoped_refptr<LayerWithForcedDrawsContent> child =
8703 make_scoped_refptr(new LayerWithForcedDrawsContent);
8704
8705 root->AddChild(clip_parent);
8706 clip_parent->AddChild(intervening);
8707 intervening->AddChild(clip_child);
8708 clip_child->AddChild(child);
8709
8710 clip_child->SetClipParent(clip_parent.get());
8711
8712 intervening->SetMasksToBounds(true);
8713 clip_parent->SetMasksToBounds(true);
8714
8715 gfx::Transform identity_transform;
8716 SetLayerPropertiesForTesting(root.get(),
8717 identity_transform,
8718 identity_transform,
8719 gfx::PointF(),
8720 gfx::PointF(),
8721 gfx::Size(50, 50),
8722 false);
8723 SetLayerPropertiesForTesting(clip_parent.get(),
8724 identity_transform,
8725 identity_transform,
8726 gfx::PointF(),
8727 gfx::PointF(),
8728 gfx::Size(40, 40),
8729 false);
8730 SetLayerPropertiesForTesting(intervening.get(),
8731 identity_transform,
8732 identity_transform,
8733 gfx::PointF(),
8734 gfx::PointF(),
8735 gfx::Size(5, 5),
8736 false);
8737 SetLayerPropertiesForTesting(clip_child.get(),
8738 identity_transform,
8739 identity_transform,
8740 gfx::PointF(),
8741 gfx::PointF(),
8742 gfx::Size(60, 60),
8743 false);
8744 SetLayerPropertiesForTesting(child.get(),
8745 identity_transform,
8746 identity_transform,
8747 gfx::PointF(),
8748 gfx::PointF(),
8749 gfx::Size(60, 60),
8750 false);
8751
8752 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8753 host->SetRootLayer(root);
8754
8755 ExecuteCalculateDrawProperties(root.get());
8756
8757 EXPECT_TRUE(root->render_surface());
8758
8759 // Neither the clip child nor its descendant should have inherited the clip
8760 // from |intervening|.
8761 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8762 clip_child->clip_rect().ToString());
8763 EXPECT_TRUE(clip_child->is_clipped());
8764 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
8765 child->visible_content_rect().ToString());
8766 EXPECT_TRUE(child->is_clipped());
8767}
8768
8769TEST_F(LayerTreeHostCommonTest,
8770 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
8771 // Ensures that non-descendant clip children in the tree do not affect
8772 // render surfaces.
8773 //
8774 // root (a render surface)
8775 // + clip_parent (masks to bounds)
8776 // + render_surface1
8777 // + clip_child
8778 // + render_surface2
8779 // + non_clip_child
8780 //
8781 // In this example render_surface2 should be unaffected by clip_child.
8782 scoped_refptr<Layer> root = Layer::Create();
8783 scoped_refptr<Layer> clip_parent = Layer::Create();
8784 scoped_refptr<Layer> render_surface1 = Layer::Create();
8785 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
8786 make_scoped_refptr(new LayerWithForcedDrawsContent);
8787 scoped_refptr<Layer> render_surface2 = Layer::Create();
8788 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
8789 make_scoped_refptr(new LayerWithForcedDrawsContent);
8790
8791 root->AddChild(clip_parent);
8792 clip_parent->AddChild(render_surface1);
8793 render_surface1->AddChild(clip_child);
8794 clip_parent->AddChild(render_surface2);
8795 render_surface2->AddChild(non_clip_child);
8796
8797 clip_child->SetClipParent(clip_parent.get());
8798
8799 clip_parent->SetMasksToBounds(true);
8800 render_surface1->SetMasksToBounds(true);
8801
8802 gfx::Transform identity_transform;
8803 SetLayerPropertiesForTesting(root.get(),
8804 identity_transform,
8805 identity_transform,
8806 gfx::PointF(),
8807 gfx::PointF(),
8808 gfx::Size(15, 15),
8809 false);
8810 SetLayerPropertiesForTesting(clip_parent.get(),
8811 identity_transform,
8812 identity_transform,
8813 gfx::PointF(),
8814 gfx::PointF(),
8815 gfx::Size(10, 10),
8816 false);
8817 SetLayerPropertiesForTesting(render_surface1.get(),
8818 identity_transform,
8819 identity_transform,
8820 gfx::PointF(),
8821 gfx::PointF(5, 5),
8822 gfx::Size(5, 5),
8823 false);
8824 SetLayerPropertiesForTesting(render_surface2.get(),
8825 identity_transform,
8826 identity_transform,
8827 gfx::PointF(),
8828 gfx::PointF(),
8829 gfx::Size(5, 5),
8830 false);
8831 SetLayerPropertiesForTesting(clip_child.get(),
8832 identity_transform,
8833 identity_transform,
8834 gfx::PointF(),
8835 gfx::PointF(-1, 1),
8836 gfx::Size(10, 10),
8837 false);
8838 SetLayerPropertiesForTesting(non_clip_child.get(),
8839 identity_transform,
8840 identity_transform,
8841 gfx::PointF(),
8842 gfx::PointF(),
8843 gfx::Size(5, 5),
8844 false);
8845
8846 render_surface1->SetForceRenderSurface(true);
8847 render_surface2->SetForceRenderSurface(true);
8848
8849 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8850 host->SetRootLayer(root);
8851
8852 ExecuteCalculateDrawProperties(root.get());
8853
8854 EXPECT_TRUE(root->render_surface());
8855 EXPECT_TRUE(render_surface1->render_surface());
8856 EXPECT_TRUE(render_surface2->render_surface());
8857
8858 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8859 render_surface1->clip_rect().ToString());
8860 EXPECT_TRUE(render_surface1->is_clipped());
8861
8862 // The render surface should not clip (it has unclipped descendants), instead
8863 // it should rely on layer clipping.
8864 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
8865 render_surface1->render_surface()->clip_rect().ToString());
8866 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
8867
8868 // That said, it should have grown to accomodate the unclipped descendant.
8869 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
8870 render_surface1->render_surface()->content_rect().ToString());
8871
8872 // This render surface should clip. It has no unclipped descendants.
8873 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8874 render_surface2->clip_rect().ToString());
8875 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
8876
8877 // It also shouldn't have grown to accomodate the clip child.
8878 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
8879 render_surface2->render_surface()->content_rect().ToString());
8880
8881 // Sanity check our num_unclipped_descendants values.
8882 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
8883 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
8884}
8885
[email protected]45948712013-09-27 02:46:488886TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
8887 FakeImplProxy proxy;
8888 FakeLayerTreeHostImpl host_impl(&proxy);
8889 scoped_ptr<LayerImpl> root =
8890 LayerImpl::Create(host_impl.active_tree(), 12345);
8891 scoped_ptr<LayerImpl> child1 =
8892 LayerImpl::Create(host_impl.active_tree(), 123456);
8893 scoped_ptr<LayerImpl> child2 =
8894 LayerImpl::Create(host_impl.active_tree(), 1234567);
8895 scoped_ptr<LayerImpl> child3 =
8896 LayerImpl::Create(host_impl.active_tree(), 12345678);
8897
8898 gfx::Transform identity_matrix;
8899 gfx::PointF anchor;
8900 gfx::PointF position;
8901 gfx::Size bounds(100, 100);
8902 SetLayerPropertiesForTesting(root.get(),
8903 identity_matrix,
8904 identity_matrix,
8905 anchor,
8906 position,
8907 bounds,
8908 false);
8909 root->SetDrawsContent(true);
8910
8911 // This layer structure normally forces render surface due to preserves3d
8912 // behavior.
8913 bool preserves3d = true;
8914 SetLayerPropertiesForTesting(child1.get(),
8915 identity_matrix,
8916 identity_matrix,
8917 anchor,
8918 position,
8919 bounds,
8920 preserves3d);
8921 child1->SetDrawsContent(true);
8922 SetLayerPropertiesForTesting(child2.get(),
8923 identity_matrix,
8924 identity_matrix,
8925 anchor,
8926 position,
8927 bounds,
8928 false);
8929 child2->SetDrawsContent(true);
8930 SetLayerPropertiesForTesting(child3.get(),
8931 identity_matrix,
8932 identity_matrix,
8933 anchor,
8934 position,
8935 bounds,
8936 false);
8937 child3->SetDrawsContent(true);
8938
8939 child2->AddChild(child3.Pass());
8940 child1->AddChild(child2.Pass());
8941 root->AddChild(child1.Pass());
8942
8943 {
8944 LayerImplList render_surface_layer_list;
8945 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8946 root.get(), root->bounds(), &render_surface_layer_list);
8947 inputs.can_render_to_separate_surface = true;
8948 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8949
8950 EXPECT_EQ(2u, render_surface_layer_list.size());
8951 }
8952
8953 {
8954 LayerImplList render_surface_layer_list;
8955 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8956 root.get(), root->bounds(), &render_surface_layer_list);
8957 inputs.can_render_to_separate_surface = false;
8958 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8959
8960 EXPECT_EQ(1u, render_surface_layer_list.size());
8961 }
8962}
8963
[email protected]a9aa60a82013-08-29 04:28:268964TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
8965 scoped_refptr<Layer> root = Layer::Create();
8966 scoped_refptr<Layer> render_surface = Layer::Create();
8967 scoped_refptr<LayerWithForcedDrawsContent> child =
8968 make_scoped_refptr(new LayerWithForcedDrawsContent);
8969
8970 root->AddChild(render_surface);
8971 render_surface->AddChild(child);
8972
8973 gfx::Transform identity_transform;
8974 SetLayerPropertiesForTesting(root.get(),
8975 identity_transform,
8976 identity_transform,
8977 gfx::PointF(),
8978 gfx::PointF(),
8979 gfx::Size(50, 50),
8980 false);
8981 SetLayerPropertiesForTesting(render_surface.get(),
8982 identity_transform,
8983 identity_transform,
8984 gfx::PointF(),
8985 gfx::PointF(),
8986 gfx::Size(30, 30),
8987 false);
8988 SetLayerPropertiesForTesting(child.get(),
8989 identity_transform,
8990 identity_transform,
8991 gfx::PointF(),
8992 gfx::PointF(),
8993 gfx::Size(20, 20),
8994 false);
8995
8996 root->SetPreserves3d(true);
8997 render_surface->SetDoubleSided(false);
8998 render_surface->SetForceRenderSurface(true);
8999
9000 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
9001 host->SetRootLayer(root);
9002
9003 ExecuteCalculateDrawProperties(root.get());
9004
9005 EXPECT_EQ(2u, render_surface_layer_list()->size());
9006 EXPECT_EQ(1u,
9007 render_surface_layer_list()->at(0)
9008 ->render_surface()->layer_list().size());
9009 EXPECT_EQ(1u,
9010 render_surface_layer_list()->at(1)
9011 ->render_surface()->layer_list().size());
9012
9013 gfx::Transform rotation_transform = identity_transform;
9014 rotation_transform.RotateAboutXAxis(180.0);
9015
9016 render_surface->SetTransform(rotation_transform);
9017
9018 ExecuteCalculateDrawProperties(root.get());
9019
9020 EXPECT_EQ(1u, render_surface_layer_list()->size());
9021 EXPECT_EQ(0u,
9022 render_surface_layer_list()->at(0)
9023 ->render_surface()->layer_list().size());
9024}
9025
[email protected]ba565742012-11-10 09:29:489026} // namespace
9027} // namespace cc