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 class MockCanvas
: public SkCanvas
{
56 explicit MockCanvas(int w
, int h
) : SkCanvas(w
, h
) {}
58 void onDrawRect(const SkRect
& rect
, const SkPaint
& paint
) override
{
59 // Capture calls before SkCanvas quickReject() kicks in.
60 rects_
.push_back(rect
);
63 std::vector
<SkRect
> rects_
;
66 class NoLowResTilingsSettings
: public GpuRasterizationEnabledSettings
{};
68 class LowResTilingsSettings
: public GpuRasterizationEnabledSettings
{
70 LowResTilingsSettings() { create_low_res_tiling
= true; }
73 class PictureLayerImplTest
: public testing::Test
{
75 PictureLayerImplTest()
76 : proxy_(base::ThreadTaskRunnerHandle::Get()),
77 host_impl_(LowResTilingsSettings(),
79 &shared_bitmap_manager_
,
83 pending_layer_(nullptr),
84 old_pending_layer_(nullptr),
85 active_layer_(nullptr) {
86 host_impl_
.SetViewportSize(gfx::Size(10000, 10000));
89 explicit PictureLayerImplTest(const LayerTreeSettings
& settings
)
90 : proxy_(base::ThreadTaskRunnerHandle::Get()),
93 &shared_bitmap_manager_
,
97 host_impl_
.SetViewportSize(gfx::Size(10000, 10000));
100 ~PictureLayerImplTest() override
{}
102 void SetUp() override
{ InitializeRenderer(); }
104 virtual void InitializeRenderer() {
105 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d());
108 void SetupDefaultTrees(const gfx::Size
& layer_bounds
) {
109 gfx::Size
tile_size(100, 100);
111 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
112 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
113 scoped_refptr
<FakePicturePileImpl
> active_pile
=
114 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
116 SetupTrees(pending_pile
, active_pile
);
119 void SetupDefaultTreesWithInvalidation(const gfx::Size
& layer_bounds
,
120 const Region
& invalidation
) {
121 gfx::Size
tile_size(100, 100);
123 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
124 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
125 scoped_refptr
<FakePicturePileImpl
> active_pile
=
126 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
128 SetupTreesWithInvalidation(pending_pile
, active_pile
, invalidation
);
131 void ActivateTree() {
132 host_impl_
.ActivateSyncTree();
133 CHECK(!host_impl_
.pending_tree());
134 CHECK(host_impl_
.recycle_tree());
135 old_pending_layer_
= pending_layer_
;
136 pending_layer_
= nullptr;
137 active_layer_
= static_cast<FakePictureLayerImpl
*>(
138 host_impl_
.active_tree()->LayerById(id_
));
140 bool update_lcd_text
= false;
141 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
144 void SetupDefaultTreesWithFixedTileSize(const gfx::Size
& layer_bounds
,
145 const gfx::Size
& tile_size
,
146 const Region
& invalidation
) {
147 gfx::Size
pile_tile_size(100, 100);
149 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
150 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, layer_bounds
);
151 scoped_refptr
<FakePicturePileImpl
> active_pile
=
152 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, layer_bounds
);
154 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
,
159 scoped_refptr
<PicturePileImpl
> pending_pile
,
160 scoped_refptr
<PicturePileImpl
> active_pile
) {
161 SetupPendingTree(active_pile
);
163 SetupPendingTreeInternal(pending_pile
, gfx::Size(), Region());
166 void SetupTreesWithInvalidation(scoped_refptr
<PicturePileImpl
> pending_pile
,
167 scoped_refptr
<PicturePileImpl
> active_pile
,
168 const Region
& pending_invalidation
) {
169 SetupPendingTreeInternal(active_pile
, gfx::Size(), Region());
171 SetupPendingTreeInternal(pending_pile
, gfx::Size(), pending_invalidation
);
174 void SetupTreesWithFixedTileSize(scoped_refptr
<PicturePileImpl
> pending_pile
,
175 scoped_refptr
<PicturePileImpl
> active_pile
,
176 const gfx::Size
& tile_size
,
177 const Region
& pending_invalidation
) {
178 SetupPendingTreeInternal(active_pile
, tile_size
, Region());
180 SetupPendingTreeInternal(pending_pile
, tile_size
, pending_invalidation
);
183 void SetupPendingTree(scoped_refptr
<RasterSource
> raster_source
) {
184 SetupPendingTreeInternal(raster_source
, gfx::Size(), Region());
187 void SetupPendingTreeWithInvalidation(
188 scoped_refptr
<RasterSource
> raster_source
,
189 const Region
& invalidation
) {
190 SetupPendingTreeInternal(raster_source
, gfx::Size(), invalidation
);
193 void SetupPendingTreeWithFixedTileSize(
194 scoped_refptr
<RasterSource
> raster_source
,
195 const gfx::Size
& tile_size
,
196 const Region
& invalidation
) {
197 SetupPendingTreeInternal(raster_source
, tile_size
, invalidation
);
200 void SetupPendingTreeInternal(scoped_refptr
<RasterSource
> raster_source
,
201 const gfx::Size
& tile_size
,
202 const Region
& invalidation
) {
203 host_impl_
.CreatePendingTree();
204 host_impl_
.pending_tree()->PushPageScaleFromMainThread(1.f
, 0.25f
, 100.f
);
205 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
207 // Steal from the recycled tree if possible.
208 scoped_ptr
<LayerImpl
> pending_root
= pending_tree
->DetachLayerTree();
209 scoped_ptr
<FakePictureLayerImpl
> pending_layer
;
210 DCHECK_IMPLIES(pending_root
, pending_root
->id() == root_id_
);
212 pending_root
= LayerImpl::Create(pending_tree
, root_id_
);
213 pending_layer
= FakePictureLayerImpl::Create(pending_tree
, id_
);
214 if (!tile_size
.IsEmpty())
215 pending_layer
->set_fixed_tile_size(tile_size
);
216 pending_layer
->SetDrawsContent(true);
218 pending_layer
.reset(static_cast<FakePictureLayerImpl
*>(
219 pending_root
->RemoveChild(pending_root
->children()[0]).release()));
220 if (!tile_size
.IsEmpty())
221 pending_layer
->set_fixed_tile_size(tile_size
);
223 pending_root
->SetHasRenderSurface(true);
224 // The bounds() just mirror the pile size.
225 pending_layer
->SetBounds(raster_source
->GetSize());
226 pending_layer
->SetRasterSourceOnPending(raster_source
, invalidation
);
228 pending_root
->AddChild(pending_layer
.Pass());
229 pending_tree
->SetRootLayer(pending_root
.Pass());
231 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
232 host_impl_
.pending_tree()->LayerById(id_
));
234 // Add tilings/tiles for the layer.
235 bool update_lcd_text
= false;
236 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
239 void SetupDrawPropertiesAndUpdateTiles(
240 FakePictureLayerImpl
* layer
,
241 float ideal_contents_scale
,
242 float device_scale_factor
,
243 float page_scale_factor
,
244 float maximum_animation_contents_scale
,
245 float starting_animation_contents_scale
,
246 bool animating_transform_to_screen
) {
247 layer
->draw_properties().ideal_contents_scale
= ideal_contents_scale
;
248 layer
->draw_properties().device_scale_factor
= device_scale_factor
;
249 layer
->draw_properties().page_scale_factor
= page_scale_factor
;
250 layer
->draw_properties().maximum_animation_contents_scale
=
251 maximum_animation_contents_scale
;
252 layer
->draw_properties().starting_animation_contents_scale
=
253 starting_animation_contents_scale
;
254 layer
->draw_properties().screen_space_transform_is_animating
=
255 animating_transform_to_screen
;
256 bool resourceless_software_draw
= false;
257 layer
->UpdateTiles(resourceless_software_draw
);
259 static void VerifyAllPrioritizedTilesExistAndHavePile(
260 const PictureLayerTiling
* tiling
,
261 PicturePileImpl
* pile
) {
262 auto prioritized_tiles
=
263 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
264 for (PictureLayerTiling::CoverageIterator
iter(
266 tiling
->contents_scale(),
267 gfx::Rect(tiling
->tiling_size()));
271 EXPECT_EQ(pile
, prioritized_tiles
[*iter
].raster_source());
275 void SetContentsScaleOnBothLayers(float contents_scale
,
276 float device_scale_factor
,
277 float page_scale_factor
,
278 float maximum_animation_contents_scale
,
279 float starting_animation_contents_scale
,
280 bool animating_transform
) {
281 SetupDrawPropertiesAndUpdateTiles(
282 pending_layer_
, contents_scale
, device_scale_factor
, page_scale_factor
,
283 maximum_animation_contents_scale
, starting_animation_contents_scale
,
284 animating_transform
);
286 SetupDrawPropertiesAndUpdateTiles(
287 active_layer_
, contents_scale
, device_scale_factor
, page_scale_factor
,
288 maximum_animation_contents_scale
, starting_animation_contents_scale
,
289 animating_transform
);
292 void ResetTilingsAndRasterScales() {
293 if (pending_layer_
) {
294 pending_layer_
->ReleaseResources();
295 EXPECT_FALSE(pending_layer_
->tilings());
296 pending_layer_
->RecreateResources();
297 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
301 active_layer_
->ReleaseResources();
302 EXPECT_FALSE(active_layer_
->tilings());
303 active_layer_
->RecreateResources();
304 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
308 size_t NumberOfTilesRequired(PictureLayerTiling
* tiling
) {
309 size_t num_required
= 0;
310 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
311 for (size_t i
= 0; i
< tiles
.size(); ++i
) {
312 if (tiles
[i
]->required_for_activation())
318 void AssertAllTilesRequired(PictureLayerTiling
* tiling
) {
319 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
320 for (size_t i
= 0; i
< tiles
.size(); ++i
)
321 EXPECT_TRUE(tiles
[i
]->required_for_activation()) << "i: " << i
;
322 EXPECT_GT(tiles
.size(), 0u);
325 void AssertNoTilesRequired(PictureLayerTiling
* tiling
) {
326 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
327 for (size_t i
= 0; i
< tiles
.size(); ++i
)
328 EXPECT_FALSE(tiles
[i
]->required_for_activation()) << "i: " << i
;
329 EXPECT_GT(tiles
.size(), 0u);
333 void TestQuadsForSolidColor(bool test_for_solid
);
335 FakeImplProxy proxy_
;
336 TestSharedBitmapManager shared_bitmap_manager_
;
337 TestTaskGraphRunner task_graph_runner_
;
338 FakeLayerTreeHostImpl host_impl_
;
341 FakePictureLayerImpl
* pending_layer_
;
342 FakePictureLayerImpl
* old_pending_layer_
;
343 FakePictureLayerImpl
* active_layer_
;
344 LayerSettings layer_settings_
;
347 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest
);
350 class NoLowResPictureLayerImplTest
: public PictureLayerImplTest
{
352 NoLowResPictureLayerImplTest()
353 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
356 TEST_F(PictureLayerImplTest
, TileGridAlignment
) {
357 // Layer to span 4 raster tiles in x and in y
358 LayerTreeSettings settings
;
359 gfx::Size
layer_size(settings
.default_tile_size
.width() * 7 / 2,
360 settings
.default_tile_size
.height() * 7 / 2);
362 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
363 FakePicturePileImpl::CreateFilledPile(layer_size
, layer_size
);
365 scoped_ptr
<FakePicturePile
> active_recording
=
366 FakePicturePile::CreateFilledPile(layer_size
, layer_size
);
367 scoped_refptr
<FakePicturePileImpl
> active_pile
=
368 FakePicturePileImpl::CreateFromPile(active_recording
.get(), nullptr);
370 SetupTrees(pending_pile
, active_pile
);
372 // Add 1x1 rects at the centers of each tile, then re-record pile contents
373 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
374 std::vector
<Tile
*> tiles
=
375 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
376 EXPECT_EQ(16u, tiles
.size());
377 std::vector
<SkRect
> rects
;
378 std::vector
<Tile
*>::const_iterator tile_iter
;
379 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
380 gfx::Point tile_center
= (*tile_iter
)->content_rect().CenterPoint();
381 gfx::Rect
rect(tile_center
.x(), tile_center
.y(), 1, 1);
382 active_recording
->add_draw_rect(rect
);
383 rects
.push_back(SkRect::MakeXYWH(rect
.x(), rect
.y(), 1, 1));
386 // Force re-raster with newly injected content
387 active_recording
->RemoveRecordingAt(0, 0);
388 active_recording
->AddRecordingAt(0, 0);
390 scoped_refptr
<FakePicturePileImpl
> updated_active_pile
=
391 FakePicturePileImpl::CreateFromPile(active_recording
.get(), nullptr);
393 std::vector
<SkRect
>::const_iterator rect_iter
= rects
.begin();
394 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
395 MockCanvas
mock_canvas(1000, 1000);
396 updated_active_pile
->PlaybackToSharedCanvas(
397 &mock_canvas
, (*tile_iter
)->content_rect(), 1.0f
);
399 // This test verifies that when drawing the contents of a specific tile
400 // at content scale 1.0, the playback canvas never receives content from
401 // neighboring tiles which indicates that the tile grid embedded in
402 // SkPicture is perfectly aligned with the compositor's tiles.
403 EXPECT_EQ(1u, mock_canvas
.rects_
.size());
404 EXPECT_EQ(*rect_iter
, mock_canvas
.rects_
[0]);
409 TEST_F(PictureLayerImplTest
, CloneNoInvalidation
) {
410 gfx::Size
tile_size(100, 100);
411 gfx::Size
layer_bounds(400, 400);
413 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
414 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
415 scoped_refptr
<FakePicturePileImpl
> active_pile
=
416 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
418 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
420 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
421 active_layer_
->tilings()->num_tilings());
423 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
424 EXPECT_GT(tilings
->num_tilings(), 0u);
425 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
426 EXPECT_TRUE(tilings
->tiling_at(i
)->AllTilesForTesting().empty());
429 TEST_F(PictureLayerImplTest
, ExternalViewportRectForPrioritizingTiles
) {
430 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
431 gfx::Size
tile_size(100, 100);
432 gfx::Size
layer_bounds(400, 400);
434 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
435 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
436 scoped_refptr
<FakePicturePileImpl
> active_pile
=
437 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
439 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
441 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
444 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
446 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the
447 // identify transform for tile priority.
448 bool resourceless_software_draw
= false;
449 gfx::Rect viewport
= gfx::Rect(layer_bounds
),
450 viewport_rect_for_tile_priority
= gfx::Rect(0, 0, 100, 100);
451 gfx::Transform transform
, transform_for_tile_priority
;
453 host_impl_
.SetExternalDrawConstraints(transform
,
456 viewport_rect_for_tile_priority
,
457 transform_for_tile_priority
,
458 resourceless_software_draw
);
459 bool update_lcd_text
= false;
460 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
462 gfx::Rect viewport_rect_for_tile_priority_in_view_space
=
463 viewport_rect_for_tile_priority
;
465 // Verify the viewport rect for tile priority is used in picture layer tiling.
466 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
467 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
468 PictureLayerTilingSet
* tilings
= active_layer_
->tilings();
469 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
470 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
472 tiling
->GetCurrentVisibleRectForTesting(),
473 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
474 tiling
->contents_scale()));
477 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in
478 // screen space and the transform for tile priority is translated and
479 // rotated. The actual viewport for tile priority used by PictureLayerImpl
480 // should be (200, 200, 100, 100) applied with the said transform.
481 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
483 viewport_rect_for_tile_priority
= gfx::Rect(200, 200, 100, 100);
484 transform_for_tile_priority
.Translate(100, 100);
485 transform_for_tile_priority
.Rotate(45);
486 host_impl_
.SetExternalDrawConstraints(transform
,
489 viewport_rect_for_tile_priority
,
490 transform_for_tile_priority
,
491 resourceless_software_draw
);
492 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
494 gfx::Transform
screen_to_view(gfx::Transform::kSkipInitialization
);
495 bool success
= transform_for_tile_priority
.GetInverse(&screen_to_view
);
496 EXPECT_TRUE(success
);
498 // Note that we don't clip this to the layer bounds, since it is expected that
499 // the rect will sometimes be outside of the layer bounds. If we clip to
500 // bounds, then tile priorities will end up being incorrect in cases of fully
502 viewport_rect_for_tile_priority_in_view_space
=
503 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
504 screen_to_view
, viewport_rect_for_tile_priority
));
506 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
507 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
508 tilings
= active_layer_
->tilings();
509 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
510 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
512 tiling
->GetCurrentVisibleRectForTesting(),
513 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
514 tiling
->contents_scale()));
518 TEST_F(PictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
519 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
521 gfx::Size
tile_size(100, 100);
522 gfx::Size
layer_bounds(400, 400);
524 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
525 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
526 scoped_refptr
<FakePicturePileImpl
> active_pile
=
527 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
529 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
531 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
534 // UpdateTiles with valid viewport. Should update tile viewport.
535 // Note viewport is considered invalid if and only if in resourceless
537 bool resourceless_software_draw
= false;
538 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
539 gfx::Transform transform
;
540 host_impl_
.SetExternalDrawConstraints(transform
,
545 resourceless_software_draw
);
546 active_layer_
->draw_properties().visible_layer_rect
= viewport
;
547 active_layer_
->draw_properties().screen_space_transform
= transform
;
548 active_layer_
->UpdateTiles(resourceless_software_draw
);
550 gfx::Rect visible_rect_for_tile_priority
=
551 active_layer_
->visible_rect_for_tile_priority();
552 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
553 gfx::Transform screen_space_transform_for_tile_priority
=
554 active_layer_
->screen_space_transform();
556 // Expand viewport and set it as invalid for prioritizing tiles.
557 // Should update viewport and transform, but not update visible rect.
558 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
559 resourceless_software_draw
= true;
560 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
561 transform
.Translate(1.f
, 1.f
);
562 active_layer_
->draw_properties().visible_layer_rect
= viewport
;
563 active_layer_
->draw_properties().screen_space_transform
= transform
;
564 host_impl_
.SetExternalDrawConstraints(transform
,
569 resourceless_software_draw
);
570 active_layer_
->UpdateTiles(resourceless_software_draw
);
572 // Transform for tile priority is updated.
573 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
574 active_layer_
->screen_space_transform());
575 // Visible rect for tile priority retains old value.
576 EXPECT_EQ(visible_rect_for_tile_priority
,
577 active_layer_
->visible_rect_for_tile_priority());
579 // Keep expanded viewport but mark it valid. Should update tile viewport.
580 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
581 resourceless_software_draw
= false;
582 host_impl_
.SetExternalDrawConstraints(transform
,
587 resourceless_software_draw
);
588 active_layer_
->UpdateTiles(resourceless_software_draw
);
590 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
591 active_layer_
->screen_space_transform());
592 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
595 TEST_F(PictureLayerImplTest
, ViewportRectForTilePriorityIsCached
) {
596 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
597 gfx::Size
tile_size(100, 100);
598 gfx::Size
layer_bounds(400, 400);
600 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
601 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
602 scoped_refptr
<FakePicturePileImpl
> active_pile
=
603 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
605 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
607 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
610 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
612 bool resourceless_software_draw
= false;
613 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
614 gfx::Rect
viewport_rect_for_tile_priority(0, 0, 100, 100);
615 gfx::Transform transform
, transform_for_tile_priority
;
617 host_impl_
.SetExternalDrawConstraints(
618 transform
, viewport
, viewport
, viewport_rect_for_tile_priority
,
619 transform_for_tile_priority
, resourceless_software_draw
);
620 bool update_lcd_text
= false;
621 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
623 EXPECT_EQ(viewport_rect_for_tile_priority
,
624 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
626 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
628 gfx::Rect
another_viewport_rect_for_tile_priority(11, 11, 50, 50);
629 host_impl_
.SetExternalDrawConstraints(
630 transform
, viewport
, viewport
, another_viewport_rect_for_tile_priority
,
631 transform_for_tile_priority
, resourceless_software_draw
);
633 // Didn't call UpdateDrawProperties yet. The viewport rect for tile priority
634 // should remain to be the previously cached value.
635 EXPECT_EQ(viewport_rect_for_tile_priority
,
636 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
637 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
639 // Now the UpdateDrawProperties is called. The viewport rect for tile
640 // priority should be the latest value.
641 EXPECT_EQ(another_viewport_rect_for_tile_priority
,
642 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
645 TEST_F(PictureLayerImplTest
, ClonePartialInvalidation
) {
646 gfx::Size
tile_size(100, 100);
647 gfx::Size
layer_bounds(400, 400);
648 gfx::Rect
layer_invalidation(150, 200, 30, 180);
650 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
651 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
652 scoped_refptr
<FakePicturePileImpl
> active_pile
=
653 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
654 scoped_refptr
<FakePicturePileImpl
> lost_pile
=
655 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
657 SetupPendingTreeWithFixedTileSize(lost_pile
, gfx::Size(50, 50), Region());
659 // Add a unique tiling on the active tree.
660 PictureLayerTiling
* tiling
= active_layer_
->AddTiling(3.f
);
661 tiling
->CreateAllTilesForTesting();
663 // Ensure UpdateTiles won't remove any tilings.
664 active_layer_
->MarkAllTilingsUsed();
666 // Then setup a new pending tree and activate it.
667 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, gfx::Size(50, 50),
670 EXPECT_EQ(2u, pending_layer_
->num_tilings());
671 EXPECT_EQ(3u, active_layer_
->num_tilings());
673 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
674 EXPECT_GT(tilings
->num_tilings(), 0u);
675 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
676 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
677 gfx::Rect content_invalidation
= gfx::ScaleToEnclosingRect(
679 tiling
->contents_scale());
680 auto prioritized_tiles
=
681 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
682 for (PictureLayerTiling::CoverageIterator
iter(
684 tiling
->contents_scale(),
685 gfx::Rect(tiling
->tiling_size()));
688 // We don't always have a tile, but when we do it's because it was
689 // invalidated and it has the latest raster source.
691 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
692 EXPECT_EQ(pending_pile
.get(), prioritized_tiles
[*iter
].raster_source());
693 EXPECT_TRUE(iter
.geometry_rect().Intersects(content_invalidation
));
695 // We don't create tiles in non-invalidated regions.
696 EXPECT_FALSE(iter
.geometry_rect().Intersects(content_invalidation
));
701 tilings
= active_layer_
->tilings();
702 EXPECT_GT(tilings
->num_tilings(), 0u);
703 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
704 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
705 gfx::Rect content_invalidation
=
706 gfx::ScaleToEnclosingRect(layer_invalidation
, tiling
->contents_scale());
707 auto prioritized_tiles
=
708 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
709 for (PictureLayerTiling::CoverageIterator
iter(
711 tiling
->contents_scale(),
712 gfx::Rect(tiling
->tiling_size()));
716 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
717 // Pile will be updated upon activation.
718 EXPECT_EQ(active_pile
.get(), prioritized_tiles
[*iter
].raster_source());
723 TEST_F(PictureLayerImplTest
, CloneFullInvalidation
) {
724 gfx::Size
tile_size(90, 80);
725 gfx::Size
layer_bounds(300, 500);
727 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
728 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
729 scoped_refptr
<FakePicturePileImpl
> active_pile
=
730 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
732 SetupTreesWithInvalidation(pending_pile
, active_pile
,
733 gfx::Rect(layer_bounds
));
735 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
736 active_layer_
->tilings()->num_tilings());
738 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
739 EXPECT_GT(tilings
->num_tilings(), 0u);
740 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
741 VerifyAllPrioritizedTilesExistAndHavePile(tilings
->tiling_at(i
),
745 TEST_F(PictureLayerImplTest
, UpdateTilesCreatesTilings
) {
746 gfx::Size
tile_size(400, 400);
747 gfx::Size
layer_bounds(1300, 1900);
749 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
750 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
751 scoped_refptr
<FakePicturePileImpl
> active_pile
=
752 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
754 SetupTrees(pending_pile
, active_pile
);
756 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
757 EXPECT_LT(low_res_factor
, 1.f
);
759 active_layer_
->ReleaseResources();
760 EXPECT_FALSE(active_layer_
->tilings());
761 active_layer_
->RecreateResources();
762 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
764 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
765 6.f
, // ideal contents scale
768 1.f
, // maximum animation scale
769 0.f
, // starting animation scale
771 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
773 active_layer_
->tilings()->tiling_at(0)->contents_scale());
774 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
775 active_layer_
->tilings()->tiling_at(1)->contents_scale());
777 // If we change the page scale factor, then we should get new tilings.
778 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
779 6.6f
, // ideal contents scale
782 1.f
, // maximum animation scale
783 0.f
, // starting animation scale
785 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
786 EXPECT_FLOAT_EQ(6.6f
,
787 active_layer_
->tilings()->tiling_at(0)->contents_scale());
788 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
789 active_layer_
->tilings()->tiling_at(2)->contents_scale());
791 // If we change the device scale factor, then we should get new tilings.
792 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
793 7.26f
, // ideal contents scale
794 3.3f
, // device scale
796 1.f
, // maximum animation scale
797 0.f
, // starting animation scale
799 ASSERT_EQ(6u, active_layer_
->tilings()->num_tilings());
800 EXPECT_FLOAT_EQ(7.26f
,
801 active_layer_
->tilings()->tiling_at(0)->contents_scale());
802 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
803 active_layer_
->tilings()->tiling_at(3)->contents_scale());
805 // If we change the device scale factor, but end up at the same total scale
806 // factor somehow, then we don't get new tilings.
807 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
808 7.26f
, // ideal contents scale
809 2.2f
, // device scale
811 1.f
, // maximum animation scale
812 0.f
, // starting animation scale
814 ASSERT_EQ(6u, active_layer_
->tilings()->num_tilings());
815 EXPECT_FLOAT_EQ(7.26f
,
816 active_layer_
->tilings()->tiling_at(0)->contents_scale());
817 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
818 active_layer_
->tilings()->tiling_at(3)->contents_scale());
821 TEST_F(PictureLayerImplTest
, PendingLayerOnlyHasHighAndLowResTiling
) {
822 gfx::Size
tile_size(400, 400);
823 gfx::Size
layer_bounds(1300, 1900);
825 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
826 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
827 scoped_refptr
<FakePicturePileImpl
> active_pile
=
828 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
830 SetupTrees(pending_pile
, active_pile
);
832 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
833 EXPECT_LT(low_res_factor
, 1.f
);
835 pending_layer_
->ReleaseResources();
836 EXPECT_FALSE(pending_layer_
->tilings());
837 pending_layer_
->RecreateResources();
838 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
840 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
841 6.f
, // ideal contents scale
844 1.f
, // maximum animation scale
845 0.f
, // starting animation scale
847 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
849 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
850 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
851 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
853 // If we change the page scale factor, then we should get new tilings.
854 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
855 6.6f
, // ideal contents scale
858 1.f
, // maximum animation scale
859 0.f
, // starting animation scale
861 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
862 EXPECT_FLOAT_EQ(6.6f
,
863 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
864 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
865 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
867 // If we change the device scale factor, then we should get new tilings.
868 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
869 7.26f
, // ideal contents scale
870 3.3f
, // device scale
872 1.f
, // maximum animation scale
873 0.f
, // starting animation scale
875 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
876 EXPECT_FLOAT_EQ(7.26f
,
877 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
878 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
879 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
881 // If we change the device scale factor, but end up at the same total scale
882 // factor somehow, then we don't get new tilings.
883 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
884 7.26f
, // ideal contents scale
885 2.2f
, // device scale
887 1.f
, // maximum animation scale
888 0.f
, // starting animation scale
890 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
891 EXPECT_FLOAT_EQ(7.26f
,
892 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
893 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
894 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
897 TEST_F(PictureLayerImplTest
, CreateTilingsEvenIfTwinHasNone
) {
898 // This test makes sure that if a layer can have tilings, then a commit makes
899 // it not able to have tilings (empty size), and then a future commit that
900 // makes it valid again should be able to create tilings.
901 gfx::Size
tile_size(400, 400);
902 gfx::Size
layer_bounds(1300, 1900);
904 scoped_refptr
<FakePicturePileImpl
> empty_pile
=
905 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
906 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
907 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
909 SetupPendingTree(valid_pile
);
910 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
913 SetupPendingTree(empty_pile
);
914 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
915 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
916 ASSERT_EQ(0u, pending_layer_
->tilings()->num_tilings());
919 EXPECT_FALSE(active_layer_
->CanHaveTilings());
920 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
922 SetupPendingTree(valid_pile
);
923 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
924 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
927 TEST_F(PictureLayerImplTest
, ZoomOutCrash
) {
928 gfx::Size
tile_size(400, 400);
929 gfx::Size
layer_bounds(1300, 1900);
931 // Set up the high and low res tilings before pinch zoom.
932 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
933 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
934 scoped_refptr
<FakePicturePileImpl
> active_pile
=
935 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
937 SetupTrees(pending_pile
, active_pile
);
938 ResetTilingsAndRasterScales();
939 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
940 SetContentsScaleOnBothLayers(32.0f
, 1.0f
, 32.0f
, 1.0f
, 0.f
, false);
941 EXPECT_EQ(32.f
, active_layer_
->HighResTiling()->contents_scale());
942 host_impl_
.PinchGestureBegin();
943 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.f
, false);
944 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.f
, false);
945 EXPECT_EQ(active_layer_
->tilings()->NumHighResTilings(), 1);
948 TEST_F(PictureLayerImplTest
, PinchGestureTilings
) {
949 gfx::Size
tile_size(400, 400);
950 gfx::Size
layer_bounds(1300, 1900);
952 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
954 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
955 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
956 scoped_refptr
<FakePicturePileImpl
> active_pile
=
957 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
959 // Set up the high and low res tilings before pinch zoom.
960 SetupTrees(pending_pile
, active_pile
);
961 ResetTilingsAndRasterScales();
963 SetContentsScaleOnBothLayers(2.f
, 1.0f
, 2.f
, 1.0f
, 0.f
, false);
964 EXPECT_BOTH_EQ(num_tilings(), 2u);
965 EXPECT_BOTH_EQ(tilings()->tiling_at(0)->contents_scale(), 2.f
);
966 EXPECT_BOTH_EQ(tilings()->tiling_at(1)->contents_scale(),
967 2.f
* low_res_factor
);
969 // Ensure UpdateTiles won't remove any tilings.
970 active_layer_
->MarkAllTilingsUsed();
972 // Start a pinch gesture.
973 host_impl_
.PinchGestureBegin();
975 // Zoom out by a small amount. We should create a tiling at half
976 // the scale (2/kMaxScaleRatioDuringPinch).
977 SetContentsScaleOnBothLayers(1.8f
, 1.0f
, 1.8f
, 1.0f
, 0.f
, false);
978 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
979 EXPECT_FLOAT_EQ(2.0f
,
980 active_layer_
->tilings()->tiling_at(0)->contents_scale());
981 EXPECT_FLOAT_EQ(1.0f
,
982 active_layer_
->tilings()->tiling_at(1)->contents_scale());
983 EXPECT_FLOAT_EQ(2.0f
* low_res_factor
,
984 active_layer_
->tilings()->tiling_at(2)->contents_scale());
986 // Ensure UpdateTiles won't remove any tilings.
987 active_layer_
->MarkAllTilingsUsed();
989 // Zoom out further, close to our low-res scale factor. We should
990 // use that tiling as high-res, and not create a new tiling.
991 SetContentsScaleOnBothLayers(low_res_factor
* 2.1f
, 1.0f
,
992 low_res_factor
* 2.1f
, 1.0f
, 0.f
, false);
993 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
995 // Zoom in a lot now. Since we increase by increments of
996 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0.
997 SetContentsScaleOnBothLayers(3.8f
, 1.0f
, 3.8f
, 1.f
, 0.f
, false);
998 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
999 EXPECT_FLOAT_EQ(4.0f
,
1000 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1003 TEST_F(PictureLayerImplTest
, SnappedTilingDuringZoom
) {
1004 gfx::Size
tile_size(300, 300);
1005 gfx::Size
layer_bounds(2600, 3800);
1007 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1008 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1009 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1010 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1012 SetupTrees(pending_pile
, active_pile
);
1014 ResetTilingsAndRasterScales();
1015 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1017 // Set up the high and low res tilings before pinch zoom.
1018 SetContentsScaleOnBothLayers(0.24f
, 1.0f
, 0.24f
, 1.0f
, 0.f
, false);
1019 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1020 EXPECT_FLOAT_EQ(0.24f
,
1021 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1022 EXPECT_FLOAT_EQ(0.0625f
,
1023 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1025 // Ensure UpdateTiles won't remove any tilings.
1026 active_layer_
->MarkAllTilingsUsed();
1028 // Start a pinch gesture.
1029 host_impl_
.PinchGestureBegin();
1031 // Zoom out by a small amount. We should create a tiling at half
1032 // the scale (1/kMaxScaleRatioDuringPinch).
1033 SetContentsScaleOnBothLayers(0.2f
, 1.0f
, 0.2f
, 1.0f
, 0.f
, false);
1034 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1035 EXPECT_FLOAT_EQ(0.24f
,
1036 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1037 EXPECT_FLOAT_EQ(0.12f
,
1038 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1039 EXPECT_FLOAT_EQ(0.0625,
1040 active_layer_
->tilings()->tiling_at(2)->contents_scale());
1042 // Ensure UpdateTiles won't remove any tilings.
1043 active_layer_
->MarkAllTilingsUsed();
1045 // Zoom out further, close to our low-res scale factor. We should
1046 // use that tiling as high-res, and not create a new tiling.
1047 SetContentsScaleOnBothLayers(0.1f
, 1.0f
, 0.1f
, 1.0f
, 0.f
, false);
1048 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1050 // Zoom in. 0.25(desired_scale) should be snapped to 0.24 during zoom-in
1051 // because 0.25(desired_scale) is within the ratio(1.2).
1052 SetContentsScaleOnBothLayers(0.25f
, 1.0f
, 0.25f
, 1.0f
, 0.f
, false);
1053 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1055 // Zoom in a lot. Since we move in factors of two, we should get a scale that
1056 // is a power of 2 times 0.24.
1057 SetContentsScaleOnBothLayers(1.f
, 1.0f
, 1.f
, 1.0f
, 0.f
, false);
1058 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
1059 EXPECT_FLOAT_EQ(1.92f
,
1060 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1063 TEST_F(PictureLayerImplTest
, CleanUpTilings
) {
1064 gfx::Size
tile_size(400, 400);
1065 gfx::Size
layer_bounds(1300, 1900);
1067 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1068 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1069 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1070 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1072 std::vector
<PictureLayerTiling
*> used_tilings
;
1074 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1075 EXPECT_LT(low_res_factor
, 1.f
);
1078 float page_scale
= 1.f
;
1080 SetupTrees(pending_pile
, active_pile
);
1081 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1082 EXPECT_EQ(1.f
, active_layer_
->HighResTiling()->contents_scale());
1084 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
1085 // |used_tilings| variable, and it's here only to ensure that active_layer_
1086 // won't remove tilings before the test has a chance to verify behavior.
1087 active_layer_
->MarkAllTilingsUsed();
1089 // We only have ideal tilings, so they aren't removed.
1090 used_tilings
.clear();
1091 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1092 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1094 host_impl_
.PinchGestureBegin();
1096 // Changing the ideal but not creating new tilings.
1099 SetContentsScaleOnBothLayers(scale
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1100 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1102 // The tilings are still our target scale, so they aren't removed.
1103 used_tilings
.clear();
1104 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1105 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
1107 host_impl_
.PinchGestureEnd();
1109 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
1112 SetContentsScaleOnBothLayers(1.2f
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1113 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
1116 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1118 1.f
* low_res_factor
,
1119 active_layer_
->tilings()->tiling_at(3)->contents_scale());
1121 // Ensure UpdateTiles won't remove any tilings.
1122 active_layer_
->MarkAllTilingsUsed();
1124 // Mark the non-ideal tilings as used. They won't be removed.
1125 used_tilings
.clear();
1126 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1127 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(3));
1128 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1129 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
1131 // Now move the ideal scale to 0.5. Our target stays 1.2.
1132 SetContentsScaleOnBothLayers(0.5f
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1134 // The high resolution tiling is between target and ideal, so is not
1135 // removed. The low res tiling for the old ideal=1.0 scale is removed.
1136 used_tilings
.clear();
1137 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1138 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1140 // Now move the ideal scale to 1.0. Our target stays 1.2.
1141 SetContentsScaleOnBothLayers(1.f
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1143 // All the tilings are between are target and the ideal, so they are not
1145 used_tilings
.clear();
1146 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1147 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1149 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
1150 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.1f
, 1.f
, page_scale
, 1.f
,
1153 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1154 // in the range [1.0,1.2] and are kept.
1155 used_tilings
.clear();
1156 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1157 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1159 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1161 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.1f
, 1.f
, page_scale
, 1.f
,
1164 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1165 // target raster scale. But it is in our used tilings set, so nothing is
1167 used_tilings
.clear();
1168 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1169 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1170 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1172 // If we remove it from our used tilings set, it is outside the range to keep
1173 // so it is deleted.
1174 used_tilings
.clear();
1175 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1176 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
1179 TEST_F(PictureLayerImplTest
, DontAddLowResDuringAnimation
) {
1180 // Make sure this layer covers multiple tiles, since otherwise low
1181 // res won't get created because it is too small.
1182 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1183 // Avoid max untiled layer size heuristics via fixed tile size.
1184 gfx::Size
layer_bounds(tile_size
.width() + 1, tile_size
.height() + 1);
1185 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
1187 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1188 float contents_scale
= 1.f
;
1189 float device_scale
= 1.f
;
1190 float page_scale
= 1.f
;
1191 float maximum_animation_scale
= 1.f
;
1192 float starting_animation_scale
= 0.f
;
1193 bool animating_transform
= true;
1195 ResetTilingsAndRasterScales();
1197 // Animating, so don't create low res even if there isn't one already.
1198 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1199 maximum_animation_scale
,
1200 starting_animation_scale
, animating_transform
);
1201 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1202 EXPECT_BOTH_EQ(num_tilings(), 1u);
1204 // Stop animating, low res gets created.
1205 animating_transform
= false;
1206 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1207 maximum_animation_scale
,
1208 starting_animation_scale
, animating_transform
);
1209 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1210 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor
);
1211 EXPECT_BOTH_EQ(num_tilings(), 2u);
1213 // Ensure UpdateTiles won't remove any tilings.
1214 active_layer_
->MarkAllTilingsUsed();
1216 // Page scale animation, new high res, but no low res. We still have
1217 // a tiling at the previous scale, it's just not marked as low res on the
1218 // active layer. The pending layer drops non-ideal tilings.
1219 contents_scale
= 2.f
;
1221 maximum_animation_scale
= 2.f
;
1222 animating_transform
= true;
1223 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1224 maximum_animation_scale
,
1225 starting_animation_scale
, animating_transform
);
1226 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1227 EXPECT_FALSE(active_layer_
->LowResTiling());
1228 EXPECT_FALSE(pending_layer_
->LowResTiling());
1229 EXPECT_EQ(3u, active_layer_
->num_tilings());
1230 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1232 // Stop animating, new low res gets created for final page scale.
1233 animating_transform
= false;
1234 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1235 maximum_animation_scale
,
1236 starting_animation_scale
, animating_transform
);
1237 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1238 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f
* low_res_factor
);
1239 EXPECT_EQ(4u, active_layer_
->num_tilings());
1240 EXPECT_EQ(2u, pending_layer_
->num_tilings());
1243 TEST_F(PictureLayerImplTest
, DontAddLowResForSmallLayers
) {
1244 gfx::Size
layer_bounds(host_impl_
.settings().default_tile_size
);
1245 gfx::Size
tile_size(100, 100);
1247 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1248 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1249 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1250 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1252 SetupTrees(pending_pile
, active_pile
);
1254 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1255 float device_scale
= 1.f
;
1256 float page_scale
= 1.f
;
1257 float maximum_animation_scale
= 1.f
;
1258 float starting_animation_scale
= 0.f
;
1259 bool animating_transform
= false;
1261 // Contents exactly fit on one tile at scale 1, no low res.
1262 float contents_scale
= 1.f
;
1263 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1264 maximum_animation_scale
,
1265 starting_animation_scale
, animating_transform
);
1266 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1267 EXPECT_BOTH_EQ(num_tilings(), 1u);
1269 ResetTilingsAndRasterScales();
1271 // Contents that are smaller than one tile, no low res.
1272 contents_scale
= 0.123f
;
1273 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1274 maximum_animation_scale
,
1275 starting_animation_scale
, animating_transform
);
1276 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1277 EXPECT_BOTH_EQ(num_tilings(), 1u);
1279 ResetTilingsAndRasterScales();
1281 // Any content bounds that would create more than one tile will
1282 // generate a low res tiling.
1283 contents_scale
= 2.5f
;
1284 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1285 maximum_animation_scale
,
1286 starting_animation_scale
, animating_transform
);
1287 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1288 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1289 contents_scale
* low_res_factor
);
1290 EXPECT_BOTH_EQ(num_tilings(), 2u);
1292 // Mask layers dont create low res since they always fit on one tile.
1293 scoped_ptr
<FakePictureLayerImpl
> mask
=
1294 FakePictureLayerImpl::CreateMaskWithRasterSource(
1295 host_impl_
.pending_tree(), 3, pending_pile
);
1296 mask
->SetBounds(layer_bounds
);
1297 mask
->SetDrawsContent(true);
1299 SetupDrawPropertiesAndUpdateTiles(
1300 mask
.get(), contents_scale
, device_scale
, page_scale
,
1301 maximum_animation_scale
, starting_animation_scale
, animating_transform
);
1302 EXPECT_EQ(mask
->HighResTiling()->contents_scale(), contents_scale
);
1303 EXPECT_EQ(mask
->num_tilings(), 1u);
1306 TEST_F(PictureLayerImplTest
, HugeMasksGetScaledDown
) {
1307 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1309 gfx::Size
tile_size(100, 100);
1310 gfx::Size
layer_bounds(1000, 1000);
1312 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1313 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1314 SetupPendingTree(valid_pile
);
1316 scoped_ptr
<FakePictureLayerImpl
> mask_ptr
=
1317 FakePictureLayerImpl::CreateMaskWithRasterSource(
1318 host_impl_
.pending_tree(), 3, valid_pile
);
1319 mask_ptr
->SetBounds(layer_bounds
);
1320 mask_ptr
->SetDrawsContent(true);
1321 pending_layer_
->SetMaskLayer(mask_ptr
.Pass());
1322 pending_layer_
->SetHasRenderSurface(true);
1324 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1325 bool update_lcd_text
= false;
1326 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1328 FakePictureLayerImpl
* pending_mask
=
1329 static_cast<FakePictureLayerImpl
*>(pending_layer_
->mask_layer());
1331 EXPECT_EQ(1.f
, pending_mask
->HighResTiling()->contents_scale());
1332 EXPECT_EQ(1u, pending_mask
->num_tilings());
1334 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1335 pending_mask
->HighResTiling()->AllTilesForTesting());
1339 FakePictureLayerImpl
* active_mask
=
1340 static_cast<FakePictureLayerImpl
*>(active_layer_
->mask_layer());
1342 // Mask layers have a tiling with a single tile in it.
1343 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1344 // The mask resource exists.
1345 ResourceId mask_resource_id
;
1346 gfx::Size mask_texture_size
;
1347 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1348 EXPECT_NE(0u, mask_resource_id
);
1349 EXPECT_EQ(active_mask
->bounds(), mask_texture_size
);
1351 // Drop resources and recreate them, still the same.
1352 pending_mask
->ReleaseResources();
1353 active_mask
->ReleaseResources();
1354 pending_mask
->RecreateResources();
1355 active_mask
->RecreateResources();
1356 SetupDrawPropertiesAndUpdateTiles(active_mask
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1358 active_mask
->HighResTiling()->CreateAllTilesForTesting();
1359 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1360 EXPECT_NE(0u, mask_resource_id
);
1361 EXPECT_EQ(active_mask
->bounds(), mask_texture_size
);
1363 // Resize larger than the max texture size.
1364 int max_texture_size
= host_impl_
.GetRendererCapabilities().max_texture_size
;
1365 gfx::Size
huge_bounds(max_texture_size
+ 1, 10);
1366 scoped_refptr
<FakePicturePileImpl
> huge_pile
=
1367 FakePicturePileImpl::CreateFilledPile(tile_size
, huge_bounds
);
1369 SetupPendingTree(huge_pile
);
1370 pending_mask
->SetBounds(huge_bounds
);
1371 pending_mask
->SetRasterSourceOnPending(huge_pile
, Region());
1373 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1374 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1376 // The mask tiling gets scaled down.
1377 EXPECT_LT(pending_mask
->HighResTiling()->contents_scale(), 1.f
);
1378 EXPECT_EQ(1u, pending_mask
->num_tilings());
1380 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1381 pending_mask
->HighResTiling()->AllTilesForTesting());
1385 // Mask layers have a tiling with a single tile in it.
1386 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1387 // The mask resource exists.
1388 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1389 EXPECT_NE(0u, mask_resource_id
);
1390 gfx::Size expected_size
= active_mask
->bounds();
1391 expected_size
.SetToMin(gfx::Size(max_texture_size
, max_texture_size
));
1392 EXPECT_EQ(expected_size
, mask_texture_size
);
1394 // Drop resources and recreate them, still the same.
1395 pending_mask
->ReleaseResources();
1396 active_mask
->ReleaseResources();
1397 pending_mask
->RecreateResources();
1398 active_mask
->RecreateResources();
1399 SetupDrawPropertiesAndUpdateTiles(active_mask
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1401 active_mask
->HighResTiling()->CreateAllTilesForTesting();
1402 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1403 EXPECT_NE(0u, mask_resource_id
);
1404 EXPECT_EQ(expected_size
, mask_texture_size
);
1406 // Do another activate, the same holds.
1407 SetupPendingTree(huge_pile
);
1409 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1410 active_layer_
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1411 EXPECT_EQ(expected_size
, mask_texture_size
);
1412 EXPECT_EQ(0u, mask_resource_id
);
1414 // Resize even larger, so that the scale would be smaller than the minimum
1415 // contents scale. Then the layer should no longer have any tiling.
1416 float min_contents_scale
= host_impl_
.settings().minimum_contents_scale
;
1417 gfx::Size
extra_huge_bounds(max_texture_size
/ min_contents_scale
+ 1, 10);
1418 scoped_refptr
<FakePicturePileImpl
> extra_huge_pile
=
1419 FakePicturePileImpl::CreateFilledPile(tile_size
, extra_huge_bounds
);
1421 SetupPendingTree(extra_huge_pile
);
1422 pending_mask
->SetBounds(extra_huge_bounds
);
1423 pending_mask
->SetRasterSourceOnPending(extra_huge_pile
, Region());
1425 EXPECT_FALSE(pending_mask
->CanHaveTilings());
1427 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1428 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1430 EXPECT_EQ(0u, pending_mask
->num_tilings());
1433 TEST_F(PictureLayerImplTest
, ScaledMaskLayer
) {
1434 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1436 gfx::Size
tile_size(100, 100);
1437 gfx::Size
layer_bounds(1000, 1000);
1439 host_impl_
.SetDeviceScaleFactor(1.3f
);
1441 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1442 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1443 SetupPendingTree(valid_pile
);
1445 scoped_ptr
<FakePictureLayerImpl
> mask_ptr
=
1446 FakePictureLayerImpl::CreateMaskWithRasterSource(
1447 host_impl_
.pending_tree(), 3, valid_pile
);
1448 mask_ptr
->SetBounds(layer_bounds
);
1449 mask_ptr
->SetDrawsContent(true);
1450 pending_layer_
->SetMaskLayer(mask_ptr
.Pass());
1451 pending_layer_
->SetHasRenderSurface(true);
1453 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1454 bool update_lcd_text
= false;
1455 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1457 FakePictureLayerImpl
* pending_mask
=
1458 static_cast<FakePictureLayerImpl
*>(pending_layer_
->mask_layer());
1460 // Masks are scaled, and do not have a low res tiling.
1461 EXPECT_EQ(1.3f
, pending_mask
->HighResTiling()->contents_scale());
1462 EXPECT_EQ(1u, pending_mask
->num_tilings());
1464 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1465 pending_mask
->HighResTiling()->AllTilesForTesting());
1469 FakePictureLayerImpl
* active_mask
=
1470 static_cast<FakePictureLayerImpl
*>(active_layer_
->mask_layer());
1472 // Mask layers have a tiling with a single tile in it.
1473 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1474 // The mask resource exists.
1475 ResourceId mask_resource_id
;
1476 gfx::Size mask_texture_size
;
1477 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1478 EXPECT_NE(0u, mask_resource_id
);
1479 gfx::Size expected_mask_texture_size
=
1480 gfx::ToCeiledSize(gfx::ScaleSize(active_mask
->bounds(), 1.3f
));
1481 EXPECT_EQ(mask_texture_size
, expected_mask_texture_size
);
1484 TEST_F(PictureLayerImplTest
, ReleaseResources
) {
1485 gfx::Size
tile_size(400, 400);
1486 gfx::Size
layer_bounds(1300, 1900);
1488 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1489 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1490 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1491 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1493 SetupTrees(pending_pile
, active_pile
);
1494 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1496 // All tilings should be removed when losing output surface.
1497 active_layer_
->ReleaseResources();
1498 EXPECT_FALSE(active_layer_
->tilings());
1499 active_layer_
->RecreateResources();
1500 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1501 pending_layer_
->ReleaseResources();
1502 EXPECT_FALSE(pending_layer_
->tilings());
1503 pending_layer_
->RecreateResources();
1504 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1506 // This should create new tilings.
1507 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
1508 1.f
, // ideal contents scale
1509 1.f
, // device scale
1511 1.f
, // maximum animation scale
1512 0.f
, // starting animation_scale
1514 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1517 TEST_F(PictureLayerImplTest
, ClampTilesToMaxTileSize
) {
1518 // The default max tile size is larger than 400x400.
1519 gfx::Size
tile_size(400, 400);
1520 gfx::Size
layer_bounds(5000, 5000);
1522 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1523 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1525 SetupPendingTree(pending_pile
);
1526 EXPECT_GE(pending_layer_
->tilings()->num_tilings(), 1u);
1528 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1530 // The default value.
1531 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1532 host_impl_
.settings().default_tile_size
.ToString());
1534 Tile
* tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1535 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1536 tile
->content_rect().size().ToString());
1538 ResetTilingsAndRasterScales();
1540 // Change the max texture size on the output surface context.
1541 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1542 TestWebGraphicsContext3D::Create();
1543 context
->set_max_texture_size(140);
1544 host_impl_
.DidLoseOutputSurface();
1545 host_impl_
.InitializeRenderer(
1546 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1548 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1550 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1552 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1554 // Verify the tiles are not larger than the context's max texture size.
1555 tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1556 EXPECT_GE(140, tile
->content_rect().width());
1557 EXPECT_GE(140, tile
->content_rect().height());
1560 TEST_F(PictureLayerImplTest
, ClampSingleTileToToMaxTileSize
) {
1561 // The default max tile size is larger than 400x400.
1562 gfx::Size
tile_size(400, 400);
1563 gfx::Size
layer_bounds(500, 500);
1565 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1566 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1567 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1568 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1570 SetupTrees(pending_pile
, active_pile
);
1571 EXPECT_GE(active_layer_
->tilings()->num_tilings(), 1u);
1573 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1575 // The default value. The layer is smaller than this.
1576 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1577 host_impl_
.settings().max_untiled_layer_size
.ToString());
1579 // There should be a single tile since the layer is small.
1580 PictureLayerTiling
* high_res_tiling
= active_layer_
->tilings()->tiling_at(0);
1581 EXPECT_EQ(1u, high_res_tiling
->AllTilesForTesting().size());
1583 ResetTilingsAndRasterScales();
1585 // Change the max texture size on the output surface context.
1586 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1587 TestWebGraphicsContext3D::Create();
1588 context
->set_max_texture_size(140);
1589 host_impl_
.DidLoseOutputSurface();
1590 host_impl_
.InitializeRenderer(
1591 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1593 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1595 ASSERT_LE(1u, active_layer_
->tilings()->num_tilings());
1597 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1599 // There should be more than one tile since the max texture size won't cover
1601 high_res_tiling
= active_layer_
->tilings()->tiling_at(0);
1602 EXPECT_LT(1u, high_res_tiling
->AllTilesForTesting().size());
1604 // Verify the tiles are not larger than the context's max texture size.
1605 Tile
* tile
= active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1606 EXPECT_GE(140, tile
->content_rect().width());
1607 EXPECT_GE(140, tile
->content_rect().height());
1610 TEST_F(PictureLayerImplTest
, DisallowTileDrawQuads
) {
1611 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1613 gfx::Size
tile_size(400, 400);
1614 gfx::Size
layer_bounds(1300, 1900);
1616 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1617 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1618 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1619 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1621 gfx::Rect
layer_invalidation(150, 200, 30, 180);
1622 SetupTreesWithInvalidation(pending_pile
, active_pile
, layer_invalidation
);
1624 active_layer_
->draw_properties().visible_layer_rect
= gfx::Rect(layer_bounds
);
1626 AppendQuadsData data
;
1627 active_layer_
->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE
, nullptr);
1628 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1629 active_layer_
->DidDraw(nullptr);
1631 ASSERT_EQ(1U, render_pass
->quad_list
.size());
1632 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
,
1633 render_pass
->quad_list
.front()->material
);
1636 TEST_F(PictureLayerImplTest
, SolidColorLayerHasVisibleFullCoverage
) {
1637 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1639 gfx::Size
tile_size(1000, 1000);
1640 gfx::Size
layer_bounds(1500, 1500);
1641 gfx::Rect
visible_rect(250, 250, 1000, 1000);
1643 scoped_ptr
<FakePicturePile
> empty_recording
=
1644 FakePicturePile::CreateEmptyPile(tile_size
, layer_bounds
);
1645 empty_recording
->SetIsSolidColor(true);
1647 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1648 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
1649 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1650 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
1652 SetupTrees(pending_pile
, active_pile
);
1654 active_layer_
->draw_properties().visible_layer_rect
= visible_rect
;
1656 AppendQuadsData data
;
1657 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1658 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1659 active_layer_
->DidDraw(nullptr);
1661 Region remaining
= visible_rect
;
1662 for (const auto& quad
: render_pass
->quad_list
) {
1663 EXPECT_TRUE(visible_rect
.Contains(quad
->rect
));
1664 EXPECT_TRUE(remaining
.Contains(quad
->rect
));
1665 remaining
.Subtract(quad
->rect
);
1668 EXPECT_TRUE(remaining
.IsEmpty());
1671 TEST_F(PictureLayerImplTest
, TileScalesWithSolidColorPile
) {
1672 gfx::Size
layer_bounds(200, 200);
1673 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1674 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1675 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1676 tile_size
, layer_bounds
, false);
1677 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1678 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1679 tile_size
, layer_bounds
, true);
1681 SetupTrees(pending_pile
, active_pile
);
1682 // Solid color pile should not allow tilings at any scale.
1683 EXPECT_FALSE(active_layer_
->CanHaveTilings());
1684 EXPECT_EQ(0.f
, active_layer_
->ideal_contents_scale());
1686 // Activate non-solid-color pending pile makes active layer can have tilings.
1688 EXPECT_TRUE(active_layer_
->CanHaveTilings());
1689 EXPECT_GT(active_layer_
->ideal_contents_scale(), 0.f
);
1692 TEST_F(NoLowResPictureLayerImplTest
, MarkRequiredOffscreenTiles
) {
1693 gfx::Size
tile_size(100, 100);
1694 gfx::Size
layer_bounds(200, 200);
1696 gfx::Transform transform
;
1697 gfx::Transform transform_for_tile_priority
;
1698 bool resourceless_software_draw
= false;
1699 gfx::Rect
viewport(0, 0, 100, 200);
1700 host_impl_
.SetExternalDrawConstraints(transform
,
1705 resourceless_software_draw
);
1707 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1708 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1709 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1711 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1712 EXPECT_EQ(viewport
, pending_layer_
->visible_rect_for_tile_priority());
1714 base::TimeTicks time_ticks
;
1715 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1716 pending_layer_
->UpdateTiles(resourceless_software_draw
);
1718 int num_visible
= 0;
1719 int num_offscreen
= 0;
1721 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
1722 pending_layer_
->picture_layer_tiling_set(), false));
1723 for (; !queue
->IsEmpty(); queue
->Pop()) {
1724 const PrioritizedTile
& prioritized_tile
= queue
->Top();
1725 DCHECK(prioritized_tile
.tile());
1726 if (prioritized_tile
.priority().distance_to_visible
== 0.f
) {
1727 EXPECT_TRUE(prioritized_tile
.tile()->required_for_activation());
1730 EXPECT_FALSE(prioritized_tile
.tile()->required_for_activation());
1735 EXPECT_GT(num_visible
, 0);
1736 EXPECT_GT(num_offscreen
, 0);
1739 TEST_F(NoLowResPictureLayerImplTest
,
1740 TileOutsideOfViewportForTilePriorityNotRequired
) {
1741 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1743 gfx::Size
tile_size(100, 100);
1744 gfx::Size
layer_bounds(400, 400);
1745 gfx::Rect
external_viewport_for_tile_priority(400, 200);
1746 gfx::Rect
visible_layer_rect(200, 400);
1748 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1749 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1750 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1751 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1752 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
1754 ASSERT_EQ(1u, pending_layer_
->num_tilings());
1755 ASSERT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
1757 // Set external viewport for tile priority.
1758 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
1759 gfx::Transform transform
;
1760 gfx::Transform transform_for_tile_priority
;
1761 bool resourceless_software_draw
= false;
1762 host_impl_
.SetExternalDrawConstraints(transform
,
1765 external_viewport_for_tile_priority
,
1766 transform_for_tile_priority
,
1767 resourceless_software_draw
);
1768 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1769 bool update_lcd_text
= false;
1770 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1772 // Set visible content rect that is different from
1773 // external_viewport_for_tile_priority.
1774 pending_layer_
->draw_properties().visible_layer_rect
= visible_layer_rect
;
1775 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
1776 pending_layer_
->UpdateTiles(resourceless_software_draw
);
1778 // Intersect the two rects. Any tile outside should not be required for
1780 gfx::Rect viewport_for_tile_priority
=
1781 pending_layer_
->viewport_rect_for_tile_priority_in_content_space();
1782 viewport_for_tile_priority
.Intersect(pending_layer_
->visible_layer_rect());
1784 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
1787 int num_outside
= 0;
1788 for (PictureLayerTiling::CoverageIterator
iter(active_layer_
->HighResTiling(),
1789 1.f
, gfx::Rect(layer_bounds
));
1794 if (viewport_for_tile_priority
.Intersects(iter
.geometry_rect())) {
1796 // Mark everything in viewport for tile priority as ready to draw.
1797 TileDrawInfo
& draw_info
= tile
->draw_info();
1798 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
1801 EXPECT_FALSE(tile
->required_for_activation());
1805 EXPECT_GT(num_inside
, 0);
1806 EXPECT_GT(num_outside
, 0);
1808 // Activate and draw active layer.
1809 host_impl_
.ActivateSyncTree();
1810 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
1811 active_layer_
->draw_properties().visible_layer_rect
= visible_layer_rect
;
1813 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1814 AppendQuadsData data
;
1815 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1816 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1817 active_layer_
->DidDraw(nullptr);
1819 // All tiles in activation rect is ready to draw.
1820 EXPECT_EQ(0u, data
.num_missing_tiles
);
1821 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1822 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1825 TEST_F(PictureLayerImplTest
, HighResTileIsComplete
) {
1826 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1828 gfx::Size
tile_size(100, 100);
1829 gfx::Size
layer_bounds(200, 200);
1831 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1832 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1834 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1837 // All high res tiles have resources.
1838 std::vector
<Tile
*> tiles
=
1839 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1840 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
1842 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1843 AppendQuadsData data
;
1844 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1845 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1846 active_layer_
->DidDraw(nullptr);
1848 // All high res tiles drew, nothing was incomplete.
1849 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1850 EXPECT_EQ(0u, data
.num_missing_tiles
);
1851 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1852 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1855 TEST_F(PictureLayerImplTest
, HighResTileIsIncomplete
) {
1856 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1858 gfx::Size
tile_size(100, 100);
1859 gfx::Size
layer_bounds(200, 200);
1861 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1862 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1863 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1866 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1867 AppendQuadsData data
;
1868 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1869 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1870 active_layer_
->DidDraw(nullptr);
1872 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1873 EXPECT_EQ(1u, data
.num_missing_tiles
);
1874 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1875 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1878 TEST_F(PictureLayerImplTest
, HighResTileIsIncompleteLowResComplete
) {
1879 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1881 gfx::Size
tile_size(100, 100);
1882 gfx::Size
layer_bounds(200, 200);
1884 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1885 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1886 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1889 std::vector
<Tile
*> low_tiles
=
1890 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1891 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1893 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1894 AppendQuadsData data
;
1895 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1896 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1897 active_layer_
->DidDraw(nullptr);
1899 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1900 EXPECT_EQ(0u, data
.num_missing_tiles
);
1901 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1902 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1905 TEST_F(PictureLayerImplTest
, LowResTileIsIncomplete
) {
1906 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1908 gfx::Size
tile_size(100, 100);
1909 gfx::Size
layer_bounds(200, 200);
1911 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1912 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1913 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1916 // All high res tiles have resources except one.
1917 std::vector
<Tile
*> high_tiles
=
1918 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1919 high_tiles
.erase(high_tiles
.begin());
1920 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
1922 // All low res tiles have resources.
1923 std::vector
<Tile
*> low_tiles
=
1924 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1925 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1927 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1928 AppendQuadsData data
;
1929 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1930 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1931 active_layer_
->DidDraw(nullptr);
1933 // The missing high res tile was replaced by a low res tile.
1934 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1935 EXPECT_EQ(0u, data
.num_missing_tiles
);
1936 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1937 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1940 TEST_F(PictureLayerImplTest
,
1941 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal
) {
1942 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1944 gfx::Size
tile_size(100, 100);
1945 gfx::Size
layer_bounds(200, 200);
1946 gfx::Size
viewport_size(400, 400);
1948 host_impl_
.SetViewportSize(viewport_size
);
1949 host_impl_
.SetDeviceScaleFactor(2.f
);
1951 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1952 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1953 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1954 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1955 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
1957 // One ideal tile exists, this will get used when drawing.
1958 std::vector
<Tile
*> ideal_tiles
;
1959 EXPECT_EQ(2.f
, active_layer_
->HighResTiling()->contents_scale());
1960 ideal_tiles
.push_back(active_layer_
->HighResTiling()->TileAt(0, 0));
1961 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1964 // Due to layer scale throttling, the raster contents scale is changed to 1,
1965 // while the ideal is still 2.
1966 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1968 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1971 EXPECT_EQ(1.f
, active_layer_
->HighResTiling()->contents_scale());
1972 EXPECT_EQ(1.f
, active_layer_
->raster_contents_scale());
1973 EXPECT_EQ(2.f
, active_layer_
->ideal_contents_scale());
1975 // Both tilings still exist.
1976 EXPECT_EQ(2.f
, active_layer_
->tilings()->tiling_at(0)->contents_scale());
1977 EXPECT_EQ(1.f
, active_layer_
->tilings()->tiling_at(1)->contents_scale());
1979 // All high res tiles have resources.
1980 std::vector
<Tile
*> high_tiles
=
1981 active_layer_
->HighResTiling()->AllTilesForTesting();
1982 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
1984 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1985 AppendQuadsData data
;
1986 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1987 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1988 active_layer_
->DidDraw(nullptr);
1990 // All high res tiles drew, and the one ideal res tile drew.
1991 ASSERT_GT(render_pass
->quad_list
.size(), 9u);
1992 EXPECT_EQ(gfx::SizeF(99.f
, 99.f
),
1993 TileDrawQuad::MaterialCast(render_pass
->quad_list
.front())
1994 ->tex_coord_rect
.size());
1995 EXPECT_EQ(gfx::SizeF(49.5f
, 49.5f
),
1996 TileDrawQuad::MaterialCast(render_pass
->quad_list
.ElementAt(1))
1997 ->tex_coord_rect
.size());
1999 // Neither the high res nor the ideal tiles were considered as incomplete.
2000 EXPECT_EQ(0u, data
.num_missing_tiles
);
2001 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
2002 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
2005 TEST_F(PictureLayerImplTest
, HighResRequiredWhenActiveAllReady
) {
2006 gfx::Size
layer_bounds(400, 400);
2007 gfx::Size
tile_size(100, 100);
2009 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
,
2010 gfx::Rect(layer_bounds
));
2012 active_layer_
->SetAllTilesReady();
2014 // All active tiles ready, so pending can only activate with all high res
2016 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2017 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2019 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2020 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2023 TEST_F(PictureLayerImplTest
, HighResRequiredWhenMissingHighResFlagOn
) {
2024 gfx::Size
layer_bounds(400, 400);
2025 gfx::Size
tile_size(100, 100);
2028 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2030 // Verify active tree not ready.
2031 Tile
* some_active_tile
=
2032 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2033 EXPECT_FALSE(some_active_tile
->draw_info().IsReadyToDraw());
2035 // When high res are required, all tiles in active high res tiling should be
2036 // required for activation.
2037 host_impl_
.SetRequiresHighResToDraw();
2039 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2040 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2041 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2042 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2044 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
2045 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2046 AssertAllTilesRequired(active_layer_
->HighResTiling());
2047 AssertNoTilesRequired(active_layer_
->LowResTiling());
2050 TEST_F(PictureLayerImplTest
, AllHighResRequiredEvenIfNotChanged
) {
2051 gfx::Size
layer_bounds(400, 400);
2052 gfx::Size
tile_size(100, 100);
2054 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2056 Tile
* some_active_tile
=
2057 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2058 EXPECT_FALSE(some_active_tile
->draw_info().IsReadyToDraw());
2060 // Since there are no invalidations, pending tree should have no tiles.
2061 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
2062 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2064 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2065 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2067 AssertAllTilesRequired(active_layer_
->HighResTiling());
2068 AssertNoTilesRequired(active_layer_
->LowResTiling());
2071 TEST_F(PictureLayerImplTest
, DisallowRequiredForActivation
) {
2072 gfx::Size
layer_bounds(400, 400);
2073 gfx::Size
tile_size(100, 100);
2075 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2077 Tile
* some_active_tile
=
2078 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2079 EXPECT_FALSE(some_active_tile
->draw_info().IsReadyToDraw());
2081 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
2082 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2083 active_layer_
->HighResTiling()->set_can_require_tiles_for_activation(false);
2084 active_layer_
->LowResTiling()->set_can_require_tiles_for_activation(false);
2085 pending_layer_
->HighResTiling()->set_can_require_tiles_for_activation(false);
2086 pending_layer_
->LowResTiling()->set_can_require_tiles_for_activation(false);
2088 // If we disallow required for activation, no tiles can be required.
2089 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2090 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2092 AssertNoTilesRequired(active_layer_
->HighResTiling());
2093 AssertNoTilesRequired(active_layer_
->LowResTiling());
2096 TEST_F(PictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
2097 gfx::Size
layer_bounds(400, 400);
2098 gfx::Size
tile_size(100, 100);
2100 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2101 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2102 // This pile will create tilings, but has no recordings so will not create any
2103 // tiles. This is attempting to simulate scrolling past the end of recorded
2104 // content on the active layer, where the recordings are so far away that
2105 // no tiles are created.
2106 bool is_solid_color
= false;
2107 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2108 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
2109 tile_size
, layer_bounds
, is_solid_color
);
2111 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2113 // Active layer has tilings, but no tiles due to missing recordings.
2114 EXPECT_TRUE(active_layer_
->CanHaveTilings());
2115 EXPECT_EQ(active_layer_
->tilings()->num_tilings(), 2u);
2116 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
2118 // Since the active layer has no tiles at all, the pending layer doesn't
2119 // need content in order to activate.
2120 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2121 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2123 AssertNoTilesRequired(pending_layer_
->HighResTiling());
2124 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2127 TEST_F(PictureLayerImplTest
, HighResRequiredIfActiveCantHaveTiles
) {
2128 gfx::Size
layer_bounds(400, 400);
2129 gfx::Size
tile_size(100, 100);
2131 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2132 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2133 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2134 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
2135 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2137 // Active layer can't have tiles.
2138 EXPECT_FALSE(active_layer_
->CanHaveTilings());
2140 // All high res tiles required. This should be considered identical
2141 // to the case where there is no active layer, to avoid flashing content.
2142 // This can happen if a layer exists for a while and switches from
2143 // not being able to have content to having content.
2144 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2145 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2147 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2148 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2151 TEST_F(PictureLayerImplTest
, HighResRequiredWhenActiveHasDifferentBounds
) {
2152 gfx::Size
pending_layer_bounds(400, 400);
2153 gfx::Size
active_layer_bounds(200, 200);
2154 gfx::Size
tile_size(100, 100);
2156 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2157 FakePicturePileImpl::CreateFilledPile(tile_size
, pending_layer_bounds
);
2158 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2159 FakePicturePileImpl::CreateFilledPile(tile_size
, active_layer_bounds
);
2161 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2163 // Since the active layer has different bounds, the pending layer needs all
2164 // high res tiles in order to activate.
2165 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2166 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2167 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2168 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2170 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2171 AssertAllTilesRequired(active_layer_
->HighResTiling());
2172 AssertNoTilesRequired(active_layer_
->LowResTiling());
2173 // Since the test doesn't invalidate the resized region, we expect that the
2174 // same low res tile would exist (which means we don't create a new one of the
2176 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2179 TEST_F(PictureLayerImplTest
, ActivateUninitializedLayer
) {
2180 gfx::Size
tile_size(100, 100);
2181 gfx::Size
layer_bounds(400, 400);
2182 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2183 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2185 host_impl_
.CreatePendingTree();
2186 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
2188 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
2189 FakePictureLayerImpl::CreateWithRasterSource(pending_tree
, id_
,
2191 pending_layer
->SetDrawsContent(true);
2192 pending_tree
->SetRootLayer(pending_layer
.Pass());
2194 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
2195 host_impl_
.pending_tree()->LayerById(id_
));
2197 // Set some state on the pending layer, make sure it is not clobbered
2198 // by a sync from the active layer. This could happen because if the
2199 // pending layer has not been post-commit initialized it will attempt
2200 // to sync from the active layer.
2201 float raster_page_scale
= 10.f
* pending_layer_
->raster_page_scale();
2202 pending_layer_
->set_raster_page_scale(raster_page_scale
);
2204 host_impl_
.ActivateSyncTree();
2206 active_layer_
= static_cast<FakePictureLayerImpl
*>(
2207 host_impl_
.active_tree()->LayerById(id_
));
2209 EXPECT_EQ(0u, active_layer_
->num_tilings());
2210 EXPECT_EQ(raster_page_scale
, active_layer_
->raster_page_scale());
2213 TEST_F(PictureLayerImplTest
, ShareTilesOnNextFrame
) {
2214 gfx::Size
layer_bounds(1500, 1500);
2215 gfx::Size
tile_size(100, 100);
2217 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2218 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2220 SetupPendingTree(pending_pile
);
2222 PictureLayerTiling
* tiling
= pending_layer_
->HighResTiling();
2223 gfx::Rect first_invalidate
= tiling
->TilingDataForTesting().TileBounds(0, 0);
2224 first_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2225 tiling
->TilingDataForTesting().border_texels());
2226 gfx::Rect second_invalidate
= tiling
->TilingDataForTesting().TileBounds(1, 1);
2227 second_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2228 tiling
->TilingDataForTesting().border_texels());
2232 // Make a pending tree with an invalidated raster tile 0,0.
2233 SetupPendingTreeWithInvalidation(pending_pile
, first_invalidate
);
2235 // Activate and make a pending tree with an invalidated raster tile 1,1.
2238 SetupPendingTreeWithInvalidation(pending_pile
, second_invalidate
);
2240 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2241 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2243 // pending_tiling->CreateAllTilesForTesting();
2245 // Tile 0,0 not exist on pending, but tile 1,1 should.
2246 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2247 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2248 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2249 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2250 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2251 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2252 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2253 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2254 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2256 // Drop the tiles on the active tree and recreate them.
2257 active_tiling
->ComputeTilePriorityRects(gfx::Rect(), 1.f
, 1.0, Occlusion());
2258 EXPECT_TRUE(active_tiling
->AllTilesForTesting().empty());
2259 active_tiling
->CreateAllTilesForTesting();
2261 // Tile 0,0 not exist on pending, but tile 1,1 should.
2262 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2263 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2264 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2265 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2266 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2267 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2268 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2269 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2270 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2273 TEST_F(PictureLayerImplTest
, PendingHasNoTilesWithNoInvalidation
) {
2274 SetupDefaultTrees(gfx::Size(1500, 1500));
2276 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2277 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2280 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2281 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2282 ASSERT_TRUE(active_tiling
);
2283 ASSERT_TRUE(pending_tiling
);
2285 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2286 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2287 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2288 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2290 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2291 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2292 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2293 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
2296 TEST_F(PictureLayerImplTest
, ShareInvalidActiveTreeTiles
) {
2297 gfx::Size
tile_size(100, 100);
2298 gfx::Size
layer_bounds(1500, 1500);
2300 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2301 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2302 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2303 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2304 SetupTreesWithInvalidation(pending_pile
, active_pile
, gfx::Rect(1, 1));
2305 // Activate the invalidation.
2307 // Make another pending tree without any invalidation in it.
2308 scoped_refptr
<FakePicturePileImpl
> pending_pile2
=
2309 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2310 SetupPendingTree(pending_pile2
);
2312 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2313 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2315 // The active tree invalidation was handled by the active tiles.
2316 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2317 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2318 ASSERT_TRUE(active_tiling
);
2319 ASSERT_TRUE(pending_tiling
);
2321 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2322 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2323 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2324 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2326 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2327 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2328 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2329 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
2332 TEST_F(PictureLayerImplTest
, RecreateInvalidPendingTreeTiles
) {
2333 // Set some invalidation on the pending tree. We should replace raster tiles
2335 SetupDefaultTreesWithInvalidation(gfx::Size(1500, 1500), gfx::Rect(1, 1));
2337 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2338 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2340 // The pending tree invalidation creates tiles on the pending tree.
2341 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2342 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2343 ASSERT_TRUE(active_tiling
);
2344 ASSERT_TRUE(pending_tiling
);
2346 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2347 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2348 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2349 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2351 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2352 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2353 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2354 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
2356 EXPECT_NE(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2359 TEST_F(PictureLayerImplTest
, SyncTilingAfterGpuRasterizationToggles
) {
2360 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2362 gfx::Size
tile_size(100, 100);
2363 gfx::Size
layer_bounds(10, 10);
2365 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2366 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2367 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2368 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2370 SetupTrees(pending_pile
, active_pile
);
2372 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2373 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(1.f
));
2375 // Gpu rasterization is disabled by default.
2376 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2377 // Toggling the gpu rasterization clears all tilings on both trees.
2378 host_impl_
.SetHasGpuRasterizationTrigger(true);
2379 host_impl_
.SetContentIsSuitableForGpuRasterization(true);
2380 host_impl_
.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2381 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2382 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2384 // Make sure that we can still add tiling to the pending layer,
2385 // that gets synced to the active layer.
2386 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2387 bool update_lcd_text
= false;
2388 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
2389 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2392 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(1.f
));
2394 SetupPendingTree(pending_pile
);
2395 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2397 // Toggling the gpu rasterization clears all tilings on both trees.
2398 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2399 host_impl_
.SetHasGpuRasterizationTrigger(false);
2400 host_impl_
.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2401 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT
,
2402 host_impl_
.gpu_rasterization_status());
2403 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2404 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2406 host_impl_
.SetHasGpuRasterizationTrigger(true);
2407 host_impl_
.SetContentIsSuitableForGpuRasterization(false);
2408 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT
,
2409 host_impl_
.gpu_rasterization_status());
2412 TEST_F(PictureLayerImplTest
, HighResCreatedWhenBoundsShrink
) {
2413 gfx::Size
tile_size(100, 100);
2415 // Put 0.5 as high res.
2416 host_impl_
.SetDeviceScaleFactor(0.5f
);
2418 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2419 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(10, 10));
2420 SetupPendingTree(pending_pile
);
2423 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2424 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(0.5f
));
2428 // Now, set the bounds to be 1x1, so that minimum contents scale becomes 1.
2430 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(1, 1));
2431 SetupPendingTree(pending_pile
);
2433 // Another sanity check.
2434 EXPECT_EQ(1.f
, pending_layer_
->MinimumContentsScale());
2436 // Since the MinContentsScale is 1, the 0.5 tiling should be replaced by a 1.0
2438 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 0.5f
, 1.f
, 1.f
, 1.f
, 0.f
,
2441 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2442 PictureLayerTiling
* tiling
=
2443 pending_layer_
->tilings()->FindTilingWithScale(1.0f
);
2444 ASSERT_TRUE(tiling
);
2445 EXPECT_EQ(HIGH_RESOLUTION
, tiling
->resolution());
2448 TEST_F(PictureLayerImplTest
, LowResTilingWithoutGpuRasterization
) {
2449 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
2450 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
2451 default_tile_size
.height() * 4);
2453 host_impl_
.SetHasGpuRasterizationTrigger(false);
2455 SetupDefaultTrees(layer_bounds
);
2456 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2457 // Should have a low-res and a high-res tiling.
2458 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
2461 TEST_F(PictureLayerImplTest
, NoLowResTilingWithGpuRasterization
) {
2462 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
2463 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
2464 default_tile_size
.height() * 4);
2466 host_impl_
.SetHasGpuRasterizationTrigger(true);
2467 host_impl_
.SetContentIsSuitableForGpuRasterization(true);
2469 SetupDefaultTrees(layer_bounds
);
2470 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2471 // Should only have the high-res tiling.
2472 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2475 TEST_F(PictureLayerImplTest
, RequiredTilesWithGpuRasterization
) {
2476 host_impl_
.SetHasGpuRasterizationTrigger(true);
2477 host_impl_
.SetContentIsSuitableForGpuRasterization(true);
2479 gfx::Size
viewport_size(1000, 1000);
2480 host_impl_
.SetViewportSize(viewport_size
);
2482 gfx::Size
layer_bounds(4000, 4000);
2483 SetupDefaultTrees(layer_bounds
);
2484 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2486 // Should only have the high-res tiling.
2487 EXPECT_EQ(1u, active_layer_
->tilings()->num_tilings());
2489 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2491 // High res tiling should have 36 tiles (3X12 tile grid).
2492 EXPECT_EQ(36u, active_layer_
->HighResTiling()->AllTilesForTesting().size());
2494 // Visible viewport should be covered by 4 tiles. No other
2495 // tiles should be required for activation.
2496 EXPECT_EQ(4u, NumberOfTilesRequired(active_layer_
->HighResTiling()));
2499 TEST_F(PictureLayerImplTest
, NoTilingIfDoesNotDrawContent
) {
2500 // Set up layers with tilings.
2501 SetupDefaultTrees(gfx::Size(10, 10));
2502 SetContentsScaleOnBothLayers(1.f
, 1.f
, 1.f
, 1.f
, 0.f
, false);
2503 pending_layer_
->PushPropertiesTo(active_layer_
);
2504 EXPECT_TRUE(pending_layer_
->DrawsContent());
2505 EXPECT_TRUE(pending_layer_
->CanHaveTilings());
2506 EXPECT_GE(pending_layer_
->num_tilings(), 0u);
2507 EXPECT_GE(active_layer_
->num_tilings(), 0u);
2509 // Set content to false, which should make CanHaveTilings return false.
2510 pending_layer_
->SetDrawsContent(false);
2511 EXPECT_FALSE(pending_layer_
->DrawsContent());
2512 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
2514 // No tilings should be pushed to active layer.
2515 pending_layer_
->PushPropertiesTo(active_layer_
);
2516 EXPECT_EQ(0u, active_layer_
->num_tilings());
2519 TEST_F(PictureLayerImplTest
, FirstTilingDuringPinch
) {
2520 SetupDefaultTrees(gfx::Size(10, 10));
2522 // We start with a tiling at scale 1.
2523 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
2525 // When we scale up by 2.3, we get a new tiling that is a power of 2, in this
2527 host_impl_
.PinchGestureBegin();
2528 float high_res_scale
= 2.3f
;
2529 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, 1.f
, 1.f
, 0.f
, false);
2530 EXPECT_EQ(4.f
, pending_layer_
->HighResTiling()->contents_scale());
2533 TEST_F(PictureLayerImplTest
, PinchingTooSmall
) {
2534 SetupDefaultTrees(gfx::Size(10, 10));
2536 // We start with a tiling at scale 1.
2537 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
2539 host_impl_
.PinchGestureBegin();
2540 float high_res_scale
= 0.0001f
;
2541 EXPECT_LT(high_res_scale
, pending_layer_
->MinimumContentsScale());
2543 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, high_res_scale
, 1.f
, 0.f
,
2545 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2546 pending_layer_
->HighResTiling()->contents_scale());
2549 TEST_F(PictureLayerImplTest
, PinchingTooSmallWithContentsScale
) {
2550 SetupDefaultTrees(gfx::Size(10, 10));
2552 ResetTilingsAndRasterScales();
2554 float contents_scale
= 0.15f
;
2555 SetContentsScaleOnBothLayers(contents_scale
, 1.f
, 1.f
, 1.f
, 0.f
, false);
2557 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2558 EXPECT_FLOAT_EQ(contents_scale
,
2559 pending_layer_
->HighResTiling()->contents_scale());
2561 host_impl_
.PinchGestureBegin();
2563 float page_scale
= 0.0001f
;
2564 EXPECT_LT(page_scale
* contents_scale
,
2565 pending_layer_
->MinimumContentsScale());
2567 SetContentsScaleOnBothLayers(contents_scale
* page_scale
, 1.f
, page_scale
,
2569 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2570 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2571 pending_layer_
->HighResTiling()->contents_scale());
2574 TEST_F(PictureLayerImplTest
, ConsiderAnimationStartScaleForRasterScale
) {
2575 gfx::Size
viewport_size(1000, 1000);
2576 host_impl_
.SetViewportSize(viewport_size
);
2578 gfx::Size
layer_bounds(100, 100);
2579 SetupDefaultTrees(layer_bounds
);
2581 float contents_scale
= 2.f
;
2582 float device_scale
= 1.f
;
2583 float page_scale
= 1.f
;
2584 float maximum_animation_scale
= 3.f
;
2585 float starting_animation_scale
= 1.f
;
2586 bool animating_transform
= true;
2588 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2590 // Maximum animation scale is greater than starting animation scale
2591 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2592 maximum_animation_scale
,
2593 starting_animation_scale
, animating_transform
);
2594 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2596 animating_transform
= false;
2598 // Once we stop animating, a new high-res tiling should be created.
2599 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2600 maximum_animation_scale
,
2601 starting_animation_scale
, animating_transform
);
2602 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2604 // Starting animation scale greater than maximum animation scale
2605 // Bounds at starting scale within the viewport
2606 animating_transform
= true;
2607 starting_animation_scale
= 5.f
;
2609 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2610 maximum_animation_scale
,
2611 starting_animation_scale
, animating_transform
);
2612 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 5.f
);
2614 // Once we stop animating, a new high-res tiling should be created.
2615 animating_transform
= false;
2616 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2617 maximum_animation_scale
,
2618 starting_animation_scale
, animating_transform
);
2619 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2621 // Starting Animation scale greater than maximum animation scale
2622 // Bounds at starting scale outisde the viewport
2623 animating_transform
= true;
2624 starting_animation_scale
= 11.f
;
2626 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2627 maximum_animation_scale
,
2628 starting_animation_scale
, animating_transform
);
2629 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2632 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForCpuRasterization
) {
2633 gfx::Size
viewport_size(1000, 1000);
2634 host_impl_
.SetViewportSize(viewport_size
);
2636 gfx::Size
layer_bounds(100, 100);
2637 SetupDefaultTrees(layer_bounds
);
2639 float contents_scale
= 1.f
;
2640 float device_scale
= 1.f
;
2641 float page_scale
= 1.f
;
2642 float maximum_animation_scale
= 1.f
;
2643 float starting_animation_scale
= 0.f
;
2644 bool animating_transform
= false;
2646 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2648 // Since we're CPU-rasterizing, starting an animation should cause tiling
2649 // resolution to get set to the maximum animation scale factor.
2650 animating_transform
= true;
2651 maximum_animation_scale
= 3.f
;
2652 contents_scale
= 2.f
;
2654 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2655 maximum_animation_scale
,
2656 starting_animation_scale
, animating_transform
);
2657 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2659 // Further changes to scale during the animation should not cause a new
2660 // high-res tiling to get created.
2661 contents_scale
= 4.f
;
2662 maximum_animation_scale
= 5.f
;
2664 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2665 maximum_animation_scale
,
2666 starting_animation_scale
, animating_transform
);
2667 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2669 // Once we stop animating, a new high-res tiling should be created.
2670 animating_transform
= false;
2672 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2673 maximum_animation_scale
,
2674 starting_animation_scale
, animating_transform
);
2675 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2677 // When animating with an unknown maximum animation scale factor, a new
2678 // high-res tiling should be created at a source scale of 1.
2679 animating_transform
= true;
2680 contents_scale
= 2.f
;
2681 maximum_animation_scale
= 0.f
;
2683 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2684 maximum_animation_scale
,
2685 starting_animation_scale
, animating_transform
);
2686 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2688 // Further changes to scale during the animation should not cause a new
2689 // high-res tiling to get created.
2690 contents_scale
= 3.f
;
2692 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2693 maximum_animation_scale
,
2694 starting_animation_scale
, animating_transform
);
2695 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2697 // Once we stop animating, a new high-res tiling should be created.
2698 animating_transform
= false;
2699 contents_scale
= 4.f
;
2701 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2702 maximum_animation_scale
,
2703 starting_animation_scale
, animating_transform
);
2704 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2706 // When animating with a maxmium animation scale factor that is so large
2707 // that the layer grows larger than the viewport at this scale, a new
2708 // high-res tiling should get created at a source scale of 1, not at its
2710 animating_transform
= true;
2711 contents_scale
= 2.f
;
2712 maximum_animation_scale
= 11.f
;
2714 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2715 maximum_animation_scale
,
2716 starting_animation_scale
, animating_transform
);
2717 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2719 // Once we stop animating, a new high-res tiling should be created.
2720 animating_transform
= false;
2721 contents_scale
= 11.f
;
2723 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2724 maximum_animation_scale
,
2725 starting_animation_scale
, animating_transform
);
2726 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2728 // When animating with a maxmium animation scale factor that is so large
2729 // that the layer grows larger than the viewport at this scale, and where
2730 // the intial source scale is < 1, a new high-res tiling should get created
2731 // at source scale 1.
2732 animating_transform
= true;
2733 contents_scale
= 0.1f
;
2734 maximum_animation_scale
= 11.f
;
2736 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2737 maximum_animation_scale
,
2738 starting_animation_scale
, animating_transform
);
2739 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2741 // Once we stop animating, a new high-res tiling should be created.
2742 animating_transform
= false;
2743 contents_scale
= 12.f
;
2745 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2746 maximum_animation_scale
,
2747 starting_animation_scale
, animating_transform
);
2748 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 12.f
);
2750 // When animating toward a smaller scale, but that is still so large that the
2751 // layer grows larger than the viewport at this scale, a new high-res tiling
2752 // should get created at source scale 1.
2753 animating_transform
= true;
2754 contents_scale
= 11.f
;
2755 maximum_animation_scale
= 11.f
;
2757 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2758 maximum_animation_scale
,
2759 starting_animation_scale
, animating_transform
);
2760 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2762 // Once we stop animating, a new high-res tiling should be created.
2763 animating_transform
= false;
2764 contents_scale
= 11.f
;
2766 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2767 maximum_animation_scale
,
2768 starting_animation_scale
, animating_transform
);
2769 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2772 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForGpuRasterization
) {
2773 gfx::Size
layer_bounds(100, 100);
2774 gfx::Size
viewport_size(1000, 1000);
2775 SetupDefaultTrees(layer_bounds
);
2776 host_impl_
.SetViewportSize(viewport_size
);
2777 host_impl_
.SetHasGpuRasterizationTrigger(true);
2778 host_impl_
.SetContentIsSuitableForGpuRasterization(true);
2779 host_impl_
.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2781 float contents_scale
= 1.f
;
2782 float device_scale
= 1.3f
;
2783 float page_scale
= 1.4f
;
2784 float maximum_animation_scale
= 1.f
;
2785 float starting_animation_scale
= 0.f
;
2786 bool animating_transform
= false;
2788 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2789 maximum_animation_scale
,
2790 starting_animation_scale
, animating_transform
);
2791 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2793 // Since we're GPU-rasterizing, starting an animation should cause tiling
2794 // resolution to get set to the current contents scale.
2795 animating_transform
= true;
2796 contents_scale
= 2.f
;
2797 maximum_animation_scale
= 4.f
;
2799 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2800 maximum_animation_scale
,
2801 starting_animation_scale
, animating_transform
);
2802 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2804 // Further changes to scale during the animation should cause a new high-res
2805 // tiling to get created.
2806 contents_scale
= 3.f
;
2808 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2809 maximum_animation_scale
,
2810 starting_animation_scale
, animating_transform
);
2811 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2813 // Since we're re-rasterizing during the animation, scales smaller than 1
2814 // should be respected.
2815 contents_scale
= 0.25f
;
2817 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2818 maximum_animation_scale
,
2819 starting_animation_scale
, animating_transform
);
2820 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.25f
);
2822 // Once we stop animating, a new high-res tiling should be created.
2823 contents_scale
= 4.f
;
2824 animating_transform
= false;
2826 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2827 maximum_animation_scale
,
2828 starting_animation_scale
, animating_transform
);
2829 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2832 TEST_F(PictureLayerImplTest
, TilingSetRasterQueue
) {
2833 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2835 host_impl_
.SetViewportSize(gfx::Size(500, 500));
2837 gfx::Size
recording_tile_size(100, 100);
2838 gfx::Size
layer_bounds(1000, 1000);
2840 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2841 FakePicturePileImpl::CreateFilledPile(recording_tile_size
, layer_bounds
);
2843 SetupPendingTree(pending_pile
);
2844 EXPECT_EQ(2u, pending_layer_
->num_tilings());
2846 std::set
<Tile
*> unique_tiles
;
2847 bool reached_prepaint
= false;
2848 int non_ideal_tile_count
= 0u;
2849 int low_res_tile_count
= 0u;
2850 int high_res_tile_count
= 0u;
2851 int high_res_now_tiles
= 0u;
2852 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
2853 pending_layer_
->picture_layer_tiling_set(), false));
2854 while (!queue
->IsEmpty()) {
2855 PrioritizedTile prioritized_tile
= queue
->Top();
2856 TilePriority priority
= prioritized_tile
.priority();
2858 EXPECT_TRUE(prioritized_tile
.tile());
2860 // Non-high res tiles only get visible tiles. Also, prepaint should only
2861 // come at the end of the iteration.
2862 if (priority
.resolution
!= HIGH_RESOLUTION
) {
2863 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
2864 } else if (reached_prepaint
) {
2865 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
2867 reached_prepaint
= priority
.priority_bin
!= TilePriority::NOW
;
2868 if (!reached_prepaint
)
2869 ++high_res_now_tiles
;
2872 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
2873 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
2874 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2876 unique_tiles
.insert(prioritized_tile
.tile());
2880 EXPECT_TRUE(reached_prepaint
);
2881 EXPECT_EQ(0, non_ideal_tile_count
);
2882 EXPECT_EQ(0, low_res_tile_count
);
2884 // With layer size being 1000x1000 and default tile size 256x256, we expect to
2885 // see 4 now tiles out of 16 total high res tiles.
2886 EXPECT_EQ(16, high_res_tile_count
);
2887 EXPECT_EQ(4, high_res_now_tiles
);
2888 EXPECT_EQ(low_res_tile_count
+ high_res_tile_count
+ non_ideal_tile_count
,
2889 static_cast<int>(unique_tiles
.size()));
2891 scoped_ptr
<TilingSetRasterQueueRequired
> required_queue(
2892 new TilingSetRasterQueueRequired(
2893 pending_layer_
->picture_layer_tiling_set(),
2894 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
));
2895 EXPECT_TRUE(required_queue
->IsEmpty());
2897 required_queue
.reset(new TilingSetRasterQueueRequired(
2898 pending_layer_
->picture_layer_tiling_set(),
2899 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
2900 EXPECT_FALSE(required_queue
->IsEmpty());
2901 int required_for_activation_count
= 0;
2902 while (!required_queue
->IsEmpty()) {
2903 PrioritizedTile prioritized_tile
= required_queue
->Top();
2904 EXPECT_TRUE(prioritized_tile
.tile()->required_for_activation());
2905 EXPECT_FALSE(prioritized_tile
.tile()->draw_info().IsReadyToDraw());
2906 ++required_for_activation_count
;
2907 required_queue
->Pop();
2910 // All of the high res tiles should be required for activation, since there is
2912 EXPECT_EQ(high_res_now_tiles
, required_for_activation_count
);
2915 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
2917 pending_layer_
->draw_properties().visible_layer_rect
=
2918 gfx::Rect(1100, 1100, 500, 500);
2919 bool resourceless_software_draw
= false;
2920 pending_layer_
->UpdateTiles(resourceless_software_draw
);
2922 unique_tiles
.clear();
2923 high_res_tile_count
= 0u;
2924 queue
.reset(new TilingSetRasterQueueAll(
2925 pending_layer_
->picture_layer_tiling_set(), false));
2926 while (!queue
->IsEmpty()) {
2927 PrioritizedTile prioritized_tile
= queue
->Top();
2928 TilePriority priority
= prioritized_tile
.priority();
2930 EXPECT_TRUE(prioritized_tile
.tile());
2932 // Non-high res tiles only get visible tiles.
2933 EXPECT_EQ(HIGH_RESOLUTION
, priority
.resolution
);
2934 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
2936 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2938 unique_tiles
.insert(prioritized_tile
.tile());
2942 EXPECT_EQ(16, high_res_tile_count
);
2943 EXPECT_EQ(high_res_tile_count
, static_cast<int>(unique_tiles
.size()));
2945 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
2947 pending_layer_
->draw_properties().visible_layer_rect
=
2948 gfx::Rect(0, 0, 500, 500);
2949 pending_layer_
->UpdateTiles(resourceless_software_draw
);
2951 std::vector
<Tile
*> high_res_tiles
=
2952 pending_layer_
->HighResTiling()->AllTilesForTesting();
2953 for (std::vector
<Tile
*>::iterator tile_it
= high_res_tiles
.begin();
2954 tile_it
!= high_res_tiles
.end();
2956 Tile
* tile
= *tile_it
;
2957 TileDrawInfo
& draw_info
= tile
->draw_info();
2958 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
2961 non_ideal_tile_count
= 0;
2962 low_res_tile_count
= 0;
2963 high_res_tile_count
= 0;
2964 queue
.reset(new TilingSetRasterQueueAll(
2965 pending_layer_
->picture_layer_tiling_set(), true));
2966 while (!queue
->IsEmpty()) {
2967 PrioritizedTile prioritized_tile
= queue
->Top();
2968 TilePriority priority
= prioritized_tile
.priority();
2970 EXPECT_TRUE(prioritized_tile
.tile());
2972 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
2973 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
2974 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2978 EXPECT_EQ(0, non_ideal_tile_count
);
2979 EXPECT_EQ(1, low_res_tile_count
);
2980 EXPECT_EQ(0, high_res_tile_count
);
2983 TEST_F(PictureLayerImplTest
, TilingSetRasterQueueActiveTree
) {
2984 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2986 host_impl_
.SetViewportSize(gfx::Size(500, 500));
2988 gfx::Size
tile_size(100, 100);
2989 gfx::Size
layer_bounds(1000, 1000);
2991 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2992 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2994 SetupPendingTree(pending_pile
);
2996 EXPECT_EQ(2u, active_layer_
->num_tilings());
2998 scoped_ptr
<TilingSetRasterQueueRequired
> queue(
2999 new TilingSetRasterQueueRequired(
3000 active_layer_
->picture_layer_tiling_set(),
3001 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
));
3002 EXPECT_FALSE(queue
->IsEmpty());
3003 while (!queue
->IsEmpty()) {
3004 PrioritizedTile prioritized_tile
= queue
->Top();
3005 EXPECT_TRUE(prioritized_tile
.tile()->required_for_draw());
3006 EXPECT_FALSE(prioritized_tile
.tile()->draw_info().IsReadyToDraw());
3010 queue
.reset(new TilingSetRasterQueueRequired(
3011 active_layer_
->picture_layer_tiling_set(),
3012 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
3013 EXPECT_TRUE(queue
->IsEmpty());
3016 TEST_F(PictureLayerImplTest
, TilingSetRasterQueueRequiredNoHighRes
) {
3017 scoped_ptr
<FakePicturePile
> empty_recording
=
3018 FakePicturePile::CreateEmptyPile(gfx::Size(256, 256),
3019 gfx::Size(1024, 1024));
3020 empty_recording
->SetIsSolidColor(true);
3022 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3023 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
3025 SetupPendingTree(pending_pile
);
3027 pending_layer_
->picture_layer_tiling_set()->FindTilingWithResolution(
3030 scoped_ptr
<TilingSetRasterQueueRequired
> queue(
3031 new TilingSetRasterQueueRequired(
3032 pending_layer_
->picture_layer_tiling_set(),
3033 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
3034 EXPECT_TRUE(queue
->IsEmpty());
3037 TEST_F(PictureLayerImplTest
, TilingSetEvictionQueue
) {
3038 gfx::Size
tile_size(100, 100);
3039 gfx::Size
layer_bounds(1000, 1000);
3040 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3042 host_impl_
.SetViewportSize(gfx::Size(500, 500));
3044 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3045 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3047 // TODO(vmpstr): Add a test with tilings other than high/low res on the active
3049 SetupPendingTree(pending_pile
);
3050 EXPECT_EQ(2u, pending_layer_
->num_tilings());
3052 std::vector
<Tile
*> all_tiles
;
3053 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3054 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3055 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
3056 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
3059 std::set
<Tile
*> all_tiles_set(all_tiles
.begin(), all_tiles
.end());
3061 bool mark_required
= false;
3062 size_t number_of_marked_tiles
= 0u;
3063 size_t number_of_unmarked_tiles
= 0u;
3064 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3065 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3066 for (PictureLayerTiling::CoverageIterator
iter(
3067 tiling
, 1.f
, pending_layer_
->visible_layer_rect());
3069 if (mark_required
) {
3070 number_of_marked_tiles
++;
3071 iter
->set_required_for_activation(true);
3073 number_of_unmarked_tiles
++;
3075 mark_required
= !mark_required
;
3080 EXPECT_EQ(17u, all_tiles
.size());
3081 EXPECT_EQ(17u, all_tiles_set
.size());
3082 EXPECT_GT(number_of_marked_tiles
, 1u);
3083 EXPECT_GT(number_of_unmarked_tiles
, 1u);
3085 // Tiles don't have resources yet.
3086 scoped_ptr
<TilingSetEvictionQueue
> queue(
3087 new TilingSetEvictionQueue(pending_layer_
->picture_layer_tiling_set()));
3088 EXPECT_TRUE(queue
->IsEmpty());
3090 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
3092 std::set
<Tile
*> unique_tiles
;
3093 float expected_scales
[] = {low_res_factor
, 1.f
};
3094 size_t scale_index
= 0;
3095 bool reached_visible
= false;
3096 PrioritizedTile last_tile
;
3097 size_t distance_decreasing
= 0;
3098 size_t distance_increasing
= 0;
3100 new TilingSetEvictionQueue(pending_layer_
->picture_layer_tiling_set()));
3101 while (!queue
->IsEmpty()) {
3102 PrioritizedTile prioritized_tile
= queue
->Top();
3103 Tile
* tile
= prioritized_tile
.tile();
3104 if (!last_tile
.tile())
3105 last_tile
= prioritized_tile
;
3109 TilePriority priority
= prioritized_tile
.priority();
3111 if (priority
.priority_bin
== TilePriority::NOW
) {
3112 reached_visible
= true;
3113 last_tile
= prioritized_tile
;
3117 EXPECT_FALSE(tile
->required_for_activation());
3119 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
3120 std::numeric_limits
<float>::epsilon()) {
3122 ASSERT_LT(scale_index
, arraysize(expected_scales
));
3125 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
3126 unique_tiles
.insert(tile
);
3128 if (tile
->required_for_activation() ==
3129 last_tile
.tile()->required_for_activation() &&
3130 std::abs(tile
->contents_scale() - last_tile
.tile()->contents_scale()) <
3131 std::numeric_limits
<float>::epsilon()) {
3132 if (priority
.distance_to_visible
<=
3133 last_tile
.priority().distance_to_visible
)
3134 ++distance_decreasing
;
3136 ++distance_increasing
;
3139 last_tile
= prioritized_tile
;
3143 // 4 high res tiles are inside the viewport, the rest are evicted.
3144 EXPECT_TRUE(reached_visible
);
3145 EXPECT_EQ(12u, unique_tiles
.size());
3146 EXPECT_EQ(1u, distance_increasing
);
3147 EXPECT_EQ(11u, distance_decreasing
);
3150 bool reached_required
= false;
3151 while (!queue
->IsEmpty()) {
3152 PrioritizedTile prioritized_tile
= queue
->Top();
3153 Tile
* tile
= prioritized_tile
.tile();
3156 TilePriority priority
= prioritized_tile
.priority();
3157 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
3159 if (reached_required
) {
3160 EXPECT_TRUE(tile
->required_for_activation());
3161 } else if (tile
->required_for_activation()) {
3162 reached_required
= true;
3166 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
3167 std::numeric_limits
<float>::epsilon()) {
3169 ASSERT_LT(scale_index
, arraysize(expected_scales
));
3172 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
3173 unique_tiles
.insert(tile
);
3177 EXPECT_TRUE(reached_required
);
3178 EXPECT_EQ(all_tiles_set
.size(), unique_tiles
.size());
3181 TEST_F(PictureLayerImplTest
, Occlusion
) {
3182 gfx::Size
tile_size(102, 102);
3183 gfx::Size
layer_bounds(1000, 1000);
3184 gfx::Size
viewport_size(1000, 1000);
3186 LayerTestCommon::LayerImplTest impl
;
3187 host_impl_
.SetViewportSize(viewport_size
);
3189 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3190 FakePicturePileImpl::CreateFilledPile(layer_bounds
, layer_bounds
);
3191 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
3194 std::vector
<Tile
*> tiles
=
3195 active_layer_
->HighResTiling()->AllTilesForTesting();
3196 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3199 SCOPED_TRACE("No occlusion");
3201 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3203 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
3204 gfx::Rect(layer_bounds
));
3205 EXPECT_EQ(100u, impl
.quad_list().size());
3209 SCOPED_TRACE("Full occlusion");
3210 gfx::Rect
occluded(active_layer_
->visible_layer_rect());
3211 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3213 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(), gfx::Rect());
3214 EXPECT_EQ(impl
.quad_list().size(), 0u);
3218 SCOPED_TRACE("Partial occlusion");
3219 gfx::Rect
occluded(150, 0, 200, 1000);
3220 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3222 size_t partially_occluded_count
= 0;
3223 LayerTestCommon::VerifyQuadsAreOccluded(
3224 impl
.quad_list(), occluded
, &partially_occluded_count
);
3225 // The layer outputs one quad, which is partially occluded.
3226 EXPECT_EQ(100u - 10u, impl
.quad_list().size());
3227 EXPECT_EQ(10u + 10u, partially_occluded_count
);
3231 TEST_F(PictureLayerImplTest
, RasterScaleChangeWithoutAnimation
) {
3232 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
3233 SetupDefaultTrees(tile_size
);
3235 ResetTilingsAndRasterScales();
3237 float contents_scale
= 2.f
;
3238 float device_scale
= 1.f
;
3239 float page_scale
= 1.f
;
3240 float maximum_animation_scale
= 1.f
;
3241 float starting_animation_scale
= 0.f
;
3242 bool animating_transform
= false;
3244 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
3245 maximum_animation_scale
,
3246 starting_animation_scale
, animating_transform
);
3247 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
3249 // Changing the source scale without being in an animation will cause
3250 // the layer to reset its source scale to 1.f.
3251 contents_scale
= 3.f
;
3253 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
3254 maximum_animation_scale
,
3255 starting_animation_scale
, animating_transform
);
3256 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3258 // Further changes to the source scale will no longer be reflected in the
3260 contents_scale
= 0.5f
;
3262 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
3263 maximum_animation_scale
,
3264 starting_animation_scale
, animating_transform
);
3265 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3268 TEST_F(PictureLayerImplTest
, LowResReadyToDrawNotEnoughToActivate
) {
3269 gfx::Size
tile_size(100, 100);
3270 gfx::Size
layer_bounds(1000, 1000);
3272 // Make sure pending tree has tiles.
3273 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3274 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3276 // All pending layer tiles required are not ready.
3277 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3279 // Initialize all low-res tiles.
3280 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3281 pending_layer_
->SetAllTilesReadyInTiling(active_layer_
->LowResTiling());
3283 // Low-res tiles should not be enough.
3284 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3286 // Initialize remaining tiles.
3287 pending_layer_
->SetAllTilesReady();
3288 active_layer_
->SetAllTilesReady();
3290 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3293 TEST_F(PictureLayerImplTest
, HighResReadyToDrawEnoughToActivate
) {
3294 gfx::Size
tile_size(100, 100);
3295 gfx::Size
layer_bounds(1000, 1000);
3297 // Make sure pending tree has tiles.
3298 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3299 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3301 // All pending layer tiles required are not ready.
3302 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3304 // Initialize all high-res tiles.
3305 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3306 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3308 // High-res tiles should be enough, since they cover everything visible.
3309 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3312 TEST_F(PictureLayerImplTest
,
3313 ActiveHighResReadyAndPendingLowResReadyNotEnoughToActivate
) {
3314 gfx::Size
tile_size(100, 100);
3315 gfx::Size
layer_bounds(1000, 1000);
3317 // Make sure pending tree has tiles.
3318 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3319 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3321 // Initialize all high-res tiles in the active layer.
3322 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3323 // And all the low-res tiles in the pending layer.
3324 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3326 // The pending high-res tiles are not ready, so we cannot activate.
3327 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3329 // When the pending high-res tiles are ready, we can activate.
3330 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3331 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3334 TEST_F(PictureLayerImplTest
, ActiveHighResReadyNotEnoughToActivate
) {
3335 gfx::Size
tile_size(100, 100);
3336 gfx::Size
layer_bounds(1000, 1000);
3338 // Make sure pending tree has tiles.
3339 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3340 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3342 // Initialize all high-res tiles in the active layer.
3343 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3345 // The pending high-res tiles are not ready, so we cannot activate.
3346 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3348 // When the pending pending high-res tiles are ready, we can activate.
3349 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3350 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3353 TEST_F(NoLowResPictureLayerImplTest
, ManageTilingsCreatesTilings
) {
3354 gfx::Size
tile_size(400, 400);
3355 gfx::Size
layer_bounds(1300, 1900);
3357 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3358 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3359 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3360 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3362 SetupTrees(pending_pile
, active_pile
);
3364 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3365 EXPECT_LT(low_res_factor
, 1.f
);
3367 ResetTilingsAndRasterScales();
3369 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3370 6.f
, // ideal contents scale
3371 3.f
, // device scale
3373 1.f
, // maximum animation scale
3374 0.f
, // starting animation scale
3376 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3377 EXPECT_FLOAT_EQ(6.f
,
3378 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3380 // If we change the page scale factor, then we should get new tilings.
3381 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3382 6.6f
, // ideal contents scale
3383 3.f
, // device scale
3385 1.f
, // maximum animation scale
3386 0.f
, // starting animation scale
3388 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3389 EXPECT_FLOAT_EQ(6.6f
,
3390 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3392 // If we change the device scale factor, then we should get new tilings.
3393 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3394 7.26f
, // ideal contents scale
3395 3.3f
, // device scale
3397 1.f
, // maximum animation scale
3398 0.f
, // starting animation scale
3400 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
3401 EXPECT_FLOAT_EQ(7.26f
,
3402 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3404 // If we change the device scale factor, but end up at the same total scale
3405 // factor somehow, then we don't get new tilings.
3406 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3407 7.26f
, // ideal contents scale
3408 2.2f
, // device scale
3410 1.f
, // maximum animation scale
3411 0.f
, // starting animation scale
3413 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
3414 EXPECT_FLOAT_EQ(7.26f
,
3415 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3418 TEST_F(NoLowResPictureLayerImplTest
, PendingLayerOnlyHasHighResTiling
) {
3419 gfx::Size
tile_size(400, 400);
3420 gfx::Size
layer_bounds(1300, 1900);
3422 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3423 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3424 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3425 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3427 SetupTrees(pending_pile
, active_pile
);
3429 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3430 EXPECT_LT(low_res_factor
, 1.f
);
3432 ResetTilingsAndRasterScales();
3434 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3435 6.f
, // ideal contents scale
3436 3.f
, // device scale
3438 1.f
, // maximum animation scale
3439 0.f
, // starting animation scale
3441 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3442 EXPECT_FLOAT_EQ(6.f
,
3443 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3445 // If we change the page scale factor, then we should get new tilings.
3446 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3447 6.6f
, // ideal contents scale
3448 3.f
, // device scale
3450 1.f
, // maximum animation scale
3451 0.f
, // starting animation scale
3453 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3454 EXPECT_FLOAT_EQ(6.6f
,
3455 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3457 // If we change the device scale factor, then we should get new tilings.
3458 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3459 7.26f
, // ideal contents scale
3460 3.3f
, // device scale
3462 1.f
, // maximum animation scale
3463 0.f
, // starting animation scale
3465 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3466 EXPECT_FLOAT_EQ(7.26f
,
3467 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3469 // If we change the device scale factor, but end up at the same total scale
3470 // factor somehow, then we don't get new tilings.
3471 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3472 7.26f
, // ideal contents scale
3473 2.2f
, // device scale
3475 1.f
, // maximum animation scale
3476 0.f
, // starting animation scale
3478 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3479 EXPECT_FLOAT_EQ(7.26f
,
3480 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3483 TEST_F(NoLowResPictureLayerImplTest
, AllHighResRequiredEvenIfNotChanged
) {
3484 gfx::Size
layer_bounds(400, 400);
3485 gfx::Size
tile_size(100, 100);
3487 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
3489 Tile
* some_active_tile
=
3490 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
3491 EXPECT_FALSE(some_active_tile
->draw_info().IsReadyToDraw());
3493 // Since there is no invalidation, pending tree should have no tiles.
3494 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
3495 if (host_impl_
.settings().create_low_res_tiling
)
3496 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
3498 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
3499 if (host_impl_
.settings().create_low_res_tiling
)
3500 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
3502 AssertAllTilesRequired(active_layer_
->HighResTiling());
3503 if (host_impl_
.settings().create_low_res_tiling
)
3504 AssertNoTilesRequired(active_layer_
->LowResTiling());
3507 TEST_F(NoLowResPictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
3508 gfx::Size
layer_bounds(400, 400);
3509 gfx::Size
tile_size(100, 100);
3511 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3512 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3513 // This pile will create tilings, but has no recordings so will not create any
3514 // tiles. This is attempting to simulate scrolling past the end of recorded
3515 // content on the active layer, where the recordings are so far away that
3516 // no tiles are created.
3517 bool is_solid_color
= false;
3518 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3519 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
3520 tile_size
, layer_bounds
, is_solid_color
);
3522 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
3524 // Active layer has tilings, but no tiles due to missing recordings.
3525 EXPECT_TRUE(active_layer_
->CanHaveTilings());
3526 EXPECT_EQ(active_layer_
->tilings()->num_tilings(),
3527 host_impl_
.settings().create_low_res_tiling
? 2u : 1u);
3528 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
3530 // Since the active layer has no tiles at all, the pending layer doesn't
3531 // need content in order to activate.
3532 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
3533 if (host_impl_
.settings().create_low_res_tiling
)
3534 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
3536 AssertNoTilesRequired(pending_layer_
->HighResTiling());
3537 if (host_impl_
.settings().create_low_res_tiling
)
3538 AssertNoTilesRequired(pending_layer_
->LowResTiling());
3541 TEST_F(NoLowResPictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
3542 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
3544 gfx::Size
tile_size(100, 100);
3545 gfx::Size
layer_bounds(400, 400);
3547 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3548 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3549 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3550 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3552 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
3554 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
3557 // UpdateTiles with valid viewport. Should update tile viewport.
3558 // Note viewport is considered invalid if and only if in resourceless
3560 bool resourceless_software_draw
= false;
3561 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
3562 gfx::Transform transform
;
3563 host_impl_
.SetExternalDrawConstraints(transform
,
3568 resourceless_software_draw
);
3569 active_layer_
->draw_properties().visible_layer_rect
= viewport
;
3570 active_layer_
->draw_properties().screen_space_transform
= transform
;
3571 active_layer_
->UpdateTiles(resourceless_software_draw
);
3573 gfx::Rect visible_rect_for_tile_priority
=
3574 active_layer_
->visible_rect_for_tile_priority();
3575 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
3576 gfx::Transform screen_space_transform_for_tile_priority
=
3577 active_layer_
->screen_space_transform();
3579 // Expand viewport and set it as invalid for prioritizing tiles.
3580 // Should update viewport and transform, but not update visible rect.
3581 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3582 resourceless_software_draw
= true;
3583 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
3584 transform
.Translate(1.f
, 1.f
);
3585 active_layer_
->draw_properties().visible_layer_rect
= viewport
;
3586 active_layer_
->draw_properties().screen_space_transform
= transform
;
3587 host_impl_
.SetExternalDrawConstraints(transform
,
3592 resourceless_software_draw
);
3593 active_layer_
->UpdateTiles(resourceless_software_draw
);
3595 // Transform for tile priority is updated.
3596 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3597 active_layer_
->screen_space_transform());
3598 // Visible rect for tile priority retains old value.
3599 EXPECT_EQ(visible_rect_for_tile_priority
,
3600 active_layer_
->visible_rect_for_tile_priority());
3602 // Keep expanded viewport but mark it valid. Should update tile viewport.
3603 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3604 resourceless_software_draw
= false;
3605 host_impl_
.SetExternalDrawConstraints(transform
,
3610 resourceless_software_draw
);
3611 active_layer_
->UpdateTiles(resourceless_software_draw
);
3613 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3614 active_layer_
->screen_space_transform());
3615 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
3618 TEST_F(NoLowResPictureLayerImplTest
, CleanUpTilings
) {
3619 gfx::Size
tile_size(400, 400);
3620 gfx::Size
layer_bounds(1300, 1900);
3622 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3623 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3624 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3625 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3627 std::vector
<PictureLayerTiling
*> used_tilings
;
3629 SetupTrees(pending_pile
, active_pile
);
3631 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3632 EXPECT_LT(low_res_factor
, 1.f
);
3634 float device_scale
= 1.7f
;
3635 float page_scale
= 3.2f
;
3638 ResetTilingsAndRasterScales();
3640 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, 0.f
,
3642 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3644 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
3645 // |used_tilings| variable, and it's here only to ensure that active_layer_
3646 // won't remove tilings before the test has a chance to verify behavior.
3647 active_layer_
->MarkAllTilingsUsed();
3649 // We only have ideal tilings, so they aren't removed.
3650 used_tilings
.clear();
3651 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3652 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3654 host_impl_
.PinchGestureBegin();
3656 // Changing the ideal but not creating new tilings.
3659 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, 0.f
,
3661 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3663 // The tilings are still our target scale, so they aren't removed.
3664 used_tilings
.clear();
3665 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3666 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3668 host_impl_
.PinchGestureEnd();
3670 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
3673 SetContentsScaleOnBothLayers(1.2f
, device_scale
, page_scale
, 1.f
, 0.f
, false);
3674 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3675 EXPECT_FLOAT_EQ(1.f
,
3676 active_layer_
->tilings()->tiling_at(1)->contents_scale());
3678 // Ensure UpdateTiles won't remove any tilings.
3679 active_layer_
->MarkAllTilingsUsed();
3681 // Mark the non-ideal tilings as used. They won't be removed.
3682 used_tilings
.clear();
3683 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3684 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3685 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3687 // Now move the ideal scale to 0.5. Our target stays 1.2.
3688 SetContentsScaleOnBothLayers(0.5f
, device_scale
, page_scale
, 1.f
, 0.f
, false);
3690 // The high resolution tiling is between target and ideal, so is not
3691 // removed. The low res tiling for the old ideal=1.0 scale is removed.
3692 used_tilings
.clear();
3693 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3694 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3696 // Now move the ideal scale to 1.0. Our target stays 1.2.
3697 SetContentsScaleOnBothLayers(1.f
, device_scale
, page_scale
, 1.f
, 0.f
, false);
3699 // All the tilings are between are target and the ideal, so they are not
3701 used_tilings
.clear();
3702 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3703 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3705 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
3706 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.1f
, device_scale
,
3707 page_scale
, 1.f
, 0.f
, false);
3709 // Because the pending layer's ideal scale is still 1.0, our tilings fall
3710 // in the range [1.0,1.2] and are kept.
3711 used_tilings
.clear();
3712 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3713 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3715 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
3717 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.1f
, device_scale
,
3718 page_scale
, 1.f
, 0.f
, false);
3720 // Our 1.0 tiling now falls outside the range between our ideal scale and our
3721 // target raster scale. But it is in our used tilings set, so nothing is
3723 used_tilings
.clear();
3724 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3725 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3726 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3728 // If we remove it from our used tilings set, it is outside the range to keep
3729 // so it is deleted.
3730 used_tilings
.clear();
3731 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3732 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3735 TEST_F(NoLowResPictureLayerImplTest
, ReleaseResources
) {
3736 gfx::Size
tile_size(400, 400);
3737 gfx::Size
layer_bounds(1300, 1900);
3739 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3740 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3741 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3742 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3744 SetupTrees(pending_pile
, active_pile
);
3745 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3746 EXPECT_EQ(1u, active_layer_
->tilings()->num_tilings());
3748 // All tilings should be removed when losing output surface.
3749 active_layer_
->ReleaseResources();
3750 EXPECT_FALSE(active_layer_
->tilings());
3751 active_layer_
->RecreateResources();
3752 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
3753 pending_layer_
->ReleaseResources();
3754 EXPECT_FALSE(pending_layer_
->tilings());
3755 pending_layer_
->RecreateResources();
3756 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
3758 // This should create new tilings.
3759 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3760 1.3f
, // ideal contents scale
3761 2.7f
, // device scale
3763 1.f
, // maximum animation scale
3764 0.f
, // starting animation scale
3766 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3769 TEST_F(PictureLayerImplTest
, SharedQuadStateContainsMaxTilingScale
) {
3770 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3772 gfx::Size
tile_size(400, 400);
3773 gfx::Size
layer_bounds(1000, 2000);
3775 host_impl_
.SetViewportSize(gfx::Size(10000, 20000));
3777 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3778 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3779 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3780 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3782 SetupTrees(pending_pile
, active_pile
);
3784 ResetTilingsAndRasterScales();
3785 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.5f
, 1.f
, 1.f
, 1.f
, 0.f
,
3788 float max_contents_scale
= active_layer_
->MaximumTilingContentsScale();
3789 EXPECT_EQ(2.5f
, max_contents_scale
);
3791 gfx::Transform scaled_draw_transform
= active_layer_
->draw_transform();
3792 scaled_draw_transform
.Scale(SK_MScalar1
/ max_contents_scale
,
3793 SK_MScalar1
/ max_contents_scale
);
3795 AppendQuadsData data
;
3796 active_layer_
->AppendQuads(render_pass
.get(), &data
);
3798 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
3799 EXPECT_EQ(1u, render_pass
->shared_quad_state_list
.size());
3800 // The quad_to_target_transform should be scaled by the
3801 // MaximumTilingContentsScale on the layer.
3802 EXPECT_EQ(scaled_draw_transform
.ToString(),
3803 render_pass
->shared_quad_state_list
.front()
3804 ->quad_to_target_transform
.ToString());
3805 // The content_bounds should be scaled by the
3806 // MaximumTilingContentsScale on the layer.
3807 EXPECT_EQ(gfx::Size(2500u, 5000u).ToString(),
3808 render_pass
->shared_quad_state_list
.front()
3809 ->quad_layer_bounds
.ToString());
3810 // The visible_layer_rect should be scaled by the
3811 // MaximumTilingContentsScale on the layer.
3812 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
3813 render_pass
->shared_quad_state_list
.front()
3814 ->visible_quad_layer_rect
.ToString());
3817 class PictureLayerImplTestWithDelegatingRenderer
: public PictureLayerImplTest
{
3819 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {}
3821 void InitializeRenderer() override
{
3822 host_impl_
.InitializeRenderer(FakeOutputSurface::CreateDelegating3d());
3826 TEST_F(PictureLayerImplTestWithDelegatingRenderer
,
3827 DelegatingRendererWithTileOOM
) {
3828 // This test is added for crbug.com/402321, where quad should be produced when
3829 // raster on demand is not allowed and tile is OOM.
3830 gfx::Size tile_size
= host_impl_
.settings().default_tile_size
;
3831 gfx::Size
layer_bounds(1000, 1000);
3834 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3835 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3836 SetupPendingTree(pending_pile
);
3837 pending_layer_
->SetBounds(layer_bounds
);
3839 bool update_lcd_text
= false;
3840 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
3841 std::vector
<Tile
*> tiles
=
3842 active_layer_
->HighResTiling()->AllTilesForTesting();
3843 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3845 // Force tiles after max_tiles to be OOM. TileManager uses
3846 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3847 // directly set state to host_impl_, so we set policy that would change the
3848 // state. We also need to update tree priority separately.
3849 GlobalStateThatImpactsTilePriority state
;
3850 size_t max_tiles
= 1;
3851 size_t memory_limit
= max_tiles
* 4 * tile_size
.width() * tile_size
.height();
3852 size_t resource_limit
= max_tiles
;
3853 ManagedMemoryPolicy
policy(memory_limit
,
3854 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
,
3856 host_impl_
.SetMemoryPolicy(policy
);
3857 host_impl_
.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES
);
3858 host_impl_
.PrepareTiles();
3860 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3861 AppendQuadsData data
;
3862 active_layer_
->WillDraw(DRAW_MODE_HARDWARE
, nullptr);
3863 active_layer_
->AppendQuads(render_pass
.get(), &data
);
3864 active_layer_
->DidDraw(nullptr);
3866 // Even when OOM, quads should be produced, and should be different material
3867 // from quads with resource.
3868 EXPECT_LT(max_tiles
, render_pass
->quad_list
.size());
3869 EXPECT_EQ(DrawQuad::Material::TILED_CONTENT
,
3870 render_pass
->quad_list
.front()->material
);
3871 EXPECT_EQ(DrawQuad::Material::SOLID_COLOR
,
3872 render_pass
->quad_list
.back()->material
);
3875 class OcclusionTrackingSettings
: public LowResTilingsSettings
{
3877 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization
= true; }
3880 class OcclusionTrackingPictureLayerImplTest
: public PictureLayerImplTest
{
3882 OcclusionTrackingPictureLayerImplTest()
3883 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
3885 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl
* layer
,
3887 size_t expected_occluded_tile_count
,
3889 size_t occluded_tile_count
= 0u;
3890 PrioritizedTile last_tile
;
3892 scoped_ptr
<TilingSetEvictionQueue
> queue(
3893 new TilingSetEvictionQueue(layer
->picture_layer_tiling_set()));
3894 while (!queue
->IsEmpty()) {
3895 PrioritizedTile prioritized_tile
= queue
->Top();
3896 Tile
* tile
= prioritized_tile
.tile();
3897 if (!last_tile
.tile())
3898 last_tile
= prioritized_tile
;
3900 // The only way we will encounter an occluded tile after an unoccluded
3901 // tile is if the priorty bin decreased, the tile is required for
3902 // activation, or the scale changed.
3903 bool tile_is_occluded
= prioritized_tile
.is_occluded();
3904 if (tile_is_occluded
) {
3905 occluded_tile_count
++;
3907 bool last_tile_is_occluded
= last_tile
.is_occluded();
3908 if (!last_tile_is_occluded
) {
3909 TilePriority::PriorityBin tile_priority_bin
=
3910 prioritized_tile
.priority().priority_bin
;
3911 TilePriority::PriorityBin last_tile_priority_bin
=
3912 last_tile
.priority().priority_bin
;
3914 EXPECT_TRUE(tile_priority_bin
< last_tile_priority_bin
||
3915 tile
->required_for_activation() ||
3916 tile
->contents_scale() !=
3917 last_tile
.tile()->contents_scale())
3918 << "line: " << source_line
;
3921 last_tile
= prioritized_tile
;
3924 EXPECT_EQ(expected_occluded_tile_count
, occluded_tile_count
)
3925 << "line: " << source_line
;
3929 TEST_F(OcclusionTrackingPictureLayerImplTest
,
3930 OccludedTilesSkippedDuringRasterization
) {
3931 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
3933 gfx::Size
tile_size(102, 102);
3934 gfx::Size
layer_bounds(1000, 1000);
3935 gfx::Size
viewport_size(500, 500);
3936 gfx::Point
occluding_layer_position(310, 0);
3938 host_impl_
.SetViewportSize(viewport_size
);
3940 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3941 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3942 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
3945 int unoccluded_tile_count
= 0;
3946 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
3947 pending_layer_
->picture_layer_tiling_set(), false));
3948 while (!queue
->IsEmpty()) {
3949 PrioritizedTile prioritized_tile
= queue
->Top();
3950 Tile
* tile
= prioritized_tile
.tile();
3952 // Occluded tiles should not be iterated over.
3953 EXPECT_FALSE(prioritized_tile
.is_occluded());
3955 // Some tiles may not be visible (i.e. outside the viewport). The rest are
3956 // visible and at least partially unoccluded, verified by the above expect.
3957 bool tile_is_visible
=
3958 tile
->content_rect().Intersects(pending_layer_
->visible_layer_rect());
3959 if (tile_is_visible
)
3960 unoccluded_tile_count
++;
3963 EXPECT_EQ(unoccluded_tile_count
, 25);
3965 // Partial occlusion.
3966 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
3967 LayerImpl
* layer1
= pending_layer_
->children()[0];
3968 layer1
->SetBounds(layer_bounds
);
3969 layer1
->SetDrawsContent(true);
3970 layer1
->SetContentsOpaque(true);
3971 layer1
->SetPosition(occluding_layer_position
);
3973 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3974 bool update_lcd_text
= false;
3975 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
3977 unoccluded_tile_count
= 0;
3978 queue
.reset(new TilingSetRasterQueueAll(
3979 pending_layer_
->picture_layer_tiling_set(), false));
3980 while (!queue
->IsEmpty()) {
3981 PrioritizedTile prioritized_tile
= queue
->Top();
3982 Tile
* tile
= prioritized_tile
.tile();
3984 EXPECT_FALSE(prioritized_tile
.is_occluded());
3986 bool tile_is_visible
=
3987 tile
->content_rect().Intersects(pending_layer_
->visible_layer_rect());
3988 if (tile_is_visible
)
3989 unoccluded_tile_count
++;
3992 EXPECT_EQ(20, unoccluded_tile_count
);
3995 layer1
->SetPosition(gfx::Point(0, 0));
3997 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3998 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4000 unoccluded_tile_count
= 0;
4001 queue
.reset(new TilingSetRasterQueueAll(
4002 pending_layer_
->picture_layer_tiling_set(), false));
4003 while (!queue
->IsEmpty()) {
4004 PrioritizedTile prioritized_tile
= queue
->Top();
4005 Tile
* tile
= prioritized_tile
.tile();
4007 EXPECT_FALSE(prioritized_tile
.is_occluded());
4009 bool tile_is_visible
=
4010 tile
->content_rect().Intersects(pending_layer_
->visible_layer_rect());
4011 if (tile_is_visible
)
4012 unoccluded_tile_count
++;
4015 EXPECT_EQ(unoccluded_tile_count
, 0);
4018 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4019 OccludedTilesNotMarkedAsRequired
) {
4020 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4022 gfx::Size
tile_size(102, 102);
4023 gfx::Size
layer_bounds(1000, 1000);
4024 gfx::Size
viewport_size(500, 500);
4025 gfx::Point
occluding_layer_position(310, 0);
4027 host_impl_
.SetViewportSize(viewport_size
);
4029 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4030 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4031 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4034 int occluded_tile_count
= 0;
4035 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4036 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4037 auto prioritized_tiles
=
4038 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4040 occluded_tile_count
= 0;
4041 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4042 gfx::Rect(layer_bounds
));
4046 const Tile
* tile
= *iter
;
4048 // Fully occluded tiles are not required for activation.
4049 if (prioritized_tiles
[tile
].is_occluded()) {
4050 EXPECT_FALSE(tile
->required_for_activation());
4051 occluded_tile_count
++;
4054 EXPECT_EQ(occluded_tile_count
, 0);
4057 // Partial occlusion.
4058 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4059 LayerImpl
* layer1
= pending_layer_
->children()[0];
4060 layer1
->SetBounds(layer_bounds
);
4061 layer1
->SetDrawsContent(true);
4062 layer1
->SetContentsOpaque(true);
4063 layer1
->SetPosition(occluding_layer_position
);
4065 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
4066 bool update_lcd_text
= false;
4067 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4069 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4070 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4071 auto prioritized_tiles
=
4072 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4074 occluded_tile_count
= 0;
4075 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4076 gfx::Rect(layer_bounds
));
4080 const Tile
* tile
= *iter
;
4082 if (prioritized_tiles
[tile
].is_occluded()) {
4083 EXPECT_FALSE(tile
->required_for_activation());
4084 occluded_tile_count
++;
4089 EXPECT_EQ(occluded_tile_count
, 5);
4092 EXPECT_EQ(occluded_tile_count
, 2);
4100 layer1
->SetPosition(gfx::PointF(0, 0));
4102 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
4103 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4105 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4106 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4107 auto prioritized_tiles
=
4108 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4110 occluded_tile_count
= 0;
4111 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4112 gfx::Rect(layer_bounds
));
4116 const Tile
* tile
= *iter
;
4118 if (prioritized_tiles
[tile
].is_occluded()) {
4119 EXPECT_FALSE(tile
->required_for_activation());
4120 occluded_tile_count
++;
4125 EXPECT_EQ(25, occluded_tile_count
);
4128 EXPECT_EQ(4, occluded_tile_count
);
4136 TEST_F(OcclusionTrackingPictureLayerImplTest
, OcclusionForDifferentScales
) {
4137 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4139 gfx::Size
tile_size(102, 102);
4140 gfx::Size
layer_bounds(1000, 1000);
4141 gfx::Size
viewport_size(500, 500);
4142 gfx::Point
occluding_layer_position(310, 0);
4144 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4145 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4147 host_impl_
.SetViewportSize(viewport_size
);
4149 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4150 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
4152 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4153 LayerImpl
* layer1
= pending_layer_
->children()[0];
4154 layer1
->SetBounds(layer_bounds
);
4155 layer1
->SetDrawsContent(true);
4156 layer1
->SetContentsOpaque(true);
4157 layer1
->SetPosition(occluding_layer_position
);
4159 pending_layer_
->tilings()->RemoveAllTilings();
4160 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
4161 pending_layer_
->AddTiling(low_res_factor
);
4162 pending_layer_
->AddTiling(0.3f
);
4163 pending_layer_
->AddTiling(0.7f
);
4164 pending_layer_
->AddTiling(1.0f
);
4165 pending_layer_
->AddTiling(2.0f
);
4167 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4168 // UpdateDrawProperties with the occluding layer.
4169 bool update_lcd_text
= false;
4170 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4172 EXPECT_EQ(5u, pending_layer_
->num_tilings());
4174 int occluded_tile_count
= 0;
4175 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4176 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4177 auto prioritized_tiles
=
4178 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4179 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4181 occluded_tile_count
= 0;
4182 for (size_t j
= 0; j
< tiles
.size(); ++j
) {
4183 if (prioritized_tiles
[tiles
[j
]].is_occluded()) {
4184 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4185 tiles
[j
]->content_rect(), 1.0f
/ tiles
[j
]->contents_scale());
4186 EXPECT_GE(scaled_content_rect
.x(), occluding_layer_position
.x());
4187 occluded_tile_count
++;
4193 EXPECT_EQ(occluded_tile_count
, 30);
4196 EXPECT_EQ(occluded_tile_count
, 5);
4199 EXPECT_EQ(occluded_tile_count
, 4);
4203 EXPECT_EQ(occluded_tile_count
, 2);
4211 TEST_F(OcclusionTrackingPictureLayerImplTest
, DifferentOcclusionOnTrees
) {
4212 gfx::Size
tile_size(102, 102);
4213 gfx::Size
layer_bounds(1000, 1000);
4214 gfx::Size
viewport_size(1000, 1000);
4215 gfx::Point
occluding_layer_position(310, 0);
4216 gfx::Rect
invalidation_rect(230, 230, 102, 102);
4218 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4219 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4220 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4221 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4223 host_impl_
.SetViewportSize(viewport_size
);
4224 SetupPendingTree(active_pile
);
4226 // Partially occlude the active layer.
4227 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 2));
4228 LayerImpl
* layer1
= pending_layer_
->children()[0];
4229 layer1
->SetBounds(layer_bounds
);
4230 layer1
->SetDrawsContent(true);
4231 layer1
->SetContentsOpaque(true);
4232 layer1
->SetPosition(occluding_layer_position
);
4236 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4237 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4238 auto prioritized_tiles
=
4239 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4241 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4242 gfx::Rect(layer_bounds
));
4246 const Tile
* tile
= *iter
;
4248 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4249 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4250 // Tiles are occluded on the active tree iff they lie beneath the
4252 EXPECT_EQ(prioritized_tiles
[tile
].is_occluded(),
4253 scaled_content_rect
.x() >= occluding_layer_position
.x());
4257 // Partially invalidate the pending layer.
4258 SetupPendingTreeWithInvalidation(pending_pile
, invalidation_rect
);
4260 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4261 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4262 auto prioritized_tiles
=
4263 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4265 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4266 gfx::Rect(layer_bounds
));
4270 const Tile
* tile
= *iter
;
4272 // All tiles are unoccluded, because the pending tree has no occlusion.
4273 EXPECT_FALSE(prioritized_tiles
[tile
].is_occluded());
4275 Tile
* twin_tile
= active_layer_
->GetPendingOrActiveTwinTiling(tiling
)
4276 ->TileAt(iter
.i(), iter
.j());
4277 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4278 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4280 if (scaled_content_rect
.Intersects(invalidation_rect
)) {
4281 // Tiles inside the invalidation rect exist on both trees.
4283 EXPECT_TRUE(twin_tile
);
4284 EXPECT_NE(tile
, twin_tile
);
4286 // Tiles outside the invalidation rect only exist on the active tree.
4288 EXPECT_FALSE(twin_tile
);
4294 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4295 OccludedTilesConsideredDuringEviction
) {
4296 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4298 gfx::Size
tile_size(102, 102);
4299 gfx::Size
layer_bounds(1000, 1000);
4300 gfx::Size
viewport_size(1000, 1000);
4301 gfx::Point
pending_occluding_layer_position(310, 0);
4302 gfx::Point
active_occluding_layer_position(0, 310);
4303 gfx::Rect
invalidation_rect(230, 230, 152, 152);
4305 host_impl_
.SetViewportSize(viewport_size
);
4306 host_impl_
.SetDeviceScaleFactor(2.f
);
4308 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4309 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4310 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4311 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4313 SetupPendingTreeWithFixedTileSize(active_pile
, tile_size
, Region());
4315 // Partially occlude the active layer.
4316 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 2));
4317 LayerImpl
* active_occluding_layer
= pending_layer_
->children()[0];
4318 active_occluding_layer
->SetBounds(layer_bounds
);
4319 active_occluding_layer
->SetDrawsContent(true);
4320 active_occluding_layer
->SetContentsOpaque(true);
4321 active_occluding_layer
->SetPosition(active_occluding_layer_position
);
4325 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4327 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, invalidation_rect
);
4329 // Partially occlude the pending layer in a different way.
4330 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 3));
4331 LayerImpl
* pending_occluding_layer
= pending_layer_
->children()[0];
4332 pending_occluding_layer
->SetBounds(layer_bounds
);
4333 pending_occluding_layer
->SetDrawsContent(true);
4334 pending_occluding_layer
->SetContentsOpaque(true);
4335 pending_occluding_layer
->SetPosition(pending_occluding_layer_position
);
4337 EXPECT_EQ(2u, pending_layer_
->num_tilings());
4338 EXPECT_EQ(2u, active_layer_
->num_tilings());
4340 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4341 // UpdateDrawProperties with the occluding layer.
4342 bool update_lcd_text
= false;
4343 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4345 // The expected number of occluded tiles on each of the 2 tilings for each of
4346 // the 3 tree priorities.
4347 size_t expected_occluded_tile_count_on_pending
[] = {4u, 0u};
4348 size_t expected_occluded_tile_count_on_active
[] = {12u, 1u};
4349 size_t total_expected_occluded_tile_count_on_trees
[] = {13u, 4u};
4351 // Verify number of occluded tiles on the pending layer for each tiling.
4352 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4353 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4354 auto prioritized_tiles
=
4355 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4357 size_t occluded_tile_count_on_pending
= 0u;
4358 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4359 gfx::Rect(layer_bounds
));
4363 if (invalidation_rect
.Intersects(iter
.geometry_rect()))
4370 if (prioritized_tiles
[tile
].is_occluded())
4371 occluded_tile_count_on_pending
++;
4373 EXPECT_EQ(expected_occluded_tile_count_on_pending
[i
],
4374 occluded_tile_count_on_pending
)
4375 << tiling
->contents_scale();
4378 // Verify number of occluded tiles on the active layer for each tiling.
4379 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4380 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4381 auto prioritized_tiles
=
4382 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4384 size_t occluded_tile_count_on_active
= 0u;
4385 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4386 gfx::Rect(layer_bounds
));
4392 if (prioritized_tiles
[tile
].is_occluded())
4393 occluded_tile_count_on_active
++;
4395 EXPECT_EQ(expected_occluded_tile_count_on_active
[i
],
4396 occluded_tile_count_on_active
)
4400 std::vector
<Tile
*> all_tiles
;
4401 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4402 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4403 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4404 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
4406 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4407 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4408 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4409 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
4412 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
4414 VerifyEvictionConsidersOcclusion(
4415 pending_layer_
, PENDING_TREE
,
4416 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
], __LINE__
);
4417 VerifyEvictionConsidersOcclusion(
4418 active_layer_
, ACTIVE_TREE
,
4419 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
], __LINE__
);
4421 // Repeat the tests without valid active tree priorities.
4422 active_layer_
->set_has_valid_tile_priorities(false);
4423 VerifyEvictionConsidersOcclusion(
4424 pending_layer_
, PENDING_TREE
,
4425 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
], __LINE__
);
4426 VerifyEvictionConsidersOcclusion(
4427 active_layer_
, ACTIVE_TREE
,
4428 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
], __LINE__
);
4429 active_layer_
->set_has_valid_tile_priorities(true);
4431 // Repeat the tests without valid pending tree priorities.
4432 pending_layer_
->set_has_valid_tile_priorities(false);
4433 VerifyEvictionConsidersOcclusion(
4434 active_layer_
, ACTIVE_TREE
,
4435 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
], __LINE__
);
4436 VerifyEvictionConsidersOcclusion(
4437 pending_layer_
, PENDING_TREE
,
4438 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
], __LINE__
);
4439 pending_layer_
->set_has_valid_tile_priorities(true);
4442 TEST_F(PictureLayerImplTest
, PendingOrActiveTwinLayer
) {
4443 gfx::Size
tile_size(102, 102);
4444 gfx::Size
layer_bounds(1000, 1000);
4446 scoped_refptr
<FakePicturePileImpl
> pile
=
4447 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4448 SetupPendingTree(pile
);
4449 EXPECT_FALSE(pending_layer_
->GetPendingOrActiveTwinLayer());
4452 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4454 SetupPendingTree(pile
);
4455 EXPECT_TRUE(pending_layer_
->GetPendingOrActiveTwinLayer());
4456 EXPECT_TRUE(active_layer_
->GetPendingOrActiveTwinLayer());
4457 EXPECT_EQ(pending_layer_
, active_layer_
->GetPendingOrActiveTwinLayer());
4458 EXPECT_EQ(active_layer_
, pending_layer_
->GetPendingOrActiveTwinLayer());
4461 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4463 // Make an empty pending tree.
4464 host_impl_
.CreatePendingTree();
4465 host_impl_
.pending_tree()->DetachLayerTree();
4466 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4469 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid
) {
4470 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4472 gfx::Size
tile_size(100, 100);
4473 gfx::Size
layer_bounds(200, 200);
4474 gfx::Rect
layer_rect(layer_bounds
);
4476 FakeContentLayerClient client
;
4477 scoped_refptr
<PictureLayer
> layer
=
4478 PictureLayer::Create(layer_settings_
, &client
);
4479 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4480 TestTaskGraphRunner task_graph_runner
;
4481 scoped_ptr
<FakeLayerTreeHost
> host
=
4482 FakeLayerTreeHost::Create(&host_client
, &task_graph_runner
);
4483 host
->SetRootLayer(layer
);
4484 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4486 int frame_number
= 0;
4488 client
.set_fill_with_nonsolid_color(!test_for_solid
);
4490 Region
invalidation(layer_rect
);
4491 recording_source
->UpdateAndExpandInvalidation(
4492 &client
, &invalidation
, layer_bounds
, layer_rect
, frame_number
++,
4493 RecordingSource::RECORD_NORMALLY
);
4495 scoped_refptr
<RasterSource
> pending_raster_source
=
4496 recording_source
->CreateRasterSource(true);
4498 SetupPendingTreeWithFixedTileSize(pending_raster_source
, tile_size
, Region());
4501 if (test_for_solid
) {
4502 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4504 ASSERT_TRUE(active_layer_
->tilings());
4505 ASSERT_GT(active_layer_
->tilings()->num_tilings(), 0u);
4506 std::vector
<Tile
*> tiles
=
4507 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
4508 EXPECT_FALSE(tiles
.empty());
4509 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4512 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
4513 AppendQuadsData data
;
4514 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
4515 active_layer_
->AppendQuads(render_pass
.get(), &data
);
4516 active_layer_
->DidDraw(nullptr);
4518 DrawQuad::Material expected
= test_for_solid
4519 ? DrawQuad::Material::SOLID_COLOR
4520 : DrawQuad::Material::TILED_CONTENT
;
4521 EXPECT_EQ(expected
, render_pass
->quad_list
.front()->material
);
4524 TEST_F(PictureLayerImplTest
, DrawSolidQuads
) {
4525 TestQuadsForSolidColor(true);
4528 TEST_F(PictureLayerImplTest
, DrawNonSolidQuads
) {
4529 TestQuadsForSolidColor(false);
4532 TEST_F(PictureLayerImplTest
, NonSolidToSolidNoTilings
) {
4533 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4535 gfx::Size
tile_size(100, 100);
4536 gfx::Size
layer_bounds(200, 200);
4537 gfx::Rect
layer_rect(layer_bounds
);
4539 FakeContentLayerClient client
;
4540 scoped_refptr
<PictureLayer
> layer
=
4541 PictureLayer::Create(layer_settings_
, &client
);
4542 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4543 TestTaskGraphRunner task_graph_runner
;
4544 scoped_ptr
<FakeLayerTreeHost
> host
=
4545 FakeLayerTreeHost::Create(&host_client
, &task_graph_runner
);
4546 host
->SetRootLayer(layer
);
4547 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4549 int frame_number
= 0;
4551 client
.set_fill_with_nonsolid_color(true);
4553 Region
invalidation1(layer_rect
);
4554 recording_source
->UpdateAndExpandInvalidation(
4555 &client
, &invalidation1
, layer_bounds
, layer_rect
, frame_number
++,
4556 RecordingSource::RECORD_NORMALLY
);
4558 scoped_refptr
<RasterSource
> raster_source1
=
4559 recording_source
->CreateRasterSource(true);
4561 SetupPendingTree(raster_source1
);
4563 bool update_lcd_text
= false;
4564 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
4566 // We've started with a solid layer that contains some tilings.
4567 ASSERT_TRUE(active_layer_
->tilings());
4568 EXPECT_NE(0u, active_layer_
->tilings()->num_tilings());
4570 client
.set_fill_with_nonsolid_color(false);
4572 Region
invalidation2(layer_rect
);
4573 recording_source
->UpdateAndExpandInvalidation(
4574 &client
, &invalidation2
, layer_bounds
, layer_rect
, frame_number
++,
4575 RecordingSource::RECORD_NORMALLY
);
4577 scoped_refptr
<RasterSource
> raster_source2
=
4578 recording_source
->CreateRasterSource(true);
4580 SetupPendingTree(raster_source2
);
4583 // We've switched to a solid color, so we should end up with no tilings.
4584 ASSERT_TRUE(active_layer_
->tilings());
4585 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4588 TEST_F(PictureLayerImplTest
, ChangeInViewportAllowsTilingUpdates
) {
4589 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4591 gfx::Size
tile_size(100, 100);
4592 gfx::Size
layer_bounds(400, 4000);
4594 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4595 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4596 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4597 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4599 SetupTrees(pending_pile
, active_pile
);
4601 Region invalidation
;
4602 gfx::Rect viewport
= gfx::Rect(0, 0, 100, 100);
4603 gfx::Transform transform
;
4605 host_impl_
.SetRequiresHighResToDraw();
4608 pending_layer_
->draw_properties().visible_layer_rect
= viewport
;
4609 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4610 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
4612 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
4614 // Ensure we can't activate.
4615 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
4617 // Now in the same frame, move the viewport (this can happen during
4619 viewport
= gfx::Rect(0, 2000, 100, 100);
4622 pending_layer_
->draw_properties().visible_layer_rect
= viewport
;
4623 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4624 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
4626 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
4628 // Make sure all viewport tiles (viewport from the tiling) are ready to draw.
4629 std::vector
<Tile
*> tiles
;
4630 for (PictureLayerTiling::CoverageIterator
iter(
4631 pending_layer_
->HighResTiling(),
4633 pending_layer_
->HighResTiling()->GetCurrentVisibleRectForTesting());
4637 tiles
.push_back(*iter
);
4639 for (PictureLayerTiling::CoverageIterator
iter(
4640 active_layer_
->HighResTiling(), 1.f
,
4641 active_layer_
->HighResTiling()->GetCurrentVisibleRectForTesting());
4644 tiles
.push_back(*iter
);
4647 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4649 // Ensure we can activate.
4650 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
4653 TEST_F(PictureLayerImplTest
, CloneMissingRecordings
) {
4654 gfx::Size
tile_size(100, 100);
4655 gfx::Size
layer_bounds(400, 400);
4657 scoped_refptr
<FakePicturePileImpl
> filled_pile
=
4658 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4660 scoped_ptr
<FakePicturePile
> partial_recording
=
4661 FakePicturePile::CreateEmptyPile(tile_size
, layer_bounds
);
4662 for (int i
= 1; i
< partial_recording
->tiling().num_tiles_x(); ++i
) {
4663 for (int j
= 1; j
< partial_recording
->tiling().num_tiles_y(); ++j
)
4664 partial_recording
->AddRecordingAt(i
, j
);
4666 scoped_refptr
<FakePicturePileImpl
> partial_pile
=
4667 FakePicturePileImpl::CreateFromPile(partial_recording
.get(), nullptr);
4669 SetupPendingTreeWithFixedTileSize(filled_pile
, tile_size
, Region());
4672 PictureLayerTiling
* pending_tiling
= old_pending_layer_
->HighResTiling();
4673 PictureLayerTiling
* active_tiling
= active_layer_
->HighResTiling();
4675 // We should have all tiles on active, and none on pending.
4676 EXPECT_EQ(0u, pending_tiling
->AllTilesForTesting().size());
4677 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4679 // Now put a partially-recorded pile on the pending tree (and invalidate
4680 // everything, since the main thread PicturePile will invalidate dropped
4681 // recordings). This will cause us to be missing some tiles.
4682 SetupPendingTreeWithFixedTileSize(partial_pile
, tile_size
,
4683 Region(gfx::Rect(layer_bounds
)));
4684 EXPECT_EQ(3u * 3u, pending_tiling
->AllTilesForTesting().size());
4685 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
4686 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
4687 EXPECT_TRUE(pending_tiling
->TileAt(2, 2));
4689 // Active is not affected yet.
4690 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4692 // Activate the tree. The same tiles go missing on the active tree.
4694 EXPECT_EQ(3u * 3u, active_tiling
->AllTilesForTesting().size());
4695 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
4696 EXPECT_FALSE(active_tiling
->TileAt(1, 1));
4697 EXPECT_TRUE(active_tiling
->TileAt(2, 2));
4699 // Now put a full recording on the pending tree again. We'll get all our tiles
4701 SetupPendingTreeWithFixedTileSize(filled_pile
, tile_size
,
4702 Region(gfx::Rect(layer_bounds
)));
4703 EXPECT_EQ(5u * 5u, pending_tiling
->AllTilesForTesting().size());
4704 Tile
* tile00
= pending_tiling
->TileAt(0, 0);
4705 Tile
* tile11
= pending_tiling
->TileAt(1, 1);
4706 Tile
* tile22
= pending_tiling
->TileAt(2, 2);
4708 // Active is not affected yet.
4709 EXPECT_EQ(3u * 3u, active_tiling
->AllTilesForTesting().size());
4711 // Activate the tree. The tiles are moved to the active tree.
4713 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4714 EXPECT_EQ(tile00
, active_tiling
->TileAt(0, 0));
4715 EXPECT_EQ(tile11
, active_tiling
->TileAt(1, 1));
4716 EXPECT_EQ(tile22
, active_tiling
->TileAt(2, 2));
4719 TEST_F(PictureLayerImplTest
, ScrollPastLiveTilesRectAndBack
) {
4720 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4722 gfx::Size
tile_size(102, 102);
4723 gfx::Size
layer_bounds(100, 100);
4724 gfx::Size
viewport_size(100, 100);
4726 host_impl_
.SetViewportSize(viewport_size
);
4727 host_impl_
.SetDeviceScaleFactor(1.f
);
4729 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4730 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4731 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4732 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4734 SetupPendingTreeWithFixedTileSize(active_pile
, tile_size
, Region());
4737 EXPECT_TRUE(active_layer_
->HighResTiling()->has_tiles());
4739 host_impl_
.SetExternalDrawConstraints(
4740 gfx::Transform(), // transform
4741 gfx::Rect(), // clip
4742 gfx::Rect(), // viewport
4743 gfx::Rect(0, 1000, 100, 100), // viewport_rect_for_tile_priority
4744 gfx::Transform(), // transform_for_tile_priority
4747 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, gfx::Rect());
4749 EXPECT_FALSE(pending_layer_
->HighResTiling()->has_tiles());
4750 EXPECT_TRUE(pending_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4752 EXPECT_FALSE(active_layer_
->HighResTiling()->has_tiles());
4753 EXPECT_TRUE(active_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4755 host_impl_
.SetExternalDrawConstraints(
4756 gfx::Transform(), // transform
4757 gfx::Rect(), // clip
4758 gfx::Rect(), // viewport
4759 gfx::Rect(0, 110, 100, 100), // viewport_rect_for_tile_priority
4760 gfx::Transform(), // transform_for_tile_priority
4763 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, gfx::Rect());
4765 EXPECT_FALSE(pending_layer_
->HighResTiling()->has_tiles());
4766 EXPECT_FALSE(pending_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4768 EXPECT_TRUE(active_layer_
->HighResTiling()->has_tiles());
4769 EXPECT_FALSE(active_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4772 TEST_F(PictureLayerImplTest
, ScrollPropagatesToPending
) {
4773 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4775 gfx::Size
tile_size(102, 102);
4776 gfx::Size
layer_bounds(1000, 1000);
4777 gfx::Size
viewport_size(100, 100);
4779 host_impl_
.SetViewportSize(viewport_size
);
4780 host_impl_
.SetDeviceScaleFactor(1.f
);
4782 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4783 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4784 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4785 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4787 SetupTrees(pending_pile
, active_pile
);
4789 active_layer_
->SetCurrentScrollOffset(gfx::ScrollOffset(0.0, 50.0));
4790 host_impl_
.active_tree()->UpdateDrawProperties(false);
4791 EXPECT_EQ("0,50 100x100", active_layer_
->HighResTiling()
4792 ->GetCurrentVisibleRectForTesting()
4795 EXPECT_EQ("0,0 100x100", pending_layer_
->HighResTiling()
4796 ->GetCurrentVisibleRectForTesting()
4798 host_impl_
.pending_tree()->UpdateDrawProperties(false);
4799 EXPECT_EQ("0,50 100x100", pending_layer_
->HighResTiling()
4800 ->GetCurrentVisibleRectForTesting()
4804 TEST_F(PictureLayerImplTest
, UpdateLCDInvalidatesPendingTree
) {
4805 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4807 gfx::Size
tile_size(102, 102);
4808 gfx::Size
layer_bounds(100, 100);
4809 gfx::Size
viewport_size(100, 100);
4811 host_impl_
.SetViewportSize(viewport_size
);
4812 host_impl_
.SetDeviceScaleFactor(1.f
);
4814 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4815 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4816 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4818 EXPECT_TRUE(pending_layer_
->RasterSourceUsesLCDText());
4819 EXPECT_TRUE(pending_layer_
->HighResTiling()->has_tiles());
4820 std::vector
<Tile
*> tiles
=
4821 pending_layer_
->HighResTiling()->AllTilesForTesting();
4822 auto prioritized_tiles
= pending_layer_
->HighResTiling()
4823 ->UpdateAndGetAllPrioritizedTilesForTesting();
4825 for (Tile
* tile
: tiles
)
4826 EXPECT_EQ(pending_layer_
->raster_source(),
4827 prioritized_tiles
[tile
].raster_source());
4829 pending_layer_
->draw_properties().can_use_lcd_text
= false;
4830 pending_layer_
->UpdateCanUseLCDTextAfterCommit();
4832 EXPECT_FALSE(pending_layer_
->RasterSourceUsesLCDText());
4833 EXPECT_NE(pending_pile
.get(), pending_layer_
->raster_source());
4834 EXPECT_TRUE(pending_layer_
->HighResTiling()->has_tiles());
4835 tiles
= pending_layer_
->HighResTiling()->AllTilesForTesting();
4836 prioritized_tiles
= pending_layer_
->HighResTiling()
4837 ->UpdateAndGetAllPrioritizedTilesForTesting();
4838 for (Tile
* tile
: tiles
)
4839 EXPECT_EQ(pending_layer_
->raster_source(),
4840 prioritized_tiles
[tile
].raster_source());
4843 TEST_F(PictureLayerImplTest
, TilingAllTilesDone
) {
4844 gfx::Size tile_size
= host_impl_
.settings().default_tile_size
;
4845 size_t tile_mem
= 4 * tile_size
.width() * tile_size
.height();
4846 gfx::Size
layer_bounds(1000, 1000);
4849 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4850 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4851 SetupPendingTree(pending_pile
);
4852 pending_layer_
->SetBounds(layer_bounds
);
4854 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
4855 active_layer_
->HighResTiling()->AllTilesForTesting());
4856 host_impl_
.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES
);
4858 EXPECT_FALSE(active_layer_
->HighResTiling()->all_tiles_done());
4861 // Set a memory policy that will fit all tiles.
4862 size_t max_tiles
= 16;
4863 size_t memory_limit
= max_tiles
* tile_mem
;
4864 ManagedMemoryPolicy
policy(memory_limit
,
4865 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
,
4867 host_impl_
.SetMemoryPolicy(policy
);
4868 host_impl_
.PrepareTiles();
4870 EXPECT_TRUE(active_layer_
->HighResTiling()->all_tiles_done());
4874 // Set a memory policy that will cause tile eviction.
4875 size_t max_tiles
= 1;
4876 size_t memory_limit
= max_tiles
* tile_mem
;
4877 ManagedMemoryPolicy
policy(memory_limit
,
4878 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
,
4880 host_impl_
.SetMemoryPolicy(policy
);
4881 host_impl_
.PrepareTiles();
4883 EXPECT_FALSE(active_layer_
->HighResTiling()->all_tiles_done());
4887 class TileSizeSettings
: public GpuRasterizationEnabledSettings
{
4889 TileSizeSettings() {
4890 default_tile_size
= gfx::Size(100, 100);
4891 max_untiled_layer_size
= gfx::Size(200, 200);
4895 class TileSizeTest
: public PictureLayerImplTest
{
4897 TileSizeTest() : PictureLayerImplTest(TileSizeSettings()) {}
4900 TEST_F(TileSizeTest
, TileSizes
) {
4901 host_impl_
.CreatePendingTree();
4903 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
4904 scoped_ptr
<FakePictureLayerImpl
> layer
=
4905 FakePictureLayerImpl::Create(pending_tree
, id_
);
4907 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
4910 host_impl_
.SetContentIsSuitableForGpuRasterization(true);
4911 host_impl_
.SetHasGpuRasterizationTrigger(false);
4912 EXPECT_EQ(host_impl_
.gpu_rasterization_status(),
4913 GpuRasterizationStatus::OFF_VIEWPORT
);
4915 // Default tile-size for large layers.
4916 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
4917 EXPECT_EQ(result
.width(), 100);
4918 EXPECT_EQ(result
.height(), 100);
4919 // Don't tile and round-up, when under max_untiled_layer_size.
4920 result
= layer
->CalculateTileSize(gfx::Size(42, 42));
4921 EXPECT_EQ(result
.width(), 64);
4922 EXPECT_EQ(result
.height(), 64);
4923 result
= layer
->CalculateTileSize(gfx::Size(191, 191));
4924 EXPECT_EQ(result
.width(), 192);
4925 EXPECT_EQ(result
.height(), 192);
4926 result
= layer
->CalculateTileSize(gfx::Size(199, 199));
4927 EXPECT_EQ(result
.width(), 200);
4928 EXPECT_EQ(result
.height(), 200);
4930 // Gpu-rasterization uses 25% viewport-height tiles.
4931 // The +2's below are for border texels.
4932 host_impl_
.SetHasGpuRasterizationTrigger(true);
4933 EXPECT_EQ(host_impl_
.gpu_rasterization_status(), GpuRasterizationStatus::ON
);
4934 host_impl_
.SetViewportSize(gfx::Size(2000, 2000));
4936 layer
->set_gpu_raster_max_texture_size(host_impl_
.device_viewport_size());
4937 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
4938 EXPECT_EQ(result
.width(), 2000 + 2 * PictureLayerTiling::kBorderTexels
);
4939 EXPECT_EQ(result
.height(), 500 + 2);
4941 // Clamp and round-up, when smaller than viewport.
4942 // Tile-height doubles to 50% when width shrinks to <= 50%.
4943 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
4944 layer
->set_gpu_raster_max_texture_size(host_impl_
.device_viewport_size());
4945 result
= layer
->CalculateTileSize(gfx::Size(447, 10000));
4946 EXPECT_EQ(result
.width(), 448);
4947 EXPECT_EQ(result
.height(), 500 + 2);
4949 // Largest layer is 50% of viewport width (rounded up), and
4950 // 50% of viewport in height.
4951 result
= layer
->CalculateTileSize(gfx::Size(447, 400));
4952 EXPECT_EQ(result
.width(), 448);
4953 EXPECT_EQ(result
.height(), 448);
4954 result
= layer
->CalculateTileSize(gfx::Size(500, 499));
4955 EXPECT_EQ(result
.width(), 512);
4956 EXPECT_EQ(result
.height(), 500 + 2);