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/resources/tiling_set_raster_queue_all.h"
18 #include "cc/resources/tiling_set_raster_queue_required.h"
19 #include "cc/test/begin_frame_args_test.h"
20 #include "cc/test/fake_content_layer_client.h"
21 #include "cc/test/fake_impl_proxy.h"
22 #include "cc/test/fake_layer_tree_host_impl.h"
23 #include "cc/test/fake_output_surface.h"
24 #include "cc/test/fake_picture_layer_impl.h"
25 #include "cc/test/fake_picture_pile_impl.h"
26 #include "cc/test/geometry_test_utils.h"
27 #include "cc/test/impl_side_painting_settings.h"
28 #include "cc/test/layer_test_common.h"
29 #include "cc/test/test_shared_bitmap_manager.h"
30 #include "cc/test/test_web_graphics_context_3d.h"
31 #include "cc/trees/layer_tree_impl.h"
32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "ui/gfx/geometry/rect_conversions.h"
34 #include "ui/gfx/geometry/size_conversions.h"
39 #define EXPECT_BOTH_EQ(expression, x) \
41 EXPECT_EQ(x, pending_layer_->expression); \
42 EXPECT_EQ(x, active_layer_->expression); \
45 #define EXPECT_BOTH_NE(expression, x) \
47 EXPECT_NE(x, pending_layer_->expression); \
48 EXPECT_NE(x, active_layer_->expression); \
51 class MockCanvas
: public SkCanvas
{
53 explicit MockCanvas(int w
, int h
) : SkCanvas(w
, h
) {}
55 void onDrawRect(const SkRect
& rect
, const SkPaint
& paint
) override
{
56 // Capture calls before SkCanvas quickReject() kicks in.
57 rects_
.push_back(rect
);
60 std::vector
<SkRect
> rects_
;
63 class NoLowResTilingsSettings
: public ImplSidePaintingSettings
{};
65 class LowResTilingsSettings
: public ImplSidePaintingSettings
{
67 LowResTilingsSettings() { create_low_res_tiling
= true; }
70 class PictureLayerImplTest
: public testing::Test
{
72 PictureLayerImplTest()
73 : proxy_(base::MessageLoopProxy::current()),
74 host_impl_(LowResTilingsSettings(), &proxy_
, &shared_bitmap_manager_
),
77 pending_layer_(nullptr),
78 old_pending_layer_(nullptr),
79 active_layer_(nullptr) {
80 host_impl_
.SetViewportSize(gfx::Size(10000, 10000));
83 explicit PictureLayerImplTest(const LayerTreeSettings
& settings
)
84 : proxy_(base::MessageLoopProxy::current()),
85 host_impl_(settings
, &proxy_
, &shared_bitmap_manager_
),
88 host_impl_
.SetViewportSize(gfx::Size(10000, 10000));
91 ~PictureLayerImplTest() override
{}
93 void SetUp() override
{ InitializeRenderer(); }
95 virtual void InitializeRenderer() {
96 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d());
99 void SetupDefaultTrees(const gfx::Size
& layer_bounds
) {
100 gfx::Size
tile_size(100, 100);
102 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
103 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
104 scoped_refptr
<FakePicturePileImpl
> active_pile
=
105 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
107 SetupTrees(pending_pile
, active_pile
);
110 void SetupDefaultTreesWithInvalidation(const gfx::Size
& layer_bounds
,
111 const Region
& invalidation
) {
112 gfx::Size
tile_size(100, 100);
114 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
115 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
116 scoped_refptr
<FakePicturePileImpl
> active_pile
=
117 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
119 SetupTreesWithInvalidation(pending_pile
, active_pile
, invalidation
);
122 void ActivateTree() {
123 host_impl_
.ActivateSyncTree();
124 CHECK(!host_impl_
.pending_tree());
125 CHECK(host_impl_
.recycle_tree());
126 old_pending_layer_
= pending_layer_
;
127 pending_layer_
= nullptr;
128 active_layer_
= static_cast<FakePictureLayerImpl
*>(
129 host_impl_
.active_tree()->LayerById(id_
));
131 bool update_lcd_text
= false;
132 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
135 void SetupDefaultTreesWithFixedTileSize(const gfx::Size
& layer_bounds
,
136 const gfx::Size
& tile_size
,
137 const Region
& invalidation
) {
138 gfx::Size
pile_tile_size(100, 100);
140 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
141 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, layer_bounds
);
142 scoped_refptr
<FakePicturePileImpl
> active_pile
=
143 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, layer_bounds
);
145 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
,
150 scoped_refptr
<PicturePileImpl
> pending_pile
,
151 scoped_refptr
<PicturePileImpl
> active_pile
) {
152 SetupPendingTree(active_pile
);
154 SetupPendingTreeInternal(pending_pile
, gfx::Size(), Region());
157 void SetupTreesWithInvalidation(scoped_refptr
<PicturePileImpl
> pending_pile
,
158 scoped_refptr
<PicturePileImpl
> active_pile
,
159 const Region
& pending_invalidation
) {
160 SetupPendingTreeInternal(active_pile
, gfx::Size(), Region());
162 SetupPendingTreeInternal(pending_pile
, gfx::Size(), pending_invalidation
);
165 void SetupTreesWithFixedTileSize(scoped_refptr
<PicturePileImpl
> pending_pile
,
166 scoped_refptr
<PicturePileImpl
> active_pile
,
167 const gfx::Size
& tile_size
,
168 const Region
& pending_invalidation
) {
169 SetupPendingTreeInternal(active_pile
, tile_size
, Region());
171 SetupPendingTreeInternal(pending_pile
, tile_size
, pending_invalidation
);
174 void SetupPendingTree(scoped_refptr
<RasterSource
> raster_source
) {
175 SetupPendingTreeInternal(raster_source
, gfx::Size(), Region());
178 void SetupPendingTreeWithInvalidation(
179 scoped_refptr
<RasterSource
> raster_source
,
180 const Region
& invalidation
) {
181 SetupPendingTreeInternal(raster_source
, gfx::Size(), invalidation
);
184 void SetupPendingTreeWithFixedTileSize(
185 scoped_refptr
<RasterSource
> raster_source
,
186 const gfx::Size
& tile_size
,
187 const Region
& invalidation
) {
188 SetupPendingTreeInternal(raster_source
, tile_size
, invalidation
);
191 void SetupPendingTreeInternal(scoped_refptr
<RasterSource
> raster_source
,
192 const gfx::Size
& tile_size
,
193 const Region
& invalidation
) {
194 host_impl_
.CreatePendingTree();
195 host_impl_
.pending_tree()->PushPageScaleFromMainThread(1.f
, 0.25f
, 100.f
);
196 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
198 // Steal from the recycled tree if possible.
199 scoped_ptr
<LayerImpl
> pending_root
= pending_tree
->DetachLayerTree();
200 scoped_ptr
<FakePictureLayerImpl
> pending_layer
;
201 DCHECK_IMPLIES(pending_root
, pending_root
->id() == root_id_
);
203 pending_root
= LayerImpl::Create(pending_tree
, root_id_
);
204 pending_layer
= FakePictureLayerImpl::Create(pending_tree
, id_
);
205 if (!tile_size
.IsEmpty())
206 pending_layer
->set_fixed_tile_size(tile_size
);
207 pending_layer
->SetDrawsContent(true);
209 pending_layer
.reset(static_cast<FakePictureLayerImpl
*>(
210 pending_root
->RemoveChild(pending_root
->children()[0]).release()));
211 if (!tile_size
.IsEmpty())
212 pending_layer
->set_fixed_tile_size(tile_size
);
214 pending_root
->SetHasRenderSurface(true);
215 // The bounds() just mirror the pile size.
216 pending_layer
->SetBounds(raster_source
->GetSize());
217 pending_layer
->SetContentBounds(raster_source
->GetSize());
218 pending_layer
->SetRasterSourceOnPending(raster_source
, invalidation
);
220 pending_root
->AddChild(pending_layer
.Pass());
221 pending_tree
->SetRootLayer(pending_root
.Pass());
223 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
224 host_impl_
.pending_tree()->LayerById(id_
));
226 // Add tilings/tiles for the layer.
227 bool update_lcd_text
= false;
228 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
231 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl
* layer
,
232 float ideal_contents_scale
,
233 float device_scale_factor
,
234 float page_scale_factor
,
235 float maximum_animation_contents_scale
,
236 bool animating_transform_to_screen
) {
237 layer
->draw_properties().ideal_contents_scale
= ideal_contents_scale
;
238 layer
->draw_properties().device_scale_factor
= device_scale_factor
;
239 layer
->draw_properties().page_scale_factor
= page_scale_factor
;
240 layer
->draw_properties().maximum_animation_contents_scale
=
241 maximum_animation_contents_scale
;
242 layer
->draw_properties().screen_space_transform_is_animating
=
243 animating_transform_to_screen
;
244 bool resourceless_software_draw
= false;
245 layer
->UpdateTiles(resourceless_software_draw
);
247 static void VerifyAllTilesExistAndHavePile(
248 const PictureLayerTiling
* tiling
,
249 PicturePileImpl
* pile
) {
250 for (PictureLayerTiling::CoverageIterator
iter(
252 tiling
->contents_scale(),
253 gfx::Rect(tiling
->tiling_size()));
257 EXPECT_EQ(pile
, iter
->raster_source());
261 void SetContentsScaleOnBothLayers(float contents_scale
,
262 float device_scale_factor
,
263 float page_scale_factor
,
264 float maximum_animation_contents_scale
,
265 bool animating_transform
) {
266 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
270 maximum_animation_contents_scale
,
271 animating_transform
);
273 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
277 maximum_animation_contents_scale
,
278 animating_transform
);
281 void ResetTilingsAndRasterScales() {
282 pending_layer_
->ReleaseResources();
283 EXPECT_FALSE(pending_layer_
->tilings());
284 pending_layer_
->RecreateResources();
285 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
287 active_layer_
->ReleaseResources();
288 EXPECT_FALSE(active_layer_
->tilings());
289 active_layer_
->RecreateResources();
290 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
293 void AssertAllTilesRequired(PictureLayerTiling
* tiling
) {
294 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
295 for (size_t i
= 0; i
< tiles
.size(); ++i
)
296 EXPECT_TRUE(tiles
[i
]->required_for_activation()) << "i: " << i
;
297 EXPECT_GT(tiles
.size(), 0u);
300 void AssertNoTilesRequired(PictureLayerTiling
* tiling
) {
301 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
302 for (size_t i
= 0; i
< tiles
.size(); ++i
)
303 EXPECT_FALSE(tiles
[i
]->required_for_activation()) << "i: " << i
;
304 EXPECT_GT(tiles
.size(), 0u);
308 void TestQuadsForSolidColor(bool test_for_solid
);
310 FakeImplProxy proxy_
;
311 TestSharedBitmapManager shared_bitmap_manager_
;
312 FakeLayerTreeHostImpl host_impl_
;
315 FakePictureLayerImpl
* pending_layer_
;
316 FakePictureLayerImpl
* old_pending_layer_
;
317 FakePictureLayerImpl
* active_layer_
;
320 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest
);
323 class NoLowResPictureLayerImplTest
: public PictureLayerImplTest
{
325 NoLowResPictureLayerImplTest()
326 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
329 TEST_F(PictureLayerImplTest
, TileGridAlignment
) {
330 // Layer to span 4 raster tiles in x and in y
331 ImplSidePaintingSettings settings
;
332 gfx::Size
layer_size(settings
.default_tile_size
.width() * 7 / 2,
333 settings
.default_tile_size
.height() * 7 / 2);
335 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
336 FakePicturePileImpl::CreateFilledPile(layer_size
, layer_size
);
338 scoped_ptr
<FakePicturePile
> active_recording
=
339 FakePicturePile::CreateFilledPile(layer_size
, layer_size
);
340 scoped_refptr
<FakePicturePileImpl
> active_pile
=
341 FakePicturePileImpl::CreateFromPile(active_recording
.get(), nullptr);
343 SetupTrees(pending_pile
, active_pile
);
345 // Add 1x1 rects at the centers of each tile, then re-record pile contents
346 active_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
347 std::vector
<Tile
*> tiles
=
348 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
349 EXPECT_EQ(16u, tiles
.size());
350 std::vector
<SkRect
> rects
;
351 std::vector
<Tile
*>::const_iterator tile_iter
;
352 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
353 gfx::Point tile_center
= (*tile_iter
)->content_rect().CenterPoint();
354 gfx::Rect
rect(tile_center
.x(), tile_center
.y(), 1, 1);
355 active_recording
->add_draw_rect(rect
);
356 rects
.push_back(SkRect::MakeXYWH(rect
.x(), rect
.y(), 1, 1));
359 // Force re-raster with newly injected content
360 active_recording
->RemoveRecordingAt(0, 0);
361 active_recording
->AddRecordingAt(0, 0);
363 scoped_refptr
<FakePicturePileImpl
> updated_active_pile
=
364 FakePicturePileImpl::CreateFromPile(active_recording
.get(), nullptr);
366 std::vector
<SkRect
>::const_iterator rect_iter
= rects
.begin();
367 for (tile_iter
= tiles
.begin(); tile_iter
< tiles
.end(); tile_iter
++) {
368 MockCanvas
mock_canvas(1000, 1000);
369 updated_active_pile
->PlaybackToSharedCanvas(
370 &mock_canvas
, (*tile_iter
)->content_rect(), 1.0f
);
372 // This test verifies that when drawing the contents of a specific tile
373 // at content scale 1.0, the playback canvas never receives content from
374 // neighboring tiles which indicates that the tile grid embedded in
375 // SkPicture is perfectly aligned with the compositor's tiles.
376 EXPECT_EQ(1u, mock_canvas
.rects_
.size());
377 EXPECT_EQ(*rect_iter
, mock_canvas
.rects_
[0]);
382 TEST_F(PictureLayerImplTest
, CloneNoInvalidation
) {
383 gfx::Size
tile_size(100, 100);
384 gfx::Size
layer_bounds(400, 400);
386 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
387 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
388 scoped_refptr
<FakePicturePileImpl
> active_pile
=
389 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
391 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
393 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
394 active_layer_
->tilings()->num_tilings());
396 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
397 EXPECT_GT(tilings
->num_tilings(), 0u);
398 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
399 VerifyAllTilesExistAndHavePile(tilings
->tiling_at(i
), pending_pile
.get());
402 TEST_F(PictureLayerImplTest
, ExternalViewportRectForPrioritizingTiles
) {
403 base::TimeTicks time_ticks
;
404 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
405 host_impl_
.SetCurrentBeginFrameArgs(
406 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
407 gfx::Size
tile_size(100, 100);
408 gfx::Size
layer_bounds(400, 400);
410 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
411 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
412 scoped_refptr
<FakePicturePileImpl
> active_pile
=
413 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
415 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
417 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
419 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
420 host_impl_
.SetCurrentBeginFrameArgs(
421 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
423 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the
424 // identify transform for tile priority.
425 bool resourceless_software_draw
= false;
426 gfx::Rect viewport
= gfx::Rect(layer_bounds
),
427 viewport_rect_for_tile_priority
= gfx::Rect(0, 0, 100, 100);
428 gfx::Transform transform
, transform_for_tile_priority
;
430 host_impl_
.SetExternalDrawConstraints(transform
,
433 viewport_rect_for_tile_priority
,
434 transform_for_tile_priority
,
435 resourceless_software_draw
);
436 bool update_lcd_text
= false;
437 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
439 gfx::Rect viewport_rect_for_tile_priority_in_view_space
=
440 viewport_rect_for_tile_priority
;
442 // Verify the viewport rect for tile priority is used in picture layer tiling.
443 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
444 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
445 PictureLayerTilingSet
* tilings
= active_layer_
->tilings();
446 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
447 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
449 tiling
->GetCurrentVisibleRectForTesting(),
450 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
451 tiling
->contents_scale()));
454 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in
455 // screen space and the transform for tile priority is translated and
456 // rotated. The actual viewport for tile priority used by PictureLayerImpl
457 // should be (200, 200, 100, 100) applied with the said transform.
458 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
459 host_impl_
.SetCurrentBeginFrameArgs(
460 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
462 viewport_rect_for_tile_priority
= gfx::Rect(200, 200, 100, 100);
463 transform_for_tile_priority
.Translate(100, 100);
464 transform_for_tile_priority
.Rotate(45);
465 host_impl_
.SetExternalDrawConstraints(transform
,
468 viewport_rect_for_tile_priority
,
469 transform_for_tile_priority
,
470 resourceless_software_draw
);
471 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
473 gfx::Transform
screen_to_view(gfx::Transform::kSkipInitialization
);
474 bool success
= transform_for_tile_priority
.GetInverse(&screen_to_view
);
475 EXPECT_TRUE(success
);
477 // Note that we don't clip this to the layer bounds, since it is expected that
478 // the rect will sometimes be outside of the layer bounds. If we clip to
479 // bounds, then tile priorities will end up being incorrect in cases of fully
481 viewport_rect_for_tile_priority_in_view_space
=
482 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
483 screen_to_view
, viewport_rect_for_tile_priority
));
485 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space
,
486 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
487 tilings
= active_layer_
->tilings();
488 for (size_t i
= 0; i
< tilings
->num_tilings(); i
++) {
489 PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
491 tiling
->GetCurrentVisibleRectForTesting(),
492 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space
,
493 tiling
->contents_scale()));
497 TEST_F(PictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
498 base::TimeTicks time_ticks
;
499 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
500 host_impl_
.SetCurrentBeginFrameArgs(
501 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
503 gfx::Size
tile_size(100, 100);
504 gfx::Size
layer_bounds(400, 400);
506 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
507 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
508 scoped_refptr
<FakePicturePileImpl
> active_pile
=
509 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
511 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
513 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
515 // UpdateTiles with valid viewport. Should update tile viewport.
516 // Note viewport is considered invalid if and only if in resourceless
518 bool resourceless_software_draw
= false;
519 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
520 gfx::Transform transform
;
521 host_impl_
.SetExternalDrawConstraints(transform
,
526 resourceless_software_draw
);
527 active_layer_
->draw_properties().visible_content_rect
= viewport
;
528 active_layer_
->draw_properties().screen_space_transform
= transform
;
529 active_layer_
->UpdateTiles(resourceless_software_draw
);
531 gfx::Rect visible_rect_for_tile_priority
=
532 active_layer_
->visible_rect_for_tile_priority();
533 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
534 gfx::Transform screen_space_transform_for_tile_priority
=
535 active_layer_
->screen_space_transform();
537 // Expand viewport and set it as invalid for prioritizing tiles.
538 // Should update viewport and transform, but not update visible rect.
539 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
540 host_impl_
.SetCurrentBeginFrameArgs(
541 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
542 resourceless_software_draw
= true;
543 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
544 transform
.Translate(1.f
, 1.f
);
545 active_layer_
->draw_properties().visible_content_rect
= viewport
;
546 active_layer_
->draw_properties().screen_space_transform
= transform
;
547 host_impl_
.SetExternalDrawConstraints(transform
,
552 resourceless_software_draw
);
553 active_layer_
->UpdateTiles(resourceless_software_draw
);
555 // Transform for tile priority is updated.
556 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
557 active_layer_
->screen_space_transform());
558 // Visible rect for tile priority retains old value.
559 EXPECT_EQ(visible_rect_for_tile_priority
,
560 active_layer_
->visible_rect_for_tile_priority());
562 // Keep expanded viewport but mark it valid. Should update tile viewport.
563 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
564 host_impl_
.SetCurrentBeginFrameArgs(
565 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
566 resourceless_software_draw
= false;
567 host_impl_
.SetExternalDrawConstraints(transform
,
572 resourceless_software_draw
);
573 active_layer_
->UpdateTiles(resourceless_software_draw
);
575 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
576 active_layer_
->screen_space_transform());
577 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
580 TEST_F(PictureLayerImplTest
, ViewportRectForTilePriorityIsCached
) {
581 base::TimeTicks time_ticks
;
582 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
583 host_impl_
.SetCurrentBeginFrameArgs(
584 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
585 gfx::Size
tile_size(100, 100);
586 gfx::Size
layer_bounds(400, 400);
588 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
589 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
590 scoped_refptr
<FakePicturePileImpl
> active_pile
=
591 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
593 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
595 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
597 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
598 host_impl_
.SetCurrentBeginFrameArgs(
599 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
601 bool resourceless_software_draw
= false;
602 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
603 gfx::Rect
viewport_rect_for_tile_priority(0, 0, 100, 100);
604 gfx::Transform transform
, transform_for_tile_priority
;
606 host_impl_
.SetExternalDrawConstraints(
607 transform
, viewport
, viewport
, viewport_rect_for_tile_priority
,
608 transform_for_tile_priority
, resourceless_software_draw
);
609 bool update_lcd_text
= false;
610 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
612 EXPECT_EQ(viewport_rect_for_tile_priority
,
613 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
615 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
616 host_impl_
.SetCurrentBeginFrameArgs(
617 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
619 gfx::Rect
another_viewport_rect_for_tile_priority(11, 11, 50, 50);
620 host_impl_
.SetExternalDrawConstraints(
621 transform
, viewport
, viewport
, another_viewport_rect_for_tile_priority
,
622 transform_for_tile_priority
, resourceless_software_draw
);
624 // Didn't call UpdateDrawProperties yet. The viewport rect for tile priority
625 // should remain to be the previously cached value.
626 EXPECT_EQ(viewport_rect_for_tile_priority
,
627 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
628 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
630 // Now the UpdateDrawProperties is called. The viewport rect for tile
631 // priority should be the latest value.
632 EXPECT_EQ(another_viewport_rect_for_tile_priority
,
633 active_layer_
->viewport_rect_for_tile_priority_in_content_space());
636 TEST_F(PictureLayerImplTest
, ClonePartialInvalidation
) {
637 gfx::Size
tile_size(100, 100);
638 gfx::Size
layer_bounds(400, 400);
639 gfx::Rect
layer_invalidation(150, 200, 30, 180);
641 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
642 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
643 scoped_refptr
<FakePicturePileImpl
> active_pile
=
644 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
645 scoped_refptr
<FakePicturePileImpl
> lost_pile
=
646 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
648 SetupPendingTreeWithFixedTileSize(lost_pile
, gfx::Size(50, 50), Region());
650 // Add a non-shared tiling on the active tree.
651 PictureLayerTiling
* tiling
= active_layer_
->AddTiling(3.f
);
652 tiling
->CreateAllTilesForTesting();
654 // Ensure UpdateTiles won't remove any tilings.
655 active_layer_
->MarkAllTilingsUsed();
657 // Then setup a new pending tree and activate it.
658 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, gfx::Size(50, 50),
661 EXPECT_EQ(2u, pending_layer_
->num_tilings());
662 EXPECT_EQ(3u, active_layer_
->num_tilings());
664 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
665 EXPECT_GT(tilings
->num_tilings(), 0u);
666 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
667 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
668 gfx::Rect content_invalidation
= gfx::ScaleToEnclosingRect(
670 tiling
->contents_scale());
671 for (PictureLayerTiling::CoverageIterator
iter(
673 tiling
->contents_scale(),
674 gfx::Rect(tiling
->tiling_size()));
678 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
679 EXPECT_EQ(pending_pile
.get(), iter
->raster_source());
683 tilings
= active_layer_
->tilings();
684 EXPECT_GT(tilings
->num_tilings(), 0u);
685 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
) {
686 const PictureLayerTiling
* tiling
= tilings
->tiling_at(i
);
687 gfx::Rect content_invalidation
=
688 gfx::ScaleToEnclosingRect(layer_invalidation
, tiling
->contents_scale());
689 for (PictureLayerTiling::CoverageIterator
iter(
691 tiling
->contents_scale(),
692 gfx::Rect(tiling
->tiling_size()));
696 EXPECT_FALSE(iter
.geometry_rect().IsEmpty());
697 if (iter
.geometry_rect().Intersects(content_invalidation
))
698 EXPECT_EQ(active_pile
.get(), iter
->raster_source());
699 else if (!active_layer_
->GetPendingOrActiveTwinTiling(tiling
))
700 EXPECT_EQ(active_pile
.get(), iter
->raster_source());
702 EXPECT_EQ(pending_pile
.get(), iter
->raster_source());
707 TEST_F(PictureLayerImplTest
, CloneFullInvalidation
) {
708 gfx::Size
tile_size(90, 80);
709 gfx::Size
layer_bounds(300, 500);
711 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
712 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
713 scoped_refptr
<FakePicturePileImpl
> active_pile
=
714 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
716 SetupTreesWithInvalidation(pending_pile
, active_pile
,
717 gfx::Rect(layer_bounds
));
719 EXPECT_EQ(pending_layer_
->tilings()->num_tilings(),
720 active_layer_
->tilings()->num_tilings());
722 const PictureLayerTilingSet
* tilings
= pending_layer_
->tilings();
723 EXPECT_GT(tilings
->num_tilings(), 0u);
724 for (size_t i
= 0; i
< tilings
->num_tilings(); ++i
)
725 VerifyAllTilesExistAndHavePile(tilings
->tiling_at(i
), pending_pile
.get());
728 TEST_F(PictureLayerImplTest
, UpdateTilesCreatesTilings
) {
729 gfx::Size
tile_size(400, 400);
730 gfx::Size
layer_bounds(1300, 1900);
732 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
733 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
734 scoped_refptr
<FakePicturePileImpl
> active_pile
=
735 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
737 SetupTrees(pending_pile
, active_pile
);
739 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
740 EXPECT_LT(low_res_factor
, 1.f
);
742 active_layer_
->ReleaseResources();
743 EXPECT_FALSE(active_layer_
->tilings());
744 active_layer_
->RecreateResources();
745 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
747 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
748 6.f
, // ideal contents scale
751 1.f
, // maximum animation scale
753 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
755 active_layer_
->tilings()->tiling_at(0)->contents_scale());
756 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
757 active_layer_
->tilings()->tiling_at(1)->contents_scale());
759 // If we change the page scale factor, then we should get new tilings.
760 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
761 6.6f
, // ideal contents scale
764 1.f
, // maximum animation scale
766 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
767 EXPECT_FLOAT_EQ(6.6f
,
768 active_layer_
->tilings()->tiling_at(0)->contents_scale());
769 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
770 active_layer_
->tilings()->tiling_at(2)->contents_scale());
772 // If we change the device scale factor, then we should get new tilings.
773 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
774 7.26f
, // ideal contents scale
775 3.3f
, // device scale
777 1.f
, // maximum animation scale
779 ASSERT_EQ(6u, active_layer_
->tilings()->num_tilings());
780 EXPECT_FLOAT_EQ(7.26f
,
781 active_layer_
->tilings()->tiling_at(0)->contents_scale());
782 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
783 active_layer_
->tilings()->tiling_at(3)->contents_scale());
785 // If we change the device scale factor, but end up at the same total scale
786 // factor somehow, then we don't get new tilings.
787 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
788 7.26f
, // ideal contents scale
789 2.2f
, // device scale
791 1.f
, // maximum animation scale
793 ASSERT_EQ(6u, active_layer_
->tilings()->num_tilings());
794 EXPECT_FLOAT_EQ(7.26f
,
795 active_layer_
->tilings()->tiling_at(0)->contents_scale());
796 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
797 active_layer_
->tilings()->tiling_at(3)->contents_scale());
800 TEST_F(PictureLayerImplTest
, PendingLayerOnlyHasHighAndLowResTiling
) {
801 gfx::Size
tile_size(400, 400);
802 gfx::Size
layer_bounds(1300, 1900);
804 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
805 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
806 scoped_refptr
<FakePicturePileImpl
> active_pile
=
807 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
809 SetupTrees(pending_pile
, active_pile
);
811 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
812 EXPECT_LT(low_res_factor
, 1.f
);
814 pending_layer_
->ReleaseResources();
815 EXPECT_FALSE(pending_layer_
->tilings());
816 pending_layer_
->RecreateResources();
817 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
819 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
820 6.f
, // ideal contents scale
823 1.f
, // maximum animation scale
825 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
827 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
828 EXPECT_FLOAT_EQ(6.f
* low_res_factor
,
829 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
831 // If we change the page scale factor, then we should get new tilings.
832 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
833 6.6f
, // ideal contents scale
836 1.f
, // maximum animation scale
838 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
839 EXPECT_FLOAT_EQ(6.6f
,
840 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
841 EXPECT_FLOAT_EQ(6.6f
* low_res_factor
,
842 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
844 // If we change the device scale factor, then we should get new tilings.
845 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
846 7.26f
, // ideal contents scale
847 3.3f
, // device scale
849 1.f
, // maximum animation scale
851 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
852 EXPECT_FLOAT_EQ(7.26f
,
853 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
854 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
855 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
857 // If we change the device scale factor, but end up at the same total scale
858 // factor somehow, then we don't get new tilings.
859 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
860 7.26f
, // ideal contents scale
861 2.2f
, // device scale
863 1.f
, // maximum animation scale
865 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
866 EXPECT_FLOAT_EQ(7.26f
,
867 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
868 EXPECT_FLOAT_EQ(7.26f
* low_res_factor
,
869 pending_layer_
->tilings()->tiling_at(1)->contents_scale());
872 TEST_F(PictureLayerImplTest
, CreateTilingsEvenIfTwinHasNone
) {
873 // This test makes sure that if a layer can have tilings, then a commit makes
874 // it not able to have tilings (empty size), and then a future commit that
875 // makes it valid again should be able to create tilings.
876 gfx::Size
tile_size(400, 400);
877 gfx::Size
layer_bounds(1300, 1900);
879 scoped_refptr
<FakePicturePileImpl
> empty_pile
=
880 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
881 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
882 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
884 SetupPendingTree(valid_pile
);
885 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
888 SetupPendingTree(empty_pile
);
889 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
890 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
891 ASSERT_EQ(0u, pending_layer_
->tilings()->num_tilings());
894 EXPECT_FALSE(active_layer_
->CanHaveTilings());
895 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
897 SetupPendingTree(valid_pile
);
898 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
899 ASSERT_EQ(0u, active_layer_
->tilings()->num_tilings());
902 TEST_F(PictureLayerImplTest
, ZoomOutCrash
) {
903 gfx::Size
tile_size(400, 400);
904 gfx::Size
layer_bounds(1300, 1900);
906 // Set up the high and low res tilings before pinch zoom.
907 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
908 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
909 scoped_refptr
<FakePicturePileImpl
> active_pile
=
910 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
912 SetupTrees(pending_pile
, active_pile
);
913 ResetTilingsAndRasterScales();
914 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
915 SetContentsScaleOnBothLayers(32.0f
, 1.0f
, 32.0f
, 1.0f
, false);
916 EXPECT_EQ(32.f
, active_layer_
->HighResTiling()->contents_scale());
917 host_impl_
.PinchGestureBegin();
918 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, false);
919 SetContentsScaleOnBothLayers(1.0f
, 1.0f
, 1.0f
, 1.0f
, false);
920 EXPECT_EQ(active_layer_
->tilings()->NumHighResTilings(), 1);
923 TEST_F(PictureLayerImplTest
, PinchGestureTilings
) {
924 gfx::Size
tile_size(400, 400);
925 gfx::Size
layer_bounds(1300, 1900);
927 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
929 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
930 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
931 scoped_refptr
<FakePicturePileImpl
> active_pile
=
932 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
934 // Set up the high and low res tilings before pinch zoom.
935 SetupTrees(pending_pile
, active_pile
);
936 ResetTilingsAndRasterScales();
938 SetContentsScaleOnBothLayers(2.f
, 1.0f
, 2.f
, 1.0f
, false);
939 EXPECT_BOTH_EQ(num_tilings(), 2u);
940 EXPECT_BOTH_EQ(tilings()->tiling_at(0)->contents_scale(), 2.f
);
941 EXPECT_BOTH_EQ(tilings()->tiling_at(1)->contents_scale(),
942 2.f
* low_res_factor
);
944 // Ensure UpdateTiles won't remove any tilings.
945 active_layer_
->MarkAllTilingsUsed();
947 // Start a pinch gesture.
948 host_impl_
.PinchGestureBegin();
950 // Zoom out by a small amount. We should create a tiling at half
951 // the scale (2/kMaxScaleRatioDuringPinch).
952 SetContentsScaleOnBothLayers(1.8f
, 1.0f
, 1.8f
, 1.0f
, false);
953 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
954 EXPECT_FLOAT_EQ(2.0f
,
955 active_layer_
->tilings()->tiling_at(0)->contents_scale());
956 EXPECT_FLOAT_EQ(1.0f
,
957 active_layer_
->tilings()->tiling_at(1)->contents_scale());
958 EXPECT_FLOAT_EQ(2.0f
* low_res_factor
,
959 active_layer_
->tilings()->tiling_at(2)->contents_scale());
961 // Ensure UpdateTiles won't remove any tilings.
962 active_layer_
->MarkAllTilingsUsed();
964 // Zoom out further, close to our low-res scale factor. We should
965 // use that tiling as high-res, and not create a new tiling.
966 SetContentsScaleOnBothLayers(low_res_factor
* 2.1f
, 1.0f
,
967 low_res_factor
* 2.1f
, 1.0f
, false);
968 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
970 // Zoom in a lot now. Since we increase by increments of
971 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0.
972 SetContentsScaleOnBothLayers(3.8f
, 1.0f
, 3.8f
, 1.f
, false);
973 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
974 EXPECT_FLOAT_EQ(4.0f
,
975 active_layer_
->tilings()->tiling_at(0)->contents_scale());
978 TEST_F(PictureLayerImplTest
, SnappedTilingDuringZoom
) {
979 gfx::Size
tile_size(300, 300);
980 gfx::Size
layer_bounds(2600, 3800);
982 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
983 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
984 scoped_refptr
<FakePicturePileImpl
> active_pile
=
985 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
987 SetupTrees(pending_pile
, active_pile
);
989 ResetTilingsAndRasterScales();
990 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
992 // Set up the high and low res tilings before pinch zoom.
993 SetContentsScaleOnBothLayers(0.24f
, 1.0f
, 0.24f
, 1.0f
, false);
994 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
995 EXPECT_FLOAT_EQ(0.24f
,
996 active_layer_
->tilings()->tiling_at(0)->contents_scale());
997 EXPECT_FLOAT_EQ(0.0625f
,
998 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1000 // Ensure UpdateTiles won't remove any tilings.
1001 active_layer_
->MarkAllTilingsUsed();
1003 // Start a pinch gesture.
1004 host_impl_
.PinchGestureBegin();
1006 // Zoom out by a small amount. We should create a tiling at half
1007 // the scale (1/kMaxScaleRatioDuringPinch).
1008 SetContentsScaleOnBothLayers(0.2f
, 1.0f
, 0.2f
, 1.0f
, false);
1009 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1010 EXPECT_FLOAT_EQ(0.24f
,
1011 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1012 EXPECT_FLOAT_EQ(0.12f
,
1013 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1014 EXPECT_FLOAT_EQ(0.0625,
1015 active_layer_
->tilings()->tiling_at(2)->contents_scale());
1017 // Ensure UpdateTiles won't remove any tilings.
1018 active_layer_
->MarkAllTilingsUsed();
1020 // Zoom out further, close to our low-res scale factor. We should
1021 // use that tiling as high-res, and not create a new tiling.
1022 SetContentsScaleOnBothLayers(0.1f
, 1.0f
, 0.1f
, 1.0f
, false);
1023 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1025 // Zoom in. 0.25(desired_scale) should be snapped to 0.24 during zoom-in
1026 // because 0.25(desired_scale) is within the ratio(1.2).
1027 SetContentsScaleOnBothLayers(0.25f
, 1.0f
, 0.25f
, 1.0f
, false);
1028 EXPECT_EQ(3u, active_layer_
->tilings()->num_tilings());
1030 // Zoom in a lot. Since we move in factors of two, we should get a scale that
1031 // is a power of 2 times 0.24.
1032 SetContentsScaleOnBothLayers(1.f
, 1.0f
, 1.f
, 1.0f
, false);
1033 EXPECT_EQ(4u, active_layer_
->tilings()->num_tilings());
1034 EXPECT_FLOAT_EQ(1.92f
,
1035 active_layer_
->tilings()->tiling_at(0)->contents_scale());
1038 TEST_F(PictureLayerImplTest
, CleanUpTilings
) {
1039 gfx::Size
tile_size(400, 400);
1040 gfx::Size
layer_bounds(1300, 1900);
1042 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1043 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1044 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1045 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1047 std::vector
<PictureLayerTiling
*> used_tilings
;
1049 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1050 EXPECT_LT(low_res_factor
, 1.f
);
1053 float page_scale
= 1.f
;
1055 SetupTrees(pending_pile
, active_pile
);
1056 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1057 EXPECT_EQ(1.f
, active_layer_
->HighResTiling()->contents_scale());
1059 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
1060 // |used_tilings| variable, and it's here only to ensure that active_layer_
1061 // won't remove tilings before the test has a chance to verify behavior.
1062 active_layer_
->MarkAllTilingsUsed();
1064 // We only have ideal tilings, so they aren't removed.
1065 used_tilings
.clear();
1066 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1067 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1069 host_impl_
.PinchGestureBegin();
1071 // Changing the ideal but not creating new tilings.
1074 SetContentsScaleOnBothLayers(scale
, 1.f
, page_scale
, 1.f
, false);
1075 EXPECT_EQ(2u, active_layer_
->tilings()->num_tilings());
1077 // The tilings are still our target scale, so they aren't removed.
1078 used_tilings
.clear();
1079 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1080 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
1082 host_impl_
.PinchGestureEnd();
1084 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
1087 SetContentsScaleOnBothLayers(1.2f
, 1.f
, page_scale
, 1.f
, false);
1088 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
1091 active_layer_
->tilings()->tiling_at(1)->contents_scale());
1093 1.f
* low_res_factor
,
1094 active_layer_
->tilings()->tiling_at(3)->contents_scale());
1096 // Ensure UpdateTiles won't remove any tilings.
1097 active_layer_
->MarkAllTilingsUsed();
1099 // Mark the non-ideal tilings as used. They won't be removed.
1100 used_tilings
.clear();
1101 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1102 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(3));
1103 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1104 ASSERT_EQ(4u, active_layer_
->tilings()->num_tilings());
1106 // Now move the ideal scale to 0.5. Our target stays 1.2.
1107 SetContentsScaleOnBothLayers(0.5f
, 1.f
, page_scale
, 1.f
, false);
1109 // The high resolution tiling is between target and ideal, so is not
1110 // removed. The low res tiling for the old ideal=1.0 scale is removed.
1111 used_tilings
.clear();
1112 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1113 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1115 // Now move the ideal scale to 1.0. Our target stays 1.2.
1116 SetContentsScaleOnBothLayers(1.f
, 1.f
, page_scale
, 1.f
, false);
1118 // All the tilings are between are target and the ideal, so they are not
1120 used_tilings
.clear();
1121 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1122 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1124 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
1125 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.1f
, 1.f
, page_scale
, 1.f
,
1128 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1129 // in the range [1.0,1.2] and are kept.
1130 used_tilings
.clear();
1131 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1132 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1134 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1136 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.1f
, 1.f
, page_scale
, 1.f
,
1139 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1140 // target raster scale. But it is in our used tilings set, so nothing is
1142 used_tilings
.clear();
1143 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
1144 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1145 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
1147 // If we remove it from our used tilings set, it is outside the range to keep
1148 // so it is deleted.
1149 used_tilings
.clear();
1150 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
1151 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
1154 TEST_F(PictureLayerImplTest
, DontAddLowResDuringAnimation
) {
1155 // Make sure this layer covers multiple tiles, since otherwise low
1156 // res won't get created because it is too small.
1157 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1158 // Avoid max untiled layer size heuristics via fixed tile size.
1159 gfx::Size
layer_bounds(tile_size
.width() + 1, tile_size
.height() + 1);
1160 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
1162 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1163 float contents_scale
= 1.f
;
1164 float device_scale
= 1.f
;
1165 float page_scale
= 1.f
;
1166 float maximum_animation_scale
= 1.f
;
1167 bool animating_transform
= true;
1169 ResetTilingsAndRasterScales();
1171 // Animating, so don't create low res even if there isn't one already.
1172 SetContentsScaleOnBothLayers(contents_scale
,
1175 maximum_animation_scale
,
1176 animating_transform
);
1177 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1178 EXPECT_BOTH_EQ(num_tilings(), 1u);
1180 // Stop animating, low res gets created.
1181 animating_transform
= false;
1182 SetContentsScaleOnBothLayers(contents_scale
,
1185 maximum_animation_scale
,
1186 animating_transform
);
1187 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
1188 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor
);
1189 EXPECT_BOTH_EQ(num_tilings(), 2u);
1191 // Ensure UpdateTiles won't remove any tilings.
1192 active_layer_
->MarkAllTilingsUsed();
1194 // Page scale animation, new high res, but no low res. We still have
1195 // a tiling at the previous scale, it's just not marked as low res on the
1196 // active layer. The pending layer drops non-ideal tilings.
1197 contents_scale
= 2.f
;
1199 maximum_animation_scale
= 2.f
;
1200 animating_transform
= true;
1201 SetContentsScaleOnBothLayers(contents_scale
,
1204 maximum_animation_scale
,
1205 animating_transform
);
1206 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1207 EXPECT_FALSE(active_layer_
->LowResTiling());
1208 EXPECT_FALSE(pending_layer_
->LowResTiling());
1209 EXPECT_EQ(3u, active_layer_
->num_tilings());
1210 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1212 // Stop animating, new low res gets created for final page scale.
1213 animating_transform
= false;
1214 SetContentsScaleOnBothLayers(contents_scale
,
1217 maximum_animation_scale
,
1218 animating_transform
);
1219 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
1220 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f
* low_res_factor
);
1221 EXPECT_EQ(4u, active_layer_
->num_tilings());
1222 EXPECT_EQ(2u, pending_layer_
->num_tilings());
1225 TEST_F(PictureLayerImplTest
, DontAddLowResForSmallLayers
) {
1226 gfx::Size
layer_bounds(host_impl_
.settings().default_tile_size
);
1227 gfx::Size
tile_size(100, 100);
1229 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1230 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1231 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1232 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1234 SetupTrees(pending_pile
, active_pile
);
1236 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
1237 float device_scale
= 1.f
;
1238 float page_scale
= 1.f
;
1239 float maximum_animation_scale
= 1.f
;
1240 bool animating_transform
= false;
1242 // Contents exactly fit on one tile at scale 1, no low res.
1243 float contents_scale
= 1.f
;
1244 SetContentsScaleOnBothLayers(contents_scale
,
1247 maximum_animation_scale
,
1248 animating_transform
);
1249 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1250 EXPECT_BOTH_EQ(num_tilings(), 1u);
1252 ResetTilingsAndRasterScales();
1254 // Contents that are smaller than one tile, no low res.
1255 contents_scale
= 0.123f
;
1256 SetContentsScaleOnBothLayers(contents_scale
,
1259 maximum_animation_scale
,
1260 animating_transform
);
1261 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1262 EXPECT_BOTH_EQ(num_tilings(), 1u);
1264 ResetTilingsAndRasterScales();
1266 // Any content bounds that would create more than one tile will
1267 // generate a low res tiling.
1268 contents_scale
= 2.5f
;
1269 SetContentsScaleOnBothLayers(contents_scale
,
1272 maximum_animation_scale
,
1273 animating_transform
);
1274 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale
);
1275 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1276 contents_scale
* low_res_factor
);
1277 EXPECT_BOTH_EQ(num_tilings(), 2u);
1279 // Mask layers dont create low res since they always fit on one tile.
1280 scoped_ptr
<FakePictureLayerImpl
> mask
=
1281 FakePictureLayerImpl::CreateMaskWithRasterSource(
1282 host_impl_
.pending_tree(), 3, pending_pile
);
1283 mask
->SetBounds(layer_bounds
);
1284 mask
->SetContentBounds(layer_bounds
);
1285 mask
->SetDrawsContent(true);
1287 SetupDrawPropertiesAndUpdateTiles(mask
.get(), contents_scale
, device_scale
,
1288 page_scale
, maximum_animation_scale
,
1289 animating_transform
);
1290 EXPECT_EQ(mask
->HighResTiling()->contents_scale(), contents_scale
);
1291 EXPECT_EQ(mask
->num_tilings(), 1u);
1294 TEST_F(PictureLayerImplTest
, HugeMasksGetScaledDown
) {
1295 base::TimeTicks time_ticks
;
1296 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1297 host_impl_
.SetCurrentBeginFrameArgs(
1298 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1300 gfx::Size
tile_size(100, 100);
1301 gfx::Size
layer_bounds(1000, 1000);
1303 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1304 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1305 SetupPendingTree(valid_pile
);
1307 scoped_ptr
<FakePictureLayerImpl
> mask_ptr
=
1308 FakePictureLayerImpl::CreateMaskWithRasterSource(
1309 host_impl_
.pending_tree(), 3, valid_pile
);
1310 mask_ptr
->SetBounds(layer_bounds
);
1311 mask_ptr
->SetContentBounds(layer_bounds
);
1312 mask_ptr
->SetDrawsContent(true);
1313 pending_layer_
->SetMaskLayer(mask_ptr
.Pass());
1314 pending_layer_
->SetHasRenderSurface(true);
1316 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1317 host_impl_
.SetCurrentBeginFrameArgs(
1318 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1319 bool update_lcd_text
= false;
1320 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1322 FakePictureLayerImpl
* pending_mask
=
1323 static_cast<FakePictureLayerImpl
*>(pending_layer_
->mask_layer());
1325 EXPECT_EQ(1.f
, pending_mask
->HighResTiling()->contents_scale());
1326 EXPECT_EQ(1u, pending_mask
->num_tilings());
1328 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1329 pending_mask
->HighResTiling()->AllTilesForTesting());
1333 FakePictureLayerImpl
* active_mask
=
1334 static_cast<FakePictureLayerImpl
*>(active_layer_
->mask_layer());
1336 // Mask layers have a tiling with a single tile in it.
1337 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1338 // The mask resource exists.
1339 ResourceProvider::ResourceId mask_resource_id
;
1340 gfx::Size mask_texture_size
;
1341 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1342 EXPECT_NE(0u, mask_resource_id
);
1343 EXPECT_EQ(active_mask
->bounds(), mask_texture_size
);
1345 // Drop resources and recreate them, still the same.
1346 pending_mask
->ReleaseResources();
1347 active_mask
->ReleaseResources();
1348 pending_mask
->RecreateResources();
1349 active_mask
->RecreateResources();
1350 SetupDrawPropertiesAndUpdateTiles(active_mask
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1351 active_mask
->HighResTiling()->CreateAllTilesForTesting();
1352 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1353 EXPECT_NE(0u, mask_resource_id
);
1354 EXPECT_EQ(active_mask
->bounds(), mask_texture_size
);
1356 // Resize larger than the max texture size.
1357 int max_texture_size
= host_impl_
.GetRendererCapabilities().max_texture_size
;
1358 gfx::Size
huge_bounds(max_texture_size
+ 1, 10);
1359 scoped_refptr
<FakePicturePileImpl
> huge_pile
=
1360 FakePicturePileImpl::CreateFilledPile(tile_size
, huge_bounds
);
1362 SetupPendingTree(huge_pile
);
1363 pending_mask
->SetBounds(huge_bounds
);
1364 pending_mask
->SetContentBounds(huge_bounds
);
1365 pending_mask
->SetRasterSourceOnPending(huge_pile
, Region());
1367 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1368 host_impl_
.SetCurrentBeginFrameArgs(
1369 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1370 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1372 // The mask tiling gets scaled down.
1373 EXPECT_LT(pending_mask
->HighResTiling()->contents_scale(), 1.f
);
1374 EXPECT_EQ(1u, pending_mask
->num_tilings());
1376 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1377 pending_mask
->HighResTiling()->AllTilesForTesting());
1381 // Mask layers have a tiling with a single tile in it.
1382 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1383 // The mask resource exists.
1384 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1385 EXPECT_NE(0u, mask_resource_id
);
1386 gfx::Size expected_size
= active_mask
->bounds();
1387 expected_size
.SetToMin(gfx::Size(max_texture_size
, max_texture_size
));
1388 EXPECT_EQ(expected_size
, mask_texture_size
);
1390 // Drop resources and recreate them, still the same.
1391 pending_mask
->ReleaseResources();
1392 active_mask
->ReleaseResources();
1393 pending_mask
->RecreateResources();
1394 active_mask
->RecreateResources();
1395 SetupDrawPropertiesAndUpdateTiles(active_mask
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1396 active_mask
->HighResTiling()->CreateAllTilesForTesting();
1397 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1398 EXPECT_NE(0u, mask_resource_id
);
1399 EXPECT_EQ(expected_size
, mask_texture_size
);
1401 // Do another activate, the same holds.
1402 SetupPendingTree(huge_pile
);
1404 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1405 active_layer_
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1406 EXPECT_EQ(expected_size
, mask_texture_size
);
1407 EXPECT_EQ(0u, mask_resource_id
);
1409 // Resize even larger, so that the scale would be smaller than the minimum
1410 // contents scale. Then the layer should no longer have any tiling.
1411 float min_contents_scale
= host_impl_
.settings().minimum_contents_scale
;
1412 gfx::Size
extra_huge_bounds(max_texture_size
/ min_contents_scale
+ 1, 10);
1413 scoped_refptr
<FakePicturePileImpl
> extra_huge_pile
=
1414 FakePicturePileImpl::CreateFilledPile(tile_size
, extra_huge_bounds
);
1416 SetupPendingTree(extra_huge_pile
);
1417 pending_mask
->SetBounds(extra_huge_bounds
);
1418 pending_mask
->SetContentBounds(extra_huge_bounds
);
1419 pending_mask
->SetRasterSourceOnPending(extra_huge_pile
, Region());
1421 EXPECT_FALSE(pending_mask
->CanHaveTilings());
1423 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1424 host_impl_
.SetCurrentBeginFrameArgs(
1425 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1426 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1428 EXPECT_EQ(0u, pending_mask
->num_tilings());
1431 TEST_F(PictureLayerImplTest
, ScaledMaskLayer
) {
1432 base::TimeTicks time_ticks
;
1433 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1434 host_impl_
.SetCurrentBeginFrameArgs(
1435 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1437 gfx::Size
tile_size(100, 100);
1438 gfx::Size
layer_bounds(1000, 1000);
1440 host_impl_
.SetDeviceScaleFactor(1.3f
);
1442 scoped_refptr
<FakePicturePileImpl
> valid_pile
=
1443 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1444 SetupPendingTree(valid_pile
);
1446 scoped_ptr
<FakePictureLayerImpl
> mask_ptr
=
1447 FakePictureLayerImpl::CreateMaskWithRasterSource(
1448 host_impl_
.pending_tree(), 3, valid_pile
);
1449 mask_ptr
->SetBounds(layer_bounds
);
1450 mask_ptr
->SetContentBounds(layer_bounds
);
1451 mask_ptr
->SetDrawsContent(true);
1452 pending_layer_
->SetMaskLayer(mask_ptr
.Pass());
1453 pending_layer_
->SetHasRenderSurface(true);
1455 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1456 host_impl_
.SetCurrentBeginFrameArgs(
1457 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1458 bool update_lcd_text
= false;
1459 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1461 FakePictureLayerImpl
* pending_mask
=
1462 static_cast<FakePictureLayerImpl
*>(pending_layer_
->mask_layer());
1464 // Masks are scaled, and do not have a low res tiling.
1465 EXPECT_EQ(1.3f
, pending_mask
->HighResTiling()->contents_scale());
1466 EXPECT_EQ(1u, pending_mask
->num_tilings());
1468 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1469 pending_mask
->HighResTiling()->AllTilesForTesting());
1473 FakePictureLayerImpl
* active_mask
=
1474 static_cast<FakePictureLayerImpl
*>(active_layer_
->mask_layer());
1476 // Mask layers have a tiling with a single tile in it.
1477 EXPECT_EQ(1u, active_mask
->HighResTiling()->AllTilesForTesting().size());
1478 // The mask resource exists.
1479 ResourceProvider::ResourceId mask_resource_id
;
1480 gfx::Size mask_texture_size
;
1481 active_mask
->GetContentsResourceId(&mask_resource_id
, &mask_texture_size
);
1482 EXPECT_NE(0u, mask_resource_id
);
1483 gfx::Size expected_mask_texture_size
=
1484 gfx::ToCeiledSize(gfx::ScaleSize(active_mask
->bounds(), 1.3f
));
1485 EXPECT_EQ(mask_texture_size
, expected_mask_texture_size
);
1488 TEST_F(PictureLayerImplTest
, ReleaseResources
) {
1489 gfx::Size
tile_size(400, 400);
1490 gfx::Size
layer_bounds(1300, 1900);
1492 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1493 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1494 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1495 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1497 SetupTrees(pending_pile
, active_pile
);
1498 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1500 // All tilings should be removed when losing output surface.
1501 active_layer_
->ReleaseResources();
1502 EXPECT_FALSE(active_layer_
->tilings());
1503 active_layer_
->RecreateResources();
1504 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
1505 pending_layer_
->ReleaseResources();
1506 EXPECT_FALSE(pending_layer_
->tilings());
1507 pending_layer_
->RecreateResources();
1508 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
1510 // This should create new tilings.
1511 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
1512 1.f
, // ideal contents scale
1513 1.f
, // device scale
1515 1.f
, // maximum animation scale
1517 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1520 TEST_F(PictureLayerImplTest
, ClampTilesToToMaxTileSize
) {
1521 // The default max tile size is larger than 400x400.
1522 gfx::Size
tile_size(400, 400);
1523 gfx::Size
layer_bounds(5000, 5000);
1525 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1526 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1527 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1528 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1530 SetupTrees(pending_pile
, active_pile
);
1531 EXPECT_GE(pending_layer_
->tilings()->num_tilings(), 1u);
1533 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1535 // The default value.
1536 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1537 host_impl_
.settings().default_tile_size
.ToString());
1539 Tile
* tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1540 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1541 tile
->content_rect().size().ToString());
1543 ResetTilingsAndRasterScales();
1545 // Change the max texture size on the output surface context.
1546 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1547 TestWebGraphicsContext3D::Create();
1548 context
->set_max_texture_size(140);
1549 host_impl_
.DidLoseOutputSurface();
1550 host_impl_
.InitializeRenderer(
1551 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1553 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1554 ASSERT_EQ(2u, pending_layer_
->tilings()->num_tilings());
1556 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1558 // Verify the tiles are not larger than the context's max texture size.
1559 tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1560 EXPECT_GE(140, tile
->content_rect().width());
1561 EXPECT_GE(140, tile
->content_rect().height());
1564 TEST_F(PictureLayerImplTest
, ClampSingleTileToToMaxTileSize
) {
1565 // The default max tile size is larger than 400x400.
1566 gfx::Size
tile_size(400, 400);
1567 gfx::Size
layer_bounds(500, 500);
1569 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1570 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1571 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1572 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1574 SetupTrees(pending_pile
, active_pile
);
1575 EXPECT_GE(pending_layer_
->tilings()->num_tilings(), 1u);
1577 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1579 // The default value. The layer is smaller than this.
1580 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1581 host_impl_
.settings().max_untiled_layer_size
.ToString());
1583 // There should be a single tile since the layer is small.
1584 PictureLayerTiling
* high_res_tiling
= pending_layer_
->tilings()->tiling_at(0);
1585 EXPECT_EQ(1u, high_res_tiling
->AllTilesForTesting().size());
1587 ResetTilingsAndRasterScales();
1589 // Change the max texture size on the output surface context.
1590 scoped_ptr
<TestWebGraphicsContext3D
> context
=
1591 TestWebGraphicsContext3D::Create();
1592 context
->set_max_texture_size(140);
1593 host_impl_
.DidLoseOutputSurface();
1594 host_impl_
.InitializeRenderer(
1595 FakeOutputSurface::Create3d(context
.Pass()).Pass());
1597 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1598 ASSERT_LE(1u, pending_layer_
->tilings()->num_tilings());
1600 pending_layer_
->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1602 // There should be more than one tile since the max texture size won't cover
1604 high_res_tiling
= pending_layer_
->tilings()->tiling_at(0);
1605 EXPECT_LT(1u, high_res_tiling
->AllTilesForTesting().size());
1607 // Verify the tiles are not larger than the context's max texture size.
1608 Tile
* tile
= pending_layer_
->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1609 EXPECT_GE(140, tile
->content_rect().width());
1610 EXPECT_GE(140, tile
->content_rect().height());
1613 TEST_F(PictureLayerImplTest
, DisallowTileDrawQuads
) {
1614 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1616 gfx::Size
tile_size(400, 400);
1617 gfx::Size
layer_bounds(1300, 1900);
1619 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1620 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1621 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1622 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1624 gfx::Rect
layer_invalidation(150, 200, 30, 180);
1625 SetupTreesWithInvalidation(pending_pile
, active_pile
, layer_invalidation
);
1627 active_layer_
->draw_properties().visible_content_rect
=
1628 gfx::Rect(layer_bounds
);
1630 AppendQuadsData data
;
1631 active_layer_
->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE
, nullptr);
1632 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1633 active_layer_
->DidDraw(nullptr);
1635 ASSERT_EQ(1U, render_pass
->quad_list
.size());
1636 EXPECT_EQ(DrawQuad::PICTURE_CONTENT
,
1637 render_pass
->quad_list
.front()->material
);
1640 TEST_F(PictureLayerImplTest
, SolidColorLayerHasVisibleFullCoverage
) {
1641 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1643 gfx::Size
tile_size(1000, 1000);
1644 gfx::Size
layer_bounds(1500, 1500);
1645 gfx::Rect
visible_rect(250, 250, 1000, 1000);
1647 scoped_ptr
<FakePicturePile
> empty_recording
=
1648 FakePicturePile::CreateEmptyPile(tile_size
, layer_bounds
);
1649 empty_recording
->SetIsSolidColor(true);
1651 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1652 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
1653 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1654 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
1656 SetupTrees(pending_pile
, active_pile
);
1658 active_layer_
->draw_properties().visible_content_rect
= visible_rect
;
1660 AppendQuadsData data
;
1661 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1662 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1663 active_layer_
->DidDraw(nullptr);
1665 Region remaining
= visible_rect
;
1666 for (const auto& quad
: render_pass
->quad_list
) {
1667 EXPECT_TRUE(visible_rect
.Contains(quad
->rect
));
1668 EXPECT_TRUE(remaining
.Contains(quad
->rect
));
1669 remaining
.Subtract(quad
->rect
);
1672 EXPECT_TRUE(remaining
.IsEmpty());
1675 TEST_F(PictureLayerImplTest
, TileScalesWithSolidColorPile
) {
1676 gfx::Size
layer_bounds(200, 200);
1677 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
1678 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1679 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1680 tile_size
, layer_bounds
, false);
1681 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1682 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1683 tile_size
, layer_bounds
, true);
1685 SetupTrees(pending_pile
, active_pile
);
1686 // Solid color pile should not allow tilings at any scale.
1687 EXPECT_FALSE(active_layer_
->CanHaveTilings());
1688 EXPECT_EQ(0.f
, active_layer_
->ideal_contents_scale());
1690 // Activate non-solid-color pending pile makes active layer can have tilings.
1692 EXPECT_TRUE(active_layer_
->CanHaveTilings());
1693 EXPECT_GT(active_layer_
->ideal_contents_scale(), 0.f
);
1696 TEST_F(NoLowResPictureLayerImplTest
, MarkRequiredOffscreenTiles
) {
1697 gfx::Size
tile_size(100, 100);
1698 gfx::Size
layer_bounds(200, 200);
1700 gfx::Transform transform
;
1701 gfx::Transform transform_for_tile_priority
;
1702 bool resourceless_software_draw
= false;
1703 gfx::Rect
viewport(0, 0, 100, 200);
1704 host_impl_
.SetExternalDrawConstraints(transform
,
1709 resourceless_software_draw
);
1711 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1712 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1713 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1715 EXPECT_EQ(1u, pending_layer_
->num_tilings());
1716 EXPECT_EQ(viewport
, pending_layer_
->visible_rect_for_tile_priority());
1718 base::TimeTicks time_ticks
;
1719 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1720 host_impl_
.SetCurrentBeginFrameArgs(
1721 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1722 pending_layer_
->UpdateTiles(resourceless_software_draw
);
1724 int num_visible
= 0;
1725 int num_offscreen
= 0;
1727 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
1728 pending_layer_
->picture_layer_tiling_set(), false));
1729 for (; !queue
->IsEmpty(); queue
->Pop()) {
1730 const Tile
* tile
= queue
->Top();
1732 if (tile
->priority(PENDING_TREE
).distance_to_visible
== 0.f
) {
1733 EXPECT_TRUE(tile
->required_for_activation());
1736 EXPECT_FALSE(tile
->required_for_activation());
1741 EXPECT_GT(num_visible
, 0);
1742 EXPECT_GT(num_offscreen
, 0);
1745 TEST_F(NoLowResPictureLayerImplTest
,
1746 TileOutsideOfViewportForTilePriorityNotRequired
) {
1747 base::TimeTicks time_ticks
;
1748 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1749 host_impl_
.SetCurrentBeginFrameArgs(
1750 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1752 gfx::Size
tile_size(100, 100);
1753 gfx::Size
layer_bounds(400, 400);
1754 gfx::Rect
external_viewport_for_tile_priority(400, 200);
1755 gfx::Rect
visible_content_rect(200, 400);
1757 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1758 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1759 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1760 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1761 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
1763 ASSERT_EQ(1u, pending_layer_
->num_tilings());
1764 ASSERT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
1766 // Set external viewport for tile priority.
1767 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
1768 gfx::Transform transform
;
1769 gfx::Transform transform_for_tile_priority
;
1770 bool resourceless_software_draw
= false;
1771 host_impl_
.SetExternalDrawConstraints(transform
,
1774 external_viewport_for_tile_priority
,
1775 transform_for_tile_priority
,
1776 resourceless_software_draw
);
1777 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1778 host_impl_
.SetCurrentBeginFrameArgs(
1779 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1780 bool update_lcd_text
= false;
1781 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
1783 // Set visible content rect that is different from
1784 // external_viewport_for_tile_priority.
1785 pending_layer_
->draw_properties().visible_content_rect
= visible_content_rect
;
1786 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
1787 host_impl_
.SetCurrentBeginFrameArgs(
1788 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1789 pending_layer_
->UpdateTiles(resourceless_software_draw
);
1791 // Intersect the two rects. Any tile outside should not be required for
1793 gfx::Rect viewport_for_tile_priority
=
1794 pending_layer_
->viewport_rect_for_tile_priority_in_content_space();
1795 viewport_for_tile_priority
.Intersect(pending_layer_
->visible_content_rect());
1798 int num_outside
= 0;
1799 for (PictureLayerTiling::CoverageIterator
iter(
1800 pending_layer_
->HighResTiling(), 1.f
, gfx::Rect(layer_bounds
));
1805 if (viewport_for_tile_priority
.Intersects(iter
.geometry_rect())) {
1807 // Mark everything in viewport for tile priority as ready to draw.
1808 TileDrawInfo
& draw_info
= tile
->draw_info();
1809 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
1812 EXPECT_FALSE(tile
->required_for_activation());
1816 EXPECT_GT(num_inside
, 0);
1817 EXPECT_GT(num_outside
, 0);
1819 // Activate and draw active layer.
1820 host_impl_
.ActivateSyncTree();
1821 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
1822 active_layer_
->draw_properties().visible_content_rect
= visible_content_rect
;
1824 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1825 AppendQuadsData data
;
1826 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1827 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1828 active_layer_
->DidDraw(nullptr);
1830 // All tiles in activation rect is ready to draw.
1831 EXPECT_EQ(0u, data
.num_missing_tiles
);
1832 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1833 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1836 TEST_F(PictureLayerImplTest
, HighResTileIsComplete
) {
1837 base::TimeTicks time_ticks
;
1838 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1839 host_impl_
.SetCurrentBeginFrameArgs(
1840 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1842 gfx::Size
tile_size(100, 100);
1843 gfx::Size
layer_bounds(200, 200);
1845 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1846 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1848 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1851 // All high res tiles have resources.
1852 std::vector
<Tile
*> tiles
=
1853 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1854 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
1856 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1857 AppendQuadsData data
;
1858 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1859 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1860 active_layer_
->DidDraw(nullptr);
1862 // All high res tiles drew, nothing was incomplete.
1863 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1864 EXPECT_EQ(0u, data
.num_missing_tiles
);
1865 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1866 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1869 TEST_F(PictureLayerImplTest
, HighResTileIsIncomplete
) {
1870 base::TimeTicks time_ticks
;
1871 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1872 host_impl_
.SetCurrentBeginFrameArgs(
1873 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1875 gfx::Size
tile_size(100, 100);
1876 gfx::Size
layer_bounds(200, 200);
1878 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1879 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1880 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1883 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1884 AppendQuadsData data
;
1885 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1886 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1887 active_layer_
->DidDraw(nullptr);
1889 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1890 EXPECT_EQ(1u, data
.num_missing_tiles
);
1891 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
1892 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1895 TEST_F(PictureLayerImplTest
, HighResTileIsIncompleteLowResComplete
) {
1896 base::TimeTicks time_ticks
;
1897 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1898 host_impl_
.SetCurrentBeginFrameArgs(
1899 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1901 gfx::Size
tile_size(100, 100);
1902 gfx::Size
layer_bounds(200, 200);
1904 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1905 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1906 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1909 std::vector
<Tile
*> low_tiles
=
1910 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1911 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1913 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1914 AppendQuadsData data
;
1915 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1916 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1917 active_layer_
->DidDraw(nullptr);
1919 EXPECT_EQ(1u, render_pass
->quad_list
.size());
1920 EXPECT_EQ(0u, data
.num_missing_tiles
);
1921 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1922 EXPECT_TRUE(active_layer_
->only_used_low_res_last_append_quads());
1925 TEST_F(PictureLayerImplTest
, LowResTileIsIncomplete
) {
1926 base::TimeTicks time_ticks
;
1927 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1928 host_impl_
.SetCurrentBeginFrameArgs(
1929 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1931 gfx::Size
tile_size(100, 100);
1932 gfx::Size
layer_bounds(200, 200);
1934 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1935 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1936 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
1939 // All high res tiles have resources except one.
1940 std::vector
<Tile
*> high_tiles
=
1941 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
1942 high_tiles
.erase(high_tiles
.begin());
1943 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
1945 // All low res tiles have resources.
1946 std::vector
<Tile
*> low_tiles
=
1947 active_layer_
->tilings()->tiling_at(1)->AllTilesForTesting();
1948 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles
);
1950 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
1951 AppendQuadsData data
;
1952 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
1953 active_layer_
->AppendQuads(render_pass
.get(), &data
);
1954 active_layer_
->DidDraw(nullptr);
1956 // The missing high res tile was replaced by a low res tile.
1957 EXPECT_EQ(9u, render_pass
->quad_list
.size());
1958 EXPECT_EQ(0u, data
.num_missing_tiles
);
1959 EXPECT_EQ(1u, data
.num_incomplete_tiles
);
1960 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
1963 TEST_F(PictureLayerImplTest
,
1964 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal
) {
1965 base::TimeTicks time_ticks
;
1966 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
1967 host_impl_
.SetCurrentBeginFrameArgs(
1968 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
1970 gfx::Size
tile_size(100, 100);
1971 gfx::Size
layer_bounds(200, 200);
1972 gfx::Size
viewport_size(400, 400);
1974 host_impl_
.SetViewportSize(viewport_size
);
1975 host_impl_
.SetDeviceScaleFactor(2.f
);
1977 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
1978 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1979 scoped_refptr
<FakePicturePileImpl
> active_pile
=
1980 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
1981 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
1983 // One ideal tile exists, this will get used when drawing.
1984 std::vector
<Tile
*> ideal_tiles
;
1985 EXPECT_EQ(2.f
, active_layer_
->HighResTiling()->contents_scale());
1986 ideal_tiles
.push_back(active_layer_
->HighResTiling()->TileAt(0, 0));
1987 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(
1990 // Due to layer scale throttling, the raster contents scale is changed to 1,
1991 // while the ideal is still 2.
1992 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
1993 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.f
, 1.f
, 1.f
, 1.f
, false);
1995 EXPECT_EQ(1.f
, active_layer_
->HighResTiling()->contents_scale());
1996 EXPECT_EQ(1.f
, active_layer_
->raster_contents_scale());
1997 EXPECT_EQ(2.f
, active_layer_
->ideal_contents_scale());
1999 // Both tilings still exist.
2000 EXPECT_EQ(2.f
, active_layer_
->tilings()->tiling_at(0)->contents_scale());
2001 EXPECT_EQ(1.f
, active_layer_
->tilings()->tiling_at(1)->contents_scale());
2003 // All high res tiles have resources.
2004 std::vector
<Tile
*> high_tiles
=
2005 active_layer_
->HighResTiling()->AllTilesForTesting();
2006 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles
);
2008 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
2009 AppendQuadsData data
;
2010 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
2011 active_layer_
->AppendQuads(render_pass
.get(), &data
);
2012 active_layer_
->DidDraw(nullptr);
2014 // All high res tiles drew, and the one ideal res tile drew.
2015 ASSERT_GT(render_pass
->quad_list
.size(), 9u);
2016 EXPECT_EQ(gfx::SizeF(99.f
, 99.f
),
2017 TileDrawQuad::MaterialCast(render_pass
->quad_list
.front())
2018 ->tex_coord_rect
.size());
2019 EXPECT_EQ(gfx::SizeF(49.5f
, 49.5f
),
2020 TileDrawQuad::MaterialCast(render_pass
->quad_list
.ElementAt(1))
2021 ->tex_coord_rect
.size());
2023 // Neither the high res nor the ideal tiles were considered as incomplete.
2024 EXPECT_EQ(0u, data
.num_missing_tiles
);
2025 EXPECT_EQ(0u, data
.num_incomplete_tiles
);
2026 EXPECT_FALSE(active_layer_
->only_used_low_res_last_append_quads());
2029 TEST_F(PictureLayerImplTest
, HighResRequiredWhenUnsharedActiveAllReady
) {
2030 gfx::Size
layer_bounds(400, 400);
2031 gfx::Size
tile_size(100, 100);
2034 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
,
2035 gfx::Rect(layer_bounds
));
2037 active_layer_
->SetAllTilesReady();
2039 // No shared tiles and all active tiles ready, so pending can only
2040 // activate with all high res tiles.
2041 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2042 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2044 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2045 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2048 TEST_F(PictureLayerImplTest
, HighResRequiredWhenMissingHighResFlagOn
) {
2049 gfx::Size
layer_bounds(400, 400);
2050 gfx::Size
tile_size(100, 100);
2052 // All tiles shared (no invalidation).
2053 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2055 // Verify active tree not ready.
2056 Tile
* some_active_tile
=
2057 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2058 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
2060 // When high res are required, even if the active tree is not ready,
2061 // the high res tiles must be ready.
2062 host_impl_
.SetRequiresHighResToDraw();
2064 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2065 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2067 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2068 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2071 TEST_F(PictureLayerImplTest
, AllHighResRequiredEvenIfShared
) {
2072 gfx::Size
layer_bounds(400, 400);
2073 gfx::Size
tile_size(100, 100);
2075 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2077 Tile
* some_active_tile
=
2078 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2079 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
2081 // All tiles shared (no invalidation), so even though the active tree's
2082 // tiles aren't ready, the high res tiles are required for activation.
2083 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2084 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2086 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2087 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2090 TEST_F(PictureLayerImplTest
, DisallowRequiredForActivation
) {
2091 gfx::Size
layer_bounds(400, 400);
2092 gfx::Size
tile_size(100, 100);
2094 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
2096 Tile
* some_active_tile
=
2097 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
2098 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
2100 pending_layer_
->HighResTiling()->set_can_require_tiles_for_activation(false);
2101 pending_layer_
->LowResTiling()->set_can_require_tiles_for_activation(false);
2103 // If we disallow required for activation, no tiles can be required.
2104 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2105 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2107 AssertNoTilesRequired(pending_layer_
->HighResTiling());
2108 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2111 TEST_F(PictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
2112 gfx::Size
layer_bounds(400, 400);
2113 gfx::Size
tile_size(100, 100);
2115 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2116 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2117 // This pile will create tilings, but has no recordings so will not create any
2118 // tiles. This is attempting to simulate scrolling past the end of recorded
2119 // content on the active layer, where the recordings are so far away that
2120 // no tiles are created.
2121 bool is_solid_color
= false;
2122 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2123 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
2124 tile_size
, layer_bounds
, is_solid_color
);
2126 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2128 // Active layer has tilings, but no tiles due to missing recordings.
2129 EXPECT_TRUE(active_layer_
->CanHaveTilings());
2130 EXPECT_EQ(active_layer_
->tilings()->num_tilings(), 2u);
2131 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
2133 // Since the active layer has no tiles at all, the pending layer doesn't
2134 // need content in order to activate.
2135 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2136 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2138 AssertNoTilesRequired(pending_layer_
->HighResTiling());
2139 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2142 TEST_F(PictureLayerImplTest
, HighResRequiredIfActiveCantHaveTiles
) {
2143 gfx::Size
layer_bounds(400, 400);
2144 gfx::Size
tile_size(100, 100);
2146 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2147 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2148 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2149 FakePicturePileImpl::CreateEmptyPile(tile_size
, layer_bounds
);
2150 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2152 // Active layer can't have tiles.
2153 EXPECT_FALSE(active_layer_
->CanHaveTilings());
2155 // All high res tiles required. This should be considered identical
2156 // to the case where there is no active layer, to avoid flashing content.
2157 // This can happen if a layer exists for a while and switches from
2158 // not being able to have content to having content.
2159 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2160 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2162 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2163 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2166 TEST_F(PictureLayerImplTest
, HighResRequiredWhenActiveHasDifferentBounds
) {
2167 gfx::Size
pending_layer_bounds(400, 400);
2168 gfx::Size
active_layer_bounds(200, 200);
2169 gfx::Size
tile_size(100, 100);
2171 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2172 FakePicturePileImpl::CreateFilledPile(tile_size
, pending_layer_bounds
);
2173 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2174 FakePicturePileImpl::CreateFilledPile(tile_size
, active_layer_bounds
);
2176 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
2178 // Since the active layer has different bounds, the pending layer needs all
2179 // high res tiles in order to activate.
2180 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2181 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2183 AssertAllTilesRequired(pending_layer_
->HighResTiling());
2184 AssertNoTilesRequired(pending_layer_
->LowResTiling());
2187 TEST_F(PictureLayerImplTest
, ActivateUninitializedLayer
) {
2188 gfx::Size
tile_size(100, 100);
2189 gfx::Size
layer_bounds(400, 400);
2190 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2191 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2193 host_impl_
.CreatePendingTree();
2194 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
2196 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
2197 FakePictureLayerImpl::CreateWithRasterSource(pending_tree
, id_
,
2199 pending_layer
->SetDrawsContent(true);
2200 pending_tree
->SetRootLayer(pending_layer
.Pass());
2202 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
2203 host_impl_
.pending_tree()->LayerById(id_
));
2205 // Set some state on the pending layer, make sure it is not clobbered
2206 // by a sync from the active layer. This could happen because if the
2207 // pending layer has not been post-commit initialized it will attempt
2208 // to sync from the active layer.
2209 float raster_page_scale
= 10.f
* pending_layer_
->raster_page_scale();
2210 pending_layer_
->set_raster_page_scale(raster_page_scale
);
2212 host_impl_
.ActivateSyncTree();
2214 active_layer_
= static_cast<FakePictureLayerImpl
*>(
2215 host_impl_
.active_tree()->LayerById(id_
));
2217 EXPECT_EQ(0u, active_layer_
->num_tilings());
2218 EXPECT_EQ(raster_page_scale
, active_layer_
->raster_page_scale());
2221 TEST_F(PictureLayerImplTest
, ShareTilesOnNextFrame
) {
2222 gfx::Size
layer_bounds(1500, 1500);
2223 gfx::Size
tile_size(100, 100);
2225 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2226 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2228 SetupPendingTree(pending_pile
);
2230 PictureLayerTiling
* tiling
= pending_layer_
->HighResTiling();
2231 gfx::Rect first_invalidate
= tiling
->TilingDataForTesting().TileBounds(0, 0);
2232 first_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2233 tiling
->TilingDataForTesting().border_texels());
2234 gfx::Rect second_invalidate
= tiling
->TilingDataForTesting().TileBounds(1, 1);
2235 second_invalidate
.Inset(tiling
->TilingDataForTesting().border_texels(),
2236 tiling
->TilingDataForTesting().border_texels());
2240 // Make a pending tree with an invalidated raster tile 0,0.
2241 SetupPendingTreeWithInvalidation(pending_pile
, first_invalidate
);
2243 // Activate and make a pending tree with an invalidated raster tile 1,1.
2246 SetupPendingTreeWithInvalidation(pending_pile
, second_invalidate
);
2248 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2249 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2251 // pending_tiling->CreateAllTilesForTesting();
2253 // Tile 0,0 should be shared, but tile 1,1 should not be.
2254 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2255 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2256 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2257 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2258 EXPECT_TRUE(pending_tiling
->TileAt(0, 0)->is_shared());
2259 EXPECT_TRUE(pending_tiling
->TileAt(1, 0)->is_shared());
2260 EXPECT_TRUE(pending_tiling
->TileAt(0, 1)->is_shared());
2261 EXPECT_FALSE(pending_tiling
->TileAt(1, 1)->is_shared());
2263 // Drop the tiles on the active tree and recreate them. The same tiles
2264 // should be shared or not.
2265 active_tiling
->ComputeTilePriorityRects(gfx::Rect(), 1.f
, 1.0, Occlusion());
2266 EXPECT_TRUE(active_tiling
->AllTilesForTesting().empty());
2267 active_tiling
->CreateAllTilesForTesting();
2269 // Tile 0,0 should be shared, but tile 1,1 should not be.
2270 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2271 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2272 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2273 EXPECT_NE(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2274 EXPECT_TRUE(pending_tiling
->TileAt(0, 0)->is_shared());
2275 EXPECT_TRUE(pending_tiling
->TileAt(1, 0)->is_shared());
2276 EXPECT_TRUE(pending_tiling
->TileAt(0, 1)->is_shared());
2277 EXPECT_FALSE(pending_tiling
->TileAt(1, 1)->is_shared());
2280 TEST_F(PictureLayerImplTest
, ShareTilesWithNoInvalidation
) {
2281 SetupDefaultTrees(gfx::Size(1500, 1500));
2283 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2284 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2286 // No invalidation, so all tiles are shared.
2287 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2288 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2289 ASSERT_TRUE(active_tiling
);
2290 ASSERT_TRUE(pending_tiling
);
2292 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2293 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2294 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2295 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2297 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2298 EXPECT_TRUE(pending_tiling
->TileAt(1, 0));
2299 EXPECT_TRUE(pending_tiling
->TileAt(0, 1));
2300 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2302 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2303 EXPECT_TRUE(active_tiling
->TileAt(0, 0)->is_shared());
2304 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2305 EXPECT_TRUE(active_tiling
->TileAt(1, 0)->is_shared());
2306 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2307 EXPECT_TRUE(active_tiling
->TileAt(0, 1)->is_shared());
2308 EXPECT_EQ(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2309 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2312 TEST_F(PictureLayerImplTest
, ShareInvalidActiveTreeTiles
) {
2313 gfx::Size
tile_size(100, 100);
2314 gfx::Size
layer_bounds(1500, 1500);
2316 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2317 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2318 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2319 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2320 SetupTreesWithInvalidation(pending_pile
, active_pile
, gfx::Rect(1, 1));
2321 // Activate the invalidation.
2323 // Make another pending tree without any invalidation in it.
2324 scoped_refptr
<FakePicturePileImpl
> pending_pile2
=
2325 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2326 SetupPendingTree(pending_pile2
);
2328 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2329 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2331 // The active tree invalidation was handled by the active tiles, so they
2332 // can be shared with the pending tree.
2333 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2334 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2335 ASSERT_TRUE(active_tiling
);
2336 ASSERT_TRUE(pending_tiling
);
2338 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2339 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2340 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2341 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2343 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2344 EXPECT_TRUE(pending_tiling
->TileAt(1, 0));
2345 EXPECT_TRUE(pending_tiling
->TileAt(0, 1));
2346 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2348 EXPECT_EQ(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2349 EXPECT_TRUE(active_tiling
->TileAt(0, 0)->is_shared());
2350 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2351 EXPECT_TRUE(active_tiling
->TileAt(1, 0)->is_shared());
2352 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2353 EXPECT_TRUE(active_tiling
->TileAt(0, 1)->is_shared());
2354 EXPECT_EQ(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2355 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2358 TEST_F(PictureLayerImplTest
, RecreateInvalidPendingTreeTiles
) {
2359 // Set some invalidation on the pending tree. We should replace raster tiles
2361 SetupDefaultTreesWithInvalidation(gfx::Size(1500, 1500), gfx::Rect(1, 1));
2363 EXPECT_GE(active_layer_
->num_tilings(), 1u);
2364 EXPECT_GE(pending_layer_
->num_tilings(), 1u);
2366 // The pending tree invalidation means tiles can not be shared with the
2368 PictureLayerTiling
* active_tiling
= active_layer_
->tilings()->tiling_at(0);
2369 PictureLayerTiling
* pending_tiling
= pending_layer_
->tilings()->tiling_at(0);
2370 ASSERT_TRUE(active_tiling
);
2371 ASSERT_TRUE(pending_tiling
);
2373 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2374 EXPECT_TRUE(active_tiling
->TileAt(1, 0));
2375 EXPECT_TRUE(active_tiling
->TileAt(0, 1));
2376 EXPECT_TRUE(active_tiling
->TileAt(1, 1));
2378 EXPECT_TRUE(pending_tiling
->TileAt(0, 0));
2379 EXPECT_TRUE(pending_tiling
->TileAt(1, 0));
2380 EXPECT_TRUE(pending_tiling
->TileAt(0, 1));
2381 EXPECT_TRUE(pending_tiling
->TileAt(1, 1));
2383 EXPECT_NE(active_tiling
->TileAt(0, 0), pending_tiling
->TileAt(0, 0));
2384 EXPECT_FALSE(active_tiling
->TileAt(0, 0)->is_shared());
2385 EXPECT_FALSE(pending_tiling
->TileAt(0, 0)->is_shared());
2386 EXPECT_EQ(active_tiling
->TileAt(1, 0), pending_tiling
->TileAt(1, 0));
2387 EXPECT_TRUE(active_tiling
->TileAt(1, 0)->is_shared());
2388 EXPECT_EQ(active_tiling
->TileAt(0, 1), pending_tiling
->TileAt(0, 1));
2389 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2390 EXPECT_EQ(active_tiling
->TileAt(1, 1), pending_tiling
->TileAt(1, 1));
2391 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
2394 TEST_F(PictureLayerImplTest
, SyncTilingAfterGpuRasterizationToggles
) {
2395 base::TimeTicks time_ticks
;
2396 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
2397 host_impl_
.SetCurrentBeginFrameArgs(
2398 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2400 gfx::Size
tile_size(100, 100);
2401 gfx::Size
layer_bounds(10, 10);
2403 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2404 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2405 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2406 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2408 SetupTrees(pending_pile
, active_pile
);
2410 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2411 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(1.f
));
2413 // Gpu rasterization is disabled by default.
2414 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2415 // Toggling the gpu rasterization clears all tilings on both trees.
2416 host_impl_
.SetUseGpuRasterization(true);
2417 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2418 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2420 // Make sure that we can still add tiling to the pending layer,
2421 // that gets synced to the active layer.
2422 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
2423 host_impl_
.SetCurrentBeginFrameArgs(
2424 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2425 bool update_lcd_text
= false;
2426 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
2427 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2430 EXPECT_TRUE(active_layer_
->tilings()->FindTilingWithScale(1.f
));
2432 SetupPendingTree(pending_pile
);
2433 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(1.f
));
2435 // Toggling the gpu rasterization clears all tilings on both trees.
2436 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2437 host_impl_
.SetUseGpuRasterization(false);
2438 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
2439 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
2442 TEST_F(PictureLayerImplTest
, HighResCreatedWhenBoundsShrink
) {
2443 gfx::Size
tile_size(100, 100);
2445 // Put 0.5 as high res.
2446 host_impl_
.SetDeviceScaleFactor(0.5f
);
2448 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2449 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(10, 10));
2450 SetupPendingTree(pending_pile
);
2453 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2454 EXPECT_TRUE(pending_layer_
->tilings()->FindTilingWithScale(0.5f
));
2458 // Now, set the bounds to be 1x1, so that minimum contents scale becomes 1.
2460 FakePicturePileImpl::CreateFilledPile(tile_size
, gfx::Size(1, 1));
2461 SetupPendingTree(pending_pile
);
2463 // Another sanity check.
2464 EXPECT_EQ(1.f
, pending_layer_
->MinimumContentsScale());
2466 // Since the MinContentsScale is 1, the 0.5 tiling should be replaced by a 1.0
2468 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 0.5f
, 1.f
, 1.f
, 1.f
, false);
2470 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2471 PictureLayerTiling
* tiling
=
2472 pending_layer_
->tilings()->FindTilingWithScale(1.0f
);
2473 ASSERT_TRUE(tiling
);
2474 EXPECT_EQ(HIGH_RESOLUTION
, tiling
->resolution());
2477 TEST_F(PictureLayerImplTest
, LowResTilingWithoutGpuRasterization
) {
2478 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
2479 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
2480 default_tile_size
.height() * 4);
2482 host_impl_
.SetUseGpuRasterization(false);
2484 SetupDefaultTrees(layer_bounds
);
2485 EXPECT_FALSE(host_impl_
.use_gpu_rasterization());
2486 // Should have a low-res and a high-res tiling.
2487 EXPECT_EQ(2u, pending_layer_
->tilings()->num_tilings());
2490 TEST_F(PictureLayerImplTest
, NoLowResTilingWithGpuRasterization
) {
2491 gfx::Size
default_tile_size(host_impl_
.settings().default_tile_size
);
2492 gfx::Size
layer_bounds(default_tile_size
.width() * 4,
2493 default_tile_size
.height() * 4);
2495 host_impl_
.SetUseGpuRasterization(true);
2497 SetupDefaultTrees(layer_bounds
);
2498 EXPECT_TRUE(host_impl_
.use_gpu_rasterization());
2499 // Should only have the high-res tiling.
2500 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
2503 TEST_F(PictureLayerImplTest
, NoTilingIfDoesNotDrawContent
) {
2504 // Set up layers with tilings.
2505 SetupDefaultTrees(gfx::Size(10, 10));
2506 SetContentsScaleOnBothLayers(1.f
, 1.f
, 1.f
, 1.f
, false);
2507 pending_layer_
->PushPropertiesTo(active_layer_
);
2508 EXPECT_TRUE(pending_layer_
->DrawsContent());
2509 EXPECT_TRUE(pending_layer_
->CanHaveTilings());
2510 EXPECT_GE(pending_layer_
->num_tilings(), 0u);
2511 EXPECT_GE(active_layer_
->num_tilings(), 0u);
2513 // Set content to false, which should make CanHaveTilings return false.
2514 pending_layer_
->SetDrawsContent(false);
2515 EXPECT_FALSE(pending_layer_
->DrawsContent());
2516 EXPECT_FALSE(pending_layer_
->CanHaveTilings());
2518 // No tilings should be pushed to active layer.
2519 pending_layer_
->PushPropertiesTo(active_layer_
);
2520 EXPECT_EQ(0u, active_layer_
->num_tilings());
2523 TEST_F(PictureLayerImplTest
, FirstTilingDuringPinch
) {
2524 SetupDefaultTrees(gfx::Size(10, 10));
2526 // We start with a tiling at scale 1.
2527 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
2529 // When we scale up by 2.3, we get a new tiling that is a power of 2, in this
2531 host_impl_
.PinchGestureBegin();
2532 float high_res_scale
= 2.3f
;
2533 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, 1.f
, 1.f
, false);
2534 EXPECT_EQ(4.f
, pending_layer_
->HighResTiling()->contents_scale());
2537 TEST_F(PictureLayerImplTest
, PinchingTooSmall
) {
2538 SetupDefaultTrees(gfx::Size(10, 10));
2540 // We start with a tiling at scale 1.
2541 EXPECT_EQ(1.f
, pending_layer_
->HighResTiling()->contents_scale());
2543 host_impl_
.PinchGestureBegin();
2544 float high_res_scale
= 0.0001f
;
2545 EXPECT_LT(high_res_scale
, pending_layer_
->MinimumContentsScale());
2547 SetContentsScaleOnBothLayers(high_res_scale
, 1.f
, high_res_scale
, 1.f
, false);
2548 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2549 pending_layer_
->HighResTiling()->contents_scale());
2552 TEST_F(PictureLayerImplTest
, PinchingTooSmallWithContentsScale
) {
2553 SetupDefaultTrees(gfx::Size(10, 10));
2555 ResetTilingsAndRasterScales();
2557 float contents_scale
= 0.15f
;
2558 SetContentsScaleOnBothLayers(contents_scale
, 1.f
, 1.f
, 1.f
, false);
2560 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2561 EXPECT_FLOAT_EQ(contents_scale
,
2562 pending_layer_
->HighResTiling()->contents_scale());
2564 host_impl_
.PinchGestureBegin();
2566 float page_scale
= 0.0001f
;
2567 EXPECT_LT(page_scale
* contents_scale
,
2568 pending_layer_
->MinimumContentsScale());
2570 SetContentsScaleOnBothLayers(contents_scale
* page_scale
, 1.f
, page_scale
,
2572 ASSERT_GE(pending_layer_
->num_tilings(), 0u);
2573 EXPECT_FLOAT_EQ(pending_layer_
->MinimumContentsScale(),
2574 pending_layer_
->HighResTiling()->contents_scale());
2577 class DeferredInitPictureLayerImplTest
: public PictureLayerImplTest
{
2579 void InitializeRenderer() override
{
2580 bool delegated_rendering
= false;
2581 host_impl_
.InitializeRenderer(FakeOutputSurface::CreateDeferredGL(
2582 scoped_ptr
<SoftwareOutputDevice
>(new SoftwareOutputDevice
),
2583 delegated_rendering
));
2586 void SetUp() override
{
2587 PictureLayerImplTest::SetUp();
2589 // Create some default active and pending trees.
2590 gfx::Size
tile_size(100, 100);
2591 gfx::Size
layer_bounds(400, 400);
2593 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2594 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2595 scoped_refptr
<FakePicturePileImpl
> active_pile
=
2596 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
2598 SetupTrees(pending_pile
, active_pile
);
2602 // This test is really a LayerTreeHostImpl test, in that it makes sure
2603 // that trees need update draw properties after deferred initialization.
2604 // However, this is also a regression test for PictureLayerImpl in that
2605 // not having this update will cause a crash.
2606 TEST_F(DeferredInitPictureLayerImplTest
, PreventUpdateTilesDuringLostContext
) {
2607 host_impl_
.pending_tree()->UpdateDrawProperties(true);
2608 host_impl_
.active_tree()->UpdateDrawProperties(false);
2609 EXPECT_FALSE(host_impl_
.pending_tree()->needs_update_draw_properties());
2610 EXPECT_FALSE(host_impl_
.active_tree()->needs_update_draw_properties());
2612 FakeOutputSurface
* fake_output_surface
=
2613 static_cast<FakeOutputSurface
*>(host_impl_
.output_surface());
2614 ASSERT_TRUE(fake_output_surface
->InitializeAndSetContext3d(
2615 TestContextProvider::Create(), TestContextProvider::Create()));
2617 // These will crash PictureLayerImpl if this is not true.
2618 ASSERT_TRUE(host_impl_
.pending_tree()->needs_update_draw_properties());
2619 ASSERT_TRUE(host_impl_
.active_tree()->needs_update_draw_properties());
2620 host_impl_
.active_tree()->UpdateDrawProperties(false);
2623 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForCpuRasterization
) {
2624 gfx::Size
viewport_size(1000, 1000);
2625 host_impl_
.SetViewportSize(viewport_size
);
2627 gfx::Size
layer_bounds(100, 100);
2628 SetupDefaultTrees(layer_bounds
);
2630 float contents_scale
= 1.f
;
2631 float device_scale
= 1.f
;
2632 float page_scale
= 1.f
;
2633 float maximum_animation_scale
= 1.f
;
2634 bool animating_transform
= false;
2636 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2638 // Since we're CPU-rasterizing, starting an animation should cause tiling
2639 // resolution to get set to the maximum animation scale factor.
2640 animating_transform
= true;
2641 maximum_animation_scale
= 3.f
;
2642 contents_scale
= 2.f
;
2644 SetContentsScaleOnBothLayers(contents_scale
,
2647 maximum_animation_scale
,
2648 animating_transform
);
2649 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2651 // Further changes to scale during the animation should not cause a new
2652 // high-res tiling to get created.
2653 contents_scale
= 4.f
;
2654 maximum_animation_scale
= 5.f
;
2656 SetContentsScaleOnBothLayers(contents_scale
,
2659 maximum_animation_scale
,
2660 animating_transform
);
2661 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2663 // Once we stop animating, a new high-res tiling should be created.
2664 animating_transform
= false;
2666 SetContentsScaleOnBothLayers(contents_scale
,
2669 maximum_animation_scale
,
2670 animating_transform
);
2671 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2673 // When animating with an unknown maximum animation scale factor, a new
2674 // high-res tiling should be created at a source scale of 1.
2675 animating_transform
= true;
2676 contents_scale
= 2.f
;
2677 maximum_animation_scale
= 0.f
;
2679 SetContentsScaleOnBothLayers(contents_scale
,
2682 maximum_animation_scale
,
2683 animating_transform
);
2684 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2686 // Further changes to scale during the animation should not cause a new
2687 // high-res tiling to get created.
2688 contents_scale
= 3.f
;
2690 SetContentsScaleOnBothLayers(contents_scale
,
2693 maximum_animation_scale
,
2694 animating_transform
);
2695 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2697 // Once we stop animating, a new high-res tiling should be created.
2698 animating_transform
= false;
2699 contents_scale
= 4.f
;
2701 SetContentsScaleOnBothLayers(contents_scale
,
2704 maximum_animation_scale
,
2705 animating_transform
);
2706 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2708 // When animating with a maxmium animation scale factor that is so large
2709 // that the layer grows larger than the viewport at this scale, a new
2710 // high-res tiling should get created at a source scale of 1, not at its
2712 animating_transform
= true;
2713 contents_scale
= 2.f
;
2714 maximum_animation_scale
= 11.f
;
2716 SetContentsScaleOnBothLayers(contents_scale
,
2719 maximum_animation_scale
,
2720 animating_transform
);
2721 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale
* device_scale
);
2723 // Once we stop animating, a new high-res tiling should be created.
2724 animating_transform
= false;
2725 contents_scale
= 11.f
;
2727 SetContentsScaleOnBothLayers(contents_scale
,
2730 maximum_animation_scale
,
2731 animating_transform
);
2732 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2734 // When animating with a maxmium animation scale factor that is so large
2735 // that the layer grows larger than the viewport at this scale, and where
2736 // the intial source scale is < 1, a new high-res tiling should get created
2737 // at source scale 1.
2738 animating_transform
= true;
2739 contents_scale
= 0.1f
;
2740 maximum_animation_scale
= 11.f
;
2742 SetContentsScaleOnBothLayers(contents_scale
,
2745 maximum_animation_scale
,
2746 animating_transform
);
2747 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2749 // Once we stop animating, a new high-res tiling should be created.
2750 animating_transform
= false;
2751 contents_scale
= 12.f
;
2753 SetContentsScaleOnBothLayers(contents_scale
,
2756 maximum_animation_scale
,
2757 animating_transform
);
2758 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 12.f
);
2760 // When animating toward a smaller scale, but that is still so large that the
2761 // layer grows larger than the viewport at this scale, a new high-res tiling
2762 // should get created at source scale 1.
2763 animating_transform
= true;
2764 contents_scale
= 11.f
;
2765 maximum_animation_scale
= 11.f
;
2767 SetContentsScaleOnBothLayers(contents_scale
,
2770 maximum_animation_scale
,
2771 animating_transform
);
2772 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale
* page_scale
);
2774 // Once we stop animating, a new high-res tiling should be created.
2775 animating_transform
= false;
2776 contents_scale
= 11.f
;
2778 SetContentsScaleOnBothLayers(contents_scale
,
2781 maximum_animation_scale
,
2782 animating_transform
);
2783 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f
);
2786 TEST_F(PictureLayerImplTest
, HighResTilingDuringAnimationForGpuRasterization
) {
2787 gfx::Size
layer_bounds(100, 100);
2788 gfx::Size
viewport_size(1000, 1000);
2789 SetupDefaultTrees(layer_bounds
);
2790 host_impl_
.SetViewportSize(viewport_size
);
2791 host_impl_
.SetUseGpuRasterization(true);
2793 float contents_scale
= 1.f
;
2794 float device_scale
= 1.3f
;
2795 float page_scale
= 1.4f
;
2796 float maximum_animation_scale
= 1.f
;
2797 bool animating_transform
= false;
2799 SetContentsScaleOnBothLayers(contents_scale
,
2802 maximum_animation_scale
,
2803 animating_transform
);
2804 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
2806 // Since we're GPU-rasterizing, starting an animation should cause tiling
2807 // resolution to get set to the current contents scale.
2808 animating_transform
= true;
2809 contents_scale
= 2.f
;
2810 maximum_animation_scale
= 4.f
;
2812 SetContentsScaleOnBothLayers(contents_scale
,
2815 maximum_animation_scale
,
2816 animating_transform
);
2817 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
2819 // Further changes to scale during the animation should cause a new high-res
2820 // tiling to get created.
2821 contents_scale
= 3.f
;
2823 SetContentsScaleOnBothLayers(contents_scale
,
2826 maximum_animation_scale
,
2827 animating_transform
);
2828 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f
);
2830 // Since we're re-rasterizing during the animation, scales smaller than 1
2831 // should be respected.
2832 contents_scale
= 0.25f
;
2834 SetContentsScaleOnBothLayers(contents_scale
,
2837 maximum_animation_scale
,
2838 animating_transform
);
2839 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.25f
);
2841 // Once we stop animating, a new high-res tiling should be created.
2842 contents_scale
= 4.f
;
2843 animating_transform
= false;
2845 SetContentsScaleOnBothLayers(contents_scale
,
2848 maximum_animation_scale
,
2849 animating_transform
);
2850 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f
);
2853 TEST_F(PictureLayerImplTest
, TilingSetRasterQueue
) {
2854 base::TimeTicks time_ticks
;
2855 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
2856 host_impl_
.SetCurrentBeginFrameArgs(
2857 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2859 host_impl_
.SetViewportSize(gfx::Size(500, 500));
2861 gfx::Size
recording_tile_size(100, 100);
2862 gfx::Size
layer_bounds(1000, 1000);
2864 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
2865 FakePicturePileImpl::CreateFilledPile(recording_tile_size
, layer_bounds
);
2867 SetupPendingTree(pending_pile
);
2868 EXPECT_EQ(2u, pending_layer_
->num_tilings());
2870 std::set
<Tile
*> unique_tiles
;
2871 bool reached_prepaint
= false;
2872 int non_ideal_tile_count
= 0u;
2873 int low_res_tile_count
= 0u;
2874 int high_res_tile_count
= 0u;
2875 int high_res_now_tiles
= 0u;
2876 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
2877 pending_layer_
->picture_layer_tiling_set(), false));
2878 while (!queue
->IsEmpty()) {
2879 Tile
* tile
= queue
->Top();
2880 TilePriority priority
= tile
->priority(PENDING_TREE
);
2884 // Non-high res tiles only get visible tiles. Also, prepaint should only
2885 // come at the end of the iteration.
2886 if (priority
.resolution
!= HIGH_RESOLUTION
) {
2887 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
2888 } else if (reached_prepaint
) {
2889 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
2891 reached_prepaint
= priority
.priority_bin
!= TilePriority::NOW
;
2892 if (!reached_prepaint
)
2893 ++high_res_now_tiles
;
2896 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
2897 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
2898 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2900 unique_tiles
.insert(tile
);
2904 EXPECT_TRUE(reached_prepaint
);
2905 EXPECT_EQ(0, non_ideal_tile_count
);
2906 EXPECT_EQ(0, low_res_tile_count
);
2908 // With layer size being 1000x1000 and default tile size 256x256, we expect to
2909 // see 4 now tiles out of 16 total high res tiles.
2910 EXPECT_EQ(16, high_res_tile_count
);
2911 EXPECT_EQ(4, high_res_now_tiles
);
2912 EXPECT_EQ(low_res_tile_count
+ high_res_tile_count
+ non_ideal_tile_count
,
2913 static_cast<int>(unique_tiles
.size()));
2915 scoped_ptr
<TilingSetRasterQueueRequired
> required_queue(
2916 new TilingSetRasterQueueRequired(
2917 pending_layer_
->picture_layer_tiling_set(),
2918 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
));
2919 EXPECT_TRUE(required_queue
->IsEmpty());
2921 required_queue
.reset(new TilingSetRasterQueueRequired(
2922 pending_layer_
->picture_layer_tiling_set(),
2923 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
2924 EXPECT_FALSE(required_queue
->IsEmpty());
2925 int required_for_activation_count
= 0;
2926 while (!required_queue
->IsEmpty()) {
2927 Tile
* tile
= required_queue
->Top();
2928 EXPECT_TRUE(tile
->required_for_activation());
2929 EXPECT_FALSE(tile
->IsReadyToDraw());
2930 ++required_for_activation_count
;
2931 required_queue
->Pop();
2934 // All of the high res tiles should be required for activation, since there is
2936 EXPECT_EQ(high_res_now_tiles
, required_for_activation_count
);
2939 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
2940 host_impl_
.SetCurrentBeginFrameArgs(
2941 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2943 pending_layer_
->draw_properties().visible_content_rect
=
2944 gfx::Rect(1100, 1100, 500, 500);
2945 bool resourceless_software_draw
= false;
2946 pending_layer_
->UpdateTiles(resourceless_software_draw
);
2948 unique_tiles
.clear();
2949 high_res_tile_count
= 0u;
2950 queue
.reset(new TilingSetRasterQueueAll(
2951 pending_layer_
->picture_layer_tiling_set(), false));
2952 while (!queue
->IsEmpty()) {
2953 Tile
* tile
= queue
->Top();
2954 TilePriority priority
= tile
->priority(PENDING_TREE
);
2958 // Non-high res tiles only get visible tiles.
2959 EXPECT_EQ(HIGH_RESOLUTION
, priority
.resolution
);
2960 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
2962 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
2964 unique_tiles
.insert(tile
);
2968 EXPECT_EQ(16, high_res_tile_count
);
2969 EXPECT_EQ(high_res_tile_count
, static_cast<int>(unique_tiles
.size()));
2971 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
2972 host_impl_
.SetCurrentBeginFrameArgs(
2973 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
2975 pending_layer_
->draw_properties().visible_content_rect
=
2976 gfx::Rect(0, 0, 500, 500);
2977 pending_layer_
->UpdateTiles(resourceless_software_draw
);
2979 std::vector
<Tile
*> high_res_tiles
=
2980 pending_layer_
->HighResTiling()->AllTilesForTesting();
2981 for (std::vector
<Tile
*>::iterator tile_it
= high_res_tiles
.begin();
2982 tile_it
!= high_res_tiles
.end();
2984 Tile
* tile
= *tile_it
;
2985 TileDrawInfo
& draw_info
= tile
->draw_info();
2986 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
2989 non_ideal_tile_count
= 0;
2990 low_res_tile_count
= 0;
2991 high_res_tile_count
= 0;
2992 queue
.reset(new TilingSetRasterQueueAll(
2993 pending_layer_
->picture_layer_tiling_set(), true));
2994 while (!queue
->IsEmpty()) {
2995 Tile
* tile
= queue
->Top();
2996 TilePriority priority
= tile
->priority(PENDING_TREE
);
3000 non_ideal_tile_count
+= priority
.resolution
== NON_IDEAL_RESOLUTION
;
3001 low_res_tile_count
+= priority
.resolution
== LOW_RESOLUTION
;
3002 high_res_tile_count
+= priority
.resolution
== HIGH_RESOLUTION
;
3006 EXPECT_EQ(0, non_ideal_tile_count
);
3007 EXPECT_EQ(1, low_res_tile_count
);
3008 EXPECT_EQ(0, high_res_tile_count
);
3011 TEST_F(PictureLayerImplTest
, TilingSetRasterQueueActiveTree
) {
3012 base::TimeTicks time_ticks
;
3013 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
3014 host_impl_
.SetCurrentBeginFrameArgs(
3015 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3017 host_impl_
.SetViewportSize(gfx::Size(500, 500));
3019 gfx::Size
tile_size(100, 100);
3020 gfx::Size
layer_bounds(1000, 1000);
3022 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3023 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3025 SetupPendingTree(pending_pile
);
3027 EXPECT_EQ(2u, active_layer_
->num_tilings());
3029 scoped_ptr
<TilingSetRasterQueueRequired
> queue(
3030 new TilingSetRasterQueueRequired(
3031 active_layer_
->picture_layer_tiling_set(),
3032 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
));
3033 EXPECT_FALSE(queue
->IsEmpty());
3034 while (!queue
->IsEmpty()) {
3035 Tile
* tile
= queue
->Top();
3036 EXPECT_TRUE(tile
->required_for_draw());
3037 EXPECT_FALSE(tile
->IsReadyToDraw());
3041 queue
.reset(new TilingSetRasterQueueRequired(
3042 active_layer_
->picture_layer_tiling_set(),
3043 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
3044 EXPECT_TRUE(queue
->IsEmpty());
3047 TEST_F(PictureLayerImplTest
, TilingSetRasterQueueRequiredNoHighRes
) {
3048 scoped_ptr
<FakePicturePile
> empty_recording
=
3049 FakePicturePile::CreateEmptyPile(gfx::Size(256, 256),
3050 gfx::Size(1024, 1024));
3051 empty_recording
->SetIsSolidColor(true);
3053 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3054 FakePicturePileImpl::CreateFromPile(empty_recording
.get(), nullptr);
3056 SetupPendingTree(pending_pile
);
3058 pending_layer_
->picture_layer_tiling_set()->FindTilingWithResolution(
3061 scoped_ptr
<TilingSetRasterQueueRequired
> queue(
3062 new TilingSetRasterQueueRequired(
3063 pending_layer_
->picture_layer_tiling_set(),
3064 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
));
3065 EXPECT_TRUE(queue
->IsEmpty());
3068 TEST_F(PictureLayerImplTest
, TilingSetEvictionQueue
) {
3069 gfx::Size
tile_size(100, 100);
3070 gfx::Size
layer_bounds(1000, 1000);
3071 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3073 host_impl_
.SetViewportSize(gfx::Size(500, 500));
3075 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3076 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3078 // TODO(vmpstr): Add a test with tilings other than high/low res on the active
3080 SetupPendingTree(pending_pile
);
3081 EXPECT_EQ(2u, pending_layer_
->num_tilings());
3083 std::vector
<Tile
*> all_tiles
;
3084 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3085 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3086 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
3087 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
3090 std::set
<Tile
*> all_tiles_set(all_tiles
.begin(), all_tiles
.end());
3092 bool mark_required
= false;
3093 size_t number_of_marked_tiles
= 0u;
3094 size_t number_of_unmarked_tiles
= 0u;
3095 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
3096 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
3097 for (PictureLayerTiling::CoverageIterator
iter(
3099 pending_layer_
->contents_scale_x(),
3100 pending_layer_
->visible_content_rect());
3103 if (mark_required
) {
3104 number_of_marked_tiles
++;
3105 iter
->set_required_for_activation(true);
3107 number_of_unmarked_tiles
++;
3109 mark_required
= !mark_required
;
3114 EXPECT_EQ(17u, all_tiles
.size());
3115 EXPECT_EQ(17u, all_tiles_set
.size());
3116 EXPECT_GT(number_of_marked_tiles
, 1u);
3117 EXPECT_GT(number_of_unmarked_tiles
, 1u);
3119 // Tiles don't have resources yet.
3120 scoped_ptr
<TilingSetEvictionQueue
> queue(
3121 new TilingSetEvictionQueue(pending_layer_
->picture_layer_tiling_set(),
3122 SAME_PRIORITY_FOR_BOTH_TREES
, false));
3123 EXPECT_TRUE(queue
->IsEmpty());
3125 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
3127 std::set
<Tile
*> unique_tiles
;
3128 float expected_scales
[] = {low_res_factor
, 1.f
};
3129 size_t scale_index
= 0;
3130 bool reached_visible
= false;
3131 Tile
* last_tile
= nullptr;
3132 size_t distance_decreasing
= 0;
3133 size_t distance_increasing
= 0;
3135 new TilingSetEvictionQueue(pending_layer_
->picture_layer_tiling_set(),
3136 SAME_PRIORITY_FOR_BOTH_TREES
, false));
3137 while (!queue
->IsEmpty()) {
3138 Tile
* tile
= queue
->Top();
3144 TilePriority priority
= tile
->priority(PENDING_TREE
);
3146 if (priority
.priority_bin
== TilePriority::NOW
) {
3147 reached_visible
= true;
3152 EXPECT_FALSE(tile
->required_for_activation());
3154 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
3155 std::numeric_limits
<float>::epsilon()) {
3157 ASSERT_LT(scale_index
, arraysize(expected_scales
));
3160 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
3161 unique_tiles
.insert(tile
);
3163 if (tile
->required_for_activation() ==
3164 last_tile
->required_for_activation() &&
3165 std::abs(tile
->contents_scale() - last_tile
->contents_scale()) <
3166 std::numeric_limits
<float>::epsilon()) {
3167 if (priority
.distance_to_visible
<=
3168 last_tile
->priority(PENDING_TREE
).distance_to_visible
)
3169 ++distance_decreasing
;
3171 ++distance_increasing
;
3178 // 4 high res tiles are inside the viewport, the rest are evicted.
3179 EXPECT_TRUE(reached_visible
);
3180 EXPECT_EQ(12u, unique_tiles
.size());
3181 EXPECT_EQ(1u, distance_increasing
);
3182 EXPECT_EQ(11u, distance_decreasing
);
3185 bool reached_required
= false;
3186 while (!queue
->IsEmpty()) {
3187 Tile
* tile
= queue
->Top();
3190 TilePriority priority
= tile
->priority(PENDING_TREE
);
3191 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
3193 if (reached_required
) {
3194 EXPECT_TRUE(tile
->required_for_activation());
3195 } else if (tile
->required_for_activation()) {
3196 reached_required
= true;
3200 while (std::abs(tile
->contents_scale() - expected_scales
[scale_index
]) >
3201 std::numeric_limits
<float>::epsilon()) {
3203 ASSERT_LT(scale_index
, arraysize(expected_scales
));
3206 EXPECT_FLOAT_EQ(tile
->contents_scale(), expected_scales
[scale_index
]);
3207 unique_tiles
.insert(tile
);
3211 EXPECT_TRUE(reached_required
);
3212 EXPECT_EQ(all_tiles_set
.size(), unique_tiles
.size());
3215 TEST_F(PictureLayerImplTest
, Occlusion
) {
3216 gfx::Size
tile_size(102, 102);
3217 gfx::Size
layer_bounds(1000, 1000);
3218 gfx::Size
viewport_size(1000, 1000);
3220 LayerTestCommon::LayerImplTest impl
;
3221 host_impl_
.SetViewportSize(viewport_size
);
3223 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3224 FakePicturePileImpl::CreateFilledPile(layer_bounds
, layer_bounds
);
3225 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
3228 std::vector
<Tile
*> tiles
=
3229 active_layer_
->HighResTiling()->AllTilesForTesting();
3230 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3233 SCOPED_TRACE("No occlusion");
3235 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3237 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(),
3238 gfx::Rect(layer_bounds
));
3239 EXPECT_EQ(100u, impl
.quad_list().size());
3243 SCOPED_TRACE("Full occlusion");
3244 gfx::Rect
occluded(active_layer_
->visible_content_rect());
3245 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3247 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl
.quad_list(), gfx::Rect());
3248 EXPECT_EQ(impl
.quad_list().size(), 0u);
3252 SCOPED_TRACE("Partial occlusion");
3253 gfx::Rect
occluded(150, 0, 200, 1000);
3254 impl
.AppendQuadsWithOcclusion(active_layer_
, occluded
);
3256 size_t partially_occluded_count
= 0;
3257 LayerTestCommon::VerifyQuadsAreOccluded(
3258 impl
.quad_list(), occluded
, &partially_occluded_count
);
3259 // The layer outputs one quad, which is partially occluded.
3260 EXPECT_EQ(100u - 10u, impl
.quad_list().size());
3261 EXPECT_EQ(10u + 10u, partially_occluded_count
);
3265 TEST_F(PictureLayerImplTest
, RasterScaleChangeWithoutAnimation
) {
3266 gfx::Size
tile_size(host_impl_
.settings().default_tile_size
);
3267 SetupDefaultTrees(tile_size
);
3269 ResetTilingsAndRasterScales();
3271 float contents_scale
= 2.f
;
3272 float device_scale
= 1.f
;
3273 float page_scale
= 1.f
;
3274 float maximum_animation_scale
= 1.f
;
3275 bool animating_transform
= false;
3277 SetContentsScaleOnBothLayers(contents_scale
,
3280 maximum_animation_scale
,
3281 animating_transform
);
3282 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f
);
3284 // Changing the source scale without being in an animation will cause
3285 // the layer to reset its source scale to 1.f.
3286 contents_scale
= 3.f
;
3288 SetContentsScaleOnBothLayers(contents_scale
,
3291 maximum_animation_scale
,
3292 animating_transform
);
3293 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3295 // Further changes to the source scale will no longer be reflected in the
3297 contents_scale
= 0.5f
;
3299 SetContentsScaleOnBothLayers(contents_scale
,
3302 maximum_animation_scale
,
3303 animating_transform
);
3304 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f
);
3307 TEST_F(PictureLayerImplTest
, LowResReadyToDrawNotEnoughToActivate
) {
3308 gfx::Size
tile_size(100, 100);
3309 gfx::Size
layer_bounds(1000, 1000);
3311 // Make sure some tiles are not shared.
3312 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3313 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3315 // All pending layer tiles required are not ready.
3316 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3318 // Initialize all low-res tiles.
3319 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3321 // Low-res tiles should not be enough.
3322 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3324 // Initialize remaining tiles.
3325 pending_layer_
->SetAllTilesReady();
3327 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3330 TEST_F(PictureLayerImplTest
, HighResReadyToDrawEnoughToActivate
) {
3331 gfx::Size
tile_size(100, 100);
3332 gfx::Size
layer_bounds(1000, 1000);
3334 // Make sure some tiles are not shared.
3335 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3336 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3338 // All pending layer tiles required are not ready.
3339 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3341 // Initialize all high-res tiles.
3342 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3344 // High-res tiles should be enough, since they cover everything visible.
3345 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3348 TEST_F(PictureLayerImplTest
,
3349 SharedActiveHighResReadyAndPendingLowResReadyNotEnoughToActivate
) {
3350 gfx::Size
tile_size(100, 100);
3351 gfx::Size
layer_bounds(1000, 1000);
3353 // Make sure some tiles are not shared.
3354 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3355 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3357 // Initialize all high-res tiles in the active layer.
3358 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3359 // And all the low-res tiles in the pending layer.
3360 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->LowResTiling());
3362 // The unshared high-res tiles are not ready, so we cannot activate.
3363 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3365 // When the unshared pending high-res tiles are ready, we can activate.
3366 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3367 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3370 TEST_F(PictureLayerImplTest
, SharedActiveHighResReadyNotEnoughToActivate
) {
3371 gfx::Size
tile_size(100, 100);
3372 gfx::Size
layer_bounds(1000, 1000);
3374 // Make sure some tiles are not shared.
3375 gfx::Rect
invalidation(gfx::Point(50, 50), tile_size
);
3376 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, invalidation
);
3378 // Initialize all high-res tiles in the active layer.
3379 active_layer_
->SetAllTilesReadyInTiling(active_layer_
->HighResTiling());
3381 // The unshared high-res tiles are not ready, so we cannot activate.
3382 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
3384 // When the unshared pending high-res tiles are ready, we can activate.
3385 pending_layer_
->SetAllTilesReadyInTiling(pending_layer_
->HighResTiling());
3386 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
3389 TEST_F(NoLowResPictureLayerImplTest
, ManageTilingsCreatesTilings
) {
3390 gfx::Size
tile_size(400, 400);
3391 gfx::Size
layer_bounds(1300, 1900);
3393 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3394 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3395 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3396 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3398 SetupTrees(pending_pile
, active_pile
);
3400 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3401 EXPECT_LT(low_res_factor
, 1.f
);
3403 ResetTilingsAndRasterScales();
3405 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3406 6.f
, // ideal contents scale
3407 3.f
, // device scale
3409 1.f
, // maximum animation scale
3411 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3412 EXPECT_FLOAT_EQ(6.f
,
3413 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3415 // If we change the page scale factor, then we should get new tilings.
3416 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3417 6.6f
, // ideal contents scale
3418 3.f
, // device scale
3420 1.f
, // maximum animation scale
3422 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3423 EXPECT_FLOAT_EQ(6.6f
,
3424 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3426 // If we change the device scale factor, then we should get new tilings.
3427 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3428 7.26f
, // ideal contents scale
3429 3.3f
, // device scale
3431 1.f
, // maximum animation scale
3433 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
3434 EXPECT_FLOAT_EQ(7.26f
,
3435 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3437 // If we change the device scale factor, but end up at the same total scale
3438 // factor somehow, then we don't get new tilings.
3439 SetupDrawPropertiesAndUpdateTiles(active_layer_
,
3440 7.26f
, // ideal contents scale
3441 2.2f
, // device scale
3443 1.f
, // maximum animation scale
3445 ASSERT_EQ(3u, active_layer_
->tilings()->num_tilings());
3446 EXPECT_FLOAT_EQ(7.26f
,
3447 active_layer_
->tilings()->tiling_at(0)->contents_scale());
3450 TEST_F(NoLowResPictureLayerImplTest
, PendingLayerOnlyHasHighResTiling
) {
3451 gfx::Size
tile_size(400, 400);
3452 gfx::Size
layer_bounds(1300, 1900);
3454 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3455 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3456 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3457 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3459 SetupTrees(pending_pile
, active_pile
);
3461 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3462 EXPECT_LT(low_res_factor
, 1.f
);
3464 ResetTilingsAndRasterScales();
3466 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3467 6.f
, // ideal contents scale
3468 3.f
, // device scale
3470 1.f
, // maximum animation scale
3472 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3473 EXPECT_FLOAT_EQ(6.f
,
3474 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3476 // If we change the page scale factor, then we should get new tilings.
3477 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3478 6.6f
, // ideal contents scale
3479 3.f
, // device scale
3481 1.f
, // maximum animation scale
3483 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3484 EXPECT_FLOAT_EQ(6.6f
,
3485 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3487 // If we change the device scale factor, then we should get new tilings.
3488 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3489 7.26f
, // ideal contents scale
3490 3.3f
, // device scale
3492 1.f
, // maximum animation scale
3494 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3495 EXPECT_FLOAT_EQ(7.26f
,
3496 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3498 // If we change the device scale factor, but end up at the same total scale
3499 // factor somehow, then we don't get new tilings.
3500 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3501 7.26f
, // ideal contents scale
3502 2.2f
, // device scale
3504 1.f
, // maximum animation scale
3506 ASSERT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3507 EXPECT_FLOAT_EQ(7.26f
,
3508 pending_layer_
->tilings()->tiling_at(0)->contents_scale());
3511 TEST_F(NoLowResPictureLayerImplTest
, AllHighResRequiredEvenIfShared
) {
3512 gfx::Size
layer_bounds(400, 400);
3513 gfx::Size
tile_size(100, 100);
3515 SetupDefaultTreesWithFixedTileSize(layer_bounds
, tile_size
, Region());
3517 Tile
* some_active_tile
=
3518 active_layer_
->HighResTiling()->AllTilesForTesting()[0];
3519 EXPECT_FALSE(some_active_tile
->IsReadyToDraw());
3521 // All tiles shared (no invalidation), so even though the active tree's
3522 // tiles aren't ready, there is nothing required.
3523 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
3524 if (host_impl_
.settings().create_low_res_tiling
)
3525 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
3527 AssertAllTilesRequired(pending_layer_
->HighResTiling());
3528 if (host_impl_
.settings().create_low_res_tiling
)
3529 AssertNoTilesRequired(pending_layer_
->LowResTiling());
3532 TEST_F(NoLowResPictureLayerImplTest
, NothingRequiredIfActiveMissingTiles
) {
3533 gfx::Size
layer_bounds(400, 400);
3534 gfx::Size
tile_size(100, 100);
3536 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3537 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3538 // This pile will create tilings, but has no recordings so will not create any
3539 // tiles. This is attempting to simulate scrolling past the end of recorded
3540 // content on the active layer, where the recordings are so far away that
3541 // no tiles are created.
3542 bool is_solid_color
= false;
3543 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3544 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
3545 tile_size
, layer_bounds
, is_solid_color
);
3547 SetupTreesWithFixedTileSize(pending_pile
, active_pile
, tile_size
, Region());
3549 // Active layer has tilings, but no tiles due to missing recordings.
3550 EXPECT_TRUE(active_layer_
->CanHaveTilings());
3551 EXPECT_EQ(active_layer_
->tilings()->num_tilings(),
3552 host_impl_
.settings().create_low_res_tiling
? 2u : 1u);
3553 EXPECT_EQ(active_layer_
->HighResTiling()->AllTilesForTesting().size(), 0u);
3555 // Since the active layer has no tiles at all, the pending layer doesn't
3556 // need content in order to activate.
3557 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
3558 if (host_impl_
.settings().create_low_res_tiling
)
3559 pending_layer_
->LowResTiling()->UpdateAllTilePrioritiesForTesting();
3561 AssertNoTilesRequired(pending_layer_
->HighResTiling());
3562 if (host_impl_
.settings().create_low_res_tiling
)
3563 AssertNoTilesRequired(pending_layer_
->LowResTiling());
3566 TEST_F(NoLowResPictureLayerImplTest
, InvalidViewportForPrioritizingTiles
) {
3567 base::TimeTicks time_ticks
;
3568 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
3569 host_impl_
.SetCurrentBeginFrameArgs(
3570 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3572 gfx::Size
tile_size(100, 100);
3573 gfx::Size
layer_bounds(400, 400);
3575 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3576 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3577 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3578 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3580 SetupTreesWithInvalidation(pending_pile
, active_pile
, Region());
3582 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
3584 // UpdateTiles with valid viewport. Should update tile viewport.
3585 // Note viewport is considered invalid if and only if in resourceless
3587 bool resourceless_software_draw
= false;
3588 gfx::Rect viewport
= gfx::Rect(layer_bounds
);
3589 gfx::Transform transform
;
3590 host_impl_
.SetExternalDrawConstraints(transform
,
3595 resourceless_software_draw
);
3596 active_layer_
->draw_properties().visible_content_rect
= viewport
;
3597 active_layer_
->draw_properties().screen_space_transform
= transform
;
3598 active_layer_
->UpdateTiles(resourceless_software_draw
);
3600 gfx::Rect visible_rect_for_tile_priority
=
3601 active_layer_
->visible_rect_for_tile_priority();
3602 EXPECT_FALSE(visible_rect_for_tile_priority
.IsEmpty());
3603 gfx::Transform screen_space_transform_for_tile_priority
=
3604 active_layer_
->screen_space_transform();
3606 // Expand viewport and set it as invalid for prioritizing tiles.
3607 // Should update viewport and transform, but not update visible rect.
3608 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
3609 host_impl_
.SetCurrentBeginFrameArgs(
3610 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3611 resourceless_software_draw
= true;
3612 viewport
= gfx::ScaleToEnclosingRect(viewport
, 2);
3613 transform
.Translate(1.f
, 1.f
);
3614 active_layer_
->draw_properties().visible_content_rect
= viewport
;
3615 active_layer_
->draw_properties().screen_space_transform
= transform
;
3616 host_impl_
.SetExternalDrawConstraints(transform
,
3621 resourceless_software_draw
);
3622 active_layer_
->UpdateTiles(resourceless_software_draw
);
3624 // Transform for tile priority is updated.
3625 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3626 active_layer_
->screen_space_transform());
3627 // Visible rect for tile priority retains old value.
3628 EXPECT_EQ(visible_rect_for_tile_priority
,
3629 active_layer_
->visible_rect_for_tile_priority());
3631 // Keep expanded viewport but mark it valid. Should update tile viewport.
3632 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
3633 host_impl_
.SetCurrentBeginFrameArgs(
3634 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
3635 resourceless_software_draw
= false;
3636 host_impl_
.SetExternalDrawConstraints(transform
,
3641 resourceless_software_draw
);
3642 active_layer_
->UpdateTiles(resourceless_software_draw
);
3644 EXPECT_TRANSFORMATION_MATRIX_EQ(transform
,
3645 active_layer_
->screen_space_transform());
3646 EXPECT_EQ(viewport
, active_layer_
->visible_rect_for_tile_priority());
3649 TEST_F(NoLowResPictureLayerImplTest
, CleanUpTilings
) {
3650 gfx::Size
tile_size(400, 400);
3651 gfx::Size
layer_bounds(1300, 1900);
3653 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3654 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3655 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3656 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3658 std::vector
<PictureLayerTiling
*> used_tilings
;
3660 SetupTrees(pending_pile
, active_pile
);
3662 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
3663 EXPECT_LT(low_res_factor
, 1.f
);
3665 float device_scale
= 1.7f
;
3666 float page_scale
= 3.2f
;
3669 ResetTilingsAndRasterScales();
3671 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
3672 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3674 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
3675 // |used_tilings| variable, and it's here only to ensure that active_layer_
3676 // won't remove tilings before the test has a chance to verify behavior.
3677 active_layer_
->MarkAllTilingsUsed();
3679 // We only have ideal tilings, so they aren't removed.
3680 used_tilings
.clear();
3681 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3682 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3684 host_impl_
.PinchGestureBegin();
3686 // Changing the ideal but not creating new tilings.
3689 SetContentsScaleOnBothLayers(scale
, device_scale
, page_scale
, 1.f
, false);
3690 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3692 // The tilings are still our target scale, so they aren't removed.
3693 used_tilings
.clear();
3694 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3695 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3697 host_impl_
.PinchGestureEnd();
3699 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
3702 SetContentsScaleOnBothLayers(1.2f
, device_scale
, page_scale
, 1.f
, false);
3703 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3704 EXPECT_FLOAT_EQ(1.f
,
3705 active_layer_
->tilings()->tiling_at(1)->contents_scale());
3707 // Ensure UpdateTiles won't remove any tilings.
3708 active_layer_
->MarkAllTilingsUsed();
3710 // Mark the non-ideal tilings as used. They won't be removed.
3711 used_tilings
.clear();
3712 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3713 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3714 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3716 // Now move the ideal scale to 0.5. Our target stays 1.2.
3717 SetContentsScaleOnBothLayers(0.5f
, device_scale
, page_scale
, 1.f
, false);
3719 // The high resolution tiling is between target and ideal, so is not
3720 // removed. The low res tiling for the old ideal=1.0 scale is removed.
3721 used_tilings
.clear();
3722 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3723 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3725 // Now move the ideal scale to 1.0. Our target stays 1.2.
3726 SetContentsScaleOnBothLayers(1.f
, device_scale
, page_scale
, 1.f
, false);
3728 // All the tilings are between are target and the ideal, so they are not
3730 used_tilings
.clear();
3731 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3732 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3734 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
3735 SetupDrawPropertiesAndUpdateTiles(
3736 active_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
3738 // Because the pending layer's ideal scale is still 1.0, our tilings fall
3739 // in the range [1.0,1.2] and are kept.
3740 used_tilings
.clear();
3741 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3742 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3744 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
3746 SetupDrawPropertiesAndUpdateTiles(
3747 pending_layer_
, 1.1f
, device_scale
, page_scale
, 1.f
, false);
3749 // Our 1.0 tiling now falls outside the range between our ideal scale and our
3750 // target raster scale. But it is in our used tilings set, so nothing is
3752 used_tilings
.clear();
3753 used_tilings
.push_back(active_layer_
->tilings()->tiling_at(1));
3754 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3755 ASSERT_EQ(2u, active_layer_
->tilings()->num_tilings());
3757 // If we remove it from our used tilings set, it is outside the range to keep
3758 // so it is deleted.
3759 used_tilings
.clear();
3760 active_layer_
->CleanUpTilingsOnActiveLayer(used_tilings
);
3761 ASSERT_EQ(1u, active_layer_
->tilings()->num_tilings());
3764 TEST_F(NoLowResPictureLayerImplTest
, ReleaseResources
) {
3765 gfx::Size
tile_size(400, 400);
3766 gfx::Size
layer_bounds(1300, 1900);
3768 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3769 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3770 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3771 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3773 SetupTrees(pending_pile
, active_pile
);
3774 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3775 EXPECT_EQ(1u, active_layer_
->tilings()->num_tilings());
3777 // All tilings should be removed when losing output surface.
3778 active_layer_
->ReleaseResources();
3779 EXPECT_FALSE(active_layer_
->tilings());
3780 active_layer_
->RecreateResources();
3781 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
3782 pending_layer_
->ReleaseResources();
3783 EXPECT_FALSE(pending_layer_
->tilings());
3784 pending_layer_
->RecreateResources();
3785 EXPECT_EQ(0u, pending_layer_
->tilings()->num_tilings());
3787 // This should create new tilings.
3788 SetupDrawPropertiesAndUpdateTiles(pending_layer_
,
3789 1.3f
, // ideal contents scale
3790 2.7f
, // device scale
3792 1.f
, // maximum animation scale
3794 EXPECT_EQ(1u, pending_layer_
->tilings()->num_tilings());
3797 TEST_F(PictureLayerImplTest
, SharedQuadStateContainsMaxTilingScale
) {
3798 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3800 gfx::Size
tile_size(400, 400);
3801 gfx::Size
layer_bounds(1000, 2000);
3803 host_impl_
.SetViewportSize(gfx::Size(10000, 20000));
3805 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3806 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3807 scoped_refptr
<FakePicturePileImpl
> active_pile
=
3808 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3810 SetupTrees(pending_pile
, active_pile
);
3812 ResetTilingsAndRasterScales();
3813 SetupDrawPropertiesAndUpdateTiles(active_layer_
, 2.5f
, 1.f
, 1.f
, 1.f
, false);
3815 float max_contents_scale
= active_layer_
->MaximumTilingContentsScale();
3816 EXPECT_EQ(2.5f
, max_contents_scale
);
3818 gfx::Transform scaled_draw_transform
= active_layer_
->draw_transform();
3819 scaled_draw_transform
.Scale(SK_MScalar1
/ max_contents_scale
,
3820 SK_MScalar1
/ max_contents_scale
);
3822 AppendQuadsData data
;
3823 active_layer_
->AppendQuads(render_pass
.get(), &data
);
3825 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
3826 EXPECT_EQ(1u, render_pass
->shared_quad_state_list
.size());
3827 // The content_to_target_transform should be scaled by the
3828 // MaximumTilingContentsScale on the layer.
3829 EXPECT_EQ(scaled_draw_transform
.ToString(),
3830 render_pass
->shared_quad_state_list
.front()
3831 ->content_to_target_transform
.ToString());
3832 // The content_bounds should be scaled by the
3833 // MaximumTilingContentsScale on the layer.
3835 gfx::Size(2500u, 5000u).ToString(),
3836 render_pass
->shared_quad_state_list
.front()->content_bounds
.ToString());
3837 // The visible_content_rect should be scaled by the
3838 // MaximumTilingContentsScale on the layer.
3839 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
3840 render_pass
->shared_quad_state_list
.front()
3841 ->visible_content_rect
.ToString());
3844 class PictureLayerImplTestWithDelegatingRenderer
: public PictureLayerImplTest
{
3846 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {}
3848 void InitializeRenderer() override
{
3849 host_impl_
.InitializeRenderer(FakeOutputSurface::CreateDelegating3d());
3853 TEST_F(PictureLayerImplTestWithDelegatingRenderer
,
3854 DelegatingRendererWithTileOOM
) {
3855 // This test is added for crbug.com/402321, where quad should be produced when
3856 // raster on demand is not allowed and tile is OOM.
3857 gfx::Size tile_size
= host_impl_
.settings().default_tile_size
;
3858 gfx::Size
layer_bounds(1000, 1000);
3861 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
3862 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
3863 SetupPendingTree(pending_pile
);
3864 pending_layer_
->SetBounds(layer_bounds
);
3866 bool update_lcd_text
= false;
3867 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
3868 std::vector
<Tile
*> tiles
=
3869 active_layer_
->HighResTiling()->AllTilesForTesting();
3870 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
3872 // Force tiles after max_tiles to be OOM. TileManager uses
3873 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3874 // directly set state to host_impl_, so we set policy that would change the
3875 // state. We also need to update tree priority separately.
3876 GlobalStateThatImpactsTilePriority state
;
3877 size_t max_tiles
= 1;
3878 size_t memory_limit
= max_tiles
* 4 * tile_size
.width() * tile_size
.height();
3879 size_t resource_limit
= max_tiles
;
3880 ManagedMemoryPolicy
policy(memory_limit
,
3881 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING
,
3883 host_impl_
.SetMemoryPolicy(policy
);
3884 host_impl_
.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES
);
3885 host_impl_
.PrepareTiles();
3887 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
3888 AppendQuadsData data
;
3889 active_layer_
->WillDraw(DRAW_MODE_HARDWARE
, nullptr);
3890 active_layer_
->AppendQuads(render_pass
.get(), &data
);
3891 active_layer_
->DidDraw(nullptr);
3893 // Even when OOM, quads should be produced, and should be different material
3894 // from quads with resource.
3895 EXPECT_LT(max_tiles
, render_pass
->quad_list
.size());
3896 EXPECT_EQ(DrawQuad::Material::TILED_CONTENT
,
3897 render_pass
->quad_list
.front()->material
);
3898 EXPECT_EQ(DrawQuad::Material::SOLID_COLOR
,
3899 render_pass
->quad_list
.back()->material
);
3902 class OcclusionTrackingSettings
: public LowResTilingsSettings
{
3904 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization
= true; }
3907 class OcclusionTrackingPictureLayerImplTest
: public PictureLayerImplTest
{
3909 OcclusionTrackingPictureLayerImplTest()
3910 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
3912 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl
* layer
,
3913 FakePictureLayerImpl
* twin_layer
,
3915 size_t expected_occluded_tile_count
) {
3916 WhichTree twin_tree
= tree
== ACTIVE_TREE
? PENDING_TREE
: ACTIVE_TREE
;
3917 for (int priority_count
= 0; priority_count
<= LAST_TREE_PRIORITY
;
3919 TreePriority tree_priority
= static_cast<TreePriority
>(priority_count
);
3920 size_t occluded_tile_count
= 0u;
3921 Tile
* last_tile
= nullptr;
3922 std::set
<Tile
*> shared_tiles
;
3924 scoped_ptr
<TilingSetEvictionQueue
> queue(
3925 new TilingSetEvictionQueue(layer
->picture_layer_tiling_set(),
3926 tree_priority
, layer
&& twin_layer
));
3927 while (!queue
->IsEmpty()) {
3928 Tile
* tile
= queue
->Top();
3931 if (tile
->is_shared())
3932 EXPECT_TRUE(shared_tiles
.insert(tile
).second
);
3934 // The only way we will encounter an occluded tile after an unoccluded
3935 // tile is if the priorty bin decreased, the tile is required for
3936 // activation, or the scale changed.
3937 bool tile_is_occluded
= tile
->is_occluded(tree
);
3938 if (tile_is_occluded
) {
3939 occluded_tile_count
++;
3941 bool last_tile_is_occluded
= last_tile
->is_occluded(tree
);
3942 if (!last_tile_is_occluded
) {
3943 TilePriority::PriorityBin tile_priority_bin
=
3944 tile
->priority(tree
).priority_bin
;
3945 TilePriority::PriorityBin last_tile_priority_bin
=
3946 last_tile
->priority(tree
).priority_bin
;
3949 (tile_priority_bin
< last_tile_priority_bin
) ||
3950 tile
->required_for_activation() ||
3951 (tile
->contents_scale() != last_tile
->contents_scale()));
3957 // Count also shared tiles which are occluded in the tree but which were
3958 // not returned by the tiling set eviction queue. Those shared tiles
3959 // shall be returned by the twin tiling set eviction queue.
3961 new TilingSetEvictionQueue(twin_layer
->picture_layer_tiling_set(),
3962 tree_priority
, layer
&& twin_layer
));
3963 while (!queue
->IsEmpty()) {
3964 Tile
* tile
= queue
->Top();
3965 if (tile
->is_shared()) {
3966 EXPECT_TRUE(shared_tiles
.insert(tile
).second
);
3967 if (tile
->is_occluded(tree
))
3968 ++occluded_tile_count
;
3969 // Check the reasons why the shared tile was not returned by
3970 // the first tiling set eviction queue.
3971 switch (tree_priority
) {
3972 case SAME_PRIORITY_FOR_BOTH_TREES
: {
3973 const TilePriority
& priority
= tile
->priority(tree
);
3974 const TilePriority
& priority_for_tree_priority
=
3975 tile
->priority_for_tree_priority(tree_priority
);
3976 const TilePriority
& twin_priority
= tile
->priority(twin_tree
);
3977 // Check if the shared tile was not returned by the first tiling
3978 // set eviction queue because it was out of order for the first
3979 // tiling set eviction queue but not for the twin tiling set
3981 if (priority
.priority_bin
!= twin_priority
.priority_bin
) {
3982 EXPECT_LT(priority_for_tree_priority
.priority_bin
,
3983 priority
.priority_bin
);
3984 EXPECT_EQ(priority_for_tree_priority
.priority_bin
,
3985 twin_priority
.priority_bin
);
3986 EXPECT_TRUE(priority_for_tree_priority
.priority_bin
<
3987 priority
.priority_bin
);
3988 } else if (tile
->is_occluded(tree
) !=
3989 tile
->is_occluded(twin_tree
)) {
3990 EXPECT_TRUE(tile
->is_occluded(tree
));
3991 EXPECT_FALSE(tile
->is_occluded(twin_tree
));
3992 EXPECT_FALSE(tile
->is_occluded_combined());
3993 } else if (priority
.distance_to_visible
!=
3994 twin_priority
.distance_to_visible
) {
3995 EXPECT_LT(priority_for_tree_priority
.distance_to_visible
,
3996 priority
.distance_to_visible
);
3997 EXPECT_EQ(priority_for_tree_priority
.distance_to_visible
,
3998 twin_priority
.distance_to_visible
);
3999 EXPECT_TRUE(priority_for_tree_priority
.distance_to_visible
<
4000 priority
.distance_to_visible
);
4002 // Shared tiles having the same active and pending priorities
4003 // should be returned only by a pending tree eviction queue.
4004 EXPECT_EQ(ACTIVE_TREE
, tree
);
4008 case SMOOTHNESS_TAKES_PRIORITY
:
4009 // Shared tiles should be returned only by an active tree
4011 EXPECT_EQ(PENDING_TREE
, tree
);
4013 case NEW_CONTENT_TAKES_PRIORITY
:
4014 // Shared tiles should be returned only by a pending tree
4016 EXPECT_EQ(ACTIVE_TREE
, tree
);
4022 EXPECT_EQ(expected_occluded_tile_count
, occluded_tile_count
);
4027 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4028 OccludedTilesSkippedDuringRasterization
) {
4029 base::TimeTicks time_ticks
;
4030 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4031 host_impl_
.SetCurrentBeginFrameArgs(
4032 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4034 gfx::Size
tile_size(102, 102);
4035 gfx::Size
layer_bounds(1000, 1000);
4036 gfx::Size
viewport_size(500, 500);
4037 gfx::Point
occluding_layer_position(310, 0);
4039 host_impl_
.SetViewportSize(viewport_size
);
4041 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4042 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4043 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4046 int unoccluded_tile_count
= 0;
4047 scoped_ptr
<TilingSetRasterQueueAll
> queue(new TilingSetRasterQueueAll(
4048 pending_layer_
->picture_layer_tiling_set(), false));
4049 while (!queue
->IsEmpty()) {
4050 Tile
* tile
= queue
->Top();
4052 // Occluded tiles should not be iterated over.
4053 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4055 // Some tiles may not be visible (i.e. outside the viewport). The rest are
4056 // visible and at least partially unoccluded, verified by the above expect.
4057 bool tile_is_visible
=
4058 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
4059 if (tile_is_visible
)
4060 unoccluded_tile_count
++;
4063 EXPECT_EQ(unoccluded_tile_count
, 25);
4065 // Partial occlusion.
4066 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4067 LayerImpl
* layer1
= pending_layer_
->children()[0];
4068 layer1
->SetBounds(layer_bounds
);
4069 layer1
->SetContentBounds(layer_bounds
);
4070 layer1
->SetDrawsContent(true);
4071 layer1
->SetContentsOpaque(true);
4072 layer1
->SetPosition(occluding_layer_position
);
4074 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4075 host_impl_
.SetCurrentBeginFrameArgs(
4076 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4077 bool update_lcd_text
= false;
4078 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4080 unoccluded_tile_count
= 0;
4081 queue
.reset(new TilingSetRasterQueueAll(
4082 pending_layer_
->picture_layer_tiling_set(), false));
4083 while (!queue
->IsEmpty()) {
4084 Tile
* tile
= queue
->Top();
4086 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4088 bool tile_is_visible
=
4089 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
4090 if (tile_is_visible
)
4091 unoccluded_tile_count
++;
4094 EXPECT_EQ(20, unoccluded_tile_count
);
4097 layer1
->SetPosition(gfx::Point(0, 0));
4099 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4100 host_impl_
.SetCurrentBeginFrameArgs(
4101 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4102 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4104 unoccluded_tile_count
= 0;
4105 queue
.reset(new TilingSetRasterQueueAll(
4106 pending_layer_
->picture_layer_tiling_set(), false));
4107 while (!queue
->IsEmpty()) {
4108 Tile
* tile
= queue
->Top();
4110 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4112 bool tile_is_visible
=
4113 tile
->content_rect().Intersects(pending_layer_
->visible_content_rect());
4114 if (tile_is_visible
)
4115 unoccluded_tile_count
++;
4118 EXPECT_EQ(unoccluded_tile_count
, 0);
4121 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4122 OccludedTilesNotMarkedAsRequired
) {
4123 base::TimeTicks time_ticks
;
4124 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4125 host_impl_
.SetCurrentBeginFrameArgs(
4126 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4128 gfx::Size
tile_size(102, 102);
4129 gfx::Size
layer_bounds(1000, 1000);
4130 gfx::Size
viewport_size(500, 500);
4131 gfx::Point
occluding_layer_position(310, 0);
4133 host_impl_
.SetViewportSize(viewport_size
);
4135 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4136 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4137 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4140 int occluded_tile_count
= 0;
4141 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4142 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4144 occluded_tile_count
= 0;
4145 for (PictureLayerTiling::CoverageIterator
iter(
4147 pending_layer_
->contents_scale_x(),
4148 gfx::Rect(layer_bounds
));
4153 const Tile
* tile
= *iter
;
4155 // Fully occluded tiles are not required for activation.
4156 if (tile
->is_occluded(PENDING_TREE
)) {
4157 EXPECT_FALSE(tile
->required_for_activation());
4158 occluded_tile_count
++;
4161 EXPECT_EQ(occluded_tile_count
, 0);
4164 // Partial occlusion.
4165 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4166 LayerImpl
* layer1
= pending_layer_
->children()[0];
4167 layer1
->SetBounds(layer_bounds
);
4168 layer1
->SetContentBounds(layer_bounds
);
4169 layer1
->SetDrawsContent(true);
4170 layer1
->SetContentsOpaque(true);
4171 layer1
->SetPosition(occluding_layer_position
);
4173 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4174 host_impl_
.SetCurrentBeginFrameArgs(
4175 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4176 bool update_lcd_text
= false;
4177 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4179 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4180 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4181 tiling
->UpdateAllTilePrioritiesForTesting();
4183 occluded_tile_count
= 0;
4184 for (PictureLayerTiling::CoverageIterator
iter(
4186 pending_layer_
->contents_scale_x(),
4187 gfx::Rect(layer_bounds
));
4192 const Tile
* tile
= *iter
;
4194 if (tile
->is_occluded(PENDING_TREE
)) {
4195 EXPECT_FALSE(tile
->required_for_activation());
4196 occluded_tile_count
++;
4201 EXPECT_EQ(occluded_tile_count
, 5);
4204 EXPECT_EQ(occluded_tile_count
, 2);
4212 layer1
->SetPosition(gfx::PointF(0, 0));
4214 time_ticks
+= base::TimeDelta::FromMilliseconds(200);
4215 host_impl_
.SetCurrentBeginFrameArgs(
4216 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4217 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4219 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4220 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4221 tiling
->UpdateAllTilePrioritiesForTesting();
4223 occluded_tile_count
= 0;
4224 for (PictureLayerTiling::CoverageIterator
iter(
4226 pending_layer_
->contents_scale_x(),
4227 gfx::Rect(layer_bounds
));
4232 const Tile
* tile
= *iter
;
4234 if (tile
->is_occluded(PENDING_TREE
)) {
4235 EXPECT_FALSE(tile
->required_for_activation());
4236 occluded_tile_count
++;
4241 EXPECT_EQ(25, occluded_tile_count
);
4244 EXPECT_EQ(4, occluded_tile_count
);
4252 TEST_F(OcclusionTrackingPictureLayerImplTest
, OcclusionForDifferentScales
) {
4253 base::TimeTicks time_ticks
;
4254 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4255 host_impl_
.SetCurrentBeginFrameArgs(
4256 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4258 gfx::Size
tile_size(102, 102);
4259 gfx::Size
layer_bounds(1000, 1000);
4260 gfx::Size
viewport_size(500, 500);
4261 gfx::Point
occluding_layer_position(310, 0);
4263 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4264 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4266 host_impl_
.SetViewportSize(viewport_size
);
4268 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, Region());
4269 ASSERT_TRUE(pending_layer_
->CanHaveTilings());
4271 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 1));
4272 LayerImpl
* layer1
= pending_layer_
->children()[0];
4273 layer1
->SetBounds(layer_bounds
);
4274 layer1
->SetContentBounds(layer_bounds
);
4275 layer1
->SetDrawsContent(true);
4276 layer1
->SetContentsOpaque(true);
4277 layer1
->SetPosition(occluding_layer_position
);
4279 pending_layer_
->tilings()->RemoveAllTilings();
4280 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
4281 pending_layer_
->AddTiling(low_res_factor
);
4282 pending_layer_
->AddTiling(0.3f
);
4283 pending_layer_
->AddTiling(0.7f
);
4284 pending_layer_
->AddTiling(1.0f
);
4285 pending_layer_
->AddTiling(2.0f
);
4287 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4288 host_impl_
.SetCurrentBeginFrameArgs(
4289 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4290 // UpdateDrawProperties with the occluding layer.
4291 bool update_lcd_text
= false;
4292 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4294 EXPECT_EQ(5u, pending_layer_
->num_tilings());
4296 int occluded_tile_count
= 0;
4297 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4298 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4299 tiling
->UpdateAllTilePrioritiesForTesting();
4300 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4302 occluded_tile_count
= 0;
4303 for (size_t j
= 0; j
< tiles
.size(); ++j
) {
4304 if (tiles
[j
]->is_occluded(PENDING_TREE
)) {
4305 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4306 tiles
[j
]->content_rect(), 1.0f
/ tiles
[j
]->contents_scale());
4307 EXPECT_GE(scaled_content_rect
.x(), occluding_layer_position
.x());
4308 occluded_tile_count
++;
4314 EXPECT_EQ(occluded_tile_count
, 30);
4317 EXPECT_EQ(occluded_tile_count
, 5);
4320 EXPECT_EQ(occluded_tile_count
, 4);
4324 EXPECT_EQ(occluded_tile_count
, 2);
4332 TEST_F(OcclusionTrackingPictureLayerImplTest
, DifferentOcclusionOnTrees
) {
4333 gfx::Size
tile_size(102, 102);
4334 gfx::Size
layer_bounds(1000, 1000);
4335 gfx::Size
viewport_size(1000, 1000);
4336 gfx::Point
occluding_layer_position(310, 0);
4337 gfx::Rect
invalidation_rect(230, 230, 102, 102);
4339 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4340 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4341 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4342 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4344 host_impl_
.SetViewportSize(viewport_size
);
4345 SetupPendingTree(active_pile
);
4347 // Partially occlude the active layer.
4348 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 2));
4349 LayerImpl
* layer1
= pending_layer_
->children()[0];
4350 layer1
->SetBounds(layer_bounds
);
4351 layer1
->SetContentBounds(layer_bounds
);
4352 layer1
->SetDrawsContent(true);
4353 layer1
->SetContentsOpaque(true);
4354 layer1
->SetPosition(occluding_layer_position
);
4358 // Partially invalidate the pending layer.
4359 SetupPendingTreeWithInvalidation(pending_pile
, invalidation_rect
);
4361 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4362 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4363 tiling
->UpdateAllTilePrioritiesForTesting();
4365 for (PictureLayerTiling::CoverageIterator
iter(
4367 pending_layer_
->contents_scale_x(),
4368 gfx::Rect(layer_bounds
));
4373 const Tile
* tile
= *iter
;
4375 // All tiles are unoccluded on the pending tree.
4376 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4378 Tile
* twin_tile
= pending_layer_
->GetPendingOrActiveTwinTiling(tiling
)
4379 ->TileAt(iter
.i(), iter
.j());
4380 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4381 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4383 if (scaled_content_rect
.Intersects(invalidation_rect
)) {
4384 // Tiles inside the invalidation rect are only on the pending tree.
4385 EXPECT_NE(tile
, twin_tile
);
4387 // Unshared tiles should be unoccluded on the active tree by default.
4388 EXPECT_FALSE(tile
->is_occluded(ACTIVE_TREE
));
4390 // Tiles outside the invalidation rect are shared between both trees.
4391 EXPECT_EQ(tile
, twin_tile
);
4392 // Shared tiles are occluded on the active tree iff they lie beneath the
4394 EXPECT_EQ(tile
->is_occluded(ACTIVE_TREE
),
4395 scaled_content_rect
.x() >= occluding_layer_position
.x());
4400 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4401 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4403 for (PictureLayerTiling::CoverageIterator
iter(
4405 active_layer_
->contents_scale_x(),
4406 gfx::Rect(layer_bounds
));
4411 const Tile
* tile
= *iter
;
4413 Tile
* twin_tile
= active_layer_
->GetPendingOrActiveTwinTiling(tiling
)
4414 ->TileAt(iter
.i(), iter
.j());
4415 gfx::Rect scaled_content_rect
= ScaleToEnclosingRect(
4416 tile
->content_rect(), 1.0f
/ tile
->contents_scale());
4418 // Since we've already checked the shared tiles, only consider tiles in
4419 // the invalidation rect.
4420 if (scaled_content_rect
.Intersects(invalidation_rect
)) {
4421 // Tiles inside the invalidation rect are only on the active tree.
4422 EXPECT_NE(tile
, twin_tile
);
4424 // Unshared tiles should be unoccluded on the pending tree by default.
4425 EXPECT_FALSE(tile
->is_occluded(PENDING_TREE
));
4427 // Unshared tiles are occluded on the active tree iff they lie beneath
4428 // the occluding layer.
4429 EXPECT_EQ(tile
->is_occluded(ACTIVE_TREE
),
4430 scaled_content_rect
.x() >= occluding_layer_position
.x());
4436 TEST_F(OcclusionTrackingPictureLayerImplTest
,
4437 OccludedTilesConsideredDuringEviction
) {
4438 base::TimeTicks time_ticks
;
4439 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4440 host_impl_
.SetCurrentBeginFrameArgs(
4441 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4443 gfx::Size
tile_size(102, 102);
4444 gfx::Size
layer_bounds(1000, 1000);
4445 gfx::Size
viewport_size(1000, 1000);
4446 gfx::Point
pending_occluding_layer_position(310, 0);
4447 gfx::Point
active_occluding_layer_position(0, 310);
4448 gfx::Rect
invalidation_rect(230, 230, 102, 102);
4450 host_impl_
.SetViewportSize(viewport_size
);
4451 host_impl_
.SetDeviceScaleFactor(2.f
);
4453 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4454 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4455 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4456 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4458 SetupPendingTreeWithFixedTileSize(active_pile
, tile_size
, Region());
4460 // Partially occlude the active layer.
4461 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 2));
4462 LayerImpl
* active_occluding_layer
= pending_layer_
->children()[0];
4463 active_occluding_layer
->SetBounds(layer_bounds
);
4464 active_occluding_layer
->SetContentBounds(layer_bounds
);
4465 active_occluding_layer
->SetDrawsContent(true);
4466 active_occluding_layer
->SetContentsOpaque(true);
4467 active_occluding_layer
->SetPosition(active_occluding_layer_position
);
4471 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4472 // are not shared between trees.
4473 SetupPendingTreeWithFixedTileSize(pending_pile
, tile_size
, invalidation_rect
);
4475 // Partially occlude the pending layer in a different way.
4476 pending_layer_
->AddChild(LayerImpl::Create(host_impl_
.pending_tree(), 3));
4477 LayerImpl
* pending_occluding_layer
= pending_layer_
->children()[0];
4478 pending_occluding_layer
->SetBounds(layer_bounds
);
4479 pending_occluding_layer
->SetContentBounds(layer_bounds
);
4480 pending_occluding_layer
->SetDrawsContent(true);
4481 pending_occluding_layer
->SetContentsOpaque(true);
4482 pending_occluding_layer
->SetPosition(pending_occluding_layer_position
);
4484 EXPECT_EQ(2u, pending_layer_
->num_tilings());
4485 EXPECT_EQ(2u, active_layer_
->num_tilings());
4487 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4488 host_impl_
.SetCurrentBeginFrameArgs(
4489 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4490 // UpdateDrawProperties with the occluding layer.
4491 bool update_lcd_text
= false;
4492 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
4494 // The expected number of occluded tiles on each of the 2 tilings for each of
4495 // the 3 tree priorities.
4496 size_t expected_occluded_tile_count_on_both
[] = {9u, 1u};
4497 size_t expected_occluded_tile_count_on_active
[] = {30u, 3u};
4498 size_t expected_occluded_tile_count_on_pending
[] = {30u, 3u};
4500 size_t total_expected_occluded_tile_count_on_trees
[] = {33u, 33u};
4502 // Verify number of occluded tiles on the pending layer for each tiling.
4503 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4504 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4505 tiling
->UpdateAllTilePrioritiesForTesting();
4507 size_t occluded_tile_count_on_pending
= 0u;
4508 size_t occluded_tile_count_on_active
= 0u;
4509 size_t occluded_tile_count_on_both
= 0u;
4510 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
,
4511 gfx::Rect(layer_bounds
));
4517 if (tile
->is_occluded(PENDING_TREE
))
4518 occluded_tile_count_on_pending
++;
4519 if (tile
->is_occluded(ACTIVE_TREE
))
4520 occluded_tile_count_on_active
++;
4521 if (tile
->is_occluded(PENDING_TREE
) && tile
->is_occluded(ACTIVE_TREE
))
4522 occluded_tile_count_on_both
++;
4524 EXPECT_EQ(expected_occluded_tile_count_on_pending
[i
],
4525 occluded_tile_count_on_pending
)
4526 << tiling
->contents_scale();
4527 EXPECT_EQ(expected_occluded_tile_count_on_active
[i
],
4528 occluded_tile_count_on_active
)
4529 << tiling
->contents_scale();
4530 EXPECT_EQ(expected_occluded_tile_count_on_both
[i
],
4531 occluded_tile_count_on_both
)
4532 << tiling
->contents_scale();
4535 // Verify number of occluded tiles on the active layer for each tiling.
4536 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
4537 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
4538 tiling
->UpdateAllTilePrioritiesForTesting();
4540 size_t occluded_tile_count_on_pending
= 0u;
4541 size_t occluded_tile_count_on_active
= 0u;
4542 size_t occluded_tile_count_on_both
= 0u;
4543 for (PictureLayerTiling::CoverageIterator
iter(
4545 pending_layer_
->contents_scale_x(),
4546 gfx::Rect(layer_bounds
));
4553 if (tile
->is_occluded(PENDING_TREE
))
4554 occluded_tile_count_on_pending
++;
4555 if (tile
->is_occluded(ACTIVE_TREE
))
4556 occluded_tile_count_on_active
++;
4557 if (tile
->is_occluded(PENDING_TREE
) && tile
->is_occluded(ACTIVE_TREE
))
4558 occluded_tile_count_on_both
++;
4560 EXPECT_EQ(expected_occluded_tile_count_on_pending
[i
],
4561 occluded_tile_count_on_pending
)
4563 EXPECT_EQ(expected_occluded_tile_count_on_active
[i
],
4564 occluded_tile_count_on_active
)
4566 EXPECT_EQ(expected_occluded_tile_count_on_both
[i
],
4567 occluded_tile_count_on_both
)
4571 std::vector
<Tile
*> all_tiles
;
4572 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
4573 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
4574 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
4575 all_tiles
.insert(all_tiles
.end(), tiles
.begin(), tiles
.end());
4578 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles
);
4580 VerifyEvictionConsidersOcclusion(
4581 pending_layer_
, active_layer_
, PENDING_TREE
,
4582 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
]);
4583 VerifyEvictionConsidersOcclusion(
4584 active_layer_
, pending_layer_
, ACTIVE_TREE
,
4585 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
]);
4587 // Repeat the tests without valid active tree priorities.
4588 active_layer_
->set_has_valid_tile_priorities(false);
4589 VerifyEvictionConsidersOcclusion(
4590 pending_layer_
, active_layer_
, PENDING_TREE
,
4591 total_expected_occluded_tile_count_on_trees
[PENDING_TREE
]);
4592 VerifyEvictionConsidersOcclusion(
4593 active_layer_
, pending_layer_
, ACTIVE_TREE
, 0u);
4594 active_layer_
->set_has_valid_tile_priorities(true);
4596 // Repeat the tests without valid pending tree priorities.
4597 pending_layer_
->set_has_valid_tile_priorities(false);
4598 VerifyEvictionConsidersOcclusion(
4599 active_layer_
, pending_layer_
, ACTIVE_TREE
,
4600 total_expected_occluded_tile_count_on_trees
[ACTIVE_TREE
]);
4601 VerifyEvictionConsidersOcclusion(
4602 pending_layer_
, active_layer_
, PENDING_TREE
, 0u);
4603 pending_layer_
->set_has_valid_tile_priorities(true);
4606 TEST_F(PictureLayerImplTest
, PendingOrActiveTwinLayer
) {
4607 gfx::Size
tile_size(102, 102);
4608 gfx::Size
layer_bounds(1000, 1000);
4610 scoped_refptr
<FakePicturePileImpl
> pile
=
4611 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4612 SetupPendingTree(pile
);
4613 EXPECT_FALSE(pending_layer_
->GetPendingOrActiveTwinLayer());
4616 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4618 SetupPendingTree(pile
);
4619 EXPECT_TRUE(pending_layer_
->GetPendingOrActiveTwinLayer());
4620 EXPECT_TRUE(active_layer_
->GetPendingOrActiveTwinLayer());
4621 EXPECT_EQ(pending_layer_
, active_layer_
->GetPendingOrActiveTwinLayer());
4622 EXPECT_EQ(active_layer_
, pending_layer_
->GetPendingOrActiveTwinLayer());
4625 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4627 // Make an empty pending tree.
4628 host_impl_
.CreatePendingTree();
4629 host_impl_
.pending_tree()->DetachLayerTree();
4630 EXPECT_FALSE(active_layer_
->GetPendingOrActiveTwinLayer());
4633 TEST_F(PictureLayerImplTest
, RecycledTwinLayer
) {
4634 gfx::Size
tile_size(102, 102);
4635 gfx::Size
layer_bounds(1000, 1000);
4637 scoped_refptr
<FakePicturePileImpl
> pile
=
4638 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4639 SetupPendingTree(pile
);
4640 EXPECT_FALSE(pending_layer_
->GetRecycledTwinLayer());
4643 EXPECT_TRUE(active_layer_
->GetRecycledTwinLayer());
4644 EXPECT_EQ(old_pending_layer_
, active_layer_
->GetRecycledTwinLayer());
4646 SetupPendingTree(pile
);
4647 EXPECT_FALSE(pending_layer_
->GetRecycledTwinLayer());
4648 EXPECT_FALSE(active_layer_
->GetRecycledTwinLayer());
4651 EXPECT_TRUE(active_layer_
->GetRecycledTwinLayer());
4652 EXPECT_EQ(old_pending_layer_
, active_layer_
->GetRecycledTwinLayer());
4654 // Make an empty pending tree.
4655 host_impl_
.CreatePendingTree();
4656 host_impl_
.pending_tree()->DetachLayerTree();
4657 EXPECT_FALSE(active_layer_
->GetRecycledTwinLayer());
4660 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid
) {
4661 base::TimeTicks time_ticks
;
4662 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4663 host_impl_
.SetCurrentBeginFrameArgs(
4664 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4666 gfx::Size
tile_size(100, 100);
4667 gfx::Size
layer_bounds(200, 200);
4668 gfx::Rect
layer_rect(layer_bounds
);
4670 FakeContentLayerClient client
;
4671 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
4672 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4673 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&host_client
);
4674 host
->SetRootLayer(layer
);
4675 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4677 int frame_number
= 0;
4679 client
.set_fill_with_nonsolid_color(!test_for_solid
);
4681 Region
invalidation(layer_rect
);
4682 recording_source
->UpdateAndExpandInvalidation(
4683 &client
, &invalidation
, layer_bounds
, layer_rect
, frame_number
++,
4684 RecordingSource::RECORD_NORMALLY
);
4686 scoped_refptr
<RasterSource
> pending_raster_source
=
4687 recording_source
->CreateRasterSource(true);
4689 SetupPendingTreeWithFixedTileSize(pending_raster_source
, tile_size
, Region());
4692 if (test_for_solid
) {
4693 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4695 ASSERT_TRUE(active_layer_
->tilings());
4696 ASSERT_GT(active_layer_
->tilings()->num_tilings(), 0u);
4697 std::vector
<Tile
*> tiles
=
4698 active_layer_
->tilings()->tiling_at(0)->AllTilesForTesting();
4699 EXPECT_FALSE(tiles
.empty());
4700 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4703 scoped_ptr
<RenderPass
> render_pass
= RenderPass::Create();
4704 AppendQuadsData data
;
4705 active_layer_
->WillDraw(DRAW_MODE_SOFTWARE
, nullptr);
4706 active_layer_
->AppendQuads(render_pass
.get(), &data
);
4707 active_layer_
->DidDraw(nullptr);
4709 DrawQuad::Material expected
= test_for_solid
4710 ? DrawQuad::Material::SOLID_COLOR
4711 : DrawQuad::Material::TILED_CONTENT
;
4712 EXPECT_EQ(expected
, render_pass
->quad_list
.front()->material
);
4715 TEST_F(PictureLayerImplTest
, DrawSolidQuads
) {
4716 TestQuadsForSolidColor(true);
4719 TEST_F(PictureLayerImplTest
, DrawNonSolidQuads
) {
4720 TestQuadsForSolidColor(false);
4723 TEST_F(PictureLayerImplTest
, NonSolidToSolidNoTilings
) {
4724 base::TimeTicks time_ticks
;
4725 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4726 host_impl_
.SetCurrentBeginFrameArgs(
4727 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4729 gfx::Size
tile_size(100, 100);
4730 gfx::Size
layer_bounds(200, 200);
4731 gfx::Rect
layer_rect(layer_bounds
);
4733 FakeContentLayerClient client
;
4734 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
4735 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
4736 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&host_client
);
4737 host
->SetRootLayer(layer
);
4738 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4740 int frame_number
= 0;
4742 client
.set_fill_with_nonsolid_color(true);
4744 Region
invalidation1(layer_rect
);
4745 recording_source
->UpdateAndExpandInvalidation(
4746 &client
, &invalidation1
, layer_bounds
, layer_rect
, frame_number
++,
4747 RecordingSource::RECORD_NORMALLY
);
4749 scoped_refptr
<RasterSource
> raster_source1
=
4750 recording_source
->CreateRasterSource(true);
4752 SetupPendingTree(raster_source1
);
4754 bool update_lcd_text
= false;
4755 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
4757 // We've started with a solid layer that contains some tilings.
4758 ASSERT_TRUE(active_layer_
->tilings());
4759 EXPECT_NE(0u, active_layer_
->tilings()->num_tilings());
4761 client
.set_fill_with_nonsolid_color(false);
4763 Region
invalidation2(layer_rect
);
4764 recording_source
->UpdateAndExpandInvalidation(
4765 &client
, &invalidation2
, layer_bounds
, layer_rect
, frame_number
++,
4766 RecordingSource::RECORD_NORMALLY
);
4768 scoped_refptr
<RasterSource
> raster_source2
=
4769 recording_source
->CreateRasterSource(true);
4771 SetupPendingTree(raster_source2
);
4774 // We've switched to a solid color, so we should end up with no tilings.
4775 ASSERT_TRUE(active_layer_
->tilings());
4776 EXPECT_EQ(0u, active_layer_
->tilings()->num_tilings());
4779 TEST_F(PictureLayerImplTest
, ChangeInViewportAllowsTilingUpdates
) {
4780 base::TimeTicks time_ticks
;
4781 time_ticks
+= base::TimeDelta::FromMilliseconds(1);
4782 host_impl_
.SetCurrentBeginFrameArgs(
4783 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
, time_ticks
));
4785 gfx::Size
tile_size(100, 100);
4786 gfx::Size
layer_bounds(400, 4000);
4788 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
4789 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4790 scoped_refptr
<FakePicturePileImpl
> active_pile
=
4791 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4793 SetupTrees(pending_pile
, active_pile
);
4795 Region invalidation
;
4796 gfx::Rect viewport
= gfx::Rect(0, 0, 100, 100);
4797 gfx::Transform transform
;
4799 host_impl_
.SetRequiresHighResToDraw();
4802 pending_layer_
->draw_properties().visible_content_rect
= viewport
;
4803 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4804 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
4805 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
4807 // Ensure we can't activate.
4808 EXPECT_FALSE(host_impl_
.tile_manager()->IsReadyToActivate());
4810 // Now in the same frame, move the viewport (this can happen during
4812 viewport
= gfx::Rect(0, 2000, 100, 100);
4815 pending_layer_
->draw_properties().visible_content_rect
= viewport
;
4816 pending_layer_
->draw_properties().screen_space_transform
= transform
;
4817 SetupDrawPropertiesAndUpdateTiles(pending_layer_
, 1.f
, 1.f
, 1.f
, 1.f
, false);
4818 pending_layer_
->HighResTiling()->UpdateAllTilePrioritiesForTesting();
4820 // Make sure all viewport tiles (viewport from the tiling) are ready to draw.
4821 std::vector
<Tile
*> tiles
;
4822 for (PictureLayerTiling::CoverageIterator
iter(
4823 pending_layer_
->HighResTiling(),
4825 pending_layer_
->HighResTiling()->GetCurrentVisibleRectForTesting());
4829 tiles
.push_back(*iter
);
4832 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
4834 // Ensure we can activate.
4835 EXPECT_TRUE(host_impl_
.tile_manager()->IsReadyToActivate());
4838 TEST_F(PictureLayerImplTest
, CloneMissingRecordings
) {
4839 gfx::Size
tile_size(100, 100);
4840 gfx::Size
layer_bounds(400, 400);
4842 scoped_refptr
<FakePicturePileImpl
> filled_pile
=
4843 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
4845 scoped_ptr
<FakePicturePile
> partial_recording
=
4846 FakePicturePile::CreateEmptyPile(tile_size
, layer_bounds
);
4847 for (int i
= 1; i
< partial_recording
->tiling().num_tiles_x(); ++i
) {
4848 for (int j
= 1; j
< partial_recording
->tiling().num_tiles_y(); ++j
)
4849 partial_recording
->AddRecordingAt(i
, j
);
4851 scoped_refptr
<FakePicturePileImpl
> partial_pile
=
4852 FakePicturePileImpl::CreateFromPile(partial_recording
.get(), nullptr);
4854 SetupPendingTreeWithFixedTileSize(filled_pile
, tile_size
, Region());
4857 PictureLayerTiling
* pending_tiling
= old_pending_layer_
->HighResTiling();
4858 PictureLayerTiling
* active_tiling
= active_layer_
->HighResTiling();
4860 // We should have all tiles in both tile sets.
4861 EXPECT_EQ(5u * 5u, pending_tiling
->AllTilesForTesting().size());
4862 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4864 // Now put a partially-recorded pile on the pending tree (and invalidate
4865 // everything, since the main thread PicturePile will invalidate dropped
4866 // recordings). This will cause us to be missing some tiles.
4867 SetupPendingTreeWithFixedTileSize(partial_pile
, tile_size
,
4868 Region(gfx::Rect(layer_bounds
)));
4869 EXPECT_EQ(3u * 3u, pending_tiling
->AllTilesForTesting().size());
4870 EXPECT_FALSE(pending_tiling
->TileAt(0, 0));
4871 EXPECT_FALSE(pending_tiling
->TileAt(1, 1));
4872 EXPECT_TRUE(pending_tiling
->TileAt(2, 2));
4874 // Active is not affected yet.
4875 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4877 // Activate the tree. The same tiles go missing on the active tree.
4879 EXPECT_EQ(3u * 3u, active_tiling
->AllTilesForTesting().size());
4880 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
4881 EXPECT_FALSE(active_tiling
->TileAt(1, 1));
4882 EXPECT_TRUE(active_tiling
->TileAt(2, 2));
4884 // Now put a full recording on the pending tree again. We'll get all our tiles
4886 SetupPendingTreeWithFixedTileSize(filled_pile
, tile_size
,
4887 Region(gfx::Rect(layer_bounds
)));
4888 EXPECT_EQ(5u * 5u, pending_tiling
->AllTilesForTesting().size());
4890 // Active is not affected yet.
4891 EXPECT_EQ(3u * 3u, active_tiling
->AllTilesForTesting().size());
4893 // Activate the tree. The tiles are created and shared on the active tree.
4895 EXPECT_EQ(5u * 5u, active_tiling
->AllTilesForTesting().size());
4896 EXPECT_TRUE(active_tiling
->TileAt(0, 0)->is_shared());
4897 EXPECT_TRUE(active_tiling
->TileAt(1, 1)->is_shared());
4898 EXPECT_TRUE(active_tiling
->TileAt(2, 2)->is_shared());
4901 class TileSizeSettings
: public ImplSidePaintingSettings
{
4903 TileSizeSettings() {
4904 default_tile_size
= gfx::Size(100, 100);
4905 max_untiled_layer_size
= gfx::Size(200, 200);
4909 class TileSizeTest
: public PictureLayerImplTest
{
4911 TileSizeTest() : PictureLayerImplTest(TileSizeSettings()) {}
4914 TEST_F(TileSizeTest
, TileSizes
) {
4915 host_impl_
.CreatePendingTree();
4917 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
4918 scoped_ptr
<FakePictureLayerImpl
> layer
=
4919 FakePictureLayerImpl::Create(pending_tree
, id_
);
4921 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
4924 host_impl_
.SetUseGpuRasterization(false);
4926 // Default tile-size for large layers.
4927 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
4928 EXPECT_EQ(result
.width(), 100);
4929 EXPECT_EQ(result
.height(), 100);
4930 // Don't tile and round-up, when under max_untiled_layer_size.
4931 result
= layer
->CalculateTileSize(gfx::Size(42, 42));
4932 EXPECT_EQ(result
.width(), 64);
4933 EXPECT_EQ(result
.height(), 64);
4934 result
= layer
->CalculateTileSize(gfx::Size(191, 191));
4935 EXPECT_EQ(result
.width(), 192);
4936 EXPECT_EQ(result
.height(), 192);
4937 result
= layer
->CalculateTileSize(gfx::Size(199, 199));
4938 EXPECT_EQ(result
.width(), 200);
4939 EXPECT_EQ(result
.height(), 200);
4941 // Gpu-rasterization uses 25% viewport-height tiles.
4942 // The +2's below are for border texels.
4943 host_impl_
.SetUseGpuRasterization(true);
4944 host_impl_
.SetViewportSize(gfx::Size(2000, 2000));
4945 result
= layer
->CalculateTileSize(gfx::Size(10000, 10000));
4946 EXPECT_EQ(result
.width(), 2000);
4947 EXPECT_EQ(result
.height(), 500 + 2);
4949 // Clamp and round-up, when smaller than viewport.
4950 // Tile-height doubles to 50% when width shrinks to <= 50%.
4951 host_impl_
.SetViewportSize(gfx::Size(1000, 1000));
4952 result
= layer
->CalculateTileSize(gfx::Size(447, 10000));
4953 EXPECT_EQ(result
.width(), 448);
4954 EXPECT_EQ(result
.height(), 500 + 2);
4956 // Largest layer is 50% of viewport width (rounded up), and
4957 // 50% of viewport in height.
4958 result
= layer
->CalculateTileSize(gfx::Size(447, 400));
4959 EXPECT_EQ(result
.width(), 448);
4960 EXPECT_EQ(result
.height(), 448);
4961 result
= layer
->CalculateTileSize(gfx::Size(500, 499));
4962 EXPECT_EQ(result
.width(), 512);
4963 EXPECT_EQ(result
.height(), 500 + 2);