1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/picture_layer_impl.h"
12 #include "cc/layers/append_quads_data.h"
13 #include "cc/layers/picture_layer.h"
14 #include "cc/quads/draw_quad.h"
15 #include "cc/test/fake_content_layer_client.h"
16 #include "cc/test/fake_impl_proxy.h"
17 #include "cc/test/fake_layer_tree_host_impl.h"
18 #include "cc/test/fake_output_surface.h"
19 #include "cc/test/fake_picture_layer_impl.h"
20 #include "cc/test/fake_picture_pile_impl.h"
21 #include "cc/test/geometry_test_utils.h"
22 #include "cc/test/impl_side_painting_settings.h"
23 #include "cc/test/layer_test_common.h"
24 #include "cc/test/test_shared_bitmap_manager.h"
25 #include "cc/test/test_web_graphics_context_3d.h"
26 #include "cc/trees/layer_tree_impl.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gfx/rect_conversions.h"
29 #include "ui/gfx/size_conversions.h"
34 class MockCanvas
: public SkCanvas
{
36 explicit MockCanvas(int w
, int h
) : SkCanvas(w
, h
) {}
38 virtual void drawRect(const SkRect
& rect
, const SkPaint
& paint
) OVERRIDE
{
39 // Capture calls before SkCanvas quickReject() kicks in.
40 rects_
.push_back(rect
);
43 std::vector
<SkRect
> rects_
;
46 class PictureLayerImplTest
: public testing::Test
{
48 PictureLayerImplTest()
49 : proxy_(base::MessageLoopProxy::current()),
50 host_impl_(ImplSidePaintingSettings(),
52 &shared_bitmap_manager_
),
55 explicit PictureLayerImplTest(const LayerTreeSettings
& settings
)
56 : proxy_(base::MessageLoopProxy::current()),
57 host_impl_(settings
, &proxy_
, &shared_bitmap_manager_
),
60 virtual ~PictureLayerImplTest() {
63 virtual void SetUp() OVERRIDE
{
67 virtual void InitializeRenderer() {
68 host_impl_
.InitializeRenderer(
69 FakeOutputSurface::Create3d().PassAs
<OutputSurface
>());
72 void SetupDefaultTrees(const gfx::Size
& layer_bounds
) {
73 gfx::Size
tile_size(100, 100);
75 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
76 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
77 scoped_refptr
<FakePicturePileImpl
> active_pile
=
78 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
80 SetupTrees(pending_pile
, active_pile
);
84 host_impl_
.ActivateSyncTree();
85 CHECK(!host_impl_
.pending_tree());
86 pending_layer_
= NULL
;
87 active_layer_
= static_cast<FakePictureLayerImpl
*>(
88 host_impl_
.active_tree()->LayerById(id_
));
91 void SetupDefaultTreesWithFixedTileSize(const gfx::Size
& layer_bounds
,
92 const gfx::Size
& tile_size
) {
93 SetupDefaultTrees(layer_bounds
);
94 pending_layer_
->set_fixed_tile_size(tile_size
);
95 active_layer_
->set_fixed_tile_size(tile_size
);
99 scoped_refptr
<PicturePileImpl
> pending_pile
,
100 scoped_refptr
<PicturePileImpl
> active_pile
) {
101 SetupPendingTree(active_pile
);
103 SetupPendingTree(pending_pile
);
104 host_impl_
.pending_tree()->SetPageScaleFactorAndLimits(1.f
, 0.25f
, 100.f
);
105 host_impl_
.active_tree()->SetPageScaleFactorAndLimits(1.f
, 0.25f
, 100.f
);
108 void CreateHighLowResAndSetAllTilesVisible() {
109 // Active layer must get updated first so pending layer can share from it.
110 active_layer_
->CreateDefaultTilingsAndTiles();
111 active_layer_
->SetAllTilesVisible();
112 pending_layer_
->CreateDefaultTilingsAndTiles();
113 pending_layer_
->SetAllTilesVisible();
116 void AddDefaultTilingsWithInvalidation(const Region
& invalidation
) {
117 active_layer_
->AddTiling(2.3f
);
118 active_layer_
->AddTiling(1.0f
);
119 active_layer_
->AddTiling(0.5f
);
120 for (size_t i
= 0; i
< active_layer_
->tilings()->num_tilings(); ++i
)
121 active_layer_
->tilings()->tiling_at(i
)->CreateAllTilesForTesting();
122 pending_layer_
->set_invalidation(invalidation
);
123 for (size_t i
= 0; i
< pending_layer_
->tilings()->num_tilings(); ++i
)
124 pending_layer_
->tilings()->tiling_at(i
)->CreateAllTilesForTesting();
127 void SetupPendingTree(scoped_refptr
<PicturePileImpl
> pile
) {
128 host_impl_
.CreatePendingTree();
129 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
130 // Clear recycled tree.
131 pending_tree
->DetachLayerTree();
133 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
134 FakePictureLayerImpl::CreateWithPile(pending_tree
, id_
, pile
);
135 pending_layer
->SetDrawsContent(true);
136 pending_tree
->SetRootLayer(pending_layer
.PassAs
<LayerImpl
>());
138 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
139 host_impl_
.pending_tree()->LayerById(id_
));
140 pending_layer_
->DoPostCommitInitializationIfNeeded();
143 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl
* layer
,
144 float ideal_contents_scale
,
145 float device_scale_factor
,
146 float page_scale_factor
,
147 float maximum_animation_contents_scale
,
148 bool animating_transform_to_screen
) {
149 layer
->draw_properties().ideal_contents_scale
= ideal_contents_scale
;
150 layer
->draw_properties().device_scale_factor
= device_scale_factor
;
151 layer
->draw_properties().page_scale_factor
= page_scale_factor
;
152 layer
->draw_properties().maximum_animation_contents_scale
=
153 maximum_animation_contents_scale
;
154 layer
->draw_properties().screen_space_transform_is_animating
=
155 animating_transform_to_screen
;
156 layer
->UpdateTiles(NULL
);
158 static void VerifyAllTilesExistAndHavePile(
159 const PictureLayerTiling
* tiling
,
160 PicturePileImpl
* pile
) {
161 for (PictureLayerTiling::CoverageIterator
iter(
162 tiling
, tiling
->contents_scale(), tiling
->TilingRect());
166 EXPECT_EQ(pile
, iter
->picture_pile());
170 void SetContentsScaleOnBothLayers(float contents_scale
,
171 float device_scale_factor
,
172 float page_scale_factor
,
173 float maximum_animation_contents_scale
,
174 bool animating_transform
) {
175 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
179 maximum_animation_contents_scale
,
180 animating_transform
);
182 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
186 maximum_animation_contents_scale
,
187 animating_transform
);
190 void ResetTilingsAndRasterScales() {
191 pending_layer_
->ReleaseResources();
192 active_layer_
->ReleaseResources();
195 void AssertAllTilesRequired(PictureLayerTiling
* tiling
) {
196 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
197 for (size_t i
= 0; i
< tiles
.size(); ++i
)
198 EXPECT_TRUE(tiles
[i
]->required_for_activation()) << "i: " << i
;
199 EXPECT_GT(tiles
.size(), 0u);
202 void AssertNoTilesRequired(PictureLayerTiling
* tiling
) {
203 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
204 for (size_t i
= 0; i
< tiles
.size(); ++i
)
205 EXPECT_FALSE(tiles
[i
]->required_for_activation()) << "i: " << i
;
206 EXPECT_GT(tiles
.size(), 0u);
210 void TestTileGridAlignmentCommon() {
211 // Layer to span 4 raster tiles in x and in y
212 ImplSidePaintingSettings settings
;
213 gfx::Size
layer_size(
214 settings
.default_tile_size
.width() * 7 / 2,
215 settings
.default_tile_size
.height() * 7 / 2);
217 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
218 FakePicturePileImpl::CreateFilledPile(layer_size
, layer_size
);
219 scoped_refptr
<FakePicturePileImpl
> active_pile
=
220 FakePicturePileImpl::CreateFilledPile(layer_size
, layer_size
);
222 SetupTrees(pending_pile
, active_pile
);
224 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
226 // Add 1x1 rects at the centers of each tile, then re-record pile contents
227 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
228 std::vector
<Tile
*> tiles
=
229 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
230 EXPECT_EQ(16u, tiles
.size());
231 std::vector
<SkRect
> rects
;
232 std::vector
<Tile
*>::const_iterator tile_iter
;
233 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
234 gfx::Point tile_center
= (*tile_iter
)->content_rect().CenterPoint();
235 gfx::Rect
rect(tile_center
.x(), tile_center
.y(), 1, 1);
236 active_pile
->add_draw_rect(rect
);
237 rects
.push_back(SkRect::MakeXYWH(rect
.x(), rect
.y(), 1, 1));
239 // Force re-record with newly injected content
240 active_pile
->RemoveRecordingAt(0, 0);
241 active_pile
->AddRecordingAt(0, 0);
243 std::vector
<SkRect
>::const_iterator rect_iter
= rects
.begin();
244 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
245 MockCanvas
mock_canvas(1000, 1000);
246 active_pile
->RasterDirect(
247 &mock_canvas
, (*tile_iter
)->content_rect(), 1.0f
, NULL
);
249 // This test verifies that when drawing the contents of a specific tile
250 // at content scale 1.0, the playback canvas never receives content from
251 // neighboring tiles which indicates that the tile grid embedded in
252 // SkPicture is perfectly aligned with the compositor's tiles.
253 EXPECT_EQ(1u, mock_canvas
.rects_
.size());
254 EXPECT_RECT_EQ(*rect_iter
, mock_canvas
.rects_
[0]);
259 FakeImplProxy proxy_
;
260 TestSharedBitmapManager shared_bitmap_manager_
;
261 FakeLayerTreeHostImpl host_impl_
;
263 FakePictureLayerImpl
* pending_layer_
;
264 FakePictureLayerImpl
* active_layer_
;
267 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest
);
270 TEST_F(PictureLayerImplTest
, TileGridAlignment
) {
271 host_impl_
.SetDeviceScaleFactor(1.f
);
272 TestTileGridAlignmentCommon();
275 TEST_F(PictureLayerImplTest
, TileGridAlignmentHiDPI
) {
276 host_impl_
.SetDeviceScaleFactor(2.f
);
277 TestTileGridAlignmentCommon();
280 TEST_F(PictureLayerImplTest
, CloneNoInvalidation
) {
281 gfx::Size
tile_size(100, 100);
282 gfx::Size
layer_bounds(400, 400);
284 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
285 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
286 scoped_refptr
<FakePicturePileImpl
> active_pile
=
287 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
289 SetupTrees(pending_pile
, active_pile
);
292 AddDefaultTilingsWithInvalidation(invalidation
);
294 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
295 active_layer_
->tilings()->num_tilings());
297 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
298 EXPECT_GT(tilings
->num_tilings(), 0u);
299 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
300 VerifyAllTilesExistAndHavePile(tilings
->tiling_at(i
), active_pile
.get());
303 TEST_F(PictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
304 base::TimeTicks time_ticks
;
305 host_impl_
.SetCurrentFrameTimeTicks(time_ticks
);
307 gfx::Size
tile_size(100, 100);
308 gfx::Size
layer_bounds(400, 400);
310 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
311 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
312 scoped_refptr
<FakePicturePileImpl
> active_pile
=
313 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
315 SetupTrees(pending_pile
, active_pile
);
318 AddDefaultTilingsWithInvalidation(invalidation
);
319 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
321 // UpdateTiles with valid viewport. Should update tile viewport.
322 // Note viewport is considered invalid if and only if in resourceless
324 bool resourceless_software_draw
= false;
325 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
326 gfx::Transform transform
;
327 host_impl_
.SetExternalDrawConstraints(
328 transform
, viewport
, viewport
, resourceless_software_draw
);
329 active_layer_
->draw_properties().visible_content_rect
= viewport
;
330 active_layer_
->draw_properties().screen_space_transform
= transform
;
331 active_layer_
->UpdateTiles(NULL
);
333 gfx::Rect visible_rect_for_tile_priority
=
334 active_layer_
->visible_rect_for_tile_priority();
335 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
336 gfx::Size viewport_size_for_tile_priority
=
337 active_layer_
->viewport_size_for_tile_priority();
338 EXPECT_FALSE(viewport_size_for_tile_priority
.IsEmpty());
339 gfx::Transform screen_space_transform_for_tile_priority
=
340 active_layer_
->screen_space_transform_for_tile_priority();
342 // Expand viewport and set it as invalid for prioritizing tiles.
343 // Should not update tile viewport.
344 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
345 host_impl_
.SetCurrentFrameTimeTicks(time_ticks
);
346 resourceless_software_draw
= true;
347 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
348 transform
.Translate(1.f
, 1.f
);
349 active_layer_
->draw_properties().visible_content_rect
= viewport
;
350 active_layer_
->draw_properties().screen_space_transform
= transform
;
351 host_impl_
.SetExternalDrawConstraints(
352 transform
, viewport
, viewport
, resourceless_software_draw
);
353 active_layer_
->UpdateTiles(NULL
);
355 EXPECT_RECT_EQ(visible_rect_for_tile_priority
,
356 active_layer_
->visible_rect_for_tile_priority());
357 EXPECT_SIZE_EQ(viewport_size_for_tile_priority
,
358 active_layer_
->viewport_size_for_tile_priority());
359 EXPECT_TRANSFORMATION_MATRIX_EQ(
360 screen_space_transform_for_tile_priority
,
361 active_layer_
->screen_space_transform_for_tile_priority());
363 // Keep expanded viewport but mark it valid. Should update tile viewport.
364 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
365 host_impl_
.SetCurrentFrameTimeTicks(time_ticks
);
366 resourceless_software_draw
= false;
367 host_impl_
.SetExternalDrawConstraints(
368 transform
, viewport
, viewport
, resourceless_software_draw
);
369 active_layer_
->UpdateTiles(NULL
);
371 EXPECT_FALSE(visible_rect_for_tile_priority
==
372 active_layer_
->visible_rect_for_tile_priority());
373 EXPECT_FALSE(viewport_size_for_tile_priority
==
374 active_layer_
->viewport_size_for_tile_priority());
375 EXPECT_FALSE(screen_space_transform_for_tile_priority
==
376 active_layer_
->screen_space_transform_for_tile_priority());
379 TEST_F(PictureLayerImplTest
, InvalidViewportAfterReleaseResources
) {
380 base::TimeTicks time_ticks
;
381 host_impl_
.SetCurrentFrameTimeTicks(time_ticks
);
383 gfx::Size
tile_size(100, 100);
384 gfx::Size
layer_bounds(400, 400);
386 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
387 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
388 scoped_refptr
<FakePicturePileImpl
> active_pile
=
389 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
391 SetupTrees(pending_pile
, active_pile
);
394 AddDefaultTilingsWithInvalidation(invalidation
);
396 bool resourceless_software_draw
= true;
397 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
398 host_impl_
.SetExternalDrawConstraints(
399 gfx::Transform(), viewport
, viewport
, resourceless_software_draw
);
400 ResetTilingsAndRasterScales();
401 host_impl_
.pending_tree()->UpdateDrawProperties();
402 host_impl_
.active_tree()->UpdateDrawProperties();
403 EXPECT_TRUE(active_layer_
->HighResTiling());
405 size_t num_tilings
= active_layer_
->num_tilings();
406 active_layer_
->UpdateTiles(NULL
);
407 pending_layer_
->AddTiling(0.5f
);
408 EXPECT_EQ(num_tilings
+ 1, active_layer_
->num_tilings());
411 TEST_F(PictureLayerImplTest
, ClonePartialInvalidation
) {
412 gfx::Size
tile_size(100, 100);
413 gfx::Size
layer_bounds(400, 400);
414 gfx::Rect
layer_invalidation(150, 200, 30, 180);
416 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
417 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
418 scoped_refptr
<FakePicturePileImpl
> active_pile
=
419 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
421 SetupTrees(pending_pile
, active_pile
);
423 Region
invalidation(layer_invalidation
);
424 AddDefaultTilingsWithInvalidation(invalidation
);
426 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
427 EXPECT_GT(tilings
->num_tilings(), 0u);
428 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
429 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
430 gfx::Rect content_invalidation
= gfx::ScaleToEnclosingRect(
432 tiling
->contents_scale());
433 for (PictureLayerTiling::CoverageIterator
iter(
434 tiling
, tiling
->contents_scale(), tiling
->TilingRect());
438 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
439 if (iter
.geometry_rect().Intersects(content_invalidation
))
440 EXPECT_EQ(pending_pile
, iter
->picture_pile());
442 EXPECT_EQ(active_pile
, iter
->picture_pile());
447 TEST_F(PictureLayerImplTest
, CloneFullInvalidation
) {
448 gfx::Size
tile_size(90, 80);
449 gfx::Size
layer_bounds(300, 500);
451 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
452 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
453 scoped_refptr
<FakePicturePileImpl
> active_pile
=
454 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
456 SetupTrees(pending_pile
, active_pile
);
458 Region
invalidation((gfx::Rect(layer_bounds
)));
459 AddDefaultTilingsWithInvalidation(invalidation
);
461 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
462 active_layer_
->tilings()->num_tilings());
464 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
465 EXPECT_GT(tilings
->num_tilings(), 0u);
466 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
467 VerifyAllTilesExistAndHavePile(tilings
->tiling_at(i
), pending_pile
.get());
470 TEST_F(PictureLayerImplTest
, NoInvalidationBoundsChange
) {
471 gfx::Size
tile_size(90, 80);
472 gfx::Size
active_layer_bounds(300, 500);
473 gfx::Size
pending_layer_bounds(400, 800);
475 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
476 FakePicturePileImpl::CreateFilledPile(tile_size
,
477 pending_layer_bounds
);
478 scoped_refptr
<FakePicturePileImpl
> active_pile
=
479 FakePicturePileImpl::CreateFilledPile(tile_size
, active_layer_bounds
);
481 SetupTrees(pending_pile
, active_pile
);
482 pending_layer_
->set_fixed_tile_size(gfx::Size(100, 100));
485 AddDefaultTilingsWithInvalidation(invalidation
);
487 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
488 EXPECT_GT(tilings
->num_tilings(), 0u);
489 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
490 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
491 gfx::Rect active_content_bounds
= gfx::ScaleToEnclosingRect(
492 gfx::Rect(active_layer_bounds
),
493 tiling
->contents_scale());
494 for (PictureLayerTiling::CoverageIterator
iter(
495 tiling
, tiling
->contents_scale(), tiling
->TilingRect());
499 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
500 std::vector
<Tile
*> active_tiles
=
501 active_layer_
->tilings()->tiling_at(i
)->AllTilesForTesting();
502 std::vector
<Tile
*> pending_tiles
= tiling
->AllTilesForTesting();
503 if (iter
.geometry_rect().right() >= active_content_bounds
.width() ||
504 iter
.geometry_rect().bottom() >= active_content_bounds
.height() ||
505 active_tiles
[0]->content_rect().size() !=
506 pending_tiles
[0]->content_rect().size()) {
507 EXPECT_EQ(pending_pile
, iter
->picture_pile());
509 EXPECT_EQ(active_pile
, iter
->picture_pile());
515 TEST_F(PictureLayerImplTest
, AddTilesFromNewRecording
) {
516 gfx::Size
tile_size(400, 400);
517 gfx::Size
layer_bounds(1300, 1900);
519 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
520 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
521 scoped_refptr
<FakePicturePileImpl
> active_pile
=
522 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
524 // Fill in some of active pile, but more of pending pile.
526 for (int x
= 0; x
< active_pile
->tiling().num_tiles_x(); ++x
) {
527 for (int y
= 0; y
< active_pile
->tiling().num_tiles_y(); ++y
) {
529 pending_pile
->AddRecordingAt(x
, y
);
530 active_pile
->AddRecordingAt(x
, y
);
534 pending_pile
->AddRecordingAt(x
, y
);
539 SetupTrees(pending_pile
, active_pile
);
541 AddDefaultTilingsWithInvalidation(invalidation
);
543 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
544 EXPECT_GT(tilings
->num_tilings(), 0u);
545 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
546 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
548 for (PictureLayerTiling::CoverageIterator
iter(
549 tiling
, tiling
->contents_scale(), tiling
->TilingRect());
552 EXPECT_FALSE(iter
.full_tile_geometry_rect().IsEmpty());
553 // Ensure there is a recording for this tile.
554 bool in_pending
= pending_pile
->CanRaster(tiling
->contents_scale(),
555 iter
.full_tile_geometry_rect());
556 bool in_active
= active_pile
->CanRaster(tiling
->contents_scale(),
557 iter
.full_tile_geometry_rect());
559 if (in_pending
&& !in_active
)
560 EXPECT_EQ(pending_pile
, iter
->picture_pile());
562 EXPECT_EQ(active_pile
, iter
->picture_pile());
569 TEST_F(PictureLayerImplTest
, ManageTilingsWithNoRecording
) {
570 gfx::Size
tile_size(400, 400);
571 gfx::Size
layer_bounds(1300, 1900);
573 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
574 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
575 scoped_refptr
<FakePicturePileImpl
> active_pile
=
576 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
578 SetupTrees(pending_pile
, active_pile
);
580 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
582 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
585 TEST_F(PictureLayerImplTest
, ManageTilingsCreatesTilings
) {
586 gfx::Size
tile_size(400, 400);
587 gfx::Size
layer_bounds(1300, 1900);
589 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
590 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
591 scoped_refptr
<FakePicturePileImpl
> active_pile
=
592 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
594 SetupTrees(pending_pile
, active_pile
);
595 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
597 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
598 EXPECT_LT(low_res_factor
, 1.f
);
600 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
601 6.f
, // ideal contents scale
604 1.f
, // maximum animation scale
606 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
608 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
609 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
610 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
612 // If we change the page scale factor, then we should get new tilings.
613 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
614 6.6f
, // ideal contents scale
617 1.f
, // maximum animation scale
619 ASSERT_EQ(4u, pending_layer_
->tilings()->num_tilings());
620 EXPECT_FLOAT_EQ(6.6f
,
621 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
622 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
623 pending_layer_
->tilings()->tiling_at(2)->contents_scale());
625 // If we change the device scale factor, then we should get new tilings.
626 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
627 7.26f
, // ideal contents scale
628 3.3f
, // device scale
630 1.f
, // maximum animation scale
632 ASSERT_EQ(6u, pending_layer_
->tilings()->num_tilings());
633 EXPECT_FLOAT_EQ(7.26f
,
634 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
635 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
636 pending_layer_
->tilings()->tiling_at(3)->contents_scale());
638 // If we change the device scale factor, but end up at the same total scale
639 // factor somehow, then we don't get new tilings.
640 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
641 7.26f
, // ideal contents scale
642 2.2f
, // device scale
644 1.f
, // maximum animation scale
646 ASSERT_EQ(6u, pending_layer_
->tilings()->num_tilings());
647 EXPECT_FLOAT_EQ(7.26f
,
648 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
649 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
650 pending_layer_
->tilings()->tiling_at(3)->contents_scale());
653 TEST_F(PictureLayerImplTest
, CreateTilingsEvenIfTwinHasNone
) {
654 // This test makes sure that if a layer can have tilings, then a commit makes
655 // it not able to have tilings (empty size), and then a future commit that
656 // makes it valid again should be able to create tilings.
657 gfx::Size
tile_size(400, 400);
658 gfx::Size
layer_bounds(1300, 1900);
660 scoped_refptr
<FakePicturePileImpl
> empty_pile
=
661 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
662 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
663 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
665 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
666 EXPECT_LT(low_res_factor
, 1.f
);
668 float high_res_scale
= 1.3f
;
669 float low_res_scale
= high_res_scale
* low_res_factor
;
670 float device_scale
= 1.7f
;
671 float page_scale
= 3.2f
;
672 float maximum_animation_scale
= 1.f
;
674 SetupPendingTree(valid_pile
);
675 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
679 maximum_animation_scale
,
681 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
682 EXPECT_FLOAT_EQ(high_res_scale
,
683 pending_layer_
->HighResTiling()->contents_scale());
684 EXPECT_FLOAT_EQ(low_res_scale
,
685 pending_layer_
->LowResTiling()->contents_scale());
688 SetupPendingTree(empty_pile
);
689 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
690 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
694 maximum_animation_scale
,
696 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
697 ASSERT_EQ(0u, pending_layer_
->tilings()->num_tilings());
700 EXPECT_FALSE(active_layer_
->CanHaveTilings());
701 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
705 maximum_animation_scale
,
707 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
709 SetupPendingTree(valid_pile
);
710 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
714 maximum_animation_scale
,
716 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
717 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
718 EXPECT_FLOAT_EQ(high_res_scale
,
719 pending_layer_
->HighResTiling()->contents_scale());
720 EXPECT_FLOAT_EQ(low_res_scale
,
721 pending_layer_
->LowResTiling()->contents_scale());
724 TEST_F(PictureLayerImplTest
, ZoomOutCrash
) {
725 gfx::Size
tile_size(400, 400);
726 gfx::Size
layer_bounds(1300, 1900);
728 // Set up the high and low res tilings before pinch zoom.
729 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
730 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
731 scoped_refptr
<FakePicturePileImpl
> active_pile
=
732 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
734 SetupTrees(pending_pile
, active_pile
);
735 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
736 SetContentsScaleOnBothLayers(32.0f
, 1.0f
, 32.0f
, 1.0f
, false);
737 host_impl_
.PinchGestureBegin();
738 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, false);
739 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, false);
740 EXPECT_EQ(active_layer_
->tilings()->NumHighResTilings(), 1);
743 TEST_F(PictureLayerImplTest
, PinchGestureTilings
) {
744 gfx::Size
tile_size(400, 400);
745 gfx::Size
layer_bounds(1300, 1900);
747 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
748 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
749 scoped_refptr
<FakePicturePileImpl
> active_pile
=
750 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
752 // Set up the high and low res tilings before pinch zoom.
753 SetupTrees(pending_pile
, active_pile
);
754 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
755 SetContentsScaleOnBothLayers(2.0f
, 1.0f
, 1.0f
, 1.0f
, false);
756 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
757 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
758 EXPECT_FLOAT_EQ(2.0f
,
759 active_layer_
->tilings()->tiling_at(0)->contents_scale());
760 EXPECT_FLOAT_EQ(2.0f
* low_res_factor
,
761 active_layer_
->tilings()->tiling_at(1)->contents_scale());
763 // Start a pinch gesture.
764 host_impl_
.PinchGestureBegin();
766 // Zoom out by a small amount. We should create a tiling at half
767 // the scale (2/kMaxScaleRatioDuringPinch).
768 SetContentsScaleOnBothLayers(1.8f
, 1.0f
, 0.9f
, 1.0f
, false);
769 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
770 EXPECT_FLOAT_EQ(2.0f
,
771 active_layer_
->tilings()->tiling_at(0)->contents_scale());
772 EXPECT_FLOAT_EQ(1.0f
,
773 active_layer_
->tilings()->tiling_at(1)->contents_scale());
774 EXPECT_FLOAT_EQ(2.0f
* low_res_factor
,
775 active_layer_
->tilings()->tiling_at(2)->contents_scale());
777 // Zoom out further, close to our low-res scale factor. We should
778 // use that tiling as high-res, and not create a new tiling.
779 SetContentsScaleOnBothLayers(
780 low_res_factor
, 1.0f
, low_res_factor
/ 2.0f
, 1.0f
, false);
781 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
783 // Zoom in a lot now. Since we increase by increments of
784 // kMaxScaleRatioDuringPinch, this will first use 1.0, then 2.0
785 // and then finally create a new tiling at 4.0.
786 SetContentsScaleOnBothLayers(4.2f
, 1.0f
, 2.1f
, 1.f
, false);
787 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
788 SetContentsScaleOnBothLayers(4.2f
, 1.0f
, 2.1f
, 1.f
, false);
789 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
790 SetContentsScaleOnBothLayers(4.2f
, 1.0f
, 2.1f
, 1.f
, false);
791 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
792 EXPECT_FLOAT_EQ(4.0f
,
793 active_layer_
->tilings()->tiling_at(0)->contents_scale());
796 TEST_F(PictureLayerImplTest
, SnappedTilingDuringZoom
) {
797 gfx::Size
tile_size(300, 300);
798 gfx::Size
layer_bounds(2600, 3800);
800 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
801 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
802 scoped_refptr
<FakePicturePileImpl
> active_pile
=
803 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
805 // Set up the high and low res tilings before pinch zoom.
806 SetupTrees(pending_pile
, active_pile
);
807 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
808 SetContentsScaleOnBothLayers(0.24f
, 1.0f
, 0.24f
, 1.0f
, false);
809 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
810 EXPECT_FLOAT_EQ(0.24f
,
811 active_layer_
->tilings()->tiling_at(0)->contents_scale());
812 EXPECT_FLOAT_EQ(0.0625f
,
813 active_layer_
->tilings()->tiling_at(1)->contents_scale());
815 // Start a pinch gesture.
816 host_impl_
.PinchGestureBegin();
818 // Zoom out by a small amount. We should create a tiling at half
819 // the scale (1/kMaxScaleRatioDuringPinch).
820 SetContentsScaleOnBothLayers(0.2f
, 1.0f
, 0.2f
, 1.0f
, false);
821 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
822 EXPECT_FLOAT_EQ(0.24f
,
823 active_layer_
->tilings()->tiling_at(0)->contents_scale());
824 EXPECT_FLOAT_EQ(0.12f
,
825 active_layer_
->tilings()->tiling_at(1)->contents_scale());
826 EXPECT_FLOAT_EQ(0.0625,
827 active_layer_
->tilings()->tiling_at(2)->contents_scale());
829 // Zoom out further, close to our low-res scale factor. We should
830 // use that tiling as high-res, and not create a new tiling.
831 SetContentsScaleOnBothLayers(0.1f
, 1.0f
, 0.1f
, 1.0f
, false);
832 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
834 // Zoom in. 0.125(desired_scale) should be snapped to 0.12 during zoom-in
835 // because 0.125(desired_scale) is within the ratio(1.2)
836 SetContentsScaleOnBothLayers(0.5f
, 1.0f
, 0.5f
, 1.0f
, false);
837 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
840 TEST_F(PictureLayerImplTest
, CleanUpTilings
) {
841 gfx::Size
tile_size(400, 400);
842 gfx::Size
layer_bounds(1300, 1900);
844 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
845 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
846 scoped_refptr
<FakePicturePileImpl
> active_pile
=
847 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
849 std::vector
<PictureLayerTiling
*> used_tilings
;
851 SetupTrees(pending_pile
, active_pile
);
852 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
854 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
855 EXPECT_LT(low_res_factor
, 1.f
);
857 float device_scale
= 1.7f
;
858 float page_scale
= 3.2f
;
861 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
862 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
864 // We only have ideal tilings, so they aren't removed.
865 used_tilings
.clear();
866 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
867 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
869 host_impl_
.PinchGestureBegin();
871 // Changing the ideal but not creating new tilings.
874 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
875 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
877 // The tilings are still our target scale, so they aren't removed.
878 used_tilings
.clear();
879 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
880 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
882 host_impl_
.PinchGestureEnd();
884 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
887 SetContentsScaleOnBothLayers(1.2f
, device_scale
, page_scale
, 1.f
, false);
888 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
891 active_layer_
->tilings()->tiling_at(1)->contents_scale());
893 1.f
* low_res_factor
,
894 active_layer_
->tilings()->tiling_at(3)->contents_scale());
896 // Mark the non-ideal tilings as used. They won't be removed.
897 used_tilings
.clear();
898 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
899 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(3));
900 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
901 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
903 // Now move the ideal scale to 0.5. Our target stays 1.2.
904 SetContentsScaleOnBothLayers(0.5f
, device_scale
, page_scale
, 1.f
, false);
906 // The high resolution tiling is between target and ideal, so is not
907 // removed. The low res tiling for the old ideal=1.0 scale is removed.
908 used_tilings
.clear();
909 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
910 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
912 // Now move the ideal scale to 1.0. Our target stays 1.2.
913 SetContentsScaleOnBothLayers(1.f
, device_scale
, page_scale
, 1.f
, false);
915 // All the tilings are between are target and the ideal, so they are not
917 used_tilings
.clear();
918 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
919 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
921 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
922 SetupDrawPropertiesAndUpdateTiles(
923 active_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
925 // Because the pending layer's ideal scale is still 1.0, our tilings fall
926 // in the range [1.0,1.2] and are kept.
927 used_tilings
.clear();
928 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
929 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
931 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
933 SetupDrawPropertiesAndUpdateTiles(
934 pending_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
936 // Our 1.0 tiling now falls outside the range between our ideal scale and our
937 // target raster scale. But it is in our used tilings set, so nothing is
939 used_tilings
.clear();
940 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
941 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
942 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
944 // If we remove it from our used tilings set, it is outside the range to keep
946 used_tilings
.clear();
947 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
948 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
951 #define EXPECT_BOTH_EQ(expression, x) \
953 EXPECT_EQ(x, pending_layer_->expression); \
954 EXPECT_EQ(x, active_layer_->expression); \
957 TEST_F(PictureLayerImplTest
, DontAddLowResDuringAnimation
) {
958 // Make sure this layer covers multiple tiles, since otherwise low
959 // res won't get created because it is too small.
960 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
961 SetupDefaultTrees(gfx::Size(tile_size
.width() + 1, tile_size
.height() + 1));
962 // Avoid max untiled layer size heuristics via fixed tile size.
963 pending_layer_
->set_fixed_tile_size(tile_size
);
964 active_layer_
->set_fixed_tile_size(tile_size
);
966 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
967 float contents_scale
= 1.f
;
968 float device_scale
= 1.f
;
969 float page_scale
= 1.f
;
970 float maximum_animation_scale
= 1.f
;
971 bool animating_transform
= true;
973 // Animating, so don't create low res even if there isn't one already.
974 SetContentsScaleOnBothLayers(contents_scale
,
977 maximum_animation_scale
,
978 animating_transform
);
979 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
980 EXPECT_BOTH_EQ(num_tilings(), 1u);
982 // Stop animating, low res gets created.
983 animating_transform
= false;
984 SetContentsScaleOnBothLayers(contents_scale
,
987 maximum_animation_scale
,
988 animating_transform
);
989 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
990 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor
);
991 EXPECT_BOTH_EQ(num_tilings(), 2u);
993 // Page scale animation, new high res, but not new low res because animating.
994 contents_scale
= 2.f
;
996 animating_transform
= true;
997 SetContentsScaleOnBothLayers(contents_scale
,
1000 maximum_animation_scale
,
1001 animating_transform
);
1002 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1003 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor
);
1004 EXPECT_BOTH_EQ(num_tilings(), 3u);
1006 // Stop animating, new low res gets created for final page scale.
1007 animating_transform
= false;
1008 SetContentsScaleOnBothLayers(contents_scale
,
1011 maximum_animation_scale
,
1012 animating_transform
);
1013 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1014 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f
* low_res_factor
);
1015 EXPECT_BOTH_EQ(num_tilings(), 4u);
1018 TEST_F(PictureLayerImplTest
, DontAddLowResForSmallLayers
) {
1019 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1020 SetupDefaultTrees(tile_size
);
1022 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1023 float device_scale
= 1.f
;
1024 float page_scale
= 1.f
;
1025 float maximum_animation_scale
= 1.f
;
1026 bool animating_transform
= false;
1028 // Contents exactly fit on one tile at scale 1, no low res.
1029 float contents_scale
= 1.f
;
1030 SetContentsScaleOnBothLayers(contents_scale
,
1033 maximum_animation_scale
,
1034 animating_transform
);
1035 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1036 EXPECT_BOTH_EQ(num_tilings(), 1u);
1038 ResetTilingsAndRasterScales();
1040 // Contents that are smaller than one tile, no low res.
1041 contents_scale
= 0.123f
;
1042 SetContentsScaleOnBothLayers(contents_scale
,
1045 maximum_animation_scale
,
1046 animating_transform
);
1047 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1048 EXPECT_BOTH_EQ(num_tilings(), 1u);
1050 ResetTilingsAndRasterScales();
1052 // Any content bounds that would create more than one tile will
1053 // generate a low res tiling.
1054 contents_scale
= 2.5f
;
1055 SetContentsScaleOnBothLayers(contents_scale
,
1058 maximum_animation_scale
,
1059 animating_transform
);
1060 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1061 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1062 contents_scale
* low_res_factor
);
1063 EXPECT_BOTH_EQ(num_tilings(), 2u);
1065 ResetTilingsAndRasterScales();
1067 // Mask layers dont create low res since they always fit on one tile.
1068 pending_layer_
->SetIsMask(true);
1069 active_layer_
->SetIsMask(true);
1070 SetContentsScaleOnBothLayers(contents_scale
,
1073 maximum_animation_scale
,
1074 animating_transform
);
1075 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1076 EXPECT_BOTH_EQ(num_tilings(), 1u);
1079 TEST_F(PictureLayerImplTest
, ReleaseResources
) {
1080 gfx::Size
tile_size(400, 400);
1081 gfx::Size
layer_bounds(1300, 1900);
1083 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1084 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1085 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1086 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1088 SetupTrees(pending_pile
, active_pile
);
1089 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1091 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
1092 1.3f
, // ideal contents scale
1093 2.7f
, // device scale
1095 1.f
, // maximum animation scale
1097 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1099 // All tilings should be removed when losing output surface.
1100 active_layer_
->ReleaseResources();
1101 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1102 pending_layer_
->ReleaseResources();
1103 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1105 // This should create new tilings.
1106 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
1107 1.3f
, // ideal contents scale
1108 2.7f
, // device scale
1110 1.f
, // maximum animation scale
1112 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1115 TEST_F(PictureLayerImplTest
, ClampTilesToToMaxTileSize
) {
1116 // The default max tile size is larger than 400x400.
1117 gfx::Size
tile_size(400, 400);
1118 gfx::Size
layer_bounds(5000, 5000);
1120 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1121 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1122 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1123 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1125 SetupTrees(pending_pile
, active_pile
);
1126 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1128 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1129 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1131 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1133 // The default value.
1134 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1135 host_impl_
.settings().default_tile_size
.ToString());
1137 Tile
* tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1138 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1139 tile
->content_rect().size().ToString());
1141 pending_layer_
->ReleaseResources();
1143 // Change the max texture size on the output surface context.
1144 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1145 TestWebGraphicsContext3D::Create();
1146 context
->set_max_texture_size(140);
1147 host_impl_
.DidLoseOutputSurface();
1148 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d(
1149 context
.Pass()).PassAs
<OutputSurface
>());
1151 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1152 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1154 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1156 // Verify the tiles are not larger than the context's max texture size.
1157 tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1158 EXPECT_GE(140, tile
->content_rect().width());
1159 EXPECT_GE(140, tile
->content_rect().height());
1162 TEST_F(PictureLayerImplTest
, ClampSingleTileToToMaxTileSize
) {
1163 // The default max tile size is larger than 400x400.
1164 gfx::Size
tile_size(400, 400);
1165 gfx::Size
layer_bounds(500, 500);
1167 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1168 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1169 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1170 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1172 SetupTrees(pending_pile
, active_pile
);
1173 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1175 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1176 ASSERT_LE(1u, pending_layer_
->tilings()->num_tilings());
1178 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1180 // The default value. The layer is smaller than this.
1181 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1182 host_impl_
.settings().max_untiled_layer_size
.ToString());
1184 // There should be a single tile since the layer is small.
1185 PictureLayerTiling
* high_res_tiling
= pending_layer_
->tilings()->tiling_at(0);
1186 EXPECT_EQ(1u, high_res_tiling
->AllTilesForTesting().size());
1188 pending_layer_
->ReleaseResources();
1190 // Change the max texture size on the output surface context.
1191 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1192 TestWebGraphicsContext3D::Create();
1193 context
->set_max_texture_size(140);
1194 host_impl_
.DidLoseOutputSurface();
1195 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d(
1196 context
.Pass()).PassAs
<OutputSurface
>());
1198 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1199 ASSERT_LE(1u, pending_layer_
->tilings()->num_tilings());
1201 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1203 // There should be more than one tile since the max texture size won't cover
1205 high_res_tiling
= pending_layer_
->tilings()->tiling_at(0);
1206 EXPECT_LT(1u, high_res_tiling
->AllTilesForTesting().size());
1208 // Verify the tiles are not larger than the context's max texture size.
1209 Tile
* tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1210 EXPECT_GE(140, tile
->content_rect().width());
1211 EXPECT_GE(140, tile
->content_rect().height());
1214 TEST_F(PictureLayerImplTest
, DisallowTileDrawQuads
) {
1215 MockOcclusionTracker
<LayerImpl
> occlusion_tracker
;
1216 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1218 gfx::Size
tile_size(400, 400);
1219 gfx::Size
layer_bounds(1300, 1900);
1221 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1222 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1223 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1224 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1226 SetupTrees(pending_pile
, active_pile
);
1228 active_layer_
->draw_properties().visible_content_rect
=
1229 gfx::Rect(layer_bounds
);
1231 gfx::Rect
layer_invalidation(150, 200, 30, 180);
1232 Region
invalidation(layer_invalidation
);
1233 AddDefaultTilingsWithInvalidation(invalidation
);
1235 AppendQuadsData data
;
1236 active_layer_
->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE
, NULL
);
1237 active_layer_
->AppendQuads(render_pass
.get(), occlusion_tracker
, &data
);
1238 active_layer_
->DidDraw(NULL
);
1240 ASSERT_EQ(1U, render_pass
->quad_list
.size());
1241 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
, render_pass
->quad_list
[0]->material
);
1244 TEST_F(PictureLayerImplTest
, MarkRequiredNullTiles
) {
1245 gfx::Size
tile_size(100, 100);
1246 gfx::Size
layer_bounds(1000, 1000);
1248 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1249 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
1250 // Layers with entirely empty piles can't get tilings.
1251 pending_pile
->AddRecordingAt(0, 0);
1253 SetupPendingTree(pending_pile
);
1255 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
1256 pending_layer_
->AddTiling(1.0f
);
1257 pending_layer_
->AddTiling(2.0f
);
1259 // It should be safe to call this (and MarkVisibleResourcesAsRequired)
1260 // on a layer with no recordings.
1261 host_impl_
.pending_tree()->UpdateDrawProperties();
1262 pending_layer_
->MarkVisibleResourcesAsRequired();
1265 TEST_F(PictureLayerImplTest
, MarkRequiredOffscreenTiles
) {
1266 gfx::Size
tile_size(100, 100);
1267 gfx::Size
layer_bounds(200, 200);
1269 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1270 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1271 SetupPendingTree(pending_pile
);
1273 pending_layer_
->set_fixed_tile_size(tile_size
);
1274 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
1275 PictureLayerTiling
* tiling
= pending_layer_
->AddTiling(1.f
);
1276 host_impl_
.pending_tree()->UpdateDrawProperties();
1277 EXPECT_EQ(tiling
->resolution(), HIGH_RESOLUTION
);
1279 pending_layer_
->draw_properties().visible_content_rect
=
1280 gfx::Rect(0, 0, 100, 200);
1282 // Fake set priorities.
1283 for (PictureLayerTiling::CoverageIterator
iter(
1284 tiling
, pending_layer_
->contents_scale_x(), gfx::Rect(layer_bounds
));
1290 TilePriority priority
;
1291 priority
.resolution
= HIGH_RESOLUTION
;
1292 gfx::Rect tile_bounds
= iter
.geometry_rect();
1293 if (pending_layer_
->visible_content_rect().Intersects(tile_bounds
)) {
1294 priority
.priority_bin
= TilePriority::NOW
;
1295 priority
.distance_to_visible
= 0.f
;
1297 priority
.priority_bin
= TilePriority::SOON
;
1298 priority
.distance_to_visible
= 1.f
;
1300 tile
->SetPriority(PENDING_TREE
, priority
);
1303 pending_layer_
->MarkVisibleResourcesAsRequired();
1305 int num_visible
= 0;
1306 int num_offscreen
= 0;
1308 for (PictureLayerTiling::CoverageIterator
iter(
1309 tiling
, pending_layer_
->contents_scale_x(), gfx::Rect(layer_bounds
));
1314 const Tile
* tile
= *iter
;
1315 if (tile
->priority(PENDING_TREE
).distance_to_visible
== 0.f
) {
1316 EXPECT_TRUE(tile
->required_for_activation());
1319 EXPECT_FALSE(tile
->required_for_activation());
1324 EXPECT_GT(num_visible
, 0);
1325 EXPECT_GT(num_offscreen
, 0);
1328 TEST_F(PictureLayerImplTest
, HighResRequiredWhenUnsharedActiveAllReady
) {
1329 gfx::Size
layer_bounds(400, 400);
1330 gfx::Size
tile_size(100, 100);
1331 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
1334 pending_layer_
->set_invalidation(gfx::Rect(layer_bounds
));
1336 CreateHighLowResAndSetAllTilesVisible();
1338 active_layer_
->SetAllTilesReady();
1340 // No shared tiles and all active tiles ready, so pending can only
1341 // activate with all high res tiles.
1342 pending_layer_
->MarkVisibleResourcesAsRequired();
1343 AssertAllTilesRequired(pending_layer_
->HighResTiling());
1344 AssertNoTilesRequired(pending_layer_
->LowResTiling());
1347 TEST_F(PictureLayerImplTest
, HighResRequiredWhenMissingHighResFlagOn
) {
1348 gfx::Size
layer_bounds(400, 400);
1349 gfx::Size
tile_size(100, 100);
1350 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
1352 // All tiles shared (no invalidation).
1353 CreateHighLowResAndSetAllTilesVisible();
1355 // Verify active tree not ready.
1356 Tile
* some_active_tile
=
1357 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
1358 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
1360 // When high res are required, even if the active tree is not ready,
1361 // the high res tiles must be ready.
1362 host_impl_
.active_tree()->SetRequiresHighResToDraw();
1363 pending_layer_
->MarkVisibleResourcesAsRequired();
1364 AssertAllTilesRequired(pending_layer_
->HighResTiling());
1365 AssertNoTilesRequired(pending_layer_
->LowResTiling());
1368 TEST_F(PictureLayerImplTest
, NothingRequiredIfAllHighResTilesShared
) {
1369 gfx::Size
layer_bounds(400, 400);
1370 gfx::Size
tile_size(100, 100);
1371 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
1373 CreateHighLowResAndSetAllTilesVisible();
1375 Tile
* some_active_tile
=
1376 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
1377 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
1379 // All tiles shared (no invalidation), so even though the active tree's
1380 // tiles aren't ready, there is nothing required.
1381 pending_layer_
->MarkVisibleResourcesAsRequired();
1382 AssertNoTilesRequired(pending_layer_
->HighResTiling());
1383 AssertNoTilesRequired(pending_layer_
->LowResTiling());
1386 TEST_F(PictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
1387 gfx::Size
layer_bounds(400, 400);
1388 gfx::Size
tile_size(100, 100);
1389 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1390 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1391 // This pile will create tilings, but has no recordings so will not create any
1392 // tiles. This is attempting to simulate scrolling past the end of recorded
1393 // content on the active layer, where the recordings are so far away that
1394 // no tiles are created.
1395 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1396 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1397 tile_size
, layer_bounds
);
1398 SetupTrees(pending_pile
, active_pile
);
1399 pending_layer_
->set_fixed_tile_size(tile_size
);
1400 active_layer_
->set_fixed_tile_size(tile_size
);
1402 CreateHighLowResAndSetAllTilesVisible();
1404 // Active layer has tilings, but no tiles due to missing recordings.
1405 EXPECT_TRUE(active_layer_
->CanHaveTilings());
1406 EXPECT_EQ(active_layer_
->tilings()->num_tilings(), 2u);
1407 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
1409 // Since the active layer has no tiles at all, the pending layer doesn't
1410 // need content in order to activate.
1411 pending_layer_
->MarkVisibleResourcesAsRequired();
1412 AssertNoTilesRequired(pending_layer_
->HighResTiling());
1413 AssertNoTilesRequired(pending_layer_
->LowResTiling());
1416 TEST_F(PictureLayerImplTest
, HighResRequiredIfActiveCantHaveTiles
) {
1417 gfx::Size
layer_bounds(400, 400);
1418 gfx::Size
tile_size(100, 100);
1419 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1420 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1421 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1422 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
1423 SetupTrees(pending_pile
, active_pile
);
1424 pending_layer_
->set_fixed_tile_size(tile_size
);
1425 active_layer_
->set_fixed_tile_size(tile_size
);
1427 CreateHighLowResAndSetAllTilesVisible();
1429 // Active layer can't have tiles.
1430 EXPECT_FALSE(active_layer_
->CanHaveTilings());
1432 // All high res tiles required. This should be considered identical
1433 // to the case where there is no active layer, to avoid flashing content.
1434 // This can happen if a layer exists for a while and switches from
1435 // not being able to have content to having content.
1436 pending_layer_
->MarkVisibleResourcesAsRequired();
1437 AssertAllTilesRequired(pending_layer_
->HighResTiling());
1438 AssertNoTilesRequired(pending_layer_
->LowResTiling());
1441 TEST_F(PictureLayerImplTest
, HighResRequiredWhenActiveHasDifferentBounds
) {
1442 gfx::Size
layer_bounds(200, 200);
1443 gfx::Size
tile_size(100, 100);
1444 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
1446 gfx::Size
pending_layer_bounds(400, 400);
1447 pending_layer_
->SetBounds(pending_layer_bounds
);
1449 CreateHighLowResAndSetAllTilesVisible();
1451 active_layer_
->SetAllTilesReady();
1453 // Since the active layer has different bounds, the pending layer needs all
1454 // high res tiles in order to activate.
1455 pending_layer_
->MarkVisibleResourcesAsRequired();
1456 AssertAllTilesRequired(pending_layer_
->HighResTiling());
1457 AssertNoTilesRequired(pending_layer_
->LowResTiling());
1460 TEST_F(PictureLayerImplTest
, ActivateUninitializedLayer
) {
1461 gfx::Size
tile_size(100, 100);
1462 gfx::Size
layer_bounds(400, 400);
1463 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1464 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1466 host_impl_
.CreatePendingTree();
1467 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
1469 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
1470 FakePictureLayerImpl::CreateWithPile(pending_tree
, id_
, pending_pile
);
1471 pending_layer
->SetDrawsContent(true);
1472 pending_tree
->SetRootLayer(pending_layer
.PassAs
<LayerImpl
>());
1474 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
1475 host_impl_
.pending_tree()->LayerById(id_
));
1477 // Set some state on the pending layer, make sure it is not clobbered
1478 // by a sync from the active layer. This could happen because if the
1479 // pending layer has not been post-commit initialized it will attempt
1480 // to sync from the active layer.
1481 float raster_page_scale
= 10.f
* pending_layer_
->raster_page_scale();
1482 pending_layer_
->set_raster_page_scale(raster_page_scale
);
1483 EXPECT_TRUE(pending_layer_
->needs_post_commit_initialization());
1485 host_impl_
.ActivateSyncTree();
1487 active_layer_
= static_cast<FakePictureLayerImpl
*>(
1488 host_impl_
.active_tree()->LayerById(id_
));
1490 EXPECT_EQ(0u, active_layer_
->num_tilings());
1491 EXPECT_EQ(raster_page_scale
, active_layer_
->raster_page_scale());
1492 EXPECT_FALSE(active_layer_
->needs_post_commit_initialization());
1495 TEST_F(PictureLayerImplTest
, RemoveInvalidTilesOnActivation
) {
1496 SetupDefaultTrees(gfx::Size(1500, 1500));
1497 AddDefaultTilingsWithInvalidation(gfx::Rect(0, 0, 1, 1));
1499 FakePictureLayerImpl
* recycled_layer
= pending_layer_
;
1500 host_impl_
.ActivateSyncTree();
1502 active_layer_
= static_cast<FakePictureLayerImpl
*>(
1503 host_impl_
.active_tree()->LayerById(id_
));
1505 EXPECT_EQ(3u, active_layer_
->num_tilings());
1506 EXPECT_EQ(3u, recycled_layer
->num_tilings());
1507 EXPECT_FALSE(host_impl_
.pending_tree());
1508 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
1509 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(i
);
1510 PictureLayerTiling
* recycled_tiling
=
1511 recycled_layer
->tilings()->tiling_at(i
);
1513 ASSERT_TRUE(active_tiling
);
1514 ASSERT_TRUE(recycled_tiling
);
1516 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1517 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
1518 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
1519 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
1521 EXPECT_FALSE(recycled_tiling
->TileAt(0, 0));
1522 EXPECT_TRUE(recycled_tiling
->TileAt(1, 0));
1523 EXPECT_TRUE(recycled_tiling
->TileAt(0, 1));
1524 EXPECT_TRUE(recycled_tiling
->TileAt(1, 1));
1526 EXPECT_EQ(active_tiling
->TileAt(1, 0), recycled_tiling
->TileAt(1, 0));
1527 EXPECT_EQ(active_tiling
->TileAt(0, 1), recycled_tiling
->TileAt(0, 1));
1528 EXPECT_EQ(active_tiling
->TileAt(1, 1), recycled_tiling
->TileAt(1, 1));
1532 TEST_F(PictureLayerImplTest
, SyncTilingAfterReleaseResource
) {
1533 SetupDefaultTrees(gfx::Size(10, 10));
1534 host_impl_
.active_tree()->UpdateDrawProperties();
1535 EXPECT_FALSE(host_impl_
.active_tree()->needs_update_draw_properties());
1537 // Contrived unit test of a real crash. A layer is transparent during a
1538 // context loss, and later becomes opaque, causing active layer SyncTiling to
1540 float new_scale
= 1.f
;
1541 active_layer_
->ReleaseResources();
1542 pending_layer_
->ReleaseResources();
1543 EXPECT_FALSE(active_layer_
->tilings()->TilingAtScale(new_scale
));
1544 pending_layer_
->AddTiling(new_scale
);
1545 EXPECT_TRUE(active_layer_
->tilings()->TilingAtScale(new_scale
));
1547 // UpdateDrawProperties early-outs if the tree doesn't need it. It is also
1548 // responsible for calling ManageTilings. These checks verify that
1549 // ReleaseResources has set needs update draw properties so that the
1550 // new tiling gets the appropriate resolution set in ManageTilings.
1551 EXPECT_TRUE(host_impl_
.active_tree()->needs_update_draw_properties());
1552 host_impl_
.active_tree()->UpdateDrawProperties();
1553 PictureLayerTiling
* high_res
=
1554 active_layer_
->tilings()->TilingAtScale(new_scale
);
1555 ASSERT_TRUE(!!high_res
);
1556 EXPECT_EQ(HIGH_RESOLUTION
, high_res
->resolution());
1559 TEST_F(PictureLayerImplTest
, SyncTilingAfterGpuRasterizationToggles
) {
1560 SetupDefaultTrees(gfx::Size(10, 10));
1562 const float kScale
= 1.f
;
1563 pending_layer_
->AddTiling(kScale
);
1564 EXPECT_TRUE(pending_layer_
->tilings()->TilingAtScale(kScale
));
1565 EXPECT_TRUE(active_layer_
->tilings()->TilingAtScale(kScale
));
1567 // Gpu rasterization is disabled by default.
1568 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
1569 // Toggling the gpu rasterization clears all tilings on both trees.
1570 host_impl_
.SetUseGpuRasterization(true);
1571 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1572 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1574 // Make sure that we can still add tiling to the pending layer,
1575 // that gets synced to the active layer.
1576 pending_layer_
->AddTiling(kScale
);
1577 EXPECT_TRUE(pending_layer_
->tilings()->TilingAtScale(kScale
));
1578 EXPECT_TRUE(active_layer_
->tilings()->TilingAtScale(kScale
));
1580 // Toggling the gpu rasterization clears all tilings on both trees.
1581 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
1582 host_impl_
.SetUseGpuRasterization(false);
1583 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1584 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1587 TEST_F(PictureLayerImplTest
, HighResCreatedWhenBoundsShrink
) {
1588 SetupDefaultTrees(gfx::Size(10, 10));
1589 host_impl_
.active_tree()->UpdateDrawProperties();
1590 EXPECT_FALSE(host_impl_
.active_tree()->needs_update_draw_properties());
1592 SetupDrawPropertiesAndUpdateTiles(
1593 active_layer_
, 0.5f
, 0.5f
, 0.5f
, 0.5f
, false);
1594 active_layer_
->tilings()->RemoveAllTilings();
1595 PictureLayerTiling
* tiling
= active_layer_
->tilings()->AddTiling(0.5f
);
1596 active_layer_
->tilings()->AddTiling(1.5f
);
1597 active_layer_
->tilings()->AddTiling(0.25f
);
1598 tiling
->set_resolution(HIGH_RESOLUTION
);
1601 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1602 ASSERT_EQ(tiling
, active_layer_
->tilings()->TilingAtScale(0.5f
));
1604 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes
1605 // 1.0f). Note that we should also ensure that the pending layer needs post
1606 // commit initialization, since this is what would happen during commit. In
1607 // other words we want the pending layer to sync from the active layer.
1608 pending_layer_
->SetBounds(gfx::Size(1, 1));
1609 pending_layer_
->SetNeedsPostCommitInitialization();
1610 pending_layer_
->set_twin_layer(NULL
);
1611 active_layer_
->set_twin_layer(NULL
);
1612 EXPECT_TRUE(pending_layer_
->needs_post_commit_initialization());
1614 // Update the draw properties: sync from active tree should happen here.
1615 host_impl_
.pending_tree()->UpdateDrawProperties();
1617 // Another sanity check.
1618 ASSERT_EQ(1.f
, pending_layer_
->MinimumContentsScale());
1620 // Now we should've synced 1.5f tiling, since that's the only one that doesn't
1621 // violate minimum contents scale. At the same time, we should've created a
1622 // new high res tiling at scale 1.0f.
1623 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1624 ASSERT_TRUE(pending_layer_
->tilings()->TilingAtScale(1.0f
));
1625 EXPECT_EQ(HIGH_RESOLUTION
,
1626 pending_layer_
->tilings()->TilingAtScale(1.0f
)->resolution());
1627 ASSERT_TRUE(pending_layer_
->tilings()->TilingAtScale(1.5f
));
1628 EXPECT_EQ(NON_IDEAL_RESOLUTION
,
1629 pending_layer_
->tilings()->TilingAtScale(1.5f
)->resolution());
1632 TEST_F(PictureLayerImplTest
, NoLowResTilingWithGpuRasterization
) {
1633 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
1634 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
1635 default_tile_size
.height() * 4);
1637 SetupDefaultTrees(layer_bounds
);
1638 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
1639 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1640 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1641 // Should have a low-res and a high-res tiling.
1642 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1644 ResetTilingsAndRasterScales();
1646 host_impl_
.SetUseGpuRasterization(true);
1647 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
1648 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1650 // Should only have the high-res tiling.
1651 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
1654 TEST_F(PictureLayerImplTest
, NoTilingIfDoesNotDrawContent
) {
1655 // Set up layers with tilings.
1656 SetupDefaultTrees(gfx::Size(10, 10));
1657 SetContentsScaleOnBothLayers(1.f
, 1.f
, 1.f
, 1.f
, false);
1658 pending_layer_
->PushPropertiesTo(active_layer_
);
1659 EXPECT_TRUE(pending_layer_
->DrawsContent());
1660 EXPECT_TRUE(pending_layer_
->CanHaveTilings());
1661 EXPECT_GE(pending_layer_
->num_tilings(), 0u);
1662 EXPECT_GE(active_layer_
->num_tilings(), 0u);
1664 // Set content to false, which should make CanHaveTilings return false.
1665 pending_layer_
->SetDrawsContent(false);
1666 EXPECT_FALSE(pending_layer_
->DrawsContent());
1667 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
1669 // No tilings should be pushed to active layer.
1670 pending_layer_
->PushPropertiesTo(active_layer_
);
1671 EXPECT_EQ(0u, active_layer_
->num_tilings());
1674 TEST_F(PictureLayerImplTest
, FirstTilingDuringPinch
) {
1675 SetupDefaultTrees(gfx::Size(10, 10));
1676 host_impl_
.PinchGestureBegin();
1677 float high_res_scale
= 2.3f
;
1678 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, 1.f
, 1.f
, false);
1680 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
1681 EXPECT_FLOAT_EQ(high_res_scale
,
1682 pending_layer_
->HighResTiling()->contents_scale());
1685 TEST_F(PictureLayerImplTest
, FirstTilingTooSmall
) {
1686 SetupDefaultTrees(gfx::Size(10, 10));
1687 host_impl_
.PinchGestureBegin();
1688 float high_res_scale
= 0.0001f
;
1689 EXPECT_GT(pending_layer_
->MinimumContentsScale(), high_res_scale
);
1691 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, 1.f
, 1.f
, false);
1693 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
1694 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
1695 pending_layer_
->HighResTiling()->contents_scale());
1698 TEST_F(PictureLayerImplTest
, PinchingTooSmall
) {
1699 SetupDefaultTrees(gfx::Size(10, 10));
1701 float contents_scale
= 0.15f
;
1702 SetContentsScaleOnBothLayers(contents_scale
, 1.f
, 1.f
, 1.f
, false);
1704 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
1705 EXPECT_FLOAT_EQ(contents_scale
,
1706 pending_layer_
->HighResTiling()->contents_scale());
1708 host_impl_
.PinchGestureBegin();
1710 float page_scale
= 0.0001f
;
1711 EXPECT_LT(page_scale
* contents_scale
,
1712 pending_layer_
->MinimumContentsScale());
1714 SetContentsScaleOnBothLayers(contents_scale
, 1.f
, page_scale
, 1.f
, false);
1715 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
1716 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
1717 pending_layer_
->HighResTiling()->contents_scale());
1720 class DeferredInitPictureLayerImplTest
: public PictureLayerImplTest
{
1722 virtual void InitializeRenderer() OVERRIDE
{
1723 bool delegated_rendering
= false;
1724 host_impl_
.InitializeRenderer(
1725 FakeOutputSurface::CreateDeferredGL(
1726 scoped_ptr
<SoftwareOutputDevice
>(new SoftwareOutputDevice
),
1727 delegated_rendering
).PassAs
<OutputSurface
>());
1730 virtual void SetUp() OVERRIDE
{
1731 PictureLayerImplTest::SetUp();
1733 // Create some default active and pending trees.
1734 gfx::Size
tile_size(100, 100);
1735 gfx::Size
layer_bounds(400, 400);
1737 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1738 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1739 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1740 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1742 SetupTrees(pending_pile
, active_pile
);
1746 // This test is really a LayerTreeHostImpl test, in that it makes sure
1747 // that trees need update draw properties after deferred initialization.
1748 // However, this is also a regression test for PictureLayerImpl in that
1749 // not having this update will cause a crash.
1750 TEST_F(DeferredInitPictureLayerImplTest
, PreventUpdateTilesDuringLostContext
) {
1751 host_impl_
.pending_tree()->UpdateDrawProperties();
1752 host_impl_
.active_tree()->UpdateDrawProperties();
1753 EXPECT_FALSE(host_impl_
.pending_tree()->needs_update_draw_properties());
1754 EXPECT_FALSE(host_impl_
.active_tree()->needs_update_draw_properties());
1756 FakeOutputSurface
* fake_output_surface
=
1757 static_cast<FakeOutputSurface
*>(host_impl_
.output_surface());
1758 ASSERT_TRUE(fake_output_surface
->InitializeAndSetContext3d(
1759 TestContextProvider::Create()));
1761 // These will crash PictureLayerImpl if this is not true.
1762 ASSERT_TRUE(host_impl_
.pending_tree()->needs_update_draw_properties());
1763 ASSERT_TRUE(host_impl_
.active_tree()->needs_update_draw_properties());
1764 host_impl_
.active_tree()->UpdateDrawProperties();
1767 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForCpuRasterization
) {
1768 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1769 SetupDefaultTrees(tile_size
);
1771 float contents_scale
= 1.f
;
1772 float device_scale
= 1.3f
;
1773 float page_scale
= 1.4f
;
1774 float maximum_animation_scale
= 1.f
;
1775 bool animating_transform
= false;
1777 SetContentsScaleOnBothLayers(contents_scale
,
1780 maximum_animation_scale
,
1781 animating_transform
);
1782 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1784 // Since we're CPU-rasterizing, starting an animation should cause tiling
1785 // resolution to get set to the maximum animation scale factor.
1786 animating_transform
= true;
1787 maximum_animation_scale
= 3.f
;
1788 contents_scale
= 2.f
;
1790 SetContentsScaleOnBothLayers(contents_scale
,
1793 maximum_animation_scale
,
1794 animating_transform
);
1795 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
1797 // Further changes to scale during the animation should not cause a new
1798 // high-res tiling to get created.
1799 contents_scale
= 4.f
;
1800 maximum_animation_scale
= 5.f
;
1802 SetContentsScaleOnBothLayers(contents_scale
,
1805 maximum_animation_scale
,
1806 animating_transform
);
1807 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
1809 // Once we stop animating, a new high-res tiling should be created.
1810 animating_transform
= false;
1812 SetContentsScaleOnBothLayers(contents_scale
,
1815 maximum_animation_scale
,
1816 animating_transform
);
1817 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
1819 // When animating with an unknown maximum animation scale factor, a new
1820 // high-res tiling should be created at the animation's initial scale.
1821 animating_transform
= true;
1822 contents_scale
= 2.f
;
1823 maximum_animation_scale
= 0.f
;
1825 SetContentsScaleOnBothLayers(contents_scale
,
1828 maximum_animation_scale
,
1829 animating_transform
);
1830 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1832 // Further changes to scale during the animation should not cause a new
1833 // high-res tiling to get created.
1834 contents_scale
= 3.f
;
1836 SetContentsScaleOnBothLayers(contents_scale
,
1839 maximum_animation_scale
,
1840 animating_transform
);
1841 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1843 // Once we stop animating, a new high-res tiling should be created.
1844 animating_transform
= false;
1845 contents_scale
= 4.f
;
1847 SetContentsScaleOnBothLayers(contents_scale
,
1850 maximum_animation_scale
,
1851 animating_transform
);
1852 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
1855 TEST_F(PictureLayerImplTest
, LayerRasterTileIterator
) {
1856 gfx::Size
tile_size(100, 100);
1857 gfx::Size
layer_bounds(1000, 1000);
1859 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1860 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1862 SetupPendingTree(pending_pile
);
1864 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
1866 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1869 PictureLayerImpl::LayerRasterTileIterator it
;
1873 it
= PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
1876 pending_layer_
->AddTiling(low_res_factor
);
1877 pending_layer_
->AddTiling(0.3f
);
1878 pending_layer_
->AddTiling(0.7f
);
1879 PictureLayerTiling
* high_res_tiling
= pending_layer_
->AddTiling(1.0f
);
1880 pending_layer_
->AddTiling(2.0f
);
1882 host_impl_
.SetViewportSize(gfx::Size(500, 500));
1883 host_impl_
.pending_tree()->UpdateDrawProperties();
1885 std::set
<Tile
*> unique_tiles
;
1886 bool reached_prepaint
= false;
1887 size_t non_ideal_tile_count
= 0u;
1888 size_t low_res_tile_count
= 0u;
1889 size_t high_res_tile_count
= 0u;
1890 for (it
= PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
1894 TilePriority priority
= tile
->priority(PENDING_TREE
);
1898 // Non-high res tiles only get visible tiles. Also, prepaint should only
1899 // come at the end of the iteration.
1900 if (priority
.resolution
!= HIGH_RESOLUTION
)
1901 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1902 else if (reached_prepaint
)
1903 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1905 reached_prepaint
= priority
.priority_bin
!= TilePriority::NOW
;
1907 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
1908 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
1909 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
1911 unique_tiles
.insert(tile
);
1914 EXPECT_TRUE(reached_prepaint
);
1915 EXPECT_EQ(0u, non_ideal_tile_count
);
1916 EXPECT_EQ(1u, low_res_tile_count
);
1917 EXPECT_EQ(16u, high_res_tile_count
);
1918 EXPECT_EQ(low_res_tile_count
+ high_res_tile_count
+ non_ideal_tile_count
,
1919 unique_tiles
.size());
1921 std::vector
<Tile
*> high_res_tiles
= high_res_tiling
->AllTilesForTesting();
1922 for (std::vector
<Tile
*>::iterator tile_it
= high_res_tiles
.begin();
1923 tile_it
!= high_res_tiles
.end();
1925 Tile
* tile
= *tile_it
;
1926 ManagedTileState::TileVersion
& tile_version
=
1927 tile
->GetTileVersionForTesting(
1928 tile
->DetermineRasterModeForTree(ACTIVE_TREE
));
1929 tile_version
.SetSolidColorForTesting(SK_ColorRED
);
1932 non_ideal_tile_count
= 0;
1933 low_res_tile_count
= 0;
1934 high_res_tile_count
= 0;
1935 for (it
= PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
1939 TilePriority priority
= tile
->priority(PENDING_TREE
);
1943 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
1944 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
1945 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
1948 EXPECT_EQ(0u, non_ideal_tile_count
);
1949 EXPECT_EQ(1u, low_res_tile_count
);
1950 EXPECT_EQ(0u, high_res_tile_count
);
1953 TEST_F(PictureLayerImplTest
, LayerEvictionTileIterator
) {
1954 gfx::Size
tile_size(100, 100);
1955 gfx::Size
layer_bounds(1000, 1000);
1957 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1958 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1960 SetupPendingTree(pending_pile
);
1962 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
1964 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1966 std::vector
<PictureLayerTiling
*> tilings
;
1967 tilings
.push_back(pending_layer_
->AddTiling(low_res_factor
));
1968 tilings
.push_back(pending_layer_
->AddTiling(0.3f
));
1969 tilings
.push_back(pending_layer_
->AddTiling(0.7f
));
1970 tilings
.push_back(pending_layer_
->AddTiling(1.0f
));
1971 tilings
.push_back(pending_layer_
->AddTiling(2.0f
));
1973 host_impl_
.SetViewportSize(gfx::Size(500, 500));
1974 host_impl_
.pending_tree()->UpdateDrawProperties();
1976 std::vector
<Tile
*> all_tiles
;
1977 for (std::vector
<PictureLayerTiling
*>::iterator tiling_iterator
=
1979 tiling_iterator
!= tilings
.end();
1980 ++tiling_iterator
) {
1981 std::vector
<Tile
*> tiles
= (*tiling_iterator
)->AllTilesForTesting();
1982 std::copy(tiles
.begin(), tiles
.end(), std::back_inserter(all_tiles
));
1985 std::set
<Tile
*> all_tiles_set(all_tiles
.begin(), all_tiles
.end());
1987 bool mark_required
= false;
1988 size_t number_of_marked_tiles
= 0u;
1989 size_t number_of_unmarked_tiles
= 0u;
1990 for (size_t i
= 0; i
< tilings
.size(); ++i
) {
1991 PictureLayerTiling
* tiling
= tilings
.at(i
);
1992 for (PictureLayerTiling::CoverageIterator
iter(
1994 pending_layer_
->contents_scale_x(),
1995 pending_layer_
->visible_content_rect());
1998 if (mark_required
) {
1999 number_of_marked_tiles
++;
2000 iter
->MarkRequiredForActivation();
2002 number_of_unmarked_tiles
++;
2004 mark_required
= !mark_required
;
2009 EXPECT_EQ(91u, all_tiles
.size());
2010 EXPECT_EQ(91u, all_tiles_set
.size());
2011 EXPECT_GT(number_of_marked_tiles
, 1u);
2012 EXPECT_GT(number_of_unmarked_tiles
, 1u);
2015 PictureLayerImpl::LayerEvictionTileIterator it
;
2018 // Tiles don't have resources yet.
2019 it
= PictureLayerImpl::LayerEvictionTileIterator(
2020 pending_layer_
, SAME_PRIORITY_FOR_BOTH_TREES
);
2023 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
2025 std::set
<Tile
*> unique_tiles
;
2026 float expected_scales
[] = {2.0f
, 0.3f
, 0.7f
, low_res_factor
, 1.0f
};
2027 size_t scale_index
= 0;
2028 bool reached_visible
= false;
2029 Tile
* last_tile
= NULL
;
2030 for (it
= PictureLayerImpl::LayerEvictionTileIterator(
2031 pending_layer_
, SAME_PRIORITY_FOR_BOTH_TREES
);
2040 TilePriority priority
= tile
->priority(PENDING_TREE
);
2042 if (priority
.priority_bin
== TilePriority::NOW
) {
2043 reached_visible
= true;
2048 EXPECT_FALSE(tile
->required_for_activation());
2050 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
2051 std::numeric_limits
<float>::epsilon()) {
2053 ASSERT_LT(scale_index
, arraysize(expected_scales
));
2056 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
2057 unique_tiles
.insert(tile
);
2059 // If the tile is the same rough bin as last tile (same activation, bin, and
2060 // scale), then distance should be decreasing.
2061 if (tile
->required_for_activation() ==
2062 last_tile
->required_for_activation() &&
2063 priority
.priority_bin
==
2064 last_tile
->priority(PENDING_TREE
).priority_bin
&&
2065 std::abs(tile
->contents_scale() - last_tile
->contents_scale()) <
2066 std::numeric_limits
<float>::epsilon()) {
2067 EXPECT_LE(priority
.distance_to_visible
,
2068 last_tile
->priority(PENDING_TREE
).distance_to_visible
);
2074 EXPECT_TRUE(reached_visible
);
2075 EXPECT_EQ(65u, unique_tiles
.size());
2078 bool reached_required
= false;
2083 TilePriority priority
= tile
->priority(PENDING_TREE
);
2084 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
2086 if (reached_required
) {
2087 EXPECT_TRUE(tile
->required_for_activation());
2088 } else if (tile
->required_for_activation()) {
2089 reached_required
= true;
2093 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
2094 std::numeric_limits
<float>::epsilon()) {
2096 ASSERT_LT(scale_index
, arraysize(expected_scales
));
2099 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
2100 unique_tiles
.insert(tile
);
2103 EXPECT_TRUE(reached_required
);
2104 EXPECT_EQ(all_tiles_set
.size(), unique_tiles
.size());
2107 TEST_F(PictureLayerImplTest
, Occlusion
) {
2108 gfx::Size
tile_size(102, 102);
2109 gfx::Size
layer_bounds(1000, 1000);
2110 gfx::Size
viewport_size(1000, 1000);
2112 LayerTestCommon::LayerImplTest impl
;
2114 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2115 FakePicturePileImpl::CreateFilledPile(layer_bounds
, layer_bounds
);
2116 SetupPendingTree(pending_pile
);
2117 pending_layer_
->SetBounds(layer_bounds
);
2119 active_layer_
->set_fixed_tile_size(tile_size
);
2121 host_impl_
.SetViewportSize(viewport_size
);
2122 host_impl_
.active_tree()->UpdateDrawProperties();
2124 std::vector
<Tile
*> tiles
=
2125 active_layer_
->HighResTiling()->AllTilesForTesting();
2126 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
2129 SCOPED_TRACE("No occlusion");
2131 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
2133 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
2134 gfx::Rect(layer_bounds
));
2135 EXPECT_EQ(100u, impl
.quad_list().size());
2139 SCOPED_TRACE("Full occlusion");
2140 gfx::Rect
occluded(active_layer_
->visible_content_rect());
2141 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
2143 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(), gfx::Rect());
2144 EXPECT_EQ(impl
.quad_list().size(), 0u);
2148 SCOPED_TRACE("Partial occlusion");
2149 gfx::Rect
occluded(150, 0, 200, 1000);
2150 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
2152 size_t partially_occluded_count
= 0;
2153 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion(
2155 gfx::Rect(layer_bounds
),
2157 &partially_occluded_count
);
2158 // The layer outputs one quad, which is partially occluded.
2159 EXPECT_EQ(100u - 10u, impl
.quad_list().size());
2160 EXPECT_EQ(10u + 10u, partially_occluded_count
);
2164 TEST_F(PictureLayerImplTest
, RasterScaleChangeWithoutAnimation
) {
2165 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
2166 SetupDefaultTrees(tile_size
);
2168 float contents_scale
= 2.f
;
2169 float device_scale
= 1.f
;
2170 float page_scale
= 1.f
;
2171 float maximum_animation_scale
= 1.f
;
2172 bool animating_transform
= false;
2174 SetContentsScaleOnBothLayers(contents_scale
,
2177 maximum_animation_scale
,
2178 animating_transform
);
2179 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2181 // Changing the source scale without being in an animation will cause
2182 // the layer to reset its source scale to 1.f.
2183 contents_scale
= 3.f
;
2185 SetContentsScaleOnBothLayers(contents_scale
,
2188 maximum_animation_scale
,
2189 animating_transform
);
2190 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2192 // Further changes to the source scale will no longer be reflected in the
2194 contents_scale
= 0.5f
;
2196 SetContentsScaleOnBothLayers(contents_scale
,
2199 maximum_animation_scale
,
2200 animating_transform
);
2201 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2204 TEST_F(PictureLayerImplTest
, LowResReadyToDrawNotEnoughToActivate
) {
2205 gfx::Size
tile_size(100, 100);
2206 gfx::Size
layer_bounds(1000, 1000);
2208 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
2210 // Make sure some tiles are not shared.
2211 pending_layer_
->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size
));
2213 CreateHighLowResAndSetAllTilesVisible();
2214 active_layer_
->SetAllTilesReady();
2215 pending_layer_
->MarkVisibleResourcesAsRequired();
2217 // All pending layer tiles required are not ready.
2218 EXPECT_FALSE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
2220 // Initialize all low-res tiles.
2221 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
2223 // Low-res tiles should not be enough.
2224 EXPECT_FALSE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
2226 // Initialize remaining tiles.
2227 pending_layer_
->SetAllTilesReady();
2229 EXPECT_TRUE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
2232 TEST_F(PictureLayerImplTest
, HighResReadyToDrawNotEnoughToActivate
) {
2233 gfx::Size
tile_size(100, 100);
2234 gfx::Size
layer_bounds(1000, 1000);
2236 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
2238 // Make sure some tiles are not shared.
2239 pending_layer_
->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size
));
2241 CreateHighLowResAndSetAllTilesVisible();
2242 active_layer_
->SetAllTilesReady();
2243 pending_layer_
->MarkVisibleResourcesAsRequired();
2245 // All pending layer tiles required are not ready.
2246 EXPECT_FALSE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
2248 // Initialize all high-res tiles.
2249 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
2251 // High-res tiles should not be enough.
2252 EXPECT_FALSE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
2254 // Initialize remaining tiles.
2255 pending_layer_
->SetAllTilesReady();
2257 EXPECT_TRUE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
2260 class NoLowResTilingsSettings
: public ImplSidePaintingSettings
{
2262 NoLowResTilingsSettings() { create_low_res_tiling
= false; }
2265 class NoLowResPictureLayerImplTest
: public PictureLayerImplTest
{
2267 NoLowResPictureLayerImplTest()
2268 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
2271 TEST_F(NoLowResPictureLayerImplTest
, ManageTilingsCreatesTilings
) {
2272 gfx::Size
tile_size(400, 400);
2273 gfx::Size
layer_bounds(1300, 1900);
2275 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2276 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2277 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2278 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2280 SetupTrees(pending_pile
, active_pile
);
2281 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2283 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
2284 EXPECT_LT(low_res_factor
, 1.f
);
2286 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
2287 6.f
, // ideal contents scale
2288 3.f
, // device scale
2290 1.f
, // maximum animation scale
2292 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2293 EXPECT_FLOAT_EQ(6.f
,
2294 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
2296 // If we change the page scale factor, then we should get new tilings.
2297 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
2298 6.6f
, // ideal contents scale
2299 3.f
, // device scale
2301 1.f
, // maximum animation scale
2303 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
2304 EXPECT_FLOAT_EQ(6.6f
,
2305 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
2307 // If we change the device scale factor, then we should get new tilings.
2308 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
2309 7.26f
, // ideal contents scale
2310 3.3f
, // device scale
2312 1.f
, // maximum animation scale
2314 ASSERT_EQ(3u, pending_layer_
->tilings()->num_tilings());
2315 EXPECT_FLOAT_EQ(7.26f
,
2316 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
2318 // If we change the device scale factor, but end up at the same total scale
2319 // factor somehow, then we don't get new tilings.
2320 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
2321 7.26f
, // ideal contents scale
2322 2.2f
, // device scale
2324 1.f
, // maximum animation scale
2326 ASSERT_EQ(3u, pending_layer_
->tilings()->num_tilings());
2327 EXPECT_FLOAT_EQ(7.26f
,
2328 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
2331 TEST_F(NoLowResPictureLayerImplTest
, MarkRequiredNullTiles
) {
2332 gfx::Size
tile_size(100, 100);
2333 gfx::Size
layer_bounds(1000, 1000);
2335 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2336 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
2337 // Layers with entirely empty piles can't get tilings.
2338 pending_pile
->AddRecordingAt(0, 0);
2340 SetupPendingTree(pending_pile
);
2342 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
2343 pending_layer_
->AddTiling(1.0f
);
2344 pending_layer_
->AddTiling(2.0f
);
2346 // It should be safe to call this (and MarkVisibleResourcesAsRequired)
2347 // on a layer with no recordings.
2348 host_impl_
.pending_tree()->UpdateDrawProperties();
2349 pending_layer_
->MarkVisibleResourcesAsRequired();
2352 TEST_F(NoLowResPictureLayerImplTest
, NothingRequiredIfAllHighResTilesShared
) {
2353 gfx::Size
layer_bounds(400, 400);
2354 gfx::Size
tile_size(100, 100);
2355 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
2357 CreateHighLowResAndSetAllTilesVisible();
2359 Tile
* some_active_tile
=
2360 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2361 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
2363 // All tiles shared (no invalidation), so even though the active tree's
2364 // tiles aren't ready, there is nothing required.
2365 pending_layer_
->MarkVisibleResourcesAsRequired();
2366 AssertNoTilesRequired(pending_layer_
->HighResTiling());
2367 if (host_impl_
.settings().create_low_res_tiling
) {
2368 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2372 TEST_F(NoLowResPictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
2373 gfx::Size
layer_bounds(400, 400);
2374 gfx::Size
tile_size(100, 100);
2375 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2376 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2377 // This pile will create tilings, but has no recordings so will not create any
2378 // tiles. This is attempting to simulate scrolling past the end of recorded
2379 // content on the active layer, where the recordings are so far away that
2380 // no tiles are created.
2381 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2382 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
2383 tile_size
, layer_bounds
);
2384 SetupTrees(pending_pile
, active_pile
);
2385 pending_layer_
->set_fixed_tile_size(tile_size
);
2386 active_layer_
->set_fixed_tile_size(tile_size
);
2388 CreateHighLowResAndSetAllTilesVisible();
2390 // Active layer has tilings, but no tiles due to missing recordings.
2391 EXPECT_TRUE(active_layer_
->CanHaveTilings());
2392 EXPECT_EQ(active_layer_
->tilings()->num_tilings(),
2393 host_impl_
.settings().create_low_res_tiling
? 2u : 1u);
2394 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
2396 // Since the active layer has no tiles at all, the pending layer doesn't
2397 // need content in order to activate.
2398 pending_layer_
->MarkVisibleResourcesAsRequired();
2399 AssertNoTilesRequired(pending_layer_
->HighResTiling());
2400 if (host_impl_
.settings().create_low_res_tiling
)
2401 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2404 TEST_F(NoLowResPictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
2405 base::TimeTicks time_ticks
;
2406 host_impl_
.SetCurrentFrameTimeTicks(time_ticks
);
2408 gfx::Size
tile_size(100, 100);
2409 gfx::Size
layer_bounds(400, 400);
2411 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2412 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2413 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2414 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2416 SetupTrees(pending_pile
, active_pile
);
2418 Region invalidation
;
2419 AddDefaultTilingsWithInvalidation(invalidation
);
2420 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
2422 // UpdateTiles with valid viewport. Should update tile viewport.
2423 // Note viewport is considered invalid if and only if in resourceless
2425 bool resourceless_software_draw
= false;
2426 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
2427 gfx::Transform transform
;
2428 host_impl_
.SetExternalDrawConstraints(
2429 transform
, viewport
, viewport
, resourceless_software_draw
);
2430 active_layer_
->draw_properties().visible_content_rect
= viewport
;
2431 active_layer_
->draw_properties().screen_space_transform
= transform
;
2432 active_layer_
->UpdateTiles(NULL
);
2434 gfx::Rect visible_rect_for_tile_priority
=
2435 active_layer_
->visible_rect_for_tile_priority();
2436 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
2437 gfx::Size viewport_size_for_tile_priority
=
2438 active_layer_
->viewport_size_for_tile_priority();
2439 EXPECT_FALSE(viewport_size_for_tile_priority
.IsEmpty());
2440 gfx::Transform screen_space_transform_for_tile_priority
=
2441 active_layer_
->screen_space_transform_for_tile_priority();
2443 // Expand viewport and set it as invalid for prioritizing tiles.
2444 // Should not update tile viewport.
2445 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
2446 host_impl_
.SetCurrentFrameTimeTicks(time_ticks
);
2447 resourceless_software_draw
= true;
2448 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
2449 transform
.Translate(1.f
, 1.f
);
2450 active_layer_
->draw_properties().visible_content_rect
= viewport
;
2451 active_layer_
->draw_properties().screen_space_transform
= transform
;
2452 host_impl_
.SetExternalDrawConstraints(
2453 transform
, viewport
, viewport
, resourceless_software_draw
);
2454 active_layer_
->UpdateTiles(NULL
);
2456 EXPECT_RECT_EQ(visible_rect_for_tile_priority
,
2457 active_layer_
->visible_rect_for_tile_priority());
2458 EXPECT_SIZE_EQ(viewport_size_for_tile_priority
,
2459 active_layer_
->viewport_size_for_tile_priority());
2460 EXPECT_TRANSFORMATION_MATRIX_EQ(
2461 screen_space_transform_for_tile_priority
,
2462 active_layer_
->screen_space_transform_for_tile_priority());
2464 // Keep expanded viewport but mark it valid. Should update tile viewport.
2465 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
2466 host_impl_
.SetCurrentFrameTimeTicks(time_ticks
);
2467 resourceless_software_draw
= false;
2468 host_impl_
.SetExternalDrawConstraints(
2469 transform
, viewport
, viewport
, resourceless_software_draw
);
2470 active_layer_
->UpdateTiles(NULL
);
2472 EXPECT_FALSE(visible_rect_for_tile_priority
==
2473 active_layer_
->visible_rect_for_tile_priority());
2474 EXPECT_FALSE(viewport_size_for_tile_priority
==
2475 active_layer_
->viewport_size_for_tile_priority());
2476 EXPECT_FALSE(screen_space_transform_for_tile_priority
==
2477 active_layer_
->screen_space_transform_for_tile_priority());
2480 TEST_F(NoLowResPictureLayerImplTest
, InvalidViewportAfterReleaseResources
) {
2481 base::TimeTicks time_ticks
;
2482 host_impl_
.SetCurrentFrameTimeTicks(time_ticks
);
2484 gfx::Size
tile_size(100, 100);
2485 gfx::Size
layer_bounds(400, 400);
2487 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2488 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2489 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2490 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2492 SetupTrees(pending_pile
, active_pile
);
2494 Region invalidation
;
2495 AddDefaultTilingsWithInvalidation(invalidation
);
2497 bool resourceless_software_draw
= true;
2498 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
2499 host_impl_
.SetExternalDrawConstraints(
2500 gfx::Transform(), viewport
, viewport
, resourceless_software_draw
);
2501 ResetTilingsAndRasterScales();
2502 host_impl_
.pending_tree()->UpdateDrawProperties();
2503 host_impl_
.active_tree()->UpdateDrawProperties();
2504 EXPECT_TRUE(active_layer_
->HighResTiling());
2506 size_t num_tilings
= active_layer_
->num_tilings();
2507 active_layer_
->UpdateTiles(NULL
);
2508 pending_layer_
->AddTiling(0.5f
);
2509 EXPECT_EQ(num_tilings
+ 1, active_layer_
->num_tilings());
2512 TEST_F(NoLowResPictureLayerImplTest
, CleanUpTilings
) {
2513 gfx::Size
tile_size(400, 400);
2514 gfx::Size
layer_bounds(1300, 1900);
2516 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2517 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2518 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2519 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2521 std::vector
<PictureLayerTiling
*> used_tilings
;
2523 SetupTrees(pending_pile
, active_pile
);
2524 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2526 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
2527 EXPECT_LT(low_res_factor
, 1.f
);
2529 float device_scale
= 1.7f
;
2530 float page_scale
= 3.2f
;
2533 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
2534 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
2536 // We only have ideal tilings, so they aren't removed.
2537 used_tilings
.clear();
2538 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
2539 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
2541 host_impl_
.PinchGestureBegin();
2543 // Changing the ideal but not creating new tilings.
2546 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
2547 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
2549 // The tilings are still our target scale, so they aren't removed.
2550 used_tilings
.clear();
2551 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
2552 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
2554 host_impl_
.PinchGestureEnd();
2556 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
2559 SetContentsScaleOnBothLayers(1.2f
, device_scale
, page_scale
, 1.f
, false);
2560 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
2561 EXPECT_FLOAT_EQ(1.f
,
2562 active_layer_
->tilings()->tiling_at(1)->contents_scale());
2564 // Mark the non-ideal tilings as used. They won't be removed.
2565 used_tilings
.clear();
2566 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
2567 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
2568 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
2570 // Now move the ideal scale to 0.5. Our target stays 1.2.
2571 SetContentsScaleOnBothLayers(0.5f
, device_scale
, page_scale
, 1.f
, false);
2573 // The high resolution tiling is between target and ideal, so is not
2574 // removed. The low res tiling for the old ideal=1.0 scale is removed.
2575 used_tilings
.clear();
2576 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
2577 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
2579 // Now move the ideal scale to 1.0. Our target stays 1.2.
2580 SetContentsScaleOnBothLayers(1.f
, device_scale
, page_scale
, 1.f
, false);
2582 // All the tilings are between are target and the ideal, so they are not
2584 used_tilings
.clear();
2585 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
2586 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
2588 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
2589 SetupDrawPropertiesAndUpdateTiles(
2590 active_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
2592 // Because the pending layer's ideal scale is still 1.0, our tilings fall
2593 // in the range [1.0,1.2] and are kept.
2594 used_tilings
.clear();
2595 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
2596 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
2598 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
2600 SetupDrawPropertiesAndUpdateTiles(
2601 pending_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
2603 // Our 1.0 tiling now falls outside the range between our ideal scale and our
2604 // target raster scale. But it is in our used tilings set, so nothing is
2606 used_tilings
.clear();
2607 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
2608 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
2609 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
2611 // If we remove it from our used tilings set, it is outside the range to keep
2612 // so it is deleted.
2613 used_tilings
.clear();
2614 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
2615 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
2618 TEST_F(PictureLayerImplTest
, ScaleCollision
) {
2619 gfx::Size
tile_size(400, 400);
2620 gfx::Size
layer_bounds(1300, 1900);
2622 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2623 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2624 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2625 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2627 std::vector
<PictureLayerTiling
*> used_tilings
;
2629 SetupTrees(pending_pile
, active_pile
);
2631 float pending_contents_scale
= 1.f
;
2632 float active_contents_scale
= 2.f
;
2633 float device_scale_factor
= 1.f
;
2634 float page_scale_factor
= 1.f
;
2635 float maximum_animation_contents_scale
= 1.f
;
2636 bool animating_transform
= false;
2638 EXPECT_TRUE(host_impl_
.settings().create_low_res_tiling
);
2639 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
2640 EXPECT_LT(low_res_factor
, 1.f
);
2642 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
2643 pending_contents_scale
,
2644 device_scale_factor
,
2646 maximum_animation_contents_scale
,
2647 animating_transform
);
2648 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
2649 active_contents_scale
,
2650 device_scale_factor
,
2652 maximum_animation_contents_scale
,
2653 animating_transform
);
2655 ASSERT_EQ(4u, pending_layer_
->tilings()->num_tilings());
2656 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
2658 EXPECT_EQ(active_contents_scale
,
2659 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
2660 EXPECT_EQ(pending_contents_scale
,
2661 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
2662 EXPECT_EQ(active_contents_scale
* low_res_factor
,
2663 pending_layer_
->tilings()->tiling_at(2)->contents_scale());
2664 EXPECT_EQ(pending_contents_scale
* low_res_factor
,
2665 pending_layer_
->tilings()->tiling_at(3)->contents_scale());
2667 EXPECT_EQ(active_contents_scale
,
2668 active_layer_
->tilings()->tiling_at(0)->contents_scale());
2669 EXPECT_EQ(pending_contents_scale
,
2670 active_layer_
->tilings()->tiling_at(1)->contents_scale());
2671 EXPECT_EQ(active_contents_scale
* low_res_factor
,
2672 active_layer_
->tilings()->tiling_at(2)->contents_scale());
2673 EXPECT_EQ(pending_contents_scale
* low_res_factor
,
2674 active_layer_
->tilings()->tiling_at(3)->contents_scale());
2676 // The unused low res tiling from the pending tree must be kept or we may add
2677 // it again on the active tree and collide with the pending tree.
2678 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
2679 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
2680 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
2682 EXPECT_EQ(active_contents_scale
,
2683 active_layer_
->tilings()->tiling_at(0)->contents_scale());
2684 EXPECT_EQ(pending_contents_scale
,
2685 active_layer_
->tilings()->tiling_at(1)->contents_scale());
2686 EXPECT_EQ(active_contents_scale
* low_res_factor
,
2687 active_layer_
->tilings()->tiling_at(2)->contents_scale());
2688 EXPECT_EQ(pending_contents_scale
* low_res_factor
,
2689 active_layer_
->tilings()->tiling_at(3)->contents_scale());
2692 TEST_F(NoLowResPictureLayerImplTest
, ReleaseResources
) {
2693 gfx::Size
tile_size(400, 400);
2694 gfx::Size
layer_bounds(1300, 1900);
2696 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2697 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2698 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2699 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2701 SetupTrees(pending_pile
, active_pile
);
2702 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2704 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
2705 1.3f
, // ideal contents scale
2706 2.7f
, // device scale
2708 1.f
, // maximum animation scale
2710 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2712 // All tilings should be removed when losing output surface.
2713 active_layer_
->ReleaseResources();
2714 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2715 pending_layer_
->ReleaseResources();
2716 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2718 // This should create new tilings.
2719 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
2720 1.3f
, // ideal contents scale
2721 2.7f
, // device scale
2723 1.f
, // maximum animation scale
2725 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2728 TEST_F(PictureLayerImplTest
, SharedQuadStateContainsMaxTilingScale
) {
2729 MockOcclusionTracker
<LayerImpl
> occlusion_tracker
;
2730 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
2732 gfx::Size
tile_size(400, 400);
2733 gfx::Size
layer_bounds(1000, 2000);
2735 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2736 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2737 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2738 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2740 SetupTrees(pending_pile
, active_pile
);
2742 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 2.5f
, 1.f
, 1.f
, 1.f
, false);
2743 host_impl_
.pending_tree()->UpdateDrawProperties();
2745 active_layer_
->draw_properties().visible_content_rect
=
2746 gfx::Rect(layer_bounds
);
2747 host_impl_
.active_tree()->UpdateDrawProperties();
2749 float max_contents_scale
= active_layer_
->MaximumTilingContentsScale();
2750 gfx::Transform scaled_draw_transform
= active_layer_
->draw_transform();
2751 scaled_draw_transform
.Scale(SK_MScalar1
/ max_contents_scale
,
2752 SK_MScalar1
/ max_contents_scale
);
2754 AppendQuadsData data
;
2755 active_layer_
->AppendQuads(render_pass
.get(), occlusion_tracker
, &data
);
2757 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
2758 EXPECT_EQ(1u, render_pass
->shared_quad_state_list
.size());
2759 // The content_to_target_transform should be scaled by the
2760 // MaximumTilingContentsScale on the layer.
2761 EXPECT_EQ(scaled_draw_transform
.ToString(),
2762 render_pass
->shared_quad_state_list
[0]
2763 ->content_to_target_transform
.ToString());
2764 // The content_bounds should be scaled by the
2765 // MaximumTilingContentsScale on the layer.
2766 EXPECT_EQ(gfx::Size(2500u, 5000u).ToString(),
2767 render_pass
->shared_quad_state_list
[0]->content_bounds
.ToString());
2768 // The visible_content_rect should be scaled by the
2769 // MaximumTilingContentsScale on the layer.
2771 gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
2772 render_pass
->shared_quad_state_list
[0]->visible_content_rect
.ToString());
2775 TEST_F(PictureLayerImplTest
, UpdateTilesForMasksWithNoVisibleContent
) {
2776 gfx::Size
tile_size(400, 400);
2777 gfx::Size
bounds(100000, 100);
2779 host_impl_
.CreatePendingTree();
2781 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl_
.pending_tree(), 1);
2783 scoped_ptr
<FakePictureLayerImpl
> layer_with_mask
=
2784 FakePictureLayerImpl::Create(host_impl_
.pending_tree(), 2);
2786 layer_with_mask
->SetBounds(bounds
);
2787 layer_with_mask
->SetContentBounds(bounds
);
2789 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2790 FakePicturePileImpl::CreateFilledPile(tile_size
, bounds
);
2791 scoped_ptr
<FakePictureLayerImpl
> mask
= FakePictureLayerImpl::CreateWithPile(
2792 host_impl_
.pending_tree(), 3, pending_pile
);
2794 mask
->SetIsMask(true);
2795 mask
->SetBounds(bounds
);
2796 mask
->SetContentBounds(bounds
);
2797 mask
->SetDrawsContent(true);
2799 FakePictureLayerImpl
* pending_mask_content
= mask
.get();
2800 layer_with_mask
->SetMaskLayer(mask
.PassAs
<LayerImpl
>());
2802 scoped_ptr
<FakePictureLayerImpl
> child_of_layer_with_mask
=
2803 FakePictureLayerImpl::Create(host_impl_
.pending_tree(), 4);
2805 child_of_layer_with_mask
->SetBounds(bounds
);
2806 child_of_layer_with_mask
->SetContentBounds(bounds
);
2807 child_of_layer_with_mask
->SetDrawsContent(true);
2809 layer_with_mask
->AddChild(child_of_layer_with_mask
.PassAs
<LayerImpl
>());
2811 root
->AddChild(layer_with_mask
.PassAs
<LayerImpl
>());
2813 host_impl_
.pending_tree()->SetRootLayer(root
.Pass());
2815 EXPECT_FALSE(pending_mask_content
->tilings());
2816 host_impl_
.pending_tree()->UpdateDrawProperties();
2817 EXPECT_NE(0u, pending_mask_content
->num_tilings());
2820 class OcclusionTrackingSettings
: public ImplSidePaintingSettings
{
2822 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization
= true; }
2825 class OcclusionTrackingPictureLayerImplTest
: public PictureLayerImplTest
{
2827 OcclusionTrackingPictureLayerImplTest()
2828 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
2831 TEST_F(OcclusionTrackingPictureLayerImplTest
,
2832 OccludedTilesSkippedDuringRasterization
) {
2833 gfx::Size
tile_size(102, 102);
2834 gfx::Size
layer_bounds(1000, 1000);
2835 gfx::Size
viewport_size(500, 500);
2836 gfx::Point
occluding_layer_position(310, 0);
2838 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2839 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2840 SetupPendingTree(pending_pile
);
2841 pending_layer_
->set_fixed_tile_size(tile_size
);
2843 host_impl_
.SetViewportSize(viewport_size
);
2844 host_impl_
.pending_tree()->UpdateDrawProperties();
2847 int unoccluded_tile_count
= 0;
2848 for (PictureLayerImpl::LayerRasterTileIterator it
=
2849 PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
2854 // Occluded tiles should not be iterated over.
2855 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
2857 // Some tiles may not be visible (i.e. outside the viewport). The rest are
2858 // visible and at least partially unoccluded, verified by the above expect.
2859 bool tile_is_visible
=
2860 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
2861 if (tile_is_visible
)
2862 unoccluded_tile_count
++;
2864 EXPECT_EQ(unoccluded_tile_count
, 25 + 4);
2866 // Partial occlusion.
2867 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
2868 LayerImpl
* layer1
= pending_layer_
->children()[0];
2869 layer1
->SetBounds(layer_bounds
);
2870 layer1
->SetContentBounds(layer_bounds
);
2871 layer1
->SetDrawsContent(true);
2872 layer1
->SetContentsOpaque(true);
2873 layer1
->SetPosition(occluding_layer_position
);
2875 host_impl_
.pending_tree()->UpdateDrawProperties();
2877 unoccluded_tile_count
= 0;
2878 for (PictureLayerImpl::LayerRasterTileIterator it
=
2879 PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
2884 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
2886 bool tile_is_visible
=
2887 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
2888 if (tile_is_visible
)
2889 unoccluded_tile_count
++;
2891 EXPECT_EQ(unoccluded_tile_count
, 20 + 2);
2894 layer1
->SetPosition(gfx::Point(0, 0));
2896 host_impl_
.pending_tree()->UpdateDrawProperties();
2898 unoccluded_tile_count
= 0;
2899 for (PictureLayerImpl::LayerRasterTileIterator it
=
2900 PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
2905 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
2907 bool tile_is_visible
=
2908 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
2909 if (tile_is_visible
)
2910 unoccluded_tile_count
++;
2912 EXPECT_EQ(unoccluded_tile_count
, 0);
2915 TEST_F(OcclusionTrackingPictureLayerImplTest
,
2916 OccludedTilesNotMarkedAsRequired
) {
2917 gfx::Size
tile_size(102, 102);
2918 gfx::Size
layer_bounds(1000, 1000);
2919 gfx::Size
viewport_size(500, 500);
2920 gfx::Point
occluding_layer_position(310, 0);
2922 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2923 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2924 SetupPendingTree(pending_pile
);
2925 pending_layer_
->set_fixed_tile_size(tile_size
);
2927 host_impl_
.SetViewportSize(viewport_size
);
2928 host_impl_
.pending_tree()->UpdateDrawProperties();
2931 int occluded_tile_count
= 0;
2932 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
2933 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
2935 occluded_tile_count
= 0;
2936 for (PictureLayerTiling::CoverageIterator
iter(
2938 pending_layer_
->contents_scale_x(),
2939 gfx::Rect(layer_bounds
));
2944 const Tile
* tile
= *iter
;
2946 // Fully occluded tiles are not required for activation.
2947 if (tile
->is_occluded(PENDING_TREE
)) {
2948 EXPECT_FALSE(tile
->required_for_activation());
2949 occluded_tile_count
++;
2952 EXPECT_EQ(occluded_tile_count
, 0);
2955 // Partial occlusion.
2956 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
2957 LayerImpl
* layer1
= pending_layer_
->children()[0];
2958 layer1
->SetBounds(layer_bounds
);
2959 layer1
->SetContentBounds(layer_bounds
);
2960 layer1
->SetDrawsContent(true);
2961 layer1
->SetContentsOpaque(true);
2962 layer1
->SetPosition(occluding_layer_position
);
2964 host_impl_
.pending_tree()->UpdateDrawProperties();
2966 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
2967 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
2969 occluded_tile_count
= 0;
2970 for (PictureLayerTiling::CoverageIterator
iter(
2972 pending_layer_
->contents_scale_x(),
2973 gfx::Rect(layer_bounds
));
2978 const Tile
* tile
= *iter
;
2980 if (tile
->is_occluded(PENDING_TREE
)) {
2981 EXPECT_FALSE(tile
->required_for_activation());
2982 occluded_tile_count
++;
2987 EXPECT_EQ(occluded_tile_count
, 5);
2990 EXPECT_EQ(occluded_tile_count
, 2);
2998 layer1
->SetPosition(gfx::PointF(0, 0));
3000 host_impl_
.pending_tree()->UpdateDrawProperties();
3002 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3003 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3005 occluded_tile_count
= 0;
3006 for (PictureLayerTiling::CoverageIterator
iter(
3008 pending_layer_
->contents_scale_x(),
3009 gfx::Rect(layer_bounds
));
3014 const Tile
* tile
= *iter
;
3016 if (tile
->is_occluded(PENDING_TREE
)) {
3017 EXPECT_FALSE(tile
->required_for_activation());
3018 occluded_tile_count
++;
3023 EXPECT_EQ(occluded_tile_count
, 25);
3026 EXPECT_EQ(occluded_tile_count
, 4);
3034 TEST_F(OcclusionTrackingPictureLayerImplTest
, OcclusionForDifferentScales
) {
3035 gfx::Size
tile_size(102, 102);
3036 gfx::Size
layer_bounds(1000, 1000);
3037 gfx::Size
viewport_size(500, 500);
3038 gfx::Point
occluding_layer_position(310, 0);
3040 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3041 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3042 SetupPendingTree(pending_pile
);
3043 pending_layer_
->set_fixed_tile_size(tile_size
);
3045 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
3047 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3049 std::vector
<PictureLayerTiling
*> tilings
;
3050 tilings
.push_back(pending_layer_
->AddTiling(low_res_factor
));
3051 tilings
.push_back(pending_layer_
->AddTiling(0.3f
));
3052 tilings
.push_back(pending_layer_
->AddTiling(0.7f
));
3053 tilings
.push_back(pending_layer_
->AddTiling(1.0f
));
3054 tilings
.push_back(pending_layer_
->AddTiling(2.0f
));
3056 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
3057 LayerImpl
* layer1
= pending_layer_
->children()[0];
3058 layer1
->SetBounds(layer_bounds
);
3059 layer1
->SetContentBounds(layer_bounds
);
3060 layer1
->SetDrawsContent(true);
3061 layer1
->SetContentsOpaque(true);
3062 layer1
->SetPosition(occluding_layer_position
);
3064 host_impl_
.SetViewportSize(viewport_size
);
3065 host_impl_
.pending_tree()->UpdateDrawProperties();
3067 int tiling_count
= 0;
3068 int occluded_tile_count
= 0;
3069 for (std::vector
<PictureLayerTiling
*>::iterator tiling_iterator
=
3071 tiling_iterator
!= tilings
.end();
3072 ++tiling_iterator
) {
3073 std::vector
<Tile
*> tiles
= (*tiling_iterator
)->AllTilesForTesting();
3075 occluded_tile_count
= 0;
3076 for (size_t i
= 0; i
< tiles
.size(); ++i
) {
3077 if (tiles
[i
]->is_occluded(PENDING_TREE
)) {
3078 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
3079 tiles
[i
]->content_rect(), 1.0f
/ tiles
[i
]->contents_scale());
3080 EXPECT_GE(scaled_content_rect
.x(), occluding_layer_position
.x());
3081 occluded_tile_count
++;
3084 switch (tiling_count
) {
3087 EXPECT_EQ(occluded_tile_count
, 2);
3090 EXPECT_EQ(occluded_tile_count
, 4);
3093 EXPECT_EQ(occluded_tile_count
, 5);
3096 EXPECT_EQ(occluded_tile_count
, 30);
3105 EXPECT_EQ(tiling_count
, 5);
3108 TEST_F(OcclusionTrackingPictureLayerImplTest
, DifferentOcclusionOnTrees
) {
3109 gfx::Size
tile_size(102, 102);
3110 gfx::Size
layer_bounds(1000, 1000);
3111 gfx::Size
viewport_size(1000, 1000);
3112 gfx::Point
occluding_layer_position(310, 0);
3113 gfx::Rect
invalidation_rect(230, 230, 102, 102);
3115 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3116 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3117 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3118 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3119 SetupTrees(pending_pile
, active_pile
);
3121 // Partially occlude the active layer.
3122 active_layer_
->AddChild(LayerImpl::Create(host_impl_
.active_tree(), 2));
3123 LayerImpl
* layer1
= active_layer_
->children()[0];
3124 layer1
->SetBounds(layer_bounds
);
3125 layer1
->SetContentBounds(layer_bounds
);
3126 layer1
->SetDrawsContent(true);
3127 layer1
->SetContentsOpaque(true);
3128 layer1
->SetPosition(occluding_layer_position
);
3130 // Partially invalidate the pending layer.
3131 pending_layer_
->set_invalidation(invalidation_rect
);
3133 host_impl_
.SetViewportSize(viewport_size
);
3135 active_layer_
->CreateDefaultTilingsAndTiles();
3136 pending_layer_
->CreateDefaultTilingsAndTiles();
3138 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3139 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3141 for (PictureLayerTiling::CoverageIterator
iter(
3143 pending_layer_
->contents_scale_x(),
3144 gfx::Rect(layer_bounds
));
3149 const Tile
* tile
= *iter
;
3151 // All tiles are unoccluded on the pending tree.
3152 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
3155 pending_layer_
->GetTwinTiling(tiling
)->TileAt(iter
.i(), iter
.j());
3156 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
3157 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
3159 if (scaled_content_rect
.Intersects(invalidation_rect
)) {
3160 // Tiles inside the invalidation rect are only on the pending tree.
3161 EXPECT_NE(tile
, twin_tile
);
3163 // Unshared tiles should be unoccluded on the active tree by default.
3164 EXPECT_FALSE(tile
->is_occluded(ACTIVE_TREE
));
3166 // Tiles outside the invalidation rect are shared between both trees.
3167 EXPECT_EQ(tile
, twin_tile
);
3168 // Shared tiles are occluded on the active tree iff they lie beneath the
3170 EXPECT_EQ(tile
->is_occluded(ACTIVE_TREE
),
3171 scaled_content_rect
.x() >= occluding_layer_position
.x());
3176 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
3177 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
3179 for (PictureLayerTiling::CoverageIterator
iter(
3181 active_layer_
->contents_scale_x(),
3182 gfx::Rect(layer_bounds
));
3187 const Tile
* tile
= *iter
;
3190 active_layer_
->GetTwinTiling(tiling
)->TileAt(iter
.i(), iter
.j());
3191 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
3192 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
3194 // Since we've already checked the shared tiles, only consider tiles in
3195 // the invalidation rect.
3196 if (scaled_content_rect
.Intersects(invalidation_rect
)) {
3197 // Tiles inside the invalidation rect are only on the active tree.
3198 EXPECT_NE(tile
, twin_tile
);
3200 // Unshared tiles should be unoccluded on the pending tree by default.
3201 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
3203 // Unshared tiles are occluded on the active tree iff they lie beneath
3204 // the occluding layer.
3205 EXPECT_EQ(tile
->is_occluded(ACTIVE_TREE
),
3206 scaled_content_rect
.x() >= occluding_layer_position
.x());