1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/picture_layer_impl.h"
12 #include "cc/base/math_util.h"
13 #include "cc/layers/append_quads_data.h"
14 #include "cc/layers/picture_layer.h"
15 #include "cc/quads/draw_quad.h"
16 #include "cc/quads/tile_draw_quad.h"
17 #include "cc/test/begin_frame_args_test.h"
18 #include "cc/test/fake_content_layer_client.h"
19 #include "cc/test/fake_impl_proxy.h"
20 #include "cc/test/fake_layer_tree_host_impl.h"
21 #include "cc/test/fake_output_surface.h"
22 #include "cc/test/fake_picture_layer_impl.h"
23 #include "cc/test/fake_picture_pile_impl.h"
24 #include "cc/test/geometry_test_utils.h"
25 #include "cc/test/impl_side_painting_settings.h"
26 #include "cc/test/layer_test_common.h"
27 #include "cc/test/test_shared_bitmap_manager.h"
28 #include "cc/test/test_web_graphics_context_3d.h"
29 #include "cc/trees/layer_tree_impl.h"
30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/gfx/geometry/rect_conversions.h"
32 #include "ui/gfx/geometry/size_conversions.h"
37 class MockCanvas
: public SkCanvas
{
39 explicit MockCanvas(int w
, int h
) : SkCanvas(w
, h
) {}
41 void drawRect(const SkRect
& rect
, const SkPaint
& paint
) override
{
42 // Capture calls before SkCanvas quickReject() kicks in.
43 rects_
.push_back(rect
);
46 std::vector
<SkRect
> rects_
;
49 class NoLowResTilingsSettings
: public ImplSidePaintingSettings
{};
51 class LowResTilingsSettings
: public ImplSidePaintingSettings
{
53 LowResTilingsSettings() { create_low_res_tiling
= true; }
56 class PictureLayerImplTest
: public testing::Test
{
58 PictureLayerImplTest()
59 : proxy_(base::MessageLoopProxy::current()),
60 host_impl_(LowResTilingsSettings(), &proxy_
, &shared_bitmap_manager_
),
62 pending_layer_(nullptr),
63 old_pending_layer_(nullptr),
64 active_layer_(nullptr) {}
66 explicit PictureLayerImplTest(const LayerTreeSettings
& settings
)
67 : proxy_(base::MessageLoopProxy::current()),
68 host_impl_(settings
, &proxy_
, &shared_bitmap_manager_
),
71 virtual ~PictureLayerImplTest() {
74 void SetUp() override
{ InitializeRenderer(); }
76 virtual void InitializeRenderer() {
77 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d());
80 void SetupDefaultTrees(const gfx::Size
& layer_bounds
) {
81 gfx::Size
tile_size(100, 100);
83 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
84 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
85 scoped_refptr
<FakePicturePileImpl
> active_pile
=
86 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
88 SetupTrees(pending_pile
, active_pile
);
92 host_impl_
.ActivateSyncTree();
93 CHECK(!host_impl_
.pending_tree());
94 CHECK(host_impl_
.recycle_tree());
95 old_pending_layer_
= pending_layer_
;
96 pending_layer_
= nullptr;
97 active_layer_
= static_cast<FakePictureLayerImpl
*>(
98 host_impl_
.active_tree()->LayerById(id_
));
101 void SetupDefaultTreesWithFixedTileSize(const gfx::Size
& layer_bounds
,
102 const gfx::Size
& tile_size
) {
103 SetupDefaultTrees(layer_bounds
);
104 pending_layer_
->set_fixed_tile_size(tile_size
);
105 active_layer_
->set_fixed_tile_size(tile_size
);
109 scoped_refptr
<PicturePileImpl
> pending_pile
,
110 scoped_refptr
<PicturePileImpl
> active_pile
) {
111 SetupPendingTree(active_pile
);
113 SetupPendingTree(pending_pile
);
116 void CreateHighLowResAndSetAllTilesVisible() {
117 // Active layer must get updated first so pending layer can share from it.
118 active_layer_
->CreateDefaultTilingsAndTiles();
119 active_layer_
->SetAllTilesVisible();
120 pending_layer_
->CreateDefaultTilingsAndTiles();
121 pending_layer_
->SetAllTilesVisible();
124 void AddDefaultTilingsWithInvalidation(const Region
& invalidation
) {
125 active_layer_
->AddTiling(2.3f
);
126 active_layer_
->AddTiling(1.0f
);
127 active_layer_
->AddTiling(0.5f
);
128 for (size_t i
= 0; i
< active_layer_
->tilings()->num_tilings(); ++i
)
129 active_layer_
->tilings()->tiling_at(i
)->CreateAllTilesForTesting();
130 pending_layer_
->set_invalidation(invalidation
);
131 for (size_t i
= 0; i
< pending_layer_
->tilings()->num_tilings(); ++i
)
132 pending_layer_
->tilings()->tiling_at(i
)->CreateAllTilesForTesting();
135 void SetupPendingTree(scoped_refptr
<RasterSource
> raster_source
) {
136 host_impl_
.CreatePendingTree();
137 host_impl_
.pending_tree()->SetPageScaleFactorAndLimits(1.f
, 0.25f
, 100.f
);
138 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
140 // Steal from the recycled tree.
141 scoped_ptr
<LayerImpl
> old_pending_root
= pending_tree
->DetachLayerTree();
142 DCHECK_IMPLIES(old_pending_root
, old_pending_root
->id() == id_
);
144 scoped_ptr
<FakePictureLayerImpl
> pending_layer
;
145 if (old_pending_root
) {
147 static_cast<FakePictureLayerImpl
*>(old_pending_root
.release()));
148 pending_layer
->SetRasterSource(raster_source
);
150 pending_layer
= FakePictureLayerImpl::CreateWithRasterSource(
151 pending_tree
, id_
, raster_source
);
152 pending_layer
->SetDrawsContent(true);
154 // The bounds() just mirror the pile size.
155 pending_layer
->SetBounds(pending_layer
->raster_source()->GetSize());
156 pending_tree
->SetRootLayer(pending_layer
.Pass());
158 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
159 host_impl_
.pending_tree()->LayerById(id_
));
160 pending_layer_
->DoPostCommitInitializationIfNeeded();
163 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl
* layer
,
164 float ideal_contents_scale
,
165 float device_scale_factor
,
166 float page_scale_factor
,
167 float maximum_animation_contents_scale
,
168 bool animating_transform_to_screen
) {
169 layer
->draw_properties().ideal_contents_scale
= ideal_contents_scale
;
170 layer
->draw_properties().device_scale_factor
= device_scale_factor
;
171 layer
->draw_properties().page_scale_factor
= page_scale_factor
;
172 layer
->draw_properties().maximum_animation_contents_scale
=
173 maximum_animation_contents_scale
;
174 layer
->draw_properties().screen_space_transform_is_animating
=
175 animating_transform_to_screen
;
176 bool resourceless_software_draw
= false;
177 layer
->UpdateTiles(Occlusion(), resourceless_software_draw
);
179 static void VerifyAllTilesExistAndHavePile(
180 const PictureLayerTiling
* tiling
,
181 PicturePileImpl
* pile
) {
182 for (PictureLayerTiling::CoverageIterator
iter(
184 tiling
->contents_scale(),
185 gfx::Rect(tiling
->tiling_size()));
189 EXPECT_EQ(pile
, iter
->raster_source());
193 void SetContentsScaleOnBothLayers(float contents_scale
,
194 float device_scale_factor
,
195 float page_scale_factor
,
196 float maximum_animation_contents_scale
,
197 bool animating_transform
) {
198 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
202 maximum_animation_contents_scale
,
203 animating_transform
);
205 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
209 maximum_animation_contents_scale
,
210 animating_transform
);
213 void ResetTilingsAndRasterScales() {
214 pending_layer_
->ReleaseResources();
215 active_layer_
->ReleaseResources();
218 void AssertAllTilesRequired(PictureLayerTiling
* tiling
) {
219 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
220 for (size_t i
= 0; i
< tiles
.size(); ++i
)
221 EXPECT_TRUE(tiles
[i
]->required_for_activation()) << "i: " << i
;
222 EXPECT_GT(tiles
.size(), 0u);
225 void AssertNoTilesRequired(PictureLayerTiling
* tiling
) {
226 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
227 for (size_t i
= 0; i
< tiles
.size(); ++i
)
228 EXPECT_FALSE(tiles
[i
]->required_for_activation()) << "i: " << i
;
229 EXPECT_GT(tiles
.size(), 0u);
233 void TestTileGridAlignmentCommon() {
234 // Layer to span 4 raster tiles in x and in y
235 ImplSidePaintingSettings settings
;
236 gfx::Size
layer_size(
237 settings
.default_tile_size
.width() * 7 / 2,
238 settings
.default_tile_size
.height() * 7 / 2);
240 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
241 FakePicturePileImpl::CreateFilledPile(layer_size
, layer_size
);
242 scoped_refptr
<FakePicturePileImpl
> active_pile
=
243 FakePicturePileImpl::CreateFilledPile(layer_size
, layer_size
);
245 SetupTrees(pending_pile
, active_pile
);
247 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
249 // Add 1x1 rects at the centers of each tile, then re-record pile contents
250 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
251 std::vector
<Tile
*> tiles
=
252 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
253 EXPECT_EQ(16u, tiles
.size());
254 std::vector
<SkRect
> rects
;
255 std::vector
<Tile
*>::const_iterator tile_iter
;
256 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
257 gfx::Point tile_center
= (*tile_iter
)->content_rect().CenterPoint();
258 gfx::Rect
rect(tile_center
.x(), tile_center
.y(), 1, 1);
259 active_pile
->add_draw_rect(rect
);
260 rects
.push_back(SkRect::MakeXYWH(rect
.x(), rect
.y(), 1, 1));
262 // Force re-record with newly injected content
263 active_pile
->RemoveRecordingAt(0, 0);
264 active_pile
->AddRecordingAt(0, 0);
266 std::vector
<SkRect
>::const_iterator rect_iter
= rects
.begin();
267 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
268 MockCanvas
mock_canvas(1000, 1000);
269 active_pile
->PlaybackToSharedCanvas(&mock_canvas
,
270 (*tile_iter
)->content_rect(), 1.0f
);
272 // This test verifies that when drawing the contents of a specific tile
273 // at content scale 1.0, the playback canvas never receives content from
274 // neighboring tiles which indicates that the tile grid embedded in
275 // SkPicture is perfectly aligned with the compositor's tiles.
276 EXPECT_EQ(1u, mock_canvas
.rects_
.size());
277 EXPECT_EQ(*rect_iter
, mock_canvas
.rects_
[0]);
282 void TestQuadsForSolidColor(bool test_for_solid
);
284 FakeImplProxy proxy_
;
285 TestSharedBitmapManager shared_bitmap_manager_
;
286 FakeLayerTreeHostImpl host_impl_
;
288 FakePictureLayerImpl
* pending_layer_
;
289 FakePictureLayerImpl
* old_pending_layer_
;
290 FakePictureLayerImpl
* active_layer_
;
293 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest
);
296 TEST_F(PictureLayerImplTest
, TileGridAlignment
) {
297 host_impl_
.SetDeviceScaleFactor(1.f
);
298 TestTileGridAlignmentCommon();
301 TEST_F(PictureLayerImplTest
, TileGridAlignmentHiDPI
) {
302 host_impl_
.SetDeviceScaleFactor(2.f
);
303 TestTileGridAlignmentCommon();
306 TEST_F(PictureLayerImplTest
, CloneNoInvalidation
) {
307 gfx::Size
tile_size(100, 100);
308 gfx::Size
layer_bounds(400, 400);
310 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
311 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
312 scoped_refptr
<FakePicturePileImpl
> active_pile
=
313 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
315 SetupTrees(pending_pile
, active_pile
);
318 AddDefaultTilingsWithInvalidation(invalidation
);
320 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
321 active_layer_
->tilings()->num_tilings());
323 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
324 EXPECT_GT(tilings
->num_tilings(), 0u);
325 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
326 VerifyAllTilesExistAndHavePile(tilings
->tiling_at(i
), active_pile
.get());
329 TEST_F(PictureLayerImplTest
, ExternalViewportRectForPrioritizingTiles
) {
330 base::TimeTicks time_ticks
;
331 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
332 host_impl_
.SetCurrentBeginFrameArgs(
333 CreateBeginFrameArgsForTesting(time_ticks
));
334 gfx::Size
tile_size(100, 100);
335 gfx::Size
layer_bounds(400, 400);
337 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
338 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
339 scoped_refptr
<FakePicturePileImpl
> active_pile
=
340 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
342 SetupTrees(pending_pile
, active_pile
);
345 AddDefaultTilingsWithInvalidation(invalidation
);
346 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
348 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
349 host_impl_
.SetCurrentBeginFrameArgs(
350 CreateBeginFrameArgsForTesting(time_ticks
));
352 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the
353 // identify transform for tile priority.
354 bool resourceless_software_draw
= false;
355 gfx::Rect viewport
= gfx::Rect(layer_bounds
),
356 viewport_rect_for_tile_priority
= gfx::Rect(0, 0, 100, 100);
357 gfx::Transform transform
, transform_for_tile_priority
;
359 host_impl_
.SetExternalDrawConstraints(transform
,
362 viewport_rect_for_tile_priority
,
363 transform_for_tile_priority
,
364 resourceless_software_draw
);
365 host_impl_
.active_tree()->UpdateDrawProperties();
367 gfx::Rect viewport_rect_for_tile_priority_in_view_space
=
368 viewport_rect_for_tile_priority
;
370 // Verify the viewport rect for tile priority is used in picture layer tiling.
371 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
372 active_layer_
->GetViewportForTilePriorityInContentSpace());
373 PictureLayerTilingSet
* tilings
= active_layer_
->tilings();
374 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
375 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
377 tiling
->GetCurrentVisibleRectForTesting(),
378 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
379 tiling
->contents_scale()));
382 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in
383 // screen space and the transform for tile priority is translated and
384 // rotated. The actual viewport for tile priority used by PictureLayerImpl
385 // should be (200, 200, 100, 100) applied with the said transform.
386 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
387 host_impl_
.SetCurrentBeginFrameArgs(
388 CreateBeginFrameArgsForTesting(time_ticks
));
390 viewport_rect_for_tile_priority
= gfx::Rect(200, 200, 100, 100);
391 transform_for_tile_priority
.Translate(100, 100);
392 transform_for_tile_priority
.Rotate(45);
393 host_impl_
.SetExternalDrawConstraints(transform
,
396 viewport_rect_for_tile_priority
,
397 transform_for_tile_priority
,
398 resourceless_software_draw
);
399 host_impl_
.active_tree()->UpdateDrawProperties();
401 gfx::Transform
screen_to_view(gfx::Transform::kSkipInitialization
);
402 bool success
= transform_for_tile_priority
.GetInverse(&screen_to_view
);
403 EXPECT_TRUE(success
);
405 // Note that we don't clip this to the layer bounds, since it is expected that
406 // the rect will sometimes be outside of the layer bounds. If we clip to
407 // bounds, then tile priorities will end up being incorrect in cases of fully
409 viewport_rect_for_tile_priority_in_view_space
=
410 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
411 screen_to_view
, viewport_rect_for_tile_priority
));
413 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
414 active_layer_
->GetViewportForTilePriorityInContentSpace());
415 tilings
= active_layer_
->tilings();
416 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
417 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
419 tiling
->GetCurrentVisibleRectForTesting(),
420 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
421 tiling
->contents_scale()));
425 TEST_F(PictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
426 base::TimeTicks time_ticks
;
427 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
428 host_impl_
.SetCurrentBeginFrameArgs(
429 CreateBeginFrameArgsForTesting(time_ticks
));
431 gfx::Size
tile_size(100, 100);
432 gfx::Size
layer_bounds(400, 400);
434 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
435 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
436 scoped_refptr
<FakePicturePileImpl
> active_pile
=
437 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
439 SetupTrees(pending_pile
, active_pile
);
442 AddDefaultTilingsWithInvalidation(invalidation
);
443 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
445 // UpdateTiles with valid viewport. Should update tile viewport.
446 // Note viewport is considered invalid if and only if in resourceless
448 bool resourceless_software_draw
= false;
449 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
450 gfx::Transform transform
;
451 host_impl_
.SetExternalDrawConstraints(transform
,
456 resourceless_software_draw
);
457 active_layer_
->draw_properties().visible_content_rect
= viewport
;
458 active_layer_
->draw_properties().screen_space_transform
= transform
;
459 active_layer_
->UpdateTiles(Occlusion(), resourceless_software_draw
);
461 gfx::Rect visible_rect_for_tile_priority
=
462 active_layer_
->visible_rect_for_tile_priority();
463 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
464 gfx::Transform screen_space_transform_for_tile_priority
=
465 active_layer_
->screen_space_transform();
467 // Expand viewport and set it as invalid for prioritizing tiles.
468 // Should update viewport and transform, but not update visible rect.
469 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
470 host_impl_
.SetCurrentBeginFrameArgs(
471 CreateBeginFrameArgsForTesting(time_ticks
));
472 resourceless_software_draw
= true;
473 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
474 transform
.Translate(1.f
, 1.f
);
475 active_layer_
->draw_properties().visible_content_rect
= viewport
;
476 active_layer_
->draw_properties().screen_space_transform
= transform
;
477 host_impl_
.SetExternalDrawConstraints(transform
,
482 resourceless_software_draw
);
483 active_layer_
->UpdateTiles(Occlusion(), resourceless_software_draw
);
485 // Transform for tile priority is updated.
486 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
487 active_layer_
->screen_space_transform());
488 // Visible rect for tile priority retains old value.
489 EXPECT_EQ(visible_rect_for_tile_priority
,
490 active_layer_
->visible_rect_for_tile_priority());
492 // Keep expanded viewport but mark it valid. Should update tile viewport.
493 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
494 host_impl_
.SetCurrentBeginFrameArgs(
495 CreateBeginFrameArgsForTesting(time_ticks
));
496 resourceless_software_draw
= false;
497 host_impl_
.SetExternalDrawConstraints(transform
,
502 resourceless_software_draw
);
503 active_layer_
->UpdateTiles(Occlusion(), resourceless_software_draw
);
505 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
506 active_layer_
->screen_space_transform());
507 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
510 TEST_F(PictureLayerImplTest
, ClonePartialInvalidation
) {
511 gfx::Size
tile_size(100, 100);
512 gfx::Size
layer_bounds(400, 400);
513 gfx::Rect
layer_invalidation(150, 200, 30, 180);
515 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
516 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
517 scoped_refptr
<FakePicturePileImpl
> active_pile
=
518 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
520 SetupTrees(pending_pile
, active_pile
);
522 Region
invalidation(layer_invalidation
);
523 AddDefaultTilingsWithInvalidation(invalidation
);
525 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
526 EXPECT_GT(tilings
->num_tilings(), 0u);
527 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
528 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
529 gfx::Rect content_invalidation
= gfx::ScaleToEnclosingRect(
531 tiling
->contents_scale());
532 for (PictureLayerTiling::CoverageIterator
iter(
534 tiling
->contents_scale(),
535 gfx::Rect(tiling
->tiling_size()));
539 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
540 if (iter
.geometry_rect().Intersects(content_invalidation
))
541 EXPECT_EQ(pending_pile
.get(), iter
->raster_source());
543 EXPECT_EQ(active_pile
.get(), iter
->raster_source());
548 TEST_F(PictureLayerImplTest
, CloneFullInvalidation
) {
549 gfx::Size
tile_size(90, 80);
550 gfx::Size
layer_bounds(300, 500);
552 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
553 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
554 scoped_refptr
<FakePicturePileImpl
> active_pile
=
555 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
557 SetupTrees(pending_pile
, active_pile
);
559 Region
invalidation((gfx::Rect(layer_bounds
)));
560 AddDefaultTilingsWithInvalidation(invalidation
);
562 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
563 active_layer_
->tilings()->num_tilings());
565 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
566 EXPECT_GT(tilings
->num_tilings(), 0u);
567 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
568 VerifyAllTilesExistAndHavePile(tilings
->tiling_at(i
), pending_pile
.get());
571 TEST_F(PictureLayerImplTest
, NoInvalidationBoundsChange
) {
572 gfx::Size
tile_size(90, 80);
573 gfx::Size
active_layer_bounds(300, 500);
574 gfx::Size
pending_layer_bounds(400, 800);
576 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
577 FakePicturePileImpl::CreateFilledPile(tile_size
,
578 pending_layer_bounds
);
579 scoped_refptr
<FakePicturePileImpl
> active_pile
=
580 FakePicturePileImpl::CreateFilledPile(tile_size
, active_layer_bounds
);
582 SetupTrees(pending_pile
, active_pile
);
583 pending_layer_
->set_fixed_tile_size(gfx::Size(100, 100));
586 AddDefaultTilingsWithInvalidation(invalidation
);
588 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
589 EXPECT_GT(tilings
->num_tilings(), 0u);
590 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
591 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
592 gfx::Rect active_content_bounds
= gfx::ScaleToEnclosingRect(
593 gfx::Rect(active_layer_bounds
),
594 tiling
->contents_scale());
595 for (PictureLayerTiling::CoverageIterator
iter(
597 tiling
->contents_scale(),
598 gfx::Rect(tiling
->tiling_size()));
602 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
603 std::vector
<Tile
*> active_tiles
=
604 active_layer_
->tilings()->tiling_at(i
)->AllTilesForTesting();
605 std::vector
<Tile
*> pending_tiles
= tiling
->AllTilesForTesting();
606 if (iter
.geometry_rect().right() >= active_content_bounds
.width() ||
607 iter
.geometry_rect().bottom() >= active_content_bounds
.height() ||
608 active_tiles
[0]->content_rect().size() !=
609 pending_tiles
[0]->content_rect().size()) {
610 EXPECT_EQ(pending_pile
.get(), iter
->raster_source());
612 EXPECT_EQ(active_pile
.get(), iter
->raster_source());
618 TEST_F(PictureLayerImplTest
, AddTilesFromNewRecording
) {
619 gfx::Size
tile_size(400, 400);
620 gfx::Size
layer_bounds(1300, 1900);
622 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
623 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
624 scoped_refptr
<FakePicturePileImpl
> active_pile
=
625 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
627 // Fill in some of active pile, but more of pending pile.
629 for (int x
= 0; x
< active_pile
->tiling().num_tiles_x(); ++x
) {
630 for (int y
= 0; y
< active_pile
->tiling().num_tiles_y(); ++y
) {
632 pending_pile
->AddRecordingAt(x
, y
);
633 active_pile
->AddRecordingAt(x
, y
);
637 pending_pile
->AddRecordingAt(x
, y
);
642 SetupTrees(pending_pile
, active_pile
);
644 AddDefaultTilingsWithInvalidation(invalidation
);
646 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
647 EXPECT_GT(tilings
->num_tilings(), 0u);
648 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
649 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
651 for (PictureLayerTiling::CoverageIterator
iter(
653 tiling
->contents_scale(),
654 gfx::Rect(tiling
->tiling_size()));
657 EXPECT_FALSE(iter
.full_tile_geometry_rect().IsEmpty());
658 // Ensure there is a recording for this tile.
659 bool in_pending
= pending_pile
->CoversRect(iter
.full_tile_geometry_rect(),
660 tiling
->contents_scale());
661 bool in_active
= active_pile
->CoversRect(iter
.full_tile_geometry_rect(),
662 tiling
->contents_scale());
664 if (in_pending
&& !in_active
)
665 EXPECT_EQ(pending_pile
.get(), iter
->raster_source());
667 EXPECT_EQ(active_pile
.get(), iter
->raster_source());
674 TEST_F(PictureLayerImplTest
, ManageTilingsWithNoRecording
) {
675 gfx::Size
tile_size(400, 400);
676 gfx::Size
layer_bounds(1300, 1900);
678 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
679 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
680 scoped_refptr
<FakePicturePileImpl
> active_pile
=
681 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
683 SetupTrees(pending_pile
, active_pile
);
685 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
687 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
690 TEST_F(PictureLayerImplTest
, ManageTilingsCreatesTilings
) {
691 gfx::Size
tile_size(400, 400);
692 gfx::Size
layer_bounds(1300, 1900);
694 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
695 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
696 scoped_refptr
<FakePicturePileImpl
> active_pile
=
697 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
699 SetupTrees(pending_pile
, active_pile
);
700 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
702 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
703 EXPECT_LT(low_res_factor
, 1.f
);
705 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
706 6.f
, // ideal contents scale
709 1.f
, // maximum animation scale
711 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
713 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
714 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
715 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
717 // If we change the page scale factor, then we should get new tilings.
718 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
719 6.6f
, // ideal contents scale
722 1.f
, // maximum animation scale
724 ASSERT_EQ(4u, pending_layer_
->tilings()->num_tilings());
725 EXPECT_FLOAT_EQ(6.6f
,
726 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
727 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
728 pending_layer_
->tilings()->tiling_at(2)->contents_scale());
730 // If we change the device scale factor, then we should get new tilings.
731 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
732 7.26f
, // ideal contents scale
733 3.3f
, // device scale
735 1.f
, // maximum animation scale
737 ASSERT_EQ(6u, pending_layer_
->tilings()->num_tilings());
738 EXPECT_FLOAT_EQ(7.26f
,
739 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
740 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
741 pending_layer_
->tilings()->tiling_at(3)->contents_scale());
743 // If we change the device scale factor, but end up at the same total scale
744 // factor somehow, then we don't get new tilings.
745 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
746 7.26f
, // ideal contents scale
747 2.2f
, // device scale
749 1.f
, // maximum animation scale
751 ASSERT_EQ(6u, pending_layer_
->tilings()->num_tilings());
752 EXPECT_FLOAT_EQ(7.26f
,
753 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
754 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
755 pending_layer_
->tilings()->tiling_at(3)->contents_scale());
758 TEST_F(PictureLayerImplTest
, CreateTilingsEvenIfTwinHasNone
) {
759 // This test makes sure that if a layer can have tilings, then a commit makes
760 // it not able to have tilings (empty size), and then a future commit that
761 // makes it valid again should be able to create tilings.
762 gfx::Size
tile_size(400, 400);
763 gfx::Size
layer_bounds(1300, 1900);
765 scoped_refptr
<FakePicturePileImpl
> empty_pile
=
766 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
767 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
768 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
770 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
771 EXPECT_LT(low_res_factor
, 1.f
);
773 float high_res_scale
= 1.3f
;
774 float low_res_scale
= high_res_scale
* low_res_factor
;
775 float device_scale
= 1.7f
;
776 float page_scale
= 3.2f
;
777 float maximum_animation_scale
= 1.f
;
779 SetupPendingTree(valid_pile
);
780 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
784 maximum_animation_scale
,
786 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
787 EXPECT_FLOAT_EQ(high_res_scale
,
788 pending_layer_
->HighResTiling()->contents_scale());
789 EXPECT_FLOAT_EQ(low_res_scale
,
790 pending_layer_
->LowResTiling()->contents_scale());
793 SetupPendingTree(empty_pile
);
794 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
795 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
799 maximum_animation_scale
,
801 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
802 ASSERT_EQ(0u, pending_layer_
->tilings()->num_tilings());
805 EXPECT_FALSE(active_layer_
->CanHaveTilings());
806 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
810 maximum_animation_scale
,
812 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
814 SetupPendingTree(valid_pile
);
815 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
819 maximum_animation_scale
,
821 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
822 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
823 EXPECT_FLOAT_EQ(high_res_scale
,
824 pending_layer_
->HighResTiling()->contents_scale());
825 EXPECT_FLOAT_EQ(low_res_scale
,
826 pending_layer_
->LowResTiling()->contents_scale());
829 TEST_F(PictureLayerImplTest
, ZoomOutCrash
) {
830 gfx::Size
tile_size(400, 400);
831 gfx::Size
layer_bounds(1300, 1900);
833 // Set up the high and low res tilings before pinch zoom.
834 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
835 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
836 scoped_refptr
<FakePicturePileImpl
> active_pile
=
837 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
839 SetupTrees(pending_pile
, active_pile
);
840 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
841 SetContentsScaleOnBothLayers(32.0f
, 1.0f
, 32.0f
, 1.0f
, false);
842 host_impl_
.PinchGestureBegin();
843 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, false);
844 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, false);
845 EXPECT_EQ(active_layer_
->tilings()->NumHighResTilings(), 1);
848 TEST_F(PictureLayerImplTest
, PinchGestureTilings
) {
849 gfx::Size
tile_size(400, 400);
850 gfx::Size
layer_bounds(1300, 1900);
852 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
853 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
854 scoped_refptr
<FakePicturePileImpl
> active_pile
=
855 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
857 // Set up the high and low res tilings before pinch zoom.
858 SetupTrees(pending_pile
, active_pile
);
859 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
860 SetContentsScaleOnBothLayers(2.0f
, 1.0f
, 1.0f
, 1.0f
, false);
861 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
862 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
863 EXPECT_FLOAT_EQ(2.0f
,
864 active_layer_
->tilings()->tiling_at(0)->contents_scale());
865 EXPECT_FLOAT_EQ(2.0f
* low_res_factor
,
866 active_layer_
->tilings()->tiling_at(1)->contents_scale());
868 // Start a pinch gesture.
869 host_impl_
.PinchGestureBegin();
871 // Zoom out by a small amount. We should create a tiling at half
872 // the scale (2/kMaxScaleRatioDuringPinch).
873 SetContentsScaleOnBothLayers(1.8f
, 1.0f
, 0.9f
, 1.0f
, false);
874 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
875 EXPECT_FLOAT_EQ(2.0f
,
876 active_layer_
->tilings()->tiling_at(0)->contents_scale());
877 EXPECT_FLOAT_EQ(1.0f
,
878 active_layer_
->tilings()->tiling_at(1)->contents_scale());
879 EXPECT_FLOAT_EQ(2.0f
* low_res_factor
,
880 active_layer_
->tilings()->tiling_at(2)->contents_scale());
882 // Zoom out further, close to our low-res scale factor. We should
883 // use that tiling as high-res, and not create a new tiling.
884 SetContentsScaleOnBothLayers(low_res_factor
* 2.1f
, 1.0f
,
885 low_res_factor
* 2.1f
, 1.0f
, false);
886 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
888 // Zoom in a lot now. Since we increase by increments of
889 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0.
890 SetContentsScaleOnBothLayers(3.8f
, 1.0f
, 2.1f
, 1.f
, false);
891 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
892 EXPECT_FLOAT_EQ(4.0f
,
893 active_layer_
->tilings()->tiling_at(0)->contents_scale());
896 TEST_F(PictureLayerImplTest
, SnappedTilingDuringZoom
) {
897 gfx::Size
tile_size(300, 300);
898 gfx::Size
layer_bounds(2600, 3800);
900 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
901 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
902 scoped_refptr
<FakePicturePileImpl
> active_pile
=
903 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
905 // Set up the high and low res tilings before pinch zoom.
906 SetupTrees(pending_pile
, active_pile
);
907 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
908 SetContentsScaleOnBothLayers(0.24f
, 1.0f
, 0.24f
, 1.0f
, false);
909 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
910 EXPECT_FLOAT_EQ(0.24f
,
911 active_layer_
->tilings()->tiling_at(0)->contents_scale());
912 EXPECT_FLOAT_EQ(0.0625f
,
913 active_layer_
->tilings()->tiling_at(1)->contents_scale());
915 // Start a pinch gesture.
916 host_impl_
.PinchGestureBegin();
918 // Zoom out by a small amount. We should create a tiling at half
919 // the scale (1/kMaxScaleRatioDuringPinch).
920 SetContentsScaleOnBothLayers(0.2f
, 1.0f
, 0.2f
, 1.0f
, false);
921 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
922 EXPECT_FLOAT_EQ(0.24f
,
923 active_layer_
->tilings()->tiling_at(0)->contents_scale());
924 EXPECT_FLOAT_EQ(0.12f
,
925 active_layer_
->tilings()->tiling_at(1)->contents_scale());
926 EXPECT_FLOAT_EQ(0.0625,
927 active_layer_
->tilings()->tiling_at(2)->contents_scale());
929 // Zoom out further, close to our low-res scale factor. We should
930 // use that tiling as high-res, and not create a new tiling.
931 SetContentsScaleOnBothLayers(0.1f
, 1.0f
, 0.1f
, 1.0f
, false);
932 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
934 // Zoom in. 0.25(desired_scale) should be snapped to 0.24 during zoom-in
935 // because 0.25(desired_scale) is within the ratio(1.2).
936 SetContentsScaleOnBothLayers(0.25f
, 1.0f
, 0.25f
, 1.0f
, false);
937 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
939 // Zoom in a lot. Since we move in factors of two, we should get a scale that
940 // is a power of 2 times 0.24.
941 SetContentsScaleOnBothLayers(1.f
, 1.0f
, 1.f
, 1.0f
, false);
942 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
943 EXPECT_FLOAT_EQ(1.92f
,
944 active_layer_
->tilings()->tiling_at(0)->contents_scale());
947 TEST_F(PictureLayerImplTest
, CleanUpTilings
) {
948 gfx::Size
tile_size(400, 400);
949 gfx::Size
layer_bounds(1300, 1900);
951 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
952 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
953 scoped_refptr
<FakePicturePileImpl
> active_pile
=
954 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
956 std::vector
<PictureLayerTiling
*> used_tilings
;
958 SetupTrees(pending_pile
, active_pile
);
959 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
961 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
962 EXPECT_LT(low_res_factor
, 1.f
);
964 float device_scale
= 1.7f
;
965 float page_scale
= 3.2f
;
968 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
969 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
971 // We only have ideal tilings, so they aren't removed.
972 used_tilings
.clear();
973 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
974 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
976 host_impl_
.PinchGestureBegin();
978 // Changing the ideal but not creating new tilings.
981 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
982 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
984 // The tilings are still our target scale, so they aren't removed.
985 used_tilings
.clear();
986 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
987 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
989 host_impl_
.PinchGestureEnd();
991 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
994 SetContentsScaleOnBothLayers(1.2f
, device_scale
, page_scale
, 1.f
, false);
995 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
998 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1000 1.f
* low_res_factor
,
1001 active_layer_
->tilings()->tiling_at(3)->contents_scale());
1003 // Mark the non-ideal tilings as used. They won't be removed.
1004 used_tilings
.clear();
1005 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1006 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(3));
1007 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1008 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
1010 // Now move the ideal scale to 0.5. Our target stays 1.2.
1011 SetContentsScaleOnBothLayers(0.5f
, device_scale
, page_scale
, 1.f
, false);
1013 // The high resolution tiling is between target and ideal, so is not
1014 // removed. The low res tiling for the old ideal=1.0 scale is removed.
1015 used_tilings
.clear();
1016 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1017 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1019 // Now move the ideal scale to 1.0. Our target stays 1.2.
1020 SetContentsScaleOnBothLayers(1.f
, device_scale
, page_scale
, 1.f
, false);
1022 // All the tilings are between are target and the ideal, so they are not
1024 used_tilings
.clear();
1025 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1026 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1028 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
1029 SetupDrawPropertiesAndUpdateTiles(
1030 active_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
1032 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1033 // in the range [1.0,1.2] and are kept.
1034 used_tilings
.clear();
1035 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1036 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1038 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1040 SetupDrawPropertiesAndUpdateTiles(
1041 pending_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
1043 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1044 // target raster scale. But it is in our used tilings set, so nothing is
1046 used_tilings
.clear();
1047 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1048 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1049 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1051 // If we remove it from our used tilings set, it is outside the range to keep
1052 // so it is deleted.
1053 used_tilings
.clear();
1054 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1055 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
1058 #define EXPECT_BOTH_EQ(expression, x) \
1060 EXPECT_EQ(x, pending_layer_->expression); \
1061 EXPECT_EQ(x, active_layer_->expression); \
1064 #define EXPECT_BOTH_NE(expression, x) \
1066 EXPECT_NE(x, pending_layer_->expression); \
1067 EXPECT_NE(x, active_layer_->expression); \
1070 TEST_F(PictureLayerImplTest
, DontAddLowResDuringAnimation
) {
1071 // Make sure this layer covers multiple tiles, since otherwise low
1072 // res won't get created because it is too small.
1073 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1074 SetupDefaultTrees(gfx::Size(tile_size
.width() + 1, tile_size
.height() + 1));
1075 // Avoid max untiled layer size heuristics via fixed tile size.
1076 pending_layer_
->set_fixed_tile_size(tile_size
);
1077 active_layer_
->set_fixed_tile_size(tile_size
);
1079 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1080 float contents_scale
= 1.f
;
1081 float device_scale
= 1.f
;
1082 float page_scale
= 1.f
;
1083 float maximum_animation_scale
= 1.f
;
1084 bool animating_transform
= true;
1086 // Animating, so don't create low res even if there isn't one already.
1087 SetContentsScaleOnBothLayers(contents_scale
,
1090 maximum_animation_scale
,
1091 animating_transform
);
1092 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1093 EXPECT_BOTH_EQ(num_tilings(), 1u);
1095 // Stop animating, low res gets created.
1096 animating_transform
= false;
1097 SetContentsScaleOnBothLayers(contents_scale
,
1100 maximum_animation_scale
,
1101 animating_transform
);
1102 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1103 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor
);
1104 EXPECT_BOTH_EQ(num_tilings(), 2u);
1106 // Page scale animation, new high res, but no low res. We still have
1107 // a tiling at the previous scale, it's just not marked as low res.
1108 contents_scale
= 2.f
;
1110 maximum_animation_scale
= 2.f
;
1111 animating_transform
= true;
1112 SetContentsScaleOnBothLayers(contents_scale
,
1115 maximum_animation_scale
,
1116 animating_transform
);
1117 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1118 EXPECT_FALSE(active_layer_
->LowResTiling());
1119 EXPECT_FALSE(pending_layer_
->LowResTiling());
1120 EXPECT_BOTH_EQ(num_tilings(), 3u);
1122 // Stop animating, new low res gets created for final page scale.
1123 animating_transform
= false;
1124 SetContentsScaleOnBothLayers(contents_scale
,
1127 maximum_animation_scale
,
1128 animating_transform
);
1129 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1130 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f
* low_res_factor
);
1131 EXPECT_BOTH_EQ(num_tilings(), 4u);
1134 TEST_F(PictureLayerImplTest
, DontAddLowResForSmallLayers
) {
1135 gfx::Size
layer_bounds(host_impl_
.settings().default_tile_size
);
1136 gfx::Size
tile_size(100, 100);
1138 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1139 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1140 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1141 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1143 SetupTrees(pending_pile
, active_pile
);
1145 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1146 float device_scale
= 1.f
;
1147 float page_scale
= 1.f
;
1148 float maximum_animation_scale
= 1.f
;
1149 bool animating_transform
= false;
1151 // Contents exactly fit on one tile at scale 1, no low res.
1152 float contents_scale
= 1.f
;
1153 SetContentsScaleOnBothLayers(contents_scale
,
1156 maximum_animation_scale
,
1157 animating_transform
);
1158 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1159 EXPECT_BOTH_EQ(num_tilings(), 1u);
1161 ResetTilingsAndRasterScales();
1163 // Contents that are smaller than one tile, no low res.
1164 contents_scale
= 0.123f
;
1165 SetContentsScaleOnBothLayers(contents_scale
,
1168 maximum_animation_scale
,
1169 animating_transform
);
1170 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1171 EXPECT_BOTH_EQ(num_tilings(), 1u);
1173 ResetTilingsAndRasterScales();
1175 // Any content bounds that would create more than one tile will
1176 // generate a low res tiling.
1177 contents_scale
= 2.5f
;
1178 SetContentsScaleOnBothLayers(contents_scale
,
1181 maximum_animation_scale
,
1182 animating_transform
);
1183 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1184 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1185 contents_scale
* low_res_factor
);
1186 EXPECT_BOTH_EQ(num_tilings(), 2u);
1188 ResetTilingsAndRasterScales();
1190 // Mask layers dont create low res since they always fit on one tile.
1191 pending_layer_
->set_is_mask(true);
1192 active_layer_
->set_is_mask(true);
1193 SetContentsScaleOnBothLayers(contents_scale
,
1196 maximum_animation_scale
,
1197 animating_transform
);
1198 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1199 EXPECT_BOTH_EQ(num_tilings(), 1u);
1202 TEST_F(PictureLayerImplTest
, HugeMasksDontGetTiles
) {
1203 gfx::Size
tile_size(100, 100);
1205 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1206 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(1000, 1000));
1207 SetupPendingTree(valid_pile
);
1208 pending_layer_
->set_is_mask(true);
1210 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1211 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
1212 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1214 pending_layer_
->HighResTiling()->CreateAllTilesForTesting();
1215 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1216 pending_layer_
->HighResTiling()->AllTilesForTesting());
1220 // Mask layers have a tiling with a single tile in it.
1221 EXPECT_EQ(1u, active_layer_
->HighResTiling()->AllTilesForTesting().size());
1222 // The mask resource exists.
1223 ResourceProvider::ResourceId mask_resource_id
;
1224 gfx::Size mask_texture_size
;
1225 active_layer_
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1226 EXPECT_NE(0u, mask_resource_id
);
1227 EXPECT_EQ(mask_texture_size
, active_layer_
->bounds());
1229 // Resize larger than the max texture size.
1230 int max_texture_size
= host_impl_
.GetRendererCapabilities().max_texture_size
;
1231 scoped_refptr
<FakePicturePileImpl
> huge_pile
=
1232 FakePicturePileImpl::CreateFilledPile(
1233 tile_size
, gfx::Size(max_texture_size
+ 1, 10));
1234 SetupPendingTree(huge_pile
);
1235 pending_layer_
->set_is_mask(true);
1237 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1238 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
1239 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1241 pending_layer_
->HighResTiling()->CreateAllTilesForTesting();
1242 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1243 pending_layer_
->HighResTiling()->AllTilesForTesting());
1247 // Mask layers have a tiling, but there should be no tiles in it.
1248 EXPECT_EQ(0u, active_layer_
->HighResTiling()->AllTilesForTesting().size());
1249 // The mask resource is empty.
1250 active_layer_
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1251 EXPECT_EQ(0u, mask_resource_id
);
1254 TEST_F(PictureLayerImplTest
, ScaledMaskLayer
) {
1255 gfx::Size
tile_size(100, 100);
1257 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1258 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(1000, 1000));
1259 SetupPendingTree(valid_pile
);
1260 pending_layer_
->set_is_mask(true);
1262 float ideal_contents_scale
= 1.3f
;
1263 SetupDrawPropertiesAndUpdateTiles(
1264 pending_layer_
, ideal_contents_scale
, 1.f
, 1.f
, 1.f
, false);
1265 EXPECT_EQ(ideal_contents_scale
,
1266 pending_layer_
->HighResTiling()->contents_scale());
1267 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1269 pending_layer_
->HighResTiling()->CreateAllTilesForTesting();
1270 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1271 pending_layer_
->HighResTiling()->AllTilesForTesting());
1275 // Mask layers have a tiling with a single tile in it.
1276 EXPECT_EQ(1u, active_layer_
->HighResTiling()->AllTilesForTesting().size());
1277 // The mask resource exists.
1278 ResourceProvider::ResourceId mask_resource_id
;
1279 gfx::Size mask_texture_size
;
1280 active_layer_
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1281 EXPECT_NE(0u, mask_resource_id
);
1282 gfx::Size expected_mask_texture_size
= gfx::ToCeiledSize(
1283 gfx::ScaleSize(active_layer_
->bounds(), ideal_contents_scale
));
1284 EXPECT_EQ(mask_texture_size
, expected_mask_texture_size
);
1287 TEST_F(PictureLayerImplTest
, ReleaseResources
) {
1288 gfx::Size
tile_size(400, 400);
1289 gfx::Size
layer_bounds(1300, 1900);
1291 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1292 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1293 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1294 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1296 SetupTrees(pending_pile
, active_pile
);
1297 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1299 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
1300 1.3f
, // ideal contents scale
1301 2.7f
, // device scale
1303 1.f
, // maximum animation scale
1305 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1307 // All tilings should be removed when losing output surface.
1308 active_layer_
->ReleaseResources();
1309 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1310 pending_layer_
->ReleaseResources();
1311 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1313 // This should create new tilings.
1314 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
1315 1.3f
, // ideal contents scale
1316 2.7f
, // device scale
1318 1.f
, // maximum animation scale
1320 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1323 TEST_F(PictureLayerImplTest
, ClampTilesToToMaxTileSize
) {
1324 // The default max tile size is larger than 400x400.
1325 gfx::Size
tile_size(400, 400);
1326 gfx::Size
layer_bounds(5000, 5000);
1328 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1329 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1330 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1331 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1333 SetupTrees(pending_pile
, active_pile
);
1334 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1336 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1337 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1339 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1341 // The default value.
1342 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1343 host_impl_
.settings().default_tile_size
.ToString());
1345 Tile
* tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1346 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1347 tile
->content_rect().size().ToString());
1349 pending_layer_
->ReleaseResources();
1351 // Change the max texture size on the output surface context.
1352 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1353 TestWebGraphicsContext3D::Create();
1354 context
->set_max_texture_size(140);
1355 host_impl_
.DidLoseOutputSurface();
1356 host_impl_
.InitializeRenderer(
1357 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1359 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1360 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1362 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1364 // Verify the tiles are not larger than the context's max texture size.
1365 tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1366 EXPECT_GE(140, tile
->content_rect().width());
1367 EXPECT_GE(140, tile
->content_rect().height());
1370 TEST_F(PictureLayerImplTest
, ClampSingleTileToToMaxTileSize
) {
1371 // The default max tile size is larger than 400x400.
1372 gfx::Size
tile_size(400, 400);
1373 gfx::Size
layer_bounds(500, 500);
1375 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1376 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1377 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1378 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1380 SetupTrees(pending_pile
, active_pile
);
1381 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1383 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1384 ASSERT_LE(1u, pending_layer_
->tilings()->num_tilings());
1386 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1388 // The default value. The layer is smaller than this.
1389 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1390 host_impl_
.settings().max_untiled_layer_size
.ToString());
1392 // There should be a single tile since the layer is small.
1393 PictureLayerTiling
* high_res_tiling
= pending_layer_
->tilings()->tiling_at(0);
1394 EXPECT_EQ(1u, high_res_tiling
->AllTilesForTesting().size());
1396 pending_layer_
->ReleaseResources();
1398 // Change the max texture size on the output surface context.
1399 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1400 TestWebGraphicsContext3D::Create();
1401 context
->set_max_texture_size(140);
1402 host_impl_
.DidLoseOutputSurface();
1403 host_impl_
.InitializeRenderer(
1404 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1406 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1407 ASSERT_LE(1u, pending_layer_
->tilings()->num_tilings());
1409 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1411 // There should be more than one tile since the max texture size won't cover
1413 high_res_tiling
= pending_layer_
->tilings()->tiling_at(0);
1414 EXPECT_LT(1u, high_res_tiling
->AllTilesForTesting().size());
1416 // Verify the tiles are not larger than the context's max texture size.
1417 Tile
* tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1418 EXPECT_GE(140, tile
->content_rect().width());
1419 EXPECT_GE(140, tile
->content_rect().height());
1422 TEST_F(PictureLayerImplTest
, DisallowTileDrawQuads
) {
1423 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1425 gfx::Size
tile_size(400, 400);
1426 gfx::Size
layer_bounds(1300, 1900);
1428 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1429 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1430 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1431 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1433 SetupTrees(pending_pile
, active_pile
);
1435 active_layer_
->draw_properties().visible_content_rect
=
1436 gfx::Rect(layer_bounds
);
1438 gfx::Rect
layer_invalidation(150, 200, 30, 180);
1439 Region
invalidation(layer_invalidation
);
1440 AddDefaultTilingsWithInvalidation(invalidation
);
1442 AppendQuadsData data
;
1443 active_layer_
->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE
, nullptr);
1444 active_layer_
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
1445 active_layer_
->DidDraw(nullptr);
1447 ASSERT_EQ(1U, render_pass
->quad_list
.size());
1448 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
,
1449 render_pass
->quad_list
.front()->material
);
1452 TEST_F(PictureLayerImplTest
, SolidColorLayerHasVisibleFullCoverage
) {
1453 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1455 gfx::Size
tile_size(1000, 1000);
1456 gfx::Size
layer_bounds(1500, 1500);
1457 gfx::Rect
visible_rect(250, 250, 1000, 1000);
1459 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1460 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
1461 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1462 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
1464 pending_pile
->set_is_solid_color(true);
1465 active_pile
->set_is_solid_color(true);
1467 SetupTrees(pending_pile
, active_pile
);
1469 active_layer_
->draw_properties().visible_content_rect
= visible_rect
;
1471 AppendQuadsData data
;
1472 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1473 active_layer_
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
1474 active_layer_
->DidDraw(nullptr);
1476 Region remaining
= visible_rect
;
1477 for (const auto& quad
: render_pass
->quad_list
) {
1478 EXPECT_TRUE(visible_rect
.Contains(quad
->rect
));
1479 EXPECT_TRUE(remaining
.Contains(quad
->rect
));
1480 remaining
.Subtract(quad
->rect
);
1483 EXPECT_TRUE(remaining
.IsEmpty());
1486 TEST_F(PictureLayerImplTest
, TileScalesWithSolidColorPile
) {
1487 gfx::Size
layer_bounds(200, 200);
1488 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1489 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1490 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1491 tile_size
, layer_bounds
);
1492 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1493 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1494 tile_size
, layer_bounds
);
1496 pending_pile
->set_is_solid_color(false);
1497 active_pile
->set_is_solid_color(true);
1498 SetupTrees(pending_pile
, active_pile
);
1499 // Solid color layer should not have tilings.
1500 ASSERT_FALSE(active_layer_
->CanHaveTilings());
1502 // Update properties with solid color pile should not allow tilings at any
1504 host_impl_
.active_tree()->UpdateDrawProperties();
1505 EXPECT_FALSE(active_layer_
->CanHaveTilings());
1506 EXPECT_EQ(0.f
, active_layer_
->ideal_contents_scale());
1508 // Push non-solid-color pending pile makes active layer can have tilings.
1509 active_layer_
->UpdateRasterSource(pending_pile
);
1510 ASSERT_TRUE(active_layer_
->CanHaveTilings());
1512 // Update properties with non-solid color pile should allow tilings.
1513 host_impl_
.active_tree()->UpdateDrawProperties();
1514 EXPECT_TRUE(active_layer_
->CanHaveTilings());
1515 EXPECT_GT(active_layer_
->ideal_contents_scale(), 0.f
);
1518 TEST_F(PictureLayerImplTest
, MarkRequiredOffscreenTiles
) {
1519 gfx::Size
tile_size(100, 100);
1520 gfx::Size
layer_bounds(200, 200);
1522 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1523 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1524 SetupPendingTree(pending_pile
);
1526 gfx::Transform transform
;
1527 gfx::Transform transform_for_tile_priority
;
1528 bool resourceless_software_draw
= false;
1529 gfx::Rect
viewport(0, 0, 100, 200);
1530 host_impl_
.SetExternalDrawConstraints(transform
,
1535 resourceless_software_draw
);
1537 pending_layer_
->set_fixed_tile_size(tile_size
);
1538 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
1539 PictureLayerTiling
* tiling
= pending_layer_
->AddTiling(1.f
);
1540 host_impl_
.pending_tree()->UpdateDrawProperties();
1541 EXPECT_EQ(viewport
, pending_layer_
->visible_rect_for_tile_priority());
1543 base::TimeTicks time_ticks
;
1544 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1545 host_impl_
.SetCurrentBeginFrameArgs(
1546 CreateBeginFrameArgsForTesting(time_ticks
));
1547 pending_layer_
->UpdateTiles(Occlusion(), resourceless_software_draw
);
1548 EXPECT_EQ(HIGH_RESOLUTION
, tiling
->resolution());
1550 int num_visible
= 0;
1551 int num_offscreen
= 0;
1553 for (PictureLayerTiling::TilingRasterTileIterator
iter(tiling
); iter
;
1555 const Tile
* tile
= *iter
;
1557 if (tile
->priority(PENDING_TREE
).distance_to_visible
== 0.f
) {
1558 EXPECT_TRUE(tile
->required_for_activation());
1561 EXPECT_FALSE(tile
->required_for_activation());
1566 EXPECT_GT(num_visible
, 0);
1567 EXPECT_GT(num_offscreen
, 0);
1570 TEST_F(PictureLayerImplTest
, TileOutsideOfViewportForTilePriorityNotRequired
) {
1571 base::TimeTicks time_ticks
;
1572 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1573 host_impl_
.SetCurrentBeginFrameArgs(
1574 CreateBeginFrameArgsForTesting(time_ticks
));
1576 gfx::Size
tile_size(100, 100);
1577 gfx::Size
layer_bounds(400, 400);
1578 gfx::Rect
external_viewport_for_tile_priority(400, 200);
1579 gfx::Rect
visible_content_rect(200, 400);
1581 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1582 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1583 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1584 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1585 SetupTrees(pending_pile
, active_pile
);
1587 active_layer_
->set_fixed_tile_size(tile_size
);
1588 pending_layer_
->set_fixed_tile_size(tile_size
);
1589 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
1590 PictureLayerTiling
* tiling
= pending_layer_
->AddTiling(1.f
);
1592 // Set external viewport for tile priority.
1593 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
1594 gfx::Transform transform
;
1595 gfx::Transform transform_for_tile_priority
;
1596 bool resourceless_software_draw
= false;
1597 host_impl_
.SetExternalDrawConstraints(transform
,
1600 external_viewport_for_tile_priority
,
1601 transform_for_tile_priority
,
1602 resourceless_software_draw
);
1603 host_impl_
.pending_tree()->UpdateDrawProperties();
1605 // Set visible content rect that is different from
1606 // external_viewport_for_tile_priority.
1607 pending_layer_
->draw_properties().visible_content_rect
= visible_content_rect
;
1608 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
1609 host_impl_
.SetCurrentBeginFrameArgs(
1610 CreateBeginFrameArgsForTesting(time_ticks
));
1611 pending_layer_
->UpdateTiles(Occlusion(), resourceless_software_draw
);
1613 // Intersect the two rects. Any tile outside should not be required for
1615 gfx::Rect viewport_for_tile_priority
=
1616 pending_layer_
->GetViewportForTilePriorityInContentSpace();
1617 viewport_for_tile_priority
.Intersect(pending_layer_
->visible_content_rect());
1620 int num_outside
= 0;
1621 for (PictureLayerTiling::CoverageIterator
iter(
1622 tiling
, pending_layer_
->contents_scale_x(), gfx::Rect(layer_bounds
));
1628 if (viewport_for_tile_priority
.Intersects(iter
.geometry_rect())) {
1630 // Mark everything in viewport for tile priority as ready to draw.
1631 ManagedTileState::DrawInfo
& draw_info
= tile
->draw_info();
1632 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
1635 EXPECT_FALSE(tile
->required_for_activation());
1639 EXPECT_GT(num_inside
, 0);
1640 EXPECT_GT(num_outside
, 0);
1642 // Activate and draw active layer.
1643 host_impl_
.ActivateSyncTree();
1644 host_impl_
.active_tree()->UpdateDrawProperties();
1645 active_layer_
->draw_properties().visible_content_rect
= visible_content_rect
;
1647 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1648 AppendQuadsData data
;
1649 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1650 active_layer_
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
1651 active_layer_
->DidDraw(nullptr);
1653 // All tiles in activation rect is ready to draw.
1654 EXPECT_EQ(0u, data
.num_missing_tiles
);
1655 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1656 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1659 TEST_F(PictureLayerImplTest
, HighResTileIsComplete
) {
1660 base::TimeTicks time_ticks
;
1661 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1662 host_impl_
.SetCurrentBeginFrameArgs(
1663 CreateBeginFrameArgsForTesting(time_ticks
));
1665 gfx::Size
tile_size(100, 100);
1666 gfx::Size
layer_bounds(200, 200);
1668 host_impl_
.SetViewportSize(layer_bounds
);
1670 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1671 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1672 SetupPendingTree(pending_pile
);
1675 // All high res tiles have resources.
1676 active_layer_
->set_fixed_tile_size(tile_size
);
1677 host_impl_
.active_tree()->UpdateDrawProperties();
1678 std::vector
<Tile
*> tiles
=
1679 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1680 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
1682 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1683 AppendQuadsData data
;
1684 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1685 active_layer_
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
1686 active_layer_
->DidDraw(nullptr);
1688 // All high res tiles drew, nothing was incomplete.
1689 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1690 EXPECT_EQ(0u, data
.num_missing_tiles
);
1691 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1692 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1695 TEST_F(PictureLayerImplTest
, HighResTileIsIncomplete
) {
1696 base::TimeTicks time_ticks
;
1697 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1698 host_impl_
.SetCurrentBeginFrameArgs(
1699 CreateBeginFrameArgsForTesting(time_ticks
));
1701 gfx::Size
tile_size(100, 100);
1702 gfx::Size
layer_bounds(200, 200);
1704 host_impl_
.SetViewportSize(layer_bounds
);
1706 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1707 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1708 SetupPendingTree(pending_pile
);
1711 active_layer_
->set_fixed_tile_size(tile_size
);
1712 host_impl_
.active_tree()->UpdateDrawProperties();
1714 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1715 AppendQuadsData data
;
1716 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1717 active_layer_
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
1718 active_layer_
->DidDraw(nullptr);
1720 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1721 EXPECT_EQ(1u, data
.num_missing_tiles
);
1722 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1723 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1726 TEST_F(PictureLayerImplTest
, HighResTileIsIncompleteLowResComplete
) {
1727 base::TimeTicks time_ticks
;
1728 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1729 host_impl_
.SetCurrentBeginFrameArgs(
1730 CreateBeginFrameArgsForTesting(time_ticks
));
1732 gfx::Size
tile_size(100, 100);
1733 gfx::Size
layer_bounds(200, 200);
1735 host_impl_
.SetViewportSize(layer_bounds
);
1737 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1738 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1739 SetupPendingTree(pending_pile
);
1742 active_layer_
->set_fixed_tile_size(tile_size
);
1743 host_impl_
.active_tree()->UpdateDrawProperties();
1744 std::vector
<Tile
*> low_tiles
=
1745 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1746 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1748 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1749 AppendQuadsData data
;
1750 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1751 active_layer_
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
1752 active_layer_
->DidDraw(nullptr);
1754 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1755 EXPECT_EQ(0u, data
.num_missing_tiles
);
1756 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1757 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1760 TEST_F(PictureLayerImplTest
, LowResTileIsIncomplete
) {
1761 base::TimeTicks time_ticks
;
1762 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1763 host_impl_
.SetCurrentBeginFrameArgs(
1764 CreateBeginFrameArgsForTesting(time_ticks
));
1766 gfx::Size
tile_size(100, 100);
1767 gfx::Size
layer_bounds(200, 200);
1769 host_impl_
.SetViewportSize(layer_bounds
);
1771 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1772 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1773 SetupPendingTree(pending_pile
);
1776 // All high res tiles have resources except one.
1777 active_layer_
->set_fixed_tile_size(tile_size
);
1778 host_impl_
.active_tree()->UpdateDrawProperties();
1779 std::vector
<Tile
*> high_tiles
=
1780 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1781 high_tiles
.erase(high_tiles
.begin());
1782 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
1784 // All low res tiles have resources.
1785 std::vector
<Tile
*> low_tiles
=
1786 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1787 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1789 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1790 AppendQuadsData data
;
1791 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1792 active_layer_
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
1793 active_layer_
->DidDraw(nullptr);
1795 // The missing high res tile was replaced by a low res tile.
1796 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1797 EXPECT_EQ(0u, data
.num_missing_tiles
);
1798 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1799 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1802 TEST_F(PictureLayerImplTest
,
1803 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal
) {
1804 base::TimeTicks time_ticks
;
1805 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1806 host_impl_
.SetCurrentBeginFrameArgs(
1807 CreateBeginFrameArgsForTesting(time_ticks
));
1809 gfx::Size
tile_size(100, 100);
1810 gfx::Size
layer_bounds(200, 200);
1812 host_impl_
.SetViewportSize(layer_bounds
);
1814 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1815 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1816 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1817 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1818 SetupTrees(pending_pile
, active_pile
);
1820 active_layer_
->set_fixed_tile_size(tile_size
);
1822 active_layer_
->draw_properties().visible_content_rect
=
1823 gfx::Rect(layer_bounds
);
1824 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.f
, 1.f
, 1.f
, 1.f
, false);
1826 // One ideal tile exists, this will get used when drawing.
1827 std::vector
<Tile
*> ideal_tiles
;
1828 EXPECT_EQ(2.f
, active_layer_
->HighResTiling()->contents_scale());
1829 ideal_tiles
.push_back(active_layer_
->HighResTiling()->TileAt(0, 0));
1830 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1833 // Due to layer scale throttling, the raster contents scale is changed to 1,
1834 // while the ideal is still 2.
1835 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1836 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.f
, 1.f
, 1.f
, 1.f
, false);
1838 EXPECT_EQ(1.f
, active_layer_
->HighResTiling()->contents_scale());
1839 EXPECT_EQ(1.f
, active_layer_
->raster_contents_scale());
1840 EXPECT_EQ(2.f
, active_layer_
->ideal_contents_scale());
1842 // Both tilings still exist.
1843 EXPECT_EQ(2.f
, active_layer_
->tilings()->tiling_at(0)->contents_scale());
1844 EXPECT_EQ(1.f
, active_layer_
->tilings()->tiling_at(1)->contents_scale());
1846 // All high res tiles have resources.
1847 std::vector
<Tile
*> high_tiles
=
1848 active_layer_
->HighResTiling()->AllTilesForTesting();
1849 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
1851 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1852 AppendQuadsData data
;
1853 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1854 active_layer_
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
1855 active_layer_
->DidDraw(nullptr);
1857 // All high res tiles drew, and the one ideal res tile drew.
1858 ASSERT_GT(render_pass
->quad_list
.size(), 9u);
1859 EXPECT_EQ(gfx::SizeF(99.f
, 99.f
),
1860 TileDrawQuad::MaterialCast(render_pass
->quad_list
.front())
1861 ->tex_coord_rect
.size());
1862 EXPECT_EQ(gfx::SizeF(49.5f
, 49.5f
),
1863 TileDrawQuad::MaterialCast(render_pass
->quad_list
.ElementAt(1))
1864 ->tex_coord_rect
.size());
1866 // Neither the high res nor the ideal tiles were considered as incomplete.
1867 EXPECT_EQ(0u, data
.num_missing_tiles
);
1868 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1869 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1872 TEST_F(PictureLayerImplTest
, HighResRequiredWhenUnsharedActiveAllReady
) {
1873 gfx::Size
layer_bounds(400, 400);
1874 gfx::Size
tile_size(100, 100);
1875 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
1878 pending_layer_
->set_invalidation(gfx::Rect(layer_bounds
));
1880 CreateHighLowResAndSetAllTilesVisible();
1882 active_layer_
->SetAllTilesReady();
1884 // No shared tiles and all active tiles ready, so pending can only
1885 // activate with all high res tiles.
1886 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
1887 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
1889 AssertAllTilesRequired(pending_layer_
->HighResTiling());
1890 AssertNoTilesRequired(pending_layer_
->LowResTiling());
1893 TEST_F(PictureLayerImplTest
, HighResRequiredWhenMissingHighResFlagOn
) {
1894 gfx::Size
layer_bounds(400, 400);
1895 gfx::Size
tile_size(100, 100);
1896 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
1898 // All tiles shared (no invalidation).
1899 CreateHighLowResAndSetAllTilesVisible();
1901 // Verify active tree not ready.
1902 Tile
* some_active_tile
=
1903 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
1904 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
1906 // When high res are required, even if the active tree is not ready,
1907 // the high res tiles must be ready.
1908 host_impl_
.SetRequiresHighResToDraw();
1910 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
1911 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
1913 AssertAllTilesRequired(pending_layer_
->HighResTiling());
1914 AssertNoTilesRequired(pending_layer_
->LowResTiling());
1917 TEST_F(PictureLayerImplTest
, AllHighResRequiredEvenIfShared
) {
1918 gfx::Size
layer_bounds(400, 400);
1919 gfx::Size
tile_size(100, 100);
1920 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
1922 CreateHighLowResAndSetAllTilesVisible();
1924 Tile
* some_active_tile
=
1925 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
1926 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
1928 // All tiles shared (no invalidation), so even though the active tree's
1929 // tiles aren't ready, the high res tiles are required for activation.
1930 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
1931 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
1933 AssertAllTilesRequired(pending_layer_
->HighResTiling());
1934 AssertNoTilesRequired(pending_layer_
->LowResTiling());
1937 TEST_F(PictureLayerImplTest
, DisallowRequiredForActivation
) {
1938 gfx::Size
layer_bounds(400, 400);
1939 gfx::Size
tile_size(100, 100);
1940 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
1942 CreateHighLowResAndSetAllTilesVisible();
1944 Tile
* some_active_tile
=
1945 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
1946 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
1948 pending_layer_
->HighResTiling()->set_can_require_tiles_for_activation(false);
1949 pending_layer_
->LowResTiling()->set_can_require_tiles_for_activation(false);
1951 // If we disallow required for activation, no tiles can be required.
1952 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
1953 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
1955 AssertNoTilesRequired(pending_layer_
->HighResTiling());
1956 AssertNoTilesRequired(pending_layer_
->LowResTiling());
1959 TEST_F(PictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
1960 gfx::Size
layer_bounds(400, 400);
1961 gfx::Size
tile_size(100, 100);
1962 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1963 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1964 // This pile will create tilings, but has no recordings so will not create any
1965 // tiles. This is attempting to simulate scrolling past the end of recorded
1966 // content on the active layer, where the recordings are so far away that
1967 // no tiles are created.
1968 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1969 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1970 tile_size
, layer_bounds
);
1971 SetupTrees(pending_pile
, active_pile
);
1972 pending_layer_
->set_fixed_tile_size(tile_size
);
1973 active_layer_
->set_fixed_tile_size(tile_size
);
1975 CreateHighLowResAndSetAllTilesVisible();
1977 // Active layer has tilings, but no tiles due to missing recordings.
1978 EXPECT_TRUE(active_layer_
->CanHaveTilings());
1979 EXPECT_EQ(active_layer_
->tilings()->num_tilings(), 2u);
1980 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
1982 // Since the active layer has no tiles at all, the pending layer doesn't
1983 // need content in order to activate.
1984 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
1985 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
1987 AssertNoTilesRequired(pending_layer_
->HighResTiling());
1988 AssertNoTilesRequired(pending_layer_
->LowResTiling());
1991 TEST_F(PictureLayerImplTest
, HighResRequiredIfActiveCantHaveTiles
) {
1992 gfx::Size
layer_bounds(400, 400);
1993 gfx::Size
tile_size(100, 100);
1994 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1995 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1996 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1997 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
1998 SetupTrees(pending_pile
, active_pile
);
1999 pending_layer_
->set_fixed_tile_size(tile_size
);
2000 active_layer_
->set_fixed_tile_size(tile_size
);
2002 CreateHighLowResAndSetAllTilesVisible();
2004 // Active layer can't have tiles.
2005 EXPECT_FALSE(active_layer_
->CanHaveTilings());
2007 // All high res tiles required. This should be considered identical
2008 // to the case where there is no active layer, to avoid flashing content.
2009 // This can happen if a layer exists for a while and switches from
2010 // not being able to have content to having content.
2011 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2012 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2014 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2015 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2018 TEST_F(PictureLayerImplTest
, HighResRequiredWhenActiveHasDifferentBounds
) {
2019 gfx::Size
layer_bounds(200, 200);
2020 gfx::Size
tile_size(100, 100);
2021 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
2023 gfx::Size
pending_layer_bounds(400, 400);
2024 pending_layer_
->SetBounds(pending_layer_bounds
);
2026 CreateHighLowResAndSetAllTilesVisible();
2027 // TODO(vmpstr): This is confusing. Rework the test to create different bounds
2028 // on different trees instead of fudging tilings.
2029 pending_layer_
->HighResTiling()->ComputeTilePriorityRects(
2030 gfx::Rect(pending_layer_bounds
), 1.f
, 1.f
, Occlusion());
2032 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2033 active_layer_
->SetAllTilesReady();
2035 // Since the active layer has different bounds, the pending layer needs all
2036 // high res tiles in order to activate.
2037 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2038 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2040 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2041 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2044 TEST_F(PictureLayerImplTest
, ActivateUninitializedLayer
) {
2045 gfx::Size
tile_size(100, 100);
2046 gfx::Size
layer_bounds(400, 400);
2047 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2048 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2050 host_impl_
.CreatePendingTree();
2051 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
2053 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
2054 FakePictureLayerImpl::CreateWithRasterSource(pending_tree
, id_
,
2056 pending_layer
->SetDrawsContent(true);
2057 pending_tree
->SetRootLayer(pending_layer
.Pass());
2059 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
2060 host_impl_
.pending_tree()->LayerById(id_
));
2062 // Set some state on the pending layer, make sure it is not clobbered
2063 // by a sync from the active layer. This could happen because if the
2064 // pending layer has not been post-commit initialized it will attempt
2065 // to sync from the active layer.
2066 float raster_page_scale
= 10.f
* pending_layer_
->raster_page_scale();
2067 pending_layer_
->set_raster_page_scale(raster_page_scale
);
2068 EXPECT_TRUE(pending_layer_
->needs_post_commit_initialization());
2070 host_impl_
.ActivateSyncTree();
2072 active_layer_
= static_cast<FakePictureLayerImpl
*>(
2073 host_impl_
.active_tree()->LayerById(id_
));
2075 EXPECT_EQ(0u, active_layer_
->num_tilings());
2076 EXPECT_EQ(raster_page_scale
, active_layer_
->raster_page_scale());
2077 EXPECT_FALSE(active_layer_
->needs_post_commit_initialization());
2080 TEST_F(PictureLayerImplTest
, ShareTilesOnNextFrame
) {
2081 SetupDefaultTrees(gfx::Size(1500, 1500));
2083 PictureLayerTiling
* tiling
= pending_layer_
->AddTiling(1.f
);
2084 gfx::Rect first_invalidate
= tiling
->TilingDataForTesting().TileBounds(0, 0);
2085 first_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2086 tiling
->TilingDataForTesting().border_texels());
2087 gfx::Rect second_invalidate
= tiling
->TilingDataForTesting().TileBounds(1, 1);
2088 second_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2089 tiling
->TilingDataForTesting().border_texels());
2091 // Make a pending tree with an invalidated raster tile 0,0.
2092 tiling
->CreateAllTilesForTesting();
2093 pending_layer_
->set_invalidation(first_invalidate
);
2095 // Activate and make a pending tree with an invalidated raster tile 1,1.
2098 host_impl_
.CreatePendingTree();
2099 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
2100 host_impl_
.pending_tree()->root_layer());
2101 pending_layer_
->set_invalidation(second_invalidate
);
2103 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2104 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2106 pending_tiling
->CreateAllTilesForTesting();
2108 // Tile 0,0 should be shared, but tile 1,1 should not be.
2109 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2110 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2111 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2112 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2113 EXPECT_TRUE(pending_tiling
->TileAt(0, 0)->is_shared());
2114 EXPECT_TRUE(pending_tiling
->TileAt(1, 0)->is_shared());
2115 EXPECT_TRUE(pending_tiling
->TileAt(0, 1)->is_shared());
2116 EXPECT_FALSE(pending_tiling
->TileAt(1, 1)->is_shared());
2118 // Drop the tiles on the active tree and recreate them. The same tiles
2119 // should be shared or not.
2120 active_tiling
->ComputeTilePriorityRects(gfx::Rect(), 1.f
, 1.0, Occlusion());
2121 EXPECT_TRUE(active_tiling
->AllTilesForTesting().empty());
2122 active_tiling
->CreateAllTilesForTesting();
2124 // Tile 0,0 should be shared, but tile 1,1 should not be.
2125 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2126 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2127 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2128 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2129 EXPECT_TRUE(pending_tiling
->TileAt(0, 0)->is_shared());
2130 EXPECT_TRUE(pending_tiling
->TileAt(1, 0)->is_shared());
2131 EXPECT_TRUE(pending_tiling
->TileAt(0, 1)->is_shared());
2132 EXPECT_FALSE(pending_tiling
->TileAt(1, 1)->is_shared());
2135 TEST_F(PictureLayerImplTest
, ShareTilesOnSync
) {
2136 SetupDefaultTrees(gfx::Size(1500, 1500));
2137 AddDefaultTilingsWithInvalidation(gfx::Rect());
2139 host_impl_
.ActivateSyncTree();
2140 host_impl_
.CreatePendingTree();
2141 active_layer_
= static_cast<FakePictureLayerImpl
*>(
2142 host_impl_
.active_tree()->LayerById(id_
));
2144 // Force the active tree to sync to the pending tree "post-commit".
2145 pending_layer_
->DoPostCommitInitializationIfNeeded();
2147 // Both invalidations should drop tiles from the pending tree.
2148 EXPECT_EQ(3u, active_layer_
->num_tilings());
2149 EXPECT_EQ(3u, pending_layer_
->num_tilings());
2150 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
2151 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(i
);
2152 PictureLayerTiling
* pending_tiling
=
2153 pending_layer_
->tilings()->tiling_at(i
);
2155 ASSERT_TRUE(active_tiling
);
2156 ASSERT_TRUE(pending_tiling
);
2158 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2159 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2160 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2161 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2163 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2164 EXPECT_TRUE(pending_tiling
->TileAt(1, 0));
2165 EXPECT_TRUE(pending_tiling
->TileAt(0, 1));
2166 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2168 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2169 EXPECT_TRUE(active_tiling
->TileAt(0, 0)->is_shared());
2170 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2171 EXPECT_TRUE(active_tiling
->TileAt(1, 0)->is_shared());
2172 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2173 EXPECT_TRUE(active_tiling
->TileAt(0, 1)->is_shared());
2174 EXPECT_EQ(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2175 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2179 TEST_F(PictureLayerImplTest
, ShareInvalidActiveTreeTilesOnSync
) {
2180 SetupDefaultTrees(gfx::Size(1500, 1500));
2181 AddDefaultTilingsWithInvalidation(gfx::Rect(0, 0, 1, 1));
2183 // This activates the 0,0,1,1 invalidation.
2184 host_impl_
.ActivateSyncTree();
2185 host_impl_
.CreatePendingTree();
2186 active_layer_
= static_cast<FakePictureLayerImpl
*>(
2187 host_impl_
.active_tree()->LayerById(id_
));
2189 // Force the active tree to sync to the pending tree "post-commit".
2190 pending_layer_
->DoPostCommitInitializationIfNeeded();
2192 // The active tree invalidation was handled by the active tiles, so they
2193 // can be shared with the pending tree.
2194 EXPECT_EQ(3u, active_layer_
->num_tilings());
2195 EXPECT_EQ(3u, pending_layer_
->num_tilings());
2196 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
2197 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(i
);
2198 PictureLayerTiling
* pending_tiling
=
2199 pending_layer_
->tilings()->tiling_at(i
);
2201 ASSERT_TRUE(active_tiling
);
2202 ASSERT_TRUE(pending_tiling
);
2204 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2205 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2206 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2207 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2209 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2210 EXPECT_TRUE(pending_tiling
->TileAt(1, 0));
2211 EXPECT_TRUE(pending_tiling
->TileAt(0, 1));
2212 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2214 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2215 EXPECT_TRUE(active_tiling
->TileAt(0, 0)->is_shared());
2216 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2217 EXPECT_TRUE(active_tiling
->TileAt(1, 0)->is_shared());
2218 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2219 EXPECT_TRUE(active_tiling
->TileAt(0, 1)->is_shared());
2220 EXPECT_EQ(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2221 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2225 TEST_F(PictureLayerImplTest
, RemoveInvalidPendingTreeTilesOnSync
) {
2226 SetupDefaultTrees(gfx::Size(1500, 1500));
2227 AddDefaultTilingsWithInvalidation(gfx::Rect());
2229 host_impl_
.ActivateSyncTree();
2230 host_impl_
.CreatePendingTree();
2231 active_layer_
= static_cast<FakePictureLayerImpl
*>(
2232 host_impl_
.active_tree()->LayerById(id_
));
2234 // Set some invalidation on the pending tree "during commit". We should
2235 // replace raster tiles that touch this.
2236 pending_layer_
->set_invalidation(gfx::Rect(1, 1));
2238 // Force the active tree to sync to the pending tree "post-commit".
2239 pending_layer_
->DoPostCommitInitializationIfNeeded();
2241 // The pending tree invalidation means tiles can not be shared with the
2243 EXPECT_EQ(3u, active_layer_
->num_tilings());
2244 EXPECT_EQ(3u, pending_layer_
->num_tilings());
2245 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
2246 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(i
);
2247 PictureLayerTiling
* pending_tiling
=
2248 pending_layer_
->tilings()->tiling_at(i
);
2250 ASSERT_TRUE(active_tiling
);
2251 ASSERT_TRUE(pending_tiling
);
2253 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2254 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2255 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2256 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2258 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2259 EXPECT_TRUE(pending_tiling
->TileAt(1, 0));
2260 EXPECT_TRUE(pending_tiling
->TileAt(0, 1));
2261 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2263 EXPECT_NE(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2264 EXPECT_FALSE(active_tiling
->TileAt(0, 0)->is_shared());
2265 EXPECT_FALSE(pending_tiling
->TileAt(0, 0)->is_shared());
2266 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2267 EXPECT_TRUE(active_tiling
->TileAt(1, 0)->is_shared());
2268 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2269 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2270 EXPECT_EQ(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2271 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2275 TEST_F(PictureLayerImplTest
, SyncTilingAfterReleaseResource
) {
2276 SetupDefaultTrees(gfx::Size(10, 10));
2277 host_impl_
.active_tree()->UpdateDrawProperties();
2278 EXPECT_FALSE(host_impl_
.active_tree()->needs_update_draw_properties());
2280 // Contrived unit test of a real crash. A layer is transparent during a
2281 // context loss, and later becomes opaque, causing active layer SyncTiling to
2283 float new_scale
= 1.f
;
2284 active_layer_
->ReleaseResources();
2285 pending_layer_
->ReleaseResources();
2286 EXPECT_FALSE(active_layer_
->tilings()->FindTilingWithScale(new_scale
));
2287 pending_layer_
->AddTiling(new_scale
);
2288 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(new_scale
));
2290 // UpdateDrawProperties early-outs if the tree doesn't need it. It is also
2291 // responsible for calling ManageTilings. These checks verify that
2292 // ReleaseResources has set needs update draw properties so that the
2293 // new tiling gets the appropriate resolution set in ManageTilings.
2294 EXPECT_TRUE(host_impl_
.active_tree()->needs_update_draw_properties());
2295 host_impl_
.active_tree()->UpdateDrawProperties();
2296 PictureLayerTiling
* high_res
=
2297 active_layer_
->tilings()->FindTilingWithScale(new_scale
);
2298 ASSERT_TRUE(!!high_res
);
2299 EXPECT_EQ(HIGH_RESOLUTION
, high_res
->resolution());
2302 TEST_F(PictureLayerImplTest
, SyncTilingAfterGpuRasterizationToggles
) {
2303 SetupDefaultTrees(gfx::Size(10, 10));
2305 const float kScale
= 1.f
;
2306 pending_layer_
->AddTiling(kScale
);
2307 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(kScale
));
2308 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(kScale
));
2310 // Gpu rasterization is disabled by default.
2311 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2312 // Toggling the gpu rasterization clears all tilings on both trees.
2313 host_impl_
.SetUseGpuRasterization(true);
2314 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2315 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2317 // Make sure that we can still add tiling to the pending layer,
2318 // that gets synced to the active layer.
2319 pending_layer_
->AddTiling(kScale
);
2320 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(kScale
));
2321 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(kScale
));
2323 // Toggling the gpu rasterization clears all tilings on both trees.
2324 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2325 host_impl_
.SetUseGpuRasterization(false);
2326 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2327 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2330 TEST_F(PictureLayerImplTest
, HighResCreatedWhenBoundsShrink
) {
2331 gfx::Size
tile_size(100, 100);
2333 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2334 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(10, 10));
2335 SetupPendingTree(active_pile
);
2337 host_impl_
.active_tree()->UpdateDrawProperties();
2338 EXPECT_FALSE(host_impl_
.active_tree()->needs_update_draw_properties());
2340 SetupDrawPropertiesAndUpdateTiles(
2341 active_layer_
, 0.5f
, 0.5f
, 0.5f
, 0.5f
, false);
2342 active_layer_
->tilings()->RemoveAllTilings();
2343 PictureLayerTiling
* tiling
= active_layer_
->AddTiling(0.5f
);
2344 active_layer_
->AddTiling(1.5f
);
2345 active_layer_
->AddTiling(0.25f
);
2346 tiling
->set_resolution(HIGH_RESOLUTION
);
2349 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
2350 ASSERT_EQ(tiling
, active_layer_
->tilings()->FindTilingWithScale(0.5f
));
2352 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes
2353 // 1.0f). Note that we should also ensure that the pending layer needs post
2354 // commit initialization, since this is what would happen during commit. In
2355 // other words we want the pending layer to sync from the active layer.
2356 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2357 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(1, 1));
2358 SetupPendingTree(pending_pile
);
2360 // Update the draw properties: sync from active tree should happen here.
2361 host_impl_
.pending_tree()->UpdateDrawProperties();
2362 EXPECT_FALSE(pending_layer_
->needs_post_commit_initialization());
2364 // Another sanity check.
2365 ASSERT_EQ(1.f
, pending_layer_
->MinimumContentsScale());
2367 // Now we should've synced 1.5f tiling, since that's the only one that doesn't
2368 // violate minimum contents scale. At the same time, we should've created a
2369 // new high res tiling at scale 1.0f.
2370 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
2371 ASSERT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.0f
));
2372 EXPECT_EQ(HIGH_RESOLUTION
,
2373 pending_layer_
->tilings()->FindTilingWithScale(1.0f
)->resolution());
2374 ASSERT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.5f
));
2375 EXPECT_EQ(NON_IDEAL_RESOLUTION
,
2376 pending_layer_
->tilings()->FindTilingWithScale(1.5f
)->resolution());
2379 TEST_F(PictureLayerImplTest
, NoLowResTilingWithGpuRasterization
) {
2380 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
2381 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
2382 default_tile_size
.height() * 4);
2384 SetupDefaultTrees(layer_bounds
);
2385 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2386 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2387 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
2388 // Should have a low-res and a high-res tiling.
2389 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
2391 ResetTilingsAndRasterScales();
2393 host_impl_
.SetUseGpuRasterization(true);
2394 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2395 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
2397 // Should only have the high-res tiling.
2398 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2401 TEST_F(PictureLayerImplTest
, NoTilingIfDoesNotDrawContent
) {
2402 // Set up layers with tilings.
2403 SetupDefaultTrees(gfx::Size(10, 10));
2404 SetContentsScaleOnBothLayers(1.f
, 1.f
, 1.f
, 1.f
, false);
2405 pending_layer_
->PushPropertiesTo(active_layer_
);
2406 EXPECT_TRUE(pending_layer_
->DrawsContent());
2407 EXPECT_TRUE(pending_layer_
->CanHaveTilings());
2408 EXPECT_GE(pending_layer_
->num_tilings(), 0u);
2409 EXPECT_GE(active_layer_
->num_tilings(), 0u);
2411 // Set content to false, which should make CanHaveTilings return false.
2412 pending_layer_
->SetDrawsContent(false);
2413 EXPECT_FALSE(pending_layer_
->DrawsContent());
2414 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
2416 // No tilings should be pushed to active layer.
2417 pending_layer_
->PushPropertiesTo(active_layer_
);
2418 EXPECT_EQ(0u, active_layer_
->num_tilings());
2421 TEST_F(PictureLayerImplTest
, FirstTilingDuringPinch
) {
2422 SetupDefaultTrees(gfx::Size(10, 10));
2423 host_impl_
.PinchGestureBegin();
2424 float high_res_scale
= 2.3f
;
2425 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, 1.f
, 1.f
, false);
2427 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2428 EXPECT_FLOAT_EQ(high_res_scale
,
2429 pending_layer_
->HighResTiling()->contents_scale());
2432 TEST_F(PictureLayerImplTest
, FirstTilingTooSmall
) {
2433 SetupDefaultTrees(gfx::Size(10, 10));
2434 host_impl_
.PinchGestureBegin();
2435 float high_res_scale
= 0.0001f
;
2436 EXPECT_GT(pending_layer_
->MinimumContentsScale(), high_res_scale
);
2438 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, 1.f
, 1.f
, false);
2440 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2441 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2442 pending_layer_
->HighResTiling()->contents_scale());
2445 TEST_F(PictureLayerImplTest
, PinchingTooSmall
) {
2446 SetupDefaultTrees(gfx::Size(10, 10));
2448 float contents_scale
= 0.15f
;
2449 SetContentsScaleOnBothLayers(contents_scale
, 1.f
, 1.f
, 1.f
, false);
2451 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2452 EXPECT_FLOAT_EQ(contents_scale
,
2453 pending_layer_
->HighResTiling()->contents_scale());
2455 host_impl_
.PinchGestureBegin();
2457 float page_scale
= 0.0001f
;
2458 EXPECT_LT(page_scale
* contents_scale
,
2459 pending_layer_
->MinimumContentsScale());
2461 SetContentsScaleOnBothLayers(contents_scale
* page_scale
, 1.f
, page_scale
,
2463 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2464 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2465 pending_layer_
->HighResTiling()->contents_scale());
2468 class DeferredInitPictureLayerImplTest
: public PictureLayerImplTest
{
2470 void InitializeRenderer() override
{
2471 bool delegated_rendering
= false;
2472 host_impl_
.InitializeRenderer(FakeOutputSurface::CreateDeferredGL(
2473 scoped_ptr
<SoftwareOutputDevice
>(new SoftwareOutputDevice
),
2474 delegated_rendering
));
2477 void SetUp() override
{
2478 PictureLayerImplTest::SetUp();
2480 // Create some default active and pending trees.
2481 gfx::Size
tile_size(100, 100);
2482 gfx::Size
layer_bounds(400, 400);
2484 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2485 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2486 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2487 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2489 SetupTrees(pending_pile
, active_pile
);
2493 // This test is really a LayerTreeHostImpl test, in that it makes sure
2494 // that trees need update draw properties after deferred initialization.
2495 // However, this is also a regression test for PictureLayerImpl in that
2496 // not having this update will cause a crash.
2497 TEST_F(DeferredInitPictureLayerImplTest
, PreventUpdateTilesDuringLostContext
) {
2498 host_impl_
.pending_tree()->UpdateDrawProperties();
2499 host_impl_
.active_tree()->UpdateDrawProperties();
2500 EXPECT_FALSE(host_impl_
.pending_tree()->needs_update_draw_properties());
2501 EXPECT_FALSE(host_impl_
.active_tree()->needs_update_draw_properties());
2503 FakeOutputSurface
* fake_output_surface
=
2504 static_cast<FakeOutputSurface
*>(host_impl_
.output_surface());
2505 ASSERT_TRUE(fake_output_surface
->InitializeAndSetContext3d(
2506 TestContextProvider::Create()));
2508 // These will crash PictureLayerImpl if this is not true.
2509 ASSERT_TRUE(host_impl_
.pending_tree()->needs_update_draw_properties());
2510 ASSERT_TRUE(host_impl_
.active_tree()->needs_update_draw_properties());
2511 host_impl_
.active_tree()->UpdateDrawProperties();
2514 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForCpuRasterization
) {
2515 gfx::Size
layer_bounds(100, 100);
2516 gfx::Size
viewport_size(1000, 1000);
2517 SetupDefaultTrees(layer_bounds
);
2518 host_impl_
.SetViewportSize(viewport_size
);
2520 float contents_scale
= 1.f
;
2521 float device_scale
= 1.3f
;
2522 float page_scale
= 1.4f
;
2523 float maximum_animation_scale
= 1.f
;
2524 bool animating_transform
= false;
2526 SetContentsScaleOnBothLayers(contents_scale
,
2529 maximum_animation_scale
,
2530 animating_transform
);
2531 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2533 // Since we're CPU-rasterizing, starting an animation should cause tiling
2534 // resolution to get set to the maximum animation scale factor.
2535 animating_transform
= true;
2536 maximum_animation_scale
= 3.f
;
2537 contents_scale
= 2.f
;
2539 SetContentsScaleOnBothLayers(contents_scale
,
2542 maximum_animation_scale
,
2543 animating_transform
);
2544 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2546 // Further changes to scale during the animation should not cause a new
2547 // high-res tiling to get created.
2548 contents_scale
= 4.f
;
2549 maximum_animation_scale
= 5.f
;
2551 SetContentsScaleOnBothLayers(contents_scale
,
2554 maximum_animation_scale
,
2555 animating_transform
);
2556 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2558 // Once we stop animating, a new high-res tiling should be created.
2559 animating_transform
= false;
2561 SetContentsScaleOnBothLayers(contents_scale
,
2564 maximum_animation_scale
,
2565 animating_transform
);
2566 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2568 // When animating with an unknown maximum animation scale factor, a new
2569 // high-res tiling should be created at a source scale of 1.
2570 animating_transform
= true;
2571 contents_scale
= 2.f
;
2572 maximum_animation_scale
= 0.f
;
2574 SetContentsScaleOnBothLayers(contents_scale
,
2577 maximum_animation_scale
,
2578 animating_transform
);
2579 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2581 // Further changes to scale during the animation should not cause a new
2582 // high-res tiling to get created.
2583 contents_scale
= 3.f
;
2585 SetContentsScaleOnBothLayers(contents_scale
,
2588 maximum_animation_scale
,
2589 animating_transform
);
2590 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2592 // Once we stop animating, a new high-res tiling should be created.
2593 animating_transform
= false;
2594 contents_scale
= 4.f
;
2596 SetContentsScaleOnBothLayers(contents_scale
,
2599 maximum_animation_scale
,
2600 animating_transform
);
2601 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2603 // When animating with a maxmium animation scale factor that is so large
2604 // that the layer grows larger than the viewport at this scale, a new
2605 // high-res tiling should get created at a source scale of 1, not at its
2607 animating_transform
= true;
2608 contents_scale
= 2.f
;
2609 maximum_animation_scale
= 11.f
;
2611 SetContentsScaleOnBothLayers(contents_scale
,
2614 maximum_animation_scale
,
2615 animating_transform
);
2616 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2618 // Once we stop animating, a new high-res tiling should be created.
2619 animating_transform
= false;
2620 contents_scale
= 11.f
;
2622 SetContentsScaleOnBothLayers(contents_scale
,
2625 maximum_animation_scale
,
2626 animating_transform
);
2627 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2629 // When animating with a maxmium animation scale factor that is so large
2630 // that the layer grows larger than the viewport at this scale, and where
2631 // the intial source scale is < 1, a new high-res tiling should get created
2632 // at source scale 1.
2633 animating_transform
= true;
2634 contents_scale
= 0.1f
;
2635 maximum_animation_scale
= 11.f
;
2637 SetContentsScaleOnBothLayers(contents_scale
,
2640 maximum_animation_scale
,
2641 animating_transform
);
2642 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2644 // Once we stop animating, a new high-res tiling should be created.
2645 animating_transform
= false;
2646 contents_scale
= 12.f
;
2648 SetContentsScaleOnBothLayers(contents_scale
,
2651 maximum_animation_scale
,
2652 animating_transform
);
2653 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 12.f
);
2655 // When animating toward a smaller scale, but that is still so large that the
2656 // layer grows larger than the viewport at this scale, a new high-res tiling
2657 // should get created at source scale 1.
2658 animating_transform
= true;
2659 contents_scale
= 11.f
;
2660 maximum_animation_scale
= 11.f
;
2662 SetContentsScaleOnBothLayers(contents_scale
,
2665 maximum_animation_scale
,
2666 animating_transform
);
2667 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2669 // Once we stop animating, a new high-res tiling should be created.
2670 animating_transform
= false;
2671 contents_scale
= 11.f
;
2673 SetContentsScaleOnBothLayers(contents_scale
,
2676 maximum_animation_scale
,
2677 animating_transform
);
2678 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2681 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForGpuRasterization
) {
2682 gfx::Size
layer_bounds(100, 100);
2683 gfx::Size
viewport_size(1000, 1000);
2684 SetupDefaultTrees(layer_bounds
);
2685 host_impl_
.SetViewportSize(viewport_size
);
2686 host_impl_
.SetUseGpuRasterization(true);
2688 float contents_scale
= 1.f
;
2689 float device_scale
= 1.3f
;
2690 float page_scale
= 1.4f
;
2691 float maximum_animation_scale
= 1.f
;
2692 bool animating_transform
= false;
2694 SetContentsScaleOnBothLayers(contents_scale
,
2697 maximum_animation_scale
,
2698 animating_transform
);
2699 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2701 // Since we're GPU-rasterizing, starting an animation should cause tiling
2702 // resolution to get set to the current contents scale.
2703 animating_transform
= true;
2704 contents_scale
= 2.f
;
2705 maximum_animation_scale
= 4.f
;
2707 SetContentsScaleOnBothLayers(contents_scale
,
2710 maximum_animation_scale
,
2711 animating_transform
);
2712 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2714 // Further changes to scale during the animation should cause a new high-res
2715 // tiling to get created.
2716 contents_scale
= 3.f
;
2718 SetContentsScaleOnBothLayers(contents_scale
,
2721 maximum_animation_scale
,
2722 animating_transform
);
2723 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2725 // Since we're re-rasterizing during the animation, scales smaller than 1
2726 // should be respected.
2727 contents_scale
= 0.25f
;
2729 SetContentsScaleOnBothLayers(contents_scale
,
2732 maximum_animation_scale
,
2733 animating_transform
);
2734 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.25f
);
2736 // Once we stop animating, a new high-res tiling should be created.
2737 contents_scale
= 4.f
;
2738 animating_transform
= false;
2740 SetContentsScaleOnBothLayers(contents_scale
,
2743 maximum_animation_scale
,
2744 animating_transform
);
2745 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2748 TEST_F(PictureLayerImplTest
, LayerRasterTileIterator
) {
2749 base::TimeTicks time_ticks
;
2750 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
2751 host_impl_
.SetCurrentBeginFrameArgs(
2752 CreateBeginFrameArgsForTesting(time_ticks
));
2754 gfx::Size
tile_size(100, 100);
2755 gfx::Size
layer_bounds(1000, 1000);
2757 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2758 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2760 SetupPendingTree(pending_pile
);
2762 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
2764 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
2767 PictureLayerImpl::LayerRasterTileIterator it
;
2771 it
= PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
2774 pending_layer_
->AddTiling(low_res_factor
);
2775 pending_layer_
->AddTiling(0.3f
);
2776 pending_layer_
->AddTiling(0.7f
);
2777 PictureLayerTiling
* high_res_tiling
= pending_layer_
->AddTiling(1.0f
);
2778 pending_layer_
->AddTiling(2.0f
);
2780 host_impl_
.SetViewportSize(gfx::Size(500, 500));
2781 host_impl_
.pending_tree()->UpdateDrawProperties();
2783 std::set
<Tile
*> unique_tiles
;
2784 bool reached_prepaint
= false;
2785 size_t non_ideal_tile_count
= 0u;
2786 size_t low_res_tile_count
= 0u;
2787 size_t high_res_tile_count
= 0u;
2788 for (it
= PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
2792 TilePriority priority
= tile
->priority(PENDING_TREE
);
2796 // Non-high res tiles only get visible tiles. Also, prepaint should only
2797 // come at the end of the iteration.
2798 if (priority
.resolution
!= HIGH_RESOLUTION
)
2799 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
2800 else if (reached_prepaint
)
2801 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
2803 reached_prepaint
= priority
.priority_bin
!= TilePriority::NOW
;
2805 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
2806 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
2807 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2809 unique_tiles
.insert(tile
);
2812 EXPECT_TRUE(reached_prepaint
);
2813 EXPECT_EQ(0u, non_ideal_tile_count
);
2814 EXPECT_EQ(0u, low_res_tile_count
);
2815 EXPECT_EQ(16u, high_res_tile_count
);
2816 EXPECT_EQ(low_res_tile_count
+ high_res_tile_count
+ non_ideal_tile_count
,
2817 unique_tiles
.size());
2820 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
2821 host_impl_
.SetCurrentBeginFrameArgs(
2822 CreateBeginFrameArgsForTesting(time_ticks
));
2824 pending_layer_
->draw_properties().visible_content_rect
=
2825 gfx::Rect(1100, 1100, 500, 500);
2826 bool resourceless_software_draw
= false;
2827 pending_layer_
->UpdateTiles(Occlusion(), resourceless_software_draw
);
2829 unique_tiles
.clear();
2830 high_res_tile_count
= 0u;
2831 for (it
= PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
2835 TilePriority priority
= tile
->priority(PENDING_TREE
);
2839 // Non-high res tiles only get visible tiles.
2840 EXPECT_EQ(HIGH_RESOLUTION
, priority
.resolution
);
2841 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
2843 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2845 unique_tiles
.insert(tile
);
2848 EXPECT_EQ(16u, high_res_tile_count
);
2849 EXPECT_EQ(high_res_tile_count
, unique_tiles
.size());
2851 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
2852 host_impl_
.SetCurrentBeginFrameArgs(
2853 CreateBeginFrameArgsForTesting(time_ticks
));
2855 pending_layer_
->draw_properties().visible_content_rect
=
2856 gfx::Rect(0, 0, 500, 500);
2857 pending_layer_
->UpdateTiles(Occlusion(), resourceless_software_draw
);
2859 std::vector
<Tile
*> high_res_tiles
= high_res_tiling
->AllTilesForTesting();
2860 for (std::vector
<Tile
*>::iterator tile_it
= high_res_tiles
.begin();
2861 tile_it
!= high_res_tiles
.end();
2863 Tile
* tile
= *tile_it
;
2864 ManagedTileState::DrawInfo
& draw_info
= tile
->draw_info();
2865 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
2868 non_ideal_tile_count
= 0;
2869 low_res_tile_count
= 0;
2870 high_res_tile_count
= 0;
2871 for (it
= PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, true); it
;
2874 TilePriority priority
= tile
->priority(PENDING_TREE
);
2878 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
2879 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
2880 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2883 EXPECT_EQ(0u, non_ideal_tile_count
);
2884 EXPECT_EQ(1u, low_res_tile_count
);
2885 EXPECT_EQ(0u, high_res_tile_count
);
2888 TEST_F(PictureLayerImplTest
, LayerEvictionTileIterator
) {
2889 gfx::Size
tile_size(100, 100);
2890 gfx::Size
layer_bounds(1000, 1000);
2892 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2893 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2895 SetupPendingTree(pending_pile
);
2897 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
2899 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
2901 std::vector
<PictureLayerTiling
*> tilings
;
2902 tilings
.push_back(pending_layer_
->AddTiling(low_res_factor
));
2903 tilings
.push_back(pending_layer_
->AddTiling(0.3f
));
2904 tilings
.push_back(pending_layer_
->AddTiling(0.7f
));
2905 tilings
.push_back(pending_layer_
->AddTiling(1.0f
));
2906 tilings
.push_back(pending_layer_
->AddTiling(2.0f
));
2908 host_impl_
.SetViewportSize(gfx::Size(500, 500));
2909 host_impl_
.pending_tree()->UpdateDrawProperties();
2911 std::vector
<Tile
*> all_tiles
;
2912 for (std::vector
<PictureLayerTiling
*>::iterator tiling_iterator
=
2914 tiling_iterator
!= tilings
.end();
2915 ++tiling_iterator
) {
2916 std::vector
<Tile
*> tiles
= (*tiling_iterator
)->AllTilesForTesting();
2917 std::copy(tiles
.begin(), tiles
.end(), std::back_inserter(all_tiles
));
2920 std::set
<Tile
*> all_tiles_set(all_tiles
.begin(), all_tiles
.end());
2922 bool mark_required
= false;
2923 size_t number_of_marked_tiles
= 0u;
2924 size_t number_of_unmarked_tiles
= 0u;
2925 for (size_t i
= 0; i
< tilings
.size(); ++i
) {
2926 PictureLayerTiling
* tiling
= tilings
.at(i
);
2927 for (PictureLayerTiling::CoverageIterator
iter(
2929 pending_layer_
->contents_scale_x(),
2930 pending_layer_
->visible_content_rect());
2933 if (mark_required
) {
2934 number_of_marked_tiles
++;
2935 iter
->set_required_for_activation(true);
2937 number_of_unmarked_tiles
++;
2939 mark_required
= !mark_required
;
2944 EXPECT_EQ(91u, all_tiles
.size());
2945 EXPECT_EQ(91u, all_tiles_set
.size());
2946 EXPECT_GT(number_of_marked_tiles
, 1u);
2947 EXPECT_GT(number_of_unmarked_tiles
, 1u);
2950 PictureLayerImpl::LayerEvictionTileIterator it
;
2953 // Tiles don't have resources yet.
2954 it
= PictureLayerImpl::LayerEvictionTileIterator(
2955 pending_layer_
, SAME_PRIORITY_FOR_BOTH_TREES
);
2958 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
2960 std::set
<Tile
*> unique_tiles
;
2961 float expected_scales
[] = {2.0f
, 0.3f
, 0.7f
, low_res_factor
, 1.0f
};
2962 size_t scale_index
= 0;
2963 bool reached_visible
= false;
2964 Tile
* last_tile
= nullptr;
2965 for (it
= PictureLayerImpl::LayerEvictionTileIterator(
2966 pending_layer_
, SAME_PRIORITY_FOR_BOTH_TREES
);
2975 TilePriority priority
= tile
->priority(PENDING_TREE
);
2977 if (priority
.priority_bin
== TilePriority::NOW
) {
2978 reached_visible
= true;
2983 EXPECT_FALSE(tile
->required_for_activation());
2985 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
2986 std::numeric_limits
<float>::epsilon()) {
2988 ASSERT_LT(scale_index
, arraysize(expected_scales
));
2991 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
2992 unique_tiles
.insert(tile
);
2994 // If the tile is the same rough bin as last tile (same activation, bin, and
2995 // scale), then distance should be decreasing.
2996 if (tile
->required_for_activation() ==
2997 last_tile
->required_for_activation() &&
2998 priority
.priority_bin
==
2999 last_tile
->priority(PENDING_TREE
).priority_bin
&&
3000 std::abs(tile
->contents_scale() - last_tile
->contents_scale()) <
3001 std::numeric_limits
<float>::epsilon()) {
3002 EXPECT_LE(priority
.distance_to_visible
,
3003 last_tile
->priority(PENDING_TREE
).distance_to_visible
);
3009 EXPECT_TRUE(reached_visible
);
3010 EXPECT_EQ(65u, unique_tiles
.size());
3013 bool reached_required
= false;
3018 TilePriority priority
= tile
->priority(PENDING_TREE
);
3019 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
3021 if (reached_required
) {
3022 EXPECT_TRUE(tile
->required_for_activation());
3023 } else if (tile
->required_for_activation()) {
3024 reached_required
= true;
3028 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
3029 std::numeric_limits
<float>::epsilon()) {
3031 ASSERT_LT(scale_index
, arraysize(expected_scales
));
3034 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
3035 unique_tiles
.insert(tile
);
3038 EXPECT_TRUE(reached_required
);
3039 EXPECT_EQ(all_tiles_set
.size(), unique_tiles
.size());
3042 TEST_F(PictureLayerImplTest
, Occlusion
) {
3043 gfx::Size
tile_size(102, 102);
3044 gfx::Size
layer_bounds(1000, 1000);
3045 gfx::Size
viewport_size(1000, 1000);
3047 LayerTestCommon::LayerImplTest impl
;
3049 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3050 FakePicturePileImpl::CreateFilledPile(layer_bounds
, layer_bounds
);
3051 SetupPendingTree(pending_pile
);
3052 pending_layer_
->SetBounds(layer_bounds
);
3054 active_layer_
->set_fixed_tile_size(tile_size
);
3056 host_impl_
.SetViewportSize(viewport_size
);
3057 host_impl_
.active_tree()->UpdateDrawProperties();
3059 std::vector
<Tile
*> tiles
=
3060 active_layer_
->HighResTiling()->AllTilesForTesting();
3061 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3064 SCOPED_TRACE("No occlusion");
3066 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3068 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
3069 gfx::Rect(layer_bounds
));
3070 EXPECT_EQ(100u, impl
.quad_list().size());
3074 SCOPED_TRACE("Full occlusion");
3075 gfx::Rect
occluded(active_layer_
->visible_content_rect());
3076 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3078 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(), gfx::Rect());
3079 EXPECT_EQ(impl
.quad_list().size(), 0u);
3083 SCOPED_TRACE("Partial occlusion");
3084 gfx::Rect
occluded(150, 0, 200, 1000);
3085 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3087 size_t partially_occluded_count
= 0;
3088 LayerTestCommon::VerifyQuadsAreOccluded(
3089 impl
.quad_list(), occluded
, &partially_occluded_count
);
3090 // The layer outputs one quad, which is partially occluded.
3091 EXPECT_EQ(100u - 10u, impl
.quad_list().size());
3092 EXPECT_EQ(10u + 10u, partially_occluded_count
);
3096 TEST_F(PictureLayerImplTest
, RasterScaleChangeWithoutAnimation
) {
3097 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
3098 SetupDefaultTrees(tile_size
);
3100 float contents_scale
= 2.f
;
3101 float device_scale
= 1.f
;
3102 float page_scale
= 1.f
;
3103 float maximum_animation_scale
= 1.f
;
3104 bool animating_transform
= false;
3106 SetContentsScaleOnBothLayers(contents_scale
,
3109 maximum_animation_scale
,
3110 animating_transform
);
3111 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
3113 // Changing the source scale without being in an animation will cause
3114 // the layer to reset its source scale to 1.f.
3115 contents_scale
= 3.f
;
3117 SetContentsScaleOnBothLayers(contents_scale
,
3120 maximum_animation_scale
,
3121 animating_transform
);
3122 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3124 // Further changes to the source scale will no longer be reflected in the
3126 contents_scale
= 0.5f
;
3128 SetContentsScaleOnBothLayers(contents_scale
,
3131 maximum_animation_scale
,
3132 animating_transform
);
3133 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3136 TEST_F(PictureLayerImplTest
, LowResReadyToDrawNotEnoughToActivate
) {
3137 gfx::Size
tile_size(100, 100);
3138 gfx::Size
layer_bounds(1000, 1000);
3140 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
3142 // Make sure some tiles are not shared.
3143 pending_layer_
->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size
));
3145 CreateHighLowResAndSetAllTilesVisible();
3146 active_layer_
->SetAllTilesReady();
3148 // All pending layer tiles required are not ready.
3149 EXPECT_FALSE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
3151 // Initialize all low-res tiles.
3152 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3154 // Low-res tiles should not be enough.
3155 EXPECT_FALSE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
3157 // Initialize remaining tiles.
3158 pending_layer_
->SetAllTilesReady();
3160 EXPECT_TRUE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
3163 TEST_F(PictureLayerImplTest
, HighResReadyToDrawEnoughToActivate
) {
3164 gfx::Size
tile_size(100, 100);
3165 gfx::Size
layer_bounds(1000, 1000);
3167 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
3169 // Make sure some tiles are not shared.
3170 pending_layer_
->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size
));
3172 CreateHighLowResAndSetAllTilesVisible();
3173 active_layer_
->SetAllTilesReady();
3175 // All pending layer tiles required are not ready.
3176 EXPECT_FALSE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
3178 // Initialize all high-res tiles.
3179 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3181 // High-res tiles should be enough, since they cover everything visible.
3182 EXPECT_TRUE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
3185 TEST_F(PictureLayerImplTest
,
3186 SharedActiveHighResReadyAndPendingLowResReadyNotEnoughToActivate
) {
3187 gfx::Size
tile_size(100, 100);
3188 gfx::Size
layer_bounds(1000, 1000);
3190 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
3192 // Make sure some tiles are not shared.
3193 pending_layer_
->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size
));
3195 CreateHighLowResAndSetAllTilesVisible();
3197 // Initialize all high-res tiles in the active layer.
3198 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3199 // And all the low-res tiles in the pending layer.
3200 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3202 // The unshared high-res tiles are not ready, so we cannot activate.
3203 EXPECT_FALSE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
3205 // When the unshared pending high-res tiles are ready, we can activate.
3206 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3207 EXPECT_TRUE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
3210 TEST_F(PictureLayerImplTest
, SharedActiveHighResReadyNotEnoughToActivate
) {
3211 gfx::Size
tile_size(100, 100);
3212 gfx::Size
layer_bounds(1000, 1000);
3214 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
3216 // Make sure some tiles are not shared.
3217 pending_layer_
->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size
));
3219 CreateHighLowResAndSetAllTilesVisible();
3221 // Initialize all high-res tiles in the active layer.
3222 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3224 // The unshared high-res tiles are not ready, so we cannot activate.
3225 EXPECT_FALSE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
3227 // When the unshared pending high-res tiles are ready, we can activate.
3228 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3229 EXPECT_TRUE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
3232 class NoLowResPictureLayerImplTest
: public PictureLayerImplTest
{
3234 NoLowResPictureLayerImplTest()
3235 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
3238 TEST_F(NoLowResPictureLayerImplTest
, ManageTilingsCreatesTilings
) {
3239 gfx::Size
tile_size(400, 400);
3240 gfx::Size
layer_bounds(1300, 1900);
3242 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3243 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3244 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3245 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3247 SetupTrees(pending_pile
, active_pile
);
3248 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
3250 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3251 EXPECT_LT(low_res_factor
, 1.f
);
3253 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3254 6.f
, // ideal contents scale
3255 3.f
, // device scale
3257 1.f
, // maximum animation scale
3259 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3260 EXPECT_FLOAT_EQ(6.f
,
3261 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3263 // If we change the page scale factor, then we should get new tilings.
3264 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3265 6.6f
, // ideal contents scale
3266 3.f
, // device scale
3268 1.f
, // maximum animation scale
3270 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
3271 EXPECT_FLOAT_EQ(6.6f
,
3272 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3274 // If we change the device scale factor, then we should get new tilings.
3275 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3276 7.26f
, // ideal contents scale
3277 3.3f
, // device scale
3279 1.f
, // maximum animation scale
3281 ASSERT_EQ(3u, pending_layer_
->tilings()->num_tilings());
3282 EXPECT_FLOAT_EQ(7.26f
,
3283 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3285 // If we change the device scale factor, but end up at the same total scale
3286 // factor somehow, then we don't get new tilings.
3287 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3288 7.26f
, // ideal contents scale
3289 2.2f
, // device scale
3291 1.f
, // maximum animation scale
3293 ASSERT_EQ(3u, pending_layer_
->tilings()->num_tilings());
3294 EXPECT_FLOAT_EQ(7.26f
,
3295 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3298 TEST_F(NoLowResPictureLayerImplTest
, AllHighResRequiredEvenIfShared
) {
3299 gfx::Size
layer_bounds(400, 400);
3300 gfx::Size
tile_size(100, 100);
3301 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
);
3303 CreateHighLowResAndSetAllTilesVisible();
3305 Tile
* some_active_tile
=
3306 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
3307 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
3309 // All tiles shared (no invalidation), so even though the active tree's
3310 // tiles aren't ready, there is nothing required.
3311 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
3312 if (host_impl_
.settings().create_low_res_tiling
)
3313 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
3315 AssertAllTilesRequired(pending_layer_
->HighResTiling());
3316 if (host_impl_
.settings().create_low_res_tiling
)
3317 AssertNoTilesRequired(pending_layer_
->LowResTiling());
3320 TEST_F(NoLowResPictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
3321 gfx::Size
layer_bounds(400, 400);
3322 gfx::Size
tile_size(100, 100);
3323 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3324 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3325 // This pile will create tilings, but has no recordings so will not create any
3326 // tiles. This is attempting to simulate scrolling past the end of recorded
3327 // content on the active layer, where the recordings are so far away that
3328 // no tiles are created.
3329 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3330 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
3331 tile_size
, layer_bounds
);
3332 SetupTrees(pending_pile
, active_pile
);
3333 pending_layer_
->set_fixed_tile_size(tile_size
);
3334 active_layer_
->set_fixed_tile_size(tile_size
);
3336 CreateHighLowResAndSetAllTilesVisible();
3338 // Active layer has tilings, but no tiles due to missing recordings.
3339 EXPECT_TRUE(active_layer_
->CanHaveTilings());
3340 EXPECT_EQ(active_layer_
->tilings()->num_tilings(),
3341 host_impl_
.settings().create_low_res_tiling
? 2u : 1u);
3342 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
3344 // Since the active layer has no tiles at all, the pending layer doesn't
3345 // need content in order to activate.
3346 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
3347 if (host_impl_
.settings().create_low_res_tiling
)
3348 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
3350 AssertNoTilesRequired(pending_layer_
->HighResTiling());
3351 if (host_impl_
.settings().create_low_res_tiling
)
3352 AssertNoTilesRequired(pending_layer_
->LowResTiling());
3355 TEST_F(NoLowResPictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
3356 base::TimeTicks time_ticks
;
3357 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
3358 host_impl_
.SetCurrentBeginFrameArgs(
3359 CreateBeginFrameArgsForTesting(time_ticks
));
3361 gfx::Size
tile_size(100, 100);
3362 gfx::Size
layer_bounds(400, 400);
3364 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3365 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3366 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3367 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3369 SetupTrees(pending_pile
, active_pile
);
3371 Region invalidation
;
3372 AddDefaultTilingsWithInvalidation(invalidation
);
3373 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
3375 // UpdateTiles with valid viewport. Should update tile viewport.
3376 // Note viewport is considered invalid if and only if in resourceless
3378 bool resourceless_software_draw
= false;
3379 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
3380 gfx::Transform transform
;
3381 host_impl_
.SetExternalDrawConstraints(transform
,
3386 resourceless_software_draw
);
3387 active_layer_
->draw_properties().visible_content_rect
= viewport
;
3388 active_layer_
->draw_properties().screen_space_transform
= transform
;
3389 active_layer_
->UpdateTiles(Occlusion(), resourceless_software_draw
);
3391 gfx::Rect visible_rect_for_tile_priority
=
3392 active_layer_
->visible_rect_for_tile_priority();
3393 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
3394 gfx::Transform screen_space_transform_for_tile_priority
=
3395 active_layer_
->screen_space_transform();
3397 // Expand viewport and set it as invalid for prioritizing tiles.
3398 // Should update viewport and transform, but not update visible rect.
3399 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
3400 host_impl_
.SetCurrentBeginFrameArgs(
3401 CreateBeginFrameArgsForTesting(time_ticks
));
3402 resourceless_software_draw
= true;
3403 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
3404 transform
.Translate(1.f
, 1.f
);
3405 active_layer_
->draw_properties().visible_content_rect
= viewport
;
3406 active_layer_
->draw_properties().screen_space_transform
= transform
;
3407 host_impl_
.SetExternalDrawConstraints(transform
,
3412 resourceless_software_draw
);
3413 active_layer_
->UpdateTiles(Occlusion(), resourceless_software_draw
);
3415 // Transform for tile priority is updated.
3416 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3417 active_layer_
->screen_space_transform());
3418 // Visible rect for tile priority retains old value.
3419 EXPECT_EQ(visible_rect_for_tile_priority
,
3420 active_layer_
->visible_rect_for_tile_priority());
3422 // Keep expanded viewport but mark it valid. Should update tile viewport.
3423 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
3424 host_impl_
.SetCurrentBeginFrameArgs(
3425 CreateBeginFrameArgsForTesting(time_ticks
));
3426 resourceless_software_draw
= false;
3427 host_impl_
.SetExternalDrawConstraints(transform
,
3432 resourceless_software_draw
);
3433 active_layer_
->UpdateTiles(Occlusion(), resourceless_software_draw
);
3435 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3436 active_layer_
->screen_space_transform());
3437 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
3440 TEST_F(NoLowResPictureLayerImplTest
, CleanUpTilings
) {
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 std::vector
<PictureLayerTiling
*> used_tilings
;
3451 SetupTrees(pending_pile
, active_pile
);
3452 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
3454 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3455 EXPECT_LT(low_res_factor
, 1.f
);
3457 float device_scale
= 1.7f
;
3458 float page_scale
= 3.2f
;
3461 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
3462 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3464 // We only have ideal tilings, so they aren't removed.
3465 used_tilings
.clear();
3466 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3467 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3469 host_impl_
.PinchGestureBegin();
3471 // Changing the ideal but not creating new tilings.
3474 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
3475 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3477 // The tilings are still our target scale, so they aren't removed.
3478 used_tilings
.clear();
3479 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3480 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3482 host_impl_
.PinchGestureEnd();
3484 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
3487 SetContentsScaleOnBothLayers(1.2f
, device_scale
, page_scale
, 1.f
, false);
3488 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3489 EXPECT_FLOAT_EQ(1.f
,
3490 active_layer_
->tilings()->tiling_at(1)->contents_scale());
3492 // Mark the non-ideal tilings as used. They won't be removed.
3493 used_tilings
.clear();
3494 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3495 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3496 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3498 // Now move the ideal scale to 0.5. Our target stays 1.2.
3499 SetContentsScaleOnBothLayers(0.5f
, device_scale
, page_scale
, 1.f
, false);
3501 // The high resolution tiling is between target and ideal, so is not
3502 // removed. The low res tiling for the old ideal=1.0 scale is removed.
3503 used_tilings
.clear();
3504 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3505 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3507 // Now move the ideal scale to 1.0. Our target stays 1.2.
3508 SetContentsScaleOnBothLayers(1.f
, device_scale
, page_scale
, 1.f
, false);
3510 // All the tilings are between are target and the ideal, so they are not
3512 used_tilings
.clear();
3513 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3514 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3516 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
3517 SetupDrawPropertiesAndUpdateTiles(
3518 active_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
3520 // Because the pending layer's ideal scale is still 1.0, our tilings fall
3521 // in the range [1.0,1.2] and are kept.
3522 used_tilings
.clear();
3523 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3524 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3526 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
3528 SetupDrawPropertiesAndUpdateTiles(
3529 pending_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
3531 // Our 1.0 tiling now falls outside the range between our ideal scale and our
3532 // target raster scale. But it is in our used tilings set, so nothing is
3534 used_tilings
.clear();
3535 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3536 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3537 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3539 // If we remove it from our used tilings set, it is outside the range to keep
3540 // so it is deleted.
3541 used_tilings
.clear();
3542 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3543 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3546 TEST_F(PictureLayerImplTest
, ScaleCollision
) {
3547 gfx::Size
tile_size(400, 400);
3548 gfx::Size
layer_bounds(1300, 1900);
3550 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3551 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3552 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3553 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3555 std::vector
<PictureLayerTiling
*> used_tilings
;
3557 SetupTrees(pending_pile
, active_pile
);
3559 float pending_contents_scale
= 1.f
;
3560 float active_contents_scale
= 2.f
;
3561 float device_scale_factor
= 1.f
;
3562 float page_scale_factor
= 1.f
;
3563 float maximum_animation_contents_scale
= 1.f
;
3564 bool animating_transform
= false;
3566 EXPECT_TRUE(host_impl_
.settings().create_low_res_tiling
);
3567 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3568 EXPECT_LT(low_res_factor
, 1.f
);
3570 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3571 pending_contents_scale
,
3572 device_scale_factor
,
3574 maximum_animation_contents_scale
,
3575 animating_transform
);
3576 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3577 active_contents_scale
,
3578 device_scale_factor
,
3580 maximum_animation_contents_scale
,
3581 animating_transform
);
3583 ASSERT_EQ(4u, pending_layer_
->tilings()->num_tilings());
3584 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
3586 EXPECT_EQ(active_contents_scale
,
3587 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3588 EXPECT_EQ(pending_contents_scale
,
3589 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
3590 EXPECT_EQ(active_contents_scale
* low_res_factor
,
3591 pending_layer_
->tilings()->tiling_at(2)->contents_scale());
3592 EXPECT_EQ(pending_contents_scale
* low_res_factor
,
3593 pending_layer_
->tilings()->tiling_at(3)->contents_scale());
3595 EXPECT_EQ(active_contents_scale
,
3596 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3597 EXPECT_EQ(pending_contents_scale
,
3598 active_layer_
->tilings()->tiling_at(1)->contents_scale());
3599 EXPECT_EQ(active_contents_scale
* low_res_factor
,
3600 active_layer_
->tilings()->tiling_at(2)->contents_scale());
3601 EXPECT_EQ(pending_contents_scale
* low_res_factor
,
3602 active_layer_
->tilings()->tiling_at(3)->contents_scale());
3604 // The unused low res tiling from the pending tree must be kept or we may add
3605 // it again on the active tree and collide with the pending tree.
3606 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3607 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3608 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
3610 EXPECT_EQ(active_contents_scale
,
3611 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3612 EXPECT_EQ(pending_contents_scale
,
3613 active_layer_
->tilings()->tiling_at(1)->contents_scale());
3614 EXPECT_EQ(active_contents_scale
* low_res_factor
,
3615 active_layer_
->tilings()->tiling_at(2)->contents_scale());
3616 EXPECT_EQ(pending_contents_scale
* low_res_factor
,
3617 active_layer_
->tilings()->tiling_at(3)->contents_scale());
3620 TEST_F(NoLowResPictureLayerImplTest
, ReleaseResources
) {
3621 gfx::Size
tile_size(400, 400);
3622 gfx::Size
layer_bounds(1300, 1900);
3624 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3625 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3626 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3627 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3629 SetupTrees(pending_pile
, active_pile
);
3630 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
3632 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3633 1.3f
, // ideal contents scale
3634 2.7f
, // device scale
3636 1.f
, // maximum animation scale
3638 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3640 // All tilings should be removed when losing output surface.
3641 active_layer_
->ReleaseResources();
3642 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
3643 pending_layer_
->ReleaseResources();
3644 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
3646 // This should create new tilings.
3647 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3648 1.3f
, // ideal contents scale
3649 2.7f
, // device scale
3651 1.f
, // maximum animation scale
3653 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3656 TEST_F(PictureLayerImplTest
, SharedQuadStateContainsMaxTilingScale
) {
3657 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3659 gfx::Size
tile_size(400, 400);
3660 gfx::Size
layer_bounds(1000, 2000);
3662 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3663 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3664 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3665 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3667 SetupTrees(pending_pile
, active_pile
);
3669 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 2.5f
, 1.f
, 1.f
, 1.f
, false);
3670 host_impl_
.pending_tree()->UpdateDrawProperties();
3672 active_layer_
->draw_properties().visible_content_rect
=
3673 gfx::Rect(layer_bounds
);
3674 host_impl_
.active_tree()->UpdateDrawProperties();
3676 float max_contents_scale
= active_layer_
->MaximumTilingContentsScale();
3677 gfx::Transform scaled_draw_transform
= active_layer_
->draw_transform();
3678 scaled_draw_transform
.Scale(SK_MScalar1
/ max_contents_scale
,
3679 SK_MScalar1
/ max_contents_scale
);
3681 AppendQuadsData data
;
3682 active_layer_
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
3684 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
3685 EXPECT_EQ(1u, render_pass
->shared_quad_state_list
.size());
3686 // The content_to_target_transform should be scaled by the
3687 // MaximumTilingContentsScale on the layer.
3688 EXPECT_EQ(scaled_draw_transform
.ToString(),
3689 render_pass
->shared_quad_state_list
.front()
3690 ->content_to_target_transform
.ToString());
3691 // The content_bounds should be scaled by the
3692 // MaximumTilingContentsScale on the layer.
3694 gfx::Size(2500u, 5000u).ToString(),
3695 render_pass
->shared_quad_state_list
.front()->content_bounds
.ToString());
3696 // The visible_content_rect should be scaled by the
3697 // MaximumTilingContentsScale on the layer.
3698 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
3699 render_pass
->shared_quad_state_list
.front()
3700 ->visible_content_rect
.ToString());
3703 TEST_F(PictureLayerImplTest
, UpdateTilesForMasksWithNoVisibleContent
) {
3704 gfx::Size
tile_size(400, 400);
3705 gfx::Size
bounds(100000, 100);
3707 host_impl_
.CreatePendingTree();
3709 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl_
.pending_tree(), 1);
3711 scoped_ptr
<FakePictureLayerImpl
> layer_with_mask
=
3712 FakePictureLayerImpl::Create(host_impl_
.pending_tree(), 2);
3714 layer_with_mask
->SetBounds(bounds
);
3715 layer_with_mask
->SetContentBounds(bounds
);
3717 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3718 FakePicturePileImpl::CreateFilledPile(tile_size
, bounds
);
3719 scoped_ptr
<FakePictureLayerImpl
> mask
=
3720 FakePictureLayerImpl::CreateWithRasterSource(host_impl_
.pending_tree(), 3,
3722 mask
->set_is_mask(true);
3724 mask
->SetBounds(bounds
);
3725 mask
->SetContentBounds(bounds
);
3726 mask
->SetDrawsContent(true);
3728 FakePictureLayerImpl
* pending_mask_content
= mask
.get();
3729 layer_with_mask
->SetMaskLayer(mask
.Pass());
3731 scoped_ptr
<FakePictureLayerImpl
> child_of_layer_with_mask
=
3732 FakePictureLayerImpl::Create(host_impl_
.pending_tree(), 4);
3734 child_of_layer_with_mask
->SetBounds(bounds
);
3735 child_of_layer_with_mask
->SetContentBounds(bounds
);
3736 child_of_layer_with_mask
->SetDrawsContent(true);
3738 layer_with_mask
->AddChild(child_of_layer_with_mask
.Pass());
3740 root
->AddChild(layer_with_mask
.Pass());
3742 host_impl_
.pending_tree()->SetRootLayer(root
.Pass());
3744 EXPECT_FALSE(pending_mask_content
->tilings());
3745 host_impl_
.pending_tree()->UpdateDrawProperties();
3746 EXPECT_NE(0u, pending_mask_content
->num_tilings());
3749 class PictureLayerImplTestWithDelegatingRenderer
: public PictureLayerImplTest
{
3751 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {}
3753 void InitializeRenderer() override
{
3754 host_impl_
.InitializeRenderer(FakeOutputSurface::CreateDelegating3d());
3758 TEST_F(PictureLayerImplTestWithDelegatingRenderer
,
3759 DelegatingRendererWithTileOOM
) {
3760 // This test is added for crbug.com/402321, where quad should be produced when
3761 // raster on demand is not allowed and tile is OOM.
3762 gfx::Size tile_size
= host_impl_
.settings().default_tile_size
;
3763 gfx::Size
layer_bounds(1000, 1000);
3766 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3767 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3768 SetupPendingTree(pending_pile
);
3769 pending_layer_
->SetBounds(layer_bounds
);
3770 host_impl_
.SetViewportSize(layer_bounds
);
3772 host_impl_
.active_tree()->UpdateDrawProperties();
3773 std::vector
<Tile
*> tiles
=
3774 active_layer_
->HighResTiling()->AllTilesForTesting();
3775 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3777 // Force tiles after max_tiles to be OOM. TileManager uses
3778 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3779 // directly set state to host_impl_, so we set policy that would change the
3780 // state. We also need to update tree priority separately.
3781 GlobalStateThatImpactsTilePriority state
;
3782 size_t max_tiles
= 1;
3783 size_t memory_limit
= max_tiles
* 4 * tile_size
.width() * tile_size
.height();
3784 size_t resource_limit
= max_tiles
;
3785 ManagedMemoryPolicy
policy(memory_limit
,
3786 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
,
3788 host_impl_
.SetMemoryPolicy(policy
);
3789 host_impl_
.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES
);
3790 host_impl_
.ManageTiles();
3792 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3793 AppendQuadsData data
;
3794 active_layer_
->WillDraw(DRAW_MODE_HARDWARE
, nullptr);
3795 active_layer_
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
3796 active_layer_
->DidDraw(nullptr);
3798 // Even when OOM, quads should be produced, and should be different material
3799 // from quads with resource.
3800 EXPECT_LT(max_tiles
, render_pass
->quad_list
.size());
3801 EXPECT_EQ(DrawQuad::Material::TILED_CONTENT
,
3802 render_pass
->quad_list
.front()->material
);
3803 EXPECT_EQ(DrawQuad::Material::SOLID_COLOR
,
3804 render_pass
->quad_list
.back()->material
);
3807 class OcclusionTrackingSettings
: public LowResTilingsSettings
{
3809 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization
= true; }
3812 class OcclusionTrackingPictureLayerImplTest
: public PictureLayerImplTest
{
3814 OcclusionTrackingPictureLayerImplTest()
3815 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
3817 void VerifyEvictionConsidersOcclusion(
3818 PictureLayerImpl
* layer
,
3819 size_t expected_occluded_tile_count
[NUM_TREE_PRIORITIES
]) {
3820 for (int priority_count
= 0; priority_count
< NUM_TREE_PRIORITIES
;
3822 TreePriority tree_priority
= static_cast<TreePriority
>(priority_count
);
3823 size_t occluded_tile_count
= 0u;
3824 Tile
* last_tile
= nullptr;
3826 for (PictureLayerImpl::LayerEvictionTileIterator it
=
3827 PictureLayerImpl::LayerEvictionTileIterator(layer
,
3835 // The only way we will encounter an occluded tile after an unoccluded
3836 // tile is if the priorty bin decreased, the tile is required for
3837 // activation, or the scale changed.
3838 bool tile_is_occluded
=
3839 tile
->is_occluded_for_tree_priority(tree_priority
);
3840 if (tile_is_occluded
) {
3841 occluded_tile_count
++;
3843 bool last_tile_is_occluded
=
3844 last_tile
->is_occluded_for_tree_priority(tree_priority
);
3845 if (!last_tile_is_occluded
) {
3846 TilePriority::PriorityBin tile_priority_bin
=
3847 tile
->priority_for_tree_priority(tree_priority
).priority_bin
;
3848 TilePriority::PriorityBin last_tile_priority_bin
=
3849 last_tile
->priority_for_tree_priority(tree_priority
)
3853 (tile_priority_bin
< last_tile_priority_bin
) ||
3854 tile
->required_for_activation() ||
3855 (tile
->contents_scale() != last_tile
->contents_scale()));
3860 EXPECT_EQ(expected_occluded_tile_count
[priority_count
],
3861 occluded_tile_count
);
3866 TEST_F(OcclusionTrackingPictureLayerImplTest
,
3867 OccludedTilesSkippedDuringRasterization
) {
3868 base::TimeTicks time_ticks
;
3869 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
3870 host_impl_
.SetCurrentBeginFrameArgs(
3871 CreateBeginFrameArgsForTesting(time_ticks
));
3873 gfx::Size
tile_size(102, 102);
3874 gfx::Size
layer_bounds(1000, 1000);
3875 gfx::Size
viewport_size(500, 500);
3876 gfx::Point
occluding_layer_position(310, 0);
3878 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3879 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3880 SetupPendingTree(pending_pile
);
3881 pending_layer_
->set_fixed_tile_size(tile_size
);
3883 host_impl_
.SetViewportSize(viewport_size
);
3884 host_impl_
.pending_tree()->UpdateDrawProperties();
3887 int unoccluded_tile_count
= 0;
3888 for (PictureLayerImpl::LayerRasterTileIterator it
=
3889 PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
3894 // Occluded tiles should not be iterated over.
3895 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
3897 // Some tiles may not be visible (i.e. outside the viewport). The rest are
3898 // visible and at least partially unoccluded, verified by the above expect.
3899 bool tile_is_visible
=
3900 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
3901 if (tile_is_visible
)
3902 unoccluded_tile_count
++;
3904 EXPECT_EQ(unoccluded_tile_count
, 25);
3906 // Partial occlusion.
3907 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
3908 LayerImpl
* layer1
= pending_layer_
->children()[0];
3909 layer1
->SetBounds(layer_bounds
);
3910 layer1
->SetContentBounds(layer_bounds
);
3911 layer1
->SetDrawsContent(true);
3912 layer1
->SetContentsOpaque(true);
3913 layer1
->SetPosition(occluding_layer_position
);
3915 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
3916 host_impl_
.SetCurrentBeginFrameArgs(
3917 CreateBeginFrameArgsForTesting(time_ticks
));
3918 host_impl_
.pending_tree()->UpdateDrawProperties();
3920 unoccluded_tile_count
= 0;
3921 for (PictureLayerImpl::LayerRasterTileIterator it
=
3922 PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
3927 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
3929 bool tile_is_visible
=
3930 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
3931 if (tile_is_visible
)
3932 unoccluded_tile_count
++;
3934 EXPECT_EQ(20, unoccluded_tile_count
);
3937 layer1
->SetPosition(gfx::Point(0, 0));
3939 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
3940 host_impl_
.SetCurrentBeginFrameArgs(
3941 CreateBeginFrameArgsForTesting(time_ticks
));
3942 host_impl_
.pending_tree()->UpdateDrawProperties();
3944 unoccluded_tile_count
= 0;
3945 for (PictureLayerImpl::LayerRasterTileIterator it
=
3946 PictureLayerImpl::LayerRasterTileIterator(pending_layer_
, false);
3951 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
3953 bool tile_is_visible
=
3954 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
3955 if (tile_is_visible
)
3956 unoccluded_tile_count
++;
3958 EXPECT_EQ(unoccluded_tile_count
, 0);
3961 TEST_F(OcclusionTrackingPictureLayerImplTest
,
3962 OccludedTilesNotMarkedAsRequired
) {
3963 base::TimeTicks time_ticks
;
3964 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
3965 host_impl_
.SetCurrentBeginFrameArgs(
3966 CreateBeginFrameArgsForTesting(time_ticks
));
3968 gfx::Size
tile_size(102, 102);
3969 gfx::Size
layer_bounds(1000, 1000);
3970 gfx::Size
viewport_size(500, 500);
3971 gfx::Point
occluding_layer_position(310, 0);
3973 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3974 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3975 SetupPendingTree(pending_pile
);
3976 pending_layer_
->set_fixed_tile_size(tile_size
);
3978 host_impl_
.SetViewportSize(viewport_size
);
3979 host_impl_
.pending_tree()->UpdateDrawProperties();
3982 int occluded_tile_count
= 0;
3983 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3984 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3986 occluded_tile_count
= 0;
3987 for (PictureLayerTiling::CoverageIterator
iter(
3989 pending_layer_
->contents_scale_x(),
3990 gfx::Rect(layer_bounds
));
3995 const Tile
* tile
= *iter
;
3997 // Fully occluded tiles are not required for activation.
3998 if (tile
->is_occluded(PENDING_TREE
)) {
3999 EXPECT_FALSE(tile
->required_for_activation());
4000 occluded_tile_count
++;
4003 EXPECT_EQ(occluded_tile_count
, 0);
4006 // Partial occlusion.
4007 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4008 LayerImpl
* layer1
= pending_layer_
->children()[0];
4009 layer1
->SetBounds(layer_bounds
);
4010 layer1
->SetContentBounds(layer_bounds
);
4011 layer1
->SetDrawsContent(true);
4012 layer1
->SetContentsOpaque(true);
4013 layer1
->SetPosition(occluding_layer_position
);
4015 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4016 host_impl_
.SetCurrentBeginFrameArgs(
4017 CreateBeginFrameArgsForTesting(time_ticks
));
4018 host_impl_
.pending_tree()->UpdateDrawProperties();
4020 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4021 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4022 tiling
->UpdateAllTilePrioritiesForTesting();
4024 occluded_tile_count
= 0;
4025 for (PictureLayerTiling::CoverageIterator
iter(
4027 pending_layer_
->contents_scale_x(),
4028 gfx::Rect(layer_bounds
));
4033 const Tile
* tile
= *iter
;
4035 if (tile
->is_occluded(PENDING_TREE
)) {
4036 EXPECT_FALSE(tile
->required_for_activation());
4037 occluded_tile_count
++;
4042 EXPECT_EQ(occluded_tile_count
, 5);
4045 EXPECT_EQ(occluded_tile_count
, 2);
4053 layer1
->SetPosition(gfx::PointF(0, 0));
4055 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4056 host_impl_
.SetCurrentBeginFrameArgs(
4057 CreateBeginFrameArgsForTesting(time_ticks
));
4058 host_impl_
.pending_tree()->UpdateDrawProperties();
4060 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4061 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4062 tiling
->UpdateAllTilePrioritiesForTesting();
4064 occluded_tile_count
= 0;
4065 for (PictureLayerTiling::CoverageIterator
iter(
4067 pending_layer_
->contents_scale_x(),
4068 gfx::Rect(layer_bounds
));
4073 const Tile
* tile
= *iter
;
4075 if (tile
->is_occluded(PENDING_TREE
)) {
4076 EXPECT_FALSE(tile
->required_for_activation());
4077 occluded_tile_count
++;
4082 EXPECT_EQ(25, occluded_tile_count
);
4085 EXPECT_EQ(4, occluded_tile_count
);
4093 TEST_F(OcclusionTrackingPictureLayerImplTest
, OcclusionForDifferentScales
) {
4094 gfx::Size
tile_size(102, 102);
4095 gfx::Size
layer_bounds(1000, 1000);
4096 gfx::Size
viewport_size(500, 500);
4097 gfx::Point
occluding_layer_position(310, 0);
4099 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4100 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4101 SetupPendingTree(pending_pile
);
4102 pending_layer_
->set_fixed_tile_size(tile_size
);
4104 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
4106 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
4108 std::vector
<PictureLayerTiling
*> tilings
;
4109 tilings
.push_back(pending_layer_
->AddTiling(low_res_factor
));
4110 tilings
.push_back(pending_layer_
->AddTiling(0.3f
));
4111 tilings
.push_back(pending_layer_
->AddTiling(0.7f
));
4112 tilings
.push_back(pending_layer_
->AddTiling(1.0f
));
4113 tilings
.push_back(pending_layer_
->AddTiling(2.0f
));
4115 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4116 LayerImpl
* layer1
= pending_layer_
->children()[0];
4117 layer1
->SetBounds(layer_bounds
);
4118 layer1
->SetContentBounds(layer_bounds
);
4119 layer1
->SetDrawsContent(true);
4120 layer1
->SetContentsOpaque(true);
4121 layer1
->SetPosition(occluding_layer_position
);
4123 host_impl_
.SetViewportSize(viewport_size
);
4124 host_impl_
.pending_tree()->UpdateDrawProperties();
4126 int tiling_count
= 0;
4127 int occluded_tile_count
= 0;
4128 for (std::vector
<PictureLayerTiling
*>::iterator tiling_iterator
=
4130 tiling_iterator
!= tilings
.end();
4131 ++tiling_iterator
) {
4132 (*tiling_iterator
)->UpdateAllTilePrioritiesForTesting();
4133 std::vector
<Tile
*> tiles
= (*tiling_iterator
)->AllTilesForTesting();
4135 occluded_tile_count
= 0;
4136 for (size_t i
= 0; i
< tiles
.size(); ++i
) {
4137 if (tiles
[i
]->is_occluded(PENDING_TREE
)) {
4138 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4139 tiles
[i
]->content_rect(), 1.0f
/ tiles
[i
]->contents_scale());
4140 EXPECT_GE(scaled_content_rect
.x(), occluding_layer_position
.x());
4141 occluded_tile_count
++;
4144 switch (tiling_count
) {
4147 EXPECT_EQ(occluded_tile_count
, 2);
4150 EXPECT_EQ(occluded_tile_count
, 4);
4153 EXPECT_EQ(occluded_tile_count
, 5);
4156 EXPECT_EQ(occluded_tile_count
, 30);
4165 EXPECT_EQ(tiling_count
, 5);
4168 TEST_F(OcclusionTrackingPictureLayerImplTest
, DifferentOcclusionOnTrees
) {
4169 gfx::Size
tile_size(102, 102);
4170 gfx::Size
layer_bounds(1000, 1000);
4171 gfx::Size
viewport_size(1000, 1000);
4172 gfx::Point
occluding_layer_position(310, 0);
4173 gfx::Rect
invalidation_rect(230, 230, 102, 102);
4175 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4176 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4177 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4178 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4179 SetupTrees(pending_pile
, active_pile
);
4181 // Partially occlude the active layer.
4182 active_layer_
->AddChild(LayerImpl::Create(host_impl_
.active_tree(), 2));
4183 LayerImpl
* layer1
= active_layer_
->children()[0];
4184 layer1
->SetBounds(layer_bounds
);
4185 layer1
->SetContentBounds(layer_bounds
);
4186 layer1
->SetDrawsContent(true);
4187 layer1
->SetContentsOpaque(true);
4188 layer1
->SetPosition(occluding_layer_position
);
4190 // Partially invalidate the pending layer.
4191 pending_layer_
->set_invalidation(invalidation_rect
);
4193 host_impl_
.SetViewportSize(viewport_size
);
4195 active_layer_
->CreateDefaultTilingsAndTiles();
4196 pending_layer_
->CreateDefaultTilingsAndTiles();
4198 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4199 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4200 tiling
->UpdateAllTilePrioritiesForTesting();
4202 for (PictureLayerTiling::CoverageIterator
iter(
4204 pending_layer_
->contents_scale_x(),
4205 gfx::Rect(layer_bounds
));
4210 const Tile
* tile
= *iter
;
4212 // All tiles are unoccluded on the pending tree.
4213 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4215 Tile
* twin_tile
= pending_layer_
->GetPendingOrActiveTwinTiling(tiling
)
4216 ->TileAt(iter
.i(), iter
.j());
4217 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4218 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4220 if (scaled_content_rect
.Intersects(invalidation_rect
)) {
4221 // Tiles inside the invalidation rect are only on the pending tree.
4222 EXPECT_NE(tile
, twin_tile
);
4224 // Unshared tiles should be unoccluded on the active tree by default.
4225 EXPECT_FALSE(tile
->is_occluded(ACTIVE_TREE
));
4227 // Tiles outside the invalidation rect are shared between both trees.
4228 EXPECT_EQ(tile
, twin_tile
);
4229 // Shared tiles are occluded on the active tree iff they lie beneath the
4231 EXPECT_EQ(tile
->is_occluded(ACTIVE_TREE
),
4232 scaled_content_rect
.x() >= occluding_layer_position
.x());
4237 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4238 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4240 for (PictureLayerTiling::CoverageIterator
iter(
4242 active_layer_
->contents_scale_x(),
4243 gfx::Rect(layer_bounds
));
4248 const Tile
* tile
= *iter
;
4250 Tile
* twin_tile
= active_layer_
->GetPendingOrActiveTwinTiling(tiling
)
4251 ->TileAt(iter
.i(), iter
.j());
4252 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4253 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4255 // Since we've already checked the shared tiles, only consider tiles in
4256 // the invalidation rect.
4257 if (scaled_content_rect
.Intersects(invalidation_rect
)) {
4258 // Tiles inside the invalidation rect are only on the active tree.
4259 EXPECT_NE(tile
, twin_tile
);
4261 // Unshared tiles should be unoccluded on the pending tree by default.
4262 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4264 // Unshared tiles are occluded on the active tree iff they lie beneath
4265 // the occluding layer.
4266 EXPECT_EQ(tile
->is_occluded(ACTIVE_TREE
),
4267 scaled_content_rect
.x() >= occluding_layer_position
.x());
4273 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4274 OccludedTilesConsideredDuringEviction
) {
4275 gfx::Size
tile_size(102, 102);
4276 gfx::Size
layer_bounds(1000, 1000);
4277 gfx::Size
viewport_size(500, 500);
4278 gfx::Point
pending_occluding_layer_position(310, 0);
4279 gfx::Point
active_occluding_layer_position(0, 310);
4280 gfx::Rect
invalidation_rect(230, 230, 102, 102);
4282 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4283 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4284 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4285 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4286 SetupTrees(pending_pile
, active_pile
);
4288 pending_layer_
->set_fixed_tile_size(tile_size
);
4289 active_layer_
->set_fixed_tile_size(tile_size
);
4291 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
4293 std::vector
<PictureLayerTiling
*> tilings
;
4294 tilings
.push_back(pending_layer_
->AddTiling(low_res_factor
));
4295 tilings
.push_back(pending_layer_
->AddTiling(0.3f
));
4296 tilings
.push_back(pending_layer_
->AddTiling(0.7f
));
4297 tilings
.push_back(pending_layer_
->AddTiling(1.0f
));
4298 tilings
.push_back(pending_layer_
->AddTiling(2.0f
));
4300 EXPECT_EQ(5u, pending_layer_
->num_tilings());
4301 EXPECT_EQ(5u, active_layer_
->num_tilings());
4303 // Partially occlude the pending layer.
4304 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4305 LayerImpl
* pending_occluding_layer
= pending_layer_
->children()[0];
4306 pending_occluding_layer
->SetBounds(layer_bounds
);
4307 pending_occluding_layer
->SetContentBounds(layer_bounds
);
4308 pending_occluding_layer
->SetDrawsContent(true);
4309 pending_occluding_layer
->SetContentsOpaque(true);
4310 pending_occluding_layer
->SetPosition(pending_occluding_layer_position
);
4312 // Partially occlude the active layer.
4313 active_layer_
->AddChild(LayerImpl::Create(host_impl_
.active_tree(), 2));
4314 LayerImpl
* active_occluding_layer
= active_layer_
->children()[0];
4315 active_occluding_layer
->SetBounds(layer_bounds
);
4316 active_occluding_layer
->SetContentBounds(layer_bounds
);
4317 active_occluding_layer
->SetDrawsContent(true);
4318 active_occluding_layer
->SetContentsOpaque(true);
4319 active_occluding_layer
->SetPosition(active_occluding_layer_position
);
4321 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4322 // are not shared between trees.
4323 pending_layer_
->set_invalidation(invalidation_rect
);
4325 host_impl_
.SetViewportSize(viewport_size
);
4326 host_impl_
.active_tree()->UpdateDrawProperties();
4327 host_impl_
.pending_tree()->UpdateDrawProperties();
4329 // The expected number of occluded tiles on each of the 5 tilings for each of
4330 // the 3 tree priorities.
4331 size_t expected_occluded_tile_count_on_both
[] = {9u, 1u, 1u, 1u, 1u};
4332 size_t expected_occluded_tile_count_on_active
[] = {30u, 5u, 4u, 2u, 2u};
4333 size_t expected_occluded_tile_count_on_pending
[] = {30u, 5u, 4u, 2u, 2u};
4335 // The total expected number of occluded tiles on all tilings for each of the
4336 // 3 tree priorities.
4337 size_t total_expected_occluded_tile_count
[] = {13u, 43u, 43u};
4339 ASSERT_EQ(arraysize(total_expected_occluded_tile_count
), NUM_TREE_PRIORITIES
);
4341 // Verify number of occluded tiles on the pending layer for each tiling.
4342 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4343 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4344 tiling
->CreateAllTilesForTesting();
4345 tiling
->UpdateAllTilePrioritiesForTesting();
4347 size_t occluded_tile_count_on_pending
= 0u;
4348 size_t occluded_tile_count_on_active
= 0u;
4349 size_t occluded_tile_count_on_both
= 0u;
4350 for (PictureLayerTiling::CoverageIterator
iter(
4352 pending_layer_
->contents_scale_x(),
4353 gfx::Rect(layer_bounds
));
4358 if (tile
->is_occluded(PENDING_TREE
))
4359 occluded_tile_count_on_pending
++;
4360 if (tile
->is_occluded(ACTIVE_TREE
))
4361 occluded_tile_count_on_active
++;
4362 if (tile
->is_occluded(PENDING_TREE
) && tile
->is_occluded(ACTIVE_TREE
))
4363 occluded_tile_count_on_both
++;
4365 EXPECT_EQ(expected_occluded_tile_count_on_pending
[i
],
4366 occluded_tile_count_on_pending
)
4368 EXPECT_EQ(expected_occluded_tile_count_on_active
[i
],
4369 occluded_tile_count_on_active
)
4371 EXPECT_EQ(expected_occluded_tile_count_on_both
[i
],
4372 occluded_tile_count_on_both
)
4376 // Verify number of occluded tiles on the active layer for each tiling.
4377 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4378 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4379 tiling
->CreateAllTilesForTesting();
4380 tiling
->UpdateAllTilePrioritiesForTesting();
4382 size_t occluded_tile_count_on_pending
= 0u;
4383 size_t occluded_tile_count_on_active
= 0u;
4384 size_t occluded_tile_count_on_both
= 0u;
4385 for (PictureLayerTiling::CoverageIterator
iter(
4387 pending_layer_
->contents_scale_x(),
4388 gfx::Rect(layer_bounds
));
4393 if (tile
->is_occluded(PENDING_TREE
))
4394 occluded_tile_count_on_pending
++;
4395 if (tile
->is_occluded(ACTIVE_TREE
))
4396 occluded_tile_count_on_active
++;
4397 if (tile
->is_occluded(PENDING_TREE
) && tile
->is_occluded(ACTIVE_TREE
))
4398 occluded_tile_count_on_both
++;
4400 EXPECT_EQ(expected_occluded_tile_count_on_pending
[i
],
4401 occluded_tile_count_on_pending
)
4403 EXPECT_EQ(expected_occluded_tile_count_on_active
[i
],
4404 occluded_tile_count_on_active
)
4406 EXPECT_EQ(expected_occluded_tile_count_on_both
[i
],
4407 occluded_tile_count_on_both
)
4411 std::vector
<Tile
*> all_tiles
;
4412 for (std::vector
<PictureLayerTiling
*>::iterator tiling_iterator
=
4414 tiling_iterator
!= tilings
.end();
4415 ++tiling_iterator
) {
4416 std::vector
<Tile
*> tiles
= (*tiling_iterator
)->AllTilesForTesting();
4417 std::copy(tiles
.begin(), tiles
.end(), std::back_inserter(all_tiles
));
4420 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
4422 VerifyEvictionConsidersOcclusion(pending_layer_
,
4423 total_expected_occluded_tile_count
);
4424 VerifyEvictionConsidersOcclusion(active_layer_
,
4425 total_expected_occluded_tile_count
);
4428 TEST_F(PictureLayerImplTest
, PendingOrActiveTwinLayer
) {
4429 gfx::Size
tile_size(102, 102);
4430 gfx::Size
layer_bounds(1000, 1000);
4432 scoped_refptr
<FakePicturePileImpl
> pile
=
4433 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4434 SetupPendingTree(pile
);
4435 EXPECT_FALSE(pending_layer_
->GetPendingOrActiveTwinLayer());
4438 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4440 SetupPendingTree(pile
);
4441 EXPECT_TRUE(pending_layer_
->GetPendingOrActiveTwinLayer());
4442 EXPECT_TRUE(active_layer_
->GetPendingOrActiveTwinLayer());
4443 EXPECT_EQ(pending_layer_
, active_layer_
->GetPendingOrActiveTwinLayer());
4444 EXPECT_EQ(active_layer_
, pending_layer_
->GetPendingOrActiveTwinLayer());
4447 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4449 // Make an empty pending tree.
4450 host_impl_
.CreatePendingTree();
4451 host_impl_
.pending_tree()->DetachLayerTree();
4452 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4455 TEST_F(PictureLayerImplTest
, RecycledTwinLayer
) {
4456 gfx::Size
tile_size(102, 102);
4457 gfx::Size
layer_bounds(1000, 1000);
4459 scoped_refptr
<FakePicturePileImpl
> pile
=
4460 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4461 SetupPendingTree(pile
);
4462 EXPECT_FALSE(pending_layer_
->GetRecycledTwinLayer());
4465 EXPECT_TRUE(active_layer_
->GetRecycledTwinLayer());
4466 EXPECT_EQ(old_pending_layer_
, active_layer_
->GetRecycledTwinLayer());
4468 SetupPendingTree(pile
);
4469 EXPECT_FALSE(pending_layer_
->GetRecycledTwinLayer());
4470 EXPECT_FALSE(active_layer_
->GetRecycledTwinLayer());
4473 EXPECT_TRUE(active_layer_
->GetRecycledTwinLayer());
4474 EXPECT_EQ(old_pending_layer_
, active_layer_
->GetRecycledTwinLayer());
4476 // Make an empty pending tree.
4477 host_impl_
.CreatePendingTree();
4478 host_impl_
.pending_tree()->DetachLayerTree();
4479 EXPECT_FALSE(active_layer_
->GetRecycledTwinLayer());
4482 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid
) {
4483 base::TimeTicks time_ticks
;
4484 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4485 host_impl_
.SetCurrentBeginFrameArgs(
4486 CreateBeginFrameArgsForTesting(time_ticks
));
4488 gfx::Size
tile_size(100, 100);
4489 gfx::Size
layer_bounds(200, 200);
4490 gfx::Rect
layer_rect(layer_bounds
);
4492 FakeContentLayerClient client
;
4493 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
4494 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4495 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&host_client
);
4496 host
->SetRootLayer(layer
);
4497 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4499 host_impl_
.SetViewportSize(layer_bounds
);
4501 int frame_number
= 0;
4503 client
.set_fill_with_nonsolid_color(!test_for_solid
);
4505 Region
invalidation(layer_rect
);
4506 recording_source
->UpdateAndExpandInvalidation(
4507 &client
, &invalidation
, false, layer_bounds
, layer_rect
, frame_number
++,
4508 Picture::RECORD_NORMALLY
);
4510 scoped_refptr
<RasterSource
> pending_raster_source
=
4511 recording_source
->CreateRasterSource();
4513 SetupPendingTree(pending_raster_source
);
4516 active_layer_
->set_fixed_tile_size(tile_size
);
4517 host_impl_
.active_tree()->UpdateDrawProperties();
4518 if (test_for_solid
) {
4519 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4521 ASSERT_TRUE(active_layer_
->tilings());
4522 ASSERT_GT(active_layer_
->tilings()->num_tilings(), 0u);
4523 std::vector
<Tile
*> tiles
=
4524 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
4525 EXPECT_FALSE(tiles
.empty());
4526 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4529 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
4530 AppendQuadsData data
;
4531 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
4532 active_layer_
->AppendQuads(render_pass
.get(), Occlusion(), &data
);
4533 active_layer_
->DidDraw(nullptr);
4535 DrawQuad::Material expected
= test_for_solid
4536 ? DrawQuad::Material::SOLID_COLOR
4537 : DrawQuad::Material::TILED_CONTENT
;
4538 EXPECT_EQ(expected
, render_pass
->quad_list
.front()->material
);
4541 TEST_F(PictureLayerImplTest
, DrawSolidQuads
) {
4542 TestQuadsForSolidColor(true);
4545 TEST_F(PictureLayerImplTest
, DrawNonSolidQuads
) {
4546 TestQuadsForSolidColor(false);
4549 TEST_F(PictureLayerImplTest
, NonSolidToSolidNoTilings
) {
4550 base::TimeTicks time_ticks
;
4551 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4552 host_impl_
.SetCurrentBeginFrameArgs(
4553 CreateBeginFrameArgsForTesting(time_ticks
));
4555 gfx::Size
tile_size(100, 100);
4556 gfx::Size
layer_bounds(200, 200);
4557 gfx::Rect
layer_rect(layer_bounds
);
4559 FakeContentLayerClient client
;
4560 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
4561 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4562 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&host_client
);
4563 host
->SetRootLayer(layer
);
4564 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4566 host_impl_
.SetViewportSize(layer_bounds
);
4568 int frame_number
= 0;
4570 client
.set_fill_with_nonsolid_color(true);
4572 Region
invalidation1(layer_rect
);
4573 recording_source
->UpdateAndExpandInvalidation(
4574 &client
, &invalidation1
, false, layer_bounds
, layer_rect
, frame_number
++,
4575 Picture::RECORD_NORMALLY
);
4577 scoped_refptr
<RasterSource
> raster_source1
=
4578 recording_source
->CreateRasterSource();
4580 SetupPendingTree(raster_source1
);
4582 host_impl_
.active_tree()->UpdateDrawProperties();
4584 // We've started with a solid layer that contains some tilings.
4585 ASSERT_TRUE(active_layer_
->tilings());
4586 EXPECT_NE(0u, active_layer_
->tilings()->num_tilings());
4588 client
.set_fill_with_nonsolid_color(false);
4590 Region
invalidation2(layer_rect
);
4591 recording_source
->UpdateAndExpandInvalidation(
4592 &client
, &invalidation2
, false, layer_bounds
, layer_rect
, frame_number
++,
4593 Picture::RECORD_NORMALLY
);
4595 scoped_refptr
<RasterSource
> raster_source2
=
4596 recording_source
->CreateRasterSource();
4598 SetupPendingTree(raster_source2
);
4601 // We've switched to a solid color, so we should end up with no tilings.
4602 ASSERT_TRUE(active_layer_
->tilings());
4603 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4606 TEST_F(PictureLayerImplTest
, ChangeInViewportAllowsTilingUpdates
) {
4607 base::TimeTicks time_ticks
;
4608 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4609 host_impl_
.SetCurrentBeginFrameArgs(
4610 CreateBeginFrameArgsForTesting(time_ticks
));
4612 gfx::Size
tile_size(100, 100);
4613 gfx::Size
layer_bounds(400, 4000);
4615 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4616 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4617 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4618 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4620 SetupTrees(pending_pile
, active_pile
);
4622 Region invalidation
;
4623 gfx::Rect viewport
= gfx::Rect(0, 0, 100, 100);
4624 gfx::Transform transform
;
4626 host_impl_
.SetRequiresHighResToDraw();
4629 pending_layer_
->draw_properties().visible_content_rect
= viewport
;
4630 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4631 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
4632 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
4634 // Ensure we can't activate.
4635 EXPECT_FALSE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
4637 // Now in the same frame, move the viewport (this can happen during
4639 viewport
= gfx::Rect(0, 2000, 100, 100);
4642 pending_layer_
->draw_properties().visible_content_rect
= viewport
;
4643 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4644 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
4645 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
4647 // Make sure all viewport tiles (viewport from the tiling) are ready to draw.
4648 std::vector
<Tile
*> tiles
;
4649 for (PictureLayerTiling::CoverageIterator
iter(
4650 pending_layer_
->HighResTiling(),
4652 pending_layer_
->HighResTiling()->GetCurrentVisibleRectForTesting());
4656 tiles
.push_back(*iter
);
4659 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4661 // Ensure we can activate.
4662 EXPECT_TRUE(pending_layer_
->AllTilesRequiredForActivationAreReadyToDraw());
4665 class TileSizeSettings
: public ImplSidePaintingSettings
{
4667 TileSizeSettings() {
4668 default_tile_size
= gfx::Size(100, 100);
4669 max_untiled_layer_size
= gfx::Size(200, 200);
4673 class TileSizeTest
: public PictureLayerImplTest
{
4675 TileSizeTest() : PictureLayerImplTest(TileSizeSettings()) {}
4678 TEST_F(TileSizeTest
, TileSizes
) {
4679 host_impl_
.CreatePendingTree();
4681 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
4682 scoped_ptr
<FakePictureLayerImpl
> layer
=
4683 FakePictureLayerImpl::Create(pending_tree
, id_
);
4685 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
4688 host_impl_
.SetUseGpuRasterization(false);
4690 // Default tile-size for large layers.
4691 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
4692 EXPECT_EQ(result
.width(), 100);
4693 EXPECT_EQ(result
.height(), 100);
4694 // Don't tile and round-up, when under max_untiled_layer_size.
4695 result
= layer
->CalculateTileSize(gfx::Size(42, 42));
4696 EXPECT_EQ(result
.width(), 64);
4697 EXPECT_EQ(result
.height(), 64);
4698 result
= layer
->CalculateTileSize(gfx::Size(191, 191));
4699 EXPECT_EQ(result
.width(), 192);
4700 EXPECT_EQ(result
.height(), 192);
4701 result
= layer
->CalculateTileSize(gfx::Size(199, 199));
4702 EXPECT_EQ(result
.width(), 200);
4703 EXPECT_EQ(result
.height(), 200);
4705 // Gpu-rasterization uses 25% viewport-height tiles.
4706 // The +2's below are for border texels.
4707 host_impl_
.SetUseGpuRasterization(true);
4708 host_impl_
.SetViewportSize(gfx::Size(2000, 2000));
4709 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
4710 EXPECT_EQ(result
.width(), 2000);
4711 EXPECT_EQ(result
.height(), 500 + 2);
4713 // Clamp and round-up, when smaller than viewport.
4714 // Tile-height doubles to 50% when width shrinks to <= 50%.
4715 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
4716 result
= layer
->CalculateTileSize(gfx::Size(447, 10000));
4717 EXPECT_EQ(result
.width(), 448);
4718 EXPECT_EQ(result
.height(), 500 + 2);
4720 // Largest layer is 50% of viewport width (rounded up), and
4721 // 50% of viewport in height.
4722 result
= layer
->CalculateTileSize(gfx::Size(447, 400));
4723 EXPECT_EQ(result
.width(), 448);
4724 EXPECT_EQ(result
.height(), 448);
4725 result
= layer
->CalculateTileSize(gfx::Size(500, 499));
4726 EXPECT_EQ(result
.width(), 512);
4727 EXPECT_EQ(result
.height(), 500 + 2);