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/gpu_rasterization_enabled_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 GpuRasterizationEnabledSettings
{};
68 class LowResTilingsSettings
: public GpuRasterizationEnabledSettings
{
70 LowResTilingsSettings() { create_low_res_tiling
= true; }
73 class PictureLayerImplTest
: public testing::Test
{
75 PictureLayerImplTest()
76 : proxy_(base::ThreadTaskRunnerHandle::Get()),
77 host_impl_(LowResTilingsSettings(),
79 &shared_bitmap_manager_
,
83 pending_layer_(nullptr),
84 old_pending_layer_(nullptr),
85 active_layer_(nullptr) {
86 host_impl_
.SetViewportSize(gfx::Size(10000, 10000));
89 explicit PictureLayerImplTest(const LayerTreeSettings
& settings
)
90 : proxy_(base::ThreadTaskRunnerHandle::Get()),
93 &shared_bitmap_manager_
,
97 host_impl_
.SetViewportSize(gfx::Size(10000, 10000));
100 ~PictureLayerImplTest() override
{}
102 void SetUp() override
{ InitializeRenderer(); }
104 virtual void InitializeRenderer() {
105 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d());
108 void SetupDefaultTrees(const gfx::Size
& layer_bounds
) {
109 gfx::Size
tile_size(100, 100);
111 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
112 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
113 scoped_refptr
<FakePicturePileImpl
> active_pile
=
114 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
116 SetupTrees(pending_pile
, active_pile
);
119 void SetupDefaultTreesWithInvalidation(const gfx::Size
& layer_bounds
,
120 const Region
& invalidation
) {
121 gfx::Size
tile_size(100, 100);
123 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
124 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
125 scoped_refptr
<FakePicturePileImpl
> active_pile
=
126 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
128 SetupTreesWithInvalidation(pending_pile
, active_pile
, invalidation
);
131 void ActivateTree() {
132 host_impl_
.ActivateSyncTree();
133 CHECK(!host_impl_
.pending_tree());
134 CHECK(host_impl_
.recycle_tree());
135 old_pending_layer_
= pending_layer_
;
136 pending_layer_
= nullptr;
137 active_layer_
= static_cast<FakePictureLayerImpl
*>(
138 host_impl_
.active_tree()->LayerById(id_
));
140 bool update_lcd_text
= false;
141 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
144 void SetupDefaultTreesWithFixedTileSize(const gfx::Size
& layer_bounds
,
145 const gfx::Size
& tile_size
,
146 const Region
& invalidation
) {
147 gfx::Size
pile_tile_size(100, 100);
149 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
150 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, layer_bounds
);
151 scoped_refptr
<FakePicturePileImpl
> active_pile
=
152 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, layer_bounds
);
154 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
,
159 scoped_refptr
<PicturePileImpl
> pending_pile
,
160 scoped_refptr
<PicturePileImpl
> active_pile
) {
161 SetupPendingTree(active_pile
);
163 SetupPendingTreeInternal(pending_pile
, gfx::Size(), Region());
166 void SetupTreesWithInvalidation(scoped_refptr
<PicturePileImpl
> pending_pile
,
167 scoped_refptr
<PicturePileImpl
> active_pile
,
168 const Region
& pending_invalidation
) {
169 SetupPendingTreeInternal(active_pile
, gfx::Size(), Region());
171 SetupPendingTreeInternal(pending_pile
, gfx::Size(), pending_invalidation
);
174 void SetupTreesWithFixedTileSize(scoped_refptr
<PicturePileImpl
> pending_pile
,
175 scoped_refptr
<PicturePileImpl
> active_pile
,
176 const gfx::Size
& tile_size
,
177 const Region
& pending_invalidation
) {
178 SetupPendingTreeInternal(active_pile
, tile_size
, Region());
180 SetupPendingTreeInternal(pending_pile
, tile_size
, pending_invalidation
);
183 void SetupPendingTree(scoped_refptr
<RasterSource
> raster_source
) {
184 SetupPendingTreeInternal(raster_source
, gfx::Size(), Region());
187 void SetupPendingTreeWithInvalidation(
188 scoped_refptr
<RasterSource
> raster_source
,
189 const Region
& invalidation
) {
190 SetupPendingTreeInternal(raster_source
, gfx::Size(), invalidation
);
193 void SetupPendingTreeWithFixedTileSize(
194 scoped_refptr
<RasterSource
> raster_source
,
195 const gfx::Size
& tile_size
,
196 const Region
& invalidation
) {
197 SetupPendingTreeInternal(raster_source
, tile_size
, invalidation
);
200 void SetupPendingTreeInternal(scoped_refptr
<RasterSource
> raster_source
,
201 const gfx::Size
& tile_size
,
202 const Region
& invalidation
) {
203 host_impl_
.CreatePendingTree();
204 host_impl_
.pending_tree()->PushPageScaleFromMainThread(1.f
, 0.25f
, 100.f
);
205 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
207 // Steal from the recycled tree if possible.
208 scoped_ptr
<LayerImpl
> pending_root
= pending_tree
->DetachLayerTree();
209 scoped_ptr
<FakePictureLayerImpl
> pending_layer
;
210 DCHECK_IMPLIES(pending_root
, pending_root
->id() == root_id_
);
212 pending_root
= LayerImpl::Create(pending_tree
, root_id_
);
213 pending_layer
= FakePictureLayerImpl::Create(pending_tree
, id_
);
214 if (!tile_size
.IsEmpty())
215 pending_layer
->set_fixed_tile_size(tile_size
);
216 pending_layer
->SetDrawsContent(true);
218 pending_layer
.reset(static_cast<FakePictureLayerImpl
*>(
219 pending_root
->RemoveChild(pending_root
->children()[0]).release()));
220 if (!tile_size
.IsEmpty())
221 pending_layer
->set_fixed_tile_size(tile_size
);
223 pending_root
->SetHasRenderSurface(true);
224 // The bounds() just mirror the pile size.
225 pending_layer
->SetBounds(raster_source
->GetSize());
226 pending_layer
->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(
241 FakePictureLayerImpl
* layer
,
242 float ideal_contents_scale
,
243 float device_scale_factor
,
244 float page_scale_factor
,
245 float maximum_animation_contents_scale
,
246 float starting_animation_contents_scale
,
247 bool animating_transform_to_screen
) {
248 layer
->draw_properties().ideal_contents_scale
= ideal_contents_scale
;
249 layer
->draw_properties().device_scale_factor
= device_scale_factor
;
250 layer
->draw_properties().page_scale_factor
= page_scale_factor
;
251 layer
->draw_properties().maximum_animation_contents_scale
=
252 maximum_animation_contents_scale
;
253 layer
->draw_properties().starting_animation_contents_scale
=
254 starting_animation_contents_scale
;
255 layer
->draw_properties().screen_space_transform_is_animating
=
256 animating_transform_to_screen
;
257 bool resourceless_software_draw
= false;
258 layer
->UpdateTiles(resourceless_software_draw
);
260 static void VerifyAllPrioritizedTilesExistAndHavePile(
261 const PictureLayerTiling
* tiling
,
262 PicturePileImpl
* pile
) {
263 auto prioritized_tiles
=
264 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
265 for (PictureLayerTiling::CoverageIterator
iter(
267 tiling
->contents_scale(),
268 gfx::Rect(tiling
->tiling_size()));
272 EXPECT_EQ(pile
, prioritized_tiles
[*iter
].raster_source());
276 void SetContentsScaleOnBothLayers(float contents_scale
,
277 float device_scale_factor
,
278 float page_scale_factor
,
279 float maximum_animation_contents_scale
,
280 float starting_animation_contents_scale
,
281 bool animating_transform
) {
282 SetupDrawPropertiesAndUpdateTiles(
283 pending_layer_
, contents_scale
, device_scale_factor
, page_scale_factor
,
284 maximum_animation_contents_scale
, starting_animation_contents_scale
,
285 animating_transform
);
287 SetupDrawPropertiesAndUpdateTiles(
288 active_layer_
, contents_scale
, device_scale_factor
, page_scale_factor
,
289 maximum_animation_contents_scale
, starting_animation_contents_scale
,
290 animating_transform
);
293 void ResetTilingsAndRasterScales() {
294 if (pending_layer_
) {
295 pending_layer_
->ReleaseResources();
296 EXPECT_FALSE(pending_layer_
->tilings());
297 pending_layer_
->RecreateResources();
298 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
302 active_layer_
->ReleaseResources();
303 EXPECT_FALSE(active_layer_
->tilings());
304 active_layer_
->RecreateResources();
305 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
309 size_t NumberOfTilesRequired(PictureLayerTiling
* tiling
) {
310 size_t num_required
= 0;
311 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
312 for (size_t i
= 0; i
< tiles
.size(); ++i
) {
313 if (tiles
[i
]->required_for_activation())
319 void AssertAllTilesRequired(PictureLayerTiling
* tiling
) {
320 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
321 for (size_t i
= 0; i
< tiles
.size(); ++i
)
322 EXPECT_TRUE(tiles
[i
]->required_for_activation()) << "i: " << i
;
323 EXPECT_GT(tiles
.size(), 0u);
326 void AssertNoTilesRequired(PictureLayerTiling
* tiling
) {
327 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
328 for (size_t i
= 0; i
< tiles
.size(); ++i
)
329 EXPECT_FALSE(tiles
[i
]->required_for_activation()) << "i: " << i
;
330 EXPECT_GT(tiles
.size(), 0u);
334 void TestQuadsForSolidColor(bool test_for_solid
);
336 FakeImplProxy proxy_
;
337 TestSharedBitmapManager shared_bitmap_manager_
;
338 TestTaskGraphRunner task_graph_runner_
;
339 FakeLayerTreeHostImpl host_impl_
;
342 FakePictureLayerImpl
* pending_layer_
;
343 FakePictureLayerImpl
* old_pending_layer_
;
344 FakePictureLayerImpl
* active_layer_
;
347 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest
);
350 class NoLowResPictureLayerImplTest
: public PictureLayerImplTest
{
352 NoLowResPictureLayerImplTest()
353 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
356 TEST_F(PictureLayerImplTest
, TileGridAlignment
) {
357 // Layer to span 4 raster tiles in x and in y
358 ImplSidePaintingSettings settings
;
359 gfx::Size
layer_size(settings
.default_tile_size
.width() * 7 / 2,
360 settings
.default_tile_size
.height() * 7 / 2);
362 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
363 FakePicturePileImpl::CreateFilledPile(layer_size
, layer_size
);
365 scoped_ptr
<FakePicturePile
> active_recording
=
366 FakePicturePile::CreateFilledPile(layer_size
, layer_size
);
367 scoped_refptr
<FakePicturePileImpl
> active_pile
=
368 FakePicturePileImpl::CreateFromPile(active_recording
.get(), nullptr);
370 SetupTrees(pending_pile
, active_pile
);
372 // Add 1x1 rects at the centers of each tile, then re-record pile contents
373 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
374 std::vector
<Tile
*> tiles
=
375 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
376 EXPECT_EQ(16u, tiles
.size());
377 std::vector
<SkRect
> rects
;
378 std::vector
<Tile
*>::const_iterator tile_iter
;
379 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
380 gfx::Point tile_center
= (*tile_iter
)->content_rect().CenterPoint();
381 gfx::Rect
rect(tile_center
.x(), tile_center
.y(), 1, 1);
382 active_recording
->add_draw_rect(rect
);
383 rects
.push_back(SkRect::MakeXYWH(rect
.x(), rect
.y(), 1, 1));
386 // Force re-raster with newly injected content
387 active_recording
->RemoveRecordingAt(0, 0);
388 active_recording
->AddRecordingAt(0, 0);
390 scoped_refptr
<FakePicturePileImpl
> updated_active_pile
=
391 FakePicturePileImpl::CreateFromPile(active_recording
.get(), nullptr);
393 std::vector
<SkRect
>::const_iterator rect_iter
= rects
.begin();
394 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
395 MockCanvas
mock_canvas(1000, 1000);
396 updated_active_pile
->PlaybackToSharedCanvas(
397 &mock_canvas
, (*tile_iter
)->content_rect(), 1.0f
);
399 // This test verifies that when drawing the contents of a specific tile
400 // at content scale 1.0, the playback canvas never receives content from
401 // neighboring tiles which indicates that the tile grid embedded in
402 // SkPicture is perfectly aligned with the compositor's tiles.
403 EXPECT_EQ(1u, mock_canvas
.rects_
.size());
404 EXPECT_EQ(*rect_iter
, mock_canvas
.rects_
[0]);
409 TEST_F(PictureLayerImplTest
, CloneNoInvalidation
) {
410 gfx::Size
tile_size(100, 100);
411 gfx::Size
layer_bounds(400, 400);
413 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
414 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
415 scoped_refptr
<FakePicturePileImpl
> active_pile
=
416 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
418 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
420 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
421 active_layer_
->tilings()->num_tilings());
423 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
424 EXPECT_GT(tilings
->num_tilings(), 0u);
425 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
426 EXPECT_TRUE(tilings
->tiling_at(i
)->AllTilesForTesting().empty());
429 TEST_F(PictureLayerImplTest
, ExternalViewportRectForPrioritizingTiles
) {
430 base::TimeTicks time_ticks
;
431 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
432 host_impl_
.SetCurrentBeginFrameArgs(
433 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
434 gfx::Size
tile_size(100, 100);
435 gfx::Size
layer_bounds(400, 400);
437 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
438 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
439 scoped_refptr
<FakePicturePileImpl
> active_pile
=
440 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
442 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
444 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
447 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
448 host_impl_
.SetCurrentBeginFrameArgs(
449 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
451 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the
452 // identify transform for tile priority.
453 bool resourceless_software_draw
= false;
454 gfx::Rect viewport
= gfx::Rect(layer_bounds
),
455 viewport_rect_for_tile_priority
= gfx::Rect(0, 0, 100, 100);
456 gfx::Transform transform
, transform_for_tile_priority
;
458 host_impl_
.SetExternalDrawConstraints(transform
,
461 viewport_rect_for_tile_priority
,
462 transform_for_tile_priority
,
463 resourceless_software_draw
);
464 bool update_lcd_text
= false;
465 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
467 gfx::Rect viewport_rect_for_tile_priority_in_view_space
=
468 viewport_rect_for_tile_priority
;
470 // Verify the viewport rect for tile priority is used in picture layer tiling.
471 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
472 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
473 PictureLayerTilingSet
* tilings
= active_layer_
->tilings();
474 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
475 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
477 tiling
->GetCurrentVisibleRectForTesting(),
478 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
479 tiling
->contents_scale()));
482 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in
483 // screen space and the transform for tile priority is translated and
484 // rotated. The actual viewport for tile priority used by PictureLayerImpl
485 // should be (200, 200, 100, 100) applied with the said transform.
486 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
487 host_impl_
.SetCurrentBeginFrameArgs(
488 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
490 viewport_rect_for_tile_priority
= gfx::Rect(200, 200, 100, 100);
491 transform_for_tile_priority
.Translate(100, 100);
492 transform_for_tile_priority
.Rotate(45);
493 host_impl_
.SetExternalDrawConstraints(transform
,
496 viewport_rect_for_tile_priority
,
497 transform_for_tile_priority
,
498 resourceless_software_draw
);
499 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
501 gfx::Transform
screen_to_view(gfx::Transform::kSkipInitialization
);
502 bool success
= transform_for_tile_priority
.GetInverse(&screen_to_view
);
503 EXPECT_TRUE(success
);
505 // Note that we don't clip this to the layer bounds, since it is expected that
506 // the rect will sometimes be outside of the layer bounds. If we clip to
507 // bounds, then tile priorities will end up being incorrect in cases of fully
509 viewport_rect_for_tile_priority_in_view_space
=
510 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
511 screen_to_view
, viewport_rect_for_tile_priority
));
513 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
514 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
515 tilings
= active_layer_
->tilings();
516 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
517 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
519 tiling
->GetCurrentVisibleRectForTesting(),
520 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
521 tiling
->contents_scale()));
525 TEST_F(PictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
526 base::TimeTicks time_ticks
;
527 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
528 host_impl_
.SetCurrentBeginFrameArgs(
529 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
531 gfx::Size
tile_size(100, 100);
532 gfx::Size
layer_bounds(400, 400);
534 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
535 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
536 scoped_refptr
<FakePicturePileImpl
> active_pile
=
537 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
539 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
541 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
544 // UpdateTiles with valid viewport. Should update tile viewport.
545 // Note viewport is considered invalid if and only if in resourceless
547 bool resourceless_software_draw
= false;
548 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
549 gfx::Transform transform
;
550 host_impl_
.SetExternalDrawConstraints(transform
,
555 resourceless_software_draw
);
556 active_layer_
->draw_properties().visible_content_rect
= viewport
;
557 active_layer_
->draw_properties().screen_space_transform
= transform
;
558 active_layer_
->UpdateTiles(resourceless_software_draw
);
560 gfx::Rect visible_rect_for_tile_priority
=
561 active_layer_
->visible_rect_for_tile_priority();
562 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
563 gfx::Transform screen_space_transform_for_tile_priority
=
564 active_layer_
->screen_space_transform();
566 // Expand viewport and set it as invalid for prioritizing tiles.
567 // Should update viewport and transform, but not update visible rect.
568 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
569 host_impl_
.SetCurrentBeginFrameArgs(
570 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
571 resourceless_software_draw
= true;
572 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
573 transform
.Translate(1.f
, 1.f
);
574 active_layer_
->draw_properties().visible_content_rect
= viewport
;
575 active_layer_
->draw_properties().screen_space_transform
= transform
;
576 host_impl_
.SetExternalDrawConstraints(transform
,
581 resourceless_software_draw
);
582 active_layer_
->UpdateTiles(resourceless_software_draw
);
584 // Transform for tile priority is updated.
585 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
586 active_layer_
->screen_space_transform());
587 // Visible rect for tile priority retains old value.
588 EXPECT_EQ(visible_rect_for_tile_priority
,
589 active_layer_
->visible_rect_for_tile_priority());
591 // Keep expanded viewport but mark it valid. Should update tile viewport.
592 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
593 host_impl_
.SetCurrentBeginFrameArgs(
594 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
595 resourceless_software_draw
= false;
596 host_impl_
.SetExternalDrawConstraints(transform
,
601 resourceless_software_draw
);
602 active_layer_
->UpdateTiles(resourceless_software_draw
);
604 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
605 active_layer_
->screen_space_transform());
606 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
609 TEST_F(PictureLayerImplTest
, ViewportRectForTilePriorityIsCached
) {
610 base::TimeTicks time_ticks
;
611 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
612 host_impl_
.SetCurrentBeginFrameArgs(
613 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
614 gfx::Size
tile_size(100, 100);
615 gfx::Size
layer_bounds(400, 400);
617 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
618 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
619 scoped_refptr
<FakePicturePileImpl
> active_pile
=
620 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
622 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
624 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
627 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
628 host_impl_
.SetCurrentBeginFrameArgs(
629 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
631 bool resourceless_software_draw
= false;
632 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
633 gfx::Rect
viewport_rect_for_tile_priority(0, 0, 100, 100);
634 gfx::Transform transform
, transform_for_tile_priority
;
636 host_impl_
.SetExternalDrawConstraints(
637 transform
, viewport
, viewport
, viewport_rect_for_tile_priority
,
638 transform_for_tile_priority
, resourceless_software_draw
);
639 bool update_lcd_text
= false;
640 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
642 EXPECT_EQ(viewport_rect_for_tile_priority
,
643 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
645 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
646 host_impl_
.SetCurrentBeginFrameArgs(
647 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
649 gfx::Rect
another_viewport_rect_for_tile_priority(11, 11, 50, 50);
650 host_impl_
.SetExternalDrawConstraints(
651 transform
, viewport
, viewport
, another_viewport_rect_for_tile_priority
,
652 transform_for_tile_priority
, resourceless_software_draw
);
654 // Didn't call UpdateDrawProperties yet. The viewport rect for tile priority
655 // should remain to be the previously cached value.
656 EXPECT_EQ(viewport_rect_for_tile_priority
,
657 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
658 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
660 // Now the UpdateDrawProperties is called. The viewport rect for tile
661 // priority should be the latest value.
662 EXPECT_EQ(another_viewport_rect_for_tile_priority
,
663 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
666 TEST_F(PictureLayerImplTest
, ClonePartialInvalidation
) {
667 gfx::Size
tile_size(100, 100);
668 gfx::Size
layer_bounds(400, 400);
669 gfx::Rect
layer_invalidation(150, 200, 30, 180);
671 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
672 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
673 scoped_refptr
<FakePicturePileImpl
> active_pile
=
674 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
675 scoped_refptr
<FakePicturePileImpl
> lost_pile
=
676 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
678 SetupPendingTreeWithFixedTileSize(lost_pile
, gfx::Size(50, 50), Region());
680 // Add a unique tiling on the active tree.
681 PictureLayerTiling
* tiling
= active_layer_
->AddTiling(3.f
);
682 tiling
->CreateAllTilesForTesting();
684 // Ensure UpdateTiles won't remove any tilings.
685 active_layer_
->MarkAllTilingsUsed();
687 // Then setup a new pending tree and activate it.
688 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, gfx::Size(50, 50),
691 EXPECT_EQ(2u, pending_layer_
->num_tilings());
692 EXPECT_EQ(3u, active_layer_
->num_tilings());
694 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
695 EXPECT_GT(tilings
->num_tilings(), 0u);
696 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
697 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
698 gfx::Rect content_invalidation
= gfx::ScaleToEnclosingRect(
700 tiling
->contents_scale());
701 auto prioritized_tiles
=
702 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
703 for (PictureLayerTiling::CoverageIterator
iter(
705 tiling
->contents_scale(),
706 gfx::Rect(tiling
->tiling_size()));
709 // We don't always have a tile, but when we do it's because it was
710 // invalidated and it has the latest raster source.
712 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
713 EXPECT_EQ(pending_pile
.get(), prioritized_tiles
[*iter
].raster_source());
714 EXPECT_TRUE(iter
.geometry_rect().Intersects(content_invalidation
));
716 // We don't create tiles in non-invalidated regions.
717 EXPECT_FALSE(iter
.geometry_rect().Intersects(content_invalidation
));
722 tilings
= active_layer_
->tilings();
723 EXPECT_GT(tilings
->num_tilings(), 0u);
724 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
725 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
726 gfx::Rect content_invalidation
=
727 gfx::ScaleToEnclosingRect(layer_invalidation
, tiling
->contents_scale());
728 auto prioritized_tiles
=
729 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
730 for (PictureLayerTiling::CoverageIterator
iter(
732 tiling
->contents_scale(),
733 gfx::Rect(tiling
->tiling_size()));
737 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
738 // Pile will be updated upon activation.
739 EXPECT_EQ(active_pile
.get(), prioritized_tiles
[*iter
].raster_source());
744 TEST_F(PictureLayerImplTest
, CloneFullInvalidation
) {
745 gfx::Size
tile_size(90, 80);
746 gfx::Size
layer_bounds(300, 500);
748 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
749 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
750 scoped_refptr
<FakePicturePileImpl
> active_pile
=
751 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
753 SetupTreesWithInvalidation(pending_pile
, active_pile
,
754 gfx::Rect(layer_bounds
));
756 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
757 active_layer_
->tilings()->num_tilings());
759 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
760 EXPECT_GT(tilings
->num_tilings(), 0u);
761 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
762 VerifyAllPrioritizedTilesExistAndHavePile(tilings
->tiling_at(i
),
766 TEST_F(PictureLayerImplTest
, UpdateTilesCreatesTilings
) {
767 gfx::Size
tile_size(400, 400);
768 gfx::Size
layer_bounds(1300, 1900);
770 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
771 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
772 scoped_refptr
<FakePicturePileImpl
> active_pile
=
773 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
775 SetupTrees(pending_pile
, active_pile
);
777 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
778 EXPECT_LT(low_res_factor
, 1.f
);
780 active_layer_
->ReleaseResources();
781 EXPECT_FALSE(active_layer_
->tilings());
782 active_layer_
->RecreateResources();
783 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
785 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
786 6.f
, // ideal contents scale
789 1.f
, // maximum animation scale
790 0.f
, // starting animation scale
792 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
794 active_layer_
->tilings()->tiling_at(0)->contents_scale());
795 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
796 active_layer_
->tilings()->tiling_at(1)->contents_scale());
798 // If we change the page scale factor, then we should get new tilings.
799 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
800 6.6f
, // ideal contents scale
803 1.f
, // maximum animation scale
804 0.f
, // starting animation scale
806 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
807 EXPECT_FLOAT_EQ(6.6f
,
808 active_layer_
->tilings()->tiling_at(0)->contents_scale());
809 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
810 active_layer_
->tilings()->tiling_at(2)->contents_scale());
812 // If we change the device scale factor, then we should get new tilings.
813 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
814 7.26f
, // ideal contents scale
815 3.3f
, // device scale
817 1.f
, // maximum animation scale
818 0.f
, // starting animation scale
820 ASSERT_EQ(6u, active_layer_
->tilings()->num_tilings());
821 EXPECT_FLOAT_EQ(7.26f
,
822 active_layer_
->tilings()->tiling_at(0)->contents_scale());
823 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
824 active_layer_
->tilings()->tiling_at(3)->contents_scale());
826 // If we change the device scale factor, but end up at the same total scale
827 // factor somehow, then we don't get new tilings.
828 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
829 7.26f
, // ideal contents scale
830 2.2f
, // device scale
832 1.f
, // maximum animation scale
833 0.f
, // starting animation scale
835 ASSERT_EQ(6u, active_layer_
->tilings()->num_tilings());
836 EXPECT_FLOAT_EQ(7.26f
,
837 active_layer_
->tilings()->tiling_at(0)->contents_scale());
838 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
839 active_layer_
->tilings()->tiling_at(3)->contents_scale());
842 TEST_F(PictureLayerImplTest
, PendingLayerOnlyHasHighAndLowResTiling
) {
843 gfx::Size
tile_size(400, 400);
844 gfx::Size
layer_bounds(1300, 1900);
846 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
847 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
848 scoped_refptr
<FakePicturePileImpl
> active_pile
=
849 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
851 SetupTrees(pending_pile
, active_pile
);
853 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
854 EXPECT_LT(low_res_factor
, 1.f
);
856 pending_layer_
->ReleaseResources();
857 EXPECT_FALSE(pending_layer_
->tilings());
858 pending_layer_
->RecreateResources();
859 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
861 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
862 6.f
, // ideal contents scale
865 1.f
, // maximum animation scale
866 0.f
, // starting animation scale
868 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
870 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
871 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
872 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
874 // If we change the page scale factor, then we should get new tilings.
875 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
876 6.6f
, // ideal contents scale
879 1.f
, // maximum animation scale
880 0.f
, // starting animation scale
882 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
883 EXPECT_FLOAT_EQ(6.6f
,
884 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
885 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
886 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
888 // If we change the device scale factor, then we should get new tilings.
889 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
890 7.26f
, // ideal contents scale
891 3.3f
, // device scale
893 1.f
, // maximum animation scale
894 0.f
, // starting animation scale
896 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
897 EXPECT_FLOAT_EQ(7.26f
,
898 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
899 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
900 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
902 // If we change the device scale factor, but end up at the same total scale
903 // factor somehow, then we don't get new tilings.
904 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
905 7.26f
, // ideal contents scale
906 2.2f
, // device scale
908 1.f
, // maximum animation scale
909 0.f
, // starting animation scale
911 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
912 EXPECT_FLOAT_EQ(7.26f
,
913 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
914 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
915 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
918 TEST_F(PictureLayerImplTest
, CreateTilingsEvenIfTwinHasNone
) {
919 // This test makes sure that if a layer can have tilings, then a commit makes
920 // it not able to have tilings (empty size), and then a future commit that
921 // makes it valid again should be able to create tilings.
922 gfx::Size
tile_size(400, 400);
923 gfx::Size
layer_bounds(1300, 1900);
925 scoped_refptr
<FakePicturePileImpl
> empty_pile
=
926 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
927 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
928 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
930 SetupPendingTree(valid_pile
);
931 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
934 SetupPendingTree(empty_pile
);
935 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
936 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
937 ASSERT_EQ(0u, pending_layer_
->tilings()->num_tilings());
940 EXPECT_FALSE(active_layer_
->CanHaveTilings());
941 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
943 SetupPendingTree(valid_pile
);
944 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
945 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
948 TEST_F(PictureLayerImplTest
, ZoomOutCrash
) {
949 gfx::Size
tile_size(400, 400);
950 gfx::Size
layer_bounds(1300, 1900);
952 // Set up the high and low res tilings before pinch zoom.
953 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
954 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
955 scoped_refptr
<FakePicturePileImpl
> active_pile
=
956 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
958 SetupTrees(pending_pile
, active_pile
);
959 ResetTilingsAndRasterScales();
960 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
961 SetContentsScaleOnBothLayers(32.0f
, 1.0f
, 32.0f
, 1.0f
, 0.f
, false);
962 EXPECT_EQ(32.f
, active_layer_
->HighResTiling()->contents_scale());
963 host_impl_
.PinchGestureBegin();
964 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.f
, false);
965 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, 0.f
, false);
966 EXPECT_EQ(active_layer_
->tilings()->NumHighResTilings(), 1);
969 TEST_F(PictureLayerImplTest
, PinchGestureTilings
) {
970 gfx::Size
tile_size(400, 400);
971 gfx::Size
layer_bounds(1300, 1900);
973 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
975 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
976 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
977 scoped_refptr
<FakePicturePileImpl
> active_pile
=
978 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
980 // Set up the high and low res tilings before pinch zoom.
981 SetupTrees(pending_pile
, active_pile
);
982 ResetTilingsAndRasterScales();
984 SetContentsScaleOnBothLayers(2.f
, 1.0f
, 2.f
, 1.0f
, 0.f
, false);
985 EXPECT_BOTH_EQ(num_tilings(), 2u);
986 EXPECT_BOTH_EQ(tilings()->tiling_at(0)->contents_scale(), 2.f
);
987 EXPECT_BOTH_EQ(tilings()->tiling_at(1)->contents_scale(),
988 2.f
* low_res_factor
);
990 // Ensure UpdateTiles won't remove any tilings.
991 active_layer_
->MarkAllTilingsUsed();
993 // Start a pinch gesture.
994 host_impl_
.PinchGestureBegin();
996 // Zoom out by a small amount. We should create a tiling at half
997 // the scale (2/kMaxScaleRatioDuringPinch).
998 SetContentsScaleOnBothLayers(1.8f
, 1.0f
, 1.8f
, 1.0f
, 0.f
, false);
999 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1000 EXPECT_FLOAT_EQ(2.0f
,
1001 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1002 EXPECT_FLOAT_EQ(1.0f
,
1003 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1004 EXPECT_FLOAT_EQ(2.0f
* low_res_factor
,
1005 active_layer_
->tilings()->tiling_at(2)->contents_scale());
1007 // Ensure UpdateTiles won't remove any tilings.
1008 active_layer_
->MarkAllTilingsUsed();
1010 // Zoom out further, close to our low-res scale factor. We should
1011 // use that tiling as high-res, and not create a new tiling.
1012 SetContentsScaleOnBothLayers(low_res_factor
* 2.1f
, 1.0f
,
1013 low_res_factor
* 2.1f
, 1.0f
, 0.f
, false);
1014 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1016 // Zoom in a lot now. Since we increase by increments of
1017 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0.
1018 SetContentsScaleOnBothLayers(3.8f
, 1.0f
, 3.8f
, 1.f
, 0.f
, false);
1019 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
1020 EXPECT_FLOAT_EQ(4.0f
,
1021 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1024 TEST_F(PictureLayerImplTest
, SnappedTilingDuringZoom
) {
1025 gfx::Size
tile_size(300, 300);
1026 gfx::Size
layer_bounds(2600, 3800);
1028 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1029 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1030 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1031 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1033 SetupTrees(pending_pile
, active_pile
);
1035 ResetTilingsAndRasterScales();
1036 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1038 // Set up the high and low res tilings before pinch zoom.
1039 SetContentsScaleOnBothLayers(0.24f
, 1.0f
, 0.24f
, 1.0f
, 0.f
, false);
1040 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1041 EXPECT_FLOAT_EQ(0.24f
,
1042 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1043 EXPECT_FLOAT_EQ(0.0625f
,
1044 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1046 // Ensure UpdateTiles won't remove any tilings.
1047 active_layer_
->MarkAllTilingsUsed();
1049 // Start a pinch gesture.
1050 host_impl_
.PinchGestureBegin();
1052 // Zoom out by a small amount. We should create a tiling at half
1053 // the scale (1/kMaxScaleRatioDuringPinch).
1054 SetContentsScaleOnBothLayers(0.2f
, 1.0f
, 0.2f
, 1.0f
, 0.f
, false);
1055 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1056 EXPECT_FLOAT_EQ(0.24f
,
1057 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1058 EXPECT_FLOAT_EQ(0.12f
,
1059 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1060 EXPECT_FLOAT_EQ(0.0625,
1061 active_layer_
->tilings()->tiling_at(2)->contents_scale());
1063 // Ensure UpdateTiles won't remove any tilings.
1064 active_layer_
->MarkAllTilingsUsed();
1066 // Zoom out further, close to our low-res scale factor. We should
1067 // use that tiling as high-res, and not create a new tiling.
1068 SetContentsScaleOnBothLayers(0.1f
, 1.0f
, 0.1f
, 1.0f
, 0.f
, false);
1069 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1071 // Zoom in. 0.25(desired_scale) should be snapped to 0.24 during zoom-in
1072 // because 0.25(desired_scale) is within the ratio(1.2).
1073 SetContentsScaleOnBothLayers(0.25f
, 1.0f
, 0.25f
, 1.0f
, 0.f
, false);
1074 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1076 // Zoom in a lot. Since we move in factors of two, we should get a scale that
1077 // is a power of 2 times 0.24.
1078 SetContentsScaleOnBothLayers(1.f
, 1.0f
, 1.f
, 1.0f
, 0.f
, false);
1079 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
1080 EXPECT_FLOAT_EQ(1.92f
,
1081 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1084 TEST_F(PictureLayerImplTest
, CleanUpTilings
) {
1085 gfx::Size
tile_size(400, 400);
1086 gfx::Size
layer_bounds(1300, 1900);
1088 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1089 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1090 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1091 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1093 std::vector
<PictureLayerTiling
*> used_tilings
;
1095 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1096 EXPECT_LT(low_res_factor
, 1.f
);
1099 float page_scale
= 1.f
;
1101 SetupTrees(pending_pile
, active_pile
);
1102 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1103 EXPECT_EQ(1.f
, active_layer_
->HighResTiling()->contents_scale());
1105 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
1106 // |used_tilings| variable, and it's here only to ensure that active_layer_
1107 // won't remove tilings before the test has a chance to verify behavior.
1108 active_layer_
->MarkAllTilingsUsed();
1110 // We only have ideal tilings, so they aren't removed.
1111 used_tilings
.clear();
1112 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1113 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1115 host_impl_
.PinchGestureBegin();
1117 // Changing the ideal but not creating new tilings.
1120 SetContentsScaleOnBothLayers(scale
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1121 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1123 // The tilings are still our target scale, so they aren't removed.
1124 used_tilings
.clear();
1125 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1126 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
1128 host_impl_
.PinchGestureEnd();
1130 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
1133 SetContentsScaleOnBothLayers(1.2f
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1134 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
1137 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1139 1.f
* low_res_factor
,
1140 active_layer_
->tilings()->tiling_at(3)->contents_scale());
1142 // Ensure UpdateTiles won't remove any tilings.
1143 active_layer_
->MarkAllTilingsUsed();
1145 // Mark the non-ideal tilings as used. They won't be removed.
1146 used_tilings
.clear();
1147 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1148 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(3));
1149 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1150 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
1152 // Now move the ideal scale to 0.5. Our target stays 1.2.
1153 SetContentsScaleOnBothLayers(0.5f
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1155 // The high resolution tiling is between target and ideal, so is not
1156 // removed. The low res tiling for the old ideal=1.0 scale is removed.
1157 used_tilings
.clear();
1158 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1159 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1161 // Now move the ideal scale to 1.0. Our target stays 1.2.
1162 SetContentsScaleOnBothLayers(1.f
, 1.f
, page_scale
, 1.f
, 0.f
, false);
1164 // All the tilings are between are target and the ideal, so they are not
1166 used_tilings
.clear();
1167 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1168 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1170 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
1171 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.1f
, 1.f
, page_scale
, 1.f
,
1174 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1175 // in the range [1.0,1.2] and are kept.
1176 used_tilings
.clear();
1177 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1178 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1180 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1182 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.1f
, 1.f
, page_scale
, 1.f
,
1185 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1186 // target raster scale. But it is in our used tilings set, so nothing is
1188 used_tilings
.clear();
1189 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1190 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1191 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1193 // If we remove it from our used tilings set, it is outside the range to keep
1194 // so it is deleted.
1195 used_tilings
.clear();
1196 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1197 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
1200 TEST_F(PictureLayerImplTest
, DontAddLowResDuringAnimation
) {
1201 // Make sure this layer covers multiple tiles, since otherwise low
1202 // res won't get created because it is too small.
1203 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1204 // Avoid max untiled layer size heuristics via fixed tile size.
1205 gfx::Size
layer_bounds(tile_size
.width() + 1, tile_size
.height() + 1);
1206 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
1208 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1209 float contents_scale
= 1.f
;
1210 float device_scale
= 1.f
;
1211 float page_scale
= 1.f
;
1212 float maximum_animation_scale
= 1.f
;
1213 float starting_animation_scale
= 0.f
;
1214 bool animating_transform
= true;
1216 ResetTilingsAndRasterScales();
1218 // Animating, so don't create low res even if there isn't one already.
1219 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1220 maximum_animation_scale
,
1221 starting_animation_scale
, animating_transform
);
1222 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1223 EXPECT_BOTH_EQ(num_tilings(), 1u);
1225 // Stop animating, low res gets created.
1226 animating_transform
= false;
1227 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1228 maximum_animation_scale
,
1229 starting_animation_scale
, animating_transform
);
1230 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1231 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor
);
1232 EXPECT_BOTH_EQ(num_tilings(), 2u);
1234 // Ensure UpdateTiles won't remove any tilings.
1235 active_layer_
->MarkAllTilingsUsed();
1237 // Page scale animation, new high res, but no low res. We still have
1238 // a tiling at the previous scale, it's just not marked as low res on the
1239 // active layer. The pending layer drops non-ideal tilings.
1240 contents_scale
= 2.f
;
1242 maximum_animation_scale
= 2.f
;
1243 animating_transform
= true;
1244 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1245 maximum_animation_scale
,
1246 starting_animation_scale
, animating_transform
);
1247 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1248 EXPECT_FALSE(active_layer_
->LowResTiling());
1249 EXPECT_FALSE(pending_layer_
->LowResTiling());
1250 EXPECT_EQ(3u, active_layer_
->num_tilings());
1251 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1253 // Stop animating, new low res gets created for final page scale.
1254 animating_transform
= false;
1255 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1256 maximum_animation_scale
,
1257 starting_animation_scale
, animating_transform
);
1258 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1259 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f
* low_res_factor
);
1260 EXPECT_EQ(4u, active_layer_
->num_tilings());
1261 EXPECT_EQ(2u, pending_layer_
->num_tilings());
1264 TEST_F(PictureLayerImplTest
, DontAddLowResForSmallLayers
) {
1265 gfx::Size
layer_bounds(host_impl_
.settings().default_tile_size
);
1266 gfx::Size
tile_size(100, 100);
1268 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1269 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1270 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1271 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1273 SetupTrees(pending_pile
, active_pile
);
1275 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1276 float device_scale
= 1.f
;
1277 float page_scale
= 1.f
;
1278 float maximum_animation_scale
= 1.f
;
1279 float starting_animation_scale
= 0.f
;
1280 bool animating_transform
= false;
1282 // Contents exactly fit on one tile at scale 1, no low res.
1283 float contents_scale
= 1.f
;
1284 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1285 maximum_animation_scale
,
1286 starting_animation_scale
, animating_transform
);
1287 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1288 EXPECT_BOTH_EQ(num_tilings(), 1u);
1290 ResetTilingsAndRasterScales();
1292 // Contents that are smaller than one tile, no low res.
1293 contents_scale
= 0.123f
;
1294 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1295 maximum_animation_scale
,
1296 starting_animation_scale
, animating_transform
);
1297 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1298 EXPECT_BOTH_EQ(num_tilings(), 1u);
1300 ResetTilingsAndRasterScales();
1302 // Any content bounds that would create more than one tile will
1303 // generate a low res tiling.
1304 contents_scale
= 2.5f
;
1305 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
1306 maximum_animation_scale
,
1307 starting_animation_scale
, animating_transform
);
1308 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1309 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1310 contents_scale
* low_res_factor
);
1311 EXPECT_BOTH_EQ(num_tilings(), 2u);
1313 // Mask layers dont create low res since they always fit on one tile.
1314 scoped_ptr
<FakePictureLayerImpl
> mask
=
1315 FakePictureLayerImpl::CreateMaskWithRasterSource(
1316 host_impl_
.pending_tree(), 3, pending_pile
);
1317 mask
->SetBounds(layer_bounds
);
1318 mask
->SetContentBounds(layer_bounds
);
1319 mask
->SetDrawsContent(true);
1321 SetupDrawPropertiesAndUpdateTiles(
1322 mask
.get(), contents_scale
, device_scale
, page_scale
,
1323 maximum_animation_scale
, starting_animation_scale
, animating_transform
);
1324 EXPECT_EQ(mask
->HighResTiling()->contents_scale(), contents_scale
);
1325 EXPECT_EQ(mask
->num_tilings(), 1u);
1328 TEST_F(PictureLayerImplTest
, HugeMasksGetScaledDown
) {
1329 base::TimeTicks time_ticks
;
1330 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1331 host_impl_
.SetCurrentBeginFrameArgs(
1332 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1334 gfx::Size
tile_size(100, 100);
1335 gfx::Size
layer_bounds(1000, 1000);
1337 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1338 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1339 SetupPendingTree(valid_pile
);
1341 scoped_ptr
<FakePictureLayerImpl
> mask_ptr
=
1342 FakePictureLayerImpl::CreateMaskWithRasterSource(
1343 host_impl_
.pending_tree(), 3, valid_pile
);
1344 mask_ptr
->SetBounds(layer_bounds
);
1345 mask_ptr
->SetContentBounds(layer_bounds
);
1346 mask_ptr
->SetDrawsContent(true);
1347 pending_layer_
->SetMaskLayer(mask_ptr
.Pass());
1348 pending_layer_
->SetHasRenderSurface(true);
1350 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1351 host_impl_
.SetCurrentBeginFrameArgs(
1352 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1353 bool update_lcd_text
= false;
1354 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1356 FakePictureLayerImpl
* pending_mask
=
1357 static_cast<FakePictureLayerImpl
*>(pending_layer_
->mask_layer());
1359 EXPECT_EQ(1.f
, pending_mask
->HighResTiling()->contents_scale());
1360 EXPECT_EQ(1u, pending_mask
->num_tilings());
1362 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1363 pending_mask
->HighResTiling()->AllTilesForTesting());
1367 FakePictureLayerImpl
* active_mask
=
1368 static_cast<FakePictureLayerImpl
*>(active_layer_
->mask_layer());
1370 // Mask layers have a tiling with a single tile in it.
1371 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1372 // The mask resource exists.
1373 ResourceProvider::ResourceId mask_resource_id
;
1374 gfx::Size mask_texture_size
;
1375 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1376 EXPECT_NE(0u, mask_resource_id
);
1377 EXPECT_EQ(active_mask
->bounds(), mask_texture_size
);
1379 // Drop resources and recreate them, still the same.
1380 pending_mask
->ReleaseResources();
1381 active_mask
->ReleaseResources();
1382 pending_mask
->RecreateResources();
1383 active_mask
->RecreateResources();
1384 SetupDrawPropertiesAndUpdateTiles(active_mask
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1386 active_mask
->HighResTiling()->CreateAllTilesForTesting();
1387 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1388 EXPECT_NE(0u, mask_resource_id
);
1389 EXPECT_EQ(active_mask
->bounds(), mask_texture_size
);
1391 // Resize larger than the max texture size.
1392 int max_texture_size
= host_impl_
.GetRendererCapabilities().max_texture_size
;
1393 gfx::Size
huge_bounds(max_texture_size
+ 1, 10);
1394 scoped_refptr
<FakePicturePileImpl
> huge_pile
=
1395 FakePicturePileImpl::CreateFilledPile(tile_size
, huge_bounds
);
1397 SetupPendingTree(huge_pile
);
1398 pending_mask
->SetBounds(huge_bounds
);
1399 pending_mask
->SetContentBounds(huge_bounds
);
1400 pending_mask
->SetRasterSourceOnPending(huge_pile
, Region());
1402 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1403 host_impl_
.SetCurrentBeginFrameArgs(
1404 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1405 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1407 // The mask tiling gets scaled down.
1408 EXPECT_LT(pending_mask
->HighResTiling()->contents_scale(), 1.f
);
1409 EXPECT_EQ(1u, pending_mask
->num_tilings());
1411 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1412 pending_mask
->HighResTiling()->AllTilesForTesting());
1416 // Mask layers have a tiling with a single tile in it.
1417 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1418 // The mask resource exists.
1419 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1420 EXPECT_NE(0u, mask_resource_id
);
1421 gfx::Size expected_size
= active_mask
->bounds();
1422 expected_size
.SetToMin(gfx::Size(max_texture_size
, max_texture_size
));
1423 EXPECT_EQ(expected_size
, mask_texture_size
);
1425 // Drop resources and recreate them, still the same.
1426 pending_mask
->ReleaseResources();
1427 active_mask
->ReleaseResources();
1428 pending_mask
->RecreateResources();
1429 active_mask
->RecreateResources();
1430 SetupDrawPropertiesAndUpdateTiles(active_mask
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1432 active_mask
->HighResTiling()->CreateAllTilesForTesting();
1433 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1434 EXPECT_NE(0u, mask_resource_id
);
1435 EXPECT_EQ(expected_size
, mask_texture_size
);
1437 // Do another activate, the same holds.
1438 SetupPendingTree(huge_pile
);
1440 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1441 active_layer_
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1442 EXPECT_EQ(expected_size
, mask_texture_size
);
1443 EXPECT_EQ(0u, mask_resource_id
);
1445 // Resize even larger, so that the scale would be smaller than the minimum
1446 // contents scale. Then the layer should no longer have any tiling.
1447 float min_contents_scale
= host_impl_
.settings().minimum_contents_scale
;
1448 gfx::Size
extra_huge_bounds(max_texture_size
/ min_contents_scale
+ 1, 10);
1449 scoped_refptr
<FakePicturePileImpl
> extra_huge_pile
=
1450 FakePicturePileImpl::CreateFilledPile(tile_size
, extra_huge_bounds
);
1452 SetupPendingTree(extra_huge_pile
);
1453 pending_mask
->SetBounds(extra_huge_bounds
);
1454 pending_mask
->SetContentBounds(extra_huge_bounds
);
1455 pending_mask
->SetRasterSourceOnPending(extra_huge_pile
, Region());
1457 EXPECT_FALSE(pending_mask
->CanHaveTilings());
1459 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1460 host_impl_
.SetCurrentBeginFrameArgs(
1461 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1462 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1464 EXPECT_EQ(0u, pending_mask
->num_tilings());
1467 TEST_F(PictureLayerImplTest
, ScaledMaskLayer
) {
1468 base::TimeTicks time_ticks
;
1469 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1470 host_impl_
.SetCurrentBeginFrameArgs(
1471 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1473 gfx::Size
tile_size(100, 100);
1474 gfx::Size
layer_bounds(1000, 1000);
1476 host_impl_
.SetDeviceScaleFactor(1.3f
);
1478 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1479 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1480 SetupPendingTree(valid_pile
);
1482 scoped_ptr
<FakePictureLayerImpl
> mask_ptr
=
1483 FakePictureLayerImpl::CreateMaskWithRasterSource(
1484 host_impl_
.pending_tree(), 3, valid_pile
);
1485 mask_ptr
->SetBounds(layer_bounds
);
1486 mask_ptr
->SetContentBounds(layer_bounds
);
1487 mask_ptr
->SetDrawsContent(true);
1488 pending_layer_
->SetMaskLayer(mask_ptr
.Pass());
1489 pending_layer_
->SetHasRenderSurface(true);
1491 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1492 host_impl_
.SetCurrentBeginFrameArgs(
1493 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1494 bool update_lcd_text
= false;
1495 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1497 FakePictureLayerImpl
* pending_mask
=
1498 static_cast<FakePictureLayerImpl
*>(pending_layer_
->mask_layer());
1500 // Masks are scaled, and do not have a low res tiling.
1501 EXPECT_EQ(1.3f
, pending_mask
->HighResTiling()->contents_scale());
1502 EXPECT_EQ(1u, pending_mask
->num_tilings());
1504 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1505 pending_mask
->HighResTiling()->AllTilesForTesting());
1509 FakePictureLayerImpl
* active_mask
=
1510 static_cast<FakePictureLayerImpl
*>(active_layer_
->mask_layer());
1512 // Mask layers have a tiling with a single tile in it.
1513 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1514 // The mask resource exists.
1515 ResourceProvider::ResourceId mask_resource_id
;
1516 gfx::Size mask_texture_size
;
1517 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1518 EXPECT_NE(0u, mask_resource_id
);
1519 gfx::Size expected_mask_texture_size
=
1520 gfx::ToCeiledSize(gfx::ScaleSize(active_mask
->bounds(), 1.3f
));
1521 EXPECT_EQ(mask_texture_size
, expected_mask_texture_size
);
1524 TEST_F(PictureLayerImplTest
, ReleaseResources
) {
1525 gfx::Size
tile_size(400, 400);
1526 gfx::Size
layer_bounds(1300, 1900);
1528 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1529 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1530 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1531 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1533 SetupTrees(pending_pile
, active_pile
);
1534 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1536 // All tilings should be removed when losing output surface.
1537 active_layer_
->ReleaseResources();
1538 EXPECT_FALSE(active_layer_
->tilings());
1539 active_layer_
->RecreateResources();
1540 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1541 pending_layer_
->ReleaseResources();
1542 EXPECT_FALSE(pending_layer_
->tilings());
1543 pending_layer_
->RecreateResources();
1544 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1546 // This should create new tilings.
1547 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
1548 1.f
, // ideal contents scale
1549 1.f
, // device scale
1551 1.f
, // maximum animation scale
1552 0.f
, // starting animation_scale
1554 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1557 TEST_F(PictureLayerImplTest
, ClampTilesToMaxTileSize
) {
1558 // The default max tile size is larger than 400x400.
1559 gfx::Size
tile_size(400, 400);
1560 gfx::Size
layer_bounds(5000, 5000);
1562 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1563 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1565 SetupPendingTree(pending_pile
);
1566 EXPECT_GE(pending_layer_
->tilings()->num_tilings(), 1u);
1568 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1570 // The default value.
1571 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1572 host_impl_
.settings().default_tile_size
.ToString());
1574 Tile
* tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1575 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1576 tile
->content_rect().size().ToString());
1578 ResetTilingsAndRasterScales();
1580 // Change the max texture size on the output surface context.
1581 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1582 TestWebGraphicsContext3D::Create();
1583 context
->set_max_texture_size(140);
1584 host_impl_
.DidLoseOutputSurface();
1585 host_impl_
.InitializeRenderer(
1586 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1588 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1590 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1592 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1594 // Verify the tiles are not larger than the context's max texture size.
1595 tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1596 EXPECT_GE(140, tile
->content_rect().width());
1597 EXPECT_GE(140, tile
->content_rect().height());
1600 TEST_F(PictureLayerImplTest
, ClampSingleTileToToMaxTileSize
) {
1601 // The default max tile size is larger than 400x400.
1602 gfx::Size
tile_size(400, 400);
1603 gfx::Size
layer_bounds(500, 500);
1605 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1606 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1607 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1608 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1610 SetupTrees(pending_pile
, active_pile
);
1611 EXPECT_GE(active_layer_
->tilings()->num_tilings(), 1u);
1613 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1615 // The default value. The layer is smaller than this.
1616 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1617 host_impl_
.settings().max_untiled_layer_size
.ToString());
1619 // There should be a single tile since the layer is small.
1620 PictureLayerTiling
* high_res_tiling
= active_layer_
->tilings()->tiling_at(0);
1621 EXPECT_EQ(1u, high_res_tiling
->AllTilesForTesting().size());
1623 ResetTilingsAndRasterScales();
1625 // Change the max texture size on the output surface context.
1626 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1627 TestWebGraphicsContext3D::Create();
1628 context
->set_max_texture_size(140);
1629 host_impl_
.DidLoseOutputSurface();
1630 host_impl_
.InitializeRenderer(
1631 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1633 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
1635 ASSERT_LE(1u, active_layer_
->tilings()->num_tilings());
1637 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1639 // There should be more than one tile since the max texture size won't cover
1641 high_res_tiling
= active_layer_
->tilings()->tiling_at(0);
1642 EXPECT_LT(1u, high_res_tiling
->AllTilesForTesting().size());
1644 // Verify the tiles are not larger than the context's max texture size.
1645 Tile
* tile
= active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1646 EXPECT_GE(140, tile
->content_rect().width());
1647 EXPECT_GE(140, tile
->content_rect().height());
1650 TEST_F(PictureLayerImplTest
, DisallowTileDrawQuads
) {
1651 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1653 gfx::Size
tile_size(400, 400);
1654 gfx::Size
layer_bounds(1300, 1900);
1656 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1657 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1658 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1659 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1661 gfx::Rect
layer_invalidation(150, 200, 30, 180);
1662 SetupTreesWithInvalidation(pending_pile
, active_pile
, layer_invalidation
);
1664 active_layer_
->draw_properties().visible_content_rect
=
1665 gfx::Rect(layer_bounds
);
1667 AppendQuadsData data
;
1668 active_layer_
->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE
, nullptr);
1669 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1670 active_layer_
->DidDraw(nullptr);
1672 ASSERT_EQ(1U, render_pass
->quad_list
.size());
1673 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
,
1674 render_pass
->quad_list
.front()->material
);
1677 TEST_F(PictureLayerImplTest
, SolidColorLayerHasVisibleFullCoverage
) {
1678 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1680 gfx::Size
tile_size(1000, 1000);
1681 gfx::Size
layer_bounds(1500, 1500);
1682 gfx::Rect
visible_rect(250, 250, 1000, 1000);
1684 scoped_ptr
<FakePicturePile
> empty_recording
=
1685 FakePicturePile::CreateEmptyPile(tile_size
, layer_bounds
);
1686 empty_recording
->SetIsSolidColor(true);
1688 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1689 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
1690 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1691 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
1693 SetupTrees(pending_pile
, active_pile
);
1695 active_layer_
->draw_properties().visible_content_rect
= visible_rect
;
1697 AppendQuadsData data
;
1698 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1699 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1700 active_layer_
->DidDraw(nullptr);
1702 Region remaining
= visible_rect
;
1703 for (const auto& quad
: render_pass
->quad_list
) {
1704 EXPECT_TRUE(visible_rect
.Contains(quad
->rect
));
1705 EXPECT_TRUE(remaining
.Contains(quad
->rect
));
1706 remaining
.Subtract(quad
->rect
);
1709 EXPECT_TRUE(remaining
.IsEmpty());
1712 TEST_F(PictureLayerImplTest
, TileScalesWithSolidColorPile
) {
1713 gfx::Size
layer_bounds(200, 200);
1714 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1715 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1716 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1717 tile_size
, layer_bounds
, false);
1718 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1719 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1720 tile_size
, layer_bounds
, true);
1722 SetupTrees(pending_pile
, active_pile
);
1723 // Solid color pile should not allow tilings at any scale.
1724 EXPECT_FALSE(active_layer_
->CanHaveTilings());
1725 EXPECT_EQ(0.f
, active_layer_
->ideal_contents_scale());
1727 // Activate non-solid-color pending pile makes active layer can have tilings.
1729 EXPECT_TRUE(active_layer_
->CanHaveTilings());
1730 EXPECT_GT(active_layer_
->ideal_contents_scale(), 0.f
);
1733 TEST_F(NoLowResPictureLayerImplTest
, MarkRequiredOffscreenTiles
) {
1734 gfx::Size
tile_size(100, 100);
1735 gfx::Size
layer_bounds(200, 200);
1737 gfx::Transform transform
;
1738 gfx::Transform transform_for_tile_priority
;
1739 bool resourceless_software_draw
= false;
1740 gfx::Rect
viewport(0, 0, 100, 200);
1741 host_impl_
.SetExternalDrawConstraints(transform
,
1746 resourceless_software_draw
);
1748 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1749 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1750 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1752 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1753 EXPECT_EQ(viewport
, pending_layer_
->visible_rect_for_tile_priority());
1755 base::TimeTicks time_ticks
;
1756 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1757 host_impl_
.SetCurrentBeginFrameArgs(
1758 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1759 pending_layer_
->UpdateTiles(resourceless_software_draw
);
1761 int num_visible
= 0;
1762 int num_offscreen
= 0;
1764 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
1765 pending_layer_
->picture_layer_tiling_set(), false));
1766 for (; !queue
->IsEmpty(); queue
->Pop()) {
1767 const PrioritizedTile
& prioritized_tile
= queue
->Top();
1768 DCHECK(prioritized_tile
.tile());
1769 if (prioritized_tile
.priority().distance_to_visible
== 0.f
) {
1770 EXPECT_TRUE(prioritized_tile
.tile()->required_for_activation());
1773 EXPECT_FALSE(prioritized_tile
.tile()->required_for_activation());
1778 EXPECT_GT(num_visible
, 0);
1779 EXPECT_GT(num_offscreen
, 0);
1782 TEST_F(NoLowResPictureLayerImplTest
,
1783 TileOutsideOfViewportForTilePriorityNotRequired
) {
1784 base::TimeTicks time_ticks
;
1785 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1786 host_impl_
.SetCurrentBeginFrameArgs(
1787 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1789 gfx::Size
tile_size(100, 100);
1790 gfx::Size
layer_bounds(400, 400);
1791 gfx::Rect
external_viewport_for_tile_priority(400, 200);
1792 gfx::Rect
visible_content_rect(200, 400);
1794 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1795 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1796 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1797 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1798 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
1800 ASSERT_EQ(1u, pending_layer_
->num_tilings());
1801 ASSERT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
1803 // Set external viewport for tile priority.
1804 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
1805 gfx::Transform transform
;
1806 gfx::Transform transform_for_tile_priority
;
1807 bool resourceless_software_draw
= false;
1808 host_impl_
.SetExternalDrawConstraints(transform
,
1811 external_viewport_for_tile_priority
,
1812 transform_for_tile_priority
,
1813 resourceless_software_draw
);
1814 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1815 host_impl_
.SetCurrentBeginFrameArgs(
1816 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1817 bool update_lcd_text
= false;
1818 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1820 // Set visible content rect that is different from
1821 // external_viewport_for_tile_priority.
1822 pending_layer_
->draw_properties().visible_content_rect
= visible_content_rect
;
1823 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
1824 host_impl_
.SetCurrentBeginFrameArgs(
1825 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1826 pending_layer_
->UpdateTiles(resourceless_software_draw
);
1828 // Intersect the two rects. Any tile outside should not be required for
1830 gfx::Rect viewport_for_tile_priority
=
1831 pending_layer_
->viewport_rect_for_tile_priority_in_content_space();
1832 viewport_for_tile_priority
.Intersect(pending_layer_
->visible_content_rect());
1834 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
1837 int num_outside
= 0;
1838 for (PictureLayerTiling::CoverageIterator
iter(active_layer_
->HighResTiling(),
1839 1.f
, gfx::Rect(layer_bounds
));
1844 if (viewport_for_tile_priority
.Intersects(iter
.geometry_rect())) {
1846 // Mark everything in viewport for tile priority as ready to draw.
1847 TileDrawInfo
& draw_info
= tile
->draw_info();
1848 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
1851 EXPECT_FALSE(tile
->required_for_activation());
1855 EXPECT_GT(num_inside
, 0);
1856 EXPECT_GT(num_outside
, 0);
1858 // Activate and draw active layer.
1859 host_impl_
.ActivateSyncTree();
1860 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
1861 active_layer_
->draw_properties().visible_content_rect
= visible_content_rect
;
1863 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1864 AppendQuadsData data
;
1865 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1866 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1867 active_layer_
->DidDraw(nullptr);
1869 // All tiles in activation rect is ready to draw.
1870 EXPECT_EQ(0u, data
.num_missing_tiles
);
1871 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1872 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1875 TEST_F(PictureLayerImplTest
, HighResTileIsComplete
) {
1876 base::TimeTicks time_ticks
;
1877 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1878 host_impl_
.SetCurrentBeginFrameArgs(
1879 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1881 gfx::Size
tile_size(100, 100);
1882 gfx::Size
layer_bounds(200, 200);
1884 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1885 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1887 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1890 // All high res tiles have resources.
1891 std::vector
<Tile
*> tiles
=
1892 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1893 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
1895 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1896 AppendQuadsData data
;
1897 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1898 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1899 active_layer_
->DidDraw(nullptr);
1901 // All high res tiles drew, nothing was incomplete.
1902 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1903 EXPECT_EQ(0u, data
.num_missing_tiles
);
1904 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1905 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1908 TEST_F(PictureLayerImplTest
, HighResTileIsIncomplete
) {
1909 base::TimeTicks time_ticks
;
1910 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1911 host_impl_
.SetCurrentBeginFrameArgs(
1912 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1914 gfx::Size
tile_size(100, 100);
1915 gfx::Size
layer_bounds(200, 200);
1917 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1918 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1919 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1922 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1923 AppendQuadsData data
;
1924 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1925 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1926 active_layer_
->DidDraw(nullptr);
1928 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1929 EXPECT_EQ(1u, data
.num_missing_tiles
);
1930 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1931 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1934 TEST_F(PictureLayerImplTest
, HighResTileIsIncompleteLowResComplete
) {
1935 base::TimeTicks time_ticks
;
1936 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1937 host_impl_
.SetCurrentBeginFrameArgs(
1938 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1940 gfx::Size
tile_size(100, 100);
1941 gfx::Size
layer_bounds(200, 200);
1943 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1944 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1945 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1948 std::vector
<Tile
*> low_tiles
=
1949 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1950 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1952 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1953 AppendQuadsData data
;
1954 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1955 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1956 active_layer_
->DidDraw(nullptr);
1958 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1959 EXPECT_EQ(0u, data
.num_missing_tiles
);
1960 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1961 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1964 TEST_F(PictureLayerImplTest
, LowResTileIsIncomplete
) {
1965 base::TimeTicks time_ticks
;
1966 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1967 host_impl_
.SetCurrentBeginFrameArgs(
1968 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1970 gfx::Size
tile_size(100, 100);
1971 gfx::Size
layer_bounds(200, 200);
1973 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1974 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1975 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1978 // All high res tiles have resources except one.
1979 std::vector
<Tile
*> high_tiles
=
1980 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1981 high_tiles
.erase(high_tiles
.begin());
1982 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
1984 // All low res tiles have resources.
1985 std::vector
<Tile
*> low_tiles
=
1986 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1987 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1989 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1990 AppendQuadsData data
;
1991 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1992 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1993 active_layer_
->DidDraw(nullptr);
1995 // The missing high res tile was replaced by a low res tile.
1996 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1997 EXPECT_EQ(0u, data
.num_missing_tiles
);
1998 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1999 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
2002 TEST_F(PictureLayerImplTest
,
2003 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal
) {
2004 base::TimeTicks time_ticks
;
2005 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
2006 host_impl_
.SetCurrentBeginFrameArgs(
2007 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2009 gfx::Size
tile_size(100, 100);
2010 gfx::Size
layer_bounds(200, 200);
2011 gfx::Size
viewport_size(400, 400);
2013 host_impl_
.SetViewportSize(viewport_size
);
2014 host_impl_
.SetDeviceScaleFactor(2.f
);
2016 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2017 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2018 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2019 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2020 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2022 // One ideal tile exists, this will get used when drawing.
2023 std::vector
<Tile
*> ideal_tiles
;
2024 EXPECT_EQ(2.f
, active_layer_
->HighResTiling()->contents_scale());
2025 ideal_tiles
.push_back(active_layer_
->HighResTiling()->TileAt(0, 0));
2026 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
2029 // Due to layer scale throttling, the raster contents scale is changed to 1,
2030 // while the ideal is still 2.
2031 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
2033 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.f
, 1.f
, 1.f
, 1.f
, 0.f
,
2036 EXPECT_EQ(1.f
, active_layer_
->HighResTiling()->contents_scale());
2037 EXPECT_EQ(1.f
, active_layer_
->raster_contents_scale());
2038 EXPECT_EQ(2.f
, active_layer_
->ideal_contents_scale());
2040 // Both tilings still exist.
2041 EXPECT_EQ(2.f
, active_layer_
->tilings()->tiling_at(0)->contents_scale());
2042 EXPECT_EQ(1.f
, active_layer_
->tilings()->tiling_at(1)->contents_scale());
2044 // All high res tiles have resources.
2045 std::vector
<Tile
*> high_tiles
=
2046 active_layer_
->HighResTiling()->AllTilesForTesting();
2047 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
2049 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
2050 AppendQuadsData data
;
2051 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
2052 active_layer_
->AppendQuads(render_pass
.get(), &data
);
2053 active_layer_
->DidDraw(nullptr);
2055 // All high res tiles drew, and the one ideal res tile drew.
2056 ASSERT_GT(render_pass
->quad_list
.size(), 9u);
2057 EXPECT_EQ(gfx::SizeF(99.f
, 99.f
),
2058 TileDrawQuad::MaterialCast(render_pass
->quad_list
.front())
2059 ->tex_coord_rect
.size());
2060 EXPECT_EQ(gfx::SizeF(49.5f
, 49.5f
),
2061 TileDrawQuad::MaterialCast(render_pass
->quad_list
.ElementAt(1))
2062 ->tex_coord_rect
.size());
2064 // Neither the high res nor the ideal tiles were considered as incomplete.
2065 EXPECT_EQ(0u, data
.num_missing_tiles
);
2066 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
2067 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
2070 TEST_F(PictureLayerImplTest
, HighResRequiredWhenActiveAllReady
) {
2071 gfx::Size
layer_bounds(400, 400);
2072 gfx::Size
tile_size(100, 100);
2074 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
,
2075 gfx::Rect(layer_bounds
));
2077 active_layer_
->SetAllTilesReady();
2079 // All active tiles ready, so pending can only activate with all high res
2081 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2082 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2084 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2085 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2088 TEST_F(PictureLayerImplTest
, HighResRequiredWhenMissingHighResFlagOn
) {
2089 gfx::Size
layer_bounds(400, 400);
2090 gfx::Size
tile_size(100, 100);
2093 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2095 // Verify active tree not ready.
2096 Tile
* some_active_tile
=
2097 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2098 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
2100 // When high res are required, all tiles in active high res tiling should be
2101 // required for activation.
2102 host_impl_
.SetRequiresHighResToDraw();
2104 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2105 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2106 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2107 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2109 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
2110 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2111 AssertAllTilesRequired(active_layer_
->HighResTiling());
2112 AssertNoTilesRequired(active_layer_
->LowResTiling());
2115 TEST_F(PictureLayerImplTest
, AllHighResRequiredEvenIfNotChanged
) {
2116 gfx::Size
layer_bounds(400, 400);
2117 gfx::Size
tile_size(100, 100);
2119 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2121 Tile
* some_active_tile
=
2122 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2123 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
2125 // Since there are no invalidations, pending tree should have no tiles.
2126 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
2127 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2129 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2130 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2132 AssertAllTilesRequired(active_layer_
->HighResTiling());
2133 AssertNoTilesRequired(active_layer_
->LowResTiling());
2136 TEST_F(PictureLayerImplTest
, DisallowRequiredForActivation
) {
2137 gfx::Size
layer_bounds(400, 400);
2138 gfx::Size
tile_size(100, 100);
2140 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2142 Tile
* some_active_tile
=
2143 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2144 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
2146 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
2147 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2148 active_layer_
->HighResTiling()->set_can_require_tiles_for_activation(false);
2149 active_layer_
->LowResTiling()->set_can_require_tiles_for_activation(false);
2150 pending_layer_
->HighResTiling()->set_can_require_tiles_for_activation(false);
2151 pending_layer_
->LowResTiling()->set_can_require_tiles_for_activation(false);
2153 // If we disallow required for activation, no tiles can be required.
2154 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2155 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2157 AssertNoTilesRequired(active_layer_
->HighResTiling());
2158 AssertNoTilesRequired(active_layer_
->LowResTiling());
2161 TEST_F(PictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
2162 gfx::Size
layer_bounds(400, 400);
2163 gfx::Size
tile_size(100, 100);
2165 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2166 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2167 // This pile will create tilings, but has no recordings so will not create any
2168 // tiles. This is attempting to simulate scrolling past the end of recorded
2169 // content on the active layer, where the recordings are so far away that
2170 // no tiles are created.
2171 bool is_solid_color
= false;
2172 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2173 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
2174 tile_size
, layer_bounds
, is_solid_color
);
2176 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2178 // Active layer has tilings, but no tiles due to missing recordings.
2179 EXPECT_TRUE(active_layer_
->CanHaveTilings());
2180 EXPECT_EQ(active_layer_
->tilings()->num_tilings(), 2u);
2181 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
2183 // Since the active layer has no tiles at all, the pending layer doesn't
2184 // need content in order to activate.
2185 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2186 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2188 AssertNoTilesRequired(pending_layer_
->HighResTiling());
2189 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2192 TEST_F(PictureLayerImplTest
, HighResRequiredIfActiveCantHaveTiles
) {
2193 gfx::Size
layer_bounds(400, 400);
2194 gfx::Size
tile_size(100, 100);
2196 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2197 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2198 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2199 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
2200 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2202 // Active layer can't have tiles.
2203 EXPECT_FALSE(active_layer_
->CanHaveTilings());
2205 // All high res tiles required. This should be considered identical
2206 // to the case where there is no active layer, to avoid flashing content.
2207 // This can happen if a layer exists for a while and switches from
2208 // not being able to have content to having content.
2209 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2210 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2212 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2213 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2216 TEST_F(PictureLayerImplTest
, HighResRequiredWhenActiveHasDifferentBounds
) {
2217 gfx::Size
pending_layer_bounds(400, 400);
2218 gfx::Size
active_layer_bounds(200, 200);
2219 gfx::Size
tile_size(100, 100);
2221 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2222 FakePicturePileImpl::CreateFilledPile(tile_size
, pending_layer_bounds
);
2223 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2224 FakePicturePileImpl::CreateFilledPile(tile_size
, active_layer_bounds
);
2226 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2228 // Since the active layer has different bounds, the pending layer needs all
2229 // high res tiles in order to activate.
2230 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2231 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2232 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2233 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
2235 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2236 AssertAllTilesRequired(active_layer_
->HighResTiling());
2237 AssertNoTilesRequired(active_layer_
->LowResTiling());
2238 // Since the test doesn't invalidate the resized region, we expect that the
2239 // same low res tile would exist (which means we don't create a new one of the
2241 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
2244 TEST_F(PictureLayerImplTest
, ActivateUninitializedLayer
) {
2245 gfx::Size
tile_size(100, 100);
2246 gfx::Size
layer_bounds(400, 400);
2247 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2248 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2250 host_impl_
.CreatePendingTree();
2251 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
2253 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
2254 FakePictureLayerImpl::CreateWithRasterSource(pending_tree
, id_
,
2256 pending_layer
->SetDrawsContent(true);
2257 pending_tree
->SetRootLayer(pending_layer
.Pass());
2259 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
2260 host_impl_
.pending_tree()->LayerById(id_
));
2262 // Set some state on the pending layer, make sure it is not clobbered
2263 // by a sync from the active layer. This could happen because if the
2264 // pending layer has not been post-commit initialized it will attempt
2265 // to sync from the active layer.
2266 float raster_page_scale
= 10.f
* pending_layer_
->raster_page_scale();
2267 pending_layer_
->set_raster_page_scale(raster_page_scale
);
2269 host_impl_
.ActivateSyncTree();
2271 active_layer_
= static_cast<FakePictureLayerImpl
*>(
2272 host_impl_
.active_tree()->LayerById(id_
));
2274 EXPECT_EQ(0u, active_layer_
->num_tilings());
2275 EXPECT_EQ(raster_page_scale
, active_layer_
->raster_page_scale());
2278 TEST_F(PictureLayerImplTest
, ShareTilesOnNextFrame
) {
2279 gfx::Size
layer_bounds(1500, 1500);
2280 gfx::Size
tile_size(100, 100);
2282 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2283 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2285 SetupPendingTree(pending_pile
);
2287 PictureLayerTiling
* tiling
= pending_layer_
->HighResTiling();
2288 gfx::Rect first_invalidate
= tiling
->TilingDataForTesting().TileBounds(0, 0);
2289 first_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2290 tiling
->TilingDataForTesting().border_texels());
2291 gfx::Rect second_invalidate
= tiling
->TilingDataForTesting().TileBounds(1, 1);
2292 second_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2293 tiling
->TilingDataForTesting().border_texels());
2297 // Make a pending tree with an invalidated raster tile 0,0.
2298 SetupPendingTreeWithInvalidation(pending_pile
, first_invalidate
);
2300 // Activate and make a pending tree with an invalidated raster tile 1,1.
2303 SetupPendingTreeWithInvalidation(pending_pile
, second_invalidate
);
2305 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2306 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2308 // pending_tiling->CreateAllTilesForTesting();
2310 // Tile 0,0 not exist on pending, but tile 1,1 should.
2311 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2312 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2313 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2314 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2315 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2316 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2317 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2318 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2319 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2321 // Drop the tiles on the active tree and recreate them.
2322 active_tiling
->ComputeTilePriorityRects(gfx::Rect(), 1.f
, 1.0, Occlusion());
2323 EXPECT_TRUE(active_tiling
->AllTilesForTesting().empty());
2324 active_tiling
->CreateAllTilesForTesting();
2326 // Tile 0,0 not exist on pending, but tile 1,1 should.
2327 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2328 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2329 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2330 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2331 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2332 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2333 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2334 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2335 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2338 TEST_F(PictureLayerImplTest
, PendingHasNoTilesWithNoInvalidation
) {
2339 SetupDefaultTrees(gfx::Size(1500, 1500));
2341 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2342 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2345 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2346 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2347 ASSERT_TRUE(active_tiling
);
2348 ASSERT_TRUE(pending_tiling
);
2350 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2351 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2352 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2353 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2355 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2356 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2357 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2358 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
2361 TEST_F(PictureLayerImplTest
, ShareInvalidActiveTreeTiles
) {
2362 gfx::Size
tile_size(100, 100);
2363 gfx::Size
layer_bounds(1500, 1500);
2365 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2366 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2367 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2368 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2369 SetupTreesWithInvalidation(pending_pile
, active_pile
, gfx::Rect(1, 1));
2370 // Activate the invalidation.
2372 // Make another pending tree without any invalidation in it.
2373 scoped_refptr
<FakePicturePileImpl
> pending_pile2
=
2374 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2375 SetupPendingTree(pending_pile2
);
2377 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2378 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2380 // The active tree invalidation was handled by the active tiles.
2381 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2382 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2383 ASSERT_TRUE(active_tiling
);
2384 ASSERT_TRUE(pending_tiling
);
2386 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2387 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2388 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2389 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2391 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
2392 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2393 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2394 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
2397 TEST_F(PictureLayerImplTest
, RecreateInvalidPendingTreeTiles
) {
2398 // Set some invalidation on the pending tree. We should replace raster tiles
2400 SetupDefaultTreesWithInvalidation(gfx::Size(1500, 1500), gfx::Rect(1, 1));
2402 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2403 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2405 // The pending tree invalidation creates tiles on the pending tree.
2406 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2407 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2408 ASSERT_TRUE(active_tiling
);
2409 ASSERT_TRUE(pending_tiling
);
2411 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2412 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2413 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2414 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2416 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2417 EXPECT_FALSE(pending_tiling
->TileAt(1, 0));
2418 EXPECT_FALSE(pending_tiling
->TileAt(0, 1));
2419 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
2421 EXPECT_NE(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2424 TEST_F(PictureLayerImplTest
, SyncTilingAfterGpuRasterizationToggles
) {
2425 base::TimeTicks time_ticks
;
2426 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
2427 host_impl_
.SetCurrentBeginFrameArgs(
2428 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2430 gfx::Size
tile_size(100, 100);
2431 gfx::Size
layer_bounds(10, 10);
2433 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2434 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2435 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2436 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2438 SetupTrees(pending_pile
, active_pile
);
2440 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2441 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(1.f
));
2443 // Gpu rasterization is disabled by default.
2444 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2445 // Toggling the gpu rasterization clears all tilings on both trees.
2446 host_impl_
.set_has_gpu_rasterization_trigger(true);
2447 host_impl_
.set_content_is_suitable_for_gpu_rasterization(true);
2448 host_impl_
.UpdateGpuRasterizationStatus();
2449 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2450 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2452 // Make sure that we can still add tiling to the pending layer,
2453 // that gets synced to the active layer.
2454 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
2455 host_impl_
.SetCurrentBeginFrameArgs(
2456 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2457 bool update_lcd_text
= false;
2458 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
2459 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2462 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(1.f
));
2464 SetupPendingTree(pending_pile
);
2465 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2467 // Toggling the gpu rasterization clears all tilings on both trees.
2468 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2469 host_impl_
.set_has_gpu_rasterization_trigger(false);
2470 host_impl_
.UpdateGpuRasterizationStatus();
2471 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT
,
2472 host_impl_
.gpu_rasterization_status());
2473 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2474 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2476 host_impl_
.set_has_gpu_rasterization_trigger(true);
2477 host_impl_
.set_content_is_suitable_for_gpu_rasterization(false);
2478 host_impl_
.UpdateGpuRasterizationStatus();
2479 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT
,
2480 host_impl_
.gpu_rasterization_status());
2483 TEST_F(PictureLayerImplTest
, HighResCreatedWhenBoundsShrink
) {
2484 gfx::Size
tile_size(100, 100);
2486 // Put 0.5 as high res.
2487 host_impl_
.SetDeviceScaleFactor(0.5f
);
2489 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2490 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(10, 10));
2491 SetupPendingTree(pending_pile
);
2494 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2495 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(0.5f
));
2499 // Now, set the bounds to be 1x1, so that minimum contents scale becomes 1.
2501 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(1, 1));
2502 SetupPendingTree(pending_pile
);
2504 // Another sanity check.
2505 EXPECT_EQ(1.f
, pending_layer_
->MinimumContentsScale());
2507 // Since the MinContentsScale is 1, the 0.5 tiling should be replaced by a 1.0
2509 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 0.5f
, 1.f
, 1.f
, 1.f
, 0.f
,
2512 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2513 PictureLayerTiling
* tiling
=
2514 pending_layer_
->tilings()->FindTilingWithScale(1.0f
);
2515 ASSERT_TRUE(tiling
);
2516 EXPECT_EQ(HIGH_RESOLUTION
, tiling
->resolution());
2519 TEST_F(PictureLayerImplTest
, LowResTilingWithoutGpuRasterization
) {
2520 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
2521 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
2522 default_tile_size
.height() * 4);
2524 host_impl_
.set_has_gpu_rasterization_trigger(false);
2525 host_impl_
.UpdateGpuRasterizationStatus();
2527 SetupDefaultTrees(layer_bounds
);
2528 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2529 // Should have a low-res and a high-res tiling.
2530 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
2533 TEST_F(PictureLayerImplTest
, NoLowResTilingWithGpuRasterization
) {
2534 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
2535 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
2536 default_tile_size
.height() * 4);
2538 host_impl_
.set_has_gpu_rasterization_trigger(true);
2539 host_impl_
.set_content_is_suitable_for_gpu_rasterization(true);
2540 host_impl_
.UpdateGpuRasterizationStatus();
2542 SetupDefaultTrees(layer_bounds
);
2543 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2544 // Should only have the high-res tiling.
2545 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2548 TEST_F(PictureLayerImplTest
, RequiredTilesWithGpuRasterization
) {
2549 host_impl_
.set_has_gpu_rasterization_trigger(true);
2550 host_impl_
.set_content_is_suitable_for_gpu_rasterization(true);
2551 host_impl_
.UpdateGpuRasterizationStatus();
2553 gfx::Size
viewport_size(1000, 1000);
2554 host_impl_
.SetViewportSize(viewport_size
);
2556 gfx::Size
layer_bounds(4000, 4000);
2557 SetupDefaultTrees(layer_bounds
);
2558 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2560 // Should only have the high-res tiling.
2561 EXPECT_EQ(1u, active_layer_
->tilings()->num_tilings());
2563 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
2565 // High res tiling should have 64 tiles (4x16 tile grid).
2566 EXPECT_EQ(64u, active_layer_
->HighResTiling()->AllTilesForTesting().size());
2568 // Visible viewport should be covered by 4 tiles. No other
2569 // tiles should be required for activation.
2570 EXPECT_EQ(4u, NumberOfTilesRequired(active_layer_
->HighResTiling()));
2573 TEST_F(PictureLayerImplTest
, NoTilingIfDoesNotDrawContent
) {
2574 // Set up layers with tilings.
2575 SetupDefaultTrees(gfx::Size(10, 10));
2576 SetContentsScaleOnBothLayers(1.f
, 1.f
, 1.f
, 1.f
, 0.f
, false);
2577 pending_layer_
->PushPropertiesTo(active_layer_
);
2578 EXPECT_TRUE(pending_layer_
->DrawsContent());
2579 EXPECT_TRUE(pending_layer_
->CanHaveTilings());
2580 EXPECT_GE(pending_layer_
->num_tilings(), 0u);
2581 EXPECT_GE(active_layer_
->num_tilings(), 0u);
2583 // Set content to false, which should make CanHaveTilings return false.
2584 pending_layer_
->SetDrawsContent(false);
2585 EXPECT_FALSE(pending_layer_
->DrawsContent());
2586 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
2588 // No tilings should be pushed to active layer.
2589 pending_layer_
->PushPropertiesTo(active_layer_
);
2590 EXPECT_EQ(0u, active_layer_
->num_tilings());
2593 TEST_F(PictureLayerImplTest
, FirstTilingDuringPinch
) {
2594 SetupDefaultTrees(gfx::Size(10, 10));
2596 // We start with a tiling at scale 1.
2597 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
2599 // When we scale up by 2.3, we get a new tiling that is a power of 2, in this
2601 host_impl_
.PinchGestureBegin();
2602 float high_res_scale
= 2.3f
;
2603 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, 1.f
, 1.f
, 0.f
, false);
2604 EXPECT_EQ(4.f
, pending_layer_
->HighResTiling()->contents_scale());
2607 TEST_F(PictureLayerImplTest
, PinchingTooSmall
) {
2608 SetupDefaultTrees(gfx::Size(10, 10));
2610 // We start with a tiling at scale 1.
2611 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
2613 host_impl_
.PinchGestureBegin();
2614 float high_res_scale
= 0.0001f
;
2615 EXPECT_LT(high_res_scale
, pending_layer_
->MinimumContentsScale());
2617 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, high_res_scale
, 1.f
, 0.f
,
2619 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2620 pending_layer_
->HighResTiling()->contents_scale());
2623 TEST_F(PictureLayerImplTest
, PinchingTooSmallWithContentsScale
) {
2624 SetupDefaultTrees(gfx::Size(10, 10));
2626 ResetTilingsAndRasterScales();
2628 float contents_scale
= 0.15f
;
2629 SetContentsScaleOnBothLayers(contents_scale
, 1.f
, 1.f
, 1.f
, 0.f
, false);
2631 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2632 EXPECT_FLOAT_EQ(contents_scale
,
2633 pending_layer_
->HighResTiling()->contents_scale());
2635 host_impl_
.PinchGestureBegin();
2637 float page_scale
= 0.0001f
;
2638 EXPECT_LT(page_scale
* contents_scale
,
2639 pending_layer_
->MinimumContentsScale());
2641 SetContentsScaleOnBothLayers(contents_scale
* page_scale
, 1.f
, page_scale
,
2643 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2644 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2645 pending_layer_
->HighResTiling()->contents_scale());
2648 TEST_F(PictureLayerImplTest
, ConsiderAnimationStartScaleForRasterScale
) {
2649 gfx::Size
viewport_size(1000, 1000);
2650 host_impl_
.SetViewportSize(viewport_size
);
2652 gfx::Size
layer_bounds(100, 100);
2653 SetupDefaultTrees(layer_bounds
);
2655 float contents_scale
= 2.f
;
2656 float device_scale
= 1.f
;
2657 float page_scale
= 1.f
;
2658 float maximum_animation_scale
= 3.f
;
2659 float starting_animation_scale
= 1.f
;
2660 bool animating_transform
= true;
2662 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2664 // Maximum animation scale is greater than starting animation scale
2665 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2666 maximum_animation_scale
,
2667 starting_animation_scale
, animating_transform
);
2668 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2670 animating_transform
= false;
2672 // Once we stop animating, a new high-res tiling should be created.
2673 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2674 maximum_animation_scale
,
2675 starting_animation_scale
, animating_transform
);
2676 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2678 // Starting animation scale greater than maximum animation scale
2679 // Bounds at starting scale within the viewport
2680 animating_transform
= true;
2681 starting_animation_scale
= 5.f
;
2683 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2684 maximum_animation_scale
,
2685 starting_animation_scale
, animating_transform
);
2686 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 5.f
);
2688 // Once we stop animating, a new high-res tiling should be created.
2689 animating_transform
= false;
2690 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2691 maximum_animation_scale
,
2692 starting_animation_scale
, animating_transform
);
2693 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2695 // Starting Animation scale greater than maximum animation scale
2696 // Bounds at starting scale outisde the viewport
2697 animating_transform
= true;
2698 starting_animation_scale
= 11.f
;
2700 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2701 maximum_animation_scale
,
2702 starting_animation_scale
, animating_transform
);
2703 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2706 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForCpuRasterization
) {
2707 gfx::Size
viewport_size(1000, 1000);
2708 host_impl_
.SetViewportSize(viewport_size
);
2710 gfx::Size
layer_bounds(100, 100);
2711 SetupDefaultTrees(layer_bounds
);
2713 float contents_scale
= 1.f
;
2714 float device_scale
= 1.f
;
2715 float page_scale
= 1.f
;
2716 float maximum_animation_scale
= 1.f
;
2717 float starting_animation_scale
= 0.f
;
2718 bool animating_transform
= false;
2720 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2722 // Since we're CPU-rasterizing, starting an animation should cause tiling
2723 // resolution to get set to the maximum animation scale factor.
2724 animating_transform
= true;
2725 maximum_animation_scale
= 3.f
;
2726 contents_scale
= 2.f
;
2728 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2729 maximum_animation_scale
,
2730 starting_animation_scale
, animating_transform
);
2731 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2733 // Further changes to scale during the animation should not cause a new
2734 // high-res tiling to get created.
2735 contents_scale
= 4.f
;
2736 maximum_animation_scale
= 5.f
;
2738 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2739 maximum_animation_scale
,
2740 starting_animation_scale
, animating_transform
);
2741 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2743 // Once we stop animating, a new high-res tiling should be created.
2744 animating_transform
= false;
2746 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2747 maximum_animation_scale
,
2748 starting_animation_scale
, animating_transform
);
2749 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2751 // When animating with an unknown maximum animation scale factor, a new
2752 // high-res tiling should be created at a source scale of 1.
2753 animating_transform
= true;
2754 contents_scale
= 2.f
;
2755 maximum_animation_scale
= 0.f
;
2757 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2758 maximum_animation_scale
,
2759 starting_animation_scale
, animating_transform
);
2760 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2762 // Further changes to scale during the animation should not cause a new
2763 // high-res tiling to get created.
2764 contents_scale
= 3.f
;
2766 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2767 maximum_animation_scale
,
2768 starting_animation_scale
, animating_transform
);
2769 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2771 // Once we stop animating, a new high-res tiling should be created.
2772 animating_transform
= false;
2773 contents_scale
= 4.f
;
2775 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2776 maximum_animation_scale
,
2777 starting_animation_scale
, animating_transform
);
2778 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2780 // When animating with a maxmium animation scale factor that is so large
2781 // that the layer grows larger than the viewport at this scale, a new
2782 // high-res tiling should get created at a source scale of 1, not at its
2784 animating_transform
= true;
2785 contents_scale
= 2.f
;
2786 maximum_animation_scale
= 11.f
;
2788 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2789 maximum_animation_scale
,
2790 starting_animation_scale
, animating_transform
);
2791 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2793 // Once we stop animating, a new high-res tiling should be created.
2794 animating_transform
= false;
2795 contents_scale
= 11.f
;
2797 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2798 maximum_animation_scale
,
2799 starting_animation_scale
, animating_transform
);
2800 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2802 // When animating with a maxmium animation scale factor that is so large
2803 // that the layer grows larger than the viewport at this scale, and where
2804 // the intial source scale is < 1, a new high-res tiling should get created
2805 // at source scale 1.
2806 animating_transform
= true;
2807 contents_scale
= 0.1f
;
2808 maximum_animation_scale
= 11.f
;
2810 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2811 maximum_animation_scale
,
2812 starting_animation_scale
, animating_transform
);
2813 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2815 // Once we stop animating, a new high-res tiling should be created.
2816 animating_transform
= false;
2817 contents_scale
= 12.f
;
2819 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2820 maximum_animation_scale
,
2821 starting_animation_scale
, animating_transform
);
2822 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 12.f
);
2824 // When animating toward a smaller scale, but that is still so large that the
2825 // layer grows larger than the viewport at this scale, a new high-res tiling
2826 // should get created at source scale 1.
2827 animating_transform
= true;
2828 contents_scale
= 11.f
;
2829 maximum_animation_scale
= 11.f
;
2831 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2832 maximum_animation_scale
,
2833 starting_animation_scale
, animating_transform
);
2834 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2836 // Once we stop animating, a new high-res tiling should be created.
2837 animating_transform
= false;
2838 contents_scale
= 11.f
;
2840 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2841 maximum_animation_scale
,
2842 starting_animation_scale
, animating_transform
);
2843 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2846 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForGpuRasterization
) {
2847 gfx::Size
layer_bounds(100, 100);
2848 gfx::Size
viewport_size(1000, 1000);
2849 SetupDefaultTrees(layer_bounds
);
2850 host_impl_
.SetViewportSize(viewport_size
);
2851 host_impl_
.set_has_gpu_rasterization_trigger(true);
2852 host_impl_
.set_content_is_suitable_for_gpu_rasterization(true);
2853 host_impl_
.UpdateGpuRasterizationStatus();
2855 float contents_scale
= 1.f
;
2856 float device_scale
= 1.3f
;
2857 float page_scale
= 1.4f
;
2858 float maximum_animation_scale
= 1.f
;
2859 float starting_animation_scale
= 0.f
;
2860 bool animating_transform
= false;
2862 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2863 maximum_animation_scale
,
2864 starting_animation_scale
, animating_transform
);
2865 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2867 // Since we're GPU-rasterizing, starting an animation should cause tiling
2868 // resolution to get set to the current contents scale.
2869 animating_transform
= true;
2870 contents_scale
= 2.f
;
2871 maximum_animation_scale
= 4.f
;
2873 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2874 maximum_animation_scale
,
2875 starting_animation_scale
, animating_transform
);
2876 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2878 // Further changes to scale during the animation should cause a new high-res
2879 // tiling to get created.
2880 contents_scale
= 3.f
;
2882 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2883 maximum_animation_scale
,
2884 starting_animation_scale
, animating_transform
);
2885 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2887 // Since we're re-rasterizing during the animation, scales smaller than 1
2888 // should be respected.
2889 contents_scale
= 0.25f
;
2891 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2892 maximum_animation_scale
,
2893 starting_animation_scale
, animating_transform
);
2894 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.25f
);
2896 // Once we stop animating, a new high-res tiling should be created.
2897 contents_scale
= 4.f
;
2898 animating_transform
= false;
2900 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
2901 maximum_animation_scale
,
2902 starting_animation_scale
, animating_transform
);
2903 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2906 TEST_F(PictureLayerImplTest
, TilingSetRasterQueue
) {
2907 base::TimeTicks time_ticks
;
2908 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
2909 host_impl_
.SetCurrentBeginFrameArgs(
2910 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2912 host_impl_
.SetViewportSize(gfx::Size(500, 500));
2914 gfx::Size
recording_tile_size(100, 100);
2915 gfx::Size
layer_bounds(1000, 1000);
2917 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2918 FakePicturePileImpl::CreateFilledPile(recording_tile_size
, layer_bounds
);
2920 SetupPendingTree(pending_pile
);
2921 EXPECT_EQ(2u, pending_layer_
->num_tilings());
2923 std::set
<Tile
*> unique_tiles
;
2924 bool reached_prepaint
= false;
2925 int non_ideal_tile_count
= 0u;
2926 int low_res_tile_count
= 0u;
2927 int high_res_tile_count
= 0u;
2928 int high_res_now_tiles
= 0u;
2929 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
2930 pending_layer_
->picture_layer_tiling_set(), false));
2931 while (!queue
->IsEmpty()) {
2932 PrioritizedTile prioritized_tile
= queue
->Top();
2933 TilePriority priority
= prioritized_tile
.priority();
2935 EXPECT_TRUE(prioritized_tile
.tile());
2937 // Non-high res tiles only get visible tiles. Also, prepaint should only
2938 // come at the end of the iteration.
2939 if (priority
.resolution
!= HIGH_RESOLUTION
) {
2940 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
2941 } else if (reached_prepaint
) {
2942 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
2944 reached_prepaint
= priority
.priority_bin
!= TilePriority::NOW
;
2945 if (!reached_prepaint
)
2946 ++high_res_now_tiles
;
2949 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
2950 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
2951 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2953 unique_tiles
.insert(prioritized_tile
.tile());
2957 EXPECT_TRUE(reached_prepaint
);
2958 EXPECT_EQ(0, non_ideal_tile_count
);
2959 EXPECT_EQ(0, low_res_tile_count
);
2961 // With layer size being 1000x1000 and default tile size 256x256, we expect to
2962 // see 4 now tiles out of 16 total high res tiles.
2963 EXPECT_EQ(16, high_res_tile_count
);
2964 EXPECT_EQ(4, high_res_now_tiles
);
2965 EXPECT_EQ(low_res_tile_count
+ high_res_tile_count
+ non_ideal_tile_count
,
2966 static_cast<int>(unique_tiles
.size()));
2968 scoped_ptr
<TilingSetRasterQueueRequired
> required_queue(
2969 new TilingSetRasterQueueRequired(
2970 pending_layer_
->picture_layer_tiling_set(),
2971 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
));
2972 EXPECT_TRUE(required_queue
->IsEmpty());
2974 required_queue
.reset(new TilingSetRasterQueueRequired(
2975 pending_layer_
->picture_layer_tiling_set(),
2976 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
2977 EXPECT_FALSE(required_queue
->IsEmpty());
2978 int required_for_activation_count
= 0;
2979 while (!required_queue
->IsEmpty()) {
2980 PrioritizedTile prioritized_tile
= required_queue
->Top();
2981 EXPECT_TRUE(prioritized_tile
.tile()->required_for_activation());
2982 EXPECT_FALSE(prioritized_tile
.tile()->IsReadyToDraw());
2983 ++required_for_activation_count
;
2984 required_queue
->Pop();
2987 // All of the high res tiles should be required for activation, since there is
2989 EXPECT_EQ(high_res_now_tiles
, required_for_activation_count
);
2992 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
2993 host_impl_
.SetCurrentBeginFrameArgs(
2994 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2996 pending_layer_
->draw_properties().visible_content_rect
=
2997 gfx::Rect(1100, 1100, 500, 500);
2998 bool resourceless_software_draw
= false;
2999 pending_layer_
->UpdateTiles(resourceless_software_draw
);
3001 unique_tiles
.clear();
3002 high_res_tile_count
= 0u;
3003 queue
.reset(new TilingSetRasterQueueAll(
3004 pending_layer_
->picture_layer_tiling_set(), false));
3005 while (!queue
->IsEmpty()) {
3006 PrioritizedTile prioritized_tile
= queue
->Top();
3007 TilePriority priority
= prioritized_tile
.priority();
3009 EXPECT_TRUE(prioritized_tile
.tile());
3011 // Non-high res tiles only get visible tiles.
3012 EXPECT_EQ(HIGH_RESOLUTION
, priority
.resolution
);
3013 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
3015 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
3017 unique_tiles
.insert(prioritized_tile
.tile());
3021 EXPECT_EQ(16, high_res_tile_count
);
3022 EXPECT_EQ(high_res_tile_count
, static_cast<int>(unique_tiles
.size()));
3024 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
3025 host_impl_
.SetCurrentBeginFrameArgs(
3026 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3028 pending_layer_
->draw_properties().visible_content_rect
=
3029 gfx::Rect(0, 0, 500, 500);
3030 pending_layer_
->UpdateTiles(resourceless_software_draw
);
3032 std::vector
<Tile
*> high_res_tiles
=
3033 pending_layer_
->HighResTiling()->AllTilesForTesting();
3034 for (std::vector
<Tile
*>::iterator tile_it
= high_res_tiles
.begin();
3035 tile_it
!= high_res_tiles
.end();
3037 Tile
* tile
= *tile_it
;
3038 TileDrawInfo
& draw_info
= tile
->draw_info();
3039 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
3042 non_ideal_tile_count
= 0;
3043 low_res_tile_count
= 0;
3044 high_res_tile_count
= 0;
3045 queue
.reset(new TilingSetRasterQueueAll(
3046 pending_layer_
->picture_layer_tiling_set(), true));
3047 while (!queue
->IsEmpty()) {
3048 PrioritizedTile prioritized_tile
= queue
->Top();
3049 TilePriority priority
= prioritized_tile
.priority();
3051 EXPECT_TRUE(prioritized_tile
.tile());
3053 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
3054 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
3055 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
3059 EXPECT_EQ(0, non_ideal_tile_count
);
3060 EXPECT_EQ(1, low_res_tile_count
);
3061 EXPECT_EQ(0, high_res_tile_count
);
3064 TEST_F(PictureLayerImplTest
, TilingSetRasterQueueActiveTree
) {
3065 base::TimeTicks time_ticks
;
3066 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
3067 host_impl_
.SetCurrentBeginFrameArgs(
3068 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3070 host_impl_
.SetViewportSize(gfx::Size(500, 500));
3072 gfx::Size
tile_size(100, 100);
3073 gfx::Size
layer_bounds(1000, 1000);
3075 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3076 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3078 SetupPendingTree(pending_pile
);
3080 EXPECT_EQ(2u, active_layer_
->num_tilings());
3082 scoped_ptr
<TilingSetRasterQueueRequired
> queue(
3083 new TilingSetRasterQueueRequired(
3084 active_layer_
->picture_layer_tiling_set(),
3085 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
));
3086 EXPECT_FALSE(queue
->IsEmpty());
3087 while (!queue
->IsEmpty()) {
3088 PrioritizedTile prioritized_tile
= queue
->Top();
3089 EXPECT_TRUE(prioritized_tile
.tile()->required_for_draw());
3090 EXPECT_FALSE(prioritized_tile
.tile()->IsReadyToDraw());
3094 queue
.reset(new TilingSetRasterQueueRequired(
3095 active_layer_
->picture_layer_tiling_set(),
3096 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
3097 EXPECT_TRUE(queue
->IsEmpty());
3100 TEST_F(PictureLayerImplTest
, TilingSetRasterQueueRequiredNoHighRes
) {
3101 scoped_ptr
<FakePicturePile
> empty_recording
=
3102 FakePicturePile::CreateEmptyPile(gfx::Size(256, 256),
3103 gfx::Size(1024, 1024));
3104 empty_recording
->SetIsSolidColor(true);
3106 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3107 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
3109 SetupPendingTree(pending_pile
);
3111 pending_layer_
->picture_layer_tiling_set()->FindTilingWithResolution(
3114 scoped_ptr
<TilingSetRasterQueueRequired
> queue(
3115 new TilingSetRasterQueueRequired(
3116 pending_layer_
->picture_layer_tiling_set(),
3117 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
3118 EXPECT_TRUE(queue
->IsEmpty());
3121 TEST_F(PictureLayerImplTest
, TilingSetEvictionQueue
) {
3122 gfx::Size
tile_size(100, 100);
3123 gfx::Size
layer_bounds(1000, 1000);
3124 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3126 host_impl_
.SetViewportSize(gfx::Size(500, 500));
3128 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3129 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3131 // TODO(vmpstr): Add a test with tilings other than high/low res on the active
3133 SetupPendingTree(pending_pile
);
3134 EXPECT_EQ(2u, pending_layer_
->num_tilings());
3136 std::vector
<Tile
*> all_tiles
;
3137 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3138 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3139 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
3140 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
3143 std::set
<Tile
*> all_tiles_set(all_tiles
.begin(), all_tiles
.end());
3145 bool mark_required
= false;
3146 size_t number_of_marked_tiles
= 0u;
3147 size_t number_of_unmarked_tiles
= 0u;
3148 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3149 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3150 for (PictureLayerTiling::CoverageIterator
iter(
3152 pending_layer_
->contents_scale_x(),
3153 pending_layer_
->visible_content_rect());
3156 if (mark_required
) {
3157 number_of_marked_tiles
++;
3158 iter
->set_required_for_activation(true);
3160 number_of_unmarked_tiles
++;
3162 mark_required
= !mark_required
;
3167 EXPECT_EQ(17u, all_tiles
.size());
3168 EXPECT_EQ(17u, all_tiles_set
.size());
3169 EXPECT_GT(number_of_marked_tiles
, 1u);
3170 EXPECT_GT(number_of_unmarked_tiles
, 1u);
3172 // Tiles don't have resources yet.
3173 scoped_ptr
<TilingSetEvictionQueue
> queue(
3174 new TilingSetEvictionQueue(pending_layer_
->picture_layer_tiling_set()));
3175 EXPECT_TRUE(queue
->IsEmpty());
3177 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
3179 std::set
<Tile
*> unique_tiles
;
3180 float expected_scales
[] = {low_res_factor
, 1.f
};
3181 size_t scale_index
= 0;
3182 bool reached_visible
= false;
3183 PrioritizedTile last_tile
;
3184 size_t distance_decreasing
= 0;
3185 size_t distance_increasing
= 0;
3187 new TilingSetEvictionQueue(pending_layer_
->picture_layer_tiling_set()));
3188 while (!queue
->IsEmpty()) {
3189 PrioritizedTile prioritized_tile
= queue
->Top();
3190 Tile
* tile
= prioritized_tile
.tile();
3191 if (!last_tile
.tile())
3192 last_tile
= prioritized_tile
;
3196 TilePriority priority
= prioritized_tile
.priority();
3198 if (priority
.priority_bin
== TilePriority::NOW
) {
3199 reached_visible
= true;
3200 last_tile
= prioritized_tile
;
3204 EXPECT_FALSE(tile
->required_for_activation());
3206 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
3207 std::numeric_limits
<float>::epsilon()) {
3209 ASSERT_LT(scale_index
, arraysize(expected_scales
));
3212 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
3213 unique_tiles
.insert(tile
);
3215 if (tile
->required_for_activation() ==
3216 last_tile
.tile()->required_for_activation() &&
3217 std::abs(tile
->contents_scale() - last_tile
.tile()->contents_scale()) <
3218 std::numeric_limits
<float>::epsilon()) {
3219 if (priority
.distance_to_visible
<=
3220 last_tile
.priority().distance_to_visible
)
3221 ++distance_decreasing
;
3223 ++distance_increasing
;
3226 last_tile
= prioritized_tile
;
3230 // 4 high res tiles are inside the viewport, the rest are evicted.
3231 EXPECT_TRUE(reached_visible
);
3232 EXPECT_EQ(12u, unique_tiles
.size());
3233 EXPECT_EQ(1u, distance_increasing
);
3234 EXPECT_EQ(11u, distance_decreasing
);
3237 bool reached_required
= false;
3238 while (!queue
->IsEmpty()) {
3239 PrioritizedTile prioritized_tile
= queue
->Top();
3240 Tile
* tile
= prioritized_tile
.tile();
3243 TilePriority priority
= prioritized_tile
.priority();
3244 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
3246 if (reached_required
) {
3247 EXPECT_TRUE(tile
->required_for_activation());
3248 } else if (tile
->required_for_activation()) {
3249 reached_required
= true;
3253 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
3254 std::numeric_limits
<float>::epsilon()) {
3256 ASSERT_LT(scale_index
, arraysize(expected_scales
));
3259 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
3260 unique_tiles
.insert(tile
);
3264 EXPECT_TRUE(reached_required
);
3265 EXPECT_EQ(all_tiles_set
.size(), unique_tiles
.size());
3268 TEST_F(PictureLayerImplTest
, Occlusion
) {
3269 gfx::Size
tile_size(102, 102);
3270 gfx::Size
layer_bounds(1000, 1000);
3271 gfx::Size
viewport_size(1000, 1000);
3273 LayerTestCommon::LayerImplTest impl
;
3274 host_impl_
.SetViewportSize(viewport_size
);
3276 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3277 FakePicturePileImpl::CreateFilledPile(layer_bounds
, layer_bounds
);
3278 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
3281 std::vector
<Tile
*> tiles
=
3282 active_layer_
->HighResTiling()->AllTilesForTesting();
3283 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3286 SCOPED_TRACE("No occlusion");
3288 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3290 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
3291 gfx::Rect(layer_bounds
));
3292 EXPECT_EQ(100u, impl
.quad_list().size());
3296 SCOPED_TRACE("Full occlusion");
3297 gfx::Rect
occluded(active_layer_
->visible_content_rect());
3298 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3300 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(), gfx::Rect());
3301 EXPECT_EQ(impl
.quad_list().size(), 0u);
3305 SCOPED_TRACE("Partial occlusion");
3306 gfx::Rect
occluded(150, 0, 200, 1000);
3307 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3309 size_t partially_occluded_count
= 0;
3310 LayerTestCommon::VerifyQuadsAreOccluded(
3311 impl
.quad_list(), occluded
, &partially_occluded_count
);
3312 // The layer outputs one quad, which is partially occluded.
3313 EXPECT_EQ(100u - 10u, impl
.quad_list().size());
3314 EXPECT_EQ(10u + 10u, partially_occluded_count
);
3318 TEST_F(PictureLayerImplTest
, RasterScaleChangeWithoutAnimation
) {
3319 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
3320 SetupDefaultTrees(tile_size
);
3322 ResetTilingsAndRasterScales();
3324 float contents_scale
= 2.f
;
3325 float device_scale
= 1.f
;
3326 float page_scale
= 1.f
;
3327 float maximum_animation_scale
= 1.f
;
3328 float starting_animation_scale
= 0.f
;
3329 bool animating_transform
= false;
3331 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
3332 maximum_animation_scale
,
3333 starting_animation_scale
, animating_transform
);
3334 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
3336 // Changing the source scale without being in an animation will cause
3337 // the layer to reset its source scale to 1.f.
3338 contents_scale
= 3.f
;
3340 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
3341 maximum_animation_scale
,
3342 starting_animation_scale
, animating_transform
);
3343 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3345 // Further changes to the source scale will no longer be reflected in the
3347 contents_scale
= 0.5f
;
3349 SetContentsScaleOnBothLayers(contents_scale
, device_scale
, page_scale
,
3350 maximum_animation_scale
,
3351 starting_animation_scale
, animating_transform
);
3352 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3355 TEST_F(PictureLayerImplTest
, LowResReadyToDrawNotEnoughToActivate
) {
3356 gfx::Size
tile_size(100, 100);
3357 gfx::Size
layer_bounds(1000, 1000);
3359 // Make sure pending tree has tiles.
3360 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3361 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3363 // All pending layer tiles required are not ready.
3364 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3366 // Initialize all low-res tiles.
3367 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3368 pending_layer_
->SetAllTilesReadyInTiling(active_layer_
->LowResTiling());
3370 // Low-res tiles should not be enough.
3371 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3373 // Initialize remaining tiles.
3374 pending_layer_
->SetAllTilesReady();
3375 active_layer_
->SetAllTilesReady();
3377 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3380 TEST_F(PictureLayerImplTest
, HighResReadyToDrawEnoughToActivate
) {
3381 gfx::Size
tile_size(100, 100);
3382 gfx::Size
layer_bounds(1000, 1000);
3384 // Make sure pending tree has tiles.
3385 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3386 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3388 // All pending layer tiles required are not ready.
3389 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3391 // Initialize all high-res tiles.
3392 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3393 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3395 // High-res tiles should be enough, since they cover everything visible.
3396 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3399 TEST_F(PictureLayerImplTest
,
3400 ActiveHighResReadyAndPendingLowResReadyNotEnoughToActivate
) {
3401 gfx::Size
tile_size(100, 100);
3402 gfx::Size
layer_bounds(1000, 1000);
3404 // Make sure pending tree has tiles.
3405 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3406 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3408 // Initialize all high-res tiles in the active layer.
3409 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3410 // And all the low-res tiles in the pending layer.
3411 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3413 // The pending high-res tiles are not ready, so we cannot activate.
3414 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3416 // When the pending high-res tiles are ready, we can activate.
3417 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3418 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3421 TEST_F(PictureLayerImplTest
, ActiveHighResReadyNotEnoughToActivate
) {
3422 gfx::Size
tile_size(100, 100);
3423 gfx::Size
layer_bounds(1000, 1000);
3425 // Make sure pending tree has tiles.
3426 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3427 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3429 // Initialize all high-res tiles in the active layer.
3430 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3432 // The pending high-res tiles are not ready, so we cannot activate.
3433 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3435 // When the pending pending high-res tiles are ready, we can activate.
3436 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3437 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3440 TEST_F(NoLowResPictureLayerImplTest
, ManageTilingsCreatesTilings
) {
3441 gfx::Size
tile_size(400, 400);
3442 gfx::Size
layer_bounds(1300, 1900);
3444 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3445 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3446 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3447 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3449 SetupTrees(pending_pile
, active_pile
);
3451 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3452 EXPECT_LT(low_res_factor
, 1.f
);
3454 ResetTilingsAndRasterScales();
3456 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3457 6.f
, // ideal contents scale
3458 3.f
, // device scale
3460 1.f
, // maximum animation scale
3461 0.f
, // starting animation scale
3463 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3464 EXPECT_FLOAT_EQ(6.f
,
3465 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3467 // If we change the page scale factor, then we should get new tilings.
3468 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3469 6.6f
, // ideal contents scale
3470 3.f
, // device scale
3472 1.f
, // maximum animation scale
3473 0.f
, // starting animation scale
3475 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3476 EXPECT_FLOAT_EQ(6.6f
,
3477 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3479 // If we change the device scale factor, then we should get new tilings.
3480 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3481 7.26f
, // ideal contents scale
3482 3.3f
, // device scale
3484 1.f
, // maximum animation scale
3485 0.f
, // starting animation scale
3487 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
3488 EXPECT_FLOAT_EQ(7.26f
,
3489 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3491 // If we change the device scale factor, but end up at the same total scale
3492 // factor somehow, then we don't get new tilings.
3493 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3494 7.26f
, // ideal contents scale
3495 2.2f
, // device scale
3497 1.f
, // maximum animation scale
3498 0.f
, // starting animation scale
3500 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
3501 EXPECT_FLOAT_EQ(7.26f
,
3502 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3505 TEST_F(NoLowResPictureLayerImplTest
, PendingLayerOnlyHasHighResTiling
) {
3506 gfx::Size
tile_size(400, 400);
3507 gfx::Size
layer_bounds(1300, 1900);
3509 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3510 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3511 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3512 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3514 SetupTrees(pending_pile
, active_pile
);
3516 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3517 EXPECT_LT(low_res_factor
, 1.f
);
3519 ResetTilingsAndRasterScales();
3521 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3522 6.f
, // ideal contents scale
3523 3.f
, // device scale
3525 1.f
, // maximum animation scale
3526 0.f
, // starting animation scale
3528 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3529 EXPECT_FLOAT_EQ(6.f
,
3530 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3532 // If we change the page scale factor, then we should get new tilings.
3533 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3534 6.6f
, // ideal contents scale
3535 3.f
, // device scale
3537 1.f
, // maximum animation scale
3538 0.f
, // starting animation scale
3540 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3541 EXPECT_FLOAT_EQ(6.6f
,
3542 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3544 // If we change the device scale factor, then we should get new tilings.
3545 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3546 7.26f
, // ideal contents scale
3547 3.3f
, // device scale
3549 1.f
, // maximum animation scale
3550 0.f
, // starting animation scale
3552 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3553 EXPECT_FLOAT_EQ(7.26f
,
3554 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3556 // If we change the device scale factor, but end up at the same total scale
3557 // factor somehow, then we don't get new tilings.
3558 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3559 7.26f
, // ideal contents scale
3560 2.2f
, // device scale
3562 1.f
, // maximum animation scale
3563 0.f
, // starting animation scale
3565 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3566 EXPECT_FLOAT_EQ(7.26f
,
3567 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3570 TEST_F(NoLowResPictureLayerImplTest
, AllHighResRequiredEvenIfNotChanged
) {
3571 gfx::Size
layer_bounds(400, 400);
3572 gfx::Size
tile_size(100, 100);
3574 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
3576 Tile
* some_active_tile
=
3577 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
3578 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
3580 // Since there is no invalidation, pending tree should have no tiles.
3581 EXPECT_TRUE(pending_layer_
->HighResTiling()->AllTilesForTesting().empty());
3582 if (host_impl_
.settings().create_low_res_tiling
)
3583 EXPECT_TRUE(pending_layer_
->LowResTiling()->AllTilesForTesting().empty());
3585 active_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
3586 if (host_impl_
.settings().create_low_res_tiling
)
3587 active_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
3589 AssertAllTilesRequired(active_layer_
->HighResTiling());
3590 if (host_impl_
.settings().create_low_res_tiling
)
3591 AssertNoTilesRequired(active_layer_
->LowResTiling());
3594 TEST_F(NoLowResPictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
3595 gfx::Size
layer_bounds(400, 400);
3596 gfx::Size
tile_size(100, 100);
3598 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3599 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3600 // This pile will create tilings, but has no recordings so will not create any
3601 // tiles. This is attempting to simulate scrolling past the end of recorded
3602 // content on the active layer, where the recordings are so far away that
3603 // no tiles are created.
3604 bool is_solid_color
= false;
3605 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3606 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
3607 tile_size
, layer_bounds
, is_solid_color
);
3609 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
3611 // Active layer has tilings, but no tiles due to missing recordings.
3612 EXPECT_TRUE(active_layer_
->CanHaveTilings());
3613 EXPECT_EQ(active_layer_
->tilings()->num_tilings(),
3614 host_impl_
.settings().create_low_res_tiling
? 2u : 1u);
3615 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
3617 // Since the active layer has no tiles at all, the pending layer doesn't
3618 // need content in order to activate.
3619 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
3620 if (host_impl_
.settings().create_low_res_tiling
)
3621 pending_layer_
->LowResTiling()->UpdateAllRequiredStateForTesting();
3623 AssertNoTilesRequired(pending_layer_
->HighResTiling());
3624 if (host_impl_
.settings().create_low_res_tiling
)
3625 AssertNoTilesRequired(pending_layer_
->LowResTiling());
3628 TEST_F(NoLowResPictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
3629 base::TimeTicks time_ticks
;
3630 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
3631 host_impl_
.SetCurrentBeginFrameArgs(
3632 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3634 gfx::Size
tile_size(100, 100);
3635 gfx::Size
layer_bounds(400, 400);
3637 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3638 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3639 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3640 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3642 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
3644 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
3647 // UpdateTiles with valid viewport. Should update tile viewport.
3648 // Note viewport is considered invalid if and only if in resourceless
3650 bool resourceless_software_draw
= false;
3651 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
3652 gfx::Transform transform
;
3653 host_impl_
.SetExternalDrawConstraints(transform
,
3658 resourceless_software_draw
);
3659 active_layer_
->draw_properties().visible_content_rect
= viewport
;
3660 active_layer_
->draw_properties().screen_space_transform
= transform
;
3661 active_layer_
->UpdateTiles(resourceless_software_draw
);
3663 gfx::Rect visible_rect_for_tile_priority
=
3664 active_layer_
->visible_rect_for_tile_priority();
3665 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
3666 gfx::Transform screen_space_transform_for_tile_priority
=
3667 active_layer_
->screen_space_transform();
3669 // Expand viewport and set it as invalid for prioritizing tiles.
3670 // Should update viewport and transform, but not update visible rect.
3671 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
3672 host_impl_
.SetCurrentBeginFrameArgs(
3673 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3674 resourceless_software_draw
= true;
3675 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
3676 transform
.Translate(1.f
, 1.f
);
3677 active_layer_
->draw_properties().visible_content_rect
= viewport
;
3678 active_layer_
->draw_properties().screen_space_transform
= transform
;
3679 host_impl_
.SetExternalDrawConstraints(transform
,
3684 resourceless_software_draw
);
3685 active_layer_
->UpdateTiles(resourceless_software_draw
);
3687 // Transform for tile priority is updated.
3688 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3689 active_layer_
->screen_space_transform());
3690 // Visible rect for tile priority retains old value.
3691 EXPECT_EQ(visible_rect_for_tile_priority
,
3692 active_layer_
->visible_rect_for_tile_priority());
3694 // Keep expanded viewport but mark it valid. Should update tile viewport.
3695 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
3696 host_impl_
.SetCurrentBeginFrameArgs(
3697 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3698 resourceless_software_draw
= false;
3699 host_impl_
.SetExternalDrawConstraints(transform
,
3704 resourceless_software_draw
);
3705 active_layer_
->UpdateTiles(resourceless_software_draw
);
3707 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3708 active_layer_
->screen_space_transform());
3709 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
3712 TEST_F(NoLowResPictureLayerImplTest
, CleanUpTilings
) {
3713 gfx::Size
tile_size(400, 400);
3714 gfx::Size
layer_bounds(1300, 1900);
3716 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3717 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3718 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3719 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3721 std::vector
<PictureLayerTiling
*> used_tilings
;
3723 SetupTrees(pending_pile
, active_pile
);
3725 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3726 EXPECT_LT(low_res_factor
, 1.f
);
3728 float device_scale
= 1.7f
;
3729 float page_scale
= 3.2f
;
3732 ResetTilingsAndRasterScales();
3734 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, 0.f
,
3736 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3738 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
3739 // |used_tilings| variable, and it's here only to ensure that active_layer_
3740 // won't remove tilings before the test has a chance to verify behavior.
3741 active_layer_
->MarkAllTilingsUsed();
3743 // We only have ideal tilings, so they aren't removed.
3744 used_tilings
.clear();
3745 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3746 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3748 host_impl_
.PinchGestureBegin();
3750 // Changing the ideal but not creating new tilings.
3753 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, 0.f
,
3755 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3757 // The tilings are still our target scale, so they aren't removed.
3758 used_tilings
.clear();
3759 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3760 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3762 host_impl_
.PinchGestureEnd();
3764 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
3767 SetContentsScaleOnBothLayers(1.2f
, device_scale
, page_scale
, 1.f
, 0.f
, false);
3768 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3769 EXPECT_FLOAT_EQ(1.f
,
3770 active_layer_
->tilings()->tiling_at(1)->contents_scale());
3772 // Ensure UpdateTiles won't remove any tilings.
3773 active_layer_
->MarkAllTilingsUsed();
3775 // Mark the non-ideal tilings as used. They won't be removed.
3776 used_tilings
.clear();
3777 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3778 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3779 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3781 // Now move the ideal scale to 0.5. Our target stays 1.2.
3782 SetContentsScaleOnBothLayers(0.5f
, device_scale
, page_scale
, 1.f
, 0.f
, false);
3784 // The high resolution tiling is between target and ideal, so is not
3785 // removed. The low res tiling for the old ideal=1.0 scale is removed.
3786 used_tilings
.clear();
3787 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3788 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3790 // Now move the ideal scale to 1.0. Our target stays 1.2.
3791 SetContentsScaleOnBothLayers(1.f
, device_scale
, page_scale
, 1.f
, 0.f
, false);
3793 // All the tilings are between are target and the ideal, so they are not
3795 used_tilings
.clear();
3796 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3797 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3799 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
3800 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.1f
, device_scale
,
3801 page_scale
, 1.f
, 0.f
, false);
3803 // Because the pending layer's ideal scale is still 1.0, our tilings fall
3804 // in the range [1.0,1.2] and are kept.
3805 used_tilings
.clear();
3806 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3807 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3809 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
3811 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.1f
, device_scale
,
3812 page_scale
, 1.f
, 0.f
, false);
3814 // Our 1.0 tiling now falls outside the range between our ideal scale and our
3815 // target raster scale. But it is in our used tilings set, so nothing is
3817 used_tilings
.clear();
3818 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3819 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3820 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3822 // If we remove it from our used tilings set, it is outside the range to keep
3823 // so it is deleted.
3824 used_tilings
.clear();
3825 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3826 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3829 TEST_F(NoLowResPictureLayerImplTest
, ReleaseResources
) {
3830 gfx::Size
tile_size(400, 400);
3831 gfx::Size
layer_bounds(1300, 1900);
3833 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3834 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3835 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3836 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3838 SetupTrees(pending_pile
, active_pile
);
3839 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3840 EXPECT_EQ(1u, active_layer_
->tilings()->num_tilings());
3842 // All tilings should be removed when losing output surface.
3843 active_layer_
->ReleaseResources();
3844 EXPECT_FALSE(active_layer_
->tilings());
3845 active_layer_
->RecreateResources();
3846 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
3847 pending_layer_
->ReleaseResources();
3848 EXPECT_FALSE(pending_layer_
->tilings());
3849 pending_layer_
->RecreateResources();
3850 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
3852 // This should create new tilings.
3853 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3854 1.3f
, // ideal contents scale
3855 2.7f
, // device scale
3857 1.f
, // maximum animation scale
3858 0.f
, // starting animation scale
3860 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3863 TEST_F(PictureLayerImplTest
, SharedQuadStateContainsMaxTilingScale
) {
3864 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3866 gfx::Size
tile_size(400, 400);
3867 gfx::Size
layer_bounds(1000, 2000);
3869 host_impl_
.SetViewportSize(gfx::Size(10000, 20000));
3871 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3872 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3873 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3874 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3876 SetupTrees(pending_pile
, active_pile
);
3878 ResetTilingsAndRasterScales();
3879 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.5f
, 1.f
, 1.f
, 1.f
, 0.f
,
3882 float max_contents_scale
= active_layer_
->MaximumTilingContentsScale();
3883 EXPECT_EQ(2.5f
, max_contents_scale
);
3885 gfx::Transform scaled_draw_transform
= active_layer_
->draw_transform();
3886 scaled_draw_transform
.Scale(SK_MScalar1
/ max_contents_scale
,
3887 SK_MScalar1
/ max_contents_scale
);
3889 AppendQuadsData data
;
3890 active_layer_
->AppendQuads(render_pass
.get(), &data
);
3892 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
3893 EXPECT_EQ(1u, render_pass
->shared_quad_state_list
.size());
3894 // The content_to_target_transform should be scaled by the
3895 // MaximumTilingContentsScale on the layer.
3896 EXPECT_EQ(scaled_draw_transform
.ToString(),
3897 render_pass
->shared_quad_state_list
.front()
3898 ->content_to_target_transform
.ToString());
3899 // The content_bounds should be scaled by the
3900 // MaximumTilingContentsScale on the layer.
3902 gfx::Size(2500u, 5000u).ToString(),
3903 render_pass
->shared_quad_state_list
.front()->content_bounds
.ToString());
3904 // The visible_content_rect should be scaled by the
3905 // MaximumTilingContentsScale on the layer.
3906 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
3907 render_pass
->shared_quad_state_list
.front()
3908 ->visible_content_rect
.ToString());
3911 class PictureLayerImplTestWithDelegatingRenderer
: public PictureLayerImplTest
{
3913 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {}
3915 void InitializeRenderer() override
{
3916 host_impl_
.InitializeRenderer(FakeOutputSurface::CreateDelegating3d());
3920 TEST_F(PictureLayerImplTestWithDelegatingRenderer
,
3921 DelegatingRendererWithTileOOM
) {
3922 // This test is added for crbug.com/402321, where quad should be produced when
3923 // raster on demand is not allowed and tile is OOM.
3924 gfx::Size tile_size
= host_impl_
.settings().default_tile_size
;
3925 gfx::Size
layer_bounds(1000, 1000);
3928 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3929 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3930 SetupPendingTree(pending_pile
);
3931 pending_layer_
->SetBounds(layer_bounds
);
3933 bool update_lcd_text
= false;
3934 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
3935 std::vector
<Tile
*> tiles
=
3936 active_layer_
->HighResTiling()->AllTilesForTesting();
3937 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3939 // Force tiles after max_tiles to be OOM. TileManager uses
3940 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3941 // directly set state to host_impl_, so we set policy that would change the
3942 // state. We also need to update tree priority separately.
3943 GlobalStateThatImpactsTilePriority state
;
3944 size_t max_tiles
= 1;
3945 size_t memory_limit
= max_tiles
* 4 * tile_size
.width() * tile_size
.height();
3946 size_t resource_limit
= max_tiles
;
3947 ManagedMemoryPolicy
policy(memory_limit
,
3948 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
,
3950 host_impl_
.SetMemoryPolicy(policy
);
3951 host_impl_
.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES
);
3952 host_impl_
.PrepareTiles();
3954 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3955 AppendQuadsData data
;
3956 active_layer_
->WillDraw(DRAW_MODE_HARDWARE
, nullptr);
3957 active_layer_
->AppendQuads(render_pass
.get(), &data
);
3958 active_layer_
->DidDraw(nullptr);
3960 // Even when OOM, quads should be produced, and should be different material
3961 // from quads with resource.
3962 EXPECT_LT(max_tiles
, render_pass
->quad_list
.size());
3963 EXPECT_EQ(DrawQuad::Material::TILED_CONTENT
,
3964 render_pass
->quad_list
.front()->material
);
3965 EXPECT_EQ(DrawQuad::Material::SOLID_COLOR
,
3966 render_pass
->quad_list
.back()->material
);
3969 class OcclusionTrackingSettings
: public LowResTilingsSettings
{
3971 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization
= true; }
3974 class OcclusionTrackingPictureLayerImplTest
: public PictureLayerImplTest
{
3976 OcclusionTrackingPictureLayerImplTest()
3977 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
3979 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl
* layer
,
3981 size_t expected_occluded_tile_count
,
3983 size_t occluded_tile_count
= 0u;
3984 PrioritizedTile last_tile
;
3986 scoped_ptr
<TilingSetEvictionQueue
> queue(
3987 new TilingSetEvictionQueue(layer
->picture_layer_tiling_set()));
3988 while (!queue
->IsEmpty()) {
3989 PrioritizedTile prioritized_tile
= queue
->Top();
3990 Tile
* tile
= prioritized_tile
.tile();
3991 if (!last_tile
.tile())
3992 last_tile
= prioritized_tile
;
3994 // The only way we will encounter an occluded tile after an unoccluded
3995 // tile is if the priorty bin decreased, the tile is required for
3996 // activation, or the scale changed.
3997 bool tile_is_occluded
= prioritized_tile
.is_occluded();
3998 if (tile_is_occluded
) {
3999 occluded_tile_count
++;
4001 bool last_tile_is_occluded
= last_tile
.is_occluded();
4002 if (!last_tile_is_occluded
) {
4003 TilePriority::PriorityBin tile_priority_bin
=
4004 prioritized_tile
.priority().priority_bin
;
4005 TilePriority::PriorityBin last_tile_priority_bin
=
4006 last_tile
.priority().priority_bin
;
4008 EXPECT_TRUE(tile_priority_bin
< last_tile_priority_bin
||
4009 tile
->required_for_activation() ||
4010 tile
->contents_scale() !=
4011 last_tile
.tile()->contents_scale())
4012 << "line: " << source_line
;
4015 last_tile
= prioritized_tile
;
4018 EXPECT_EQ(expected_occluded_tile_count
, occluded_tile_count
)
4019 << "line: " << source_line
;
4023 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4024 OccludedTilesSkippedDuringRasterization
) {
4025 base::TimeTicks time_ticks
;
4026 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4027 host_impl_
.SetCurrentBeginFrameArgs(
4028 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4030 gfx::Size
tile_size(102, 102);
4031 gfx::Size
layer_bounds(1000, 1000);
4032 gfx::Size
viewport_size(500, 500);
4033 gfx::Point
occluding_layer_position(310, 0);
4035 host_impl_
.SetViewportSize(viewport_size
);
4037 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4038 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4039 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4042 int unoccluded_tile_count
= 0;
4043 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
4044 pending_layer_
->picture_layer_tiling_set(), false));
4045 while (!queue
->IsEmpty()) {
4046 PrioritizedTile prioritized_tile
= queue
->Top();
4047 Tile
* tile
= prioritized_tile
.tile();
4049 // Occluded tiles should not be iterated over.
4050 EXPECT_FALSE(prioritized_tile
.is_occluded());
4052 // Some tiles may not be visible (i.e. outside the viewport). The rest are
4053 // visible and at least partially unoccluded, verified by the above expect.
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(unoccluded_tile_count
, 25);
4062 // Partial occlusion.
4063 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4064 LayerImpl
* layer1
= pending_layer_
->children()[0];
4065 layer1
->SetBounds(layer_bounds
);
4066 layer1
->SetContentBounds(layer_bounds
);
4067 layer1
->SetDrawsContent(true);
4068 layer1
->SetContentsOpaque(true);
4069 layer1
->SetPosition(occluding_layer_position
);
4071 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4072 host_impl_
.SetCurrentBeginFrameArgs(
4073 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4074 bool update_lcd_text
= false;
4075 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4077 unoccluded_tile_count
= 0;
4078 queue
.reset(new TilingSetRasterQueueAll(
4079 pending_layer_
->picture_layer_tiling_set(), false));
4080 while (!queue
->IsEmpty()) {
4081 PrioritizedTile prioritized_tile
= queue
->Top();
4082 Tile
* tile
= prioritized_tile
.tile();
4084 EXPECT_FALSE(prioritized_tile
.is_occluded());
4086 bool tile_is_visible
=
4087 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
4088 if (tile_is_visible
)
4089 unoccluded_tile_count
++;
4092 EXPECT_EQ(20, unoccluded_tile_count
);
4095 layer1
->SetPosition(gfx::Point(0, 0));
4097 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4098 host_impl_
.SetCurrentBeginFrameArgs(
4099 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4100 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4102 unoccluded_tile_count
= 0;
4103 queue
.reset(new TilingSetRasterQueueAll(
4104 pending_layer_
->picture_layer_tiling_set(), false));
4105 while (!queue
->IsEmpty()) {
4106 PrioritizedTile prioritized_tile
= queue
->Top();
4107 Tile
* tile
= prioritized_tile
.tile();
4109 EXPECT_FALSE(prioritized_tile
.is_occluded());
4111 bool tile_is_visible
=
4112 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
4113 if (tile_is_visible
)
4114 unoccluded_tile_count
++;
4117 EXPECT_EQ(unoccluded_tile_count
, 0);
4120 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4121 OccludedTilesNotMarkedAsRequired
) {
4122 base::TimeTicks time_ticks
;
4123 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4124 host_impl_
.SetCurrentBeginFrameArgs(
4125 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4127 gfx::Size
tile_size(102, 102);
4128 gfx::Size
layer_bounds(1000, 1000);
4129 gfx::Size
viewport_size(500, 500);
4130 gfx::Point
occluding_layer_position(310, 0);
4132 host_impl_
.SetViewportSize(viewport_size
);
4134 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4135 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4136 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4139 int occluded_tile_count
= 0;
4140 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4141 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4142 auto prioritized_tiles
=
4143 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4145 occluded_tile_count
= 0;
4146 for (PictureLayerTiling::CoverageIterator
iter(
4148 pending_layer_
->contents_scale_x(),
4149 gfx::Rect(layer_bounds
));
4154 const Tile
* tile
= *iter
;
4156 // Fully occluded tiles are not required for activation.
4157 if (prioritized_tiles
[tile
].is_occluded()) {
4158 EXPECT_FALSE(tile
->required_for_activation());
4159 occluded_tile_count
++;
4162 EXPECT_EQ(occluded_tile_count
, 0);
4165 // Partial occlusion.
4166 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4167 LayerImpl
* layer1
= pending_layer_
->children()[0];
4168 layer1
->SetBounds(layer_bounds
);
4169 layer1
->SetContentBounds(layer_bounds
);
4170 layer1
->SetDrawsContent(true);
4171 layer1
->SetContentsOpaque(true);
4172 layer1
->SetPosition(occluding_layer_position
);
4174 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4175 host_impl_
.SetCurrentBeginFrameArgs(
4176 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4177 bool update_lcd_text
= false;
4178 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4180 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4181 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4182 auto prioritized_tiles
=
4183 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4185 occluded_tile_count
= 0;
4186 for (PictureLayerTiling::CoverageIterator
iter(
4188 pending_layer_
->contents_scale_x(),
4189 gfx::Rect(layer_bounds
));
4194 const Tile
* tile
= *iter
;
4196 if (prioritized_tiles
[tile
].is_occluded()) {
4197 EXPECT_FALSE(tile
->required_for_activation());
4198 occluded_tile_count
++;
4203 EXPECT_EQ(occluded_tile_count
, 5);
4206 EXPECT_EQ(occluded_tile_count
, 2);
4214 layer1
->SetPosition(gfx::PointF(0, 0));
4216 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4217 host_impl_
.SetCurrentBeginFrameArgs(
4218 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4219 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4221 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4222 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4223 auto prioritized_tiles
=
4224 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4226 occluded_tile_count
= 0;
4227 for (PictureLayerTiling::CoverageIterator
iter(
4229 pending_layer_
->contents_scale_x(),
4230 gfx::Rect(layer_bounds
));
4235 const Tile
* tile
= *iter
;
4237 if (prioritized_tiles
[tile
].is_occluded()) {
4238 EXPECT_FALSE(tile
->required_for_activation());
4239 occluded_tile_count
++;
4244 EXPECT_EQ(25, occluded_tile_count
);
4247 EXPECT_EQ(4, occluded_tile_count
);
4255 TEST_F(OcclusionTrackingPictureLayerImplTest
, OcclusionForDifferentScales
) {
4256 base::TimeTicks time_ticks
;
4257 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4258 host_impl_
.SetCurrentBeginFrameArgs(
4259 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4261 gfx::Size
tile_size(102, 102);
4262 gfx::Size
layer_bounds(1000, 1000);
4263 gfx::Size
viewport_size(500, 500);
4264 gfx::Point
occluding_layer_position(310, 0);
4266 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4267 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4269 host_impl_
.SetViewportSize(viewport_size
);
4271 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4272 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
4274 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4275 LayerImpl
* layer1
= pending_layer_
->children()[0];
4276 layer1
->SetBounds(layer_bounds
);
4277 layer1
->SetContentBounds(layer_bounds
);
4278 layer1
->SetDrawsContent(true);
4279 layer1
->SetContentsOpaque(true);
4280 layer1
->SetPosition(occluding_layer_position
);
4282 pending_layer_
->tilings()->RemoveAllTilings();
4283 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
4284 pending_layer_
->AddTiling(low_res_factor
);
4285 pending_layer_
->AddTiling(0.3f
);
4286 pending_layer_
->AddTiling(0.7f
);
4287 pending_layer_
->AddTiling(1.0f
);
4288 pending_layer_
->AddTiling(2.0f
);
4290 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4291 host_impl_
.SetCurrentBeginFrameArgs(
4292 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4293 // UpdateDrawProperties with the occluding layer.
4294 bool update_lcd_text
= false;
4295 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4297 EXPECT_EQ(5u, pending_layer_
->num_tilings());
4299 int occluded_tile_count
= 0;
4300 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4301 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4302 auto prioritized_tiles
=
4303 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4304 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4306 occluded_tile_count
= 0;
4307 for (size_t j
= 0; j
< tiles
.size(); ++j
) {
4308 if (prioritized_tiles
[tiles
[j
]].is_occluded()) {
4309 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4310 tiles
[j
]->content_rect(), 1.0f
/ tiles
[j
]->contents_scale());
4311 EXPECT_GE(scaled_content_rect
.x(), occluding_layer_position
.x());
4312 occluded_tile_count
++;
4318 EXPECT_EQ(occluded_tile_count
, 30);
4321 EXPECT_EQ(occluded_tile_count
, 5);
4324 EXPECT_EQ(occluded_tile_count
, 4);
4328 EXPECT_EQ(occluded_tile_count
, 2);
4336 TEST_F(OcclusionTrackingPictureLayerImplTest
, DifferentOcclusionOnTrees
) {
4337 gfx::Size
tile_size(102, 102);
4338 gfx::Size
layer_bounds(1000, 1000);
4339 gfx::Size
viewport_size(1000, 1000);
4340 gfx::Point
occluding_layer_position(310, 0);
4341 gfx::Rect
invalidation_rect(230, 230, 102, 102);
4343 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4344 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4345 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4346 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4348 host_impl_
.SetViewportSize(viewport_size
);
4349 SetupPendingTree(active_pile
);
4351 // Partially occlude the active layer.
4352 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 2));
4353 LayerImpl
* layer1
= pending_layer_
->children()[0];
4354 layer1
->SetBounds(layer_bounds
);
4355 layer1
->SetContentBounds(layer_bounds
);
4356 layer1
->SetDrawsContent(true);
4357 layer1
->SetContentsOpaque(true);
4358 layer1
->SetPosition(occluding_layer_position
);
4362 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4363 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4364 auto prioritized_tiles
=
4365 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4368 PictureLayerTiling::CoverageIterator
iter(
4369 tiling
, active_layer_
->contents_scale_x(), gfx::Rect(layer_bounds
));
4373 const Tile
* tile
= *iter
;
4375 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4376 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4377 // Tiles are occluded on the active tree iff they lie beneath the
4379 EXPECT_EQ(prioritized_tiles
[tile
].is_occluded(),
4380 scaled_content_rect
.x() >= occluding_layer_position
.x());
4384 // Partially invalidate the pending layer.
4385 SetupPendingTreeWithInvalidation(pending_pile
, invalidation_rect
);
4387 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4388 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4389 auto prioritized_tiles
=
4390 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4392 for (PictureLayerTiling::CoverageIterator
iter(
4394 active_layer_
->contents_scale_x(),
4395 gfx::Rect(layer_bounds
));
4400 const Tile
* tile
= *iter
;
4402 // All tiles are unoccluded, because the pending tree has no occlusion.
4403 EXPECT_FALSE(prioritized_tiles
[tile
].is_occluded());
4405 Tile
* twin_tile
= active_layer_
->GetPendingOrActiveTwinTiling(tiling
)
4406 ->TileAt(iter
.i(), iter
.j());
4407 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4408 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4410 if (scaled_content_rect
.Intersects(invalidation_rect
)) {
4411 // Tiles inside the invalidation rect exist on both trees.
4413 EXPECT_TRUE(twin_tile
);
4414 EXPECT_NE(tile
, twin_tile
);
4416 // Tiles outside the invalidation rect only exist on the active tree.
4418 EXPECT_FALSE(twin_tile
);
4424 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4425 OccludedTilesConsideredDuringEviction
) {
4426 base::TimeTicks time_ticks
;
4427 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4428 host_impl_
.SetCurrentBeginFrameArgs(
4429 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4431 gfx::Size
tile_size(102, 102);
4432 gfx::Size
layer_bounds(1000, 1000);
4433 gfx::Size
viewport_size(1000, 1000);
4434 gfx::Point
pending_occluding_layer_position(310, 0);
4435 gfx::Point
active_occluding_layer_position(0, 310);
4436 gfx::Rect
invalidation_rect(230, 230, 152, 152);
4438 host_impl_
.SetViewportSize(viewport_size
);
4439 host_impl_
.SetDeviceScaleFactor(2.f
);
4441 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4442 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4443 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4444 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4446 SetupPendingTreeWithFixedTileSize(active_pile
, tile_size
, Region());
4448 // Partially occlude the active layer.
4449 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 2));
4450 LayerImpl
* active_occluding_layer
= pending_layer_
->children()[0];
4451 active_occluding_layer
->SetBounds(layer_bounds
);
4452 active_occluding_layer
->SetContentBounds(layer_bounds
);
4453 active_occluding_layer
->SetDrawsContent(true);
4454 active_occluding_layer
->SetContentsOpaque(true);
4455 active_occluding_layer
->SetPosition(active_occluding_layer_position
);
4459 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4461 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, invalidation_rect
);
4463 // Partially occlude the pending layer in a different way.
4464 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 3));
4465 LayerImpl
* pending_occluding_layer
= pending_layer_
->children()[0];
4466 pending_occluding_layer
->SetBounds(layer_bounds
);
4467 pending_occluding_layer
->SetContentBounds(layer_bounds
);
4468 pending_occluding_layer
->SetDrawsContent(true);
4469 pending_occluding_layer
->SetContentsOpaque(true);
4470 pending_occluding_layer
->SetPosition(pending_occluding_layer_position
);
4472 EXPECT_EQ(2u, pending_layer_
->num_tilings());
4473 EXPECT_EQ(2u, active_layer_
->num_tilings());
4475 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4476 host_impl_
.SetCurrentBeginFrameArgs(
4477 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4478 // UpdateDrawProperties with the occluding layer.
4479 bool update_lcd_text
= false;
4480 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4482 // The expected number of occluded tiles on each of the 2 tilings for each of
4483 // the 3 tree priorities.
4484 size_t expected_occluded_tile_count_on_pending
[] = {4u, 0u};
4485 size_t expected_occluded_tile_count_on_active
[] = {12u, 1u};
4486 size_t total_expected_occluded_tile_count_on_trees
[] = {13u, 4u};
4488 // Verify number of occluded tiles on the pending layer for each tiling.
4489 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4490 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4491 auto prioritized_tiles
=
4492 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4494 size_t occluded_tile_count_on_pending
= 0u;
4495 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4496 gfx::Rect(layer_bounds
));
4500 if (invalidation_rect
.Intersects(iter
.geometry_rect()))
4507 if (prioritized_tiles
[tile
].is_occluded())
4508 occluded_tile_count_on_pending
++;
4510 EXPECT_EQ(expected_occluded_tile_count_on_pending
[i
],
4511 occluded_tile_count_on_pending
)
4512 << tiling
->contents_scale();
4515 // Verify number of occluded tiles on the active layer for each tiling.
4516 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4517 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4518 auto prioritized_tiles
=
4519 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
4521 size_t occluded_tile_count_on_active
= 0u;
4522 for (PictureLayerTiling::CoverageIterator
iter(
4524 pending_layer_
->contents_scale_x(),
4525 gfx::Rect(layer_bounds
));
4532 if (prioritized_tiles
[tile
].is_occluded())
4533 occluded_tile_count_on_active
++;
4535 EXPECT_EQ(expected_occluded_tile_count_on_active
[i
],
4536 occluded_tile_count_on_active
)
4540 std::vector
<Tile
*> all_tiles
;
4541 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4542 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4543 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4544 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
4546 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4547 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4548 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4549 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
4552 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
4554 VerifyEvictionConsidersOcclusion(
4555 pending_layer_
, PENDING_TREE
,
4556 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
], __LINE__
);
4557 VerifyEvictionConsidersOcclusion(
4558 active_layer_
, ACTIVE_TREE
,
4559 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
], __LINE__
);
4561 // Repeat the tests without valid active tree priorities.
4562 active_layer_
->set_has_valid_tile_priorities(false);
4563 VerifyEvictionConsidersOcclusion(
4564 pending_layer_
, PENDING_TREE
,
4565 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
], __LINE__
);
4566 VerifyEvictionConsidersOcclusion(
4567 active_layer_
, ACTIVE_TREE
,
4568 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
], __LINE__
);
4569 active_layer_
->set_has_valid_tile_priorities(true);
4571 // Repeat the tests without valid pending tree priorities.
4572 pending_layer_
->set_has_valid_tile_priorities(false);
4573 VerifyEvictionConsidersOcclusion(
4574 active_layer_
, ACTIVE_TREE
,
4575 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
], __LINE__
);
4576 VerifyEvictionConsidersOcclusion(
4577 pending_layer_
, PENDING_TREE
,
4578 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
], __LINE__
);
4579 pending_layer_
->set_has_valid_tile_priorities(true);
4582 TEST_F(PictureLayerImplTest
, PendingOrActiveTwinLayer
) {
4583 gfx::Size
tile_size(102, 102);
4584 gfx::Size
layer_bounds(1000, 1000);
4586 scoped_refptr
<FakePicturePileImpl
> pile
=
4587 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4588 SetupPendingTree(pile
);
4589 EXPECT_FALSE(pending_layer_
->GetPendingOrActiveTwinLayer());
4592 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4594 SetupPendingTree(pile
);
4595 EXPECT_TRUE(pending_layer_
->GetPendingOrActiveTwinLayer());
4596 EXPECT_TRUE(active_layer_
->GetPendingOrActiveTwinLayer());
4597 EXPECT_EQ(pending_layer_
, active_layer_
->GetPendingOrActiveTwinLayer());
4598 EXPECT_EQ(active_layer_
, pending_layer_
->GetPendingOrActiveTwinLayer());
4601 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4603 // Make an empty pending tree.
4604 host_impl_
.CreatePendingTree();
4605 host_impl_
.pending_tree()->DetachLayerTree();
4606 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4609 TEST_F(PictureLayerImplTest
, RecycledTwinLayer
) {
4610 gfx::Size
tile_size(102, 102);
4611 gfx::Size
layer_bounds(1000, 1000);
4613 scoped_refptr
<FakePicturePileImpl
> pile
=
4614 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4615 SetupPendingTree(pile
);
4616 EXPECT_FALSE(pending_layer_
->GetRecycledTwinLayer());
4619 EXPECT_TRUE(active_layer_
->GetRecycledTwinLayer());
4620 EXPECT_EQ(old_pending_layer_
, active_layer_
->GetRecycledTwinLayer());
4622 SetupPendingTree(pile
);
4623 EXPECT_FALSE(pending_layer_
->GetRecycledTwinLayer());
4624 EXPECT_FALSE(active_layer_
->GetRecycledTwinLayer());
4627 EXPECT_TRUE(active_layer_
->GetRecycledTwinLayer());
4628 EXPECT_EQ(old_pending_layer_
, active_layer_
->GetRecycledTwinLayer());
4630 // Make an empty pending tree.
4631 host_impl_
.CreatePendingTree();
4632 host_impl_
.pending_tree()->DetachLayerTree();
4633 EXPECT_FALSE(active_layer_
->GetRecycledTwinLayer());
4636 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid
) {
4637 base::TimeTicks time_ticks
;
4638 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4639 host_impl_
.SetCurrentBeginFrameArgs(
4640 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4642 gfx::Size
tile_size(100, 100);
4643 gfx::Size
layer_bounds(200, 200);
4644 gfx::Rect
layer_rect(layer_bounds
);
4646 FakeContentLayerClient client
;
4647 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
4648 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4649 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&host_client
);
4650 host
->SetRootLayer(layer
);
4651 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4653 int frame_number
= 0;
4655 client
.set_fill_with_nonsolid_color(!test_for_solid
);
4657 Region
invalidation(layer_rect
);
4658 recording_source
->UpdateAndExpandInvalidation(
4659 &client
, &invalidation
, layer_bounds
, layer_rect
, frame_number
++,
4660 RecordingSource::RECORD_NORMALLY
);
4662 scoped_refptr
<RasterSource
> pending_raster_source
=
4663 recording_source
->CreateRasterSource(true);
4665 SetupPendingTreeWithFixedTileSize(pending_raster_source
, tile_size
, Region());
4668 if (test_for_solid
) {
4669 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4671 ASSERT_TRUE(active_layer_
->tilings());
4672 ASSERT_GT(active_layer_
->tilings()->num_tilings(), 0u);
4673 std::vector
<Tile
*> tiles
=
4674 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
4675 EXPECT_FALSE(tiles
.empty());
4676 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4679 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
4680 AppendQuadsData data
;
4681 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
4682 active_layer_
->AppendQuads(render_pass
.get(), &data
);
4683 active_layer_
->DidDraw(nullptr);
4685 DrawQuad::Material expected
= test_for_solid
4686 ? DrawQuad::Material::SOLID_COLOR
4687 : DrawQuad::Material::TILED_CONTENT
;
4688 EXPECT_EQ(expected
, render_pass
->quad_list
.front()->material
);
4691 TEST_F(PictureLayerImplTest
, DrawSolidQuads
) {
4692 TestQuadsForSolidColor(true);
4695 TEST_F(PictureLayerImplTest
, DrawNonSolidQuads
) {
4696 TestQuadsForSolidColor(false);
4699 TEST_F(PictureLayerImplTest
, NonSolidToSolidNoTilings
) {
4700 base::TimeTicks time_ticks
;
4701 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4702 host_impl_
.SetCurrentBeginFrameArgs(
4703 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4705 gfx::Size
tile_size(100, 100);
4706 gfx::Size
layer_bounds(200, 200);
4707 gfx::Rect
layer_rect(layer_bounds
);
4709 FakeContentLayerClient client
;
4710 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
4711 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4712 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&host_client
);
4713 host
->SetRootLayer(layer
);
4714 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4716 int frame_number
= 0;
4718 client
.set_fill_with_nonsolid_color(true);
4720 Region
invalidation1(layer_rect
);
4721 recording_source
->UpdateAndExpandInvalidation(
4722 &client
, &invalidation1
, layer_bounds
, layer_rect
, frame_number
++,
4723 RecordingSource::RECORD_NORMALLY
);
4725 scoped_refptr
<RasterSource
> raster_source1
=
4726 recording_source
->CreateRasterSource(true);
4728 SetupPendingTree(raster_source1
);
4730 bool update_lcd_text
= false;
4731 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
4733 // We've started with a solid layer that contains some tilings.
4734 ASSERT_TRUE(active_layer_
->tilings());
4735 EXPECT_NE(0u, active_layer_
->tilings()->num_tilings());
4737 client
.set_fill_with_nonsolid_color(false);
4739 Region
invalidation2(layer_rect
);
4740 recording_source
->UpdateAndExpandInvalidation(
4741 &client
, &invalidation2
, layer_bounds
, layer_rect
, frame_number
++,
4742 RecordingSource::RECORD_NORMALLY
);
4744 scoped_refptr
<RasterSource
> raster_source2
=
4745 recording_source
->CreateRasterSource(true);
4747 SetupPendingTree(raster_source2
);
4750 // We've switched to a solid color, so we should end up with no tilings.
4751 ASSERT_TRUE(active_layer_
->tilings());
4752 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4755 TEST_F(PictureLayerImplTest
, ChangeInViewportAllowsTilingUpdates
) {
4756 base::TimeTicks time_ticks
;
4757 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4758 host_impl_
.SetCurrentBeginFrameArgs(
4759 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4761 gfx::Size
tile_size(100, 100);
4762 gfx::Size
layer_bounds(400, 4000);
4764 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4765 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4766 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4767 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4769 SetupTrees(pending_pile
, active_pile
);
4771 Region invalidation
;
4772 gfx::Rect viewport
= gfx::Rect(0, 0, 100, 100);
4773 gfx::Transform transform
;
4775 host_impl_
.SetRequiresHighResToDraw();
4778 pending_layer_
->draw_properties().visible_content_rect
= viewport
;
4779 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4780 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
4782 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
4784 // Ensure we can't activate.
4785 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
4787 // Now in the same frame, move the viewport (this can happen during
4789 viewport
= gfx::Rect(0, 2000, 100, 100);
4792 pending_layer_
->draw_properties().visible_content_rect
= viewport
;
4793 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4794 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, 0.f
,
4796 pending_layer_
->HighResTiling()->UpdateAllRequiredStateForTesting();
4798 // Make sure all viewport tiles (viewport from the tiling) are ready to draw.
4799 std::vector
<Tile
*> tiles
;
4800 for (PictureLayerTiling::CoverageIterator
iter(
4801 pending_layer_
->HighResTiling(),
4803 pending_layer_
->HighResTiling()->GetCurrentVisibleRectForTesting());
4807 tiles
.push_back(*iter
);
4809 for (PictureLayerTiling::CoverageIterator
iter(
4810 active_layer_
->HighResTiling(), 1.f
,
4811 active_layer_
->HighResTiling()->GetCurrentVisibleRectForTesting());
4814 tiles
.push_back(*iter
);
4817 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4819 // Ensure we can activate.
4820 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
4823 TEST_F(PictureLayerImplTest
, CloneMissingRecordings
) {
4824 gfx::Size
tile_size(100, 100);
4825 gfx::Size
layer_bounds(400, 400);
4827 scoped_refptr
<FakePicturePileImpl
> filled_pile
=
4828 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4830 scoped_ptr
<FakePicturePile
> partial_recording
=
4831 FakePicturePile::CreateEmptyPile(tile_size
, layer_bounds
);
4832 for (int i
= 1; i
< partial_recording
->tiling().num_tiles_x(); ++i
) {
4833 for (int j
= 1; j
< partial_recording
->tiling().num_tiles_y(); ++j
)
4834 partial_recording
->AddRecordingAt(i
, j
);
4836 scoped_refptr
<FakePicturePileImpl
> partial_pile
=
4837 FakePicturePileImpl::CreateFromPile(partial_recording
.get(), nullptr);
4839 SetupPendingTreeWithFixedTileSize(filled_pile
, tile_size
, Region());
4842 PictureLayerTiling
* pending_tiling
= old_pending_layer_
->HighResTiling();
4843 PictureLayerTiling
* active_tiling
= active_layer_
->HighResTiling();
4845 // We should have all tiles on active, and none on pending.
4846 EXPECT_EQ(0u, pending_tiling
->AllTilesForTesting().size());
4847 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4849 // Now put a partially-recorded pile on the pending tree (and invalidate
4850 // everything, since the main thread PicturePile will invalidate dropped
4851 // recordings). This will cause us to be missing some tiles.
4852 SetupPendingTreeWithFixedTileSize(partial_pile
, tile_size
,
4853 Region(gfx::Rect(layer_bounds
)));
4854 EXPECT_EQ(3u * 3u, pending_tiling
->AllTilesForTesting().size());
4855 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
4856 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
4857 EXPECT_TRUE(pending_tiling
->TileAt(2, 2));
4859 // Active is not affected yet.
4860 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4862 // Activate the tree. The same tiles go missing on the active tree.
4864 EXPECT_EQ(3u * 3u, active_tiling
->AllTilesForTesting().size());
4865 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
4866 EXPECT_FALSE(active_tiling
->TileAt(1, 1));
4867 EXPECT_TRUE(active_tiling
->TileAt(2, 2));
4869 // Now put a full recording on the pending tree again. We'll get all our tiles
4871 SetupPendingTreeWithFixedTileSize(filled_pile
, tile_size
,
4872 Region(gfx::Rect(layer_bounds
)));
4873 EXPECT_EQ(5u * 5u, pending_tiling
->AllTilesForTesting().size());
4874 Tile
* tile00
= pending_tiling
->TileAt(0, 0);
4875 Tile
* tile11
= pending_tiling
->TileAt(1, 1);
4876 Tile
* tile22
= pending_tiling
->TileAt(2, 2);
4878 // Active is not affected yet.
4879 EXPECT_EQ(3u * 3u, active_tiling
->AllTilesForTesting().size());
4881 // Activate the tree. The tiles are moved to the active tree.
4883 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4884 EXPECT_EQ(tile00
, active_tiling
->TileAt(0, 0));
4885 EXPECT_EQ(tile11
, active_tiling
->TileAt(1, 1));
4886 EXPECT_EQ(tile22
, active_tiling
->TileAt(2, 2));
4889 TEST_F(PictureLayerImplTest
, ScrollPastLiveTilesRectAndBack
) {
4890 base::TimeTicks time_ticks
;
4891 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4892 host_impl_
.SetCurrentBeginFrameArgs(
4893 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4895 gfx::Size
tile_size(102, 102);
4896 gfx::Size
layer_bounds(100, 100);
4897 gfx::Size
viewport_size(100, 100);
4899 host_impl_
.SetViewportSize(viewport_size
);
4900 host_impl_
.SetDeviceScaleFactor(1.f
);
4902 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4903 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4904 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4905 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4907 SetupPendingTreeWithFixedTileSize(active_pile
, tile_size
, Region());
4910 EXPECT_TRUE(active_layer_
->HighResTiling()->has_tiles());
4912 host_impl_
.SetExternalDrawConstraints(
4913 gfx::Transform(), // transform
4914 gfx::Rect(), // clip
4915 gfx::Rect(), // viewport
4916 gfx::Rect(0, 1000, 100, 100), // viewport_rect_for_tile_priority
4917 gfx::Transform(), // transform_for_tile_priority
4920 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, gfx::Rect());
4922 EXPECT_FALSE(pending_layer_
->HighResTiling()->has_tiles());
4923 EXPECT_TRUE(pending_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4925 EXPECT_FALSE(active_layer_
->HighResTiling()->has_tiles());
4926 EXPECT_TRUE(active_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4928 host_impl_
.SetExternalDrawConstraints(
4929 gfx::Transform(), // transform
4930 gfx::Rect(), // clip
4931 gfx::Rect(), // viewport
4932 gfx::Rect(0, 110, 100, 100), // viewport_rect_for_tile_priority
4933 gfx::Transform(), // transform_for_tile_priority
4936 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, gfx::Rect());
4938 EXPECT_FALSE(pending_layer_
->HighResTiling()->has_tiles());
4939 EXPECT_FALSE(pending_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4941 EXPECT_TRUE(active_layer_
->HighResTiling()->has_tiles());
4942 EXPECT_FALSE(active_layer_
->HighResTiling()->live_tiles_rect().IsEmpty());
4945 TEST_F(PictureLayerImplTest
, ScrollPropagatesToPending
) {
4946 base::TimeTicks time_ticks
;
4947 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4948 host_impl_
.SetCurrentBeginFrameArgs(
4949 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4951 gfx::Size
tile_size(102, 102);
4952 gfx::Size
layer_bounds(1000, 1000);
4953 gfx::Size
viewport_size(100, 100);
4955 host_impl_
.SetViewportSize(viewport_size
);
4956 host_impl_
.SetDeviceScaleFactor(1.f
);
4958 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4959 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4960 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4961 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4963 SetupTrees(pending_pile
, active_pile
);
4965 active_layer_
->SetCurrentScrollOffset(gfx::ScrollOffset(0.0, 50.0));
4966 host_impl_
.active_tree()->UpdateDrawProperties(false);
4967 EXPECT_EQ("0,50 100x100", active_layer_
->HighResTiling()
4968 ->GetCurrentVisibleRectForTesting()
4971 EXPECT_EQ("0,0 100x100", pending_layer_
->HighResTiling()
4972 ->GetCurrentVisibleRectForTesting()
4974 host_impl_
.pending_tree()->UpdateDrawProperties(false);
4975 EXPECT_EQ("0,50 100x100", pending_layer_
->HighResTiling()
4976 ->GetCurrentVisibleRectForTesting()
4980 TEST_F(PictureLayerImplTest
, UpdateLCDInvalidatesPendingTree
) {
4981 base::TimeTicks time_ticks
;
4982 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4983 host_impl_
.SetCurrentBeginFrameArgs(
4984 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4986 gfx::Size
tile_size(102, 102);
4987 gfx::Size
layer_bounds(100, 100);
4988 gfx::Size
viewport_size(100, 100);
4990 host_impl_
.SetViewportSize(viewport_size
);
4991 host_impl_
.SetDeviceScaleFactor(1.f
);
4993 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4994 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4995 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4997 EXPECT_TRUE(pending_layer_
->RasterSourceUsesLCDText());
4998 EXPECT_TRUE(pending_layer_
->HighResTiling()->has_tiles());
4999 std::vector
<Tile
*> tiles
=
5000 pending_layer_
->HighResTiling()->AllTilesForTesting();
5001 auto prioritized_tiles
= pending_layer_
->HighResTiling()
5002 ->UpdateAndGetAllPrioritizedTilesForTesting();
5004 for (Tile
* tile
: tiles
)
5005 EXPECT_EQ(pending_layer_
->raster_source(),
5006 prioritized_tiles
[tile
].raster_source());
5008 pending_layer_
->draw_properties().can_use_lcd_text
= false;
5009 pending_layer_
->UpdateCanUseLCDTextAfterCommit();
5011 EXPECT_FALSE(pending_layer_
->RasterSourceUsesLCDText());
5012 EXPECT_NE(pending_pile
.get(), pending_layer_
->raster_source());
5013 EXPECT_TRUE(pending_layer_
->HighResTiling()->has_tiles());
5014 tiles
= pending_layer_
->HighResTiling()->AllTilesForTesting();
5015 prioritized_tiles
= pending_layer_
->HighResTiling()
5016 ->UpdateAndGetAllPrioritizedTilesForTesting();
5017 for (Tile
* tile
: tiles
)
5018 EXPECT_EQ(pending_layer_
->raster_source(),
5019 prioritized_tiles
[tile
].raster_source());
5022 class TileSizeSettings
: public GpuRasterizationEnabledSettings
{
5024 TileSizeSettings() {
5025 default_tile_size
= gfx::Size(100, 100);
5026 max_untiled_layer_size
= gfx::Size(200, 200);
5030 class TileSizeTest
: public PictureLayerImplTest
{
5032 TileSizeTest() : PictureLayerImplTest(TileSizeSettings()) {}
5035 TEST_F(TileSizeTest
, TileSizes
) {
5036 host_impl_
.CreatePendingTree();
5038 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
5039 scoped_ptr
<FakePictureLayerImpl
> layer
=
5040 FakePictureLayerImpl::Create(pending_tree
, id_
);
5042 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
5045 host_impl_
.set_content_is_suitable_for_gpu_rasterization(true);
5046 host_impl_
.set_has_gpu_rasterization_trigger(false);
5047 host_impl_
.UpdateGpuRasterizationStatus();
5048 EXPECT_EQ(host_impl_
.gpu_rasterization_status(),
5049 GpuRasterizationStatus::OFF_VIEWPORT
);
5051 // Default tile-size for large layers.
5052 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
5053 EXPECT_EQ(result
.width(), 100);
5054 EXPECT_EQ(result
.height(), 100);
5055 // Don't tile and round-up, when under max_untiled_layer_size.
5056 result
= layer
->CalculateTileSize(gfx::Size(42, 42));
5057 EXPECT_EQ(result
.width(), 64);
5058 EXPECT_EQ(result
.height(), 64);
5059 result
= layer
->CalculateTileSize(gfx::Size(191, 191));
5060 EXPECT_EQ(result
.width(), 192);
5061 EXPECT_EQ(result
.height(), 192);
5062 result
= layer
->CalculateTileSize(gfx::Size(199, 199));
5063 EXPECT_EQ(result
.width(), 200);
5064 EXPECT_EQ(result
.height(), 200);
5066 // Gpu-rasterization uses 25% viewport-height tiles.
5067 // The +2's below are for border texels.
5068 host_impl_
.set_has_gpu_rasterization_trigger(true);
5069 host_impl_
.UpdateGpuRasterizationStatus();
5070 EXPECT_EQ(host_impl_
.gpu_rasterization_status(), GpuRasterizationStatus::ON
);
5071 host_impl_
.SetViewportSize(gfx::Size(2000, 2000));
5073 layer
->set_gpu_raster_max_texture_size(host_impl_
.device_viewport_size());
5074 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
5075 EXPECT_EQ(result
.width(), 2000 + 2 * PictureLayerTiling::kBorderTexels
);
5076 EXPECT_EQ(result
.height(), 500 + 2);
5078 // Clamp and round-up, when smaller than viewport.
5079 // Tile-height doubles to 50% when width shrinks to <= 50%.
5080 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
5081 layer
->set_gpu_raster_max_texture_size(host_impl_
.device_viewport_size());
5082 result
= layer
->CalculateTileSize(gfx::Size(447, 10000));
5083 EXPECT_EQ(result
.width(), 448);
5084 EXPECT_EQ(result
.height(), 500 + 2);
5086 // Largest layer is 50% of viewport width (rounded up), and
5087 // 50% of viewport in height.
5088 result
= layer
->CalculateTileSize(gfx::Size(447, 400));
5089 EXPECT_EQ(result
.width(), 448);
5090 EXPECT_EQ(result
.height(), 448);
5091 result
= layer
->CalculateTileSize(gfx::Size(500, 499));
5092 EXPECT_EQ(result
.width(), 512);
5093 EXPECT_EQ(result
.height(), 500 + 2);