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 "base/location.h"
13 #include "base/thread_task_runner_handle.h"
14 #include "cc/base/math_util.h"
15 #include "cc/layers/append_quads_data.h"
16 #include "cc/layers/picture_layer.h"
17 #include "cc/quads/draw_quad.h"
18 #include "cc/quads/tile_draw_quad.h"
19 #include "cc/test/begin_frame_args_test.h"
20 #include "cc/test/fake_content_layer_client.h"
21 #include "cc/test/fake_impl_proxy.h"
22 #include "cc/test/fake_layer_tree_host_impl.h"
23 #include "cc/test/fake_output_surface.h"
24 #include "cc/test/fake_picture_layer_impl.h"
25 #include "cc/test/fake_picture_pile_impl.h"
26 #include "cc/test/geometry_test_utils.h"
27 #include "cc/test/gpu_rasterization_enabled_settings.h"
28 #include "cc/test/layer_test_common.h"
29 #include "cc/test/test_shared_bitmap_manager.h"
30 #include "cc/test/test_task_graph_runner.h"
31 #include "cc/test/test_web_graphics_context_3d.h"
32 #include "cc/tiles/tiling_set_raster_queue_all.h"
33 #include "cc/tiles/tiling_set_raster_queue_required.h"
34 #include "cc/trees/layer_tree_impl.h"
35 #include "testing/gtest/include/gtest/gtest.h"
36 #include "ui/gfx/geometry/rect_conversions.h"
37 #include "ui/gfx/geometry/size_conversions.h"
42 #define EXPECT_BOTH_EQ(expression, x) \
44 EXPECT_EQ(x, pending_layer_->expression); \
45 EXPECT_EQ(x, active_layer_->expression); \
48 #define EXPECT_BOTH_NE(expression, x) \
50 EXPECT_NE(x, pending_layer_->expression); \
51 EXPECT_NE(x, active_layer_->expression); \
54 #define EXPECT_BOTH_TRUE(expression) \
56 EXPECT_TRUE(pending_layer_->expression); \
57 EXPECT_TRUE(active_layer_->expression); \
60 #define EXPECT_BOTH_FALSE(expression) \
62 EXPECT_FALSE(pending_layer_->expression); \
63 EXPECT_FALSE(active_layer_->expression); \
66 class MockCanvas
: public SkCanvas
{
68 explicit MockCanvas(int w
, int h
) : SkCanvas(w
, h
) {}
70 void onDrawRect(const SkRect
& rect
, const SkPaint
& paint
) override
{
71 // Capture calls before SkCanvas quickReject() kicks in.
72 rects_
.push_back(rect
);
75 std::vector
<SkRect
> rects_
;
78 class PictureLayerImplTestSettings
: public GpuRasterizationEnabledSettings
{
80 PictureLayerImplTestSettings() {
81 layer_transforms_should_scale_layer_contents
= true;
85 class NoLowResTilingsSettings
: public PictureLayerImplTestSettings
{};
87 class LowResTilingsSettings
: public PictureLayerImplTestSettings
{
89 LowResTilingsSettings() { create_low_res_tiling
= true; }
92 class PictureLayerImplTest
: public testing::Test
{
94 PictureLayerImplTest()
95 : proxy_(base::ThreadTaskRunnerHandle::Get()),
96 host_impl_(LowResTilingsSettings(),
98 &shared_bitmap_manager_
,
102 pending_layer_(nullptr),
103 old_pending_layer_(nullptr),
104 active_layer_(nullptr) {
105 host_impl_
.SetViewportSize(gfx::Size(10000, 10000));
108 explicit PictureLayerImplTest(const LayerTreeSettings
& settings
)
109 : proxy_(base::ThreadTaskRunnerHandle::Get()),
112 &shared_bitmap_manager_
,
113 &task_graph_runner_
),
116 host_impl_
.SetViewportSize(gfx::Size(10000, 10000));
119 ~PictureLayerImplTest() override
{}
121 void SetUp() override
{ InitializeRenderer(); }
123 virtual void InitializeRenderer() {
124 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d());
127 void SetupDefaultTrees(const gfx::Size
& layer_bounds
) {
128 gfx::Size
tile_size(100, 100);
130 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
131 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
132 scoped_refptr
<FakePicturePileImpl
> active_pile
=
133 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
135 SetupTrees(pending_pile
, active_pile
);
138 void SetupDefaultTreesWithInvalidation(const gfx::Size
& layer_bounds
,
139 const Region
& invalidation
) {
140 gfx::Size
tile_size(100, 100);
142 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
143 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
144 scoped_refptr
<FakePicturePileImpl
> active_pile
=
145 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
147 SetupTreesWithInvalidation(pending_pile
, active_pile
, invalidation
);
150 void ActivateTree() {
151 host_impl_
.ActivateSyncTree();
152 CHECK(!host_impl_
.pending_tree());
153 CHECK(host_impl_
.recycle_tree());
154 old_pending_layer_
= pending_layer_
;
155 pending_layer_
= nullptr;
156 active_layer_
= static_cast<FakePictureLayerImpl
*>(
157 host_impl_
.active_tree()->LayerById(id_
));
159 bool update_lcd_text
= false;
160 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
163 void SetupDefaultTreesWithFixedTileSize(const gfx::Size
& layer_bounds
,
164 const gfx::Size
& tile_size
,
165 const Region
& invalidation
) {
166 gfx::Size
pile_tile_size(100, 100);
168 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
169 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, layer_bounds
);
170 scoped_refptr
<FakePicturePileImpl
> active_pile
=
171 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, layer_bounds
);
173 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
,
178 scoped_refptr
<PicturePileImpl
> pending_pile
,
179 scoped_refptr
<PicturePileImpl
> active_pile
) {
180 SetupPendingTree(active_pile
);
182 SetupPendingTreeInternal(pending_pile
, gfx::Size(), Region());
185 void SetupTreesWithInvalidation(scoped_refptr
<PicturePileImpl
> pending_pile
,
186 scoped_refptr
<PicturePileImpl
> active_pile
,
187 const Region
& pending_invalidation
) {
188 SetupPendingTreeInternal(active_pile
, gfx::Size(), Region());
190 SetupPendingTreeInternal(pending_pile
, gfx::Size(), pending_invalidation
);
193 void SetupTreesWithFixedTileSize(scoped_refptr
<PicturePileImpl
> pending_pile
,
194 scoped_refptr
<PicturePileImpl
> active_pile
,
195 const gfx::Size
& tile_size
,
196 const Region
& pending_invalidation
) {
197 SetupPendingTreeInternal(active_pile
, tile_size
, Region());
199 SetupPendingTreeInternal(pending_pile
, tile_size
, pending_invalidation
);
202 void SetupPendingTree(scoped_refptr
<RasterSource
> raster_source
) {
203 SetupPendingTreeInternal(raster_source
, gfx::Size(), Region());
206 void SetupPendingTreeWithInvalidation(
207 scoped_refptr
<RasterSource
> raster_source
,
208 const Region
& invalidation
) {
209 SetupPendingTreeInternal(raster_source
, gfx::Size(), invalidation
);
212 void SetupPendingTreeWithFixedTileSize(
213 scoped_refptr
<RasterSource
> raster_source
,
214 const gfx::Size
& tile_size
,
215 const Region
& invalidation
) {
216 SetupPendingTreeInternal(raster_source
, tile_size
, invalidation
);
219 void SetupPendingTreeInternal(scoped_refptr
<RasterSource
> raster_source
,
220 const gfx::Size
& tile_size
,
221 const Region
& invalidation
) {
222 host_impl_
.CreatePendingTree();
223 host_impl_
.pending_tree()->PushPageScaleFromMainThread(1.f
, 0.00001f
,
225 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
227 // Steal from the recycled tree if possible.
228 scoped_ptr
<LayerImpl
> pending_root
= pending_tree
->DetachLayerTree();
229 scoped_ptr
<FakePictureLayerImpl
> pending_layer
;
230 DCHECK_IMPLIES(pending_root
, pending_root
->id() == root_id_
);
232 pending_root
= LayerImpl::Create(pending_tree
, root_id_
);
233 pending_layer
= FakePictureLayerImpl::Create(pending_tree
, id_
);
234 if (!tile_size
.IsEmpty())
235 pending_layer
->set_fixed_tile_size(tile_size
);
236 pending_layer
->SetDrawsContent(true);
238 pending_layer
.reset(static_cast<FakePictureLayerImpl
*>(
239 pending_root
->RemoveChild(pending_root
->children()[0]).release()));
240 if (!tile_size
.IsEmpty())
241 pending_layer
->set_fixed_tile_size(tile_size
);
243 pending_root
->SetHasRenderSurface(true);
244 // The bounds() just mirror the pile size.
245 pending_layer
->SetBounds(raster_source
->GetSize());
246 pending_layer
->SetRasterSourceOnPending(raster_source
, invalidation
);
248 pending_root
->AddChild(pending_layer
.Pass());
249 pending_tree
->SetRootLayer(pending_root
.Pass());
251 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
252 host_impl_
.pending_tree()->LayerById(id_
));
254 // Add tilings/tiles for the layer.
255 bool update_lcd_text
= false;
256 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
259 void SetupDrawPropertiesAndUpdateTiles(
260 FakePictureLayerImpl
* layer
,
261 float ideal_contents_scale
,
262 float device_scale_factor
,
263 float page_scale_factor
,
264 float maximum_animation_contents_scale
,
265 float starting_animation_contents_scale
,
266 bool animating_transform_to_screen
) {
267 host_impl_
.SetDeviceScaleFactor(device_scale_factor
);
268 host_impl_
.SetPageScaleOnActiveTree(page_scale_factor
);
270 gfx::Transform scale_transform
;
271 scale_transform
.Scale(ideal_contents_scale
, ideal_contents_scale
);
272 layer
->draw_properties().target_space_transform
= scale_transform
;
273 DCHECK_EQ(layer
->GetIdealContentsScale(), ideal_contents_scale
);
274 layer
->draw_properties().maximum_animation_contents_scale
=
275 maximum_animation_contents_scale
;
276 layer
->draw_properties().starting_animation_contents_scale
=
277 starting_animation_contents_scale
;
278 layer
->draw_properties().screen_space_transform_is_animating
=
279 animating_transform_to_screen
;
280 bool resourceless_software_draw
= false;
281 layer
->UpdateTiles(resourceless_software_draw
);
283 static void VerifyAllPrioritizedTilesExistAndHavePile(
284 const PictureLayerTiling
* tiling
,
285 PicturePileImpl
* pile
) {
286 auto prioritized_tiles
=
287 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
288 for (PictureLayerTiling::CoverageIterator
iter(
290 tiling
->contents_scale(),
291 gfx::Rect(tiling
->tiling_size()));
295 EXPECT_EQ(pile
, prioritized_tiles
[*iter
].raster_source());
299 void SetContentsScaleOnBothLayers(float contents_scale
,
300 float device_scale_factor
,
301 float page_scale_factor
,
302 float maximum_animation_contents_scale
,
303 float starting_animation_contents_scale
,
304 bool animating_transform
) {
305 SetupDrawPropertiesAndUpdateTiles(
306 pending_layer_
, contents_scale
, device_scale_factor
, page_scale_factor
,
307 maximum_animation_contents_scale
, starting_animation_contents_scale
,
308 animating_transform
);
310 SetupDrawPropertiesAndUpdateTiles(
311 active_layer_
, contents_scale
, device_scale_factor
, page_scale_factor
,
312 maximum_animation_contents_scale
, starting_animation_contents_scale
,
313 animating_transform
);
316 void ResetTilingsAndRasterScales() {
317 if (pending_layer_
) {
318 pending_layer_
->ReleaseResources();
319 EXPECT_FALSE(pending_layer_
->tilings());
320 pending_layer_
->RecreateResources();
321 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
325 active_layer_
->ReleaseResources();
326 EXPECT_FALSE(active_layer_
->tilings());
327 active_layer_
->RecreateResources();
328 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
332 size_t NumberOfTilesRequired(PictureLayerTiling
* tiling
) {
333 size_t num_required
= 0;
334 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
335 for (size_t i
= 0; i
< tiles
.size(); ++i
) {
336 if (tiles
[i
]->required_for_activation())
342 void AssertAllTilesRequired(PictureLayerTiling
* tiling
) {
343 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
344 for (size_t i
= 0; i
< tiles
.size(); ++i
)
345 EXPECT_TRUE(tiles
[i
]->required_for_activation()) << "i: " << i
;
346 EXPECT_GT(tiles
.size(), 0u);
349 void AssertNoTilesRequired(PictureLayerTiling
* tiling
) {
350 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
351 for (size_t i
= 0; i
< tiles
.size(); ++i
)
352 EXPECT_FALSE(tiles
[i
]->required_for_activation()) << "i: " << i
;
353 EXPECT_GT(tiles
.size(), 0u);
357 void TestQuadsForSolidColor(bool test_for_solid
);
359 FakeImplProxy proxy_
;
360 TestSharedBitmapManager shared_bitmap_manager_
;
361 TestTaskGraphRunner task_graph_runner_
;
362 FakeLayerTreeHostImpl host_impl_
;
365 FakePictureLayerImpl
* pending_layer_
;
366 FakePictureLayerImpl
* old_pending_layer_
;
367 FakePictureLayerImpl
* active_layer_
;
368 LayerSettings layer_settings_
;
371 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest
);
374 class NoLowResPictureLayerImplTest
: public PictureLayerImplTest
{
376 NoLowResPictureLayerImplTest()
377 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
380 TEST_F(PictureLayerImplTest
, TileGridAlignment
) {
381 // Layer to span 4 raster tiles in x and in y
382 LayerTreeSettings settings
;
383 gfx::Size
layer_size(settings
.default_tile_size
.width() * 7 / 2,
384 settings
.default_tile_size
.height() * 7 / 2);
386 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
387 FakePicturePileImpl::CreateFilledPile(layer_size
, layer_size
);
389 scoped_ptr
<FakePicturePile
> active_recording
=
390 FakePicturePile::CreateFilledPile(layer_size
, layer_size
);
391 scoped_refptr
<FakePicturePileImpl
> active_pile
=
392 FakePicturePileImpl::CreateFromPile(active_recording
.get(), nullptr);
394 SetupTrees(pending_pile
, active_pile
);
396 // Add 1x1 rects at the centers of each tile, then re-record pile contents
397 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
398 std::vector
<Tile
*> tiles
=
399 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
400 EXPECT_EQ(16u, tiles
.size());
401 std::vector
<SkRect
> rects
;
402 std::vector
<Tile
*>::const_iterator tile_iter
;
403 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
404 gfx::Point tile_center
= (*tile_iter
)->content_rect().CenterPoint();
405 gfx::Rect
rect(tile_center
.x(), tile_center
.y(), 1, 1);
406 active_recording
->add_draw_rect(rect
);
407 rects
.push_back(SkRect::MakeXYWH(rect
.x(), rect
.y(), 1, 1));
410 // Force re-raster with newly injected content
411 active_recording
->RemoveRecordingAt(0, 0);
412 active_recording
->AddRecordingAt(0, 0);
414 scoped_refptr
<FakePicturePileImpl
> updated_active_pile
=
415 FakePicturePileImpl::CreateFromPile(active_recording
.get(), nullptr);
417 std::vector
<SkRect
>::const_iterator rect_iter
= rects
.begin();
418 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
419 MockCanvas
mock_canvas(1000, 1000);
420 updated_active_pile
->PlaybackToSharedCanvas(
421 &mock_canvas
, (*tile_iter
)->content_rect(), 1.0f
);
423 // This test verifies that when drawing the contents of a specific tile
424 // at content scale 1.0, the playback canvas never receives content from
425 // neighboring tiles which indicates that the tile grid embedded in
426 // SkPicture is perfectly aligned with the compositor's tiles.
427 EXPECT_EQ(1u, mock_canvas
.rects_
.size());
428 EXPECT_EQ(*rect_iter
, mock_canvas
.rects_
[0]);
433 TEST_F(PictureLayerImplTest
, CloneNoInvalidation
) {
434 gfx::Size
tile_size(100, 100);
435 gfx::Size
layer_bounds(400, 400);
437 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
438 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
439 scoped_refptr
<FakePicturePileImpl
> active_pile
=
440 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
442 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
444 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
445 active_layer_
->tilings()->num_tilings());
447 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
448 EXPECT_GT(tilings
->num_tilings(), 0u);
449 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
450 EXPECT_TRUE(tilings
->tiling_at(i
)->AllTilesForTesting().empty());
453 TEST_F(PictureLayerImplTest
, ExternalViewportRectForPrioritizingTiles
) {
454 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
455 gfx::Size
tile_size(100, 100);
456 gfx::Size
layer_bounds(400, 400);
458 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
459 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
460 scoped_refptr
<FakePicturePileImpl
> active_pile
=
461 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
463 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
465 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
468 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
470 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the
471 // identify transform for tile priority.
472 bool resourceless_software_draw
= false;
473 gfx::Rect viewport
= gfx::Rect(layer_bounds
),
474 viewport_rect_for_tile_priority
= gfx::Rect(0, 0, 100, 100);
475 gfx::Transform transform
, transform_for_tile_priority
;
477 host_impl_
.SetExternalDrawConstraints(transform
,
480 viewport_rect_for_tile_priority
,
481 transform_for_tile_priority
,
482 resourceless_software_draw
);
483 bool update_lcd_text
= false;
484 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
486 gfx::Rect viewport_rect_for_tile_priority_in_view_space
=
487 viewport_rect_for_tile_priority
;
489 // Verify the viewport rect for tile priority is used in picture layer tiling.
490 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
491 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
492 PictureLayerTilingSet
* tilings
= active_layer_
->tilings();
493 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
494 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
496 tiling
->GetCurrentVisibleRectForTesting(),
497 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
498 tiling
->contents_scale()));
501 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in
502 // screen space and the transform for tile priority is translated and
503 // rotated. The actual viewport for tile priority used by PictureLayerImpl
504 // should be (200, 200, 100, 100) applied with the said transform.
505 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
507 viewport_rect_for_tile_priority
= gfx::Rect(200, 200, 100, 100);
508 transform_for_tile_priority
.Translate(100, 100);
509 transform_for_tile_priority
.Rotate(45);
510 host_impl_
.SetExternalDrawConstraints(transform
,
513 viewport_rect_for_tile_priority
,
514 transform_for_tile_priority
,
515 resourceless_software_draw
);
516 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
518 gfx::Transform
screen_to_view(gfx::Transform::kSkipInitialization
);
519 bool success
= transform_for_tile_priority
.GetInverse(&screen_to_view
);
520 EXPECT_TRUE(success
);
522 // Note that we don't clip this to the layer bounds, since it is expected that
523 // the rect will sometimes be outside of the layer bounds. If we clip to
524 // bounds, then tile priorities will end up being incorrect in cases of fully
526 viewport_rect_for_tile_priority_in_view_space
=
527 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
528 screen_to_view
, viewport_rect_for_tile_priority
));
530 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
531 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
532 tilings
= active_layer_
->tilings();
533 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
534 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
536 tiling
->GetCurrentVisibleRectForTesting(),
537 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
538 tiling
->contents_scale()));
542 TEST_F(PictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
543 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
545 gfx::Size
tile_size(100, 100);
546 gfx::Size
layer_bounds(400, 400);
548 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
549 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
550 scoped_refptr
<FakePicturePileImpl
> active_pile
=
551 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
553 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
555 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
558 // UpdateTiles with valid viewport. Should update tile viewport.
559 // Note viewport is considered invalid if and only if in resourceless
561 bool resourceless_software_draw
= false;
562 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
563 gfx::Transform transform
;
564 host_impl_
.SetExternalDrawConstraints(transform
,
569 resourceless_software_draw
);
570 active_layer_
->draw_properties().visible_layer_rect
= viewport
;
571 active_layer_
->draw_properties().screen_space_transform
= transform
;
572 active_layer_
->UpdateTiles(resourceless_software_draw
);
574 gfx::Rect visible_rect_for_tile_priority
=
575 active_layer_
->visible_rect_for_tile_priority();
576 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
577 gfx::Transform screen_space_transform_for_tile_priority
=
578 active_layer_
->screen_space_transform();
580 // Expand viewport and set it as invalid for prioritizing tiles.
581 // Should update viewport and transform, but not update visible rect.
582 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
583 resourceless_software_draw
= true;
584 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
585 transform
.Translate(1.f
, 1.f
);
586 active_layer_
->draw_properties().visible_layer_rect
= viewport
;
587 active_layer_
->draw_properties().screen_space_transform
= transform
;
588 host_impl_
.SetExternalDrawConstraints(transform
,
593 resourceless_software_draw
);
594 active_layer_
->UpdateTiles(resourceless_software_draw
);
596 // Transform for tile priority is updated.
597 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
598 active_layer_
->screen_space_transform());
599 // Visible rect for tile priority retains old value.
600 EXPECT_EQ(visible_rect_for_tile_priority
,
601 active_layer_
->visible_rect_for_tile_priority());
603 // Keep expanded viewport but mark it valid. Should update tile viewport.
604 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
605 resourceless_software_draw
= false;
606 host_impl_
.SetExternalDrawConstraints(transform
,
611 resourceless_software_draw
);
612 active_layer_
->UpdateTiles(resourceless_software_draw
);
614 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
615 active_layer_
->screen_space_transform());
616 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
619 TEST_F(PictureLayerImplTest
, ViewportRectForTilePriorityIsCached
) {
620 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
621 gfx::Size
tile_size(100, 100);
622 gfx::Size
layer_bounds(400, 400);
624 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
625 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
626 scoped_refptr
<FakePicturePileImpl
> active_pile
=
627 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
629 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
631 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
634 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
636 bool resourceless_software_draw
= false;
637 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
638 gfx::Rect
viewport_rect_for_tile_priority(0, 0, 100, 100);
639 gfx::Transform transform
, transform_for_tile_priority
;
641 host_impl_
.SetExternalDrawConstraints(
642 transform
, viewport
, viewport
, viewport_rect_for_tile_priority
,
643 transform_for_tile_priority
, resourceless_software_draw
);
644 bool update_lcd_text
= false;
645 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
647 EXPECT_EQ(viewport_rect_for_tile_priority
,
648 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
650 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
652 gfx::Rect
another_viewport_rect_for_tile_priority(11, 11, 50, 50);
653 host_impl_
.SetExternalDrawConstraints(
654 transform
, viewport
, viewport
, another_viewport_rect_for_tile_priority
,
655 transform_for_tile_priority
, resourceless_software_draw
);
657 // Didn't call UpdateDrawProperties yet. The viewport rect for tile priority
658 // should remain to be the previously cached value.
659 EXPECT_EQ(viewport_rect_for_tile_priority
,
660 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
661 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
663 // Now the UpdateDrawProperties is called. The viewport rect for tile
664 // priority should be the latest value.
665 EXPECT_EQ(another_viewport_rect_for_tile_priority
,
666 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
669 TEST_F(PictureLayerImplTest
, ClonePartialInvalidation
) {
670 gfx::Size
tile_size(100, 100);
671 gfx::Size
layer_bounds(400, 400);
672 gfx::Rect
layer_invalidation(150, 200, 30, 180);
674 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
675 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
676 scoped_refptr
<FakePicturePileImpl
> active_pile
=
677 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
678 scoped_refptr
<FakePicturePileImpl
> lost_pile
=
679 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
681 SetupPendingTreeWithFixedTileSize(lost_pile
, gfx::Size(50, 50), Region());
683 // Add a unique tiling on the active tree.
684 PictureLayerTiling
* tiling
= active_layer_
->AddTiling(3.f
);
685 tiling
->CreateAllTilesForTesting();
687 // Ensure UpdateTiles won't remove any tilings.
688 active_layer_
->MarkAllTilingsUsed();
690 // Then setup a new pending tree and activate it.
691 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, gfx::Size(50, 50),
694 EXPECT_EQ(2u, pending_layer_
->num_tilings());
695 EXPECT_EQ(3u, active_layer_
->num_tilings());
697 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
698 EXPECT_GT(tilings
->num_tilings(), 0u);
699 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
700 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
701 gfx::Rect content_invalidation
= gfx::ScaleToEnclosingRect(
703 tiling
->contents_scale());
704 auto prioritized_tiles
=
705 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
706 for (PictureLayerTiling::CoverageIterator
iter(
708 tiling
->contents_scale(),
709 gfx::Rect(tiling
->tiling_size()));
712 // We don't always have a tile, but when we do it's because it was
713 // invalidated and it has the latest raster source.
715 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
716 EXPECT_EQ(pending_pile
.get(), prioritized_tiles
[*iter
].raster_source());
717 EXPECT_TRUE(iter
.geometry_rect().Intersects(content_invalidation
));
719 // We don't create tiles in non-invalidated regions.
720 EXPECT_FALSE(iter
.geometry_rect().Intersects(content_invalidation
));
725 tilings
= active_layer_
->tilings();
726 EXPECT_GT(tilings
->num_tilings(), 0u);
727 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
728 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
729 gfx::Rect content_invalidation
=
730 gfx::ScaleToEnclosingRect(layer_invalidation
, tiling
->contents_scale());
731 auto prioritized_tiles
=
732 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
733 for (PictureLayerTiling::CoverageIterator
iter(
735 tiling
->contents_scale(),
736 gfx::Rect(tiling
->tiling_size()));
740 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
741 // Pile will be updated upon activation.
742 EXPECT_EQ(active_pile
.get(), prioritized_tiles
[*iter
].raster_source());
747 TEST_F(PictureLayerImplTest
, CloneFullInvalidation
) {
748 gfx::Size
tile_size(90, 80);
749 gfx::Size
layer_bounds(300, 500);
751 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
752 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
753 scoped_refptr
<FakePicturePileImpl
> active_pile
=
754 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
756 SetupTreesWithInvalidation(pending_pile
, active_pile
,
757 gfx::Rect(layer_bounds
));
759 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
760 active_layer_
->tilings()->num_tilings());
762 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
763 EXPECT_GT(tilings
->num_tilings(), 0u);
764 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
765 VerifyAllPrioritizedTilesExistAndHavePile(tilings
->tiling_at(i
),
769 TEST_F(PictureLayerImplTest
, UpdateTilesCreatesTilings
) {
770 gfx::Size
tile_size(400, 400);
771 gfx::Size
layer_bounds(1300, 1900);
773 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
774 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
775 scoped_refptr
<FakePicturePileImpl
> active_pile
=
776 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
778 SetupTrees(pending_pile
, active_pile
);
780 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
781 EXPECT_LT(low_res_factor
, 1.f
);
783 active_layer_
->ReleaseResources();
784 EXPECT_FALSE(active_layer_
->tilings());
785 active_layer_
->RecreateResources();
786 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
788 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
789 6.f
, // ideal contents scale
792 1.f
, // maximum animation scale
793 0.f
, // starting animation scale
795 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
797 active_layer_
->tilings()->tiling_at(0)->contents_scale());
798 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
799 active_layer_
->tilings()->tiling_at(1)->contents_scale());
801 // If we change the page scale factor, then we should get new tilings.
802 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
803 6.6f
, // ideal contents scale
806 1.f
, // maximum animation scale
807 0.f
, // starting animation scale
809 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
810 EXPECT_FLOAT_EQ(6.6f
,
811 active_layer_
->tilings()->tiling_at(0)->contents_scale());
812 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
813 active_layer_
->tilings()->tiling_at(2)->contents_scale());
815 // If we change the device scale factor, then we should get new tilings.
816 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
817 7.26f
, // ideal contents scale
818 3.3f
, // device scale
820 1.f
, // maximum animation scale
821 0.f
, // starting animation scale
823 ASSERT_EQ(6u, active_layer_
->tilings()->num_tilings());
824 EXPECT_FLOAT_EQ(7.26f
,
825 active_layer_
->tilings()->tiling_at(0)->contents_scale());
826 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
827 active_layer_
->tilings()->tiling_at(3)->contents_scale());
829 // If we change the device scale factor, but end up at the same total scale
830 // factor somehow, then we don't get new tilings.
831 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
832 7.26f
, // ideal contents scale
833 2.2f
, // device scale
835 1.f
, // maximum animation scale
836 0.f
, // starting animation scale
838 ASSERT_EQ(6u, active_layer_
->tilings()->num_tilings());
839 EXPECT_FLOAT_EQ(7.26f
,
840 active_layer_
->tilings()->tiling_at(0)->contents_scale());
841 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
842 active_layer_
->tilings()->tiling_at(3)->contents_scale());
845 TEST_F(PictureLayerImplTest
, PendingLayerOnlyHasHighAndLowResTiling
) {
846 gfx::Size
tile_size(400, 400);
847 gfx::Size
layer_bounds(1300, 1900);
849 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
850 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
851 scoped_refptr
<FakePicturePileImpl
> active_pile
=
852 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
854 SetupTrees(pending_pile
, active_pile
);
856 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
857 EXPECT_LT(low_res_factor
, 1.f
);
859 pending_layer_
->ReleaseResources();
860 EXPECT_FALSE(pending_layer_
->tilings());
861 pending_layer_
->RecreateResources();
862 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
864 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
865 6.f
, // ideal contents scale
868 1.f
, // maximum animation scale
869 0.f
, // starting animation scale
871 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
873 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
874 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
875 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
877 // If we change the page scale factor, then we should get new tilings.
878 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
879 6.6f
, // ideal contents scale
882 1.f
, // maximum animation scale
883 0.f
, // starting animation scale
885 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
886 EXPECT_FLOAT_EQ(6.6f
,
887 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
888 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
889 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
891 // If we change the device scale factor, then we should get new tilings.
892 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
893 7.26f
, // ideal contents scale
894 3.3f
, // device scale
896 1.f
, // maximum animation scale
897 0.f
, // starting animation scale
899 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
900 EXPECT_FLOAT_EQ(7.26f
,
901 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
902 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
903 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
905 // If we change the device scale factor, but end up at the same total scale
906 // factor somehow, then we don't get new tilings.
907 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
908 7.26f
, // ideal contents scale
909 2.2f
, // device scale
911 1.f
, // maximum animation scale
912 0.f
, // starting animation scale
914 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
915 EXPECT_FLOAT_EQ(7.26f
,
916 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
917 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
918 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
921 TEST_F(PictureLayerImplTest
, CreateTilingsEvenIfTwinHasNone
) {
922 // This test makes sure that if a layer can have tilings, then a commit makes
923 // it not able to have tilings (empty size), and then a future commit that
924 // makes it valid again should be able to create tilings.
925 gfx::Size
tile_size(400, 400);
926 gfx::Size
layer_bounds(1300, 1900);
928 scoped_refptr
<FakePicturePileImpl
> empty_pile
=
929 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
930 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
931 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
933 SetupPendingTree(valid_pile
);
934 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
937 SetupPendingTree(empty_pile
);
938 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
939 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
940 ASSERT_EQ(0u, pending_layer_
->tilings()->num_tilings());
943 EXPECT_FALSE(active_layer_
->CanHaveTilings());
944 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
946 SetupPendingTree(valid_pile
);
947 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
948 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
951 TEST_F(PictureLayerImplTest
, ZoomOutCrash
) {
952 gfx::Size
tile_size(400, 400);
953 gfx::Size
layer_bounds(1300, 1900);
955 // Set up the high and low res tilings before pinch zoom.
956 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
957 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
958 scoped_refptr
<FakePicturePileImpl
> active_pile
=
959 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
961 SetupTrees(pending_pile
, active_pile
);
962 ResetTilingsAndRasterScales();
963 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
964 SetContentsScaleOnBothLayers(32.0f
, 1.0f
, 32.0f
, 1.0f
, 0.f
, false);
965 EXPECT_EQ(32.f
, active_layer_
->HighResTiling()->contents_scale());
966 host_impl_
.PinchGestureBegin();
967 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.f
, false);
968 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.f
, false);
969 EXPECT_EQ(active_layer_
->tilings()->NumHighResTilings(), 1);
972 TEST_F(PictureLayerImplTest
, PinchGestureTilings
) {
973 gfx::Size
tile_size(400, 400);
974 gfx::Size
layer_bounds(1300, 1900);
976 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
978 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
979 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
980 scoped_refptr
<FakePicturePileImpl
> active_pile
=
981 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
983 // Set up the high and low res tilings before pinch zoom.
984 SetupTrees(pending_pile
, active_pile
);
985 ResetTilingsAndRasterScales();
987 SetContentsScaleOnBothLayers(2.f
, 1.0f
, 2.f
, 1.0f
, 0.f
, false);
988 EXPECT_BOTH_EQ(num_tilings(), 2u);
989 EXPECT_BOTH_EQ(tilings()->tiling_at(0)->contents_scale(), 2.f
);
990 EXPECT_BOTH_EQ(tilings()->tiling_at(1)->contents_scale(),
991 2.f
* low_res_factor
);
993 // Ensure UpdateTiles won't remove any tilings.
994 active_layer_
->MarkAllTilingsUsed();
996 // Start a pinch gesture.
997 host_impl_
.PinchGestureBegin();
999 // Zoom out by a small amount. We should create a tiling at half
1000 // the scale (2/kMaxScaleRatioDuringPinch).
1001 SetContentsScaleOnBothLayers(1.8f
, 1.0f
, 1.8f
, 1.0f
, 0.f
, false);
1002 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1003 EXPECT_FLOAT_EQ(2.0f
,
1004 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1005 EXPECT_FLOAT_EQ(1.0f
,
1006 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1007 EXPECT_FLOAT_EQ(2.0f
* low_res_factor
,
1008 active_layer_
->tilings()->tiling_at(2)->contents_scale());
1010 // Ensure UpdateTiles won't remove any tilings.
1011 active_layer_
->MarkAllTilingsUsed();
1013 // Zoom out further, close to our low-res scale factor. We should
1014 // use that tiling as high-res, and not create a new tiling.
1015 SetContentsScaleOnBothLayers(low_res_factor
* 2.1f
, 1.0f
,
1016 low_res_factor
* 2.1f
, 1.0f
, 0.f
, false);
1017 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1019 // Zoom in a lot now. Since we increase by increments of
1020 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0.
1021 SetContentsScaleOnBothLayers(3.8f
, 1.0f
, 3.8f
, 1.f
, 0.f
, false);
1022 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
1023 EXPECT_FLOAT_EQ(4.0f
,
1024 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1027 TEST_F(PictureLayerImplTest
, SnappedTilingDuringZoom
) {
1028 gfx::Size
tile_size(300, 300);
1029 gfx::Size
layer_bounds(2600, 3800);
1031 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1032 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1033 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1034 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1036 SetupTrees(pending_pile
, active_pile
);
1038 ResetTilingsAndRasterScales();
1039 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1041 // Set up the high and low res tilings before pinch zoom.
1042 SetContentsScaleOnBothLayers(0.24f
, 1.0f
, 0.24f
, 1.0f
, 0.f
, false);
1043 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1044 EXPECT_FLOAT_EQ(0.24f
,
1045 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1046 EXPECT_FLOAT_EQ(0.0625f
,
1047 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1049 // Ensure UpdateTiles won't remove any tilings.
1050 active_layer_
->MarkAllTilingsUsed();
1052 // Start a pinch gesture.
1053 host_impl_
.PinchGestureBegin();
1055 // Zoom out by a small amount. We should create a tiling at half
1056 // the scale (1/kMaxScaleRatioDuringPinch).
1057 SetContentsScaleOnBothLayers(0.2f
, 1.0f
, 0.2f
, 1.0f
, 0.f
, false);
1058 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1059 EXPECT_FLOAT_EQ(0.24f
,
1060 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1061 EXPECT_FLOAT_EQ(0.12f
,
1062 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1063 EXPECT_FLOAT_EQ(0.0625,
1064 active_layer_
->tilings()->tiling_at(2)->contents_scale());
1066 // Ensure UpdateTiles won't remove any tilings.
1067 active_layer_
->MarkAllTilingsUsed();
1069 // Zoom out further, close to our low-res scale factor. We should
1070 // use that tiling as high-res, and not create a new tiling.
1071 SetContentsScaleOnBothLayers(0.1f
, 1.0f
, 0.1f
, 1.0f
, 0.f
, false);
1072 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1074 // Zoom in. 0.25(desired_scale) should be snapped to 0.24 during zoom-in
1075 // because 0.25(desired_scale) is within the ratio(1.2).
1076 SetContentsScaleOnBothLayers(0.25f
, 1.0f
, 0.25f
, 1.0f
, 0.f
, false);
1077 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1079 // Zoom in a lot. Since we move in factors of two, we should get a scale that
1080 // is a power of 2 times 0.24.
1081 SetContentsScaleOnBothLayers(1.f
, 1.0f
, 1.f
, 1.0f
, 0.f
, false);
1082 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
1083 EXPECT_FLOAT_EQ(1.92f
,
1084 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1087 TEST_F(PictureLayerImplTest
, CleanUpTilings
) {
1088 gfx::Size
tile_size(400, 400);
1089 gfx::Size
layer_bounds(1300, 1900);
1091 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1092 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1093 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1094 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1096 std::vector
<PictureLayerTiling
*> used_tilings
;
1098 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1099 EXPECT_LT(low_res_factor
, 1.f
);
1102 float page_scale
= 1.f
;
1104 SetupTrees(pending_pile
, active_pile
);
1105 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1106 EXPECT_EQ(1.f
, active_layer_
->HighResTiling()->contents_scale());
1108 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
1109 // |used_tilings| variable, and it's here only to ensure that active_layer_
1110 // won't remove tilings before the test has a chance to verify behavior.
1111 active_layer_
->MarkAllTilingsUsed();
1113 // We only have ideal tilings, so they aren't removed.
1114 used_tilings
.clear();
1115 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1116 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1118 host_impl_
.PinchGestureBegin();
1120 // Changing the ideal but not creating new tilings.
1123 SetContentsScaleOnBothLayers(scale
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1124 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1126 // The tilings are still our target scale, so they aren't removed.
1127 used_tilings
.clear();
1128 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1129 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
1131 host_impl_
.PinchGestureEnd();
1133 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
1136 SetContentsScaleOnBothLayers(1.2f
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1137 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
1140 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1142 1.f
* low_res_factor
,
1143 active_layer_
->tilings()->tiling_at(3)->contents_scale());
1145 // Ensure UpdateTiles won't remove any tilings.
1146 active_layer_
->MarkAllTilingsUsed();
1148 // Mark the non-ideal tilings as used. They won't be removed.
1149 used_tilings
.clear();
1150 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1151 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(3));
1152 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1153 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
1155 // Now move the ideal scale to 0.5. Our target stays 1.2.
1156 SetContentsScaleOnBothLayers(0.5f
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1158 // The high resolution tiling is between target and ideal, so is not
1159 // removed. The low res tiling for the old ideal=1.0 scale is removed.
1160 used_tilings
.clear();
1161 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1162 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1164 // Now move the ideal scale to 1.0. Our target stays 1.2.
1165 SetContentsScaleOnBothLayers(1.f
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1167 // All the tilings are between are target and the ideal, so they are not
1169 used_tilings
.clear();
1170 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1171 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1173 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
1174 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.1f
, 1.f
, page_scale
, 1.f
,
1177 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1178 // in the range [1.0,1.2] and are kept.
1179 used_tilings
.clear();
1180 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1181 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1183 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1185 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.1f
, 1.f
, page_scale
, 1.f
,
1188 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1189 // target raster scale. But it is in our used tilings set, so nothing is
1191 used_tilings
.clear();
1192 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1193 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1194 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1196 // If we remove it from our used tilings set, it is outside the range to keep
1197 // so it is deleted.
1198 used_tilings
.clear();
1199 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1200 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
1203 TEST_F(PictureLayerImplTest
, DontAddLowResDuringAnimation
) {
1204 // Make sure this layer covers multiple tiles, since otherwise low
1205 // res won't get created because it is too small.
1206 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1207 // Avoid max untiled layer size heuristics via fixed tile size.
1208 gfx::Size
layer_bounds(tile_size
.width() + 1, tile_size
.height() + 1);
1209 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
1211 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1212 float contents_scale
= 1.f
;
1213 float device_scale
= 1.f
;
1214 float page_scale
= 1.f
;
1215 float maximum_animation_scale
= 1.f
;
1216 float starting_animation_scale
= 0.f
;
1217 bool animating_transform
= true;
1219 ResetTilingsAndRasterScales();
1221 // Animating, so don't create low res even if there isn't one already.
1222 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1223 maximum_animation_scale
,
1224 starting_animation_scale
, animating_transform
);
1225 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1226 EXPECT_BOTH_EQ(num_tilings(), 1u);
1228 // Stop animating, low res gets created.
1229 animating_transform
= false;
1230 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1231 maximum_animation_scale
,
1232 starting_animation_scale
, animating_transform
);
1233 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1234 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor
);
1235 EXPECT_BOTH_EQ(num_tilings(), 2u);
1237 // Ensure UpdateTiles won't remove any tilings.
1238 active_layer_
->MarkAllTilingsUsed();
1240 // Page scale animation, new high res, but no low res. We still have
1241 // a tiling at the previous scale, it's just not marked as low res on the
1242 // active layer. The pending layer drops non-ideal tilings.
1243 contents_scale
= 2.f
;
1245 maximum_animation_scale
= 2.f
;
1246 animating_transform
= true;
1247 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1248 maximum_animation_scale
,
1249 starting_animation_scale
, animating_transform
);
1250 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1251 EXPECT_FALSE(active_layer_
->LowResTiling());
1252 EXPECT_FALSE(pending_layer_
->LowResTiling());
1253 EXPECT_EQ(3u, active_layer_
->num_tilings());
1254 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1256 // Stop animating, new low res gets created for final page scale.
1257 animating_transform
= false;
1258 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1259 maximum_animation_scale
,
1260 starting_animation_scale
, animating_transform
);
1261 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1262 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f
* low_res_factor
);
1263 EXPECT_EQ(4u, active_layer_
->num_tilings());
1264 EXPECT_EQ(2u, pending_layer_
->num_tilings());
1267 TEST_F(PictureLayerImplTest
, DontAddLowResForSmallLayers
) {
1268 gfx::Size
layer_bounds(host_impl_
.settings().default_tile_size
);
1269 gfx::Size
tile_size(100, 100);
1271 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1272 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1273 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1274 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1276 SetupTrees(pending_pile
, active_pile
);
1278 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1279 float device_scale
= 1.f
;
1280 float page_scale
= 1.f
;
1281 float maximum_animation_scale
= 1.f
;
1282 float starting_animation_scale
= 0.f
;
1283 bool animating_transform
= false;
1285 // Contents exactly fit on one tile at scale 1, no low res.
1286 float contents_scale
= 1.f
;
1287 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1288 maximum_animation_scale
,
1289 starting_animation_scale
, animating_transform
);
1290 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1291 EXPECT_BOTH_EQ(num_tilings(), 1u);
1293 ResetTilingsAndRasterScales();
1295 // Contents that are smaller than one tile, no low res.
1296 contents_scale
= 0.123f
;
1297 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1298 maximum_animation_scale
,
1299 starting_animation_scale
, animating_transform
);
1300 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1301 EXPECT_BOTH_EQ(num_tilings(), 1u);
1303 ResetTilingsAndRasterScales();
1305 // Any content bounds that would create more than one tile will
1306 // generate a low res tiling.
1307 contents_scale
= 2.5f
;
1308 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1309 maximum_animation_scale
,
1310 starting_animation_scale
, animating_transform
);
1311 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1312 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1313 contents_scale
* low_res_factor
);
1314 EXPECT_BOTH_EQ(num_tilings(), 2u);
1316 // Mask layers dont create low res since they always fit on one tile.
1317 scoped_ptr
<FakePictureLayerImpl
> mask
=
1318 FakePictureLayerImpl::CreateMaskWithRasterSource(
1319 host_impl_
.pending_tree(), 3, pending_pile
);
1320 mask
->SetBounds(layer_bounds
);
1321 mask
->SetDrawsContent(true);
1323 SetupDrawPropertiesAndUpdateTiles(
1324 mask
.get(), contents_scale
, device_scale
, page_scale
,
1325 maximum_animation_scale
, starting_animation_scale
, animating_transform
);
1326 EXPECT_EQ(mask
->HighResTiling()->contents_scale(), contents_scale
);
1327 EXPECT_EQ(mask
->num_tilings(), 1u);
1330 TEST_F(PictureLayerImplTest
, HugeMasksGetScaledDown
) {
1331 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1333 gfx::Size
tile_size(100, 100);
1334 gfx::Size
layer_bounds(1000, 1000);
1336 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1337 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1338 SetupPendingTree(valid_pile
);
1340 scoped_ptr
<FakePictureLayerImpl
> mask_ptr
=
1341 FakePictureLayerImpl::CreateMaskWithRasterSource(
1342 host_impl_
.pending_tree(), 3, valid_pile
);
1343 mask_ptr
->SetBounds(layer_bounds
);
1344 mask_ptr
->SetDrawsContent(true);
1345 pending_layer_
->SetMaskLayer(mask_ptr
.Pass());
1346 pending_layer_
->SetHasRenderSurface(true);
1348 host_impl_
.pending_tree()->BuildPropertyTreesForTesting();
1349 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1350 bool update_lcd_text
= false;
1351 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1353 FakePictureLayerImpl
* pending_mask
=
1354 static_cast<FakePictureLayerImpl
*>(pending_layer_
->mask_layer());
1356 EXPECT_EQ(1.f
, pending_mask
->HighResTiling()->contents_scale());
1357 EXPECT_EQ(1u, pending_mask
->num_tilings());
1359 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1360 pending_mask
->HighResTiling()->AllTilesForTesting());
1364 FakePictureLayerImpl
* active_mask
=
1365 static_cast<FakePictureLayerImpl
*>(active_layer_
->mask_layer());
1367 // Mask layers have a tiling with a single tile in it.
1368 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1369 // The mask resource exists.
1370 ResourceId mask_resource_id
;
1371 gfx::Size mask_texture_size
;
1372 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1373 EXPECT_NE(0u, mask_resource_id
);
1374 EXPECT_EQ(active_mask
->bounds(), mask_texture_size
);
1376 // Drop resources and recreate them, still the same.
1377 pending_mask
->ReleaseResources();
1378 active_mask
->ReleaseResources();
1379 pending_mask
->RecreateResources();
1380 active_mask
->RecreateResources();
1381 SetupDrawPropertiesAndUpdateTiles(active_mask
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1383 active_mask
->HighResTiling()->CreateAllTilesForTesting();
1384 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1385 EXPECT_NE(0u, mask_resource_id
);
1386 EXPECT_EQ(active_mask
->bounds(), mask_texture_size
);
1388 // Resize larger than the max texture size.
1389 int max_texture_size
= host_impl_
.GetRendererCapabilities().max_texture_size
;
1390 gfx::Size
huge_bounds(max_texture_size
+ 1, 10);
1391 scoped_refptr
<FakePicturePileImpl
> huge_pile
=
1392 FakePicturePileImpl::CreateFilledPile(tile_size
, huge_bounds
);
1394 SetupPendingTree(huge_pile
);
1395 pending_mask
->SetBounds(huge_bounds
);
1396 pending_mask
->SetRasterSourceOnPending(huge_pile
, Region());
1398 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1399 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1401 // The mask tiling gets scaled down.
1402 EXPECT_LT(pending_mask
->HighResTiling()->contents_scale(), 1.f
);
1403 EXPECT_EQ(1u, pending_mask
->num_tilings());
1405 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1406 pending_mask
->HighResTiling()->AllTilesForTesting());
1410 // Mask layers have a tiling with a single tile in it.
1411 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1412 // The mask resource exists.
1413 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1414 EXPECT_NE(0u, mask_resource_id
);
1415 gfx::Size expected_size
= active_mask
->bounds();
1416 expected_size
.SetToMin(gfx::Size(max_texture_size
, max_texture_size
));
1417 EXPECT_EQ(expected_size
, mask_texture_size
);
1419 // Drop resources and recreate them, still the same.
1420 pending_mask
->ReleaseResources();
1421 active_mask
->ReleaseResources();
1422 pending_mask
->RecreateResources();
1423 active_mask
->RecreateResources();
1424 SetupDrawPropertiesAndUpdateTiles(active_mask
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1426 active_mask
->HighResTiling()->CreateAllTilesForTesting();
1427 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1428 EXPECT_NE(0u, mask_resource_id
);
1429 EXPECT_EQ(expected_size
, mask_texture_size
);
1431 // Do another activate, the same holds.
1432 SetupPendingTree(huge_pile
);
1434 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1435 active_layer_
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1436 EXPECT_EQ(expected_size
, mask_texture_size
);
1437 EXPECT_EQ(0u, mask_resource_id
);
1439 // Resize even larger, so that the scale would be smaller than the minimum
1440 // contents scale. Then the layer should no longer have any tiling.
1441 float min_contents_scale
= host_impl_
.settings().minimum_contents_scale
;
1442 gfx::Size
extra_huge_bounds(max_texture_size
/ min_contents_scale
+ 1, 10);
1443 scoped_refptr
<FakePicturePileImpl
> extra_huge_pile
=
1444 FakePicturePileImpl::CreateFilledPile(tile_size
, extra_huge_bounds
);
1446 SetupPendingTree(extra_huge_pile
);
1447 pending_mask
->SetBounds(extra_huge_bounds
);
1448 pending_mask
->SetRasterSourceOnPending(extra_huge_pile
, Region());
1450 EXPECT_FALSE(pending_mask
->CanHaveTilings());
1452 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1453 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1455 EXPECT_EQ(0u, pending_mask
->num_tilings());
1458 TEST_F(PictureLayerImplTest
, ScaledMaskLayer
) {
1459 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1461 gfx::Size
tile_size(100, 100);
1462 gfx::Size
layer_bounds(1000, 1000);
1464 host_impl_
.SetDeviceScaleFactor(1.3f
);
1466 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1467 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1468 SetupPendingTree(valid_pile
);
1470 scoped_ptr
<FakePictureLayerImpl
> mask_ptr
=
1471 FakePictureLayerImpl::CreateMaskWithRasterSource(
1472 host_impl_
.pending_tree(), 3, valid_pile
);
1473 mask_ptr
->SetBounds(layer_bounds
);
1474 mask_ptr
->SetDrawsContent(true);
1475 pending_layer_
->SetMaskLayer(mask_ptr
.Pass());
1476 pending_layer_
->SetHasRenderSurface(true);
1478 host_impl_
.pending_tree()->BuildPropertyTreesForTesting();
1479 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1480 bool update_lcd_text
= false;
1481 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1483 FakePictureLayerImpl
* pending_mask
=
1484 static_cast<FakePictureLayerImpl
*>(pending_layer_
->mask_layer());
1486 // Masks are scaled, and do not have a low res tiling.
1487 EXPECT_EQ(1.3f
, pending_mask
->HighResTiling()->contents_scale());
1488 EXPECT_EQ(1u, pending_mask
->num_tilings());
1490 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1491 pending_mask
->HighResTiling()->AllTilesForTesting());
1495 FakePictureLayerImpl
* active_mask
=
1496 static_cast<FakePictureLayerImpl
*>(active_layer_
->mask_layer());
1498 // Mask layers have a tiling with a single tile in it.
1499 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1500 // The mask resource exists.
1501 ResourceId mask_resource_id
;
1502 gfx::Size mask_texture_size
;
1503 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1504 EXPECT_NE(0u, mask_resource_id
);
1505 gfx::Size expected_mask_texture_size
=
1506 gfx::ToCeiledSize(gfx::ScaleSize(active_mask
->bounds(), 1.3f
));
1507 EXPECT_EQ(mask_texture_size
, expected_mask_texture_size
);
1510 TEST_F(PictureLayerImplTest
, ReleaseResources
) {
1511 gfx::Size
tile_size(400, 400);
1512 gfx::Size
layer_bounds(1300, 1900);
1514 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1515 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1516 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1517 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1519 SetupTrees(pending_pile
, active_pile
);
1520 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1522 // All tilings should be removed when losing output surface.
1523 active_layer_
->ReleaseResources();
1524 EXPECT_FALSE(active_layer_
->tilings());
1525 active_layer_
->RecreateResources();
1526 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1527 pending_layer_
->ReleaseResources();
1528 EXPECT_FALSE(pending_layer_
->tilings());
1529 pending_layer_
->RecreateResources();
1530 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1532 // This should create new tilings.
1533 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
1534 1.f
, // ideal contents scale
1535 1.f
, // device scale
1537 1.f
, // maximum animation scale
1538 0.f
, // starting animation_scale
1540 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1543 TEST_F(PictureLayerImplTest
, ClampTilesToMaxTileSize
) {
1544 // The default max tile size is larger than 400x400.
1545 gfx::Size
tile_size(400, 400);
1546 gfx::Size
layer_bounds(5000, 5000);
1548 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1549 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1551 SetupPendingTree(pending_pile
);
1552 EXPECT_GE(pending_layer_
->tilings()->num_tilings(), 1u);
1554 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1556 // The default value.
1557 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1558 host_impl_
.settings().default_tile_size
.ToString());
1560 Tile
* tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1561 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1562 tile
->content_rect().size().ToString());
1564 ResetTilingsAndRasterScales();
1566 // Change the max texture size on the output surface context.
1567 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1568 TestWebGraphicsContext3D::Create();
1569 context
->set_max_texture_size(140);
1570 host_impl_
.DidLoseOutputSurface();
1571 host_impl_
.InitializeRenderer(
1572 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1574 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1576 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1578 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1580 // Verify the tiles are not larger than the context's max texture size.
1581 tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1582 EXPECT_GE(140, tile
->content_rect().width());
1583 EXPECT_GE(140, tile
->content_rect().height());
1586 TEST_F(PictureLayerImplTest
, ClampSingleTileToToMaxTileSize
) {
1587 // The default max tile size is larger than 400x400.
1588 gfx::Size
tile_size(400, 400);
1589 gfx::Size
layer_bounds(500, 500);
1591 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1592 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1593 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1594 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1596 SetupTrees(pending_pile
, active_pile
);
1597 EXPECT_GE(active_layer_
->tilings()->num_tilings(), 1u);
1599 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1601 // The default value. The layer is smaller than this.
1602 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1603 host_impl_
.settings().max_untiled_layer_size
.ToString());
1605 // There should be a single tile since the layer is small.
1606 PictureLayerTiling
* high_res_tiling
= active_layer_
->tilings()->tiling_at(0);
1607 EXPECT_EQ(1u, high_res_tiling
->AllTilesForTesting().size());
1609 ResetTilingsAndRasterScales();
1611 // Change the max texture size on the output surface context.
1612 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1613 TestWebGraphicsContext3D::Create();
1614 context
->set_max_texture_size(140);
1615 host_impl_
.DidLoseOutputSurface();
1616 host_impl_
.InitializeRenderer(
1617 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1619 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1621 ASSERT_LE(1u, active_layer_
->tilings()->num_tilings());
1623 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1625 // There should be more than one tile since the max texture size won't cover
1627 high_res_tiling
= active_layer_
->tilings()->tiling_at(0);
1628 EXPECT_LT(1u, high_res_tiling
->AllTilesForTesting().size());
1630 // Verify the tiles are not larger than the context's max texture size.
1631 Tile
* tile
= active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1632 EXPECT_GE(140, tile
->content_rect().width());
1633 EXPECT_GE(140, tile
->content_rect().height());
1636 TEST_F(PictureLayerImplTest
, DisallowTileDrawQuads
) {
1637 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1639 gfx::Size
tile_size(400, 400);
1640 gfx::Size
layer_bounds(1300, 1900);
1642 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1643 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1644 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1645 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1647 gfx::Rect
layer_invalidation(150, 200, 30, 180);
1648 SetupTreesWithInvalidation(pending_pile
, active_pile
, layer_invalidation
);
1650 active_layer_
->draw_properties().visible_layer_rect
= gfx::Rect(layer_bounds
);
1652 AppendQuadsData data
;
1653 active_layer_
->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE
, nullptr);
1654 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1655 active_layer_
->DidDraw(nullptr);
1657 ASSERT_EQ(1U, render_pass
->quad_list
.size());
1658 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
,
1659 render_pass
->quad_list
.front()->material
);
1662 TEST_F(PictureLayerImplTest
, SolidColorLayerHasVisibleFullCoverage
) {
1663 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1665 gfx::Size
tile_size(1000, 1000);
1666 gfx::Size
layer_bounds(1500, 1500);
1667 gfx::Rect
visible_rect(250, 250, 1000, 1000);
1669 scoped_ptr
<FakePicturePile
> empty_recording
=
1670 FakePicturePile::CreateEmptyPile(tile_size
, layer_bounds
);
1671 empty_recording
->SetIsSolidColor(true);
1673 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1674 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
1675 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1676 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
1678 SetupTrees(pending_pile
, active_pile
);
1680 active_layer_
->draw_properties().visible_layer_rect
= visible_rect
;
1682 AppendQuadsData data
;
1683 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1684 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1685 active_layer_
->DidDraw(nullptr);
1687 Region remaining
= visible_rect
;
1688 for (const auto& quad
: render_pass
->quad_list
) {
1689 EXPECT_TRUE(visible_rect
.Contains(quad
->rect
));
1690 EXPECT_TRUE(remaining
.Contains(quad
->rect
));
1691 remaining
.Subtract(quad
->rect
);
1694 EXPECT_TRUE(remaining
.IsEmpty());
1697 TEST_F(PictureLayerImplTest
, TileScalesWithSolidColorPile
) {
1698 gfx::Size
layer_bounds(200, 200);
1699 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1700 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1701 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1702 tile_size
, layer_bounds
, false);
1703 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1704 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1705 tile_size
, layer_bounds
, true);
1707 SetupTrees(pending_pile
, active_pile
);
1708 // Solid color pile should not allow tilings at any scale.
1709 EXPECT_FALSE(active_layer_
->CanHaveTilings());
1710 EXPECT_EQ(0.f
, active_layer_
->ideal_contents_scale());
1712 // Activate non-solid-color pending pile makes active layer can have tilings.
1714 EXPECT_TRUE(active_layer_
->CanHaveTilings());
1715 EXPECT_GT(active_layer_
->ideal_contents_scale(), 0.f
);
1718 TEST_F(NoLowResPictureLayerImplTest
, MarkRequiredOffscreenTiles
) {
1719 gfx::Size
tile_size(100, 100);
1720 gfx::Size
layer_bounds(200, 200);
1722 gfx::Transform transform
;
1723 gfx::Transform transform_for_tile_priority
;
1724 bool resourceless_software_draw
= false;
1725 gfx::Rect
viewport(0, 0, 100, 200);
1726 host_impl_
.SetExternalDrawConstraints(transform
,
1731 resourceless_software_draw
);
1733 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1734 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1735 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1737 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1738 EXPECT_EQ(viewport
, pending_layer_
->visible_rect_for_tile_priority());
1740 base::TimeTicks time_ticks
;
1741 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1742 pending_layer_
->UpdateTiles(resourceless_software_draw
);
1744 int num_visible
= 0;
1745 int num_offscreen
= 0;
1747 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
1748 pending_layer_
->picture_layer_tiling_set(), false));
1749 for (; !queue
->IsEmpty(); queue
->Pop()) {
1750 const PrioritizedTile
& prioritized_tile
= queue
->Top();
1751 DCHECK(prioritized_tile
.tile());
1752 if (prioritized_tile
.priority().distance_to_visible
== 0.f
) {
1753 EXPECT_TRUE(prioritized_tile
.tile()->required_for_activation());
1756 EXPECT_FALSE(prioritized_tile
.tile()->required_for_activation());
1761 EXPECT_GT(num_visible
, 0);
1762 EXPECT_GT(num_offscreen
, 0);
1765 TEST_F(NoLowResPictureLayerImplTest
,
1766 TileOutsideOfViewportForTilePriorityNotRequired
) {
1767 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1769 gfx::Size
tile_size(100, 100);
1770 gfx::Size
layer_bounds(400, 400);
1771 gfx::Rect
external_viewport_for_tile_priority(400, 200);
1772 gfx::Rect
visible_layer_rect(200, 400);
1774 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1775 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1776 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1777 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1778 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
1780 ASSERT_EQ(1u, pending_layer_
->num_tilings());
1781 ASSERT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
1783 // Set external viewport for tile priority.
1784 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
1785 gfx::Transform transform
;
1786 gfx::Transform transform_for_tile_priority
;
1787 bool resourceless_software_draw
= false;
1788 host_impl_
.SetExternalDrawConstraints(transform
,
1791 external_viewport_for_tile_priority
,
1792 transform_for_tile_priority
,
1793 resourceless_software_draw
);
1794 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1795 bool update_lcd_text
= false;
1796 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1798 // Set visible content rect that is different from
1799 // external_viewport_for_tile_priority.
1800 pending_layer_
->draw_properties().visible_layer_rect
= visible_layer_rect
;
1801 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
1802 pending_layer_
->UpdateTiles(resourceless_software_draw
);
1804 // Intersect the two rects. Any tile outside should not be required for
1806 gfx::Rect viewport_for_tile_priority
=
1807 pending_layer_
->viewport_rect_for_tile_priority_in_content_space();
1808 viewport_for_tile_priority
.Intersect(pending_layer_
->visible_layer_rect());
1810 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
1813 int num_outside
= 0;
1814 for (PictureLayerTiling::CoverageIterator
iter(active_layer_
->HighResTiling(),
1815 1.f
, gfx::Rect(layer_bounds
));
1820 if (viewport_for_tile_priority
.Intersects(iter
.geometry_rect())) {
1822 // Mark everything in viewport for tile priority as ready to draw.
1823 TileDrawInfo
& draw_info
= tile
->draw_info();
1824 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
1827 EXPECT_FALSE(tile
->required_for_activation());
1831 EXPECT_GT(num_inside
, 0);
1832 EXPECT_GT(num_outside
, 0);
1834 // Activate and draw active layer.
1835 host_impl_
.ActivateSyncTree();
1836 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
1837 active_layer_
->draw_properties().visible_layer_rect
= visible_layer_rect
;
1839 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1840 AppendQuadsData data
;
1841 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1842 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1843 active_layer_
->DidDraw(nullptr);
1845 // All tiles in activation rect is ready to draw.
1846 EXPECT_EQ(0u, data
.num_missing_tiles
);
1847 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1848 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1851 TEST_F(PictureLayerImplTest
, HighResTileIsComplete
) {
1852 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1854 gfx::Size
tile_size(100, 100);
1855 gfx::Size
layer_bounds(200, 200);
1857 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1858 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1860 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1863 // All high res tiles have resources.
1864 std::vector
<Tile
*> tiles
=
1865 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1866 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
1868 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1869 AppendQuadsData data
;
1870 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1871 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1872 active_layer_
->DidDraw(nullptr);
1874 // All high res tiles drew, nothing was incomplete.
1875 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1876 EXPECT_EQ(0u, data
.num_missing_tiles
);
1877 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1878 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1881 TEST_F(PictureLayerImplTest
, HighResTileIsIncomplete
) {
1882 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1884 gfx::Size
tile_size(100, 100);
1885 gfx::Size
layer_bounds(200, 200);
1887 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1888 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1889 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1892 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1893 AppendQuadsData data
;
1894 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1895 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1896 active_layer_
->DidDraw(nullptr);
1898 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1899 EXPECT_EQ(1u, data
.num_missing_tiles
);
1900 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1901 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1904 TEST_F(PictureLayerImplTest
, HighResTileIsIncompleteLowResComplete
) {
1905 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1907 gfx::Size
tile_size(100, 100);
1908 gfx::Size
layer_bounds(200, 200);
1910 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1911 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1912 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1915 std::vector
<Tile
*> low_tiles
=
1916 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1917 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1919 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1920 AppendQuadsData data
;
1921 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1922 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1923 active_layer_
->DidDraw(nullptr);
1925 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1926 EXPECT_EQ(0u, data
.num_missing_tiles
);
1927 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1928 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1931 TEST_F(PictureLayerImplTest
, LowResTileIsIncomplete
) {
1932 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1934 gfx::Size
tile_size(100, 100);
1935 gfx::Size
layer_bounds(200, 200);
1937 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1938 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1939 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1942 // All high res tiles have resources except one.
1943 std::vector
<Tile
*> high_tiles
=
1944 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1945 high_tiles
.erase(high_tiles
.begin());
1946 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
1948 // All low res tiles have resources.
1949 std::vector
<Tile
*> low_tiles
=
1950 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1951 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1953 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1954 AppendQuadsData data
;
1955 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1956 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1957 active_layer_
->DidDraw(nullptr);
1959 // The missing high res tile was replaced by a low res tile.
1960 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1961 EXPECT_EQ(0u, data
.num_missing_tiles
);
1962 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1963 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1966 TEST_F(PictureLayerImplTest
,
1967 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal
) {
1968 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1970 gfx::Size
tile_size(100, 100);
1971 gfx::Size
layer_bounds(200, 200);
1972 gfx::Size
viewport_size(400, 400);
1974 host_impl_
.SetViewportSize(viewport_size
);
1975 host_impl_
.SetDeviceScaleFactor(2.f
);
1977 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1978 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1979 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1980 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1981 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
1983 // One ideal tile exists, this will get used when drawing.
1984 std::vector
<Tile
*> ideal_tiles
;
1985 EXPECT_EQ(2.f
, active_layer_
->HighResTiling()->contents_scale());
1986 ideal_tiles
.push_back(active_layer_
->HighResTiling()->TileAt(0, 0));
1987 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1990 // Due to layer scale throttling, the raster contents scale is changed to 1,
1991 // while the ideal is still 2.
1992 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1994 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1997 EXPECT_EQ(1.f
, active_layer_
->HighResTiling()->contents_scale());
1998 EXPECT_EQ(1.f
, active_layer_
->raster_contents_scale());
1999 EXPECT_EQ(2.f
, active_layer_
->ideal_contents_scale());
2001 // Both tilings still exist.
2002 EXPECT_EQ(2.f
, active_layer_
->tilings()->tiling_at(0)->contents_scale());
2003 EXPECT_EQ(1.f
, active_layer_
->tilings()->tiling_at(1)->contents_scale());
2005 // All high res tiles have resources.
2006 std::vector
<Tile
*> high_tiles
=
2007 active_layer_
->HighResTiling()->AllTilesForTesting();
2008 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
2010 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
2011 AppendQuadsData data
;
2012 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
2013 active_layer_
->AppendQuads(render_pass
.get(), &data
);
2014 active_layer_
->DidDraw(nullptr);
2016 // All high res tiles drew, and the one ideal res tile drew.
2017 ASSERT_GT(render_pass
->quad_list
.size(), 9u);
2018 EXPECT_EQ(gfx::SizeF(99.f
, 99.f
),
2019 TileDrawQuad::MaterialCast(render_pass
->quad_list
.front())
2020 ->tex_coord_rect
.size());
2021 EXPECT_EQ(gfx::SizeF(49.5f
, 49.5f
),
2022 TileDrawQuad::MaterialCast(render_pass
->quad_list
.ElementAt(1))
2023 ->tex_coord_rect
.size());
2025 // Neither the high res nor the ideal tiles were considered as incomplete.
2026 EXPECT_EQ(0u, data
.num_missing_tiles
);
2027 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
2028 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
2031 TEST_F(PictureLayerImplTest
, HighResRequiredWhenActiveAllReady
) {
2032 gfx::Size
layer_bounds(400, 400);
2033 gfx::Size
tile_size(100, 100);
2035 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
,
2036 gfx::Rect(layer_bounds
));
2038 active_layer_
->SetAllTilesReady();
2040 // All active tiles ready, so pending can only activate with all high res
2042 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2043 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2045 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2046 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2049 TEST_F(PictureLayerImplTest
, HighResRequiredWhenMissingHighResFlagOn
) {
2050 gfx::Size
layer_bounds(400, 400);
2051 gfx::Size
tile_size(100, 100);
2054 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2056 // Verify active tree not ready.
2057 Tile
* some_active_tile
=
2058 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2059 EXPECT_FALSE(some_active_tile
->draw_info().IsReadyToDraw());
2061 // When high res are required, all tiles in active high res tiling should be
2062 // required for activation.
2063 host_impl_
.SetRequiresHighResToDraw();
2065 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2066 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2067 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2068 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2070 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
2071 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2072 AssertAllTilesRequired(active_layer_
->HighResTiling());
2073 AssertNoTilesRequired(active_layer_
->LowResTiling());
2076 TEST_F(PictureLayerImplTest
, AllHighResRequiredEvenIfNotChanged
) {
2077 gfx::Size
layer_bounds(400, 400);
2078 gfx::Size
tile_size(100, 100);
2080 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2082 Tile
* some_active_tile
=
2083 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2084 EXPECT_FALSE(some_active_tile
->draw_info().IsReadyToDraw());
2086 // Since there are no invalidations, pending tree should have no tiles.
2087 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
2088 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2090 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2091 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2093 AssertAllTilesRequired(active_layer_
->HighResTiling());
2094 AssertNoTilesRequired(active_layer_
->LowResTiling());
2097 TEST_F(PictureLayerImplTest
, DisallowRequiredForActivation
) {
2098 gfx::Size
layer_bounds(400, 400);
2099 gfx::Size
tile_size(100, 100);
2101 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2103 Tile
* some_active_tile
=
2104 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2105 EXPECT_FALSE(some_active_tile
->draw_info().IsReadyToDraw());
2107 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
2108 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2109 active_layer_
->HighResTiling()->set_can_require_tiles_for_activation(false);
2110 active_layer_
->LowResTiling()->set_can_require_tiles_for_activation(false);
2111 pending_layer_
->HighResTiling()->set_can_require_tiles_for_activation(false);
2112 pending_layer_
->LowResTiling()->set_can_require_tiles_for_activation(false);
2114 // If we disallow required for activation, no tiles can be required.
2115 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2116 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2118 AssertNoTilesRequired(active_layer_
->HighResTiling());
2119 AssertNoTilesRequired(active_layer_
->LowResTiling());
2122 TEST_F(PictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
2123 gfx::Size
layer_bounds(400, 400);
2124 gfx::Size
tile_size(100, 100);
2126 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2127 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2128 // This pile will create tilings, but has no recordings so will not create any
2129 // tiles. This is attempting to simulate scrolling past the end of recorded
2130 // content on the active layer, where the recordings are so far away that
2131 // no tiles are created.
2132 bool is_solid_color
= false;
2133 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2134 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
2135 tile_size
, layer_bounds
, is_solid_color
);
2137 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2139 // Active layer has tilings, but no tiles due to missing recordings.
2140 EXPECT_TRUE(active_layer_
->CanHaveTilings());
2141 EXPECT_EQ(active_layer_
->tilings()->num_tilings(), 2u);
2142 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
2144 // Since the active layer has no tiles at all, the pending layer doesn't
2145 // need content in order to activate.
2146 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2147 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2149 AssertNoTilesRequired(pending_layer_
->HighResTiling());
2150 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2153 TEST_F(PictureLayerImplTest
, HighResRequiredIfActiveCantHaveTiles
) {
2154 gfx::Size
layer_bounds(400, 400);
2155 gfx::Size
tile_size(100, 100);
2157 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2158 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2159 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2160 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
2161 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2163 // Active layer can't have tiles.
2164 EXPECT_FALSE(active_layer_
->CanHaveTilings());
2166 // All high res tiles required. This should be considered identical
2167 // to the case where there is no active layer, to avoid flashing content.
2168 // This can happen if a layer exists for a while and switches from
2169 // not being able to have content to having content.
2170 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2171 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2173 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2174 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2177 TEST_F(PictureLayerImplTest
, HighResRequiredWhenActiveHasDifferentBounds
) {
2178 gfx::Size
pending_layer_bounds(400, 400);
2179 gfx::Size
active_layer_bounds(200, 200);
2180 gfx::Size
tile_size(100, 100);
2182 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2183 FakePicturePileImpl::CreateFilledPile(tile_size
, pending_layer_bounds
);
2184 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2185 FakePicturePileImpl::CreateFilledPile(tile_size
, active_layer_bounds
);
2187 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2189 // Since the active layer has different bounds, the pending layer needs all
2190 // high res tiles in order to activate.
2191 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2192 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2193 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2194 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2196 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2197 AssertAllTilesRequired(active_layer_
->HighResTiling());
2198 AssertNoTilesRequired(active_layer_
->LowResTiling());
2199 // Since the test doesn't invalidate the resized region, we expect that the
2200 // same low res tile would exist (which means we don't create a new one of the
2202 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2205 TEST_F(PictureLayerImplTest
, ActivateUninitializedLayer
) {
2206 gfx::Size
tile_size(100, 100);
2207 gfx::Size
layer_bounds(400, 400);
2208 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2209 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2211 host_impl_
.CreatePendingTree();
2212 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
2214 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
2215 FakePictureLayerImpl::CreateWithRasterSource(pending_tree
, id_
,
2217 pending_layer
->SetDrawsContent(true);
2218 pending_tree
->SetRootLayer(pending_layer
.Pass());
2220 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
2221 host_impl_
.pending_tree()->LayerById(id_
));
2223 // Set some state on the pending layer, make sure it is not clobbered
2224 // by a sync from the active layer. This could happen because if the
2225 // pending layer has not been post-commit initialized it will attempt
2226 // to sync from the active layer.
2227 float raster_page_scale
= 10.f
* pending_layer_
->raster_page_scale();
2228 pending_layer_
->set_raster_page_scale(raster_page_scale
);
2230 host_impl_
.ActivateSyncTree();
2232 active_layer_
= static_cast<FakePictureLayerImpl
*>(
2233 host_impl_
.active_tree()->LayerById(id_
));
2235 EXPECT_EQ(0u, active_layer_
->num_tilings());
2236 EXPECT_EQ(raster_page_scale
, active_layer_
->raster_page_scale());
2239 TEST_F(PictureLayerImplTest
, ShareTilesOnNextFrame
) {
2240 gfx::Size
layer_bounds(1500, 1500);
2241 gfx::Size
tile_size(100, 100);
2243 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2244 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2246 SetupPendingTree(pending_pile
);
2248 PictureLayerTiling
* tiling
= pending_layer_
->HighResTiling();
2249 gfx::Rect first_invalidate
= tiling
->TilingDataForTesting().TileBounds(0, 0);
2250 first_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2251 tiling
->TilingDataForTesting().border_texels());
2252 gfx::Rect second_invalidate
= tiling
->TilingDataForTesting().TileBounds(1, 1);
2253 second_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2254 tiling
->TilingDataForTesting().border_texels());
2258 // Make a pending tree with an invalidated raster tile 0,0.
2259 SetupPendingTreeWithInvalidation(pending_pile
, first_invalidate
);
2261 // Activate and make a pending tree with an invalidated raster tile 1,1.
2264 SetupPendingTreeWithInvalidation(pending_pile
, second_invalidate
);
2266 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2267 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2269 // pending_tiling->CreateAllTilesForTesting();
2271 // Tile 0,0 not exist on pending, but tile 1,1 should.
2272 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2273 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2274 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2275 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2276 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2277 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2278 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2279 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2280 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2282 // Drop the tiles on the active tree and recreate them.
2283 active_tiling
->ComputeTilePriorityRects(gfx::Rect(), 1.f
, 1.0, Occlusion());
2284 EXPECT_TRUE(active_tiling
->AllTilesForTesting().empty());
2285 active_tiling
->CreateAllTilesForTesting();
2287 // Tile 0,0 not exist on pending, but tile 1,1 should.
2288 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2289 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2290 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2291 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2292 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2293 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2294 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2295 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2296 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2299 TEST_F(PictureLayerImplTest
, PendingHasNoTilesWithNoInvalidation
) {
2300 SetupDefaultTrees(gfx::Size(1500, 1500));
2302 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2303 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2306 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2307 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2308 ASSERT_TRUE(active_tiling
);
2309 ASSERT_TRUE(pending_tiling
);
2311 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2312 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2313 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2314 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2316 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2317 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2318 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2319 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
2322 TEST_F(PictureLayerImplTest
, ShareInvalidActiveTreeTiles
) {
2323 gfx::Size
tile_size(100, 100);
2324 gfx::Size
layer_bounds(1500, 1500);
2326 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2327 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2328 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2329 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2330 SetupTreesWithInvalidation(pending_pile
, active_pile
, gfx::Rect(1, 1));
2331 // Activate the invalidation.
2333 // Make another pending tree without any invalidation in it.
2334 scoped_refptr
<FakePicturePileImpl
> pending_pile2
=
2335 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2336 SetupPendingTree(pending_pile2
);
2338 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2339 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2341 // The active tree invalidation was handled by the active tiles.
2342 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2343 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2344 ASSERT_TRUE(active_tiling
);
2345 ASSERT_TRUE(pending_tiling
);
2347 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2348 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2349 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2350 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2352 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2353 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2354 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2355 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
2358 TEST_F(PictureLayerImplTest
, RecreateInvalidPendingTreeTiles
) {
2359 // Set some invalidation on the pending tree. We should replace raster tiles
2361 SetupDefaultTreesWithInvalidation(gfx::Size(1500, 1500), gfx::Rect(1, 1));
2363 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2364 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2366 // The pending tree invalidation creates tiles on the pending tree.
2367 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2368 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2369 ASSERT_TRUE(active_tiling
);
2370 ASSERT_TRUE(pending_tiling
);
2372 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2373 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2374 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2375 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2377 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2378 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2379 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2380 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
2382 EXPECT_NE(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2385 TEST_F(PictureLayerImplTest
, SyncTilingAfterGpuRasterizationToggles
) {
2386 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2388 gfx::Size
tile_size(100, 100);
2389 gfx::Size
layer_bounds(10, 10);
2391 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2392 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2393 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2394 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2396 SetupTrees(pending_pile
, active_pile
);
2398 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2399 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(1.f
));
2401 // Gpu rasterization is disabled by default.
2402 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2403 // Toggling the gpu rasterization clears all tilings on both trees.
2404 host_impl_
.SetHasGpuRasterizationTrigger(true);
2405 host_impl_
.SetContentIsSuitableForGpuRasterization(true);
2406 host_impl_
.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2407 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2408 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2410 // Make sure that we can still add tiling to the pending layer,
2411 // that gets synced to the active layer.
2412 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2413 bool update_lcd_text
= false;
2414 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
2415 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2418 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(1.f
));
2420 SetupPendingTree(pending_pile
);
2421 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2423 // Toggling the gpu rasterization clears all tilings on both trees.
2424 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2425 host_impl_
.SetHasGpuRasterizationTrigger(false);
2426 host_impl_
.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2427 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT
,
2428 host_impl_
.gpu_rasterization_status());
2429 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2430 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2432 host_impl_
.SetHasGpuRasterizationTrigger(true);
2433 host_impl_
.SetContentIsSuitableForGpuRasterization(false);
2434 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT
,
2435 host_impl_
.gpu_rasterization_status());
2438 TEST_F(PictureLayerImplTest
, HighResCreatedWhenBoundsShrink
) {
2439 gfx::Size
tile_size(100, 100);
2441 // Put 0.5 as high res.
2442 host_impl_
.SetDeviceScaleFactor(0.5f
);
2444 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2445 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(10, 10));
2446 SetupPendingTree(pending_pile
);
2449 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2450 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(0.5f
));
2454 // Now, set the bounds to be 1x1, so that minimum contents scale becomes 1.
2456 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(1, 1));
2457 SetupPendingTree(pending_pile
);
2459 // Another sanity check.
2460 EXPECT_EQ(1.f
, pending_layer_
->MinimumContentsScale());
2462 // Since the MinContentsScale is 1, the 0.5 tiling should have been replaced
2463 // by a 1.0 tiling during the UDP in SetupPendingTree.
2464 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2465 PictureLayerTiling
* tiling
=
2466 pending_layer_
->tilings()->FindTilingWithScale(1.0f
);
2467 ASSERT_TRUE(tiling
);
2468 EXPECT_EQ(HIGH_RESOLUTION
, tiling
->resolution());
2471 TEST_F(PictureLayerImplTest
, LowResTilingWithoutGpuRasterization
) {
2472 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
2473 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
2474 default_tile_size
.height() * 4);
2476 host_impl_
.SetHasGpuRasterizationTrigger(false);
2478 SetupDefaultTrees(layer_bounds
);
2479 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2480 // Should have a low-res and a high-res tiling.
2481 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
2484 TEST_F(PictureLayerImplTest
, NoLowResTilingWithGpuRasterization
) {
2485 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
2486 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
2487 default_tile_size
.height() * 4);
2489 host_impl_
.SetHasGpuRasterizationTrigger(true);
2490 host_impl_
.SetContentIsSuitableForGpuRasterization(true);
2492 SetupDefaultTrees(layer_bounds
);
2493 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2494 // Should only have the high-res tiling.
2495 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2498 TEST_F(PictureLayerImplTest
, RequiredTilesWithGpuRasterization
) {
2499 host_impl_
.SetHasGpuRasterizationTrigger(true);
2500 host_impl_
.SetContentIsSuitableForGpuRasterization(true);
2502 gfx::Size
viewport_size(1000, 1000);
2503 host_impl_
.SetViewportSize(viewport_size
);
2505 gfx::Size
layer_bounds(4000, 4000);
2506 SetupDefaultTrees(layer_bounds
);
2507 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2509 // Should only have the high-res tiling.
2510 EXPECT_EQ(1u, active_layer_
->tilings()->num_tilings());
2512 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2514 // High res tiling should have 64 tiles (4x16 tile grid).
2515 EXPECT_EQ(64u, active_layer_
->HighResTiling()->AllTilesForTesting().size());
2517 // Visible viewport should be covered by 4 tiles. No other
2518 // tiles should be required for activation.
2519 EXPECT_EQ(4u, NumberOfTilesRequired(active_layer_
->HighResTiling()));
2522 TEST_F(PictureLayerImplTest
, NoTilingIfDoesNotDrawContent
) {
2523 // Set up layers with tilings.
2524 SetupDefaultTrees(gfx::Size(10, 10));
2525 SetContentsScaleOnBothLayers(1.f
, 1.f
, 1.f
, 1.f
, 0.f
, false);
2526 pending_layer_
->PushPropertiesTo(active_layer_
);
2527 EXPECT_TRUE(pending_layer_
->DrawsContent());
2528 EXPECT_TRUE(pending_layer_
->CanHaveTilings());
2529 EXPECT_GE(pending_layer_
->num_tilings(), 0u);
2530 EXPECT_GE(active_layer_
->num_tilings(), 0u);
2532 // Set content to false, which should make CanHaveTilings return false.
2533 pending_layer_
->SetDrawsContent(false);
2534 EXPECT_FALSE(pending_layer_
->DrawsContent());
2535 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
2537 // No tilings should be pushed to active layer.
2538 pending_layer_
->PushPropertiesTo(active_layer_
);
2539 EXPECT_EQ(0u, active_layer_
->num_tilings());
2542 TEST_F(PictureLayerImplTest
, FirstTilingDuringPinch
) {
2543 SetupDefaultTrees(gfx::Size(10, 10));
2545 // We start with a tiling at scale 1.
2546 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
2548 // When we page scale up by 2.3, we get a new tiling that is a power of 2, in
2550 host_impl_
.PinchGestureBegin();
2551 float high_res_scale
= 2.3f
;
2552 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, high_res_scale
, 1.f
, 0.f
,
2554 EXPECT_EQ(4.f
, pending_layer_
->HighResTiling()->contents_scale());
2557 TEST_F(PictureLayerImplTest
, PinchingTooSmall
) {
2558 SetupDefaultTrees(gfx::Size(10, 10));
2560 // We start with a tiling at scale 1.
2561 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
2563 host_impl_
.PinchGestureBegin();
2564 float high_res_scale
= 0.0001f
;
2565 EXPECT_LT(high_res_scale
, pending_layer_
->MinimumContentsScale());
2567 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, high_res_scale
, 1.f
, 0.f
,
2569 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2570 pending_layer_
->HighResTiling()->contents_scale());
2573 TEST_F(PictureLayerImplTest
, PinchingTooSmallWithContentsScale
) {
2574 SetupDefaultTrees(gfx::Size(10, 10));
2576 ResetTilingsAndRasterScales();
2578 float contents_scale
= 0.15f
;
2579 SetContentsScaleOnBothLayers(contents_scale
, 1.f
, 1.f
, 1.f
, 0.f
, false);
2581 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2582 EXPECT_FLOAT_EQ(contents_scale
,
2583 pending_layer_
->HighResTiling()->contents_scale());
2585 host_impl_
.PinchGestureBegin();
2587 float page_scale
= 0.0001f
;
2588 EXPECT_LT(page_scale
* contents_scale
,
2589 pending_layer_
->MinimumContentsScale());
2591 SetContentsScaleOnBothLayers(contents_scale
* page_scale
, 1.f
, page_scale
,
2593 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2594 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2595 pending_layer_
->HighResTiling()->contents_scale());
2598 TEST_F(PictureLayerImplTest
, ConsiderAnimationStartScaleForRasterScale
) {
2599 gfx::Size
viewport_size(1000, 1000);
2600 host_impl_
.SetViewportSize(viewport_size
);
2602 gfx::Size
layer_bounds(100, 100);
2603 SetupDefaultTrees(layer_bounds
);
2605 float contents_scale
= 2.f
;
2606 float device_scale
= 1.f
;
2607 float page_scale
= 1.f
;
2608 float maximum_animation_scale
= 3.f
;
2609 float starting_animation_scale
= 1.f
;
2610 bool animating_transform
= true;
2612 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2614 // Maximum animation scale is greater than starting animation scale
2615 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2616 maximum_animation_scale
,
2617 starting_animation_scale
, animating_transform
);
2618 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2620 animating_transform
= false;
2622 // Once we stop animating, a new high-res tiling should be created.
2623 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2624 maximum_animation_scale
,
2625 starting_animation_scale
, animating_transform
);
2626 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2628 // Starting animation scale greater than maximum animation scale
2629 // Bounds at starting scale within the viewport
2630 animating_transform
= true;
2631 starting_animation_scale
= 5.f
;
2633 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2634 maximum_animation_scale
,
2635 starting_animation_scale
, animating_transform
);
2636 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 5.f
);
2638 // Once we stop animating, a new high-res tiling should be created.
2639 animating_transform
= false;
2640 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2641 maximum_animation_scale
,
2642 starting_animation_scale
, animating_transform
);
2643 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2645 // Starting Animation scale greater than maximum animation scale
2646 // Bounds at starting scale outisde the viewport
2647 animating_transform
= true;
2648 starting_animation_scale
= 11.f
;
2650 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2651 maximum_animation_scale
,
2652 starting_animation_scale
, animating_transform
);
2653 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2656 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForCpuRasterization
) {
2657 gfx::Size
viewport_size(1000, 1000);
2658 host_impl_
.SetViewportSize(viewport_size
);
2660 gfx::Size
layer_bounds(100, 100);
2661 SetupDefaultTrees(layer_bounds
);
2663 float contents_scale
= 1.f
;
2664 float device_scale
= 1.f
;
2665 float page_scale
= 1.f
;
2666 float maximum_animation_scale
= 1.f
;
2667 float starting_animation_scale
= 0.f
;
2668 bool animating_transform
= false;
2670 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2672 // Since we're CPU-rasterizing, starting an animation should cause tiling
2673 // resolution to get set to the maximum animation scale factor.
2674 animating_transform
= true;
2675 maximum_animation_scale
= 3.f
;
2676 contents_scale
= 2.f
;
2678 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2679 maximum_animation_scale
,
2680 starting_animation_scale
, animating_transform
);
2681 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2682 EXPECT_BOTH_TRUE(GetRasterSource()->ShouldAttemptToUseDistanceFieldText());
2684 // Further changes to scale during the animation should not cause a new
2685 // high-res tiling to get created.
2686 contents_scale
= 4.f
;
2687 maximum_animation_scale
= 5.f
;
2689 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2690 maximum_animation_scale
,
2691 starting_animation_scale
, animating_transform
);
2692 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2694 // Once we stop animating, a new high-res tiling should be created.
2695 animating_transform
= false;
2697 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2698 maximum_animation_scale
,
2699 starting_animation_scale
, animating_transform
);
2700 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2702 // When animating with an unknown maximum animation scale factor, a new
2703 // high-res tiling should be created at a source scale of 1.
2704 animating_transform
= true;
2705 contents_scale
= 2.f
;
2706 maximum_animation_scale
= 0.f
;
2708 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2709 maximum_animation_scale
,
2710 starting_animation_scale
, animating_transform
);
2711 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2713 // Further changes to scale during the animation should not cause a new
2714 // high-res tiling to get created.
2715 contents_scale
= 3.f
;
2717 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2718 maximum_animation_scale
,
2719 starting_animation_scale
, animating_transform
);
2720 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2722 // Once we stop animating, a new high-res tiling should be created.
2723 animating_transform
= false;
2724 contents_scale
= 4.f
;
2726 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2727 maximum_animation_scale
,
2728 starting_animation_scale
, animating_transform
);
2729 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2731 // When animating with a maxmium animation scale factor that is so large
2732 // that the layer grows larger than the viewport at this scale, a new
2733 // high-res tiling should get created at a source scale of 1, not at its
2735 animating_transform
= true;
2736 contents_scale
= 2.f
;
2737 maximum_animation_scale
= 11.f
;
2739 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2740 maximum_animation_scale
,
2741 starting_animation_scale
, animating_transform
);
2742 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2744 // Once we stop animating, a new high-res tiling should be created.
2745 animating_transform
= false;
2746 contents_scale
= 11.f
;
2748 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2749 maximum_animation_scale
,
2750 starting_animation_scale
, animating_transform
);
2751 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2753 // When animating with a maxmium animation scale factor that is so large
2754 // that the layer grows larger than the viewport at this scale, and where
2755 // the intial source scale is < 1, a new high-res tiling should get created
2756 // at source scale 1.
2757 animating_transform
= true;
2758 contents_scale
= 0.1f
;
2759 maximum_animation_scale
= 11.f
;
2761 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2762 maximum_animation_scale
,
2763 starting_animation_scale
, animating_transform
);
2764 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2766 // Once we stop animating, a new high-res tiling should be created.
2767 animating_transform
= false;
2768 contents_scale
= 12.f
;
2770 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2771 maximum_animation_scale
,
2772 starting_animation_scale
, animating_transform
);
2773 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 12.f
);
2775 // When animating toward a smaller scale, but that is still so large that the
2776 // layer grows larger than the viewport at this scale, a new high-res tiling
2777 // should get created at source scale 1.
2778 animating_transform
= true;
2779 contents_scale
= 11.f
;
2780 maximum_animation_scale
= 11.f
;
2782 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2783 maximum_animation_scale
,
2784 starting_animation_scale
, animating_transform
);
2785 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2787 // Once we stop animating, a new high-res tiling should be created.
2788 animating_transform
= false;
2789 contents_scale
= 11.f
;
2791 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2792 maximum_animation_scale
,
2793 starting_animation_scale
, animating_transform
);
2794 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2797 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForGpuRasterization
) {
2798 gfx::Size
layer_bounds(100, 100);
2799 gfx::Size
viewport_size(1000, 1000);
2800 SetupDefaultTrees(layer_bounds
);
2801 host_impl_
.SetViewportSize(viewport_size
);
2802 host_impl_
.SetHasGpuRasterizationTrigger(true);
2803 host_impl_
.SetContentIsSuitableForGpuRasterization(true);
2804 host_impl_
.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2806 float contents_scale
= 1.f
;
2807 float device_scale
= 1.3f
;
2808 float page_scale
= 1.4f
;
2809 float maximum_animation_scale
= 1.f
;
2810 float starting_animation_scale
= 0.f
;
2811 bool animating_transform
= false;
2813 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2814 maximum_animation_scale
,
2815 starting_animation_scale
, animating_transform
);
2816 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2817 EXPECT_BOTH_FALSE(GetRasterSource()->ShouldAttemptToUseDistanceFieldText());
2819 // Since we're GPU-rasterizing, starting an animation should cause tiling
2820 // resolution to get set to the current contents scale.
2821 animating_transform
= true;
2822 contents_scale
= 2.f
;
2823 maximum_animation_scale
= 4.f
;
2825 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2826 maximum_animation_scale
,
2827 starting_animation_scale
, animating_transform
);
2828 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2829 EXPECT_BOTH_TRUE(GetRasterSource()->ShouldAttemptToUseDistanceFieldText());
2831 // Further changes to scale during the animation should cause a new high-res
2832 // tiling to get created.
2833 contents_scale
= 3.f
;
2835 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2836 maximum_animation_scale
,
2837 starting_animation_scale
, animating_transform
);
2838 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2840 // Since we're re-rasterizing during the animation, scales smaller than 1
2841 // should be respected.
2842 contents_scale
= 0.25f
;
2844 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2845 maximum_animation_scale
,
2846 starting_animation_scale
, animating_transform
);
2847 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.25f
);
2849 // Once we stop animating, a new high-res tiling should be created.
2850 contents_scale
= 4.f
;
2851 animating_transform
= false;
2853 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2854 maximum_animation_scale
,
2855 starting_animation_scale
, animating_transform
);
2856 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2859 TEST_F(PictureLayerImplTest
, TilingSetRasterQueue
) {
2860 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2862 host_impl_
.SetViewportSize(gfx::Size(500, 500));
2864 gfx::Size
recording_tile_size(100, 100);
2865 gfx::Size
layer_bounds(1000, 1000);
2867 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2868 FakePicturePileImpl::CreateFilledPile(recording_tile_size
, layer_bounds
);
2870 SetupPendingTree(pending_pile
);
2871 EXPECT_EQ(2u, pending_layer_
->num_tilings());
2873 std::set
<Tile
*> unique_tiles
;
2874 bool reached_prepaint
= false;
2875 int non_ideal_tile_count
= 0u;
2876 int low_res_tile_count
= 0u;
2877 int high_res_tile_count
= 0u;
2878 int high_res_now_tiles
= 0u;
2879 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
2880 pending_layer_
->picture_layer_tiling_set(), false));
2881 while (!queue
->IsEmpty()) {
2882 PrioritizedTile prioritized_tile
= queue
->Top();
2883 TilePriority priority
= prioritized_tile
.priority();
2885 EXPECT_TRUE(prioritized_tile
.tile());
2887 // Non-high res tiles only get visible tiles. Also, prepaint should only
2888 // come at the end of the iteration.
2889 if (priority
.resolution
!= HIGH_RESOLUTION
) {
2890 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
2891 } else if (reached_prepaint
) {
2892 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
2894 reached_prepaint
= priority
.priority_bin
!= TilePriority::NOW
;
2895 if (!reached_prepaint
)
2896 ++high_res_now_tiles
;
2899 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
2900 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
2901 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2903 unique_tiles
.insert(prioritized_tile
.tile());
2907 EXPECT_TRUE(reached_prepaint
);
2908 EXPECT_EQ(0, non_ideal_tile_count
);
2909 EXPECT_EQ(0, low_res_tile_count
);
2911 // With layer size being 1000x1000 and default tile size 256x256, we expect to
2912 // see 4 now tiles out of 16 total high res tiles.
2913 EXPECT_EQ(16, high_res_tile_count
);
2914 EXPECT_EQ(4, high_res_now_tiles
);
2915 EXPECT_EQ(low_res_tile_count
+ high_res_tile_count
+ non_ideal_tile_count
,
2916 static_cast<int>(unique_tiles
.size()));
2918 scoped_ptr
<TilingSetRasterQueueRequired
> required_queue(
2919 new TilingSetRasterQueueRequired(
2920 pending_layer_
->picture_layer_tiling_set(),
2921 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
));
2922 EXPECT_TRUE(required_queue
->IsEmpty());
2924 required_queue
.reset(new TilingSetRasterQueueRequired(
2925 pending_layer_
->picture_layer_tiling_set(),
2926 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
2927 EXPECT_FALSE(required_queue
->IsEmpty());
2928 int required_for_activation_count
= 0;
2929 while (!required_queue
->IsEmpty()) {
2930 PrioritizedTile prioritized_tile
= required_queue
->Top();
2931 EXPECT_TRUE(prioritized_tile
.tile()->required_for_activation());
2932 EXPECT_FALSE(prioritized_tile
.tile()->draw_info().IsReadyToDraw());
2933 ++required_for_activation_count
;
2934 required_queue
->Pop();
2937 // All of the high res tiles should be required for activation, since there is
2939 EXPECT_EQ(high_res_now_tiles
, required_for_activation_count
);
2942 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
2944 pending_layer_
->draw_properties().visible_layer_rect
=
2945 gfx::Rect(1100, 1100, 500, 500);
2946 bool resourceless_software_draw
= false;
2947 pending_layer_
->UpdateTiles(resourceless_software_draw
);
2949 unique_tiles
.clear();
2950 high_res_tile_count
= 0u;
2951 queue
.reset(new TilingSetRasterQueueAll(
2952 pending_layer_
->picture_layer_tiling_set(), false));
2953 while (!queue
->IsEmpty()) {
2954 PrioritizedTile prioritized_tile
= queue
->Top();
2955 TilePriority priority
= prioritized_tile
.priority();
2957 EXPECT_TRUE(prioritized_tile
.tile());
2959 // Non-high res tiles only get visible tiles.
2960 EXPECT_EQ(HIGH_RESOLUTION
, priority
.resolution
);
2961 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
2963 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2965 unique_tiles
.insert(prioritized_tile
.tile());
2969 EXPECT_EQ(16, high_res_tile_count
);
2970 EXPECT_EQ(high_res_tile_count
, static_cast<int>(unique_tiles
.size()));
2972 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
2974 pending_layer_
->draw_properties().visible_layer_rect
=
2975 gfx::Rect(0, 0, 500, 500);
2976 pending_layer_
->UpdateTiles(resourceless_software_draw
);
2978 std::vector
<Tile
*> high_res_tiles
=
2979 pending_layer_
->HighResTiling()->AllTilesForTesting();
2980 for (std::vector
<Tile
*>::iterator tile_it
= high_res_tiles
.begin();
2981 tile_it
!= high_res_tiles
.end();
2983 Tile
* tile
= *tile_it
;
2984 TileDrawInfo
& draw_info
= tile
->draw_info();
2985 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
2988 non_ideal_tile_count
= 0;
2989 low_res_tile_count
= 0;
2990 high_res_tile_count
= 0;
2991 queue
.reset(new TilingSetRasterQueueAll(
2992 pending_layer_
->picture_layer_tiling_set(), true));
2993 while (!queue
->IsEmpty()) {
2994 PrioritizedTile prioritized_tile
= queue
->Top();
2995 TilePriority priority
= prioritized_tile
.priority();
2997 EXPECT_TRUE(prioritized_tile
.tile());
2999 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
3000 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
3001 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
3005 EXPECT_EQ(0, non_ideal_tile_count
);
3006 EXPECT_EQ(1, low_res_tile_count
);
3007 EXPECT_EQ(0, high_res_tile_count
);
3010 TEST_F(PictureLayerImplTest
, TilingSetRasterQueueActiveTree
) {
3011 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
3013 host_impl_
.SetViewportSize(gfx::Size(500, 500));
3015 gfx::Size
tile_size(100, 100);
3016 gfx::Size
layer_bounds(1000, 1000);
3018 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3019 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3021 SetupPendingTree(pending_pile
);
3023 EXPECT_EQ(2u, active_layer_
->num_tilings());
3025 scoped_ptr
<TilingSetRasterQueueRequired
> queue(
3026 new TilingSetRasterQueueRequired(
3027 active_layer_
->picture_layer_tiling_set(),
3028 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
));
3029 EXPECT_FALSE(queue
->IsEmpty());
3030 while (!queue
->IsEmpty()) {
3031 PrioritizedTile prioritized_tile
= queue
->Top();
3032 EXPECT_TRUE(prioritized_tile
.tile()->required_for_draw());
3033 EXPECT_FALSE(prioritized_tile
.tile()->draw_info().IsReadyToDraw());
3037 queue
.reset(new TilingSetRasterQueueRequired(
3038 active_layer_
->picture_layer_tiling_set(),
3039 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
3040 EXPECT_TRUE(queue
->IsEmpty());
3043 TEST_F(PictureLayerImplTest
, TilingSetRasterQueueRequiredNoHighRes
) {
3044 scoped_ptr
<FakePicturePile
> empty_recording
=
3045 FakePicturePile::CreateEmptyPile(gfx::Size(256, 256),
3046 gfx::Size(1024, 1024));
3047 empty_recording
->SetIsSolidColor(true);
3049 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3050 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
3052 SetupPendingTree(pending_pile
);
3054 pending_layer_
->picture_layer_tiling_set()->FindTilingWithResolution(
3057 scoped_ptr
<TilingSetRasterQueueRequired
> queue(
3058 new TilingSetRasterQueueRequired(
3059 pending_layer_
->picture_layer_tiling_set(),
3060 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
3061 EXPECT_TRUE(queue
->IsEmpty());
3064 TEST_F(PictureLayerImplTest
, TilingSetEvictionQueue
) {
3065 gfx::Size
tile_size(100, 100);
3066 gfx::Size
layer_bounds(1000, 1000);
3067 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3069 host_impl_
.SetViewportSize(gfx::Size(500, 500));
3071 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3072 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3074 // TODO(vmpstr): Add a test with tilings other than high/low res on the active
3076 SetupPendingTree(pending_pile
);
3077 EXPECT_EQ(2u, pending_layer_
->num_tilings());
3079 std::vector
<Tile
*> all_tiles
;
3080 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3081 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3082 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
3083 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
3086 std::set
<Tile
*> all_tiles_set(all_tiles
.begin(), all_tiles
.end());
3088 bool mark_required
= false;
3089 size_t number_of_marked_tiles
= 0u;
3090 size_t number_of_unmarked_tiles
= 0u;
3091 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3092 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3093 for (PictureLayerTiling::CoverageIterator
iter(
3094 tiling
, 1.f
, pending_layer_
->visible_layer_rect());
3096 if (mark_required
) {
3097 number_of_marked_tiles
++;
3098 iter
->set_required_for_activation(true);
3100 number_of_unmarked_tiles
++;
3102 mark_required
= !mark_required
;
3107 EXPECT_EQ(17u, all_tiles
.size());
3108 EXPECT_EQ(17u, all_tiles_set
.size());
3109 EXPECT_GT(number_of_marked_tiles
, 1u);
3110 EXPECT_GT(number_of_unmarked_tiles
, 1u);
3112 // Tiles don't have resources yet.
3113 scoped_ptr
<TilingSetEvictionQueue
> queue(
3114 new TilingSetEvictionQueue(pending_layer_
->picture_layer_tiling_set()));
3115 EXPECT_TRUE(queue
->IsEmpty());
3117 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
3119 std::set
<Tile
*> unique_tiles
;
3120 float expected_scales
[] = {low_res_factor
, 1.f
};
3121 size_t scale_index
= 0;
3122 bool reached_visible
= false;
3123 PrioritizedTile last_tile
;
3124 size_t distance_decreasing
= 0;
3125 size_t distance_increasing
= 0;
3127 new TilingSetEvictionQueue(pending_layer_
->picture_layer_tiling_set()));
3128 while (!queue
->IsEmpty()) {
3129 PrioritizedTile prioritized_tile
= queue
->Top();
3130 Tile
* tile
= prioritized_tile
.tile();
3131 if (!last_tile
.tile())
3132 last_tile
= prioritized_tile
;
3136 TilePriority priority
= prioritized_tile
.priority();
3138 if (priority
.priority_bin
== TilePriority::NOW
) {
3139 reached_visible
= true;
3140 last_tile
= prioritized_tile
;
3144 EXPECT_FALSE(tile
->required_for_activation());
3146 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
3147 std::numeric_limits
<float>::epsilon()) {
3149 ASSERT_LT(scale_index
, arraysize(expected_scales
));
3152 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
3153 unique_tiles
.insert(tile
);
3155 if (tile
->required_for_activation() ==
3156 last_tile
.tile()->required_for_activation() &&
3157 std::abs(tile
->contents_scale() - last_tile
.tile()->contents_scale()) <
3158 std::numeric_limits
<float>::epsilon()) {
3159 if (priority
.distance_to_visible
<=
3160 last_tile
.priority().distance_to_visible
)
3161 ++distance_decreasing
;
3163 ++distance_increasing
;
3166 last_tile
= prioritized_tile
;
3170 // 4 high res tiles are inside the viewport, the rest are evicted.
3171 EXPECT_TRUE(reached_visible
);
3172 EXPECT_EQ(12u, unique_tiles
.size());
3173 EXPECT_EQ(1u, distance_increasing
);
3174 EXPECT_EQ(11u, distance_decreasing
);
3177 bool reached_required
= false;
3178 while (!queue
->IsEmpty()) {
3179 PrioritizedTile prioritized_tile
= queue
->Top();
3180 Tile
* tile
= prioritized_tile
.tile();
3183 TilePriority priority
= prioritized_tile
.priority();
3184 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
3186 if (reached_required
) {
3187 EXPECT_TRUE(tile
->required_for_activation());
3188 } else if (tile
->required_for_activation()) {
3189 reached_required
= true;
3193 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
3194 std::numeric_limits
<float>::epsilon()) {
3196 ASSERT_LT(scale_index
, arraysize(expected_scales
));
3199 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
3200 unique_tiles
.insert(tile
);
3204 EXPECT_TRUE(reached_required
);
3205 EXPECT_EQ(all_tiles_set
.size(), unique_tiles
.size());
3208 TEST_F(PictureLayerImplTest
, Occlusion
) {
3209 gfx::Size
tile_size(102, 102);
3210 gfx::Size
layer_bounds(1000, 1000);
3211 gfx::Size
viewport_size(1000, 1000);
3213 LayerTestCommon::LayerImplTest impl
;
3214 host_impl_
.SetViewportSize(viewport_size
);
3216 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3217 FakePicturePileImpl::CreateFilledPile(layer_bounds
, layer_bounds
);
3218 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
3221 std::vector
<Tile
*> tiles
=
3222 active_layer_
->HighResTiling()->AllTilesForTesting();
3223 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3226 SCOPED_TRACE("No occlusion");
3228 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3230 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
3231 gfx::Rect(layer_bounds
));
3232 EXPECT_EQ(100u, impl
.quad_list().size());
3236 SCOPED_TRACE("Full occlusion");
3237 gfx::Rect
occluded(active_layer_
->visible_layer_rect());
3238 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3240 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(), gfx::Rect());
3241 EXPECT_EQ(impl
.quad_list().size(), 0u);
3245 SCOPED_TRACE("Partial occlusion");
3246 gfx::Rect
occluded(150, 0, 200, 1000);
3247 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3249 size_t partially_occluded_count
= 0;
3250 LayerTestCommon::VerifyQuadsAreOccluded(
3251 impl
.quad_list(), occluded
, &partially_occluded_count
);
3252 // The layer outputs one quad, which is partially occluded.
3253 EXPECT_EQ(100u - 10u, impl
.quad_list().size());
3254 EXPECT_EQ(10u + 10u, partially_occluded_count
);
3258 TEST_F(PictureLayerImplTest
, RasterScaleChangeWithoutAnimation
) {
3259 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
3260 SetupDefaultTrees(tile_size
);
3262 ResetTilingsAndRasterScales();
3264 float contents_scale
= 2.f
;
3265 float device_scale
= 1.f
;
3266 float page_scale
= 1.f
;
3267 float maximum_animation_scale
= 1.f
;
3268 float starting_animation_scale
= 0.f
;
3269 bool animating_transform
= false;
3271 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
3272 maximum_animation_scale
,
3273 starting_animation_scale
, animating_transform
);
3274 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
3276 // Changing the source scale without being in an animation will cause
3277 // the layer to reset its source scale to 1.f.
3278 contents_scale
= 3.f
;
3280 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
3281 maximum_animation_scale
,
3282 starting_animation_scale
, animating_transform
);
3283 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3285 // Further changes to the source scale will no longer be reflected in the
3287 contents_scale
= 0.5f
;
3289 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
3290 maximum_animation_scale
,
3291 starting_animation_scale
, animating_transform
);
3292 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3295 TEST_F(PictureLayerImplTest
, LowResReadyToDrawNotEnoughToActivate
) {
3296 gfx::Size
tile_size(100, 100);
3297 gfx::Size
layer_bounds(1000, 1000);
3299 // Make sure pending tree has tiles.
3300 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3301 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3303 // All pending layer tiles required are not ready.
3304 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3306 // Initialize all low-res tiles.
3307 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3308 pending_layer_
->SetAllTilesReadyInTiling(active_layer_
->LowResTiling());
3310 // Low-res tiles should not be enough.
3311 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3313 // Initialize remaining tiles.
3314 pending_layer_
->SetAllTilesReady();
3315 active_layer_
->SetAllTilesReady();
3317 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3320 TEST_F(PictureLayerImplTest
, HighResReadyToDrawEnoughToActivate
) {
3321 gfx::Size
tile_size(100, 100);
3322 gfx::Size
layer_bounds(1000, 1000);
3324 // Make sure pending tree has tiles.
3325 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3326 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3328 // All pending layer tiles required are not ready.
3329 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3331 // Initialize all high-res tiles.
3332 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3333 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3335 // High-res tiles should be enough, since they cover everything visible.
3336 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3339 TEST_F(PictureLayerImplTest
,
3340 ActiveHighResReadyAndPendingLowResReadyNotEnoughToActivate
) {
3341 gfx::Size
tile_size(100, 100);
3342 gfx::Size
layer_bounds(1000, 1000);
3344 // Make sure pending tree has tiles.
3345 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3346 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3348 // Initialize all high-res tiles in the active layer.
3349 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3350 // And all the low-res tiles in the pending layer.
3351 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3353 // The pending high-res tiles are not ready, so we cannot activate.
3354 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3356 // When the pending high-res tiles are ready, we can activate.
3357 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3358 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3361 TEST_F(PictureLayerImplTest
, ActiveHighResReadyNotEnoughToActivate
) {
3362 gfx::Size
tile_size(100, 100);
3363 gfx::Size
layer_bounds(1000, 1000);
3365 // Make sure pending tree has tiles.
3366 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3367 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3369 // Initialize all high-res tiles in the active layer.
3370 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3372 // The pending high-res tiles are not ready, so we cannot activate.
3373 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3375 // When the pending pending high-res tiles are ready, we can activate.
3376 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3377 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3380 TEST_F(NoLowResPictureLayerImplTest
, ManageTilingsCreatesTilings
) {
3381 gfx::Size
tile_size(400, 400);
3382 gfx::Size
layer_bounds(1300, 1900);
3384 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3385 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3386 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3387 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3389 SetupTrees(pending_pile
, active_pile
);
3391 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3392 EXPECT_LT(low_res_factor
, 1.f
);
3394 ResetTilingsAndRasterScales();
3396 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3397 6.f
, // ideal contents scale
3398 3.f
, // device scale
3400 1.f
, // maximum animation scale
3401 0.f
, // starting animation scale
3403 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3404 EXPECT_FLOAT_EQ(6.f
,
3405 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3407 // If we change the page scale factor, then we should get new tilings.
3408 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3409 6.6f
, // ideal contents scale
3410 3.f
, // device scale
3412 1.f
, // maximum animation scale
3413 0.f
, // starting animation scale
3415 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3416 EXPECT_FLOAT_EQ(6.6f
,
3417 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3419 // If we change the device scale factor, then we should get new tilings.
3420 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3421 7.26f
, // ideal contents scale
3422 3.3f
, // device scale
3424 1.f
, // maximum animation scale
3425 0.f
, // starting animation scale
3427 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
3428 EXPECT_FLOAT_EQ(7.26f
,
3429 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3431 // If we change the device scale factor, but end up at the same total scale
3432 // factor somehow, then we don't get new tilings.
3433 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3434 7.26f
, // ideal contents scale
3435 2.2f
, // device scale
3437 1.f
, // maximum animation scale
3438 0.f
, // starting animation scale
3440 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
3441 EXPECT_FLOAT_EQ(7.26f
,
3442 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3445 TEST_F(NoLowResPictureLayerImplTest
, PendingLayerOnlyHasHighResTiling
) {
3446 gfx::Size
tile_size(400, 400);
3447 gfx::Size
layer_bounds(1300, 1900);
3449 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3450 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3451 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3452 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3454 SetupTrees(pending_pile
, active_pile
);
3456 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3457 EXPECT_LT(low_res_factor
, 1.f
);
3459 ResetTilingsAndRasterScales();
3461 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3462 6.f
, // ideal contents scale
3463 3.f
, // device scale
3465 1.f
, // maximum animation scale
3466 0.f
, // starting animation scale
3468 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3469 EXPECT_FLOAT_EQ(6.f
,
3470 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3472 // If we change the page scale factor, then we should get new tilings.
3473 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3474 6.6f
, // ideal contents scale
3475 3.f
, // device scale
3477 1.f
, // maximum animation scale
3478 0.f
, // starting animation scale
3480 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3481 EXPECT_FLOAT_EQ(6.6f
,
3482 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3484 // If we change the device scale factor, then we should get new tilings.
3485 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3486 7.26f
, // ideal contents scale
3487 3.3f
, // device scale
3489 1.f
, // maximum animation scale
3490 0.f
, // starting animation scale
3492 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3493 EXPECT_FLOAT_EQ(7.26f
,
3494 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3496 // If we change the device scale factor, but end up at the same total scale
3497 // factor somehow, then we don't get new tilings.
3498 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3499 7.26f
, // ideal contents scale
3500 2.2f
, // device scale
3502 1.f
, // maximum animation scale
3503 0.f
, // starting animation scale
3505 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3506 EXPECT_FLOAT_EQ(7.26f
,
3507 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3510 TEST_F(NoLowResPictureLayerImplTest
, AllHighResRequiredEvenIfNotChanged
) {
3511 gfx::Size
layer_bounds(400, 400);
3512 gfx::Size
tile_size(100, 100);
3514 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
3516 Tile
* some_active_tile
=
3517 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
3518 EXPECT_FALSE(some_active_tile
->draw_info().IsReadyToDraw());
3520 // Since there is no invalidation, pending tree should have no tiles.
3521 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
3522 if (host_impl_
.settings().create_low_res_tiling
)
3523 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
3525 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
3526 if (host_impl_
.settings().create_low_res_tiling
)
3527 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
3529 AssertAllTilesRequired(active_layer_
->HighResTiling());
3530 if (host_impl_
.settings().create_low_res_tiling
)
3531 AssertNoTilesRequired(active_layer_
->LowResTiling());
3534 TEST_F(NoLowResPictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
3535 gfx::Size
layer_bounds(400, 400);
3536 gfx::Size
tile_size(100, 100);
3538 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3539 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3540 // This pile will create tilings, but has no recordings so will not create any
3541 // tiles. This is attempting to simulate scrolling past the end of recorded
3542 // content on the active layer, where the recordings are so far away that
3543 // no tiles are created.
3544 bool is_solid_color
= false;
3545 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3546 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
3547 tile_size
, layer_bounds
, is_solid_color
);
3549 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
3551 // Active layer has tilings, but no tiles due to missing recordings.
3552 EXPECT_TRUE(active_layer_
->CanHaveTilings());
3553 EXPECT_EQ(active_layer_
->tilings()->num_tilings(),
3554 host_impl_
.settings().create_low_res_tiling
? 2u : 1u);
3555 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
3557 // Since the active layer has no tiles at all, the pending layer doesn't
3558 // need content in order to activate.
3559 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
3560 if (host_impl_
.settings().create_low_res_tiling
)
3561 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
3563 AssertNoTilesRequired(pending_layer_
->HighResTiling());
3564 if (host_impl_
.settings().create_low_res_tiling
)
3565 AssertNoTilesRequired(pending_layer_
->LowResTiling());
3568 TEST_F(NoLowResPictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
3569 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
3571 gfx::Size
tile_size(100, 100);
3572 gfx::Size
layer_bounds(400, 400);
3574 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3575 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3576 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3577 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3579 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
3581 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
3584 // UpdateTiles with valid viewport. Should update tile viewport.
3585 // Note viewport is considered invalid if and only if in resourceless
3587 bool resourceless_software_draw
= false;
3588 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
3589 gfx::Transform transform
;
3590 host_impl_
.SetExternalDrawConstraints(transform
,
3595 resourceless_software_draw
);
3596 active_layer_
->draw_properties().visible_layer_rect
= viewport
;
3597 active_layer_
->draw_properties().screen_space_transform
= transform
;
3598 active_layer_
->UpdateTiles(resourceless_software_draw
);
3600 gfx::Rect visible_rect_for_tile_priority
=
3601 active_layer_
->visible_rect_for_tile_priority();
3602 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
3603 gfx::Transform screen_space_transform_for_tile_priority
=
3604 active_layer_
->screen_space_transform();
3606 // Expand viewport and set it as invalid for prioritizing tiles.
3607 // Should update viewport and transform, but not update visible rect.
3608 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3609 resourceless_software_draw
= true;
3610 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
3611 transform
.Translate(1.f
, 1.f
);
3612 active_layer_
->draw_properties().visible_layer_rect
= viewport
;
3613 active_layer_
->draw_properties().screen_space_transform
= transform
;
3614 host_impl_
.SetExternalDrawConstraints(transform
,
3619 resourceless_software_draw
);
3620 active_layer_
->UpdateTiles(resourceless_software_draw
);
3622 // Transform for tile priority is updated.
3623 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3624 active_layer_
->screen_space_transform());
3625 // Visible rect for tile priority retains old value.
3626 EXPECT_EQ(visible_rect_for_tile_priority
,
3627 active_layer_
->visible_rect_for_tile_priority());
3629 // Keep expanded viewport but mark it valid. Should update tile viewport.
3630 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3631 resourceless_software_draw
= false;
3632 host_impl_
.SetExternalDrawConstraints(transform
,
3637 resourceless_software_draw
);
3638 active_layer_
->UpdateTiles(resourceless_software_draw
);
3640 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3641 active_layer_
->screen_space_transform());
3642 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
3645 TEST_F(NoLowResPictureLayerImplTest
, CleanUpTilings
) {
3646 gfx::Size
tile_size(400, 400);
3647 gfx::Size
layer_bounds(1300, 1900);
3649 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3650 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3651 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3652 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3654 std::vector
<PictureLayerTiling
*> used_tilings
;
3656 SetupTrees(pending_pile
, active_pile
);
3658 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3659 EXPECT_LT(low_res_factor
, 1.f
);
3661 float device_scale
= 1.7f
;
3662 float page_scale
= 3.2f
;
3665 ResetTilingsAndRasterScales();
3667 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, 0.f
,
3669 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3671 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
3672 // |used_tilings| variable, and it's here only to ensure that active_layer_
3673 // won't remove tilings before the test has a chance to verify behavior.
3674 active_layer_
->MarkAllTilingsUsed();
3676 // We only have ideal tilings, so they aren't removed.
3677 used_tilings
.clear();
3678 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3679 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3681 host_impl_
.PinchGestureBegin();
3683 // Changing the ideal but not creating new tilings.
3686 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, 0.f
,
3688 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3690 // The tilings are still our target scale, so they aren't removed.
3691 used_tilings
.clear();
3692 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3693 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3695 host_impl_
.PinchGestureEnd();
3697 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
3700 SetContentsScaleOnBothLayers(1.2f
, device_scale
, page_scale
, 1.f
, 0.f
, false);
3701 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3702 EXPECT_FLOAT_EQ(1.f
,
3703 active_layer_
->tilings()->tiling_at(1)->contents_scale());
3705 // Ensure UpdateTiles won't remove any tilings.
3706 active_layer_
->MarkAllTilingsUsed();
3708 // Mark the non-ideal tilings as used. They won't be removed.
3709 used_tilings
.clear();
3710 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3711 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3712 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3714 // Now move the ideal scale to 0.5. Our target stays 1.2.
3715 SetContentsScaleOnBothLayers(0.5f
, device_scale
, page_scale
, 1.f
, 0.f
, false);
3717 // The high resolution tiling is between target and ideal, so is not
3718 // removed. The low res tiling for the old ideal=1.0 scale is removed.
3719 used_tilings
.clear();
3720 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3721 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3723 // Now move the ideal scale to 1.0. Our target stays 1.2.
3724 SetContentsScaleOnBothLayers(1.f
, device_scale
, page_scale
, 1.f
, 0.f
, false);
3726 // All the tilings are between are target and the ideal, so they are not
3728 used_tilings
.clear();
3729 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3730 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3732 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
3733 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.1f
, device_scale
,
3734 page_scale
, 1.f
, 0.f
, false);
3736 // Because the pending layer's ideal scale is still 1.0, our tilings fall
3737 // in the range [1.0,1.2] and are kept.
3738 used_tilings
.clear();
3739 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3740 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3742 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
3744 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.1f
, device_scale
,
3745 page_scale
, 1.f
, 0.f
, false);
3747 // Our 1.0 tiling now falls outside the range between our ideal scale and our
3748 // target raster scale. But it is in our used tilings set, so nothing is
3750 used_tilings
.clear();
3751 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3752 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3753 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3755 // If we remove it from our used tilings set, it is outside the range to keep
3756 // so it is deleted.
3757 used_tilings
.clear();
3758 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3759 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3762 TEST_F(NoLowResPictureLayerImplTest
, ReleaseResources
) {
3763 gfx::Size
tile_size(400, 400);
3764 gfx::Size
layer_bounds(1300, 1900);
3766 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3767 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3768 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3769 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3771 SetupTrees(pending_pile
, active_pile
);
3772 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3773 EXPECT_EQ(1u, active_layer_
->tilings()->num_tilings());
3775 // All tilings should be removed when losing output surface.
3776 active_layer_
->ReleaseResources();
3777 EXPECT_FALSE(active_layer_
->tilings());
3778 active_layer_
->RecreateResources();
3779 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
3780 pending_layer_
->ReleaseResources();
3781 EXPECT_FALSE(pending_layer_
->tilings());
3782 pending_layer_
->RecreateResources();
3783 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
3785 // This should create new tilings.
3786 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3787 1.3f
, // ideal contents scale
3788 2.7f
, // device scale
3790 1.f
, // maximum animation scale
3791 0.f
, // starting animation scale
3793 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3796 TEST_F(PictureLayerImplTest
, SharedQuadStateContainsMaxTilingScale
) {
3797 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3799 gfx::Size
tile_size(400, 400);
3800 gfx::Size
layer_bounds(1000, 2000);
3802 host_impl_
.SetViewportSize(gfx::Size(10000, 20000));
3804 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3805 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3806 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3807 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3809 SetupTrees(pending_pile
, active_pile
);
3811 ResetTilingsAndRasterScales();
3812 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.5f
, 1.f
, 1.f
, 1.f
, 0.f
,
3815 float max_contents_scale
= active_layer_
->MaximumTilingContentsScale();
3816 EXPECT_EQ(2.5f
, max_contents_scale
);
3818 gfx::Transform scaled_draw_transform
= active_layer_
->draw_transform();
3819 scaled_draw_transform
.Scale(SK_MScalar1
/ max_contents_scale
,
3820 SK_MScalar1
/ max_contents_scale
);
3822 AppendQuadsData data
;
3823 active_layer_
->AppendQuads(render_pass
.get(), &data
);
3825 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
3826 EXPECT_EQ(1u, render_pass
->shared_quad_state_list
.size());
3827 // The quad_to_target_transform should be scaled by the
3828 // MaximumTilingContentsScale on the layer.
3829 EXPECT_EQ(scaled_draw_transform
.ToString(),
3830 render_pass
->shared_quad_state_list
.front()
3831 ->quad_to_target_transform
.ToString());
3832 // The content_bounds should be scaled by the
3833 // MaximumTilingContentsScale on the layer.
3834 EXPECT_EQ(gfx::Size(2500u, 5000u).ToString(),
3835 render_pass
->shared_quad_state_list
.front()
3836 ->quad_layer_bounds
.ToString());
3837 // The visible_layer_rect should be scaled by the
3838 // MaximumTilingContentsScale on the layer.
3839 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
3840 render_pass
->shared_quad_state_list
.front()
3841 ->visible_quad_layer_rect
.ToString());
3844 class PictureLayerImplTestWithDelegatingRenderer
: public PictureLayerImplTest
{
3846 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {}
3848 void InitializeRenderer() override
{
3849 host_impl_
.InitializeRenderer(FakeOutputSurface::CreateDelegating3d());
3853 TEST_F(PictureLayerImplTestWithDelegatingRenderer
,
3854 DelegatingRendererWithTileOOM
) {
3855 // This test is added for crbug.com/402321, where quad should be produced when
3856 // raster on demand is not allowed and tile is OOM.
3857 gfx::Size tile_size
= host_impl_
.settings().default_tile_size
;
3858 gfx::Size
layer_bounds(1000, 1000);
3861 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3862 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3863 SetupPendingTree(pending_pile
);
3864 pending_layer_
->SetBounds(layer_bounds
);
3866 bool update_lcd_text
= false;
3867 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
3868 std::vector
<Tile
*> tiles
=
3869 active_layer_
->HighResTiling()->AllTilesForTesting();
3870 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3872 // Force tiles after max_tiles to be OOM. TileManager uses
3873 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3874 // directly set state to host_impl_, so we set policy that would change the
3875 // state. We also need to update tree priority separately.
3876 GlobalStateThatImpactsTilePriority state
;
3877 size_t max_tiles
= 1;
3878 size_t memory_limit
= max_tiles
* 4 * tile_size
.width() * tile_size
.height();
3879 size_t resource_limit
= max_tiles
;
3880 ManagedMemoryPolicy
policy(memory_limit
,
3881 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
,
3883 host_impl_
.SetMemoryPolicy(policy
);
3884 host_impl_
.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES
);
3885 host_impl_
.PrepareTiles();
3887 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3888 AppendQuadsData data
;
3889 active_layer_
->WillDraw(DRAW_MODE_HARDWARE
, nullptr);
3890 active_layer_
->AppendQuads(render_pass
.get(), &data
);
3891 active_layer_
->DidDraw(nullptr);
3893 // Even when OOM, quads should be produced, and should be different material
3894 // from quads with resource.
3895 EXPECT_LT(max_tiles
, render_pass
->quad_list
.size());
3896 EXPECT_EQ(DrawQuad::Material::TILED_CONTENT
,
3897 render_pass
->quad_list
.front()->material
);
3898 EXPECT_EQ(DrawQuad::Material::SOLID_COLOR
,
3899 render_pass
->quad_list
.back()->material
);
3902 class OcclusionTrackingSettings
: public LowResTilingsSettings
{
3904 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization
= true; }
3907 class OcclusionTrackingPictureLayerImplTest
: public PictureLayerImplTest
{
3909 OcclusionTrackingPictureLayerImplTest()
3910 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
3912 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl
* layer
,
3914 size_t expected_occluded_tile_count
,
3916 size_t occluded_tile_count
= 0u;
3917 PrioritizedTile last_tile
;
3919 scoped_ptr
<TilingSetEvictionQueue
> queue(
3920 new TilingSetEvictionQueue(layer
->picture_layer_tiling_set()));
3921 while (!queue
->IsEmpty()) {
3922 PrioritizedTile prioritized_tile
= queue
->Top();
3923 Tile
* tile
= prioritized_tile
.tile();
3924 if (!last_tile
.tile())
3925 last_tile
= prioritized_tile
;
3927 // The only way we will encounter an occluded tile after an unoccluded
3928 // tile is if the priorty bin decreased, the tile is required for
3929 // activation, or the scale changed.
3930 bool tile_is_occluded
= prioritized_tile
.is_occluded();
3931 if (tile_is_occluded
) {
3932 occluded_tile_count
++;
3934 bool last_tile_is_occluded
= last_tile
.is_occluded();
3935 if (!last_tile_is_occluded
) {
3936 TilePriority::PriorityBin tile_priority_bin
=
3937 prioritized_tile
.priority().priority_bin
;
3938 TilePriority::PriorityBin last_tile_priority_bin
=
3939 last_tile
.priority().priority_bin
;
3941 EXPECT_TRUE(tile_priority_bin
< last_tile_priority_bin
||
3942 tile
->required_for_activation() ||
3943 tile
->contents_scale() !=
3944 last_tile
.tile()->contents_scale())
3945 << "line: " << source_line
;
3948 last_tile
= prioritized_tile
;
3951 EXPECT_EQ(expected_occluded_tile_count
, occluded_tile_count
)
3952 << "line: " << source_line
;
3956 TEST_F(OcclusionTrackingPictureLayerImplTest
,
3957 OccludedTilesSkippedDuringRasterization
) {
3958 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
3960 gfx::Size
tile_size(102, 102);
3961 gfx::Size
layer_bounds(1000, 1000);
3962 gfx::Size
viewport_size(500, 500);
3963 gfx::Point
occluding_layer_position(310, 0);
3965 host_impl_
.SetViewportSize(viewport_size
);
3967 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3968 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3969 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
3972 int unoccluded_tile_count
= 0;
3973 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
3974 pending_layer_
->picture_layer_tiling_set(), false));
3975 while (!queue
->IsEmpty()) {
3976 PrioritizedTile prioritized_tile
= queue
->Top();
3977 Tile
* tile
= prioritized_tile
.tile();
3979 // Occluded tiles should not be iterated over.
3980 EXPECT_FALSE(prioritized_tile
.is_occluded());
3982 // Some tiles may not be visible (i.e. outside the viewport). The rest are
3983 // visible and at least partially unoccluded, verified by the above expect.
3984 bool tile_is_visible
=
3985 tile
->content_rect().Intersects(pending_layer_
->visible_layer_rect());
3986 if (tile_is_visible
)
3987 unoccluded_tile_count
++;
3990 EXPECT_EQ(unoccluded_tile_count
, 25);
3992 // Partial occlusion.
3993 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
3994 LayerImpl
* layer1
= pending_layer_
->children()[0];
3995 layer1
->SetBounds(layer_bounds
);
3996 layer1
->SetDrawsContent(true);
3997 layer1
->SetContentsOpaque(true);
3998 layer1
->SetPosition(occluding_layer_position
);
4000 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
4001 bool update_lcd_text
= false;
4002 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4004 unoccluded_tile_count
= 0;
4005 queue
.reset(new TilingSetRasterQueueAll(
4006 pending_layer_
->picture_layer_tiling_set(), false));
4007 while (!queue
->IsEmpty()) {
4008 PrioritizedTile prioritized_tile
= queue
->Top();
4009 Tile
* tile
= prioritized_tile
.tile();
4011 EXPECT_FALSE(prioritized_tile
.is_occluded());
4013 bool tile_is_visible
=
4014 tile
->content_rect().Intersects(pending_layer_
->visible_layer_rect());
4015 if (tile_is_visible
)
4016 unoccluded_tile_count
++;
4019 EXPECT_EQ(20, unoccluded_tile_count
);
4022 layer1
->SetPosition(gfx::Point(0, 0));
4024 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
4025 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4027 unoccluded_tile_count
= 0;
4028 queue
.reset(new TilingSetRasterQueueAll(
4029 pending_layer_
->picture_layer_tiling_set(), false));
4030 while (!queue
->IsEmpty()) {
4031 PrioritizedTile prioritized_tile
= queue
->Top();
4032 Tile
* tile
= prioritized_tile
.tile();
4034 EXPECT_FALSE(prioritized_tile
.is_occluded());
4036 bool tile_is_visible
=
4037 tile
->content_rect().Intersects(pending_layer_
->visible_layer_rect());
4038 if (tile_is_visible
)
4039 unoccluded_tile_count
++;
4042 EXPECT_EQ(unoccluded_tile_count
, 0);
4045 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4046 OccludedTilesNotMarkedAsRequired
) {
4047 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4049 gfx::Size
tile_size(102, 102);
4050 gfx::Size
layer_bounds(1000, 1000);
4051 gfx::Size
viewport_size(500, 500);
4052 gfx::Point
occluding_layer_position(310, 0);
4054 host_impl_
.SetViewportSize(viewport_size
);
4056 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4057 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4058 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4061 int occluded_tile_count
= 0;
4062 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4063 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4064 auto prioritized_tiles
=
4065 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4067 occluded_tile_count
= 0;
4068 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4069 gfx::Rect(layer_bounds
));
4073 const Tile
* tile
= *iter
;
4075 // Fully occluded tiles are not required for activation.
4076 if (prioritized_tiles
[tile
].is_occluded()) {
4077 EXPECT_FALSE(tile
->required_for_activation());
4078 occluded_tile_count
++;
4081 EXPECT_EQ(occluded_tile_count
, 0);
4084 // Partial occlusion.
4085 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4086 LayerImpl
* layer1
= pending_layer_
->children()[0];
4087 layer1
->SetBounds(layer_bounds
);
4088 layer1
->SetDrawsContent(true);
4089 layer1
->SetContentsOpaque(true);
4090 layer1
->SetPosition(occluding_layer_position
);
4092 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
4093 bool update_lcd_text
= false;
4094 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4096 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4097 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4098 auto prioritized_tiles
=
4099 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4101 occluded_tile_count
= 0;
4102 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4103 gfx::Rect(layer_bounds
));
4107 const Tile
* tile
= *iter
;
4109 if (prioritized_tiles
[tile
].is_occluded()) {
4110 EXPECT_FALSE(tile
->required_for_activation());
4111 occluded_tile_count
++;
4116 EXPECT_EQ(occluded_tile_count
, 5);
4119 EXPECT_EQ(occluded_tile_count
, 2);
4127 layer1
->SetPosition(gfx::PointF(0, 0));
4129 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
4130 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4132 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4133 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4134 auto prioritized_tiles
=
4135 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4137 occluded_tile_count
= 0;
4138 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4139 gfx::Rect(layer_bounds
));
4143 const Tile
* tile
= *iter
;
4145 if (prioritized_tiles
[tile
].is_occluded()) {
4146 EXPECT_FALSE(tile
->required_for_activation());
4147 occluded_tile_count
++;
4152 EXPECT_EQ(25, occluded_tile_count
);
4155 EXPECT_EQ(4, occluded_tile_count
);
4163 TEST_F(OcclusionTrackingPictureLayerImplTest
, OcclusionForDifferentScales
) {
4164 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4166 gfx::Size
tile_size(102, 102);
4167 gfx::Size
layer_bounds(1000, 1000);
4168 gfx::Size
viewport_size(500, 500);
4169 gfx::Point
occluding_layer_position(310, 0);
4171 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4172 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4174 host_impl_
.SetViewportSize(viewport_size
);
4176 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4177 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
4179 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4180 LayerImpl
* layer1
= pending_layer_
->children()[0];
4181 layer1
->SetBounds(layer_bounds
);
4182 layer1
->SetDrawsContent(true);
4183 layer1
->SetContentsOpaque(true);
4184 layer1
->SetPosition(occluding_layer_position
);
4186 pending_layer_
->tilings()->RemoveAllTilings();
4187 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
4188 pending_layer_
->AddTiling(low_res_factor
);
4189 pending_layer_
->AddTiling(0.3f
);
4190 pending_layer_
->AddTiling(0.7f
);
4191 pending_layer_
->AddTiling(1.0f
);
4192 pending_layer_
->AddTiling(2.0f
);
4194 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4195 // UpdateDrawProperties with the occluding layer.
4196 bool update_lcd_text
= false;
4197 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4199 EXPECT_EQ(5u, pending_layer_
->num_tilings());
4201 int occluded_tile_count
= 0;
4202 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4203 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4204 auto prioritized_tiles
=
4205 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4206 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4208 occluded_tile_count
= 0;
4209 for (size_t j
= 0; j
< tiles
.size(); ++j
) {
4210 if (prioritized_tiles
[tiles
[j
]].is_occluded()) {
4211 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4212 tiles
[j
]->content_rect(), 1.0f
/ tiles
[j
]->contents_scale());
4213 EXPECT_GE(scaled_content_rect
.x(), occluding_layer_position
.x());
4214 occluded_tile_count
++;
4220 EXPECT_EQ(occluded_tile_count
, 30);
4223 EXPECT_EQ(occluded_tile_count
, 5);
4226 EXPECT_EQ(occluded_tile_count
, 4);
4230 EXPECT_EQ(occluded_tile_count
, 2);
4238 TEST_F(OcclusionTrackingPictureLayerImplTest
, DifferentOcclusionOnTrees
) {
4239 gfx::Size
tile_size(102, 102);
4240 gfx::Size
layer_bounds(1000, 1000);
4241 gfx::Size
viewport_size(1000, 1000);
4242 gfx::Point
occluding_layer_position(310, 0);
4243 gfx::Rect
invalidation_rect(230, 230, 102, 102);
4245 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4246 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4247 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4248 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4250 host_impl_
.SetViewportSize(viewport_size
);
4251 SetupPendingTree(active_pile
);
4253 // Partially occlude the active layer.
4254 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 2));
4255 LayerImpl
* layer1
= pending_layer_
->children()[0];
4256 layer1
->SetBounds(layer_bounds
);
4257 layer1
->SetDrawsContent(true);
4258 layer1
->SetContentsOpaque(true);
4259 layer1
->SetPosition(occluding_layer_position
);
4263 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4264 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4265 auto prioritized_tiles
=
4266 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4268 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4269 gfx::Rect(layer_bounds
));
4273 const Tile
* tile
= *iter
;
4275 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4276 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4277 // Tiles are occluded on the active tree iff they lie beneath the
4279 EXPECT_EQ(prioritized_tiles
[tile
].is_occluded(),
4280 scaled_content_rect
.x() >= occluding_layer_position
.x());
4284 // Partially invalidate the pending layer.
4285 SetupPendingTreeWithInvalidation(pending_pile
, invalidation_rect
);
4287 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4288 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4289 auto prioritized_tiles
=
4290 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4292 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4293 gfx::Rect(layer_bounds
));
4297 const Tile
* tile
= *iter
;
4299 // All tiles are unoccluded, because the pending tree has no occlusion.
4300 EXPECT_FALSE(prioritized_tiles
[tile
].is_occluded());
4302 Tile
* twin_tile
= active_layer_
->GetPendingOrActiveTwinTiling(tiling
)
4303 ->TileAt(iter
.i(), iter
.j());
4304 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4305 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4307 if (scaled_content_rect
.Intersects(invalidation_rect
)) {
4308 // Tiles inside the invalidation rect exist on both trees.
4310 EXPECT_TRUE(twin_tile
);
4311 EXPECT_NE(tile
, twin_tile
);
4313 // Tiles outside the invalidation rect only exist on the active tree.
4315 EXPECT_FALSE(twin_tile
);
4321 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4322 OccludedTilesConsideredDuringEviction
) {
4323 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4325 gfx::Size
tile_size(102, 102);
4326 gfx::Size
layer_bounds(1000, 1000);
4327 gfx::Size
viewport_size(1000, 1000);
4328 gfx::Point
pending_occluding_layer_position(310, 0);
4329 gfx::Point
active_occluding_layer_position(0, 310);
4330 gfx::Rect
invalidation_rect(230, 230, 152, 152);
4332 host_impl_
.SetViewportSize(viewport_size
);
4333 host_impl_
.SetDeviceScaleFactor(2.f
);
4335 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4336 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4337 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4338 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4340 SetupPendingTreeWithFixedTileSize(active_pile
, tile_size
, Region());
4342 // Partially occlude the active layer.
4343 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 2));
4344 LayerImpl
* active_occluding_layer
= pending_layer_
->children()[0];
4345 active_occluding_layer
->SetBounds(layer_bounds
);
4346 active_occluding_layer
->SetDrawsContent(true);
4347 active_occluding_layer
->SetContentsOpaque(true);
4348 active_occluding_layer
->SetPosition(active_occluding_layer_position
);
4352 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4354 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, invalidation_rect
);
4356 // Partially occlude the pending layer in a different way.
4357 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 3));
4358 LayerImpl
* pending_occluding_layer
= pending_layer_
->children()[0];
4359 pending_occluding_layer
->SetBounds(layer_bounds
);
4360 pending_occluding_layer
->SetDrawsContent(true);
4361 pending_occluding_layer
->SetContentsOpaque(true);
4362 pending_occluding_layer
->SetPosition(pending_occluding_layer_position
);
4364 EXPECT_EQ(2u, pending_layer_
->num_tilings());
4365 EXPECT_EQ(2u, active_layer_
->num_tilings());
4367 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4368 // UpdateDrawProperties with the occluding layer.
4369 bool update_lcd_text
= false;
4370 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4372 // The expected number of occluded tiles on each of the 2 tilings for each of
4373 // the 3 tree priorities.
4374 size_t expected_occluded_tile_count_on_pending
[] = {4u, 0u};
4375 size_t expected_occluded_tile_count_on_active
[] = {12u, 1u};
4376 size_t total_expected_occluded_tile_count_on_trees
[] = {13u, 4u};
4378 // Verify number of occluded tiles on the pending layer for each tiling.
4379 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4380 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4381 auto prioritized_tiles
=
4382 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4384 size_t occluded_tile_count_on_pending
= 0u;
4385 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4386 gfx::Rect(layer_bounds
));
4390 if (invalidation_rect
.Intersects(iter
.geometry_rect()))
4397 if (prioritized_tiles
[tile
].is_occluded())
4398 occluded_tile_count_on_pending
++;
4400 EXPECT_EQ(expected_occluded_tile_count_on_pending
[i
],
4401 occluded_tile_count_on_pending
)
4402 << tiling
->contents_scale();
4405 // Verify number of occluded tiles on the active layer for each tiling.
4406 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4407 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4408 auto prioritized_tiles
=
4409 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4411 size_t occluded_tile_count_on_active
= 0u;
4412 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4413 gfx::Rect(layer_bounds
));
4419 if (prioritized_tiles
[tile
].is_occluded())
4420 occluded_tile_count_on_active
++;
4422 EXPECT_EQ(expected_occluded_tile_count_on_active
[i
],
4423 occluded_tile_count_on_active
)
4427 std::vector
<Tile
*> all_tiles
;
4428 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4429 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4430 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4431 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
4433 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4434 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4435 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4436 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
4439 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
4441 VerifyEvictionConsidersOcclusion(
4442 pending_layer_
, PENDING_TREE
,
4443 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
], __LINE__
);
4444 VerifyEvictionConsidersOcclusion(
4445 active_layer_
, ACTIVE_TREE
,
4446 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
], __LINE__
);
4448 // Repeat the tests without valid active tree priorities.
4449 active_layer_
->set_has_valid_tile_priorities(false);
4450 VerifyEvictionConsidersOcclusion(
4451 pending_layer_
, PENDING_TREE
,
4452 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
], __LINE__
);
4453 VerifyEvictionConsidersOcclusion(
4454 active_layer_
, ACTIVE_TREE
,
4455 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
], __LINE__
);
4456 active_layer_
->set_has_valid_tile_priorities(true);
4458 // Repeat the tests without valid pending tree priorities.
4459 pending_layer_
->set_has_valid_tile_priorities(false);
4460 VerifyEvictionConsidersOcclusion(
4461 active_layer_
, ACTIVE_TREE
,
4462 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
], __LINE__
);
4463 VerifyEvictionConsidersOcclusion(
4464 pending_layer_
, PENDING_TREE
,
4465 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
], __LINE__
);
4466 pending_layer_
->set_has_valid_tile_priorities(true);
4469 TEST_F(PictureLayerImplTest
, PendingOrActiveTwinLayer
) {
4470 gfx::Size
tile_size(102, 102);
4471 gfx::Size
layer_bounds(1000, 1000);
4473 scoped_refptr
<FakePicturePileImpl
> pile
=
4474 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4475 SetupPendingTree(pile
);
4476 EXPECT_FALSE(pending_layer_
->GetPendingOrActiveTwinLayer());
4479 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4481 SetupPendingTree(pile
);
4482 EXPECT_TRUE(pending_layer_
->GetPendingOrActiveTwinLayer());
4483 EXPECT_TRUE(active_layer_
->GetPendingOrActiveTwinLayer());
4484 EXPECT_EQ(pending_layer_
, active_layer_
->GetPendingOrActiveTwinLayer());
4485 EXPECT_EQ(active_layer_
, pending_layer_
->GetPendingOrActiveTwinLayer());
4488 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4490 // Make an empty pending tree.
4491 host_impl_
.CreatePendingTree();
4492 host_impl_
.pending_tree()->DetachLayerTree();
4493 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4496 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid
) {
4497 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4499 gfx::Size
tile_size(100, 100);
4500 gfx::Size
layer_bounds(200, 200);
4501 gfx::Rect
layer_rect(layer_bounds
);
4503 FakeContentLayerClient client
;
4504 scoped_refptr
<PictureLayer
> layer
=
4505 PictureLayer::Create(layer_settings_
, &client
);
4506 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4507 TestTaskGraphRunner task_graph_runner
;
4508 scoped_ptr
<FakeLayerTreeHost
> host
=
4509 FakeLayerTreeHost::Create(&host_client
, &task_graph_runner
);
4510 host
->SetRootLayer(layer
);
4511 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4513 int frame_number
= 0;
4515 client
.set_fill_with_nonsolid_color(!test_for_solid
);
4517 Region
invalidation(layer_rect
);
4518 recording_source
->UpdateAndExpandInvalidation(
4519 &client
, &invalidation
, layer_bounds
, layer_rect
, frame_number
++,
4520 RecordingSource::RECORD_NORMALLY
);
4522 scoped_refptr
<RasterSource
> pending_raster_source
=
4523 recording_source
->CreateRasterSource(true);
4525 SetupPendingTreeWithFixedTileSize(pending_raster_source
, tile_size
, Region());
4528 if (test_for_solid
) {
4529 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4531 ASSERT_TRUE(active_layer_
->tilings());
4532 ASSERT_GT(active_layer_
->tilings()->num_tilings(), 0u);
4533 std::vector
<Tile
*> tiles
=
4534 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
4535 EXPECT_FALSE(tiles
.empty());
4536 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4539 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
4540 AppendQuadsData data
;
4541 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
4542 active_layer_
->AppendQuads(render_pass
.get(), &data
);
4543 active_layer_
->DidDraw(nullptr);
4545 DrawQuad::Material expected
= test_for_solid
4546 ? DrawQuad::Material::SOLID_COLOR
4547 : DrawQuad::Material::TILED_CONTENT
;
4548 EXPECT_EQ(expected
, render_pass
->quad_list
.front()->material
);
4551 TEST_F(PictureLayerImplTest
, DrawSolidQuads
) {
4552 TestQuadsForSolidColor(true);
4555 TEST_F(PictureLayerImplTest
, DrawNonSolidQuads
) {
4556 TestQuadsForSolidColor(false);
4559 TEST_F(PictureLayerImplTest
, NonSolidToSolidNoTilings
) {
4560 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4562 gfx::Size
tile_size(100, 100);
4563 gfx::Size
layer_bounds(200, 200);
4564 gfx::Rect
layer_rect(layer_bounds
);
4566 FakeContentLayerClient client
;
4567 scoped_refptr
<PictureLayer
> layer
=
4568 PictureLayer::Create(layer_settings_
, &client
);
4569 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4570 TestTaskGraphRunner task_graph_runner
;
4571 scoped_ptr
<FakeLayerTreeHost
> host
=
4572 FakeLayerTreeHost::Create(&host_client
, &task_graph_runner
);
4573 host
->SetRootLayer(layer
);
4574 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4576 int frame_number
= 0;
4578 client
.set_fill_with_nonsolid_color(true);
4580 Region
invalidation1(layer_rect
);
4581 recording_source
->UpdateAndExpandInvalidation(
4582 &client
, &invalidation1
, layer_bounds
, layer_rect
, frame_number
++,
4583 RecordingSource::RECORD_NORMALLY
);
4585 scoped_refptr
<RasterSource
> raster_source1
=
4586 recording_source
->CreateRasterSource(true);
4588 SetupPendingTree(raster_source1
);
4590 bool update_lcd_text
= false;
4591 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
4593 // We've started with a solid layer that contains some tilings.
4594 ASSERT_TRUE(active_layer_
->tilings());
4595 EXPECT_NE(0u, active_layer_
->tilings()->num_tilings());
4597 client
.set_fill_with_nonsolid_color(false);
4599 Region
invalidation2(layer_rect
);
4600 recording_source
->UpdateAndExpandInvalidation(
4601 &client
, &invalidation2
, layer_bounds
, layer_rect
, frame_number
++,
4602 RecordingSource::RECORD_NORMALLY
);
4604 scoped_refptr
<RasterSource
> raster_source2
=
4605 recording_source
->CreateRasterSource(true);
4607 SetupPendingTree(raster_source2
);
4610 // We've switched to a solid color, so we should end up with no tilings.
4611 ASSERT_TRUE(active_layer_
->tilings());
4612 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4615 TEST_F(PictureLayerImplTest
, ChangeInViewportAllowsTilingUpdates
) {
4616 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4618 gfx::Size
tile_size(100, 100);
4619 gfx::Size
layer_bounds(400, 4000);
4621 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4622 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4623 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4624 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4626 SetupTrees(pending_pile
, active_pile
);
4628 Region invalidation
;
4629 gfx::Rect viewport
= gfx::Rect(0, 0, 100, 100);
4630 gfx::Transform transform
;
4632 host_impl_
.SetRequiresHighResToDraw();
4635 pending_layer_
->draw_properties().visible_layer_rect
= viewport
;
4636 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4637 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
4639 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
4641 // Ensure we can't activate.
4642 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
4644 // Now in the same frame, move the viewport (this can happen during
4646 viewport
= gfx::Rect(0, 2000, 100, 100);
4649 pending_layer_
->draw_properties().visible_layer_rect
= viewport
;
4650 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4651 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
4653 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
4655 // Make sure all viewport tiles (viewport from the tiling) are ready to draw.
4656 std::vector
<Tile
*> tiles
;
4657 for (PictureLayerTiling::CoverageIterator
iter(
4658 pending_layer_
->HighResTiling(),
4660 pending_layer_
->HighResTiling()->GetCurrentVisibleRectForTesting());
4664 tiles
.push_back(*iter
);
4666 for (PictureLayerTiling::CoverageIterator
iter(
4667 active_layer_
->HighResTiling(), 1.f
,
4668 active_layer_
->HighResTiling()->GetCurrentVisibleRectForTesting());
4671 tiles
.push_back(*iter
);
4674 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4676 // Ensure we can activate.
4677 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
4680 TEST_F(PictureLayerImplTest
, CloneMissingRecordings
) {
4681 gfx::Size
tile_size(100, 100);
4682 gfx::Size
layer_bounds(400, 400);
4684 scoped_refptr
<FakePicturePileImpl
> filled_pile
=
4685 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4687 scoped_ptr
<FakePicturePile
> partial_recording
=
4688 FakePicturePile::CreateEmptyPile(tile_size
, layer_bounds
);
4689 for (int i
= 1; i
< partial_recording
->tiling().num_tiles_x(); ++i
) {
4690 for (int j
= 1; j
< partial_recording
->tiling().num_tiles_y(); ++j
)
4691 partial_recording
->AddRecordingAt(i
, j
);
4693 scoped_refptr
<FakePicturePileImpl
> partial_pile
=
4694 FakePicturePileImpl::CreateFromPile(partial_recording
.get(), nullptr);
4696 SetupPendingTreeWithFixedTileSize(filled_pile
, tile_size
, Region());
4699 PictureLayerTiling
* pending_tiling
= old_pending_layer_
->HighResTiling();
4700 PictureLayerTiling
* active_tiling
= active_layer_
->HighResTiling();
4702 // We should have all tiles on active, and none on pending.
4703 EXPECT_EQ(0u, pending_tiling
->AllTilesForTesting().size());
4704 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4706 // Now put a partially-recorded pile on the pending tree (and invalidate
4707 // everything, since the main thread PicturePile will invalidate dropped
4708 // recordings). This will cause us to be missing some tiles.
4709 SetupPendingTreeWithFixedTileSize(partial_pile
, tile_size
,
4710 Region(gfx::Rect(layer_bounds
)));
4711 EXPECT_EQ(3u * 3u, pending_tiling
->AllTilesForTesting().size());
4712 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
4713 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
4714 EXPECT_TRUE(pending_tiling
->TileAt(2, 2));
4716 // Active is not affected yet.
4717 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4719 // Activate the tree. The same tiles go missing on the active tree.
4721 EXPECT_EQ(3u * 3u, active_tiling
->AllTilesForTesting().size());
4722 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
4723 EXPECT_FALSE(active_tiling
->TileAt(1, 1));
4724 EXPECT_TRUE(active_tiling
->TileAt(2, 2));
4726 // Now put a full recording on the pending tree again. We'll get all our tiles
4728 SetupPendingTreeWithFixedTileSize(filled_pile
, tile_size
,
4729 Region(gfx::Rect(layer_bounds
)));
4730 EXPECT_EQ(5u * 5u, pending_tiling
->AllTilesForTesting().size());
4731 Tile
* tile00
= pending_tiling
->TileAt(0, 0);
4732 Tile
* tile11
= pending_tiling
->TileAt(1, 1);
4733 Tile
* tile22
= pending_tiling
->TileAt(2, 2);
4735 // Active is not affected yet.
4736 EXPECT_EQ(3u * 3u, active_tiling
->AllTilesForTesting().size());
4738 // Activate the tree. The tiles are moved to the active tree.
4740 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4741 EXPECT_EQ(tile00
, active_tiling
->TileAt(0, 0));
4742 EXPECT_EQ(tile11
, active_tiling
->TileAt(1, 1));
4743 EXPECT_EQ(tile22
, active_tiling
->TileAt(2, 2));
4746 TEST_F(PictureLayerImplTest
, ScrollPastLiveTilesRectAndBack
) {
4747 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4749 gfx::Size
tile_size(102, 102);
4750 gfx::Size
layer_bounds(100, 100);
4751 gfx::Size
viewport_size(100, 100);
4753 host_impl_
.SetViewportSize(viewport_size
);
4754 host_impl_
.SetDeviceScaleFactor(1.f
);
4756 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4757 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4758 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4759 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4761 SetupPendingTreeWithFixedTileSize(active_pile
, tile_size
, Region());
4764 EXPECT_TRUE(active_layer_
->HighResTiling()->has_tiles());
4766 host_impl_
.SetExternalDrawConstraints(
4767 gfx::Transform(), // transform
4768 gfx::Rect(), // clip
4769 gfx::Rect(), // viewport
4770 gfx::Rect(0, 5000, 100, 100), // viewport_rect_for_tile_priority
4771 gfx::Transform(), // transform_for_tile_priority
4774 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, gfx::Rect());
4776 EXPECT_FALSE(pending_layer_
->HighResTiling()->has_tiles());
4777 EXPECT_TRUE(pending_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4779 EXPECT_FALSE(active_layer_
->HighResTiling()->has_tiles());
4780 EXPECT_TRUE(active_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4782 host_impl_
.SetExternalDrawConstraints(
4783 gfx::Transform(), // transform
4784 gfx::Rect(), // clip
4785 gfx::Rect(), // viewport
4786 gfx::Rect(0, 110, 100, 100), // viewport_rect_for_tile_priority
4787 gfx::Transform(), // transform_for_tile_priority
4790 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, gfx::Rect());
4792 EXPECT_FALSE(pending_layer_
->HighResTiling()->has_tiles());
4793 EXPECT_FALSE(pending_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4795 EXPECT_TRUE(active_layer_
->HighResTiling()->has_tiles());
4796 EXPECT_FALSE(active_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4799 TEST_F(PictureLayerImplTest
, ScrollPropagatesToPending
) {
4800 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4802 gfx::Size
tile_size(102, 102);
4803 gfx::Size
layer_bounds(1000, 1000);
4804 gfx::Size
viewport_size(100, 100);
4806 host_impl_
.SetViewportSize(viewport_size
);
4807 host_impl_
.SetDeviceScaleFactor(1.f
);
4809 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4810 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4811 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4812 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4814 SetupTrees(pending_pile
, active_pile
);
4816 active_layer_
->SetCurrentScrollOffset(gfx::ScrollOffset(0.0, 50.0));
4817 host_impl_
.active_tree()->UpdateDrawProperties(false);
4818 EXPECT_EQ("0,50 100x100", active_layer_
->HighResTiling()
4819 ->GetCurrentVisibleRectForTesting()
4822 EXPECT_EQ("0,0 100x100", pending_layer_
->HighResTiling()
4823 ->GetCurrentVisibleRectForTesting()
4825 host_impl_
.pending_tree()->UpdateDrawProperties(false);
4826 EXPECT_EQ("0,50 100x100", pending_layer_
->HighResTiling()
4827 ->GetCurrentVisibleRectForTesting()
4831 TEST_F(PictureLayerImplTest
, UpdateLCDInvalidatesPendingTree
) {
4832 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4834 gfx::Size
tile_size(102, 102);
4835 gfx::Size
layer_bounds(100, 100);
4836 gfx::Size
viewport_size(100, 100);
4838 host_impl_
.SetViewportSize(viewport_size
);
4839 host_impl_
.SetDeviceScaleFactor(1.f
);
4841 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4842 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4843 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4845 EXPECT_TRUE(pending_layer_
->RasterSourceUsesLCDText());
4846 EXPECT_TRUE(pending_layer_
->HighResTiling()->has_tiles());
4847 std::vector
<Tile
*> tiles
=
4848 pending_layer_
->HighResTiling()->AllTilesForTesting();
4849 auto prioritized_tiles
= pending_layer_
->HighResTiling()
4850 ->UpdateAndGetAllPrioritizedTilesForTesting();
4852 for (Tile
* tile
: tiles
)
4853 EXPECT_EQ(pending_layer_
->raster_source(),
4854 prioritized_tiles
[tile
].raster_source());
4856 pending_layer_
->draw_properties().can_use_lcd_text
= false;
4857 pending_layer_
->UpdateCanUseLCDTextAfterCommit();
4859 EXPECT_FALSE(pending_layer_
->RasterSourceUsesLCDText());
4860 EXPECT_NE(pending_pile
.get(), pending_layer_
->raster_source());
4861 EXPECT_TRUE(pending_layer_
->HighResTiling()->has_tiles());
4862 tiles
= pending_layer_
->HighResTiling()->AllTilesForTesting();
4863 prioritized_tiles
= pending_layer_
->HighResTiling()
4864 ->UpdateAndGetAllPrioritizedTilesForTesting();
4865 for (Tile
* tile
: tiles
)
4866 EXPECT_EQ(pending_layer_
->raster_source(),
4867 prioritized_tiles
[tile
].raster_source());
4870 TEST_F(PictureLayerImplTest
, TilingAllTilesDone
) {
4871 gfx::Size tile_size
= host_impl_
.settings().default_tile_size
;
4872 size_t tile_mem
= 4 * tile_size
.width() * tile_size
.height();
4873 gfx::Size
layer_bounds(1000, 1000);
4876 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4877 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4878 SetupPendingTree(pending_pile
);
4879 pending_layer_
->SetBounds(layer_bounds
);
4881 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
4882 active_layer_
->HighResTiling()->AllTilesForTesting());
4883 host_impl_
.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES
);
4885 EXPECT_FALSE(active_layer_
->HighResTiling()->all_tiles_done());
4888 // Set a memory policy that will fit all tiles.
4889 size_t max_tiles
= 16;
4890 size_t memory_limit
= max_tiles
* tile_mem
;
4891 ManagedMemoryPolicy
policy(memory_limit
,
4892 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
,
4894 host_impl_
.SetMemoryPolicy(policy
);
4895 host_impl_
.PrepareTiles();
4897 EXPECT_TRUE(active_layer_
->HighResTiling()->all_tiles_done());
4901 // Set a memory policy that will cause tile eviction.
4902 size_t max_tiles
= 1;
4903 size_t memory_limit
= max_tiles
* tile_mem
;
4904 ManagedMemoryPolicy
policy(memory_limit
,
4905 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
,
4907 host_impl_
.SetMemoryPolicy(policy
);
4908 host_impl_
.PrepareTiles();
4910 EXPECT_FALSE(active_layer_
->HighResTiling()->all_tiles_done());
4914 class TileSizeSettings
: public PictureLayerImplTestSettings
{
4916 TileSizeSettings() {
4917 default_tile_size
= gfx::Size(100, 100);
4918 max_untiled_layer_size
= gfx::Size(200, 200);
4922 class TileSizeTest
: public PictureLayerImplTest
{
4924 TileSizeTest() : PictureLayerImplTest(TileSizeSettings()) {}
4927 TEST_F(TileSizeTest
, TileSizes
) {
4928 host_impl_
.CreatePendingTree();
4930 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
4931 scoped_ptr
<FakePictureLayerImpl
> layer
=
4932 FakePictureLayerImpl::Create(pending_tree
, id_
);
4934 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
4937 host_impl_
.SetContentIsSuitableForGpuRasterization(true);
4938 host_impl_
.SetHasGpuRasterizationTrigger(false);
4939 EXPECT_EQ(host_impl_
.gpu_rasterization_status(),
4940 GpuRasterizationStatus::OFF_VIEWPORT
);
4942 // Default tile-size for large layers.
4943 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
4944 EXPECT_EQ(result
.width(), 100);
4945 EXPECT_EQ(result
.height(), 100);
4946 // Don't tile and round-up, when under max_untiled_layer_size.
4947 result
= layer
->CalculateTileSize(gfx::Size(42, 42));
4948 EXPECT_EQ(result
.width(), 64);
4949 EXPECT_EQ(result
.height(), 64);
4950 result
= layer
->CalculateTileSize(gfx::Size(191, 191));
4951 EXPECT_EQ(result
.width(), 192);
4952 EXPECT_EQ(result
.height(), 192);
4953 result
= layer
->CalculateTileSize(gfx::Size(199, 199));
4954 EXPECT_EQ(result
.width(), 200);
4955 EXPECT_EQ(result
.height(), 200);
4957 // Gpu-rasterization uses 25% viewport-height tiles.
4958 // The +2's below are for border texels.
4959 host_impl_
.SetHasGpuRasterizationTrigger(true);
4960 EXPECT_EQ(host_impl_
.gpu_rasterization_status(), GpuRasterizationStatus::ON
);
4961 host_impl_
.SetViewportSize(gfx::Size(2000, 2000));
4963 layer
->set_gpu_raster_max_texture_size(host_impl_
.device_viewport_size());
4964 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
4965 EXPECT_EQ(result
.width(), 2000 + 2 * PictureLayerTiling::kBorderTexels
);
4966 EXPECT_EQ(result
.height(), 500 + 2);
4968 // Clamp and round-up, when smaller than viewport.
4969 // Tile-height doubles to 50% when width shrinks to <= 50%.
4970 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
4971 layer
->set_gpu_raster_max_texture_size(host_impl_
.device_viewport_size());
4972 result
= layer
->CalculateTileSize(gfx::Size(447, 10000));
4973 EXPECT_EQ(result
.width(), 448);
4974 EXPECT_EQ(result
.height(), 500 + 2);
4976 // Largest layer is 50% of viewport width (rounded up), and
4977 // 50% of viewport in height.
4978 result
= layer
->CalculateTileSize(gfx::Size(447, 400));
4979 EXPECT_EQ(result
.width(), 448);
4980 EXPECT_EQ(result
.height(), 448);
4981 result
= layer
->CalculateTileSize(gfx::Size(500, 499));
4982 EXPECT_EQ(result
.width(), 512);
4983 EXPECT_EQ(result
.height(), 500 + 2);
4986 TEST_F(NoLowResPictureLayerImplTest
, LowResWasHighResCollision
) {
4987 gfx::Size
tile_size(400, 400);
4988 gfx::Size
layer_bounds(1300, 1900);
4990 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
4992 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4993 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4994 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4995 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4997 // Set up the high and low res tilings before pinch zoom.
4998 SetupTrees(pending_pile
, active_pile
);
4999 ResetTilingsAndRasterScales();
5001 float page_scale
= 2.f
;
5002 SetContentsScaleOnBothLayers(page_scale
, 1.0f
, page_scale
, 1.0f
, 0.f
, false);
5003 EXPECT_BOTH_EQ(num_tilings(), 1u);
5004 EXPECT_BOTH_EQ(tilings()->tiling_at(0)->contents_scale(), page_scale
);
5006 host_impl_
.PinchGestureBegin();
5008 // Zoom out to exactly the low res factor so that the previous high res
5009 // would be equal to the current low res (if it were possible to have one).
5010 float zoomed
= page_scale
/ low_res_factor
;
5011 SetContentsScaleOnBothLayers(zoomed
, 1.0f
, zoomed
, 1.0f
, 0.f
, false);
5012 EXPECT_EQ(1u, pending_layer_
->num_tilings());
5013 EXPECT_EQ(zoomed
, pending_layer_
->tilings()->tiling_at(0)->contents_scale());
5016 TEST_F(PictureLayerImplTest
, HighResWasLowResCollision
) {
5017 gfx::Size
tile_size(400, 400);
5018 gfx::Size
layer_bounds(1300, 1900);
5020 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
5022 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
5023 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
5024 scoped_refptr
<FakePicturePileImpl
> active_pile
=
5025 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
5027 // Set up the high and low res tilings before pinch zoom.
5028 SetupTrees(pending_pile
, active_pile
);
5029 ResetTilingsAndRasterScales();
5031 float page_scale
= 4.f
;
5032 float low_res
= page_scale
* low_res_factor
;
5033 float extra_low_res
= low_res
* low_res_factor
;
5034 SetupDrawPropertiesAndUpdateTiles(active_layer_
, page_scale
, 1.0f
, page_scale
,
5036 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
5037 EXPECT_EQ(page_scale
,
5038 active_layer_
->tilings()->tiling_at(0)->contents_scale());
5039 EXPECT_EQ(low_res
, active_layer_
->tilings()->tiling_at(1)->contents_scale());
5041 // Grab a current low res tile.
5042 PictureLayerTiling
* old_low_res_tiling
=
5043 active_layer_
->tilings()->tiling_at(1);
5044 Tile
* old_low_res_tile
= active_layer_
->tilings()->tiling_at(1)->TileAt(0, 0);
5046 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
5048 // Zoom in to exactly the low res factor so that the previous low res
5049 // would be equal to the current high res.
5050 SetupDrawPropertiesAndUpdateTiles(active_layer_
, low_res
, 1.0f
, low_res
, 1.0f
,
5052 // 3 tilings. The old high res, the new high res (old low res) and the new low
5054 EXPECT_EQ(3u, active_layer_
->num_tilings());
5055 PictureLayerTilingSet
* tilings
= active_layer_
->tilings();
5056 EXPECT_EQ(page_scale
, tilings
->tiling_at(0)->contents_scale());
5057 EXPECT_EQ(low_res
, tilings
->tiling_at(1)->contents_scale());
5058 EXPECT_EQ(extra_low_res
, tilings
->tiling_at(2)->contents_scale());
5060 EXPECT_EQ(NON_IDEAL_RESOLUTION
, tilings
->tiling_at(0)->resolution());
5061 EXPECT_EQ(HIGH_RESOLUTION
, tilings
->tiling_at(1)->resolution());
5062 EXPECT_EQ(LOW_RESOLUTION
, tilings
->tiling_at(2)->resolution());
5064 EXPECT_FALSE(tilings
->tiling_at(0)->was_ever_low_resolution());
5065 EXPECT_TRUE(tilings
->tiling_at(1)->was_ever_low_resolution());
5066 EXPECT_TRUE(tilings
->tiling_at(2)->was_ever_low_resolution());
5068 // The old low res tile was destroyed and replaced.
5069 EXPECT_EQ(old_low_res_tiling
, tilings
->tiling_at(1));
5070 EXPECT_NE(old_low_res_tile
, tilings
->tiling_at(1)->TileAt(0, 0));
5071 EXPECT_TRUE(tilings
->tiling_at(1)->TileAt(0, 0));