Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: cc/trees/layer_tree_host_common_unittest.cc

Issue 2178073003: cc: Use setter methods on layer instead of SetLayerPropertiesForTesting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host_common.h" 5 #include "cc/trees/layer_tree_host_common.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 LayerImpl* target = AddChild<LayerImpl>(root); 121 LayerImpl* target = AddChild<LayerImpl>(root);
122 LayerImpl* drawing_layer = AddChild<LayerImpl>(target); 122 LayerImpl* drawing_layer = AddChild<LayerImpl>(target);
123 123
124 root->SetDrawsContent(true); 124 root->SetDrawsContent(true);
125 target->SetDrawsContent(true); 125 target->SetDrawsContent(true);
126 target->SetMasksToBounds(true); 126 target->SetMasksToBounds(true);
127 drawing_layer->SetDrawsContent(true); 127 drawing_layer->SetDrawsContent(true);
128 128
129 gfx::Transform identity; 129 gfx::Transform identity;
130 130
131 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), 131 root->SetBounds(gfx::Size(500, 500));
132 gfx::Size(500, 500), true, false, true); 132 root->test_properties()->force_render_surface = true;
133 SetLayerPropertiesForTesting(target, identity, gfx::Point3F(), 133 target->SetPosition(gfx::PointF(target_rect.origin()));
134 gfx::PointF(target_rect.origin()), 134 target->SetBounds(target_rect.size());
135 target_rect.size(), true, false, true); 135 target->test_properties()->force_render_surface = true;
136 SetLayerPropertiesForTesting(drawing_layer, layer_transform, gfx::Point3F(), 136 drawing_layer->SetTransform(layer_transform);
137 gfx::PointF(layer_rect.origin()), 137 drawing_layer->SetPosition(gfx::PointF(layer_rect.origin()));
138 layer_rect.size(), true, false, false); 138 drawing_layer->SetBounds(layer_rect.size());
139 drawing_layer->test_properties()->should_flatten_transform = false;
139 140
140 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 141 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
141 ExecuteCalculateDrawProperties(root); 142 ExecuteCalculateDrawProperties(root);
142 143
143 return drawing_layer; 144 return drawing_layer;
144 } 145 }
145 }; 146 };
146 147
147 TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { 148 TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
148 // Sanity check: For layers positioned at zero, with zero size, 149 // Sanity check: For layers positioned at zero, with zero size,
149 // and with identity transforms, then the draw transform, 150 // and with identity transforms, then the draw transform,
150 // screen space transform, and the hierarchy passed on to children 151 // screen space transform, and the hierarchy passed on to children
151 // layers should also be identity transforms. 152 // layers should also be identity transforms.
152 153
153 LayerImpl* parent = root_layer_for_testing(); 154 LayerImpl* parent = root_layer_for_testing();
154 LayerImpl* child = AddChild<LayerImpl>(parent); 155 LayerImpl* child = AddChild<LayerImpl>(parent);
155 LayerImpl* grand_child = AddChild<LayerImpl>(child); 156 LayerImpl* grand_child = AddChild<LayerImpl>(child);
156 157
157 gfx::Transform identity_matrix; 158 gfx::Transform identity_matrix;
158 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), 159 parent->SetBounds(gfx::Size(100, 100));
159 gfx::PointF(), gfx::Size(100, 100), true, false);
160 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
161 gfx::PointF(), gfx::Size(), true, false);
162 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
163 gfx::PointF(), gfx::Size(), true, false);
164 160
165 ExecuteCalculateDrawProperties(parent); 161 ExecuteCalculateDrawProperties(parent);
166 162
167 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); 163 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
168 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, 164 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
169 child->ScreenSpaceTransform()); 165 child->ScreenSpaceTransform());
170 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, 166 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
171 grand_child->DrawTransform()); 167 grand_child->DrawTransform());
172 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, 168 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
173 grand_child->ScreenSpaceTransform()); 169 grand_child->ScreenSpaceTransform());
174 } 170 }
175 171
176 TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) { 172 TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) {
177 // Tests that effect tree node gets a valid transform id when a layer 173 // Tests that effect tree node gets a valid transform id when a layer
178 // has opacity but doesn't create a render surface. 174 // has opacity but doesn't create a render surface.
179 LayerImpl* parent = root_layer_for_testing(); 175 LayerImpl* parent = root_layer_for_testing();
180 LayerImpl* child = AddChild<LayerImpl>(parent); 176 LayerImpl* child = AddChild<LayerImpl>(parent);
181 child->SetDrawsContent(true); 177 child->SetDrawsContent(true);
182 178
183 gfx::Transform identity_matrix; 179 gfx::Transform identity_matrix;
184 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), 180 parent->SetBounds(gfx::Size(100, 100));
185 gfx::PointF(), gfx::Size(100, 100), true, false); 181 child->SetPosition(gfx::PointF(10, 10));
186 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), 182 child->SetBounds(gfx::Size(100, 100));
187 gfx::PointF(10, 10), gfx::Size(100, 100), true,
188 false);
189 child->test_properties()->opacity = 0.f; 183 child->test_properties()->opacity = 0.f;
190 ExecuteCalculateDrawProperties(parent); 184 ExecuteCalculateDrawProperties(parent);
191 EffectTree& effect_tree = 185 EffectTree& effect_tree =
192 parent->layer_tree_impl()->property_trees()->effect_tree; 186 parent->layer_tree_impl()->property_trees()->effect_tree;
193 EffectNode* node = effect_tree.Node(child->effect_tree_index()); 187 EffectNode* node = effect_tree.Node(child->effect_tree_index());
194 const int transform_tree_size = parent->layer_tree_impl() 188 const int transform_tree_size = parent->layer_tree_impl()
195 ->property_trees() 189 ->property_trees()
196 ->transform_tree.next_available_id(); 190 ->transform_tree.next_available_id();
197 EXPECT_LT(node->transform_id, transform_tree_size); 191 EXPECT_LT(node->transform_id, transform_tree_size);
198 } 192 }
199 193
200 TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { 194 TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
201 gfx::Transform identity_matrix; 195 gfx::Transform identity_matrix;
202 LayerImpl* root = root_layer_for_testing(); 196 LayerImpl* root = root_layer_for_testing();
203 LayerImpl* layer = AddChild<LayerImpl>(root); 197 LayerImpl* layer = AddChild<LayerImpl>(root);
204 198
205 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
206 gfx::PointF(), gfx::Size(1, 2), true, false);
207
208 TransformTree& transform_tree = 199 TransformTree& transform_tree =
209 host_impl()->active_tree()->property_trees()->transform_tree; 200 host_impl()->active_tree()->property_trees()->transform_tree;
210 EffectTree& effect_tree = 201 EffectTree& effect_tree =
211 host_impl()->active_tree()->property_trees()->effect_tree; 202 host_impl()->active_tree()->property_trees()->effect_tree;
212 203
213 // Case 2: Setting the bounds of the layer should not affect either the draw 204 root->SetBounds(gfx::Size(1, 2));
205
206 // Case 1: Setting the bounds of the layer should not affect either the draw
214 // transform or the screenspace transform. 207 // transform or the screenspace transform.
215 gfx::Transform translation_to_center; 208 layer->SetBounds(gfx::Size(10, 12));
216 translation_to_center.Translate(5.0, 6.0);
217 SetLayerPropertiesForTesting(layer, identity_matrix, gfx::Point3F(),
218 gfx::PointF(), gfx::Size(10, 12), true, false);
219 ExecuteCalculateDrawProperties(root); 209 ExecuteCalculateDrawProperties(root);
220 EXPECT_TRANSFORMATION_MATRIX_EQ( 210 EXPECT_TRANSFORMATION_MATRIX_EQ(
221 identity_matrix, 211 identity_matrix,
222 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); 212 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
223 EXPECT_TRANSFORMATION_MATRIX_EQ( 213 EXPECT_TRANSFORMATION_MATRIX_EQ(
224 identity_matrix, 214 identity_matrix,
225 draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); 215 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
226 216
227 // Case 3: The anchor point by itself (without a layer transform) should have 217 // Case 2: The anchor point by itself (without a layer transform) should have
228 // no effect on the transforms. 218 // no effect on the transforms.
229 SetLayerPropertiesForTesting(layer, identity_matrix, 219 layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
230 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), 220 layer->SetBounds(gfx::Size(10, 12));
231 gfx::Size(10, 12), true, false);
232 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 221 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
233 ExecuteCalculateDrawProperties(root); 222 ExecuteCalculateDrawProperties(root);
234 EXPECT_TRANSFORMATION_MATRIX_EQ( 223 EXPECT_TRANSFORMATION_MATRIX_EQ(
235 identity_matrix, 224 identity_matrix,
236 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); 225 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
237 EXPECT_TRANSFORMATION_MATRIX_EQ( 226 EXPECT_TRANSFORMATION_MATRIX_EQ(
238 identity_matrix, 227 identity_matrix,
239 draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); 228 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
240 229
241 // Case 4: A change in actual position affects both the draw transform and 230 // Case 3: A change in actual position affects both the draw transform and
242 // screen space transform. 231 // screen space transform.
243 gfx::Transform position_transform; 232 gfx::Transform position_transform;
244 position_transform.Translate(0.f, 1.2f); 233 position_transform.Translate(0.f, 1.2f);
245 SetLayerPropertiesForTesting( 234 layer->SetPosition(gfx::PointF(0.f, 1.2f));
246 layer, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
247 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
248 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 235 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
249 ExecuteCalculateDrawProperties(root); 236 ExecuteCalculateDrawProperties(root);
250 EXPECT_TRANSFORMATION_MATRIX_EQ( 237 EXPECT_TRANSFORMATION_MATRIX_EQ(
251 position_transform, 238 position_transform,
252 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); 239 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
253 EXPECT_TRANSFORMATION_MATRIX_EQ( 240 EXPECT_TRANSFORMATION_MATRIX_EQ(
254 position_transform, 241 position_transform,
255 draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); 242 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
256 243
257 // Case 5: In the correct sequence of transforms, the layer transform should 244 // Case 4: In the correct sequence of transforms, the layer transform should
258 // pre-multiply the translation_to_center. This is easily tested by using a 245 // pre-multiply the translation-to-center. This is easily tested by using a
259 // scale transform, because scale and translation are not commutative. 246 // scale transform, because scale and translation are not commutative.
260 gfx::Transform layer_transform; 247 gfx::Transform layer_transform;
261 layer_transform.Scale3d(2.0, 2.0, 1.0); 248 layer_transform.Scale3d(2.0, 2.0, 1.0);
262 SetLayerPropertiesForTesting(layer, layer_transform, gfx::Point3F(), 249 layer->SetTransform(layer_transform);
263 gfx::PointF(), gfx::Size(10, 12), true, false); 250 layer->test_properties()->transform_origin = gfx::Point3F();
251 layer->SetPosition(gfx::PointF());
264 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 252 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
265 ExecuteCalculateDrawProperties(root); 253 ExecuteCalculateDrawProperties(root);
266 EXPECT_TRANSFORMATION_MATRIX_EQ( 254 EXPECT_TRANSFORMATION_MATRIX_EQ(
267 layer_transform, 255 layer_transform,
268 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); 256 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
269 EXPECT_TRANSFORMATION_MATRIX_EQ( 257 EXPECT_TRANSFORMATION_MATRIX_EQ(
270 layer_transform, 258 layer_transform,
271 draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); 259 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
272 260
273 // Case 6: The layer transform should occur with respect to the anchor point. 261 // Case 5: The layer transform should occur with respect to the anchor point.
274 gfx::Transform translation_to_anchor; 262 gfx::Transform translation_to_anchor;
275 translation_to_anchor.Translate(5.0, 0.0); 263 translation_to_anchor.Translate(5.0, 0.0);
276 gfx::Transform expected_result = 264 gfx::Transform expected_result =
277 translation_to_anchor * layer_transform * Inverse(translation_to_anchor); 265 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
278 SetLayerPropertiesForTesting(layer, layer_transform, 266 layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f);
279 gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(),
280 gfx::Size(10, 12), true, false);
281 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 267 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
282 ExecuteCalculateDrawProperties(root); 268 ExecuteCalculateDrawProperties(root);
283 EXPECT_TRANSFORMATION_MATRIX_EQ( 269 EXPECT_TRANSFORMATION_MATRIX_EQ(
284 expected_result, 270 expected_result,
285 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); 271 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
286 EXPECT_TRANSFORMATION_MATRIX_EQ( 272 EXPECT_TRANSFORMATION_MATRIX_EQ(
287 expected_result, 273 expected_result,
288 draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); 274 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
289 275
290 // Case 7: Verify that position pre-multiplies the layer transform. The 276 // Case 6: Verify that position pre-multiplies the layer transform. The
291 // current implementation of CalculateDrawProperties does this implicitly, but 277 // current implementation of CalculateDrawProperties does this implicitly, but
292 // it is still worth testing to detect accidental regressions. 278 // it is still worth testing to detect accidental regressions.
293 expected_result = position_transform * translation_to_anchor * 279 expected_result = position_transform * translation_to_anchor *
294 layer_transform * Inverse(translation_to_anchor); 280 layer_transform * Inverse(translation_to_anchor);
295 SetLayerPropertiesForTesting( 281 layer->SetPosition(gfx::PointF(0.f, 1.2f));
296 layer, layer_transform, gfx::Point3F(5.0f, 0.f, 0.f),
297 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
298 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 282 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
299 ExecuteCalculateDrawProperties(root); 283 ExecuteCalculateDrawProperties(root);
300 EXPECT_TRANSFORMATION_MATRIX_EQ( 284 EXPECT_TRANSFORMATION_MATRIX_EQ(
301 expected_result, 285 expected_result,
302 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); 286 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
303 EXPECT_TRANSFORMATION_MATRIX_EQ( 287 EXPECT_TRANSFORMATION_MATRIX_EQ(
304 expected_result, 288 expected_result,
305 draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); 289 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
306 } 290 }
307 291
(...skipping 10 matching lines...) Expand all
318 TestSharedBitmapManager shared_bitmap_manager; 302 TestSharedBitmapManager shared_bitmap_manager;
319 TestTaskGraphRunner task_graph_runner; 303 TestTaskGraphRunner task_graph_runner;
320 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 304 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
321 &task_graph_runner); 305 &task_graph_runner);
322 306
323 gfx::Transform identity_matrix; 307 gfx::Transform identity_matrix;
324 std::unique_ptr<LayerImpl> sublayer_scoped_ptr( 308 std::unique_ptr<LayerImpl> sublayer_scoped_ptr(
325 LayerImpl::Create(host_impl.active_tree(), 1)); 309 LayerImpl::Create(host_impl.active_tree(), 1));
326 LayerImpl* sublayer = sublayer_scoped_ptr.get(); 310 LayerImpl* sublayer = sublayer_scoped_ptr.get();
327 sublayer->SetDrawsContent(true); 311 sublayer->SetDrawsContent(true);
328 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(), 312 sublayer->SetBounds(gfx::Size(500, 500));
329 gfx::PointF(), gfx::Size(500, 500), true, false,
330 false);
331 313
332 std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr( 314 std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr(
333 LayerImpl::Create(host_impl.active_tree(), 2)); 315 LayerImpl::Create(host_impl.active_tree(), 2));
334 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); 316 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
335 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(), 317 scroll_layer->SetBounds(gfx::Size(10, 20));
336 gfx::PointF(), gfx::Size(10, 20), true, false,
337 false);
338 std::unique_ptr<LayerImpl> clip_layer_scoped_ptr( 318 std::unique_ptr<LayerImpl> clip_layer_scoped_ptr(
339 LayerImpl::Create(host_impl.active_tree(), 4)); 319 LayerImpl::Create(host_impl.active_tree(), 4));
340 LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); 320 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
341 321
342 scroll_layer->SetScrollClipLayer(clip_layer->id()); 322 scroll_layer->SetScrollClipLayer(clip_layer->id());
343 clip_layer->SetBounds( 323 clip_layer->SetBounds(
344 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), 324 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
345 scroll_layer->bounds().height() + kMaxScrollOffset.y())); 325 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
346 scroll_layer->SetScrollClipLayer(clip_layer->id()); 326 scroll_layer->SetScrollClipLayer(clip_layer->id());
347 SetScrollOffsetDelta(scroll_layer, kScrollDelta); 327 SetScrollOffsetDelta(scroll_layer, kScrollDelta);
348 gfx::Transform impl_transform; 328 gfx::Transform impl_transform;
349 scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr)); 329 scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr));
350 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); 330 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
351 clip_layer->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr)); 331 clip_layer->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr));
352 scroll_layer_raw_ptr->layer_tree_impl() 332 scroll_layer_raw_ptr->layer_tree_impl()
353 ->property_trees() 333 ->property_trees()
354 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(), 334 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(),
355 kScrollOffset); 335 kScrollOffset);
356 336
357 std::unique_ptr<LayerImpl> root( 337 std::unique_ptr<LayerImpl> root(
358 LayerImpl::Create(host_impl.active_tree(), 3)); 338 LayerImpl::Create(host_impl.active_tree(), 3));
359 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), 339 root->SetBounds(gfx::Size(3, 4));
360 gfx::PointF(), gfx::Size(3, 4), true, false,
361 false);
362 root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr)); 340 root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr));
363 root->SetHasRenderSurface(true); 341 root->SetHasRenderSurface(true);
364 LayerImpl* root_layer = root.get(); 342 LayerImpl* root_layer = root.get();
365 host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); 343 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
366 344
367 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, 345 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
368 scroll_layer->test_properties()->parent); 346 scroll_layer->test_properties()->parent);
369 gfx::Transform expected_transform = identity_matrix; 347 gfx::Transform expected_transform = identity_matrix;
370 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; 348 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
371 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * 349 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
372 page_scale * kDeviceScale), 350 page_scale * kDeviceScale),
373 MathUtil::Round(sub_layer_screen_position.y() * 351 MathUtil::Round(sub_layer_screen_position.y() *
374 page_scale * kDeviceScale)); 352 page_scale * kDeviceScale));
375 expected_transform.Scale(page_scale * kDeviceScale, 353 expected_transform.Scale(page_scale * kDeviceScale,
376 page_scale * kDeviceScale); 354 page_scale * kDeviceScale);
377 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, 355 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
378 sublayer->DrawTransform()); 356 sublayer->DrawTransform());
379 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, 357 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
380 sublayer->ScreenSpaceTransform()); 358 sublayer->ScreenSpaceTransform());
381 359
382 gfx::Transform arbitrary_translate; 360 gfx::Transform arbitrary_translate;
383 const float kTranslateX = 10.6f; 361 const float kTranslateX = 10.6f;
384 const float kTranslateY = 20.6f; 362 const float kTranslateY = 20.6f;
385 arbitrary_translate.Translate(kTranslateX, kTranslateY); 363 arbitrary_translate.Translate(kTranslateX, kTranslateY);
386 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate, 364 scroll_layer->SetTransform(arbitrary_translate);
387 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
388 true, false, false);
389 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; 365 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
390 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, 366 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
391 scroll_layer->test_properties()->parent); 367 scroll_layer->test_properties()->parent);
392 expected_transform.MakeIdentity(); 368 expected_transform.MakeIdentity();
393 expected_transform.Translate( 369 expected_transform.Translate(
394 MathUtil::Round(kTranslateX * page_scale * kDeviceScale + 370 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
395 sub_layer_screen_position.x() * page_scale * 371 sub_layer_screen_position.x() * page_scale *
396 kDeviceScale), 372 kDeviceScale),
397 MathUtil::Round(kTranslateY * page_scale * kDeviceScale + 373 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
398 sub_layer_screen_position.y() * page_scale * 374 sub_layer_screen_position.y() * page_scale *
(...skipping 28 matching lines...) Expand all
427 } 403 }
428 404
429 TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { 405 TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
430 gfx::Transform identity_matrix; 406 gfx::Transform identity_matrix;
431 LayerImpl* root = root_layer_for_testing(); 407 LayerImpl* root = root_layer_for_testing();
432 LayerImpl* parent = AddChild<LayerImpl>(root); 408 LayerImpl* parent = AddChild<LayerImpl>(root);
433 LayerImpl* child = AddChild<LayerImpl>(parent); 409 LayerImpl* child = AddChild<LayerImpl>(parent);
434 LayerImpl* grand_child = AddChild<LayerImpl>(child); 410 LayerImpl* grand_child = AddChild<LayerImpl>(child);
435 411
436 // One-time setup of root layer 412 // One-time setup of root layer
437 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 413 root->SetBounds(gfx::Size(1, 2));
438 gfx::PointF(), gfx::Size(1, 2), true, false);
439 414
440 TransformTree& transform_tree = 415 TransformTree& transform_tree =
441 host_impl()->active_tree()->property_trees()->transform_tree; 416 host_impl()->active_tree()->property_trees()->transform_tree;
442 EffectTree& effect_tree = 417 EffectTree& effect_tree =
443 host_impl()->active_tree()->property_trees()->effect_tree; 418 host_impl()->active_tree()->property_trees()->effect_tree;
444 419
445 // Case 1: parent's anchor point should not affect child or grand_child. 420 // Case 1: parent's anchor point should not affect child or grand_child.
446 SetLayerPropertiesForTesting(parent, identity_matrix, 421 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
447 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), 422 parent->SetBounds(gfx::Size(10, 12));
448 gfx::Size(10, 12), true, false); 423 child->SetBounds(gfx::Size(16, 18));
449 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), 424 grand_child->SetBounds(gfx::Size(76, 78));
450 gfx::PointF(), gfx::Size(16, 18), true, false);
451 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
452 gfx::PointF(), gfx::Size(76, 78), true, false);
453 ExecuteCalculateDrawProperties(root); 425 ExecuteCalculateDrawProperties(root);
454 426
455 EXPECT_TRANSFORMATION_MATRIX_EQ( 427 EXPECT_TRANSFORMATION_MATRIX_EQ(
456 identity_matrix, 428 identity_matrix,
457 draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); 429 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
458 EXPECT_TRANSFORMATION_MATRIX_EQ( 430 EXPECT_TRANSFORMATION_MATRIX_EQ(
459 identity_matrix, 431 identity_matrix,
460 draw_property_utils::ScreenSpaceTransform(child, transform_tree)); 432 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
461 EXPECT_TRANSFORMATION_MATRIX_EQ( 433 EXPECT_TRANSFORMATION_MATRIX_EQ(
462 identity_matrix, draw_property_utils::DrawTransform( 434 identity_matrix, draw_property_utils::DrawTransform(
463 grand_child, transform_tree, effect_tree)); 435 grand_child, transform_tree, effect_tree));
464 EXPECT_TRANSFORMATION_MATRIX_EQ( 436 EXPECT_TRANSFORMATION_MATRIX_EQ(
465 identity_matrix, 437 identity_matrix,
466 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); 438 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
467 439
468 // Case 2: parent's position affects child and grand_child. 440 // Case 2: parent's position affects child and grand_child.
469 gfx::Transform parent_position_transform; 441 gfx::Transform parent_position_transform;
470 parent_position_transform.Translate(0.f, 1.2f); 442 parent_position_transform.Translate(0.f, 1.2f);
471 SetLayerPropertiesForTesting( 443 parent->SetPosition(gfx::PointF(0.f, 1.2f));
472 parent, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
473 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
474 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
475 gfx::PointF(), gfx::Size(16, 18), true, false);
476 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
477 gfx::PointF(), gfx::Size(76, 78), true, false);
478 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 444 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
479 ExecuteCalculateDrawProperties(root); 445 ExecuteCalculateDrawProperties(root);
480 EXPECT_TRANSFORMATION_MATRIX_EQ( 446 EXPECT_TRANSFORMATION_MATRIX_EQ(
481 parent_position_transform, 447 parent_position_transform,
482 draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); 448 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
483 EXPECT_TRANSFORMATION_MATRIX_EQ( 449 EXPECT_TRANSFORMATION_MATRIX_EQ(
484 parent_position_transform, 450 parent_position_transform,
485 draw_property_utils::ScreenSpaceTransform(child, transform_tree)); 451 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
486 EXPECT_TRANSFORMATION_MATRIX_EQ( 452 EXPECT_TRANSFORMATION_MATRIX_EQ(
487 parent_position_transform, draw_property_utils::DrawTransform( 453 parent_position_transform, draw_property_utils::DrawTransform(
488 grand_child, transform_tree, effect_tree)); 454 grand_child, transform_tree, effect_tree));
489 EXPECT_TRANSFORMATION_MATRIX_EQ( 455 EXPECT_TRANSFORMATION_MATRIX_EQ(
490 parent_position_transform, 456 parent_position_transform,
491 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); 457 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
492 458
493 // Case 3: parent's local transform affects child and grandchild 459 // Case 3: parent's local transform affects child and grandchild
494 gfx::Transform parent_layer_transform; 460 gfx::Transform parent_layer_transform;
495 parent_layer_transform.Scale3d(2.0, 2.0, 1.0); 461 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
496 gfx::Transform parent_translation_to_anchor; 462 gfx::Transform parent_translation_to_anchor;
497 parent_translation_to_anchor.Translate(2.5, 3.0); 463 parent_translation_to_anchor.Translate(2.5, 3.0);
498 gfx::Transform parent_composite_transform = 464 gfx::Transform parent_composite_transform =
499 parent_translation_to_anchor * parent_layer_transform * 465 parent_translation_to_anchor * parent_layer_transform *
500 Inverse(parent_translation_to_anchor); 466 Inverse(parent_translation_to_anchor);
501 SetLayerPropertiesForTesting(parent, parent_layer_transform, 467 parent->SetTransform(parent_layer_transform);
502 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), 468 parent->SetPosition(gfx::PointF());
503 gfx::Size(10, 12), true, false);
504 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
505 gfx::PointF(), gfx::Size(16, 18), true, false);
506 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
507 gfx::PointF(), gfx::Size(76, 78), true, false);
508 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 469 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
509 ExecuteCalculateDrawProperties(root); 470 ExecuteCalculateDrawProperties(root);
510 EXPECT_TRANSFORMATION_MATRIX_EQ( 471 EXPECT_TRANSFORMATION_MATRIX_EQ(
511 parent_composite_transform, 472 parent_composite_transform,
512 draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); 473 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
513 EXPECT_TRANSFORMATION_MATRIX_EQ( 474 EXPECT_TRANSFORMATION_MATRIX_EQ(
514 parent_composite_transform, 475 parent_composite_transform,
515 draw_property_utils::ScreenSpaceTransform(child, transform_tree)); 476 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
516 EXPECT_TRANSFORMATION_MATRIX_EQ( 477 EXPECT_TRANSFORMATION_MATRIX_EQ(
517 parent_composite_transform, 478 parent_composite_transform,
518 draw_property_utils::DrawTransform(grand_child, transform_tree, 479 draw_property_utils::DrawTransform(grand_child, transform_tree,
519 effect_tree)); 480 effect_tree));
520 EXPECT_TRANSFORMATION_MATRIX_EQ( 481 EXPECT_TRANSFORMATION_MATRIX_EQ(
521 parent_composite_transform, 482 parent_composite_transform,
522 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); 483 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
523 } 484 }
524 485
525 TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { 486 TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
526 LayerImpl* root = root_layer_for_testing(); 487 LayerImpl* root = root_layer_for_testing();
527 LayerImpl* parent = AddChildToRoot<LayerImpl>(); 488 LayerImpl* parent = AddChildToRoot<LayerImpl>();
528 LayerImpl* child = AddChild<LayerImpl>(parent); 489 LayerImpl* child = AddChild<LayerImpl>(parent);
529 LayerImpl* grand_child = AddChild<LayerImpl>(child); 490 LayerImpl* grand_child = AddChild<LayerImpl>(child);
530 grand_child->SetDrawsContent(true);
531
532 gfx::Transform identity_matrix;
533 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
534 gfx::PointF(), gfx::Size(1, 2), true, false,
535 true);
536
537 // Child is set up so that a new render surface should be created.
538 child->test_properties()->opacity = 0.5f;
539 child->SetDrawsContent(true);
540 491
541 gfx::Transform parent_layer_transform; 492 gfx::Transform parent_layer_transform;
542 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); 493 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
543 gfx::Transform parent_translation_to_anchor; 494 gfx::Transform parent_translation_to_anchor;
544 parent_translation_to_anchor.Translate(25.0, 30.0); 495 parent_translation_to_anchor.Translate(25.0, 30.0);
545 496
546 gfx::Transform parent_composite_transform = 497 gfx::Transform parent_composite_transform =
547 parent_translation_to_anchor * parent_layer_transform * 498 parent_translation_to_anchor * parent_layer_transform *
548 Inverse(parent_translation_to_anchor); 499 Inverse(parent_translation_to_anchor);
549 gfx::Vector2dF parent_composite_scale = 500 gfx::Vector2dF parent_composite_scale =
550 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, 501 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
551 1.f); 502 1.f);
552 gfx::Transform surface_sublayer_transform; 503 gfx::Transform surface_sublayer_transform;
553 surface_sublayer_transform.Scale(parent_composite_scale.x(), 504 surface_sublayer_transform.Scale(parent_composite_scale.x(),
554 parent_composite_scale.y()); 505 parent_composite_scale.y());
555 gfx::Transform surface_sublayer_composite_transform = 506 gfx::Transform surface_sublayer_composite_transform =
556 parent_composite_transform * Inverse(surface_sublayer_transform); 507 parent_composite_transform * Inverse(surface_sublayer_transform);
557 508
558 SetLayerPropertiesForTesting(parent, parent_layer_transform, 509 root->SetBounds(gfx::Size(1, 2));
559 gfx::Point3F(25.0f, 30.0f, 0.f), gfx::PointF(), 510 parent->SetTransform(parent_layer_transform);
560 gfx::Size(100, 120), true, false, false); 511 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f);
561 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), 512 parent->SetBounds(gfx::Size(100, 120));
562 gfx::PointF(), gfx::Size(16, 18), true, false, 513 child->SetBounds(gfx::Size(16, 18));
563 true); 514 child->test_properties()->force_render_surface = true;
564 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), 515 grand_child->SetBounds(gfx::Size(8, 10));
565 gfx::PointF(), gfx::Size(8, 10), true, false, 516 grand_child->SetDrawsContent(true);
566 false);
567 ExecuteCalculateDrawProperties(root); 517 ExecuteCalculateDrawProperties(root);
568 518
569 // Render surface should have been created now. 519 // Render surface should have been created now.
570 ASSERT_TRUE(child->render_surface()); 520 ASSERT_TRUE(child->render_surface());
571 ASSERT_EQ(child->render_surface(), child->render_target()); 521 ASSERT_EQ(child->render_surface(), child->render_target());
572 522
573 // The child layer's draw transform should refer to its new render surface. 523 // The child layer's draw transform should refer to its new render surface.
574 // The screen-space transform, however, should still refer to the root. 524 // The screen-space transform, however, should still refer to the root.
575 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, 525 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
576 child->DrawTransform()); 526 child->DrawTransform());
(...skipping 11 matching lines...) Expand all
588 EXPECT_TRANSFORMATION_MATRIX_EQ( 538 EXPECT_TRANSFORMATION_MATRIX_EQ(
589 surface_sublayer_composite_transform, 539 surface_sublayer_composite_transform,
590 child->render_target()->screen_space_transform()); 540 child->render_target()->screen_space_transform());
591 } 541 }
592 542
593 TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { 543 TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
594 LayerImpl* root = root_layer_for_testing(); 544 LayerImpl* root = root_layer_for_testing();
595 LayerImpl* parent = AddChildToRoot<LayerImpl>(); 545 LayerImpl* parent = AddChildToRoot<LayerImpl>();
596 LayerImpl* child = AddChild<LayerImpl>(parent); 546 LayerImpl* child = AddChild<LayerImpl>(parent);
597 LayerImpl* grand_child = AddChild<LayerImpl>(child); 547 LayerImpl* grand_child = AddChild<LayerImpl>(child);
598 grand_child->SetDrawsContent(true);
599
600 gfx::Transform identity_matrix;
601 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
602 gfx::PointF(), gfx::Size(100, 100), true, false,
603 true);
604 548
605 gfx::Transform parent_transform; 549 gfx::Transform parent_transform;
606 parent_transform.Translate(10.0, 10.0); 550 parent_transform.Translate(10.0, 10.0);
607 551
608 gfx::Transform child_transform; 552 gfx::Transform child_transform;
609 child_transform.Rotate(45.0); 553 child_transform.Rotate(45.0);
610 554
611 // child gets a render surface when surfaces are enabled. 555 root->SetBounds(gfx::Size(100, 100));
612 SetLayerPropertiesForTesting(parent, parent_transform, gfx::Point3F(), 556 parent->SetTransform(parent_transform);
613 gfx::PointF(), gfx::Size(10, 10), true, false, 557 parent->SetBounds(gfx::Size(10, 10));
614 false); 558 child->SetTransform(child_transform);
615 SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(), 559 child->SetBounds(gfx::Size(10, 10));
616 gfx::PointF(), gfx::Size(10, 10), true, false, 560 child->test_properties()->force_render_surface = true;
617 true); 561 grand_child->SetPosition(gfx::PointF(2.f, 2.f));
618 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), 562 grand_child->SetBounds(gfx::Size(20, 20));
619 gfx::PointF(2.0, 2.0), gfx::Size(20, 20), true, 563 grand_child->SetDrawsContent(true);
620 false, false);
621 564
622 gfx::Transform expected_grand_child_screen_space_transform; 565 gfx::Transform expected_grand_child_screen_space_transform;
623 expected_grand_child_screen_space_transform.Translate(10.0, 10.0); 566 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
624 expected_grand_child_screen_space_transform.Rotate(45.0); 567 expected_grand_child_screen_space_transform.Rotate(45.0);
625 expected_grand_child_screen_space_transform.Translate(2.0, 2.0); 568 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
626 569
627 // First compute draw properties with separate surfaces enabled. 570 // First compute draw properties with separate surfaces enabled.
628 ExecuteCalculateDrawProperties(root); 571 ExecuteCalculateDrawProperties(root);
629 572
630 // The grand child's draw transform should be its offset wrt the child. 573 // The grand child's draw transform should be its offset wrt the child.
(...skipping 12 matching lines...) Expand all
643 grand_child->DrawTransform()); 586 grand_child->DrawTransform());
644 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, 587 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
645 grand_child->ScreenSpaceTransform()); 588 grand_child->ScreenSpaceTransform());
646 } 589 }
647 590
648 TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { 591 TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
649 LayerImpl* root = root_layer_for_testing(); 592 LayerImpl* root = root_layer_for_testing();
650 LayerImpl* parent = AddChildToRoot<LayerImpl>(); 593 LayerImpl* parent = AddChildToRoot<LayerImpl>();
651 LayerImpl* child = AddChild<LayerImpl>(parent); 594 LayerImpl* child = AddChild<LayerImpl>(parent);
652 LayerImpl* grand_child = AddChild<LayerImpl>(child); 595 LayerImpl* grand_child = AddChild<LayerImpl>(child);
653 grand_child->SetDrawsContent(true);
654 std::unique_ptr<LayerImpl> child_replica = 596 std::unique_ptr<LayerImpl> child_replica =
655 LayerImpl::Create(host_impl()->active_tree(), 100); 597 LayerImpl::Create(host_impl()->active_tree(), 100);
656 598
657 // One-time setup of root layer
658 gfx::Transform identity_matrix;
659 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
660 gfx::PointF(), gfx::Size(1, 2), true, false,
661 true);
662
663 // Child is set up so that a new render surface should be created.
664 child->test_properties()->opacity = 0.5f;
665
666 gfx::Transform parent_layer_transform; 599 gfx::Transform parent_layer_transform;
667 parent_layer_transform.Scale3d(2.0, 2.0, 1.0); 600 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
668 gfx::Transform parent_translation_to_anchor; 601 gfx::Transform parent_translation_to_anchor;
669 parent_translation_to_anchor.Translate(2.5, 3.0); 602 parent_translation_to_anchor.Translate(2.5, 3.0);
670 gfx::Transform parent_composite_transform = 603 gfx::Transform parent_composite_transform =
671 parent_translation_to_anchor * parent_layer_transform * 604 parent_translation_to_anchor * parent_layer_transform *
672 Inverse(parent_translation_to_anchor); 605 Inverse(parent_translation_to_anchor);
673 gfx::Transform replica_layer_transform; 606 gfx::Transform replica_layer_transform;
674 replica_layer_transform.Scale3d(3.0, 3.0, 1.0); 607 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
675 gfx::Vector2dF parent_composite_scale = 608 gfx::Vector2dF parent_composite_scale =
676 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, 609 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
677 1.f); 610 1.f);
678 gfx::Transform surface_sublayer_transform; 611 gfx::Transform surface_sublayer_transform;
679 surface_sublayer_transform.Scale(parent_composite_scale.x(), 612 surface_sublayer_transform.Scale(parent_composite_scale.x(),
680 parent_composite_scale.y()); 613 parent_composite_scale.y());
681 gfx::Transform replica_composite_transform = 614 gfx::Transform replica_composite_transform =
682 parent_composite_transform * replica_layer_transform * 615 parent_composite_transform * replica_layer_transform *
683 Inverse(surface_sublayer_transform); 616 Inverse(surface_sublayer_transform);
684 child_replica->SetDrawsContent(true);
685 // Child's render surface should not exist yet.
686 ASSERT_FALSE(child->render_surface());
687 617
688 SetLayerPropertiesForTesting(parent, parent_layer_transform, 618 root->SetBounds(gfx::Size(1, 2));
689 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), 619 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
690 gfx::Size(10, 12), true, false, false); 620 parent->SetTransform(parent_layer_transform);
691 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), 621 parent->SetBounds(gfx::Size(10, 12));
692 gfx::PointF(), gfx::Size(16, 18), true, false, 622 child->SetBounds(gfx::Size(16, 18));
693 true); 623 child->test_properties()->force_render_surface = true;
694 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), 624 grand_child->SetPosition(gfx::PointF(-0.5f, -0.5f));
695 gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true, 625 grand_child->SetBounds(gfx::Size(1, 1));
696 false, false); 626
697 SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform, 627 child_replica->SetTransform(replica_layer_transform);
698 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
699 false, false);
700 child->test_properties()->SetReplicaLayer(std::move(child_replica)); 628 child->test_properties()->SetReplicaLayer(std::move(child_replica));
701 629
702 ExecuteCalculateDrawProperties(root); 630 ExecuteCalculateDrawProperties(root);
703 631
704 // Render surface should have been created now. 632 // Render surface should have been created now.
705 ASSERT_TRUE(child->render_surface()); 633 ASSERT_TRUE(child->render_surface());
706 ASSERT_EQ(child->render_surface(), child->render_target()); 634 ASSERT_EQ(child->render_surface(), child->render_target());
707 635
708 EXPECT_TRANSFORMATION_MATRIX_EQ( 636 EXPECT_TRANSFORMATION_MATRIX_EQ(
709 replica_composite_transform, 637 replica_composite_transform,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 std::unique_ptr<LayerImpl> replica_of_rs1 = 678 std::unique_ptr<LayerImpl> replica_of_rs1 =
751 LayerImpl::Create(host_impl()->active_tree(), 101); 679 LayerImpl::Create(host_impl()->active_tree(), 101);
752 std::unique_ptr<LayerImpl> replica_of_rs2 = 680 std::unique_ptr<LayerImpl> replica_of_rs2 =
753 LayerImpl::Create(host_impl()->active_tree(), 102); 681 LayerImpl::Create(host_impl()->active_tree(), 102);
754 682
755 // In combination with descendant draws content, opacity != 1 forces the layer 683 // In combination with descendant draws content, opacity != 1 forces the layer
756 // to have a new render surface. 684 // to have a new render surface.
757 render_surface1->test_properties()->opacity = 0.5f; 685 render_surface1->test_properties()->opacity = 0.5f;
758 render_surface2->test_properties()->opacity = 0.33f; 686 render_surface2->test_properties()->opacity = 0.33f;
759 687
760 // One-time setup of root layer
761 gfx::Transform identity_matrix;
762 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
763 gfx::PointF(), gfx::Size(1, 2), true, false,
764 true);
765
766 // All layers in the tree are initialized with an anchor at .25 and a size of 688 // All layers in the tree are initialized with an anchor at .25 and a size of
767 // (10,10). matrix "A" is the composite layer transform used in all layers, 689 // (10,10). matrix "A" is the composite layer transform used in all layers,
768 // Matrix "R" is the composite replica transform used in all replica layers. 690 // Matrix "R" is the composite replica transform used in all replica layers.
769 gfx::Transform translation_to_anchor; 691 gfx::Transform translation_to_anchor;
770 translation_to_anchor.Translate(2.5, 0.0); 692 translation_to_anchor.Translate(2.5, 0.0);
771 gfx::Transform layer_transform; 693 gfx::Transform layer_transform;
772 layer_transform.Translate(1.0, 1.0); 694 layer_transform.Translate(1.0, 1.0);
773 gfx::Transform replica_layer_transform; 695 gfx::Transform replica_layer_transform;
774 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); 696 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
775 697
(...skipping 19 matching lines...) Expand all
795 gfx::Transform surface2_sublayer_transform; 717 gfx::Transform surface2_sublayer_transform;
796 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), 718 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
797 surface2_parent_transform_scale.y()); 719 surface2_parent_transform_scale.y());
798 720
799 // SS2 = transform given to the subtree of render_surface2 721 // SS2 = transform given to the subtree of render_surface2
800 gfx::Transform SS2 = surface2_sublayer_transform; 722 gfx::Transform SS2 = surface2_sublayer_transform;
801 // S2 = transform to move from render_surface2 pixels to the layer space of 723 // S2 = transform to move from render_surface2 pixels to the layer space of
802 // the owning layer 724 // the owning layer
803 gfx::Transform S2 = Inverse(surface2_sublayer_transform); 725 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
804 726
805 SetLayerPropertiesForTesting(parent, layer_transform, 727 root->SetBounds(gfx::Size(1, 2));
806 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), 728 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f);
807 gfx::Size(10, 10), true, false, false); 729 parent->SetTransform(layer_transform);
808 SetLayerPropertiesForTesting(render_surface1, layer_transform, 730 parent->SetBounds(gfx::Size(10, 10));
809 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), 731 render_surface1->test_properties()->transform_origin =
810 gfx::Size(10, 10), true, false, true); 732 gfx::Point3F(2.5f, 0.f, 0.f);
811 SetLayerPropertiesForTesting(render_surface2, layer_transform, 733 render_surface1->SetTransform(layer_transform);
812 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), 734 render_surface1->SetBounds(gfx::Size(10, 10));
813 gfx::Size(10, 10), true, false, true); 735 render_surface1->test_properties()->force_render_surface = true;
814 SetLayerPropertiesForTesting(child_of_root, layer_transform, 736 render_surface2->test_properties()->transform_origin =
815 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), 737 gfx::Point3F(2.5f, 0.f, 0.f);
816 gfx::Size(10, 10), true, false, false); 738 render_surface2->SetTransform(layer_transform);
817 SetLayerPropertiesForTesting(child_of_rs1, layer_transform, 739 render_surface2->SetBounds(gfx::Size(10, 10));
818 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), 740 render_surface2->test_properties()->force_render_surface = true;
819 gfx::Size(10, 10), true, false, false); 741 child_of_root->test_properties()->transform_origin =
820 SetLayerPropertiesForTesting(child_of_rs2, layer_transform, 742 gfx::Point3F(2.5f, 0.f, 0.f);
821 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), 743 child_of_root->SetTransform(layer_transform);
822 gfx::Size(10, 10), true, false, false); 744 child_of_root->SetBounds(gfx::Size(10, 10));
823 SetLayerPropertiesForTesting(grand_child_of_root, layer_transform, 745 child_of_rs1->test_properties()->transform_origin =
824 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), 746 gfx::Point3F(2.5f, 0.f, 0.f);
825 gfx::Size(10, 10), true, false, false); 747 child_of_rs1->SetTransform(layer_transform);
826 SetLayerPropertiesForTesting(grand_child_of_rs1, layer_transform, 748 child_of_rs1->SetBounds(gfx::Size(10, 10));
827 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), 749 child_of_rs2->test_properties()->transform_origin =
828 gfx::Size(10, 10), true, false, false); 750 gfx::Point3F(2.5f, 0.f, 0.f);
829 SetLayerPropertiesForTesting(grand_child_of_rs2, layer_transform, 751 child_of_rs2->SetTransform(layer_transform);
830 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), 752 child_of_rs2->SetBounds(gfx::Size(10, 10));
831 gfx::Size(10, 10), true, false, false); 753 grand_child_of_root->test_properties()->transform_origin =
832 SetLayerPropertiesForTesting(replica_of_rs1.get(), replica_layer_transform, 754 gfx::Point3F(2.5f, 0.f, 0.f);
833 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), 755 grand_child_of_root->SetTransform(layer_transform);
834 gfx::Size(), true, false, false); 756 grand_child_of_root->SetBounds(gfx::Size(10, 10));
835 SetLayerPropertiesForTesting(replica_of_rs2.get(), replica_layer_transform, 757 grand_child_of_rs1->test_properties()->transform_origin =
836 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), 758 gfx::Point3F(2.5f, 0.f, 0.f);
837 gfx::Size(), true, false, false); 759 grand_child_of_rs1->SetTransform(layer_transform);
760 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
761 grand_child_of_rs2->test_properties()->transform_origin =
762 gfx::Point3F(2.5f, 0.f, 0.f);
763 grand_child_of_rs2->SetTransform(layer_transform);
764 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
765 replica_of_rs1->test_properties()->transform_origin =
766 gfx::Point3F(2.5f, 0.f, 0.f);
767 replica_of_rs1->SetTransform(replica_layer_transform);
768 replica_of_rs2->test_properties()->transform_origin =
769 gfx::Point3F(2.5f, 0.f, 0.f);
770 replica_of_rs2->SetTransform(replica_layer_transform);
838 771
839 // We need to set parent on replica layers for property tree building. 772 // We need to set parent on replica layers for property tree building.
840 replica_of_rs1->test_properties()->parent = render_surface1; 773 replica_of_rs1->test_properties()->parent = render_surface1;
841 replica_of_rs2->test_properties()->parent = render_surface2; 774 replica_of_rs2->test_properties()->parent = render_surface2;
842 render_surface1->test_properties()->SetReplicaLayer( 775 render_surface1->test_properties()->SetReplicaLayer(
843 std::move(replica_of_rs1)); 776 std::move(replica_of_rs1));
844 render_surface2->test_properties()->SetReplicaLayer( 777 render_surface2->test_properties()->SetReplicaLayer(
845 std::move(replica_of_rs2)); 778 std::move(replica_of_rs2));
846 ExecuteCalculateDrawProperties(root); 779 ExecuteCalculateDrawProperties(root);
847 780
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 LayerImpl* child = AddChildToRoot<LayerImpl>(); 906 LayerImpl* child = AddChildToRoot<LayerImpl>();
974 child->SetDrawsContent(true); 907 child->SetDrawsContent(true);
975 LayerImpl* grand_child = AddChild<LayerImpl>(child); 908 LayerImpl* grand_child = AddChild<LayerImpl>(child);
976 grand_child->SetDrawsContent(true); 909 grand_child->SetDrawsContent(true);
977 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); 910 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
978 great_grand_child->SetDrawsContent(true); 911 great_grand_child->SetDrawsContent(true);
979 912
980 gfx::Transform rotation_about_y_axis; 913 gfx::Transform rotation_about_y_axis;
981 rotation_about_y_axis.RotateAboutYAxis(30.0); 914 rotation_about_y_axis.RotateAboutYAxis(30.0);
982 915
983 const gfx::Transform identity_matrix; 916 root->SetBounds(gfx::Size(100, 100));
984 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 917 child->SetTransform(rotation_about_y_axis);
985 gfx::PointF(), gfx::Size(100, 100), true, false, 918 child->SetBounds(gfx::Size(10, 10));
986 true); 919 child->test_properties()->force_render_surface = true;
987 SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(), 920 grand_child->SetTransform(rotation_about_y_axis);
988 gfx::PointF(), gfx::Size(10, 10), true, false, 921 grand_child->SetBounds(gfx::Size(10, 10));
989 true); 922 great_grand_child->SetBounds(gfx::Size(10, 10));
990 SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis,
991 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
992 true, false, false);
993 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
994 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
995 true, false, false);
996 923
997 // No layers in this test should preserve 3d. 924 // No layers in this test should preserve 3d.
998 ASSERT_TRUE(root->test_properties()->should_flatten_transform); 925 ASSERT_TRUE(root->test_properties()->should_flatten_transform);
999 ASSERT_TRUE(child->test_properties()->should_flatten_transform); 926 ASSERT_TRUE(child->test_properties()->should_flatten_transform);
1000 ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform); 927 ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform);
1001 ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform); 928 ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform);
1002 929
1003 gfx::Transform expected_child_draw_transform = rotation_about_y_axis; 930 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1004 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; 931 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1005 gfx::Transform expected_grand_child_draw_transform = 932 gfx::Transform expected_grand_child_draw_transform =
1006 rotation_about_y_axis; // draws onto child's render surface 933 rotation_about_y_axis; // draws onto child's render surface
1007 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; 934 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1008 flattened_rotation_about_y.FlattenTo2d(); 935 flattened_rotation_about_y.FlattenTo2d();
1009 gfx::Transform expected_grand_child_screen_space_transform = 936 gfx::Transform expected_grand_child_screen_space_transform =
1010 flattened_rotation_about_y * rotation_about_y_axis; 937 flattened_rotation_about_y * rotation_about_y_axis;
1011 gfx::Transform expected_great_grand_child_draw_transform = 938 gfx::Transform expected_great_grand_child_draw_transform =
1012 flattened_rotation_about_y; 939 flattened_rotation_about_y;
1013 gfx::Transform expected_great_grand_child_screen_space_transform = 940 gfx::Transform expected_great_grand_child_screen_space_transform =
1014 flattened_rotation_about_y * flattened_rotation_about_y; 941 flattened_rotation_about_y * flattened_rotation_about_y;
1015 942
1016 ExecuteCalculateDrawProperties(root); 943 ExecuteCalculateDrawProperties(root);
1017 944
1018 // The child's draw transform should have been taken by its surface. 945 // The child's draw transform should have been taken by its surface.
1019 ASSERT_TRUE(child->render_surface()); 946 ASSERT_TRUE(child->render_surface());
1020 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, 947 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1021 child->render_surface()->draw_transform()); 948 child->render_surface()->draw_transform());
1022 EXPECT_TRANSFORMATION_MATRIX_EQ( 949 EXPECT_TRANSFORMATION_MATRIX_EQ(
1023 expected_child_screen_space_transform, 950 expected_child_screen_space_transform,
1024 child->render_surface()->screen_space_transform()); 951 child->render_surface()->screen_space_transform());
1025 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); 952 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1026 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, 953 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1027 child->ScreenSpaceTransform()); 954 child->ScreenSpaceTransform());
1028 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, 955 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1029 grand_child->DrawTransform()); 956 grand_child->DrawTransform());
1030 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, 957 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1031 grand_child->ScreenSpaceTransform()); 958 grand_child->ScreenSpaceTransform());
1032 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, 959 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
1033 great_grand_child->DrawTransform()); 960 great_grand_child->DrawTransform());
1034 EXPECT_TRANSFORMATION_MATRIX_EQ( 961 EXPECT_TRANSFORMATION_MATRIX_EQ(
1035 expected_great_grand_child_screen_space_transform, 962 expected_great_grand_child_screen_space_transform,
1036 great_grand_child->ScreenSpaceTransform()); 963 great_grand_child->ScreenSpaceTransform());
1037 } 964 }
1038 965
1039 TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { 966 TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
1040 LayerImpl* root = root_layer_for_testing(); 967 LayerImpl* root = root_layer_for_testing();
1041 LayerImpl* child = AddChild<LayerImpl>(root); 968 LayerImpl* child = AddChild<LayerImpl>(root);
1042 LayerImpl* grand_child = AddChild<LayerImpl>(child); 969 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1043 970
1044 gfx::Transform child_transform; 971 gfx::Transform child_transform;
1045 child_transform.Translate(50.0, 50.0); 972 child_transform.Translate(50.0, 50.0);
1046 child_transform.RotateAboutZAxis(30.0); 973 child_transform.RotateAboutZAxis(30.0);
1047 974
1048 gfx::Transform grand_child_transform; 975 gfx::Transform grand_child_transform;
1049 grand_child_transform.RotateAboutYAxis(90.0); 976 grand_child_transform.RotateAboutYAxis(90.0);
1050 977
1051 const gfx::Transform identity_matrix; 978 root->SetBounds(gfx::Size(200, 200));
1052 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 979 child->SetTransform(child_transform);
1053 gfx::PointF(), gfx::Size(200, 200), true, false, 980 child->SetBounds(gfx::Size(10, 10));
1054 true); 981 grand_child->SetTransform(grand_child_transform);
1055 SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(), 982 grand_child->SetBounds(gfx::Size(100, 100));
1056 gfx::PointF(), gfx::Size(10, 10), true, false,
1057 false);
1058 SetLayerPropertiesForTesting(grand_child, grand_child_transform,
1059 gfx::Point3F(), gfx::PointF(),
1060 gfx::Size(100, 100), true, false, false);
1061
1062 grand_child->test_properties()->should_flatten_transform = false; 983 grand_child->test_properties()->should_flatten_transform = false;
1063 grand_child->SetDrawsContent(true); 984 grand_child->SetDrawsContent(true);
1064
1065 ExecuteCalculateDrawProperties(root); 985 ExecuteCalculateDrawProperties(root);
1066 986
1067 // Mapping grand_child's bounds to target space produces a non-empty rect 987 // Mapping grand_child's bounds to target space produces a non-empty rect
1068 // that is fully contained within the target's bounds, so grand_child should 988 // that is fully contained within the target's bounds, so grand_child should
1069 // be considered fully visible. 989 // be considered fully visible.
1070 EXPECT_EQ(gfx::Rect(grand_child->bounds()), 990 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
1071 grand_child->visible_layer_rect()); 991 grand_child->visible_layer_rect());
1072 } 992 }
1073 993
1074 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { 994 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
1075 // A layer that is empty in one axis, but not the other, was accidentally 995 // A layer that is empty in one axis, but not the other, was accidentally
1076 // skipping a necessary translation. Without that translation, the coordinate 996 // skipping a necessary translation. Without that translation, the coordinate
1077 // space of the layer's draw transform is incorrect. 997 // space of the layer's draw transform is incorrect.
1078 // 998 //
1079 // Normally this isn't a problem, because the layer wouldn't be drawn anyway, 999 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1080 // but if that layer becomes a render surface, then its draw transform is 1000 // but if that layer becomes a render surface, then its draw transform is
1081 // implicitly inherited by the rest of the subtree, which then is positioned 1001 // implicitly inherited by the rest of the subtree, which then is positioned
1082 // incorrectly as a result. 1002 // incorrectly as a result.
1083 1003
1084 LayerImpl* root = root_layer_for_testing(); 1004 LayerImpl* root = root_layer_for_testing();
1085 LayerImpl* child = AddChild<LayerImpl>(root); 1005 LayerImpl* child = AddChild<LayerImpl>(root);
1086 LayerImpl* grand_child = AddChild<LayerImpl>(child); 1006 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1087 grand_child->SetDrawsContent(true); 1007 grand_child->SetDrawsContent(true);
1088 1008
1009 root->SetBounds(gfx::Size(100, 100));
1089 // The child height is zero, but has non-zero width that should be accounted 1010 // The child height is zero, but has non-zero width that should be accounted
1090 // for while computing draw transforms. 1011 // for while computing draw transforms.
1091 const gfx::Transform identity_matrix; 1012 child->SetBounds(gfx::Size(10, 0));
1092 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 1013 child->test_properties()->force_render_surface = true;
1093 gfx::PointF(), gfx::Size(100, 100), true, false, 1014 grand_child->SetBounds(gfx::Size(10, 10));
1094 true);
1095 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1096 gfx::PointF(), gfx::Size(10, 0), true, false,
1097 true);
1098 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1099 gfx::PointF(), gfx::Size(10, 10), true, false,
1100 false);
1101
1102 ExecuteCalculateDrawProperties(root); 1015 ExecuteCalculateDrawProperties(root);
1103 1016
1104 ASSERT_TRUE(child->has_render_surface()); 1017 ASSERT_TRUE(child->has_render_surface());
1105 // This is the real test, the rest are sanity checks. 1018 // This is the real test, the rest are sanity checks.
1106 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, 1019 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
1107 child->render_surface()->draw_transform()); 1020 child->render_surface()->draw_transform());
1108 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); 1021 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1109 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, 1022 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
1110 grand_child->DrawTransform()); 1023 grand_child->DrawTransform());
1111 } 1024 }
1112 1025
1113 TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { 1026 TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) {
1114 const gfx::Transform identity_matrix; 1027 const gfx::Transform identity_matrix;
1115 LayerImpl* root = root_layer_for_testing(); 1028 LayerImpl* root = root_layer_for_testing();
1116 LayerImpl* render_surface = AddChild<LayerImpl>(root); 1029 LayerImpl* render_surface = AddChild<LayerImpl>(root);
1117 LayerImpl* child = AddChild<LayerImpl>(render_surface); 1030 LayerImpl* child = AddChild<LayerImpl>(render_surface);
1118 LayerImpl* grand_child = AddChild<LayerImpl>(child); 1031 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1119 1032
1120 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1121 gfx::PointF(), gfx::Size(100, 100), true, false,
1122 true);
1123 gfx::Transform translate; 1033 gfx::Transform translate;
1124 translate.Translate3d(5, 5, 5); 1034 translate.Translate3d(5, 5, 5);
1125 SetLayerPropertiesForTesting(render_surface, translate, gfx::Point3F(), 1035
1126 gfx::PointF(), gfx::Size(100, 100), true, false, 1036 root->SetBounds(gfx::Size(100, 100));
1127 true); 1037 render_surface->SetTransform(translate);
1128 SetLayerPropertiesForTesting(child, translate, gfx::Point3F(), gfx::PointF(), 1038 render_surface->SetBounds(gfx::Size(100, 100));
1129 gfx::Size(100, 100), true, false, false); 1039 render_surface->test_properties()->force_render_surface = true;
1130 SetLayerPropertiesForTesting(grand_child, translate, gfx::Point3F(), 1040 child->SetTransform(translate);
1131 gfx::PointF(), gfx::Size(100, 100), true, false, 1041 child->SetBounds(gfx::Size(100, 100));
1132 false); 1042 grand_child->SetTransform(translate);
1043 grand_child->SetBounds(gfx::Size(100, 100));
1133 grand_child->SetDrawsContent(true); 1044 grand_child->SetDrawsContent(true);
1134 1045
1135 // render_surface will have a sublayer scale because of device scale factor. 1046 // render_surface will have a sublayer scale because of device scale factor.
1136 float device_scale_factor = 2.0f; 1047 float device_scale_factor = 2.0f;
1137 LayerImplList render_surface_layer_list_impl; 1048 LayerImplList render_surface_layer_list_impl;
1138 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 1049 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1139 root, root->bounds(), translate, &render_surface_layer_list_impl); 1050 root, root->bounds(), translate, &render_surface_layer_list_impl);
1140 inputs.device_scale_factor = device_scale_factor; 1051 inputs.device_scale_factor = device_scale_factor;
1141 inputs.property_trees->needs_rebuild = true; 1052 inputs.property_trees->needs_rebuild = true;
1142 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 1053 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
1143 1054
1144 // Between grand_child and render_surface, we translate by (10, 10) and scale 1055 // Between grand_child and render_surface, we translate by (10, 10) and scale
1145 // by a factor of 2. 1056 // by a factor of 2.
1146 gfx::Vector2dF expected_translation(20.0f, 20.0f); 1057 gfx::Vector2dF expected_translation(20.0f, 20.0f);
1147 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(), 1058 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(),
1148 expected_translation); 1059 expected_translation);
1149 } 1060 }
1150 1061
1151 TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { 1062 TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
1152 // Transformations applied at the root of the tree should be forwarded 1063 // Transformations applied at the root of the tree should be forwarded
1153 // to child layers instead of applied to the root RenderSurface. 1064 // to child layers instead of applied to the root RenderSurface.
1154 const gfx::Transform identity_matrix; 1065 const gfx::Transform identity_matrix;
1155 LayerImpl* root = root_layer_for_testing(); 1066 LayerImpl* root = root_layer_for_testing();
1067 LayerImpl* child = AddChild<LayerImpl>(root);
1068
1156 root->SetDrawsContent(true); 1069 root->SetDrawsContent(true);
1157 LayerImpl* child = AddChild<LayerImpl>(root); 1070 root->SetBounds(gfx::Size(20, 20));
1158 child->SetDrawsContent(true); 1071 child->SetDrawsContent(true);
1159
1160 child->SetScrollClipLayer(root->id()); 1072 child->SetScrollClipLayer(root->id());
1161 1073 child->SetBounds(gfx::Size(20, 20));
1162 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1163 gfx::PointF(), gfx::Size(20, 20), true, false,
1164 true);
1165 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1166 gfx::PointF(), gfx::Size(20, 20), true, false,
1167 false);
1168 1074
1169 gfx::Transform translate; 1075 gfx::Transform translate;
1170 translate.Translate(50, 50); 1076 translate.Translate(50, 50);
1171 { 1077 {
1172 LayerImplList render_surface_layer_list_impl; 1078 LayerImplList render_surface_layer_list_impl;
1173 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 1079 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1174 root, root->bounds(), translate, &render_surface_layer_list_impl); 1080 root, root->bounds(), translate, &render_surface_layer_list_impl);
1175 inputs.property_trees->needs_rebuild = true; 1081 inputs.property_trees->needs_rebuild = true;
1176 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 1082 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
1177 EXPECT_TRANSFORMATION_MATRIX_EQ( 1083 EXPECT_TRANSFORMATION_MATRIX_EQ(
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 compositeSquared, root->draw_properties().target_space_transform); 1196 compositeSquared, root->draw_properties().target_space_transform);
1291 EXPECT_TRANSFORMATION_MATRIX_EQ( 1197 EXPECT_TRANSFORMATION_MATRIX_EQ(
1292 compositeSquared, child->draw_properties().target_space_transform); 1198 compositeSquared, child->draw_properties().target_space_transform);
1293 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, 1199 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1294 root->render_surface()->draw_transform()); 1200 root->render_surface()->draw_transform());
1295 } 1201 }
1296 } 1202 }
1297 1203
1298 TEST_F(LayerTreeHostCommonTest, 1204 TEST_F(LayerTreeHostCommonTest,
1299 RenderSurfaceListForRenderSurfaceWithClippedLayer) { 1205 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
1300 LayerImpl* parent = root_layer_for_testing(); 1206 LayerImpl* root = root_layer_for_testing();
1301 parent->SetMasksToBounds(true);
1302 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); 1207 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1303 LayerImpl* child = AddChild<LayerImpl>(render_surface1); 1208 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1209
1210 root->SetBounds(gfx::Size(10, 10));
1211 root->SetMasksToBounds(true);
1212 render_surface1->SetBounds(gfx::Size(10, 10));
1213 render_surface1->test_properties()->force_render_surface = true;
1304 child->SetDrawsContent(true); 1214 child->SetDrawsContent(true);
1215 child->SetPosition(gfx::PointF(30.f, 30.f));
1216 child->SetBounds(gfx::Size(10, 10));
1217 ExecuteCalculateDrawProperties(root);
1305 1218
1306 const gfx::Transform identity_matrix; 1219 // The child layer's content is entirely outside the root's clip rect, so
1307 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1308 gfx::PointF(), gfx::Size(10, 10), true, false,
1309 true);
1310 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1311 gfx::PointF(), gfx::Size(10, 10), true, false,
1312 true);
1313 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1314 gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true,
1315 false, false);
1316
1317 ExecuteCalculateDrawProperties(parent);
1318
1319 // The child layer's content is entirely outside the parent's clip rect, so
1320 // the intermediate render surface should not be listed here, even if it was 1220 // the intermediate render surface should not be listed here, even if it was
1321 // forced to be created. Render surfaces without children or visible content 1221 // forced to be created. Render surfaces without children or visible content
1322 // are unexpected at draw time (e.g. we might try to create a content texture 1222 // are unexpected at draw time (e.g. we might try to create a content texture
1323 // of size 0). 1223 // of size 0).
1324 ASSERT_TRUE(parent->render_surface()); 1224 ASSERT_TRUE(root->render_surface());
1325 EXPECT_EQ(1U, render_surface_layer_list_impl()->size()); 1225 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
1326 } 1226 }
1327 1227
1328 TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { 1228 TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
1329 LayerImpl* parent = root_layer_for_testing(); 1229 LayerImpl* root = root_layer_for_testing();
1330 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); 1230 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
1331 LayerImpl* child = AddChild<LayerImpl>(render_surface1); 1231 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1232
1233 render_surface1->SetBounds(gfx::Size(10, 10));
1234 render_surface1->test_properties()->force_render_surface = true;
1235 render_surface1->test_properties()->opacity = 0.f;
1236 child->SetBounds(gfx::Size(10, 10));
1332 child->SetDrawsContent(true); 1237 child->SetDrawsContent(true);
1333 1238
1334 const gfx::Transform identity_matrix;
1335 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1336 gfx::PointF(), gfx::Size(10, 10), true, false,
1337 true);
1338 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1339 gfx::PointF(), gfx::Size(10, 10), true, false,
1340 false);
1341 render_surface1->test_properties()->opacity = 0.f;
1342
1343 LayerImplList render_surface_layer_list; 1239 LayerImplList render_surface_layer_list;
1344 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 1240 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1345 parent, parent->bounds(), &render_surface_layer_list); 1241 root, root->bounds(), &render_surface_layer_list);
1346 inputs.can_adjust_raster_scales = true; 1242 inputs.can_adjust_raster_scales = true;
1347 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 1243 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
1348 1244
1349 // Since the layer is transparent, render_surface1->render_surface() should 1245 // Since the layer is transparent, render_surface1->render_surface() should
1350 // not have gotten added anywhere. Also, the drawable content rect should not 1246 // not have gotten added anywhere. Also, the drawable content rect should not
1351 // have been extended by the children. 1247 // have been extended by the children.
1352 ASSERT_TRUE(parent->render_surface()); 1248 ASSERT_TRUE(root->render_surface());
1353 EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); 1249 EXPECT_EQ(0U, root->render_surface()->layer_list().size());
1354 EXPECT_EQ(1U, render_surface_layer_list.size()); 1250 EXPECT_EQ(1U, render_surface_layer_list.size());
1355 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); 1251 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
1356 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); 1252 EXPECT_EQ(gfx::Rect(), root->drawable_content_rect());
1357 } 1253 }
1358 1254
1359 TEST_F(LayerTreeHostCommonTest, 1255 TEST_F(LayerTreeHostCommonTest,
1360 RenderSurfaceListForTransparentChildWithBackgroundFilter) { 1256 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
1361 LayerImpl* parent = root_layer_for_testing(); 1257 LayerImpl* root = root_layer_for_testing();
1362 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); 1258 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
1363 LayerImpl* child = AddChild<LayerImpl>(render_surface1); 1259 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1364 child->SetDrawsContent(true);
1365 1260
1366 const gfx::Transform identity_matrix; 1261 root->SetBounds(gfx::Size(10, 10));
1367 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), 1262 render_surface1->SetBounds(gfx::Size(10, 10));
1368 gfx::PointF(), gfx::Size(10, 10), true, false, 1263 render_surface1->test_properties()->force_render_surface = true;
1369 true);
1370 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1371 gfx::PointF(), gfx::Size(10, 10), true, false,
1372 true);
1373 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1374 gfx::PointF(), gfx::Size(10, 10), true, false,
1375 false);
1376 render_surface1->test_properties()->opacity = 0.f; 1264 render_surface1->test_properties()->opacity = 0.f;
1377 render_surface1->SetDrawsContent(true); 1265 render_surface1->SetDrawsContent(true);
1378 child->SetDrawsContent(true);
1379 FilterOperations filters; 1266 FilterOperations filters;
1380 filters.Append(FilterOperation::CreateBlurFilter(1.5f)); 1267 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
1381 render_surface1->test_properties()->background_filters = filters; 1268 render_surface1->test_properties()->background_filters = filters;
1269 child->SetBounds(gfx::Size(10, 10));
1270 child->SetDrawsContent(true);
1382 1271
1383 { 1272 {
1384 LayerImplList render_surface_layer_list; 1273 LayerImplList render_surface_layer_list;
1385 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 1274 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1386 parent, parent->bounds(), &render_surface_layer_list); 1275 root, root->bounds(), &render_surface_layer_list);
1387 inputs.can_adjust_raster_scales = true; 1276 inputs.can_adjust_raster_scales = true;
1388 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 1277 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
1389 EXPECT_EQ(2U, render_surface_layer_list.size()); 1278 EXPECT_EQ(2U, render_surface_layer_list.size());
1390 } 1279 }
1391 // The layer is fully transparent, but has a background filter, so it 1280 // The layer is fully transparent, but has a background filter, so it
1392 // shouldn't be skipped and should be drawn. 1281 // shouldn't be skipped and should be drawn.
1393 ASSERT_TRUE(parent->render_surface()); 1282 ASSERT_TRUE(root->render_surface());
1394 EXPECT_EQ(1U, parent->render_surface()->layer_list().size()); 1283 EXPECT_EQ(1U, root->render_surface()->layer_list().size());
1395 EXPECT_EQ(gfx::RectF(0, 0, 10, 10), 1284 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
1396 parent->render_surface()->DrawableContentRect()); 1285 root->render_surface()->DrawableContentRect());
1397 EffectTree& effect_tree = 1286 EffectTree& effect_tree =
1398 parent->layer_tree_impl()->property_trees()->effect_tree; 1287 root->layer_tree_impl()->property_trees()->effect_tree;
1399 EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index()); 1288 EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index());
1400 EXPECT_TRUE(node->is_drawn); 1289 EXPECT_TRUE(node->is_drawn);
1401 1290
1402 // When parent is transparent, the layer should not be drawn. 1291 // When root is transparent, the layer should not be drawn.
1403 parent->OnOpacityAnimated(0.f); 1292 root->OnOpacityAnimated(0.f);
1404 render_surface1->OnOpacityAnimated(1.f); 1293 render_surface1->OnOpacityAnimated(1.f);
1405 render_surface1->set_visible_layer_rect(gfx::Rect()); 1294 render_surface1->set_visible_layer_rect(gfx::Rect());
1406 { 1295 {
1407 LayerImplList render_surface_layer_list; 1296 LayerImplList render_surface_layer_list;
1408 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 1297 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1409 parent, parent->bounds(), &render_surface_layer_list); 1298 root, root->bounds(), &render_surface_layer_list);
1410 inputs.can_adjust_raster_scales = true; 1299 inputs.can_adjust_raster_scales = true;
1411 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 1300 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
1412 } 1301 }
1413 1302
1414 node = effect_tree.Node(render_surface1->effect_tree_index()); 1303 node = effect_tree.Node(render_surface1->effect_tree_index());
1415 EXPECT_FALSE(node->is_drawn); 1304 EXPECT_FALSE(node->is_drawn);
1416 EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect()); 1305 EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect());
1417 } 1306 }
1418 1307
1419 TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) { 1308 TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) {
1420 LayerImpl* root = root_layer_for_testing(); 1309 LayerImpl* root = root_layer_for_testing();
1421 LayerImpl* parent = AddChild<LayerImpl>(root); 1310 LayerImpl* parent = AddChild<LayerImpl>(root);
1422 LayerImpl* child1 = AddChild<LayerImpl>(parent); 1311 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1423 LayerImpl* child2 = AddChild<LayerImpl>(parent); 1312 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1424 child1->SetDrawsContent(true);
1425 child2->SetDrawsContent(true);
1426 1313
1427 const gfx::Transform identity_matrix;
1428 gfx::Transform scale_matrix; 1314 gfx::Transform scale_matrix;
1429 scale_matrix.Scale(2.0f, 2.0f); 1315 scale_matrix.Scale(2.0f, 2.0f);
1430 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 1316
1431 gfx::PointF(), gfx::Size(100, 100), true, false, 1317 root->SetBounds(gfx::Size(100, 100));
1432 true); 1318 parent->SetTransform(scale_matrix);
1433 SetLayerPropertiesForTesting(parent, scale_matrix, gfx::Point3F(),
1434 gfx::PointF(), gfx::Size(), true, false, true);
1435 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1436 gfx::PointF(0, 0), gfx::Size(25, 25), true,
1437 false, true);
1438 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1439 gfx::PointF(25, 25), gfx::Size(25, 25), true,
1440 false, true);
1441 FilterOperations filters; 1319 FilterOperations filters;
1442 filters.Append(FilterOperation::CreateBlurFilter(10.0f)); 1320 filters.Append(FilterOperation::CreateBlurFilter(10.0f));
1443 parent->test_properties()->filters = filters; 1321 parent->test_properties()->filters = filters;
1322 parent->test_properties()->force_render_surface = true;
1323 child1->SetBounds(gfx::Size(25, 25));
1324 child1->SetDrawsContent(true);
1325 child1->test_properties()->force_render_surface = true;
1326 child2->SetPosition(gfx::PointF(25, 25));
1327 child2->SetBounds(gfx::Size(25, 25));
1328 child2->SetDrawsContent(true);
1329 child2->test_properties()->force_render_surface = true;
1444 1330
1445 LayerImplList render_surface_layer_list; 1331 LayerImplList render_surface_layer_list;
1446 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 1332 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1447 root, root->bounds(), &render_surface_layer_list); 1333 root, root->bounds(), &render_surface_layer_list);
1448 inputs.can_adjust_raster_scales = true; 1334 inputs.can_adjust_raster_scales = true;
1449 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 1335 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
1450 1336
1451 ASSERT_TRUE(parent->render_surface()); 1337 ASSERT_TRUE(parent->render_surface());
1452 EXPECT_EQ(2U, parent->render_surface()->layer_list().size()); 1338 EXPECT_EQ(2U, parent->render_surface()->layer_list().size());
1453 EXPECT_EQ(4U, render_surface_layer_list.size()); 1339 EXPECT_EQ(4U, render_surface_layer_list.size());
1454 1340
1455 // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the 1341 // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the
1456 // blur (-30,-30 110x110), and then scaled by the scale matrix 1342 // blur (-30,-30 110x110), and then scaled by the scale matrix
1457 // (-60,-60 220x220). 1343 // (-60,-60 220x220).
1458 EXPECT_EQ(gfx::RectF(-60, -60, 220, 220), 1344 EXPECT_EQ(gfx::RectF(-60, -60, 220, 220),
1459 parent->render_surface()->DrawableContentRect()); 1345 parent->render_surface()->DrawableContentRect());
1460 } 1346 }
1461 1347
1462 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) { 1348 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) {
1463 LayerImpl* root = root_layer_for_testing(); 1349 LayerImpl* root = root_layer_for_testing();
1464 LayerImpl* child = AddChild<LayerImpl>(root); 1350 LayerImpl* child = AddChild<LayerImpl>(root);
1351
1352 root->SetBounds(gfx::Size(100, 100));
1353 child->SetBounds(gfx::Size(25, 25));
1465 child->SetDrawsContent(true); 1354 child->SetDrawsContent(true);
1466 1355 child->test_properties()->force_render_surface = true;
1467 SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(),
1468 gfx::PointF(), gfx::Size(100, 100), true, false,
1469 true);
1470 SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(),
1471 gfx::PointF(), gfx::Size(25, 25), true, false,
1472 true);
1473
1474 FilterOperations filters; 1356 FilterOperations filters;
1475 filters.Append(FilterOperation::CreateReferenceFilter( 1357 filters.Append(FilterOperation::CreateReferenceFilter(
1476 SkOffsetImageFilter::Make(50, 50, nullptr))); 1358 SkOffsetImageFilter::Make(50, 50, nullptr)));
1477 child->test_properties()->filters = filters; 1359 child->test_properties()->filters = filters;
1478
1479 ExecuteCalculateDrawProperties(root); 1360 ExecuteCalculateDrawProperties(root);
1480 1361
1481 // The render surface's size should be unaffected by the offset image filter; 1362 // The render surface's size should be unaffected by the offset image filter;
1482 // it need only have a drawable content rect large enough to contain the 1363 // it need only have a drawable content rect large enough to contain the
1483 // contents (at the new offset). 1364 // contents (at the new offset).
1484 ASSERT_TRUE(child->render_surface()); 1365 ASSERT_TRUE(child->render_surface());
1485 EXPECT_EQ(gfx::RectF(50, 50, 25, 25), 1366 EXPECT_EQ(gfx::RectF(50, 50, 25, 25),
1486 child->render_surface()->DrawableContentRect()); 1367 child->render_surface()->DrawableContentRect());
1487 } 1368 }
1488 1369
1489 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) { 1370 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) {
1490 const float device_scale_factor = 2.0f; 1371 const float device_scale_factor = 2.0f;
1491 1372
1492 LayerImpl* root = root_layer_for_testing(); 1373 LayerImpl* root = root_layer_for_testing();
1493 LayerImpl* child = AddChild<LayerImpl>(root); 1374 LayerImpl* child = AddChild<LayerImpl>(root);
1375
1376 root->SetBounds(gfx::Size(100, 100));
1377 child->SetBounds(gfx::Size(25, 25));
1494 child->SetDrawsContent(true); 1378 child->SetDrawsContent(true);
1495 1379 child->test_properties()->force_render_surface = true;
1496 SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(),
1497 gfx::PointF(), gfx::Size(100, 100), true, false,
1498 true);
1499 SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(),
1500 gfx::PointF(), gfx::Size(25, 25), true, false,
1501 true);
1502 1380
1503 FilterOperations filters; 1381 FilterOperations filters;
1504 filters.Append(FilterOperation::CreateReferenceFilter( 1382 filters.Append(FilterOperation::CreateReferenceFilter(
1505 SkOffsetImageFilter::Make(50, 50, nullptr))); 1383 SkOffsetImageFilter::Make(50, 50, nullptr)));
1506 child->test_properties()->filters = filters; 1384 child->test_properties()->filters = filters;
1507 1385
1508 ExecuteCalculateDrawProperties(root, device_scale_factor); 1386 ExecuteCalculateDrawProperties(root, device_scale_factor);
1509 1387
1510 // The render surface's size should be unaffected by the offset image filter; 1388 // The render surface's size should be unaffected by the offset image filter;
1511 // it need only have a drawable content rect large enough to contain the 1389 // it need only have a drawable content rect large enough to contain the
1512 // contents (at the new offset). All coordinates should be scaled by 2, 1390 // contents (at the new offset). All coordinates should be scaled by 2,
1513 // corresponding to the device scale factor. 1391 // corresponding to the device scale factor.
1514 ASSERT_TRUE(child->render_surface()); 1392 ASSERT_TRUE(child->render_surface());
1515 EXPECT_EQ(gfx::RectF(100, 100, 50, 50), 1393 EXPECT_EQ(gfx::RectF(100, 100, 50, 50),
1516 child->render_surface()->DrawableContentRect()); 1394 child->render_surface()->DrawableContentRect());
1517 } 1395 }
1518 1396
1519 TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { 1397 TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
1520 LayerImpl* parent = root_layer_for_testing(); 1398 LayerImpl* root = root_layer_for_testing();
1521 LayerImpl* child = AddChild<LayerImpl>(parent); 1399 LayerImpl* child = AddChild<LayerImpl>(root);
1400
1401 root->SetBounds(gfx::Size(10, 10));
1402 child->SetBounds(gfx::Size(10, 10));
1522 child->SetDrawsContent(true); 1403 child->SetDrawsContent(true);
1523 1404 child->SetBlendMode(SkXfermode::kMultiply_Mode);
1524 const gfx::Transform identity_matrix;
1525 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
1526 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1527 gfx::PointF(), gfx::Size(10, 10), true, false,
1528 true);
1529 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1530 gfx::PointF(), gfx::Size(10, 10), true, false,
1531 true);
1532
1533 child->SetBlendMode(blend_mode);
1534 child->test_properties()->opacity = 0.5f; 1405 child->test_properties()->opacity = 0.5f;
1535 1406 child->test_properties()->force_render_surface = true;
1536 ExecuteCalculateDrawProperties(parent); 1407 ExecuteCalculateDrawProperties(root);
1537 1408
1538 // Since the child layer has a blend mode other than normal, it should get 1409 // Since the child layer has a blend mode other than normal, it should get
1539 // its own render surface. Also, layer's draw_properties should contain the 1410 // its own render surface. Also, layer's draw_properties should contain the
1540 // default blend mode, since the render surface becomes responsible for 1411 // default blend mode, since the render surface becomes responsible for
1541 // applying the blend mode. 1412 // applying the blend mode.
1542 ASSERT_TRUE(child->render_surface()); 1413 ASSERT_TRUE(child->render_surface());
1543 EXPECT_EQ(1.0f, child->draw_opacity()); 1414 EXPECT_EQ(1.0f, child->draw_opacity());
1544 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity()); 1415 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
1545 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode()); 1416 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
1546 } 1417 }
1547 1418
1548 TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) { 1419 TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) {
1549 LayerImpl* root = root_layer_for_testing(); 1420 LayerImpl* root = root_layer_for_testing();
1550 LayerImpl* surface1 = AddChildToRoot<LayerImpl>(); 1421 LayerImpl* surface1 = AddChildToRoot<LayerImpl>();
1551 LayerImpl* not_surface = AddChild<LayerImpl>(surface1); 1422 LayerImpl* not_surface = AddChild<LayerImpl>(surface1);
1552 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface); 1423 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface);
1553 1424
1554 const gfx::Transform identity_matrix; 1425 root->SetBounds(gfx::Size(10, 10));
1555 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 1426 surface1->SetBounds(gfx::Size(10, 10));
1556 gfx::PointF(), gfx::Size(10, 10), true, false,
1557 true);
1558 SetLayerPropertiesForTesting(surface1, identity_matrix, gfx::Point3F(),
1559 gfx::PointF(), gfx::Size(10, 10), true, false,
1560 true);
1561 SetLayerPropertiesForTesting(not_surface, identity_matrix, gfx::Point3F(),
1562 gfx::PointF(), gfx::Size(10, 10), true, false,
1563 false);
1564 SetLayerPropertiesForTesting(surface2, identity_matrix, gfx::Point3F(),
1565 gfx::PointF(), gfx::Size(10, 10), true, false,
1566 true);
1567 surface1->SetDrawsContent(true); 1427 surface1->SetDrawsContent(true);
1428 surface1->test_properties()->opacity = 0.5f;
1429 surface1->test_properties()->force_render_surface = true;
1430 not_surface->SetBounds(gfx::Size(10, 10));
1431 not_surface->test_properties()->opacity = 0.5f;
1432 surface2->SetBounds(gfx::Size(10, 10));
1568 surface2->SetDrawsContent(true); 1433 surface2->SetDrawsContent(true);
1569
1570 surface1->test_properties()->opacity = 0.5f;
1571 not_surface->test_properties()->opacity = 0.5f;
1572 surface2->test_properties()->opacity = 0.5f; 1434 surface2->test_properties()->opacity = 0.5f;
1573 1435 surface2->test_properties()->force_render_surface = true;
1574 ExecuteCalculateDrawProperties(root); 1436 ExecuteCalculateDrawProperties(root);
1575 1437
1576 ASSERT_TRUE(surface1->render_surface()); 1438 ASSERT_TRUE(surface1->render_surface());
1577 ASSERT_FALSE(not_surface->render_surface()); 1439 ASSERT_FALSE(not_surface->render_surface());
1578 ASSERT_TRUE(surface2->render_surface()); 1440 ASSERT_TRUE(surface2->render_surface());
1579 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); 1441 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity());
1580 // surface2's draw opacity should include the opacity of not-surface and 1442 // surface2's draw opacity should include the opacity of not-surface and
1581 // itself, but not the opacity of surface1. 1443 // itself, but not the opacity of surface1.
1582 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); 1444 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity());
1583 } 1445 }
1584 1446
1585 TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) { 1447 TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1586 // Tests that when separate surfaces are disabled, a layer's draw opacity is 1448 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1587 // the product of all ancestor layer opacties and the layer's own opacity. 1449 // the product of all ancestor layer opacties and the layer's own opacity.
1588 // (Rendering will still be incorrect in situations where we really do need 1450 // (Rendering will still be incorrect in situations where we really do need
1589 // surfaces to apply opacity, such as when we have overlapping layers with an 1451 // surfaces to apply opacity, such as when we have overlapping layers with an
1590 // ancestor whose opacity is <1.) 1452 // ancestor whose opacity is <1.)
1591 LayerImpl* root = root_layer_for_testing(); 1453 LayerImpl* root = root_layer_for_testing();
1592 LayerImpl* parent = AddChild<LayerImpl>(root); 1454 LayerImpl* parent = AddChild<LayerImpl>(root);
1593 LayerImpl* child1 = AddChild<LayerImpl>(parent); 1455 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1594 LayerImpl* child2 = AddChild<LayerImpl>(parent); 1456 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1595 LayerImpl* grand_child = AddChild<LayerImpl>(child1); 1457 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1596 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); 1458 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1597 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); 1459 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1598 1460
1461 root->SetBounds(gfx::Size(100, 100));
1599 root->SetDrawsContent(true); 1462 root->SetDrawsContent(true);
1463 parent->SetBounds(gfx::Size(100, 100));
1600 parent->SetDrawsContent(true); 1464 parent->SetDrawsContent(true);
1465 child1->SetBounds(gfx::Size(100, 100));
1601 child1->SetDrawsContent(true); 1466 child1->SetDrawsContent(true);
1467 child1->test_properties()->opacity = 0.5f;
1468 child1->test_properties()->force_render_surface = true;
1469 child2->SetBounds(gfx::Size(100, 100));
1602 child2->SetDrawsContent(true); 1470 child2->SetDrawsContent(true);
1471 grand_child->SetBounds(gfx::Size(100, 100));
1603 grand_child->SetDrawsContent(true); 1472 grand_child->SetDrawsContent(true);
1473 grand_child->test_properties()->opacity = 0.5f;
1474 grand_child->test_properties()->force_render_surface = true;
1475 leaf_node1->SetBounds(gfx::Size(100, 100));
1604 leaf_node1->SetDrawsContent(true); 1476 leaf_node1->SetDrawsContent(true);
1477 leaf_node1->test_properties()->opacity = 0.5f;
1478 leaf_node2->SetBounds(gfx::Size(100, 100));
1605 leaf_node2->SetDrawsContent(true); 1479 leaf_node2->SetDrawsContent(true);
1606
1607 const gfx::Transform identity_matrix;
1608
1609 // child1 and grand_child get render surfaces when surfaces are enabled.
1610 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1611 gfx::PointF(), gfx::Size(100, 100), true, false,
1612 true);
1613 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1614 gfx::PointF(), gfx::Size(100, 100), true, false,
1615 false);
1616 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1617 gfx::PointF(), gfx::Size(100, 100), true, false,
1618 true);
1619 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1620 gfx::PointF(), gfx::Size(100, 100), true, false,
1621 false);
1622 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1623 gfx::PointF(), gfx::Size(100, 100), true, false,
1624 true);
1625 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1626 gfx::PointF(), gfx::Size(100, 100), true, false,
1627 false);
1628 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1629 gfx::PointF(), gfx::Size(100, 100), true, false,
1630 false);
1631
1632 child1->test_properties()->opacity = 0.5f;
1633 grand_child->test_properties()->opacity = 0.5f;
1634 leaf_node1->test_properties()->opacity = 0.5f;
1635 leaf_node2->test_properties()->opacity = 0.5f; 1480 leaf_node2->test_properties()->opacity = 0.5f;
1636 1481
1637 // With surfaces enabled, each layer's draw opacity is the product of layer 1482 // With surfaces enabled, each layer's draw opacity is the product of layer
1638 // opacities on the path from the layer to its render target, not including 1483 // opacities on the path from the layer to its render target, not including
1639 // the opacity of the layer that owns the target surface (since that opacity 1484 // the opacity of the layer that owns the target surface (since that opacity
1640 // is applied by the surface). 1485 // is applied by the surface).
1641 ExecuteCalculateDrawProperties(root); 1486 ExecuteCalculateDrawProperties(root);
1642 EXPECT_EQ(1.f, root->draw_opacity()); 1487 EXPECT_EQ(1.f, root->draw_opacity());
1643 EXPECT_EQ(1.f, parent->draw_opacity()); 1488 EXPECT_EQ(1.f, parent->draw_opacity());
1644 EXPECT_EQ(1.f, child1->draw_opacity()); 1489 EXPECT_EQ(1.f, child1->draw_opacity());
1645 EXPECT_EQ(1.f, child2->draw_opacity()); 1490 EXPECT_EQ(1.f, child2->draw_opacity());
1646 EXPECT_EQ(1.f, grand_child->draw_opacity()); 1491 EXPECT_EQ(1.f, grand_child->draw_opacity());
1647 EXPECT_EQ(0.5f, leaf_node1->draw_opacity()); 1492 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1648 EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); 1493 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1649 1494
1650 // With surfaces disabled, each layer's draw opacity is the product of layer 1495 // With surfaces disabled, each layer's draw opacity is the product of layer
1651 // opacities on the path from the layer to the root. 1496 // opacities on the path from the layer to the root.
1652 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); 1497 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1653 EXPECT_EQ(1.f, root->draw_opacity()); 1498 EXPECT_EQ(1.f, root->draw_opacity());
1654 EXPECT_EQ(1.f, parent->draw_opacity()); 1499 EXPECT_EQ(1.f, parent->draw_opacity());
1655 EXPECT_EQ(0.5f, child1->draw_opacity()); 1500 EXPECT_EQ(0.5f, child1->draw_opacity());
1656 EXPECT_EQ(1.f, child2->draw_opacity()); 1501 EXPECT_EQ(1.f, child2->draw_opacity());
1657 EXPECT_EQ(0.25f, grand_child->draw_opacity()); 1502 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1658 EXPECT_EQ(0.125f, leaf_node1->draw_opacity()); 1503 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1659 EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); 1504 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1660 } 1505 }
1661 1506
1662 TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { 1507 TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
1663 LayerImpl* parent = root_layer_for_testing(); 1508 LayerImpl* root = root_layer_for_testing();
1664 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); 1509 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1665 LayerImpl* child = AddChild<LayerImpl>(render_surface1); 1510 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1666 1511
1667 const gfx::Transform identity_matrix; 1512 root->SetBounds(gfx::Size(10, 10));
1668 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), 1513 render_surface1->SetBounds(gfx::Size(10, 10));
1669 gfx::PointF(), gfx::Size(10, 10), true, false); 1514 render_surface1->test_properties()->force_render_surface = true;
1670 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), 1515 child->SetBounds(gfx::Size(10, 10));
1671 gfx::PointF(), gfx::Size(10, 10), true, false);
1672 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1673 gfx::PointF(), gfx::Size(10, 10), true, false);
1674
1675 child->SetDrawsContent(true); 1516 child->SetDrawsContent(true);
1676 render_surface1->test_properties()->force_render_surface = true;
1677 1517
1678 { 1518 {
1679 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); 1519 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
1680 1520
1681 // The root layer always creates a render surface 1521 // The root layer always creates a render surface
1682 EXPECT_TRUE(parent->has_render_surface()); 1522 EXPECT_TRUE(root->has_render_surface());
1683 EXPECT_TRUE(render_surface1->has_render_surface()); 1523 EXPECT_TRUE(render_surface1->has_render_surface());
1684 } 1524 }
1685 1525
1686 { 1526 {
1687 render_surface1->test_properties()->force_render_surface = false; 1527 render_surface1->test_properties()->force_render_surface = false;
1688 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true; 1528 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true;
1689 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); 1529 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
1690 EXPECT_TRUE(parent->has_render_surface()); 1530 EXPECT_TRUE(root->has_render_surface());
1691 EXPECT_FALSE(render_surface1->has_render_surface()); 1531 EXPECT_FALSE(render_surface1->has_render_surface());
1692 } 1532 }
1693 } 1533 }
1694 1534
1695 TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { 1535 TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1696 // Render surfaces act as a flattening point for their subtree, so should 1536 // Render surfaces act as a flattening point for their subtree, so should
1697 // always flatten the target-to-screen space transform seen by descendants. 1537 // always flatten the target-to-screen space transform seen by descendants.
1698
1699 LayerImpl* root = root_layer_for_testing(); 1538 LayerImpl* root = root_layer_for_testing();
1700 LayerImpl* parent = AddChild<LayerImpl>(root); 1539 LayerImpl* parent = AddChild<LayerImpl>(root);
1701 LayerImpl* child = AddChild<LayerImpl>(parent); 1540 LayerImpl* child = AddChild<LayerImpl>(parent);
1702 LayerImpl* grand_child = AddChild<LayerImpl>(child); 1541 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1703 1542
1704 child->SetDrawsContent(true);
1705 grand_child->SetDrawsContent(true);
1706
1707 gfx::Transform rotation_about_y_axis; 1543 gfx::Transform rotation_about_y_axis;
1708 rotation_about_y_axis.RotateAboutYAxis(30.0); 1544 rotation_about_y_axis.RotateAboutYAxis(30.0);
1709 // Make |parent| have a render surface.
1710 parent->test_properties()->opacity = 0.9f;
1711 1545
1712 const gfx::Transform identity_matrix; 1546 root->SetBounds(gfx::Size(100, 100));
1713 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 1547 parent->SetTransform(rotation_about_y_axis);
1714 gfx::PointF(), gfx::Size(100, 100), true, false, 1548 parent->SetBounds(gfx::Size(10, 10));
1715 true); 1549 parent->test_properties()->force_render_surface = true;
1716 SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(), 1550 child->SetBounds(gfx::Size(10, 10));
1717 gfx::PointF(), gfx::Size(10, 10), true, false, 1551 child->SetDrawsContent(true);
1718 true); 1552 grand_child->SetBounds(gfx::Size(10, 10));
1719 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), 1553 grand_child->SetDrawsContent(true);
1720 gfx::PointF(), gfx::Size(10, 10), true, false,
1721 false);
1722 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1723 gfx::PointF(), gfx::Size(10, 10), true, false,
1724 false);
1725
1726 grand_child->test_properties()->should_flatten_transform = false; 1554 grand_child->test_properties()->should_flatten_transform = false;
1727
1728 // Only grand_child should preserve 3d.
1729 EXPECT_TRUE(root->test_properties()->should_flatten_transform);
1730 EXPECT_TRUE(parent->test_properties()->should_flatten_transform);
1731 EXPECT_TRUE(child->test_properties()->should_flatten_transform);
1732 EXPECT_FALSE(grand_child->test_properties()->should_flatten_transform);
1733
1734 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1735 flattened_rotation_about_y.FlattenTo2d();
1736
1737 ExecuteCalculateDrawProperties(root); 1555 ExecuteCalculateDrawProperties(root);
1738 1556
1739 EXPECT_TRUE(parent->render_surface()); 1557 EXPECT_TRUE(parent->render_surface());
1740 EXPECT_FALSE(child->render_surface()); 1558 EXPECT_FALSE(child->render_surface());
1741 EXPECT_FALSE(grand_child->render_surface()); 1559 EXPECT_FALSE(grand_child->render_surface());
1742 1560
1743 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); 1561 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1744 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, 1562 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
1745 grand_child->DrawTransform()); 1563 grand_child->DrawTransform());
1746 1564
1747 // The screen-space transform inherited by |child| and |grand_child| should 1565 // The screen-space transform inherited by |child| and |grand_child| should
1748 // have been flattened at their render target. In particular, the fact that 1566 // have been flattened at their render target. In particular, the fact that
1749 // |grand_child| happens to preserve 3d shouldn't affect this flattening. 1567 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1568 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1569 flattened_rotation_about_y.FlattenTo2d();
1750 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, 1570 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1751 child->ScreenSpaceTransform()); 1571 child->ScreenSpaceTransform());
1752 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, 1572 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1753 grand_child->ScreenSpaceTransform()); 1573 grand_child->ScreenSpaceTransform());
1754 } 1574 }
1755 1575
1756 TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { 1576 TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
1757 // The entire subtree of layers that are outside the clip rect should be 1577 // The entire subtree of layers that are outside the clip rect should be
1758 // culled away, and should not affect the render_surface_layer_list. 1578 // culled away, and should not affect the render_surface_layer_list.
1759 // 1579 //
1760 // The test tree is set up as follows: 1580 // The test tree is set up as follows:
1761 // - all layers except the leaf_nodes are forced to be a new render surface 1581 // - all layers except the leaf_nodes are forced to be a new render surface
1762 // that have something to draw. 1582 // that have something to draw.
1763 // - parent is a large container layer. 1583 // - parent is a large container layer.
1764 // - child has masksToBounds=true to cause clipping. 1584 // - child has MasksToBounds=true to cause clipping.
1765 // - grand_child is positioned outside of the child's bounds 1585 // - grand_child is positioned outside of the child's bounds
1766 // - great_grand_child is also kept outside child's bounds. 1586 // - great_grand_child is also kept outside child's bounds.
1767 // 1587 //
1768 // In this configuration, grand_child and great_grand_child are completely 1588 // In this configuration, grand_child and great_grand_child are completely
1769 // outside the clip rect, and they should never get scheduled on the list of 1589 // outside the clip rect, and they should never get scheduled on the list of
1770 // render surfaces. 1590 // render surfaces.
1771 1591
1772 LayerImpl* parent = root_layer_for_testing(); 1592 LayerImpl* root = root_layer_for_testing();
1773 LayerImpl* child = AddChildToRoot<LayerImpl>(); 1593 LayerImpl* child = AddChildToRoot<LayerImpl>();
1774 LayerImpl* grand_child = AddChild<LayerImpl>(child); 1594 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1775 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); 1595 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
1776 1596
1777 // leaf_node1 ensures that parent and child are kept on the 1597 // leaf_node1 ensures that root and child are kept on the
1778 // render_surface_layer_list, even though grand_child and great_grand_child 1598 // render_surface_layer_list, even though grand_child and great_grand_child
1779 // should be clipped. 1599 // should be clipped.
1780 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child); 1600 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
1601 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
1602
1603 root->SetBounds(gfx::Size(500, 500));
1604 child->SetBounds(gfx::Size(20, 20));
1605 child->SetMasksToBounds(true);
1606 child->test_properties()->force_render_surface = true;
1607 grand_child->SetPosition(gfx::PointF(45.f, 45.f));
1608 grand_child->SetBounds(gfx::Size(10, 10));
1609 great_grand_child->SetBounds(gfx::Size(10, 10));
1610 leaf_node1->SetBounds(gfx::Size(500, 500));
1781 leaf_node1->SetDrawsContent(true); 1611 leaf_node1->SetDrawsContent(true);
1782 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child); 1612 leaf_node1->SetBounds(gfx::Size(20, 20));
1783 leaf_node2->SetDrawsContent(true); 1613 leaf_node2->SetDrawsContent(true);
1784 1614 ExecuteCalculateDrawProperties(root);
1785 const gfx::Transform identity_matrix;
1786
1787 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1788 gfx::PointF(), gfx::Size(500, 500), true, false,
1789 true);
1790 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1791 gfx::PointF(), gfx::Size(20, 20), true, false,
1792 true);
1793 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1794 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1795 false, false);
1796 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
1797 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1798 true, false, false);
1799 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1800 gfx::PointF(), gfx::Size(500, 500), true, false,
1801 false);
1802 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1803 gfx::PointF(), gfx::Size(20, 20), true, false,
1804 false);
1805
1806 child->SetMasksToBounds(true);
1807 child->test_properties()->opacity = 0.4f;
1808 grand_child->test_properties()->opacity = 0.5f;
1809 great_grand_child->test_properties()->opacity = 0.4f;
1810
1811 ExecuteCalculateDrawProperties(parent);
1812 1615
1813 ASSERT_EQ(2U, render_surface_layer_list_impl()->size()); 1616 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
1814 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id()); 1617 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
1815 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id()); 1618 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
1816 } 1619 }
1817 1620
1818 TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { 1621 TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
1819 // When a render surface has a clip rect, it is used to clip the content rect 1622 // When a render surface has a clip rect, it is used to clip the content rect
1820 // of the surface. 1623 // of the surface.
1821 1624
1822 // The test tree is set up as follows: 1625 // The test tree is set up as follows:
1823 // - parent is a container layer that masksToBounds=true to cause clipping. 1626 // - root is a container layer that masksToBounds=true to cause clipping.
1824 // - child is a render surface, which has a clip rect set to the bounds of 1627 // - child is a render surface, which has a clip rect set to the bounds of
1825 // the parent. 1628 // the root.
1826 // - grand_child is a render surface, and the only visible content in child. 1629 // - grand_child is a render surface, and the only visible content in child.
1827 // It is positioned outside of the clip rect from parent. 1630 // It is positioned outside of the clip rect from root.
1828 1631
1829 // In this configuration, grand_child should be outside the clipped 1632 // In this configuration, grand_child should be outside the clipped
1830 // content rect of the child, making grand_child not appear in the 1633 // content rect of the child, making grand_child not appear in the
1831 // render_surface_layer_list. 1634 // render_surface_layer_list.
1832 1635
1833 LayerImpl* parent = root_layer_for_testing(); 1636 LayerImpl* root = root_layer_for_testing();
1834 LayerImpl* child = AddChildToRoot<LayerImpl>(); 1637 LayerImpl* child = AddChildToRoot<LayerImpl>();
1835 LayerImpl* grand_child = AddChild<LayerImpl>(child); 1638 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1836 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); 1639 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
1837 leaf_node->SetDrawsContent(true);
1838 1640
1839 const gfx::Transform identity_matrix; 1641 const gfx::Transform identity_matrix;
1840 1642
1841 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), 1643 root->SetMasksToBounds(true);
1842 gfx::PointF(), gfx::Size(100, 100), true, false, 1644 root->SetBounds(gfx::Size(100, 100));
1843 true); 1645 child->SetBounds(gfx::Size(20, 20));
1844 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), 1646 child->test_properties()->force_render_surface = true;
1845 gfx::PointF(), gfx::Size(20, 20), true, false, 1647 grand_child->SetPosition(gfx::PointF(200.f, 200.f));
1846 true); 1648 grand_child->SetBounds(gfx::Size(10, 10));
1847 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), 1649 grand_child->test_properties()->force_render_surface = true;
1848 gfx::PointF(200.f, 200.f), gfx::Size(10, 10), 1650 leaf_node->SetBounds(gfx::Size(10, 10));
1849 true, false, true); 1651 leaf_node->SetDrawsContent(true);
1850 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(), 1652 ExecuteCalculateDrawProperties(root);
1851 gfx::PointF(), gfx::Size(10, 10), true, false,
1852 false);
1853
1854 parent->SetMasksToBounds(true);
1855 child->test_properties()->opacity = 0.4f;
1856 grand_child->test_properties()->opacity = 0.4f;
1857
1858 ExecuteCalculateDrawProperties(parent);
1859 1653
1860 // We should cull child and grand_child from the 1654 // We should cull child and grand_child from the
1861 // render_surface_layer_list. 1655 // render_surface_layer_list.
1862 ASSERT_EQ(1U, render_surface_layer_list_impl()->size()); 1656 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
1863 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id()); 1657 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
1864 } 1658 }
1865 1659
1866 TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) { 1660 TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1867 // Tests that LayerImpl's IsClipped() property is set to true when: 1661 // Tests that LayerImpl's IsClipped() property is set to true when:
1868 // - the layer clips its subtree, e.g. masks to bounds, 1662 // - the layer clips its subtree, e.g. masks to bounds,
1869 // - the layer is clipped by an ancestor that contributes to the same 1663 // - the layer is clipped by an ancestor that contributes to the same
1870 // render target, 1664 // render target,
1871 // - a surface is clipped by an ancestor that contributes to the same 1665 // - a surface is clipped by an ancestor that contributes to the same
1872 // render target. 1666 // render target.
1873 // 1667 //
1874 // In particular, for a layer that owns a render surface: 1668 // In particular, for a layer that owns a render surface:
1875 // - the render surface inherits any clip from ancestors, and does NOT 1669 // - the render surface inherits any clip from ancestors, and does NOT
1876 // pass that clipped status to the layer itself. 1670 // pass that clipped status to the layer itself.
1877 // - but if the layer itself masks to bounds, it is considered clipped 1671 // - but if the layer itself masks to bounds, it is considered clipped
1878 // and propagates the clip to the subtree. 1672 // and propagates the clip to the subtree.
1879 1673
1880 const gfx::Transform identity_matrix; 1674 const gfx::Transform identity_matrix;
1881 LayerImpl* root = root_layer_for_testing(); 1675 LayerImpl* root = root_layer_for_testing();
1882 LayerImpl* parent = AddChild<LayerImpl>(root); 1676 LayerImpl* parent = AddChild<LayerImpl>(root);
1677 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1678 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1679 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1680 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1681 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1682
1683 root->SetBounds(gfx::Size(100, 100));
1684 parent->SetBounds(gfx::Size(100, 100));
1883 parent->SetDrawsContent(true); 1685 parent->SetDrawsContent(true);
1884 LayerImpl* child1 = AddChild<LayerImpl>(parent); 1686 child1->SetBounds(gfx::Size(100, 100));
1885 child1->SetDrawsContent(true); 1687 child1->SetDrawsContent(true);
1886 LayerImpl* child2 = AddChild<LayerImpl>(parent); 1688 child2->SetBounds(gfx::Size(100, 100));
1887 child2->SetDrawsContent(true); 1689 child2->SetDrawsContent(true);
1888 LayerImpl* grand_child = AddChild<LayerImpl>(child1); 1690 child2->test_properties()->force_render_surface = true;
1691 grand_child->SetBounds(gfx::Size(100, 100));
1889 grand_child->SetDrawsContent(true); 1692 grand_child->SetDrawsContent(true);
1890 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); 1693 leaf_node1->SetBounds(gfx::Size(100, 100));
1891 leaf_node1->SetDrawsContent(true); 1694 leaf_node1->SetDrawsContent(true);
1892 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); 1695 leaf_node2->SetBounds(gfx::Size(100, 100));
1893 leaf_node2->SetDrawsContent(true); 1696 leaf_node2->SetDrawsContent(true);
1894 1697
1895 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1896 gfx::PointF(), gfx::Size(100, 100), true, false,
1897 true);
1898 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1899 gfx::PointF(), gfx::Size(100, 100), true, false,
1900 false);
1901 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1902 gfx::PointF(), gfx::Size(100, 100), true, false,
1903 false);
1904 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1905 gfx::PointF(), gfx::Size(100, 100), true, false,
1906 true);
1907 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1908 gfx::PointF(), gfx::Size(100, 100), true, false,
1909 false);
1910 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1911 gfx::PointF(), gfx::Size(100, 100), true, false,
1912 false);
1913 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1914 gfx::PointF(), gfx::Size(100, 100), true, false,
1915 false);
1916
1917 // Case 1: nothing is clipped except the root render surface. 1698 // Case 1: nothing is clipped except the root render surface.
1918 ExecuteCalculateDrawProperties(root); 1699 ExecuteCalculateDrawProperties(root);
1919 1700
1920 ASSERT_TRUE(root->render_surface()); 1701 ASSERT_TRUE(root->render_surface());
1921 ASSERT_TRUE(child2->render_surface()); 1702 ASSERT_TRUE(child2->render_surface());
1922 1703
1923 EXPECT_FALSE(root->is_clipped()); 1704 EXPECT_FALSE(root->is_clipped());
1924 EXPECT_TRUE(root->render_surface()->is_clipped()); 1705 EXPECT_TRUE(root->render_surface()->is_clipped());
1925 EXPECT_FALSE(parent->is_clipped()); 1706 EXPECT_FALSE(parent->is_clipped());
1926 EXPECT_FALSE(child1->is_clipped()); 1707 EXPECT_FALSE(child1->is_clipped());
1927 EXPECT_FALSE(child2->is_clipped()); 1708 EXPECT_FALSE(child2->is_clipped());
1928 EXPECT_FALSE(child2->render_surface()->is_clipped()); 1709 EXPECT_FALSE(child2->render_surface()->is_clipped());
1929 EXPECT_FALSE(grand_child->is_clipped()); 1710 EXPECT_FALSE(grand_child->is_clipped());
1930 EXPECT_FALSE(leaf_node1->is_clipped()); 1711 EXPECT_FALSE(leaf_node1->is_clipped());
1931 EXPECT_FALSE(leaf_node2->is_clipped()); 1712 EXPECT_FALSE(leaf_node2->is_clipped());
1932 1713
1933 // Case 2: parent masksToBounds, so the parent, child1, and child2's 1714 // Case 2: parent MasksToBounds, so the parent, child1, and child2's
1934 // surface are clipped. But layers that contribute to child2's surface are 1715 // surface are clipped. But layers that contribute to child2's surface are
1935 // not clipped explicitly because child2's surface already accounts for 1716 // not clipped explicitly because child2's surface already accounts for
1936 // that clip. 1717 // that clip.
1937 parent->SetMasksToBounds(true); 1718 parent->SetMasksToBounds(true);
1938 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 1719 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1939 1720
1940 ExecuteCalculateDrawProperties(root); 1721 ExecuteCalculateDrawProperties(root);
1941 1722
1942 ASSERT_TRUE(root->render_surface()); 1723 ASSERT_TRUE(root->render_surface());
1943 ASSERT_TRUE(child2->render_surface()); 1724 ASSERT_TRUE(child2->render_surface());
1944 1725
1945 EXPECT_FALSE(root->is_clipped()); 1726 EXPECT_FALSE(root->is_clipped());
1946 EXPECT_TRUE(root->render_surface()->is_clipped()); 1727 EXPECT_TRUE(root->render_surface()->is_clipped());
1947 EXPECT_TRUE(parent->is_clipped()); 1728 EXPECT_TRUE(parent->is_clipped());
1948 EXPECT_TRUE(child1->is_clipped()); 1729 EXPECT_TRUE(child1->is_clipped());
1949 EXPECT_FALSE(child2->is_clipped()); 1730 EXPECT_FALSE(child2->is_clipped());
1950 EXPECT_TRUE(child2->render_surface()->is_clipped()); 1731 EXPECT_TRUE(child2->render_surface()->is_clipped());
1951 EXPECT_TRUE(grand_child->is_clipped()); 1732 EXPECT_TRUE(grand_child->is_clipped());
1952 EXPECT_TRUE(leaf_node1->is_clipped()); 1733 EXPECT_TRUE(leaf_node1->is_clipped());
1953 EXPECT_FALSE(leaf_node2->is_clipped()); 1734 EXPECT_FALSE(leaf_node2->is_clipped());
1954 1735
1955 parent->SetMasksToBounds(false); 1736 parent->SetMasksToBounds(false);
1956 1737
1957 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and 1738 // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and
1958 // child2's render surface is not clipped. 1739 // child2's render surface is not clipped.
1959 child2->SetMasksToBounds(true); 1740 child2->SetMasksToBounds(true);
1960 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 1741 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1961 1742
1962 ExecuteCalculateDrawProperties(root); 1743 ExecuteCalculateDrawProperties(root);
1963 1744
1964 ASSERT_TRUE(root->render_surface()); 1745 ASSERT_TRUE(root->render_surface());
1965 ASSERT_TRUE(child2->render_surface()); 1746 ASSERT_TRUE(child2->render_surface());
1966 1747
1967 EXPECT_FALSE(root->is_clipped()); 1748 EXPECT_FALSE(root->is_clipped());
1968 EXPECT_TRUE(root->render_surface()->is_clipped()); 1749 EXPECT_TRUE(root->render_surface()->is_clipped());
1969 EXPECT_FALSE(parent->is_clipped()); 1750 EXPECT_FALSE(parent->is_clipped());
1970 EXPECT_FALSE(child1->is_clipped()); 1751 EXPECT_FALSE(child1->is_clipped());
1971 EXPECT_TRUE(child2->is_clipped()); 1752 EXPECT_TRUE(child2->is_clipped());
1972 EXPECT_FALSE(child2->render_surface()->is_clipped()); 1753 EXPECT_FALSE(child2->render_surface()->is_clipped());
1973 EXPECT_FALSE(grand_child->is_clipped()); 1754 EXPECT_FALSE(grand_child->is_clipped());
1974 EXPECT_FALSE(leaf_node1->is_clipped()); 1755 EXPECT_FALSE(leaf_node1->is_clipped());
1975 EXPECT_TRUE(leaf_node2->is_clipped()); 1756 EXPECT_TRUE(leaf_node2->is_clipped());
1976 } 1757 }
1977 1758
1978 TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) { 1759 TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) {
1979 // Tests that when as long as layer is clipped, it's clip rect is set to 1760 // Tests that when as long as layer is clipped, it's clip rect is set to
1980 // correct value. 1761 // correct value.
1981 LayerImpl* root = root_layer_for_testing(); 1762 LayerImpl* root = root_layer_for_testing();
1982 LayerImpl* parent = AddChild<LayerImpl>(root); 1763 LayerImpl* parent = AddChild<LayerImpl>(root);
1983 LayerImpl* child = AddChild<LayerImpl>(parent); 1764 LayerImpl* child = AddChild<LayerImpl>(parent);
1984 1765
1766 root->SetBounds(gfx::Size(100, 100));
1985 root->SetDrawsContent(true); 1767 root->SetDrawsContent(true);
1768 parent->SetBounds(gfx::Size(100, 100));
1986 parent->SetDrawsContent(true); 1769 parent->SetDrawsContent(true);
1770 child->SetBounds(gfx::Size(100, 100));
1987 child->SetDrawsContent(true); 1771 child->SetDrawsContent(true);
1988
1989 const gfx::Transform identity_matrix;
1990
1991 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1992 gfx::PointF(), gfx::Size(100, 100), true, false,
1993 true);
1994 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1995 gfx::PointF(), gfx::Size(100, 100), true, false,
1996 false);
1997 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1998 gfx::PointF(), gfx::Size(100, 100), true, false,
1999 false);
2000 child->SetMasksToBounds(true); 1772 child->SetMasksToBounds(true);
2001 1773
2002 ExecuteCalculateDrawProperties(root); 1774 ExecuteCalculateDrawProperties(root);
2003 1775
2004 EXPECT_FALSE(root->is_clipped()); 1776 EXPECT_FALSE(root->is_clipped());
2005 EXPECT_FALSE(parent->is_clipped()); 1777 EXPECT_FALSE(parent->is_clipped());
2006 EXPECT_TRUE(child->is_clipped()); 1778 EXPECT_TRUE(child->is_clipped());
2007 EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect()); 1779 EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect());
2008 1780
2009 parent->SetMasksToBounds(true); 1781 parent->SetMasksToBounds(true);
2010 child->SetPosition(gfx::PointF(100, 100)); 1782 child->SetPosition(gfx::PointF(100.f, 100.f));
2011 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 1783 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2012 1784
2013 ExecuteCalculateDrawProperties(root); 1785 ExecuteCalculateDrawProperties(root);
2014 1786
2015 EXPECT_FALSE(root->is_clipped()); 1787 EXPECT_FALSE(root->is_clipped());
2016 EXPECT_TRUE(parent->is_clipped()); 1788 EXPECT_TRUE(parent->is_clipped());
2017 EXPECT_TRUE(child->is_clipped()); 1789 EXPECT_TRUE(child->is_clipped());
2018 EXPECT_EQ(gfx::Rect(), child->clip_rect()); 1790 EXPECT_EQ(gfx::Rect(), child->clip_rect());
2019 } 1791 }
2020 1792
2021 TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { 1793 TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
2022 // Tests that when separate surfaces are disabled, is_clipped is true exactly 1794 // Tests that when separate surfaces are disabled, is_clipped is true exactly
2023 // when a layer or its ancestor has a clip; in particular, if a layer 1795 // when a layer or its ancestor has a clip; in particular, if a layer
2024 // is_clipped, so is its entire subtree (since there are no render surfaces 1796 // is_clipped, so is its entire subtree (since there are no render surfaces
2025 // that can reset is_clipped). 1797 // that can reset is_clipped).
2026 LayerImpl* root = root_layer_for_testing(); 1798 LayerImpl* root = root_layer_for_testing();
2027 LayerImpl* parent = AddChild<LayerImpl>(root); 1799 LayerImpl* parent = AddChild<LayerImpl>(root);
2028 LayerImpl* child1 = AddChild<LayerImpl>(parent); 1800 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2029 LayerImpl* child2 = AddChild<LayerImpl>(parent); 1801 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2030 LayerImpl* grand_child = AddChild<LayerImpl>(child1); 1802 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2031 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); 1803 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2032 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); 1804 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2033 1805
1806 root->SetBounds(gfx::Size(100, 100));
2034 root->SetDrawsContent(true); 1807 root->SetDrawsContent(true);
1808 parent->SetBounds(gfx::Size(100, 100));
2035 parent->SetDrawsContent(true); 1809 parent->SetDrawsContent(true);
1810 child1->SetBounds(gfx::Size(100, 100));
2036 child1->SetDrawsContent(true); 1811 child1->SetDrawsContent(true);
1812 child1->test_properties()->force_render_surface = true;
1813 child2->SetBounds(gfx::Size(100, 100));
2037 child2->SetDrawsContent(true); 1814 child2->SetDrawsContent(true);
1815 grand_child->SetBounds(gfx::Size(100, 100));
2038 grand_child->SetDrawsContent(true); 1816 grand_child->SetDrawsContent(true);
1817 grand_child->test_properties()->force_render_surface = true;
1818 leaf_node1->SetBounds(gfx::Size(100, 100));
2039 leaf_node1->SetDrawsContent(true); 1819 leaf_node1->SetDrawsContent(true);
1820 leaf_node2->SetBounds(gfx::Size(100, 100));
2040 leaf_node2->SetDrawsContent(true); 1821 leaf_node2->SetDrawsContent(true);
2041 1822
2042 const gfx::Transform identity_matrix;
2043
2044 // child1 and grand_child get render surfaces when surfaces are enabled.
2045 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2046 gfx::PointF(), gfx::Size(100, 100), true, false,
2047 true);
2048 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2049 gfx::PointF(), gfx::Size(100, 100), true, false,
2050 false);
2051 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2052 gfx::PointF(), gfx::Size(100, 100), true, false,
2053 true);
2054 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2055 gfx::PointF(), gfx::Size(100, 100), true, false,
2056 false);
2057 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2058 gfx::PointF(), gfx::Size(100, 100), true, false,
2059 true);
2060 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2061 gfx::PointF(), gfx::Size(100, 100), true, false,
2062 false);
2063 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2064 gfx::PointF(), gfx::Size(100, 100), true, false,
2065 false);
2066
2067 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with 1823 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
2068 // or without surfaces. 1824 // or without surfaces.
2069 root->SetHasRenderSurface(true);
2070 child1->SetHasRenderSurface(true);
2071 grand_child->SetHasRenderSurface(true);
2072 ExecuteCalculateDrawProperties(root); 1825 ExecuteCalculateDrawProperties(root);
2073 EXPECT_FALSE(root->is_clipped()); 1826 EXPECT_FALSE(root->is_clipped());
2074 EXPECT_FALSE(parent->is_clipped()); 1827 EXPECT_FALSE(parent->is_clipped());
2075 EXPECT_FALSE(child1->is_clipped()); 1828 EXPECT_FALSE(child1->is_clipped());
2076 EXPECT_FALSE(child2->is_clipped()); 1829 EXPECT_FALSE(child2->is_clipped());
2077 EXPECT_FALSE(grand_child->is_clipped()); 1830 EXPECT_FALSE(grand_child->is_clipped());
2078 EXPECT_FALSE(leaf_node1->is_clipped()); 1831 EXPECT_FALSE(leaf_node1->is_clipped());
2079 EXPECT_FALSE(leaf_node2->is_clipped()); 1832 EXPECT_FALSE(leaf_node2->is_clipped());
2080 1833
2081 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); 1834 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2082 EXPECT_FALSE(root->is_clipped()); 1835 EXPECT_FALSE(root->is_clipped());
2083 EXPECT_FALSE(parent->is_clipped()); 1836 EXPECT_FALSE(parent->is_clipped());
2084 EXPECT_FALSE(child1->is_clipped()); 1837 EXPECT_FALSE(child1->is_clipped());
2085 EXPECT_FALSE(child2->is_clipped()); 1838 EXPECT_FALSE(child2->is_clipped());
2086 EXPECT_FALSE(grand_child->is_clipped()); 1839 EXPECT_FALSE(grand_child->is_clipped());
2087 EXPECT_FALSE(leaf_node1->is_clipped()); 1840 EXPECT_FALSE(leaf_node1->is_clipped());
2088 EXPECT_FALSE(leaf_node2->is_clipped()); 1841 EXPECT_FALSE(leaf_node2->is_clipped());
2089 1842
2090 // Case 2: The root is clipped. With surfaces, this only persists until the 1843 // Case 2: The root is clipped. With surfaces, this only persists until the
2091 // next render surface. Without surfaces, the entire tree is clipped. 1844 // next render surface. Without surfaces, the entire tree is clipped.
2092 root->SetMasksToBounds(true); 1845 root->SetMasksToBounds(true);
2093 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 1846 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2094 root->SetHasRenderSurface(true);
2095 child1->SetHasRenderSurface(true);
2096 grand_child->SetHasRenderSurface(true);
2097 ExecuteCalculateDrawProperties(root); 1847 ExecuteCalculateDrawProperties(root);
2098 EXPECT_TRUE(root->is_clipped()); 1848 EXPECT_TRUE(root->is_clipped());
2099 EXPECT_TRUE(parent->is_clipped()); 1849 EXPECT_TRUE(parent->is_clipped());
2100 EXPECT_FALSE(child1->is_clipped()); 1850 EXPECT_FALSE(child1->is_clipped());
2101 EXPECT_TRUE(child2->is_clipped()); 1851 EXPECT_TRUE(child2->is_clipped());
2102 EXPECT_FALSE(grand_child->is_clipped()); 1852 EXPECT_FALSE(grand_child->is_clipped());
2103 EXPECT_FALSE(leaf_node1->is_clipped()); 1853 EXPECT_FALSE(leaf_node1->is_clipped());
2104 EXPECT_TRUE(leaf_node2->is_clipped()); 1854 EXPECT_TRUE(leaf_node2->is_clipped());
2105 1855
2106 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); 1856 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2107 EXPECT_TRUE(root->is_clipped()); 1857 EXPECT_TRUE(root->is_clipped());
2108 EXPECT_TRUE(parent->is_clipped()); 1858 EXPECT_TRUE(parent->is_clipped());
2109 EXPECT_TRUE(child1->is_clipped()); 1859 EXPECT_TRUE(child1->is_clipped());
2110 EXPECT_TRUE(child2->is_clipped()); 1860 EXPECT_TRUE(child2->is_clipped());
2111 EXPECT_TRUE(grand_child->is_clipped()); 1861 EXPECT_TRUE(grand_child->is_clipped());
2112 EXPECT_TRUE(leaf_node1->is_clipped()); 1862 EXPECT_TRUE(leaf_node1->is_clipped());
2113 EXPECT_TRUE(leaf_node2->is_clipped()); 1863 EXPECT_TRUE(leaf_node2->is_clipped());
2114 1864
2115 root->SetMasksToBounds(false); 1865 root->SetMasksToBounds(false);
2116 1866
2117 // Case 3: The parent is clipped. Again, with surfaces, this only persists 1867 // Case 3: The parent is clipped. Again, with surfaces, this only persists
2118 // until the next render surface. Without surfaces, parent's entire subtree is 1868 // until the next render surface. Without surfaces, parent's entire subtree is
2119 // clipped. 1869 // clipped.
2120 parent->SetMasksToBounds(true); 1870 parent->SetMasksToBounds(true);
2121 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 1871 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2122 root->SetHasRenderSurface(true);
2123 child1->SetHasRenderSurface(true);
2124 grand_child->SetHasRenderSurface(true);
2125 ExecuteCalculateDrawProperties(root); 1872 ExecuteCalculateDrawProperties(root);
2126 EXPECT_FALSE(root->is_clipped()); 1873 EXPECT_FALSE(root->is_clipped());
2127 EXPECT_TRUE(parent->is_clipped()); 1874 EXPECT_TRUE(parent->is_clipped());
2128 EXPECT_FALSE(child1->is_clipped()); 1875 EXPECT_FALSE(child1->is_clipped());
2129 EXPECT_TRUE(child2->is_clipped()); 1876 EXPECT_TRUE(child2->is_clipped());
2130 EXPECT_FALSE(grand_child->is_clipped()); 1877 EXPECT_FALSE(grand_child->is_clipped());
2131 EXPECT_FALSE(leaf_node1->is_clipped()); 1878 EXPECT_FALSE(leaf_node1->is_clipped());
2132 EXPECT_TRUE(leaf_node2->is_clipped()); 1879 EXPECT_TRUE(leaf_node2->is_clipped());
2133 1880
2134 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); 1881 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2135 EXPECT_FALSE(root->is_clipped()); 1882 EXPECT_FALSE(root->is_clipped());
2136 EXPECT_TRUE(parent->is_clipped()); 1883 EXPECT_TRUE(parent->is_clipped());
2137 EXPECT_TRUE(child1->is_clipped()); 1884 EXPECT_TRUE(child1->is_clipped());
2138 EXPECT_TRUE(child2->is_clipped()); 1885 EXPECT_TRUE(child2->is_clipped());
2139 EXPECT_TRUE(grand_child->is_clipped()); 1886 EXPECT_TRUE(grand_child->is_clipped());
2140 EXPECT_TRUE(leaf_node1->is_clipped()); 1887 EXPECT_TRUE(leaf_node1->is_clipped());
2141 EXPECT_TRUE(leaf_node2->is_clipped()); 1888 EXPECT_TRUE(leaf_node2->is_clipped());
2142 1889
2143 parent->SetMasksToBounds(false); 1890 parent->SetMasksToBounds(false);
2144 1891
2145 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it 1892 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
2146 // has no non-surface children. Without surfaces, child1's entire subtree is 1893 // has no non-surface children. Without surfaces, child1's entire subtree is
2147 // clipped. 1894 // clipped.
2148 child1->SetMasksToBounds(true); 1895 child1->SetMasksToBounds(true);
2149 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 1896 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2150 root->SetHasRenderSurface(true);
2151 child1->SetHasRenderSurface(true);
2152 grand_child->SetHasRenderSurface(true);
2153 ExecuteCalculateDrawProperties(root); 1897 ExecuteCalculateDrawProperties(root);
2154 EXPECT_FALSE(root->is_clipped()); 1898 EXPECT_FALSE(root->is_clipped());
2155 EXPECT_FALSE(parent->is_clipped()); 1899 EXPECT_FALSE(parent->is_clipped());
2156 EXPECT_TRUE(child1->is_clipped()); 1900 EXPECT_TRUE(child1->is_clipped());
2157 EXPECT_FALSE(child2->is_clipped()); 1901 EXPECT_FALSE(child2->is_clipped());
2158 EXPECT_FALSE(grand_child->is_clipped()); 1902 EXPECT_FALSE(grand_child->is_clipped());
2159 EXPECT_FALSE(leaf_node1->is_clipped()); 1903 EXPECT_FALSE(leaf_node1->is_clipped());
2160 EXPECT_FALSE(leaf_node2->is_clipped()); 1904 EXPECT_FALSE(leaf_node2->is_clipped());
2161 1905
2162 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); 1906 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2163 EXPECT_FALSE(root->is_clipped()); 1907 EXPECT_FALSE(root->is_clipped());
2164 EXPECT_FALSE(parent->is_clipped()); 1908 EXPECT_FALSE(parent->is_clipped());
2165 EXPECT_TRUE(child1->is_clipped()); 1909 EXPECT_TRUE(child1->is_clipped());
2166 EXPECT_FALSE(child2->is_clipped()); 1910 EXPECT_FALSE(child2->is_clipped());
2167 EXPECT_TRUE(grand_child->is_clipped()); 1911 EXPECT_TRUE(grand_child->is_clipped());
2168 EXPECT_TRUE(leaf_node1->is_clipped()); 1912 EXPECT_TRUE(leaf_node1->is_clipped());
2169 EXPECT_FALSE(leaf_node2->is_clipped()); 1913 EXPECT_FALSE(leaf_node2->is_clipped());
2170 1914
2171 child1->SetMasksToBounds(false); 1915 child1->SetMasksToBounds(false);
2172 1916
2173 // Case 5: Only the leaf nodes are clipped. The behavior with and without 1917 // Case 5: Only the leaf nodes are clipped. The behavior with and without
2174 // surfaces is the same. 1918 // surfaces is the same.
2175 leaf_node1->SetMasksToBounds(true); 1919 leaf_node1->SetMasksToBounds(true);
2176 leaf_node2->SetMasksToBounds(true); 1920 leaf_node2->SetMasksToBounds(true);
2177 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 1921 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2178 root->SetHasRenderSurface(true);
2179 child1->SetHasRenderSurface(true);
2180 grand_child->SetHasRenderSurface(true);
2181 ExecuteCalculateDrawProperties(root); 1922 ExecuteCalculateDrawProperties(root);
2182 EXPECT_FALSE(root->is_clipped()); 1923 EXPECT_FALSE(root->is_clipped());
2183 EXPECT_FALSE(parent->is_clipped()); 1924 EXPECT_FALSE(parent->is_clipped());
2184 EXPECT_FALSE(child1->is_clipped()); 1925 EXPECT_FALSE(child1->is_clipped());
2185 EXPECT_FALSE(child2->is_clipped()); 1926 EXPECT_FALSE(child2->is_clipped());
2186 EXPECT_FALSE(grand_child->is_clipped()); 1927 EXPECT_FALSE(grand_child->is_clipped());
2187 EXPECT_TRUE(leaf_node1->is_clipped()); 1928 EXPECT_TRUE(leaf_node1->is_clipped());
2188 EXPECT_TRUE(leaf_node2->is_clipped()); 1929 EXPECT_TRUE(leaf_node2->is_clipped());
2189 1930
2190 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); 1931 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2191 EXPECT_FALSE(root->is_clipped()); 1932 EXPECT_FALSE(root->is_clipped());
2192 EXPECT_FALSE(parent->is_clipped()); 1933 EXPECT_FALSE(parent->is_clipped());
2193 EXPECT_FALSE(child1->is_clipped()); 1934 EXPECT_FALSE(child1->is_clipped());
2194 EXPECT_FALSE(child2->is_clipped()); 1935 EXPECT_FALSE(child2->is_clipped());
2195 EXPECT_FALSE(grand_child->is_clipped()); 1936 EXPECT_FALSE(grand_child->is_clipped());
2196 EXPECT_TRUE(leaf_node1->is_clipped()); 1937 EXPECT_TRUE(leaf_node1->is_clipped());
2197 EXPECT_TRUE(leaf_node2->is_clipped()); 1938 EXPECT_TRUE(leaf_node2->is_clipped());
2198 } 1939 }
2199 1940
2200 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { 1941 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
2201 // Verify that layers get the appropriate DrawableContentRect when their 1942 // Verify that layers get the appropriate DrawableContentRect when their
2202 // parent masksToBounds is true. 1943 // parent MasksToBounds is true.
2203 // 1944 //
2204 // grand_child1 - completely inside the region; DrawableContentRect should 1945 // grand_child1 - completely inside the region; DrawableContentRect should
2205 // be the layer rect expressed in target space. 1946 // be the layer rect expressed in target space.
2206 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect 1947 // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect
2207 // will be the intersection of layer bounds and the mask region. 1948 // will be the intersection of layer bounds and the mask region.
2208 // grand_child3 - partially clipped and masksToBounds; the 1949 // grand_child3 - partially clipped and MasksToBounds; the
2209 // DrawableContentRect will still be the intersection of layer bounds and 1950 // DrawableContentRect will still be the intersection of layer bounds and
2210 // the mask region. 1951 // the mask region.
2211 // grand_child4 - outside parent's clip rect; the DrawableContentRect should 1952 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2212 // be empty. 1953 // be empty.
2213 1954
2214 const gfx::Transform identity_matrix; 1955 const gfx::Transform identity_matrix;
2215 LayerImpl* parent = root_layer_for_testing(); 1956 LayerImpl* parent = root_layer_for_testing();
2216 LayerImpl* child = AddChild<LayerImpl>(parent); 1957 LayerImpl* child = AddChild<LayerImpl>(parent);
2217 LayerImpl* grand_child1 = AddChild<LayerImpl>(child); 1958 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
1959 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
1960 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
1961 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
1962
1963 parent->SetBounds(gfx::Size(500, 500));
1964 child->SetMasksToBounds(true);
1965 child->SetBounds(gfx::Size(20, 20));
1966 child->test_properties()->force_render_surface = true;
1967 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
1968 grand_child1->SetBounds(gfx::Size(10, 10));
2218 grand_child1->SetDrawsContent(true); 1969 grand_child1->SetDrawsContent(true);
2219 LayerImpl* grand_child2 = AddChild<LayerImpl>(child); 1970 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
1971 grand_child2->SetBounds(gfx::Size(10, 10));
2220 grand_child2->SetDrawsContent(true); 1972 grand_child2->SetDrawsContent(true);
2221 LayerImpl* grand_child3 = AddChild<LayerImpl>(child); 1973 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
1974 grand_child3->SetMasksToBounds(true);
1975 grand_child3->SetBounds(gfx::Size(10, 10));
2222 grand_child3->SetDrawsContent(true); 1976 grand_child3->SetDrawsContent(true);
2223 LayerImpl* grand_child4 = AddChild<LayerImpl>(child); 1977 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
1978 grand_child4->SetBounds(gfx::Size(10, 10));
2224 grand_child4->SetDrawsContent(true); 1979 grand_child4->SetDrawsContent(true);
2225
2226 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2227 gfx::PointF(), gfx::Size(500, 500), true, false,
2228 true);
2229 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2230 gfx::PointF(), gfx::Size(20, 20), true, false,
2231 true);
2232 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2233 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
2234 false, false);
2235 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2236 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2237 false, false);
2238 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2239 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2240 false, false);
2241 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
2242 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
2243 false, false);
2244
2245 child->SetMasksToBounds(true);
2246 grand_child3->SetMasksToBounds(true);
2247
2248 // Force child to be a render surface.
2249 child->test_properties()->opacity = 0.4f;
2250
2251 ExecuteCalculateDrawProperties(parent); 1980 ExecuteCalculateDrawProperties(parent);
2252 1981
2253 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); 1982 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2254 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); 1983 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2255 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); 1984 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2256 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); 1985 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2257 } 1986 }
2258 1987
2259 TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { 1988 TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
2260 // Verify that render surfaces (and their layers) get the appropriate 1989 // Verify that render surfaces (and their layers) get the appropriate
2261 // clip rects when their parent masksToBounds is true. 1990 // clip rects when their parent MasksToBounds is true.
2262 // 1991 //
2263 // Layers that own render surfaces (at least for now) do not inherit any 1992 // Layers that own render surfaces (at least for now) do not inherit any
2264 // clipping; instead the surface will enforce the clip for the entire subtree. 1993 // clipping; instead the surface will enforce the clip for the entire subtree.
2265 // They may still have a clip rect of their own layer bounds, however, if 1994 // They may still have a clip rect of their own layer bounds, however, if
2266 // masksToBounds was true. 1995 // MasksToBounds was true.
2267 LayerImpl* parent = root_layer_for_testing(); 1996 LayerImpl* parent = root_layer_for_testing();
2268 LayerImpl* child = AddChildToRoot<LayerImpl>(); 1997 LayerImpl* child = AddChildToRoot<LayerImpl>();
2269 LayerImpl* grand_child1 = AddChild<LayerImpl>(child); 1998 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2270 LayerImpl* grand_child2 = AddChild<LayerImpl>(child); 1999 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2271 LayerImpl* grand_child3 = AddChild<LayerImpl>(child); 2000 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2272 LayerImpl* grand_child4 = AddChild<LayerImpl>(child); 2001 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
2273 // the leaf nodes ensure that these grand_children become render surfaces for 2002 // The leaf nodes ensure that these grand_children become render surfaces for
2274 // this test. 2003 // this test.
2275 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); 2004 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
2005 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
2006 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
2007 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
2008
2009 parent->SetBounds(gfx::Size(500, 500));
2010 child->SetBounds(gfx::Size(20, 20));
2011 child->SetMasksToBounds(true);
2012 child->test_properties()->force_render_surface = true;
2013 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2014 grand_child1->SetBounds(gfx::Size(10, 10));
2015 grand_child1->test_properties()->force_render_surface = true;
2016 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
2017 grand_child2->SetBounds(gfx::Size(10, 10));
2018 grand_child2->test_properties()->force_render_surface = true;
2019 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
2020 grand_child3->SetBounds(gfx::Size(10, 10));
2021 grand_child3->SetMasksToBounds(true);
2022 grand_child3->test_properties()->force_render_surface = true;
2023 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
2024 grand_child4->SetBounds(gfx::Size(10, 10));
2025 grand_child4->SetMasksToBounds(true);
2026 grand_child4->test_properties()->force_render_surface = true;
2027 leaf_node1->SetBounds(gfx::Size(10, 10));
2276 leaf_node1->SetDrawsContent(true); 2028 leaf_node1->SetDrawsContent(true);
2277 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); 2029 leaf_node2->SetBounds(gfx::Size(10, 10));
2278 leaf_node2->SetDrawsContent(true); 2030 leaf_node2->SetDrawsContent(true);
2279 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3); 2031 leaf_node3->SetBounds(gfx::Size(10, 10));
2280 leaf_node3->SetDrawsContent(true); 2032 leaf_node3->SetDrawsContent(true);
2281 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4); 2033 leaf_node4->SetBounds(gfx::Size(10, 10));
2282 leaf_node4->SetDrawsContent(true); 2034 leaf_node4->SetDrawsContent(true);
2283
2284 const gfx::Transform identity_matrix;
2285
2286 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2287 gfx::PointF(), gfx::Size(500, 500), true, false,
2288 true);
2289 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2290 gfx::PointF(), gfx::Size(20, 20), true, false,
2291 true);
2292 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2293 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
2294 false, true);
2295 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2296 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2297 false, true);
2298 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2299 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2300 false, true);
2301 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
2302 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
2303 false, true);
2304 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2305 gfx::PointF(), gfx::Size(10, 10), true, false,
2306 false);
2307 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2308 gfx::PointF(), gfx::Size(10, 10), true, false,
2309 false);
2310 SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(),
2311 gfx::PointF(), gfx::Size(10, 10), true, false,
2312 false);
2313 SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(),
2314 gfx::PointF(), gfx::Size(10, 10), true, false,
2315 false);
2316
2317 child->SetMasksToBounds(true);
2318 grand_child3->SetMasksToBounds(true);
2319 grand_child4->SetMasksToBounds(true);
2320
2321 // Force everyone to be a render surface.
2322 child->test_properties()->opacity = 0.4f;
2323 grand_child1->test_properties()->opacity = 0.5f;
2324 grand_child2->test_properties()->opacity = 0.5f;
2325 grand_child3->test_properties()->opacity = 0.5f;
2326 grand_child4->test_properties()->opacity = 0.5f;
2327
2328 ExecuteCalculateDrawProperties(parent); 2035 ExecuteCalculateDrawProperties(parent);
2329 2036
2330 ASSERT_TRUE(grand_child1->render_surface()); 2037 ASSERT_TRUE(grand_child1->render_surface());
2331 ASSERT_TRUE(grand_child2->render_surface()); 2038 ASSERT_TRUE(grand_child2->render_surface());
2332 ASSERT_TRUE(grand_child3->render_surface()); 2039 ASSERT_TRUE(grand_child3->render_surface());
2333 2040
2334 // Surfaces are clipped by their parent, but un-affected by the owning layer's 2041 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2335 // masksToBounds. 2042 // MasksToBounds.
2336 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), 2043 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2337 grand_child1->render_surface()->clip_rect()); 2044 grand_child1->render_surface()->clip_rect());
2338 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), 2045 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2339 grand_child2->render_surface()->clip_rect()); 2046 grand_child2->render_surface()->clip_rect());
2340 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), 2047 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2341 grand_child3->render_surface()->clip_rect()); 2048 grand_child3->render_surface()->clip_rect());
2342 } 2049 }
2343 2050
2344 TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { 2051 TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2345 // Tests that when separate surfaces are disabled, a layer's clip_rect is the 2052 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2346 // intersection of all ancestor clips in screen space; in particular, if a 2053 // intersection of all ancestor clips in screen space; in particular, if a
2347 // layer masks to bounds, it contributes to the clip_rect of all layers in its 2054 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2348 // subtree (since there are no render surfaces that can reset the clip_rect). 2055 // subtree (since there are no render surfaces that can reset the clip_rect).
2349 LayerImpl* root = root_layer_for_testing(); 2056 LayerImpl* root = root_layer_for_testing();
2350 LayerImpl* parent = AddChild<LayerImpl>(root); 2057 LayerImpl* parent = AddChild<LayerImpl>(root);
2351 LayerImpl* child1 = AddChild<LayerImpl>(parent); 2058 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2352 LayerImpl* child2 = AddChild<LayerImpl>(parent); 2059 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2353 LayerImpl* grand_child = AddChild<LayerImpl>(child1); 2060 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2354 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); 2061 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2355 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); 2062 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2356 2063
2064 root->SetBounds(gfx::Size(100, 100));
2065 parent->SetPosition(gfx::PointF(2.f, 2.f));
2066 parent->SetBounds(gfx::Size(400, 400));
2067 child1->SetPosition(gfx::PointF(4.f, 4.f));
2068 child1->SetBounds(gfx::Size(800, 800));
2069 child2->SetPosition(gfx::PointF(3.f, 3.f));
2070 child2->SetBounds(gfx::Size(800, 800));
2071 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2072 grand_child->SetBounds(gfx::Size(1500, 1500));
2073 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
2074 leaf_node1->SetBounds(gfx::Size(2000, 2000));
2075 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
2076 leaf_node2->SetBounds(gfx::Size(2000, 2000));
2077
2357 root->SetDrawsContent(true); 2078 root->SetDrawsContent(true);
2358 parent->SetDrawsContent(true); 2079 parent->SetDrawsContent(true);
2359 child1->SetDrawsContent(true); 2080 child1->SetDrawsContent(true);
2360 child2->SetDrawsContent(true); 2081 child2->SetDrawsContent(true);
2361 grand_child->SetDrawsContent(true); 2082 grand_child->SetDrawsContent(true);
2362 leaf_node1->SetDrawsContent(true); 2083 leaf_node1->SetDrawsContent(true);
2363 leaf_node2->SetDrawsContent(true); 2084 leaf_node2->SetDrawsContent(true);
2364 2085
2365 const gfx::Transform identity_matrix; 2086 root->test_properties()->force_render_surface = true;
2366 2087 child1->test_properties()->force_render_surface = true;
2367 // child1 and grand_child get render surfaces when surfaces are enabled. 2088 grand_child->test_properties()->force_render_surface = true;
2368 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2369 gfx::PointF(), gfx::Size(100, 100), true, false);
2370 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2371 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2372 false);
2373 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2374 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2375 false);
2376 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2377 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
2378 false);
2379 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2380 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2381 true, false);
2382 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2383 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2384 true, false);
2385 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2386 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
2387 true, false);
2388 2089
2389 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its 2090 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2390 // bounds in target space. The only thing that changes when surfaces are 2091 // bounds in target space. The only thing that changes when surfaces are
2391 // disabled is that target space is always screen space. 2092 // disabled is that target space is always screen space.
2392 root->test_properties()->force_render_surface = true;
2393 child1->test_properties()->force_render_surface = true;
2394 grand_child->test_properties()->force_render_surface = true;
2395 ExecuteCalculateDrawProperties(root); 2093 ExecuteCalculateDrawProperties(root);
2396 EXPECT_TRUE(root->has_render_surface()); 2094 EXPECT_TRUE(root->has_render_surface());
2397 EXPECT_FALSE(parent->has_render_surface()); 2095 EXPECT_FALSE(parent->has_render_surface());
2398 EXPECT_TRUE(child1->has_render_surface()); 2096 EXPECT_TRUE(child1->has_render_surface());
2399 EXPECT_FALSE(child2->has_render_surface()); 2097 EXPECT_FALSE(child2->has_render_surface());
2400 EXPECT_TRUE(grand_child->has_render_surface()); 2098 EXPECT_TRUE(grand_child->has_render_surface());
2401 EXPECT_FALSE(leaf_node1->has_render_surface()); 2099 EXPECT_FALSE(leaf_node1->has_render_surface());
2402 EXPECT_FALSE(leaf_node2->has_render_surface()); 2100 EXPECT_FALSE(leaf_node2->has_render_surface());
2403 EXPECT_FALSE(root->is_clipped()); 2101 EXPECT_FALSE(root->is_clipped());
2404 EXPECT_FALSE(parent->is_clipped()); 2102 EXPECT_FALSE(parent->is_clipped());
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2525 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); 2223 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2526 } 2224 }
2527 2225
2528 TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) { 2226 TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) {
2529 LayerImpl* root = root_layer_for_testing(); 2227 LayerImpl* root = root_layer_for_testing();
2530 LayerImpl* parent = AddChild<LayerImpl>(root); 2228 LayerImpl* parent = AddChild<LayerImpl>(root);
2531 LayerImpl* child = AddChild<LayerImpl>(parent); 2229 LayerImpl* child = AddChild<LayerImpl>(parent);
2532 LayerImpl* grand_child = AddChild<LayerImpl>(child); 2230 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2533 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); 2231 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2534 2232
2233 root->SetBounds(gfx::Size(100, 100));
2234 parent->SetPosition(gfx::PointF(2.f, 2.f));
2235 parent->SetBounds(gfx::Size(400, 400));
2236 parent->SetMasksToBounds(true);
2237 child->SetPosition(gfx::PointF(4.f, 4.f));
2238 child->SetBounds(gfx::Size(800, 800));
2239 child->SetMasksToBounds(true);
2240 child->test_properties()->force_render_surface = true;
2241 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2242 grand_child->SetBounds(gfx::Size(1500, 1500));
2243 grand_child->test_properties()->force_render_surface = true;
2244 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2245 leaf_node->SetBounds(gfx::Size(2000, 2000));
2246
2535 root->SetDrawsContent(true); 2247 root->SetDrawsContent(true);
2536 parent->SetDrawsContent(true); 2248 parent->SetDrawsContent(true);
2537 child->SetDrawsContent(true); 2249 child->SetDrawsContent(true);
2538 grand_child->SetDrawsContent(true); 2250 grand_child->SetDrawsContent(true);
2539 leaf_node->SetDrawsContent(true); 2251 leaf_node->SetDrawsContent(true);
2540 2252
2541 const gfx::Transform identity_matrix;
2542
2543 // child and grand_child will get render surfaces if surfaces are enabled.
2544 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2545 gfx::PointF(), gfx::Size(100, 100), true, false,
2546 true);
2547 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2548 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2549 false, false);
2550 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2551 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2552 false, true);
2553 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2554 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2555 true, false, true);
2556 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
2557 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2558 true, false, false);
2559
2560 parent->SetMasksToBounds(true);
2561 child->SetMasksToBounds(true);
2562
2563 root->SetHasRenderSurface(true);
2564 child->SetHasRenderSurface(true);
2565 grand_child->SetHasRenderSurface(true);
2566
2567 host_impl()->set_resourceless_software_draw_for_testing(); 2253 host_impl()->set_resourceless_software_draw_for_testing();
2568 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); 2254 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2569 gfx::PointF test_point(90.f, 90.f); 2255 gfx::PointF test_point(90.f, 90.f);
2570 LayerImpl* result_layer = 2256 LayerImpl* result_layer =
2571 root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point); 2257 root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point);
2572 ASSERT_TRUE(result_layer); 2258 ASSERT_TRUE(result_layer);
2573 EXPECT_EQ(leaf_node, result_layer); 2259 EXPECT_EQ(leaf_node, result_layer);
2574 } 2260 }
2575 2261
2576 TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { 2262 TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2577 // Tests that draw properties are computed correctly when we disable and then 2263 // Tests that draw properties are computed correctly when we disable and then
2578 // re-enable separate surfaces. 2264 // re-enable separate surfaces.
2579 LayerImpl* root = root_layer_for_testing(); 2265 LayerImpl* root = root_layer_for_testing();
2580 LayerImpl* parent = AddChild<LayerImpl>(root); 2266 LayerImpl* parent = AddChild<LayerImpl>(root);
2581 LayerImpl* child = AddChild<LayerImpl>(parent); 2267 LayerImpl* child = AddChild<LayerImpl>(parent);
2582 LayerImpl* grand_child = AddChild<LayerImpl>(child); 2268 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2583 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); 2269 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2584 2270
2271 root->SetBounds(gfx::Size(100, 100));
2272 parent->SetPosition(gfx::PointF(2.f, 2.f));
2273 parent->SetBounds(gfx::Size(400, 400));
2274 parent->SetMasksToBounds(true);
2275 child->SetPosition(gfx::PointF(4.f, 4.f));
2276 child->SetBounds(gfx::Size(800, 800));
2277 child->SetMasksToBounds(true);
2278 child->test_properties()->force_render_surface = true;
2279 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2280 grand_child->SetBounds(gfx::Size(1500, 1500));
2281 grand_child->test_properties()->force_render_surface = true;
2282 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2283 leaf_node->SetBounds(gfx::Size(2000, 2000));
2284
2585 root->SetDrawsContent(true); 2285 root->SetDrawsContent(true);
2586 parent->SetDrawsContent(true); 2286 parent->SetDrawsContent(true);
2587 child->SetDrawsContent(true); 2287 child->SetDrawsContent(true);
2588 grand_child->SetDrawsContent(true); 2288 grand_child->SetDrawsContent(true);
2589 leaf_node->SetDrawsContent(true); 2289 leaf_node->SetDrawsContent(true);
2590 2290
2591 const gfx::Transform identity_matrix;
2592
2593 // child and grand_child get render surfaces when surfaces are enabled.
2594 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2595 gfx::PointF(), gfx::Size(100, 100), true, false,
2596 true);
2597 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2598 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2599 false, false);
2600 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2601 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2602 false, true);
2603 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2604 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2605 true, false, true);
2606 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
2607 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2608 true, false, false);
2609
2610 parent->SetMasksToBounds(true);
2611 child->SetMasksToBounds(true);
2612
2613 root->SetHasRenderSurface(true);
2614 child->SetHasRenderSurface(true);
2615 grand_child->SetHasRenderSurface(true);
2616
2617 gfx::Transform expected_leaf_draw_transform_with_surfaces; 2291 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2618 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); 2292 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2619 2293
2620 gfx::Transform expected_leaf_draw_transform_without_surfaces; 2294 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2621 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); 2295 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2622 2296
2623 ExecuteCalculateDrawProperties(root); 2297 ExecuteCalculateDrawProperties(root);
2624 EXPECT_FALSE(leaf_node->is_clipped()); 2298 EXPECT_FALSE(leaf_node->is_clipped());
2625 EXPECT_TRUE(leaf_node->render_target()->is_clipped()); 2299 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
2626 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); 2300 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2627 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, 2301 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2628 leaf_node->DrawTransform()); 2302 leaf_node->DrawTransform());
2629 2303
2630 root->SetHasRenderSurface(true);
2631 child->SetHasRenderSurface(true);
2632 grand_child->SetHasRenderSurface(true);
2633
2634 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); 2304 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2635 EXPECT_TRUE(leaf_node->is_clipped()); 2305 EXPECT_TRUE(leaf_node->is_clipped());
2636 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); 2306 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2637 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); 2307 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
2638 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces, 2308 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces,
2639 leaf_node->DrawTransform()); 2309 leaf_node->DrawTransform());
2640 2310
2641 root->SetHasRenderSurface(true);
2642 child->SetHasRenderSurface(true);
2643 grand_child->SetHasRenderSurface(true);
2644
2645 ExecuteCalculateDrawProperties(root); 2311 ExecuteCalculateDrawProperties(root);
2646 EXPECT_FALSE(leaf_node->is_clipped()); 2312 EXPECT_FALSE(leaf_node->is_clipped());
2647 EXPECT_TRUE(leaf_node->render_target()->is_clipped()); 2313 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
2648 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); 2314 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2649 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, 2315 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2650 leaf_node->DrawTransform()); 2316 leaf_node->DrawTransform());
2651 } 2317 }
2652 2318
2653 TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { 2319 TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
2654 LayerImpl* parent = root_layer_for_testing(); 2320 LayerImpl* root = root_layer_for_testing();
2655 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); 2321 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2656 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); 2322 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2657 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); 2323 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2658 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); 2324 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2659 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); 2325 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2660 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); 2326 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2661 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); 2327 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2662 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); 2328 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
2663 2329
2664 parent->SetDrawsContent(true); 2330 root->SetDrawsContent(true);
2665 render_surface1->SetDrawsContent(true); 2331 render_surface1->SetDrawsContent(true);
2666 child_of_rs1->SetDrawsContent(true); 2332 child_of_rs1->SetDrawsContent(true);
2667 grand_child_of_rs1->SetDrawsContent(true); 2333 grand_child_of_rs1->SetDrawsContent(true);
2668 render_surface2->SetDrawsContent(true); 2334 render_surface2->SetDrawsContent(true);
2669 child_of_rs2->SetDrawsContent(true); 2335 child_of_rs2->SetDrawsContent(true);
2670 grand_child_of_rs2->SetDrawsContent(true); 2336 grand_child_of_rs2->SetDrawsContent(true);
2671 child_of_root->SetDrawsContent(true); 2337 child_of_root->SetDrawsContent(true);
2672 grand_child_of_root->SetDrawsContent(true); 2338 grand_child_of_root->SetDrawsContent(true);
2673 2339
2674 gfx::Transform layer_transform; 2340 gfx::Transform layer_transform;
2675 layer_transform.Translate(1.0, 1.0); 2341 layer_transform.Translate(1.0, 1.0);
2676 2342
2677 SetLayerPropertiesForTesting( 2343 root->SetTransform(layer_transform);
2678 parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), 2344 root->SetPosition(gfx::PointF(2.5f, 0.f));
2679 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); 2345 root->SetBounds(gfx::Size(10, 10));
2680 SetLayerPropertiesForTesting( 2346 root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f);
2681 render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), 2347 render_surface1->SetTransform(layer_transform);
2682 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); 2348 render_surface1->SetPosition(gfx::PointF(2.5f, 0.f));
2683 SetLayerPropertiesForTesting( 2349 render_surface1->SetBounds(gfx::Size(10, 10));
2684 render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), 2350 render_surface1->test_properties()->transform_origin =
2685 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); 2351 gfx::Point3F(0.25f, 0.f, 0.f);
2686 SetLayerPropertiesForTesting( 2352 render_surface1->test_properties()->force_render_surface = true;
2687 child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), 2353 render_surface2->SetTransform(layer_transform);
2688 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); 2354 render_surface2->SetPosition(gfx::PointF(2.5f, 0.f));
2689 SetLayerPropertiesForTesting( 2355 render_surface2->SetBounds(gfx::Size(10, 10));
2690 child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), 2356 render_surface2->test_properties()->transform_origin =
2691 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); 2357 gfx::Point3F(0.25f, 0.f, 0.f);
2692 SetLayerPropertiesForTesting( 2358 render_surface2->test_properties()->force_render_surface = true;
2693 child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), 2359 child_of_root->SetTransform(layer_transform);
2694 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); 2360 child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2695 SetLayerPropertiesForTesting( 2361 child_of_root->SetBounds(gfx::Size(10, 10));
2696 grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), 2362 child_of_root->test_properties()->transform_origin =
2697 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); 2363 gfx::Point3F(0.25f, 0.f, 0.f);
2698 SetLayerPropertiesForTesting( 2364 child_of_rs1->SetTransform(layer_transform);
2699 grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), 2365 child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2700 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); 2366 child_of_rs1->SetBounds(gfx::Size(10, 10));
2701 SetLayerPropertiesForTesting( 2367 child_of_rs1->test_properties()->transform_origin =
2702 grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), 2368 gfx::Point3F(0.25f, 0.f, 0.f);
2703 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); 2369 child_of_rs2->SetTransform(layer_transform);
2370 child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2371 child_of_rs2->SetBounds(gfx::Size(10, 10));
2372 child_of_rs2->test_properties()->transform_origin =
2373 gfx::Point3F(0.25f, 0.f, 0.f);
2374 grand_child_of_root->SetTransform(layer_transform);
2375 grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2376 grand_child_of_root->SetBounds(gfx::Size(10, 10));
2377 grand_child_of_root->test_properties()->transform_origin =
2378 gfx::Point3F(0.25f, 0.f, 0.f);
2379 grand_child_of_rs1->SetTransform(layer_transform);
2380 grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2381 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
2382 grand_child_of_rs1->test_properties()->transform_origin =
2383 gfx::Point3F(0.25f, 0.f, 0.f);
2384 grand_child_of_rs2->SetTransform(layer_transform);
2385 grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2386 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
2387 grand_child_of_rs2->test_properties()->transform_origin =
2388 gfx::Point3F(0.25f, 0.f, 0.f);
2704 2389
2705 parent->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); 2390 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
2706 SetElementIdsForTesting(); 2391 SetElementIdsForTesting();
2707 2392
2708 // Put an animated opacity on the render surface. 2393 // Put an animated opacity on the render surface.
2709 AddOpacityTransitionToElementWithPlayer( 2394 AddOpacityTransitionToElementWithPlayer(
2710 render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false); 2395 render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false);
2711 2396
2712 // Also put an animated opacity on a layer without descendants. 2397 // Also put an animated opacity on a layer without descendants.
2713 AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(), 2398 AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(),
2714 timeline_impl(), 10.0, 1.f, 0.f, 2399 timeline_impl(), 10.0, 1.f, 0.f,
2715 false); 2400 false);
2716 2401
2717 // Put a transform animation on the render surface. 2402 // Put a transform animation on the render surface.
2718 AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(), 2403 AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(),
2719 timeline_impl(), 10.0, 30, 0); 2404 timeline_impl(), 10.0, 30, 0);
2720 2405
2721 // Also put transform animations on grand_child_of_root, and 2406 // Also put transform animations on grand_child_of_root, and
2722 // grand_child_of_rs2 2407 // grand_child_of_rs2
2723 AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(), 2408 AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(),
2724 timeline_impl(), 10.0, 30, 0); 2409 timeline_impl(), 10.0, 30, 0);
2725 AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(), 2410 AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(),
2726 timeline_impl(), 10.0, 30, 0); 2411 timeline_impl(), 10.0, 30, 0);
2727 2412
2728 parent->layer_tree_impl()->property_trees()->needs_rebuild = true; 2413 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
2729 ExecuteCalculateDrawProperties(parent); 2414 ExecuteCalculateDrawProperties(root);
2730 2415
2731 // Only layers that are associated with render surfaces should have an actual 2416 // Only layers that are associated with render surfaces should have an actual
2732 // RenderSurface() value. 2417 // RenderSurface() value.
2733 ASSERT_TRUE(parent->render_surface()); 2418 ASSERT_TRUE(root->render_surface());
2734 ASSERT_FALSE(child_of_root->render_surface()); 2419 ASSERT_FALSE(child_of_root->render_surface());
2735 ASSERT_FALSE(grand_child_of_root->render_surface()); 2420 ASSERT_FALSE(grand_child_of_root->render_surface());
2736 2421
2737 ASSERT_TRUE(render_surface1->render_surface()); 2422 ASSERT_TRUE(render_surface1->render_surface());
2738 ASSERT_FALSE(child_of_rs1->render_surface()); 2423 ASSERT_FALSE(child_of_rs1->render_surface());
2739 ASSERT_FALSE(grand_child_of_rs1->render_surface()); 2424 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2740 2425
2741 ASSERT_TRUE(render_surface2->render_surface()); 2426 ASSERT_TRUE(render_surface2->render_surface());
2742 ASSERT_FALSE(child_of_rs2->render_surface()); 2427 ASSERT_FALSE(child_of_rs2->render_surface());
2743 ASSERT_FALSE(grand_child_of_rs2->render_surface()); 2428 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2744 2429
2745 // Verify all render target accessors 2430 // Verify all render target accessors
2746 EXPECT_EQ(parent->render_surface(), parent->render_target()); 2431 EXPECT_EQ(root->render_surface(), root->render_target());
2747 EXPECT_EQ(parent->render_surface(), child_of_root->render_target()); 2432 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
2748 EXPECT_EQ(parent->render_surface(), grand_child_of_root->render_target()); 2433 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
2749 2434
2750 EXPECT_EQ(render_surface1->render_surface(), 2435 EXPECT_EQ(render_surface1->render_surface(),
2751 render_surface1->render_target()); 2436 render_surface1->render_target());
2752 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); 2437 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
2753 EXPECT_EQ(render_surface1->render_surface(), 2438 EXPECT_EQ(render_surface1->render_surface(),
2754 grand_child_of_rs1->render_target()); 2439 grand_child_of_rs1->render_target());
2755 2440
2756 EXPECT_EQ(render_surface2->render_surface(), 2441 EXPECT_EQ(render_surface2->render_surface(),
2757 render_surface2->render_target()); 2442 render_surface2->render_target());
2758 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); 2443 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
2759 EXPECT_EQ(render_surface2->render_surface(), 2444 EXPECT_EQ(render_surface2->render_surface(),
2760 grand_child_of_rs2->render_target()); 2445 grand_child_of_rs2->render_target());
2761 2446
2762 // Verify screen_space_transform_is_animating values 2447 // Verify screen_space_transform_is_animating values
2763 EXPECT_FALSE(parent->screen_space_transform_is_animating()); 2448 EXPECT_FALSE(root->screen_space_transform_is_animating());
2764 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); 2449 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2765 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); 2450 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2766 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); 2451 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2767 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); 2452 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2768 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); 2453 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2769 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); 2454 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2770 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); 2455 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2771 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); 2456 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2772 2457
2773 // Sanity check. If these fail there is probably a bug in the test itself. 2458 // Sanity check. If these fail there is probably a bug in the test itself.
2774 // It is expected that we correctly set up transforms so that the y-component 2459 // It is expected that we correctly set up transforms so that the y-component
2775 // of the screen-space transform encodes the "depth" of the layer in the tree. 2460 // of the screen-space transform encodes the "depth" of the layer in the tree.
2776 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); 2461 EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3));
2777 EXPECT_FLOAT_EQ(2.0, 2462 EXPECT_FLOAT_EQ(2.0,
2778 child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); 2463 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
2779 EXPECT_FLOAT_EQ( 2464 EXPECT_FLOAT_EQ(
2780 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); 2465 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
2781 2466
2782 EXPECT_FLOAT_EQ(2.0, 2467 EXPECT_FLOAT_EQ(2.0,
2783 render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); 2468 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
2784 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); 2469 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
2785 EXPECT_FLOAT_EQ( 2470 EXPECT_FLOAT_EQ(
2786 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); 2471 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
2787 2472
2788 EXPECT_FLOAT_EQ(3.0, 2473 EXPECT_FLOAT_EQ(3.0,
2789 render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); 2474 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
2790 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); 2475 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
2791 EXPECT_FLOAT_EQ( 2476 EXPECT_FLOAT_EQ(
2792 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); 2477 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
2793 } 2478 }
2794 2479
2795 TEST_F(LayerTreeHostCommonTest, LargeTransforms) { 2480 TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
2796 LayerImpl* parent = root_layer_for_testing(); 2481 LayerImpl* root = root_layer_for_testing();
2797 LayerImpl* child = AddChildToRoot<LayerImpl>(); 2482 LayerImpl* child = AddChildToRoot<LayerImpl>();
2798 LayerImpl* grand_child = AddChild<LayerImpl>(child); 2483 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2799 2484
2800 grand_child->SetDrawsContent(true);
2801
2802 gfx::Transform large_transform; 2485 gfx::Transform large_transform;
2803 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); 2486 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2804 2487
2805 gfx::Transform identity; 2488 root->SetBounds(gfx::Size(10, 10));
2806 2489 child->SetTransform(large_transform);
2807 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(), 2490 child->SetBounds(gfx::Size(10, 10));
2808 gfx::Size(10, 10), true, false, true); 2491 grand_child->SetTransform(large_transform);
2809 SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(), 2492 grand_child->SetBounds(gfx::Size(10, 10));
2810 gfx::PointF(), gfx::Size(10, 10), true, false, 2493 grand_child->SetDrawsContent(true);
2811 false); 2494 ExecuteCalculateDrawProperties(root);
2812 SetLayerPropertiesForTesting(grand_child, large_transform, gfx::Point3F(),
2813 gfx::PointF(), gfx::Size(10, 10), true, false,
2814 false);
2815 ExecuteCalculateDrawProperties(parent);
2816 2495
2817 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); 2496 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2818 } 2497 }
2819 2498
2820 TEST_F(LayerTreeHostCommonTest, 2499 TEST_F(LayerTreeHostCommonTest,
2821 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) { 2500 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
2822 LayerImpl* parent = root_layer_for_testing(); 2501 LayerImpl* root = root_layer_for_testing();
2823 LayerImpl* child = AddChild<LayerImpl>(parent); 2502 LayerImpl* child = AddChild<LayerImpl>(root);
2824 LayerImpl* grand_child = AddChild<LayerImpl>(child); 2503 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2825 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); 2504 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2826 2505
2827 parent->SetDrawsContent(true); 2506 root->SetDrawsContent(true);
2828 child->SetDrawsContent(true); 2507 child->SetDrawsContent(true);
2829 grand_child->SetDrawsContent(true); 2508 grand_child->SetDrawsContent(true);
2830 great_grand_child->SetDrawsContent(true); 2509 great_grand_child->SetDrawsContent(true);
2831 2510
2832 gfx::Transform identity; 2511 gfx::Transform identity;
2833 2512
2834 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(), 2513 root->SetBounds(gfx::Size(10, 10));
2835 gfx::Size(10, 10), true, false, true); 2514 child->SetBounds(gfx::Size(10, 10));
2836 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(), 2515 grand_child->SetBounds(gfx::Size(10, 10));
2837 gfx::Size(10, 10), true, false, false); 2516 great_grand_child->SetBounds(gfx::Size(10, 10));
2838 SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(),
2839 gfx::PointF(), gfx::Size(10, 10), true, false,
2840 false);
2841 SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(),
2842 gfx::PointF(), gfx::Size(10, 10), true, false,
2843 false);
2844 2517
2845 SetElementIdsForTesting(); 2518 SetElementIdsForTesting();
2846 2519
2847 // Add a transform animation with a start delay to |grand_child|. 2520 // Add a transform animation with a start delay to |grand_child|.
2848 std::unique_ptr<Animation> animation = Animation::Create( 2521 std::unique_ptr<Animation> animation = Animation::Create(
2849 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1, 2522 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
2850 TargetProperty::TRANSFORM); 2523 TargetProperty::TRANSFORM);
2851 animation->set_fill_mode(Animation::FillMode::NONE); 2524 animation->set_fill_mode(Animation::FillMode::NONE);
2852 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); 2525 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
2853 AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(), 2526 AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(),
2854 std::move(animation)); 2527 std::move(animation));
2855 ExecuteCalculateDrawProperties(parent); 2528 ExecuteCalculateDrawProperties(root);
2856 2529
2857 EXPECT_FALSE(parent->screen_space_transform_is_animating()); 2530 EXPECT_FALSE(root->screen_space_transform_is_animating());
2858 EXPECT_FALSE(child->screen_space_transform_is_animating()); 2531 EXPECT_FALSE(child->screen_space_transform_is_animating());
2859 2532
2860 EXPECT_FALSE(grand_child->TransformIsAnimating()); 2533 EXPECT_FALSE(grand_child->TransformIsAnimating());
2861 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation()); 2534 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2862 EXPECT_TRUE(grand_child->screen_space_transform_is_animating()); 2535 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2863 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating()); 2536 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2864 } 2537 }
2865 2538
2866 TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) { 2539 TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) {
2867 // Test visible layer rect and drawable content rect are calculated correctly 2540 // Test visible layer rect and drawable content rect are calculated correctly
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
3168 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( 2841 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
3169 target_surface_rect, layer_to_surface_transform, layer_content_rect); 2842 target_surface_rect, layer_to_surface_transform, layer_content_rect);
3170 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); 2843 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
3171 EXPECT_EQ(expected_drawable_content_rect, 2844 EXPECT_EQ(expected_drawable_content_rect,
3172 drawing_layer->drawable_content_rect()); 2845 drawing_layer->drawable_content_rect());
3173 } 2846 }
3174 2847
3175 TEST_F(LayerTreeHostCommonTest, 2848 TEST_F(LayerTreeHostCommonTest,
3176 VisibleRectsForPositionedRootLayerClippedByViewport) { 2849 VisibleRectsForPositionedRootLayerClippedByViewport) {
3177 LayerImpl* root = root_layer_for_testing(); 2850 LayerImpl* root = root_layer_for_testing();
2851
2852 root->SetPosition(gfx::PointF(60, 70));
2853 root->SetBounds(gfx::Size(100, 100));
3178 root->SetDrawsContent(true); 2854 root->SetDrawsContent(true);
3179
3180 gfx::Transform identity_matrix;
3181 // Root layer is positioned at (60, 70). The default device viewport size
3182 // is (0, 0, 100x100) in target space. So the root layer's visible rect
3183 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
3184 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3185 gfx::PointF(60, 70), gfx::Size(100, 100), true,
3186 false, true);
3187 ExecuteCalculateDrawProperties(root); 2855 ExecuteCalculateDrawProperties(root);
3188 2856
3189 EXPECT_EQ(gfx::RectF(100.f, 100.f), 2857 EXPECT_EQ(gfx::RectF(100.f, 100.f),
3190 root->render_surface()->DrawableContentRect()); 2858 root->render_surface()->DrawableContentRect());
3191 // In target space, not clipped. 2859 // In target space, not clipped.
3192 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); 2860 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
3193 // In layer space, clipped. 2861 // In layer space, clipped.
3194 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); 2862 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
3195 } 2863 }
3196 2864
3197 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { 2865 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
3198 LayerImpl* root = root_layer_for_testing(); 2866 LayerImpl* root = root_layer_for_testing();
3199 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); 2867 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
2868 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
2869 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
2870
2871 root->SetBounds(gfx::Size(100, 100));
2872 child1_layer->SetBounds(gfx::Size(50, 50));
3200 child1_layer->SetDrawsContent(true); 2873 child1_layer->SetDrawsContent(true);
3201 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); 2874 child2_layer->SetPosition(gfx::PointF(75.f, 75.f));
2875 child2_layer->SetBounds(gfx::Size(50, 50));
3202 child2_layer->SetDrawsContent(true); 2876 child2_layer->SetDrawsContent(true);
3203 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); 2877 child3_layer->SetPosition(gfx::PointF(125.f, 125.f));
2878 child3_layer->SetBounds(gfx::Size(50, 50));
3204 child3_layer->SetDrawsContent(true); 2879 child3_layer->SetDrawsContent(true);
3205
3206 gfx::Transform identity_matrix;
3207 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3208 gfx::PointF(), gfx::Size(100, 100), true, false,
3209 true);
3210 SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(),
3211 gfx::PointF(), gfx::Size(50, 50), true, false,
3212 false);
3213 SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(),
3214 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3215 false, false);
3216 SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(),
3217 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3218 true, false, false);
3219
3220 ExecuteCalculateDrawProperties(root); 2880 ExecuteCalculateDrawProperties(root);
3221 2881
3222 EXPECT_EQ(gfx::RectF(100.f, 100.f), 2882 EXPECT_EQ(gfx::RectF(100.f, 100.f),
3223 root->render_surface()->DrawableContentRect()); 2883 root->render_surface()->DrawableContentRect());
3224 2884
3225 // Layers that do not draw content should have empty visible_layer_rects. 2885 // Layers that do not draw content should have empty visible_layer_rects.
3226 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); 2886 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3227 2887
3228 // layer visible_layer_rects are clipped by their target surface. 2888 // layer visible_layer_rects are clipped by their target surface.
3229 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); 2889 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
3230 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); 2890 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
3231 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); 2891 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
3232 2892
3233 // layer drawable_content_rects are not clipped. 2893 // layer drawable_content_rects are not clipped.
3234 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect()); 2894 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
3235 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect()); 2895 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
3236 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect()); 2896 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
3237 } 2897 }
3238 2898
3239 TEST_F(LayerTreeHostCommonTest, 2899 TEST_F(LayerTreeHostCommonTest,
3240 DrawableAndVisibleContentRectsForLayersClippedByLayer) { 2900 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
3241 LayerImpl* root = root_layer_for_testing(); 2901 LayerImpl* root = root_layer_for_testing();
3242 LayerImpl* child = AddChildToRoot<LayerImpl>(); 2902 LayerImpl* child = AddChildToRoot<LayerImpl>();
3243 LayerImpl* grand_child1 = AddChild<LayerImpl>(child); 2903 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2904 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2905 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2906
2907 root->SetBounds(gfx::Size(100, 100));
2908 child->SetBounds(gfx::Size(100, 100));
2909 child->SetMasksToBounds(true);
2910 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2911 grand_child1->SetBounds(gfx::Size(50, 50));
3244 grand_child1->SetDrawsContent(true); 2912 grand_child1->SetDrawsContent(true);
3245 LayerImpl* grand_child2 = AddChild<LayerImpl>(child); 2913 grand_child2->SetPosition(gfx::PointF(75.f, 75.f));
2914 grand_child2->SetBounds(gfx::Size(50, 50));
3246 grand_child2->SetDrawsContent(true); 2915 grand_child2->SetDrawsContent(true);
3247 LayerImpl* grand_child3 = AddChild<LayerImpl>(child); 2916 grand_child3->SetPosition(gfx::PointF(125.f, 125.f));
2917 grand_child3->SetBounds(gfx::Size(50, 50));
3248 grand_child3->SetDrawsContent(true); 2918 grand_child3->SetDrawsContent(true);
3249
3250 gfx::Transform identity_matrix;
3251 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3252 gfx::PointF(), gfx::Size(100, 100), true, false,
3253 true);
3254 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
3255 gfx::PointF(), gfx::Size(100, 100), true, false,
3256 false);
3257 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
3258 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3259 false, false);
3260 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
3261 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3262 false, false);
3263 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
3264 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3265 true, false, false);
3266
3267 child->SetMasksToBounds(true);
3268 ExecuteCalculateDrawProperties(root); 2919 ExecuteCalculateDrawProperties(root);
3269 2920
3270 EXPECT_EQ(gfx::RectF(100.f, 100.f), 2921 EXPECT_EQ(gfx::RectF(100.f, 100.f),
3271 root->render_surface()->DrawableContentRect()); 2922 root->render_surface()->DrawableContentRect());
3272 2923
3273 // Layers that do not draw content should have empty visible content rects. 2924 // Layers that do not draw content should have empty visible content rects.
3274 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); 2925 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3275 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); 2926 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
3276 2927
3277 // All grandchild visible content rects should be clipped by child. 2928 // All grandchild visible content rects should be clipped by child.
(...skipping 10 matching lines...) Expand all
3288 TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { 2939 TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
3289 LayerImpl* root = root_layer_for_testing(); 2940 LayerImpl* root = root_layer_for_testing();
3290 LayerImpl* child = AddChild<LayerImpl>(root); 2941 LayerImpl* child = AddChild<LayerImpl>(root);
3291 LayerImpl* grand_child = AddChild<LayerImpl>(child); 2942 LayerImpl* grand_child = AddChild<LayerImpl>(child);
3292 2943
3293 gfx::Transform identity_matrix; 2944 gfx::Transform identity_matrix;
3294 gfx::Transform child_scale_matrix; 2945 gfx::Transform child_scale_matrix;
3295 child_scale_matrix.Scale(0.25f, 0.25f); 2946 child_scale_matrix.Scale(0.25f, 0.25f);
3296 gfx::Transform grand_child_scale_matrix; 2947 gfx::Transform grand_child_scale_matrix;
3297 grand_child_scale_matrix.Scale(0.246f, 0.246f); 2948 grand_child_scale_matrix.Scale(0.246f, 0.246f);
3298 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3299 gfx::PointF(), gfx::Size(100, 100), true, false,
3300 true);
3301 SetLayerPropertiesForTesting(child, child_scale_matrix, gfx::Point3F(),
3302 gfx::PointF(), gfx::Size(10, 10), true, false,
3303 false);
3304 SetLayerPropertiesForTesting(grand_child, grand_child_scale_matrix,
3305 gfx::Point3F(), gfx::PointF(),
3306 gfx::Size(100, 100), true, false, false);
3307 2949
2950 root->SetBounds(gfx::Size(100, 100));
2951 child->SetTransform(child_scale_matrix);
2952 child->SetBounds(gfx::Size(10, 10));
3308 child->SetMasksToBounds(true); 2953 child->SetMasksToBounds(true);
2954 grand_child->SetTransform(grand_child_scale_matrix);
2955 grand_child->SetBounds(gfx::Size(100, 100));
3309 grand_child->SetDrawsContent(true); 2956 grand_child->SetDrawsContent(true);
3310 ExecuteCalculateDrawProperties(root); 2957 ExecuteCalculateDrawProperties(root);
3311 2958
3312 // The visible rect is expanded to integer coordinates. 2959 // The visible rect is expanded to integer coordinates.
3313 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect()); 2960 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect());
3314 } 2961 }
3315 2962
3316 TEST_F(LayerTreeHostCommonTest, 2963 TEST_F(LayerTreeHostCommonTest,
3317 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { 2964 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
3318 LayerImpl* root = root_layer_for_testing(); 2965 LayerImpl* root = root_layer_for_testing();
3319 LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); 2966 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3320 LayerImpl* child1 = AddChild<LayerImpl>(render_surface); 2967 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
2968 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
2969 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
2970
2971 root->SetBounds(gfx::Size(100, 100));
2972 render_surface->SetBounds(gfx::Size(3, 4));
2973 render_surface->test_properties()->force_render_surface = true;
2974 child1->SetPosition(gfx::PointF(5.f, 5.f));
2975 child1->SetBounds(gfx::Size(50, 50));
3321 child1->SetDrawsContent(true); 2976 child1->SetDrawsContent(true);
3322 LayerImpl* child2 = AddChild<LayerImpl>(render_surface); 2977 child2->SetPosition(gfx::PointF(75.f, 75.f));
2978 child2->SetBounds(gfx::Size(50, 50));
3323 child2->SetDrawsContent(true); 2979 child2->SetDrawsContent(true);
3324 LayerImpl* child3 = AddChild<LayerImpl>(render_surface); 2980 child3->SetPosition(gfx::PointF(125.f, 125.f));
2981 child3->SetBounds(gfx::Size(50, 50));
3325 child3->SetDrawsContent(true); 2982 child3->SetDrawsContent(true);
3326
3327 gfx::Transform identity_matrix;
3328 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3329 gfx::PointF(), gfx::Size(100, 100), true, false,
3330 true);
3331 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3332 gfx::PointF(), gfx::Size(3, 4), true, false,
3333 true);
3334 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3335 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3336 false, false);
3337 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3338 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3339 false, false);
3340 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3341 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3342 true, false, false);
3343
3344 ExecuteCalculateDrawProperties(root); 2983 ExecuteCalculateDrawProperties(root);
3345 2984
3346 ASSERT_TRUE(render_surface->render_surface()); 2985 ASSERT_TRUE(render_surface->render_surface());
3347 2986
3348 EXPECT_EQ(gfx::RectF(100.f, 100.f), 2987 EXPECT_EQ(gfx::RectF(100.f, 100.f),
3349 root->render_surface()->DrawableContentRect()); 2988 root->render_surface()->DrawableContentRect());
3350 2989
3351 // Layers that do not draw content should have empty visible content rects. 2990 // Layers that do not draw content should have empty visible content rects.
3352 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); 2991 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3353 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); 2992 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
(...skipping 17 matching lines...) Expand all
3371 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { 3010 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
3372 LayerImpl* root = root_layer_for_testing(); 3011 LayerImpl* root = root_layer_for_testing();
3373 LayerImpl* parent = AddChild<LayerImpl>(root); 3012 LayerImpl* parent = AddChild<LayerImpl>(root);
3374 LayerImpl* child1 = AddChild<LayerImpl>(parent); 3013 LayerImpl* child1 = AddChild<LayerImpl>(parent);
3375 LayerImpl* child2 = AddChild<LayerImpl>(parent); 3014 LayerImpl* child2 = AddChild<LayerImpl>(parent);
3376 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); 3015 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
3377 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); 3016 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
3378 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); 3017 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
3379 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); 3018 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
3380 3019
3020 root->SetBounds(gfx::Size(100, 100));
3021 parent->SetPosition(gfx::PointF(2.f, 2.f));
3022 parent->SetBounds(gfx::Size(400, 400));
3023 child1->SetPosition(gfx::PointF(4.f, 4.f));
3024 child1->SetBounds(gfx::Size(800, 800));
3025 child1->test_properties()->force_render_surface = true;
3026 child2->SetPosition(gfx::PointF(3.f, 3.f));
3027 child2->SetBounds(gfx::Size(800, 800));
3028 child2->test_properties()->force_render_surface = true;
3029 grand_child1->SetPosition(gfx::PointF(8.f, 8.f));
3030 grand_child1->SetBounds(gfx::Size(1500, 1500));
3031 grand_child2->SetPosition(gfx::PointF(7.f, 7.f));
3032 grand_child2->SetBounds(gfx::Size(1500, 1500));
3033 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
3034 leaf_node1->SetBounds(gfx::Size(2000, 2000));
3035 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
3036 leaf_node2->SetBounds(gfx::Size(2000, 2000));
3037
3381 root->SetDrawsContent(true); 3038 root->SetDrawsContent(true);
3382 parent->SetDrawsContent(true); 3039 parent->SetDrawsContent(true);
3383 child1->SetDrawsContent(true); 3040 child1->SetDrawsContent(true);
3384 child2->SetDrawsContent(true); 3041 child2->SetDrawsContent(true);
3385 grand_child1->SetDrawsContent(true); 3042 grand_child1->SetDrawsContent(true);
3386 grand_child2->SetDrawsContent(true); 3043 grand_child2->SetDrawsContent(true);
3387 leaf_node1->SetDrawsContent(true); 3044 leaf_node1->SetDrawsContent(true);
3388 leaf_node2->SetDrawsContent(true); 3045 leaf_node2->SetDrawsContent(true);
3389 3046
3390 const gfx::Transform identity_matrix;
3391
3392 // child1 and child2 get render surfaces when surfaces are enabled.
3393 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3394 gfx::PointF(), gfx::Size(100, 100), true, false,
3395 true);
3396 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3397 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
3398 false, false);
3399 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3400 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
3401 false, true);
3402 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3403 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
3404 false, true);
3405 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
3406 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
3407 true, false, false);
3408 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
3409 gfx::PointF(7.f, 7.f), gfx::Size(1500, 1500),
3410 true, false, false);
3411 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
3412 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
3413 true, false, false);
3414 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
3415 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
3416 true, false, false);
3417
3418 // Case 1: No layers clip. Visible rects are clipped by the viewport, but the 3047 // Case 1: No layers clip. Visible rects are clipped by the viewport, but the
3419 // viewport clip doesn't apply to layers that draw into unclipped surfaces. 3048 // viewport clip doesn't apply to layers that draw into unclipped surfaces.
3420 // Each layer's drawable content rect is its bounds in target space; the only 3049 // Each layer's drawable content rect is its bounds in target space; the only
3421 // thing that changes with surfaces disabled is that target space is always 3050 // thing that changes with surfaces disabled is that target space is always
3422 // screen space. 3051 // screen space.
3423 root->SetHasRenderSurface(true); 3052 root->SetHasRenderSurface(true);
3424 child1->SetHasRenderSurface(true); 3053 child1->SetHasRenderSurface(true);
3425 child2->SetHasRenderSurface(true); 3054 child2->SetHasRenderSurface(true);
3426 ExecuteCalculateDrawProperties(root); 3055 ExecuteCalculateDrawProperties(root);
3427 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); 3056 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3464 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); 3093 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
3465 3094
3466 // Case 2: The parent clips. In this case, neither surface is unclipped, so 3095 // Case 2: The parent clips. In this case, neither surface is unclipped, so
3467 // all visible layer rects are clipped by the intersection of all ancestor 3096 // all visible layer rects are clipped by the intersection of all ancestor
3468 // clips, whether or not surfaces are disabled. However, drawable content 3097 // clips, whether or not surfaces are disabled. However, drawable content
3469 // rects are clipped only until the next render surface is reached, so 3098 // rects are clipped only until the next render surface is reached, so
3470 // descendants of parent have their drawable content rects clipped only when 3099 // descendants of parent have their drawable content rects clipped only when
3471 // surfaces are disabled. 3100 // surfaces are disabled.
3472 parent->SetMasksToBounds(true); 3101 parent->SetMasksToBounds(true);
3473 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 3102 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3474 root->SetHasRenderSurface(true);
3475 child1->SetHasRenderSurface(true);
3476 child2->SetHasRenderSurface(true);
3477 ExecuteCalculateDrawProperties(root); 3103 ExecuteCalculateDrawProperties(root);
3478 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); 3104 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3479 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); 3105 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3480 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); 3106 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3481 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); 3107 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3482 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); 3108 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3483 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); 3109 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3484 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); 3110 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3485 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); 3111 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3486 3112
(...skipping 27 matching lines...) Expand all
3514 3140
3515 parent->SetMasksToBounds(false); 3141 parent->SetMasksToBounds(false);
3516 3142
3517 // Case 3: child1 and grand_child2 clip. In this case, descendants of these 3143 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
3518 // layers have their visible rects clipped by them; without surfaces, these 3144 // layers have their visible rects clipped by them; without surfaces, these
3519 // rects are also clipped by the viewport. Similarly, descendants of these 3145 // rects are also clipped by the viewport. Similarly, descendants of these
3520 // layers have their drawable content rects clipped by them. 3146 // layers have their drawable content rects clipped by them.
3521 child1->SetMasksToBounds(true); 3147 child1->SetMasksToBounds(true);
3522 grand_child2->SetMasksToBounds(true); 3148 grand_child2->SetMasksToBounds(true);
3523 host_impl()->active_tree()->property_trees()->needs_rebuild = true; 3149 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3524 root->SetHasRenderSurface(true);
3525 child1->SetHasRenderSurface(true);
3526 child2->SetHasRenderSurface(true);
3527 ExecuteCalculateDrawProperties(root); 3150 ExecuteCalculateDrawProperties(root);
3528 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); 3151 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3529 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); 3152 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3530 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect()); 3153 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3531 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect()); 3154 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3532 EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect()); 3155 EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect());
3533 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect()); 3156 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3534 EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect()); 3157 EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect());
3535 EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect()); 3158 EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect());
3536 3159
(...skipping 26 matching lines...) Expand all
3563 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); 3186 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3564 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); 3187 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3565 } 3188 }
3566 3189
3567 TEST_F(LayerTreeHostCommonTest, 3190 TEST_F(LayerTreeHostCommonTest,
3568 VisibleContentRectsForClippedSurfaceWithEmptyClip) { 3191 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
3569 LayerImpl* root = root_layer_for_testing(); 3192 LayerImpl* root = root_layer_for_testing();
3570 LayerImpl* child1 = AddChild<LayerImpl>(root); 3193 LayerImpl* child1 = AddChild<LayerImpl>(root);
3571 LayerImpl* child2 = AddChild<LayerImpl>(root); 3194 LayerImpl* child2 = AddChild<LayerImpl>(root);
3572 LayerImpl* child3 = AddChild<LayerImpl>(root); 3195 LayerImpl* child3 = AddChild<LayerImpl>(root);
3196
3197 root->SetBounds(gfx::Size(100, 100));
3198 child1->SetPosition(gfx::PointF(5.f, 5.f));
3199 child1->SetBounds(gfx::Size(50, 50));
3573 child1->SetDrawsContent(true); 3200 child1->SetDrawsContent(true);
3201 child2->SetPosition(gfx::PointF(75.f, 75.f));
3202 child2->SetBounds(gfx::Size(50, 50));
3574 child2->SetDrawsContent(true); 3203 child2->SetDrawsContent(true);
3204 child3->SetPosition(gfx::PointF(125.f, 125.f));
3205 child3->SetBounds(gfx::Size(50, 50));
3575 child3->SetDrawsContent(true); 3206 child3->SetDrawsContent(true);
3576 3207
3577 gfx::Transform identity_matrix;
3578 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3579 gfx::PointF(), gfx::Size(100, 100), true, false,
3580 true);
3581 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3582 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3583 false, false);
3584 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3585 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3586 false, false);
3587 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3588 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3589 true, false, false);
3590
3591 LayerImplList render_surface_layer_list_impl; 3208 LayerImplList render_surface_layer_list_impl;
3592 // Now set the root render surface an empty clip. 3209 // Now set the root render surface an empty clip.
3593 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 3210 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
3594 root, gfx::Size(), &render_surface_layer_list_impl); 3211 root, gfx::Size(), &render_surface_layer_list_impl);
3595 3212
3596 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 3213 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
3597 ASSERT_TRUE(root->render_surface()); 3214 ASSERT_TRUE(root->render_surface());
3598 EXPECT_FALSE(root->is_clipped()); 3215 EXPECT_FALSE(root->is_clipped());
3599 3216
3600 gfx::Rect empty; 3217 gfx::Rect empty;
3601 EXPECT_EQ(empty, root->render_surface()->clip_rect()); 3218 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3602 EXPECT_TRUE(root->render_surface()->is_clipped()); 3219 EXPECT_TRUE(root->render_surface()->is_clipped());
3603 3220
3604 // Visible content rect calculation will check if the target surface is 3221 // Visible content rect calculation will check if the target surface is
3605 // clipped or not. An empty clip rect does not indicate the render surface 3222 // clipped or not. An empty clip rect does not indicate the render surface
3606 // is unclipped. 3223 // is unclipped.
3607 EXPECT_EQ(empty, child1->visible_layer_rect()); 3224 EXPECT_EQ(empty, child1->visible_layer_rect());
3608 EXPECT_EQ(empty, child2->visible_layer_rect()); 3225 EXPECT_EQ(empty, child2->visible_layer_rect());
3609 EXPECT_EQ(empty, child3->visible_layer_rect()); 3226 EXPECT_EQ(empty, child3->visible_layer_rect());
3610 } 3227 }
3611 3228
3612 TEST_F(LayerTreeHostCommonTest, 3229 TEST_F(LayerTreeHostCommonTest,
3613 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { 3230 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
3614 LayerImpl* root = root_layer_for_testing(); 3231 LayerImpl* root = root_layer_for_testing();
3615 LayerImpl* child = AddChildToRoot<LayerImpl>(); 3232 LayerImpl* child = AddChildToRoot<LayerImpl>();
3233
3234 root->SetBounds(gfx::Size(100, 100));
3235 child->SetPosition(gfx::PointF(5.f, 5.f));
3236 child->SetBounds(gfx::Size(50, 50));
3616 child->SetDrawsContent(true); 3237 child->SetDrawsContent(true);
3617 3238
3618 // Case 1: a truly degenerate matrix 3239 // Case 1: a truly degenerate matrix
3619 gfx::Transform identity_matrix; 3240 gfx::Transform identity_matrix;
3620 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 3241 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3621 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); 3242 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3622 3243
3623 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 3244 child->SetTransform(uninvertible_matrix);
3624 gfx::PointF(), gfx::Size(100, 100), true, false,
3625 true);
3626 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3627 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3628 false, false);
3629
3630 ExecuteCalculateDrawProperties(root); 3245 ExecuteCalculateDrawProperties(root);
3631 3246
3632 EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); 3247 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
3633 EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); 3248 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
3634 3249
3635 // Case 2: a matrix with flattened z, uninvertible and not visible according 3250 // Case 2: a matrix with flattened z, uninvertible and not visible according
3636 // to the CSS spec. 3251 // to the CSS spec.
3637 uninvertible_matrix.MakeIdentity(); 3252 uninvertible_matrix.MakeIdentity();
3638 uninvertible_matrix.matrix().set(2, 2, 0.0); 3253 uninvertible_matrix.matrix().set(2, 2, 0.0);
3639 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); 3254 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3640 3255
3641 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), 3256 child->SetTransform(uninvertible_matrix);
3642 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3643 false, false);
3644
3645 ExecuteCalculateDrawProperties(root); 3257 ExecuteCalculateDrawProperties(root);
3646 3258
3647 EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); 3259 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
3648 EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); 3260 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
3649 3261
3650 // Case 3: a matrix with flattened z, also uninvertible and not visible. 3262 // Case 3: a matrix with flattened z, also uninvertible and not visible.
3651 uninvertible_matrix.MakeIdentity(); 3263 uninvertible_matrix.MakeIdentity();
3652 uninvertible_matrix.Translate(500.0, 0.0); 3264 uninvertible_matrix.Translate(500.0, 0.0);
3653 uninvertible_matrix.matrix().set(2, 2, 0.0); 3265 uninvertible_matrix.matrix().set(2, 2, 0.0);
3654 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); 3266 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3655 3267
3656 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), 3268 child->SetTransform(uninvertible_matrix);
3657 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3658 false, false);
3659
3660 ExecuteCalculateDrawProperties(root); 3269 ExecuteCalculateDrawProperties(root);
3661 3270
3662 EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); 3271 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
3663 EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); 3272 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
3664 } 3273 }
3665 3274
3666 TEST_F(LayerTreeHostCommonTest, 3275 TEST_F(LayerTreeHostCommonTest,
3667 VisibleContentRectForLayerWithUninvertibleDrawTransform) { 3276 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
3668 LayerImpl* root = root_layer_for_testing(); 3277 LayerImpl* root = root_layer_for_testing();
3669 LayerImpl* child = AddChildToRoot<LayerImpl>(); 3278 LayerImpl* child = AddChildToRoot<LayerImpl>();
3670 LayerImpl* grand_child = AddChild<LayerImpl>(child); 3279 LayerImpl* grand_child = AddChild<LayerImpl>(child);
3671 child->SetDrawsContent(true);
3672 grand_child->SetDrawsContent(true);
3673 3280
3674 gfx::Transform identity_matrix; 3281 gfx::Transform identity_matrix;
3675 3282
3676 gfx::Transform perspective; 3283 gfx::Transform perspective;
3677 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); 3284 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3678 3285
3679 gfx::Transform rotation; 3286 gfx::Transform rotation;
3680 rotation.RotateAboutYAxis(45.0); 3287 rotation.RotateAboutYAxis(45.0);
3681 3288
3682 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 3289 root->SetBounds(gfx::Size(100, 100));
3683 gfx::PointF(), gfx::Size(100, 100), true, false, 3290 child->SetTransform(perspective);
3684 true); 3291 child->SetPosition(gfx::PointF(10.f, 10.f));
3685 SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(), 3292 child->SetBounds(gfx::Size(100, 100));
3686 gfx::PointF(10.f, 10.f), gfx::Size(100, 100), 3293 child->SetDrawsContent(true);
3687 false, true, false); 3294 child->Set3dSortingContextId(1);
3688 SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(), 3295 child->test_properties()->should_flatten_transform = false;
3689 gfx::PointF(), gfx::Size(100, 100), false, true, 3296 grand_child->SetTransform(rotation);
3690 false); 3297 grand_child->SetBounds(gfx::Size(100, 100));
3691 3298 grand_child->SetDrawsContent(true);
3299 grand_child->Set3dSortingContextId(1);
3300 grand_child->test_properties()->should_flatten_transform = false;
3692 ExecuteCalculateDrawProperties(root); 3301 ExecuteCalculateDrawProperties(root);
3693 3302
3694 // Though all layers have invertible transforms, matrix multiplication using 3303 // Though all layers have invertible transforms, matrix multiplication using
3695 // floating-point math makes the draw transform uninvertible. 3304 // floating-point math makes the draw transform uninvertible.
3696 EXPECT_FALSE(root->layer_tree_impl() 3305 EXPECT_FALSE(root->layer_tree_impl()
3697 ->property_trees() 3306 ->property_trees()
3698 ->transform_tree.Node(grand_child->transform_tree_index()) 3307 ->transform_tree.Node(grand_child->transform_tree_index())
3699 ->ancestors_are_invertible); 3308 ->ancestors_are_invertible);
3700 3309
3701 // CalcDrawProps skips a subtree when a layer's screen space transform is 3310 // CalcDrawProps skips a subtree when a layer's screen space transform is
(...skipping 24 matching lines...) Expand all
3726 3335
3727 surface->SetDrawsContent(true); 3336 surface->SetDrawsContent(true);
3728 surface_child->SetDrawsContent(true); 3337 surface_child->SetDrawsContent(true);
3729 surface_sibling->SetDrawsContent(true); 3338 surface_sibling->SetDrawsContent(true);
3730 surface_child_mask->SetDrawsContent(true); 3339 surface_child_mask->SetDrawsContent(true);
3731 surface->SetContentsOpaque(true); 3340 surface->SetContentsOpaque(true);
3732 surface_child->SetContentsOpaque(true); 3341 surface_child->SetContentsOpaque(true);
3733 surface_sibling->SetContentsOpaque(true); 3342 surface_sibling->SetContentsOpaque(true);
3734 surface_child_mask->SetContentsOpaque(true); 3343 surface_child_mask->SetContentsOpaque(true);
3735 3344
3736 surface->test_properties()->opacity = 0.5f;
3737 surface_child->test_properties()->opacity = 0.6f;
3738
3739 gfx::Transform identity_matrix;
3740 gfx::Transform translate; 3345 gfx::Transform translate;
3741 translate.Translate(20.f, 20.f); 3346 translate.Translate(20.f, 20.f);
3742 3347
3743 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), 3348 root->SetBounds(gfx::Size(1000, 1000));
3744 gfx::PointF(), gfx::Size(1000, 1000), true, 3349 child->SetBounds(gfx::Size(300, 300));
3745 false, true); 3350 surface->SetTransform(translate);
3746 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), 3351 surface->SetBounds(gfx::Size(300, 300));
3747 gfx::PointF(), gfx::Size(300, 300), false, true, 3352 surface->test_properties()->force_render_surface = true;
3748 false); 3353 surface_child->SetBounds(gfx::Size(300, 300));
3749 SetLayerPropertiesForTesting(surface.get(), translate, gfx::Point3F(), 3354 surface_child->test_properties()->force_render_surface = true;
3750 gfx::PointF(), gfx::Size(300, 300), false, true, 3355 surface_sibling->SetBounds(gfx::Size(200, 200));
3751 true);
3752 SetLayerPropertiesForTesting(surface_child.get(), identity_matrix,
3753 gfx::Point3F(), gfx::PointF(),
3754 gfx::Size(300, 300), false, false, true);
3755 SetLayerPropertiesForTesting(surface_sibling.get(), identity_matrix,
3756 gfx::Point3F(), gfx::PointF(),
3757 gfx::Size(200, 200), false, false, false);
3758 3356
3759 LayerImpl* surface_ptr = surface.get(); 3357 LayerImpl* surface_ptr = surface.get();
3760 LayerImpl* surface_child_ptr = surface_child.get(); 3358 LayerImpl* surface_child_ptr = surface_child.get();
3761 LayerImpl* surface_child_mask_ptr = surface_child_mask.get(); 3359 LayerImpl* surface_child_mask_ptr = surface_child_mask.get();
3762 3360
3763 host_impl.SetViewportSize(root->bounds()); 3361 host_impl.SetViewportSize(root->bounds());
3764 3362
3765 surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask)); 3363 surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask));
3766 surface->test_properties()->AddChild(std::move(surface_child)); 3364 surface->test_properties()->AddChild(std::move(surface_child));
3767 child->test_properties()->AddChild(std::move(surface)); 3365 child->test_properties()->AddChild(std::move(surface));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3800 &task_graph_runner); 3398 &task_graph_runner);
3801 3399
3802 std::unique_ptr<LayerImpl> root = 3400 std::unique_ptr<LayerImpl> root =
3803 LayerImpl::Create(host_impl.active_tree(), 1); 3401 LayerImpl::Create(host_impl.active_tree(), 1);
3804 std::unique_ptr<LayerImpl> child = 3402 std::unique_ptr<LayerImpl> child =
3805 LayerImpl::Create(host_impl.active_tree(), 2); 3403 LayerImpl::Create(host_impl.active_tree(), 2);
3806 std::unique_ptr<LayerImpl> grand_child = 3404 std::unique_ptr<LayerImpl> grand_child =
3807 LayerImpl::Create(host_impl.active_tree(), 3); 3405 LayerImpl::Create(host_impl.active_tree(), 3);
3808 std::unique_ptr<LayerImpl> occluding_child = 3406 std::unique_ptr<LayerImpl> occluding_child =
3809 LayerImpl::Create(host_impl.active_tree(), 4); 3407 LayerImpl::Create(host_impl.active_tree(), 4);
3810 child->SetDrawsContent(true);
3811 grand_child->SetDrawsContent(true);
3812 occluding_child->SetDrawsContent(true);
3813 occluding_child->SetContentsOpaque(true);
3814 3408
3815 gfx::Transform identity_matrix; 3409 gfx::Transform identity_matrix;
3816 gfx::Transform perspective; 3410 gfx::Transform perspective;
3817 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); 3411 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3818 3412
3819 gfx::Transform rotation; 3413 gfx::Transform rotation;
3820 rotation.RotateAboutYAxis(45.0); 3414 rotation.RotateAboutYAxis(45.0);
3821 3415
3822 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), 3416 root->SetBounds(gfx::Size(1000, 1000));
3823 gfx::PointF(), gfx::Size(1000, 1000), true, 3417 child->SetTransform(perspective);
3824 false, true); 3418 child->SetPosition(gfx::PointF(10.f, 10.f));
3825 SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(), 3419 child->SetBounds(gfx::Size(300, 300));
3826 gfx::PointF(10.f, 10.f), gfx::Size(300, 300), 3420 child->test_properties()->should_flatten_transform = false;
3827 false, true, false); 3421 child->Set3dSortingContextId(1);
3828 SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(), 3422 grand_child->SetTransform(rotation);
3829 gfx::PointF(), gfx::Size(200, 200), false, true, 3423 grand_child->SetBounds(gfx::Size(200, 200));
3830 false); 3424 grand_child->test_properties()->should_flatten_transform = false;
3831 SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix, 3425 grand_child->Set3dSortingContextId(1);
3832 gfx::Point3F(), gfx::PointF(), 3426 occluding_child->SetBounds(gfx::Size(200, 200));
3833 gfx::Size(200, 200), false, false, false); 3427 occluding_child->test_properties()->should_flatten_transform = false;
3428
3429 child->SetDrawsContent(true);
3430 grand_child->SetDrawsContent(true);
3431 occluding_child->SetDrawsContent(true);
3432 occluding_child->SetContentsOpaque(true);
3834 3433
3835 host_impl.SetViewportSize(root->bounds()); 3434 host_impl.SetViewportSize(root->bounds());
3836 3435
3837 child->test_properties()->AddChild(std::move(grand_child)); 3436 child->test_properties()->AddChild(std::move(grand_child));
3838 root->test_properties()->AddChild(std::move(child)); 3437 root->test_properties()->AddChild(std::move(child));
3839 root->test_properties()->AddChild(std::move(occluding_child)); 3438 root->test_properties()->AddChild(std::move(occluding_child));
3840 host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); 3439 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
3841 host_impl.SetVisible(true); 3440 host_impl.SetVisible(true);
3842 host_impl.InitializeRenderer(output_surface.get()); 3441 host_impl.InitializeRenderer(output_surface.get());
3843 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); 3442 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
(...skipping 23 matching lines...) Expand all
3867 layer_bounds, 3466 layer_bounds,
3868 grand_child_ptr->draw_properties() 3467 grand_child_ptr->draw_properties()
3869 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds)); 3468 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3870 } 3469 }
3871 3470
3872 TEST_F(LayerTreeHostCommonTest, 3471 TEST_F(LayerTreeHostCommonTest,
3873 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { 3472 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
3874 LayerImpl* root = root_layer_for_testing(); 3473 LayerImpl* root = root_layer_for_testing();
3875 LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); 3474 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3876 LayerImpl* child1 = AddChild<LayerImpl>(render_surface); 3475 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3476 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
3477 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
3478
3479 root->SetBounds(gfx::Size(100, 100));
3480 root->SetMasksToBounds(true);
3481 render_surface->SetBounds(gfx::Size(3, 4));
3482 render_surface->test_properties()->force_render_surface = true;
3483 child1->SetPosition(gfx::PointF(5.f, 5.f));
3484 child1->SetBounds(gfx::Size(50, 50));
3877 child1->SetDrawsContent(true); 3485 child1->SetDrawsContent(true);
3878 LayerImpl* child2 = AddChild<LayerImpl>(render_surface); 3486 child2->SetPosition(gfx::PointF(75.f, 75.f));
3487 child2->SetBounds(gfx::Size(50, 50));
3879 child2->SetDrawsContent(true); 3488 child2->SetDrawsContent(true);
3880 LayerImpl* child3 = AddChild<LayerImpl>(render_surface); 3489 child3->SetPosition(gfx::PointF(125.f, 125.f));
3490 child3->SetBounds(gfx::Size(50, 50));
3881 child3->SetDrawsContent(true); 3491 child3->SetDrawsContent(true);
3882
3883 gfx::Transform identity_matrix;
3884 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3885 gfx::PointF(), gfx::Size(100, 100), true, false,
3886 true);
3887 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3888 gfx::PointF(), gfx::Size(3, 4), true, false,
3889 true);
3890 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3891 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3892 false, false);
3893 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3894 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3895 false, false);
3896 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3897 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3898 true, false, false);
3899
3900 root->SetMasksToBounds(true);
3901
3902 ExecuteCalculateDrawProperties(root); 3492 ExecuteCalculateDrawProperties(root);
3903 3493
3904 ASSERT_TRUE(render_surface->render_surface()); 3494 ASSERT_TRUE(render_surface->render_surface());
3905 3495
3906 EXPECT_EQ(gfx::RectF(100.f, 100.f), 3496 EXPECT_EQ(gfx::RectF(100.f, 100.f),
3907 root->render_surface()->DrawableContentRect()); 3497 root->render_surface()->DrawableContentRect());
3908 3498
3909 // Layers that do not draw content should have empty visible content rects. 3499 // Layers that do not draw content should have empty visible content rects.
3910 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); 3500 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3911 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); 3501 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
(...skipping 15 matching lines...) Expand all
3927 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); 3517 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3928 } 3518 }
3929 3519
3930 TEST_F(LayerTreeHostCommonTest, 3520 TEST_F(LayerTreeHostCommonTest,
3931 DrawableAndVisibleContentRectsForSurfaceHierarchy) { 3521 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
3932 // Check that clipping does not propagate down surfaces. 3522 // Check that clipping does not propagate down surfaces.
3933 LayerImpl* root = root_layer_for_testing(); 3523 LayerImpl* root = root_layer_for_testing();
3934 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); 3524 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3935 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); 3525 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3936 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2); 3526 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
3527 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
3528 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
3529
3530 root->SetBounds(gfx::Size(100, 100));
3531 root->SetMasksToBounds(true);
3532 render_surface1->SetBounds(gfx::Size(3, 4));
3533 render_surface1->test_properties()->force_render_surface = true;
3534 render_surface2->SetBounds(gfx::Size(7, 13));
3535 render_surface2->test_properties()->force_render_surface = true;
3536 child1->SetPosition(gfx::PointF(5.f, 5.f));
3537 child1->SetBounds(gfx::Size(50, 50));
3937 child1->SetDrawsContent(true); 3538 child1->SetDrawsContent(true);
3938 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); 3539 child2->SetPosition(gfx::PointF(75.f, 75.f));
3540 child2->SetBounds(gfx::Size(50, 50));
3939 child2->SetDrawsContent(true); 3541 child2->SetDrawsContent(true);
3940 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2); 3542 child3->SetPosition(gfx::PointF(125.f, 125.f));
3543 child3->SetBounds(gfx::Size(50, 50));
3941 child3->SetDrawsContent(true); 3544 child3->SetDrawsContent(true);
3942
3943 gfx::Transform identity_matrix;
3944 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3945 gfx::PointF(), gfx::Size(100, 100), true, false,
3946 true);
3947 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3948 gfx::PointF(), gfx::Size(3, 4), true, false,
3949 true);
3950 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3951 gfx::PointF(), gfx::Size(7, 13), true, false,
3952 true);
3953 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3954 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3955 false, false);
3956 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3957 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3958 false, false);
3959 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3960 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3961 true, false, false);
3962
3963 root->SetMasksToBounds(true);
3964
3965 ExecuteCalculateDrawProperties(root); 3545 ExecuteCalculateDrawProperties(root);
3966 3546
3967 ASSERT_TRUE(render_surface1->render_surface()); 3547 ASSERT_TRUE(render_surface1->render_surface());
3968 ASSERT_TRUE(render_surface2->render_surface()); 3548 ASSERT_TRUE(render_surface2->render_surface());
3969 3549
3970 EXPECT_EQ(gfx::RectF(100.f, 100.f), 3550 EXPECT_EQ(gfx::RectF(100.f, 100.f),
3971 root->render_surface()->DrawableContentRect()); 3551 root->render_surface()->DrawableContentRect());
3972 3552
3973 // Layers that do not draw content should have empty visible content rects. 3553 // Layers that do not draw content should have empty visible content rects.
3974 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); 3554 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
(...skipping 22 matching lines...) Expand all
3997 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); 3577 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3998 } 3578 }
3999 3579
4000 TEST_F(LayerTreeHostCommonTest, 3580 TEST_F(LayerTreeHostCommonTest,
4001 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) { 3581 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
4002 LayerImpl* root = root_layer_for_testing(); 3582 LayerImpl* root = root_layer_for_testing();
4003 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); 3583 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
4004 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); 3584 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
4005 LayerImpl* child2 = AddChild<LayerImpl>(child1); 3585 LayerImpl* child2 = AddChild<LayerImpl>(child1);
4006 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2); 3586 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
3587
3588 root->SetBounds(gfx::Size(100, 100));
3589 render_surface1->SetBounds(gfx::Size(100, 100));
3590 render_surface1->test_properties()->force_render_surface = true;
3591 child1->SetBounds(gfx::Size(500, 500));
4007 child1->SetDrawsContent(true); 3592 child1->SetDrawsContent(true);
3593 child2->SetBounds(gfx::Size(700, 700));
4008 child2->SetDrawsContent(true); 3594 child2->SetDrawsContent(true);
3595 render_surface2->SetBounds(gfx::Size(1000, 1000));
3596 render_surface2->test_properties()->force_render_surface = true;
4009 render_surface2->SetDrawsContent(true); 3597 render_surface2->SetDrawsContent(true);
4010 3598
4011 gfx::Transform identity_matrix;
4012 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4013 gfx::PointF(), gfx::Size(100, 100), true, false,
4014 true);
4015 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
4016 gfx::PointF(), gfx::Size(100, 100), true, false,
4017 true);
4018 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
4019 gfx::PointF(), gfx::Size(500, 500), true, false,
4020 false);
4021 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4022 gfx::PointF(), gfx::Size(700, 700), true, false,
4023 false);
4024 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
4025 gfx::PointF(), gfx::Size(1000, 1000), true,
4026 false, true);
4027
4028 child1->SetMasksToBounds(true); 3599 child1->SetMasksToBounds(true);
4029 child2->SetMasksToBounds(true); 3600 child2->SetMasksToBounds(true);
4030
4031 ExecuteCalculateDrawProperties(root); 3601 ExecuteCalculateDrawProperties(root);
4032 EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect()); 3602 EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect());
4033 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); 3603 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
4034 } 3604 }
4035 3605
4036 TEST_F(LayerTreeHostCommonTest, 3606 TEST_F(LayerTreeHostCommonTest,
4037 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { 3607 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
4038 LayerImpl* root = root_layer_for_testing(); 3608 LayerImpl* root = root_layer_for_testing();
4039 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); 3609 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
4040 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); 3610 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
4041 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); 3611 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
4042 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); 3612 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
4043 3613
3614 root->SetBounds(gfx::Size(100, 100));
3615
3616 clip_parent->SetBounds(gfx::Size(50, 50));
3617 clip_parent->SetMasksToBounds(true);
3618 clip_parent->test_properties()->clip_children =
3619 base::MakeUnique<std::set<LayerImpl*>>();
3620 clip_parent->test_properties()->clip_children->insert(clip_child);
3621
3622 render_surface1->SetBounds(gfx::Size(20, 20));
3623 render_surface1->SetMasksToBounds(true);
4044 render_surface1->SetDrawsContent(true); 3624 render_surface1->SetDrawsContent(true);
4045 render_surface2->SetDrawsContent(true); 3625 render_surface1->test_properties()->force_render_surface = true;
3626
3627 clip_child->SetBounds(gfx::Size(60, 60));
4046 clip_child->SetDrawsContent(true); 3628 clip_child->SetDrawsContent(true);
4047 clip_child->test_properties()->clip_parent = clip_parent; 3629 clip_child->test_properties()->clip_parent = clip_parent;
4048 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
4049 clip_children->insert(clip_child);
4050 clip_parent->test_properties()->clip_children.reset(clip_children.release());
4051 3630
4052 gfx::Transform identity_matrix; 3631 render_surface2->SetBounds(gfx::Size(60, 60));
4053 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 3632 render_surface2->SetDrawsContent(true);
4054 gfx::PointF(), gfx::Size(100, 100), true, false, 3633 render_surface2->test_properties()->force_render_surface = true;
4055 true);
4056 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
4057 gfx::PointF(), gfx::Size(50, 50), true, false,
4058 false);
4059 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
4060 gfx::PointF(), gfx::Size(20, 20), true, false,
4061 true);
4062 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
4063 gfx::PointF(), gfx::Size(60, 60), true, false,
4064 false);
4065 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
4066 gfx::PointF(), gfx::Size(60, 60), true, false,
4067 true);
4068 clip_parent->SetMasksToBounds(true);
4069 render_surface1->SetMasksToBounds(true);
4070 3634
4071 ExecuteCalculateDrawProperties(root); 3635 ExecuteCalculateDrawProperties(root);
4072 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect()); 3636 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
4073 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect()); 3637 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
4074 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect()); 3638 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
4075 } 3639 }
4076 3640
4077 TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) { 3641 TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
4078 LayerImpl* root = root_layer_for_testing(); 3642 LayerImpl* root = root_layer_for_testing();
4079 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); 3643 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
4080 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); 3644 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
4081 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); 3645 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
4082 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); 3646 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
4083 3647
3648 root->SetBounds(gfx::Size(100, 100));
3649
3650 clip_parent->SetPosition(gfx::PointF(2.f, 2.f));
3651 clip_parent->SetBounds(gfx::Size(50, 50));
3652 clip_parent->test_properties()->clip_children =
3653 base::MakeUnique<std::set<LayerImpl*>>();
3654 clip_parent->test_properties()->clip_children->insert(clip_child);
3655
3656 render_surface1->SetBounds(gfx::Size(20, 20));
4084 render_surface1->SetDrawsContent(true); 3657 render_surface1->SetDrawsContent(true);
4085 render_surface2->SetDrawsContent(true); 3658 render_surface1->test_properties()->force_render_surface = true;
3659
3660 clip_child->SetBounds(gfx::Size(60, 60));
4086 clip_child->SetDrawsContent(true); 3661 clip_child->SetDrawsContent(true);
4087 clip_child->test_properties()->clip_parent = clip_parent; 3662 clip_child->test_properties()->clip_parent = clip_parent;
4088 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
4089 clip_children->insert(clip_child);
4090 clip_parent->test_properties()->clip_children.reset(clip_children.release());
4091 3663
4092 gfx::Transform identity_matrix; 3664 render_surface2->SetBounds(gfx::Size(60, 60));
4093 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 3665 render_surface2->SetDrawsContent(true);
4094 gfx::PointF(), gfx::Size(100, 100), true, false, 3666 render_surface2->test_properties()->force_render_surface = true;
4095 true); 3667
4096 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
4097 gfx::PointF(2.f, 2.f), gfx::Size(50, 50), true,
4098 false, false);
4099 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
4100 gfx::PointF(), gfx::Size(20, 20), true, false,
4101 true);
4102 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
4103 gfx::PointF(), gfx::Size(60, 60), true, false,
4104 false);
4105 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
4106 gfx::PointF(), gfx::Size(60, 60), true, false,
4107 true);
4108 clip_parent->SetMasksToBounds(true); 3668 clip_parent->SetMasksToBounds(true);
4109 render_surface1->SetMasksToBounds(true); 3669 render_surface1->SetMasksToBounds(true);
4110 3670
4111 ExecuteCalculateDrawProperties(root); 3671 ExecuteCalculateDrawProperties(root);
4112 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect()); 3672 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect());
4113 } 3673 }
4114 3674
4115 TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) { 3675 TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
4116 // Test that only drawn layers contribute to render surface content rect. 3676 // Test that only drawn layers contribute to render surface content rect.
4117 LayerImpl* root = root_layer_for_testing(); 3677 LayerImpl* root = root_layer_for_testing();
4118 LayerImpl* surface = AddChildToRoot<LayerImpl>(); 3678 LayerImpl* surface = AddChildToRoot<LayerImpl>();
4119 LayerImpl* test_layer = AddChild<LayerImpl>(surface); 3679 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
4120 3680
4121 test_layer->SetDrawsContent(false); 3681 root->SetBounds(gfx::Size(200, 200));
3682 surface->SetBounds(gfx::Size(100, 100));
4122 surface->SetDrawsContent(true); 3683 surface->SetDrawsContent(true);
4123 gfx::Transform identity_matrix; 3684 surface->test_properties()->force_render_surface = true;
4124 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 3685 test_layer->SetBounds(gfx::Size(150, 150));
4125 gfx::PointF(), gfx::Size(200, 200), true, false,
4126 true);
4127 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
4128 gfx::PointF(), gfx::Size(100, 100), true, false,
4129 true);
4130 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
4131 gfx::PointF(), gfx::Size(150, 150), true, false,
4132 false);
4133 3686
4134 ExecuteCalculateDrawProperties(root); 3687 ExecuteCalculateDrawProperties(root);
4135 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect()); 3688 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect());
4136 3689
4137 test_layer->SetDrawsContent(true); 3690 test_layer->SetDrawsContent(true);
4138 ExecuteCalculateDrawProperties(root); 3691 ExecuteCalculateDrawProperties(root);
4139 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect()); 3692 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect());
4140 } 3693 }
4141 3694
4142 TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) { 3695 TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
4143 // Tests visible rects computation when we have unclipped_surface-> 3696 // Tests visible rects computation when we have unclipped_surface->
4144 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds 3697 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
4145 // of surface_with_unclipped_descendants doesn't propagate to the 3698 // of surface_with_unclipped_descendants doesn't propagate to the
4146 // clipped_surface below it. 3699 // clipped_surface below it.
4147 LayerImpl* root = root_layer_for_testing(); 3700 LayerImpl* root = root_layer_for_testing();
4148 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); 3701 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
4149 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); 3702 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
4150 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); 3703 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
4151 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); 3704 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
4152 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); 3705 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
4153 3706
3707 root->SetBounds(gfx::Size(100, 100));
3708
3709 unclipped_surface->SetBounds(gfx::Size(30, 30));
4154 unclipped_surface->SetDrawsContent(true); 3710 unclipped_surface->SetDrawsContent(true);
3711 unclipped_surface->test_properties()->force_render_surface = true;
3712
3713 clip_parent->SetBounds(gfx::Size(50, 50));
3714 clip_parent->test_properties()->clip_children =
3715 base::MakeUnique<std::set<LayerImpl*>>();
3716 clip_parent->test_properties()->clip_children->insert(clip_child);
3717
3718 unclipped_desc_surface->SetBounds(gfx::Size(20, 20));
4155 unclipped_desc_surface->SetDrawsContent(true); 3719 unclipped_desc_surface->SetDrawsContent(true);
3720 unclipped_desc_surface->test_properties()->force_render_surface = true;
3721
3722 clip_child->SetBounds(gfx::Size(60, 60));
3723 clip_child->test_properties()->clip_parent = clip_parent;
3724
3725 clipped_surface->SetBounds(gfx::Size(60, 60));
4156 clipped_surface->SetDrawsContent(true); 3726 clipped_surface->SetDrawsContent(true);
4157 clip_child->test_properties()->clip_parent = clip_parent; 3727 clipped_surface->test_properties()->force_render_surface = true;
4158 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
4159 clip_children->insert(clip_child);
4160 clip_parent->test_properties()->clip_children.reset(clip_children.release());
4161 3728
4162 gfx::Transform identity_matrix;
4163 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4164 gfx::PointF(), gfx::Size(100, 100), true, false,
4165 true);
4166 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
4167 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4168 true, false, true);
4169 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
4170 gfx::PointF(), gfx::Size(50, 50), true, false,
4171 false);
4172 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
4173 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4174 true, false, true);
4175 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
4176 gfx::PointF(), gfx::Size(60, 60), true, false,
4177 false);
4178 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
4179 gfx::PointF(), gfx::Size(60, 60), true, false,
4180 true);
4181 clip_parent->SetMasksToBounds(true); 3729 clip_parent->SetMasksToBounds(true);
4182 3730
4183 ExecuteCalculateDrawProperties(root); 3731 ExecuteCalculateDrawProperties(root);
4184 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect()); 3732 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
4185 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect()); 3733 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
4186 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect()); 3734 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
4187 } 3735 }
4188 3736
4189 TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) { 3737 TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
4190 // Tests visible rects computation when we have unclipped_surface-> 3738 // Tests visible rects computation when we have unclipped_surface->
4191 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds 3739 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
4192 // of root propagate to the clipped_surface. 3740 // of root propagate to the clipped_surface.
4193 LayerImpl* root = root_layer_for_testing(); 3741 LayerImpl* root = root_layer_for_testing();
4194 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); 3742 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
4195 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); 3743 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
4196 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); 3744 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
4197 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); 3745 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
4198 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); 3746 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
4199 3747
3748 root->SetBounds(gfx::Size(10, 10));
3749
3750 unclipped_surface->SetBounds(gfx::Size(50, 50));
4200 unclipped_surface->SetDrawsContent(true); 3751 unclipped_surface->SetDrawsContent(true);
3752 unclipped_surface->test_properties()->force_render_surface = true;
3753
3754 clip_parent->SetBounds(gfx::Size(50, 50));
3755 clip_parent->test_properties()->clip_children =
3756 base::MakeUnique<std::set<LayerImpl*>>();
3757 clip_parent->test_properties()->clip_children->insert(clip_child);
3758
3759 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
4201 unclipped_desc_surface->SetDrawsContent(true); 3760 unclipped_desc_surface->SetDrawsContent(true);
3761 unclipped_desc_surface->test_properties()->force_render_surface = true;
3762
3763 clip_child->SetBounds(gfx::Size(100, 100));
3764 clip_child->test_properties()->clip_parent = clip_parent;
3765
3766 clipped_surface->SetBounds(gfx::Size(50, 50));
4202 clipped_surface->SetDrawsContent(true); 3767 clipped_surface->SetDrawsContent(true);
4203 clip_child->test_properties()->clip_parent = clip_parent; 3768 clipped_surface->test_properties()->force_render_surface = true;
4204 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
4205 clip_children->insert(clip_child);
4206 clip_parent->test_properties()->clip_children.reset(clip_children.release());
4207 3769
4208 gfx::Transform identity_matrix;
4209 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4210 gfx::PointF(), gfx::Size(10, 10), true, false,
4211 true);
4212 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
4213 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
4214 true, false, true);
4215 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
4216 gfx::PointF(), gfx::Size(50, 50), true, false,
4217 false);
4218 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
4219 gfx::Point3F(), gfx::PointF(),
4220 gfx::Size(100, 100), true, false, true);
4221 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
4222 gfx::PointF(), gfx::Size(100, 100), true, false,
4223 false);
4224 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
4225 gfx::PointF(), gfx::Size(50, 50), true, false,
4226 true);
4227 clip_parent->SetMasksToBounds(true); 3770 clip_parent->SetMasksToBounds(true);
4228 unclipped_desc_surface->SetMasksToBounds(true); 3771 unclipped_desc_surface->SetMasksToBounds(true);
4229 3772
4230 ExecuteCalculateDrawProperties(root); 3773 ExecuteCalculateDrawProperties(root);
4231 EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect()); 3774 EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect());
4232 EXPECT_EQ(gfx::Rect(50, 50), unclipped_desc_surface->visible_layer_rect()); 3775 EXPECT_EQ(gfx::Rect(50, 50), unclipped_desc_surface->visible_layer_rect());
4233 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect()); 3776 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
4234 } 3777 }
4235 3778
4236 TEST_F(LayerTreeHostCommonTest, 3779 TEST_F(LayerTreeHostCommonTest,
4237 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { 3780 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
4238 // Layers that have non-axis aligned bounds (due to transforms) have an 3781 // Layers that have non-axis aligned bounds (due to transforms) have an
4239 // expanded, axis-aligned DrawableContentRect and visible content rect. 3782 // expanded, axis-aligned DrawableContentRect and visible content rect.
4240 LayerImpl* root = root_layer_for_testing(); 3783 LayerImpl* root = root_layer_for_testing();
4241 LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); 3784 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4242 LayerImpl* child1 = AddChild<LayerImpl>(render_surface); 3785 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
4243 child1->SetDrawsContent(true);
4244 3786
4245 gfx::Transform identity_matrix; 3787 gfx::Transform identity_matrix;
4246 gfx::Transform child_rotation; 3788 gfx::Transform child_rotation;
4247 child_rotation.Rotate(45.0); 3789 child_rotation.Rotate(45.0);
4248 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4249 gfx::PointF(), gfx::Size(100, 100), true, false,
4250 true);
4251 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
4252 gfx::PointF(), gfx::Size(3, 4), true, false,
4253 true);
4254 SetLayerPropertiesForTesting(
4255 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
4256 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
4257 3790
3791 root->SetBounds(gfx::Size(100, 100));
3792 render_surface->SetBounds(gfx::Size(3, 4));
3793 render_surface->test_properties()->force_render_surface = true;
3794 child1->SetTransform(child_rotation);
3795 child1->SetPosition(gfx::PointF(25.f, 25.f));
3796 child1->SetBounds(gfx::Size(50, 50));
3797 child1->SetDrawsContent(true);
3798 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
4258 ExecuteCalculateDrawProperties(root); 3799 ExecuteCalculateDrawProperties(root);
4259 3800
4260 ASSERT_TRUE(render_surface->render_surface()); 3801 ASSERT_TRUE(render_surface->render_surface());
4261 3802
4262 EXPECT_EQ(gfx::RectF(100.f, 100.f), 3803 EXPECT_EQ(gfx::RectF(100.f, 100.f),
4263 root->render_surface()->DrawableContentRect()); 3804 root->render_surface()->DrawableContentRect());
4264 3805
4265 // Layers that do not draw content should have empty visible content rects. 3806 // Layers that do not draw content should have empty visible content rects.
4266 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); 3807 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
4267 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); 3808 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
(...skipping 14 matching lines...) Expand all
4282 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); 3823 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
4283 } 3824 }
4284 3825
4285 TEST_F(LayerTreeHostCommonTest, 3826 TEST_F(LayerTreeHostCommonTest,
4286 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { 3827 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
4287 // Layers that have non-axis aligned bounds (due to transforms) have an 3828 // Layers that have non-axis aligned bounds (due to transforms) have an
4288 // expanded, axis-aligned DrawableContentRect and visible content rect. 3829 // expanded, axis-aligned DrawableContentRect and visible content rect.
4289 LayerImpl* root = root_layer_for_testing(); 3830 LayerImpl* root = root_layer_for_testing();
4290 LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); 3831 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4291 LayerImpl* child1 = AddChild<LayerImpl>(render_surface); 3832 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
4292 child1->SetDrawsContent(true);
4293 3833
4294 gfx::Transform identity_matrix;
4295 gfx::Transform child_rotation; 3834 gfx::Transform child_rotation;
4296 child_rotation.Rotate(45.0); 3835 child_rotation.Rotate(45.0);
4297 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4298 gfx::PointF(), gfx::Size(50, 50), true, false,
4299 true);
4300 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
4301 gfx::PointF(), gfx::Size(3, 4), true, false,
4302 true);
4303 3836
4304 SetLayerPropertiesForTesting( 3837 root->SetBounds(gfx::Size(50, 50));
4305 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
4306 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
4307
4308 root->SetMasksToBounds(true); 3838 root->SetMasksToBounds(true);
4309 3839 render_surface->SetBounds(gfx::Size(3, 4));
3840 render_surface->test_properties()->force_render_surface = true;
3841 child1->SetPosition(gfx::PointF(25.f, 25.f));
3842 child1->SetBounds(gfx::Size(50, 50));
3843 child1->SetDrawsContent(true);
3844 child1->SetTransform(child_rotation);
3845 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
4310 ExecuteCalculateDrawProperties(root); 3846 ExecuteCalculateDrawProperties(root);
4311 3847
4312 ASSERT_TRUE(render_surface->render_surface()); 3848 ASSERT_TRUE(render_surface->render_surface());
4313 3849
4314 // The clipped surface clamps the DrawableContentRect that encloses the 3850 // The clipped surface clamps the DrawableContentRect that encloses the
4315 // rotated layer. 3851 // rotated layer.
4316 int diagonal_radius = ceil(sqrt(2.0) * 25.0); 3852 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
4317 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, 3853 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
4318 50 - diagonal_radius, 3854 50 - diagonal_radius,
4319 diagonal_radius * 2, 3855 diagonal_radius * 2,
4320 diagonal_radius * 2); 3856 diagonal_radius * 2);
4321 gfx::RectF expected_surface_drawable_content( 3857 gfx::RectF expected_surface_drawable_content(
4322 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); 3858 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
4323 EXPECT_EQ(expected_surface_drawable_content, 3859 EXPECT_EQ(expected_surface_drawable_content,
4324 render_surface->render_surface()->DrawableContentRect()); 3860 render_surface->render_surface()->DrawableContentRect());
4325 3861
4326 // On the clipped surface, only a quarter of the child1 is visible, but when 3862 // On the clipped surface, only a quarter of the child1 is visible, but when
4327 // rotating it back to child1's content space, the actual enclosing rect ends 3863 // rotating it back to child1's content space, the actual enclosing rect ends
4328 // up covering the full left half of child1. 3864 // up covering the full left half of child1.
4329 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect()); 3865 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect());
4330 3866
4331 // The child's DrawableContentRect is unclipped. 3867 // The child's DrawableContentRect is unclipped.
4332 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); 3868 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
4333 } 3869 }
4334 3870
4335 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { 3871 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
4336 LayerImpl* root = root_layer_for_testing(); 3872 LayerImpl* root = root_layer_for_testing();
4337 FakePictureLayerImpl* render_surface1 = 3873 FakePictureLayerImpl* render_surface1 =
4338 AddChildToRoot<FakePictureLayerImpl>(); 3874 AddChildToRoot<FakePictureLayerImpl>();
4339 render_surface1->SetDrawsContent(true);
4340 FakePictureLayerImpl* render_surface2 = 3875 FakePictureLayerImpl* render_surface2 =
4341 AddChild<FakePictureLayerImpl>(render_surface1); 3876 AddChild<FakePictureLayerImpl>(render_surface1);
4342 render_surface2->SetDrawsContent(true);
4343 FakePictureLayerImpl* child1 = 3877 FakePictureLayerImpl* child1 =
4344 AddChild<FakePictureLayerImpl>(render_surface2); 3878 AddChild<FakePictureLayerImpl>(render_surface2);
4345 child1->SetDrawsContent(true);
4346 FakePictureLayerImpl* child2 = 3879 FakePictureLayerImpl* child2 =
4347 AddChild<FakePictureLayerImpl>(render_surface2); 3880 AddChild<FakePictureLayerImpl>(render_surface2);
4348 child2->SetDrawsContent(true);
4349 FakePictureLayerImpl* child3 = 3881 FakePictureLayerImpl* child3 =
4350 AddChild<FakePictureLayerImpl>(render_surface2); 3882 AddChild<FakePictureLayerImpl>(render_surface2);
3883
3884 root->SetBounds(gfx::Size(100, 100));
3885 root->SetMasksToBounds(true);
3886 render_surface1->SetBounds(gfx::Size(3, 4));
3887 render_surface1->SetPosition(gfx::PointF(5.f, 5.f));
3888 render_surface1->SetDrawsContent(true);
3889 render_surface1->test_properties()->force_render_surface = true;
3890 render_surface2->SetBounds(gfx::Size(7, 13));
3891 render_surface2->SetPosition(gfx::PointF(5.f, 5.f));
3892 render_surface2->SetDrawsContent(true);
3893 render_surface2->test_properties()->force_render_surface = true;
3894 child1->SetBounds(gfx::Size(50, 50));
3895 child1->SetPosition(gfx::PointF(5.f, 5.f));
3896 child1->SetDrawsContent(true);
3897 child2->SetBounds(gfx::Size(50, 50));
3898 child2->SetPosition(gfx::PointF(75.f, 75.f));
3899 child2->SetDrawsContent(true);
3900 child3->SetBounds(gfx::Size(50, 50));
3901 child3->SetPosition(gfx::PointF(125.f, 125.f));
4351 child3->SetDrawsContent(true); 3902 child3->SetDrawsContent(true);
4352
4353 gfx::Transform identity_matrix;
4354 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4355 gfx::PointF(), gfx::Size(100, 100), true, false,
4356 true);
4357 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
4358 gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true,
4359 false, true);
4360 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
4361 gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true,
4362 false, true);
4363 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
4364 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
4365 false, false);
4366 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4367 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
4368 false, false);
4369 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
4370 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
4371 true, false, false);
4372
4373 float device_scale_factor = 2.f; 3903 float device_scale_factor = 2.f;
4374
4375 root->SetMasksToBounds(true);
4376
4377 ExecuteCalculateDrawProperties(root, device_scale_factor); 3904 ExecuteCalculateDrawProperties(root, device_scale_factor);
4378 3905
4379 ASSERT_TRUE(render_surface1->render_surface()); 3906 ASSERT_TRUE(render_surface1->render_surface());
4380 ASSERT_TRUE(render_surface2->render_surface()); 3907 ASSERT_TRUE(render_surface2->render_surface());
4381 3908
4382 // drawable_content_rects for all layers and surfaces are scaled by 3909 // drawable_content_rects for all layers and surfaces are scaled by
4383 // device_scale_factor. 3910 // device_scale_factor.
4384 EXPECT_EQ(gfx::RectF(200.f, 200.f), 3911 EXPECT_EQ(gfx::RectF(200.f, 200.f),
4385 root->render_surface()->DrawableContentRect()); 3912 root->render_surface()->DrawableContentRect());
4386 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), 3913 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
(...skipping 19 matching lines...) Expand all
4406 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); 3933 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
4407 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); 3934 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
4408 } 3935 }
4409 3936
4410 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { 3937 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
4411 // Verify the behavior of back-face culling when there are no preserve-3d 3938 // Verify the behavior of back-face culling when there are no preserve-3d
4412 // layers. Note that 3d transforms still apply in this case, but they are 3939 // layers. Note that 3d transforms still apply in this case, but they are
4413 // "flattened" to each parent layer according to current W3C spec. 3940 // "flattened" to each parent layer according to current W3C spec.
4414 3941
4415 const gfx::Transform identity_matrix; 3942 const gfx::Transform identity_matrix;
4416 LayerImpl* parent = root_layer_for_testing(); 3943 LayerImpl* root = root_layer_for_testing();
4417 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); 3944 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4418 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); 3945 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4419 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); 3946 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4420 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); 3947 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4421 LayerImpl* front_facing_child_of_front_facing_surface = 3948 LayerImpl* front_facing_child_of_front_facing_surface =
4422 AddChild<LayerImpl>(front_facing_surface); 3949 AddChild<LayerImpl>(front_facing_surface);
4423 LayerImpl* back_facing_child_of_front_facing_surface = 3950 LayerImpl* back_facing_child_of_front_facing_surface =
4424 AddChild<LayerImpl>(front_facing_surface); 3951 AddChild<LayerImpl>(front_facing_surface);
4425 LayerImpl* front_facing_child_of_back_facing_surface = 3952 LayerImpl* front_facing_child_of_back_facing_surface =
4426 AddChild<LayerImpl>(back_facing_surface); 3953 AddChild<LayerImpl>(back_facing_surface);
(...skipping 22 matching lines...) Expand all
4449 front_facing_child_of_front_facing_surface->SetDrawsContent(true); 3976 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4450 back_facing_child_of_front_facing_surface->SetDrawsContent(true); 3977 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4451 front_facing_child_of_back_facing_surface->SetDrawsContent(true); 3978 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4452 back_facing_child_of_back_facing_surface->SetDrawsContent(true); 3979 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
4453 3980
4454 gfx::Transform backface_matrix; 3981 gfx::Transform backface_matrix;
4455 backface_matrix.Translate(50.0, 50.0); 3982 backface_matrix.Translate(50.0, 50.0);
4456 backface_matrix.RotateAboutYAxis(180.0); 3983 backface_matrix.RotateAboutYAxis(180.0);
4457 backface_matrix.Translate(-50.0, -50.0); 3984 backface_matrix.Translate(-50.0, -50.0);
4458 3985
4459 // Having a descendant and opacity will force these to have render surfaces. 3986 root->SetBounds(gfx::Size(100, 100));
4460 front_facing_surface->test_properties()->opacity = 0.5f; 3987 front_facing_child->SetBounds(gfx::Size(100, 100));
4461 back_facing_surface->test_properties()->opacity = 0.5f; 3988 back_facing_child->SetBounds(gfx::Size(100, 100));
3989 front_facing_surface->SetBounds(gfx::Size(100, 100));
3990 back_facing_surface->SetBounds(gfx::Size(100, 100));
3991 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
3992 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
3993 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
3994 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4462 3995
4463 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, 3996 front_facing_surface->test_properties()->force_render_surface = true;
4464 // these layers should blindly use their own local transforms to determine 3997 back_facing_surface->test_properties()->force_render_surface = true;
4465 // back-face culling.
4466 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4467 gfx::PointF(), gfx::Size(100, 100), true, false);
4468 SetLayerPropertiesForTesting(front_facing_child, identity_matrix,
4469 gfx::Point3F(), gfx::PointF(),
4470 gfx::Size(100, 100), true, false);
4471 SetLayerPropertiesForTesting(back_facing_child, backface_matrix,
4472 gfx::Point3F(), gfx::PointF(),
4473 gfx::Size(100, 100), true, false);
4474 SetLayerPropertiesForTesting(front_facing_surface, identity_matrix,
4475 gfx::Point3F(), gfx::PointF(),
4476 gfx::Size(100, 100), true, false);
4477 SetLayerPropertiesForTesting(back_facing_surface, backface_matrix,
4478 gfx::Point3F(), gfx::PointF(),
4479 gfx::Size(100, 100), true, false);
4480 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface,
4481 identity_matrix, gfx::Point3F(), gfx::PointF(),
4482 gfx::Size(100, 100), true, false);
4483 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface,
4484 backface_matrix, gfx::Point3F(), gfx::PointF(),
4485 gfx::Size(100, 100), true, false);
4486 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface,
4487 identity_matrix, gfx::Point3F(), gfx::PointF(),
4488 gfx::Size(100, 100), true, false);
4489 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface,
4490 backface_matrix, gfx::Point3F(), gfx::PointF(),
4491 gfx::Size(100, 100), true, false);
4492 3998
4493 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); 3999 back_facing_child->SetTransform(backface_matrix);
4000 back_facing_surface->SetTransform(backface_matrix);
4001 back_facing_child_of_front_facing_surface->SetTransform(backface_matrix);
4002 back_facing_child_of_back_facing_surface->SetTransform(backface_matrix);
4003
4004 // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms
4005 // spec, these layers should blindly use their own local transforms to
4006 // determine back-face culling.
4007 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
4494 4008
4495 // Verify which render surfaces were created. 4009 // Verify which render surfaces were created.
4496 EXPECT_FALSE(front_facing_child->has_render_surface()); 4010 EXPECT_FALSE(front_facing_child->has_render_surface());
4497 EXPECT_FALSE(back_facing_child->has_render_surface()); 4011 EXPECT_FALSE(back_facing_child->has_render_surface());
4498 EXPECT_TRUE(front_facing_surface->has_render_surface()); 4012 EXPECT_TRUE(front_facing_surface->has_render_surface());
4499 EXPECT_TRUE(back_facing_surface->has_render_surface()); 4013 EXPECT_TRUE(back_facing_surface->has_render_surface());
4500 EXPECT_FALSE( 4014 EXPECT_FALSE(
4501 front_facing_child_of_front_facing_surface->has_render_surface()); 4015 front_facing_child_of_front_facing_surface->has_render_surface());
4502 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); 4016 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4503 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); 4017 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4504 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); 4018 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
4505 4019
4506 EXPECT_EQ(4u, update_layer_list_impl()->size()); 4020 EXPECT_EQ(4u, update_layer_list_impl()->size());
4507 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); 4021 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4508 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); 4022 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4509 EXPECT_TRUE(UpdateLayerListImplContains( 4023 EXPECT_TRUE(UpdateLayerListImplContains(
4510 front_facing_child_of_front_facing_surface->id())); 4024 front_facing_child_of_front_facing_surface->id()));
4511 EXPECT_TRUE(UpdateLayerListImplContains( 4025 EXPECT_TRUE(UpdateLayerListImplContains(
4512 front_facing_child_of_back_facing_surface->id())); 4026 front_facing_child_of_back_facing_surface->id()));
4513 } 4027 }
4514 4028
4515 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { 4029 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
4516 // Verify the behavior of back-face culling when preserves-3d transform style 4030 // Verify the behavior of back-face culling when preserves-3d transform style
4517 // is used. 4031 // is used.
4518 4032
4519 const gfx::Transform identity_matrix; 4033 const gfx::Transform identity_matrix;
4520 LayerImpl* parent = root_layer_for_testing(); 4034 LayerImpl* root = root_layer_for_testing();
4521 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); 4035 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4522 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); 4036 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4523 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); 4037 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4524 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); 4038 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4525 LayerImpl* front_facing_child_of_front_facing_surface = 4039 LayerImpl* front_facing_child_of_front_facing_surface =
4526 AddChild<LayerImpl>(front_facing_surface); 4040 AddChild<LayerImpl>(front_facing_surface);
4527 LayerImpl* back_facing_child_of_front_facing_surface = 4041 LayerImpl* back_facing_child_of_front_facing_surface =
4528 AddChild<LayerImpl>(front_facing_surface); 4042 AddChild<LayerImpl>(front_facing_surface);
4529 LayerImpl* front_facing_child_of_back_facing_surface = 4043 LayerImpl* front_facing_child_of_back_facing_surface =
4530 AddChild<LayerImpl>(back_facing_surface); 4044 AddChild<LayerImpl>(back_facing_surface);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4562 front_facing_child_of_back_facing_surface->SetDrawsContent(true); 4076 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4563 back_facing_child_of_back_facing_surface->SetDrawsContent(true); 4077 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
4564 dummy_replica_layer1->SetDrawsContent(true); 4078 dummy_replica_layer1->SetDrawsContent(true);
4565 dummy_replica_layer2->SetDrawsContent(true); 4079 dummy_replica_layer2->SetDrawsContent(true);
4566 4080
4567 gfx::Transform backface_matrix; 4081 gfx::Transform backface_matrix;
4568 backface_matrix.Translate(50.0, 50.0); 4082 backface_matrix.Translate(50.0, 50.0);
4569 backface_matrix.RotateAboutYAxis(180.0); 4083 backface_matrix.RotateAboutYAxis(180.0);
4570 backface_matrix.Translate(-50.0, -50.0); 4084 backface_matrix.Translate(-50.0, -50.0);
4571 4085
4086 root->SetBounds(gfx::Size(100, 100));
4087 front_facing_child->SetBounds(gfx::Size(100, 100));
4088 back_facing_child->SetBounds(gfx::Size(100, 100));
4089 front_facing_surface->SetBounds(gfx::Size(100, 100));
4090 back_facing_surface->SetBounds(gfx::Size(100, 100));
4091 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4092 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4093 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4094 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4095
4096 back_facing_child->SetTransform(backface_matrix);
4097 back_facing_surface->SetTransform(backface_matrix);
4098 back_facing_child_of_front_facing_surface->SetTransform(backface_matrix);
4099 back_facing_child_of_back_facing_surface->SetTransform(backface_matrix);
4100
4572 // Each surface creates its own new 3d rendering context (as defined by W3C 4101 // Each surface creates its own new 3d rendering context (as defined by W3C
4573 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d 4102 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
4574 // rendering context should use the transform with respect to that context. 4103 // rendering context should use the transform with respect to that context.
4575 // This 3d rendering context occurs when (a) parent's transform style is flat 4104 // This 3d rendering context occurs when (a) parent's transform style is flat
4576 // and (b) the layer's transform style is preserve-3d. 4105 // and (b) the layer's transform style is preserve-3d.
4577 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), 4106 front_facing_surface->test_properties()->should_flatten_transform = false;
4578 gfx::PointF(), gfx::Size(100, 100), true, 4107 front_facing_surface->Set3dSortingContextId(1);
4579 false); // parent transform style is flat. 4108 back_facing_surface->test_properties()->should_flatten_transform = false;
4580 SetLayerPropertiesForTesting(front_facing_child, identity_matrix, 4109 back_facing_surface->Set3dSortingContextId(1);
4581 gfx::Point3F(), gfx::PointF(), 4110 front_facing_child_of_front_facing_surface->Set3dSortingContextId(1);
4582 gfx::Size(100, 100), true, false); 4111 back_facing_child_of_front_facing_surface->Set3dSortingContextId(1);
4583 SetLayerPropertiesForTesting(back_facing_child, backface_matrix, 4112 front_facing_child_of_back_facing_surface->Set3dSortingContextId(1);
4584 gfx::Point3F(), gfx::PointF(), 4113 back_facing_child_of_back_facing_surface->Set3dSortingContextId(1);
4585 gfx::Size(100, 100), true, false);
4586 // surface transform style is preserve-3d.
4587 SetLayerPropertiesForTesting(front_facing_surface, identity_matrix,
4588 gfx::Point3F(), gfx::PointF(),
4589 gfx::Size(100, 100), false, true);
4590 // surface transform style is preserve-3d.
4591 SetLayerPropertiesForTesting(back_facing_surface, backface_matrix,
4592 gfx::Point3F(), gfx::PointF(),
4593 gfx::Size(100, 100), false, true);
4594 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface,
4595 identity_matrix, gfx::Point3F(), gfx::PointF(),
4596 gfx::Size(100, 100), true, true);
4597 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface,
4598 backface_matrix, gfx::Point3F(), gfx::PointF(),
4599 gfx::Size(100, 100), true, true);
4600 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface,
4601 identity_matrix, gfx::Point3F(), gfx::PointF(),
4602 gfx::Size(100, 100), true, true);
4603 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface,
4604 backface_matrix, gfx::Point3F(), gfx::PointF(),
4605 gfx::Size(100, 100), true, true);
4606 4114
4607 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); 4115 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
4608 4116
4609 // Verify which render surfaces were created and used. 4117 // Verify which render surfaces were created and used.
4610 EXPECT_FALSE(front_facing_child->has_render_surface()); 4118 EXPECT_FALSE(front_facing_child->has_render_surface());
4611 EXPECT_FALSE(back_facing_child->has_render_surface()); 4119 EXPECT_FALSE(back_facing_child->has_render_surface());
4612 EXPECT_TRUE(front_facing_surface->has_render_surface()); 4120 EXPECT_TRUE(front_facing_surface->has_render_surface());
4613 // We expect that a has_render_surface was created but not used. 4121 // We expect that a has_render_surface was created but not used.
4614 EXPECT_TRUE(back_facing_surface->has_render_surface()); 4122 EXPECT_TRUE(back_facing_surface->has_render_surface());
4615 EXPECT_FALSE( 4123 EXPECT_FALSE(
4616 front_facing_child_of_front_facing_surface->has_render_surface()); 4124 front_facing_child_of_front_facing_surface->has_render_surface());
4617 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); 4125 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4618 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); 4126 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4619 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); 4127 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
4620 4128
4621 EXPECT_EQ(3u, update_layer_list_impl()->size()); 4129 EXPECT_EQ(3u, update_layer_list_impl()->size());
4622 4130
4623 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); 4131 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4624 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); 4132 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4625 EXPECT_TRUE(UpdateLayerListImplContains( 4133 EXPECT_TRUE(UpdateLayerListImplContains(
4626 front_facing_child_of_front_facing_surface->id())); 4134 front_facing_child_of_front_facing_surface->id()));
4627 } 4135 }
4628 4136
4629 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { 4137 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
4630 // Verify that layers are appropriately culled when their back face is showing 4138 // Verify that layers are appropriately culled when their back face is showing
4631 // and they are not double sided, while animations are going on. 4139 // and they are not double sided, while animations are going on.
4632 // 4140 //
4633 // Even layers that are animating get culled if their back face is showing and 4141 // Even layers that are animating get culled if their back face is showing and
4634 // they are not double sided. 4142 // they are not double sided.
4635 const gfx::Transform identity_matrix; 4143 const gfx::Transform identity_matrix;
4636 LayerImpl* parent = root_layer_for_testing(); 4144 LayerImpl* root = root_layer_for_testing();
4637 LayerImpl* child = AddChildToRoot<LayerImpl>(); 4145 LayerImpl* child = AddChildToRoot<LayerImpl>();
4638 LayerImpl* animating_surface = AddChildToRoot<LayerImpl>(); 4146 LayerImpl* animating_surface = AddChildToRoot<LayerImpl>();
4639 LayerImpl* child_of_animating_surface = 4147 LayerImpl* child_of_animating_surface =
4640 AddChild<LayerImpl>(animating_surface); 4148 AddChild<LayerImpl>(animating_surface);
4641 LayerImpl* animating_child = AddChildToRoot<LayerImpl>(); 4149 LayerImpl* animating_child = AddChildToRoot<LayerImpl>();
4642 LayerImpl* child2 = AddChildToRoot<LayerImpl>(); 4150 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
4643 4151
4644 // Nothing is double-sided 4152 // Nothing is double-sided
4645 child->test_properties()->double_sided = false; 4153 child->test_properties()->double_sided = false;
4646 child2->test_properties()->double_sided = false; 4154 child2->test_properties()->double_sided = false;
(...skipping 15 matching lines...) Expand all
4662 4170
4663 SetElementIdsForTesting(); 4171 SetElementIdsForTesting();
4664 4172
4665 // Animate the transform on the render surface. 4173 // Animate the transform on the render surface.
4666 AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(), 4174 AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(),
4667 timeline_impl(), 10.0, 30, 0); 4175 timeline_impl(), 10.0, 30, 0);
4668 // This is just an animating layer, not a surface. 4176 // This is just an animating layer, not a surface.
4669 AddAnimatedTransformToElementWithPlayer(animating_child->element_id(), 4177 AddAnimatedTransformToElementWithPlayer(animating_child->element_id(),
4670 timeline_impl(), 10.0, 30, 0); 4178 timeline_impl(), 10.0, 30, 0);
4671 4179
4672 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), 4180 root->SetBounds(gfx::Size(100, 100));
4673 gfx::PointF(), gfx::Size(100, 100), true, false); 4181 child->SetBounds(gfx::Size(100, 100));
4674 SetLayerPropertiesForTesting(child, backface_matrix, gfx::Point3F(), 4182 child->SetTransform(backface_matrix);
4675 gfx::PointF(), gfx::Size(100, 100), true, false); 4183 animating_surface->SetBounds(gfx::Size(100, 100));
4676 SetLayerPropertiesForTesting(animating_surface, backface_matrix, 4184 animating_surface->SetTransform(backface_matrix);
4677 gfx::Point3F(), gfx::PointF(), 4185 animating_surface->test_properties()->force_render_surface = true;
4678 gfx::Size(100, 100), true, false, true); 4186 child_of_animating_surface->SetBounds(gfx::Size(100, 100));
4679 SetLayerPropertiesForTesting(child_of_animating_surface, backface_matrix, 4187 child_of_animating_surface->SetTransform(backface_matrix);
4680 gfx::Point3F(), gfx::PointF(), 4188 animating_child->SetBounds(gfx::Size(100, 100));
4681 gfx::Size(100, 100), true, false); 4189 animating_child->SetTransform(backface_matrix);
4682 SetLayerPropertiesForTesting(animating_child, backface_matrix, gfx::Point3F(), 4190 child2->SetBounds(gfx::Size(100, 100));
4683 gfx::PointF(), gfx::Size(100, 100), true, false);
4684 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4685 gfx::PointF(), gfx::Size(100, 100), true, false);
4686 4191
4687 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); 4192 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
4688 4193
4689 EXPECT_FALSE(child->has_render_surface()); 4194 EXPECT_FALSE(child->has_render_surface());
4690 EXPECT_TRUE(animating_surface->has_render_surface()); 4195 EXPECT_TRUE(animating_surface->has_render_surface());
4691 EXPECT_FALSE(child_of_animating_surface->has_render_surface()); 4196 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
4692 EXPECT_FALSE(animating_child->has_render_surface()); 4197 EXPECT_FALSE(animating_child->has_render_surface());
4693 EXPECT_FALSE(child2->has_render_surface()); 4198 EXPECT_FALSE(child2->has_render_surface());
4694 4199
4695 EXPECT_EQ(1u, update_layer_list_impl()->size()); 4200 EXPECT_EQ(1u, update_layer_list_impl()->size());
4696 4201
4697 // The back facing layers are culled from the layer list, and have an empty 4202 // The back facing layers are culled from the layer list, and have an empty
4698 // visible rect. 4203 // visible rect.
4699 EXPECT_TRUE(UpdateLayerListImplContains(child2->id())); 4204 EXPECT_TRUE(UpdateLayerListImplContains(child2->id()));
4700 EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); 4205 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
4701 EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty()); 4206 EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty());
4702 EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty()); 4207 EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty());
4703 EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty()); 4208 EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty());
4704 4209
4705 EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect()); 4210 EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect());
4706 } 4211 }
4707 4212
4708 TEST_F(LayerTreeHostCommonTest, 4213 TEST_F(LayerTreeHostCommonTest,
4709 BackFaceCullingWithPreserves3dForFlatteningSurface) { 4214 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4710 // Verify the behavior of back-face culling for a render surface that is 4215 // Verify the behavior of back-face culling for a render surface that is
4711 // created when it flattens its subtree, and its parent has preserves-3d. 4216 // created when it flattens its subtree, and its parent has preserves-3d.
4712 4217
4713 const gfx::Transform identity_matrix; 4218 const gfx::Transform identity_matrix;
4714 LayerImpl* parent = root_layer_for_testing(); 4219 LayerImpl* root = root_layer_for_testing();
4715 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); 4220 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4716 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); 4221 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4717 LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface); 4222 LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface);
4718 LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface); 4223 LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface);
4719 4224
4720 // RenderSurfaces are not double-sided 4225 // RenderSurfaces are not double-sided
4721 front_facing_surface->test_properties()->double_sided = false; 4226 front_facing_surface->test_properties()->double_sided = false;
4722 back_facing_surface->test_properties()->double_sided = false; 4227 back_facing_surface->test_properties()->double_sided = false;
4723 4228
4724 // Everything draws content. 4229 // Everything draws content.
4725 front_facing_surface->SetDrawsContent(true); 4230 front_facing_surface->SetDrawsContent(true);
4726 back_facing_surface->SetDrawsContent(true); 4231 back_facing_surface->SetDrawsContent(true);
4727 child1->SetDrawsContent(true); 4232 child1->SetDrawsContent(true);
4728 child2->SetDrawsContent(true); 4233 child2->SetDrawsContent(true);
4729 4234
4730 gfx::Transform backface_matrix; 4235 gfx::Transform backface_matrix;
4731 backface_matrix.Translate(50.0, 50.0); 4236 backface_matrix.Translate(50.0, 50.0);
4732 backface_matrix.RotateAboutYAxis(180.0); 4237 backface_matrix.RotateAboutYAxis(180.0);
4733 backface_matrix.Translate(-50.0, -50.0); 4238 backface_matrix.Translate(-50.0, -50.0);
4734 4239
4735 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), 4240 root->SetBounds(gfx::Size(100, 100));
4736 gfx::PointF(), gfx::Size(100, 100), false, 4241 front_facing_surface->SetBounds(gfx::Size(100, 100));
4737 true); // parent transform style is preserve3d. 4242 front_facing_surface->test_properties()->force_render_surface = true;
4738 SetLayerPropertiesForTesting(front_facing_surface, identity_matrix, 4243 back_facing_surface->SetBounds(gfx::Size(100, 100));
4739 gfx::Point3F(), gfx::PointF(), 4244 back_facing_surface->SetTransform(backface_matrix);
4740 gfx::Size(100, 100), true, 4245 back_facing_surface->test_properties()->force_render_surface = true;
4741 true); // surface transform style is flat. 4246 child1->SetBounds(gfx::Size(100, 100));
4742 SetLayerPropertiesForTesting(back_facing_surface, backface_matrix, 4247 child2->SetBounds(gfx::Size(100, 100));
4743 gfx::Point3F(), gfx::PointF(),
4744 gfx::Size(100, 100), true,
4745 true); // surface transform style is flat.
4746 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
4747 gfx::PointF(), gfx::Size(100, 100), true, false);
4748 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4749 gfx::PointF(), gfx::Size(100, 100), true, false);
4750 4248
4751 front_facing_surface->Set3dSortingContextId(1); 4249 front_facing_surface->Set3dSortingContextId(1);
4752 back_facing_surface->Set3dSortingContextId(1); 4250 back_facing_surface->Set3dSortingContextId(1);
4753 4251
4754 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); 4252 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
4755 4253
4756 // Verify which render surfaces were created and used. 4254 // Verify which render surfaces were created and used.
4757 EXPECT_TRUE(front_facing_surface->has_render_surface()); 4255 EXPECT_TRUE(front_facing_surface->has_render_surface());
4758 4256
4759 // We expect the render surface to have been created, but remain unused. 4257 // We expect the render surface to have been created, but remain unused.
4760 EXPECT_TRUE(back_facing_surface->has_render_surface()); 4258 EXPECT_TRUE(back_facing_surface->has_render_surface());
4761 EXPECT_FALSE(child1->has_render_surface()); 4259 EXPECT_FALSE(child1->has_render_surface());
4762 EXPECT_FALSE(child2->has_render_surface()); 4260 EXPECT_FALSE(child2->has_render_surface());
4763 4261
4764 EXPECT_EQ(2u, update_layer_list_impl()->size()); 4262 EXPECT_EQ(2u, update_layer_list_impl()->size());
4765 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); 4263 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4766 EXPECT_TRUE(UpdateLayerListImplContains(child1->id())); 4264 EXPECT_TRUE(UpdateLayerListImplContains(child1->id()));
4767 } 4265 }
4768 4266
4769 TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { 4267 TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
4770 // Verify draw and screen space transforms of layers not in a surface. 4268 // Verify draw and screen space transforms of layers not in a surface.
4771 gfx::Transform identity_matrix; 4269 gfx::Transform identity_matrix;
4772 4270
4773 LayerImpl* parent = root_layer_for_testing(); 4271 LayerImpl* root = root_layer_for_testing();
4774 parent->SetDrawsContent(true); 4272 root->SetBounds(gfx::Size(100, 100));
4775 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), 4273 root->SetDrawsContent(true);
4776 gfx::PointF(), gfx::Size(100, 100), false, true,
4777 true);
4778 4274
4779 LayerImpl* child = AddChildToRoot<LayerImpl>(); 4275 LayerImpl* child = AddChildToRoot<LayerImpl>();
4276 child->SetPosition(gfx::PointF(2.f, 2.f));
4277 child->SetBounds(gfx::Size(10, 10));
4780 child->SetDrawsContent(true); 4278 child->SetDrawsContent(true);
4781 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4782 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4783 true, false);
4784 4279
4785 LayerImpl* child2 = AddChildToRoot<LayerImpl>(); 4280 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
4281 child2->SetPosition(gfx::PointF(2.f, 2.f));
4282 child2->SetBounds(gfx::Size(5, 5));
4786 child2->SetDrawsContent(true); 4283 child2->SetDrawsContent(true);
4787 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4788 gfx::PointF(2.f, 2.f), gfx::Size(5, 5), false,
4789 true, false);
4790 4284
4791 float device_scale_factor = 2.5f; 4285 float device_scale_factor = 2.5f;
4792 gfx::Size viewport_size(100, 100); 4286 gfx::Size viewport_size(100, 100);
4793 ExecuteCalculateDrawProperties(parent, device_scale_factor); 4287 ExecuteCalculateDrawProperties(root, device_scale_factor);
4794 4288
4795 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent); 4289 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, root);
4796 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child); 4290 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child);
4797 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child2); 4291 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child2);
4798 4292
4799 EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); 4293 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
4800 4294
4801 // Verify parent transforms 4295 // Verify root transforms
4802 gfx::Transform expected_parent_transform; 4296 gfx::Transform expected_root_transform;
4803 expected_parent_transform.Scale(device_scale_factor, device_scale_factor); 4297 expected_root_transform.Scale(device_scale_factor, device_scale_factor);
4804 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, 4298 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4805 parent->ScreenSpaceTransform()); 4299 root->ScreenSpaceTransform());
4806 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, 4300 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4807 parent->DrawTransform()); 4301 root->DrawTransform());
4808 4302
4809 // Verify results of transformed parent rects 4303 // Verify results of transformed root rects
4810 gfx::RectF parent_bounds(gfx::SizeF(parent->bounds())); 4304 gfx::RectF root_bounds(gfx::SizeF(root->bounds()));
4811 4305
4812 gfx::RectF parent_draw_rect = 4306 gfx::RectF root_draw_rect =
4813 MathUtil::MapClippedRect(parent->DrawTransform(), parent_bounds); 4307 MathUtil::MapClippedRect(root->DrawTransform(), root_bounds);
4814 gfx::RectF parent_screen_space_rect = 4308 gfx::RectF root_screen_space_rect =
4815 MathUtil::MapClippedRect(parent->ScreenSpaceTransform(), parent_bounds); 4309 MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds);
4816 4310
4817 gfx::RectF expected_parent_draw_rect(gfx::SizeF(parent->bounds())); 4311 gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds()));
4818 expected_parent_draw_rect.Scale(device_scale_factor); 4312 expected_root_draw_rect.Scale(device_scale_factor);
4819 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); 4313 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect);
4820 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); 4314 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect);
4821 4315
4822 // Verify child and child2 transforms. They should match. 4316 // Verify child and child2 transforms. They should match.
4823 gfx::Transform expected_child_transform; 4317 gfx::Transform expected_child_transform;
4824 expected_child_transform.Scale(device_scale_factor, device_scale_factor); 4318 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4825 expected_child_transform.Translate(child->position().x(), 4319 expected_child_transform.Translate(child->position().x(),
4826 child->position().y()); 4320 child->position().y());
4827 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 4321 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4828 child->DrawTransform()); 4322 child->DrawTransform());
4829 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 4323 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4830 child->ScreenSpaceTransform()); 4324 child->ScreenSpaceTransform());
(...skipping 28 matching lines...) Expand all
4859 TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { 4353 TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
4860 // Verify draw and screen space transforms of layers in a surface. 4354 // Verify draw and screen space transforms of layers in a surface.
4861 gfx::Transform identity_matrix; 4355 gfx::Transform identity_matrix;
4862 gfx::Transform perspective_matrix; 4356 gfx::Transform perspective_matrix;
4863 perspective_matrix.ApplyPerspectiveDepth(2.0); 4357 perspective_matrix.ApplyPerspectiveDepth(2.0);
4864 4358
4865 gfx::Transform scale_small_matrix; 4359 gfx::Transform scale_small_matrix;
4866 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); 4360 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
4867 4361
4868 LayerImpl* root = root_layer_for_testing(); 4362 LayerImpl* root = root_layer_for_testing();
4869 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 4363 root->SetBounds(gfx::Size(100, 100));
4870 gfx::PointF(), gfx::Size(100, 100), false, true,
4871 false);
4872 4364
4873 LayerImpl* page_scale = AddChildToRoot<LayerImpl>(); 4365 LayerImpl* page_scale = AddChildToRoot<LayerImpl>();
4874 SetLayerPropertiesForTesting(page_scale, identity_matrix, gfx::Point3F(), 4366 page_scale->SetBounds(gfx::Size(100, 100));
4875 gfx::PointF(), gfx::Size(100, 100), false, true,
4876 false);
4877 4367
4878 LayerImpl* parent = AddChild<LayerImpl>(page_scale); 4368 LayerImpl* parent = AddChild<LayerImpl>(page_scale);
4369 parent->SetBounds(gfx::Size(100, 100));
4879 parent->SetDrawsContent(true); 4370 parent->SetDrawsContent(true);
4880 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4881 gfx::PointF(), gfx::Size(100, 100), false, true,
4882 false);
4883 4371
4884 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent); 4372 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
4885 SetLayerPropertiesForTesting(perspective_surface, 4373 perspective_surface->SetPosition(gfx::PointF(2.f, 2.f));
4886 perspective_matrix * scale_small_matrix, 4374 perspective_surface->SetBounds(gfx::Size(10, 10));
4887 gfx::Point3F(), gfx::PointF(2.f, 2.f), 4375 perspective_surface->SetTransform(perspective_matrix * scale_small_matrix);
4888 gfx::Size(10, 10), false, true, true);
4889 perspective_surface->SetDrawsContent(true); 4376 perspective_surface->SetDrawsContent(true);
4377 perspective_surface->test_properties()->force_render_surface = true;
4890 4378
4891 LayerImpl* scale_surface = AddChild<LayerImpl>(parent); 4379 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
4892 SetLayerPropertiesForTesting(scale_surface, scale_small_matrix, 4380 scale_surface->SetPosition(gfx::PointF(2.f, 2.f));
4893 gfx::Point3F(), gfx::PointF(2.f, 2.f), 4381 scale_surface->SetBounds(gfx::Size(10, 10));
4894 gfx::Size(10, 10), false, true, true); 4382 scale_surface->SetTransform(scale_small_matrix);
4895 scale_surface->SetDrawsContent(true); 4383 scale_surface->SetDrawsContent(true);
4384 scale_surface->test_properties()->force_render_surface = true;
4896 4385
4897 float device_scale_factor = 2.5f; 4386 float device_scale_factor = 2.5f;
4898 float page_scale_factor = 3.f; 4387 float page_scale_factor = 3.f;
4899 root->layer_tree_impl()->SetViewportLayersFromIds( 4388 root->layer_tree_impl()->SetViewportLayersFromIds(
4900 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, 4389 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID,
4901 Layer::INVALID_ID); 4390 Layer::INVALID_ID);
4902 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); 4391 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
4903 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); 4392 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor);
4904 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, 4393 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4905 root); 4394 root);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
4965 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); 4454 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4966 4455
4967 gfx::Transform child_scale_matrix; 4456 gfx::Transform child_scale_matrix;
4968 SkMScalar initial_child_scale = 0.25; 4457 SkMScalar initial_child_scale = 0.25;
4969 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); 4458 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4970 4459
4971 LayerImpl* root = root_layer_for_testing(); 4460 LayerImpl* root = root_layer_for_testing();
4972 root->SetBounds(gfx::Size(100, 100)); 4461 root->SetBounds(gfx::Size(100, 100));
4973 4462
4974 LayerImpl* parent = AddChildToRoot<LayerImpl>(); 4463 LayerImpl* parent = AddChildToRoot<LayerImpl>();
4464 parent->SetBounds(gfx::Size(100, 100));
4465 parent->SetTransform(parent_scale_matrix);
4975 parent->SetDrawsContent(true); 4466 parent->SetDrawsContent(true);
4976 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4977 gfx::PointF(), gfx::Size(100, 100), false, true,
4978 false);
4979 4467
4980 LayerImpl* child_scale = AddChild<LayerImpl>(parent); 4468 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
4469 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
4470 child_scale->SetBounds(gfx::Size(10, 10));
4471 child_scale->SetTransform(child_scale_matrix);
4981 child_scale->SetDrawsContent(true); 4472 child_scale->SetDrawsContent(true);
4982 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4983 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4984 true, false);
4985 4473
4986 float device_scale_factor = 2.5f; 4474 float device_scale_factor = 2.5f;
4987 float page_scale_factor = 0.01f; 4475 float page_scale_factor = 0.01f;
4988 4476
4989 { 4477 {
4990 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, 4478 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4991 root); 4479 root);
4992 4480
4993 // The ideal scale is able to go below 1. 4481 // The ideal scale is able to go below 1.
4994 float expected_ideal_scale = 4482 float expected_ideal_scale =
(...skipping 14 matching lines...) Expand all
5009 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); 4497 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
5010 4498
5011 gfx::Transform child_scale_matrix; 4499 gfx::Transform child_scale_matrix;
5012 SkMScalar initial_child_scale = 1.25; 4500 SkMScalar initial_child_scale = 1.25;
5013 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); 4501 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
5014 4502
5015 LayerImpl* root = root_layer_for_testing(); 4503 LayerImpl* root = root_layer_for_testing();
5016 root->SetBounds(gfx::Size(100, 100)); 4504 root->SetBounds(gfx::Size(100, 100));
5017 4505
5018 LayerImpl* parent = AddChildToRoot<LayerImpl>(); 4506 LayerImpl* parent = AddChildToRoot<LayerImpl>();
4507 parent->SetBounds(gfx::Size(100, 100));
4508 parent->SetTransform(parent_scale_matrix);
5019 parent->SetDrawsContent(true); 4509 parent->SetDrawsContent(true);
5020 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
5021 gfx::PointF(), gfx::Size(100, 100), false, true,
5022 false);
5023 4510
5024 LayerImpl* child_scale = AddChild<LayerImpl>(parent); 4511 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
4512 child_scale->SetBounds(gfx::Size(10, 10));
4513 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
4514 child_scale->SetTransform(child_scale_matrix);
5025 child_scale->SetDrawsContent(true); 4515 child_scale->SetDrawsContent(true);
5026 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
5027 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
5028 true, false);
5029 4516
5030 { 4517 ExecuteCalculateDrawProperties(root);
5031 ExecuteCalculateDrawProperties(root);
5032 4518
5033 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); 4519 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
5034 // Animating layers compute ideal scale in the same way as when 4520 // Animating layers compute ideal scale in the same way as when
5035 // they are static. 4521 // they are static.
5036 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, 4522 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
5037 child_scale); 4523 child_scale);
5038 }
5039 } 4524 }
5040 4525
5041 TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { 4526 TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
5042 gfx::Transform identity_matrix; 4527 gfx::Transform identity_matrix;
5043 4528
5044 LayerImpl* parent = root_layer_for_testing(); 4529 LayerImpl* parent = root_layer_for_testing();
4530 parent->SetBounds(gfx::Size(30, 30));
5045 parent->SetDrawsContent(true); 4531 parent->SetDrawsContent(true);
5046 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), 4532 parent->Set3dSortingContextId(1);
5047 gfx::PointF(), gfx::Size(30, 30), false, true, 4533 parent->test_properties()->should_flatten_transform = false;
5048 true);
5049 4534
5050 LayerImpl* child = AddChildToRoot<LayerImpl>(); 4535 LayerImpl* child = AddChildToRoot<LayerImpl>();
4536 child->SetBounds(gfx::Size(10, 10));
4537 child->SetPosition(gfx::PointF(2.f, 2.f));
5051 child->SetDrawsContent(true); 4538 child->SetDrawsContent(true);
5052 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), 4539 child->test_properties()->force_render_surface = true;
5053 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
5054 true, true);
5055 4540
5056 gfx::Transform replica_transform; 4541 gfx::Transform replica_transform;
5057 replica_transform.Scale(1.0, -1.0); 4542 replica_transform.Scale(1.0, -1.0);
5058 4543
5059 std::unique_ptr<LayerImpl> replica = 4544 std::unique_ptr<LayerImpl> replica =
5060 LayerImpl::Create(host_impl()->active_tree(), 7); 4545 LayerImpl::Create(host_impl()->active_tree(), 7);
5061 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(), 4546 replica->SetPosition(gfx::PointF(2.f, 2.f));
5062 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, 4547 replica->SetTransform(replica_transform);
5063 true, false); 4548
5064 // We need to set parent on replica layer for property tree building. 4549 // We need to set parent on replica layer for property tree building.
5065 replica->test_properties()->parent = child; 4550 replica->test_properties()->parent = child;
5066 child->test_properties()->SetReplicaLayer(std::move(replica)); 4551 child->test_properties()->SetReplicaLayer(std::move(replica));
5067 4552
5068 // This layer should end up in the same surface as child, with the same draw 4553 // This layer should end up in the same surface as child, with the same draw
5069 // and screen space transforms. 4554 // and screen space transforms.
5070 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child); 4555 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
4556 duplicate_child_non_owner->SetBounds(gfx::Size(10, 10));
5071 duplicate_child_non_owner->SetDrawsContent(true); 4557 duplicate_child_non_owner->SetDrawsContent(true);
5072 SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix,
5073 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5074 false, true, false);
5075 4558
5076 float device_scale_factor = 1.5f; 4559 float device_scale_factor = 1.5f;
5077 ExecuteCalculateDrawProperties(parent, device_scale_factor); 4560 ExecuteCalculateDrawProperties(parent, device_scale_factor);
5078 4561
5079 // We should have two render surfaces. The root's render surface and child's 4562 // We should have two render surfaces. The root's render surface and child's
5080 // render surface (it needs one because it has a replica layer). 4563 // render surface (it needs one because it has a replica layer).
5081 EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); 4564 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5082 4565
5083 gfx::Transform expected_parent_transform; 4566 gfx::Transform expected_parent_transform;
5084 expected_parent_transform.Scale(device_scale_factor, device_scale_factor); 4567 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
5149 EXPECT_TRANSFORMATION_MATRIX_EQ( 4632 EXPECT_TRANSFORMATION_MATRIX_EQ(
5150 expected_replica_screen_space_transform, 4633 expected_replica_screen_space_transform,
5151 child->render_surface()->replica_screen_space_transform()); 4634 child->render_surface()->replica_screen_space_transform());
5152 } 4635 }
5153 4636
5154 TEST_F(LayerTreeHostCommonTest, 4637 TEST_F(LayerTreeHostCommonTest,
5155 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { 4638 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
5156 gfx::Transform identity_matrix; 4639 gfx::Transform identity_matrix;
5157 4640
5158 LayerImpl* parent = root_layer_for_testing(); 4641 LayerImpl* parent = root_layer_for_testing();
4642 parent->SetBounds(gfx::Size(33, 31));
5159 parent->SetDrawsContent(true); 4643 parent->SetDrawsContent(true);
5160 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
5161 gfx::PointF(), gfx::Size(33, 31), false, true,
5162 true);
5163 4644
5164 LayerImpl* child = AddChildToRoot<LayerImpl>(); 4645 LayerImpl* child = AddChildToRoot<LayerImpl>();
4646 child->SetBounds(gfx::Size(13, 11));
5165 child->SetDrawsContent(true); 4647 child->SetDrawsContent(true);
5166 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), 4648 child->test_properties()->force_render_surface = true;
5167 gfx::PointF(), gfx::Size(13, 11), false, true,
5168 true);
5169 4649
5170 gfx::Transform replica_transform; 4650 gfx::Transform replica_transform;
5171 replica_transform.Scale(1.0, -1.0); 4651 replica_transform.Scale(1.0, -1.0);
5172 std::unique_ptr<LayerImpl> replica = 4652 std::unique_ptr<LayerImpl> replica =
5173 LayerImpl::Create(host_impl()->active_tree(), 7); 4653 LayerImpl::Create(host_impl()->active_tree(), 7);
5174 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(), 4654 replica->SetTransform(replica_transform);
5175 gfx::PointF(), gfx::Size(13, 11), false, true,
5176 false);
5177 child->test_properties()->SetReplicaLayer(std::move(replica)); 4655 child->test_properties()->SetReplicaLayer(std::move(replica));
5178 4656
5179 float device_scale_factor = 1.7f; 4657 float device_scale_factor = 1.7f;
5180 ExecuteCalculateDrawProperties(parent, device_scale_factor); 4658 ExecuteCalculateDrawProperties(parent, device_scale_factor);
5181 4659
5182 // We should have two render surfaces. The root's render surface and child's 4660 // We should have two render surfaces. The root's render surface and child's
5183 // render surface (it needs one because it has a replica layer). 4661 // render surface (it needs one because it has a replica layer).
5184 EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); 4662 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5185 4663
5186 gfx::Transform identity_transform; 4664 gfx::Transform identity_transform;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
5224 EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id())); 4702 EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id()));
5225 EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id())); 4703 EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id()));
5226 EXPECT_EQ(replica_layer.get(), host()->LayerById(replica_layer->id())); 4704 EXPECT_EQ(replica_layer.get(), host()->LayerById(replica_layer->id()));
5227 EXPECT_FALSE(host()->LayerById(nonexistent_id)); 4705 EXPECT_FALSE(host()->LayerById(nonexistent_id));
5228 } 4706 }
5229 4707
5230 TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { 4708 TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
5231 LayerImpl* root = root_layer_for_testing(); 4709 LayerImpl* root = root_layer_for_testing();
5232 LayerImpl* child = AddChild<LayerImpl>(root); 4710 LayerImpl* child = AddChild<LayerImpl>(root);
5233 LayerImpl* grand_child = AddChild<LayerImpl>(child); 4711 LayerImpl* grand_child = AddChild<LayerImpl>(child);
4712
4713 root->SetBounds(gfx::Size(100, 100));
4714 child->SetBounds(gfx::Size(10, 10));
4715 child->test_properties()->opacity = 0.5f;
4716 grand_child->SetBounds(gfx::Size(10, 10));
5234 grand_child->SetDrawsContent(true); 4717 grand_child->SetDrawsContent(true);
5235
5236 const gfx::Transform identity_matrix;
5237 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
5238 gfx::PointF(), gfx::Size(100, 100), true, false);
5239 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
5240 gfx::PointF(), gfx::Size(10, 10), true, false);
5241 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
5242 gfx::PointF(), gfx::Size(10, 10), true, false);
5243
5244 child->test_properties()->opacity = 0.5f;
5245
5246 ExecuteCalculateDrawProperties(root); 4718 ExecuteCalculateDrawProperties(root);
5247
5248 EXPECT_FALSE(child->has_render_surface()); 4719 EXPECT_FALSE(child->has_render_surface());
5249 } 4720 }
5250 4721
5251 TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { 4722 TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
5252 FakeImplTaskRunnerProvider task_runner_provider; 4723 FakeImplTaskRunnerProvider task_runner_provider;
5253 TestSharedBitmapManager shared_bitmap_manager; 4724 TestSharedBitmapManager shared_bitmap_manager;
5254 TestTaskGraphRunner task_graph_runner; 4725 TestTaskGraphRunner task_graph_runner;
5255 FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider, 4726 FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider,
5256 &shared_bitmap_manager, &task_graph_runner); 4727 &shared_bitmap_manager, &task_graph_runner);
5257 host_impl.CreatePendingTree(); 4728 host_impl.CreatePendingTree();
5258 std::unique_ptr<LayerImpl> root = 4729 std::unique_ptr<LayerImpl> root =
5259 LayerImpl::Create(host_impl.pending_tree(), 1); 4730 LayerImpl::Create(host_impl.pending_tree(), 1);
5260 4731 root->SetBounds(gfx::Size(100, 100));
5261 const gfx::Transform identity_matrix;
5262 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5263 gfx::PointF(), gfx::Size(100, 100), true, false,
5264 false);
5265 root->SetDrawsContent(true); 4732 root->SetDrawsContent(true);
5266 4733
5267 std::unique_ptr<LayerImpl> child = 4734 std::unique_ptr<LayerImpl> child =
5268 LayerImpl::Create(host_impl.pending_tree(), 2); 4735 LayerImpl::Create(host_impl.pending_tree(), 2);
5269 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), 4736 child->SetBounds(gfx::Size(50, 50));
5270 gfx::PointF(), gfx::Size(50, 50), true, false,
5271 false);
5272 child->SetDrawsContent(true); 4737 child->SetDrawsContent(true);
5273 child->test_properties()->opacity = 0.0f; 4738 child->test_properties()->opacity = 0.0f;
5274 4739
5275 const int child_id = child->id(); 4740 const int child_id = child->id();
5276 root->test_properties()->AddChild(std::move(child)); 4741 root->test_properties()->AddChild(std::move(child));
5277 root->SetHasRenderSurface(true); 4742 root->SetHasRenderSurface(true);
5278 LayerImpl* root_layer = root.get(); 4743 LayerImpl* root_layer = root.get();
5279 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); 4744 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
5280 host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting(); 4745 host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting();
5281 4746
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
5405 4870
5406 root_->SetContentsOpaque(true); 4871 root_->SetContentsOpaque(true);
5407 child_->SetContentsOpaque(true); 4872 child_->SetContentsOpaque(true);
5408 grand_child_->SetContentsOpaque(true); 4873 grand_child_->SetContentsOpaque(true);
5409 4874
5410 root_->SetDrawsContent(true); 4875 root_->SetDrawsContent(true);
5411 child_->SetDrawsContent(true); 4876 child_->SetDrawsContent(true);
5412 grand_child_->SetDrawsContent(true); 4877 grand_child_->SetDrawsContent(true);
5413 4878
5414 gfx::Transform identity_matrix; 4879 gfx::Transform identity_matrix;
5415 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(), 4880 root_->SetBounds(gfx::Size(1, 1));
5416 gfx::PointF(), gfx::Size(1, 1), true, false, 4881 child_->SetBounds(gfx::Size(1, 1));
5417 true); 4882 grand_child_->SetBounds(gfx::Size(1, 1));
5418 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(), 4883
5419 gfx::PointF(), gfx::Size(1, 1), true, false, 4884 child_->test_properties()->force_render_surface =
5420 std::tr1::get<2>(GetParam())); 4885 std::tr1::get<2>(GetParam());
5421 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
5422 gfx::PointF(), gfx::Size(1, 1), true, false,
5423 false);
5424 } 4886 }
5425 4887
5426 bool can_use_lcd_text_; 4888 bool can_use_lcd_text_;
5427 bool layers_always_allowed_lcd_text_; 4889 bool layers_always_allowed_lcd_text_;
5428 4890
5429 FakeImplTaskRunnerProvider task_runner_provider_; 4891 FakeImplTaskRunnerProvider task_runner_provider_;
5430 TestSharedBitmapManager shared_bitmap_manager_; 4892 TestSharedBitmapManager shared_bitmap_manager_;
5431 TestTaskGraphRunner task_graph_runner_; 4893 TestTaskGraphRunner task_graph_runner_;
5432 FakeLayerTreeHostImpl host_impl_; 4894 FakeLayerTreeHostImpl host_impl_;
5433 scoped_refptr<AnimationTimeline> timeline_; 4895 scoped_refptr<AnimationTimeline> timeline_;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
5588 FakeImplTaskRunnerProvider task_runner_provider; 5050 FakeImplTaskRunnerProvider task_runner_provider;
5589 TestSharedBitmapManager shared_bitmap_manager; 5051 TestSharedBitmapManager shared_bitmap_manager;
5590 TestTaskGraphRunner task_graph_runner; 5052 TestTaskGraphRunner task_graph_runner;
5591 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 5053 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
5592 &task_graph_runner); 5054 &task_graph_runner);
5593 host_impl.CreatePendingTree(); 5055 host_impl.CreatePendingTree();
5594 const gfx::Transform identity_matrix; 5056 const gfx::Transform identity_matrix;
5595 5057
5596 std::unique_ptr<LayerImpl> root = 5058 std::unique_ptr<LayerImpl> root =
5597 LayerImpl::Create(host_impl.pending_tree(), 1); 5059 LayerImpl::Create(host_impl.pending_tree(), 1);
5060 root->SetBounds(gfx::Size(50, 50));
5061 root->SetDrawsContent(true);
5598 LayerImpl* root_layer = root.get(); 5062 LayerImpl* root_layer = root.get();
5599 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5600 gfx::PointF(), gfx::Size(50, 50), true, false,
5601 false);
5602 root->SetDrawsContent(true);
5603 5063
5604 std::unique_ptr<LayerImpl> child = 5064 std::unique_ptr<LayerImpl> child =
5605 LayerImpl::Create(host_impl.pending_tree(), 2); 5065 LayerImpl::Create(host_impl.pending_tree(), 2);
5606 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), 5066 child->SetBounds(gfx::Size(40, 40));
5607 gfx::PointF(), gfx::Size(40, 40), true, false,
5608 false);
5609 child->SetDrawsContent(true); 5067 child->SetDrawsContent(true);
5610 5068
5611 std::unique_ptr<LayerImpl> grand_child = 5069 std::unique_ptr<LayerImpl> grand_child =
5612 LayerImpl::Create(host_impl.pending_tree(), 3); 5070 LayerImpl::Create(host_impl.pending_tree(), 3);
5613 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, 5071 grand_child->SetBounds(gfx::Size(30, 30));
5614 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5615 true, false, false);
5616 grand_child->SetDrawsContent(true); 5072 grand_child->SetDrawsContent(true);
5617 grand_child->test_properties()->hide_layer_and_subtree = true; 5073 grand_child->test_properties()->hide_layer_and_subtree = true;
5618 5074
5619 child->test_properties()->AddChild(std::move(grand_child)); 5075 child->test_properties()->AddChild(std::move(grand_child));
5620 root->test_properties()->AddChild(std::move(child)); 5076 root->test_properties()->AddChild(std::move(child));
5621 root->SetHasRenderSurface(true); 5077 root->SetHasRenderSurface(true);
5622 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); 5078 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
5623 5079
5624 LayerImplList render_surface_layer_list; 5080 LayerImplList render_surface_layer_list;
5625 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 5081 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
(...skipping 13 matching lines...) Expand all
5639 FakeImplTaskRunnerProvider task_runner_provider; 5095 FakeImplTaskRunnerProvider task_runner_provider;
5640 TestSharedBitmapManager shared_bitmap_manager; 5096 TestSharedBitmapManager shared_bitmap_manager;
5641 TestTaskGraphRunner task_graph_runner; 5097 TestTaskGraphRunner task_graph_runner;
5642 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 5098 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
5643 &task_graph_runner); 5099 &task_graph_runner);
5644 host_impl.CreatePendingTree(); 5100 host_impl.CreatePendingTree();
5645 const gfx::Transform identity_matrix; 5101 const gfx::Transform identity_matrix;
5646 5102
5647 std::unique_ptr<LayerImpl> root = 5103 std::unique_ptr<LayerImpl> root =
5648 LayerImpl::Create(host_impl.pending_tree(), 1); 5104 LayerImpl::Create(host_impl.pending_tree(), 1);
5649 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), 5105 root->SetBounds(gfx::Size(50, 50));
5650 gfx::PointF(), gfx::Size(50, 50), true, false,
5651 true);
5652 root->SetDrawsContent(true); 5106 root->SetDrawsContent(true);
5653 LayerImpl* root_layer = root.get(); 5107 LayerImpl* root_layer = root.get();
5654 5108
5655 std::unique_ptr<LayerImpl> child = 5109 std::unique_ptr<LayerImpl> child =
5656 LayerImpl::Create(host_impl.pending_tree(), 2); 5110 LayerImpl::Create(host_impl.pending_tree(), 2);
5657 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), 5111 child->SetBounds(gfx::Size(40, 40));
5658 gfx::PointF(), gfx::Size(40, 40), true, false,
5659 false);
5660 child->SetDrawsContent(true); 5112 child->SetDrawsContent(true);
5661 child->test_properties()->hide_layer_and_subtree = true; 5113 child->test_properties()->hide_layer_and_subtree = true;
5662 5114
5663 std::unique_ptr<LayerImpl> grand_child = 5115 std::unique_ptr<LayerImpl> grand_child =
5664 LayerImpl::Create(host_impl.pending_tree(), 3); 5116 LayerImpl::Create(host_impl.pending_tree(), 3);
5665 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, 5117 grand_child->SetBounds(gfx::Size(30, 30));
5666 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5667 true, false, false);
5668 grand_child->SetDrawsContent(true); 5118 grand_child->SetDrawsContent(true);
5669 5119
5670 child->test_properties()->AddChild(std::move(grand_child)); 5120 child->test_properties()->AddChild(std::move(grand_child));
5671 root->test_properties()->AddChild(std::move(child)); 5121 root->test_properties()->AddChild(std::move(child));
5672 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); 5122 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
5673 5123
5674 LayerImplList render_surface_layer_list; 5124 LayerImplList render_surface_layer_list;
5675 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 5125 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5676 root_layer, root_layer->bounds(), &render_surface_layer_list); 5126 root_layer, root_layer->bounds(), &render_surface_layer_list);
5677 inputs.can_adjust_raster_scales = true; 5127 inputs.can_adjust_raster_scales = true;
(...skipping 12 matching lines...) Expand all
5690 FakeImplTaskRunnerProvider task_runner_provider; 5140 FakeImplTaskRunnerProvider task_runner_provider;
5691 TestSharedBitmapManager shared_bitmap_manager; 5141 TestSharedBitmapManager shared_bitmap_manager;
5692 TestTaskGraphRunner task_graph_runner; 5142 TestTaskGraphRunner task_graph_runner;
5693 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 5143 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
5694 &task_graph_runner); 5144 &task_graph_runner);
5695 host_impl.CreatePendingTree(); 5145 host_impl.CreatePendingTree();
5696 const gfx::Transform identity_matrix; 5146 const gfx::Transform identity_matrix;
5697 5147
5698 std::unique_ptr<LayerImpl> root = 5148 std::unique_ptr<LayerImpl> root =
5699 LayerImpl::Create(host_impl.pending_tree(), 1); 5149 LayerImpl::Create(host_impl.pending_tree(), 1);
5700 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), 5150 root->SetBounds(gfx::Size(50, 50));
5701 gfx::PointF(), gfx::Size(50, 50), true, false,
5702 true);
5703 root->SetDrawsContent(true); 5151 root->SetDrawsContent(true);
5704 LayerImpl* root_layer = root.get(); 5152 LayerImpl* root_layer = root.get();
5705 5153
5706 std::unique_ptr<LayerImpl> copy_grand_parent = 5154 std::unique_ptr<LayerImpl> copy_grand_parent =
5707 LayerImpl::Create(host_impl.pending_tree(), 2); 5155 LayerImpl::Create(host_impl.pending_tree(), 2);
5708 SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix, 5156 copy_grand_parent->SetBounds(gfx::Size(40, 40));
5709 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5710 true, false, false);
5711 copy_grand_parent->SetDrawsContent(true); 5157 copy_grand_parent->SetDrawsContent(true);
5712 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get(); 5158 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
5713 5159
5714 std::unique_ptr<LayerImpl> copy_parent = 5160 std::unique_ptr<LayerImpl> copy_parent =
5715 LayerImpl::Create(host_impl.pending_tree(), 3); 5161 LayerImpl::Create(host_impl.pending_tree(), 3);
5716 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix, 5162 copy_parent->SetBounds(gfx::Size(30, 30));
5717 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5718 true, false, true);
5719 copy_parent->SetDrawsContent(true); 5163 copy_parent->SetDrawsContent(true);
5164 copy_parent->test_properties()->force_render_surface = true;
5720 LayerImpl* copy_parent_layer = copy_parent.get(); 5165 LayerImpl* copy_parent_layer = copy_parent.get();
5721 5166
5722 std::unique_ptr<LayerImpl> copy_request = 5167 std::unique_ptr<LayerImpl> copy_request =
5723 LayerImpl::Create(host_impl.pending_tree(), 4); 5168 LayerImpl::Create(host_impl.pending_tree(), 4);
5724 SetLayerPropertiesForTesting(copy_request.get(), identity_matrix, 5169 copy_request->SetBounds(gfx::Size(20, 20));
5725 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5726 true, false, true);
5727 copy_request->SetDrawsContent(true); 5170 copy_request->SetDrawsContent(true);
5171 copy_request->test_properties()->force_render_surface = true;
5728 LayerImpl* copy_layer = copy_request.get(); 5172 LayerImpl* copy_layer = copy_request.get();
5729 5173
5730 std::unique_ptr<LayerImpl> copy_child = 5174 std::unique_ptr<LayerImpl> copy_child =
5731 LayerImpl::Create(host_impl.pending_tree(), 5); 5175 LayerImpl::Create(host_impl.pending_tree(), 5);
5732 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix, 5176 copy_child->SetBounds(gfx::Size(20, 20));
5733 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5734 true, false, false);
5735 copy_child->SetDrawsContent(true); 5177 copy_child->SetDrawsContent(true);
5736 LayerImpl* copy_child_layer = copy_child.get(); 5178 LayerImpl* copy_child_layer = copy_child.get();
5737 5179
5738 std::unique_ptr<LayerImpl> copy_grand_child = 5180 std::unique_ptr<LayerImpl> copy_grand_child =
5739 LayerImpl::Create(host_impl.pending_tree(), 6); 5181 LayerImpl::Create(host_impl.pending_tree(), 6);
5740 SetLayerPropertiesForTesting(copy_grand_child.get(), identity_matrix, 5182 copy_grand_child->SetBounds(gfx::Size(20, 20));
5741 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), 5183 copy_grand_child->SetDrawsContent(true);
5742 true, false, false);
5743 copy_child->SetDrawsContent(true);
5744 LayerImpl* copy_grand_child_layer = copy_grand_child.get(); 5184 LayerImpl* copy_grand_child_layer = copy_grand_child.get();
5745 5185
5746 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before = 5186 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before =
5747 LayerImpl::Create(host_impl.pending_tree(), 7); 5187 LayerImpl::Create(host_impl.pending_tree(), 7);
5748 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), 5188 copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40));
5749 identity_matrix, gfx::Point3F(), gfx::PointF(),
5750 gfx::Size(40, 40), true, false, false);
5751 copy_grand_parent_sibling_before->SetDrawsContent(true); 5189 copy_grand_parent_sibling_before->SetDrawsContent(true);
5752 LayerImpl* copy_grand_parent_sibling_before_layer = 5190 LayerImpl* copy_grand_parent_sibling_before_layer =
5753 copy_grand_parent_sibling_before.get(); 5191 copy_grand_parent_sibling_before.get();
5754 5192
5755 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after = 5193 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after =
5756 LayerImpl::Create(host_impl.pending_tree(), 8); 5194 LayerImpl::Create(host_impl.pending_tree(), 8);
5757 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), 5195 copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40));
5758 identity_matrix, gfx::Point3F(), gfx::PointF(),
5759 gfx::Size(40, 40), true, false, false);
5760 copy_grand_parent_sibling_after->SetDrawsContent(true); 5196 copy_grand_parent_sibling_after->SetDrawsContent(true);
5761 LayerImpl* copy_grand_parent_sibling_after_layer = 5197 LayerImpl* copy_grand_parent_sibling_after_layer =
5762 copy_grand_parent_sibling_after.get(); 5198 copy_grand_parent_sibling_after.get();
5763 5199
5764 copy_child->test_properties()->AddChild(std::move(copy_grand_child)); 5200 copy_child->test_properties()->AddChild(std::move(copy_grand_child));
5765 copy_request->test_properties()->AddChild(std::move(copy_child)); 5201 copy_request->test_properties()->AddChild(std::move(copy_child));
5766 copy_parent->test_properties()->AddChild(std::move(copy_request)); 5202 copy_parent->test_properties()->AddChild(std::move(copy_request));
5767 copy_grand_parent->test_properties()->AddChild(std::move(copy_parent)); 5203 copy_grand_parent->test_properties()->AddChild(std::move(copy_parent));
5768 root->test_properties()->AddChild( 5204 root->test_properties()->AddChild(
5769 std::move(copy_grand_parent_sibling_before)); 5205 std::move(copy_grand_parent_sibling_before));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
5851 FakeImplTaskRunnerProvider task_runner_provider; 5287 FakeImplTaskRunnerProvider task_runner_provider;
5852 TestSharedBitmapManager shared_bitmap_manager; 5288 TestSharedBitmapManager shared_bitmap_manager;
5853 TestTaskGraphRunner task_graph_runner; 5289 TestTaskGraphRunner task_graph_runner;
5854 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 5290 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
5855 &task_graph_runner); 5291 &task_graph_runner);
5856 host_impl.CreatePendingTree(); 5292 host_impl.CreatePendingTree();
5857 const gfx::Transform identity_matrix; 5293 const gfx::Transform identity_matrix;
5858 5294
5859 std::unique_ptr<LayerImpl> root = 5295 std::unique_ptr<LayerImpl> root =
5860 LayerImpl::Create(host_impl.pending_tree(), 1); 5296 LayerImpl::Create(host_impl.pending_tree(), 1);
5861 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), 5297 root->SetBounds(gfx::Size(50, 50));
5862 gfx::PointF(), gfx::Size(50, 50), true, false,
5863 true);
5864 root->SetDrawsContent(true); 5298 root->SetDrawsContent(true);
5865 5299
5866 std::unique_ptr<LayerImpl> copy_parent = 5300 std::unique_ptr<LayerImpl> copy_parent =
5867 LayerImpl::Create(host_impl.pending_tree(), 2); 5301 LayerImpl::Create(host_impl.pending_tree(), 2);
5868 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
5869 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
5870 false, false);
5871 copy_parent->SetDrawsContent(true); 5302 copy_parent->SetDrawsContent(true);
5872 copy_parent->SetMasksToBounds(true); 5303 copy_parent->SetMasksToBounds(true);
5873 5304
5874 std::unique_ptr<LayerImpl> copy_layer = 5305 std::unique_ptr<LayerImpl> copy_layer =
5875 LayerImpl::Create(host_impl.pending_tree(), 3); 5306 LayerImpl::Create(host_impl.pending_tree(), 3);
5876 SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix, 5307 copy_layer->SetBounds(gfx::Size(30, 30));
5877 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5878 true, false, true);
5879 copy_layer->SetDrawsContent(true); 5308 copy_layer->SetDrawsContent(true);
5309 copy_layer->test_properties()->force_render_surface = true;
5880 5310
5881 std::unique_ptr<LayerImpl> copy_child = 5311 std::unique_ptr<LayerImpl> copy_child =
5882 LayerImpl::Create(host_impl.pending_tree(), 4); 5312 LayerImpl::Create(host_impl.pending_tree(), 4);
5883 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix, 5313 copy_child->SetBounds(gfx::Size(20, 20));
5884 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5885 true, false, false);
5886 copy_child->SetDrawsContent(true); 5314 copy_child->SetDrawsContent(true);
5887 5315
5888 copy_layer->test_properties()->copy_requests.push_back( 5316 copy_layer->test_properties()->copy_requests.push_back(
5889 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); 5317 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5890 5318
5891 copy_layer->test_properties()->AddChild(std::move(copy_child)); 5319 copy_layer->test_properties()->AddChild(std::move(copy_child));
5892 copy_parent->test_properties()->AddChild(std::move(copy_layer)); 5320 copy_parent->test_properties()->AddChild(std::move(copy_layer));
5893 root->test_properties()->AddChild(std::move(copy_parent)); 5321 root->test_properties()->AddChild(std::move(copy_parent));
5894 5322
5895 LayerImplList render_surface_layer_list; 5323 LayerImplList render_surface_layer_list;
(...skipping 12 matching lines...) Expand all
5908 // other layers are empty/clipped away. 5336 // other layers are empty/clipped away.
5909 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); 5337 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5910 EXPECT_EQ(root_layer->id(), 5338 EXPECT_EQ(root_layer->id(),
5911 root_layer->render_surface()->layer_list().at(0)->id()); 5339 root_layer->render_surface()->layer_list().at(0)->id());
5912 } 5340 }
5913 5341
5914 TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) { 5342 TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) {
5915 const gfx::Transform identity_matrix; 5343 const gfx::Transform identity_matrix;
5916 5344
5917 LayerImpl* root = root_layer_for_testing(); 5345 LayerImpl* root = root_layer_for_testing();
5918 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), 5346 root->SetBounds(gfx::Size(50, 50));
5919 gfx::PointF(), gfx::Size(50, 50), true, false,
5920 true);
5921 root->SetDrawsContent(true); 5347 root->SetDrawsContent(true);
5922 root->SetMasksToBounds(true); 5348 root->SetMasksToBounds(true);
5923 5349
5924 LayerImpl* copy_layer = AddChild<LayerImpl>(root); 5350 LayerImpl* copy_layer = AddChild<LayerImpl>(root);
5925 SetLayerPropertiesForTesting(copy_layer, identity_matrix, gfx::Point3F(), 5351 copy_layer->SetBounds(gfx::Size(100, 100));
5926 gfx::PointF(), gfx::Size(100, 100), true, false,
5927 true);
5928 copy_layer->SetDrawsContent(true); 5352 copy_layer->SetDrawsContent(true);
5353 copy_layer->test_properties()->force_render_surface = true;
5929 5354
5930 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer); 5355 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
5931 SetLayerPropertiesForTesting(copy_child, identity_matrix, gfx::Point3F(), 5356 copy_child->SetPosition(gfx::PointF(40.f, 40.f));
5932 gfx::PointF(40, 40), gfx::Size(20, 20), true, 5357 copy_child->SetBounds(gfx::Size(20, 20));
5933 false, false);
5934 copy_child->SetDrawsContent(true); 5358 copy_child->SetDrawsContent(true);
5935 5359
5936 LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer); 5360 LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer);
5937 SetLayerPropertiesForTesting(copy_clip, identity_matrix, gfx::Point3F(), 5361 copy_clip->SetBounds(gfx::Size(55, 55));
5938 gfx::PointF(), gfx::Size(55, 55), true, false,
5939 false);
5940 copy_clip->SetMasksToBounds(true); 5362 copy_clip->SetMasksToBounds(true);
5941 5363
5942 LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip); 5364 LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip);
5943 SetLayerPropertiesForTesting(copy_clipped_child, identity_matrix, 5365 copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f));
5944 gfx::Point3F(), gfx::PointF(40, 40), 5366 copy_clipped_child->SetBounds(gfx::Size(20, 20));
5945 gfx::Size(20, 20), true, false, false);
5946 copy_clipped_child->SetDrawsContent(true); 5367 copy_clipped_child->SetDrawsContent(true);
5947 5368
5948 LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip); 5369 LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip);
5949 SetLayerPropertiesForTesting(copy_surface, identity_matrix, gfx::Point3F(), 5370 copy_surface->SetPosition(gfx::PointF(45.f, 45.f));
5950 gfx::PointF(45, 45), gfx::Size(20, 20), true, 5371 copy_surface->SetBounds(gfx::Size(20, 20));
5951 false, true);
5952 copy_surface->SetDrawsContent(true); 5372 copy_surface->SetDrawsContent(true);
5373 copy_surface->test_properties()->force_render_surface = true;
5953 5374
5954 copy_layer->test_properties()->copy_requests.push_back( 5375 copy_layer->test_properties()->copy_requests.push_back(
5955 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); 5376 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5956 5377
5957 DCHECK(!copy_layer->test_properties()->copy_requests.empty()); 5378 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
5958 ExecuteCalculateDrawProperties(root); 5379 ExecuteCalculateDrawProperties(root);
5959 DCHECK(copy_layer->test_properties()->copy_requests.empty()); 5380 DCHECK(copy_layer->test_properties()->copy_requests.empty());
5960 5381
5961 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect()); 5382 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect());
5962 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect()); 5383 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect());
(...skipping 29 matching lines...) Expand all
5992 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); 5413 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5993 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); 5414 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5994 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); 5415 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
5995 } 5416 }
5996 5417
5997 TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { 5418 TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
5998 LayerImpl* root = root_layer_for_testing(); 5419 LayerImpl* root = root_layer_for_testing();
5999 LayerImpl* surface = AddChild<LayerImpl>(root); 5420 LayerImpl* surface = AddChild<LayerImpl>(root);
6000 LayerImpl* surface_child = AddChild<LayerImpl>(surface); 5421 LayerImpl* surface_child = AddChild<LayerImpl>(surface);
6001 5422
6002 const gfx::Transform identity_matrix; 5423 root->SetBounds(gfx::Size(50, 50));
6003 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
6004 gfx::PointF(), gfx::Size(50, 50), true, false,
6005 true);
6006 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
6007 gfx::PointF(-10, 20), gfx::Size(), true, false,
6008 true);
6009 SetLayerPropertiesForTesting(surface_child, identity_matrix, gfx::Point3F(),
6010 gfx::PointF(), gfx::Size(50, 50), true, false,
6011 false);
6012 root->SetDrawsContent(true); 5424 root->SetDrawsContent(true);
5425 surface->SetPosition(gfx::PointF(-10, 20));
5426 surface->test_properties()->force_render_surface = true;
5427 surface_child->SetBounds(gfx::Size(50, 50));
6013 surface_child->SetDrawsContent(true); 5428 surface_child->SetDrawsContent(true);
6014
6015 ExecuteCalculateDrawProperties(root); 5429 ExecuteCalculateDrawProperties(root);
6016 5430
6017 // The visible_layer_rect for the |surface_child| should not be clipped by 5431 // The visible_layer_rect for the |surface_child| should not be clipped by
6018 // the viewport. 5432 // the viewport.
6019 EXPECT_EQ(gfx::Rect(50, 50), surface_child->visible_layer_rect()); 5433 EXPECT_EQ(gfx::Rect(50, 50), surface_child->visible_layer_rect());
6020 } 5434 }
6021 5435
6022 TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { 5436 TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
6023 // Ensure that a transform between the layer and its render surface is not a 5437 // Ensure that a transform between the layer and its render surface is not a
6024 // problem. Constructs the following layer tree. 5438 // problem. Constructs the following layer tree.
(...skipping 4543 matching lines...) Expand 10 before | Expand all | Expand 10 after
10568 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); 9982 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10569 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); 9983 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10570 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); 9984 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10571 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); 9985 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10572 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); 9986 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10573 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); 9987 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10574 } 9988 }
10575 9989
10576 } // namespace 9990 } // namespace
10577 } // namespace cc 9991 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698