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/resources/tiling_set_raster_queue_all.h"
20 #include "cc/resources/tiling_set_raster_queue_required.h"
21 #include "cc/test/begin_frame_args_test.h"
22 #include "cc/test/fake_content_layer_client.h"
23 #include "cc/test/fake_impl_proxy.h"
24 #include "cc/test/fake_layer_tree_host_impl.h"
25 #include "cc/test/fake_output_surface.h"
26 #include "cc/test/fake_picture_layer_impl.h"
27 #include "cc/test/fake_picture_pile_impl.h"
28 #include "cc/test/geometry_test_utils.h"
29 #include "cc/test/impl_side_painting_settings.h"
30 #include "cc/test/layer_test_common.h"
31 #include "cc/test/test_shared_bitmap_manager.h"
32 #include "cc/test/test_task_graph_runner.h"
33 #include "cc/test/test_web_graphics_context_3d.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 ImplSidePaintingSettings
{};
68 class LowResTilingsSettings
: public ImplSidePaintingSettings
{
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
->SetContentBounds(raster_source
->GetSize());
227 pending_layer
->SetRasterSourceOnPending(raster_source
, invalidation
);
229 pending_root
->AddChild(pending_layer
.Pass());
230 pending_tree
->SetRootLayer(pending_root
.Pass());
232 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
233 host_impl_
.pending_tree()->LayerById(id_
));
235 // Add tilings/tiles for the layer.
236 bool update_lcd_text
= false;
237 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
240 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl
* layer
,
241 float ideal_contents_scale
,
242 float device_scale_factor
,
243 float page_scale_factor
,
244 float maximum_animation_contents_scale
,
245 bool animating_transform_to_screen
) {
246 layer
->draw_properties().ideal_contents_scale
= ideal_contents_scale
;
247 layer
->draw_properties().device_scale_factor
= device_scale_factor
;
248 layer
->draw_properties().page_scale_factor
= page_scale_factor
;
249 layer
->draw_properties().maximum_animation_contents_scale
=
250 maximum_animation_contents_scale
;
251 layer
->draw_properties().screen_space_transform_is_animating
=
252 animating_transform_to_screen
;
253 bool resourceless_software_draw
= false;
254 layer
->UpdateTiles(resourceless_software_draw
);
256 static void VerifyAllTilesExistAndHavePile(
257 const PictureLayerTiling
* tiling
,
258 PicturePileImpl
* pile
) {
259 for (PictureLayerTiling::CoverageIterator
iter(
261 tiling
->contents_scale(),
262 gfx::Rect(tiling
->tiling_size()));
266 EXPECT_EQ(pile
, iter
->raster_source());
270 void SetContentsScaleOnBothLayers(float contents_scale
,
271 float device_scale_factor
,
272 float page_scale_factor
,
273 float maximum_animation_contents_scale
,
274 bool animating_transform
) {
275 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
279 maximum_animation_contents_scale
,
280 animating_transform
);
282 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
286 maximum_animation_contents_scale
,
287 animating_transform
);
290 void ResetTilingsAndRasterScales() {
291 pending_layer_
->ReleaseResources();
292 EXPECT_FALSE(pending_layer_
->tilings());
293 pending_layer_
->RecreateResources();
294 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
296 active_layer_
->ReleaseResources();
297 EXPECT_FALSE(active_layer_
->tilings());
298 active_layer_
->RecreateResources();
299 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
302 size_t NumberOfTilesRequired(PictureLayerTiling
* tiling
) {
303 size_t num_required
= 0;
304 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
305 for (size_t i
= 0; i
< tiles
.size(); ++i
) {
306 if (tiles
[i
]->required_for_activation())
312 void AssertAllTilesRequired(PictureLayerTiling
* tiling
) {
313 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
314 for (size_t i
= 0; i
< tiles
.size(); ++i
)
315 EXPECT_TRUE(tiles
[i
]->required_for_activation()) << "i: " << i
;
316 EXPECT_GT(tiles
.size(), 0u);
319 void AssertNoTilesRequired(PictureLayerTiling
* tiling
) {
320 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
321 for (size_t i
= 0; i
< tiles
.size(); ++i
)
322 EXPECT_FALSE(tiles
[i
]->required_for_activation()) << "i: " << i
;
323 EXPECT_GT(tiles
.size(), 0u);
327 void TestQuadsForSolidColor(bool test_for_solid
);
329 FakeImplProxy proxy_
;
330 TestSharedBitmapManager shared_bitmap_manager_
;
331 TestTaskGraphRunner task_graph_runner_
;
332 FakeLayerTreeHostImpl host_impl_
;
335 FakePictureLayerImpl
* pending_layer_
;
336 FakePictureLayerImpl
* old_pending_layer_
;
337 FakePictureLayerImpl
* active_layer_
;
340 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest
);
343 class NoLowResPictureLayerImplTest
: public PictureLayerImplTest
{
345 NoLowResPictureLayerImplTest()
346 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
349 TEST_F(PictureLayerImplTest
, TileGridAlignment
) {
350 // Layer to span 4 raster tiles in x and in y
351 ImplSidePaintingSettings settings
;
352 gfx::Size
layer_size(settings
.default_tile_size
.width() * 7 / 2,
353 settings
.default_tile_size
.height() * 7 / 2);
355 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
356 FakePicturePileImpl::CreateFilledPile(layer_size
, layer_size
);
358 scoped_ptr
<FakePicturePile
> active_recording
=
359 FakePicturePile::CreateFilledPile(layer_size
, layer_size
);
360 scoped_refptr
<FakePicturePileImpl
> active_pile
=
361 FakePicturePileImpl::CreateFromPile(active_recording
.get(), nullptr);
363 SetupTrees(pending_pile
, active_pile
);
365 // Add 1x1 rects at the centers of each tile, then re-record pile contents
366 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
367 std::vector
<Tile
*> tiles
=
368 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
369 EXPECT_EQ(16u, tiles
.size());
370 std::vector
<SkRect
> rects
;
371 std::vector
<Tile
*>::const_iterator tile_iter
;
372 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
373 gfx::Point tile_center
= (*tile_iter
)->content_rect().CenterPoint();
374 gfx::Rect
rect(tile_center
.x(), tile_center
.y(), 1, 1);
375 active_recording
->add_draw_rect(rect
);
376 rects
.push_back(SkRect::MakeXYWH(rect
.x(), rect
.y(), 1, 1));
379 // Force re-raster with newly injected content
380 active_recording
->RemoveRecordingAt(0, 0);
381 active_recording
->AddRecordingAt(0, 0);
383 scoped_refptr
<FakePicturePileImpl
> updated_active_pile
=
384 FakePicturePileImpl::CreateFromPile(active_recording
.get(), nullptr);
386 std::vector
<SkRect
>::const_iterator rect_iter
= rects
.begin();
387 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
388 MockCanvas
mock_canvas(1000, 1000);
389 updated_active_pile
->PlaybackToSharedCanvas(
390 &mock_canvas
, (*tile_iter
)->content_rect(), 1.0f
);
392 // This test verifies that when drawing the contents of a specific tile
393 // at content scale 1.0, the playback canvas never receives content from
394 // neighboring tiles which indicates that the tile grid embedded in
395 // SkPicture is perfectly aligned with the compositor's tiles.
396 EXPECT_EQ(1u, mock_canvas
.rects_
.size());
397 EXPECT_EQ(*rect_iter
, mock_canvas
.rects_
[0]);
402 TEST_F(PictureLayerImplTest
, CloneNoInvalidation
) {
403 gfx::Size
tile_size(100, 100);
404 gfx::Size
layer_bounds(400, 400);
406 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
407 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
408 scoped_refptr
<FakePicturePileImpl
> active_pile
=
409 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
411 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
413 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
414 active_layer_
->tilings()->num_tilings());
416 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
417 EXPECT_GT(tilings
->num_tilings(), 0u);
418 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
419 VerifyAllTilesExistAndHavePile(tilings
->tiling_at(i
), pending_pile
.get());
422 TEST_F(PictureLayerImplTest
, ExternalViewportRectForPrioritizingTiles
) {
423 base::TimeTicks time_ticks
;
424 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
425 host_impl_
.SetCurrentBeginFrameArgs(
426 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
427 gfx::Size
tile_size(100, 100);
428 gfx::Size
layer_bounds(400, 400);
430 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
431 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
432 scoped_refptr
<FakePicturePileImpl
> active_pile
=
433 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
435 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
437 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
439 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
440 host_impl_
.SetCurrentBeginFrameArgs(
441 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
443 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the
444 // identify transform for tile priority.
445 bool resourceless_software_draw
= false;
446 gfx::Rect viewport
= gfx::Rect(layer_bounds
),
447 viewport_rect_for_tile_priority
= gfx::Rect(0, 0, 100, 100);
448 gfx::Transform transform
, transform_for_tile_priority
;
450 host_impl_
.SetExternalDrawConstraints(transform
,
453 viewport_rect_for_tile_priority
,
454 transform_for_tile_priority
,
455 resourceless_software_draw
);
456 bool update_lcd_text
= false;
457 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
459 gfx::Rect viewport_rect_for_tile_priority_in_view_space
=
460 viewport_rect_for_tile_priority
;
462 // Verify the viewport rect for tile priority is used in picture layer tiling.
463 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
464 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
465 PictureLayerTilingSet
* tilings
= active_layer_
->tilings();
466 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
467 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
469 tiling
->GetCurrentVisibleRectForTesting(),
470 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
471 tiling
->contents_scale()));
474 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in
475 // screen space and the transform for tile priority is translated and
476 // rotated. The actual viewport for tile priority used by PictureLayerImpl
477 // should be (200, 200, 100, 100) applied with the said transform.
478 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
479 host_impl_
.SetCurrentBeginFrameArgs(
480 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
482 viewport_rect_for_tile_priority
= gfx::Rect(200, 200, 100, 100);
483 transform_for_tile_priority
.Translate(100, 100);
484 transform_for_tile_priority
.Rotate(45);
485 host_impl_
.SetExternalDrawConstraints(transform
,
488 viewport_rect_for_tile_priority
,
489 transform_for_tile_priority
,
490 resourceless_software_draw
);
491 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
493 gfx::Transform
screen_to_view(gfx::Transform::kSkipInitialization
);
494 bool success
= transform_for_tile_priority
.GetInverse(&screen_to_view
);
495 EXPECT_TRUE(success
);
497 // Note that we don't clip this to the layer bounds, since it is expected that
498 // the rect will sometimes be outside of the layer bounds. If we clip to
499 // bounds, then tile priorities will end up being incorrect in cases of fully
501 viewport_rect_for_tile_priority_in_view_space
=
502 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
503 screen_to_view
, viewport_rect_for_tile_priority
));
505 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
506 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
507 tilings
= active_layer_
->tilings();
508 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
509 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
511 tiling
->GetCurrentVisibleRectForTesting(),
512 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
513 tiling
->contents_scale()));
517 TEST_F(PictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
518 base::TimeTicks time_ticks
;
519 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
520 host_impl_
.SetCurrentBeginFrameArgs(
521 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
523 gfx::Size
tile_size(100, 100);
524 gfx::Size
layer_bounds(400, 400);
526 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
527 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
528 scoped_refptr
<FakePicturePileImpl
> active_pile
=
529 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
531 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
533 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
535 // UpdateTiles with valid viewport. Should update tile viewport.
536 // Note viewport is considered invalid if and only if in resourceless
538 bool resourceless_software_draw
= false;
539 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
540 gfx::Transform transform
;
541 host_impl_
.SetExternalDrawConstraints(transform
,
546 resourceless_software_draw
);
547 active_layer_
->draw_properties().visible_content_rect
= viewport
;
548 active_layer_
->draw_properties().screen_space_transform
= transform
;
549 active_layer_
->UpdateTiles(resourceless_software_draw
);
551 gfx::Rect visible_rect_for_tile_priority
=
552 active_layer_
->visible_rect_for_tile_priority();
553 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
554 gfx::Transform screen_space_transform_for_tile_priority
=
555 active_layer_
->screen_space_transform();
557 // Expand viewport and set it as invalid for prioritizing tiles.
558 // Should update viewport and transform, but not update visible rect.
559 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
560 host_impl_
.SetCurrentBeginFrameArgs(
561 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
562 resourceless_software_draw
= true;
563 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
564 transform
.Translate(1.f
, 1.f
);
565 active_layer_
->draw_properties().visible_content_rect
= viewport
;
566 active_layer_
->draw_properties().screen_space_transform
= transform
;
567 host_impl_
.SetExternalDrawConstraints(transform
,
572 resourceless_software_draw
);
573 active_layer_
->UpdateTiles(resourceless_software_draw
);
575 // Transform for tile priority is updated.
576 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
577 active_layer_
->screen_space_transform());
578 // Visible rect for tile priority retains old value.
579 EXPECT_EQ(visible_rect_for_tile_priority
,
580 active_layer_
->visible_rect_for_tile_priority());
582 // Keep expanded viewport but mark it valid. Should update tile viewport.
583 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
584 host_impl_
.SetCurrentBeginFrameArgs(
585 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
586 resourceless_software_draw
= false;
587 host_impl_
.SetExternalDrawConstraints(transform
,
592 resourceless_software_draw
);
593 active_layer_
->UpdateTiles(resourceless_software_draw
);
595 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
596 active_layer_
->screen_space_transform());
597 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
600 TEST_F(PictureLayerImplTest
, ViewportRectForTilePriorityIsCached
) {
601 base::TimeTicks time_ticks
;
602 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
603 host_impl_
.SetCurrentBeginFrameArgs(
604 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
605 gfx::Size
tile_size(100, 100);
606 gfx::Size
layer_bounds(400, 400);
608 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
609 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
610 scoped_refptr
<FakePicturePileImpl
> active_pile
=
611 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
613 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
615 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
617 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
618 host_impl_
.SetCurrentBeginFrameArgs(
619 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
621 bool resourceless_software_draw
= false;
622 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
623 gfx::Rect
viewport_rect_for_tile_priority(0, 0, 100, 100);
624 gfx::Transform transform
, transform_for_tile_priority
;
626 host_impl_
.SetExternalDrawConstraints(
627 transform
, viewport
, viewport
, viewport_rect_for_tile_priority
,
628 transform_for_tile_priority
, resourceless_software_draw
);
629 bool update_lcd_text
= false;
630 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
632 EXPECT_EQ(viewport_rect_for_tile_priority
,
633 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
635 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
636 host_impl_
.SetCurrentBeginFrameArgs(
637 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
639 gfx::Rect
another_viewport_rect_for_tile_priority(11, 11, 50, 50);
640 host_impl_
.SetExternalDrawConstraints(
641 transform
, viewport
, viewport
, another_viewport_rect_for_tile_priority
,
642 transform_for_tile_priority
, resourceless_software_draw
);
644 // Didn't call UpdateDrawProperties yet. The viewport rect for tile priority
645 // should remain to be the previously cached value.
646 EXPECT_EQ(viewport_rect_for_tile_priority
,
647 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
648 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
650 // Now the UpdateDrawProperties is called. The viewport rect for tile
651 // priority should be the latest value.
652 EXPECT_EQ(another_viewport_rect_for_tile_priority
,
653 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
656 TEST_F(PictureLayerImplTest
, ClonePartialInvalidation
) {
657 gfx::Size
tile_size(100, 100);
658 gfx::Size
layer_bounds(400, 400);
659 gfx::Rect
layer_invalidation(150, 200, 30, 180);
661 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
662 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
663 scoped_refptr
<FakePicturePileImpl
> active_pile
=
664 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
665 scoped_refptr
<FakePicturePileImpl
> lost_pile
=
666 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
668 SetupPendingTreeWithFixedTileSize(lost_pile
, gfx::Size(50, 50), Region());
670 // Add a non-shared tiling on the active tree.
671 PictureLayerTiling
* tiling
= active_layer_
->AddTiling(3.f
);
672 tiling
->CreateAllTilesForTesting();
674 // Ensure UpdateTiles won't remove any tilings.
675 active_layer_
->MarkAllTilingsUsed();
677 // Then setup a new pending tree and activate it.
678 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, gfx::Size(50, 50),
681 EXPECT_EQ(2u, pending_layer_
->num_tilings());
682 EXPECT_EQ(3u, active_layer_
->num_tilings());
684 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
685 EXPECT_GT(tilings
->num_tilings(), 0u);
686 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
687 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
688 gfx::Rect content_invalidation
= gfx::ScaleToEnclosingRect(
690 tiling
->contents_scale());
691 for (PictureLayerTiling::CoverageIterator
iter(
693 tiling
->contents_scale(),
694 gfx::Rect(tiling
->tiling_size()));
698 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
699 EXPECT_EQ(pending_pile
.get(), iter
->raster_source());
703 tilings
= active_layer_
->tilings();
704 EXPECT_GT(tilings
->num_tilings(), 0u);
705 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
706 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
707 gfx::Rect content_invalidation
=
708 gfx::ScaleToEnclosingRect(layer_invalidation
, tiling
->contents_scale());
709 for (PictureLayerTiling::CoverageIterator
iter(
711 tiling
->contents_scale(),
712 gfx::Rect(tiling
->tiling_size()));
716 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
717 if (iter
.geometry_rect().Intersects(content_invalidation
))
718 EXPECT_EQ(active_pile
.get(), iter
->raster_source());
719 else if (!active_layer_
->GetPendingOrActiveTwinTiling(tiling
))
720 EXPECT_EQ(active_pile
.get(), iter
->raster_source());
722 EXPECT_EQ(pending_pile
.get(), iter
->raster_source());
727 TEST_F(PictureLayerImplTest
, CloneFullInvalidation
) {
728 gfx::Size
tile_size(90, 80);
729 gfx::Size
layer_bounds(300, 500);
731 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
732 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
733 scoped_refptr
<FakePicturePileImpl
> active_pile
=
734 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
736 SetupTreesWithInvalidation(pending_pile
, active_pile
,
737 gfx::Rect(layer_bounds
));
739 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
740 active_layer_
->tilings()->num_tilings());
742 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
743 EXPECT_GT(tilings
->num_tilings(), 0u);
744 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
745 VerifyAllTilesExistAndHavePile(tilings
->tiling_at(i
), pending_pile
.get());
748 TEST_F(PictureLayerImplTest
, UpdateTilesCreatesTilings
) {
749 gfx::Size
tile_size(400, 400);
750 gfx::Size
layer_bounds(1300, 1900);
752 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
753 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
754 scoped_refptr
<FakePicturePileImpl
> active_pile
=
755 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
757 SetupTrees(pending_pile
, active_pile
);
759 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
760 EXPECT_LT(low_res_factor
, 1.f
);
762 active_layer_
->ReleaseResources();
763 EXPECT_FALSE(active_layer_
->tilings());
764 active_layer_
->RecreateResources();
765 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
767 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
768 6.f
, // ideal contents scale
771 1.f
, // maximum animation scale
773 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
775 active_layer_
->tilings()->tiling_at(0)->contents_scale());
776 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
777 active_layer_
->tilings()->tiling_at(1)->contents_scale());
779 // If we change the page scale factor, then we should get new tilings.
780 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
781 6.6f
, // ideal contents scale
784 1.f
, // maximum animation scale
786 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
787 EXPECT_FLOAT_EQ(6.6f
,
788 active_layer_
->tilings()->tiling_at(0)->contents_scale());
789 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
790 active_layer_
->tilings()->tiling_at(2)->contents_scale());
792 // If we change the device scale factor, then we should get new tilings.
793 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
794 7.26f
, // ideal contents scale
795 3.3f
, // device scale
797 1.f
, // maximum 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
813 ASSERT_EQ(6u, active_layer_
->tilings()->num_tilings());
814 EXPECT_FLOAT_EQ(7.26f
,
815 active_layer_
->tilings()->tiling_at(0)->contents_scale());
816 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
817 active_layer_
->tilings()->tiling_at(3)->contents_scale());
820 TEST_F(PictureLayerImplTest
, PendingLayerOnlyHasHighAndLowResTiling
) {
821 gfx::Size
tile_size(400, 400);
822 gfx::Size
layer_bounds(1300, 1900);
824 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
825 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
826 scoped_refptr
<FakePicturePileImpl
> active_pile
=
827 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
829 SetupTrees(pending_pile
, active_pile
);
831 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
832 EXPECT_LT(low_res_factor
, 1.f
);
834 pending_layer_
->ReleaseResources();
835 EXPECT_FALSE(pending_layer_
->tilings());
836 pending_layer_
->RecreateResources();
837 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
839 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
840 6.f
, // ideal contents scale
843 1.f
, // maximum animation scale
845 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
847 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
848 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
849 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
851 // If we change the page scale factor, then we should get new tilings.
852 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
853 6.6f
, // ideal contents scale
856 1.f
, // maximum animation scale
858 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
859 EXPECT_FLOAT_EQ(6.6f
,
860 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
861 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
862 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
864 // If we change the device scale factor, then we should get new tilings.
865 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
866 7.26f
, // ideal contents scale
867 3.3f
, // device scale
869 1.f
, // maximum animation scale
871 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
872 EXPECT_FLOAT_EQ(7.26f
,
873 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
874 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
875 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
877 // If we change the device scale factor, but end up at the same total scale
878 // factor somehow, then we don't get new tilings.
879 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
880 7.26f
, // ideal contents scale
881 2.2f
, // device scale
883 1.f
, // maximum animation scale
885 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
886 EXPECT_FLOAT_EQ(7.26f
,
887 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
888 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
889 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
892 TEST_F(PictureLayerImplTest
, CreateTilingsEvenIfTwinHasNone
) {
893 // This test makes sure that if a layer can have tilings, then a commit makes
894 // it not able to have tilings (empty size), and then a future commit that
895 // makes it valid again should be able to create tilings.
896 gfx::Size
tile_size(400, 400);
897 gfx::Size
layer_bounds(1300, 1900);
899 scoped_refptr
<FakePicturePileImpl
> empty_pile
=
900 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
901 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
902 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
904 SetupPendingTree(valid_pile
);
905 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
908 SetupPendingTree(empty_pile
);
909 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
910 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
911 ASSERT_EQ(0u, pending_layer_
->tilings()->num_tilings());
914 EXPECT_FALSE(active_layer_
->CanHaveTilings());
915 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
917 SetupPendingTree(valid_pile
);
918 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
919 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
922 TEST_F(PictureLayerImplTest
, ZoomOutCrash
) {
923 gfx::Size
tile_size(400, 400);
924 gfx::Size
layer_bounds(1300, 1900);
926 // Set up the high and low res tilings before pinch zoom.
927 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
928 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
929 scoped_refptr
<FakePicturePileImpl
> active_pile
=
930 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
932 SetupTrees(pending_pile
, active_pile
);
933 ResetTilingsAndRasterScales();
934 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
935 SetContentsScaleOnBothLayers(32.0f
, 1.0f
, 32.0f
, 1.0f
, false);
936 EXPECT_EQ(32.f
, active_layer_
->HighResTiling()->contents_scale());
937 host_impl_
.PinchGestureBegin();
938 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, false);
939 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, false);
940 EXPECT_EQ(active_layer_
->tilings()->NumHighResTilings(), 1);
943 TEST_F(PictureLayerImplTest
, PinchGestureTilings
) {
944 gfx::Size
tile_size(400, 400);
945 gfx::Size
layer_bounds(1300, 1900);
947 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
949 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
950 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
951 scoped_refptr
<FakePicturePileImpl
> active_pile
=
952 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
954 // Set up the high and low res tilings before pinch zoom.
955 SetupTrees(pending_pile
, active_pile
);
956 ResetTilingsAndRasterScales();
958 SetContentsScaleOnBothLayers(2.f
, 1.0f
, 2.f
, 1.0f
, false);
959 EXPECT_BOTH_EQ(num_tilings(), 2u);
960 EXPECT_BOTH_EQ(tilings()->tiling_at(0)->contents_scale(), 2.f
);
961 EXPECT_BOTH_EQ(tilings()->tiling_at(1)->contents_scale(),
962 2.f
* low_res_factor
);
964 // Ensure UpdateTiles won't remove any tilings.
965 active_layer_
->MarkAllTilingsUsed();
967 // Start a pinch gesture.
968 host_impl_
.PinchGestureBegin();
970 // Zoom out by a small amount. We should create a tiling at half
971 // the scale (2/kMaxScaleRatioDuringPinch).
972 SetContentsScaleOnBothLayers(1.8f
, 1.0f
, 1.8f
, 1.0f
, false);
973 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
974 EXPECT_FLOAT_EQ(2.0f
,
975 active_layer_
->tilings()->tiling_at(0)->contents_scale());
976 EXPECT_FLOAT_EQ(1.0f
,
977 active_layer_
->tilings()->tiling_at(1)->contents_scale());
978 EXPECT_FLOAT_EQ(2.0f
* low_res_factor
,
979 active_layer_
->tilings()->tiling_at(2)->contents_scale());
981 // Ensure UpdateTiles won't remove any tilings.
982 active_layer_
->MarkAllTilingsUsed();
984 // Zoom out further, close to our low-res scale factor. We should
985 // use that tiling as high-res, and not create a new tiling.
986 SetContentsScaleOnBothLayers(low_res_factor
* 2.1f
, 1.0f
,
987 low_res_factor
* 2.1f
, 1.0f
, false);
988 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
990 // Zoom in a lot now. Since we increase by increments of
991 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0.
992 SetContentsScaleOnBothLayers(3.8f
, 1.0f
, 3.8f
, 1.f
, false);
993 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
994 EXPECT_FLOAT_EQ(4.0f
,
995 active_layer_
->tilings()->tiling_at(0)->contents_scale());
998 TEST_F(PictureLayerImplTest
, SnappedTilingDuringZoom
) {
999 gfx::Size
tile_size(300, 300);
1000 gfx::Size
layer_bounds(2600, 3800);
1002 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1003 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1004 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1005 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1007 SetupTrees(pending_pile
, active_pile
);
1009 ResetTilingsAndRasterScales();
1010 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1012 // Set up the high and low res tilings before pinch zoom.
1013 SetContentsScaleOnBothLayers(0.24f
, 1.0f
, 0.24f
, 1.0f
, false);
1014 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1015 EXPECT_FLOAT_EQ(0.24f
,
1016 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1017 EXPECT_FLOAT_EQ(0.0625f
,
1018 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1020 // Ensure UpdateTiles won't remove any tilings.
1021 active_layer_
->MarkAllTilingsUsed();
1023 // Start a pinch gesture.
1024 host_impl_
.PinchGestureBegin();
1026 // Zoom out by a small amount. We should create a tiling at half
1027 // the scale (1/kMaxScaleRatioDuringPinch).
1028 SetContentsScaleOnBothLayers(0.2f
, 1.0f
, 0.2f
, 1.0f
, false);
1029 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1030 EXPECT_FLOAT_EQ(0.24f
,
1031 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1032 EXPECT_FLOAT_EQ(0.12f
,
1033 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1034 EXPECT_FLOAT_EQ(0.0625,
1035 active_layer_
->tilings()->tiling_at(2)->contents_scale());
1037 // Ensure UpdateTiles won't remove any tilings.
1038 active_layer_
->MarkAllTilingsUsed();
1040 // Zoom out further, close to our low-res scale factor. We should
1041 // use that tiling as high-res, and not create a new tiling.
1042 SetContentsScaleOnBothLayers(0.1f
, 1.0f
, 0.1f
, 1.0f
, false);
1043 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1045 // Zoom in. 0.25(desired_scale) should be snapped to 0.24 during zoom-in
1046 // because 0.25(desired_scale) is within the ratio(1.2).
1047 SetContentsScaleOnBothLayers(0.25f
, 1.0f
, 0.25f
, 1.0f
, false);
1048 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1050 // Zoom in a lot. Since we move in factors of two, we should get a scale that
1051 // is a power of 2 times 0.24.
1052 SetContentsScaleOnBothLayers(1.f
, 1.0f
, 1.f
, 1.0f
, false);
1053 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
1054 EXPECT_FLOAT_EQ(1.92f
,
1055 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1058 TEST_F(PictureLayerImplTest
, CleanUpTilings
) {
1059 gfx::Size
tile_size(400, 400);
1060 gfx::Size
layer_bounds(1300, 1900);
1062 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1063 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1064 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1065 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1067 std::vector
<PictureLayerTiling
*> used_tilings
;
1069 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1070 EXPECT_LT(low_res_factor
, 1.f
);
1073 float page_scale
= 1.f
;
1075 SetupTrees(pending_pile
, active_pile
);
1076 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1077 EXPECT_EQ(1.f
, active_layer_
->HighResTiling()->contents_scale());
1079 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
1080 // |used_tilings| variable, and it's here only to ensure that active_layer_
1081 // won't remove tilings before the test has a chance to verify behavior.
1082 active_layer_
->MarkAllTilingsUsed();
1084 // We only have ideal tilings, so they aren't removed.
1085 used_tilings
.clear();
1086 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1087 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1089 host_impl_
.PinchGestureBegin();
1091 // Changing the ideal but not creating new tilings.
1094 SetContentsScaleOnBothLayers(scale
, 1.f
, page_scale
, 1.f
, false);
1095 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1097 // The tilings are still our target scale, so they aren't removed.
1098 used_tilings
.clear();
1099 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1100 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
1102 host_impl_
.PinchGestureEnd();
1104 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
1107 SetContentsScaleOnBothLayers(1.2f
, 1.f
, page_scale
, 1.f
, false);
1108 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
1111 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1113 1.f
* low_res_factor
,
1114 active_layer_
->tilings()->tiling_at(3)->contents_scale());
1116 // Ensure UpdateTiles won't remove any tilings.
1117 active_layer_
->MarkAllTilingsUsed();
1119 // Mark the non-ideal tilings as used. They won't be removed.
1120 used_tilings
.clear();
1121 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1122 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(3));
1123 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1124 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
1126 // Now move the ideal scale to 0.5. Our target stays 1.2.
1127 SetContentsScaleOnBothLayers(0.5f
, 1.f
, page_scale
, 1.f
, false);
1129 // The high resolution tiling is between target and ideal, so is not
1130 // removed. The low res tiling for the old ideal=1.0 scale is removed.
1131 used_tilings
.clear();
1132 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1133 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1135 // Now move the ideal scale to 1.0. Our target stays 1.2.
1136 SetContentsScaleOnBothLayers(1.f
, 1.f
, page_scale
, 1.f
, false);
1138 // All the tilings are between are target and the ideal, so they are not
1140 used_tilings
.clear();
1141 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1142 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1144 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
1145 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.1f
, 1.f
, page_scale
, 1.f
,
1148 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1149 // in the range [1.0,1.2] and are kept.
1150 used_tilings
.clear();
1151 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1152 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1154 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1156 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.1f
, 1.f
, page_scale
, 1.f
,
1159 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1160 // target raster scale. But it is in our used tilings set, so nothing is
1162 used_tilings
.clear();
1163 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1164 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1165 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1167 // If we remove it from our used tilings set, it is outside the range to keep
1168 // so it is deleted.
1169 used_tilings
.clear();
1170 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1171 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
1174 TEST_F(PictureLayerImplTest
, DontAddLowResDuringAnimation
) {
1175 // Make sure this layer covers multiple tiles, since otherwise low
1176 // res won't get created because it is too small.
1177 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1178 // Avoid max untiled layer size heuristics via fixed tile size.
1179 gfx::Size
layer_bounds(tile_size
.width() + 1, tile_size
.height() + 1);
1180 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
1182 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1183 float contents_scale
= 1.f
;
1184 float device_scale
= 1.f
;
1185 float page_scale
= 1.f
;
1186 float maximum_animation_scale
= 1.f
;
1187 bool animating_transform
= true;
1189 ResetTilingsAndRasterScales();
1191 // Animating, so don't create low res even if there isn't one already.
1192 SetContentsScaleOnBothLayers(contents_scale
,
1195 maximum_animation_scale
,
1196 animating_transform
);
1197 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1198 EXPECT_BOTH_EQ(num_tilings(), 1u);
1200 // Stop animating, low res gets created.
1201 animating_transform
= false;
1202 SetContentsScaleOnBothLayers(contents_scale
,
1205 maximum_animation_scale
,
1206 animating_transform
);
1207 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1208 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor
);
1209 EXPECT_BOTH_EQ(num_tilings(), 2u);
1211 // Ensure UpdateTiles won't remove any tilings.
1212 active_layer_
->MarkAllTilingsUsed();
1214 // Page scale animation, new high res, but no low res. We still have
1215 // a tiling at the previous scale, it's just not marked as low res on the
1216 // active layer. The pending layer drops non-ideal tilings.
1217 contents_scale
= 2.f
;
1219 maximum_animation_scale
= 2.f
;
1220 animating_transform
= true;
1221 SetContentsScaleOnBothLayers(contents_scale
,
1224 maximum_animation_scale
,
1225 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
,
1237 maximum_animation_scale
,
1238 animating_transform
);
1239 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1240 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f
* low_res_factor
);
1241 EXPECT_EQ(4u, active_layer_
->num_tilings());
1242 EXPECT_EQ(2u, pending_layer_
->num_tilings());
1245 TEST_F(PictureLayerImplTest
, DontAddLowResForSmallLayers
) {
1246 gfx::Size
layer_bounds(host_impl_
.settings().default_tile_size
);
1247 gfx::Size
tile_size(100, 100);
1249 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1250 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1251 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1252 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1254 SetupTrees(pending_pile
, active_pile
);
1256 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1257 float device_scale
= 1.f
;
1258 float page_scale
= 1.f
;
1259 float maximum_animation_scale
= 1.f
;
1260 bool animating_transform
= false;
1262 // Contents exactly fit on one tile at scale 1, no low res.
1263 float contents_scale
= 1.f
;
1264 SetContentsScaleOnBothLayers(contents_scale
,
1267 maximum_animation_scale
,
1268 animating_transform
);
1269 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1270 EXPECT_BOTH_EQ(num_tilings(), 1u);
1272 ResetTilingsAndRasterScales();
1274 // Contents that are smaller than one tile, no low res.
1275 contents_scale
= 0.123f
;
1276 SetContentsScaleOnBothLayers(contents_scale
,
1279 maximum_animation_scale
,
1280 animating_transform
);
1281 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1282 EXPECT_BOTH_EQ(num_tilings(), 1u);
1284 ResetTilingsAndRasterScales();
1286 // Any content bounds that would create more than one tile will
1287 // generate a low res tiling.
1288 contents_scale
= 2.5f
;
1289 SetContentsScaleOnBothLayers(contents_scale
,
1292 maximum_animation_scale
,
1293 animating_transform
);
1294 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1295 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1296 contents_scale
* low_res_factor
);
1297 EXPECT_BOTH_EQ(num_tilings(), 2u);
1299 // Mask layers dont create low res since they always fit on one tile.
1300 scoped_ptr
<FakePictureLayerImpl
> mask
=
1301 FakePictureLayerImpl::CreateMaskWithRasterSource(
1302 host_impl_
.pending_tree(), 3, pending_pile
);
1303 mask
->SetBounds(layer_bounds
);
1304 mask
->SetContentBounds(layer_bounds
);
1305 mask
->SetDrawsContent(true);
1307 SetupDrawPropertiesAndUpdateTiles(mask
.get(), contents_scale
, device_scale
,
1308 page_scale
, maximum_animation_scale
,
1309 animating_transform
);
1310 EXPECT_EQ(mask
->HighResTiling()->contents_scale(), contents_scale
);
1311 EXPECT_EQ(mask
->num_tilings(), 1u);
1314 TEST_F(PictureLayerImplTest
, HugeMasksGetScaledDown
) {
1315 base::TimeTicks time_ticks
;
1316 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1317 host_impl_
.SetCurrentBeginFrameArgs(
1318 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1320 gfx::Size
tile_size(100, 100);
1321 gfx::Size
layer_bounds(1000, 1000);
1323 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1324 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1325 SetupPendingTree(valid_pile
);
1327 scoped_ptr
<FakePictureLayerImpl
> mask_ptr
=
1328 FakePictureLayerImpl::CreateMaskWithRasterSource(
1329 host_impl_
.pending_tree(), 3, valid_pile
);
1330 mask_ptr
->SetBounds(layer_bounds
);
1331 mask_ptr
->SetContentBounds(layer_bounds
);
1332 mask_ptr
->SetDrawsContent(true);
1333 pending_layer_
->SetMaskLayer(mask_ptr
.Pass());
1334 pending_layer_
->SetHasRenderSurface(true);
1336 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1337 host_impl_
.SetCurrentBeginFrameArgs(
1338 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1339 bool update_lcd_text
= false;
1340 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1342 FakePictureLayerImpl
* pending_mask
=
1343 static_cast<FakePictureLayerImpl
*>(pending_layer_
->mask_layer());
1345 EXPECT_EQ(1.f
, pending_mask
->HighResTiling()->contents_scale());
1346 EXPECT_EQ(1u, pending_mask
->num_tilings());
1348 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1349 pending_mask
->HighResTiling()->AllTilesForTesting());
1353 FakePictureLayerImpl
* active_mask
=
1354 static_cast<FakePictureLayerImpl
*>(active_layer_
->mask_layer());
1356 // Mask layers have a tiling with a single tile in it.
1357 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1358 // The mask resource exists.
1359 ResourceProvider::ResourceId mask_resource_id
;
1360 gfx::Size mask_texture_size
;
1361 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1362 EXPECT_NE(0u, mask_resource_id
);
1363 EXPECT_EQ(active_mask
->bounds(), mask_texture_size
);
1365 // Drop resources and recreate them, still the same.
1366 pending_mask
->ReleaseResources();
1367 active_mask
->ReleaseResources();
1368 pending_mask
->RecreateResources();
1369 active_mask
->RecreateResources();
1370 SetupDrawPropertiesAndUpdateTiles(active_mask
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1371 active_mask
->HighResTiling()->CreateAllTilesForTesting();
1372 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1373 EXPECT_NE(0u, mask_resource_id
);
1374 EXPECT_EQ(active_mask
->bounds(), mask_texture_size
);
1376 // Resize larger than the max texture size.
1377 int max_texture_size
= host_impl_
.GetRendererCapabilities().max_texture_size
;
1378 gfx::Size
huge_bounds(max_texture_size
+ 1, 10);
1379 scoped_refptr
<FakePicturePileImpl
> huge_pile
=
1380 FakePicturePileImpl::CreateFilledPile(tile_size
, huge_bounds
);
1382 SetupPendingTree(huge_pile
);
1383 pending_mask
->SetBounds(huge_bounds
);
1384 pending_mask
->SetContentBounds(huge_bounds
);
1385 pending_mask
->SetRasterSourceOnPending(huge_pile
, Region());
1387 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1388 host_impl_
.SetCurrentBeginFrameArgs(
1389 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1390 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1392 // The mask tiling gets scaled down.
1393 EXPECT_LT(pending_mask
->HighResTiling()->contents_scale(), 1.f
);
1394 EXPECT_EQ(1u, pending_mask
->num_tilings());
1396 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1397 pending_mask
->HighResTiling()->AllTilesForTesting());
1401 // Mask layers have a tiling with a single tile in it.
1402 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1403 // The mask resource exists.
1404 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1405 EXPECT_NE(0u, mask_resource_id
);
1406 gfx::Size expected_size
= active_mask
->bounds();
1407 expected_size
.SetToMin(gfx::Size(max_texture_size
, max_texture_size
));
1408 EXPECT_EQ(expected_size
, mask_texture_size
);
1410 // Drop resources and recreate them, still the same.
1411 pending_mask
->ReleaseResources();
1412 active_mask
->ReleaseResources();
1413 pending_mask
->RecreateResources();
1414 active_mask
->RecreateResources();
1415 SetupDrawPropertiesAndUpdateTiles(active_mask
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1416 active_mask
->HighResTiling()->CreateAllTilesForTesting();
1417 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1418 EXPECT_NE(0u, mask_resource_id
);
1419 EXPECT_EQ(expected_size
, mask_texture_size
);
1421 // Do another activate, the same holds.
1422 SetupPendingTree(huge_pile
);
1424 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1425 active_layer_
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1426 EXPECT_EQ(expected_size
, mask_texture_size
);
1427 EXPECT_EQ(0u, mask_resource_id
);
1429 // Resize even larger, so that the scale would be smaller than the minimum
1430 // contents scale. Then the layer should no longer have any tiling.
1431 float min_contents_scale
= host_impl_
.settings().minimum_contents_scale
;
1432 gfx::Size
extra_huge_bounds(max_texture_size
/ min_contents_scale
+ 1, 10);
1433 scoped_refptr
<FakePicturePileImpl
> extra_huge_pile
=
1434 FakePicturePileImpl::CreateFilledPile(tile_size
, extra_huge_bounds
);
1436 SetupPendingTree(extra_huge_pile
);
1437 pending_mask
->SetBounds(extra_huge_bounds
);
1438 pending_mask
->SetContentBounds(extra_huge_bounds
);
1439 pending_mask
->SetRasterSourceOnPending(extra_huge_pile
, Region());
1441 EXPECT_FALSE(pending_mask
->CanHaveTilings());
1443 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1444 host_impl_
.SetCurrentBeginFrameArgs(
1445 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1446 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1448 EXPECT_EQ(0u, pending_mask
->num_tilings());
1451 TEST_F(PictureLayerImplTest
, ScaledMaskLayer
) {
1452 base::TimeTicks time_ticks
;
1453 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1454 host_impl_
.SetCurrentBeginFrameArgs(
1455 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1457 gfx::Size
tile_size(100, 100);
1458 gfx::Size
layer_bounds(1000, 1000);
1460 host_impl_
.SetDeviceScaleFactor(1.3f
);
1462 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1463 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1464 SetupPendingTree(valid_pile
);
1466 scoped_ptr
<FakePictureLayerImpl
> mask_ptr
=
1467 FakePictureLayerImpl::CreateMaskWithRasterSource(
1468 host_impl_
.pending_tree(), 3, valid_pile
);
1469 mask_ptr
->SetBounds(layer_bounds
);
1470 mask_ptr
->SetContentBounds(layer_bounds
);
1471 mask_ptr
->SetDrawsContent(true);
1472 pending_layer_
->SetMaskLayer(mask_ptr
.Pass());
1473 pending_layer_
->SetHasRenderSurface(true);
1475 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1476 host_impl_
.SetCurrentBeginFrameArgs(
1477 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1478 bool update_lcd_text
= false;
1479 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1481 FakePictureLayerImpl
* pending_mask
=
1482 static_cast<FakePictureLayerImpl
*>(pending_layer_
->mask_layer());
1484 // Masks are scaled, and do not have a low res tiling.
1485 EXPECT_EQ(1.3f
, pending_mask
->HighResTiling()->contents_scale());
1486 EXPECT_EQ(1u, pending_mask
->num_tilings());
1488 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1489 pending_mask
->HighResTiling()->AllTilesForTesting());
1493 FakePictureLayerImpl
* active_mask
=
1494 static_cast<FakePictureLayerImpl
*>(active_layer_
->mask_layer());
1496 // Mask layers have a tiling with a single tile in it.
1497 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1498 // The mask resource exists.
1499 ResourceProvider::ResourceId mask_resource_id
;
1500 gfx::Size mask_texture_size
;
1501 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1502 EXPECT_NE(0u, mask_resource_id
);
1503 gfx::Size expected_mask_texture_size
=
1504 gfx::ToCeiledSize(gfx::ScaleSize(active_mask
->bounds(), 1.3f
));
1505 EXPECT_EQ(mask_texture_size
, expected_mask_texture_size
);
1508 TEST_F(PictureLayerImplTest
, ReleaseResources
) {
1509 gfx::Size
tile_size(400, 400);
1510 gfx::Size
layer_bounds(1300, 1900);
1512 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1513 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1514 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1515 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1517 SetupTrees(pending_pile
, active_pile
);
1518 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1520 // All tilings should be removed when losing output surface.
1521 active_layer_
->ReleaseResources();
1522 EXPECT_FALSE(active_layer_
->tilings());
1523 active_layer_
->RecreateResources();
1524 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1525 pending_layer_
->ReleaseResources();
1526 EXPECT_FALSE(pending_layer_
->tilings());
1527 pending_layer_
->RecreateResources();
1528 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1530 // This should create new tilings.
1531 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
1532 1.f
, // ideal contents scale
1533 1.f
, // device scale
1535 1.f
, // maximum animation scale
1537 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1540 TEST_F(PictureLayerImplTest
, ClampTilesToToMaxTileSize
) {
1541 // The default max tile size is larger than 400x400.
1542 gfx::Size
tile_size(400, 400);
1543 gfx::Size
layer_bounds(5000, 5000);
1545 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1546 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1547 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1548 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1550 SetupTrees(pending_pile
, active_pile
);
1551 EXPECT_GE(pending_layer_
->tilings()->num_tilings(), 1u);
1553 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1555 // The default value.
1556 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1557 host_impl_
.settings().default_tile_size
.ToString());
1559 Tile
* tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1560 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1561 tile
->content_rect().size().ToString());
1563 ResetTilingsAndRasterScales();
1565 // Change the max texture size on the output surface context.
1566 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1567 TestWebGraphicsContext3D::Create();
1568 context
->set_max_texture_size(140);
1569 host_impl_
.DidLoseOutputSurface();
1570 host_impl_
.InitializeRenderer(
1571 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1573 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1574 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1576 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1578 // Verify the tiles are not larger than the context's max texture size.
1579 tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1580 EXPECT_GE(140, tile
->content_rect().width());
1581 EXPECT_GE(140, tile
->content_rect().height());
1584 TEST_F(PictureLayerImplTest
, ClampSingleTileToToMaxTileSize
) {
1585 // The default max tile size is larger than 400x400.
1586 gfx::Size
tile_size(400, 400);
1587 gfx::Size
layer_bounds(500, 500);
1589 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1590 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1591 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1592 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1594 SetupTrees(pending_pile
, active_pile
);
1595 EXPECT_GE(pending_layer_
->tilings()->num_tilings(), 1u);
1597 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1599 // The default value. The layer is smaller than this.
1600 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1601 host_impl_
.settings().max_untiled_layer_size
.ToString());
1603 // There should be a single tile since the layer is small.
1604 PictureLayerTiling
* high_res_tiling
= pending_layer_
->tilings()->tiling_at(0);
1605 EXPECT_EQ(1u, high_res_tiling
->AllTilesForTesting().size());
1607 ResetTilingsAndRasterScales();
1609 // Change the max texture size on the output surface context.
1610 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1611 TestWebGraphicsContext3D::Create();
1612 context
->set_max_texture_size(140);
1613 host_impl_
.DidLoseOutputSurface();
1614 host_impl_
.InitializeRenderer(
1615 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1617 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1618 ASSERT_LE(1u, pending_layer_
->tilings()->num_tilings());
1620 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1622 // There should be more than one tile since the max texture size won't cover
1624 high_res_tiling
= pending_layer_
->tilings()->tiling_at(0);
1625 EXPECT_LT(1u, high_res_tiling
->AllTilesForTesting().size());
1627 // Verify the tiles are not larger than the context's max texture size.
1628 Tile
* tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1629 EXPECT_GE(140, tile
->content_rect().width());
1630 EXPECT_GE(140, tile
->content_rect().height());
1633 TEST_F(PictureLayerImplTest
, DisallowTileDrawQuads
) {
1634 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1636 gfx::Size
tile_size(400, 400);
1637 gfx::Size
layer_bounds(1300, 1900);
1639 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1640 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1641 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1642 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1644 gfx::Rect
layer_invalidation(150, 200, 30, 180);
1645 SetupTreesWithInvalidation(pending_pile
, active_pile
, layer_invalidation
);
1647 active_layer_
->draw_properties().visible_content_rect
=
1648 gfx::Rect(layer_bounds
);
1650 AppendQuadsData data
;
1651 active_layer_
->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE
, nullptr);
1652 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1653 active_layer_
->DidDraw(nullptr);
1655 ASSERT_EQ(1U, render_pass
->quad_list
.size());
1656 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
,
1657 render_pass
->quad_list
.front()->material
);
1660 TEST_F(PictureLayerImplTest
, SolidColorLayerHasVisibleFullCoverage
) {
1661 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1663 gfx::Size
tile_size(1000, 1000);
1664 gfx::Size
layer_bounds(1500, 1500);
1665 gfx::Rect
visible_rect(250, 250, 1000, 1000);
1667 scoped_ptr
<FakePicturePile
> empty_recording
=
1668 FakePicturePile::CreateEmptyPile(tile_size
, layer_bounds
);
1669 empty_recording
->SetIsSolidColor(true);
1671 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1672 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
1673 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1674 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
1676 SetupTrees(pending_pile
, active_pile
);
1678 active_layer_
->draw_properties().visible_content_rect
= visible_rect
;
1680 AppendQuadsData data
;
1681 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1682 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1683 active_layer_
->DidDraw(nullptr);
1685 Region remaining
= visible_rect
;
1686 for (const auto& quad
: render_pass
->quad_list
) {
1687 EXPECT_TRUE(visible_rect
.Contains(quad
->rect
));
1688 EXPECT_TRUE(remaining
.Contains(quad
->rect
));
1689 remaining
.Subtract(quad
->rect
);
1692 EXPECT_TRUE(remaining
.IsEmpty());
1695 TEST_F(PictureLayerImplTest
, TileScalesWithSolidColorPile
) {
1696 gfx::Size
layer_bounds(200, 200);
1697 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1698 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1699 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1700 tile_size
, layer_bounds
, false);
1701 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1702 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1703 tile_size
, layer_bounds
, true);
1705 SetupTrees(pending_pile
, active_pile
);
1706 // Solid color pile should not allow tilings at any scale.
1707 EXPECT_FALSE(active_layer_
->CanHaveTilings());
1708 EXPECT_EQ(0.f
, active_layer_
->ideal_contents_scale());
1710 // Activate non-solid-color pending pile makes active layer can have tilings.
1712 EXPECT_TRUE(active_layer_
->CanHaveTilings());
1713 EXPECT_GT(active_layer_
->ideal_contents_scale(), 0.f
);
1716 TEST_F(NoLowResPictureLayerImplTest
, MarkRequiredOffscreenTiles
) {
1717 gfx::Size
tile_size(100, 100);
1718 gfx::Size
layer_bounds(200, 200);
1720 gfx::Transform transform
;
1721 gfx::Transform transform_for_tile_priority
;
1722 bool resourceless_software_draw
= false;
1723 gfx::Rect
viewport(0, 0, 100, 200);
1724 host_impl_
.SetExternalDrawConstraints(transform
,
1729 resourceless_software_draw
);
1731 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1732 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1733 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1735 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1736 EXPECT_EQ(viewport
, pending_layer_
->visible_rect_for_tile_priority());
1738 base::TimeTicks time_ticks
;
1739 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1740 host_impl_
.SetCurrentBeginFrameArgs(
1741 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1742 pending_layer_
->UpdateTiles(resourceless_software_draw
);
1744 int num_visible
= 0;
1745 int num_offscreen
= 0;
1747 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
1748 pending_layer_
->picture_layer_tiling_set(), false));
1749 for (; !queue
->IsEmpty(); queue
->Pop()) {
1750 const Tile
* tile
= queue
->Top();
1752 if (tile
->priority(PENDING_TREE
).distance_to_visible
== 0.f
) {
1753 EXPECT_TRUE(tile
->required_for_activation());
1756 EXPECT_FALSE(tile
->required_for_activation());
1761 EXPECT_GT(num_visible
, 0);
1762 EXPECT_GT(num_offscreen
, 0);
1765 TEST_F(NoLowResPictureLayerImplTest
,
1766 TileOutsideOfViewportForTilePriorityNotRequired
) {
1767 base::TimeTicks time_ticks
;
1768 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1769 host_impl_
.SetCurrentBeginFrameArgs(
1770 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1772 gfx::Size
tile_size(100, 100);
1773 gfx::Size
layer_bounds(400, 400);
1774 gfx::Rect
external_viewport_for_tile_priority(400, 200);
1775 gfx::Rect
visible_content_rect(200, 400);
1777 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1778 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1779 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1780 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1781 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
1783 ASSERT_EQ(1u, pending_layer_
->num_tilings());
1784 ASSERT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
1786 // Set external viewport for tile priority.
1787 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
1788 gfx::Transform transform
;
1789 gfx::Transform transform_for_tile_priority
;
1790 bool resourceless_software_draw
= false;
1791 host_impl_
.SetExternalDrawConstraints(transform
,
1794 external_viewport_for_tile_priority
,
1795 transform_for_tile_priority
,
1796 resourceless_software_draw
);
1797 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1798 host_impl_
.SetCurrentBeginFrameArgs(
1799 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1800 bool update_lcd_text
= false;
1801 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1803 // Set visible content rect that is different from
1804 // external_viewport_for_tile_priority.
1805 pending_layer_
->draw_properties().visible_content_rect
= visible_content_rect
;
1806 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
1807 host_impl_
.SetCurrentBeginFrameArgs(
1808 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1809 pending_layer_
->UpdateTiles(resourceless_software_draw
);
1811 // Intersect the two rects. Any tile outside should not be required for
1813 gfx::Rect viewport_for_tile_priority
=
1814 pending_layer_
->viewport_rect_for_tile_priority_in_content_space();
1815 viewport_for_tile_priority
.Intersect(pending_layer_
->visible_content_rect());
1818 int num_outside
= 0;
1819 for (PictureLayerTiling::CoverageIterator
iter(
1820 pending_layer_
->HighResTiling(), 1.f
, gfx::Rect(layer_bounds
));
1825 if (viewport_for_tile_priority
.Intersects(iter
.geometry_rect())) {
1827 // Mark everything in viewport for tile priority as ready to draw.
1828 TileDrawInfo
& draw_info
= tile
->draw_info();
1829 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
1832 EXPECT_FALSE(tile
->required_for_activation());
1836 EXPECT_GT(num_inside
, 0);
1837 EXPECT_GT(num_outside
, 0);
1839 // Activate and draw active layer.
1840 host_impl_
.ActivateSyncTree();
1841 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
1842 active_layer_
->draw_properties().visible_content_rect
= visible_content_rect
;
1844 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1845 AppendQuadsData data
;
1846 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1847 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1848 active_layer_
->DidDraw(nullptr);
1850 // All tiles in activation rect is ready to draw.
1851 EXPECT_EQ(0u, data
.num_missing_tiles
);
1852 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1853 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1856 TEST_F(PictureLayerImplTest
, HighResTileIsComplete
) {
1857 base::TimeTicks time_ticks
;
1858 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1859 host_impl_
.SetCurrentBeginFrameArgs(
1860 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1862 gfx::Size
tile_size(100, 100);
1863 gfx::Size
layer_bounds(200, 200);
1865 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1866 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1868 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1871 // All high res tiles have resources.
1872 std::vector
<Tile
*> tiles
=
1873 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1874 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
1876 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1877 AppendQuadsData data
;
1878 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1879 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1880 active_layer_
->DidDraw(nullptr);
1882 // All high res tiles drew, nothing was incomplete.
1883 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1884 EXPECT_EQ(0u, data
.num_missing_tiles
);
1885 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1886 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1889 TEST_F(PictureLayerImplTest
, HighResTileIsIncomplete
) {
1890 base::TimeTicks time_ticks
;
1891 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1892 host_impl_
.SetCurrentBeginFrameArgs(
1893 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1895 gfx::Size
tile_size(100, 100);
1896 gfx::Size
layer_bounds(200, 200);
1898 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1899 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1900 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1903 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1904 AppendQuadsData data
;
1905 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1906 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1907 active_layer_
->DidDraw(nullptr);
1909 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1910 EXPECT_EQ(1u, data
.num_missing_tiles
);
1911 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1912 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1915 TEST_F(PictureLayerImplTest
, HighResTileIsIncompleteLowResComplete
) {
1916 base::TimeTicks time_ticks
;
1917 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1918 host_impl_
.SetCurrentBeginFrameArgs(
1919 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1921 gfx::Size
tile_size(100, 100);
1922 gfx::Size
layer_bounds(200, 200);
1924 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1925 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1926 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1929 std::vector
<Tile
*> low_tiles
=
1930 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1931 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1933 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1934 AppendQuadsData data
;
1935 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1936 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1937 active_layer_
->DidDraw(nullptr);
1939 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1940 EXPECT_EQ(0u, data
.num_missing_tiles
);
1941 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1942 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1945 TEST_F(PictureLayerImplTest
, LowResTileIsIncomplete
) {
1946 base::TimeTicks time_ticks
;
1947 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1948 host_impl_
.SetCurrentBeginFrameArgs(
1949 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1951 gfx::Size
tile_size(100, 100);
1952 gfx::Size
layer_bounds(200, 200);
1954 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1955 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1956 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1959 // All high res tiles have resources except one.
1960 std::vector
<Tile
*> high_tiles
=
1961 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1962 high_tiles
.erase(high_tiles
.begin());
1963 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
1965 // All low res tiles have resources.
1966 std::vector
<Tile
*> low_tiles
=
1967 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1968 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1970 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1971 AppendQuadsData data
;
1972 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1973 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1974 active_layer_
->DidDraw(nullptr);
1976 // The missing high res tile was replaced by a low res tile.
1977 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1978 EXPECT_EQ(0u, data
.num_missing_tiles
);
1979 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1980 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1983 TEST_F(PictureLayerImplTest
,
1984 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal
) {
1985 base::TimeTicks time_ticks
;
1986 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1987 host_impl_
.SetCurrentBeginFrameArgs(
1988 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1990 gfx::Size
tile_size(100, 100);
1991 gfx::Size
layer_bounds(200, 200);
1992 gfx::Size
viewport_size(400, 400);
1994 host_impl_
.SetViewportSize(viewport_size
);
1995 host_impl_
.SetDeviceScaleFactor(2.f
);
1997 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1998 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1999 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2000 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2001 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2003 // One ideal tile exists, this will get used when drawing.
2004 std::vector
<Tile
*> ideal_tiles
;
2005 EXPECT_EQ(2.f
, active_layer_
->HighResTiling()->contents_scale());
2006 ideal_tiles
.push_back(active_layer_
->HighResTiling()->TileAt(0, 0));
2007 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
2010 // Due to layer scale throttling, the raster contents scale is changed to 1,
2011 // while the ideal is still 2.
2012 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
2013 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.f
, 1.f
, 1.f
, 1.f
, false);
2015 EXPECT_EQ(1.f
, active_layer_
->HighResTiling()->contents_scale());
2016 EXPECT_EQ(1.f
, active_layer_
->raster_contents_scale());
2017 EXPECT_EQ(2.f
, active_layer_
->ideal_contents_scale());
2019 // Both tilings still exist.
2020 EXPECT_EQ(2.f
, active_layer_
->tilings()->tiling_at(0)->contents_scale());
2021 EXPECT_EQ(1.f
, active_layer_
->tilings()->tiling_at(1)->contents_scale());
2023 // All high res tiles have resources.
2024 std::vector
<Tile
*> high_tiles
=
2025 active_layer_
->HighResTiling()->AllTilesForTesting();
2026 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
2028 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
2029 AppendQuadsData data
;
2030 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
2031 active_layer_
->AppendQuads(render_pass
.get(), &data
);
2032 active_layer_
->DidDraw(nullptr);
2034 // All high res tiles drew, and the one ideal res tile drew.
2035 ASSERT_GT(render_pass
->quad_list
.size(), 9u);
2036 EXPECT_EQ(gfx::SizeF(99.f
, 99.f
),
2037 TileDrawQuad::MaterialCast(render_pass
->quad_list
.front())
2038 ->tex_coord_rect
.size());
2039 EXPECT_EQ(gfx::SizeF(49.5f
, 49.5f
),
2040 TileDrawQuad::MaterialCast(render_pass
->quad_list
.ElementAt(1))
2041 ->tex_coord_rect
.size());
2043 // Neither the high res nor the ideal tiles were considered as incomplete.
2044 EXPECT_EQ(0u, data
.num_missing_tiles
);
2045 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
2046 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
2049 TEST_F(PictureLayerImplTest
, HighResRequiredWhenUnsharedActiveAllReady
) {
2050 gfx::Size
layer_bounds(400, 400);
2051 gfx::Size
tile_size(100, 100);
2054 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
,
2055 gfx::Rect(layer_bounds
));
2057 active_layer_
->SetAllTilesReady();
2059 // No shared tiles and all active tiles ready, so pending can only
2060 // activate with all high res tiles.
2061 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2062 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2064 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2065 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2068 TEST_F(PictureLayerImplTest
, HighResRequiredWhenMissingHighResFlagOn
) {
2069 gfx::Size
layer_bounds(400, 400);
2070 gfx::Size
tile_size(100, 100);
2072 // All tiles shared (no invalidation).
2073 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2075 // Verify active tree not ready.
2076 Tile
* some_active_tile
=
2077 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2078 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
2080 // When high res are required, even if the active tree is not ready,
2081 // the high res tiles must be ready.
2082 host_impl_
.SetRequiresHighResToDraw();
2084 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2085 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2087 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2088 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2091 TEST_F(PictureLayerImplTest
, AllHighResRequiredEvenIfShared
) {
2092 gfx::Size
layer_bounds(400, 400);
2093 gfx::Size
tile_size(100, 100);
2095 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2097 Tile
* some_active_tile
=
2098 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2099 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
2101 // All tiles shared (no invalidation), so even though the active tree's
2102 // tiles aren't ready, the high res tiles are required for activation.
2103 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2104 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2106 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2107 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2110 TEST_F(PictureLayerImplTest
, DisallowRequiredForActivation
) {
2111 gfx::Size
layer_bounds(400, 400);
2112 gfx::Size
tile_size(100, 100);
2114 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2116 Tile
* some_active_tile
=
2117 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2118 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
2120 pending_layer_
->HighResTiling()->set_can_require_tiles_for_activation(false);
2121 pending_layer_
->LowResTiling()->set_can_require_tiles_for_activation(false);
2123 // If we disallow required for activation, no tiles can be required.
2124 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2125 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2127 AssertNoTilesRequired(pending_layer_
->HighResTiling());
2128 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2131 TEST_F(PictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
2132 gfx::Size
layer_bounds(400, 400);
2133 gfx::Size
tile_size(100, 100);
2135 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2136 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2137 // This pile will create tilings, but has no recordings so will not create any
2138 // tiles. This is attempting to simulate scrolling past the end of recorded
2139 // content on the active layer, where the recordings are so far away that
2140 // no tiles are created.
2141 bool is_solid_color
= false;
2142 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2143 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
2144 tile_size
, layer_bounds
, is_solid_color
);
2146 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2148 // Active layer has tilings, but no tiles due to missing recordings.
2149 EXPECT_TRUE(active_layer_
->CanHaveTilings());
2150 EXPECT_EQ(active_layer_
->tilings()->num_tilings(), 2u);
2151 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
2153 // Since the active layer has no tiles at all, the pending layer doesn't
2154 // need content in order to activate.
2155 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2156 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2158 AssertNoTilesRequired(pending_layer_
->HighResTiling());
2159 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2162 TEST_F(PictureLayerImplTest
, HighResRequiredIfActiveCantHaveTiles
) {
2163 gfx::Size
layer_bounds(400, 400);
2164 gfx::Size
tile_size(100, 100);
2166 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2167 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2168 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2169 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
2170 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2172 // Active layer can't have tiles.
2173 EXPECT_FALSE(active_layer_
->CanHaveTilings());
2175 // All high res tiles required. This should be considered identical
2176 // to the case where there is no active layer, to avoid flashing content.
2177 // This can happen if a layer exists for a while and switches from
2178 // not being able to have content to having content.
2179 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2180 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2182 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2183 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2186 TEST_F(PictureLayerImplTest
, HighResRequiredWhenActiveHasDifferentBounds
) {
2187 gfx::Size
pending_layer_bounds(400, 400);
2188 gfx::Size
active_layer_bounds(200, 200);
2189 gfx::Size
tile_size(100, 100);
2191 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2192 FakePicturePileImpl::CreateFilledPile(tile_size
, pending_layer_bounds
);
2193 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2194 FakePicturePileImpl::CreateFilledPile(tile_size
, active_layer_bounds
);
2196 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2198 // Since the active layer has different bounds, the pending layer needs all
2199 // high res tiles in order to activate.
2200 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2201 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2203 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2204 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2207 TEST_F(PictureLayerImplTest
, ActivateUninitializedLayer
) {
2208 gfx::Size
tile_size(100, 100);
2209 gfx::Size
layer_bounds(400, 400);
2210 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2211 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2213 host_impl_
.CreatePendingTree();
2214 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
2216 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
2217 FakePictureLayerImpl::CreateWithRasterSource(pending_tree
, id_
,
2219 pending_layer
->SetDrawsContent(true);
2220 pending_tree
->SetRootLayer(pending_layer
.Pass());
2222 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
2223 host_impl_
.pending_tree()->LayerById(id_
));
2225 // Set some state on the pending layer, make sure it is not clobbered
2226 // by a sync from the active layer. This could happen because if the
2227 // pending layer has not been post-commit initialized it will attempt
2228 // to sync from the active layer.
2229 float raster_page_scale
= 10.f
* pending_layer_
->raster_page_scale();
2230 pending_layer_
->set_raster_page_scale(raster_page_scale
);
2232 host_impl_
.ActivateSyncTree();
2234 active_layer_
= static_cast<FakePictureLayerImpl
*>(
2235 host_impl_
.active_tree()->LayerById(id_
));
2237 EXPECT_EQ(0u, active_layer_
->num_tilings());
2238 EXPECT_EQ(raster_page_scale
, active_layer_
->raster_page_scale());
2241 TEST_F(PictureLayerImplTest
, ShareTilesOnNextFrame
) {
2242 gfx::Size
layer_bounds(1500, 1500);
2243 gfx::Size
tile_size(100, 100);
2245 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2246 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2248 SetupPendingTree(pending_pile
);
2250 PictureLayerTiling
* tiling
= pending_layer_
->HighResTiling();
2251 gfx::Rect first_invalidate
= tiling
->TilingDataForTesting().TileBounds(0, 0);
2252 first_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2253 tiling
->TilingDataForTesting().border_texels());
2254 gfx::Rect second_invalidate
= tiling
->TilingDataForTesting().TileBounds(1, 1);
2255 second_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2256 tiling
->TilingDataForTesting().border_texels());
2260 // Make a pending tree with an invalidated raster tile 0,0.
2261 SetupPendingTreeWithInvalidation(pending_pile
, first_invalidate
);
2263 // Activate and make a pending tree with an invalidated raster tile 1,1.
2266 SetupPendingTreeWithInvalidation(pending_pile
, second_invalidate
);
2268 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2269 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2271 // pending_tiling->CreateAllTilesForTesting();
2273 // Tile 0,0 should be shared, but tile 1,1 should not be.
2274 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2275 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2276 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2277 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2278 EXPECT_TRUE(pending_tiling
->TileAt(0, 0)->is_shared());
2279 EXPECT_TRUE(pending_tiling
->TileAt(1, 0)->is_shared());
2280 EXPECT_TRUE(pending_tiling
->TileAt(0, 1)->is_shared());
2281 EXPECT_FALSE(pending_tiling
->TileAt(1, 1)->is_shared());
2283 // Drop the tiles on the active tree and recreate them. The same tiles
2284 // should be shared or not.
2285 active_tiling
->ComputeTilePriorityRects(gfx::Rect(), 1.f
, 1.0, Occlusion());
2286 EXPECT_TRUE(active_tiling
->AllTilesForTesting().empty());
2287 active_tiling
->CreateAllTilesForTesting();
2289 // Tile 0,0 should be shared, but tile 1,1 should not be.
2290 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2291 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2292 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2293 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2294 EXPECT_TRUE(pending_tiling
->TileAt(0, 0)->is_shared());
2295 EXPECT_TRUE(pending_tiling
->TileAt(1, 0)->is_shared());
2296 EXPECT_TRUE(pending_tiling
->TileAt(0, 1)->is_shared());
2297 EXPECT_FALSE(pending_tiling
->TileAt(1, 1)->is_shared());
2300 TEST_F(PictureLayerImplTest
, ShareTilesWithNoInvalidation
) {
2301 SetupDefaultTrees(gfx::Size(1500, 1500));
2303 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2304 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2306 // No invalidation, so all tiles are shared.
2307 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2308 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2309 ASSERT_TRUE(active_tiling
);
2310 ASSERT_TRUE(pending_tiling
);
2312 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2313 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2314 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2315 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2317 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2318 EXPECT_TRUE(pending_tiling
->TileAt(1, 0));
2319 EXPECT_TRUE(pending_tiling
->TileAt(0, 1));
2320 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2322 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2323 EXPECT_TRUE(active_tiling
->TileAt(0, 0)->is_shared());
2324 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2325 EXPECT_TRUE(active_tiling
->TileAt(1, 0)->is_shared());
2326 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2327 EXPECT_TRUE(active_tiling
->TileAt(0, 1)->is_shared());
2328 EXPECT_EQ(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2329 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2332 TEST_F(PictureLayerImplTest
, ShareInvalidActiveTreeTiles
) {
2333 gfx::Size
tile_size(100, 100);
2334 gfx::Size
layer_bounds(1500, 1500);
2336 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2337 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2338 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2339 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2340 SetupTreesWithInvalidation(pending_pile
, active_pile
, gfx::Rect(1, 1));
2341 // Activate the invalidation.
2343 // Make another pending tree without any invalidation in it.
2344 scoped_refptr
<FakePicturePileImpl
> pending_pile2
=
2345 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2346 SetupPendingTree(pending_pile2
);
2348 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2349 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2351 // The active tree invalidation was handled by the active tiles, so they
2352 // can be shared with the pending tree.
2353 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2354 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2355 ASSERT_TRUE(active_tiling
);
2356 ASSERT_TRUE(pending_tiling
);
2358 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2359 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2360 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2361 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2363 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2364 EXPECT_TRUE(pending_tiling
->TileAt(1, 0));
2365 EXPECT_TRUE(pending_tiling
->TileAt(0, 1));
2366 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2368 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2369 EXPECT_TRUE(active_tiling
->TileAt(0, 0)->is_shared());
2370 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2371 EXPECT_TRUE(active_tiling
->TileAt(1, 0)->is_shared());
2372 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2373 EXPECT_TRUE(active_tiling
->TileAt(0, 1)->is_shared());
2374 EXPECT_EQ(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2375 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2378 TEST_F(PictureLayerImplTest
, RecreateInvalidPendingTreeTiles
) {
2379 // Set some invalidation on the pending tree. We should replace raster tiles
2381 SetupDefaultTreesWithInvalidation(gfx::Size(1500, 1500), gfx::Rect(1, 1));
2383 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2384 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2386 // The pending tree invalidation means tiles can not be shared with the
2388 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2389 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2390 ASSERT_TRUE(active_tiling
);
2391 ASSERT_TRUE(pending_tiling
);
2393 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2394 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2395 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2396 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2398 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2399 EXPECT_TRUE(pending_tiling
->TileAt(1, 0));
2400 EXPECT_TRUE(pending_tiling
->TileAt(0, 1));
2401 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2403 EXPECT_NE(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2404 EXPECT_FALSE(active_tiling
->TileAt(0, 0)->is_shared());
2405 EXPECT_FALSE(pending_tiling
->TileAt(0, 0)->is_shared());
2406 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2407 EXPECT_TRUE(active_tiling
->TileAt(1, 0)->is_shared());
2408 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2409 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2410 EXPECT_EQ(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2411 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2414 TEST_F(PictureLayerImplTest
, SyncTilingAfterGpuRasterizationToggles
) {
2415 base::TimeTicks time_ticks
;
2416 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
2417 host_impl_
.SetCurrentBeginFrameArgs(
2418 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2420 gfx::Size
tile_size(100, 100);
2421 gfx::Size
layer_bounds(10, 10);
2423 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2424 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2425 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2426 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2428 SetupTrees(pending_pile
, active_pile
);
2430 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2431 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(1.f
));
2433 // Gpu rasterization is disabled by default.
2434 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2435 // Toggling the gpu rasterization clears all tilings on both trees.
2436 host_impl_
.SetUseGpuRasterization(true);
2437 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2438 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2440 // Make sure that we can still add tiling to the pending layer,
2441 // that gets synced to the active layer.
2442 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
2443 host_impl_
.SetCurrentBeginFrameArgs(
2444 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2445 bool update_lcd_text
= false;
2446 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
2447 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2450 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(1.f
));
2452 SetupPendingTree(pending_pile
);
2453 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2455 // Toggling the gpu rasterization clears all tilings on both trees.
2456 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2457 host_impl_
.SetUseGpuRasterization(false);
2458 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2459 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2462 TEST_F(PictureLayerImplTest
, HighResCreatedWhenBoundsShrink
) {
2463 gfx::Size
tile_size(100, 100);
2465 // Put 0.5 as high res.
2466 host_impl_
.SetDeviceScaleFactor(0.5f
);
2468 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2469 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(10, 10));
2470 SetupPendingTree(pending_pile
);
2473 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2474 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(0.5f
));
2478 // Now, set the bounds to be 1x1, so that minimum contents scale becomes 1.
2480 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(1, 1));
2481 SetupPendingTree(pending_pile
);
2483 // Another sanity check.
2484 EXPECT_EQ(1.f
, pending_layer_
->MinimumContentsScale());
2486 // Since the MinContentsScale is 1, the 0.5 tiling should be replaced by a 1.0
2488 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 0.5f
, 1.f
, 1.f
, 1.f
, false);
2490 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2491 PictureLayerTiling
* tiling
=
2492 pending_layer_
->tilings()->FindTilingWithScale(1.0f
);
2493 ASSERT_TRUE(tiling
);
2494 EXPECT_EQ(HIGH_RESOLUTION
, tiling
->resolution());
2497 TEST_F(PictureLayerImplTest
, LowResTilingWithoutGpuRasterization
) {
2498 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
2499 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
2500 default_tile_size
.height() * 4);
2502 host_impl_
.SetUseGpuRasterization(false);
2504 SetupDefaultTrees(layer_bounds
);
2505 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2506 // Should have a low-res and a high-res tiling.
2507 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
2510 TEST_F(PictureLayerImplTest
, NoLowResTilingWithGpuRasterization
) {
2511 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
2512 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
2513 default_tile_size
.height() * 4);
2515 host_impl_
.SetUseGpuRasterization(true);
2517 SetupDefaultTrees(layer_bounds
);
2518 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2519 // Should only have the high-res tiling.
2520 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2523 TEST_F(PictureLayerImplTest
, RequiredTilesWithGpuRasterization
) {
2524 host_impl_
.SetUseGpuRasterization(true);
2526 gfx::Size
viewport_size(1000, 1000);
2527 host_impl_
.SetViewportSize(viewport_size
);
2529 gfx::Size
layer_bounds(4000, 4000);
2530 SetupDefaultTrees(layer_bounds
);
2531 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2533 // Should only have the high-res tiling.
2534 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2536 active_layer_
->SetAllTilesReady();
2537 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2539 // High res tiling should have 64 tiles (4x16 tile grid).
2540 EXPECT_EQ(64u, pending_layer_
->HighResTiling()->AllTilesForTesting().size());
2542 // Visible viewport should be covered by 4 tiles. No other
2543 // tiles should be required for activation.
2544 EXPECT_EQ(4u, NumberOfTilesRequired(pending_layer_
->HighResTiling()));
2547 TEST_F(PictureLayerImplTest
, NoTilingIfDoesNotDrawContent
) {
2548 // Set up layers with tilings.
2549 SetupDefaultTrees(gfx::Size(10, 10));
2550 SetContentsScaleOnBothLayers(1.f
, 1.f
, 1.f
, 1.f
, false);
2551 pending_layer_
->PushPropertiesTo(active_layer_
);
2552 EXPECT_TRUE(pending_layer_
->DrawsContent());
2553 EXPECT_TRUE(pending_layer_
->CanHaveTilings());
2554 EXPECT_GE(pending_layer_
->num_tilings(), 0u);
2555 EXPECT_GE(active_layer_
->num_tilings(), 0u);
2557 // Set content to false, which should make CanHaveTilings return false.
2558 pending_layer_
->SetDrawsContent(false);
2559 EXPECT_FALSE(pending_layer_
->DrawsContent());
2560 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
2562 // No tilings should be pushed to active layer.
2563 pending_layer_
->PushPropertiesTo(active_layer_
);
2564 EXPECT_EQ(0u, active_layer_
->num_tilings());
2567 TEST_F(PictureLayerImplTest
, FirstTilingDuringPinch
) {
2568 SetupDefaultTrees(gfx::Size(10, 10));
2570 // We start with a tiling at scale 1.
2571 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
2573 // When we scale up by 2.3, we get a new tiling that is a power of 2, in this
2575 host_impl_
.PinchGestureBegin();
2576 float high_res_scale
= 2.3f
;
2577 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, 1.f
, 1.f
, false);
2578 EXPECT_EQ(4.f
, pending_layer_
->HighResTiling()->contents_scale());
2581 TEST_F(PictureLayerImplTest
, PinchingTooSmall
) {
2582 SetupDefaultTrees(gfx::Size(10, 10));
2584 // We start with a tiling at scale 1.
2585 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
2587 host_impl_
.PinchGestureBegin();
2588 float high_res_scale
= 0.0001f
;
2589 EXPECT_LT(high_res_scale
, pending_layer_
->MinimumContentsScale());
2591 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, high_res_scale
, 1.f
, false);
2592 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2593 pending_layer_
->HighResTiling()->contents_scale());
2596 TEST_F(PictureLayerImplTest
, PinchingTooSmallWithContentsScale
) {
2597 SetupDefaultTrees(gfx::Size(10, 10));
2599 ResetTilingsAndRasterScales();
2601 float contents_scale
= 0.15f
;
2602 SetContentsScaleOnBothLayers(contents_scale
, 1.f
, 1.f
, 1.f
, false);
2604 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2605 EXPECT_FLOAT_EQ(contents_scale
,
2606 pending_layer_
->HighResTiling()->contents_scale());
2608 host_impl_
.PinchGestureBegin();
2610 float page_scale
= 0.0001f
;
2611 EXPECT_LT(page_scale
* contents_scale
,
2612 pending_layer_
->MinimumContentsScale());
2614 SetContentsScaleOnBothLayers(contents_scale
* page_scale
, 1.f
, page_scale
,
2616 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2617 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2618 pending_layer_
->HighResTiling()->contents_scale());
2621 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForCpuRasterization
) {
2622 gfx::Size
viewport_size(1000, 1000);
2623 host_impl_
.SetViewportSize(viewport_size
);
2625 gfx::Size
layer_bounds(100, 100);
2626 SetupDefaultTrees(layer_bounds
);
2628 float contents_scale
= 1.f
;
2629 float device_scale
= 1.f
;
2630 float page_scale
= 1.f
;
2631 float maximum_animation_scale
= 1.f
;
2632 bool animating_transform
= false;
2634 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2636 // Since we're CPU-rasterizing, starting an animation should cause tiling
2637 // resolution to get set to the maximum animation scale factor.
2638 animating_transform
= true;
2639 maximum_animation_scale
= 3.f
;
2640 contents_scale
= 2.f
;
2642 SetContentsScaleOnBothLayers(contents_scale
,
2645 maximum_animation_scale
,
2646 animating_transform
);
2647 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2649 // Further changes to scale during the animation should not cause a new
2650 // high-res tiling to get created.
2651 contents_scale
= 4.f
;
2652 maximum_animation_scale
= 5.f
;
2654 SetContentsScaleOnBothLayers(contents_scale
,
2657 maximum_animation_scale
,
2658 animating_transform
);
2659 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2661 // Once we stop animating, a new high-res tiling should be created.
2662 animating_transform
= false;
2664 SetContentsScaleOnBothLayers(contents_scale
,
2667 maximum_animation_scale
,
2668 animating_transform
);
2669 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2671 // When animating with an unknown maximum animation scale factor, a new
2672 // high-res tiling should be created at a source scale of 1.
2673 animating_transform
= true;
2674 contents_scale
= 2.f
;
2675 maximum_animation_scale
= 0.f
;
2677 SetContentsScaleOnBothLayers(contents_scale
,
2680 maximum_animation_scale
,
2681 animating_transform
);
2682 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2684 // Further changes to scale during the animation should not cause a new
2685 // high-res tiling to get created.
2686 contents_scale
= 3.f
;
2688 SetContentsScaleOnBothLayers(contents_scale
,
2691 maximum_animation_scale
,
2692 animating_transform
);
2693 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2695 // Once we stop animating, a new high-res tiling should be created.
2696 animating_transform
= false;
2697 contents_scale
= 4.f
;
2699 SetContentsScaleOnBothLayers(contents_scale
,
2702 maximum_animation_scale
,
2703 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
,
2717 maximum_animation_scale
,
2718 animating_transform
);
2719 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2721 // Once we stop animating, a new high-res tiling should be created.
2722 animating_transform
= false;
2723 contents_scale
= 11.f
;
2725 SetContentsScaleOnBothLayers(contents_scale
,
2728 maximum_animation_scale
,
2729 animating_transform
);
2730 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2732 // When animating with a maxmium animation scale factor that is so large
2733 // that the layer grows larger than the viewport at this scale, and where
2734 // the intial source scale is < 1, a new high-res tiling should get created
2735 // at source scale 1.
2736 animating_transform
= true;
2737 contents_scale
= 0.1f
;
2738 maximum_animation_scale
= 11.f
;
2740 SetContentsScaleOnBothLayers(contents_scale
,
2743 maximum_animation_scale
,
2744 animating_transform
);
2745 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2747 // Once we stop animating, a new high-res tiling should be created.
2748 animating_transform
= false;
2749 contents_scale
= 12.f
;
2751 SetContentsScaleOnBothLayers(contents_scale
,
2754 maximum_animation_scale
,
2755 animating_transform
);
2756 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 12.f
);
2758 // When animating toward a smaller scale, but that is still so large that the
2759 // layer grows larger than the viewport at this scale, a new high-res tiling
2760 // should get created at source scale 1.
2761 animating_transform
= true;
2762 contents_scale
= 11.f
;
2763 maximum_animation_scale
= 11.f
;
2765 SetContentsScaleOnBothLayers(contents_scale
,
2768 maximum_animation_scale
,
2769 animating_transform
);
2770 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2772 // Once we stop animating, a new high-res tiling should be created.
2773 animating_transform
= false;
2774 contents_scale
= 11.f
;
2776 SetContentsScaleOnBothLayers(contents_scale
,
2779 maximum_animation_scale
,
2780 animating_transform
);
2781 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2784 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForGpuRasterization
) {
2785 gfx::Size
layer_bounds(100, 100);
2786 gfx::Size
viewport_size(1000, 1000);
2787 SetupDefaultTrees(layer_bounds
);
2788 host_impl_
.SetViewportSize(viewport_size
);
2789 host_impl_
.SetUseGpuRasterization(true);
2791 float contents_scale
= 1.f
;
2792 float device_scale
= 1.3f
;
2793 float page_scale
= 1.4f
;
2794 float maximum_animation_scale
= 1.f
;
2795 bool animating_transform
= false;
2797 SetContentsScaleOnBothLayers(contents_scale
,
2800 maximum_animation_scale
,
2801 animating_transform
);
2802 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2804 // Since we're GPU-rasterizing, starting an animation should cause tiling
2805 // resolution to get set to the current contents scale.
2806 animating_transform
= true;
2807 contents_scale
= 2.f
;
2808 maximum_animation_scale
= 4.f
;
2810 SetContentsScaleOnBothLayers(contents_scale
,
2813 maximum_animation_scale
,
2814 animating_transform
);
2815 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2817 // Further changes to scale during the animation should cause a new high-res
2818 // tiling to get created.
2819 contents_scale
= 3.f
;
2821 SetContentsScaleOnBothLayers(contents_scale
,
2824 maximum_animation_scale
,
2825 animating_transform
);
2826 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2828 // Since we're re-rasterizing during the animation, scales smaller than 1
2829 // should be respected.
2830 contents_scale
= 0.25f
;
2832 SetContentsScaleOnBothLayers(contents_scale
,
2835 maximum_animation_scale
,
2836 animating_transform
);
2837 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.25f
);
2839 // Once we stop animating, a new high-res tiling should be created.
2840 contents_scale
= 4.f
;
2841 animating_transform
= false;
2843 SetContentsScaleOnBothLayers(contents_scale
,
2846 maximum_animation_scale
,
2847 animating_transform
);
2848 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2851 TEST_F(PictureLayerImplTest
, TilingSetRasterQueue
) {
2852 base::TimeTicks time_ticks
;
2853 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
2854 host_impl_
.SetCurrentBeginFrameArgs(
2855 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2857 host_impl_
.SetViewportSize(gfx::Size(500, 500));
2859 gfx::Size
recording_tile_size(100, 100);
2860 gfx::Size
layer_bounds(1000, 1000);
2862 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2863 FakePicturePileImpl::CreateFilledPile(recording_tile_size
, layer_bounds
);
2865 SetupPendingTree(pending_pile
);
2866 EXPECT_EQ(2u, pending_layer_
->num_tilings());
2868 std::set
<Tile
*> unique_tiles
;
2869 bool reached_prepaint
= false;
2870 int non_ideal_tile_count
= 0u;
2871 int low_res_tile_count
= 0u;
2872 int high_res_tile_count
= 0u;
2873 int high_res_now_tiles
= 0u;
2874 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
2875 pending_layer_
->picture_layer_tiling_set(), false));
2876 while (!queue
->IsEmpty()) {
2877 Tile
* tile
= queue
->Top();
2878 TilePriority priority
= tile
->priority(PENDING_TREE
);
2882 // Non-high res tiles only get visible tiles. Also, prepaint should only
2883 // come at the end of the iteration.
2884 if (priority
.resolution
!= HIGH_RESOLUTION
) {
2885 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
2886 } else if (reached_prepaint
) {
2887 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
2889 reached_prepaint
= priority
.priority_bin
!= TilePriority::NOW
;
2890 if (!reached_prepaint
)
2891 ++high_res_now_tiles
;
2894 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
2895 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
2896 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2898 unique_tiles
.insert(tile
);
2902 EXPECT_TRUE(reached_prepaint
);
2903 EXPECT_EQ(0, non_ideal_tile_count
);
2904 EXPECT_EQ(0, low_res_tile_count
);
2906 // With layer size being 1000x1000 and default tile size 256x256, we expect to
2907 // see 4 now tiles out of 16 total high res tiles.
2908 EXPECT_EQ(16, high_res_tile_count
);
2909 EXPECT_EQ(4, high_res_now_tiles
);
2910 EXPECT_EQ(low_res_tile_count
+ high_res_tile_count
+ non_ideal_tile_count
,
2911 static_cast<int>(unique_tiles
.size()));
2913 scoped_ptr
<TilingSetRasterQueueRequired
> required_queue(
2914 new TilingSetRasterQueueRequired(
2915 pending_layer_
->picture_layer_tiling_set(),
2916 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
));
2917 EXPECT_TRUE(required_queue
->IsEmpty());
2919 required_queue
.reset(new TilingSetRasterQueueRequired(
2920 pending_layer_
->picture_layer_tiling_set(),
2921 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
2922 EXPECT_FALSE(required_queue
->IsEmpty());
2923 int required_for_activation_count
= 0;
2924 while (!required_queue
->IsEmpty()) {
2925 Tile
* tile
= required_queue
->Top();
2926 EXPECT_TRUE(tile
->required_for_activation());
2927 EXPECT_FALSE(tile
->IsReadyToDraw());
2928 ++required_for_activation_count
;
2929 required_queue
->Pop();
2932 // All of the high res tiles should be required for activation, since there is
2934 EXPECT_EQ(high_res_now_tiles
, required_for_activation_count
);
2937 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
2938 host_impl_
.SetCurrentBeginFrameArgs(
2939 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2941 pending_layer_
->draw_properties().visible_content_rect
=
2942 gfx::Rect(1100, 1100, 500, 500);
2943 bool resourceless_software_draw
= false;
2944 pending_layer_
->UpdateTiles(resourceless_software_draw
);
2946 unique_tiles
.clear();
2947 high_res_tile_count
= 0u;
2948 queue
.reset(new TilingSetRasterQueueAll(
2949 pending_layer_
->picture_layer_tiling_set(), false));
2950 while (!queue
->IsEmpty()) {
2951 Tile
* tile
= queue
->Top();
2952 TilePriority priority
= tile
->priority(PENDING_TREE
);
2956 // Non-high res tiles only get visible tiles.
2957 EXPECT_EQ(HIGH_RESOLUTION
, priority
.resolution
);
2958 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
2960 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2962 unique_tiles
.insert(tile
);
2966 EXPECT_EQ(16, high_res_tile_count
);
2967 EXPECT_EQ(high_res_tile_count
, static_cast<int>(unique_tiles
.size()));
2969 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
2970 host_impl_
.SetCurrentBeginFrameArgs(
2971 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2973 pending_layer_
->draw_properties().visible_content_rect
=
2974 gfx::Rect(0, 0, 500, 500);
2975 pending_layer_
->UpdateTiles(resourceless_software_draw
);
2977 std::vector
<Tile
*> high_res_tiles
=
2978 pending_layer_
->HighResTiling()->AllTilesForTesting();
2979 for (std::vector
<Tile
*>::iterator tile_it
= high_res_tiles
.begin();
2980 tile_it
!= high_res_tiles
.end();
2982 Tile
* tile
= *tile_it
;
2983 TileDrawInfo
& draw_info
= tile
->draw_info();
2984 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
2987 non_ideal_tile_count
= 0;
2988 low_res_tile_count
= 0;
2989 high_res_tile_count
= 0;
2990 queue
.reset(new TilingSetRasterQueueAll(
2991 pending_layer_
->picture_layer_tiling_set(), true));
2992 while (!queue
->IsEmpty()) {
2993 Tile
* tile
= queue
->Top();
2994 TilePriority priority
= tile
->priority(PENDING_TREE
);
2998 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
2999 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
3000 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
3004 EXPECT_EQ(0, non_ideal_tile_count
);
3005 EXPECT_EQ(1, low_res_tile_count
);
3006 EXPECT_EQ(0, high_res_tile_count
);
3009 TEST_F(PictureLayerImplTest
, TilingSetRasterQueueActiveTree
) {
3010 base::TimeTicks time_ticks
;
3011 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
3012 host_impl_
.SetCurrentBeginFrameArgs(
3013 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3015 host_impl_
.SetViewportSize(gfx::Size(500, 500));
3017 gfx::Size
tile_size(100, 100);
3018 gfx::Size
layer_bounds(1000, 1000);
3020 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3021 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3023 SetupPendingTree(pending_pile
);
3025 EXPECT_EQ(2u, active_layer_
->num_tilings());
3027 scoped_ptr
<TilingSetRasterQueueRequired
> queue(
3028 new TilingSetRasterQueueRequired(
3029 active_layer_
->picture_layer_tiling_set(),
3030 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
));
3031 EXPECT_FALSE(queue
->IsEmpty());
3032 while (!queue
->IsEmpty()) {
3033 Tile
* tile
= queue
->Top();
3034 EXPECT_TRUE(tile
->required_for_draw());
3035 EXPECT_FALSE(tile
->IsReadyToDraw());
3039 queue
.reset(new TilingSetRasterQueueRequired(
3040 active_layer_
->picture_layer_tiling_set(),
3041 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
3042 EXPECT_TRUE(queue
->IsEmpty());
3045 TEST_F(PictureLayerImplTest
, TilingSetRasterQueueRequiredNoHighRes
) {
3046 scoped_ptr
<FakePicturePile
> empty_recording
=
3047 FakePicturePile::CreateEmptyPile(gfx::Size(256, 256),
3048 gfx::Size(1024, 1024));
3049 empty_recording
->SetIsSolidColor(true);
3051 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3052 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
3054 SetupPendingTree(pending_pile
);
3056 pending_layer_
->picture_layer_tiling_set()->FindTilingWithResolution(
3059 scoped_ptr
<TilingSetRasterQueueRequired
> queue(
3060 new TilingSetRasterQueueRequired(
3061 pending_layer_
->picture_layer_tiling_set(),
3062 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
3063 EXPECT_TRUE(queue
->IsEmpty());
3066 TEST_F(PictureLayerImplTest
, TilingSetEvictionQueue
) {
3067 gfx::Size
tile_size(100, 100);
3068 gfx::Size
layer_bounds(1000, 1000);
3069 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3071 host_impl_
.SetViewportSize(gfx::Size(500, 500));
3073 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3074 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3076 // TODO(vmpstr): Add a test with tilings other than high/low res on the active
3078 SetupPendingTree(pending_pile
);
3079 EXPECT_EQ(2u, pending_layer_
->num_tilings());
3081 std::vector
<Tile
*> all_tiles
;
3082 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3083 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3084 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
3085 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
3088 std::set
<Tile
*> all_tiles_set(all_tiles
.begin(), all_tiles
.end());
3090 bool mark_required
= false;
3091 size_t number_of_marked_tiles
= 0u;
3092 size_t number_of_unmarked_tiles
= 0u;
3093 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3094 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3095 for (PictureLayerTiling::CoverageIterator
iter(
3097 pending_layer_
->contents_scale_x(),
3098 pending_layer_
->visible_content_rect());
3101 if (mark_required
) {
3102 number_of_marked_tiles
++;
3103 iter
->set_required_for_activation(true);
3105 number_of_unmarked_tiles
++;
3107 mark_required
= !mark_required
;
3112 EXPECT_EQ(17u, all_tiles
.size());
3113 EXPECT_EQ(17u, all_tiles_set
.size());
3114 EXPECT_GT(number_of_marked_tiles
, 1u);
3115 EXPECT_GT(number_of_unmarked_tiles
, 1u);
3117 // Tiles don't have resources yet.
3118 scoped_ptr
<TilingSetEvictionQueue
> queue(new TilingSetEvictionQueue(
3119 pending_layer_
->picture_layer_tiling_set(), false));
3120 EXPECT_TRUE(queue
->IsEmpty());
3122 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
3124 std::set
<Tile
*> unique_tiles
;
3125 float expected_scales
[] = {low_res_factor
, 1.f
};
3126 size_t scale_index
= 0;
3127 bool reached_visible
= false;
3128 Tile
* last_tile
= nullptr;
3129 size_t distance_decreasing
= 0;
3130 size_t distance_increasing
= 0;
3131 queue
.reset(new TilingSetEvictionQueue(
3132 pending_layer_
->picture_layer_tiling_set(), false));
3133 while (!queue
->IsEmpty()) {
3134 Tile
* tile
= queue
->Top();
3140 TilePriority priority
= tile
->priority(PENDING_TREE
);
3142 if (priority
.priority_bin
== TilePriority::NOW
) {
3143 reached_visible
= true;
3148 EXPECT_FALSE(tile
->required_for_activation());
3150 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
3151 std::numeric_limits
<float>::epsilon()) {
3153 ASSERT_LT(scale_index
, arraysize(expected_scales
));
3156 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
3157 unique_tiles
.insert(tile
);
3159 if (tile
->required_for_activation() ==
3160 last_tile
->required_for_activation() &&
3161 std::abs(tile
->contents_scale() - last_tile
->contents_scale()) <
3162 std::numeric_limits
<float>::epsilon()) {
3163 if (priority
.distance_to_visible
<=
3164 last_tile
->priority(PENDING_TREE
).distance_to_visible
)
3165 ++distance_decreasing
;
3167 ++distance_increasing
;
3174 // 4 high res tiles are inside the viewport, the rest are evicted.
3175 EXPECT_TRUE(reached_visible
);
3176 EXPECT_EQ(12u, unique_tiles
.size());
3177 EXPECT_EQ(1u, distance_increasing
);
3178 EXPECT_EQ(11u, distance_decreasing
);
3181 bool reached_required
= false;
3182 while (!queue
->IsEmpty()) {
3183 Tile
* tile
= queue
->Top();
3186 TilePriority priority
= tile
->priority(PENDING_TREE
);
3187 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
3189 if (reached_required
) {
3190 EXPECT_TRUE(tile
->required_for_activation());
3191 } else if (tile
->required_for_activation()) {
3192 reached_required
= true;
3196 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
3197 std::numeric_limits
<float>::epsilon()) {
3199 ASSERT_LT(scale_index
, arraysize(expected_scales
));
3202 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
3203 unique_tiles
.insert(tile
);
3207 EXPECT_TRUE(reached_required
);
3208 EXPECT_EQ(all_tiles_set
.size(), unique_tiles
.size());
3211 TEST_F(PictureLayerImplTest
, Occlusion
) {
3212 gfx::Size
tile_size(102, 102);
3213 gfx::Size
layer_bounds(1000, 1000);
3214 gfx::Size
viewport_size(1000, 1000);
3216 LayerTestCommon::LayerImplTest impl
;
3217 host_impl_
.SetViewportSize(viewport_size
);
3219 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3220 FakePicturePileImpl::CreateFilledPile(layer_bounds
, layer_bounds
);
3221 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
3224 std::vector
<Tile
*> tiles
=
3225 active_layer_
->HighResTiling()->AllTilesForTesting();
3226 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3229 SCOPED_TRACE("No occlusion");
3231 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3233 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
3234 gfx::Rect(layer_bounds
));
3235 EXPECT_EQ(100u, impl
.quad_list().size());
3239 SCOPED_TRACE("Full occlusion");
3240 gfx::Rect
occluded(active_layer_
->visible_content_rect());
3241 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3243 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(), gfx::Rect());
3244 EXPECT_EQ(impl
.quad_list().size(), 0u);
3248 SCOPED_TRACE("Partial occlusion");
3249 gfx::Rect
occluded(150, 0, 200, 1000);
3250 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3252 size_t partially_occluded_count
= 0;
3253 LayerTestCommon::VerifyQuadsAreOccluded(
3254 impl
.quad_list(), occluded
, &partially_occluded_count
);
3255 // The layer outputs one quad, which is partially occluded.
3256 EXPECT_EQ(100u - 10u, impl
.quad_list().size());
3257 EXPECT_EQ(10u + 10u, partially_occluded_count
);
3261 TEST_F(PictureLayerImplTest
, RasterScaleChangeWithoutAnimation
) {
3262 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
3263 SetupDefaultTrees(tile_size
);
3265 ResetTilingsAndRasterScales();
3267 float contents_scale
= 2.f
;
3268 float device_scale
= 1.f
;
3269 float page_scale
= 1.f
;
3270 float maximum_animation_scale
= 1.f
;
3271 bool animating_transform
= false;
3273 SetContentsScaleOnBothLayers(contents_scale
,
3276 maximum_animation_scale
,
3277 animating_transform
);
3278 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
3280 // Changing the source scale without being in an animation will cause
3281 // the layer to reset its source scale to 1.f.
3282 contents_scale
= 3.f
;
3284 SetContentsScaleOnBothLayers(contents_scale
,
3287 maximum_animation_scale
,
3288 animating_transform
);
3289 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3291 // Further changes to the source scale will no longer be reflected in the
3293 contents_scale
= 0.5f
;
3295 SetContentsScaleOnBothLayers(contents_scale
,
3298 maximum_animation_scale
,
3299 animating_transform
);
3300 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3303 TEST_F(PictureLayerImplTest
, LowResReadyToDrawNotEnoughToActivate
) {
3304 gfx::Size
tile_size(100, 100);
3305 gfx::Size
layer_bounds(1000, 1000);
3307 // Make sure some tiles are not shared.
3308 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3309 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3311 // All pending layer tiles required are not ready.
3312 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3314 // Initialize all low-res tiles.
3315 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3317 // Low-res tiles should not be enough.
3318 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3320 // Initialize remaining tiles.
3321 pending_layer_
->SetAllTilesReady();
3323 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3326 TEST_F(PictureLayerImplTest
, HighResReadyToDrawEnoughToActivate
) {
3327 gfx::Size
tile_size(100, 100);
3328 gfx::Size
layer_bounds(1000, 1000);
3330 // Make sure some tiles are not shared.
3331 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3332 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3334 // All pending layer tiles required are not ready.
3335 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3337 // Initialize all high-res tiles.
3338 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3340 // High-res tiles should be enough, since they cover everything visible.
3341 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3344 TEST_F(PictureLayerImplTest
,
3345 SharedActiveHighResReadyAndPendingLowResReadyNotEnoughToActivate
) {
3346 gfx::Size
tile_size(100, 100);
3347 gfx::Size
layer_bounds(1000, 1000);
3349 // Make sure some tiles are not shared.
3350 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3351 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3353 // Initialize all high-res tiles in the active layer.
3354 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3355 // And all the low-res tiles in the pending layer.
3356 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3358 // The unshared high-res tiles are not ready, so we cannot activate.
3359 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3361 // When the unshared pending high-res tiles are ready, we can activate.
3362 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3363 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3366 TEST_F(PictureLayerImplTest
, SharedActiveHighResReadyNotEnoughToActivate
) {
3367 gfx::Size
tile_size(100, 100);
3368 gfx::Size
layer_bounds(1000, 1000);
3370 // Make sure some tiles are not shared.
3371 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3372 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3374 // Initialize all high-res tiles in the active layer.
3375 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3377 // The unshared high-res tiles are not ready, so we cannot activate.
3378 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3380 // When the unshared pending high-res tiles are ready, we can activate.
3381 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3382 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3385 TEST_F(NoLowResPictureLayerImplTest
, ManageTilingsCreatesTilings
) {
3386 gfx::Size
tile_size(400, 400);
3387 gfx::Size
layer_bounds(1300, 1900);
3389 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3390 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3391 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3392 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3394 SetupTrees(pending_pile
, active_pile
);
3396 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3397 EXPECT_LT(low_res_factor
, 1.f
);
3399 ResetTilingsAndRasterScales();
3401 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3402 6.f
, // ideal contents scale
3403 3.f
, // device scale
3405 1.f
, // maximum animation scale
3407 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3408 EXPECT_FLOAT_EQ(6.f
,
3409 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3411 // If we change the page scale factor, then we should get new tilings.
3412 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3413 6.6f
, // ideal contents scale
3414 3.f
, // device scale
3416 1.f
, // maximum animation scale
3418 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3419 EXPECT_FLOAT_EQ(6.6f
,
3420 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3422 // If we change the device scale factor, then we should get new tilings.
3423 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3424 7.26f
, // ideal contents scale
3425 3.3f
, // device scale
3427 1.f
, // maximum animation scale
3429 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
3430 EXPECT_FLOAT_EQ(7.26f
,
3431 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3433 // If we change the device scale factor, but end up at the same total scale
3434 // factor somehow, then we don't get new tilings.
3435 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3436 7.26f
, // ideal contents scale
3437 2.2f
, // device scale
3439 1.f
, // maximum animation scale
3441 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
3442 EXPECT_FLOAT_EQ(7.26f
,
3443 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3446 TEST_F(NoLowResPictureLayerImplTest
, PendingLayerOnlyHasHighResTiling
) {
3447 gfx::Size
tile_size(400, 400);
3448 gfx::Size
layer_bounds(1300, 1900);
3450 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3451 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3452 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3453 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3455 SetupTrees(pending_pile
, active_pile
);
3457 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3458 EXPECT_LT(low_res_factor
, 1.f
);
3460 ResetTilingsAndRasterScales();
3462 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3463 6.f
, // ideal contents scale
3464 3.f
, // device scale
3466 1.f
, // maximum animation scale
3468 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3469 EXPECT_FLOAT_EQ(6.f
,
3470 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3472 // If we change the page scale factor, then we should get new tilings.
3473 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3474 6.6f
, // ideal contents scale
3475 3.f
, // device scale
3477 1.f
, // maximum animation scale
3479 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3480 EXPECT_FLOAT_EQ(6.6f
,
3481 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3483 // If we change the device scale factor, then we should get new tilings.
3484 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3485 7.26f
, // ideal contents scale
3486 3.3f
, // device scale
3488 1.f
, // maximum animation scale
3490 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3491 EXPECT_FLOAT_EQ(7.26f
,
3492 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3494 // If we change the device scale factor, but end up at the same total scale
3495 // factor somehow, then we don't get new tilings.
3496 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3497 7.26f
, // ideal contents scale
3498 2.2f
, // device scale
3500 1.f
, // maximum animation scale
3502 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3503 EXPECT_FLOAT_EQ(7.26f
,
3504 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3507 TEST_F(NoLowResPictureLayerImplTest
, AllHighResRequiredEvenIfShared
) {
3508 gfx::Size
layer_bounds(400, 400);
3509 gfx::Size
tile_size(100, 100);
3511 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
3513 Tile
* some_active_tile
=
3514 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
3515 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
3517 // All tiles shared (no invalidation), so even though the active tree's
3518 // tiles aren't ready, there is nothing required.
3519 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
3520 if (host_impl_
.settings().create_low_res_tiling
)
3521 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
3523 AssertAllTilesRequired(pending_layer_
->HighResTiling());
3524 if (host_impl_
.settings().create_low_res_tiling
)
3525 AssertNoTilesRequired(pending_layer_
->LowResTiling());
3528 TEST_F(NoLowResPictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
3529 gfx::Size
layer_bounds(400, 400);
3530 gfx::Size
tile_size(100, 100);
3532 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3533 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3534 // This pile will create tilings, but has no recordings so will not create any
3535 // tiles. This is attempting to simulate scrolling past the end of recorded
3536 // content on the active layer, where the recordings are so far away that
3537 // no tiles are created.
3538 bool is_solid_color
= false;
3539 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3540 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
3541 tile_size
, layer_bounds
, is_solid_color
);
3543 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
3545 // Active layer has tilings, but no tiles due to missing recordings.
3546 EXPECT_TRUE(active_layer_
->CanHaveTilings());
3547 EXPECT_EQ(active_layer_
->tilings()->num_tilings(),
3548 host_impl_
.settings().create_low_res_tiling
? 2u : 1u);
3549 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
3551 // Since the active layer has no tiles at all, the pending layer doesn't
3552 // need content in order to activate.
3553 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
3554 if (host_impl_
.settings().create_low_res_tiling
)
3555 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
3557 AssertNoTilesRequired(pending_layer_
->HighResTiling());
3558 if (host_impl_
.settings().create_low_res_tiling
)
3559 AssertNoTilesRequired(pending_layer_
->LowResTiling());
3562 TEST_F(NoLowResPictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
3563 base::TimeTicks time_ticks
;
3564 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
3565 host_impl_
.SetCurrentBeginFrameArgs(
3566 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3568 gfx::Size
tile_size(100, 100);
3569 gfx::Size
layer_bounds(400, 400);
3571 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3572 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3573 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3574 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3576 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
3578 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
3580 // UpdateTiles with valid viewport. Should update tile viewport.
3581 // Note viewport is considered invalid if and only if in resourceless
3583 bool resourceless_software_draw
= false;
3584 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
3585 gfx::Transform transform
;
3586 host_impl_
.SetExternalDrawConstraints(transform
,
3591 resourceless_software_draw
);
3592 active_layer_
->draw_properties().visible_content_rect
= viewport
;
3593 active_layer_
->draw_properties().screen_space_transform
= transform
;
3594 active_layer_
->UpdateTiles(resourceless_software_draw
);
3596 gfx::Rect visible_rect_for_tile_priority
=
3597 active_layer_
->visible_rect_for_tile_priority();
3598 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
3599 gfx::Transform screen_space_transform_for_tile_priority
=
3600 active_layer_
->screen_space_transform();
3602 // Expand viewport and set it as invalid for prioritizing tiles.
3603 // Should update viewport and transform, but not update visible rect.
3604 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
3605 host_impl_
.SetCurrentBeginFrameArgs(
3606 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3607 resourceless_software_draw
= true;
3608 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
3609 transform
.Translate(1.f
, 1.f
);
3610 active_layer_
->draw_properties().visible_content_rect
= viewport
;
3611 active_layer_
->draw_properties().screen_space_transform
= transform
;
3612 host_impl_
.SetExternalDrawConstraints(transform
,
3617 resourceless_software_draw
);
3618 active_layer_
->UpdateTiles(resourceless_software_draw
);
3620 // Transform for tile priority is updated.
3621 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3622 active_layer_
->screen_space_transform());
3623 // Visible rect for tile priority retains old value.
3624 EXPECT_EQ(visible_rect_for_tile_priority
,
3625 active_layer_
->visible_rect_for_tile_priority());
3627 // Keep expanded viewport but mark it valid. Should update tile viewport.
3628 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
3629 host_impl_
.SetCurrentBeginFrameArgs(
3630 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3631 resourceless_software_draw
= false;
3632 host_impl_
.SetExternalDrawConstraints(transform
,
3637 resourceless_software_draw
);
3638 active_layer_
->UpdateTiles(resourceless_software_draw
);
3640 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3641 active_layer_
->screen_space_transform());
3642 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
3645 TEST_F(NoLowResPictureLayerImplTest
, CleanUpTilings
) {
3646 gfx::Size
tile_size(400, 400);
3647 gfx::Size
layer_bounds(1300, 1900);
3649 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3650 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3651 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3652 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3654 std::vector
<PictureLayerTiling
*> used_tilings
;
3656 SetupTrees(pending_pile
, active_pile
);
3658 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3659 EXPECT_LT(low_res_factor
, 1.f
);
3661 float device_scale
= 1.7f
;
3662 float page_scale
= 3.2f
;
3665 ResetTilingsAndRasterScales();
3667 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
3668 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3670 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
3671 // |used_tilings| variable, and it's here only to ensure that active_layer_
3672 // won't remove tilings before the test has a chance to verify behavior.
3673 active_layer_
->MarkAllTilingsUsed();
3675 // We only have ideal tilings, so they aren't removed.
3676 used_tilings
.clear();
3677 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3678 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3680 host_impl_
.PinchGestureBegin();
3682 // Changing the ideal but not creating new tilings.
3685 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
3686 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3688 // The tilings are still our target scale, so they aren't removed.
3689 used_tilings
.clear();
3690 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3691 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3693 host_impl_
.PinchGestureEnd();
3695 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
3698 SetContentsScaleOnBothLayers(1.2f
, device_scale
, page_scale
, 1.f
, false);
3699 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3700 EXPECT_FLOAT_EQ(1.f
,
3701 active_layer_
->tilings()->tiling_at(1)->contents_scale());
3703 // Ensure UpdateTiles won't remove any tilings.
3704 active_layer_
->MarkAllTilingsUsed();
3706 // Mark the non-ideal tilings as used. They won't be removed.
3707 used_tilings
.clear();
3708 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3709 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3710 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3712 // Now move the ideal scale to 0.5. Our target stays 1.2.
3713 SetContentsScaleOnBothLayers(0.5f
, device_scale
, page_scale
, 1.f
, false);
3715 // The high resolution tiling is between target and ideal, so is not
3716 // removed. The low res tiling for the old ideal=1.0 scale is removed.
3717 used_tilings
.clear();
3718 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3719 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3721 // Now move the ideal scale to 1.0. Our target stays 1.2.
3722 SetContentsScaleOnBothLayers(1.f
, device_scale
, page_scale
, 1.f
, false);
3724 // All the tilings are between are target and the ideal, so they are not
3726 used_tilings
.clear();
3727 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3728 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3730 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
3731 SetupDrawPropertiesAndUpdateTiles(
3732 active_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
3734 // Because the pending layer's ideal scale is still 1.0, our tilings fall
3735 // in the range [1.0,1.2] and are kept.
3736 used_tilings
.clear();
3737 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3738 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3740 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
3742 SetupDrawPropertiesAndUpdateTiles(
3743 pending_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
3745 // Our 1.0 tiling now falls outside the range between our ideal scale and our
3746 // target raster scale. But it is in our used tilings set, so nothing is
3748 used_tilings
.clear();
3749 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3750 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3751 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3753 // If we remove it from our used tilings set, it is outside the range to keep
3754 // so it is deleted.
3755 used_tilings
.clear();
3756 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3757 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3760 TEST_F(NoLowResPictureLayerImplTest
, ReleaseResources
) {
3761 gfx::Size
tile_size(400, 400);
3762 gfx::Size
layer_bounds(1300, 1900);
3764 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3765 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3766 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3767 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3769 SetupTrees(pending_pile
, active_pile
);
3770 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3771 EXPECT_EQ(1u, active_layer_
->tilings()->num_tilings());
3773 // All tilings should be removed when losing output surface.
3774 active_layer_
->ReleaseResources();
3775 EXPECT_FALSE(active_layer_
->tilings());
3776 active_layer_
->RecreateResources();
3777 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
3778 pending_layer_
->ReleaseResources();
3779 EXPECT_FALSE(pending_layer_
->tilings());
3780 pending_layer_
->RecreateResources();
3781 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
3783 // This should create new tilings.
3784 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3785 1.3f
, // ideal contents scale
3786 2.7f
, // device scale
3788 1.f
, // maximum animation scale
3790 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3793 TEST_F(PictureLayerImplTest
, SharedQuadStateContainsMaxTilingScale
) {
3794 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3796 gfx::Size
tile_size(400, 400);
3797 gfx::Size
layer_bounds(1000, 2000);
3799 host_impl_
.SetViewportSize(gfx::Size(10000, 20000));
3801 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3802 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3803 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3804 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3806 SetupTrees(pending_pile
, active_pile
);
3808 ResetTilingsAndRasterScales();
3809 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.5f
, 1.f
, 1.f
, 1.f
, false);
3811 float max_contents_scale
= active_layer_
->MaximumTilingContentsScale();
3812 EXPECT_EQ(2.5f
, max_contents_scale
);
3814 gfx::Transform scaled_draw_transform
= active_layer_
->draw_transform();
3815 scaled_draw_transform
.Scale(SK_MScalar1
/ max_contents_scale
,
3816 SK_MScalar1
/ max_contents_scale
);
3818 AppendQuadsData data
;
3819 active_layer_
->AppendQuads(render_pass
.get(), &data
);
3821 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
3822 EXPECT_EQ(1u, render_pass
->shared_quad_state_list
.size());
3823 // The content_to_target_transform should be scaled by the
3824 // MaximumTilingContentsScale on the layer.
3825 EXPECT_EQ(scaled_draw_transform
.ToString(),
3826 render_pass
->shared_quad_state_list
.front()
3827 ->content_to_target_transform
.ToString());
3828 // The content_bounds should be scaled by the
3829 // MaximumTilingContentsScale on the layer.
3831 gfx::Size(2500u, 5000u).ToString(),
3832 render_pass
->shared_quad_state_list
.front()->content_bounds
.ToString());
3833 // The visible_content_rect should be scaled by the
3834 // MaximumTilingContentsScale on the layer.
3835 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
3836 render_pass
->shared_quad_state_list
.front()
3837 ->visible_content_rect
.ToString());
3840 class PictureLayerImplTestWithDelegatingRenderer
: public PictureLayerImplTest
{
3842 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {}
3844 void InitializeRenderer() override
{
3845 host_impl_
.InitializeRenderer(FakeOutputSurface::CreateDelegating3d());
3849 TEST_F(PictureLayerImplTestWithDelegatingRenderer
,
3850 DelegatingRendererWithTileOOM
) {
3851 // This test is added for crbug.com/402321, where quad should be produced when
3852 // raster on demand is not allowed and tile is OOM.
3853 gfx::Size tile_size
= host_impl_
.settings().default_tile_size
;
3854 gfx::Size
layer_bounds(1000, 1000);
3857 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3858 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3859 SetupPendingTree(pending_pile
);
3860 pending_layer_
->SetBounds(layer_bounds
);
3862 bool update_lcd_text
= false;
3863 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
3864 std::vector
<Tile
*> tiles
=
3865 active_layer_
->HighResTiling()->AllTilesForTesting();
3866 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3868 // Force tiles after max_tiles to be OOM. TileManager uses
3869 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3870 // directly set state to host_impl_, so we set policy that would change the
3871 // state. We also need to update tree priority separately.
3872 GlobalStateThatImpactsTilePriority state
;
3873 size_t max_tiles
= 1;
3874 size_t memory_limit
= max_tiles
* 4 * tile_size
.width() * tile_size
.height();
3875 size_t resource_limit
= max_tiles
;
3876 ManagedMemoryPolicy
policy(memory_limit
,
3877 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
,
3879 host_impl_
.SetMemoryPolicy(policy
);
3880 host_impl_
.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES
);
3881 host_impl_
.PrepareTiles();
3883 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3884 AppendQuadsData data
;
3885 active_layer_
->WillDraw(DRAW_MODE_HARDWARE
, nullptr);
3886 active_layer_
->AppendQuads(render_pass
.get(), &data
);
3887 active_layer_
->DidDraw(nullptr);
3889 // Even when OOM, quads should be produced, and should be different material
3890 // from quads with resource.
3891 EXPECT_LT(max_tiles
, render_pass
->quad_list
.size());
3892 EXPECT_EQ(DrawQuad::Material::TILED_CONTENT
,
3893 render_pass
->quad_list
.front()->material
);
3894 EXPECT_EQ(DrawQuad::Material::SOLID_COLOR
,
3895 render_pass
->quad_list
.back()->material
);
3898 class OcclusionTrackingSettings
: public LowResTilingsSettings
{
3900 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization
= true; }
3903 class OcclusionTrackingPictureLayerImplTest
: public PictureLayerImplTest
{
3905 OcclusionTrackingPictureLayerImplTest()
3906 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
3908 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl
* layer
,
3909 FakePictureLayerImpl
* twin_layer
,
3911 size_t expected_occluded_tile_count
) {
3912 WhichTree twin_tree
= tree
== ACTIVE_TREE
? PENDING_TREE
: ACTIVE_TREE
;
3913 size_t occluded_tile_count
= 0u;
3914 Tile
* last_tile
= nullptr;
3915 std::set
<Tile
*> shared_tiles
;
3917 scoped_ptr
<TilingSetEvictionQueue
> queue(new TilingSetEvictionQueue(
3918 layer
->picture_layer_tiling_set(), layer
&& twin_layer
));
3919 while (!queue
->IsEmpty()) {
3920 Tile
* tile
= queue
->Top();
3923 if (tile
->is_shared())
3924 EXPECT_TRUE(shared_tiles
.insert(tile
).second
);
3926 // The only way we will encounter an occluded tile after an unoccluded
3927 // tile is if the priorty bin decreased, the tile is required for
3928 // activation, or the scale changed.
3929 bool tile_is_occluded
= tile
->is_occluded(tree
);
3930 if (tile_is_occluded
) {
3931 occluded_tile_count
++;
3933 bool last_tile_is_occluded
= last_tile
->is_occluded(tree
);
3934 if (!last_tile_is_occluded
) {
3935 TilePriority::PriorityBin tile_priority_bin
=
3936 tile
->priority(tree
).priority_bin
;
3937 TilePriority::PriorityBin last_tile_priority_bin
=
3938 last_tile
->priority(tree
).priority_bin
;
3940 EXPECT_TRUE(tile_priority_bin
< last_tile_priority_bin
||
3941 tile
->required_for_activation() ||
3942 tile
->contents_scale() != last_tile
->contents_scale());
3948 // Count also shared tiles which are occluded in the tree but which were
3949 // not returned by the tiling set eviction queue. Those shared tiles
3950 // shall be returned by the twin tiling set eviction queue.
3951 queue
.reset(new TilingSetEvictionQueue(
3952 twin_layer
->picture_layer_tiling_set(), layer
&& twin_layer
));
3953 while (!queue
->IsEmpty()) {
3954 Tile
* tile
= queue
->Top();
3955 if (tile
->is_shared()) {
3956 EXPECT_TRUE(shared_tiles
.insert(tile
).second
);
3957 if (tile
->is_occluded(tree
))
3958 ++occluded_tile_count
;
3959 // Check the reasons why the shared tile was not returned by
3960 // the first tiling set eviction queue.
3961 const TilePriority
& combined_priority
= tile
->combined_priority();
3962 const TilePriority
& priority
= tile
->priority(tree
);
3963 const TilePriority
& twin_priority
= tile
->priority(twin_tree
);
3964 // Check if the shared tile was not returned by the first tiling
3965 // set eviction queue because it was out of order for the first
3966 // tiling set eviction queue but not for the twin tiling set
3968 if (priority
.priority_bin
!= twin_priority
.priority_bin
) {
3969 EXPECT_LT(combined_priority
.priority_bin
, priority
.priority_bin
);
3970 EXPECT_EQ(combined_priority
.priority_bin
, twin_priority
.priority_bin
);
3971 } else if (tile
->is_occluded(tree
) != tile
->is_occluded(twin_tree
)) {
3972 EXPECT_TRUE(tile
->is_occluded(tree
));
3973 EXPECT_FALSE(tile
->is_occluded(twin_tree
));
3974 EXPECT_FALSE(tile
->is_occluded_combined());
3975 } else if (priority
.distance_to_visible
!=
3976 twin_priority
.distance_to_visible
) {
3977 EXPECT_LT(combined_priority
.distance_to_visible
,
3978 priority
.distance_to_visible
);
3979 EXPECT_EQ(combined_priority
.distance_to_visible
,
3980 twin_priority
.distance_to_visible
);
3982 // Shared tiles having the same active and pending priorities
3983 // should be returned only by a pending tree eviction queue.
3984 EXPECT_EQ(ACTIVE_TREE
, tree
);
3989 EXPECT_EQ(expected_occluded_tile_count
, occluded_tile_count
);
3993 TEST_F(OcclusionTrackingPictureLayerImplTest
,
3994 OccludedTilesSkippedDuringRasterization
) {
3995 base::TimeTicks time_ticks
;
3996 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
3997 host_impl_
.SetCurrentBeginFrameArgs(
3998 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4000 gfx::Size
tile_size(102, 102);
4001 gfx::Size
layer_bounds(1000, 1000);
4002 gfx::Size
viewport_size(500, 500);
4003 gfx::Point
occluding_layer_position(310, 0);
4005 host_impl_
.SetViewportSize(viewport_size
);
4007 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4008 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4009 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4012 int unoccluded_tile_count
= 0;
4013 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
4014 pending_layer_
->picture_layer_tiling_set(), false));
4015 while (!queue
->IsEmpty()) {
4016 Tile
* tile
= queue
->Top();
4018 // Occluded tiles should not be iterated over.
4019 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4021 // Some tiles may not be visible (i.e. outside the viewport). The rest are
4022 // visible and at least partially unoccluded, verified by the above expect.
4023 bool tile_is_visible
=
4024 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
4025 if (tile_is_visible
)
4026 unoccluded_tile_count
++;
4029 EXPECT_EQ(unoccluded_tile_count
, 25);
4031 // Partial occlusion.
4032 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4033 LayerImpl
* layer1
= pending_layer_
->children()[0];
4034 layer1
->SetBounds(layer_bounds
);
4035 layer1
->SetContentBounds(layer_bounds
);
4036 layer1
->SetDrawsContent(true);
4037 layer1
->SetContentsOpaque(true);
4038 layer1
->SetPosition(occluding_layer_position
);
4040 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4041 host_impl_
.SetCurrentBeginFrameArgs(
4042 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4043 bool update_lcd_text
= false;
4044 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4046 unoccluded_tile_count
= 0;
4047 queue
.reset(new TilingSetRasterQueueAll(
4048 pending_layer_
->picture_layer_tiling_set(), false));
4049 while (!queue
->IsEmpty()) {
4050 Tile
* tile
= queue
->Top();
4052 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4054 bool tile_is_visible
=
4055 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
4056 if (tile_is_visible
)
4057 unoccluded_tile_count
++;
4060 EXPECT_EQ(20, unoccluded_tile_count
);
4063 layer1
->SetPosition(gfx::Point(0, 0));
4065 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4066 host_impl_
.SetCurrentBeginFrameArgs(
4067 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4068 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4070 unoccluded_tile_count
= 0;
4071 queue
.reset(new TilingSetRasterQueueAll(
4072 pending_layer_
->picture_layer_tiling_set(), false));
4073 while (!queue
->IsEmpty()) {
4074 Tile
* tile
= queue
->Top();
4076 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4078 bool tile_is_visible
=
4079 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
4080 if (tile_is_visible
)
4081 unoccluded_tile_count
++;
4084 EXPECT_EQ(unoccluded_tile_count
, 0);
4087 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4088 OccludedTilesNotMarkedAsRequired
) {
4089 base::TimeTicks time_ticks
;
4090 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4091 host_impl_
.SetCurrentBeginFrameArgs(
4092 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4094 gfx::Size
tile_size(102, 102);
4095 gfx::Size
layer_bounds(1000, 1000);
4096 gfx::Size
viewport_size(500, 500);
4097 gfx::Point
occluding_layer_position(310, 0);
4099 host_impl_
.SetViewportSize(viewport_size
);
4101 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4102 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4103 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4106 int occluded_tile_count
= 0;
4107 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4108 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4110 occluded_tile_count
= 0;
4111 for (PictureLayerTiling::CoverageIterator
iter(
4113 pending_layer_
->contents_scale_x(),
4114 gfx::Rect(layer_bounds
));
4119 const Tile
* tile
= *iter
;
4121 // Fully occluded tiles are not required for activation.
4122 if (tile
->is_occluded(PENDING_TREE
)) {
4123 EXPECT_FALSE(tile
->required_for_activation());
4124 occluded_tile_count
++;
4127 EXPECT_EQ(occluded_tile_count
, 0);
4130 // Partial occlusion.
4131 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4132 LayerImpl
* layer1
= pending_layer_
->children()[0];
4133 layer1
->SetBounds(layer_bounds
);
4134 layer1
->SetContentBounds(layer_bounds
);
4135 layer1
->SetDrawsContent(true);
4136 layer1
->SetContentsOpaque(true);
4137 layer1
->SetPosition(occluding_layer_position
);
4139 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4140 host_impl_
.SetCurrentBeginFrameArgs(
4141 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4142 bool update_lcd_text
= false;
4143 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4145 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4146 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4147 tiling
->UpdateAllTilePrioritiesForTesting();
4149 occluded_tile_count
= 0;
4150 for (PictureLayerTiling::CoverageIterator
iter(
4152 pending_layer_
->contents_scale_x(),
4153 gfx::Rect(layer_bounds
));
4158 const Tile
* tile
= *iter
;
4160 if (tile
->is_occluded(PENDING_TREE
)) {
4161 EXPECT_FALSE(tile
->required_for_activation());
4162 occluded_tile_count
++;
4167 EXPECT_EQ(occluded_tile_count
, 5);
4170 EXPECT_EQ(occluded_tile_count
, 2);
4178 layer1
->SetPosition(gfx::PointF(0, 0));
4180 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4181 host_impl_
.SetCurrentBeginFrameArgs(
4182 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4183 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4185 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4186 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4187 tiling
->UpdateAllTilePrioritiesForTesting();
4189 occluded_tile_count
= 0;
4190 for (PictureLayerTiling::CoverageIterator
iter(
4192 pending_layer_
->contents_scale_x(),
4193 gfx::Rect(layer_bounds
));
4198 const Tile
* tile
= *iter
;
4200 if (tile
->is_occluded(PENDING_TREE
)) {
4201 EXPECT_FALSE(tile
->required_for_activation());
4202 occluded_tile_count
++;
4207 EXPECT_EQ(25, occluded_tile_count
);
4210 EXPECT_EQ(4, occluded_tile_count
);
4218 TEST_F(OcclusionTrackingPictureLayerImplTest
, OcclusionForDifferentScales
) {
4219 base::TimeTicks time_ticks
;
4220 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4221 host_impl_
.SetCurrentBeginFrameArgs(
4222 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4224 gfx::Size
tile_size(102, 102);
4225 gfx::Size
layer_bounds(1000, 1000);
4226 gfx::Size
viewport_size(500, 500);
4227 gfx::Point
occluding_layer_position(310, 0);
4229 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4230 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4232 host_impl_
.SetViewportSize(viewport_size
);
4234 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4235 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
4237 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4238 LayerImpl
* layer1
= pending_layer_
->children()[0];
4239 layer1
->SetBounds(layer_bounds
);
4240 layer1
->SetContentBounds(layer_bounds
);
4241 layer1
->SetDrawsContent(true);
4242 layer1
->SetContentsOpaque(true);
4243 layer1
->SetPosition(occluding_layer_position
);
4245 pending_layer_
->tilings()->RemoveAllTilings();
4246 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
4247 pending_layer_
->AddTiling(low_res_factor
);
4248 pending_layer_
->AddTiling(0.3f
);
4249 pending_layer_
->AddTiling(0.7f
);
4250 pending_layer_
->AddTiling(1.0f
);
4251 pending_layer_
->AddTiling(2.0f
);
4253 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4254 host_impl_
.SetCurrentBeginFrameArgs(
4255 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4256 // UpdateDrawProperties with the occluding layer.
4257 bool update_lcd_text
= false;
4258 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4260 EXPECT_EQ(5u, pending_layer_
->num_tilings());
4262 int occluded_tile_count
= 0;
4263 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4264 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4265 tiling
->UpdateAllTilePrioritiesForTesting();
4266 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4268 occluded_tile_count
= 0;
4269 for (size_t j
= 0; j
< tiles
.size(); ++j
) {
4270 if (tiles
[j
]->is_occluded(PENDING_TREE
)) {
4271 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4272 tiles
[j
]->content_rect(), 1.0f
/ tiles
[j
]->contents_scale());
4273 EXPECT_GE(scaled_content_rect
.x(), occluding_layer_position
.x());
4274 occluded_tile_count
++;
4280 EXPECT_EQ(occluded_tile_count
, 30);
4283 EXPECT_EQ(occluded_tile_count
, 5);
4286 EXPECT_EQ(occluded_tile_count
, 4);
4290 EXPECT_EQ(occluded_tile_count
, 2);
4298 TEST_F(OcclusionTrackingPictureLayerImplTest
, DifferentOcclusionOnTrees
) {
4299 gfx::Size
tile_size(102, 102);
4300 gfx::Size
layer_bounds(1000, 1000);
4301 gfx::Size
viewport_size(1000, 1000);
4302 gfx::Point
occluding_layer_position(310, 0);
4303 gfx::Rect
invalidation_rect(230, 230, 102, 102);
4305 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4306 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4307 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4308 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4310 host_impl_
.SetViewportSize(viewport_size
);
4311 SetupPendingTree(active_pile
);
4313 // Partially occlude the active layer.
4314 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 2));
4315 LayerImpl
* layer1
= pending_layer_
->children()[0];
4316 layer1
->SetBounds(layer_bounds
);
4317 layer1
->SetContentBounds(layer_bounds
);
4318 layer1
->SetDrawsContent(true);
4319 layer1
->SetContentsOpaque(true);
4320 layer1
->SetPosition(occluding_layer_position
);
4324 // Partially invalidate the pending layer.
4325 SetupPendingTreeWithInvalidation(pending_pile
, invalidation_rect
);
4327 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4328 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4329 tiling
->UpdateAllTilePrioritiesForTesting();
4331 for (PictureLayerTiling::CoverageIterator
iter(
4333 pending_layer_
->contents_scale_x(),
4334 gfx::Rect(layer_bounds
));
4339 const Tile
* tile
= *iter
;
4341 // All tiles are unoccluded on the pending tree.
4342 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4344 Tile
* twin_tile
= pending_layer_
->GetPendingOrActiveTwinTiling(tiling
)
4345 ->TileAt(iter
.i(), iter
.j());
4346 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4347 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4349 if (scaled_content_rect
.Intersects(invalidation_rect
)) {
4350 // Tiles inside the invalidation rect are only on the pending tree.
4351 EXPECT_NE(tile
, twin_tile
);
4353 // Unshared tiles should be unoccluded on the active tree by default.
4354 EXPECT_FALSE(tile
->is_occluded(ACTIVE_TREE
));
4356 // Tiles outside the invalidation rect are shared between both trees.
4357 EXPECT_EQ(tile
, twin_tile
);
4358 // Shared tiles are occluded on the active tree iff they lie beneath the
4360 EXPECT_EQ(tile
->is_occluded(ACTIVE_TREE
),
4361 scaled_content_rect
.x() >= occluding_layer_position
.x());
4366 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4367 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4369 for (PictureLayerTiling::CoverageIterator
iter(
4371 active_layer_
->contents_scale_x(),
4372 gfx::Rect(layer_bounds
));
4377 const Tile
* tile
= *iter
;
4379 Tile
* twin_tile
= active_layer_
->GetPendingOrActiveTwinTiling(tiling
)
4380 ->TileAt(iter
.i(), iter
.j());
4381 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4382 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4384 // Since we've already checked the shared tiles, only consider tiles in
4385 // the invalidation rect.
4386 if (scaled_content_rect
.Intersects(invalidation_rect
)) {
4387 // Tiles inside the invalidation rect are only on the active tree.
4388 EXPECT_NE(tile
, twin_tile
);
4390 // Unshared tiles should be unoccluded on the pending tree by default.
4391 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4393 // Unshared tiles are occluded on the active tree iff they lie beneath
4394 // the occluding layer.
4395 EXPECT_EQ(tile
->is_occluded(ACTIVE_TREE
),
4396 scaled_content_rect
.x() >= occluding_layer_position
.x());
4402 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4403 OccludedTilesConsideredDuringEviction
) {
4404 base::TimeTicks time_ticks
;
4405 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4406 host_impl_
.SetCurrentBeginFrameArgs(
4407 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4409 gfx::Size
tile_size(102, 102);
4410 gfx::Size
layer_bounds(1000, 1000);
4411 gfx::Size
viewport_size(1000, 1000);
4412 gfx::Point
pending_occluding_layer_position(310, 0);
4413 gfx::Point
active_occluding_layer_position(0, 310);
4414 gfx::Rect
invalidation_rect(230, 230, 102, 102);
4416 host_impl_
.SetViewportSize(viewport_size
);
4417 host_impl_
.SetDeviceScaleFactor(2.f
);
4419 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4420 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4421 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4422 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4424 SetupPendingTreeWithFixedTileSize(active_pile
, tile_size
, Region());
4426 // Partially occlude the active layer.
4427 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 2));
4428 LayerImpl
* active_occluding_layer
= pending_layer_
->children()[0];
4429 active_occluding_layer
->SetBounds(layer_bounds
);
4430 active_occluding_layer
->SetContentBounds(layer_bounds
);
4431 active_occluding_layer
->SetDrawsContent(true);
4432 active_occluding_layer
->SetContentsOpaque(true);
4433 active_occluding_layer
->SetPosition(active_occluding_layer_position
);
4437 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4438 // are not shared between trees.
4439 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, invalidation_rect
);
4441 // Partially occlude the pending layer in a different way.
4442 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 3));
4443 LayerImpl
* pending_occluding_layer
= pending_layer_
->children()[0];
4444 pending_occluding_layer
->SetBounds(layer_bounds
);
4445 pending_occluding_layer
->SetContentBounds(layer_bounds
);
4446 pending_occluding_layer
->SetDrawsContent(true);
4447 pending_occluding_layer
->SetContentsOpaque(true);
4448 pending_occluding_layer
->SetPosition(pending_occluding_layer_position
);
4450 EXPECT_EQ(2u, pending_layer_
->num_tilings());
4451 EXPECT_EQ(2u, active_layer_
->num_tilings());
4453 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4454 host_impl_
.SetCurrentBeginFrameArgs(
4455 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4456 // UpdateDrawProperties with the occluding layer.
4457 bool update_lcd_text
= false;
4458 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4460 // The expected number of occluded tiles on each of the 2 tilings for each of
4461 // the 3 tree priorities.
4462 size_t expected_occluded_tile_count_on_both
[] = {9u, 1u};
4463 size_t expected_occluded_tile_count_on_active
[] = {30u, 3u};
4464 size_t expected_occluded_tile_count_on_pending
[] = {30u, 3u};
4466 size_t total_expected_occluded_tile_count_on_trees
[] = {33u, 33u};
4468 // Verify number of occluded tiles on the pending layer for each tiling.
4469 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4470 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4471 tiling
->UpdateAllTilePrioritiesForTesting();
4473 size_t occluded_tile_count_on_pending
= 0u;
4474 size_t occluded_tile_count_on_active
= 0u;
4475 size_t occluded_tile_count_on_both
= 0u;
4476 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4477 gfx::Rect(layer_bounds
));
4483 if (tile
->is_occluded(PENDING_TREE
))
4484 occluded_tile_count_on_pending
++;
4485 if (tile
->is_occluded(ACTIVE_TREE
))
4486 occluded_tile_count_on_active
++;
4487 if (tile
->is_occluded(PENDING_TREE
) && tile
->is_occluded(ACTIVE_TREE
))
4488 occluded_tile_count_on_both
++;
4490 EXPECT_EQ(expected_occluded_tile_count_on_pending
[i
],
4491 occluded_tile_count_on_pending
)
4492 << tiling
->contents_scale();
4493 EXPECT_EQ(expected_occluded_tile_count_on_active
[i
],
4494 occluded_tile_count_on_active
)
4495 << tiling
->contents_scale();
4496 EXPECT_EQ(expected_occluded_tile_count_on_both
[i
],
4497 occluded_tile_count_on_both
)
4498 << tiling
->contents_scale();
4501 // Verify number of occluded tiles on the active layer for each tiling.
4502 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4503 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4504 tiling
->UpdateAllTilePrioritiesForTesting();
4506 size_t occluded_tile_count_on_pending
= 0u;
4507 size_t occluded_tile_count_on_active
= 0u;
4508 size_t occluded_tile_count_on_both
= 0u;
4509 for (PictureLayerTiling::CoverageIterator
iter(
4511 pending_layer_
->contents_scale_x(),
4512 gfx::Rect(layer_bounds
));
4519 if (tile
->is_occluded(PENDING_TREE
))
4520 occluded_tile_count_on_pending
++;
4521 if (tile
->is_occluded(ACTIVE_TREE
))
4522 occluded_tile_count_on_active
++;
4523 if (tile
->is_occluded(PENDING_TREE
) && tile
->is_occluded(ACTIVE_TREE
))
4524 occluded_tile_count_on_both
++;
4526 EXPECT_EQ(expected_occluded_tile_count_on_pending
[i
],
4527 occluded_tile_count_on_pending
)
4529 EXPECT_EQ(expected_occluded_tile_count_on_active
[i
],
4530 occluded_tile_count_on_active
)
4532 EXPECT_EQ(expected_occluded_tile_count_on_both
[i
],
4533 occluded_tile_count_on_both
)
4537 std::vector
<Tile
*> all_tiles
;
4538 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4539 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4540 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4541 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
4544 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
4546 VerifyEvictionConsidersOcclusion(
4547 pending_layer_
, active_layer_
, PENDING_TREE
,
4548 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
]);
4549 VerifyEvictionConsidersOcclusion(
4550 active_layer_
, pending_layer_
, ACTIVE_TREE
,
4551 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
]);
4553 // Repeat the tests without valid active tree priorities.
4554 active_layer_
->set_has_valid_tile_priorities(false);
4555 VerifyEvictionConsidersOcclusion(
4556 pending_layer_
, active_layer_
, PENDING_TREE
,
4557 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
]);
4558 VerifyEvictionConsidersOcclusion(
4559 active_layer_
, pending_layer_
, ACTIVE_TREE
, 0u);
4560 active_layer_
->set_has_valid_tile_priorities(true);
4562 // Repeat the tests without valid pending tree priorities.
4563 pending_layer_
->set_has_valid_tile_priorities(false);
4564 VerifyEvictionConsidersOcclusion(
4565 active_layer_
, pending_layer_
, ACTIVE_TREE
,
4566 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
]);
4567 VerifyEvictionConsidersOcclusion(
4568 pending_layer_
, active_layer_
, PENDING_TREE
, 0u);
4569 pending_layer_
->set_has_valid_tile_priorities(true);
4572 TEST_F(PictureLayerImplTest
, PendingOrActiveTwinLayer
) {
4573 gfx::Size
tile_size(102, 102);
4574 gfx::Size
layer_bounds(1000, 1000);
4576 scoped_refptr
<FakePicturePileImpl
> pile
=
4577 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4578 SetupPendingTree(pile
);
4579 EXPECT_FALSE(pending_layer_
->GetPendingOrActiveTwinLayer());
4582 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4584 SetupPendingTree(pile
);
4585 EXPECT_TRUE(pending_layer_
->GetPendingOrActiveTwinLayer());
4586 EXPECT_TRUE(active_layer_
->GetPendingOrActiveTwinLayer());
4587 EXPECT_EQ(pending_layer_
, active_layer_
->GetPendingOrActiveTwinLayer());
4588 EXPECT_EQ(active_layer_
, pending_layer_
->GetPendingOrActiveTwinLayer());
4591 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4593 // Make an empty pending tree.
4594 host_impl_
.CreatePendingTree();
4595 host_impl_
.pending_tree()->DetachLayerTree();
4596 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4599 TEST_F(PictureLayerImplTest
, RecycledTwinLayer
) {
4600 gfx::Size
tile_size(102, 102);
4601 gfx::Size
layer_bounds(1000, 1000);
4603 scoped_refptr
<FakePicturePileImpl
> pile
=
4604 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4605 SetupPendingTree(pile
);
4606 EXPECT_FALSE(pending_layer_
->GetRecycledTwinLayer());
4609 EXPECT_TRUE(active_layer_
->GetRecycledTwinLayer());
4610 EXPECT_EQ(old_pending_layer_
, active_layer_
->GetRecycledTwinLayer());
4612 SetupPendingTree(pile
);
4613 EXPECT_FALSE(pending_layer_
->GetRecycledTwinLayer());
4614 EXPECT_FALSE(active_layer_
->GetRecycledTwinLayer());
4617 EXPECT_TRUE(active_layer_
->GetRecycledTwinLayer());
4618 EXPECT_EQ(old_pending_layer_
, active_layer_
->GetRecycledTwinLayer());
4620 // Make an empty pending tree.
4621 host_impl_
.CreatePendingTree();
4622 host_impl_
.pending_tree()->DetachLayerTree();
4623 EXPECT_FALSE(active_layer_
->GetRecycledTwinLayer());
4626 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid
) {
4627 base::TimeTicks time_ticks
;
4628 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4629 host_impl_
.SetCurrentBeginFrameArgs(
4630 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4632 gfx::Size
tile_size(100, 100);
4633 gfx::Size
layer_bounds(200, 200);
4634 gfx::Rect
layer_rect(layer_bounds
);
4636 FakeContentLayerClient client
;
4637 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
4638 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4639 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&host_client
);
4640 host
->SetRootLayer(layer
);
4641 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4643 int frame_number
= 0;
4645 client
.set_fill_with_nonsolid_color(!test_for_solid
);
4647 Region
invalidation(layer_rect
);
4648 recording_source
->UpdateAndExpandInvalidation(
4649 &client
, &invalidation
, layer_bounds
, layer_rect
, frame_number
++,
4650 RecordingSource::RECORD_NORMALLY
);
4652 scoped_refptr
<RasterSource
> pending_raster_source
=
4653 recording_source
->CreateRasterSource(true);
4655 SetupPendingTreeWithFixedTileSize(pending_raster_source
, tile_size
, Region());
4658 if (test_for_solid
) {
4659 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4661 ASSERT_TRUE(active_layer_
->tilings());
4662 ASSERT_GT(active_layer_
->tilings()->num_tilings(), 0u);
4663 std::vector
<Tile
*> tiles
=
4664 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
4665 EXPECT_FALSE(tiles
.empty());
4666 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4669 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
4670 AppendQuadsData data
;
4671 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
4672 active_layer_
->AppendQuads(render_pass
.get(), &data
);
4673 active_layer_
->DidDraw(nullptr);
4675 DrawQuad::Material expected
= test_for_solid
4676 ? DrawQuad::Material::SOLID_COLOR
4677 : DrawQuad::Material::TILED_CONTENT
;
4678 EXPECT_EQ(expected
, render_pass
->quad_list
.front()->material
);
4681 TEST_F(PictureLayerImplTest
, DrawSolidQuads
) {
4682 TestQuadsForSolidColor(true);
4685 TEST_F(PictureLayerImplTest
, DrawNonSolidQuads
) {
4686 TestQuadsForSolidColor(false);
4689 TEST_F(PictureLayerImplTest
, NonSolidToSolidNoTilings
) {
4690 base::TimeTicks time_ticks
;
4691 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4692 host_impl_
.SetCurrentBeginFrameArgs(
4693 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4695 gfx::Size
tile_size(100, 100);
4696 gfx::Size
layer_bounds(200, 200);
4697 gfx::Rect
layer_rect(layer_bounds
);
4699 FakeContentLayerClient client
;
4700 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
4701 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4702 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&host_client
);
4703 host
->SetRootLayer(layer
);
4704 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4706 int frame_number
= 0;
4708 client
.set_fill_with_nonsolid_color(true);
4710 Region
invalidation1(layer_rect
);
4711 recording_source
->UpdateAndExpandInvalidation(
4712 &client
, &invalidation1
, layer_bounds
, layer_rect
, frame_number
++,
4713 RecordingSource::RECORD_NORMALLY
);
4715 scoped_refptr
<RasterSource
> raster_source1
=
4716 recording_source
->CreateRasterSource(true);
4718 SetupPendingTree(raster_source1
);
4720 bool update_lcd_text
= false;
4721 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
4723 // We've started with a solid layer that contains some tilings.
4724 ASSERT_TRUE(active_layer_
->tilings());
4725 EXPECT_NE(0u, active_layer_
->tilings()->num_tilings());
4727 client
.set_fill_with_nonsolid_color(false);
4729 Region
invalidation2(layer_rect
);
4730 recording_source
->UpdateAndExpandInvalidation(
4731 &client
, &invalidation2
, layer_bounds
, layer_rect
, frame_number
++,
4732 RecordingSource::RECORD_NORMALLY
);
4734 scoped_refptr
<RasterSource
> raster_source2
=
4735 recording_source
->CreateRasterSource(true);
4737 SetupPendingTree(raster_source2
);
4740 // We've switched to a solid color, so we should end up with no tilings.
4741 ASSERT_TRUE(active_layer_
->tilings());
4742 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4745 TEST_F(PictureLayerImplTest
, ChangeInViewportAllowsTilingUpdates
) {
4746 base::TimeTicks time_ticks
;
4747 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4748 host_impl_
.SetCurrentBeginFrameArgs(
4749 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4751 gfx::Size
tile_size(100, 100);
4752 gfx::Size
layer_bounds(400, 4000);
4754 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4755 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4756 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4757 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4759 SetupTrees(pending_pile
, active_pile
);
4761 Region invalidation
;
4762 gfx::Rect viewport
= gfx::Rect(0, 0, 100, 100);
4763 gfx::Transform transform
;
4765 host_impl_
.SetRequiresHighResToDraw();
4768 pending_layer_
->draw_properties().visible_content_rect
= viewport
;
4769 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4770 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
4771 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
4773 // Ensure we can't activate.
4774 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
4776 // Now in the same frame, move the viewport (this can happen during
4778 viewport
= gfx::Rect(0, 2000, 100, 100);
4781 pending_layer_
->draw_properties().visible_content_rect
= viewport
;
4782 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4783 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
4784 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
4786 // Make sure all viewport tiles (viewport from the tiling) are ready to draw.
4787 std::vector
<Tile
*> tiles
;
4788 for (PictureLayerTiling::CoverageIterator
iter(
4789 pending_layer_
->HighResTiling(),
4791 pending_layer_
->HighResTiling()->GetCurrentVisibleRectForTesting());
4795 tiles
.push_back(*iter
);
4798 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4800 // Ensure we can activate.
4801 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
4804 TEST_F(PictureLayerImplTest
, CloneMissingRecordings
) {
4805 gfx::Size
tile_size(100, 100);
4806 gfx::Size
layer_bounds(400, 400);
4808 scoped_refptr
<FakePicturePileImpl
> filled_pile
=
4809 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4811 scoped_ptr
<FakePicturePile
> partial_recording
=
4812 FakePicturePile::CreateEmptyPile(tile_size
, layer_bounds
);
4813 for (int i
= 1; i
< partial_recording
->tiling().num_tiles_x(); ++i
) {
4814 for (int j
= 1; j
< partial_recording
->tiling().num_tiles_y(); ++j
)
4815 partial_recording
->AddRecordingAt(i
, j
);
4817 scoped_refptr
<FakePicturePileImpl
> partial_pile
=
4818 FakePicturePileImpl::CreateFromPile(partial_recording
.get(), nullptr);
4820 SetupPendingTreeWithFixedTileSize(filled_pile
, tile_size
, Region());
4823 PictureLayerTiling
* pending_tiling
= old_pending_layer_
->HighResTiling();
4824 PictureLayerTiling
* active_tiling
= active_layer_
->HighResTiling();
4826 // We should have all tiles in both tile sets.
4827 EXPECT_EQ(5u * 5u, pending_tiling
->AllTilesForTesting().size());
4828 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4830 // Now put a partially-recorded pile on the pending tree (and invalidate
4831 // everything, since the main thread PicturePile will invalidate dropped
4832 // recordings). This will cause us to be missing some tiles.
4833 SetupPendingTreeWithFixedTileSize(partial_pile
, tile_size
,
4834 Region(gfx::Rect(layer_bounds
)));
4835 EXPECT_EQ(3u * 3u, pending_tiling
->AllTilesForTesting().size());
4836 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
4837 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
4838 EXPECT_TRUE(pending_tiling
->TileAt(2, 2));
4840 // Active is not affected yet.
4841 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4843 // Activate the tree. The same tiles go missing on the active tree.
4845 EXPECT_EQ(3u * 3u, active_tiling
->AllTilesForTesting().size());
4846 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
4847 EXPECT_FALSE(active_tiling
->TileAt(1, 1));
4848 EXPECT_TRUE(active_tiling
->TileAt(2, 2));
4850 // Now put a full recording on the pending tree again. We'll get all our tiles
4852 SetupPendingTreeWithFixedTileSize(filled_pile
, tile_size
,
4853 Region(gfx::Rect(layer_bounds
)));
4854 EXPECT_EQ(5u * 5u, pending_tiling
->AllTilesForTesting().size());
4856 // Active is not affected yet.
4857 EXPECT_EQ(3u * 3u, active_tiling
->AllTilesForTesting().size());
4859 // Activate the tree. The tiles are created and shared on the active tree.
4861 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4862 EXPECT_TRUE(active_tiling
->TileAt(0, 0)->is_shared());
4863 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
4864 EXPECT_TRUE(active_tiling
->TileAt(2, 2)->is_shared());
4867 class TileSizeSettings
: public ImplSidePaintingSettings
{
4869 TileSizeSettings() {
4870 default_tile_size
= gfx::Size(100, 100);
4871 max_untiled_layer_size
= gfx::Size(200, 200);
4875 class TileSizeTest
: public PictureLayerImplTest
{
4877 TileSizeTest() : PictureLayerImplTest(TileSizeSettings()) {}
4880 TEST_F(TileSizeTest
, TileSizes
) {
4881 host_impl_
.CreatePendingTree();
4883 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
4884 scoped_ptr
<FakePictureLayerImpl
> layer
=
4885 FakePictureLayerImpl::Create(pending_tree
, id_
);
4887 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
4890 host_impl_
.SetUseGpuRasterization(false);
4892 // Default tile-size for large layers.
4893 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
4894 EXPECT_EQ(result
.width(), 100);
4895 EXPECT_EQ(result
.height(), 100);
4896 // Don't tile and round-up, when under max_untiled_layer_size.
4897 result
= layer
->CalculateTileSize(gfx::Size(42, 42));
4898 EXPECT_EQ(result
.width(), 64);
4899 EXPECT_EQ(result
.height(), 64);
4900 result
= layer
->CalculateTileSize(gfx::Size(191, 191));
4901 EXPECT_EQ(result
.width(), 192);
4902 EXPECT_EQ(result
.height(), 192);
4903 result
= layer
->CalculateTileSize(gfx::Size(199, 199));
4904 EXPECT_EQ(result
.width(), 200);
4905 EXPECT_EQ(result
.height(), 200);
4907 // Gpu-rasterization uses 25% viewport-height tiles.
4908 // The +2's below are for border texels.
4909 host_impl_
.SetUseGpuRasterization(true);
4910 host_impl_
.SetViewportSize(gfx::Size(2000, 2000));
4912 layer
->set_gpu_raster_max_texture_size(host_impl_
.device_viewport_size());
4913 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
4914 EXPECT_EQ(result
.width(), 2000 + 2 * PictureLayerTiling::kBorderTexels
);
4915 EXPECT_EQ(result
.height(), 500 + 2);
4917 // Clamp and round-up, when smaller than viewport.
4918 // Tile-height doubles to 50% when width shrinks to <= 50%.
4919 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
4920 layer
->set_gpu_raster_max_texture_size(host_impl_
.device_viewport_size());
4921 result
= layer
->CalculateTileSize(gfx::Size(447, 10000));
4922 EXPECT_EQ(result
.width(), 448);
4923 EXPECT_EQ(result
.height(), 500 + 2);
4925 // Largest layer is 50% of viewport width (rounded up), and
4926 // 50% of viewport in height.
4927 result
= layer
->CalculateTileSize(gfx::Size(447, 400));
4928 EXPECT_EQ(result
.width(), 448);
4929 EXPECT_EQ(result
.height(), 448);
4930 result
= layer
->CalculateTileSize(gfx::Size(500, 499));
4931 EXPECT_EQ(result
.width(), 512);
4932 EXPECT_EQ(result
.height(), 500 + 2);