Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / layers / picture_layer_impl_unittest.cc
blob1628c0c5c76f384b3554af4c6afd3f333ee047fb
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"
7 #include <algorithm>
8 #include <limits>
9 #include <set>
10 #include <utility>
12 #include "base/location.h"
13 #include "base/thread_task_runner_handle.h"
14 #include "cc/base/math_util.h"
15 #include "cc/layers/append_quads_data.h"
16 #include "cc/layers/picture_layer.h"
17 #include "cc/quads/draw_quad.h"
18 #include "cc/quads/tile_draw_quad.h"
19 #include "cc/test/begin_frame_args_test.h"
20 #include "cc/test/fake_content_layer_client.h"
21 #include "cc/test/fake_impl_proxy.h"
22 #include "cc/test/fake_layer_tree_host_impl.h"
23 #include "cc/test/fake_output_surface.h"
24 #include "cc/test/fake_picture_layer_impl.h"
25 #include "cc/test/fake_picture_pile_impl.h"
26 #include "cc/test/geometry_test_utils.h"
27 #include "cc/test/gpu_rasterization_enabled_settings.h"
28 #include "cc/test/layer_test_common.h"
29 #include "cc/test/test_shared_bitmap_manager.h"
30 #include "cc/test/test_task_graph_runner.h"
31 #include "cc/test/test_web_graphics_context_3d.h"
32 #include "cc/tiles/tiling_set_raster_queue_all.h"
33 #include "cc/tiles/tiling_set_raster_queue_required.h"
34 #include "cc/trees/layer_tree_impl.h"
35 #include "testing/gtest/include/gtest/gtest.h"
36 #include "ui/gfx/geometry/rect_conversions.h"
37 #include "ui/gfx/geometry/size_conversions.h"
39 namespace cc {
40 namespace {
42 #define EXPECT_BOTH_EQ(expression, x) \
43 do { \
44 EXPECT_EQ(x, pending_layer_->expression); \
45 EXPECT_EQ(x, active_layer_->expression); \
46 } while (false)
48 #define EXPECT_BOTH_NE(expression, x) \
49 do { \
50 EXPECT_NE(x, pending_layer_->expression); \
51 EXPECT_NE(x, active_layer_->expression); \
52 } while (false)
54 #define EXPECT_BOTH_TRUE(expression) \
55 do { \
56 EXPECT_TRUE(pending_layer_->expression); \
57 EXPECT_TRUE(active_layer_->expression); \
58 } while (false)
60 #define EXPECT_BOTH_FALSE(expression) \
61 do { \
62 EXPECT_FALSE(pending_layer_->expression); \
63 EXPECT_FALSE(active_layer_->expression); \
64 } while (false)
66 class MockCanvas : public SkCanvas {
67 public:
68 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {}
70 void onDrawRect(const SkRect& rect, const SkPaint& paint) override {
71 // Capture calls before SkCanvas quickReject() kicks in.
72 rects_.push_back(rect);
75 std::vector<SkRect> rects_;
78 class PictureLayerImplTestSettings : public GpuRasterizationEnabledSettings {
79 public:
80 PictureLayerImplTestSettings() {
81 layer_transforms_should_scale_layer_contents = true;
85 class NoLowResTilingsSettings : public PictureLayerImplTestSettings {};
87 class LowResTilingsSettings : public PictureLayerImplTestSettings {
88 public:
89 LowResTilingsSettings() { create_low_res_tiling = true; }
92 class PictureLayerImplTest : public testing::Test {
93 public:
94 PictureLayerImplTest()
95 : proxy_(base::ThreadTaskRunnerHandle::Get()),
96 host_impl_(LowResTilingsSettings(),
97 &proxy_,
98 &shared_bitmap_manager_,
99 &task_graph_runner_),
100 root_id_(6),
101 id_(7),
102 pending_layer_(nullptr),
103 old_pending_layer_(nullptr),
104 active_layer_(nullptr) {
105 host_impl_.SetViewportSize(gfx::Size(10000, 10000));
108 explicit PictureLayerImplTest(const LayerTreeSettings& settings)
109 : proxy_(base::ThreadTaskRunnerHandle::Get()),
110 host_impl_(settings,
111 &proxy_,
112 &shared_bitmap_manager_,
113 &task_graph_runner_),
114 root_id_(6),
115 id_(7) {
116 host_impl_.SetViewportSize(gfx::Size(10000, 10000));
119 ~PictureLayerImplTest() override {}
121 void SetUp() override { InitializeRenderer(); }
123 virtual void InitializeRenderer() {
124 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d());
127 void SetupDefaultTrees(const gfx::Size& layer_bounds) {
128 gfx::Size tile_size(100, 100);
130 scoped_refptr<FakePicturePileImpl> pending_pile =
131 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
132 scoped_refptr<FakePicturePileImpl> active_pile =
133 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
135 SetupTrees(pending_pile, active_pile);
138 void SetupDefaultTreesWithInvalidation(const gfx::Size& layer_bounds,
139 const Region& invalidation) {
140 gfx::Size tile_size(100, 100);
142 scoped_refptr<FakePicturePileImpl> pending_pile =
143 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
144 scoped_refptr<FakePicturePileImpl> active_pile =
145 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
147 SetupTreesWithInvalidation(pending_pile, active_pile, invalidation);
150 void ActivateTree() {
151 host_impl_.ActivateSyncTree();
152 CHECK(!host_impl_.pending_tree());
153 CHECK(host_impl_.recycle_tree());
154 old_pending_layer_ = pending_layer_;
155 pending_layer_ = nullptr;
156 active_layer_ = static_cast<FakePictureLayerImpl*>(
157 host_impl_.active_tree()->LayerById(id_));
159 bool update_lcd_text = false;
160 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
163 void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds,
164 const gfx::Size& tile_size,
165 const Region& invalidation) {
166 gfx::Size pile_tile_size(100, 100);
168 scoped_refptr<FakePicturePileImpl> pending_pile =
169 FakePicturePileImpl::CreateFilledPile(pile_tile_size, layer_bounds);
170 scoped_refptr<FakePicturePileImpl> active_pile =
171 FakePicturePileImpl::CreateFilledPile(pile_tile_size, layer_bounds);
173 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size,
174 invalidation);
177 void SetupTrees(
178 scoped_refptr<PicturePileImpl> pending_pile,
179 scoped_refptr<PicturePileImpl> active_pile) {
180 SetupPendingTree(active_pile);
181 ActivateTree();
182 SetupPendingTreeInternal(pending_pile, gfx::Size(), Region());
185 void SetupTreesWithInvalidation(scoped_refptr<PicturePileImpl> pending_pile,
186 scoped_refptr<PicturePileImpl> active_pile,
187 const Region& pending_invalidation) {
188 SetupPendingTreeInternal(active_pile, gfx::Size(), Region());
189 ActivateTree();
190 SetupPendingTreeInternal(pending_pile, gfx::Size(), pending_invalidation);
193 void SetupTreesWithFixedTileSize(scoped_refptr<PicturePileImpl> pending_pile,
194 scoped_refptr<PicturePileImpl> active_pile,
195 const gfx::Size& tile_size,
196 const Region& pending_invalidation) {
197 SetupPendingTreeInternal(active_pile, tile_size, Region());
198 ActivateTree();
199 SetupPendingTreeInternal(pending_pile, tile_size, pending_invalidation);
202 void SetupPendingTree(scoped_refptr<RasterSource> raster_source) {
203 SetupPendingTreeInternal(raster_source, gfx::Size(), Region());
206 void SetupPendingTreeWithInvalidation(
207 scoped_refptr<RasterSource> raster_source,
208 const Region& invalidation) {
209 SetupPendingTreeInternal(raster_source, gfx::Size(), invalidation);
212 void SetupPendingTreeWithFixedTileSize(
213 scoped_refptr<RasterSource> raster_source,
214 const gfx::Size& tile_size,
215 const Region& invalidation) {
216 SetupPendingTreeInternal(raster_source, tile_size, invalidation);
219 void SetupPendingTreeInternal(scoped_refptr<RasterSource> raster_source,
220 const gfx::Size& tile_size,
221 const Region& invalidation) {
222 host_impl_.CreatePendingTree();
223 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.00001f,
224 100000.f);
225 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
227 // Steal from the recycled tree if possible.
228 scoped_ptr<LayerImpl> pending_root = pending_tree->DetachLayerTree();
229 scoped_ptr<FakePictureLayerImpl> pending_layer;
230 DCHECK_IMPLIES(pending_root, pending_root->id() == root_id_);
231 if (!pending_root) {
232 pending_root = LayerImpl::Create(pending_tree, root_id_);
233 pending_layer = FakePictureLayerImpl::Create(pending_tree, id_);
234 if (!tile_size.IsEmpty())
235 pending_layer->set_fixed_tile_size(tile_size);
236 pending_layer->SetDrawsContent(true);
237 } else {
238 pending_layer.reset(static_cast<FakePictureLayerImpl*>(
239 pending_root->RemoveChild(pending_root->children()[0]).release()));
240 if (!tile_size.IsEmpty())
241 pending_layer->set_fixed_tile_size(tile_size);
243 pending_root->SetHasRenderSurface(true);
244 // The bounds() just mirror the pile size.
245 pending_layer->SetBounds(raster_source->GetSize());
246 pending_layer->SetRasterSourceOnPending(raster_source, invalidation);
248 pending_root->AddChild(pending_layer.Pass());
249 pending_tree->SetRootLayer(pending_root.Pass());
251 pending_layer_ = static_cast<FakePictureLayerImpl*>(
252 host_impl_.pending_tree()->LayerById(id_));
254 // Add tilings/tiles for the layer.
255 bool update_lcd_text = false;
256 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
259 void SetupDrawPropertiesAndUpdateTiles(
260 FakePictureLayerImpl* layer,
261 float ideal_contents_scale,
262 float device_scale_factor,
263 float page_scale_factor,
264 float maximum_animation_contents_scale,
265 float starting_animation_contents_scale,
266 bool animating_transform_to_screen) {
267 host_impl_.SetDeviceScaleFactor(device_scale_factor);
268 host_impl_.active_tree()->SetPageScaleOnActiveTree(page_scale_factor);
270 gfx::Transform scale_transform;
271 scale_transform.Scale(ideal_contents_scale, ideal_contents_scale);
272 layer->draw_properties().target_space_transform = scale_transform;
273 DCHECK_EQ(layer->GetIdealContentsScale(), ideal_contents_scale);
274 layer->draw_properties().maximum_animation_contents_scale =
275 maximum_animation_contents_scale;
276 layer->draw_properties().starting_animation_contents_scale =
277 starting_animation_contents_scale;
278 layer->draw_properties().screen_space_transform_is_animating =
279 animating_transform_to_screen;
280 bool resourceless_software_draw = false;
281 layer->UpdateTiles(resourceless_software_draw);
283 static void VerifyAllPrioritizedTilesExistAndHavePile(
284 const PictureLayerTiling* tiling,
285 PicturePileImpl* pile) {
286 auto prioritized_tiles =
287 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
288 for (PictureLayerTiling::CoverageIterator iter(
289 tiling,
290 tiling->contents_scale(),
291 gfx::Rect(tiling->tiling_size()));
292 iter;
293 ++iter) {
294 EXPECT_TRUE(*iter);
295 EXPECT_EQ(pile, prioritized_tiles[*iter].raster_source());
299 void SetContentsScaleOnBothLayers(float contents_scale,
300 float device_scale_factor,
301 float page_scale_factor,
302 float maximum_animation_contents_scale,
303 float starting_animation_contents_scale,
304 bool animating_transform) {
305 SetupDrawPropertiesAndUpdateTiles(
306 pending_layer_, contents_scale, device_scale_factor, page_scale_factor,
307 maximum_animation_contents_scale, starting_animation_contents_scale,
308 animating_transform);
310 SetupDrawPropertiesAndUpdateTiles(
311 active_layer_, contents_scale, device_scale_factor, page_scale_factor,
312 maximum_animation_contents_scale, starting_animation_contents_scale,
313 animating_transform);
316 void ResetTilingsAndRasterScales() {
317 if (pending_layer_) {
318 pending_layer_->ReleaseResources();
319 EXPECT_FALSE(pending_layer_->tilings());
320 pending_layer_->RecreateResources();
321 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
324 if (active_layer_) {
325 active_layer_->ReleaseResources();
326 EXPECT_FALSE(active_layer_->tilings());
327 active_layer_->RecreateResources();
328 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
332 size_t NumberOfTilesRequired(PictureLayerTiling* tiling) {
333 size_t num_required = 0;
334 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
335 for (size_t i = 0; i < tiles.size(); ++i) {
336 if (tiles[i]->required_for_activation())
337 num_required++;
339 return num_required;
342 void AssertAllTilesRequired(PictureLayerTiling* tiling) {
343 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
344 for (size_t i = 0; i < tiles.size(); ++i)
345 EXPECT_TRUE(tiles[i]->required_for_activation()) << "i: " << i;
346 EXPECT_GT(tiles.size(), 0u);
349 void AssertNoTilesRequired(PictureLayerTiling* tiling) {
350 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
351 for (size_t i = 0; i < tiles.size(); ++i)
352 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i;
353 EXPECT_GT(tiles.size(), 0u);
356 protected:
357 void TestQuadsForSolidColor(bool test_for_solid);
359 FakeImplProxy proxy_;
360 TestSharedBitmapManager shared_bitmap_manager_;
361 TestTaskGraphRunner task_graph_runner_;
362 FakeLayerTreeHostImpl host_impl_;
363 int root_id_;
364 int id_;
365 FakePictureLayerImpl* pending_layer_;
366 FakePictureLayerImpl* old_pending_layer_;
367 FakePictureLayerImpl* active_layer_;
368 LayerSettings layer_settings_;
370 private:
371 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest);
374 class NoLowResPictureLayerImplTest : public PictureLayerImplTest {
375 public:
376 NoLowResPictureLayerImplTest()
377 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
380 TEST_F(PictureLayerImplTest, TileGridAlignment) {
381 // Layer to span 4 raster tiles in x and in y
382 LayerTreeSettings settings;
383 gfx::Size layer_size(settings.default_tile_size.width() * 7 / 2,
384 settings.default_tile_size.height() * 7 / 2);
386 scoped_refptr<FakePicturePileImpl> pending_pile =
387 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
389 scoped_ptr<FakePicturePile> active_recording =
390 FakePicturePile::CreateFilledPile(layer_size, layer_size);
391 scoped_refptr<FakePicturePileImpl> active_pile =
392 FakePicturePileImpl::CreateFromPile(active_recording.get(), nullptr);
394 SetupTrees(pending_pile, active_pile);
396 // Add 1x1 rects at the centers of each tile, then re-record pile contents
397 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
398 std::vector<Tile*> tiles =
399 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
400 EXPECT_EQ(16u, tiles.size());
401 std::vector<SkRect> rects;
402 std::vector<Tile*>::const_iterator tile_iter;
403 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
404 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint();
405 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1);
406 active_recording->add_draw_rect(rect);
407 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1));
410 // Force re-raster with newly injected content
411 active_recording->RemoveRecordingAt(0, 0);
412 active_recording->AddRecordingAt(0, 0);
414 scoped_refptr<FakePicturePileImpl> updated_active_pile =
415 FakePicturePileImpl::CreateFromPile(active_recording.get(), nullptr);
417 std::vector<SkRect>::const_iterator rect_iter = rects.begin();
418 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
419 MockCanvas mock_canvas(1000, 1000);
420 updated_active_pile->PlaybackToSharedCanvas(
421 &mock_canvas, (*tile_iter)->content_rect(), 1.0f);
423 // This test verifies that when drawing the contents of a specific tile
424 // at content scale 1.0, the playback canvas never receives content from
425 // neighboring tiles which indicates that the tile grid embedded in
426 // SkPicture is perfectly aligned with the compositor's tiles.
427 EXPECT_EQ(1u, mock_canvas.rects_.size());
428 EXPECT_EQ(*rect_iter, mock_canvas.rects_[0]);
429 rect_iter++;
433 TEST_F(PictureLayerImplTest, CloneNoInvalidation) {
434 gfx::Size tile_size(100, 100);
435 gfx::Size layer_bounds(400, 400);
437 scoped_refptr<FakePicturePileImpl> pending_pile =
438 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
439 scoped_refptr<FakePicturePileImpl> active_pile =
440 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
442 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
444 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
445 active_layer_->tilings()->num_tilings());
447 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
448 EXPECT_GT(tilings->num_tilings(), 0u);
449 for (size_t i = 0; i < tilings->num_tilings(); ++i)
450 EXPECT_TRUE(tilings->tiling_at(i)->AllTilesForTesting().empty());
453 TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) {
454 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
455 gfx::Size tile_size(100, 100);
456 gfx::Size layer_bounds(400, 400);
458 scoped_refptr<FakePicturePileImpl> pending_pile =
459 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
460 scoped_refptr<FakePicturePileImpl> active_pile =
461 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
463 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
465 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
466 false);
468 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
470 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the
471 // identify transform for tile priority.
472 bool resourceless_software_draw = false;
473 gfx::Rect viewport = gfx::Rect(layer_bounds),
474 viewport_rect_for_tile_priority = gfx::Rect(0, 0, 100, 100);
475 gfx::Transform transform, transform_for_tile_priority;
477 host_impl_.SetExternalDrawConstraints(transform,
478 viewport,
479 viewport,
480 viewport_rect_for_tile_priority,
481 transform_for_tile_priority,
482 resourceless_software_draw);
483 bool update_lcd_text = false;
484 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
486 gfx::Rect viewport_rect_for_tile_priority_in_view_space =
487 viewport_rect_for_tile_priority;
489 // Verify the viewport rect for tile priority is used in picture layer tiling.
490 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space,
491 active_layer_->viewport_rect_for_tile_priority_in_content_space());
492 PictureLayerTilingSet* tilings = active_layer_->tilings();
493 for (size_t i = 0; i < tilings->num_tilings(); i++) {
494 PictureLayerTiling* tiling = tilings->tiling_at(i);
495 EXPECT_EQ(
496 tiling->GetCurrentVisibleRectForTesting(),
497 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space,
498 tiling->contents_scale()));
501 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in
502 // screen space and the transform for tile priority is translated and
503 // rotated. The actual viewport for tile priority used by PictureLayerImpl
504 // should be (200, 200, 100, 100) applied with the said transform.
505 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
507 viewport_rect_for_tile_priority = gfx::Rect(200, 200, 100, 100);
508 transform_for_tile_priority.Translate(100, 100);
509 transform_for_tile_priority.Rotate(45);
510 host_impl_.SetExternalDrawConstraints(transform,
511 viewport,
512 viewport,
513 viewport_rect_for_tile_priority,
514 transform_for_tile_priority,
515 resourceless_software_draw);
516 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
518 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization);
519 bool success = transform_for_tile_priority.GetInverse(&screen_to_view);
520 EXPECT_TRUE(success);
522 // Note that we don't clip this to the layer bounds, since it is expected that
523 // the rect will sometimes be outside of the layer bounds. If we clip to
524 // bounds, then tile priorities will end up being incorrect in cases of fully
525 // offscreen layer.
526 viewport_rect_for_tile_priority_in_view_space =
527 MathUtil::ProjectEnclosingClippedRect(screen_to_view,
528 viewport_rect_for_tile_priority);
530 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space,
531 active_layer_->viewport_rect_for_tile_priority_in_content_space());
532 tilings = active_layer_->tilings();
533 for (size_t i = 0; i < tilings->num_tilings(); i++) {
534 PictureLayerTiling* tiling = tilings->tiling_at(i);
535 EXPECT_EQ(
536 tiling->GetCurrentVisibleRectForTesting(),
537 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space,
538 tiling->contents_scale()));
542 TEST_F(PictureLayerImplTest, InvalidViewportForPrioritizingTiles) {
543 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
545 gfx::Size tile_size(100, 100);
546 gfx::Size layer_bounds(400, 400);
548 scoped_refptr<FakePicturePileImpl> pending_pile =
549 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
550 scoped_refptr<FakePicturePileImpl> active_pile =
551 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
553 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
555 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
556 false);
558 // UpdateTiles with valid viewport. Should update tile viewport.
559 // Note viewport is considered invalid if and only if in resourceless
560 // software draw.
561 bool resourceless_software_draw = false;
562 gfx::Rect viewport = gfx::Rect(layer_bounds);
563 gfx::Transform transform;
564 host_impl_.SetExternalDrawConstraints(transform,
565 viewport,
566 viewport,
567 viewport,
568 transform,
569 resourceless_software_draw);
570 active_layer_->draw_properties().visible_layer_rect = viewport;
571 active_layer_->draw_properties().screen_space_transform = transform;
572 active_layer_->UpdateTiles(resourceless_software_draw);
574 gfx::Rect visible_rect_for_tile_priority =
575 active_layer_->visible_rect_for_tile_priority();
576 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty());
577 gfx::Transform screen_space_transform_for_tile_priority =
578 active_layer_->screen_space_transform();
580 // Expand viewport and set it as invalid for prioritizing tiles.
581 // Should update viewport and transform, but not update visible rect.
582 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
583 resourceless_software_draw = true;
584 viewport = gfx::ScaleToEnclosingRect(viewport, 2);
585 transform.Translate(1.f, 1.f);
586 active_layer_->draw_properties().visible_layer_rect = viewport;
587 active_layer_->draw_properties().screen_space_transform = transform;
588 host_impl_.SetExternalDrawConstraints(transform,
589 viewport,
590 viewport,
591 viewport,
592 transform,
593 resourceless_software_draw);
594 active_layer_->UpdateTiles(resourceless_software_draw);
596 // Transform for tile priority is updated.
597 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
598 active_layer_->screen_space_transform());
599 // Visible rect for tile priority retains old value.
600 EXPECT_EQ(visible_rect_for_tile_priority,
601 active_layer_->visible_rect_for_tile_priority());
603 // Keep expanded viewport but mark it valid. Should update tile viewport.
604 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
605 resourceless_software_draw = false;
606 host_impl_.SetExternalDrawConstraints(transform,
607 viewport,
608 viewport,
609 viewport,
610 transform,
611 resourceless_software_draw);
612 active_layer_->UpdateTiles(resourceless_software_draw);
614 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
615 active_layer_->screen_space_transform());
616 EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority());
619 TEST_F(PictureLayerImplTest, ViewportRectForTilePriorityIsCached) {
620 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
621 gfx::Size tile_size(100, 100);
622 gfx::Size layer_bounds(400, 400);
624 scoped_refptr<FakePicturePileImpl> pending_pile =
625 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
626 scoped_refptr<FakePicturePileImpl> active_pile =
627 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
629 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
631 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
632 false);
634 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
636 bool resourceless_software_draw = false;
637 gfx::Rect viewport = gfx::Rect(layer_bounds);
638 gfx::Rect viewport_rect_for_tile_priority(0, 0, 100, 100);
639 gfx::Transform transform, transform_for_tile_priority;
641 host_impl_.SetExternalDrawConstraints(
642 transform, viewport, viewport, viewport_rect_for_tile_priority,
643 transform_for_tile_priority, resourceless_software_draw);
644 bool update_lcd_text = false;
645 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
647 EXPECT_EQ(viewport_rect_for_tile_priority,
648 active_layer_->viewport_rect_for_tile_priority_in_content_space());
650 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
652 gfx::Rect another_viewport_rect_for_tile_priority(11, 11, 50, 50);
653 host_impl_.SetExternalDrawConstraints(
654 transform, viewport, viewport, another_viewport_rect_for_tile_priority,
655 transform_for_tile_priority, resourceless_software_draw);
657 // Didn't call UpdateDrawProperties yet. The viewport rect for tile priority
658 // should remain to be the previously cached value.
659 EXPECT_EQ(viewport_rect_for_tile_priority,
660 active_layer_->viewport_rect_for_tile_priority_in_content_space());
661 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
663 // Now the UpdateDrawProperties is called. The viewport rect for tile
664 // priority should be the latest value.
665 EXPECT_EQ(another_viewport_rect_for_tile_priority,
666 active_layer_->viewport_rect_for_tile_priority_in_content_space());
669 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) {
670 gfx::Size tile_size(100, 100);
671 gfx::Size layer_bounds(400, 400);
672 gfx::Rect layer_invalidation(150, 200, 30, 180);
674 scoped_refptr<FakePicturePileImpl> pending_pile =
675 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
676 scoped_refptr<FakePicturePileImpl> active_pile =
677 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
678 scoped_refptr<FakePicturePileImpl> lost_pile =
679 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
681 SetupPendingTreeWithFixedTileSize(lost_pile, gfx::Size(50, 50), Region());
682 ActivateTree();
683 // Add a unique tiling on the active tree.
684 PictureLayerTiling* tiling = active_layer_->AddTiling(3.f);
685 tiling->set_resolution(HIGH_RESOLUTION);
686 tiling->CreateAllTilesForTesting();
688 // Ensure UpdateTiles won't remove any tilings.
689 active_layer_->MarkAllTilingsUsed();
691 // Then setup a new pending tree and activate it.
692 SetupTreesWithFixedTileSize(pending_pile, active_pile, gfx::Size(50, 50),
693 layer_invalidation);
695 EXPECT_EQ(1u, pending_layer_->num_tilings());
696 EXPECT_EQ(3u, active_layer_->num_tilings());
698 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
699 EXPECT_GT(tilings->num_tilings(), 0u);
700 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
701 const PictureLayerTiling* tiling = tilings->tiling_at(i);
702 gfx::Rect content_invalidation = gfx::ScaleToEnclosingRect(
703 layer_invalidation,
704 tiling->contents_scale());
705 auto prioritized_tiles =
706 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
707 for (PictureLayerTiling::CoverageIterator iter(
708 tiling,
709 tiling->contents_scale(),
710 gfx::Rect(tiling->tiling_size()));
711 iter;
712 ++iter) {
713 // We don't always have a tile, but when we do it's because it was
714 // invalidated and it has the latest raster source.
715 if (*iter) {
716 EXPECT_FALSE(iter.geometry_rect().IsEmpty());
717 EXPECT_EQ(pending_pile.get(), prioritized_tiles[*iter].raster_source());
718 EXPECT_TRUE(iter.geometry_rect().Intersects(content_invalidation));
719 } else {
720 // We don't create tiles in non-invalidated regions.
721 EXPECT_FALSE(iter.geometry_rect().Intersects(content_invalidation));
726 tilings = active_layer_->tilings();
727 EXPECT_GT(tilings->num_tilings(), 0u);
728 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
729 const PictureLayerTiling* tiling = tilings->tiling_at(i);
730 gfx::Rect content_invalidation =
731 gfx::ScaleToEnclosingRect(layer_invalidation, tiling->contents_scale());
732 auto prioritized_tiles =
733 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
734 for (PictureLayerTiling::CoverageIterator iter(
735 tiling,
736 tiling->contents_scale(),
737 gfx::Rect(tiling->tiling_size()));
738 iter;
739 ++iter) {
740 EXPECT_TRUE(*iter);
741 EXPECT_FALSE(iter.geometry_rect().IsEmpty());
742 // Pile will be updated upon activation.
743 EXPECT_EQ(active_pile.get(), prioritized_tiles[*iter].raster_source());
748 TEST_F(PictureLayerImplTest, CloneFullInvalidation) {
749 gfx::Size tile_size(90, 80);
750 gfx::Size layer_bounds(300, 500);
752 scoped_refptr<FakePicturePileImpl> pending_pile =
753 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
754 scoped_refptr<FakePicturePileImpl> active_pile =
755 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
757 SetupTreesWithInvalidation(pending_pile, active_pile,
758 gfx::Rect(layer_bounds));
760 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
761 active_layer_->tilings()->num_tilings());
763 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
764 EXPECT_GT(tilings->num_tilings(), 0u);
765 for (size_t i = 0; i < tilings->num_tilings(); ++i)
766 VerifyAllPrioritizedTilesExistAndHavePile(tilings->tiling_at(i),
767 pending_pile.get());
770 TEST_F(PictureLayerImplTest, UpdateTilesCreatesTilings) {
771 gfx::Size tile_size(400, 400);
772 gfx::Size layer_bounds(1300, 1900);
774 scoped_refptr<FakePicturePileImpl> pending_pile =
775 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
776 scoped_refptr<FakePicturePileImpl> active_pile =
777 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
779 SetupTrees(pending_pile, active_pile);
781 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
782 EXPECT_LT(low_res_factor, 1.f);
784 active_layer_->ReleaseResources();
785 EXPECT_FALSE(active_layer_->tilings());
786 active_layer_->RecreateResources();
787 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
789 SetupDrawPropertiesAndUpdateTiles(active_layer_,
790 6.f, // ideal contents scale
791 3.f, // device scale
792 2.f, // page scale
793 1.f, // maximum animation scale
794 0.f, // starting animation scale
795 false);
796 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
797 EXPECT_FLOAT_EQ(6.f,
798 active_layer_->tilings()->tiling_at(0)->contents_scale());
799 EXPECT_FLOAT_EQ(6.f * low_res_factor,
800 active_layer_->tilings()->tiling_at(1)->contents_scale());
802 // If we change the page scale factor, then we should get new tilings.
803 SetupDrawPropertiesAndUpdateTiles(active_layer_,
804 6.6f, // ideal contents scale
805 3.f, // device scale
806 2.2f, // page scale
807 1.f, // maximum animation scale
808 0.f, // starting animation scale
809 false);
810 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
811 EXPECT_FLOAT_EQ(6.6f,
812 active_layer_->tilings()->tiling_at(0)->contents_scale());
813 EXPECT_FLOAT_EQ(6.6f * low_res_factor,
814 active_layer_->tilings()->tiling_at(2)->contents_scale());
816 // If we change the device scale factor, then we should get new tilings.
817 SetupDrawPropertiesAndUpdateTiles(active_layer_,
818 7.26f, // ideal contents scale
819 3.3f, // device scale
820 2.2f, // page scale
821 1.f, // maximum animation scale
822 0.f, // starting animation scale
823 false);
824 ASSERT_EQ(6u, active_layer_->tilings()->num_tilings());
825 EXPECT_FLOAT_EQ(7.26f,
826 active_layer_->tilings()->tiling_at(0)->contents_scale());
827 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
828 active_layer_->tilings()->tiling_at(3)->contents_scale());
830 // If we change the device scale factor, but end up at the same total scale
831 // factor somehow, then we don't get new tilings.
832 SetupDrawPropertiesAndUpdateTiles(active_layer_,
833 7.26f, // ideal contents scale
834 2.2f, // device scale
835 3.3f, // page scale
836 1.f, // maximum animation scale
837 0.f, // starting animation scale
838 false);
839 ASSERT_EQ(6u, active_layer_->tilings()->num_tilings());
840 EXPECT_FLOAT_EQ(7.26f,
841 active_layer_->tilings()->tiling_at(0)->contents_scale());
842 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
843 active_layer_->tilings()->tiling_at(3)->contents_scale());
846 TEST_F(PictureLayerImplTest, PendingLayerOnlyHasHighResTiling) {
847 gfx::Size tile_size(400, 400);
848 gfx::Size layer_bounds(1300, 1900);
850 scoped_refptr<FakePicturePileImpl> pending_pile =
851 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
852 scoped_refptr<FakePicturePileImpl> active_pile =
853 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
855 SetupTrees(pending_pile, active_pile);
857 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
858 EXPECT_LT(low_res_factor, 1.f);
860 pending_layer_->ReleaseResources();
861 EXPECT_FALSE(pending_layer_->tilings());
862 pending_layer_->RecreateResources();
863 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
865 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
866 6.f, // ideal contents scale
867 3.f, // device scale
868 2.f, // page scale
869 1.f, // maximum animation scale
870 0.f, // starting animation scale
871 false);
872 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
873 EXPECT_FLOAT_EQ(6.f,
874 pending_layer_->tilings()->tiling_at(0)->contents_scale());
876 // If we change the page scale factor, then we should get new tilings.
877 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
878 6.6f, // ideal contents scale
879 3.f, // device scale
880 2.2f, // page scale
881 1.f, // maximum animation scale
882 0.f, // starting animation scale
883 false);
884 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
885 EXPECT_FLOAT_EQ(6.6f,
886 pending_layer_->tilings()->tiling_at(0)->contents_scale());
888 // If we change the device scale factor, then we should get new tilings.
889 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
890 7.26f, // ideal contents scale
891 3.3f, // device scale
892 2.2f, // page scale
893 1.f, // maximum animation scale
894 0.f, // starting animation scale
895 false);
896 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
897 EXPECT_FLOAT_EQ(7.26f,
898 pending_layer_->tilings()->tiling_at(0)->contents_scale());
900 // If we change the device scale factor, but end up at the same total scale
901 // factor somehow, then we don't get new tilings.
902 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
903 7.26f, // ideal contents scale
904 2.2f, // device scale
905 3.3f, // page scale
906 1.f, // maximum animation scale
907 0.f, // starting animation scale
908 false);
909 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
910 EXPECT_FLOAT_EQ(7.26f,
911 pending_layer_->tilings()->tiling_at(0)->contents_scale());
914 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) {
915 // This test makes sure that if a layer can have tilings, then a commit makes
916 // it not able to have tilings (empty size), and then a future commit that
917 // makes it valid again should be able to create tilings.
918 gfx::Size tile_size(400, 400);
919 gfx::Size layer_bounds(1300, 1900);
921 scoped_refptr<FakePicturePileImpl> empty_pile =
922 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
923 scoped_refptr<FakePicturePileImpl> valid_pile =
924 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
926 SetupPendingTree(valid_pile);
927 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
929 ActivateTree();
930 SetupPendingTree(empty_pile);
931 EXPECT_FALSE(pending_layer_->CanHaveTilings());
932 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
933 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
935 ActivateTree();
936 EXPECT_FALSE(active_layer_->CanHaveTilings());
937 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
939 SetupPendingTree(valid_pile);
940 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
941 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
944 TEST_F(PictureLayerImplTest, LowResTilingStaysOnActiveTree) {
945 gfx::Size tile_size(400, 400);
946 gfx::Size layer_bounds(1300, 1900);
948 scoped_refptr<FakePicturePileImpl> valid_pile =
949 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
950 scoped_refptr<FakePicturePileImpl> other_valid_pile =
951 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
953 SetupPendingTree(valid_pile);
954 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
956 ActivateTree();
957 SetupPendingTree(other_valid_pile);
958 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
959 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
960 auto* low_res_tiling =
961 active_layer_->tilings()->FindTilingWithResolution(LOW_RESOLUTION);
962 EXPECT_TRUE(low_res_tiling);
964 ActivateTree();
965 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
966 auto* other_low_res_tiling =
967 active_layer_->tilings()->FindTilingWithResolution(LOW_RESOLUTION);
968 EXPECT_TRUE(other_low_res_tiling);
969 EXPECT_EQ(low_res_tiling, other_low_res_tiling);
972 TEST_F(PictureLayerImplTest, ZoomOutCrash) {
973 gfx::Size tile_size(400, 400);
974 gfx::Size layer_bounds(1300, 1900);
976 // Set up the high and low res tilings before pinch zoom.
977 scoped_refptr<FakePicturePileImpl> pending_pile =
978 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
979 scoped_refptr<FakePicturePileImpl> active_pile =
980 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
982 SetupTrees(pending_pile, active_pile);
983 ResetTilingsAndRasterScales();
984 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
985 SetContentsScaleOnBothLayers(32.0f, 1.0f, 32.0f, 1.0f, 0.f, false);
986 EXPECT_EQ(32.f, active_layer_->HighResTiling()->contents_scale());
987 host_impl_.PinchGestureBegin();
988 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, 0.f, false);
989 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, 0.f, false);
990 EXPECT_EQ(active_layer_->tilings()->NumHighResTilings(), 1);
993 TEST_F(PictureLayerImplTest, PinchGestureTilings) {
994 gfx::Size tile_size(400, 400);
995 gfx::Size layer_bounds(1300, 1900);
997 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
999 scoped_refptr<FakePicturePileImpl> pending_pile =
1000 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1001 scoped_refptr<FakePicturePileImpl> active_pile =
1002 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1004 // Set up the high and low res tilings before pinch zoom.
1005 SetupTrees(pending_pile, active_pile);
1006 ResetTilingsAndRasterScales();
1008 SetContentsScaleOnBothLayers(2.f, 1.0f, 2.f, 1.0f, 0.f, false);
1009 EXPECT_EQ(active_layer_->num_tilings(), 2u);
1010 EXPECT_EQ(pending_layer_->num_tilings(), 1u);
1011 EXPECT_EQ(active_layer_->tilings()->tiling_at(0)->contents_scale(), 2.f);
1012 EXPECT_EQ(active_layer_->tilings()->tiling_at(1)->contents_scale(),
1013 2.f * low_res_factor);
1014 // One of the tilings has to be a low resolution one.
1015 EXPECT_EQ(LOW_RESOLUTION,
1016 active_layer_->tilings()->tiling_at(1)->resolution());
1018 // Ensure UpdateTiles won't remove any tilings.
1019 active_layer_->MarkAllTilingsUsed();
1021 // Start a pinch gesture.
1022 host_impl_.PinchGestureBegin();
1024 // Zoom out by a small amount. We should create a tiling at half
1025 // the scale (2/kMaxScaleRatioDuringPinch).
1026 SetContentsScaleOnBothLayers(1.8f, 1.0f, 1.8f, 1.0f, 0.f, false);
1027 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
1028 EXPECT_FLOAT_EQ(2.0f,
1029 active_layer_->tilings()->tiling_at(0)->contents_scale());
1030 EXPECT_FLOAT_EQ(1.0f,
1031 active_layer_->tilings()->tiling_at(1)->contents_scale());
1032 EXPECT_FLOAT_EQ(2.0f * low_res_factor,
1033 active_layer_->tilings()->tiling_at(2)->contents_scale());
1034 // Since we're pinching, we shouldn't create a low resolution tiling.
1035 EXPECT_FALSE(
1036 active_layer_->tilings()->FindTilingWithResolution(LOW_RESOLUTION));
1038 // Ensure UpdateTiles won't remove any tilings.
1039 active_layer_->MarkAllTilingsUsed();
1041 // Zoom out further, close to our low-res scale factor. We should
1042 // use that tiling as high-res, and not create a new tiling.
1043 SetContentsScaleOnBothLayers(low_res_factor * 2.1f, 1.0f,
1044 low_res_factor * 2.1f, 1.0f, 0.f, false);
1045 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
1046 EXPECT_FALSE(
1047 active_layer_->tilings()->FindTilingWithResolution(LOW_RESOLUTION));
1049 // Zoom in a lot now. Since we increase by increments of
1050 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0.
1051 SetContentsScaleOnBothLayers(3.8f, 1.0f, 3.8f, 1.f, 0.f, false);
1052 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings());
1053 EXPECT_FLOAT_EQ(4.0f,
1054 active_layer_->tilings()->tiling_at(0)->contents_scale());
1055 // Although one of the tilings matches the low resolution scale, it still
1056 // shouldn't be marked as low resolution since we're pinching.
1057 auto* low_res_tiling =
1058 active_layer_->tilings()->FindTilingWithScale(4.f * low_res_factor);
1059 EXPECT_TRUE(low_res_tiling);
1060 EXPECT_NE(LOW_RESOLUTION, low_res_tiling->resolution());
1062 // Stop a pinch gesture.
1063 host_impl_.PinchGestureEnd();
1065 // Ensure UpdateTiles won't remove any tilings.
1066 active_layer_->MarkAllTilingsUsed();
1068 // After pinch ends, set the scale to what the raster scale was updated to
1069 // (checked above).
1070 SetContentsScaleOnBothLayers(4.0f, 1.0f, 4.0f, 1.f, 0.f, false);
1071 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings());
1072 EXPECT_FLOAT_EQ(4.0f,
1073 active_layer_->tilings()->tiling_at(0)->contents_scale());
1074 // Now that we stopped pinching, the low resolution tiling that existed should
1075 // now be marked as low resolution.
1076 low_res_tiling =
1077 active_layer_->tilings()->FindTilingWithScale(4.f * low_res_factor);
1078 EXPECT_TRUE(low_res_tiling);
1079 EXPECT_EQ(LOW_RESOLUTION, low_res_tiling->resolution());
1082 TEST_F(PictureLayerImplTest, SnappedTilingDuringZoom) {
1083 gfx::Size tile_size(300, 300);
1084 gfx::Size layer_bounds(2600, 3800);
1086 scoped_refptr<FakePicturePileImpl> pending_pile =
1087 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1088 scoped_refptr<FakePicturePileImpl> active_pile =
1089 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1091 SetupTrees(pending_pile, active_pile);
1093 ResetTilingsAndRasterScales();
1094 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1096 // Set up the high and low res tilings before pinch zoom.
1097 SetContentsScaleOnBothLayers(0.24f, 1.0f, 0.24f, 1.0f, 0.f, false);
1098 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
1099 EXPECT_FLOAT_EQ(0.24f,
1100 active_layer_->tilings()->tiling_at(0)->contents_scale());
1101 EXPECT_FLOAT_EQ(0.0625f,
1102 active_layer_->tilings()->tiling_at(1)->contents_scale());
1104 // Ensure UpdateTiles won't remove any tilings.
1105 active_layer_->MarkAllTilingsUsed();
1107 // Start a pinch gesture.
1108 host_impl_.PinchGestureBegin();
1110 // Zoom out by a small amount. We should create a tiling at half
1111 // the scale (1/kMaxScaleRatioDuringPinch).
1112 SetContentsScaleOnBothLayers(0.2f, 1.0f, 0.2f, 1.0f, 0.f, false);
1113 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
1114 EXPECT_FLOAT_EQ(0.24f,
1115 active_layer_->tilings()->tiling_at(0)->contents_scale());
1116 EXPECT_FLOAT_EQ(0.12f,
1117 active_layer_->tilings()->tiling_at(1)->contents_scale());
1118 EXPECT_FLOAT_EQ(0.0625,
1119 active_layer_->tilings()->tiling_at(2)->contents_scale());
1121 // Ensure UpdateTiles won't remove any tilings.
1122 active_layer_->MarkAllTilingsUsed();
1124 // Zoom out further, close to our low-res scale factor. We should
1125 // use that tiling as high-res, and not create a new tiling.
1126 SetContentsScaleOnBothLayers(0.1f, 1.0f, 0.1f, 1.0f, 0.f, false);
1127 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
1129 // Zoom in. 0.25(desired_scale) should be snapped to 0.24 during zoom-in
1130 // because 0.25(desired_scale) is within the ratio(1.2).
1131 SetContentsScaleOnBothLayers(0.25f, 1.0f, 0.25f, 1.0f, 0.f, false);
1132 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
1134 // Zoom in a lot. Since we move in factors of two, we should get a scale that
1135 // is a power of 2 times 0.24.
1136 SetContentsScaleOnBothLayers(1.f, 1.0f, 1.f, 1.0f, 0.f, false);
1137 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings());
1138 EXPECT_FLOAT_EQ(1.92f,
1139 active_layer_->tilings()->tiling_at(0)->contents_scale());
1142 TEST_F(PictureLayerImplTest, CleanUpTilings) {
1143 gfx::Size tile_size(400, 400);
1144 gfx::Size layer_bounds(1300, 1900);
1146 scoped_refptr<FakePicturePileImpl> pending_pile =
1147 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1148 scoped_refptr<FakePicturePileImpl> active_pile =
1149 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1151 std::vector<PictureLayerTiling*> used_tilings;
1153 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1154 EXPECT_LT(low_res_factor, 1.f);
1156 float scale = 1.f;
1157 float page_scale = 1.f;
1159 SetupTrees(pending_pile, active_pile);
1160 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
1161 EXPECT_EQ(1.f, active_layer_->HighResTiling()->contents_scale());
1163 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
1164 // |used_tilings| variable, and it's here only to ensure that active_layer_
1165 // won't remove tilings before the test has a chance to verify behavior.
1166 active_layer_->MarkAllTilingsUsed();
1168 // We only have ideal tilings, so they aren't removed.
1169 used_tilings.clear();
1170 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1171 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
1173 host_impl_.PinchGestureBegin();
1175 // Changing the ideal but not creating new tilings.
1176 scale = 1.5f;
1177 page_scale = 1.5f;
1178 SetContentsScaleOnBothLayers(scale, 1.f, page_scale, 1.f, 0.f, false);
1179 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
1181 // The tilings are still our target scale, so they aren't removed.
1182 used_tilings.clear();
1183 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1184 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
1186 host_impl_.PinchGestureEnd();
1188 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
1189 scale = 1.2f;
1190 page_scale = 1.2f;
1191 SetContentsScaleOnBothLayers(1.2f, 1.f, page_scale, 1.f, 0.f, false);
1192 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
1193 EXPECT_FLOAT_EQ(
1194 1.f,
1195 active_layer_->tilings()->tiling_at(1)->contents_scale());
1196 EXPECT_FLOAT_EQ(
1197 1.f * low_res_factor,
1198 active_layer_->tilings()->tiling_at(3)->contents_scale());
1200 // Ensure UpdateTiles won't remove any tilings.
1201 active_layer_->MarkAllTilingsUsed();
1203 // Mark the non-ideal tilings as used. They won't be removed.
1204 used_tilings.clear();
1205 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
1206 used_tilings.push_back(active_layer_->tilings()->tiling_at(3));
1207 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1208 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
1210 // Now move the ideal scale to 0.5. Our target stays 1.2.
1211 SetContentsScaleOnBothLayers(0.5f, 1.f, page_scale, 1.f, 0.f, false);
1213 // The high resolution tiling is between target and ideal, so is not
1214 // removed. The low res tiling for the old ideal=1.0 scale is removed.
1215 used_tilings.clear();
1216 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1217 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1219 // Now move the ideal scale to 1.0. Our target stays 1.2.
1220 SetContentsScaleOnBothLayers(1.f, 1.f, page_scale, 1.f, 0.f, false);
1222 // All the tilings are between are target and the ideal, so they are not
1223 // removed.
1224 used_tilings.clear();
1225 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1226 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1228 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
1229 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.1f, 1.f, page_scale, 1.f,
1230 0.f, false);
1232 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1233 // in the range [1.0,1.2] and are kept.
1234 used_tilings.clear();
1235 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1236 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1238 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1239 // 1.2 still.
1240 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.1f, 1.f, page_scale, 1.f,
1241 0.f, false);
1243 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1244 // target raster scale. But it is in our used tilings set, so nothing is
1245 // deleted.
1246 used_tilings.clear();
1247 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
1248 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1249 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1251 // If we remove it from our used tilings set, it is outside the range to keep
1252 // so it is deleted.
1253 used_tilings.clear();
1254 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1255 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
1258 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) {
1259 // Make sure this layer covers multiple tiles, since otherwise low
1260 // res won't get created because it is too small.
1261 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1262 // Avoid max untiled layer size heuristics via fixed tile size.
1263 gfx::Size layer_bounds(tile_size.width() + 1, tile_size.height() + 1);
1264 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1266 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1267 float contents_scale = 1.f;
1268 float device_scale = 1.f;
1269 float page_scale = 1.f;
1270 float maximum_animation_scale = 1.f;
1271 float starting_animation_scale = 0.f;
1272 bool animating_transform = true;
1274 ResetTilingsAndRasterScales();
1276 // Animating, so don't create low res even if there isn't one already.
1277 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1278 maximum_animation_scale,
1279 starting_animation_scale, animating_transform);
1280 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1281 EXPECT_BOTH_EQ(num_tilings(), 1u);
1283 // Stop animating, low res gets created.
1284 animating_transform = false;
1285 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1286 maximum_animation_scale,
1287 starting_animation_scale, animating_transform);
1288 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1289 EXPECT_EQ(active_layer_->LowResTiling()->contents_scale(), low_res_factor);
1290 EXPECT_EQ(active_layer_->num_tilings(), 2u);
1291 EXPECT_EQ(pending_layer_->num_tilings(), 1u);
1293 // Ensure UpdateTiles won't remove any tilings.
1294 active_layer_->MarkAllTilingsUsed();
1296 // Page scale animation, new high res, but no low res. We still have
1297 // a tiling at the previous scale, it's just not marked as low res on the
1298 // active layer. The pending layer drops non-ideal tilings.
1299 contents_scale = 2.f;
1300 page_scale = 2.f;
1301 maximum_animation_scale = 2.f;
1302 animating_transform = true;
1303 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1304 maximum_animation_scale,
1305 starting_animation_scale, animating_transform);
1306 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1307 EXPECT_FALSE(active_layer_->LowResTiling());
1308 EXPECT_FALSE(pending_layer_->LowResTiling());
1309 EXPECT_EQ(3u, active_layer_->num_tilings());
1310 EXPECT_EQ(1u, pending_layer_->num_tilings());
1312 // Stop animating, new low res gets created for final page scale.
1313 animating_transform = false;
1314 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1315 maximum_animation_scale,
1316 starting_animation_scale, animating_transform);
1317 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1318 EXPECT_EQ(active_layer_->LowResTiling()->contents_scale(),
1319 2.f * low_res_factor);
1320 EXPECT_EQ(4u, active_layer_->num_tilings());
1321 EXPECT_EQ(1u, pending_layer_->num_tilings());
1324 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) {
1325 gfx::Size layer_bounds(host_impl_.settings().default_tile_size);
1326 gfx::Size tile_size(100, 100);
1328 scoped_refptr<FakePicturePileImpl> pending_pile =
1329 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1330 scoped_refptr<FakePicturePileImpl> active_pile =
1331 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1333 SetupTrees(pending_pile, active_pile);
1335 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1336 float device_scale = 1.f;
1337 float page_scale = 1.f;
1338 float maximum_animation_scale = 1.f;
1339 float starting_animation_scale = 0.f;
1340 bool animating_transform = false;
1342 // Contents exactly fit on one tile at scale 1, no low res.
1343 float contents_scale = 1.f;
1344 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1345 maximum_animation_scale,
1346 starting_animation_scale, animating_transform);
1347 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1348 EXPECT_BOTH_EQ(num_tilings(), 1u);
1350 ResetTilingsAndRasterScales();
1352 // Contents that are smaller than one tile, no low res.
1353 contents_scale = 0.123f;
1354 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1355 maximum_animation_scale,
1356 starting_animation_scale, animating_transform);
1357 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1358 EXPECT_BOTH_EQ(num_tilings(), 1u);
1360 ResetTilingsAndRasterScales();
1362 // Any content bounds that would create more than one tile will
1363 // generate a low res tiling.
1364 contents_scale = 2.5f;
1365 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
1366 maximum_animation_scale,
1367 starting_animation_scale, animating_transform);
1368 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1369 EXPECT_EQ(active_layer_->LowResTiling()->contents_scale(),
1370 contents_scale * low_res_factor);
1371 EXPECT_FALSE(pending_layer_->LowResTiling());
1372 EXPECT_EQ(active_layer_->num_tilings(), 2u);
1373 EXPECT_EQ(pending_layer_->num_tilings(), 1u);
1375 // Mask layers dont create low res since they always fit on one tile.
1376 scoped_ptr<FakePictureLayerImpl> mask =
1377 FakePictureLayerImpl::CreateMaskWithRasterSource(
1378 host_impl_.pending_tree(), 3, pending_pile);
1379 mask->SetBounds(layer_bounds);
1380 mask->SetDrawsContent(true);
1382 SetupDrawPropertiesAndUpdateTiles(
1383 mask.get(), contents_scale, device_scale, page_scale,
1384 maximum_animation_scale, starting_animation_scale, animating_transform);
1385 EXPECT_EQ(mask->HighResTiling()->contents_scale(), contents_scale);
1386 EXPECT_EQ(mask->num_tilings(), 1u);
1389 TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) {
1390 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1392 gfx::Size tile_size(100, 100);
1393 gfx::Size layer_bounds(1000, 1000);
1395 scoped_refptr<FakePicturePileImpl> valid_pile =
1396 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1397 SetupPendingTree(valid_pile);
1399 scoped_ptr<FakePictureLayerImpl> mask_ptr =
1400 FakePictureLayerImpl::CreateMaskWithRasterSource(
1401 host_impl_.pending_tree(), 3, valid_pile);
1402 mask_ptr->SetBounds(layer_bounds);
1403 mask_ptr->SetDrawsContent(true);
1404 pending_layer_->SetMaskLayer(mask_ptr.Pass());
1405 pending_layer_->SetHasRenderSurface(true);
1407 host_impl_.pending_tree()->BuildPropertyTreesForTesting();
1408 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1409 bool update_lcd_text = false;
1410 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1412 FakePictureLayerImpl* pending_mask =
1413 static_cast<FakePictureLayerImpl*>(pending_layer_->mask_layer());
1415 EXPECT_EQ(1.f, pending_mask->HighResTiling()->contents_scale());
1416 EXPECT_EQ(1u, pending_mask->num_tilings());
1418 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1419 pending_mask->HighResTiling()->AllTilesForTesting());
1421 ActivateTree();
1423 FakePictureLayerImpl* active_mask =
1424 static_cast<FakePictureLayerImpl*>(active_layer_->mask_layer());
1426 // Mask layers have a tiling with a single tile in it.
1427 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1428 // The mask resource exists.
1429 ResourceId mask_resource_id;
1430 gfx::Size mask_texture_size;
1431 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1432 EXPECT_NE(0u, mask_resource_id);
1433 EXPECT_EQ(active_mask->bounds(), mask_texture_size);
1435 // Drop resources and recreate them, still the same.
1436 pending_mask->ReleaseResources();
1437 active_mask->ReleaseResources();
1438 pending_mask->RecreateResources();
1439 active_mask->RecreateResources();
1440 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, 0.f,
1441 false);
1442 active_mask->HighResTiling()->CreateAllTilesForTesting();
1443 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1444 EXPECT_NE(0u, mask_resource_id);
1445 EXPECT_EQ(active_mask->bounds(), mask_texture_size);
1447 // Resize larger than the max texture size.
1448 int max_texture_size = host_impl_.GetRendererCapabilities().max_texture_size;
1449 gfx::Size huge_bounds(max_texture_size + 1, 10);
1450 scoped_refptr<FakePicturePileImpl> huge_pile =
1451 FakePicturePileImpl::CreateFilledPile(tile_size, huge_bounds);
1453 SetupPendingTree(huge_pile);
1454 pending_mask->SetBounds(huge_bounds);
1455 pending_mask->SetRasterSourceOnPending(huge_pile, Region());
1457 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1458 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1460 // The mask tiling gets scaled down.
1461 EXPECT_LT(pending_mask->HighResTiling()->contents_scale(), 1.f);
1462 EXPECT_EQ(1u, pending_mask->num_tilings());
1464 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1465 pending_mask->HighResTiling()->AllTilesForTesting());
1467 ActivateTree();
1469 // Mask layers have a tiling with a single tile in it.
1470 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1471 // The mask resource exists.
1472 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1473 EXPECT_NE(0u, mask_resource_id);
1474 gfx::Size expected_size = active_mask->bounds();
1475 expected_size.SetToMin(gfx::Size(max_texture_size, max_texture_size));
1476 EXPECT_EQ(expected_size, mask_texture_size);
1478 // Drop resources and recreate them, still the same.
1479 pending_mask->ReleaseResources();
1480 active_mask->ReleaseResources();
1481 pending_mask->RecreateResources();
1482 active_mask->RecreateResources();
1483 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, 0.f,
1484 false);
1485 active_mask->HighResTiling()->CreateAllTilesForTesting();
1486 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1487 EXPECT_NE(0u, mask_resource_id);
1488 EXPECT_EQ(expected_size, mask_texture_size);
1490 // Do another activate, the same holds.
1491 SetupPendingTree(huge_pile);
1492 ActivateTree();
1493 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1494 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1495 EXPECT_EQ(expected_size, mask_texture_size);
1496 EXPECT_EQ(0u, mask_resource_id);
1498 // Resize even larger, so that the scale would be smaller than the minimum
1499 // contents scale. Then the layer should no longer have any tiling.
1500 float min_contents_scale = host_impl_.settings().minimum_contents_scale;
1501 gfx::Size extra_huge_bounds(max_texture_size / min_contents_scale + 1, 10);
1502 scoped_refptr<FakePicturePileImpl> extra_huge_pile =
1503 FakePicturePileImpl::CreateFilledPile(tile_size, extra_huge_bounds);
1505 SetupPendingTree(extra_huge_pile);
1506 pending_mask->SetBounds(extra_huge_bounds);
1507 pending_mask->SetRasterSourceOnPending(extra_huge_pile, Region());
1509 EXPECT_FALSE(pending_mask->CanHaveTilings());
1511 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1512 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1514 EXPECT_EQ(0u, pending_mask->num_tilings());
1517 TEST_F(PictureLayerImplTest, ScaledMaskLayer) {
1518 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1520 gfx::Size tile_size(100, 100);
1521 gfx::Size layer_bounds(1000, 1000);
1523 host_impl_.SetDeviceScaleFactor(1.3f);
1525 scoped_refptr<FakePicturePileImpl> valid_pile =
1526 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1527 SetupPendingTree(valid_pile);
1529 scoped_ptr<FakePictureLayerImpl> mask_ptr =
1530 FakePictureLayerImpl::CreateMaskWithRasterSource(
1531 host_impl_.pending_tree(), 3, valid_pile);
1532 mask_ptr->SetBounds(layer_bounds);
1533 mask_ptr->SetDrawsContent(true);
1534 pending_layer_->SetMaskLayer(mask_ptr.Pass());
1535 pending_layer_->SetHasRenderSurface(true);
1537 host_impl_.pending_tree()->BuildPropertyTreesForTesting();
1538 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1539 bool update_lcd_text = false;
1540 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1542 FakePictureLayerImpl* pending_mask =
1543 static_cast<FakePictureLayerImpl*>(pending_layer_->mask_layer());
1545 // Masks are scaled, and do not have a low res tiling.
1546 EXPECT_EQ(1.3f, pending_mask->HighResTiling()->contents_scale());
1547 EXPECT_EQ(1u, pending_mask->num_tilings());
1549 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1550 pending_mask->HighResTiling()->AllTilesForTesting());
1552 ActivateTree();
1554 FakePictureLayerImpl* active_mask =
1555 static_cast<FakePictureLayerImpl*>(active_layer_->mask_layer());
1557 // Mask layers have a tiling with a single tile in it.
1558 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1559 // The mask resource exists.
1560 ResourceId mask_resource_id;
1561 gfx::Size mask_texture_size;
1562 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1563 EXPECT_NE(0u, mask_resource_id);
1564 gfx::Size expected_mask_texture_size =
1565 gfx::ToCeiledSize(gfx::ScaleSize(active_mask->bounds(), 1.3f));
1566 EXPECT_EQ(mask_texture_size, expected_mask_texture_size);
1569 TEST_F(PictureLayerImplTest, ReleaseResources) {
1570 gfx::Size tile_size(400, 400);
1571 gfx::Size layer_bounds(1300, 1900);
1573 scoped_refptr<FakePicturePileImpl> pending_pile =
1574 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1575 scoped_refptr<FakePicturePileImpl> active_pile =
1576 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1578 SetupTrees(pending_pile, active_pile);
1579 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
1581 // All tilings should be removed when losing output surface.
1582 active_layer_->ReleaseResources();
1583 EXPECT_FALSE(active_layer_->tilings());
1584 active_layer_->RecreateResources();
1585 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1586 pending_layer_->ReleaseResources();
1587 EXPECT_FALSE(pending_layer_->tilings());
1588 pending_layer_->RecreateResources();
1589 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1591 // This should create new tilings.
1592 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
1593 1.f, // ideal contents scale
1594 1.f, // device scale
1595 1.f, // page scale
1596 1.f, // maximum animation scale
1597 0.f, // starting animation_scale
1598 false);
1599 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
1602 TEST_F(PictureLayerImplTest, ClampTilesToMaxTileSize) {
1603 // The default max tile size is larger than 400x400.
1604 gfx::Size tile_size(400, 400);
1605 gfx::Size layer_bounds(5000, 5000);
1607 scoped_refptr<FakePicturePileImpl> pending_pile =
1608 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1610 SetupPendingTree(pending_pile);
1611 EXPECT_GE(pending_layer_->tilings()->num_tilings(), 1u);
1613 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1615 // The default value.
1616 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1617 host_impl_.settings().default_tile_size.ToString());
1619 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1620 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1621 tile->content_rect().size().ToString());
1623 ResetTilingsAndRasterScales();
1625 // Change the max texture size on the output surface context.
1626 scoped_ptr<TestWebGraphicsContext3D> context =
1627 TestWebGraphicsContext3D::Create();
1628 context->set_max_texture_size(140);
1629 host_impl_.DidLoseOutputSurface();
1630 host_impl_.InitializeRenderer(
1631 FakeOutputSurface::Create3d(context.Pass()).Pass());
1633 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
1634 false);
1635 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
1637 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1639 // Verify the tiles are not larger than the context's max texture size.
1640 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1641 EXPECT_GE(140, tile->content_rect().width());
1642 EXPECT_GE(140, tile->content_rect().height());
1645 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) {
1646 // The default max tile size is larger than 400x400.
1647 gfx::Size tile_size(400, 400);
1648 gfx::Size layer_bounds(500, 500);
1650 scoped_refptr<FakePicturePileImpl> pending_pile =
1651 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1652 scoped_refptr<FakePicturePileImpl> active_pile =
1653 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1655 SetupTrees(pending_pile, active_pile);
1656 EXPECT_GE(active_layer_->tilings()->num_tilings(), 1u);
1658 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1660 // The default value. The layer is smaller than this.
1661 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1662 host_impl_.settings().max_untiled_layer_size.ToString());
1664 // There should be a single tile since the layer is small.
1665 PictureLayerTiling* high_res_tiling = active_layer_->tilings()->tiling_at(0);
1666 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size());
1668 ResetTilingsAndRasterScales();
1670 // Change the max texture size on the output surface context.
1671 scoped_ptr<TestWebGraphicsContext3D> context =
1672 TestWebGraphicsContext3D::Create();
1673 context->set_max_texture_size(140);
1674 host_impl_.DidLoseOutputSurface();
1675 host_impl_.InitializeRenderer(
1676 FakeOutputSurface::Create3d(context.Pass()).Pass());
1678 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
1679 false);
1680 ASSERT_LE(1u, active_layer_->tilings()->num_tilings());
1682 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1684 // There should be more than one tile since the max texture size won't cover
1685 // the layer.
1686 high_res_tiling = active_layer_->tilings()->tiling_at(0);
1687 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size());
1689 // Verify the tiles are not larger than the context's max texture size.
1690 Tile* tile = active_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1691 EXPECT_GE(140, tile->content_rect().width());
1692 EXPECT_GE(140, tile->content_rect().height());
1695 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) {
1696 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1698 gfx::Size tile_size(400, 400);
1699 gfx::Size layer_bounds(1300, 1900);
1700 gfx::Rect layer_rect(layer_bounds);
1702 scoped_refptr<FakePicturePileImpl> pending_pile =
1703 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1704 scoped_refptr<FakePicturePileImpl> active_pile =
1705 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1707 gfx::Rect layer_invalidation(150, 200, 30, 180);
1708 SetupTreesWithInvalidation(pending_pile, active_pile, layer_invalidation);
1710 active_layer_->SetContentsOpaque(true);
1711 active_layer_->draw_properties().visible_layer_rect = gfx::Rect(layer_bounds);
1713 AppendQuadsData data;
1714 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr);
1715 active_layer_->AppendQuads(render_pass.get(), &data);
1716 active_layer_->DidDraw(nullptr);
1718 ASSERT_EQ(1U, render_pass->quad_list.size());
1719 EXPECT_EQ(DrawQuad::PICTURE_CONTENT,
1720 render_pass->quad_list.front()->material);
1721 EXPECT_EQ(render_pass->quad_list.front()->rect, layer_rect);
1722 EXPECT_EQ(render_pass->quad_list.front()->opaque_rect, layer_rect);
1723 EXPECT_EQ(render_pass->quad_list.front()->visible_rect, layer_rect);
1726 TEST_F(PictureLayerImplTest, ResourcelessPartialRecording) {
1727 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1729 gfx::Size tile_size(400, 400);
1730 gfx::Size layer_bounds(700, 650);
1731 gfx::Rect layer_rect(layer_bounds);
1732 host_impl_.SetDeviceScaleFactor(2.f);
1734 gfx::Rect recorded_viewport(20, 30, 40, 50);
1735 bool is_filled = true;
1736 scoped_refptr<FakePicturePileImpl> active_pile =
1737 FakePicturePileImpl::CreatePile(tile_size, layer_bounds,
1738 recorded_viewport, is_filled);
1739 SetupPendingTree(active_pile);
1740 ActivateTree();
1742 active_layer_->SetContentsOpaque(true);
1743 gfx::Rect visible_rect(30, 35, 10, 5);
1744 active_layer_->draw_properties().visible_layer_rect = visible_rect;
1746 AppendQuadsData data;
1747 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr);
1748 active_layer_->AppendQuads(render_pass.get(), &data);
1749 active_layer_->DidDraw(nullptr);
1751 gfx::Rect scaled_visible = gfx::ScaleToEnclosingRect(visible_rect, 2.f);
1752 gfx::Rect scaled_recorded = gfx::ScaleToEnclosingRect(recorded_viewport, 2.f);
1753 gfx::Rect quad_visible = gfx::IntersectRects(scaled_visible, scaled_recorded);
1755 ASSERT_EQ(1U, render_pass->quad_list.size());
1756 EXPECT_EQ(DrawQuad::PICTURE_CONTENT,
1757 render_pass->quad_list.front()->material);
1758 const DrawQuad* quad = render_pass->quad_list.front();
1759 EXPECT_EQ(quad_visible, quad->rect);
1760 EXPECT_EQ(quad_visible, quad->opaque_rect);
1761 EXPECT_EQ(quad_visible, quad->visible_rect);
1764 TEST_F(PictureLayerImplTest, ResourcelessEmptyRecording) {
1765 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1767 gfx::Size tile_size(400, 400);
1768 gfx::Size layer_bounds(700, 650);
1770 scoped_refptr<FakePicturePileImpl> active_pile =
1771 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
1772 SetupPendingTree(active_pile);
1773 ActivateTree();
1775 active_layer_->SetContentsOpaque(true);
1776 active_layer_->draw_properties().visible_layer_rect = gfx::Rect(layer_bounds);
1778 AppendQuadsData data;
1779 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr);
1780 active_layer_->AppendQuads(render_pass.get(), &data);
1781 active_layer_->DidDraw(nullptr);
1783 EXPECT_EQ(0U, render_pass->quad_list.size());
1786 TEST_F(PictureLayerImplTest, SolidColorLayerHasVisibleFullCoverage) {
1787 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1789 gfx::Size tile_size(1000, 1000);
1790 gfx::Size layer_bounds(1500, 1500);
1791 gfx::Rect visible_rect(250, 250, 1000, 1000);
1793 scoped_ptr<FakePicturePile> empty_recording =
1794 FakePicturePile::CreateEmptyPile(tile_size, layer_bounds);
1795 empty_recording->SetIsSolidColor(true);
1797 scoped_refptr<FakePicturePileImpl> pending_pile =
1798 FakePicturePileImpl::CreateFromPile(empty_recording.get(), nullptr);
1799 scoped_refptr<FakePicturePileImpl> active_pile =
1800 FakePicturePileImpl::CreateFromPile(empty_recording.get(), nullptr);
1802 SetupTrees(pending_pile, active_pile);
1804 active_layer_->draw_properties().visible_layer_rect = visible_rect;
1806 AppendQuadsData data;
1807 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1808 active_layer_->AppendQuads(render_pass.get(), &data);
1809 active_layer_->DidDraw(nullptr);
1811 Region remaining = visible_rect;
1812 for (const auto& quad : render_pass->quad_list) {
1813 EXPECT_TRUE(visible_rect.Contains(quad->rect));
1814 EXPECT_TRUE(remaining.Contains(quad->rect));
1815 remaining.Subtract(quad->rect);
1818 EXPECT_TRUE(remaining.IsEmpty());
1821 TEST_F(PictureLayerImplTest, TileScalesWithSolidColorPile) {
1822 gfx::Size layer_bounds(200, 200);
1823 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1824 scoped_refptr<FakePicturePileImpl> pending_pile =
1825 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1826 tile_size, layer_bounds, false);
1827 scoped_refptr<FakePicturePileImpl> active_pile =
1828 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1829 tile_size, layer_bounds, true);
1831 SetupTrees(pending_pile, active_pile);
1832 // Solid color pile should not allow tilings at any scale.
1833 EXPECT_FALSE(active_layer_->CanHaveTilings());
1834 EXPECT_EQ(0.f, active_layer_->ideal_contents_scale());
1836 // Activate non-solid-color pending pile makes active layer can have tilings.
1837 ActivateTree();
1838 EXPECT_TRUE(active_layer_->CanHaveTilings());
1839 EXPECT_GT(active_layer_->ideal_contents_scale(), 0.f);
1842 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredOffscreenTiles) {
1843 gfx::Size tile_size(100, 100);
1844 gfx::Size layer_bounds(200, 200);
1846 gfx::Transform transform;
1847 gfx::Transform transform_for_tile_priority;
1848 bool resourceless_software_draw = false;
1849 gfx::Rect viewport(0, 0, 100, 200);
1850 host_impl_.SetExternalDrawConstraints(transform,
1851 viewport,
1852 viewport,
1853 viewport,
1854 transform,
1855 resourceless_software_draw);
1857 scoped_refptr<FakePicturePileImpl> pending_pile =
1858 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1859 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1861 EXPECT_EQ(1u, pending_layer_->num_tilings());
1862 EXPECT_EQ(viewport, pending_layer_->visible_rect_for_tile_priority());
1864 base::TimeTicks time_ticks;
1865 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1866 pending_layer_->UpdateTiles(resourceless_software_draw);
1868 int num_visible = 0;
1869 int num_offscreen = 0;
1871 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
1872 pending_layer_->picture_layer_tiling_set(), false));
1873 for (; !queue->IsEmpty(); queue->Pop()) {
1874 const PrioritizedTile& prioritized_tile = queue->Top();
1875 DCHECK(prioritized_tile.tile());
1876 if (prioritized_tile.priority().distance_to_visible == 0.f) {
1877 EXPECT_TRUE(prioritized_tile.tile()->required_for_activation());
1878 num_visible++;
1879 } else {
1880 EXPECT_FALSE(prioritized_tile.tile()->required_for_activation());
1881 num_offscreen++;
1885 EXPECT_GT(num_visible, 0);
1886 EXPECT_GT(num_offscreen, 0);
1889 TEST_F(NoLowResPictureLayerImplTest,
1890 TileOutsideOfViewportForTilePriorityNotRequired) {
1891 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1893 gfx::Size tile_size(100, 100);
1894 gfx::Size layer_bounds(400, 400);
1895 gfx::Rect external_viewport_for_tile_priority(400, 200);
1896 gfx::Rect visible_layer_rect(200, 400);
1898 scoped_refptr<FakePicturePileImpl> active_pile =
1899 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1900 scoped_refptr<FakePicturePileImpl> pending_pile =
1901 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1902 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
1904 ASSERT_EQ(1u, pending_layer_->num_tilings());
1905 ASSERT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
1907 // Set external viewport for tile priority.
1908 gfx::Rect viewport = gfx::Rect(layer_bounds);
1909 gfx::Transform transform;
1910 gfx::Transform transform_for_tile_priority;
1911 bool resourceless_software_draw = false;
1912 host_impl_.SetExternalDrawConstraints(transform,
1913 viewport,
1914 viewport,
1915 external_viewport_for_tile_priority,
1916 transform_for_tile_priority,
1917 resourceless_software_draw);
1918 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1919 bool update_lcd_text = false;
1920 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1922 // Set visible content rect that is different from
1923 // external_viewport_for_tile_priority.
1924 pending_layer_->draw_properties().visible_layer_rect = visible_layer_rect;
1925 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
1926 pending_layer_->UpdateTiles(resourceless_software_draw);
1928 // Intersect the two rects. Any tile outside should not be required for
1929 // activation.
1930 gfx::Rect viewport_for_tile_priority =
1931 pending_layer_->viewport_rect_for_tile_priority_in_content_space();
1932 viewport_for_tile_priority.Intersect(pending_layer_->visible_layer_rect());
1934 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
1936 int num_inside = 0;
1937 int num_outside = 0;
1938 for (PictureLayerTiling::CoverageIterator iter(active_layer_->HighResTiling(),
1939 1.f, gfx::Rect(layer_bounds));
1940 iter; ++iter) {
1941 if (!*iter)
1942 continue;
1943 Tile* tile = *iter;
1944 if (viewport_for_tile_priority.Intersects(iter.geometry_rect())) {
1945 num_inside++;
1946 // Mark everything in viewport for tile priority as ready to draw.
1947 TileDrawInfo& draw_info = tile->draw_info();
1948 draw_info.SetSolidColorForTesting(SK_ColorRED);
1949 } else {
1950 num_outside++;
1951 EXPECT_FALSE(tile->required_for_activation());
1955 EXPECT_GT(num_inside, 0);
1956 EXPECT_GT(num_outside, 0);
1958 // Activate and draw active layer.
1959 host_impl_.ActivateSyncTree();
1960 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
1961 active_layer_->draw_properties().visible_layer_rect = visible_layer_rect;
1963 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1964 AppendQuadsData data;
1965 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1966 active_layer_->AppendQuads(render_pass.get(), &data);
1967 active_layer_->DidDraw(nullptr);
1969 // All tiles in activation rect is ready to draw.
1970 EXPECT_EQ(0u, data.num_missing_tiles);
1971 EXPECT_EQ(0u, data.num_incomplete_tiles);
1972 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
1975 TEST_F(PictureLayerImplTest, HighResTileIsComplete) {
1976 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1978 gfx::Size tile_size(100, 100);
1979 gfx::Size layer_bounds(200, 200);
1981 scoped_refptr<FakePicturePileImpl> pending_pile =
1982 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1984 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1985 ActivateTree();
1987 // All high res tiles have resources.
1988 std::vector<Tile*> tiles =
1989 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
1990 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
1992 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1993 AppendQuadsData data;
1994 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1995 active_layer_->AppendQuads(render_pass.get(), &data);
1996 active_layer_->DidDraw(nullptr);
1998 // All high res tiles drew, nothing was incomplete.
1999 EXPECT_EQ(9u, render_pass->quad_list.size());
2000 EXPECT_EQ(0u, data.num_missing_tiles);
2001 EXPECT_EQ(0u, data.num_incomplete_tiles);
2002 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
2005 TEST_F(PictureLayerImplTest, HighResTileIsIncomplete) {
2006 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2008 gfx::Size tile_size(100, 100);
2009 gfx::Size layer_bounds(200, 200);
2011 scoped_refptr<FakePicturePileImpl> pending_pile =
2012 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2013 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
2014 ActivateTree();
2016 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
2017 AppendQuadsData data;
2018 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
2019 active_layer_->AppendQuads(render_pass.get(), &data);
2020 active_layer_->DidDraw(nullptr);
2022 EXPECT_EQ(1u, render_pass->quad_list.size());
2023 EXPECT_EQ(1u, data.num_missing_tiles);
2024 EXPECT_EQ(0u, data.num_incomplete_tiles);
2025 EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads());
2028 TEST_F(PictureLayerImplTest, HighResTileIsIncompleteLowResComplete) {
2029 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2031 gfx::Size tile_size(100, 100);
2032 gfx::Size layer_bounds(200, 200);
2034 scoped_refptr<FakePicturePileImpl> pending_pile =
2035 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2036 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
2037 ActivateTree();
2039 std::vector<Tile*> low_tiles =
2040 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting();
2041 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles);
2043 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
2044 AppendQuadsData data;
2045 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
2046 active_layer_->AppendQuads(render_pass.get(), &data);
2047 active_layer_->DidDraw(nullptr);
2049 EXPECT_EQ(1u, render_pass->quad_list.size());
2050 EXPECT_EQ(0u, data.num_missing_tiles);
2051 EXPECT_EQ(1u, data.num_incomplete_tiles);
2052 EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads());
2055 TEST_F(PictureLayerImplTest, LowResTileIsIncomplete) {
2056 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2058 gfx::Size tile_size(100, 100);
2059 gfx::Size layer_bounds(200, 200);
2061 scoped_refptr<FakePicturePileImpl> pending_pile =
2062 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2063 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
2064 ActivateTree();
2066 // All high res tiles have resources except one.
2067 std::vector<Tile*> high_tiles =
2068 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
2069 high_tiles.erase(high_tiles.begin());
2070 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles);
2072 // All low res tiles have resources.
2073 std::vector<Tile*> low_tiles =
2074 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting();
2075 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles);
2077 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
2078 AppendQuadsData data;
2079 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
2080 active_layer_->AppendQuads(render_pass.get(), &data);
2081 active_layer_->DidDraw(nullptr);
2083 // The missing high res tile was replaced by a low res tile.
2084 EXPECT_EQ(9u, render_pass->quad_list.size());
2085 EXPECT_EQ(0u, data.num_missing_tiles);
2086 EXPECT_EQ(1u, data.num_incomplete_tiles);
2087 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
2090 TEST_F(PictureLayerImplTest,
2091 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal) {
2092 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2094 gfx::Size tile_size(100, 100);
2095 gfx::Size layer_bounds(200, 200);
2096 gfx::Size viewport_size(400, 400);
2098 host_impl_.SetViewportSize(viewport_size);
2099 host_impl_.SetDeviceScaleFactor(2.f);
2101 scoped_refptr<FakePicturePileImpl> pending_pile =
2102 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2103 scoped_refptr<FakePicturePileImpl> active_pile =
2104 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2105 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
2107 // One ideal tile exists, this will get used when drawing.
2108 std::vector<Tile*> ideal_tiles;
2109 EXPECT_EQ(2.f, active_layer_->HighResTiling()->contents_scale());
2110 ideal_tiles.push_back(active_layer_->HighResTiling()->TileAt(0, 0));
2111 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
2112 ideal_tiles);
2114 // Due to layer scale throttling, the raster contents scale is changed to 1,
2115 // while the ideal is still 2.
2116 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
2117 false);
2118 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.f, 1.f, 1.f, 1.f, 0.f,
2119 false);
2121 EXPECT_EQ(1.f, active_layer_->HighResTiling()->contents_scale());
2122 EXPECT_EQ(1.f, active_layer_->raster_contents_scale());
2123 EXPECT_EQ(2.f, active_layer_->ideal_contents_scale());
2125 // Both tilings still exist.
2126 EXPECT_EQ(2.f, active_layer_->tilings()->tiling_at(0)->contents_scale());
2127 EXPECT_EQ(1.f, active_layer_->tilings()->tiling_at(1)->contents_scale());
2129 // All high res tiles have resources.
2130 std::vector<Tile*> high_tiles =
2131 active_layer_->HighResTiling()->AllTilesForTesting();
2132 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles);
2134 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
2135 AppendQuadsData data;
2136 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
2137 active_layer_->AppendQuads(render_pass.get(), &data);
2138 active_layer_->DidDraw(nullptr);
2140 // All high res tiles drew, and the one ideal res tile drew.
2141 ASSERT_GT(render_pass->quad_list.size(), 9u);
2142 EXPECT_EQ(gfx::SizeF(99.f, 99.f),
2143 TileDrawQuad::MaterialCast(render_pass->quad_list.front())
2144 ->tex_coord_rect.size());
2145 EXPECT_EQ(gfx::SizeF(49.5f, 49.5f),
2146 TileDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(1))
2147 ->tex_coord_rect.size());
2149 // Neither the high res nor the ideal tiles were considered as incomplete.
2150 EXPECT_EQ(0u, data.num_missing_tiles);
2151 EXPECT_EQ(0u, data.num_incomplete_tiles);
2152 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
2155 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveAllReady) {
2156 gfx::Size layer_bounds(400, 400);
2157 gfx::Size tile_size(100, 100);
2159 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size,
2160 gfx::Rect(layer_bounds));
2162 active_layer_->SetAllTilesReady();
2164 // All active tiles ready, so pending can only activate with all high res
2165 // tiles.
2166 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2167 EXPECT_FALSE(pending_layer_->LowResTiling());
2169 AssertAllTilesRequired(pending_layer_->HighResTiling());
2172 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) {
2173 gfx::Size layer_bounds(400, 400);
2174 gfx::Size tile_size(100, 100);
2176 // No invalidation.
2177 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
2179 // Verify active tree not ready.
2180 Tile* some_active_tile =
2181 active_layer_->HighResTiling()->AllTilesForTesting()[0];
2182 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw());
2184 // When high res are required, all tiles in active high res tiling should be
2185 // required for activation.
2186 host_impl_.SetRequiresHighResToDraw();
2188 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2189 EXPECT_FALSE(pending_layer_->LowResTiling());
2190 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2191 active_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
2193 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
2194 AssertAllTilesRequired(active_layer_->HighResTiling());
2195 AssertNoTilesRequired(active_layer_->LowResTiling());
2198 TEST_F(PictureLayerImplTest, AllHighResRequiredEvenIfNotChanged) {
2199 gfx::Size layer_bounds(400, 400);
2200 gfx::Size tile_size(100, 100);
2202 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
2204 Tile* some_active_tile =
2205 active_layer_->HighResTiling()->AllTilesForTesting()[0];
2206 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw());
2208 // Since there are no invalidations, pending tree should have no tiles.
2209 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
2210 EXPECT_FALSE(pending_layer_->LowResTiling());
2212 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2213 active_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
2215 AssertAllTilesRequired(active_layer_->HighResTiling());
2216 AssertNoTilesRequired(active_layer_->LowResTiling());
2219 TEST_F(PictureLayerImplTest, DisallowRequiredForActivation) {
2220 gfx::Size layer_bounds(400, 400);
2221 gfx::Size tile_size(100, 100);
2223 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
2225 Tile* some_active_tile =
2226 active_layer_->HighResTiling()->AllTilesForTesting()[0];
2227 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw());
2229 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
2230 EXPECT_FALSE(pending_layer_->LowResTiling());
2231 active_layer_->HighResTiling()->set_can_require_tiles_for_activation(false);
2232 active_layer_->LowResTiling()->set_can_require_tiles_for_activation(false);
2233 pending_layer_->HighResTiling()->set_can_require_tiles_for_activation(false);
2235 // If we disallow required for activation, no tiles can be required.
2236 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2237 active_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
2239 AssertNoTilesRequired(active_layer_->HighResTiling());
2240 AssertNoTilesRequired(active_layer_->LowResTiling());
2243 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) {
2244 gfx::Size layer_bounds(400, 400);
2245 gfx::Size tile_size(100, 100);
2247 scoped_refptr<FakePicturePileImpl> pending_pile =
2248 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2249 // This pile will create tilings, but has no recordings so will not create any
2250 // tiles. This is attempting to simulate scrolling past the end of recorded
2251 // content on the active layer, where the recordings are so far away that
2252 // no tiles are created.
2253 bool is_solid_color = false;
2254 scoped_refptr<FakePicturePileImpl> active_pile =
2255 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
2256 tile_size, layer_bounds, is_solid_color);
2258 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
2260 // Active layer has tilings, but no tiles due to missing recordings.
2261 EXPECT_TRUE(active_layer_->CanHaveTilings());
2262 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u);
2263 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u);
2265 // Since the active layer has no tiles at all, the pending layer doesn't
2266 // need content in order to activate.
2267 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2268 EXPECT_FALSE(pending_layer_->LowResTiling());
2270 AssertNoTilesRequired(pending_layer_->HighResTiling());
2273 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) {
2274 gfx::Size layer_bounds(400, 400);
2275 gfx::Size tile_size(100, 100);
2277 scoped_refptr<FakePicturePileImpl> pending_pile =
2278 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2279 scoped_refptr<FakePicturePileImpl> active_pile =
2280 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
2281 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
2283 // Active layer can't have tiles.
2284 EXPECT_FALSE(active_layer_->CanHaveTilings());
2286 // All high res tiles required. This should be considered identical
2287 // to the case where there is no active layer, to avoid flashing content.
2288 // This can happen if a layer exists for a while and switches from
2289 // not being able to have content to having content.
2290 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2291 EXPECT_FALSE(pending_layer_->LowResTiling());
2293 AssertAllTilesRequired(pending_layer_->HighResTiling());
2296 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveHasDifferentBounds) {
2297 gfx::Size pending_layer_bounds(400, 400);
2298 gfx::Size active_layer_bounds(200, 200);
2299 gfx::Size tile_size(100, 100);
2301 scoped_refptr<FakePicturePileImpl> pending_pile =
2302 FakePicturePileImpl::CreateFilledPile(tile_size, pending_layer_bounds);
2303 scoped_refptr<FakePicturePileImpl> active_pile =
2304 FakePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds);
2306 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
2308 // Since the active layer has different bounds, the pending layer needs all
2309 // high res tiles in order to activate.
2310 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2311 EXPECT_FALSE(pending_layer_->LowResTiling());
2312 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2313 active_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
2315 AssertAllTilesRequired(pending_layer_->HighResTiling());
2316 AssertAllTilesRequired(active_layer_->HighResTiling());
2317 AssertNoTilesRequired(active_layer_->LowResTiling());
2320 TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) {
2321 gfx::Size tile_size(100, 100);
2322 gfx::Size layer_bounds(400, 400);
2323 scoped_refptr<FakePicturePileImpl> pending_pile =
2324 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2326 host_impl_.CreatePendingTree();
2327 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
2329 scoped_ptr<FakePictureLayerImpl> pending_layer =
2330 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, id_,
2331 pending_pile);
2332 pending_layer->SetDrawsContent(true);
2333 pending_tree->SetRootLayer(pending_layer.Pass());
2335 pending_layer_ = static_cast<FakePictureLayerImpl*>(
2336 host_impl_.pending_tree()->LayerById(id_));
2338 // Set some state on the pending layer, make sure it is not clobbered
2339 // by a sync from the active layer. This could happen because if the
2340 // pending layer has not been post-commit initialized it will attempt
2341 // to sync from the active layer.
2342 float raster_page_scale = 10.f * pending_layer_->raster_page_scale();
2343 pending_layer_->set_raster_page_scale(raster_page_scale);
2345 host_impl_.ActivateSyncTree();
2347 active_layer_ = static_cast<FakePictureLayerImpl*>(
2348 host_impl_.active_tree()->LayerById(id_));
2350 EXPECT_EQ(0u, active_layer_->num_tilings());
2351 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale());
2354 TEST_F(PictureLayerImplTest, ShareTilesOnNextFrame) {
2355 gfx::Size layer_bounds(1500, 1500);
2356 gfx::Size tile_size(100, 100);
2358 scoped_refptr<FakePicturePileImpl> pending_pile =
2359 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2361 SetupPendingTree(pending_pile);
2363 PictureLayerTiling* tiling = pending_layer_->HighResTiling();
2364 gfx::Rect first_invalidate = tiling->TilingDataForTesting().TileBounds(0, 0);
2365 first_invalidate.Inset(tiling->TilingDataForTesting().border_texels(),
2366 tiling->TilingDataForTesting().border_texels());
2367 gfx::Rect second_invalidate = tiling->TilingDataForTesting().TileBounds(1, 1);
2368 second_invalidate.Inset(tiling->TilingDataForTesting().border_texels(),
2369 tiling->TilingDataForTesting().border_texels());
2371 ActivateTree();
2373 // Make a pending tree with an invalidated raster tile 0,0.
2374 SetupPendingTreeWithInvalidation(pending_pile, first_invalidate);
2376 // Activate and make a pending tree with an invalidated raster tile 1,1.
2377 ActivateTree();
2379 SetupPendingTreeWithInvalidation(pending_pile, second_invalidate);
2381 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2382 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2384 // pending_tiling->CreateAllTilesForTesting();
2386 // Tile 0,0 not exist on pending, but tile 1,1 should.
2387 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2388 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2389 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2390 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2391 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2392 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2393 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2394 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2395 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
2397 // Drop the tiles on the active tree and recreate them.
2398 active_tiling->ComputeTilePriorityRects(gfx::Rect(), 1.f, 1.0, Occlusion());
2399 EXPECT_TRUE(active_tiling->AllTilesForTesting().empty());
2400 active_tiling->CreateAllTilesForTesting();
2402 // Tile 0,0 not exist on pending, but tile 1,1 should.
2403 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2404 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2405 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2406 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2407 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2408 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2409 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2410 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2411 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
2414 TEST_F(PictureLayerImplTest, PendingHasNoTilesWithNoInvalidation) {
2415 SetupDefaultTrees(gfx::Size(1500, 1500));
2417 EXPECT_GE(active_layer_->num_tilings(), 1u);
2418 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2420 // No invalidation.
2421 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2422 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2423 ASSERT_TRUE(active_tiling);
2424 ASSERT_TRUE(pending_tiling);
2426 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2427 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2428 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2429 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2431 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2432 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2433 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2434 EXPECT_FALSE(pending_tiling->TileAt(1, 1));
2437 TEST_F(PictureLayerImplTest, ShareInvalidActiveTreeTiles) {
2438 gfx::Size tile_size(100, 100);
2439 gfx::Size layer_bounds(1500, 1500);
2441 scoped_refptr<FakePicturePileImpl> pending_pile =
2442 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2443 scoped_refptr<FakePicturePileImpl> active_pile =
2444 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2445 SetupTreesWithInvalidation(pending_pile, active_pile, gfx::Rect(1, 1));
2446 // Activate the invalidation.
2447 ActivateTree();
2448 // Make another pending tree without any invalidation in it.
2449 scoped_refptr<FakePicturePileImpl> pending_pile2 =
2450 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2451 SetupPendingTree(pending_pile2);
2453 EXPECT_GE(active_layer_->num_tilings(), 1u);
2454 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2456 // The active tree invalidation was handled by the active tiles.
2457 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2458 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2459 ASSERT_TRUE(active_tiling);
2460 ASSERT_TRUE(pending_tiling);
2462 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2463 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2464 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2465 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2467 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2468 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2469 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2470 EXPECT_FALSE(pending_tiling->TileAt(1, 1));
2473 TEST_F(PictureLayerImplTest, RecreateInvalidPendingTreeTiles) {
2474 // Set some invalidation on the pending tree. We should replace raster tiles
2475 // that touch this.
2476 SetupDefaultTreesWithInvalidation(gfx::Size(1500, 1500), gfx::Rect(1, 1));
2478 EXPECT_GE(active_layer_->num_tilings(), 1u);
2479 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2481 // The pending tree invalidation creates tiles on the pending tree.
2482 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2483 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2484 ASSERT_TRUE(active_tiling);
2485 ASSERT_TRUE(pending_tiling);
2487 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2488 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2489 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2490 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2492 EXPECT_TRUE(pending_tiling->TileAt(0, 0));
2493 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2494 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2495 EXPECT_FALSE(pending_tiling->TileAt(1, 1));
2497 EXPECT_NE(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2500 TEST_F(PictureLayerImplTest, SyncTilingAfterGpuRasterizationToggles) {
2501 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2503 gfx::Size tile_size(100, 100);
2504 gfx::Size layer_bounds(10, 10);
2506 scoped_refptr<FakePicturePileImpl> pending_pile =
2507 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2508 scoped_refptr<FakePicturePileImpl> active_pile =
2509 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2511 SetupTrees(pending_pile, active_pile);
2513 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2514 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f));
2516 // Gpu rasterization is disabled by default.
2517 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
2518 // Toggling the gpu rasterization clears all tilings on both trees.
2519 host_impl_.SetHasGpuRasterizationTrigger(true);
2520 host_impl_.SetContentIsSuitableForGpuRasterization(true);
2521 host_impl_.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2522 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2523 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2525 // Make sure that we can still add tiling to the pending layer,
2526 // that gets synced to the active layer.
2527 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2528 bool update_lcd_text = false;
2529 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
2530 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2532 ActivateTree();
2533 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f));
2535 SetupPendingTree(pending_pile);
2536 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2538 // Toggling the gpu rasterization clears all tilings on both trees.
2539 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2540 host_impl_.SetHasGpuRasterizationTrigger(false);
2541 host_impl_.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2542 EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT,
2543 host_impl_.gpu_rasterization_status());
2544 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2545 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2547 host_impl_.SetHasGpuRasterizationTrigger(true);
2548 host_impl_.SetContentIsSuitableForGpuRasterization(false);
2549 EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT,
2550 host_impl_.gpu_rasterization_status());
2553 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) {
2554 gfx::Size tile_size(100, 100);
2556 // Put 0.5 as high res.
2557 host_impl_.SetDeviceScaleFactor(0.5f);
2559 scoped_refptr<FakePicturePileImpl> pending_pile =
2560 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(10, 10));
2561 SetupPendingTree(pending_pile);
2563 // Sanity checks.
2564 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2565 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(0.5f));
2567 ActivateTree();
2569 // Now, set the bounds to be 1x1, so that minimum contents scale becomes 1.
2570 pending_pile =
2571 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1, 1));
2572 SetupPendingTree(pending_pile);
2574 // Another sanity check.
2575 EXPECT_EQ(1.f, pending_layer_->MinimumContentsScale());
2577 // Since the MinContentsScale is 1, the 0.5 tiling should have been replaced
2578 // by a 1.0 tiling during the UDP in SetupPendingTree.
2579 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2580 PictureLayerTiling* tiling =
2581 pending_layer_->tilings()->FindTilingWithScale(1.0f);
2582 ASSERT_TRUE(tiling);
2583 EXPECT_EQ(HIGH_RESOLUTION, tiling->resolution());
2586 TEST_F(PictureLayerImplTest, LowResTilingWithoutGpuRasterization) {
2587 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
2588 gfx::Size layer_bounds(default_tile_size.width() * 4,
2589 default_tile_size.height() * 4);
2591 host_impl_.SetHasGpuRasterizationTrigger(false);
2593 SetupDefaultTrees(layer_bounds);
2594 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
2595 // Should have only a high-res tiling.
2596 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2597 ActivateTree();
2598 // Should add a high and a low res for active tree.
2599 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
2602 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) {
2603 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
2604 gfx::Size layer_bounds(default_tile_size.width() * 4,
2605 default_tile_size.height() * 4);
2607 host_impl_.SetHasGpuRasterizationTrigger(true);
2608 host_impl_.SetContentIsSuitableForGpuRasterization(true);
2610 SetupDefaultTrees(layer_bounds);
2611 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2612 // Should only have the high-res tiling.
2613 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2614 ActivateTree();
2615 // Should only have the high-res tiling.
2616 EXPECT_EQ(1u, active_layer_->tilings()->num_tilings());
2619 TEST_F(PictureLayerImplTest, RequiredTilesWithGpuRasterization) {
2620 host_impl_.SetHasGpuRasterizationTrigger(true);
2621 host_impl_.SetContentIsSuitableForGpuRasterization(true);
2623 gfx::Size viewport_size(1000, 1000);
2624 host_impl_.SetViewportSize(viewport_size);
2626 gfx::Size layer_bounds(4000, 4000);
2627 SetupDefaultTrees(layer_bounds);
2628 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2630 // Should only have the high-res tiling.
2631 EXPECT_EQ(1u, active_layer_->tilings()->num_tilings());
2633 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
2635 // High res tiling should have 64 tiles (4x16 tile grid).
2636 EXPECT_EQ(64u, active_layer_->HighResTiling()->AllTilesForTesting().size());
2638 // Visible viewport should be covered by 4 tiles. No other
2639 // tiles should be required for activation.
2640 EXPECT_EQ(4u, NumberOfTilesRequired(active_layer_->HighResTiling()));
2643 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) {
2644 // Set up layers with tilings.
2645 SetupDefaultTrees(gfx::Size(10, 10));
2646 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, 0.f, false);
2647 pending_layer_->PushPropertiesTo(active_layer_);
2648 EXPECT_TRUE(pending_layer_->DrawsContent());
2649 EXPECT_TRUE(pending_layer_->CanHaveTilings());
2650 EXPECT_GE(pending_layer_->num_tilings(), 0u);
2651 EXPECT_GE(active_layer_->num_tilings(), 0u);
2653 // Set content to false, which should make CanHaveTilings return false.
2654 pending_layer_->SetDrawsContent(false);
2655 EXPECT_FALSE(pending_layer_->DrawsContent());
2656 EXPECT_FALSE(pending_layer_->CanHaveTilings());
2658 // No tilings should be pushed to active layer.
2659 pending_layer_->PushPropertiesTo(active_layer_);
2660 EXPECT_EQ(0u, active_layer_->num_tilings());
2663 TEST_F(PictureLayerImplTest, FirstTilingDuringPinch) {
2664 SetupDefaultTrees(gfx::Size(10, 10));
2666 // We start with a tiling at scale 1.
2667 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
2669 // When we page scale up by 2.3, we get a new tiling that is a power of 2, in
2670 // this case 4.
2671 host_impl_.PinchGestureBegin();
2672 float high_res_scale = 2.3f;
2673 SetContentsScaleOnBothLayers(high_res_scale, 1.f, high_res_scale, 1.f, 0.f,
2674 false);
2675 EXPECT_EQ(4.f, pending_layer_->HighResTiling()->contents_scale());
2678 TEST_F(PictureLayerImplTest, PinchingTooSmall) {
2679 SetupDefaultTrees(gfx::Size(10, 10));
2681 // We start with a tiling at scale 1.
2682 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
2684 host_impl_.PinchGestureBegin();
2685 float high_res_scale = 0.0001f;
2686 EXPECT_LT(high_res_scale, pending_layer_->MinimumContentsScale());
2688 SetContentsScaleOnBothLayers(high_res_scale, 1.f, high_res_scale, 1.f, 0.f,
2689 false);
2690 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
2691 pending_layer_->HighResTiling()->contents_scale());
2694 TEST_F(PictureLayerImplTest, PinchingTooSmallWithContentsScale) {
2695 SetupDefaultTrees(gfx::Size(10, 10));
2697 ResetTilingsAndRasterScales();
2699 float contents_scale = 0.15f;
2700 SetContentsScaleOnBothLayers(contents_scale, 1.f, 1.f, 1.f, 0.f, false);
2702 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2703 EXPECT_FLOAT_EQ(contents_scale,
2704 pending_layer_->HighResTiling()->contents_scale());
2706 host_impl_.PinchGestureBegin();
2708 float page_scale = 0.0001f;
2709 EXPECT_LT(page_scale * contents_scale,
2710 pending_layer_->MinimumContentsScale());
2712 SetContentsScaleOnBothLayers(contents_scale * page_scale, 1.f, page_scale,
2713 1.f, 0.f, false);
2714 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2715 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
2716 pending_layer_->HighResTiling()->contents_scale());
2719 TEST_F(PictureLayerImplTest, ConsiderAnimationStartScaleForRasterScale) {
2720 gfx::Size viewport_size(1000, 1000);
2721 host_impl_.SetViewportSize(viewport_size);
2723 gfx::Size layer_bounds(100, 100);
2724 SetupDefaultTrees(layer_bounds);
2726 float contents_scale = 2.f;
2727 float device_scale = 1.f;
2728 float page_scale = 1.f;
2729 float maximum_animation_scale = 3.f;
2730 float starting_animation_scale = 1.f;
2731 bool animating_transform = true;
2733 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2735 // Maximum animation scale is greater than starting animation scale
2736 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2737 maximum_animation_scale,
2738 starting_animation_scale, animating_transform);
2739 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2741 animating_transform = false;
2743 // Once we stop animating, a new high-res tiling should be created.
2744 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2745 maximum_animation_scale,
2746 starting_animation_scale, animating_transform);
2747 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
2749 // Starting animation scale greater than maximum animation scale
2750 // Bounds at starting scale within the viewport
2751 animating_transform = true;
2752 starting_animation_scale = 5.f;
2754 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2755 maximum_animation_scale,
2756 starting_animation_scale, animating_transform);
2757 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 5.f);
2759 // Once we stop animating, a new high-res tiling should be created.
2760 animating_transform = false;
2761 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2762 maximum_animation_scale,
2763 starting_animation_scale, animating_transform);
2764 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
2766 // Starting Animation scale greater than maximum animation scale
2767 // Bounds at starting scale outisde the viewport
2768 animating_transform = true;
2769 starting_animation_scale = 11.f;
2771 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2772 maximum_animation_scale,
2773 starting_animation_scale, animating_transform);
2774 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2777 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForCpuRasterization) {
2778 gfx::Size viewport_size(1000, 1000);
2779 host_impl_.SetViewportSize(viewport_size);
2781 gfx::Size layer_bounds(100, 100);
2782 SetupDefaultTrees(layer_bounds);
2784 float contents_scale = 1.f;
2785 float device_scale = 1.f;
2786 float page_scale = 1.f;
2787 float maximum_animation_scale = 1.f;
2788 float starting_animation_scale = 0.f;
2789 bool animating_transform = false;
2791 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2793 // Since we're CPU-rasterizing, starting an animation should cause tiling
2794 // resolution to get set to the maximum animation scale factor.
2795 animating_transform = true;
2796 maximum_animation_scale = 3.f;
2797 contents_scale = 2.f;
2799 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2800 maximum_animation_scale,
2801 starting_animation_scale, animating_transform);
2802 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2803 EXPECT_BOTH_TRUE(GetRasterSource()->ShouldAttemptToUseDistanceFieldText());
2805 // Further changes to scale during the animation should not cause a new
2806 // high-res tiling to get created.
2807 contents_scale = 4.f;
2808 maximum_animation_scale = 5.f;
2810 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2811 maximum_animation_scale,
2812 starting_animation_scale, animating_transform);
2813 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2815 // Once we stop animating, a new high-res tiling should be created.
2816 animating_transform = false;
2818 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2819 maximum_animation_scale,
2820 starting_animation_scale, animating_transform);
2821 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2823 // When animating with an unknown maximum animation scale factor, a new
2824 // high-res tiling should be created at a source scale of 1.
2825 animating_transform = true;
2826 contents_scale = 2.f;
2827 maximum_animation_scale = 0.f;
2829 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2830 maximum_animation_scale,
2831 starting_animation_scale, animating_transform);
2832 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale * device_scale);
2834 // Further changes to scale during the animation should not cause a new
2835 // high-res tiling to get created.
2836 contents_scale = 3.f;
2838 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2839 maximum_animation_scale,
2840 starting_animation_scale, animating_transform);
2841 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale * device_scale);
2843 // Once we stop animating, a new high-res tiling should be created.
2844 animating_transform = false;
2845 contents_scale = 4.f;
2847 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2848 maximum_animation_scale,
2849 starting_animation_scale, animating_transform);
2850 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2852 // When animating with a maxmium animation scale factor that is so large
2853 // that the layer grows larger than the viewport at this scale, a new
2854 // high-res tiling should get created at a source scale of 1, not at its
2855 // maximum scale.
2856 animating_transform = true;
2857 contents_scale = 2.f;
2858 maximum_animation_scale = 11.f;
2860 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2861 maximum_animation_scale,
2862 starting_animation_scale, animating_transform);
2863 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale * device_scale);
2865 // Once we stop animating, a new high-res tiling should be created.
2866 animating_transform = false;
2867 contents_scale = 11.f;
2869 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2870 maximum_animation_scale,
2871 starting_animation_scale, animating_transform);
2872 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f);
2874 // When animating with a maxmium animation scale factor that is so large
2875 // that the layer grows larger than the viewport at this scale, and where
2876 // the intial source scale is < 1, a new high-res tiling should get created
2877 // at source scale 1.
2878 animating_transform = true;
2879 contents_scale = 0.1f;
2880 maximum_animation_scale = 11.f;
2882 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2883 maximum_animation_scale,
2884 starting_animation_scale, animating_transform);
2885 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale * page_scale);
2887 // Once we stop animating, a new high-res tiling should be created.
2888 animating_transform = false;
2889 contents_scale = 12.f;
2891 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2892 maximum_animation_scale,
2893 starting_animation_scale, animating_transform);
2894 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 12.f);
2896 // When animating toward a smaller scale, but that is still so large that the
2897 // layer grows larger than the viewport at this scale, a new high-res tiling
2898 // should get created at source scale 1.
2899 animating_transform = true;
2900 contents_scale = 11.f;
2901 maximum_animation_scale = 11.f;
2903 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2904 maximum_animation_scale,
2905 starting_animation_scale, animating_transform);
2906 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale * page_scale);
2908 // Once we stop animating, a new high-res tiling should be created.
2909 animating_transform = false;
2910 contents_scale = 11.f;
2912 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2913 maximum_animation_scale,
2914 starting_animation_scale, animating_transform);
2915 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f);
2918 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForGpuRasterization) {
2919 gfx::Size layer_bounds(100, 100);
2920 gfx::Size viewport_size(1000, 1000);
2921 SetupDefaultTrees(layer_bounds);
2922 host_impl_.SetViewportSize(viewport_size);
2923 host_impl_.SetHasGpuRasterizationTrigger(true);
2924 host_impl_.SetContentIsSuitableForGpuRasterization(true);
2925 host_impl_.UpdateTreeResourcesForGpuRasterizationIfNeeded();
2927 float contents_scale = 1.f;
2928 float device_scale = 1.3f;
2929 float page_scale = 1.4f;
2930 float maximum_animation_scale = 1.f;
2931 float starting_animation_scale = 0.f;
2932 bool animating_transform = false;
2934 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2935 maximum_animation_scale,
2936 starting_animation_scale, animating_transform);
2937 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2938 EXPECT_BOTH_FALSE(GetRasterSource()->ShouldAttemptToUseDistanceFieldText());
2940 // Since we're GPU-rasterizing, starting an animation should cause tiling
2941 // resolution to get set to the current contents scale.
2942 animating_transform = true;
2943 contents_scale = 2.f;
2944 maximum_animation_scale = 4.f;
2946 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2947 maximum_animation_scale,
2948 starting_animation_scale, animating_transform);
2949 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
2950 EXPECT_BOTH_TRUE(GetRasterSource()->ShouldAttemptToUseDistanceFieldText());
2952 // Further changes to scale during the animation should cause a new high-res
2953 // tiling to get created.
2954 contents_scale = 3.f;
2956 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2957 maximum_animation_scale,
2958 starting_animation_scale, animating_transform);
2959 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2961 // Since we're re-rasterizing during the animation, scales smaller than 1
2962 // should be respected.
2963 contents_scale = 0.25f;
2965 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2966 maximum_animation_scale,
2967 starting_animation_scale, animating_transform);
2968 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.25f);
2970 // Once we stop animating, a new high-res tiling should be created.
2971 contents_scale = 4.f;
2972 animating_transform = false;
2974 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
2975 maximum_animation_scale,
2976 starting_animation_scale, animating_transform);
2977 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2980 TEST_F(PictureLayerImplTest, TilingSetRasterQueue) {
2981 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
2983 host_impl_.SetViewportSize(gfx::Size(500, 500));
2985 gfx::Size recording_tile_size(100, 100);
2986 gfx::Size layer_bounds(1000, 1000);
2988 scoped_refptr<FakePicturePileImpl> pending_pile =
2989 FakePicturePileImpl::CreateFilledPile(recording_tile_size, layer_bounds);
2991 SetupPendingTree(pending_pile);
2992 EXPECT_EQ(1u, pending_layer_->num_tilings());
2994 std::set<Tile*> unique_tiles;
2995 bool reached_prepaint = false;
2996 int non_ideal_tile_count = 0u;
2997 int low_res_tile_count = 0u;
2998 int high_res_tile_count = 0u;
2999 int high_res_now_tiles = 0u;
3000 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
3001 pending_layer_->picture_layer_tiling_set(), false));
3002 while (!queue->IsEmpty()) {
3003 PrioritizedTile prioritized_tile = queue->Top();
3004 TilePriority priority = prioritized_tile.priority();
3006 EXPECT_TRUE(prioritized_tile.tile());
3008 // Non-high res tiles only get visible tiles. Also, prepaint should only
3009 // come at the end of the iteration.
3010 if (priority.resolution != HIGH_RESOLUTION) {
3011 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
3012 } else if (reached_prepaint) {
3013 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
3014 } else {
3015 reached_prepaint = priority.priority_bin != TilePriority::NOW;
3016 if (!reached_prepaint)
3017 ++high_res_now_tiles;
3020 non_ideal_tile_count += priority.resolution == NON_IDEAL_RESOLUTION;
3021 low_res_tile_count += priority.resolution == LOW_RESOLUTION;
3022 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
3024 unique_tiles.insert(prioritized_tile.tile());
3025 queue->Pop();
3028 EXPECT_TRUE(reached_prepaint);
3029 EXPECT_EQ(0, non_ideal_tile_count);
3030 EXPECT_EQ(0, low_res_tile_count);
3032 // With layer size being 1000x1000 and default tile size 256x256, we expect to
3033 // see 4 now tiles out of 16 total high res tiles.
3034 EXPECT_EQ(16, high_res_tile_count);
3035 EXPECT_EQ(4, high_res_now_tiles);
3036 EXPECT_EQ(low_res_tile_count + high_res_tile_count + non_ideal_tile_count,
3037 static_cast<int>(unique_tiles.size()));
3039 scoped_ptr<TilingSetRasterQueueRequired> required_queue(
3040 new TilingSetRasterQueueRequired(
3041 pending_layer_->picture_layer_tiling_set(),
3042 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW));
3043 EXPECT_TRUE(required_queue->IsEmpty());
3045 required_queue.reset(new TilingSetRasterQueueRequired(
3046 pending_layer_->picture_layer_tiling_set(),
3047 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION));
3048 EXPECT_FALSE(required_queue->IsEmpty());
3049 int required_for_activation_count = 0;
3050 while (!required_queue->IsEmpty()) {
3051 PrioritizedTile prioritized_tile = required_queue->Top();
3052 EXPECT_TRUE(prioritized_tile.tile()->required_for_activation());
3053 EXPECT_FALSE(prioritized_tile.tile()->draw_info().IsReadyToDraw());
3054 ++required_for_activation_count;
3055 required_queue->Pop();
3058 // All of the high res tiles should be required for activation, since there is
3059 // no active twin.
3060 EXPECT_EQ(high_res_now_tiles, required_for_activation_count);
3062 // No NOW tiles.
3063 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3065 pending_layer_->draw_properties().visible_layer_rect =
3066 gfx::Rect(1100, 1100, 500, 500);
3067 bool resourceless_software_draw = false;
3068 pending_layer_->UpdateTiles(resourceless_software_draw);
3070 unique_tiles.clear();
3071 high_res_tile_count = 0u;
3072 queue.reset(new TilingSetRasterQueueAll(
3073 pending_layer_->picture_layer_tiling_set(), false));
3074 while (!queue->IsEmpty()) {
3075 PrioritizedTile prioritized_tile = queue->Top();
3076 TilePriority priority = prioritized_tile.priority();
3078 EXPECT_TRUE(prioritized_tile.tile());
3080 // Non-high res tiles only get visible tiles.
3081 EXPECT_EQ(HIGH_RESOLUTION, priority.resolution);
3082 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
3084 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
3086 unique_tiles.insert(prioritized_tile.tile());
3087 queue->Pop();
3090 EXPECT_EQ(16, high_res_tile_count);
3091 EXPECT_EQ(high_res_tile_count, static_cast<int>(unique_tiles.size()));
3093 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3095 pending_layer_->draw_properties().visible_layer_rect =
3096 gfx::Rect(0, 0, 500, 500);
3097 pending_layer_->UpdateTiles(resourceless_software_draw);
3099 std::vector<Tile*> high_res_tiles =
3100 pending_layer_->HighResTiling()->AllTilesForTesting();
3101 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin();
3102 tile_it != high_res_tiles.end();
3103 ++tile_it) {
3104 Tile* tile = *tile_it;
3105 TileDrawInfo& draw_info = tile->draw_info();
3106 draw_info.SetSolidColorForTesting(SK_ColorRED);
3109 queue.reset(new TilingSetRasterQueueAll(
3110 pending_layer_->picture_layer_tiling_set(), true));
3111 EXPECT_TRUE(queue->IsEmpty());
3114 TEST_F(PictureLayerImplTest, TilingSetRasterQueueActiveTree) {
3115 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
3117 host_impl_.SetViewportSize(gfx::Size(500, 500));
3119 gfx::Size tile_size(100, 100);
3120 gfx::Size layer_bounds(1000, 1000);
3122 scoped_refptr<FakePicturePileImpl> pending_pile =
3123 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3125 SetupPendingTree(pending_pile);
3126 ActivateTree();
3127 EXPECT_EQ(2u, active_layer_->num_tilings());
3129 scoped_ptr<TilingSetRasterQueueRequired> queue(
3130 new TilingSetRasterQueueRequired(
3131 active_layer_->picture_layer_tiling_set(),
3132 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW));
3133 EXPECT_FALSE(queue->IsEmpty());
3134 while (!queue->IsEmpty()) {
3135 PrioritizedTile prioritized_tile = queue->Top();
3136 EXPECT_TRUE(prioritized_tile.tile()->required_for_draw());
3137 EXPECT_FALSE(prioritized_tile.tile()->draw_info().IsReadyToDraw());
3138 queue->Pop();
3141 queue.reset(new TilingSetRasterQueueRequired(
3142 active_layer_->picture_layer_tiling_set(),
3143 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION));
3144 EXPECT_TRUE(queue->IsEmpty());
3147 TEST_F(PictureLayerImplTest, TilingSetRasterQueueRequiredNoHighRes) {
3148 scoped_ptr<FakePicturePile> empty_recording =
3149 FakePicturePile::CreateEmptyPile(gfx::Size(256, 256),
3150 gfx::Size(1024, 1024));
3151 empty_recording->SetIsSolidColor(true);
3153 scoped_refptr<FakePicturePileImpl> pending_pile =
3154 FakePicturePileImpl::CreateFromPile(empty_recording.get(), nullptr);
3156 SetupPendingTree(pending_pile);
3157 EXPECT_FALSE(
3158 pending_layer_->picture_layer_tiling_set()->FindTilingWithResolution(
3159 HIGH_RESOLUTION));
3161 scoped_ptr<TilingSetRasterQueueRequired> queue(
3162 new TilingSetRasterQueueRequired(
3163 pending_layer_->picture_layer_tiling_set(),
3164 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION));
3165 EXPECT_TRUE(queue->IsEmpty());
3168 TEST_F(PictureLayerImplTest, TilingSetEvictionQueue) {
3169 gfx::Size tile_size(100, 100);
3170 gfx::Size layer_bounds(1000, 1000);
3171 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3173 host_impl_.SetViewportSize(gfx::Size(500, 500));
3175 scoped_refptr<FakePicturePileImpl> pending_pile =
3176 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3178 // TODO(vmpstr): Add a test with tilings other than high res on the active
3179 // tree (crbug.com/519607).
3180 SetupPendingTree(pending_pile);
3181 EXPECT_EQ(1u, pending_layer_->num_tilings());
3183 std::vector<Tile*> all_tiles;
3184 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3185 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3186 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
3187 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end());
3190 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end());
3192 bool mark_required = false;
3193 size_t number_of_marked_tiles = 0u;
3194 size_t number_of_unmarked_tiles = 0u;
3195 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3196 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3197 for (PictureLayerTiling::CoverageIterator iter(
3198 tiling, 1.f, pending_layer_->visible_layer_rect());
3199 iter; ++iter) {
3200 if (mark_required) {
3201 number_of_marked_tiles++;
3202 iter->set_required_for_activation(true);
3203 } else {
3204 number_of_unmarked_tiles++;
3206 mark_required = !mark_required;
3210 // Sanity checks.
3211 EXPECT_EQ(16u, all_tiles.size());
3212 EXPECT_EQ(16u, all_tiles_set.size());
3213 EXPECT_GT(number_of_marked_tiles, 1u);
3214 EXPECT_GT(number_of_unmarked_tiles, 1u);
3216 // Tiles don't have resources yet.
3217 scoped_ptr<TilingSetEvictionQueue> queue(
3218 new TilingSetEvictionQueue(pending_layer_->picture_layer_tiling_set()));
3219 EXPECT_TRUE(queue->IsEmpty());
3221 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
3223 std::set<Tile*> unique_tiles;
3224 float expected_scales[] = {low_res_factor, 1.f};
3225 size_t scale_index = 0;
3226 bool reached_visible = false;
3227 PrioritizedTile last_tile;
3228 size_t distance_decreasing = 0;
3229 size_t distance_increasing = 0;
3230 queue.reset(
3231 new TilingSetEvictionQueue(pending_layer_->picture_layer_tiling_set()));
3232 while (!queue->IsEmpty()) {
3233 PrioritizedTile prioritized_tile = queue->Top();
3234 Tile* tile = prioritized_tile.tile();
3235 if (!last_tile.tile())
3236 last_tile = prioritized_tile;
3238 EXPECT_TRUE(tile);
3240 TilePriority priority = prioritized_tile.priority();
3242 if (priority.priority_bin == TilePriority::NOW) {
3243 reached_visible = true;
3244 last_tile = prioritized_tile;
3245 break;
3248 EXPECT_FALSE(tile->required_for_activation());
3250 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) >
3251 std::numeric_limits<float>::epsilon()) {
3252 ++scale_index;
3253 ASSERT_LT(scale_index, arraysize(expected_scales));
3256 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]);
3257 unique_tiles.insert(tile);
3259 if (tile->required_for_activation() ==
3260 last_tile.tile()->required_for_activation() &&
3261 std::abs(tile->contents_scale() - last_tile.tile()->contents_scale()) <
3262 std::numeric_limits<float>::epsilon()) {
3263 if (priority.distance_to_visible <=
3264 last_tile.priority().distance_to_visible)
3265 ++distance_decreasing;
3266 else
3267 ++distance_increasing;
3270 last_tile = prioritized_tile;
3271 queue->Pop();
3274 // 4 high res tiles are inside the viewport, the rest are evicted.
3275 EXPECT_TRUE(reached_visible);
3276 EXPECT_EQ(12u, unique_tiles.size());
3277 EXPECT_EQ(1u, distance_increasing);
3278 EXPECT_EQ(11u, distance_decreasing);
3280 scale_index = 0;
3281 bool reached_required = false;
3282 while (!queue->IsEmpty()) {
3283 PrioritizedTile prioritized_tile = queue->Top();
3284 Tile* tile = prioritized_tile.tile();
3285 EXPECT_TRUE(tile);
3287 TilePriority priority = prioritized_tile.priority();
3288 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
3290 if (reached_required) {
3291 EXPECT_TRUE(tile->required_for_activation());
3292 } else if (tile->required_for_activation()) {
3293 reached_required = true;
3294 scale_index = 0;
3297 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) >
3298 std::numeric_limits<float>::epsilon()) {
3299 ++scale_index;
3300 ASSERT_LT(scale_index, arraysize(expected_scales));
3303 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]);
3304 unique_tiles.insert(tile);
3305 queue->Pop();
3308 EXPECT_TRUE(reached_required);
3309 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size());
3312 TEST_F(PictureLayerImplTest, Occlusion) {
3313 gfx::Size tile_size(102, 102);
3314 gfx::Size layer_bounds(1000, 1000);
3315 gfx::Size viewport_size(1000, 1000);
3317 LayerTestCommon::LayerImplTest impl;
3318 host_impl_.SetViewportSize(viewport_size);
3320 scoped_refptr<FakePicturePileImpl> pending_pile =
3321 FakePicturePileImpl::CreateFilledPile(layer_bounds, layer_bounds);
3322 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
3323 ActivateTree();
3325 std::vector<Tile*> tiles =
3326 active_layer_->HighResTiling()->AllTilesForTesting();
3327 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
3330 SCOPED_TRACE("No occlusion");
3331 gfx::Rect occluded;
3332 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
3334 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
3335 gfx::Rect(layer_bounds));
3336 EXPECT_EQ(100u, impl.quad_list().size());
3340 SCOPED_TRACE("Full occlusion");
3341 gfx::Rect occluded(active_layer_->visible_layer_rect());
3342 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
3344 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
3345 EXPECT_EQ(impl.quad_list().size(), 0u);
3349 SCOPED_TRACE("Partial occlusion");
3350 gfx::Rect occluded(150, 0, 200, 1000);
3351 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
3353 size_t partially_occluded_count = 0;
3354 LayerTestCommon::VerifyQuadsAreOccluded(
3355 impl.quad_list(), occluded, &partially_occluded_count);
3356 // The layer outputs one quad, which is partially occluded.
3357 EXPECT_EQ(100u - 10u, impl.quad_list().size());
3358 EXPECT_EQ(10u + 10u, partially_occluded_count);
3362 TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) {
3363 gfx::Size tile_size(host_impl_.settings().default_tile_size);
3364 SetupDefaultTrees(tile_size);
3366 ResetTilingsAndRasterScales();
3368 float contents_scale = 2.f;
3369 float device_scale = 1.f;
3370 float page_scale = 1.f;
3371 float maximum_animation_scale = 1.f;
3372 float starting_animation_scale = 0.f;
3373 bool animating_transform = false;
3375 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
3376 maximum_animation_scale,
3377 starting_animation_scale, animating_transform);
3378 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
3380 // Changing the source scale without being in an animation will cause
3381 // the layer to reset its source scale to 1.f.
3382 contents_scale = 3.f;
3384 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
3385 maximum_animation_scale,
3386 starting_animation_scale, animating_transform);
3387 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
3389 // Further changes to the source scale will no longer be reflected in the
3390 // contents scale.
3391 contents_scale = 0.5f;
3393 SetContentsScaleOnBothLayers(contents_scale, device_scale, page_scale,
3394 maximum_animation_scale,
3395 starting_animation_scale, animating_transform);
3396 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
3399 TEST_F(PictureLayerImplTest, LowResReadyToDrawNotEnoughToActivate) {
3400 gfx::Size tile_size(100, 100);
3401 gfx::Size layer_bounds(1000, 1000);
3403 // Make sure pending tree has tiles.
3404 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3405 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3407 // All pending layer tiles required are not ready.
3408 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3410 // Initialize all low-res tiles.
3411 EXPECT_FALSE(pending_layer_->LowResTiling());
3412 pending_layer_->SetAllTilesReadyInTiling(active_layer_->LowResTiling());
3414 // Low-res tiles should not be enough.
3415 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3417 // Initialize remaining tiles.
3418 pending_layer_->SetAllTilesReady();
3419 active_layer_->SetAllTilesReady();
3421 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
3424 TEST_F(PictureLayerImplTest, HighResReadyToDrawEnoughToActivate) {
3425 gfx::Size tile_size(100, 100);
3426 gfx::Size layer_bounds(1000, 1000);
3428 // Make sure pending tree has tiles.
3429 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3430 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3432 // All pending layer tiles required are not ready.
3433 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3435 // Initialize all high-res tiles.
3436 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
3437 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling());
3439 // High-res tiles should be enough, since they cover everything visible.
3440 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
3443 TEST_F(PictureLayerImplTest, ActiveHighResReadyNotEnoughToActivate) {
3444 gfx::Size tile_size(100, 100);
3445 gfx::Size layer_bounds(1000, 1000);
3447 // Make sure pending tree has tiles.
3448 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3449 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3451 // Initialize all high-res tiles in the active layer.
3452 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling());
3454 // The pending high-res tiles are not ready, so we cannot activate.
3455 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3457 // When the pending high-res tiles are ready, we can activate.
3458 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
3459 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
3462 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) {
3463 gfx::Size tile_size(400, 400);
3464 gfx::Size layer_bounds(1300, 1900);
3466 scoped_refptr<FakePicturePileImpl> pending_pile =
3467 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3468 scoped_refptr<FakePicturePileImpl> active_pile =
3469 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3471 SetupTrees(pending_pile, active_pile);
3473 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3474 EXPECT_LT(low_res_factor, 1.f);
3476 ResetTilingsAndRasterScales();
3478 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3479 6.f, // ideal contents scale
3480 3.f, // device scale
3481 2.f, // page scale
3482 1.f, // maximum animation scale
3483 0.f, // starting animation scale
3484 false);
3485 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3486 EXPECT_FLOAT_EQ(6.f,
3487 active_layer_->tilings()->tiling_at(0)->contents_scale());
3489 // If we change the page scale factor, then we should get new tilings.
3490 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3491 6.6f, // ideal contents scale
3492 3.f, // device scale
3493 2.2f, // page scale
3494 1.f, // maximum animation scale
3495 0.f, // starting animation scale
3496 false);
3497 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3498 EXPECT_FLOAT_EQ(6.6f,
3499 active_layer_->tilings()->tiling_at(0)->contents_scale());
3501 // If we change the device scale factor, then we should get new tilings.
3502 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3503 7.26f, // ideal contents scale
3504 3.3f, // device scale
3505 2.2f, // page scale
3506 1.f, // maximum animation scale
3507 0.f, // starting animation scale
3508 false);
3509 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
3510 EXPECT_FLOAT_EQ(7.26f,
3511 active_layer_->tilings()->tiling_at(0)->contents_scale());
3513 // If we change the device scale factor, but end up at the same total scale
3514 // factor somehow, then we don't get new tilings.
3515 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3516 7.26f, // ideal contents scale
3517 2.2f, // device scale
3518 3.3f, // page scale
3519 1.f, // maximum animation scale
3520 0.f, // starting animation scale
3521 false);
3522 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
3523 EXPECT_FLOAT_EQ(7.26f,
3524 active_layer_->tilings()->tiling_at(0)->contents_scale());
3527 TEST_F(NoLowResPictureLayerImplTest, PendingLayerOnlyHasHighResTiling) {
3528 gfx::Size tile_size(400, 400);
3529 gfx::Size layer_bounds(1300, 1900);
3531 scoped_refptr<FakePicturePileImpl> pending_pile =
3532 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3533 scoped_refptr<FakePicturePileImpl> active_pile =
3534 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3536 SetupTrees(pending_pile, active_pile);
3538 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3539 EXPECT_LT(low_res_factor, 1.f);
3541 ResetTilingsAndRasterScales();
3543 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3544 6.f, // ideal contents scale
3545 3.f, // device scale
3546 2.f, // page scale
3547 1.f, // maximum animation scale
3548 0.f, // starting animation scale
3549 false);
3550 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3551 EXPECT_FLOAT_EQ(6.f,
3552 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3554 // If we change the page scale factor, then we should get new tilings.
3555 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3556 6.6f, // ideal contents scale
3557 3.f, // device scale
3558 2.2f, // page scale
3559 1.f, // maximum animation scale
3560 0.f, // starting animation scale
3561 false);
3562 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3563 EXPECT_FLOAT_EQ(6.6f,
3564 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3566 // If we change the device scale factor, then we should get new tilings.
3567 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3568 7.26f, // ideal contents scale
3569 3.3f, // device scale
3570 2.2f, // page scale
3571 1.f, // maximum animation scale
3572 0.f, // starting animation scale
3573 false);
3574 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3575 EXPECT_FLOAT_EQ(7.26f,
3576 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3578 // If we change the device scale factor, but end up at the same total scale
3579 // factor somehow, then we don't get new tilings.
3580 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3581 7.26f, // ideal contents scale
3582 2.2f, // device scale
3583 3.3f, // page scale
3584 1.f, // maximum animation scale
3585 0.f, // starting animation scale
3586 false);
3587 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3588 EXPECT_FLOAT_EQ(7.26f,
3589 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3592 TEST_F(NoLowResPictureLayerImplTest, AllHighResRequiredEvenIfNotChanged) {
3593 gfx::Size layer_bounds(400, 400);
3594 gfx::Size tile_size(100, 100);
3596 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
3598 Tile* some_active_tile =
3599 active_layer_->HighResTiling()->AllTilesForTesting()[0];
3600 EXPECT_FALSE(some_active_tile->draw_info().IsReadyToDraw());
3602 // Since there is no invalidation, pending tree should have no tiles.
3603 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
3604 if (host_impl_.settings().create_low_res_tiling)
3605 EXPECT_TRUE(pending_layer_->LowResTiling()->AllTilesForTesting().empty());
3607 active_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
3608 if (host_impl_.settings().create_low_res_tiling)
3609 active_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
3611 AssertAllTilesRequired(active_layer_->HighResTiling());
3612 if (host_impl_.settings().create_low_res_tiling)
3613 AssertNoTilesRequired(active_layer_->LowResTiling());
3616 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) {
3617 gfx::Size layer_bounds(400, 400);
3618 gfx::Size tile_size(100, 100);
3620 scoped_refptr<FakePicturePileImpl> pending_pile =
3621 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3622 // This pile will create tilings, but has no recordings so will not create any
3623 // tiles. This is attempting to simulate scrolling past the end of recorded
3624 // content on the active layer, where the recordings are so far away that
3625 // no tiles are created.
3626 bool is_solid_color = false;
3627 scoped_refptr<FakePicturePileImpl> active_pile =
3628 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
3629 tile_size, layer_bounds, is_solid_color);
3631 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
3633 // Active layer has tilings, but no tiles due to missing recordings.
3634 EXPECT_TRUE(active_layer_->CanHaveTilings());
3635 EXPECT_EQ(active_layer_->tilings()->num_tilings(),
3636 host_impl_.settings().create_low_res_tiling ? 2u : 1u);
3637 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u);
3639 // Since the active layer has no tiles at all, the pending layer doesn't
3640 // need content in order to activate.
3641 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
3642 if (host_impl_.settings().create_low_res_tiling)
3643 pending_layer_->LowResTiling()->UpdateAllRequiredStateForTesting();
3645 AssertNoTilesRequired(pending_layer_->HighResTiling());
3646 if (host_impl_.settings().create_low_res_tiling)
3647 AssertNoTilesRequired(pending_layer_->LowResTiling());
3650 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) {
3651 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
3653 gfx::Size tile_size(100, 100);
3654 gfx::Size layer_bounds(400, 400);
3656 scoped_refptr<FakePicturePileImpl> pending_pile =
3657 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3658 scoped_refptr<FakePicturePileImpl> active_pile =
3659 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3661 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
3663 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
3664 false);
3666 // UpdateTiles with valid viewport. Should update tile viewport.
3667 // Note viewport is considered invalid if and only if in resourceless
3668 // software draw.
3669 bool resourceless_software_draw = false;
3670 gfx::Rect viewport = gfx::Rect(layer_bounds);
3671 gfx::Transform transform;
3672 host_impl_.SetExternalDrawConstraints(transform,
3673 viewport,
3674 viewport,
3675 viewport,
3676 transform,
3677 resourceless_software_draw);
3678 active_layer_->draw_properties().visible_layer_rect = viewport;
3679 active_layer_->draw_properties().screen_space_transform = transform;
3680 active_layer_->UpdateTiles(resourceless_software_draw);
3682 gfx::Rect visible_rect_for_tile_priority =
3683 active_layer_->visible_rect_for_tile_priority();
3684 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty());
3685 gfx::Transform screen_space_transform_for_tile_priority =
3686 active_layer_->screen_space_transform();
3688 // Expand viewport and set it as invalid for prioritizing tiles.
3689 // Should update viewport and transform, but not update visible rect.
3690 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3691 resourceless_software_draw = true;
3692 viewport = gfx::ScaleToEnclosingRect(viewport, 2);
3693 transform.Translate(1.f, 1.f);
3694 active_layer_->draw_properties().visible_layer_rect = viewport;
3695 active_layer_->draw_properties().screen_space_transform = transform;
3696 host_impl_.SetExternalDrawConstraints(transform,
3697 viewport,
3698 viewport,
3699 viewport,
3700 transform,
3701 resourceless_software_draw);
3702 active_layer_->UpdateTiles(resourceless_software_draw);
3704 // Transform for tile priority is updated.
3705 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
3706 active_layer_->screen_space_transform());
3707 // Visible rect for tile priority retains old value.
3708 EXPECT_EQ(visible_rect_for_tile_priority,
3709 active_layer_->visible_rect_for_tile_priority());
3711 // Keep expanded viewport but mark it valid. Should update tile viewport.
3712 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3713 resourceless_software_draw = false;
3714 host_impl_.SetExternalDrawConstraints(transform,
3715 viewport,
3716 viewport,
3717 viewport,
3718 transform,
3719 resourceless_software_draw);
3720 active_layer_->UpdateTiles(resourceless_software_draw);
3722 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
3723 active_layer_->screen_space_transform());
3724 EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority());
3727 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) {
3728 gfx::Size tile_size(400, 400);
3729 gfx::Size layer_bounds(1300, 1900);
3731 scoped_refptr<FakePicturePileImpl> pending_pile =
3732 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3733 scoped_refptr<FakePicturePileImpl> active_pile =
3734 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3736 std::vector<PictureLayerTiling*> used_tilings;
3738 SetupTrees(pending_pile, active_pile);
3740 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3741 EXPECT_LT(low_res_factor, 1.f);
3743 float device_scale = 1.7f;
3744 float page_scale = 3.2f;
3745 float scale = 1.f;
3747 ResetTilingsAndRasterScales();
3749 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, 0.f,
3750 false);
3751 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3753 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
3754 // |used_tilings| variable, and it's here only to ensure that active_layer_
3755 // won't remove tilings before the test has a chance to verify behavior.
3756 active_layer_->MarkAllTilingsUsed();
3758 // We only have ideal tilings, so they aren't removed.
3759 used_tilings.clear();
3760 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3761 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3763 host_impl_.PinchGestureBegin();
3765 // Changing the ideal but not creating new tilings.
3766 scale *= 1.5f;
3767 page_scale *= 1.5f;
3768 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, 0.f,
3769 false);
3770 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3772 // The tilings are still our target scale, so they aren't removed.
3773 used_tilings.clear();
3774 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3775 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3777 host_impl_.PinchGestureEnd();
3779 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
3780 scale /= 4.f;
3781 page_scale /= 4.f;
3782 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, 0.f, false);
3783 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3784 EXPECT_FLOAT_EQ(1.f,
3785 active_layer_->tilings()->tiling_at(1)->contents_scale());
3787 // Ensure UpdateTiles won't remove any tilings.
3788 active_layer_->MarkAllTilingsUsed();
3790 // Mark the non-ideal tilings as used. They won't be removed.
3791 used_tilings.clear();
3792 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
3793 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3794 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3796 // Now move the ideal scale to 0.5. Our target stays 1.2.
3797 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, 0.f, false);
3799 // The high resolution tiling is between target and ideal, so is not
3800 // removed. The low res tiling for the old ideal=1.0 scale is removed.
3801 used_tilings.clear();
3802 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3803 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3805 // Now move the ideal scale to 1.0. Our target stays 1.2.
3806 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, 0.f, false);
3808 // All the tilings are between are target and the ideal, so they are not
3809 // removed.
3810 used_tilings.clear();
3811 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3812 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3814 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
3815 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.1f, device_scale,
3816 page_scale, 1.f, 0.f, false);
3818 // Because the pending layer's ideal scale is still 1.0, our tilings fall
3819 // in the range [1.0,1.2] and are kept.
3820 used_tilings.clear();
3821 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3822 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3824 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
3825 // 1.2 still.
3826 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.1f, device_scale,
3827 page_scale, 1.f, 0.f, false);
3829 // Our 1.0 tiling now falls outside the range between our ideal scale and our
3830 // target raster scale. But it is in our used tilings set, so nothing is
3831 // deleted.
3832 used_tilings.clear();
3833 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
3834 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3835 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3837 // If we remove it from our used tilings set, it is outside the range to keep
3838 // so it is deleted.
3839 used_tilings.clear();
3840 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3841 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3844 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) {
3845 gfx::Size tile_size(400, 400);
3846 gfx::Size layer_bounds(1300, 1900);
3848 scoped_refptr<FakePicturePileImpl> pending_pile =
3849 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3850 scoped_refptr<FakePicturePileImpl> active_pile =
3851 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3853 SetupTrees(pending_pile, active_pile);
3854 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3855 EXPECT_EQ(1u, active_layer_->tilings()->num_tilings());
3857 // All tilings should be removed when losing output surface.
3858 active_layer_->ReleaseResources();
3859 EXPECT_FALSE(active_layer_->tilings());
3860 active_layer_->RecreateResources();
3861 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
3862 pending_layer_->ReleaseResources();
3863 EXPECT_FALSE(pending_layer_->tilings());
3864 pending_layer_->RecreateResources();
3865 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3867 // This should create new tilings.
3868 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3869 1.3f, // ideal contents scale
3870 2.7f, // device scale
3871 3.2f, // page scale
3872 1.f, // maximum animation scale
3873 0.f, // starting animation scale
3874 false);
3875 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3878 TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) {
3879 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
3881 gfx::Size tile_size(400, 400);
3882 gfx::Size layer_bounds(1000, 2000);
3884 host_impl_.SetViewportSize(gfx::Size(10000, 20000));
3886 scoped_refptr<FakePicturePileImpl> pending_pile =
3887 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3888 scoped_refptr<FakePicturePileImpl> active_pile =
3889 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3891 SetupTrees(pending_pile, active_pile);
3893 ResetTilingsAndRasterScales();
3894 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.5f, 1.f, 1.f, 1.f, 0.f,
3895 false);
3897 float max_contents_scale = active_layer_->MaximumTilingContentsScale();
3898 EXPECT_EQ(2.5f, max_contents_scale);
3900 gfx::Transform scaled_draw_transform = active_layer_->draw_transform();
3901 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale,
3902 SK_MScalar1 / max_contents_scale);
3904 AppendQuadsData data;
3905 active_layer_->AppendQuads(render_pass.get(), &data);
3907 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
3908 EXPECT_EQ(1u, render_pass->shared_quad_state_list.size());
3909 // The quad_to_target_transform should be scaled by the
3910 // MaximumTilingContentsScale on the layer.
3911 EXPECT_EQ(scaled_draw_transform.ToString(),
3912 render_pass->shared_quad_state_list.front()
3913 ->quad_to_target_transform.ToString());
3914 // The content_bounds should be scaled by the
3915 // MaximumTilingContentsScale on the layer.
3916 EXPECT_EQ(gfx::Size(2500u, 5000u).ToString(),
3917 render_pass->shared_quad_state_list.front()
3918 ->quad_layer_bounds.ToString());
3919 // The visible_layer_rect should be scaled by the
3920 // MaximumTilingContentsScale on the layer.
3921 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
3922 render_pass->shared_quad_state_list.front()
3923 ->visible_quad_layer_rect.ToString());
3926 class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest {
3927 public:
3928 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {}
3930 void InitializeRenderer() override {
3931 host_impl_.InitializeRenderer(FakeOutputSurface::CreateDelegating3d());
3935 TEST_F(PictureLayerImplTestWithDelegatingRenderer,
3936 DelegatingRendererWithTileOOM) {
3937 // This test is added for crbug.com/402321, where quad should be produced when
3938 // raster on demand is not allowed and tile is OOM.
3939 gfx::Size tile_size = host_impl_.settings().default_tile_size;
3940 gfx::Size layer_bounds(1000, 1000);
3942 // Create tiles.
3943 scoped_refptr<FakePicturePileImpl> pending_pile =
3944 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3945 SetupPendingTree(pending_pile);
3946 pending_layer_->SetBounds(layer_bounds);
3947 ActivateTree();
3948 bool update_lcd_text = false;
3949 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
3950 std::vector<Tile*> tiles =
3951 active_layer_->HighResTiling()->AllTilesForTesting();
3952 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
3954 // Force tiles after max_tiles to be OOM. TileManager uses
3955 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3956 // directly set state to host_impl_, so we set policy that would change the
3957 // state. We also need to update tree priority separately.
3958 GlobalStateThatImpactsTilePriority state;
3959 size_t max_tiles = 1;
3960 size_t memory_limit = max_tiles * 4 * tile_size.width() * tile_size.height();
3961 size_t resource_limit = max_tiles;
3962 ManagedMemoryPolicy policy(memory_limit,
3963 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
3964 resource_limit);
3965 host_impl_.SetMemoryPolicy(policy);
3966 host_impl_.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES);
3967 host_impl_.PrepareTiles();
3969 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
3970 AppendQuadsData data;
3971 active_layer_->WillDraw(DRAW_MODE_HARDWARE, nullptr);
3972 active_layer_->AppendQuads(render_pass.get(), &data);
3973 active_layer_->DidDraw(nullptr);
3975 // Even when OOM, quads should be produced, and should be different material
3976 // from quads with resource.
3977 EXPECT_LT(max_tiles, render_pass->quad_list.size());
3978 EXPECT_EQ(DrawQuad::Material::TILED_CONTENT,
3979 render_pass->quad_list.front()->material);
3980 EXPECT_EQ(DrawQuad::Material::SOLID_COLOR,
3981 render_pass->quad_list.back()->material);
3984 class OcclusionTrackingSettings : public LowResTilingsSettings {
3985 public:
3986 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; }
3989 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest {
3990 public:
3991 OcclusionTrackingPictureLayerImplTest()
3992 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
3994 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl* layer,
3995 WhichTree tree,
3996 size_t expected_occluded_tile_count,
3997 int source_line) {
3998 size_t occluded_tile_count = 0u;
3999 PrioritizedTile last_tile;
4001 scoped_ptr<TilingSetEvictionQueue> queue(
4002 new TilingSetEvictionQueue(layer->picture_layer_tiling_set()));
4003 while (!queue->IsEmpty()) {
4004 PrioritizedTile prioritized_tile = queue->Top();
4005 Tile* tile = prioritized_tile.tile();
4006 if (!last_tile.tile())
4007 last_tile = prioritized_tile;
4009 // The only way we will encounter an occluded tile after an unoccluded
4010 // tile is if the priorty bin decreased, the tile is required for
4011 // activation, or the scale changed.
4012 bool tile_is_occluded = prioritized_tile.is_occluded();
4013 if (tile_is_occluded) {
4014 occluded_tile_count++;
4016 bool last_tile_is_occluded = last_tile.is_occluded();
4017 if (!last_tile_is_occluded) {
4018 TilePriority::PriorityBin tile_priority_bin =
4019 prioritized_tile.priority().priority_bin;
4020 TilePriority::PriorityBin last_tile_priority_bin =
4021 last_tile.priority().priority_bin;
4023 EXPECT_TRUE(tile_priority_bin < last_tile_priority_bin ||
4024 tile->required_for_activation() ||
4025 tile->contents_scale() !=
4026 last_tile.tile()->contents_scale())
4027 << "line: " << source_line;
4030 last_tile = prioritized_tile;
4031 queue->Pop();
4033 EXPECT_EQ(expected_occluded_tile_count, occluded_tile_count)
4034 << "line: " << source_line;
4038 TEST_F(OcclusionTrackingPictureLayerImplTest,
4039 OccludedTilesSkippedDuringRasterization) {
4040 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4042 gfx::Size tile_size(102, 102);
4043 gfx::Size layer_bounds(1000, 1000);
4044 gfx::Size viewport_size(500, 500);
4045 gfx::Point occluding_layer_position(310, 0);
4047 host_impl_.SetViewportSize(viewport_size);
4049 scoped_refptr<FakePicturePileImpl> pending_pile =
4050 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4051 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
4053 // No occlusion.
4054 int unoccluded_tile_count = 0;
4055 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
4056 pending_layer_->picture_layer_tiling_set(), false));
4057 while (!queue->IsEmpty()) {
4058 PrioritizedTile prioritized_tile = queue->Top();
4059 Tile* tile = prioritized_tile.tile();
4061 // Occluded tiles should not be iterated over.
4062 EXPECT_FALSE(prioritized_tile.is_occluded());
4064 // Some tiles may not be visible (i.e. outside the viewport). The rest are
4065 // visible and at least partially unoccluded, verified by the above expect.
4066 bool tile_is_visible =
4067 tile->content_rect().Intersects(pending_layer_->visible_layer_rect());
4068 if (tile_is_visible)
4069 unoccluded_tile_count++;
4070 queue->Pop();
4072 EXPECT_EQ(unoccluded_tile_count, 25);
4074 // Partial occlusion.
4075 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
4076 LayerImpl* layer1 = pending_layer_->children()[0];
4077 layer1->SetBounds(layer_bounds);
4078 layer1->SetDrawsContent(true);
4079 layer1->SetContentsOpaque(true);
4080 layer1->SetPosition(occluding_layer_position);
4082 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
4083 bool update_lcd_text = false;
4084 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4086 unoccluded_tile_count = 0;
4087 queue.reset(new TilingSetRasterQueueAll(
4088 pending_layer_->picture_layer_tiling_set(), false));
4089 while (!queue->IsEmpty()) {
4090 PrioritizedTile prioritized_tile = queue->Top();
4091 Tile* tile = prioritized_tile.tile();
4093 EXPECT_FALSE(prioritized_tile.is_occluded());
4095 bool tile_is_visible =
4096 tile->content_rect().Intersects(pending_layer_->visible_layer_rect());
4097 if (tile_is_visible)
4098 unoccluded_tile_count++;
4099 queue->Pop();
4101 EXPECT_EQ(20, unoccluded_tile_count);
4103 // Full occlusion.
4104 layer1->SetPosition(gfx::Point(0, 0));
4106 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
4107 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4109 unoccluded_tile_count = 0;
4110 queue.reset(new TilingSetRasterQueueAll(
4111 pending_layer_->picture_layer_tiling_set(), false));
4112 while (!queue->IsEmpty()) {
4113 PrioritizedTile prioritized_tile = queue->Top();
4114 Tile* tile = prioritized_tile.tile();
4116 EXPECT_FALSE(prioritized_tile.is_occluded());
4118 bool tile_is_visible =
4119 tile->content_rect().Intersects(pending_layer_->visible_layer_rect());
4120 if (tile_is_visible)
4121 unoccluded_tile_count++;
4122 queue->Pop();
4124 EXPECT_EQ(unoccluded_tile_count, 0);
4127 TEST_F(OcclusionTrackingPictureLayerImplTest,
4128 OccludedTilesNotMarkedAsRequired) {
4129 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4131 gfx::Size tile_size(102, 102);
4132 gfx::Size layer_bounds(1000, 1000);
4133 gfx::Size viewport_size(500, 500);
4134 gfx::Point occluding_layer_position(310, 0);
4136 host_impl_.SetViewportSize(viewport_size);
4138 scoped_refptr<FakePicturePileImpl> pending_pile =
4139 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4140 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
4142 // No occlusion.
4143 int occluded_tile_count = 0;
4144 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4145 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4146 auto prioritized_tiles =
4147 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
4149 occluded_tile_count = 0;
4150 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4151 gfx::Rect(layer_bounds));
4152 iter; ++iter) {
4153 if (!*iter)
4154 continue;
4155 const Tile* tile = *iter;
4157 // Fully occluded tiles are not required for activation.
4158 if (prioritized_tiles[tile].is_occluded()) {
4159 EXPECT_FALSE(tile->required_for_activation());
4160 occluded_tile_count++;
4163 EXPECT_EQ(occluded_tile_count, 0);
4166 // Partial occlusion.
4167 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
4168 LayerImpl* layer1 = pending_layer_->children()[0];
4169 layer1->SetBounds(layer_bounds);
4170 layer1->SetDrawsContent(true);
4171 layer1->SetContentsOpaque(true);
4172 layer1->SetPosition(occluding_layer_position);
4174 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
4175 bool update_lcd_text = false;
4176 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4178 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4179 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4180 auto prioritized_tiles =
4181 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
4183 occluded_tile_count = 0;
4184 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4185 gfx::Rect(layer_bounds));
4186 iter; ++iter) {
4187 if (!*iter)
4188 continue;
4189 const Tile* tile = *iter;
4191 if (prioritized_tiles[tile].is_occluded()) {
4192 EXPECT_FALSE(tile->required_for_activation());
4193 occluded_tile_count++;
4196 switch (i) {
4197 case 0:
4198 EXPECT_EQ(occluded_tile_count, 5);
4199 break;
4200 case 1:
4201 EXPECT_EQ(occluded_tile_count, 2);
4202 break;
4203 default:
4204 NOTREACHED();
4208 // Full occlusion.
4209 layer1->SetPosition(gfx::PointF(0, 0));
4211 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
4212 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4214 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4215 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4216 auto prioritized_tiles =
4217 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
4219 occluded_tile_count = 0;
4220 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4221 gfx::Rect(layer_bounds));
4222 iter; ++iter) {
4223 if (!*iter)
4224 continue;
4225 const Tile* tile = *iter;
4227 if (prioritized_tiles[tile].is_occluded()) {
4228 EXPECT_FALSE(tile->required_for_activation());
4229 occluded_tile_count++;
4232 switch (i) {
4233 case 0:
4234 EXPECT_EQ(25, occluded_tile_count);
4235 break;
4236 case 1:
4237 EXPECT_EQ(4, occluded_tile_count);
4238 break;
4239 default:
4240 NOTREACHED();
4245 TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) {
4246 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4248 gfx::Size tile_size(102, 102);
4249 gfx::Size layer_bounds(1000, 1000);
4250 gfx::Size viewport_size(500, 500);
4251 gfx::Point occluding_layer_position(310, 0);
4253 scoped_refptr<FakePicturePileImpl> pending_pile =
4254 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4256 host_impl_.SetViewportSize(viewport_size);
4258 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
4259 ASSERT_TRUE(pending_layer_->CanHaveTilings());
4261 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
4262 LayerImpl* layer1 = pending_layer_->children()[0];
4263 layer1->SetBounds(layer_bounds);
4264 layer1->SetDrawsContent(true);
4265 layer1->SetContentsOpaque(true);
4266 layer1->SetPosition(occluding_layer_position);
4268 pending_layer_->tilings()->RemoveAllTilings();
4269 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
4270 pending_layer_->AddTiling(low_res_factor)->set_resolution(LOW_RESOLUTION);
4271 pending_layer_->AddTiling(0.3f)->set_resolution(HIGH_RESOLUTION);
4272 pending_layer_->AddTiling(0.7f)->set_resolution(HIGH_RESOLUTION);
4273 pending_layer_->AddTiling(1.0f)->set_resolution(HIGH_RESOLUTION);
4274 pending_layer_->AddTiling(2.0f)->set_resolution(HIGH_RESOLUTION);
4276 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4277 // UpdateDrawProperties with the occluding layer.
4278 bool update_lcd_text = false;
4279 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4281 EXPECT_EQ(5u, pending_layer_->num_tilings());
4283 int occluded_tile_count = 0;
4284 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4285 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4286 auto prioritized_tiles =
4287 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
4288 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
4290 occluded_tile_count = 0;
4291 for (size_t j = 0; j < tiles.size(); ++j) {
4292 if (prioritized_tiles[tiles[j]].is_occluded()) {
4293 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4294 tiles[j]->content_rect(), 1.0f / tiles[j]->contents_scale());
4295 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x());
4296 occluded_tile_count++;
4300 switch (i) {
4301 case 0:
4302 EXPECT_EQ(occluded_tile_count, 30);
4303 break;
4304 case 1:
4305 EXPECT_EQ(occluded_tile_count, 5);
4306 break;
4307 case 2:
4308 EXPECT_EQ(occluded_tile_count, 4);
4309 break;
4310 case 4:
4311 case 3:
4312 EXPECT_EQ(occluded_tile_count, 2);
4313 break;
4314 default:
4315 NOTREACHED();
4320 TEST_F(OcclusionTrackingPictureLayerImplTest, DifferentOcclusionOnTrees) {
4321 gfx::Size tile_size(102, 102);
4322 gfx::Size layer_bounds(1000, 1000);
4323 gfx::Size viewport_size(1000, 1000);
4324 gfx::Point occluding_layer_position(310, 0);
4325 gfx::Rect invalidation_rect(230, 230, 102, 102);
4327 scoped_refptr<FakePicturePileImpl> pending_pile =
4328 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4329 scoped_refptr<FakePicturePileImpl> active_pile =
4330 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4332 host_impl_.SetViewportSize(viewport_size);
4333 SetupPendingTree(active_pile);
4335 // Partially occlude the active layer.
4336 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2));
4337 LayerImpl* layer1 = pending_layer_->children()[0];
4338 layer1->SetBounds(layer_bounds);
4339 layer1->SetDrawsContent(true);
4340 layer1->SetContentsOpaque(true);
4341 layer1->SetPosition(occluding_layer_position);
4343 ActivateTree();
4345 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4346 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4347 auto prioritized_tiles =
4348 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
4350 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4351 gfx::Rect(layer_bounds));
4352 iter; ++iter) {
4353 if (!*iter)
4354 continue;
4355 const Tile* tile = *iter;
4357 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4358 tile->content_rect(), 1.0f / tile->contents_scale());
4359 // Tiles are occluded on the active tree iff they lie beneath the
4360 // occluding layer.
4361 EXPECT_EQ(prioritized_tiles[tile].is_occluded(),
4362 scaled_content_rect.x() >= occluding_layer_position.x());
4366 // Partially invalidate the pending layer.
4367 SetupPendingTreeWithInvalidation(pending_pile, invalidation_rect);
4369 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4370 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4371 auto prioritized_tiles =
4372 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
4374 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4375 gfx::Rect(layer_bounds));
4376 iter; ++iter) {
4377 if (!*iter)
4378 continue;
4379 const Tile* tile = *iter;
4380 EXPECT_TRUE(tile);
4382 // All tiles are unoccluded, because the pending tree has no occlusion.
4383 EXPECT_FALSE(prioritized_tiles[tile].is_occluded());
4385 if (tiling->resolution() == LOW_RESOLUTION) {
4386 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinTiling(tiling));
4387 continue;
4390 Tile* twin_tile = active_layer_->GetPendingOrActiveTwinTiling(tiling)
4391 ->TileAt(iter.i(), iter.j());
4392 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4393 tile->content_rect(), 1.0f / tile->contents_scale());
4395 if (scaled_content_rect.Intersects(invalidation_rect)) {
4396 // Tiles inside the invalidation rect exist on both trees.
4397 EXPECT_TRUE(twin_tile);
4398 EXPECT_NE(tile, twin_tile);
4399 } else {
4400 // Tiles outside the invalidation rect only exist on the active tree.
4401 EXPECT_FALSE(twin_tile);
4407 TEST_F(OcclusionTrackingPictureLayerImplTest,
4408 OccludedTilesConsideredDuringEviction) {
4409 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4411 gfx::Size tile_size(102, 102);
4412 gfx::Size layer_bounds(1000, 1000);
4413 gfx::Size viewport_size(1000, 1000);
4414 gfx::Point pending_occluding_layer_position(310, 0);
4415 gfx::Point active_occluding_layer_position(0, 310);
4416 gfx::Rect invalidation_rect(230, 230, 152, 152);
4418 host_impl_.SetViewportSize(viewport_size);
4419 host_impl_.SetDeviceScaleFactor(2.f);
4421 scoped_refptr<FakePicturePileImpl> pending_pile =
4422 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4423 scoped_refptr<FakePicturePileImpl> active_pile =
4424 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4426 SetupPendingTreeWithFixedTileSize(active_pile, tile_size, Region());
4428 // Partially occlude the active layer.
4429 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2));
4430 LayerImpl* active_occluding_layer = pending_layer_->children()[0];
4431 active_occluding_layer->SetBounds(layer_bounds);
4432 active_occluding_layer->SetDrawsContent(true);
4433 active_occluding_layer->SetContentsOpaque(true);
4434 active_occluding_layer->SetPosition(active_occluding_layer_position);
4436 ActivateTree();
4438 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4439 // are created.
4440 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, invalidation_rect);
4442 // Partially occlude the pending layer in a different way.
4443 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 3));
4444 LayerImpl* pending_occluding_layer = pending_layer_->children()[0];
4445 pending_occluding_layer->SetBounds(layer_bounds);
4446 pending_occluding_layer->SetDrawsContent(true);
4447 pending_occluding_layer->SetContentsOpaque(true);
4448 pending_occluding_layer->SetPosition(pending_occluding_layer_position);
4450 EXPECT_EQ(1u, pending_layer_->num_tilings());
4451 EXPECT_EQ(2u, active_layer_->num_tilings());
4453 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4454 // UpdateDrawProperties with the occluding layer.
4455 bool update_lcd_text = false;
4456 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4458 // The expected number of occluded tiles on each of the 2 tilings for each of
4459 // the 3 tree priorities.
4460 size_t expected_occluded_tile_count_on_pending[] = {4u, 0u};
4461 size_t expected_occluded_tile_count_on_active[] = {12u, 3u};
4462 size_t total_expected_occluded_tile_count_on_trees[] = {15u, 4u};
4464 // Verify number of occluded tiles on the pending layer for each tiling.
4465 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4466 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4467 auto prioritized_tiles =
4468 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
4470 size_t occluded_tile_count_on_pending = 0u;
4471 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4472 gfx::Rect(layer_bounds));
4473 iter; ++iter) {
4474 Tile* tile = *iter;
4476 if (invalidation_rect.Intersects(iter.geometry_rect()))
4477 EXPECT_TRUE(tile);
4478 else
4479 EXPECT_FALSE(tile);
4481 if (!tile)
4482 continue;
4483 if (prioritized_tiles[tile].is_occluded())
4484 occluded_tile_count_on_pending++;
4486 EXPECT_EQ(expected_occluded_tile_count_on_pending[i],
4487 occluded_tile_count_on_pending)
4488 << tiling->contents_scale();
4491 // Verify number of occluded tiles on the active layer for each tiling.
4492 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4493 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4494 auto prioritized_tiles =
4495 tiling->UpdateAndGetAllPrioritizedTilesForTesting();
4497 size_t occluded_tile_count_on_active = 0u;
4498 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4499 gfx::Rect(layer_bounds));
4500 iter; ++iter) {
4501 Tile* tile = *iter;
4503 if (!tile)
4504 continue;
4505 if (prioritized_tiles[tile].is_occluded())
4506 occluded_tile_count_on_active++;
4508 EXPECT_EQ(expected_occluded_tile_count_on_active[i],
4509 occluded_tile_count_on_active)
4510 << i;
4513 std::vector<Tile*> all_tiles;
4514 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4515 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4516 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
4517 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end());
4519 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4520 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4521 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
4522 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end());
4525 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
4527 VerifyEvictionConsidersOcclusion(
4528 pending_layer_, PENDING_TREE,
4529 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__);
4530 VerifyEvictionConsidersOcclusion(
4531 active_layer_, ACTIVE_TREE,
4532 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__);
4534 // Repeat the tests without valid active tree priorities.
4535 active_layer_->set_has_valid_tile_priorities(false);
4536 VerifyEvictionConsidersOcclusion(
4537 pending_layer_, PENDING_TREE,
4538 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__);
4539 VerifyEvictionConsidersOcclusion(
4540 active_layer_, ACTIVE_TREE,
4541 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__);
4542 active_layer_->set_has_valid_tile_priorities(true);
4544 // Repeat the tests without valid pending tree priorities.
4545 pending_layer_->set_has_valid_tile_priorities(false);
4546 VerifyEvictionConsidersOcclusion(
4547 active_layer_, ACTIVE_TREE,
4548 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__);
4549 VerifyEvictionConsidersOcclusion(
4550 pending_layer_, PENDING_TREE,
4551 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__);
4552 pending_layer_->set_has_valid_tile_priorities(true);
4555 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) {
4556 gfx::Size tile_size(102, 102);
4557 gfx::Size layer_bounds(1000, 1000);
4559 scoped_refptr<FakePicturePileImpl> pile =
4560 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4561 SetupPendingTree(pile);
4562 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer());
4564 ActivateTree();
4565 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4567 SetupPendingTree(pile);
4568 EXPECT_TRUE(pending_layer_->GetPendingOrActiveTwinLayer());
4569 EXPECT_TRUE(active_layer_->GetPendingOrActiveTwinLayer());
4570 EXPECT_EQ(pending_layer_, active_layer_->GetPendingOrActiveTwinLayer());
4571 EXPECT_EQ(active_layer_, pending_layer_->GetPendingOrActiveTwinLayer());
4573 ActivateTree();
4574 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4576 // Make an empty pending tree.
4577 host_impl_.CreatePendingTree();
4578 host_impl_.pending_tree()->DetachLayerTree();
4579 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4582 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) {
4583 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4585 gfx::Size tile_size(100, 100);
4586 gfx::Size layer_bounds(200, 200);
4587 gfx::Rect layer_rect(layer_bounds);
4589 FakeContentLayerClient client;
4590 scoped_refptr<PictureLayer> layer =
4591 PictureLayer::Create(layer_settings_, &client);
4592 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
4593 TestTaskGraphRunner task_graph_runner;
4594 scoped_ptr<FakeLayerTreeHost> host =
4595 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
4596 host->SetRootLayer(layer);
4597 RecordingSource* recording_source = layer->GetRecordingSourceForTesting();
4599 int frame_number = 0;
4601 client.set_fill_with_nonsolid_color(!test_for_solid);
4603 Region invalidation(layer_rect);
4604 recording_source->UpdateAndExpandInvalidation(
4605 &client, &invalidation, layer_bounds, layer_rect, frame_number++,
4606 RecordingSource::RECORD_NORMALLY);
4608 scoped_refptr<RasterSource> pending_raster_source =
4609 recording_source->CreateRasterSource(true);
4611 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
4612 ActivateTree();
4614 if (test_for_solid) {
4615 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
4616 } else {
4617 ASSERT_TRUE(active_layer_->tilings());
4618 ASSERT_GT(active_layer_->tilings()->num_tilings(), 0u);
4619 std::vector<Tile*> tiles =
4620 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
4621 EXPECT_FALSE(tiles.empty());
4622 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
4625 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
4626 AppendQuadsData data;
4627 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
4628 active_layer_->AppendQuads(render_pass.get(), &data);
4629 active_layer_->DidDraw(nullptr);
4631 DrawQuad::Material expected = test_for_solid
4632 ? DrawQuad::Material::SOLID_COLOR
4633 : DrawQuad::Material::TILED_CONTENT;
4634 EXPECT_EQ(expected, render_pass->quad_list.front()->material);
4637 TEST_F(PictureLayerImplTest, DrawSolidQuads) {
4638 TestQuadsForSolidColor(true);
4641 TEST_F(PictureLayerImplTest, DrawNonSolidQuads) {
4642 TestQuadsForSolidColor(false);
4645 TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) {
4646 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4648 gfx::Size tile_size(100, 100);
4649 gfx::Size layer_bounds(200, 200);
4650 gfx::Rect layer_rect(layer_bounds);
4652 FakeContentLayerClient client;
4653 scoped_refptr<PictureLayer> layer =
4654 PictureLayer::Create(layer_settings_, &client);
4655 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
4656 TestTaskGraphRunner task_graph_runner;
4657 scoped_ptr<FakeLayerTreeHost> host =
4658 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
4659 host->SetRootLayer(layer);
4660 RecordingSource* recording_source = layer->GetRecordingSourceForTesting();
4662 int frame_number = 0;
4664 client.set_fill_with_nonsolid_color(true);
4666 Region invalidation1(layer_rect);
4667 recording_source->UpdateAndExpandInvalidation(
4668 &client, &invalidation1, layer_bounds, layer_rect, frame_number++,
4669 RecordingSource::RECORD_NORMALLY);
4671 scoped_refptr<RasterSource> raster_source1 =
4672 recording_source->CreateRasterSource(true);
4674 SetupPendingTree(raster_source1);
4675 ActivateTree();
4676 bool update_lcd_text = false;
4677 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
4679 // We've started with a solid layer that contains some tilings.
4680 ASSERT_TRUE(active_layer_->tilings());
4681 EXPECT_NE(0u, active_layer_->tilings()->num_tilings());
4683 client.set_fill_with_nonsolid_color(false);
4685 Region invalidation2(layer_rect);
4686 recording_source->UpdateAndExpandInvalidation(
4687 &client, &invalidation2, layer_bounds, layer_rect, frame_number++,
4688 RecordingSource::RECORD_NORMALLY);
4690 scoped_refptr<RasterSource> raster_source2 =
4691 recording_source->CreateRasterSource(true);
4693 SetupPendingTree(raster_source2);
4694 ActivateTree();
4696 // We've switched to a solid color, so we should end up with no tilings.
4697 ASSERT_TRUE(active_layer_->tilings());
4698 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
4701 TEST_F(PictureLayerImplTest, ChangeInViewportAllowsTilingUpdates) {
4702 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4704 gfx::Size tile_size(100, 100);
4705 gfx::Size layer_bounds(400, 4000);
4707 scoped_refptr<FakePicturePileImpl> pending_pile =
4708 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4709 scoped_refptr<FakePicturePileImpl> active_pile =
4710 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4712 SetupTrees(pending_pile, active_pile);
4714 Region invalidation;
4715 gfx::Rect viewport = gfx::Rect(0, 0, 100, 100);
4716 gfx::Transform transform;
4718 host_impl_.SetRequiresHighResToDraw();
4720 // Update tiles.
4721 pending_layer_->draw_properties().visible_layer_rect = viewport;
4722 pending_layer_->draw_properties().screen_space_transform = transform;
4723 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
4724 false);
4725 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
4727 // Ensure we can't activate.
4728 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
4730 // Now in the same frame, move the viewport (this can happen during
4731 // animation).
4732 viewport = gfx::Rect(0, 2000, 100, 100);
4734 // Update tiles.
4735 pending_layer_->draw_properties().visible_layer_rect = viewport;
4736 pending_layer_->draw_properties().screen_space_transform = transform;
4737 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, 0.f,
4738 false);
4739 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting();
4741 // Make sure all viewport tiles (viewport from the tiling) are ready to draw.
4742 std::vector<Tile*> tiles;
4743 for (PictureLayerTiling::CoverageIterator iter(
4744 pending_layer_->HighResTiling(),
4745 1.f,
4746 pending_layer_->HighResTiling()->GetCurrentVisibleRectForTesting());
4747 iter;
4748 ++iter) {
4749 if (*iter)
4750 tiles.push_back(*iter);
4752 for (PictureLayerTiling::CoverageIterator iter(
4753 active_layer_->HighResTiling(), 1.f,
4754 active_layer_->HighResTiling()->GetCurrentVisibleRectForTesting());
4755 iter; ++iter) {
4756 if (*iter)
4757 tiles.push_back(*iter);
4760 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
4762 // Ensure we can activate.
4763 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
4766 TEST_F(PictureLayerImplTest, CloneMissingRecordings) {
4767 gfx::Size tile_size(100, 100);
4768 gfx::Size layer_bounds(400, 400);
4770 scoped_refptr<FakePicturePileImpl> filled_pile =
4771 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4773 scoped_ptr<FakePicturePile> partial_recording =
4774 FakePicturePile::CreateEmptyPile(tile_size, layer_bounds);
4775 for (int i = 1; i < partial_recording->tiling().num_tiles_x(); ++i) {
4776 for (int j = 1; j < partial_recording->tiling().num_tiles_y(); ++j)
4777 partial_recording->AddRecordingAt(i, j);
4779 scoped_refptr<FakePicturePileImpl> partial_pile =
4780 FakePicturePileImpl::CreateFromPile(partial_recording.get(), nullptr);
4782 SetupPendingTreeWithFixedTileSize(filled_pile, tile_size, Region());
4783 ActivateTree();
4785 PictureLayerTiling* pending_tiling = old_pending_layer_->HighResTiling();
4786 PictureLayerTiling* active_tiling = active_layer_->HighResTiling();
4788 // We should have all tiles on active, and none on pending.
4789 EXPECT_EQ(0u, pending_tiling->AllTilesForTesting().size());
4790 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size());
4792 // Now put a partially-recorded pile on the pending tree (and invalidate
4793 // everything, since the main thread PicturePile will invalidate dropped
4794 // recordings). This will cause us to be missing some tiles.
4795 SetupPendingTreeWithFixedTileSize(partial_pile, tile_size,
4796 Region(gfx::Rect(layer_bounds)));
4797 EXPECT_EQ(3u * 3u, pending_tiling->AllTilesForTesting().size());
4798 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
4799 EXPECT_FALSE(pending_tiling->TileAt(1, 1));
4800 EXPECT_TRUE(pending_tiling->TileAt(2, 2));
4802 // Active is not affected yet.
4803 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size());
4805 // Activate the tree. The same tiles go missing on the active tree.
4806 ActivateTree();
4807 EXPECT_EQ(3u * 3u, active_tiling->AllTilesForTesting().size());
4808 EXPECT_FALSE(active_tiling->TileAt(0, 0));
4809 EXPECT_FALSE(active_tiling->TileAt(1, 1));
4810 EXPECT_TRUE(active_tiling->TileAt(2, 2));
4812 // Now put a full recording on the pending tree again. We'll get all our tiles
4813 // back.
4814 SetupPendingTreeWithFixedTileSize(filled_pile, tile_size,
4815 Region(gfx::Rect(layer_bounds)));
4816 EXPECT_EQ(5u * 5u, pending_tiling->AllTilesForTesting().size());
4817 Tile* tile00 = pending_tiling->TileAt(0, 0);
4818 Tile* tile11 = pending_tiling->TileAt(1, 1);
4819 Tile* tile22 = pending_tiling->TileAt(2, 2);
4821 // Active is not affected yet.
4822 EXPECT_EQ(3u * 3u, active_tiling->AllTilesForTesting().size());
4824 // Activate the tree. The tiles are moved to the active tree.
4825 ActivateTree();
4826 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size());
4827 EXPECT_EQ(tile00, active_tiling->TileAt(0, 0));
4828 EXPECT_EQ(tile11, active_tiling->TileAt(1, 1));
4829 EXPECT_EQ(tile22, active_tiling->TileAt(2, 2));
4832 TEST_F(PictureLayerImplTest, ScrollPastLiveTilesRectAndBack) {
4833 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4835 gfx::Size tile_size(102, 102);
4836 gfx::Size layer_bounds(100, 100);
4837 gfx::Size viewport_size(100, 100);
4839 host_impl_.SetViewportSize(viewport_size);
4840 host_impl_.SetDeviceScaleFactor(1.f);
4842 scoped_refptr<FakePicturePileImpl> pending_pile =
4843 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4844 scoped_refptr<FakePicturePileImpl> active_pile =
4845 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4847 SetupPendingTreeWithFixedTileSize(active_pile, tile_size, Region());
4849 ActivateTree();
4850 EXPECT_TRUE(active_layer_->HighResTiling()->has_tiles());
4852 host_impl_.SetExternalDrawConstraints(
4853 gfx::Transform(), // transform
4854 gfx::Rect(), // clip
4855 gfx::Rect(), // viewport
4856 gfx::Rect(0, 5000, 100, 100), // viewport_rect_for_tile_priority
4857 gfx::Transform(), // transform_for_tile_priority
4858 false);
4860 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, gfx::Rect());
4862 EXPECT_FALSE(pending_layer_->HighResTiling()->has_tiles());
4863 EXPECT_TRUE(pending_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4864 ActivateTree();
4865 EXPECT_FALSE(active_layer_->HighResTiling()->has_tiles());
4866 EXPECT_TRUE(active_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4868 host_impl_.SetExternalDrawConstraints(
4869 gfx::Transform(), // transform
4870 gfx::Rect(), // clip
4871 gfx::Rect(), // viewport
4872 gfx::Rect(0, 110, 100, 100), // viewport_rect_for_tile_priority
4873 gfx::Transform(), // transform_for_tile_priority
4874 false);
4876 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, gfx::Rect());
4878 EXPECT_FALSE(pending_layer_->HighResTiling()->has_tiles());
4879 EXPECT_FALSE(pending_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4880 ActivateTree();
4881 EXPECT_TRUE(active_layer_->HighResTiling()->has_tiles());
4882 EXPECT_FALSE(active_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4885 TEST_F(PictureLayerImplTest, ScrollPropagatesToPending) {
4886 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4888 gfx::Size tile_size(102, 102);
4889 gfx::Size layer_bounds(1000, 1000);
4890 gfx::Size viewport_size(100, 100);
4892 host_impl_.SetViewportSize(viewport_size);
4893 host_impl_.SetDeviceScaleFactor(1.f);
4895 scoped_refptr<FakePicturePileImpl> pending_pile =
4896 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4897 scoped_refptr<FakePicturePileImpl> active_pile =
4898 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4900 SetupTrees(pending_pile, active_pile);
4902 active_layer_->SetCurrentScrollOffset(gfx::ScrollOffset(0.0, 50.0));
4903 host_impl_.active_tree()->UpdateDrawProperties(false);
4904 EXPECT_EQ("0,50 100x100", active_layer_->HighResTiling()
4905 ->GetCurrentVisibleRectForTesting()
4906 .ToString());
4908 EXPECT_EQ("0,0 100x100", pending_layer_->HighResTiling()
4909 ->GetCurrentVisibleRectForTesting()
4910 .ToString());
4911 host_impl_.pending_tree()->UpdateDrawProperties(false);
4912 EXPECT_EQ("0,50 100x100", pending_layer_->HighResTiling()
4913 ->GetCurrentVisibleRectForTesting()
4914 .ToString());
4917 TEST_F(PictureLayerImplTest, UpdateLCDInvalidatesPendingTree) {
4918 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4920 gfx::Size tile_size(102, 102);
4921 gfx::Size layer_bounds(100, 100);
4922 gfx::Size viewport_size(100, 100);
4924 host_impl_.SetViewportSize(viewport_size);
4925 host_impl_.SetDeviceScaleFactor(1.f);
4927 scoped_refptr<FakePicturePileImpl> pending_pile =
4928 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4929 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
4931 EXPECT_TRUE(pending_layer_->RasterSourceUsesLCDText());
4932 EXPECT_TRUE(pending_layer_->HighResTiling()->has_tiles());
4933 std::vector<Tile*> tiles =
4934 pending_layer_->HighResTiling()->AllTilesForTesting();
4935 auto prioritized_tiles = pending_layer_->HighResTiling()
4936 ->UpdateAndGetAllPrioritizedTilesForTesting();
4938 for (Tile* tile : tiles)
4939 EXPECT_EQ(pending_layer_->raster_source(),
4940 prioritized_tiles[tile].raster_source());
4942 pending_layer_->draw_properties().can_use_lcd_text = false;
4943 pending_layer_->UpdateCanUseLCDTextAfterCommit();
4945 EXPECT_FALSE(pending_layer_->RasterSourceUsesLCDText());
4946 EXPECT_NE(pending_pile.get(), pending_layer_->raster_source());
4947 EXPECT_TRUE(pending_layer_->HighResTiling()->has_tiles());
4948 tiles = pending_layer_->HighResTiling()->AllTilesForTesting();
4949 prioritized_tiles = pending_layer_->HighResTiling()
4950 ->UpdateAndGetAllPrioritizedTilesForTesting();
4951 for (Tile* tile : tiles)
4952 EXPECT_EQ(pending_layer_->raster_source(),
4953 prioritized_tiles[tile].raster_source());
4956 TEST_F(PictureLayerImplTest, TilingAllTilesDone) {
4957 gfx::Size tile_size = host_impl_.settings().default_tile_size;
4958 size_t tile_mem = 4 * tile_size.width() * tile_size.height();
4959 gfx::Size layer_bounds(1000, 1000);
4961 // Create tiles.
4962 scoped_refptr<FakePicturePileImpl> pending_pile =
4963 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4964 SetupPendingTree(pending_pile);
4965 pending_layer_->SetBounds(layer_bounds);
4966 ActivateTree();
4967 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
4968 active_layer_->HighResTiling()->AllTilesForTesting());
4969 host_impl_.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES);
4971 EXPECT_FALSE(active_layer_->HighResTiling()->all_tiles_done());
4974 // Set a memory policy that will fit all tiles.
4975 size_t max_tiles = 16;
4976 size_t memory_limit = max_tiles * tile_mem;
4977 ManagedMemoryPolicy policy(memory_limit,
4978 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
4979 max_tiles);
4980 host_impl_.SetMemoryPolicy(policy);
4981 host_impl_.PrepareTiles();
4983 EXPECT_TRUE(active_layer_->HighResTiling()->all_tiles_done());
4987 // Set a memory policy that will cause tile eviction.
4988 size_t max_tiles = 1;
4989 size_t memory_limit = max_tiles * tile_mem;
4990 ManagedMemoryPolicy policy(memory_limit,
4991 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
4992 max_tiles);
4993 host_impl_.SetMemoryPolicy(policy);
4994 host_impl_.PrepareTiles();
4996 EXPECT_FALSE(active_layer_->HighResTiling()->all_tiles_done());
5000 class TileSizeSettings : public PictureLayerImplTestSettings {
5001 public:
5002 TileSizeSettings() {
5003 default_tile_size = gfx::Size(100, 100);
5004 max_untiled_layer_size = gfx::Size(200, 200);
5008 class TileSizeTest : public PictureLayerImplTest {
5009 public:
5010 TileSizeTest() : PictureLayerImplTest(TileSizeSettings()) {}
5013 TEST_F(TileSizeTest, TileSizes) {
5014 host_impl_.CreatePendingTree();
5016 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
5017 scoped_ptr<FakePictureLayerImpl> layer =
5018 FakePictureLayerImpl::Create(pending_tree, id_);
5020 host_impl_.SetViewportSize(gfx::Size(1000, 1000));
5021 gfx::Size result;
5023 host_impl_.SetContentIsSuitableForGpuRasterization(true);
5024 host_impl_.SetHasGpuRasterizationTrigger(false);
5025 EXPECT_EQ(host_impl_.gpu_rasterization_status(),
5026 GpuRasterizationStatus::OFF_VIEWPORT);
5028 // Default tile-size for large layers.
5029 result = layer->CalculateTileSize(gfx::Size(10000, 10000));
5030 EXPECT_EQ(result.width(), 100);
5031 EXPECT_EQ(result.height(), 100);
5032 // Don't tile and round-up, when under max_untiled_layer_size.
5033 result = layer->CalculateTileSize(gfx::Size(42, 42));
5034 EXPECT_EQ(result.width(), 64);
5035 EXPECT_EQ(result.height(), 64);
5036 result = layer->CalculateTileSize(gfx::Size(191, 191));
5037 EXPECT_EQ(result.width(), 192);
5038 EXPECT_EQ(result.height(), 192);
5039 result = layer->CalculateTileSize(gfx::Size(199, 199));
5040 EXPECT_EQ(result.width(), 200);
5041 EXPECT_EQ(result.height(), 200);
5043 // Gpu-rasterization uses 25% viewport-height tiles.
5044 // The +2's below are for border texels.
5045 host_impl_.SetHasGpuRasterizationTrigger(true);
5046 EXPECT_EQ(host_impl_.gpu_rasterization_status(), GpuRasterizationStatus::ON);
5047 host_impl_.SetViewportSize(gfx::Size(2000, 2000));
5049 layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size());
5050 result = layer->CalculateTileSize(gfx::Size(10000, 10000));
5051 EXPECT_EQ(result.width(), 2000 + 2 * PictureLayerTiling::kBorderTexels);
5052 EXPECT_EQ(result.height(), 500 + 2);
5054 // Clamp and round-up, when smaller than viewport.
5055 // Tile-height doubles to 50% when width shrinks to <= 50%.
5056 host_impl_.SetViewportSize(gfx::Size(1000, 1000));
5057 layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size());
5058 result = layer->CalculateTileSize(gfx::Size(447, 10000));
5059 EXPECT_EQ(result.width(), 448);
5060 EXPECT_EQ(result.height(), 500 + 2);
5062 // Largest layer is 50% of viewport width (rounded up), and
5063 // 50% of viewport in height.
5064 result = layer->CalculateTileSize(gfx::Size(447, 400));
5065 EXPECT_EQ(result.width(), 448);
5066 EXPECT_EQ(result.height(), 448);
5067 result = layer->CalculateTileSize(gfx::Size(500, 499));
5068 EXPECT_EQ(result.width(), 512);
5069 EXPECT_EQ(result.height(), 500 + 2);
5072 TEST_F(NoLowResPictureLayerImplTest, LowResWasHighResCollision) {
5073 gfx::Size tile_size(400, 400);
5074 gfx::Size layer_bounds(1300, 1900);
5076 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
5078 scoped_refptr<FakePicturePileImpl> pending_pile =
5079 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
5080 scoped_refptr<FakePicturePileImpl> active_pile =
5081 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
5083 // Set up the high and low res tilings before pinch zoom.
5084 SetupTrees(pending_pile, active_pile);
5085 ResetTilingsAndRasterScales();
5087 float page_scale = 2.f;
5088 SetContentsScaleOnBothLayers(page_scale, 1.0f, page_scale, 1.0f, 0.f, false);
5089 EXPECT_BOTH_EQ(num_tilings(), 1u);
5090 EXPECT_BOTH_EQ(tilings()->tiling_at(0)->contents_scale(), page_scale);
5092 host_impl_.PinchGestureBegin();
5094 // Zoom out to exactly the low res factor so that the previous high res
5095 // would be equal to the current low res (if it were possible to have one).
5096 float zoomed = page_scale / low_res_factor;
5097 SetContentsScaleOnBothLayers(zoomed, 1.0f, zoomed, 1.0f, 0.f, false);
5098 EXPECT_EQ(1u, pending_layer_->num_tilings());
5099 EXPECT_EQ(zoomed, pending_layer_->tilings()->tiling_at(0)->contents_scale());
5102 TEST_F(PictureLayerImplTest, HighResWasLowResCollision) {
5103 gfx::Size tile_size(400, 400);
5104 gfx::Size layer_bounds(1300, 1900);
5106 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
5108 scoped_refptr<FakePicturePileImpl> pending_pile =
5109 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
5110 scoped_refptr<FakePicturePileImpl> active_pile =
5111 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
5113 // Set up the high and low res tilings before pinch zoom.
5114 SetupTrees(pending_pile, active_pile);
5115 ResetTilingsAndRasterScales();
5117 float page_scale = 4.f;
5118 float low_res = page_scale * low_res_factor;
5119 float extra_low_res = low_res * low_res_factor;
5120 SetupDrawPropertiesAndUpdateTiles(active_layer_, page_scale, 1.0f, page_scale,
5121 1.0f, 0.f, false);
5122 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
5123 EXPECT_EQ(page_scale,
5124 active_layer_->tilings()->tiling_at(0)->contents_scale());
5125 EXPECT_EQ(low_res, active_layer_->tilings()->tiling_at(1)->contents_scale());
5127 // Grab a current low res tile.
5128 PictureLayerTiling* old_low_res_tiling =
5129 active_layer_->tilings()->tiling_at(1);
5130 Tile* old_low_res_tile = active_layer_->tilings()->tiling_at(1)->TileAt(0, 0);
5132 // The tiling knows it has low res content.
5133 EXPECT_TRUE(active_layer_->tilings()
5134 ->tiling_at(1)
5135 ->may_contain_low_resolution_tiles());
5137 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
5139 // Zoom in to exactly the low res factor so that the previous low res
5140 // would be equal to the current high res.
5141 SetupDrawPropertiesAndUpdateTiles(active_layer_, low_res, 1.0f, low_res, 1.0f,
5142 0.f, false);
5143 // 3 tilings. The old high res, the new high res (old low res) and the new low
5144 // res.
5145 EXPECT_EQ(3u, active_layer_->num_tilings());
5147 PictureLayerTilingSet* tilings = active_layer_->tilings();
5148 EXPECT_EQ(page_scale, tilings->tiling_at(0)->contents_scale());
5149 EXPECT_EQ(low_res, tilings->tiling_at(1)->contents_scale());
5150 EXPECT_EQ(extra_low_res, tilings->tiling_at(2)->contents_scale());
5152 EXPECT_EQ(NON_IDEAL_RESOLUTION, tilings->tiling_at(0)->resolution());
5153 EXPECT_EQ(HIGH_RESOLUTION, tilings->tiling_at(1)->resolution());
5154 EXPECT_EQ(LOW_RESOLUTION, tilings->tiling_at(2)->resolution());
5156 // The old low res tile was destroyed and replaced.
5157 EXPECT_EQ(old_low_res_tiling, tilings->tiling_at(1));
5158 EXPECT_NE(old_low_res_tile, tilings->tiling_at(1)->TileAt(0, 0));
5159 EXPECT_TRUE(tilings->tiling_at(1)->TileAt(0, 0));
5161 // New high res tiling.
5162 EXPECT_FALSE(tilings->tiling_at(0)->may_contain_low_resolution_tiles());
5163 // New low res tiling.
5164 EXPECT_TRUE(tilings->tiling_at(2)->may_contain_low_resolution_tiles());
5166 // This tiling will be high res now, it won't contain low res content since it
5167 // was all destroyed.
5168 EXPECT_FALSE(tilings->tiling_at(1)->may_contain_low_resolution_tiles());
5171 } // namespace
5172 } // namespace cc