blob: fa5450d45f47a52c6385c2b0ec86217da22da547 [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
167 private:
168 scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
169};
170
171class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
172 public testing::Test {
173};
[email protected]94f206c12012-08-25 00:09:14174
[email protected]96baf3e2012-10-22 23:09:55175class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:32176 public:
177 LayerWithForcedDrawsContent() : Layer() {}
[email protected]94f206c12012-08-25 00:09:14178
[email protected]fb661802013-03-25 01:59:32179 virtual bool DrawsContent() const OVERRIDE;
[email protected]d58499a2012-10-09 22:27:47180
[email protected]fb661802013-03-25 01:59:32181 private:
182 virtual ~LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:14183};
184
[email protected]aedf4e52013-01-09 23:24:44185class LayerCanClipSelf : public Layer {
[email protected]fb661802013-03-25 01:59:32186 public:
187 LayerCanClipSelf() : Layer() {}
[email protected]aedf4e52013-01-09 23:24:44188
[email protected]fb661802013-03-25 01:59:32189 virtual bool DrawsContent() const OVERRIDE;
190 virtual bool CanClipSelf() const OVERRIDE;
[email protected]aedf4e52013-01-09 23:24:44191
[email protected]fb661802013-03-25 01:59:32192 private:
193 virtual ~LayerCanClipSelf() {}
[email protected]aedf4e52013-01-09 23:24:44194};
195
[email protected]fb661802013-03-25 01:59:32196bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:44197
[email protected]fb661802013-03-25 01:59:32198bool LayerCanClipSelf::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:44199
[email protected]fb661802013-03-25 01:59:32200bool LayerCanClipSelf::CanClipSelf() const { return true; }
[email protected]aedf4e52013-01-09 23:24:44201
[email protected]96baf3e2012-10-22 23:09:55202class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:32203 public:
204 MockContentLayerClient() {}
205 virtual ~MockContentLayerClient() {}
206 virtual void PaintContents(SkCanvas* canvas,
207 gfx::Rect clip,
208 gfx::RectF* opaque) OVERRIDE {}
209 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
[email protected]f34a24232012-09-20 22:59:55210};
211
[email protected]fb661802013-03-25 01:59:32212scoped_refptr<ContentLayer> CreateDrawableContentLayer(
213 ContentLayerClient* delegate) {
214 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate);
215 to_return->SetIsDrawable(true);
216 return to_return;
[email protected]f34a24232012-09-20 22:59:55217}
218
[email protected]989386c2013-07-18 21:37:23219#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
220 do { \
221 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
222 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:47223 } while (false)
224
[email protected]989386c2013-07-18 21:37:23225TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32226 // Sanity check: For layers positioned at zero, with zero size,
227 // and with identity transforms, then the draw transform,
228 // screen space transform, and the hierarchy passed on to children
229 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14230
[email protected]fb661802013-03-25 01:59:32231 scoped_refptr<Layer> parent = Layer::Create();
232 scoped_refptr<Layer> child = Layer::Create();
233 scoped_refptr<Layer> grand_child = Layer::Create();
234 parent->AddChild(child);
235 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14236
[email protected]d600df7d2013-08-03 02:34:28237 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
238 host->SetRootLayer(parent);
239
[email protected]fb661802013-03-25 01:59:32240 gfx::Transform identity_matrix;
241 SetLayerPropertiesForTesting(parent.get(),
242 identity_matrix,
243 identity_matrix,
244 gfx::PointF(),
245 gfx::PointF(),
246 gfx::Size(100, 100),
247 false);
248 SetLayerPropertiesForTesting(child.get(),
249 identity_matrix,
250 identity_matrix,
251 gfx::PointF(),
252 gfx::PointF(),
253 gfx::Size(),
254 false);
255 SetLayerPropertiesForTesting(grand_child.get(),
256 identity_matrix,
257 identity_matrix,
258 gfx::PointF(),
259 gfx::PointF(),
260 gfx::Size(),
261 false);
[email protected]94f206c12012-08-25 00:09:14262
[email protected]fb661802013-03-25 01:59:32263 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14264
[email protected]fb661802013-03-25 01:59:32265 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
266 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
267 child->screen_space_transform());
268 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
269 grand_child->draw_transform());
270 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
271 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14272}
273
[email protected]989386c2013-07-18 21:37:23274TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32275 gfx::Transform identity_matrix;
276 scoped_refptr<Layer> layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:14277
[email protected]fb661802013-03-25 01:59:32278 scoped_refptr<Layer> root = Layer::Create();
279 SetLayerPropertiesForTesting(root.get(),
280 identity_matrix,
281 identity_matrix,
282 gfx::PointF(),
283 gfx::PointF(),
284 gfx::Size(1, 2),
285 false);
286 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42287
[email protected]d600df7d2013-08-03 02:34:28288 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
289 host->SetRootLayer(root);
290
[email protected]fb661802013-03-25 01:59:32291 // Case 1: setting the sublayer transform should not affect this layer's draw
292 // transform or screen-space transform.
293 gfx::Transform arbitrary_translation;
294 arbitrary_translation.Translate(10.0, 20.0);
295 SetLayerPropertiesForTesting(layer.get(),
296 identity_matrix,
297 arbitrary_translation,
298 gfx::PointF(),
299 gfx::PointF(),
300 gfx::Size(100, 100),
301 false);
302 ExecuteCalculateDrawProperties(root.get());
303 gfx::Transform expected_draw_transform = identity_matrix;
304 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
305 layer->draw_transform());
306 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
307 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14308
[email protected]fb661802013-03-25 01:59:32309 // Case 2: Setting the bounds of the layer should not affect either the draw
310 // transform or the screenspace transform.
311 gfx::Transform translation_to_center;
312 translation_to_center.Translate(5.0, 6.0);
313 SetLayerPropertiesForTesting(layer.get(),
314 identity_matrix,
315 identity_matrix,
316 gfx::PointF(),
317 gfx::PointF(),
318 gfx::Size(10, 12),
319 false);
320 ExecuteCalculateDrawProperties(root.get());
321 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
322 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
323 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14324
[email protected]fb661802013-03-25 01:59:32325 // Case 3: The anchor point by itself (without a layer transform) should have
326 // no effect on the transforms.
327 SetLayerPropertiesForTesting(layer.get(),
328 identity_matrix,
329 identity_matrix,
330 gfx::PointF(0.25f, 0.25f),
331 gfx::PointF(),
332 gfx::Size(10, 12),
333 false);
334 ExecuteCalculateDrawProperties(root.get());
335 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
336 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
337 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14338
[email protected]fb661802013-03-25 01:59:32339 // Case 4: A change in actual position affects both the draw transform and
340 // screen space transform.
341 gfx::Transform position_transform;
342 position_transform.Translate(0.0, 1.2);
343 SetLayerPropertiesForTesting(layer.get(),
344 identity_matrix,
345 identity_matrix,
346 gfx::PointF(0.25f, 0.25f),
347 gfx::PointF(0.f, 1.2f),
348 gfx::Size(10, 12),
349 false);
350 ExecuteCalculateDrawProperties(root.get());
351 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
352 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
353 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14354
[email protected]fb661802013-03-25 01:59:32355 // Case 5: In the correct sequence of transforms, the layer transform should
356 // pre-multiply the translation_to_center. This is easily tested by using a
357 // scale transform, because scale and translation are not commutative.
358 gfx::Transform layer_transform;
359 layer_transform.Scale3d(2.0, 2.0, 1.0);
360 SetLayerPropertiesForTesting(layer.get(),
361 layer_transform,
362 identity_matrix,
363 gfx::PointF(),
364 gfx::PointF(),
365 gfx::Size(10, 12),
366 false);
367 ExecuteCalculateDrawProperties(root.get());
368 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
369 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
370 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14371
[email protected]fb661802013-03-25 01:59:32372 // Case 6: The layer transform should occur with respect to the anchor point.
373 gfx::Transform translation_to_anchor;
374 translation_to_anchor.Translate(5.0, 0.0);
375 gfx::Transform expected_result =
376 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
377 SetLayerPropertiesForTesting(layer.get(),
378 layer_transform,
379 identity_matrix,
380 gfx::PointF(0.5f, 0.f),
381 gfx::PointF(),
382 gfx::Size(10, 12),
383 false);
384 ExecuteCalculateDrawProperties(root.get());
385 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
386 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
387 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14388
[email protected]fb661802013-03-25 01:59:32389 // Case 7: Verify that position pre-multiplies the layer transform. The
390 // current implementation of CalculateDrawProperties does this implicitly, but
391 // it is still worth testing to detect accidental regressions.
392 expected_result = position_transform * translation_to_anchor *
393 layer_transform * Inverse(translation_to_anchor);
394 SetLayerPropertiesForTesting(layer.get(),
395 layer_transform,
396 identity_matrix,
397 gfx::PointF(0.5f, 0.f),
398 gfx::PointF(0.f, 1.2f),
399 gfx::Size(10, 12),
400 false);
401 ExecuteCalculateDrawProperties(root.get());
402 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
403 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
404 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14405}
406
[email protected]989386c2013-07-18 21:37:23407TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
[email protected]fb661802013-03-25 01:59:32408 const gfx::Vector2d kScrollOffset(50, 100);
409 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01410 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32411 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
412 -kScrollOffset.y());
413 const float kPageScale = 0.888f;
414 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20415
[email protected]fb661802013-03-25 01:59:32416 FakeImplProxy proxy;
417 FakeLayerTreeHostImpl host_impl(&proxy);
[email protected]657b24c2013-03-06 09:01:20418
[email protected]fb661802013-03-25 01:59:32419 gfx::Transform identity_matrix;
420 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
421 LayerImpl::Create(host_impl.active_tree(), 1));
422 LayerImpl* sublayer = sublayer_scoped_ptr.get();
423 sublayer->SetContentsScale(kPageScale * kDeviceScale,
424 kPageScale * kDeviceScale);
425 SetLayerPropertiesForTesting(sublayer,
426 identity_matrix,
427 identity_matrix,
428 gfx::Point(),
429 gfx::PointF(),
430 gfx::Size(500, 500),
431 false);
[email protected]657b24c2013-03-06 09:01:20432
[email protected]fb661802013-03-25 01:59:32433 scoped_ptr<LayerImpl> scroll_layerScopedPtr(
434 LayerImpl::Create(host_impl.active_tree(), 2));
435 LayerImpl* scroll_layer = scroll_layerScopedPtr.get();
436 SetLayerPropertiesForTesting(scroll_layer,
437 identity_matrix,
438 identity_matrix,
439 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47440 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32441 gfx::Size(10, 20),
442 false);
443 scroll_layer->SetScrollable(true);
[email protected]d30700f12013-07-31 08:21:01444 scroll_layer->SetMaxScrollOffset(kMaxScrollOffset);
[email protected]fb661802013-03-25 01:59:32445 scroll_layer->SetScrollOffset(kScrollOffset);
446 scroll_layer->SetScrollDelta(kScrollDelta);
447 gfx::Transform impl_transform;
[email protected]fb661802013-03-25 01:59:32448 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
[email protected]657b24c2013-03-06 09:01:20449
[email protected]fb661802013-03-25 01:59:32450 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
451 SetLayerPropertiesForTesting(root.get(),
452 identity_matrix,
453 identity_matrix,
454 gfx::PointF(),
455 gfx::PointF(),
456 gfx::Size(3, 4),
457 false);
458 root->AddChild(scroll_layerScopedPtr.Pass());
[email protected]657b24c2013-03-06 09:01:20459
[email protected]f2136262013-04-26 21:10:19460 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32461 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32462 gfx::Transform expected_transform = identity_matrix;
463 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
464 sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
465 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
466 MathUtil::Round(sub_layer_screen_position.y()));
467 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
468 sublayer->draw_transform());
469 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
470 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20471
[email protected]fb661802013-03-25 01:59:32472 gfx::Transform arbitrary_translate;
473 const float kTranslateX = 10.6f;
474 const float kTranslateY = 20.6f;
475 arbitrary_translate.Translate(kTranslateX, kTranslateY);
476 SetLayerPropertiesForTesting(scroll_layer,
477 arbitrary_translate,
478 identity_matrix,
479 gfx::PointF(),
[email protected]4ec78f82013-07-11 18:45:47480 gfx::PointF(),
[email protected]fb661802013-03-25 01:59:32481 gfx::Size(10, 20),
482 false);
[email protected]f2136262013-04-26 21:10:19483 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32484 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32485 expected_transform.MakeIdentity();
486 expected_transform.Translate(
487 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
488 sub_layer_screen_position.x()),
489 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
490 sub_layer_screen_position.y()));
491 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
492 sublayer->draw_transform());
[email protected]657b24c2013-03-06 09:01:20493}
494
[email protected]989386c2013-07-18 21:37:23495TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32496 gfx::Transform identity_matrix;
497 scoped_refptr<Layer> root = Layer::Create();
498 scoped_refptr<Layer> parent = Layer::Create();
499 scoped_refptr<Layer> child = Layer::Create();
500 scoped_refptr<Layer> grand_child = Layer::Create();
501 root->AddChild(parent);
502 parent->AddChild(child);
503 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14504
[email protected]d600df7d2013-08-03 02:34:28505 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
506 host->SetRootLayer(root);
507
[email protected]fb661802013-03-25 01:59:32508 // One-time setup of root layer
509 SetLayerPropertiesForTesting(root.get(),
510 identity_matrix,
511 identity_matrix,
512 gfx::PointF(),
513 gfx::PointF(),
514 gfx::Size(1, 2),
515 false);
[email protected]ecc12622012-10-30 20:45:42516
[email protected]fb661802013-03-25 01:59:32517 // Case 1: parent's anchor point should not affect child or grand_child.
518 SetLayerPropertiesForTesting(parent.get(),
519 identity_matrix,
520 identity_matrix,
521 gfx::PointF(0.25f, 0.25f),
522 gfx::PointF(),
523 gfx::Size(10, 12),
524 false);
525 SetLayerPropertiesForTesting(child.get(),
526 identity_matrix,
527 identity_matrix,
528 gfx::PointF(),
529 gfx::PointF(),
530 gfx::Size(16, 18),
531 false);
532 SetLayerPropertiesForTesting(grand_child.get(),
533 identity_matrix,
534 identity_matrix,
535 gfx::PointF(),
536 gfx::PointF(),
537 gfx::Size(76, 78),
538 false);
539 ExecuteCalculateDrawProperties(root.get());
540 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
541 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
542 child->screen_space_transform());
543 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
544 grand_child->draw_transform());
545 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
546 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14547
[email protected]fb661802013-03-25 01:59:32548 // Case 2: parent's position affects child and grand_child.
549 gfx::Transform parent_position_transform;
550 parent_position_transform.Translate(0.0, 1.2);
551 SetLayerPropertiesForTesting(parent.get(),
552 identity_matrix,
553 identity_matrix,
554 gfx::PointF(0.25f, 0.25f),
555 gfx::PointF(0.f, 1.2f),
556 gfx::Size(10, 12),
557 false);
558 SetLayerPropertiesForTesting(child.get(),
559 identity_matrix,
560 identity_matrix,
561 gfx::PointF(),
562 gfx::PointF(),
563 gfx::Size(16, 18),
564 false);
565 SetLayerPropertiesForTesting(grand_child.get(),
566 identity_matrix,
567 identity_matrix,
568 gfx::PointF(),
569 gfx::PointF(),
570 gfx::Size(76, 78),
571 false);
572 ExecuteCalculateDrawProperties(root.get());
573 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
574 child->draw_transform());
575 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
576 child->screen_space_transform());
577 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
578 grand_child->draw_transform());
579 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
580 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14581
[email protected]fb661802013-03-25 01:59:32582 // Case 3: parent's local transform affects child and grandchild
583 gfx::Transform parent_layer_transform;
584 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
585 gfx::Transform parent_translation_to_anchor;
586 parent_translation_to_anchor.Translate(2.5, 3.0);
587 gfx::Transform parent_composite_transform =
588 parent_translation_to_anchor * parent_layer_transform *
589 Inverse(parent_translation_to_anchor);
590 SetLayerPropertiesForTesting(parent.get(),
591 parent_layer_transform,
592 identity_matrix,
593 gfx::PointF(0.25f, 0.25f),
594 gfx::PointF(),
595 gfx::Size(10, 12),
596 false);
597 SetLayerPropertiesForTesting(child.get(),
598 identity_matrix,
599 identity_matrix,
600 gfx::PointF(),
601 gfx::PointF(),
602 gfx::Size(16, 18),
603 false);
604 SetLayerPropertiesForTesting(grand_child.get(),
605 identity_matrix,
606 identity_matrix,
607 gfx::PointF(),
608 gfx::PointF(),
609 gfx::Size(76, 78),
610 false);
611 ExecuteCalculateDrawProperties(root.get());
612 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
613 child->draw_transform());
614 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
615 child->screen_space_transform());
616 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
617 grand_child->draw_transform());
618 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
619 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14620
[email protected]fb661802013-03-25 01:59:32621 // Case 4: parent's sublayer matrix affects child and grandchild scaling is
622 // used here again so that the correct sequence of transforms is properly
623 // tested. Note that preserves3d is false, but the sublayer matrix should
624 // retain its 3D properties when given to child. But then, the child also
625 // does not preserve3D. When it gives its hierarchy to the grand_child, it
626 // should be flattened to 2D.
627 gfx::Transform parent_sublayer_matrix;
628 parent_sublayer_matrix.Scale3d(10.0, 10.0, 3.3);
629 // Sublayer matrix is applied to the anchor point of the parent layer.
630 parent_composite_transform =
631 parent_translation_to_anchor * parent_layer_transform *
632 Inverse(parent_translation_to_anchor) * parent_translation_to_anchor *
633 parent_sublayer_matrix * Inverse(parent_translation_to_anchor);
634 gfx::Transform flattened_composite_transform = parent_composite_transform;
635 flattened_composite_transform.FlattenTo2d();
636 SetLayerPropertiesForTesting(parent.get(),
637 parent_layer_transform,
638 parent_sublayer_matrix,
639 gfx::PointF(0.25f, 0.25f),
640 gfx::PointF(),
641 gfx::Size(10, 12),
642 false);
643 SetLayerPropertiesForTesting(child.get(),
644 identity_matrix,
645 identity_matrix,
646 gfx::PointF(),
647 gfx::PointF(),
648 gfx::Size(16, 18),
649 false);
650 SetLayerPropertiesForTesting(grand_child.get(),
651 identity_matrix,
652 identity_matrix,
653 gfx::PointF(),
654 gfx::PointF(),
655 gfx::Size(76, 78),
656 false);
657 ExecuteCalculateDrawProperties(root.get());
658 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
659 child->draw_transform());
660 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
661 child->screen_space_transform());
662 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_composite_transform,
663 grand_child->draw_transform());
664 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_composite_transform,
665 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14666
[email protected]fb661802013-03-25 01:59:32667 // Case 5: same as Case 4, except that child does preserve 3D, so the
668 // grand_child should receive the non-flattened composite transform.
669 SetLayerPropertiesForTesting(parent.get(),
670 parent_layer_transform,
671 parent_sublayer_matrix,
672 gfx::PointF(0.25f, 0.25f),
673 gfx::PointF(),
674 gfx::Size(10, 12),
675 false);
676 SetLayerPropertiesForTesting(child.get(),
677 identity_matrix,
678 identity_matrix,
679 gfx::PointF(),
680 gfx::PointF(),
681 gfx::Size(16, 18),
682 true);
683 SetLayerPropertiesForTesting(grand_child.get(),
684 identity_matrix,
685 identity_matrix,
686 gfx::PointF(),
687 gfx::PointF(),
688 gfx::Size(76, 78),
689 false);
690 ExecuteCalculateDrawProperties(root.get());
691 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
692 child->draw_transform());
693 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
694 child->screen_space_transform());
695 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
696 grand_child->draw_transform());
697 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
698 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14699}
700
[email protected]989386c2013-07-18 21:37:23701TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
[email protected]fb661802013-03-25 01:59:32702 scoped_refptr<Layer> root = Layer::Create();
703 scoped_refptr<Layer> parent = Layer::Create();
704 scoped_refptr<Layer> child = Layer::Create();
705 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
706 make_scoped_refptr(new LayerWithForcedDrawsContent());
707 root->AddChild(parent);
708 parent->AddChild(child);
709 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14710
[email protected]d600df7d2013-08-03 02:34:28711 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
712 host->SetRootLayer(root);
713
[email protected]fb661802013-03-25 01:59:32714 // One-time setup of root layer
715 gfx::Transform identity_matrix;
716 SetLayerPropertiesForTesting(root.get(),
717 identity_matrix,
718 identity_matrix,
719 gfx::PointF(),
720 gfx::PointF(),
721 gfx::Size(1, 2),
722 false);
[email protected]ecc12622012-10-30 20:45:42723
[email protected]fb661802013-03-25 01:59:32724 // Child is set up so that a new render surface should be created.
725 child->SetOpacity(0.5f);
726 child->SetForceRenderSurface(true);
[email protected]94f206c12012-08-25 00:09:14727
[email protected]fb661802013-03-25 01:59:32728 gfx::Transform parent_layer_transform;
729 parent_layer_transform.Scale3d(1.0, 0.9, 1.0);
730 gfx::Transform parent_translation_to_anchor;
731 parent_translation_to_anchor.Translate(25.0, 30.0);
732 gfx::Transform parent_sublayer_matrix;
733 parent_sublayer_matrix.Scale3d(0.9, 1.0, 3.3);
[email protected]aedf4e52013-01-09 23:24:44734
[email protected]fb661802013-03-25 01:59:32735 gfx::Transform parent_composite_transform =
736 parent_translation_to_anchor * parent_layer_transform *
737 Inverse(parent_translation_to_anchor) * parent_translation_to_anchor *
738 parent_sublayer_matrix * Inverse(parent_translation_to_anchor);
739 gfx::Vector2dF parent_composite_scale =
740 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
741 1.f);
742 gfx::Transform surface_sublayer_transform;
743 surface_sublayer_transform.Scale(parent_composite_scale.x(),
744 parent_composite_scale.y());
745 gfx::Transform surface_sublayer_composite_transform =
746 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14747
[email protected]fb661802013-03-25 01:59:32748 // Child's render surface should not exist yet.
749 ASSERT_FALSE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:14750
[email protected]fb661802013-03-25 01:59:32751 SetLayerPropertiesForTesting(parent.get(),
752 parent_layer_transform,
753 parent_sublayer_matrix,
754 gfx::PointF(0.25f, 0.25f),
755 gfx::PointF(),
756 gfx::Size(100, 120),
757 false);
758 SetLayerPropertiesForTesting(child.get(),
759 identity_matrix,
760 identity_matrix,
761 gfx::PointF(),
762 gfx::PointF(),
763 gfx::Size(16, 18),
764 false);
765 SetLayerPropertiesForTesting(grand_child.get(),
766 identity_matrix,
767 identity_matrix,
768 gfx::PointF(),
769 gfx::PointF(),
770 gfx::Size(8, 10),
771 false);
772 ExecuteCalculateDrawProperties(root.get());
[email protected]94f206c12012-08-25 00:09:14773
[email protected]fb661802013-03-25 01:59:32774 // Render surface should have been created now.
775 ASSERT_TRUE(child->render_surface());
776 ASSERT_EQ(child, child->render_target());
[email protected]94f206c12012-08-25 00:09:14777
[email protected]fb661802013-03-25 01:59:32778 // The child layer's draw transform should refer to its new render surface.
779 // The screen-space transform, however, should still refer to the root.
780 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
781 child->draw_transform());
782 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
783 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14784
[email protected]fb661802013-03-25 01:59:32785 // Because the grand_child is the only drawable content, the child's render
786 // surface will tighten its bounds to the grand_child. The scale at which the
787 // surface's subtree is drawn must be removed from the composite transform.
788 EXPECT_TRANSFORMATION_MATRIX_EQ(
789 surface_sublayer_composite_transform,
790 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14791
[email protected]fb661802013-03-25 01:59:32792 // The screen space is the same as the target since the child surface draws
793 // into the root.
794 EXPECT_TRANSFORMATION_MATRIX_EQ(
795 surface_sublayer_composite_transform,
796 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14797}
798
[email protected]989386c2013-07-18 21:37:23799TEST_F(LayerTreeHostCommonTest, SublayerTransformWithAnchorPoint) {
[email protected]fb661802013-03-25 01:59:32800 // crbug.com/157961 - we were always applying the sublayer transform about
801 // the center of the layer, rather than the anchor point.
[email protected]9a3e6b72013-02-12 18:31:21802
[email protected]fb661802013-03-25 01:59:32803 scoped_refptr<Layer> root = Layer::Create();
804 scoped_refptr<Layer> parent = Layer::Create();
805 scoped_refptr<LayerWithForcedDrawsContent> child =
806 make_scoped_refptr(new LayerWithForcedDrawsContent());
807 root->AddChild(parent);
808 parent->AddChild(child);
[email protected]9a3e6b72013-02-12 18:31:21809
[email protected]d600df7d2013-08-03 02:34:28810 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
811 host->SetRootLayer(root);
812
[email protected]fb661802013-03-25 01:59:32813 gfx::Transform identity_matrix;
814 gfx::Transform parent_sublayer_matrix;
815 parent_sublayer_matrix.ApplyPerspectiveDepth(2.0);
816 gfx::PointF parent_anchor_point(0.2f, 0.8f);
[email protected]9a3e6b72013-02-12 18:31:21817
[email protected]fb661802013-03-25 01:59:32818 SetLayerPropertiesForTesting(root.get(),
819 identity_matrix,
820 identity_matrix,
821 gfx::PointF(),
822 gfx::PointF(),
823 gfx::Size(1, 2),
824 false);
825 SetLayerPropertiesForTesting(parent.get(),
826 identity_matrix,
827 parent_sublayer_matrix,
828 parent_anchor_point,
829 gfx::PointF(),
830 gfx::Size(100, 100),
831 false);
832 SetLayerPropertiesForTesting(child.get(),
833 identity_matrix,
834 identity_matrix,
835 gfx::PointF(),
836 gfx::PointF(),
837 gfx::Size(10, 10),
838 false);
839 ExecuteCalculateDrawProperties(root.get());
[email protected]9a3e6b72013-02-12 18:31:21840
[email protected]fb661802013-03-25 01:59:32841 gfx::Transform expected_child_draw_transform;
842 expected_child_draw_transform.Translate(20.0, 80.0);
843 expected_child_draw_transform.ApplyPerspectiveDepth(2.0);
844 expected_child_draw_transform.Translate(-20.0, -80.0);
845 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
846 child->draw_transform());
[email protected]9a3e6b72013-02-12 18:31:21847}
848
[email protected]989386c2013-07-18 21:37:23849TEST_F(LayerTreeHostCommonTest, SeparateRenderTargetRequirementWithClipping) {
[email protected]fb661802013-03-25 01:59:32850 scoped_refptr<Layer> root = Layer::Create();
851 scoped_refptr<Layer> parent = Layer::Create();
852 scoped_refptr<Layer> child = Layer::Create();
853 scoped_refptr<Layer> grand_child = make_scoped_refptr(new LayerCanClipSelf());
854 root->AddChild(parent);
855 parent->AddChild(child);
856 child->AddChild(grand_child);
857 parent->SetMasksToBounds(true);
858 child->SetMasksToBounds(true);
[email protected]9a3e6b72013-02-12 18:31:21859
[email protected]d600df7d2013-08-03 02:34:28860 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
861 host->SetRootLayer(root);
862
[email protected]fb661802013-03-25 01:59:32863 gfx::Transform identity_matrix;
864 gfx::Transform parent_layer_transform;
865 gfx::Transform parent_sublayer_matrix;
866 gfx::Transform child_layer_matrix;
867
868 // No render surface should exist yet.
869 EXPECT_FALSE(root->render_surface());
870 EXPECT_FALSE(parent->render_surface());
871 EXPECT_FALSE(child->render_surface());
872 EXPECT_FALSE(grand_child->render_surface());
873
874 // One-time setup of root layer
875 parent_layer_transform.Scale3d(1.0, 0.9, 1.0);
876 parent_sublayer_matrix.Scale3d(0.9, 1.0, 3.3);
877 child_layer_matrix.Rotate(20.0);
878
879 SetLayerPropertiesForTesting(root.get(),
880 identity_matrix,
881 identity_matrix,
882 gfx::PointF(),
883 gfx::PointF(),
884 gfx::Size(1, 2),
885 false);
886 SetLayerPropertiesForTesting(parent.get(),
887 parent_layer_transform,
888 parent_sublayer_matrix,
889 gfx::PointF(0.25f, 0.25f),
890 gfx::PointF(),
891 gfx::Size(100, 120),
892 false);
893 SetLayerPropertiesForTesting(child.get(),
894 child_layer_matrix,
895 identity_matrix,
896 gfx::PointF(),
897 gfx::PointF(),
898 gfx::Size(16, 18),
899 false);
900 SetLayerPropertiesForTesting(grand_child.get(),
901 identity_matrix,
902 identity_matrix,
903 gfx::PointF(),
904 gfx::PointF(),
905 gfx::Size(8, 10),
906 false);
907
908 ExecuteCalculateDrawProperties(root.get());
909
910 // Render surfaces should have been created according to clipping rules now
911 // (grandchild can clip self).
912 EXPECT_TRUE(root->render_surface());
913 EXPECT_FALSE(parent->render_surface());
914 EXPECT_FALSE(child->render_surface());
915 EXPECT_FALSE(grand_child->render_surface());
916}
917
[email protected]989386c2013-07-18 21:37:23918TEST_F(LayerTreeHostCommonTest,
919 SeparateRenderTargetRequirementWithoutClipping) {
[email protected]fb661802013-03-25 01:59:32920 scoped_refptr<Layer> root = Layer::Create();
921 scoped_refptr<Layer> parent = Layer::Create();
922 scoped_refptr<Layer> child = Layer::Create();
923 // This layer cannot clip itself, a feature we are testing here.
924 scoped_refptr<Layer> grand_child =
925 make_scoped_refptr(new LayerWithForcedDrawsContent());
926 root->AddChild(parent);
927 parent->AddChild(child);
928 child->AddChild(grand_child);
929 parent->SetMasksToBounds(true);
930 child->SetMasksToBounds(true);
931
[email protected]d600df7d2013-08-03 02:34:28932 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
933 host->SetRootLayer(root);
934
[email protected]fb661802013-03-25 01:59:32935 gfx::Transform identity_matrix;
936 gfx::Transform parent_layer_transform;
937 gfx::Transform parent_sublayer_matrix;
938 gfx::Transform child_layer_matrix;
939
940 // No render surface should exist yet.
941 EXPECT_FALSE(root->render_surface());
942 EXPECT_FALSE(parent->render_surface());
943 EXPECT_FALSE(child->render_surface());
944 EXPECT_FALSE(grand_child->render_surface());
945
946 // One-time setup of root layer
947 parent_layer_transform.Scale3d(1.0, 0.9, 1.0);
948 parent_sublayer_matrix.Scale3d(0.9, 1.0, 3.3);
949 child_layer_matrix.Rotate(20.0);
950
951 SetLayerPropertiesForTesting(root.get(),
952 identity_matrix,
953 identity_matrix,
954 gfx::PointF(),
955 gfx::PointF(),
956 gfx::Size(1, 2),
957 false);
958 SetLayerPropertiesForTesting(parent.get(),
959 parent_layer_transform,
960 parent_sublayer_matrix,
961 gfx::PointF(0.25f, 0.25f),
962 gfx::PointF(),
963 gfx::Size(100, 120),
964 false);
965 SetLayerPropertiesForTesting(child.get(),
966 child_layer_matrix,
967 identity_matrix,
968 gfx::PointF(),
969 gfx::PointF(),
970 gfx::Size(16, 18),
971 false);
972 SetLayerPropertiesForTesting(grand_child.get(),
973 identity_matrix,
974 identity_matrix,
975 gfx::PointF(),
976 gfx::PointF(),
977 gfx::Size(8, 10),
978 false);
979
980 ExecuteCalculateDrawProperties(root.get());
981
982 // Render surfaces should have been created according to clipping rules now
983 // (grandchild can't clip self).
984 EXPECT_TRUE(root->render_surface());
985 EXPECT_FALSE(parent->render_surface());
986 EXPECT_TRUE(child->render_surface());
987 EXPECT_FALSE(grand_child->render_surface());
988}
989
[email protected]989386c2013-07-18 21:37:23990TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
[email protected]fb661802013-03-25 01:59:32991 scoped_refptr<Layer> root = Layer::Create();
992 scoped_refptr<Layer> parent = Layer::Create();
993 scoped_refptr<Layer> child = Layer::Create();
994 scoped_refptr<Layer> child_replica = Layer::Create();
995 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
996 make_scoped_refptr(new LayerWithForcedDrawsContent());
997 root->AddChild(parent);
998 parent->AddChild(child);
999 child->AddChild(grand_child);
1000 child->SetReplicaLayer(child_replica.get());
1001
[email protected]d600df7d2013-08-03 02:34:281002 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1003 host->SetRootLayer(root);
1004
[email protected]fb661802013-03-25 01:59:321005 // One-time setup of root layer
1006 gfx::Transform identity_matrix;
1007 SetLayerPropertiesForTesting(root.get(),
1008 identity_matrix,
1009 identity_matrix,
1010 gfx::PointF(),
1011 gfx::PointF(),
1012 gfx::Size(1, 2),
1013 false);
1014
1015 // Child is set up so that a new render surface should be created.
1016 child->SetOpacity(0.5f);
1017
1018 gfx::Transform parent_layer_transform;
1019 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
1020 gfx::Transform parent_translation_to_anchor;
1021 parent_translation_to_anchor.Translate(2.5, 3.0);
1022 gfx::Transform parent_sublayer_matrix;
1023 parent_sublayer_matrix.Scale3d(10.0, 10.0, 3.3);
1024 gfx::Transform parent_composite_transform =
1025 parent_translation_to_anchor * parent_layer_transform *
1026 Inverse(parent_translation_to_anchor) * parent_translation_to_anchor *
1027 parent_sublayer_matrix * Inverse(parent_translation_to_anchor);
1028 gfx::Transform replica_layer_transform;
1029 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
1030 gfx::Vector2dF parent_composite_scale =
1031 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
1032 1.f);
1033 gfx::Transform surface_sublayer_transform;
1034 surface_sublayer_transform.Scale(parent_composite_scale.x(),
1035 parent_composite_scale.y());
1036 gfx::Transform replica_composite_transform =
1037 parent_composite_transform * replica_layer_transform *
1038 Inverse(surface_sublayer_transform);
1039
1040 // Child's render surface should not exist yet.
1041 ASSERT_FALSE(child->render_surface());
1042
1043 SetLayerPropertiesForTesting(parent.get(),
1044 parent_layer_transform,
1045 parent_sublayer_matrix,
1046 gfx::PointF(0.25f, 0.25f),
1047 gfx::PointF(),
1048 gfx::Size(10, 12),
1049 false);
1050 SetLayerPropertiesForTesting(child.get(),
1051 identity_matrix,
1052 identity_matrix,
1053 gfx::PointF(),
1054 gfx::PointF(),
1055 gfx::Size(16, 18),
1056 false);
1057 SetLayerPropertiesForTesting(grand_child.get(),
1058 identity_matrix,
1059 identity_matrix,
1060 gfx::PointF(),
1061 gfx::PointF(-0.5f, -0.5f),
1062 gfx::Size(1, 1),
1063 false);
1064 SetLayerPropertiesForTesting(child_replica.get(),
1065 replica_layer_transform,
1066 identity_matrix,
1067 gfx::PointF(),
1068 gfx::PointF(),
1069 gfx::Size(),
1070 false);
1071 ExecuteCalculateDrawProperties(root.get());
1072
1073 // Render surface should have been created now.
1074 ASSERT_TRUE(child->render_surface());
1075 ASSERT_EQ(child, child->render_target());
1076
1077 EXPECT_TRANSFORMATION_MATRIX_EQ(
1078 replica_composite_transform,
1079 child->render_target()->render_surface()->replica_draw_transform());
1080 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
1081 child->render_target()->render_surface()
1082 ->replica_screen_space_transform());
1083}
1084
[email protected]989386c2013-07-18 21:37:231085TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:321086 // This test creates a more complex tree and verifies it all at once. This
1087 // covers the following cases:
1088 // - layers that are described w.r.t. a render surface: should have draw
1089 // transforms described w.r.t. that surface
1090 // - A render surface described w.r.t. an ancestor render surface: should
1091 // have a draw transform described w.r.t. that ancestor surface
1092 // - Replicas of a render surface are described w.r.t. the replica's
1093 // transform around its anchor, along with the surface itself.
1094 // - Sanity check on recursion: verify transforms of layers described w.r.t.
1095 // a render surface that is described w.r.t. an ancestor render surface.
1096 // - verifying that each layer has a reference to the correct render surface
1097 // and render target values.
1098
1099 scoped_refptr<Layer> root = Layer::Create();
1100 scoped_refptr<Layer> parent = Layer::Create();
1101 scoped_refptr<Layer> render_surface1 = Layer::Create();
1102 scoped_refptr<Layer> render_surface2 = Layer::Create();
1103 scoped_refptr<Layer> child_of_root = Layer::Create();
1104 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
1105 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
1106 scoped_refptr<Layer> replica_of_rs1 = Layer::Create();
1107 scoped_refptr<Layer> replica_of_rs2 = Layer::Create();
1108 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
1109 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
1110 make_scoped_refptr(new LayerWithForcedDrawsContent());
1111 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
1112 make_scoped_refptr(new LayerWithForcedDrawsContent());
1113 root->AddChild(parent);
1114 parent->AddChild(render_surface1);
1115 parent->AddChild(child_of_root);
1116 render_surface1->AddChild(child_of_rs1);
1117 render_surface1->AddChild(render_surface2);
1118 render_surface2->AddChild(child_of_rs2);
1119 child_of_root->AddChild(grand_child_of_root);
1120 child_of_rs1->AddChild(grand_child_of_rs1);
1121 child_of_rs2->AddChild(grand_child_of_rs2);
1122 render_surface1->SetReplicaLayer(replica_of_rs1.get());
1123 render_surface2->SetReplicaLayer(replica_of_rs2.get());
1124
[email protected]d600df7d2013-08-03 02:34:281125 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1126 host->SetRootLayer(root);
1127
[email protected]fb661802013-03-25 01:59:321128 // In combination with descendant draws content, opacity != 1 forces the layer
1129 // to have a new render surface.
1130 render_surface1->SetOpacity(0.5f);
1131 render_surface2->SetOpacity(0.33f);
1132
1133 // One-time setup of root layer
1134 gfx::Transform identity_matrix;
1135 SetLayerPropertiesForTesting(root.get(),
1136 identity_matrix,
1137 identity_matrix,
1138 gfx::PointF(),
1139 gfx::PointF(),
1140 gfx::Size(1, 2),
1141 false);
1142
1143 // All layers in the tree are initialized with an anchor at .25 and a size of
1144 // (10,10). matrix "A" is the composite layer transform used in all layers,
1145 // centered about the anchor point. matrix "B" is the sublayer transform used
1146 // in all layers, centered about the center position of the layer. matrix "R"
1147 // is the composite replica transform used in all replica layers.
1148 //
1149 // x component tests that layer_transform and sublayer_transform are done in
1150 // the right order (translation and scale are noncommutative). y component
1151 // has a translation by 1 for every ancestor, which indicates the "depth" of
1152 // the layer in the hierarchy.
1153 gfx::Transform translation_to_anchor;
1154 translation_to_anchor.Translate(2.5, 0.0);
1155 gfx::Transform layer_transform;
1156 layer_transform.Translate(1.0, 1.0);
1157 gfx::Transform sublayer_transform;
1158 sublayer_transform.Scale3d(10.0, 1.0, 1.0);
1159 gfx::Transform replica_layer_transform;
1160 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
1161
1162 gfx::Transform A =
1163 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
1164 gfx::Transform B = translation_to_anchor * sublayer_transform *
1165 Inverse(translation_to_anchor);
1166 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
1167 Inverse(translation_to_anchor);
1168
1169 gfx::Vector2dF surface1_parent_transform_scale =
1170 MathUtil::ComputeTransform2dScaleComponents(A * B, 1.f);
1171 gfx::Transform surface1_sublayer_transform;
1172 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
1173 surface1_parent_transform_scale.y());
1174
1175 // SS1 = transform given to the subtree of render_surface1
1176 gfx::Transform SS1 = surface1_sublayer_transform;
1177 // S1 = transform to move from render_surface1 pixels to the layer space of
1178 // the owning layer
1179 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
1180
1181 gfx::Vector2dF surface2_parent_transform_scale =
1182 MathUtil::ComputeTransform2dScaleComponents(SS1 * A * B, 1.f);
1183 gfx::Transform surface2_sublayer_transform;
1184 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
1185 surface2_parent_transform_scale.y());
1186
1187 // SS2 = transform given to the subtree of render_surface2
1188 gfx::Transform SS2 = surface2_sublayer_transform;
1189 // S2 = transform to move from render_surface2 pixels to the layer space of
1190 // the owning layer
1191 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
1192
1193 SetLayerPropertiesForTesting(parent.get(),
1194 layer_transform,
1195 sublayer_transform,
1196 gfx::PointF(0.25f, 0.f),
1197 gfx::PointF(),
1198 gfx::Size(10, 10),
1199 false);
1200 SetLayerPropertiesForTesting(render_surface1.get(),
1201 layer_transform,
1202 sublayer_transform,
1203 gfx::PointF(0.25f, 0.f),
1204 gfx::PointF(),
1205 gfx::Size(10, 10),
1206 false);
1207 SetLayerPropertiesForTesting(render_surface2.get(),
1208 layer_transform,
1209 sublayer_transform,
1210 gfx::PointF(0.25f, 0.f),
1211 gfx::PointF(),
1212 gfx::Size(10, 10),
1213 false);
1214 SetLayerPropertiesForTesting(child_of_root.get(),
1215 layer_transform,
1216 sublayer_transform,
1217 gfx::PointF(0.25f, 0.f),
1218 gfx::PointF(),
1219 gfx::Size(10, 10),
1220 false);
1221 SetLayerPropertiesForTesting(child_of_rs1.get(),
1222 layer_transform,
1223 sublayer_transform,
1224 gfx::PointF(0.25f, 0.f),
1225 gfx::PointF(),
1226 gfx::Size(10, 10),
1227 false);
1228 SetLayerPropertiesForTesting(child_of_rs2.get(),
1229 layer_transform,
1230 sublayer_transform,
1231 gfx::PointF(0.25f, 0.f),
1232 gfx::PointF(),
1233 gfx::Size(10, 10),
1234 false);
1235 SetLayerPropertiesForTesting(grand_child_of_root.get(),
1236 layer_transform,
1237 sublayer_transform,
1238 gfx::PointF(0.25f, 0.f),
1239 gfx::PointF(),
1240 gfx::Size(10, 10),
1241 false);
1242 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
1243 layer_transform,
1244 sublayer_transform,
1245 gfx::PointF(0.25f, 0.f),
1246 gfx::PointF(),
1247 gfx::Size(10, 10),
1248 false);
1249 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
1250 layer_transform,
1251 sublayer_transform,
1252 gfx::PointF(0.25f, 0.f),
1253 gfx::PointF(),
1254 gfx::Size(10, 10),
1255 false);
1256 SetLayerPropertiesForTesting(replica_of_rs1.get(),
1257 replica_layer_transform,
1258 sublayer_transform,
1259 gfx::PointF(0.25f, 0.f),
1260 gfx::PointF(),
1261 gfx::Size(),
1262 false);
1263 SetLayerPropertiesForTesting(replica_of_rs2.get(),
1264 replica_layer_transform,
1265 sublayer_transform,
1266 gfx::PointF(0.25f, 0.f),
1267 gfx::PointF(),
1268 gfx::Size(),
1269 false);
1270
1271 ExecuteCalculateDrawProperties(root.get());
1272
1273 // Only layers that are associated with render surfaces should have an actual
1274 // RenderSurface() value.
1275 ASSERT_TRUE(root->render_surface());
1276 ASSERT_FALSE(child_of_root->render_surface());
1277 ASSERT_FALSE(grand_child_of_root->render_surface());
1278
1279 ASSERT_TRUE(render_surface1->render_surface());
1280 ASSERT_FALSE(child_of_rs1->render_surface());
1281 ASSERT_FALSE(grand_child_of_rs1->render_surface());
1282
1283 ASSERT_TRUE(render_surface2->render_surface());
1284 ASSERT_FALSE(child_of_rs2->render_surface());
1285 ASSERT_FALSE(grand_child_of_rs2->render_surface());
1286
1287 // Verify all render target accessors
1288 EXPECT_EQ(root, parent->render_target());
1289 EXPECT_EQ(root, child_of_root->render_target());
1290 EXPECT_EQ(root, grand_child_of_root->render_target());
1291
1292 EXPECT_EQ(render_surface1, render_surface1->render_target());
1293 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
1294 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
1295
1296 EXPECT_EQ(render_surface2, render_surface2->render_target());
1297 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
1298 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
1299
1300 // Verify layer draw transforms note that draw transforms are described with
1301 // respect to the nearest ancestor render surface but screen space transforms
1302 // are described with respect to the root.
1303 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
1304 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, child_of_root->draw_transform());
1305 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A,
1306 grand_child_of_root->draw_transform());
1307
1308 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
1309 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A, child_of_rs1->draw_transform());
1310 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A * B * A,
1311 grand_child_of_rs1->draw_transform());
1312
1313 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
1314 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * B * A, child_of_rs2->draw_transform());
1315 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * B * A * B * A,
1316 grand_child_of_rs2->draw_transform());
1317
1318 // Verify layer screen-space transforms
1319 //
1320 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
1321 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A,
1322 child_of_root->screen_space_transform());
1323 EXPECT_TRANSFORMATION_MATRIX_EQ(
1324 A * B * A * B * A, grand_child_of_root->screen_space_transform());
1325
1326 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A,
1327 render_surface1->screen_space_transform());
1328 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A,
1329 child_of_rs1->screen_space_transform());
1330 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A,
1331 grand_child_of_rs1->screen_space_transform());
1332
1333 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A,
1334 render_surface2->screen_space_transform());
1335 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A,
1336 child_of_rs2->screen_space_transform());
1337 EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A * B * A,
1338 grand_child_of_rs2->screen_space_transform());
1339
1340 // Verify render surface transforms.
1341 //
1342 // Draw transform of render surface 1 is described with respect to root.
1343 EXPECT_TRANSFORMATION_MATRIX_EQ(
1344 A * B * A * S1, render_surface1->render_surface()->draw_transform());
1345 EXPECT_TRANSFORMATION_MATRIX_EQ(
1346 A * B * R * S1,
1347 render_surface1->render_surface()->replica_draw_transform());
1348 EXPECT_TRANSFORMATION_MATRIX_EQ(
1349 A * B * A * S1,
1350 render_surface1->render_surface()->screen_space_transform());
1351 EXPECT_TRANSFORMATION_MATRIX_EQ(
1352 A * B * R * S1,
1353 render_surface1->render_surface()->replica_screen_space_transform());
1354 // Draw transform of render surface 2 is described with respect to render
1355 // surface 1.
1356 EXPECT_TRANSFORMATION_MATRIX_EQ(
1357 SS1 * B * A * S2, render_surface2->render_surface()->draw_transform());
1358 EXPECT_TRANSFORMATION_MATRIX_EQ(
1359 SS1 * B * R * S2,
1360 render_surface2->render_surface()->replica_draw_transform());
1361 EXPECT_TRANSFORMATION_MATRIX_EQ(
1362 A * B * A * B * A * S2,
1363 render_surface2->render_surface()->screen_space_transform());
1364 EXPECT_TRANSFORMATION_MATRIX_EQ(
1365 A * B * A * B * R * S2,
1366 render_surface2->render_surface()->replica_screen_space_transform());
1367
1368 // Sanity check. If these fail there is probably a bug in the test itself. It
1369 // is expected that we correctly set up transforms so that the y-component of
1370 // the screen-space transform encodes the "depth" of the layer in the tree.
1371 EXPECT_FLOAT_EQ(1.0,
1372 parent->screen_space_transform().matrix().getDouble(1, 3));
1373 EXPECT_FLOAT_EQ(
1374 2.0, child_of_root->screen_space_transform().matrix().getDouble(1, 3));
1375 EXPECT_FLOAT_EQ(
1376 3.0,
1377 grand_child_of_root->screen_space_transform().matrix().getDouble(1, 3));
1378
1379 EXPECT_FLOAT_EQ(
1380 2.0, render_surface1->screen_space_transform().matrix().getDouble(1, 3));
1381 EXPECT_FLOAT_EQ(
1382 3.0, child_of_rs1->screen_space_transform().matrix().getDouble(1, 3));
1383 EXPECT_FLOAT_EQ(
1384 4.0,
1385 grand_child_of_rs1->screen_space_transform().matrix().getDouble(1, 3));
1386
1387 EXPECT_FLOAT_EQ(
1388 3.0, render_surface2->screen_space_transform().matrix().getDouble(1, 3));
1389 EXPECT_FLOAT_EQ(
1390 4.0, child_of_rs2->screen_space_transform().matrix().getDouble(1, 3));
1391 EXPECT_FLOAT_EQ(
1392 5.0,
1393 grand_child_of_rs2->screen_space_transform().matrix().getDouble(1, 3));
1394}
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);
1663 EXPECT_EQ(compositeSquared, root->draw_properties().target_space_transform);
1664 EXPECT_EQ(compositeCubed, child->draw_properties().target_space_transform);
1665 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1666 }
[email protected]f224cc92013-06-06 23:23:321667}
1668
[email protected]989386c2013-07-18 21:37:231669TEST_F(LayerTreeHostCommonTest,
1670 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321671 scoped_refptr<Layer> parent = Layer::Create();
1672 scoped_refptr<Layer> render_surface1 = Layer::Create();
1673 scoped_refptr<LayerWithForcedDrawsContent> child =
1674 make_scoped_refptr(new LayerWithForcedDrawsContent());
1675
[email protected]d600df7d2013-08-03 02:34:281676 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1677 host->SetRootLayer(parent);
1678
1679
[email protected]fb661802013-03-25 01:59:321680 const gfx::Transform identity_matrix;
1681 SetLayerPropertiesForTesting(parent.get(),
1682 identity_matrix,
1683 identity_matrix,
1684 gfx::PointF(),
1685 gfx::PointF(),
1686 gfx::Size(10, 10),
1687 false);
1688 SetLayerPropertiesForTesting(render_surface1.get(),
1689 identity_matrix,
1690 identity_matrix,
1691 gfx::PointF(),
1692 gfx::PointF(),
1693 gfx::Size(10, 10),
1694 false);
1695 SetLayerPropertiesForTesting(child.get(),
1696 identity_matrix,
1697 identity_matrix,
1698 gfx::PointF(),
1699 gfx::PointF(30.f, 30.f),
1700 gfx::Size(10, 10),
1701 false);
1702
1703 parent->AddChild(render_surface1);
1704 parent->SetMasksToBounds(true);
1705 render_surface1->AddChild(child);
1706 render_surface1->SetForceRenderSurface(true);
1707
[email protected]989386c2013-07-18 21:37:231708 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531709 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1710 parent.get(),
1711 parent->bounds(),
1712 gfx::Transform(),
1713 &render_surface_layer_list);
1714 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321715
1716 // The child layer's content is entirely outside the parent's clip rect, so
1717 // the intermediate render surface should not be listed here, even if it was
1718 // forced to be created. Render surfaces without children or visible content
1719 // are unexpected at draw time (e.g. we might try to create a content texture
1720 // of size 0).
1721 ASSERT_TRUE(parent->render_surface());
1722 ASSERT_FALSE(render_surface1->render_surface());
1723 EXPECT_EQ(1U, render_surface_layer_list.size());
1724}
1725
[email protected]989386c2013-07-18 21:37:231726TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321727 scoped_refptr<Layer> parent = Layer::Create();
1728 scoped_refptr<Layer> render_surface1 = Layer::Create();
1729 scoped_refptr<LayerWithForcedDrawsContent> child =
1730 make_scoped_refptr(new LayerWithForcedDrawsContent());
1731
[email protected]d600df7d2013-08-03 02:34:281732 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1733 host->SetRootLayer(parent);
1734
[email protected]fb661802013-03-25 01:59:321735 const gfx::Transform identity_matrix;
1736 SetLayerPropertiesForTesting(render_surface1.get(),
1737 identity_matrix,
1738 identity_matrix,
1739 gfx::PointF(),
1740 gfx::PointF(),
1741 gfx::Size(10, 10),
1742 false);
1743 SetLayerPropertiesForTesting(child.get(),
1744 identity_matrix,
1745 identity_matrix,
1746 gfx::PointF(),
1747 gfx::PointF(),
1748 gfx::Size(10, 10),
1749 false);
1750
1751 parent->AddChild(render_surface1);
1752 render_surface1->AddChild(child);
1753 render_surface1->SetForceRenderSurface(true);
1754 render_surface1->SetOpacity(0.f);
1755
[email protected]989386c2013-07-18 21:37:231756 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531757 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1758 parent.get(), parent->bounds(), &render_surface_layer_list);
1759 inputs.can_adjust_raster_scales = true;
1760 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321761
1762 // Since the layer is transparent, render_surface1->render_surface() should
1763 // not have gotten added anywhere. Also, the drawable content rect should not
1764 // have been extended by the children.
1765 ASSERT_TRUE(parent->render_surface());
1766 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1767 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231768 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321769 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1770}
1771
[email protected]989386c2013-07-18 21:37:231772TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321773 scoped_refptr<Layer> parent = Layer::Create();
1774 scoped_refptr<Layer> render_surface1 = Layer::Create();
1775 scoped_refptr<LayerWithForcedDrawsContent> child =
1776 make_scoped_refptr(new LayerWithForcedDrawsContent());
1777 render_surface1->SetForceRenderSurface(true);
1778
[email protected]d600df7d2013-08-03 02:34:281779 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1780 host->SetRootLayer(parent);
1781
[email protected]fb661802013-03-25 01:59:321782 const gfx::Transform identity_matrix;
1783 SetLayerPropertiesForTesting(parent.get(),
1784 identity_matrix,
1785 identity_matrix,
1786 gfx::PointF(),
1787 gfx::PointF(),
1788 gfx::Size(10, 10),
1789 false);
1790 SetLayerPropertiesForTesting(render_surface1.get(),
1791 identity_matrix,
1792 identity_matrix,
1793 gfx::PointF(),
1794 gfx::PointF(),
1795 gfx::Size(10, 10),
1796 false);
1797 SetLayerPropertiesForTesting(child.get(),
1798 identity_matrix,
1799 identity_matrix,
1800 gfx::PointF(),
1801 gfx::PointF(),
1802 gfx::Size(10, 10),
1803 false);
1804
1805 parent->AddChild(render_surface1);
1806 render_surface1->AddChild(child);
1807
1808 // Sanity check before the actual test
1809 EXPECT_FALSE(parent->render_surface());
1810 EXPECT_FALSE(render_surface1->render_surface());
1811
[email protected]989386c2013-07-18 21:37:231812 {
1813 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531814 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1815 parent.get(), parent->bounds(), &render_surface_layer_list);
1816 inputs.can_adjust_raster_scales = true;
1817 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321818
[email protected]989386c2013-07-18 21:37:231819 // The root layer always creates a render surface
1820 EXPECT_TRUE(parent->render_surface());
1821 EXPECT_TRUE(render_surface1->render_surface());
1822 EXPECT_EQ(2U, render_surface_layer_list.size());
1823 }
[email protected]fb661802013-03-25 01:59:321824
[email protected]989386c2013-07-18 21:37:231825 {
1826 RenderSurfaceLayerList render_surface_layer_list;
1827 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531828 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1829 parent.get(), parent->bounds(), &render_surface_layer_list);
1830 inputs.can_adjust_raster_scales = true;
1831 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231832 EXPECT_TRUE(parent->render_surface());
1833 EXPECT_FALSE(render_surface1->render_surface());
1834 EXPECT_EQ(1U, render_surface_layer_list.size());
1835 }
[email protected]fb661802013-03-25 01:59:321836}
1837
[email protected]989386c2013-07-18 21:37:231838TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321839 // The entire subtree of layers that are outside the clip rect should be
1840 // culled away, and should not affect the render_surface_layer_list.
1841 //
1842 // The test tree is set up as follows:
1843 // - all layers except the leaf_nodes are forced to be a new render surface
1844 // that have something to draw.
1845 // - parent is a large container layer.
1846 // - child has masksToBounds=true to cause clipping.
1847 // - grand_child is positioned outside of the child's bounds
1848 // - great_grand_child is also kept outside child's bounds.
1849 //
1850 // In this configuration, grand_child and great_grand_child are completely
1851 // outside the clip rect, and they should never get scheduled on the list of
1852 // render surfaces.
1853 //
1854
1855 const gfx::Transform identity_matrix;
1856 scoped_refptr<Layer> parent = Layer::Create();
1857 scoped_refptr<Layer> child = Layer::Create();
1858 scoped_refptr<Layer> grand_child = Layer::Create();
1859 scoped_refptr<Layer> great_grand_child = Layer::Create();
1860 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1861 make_scoped_refptr(new LayerWithForcedDrawsContent());
1862 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1863 make_scoped_refptr(new LayerWithForcedDrawsContent());
1864 parent->AddChild(child);
1865 child->AddChild(grand_child);
1866 grand_child->AddChild(great_grand_child);
1867
[email protected]d600df7d2013-08-03 02:34:281868 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1869 host->SetRootLayer(parent);
1870
[email protected]fb661802013-03-25 01:59:321871 // leaf_node1 ensures that parent and child are kept on the
1872 // render_surface_layer_list, even though grand_child and great_grand_child
1873 // should be clipped.
1874 child->AddChild(leaf_node1);
1875 great_grand_child->AddChild(leaf_node2);
1876
1877 SetLayerPropertiesForTesting(parent.get(),
1878 identity_matrix,
1879 identity_matrix,
1880 gfx::PointF(),
1881 gfx::PointF(),
1882 gfx::Size(500, 500),
1883 false);
1884 SetLayerPropertiesForTesting(child.get(),
1885 identity_matrix,
1886 identity_matrix,
1887 gfx::PointF(),
1888 gfx::PointF(),
1889 gfx::Size(20, 20),
1890 false);
1891 SetLayerPropertiesForTesting(grand_child.get(),
1892 identity_matrix,
1893 identity_matrix,
1894 gfx::PointF(),
1895 gfx::PointF(45.f, 45.f),
1896 gfx::Size(10, 10),
1897 false);
1898 SetLayerPropertiesForTesting(great_grand_child.get(),
1899 identity_matrix,
1900 identity_matrix,
1901 gfx::PointF(),
1902 gfx::PointF(),
1903 gfx::Size(10, 10),
1904 false);
1905 SetLayerPropertiesForTesting(leaf_node1.get(),
1906 identity_matrix,
1907 identity_matrix,
1908 gfx::PointF(),
1909 gfx::PointF(),
1910 gfx::Size(500, 500),
1911 false);
1912 SetLayerPropertiesForTesting(leaf_node2.get(),
1913 identity_matrix,
1914 identity_matrix,
1915 gfx::PointF(),
1916 gfx::PointF(),
1917 gfx::Size(20, 20),
1918 false);
1919
1920 child->SetMasksToBounds(true);
1921 child->SetOpacity(0.4f);
1922 child->SetForceRenderSurface(true);
1923 grand_child->SetOpacity(0.5f);
1924 great_grand_child->SetOpacity(0.4f);
1925
[email protected]989386c2013-07-18 21:37:231926 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531927 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1928 parent.get(), parent->bounds(), &render_surface_layer_list);
1929 inputs.can_adjust_raster_scales = true;
1930 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321931
1932 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231933 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1934 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321935}
1936
[email protected]989386c2013-07-18 21:37:231937TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321938 // When a render surface has a clip rect, it is used to clip the content rect
1939 // of the surface. When the render surface is animating its transforms, then
1940 // the content rect's position in the clip rect is not defined on the main
1941 // thread, and its content rect should not be clipped.
1942
1943 // The test tree is set up as follows:
1944 // - parent is a container layer that masksToBounds=true to cause clipping.
1945 // - child is a render surface, which has a clip rect set to the bounds of
1946 // the parent.
1947 // - grand_child is a render surface, and the only visible content in child.
1948 // It is positioned outside of the clip rect from parent.
1949
1950 // In this configuration, grand_child should be outside the clipped
1951 // content rect of the child, making grand_child not appear in the
1952 // render_surface_layer_list. However, when we place an animation on the
1953 // child, this clipping should be avoided and we should keep the grand_child
1954 // in the render_surface_layer_list.
1955
1956 const gfx::Transform identity_matrix;
1957 scoped_refptr<Layer> parent = Layer::Create();
1958 scoped_refptr<Layer> child = Layer::Create();
1959 scoped_refptr<Layer> grand_child = Layer::Create();
1960 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1961 make_scoped_refptr(new LayerWithForcedDrawsContent());
1962 parent->AddChild(child);
1963 child->AddChild(grand_child);
1964 grand_child->AddChild(leaf_node);
1965
[email protected]d600df7d2013-08-03 02:34:281966 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
1967 host->SetRootLayer(parent);
1968
[email protected]fb661802013-03-25 01:59:321969 SetLayerPropertiesForTesting(parent.get(),
1970 identity_matrix,
1971 identity_matrix,
1972 gfx::PointF(),
1973 gfx::PointF(),
1974 gfx::Size(100, 100),
1975 false);
1976 SetLayerPropertiesForTesting(child.get(),
1977 identity_matrix,
1978 identity_matrix,
1979 gfx::PointF(),
1980 gfx::PointF(),
1981 gfx::Size(20, 20),
1982 false);
1983 SetLayerPropertiesForTesting(grand_child.get(),
1984 identity_matrix,
1985 identity_matrix,
1986 gfx::PointF(),
1987 gfx::PointF(200.f, 200.f),
1988 gfx::Size(10, 10),
1989 false);
1990 SetLayerPropertiesForTesting(leaf_node.get(),
1991 identity_matrix,
1992 identity_matrix,
1993 gfx::PointF(),
1994 gfx::PointF(),
1995 gfx::Size(10, 10),
1996 false);
1997
1998 parent->SetMasksToBounds(true);
1999 child->SetOpacity(0.4f);
2000 child->SetForceRenderSurface(true);
2001 grand_child->SetOpacity(0.4f);
2002 grand_child->SetForceRenderSurface(true);
2003
[email protected]989386c2013-07-18 21:37:232004 {
2005 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532006 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2007 parent.get(), parent->bounds(), &render_surface_layer_list);
2008 inputs.can_adjust_raster_scales = true;
2009 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322010
[email protected]989386c2013-07-18 21:37:232011 // Without an animation, we should cull child and grand_child from the
2012 // render_surface_layer_list.
2013 ASSERT_EQ(1U, render_surface_layer_list.size());
2014 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
2015 }
[email protected]fb661802013-03-25 01:59:322016
2017 // Now put an animating transform on child.
2018 AddAnimatedTransformToController(
2019 child->layer_animation_controller(), 10.0, 30, 0);
2020
[email protected]989386c2013-07-18 21:37:232021 {
2022 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532023 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2024 parent.get(), parent->bounds(), &render_surface_layer_list);
2025 inputs.can_adjust_raster_scales = true;
2026 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322027
[email protected]989386c2013-07-18 21:37:232028 // With an animating transform, we should keep child and grand_child in the
2029 // render_surface_layer_list.
2030 ASSERT_EQ(3U, render_surface_layer_list.size());
2031 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
2032 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
2033 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
2034 }
[email protected]fb661802013-03-25 01:59:322035}
2036
[email protected]989386c2013-07-18 21:37:232037TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:322038 // Layer's IsClipped() property is set to true when:
2039 // - the layer clips its subtree, e.g. masks to bounds,
2040 // - the layer is clipped by an ancestor that contributes to the same
2041 // render target,
2042 // - a surface is clipped by an ancestor that contributes to the same
2043 // render target.
2044 //
2045 // In particular, for a layer that owns a render surface:
2046 // - the render surface inherits any clip from ancestors, and does NOT
2047 // pass that clipped status to the layer itself.
2048 // - but if the layer itself masks to bounds, it is considered clipped
2049 // and propagates the clip to the subtree.
2050
2051 const gfx::Transform identity_matrix;
2052 scoped_refptr<Layer> root = Layer::Create();
2053 scoped_refptr<Layer> parent = Layer::Create();
2054 scoped_refptr<Layer> child1 = Layer::Create();
2055 scoped_refptr<Layer> child2 = Layer::Create();
2056 scoped_refptr<Layer> grand_child = Layer::Create();
2057 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2058 make_scoped_refptr(new LayerWithForcedDrawsContent());
2059 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2060 make_scoped_refptr(new LayerWithForcedDrawsContent());
2061 root->AddChild(parent);
2062 parent->AddChild(child1);
2063 parent->AddChild(child2);
2064 child1->AddChild(grand_child);
2065 child2->AddChild(leaf_node2);
2066 grand_child->AddChild(leaf_node1);
2067
[email protected]d600df7d2013-08-03 02:34:282068 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2069 host->SetRootLayer(root);
2070
[email protected]fb661802013-03-25 01:59:322071 child2->SetForceRenderSurface(true);
2072
2073 SetLayerPropertiesForTesting(root.get(),
2074 identity_matrix,
2075 identity_matrix,
2076 gfx::PointF(),
2077 gfx::PointF(),
2078 gfx::Size(100, 100),
2079 false);
2080 SetLayerPropertiesForTesting(parent.get(),
2081 identity_matrix,
2082 identity_matrix,
2083 gfx::PointF(),
2084 gfx::PointF(),
2085 gfx::Size(100, 100),
2086 false);
2087 SetLayerPropertiesForTesting(child1.get(),
2088 identity_matrix,
2089 identity_matrix,
2090 gfx::PointF(),
2091 gfx::PointF(),
2092 gfx::Size(100, 100),
2093 false);
2094 SetLayerPropertiesForTesting(child2.get(),
2095 identity_matrix,
2096 identity_matrix,
2097 gfx::PointF(),
2098 gfx::PointF(),
2099 gfx::Size(100, 100),
2100 false);
2101 SetLayerPropertiesForTesting(grand_child.get(),
2102 identity_matrix,
2103 identity_matrix,
2104 gfx::PointF(),
2105 gfx::PointF(),
2106 gfx::Size(100, 100),
2107 false);
2108 SetLayerPropertiesForTesting(leaf_node1.get(),
2109 identity_matrix,
2110 identity_matrix,
2111 gfx::PointF(),
2112 gfx::PointF(),
2113 gfx::Size(100, 100),
2114 false);
2115 SetLayerPropertiesForTesting(leaf_node2.get(),
2116 identity_matrix,
2117 identity_matrix,
2118 gfx::PointF(),
2119 gfx::PointF(),
2120 gfx::Size(100, 100),
2121 false);
2122
[email protected]989386c2013-07-18 21:37:232123 // Case 1: nothing is clipped except the root render surface.
2124 {
2125 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532126 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2127 root.get(), parent->bounds(), &render_surface_layer_list);
2128 inputs.can_adjust_raster_scales = true;
2129 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322130
[email protected]989386c2013-07-18 21:37:232131 ASSERT_TRUE(root->render_surface());
2132 ASSERT_TRUE(child2->render_surface());
2133
2134 EXPECT_FALSE(root->is_clipped());
2135 EXPECT_TRUE(root->render_surface()->is_clipped());
2136 EXPECT_FALSE(parent->is_clipped());
2137 EXPECT_FALSE(child1->is_clipped());
2138 EXPECT_FALSE(child2->is_clipped());
2139 EXPECT_FALSE(child2->render_surface()->is_clipped());
2140 EXPECT_FALSE(grand_child->is_clipped());
2141 EXPECT_FALSE(leaf_node1->is_clipped());
2142 EXPECT_FALSE(leaf_node2->is_clipped());
2143 }
[email protected]fb661802013-03-25 01:59:322144
2145 // Case 2: parent masksToBounds, so the parent, child1, and child2's
2146 // surface are clipped. But layers that contribute to child2's surface are
2147 // not clipped explicitly because child2's surface already accounts for
2148 // that clip.
[email protected]989386c2013-07-18 21:37:232149 {
2150 RenderSurfaceLayerList render_surface_layer_list;
2151 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:532152 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2153 root.get(), parent->bounds(), &render_surface_layer_list);
2154 inputs.can_adjust_raster_scales = true;
2155 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322156
[email protected]989386c2013-07-18 21:37:232157 ASSERT_TRUE(root->render_surface());
2158 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:322159
[email protected]989386c2013-07-18 21:37:232160 EXPECT_FALSE(root->is_clipped());
2161 EXPECT_TRUE(root->render_surface()->is_clipped());
2162 EXPECT_TRUE(parent->is_clipped());
2163 EXPECT_TRUE(child1->is_clipped());
2164 EXPECT_FALSE(child2->is_clipped());
2165 EXPECT_TRUE(child2->render_surface()->is_clipped());
2166 EXPECT_TRUE(grand_child->is_clipped());
2167 EXPECT_TRUE(leaf_node1->is_clipped());
2168 EXPECT_FALSE(leaf_node2->is_clipped());
2169 }
[email protected]fb661802013-03-25 01:59:322170
2171 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
2172 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:232173 {
2174 RenderSurfaceLayerList render_surface_layer_list;
2175 parent->SetMasksToBounds(false);
2176 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:532177 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2178 root.get(), parent->bounds(), &render_surface_layer_list);
2179 inputs.can_adjust_raster_scales = true;
2180 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322181
[email protected]989386c2013-07-18 21:37:232182 ASSERT_TRUE(root->render_surface());
2183 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:322184
[email protected]989386c2013-07-18 21:37:232185 EXPECT_FALSE(root->is_clipped());
2186 EXPECT_TRUE(root->render_surface()->is_clipped());
2187 EXPECT_FALSE(parent->is_clipped());
2188 EXPECT_FALSE(child1->is_clipped());
2189 EXPECT_TRUE(child2->is_clipped());
2190 EXPECT_FALSE(child2->render_surface()->is_clipped());
2191 EXPECT_FALSE(grand_child->is_clipped());
2192 EXPECT_FALSE(leaf_node1->is_clipped());
2193 EXPECT_TRUE(leaf_node2->is_clipped());
2194 }
[email protected]fb661802013-03-25 01:59:322195}
2196
[email protected]fd9a3b6d2013-08-03 00:46:172197TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322198 // Verify that layers get the appropriate DrawableContentRect when their
2199 // parent masksToBounds is true.
2200 //
2201 // grand_child1 - completely inside the region; DrawableContentRect should
2202 // be the layer rect expressed in target space.
2203 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
2204 // will be the intersection of layer bounds and the mask region.
2205 // grand_child3 - partially clipped and masksToBounds; the
2206 // DrawableContentRect will still be the intersection of layer bounds and
2207 // the mask region.
2208 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2209 // be empty.
2210 //
2211
2212 const gfx::Transform identity_matrix;
2213 scoped_refptr<Layer> parent = Layer::Create();
2214 scoped_refptr<Layer> child = Layer::Create();
2215 scoped_refptr<Layer> grand_child1 = Layer::Create();
2216 scoped_refptr<Layer> grand_child2 = Layer::Create();
2217 scoped_refptr<Layer> grand_child3 = Layer::Create();
2218 scoped_refptr<Layer> grand_child4 = Layer::Create();
2219
2220 parent->AddChild(child);
2221 child->AddChild(grand_child1);
2222 child->AddChild(grand_child2);
2223 child->AddChild(grand_child3);
2224 child->AddChild(grand_child4);
2225
[email protected]d600df7d2013-08-03 02:34:282226 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2227 host->SetRootLayer(parent);
2228
[email protected]fb661802013-03-25 01:59:322229 SetLayerPropertiesForTesting(parent.get(),
2230 identity_matrix,
2231 identity_matrix,
2232 gfx::PointF(),
2233 gfx::PointF(),
2234 gfx::Size(500, 500),
2235 false);
2236 SetLayerPropertiesForTesting(child.get(),
2237 identity_matrix,
2238 identity_matrix,
2239 gfx::PointF(),
2240 gfx::PointF(),
2241 gfx::Size(20, 20),
2242 false);
2243 SetLayerPropertiesForTesting(grand_child1.get(),
2244 identity_matrix,
2245 identity_matrix,
2246 gfx::PointF(),
2247 gfx::PointF(5.f, 5.f),
2248 gfx::Size(10, 10),
2249 false);
2250 SetLayerPropertiesForTesting(grand_child2.get(),
2251 identity_matrix,
2252 identity_matrix,
2253 gfx::PointF(),
2254 gfx::PointF(15.f, 15.f),
2255 gfx::Size(10, 10),
2256 false);
2257 SetLayerPropertiesForTesting(grand_child3.get(),
2258 identity_matrix,
2259 identity_matrix,
2260 gfx::PointF(),
2261 gfx::PointF(15.f, 15.f),
2262 gfx::Size(10, 10),
2263 false);
2264 SetLayerPropertiesForTesting(grand_child4.get(),
2265 identity_matrix,
2266 identity_matrix,
2267 gfx::PointF(),
2268 gfx::PointF(45.f, 45.f),
2269 gfx::Size(10, 10),
2270 false);
2271
2272 child->SetMasksToBounds(true);
2273 grand_child3->SetMasksToBounds(true);
2274
2275 // Force everyone to be a render surface.
2276 child->SetOpacity(0.4f);
2277 grand_child1->SetOpacity(0.5f);
2278 grand_child2->SetOpacity(0.5f);
2279 grand_child3->SetOpacity(0.5f);
2280 grand_child4->SetOpacity(0.5f);
2281
[email protected]989386c2013-07-18 21:37:232282 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532283 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2284 parent.get(), parent->bounds(), &render_surface_layer_list);
2285 inputs.can_adjust_raster_scales = true;
2286 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322287
[email protected]2c7c6702013-03-26 03:14:052288 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
[email protected]fb661802013-03-25 01:59:322289 grand_child1->drawable_content_rect());
[email protected]2c7c6702013-03-26 03:14:052290 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
[email protected]fb661802013-03-25 01:59:322291 grand_child3->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());
2294 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2295}
2296
[email protected]989386c2013-07-18 21:37:232297TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322298 // Verify that render surfaces (and their layers) get the appropriate
2299 // clip rects when their parent masksToBounds is true.
2300 //
2301 // Layers that own render surfaces (at least for now) do not inherit any
2302 // clipping; instead the surface will enforce the clip for the entire subtree.
2303 // They may still have a clip rect of their own layer bounds, however, if
2304 // masksToBounds was true.
2305 const gfx::Transform identity_matrix;
2306 scoped_refptr<Layer> parent = Layer::Create();
2307 scoped_refptr<Layer> child = Layer::Create();
2308 scoped_refptr<Layer> grand_child1 = Layer::Create();
2309 scoped_refptr<Layer> grand_child2 = Layer::Create();
2310 scoped_refptr<Layer> grand_child3 = Layer::Create();
2311 scoped_refptr<Layer> grand_child4 = Layer::Create();
2312 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2313 make_scoped_refptr(new LayerWithForcedDrawsContent());
2314 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2315 make_scoped_refptr(new LayerWithForcedDrawsContent());
2316 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
2317 make_scoped_refptr(new LayerWithForcedDrawsContent());
2318 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
2319 make_scoped_refptr(new LayerWithForcedDrawsContent());
2320
2321 parent->AddChild(child);
2322 child->AddChild(grand_child1);
2323 child->AddChild(grand_child2);
2324 child->AddChild(grand_child3);
2325 child->AddChild(grand_child4);
2326
[email protected]d600df7d2013-08-03 02:34:282327 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2328 host->SetRootLayer(parent);
2329
[email protected]fb661802013-03-25 01:59:322330 // the leaf nodes ensure that these grand_children become render surfaces for
2331 // this test.
2332 grand_child1->AddChild(leaf_node1);
2333 grand_child2->AddChild(leaf_node2);
2334 grand_child3->AddChild(leaf_node3);
2335 grand_child4->AddChild(leaf_node4);
2336
2337 SetLayerPropertiesForTesting(parent.get(),
2338 identity_matrix,
2339 identity_matrix,
2340 gfx::PointF(),
2341 gfx::PointF(),
2342 gfx::Size(500, 500),
2343 false);
2344 SetLayerPropertiesForTesting(child.get(),
2345 identity_matrix,
2346 identity_matrix,
2347 gfx::PointF(),
2348 gfx::PointF(),
2349 gfx::Size(20, 20),
2350 false);
2351 SetLayerPropertiesForTesting(grand_child1.get(),
2352 identity_matrix,
2353 identity_matrix,
2354 gfx::PointF(),
2355 gfx::PointF(5.f, 5.f),
2356 gfx::Size(10, 10),
2357 false);
2358 SetLayerPropertiesForTesting(grand_child2.get(),
2359 identity_matrix,
2360 identity_matrix,
2361 gfx::PointF(),
2362 gfx::PointF(15.f, 15.f),
2363 gfx::Size(10, 10),
2364 false);
2365 SetLayerPropertiesForTesting(grand_child3.get(),
2366 identity_matrix,
2367 identity_matrix,
2368 gfx::PointF(),
2369 gfx::PointF(15.f, 15.f),
2370 gfx::Size(10, 10),
2371 false);
2372 SetLayerPropertiesForTesting(grand_child4.get(),
2373 identity_matrix,
2374 identity_matrix,
2375 gfx::PointF(),
2376 gfx::PointF(45.f, 45.f),
2377 gfx::Size(10, 10),
2378 false);
2379 SetLayerPropertiesForTesting(leaf_node1.get(),
2380 identity_matrix,
2381 identity_matrix,
2382 gfx::PointF(),
2383 gfx::PointF(),
2384 gfx::Size(10, 10),
2385 false);
2386 SetLayerPropertiesForTesting(leaf_node2.get(),
2387 identity_matrix,
2388 identity_matrix,
2389 gfx::PointF(),
2390 gfx::PointF(),
2391 gfx::Size(10, 10),
2392 false);
2393 SetLayerPropertiesForTesting(leaf_node3.get(),
2394 identity_matrix,
2395 identity_matrix,
2396 gfx::PointF(),
2397 gfx::PointF(),
2398 gfx::Size(10, 10),
2399 false);
2400 SetLayerPropertiesForTesting(leaf_node4.get(),
2401 identity_matrix,
2402 identity_matrix,
2403 gfx::PointF(),
2404 gfx::PointF(),
2405 gfx::Size(10, 10),
2406 false);
2407
2408 child->SetMasksToBounds(true);
2409 grand_child3->SetMasksToBounds(true);
2410 grand_child4->SetMasksToBounds(true);
2411
2412 // Force everyone to be a render surface.
2413 child->SetOpacity(0.4f);
2414 child->SetForceRenderSurface(true);
2415 grand_child1->SetOpacity(0.5f);
2416 grand_child1->SetForceRenderSurface(true);
2417 grand_child2->SetOpacity(0.5f);
2418 grand_child2->SetForceRenderSurface(true);
2419 grand_child3->SetOpacity(0.5f);
2420 grand_child3->SetForceRenderSurface(true);
2421 grand_child4->SetOpacity(0.5f);
2422 grand_child4->SetForceRenderSurface(true);
2423
[email protected]989386c2013-07-18 21:37:232424 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532425 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2426 parent.get(), parent->bounds(), &render_surface_layer_list);
2427 inputs.can_adjust_raster_scales = true;
2428 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322429 ASSERT_TRUE(grand_child1->render_surface());
2430 ASSERT_TRUE(grand_child2->render_surface());
2431 ASSERT_TRUE(grand_child3->render_surface());
2432 // Because grand_child4 is entirely clipped, it is expected to not have a
2433 // render surface.
2434 EXPECT_FALSE(grand_child4->render_surface());
2435
2436 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2437 // masksToBounds.
[email protected]2c7c6702013-03-26 03:14:052438 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
[email protected]fb661802013-03-25 01:59:322439 grand_child1->render_surface()->clip_rect());
[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_child2->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_child3->render_surface()->clip_rect());
2444}
2445
[email protected]989386c2013-07-18 21:37:232446TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322447 scoped_refptr<Layer> parent = Layer::Create();
2448 scoped_refptr<Layer> render_surface1 = Layer::Create();
2449 scoped_refptr<Layer> render_surface2 = Layer::Create();
2450 scoped_refptr<Layer> child_of_root = Layer::Create();
2451 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2452 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2453 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2454 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2455 make_scoped_refptr(new LayerWithForcedDrawsContent());
2456 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2457 make_scoped_refptr(new LayerWithForcedDrawsContent());
2458 parent->AddChild(render_surface1);
2459 parent->AddChild(child_of_root);
2460 render_surface1->AddChild(child_of_rs1);
2461 render_surface1->AddChild(render_surface2);
2462 render_surface2->AddChild(child_of_rs2);
2463 child_of_root->AddChild(grand_child_of_root);
2464 child_of_rs1->AddChild(grand_child_of_rs1);
2465 child_of_rs2->AddChild(grand_child_of_rs2);
2466
[email protected]d600df7d2013-08-03 02:34:282467 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2468 host->SetRootLayer(parent);
2469
[email protected]fb661802013-03-25 01:59:322470 // Make our render surfaces.
2471 render_surface1->SetForceRenderSurface(true);
2472 render_surface2->SetForceRenderSurface(true);
2473
2474 gfx::Transform layer_transform;
2475 layer_transform.Translate(1.0, 1.0);
2476 gfx::Transform sublayer_transform;
2477 sublayer_transform.Scale3d(10.0, 1.0, 1.0);
2478
2479 SetLayerPropertiesForTesting(parent.get(),
2480 layer_transform,
2481 sublayer_transform,
2482 gfx::PointF(0.25f, 0.f),
2483 gfx::PointF(2.5f, 0.f),
2484 gfx::Size(10, 10),
2485 false);
2486 SetLayerPropertiesForTesting(render_surface1.get(),
2487 layer_transform,
2488 sublayer_transform,
2489 gfx::PointF(0.25f, 0.f),
2490 gfx::PointF(2.5f, 0.f),
2491 gfx::Size(10, 10),
2492 false);
2493 SetLayerPropertiesForTesting(render_surface2.get(),
2494 layer_transform,
2495 sublayer_transform,
2496 gfx::PointF(0.25f, 0.f),
2497 gfx::PointF(2.5f, 0.f),
2498 gfx::Size(10, 10),
2499 false);
2500 SetLayerPropertiesForTesting(child_of_root.get(),
2501 layer_transform,
2502 sublayer_transform,
2503 gfx::PointF(0.25f, 0.f),
2504 gfx::PointF(2.5f, 0.f),
2505 gfx::Size(10, 10),
2506 false);
2507 SetLayerPropertiesForTesting(child_of_rs1.get(),
2508 layer_transform,
2509 sublayer_transform,
2510 gfx::PointF(0.25f, 0.f),
2511 gfx::PointF(2.5f, 0.f),
2512 gfx::Size(10, 10),
2513 false);
2514 SetLayerPropertiesForTesting(child_of_rs2.get(),
2515 layer_transform,
2516 sublayer_transform,
2517 gfx::PointF(0.25f, 0.f),
2518 gfx::PointF(2.5f, 0.f),
2519 gfx::Size(10, 10),
2520 false);
2521 SetLayerPropertiesForTesting(grand_child_of_root.get(),
2522 layer_transform,
2523 sublayer_transform,
2524 gfx::PointF(0.25f, 0.f),
2525 gfx::PointF(2.5f, 0.f),
2526 gfx::Size(10, 10),
2527 false);
2528 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
2529 layer_transform,
2530 sublayer_transform,
2531 gfx::PointF(0.25f, 0.f),
2532 gfx::PointF(2.5f, 0.f),
2533 gfx::Size(10, 10),
2534 false);
2535 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
2536 layer_transform,
2537 sublayer_transform,
2538 gfx::PointF(0.25f, 0.f),
2539 gfx::PointF(2.5f, 0.f),
2540 gfx::Size(10, 10),
2541 false);
2542
2543 // Put an animated opacity on the render surface.
2544 AddOpacityTransitionToController(
2545 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2546
2547 // Also put an animated opacity on a layer without descendants.
2548 AddOpacityTransitionToController(
2549 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2550
2551 // Put a transform animation on the render surface.
2552 AddAnimatedTransformToController(
2553 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2554
2555 // Also put transform animations on grand_child_of_root, and
2556 // grand_child_of_rs2
2557 AddAnimatedTransformToController(
2558 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2559 AddAnimatedTransformToController(
2560 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2561
2562 ExecuteCalculateDrawProperties(parent.get());
2563
2564 // Only layers that are associated with render surfaces should have an actual
2565 // RenderSurface() value.
2566 ASSERT_TRUE(parent->render_surface());
2567 ASSERT_FALSE(child_of_root->render_surface());
2568 ASSERT_FALSE(grand_child_of_root->render_surface());
2569
2570 ASSERT_TRUE(render_surface1->render_surface());
2571 ASSERT_FALSE(child_of_rs1->render_surface());
2572 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2573
2574 ASSERT_TRUE(render_surface2->render_surface());
2575 ASSERT_FALSE(child_of_rs2->render_surface());
2576 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2577
2578 // Verify all render target accessors
2579 EXPECT_EQ(parent, parent->render_target());
2580 EXPECT_EQ(parent, child_of_root->render_target());
2581 EXPECT_EQ(parent, grand_child_of_root->render_target());
2582
2583 EXPECT_EQ(render_surface1, render_surface1->render_target());
2584 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2585 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
2586
2587 EXPECT_EQ(render_surface2, render_surface2->render_target());
2588 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2589 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
2590
2591 // Verify draw_opacity_is_animating values
2592 EXPECT_FALSE(parent->draw_opacity_is_animating());
2593 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2594 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2595 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2596 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2597 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2598 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2599 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2600 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2601 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2602 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2603
2604 // Verify draw_transform_is_animating values
2605 EXPECT_FALSE(parent->draw_transform_is_animating());
2606 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2607 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2608 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2609 EXPECT_FALSE(render_surface1->render_surface()
2610 ->target_surface_transforms_are_animating());
2611 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2612 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2613 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2614 EXPECT_TRUE(render_surface2->render_surface()
2615 ->target_surface_transforms_are_animating());
2616 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2617 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2618
2619 // Verify screen_space_transform_is_animating values
2620 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2621 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2622 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2623 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2624 EXPECT_FALSE(render_surface1->render_surface()
2625 ->screen_space_transforms_are_animating());
2626 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2627 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2628 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2629 EXPECT_TRUE(render_surface2->render_surface()
2630 ->screen_space_transforms_are_animating());
2631 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2632 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2633
2634 // Sanity check. If these fail there is probably a bug in the test itself.
2635 // It is expected that we correctly set up transforms so that the y-component
2636 // of the screen-space transform encodes the "depth" of the layer in the tree.
2637 EXPECT_FLOAT_EQ(1.0,
2638 parent->screen_space_transform().matrix().getDouble(1, 3));
2639 EXPECT_FLOAT_EQ(
2640 2.0, child_of_root->screen_space_transform().matrix().getDouble(1, 3));
2641 EXPECT_FLOAT_EQ(
2642 3.0,
2643 grand_child_of_root->screen_space_transform().matrix().getDouble(1, 3));
2644
2645 EXPECT_FLOAT_EQ(
2646 2.0, render_surface1->screen_space_transform().matrix().getDouble(1, 3));
2647 EXPECT_FLOAT_EQ(
2648 3.0, child_of_rs1->screen_space_transform().matrix().getDouble(1, 3));
2649 EXPECT_FLOAT_EQ(
2650 4.0,
2651 grand_child_of_rs1->screen_space_transform().matrix().getDouble(1, 3));
2652
2653 EXPECT_FLOAT_EQ(
2654 3.0, render_surface2->screen_space_transform().matrix().getDouble(1, 3));
2655 EXPECT_FLOAT_EQ(
2656 4.0, child_of_rs2->screen_space_transform().matrix().getDouble(1, 3));
2657 EXPECT_FLOAT_EQ(
2658 5.0,
2659 grand_child_of_rs2->screen_space_transform().matrix().getDouble(1, 3));
2660}
2661
[email protected]989386c2013-07-18 21:37:232662TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322663 // Test the calculateVisibleRect() function works correctly for identity
2664 // transforms.
2665
[email protected]2c7c6702013-03-26 03:14:052666 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322667 gfx::Transform layer_to_surface_transform;
2668
2669 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232670 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052671 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322672 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2673 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2674 EXPECT_RECT_EQ(expected, actual);
2675
2676 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052677 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322678 actual = LayerTreeHostCommon::CalculateVisibleRect(
2679 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2680 EXPECT_TRUE(actual.IsEmpty());
2681
2682 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052683 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2684 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322685 actual = LayerTreeHostCommon::CalculateVisibleRect(
2686 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2687 EXPECT_RECT_EQ(expected, actual);
2688}
2689
[email protected]989386c2013-07-18 21:37:232690TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322691 // Test the calculateVisibleRect() function works correctly for scaling
2692 // transforms.
2693
[email protected]2c7c6702013-03-26 03:14:052694 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2695 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322696 gfx::Transform layer_to_surface_transform;
2697
2698 // Case 1: Layer is contained within the surface.
2699 layer_to_surface_transform.MakeIdentity();
2700 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052701 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322702 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2703 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2704 EXPECT_RECT_EQ(expected, actual);
2705
2706 // Case 2: Layer is outside the surface rect.
2707 layer_to_surface_transform.MakeIdentity();
2708 layer_to_surface_transform.Translate(120.0, 120.0);
2709 actual = LayerTreeHostCommon::CalculateVisibleRect(
2710 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2711 EXPECT_TRUE(actual.IsEmpty());
2712
2713 // Case 3: Layer is partially overlapping the surface rect.
2714 layer_to_surface_transform.MakeIdentity();
2715 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052716 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322717 actual = LayerTreeHostCommon::CalculateVisibleRect(
2718 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2719 EXPECT_RECT_EQ(expected, actual);
2720}
2721
[email protected]989386c2013-07-18 21:37:232722TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322723 // Test the calculateVisibleRect() function works correctly for rotations
2724 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2725 // should return the g in the layer's space.
2726
[email protected]2c7c6702013-03-26 03:14:052727 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2728 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322729 gfx::Transform layer_to_surface_transform;
2730
2731 // Case 1: Layer is contained within the surface.
2732 layer_to_surface_transform.MakeIdentity();
2733 layer_to_surface_transform.Translate(50.0, 50.0);
2734 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052735 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322736 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2737 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2738 EXPECT_RECT_EQ(expected, actual);
2739
2740 // Case 2: Layer is outside the surface rect.
2741 layer_to_surface_transform.MakeIdentity();
2742 layer_to_surface_transform.Translate(-50.0, 0.0);
2743 layer_to_surface_transform.Rotate(45.0);
2744 actual = LayerTreeHostCommon::CalculateVisibleRect(
2745 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2746 EXPECT_TRUE(actual.IsEmpty());
2747
2748 // Case 3: The layer is rotated about its top-left corner. In surface space,
2749 // the layer is oriented diagonally, with the left half outside of the render
2750 // surface. In this case, the g should still be the entire layer
2751 // (remember the g is computed in layer space); both the top-left
2752 // and bottom-right corners of the layer are still visible.
2753 layer_to_surface_transform.MakeIdentity();
2754 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052755 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322756 actual = LayerTreeHostCommon::CalculateVisibleRect(
2757 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2758 EXPECT_RECT_EQ(expected, actual);
2759
2760 // Case 4: The layer is rotated about its top-left corner, and translated
2761 // upwards. In surface space, the layer is oriented diagonally, with only the
2762 // top corner of the surface overlapping the layer. In layer space, the render
2763 // surface overlaps the right side of the layer. The g should be
2764 // the layer's right half.
2765 layer_to_surface_transform.MakeIdentity();
2766 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2767 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052768 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322769 actual = LayerTreeHostCommon::CalculateVisibleRect(
2770 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2771 EXPECT_RECT_EQ(expected, actual);
2772}
2773
[email protected]989386c2013-07-18 21:37:232774TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322775 // Test that the calculateVisibleRect() function works correctly for 3d
2776 // transforms.
2777
[email protected]2c7c6702013-03-26 03:14:052778 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2779 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322780 gfx::Transform layer_to_surface_transform;
2781
2782 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2783 // degrees, should be fully contained in the render surface.
2784 layer_to_surface_transform.MakeIdentity();
2785 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052786 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322787 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2788 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2789 EXPECT_RECT_EQ(expected, actual);
2790
2791 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2792 // degrees, but shifted to the side so only the right-half the layer would be
2793 // visible on the surface.
2794 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2795 double half_width_of_rotated_layer = (100.0 / sqrt(2.0)) * 0.5;
2796 layer_to_surface_transform.MakeIdentity();
2797 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232798 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2799 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052800 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322801 actual = LayerTreeHostCommon::CalculateVisibleRect(
2802 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2803 EXPECT_RECT_EQ(expected, actual);
2804}
2805
[email protected]989386c2013-07-18 21:37:232806TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322807 // Test the calculateVisibleRect() function works correctly when the layer has
2808 // a perspective projection onto the target surface.
2809
[email protected]2c7c6702013-03-26 03:14:052810 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2811 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322812 gfx::Transform layer_to_surface_transform;
2813
2814 // Case 1: Even though the layer is twice as large as the surface, due to
2815 // perspective foreshortening, the layer will fit fully in the surface when
2816 // its translated more than the perspective amount.
2817 layer_to_surface_transform.MakeIdentity();
2818
2819 // The following sequence of transforms applies the perspective about the
2820 // center of the surface.
2821 layer_to_surface_transform.Translate(50.0, 50.0);
2822 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2823 layer_to_surface_transform.Translate(-50.0, -50.0);
2824
2825 // This translate places the layer in front of the surface's projection plane.
2826 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2827
[email protected]2c7c6702013-03-26 03:14:052828 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322829 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2830 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2831 EXPECT_RECT_EQ(expected, actual);
2832
2833 // Case 2: same projection as before, except that the layer is also translated
2834 // to the side, so that only the right half of the layer should be visible.
2835 //
2836 // Explanation of expected result: The perspective ratio is (z distance
2837 // between layer and camera origin) / (z distance between projection plane and
2838 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2839 // move a layer by translating -50 units in projected surface units (so that
2840 // only half of it is visible), then we would need to translate by (-36 / 9) *
2841 // -50 == -200 in the layer's units.
2842 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232843 expected = gfx::Rect(gfx::Point(50, -50),
2844 gfx::Size(100, 200)); // The right half of the layer's
2845 // bounding rect.
[email protected]fb661802013-03-25 01:59:322846 actual = LayerTreeHostCommon::CalculateVisibleRect(
2847 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2848 EXPECT_RECT_EQ(expected, actual);
2849}
2850
[email protected]989386c2013-07-18 21:37:232851TEST_F(LayerTreeHostCommonTest,
2852 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322853 // There is currently no explicit concept of an orthographic projection plane
2854 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2855 // are technically behind the surface in an orthographic world should not be
2856 // clipped when they are flattened to the surface.
2857
[email protected]2c7c6702013-03-26 03:14:052858 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2859 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322860 gfx::Transform layer_to_surface_transform;
2861
2862 // This sequence of transforms effectively rotates the layer about the y-axis
2863 // at the center of the layer.
2864 layer_to_surface_transform.MakeIdentity();
2865 layer_to_surface_transform.Translate(50.0, 0.0);
2866 layer_to_surface_transform.RotateAboutYAxis(45.0);
2867 layer_to_surface_transform.Translate(-50.0, 0.0);
2868
[email protected]2c7c6702013-03-26 03:14:052869 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322870 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2871 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2872 EXPECT_RECT_EQ(expected, actual);
2873}
2874
[email protected]989386c2013-07-18 21:37:232875TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322876 // Test the calculateVisibleRect() function works correctly when projecting a
2877 // surface onto a layer, but the layer is partially behind the camera (not
2878 // just behind the projection plane). In this case, the cartesian coordinates
2879 // may seem to be valid, but actually they are not. The visible rect needs to
2880 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2881 // converting to cartesian coordinates.
2882
[email protected]2c7c6702013-03-26 03:14:052883 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232884 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322885 gfx::Transform layer_to_surface_transform;
2886
2887 // The layer is positioned so that the right half of the layer should be in
2888 // front of the camera, while the other half is behind the surface's
2889 // projection plane. The following sequence of transforms applies the
2890 // perspective and rotation about the center of the layer.
2891 layer_to_surface_transform.MakeIdentity();
2892 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2893 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2894 layer_to_surface_transform.RotateAboutYAxis(45.0);
2895
2896 // Sanity check that this transform does indeed cause w < 0 when applying the
2897 // transform, otherwise this code is not testing the intended scenario.
2898 bool clipped;
2899 MathUtil::MapQuad(layer_to_surface_transform,
2900 gfx::QuadF(gfx::RectF(layer_content_rect)),
2901 &clipped);
2902 ASSERT_TRUE(clipped);
2903
2904 int expected_x_position = 0;
2905 int expected_width = 10;
2906 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2907 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2908 EXPECT_EQ(expected_x_position, actual.x());
2909 EXPECT_EQ(expected_width, actual.width());
2910}
2911
[email protected]989386c2013-07-18 21:37:232912TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322913 // To determine visible rect in layer space, there needs to be an
2914 // un-projection from surface space to layer space. When the original
2915 // transform was a perspective projection that was clipped, it returns a rect
2916 // that encloses the clipped bounds. Un-projecting this new rect may require
2917 // clipping again.
2918
2919 // This sequence of transforms causes one corner of the layer to protrude
2920 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232921 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2922 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322923 gfx::Transform layer_to_surface_transform;
2924 layer_to_surface_transform.MakeIdentity();
2925 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2926 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2927 layer_to_surface_transform.RotateAboutYAxis(45.0);
2928 layer_to_surface_transform.RotateAboutXAxis(80.0);
2929
2930 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2931 // code is not testing the intended scenario.
2932 bool clipped;
2933 gfx::RectF clipped_rect =
2934 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2935 MathUtil::ProjectQuad(
2936 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2937 ASSERT_TRUE(clipped);
2938
2939 // Only the corner of the layer is not visible on the surface because of being
2940 // clipped. But, the net result of rounding visible region to an axis-aligned
2941 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052942 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322943 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2944 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2945 EXPECT_RECT_EQ(expected, actual);
2946}
2947
[email protected]989386c2013-07-18 21:37:232948TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322949 scoped_refptr<Layer> root = Layer::Create();
2950 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2951 make_scoped_refptr(new LayerWithForcedDrawsContent());
2952 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2953 make_scoped_refptr(new LayerWithForcedDrawsContent());
2954 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2955 make_scoped_refptr(new LayerWithForcedDrawsContent());
2956 root->AddChild(child1);
2957 root->AddChild(child2);
2958 root->AddChild(child3);
2959
[email protected]d600df7d2013-08-03 02:34:282960 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2961 host->SetRootLayer(root);
2962
[email protected]fb661802013-03-25 01:59:322963 gfx::Transform identity_matrix;
2964 SetLayerPropertiesForTesting(root.get(),
2965 identity_matrix,
2966 identity_matrix,
2967 gfx::PointF(),
2968 gfx::PointF(),
2969 gfx::Size(100, 100),
2970 false);
2971 SetLayerPropertiesForTesting(child1.get(),
2972 identity_matrix,
2973 identity_matrix,
2974 gfx::PointF(),
2975 gfx::PointF(),
2976 gfx::Size(50, 50),
2977 false);
2978 SetLayerPropertiesForTesting(child2.get(),
2979 identity_matrix,
2980 identity_matrix,
2981 gfx::PointF(),
2982 gfx::PointF(75.f, 75.f),
2983 gfx::Size(50, 50),
2984 false);
2985 SetLayerPropertiesForTesting(child3.get(),
2986 identity_matrix,
2987 identity_matrix,
2988 gfx::PointF(),
2989 gfx::PointF(125.f, 125.f),
2990 gfx::Size(50, 50),
2991 false);
2992
2993 ExecuteCalculateDrawProperties(root.get());
2994
2995 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2996 root->render_surface()->DrawableContentRect());
2997 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2998
2999 // Layers that do not draw content should have empty visible_content_rects.
3000 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3001
3002 // layer visible_content_rects are clipped by their target surface.
3003 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3004 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
3005 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3006
3007 // layer drawable_content_rects are not clipped.
3008 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
3009 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3010 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3011}
3012
[email protected]989386c2013-07-18 21:37:233013TEST_F(LayerTreeHostCommonTest,
3014 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:323015 scoped_refptr<Layer> root = Layer::Create();
3016 scoped_refptr<Layer> child = Layer::Create();
3017 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
3018 make_scoped_refptr(new LayerWithForcedDrawsContent());
3019 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
3020 make_scoped_refptr(new LayerWithForcedDrawsContent());
3021 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
3022 make_scoped_refptr(new LayerWithForcedDrawsContent());
3023 root->AddChild(child);
3024 child->AddChild(grand_child1);
3025 child->AddChild(grand_child2);
3026 child->AddChild(grand_child3);
3027
[email protected]d600df7d2013-08-03 02:34:283028 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3029 host->SetRootLayer(root);
3030
[email protected]fb661802013-03-25 01:59:323031 gfx::Transform identity_matrix;
3032 SetLayerPropertiesForTesting(root.get(),
3033 identity_matrix,
3034 identity_matrix,
3035 gfx::PointF(),
3036 gfx::PointF(),
3037 gfx::Size(100, 100),
3038 false);
3039 SetLayerPropertiesForTesting(child.get(),
3040 identity_matrix,
3041 identity_matrix,
3042 gfx::PointF(),
3043 gfx::PointF(),
3044 gfx::Size(100, 100),
3045 false);
3046 SetLayerPropertiesForTesting(grand_child1.get(),
3047 identity_matrix,
3048 identity_matrix,
3049 gfx::PointF(),
3050 gfx::PointF(5.f, 5.f),
3051 gfx::Size(50, 50),
3052 false);
3053 SetLayerPropertiesForTesting(grand_child2.get(),
3054 identity_matrix,
3055 identity_matrix,
3056 gfx::PointF(),
3057 gfx::PointF(75.f, 75.f),
3058 gfx::Size(50, 50),
3059 false);
3060 SetLayerPropertiesForTesting(grand_child3.get(),
3061 identity_matrix,
3062 identity_matrix,
3063 gfx::PointF(),
3064 gfx::PointF(125.f, 125.f),
3065 gfx::Size(50, 50),
3066 false);
3067
3068 child->SetMasksToBounds(true);
3069 ExecuteCalculateDrawProperties(root.get());
3070
3071 ASSERT_FALSE(child->render_surface());
3072
3073 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3074 root->render_surface()->DrawableContentRect());
3075 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3076
3077 // Layers that do not draw content should have empty visible content rects.
3078 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3079 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
3080
3081 // All grandchild visible content rects should be clipped by child.
3082 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
3083 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
3084 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
3085
3086 // All grandchild DrawableContentRects should also be clipped by child.
3087 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
3088 grand_child1->drawable_content_rect());
3089 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
3090 grand_child2->drawable_content_rect());
3091 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
3092}
3093
[email protected]989386c2013-07-18 21:37:233094TEST_F(LayerTreeHostCommonTest,
3095 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:323096 scoped_refptr<Layer> root = Layer::Create();
3097 scoped_refptr<Layer> render_surface1 = Layer::Create();
3098 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3099 make_scoped_refptr(new LayerWithForcedDrawsContent());
3100 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3101 make_scoped_refptr(new LayerWithForcedDrawsContent());
3102 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3103 make_scoped_refptr(new LayerWithForcedDrawsContent());
3104 root->AddChild(render_surface1);
3105 render_surface1->AddChild(child1);
3106 render_surface1->AddChild(child2);
3107 render_surface1->AddChild(child3);
3108
[email protected]d600df7d2013-08-03 02:34:283109 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3110 host->SetRootLayer(root);
3111
[email protected]fb661802013-03-25 01:59:323112 gfx::Transform identity_matrix;
3113 SetLayerPropertiesForTesting(root.get(),
3114 identity_matrix,
3115 identity_matrix,
3116 gfx::PointF(),
3117 gfx::PointF(),
3118 gfx::Size(100, 100),
3119 false);
3120 SetLayerPropertiesForTesting(render_surface1.get(),
3121 identity_matrix,
3122 identity_matrix,
3123 gfx::PointF(),
3124 gfx::PointF(),
3125 gfx::Size(3, 4),
3126 false);
3127 SetLayerPropertiesForTesting(child1.get(),
3128 identity_matrix,
3129 identity_matrix,
3130 gfx::PointF(),
3131 gfx::PointF(5.f, 5.f),
3132 gfx::Size(50, 50),
3133 false);
3134 SetLayerPropertiesForTesting(child2.get(),
3135 identity_matrix,
3136 identity_matrix,
3137 gfx::PointF(),
3138 gfx::PointF(75.f, 75.f),
3139 gfx::Size(50, 50),
3140 false);
3141 SetLayerPropertiesForTesting(child3.get(),
3142 identity_matrix,
3143 identity_matrix,
3144 gfx::PointF(),
3145 gfx::PointF(125.f, 125.f),
3146 gfx::Size(50, 50),
3147 false);
3148
3149 render_surface1->SetForceRenderSurface(true);
3150 ExecuteCalculateDrawProperties(root.get());
3151
3152 ASSERT_TRUE(render_surface1->render_surface());
3153
3154 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3155 root->render_surface()->DrawableContentRect());
3156 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3157
3158 // Layers that do not draw content should have empty visible content rects.
3159 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3160 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3161 render_surface1->visible_content_rect());
3162
3163 // An unclipped surface grows its DrawableContentRect to include all drawable
3164 // regions of the subtree.
3165 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3166 render_surface1->render_surface()->DrawableContentRect());
3167
3168 // All layers that draw content into the unclipped surface are also unclipped.
3169 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3170 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3171 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
3172
3173 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3174 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3175 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3176}
3177
[email protected]989386c2013-07-18 21:37:233178TEST_F(LayerTreeHostCommonTest,
3179 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:473180 scoped_refptr<Layer> root = Layer::Create();
3181 scoped_refptr<LayerWithForcedDrawsContent> child =
3182 make_scoped_refptr(new LayerWithForcedDrawsContent());
3183 root->AddChild(child);
3184
[email protected]d600df7d2013-08-03 02:34:283185 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3186 host->SetRootLayer(root);
3187
[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);
3190
3191 SetLayerPropertiesForTesting(root.get(),
3192 identity_matrix,
3193 identity_matrix,
3194 gfx::PointF(),
3195 gfx::PointF(),
3196 gfx::Size(100, 100),
3197 false);
3198 SetLayerPropertiesForTesting(child.get(),
3199 uninvertible_matrix,
3200 identity_matrix,
3201 gfx::PointF(),
3202 gfx::PointF(5.f, 5.f),
3203 gfx::Size(50, 50),
3204 false);
3205
3206 ExecuteCalculateDrawProperties(root.get());
3207
3208 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
3209 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
3210}
3211
[email protected]989386c2013-07-18 21:37:233212TEST_F(LayerTreeHostCommonTest,
3213 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:323214 scoped_refptr<Layer> root = Layer::Create();
3215 scoped_refptr<Layer> render_surface1 = Layer::Create();
3216 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3217 make_scoped_refptr(new LayerWithForcedDrawsContent());
3218 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3219 make_scoped_refptr(new LayerWithForcedDrawsContent());
3220 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3221 make_scoped_refptr(new LayerWithForcedDrawsContent());
3222 root->AddChild(render_surface1);
3223 render_surface1->AddChild(child1);
3224 render_surface1->AddChild(child2);
3225 render_surface1->AddChild(child3);
3226
[email protected]d600df7d2013-08-03 02:34:283227 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3228 host->SetRootLayer(root);
3229
[email protected]fb661802013-03-25 01:59:323230 gfx::Transform identity_matrix;
3231 SetLayerPropertiesForTesting(root.get(),
3232 identity_matrix,
3233 identity_matrix,
3234 gfx::PointF(),
3235 gfx::PointF(),
3236 gfx::Size(100, 100),
3237 false);
3238 SetLayerPropertiesForTesting(render_surface1.get(),
3239 identity_matrix,
3240 identity_matrix,
3241 gfx::PointF(),
3242 gfx::PointF(),
3243 gfx::Size(3, 4),
3244 false);
3245 SetLayerPropertiesForTesting(child1.get(),
3246 identity_matrix,
3247 identity_matrix,
3248 gfx::PointF(),
3249 gfx::PointF(5.f, 5.f),
3250 gfx::Size(50, 50),
3251 false);
3252 SetLayerPropertiesForTesting(child2.get(),
3253 identity_matrix,
3254 identity_matrix,
3255 gfx::PointF(),
3256 gfx::PointF(75.f, 75.f),
3257 gfx::Size(50, 50),
3258 false);
3259 SetLayerPropertiesForTesting(child3.get(),
3260 identity_matrix,
3261 identity_matrix,
3262 gfx::PointF(),
3263 gfx::PointF(125.f, 125.f),
3264 gfx::Size(50, 50),
3265 false);
3266
3267 root->SetMasksToBounds(true);
3268 render_surface1->SetForceRenderSurface(true);
3269 ExecuteCalculateDrawProperties(root.get());
3270
3271 ASSERT_TRUE(render_surface1->render_surface());
3272
3273 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3274 root->render_surface()->DrawableContentRect());
3275 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3276
3277 // Layers that do not draw content should have empty visible content rects.
3278 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3279 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3280 render_surface1->visible_content_rect());
3281
3282 // A clipped surface grows its DrawableContentRect to include all drawable
3283 // regions of the subtree, but also gets clamped by the ancestor's clip.
3284 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3285 render_surface1->render_surface()->DrawableContentRect());
3286
3287 // All layers that draw content into the surface have their visible content
3288 // rect clipped by the surface clip rect.
3289 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3290 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
3291 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3292
3293 // But the DrawableContentRects are unclipped.
3294 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3295 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3296 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3297}
3298
[email protected]989386c2013-07-18 21:37:233299TEST_F(LayerTreeHostCommonTest,
3300 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323301 // Check that clipping does not propagate down surfaces.
3302 scoped_refptr<Layer> root = Layer::Create();
3303 scoped_refptr<Layer> render_surface1 = Layer::Create();
3304 scoped_refptr<Layer> render_surface2 = Layer::Create();
3305 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3306 make_scoped_refptr(new LayerWithForcedDrawsContent());
3307 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3308 make_scoped_refptr(new LayerWithForcedDrawsContent());
3309 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3310 make_scoped_refptr(new LayerWithForcedDrawsContent());
3311 root->AddChild(render_surface1);
3312 render_surface1->AddChild(render_surface2);
3313 render_surface2->AddChild(child1);
3314 render_surface2->AddChild(child2);
3315 render_surface2->AddChild(child3);
3316
[email protected]d600df7d2013-08-03 02:34:283317 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3318 host->SetRootLayer(root);
3319
[email protected]fb661802013-03-25 01:59:323320 gfx::Transform identity_matrix;
3321 SetLayerPropertiesForTesting(root.get(),
3322 identity_matrix,
3323 identity_matrix,
3324 gfx::PointF(),
3325 gfx::PointF(),
3326 gfx::Size(100, 100),
3327 false);
3328 SetLayerPropertiesForTesting(render_surface1.get(),
3329 identity_matrix,
3330 identity_matrix,
3331 gfx::PointF(),
3332 gfx::PointF(),
3333 gfx::Size(3, 4),
3334 false);
3335 SetLayerPropertiesForTesting(render_surface2.get(),
3336 identity_matrix,
3337 identity_matrix,
3338 gfx::PointF(),
3339 gfx::PointF(),
3340 gfx::Size(7, 13),
3341 false);
3342 SetLayerPropertiesForTesting(child1.get(),
3343 identity_matrix,
3344 identity_matrix,
3345 gfx::PointF(),
3346 gfx::PointF(5.f, 5.f),
3347 gfx::Size(50, 50),
3348 false);
3349 SetLayerPropertiesForTesting(child2.get(),
3350 identity_matrix,
3351 identity_matrix,
3352 gfx::PointF(),
3353 gfx::PointF(75.f, 75.f),
3354 gfx::Size(50, 50),
3355 false);
3356 SetLayerPropertiesForTesting(child3.get(),
3357 identity_matrix,
3358 identity_matrix,
3359 gfx::PointF(),
3360 gfx::PointF(125.f, 125.f),
3361 gfx::Size(50, 50),
3362 false);
3363
3364 root->SetMasksToBounds(true);
3365 render_surface1->SetForceRenderSurface(true);
3366 render_surface2->SetForceRenderSurface(true);
3367 ExecuteCalculateDrawProperties(root.get());
3368
3369 ASSERT_TRUE(render_surface1->render_surface());
3370 ASSERT_TRUE(render_surface2->render_surface());
3371
3372 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3373 root->render_surface()->DrawableContentRect());
3374 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3375
3376 // Layers that do not draw content should have empty visible content rects.
3377 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3378 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3379 render_surface1->visible_content_rect());
3380 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3381 render_surface2->visible_content_rect());
3382
3383 // A clipped surface grows its DrawableContentRect to include all drawable
3384 // regions of the subtree, but also gets clamped by the ancestor's clip.
3385 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3386 render_surface1->render_surface()->DrawableContentRect());
3387
3388 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3389 // is only implicitly clipped by render_surface1's content rect. So,
3390 // render_surface2 grows to enclose all drawable content of its subtree.
3391 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3392 render_surface2->render_surface()->DrawableContentRect());
3393
3394 // All layers that draw content into render_surface2 think they are unclipped.
3395 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3396 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3397 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
3398
3399 // DrawableContentRects are also unclipped.
3400 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3401 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3402 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3403}
3404
[email protected]989386c2013-07-18 21:37:233405TEST_F(LayerTreeHostCommonTest,
3406 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323407 // Layers that have non-axis aligned bounds (due to transforms) have an
3408 // expanded, axis-aligned DrawableContentRect and visible content rect.
3409
3410 scoped_refptr<Layer> root = Layer::Create();
3411 scoped_refptr<Layer> render_surface1 = Layer::Create();
3412 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3413 make_scoped_refptr(new LayerWithForcedDrawsContent());
3414 root->AddChild(render_surface1);
3415 render_surface1->AddChild(child1);
3416
[email protected]d600df7d2013-08-03 02:34:283417 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3418 host->SetRootLayer(root);
3419
[email protected]fb661802013-03-25 01:59:323420 gfx::Transform identity_matrix;
3421 gfx::Transform child_rotation;
3422 child_rotation.Rotate(45.0);
3423 SetLayerPropertiesForTesting(root.get(),
3424 identity_matrix,
3425 identity_matrix,
3426 gfx::PointF(),
3427 gfx::PointF(),
3428 gfx::Size(100, 100),
3429 false);
3430 SetLayerPropertiesForTesting(render_surface1.get(),
3431 identity_matrix,
3432 identity_matrix,
3433 gfx::PointF(),
3434 gfx::PointF(),
3435 gfx::Size(3, 4),
3436 false);
3437 SetLayerPropertiesForTesting(child1.get(),
3438 child_rotation,
3439 identity_matrix,
3440 gfx::PointF(0.5f, 0.5f),
3441 gfx::PointF(25.f, 25.f),
3442 gfx::Size(50, 50),
3443 false);
3444
3445 render_surface1->SetForceRenderSurface(true);
3446 ExecuteCalculateDrawProperties(root.get());
3447
3448 ASSERT_TRUE(render_surface1->render_surface());
3449
3450 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3451 root->render_surface()->DrawableContentRect());
3452 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3453
3454 // Layers that do not draw content should have empty visible content rects.
3455 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3456 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3457 render_surface1->visible_content_rect());
3458
3459 // The unclipped surface grows its DrawableContentRect to include all drawable
3460 // regions of the subtree.
3461 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3462 gfx::Rect expected_surface_drawable_content =
3463 gfx::Rect(50.0 - diagonal_radius,
3464 50.0 - diagonal_radius,
3465 diagonal_radius * 2.0,
3466 diagonal_radius * 2.0);
3467 EXPECT_RECT_EQ(expected_surface_drawable_content,
3468 render_surface1->render_surface()->DrawableContentRect());
3469
3470 // All layers that draw content into the unclipped surface are also unclipped.
3471 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3472 EXPECT_RECT_EQ(expected_surface_drawable_content,
3473 child1->drawable_content_rect());
3474}
3475
[email protected]989386c2013-07-18 21:37:233476TEST_F(LayerTreeHostCommonTest,
3477 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323478 // Layers that have non-axis aligned bounds (due to transforms) have an
3479 // expanded, axis-aligned DrawableContentRect and visible content rect.
3480
3481 scoped_refptr<Layer> root = Layer::Create();
3482 scoped_refptr<Layer> render_surface1 = Layer::Create();
3483 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3484 make_scoped_refptr(new LayerWithForcedDrawsContent());
3485 root->AddChild(render_surface1);
3486 render_surface1->AddChild(child1);
3487
[email protected]d600df7d2013-08-03 02:34:283488 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3489 host->SetRootLayer(root);
3490
[email protected]fb661802013-03-25 01:59:323491 gfx::Transform identity_matrix;
3492 gfx::Transform child_rotation;
3493 child_rotation.Rotate(45.0);
3494 SetLayerPropertiesForTesting(root.get(),
3495 identity_matrix,
3496 identity_matrix,
3497 gfx::PointF(),
3498 gfx::PointF(),
3499 gfx::Size(50, 50),
3500 false);
3501 SetLayerPropertiesForTesting(render_surface1.get(),
3502 identity_matrix,
3503 identity_matrix,
3504 gfx::PointF(),
3505 gfx::PointF(),
3506 gfx::Size(3, 4),
3507 false);
3508 SetLayerPropertiesForTesting(child1.get(),
3509 child_rotation,
3510 identity_matrix,
3511 gfx::PointF(0.5f, 0.5f),
3512 gfx::PointF(25.f, 25.f),
3513 gfx::Size(50, 50),
3514 false);
3515
3516 root->SetMasksToBounds(true);
3517 render_surface1->SetForceRenderSurface(true);
3518 ExecuteCalculateDrawProperties(root.get());
3519
3520 ASSERT_TRUE(render_surface1->render_surface());
3521
3522 // The clipped surface clamps the DrawableContentRect that encloses the
3523 // rotated layer.
3524 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3525 gfx::Rect unclipped_surface_content = gfx::Rect(50.0 - diagonal_radius,
3526 50.0 - diagonal_radius,
3527 diagonal_radius * 2.0,
3528 diagonal_radius * 2.0);
3529 gfx::Rect expected_surface_drawable_content =
3530 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
3531 EXPECT_RECT_EQ(expected_surface_drawable_content,
3532 render_surface1->render_surface()->DrawableContentRect());
3533
3534 // On the clipped surface, only a quarter of the child1 is visible, but when
3535 // rotating it back to child1's content space, the actual enclosing rect ends
3536 // up covering the full left half of child1.
3537 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
3538
3539 // The child's DrawableContentRect is unclipped.
3540 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3541}
3542
[email protected]989386c2013-07-18 21:37:233543TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323544 MockContentLayerClient client;
3545
3546 scoped_refptr<Layer> root = Layer::Create();
3547 scoped_refptr<ContentLayer> render_surface1 =
3548 CreateDrawableContentLayer(&client);
3549 scoped_refptr<ContentLayer> render_surface2 =
3550 CreateDrawableContentLayer(&client);
3551 scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client);
3552 scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client);
3553 scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client);
3554 root->AddChild(render_surface1);
3555 render_surface1->AddChild(render_surface2);
3556 render_surface2->AddChild(child1);
3557 render_surface2->AddChild(child2);
3558 render_surface2->AddChild(child3);
3559
[email protected]d600df7d2013-08-03 02:34:283560 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3561 host->SetRootLayer(root);
3562
[email protected]fb661802013-03-25 01:59:323563 gfx::Transform identity_matrix;
3564 SetLayerPropertiesForTesting(root.get(),
3565 identity_matrix,
3566 identity_matrix,
3567 gfx::PointF(),
3568 gfx::PointF(),
3569 gfx::Size(100, 100),
3570 false);
3571 SetLayerPropertiesForTesting(render_surface1.get(),
3572 identity_matrix,
3573 identity_matrix,
3574 gfx::PointF(),
3575 gfx::PointF(5.f, 5.f),
3576 gfx::Size(3, 4),
3577 false);
3578 SetLayerPropertiesForTesting(render_surface2.get(),
3579 identity_matrix,
3580 identity_matrix,
3581 gfx::PointF(),
3582 gfx::PointF(5.f, 5.f),
3583 gfx::Size(7, 13),
3584 false);
3585 SetLayerPropertiesForTesting(child1.get(),
3586 identity_matrix,
3587 identity_matrix,
3588 gfx::PointF(),
3589 gfx::PointF(5.f, 5.f),
3590 gfx::Size(50, 50),
3591 false);
3592 SetLayerPropertiesForTesting(child2.get(),
3593 identity_matrix,
3594 identity_matrix,
3595 gfx::PointF(),
3596 gfx::PointF(75.f, 75.f),
3597 gfx::Size(50, 50),
3598 false);
3599 SetLayerPropertiesForTesting(child3.get(),
3600 identity_matrix,
3601 identity_matrix,
3602 gfx::PointF(),
3603 gfx::PointF(125.f, 125.f),
3604 gfx::Size(50, 50),
3605 false);
3606
3607 float device_scale_factor = 2.f;
3608
3609 root->SetMasksToBounds(true);
3610 render_surface1->SetForceRenderSurface(true);
3611 render_surface2->SetForceRenderSurface(true);
3612 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3613
3614 ASSERT_TRUE(render_surface1->render_surface());
3615 ASSERT_TRUE(render_surface2->render_surface());
3616
3617 // drawable_content_rects for all layers and surfaces are scaled by
3618 // device_scale_factor.
3619 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3620 root->render_surface()->DrawableContentRect());
3621 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3622 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3623 render_surface1->render_surface()->DrawableContentRect());
3624
3625 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3626 // is only implicitly clipped by render_surface1.
3627 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3628 render_surface2->render_surface()->DrawableContentRect());
3629
3630 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3631 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3632 child2->drawable_content_rect());
3633 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3634 child3->drawable_content_rect());
3635
3636 // The root layer does not actually draw content of its own.
3637 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3638
3639 // All layer visible content rects are expressed in content space of each
3640 // layer, so they are also scaled by the device_scale_factor.
3641 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8),
3642 render_surface1->visible_content_rect());
3643 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26),
3644 render_surface2->visible_content_rect());
3645 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect());
3646 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect());
3647 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect());
3648}
3649
[email protected]989386c2013-07-18 21:37:233650TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323651 // Verify the behavior of back-face culling when there are no preserve-3d
3652 // layers. Note that 3d transforms still apply in this case, but they are
3653 // "flattened" to each parent layer according to current W3C spec.
3654
3655 const gfx::Transform identity_matrix;
3656 scoped_refptr<Layer> parent = Layer::Create();
3657 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3658 make_scoped_refptr(new LayerWithForcedDrawsContent());
3659 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3660 make_scoped_refptr(new LayerWithForcedDrawsContent());
3661 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3662 make_scoped_refptr(new LayerWithForcedDrawsContent());
3663 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3664 make_scoped_refptr(new LayerWithForcedDrawsContent());
3665 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233666 front_facing_child_of_front_facing_surface =
3667 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323668 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233669 back_facing_child_of_front_facing_surface =
3670 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323671 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233672 front_facing_child_of_back_facing_surface =
3673 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323674 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233675 back_facing_child_of_back_facing_surface =
3676 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323677
3678 parent->AddChild(front_facing_child);
3679 parent->AddChild(back_facing_child);
3680 parent->AddChild(front_facing_surface);
3681 parent->AddChild(back_facing_surface);
3682 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3683 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3684 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3685 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3686
[email protected]d600df7d2013-08-03 02:34:283687 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3688 host->SetRootLayer(parent);
3689
[email protected]fb661802013-03-25 01:59:323690 // Nothing is double-sided
3691 front_facing_child->SetDoubleSided(false);
3692 back_facing_child->SetDoubleSided(false);
3693 front_facing_surface->SetDoubleSided(false);
3694 back_facing_surface->SetDoubleSided(false);
3695 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3696 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3697 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3698 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3699
3700 gfx::Transform backface_matrix;
3701 backface_matrix.Translate(50.0, 50.0);
3702 backface_matrix.RotateAboutYAxis(180.0);
3703 backface_matrix.Translate(-50.0, -50.0);
3704
3705 // Having a descendant and opacity will force these to have render surfaces.
3706 front_facing_surface->SetOpacity(0.5f);
3707 back_facing_surface->SetOpacity(0.5f);
3708
3709 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3710 // these layers should blindly use their own local transforms to determine
3711 // back-face culling.
3712 SetLayerPropertiesForTesting(parent.get(),
3713 identity_matrix,
3714 identity_matrix,
3715 gfx::PointF(),
3716 gfx::PointF(),
3717 gfx::Size(100, 100),
3718 false);
3719 SetLayerPropertiesForTesting(front_facing_child.get(),
3720 identity_matrix,
3721 identity_matrix,
3722 gfx::PointF(),
3723 gfx::PointF(),
3724 gfx::Size(100, 100),
3725 false);
3726 SetLayerPropertiesForTesting(back_facing_child.get(),
3727 backface_matrix,
3728 identity_matrix,
3729 gfx::PointF(),
3730 gfx::PointF(),
3731 gfx::Size(100, 100),
3732 false);
3733 SetLayerPropertiesForTesting(front_facing_surface.get(),
3734 identity_matrix,
3735 identity_matrix,
3736 gfx::PointF(),
3737 gfx::PointF(),
3738 gfx::Size(100, 100),
3739 false);
3740 SetLayerPropertiesForTesting(back_facing_surface.get(),
3741 backface_matrix,
3742 identity_matrix,
3743 gfx::PointF(),
3744 gfx::PointF(),
3745 gfx::Size(100, 100),
3746 false);
3747 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3748 identity_matrix,
3749 identity_matrix,
3750 gfx::PointF(),
3751 gfx::PointF(),
3752 gfx::Size(100, 100),
3753 false);
3754 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3755 backface_matrix,
3756 identity_matrix,
3757 gfx::PointF(),
3758 gfx::PointF(),
3759 gfx::Size(100, 100),
3760 false);
3761 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3762 identity_matrix,
3763 identity_matrix,
3764 gfx::PointF(),
3765 gfx::PointF(),
3766 gfx::Size(100, 100),
3767 false);
3768 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3769 backface_matrix,
3770 identity_matrix,
3771 gfx::PointF(),
3772 gfx::PointF(),
3773 gfx::Size(100, 100),
3774 false);
3775
[email protected]989386c2013-07-18 21:37:233776 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533777 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3778 parent.get(), parent->bounds(), &render_surface_layer_list);
3779 inputs.can_adjust_raster_scales = true;
3780 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323781
3782 // Verify which render surfaces were created.
3783 EXPECT_FALSE(front_facing_child->render_surface());
3784 EXPECT_FALSE(back_facing_child->render_surface());
3785 EXPECT_TRUE(front_facing_surface->render_surface());
3786 EXPECT_TRUE(back_facing_surface->render_surface());
3787 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3788 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3789 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3790 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3791
3792 // Verify the render_surface_layer_list.
3793 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233794 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3795 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323796 // Even though the back facing surface LAYER gets culled, the other
3797 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233798 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323799
3800 // Verify root surface's layer list.
3801 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233802 3u,
3803 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3804 EXPECT_EQ(front_facing_child->id(),
3805 render_surface_layer_list.at(0)
3806 ->render_surface()->layer_list().at(0)->id());
3807 EXPECT_EQ(front_facing_surface->id(),
3808 render_surface_layer_list.at(0)
3809 ->render_surface()->layer_list().at(1)->id());
3810 EXPECT_EQ(back_facing_surface->id(),
3811 render_surface_layer_list.at(0)
3812 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:323813
3814 // Verify front_facing_surface's layer list.
3815 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233816 2u,
3817 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3818 EXPECT_EQ(front_facing_surface->id(),
3819 render_surface_layer_list.at(1)
3820 ->render_surface()->layer_list().at(0)->id());
3821 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3822 render_surface_layer_list.at(1)
3823 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323824
3825 // Verify back_facing_surface's layer list; its own layer should be culled
3826 // from the surface list.
3827 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233828 1u,
3829 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3830 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3831 render_surface_layer_list.at(2)
3832 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:323833}
3834
[email protected]989386c2013-07-18 21:37:233835TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323836 // Verify the behavior of back-face culling when preserves-3d transform style
3837 // is used.
3838
3839 const gfx::Transform identity_matrix;
3840 scoped_refptr<Layer> parent = Layer::Create();
3841 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3842 make_scoped_refptr(new LayerWithForcedDrawsContent());
3843 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3844 make_scoped_refptr(new LayerWithForcedDrawsContent());
3845 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3846 make_scoped_refptr(new LayerWithForcedDrawsContent());
3847 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3848 make_scoped_refptr(new LayerWithForcedDrawsContent());
3849 scoped_refptr<LayerWithForcedDrawsContent>
3850 front_facing_child_of_front_facing_surface =
3851 make_scoped_refptr(new LayerWithForcedDrawsContent());
3852 scoped_refptr<LayerWithForcedDrawsContent>
3853 back_facing_child_of_front_facing_surface =
3854 make_scoped_refptr(new LayerWithForcedDrawsContent());
3855 scoped_refptr<LayerWithForcedDrawsContent>
3856 front_facing_child_of_back_facing_surface =
3857 make_scoped_refptr(new LayerWithForcedDrawsContent());
3858 scoped_refptr<LayerWithForcedDrawsContent>
3859 back_facing_child_of_back_facing_surface =
3860 make_scoped_refptr(new LayerWithForcedDrawsContent());
3861 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3862 make_scoped_refptr(new LayerWithForcedDrawsContent());
3863 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3864 make_scoped_refptr(new LayerWithForcedDrawsContent());
3865
3866 parent->AddChild(front_facing_child);
3867 parent->AddChild(back_facing_child);
3868 parent->AddChild(front_facing_surface);
3869 parent->AddChild(back_facing_surface);
3870 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3871 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3872 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3873 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3874
[email protected]d600df7d2013-08-03 02:34:283875 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
3876 host->SetRootLayer(parent);
3877
[email protected]fb661802013-03-25 01:59:323878 // Nothing is double-sided
3879 front_facing_child->SetDoubleSided(false);
3880 back_facing_child->SetDoubleSided(false);
3881 front_facing_surface->SetDoubleSided(false);
3882 back_facing_surface->SetDoubleSided(false);
3883 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3884 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3885 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3886 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3887
3888 gfx::Transform backface_matrix;
3889 backface_matrix.Translate(50.0, 50.0);
3890 backface_matrix.RotateAboutYAxis(180.0);
3891 backface_matrix.Translate(-50.0, -50.0);
3892
3893 // Opacity will not force creation of render surfaces in this case because of
3894 // the preserve-3d transform style. Instead, an example of when a surface
3895 // would be created with preserve-3d is when there is a replica layer.
3896 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3897 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3898
3899 // Each surface creates its own new 3d rendering context (as defined by W3C
3900 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3901 // rendering context should use the transform with respect to that context.
3902 // This 3d rendering context occurs when (a) parent's transform style is flat
3903 // and (b) the layer's transform style is preserve-3d.
3904 SetLayerPropertiesForTesting(parent.get(),
3905 identity_matrix,
3906 identity_matrix,
3907 gfx::PointF(),
3908 gfx::PointF(),
3909 gfx::Size(100, 100),
3910 false); // parent transform style is flat.
3911 SetLayerPropertiesForTesting(front_facing_child.get(),
3912 identity_matrix,
3913 identity_matrix,
3914 gfx::PointF(),
3915 gfx::PointF(),
3916 gfx::Size(100, 100),
3917 false);
3918 SetLayerPropertiesForTesting(back_facing_child.get(),
3919 backface_matrix,
3920 identity_matrix,
3921 gfx::PointF(),
3922 gfx::PointF(),
3923 gfx::Size(100, 100),
3924 false);
3925 SetLayerPropertiesForTesting(
3926 front_facing_surface.get(),
3927 identity_matrix,
3928 identity_matrix,
3929 gfx::PointF(),
3930 gfx::PointF(),
3931 gfx::Size(100, 100),
3932 true); // surface transform style is preserve-3d.
3933 SetLayerPropertiesForTesting(
3934 back_facing_surface.get(),
3935 backface_matrix,
3936 identity_matrix,
3937 gfx::PointF(),
3938 gfx::PointF(),
3939 gfx::Size(100, 100),
3940 true); // surface transform style is preserve-3d.
3941 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3942 identity_matrix,
3943 identity_matrix,
3944 gfx::PointF(),
3945 gfx::PointF(),
3946 gfx::Size(100, 100),
3947 false);
3948 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3949 backface_matrix,
3950 identity_matrix,
3951 gfx::PointF(),
3952 gfx::PointF(),
3953 gfx::Size(100, 100),
3954 false);
3955 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3956 identity_matrix,
3957 identity_matrix,
3958 gfx::PointF(),
3959 gfx::PointF(),
3960 gfx::Size(100, 100),
3961 false);
3962 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3963 backface_matrix,
3964 identity_matrix,
3965 gfx::PointF(),
3966 gfx::PointF(),
3967 gfx::Size(100, 100),
3968 false);
3969
[email protected]989386c2013-07-18 21:37:233970 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533971 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3972 parent.get(), parent->bounds(), &render_surface_layer_list);
3973 inputs.can_adjust_raster_scales = true;
3974 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323975
3976 // Verify which render surfaces were created.
3977 EXPECT_FALSE(front_facing_child->render_surface());
3978 EXPECT_FALSE(back_facing_child->render_surface());
3979 EXPECT_TRUE(front_facing_surface->render_surface());
3980 EXPECT_FALSE(back_facing_surface->render_surface());
3981 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3982 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3983 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3984 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3985
3986 // Verify the render_surface_layer_list. The back-facing surface should be
3987 // culled.
3988 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233989 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3990 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323991
3992 // Verify root surface's layer list.
3993 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233994 2u,
3995 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3996 EXPECT_EQ(front_facing_child->id(),
3997 render_surface_layer_list.at(0)
3998 ->render_surface()->layer_list().at(0)->id());
3999 EXPECT_EQ(front_facing_surface->id(),
4000 render_surface_layer_list.at(0)
4001 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324002
4003 // Verify front_facing_surface's layer list.
4004 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234005 2u,
4006 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4007 EXPECT_EQ(front_facing_surface->id(),
4008 render_surface_layer_list.at(1)
4009 ->render_surface()->layer_list().at(0)->id());
4010 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
4011 render_surface_layer_list.at(1)
4012 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324013}
4014
[email protected]989386c2013-07-18 21:37:234015TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324016 // Verify that layers are appropriately culled when their back face is showing
4017 // and they are not double sided, while animations are going on.
4018 //
4019 // Layers that are animating do not get culled on the main thread, as their
4020 // transforms should be treated as "unknown" so we can not be sure that their
4021 // back face is really showing.
4022 const gfx::Transform identity_matrix;
4023 scoped_refptr<Layer> parent = Layer::Create();
4024 scoped_refptr<LayerWithForcedDrawsContent> child =
4025 make_scoped_refptr(new LayerWithForcedDrawsContent());
4026 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
4027 make_scoped_refptr(new LayerWithForcedDrawsContent());
4028 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
4029 make_scoped_refptr(new LayerWithForcedDrawsContent());
4030 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
4031 make_scoped_refptr(new LayerWithForcedDrawsContent());
4032 scoped_refptr<LayerWithForcedDrawsContent> child2 =
4033 make_scoped_refptr(new LayerWithForcedDrawsContent());
4034
4035 parent->AddChild(child);
4036 parent->AddChild(animating_surface);
4037 animating_surface->AddChild(child_of_animating_surface);
4038 parent->AddChild(animating_child);
4039 parent->AddChild(child2);
4040
[email protected]d600df7d2013-08-03 02:34:284041 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4042 host->SetRootLayer(parent);
4043
[email protected]fb661802013-03-25 01:59:324044 // Nothing is double-sided
4045 child->SetDoubleSided(false);
4046 child2->SetDoubleSided(false);
4047 animating_surface->SetDoubleSided(false);
4048 child_of_animating_surface->SetDoubleSided(false);
4049 animating_child->SetDoubleSided(false);
4050
4051 gfx::Transform backface_matrix;
4052 backface_matrix.Translate(50.0, 50.0);
4053 backface_matrix.RotateAboutYAxis(180.0);
4054 backface_matrix.Translate(-50.0, -50.0);
4055
4056 // Make our render surface.
4057 animating_surface->SetForceRenderSurface(true);
4058
4059 // Animate the transform on the render surface.
4060 AddAnimatedTransformToController(
4061 animating_surface->layer_animation_controller(), 10.0, 30, 0);
4062 // This is just an animating layer, not a surface.
4063 AddAnimatedTransformToController(
4064 animating_child->layer_animation_controller(), 10.0, 30, 0);
4065
4066 SetLayerPropertiesForTesting(parent.get(),
4067 identity_matrix,
4068 identity_matrix,
4069 gfx::PointF(),
4070 gfx::PointF(),
4071 gfx::Size(100, 100),
4072 false);
4073 SetLayerPropertiesForTesting(child.get(),
4074 backface_matrix,
4075 identity_matrix,
4076 gfx::PointF(),
4077 gfx::PointF(),
4078 gfx::Size(100, 100),
4079 false);
4080 SetLayerPropertiesForTesting(animating_surface.get(),
4081 backface_matrix,
4082 identity_matrix,
4083 gfx::PointF(),
4084 gfx::PointF(),
4085 gfx::Size(100, 100),
4086 false);
4087 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
4088 backface_matrix,
4089 identity_matrix,
4090 gfx::PointF(),
4091 gfx::PointF(),
4092 gfx::Size(100, 100),
4093 false);
4094 SetLayerPropertiesForTesting(animating_child.get(),
4095 backface_matrix,
4096 identity_matrix,
4097 gfx::PointF(),
4098 gfx::PointF(),
4099 gfx::Size(100, 100),
4100 false);
4101 SetLayerPropertiesForTesting(child2.get(),
4102 identity_matrix,
4103 identity_matrix,
4104 gfx::PointF(),
4105 gfx::PointF(),
4106 gfx::Size(100, 100),
4107 false);
4108
[email protected]989386c2013-07-18 21:37:234109 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534110 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4111 parent.get(), parent->bounds(), &render_surface_layer_list);
4112 inputs.can_adjust_raster_scales = true;
4113 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324114
4115 EXPECT_FALSE(child->render_surface());
4116 EXPECT_TRUE(animating_surface->render_surface());
4117 EXPECT_FALSE(child_of_animating_surface->render_surface());
4118 EXPECT_FALSE(animating_child->render_surface());
4119 EXPECT_FALSE(child2->render_surface());
4120
4121 // Verify that the animating_child and child_of_animating_surface were not
4122 // culled, but that child was.
4123 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234124 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4125 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324126
4127 // The non-animating child be culled from the layer list for the parent render
4128 // surface.
4129 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234130 3u,
4131 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4132 EXPECT_EQ(animating_surface->id(),
4133 render_surface_layer_list.at(0)
4134 ->render_surface()->layer_list().at(0)->id());
4135 EXPECT_EQ(animating_child->id(),
4136 render_surface_layer_list.at(0)
4137 ->render_surface()->layer_list().at(1)->id());
4138 EXPECT_EQ(child2->id(),
4139 render_surface_layer_list.at(0)
4140 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:324141
4142 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234143 2u,
4144 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4145 EXPECT_EQ(animating_surface->id(),
4146 render_surface_layer_list.at(1)
4147 ->render_surface()->layer_list().at(0)->id());
4148 EXPECT_EQ(child_of_animating_surface->id(),
4149 render_surface_layer_list.at(1)
4150 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324151
4152 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
4153
4154 // The animating layers should have a visible content rect that represents the
4155 // area of the front face that is within the viewport.
4156 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054157 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:324158 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054159 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324160 // And layers in the subtree of the animating layer should have valid visible
4161 // content rects also.
[email protected]989386c2013-07-18 21:37:234162 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
4163 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324164}
4165
[email protected]989386c2013-07-18 21:37:234166TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324167 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4168 // Verify the behavior of back-face culling for a render surface that is
4169 // created when it flattens its subtree, and its parent has preserves-3d.
4170
4171 const gfx::Transform identity_matrix;
4172 scoped_refptr<Layer> parent = Layer::Create();
4173 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
4174 make_scoped_refptr(new LayerWithForcedDrawsContent());
4175 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
4176 make_scoped_refptr(new LayerWithForcedDrawsContent());
4177 scoped_refptr<LayerWithForcedDrawsContent> child1 =
4178 make_scoped_refptr(new LayerWithForcedDrawsContent());
4179 scoped_refptr<LayerWithForcedDrawsContent> child2 =
4180 make_scoped_refptr(new LayerWithForcedDrawsContent());
4181
4182 parent->AddChild(front_facing_surface);
4183 parent->AddChild(back_facing_surface);
4184 front_facing_surface->AddChild(child1);
4185 back_facing_surface->AddChild(child2);
4186
[email protected]d600df7d2013-08-03 02:34:284187 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4188 host->SetRootLayer(parent);
4189
[email protected]fb661802013-03-25 01:59:324190 // RenderSurfaces are not double-sided
4191 front_facing_surface->SetDoubleSided(false);
4192 back_facing_surface->SetDoubleSided(false);
4193
4194 gfx::Transform backface_matrix;
4195 backface_matrix.Translate(50.0, 50.0);
4196 backface_matrix.RotateAboutYAxis(180.0);
4197 backface_matrix.Translate(-50.0, -50.0);
4198
4199 SetLayerPropertiesForTesting(parent.get(),
4200 identity_matrix,
4201 identity_matrix,
4202 gfx::PointF(),
4203 gfx::PointF(),
4204 gfx::Size(100, 100),
4205 true); // parent transform style is preserve3d.
4206 SetLayerPropertiesForTesting(front_facing_surface.get(),
4207 identity_matrix,
4208 identity_matrix,
4209 gfx::PointF(),
4210 gfx::PointF(),
4211 gfx::Size(100, 100),
4212 false); // surface transform style is flat.
4213 SetLayerPropertiesForTesting(back_facing_surface.get(),
4214 backface_matrix,
4215 identity_matrix,
4216 gfx::PointF(),
4217 gfx::PointF(),
4218 gfx::Size(100, 100),
4219 false); // surface transform style is flat.
4220 SetLayerPropertiesForTesting(child1.get(),
4221 identity_matrix,
4222 identity_matrix,
4223 gfx::PointF(),
4224 gfx::PointF(),
4225 gfx::Size(100, 100),
4226 false);
4227 SetLayerPropertiesForTesting(child2.get(),
4228 identity_matrix,
4229 identity_matrix,
4230 gfx::PointF(),
4231 gfx::PointF(),
4232 gfx::Size(100, 100),
4233 false);
4234
[email protected]989386c2013-07-18 21:37:234235 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534236 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4237 parent.get(), parent->bounds(), &render_surface_layer_list);
4238 inputs.can_adjust_raster_scales = true;
4239 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324240
4241 // Verify which render surfaces were created.
4242 EXPECT_TRUE(front_facing_surface->render_surface());
4243 EXPECT_FALSE(
4244 back_facing_surface->render_surface()); // because it should be culled
4245 EXPECT_FALSE(child1->render_surface());
4246 EXPECT_FALSE(child2->render_surface());
4247
4248 // Verify the render_surface_layer_list. The back-facing surface should be
4249 // culled.
4250 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234251 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4252 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324253
4254 // Verify root surface's layer list.
4255 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234256 1u,
4257 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4258 EXPECT_EQ(front_facing_surface->id(),
4259 render_surface_layer_list.at(0)
4260 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324261
4262 // Verify front_facing_surface's layer list.
4263 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234264 2u,
4265 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4266 EXPECT_EQ(front_facing_surface->id(),
4267 render_surface_layer_list.at(1)
4268 ->render_surface()->layer_list().at(0)->id());
4269 EXPECT_EQ(child1->id(),
4270 render_surface_layer_list.at(1)
4271 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324272}
4273
[email protected]989386c2013-07-18 21:37:234274
4275TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:324276 // Hit testing on an empty render_surface_layer_list should return a null
4277 // pointer.
[email protected]50761e92013-03-29 20:51:284278 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:324279
4280 gfx::Point test_point(0, 0);
4281 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4282 test_point, render_surface_layer_list);
4283 EXPECT_FALSE(result_layer);
4284
4285 test_point = gfx::Point(10, 20);
4286 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4287 test_point, render_surface_layer_list);
4288 EXPECT_FALSE(result_layer);
4289}
4290
[email protected]989386c2013-07-18 21:37:234291TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayer) {
[email protected]fb661802013-03-25 01:59:324292 FakeImplProxy proxy;
4293 FakeLayerTreeHostImpl host_impl(&proxy);
4294 scoped_ptr<LayerImpl> root =
4295 LayerImpl::Create(host_impl.active_tree(), 12345);
4296
4297 gfx::Transform identity_matrix;
4298 gfx::PointF anchor;
4299 gfx::PointF position;
4300 gfx::Size bounds(100, 100);
4301 SetLayerPropertiesForTesting(root.get(),
4302 identity_matrix,
4303 identity_matrix,
4304 anchor,
4305 position,
4306 bounds,
4307 false);
4308 root->SetDrawsContent(true);
4309
[email protected]50761e92013-03-29 20:51:284310 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534311 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4312 root.get(), root->bounds(), &render_surface_layer_list);
4313 inputs.can_adjust_raster_scales = true;
4314 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324315
4316 // Sanity check the scenario we just created.
4317 ASSERT_EQ(1u, render_surface_layer_list.size());
4318 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4319
4320 // Hit testing for a point outside the layer should return a null pointer.
4321 gfx::Point test_point(101, 101);
4322 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4323 test_point, render_surface_layer_list);
4324 EXPECT_FALSE(result_layer);
4325
4326 test_point = gfx::Point(-1, -1);
4327 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4328 test_point, render_surface_layer_list);
4329 EXPECT_FALSE(result_layer);
4330
4331 // Hit testing for a point inside should return the root layer.
4332 test_point = gfx::Point(1, 1);
4333 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4334 test_point, render_surface_layer_list);
4335 ASSERT_TRUE(result_layer);
4336 EXPECT_EQ(12345, result_layer->id());
4337
4338 test_point = gfx::Point(99, 99);
4339 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4340 test_point, render_surface_layer_list);
4341 ASSERT_TRUE(result_layer);
4342 EXPECT_EQ(12345, result_layer->id());
4343}
4344
[email protected]989386c2013-07-18 21:37:234345TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) {
[email protected]fb661802013-03-25 01:59:324346 FakeImplProxy proxy;
4347 FakeLayerTreeHostImpl host_impl(&proxy);
4348 scoped_ptr<LayerImpl> root =
4349 LayerImpl::Create(host_impl.active_tree(), 12345);
4350 scoped_ptr<HeadsUpDisplayLayerImpl> hud =
4351 HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111);
4352
4353 gfx::Transform identity_matrix;
4354 gfx::PointF anchor;
4355 gfx::PointF position;
4356 gfx::Size bounds(100, 100);
4357 SetLayerPropertiesForTesting(root.get(),
4358 identity_matrix,
4359 identity_matrix,
4360 anchor,
4361 position,
4362 bounds,
4363 false);
4364 root->SetDrawsContent(true);
4365
4366 // Create hud and add it as a child of root.
4367 gfx::Size hud_bounds(200, 200);
4368 SetLayerPropertiesForTesting(hud.get(),
4369 identity_matrix,
4370 identity_matrix,
4371 anchor,
4372 position,
4373 hud_bounds,
4374 false);
4375 hud->SetDrawsContent(true);
4376
4377 host_impl.active_tree()->set_hud_layer(hud.get());
4378 root->AddChild(hud.PassAs<LayerImpl>());
4379
[email protected]50761e92013-03-29 20:51:284380 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534381 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4382 root.get(), hud_bounds, &render_surface_layer_list);
4383 inputs.can_adjust_raster_scales = true;
4384 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324385
4386 // Sanity check the scenario we just created.
4387 ASSERT_EQ(1u, render_surface_layer_list.size());
4388 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4389
4390 // Hit testing for a point inside HUD, but outside root should return null
4391 gfx::Point test_point(101, 101);
4392 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4393 test_point, render_surface_layer_list);
4394 EXPECT_FALSE(result_layer);
4395
4396 test_point = gfx::Point(-1, -1);
4397 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4398 test_point, render_surface_layer_list);
4399 EXPECT_FALSE(result_layer);
4400
4401 // Hit testing for a point inside should return the root layer, never the HUD
4402 // layer.
4403 test_point = gfx::Point(1, 1);
4404 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4405 test_point, render_surface_layer_list);
4406 ASSERT_TRUE(result_layer);
4407 EXPECT_EQ(12345, result_layer->id());
4408
4409 test_point = gfx::Point(99, 99);
4410 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4411 test_point, render_surface_layer_list);
4412 ASSERT_TRUE(result_layer);
4413 EXPECT_EQ(12345, result_layer->id());
4414}
4415
[email protected]989386c2013-07-18 21:37:234416TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) {
[email protected]fb661802013-03-25 01:59:324417 FakeImplProxy proxy;
4418 FakeLayerTreeHostImpl host_impl(&proxy);
4419 scoped_ptr<LayerImpl> root =
4420 LayerImpl::Create(host_impl.active_tree(), 12345);
4421
4422 gfx::Transform uninvertible_transform;
4423 uninvertible_transform.matrix().setDouble(0, 0, 0.0);
4424 uninvertible_transform.matrix().setDouble(1, 1, 0.0);
4425 uninvertible_transform.matrix().setDouble(2, 2, 0.0);
4426 uninvertible_transform.matrix().setDouble(3, 3, 0.0);
4427 ASSERT_FALSE(uninvertible_transform.IsInvertible());
4428
4429 gfx::Transform identity_matrix;
4430 gfx::PointF anchor;
4431 gfx::PointF position;
4432 gfx::Size bounds(100, 100);
4433 SetLayerPropertiesForTesting(root.get(),
4434 uninvertible_transform,
4435 identity_matrix,
4436 anchor,
4437 position,
4438 bounds,
4439 false);
4440 root->SetDrawsContent(true);
4441
[email protected]50761e92013-03-29 20:51:284442 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534443 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4444 root.get(), root->bounds(), &render_surface_layer_list);
4445 inputs.can_adjust_raster_scales = true;
4446 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324447
4448 // Sanity check the scenario we just created.
4449 ASSERT_EQ(1u, render_surface_layer_list.size());
4450 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4451 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
4452
4453 // Hit testing any point should not hit the layer. If the invertible matrix is
4454 // accidentally ignored and treated like an identity, then the hit testing
4455 // will incorrectly hit the layer when it shouldn't.
4456 gfx::Point test_point(1, 1);
4457 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4458 test_point, render_surface_layer_list);
4459 EXPECT_FALSE(result_layer);
4460
4461 test_point = gfx::Point(10, 10);
4462 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4463 test_point, render_surface_layer_list);
4464 EXPECT_FALSE(result_layer);
4465
4466 test_point = gfx::Point(10, 30);
4467 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4468 test_point, render_surface_layer_list);
4469 EXPECT_FALSE(result_layer);
4470
4471 test_point = gfx::Point(50, 50);
4472 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4473 test_point, render_surface_layer_list);
4474 EXPECT_FALSE(result_layer);
4475
4476 test_point = gfx::Point(67, 48);
4477 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4478 test_point, render_surface_layer_list);
4479 EXPECT_FALSE(result_layer);
4480
4481 test_point = gfx::Point(99, 99);
4482 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4483 test_point, render_surface_layer_list);
4484 EXPECT_FALSE(result_layer);
4485
4486 test_point = gfx::Point(-1, -1);
4487 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4488 test_point, render_surface_layer_list);
4489 EXPECT_FALSE(result_layer);
4490}
4491
[email protected]989386c2013-07-18 21:37:234492TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) {
[email protected]fb661802013-03-25 01:59:324493 FakeImplProxy proxy;
4494 FakeLayerTreeHostImpl host_impl(&proxy);
4495 scoped_ptr<LayerImpl> root =
4496 LayerImpl::Create(host_impl.active_tree(), 12345);
4497
4498 gfx::Transform identity_matrix;
4499 gfx::PointF anchor;
4500 // this layer is positioned, and hit testing should correctly know where the
4501 // layer is located.
4502 gfx::PointF position(50.f, 50.f);
4503 gfx::Size bounds(100, 100);
4504 SetLayerPropertiesForTesting(root.get(),
4505 identity_matrix,
4506 identity_matrix,
4507 anchor,
4508 position,
4509 bounds,
4510 false);
4511 root->SetDrawsContent(true);
4512
[email protected]50761e92013-03-29 20:51:284513 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534514 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4515 root.get(), root->bounds(), &render_surface_layer_list);
4516 inputs.can_adjust_raster_scales = true;
4517 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324518
4519 // Sanity check the scenario we just created.
4520 ASSERT_EQ(1u, render_surface_layer_list.size());
4521 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4522
4523 // Hit testing for a point outside the layer should return a null pointer.
4524 gfx::Point test_point(49, 49);
4525 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4526 test_point, render_surface_layer_list);
4527 EXPECT_FALSE(result_layer);
4528
4529 // Even though the layer exists at (101, 101), it should not be visible there
4530 // since the root render surface would clamp it.
4531 test_point = gfx::Point(101, 101);
4532 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4533 test_point, render_surface_layer_list);
4534 EXPECT_FALSE(result_layer);
4535
4536 // Hit testing for a point inside should return the root layer.
4537 test_point = gfx::Point(51, 51);
4538 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4539 test_point, render_surface_layer_list);
4540 ASSERT_TRUE(result_layer);
4541 EXPECT_EQ(12345, result_layer->id());
4542
4543 test_point = gfx::Point(99, 99);
4544 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4545 test_point, render_surface_layer_list);
4546 ASSERT_TRUE(result_layer);
4547 EXPECT_EQ(12345, result_layer->id());
4548}
4549
[email protected]989386c2013-07-18 21:37:234550TEST_F(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324551 FakeImplProxy proxy;
4552 FakeLayerTreeHostImpl host_impl(&proxy);
4553 scoped_ptr<LayerImpl> root =
4554 LayerImpl::Create(host_impl.active_tree(), 12345);
4555
4556 gfx::Transform identity_matrix;
4557 gfx::Transform rotation45_degrees_about_center;
4558 rotation45_degrees_about_center.Translate(50.0, 50.0);
4559 rotation45_degrees_about_center.RotateAboutZAxis(45.0);
4560 rotation45_degrees_about_center.Translate(-50.0, -50.0);
4561 gfx::PointF anchor;
4562 gfx::PointF position;
4563 gfx::Size bounds(100, 100);
4564 SetLayerPropertiesForTesting(root.get(),
4565 rotation45_degrees_about_center,
4566 identity_matrix,
4567 anchor,
4568 position,
4569 bounds,
4570 false);
4571 root->SetDrawsContent(true);
4572
[email protected]50761e92013-03-29 20:51:284573 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534574 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4575 root.get(), root->bounds(), &render_surface_layer_list);
4576 inputs.can_adjust_raster_scales = true;
4577 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324578
4579 // Sanity check the scenario we just created.
4580 ASSERT_EQ(1u, render_surface_layer_list.size());
4581 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4582
4583 // Hit testing for points outside the layer.
4584 // These corners would have been inside the un-transformed layer, but they
4585 // should not hit the correctly transformed layer.
4586 gfx::Point test_point(99, 99);
4587 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4588 test_point, render_surface_layer_list);
4589 EXPECT_FALSE(result_layer);
4590
4591 test_point = gfx::Point(1, 1);
4592 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4593 test_point, render_surface_layer_list);
4594 EXPECT_FALSE(result_layer);
4595
4596 // Hit testing for a point inside should return the root layer.
4597 test_point = gfx::Point(1, 50);
4598 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4599 test_point, render_surface_layer_list);
4600 ASSERT_TRUE(result_layer);
4601 EXPECT_EQ(12345, result_layer->id());
4602
4603 // Hit testing the corners that would overlap the unclipped layer, but are
4604 // outside the clipped region.
4605 test_point = gfx::Point(50, -1);
4606 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4607 test_point, render_surface_layer_list);
4608 ASSERT_FALSE(result_layer);
4609
4610 test_point = gfx::Point(-1, 50);
4611 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4612 test_point, render_surface_layer_list);
4613 ASSERT_FALSE(result_layer);
4614}
4615
[email protected]989386c2013-07-18 21:37:234616TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) {
[email protected]fb661802013-03-25 01:59:324617 FakeImplProxy proxy;
4618 FakeLayerTreeHostImpl host_impl(&proxy);
4619 scoped_ptr<LayerImpl> root =
4620 LayerImpl::Create(host_impl.active_tree(), 12345);
4621
4622 gfx::Transform identity_matrix;
4623
4624 // perspective_projection_about_center * translation_by_z is designed so that
4625 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
4626 gfx::Transform perspective_projection_about_center;
4627 perspective_projection_about_center.Translate(50.0, 50.0);
4628 perspective_projection_about_center.ApplyPerspectiveDepth(1.0);
4629 perspective_projection_about_center.Translate(-50.0, -50.0);
4630 gfx::Transform translation_by_z;
4631 translation_by_z.Translate3d(0.0, 0.0, -1.0);
4632
4633 gfx::PointF anchor;
4634 gfx::PointF position;
4635 gfx::Size bounds(100, 100);
4636 SetLayerPropertiesForTesting(
4637 root.get(),
4638 perspective_projection_about_center * translation_by_z,
4639 identity_matrix,
4640 anchor,
4641 position,
4642 bounds,
4643 false);
4644 root->SetDrawsContent(true);
4645
[email protected]50761e92013-03-29 20:51:284646 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534647 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4648 root.get(), root->bounds(), &render_surface_layer_list);
4649 inputs.can_adjust_raster_scales = true;
4650 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324651
4652 // Sanity check the scenario we just created.
4653 ASSERT_EQ(1u, render_surface_layer_list.size());
4654 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4655
4656 // Hit testing for points outside the layer.
4657 // These corners would have been inside the un-transformed layer, but they
4658 // should not hit the correctly transformed layer.
4659 gfx::Point test_point(24, 24);
4660 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4661 test_point, render_surface_layer_list);
4662 EXPECT_FALSE(result_layer);
4663
4664 test_point = gfx::Point(76, 76);
4665 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4666 test_point, render_surface_layer_list);
4667 EXPECT_FALSE(result_layer);
4668
4669 // Hit testing for a point inside should return the root layer.
4670 test_point = gfx::Point(26, 26);
4671 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4672 test_point, render_surface_layer_list);
4673 ASSERT_TRUE(result_layer);
4674 EXPECT_EQ(12345, result_layer->id());
4675
4676 test_point = gfx::Point(74, 74);
4677 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4678 test_point, render_surface_layer_list);
4679 ASSERT_TRUE(result_layer);
4680 EXPECT_EQ(12345, result_layer->id());
4681}
4682
[email protected]989386c2013-07-18 21:37:234683TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) {
[email protected]fb661802013-03-25 01:59:324684 // A layer's visible content rect is actually in the layer's content space.
4685 // The screen space transform converts from the layer's origin space to screen
4686 // space. This test makes sure that hit testing works correctly accounts for
4687 // the contents scale. A contents scale that is not 1 effectively forces a
4688 // non-identity transform between layer's content space and layer's origin
4689 // space. The hit testing code must take this into account.
4690 //
4691 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
4692 // contents scale is ignored, then hit testing will mis-interpret the visible
4693 // content rect as being larger than the actual bounds of the layer.
4694 //
4695 FakeImplProxy proxy;
4696 FakeLayerTreeHostImpl host_impl(&proxy);
4697 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4698
4699 gfx::Transform identity_matrix;
4700 gfx::PointF anchor;
4701
4702 SetLayerPropertiesForTesting(root.get(),
4703 identity_matrix,
4704 identity_matrix,
4705 anchor,
4706 gfx::PointF(),
4707 gfx::Size(100, 100),
4708 false);
4709 {
4710 gfx::PointF position(25.f, 25.f);
4711 gfx::Size bounds(50, 50);
4712 scoped_ptr<LayerImpl> test_layer =
4713 LayerImpl::Create(host_impl.active_tree(), 12345);
4714 SetLayerPropertiesForTesting(test_layer.get(),
4715 identity_matrix,
4716 identity_matrix,
4717 anchor,
4718 position,
4719 bounds,
4720 false);
4721
4722 // override content bounds and contents scale
4723 test_layer->SetContentBounds(gfx::Size(100, 100));
4724 test_layer->SetContentsScale(2, 2);
4725
4726 test_layer->SetDrawsContent(true);
4727 root->AddChild(test_layer.Pass());
4728 }
4729
[email protected]50761e92013-03-29 20:51:284730 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534731 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4732 root.get(), root->bounds(), &render_surface_layer_list);
4733 inputs.can_adjust_raster_scales = true;
4734 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324735
4736 // Sanity check the scenario we just created.
4737 // The visible content rect for test_layer is actually 100x100, even though
4738 // its layout size is 50x50, positioned at 25x25.
4739 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:054740 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
[email protected]fb661802013-03-25 01:59:324741 test_layer->visible_content_rect());
4742 ASSERT_EQ(1u, render_surface_layer_list.size());
4743 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4744
4745 // Hit testing for a point outside the layer should return a null pointer (the
4746 // root layer does not draw content, so it will not be hit tested either).
4747 gfx::Point test_point(101, 101);
4748 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4749 test_point, render_surface_layer_list);
4750 EXPECT_FALSE(result_layer);
4751
4752 test_point = gfx::Point(24, 24);
4753 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4754 test_point, render_surface_layer_list);
4755 EXPECT_FALSE(result_layer);
4756
4757 test_point = gfx::Point(76, 76);
4758 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4759 test_point, render_surface_layer_list);
4760 EXPECT_FALSE(result_layer);
4761
4762 // Hit testing for a point inside should return the test layer.
4763 test_point = gfx::Point(26, 26);
4764 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4765 test_point, render_surface_layer_list);
4766 ASSERT_TRUE(result_layer);
4767 EXPECT_EQ(12345, result_layer->id());
4768
4769 test_point = gfx::Point(74, 74);
4770 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4771 test_point, render_surface_layer_list);
4772 ASSERT_TRUE(result_layer);
4773 EXPECT_EQ(12345, result_layer->id());
4774}
4775
[email protected]989386c2013-07-18 21:37:234776TEST_F(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) {
[email protected]fb661802013-03-25 01:59:324777 // Test that hit-testing will only work for the visible portion of a layer,
4778 // and not the entire layer bounds. Here we just test the simple axis-aligned
4779 // case.
4780 gfx::Transform identity_matrix;
4781 gfx::PointF anchor;
4782
4783 FakeImplProxy proxy;
4784 FakeLayerTreeHostImpl host_impl(&proxy);
4785 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
4786 SetLayerPropertiesForTesting(root.get(),
4787 identity_matrix,
4788 identity_matrix,
4789 anchor,
4790 gfx::PointF(),
4791 gfx::Size(100, 100),
4792 false);
4793 {
4794 scoped_ptr<LayerImpl> clipping_layer =
4795 LayerImpl::Create(host_impl.active_tree(), 123);
4796 // this layer is positioned, and hit testing should correctly know where the
4797 // layer is located.
[email protected]ca2902e92013-03-28 01:45:354798 gfx::PointF position(25.f, 25.f);
[email protected]fb661802013-03-25 01:59:324799 gfx::Size bounds(50, 50);
4800 SetLayerPropertiesForTesting(clipping_layer.get(),
4801 identity_matrix,
4802 identity_matrix,
4803 anchor,
4804 position,
4805 bounds,
4806 false);
4807 clipping_layer->SetMasksToBounds(true);
4808
4809 scoped_ptr<LayerImpl> child =
4810 LayerImpl::Create(host_impl.active_tree(), 456);
4811 position = gfx::PointF(-50.f, -50.f);
4812 bounds = gfx::Size(300, 300);
4813 SetLayerPropertiesForTesting(child.get(),
4814 identity_matrix,
4815 identity_matrix,
4816 anchor,
4817 position,
4818 bounds,
4819 false);
4820 child->SetDrawsContent(true);
4821 clipping_layer->AddChild(child.Pass());
4822 root->AddChild(clipping_layer.Pass());
4823 }
4824
[email protected]50761e92013-03-29 20:51:284825 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534826 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4827 root.get(), root->bounds(), &render_surface_layer_list);
4828 inputs.can_adjust_raster_scales = true;
4829 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324830
4831 // Sanity check the scenario we just created.
4832 ASSERT_EQ(1u, render_surface_layer_list.size());
4833 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:234834 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324835
4836 // Hit testing for a point outside the layer should return a null pointer.
4837 // Despite the child layer being very large, it should be clipped to the root
4838 // layer's bounds.
4839 gfx::Point test_point(24, 24);
4840 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4841 test_point, render_surface_layer_list);
4842 EXPECT_FALSE(result_layer);
4843
4844 // Even though the layer exists at (101, 101), it should not be visible there
4845 // since the clipping_layer would clamp it.
4846 test_point = gfx::Point(76, 76);
4847 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4848 test_point, render_surface_layer_list);
4849 EXPECT_FALSE(result_layer);
4850
4851 // Hit testing for a point inside should return the child layer.
4852 test_point = gfx::Point(26, 26);
4853 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4854 test_point, render_surface_layer_list);
4855 ASSERT_TRUE(result_layer);
4856 EXPECT_EQ(456, result_layer->id());
4857
4858 test_point = gfx::Point(74, 74);
4859 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4860 test_point, render_surface_layer_list);
4861 ASSERT_TRUE(result_layer);
4862 EXPECT_EQ(456, result_layer->id());
4863}
4864
[email protected]989386c2013-07-18 21:37:234865TEST_F(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) {
[email protected]fb661802013-03-25 01:59:324866 // This test checks whether hit testing correctly avoids hit testing with
4867 // multiple ancestors that clip in non axis-aligned ways. To pass this test,
4868 // the hit testing algorithm needs to recognize that multiple parent layers
4869 // may clip the layer, and should not actually hit those clipped areas.
4870 //
4871 // The child and grand_child layers are both initialized to clip the
4872 // rotated_leaf. The child layer is rotated about the top-left corner, so that
4873 // the root + child clips combined create a triangle. The rotated_leaf will
4874 // only be visible where it overlaps this triangle.
4875 //
4876 FakeImplProxy proxy;
4877 FakeLayerTreeHostImpl host_impl(&proxy);
4878 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123);
4879
4880 gfx::Transform identity_matrix;
4881 gfx::PointF anchor;
4882 gfx::PointF position;
4883 gfx::Size bounds(100, 100);
4884 SetLayerPropertiesForTesting(root.get(),
4885 identity_matrix,
4886 identity_matrix,
4887 anchor,
4888 position,
4889 bounds,
4890 false);
4891 root->SetMasksToBounds(true);
4892 {
4893 scoped_ptr<LayerImpl> child =
4894 LayerImpl::Create(host_impl.active_tree(), 456);
4895 scoped_ptr<LayerImpl> grand_child =
4896 LayerImpl::Create(host_impl.active_tree(), 789);
4897 scoped_ptr<LayerImpl> rotated_leaf =
4898 LayerImpl::Create(host_impl.active_tree(), 2468);
4899
4900 position = gfx::PointF(10.f, 10.f);
4901 bounds = gfx::Size(80, 80);
4902 SetLayerPropertiesForTesting(child.get(),
4903 identity_matrix,
4904 identity_matrix,
4905 anchor,
4906 position,
4907 bounds,
4908 false);
[email protected]7aba6662013-03-12 10:17:344909 child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444910
[email protected]fb661802013-03-25 01:59:324911 gfx::Transform rotation45_degrees_about_corner;
4912 rotation45_degrees_about_corner.RotateAboutZAxis(45.0);
[email protected]aedf4e52013-01-09 23:24:444913
[email protected]fb661802013-03-25 01:59:324914 // remember, positioned with respect to its parent which is already at 10,
4915 // 10
4916 position = gfx::PointF();
4917 bounds =
4918 gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
4919 SetLayerPropertiesForTesting(grand_child.get(),
4920 rotation45_degrees_about_corner,
4921 identity_matrix,
4922 anchor,
4923 position,
4924 bounds,
4925 false);
4926 grand_child->SetMasksToBounds(true);
[email protected]aedf4e52013-01-09 23:24:444927
[email protected]fb661802013-03-25 01:59:324928 // Rotates about the center of the layer
4929 gfx::Transform rotated_leaf_transform;
4930 rotated_leaf_transform.Translate(
4931 -10.0, -10.0); // cancel out the grand_parent's position
4932 rotated_leaf_transform.RotateAboutZAxis(
4933 -45.0); // cancel out the corner 45-degree rotation of the parent.
4934 rotated_leaf_transform.Translate(50.0, 50.0);
4935 rotated_leaf_transform.RotateAboutZAxis(45.0);
4936 rotated_leaf_transform.Translate(-50.0, -50.0);
4937 position = gfx::PointF();
4938 bounds = gfx::Size(100, 100);
4939 SetLayerPropertiesForTesting(rotated_leaf.get(),
4940 rotated_leaf_transform,
4941 identity_matrix,
4942 anchor,
4943 position,
4944 bounds,
4945 false);
4946 rotated_leaf->SetDrawsContent(true);
[email protected]aedf4e52013-01-09 23:24:444947
[email protected]fb661802013-03-25 01:59:324948 grand_child->AddChild(rotated_leaf.Pass());
4949 child->AddChild(grand_child.Pass());
4950 root->AddChild(child.Pass());
4951 }
[email protected]aedf4e52013-01-09 23:24:444952
[email protected]50761e92013-03-29 20:51:284953 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534954 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4955 root.get(), root->bounds(), &render_surface_layer_list);
4956 inputs.can_adjust_raster_scales = true;
4957 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:444958
[email protected]fb661802013-03-25 01:59:324959 // Sanity check the scenario we just created.
4960 // The grand_child is expected to create a render surface because it
[email protected]989386c2013-07-18 21:37:234961 // MasksToBounds and is not axis aligned.
[email protected]fb661802013-03-25 01:59:324962 ASSERT_EQ(2u, render_surface_layer_list.size());
4963 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234964 1u,
4965 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324966 ASSERT_EQ(789,
[email protected]989386c2013-07-18 21:37:234967 render_surface_layer_list.at(0)->render_surface()->layer_list().at(
4968 0)->id()); // grand_child's surface.
[email protected]fb661802013-03-25 01:59:324969 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234970 1u,
4971 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:324972 ASSERT_EQ(
4973 2468,
[email protected]989386c2013-07-18 21:37:234974 render_surface_layer_list[1]->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324975
4976 // (11, 89) is close to the the bottom left corner within the clip, but it is
4977 // not inside the layer.
4978 gfx::Point test_point(11, 89);
4979 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4980 test_point, render_surface_layer_list);
4981 EXPECT_FALSE(result_layer);
4982
4983 // Closer inwards from the bottom left will overlap the layer.
4984 test_point = gfx::Point(25, 75);
4985 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4986 test_point, render_surface_layer_list);
4987 ASSERT_TRUE(result_layer);
4988 EXPECT_EQ(2468, result_layer->id());
4989
4990 // (4, 50) is inside the unclipped layer, but that corner of the layer should
4991 // be clipped away by the grandparent and should not get hit. If hit testing
4992 // blindly uses visible content rect without considering how parent may clip
4993 // the layer, then hit testing would accidentally think that the point
4994 // successfully hits the layer.
4995 test_point = gfx::Point(4, 50);
4996 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
4997 test_point, render_surface_layer_list);
4998 EXPECT_FALSE(result_layer);
4999
5000 // (11, 50) is inside the layer and within the clipped area.
5001 test_point = gfx::Point(11, 50);
5002 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5003 test_point, render_surface_layer_list);
5004 ASSERT_TRUE(result_layer);
5005 EXPECT_EQ(2468, result_layer->id());
5006
5007 // Around the middle, just to the right and up, would have hit the layer
5008 // except that that area should be clipped away by the parent.
5009 test_point = gfx::Point(51, 51);
5010 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5011 test_point, render_surface_layer_list);
5012 EXPECT_FALSE(result_layer);
5013
5014 // Around the middle, just to the left and down, should successfully hit the
5015 // layer.
5016 test_point = gfx::Point(49, 51);
5017 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5018 test_point, render_surface_layer_list);
5019 ASSERT_TRUE(result_layer);
5020 EXPECT_EQ(2468, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:445021}
5022
[email protected]989386c2013-07-18 21:37:235023TEST_F(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:325024 // This test checks that hit testing code does not accidentally clip to layer
5025 // bounds for a layer that actually does not clip.
5026 gfx::Transform identity_matrix;
5027 gfx::PointF anchor;
[email protected]aedf4e52013-01-09 23:24:445028
[email protected]fb661802013-03-25 01:59:325029 FakeImplProxy proxy;
5030 FakeLayerTreeHostImpl host_impl(&proxy);
5031 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5032 SetLayerPropertiesForTesting(root.get(),
5033 identity_matrix,
5034 identity_matrix,
5035 anchor,
5036 gfx::PointF(),
5037 gfx::Size(100, 100),
5038 false);
5039 {
5040 scoped_ptr<LayerImpl> intermediate_layer =
5041 LayerImpl::Create(host_impl.active_tree(), 123);
5042 // this layer is positioned, and hit testing should correctly know where the
5043 // layer is located.
5044 gfx::PointF position(10.f, 10.f);
5045 gfx::Size bounds(50, 50);
5046 SetLayerPropertiesForTesting(intermediate_layer.get(),
5047 identity_matrix,
5048 identity_matrix,
5049 anchor,
5050 position,
5051 bounds,
5052 false);
5053 // Sanity check the intermediate layer should not clip.
5054 ASSERT_FALSE(intermediate_layer->masks_to_bounds());
5055 ASSERT_FALSE(intermediate_layer->mask_layer());
[email protected]aedf4e52013-01-09 23:24:445056
[email protected]fb661802013-03-25 01:59:325057 // The child of the intermediate_layer is translated so that it does not
5058 // overlap intermediate_layer at all. If child is incorrectly clipped, we
5059 // would not be able to hit it successfully.
5060 scoped_ptr<LayerImpl> child =
5061 LayerImpl::Create(host_impl.active_tree(), 456);
5062 position = gfx::PointF(60.f, 60.f); // 70, 70 in screen space
5063 bounds = gfx::Size(20, 20);
5064 SetLayerPropertiesForTesting(child.get(),
5065 identity_matrix,
5066 identity_matrix,
5067 anchor,
5068 position,
5069 bounds,
5070 false);
5071 child->SetDrawsContent(true);
5072 intermediate_layer->AddChild(child.Pass());
5073 root->AddChild(intermediate_layer.Pass());
5074 }
[email protected]aedf4e52013-01-09 23:24:445075
[email protected]50761e92013-03-29 20:51:285076 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535077 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5078 root.get(), root->bounds(), &render_surface_layer_list);
5079 inputs.can_adjust_raster_scales = true;
5080 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]aedf4e52013-01-09 23:24:445081
[email protected]fb661802013-03-25 01:59:325082 // Sanity check the scenario we just created.
5083 ASSERT_EQ(1u, render_surface_layer_list.size());
5084 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235085 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]aedf4e52013-01-09 23:24:445086
[email protected]fb661802013-03-25 01:59:325087 // Hit testing for a point outside the layer should return a null pointer.
5088 gfx::Point test_point(69, 69);
5089 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5090 test_point, render_surface_layer_list);
5091 EXPECT_FALSE(result_layer);
[email protected]aedf4e52013-01-09 23:24:445092
[email protected]fb661802013-03-25 01:59:325093 test_point = gfx::Point(91, 91);
5094 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5095 test_point, render_surface_layer_list);
5096 EXPECT_FALSE(result_layer);
5097
5098 // Hit testing for a point inside should return the child layer.
5099 test_point = gfx::Point(71, 71);
5100 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5101 test_point, render_surface_layer_list);
5102 ASSERT_TRUE(result_layer);
5103 EXPECT_EQ(456, result_layer->id());
5104
5105 test_point = gfx::Point(89, 89);
5106 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5107 test_point, render_surface_layer_list);
5108 ASSERT_TRUE(result_layer);
5109 EXPECT_EQ(456, result_layer->id());
[email protected]aedf4e52013-01-09 23:24:445110}
5111
[email protected]989386c2013-07-18 21:37:235112TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayers) {
[email protected]fb661802013-03-25 01:59:325113 FakeImplProxy proxy;
5114 FakeLayerTreeHostImpl host_impl(&proxy);
5115 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145116
[email protected]fb661802013-03-25 01:59:325117 gfx::Transform identity_matrix;
5118 gfx::PointF anchor;
5119 gfx::PointF position;
5120 gfx::Size bounds(100, 100);
5121 SetLayerPropertiesForTesting(root.get(),
5122 identity_matrix,
5123 identity_matrix,
5124 anchor,
5125 position,
5126 bounds,
5127 false);
5128 root->SetDrawsContent(true);
5129 {
5130 // child 1 and child2 are initialized to overlap between x=50 and x=60.
5131 // grand_child is set to overlap both child1 and child2 between y=50 and
5132 // y=60. The expected stacking order is: (front) child2, (second)
5133 // grand_child, (third) child1, and (back) the root layer behind all other
5134 // layers.
[email protected]ecc12622012-10-30 20:45:425135
[email protected]fb661802013-03-25 01:59:325136 scoped_ptr<LayerImpl> child1 =
5137 LayerImpl::Create(host_impl.active_tree(), 2);
5138 scoped_ptr<LayerImpl> child2 =
5139 LayerImpl::Create(host_impl.active_tree(), 3);
5140 scoped_ptr<LayerImpl> grand_child1 =
5141 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:145142
[email protected]fb661802013-03-25 01:59:325143 position = gfx::PointF(10.f, 10.f);
5144 bounds = gfx::Size(50, 50);
5145 SetLayerPropertiesForTesting(child1.get(),
5146 identity_matrix,
5147 identity_matrix,
5148 anchor,
5149 position,
5150 bounds,
5151 false);
5152 child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145153
[email protected]fb661802013-03-25 01:59:325154 position = gfx::PointF(50.f, 10.f);
5155 bounds = gfx::Size(50, 50);
5156 SetLayerPropertiesForTesting(child2.get(),
5157 identity_matrix,
5158 identity_matrix,
5159 anchor,
5160 position,
5161 bounds,
5162 false);
5163 child2->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145164
[email protected]fb661802013-03-25 01:59:325165 // Remember that grand_child is positioned with respect to its parent (i.e.
5166 // child1). In screen space, the intended position is (10, 50), with size
5167 // 100 x 50.
5168 position = gfx::PointF(0.f, 40.f);
5169 bounds = gfx::Size(100, 50);
5170 SetLayerPropertiesForTesting(grand_child1.get(),
5171 identity_matrix,
5172 identity_matrix,
5173 anchor,
5174 position,
5175 bounds,
5176 false);
5177 grand_child1->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145178
[email protected]fb661802013-03-25 01:59:325179 child1->AddChild(grand_child1.Pass());
5180 root->AddChild(child1.Pass());
5181 root->AddChild(child2.Pass());
5182 }
[email protected]94f206c12012-08-25 00:09:145183
[email protected]fb661802013-03-25 01:59:325184 LayerImpl* child1 = root->children()[0];
5185 LayerImpl* child2 = root->children()[1];
5186 LayerImpl* grand_child1 = child1->children()[0];
5187
[email protected]50761e92013-03-29 20:51:285188 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535189 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5190 root.get(), root->bounds(), &render_surface_layer_list);
5191 inputs.can_adjust_raster_scales = true;
5192 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325193
5194 // Sanity check the scenario we just created.
5195 ASSERT_TRUE(child1);
5196 ASSERT_TRUE(child2);
5197 ASSERT_TRUE(grand_child1);
5198 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:235199
5200 RenderSurfaceImpl* root_render_surface = root->render_surface();
5201 ASSERT_EQ(4u, root_render_surface->layer_list().size());
5202 ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer
5203 ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1
5204 ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1
5205 ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2
[email protected]fb661802013-03-25 01:59:325206
5207 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5208 // the root layer.
5209 gfx::Point test_point = gfx::Point(1, 1);
5210 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5211 test_point, render_surface_layer_list);
5212 ASSERT_TRUE(result_layer);
5213 EXPECT_EQ(1, result_layer->id());
5214
5215 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5216 // on top.
5217 test_point = gfx::Point(15, 15);
5218 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5219 test_point, render_surface_layer_list);
5220 ASSERT_TRUE(result_layer);
5221 EXPECT_EQ(2, result_layer->id());
5222
5223 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5224 test_point = gfx::Point(51, 20);
5225 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5226 test_point, render_surface_layer_list);
5227 ASSERT_TRUE(result_layer);
5228 EXPECT_EQ(3, result_layer->id());
5229
5230 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5231 // top.
5232 test_point = gfx::Point(80, 51);
5233 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5234 test_point, render_surface_layer_list);
5235 ASSERT_TRUE(result_layer);
5236 EXPECT_EQ(3, result_layer->id());
5237
5238 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5239 // of all other layers.
5240 test_point = gfx::Point(51, 51);
5241 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5242 test_point, render_surface_layer_list);
5243 ASSERT_TRUE(result_layer);
5244 EXPECT_EQ(3, result_layer->id());
5245
5246 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5247 // be on top.
5248 test_point = gfx::Point(20, 51);
5249 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5250 test_point, render_surface_layer_list);
5251 ASSERT_TRUE(result_layer);
5252 EXPECT_EQ(4, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145253}
5254
[email protected]989386c2013-07-18 21:37:235255TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) {
[email protected]fb661802013-03-25 01:59:325256 //
5257 // The geometry is set up similarly to the previous case, but
5258 // all layers are forced to be render surfaces now.
5259 //
5260 FakeImplProxy proxy;
5261 FakeLayerTreeHostImpl host_impl(&proxy);
5262 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145263
[email protected]fb661802013-03-25 01:59:325264 gfx::Transform identity_matrix;
5265 gfx::PointF anchor;
5266 gfx::PointF position;
5267 gfx::Size bounds(100, 100);
5268 SetLayerPropertiesForTesting(root.get(),
5269 identity_matrix,
5270 identity_matrix,
5271 anchor,
5272 position,
5273 bounds,
5274 false);
5275 root->SetDrawsContent(true);
5276 {
5277 // child 1 and child2 are initialized to overlap between x=50 and x=60.
5278 // grand_child is set to overlap both child1 and child2 between y=50 and
5279 // y=60. The expected stacking order is: (front) child2, (second)
5280 // grand_child, (third) child1, and (back) the root layer behind all other
5281 // layers.
[email protected]94f206c12012-08-25 00:09:145282
[email protected]fb661802013-03-25 01:59:325283 scoped_ptr<LayerImpl> child1 =
5284 LayerImpl::Create(host_impl.active_tree(), 2);
5285 scoped_ptr<LayerImpl> child2 =
5286 LayerImpl::Create(host_impl.active_tree(), 3);
5287 scoped_ptr<LayerImpl> grand_child1 =
5288 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]94f206c12012-08-25 00:09:145289
[email protected]fb661802013-03-25 01:59:325290 position = gfx::PointF(10.f, 10.f);
5291 bounds = gfx::Size(50, 50);
5292 SetLayerPropertiesForTesting(child1.get(),
5293 identity_matrix,
5294 identity_matrix,
5295 anchor,
5296 position,
5297 bounds,
5298 false);
5299 child1->SetDrawsContent(true);
5300 child1->SetForceRenderSurface(true);
[email protected]ecc12622012-10-30 20:45:425301
[email protected]fb661802013-03-25 01:59:325302 position = gfx::PointF(50.f, 10.f);
5303 bounds = gfx::Size(50, 50);
5304 SetLayerPropertiesForTesting(child2.get(),
5305 identity_matrix,
5306 identity_matrix,
5307 anchor,
5308 position,
5309 bounds,
5310 false);
5311 child2->SetDrawsContent(true);
[email protected]7aba6662013-03-12 10:17:345312 child2->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015313
[email protected]fb661802013-03-25 01:59:325314 // Remember that grand_child is positioned with respect to its parent (i.e.
5315 // child1). In screen space, the intended position is (10, 50), with size
5316 // 100 x 50.
5317 position = gfx::PointF(0.f, 40.f);
5318 bounds = gfx::Size(100, 50);
5319 SetLayerPropertiesForTesting(grand_child1.get(),
5320 identity_matrix,
5321 identity_matrix,
5322 anchor,
5323 position,
5324 bounds,
5325 false);
5326 grand_child1->SetDrawsContent(true);
5327 grand_child1->SetForceRenderSurface(true);
[email protected]dc462d782012-11-21 21:43:015328
[email protected]fb661802013-03-25 01:59:325329 child1->AddChild(grand_child1.Pass());
5330 root->AddChild(child1.Pass());
5331 root->AddChild(child2.Pass());
5332 }
[email protected]dc462d782012-11-21 21:43:015333
[email protected]fb661802013-03-25 01:59:325334 LayerImpl* child1 = root->children()[0];
5335 LayerImpl* child2 = root->children()[1];
5336 LayerImpl* grand_child1 = child1->children()[0];
[email protected]dc462d782012-11-21 21:43:015337
[email protected]50761e92013-03-29 20:51:285338 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535339 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5340 root.get(), root->bounds(), &render_surface_layer_list);
5341 inputs.can_adjust_raster_scales = true;
5342 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]dc462d782012-11-21 21:43:015343
[email protected]fb661802013-03-25 01:59:325344 // Sanity check the scenario we just created.
5345 ASSERT_TRUE(child1);
5346 ASSERT_TRUE(child2);
5347 ASSERT_TRUE(grand_child1);
5348 ASSERT_TRUE(child1->render_surface());
5349 ASSERT_TRUE(child2->render_surface());
5350 ASSERT_TRUE(grand_child1->render_surface());
5351 ASSERT_EQ(4u, render_surface_layer_list.size());
5352 // The root surface has the root layer, and child1's and child2's render
5353 // surfaces.
5354 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
5355 // The child1 surface has the child1 layer and grand_child1's render surface.
5356 ASSERT_EQ(2u, child1->render_surface()->layer_list().size());
5357 ASSERT_EQ(1u, child2->render_surface()->layer_list().size());
5358 ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235359 ASSERT_EQ(1, render_surface_layer_list.at(0)->id()); // root layer
[email protected]fb661802013-03-25 01:59:325360 ASSERT_EQ(2, render_surface_layer_list[1]->id()); // child1
[email protected]989386c2013-07-18 21:37:235361 ASSERT_EQ(4, render_surface_layer_list.at(2)->id()); // grand_child1
[email protected]fb661802013-03-25 01:59:325362 ASSERT_EQ(3, render_surface_layer_list[3]->id()); // child2
[email protected]dc462d782012-11-21 21:43:015363
[email protected]fb661802013-03-25 01:59:325364 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
5365 // the root layer.
5366 gfx::Point test_point = gfx::Point(1, 1);
5367 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5368 test_point, render_surface_layer_list);
5369 ASSERT_TRUE(result_layer);
5370 EXPECT_EQ(1, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015371
[email protected]fb661802013-03-25 01:59:325372 // At (15, 15), child1 and root are the only layers. child1 is expected to be
5373 // on top.
5374 test_point = gfx::Point(15, 15);
5375 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5376 test_point, render_surface_layer_list);
5377 ASSERT_TRUE(result_layer);
5378 EXPECT_EQ(2, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015379
[email protected]fb661802013-03-25 01:59:325380 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
5381 test_point = gfx::Point(51, 20);
5382 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5383 test_point, render_surface_layer_list);
5384 ASSERT_TRUE(result_layer);
5385 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015386
[email protected]fb661802013-03-25 01:59:325387 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
5388 // top.
5389 test_point = gfx::Point(80, 51);
5390 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5391 test_point, render_surface_layer_list);
5392 ASSERT_TRUE(result_layer);
5393 EXPECT_EQ(3, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015394
[email protected]fb661802013-03-25 01:59:325395 // At (51, 51), all layers overlap each other. child2 is expected to be on top
5396 // of all other layers.
5397 test_point = gfx::Point(51, 51);
5398 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5399 test_point, render_surface_layer_list);
5400 ASSERT_TRUE(result_layer);
5401 EXPECT_EQ(3, result_layer->id());
5402
5403 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
5404 // be on top.
5405 test_point = gfx::Point(20, 51);
5406 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5407 test_point, render_surface_layer_list);
5408 ASSERT_TRUE(result_layer);
5409 EXPECT_EQ(4, result_layer->id());
[email protected]dc462d782012-11-21 21:43:015410}
5411
[email protected]989386c2013-07-18 21:37:235412TEST_F(LayerTreeHostCommonTest,
5413 HitCheckingTouchHandlerRegionsForEmptyLayerList) {
[email protected]fb661802013-03-25 01:59:325414 // Hit checking on an empty render_surface_layer_list should return a null
5415 // pointer.
[email protected]50761e92013-03-29 20:51:285416 LayerImplList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145417
[email protected]fb661802013-03-25 01:59:325418 gfx::Point test_point(0, 0);
5419 LayerImpl* result_layer =
5420 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5421 test_point, render_surface_layer_list);
5422 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145423
[email protected]fb661802013-03-25 01:59:325424 test_point = gfx::Point(10, 20);
5425 result_layer =
5426 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5427 test_point, render_surface_layer_list);
5428 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145429}
5430
[email protected]989386c2013-07-18 21:37:235431TEST_F(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:325432 FakeImplProxy proxy;
5433 FakeLayerTreeHostImpl host_impl(&proxy);
5434 scoped_ptr<LayerImpl> root =
5435 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145436
[email protected]fb661802013-03-25 01:59:325437 gfx::Transform identity_matrix;
5438 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5439 gfx::PointF anchor;
5440 gfx::PointF position;
5441 gfx::Size bounds(100, 100);
5442 SetLayerPropertiesForTesting(root.get(),
5443 identity_matrix,
5444 identity_matrix,
5445 anchor,
5446 position,
5447 bounds,
5448 false);
5449 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:145450
[email protected]50761e92013-03-29 20:51:285451 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535452 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5453 root.get(), root->bounds(), &render_surface_layer_list);
5454 inputs.can_adjust_raster_scales = true;
5455 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145456
[email protected]fb661802013-03-25 01:59:325457 // Sanity check the scenario we just created.
5458 ASSERT_EQ(1u, render_surface_layer_list.size());
5459 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145460
[email protected]fb661802013-03-25 01:59:325461 // Hit checking for any point should return a null pointer for a layer without
5462 // any touch event handler regions.
5463 gfx::Point test_point(11, 11);
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 root->SetTouchEventHandlerRegion(touch_handler_region);
5470 // Hit checking for a point outside the layer should return a null pointer.
5471 test_point = gfx::Point(101, 101);
5472 result_layer =
5473 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5474 test_point, render_surface_layer_list);
5475 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145476
[email protected]fb661802013-03-25 01:59:325477 test_point = gfx::Point(-1, -1);
5478 result_layer =
5479 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5480 test_point, render_surface_layer_list);
5481 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145482
[email protected]fb661802013-03-25 01:59:325483 // Hit checking for a point inside the layer, but outside the touch handler
5484 // region should return a null pointer.
5485 test_point = gfx::Point(1, 1);
5486 result_layer =
5487 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5488 test_point, render_surface_layer_list);
5489 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145490
[email protected]fb661802013-03-25 01:59:325491 test_point = gfx::Point(99, 99);
5492 result_layer =
5493 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5494 test_point, render_surface_layer_list);
5495 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145496
[email protected]fb661802013-03-25 01:59:325497 // Hit checking for a point inside the touch event handler region should
5498 // return the root layer.
5499 test_point = gfx::Point(11, 11);
5500 result_layer =
5501 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5502 test_point, render_surface_layer_list);
5503 ASSERT_TRUE(result_layer);
5504 EXPECT_EQ(12345, result_layer->id());
5505
5506 test_point = gfx::Point(59, 59);
5507 result_layer =
5508 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5509 test_point, render_surface_layer_list);
5510 ASSERT_TRUE(result_layer);
5511 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145512}
5513
[email protected]989386c2013-07-18 21:37:235514TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325515 HitCheckingTouchHandlerRegionsForUninvertibleTransform) {
5516 FakeImplProxy proxy;
5517 FakeLayerTreeHostImpl host_impl(&proxy);
5518 scoped_ptr<LayerImpl> root =
5519 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145520
[email protected]fb661802013-03-25 01:59:325521 gfx::Transform uninvertible_transform;
5522 uninvertible_transform.matrix().setDouble(0, 0, 0.0);
5523 uninvertible_transform.matrix().setDouble(1, 1, 0.0);
5524 uninvertible_transform.matrix().setDouble(2, 2, 0.0);
5525 uninvertible_transform.matrix().setDouble(3, 3, 0.0);
5526 ASSERT_FALSE(uninvertible_transform.IsInvertible());
[email protected]94f206c12012-08-25 00:09:145527
[email protected]fb661802013-03-25 01:59:325528 gfx::Transform identity_matrix;
5529 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5530 gfx::PointF anchor;
5531 gfx::PointF position;
5532 gfx::Size bounds(100, 100);
5533 SetLayerPropertiesForTesting(root.get(),
5534 uninvertible_transform,
5535 identity_matrix,
5536 anchor,
5537 position,
5538 bounds,
5539 false);
5540 root->SetDrawsContent(true);
5541 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145542
[email protected]50761e92013-03-29 20:51:285543 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535544 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5545 root.get(), root->bounds(), &render_surface_layer_list);
5546 inputs.can_adjust_raster_scales = true;
5547 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145548
[email protected]fb661802013-03-25 01:59:325549 // Sanity check the scenario we just created.
5550 ASSERT_EQ(1u, render_surface_layer_list.size());
5551 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5552 ASSERT_FALSE(root->screen_space_transform().IsInvertible());
[email protected]de4afb5e2012-12-20 00:11:345553
[email protected]fb661802013-03-25 01:59:325554 // Hit checking any point should not hit the touch handler region on the
5555 // layer. If the invertible matrix is accidentally ignored and treated like an
5556 // identity, then the hit testing will incorrectly hit the layer when it
5557 // shouldn't.
5558 gfx::Point test_point(1, 1);
5559 LayerImpl* result_layer =
5560 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5561 test_point, render_surface_layer_list);
5562 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345563
[email protected]fb661802013-03-25 01:59:325564 test_point = gfx::Point(10, 10);
5565 result_layer =
5566 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5567 test_point, render_surface_layer_list);
5568 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345569
[email protected]fb661802013-03-25 01:59:325570 test_point = gfx::Point(10, 30);
5571 result_layer =
5572 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5573 test_point, render_surface_layer_list);
5574 EXPECT_FALSE(result_layer);
[email protected]de4afb5e2012-12-20 00:11:345575
[email protected]fb661802013-03-25 01:59:325576 test_point = gfx::Point(50, 50);
5577 result_layer =
5578 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5579 test_point, render_surface_layer_list);
5580 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145581
[email protected]fb661802013-03-25 01:59:325582 test_point = gfx::Point(67, 48);
5583 result_layer =
5584 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5585 test_point, render_surface_layer_list);
5586 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145587
[email protected]fb661802013-03-25 01:59:325588 test_point = gfx::Point(99, 99);
5589 result_layer =
5590 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5591 test_point, render_surface_layer_list);
5592 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145593
[email protected]fb661802013-03-25 01:59:325594 test_point = gfx::Point(-1, -1);
5595 result_layer =
5596 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5597 test_point, render_surface_layer_list);
5598 EXPECT_FALSE(result_layer);
[email protected]94f206c12012-08-25 00:09:145599}
5600
[email protected]989386c2013-07-18 21:37:235601TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325602 HitCheckingTouchHandlerRegionsForSinglePositionedLayer) {
5603 FakeImplProxy proxy;
5604 FakeLayerTreeHostImpl host_impl(&proxy);
5605 scoped_ptr<LayerImpl> root =
5606 LayerImpl::Create(host_impl.active_tree(), 12345);
[email protected]94f206c12012-08-25 00:09:145607
[email protected]fb661802013-03-25 01:59:325608 gfx::Transform identity_matrix;
5609 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5610 gfx::PointF anchor;
5611 // this layer is positioned, and hit testing should correctly know where the
5612 // layer is located.
5613 gfx::PointF position(50.f, 50.f);
5614 gfx::Size bounds(100, 100);
5615 SetLayerPropertiesForTesting(root.get(),
5616 identity_matrix,
5617 identity_matrix,
5618 anchor,
5619 position,
5620 bounds,
5621 false);
5622 root->SetDrawsContent(true);
5623 root->SetTouchEventHandlerRegion(touch_handler_region);
[email protected]94f206c12012-08-25 00:09:145624
[email protected]50761e92013-03-29 20:51:285625 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535626 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5627 root.get(), root->bounds(), &render_surface_layer_list);
5628 inputs.can_adjust_raster_scales = true;
5629 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145630
[email protected]fb661802013-03-25 01:59:325631 // Sanity check the scenario we just created.
5632 ASSERT_EQ(1u, render_surface_layer_list.size());
5633 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145634
[email protected]fb661802013-03-25 01:59:325635 // Hit checking for a point outside the layer should return a null pointer.
5636 gfx::Point test_point(49, 49);
5637 LayerImpl* result_layer =
5638 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5639 test_point, render_surface_layer_list);
5640 EXPECT_FALSE(result_layer);
5641
5642 // Even though the layer has a touch handler region containing (101, 101), it
5643 // should not be visible there since the root render surface would clamp it.
5644 test_point = gfx::Point(101, 101);
5645 result_layer =
5646 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5647 test_point, render_surface_layer_list);
5648 EXPECT_FALSE(result_layer);
5649
5650 // Hit checking for a point inside the layer, but outside the touch handler
5651 // region should return a null pointer.
5652 test_point = gfx::Point(51, 51);
5653 result_layer =
5654 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5655 test_point, render_surface_layer_list);
5656 EXPECT_FALSE(result_layer);
5657
5658 // Hit checking for a point inside the touch event handler region should
5659 // return the root layer.
5660 test_point = gfx::Point(61, 61);
5661 result_layer =
5662 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5663 test_point, render_surface_layer_list);
5664 ASSERT_TRUE(result_layer);
5665 EXPECT_EQ(12345, result_layer->id());
5666
5667 test_point = gfx::Point(99, 99);
5668 result_layer =
5669 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5670 test_point, render_surface_layer_list);
5671 ASSERT_TRUE(result_layer);
5672 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145673}
5674
[email protected]989386c2013-07-18 21:37:235675TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325676 HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) {
5677 // A layer's visible content rect is actually in the layer's content space.
5678 // The screen space transform converts from the layer's origin space to screen
5679 // space. This test makes sure that hit testing works correctly accounts for
5680 // the contents scale. A contents scale that is not 1 effectively forces a
5681 // non-identity transform between layer's content space and layer's origin
5682 // space. The hit testing code must take this into account.
5683 //
5684 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
5685 // contents scale is ignored, then hit checking will mis-interpret the visible
5686 // content rect as being larger than the actual bounds of the layer.
5687 //
5688 FakeImplProxy proxy;
5689 FakeLayerTreeHostImpl host_impl(&proxy);
5690 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145691
[email protected]fb661802013-03-25 01:59:325692 gfx::Transform identity_matrix;
5693 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145694
[email protected]fb661802013-03-25 01:59:325695 SetLayerPropertiesForTesting(root.get(),
5696 identity_matrix,
5697 identity_matrix,
5698 anchor,
5699 gfx::PointF(),
5700 gfx::Size(100, 100),
5701 false);
5702 {
5703 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5704 gfx::PointF position(25.f, 25.f);
5705 gfx::Size bounds(50, 50);
5706 scoped_ptr<LayerImpl> test_layer =
5707 LayerImpl::Create(host_impl.active_tree(), 12345);
5708 SetLayerPropertiesForTesting(test_layer.get(),
5709 identity_matrix,
5710 identity_matrix,
5711 anchor,
5712 position,
5713 bounds,
5714 false);
[email protected]94f206c12012-08-25 00:09:145715
[email protected]fb661802013-03-25 01:59:325716 // override content bounds and contents scale
5717 test_layer->SetContentBounds(gfx::Size(100, 100));
5718 test_layer->SetContentsScale(2, 2);
[email protected]94f206c12012-08-25 00:09:145719
[email protected]fb661802013-03-25 01:59:325720 test_layer->SetDrawsContent(true);
5721 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5722 root->AddChild(test_layer.Pass());
5723 }
5724
[email protected]50761e92013-03-29 20:51:285725 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535726 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5727 root.get(), root->bounds(), &render_surface_layer_list);
5728 inputs.can_adjust_raster_scales = true;
5729 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325730
5731 // Sanity check the scenario we just created.
5732 // The visible content rect for test_layer is actually 100x100, even though
5733 // its layout size is 50x50, positioned at 25x25.
5734 LayerImpl* test_layer = root->children()[0];
[email protected]2c7c6702013-03-26 03:14:055735 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect());
[email protected]fb661802013-03-25 01:59:325736 ASSERT_EQ(1u, render_surface_layer_list.size());
5737 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5738
5739 // Hit checking for a point outside the layer should return a null pointer
5740 // (the root layer does not draw content, so it will not be tested either).
5741 gfx::Point test_point(76, 76);
5742 LayerImpl* result_layer =
5743 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5744 test_point, render_surface_layer_list);
5745 EXPECT_FALSE(result_layer);
5746
5747 // Hit checking for a point inside the layer, but outside the touch handler
5748 // region should return a null pointer.
5749 test_point = gfx::Point(26, 26);
5750 result_layer =
5751 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5752 test_point, render_surface_layer_list);
5753 EXPECT_FALSE(result_layer);
5754
5755 test_point = gfx::Point(34, 34);
5756 result_layer =
5757 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5758 test_point, render_surface_layer_list);
5759 EXPECT_FALSE(result_layer);
5760
5761 test_point = gfx::Point(65, 65);
5762 result_layer =
5763 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5764 test_point, render_surface_layer_list);
5765 EXPECT_FALSE(result_layer);
5766
5767 test_point = gfx::Point(74, 74);
5768 result_layer =
5769 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5770 test_point, render_surface_layer_list);
5771 EXPECT_FALSE(result_layer);
5772
5773 // Hit checking for a point inside the touch event handler region should
5774 // return the root layer.
5775 test_point = gfx::Point(35, 35);
5776 result_layer =
5777 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5778 test_point, render_surface_layer_list);
5779 ASSERT_TRUE(result_layer);
5780 EXPECT_EQ(12345, result_layer->id());
5781
5782 test_point = gfx::Point(64, 64);
5783 result_layer =
5784 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5785 test_point, render_surface_layer_list);
5786 ASSERT_TRUE(result_layer);
5787 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145788}
5789
[email protected]989386c2013-07-18 21:37:235790TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325791 HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) {
5792 // The layer's device_scale_factor and page_scale_factor should scale the
5793 // content rect and we should be able to hit the touch handler region by
5794 // scaling the points accordingly.
5795 FakeImplProxy proxy;
5796 FakeLayerTreeHostImpl host_impl(&proxy);
5797 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]94f206c12012-08-25 00:09:145798
[email protected]fb661802013-03-25 01:59:325799 gfx::Transform identity_matrix;
5800 gfx::PointF anchor;
5801 // Set the bounds of the root layer big enough to fit the child when scaled.
5802 SetLayerPropertiesForTesting(root.get(),
5803 identity_matrix,
5804 identity_matrix,
5805 anchor,
5806 gfx::PointF(),
5807 gfx::Size(100, 100),
5808 false);
5809 {
5810 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
5811 gfx::PointF position(25.f, 25.f);
5812 gfx::Size bounds(50, 50);
5813 scoped_ptr<LayerImpl> test_layer =
5814 LayerImpl::Create(host_impl.active_tree(), 12345);
5815 SetLayerPropertiesForTesting(test_layer.get(),
5816 identity_matrix,
5817 identity_matrix,
5818 anchor,
5819 position,
5820 bounds,
5821 false);
[email protected]94f206c12012-08-25 00:09:145822
[email protected]fb661802013-03-25 01:59:325823 test_layer->SetDrawsContent(true);
5824 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
5825 root->AddChild(test_layer.Pass());
5826 }
[email protected]94f206c12012-08-25 00:09:145827
[email protected]50761e92013-03-29 20:51:285828 LayerImplList render_surface_layer_list;
[email protected]fb661802013-03-25 01:59:325829 float device_scale_factor = 3.f;
5830 float page_scale_factor = 5.f;
[email protected]fb661802013-03-25 01:59:325831 gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize(
5832 gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor));
[email protected]7aad55f2013-07-26 11:25:535833
5834 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5835 root.get(), scaled_bounds_for_root, &render_surface_layer_list);
5836 inputs.device_scale_factor = device_scale_factor;
5837 inputs.page_scale_factor = page_scale_factor;
5838 inputs.page_scale_application_layer = root.get();
5839 inputs.can_adjust_raster_scales = true;
5840 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145841
[email protected]fb661802013-03-25 01:59:325842 // Sanity check the scenario we just created.
5843 // The visible content rect for test_layer is actually 100x100, even though
5844 // its layout size is 50x50, positioned at 25x25.
5845 LayerImpl* test_layer = root->children()[0];
5846 ASSERT_EQ(1u, render_surface_layer_list.size());
5847 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]94f206c12012-08-25 00:09:145848
[email protected]fb661802013-03-25 01:59:325849 // Check whether the child layer fits into the root after scaled.
5850 EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()),
5851 test_layer->visible_content_rect());
5852
5853 // Hit checking for a point outside the layer should return a null pointer
5854 // (the root layer does not draw content, so it will not be tested either).
5855 gfx::PointF test_point(76.f, 76.f);
5856 test_point =
5857 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5858 LayerImpl* result_layer =
5859 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5860 test_point, render_surface_layer_list);
5861 EXPECT_FALSE(result_layer);
5862
5863 // Hit checking for a point inside the layer, but outside the touch handler
5864 // region should return a null pointer.
5865 test_point = gfx::Point(26, 26);
5866 test_point =
5867 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5868 result_layer =
5869 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5870 test_point, render_surface_layer_list);
5871 EXPECT_FALSE(result_layer);
5872
5873 test_point = gfx::Point(34, 34);
5874 test_point =
5875 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5876 result_layer =
5877 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5878 test_point, render_surface_layer_list);
5879 EXPECT_FALSE(result_layer);
5880
5881 test_point = gfx::Point(65, 65);
5882 test_point =
5883 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5884 result_layer =
5885 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5886 test_point, render_surface_layer_list);
5887 EXPECT_FALSE(result_layer);
5888
5889 test_point = gfx::Point(74, 74);
5890 test_point =
5891 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5892 result_layer =
5893 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5894 test_point, render_surface_layer_list);
5895 EXPECT_FALSE(result_layer);
5896
5897 // Hit checking for a point inside the touch event handler region should
5898 // return the root layer.
5899 test_point = gfx::Point(35, 35);
5900 test_point =
5901 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5902 result_layer =
5903 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5904 test_point, render_surface_layer_list);
5905 ASSERT_TRUE(result_layer);
5906 EXPECT_EQ(12345, result_layer->id());
5907
5908 test_point = gfx::Point(64, 64);
5909 test_point =
5910 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
5911 result_layer =
5912 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5913 test_point, render_surface_layer_list);
5914 ASSERT_TRUE(result_layer);
5915 EXPECT_EQ(12345, result_layer->id());
[email protected]94f206c12012-08-25 00:09:145916}
5917
[email protected]989386c2013-07-18 21:37:235918TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325919 HitCheckingTouchHandlerRegionsForSimpleClippedLayer) {
5920 // Test that hit-checking will only work for the visible portion of a layer,
5921 // and not the entire layer bounds. Here we just test the simple axis-aligned
5922 // case.
5923 gfx::Transform identity_matrix;
5924 gfx::PointF anchor;
[email protected]94f206c12012-08-25 00:09:145925
[email protected]fb661802013-03-25 01:59:325926 FakeImplProxy proxy;
5927 FakeLayerTreeHostImpl host_impl(&proxy);
5928 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5929 SetLayerPropertiesForTesting(root.get(),
5930 identity_matrix,
5931 identity_matrix,
5932 anchor,
5933 gfx::PointF(),
5934 gfx::Size(100, 100),
5935 false);
5936 {
5937 scoped_ptr<LayerImpl> clipping_layer =
5938 LayerImpl::Create(host_impl.active_tree(), 123);
5939 // this layer is positioned, and hit testing should correctly know where the
5940 // layer is located.
5941 gfx::PointF position(25.f, 25.f);
5942 gfx::Size bounds(50, 50);
5943 SetLayerPropertiesForTesting(clipping_layer.get(),
5944 identity_matrix,
5945 identity_matrix,
5946 anchor,
5947 position,
5948 bounds,
5949 false);
5950 clipping_layer->SetMasksToBounds(true);
[email protected]94f206c12012-08-25 00:09:145951
[email protected]fb661802013-03-25 01:59:325952 scoped_ptr<LayerImpl> child =
5953 LayerImpl::Create(host_impl.active_tree(), 456);
5954 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5955 position = gfx::PointF(-50.f, -50.f);
5956 bounds = gfx::Size(300, 300);
5957 SetLayerPropertiesForTesting(child.get(),
5958 identity_matrix,
5959 identity_matrix,
5960 anchor,
5961 position,
5962 bounds,
5963 false);
5964 child->SetDrawsContent(true);
5965 child->SetTouchEventHandlerRegion(touch_handler_region);
5966 clipping_layer->AddChild(child.Pass());
5967 root->AddChild(clipping_layer.Pass());
5968 }
[email protected]94f206c12012-08-25 00:09:145969
[email protected]50761e92013-03-29 20:51:285970 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535971 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5972 root.get(), root->bounds(), &render_surface_layer_list);
5973 inputs.can_adjust_raster_scales = true;
5974 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:325975
5976 // Sanity check the scenario we just created.
5977 ASSERT_EQ(1u, render_surface_layer_list.size());
5978 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235979 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:325980
5981 // Hit checking for a point outside the layer should return a null pointer.
5982 // Despite the child layer being very large, it should be clipped to the root
5983 // layer's bounds.
5984 gfx::Point test_point(24, 24);
5985 LayerImpl* result_layer =
5986 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5987 test_point, render_surface_layer_list);
5988 EXPECT_FALSE(result_layer);
5989
5990 // Hit checking for a point inside the layer, but outside the touch handler
5991 // region should return a null pointer.
5992 test_point = gfx::Point(35, 35);
5993 result_layer =
5994 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
5995 test_point, render_surface_layer_list);
5996 EXPECT_FALSE(result_layer);
5997
5998 test_point = gfx::Point(74, 74);
5999 result_layer =
6000 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6001 test_point, render_surface_layer_list);
6002 EXPECT_FALSE(result_layer);
6003
6004 // Hit checking for a point inside the touch event handler region should
6005 // return the root layer.
6006 test_point = gfx::Point(25, 25);
6007 result_layer =
6008 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6009 test_point, render_surface_layer_list);
6010 ASSERT_TRUE(result_layer);
6011 EXPECT_EQ(456, result_layer->id());
6012
6013 test_point = gfx::Point(34, 34);
6014 result_layer =
6015 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6016 test_point, render_surface_layer_list);
6017 ASSERT_TRUE(result_layer);
6018 EXPECT_EQ(456, result_layer->id());
[email protected]94f206c12012-08-25 00:09:146019}
6020
[email protected]fb661802013-03-25 01:59:326021class NoScaleContentLayer : public ContentLayer {
6022 public:
6023 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
6024 return make_scoped_refptr(new NoScaleContentLayer(client));
6025 }
[email protected]94f206c12012-08-25 00:09:146026
[email protected]fb661802013-03-25 01:59:326027 virtual void CalculateContentsScale(float ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066028 float device_scale_factor,
6029 float page_scale_factor,
[email protected]fb661802013-03-25 01:59:326030 bool animating_transform_to_screen,
6031 float* contents_scale_x,
6032 float* contents_scale_y,
6033 gfx::Size* content_bounds) OVERRIDE {
6034 // Skip over the ContentLayer to the base Layer class.
6035 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]b673495c2013-05-07 17:16:066036 device_scale_factor,
6037 page_scale_factor,
[email protected]fb661802013-03-25 01:59:326038 animating_transform_to_screen,
6039 contents_scale_x,
6040 contents_scale_y,
6041 content_bounds);
6042 }
[email protected]94f206c12012-08-25 00:09:146043
[email protected]fb661802013-03-25 01:59:326044 protected:
6045 explicit NoScaleContentLayer(ContentLayerClient* client)
6046 : ContentLayer(client) {}
6047 virtual ~NoScaleContentLayer() {}
[email protected]518ee582012-10-24 18:29:446048};
6049
[email protected]fb661802013-03-25 01:59:326050scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
6051 ContentLayerClient* delegate) {
6052 scoped_refptr<NoScaleContentLayer> to_return =
6053 NoScaleContentLayer::Create(delegate);
6054 to_return->SetIsDrawable(true);
6055 return to_return;
[email protected]518ee582012-10-24 18:29:446056}
6057
[email protected]989386c2013-07-18 21:37:236058TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326059 // Verify draw and screen space transforms of layers not in a surface.
6060 MockContentLayerClient delegate;
6061 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:146062
[email protected]fb661802013-03-25 01:59:326063 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6064 SetLayerPropertiesForTesting(parent.get(),
6065 identity_matrix,
6066 identity_matrix,
6067 gfx::PointF(),
6068 gfx::PointF(),
6069 gfx::Size(100, 100),
6070 true);
[email protected]94f206c12012-08-25 00:09:146071
[email protected]fb661802013-03-25 01:59:326072 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6073 SetLayerPropertiesForTesting(child.get(),
6074 identity_matrix,
6075 identity_matrix,
6076 gfx::PointF(),
6077 gfx::PointF(2.f, 2.f),
6078 gfx::Size(10, 10),
6079 true);
[email protected]94f206c12012-08-25 00:09:146080
[email protected]fb661802013-03-25 01:59:326081 scoped_refptr<ContentLayer> child_empty =
6082 CreateDrawableContentLayer(&delegate);
6083 SetLayerPropertiesForTesting(child_empty.get(),
6084 identity_matrix,
6085 identity_matrix,
6086 gfx::PointF(),
6087 gfx::PointF(2.f, 2.f),
6088 gfx::Size(),
6089 true);
[email protected]f89f5632012-11-14 23:34:456090
[email protected]fb661802013-03-25 01:59:326091 scoped_refptr<NoScaleContentLayer> child_no_scale =
6092 CreateNoScaleDrawableContentLayer(&delegate);
6093 SetLayerPropertiesForTesting(child_no_scale.get(),
6094 identity_matrix,
6095 identity_matrix,
6096 gfx::PointF(),
6097 gfx::PointF(2.f, 2.f),
6098 gfx::Size(10, 10),
6099 true);
[email protected]94f206c12012-08-25 00:09:146100
[email protected]fb661802013-03-25 01:59:326101 parent->AddChild(child);
6102 parent->AddChild(child_empty);
6103 parent->AddChild(child_no_scale);
[email protected]94f206c12012-08-25 00:09:146104
[email protected]d600df7d2013-08-03 02:34:286105 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6106 host->SetRootLayer(parent);
6107
[email protected]fb661802013-03-25 01:59:326108 float device_scale_factor = 2.5f;
6109 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:146110
[email protected]7aad55f2013-07-26 11:25:536111 RenderSurfaceLayerList render_surface_layer_list;
6112 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6113 parent.get(), parent->bounds(), &render_surface_layer_list);
6114 inputs.device_scale_factor = device_scale_factor;
6115 inputs.page_scale_factor = page_scale_factor;
6116 inputs.can_adjust_raster_scales = true;
6117 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446118
[email protected]fb661802013-03-25 01:59:326119 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6120 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6121 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6122 child_empty);
6123 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]94f206c12012-08-25 00:09:146124
[email protected]fb661802013-03-25 01:59:326125 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:146126
[email protected]fb661802013-03-25 01:59:326127 // Verify parent transforms
6128 gfx::Transform expected_parent_transform;
6129 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6130 parent->screen_space_transform());
6131 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6132 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:146133
[email protected]fb661802013-03-25 01:59:326134 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056135 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:146136
[email protected]fb661802013-03-25 01:59:326137 gfx::RectF parent_draw_rect =
6138 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6139 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6140 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:146141
[email protected]2c7c6702013-03-26 03:14:056142 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326143 expected_parent_draw_rect.Scale(device_scale_factor);
6144 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6145 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146146
[email protected]fb661802013-03-25 01:59:326147 // Verify child and child_empty transforms. They should match.
6148 gfx::Transform expected_child_transform;
6149 expected_child_transform.Translate(
6150 device_scale_factor * child->position().x(),
6151 device_scale_factor * child->position().y());
6152 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6153 child->draw_transform());
6154 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6155 child->screen_space_transform());
6156 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6157 child_empty->draw_transform());
6158 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6159 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146160
[email protected]fb661802013-03-25 01:59:326161 // Verify results of transformed child and child_empty rects. They should
6162 // match.
[email protected]2c7c6702013-03-26 03:14:056163 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:146164
[email protected]fb661802013-03-25 01:59:326165 gfx::RectF child_draw_rect =
6166 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6167 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6168 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:146169
[email protected]fb661802013-03-25 01:59:326170 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
6171 child_empty->draw_transform(), child_content_bounds);
6172 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
6173 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:456174
[email protected]fb661802013-03-25 01:59:326175 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
6176 expected_child_draw_rect.Scale(device_scale_factor);
6177 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6178 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
6179 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
6180 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:146181
[email protected]fb661802013-03-25 01:59:326182 // Verify child_no_scale transforms
6183 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6184 // All transforms operate on content rects. The child's content rect
6185 // incorporates device scale, but the child_no_scale does not; add it here.
6186 expected_child_no_scale_transform.Scale(device_scale_factor,
6187 device_scale_factor);
6188 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6189 child_no_scale->draw_transform());
6190 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6191 child_no_scale->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:146192}
6193
[email protected]989386c2013-07-18 21:37:236194TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:326195 // Verify draw and screen space transforms of layers in a surface.
6196 MockContentLayerClient delegate;
6197 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:096198
[email protected]fb661802013-03-25 01:59:326199 gfx::Transform perspective_matrix;
6200 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:096201
[email protected]fb661802013-03-25 01:59:326202 gfx::Transform scale_small_matrix;
6203 scale_small_matrix.Scale(1.0 / 10.0, 1.0 / 12.0);
[email protected]1b30e8e2012-12-21 02:59:096204
[email protected]9781afa2013-07-17 23:15:326205 scoped_refptr<Layer> root = Layer::Create();
6206
[email protected]fb661802013-03-25 01:59:326207 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6208 SetLayerPropertiesForTesting(parent.get(),
6209 identity_matrix,
6210 identity_matrix,
6211 gfx::PointF(),
6212 gfx::PointF(),
6213 gfx::Size(100, 100),
6214 true);
[email protected]1b30e8e2012-12-21 02:59:096215
[email protected]fb661802013-03-25 01:59:326216 scoped_refptr<ContentLayer> perspective_surface =
6217 CreateDrawableContentLayer(&delegate);
6218 SetLayerPropertiesForTesting(perspective_surface.get(),
6219 perspective_matrix * scale_small_matrix,
6220 identity_matrix,
6221 gfx::PointF(),
6222 gfx::PointF(2.f, 2.f),
6223 gfx::Size(10, 10),
6224 true);
[email protected]1b30e8e2012-12-21 02:59:096225
[email protected]fb661802013-03-25 01:59:326226 scoped_refptr<ContentLayer> scale_surface =
6227 CreateDrawableContentLayer(&delegate);
6228 SetLayerPropertiesForTesting(scale_surface.get(),
6229 scale_small_matrix,
6230 identity_matrix,
6231 gfx::PointF(),
6232 gfx::PointF(2.f, 2.f),
6233 gfx::Size(10, 10),
6234 true);
[email protected]1b30e8e2012-12-21 02:59:096235
[email protected]fb661802013-03-25 01:59:326236 perspective_surface->SetForceRenderSurface(true);
6237 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:096238
[email protected]fb661802013-03-25 01:59:326239 parent->AddChild(perspective_surface);
6240 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:326241 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:096242
[email protected]d600df7d2013-08-03 02:34:286243 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6244 host->SetRootLayer(root);
6245
[email protected]fb661802013-03-25 01:59:326246 float device_scale_factor = 2.5f;
6247 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:096248
[email protected]7aad55f2013-07-26 11:25:536249 RenderSurfaceLayerList render_surface_layer_list;
6250 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6251 root.get(), parent->bounds(), &render_surface_layer_list);
6252 inputs.device_scale_factor = device_scale_factor;
6253 inputs.page_scale_factor = page_scale_factor;
6254 inputs.page_scale_application_layer = root;
6255 inputs.can_adjust_raster_scales = true;
6256 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:096257
[email protected]fb661802013-03-25 01:59:326258 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6259 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6260 perspective_surface);
6261 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6262 scale_surface);
[email protected]1b30e8e2012-12-21 02:59:096263
[email protected]fb661802013-03-25 01:59:326264 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:096265
[email protected]fb661802013-03-25 01:59:326266 gfx::Transform expected_parent_draw_transform;
6267 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
6268 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096269
[email protected]fb661802013-03-25 01:59:326270 // The scaled surface is rendered at its appropriate scale, and drawn 1:1
6271 // into its target.
6272 gfx::Transform expected_scale_surface_draw_transform;
6273 expected_scale_surface_draw_transform.Translate(
6274 device_scale_factor * page_scale_factor * scale_surface->position().x(),
6275 device_scale_factor * page_scale_factor * scale_surface->position().y());
[email protected]fb661802013-03-25 01:59:326276 EXPECT_TRANSFORMATION_MATRIX_EQ(
6277 expected_scale_surface_draw_transform,
6278 scale_surface->render_surface()->draw_transform());
[email protected]a52c6ff2013-05-04 05:33:156279 gfx::Transform expected_scale_surface_layer_draw_transform =
6280 scale_small_matrix;
[email protected]fb661802013-03-25 01:59:326281 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform,
6282 scale_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096283
[email protected]fb661802013-03-25 01:59:326284 // The scale for the perspective surface is not known, so it is rendered 1:1
6285 // with the screen, and then scaled during drawing.
6286 gfx::Transform expected_perspective_surface_draw_transform;
6287 expected_perspective_surface_draw_transform.Translate(
6288 device_scale_factor * page_scale_factor *
6289 perspective_surface->position().x(),
6290 device_scale_factor * page_scale_factor *
6291 perspective_surface->position().y());
6292 expected_perspective_surface_draw_transform.PreconcatTransform(
6293 perspective_matrix);
6294 expected_perspective_surface_draw_transform.PreconcatTransform(
6295 scale_small_matrix);
6296 gfx::Transform expected_perspective_surface_layer_draw_transform;
6297 EXPECT_TRANSFORMATION_MATRIX_EQ(
6298 expected_perspective_surface_draw_transform,
6299 perspective_surface->render_surface()->draw_transform());
6300 EXPECT_TRANSFORMATION_MATRIX_EQ(
6301 expected_perspective_surface_layer_draw_transform,
6302 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:096303}
6304
[email protected]989386c2013-07-18 21:37:236305TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:326306 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
6307 // Verify draw and screen space transforms of layers not in a surface.
6308 MockContentLayerClient delegate;
6309 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:476310
[email protected]fb661802013-03-25 01:59:326311 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6312 SetLayerPropertiesForTesting(parent.get(),
6313 identity_matrix,
6314 identity_matrix,
6315 gfx::PointF(),
6316 gfx::PointF(),
6317 gfx::Size(133, 133),
6318 true);
[email protected]904e9132012-11-01 00:12:476319
[email protected]fb661802013-03-25 01:59:326320 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
6321 SetLayerPropertiesForTesting(child.get(),
6322 identity_matrix,
6323 identity_matrix,
6324 gfx::PointF(),
6325 gfx::PointF(),
6326 gfx::Size(13, 13),
6327 true);
[email protected]904e9132012-11-01 00:12:476328
[email protected]fb661802013-03-25 01:59:326329 scoped_refptr<NoScaleContentLayer> child_no_scale =
6330 CreateNoScaleDrawableContentLayer(&delegate);
6331 SetLayerPropertiesForTesting(child_no_scale.get(),
6332 identity_matrix,
6333 identity_matrix,
6334 gfx::PointF(),
6335 gfx::PointF(),
6336 gfx::Size(13, 13),
6337 true);
[email protected]904e9132012-11-01 00:12:476338
[email protected]fb661802013-03-25 01:59:326339 parent->AddChild(child);
6340 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:476341
[email protected]d600df7d2013-08-03 02:34:286342 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6343 host->SetRootLayer(parent);
6344
[email protected]fb661802013-03-25 01:59:326345 float device_scale_factor = 1.7f;
6346 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:476347
[email protected]7aad55f2013-07-26 11:25:536348 RenderSurfaceLayerList render_surface_layer_list;
6349 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6350 parent.get(), parent->bounds(), &render_surface_layer_list);
6351 inputs.device_scale_factor = device_scale_factor;
6352 inputs.page_scale_factor = page_scale_factor;
6353 inputs.page_scale_application_layer = parent.get();
6354 inputs.can_adjust_raster_scales = true;
6355 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:476356
[email protected]fb661802013-03-25 01:59:326357 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6358 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
6359 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:476360
[email protected]fb661802013-03-25 01:59:326361 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:476362
[email protected]fb661802013-03-25 01:59:326363 // Verify parent transforms
6364 gfx::Transform expected_parent_transform;
6365 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6366 parent->screen_space_transform());
6367 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6368 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:476369
[email protected]fb661802013-03-25 01:59:326370 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:056371 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:476372
[email protected]fb661802013-03-25 01:59:326373 gfx::RectF parent_draw_rect =
6374 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6375 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6376 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:476377
[email protected]2c7c6702013-03-26 03:14:056378 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:326379 expected_parent_draw_rect.Scale(device_scale_factor);
6380 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
6381 expected_parent_draw_rect.set_height(
6382 ceil(expected_parent_draw_rect.height()));
6383 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6384 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476385
[email protected]fb661802013-03-25 01:59:326386 // Verify child transforms
6387 gfx::Transform expected_child_transform;
6388 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6389 child->draw_transform());
6390 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6391 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476392
[email protected]fb661802013-03-25 01:59:326393 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:056394 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:476395
[email protected]fb661802013-03-25 01:59:326396 gfx::RectF child_draw_rect =
6397 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6398 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6399 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:476400
[email protected]2c7c6702013-03-26 03:14:056401 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:326402 expected_child_draw_rect.Scale(device_scale_factor);
6403 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
6404 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
6405 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6406 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:476407
[email protected]fb661802013-03-25 01:59:326408 // Verify child_no_scale transforms
6409 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6410 // All transforms operate on content rects. The child's content rect
6411 // incorporates device scale, but the child_no_scale does not; add it here.
6412 expected_child_no_scale_transform.Scale(device_scale_factor,
6413 device_scale_factor);
6414 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6415 child_no_scale->draw_transform());
6416 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6417 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:476418}
6419
[email protected]989386c2013-07-18 21:37:236420TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:326421 MockContentLayerClient delegate;
6422 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446423
[email protected]fb661802013-03-25 01:59:326424 gfx::Transform parent_scale_matrix;
6425 double initial_parent_scale = 1.75;
6426 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446427
[email protected]fb661802013-03-25 01:59:326428 gfx::Transform child_scale_matrix;
6429 double initial_child_scale = 1.25;
6430 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446431
[email protected]35a99a12013-05-09 23:52:296432 scoped_refptr<Layer> root = Layer::Create();
6433 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446434
[email protected]fb661802013-03-25 01:59:326435 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6436 SetLayerPropertiesForTesting(parent.get(),
6437 parent_scale_matrix,
6438 identity_matrix,
6439 gfx::PointF(),
6440 gfx::PointF(),
6441 gfx::Size(100, 100),
6442 true);
[email protected]518ee582012-10-24 18:29:446443
[email protected]fb661802013-03-25 01:59:326444 scoped_refptr<ContentLayer> child_scale =
6445 CreateDrawableContentLayer(&delegate);
6446 SetLayerPropertiesForTesting(child_scale.get(),
6447 child_scale_matrix,
6448 identity_matrix,
6449 gfx::PointF(),
6450 gfx::PointF(2.f, 2.f),
6451 gfx::Size(10, 10),
6452 true);
[email protected]518ee582012-10-24 18:29:446453
[email protected]fb661802013-03-25 01:59:326454 scoped_refptr<ContentLayer> child_empty =
6455 CreateDrawableContentLayer(&delegate);
6456 SetLayerPropertiesForTesting(child_empty.get(),
6457 child_scale_matrix,
6458 identity_matrix,
6459 gfx::PointF(),
6460 gfx::PointF(2.f, 2.f),
6461 gfx::Size(),
6462 true);
[email protected]f89f5632012-11-14 23:34:456463
[email protected]fb661802013-03-25 01:59:326464 scoped_refptr<NoScaleContentLayer> child_no_scale =
6465 CreateNoScaleDrawableContentLayer(&delegate);
6466 SetLayerPropertiesForTesting(child_no_scale.get(),
6467 child_scale_matrix,
6468 identity_matrix,
6469 gfx::PointF(),
6470 gfx::PointF(12.f, 12.f),
6471 gfx::Size(10, 10),
6472 true);
[email protected]518ee582012-10-24 18:29:446473
[email protected]35a99a12013-05-09 23:52:296474 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446475
[email protected]fb661802013-03-25 01:59:326476 parent->AddChild(child_scale);
6477 parent->AddChild(child_empty);
6478 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:446479
[email protected]d600df7d2013-08-03 02:34:286480 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6481 host->SetRootLayer(root);
6482
[email protected]fb661802013-03-25 01:59:326483 float device_scale_factor = 2.5f;
6484 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:446485
[email protected]989386c2013-07-18 21:37:236486 {
6487 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536488 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6489 root.get(), root->bounds(), &render_surface_layer_list);
6490 inputs.device_scale_factor = device_scale_factor;
6491 inputs.page_scale_factor = page_scale_factor;
6492 inputs.page_scale_application_layer = root.get();
6493 inputs.can_adjust_raster_scales = true;
6494 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:446495
[email protected]989386c2013-07-18 21:37:236496 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6497 initial_parent_scale, parent);
6498 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6499 initial_parent_scale * initial_child_scale,
6500 child_scale);
6501 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6502 initial_parent_scale * initial_child_scale,
6503 child_empty);
6504 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:446505
[email protected]989386c2013-07-18 21:37:236506 // The parent is scaled up and shouldn't need to scale during draw. The
6507 // child that can scale its contents should also not need to scale during
6508 // draw. This shouldn't change if the child has empty bounds. The other
6509 // children should.
6510 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(0, 0));
6511 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(1, 1));
6512 EXPECT_FLOAT_EQ(1.0,
6513 child_scale->draw_transform().matrix().getDouble(0, 0));
6514 EXPECT_FLOAT_EQ(1.0,
6515 child_scale->draw_transform().matrix().getDouble(1, 1));
6516 EXPECT_FLOAT_EQ(1.0,
6517 child_empty->draw_transform().matrix().getDouble(0, 0));
6518 EXPECT_FLOAT_EQ(1.0,
6519 child_empty->draw_transform().matrix().getDouble(1, 1));
6520 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6521 initial_parent_scale * initial_child_scale,
6522 child_no_scale->draw_transform().matrix().getDouble(0, 0));
6523 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6524 initial_parent_scale * initial_child_scale,
6525 child_no_scale->draw_transform().matrix().getDouble(1, 1));
6526 }
[email protected]518ee582012-10-24 18:29:446527
[email protected]fb661802013-03-25 01:59:326528 // If the device_scale_factor or page_scale_factor changes, then it should be
6529 // updated using the initial transform as the raster scale.
6530 device_scale_factor = 2.25f;
6531 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:446532
[email protected]989386c2013-07-18 21:37:236533 {
6534 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536535 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6536 root.get(), root->bounds(), &render_surface_layer_list);
6537 inputs.device_scale_factor = device_scale_factor;
6538 inputs.page_scale_factor = page_scale_factor;
6539 inputs.page_scale_application_layer = root.get();
6540 inputs.can_adjust_raster_scales = true;
6541 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6542
6543 EXPECT_CONTENTS_SCALE_EQ(
6544 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:236545 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536546 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:236547 child_scale);
6548 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6549 initial_parent_scale * initial_child_scale,
6550 child_empty);
6551 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6552 }
[email protected]d0518202013-02-08 02:06:496553
[email protected]fb661802013-03-25 01:59:326554 // If the transform changes, we expect the raster scale to be reset to 1.0.
6555 double second_child_scale = 1.75;
6556 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
6557 second_child_scale / initial_child_scale);
6558 child_scale->SetTransform(child_scale_matrix);
6559 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:496560
[email protected]989386c2013-07-18 21:37:236561 {
6562 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536563 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6564 root.get(), root->bounds(), &render_surface_layer_list);
6565 inputs.device_scale_factor = device_scale_factor;
6566 inputs.page_scale_factor = page_scale_factor;
6567 inputs.page_scale_application_layer = root.get();
6568 inputs.can_adjust_raster_scales = true;
6569 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496570
[email protected]989386c2013-07-18 21:37:236571 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6572 initial_parent_scale,
6573 parent);
6574 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6575 child_scale);
6576 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6577 child_empty);
6578 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6579 }
[email protected]d0518202013-02-08 02:06:496580
[email protected]fb661802013-03-25 01:59:326581 // If the device_scale_factor or page_scale_factor changes, then it should be
6582 // updated, but still using 1.0 as the raster scale.
6583 device_scale_factor = 2.75f;
6584 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:496585
[email protected]989386c2013-07-18 21:37:236586 {
6587 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536588 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6589 root.get(), root->bounds(), &render_surface_layer_list);
6590 inputs.device_scale_factor = device_scale_factor;
6591 inputs.page_scale_factor = page_scale_factor;
6592 inputs.page_scale_application_layer = root.get();
6593 inputs.can_adjust_raster_scales = true;
6594 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:496595
[email protected]989386c2013-07-18 21:37:236596 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6597 initial_parent_scale,
6598 parent);
6599 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6600 child_scale);
6601 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6602 child_empty);
6603 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6604 }
[email protected]518ee582012-10-24 18:29:446605}
6606
[email protected]989386c2013-07-18 21:37:236607TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:296608 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:326609 MockContentLayerClient delegate;
6610 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:216611
[email protected]fb661802013-03-25 01:59:326612 gfx::Transform parent_scale_matrix;
6613 double initial_parent_scale = 1.75;
6614 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:216615
[email protected]fb661802013-03-25 01:59:326616 gfx::Transform child_scale_matrix;
[email protected]35a99a12013-05-09 23:52:296617 double initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:326618 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:216619
[email protected]35a99a12013-05-09 23:52:296620 scoped_refptr<Layer> root = Layer::Create();
6621 root->SetBounds(gfx::Size(100, 100));
6622
[email protected]fb661802013-03-25 01:59:326623 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6624 SetLayerPropertiesForTesting(parent.get(),
6625 parent_scale_matrix,
6626 identity_matrix,
6627 gfx::PointF(),
6628 gfx::PointF(),
6629 gfx::Size(100, 100),
6630 true);
[email protected]11ec92972012-11-10 03:06:216631
[email protected]fb661802013-03-25 01:59:326632 scoped_refptr<ContentLayer> child_scale =
6633 CreateDrawableContentLayer(&delegate);
6634 SetLayerPropertiesForTesting(child_scale.get(),
6635 child_scale_matrix,
6636 identity_matrix,
6637 gfx::PointF(),
6638 gfx::PointF(2.f, 2.f),
6639 gfx::Size(10, 10),
6640 true);
[email protected]11ec92972012-11-10 03:06:216641
[email protected]35a99a12013-05-09 23:52:296642 scoped_refptr<ContentLayer> child_empty =
6643 CreateDrawableContentLayer(&delegate);
6644 SetLayerPropertiesForTesting(child_empty.get(),
6645 child_scale_matrix,
6646 identity_matrix,
6647 gfx::PointF(),
6648 gfx::PointF(2.f, 2.f),
6649 gfx::Size(),
6650 true);
6651
6652 scoped_refptr<NoScaleContentLayer> child_no_scale =
6653 CreateNoScaleDrawableContentLayer(&delegate);
6654 SetLayerPropertiesForTesting(child_no_scale.get(),
6655 child_scale_matrix,
6656 identity_matrix,
6657 gfx::PointF(),
6658 gfx::PointF(12.f, 12.f),
6659 gfx::Size(10, 10),
6660 true);
6661
6662 root->AddChild(parent);
6663
6664 parent->AddChild(child_scale);
6665 parent->AddChild(child_empty);
6666 parent->AddChild(child_no_scale);
6667
[email protected]d600df7d2013-08-03 02:34:286668 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6669 host->SetRootLayer(root);
6670
[email protected]989386c2013-07-18 21:37:236671 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:296672
6673 float device_scale_factor = 2.5f;
6674 float page_scale_factor = 1.f;
6675
[email protected]7aad55f2013-07-26 11:25:536676 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6677 root.get(), root->bounds(), &render_surface_layer_list);
6678 inputs.device_scale_factor = device_scale_factor;
6679 inputs.page_scale_factor = page_scale_factor;
6680 inputs.page_scale_application_layer = root.get(),
6681 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:296682
6683 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6684 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6685 child_scale);
6686 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6687 child_empty);
6688 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6689
6690 // Since the transform scale does not affect contents scale, it should affect
6691 // the draw transform instead.
6692 EXPECT_FLOAT_EQ(initial_parent_scale,
6693 parent->draw_transform().matrix().getDouble(0, 0));
6694 EXPECT_FLOAT_EQ(initial_parent_scale,
6695 parent->draw_transform().matrix().getDouble(1, 1));
6696 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
6697 child_scale->draw_transform().matrix().getDouble(0, 0));
6698 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
6699 child_scale->draw_transform().matrix().getDouble(1, 1));
6700 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
6701 child_empty->draw_transform().matrix().getDouble(0, 0));
6702 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
6703 child_empty->draw_transform().matrix().getDouble(1, 1));
6704 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6705 initial_parent_scale * initial_child_scale,
6706 child_no_scale->draw_transform().matrix().getDouble(0, 0));
6707 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6708 initial_parent_scale * initial_child_scale,
6709 child_no_scale->draw_transform().matrix().getDouble(1, 1));
6710}
6711
[email protected]989386c2013-07-18 21:37:236712TEST_F(LayerTreeHostCommonTest, SmallContentsScale) {
[email protected]35a99a12013-05-09 23:52:296713 MockContentLayerClient delegate;
6714 gfx::Transform identity_matrix;
6715
6716 gfx::Transform parent_scale_matrix;
6717 double initial_parent_scale = 1.75;
6718 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6719
6720 gfx::Transform child_scale_matrix;
6721 double initial_child_scale = 0.25;
6722 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6723
6724 scoped_refptr<Layer> root = Layer::Create();
6725 root->SetBounds(gfx::Size(100, 100));
6726
6727 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6728 SetLayerPropertiesForTesting(parent.get(),
6729 parent_scale_matrix,
6730 identity_matrix,
6731 gfx::PointF(),
6732 gfx::PointF(),
6733 gfx::Size(100, 100),
6734 true);
6735
6736 scoped_refptr<ContentLayer> child_scale =
6737 CreateDrawableContentLayer(&delegate);
6738 SetLayerPropertiesForTesting(child_scale.get(),
6739 child_scale_matrix,
6740 identity_matrix,
6741 gfx::PointF(),
6742 gfx::PointF(2.f, 2.f),
6743 gfx::Size(10, 10),
6744 true);
6745
6746 root->AddChild(parent);
6747
[email protected]fb661802013-03-25 01:59:326748 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:216749
[email protected]d600df7d2013-08-03 02:34:286750 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6751 host->SetRootLayer(root);
6752
[email protected]fb661802013-03-25 01:59:326753 float device_scale_factor = 2.5f;
6754 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:216755
[email protected]989386c2013-07-18 21:37:236756 {
6757 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536758 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6759 root.get(), root->bounds(), &render_surface_layer_list);
6760 inputs.device_scale_factor = device_scale_factor;
6761 inputs.page_scale_factor = page_scale_factor;
6762 inputs.page_scale_application_layer = root.get();
6763 inputs.can_adjust_raster_scales = true;
6764 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216765
[email protected]989386c2013-07-18 21:37:236766 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6767 initial_parent_scale,
6768 parent);
6769 // The child's scale is < 1, so we should not save and use that scale
6770 // factor.
6771 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1,
6772 child_scale);
6773 }
[email protected]11ec92972012-11-10 03:06:216774
[email protected]fb661802013-03-25 01:59:326775 // When chilld's total scale becomes >= 1, we should save and use that scale
6776 // factor.
6777 child_scale_matrix.MakeIdentity();
6778 double final_child_scale = 0.75;
6779 child_scale_matrix.Scale(final_child_scale, final_child_scale);
6780 child_scale->SetTransform(child_scale_matrix);
[email protected]11ec92972012-11-10 03:06:216781
[email protected]989386c2013-07-18 21:37:236782 {
6783 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536784 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6785 root.get(), root->bounds(), &render_surface_layer_list);
6786 inputs.device_scale_factor = device_scale_factor;
6787 inputs.page_scale_factor = page_scale_factor;
6788 inputs.page_scale_application_layer = root.get();
6789 inputs.can_adjust_raster_scales = true;
6790 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:216791
[email protected]989386c2013-07-18 21:37:236792 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6793 initial_parent_scale,
6794 parent);
6795 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6796 initial_parent_scale * final_child_scale,
6797 child_scale);
6798 }
[email protected]11ec92972012-11-10 03:06:216799}
6800
[email protected]989386c2013-07-18 21:37:236801TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:326802 MockContentLayerClient delegate;
6803 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:446804
[email protected]fb661802013-03-25 01:59:326805 gfx::Transform parent_scale_matrix;
6806 double initial_parent_scale = 2.0;
6807 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:446808
[email protected]fb661802013-03-25 01:59:326809 gfx::Transform child_scale_matrix;
6810 double initial_child_scale = 3.0;
6811 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:446812
[email protected]35a99a12013-05-09 23:52:296813 scoped_refptr<Layer> root = Layer::Create();
6814 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:446815
[email protected]fb661802013-03-25 01:59:326816 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6817 SetLayerPropertiesForTesting(parent.get(),
6818 parent_scale_matrix,
6819 identity_matrix,
6820 gfx::PointF(),
6821 gfx::PointF(),
6822 gfx::Size(100, 100),
6823 true);
[email protected]518ee582012-10-24 18:29:446824
[email protected]fb661802013-03-25 01:59:326825 scoped_refptr<ContentLayer> surface_scale =
6826 CreateDrawableContentLayer(&delegate);
6827 SetLayerPropertiesForTesting(surface_scale.get(),
6828 child_scale_matrix,
6829 identity_matrix,
6830 gfx::PointF(),
6831 gfx::PointF(2.f, 2.f),
6832 gfx::Size(10, 10),
6833 true);
[email protected]518ee582012-10-24 18:29:446834
[email protected]fb661802013-03-25 01:59:326835 scoped_refptr<ContentLayer> surface_scale_child_scale =
6836 CreateDrawableContentLayer(&delegate);
6837 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
6838 child_scale_matrix,
6839 identity_matrix,
6840 gfx::PointF(),
6841 gfx::PointF(),
6842 gfx::Size(10, 10),
6843 true);
[email protected]518ee582012-10-24 18:29:446844
[email protected]fb661802013-03-25 01:59:326845 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
6846 CreateNoScaleDrawableContentLayer(&delegate);
6847 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
6848 child_scale_matrix,
6849 identity_matrix,
6850 gfx::PointF(),
6851 gfx::PointF(),
6852 gfx::Size(10, 10),
6853 true);
[email protected]518ee582012-10-24 18:29:446854
[email protected]fb661802013-03-25 01:59:326855 scoped_refptr<NoScaleContentLayer> surface_no_scale =
6856 CreateNoScaleDrawableContentLayer(&delegate);
6857 SetLayerPropertiesForTesting(surface_no_scale.get(),
6858 child_scale_matrix,
6859 identity_matrix,
6860 gfx::PointF(),
6861 gfx::PointF(12.f, 12.f),
6862 gfx::Size(10, 10),
6863 true);
[email protected]518ee582012-10-24 18:29:446864
[email protected]fb661802013-03-25 01:59:326865 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
6866 CreateDrawableContentLayer(&delegate);
6867 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
6868 child_scale_matrix,
6869 identity_matrix,
6870 gfx::PointF(),
6871 gfx::PointF(),
6872 gfx::Size(10, 10),
6873 true);
[email protected]518ee582012-10-24 18:29:446874
[email protected]fb661802013-03-25 01:59:326875 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
6876 CreateNoScaleDrawableContentLayer(&delegate);
6877 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
6878 child_scale_matrix,
6879 identity_matrix,
6880 gfx::PointF(),
6881 gfx::PointF(),
6882 gfx::Size(10, 10),
6883 true);
[email protected]518ee582012-10-24 18:29:446884
[email protected]35a99a12013-05-09 23:52:296885 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:446886
[email protected]fb661802013-03-25 01:59:326887 parent->AddChild(surface_scale);
6888 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:446889
[email protected]fb661802013-03-25 01:59:326890 surface_scale->SetForceRenderSurface(true);
6891 surface_scale->AddChild(surface_scale_child_scale);
6892 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446893
[email protected]fb661802013-03-25 01:59:326894 surface_no_scale->SetForceRenderSurface(true);
6895 surface_no_scale->AddChild(surface_no_scale_child_scale);
6896 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446897
[email protected]d600df7d2013-08-03 02:34:286898 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6899 host->SetRootLayer(root);
6900
[email protected]fb661802013-03-25 01:59:326901 double device_scale_factor = 5;
6902 double page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:446903
[email protected]7aad55f2013-07-26 11:25:536904 RenderSurfaceLayerList render_surface_layer_list;
6905 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6906 root.get(), root->bounds(), &render_surface_layer_list);
6907 inputs.device_scale_factor = device_scale_factor;
6908 inputs.page_scale_factor = page_scale_factor;
6909 inputs.page_scale_application_layer = root.get();
6910 inputs.can_adjust_raster_scales = true;
6911 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6912
6913 EXPECT_CONTENTS_SCALE_EQ(
6914 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:196915 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:536916 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:326917 surface_scale);
6918 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
6919 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:326920 device_scale_factor * page_scale_factor * initial_parent_scale *
6921 initial_child_scale * initial_child_scale,
6922 surface_scale_child_scale);
6923 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
6924 EXPECT_CONTENTS_SCALE_EQ(
6925 device_scale_factor * page_scale_factor * initial_parent_scale *
6926 initial_child_scale * initial_child_scale,
6927 surface_no_scale_child_scale);
6928 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:446929
[email protected]fb661802013-03-25 01:59:326930 // The parent is scaled up and shouldn't need to scale during draw.
6931 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(0, 0));
6932 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(1, 1));
[email protected]518ee582012-10-24 18:29:446933
[email protected]fb661802013-03-25 01:59:326934 // RenderSurfaces should always be 1:1 with their target.
6935 EXPECT_FLOAT_EQ(
6936 1.0,
6937 surface_scale->render_surface()->draw_transform().matrix().getDouble(0,
6938 0));
6939 EXPECT_FLOAT_EQ(
6940 1.0,
6941 surface_scale->render_surface()->draw_transform().matrix().getDouble(1,
6942 1));
[email protected]518ee582012-10-24 18:29:446943
[email protected]fb661802013-03-25 01:59:326944 // The surface_scale can apply contents scale so the layer shouldn't need to
6945 // scale during draw.
6946 EXPECT_FLOAT_EQ(1.0,
6947 surface_scale->draw_transform().matrix().getDouble(0, 0));
6948 EXPECT_FLOAT_EQ(1.0,
6949 surface_scale->draw_transform().matrix().getDouble(1, 1));
[email protected]518ee582012-10-24 18:29:446950
[email protected]fb661802013-03-25 01:59:326951 // The surface_scale_child_scale can apply contents scale so it shouldn't need
6952 // to scale during draw.
6953 EXPECT_FLOAT_EQ(
6954 1.0,
6955 surface_scale_child_scale->draw_transform().matrix().getDouble(0, 0));
6956 EXPECT_FLOAT_EQ(
6957 1.0,
6958 surface_scale_child_scale->draw_transform().matrix().getDouble(1, 1));
[email protected]518ee582012-10-24 18:29:446959
[email protected]fb661802013-03-25 01:59:326960 // The surface_scale_child_no_scale can not apply contents scale, so it needs
6961 // to be scaled during draw.
6962 EXPECT_FLOAT_EQ(
6963 device_scale_factor * page_scale_factor * initial_parent_scale *
6964 initial_child_scale * initial_child_scale,
6965 surface_scale_child_no_scale->draw_transform().matrix().getDouble(0, 0));
6966 EXPECT_FLOAT_EQ(
6967 device_scale_factor * page_scale_factor * initial_parent_scale *
6968 initial_child_scale * initial_child_scale,
6969 surface_scale_child_no_scale->draw_transform().matrix().getDouble(1, 1));
[email protected]518ee582012-10-24 18:29:446970
[email protected]fb661802013-03-25 01:59:326971 // RenderSurfaces should always be 1:1 with their target.
6972 EXPECT_FLOAT_EQ(
6973 1.0,
6974 surface_no_scale->render_surface()->draw_transform().matrix().getDouble(
6975 0, 0));
6976 EXPECT_FLOAT_EQ(
6977 1.0,
6978 surface_no_scale->render_surface()->draw_transform().matrix().getDouble(
6979 1, 1));
[email protected]518ee582012-10-24 18:29:446980
[email protected]fb661802013-03-25 01:59:326981 // The surface_no_scale layer can not apply contents scale, so it needs to be
6982 // scaled during draw.
6983 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6984 initial_parent_scale * initial_child_scale,
6985 surface_no_scale->draw_transform().matrix().getDouble(0, 0));
6986 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6987 initial_parent_scale * initial_child_scale,
6988 surface_no_scale->draw_transform().matrix().getDouble(1, 1));
[email protected]518ee582012-10-24 18:29:446989
[email protected]fb661802013-03-25 01:59:326990 // The surface_scale_child_scale can apply contents scale so it shouldn't need
6991 // to scale during draw.
6992 EXPECT_FLOAT_EQ(
6993 1.0,
6994 surface_no_scale_child_scale->draw_transform().matrix().getDouble(0, 0));
6995 EXPECT_FLOAT_EQ(
6996 1.0,
6997 surface_no_scale_child_scale->draw_transform().matrix().getDouble(1, 1));
[email protected]518ee582012-10-24 18:29:446998
[email protected]fb661802013-03-25 01:59:326999 // The surface_scale_child_no_scale can not apply contents scale, so it needs
7000 // to be scaled during draw.
7001 EXPECT_FLOAT_EQ(
7002 device_scale_factor * page_scale_factor * initial_parent_scale *
7003 initial_child_scale * initial_child_scale,
7004 surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(0,
7005 0));
7006 EXPECT_FLOAT_EQ(
7007 device_scale_factor * page_scale_factor * initial_parent_scale *
7008 initial_child_scale * initial_child_scale,
7009 surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(1,
7010 1));
[email protected]35a99a12013-05-09 23:52:297011}
[email protected]518ee582012-10-24 18:29:447012
[email protected]989386c2013-07-18 21:37:237013TEST_F(LayerTreeHostCommonTest,
[email protected]35a99a12013-05-09 23:52:297014 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
7015 MockContentLayerClient delegate;
7016 gfx::Transform identity_matrix;
7017
7018 gfx::Transform parent_scale_matrix;
7019 double initial_parent_scale = 2.0;
7020 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
7021
7022 gfx::Transform child_scale_matrix;
7023 double initial_child_scale = 3.0;
7024 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
7025
7026 scoped_refptr<Layer> root = Layer::Create();
7027 root->SetBounds(gfx::Size(100, 100));
7028
7029 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7030 SetLayerPropertiesForTesting(parent.get(),
7031 parent_scale_matrix,
7032 identity_matrix,
7033 gfx::PointF(),
7034 gfx::PointF(),
7035 gfx::Size(100, 100),
7036 true);
7037
7038 scoped_refptr<ContentLayer> surface_scale =
7039 CreateDrawableContentLayer(&delegate);
7040 SetLayerPropertiesForTesting(surface_scale.get(),
7041 child_scale_matrix,
7042 identity_matrix,
7043 gfx::PointF(),
7044 gfx::PointF(2.f, 2.f),
7045 gfx::Size(10, 10),
7046 true);
7047
7048 scoped_refptr<ContentLayer> surface_scale_child_scale =
7049 CreateDrawableContentLayer(&delegate);
7050 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
7051 child_scale_matrix,
7052 identity_matrix,
7053 gfx::PointF(),
7054 gfx::PointF(),
7055 gfx::Size(10, 10),
7056 true);
7057
7058 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
7059 CreateNoScaleDrawableContentLayer(&delegate);
7060 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
7061 child_scale_matrix,
7062 identity_matrix,
7063 gfx::PointF(),
7064 gfx::PointF(),
7065 gfx::Size(10, 10),
7066 true);
7067
7068 scoped_refptr<NoScaleContentLayer> surface_no_scale =
7069 CreateNoScaleDrawableContentLayer(&delegate);
7070 SetLayerPropertiesForTesting(surface_no_scale.get(),
7071 child_scale_matrix,
7072 identity_matrix,
7073 gfx::PointF(),
7074 gfx::PointF(12.f, 12.f),
7075 gfx::Size(10, 10),
7076 true);
7077
7078 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
7079 CreateDrawableContentLayer(&delegate);
7080 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
7081 child_scale_matrix,
7082 identity_matrix,
7083 gfx::PointF(),
7084 gfx::PointF(),
7085 gfx::Size(10, 10),
7086 true);
7087
7088 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
7089 CreateNoScaleDrawableContentLayer(&delegate);
7090 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
7091 child_scale_matrix,
7092 identity_matrix,
7093 gfx::PointF(),
7094 gfx::PointF(),
7095 gfx::Size(10, 10),
7096 true);
7097
7098 root->AddChild(parent);
7099
7100 parent->AddChild(surface_scale);
7101 parent->AddChild(surface_no_scale);
7102
7103 surface_scale->SetForceRenderSurface(true);
7104 surface_scale->AddChild(surface_scale_child_scale);
7105 surface_scale->AddChild(surface_scale_child_no_scale);
7106
7107 surface_no_scale->SetForceRenderSurface(true);
7108 surface_no_scale->AddChild(surface_no_scale_child_scale);
7109 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
7110
[email protected]d600df7d2013-08-03 02:34:287111 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7112 host->SetRootLayer(root);
7113
[email protected]989386c2013-07-18 21:37:237114 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:297115
[email protected]7aad55f2013-07-26 11:25:537116 double device_scale_factor = 5.0;
7117 double page_scale_factor = 7.0;
7118 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7119 root.get(), root->bounds(), &render_surface_layer_list);
7120 inputs.device_scale_factor = device_scale_factor;
7121 inputs.page_scale_factor = page_scale_factor;
7122 inputs.page_scale_application_layer = root.get();
7123 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:297124
[email protected]35a99a12013-05-09 23:52:297125 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7126 parent);
7127 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7128 surface_scale);
7129 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
7130 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7131 surface_scale_child_scale);
7132 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
7133 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7134 surface_no_scale_child_scale);
7135 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
7136
7137 // The parent is scaled up during draw, since its contents are not scaled by
7138 // the transform hierarchy.
7139 EXPECT_FLOAT_EQ(initial_parent_scale,
7140 parent->draw_transform().matrix().getDouble(0, 0));
7141 EXPECT_FLOAT_EQ(initial_parent_scale,
7142 parent->draw_transform().matrix().getDouble(1, 1));
7143
7144 // The child surface is scaled up during draw since its subtree is not scaled
7145 // by the transform hierarchy.
7146 EXPECT_FLOAT_EQ(
7147 initial_parent_scale * initial_child_scale,
7148 surface_scale->render_surface()->draw_transform().matrix().getDouble(0,
7149 0));
7150 EXPECT_FLOAT_EQ(
7151 initial_parent_scale * initial_child_scale,
7152 surface_scale->render_surface()->draw_transform().matrix().getDouble(1,
7153 1));
7154
7155 // The surface_scale's RenderSurface is scaled during draw, so the layer does
7156 // not need to be scaled when drawing into its surface.
[email protected]fb661802013-03-25 01:59:327157 EXPECT_FLOAT_EQ(1.0,
[email protected]35a99a12013-05-09 23:52:297158 surface_scale->draw_transform().matrix().getDouble(0, 0));
[email protected]fb661802013-03-25 01:59:327159 EXPECT_FLOAT_EQ(1.0,
[email protected]35a99a12013-05-09 23:52:297160 surface_scale->draw_transform().matrix().getDouble(1, 1));
[email protected]518ee582012-10-24 18:29:447161
[email protected]35a99a12013-05-09 23:52:297162 // The surface_scale_child_scale is scaled when drawing into its surface,
7163 // since its content bounds are not scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:327164 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297165 initial_child_scale,
7166 surface_scale_child_scale->draw_transform().matrix().getDouble(0, 0));
[email protected]fb661802013-03-25 01:59:327167 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297168 initial_child_scale,
7169 surface_scale_child_scale->draw_transform().matrix().getDouble(1, 1));
[email protected]518ee582012-10-24 18:29:447170
[email protected]35a99a12013-05-09 23:52:297171 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
7172 // needs to be scaled by the device and page scale factors, along with the
7173 // transform hierarchy.
[email protected]fb661802013-03-25 01:59:327174 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297175 device_scale_factor * page_scale_factor * initial_child_scale,
7176 surface_scale_child_no_scale->draw_transform().matrix().getDouble(0, 0));
7177 EXPECT_FLOAT_EQ(
7178 device_scale_factor * page_scale_factor * initial_child_scale,
7179 surface_scale_child_no_scale->draw_transform().matrix().getDouble(1, 1));
7180
7181 // The child surface is scaled up during draw since its subtree is not scaled
7182 // by the transform hierarchy.
7183 EXPECT_FLOAT_EQ(
7184 initial_parent_scale * initial_child_scale,
7185 surface_no_scale->render_surface()->draw_transform().matrix().getDouble(
[email protected]fb661802013-03-25 01:59:327186 0, 0));
7187 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297188 initial_parent_scale * initial_child_scale,
7189 surface_no_scale->render_surface()->draw_transform().matrix().getDouble(
[email protected]fb661802013-03-25 01:59:327190 1, 1));
[email protected]518ee582012-10-24 18:29:447191
[email protected]35a99a12013-05-09 23:52:297192 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
7193 // be scaled by the device and page scale factors. Its surface is already
7194 // scaled by the transform hierarchy so those don't need to scale the layer's
7195 // drawing.
7196 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
7197 surface_no_scale->draw_transform().matrix().getDouble(0, 0));
7198 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
7199 surface_no_scale->draw_transform().matrix().getDouble(1, 1));
7200
7201 // The surface_no_scale_child_scale has its contents scaled by the page and
7202 // device scale factors, but needs to be scaled by the transform hierarchy
7203 // when drawing.
[email protected]fb661802013-03-25 01:59:327204 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297205 initial_child_scale,
7206 surface_no_scale_child_scale->draw_transform().matrix().getDouble(0, 0));
[email protected]fb661802013-03-25 01:59:327207 EXPECT_FLOAT_EQ(
[email protected]35a99a12013-05-09 23:52:297208 initial_child_scale,
7209 surface_no_scale_child_scale->draw_transform().matrix().getDouble(1, 1));
7210
7211 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
7212 // needs to be scaled by the device and page scale factors. It also needs to
7213 // be scaled by any transform heirarchy below its target surface.
7214 EXPECT_FLOAT_EQ(
7215 device_scale_factor * page_scale_factor * initial_child_scale,
7216 surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(0,
7217 0));
7218 EXPECT_FLOAT_EQ(
7219 device_scale_factor * page_scale_factor * initial_child_scale,
7220 surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(1,
7221 1));
[email protected]518ee582012-10-24 18:29:447222}
7223
[email protected]989386c2013-07-18 21:37:237224TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:327225 MockContentLayerClient delegate;
7226 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267227
[email protected]fb661802013-03-25 01:59:327228 gfx::Transform parent_scale_matrix;
7229 double initial_parent_scale = 1.75;
7230 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:267231
[email protected]fb661802013-03-25 01:59:327232 gfx::Transform child_scale_matrix;
7233 double initial_child_scale = 1.25;
7234 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:267235
[email protected]35a99a12013-05-09 23:52:297236 scoped_refptr<Layer> root = Layer::Create();
7237 root->SetBounds(gfx::Size(100, 100));
7238
[email protected]fb661802013-03-25 01:59:327239 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7240 SetLayerPropertiesForTesting(parent.get(),
7241 parent_scale_matrix,
7242 identity_matrix,
7243 gfx::PointF(),
7244 gfx::PointF(),
7245 gfx::Size(100, 100),
7246 true);
[email protected]6a9cff92012-11-08 11:53:267247
[email protected]fb661802013-03-25 01:59:327248 scoped_refptr<ContentLayer> child_scale =
7249 CreateDrawableContentLayer(&delegate);
7250 SetLayerPropertiesForTesting(child_scale.get(),
7251 child_scale_matrix,
7252 identity_matrix,
7253 gfx::PointF(),
7254 gfx::PointF(2.f, 2.f),
7255 gfx::Size(10, 10),
7256 true);
[email protected]6a9cff92012-11-08 11:53:267257
[email protected]35a99a12013-05-09 23:52:297258 root->AddChild(parent);
7259
[email protected]fb661802013-03-25 01:59:327260 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:267261
[email protected]d600df7d2013-08-03 02:34:287262 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7263 host->SetRootLayer(root);
7264
[email protected]fb661802013-03-25 01:59:327265 // Now put an animating transform on child.
7266 int animation_id = AddAnimatedTransformToController(
7267 child_scale->layer_animation_controller(), 10.0, 30, 0);
[email protected]6a9cff92012-11-08 11:53:267268
[email protected]989386c2013-07-18 21:37:237269 {
7270 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537271 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7272 root.get(), root->bounds(), &render_surface_layer_list);
7273 inputs.can_adjust_raster_scales = true;
7274 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267275
[email protected]989386c2013-07-18 21:37:237276 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7277 // The layers with animating transforms should not compute a contents scale
7278 // other than 1 until they finish animating.
7279 EXPECT_CONTENTS_SCALE_EQ(1, child_scale);
7280 }
[email protected]6a9cff92012-11-08 11:53:267281
[email protected]fb661802013-03-25 01:59:327282 // Remove the animation, now it can save a raster scale.
7283 child_scale->layer_animation_controller()->RemoveAnimation(animation_id);
[email protected]6a9cff92012-11-08 11:53:267284
[email protected]989386c2013-07-18 21:37:237285 {
7286 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537287 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7288 root.get(), root->bounds(), &render_surface_layer_list);
7289 inputs.can_adjust_raster_scales = true;
7290 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:267291
[email protected]989386c2013-07-18 21:37:237292 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent);
7293 // The layers with animating transforms should not compute a contents scale
7294 // other than 1 until they finish animating.
7295 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale,
7296 child_scale);
7297 }
[email protected]6a9cff92012-11-08 11:53:267298}
7299
[email protected]989386c2013-07-18 21:37:237300TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:327301 MockContentLayerClient delegate;
7302 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:267303
[email protected]fb661802013-03-25 01:59:327304 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7305 SetLayerPropertiesForTesting(parent.get(),
7306 identity_matrix,
7307 identity_matrix,
7308 gfx::PointF(),
7309 gfx::PointF(),
7310 gfx::Size(30, 30),
7311 true);
[email protected]94f206c12012-08-25 00:09:147312
[email protected]fb661802013-03-25 01:59:327313 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7314 SetLayerPropertiesForTesting(child.get(),
7315 identity_matrix,
7316 identity_matrix,
7317 gfx::PointF(),
7318 gfx::PointF(2.f, 2.f),
7319 gfx::Size(10, 10),
7320 true);
[email protected]94f206c12012-08-25 00:09:147321
[email protected]fb661802013-03-25 01:59:327322 gfx::Transform replica_transform;
7323 replica_transform.Scale(1.0, -1.0);
7324 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7325 SetLayerPropertiesForTesting(replica.get(),
7326 replica_transform,
7327 identity_matrix,
7328 gfx::PointF(),
7329 gfx::PointF(2.f, 2.f),
7330 gfx::Size(10, 10),
7331 true);
[email protected]94f206c12012-08-25 00:09:147332
[email protected]fb661802013-03-25 01:59:327333 // This layer should end up in the same surface as child, with the same draw
7334 // and screen space transforms.
7335 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7336 CreateDrawableContentLayer(&delegate);
7337 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7338 identity_matrix,
7339 identity_matrix,
7340 gfx::PointF(),
7341 gfx::PointF(),
7342 gfx::Size(10, 10),
7343 true);
[email protected]94f206c12012-08-25 00:09:147344
[email protected]fb661802013-03-25 01:59:327345 parent->AddChild(child);
7346 child->AddChild(duplicate_child_non_owner);
7347 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:147348
[email protected]d600df7d2013-08-03 02:34:287349 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7350 host->SetRootLayer(parent);
7351
[email protected]989386c2013-07-18 21:37:237352 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:147353
[email protected]fb661802013-03-25 01:59:327354 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:537355 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7356 parent.get(), parent->bounds(), &render_surface_layer_list);
7357 inputs.device_scale_factor = device_scale_factor;
7358 inputs.can_adjust_raster_scales = true;
7359 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:147360
[email protected]fb661802013-03-25 01:59:327361 // We should have two render surfaces. The root's render surface and child's
7362 // render surface (it needs one because it has a replica layer).
7363 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:147364
[email protected]fb661802013-03-25 01:59:327365 gfx::Transform expected_parent_transform;
7366 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7367 parent->screen_space_transform());
7368 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
7369 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:147370
[email protected]fb661802013-03-25 01:59:327371 gfx::Transform expected_draw_transform;
7372 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
7373 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:147374
[email protected]fb661802013-03-25 01:59:327375 gfx::Transform expected_screen_space_transform;
7376 expected_screen_space_transform.Translate(
7377 device_scale_factor * child->position().x(),
7378 device_scale_factor * child->position().y());
7379 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
7380 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147381
[email protected]fb661802013-03-25 01:59:327382 gfx::Transform expected_duplicate_child_draw_transform =
7383 child->draw_transform();
7384 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
7385 duplicate_child_non_owner->draw_transform());
7386 EXPECT_TRANSFORMATION_MATRIX_EQ(
7387 child->screen_space_transform(),
7388 duplicate_child_non_owner->screen_space_transform());
7389 EXPECT_RECT_EQ(child->drawable_content_rect(),
7390 duplicate_child_non_owner->drawable_content_rect());
7391 EXPECT_EQ(child->content_bounds(),
7392 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:147393
[email protected]fb661802013-03-25 01:59:327394 gfx::Transform expected_render_surface_draw_transform;
7395 expected_render_surface_draw_transform.Translate(
7396 device_scale_factor * child->position().x(),
7397 device_scale_factor * child->position().y());
7398 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
7399 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147400
[email protected]fb661802013-03-25 01:59:327401 gfx::Transform expected_surface_draw_transform;
7402 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
7403 device_scale_factor * 2.f);
7404 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
7405 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:147406
[email protected]fb661802013-03-25 01:59:327407 gfx::Transform expected_surface_screen_space_transform;
7408 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
7409 device_scale_factor * 2.f);
7410 EXPECT_TRANSFORMATION_MATRIX_EQ(
7411 expected_surface_screen_space_transform,
7412 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147413
[email protected]fb661802013-03-25 01:59:327414 gfx::Transform expected_replica_draw_transform;
7415 expected_replica_draw_transform.matrix().setDouble(1, 1, -1.0);
7416 expected_replica_draw_transform.matrix().setDouble(0, 3, 6.0);
7417 expected_replica_draw_transform.matrix().setDouble(1, 3, 6.0);
7418 EXPECT_TRANSFORMATION_MATRIX_EQ(
7419 expected_replica_draw_transform,
7420 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:147421
[email protected]fb661802013-03-25 01:59:327422 gfx::Transform expected_replica_screen_space_transform;
7423 expected_replica_screen_space_transform.matrix().setDouble(1, 1, -1.0);
7424 expected_replica_screen_space_transform.matrix().setDouble(0, 3, 6.0);
7425 expected_replica_screen_space_transform.matrix().setDouble(1, 3, 6.0);
7426 EXPECT_TRANSFORMATION_MATRIX_EQ(
7427 expected_replica_screen_space_transform,
7428 child->render_surface()->replica_screen_space_transform());
7429 EXPECT_TRANSFORMATION_MATRIX_EQ(
7430 expected_replica_screen_space_transform,
7431 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:477432}
7433
[email protected]989386c2013-07-18 21:37:237434TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:327435 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
7436 MockContentLayerClient delegate;
7437 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:477438
[email protected]fb661802013-03-25 01:59:327439 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7440 SetLayerPropertiesForTesting(parent.get(),
7441 identity_matrix,
7442 identity_matrix,
7443 gfx::PointF(),
7444 gfx::PointF(),
7445 gfx::Size(33, 31),
7446 true);
[email protected]904e9132012-11-01 00:12:477447
[email protected]fb661802013-03-25 01:59:327448 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
7449 SetLayerPropertiesForTesting(child.get(),
7450 identity_matrix,
7451 identity_matrix,
7452 gfx::PointF(),
7453 gfx::PointF(),
7454 gfx::Size(13, 11),
7455 true);
[email protected]904e9132012-11-01 00:12:477456
[email protected]fb661802013-03-25 01:59:327457 gfx::Transform replica_transform;
7458 replica_transform.Scale(1.0, -1.0);
7459 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate);
7460 SetLayerPropertiesForTesting(replica.get(),
7461 replica_transform,
7462 identity_matrix,
7463 gfx::PointF(),
7464 gfx::PointF(),
7465 gfx::Size(13, 11),
7466 true);
[email protected]904e9132012-11-01 00:12:477467
[email protected]fb661802013-03-25 01:59:327468 // This layer should end up in the same surface as child, with the same draw
7469 // and screen space transforms.
7470 scoped_refptr<ContentLayer> duplicate_child_non_owner =
7471 CreateDrawableContentLayer(&delegate);
7472 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
7473 identity_matrix,
7474 identity_matrix,
7475 gfx::PointF(),
7476 gfx::PointF(),
7477 gfx::Size(13, 11),
7478 true);
[email protected]904e9132012-11-01 00:12:477479
[email protected]fb661802013-03-25 01:59:327480 parent->AddChild(child);
7481 child->AddChild(duplicate_child_non_owner);
7482 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:477483
[email protected]d600df7d2013-08-03 02:34:287484 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7485 host->SetRootLayer(parent);
7486
[email protected]873639e2013-07-24 19:56:317487 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:537488
7489 RenderSurfaceLayerList render_surface_layer_list;
7490 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7491 parent.get(), parent->bounds(), &render_surface_layer_list);
7492 inputs.device_scale_factor = device_scale_factor;
7493 inputs.can_adjust_raster_scales = true;
7494 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:477495
[email protected]fb661802013-03-25 01:59:327496 // We should have two render surfaces. The root's render surface and child's
7497 // render surface (it needs one because it has a replica layer).
7498 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:477499
[email protected]fb661802013-03-25 01:59:327500 gfx::Transform identity_transform;
[email protected]904e9132012-11-01 00:12:477501
[email protected]fb661802013-03-25 01:59:327502 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7503 parent->screen_space_transform());
7504 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform());
7505 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform());
7506 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7507 child->screen_space_transform());
7508 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7509 duplicate_child_non_owner->draw_transform());
7510 EXPECT_TRANSFORMATION_MATRIX_EQ(
7511 identity_transform, duplicate_child_non_owner->screen_space_transform());
7512 EXPECT_RECT_EQ(child->drawable_content_rect(),
7513 duplicate_child_non_owner->drawable_content_rect());
7514 EXPECT_EQ(child->content_bounds(),
7515 duplicate_child_non_owner->content_bounds());
[email protected]904e9132012-11-01 00:12:477516
[email protected]fb661802013-03-25 01:59:327517 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7518 child->render_surface()->draw_transform());
7519 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7520 child->render_surface()->draw_transform());
7521 EXPECT_TRANSFORMATION_MATRIX_EQ(
7522 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:477523
[email protected]fb661802013-03-25 01:59:327524 gfx::Transform expected_replica_draw_transform;
7525 expected_replica_draw_transform.matrix().setDouble(1, 1, -1.0);
7526 EXPECT_TRANSFORMATION_MATRIX_EQ(
7527 expected_replica_draw_transform,
7528 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:477529
[email protected]fb661802013-03-25 01:59:327530 gfx::Transform expected_replica_screen_space_transform;
7531 expected_replica_screen_space_transform.matrix().setDouble(1, 1, -1.0);
7532 EXPECT_TRANSFORMATION_MATRIX_EQ(
7533 expected_replica_screen_space_transform,
7534 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:147535}
7536
[email protected]989386c2013-07-18 21:37:237537TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:327538 scoped_refptr<Layer> root = Layer::Create();
7539 scoped_refptr<Layer> child = Layer::Create();
7540 scoped_refptr<Layer> grand_child = Layer::Create();
7541 scoped_refptr<Layer> mask_layer = Layer::Create();
7542 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:147543
[email protected]fb661802013-03-25 01:59:327544 grand_child->SetReplicaLayer(replica_layer.get());
7545 child->AddChild(grand_child.get());
7546 child->SetMaskLayer(mask_layer.get());
7547 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:147548
[email protected]d600df7d2013-08-03 02:34:287549 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7550 host->SetRootLayer(root);
7551
[email protected]fb661802013-03-25 01:59:327552 int nonexistent_id = -1;
7553 EXPECT_EQ(root,
7554 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
7555 EXPECT_EQ(child,
7556 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
7557 EXPECT_EQ(
7558 grand_child,
7559 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
7560 EXPECT_EQ(
7561 mask_layer,
7562 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
7563 EXPECT_EQ(
7564 replica_layer,
7565 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
7566 EXPECT_EQ(
7567 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:147568}
7569
[email protected]989386c2013-07-18 21:37:237570TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:327571 scoped_refptr<Layer> root = Layer::Create();
7572 scoped_refptr<Layer> child = Layer::Create();
7573 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
7574 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:577575
[email protected]fb661802013-03-25 01:59:327576 const gfx::Transform identity_matrix;
7577 SetLayerPropertiesForTesting(root.get(),
7578 identity_matrix,
7579 identity_matrix,
7580 gfx::PointF(),
7581 gfx::PointF(),
7582 gfx::Size(100, 100),
7583 false);
7584 SetLayerPropertiesForTesting(child.get(),
7585 identity_matrix,
7586 identity_matrix,
7587 gfx::PointF(),
7588 gfx::PointF(),
7589 gfx::Size(10, 10),
7590 false);
7591 SetLayerPropertiesForTesting(grand_child.get(),
7592 identity_matrix,
7593 identity_matrix,
7594 gfx::PointF(),
7595 gfx::PointF(),
7596 gfx::Size(10, 10),
7597 false);
[email protected]498ec6e0e2012-11-30 18:24:577598
[email protected]fb661802013-03-25 01:59:327599 root->AddChild(child);
7600 child->AddChild(grand_child);
7601 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:577602
[email protected]d600df7d2013-08-03 02:34:287603 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7604 host->SetRootLayer(root);
7605
[email protected]fb661802013-03-25 01:59:327606 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:577607
[email protected]fb661802013-03-25 01:59:327608 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:577609}
7610
[email protected]989386c2013-07-18 21:37:237611TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:167612 FakeImplProxy proxy;
7613 FakeLayerTreeHostImpl host_impl(&proxy);
7614 host_impl.CreatePendingTree();
7615 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7616
7617 const gfx::Transform identity_matrix;
7618 SetLayerPropertiesForTesting(root.get(),
7619 identity_matrix,
7620 identity_matrix,
7621 gfx::PointF(),
7622 gfx::PointF(),
7623 gfx::Size(100, 100),
7624 false);
7625 root->SetDrawsContent(true);
7626
7627 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7628 SetLayerPropertiesForTesting(child.get(),
7629 identity_matrix,
7630 identity_matrix,
7631 gfx::PointF(),
7632 gfx::PointF(),
7633 gfx::Size(50, 50),
7634 false);
7635 child->SetDrawsContent(true);
7636 child->SetOpacity(0.0f);
7637
7638 // Add opacity animation.
7639 AddOpacityTransitionToController(
7640 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
7641
7642 root->AddChild(child.Pass());
7643
[email protected]c0ae06c12013-06-24 18:32:197644 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537645 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7646 root.get(), root->bounds(), &render_surface_layer_list);
7647 inputs.can_adjust_raster_scales = true;
7648 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:167649
7650 // We should have one render surface and two layers. The child
7651 // layer should be included even though it is transparent.
7652 ASSERT_EQ(1u, render_surface_layer_list.size());
7653 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
7654}
7655
[email protected]10aabcc32012-12-13 09:18:597656typedef std::tr1::tuple<bool, bool> LCDTextTestParam;
[email protected]989386c2013-07-18 21:37:237657class LCDTextTest
7658 : public LayerTreeHostCommonTestBase,
7659 public testing::TestWithParam<LCDTextTestParam> {
[email protected]fb661802013-03-25 01:59:327660 protected:
7661 virtual void SetUp() {
7662 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
[email protected]10aabcc32012-12-13 09:18:597663
[email protected]fb661802013-03-25 01:59:327664 root_ = Layer::Create();
7665 child_ = Layer::Create();
7666 grand_child_ = Layer::Create();
7667 child_->AddChild(grand_child_.get());
7668 root_->AddChild(child_.get());
[email protected]10aabcc32012-12-13 09:18:597669
[email protected]fb661802013-03-25 01:59:327670 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307671 SetLayerPropertiesForTesting(root_.get(),
[email protected]fb661802013-03-25 01:59:327672 identity_matrix,
7673 identity_matrix,
7674 gfx::PointF(),
7675 gfx::PointF(),
7676 gfx::Size(1, 1),
7677 false);
[email protected]22898ed2013-06-01 04:52:307678 SetLayerPropertiesForTesting(child_.get(),
[email protected]fb661802013-03-25 01:59:327679 identity_matrix,
7680 identity_matrix,
7681 gfx::PointF(),
7682 gfx::PointF(),
7683 gfx::Size(1, 1),
7684 false);
[email protected]22898ed2013-06-01 04:52:307685 SetLayerPropertiesForTesting(grand_child_.get(),
[email protected]fb661802013-03-25 01:59:327686 identity_matrix,
7687 identity_matrix,
7688 gfx::PointF(),
7689 gfx::PointF(),
7690 gfx::Size(1, 1),
7691 false);
[email protected]10aabcc32012-12-13 09:18:597692
[email protected]fb661802013-03-25 01:59:327693 child_->SetForceRenderSurface(std::tr1::get<1>(GetParam()));
[email protected]d600df7d2013-08-03 02:34:287694
7695 host_ = FakeLayerTreeHost::Create();
7696 host_->SetRootLayer(root_);
[email protected]fb661802013-03-25 01:59:327697 }
[email protected]10aabcc32012-12-13 09:18:597698
[email protected]fb661802013-03-25 01:59:327699 bool can_use_lcd_text_;
[email protected]d600df7d2013-08-03 02:34:287700 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]fb661802013-03-25 01:59:327701 scoped_refptr<Layer> root_;
7702 scoped_refptr<Layer> child_;
7703 scoped_refptr<Layer> grand_child_;
[email protected]10aabcc32012-12-13 09:18:597704};
7705
[email protected]fb661802013-03-25 01:59:327706TEST_P(LCDTextTest, CanUseLCDText) {
7707 // Case 1: Identity transform.
7708 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:307709 ExecuteCalculateDrawProperties(
7710 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327711 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7712 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7713 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597714
[email protected]fb661802013-03-25 01:59:327715 // Case 2: Integral translation.
7716 gfx::Transform integral_translation;
7717 integral_translation.Translate(1.0, 2.0);
7718 child_->SetTransform(integral_translation);
[email protected]22898ed2013-06-01 04:52:307719 ExecuteCalculateDrawProperties(
7720 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327721 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7722 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7723 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597724
[email protected]fb661802013-03-25 01:59:327725 // Case 3: Non-integral translation.
7726 gfx::Transform non_integral_translation;
7727 non_integral_translation.Translate(1.5, 2.5);
7728 child_->SetTransform(non_integral_translation);
[email protected]22898ed2013-06-01 04:52:307729 ExecuteCalculateDrawProperties(
7730 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327731 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7732 EXPECT_FALSE(child_->can_use_lcd_text());
7733 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597734
[email protected]fb661802013-03-25 01:59:327735 // Case 4: Rotation.
7736 gfx::Transform rotation;
7737 rotation.Rotate(10.0);
7738 child_->SetTransform(rotation);
[email protected]22898ed2013-06-01 04:52:307739 ExecuteCalculateDrawProperties(
7740 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327741 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7742 EXPECT_FALSE(child_->can_use_lcd_text());
7743 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597744
[email protected]fb661802013-03-25 01:59:327745 // Case 5: Scale.
7746 gfx::Transform scale;
7747 scale.Scale(2.0, 2.0);
7748 child_->SetTransform(scale);
[email protected]22898ed2013-06-01 04:52:307749 ExecuteCalculateDrawProperties(
7750 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327751 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7752 EXPECT_FALSE(child_->can_use_lcd_text());
7753 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597754
[email protected]fb661802013-03-25 01:59:327755 // Case 6: Skew.
7756 gfx::Transform skew;
7757 skew.SkewX(10.0);
7758 child_->SetTransform(skew);
[email protected]22898ed2013-06-01 04:52:307759 ExecuteCalculateDrawProperties(
7760 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327761 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7762 EXPECT_FALSE(child_->can_use_lcd_text());
7763 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597764
[email protected]fb661802013-03-25 01:59:327765 // Case 7: Translucent.
7766 child_->SetTransform(identity_matrix);
7767 child_->SetOpacity(0.5f);
[email protected]22898ed2013-06-01 04:52:307768 ExecuteCalculateDrawProperties(
7769 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327770 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7771 EXPECT_FALSE(child_->can_use_lcd_text());
7772 EXPECT_FALSE(grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597773
[email protected]fb661802013-03-25 01:59:327774 // Case 8: Sanity check: restore transform and opacity.
7775 child_->SetTransform(identity_matrix);
7776 child_->SetOpacity(1.f);
[email protected]22898ed2013-06-01 04:52:307777 ExecuteCalculateDrawProperties(
7778 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327779 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7780 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7781 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597782}
7783
[email protected]fd9a3b6d2013-08-03 00:46:177784TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
[email protected]fb661802013-03-25 01:59:327785 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
[email protected]22898ed2013-06-01 04:52:307786 ExecuteCalculateDrawProperties(
7787 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327788 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7789 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7790 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597791
[email protected]fb661802013-03-25 01:59:327792 // Add opacity animation.
7793 child_->SetOpacity(0.9f);
7794 AddOpacityTransitionToController(
7795 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:597796
[email protected]22898ed2013-06-01 04:52:307797 ExecuteCalculateDrawProperties(
7798 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_);
[email protected]fb661802013-03-25 01:59:327799 // Text AA should not be adjusted while animation is active.
7800 // Make sure LCD text AA setting remains unchanged.
7801 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text());
7802 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
7803 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:597804}
7805
7806INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
7807 LCDTextTest,
[email protected]fb661802013-03-25 01:59:327808 testing::Combine(testing::Bool(), testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:597809
[email protected]989386c2013-07-18 21:37:237810TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:197811 FakeImplProxy proxy;
7812 FakeLayerTreeHostImpl host_impl(&proxy);
7813 host_impl.CreatePendingTree();
7814 const gfx::Transform identity_matrix;
7815
7816 scoped_refptr<Layer> root = Layer::Create();
7817 SetLayerPropertiesForTesting(root.get(),
7818 identity_matrix,
7819 identity_matrix,
7820 gfx::PointF(),
7821 gfx::PointF(),
7822 gfx::Size(50, 50),
7823 false);
7824 root->SetIsDrawable(true);
7825
7826 scoped_refptr<Layer> child = Layer::Create();
7827 SetLayerPropertiesForTesting(child.get(),
7828 identity_matrix,
7829 identity_matrix,
7830 gfx::PointF(),
7831 gfx::PointF(),
7832 gfx::Size(40, 40),
7833 false);
7834 child->SetIsDrawable(true);
7835
7836 scoped_refptr<Layer> grand_child = Layer::Create();
7837 SetLayerPropertiesForTesting(grand_child.get(),
7838 identity_matrix,
7839 identity_matrix,
7840 gfx::PointF(),
7841 gfx::PointF(),
7842 gfx::Size(30, 30),
7843 false);
7844 grand_child->SetIsDrawable(true);
7845 grand_child->SetHideLayerAndSubtree(true);
7846
7847 child->AddChild(grand_child);
7848 root->AddChild(child);
7849
[email protected]d600df7d2013-08-03 02:34:287850 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7851 host->SetRootLayer(root);
7852
[email protected]989386c2013-07-18 21:37:237853 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537854 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7855 root.get(), root->bounds(), &render_surface_layer_list);
7856 inputs.can_adjust_raster_scales = true;
7857 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197858
7859 // We should have one render surface and two layers. The grand child has
7860 // hidden itself.
7861 ASSERT_EQ(1u, render_surface_layer_list.size());
7862 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237863 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
7864 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197865}
7866
[email protected]989386c2013-07-18 21:37:237867TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:197868 FakeImplProxy proxy;
7869 FakeLayerTreeHostImpl host_impl(&proxy);
7870 host_impl.CreatePendingTree();
7871 const gfx::Transform identity_matrix;
7872
7873 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7874 SetLayerPropertiesForTesting(root.get(),
7875 identity_matrix,
7876 identity_matrix,
7877 gfx::PointF(),
7878 gfx::PointF(),
7879 gfx::Size(50, 50),
7880 false);
7881 root->SetDrawsContent(true);
7882
7883 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7884 SetLayerPropertiesForTesting(child.get(),
7885 identity_matrix,
7886 identity_matrix,
7887 gfx::PointF(),
7888 gfx::PointF(),
7889 gfx::Size(40, 40),
7890 false);
7891 child->SetDrawsContent(true);
7892
7893 scoped_ptr<LayerImpl> grand_child =
7894 LayerImpl::Create(host_impl.pending_tree(), 3);
7895 SetLayerPropertiesForTesting(grand_child.get(),
7896 identity_matrix,
7897 identity_matrix,
7898 gfx::PointF(),
7899 gfx::PointF(),
7900 gfx::Size(30, 30),
7901 false);
7902 grand_child->SetDrawsContent(true);
7903 grand_child->SetHideLayerAndSubtree(true);
7904
7905 child->AddChild(grand_child.Pass());
7906 root->AddChild(child.Pass());
7907
7908 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537909 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7910 root.get(), root->bounds(), &render_surface_layer_list);
7911 inputs.can_adjust_raster_scales = true;
7912 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197913
7914 // We should have one render surface and two layers. The grand child has
7915 // hidden itself.
7916 ASSERT_EQ(1u, render_surface_layer_list.size());
7917 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237918 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
7919 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:197920}
7921
[email protected]989386c2013-07-18 21:37:237922TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:197923 FakeImplProxy proxy;
7924 FakeLayerTreeHostImpl host_impl(&proxy);
7925 host_impl.CreatePendingTree();
7926 const gfx::Transform identity_matrix;
7927
7928 scoped_refptr<Layer> root = Layer::Create();
7929 SetLayerPropertiesForTesting(root.get(),
7930 identity_matrix,
7931 identity_matrix,
7932 gfx::PointF(),
7933 gfx::PointF(),
7934 gfx::Size(50, 50),
7935 false);
7936 root->SetIsDrawable(true);
7937
7938 scoped_refptr<Layer> child = Layer::Create();
7939 SetLayerPropertiesForTesting(child.get(),
7940 identity_matrix,
7941 identity_matrix,
7942 gfx::PointF(),
7943 gfx::PointF(),
7944 gfx::Size(40, 40),
7945 false);
7946 child->SetIsDrawable(true);
7947 child->SetHideLayerAndSubtree(true);
7948
7949 scoped_refptr<Layer> grand_child = Layer::Create();
7950 SetLayerPropertiesForTesting(grand_child.get(),
7951 identity_matrix,
7952 identity_matrix,
7953 gfx::PointF(),
7954 gfx::PointF(),
7955 gfx::Size(30, 30),
7956 false);
7957 grand_child->SetIsDrawable(true);
7958
7959 child->AddChild(grand_child);
7960 root->AddChild(child);
7961
[email protected]d600df7d2013-08-03 02:34:287962 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7963 host->SetRootLayer(root);
7964
[email protected]989386c2013-07-18 21:37:237965 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:537966 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7967 root.get(), root->bounds(), &render_surface_layer_list);
7968 inputs.can_adjust_raster_scales = true;
7969 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:197970
7971 // We should have one render surface and one layers. The child has
7972 // hidden itself and the grand child.
7973 ASSERT_EQ(1u, render_surface_layer_list.size());
7974 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:237975 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:197976}
7977
[email protected]989386c2013-07-18 21:37:237978TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:197979 FakeImplProxy proxy;
7980 FakeLayerTreeHostImpl host_impl(&proxy);
7981 host_impl.CreatePendingTree();
7982 const gfx::Transform identity_matrix;
7983
7984 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
7985 SetLayerPropertiesForTesting(root.get(),
7986 identity_matrix,
7987 identity_matrix,
7988 gfx::PointF(),
7989 gfx::PointF(),
7990 gfx::Size(50, 50),
7991 false);
7992 root->SetDrawsContent(true);
7993
7994 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
7995 SetLayerPropertiesForTesting(child.get(),
7996 identity_matrix,
7997 identity_matrix,
7998 gfx::PointF(),
7999 gfx::PointF(),
8000 gfx::Size(40, 40),
8001 false);
8002 child->SetDrawsContent(true);
8003 child->SetHideLayerAndSubtree(true);
8004
8005 scoped_ptr<LayerImpl> grand_child =
8006 LayerImpl::Create(host_impl.pending_tree(), 3);
8007 SetLayerPropertiesForTesting(grand_child.get(),
8008 identity_matrix,
8009 identity_matrix,
8010 gfx::PointF(),
8011 gfx::PointF(),
8012 gfx::Size(30, 30),
8013 false);
8014 grand_child->SetDrawsContent(true);
8015
8016 child->AddChild(grand_child.Pass());
8017 root->AddChild(child.Pass());
8018
8019 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538020 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8021 root.get(), root->bounds(), &render_surface_layer_list);
8022 inputs.can_adjust_raster_scales = true;
8023 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:198024
8025 // We should have one render surface and one layers. The child has
8026 // hidden itself and the grand child.
8027 ASSERT_EQ(1u, render_surface_layer_list.size());
8028 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238029 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:198030}
8031
[email protected]30fe19ff2013-07-04 00:54:458032void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
8033
[email protected]989386c2013-07-18 21:37:238034TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458035 FakeImplProxy proxy;
8036 FakeLayerTreeHostImpl host_impl(&proxy);
8037 host_impl.CreatePendingTree();
8038 const gfx::Transform identity_matrix;
8039
8040 scoped_refptr<Layer> root = Layer::Create();
8041 SetLayerPropertiesForTesting(root.get(),
8042 identity_matrix,
8043 identity_matrix,
8044 gfx::PointF(),
8045 gfx::PointF(),
8046 gfx::Size(50, 50),
8047 false);
8048 root->SetIsDrawable(true);
8049
8050 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
8051 SetLayerPropertiesForTesting(copy_grand_parent.get(),
8052 identity_matrix,
8053 identity_matrix,
8054 gfx::PointF(),
8055 gfx::PointF(),
8056 gfx::Size(40, 40),
8057 false);
8058 copy_grand_parent->SetIsDrawable(true);
8059
8060 scoped_refptr<Layer> copy_parent = Layer::Create();
8061 SetLayerPropertiesForTesting(copy_parent.get(),
8062 identity_matrix,
8063 identity_matrix,
8064 gfx::PointF(),
8065 gfx::PointF(),
8066 gfx::Size(30, 30),
8067 false);
8068 copy_parent->SetIsDrawable(true);
8069 copy_parent->SetForceRenderSurface(true);
8070
8071 scoped_refptr<Layer> copy_layer = Layer::Create();
8072 SetLayerPropertiesForTesting(copy_layer.get(),
8073 identity_matrix,
8074 identity_matrix,
8075 gfx::PointF(),
8076 gfx::PointF(),
8077 gfx::Size(20, 20),
8078 false);
8079 copy_layer->SetIsDrawable(true);
8080
8081 scoped_refptr<Layer> copy_child = Layer::Create();
8082 SetLayerPropertiesForTesting(copy_child.get(),
8083 identity_matrix,
8084 identity_matrix,
8085 gfx::PointF(),
8086 gfx::PointF(),
8087 gfx::Size(20, 20),
8088 false);
8089 copy_child->SetIsDrawable(true);
8090
[email protected]ac020122013-07-12 23:45:538091 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
8092 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
8093 identity_matrix,
8094 identity_matrix,
8095 gfx::PointF(),
8096 gfx::PointF(),
8097 gfx::Size(40, 40),
8098 false);
8099 copy_grand_parent_sibling_before->SetIsDrawable(true);
8100
8101 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
8102 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
8103 identity_matrix,
8104 identity_matrix,
8105 gfx::PointF(),
8106 gfx::PointF(),
8107 gfx::Size(40, 40),
8108 false);
8109 copy_grand_parent_sibling_after->SetIsDrawable(true);
8110
[email protected]30fe19ff2013-07-04 00:54:458111 copy_layer->AddChild(copy_child);
8112 copy_parent->AddChild(copy_layer);
8113 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:538114 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:458115 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:538116 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:458117
[email protected]d600df7d2013-08-03 02:34:288118 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8119 host->SetRootLayer(root);
8120
[email protected]30fe19ff2013-07-04 00:54:458121 // Hide the copy_grand_parent and its subtree. But make a copy request in that
8122 // hidden subtree on copy_layer.
8123 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:538124 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
8125 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:458126 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8127 base::Bind(&EmptyCopyOutputCallback)));
8128 EXPECT_TRUE(copy_layer->HasCopyRequest());
8129
[email protected]989386c2013-07-18 21:37:238130 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538131 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8132 root.get(), root->bounds(), &render_surface_layer_list);
8133 inputs.can_adjust_raster_scales = true;
8134 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458135
[email protected]ac020122013-07-12 23:45:538136 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
8137 EXPECT_TRUE(copy_grand_parent->draw_properties().
8138 layer_or_descendant_has_copy_request);
8139 EXPECT_TRUE(copy_parent->draw_properties().
8140 layer_or_descendant_has_copy_request);
8141 EXPECT_TRUE(copy_layer->draw_properties().
8142 layer_or_descendant_has_copy_request);
8143 EXPECT_FALSE(copy_child->draw_properties().
8144 layer_or_descendant_has_copy_request);
8145 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
8146 layer_or_descendant_has_copy_request);
8147 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
8148 layer_or_descendant_has_copy_request);
8149
[email protected]30fe19ff2013-07-04 00:54:458150 // We should have three render surfaces, one for the root, one for the parent
8151 // since it owns a surface, and one for the copy_layer.
8152 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238153 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
8154 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
8155 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:458156
8157 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:538158 // copy_grand_parent is hidden along with its siblings, but the copy_parent
8159 // will appear since something in its subtree needs to be drawn for a copy
8160 // request.
[email protected]30fe19ff2013-07-04 00:54:458161 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238162 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
8163 EXPECT_EQ(copy_parent->id(),
8164 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458165
8166 // Nothing actually drawns into the copy parent, so only the copy_layer will
8167 // appear in its list, since it needs to be drawn for the copy request.
8168 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
8169 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238170 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458171
8172 // The copy_layer's render surface should have two contributing layers.
8173 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
8174 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:238175 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458176 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:238177 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:458178}
8179
[email protected]989386c2013-07-18 21:37:238180TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:458181 FakeImplProxy proxy;
8182 FakeLayerTreeHostImpl host_impl(&proxy);
8183 host_impl.CreatePendingTree();
8184 const gfx::Transform identity_matrix;
8185
8186 scoped_refptr<Layer> root = Layer::Create();
8187 SetLayerPropertiesForTesting(root.get(),
8188 identity_matrix,
8189 identity_matrix,
8190 gfx::PointF(),
8191 gfx::PointF(),
8192 gfx::Size(50, 50),
8193 false);
8194 root->SetIsDrawable(true);
8195
8196 scoped_refptr<Layer> copy_parent = Layer::Create();
8197 SetLayerPropertiesForTesting(copy_parent.get(),
8198 identity_matrix,
8199 identity_matrix,
8200 gfx::PointF(),
8201 gfx::PointF(),
8202 gfx::Size(),
8203 false);
8204 copy_parent->SetIsDrawable(true);
8205 copy_parent->SetMasksToBounds(true);
8206
8207 scoped_refptr<Layer> copy_layer = Layer::Create();
8208 SetLayerPropertiesForTesting(copy_layer.get(),
8209 identity_matrix,
8210 identity_matrix,
8211 gfx::PointF(),
8212 gfx::PointF(),
8213 gfx::Size(30, 30),
8214 false);
8215 copy_layer->SetIsDrawable(true);
8216
8217 scoped_refptr<Layer> copy_child = Layer::Create();
8218 SetLayerPropertiesForTesting(copy_child.get(),
8219 identity_matrix,
8220 identity_matrix,
8221 gfx::PointF(),
8222 gfx::PointF(),
8223 gfx::Size(20, 20),
8224 false);
8225 copy_child->SetIsDrawable(true);
8226
8227 copy_layer->AddChild(copy_child);
8228 copy_parent->AddChild(copy_layer);
8229 root->AddChild(copy_parent);
8230
[email protected]d600df7d2013-08-03 02:34:288231 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8232 host->SetRootLayer(root);
8233
[email protected]30fe19ff2013-07-04 00:54:458234 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
8235 base::Bind(&EmptyCopyOutputCallback)));
8236 EXPECT_TRUE(copy_layer->HasCopyRequest());
8237
[email protected]989386c2013-07-18 21:37:238238 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538239 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8240 root.get(), root->bounds(), &render_surface_layer_list);
8241 inputs.can_adjust_raster_scales = true;
8242 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:458243
8244 // We should have one render surface, as the others are clipped out.
8245 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:238246 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458247
8248 // The root render surface should only have 1 contributing layer, since the
8249 // other layers are empty/clipped away.
8250 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:238251 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:458252}
8253
[email protected]11a07b102013-07-24 17:33:198254TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
8255 FakeImplProxy proxy;
8256 FakeLayerTreeHostImpl host_impl(&proxy);
8257 host_impl.CreatePendingTree();
8258 const gfx::Transform identity_matrix;
8259
8260 scoped_refptr<Layer> root = Layer::Create();
8261 SetLayerPropertiesForTesting(root.get(),
8262 identity_matrix,
8263 identity_matrix,
8264 gfx::PointF(),
8265 gfx::PointF(),
8266 gfx::Size(50, 50),
8267 false);
8268 root->SetIsDrawable(true);
8269
8270 // The surface is moved slightly outside of the viewport.
8271 scoped_refptr<Layer> surface = Layer::Create();
8272 SetLayerPropertiesForTesting(surface.get(),
8273 identity_matrix,
8274 identity_matrix,
8275 gfx::PointF(),
8276 gfx::PointF(-10, -20),
8277 gfx::Size(),
8278 false);
8279 surface->SetForceRenderSurface(true);
8280
8281 scoped_refptr<Layer> surface_child = Layer::Create();
8282 SetLayerPropertiesForTesting(surface_child.get(),
8283 identity_matrix,
8284 identity_matrix,
8285 gfx::PointF(),
8286 gfx::PointF(),
8287 gfx::Size(50, 50),
8288 false);
8289 surface_child->SetIsDrawable(true);
8290
8291 surface->AddChild(surface_child);
8292 root->AddChild(surface);
8293
[email protected]d600df7d2013-08-03 02:34:288294 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
8295 host->SetRootLayer(root);
8296
[email protected]11a07b102013-07-24 17:33:198297 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:538298 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8299 root.get(), root->bounds(), &render_surface_layer_list);
8300 inputs.can_adjust_raster_scales = true;
8301 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:198302
8303 // The visible_content_rect for the |surface_child| should not be clipped by
8304 // the viewport.
8305 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
8306 surface_child->visible_content_rect().ToString());
8307}
8308
[email protected]ba565742012-11-10 09:29:488309} // namespace
8310} // namespace cc