Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / cc / layers / picture_layer_impl_unittest.cc
blob67ca4f598d6691714ff0d5df735f8851c2cf2e08
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/resources/tiling_set_raster_queue_all.h"
20 #include "cc/resources/tiling_set_raster_queue_required.h"
21 #include "cc/test/begin_frame_args_test.h"
22 #include "cc/test/fake_content_layer_client.h"
23 #include "cc/test/fake_impl_proxy.h"
24 #include "cc/test/fake_layer_tree_host_impl.h"
25 #include "cc/test/fake_output_surface.h"
26 #include "cc/test/fake_picture_layer_impl.h"
27 #include "cc/test/fake_picture_pile_impl.h"
28 #include "cc/test/geometry_test_utils.h"
29 #include "cc/test/impl_side_painting_settings.h"
30 #include "cc/test/layer_test_common.h"
31 #include "cc/test/test_shared_bitmap_manager.h"
32 #include "cc/test/test_task_graph_runner.h"
33 #include "cc/test/test_web_graphics_context_3d.h"
34 #include "cc/trees/layer_tree_impl.h"
35 #include "testing/gtest/include/gtest/gtest.h"
36 #include "ui/gfx/geometry/rect_conversions.h"
37 #include "ui/gfx/geometry/size_conversions.h"
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 class MockCanvas : public SkCanvas {
55 public:
56 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {}
58 void onDrawRect(const SkRect& rect, const SkPaint& paint) override {
59 // Capture calls before SkCanvas quickReject() kicks in.
60 rects_.push_back(rect);
63 std::vector<SkRect> rects_;
66 class NoLowResTilingsSettings : public ImplSidePaintingSettings {};
68 class LowResTilingsSettings : public ImplSidePaintingSettings {
69 public:
70 LowResTilingsSettings() { create_low_res_tiling = true; }
73 class PictureLayerImplTest : public testing::Test {
74 public:
75 PictureLayerImplTest()
76 : proxy_(base::ThreadTaskRunnerHandle::Get()),
77 host_impl_(LowResTilingsSettings(),
78 &proxy_,
79 &shared_bitmap_manager_,
80 &task_graph_runner_),
81 root_id_(6),
82 id_(7),
83 pending_layer_(nullptr),
84 old_pending_layer_(nullptr),
85 active_layer_(nullptr) {
86 host_impl_.SetViewportSize(gfx::Size(10000, 10000));
89 explicit PictureLayerImplTest(const LayerTreeSettings& settings)
90 : proxy_(base::ThreadTaskRunnerHandle::Get()),
91 host_impl_(settings,
92 &proxy_,
93 &shared_bitmap_manager_,
94 &task_graph_runner_),
95 root_id_(6),
96 id_(7) {
97 host_impl_.SetViewportSize(gfx::Size(10000, 10000));
100 ~PictureLayerImplTest() override {}
102 void SetUp() override { InitializeRenderer(); }
104 virtual void InitializeRenderer() {
105 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d());
108 void SetupDefaultTrees(const gfx::Size& layer_bounds) {
109 gfx::Size tile_size(100, 100);
111 scoped_refptr<FakePicturePileImpl> pending_pile =
112 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
113 scoped_refptr<FakePicturePileImpl> active_pile =
114 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
116 SetupTrees(pending_pile, active_pile);
119 void SetupDefaultTreesWithInvalidation(const gfx::Size& layer_bounds,
120 const Region& invalidation) {
121 gfx::Size tile_size(100, 100);
123 scoped_refptr<FakePicturePileImpl> pending_pile =
124 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
125 scoped_refptr<FakePicturePileImpl> active_pile =
126 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
128 SetupTreesWithInvalidation(pending_pile, active_pile, invalidation);
131 void ActivateTree() {
132 host_impl_.ActivateSyncTree();
133 CHECK(!host_impl_.pending_tree());
134 CHECK(host_impl_.recycle_tree());
135 old_pending_layer_ = pending_layer_;
136 pending_layer_ = nullptr;
137 active_layer_ = static_cast<FakePictureLayerImpl*>(
138 host_impl_.active_tree()->LayerById(id_));
140 bool update_lcd_text = false;
141 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
144 void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds,
145 const gfx::Size& tile_size,
146 const Region& invalidation) {
147 gfx::Size pile_tile_size(100, 100);
149 scoped_refptr<FakePicturePileImpl> pending_pile =
150 FakePicturePileImpl::CreateFilledPile(pile_tile_size, layer_bounds);
151 scoped_refptr<FakePicturePileImpl> active_pile =
152 FakePicturePileImpl::CreateFilledPile(pile_tile_size, layer_bounds);
154 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size,
155 invalidation);
158 void SetupTrees(
159 scoped_refptr<PicturePileImpl> pending_pile,
160 scoped_refptr<PicturePileImpl> active_pile) {
161 SetupPendingTree(active_pile);
162 ActivateTree();
163 SetupPendingTreeInternal(pending_pile, gfx::Size(), Region());
166 void SetupTreesWithInvalidation(scoped_refptr<PicturePileImpl> pending_pile,
167 scoped_refptr<PicturePileImpl> active_pile,
168 const Region& pending_invalidation) {
169 SetupPendingTreeInternal(active_pile, gfx::Size(), Region());
170 ActivateTree();
171 SetupPendingTreeInternal(pending_pile, gfx::Size(), pending_invalidation);
174 void SetupTreesWithFixedTileSize(scoped_refptr<PicturePileImpl> pending_pile,
175 scoped_refptr<PicturePileImpl> active_pile,
176 const gfx::Size& tile_size,
177 const Region& pending_invalidation) {
178 SetupPendingTreeInternal(active_pile, tile_size, Region());
179 ActivateTree();
180 SetupPendingTreeInternal(pending_pile, tile_size, pending_invalidation);
183 void SetupPendingTree(scoped_refptr<RasterSource> raster_source) {
184 SetupPendingTreeInternal(raster_source, gfx::Size(), Region());
187 void SetupPendingTreeWithInvalidation(
188 scoped_refptr<RasterSource> raster_source,
189 const Region& invalidation) {
190 SetupPendingTreeInternal(raster_source, gfx::Size(), invalidation);
193 void SetupPendingTreeWithFixedTileSize(
194 scoped_refptr<RasterSource> raster_source,
195 const gfx::Size& tile_size,
196 const Region& invalidation) {
197 SetupPendingTreeInternal(raster_source, tile_size, invalidation);
200 void SetupPendingTreeInternal(scoped_refptr<RasterSource> raster_source,
201 const gfx::Size& tile_size,
202 const Region& invalidation) {
203 host_impl_.CreatePendingTree();
204 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 100.f);
205 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
207 // Steal from the recycled tree if possible.
208 scoped_ptr<LayerImpl> pending_root = pending_tree->DetachLayerTree();
209 scoped_ptr<FakePictureLayerImpl> pending_layer;
210 DCHECK_IMPLIES(pending_root, pending_root->id() == root_id_);
211 if (!pending_root) {
212 pending_root = LayerImpl::Create(pending_tree, root_id_);
213 pending_layer = FakePictureLayerImpl::Create(pending_tree, id_);
214 if (!tile_size.IsEmpty())
215 pending_layer->set_fixed_tile_size(tile_size);
216 pending_layer->SetDrawsContent(true);
217 } else {
218 pending_layer.reset(static_cast<FakePictureLayerImpl*>(
219 pending_root->RemoveChild(pending_root->children()[0]).release()));
220 if (!tile_size.IsEmpty())
221 pending_layer->set_fixed_tile_size(tile_size);
223 pending_root->SetHasRenderSurface(true);
224 // The bounds() just mirror the pile size.
225 pending_layer->SetBounds(raster_source->GetSize());
226 pending_layer->SetContentBounds(raster_source->GetSize());
227 pending_layer->SetRasterSourceOnPending(raster_source, invalidation);
229 pending_root->AddChild(pending_layer.Pass());
230 pending_tree->SetRootLayer(pending_root.Pass());
232 pending_layer_ = static_cast<FakePictureLayerImpl*>(
233 host_impl_.pending_tree()->LayerById(id_));
235 // Add tilings/tiles for the layer.
236 bool update_lcd_text = false;
237 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
240 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer,
241 float ideal_contents_scale,
242 float device_scale_factor,
243 float page_scale_factor,
244 float maximum_animation_contents_scale,
245 bool animating_transform_to_screen) {
246 layer->draw_properties().ideal_contents_scale = ideal_contents_scale;
247 layer->draw_properties().device_scale_factor = device_scale_factor;
248 layer->draw_properties().page_scale_factor = page_scale_factor;
249 layer->draw_properties().maximum_animation_contents_scale =
250 maximum_animation_contents_scale;
251 layer->draw_properties().screen_space_transform_is_animating =
252 animating_transform_to_screen;
253 bool resourceless_software_draw = false;
254 layer->UpdateTiles(resourceless_software_draw);
256 static void VerifyAllTilesExistAndHavePile(
257 const PictureLayerTiling* tiling,
258 PicturePileImpl* pile) {
259 for (PictureLayerTiling::CoverageIterator iter(
260 tiling,
261 tiling->contents_scale(),
262 gfx::Rect(tiling->tiling_size()));
263 iter;
264 ++iter) {
265 EXPECT_TRUE(*iter);
266 EXPECT_EQ(pile, iter->raster_source());
270 void SetContentsScaleOnBothLayers(float contents_scale,
271 float device_scale_factor,
272 float page_scale_factor,
273 float maximum_animation_contents_scale,
274 bool animating_transform) {
275 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
276 contents_scale,
277 device_scale_factor,
278 page_scale_factor,
279 maximum_animation_contents_scale,
280 animating_transform);
282 SetupDrawPropertiesAndUpdateTiles(active_layer_,
283 contents_scale,
284 device_scale_factor,
285 page_scale_factor,
286 maximum_animation_contents_scale,
287 animating_transform);
290 void ResetTilingsAndRasterScales() {
291 if (pending_layer_) {
292 pending_layer_->ReleaseResources();
293 EXPECT_FALSE(pending_layer_->tilings());
294 pending_layer_->RecreateResources();
295 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
298 if (active_layer_) {
299 active_layer_->ReleaseResources();
300 EXPECT_FALSE(active_layer_->tilings());
301 active_layer_->RecreateResources();
302 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
306 size_t NumberOfTilesRequired(PictureLayerTiling* tiling) {
307 size_t num_required = 0;
308 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
309 for (size_t i = 0; i < tiles.size(); ++i) {
310 if (tiles[i]->required_for_activation())
311 num_required++;
313 return num_required;
316 void AssertAllTilesRequired(PictureLayerTiling* tiling) {
317 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
318 for (size_t i = 0; i < tiles.size(); ++i)
319 EXPECT_TRUE(tiles[i]->required_for_activation()) << "i: " << i;
320 EXPECT_GT(tiles.size(), 0u);
323 void AssertNoTilesRequired(PictureLayerTiling* tiling) {
324 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
325 for (size_t i = 0; i < tiles.size(); ++i)
326 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i;
327 EXPECT_GT(tiles.size(), 0u);
330 protected:
331 void TestQuadsForSolidColor(bool test_for_solid);
333 FakeImplProxy proxy_;
334 TestSharedBitmapManager shared_bitmap_manager_;
335 TestTaskGraphRunner task_graph_runner_;
336 FakeLayerTreeHostImpl host_impl_;
337 int root_id_;
338 int id_;
339 FakePictureLayerImpl* pending_layer_;
340 FakePictureLayerImpl* old_pending_layer_;
341 FakePictureLayerImpl* active_layer_;
343 private:
344 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest);
347 class NoLowResPictureLayerImplTest : public PictureLayerImplTest {
348 public:
349 NoLowResPictureLayerImplTest()
350 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
353 TEST_F(PictureLayerImplTest, TileGridAlignment) {
354 // Layer to span 4 raster tiles in x and in y
355 ImplSidePaintingSettings settings;
356 gfx::Size layer_size(settings.default_tile_size.width() * 7 / 2,
357 settings.default_tile_size.height() * 7 / 2);
359 scoped_refptr<FakePicturePileImpl> pending_pile =
360 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
362 scoped_ptr<FakePicturePile> active_recording =
363 FakePicturePile::CreateFilledPile(layer_size, layer_size);
364 scoped_refptr<FakePicturePileImpl> active_pile =
365 FakePicturePileImpl::CreateFromPile(active_recording.get(), nullptr);
367 SetupTrees(pending_pile, active_pile);
369 // Add 1x1 rects at the centers of each tile, then re-record pile contents
370 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
371 std::vector<Tile*> tiles =
372 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
373 EXPECT_EQ(16u, tiles.size());
374 std::vector<SkRect> rects;
375 std::vector<Tile*>::const_iterator tile_iter;
376 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
377 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint();
378 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1);
379 active_recording->add_draw_rect(rect);
380 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1));
383 // Force re-raster with newly injected content
384 active_recording->RemoveRecordingAt(0, 0);
385 active_recording->AddRecordingAt(0, 0);
387 scoped_refptr<FakePicturePileImpl> updated_active_pile =
388 FakePicturePileImpl::CreateFromPile(active_recording.get(), nullptr);
390 std::vector<SkRect>::const_iterator rect_iter = rects.begin();
391 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
392 MockCanvas mock_canvas(1000, 1000);
393 updated_active_pile->PlaybackToSharedCanvas(
394 &mock_canvas, (*tile_iter)->content_rect(), 1.0f);
396 // This test verifies that when drawing the contents of a specific tile
397 // at content scale 1.0, the playback canvas never receives content from
398 // neighboring tiles which indicates that the tile grid embedded in
399 // SkPicture is perfectly aligned with the compositor's tiles.
400 EXPECT_EQ(1u, mock_canvas.rects_.size());
401 EXPECT_EQ(*rect_iter, mock_canvas.rects_[0]);
402 rect_iter++;
406 TEST_F(PictureLayerImplTest, CloneNoInvalidation) {
407 gfx::Size tile_size(100, 100);
408 gfx::Size layer_bounds(400, 400);
410 scoped_refptr<FakePicturePileImpl> pending_pile =
411 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
412 scoped_refptr<FakePicturePileImpl> active_pile =
413 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
415 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
417 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
418 active_layer_->tilings()->num_tilings());
420 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
421 EXPECT_GT(tilings->num_tilings(), 0u);
422 for (size_t i = 0; i < tilings->num_tilings(); ++i)
423 EXPECT_TRUE(tilings->tiling_at(i)->AllTilesForTesting().empty());
426 TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) {
427 base::TimeTicks time_ticks;
428 time_ticks += base::TimeDelta::FromMilliseconds(1);
429 host_impl_.SetCurrentBeginFrameArgs(
430 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
431 gfx::Size tile_size(100, 100);
432 gfx::Size layer_bounds(400, 400);
434 scoped_refptr<FakePicturePileImpl> pending_pile =
435 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
436 scoped_refptr<FakePicturePileImpl> active_pile =
437 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
439 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
441 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
443 time_ticks += base::TimeDelta::FromMilliseconds(200);
444 host_impl_.SetCurrentBeginFrameArgs(
445 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
447 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the
448 // identify transform for tile priority.
449 bool resourceless_software_draw = false;
450 gfx::Rect viewport = gfx::Rect(layer_bounds),
451 viewport_rect_for_tile_priority = gfx::Rect(0, 0, 100, 100);
452 gfx::Transform transform, transform_for_tile_priority;
454 host_impl_.SetExternalDrawConstraints(transform,
455 viewport,
456 viewport,
457 viewport_rect_for_tile_priority,
458 transform_for_tile_priority,
459 resourceless_software_draw);
460 bool update_lcd_text = false;
461 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
463 gfx::Rect viewport_rect_for_tile_priority_in_view_space =
464 viewport_rect_for_tile_priority;
466 // Verify the viewport rect for tile priority is used in picture layer tiling.
467 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space,
468 active_layer_->viewport_rect_for_tile_priority_in_content_space());
469 PictureLayerTilingSet* tilings = active_layer_->tilings();
470 for (size_t i = 0; i < tilings->num_tilings(); i++) {
471 PictureLayerTiling* tiling = tilings->tiling_at(i);
472 EXPECT_EQ(
473 tiling->GetCurrentVisibleRectForTesting(),
474 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space,
475 tiling->contents_scale()));
478 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in
479 // screen space and the transform for tile priority is translated and
480 // rotated. The actual viewport for tile priority used by PictureLayerImpl
481 // should be (200, 200, 100, 100) applied with the said transform.
482 time_ticks += base::TimeDelta::FromMilliseconds(200);
483 host_impl_.SetCurrentBeginFrameArgs(
484 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
486 viewport_rect_for_tile_priority = gfx::Rect(200, 200, 100, 100);
487 transform_for_tile_priority.Translate(100, 100);
488 transform_for_tile_priority.Rotate(45);
489 host_impl_.SetExternalDrawConstraints(transform,
490 viewport,
491 viewport,
492 viewport_rect_for_tile_priority,
493 transform_for_tile_priority,
494 resourceless_software_draw);
495 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
497 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization);
498 bool success = transform_for_tile_priority.GetInverse(&screen_to_view);
499 EXPECT_TRUE(success);
501 // Note that we don't clip this to the layer bounds, since it is expected that
502 // the rect will sometimes be outside of the layer bounds. If we clip to
503 // bounds, then tile priorities will end up being incorrect in cases of fully
504 // offscreen layer.
505 viewport_rect_for_tile_priority_in_view_space =
506 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
507 screen_to_view, viewport_rect_for_tile_priority));
509 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space,
510 active_layer_->viewport_rect_for_tile_priority_in_content_space());
511 tilings = active_layer_->tilings();
512 for (size_t i = 0; i < tilings->num_tilings(); i++) {
513 PictureLayerTiling* tiling = tilings->tiling_at(i);
514 EXPECT_EQ(
515 tiling->GetCurrentVisibleRectForTesting(),
516 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space,
517 tiling->contents_scale()));
521 TEST_F(PictureLayerImplTest, InvalidViewportForPrioritizingTiles) {
522 base::TimeTicks time_ticks;
523 time_ticks += base::TimeDelta::FromMilliseconds(1);
524 host_impl_.SetCurrentBeginFrameArgs(
525 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
527 gfx::Size tile_size(100, 100);
528 gfx::Size layer_bounds(400, 400);
530 scoped_refptr<FakePicturePileImpl> pending_pile =
531 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
532 scoped_refptr<FakePicturePileImpl> active_pile =
533 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
535 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
537 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
539 // UpdateTiles with valid viewport. Should update tile viewport.
540 // Note viewport is considered invalid if and only if in resourceless
541 // software draw.
542 bool resourceless_software_draw = false;
543 gfx::Rect viewport = gfx::Rect(layer_bounds);
544 gfx::Transform transform;
545 host_impl_.SetExternalDrawConstraints(transform,
546 viewport,
547 viewport,
548 viewport,
549 transform,
550 resourceless_software_draw);
551 active_layer_->draw_properties().visible_content_rect = viewport;
552 active_layer_->draw_properties().screen_space_transform = transform;
553 active_layer_->UpdateTiles(resourceless_software_draw);
555 gfx::Rect visible_rect_for_tile_priority =
556 active_layer_->visible_rect_for_tile_priority();
557 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty());
558 gfx::Transform screen_space_transform_for_tile_priority =
559 active_layer_->screen_space_transform();
561 // Expand viewport and set it as invalid for prioritizing tiles.
562 // Should update viewport and transform, but not update visible rect.
563 time_ticks += base::TimeDelta::FromMilliseconds(200);
564 host_impl_.SetCurrentBeginFrameArgs(
565 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
566 resourceless_software_draw = true;
567 viewport = gfx::ScaleToEnclosingRect(viewport, 2);
568 transform.Translate(1.f, 1.f);
569 active_layer_->draw_properties().visible_content_rect = viewport;
570 active_layer_->draw_properties().screen_space_transform = transform;
571 host_impl_.SetExternalDrawConstraints(transform,
572 viewport,
573 viewport,
574 viewport,
575 transform,
576 resourceless_software_draw);
577 active_layer_->UpdateTiles(resourceless_software_draw);
579 // Transform for tile priority is updated.
580 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
581 active_layer_->screen_space_transform());
582 // Visible rect for tile priority retains old value.
583 EXPECT_EQ(visible_rect_for_tile_priority,
584 active_layer_->visible_rect_for_tile_priority());
586 // Keep expanded viewport but mark it valid. Should update tile viewport.
587 time_ticks += base::TimeDelta::FromMilliseconds(200);
588 host_impl_.SetCurrentBeginFrameArgs(
589 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
590 resourceless_software_draw = false;
591 host_impl_.SetExternalDrawConstraints(transform,
592 viewport,
593 viewport,
594 viewport,
595 transform,
596 resourceless_software_draw);
597 active_layer_->UpdateTiles(resourceless_software_draw);
599 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
600 active_layer_->screen_space_transform());
601 EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority());
604 TEST_F(PictureLayerImplTest, ViewportRectForTilePriorityIsCached) {
605 base::TimeTicks time_ticks;
606 time_ticks += base::TimeDelta::FromMilliseconds(1);
607 host_impl_.SetCurrentBeginFrameArgs(
608 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
609 gfx::Size tile_size(100, 100);
610 gfx::Size layer_bounds(400, 400);
612 scoped_refptr<FakePicturePileImpl> pending_pile =
613 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
614 scoped_refptr<FakePicturePileImpl> active_pile =
615 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
617 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
619 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
621 time_ticks += base::TimeDelta::FromMilliseconds(200);
622 host_impl_.SetCurrentBeginFrameArgs(
623 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
625 bool resourceless_software_draw = false;
626 gfx::Rect viewport = gfx::Rect(layer_bounds);
627 gfx::Rect viewport_rect_for_tile_priority(0, 0, 100, 100);
628 gfx::Transform transform, transform_for_tile_priority;
630 host_impl_.SetExternalDrawConstraints(
631 transform, viewport, viewport, viewport_rect_for_tile_priority,
632 transform_for_tile_priority, resourceless_software_draw);
633 bool update_lcd_text = false;
634 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
636 EXPECT_EQ(viewport_rect_for_tile_priority,
637 active_layer_->viewport_rect_for_tile_priority_in_content_space());
639 time_ticks += base::TimeDelta::FromMilliseconds(200);
640 host_impl_.SetCurrentBeginFrameArgs(
641 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
643 gfx::Rect another_viewport_rect_for_tile_priority(11, 11, 50, 50);
644 host_impl_.SetExternalDrawConstraints(
645 transform, viewport, viewport, another_viewport_rect_for_tile_priority,
646 transform_for_tile_priority, resourceless_software_draw);
648 // Didn't call UpdateDrawProperties yet. The viewport rect for tile priority
649 // should remain to be the previously cached value.
650 EXPECT_EQ(viewport_rect_for_tile_priority,
651 active_layer_->viewport_rect_for_tile_priority_in_content_space());
652 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
654 // Now the UpdateDrawProperties is called. The viewport rect for tile
655 // priority should be the latest value.
656 EXPECT_EQ(another_viewport_rect_for_tile_priority,
657 active_layer_->viewport_rect_for_tile_priority_in_content_space());
660 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) {
661 gfx::Size tile_size(100, 100);
662 gfx::Size layer_bounds(400, 400);
663 gfx::Rect layer_invalidation(150, 200, 30, 180);
665 scoped_refptr<FakePicturePileImpl> pending_pile =
666 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
667 scoped_refptr<FakePicturePileImpl> active_pile =
668 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
669 scoped_refptr<FakePicturePileImpl> lost_pile =
670 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
672 SetupPendingTreeWithFixedTileSize(lost_pile, gfx::Size(50, 50), Region());
673 ActivateTree();
674 // Add a unique tiling on the active tree.
675 PictureLayerTiling* tiling = active_layer_->AddTiling(3.f);
676 tiling->CreateAllTilesForTesting();
678 // Ensure UpdateTiles won't remove any tilings.
679 active_layer_->MarkAllTilingsUsed();
681 // Then setup a new pending tree and activate it.
682 SetupTreesWithFixedTileSize(pending_pile, active_pile, gfx::Size(50, 50),
683 layer_invalidation);
685 EXPECT_EQ(2u, pending_layer_->num_tilings());
686 EXPECT_EQ(3u, active_layer_->num_tilings());
688 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
689 EXPECT_GT(tilings->num_tilings(), 0u);
690 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
691 const PictureLayerTiling* tiling = tilings->tiling_at(i);
692 gfx::Rect content_invalidation = gfx::ScaleToEnclosingRect(
693 layer_invalidation,
694 tiling->contents_scale());
695 for (PictureLayerTiling::CoverageIterator iter(
696 tiling,
697 tiling->contents_scale(),
698 gfx::Rect(tiling->tiling_size()));
699 iter;
700 ++iter) {
701 // We don't always have a tile, but when we do it's because it was
702 // invalidated and it has the latest raster source.
703 if (*iter) {
704 EXPECT_FALSE(iter.geometry_rect().IsEmpty());
705 EXPECT_EQ(pending_pile.get(), iter->raster_source());
706 EXPECT_TRUE(iter.geometry_rect().Intersects(content_invalidation));
707 } else {
708 // We don't create tiles in non-invalidated regions.
709 EXPECT_FALSE(iter.geometry_rect().Intersects(content_invalidation));
714 tilings = active_layer_->tilings();
715 EXPECT_GT(tilings->num_tilings(), 0u);
716 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
717 const PictureLayerTiling* tiling = tilings->tiling_at(i);
718 gfx::Rect content_invalidation =
719 gfx::ScaleToEnclosingRect(layer_invalidation, tiling->contents_scale());
720 for (PictureLayerTiling::CoverageIterator iter(
721 tiling,
722 tiling->contents_scale(),
723 gfx::Rect(tiling->tiling_size()));
724 iter;
725 ++iter) {
726 EXPECT_TRUE(*iter);
727 EXPECT_FALSE(iter.geometry_rect().IsEmpty());
728 // Pile will be updated upon activation.
729 EXPECT_EQ(active_pile.get(), iter->raster_source());
734 TEST_F(PictureLayerImplTest, CloneFullInvalidation) {
735 gfx::Size tile_size(90, 80);
736 gfx::Size layer_bounds(300, 500);
738 scoped_refptr<FakePicturePileImpl> pending_pile =
739 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
740 scoped_refptr<FakePicturePileImpl> active_pile =
741 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
743 SetupTreesWithInvalidation(pending_pile, active_pile,
744 gfx::Rect(layer_bounds));
746 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
747 active_layer_->tilings()->num_tilings());
749 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
750 EXPECT_GT(tilings->num_tilings(), 0u);
751 for (size_t i = 0; i < tilings->num_tilings(); ++i)
752 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), pending_pile.get());
755 TEST_F(PictureLayerImplTest, UpdateTilesCreatesTilings) {
756 gfx::Size tile_size(400, 400);
757 gfx::Size layer_bounds(1300, 1900);
759 scoped_refptr<FakePicturePileImpl> pending_pile =
760 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
761 scoped_refptr<FakePicturePileImpl> active_pile =
762 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
764 SetupTrees(pending_pile, active_pile);
766 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
767 EXPECT_LT(low_res_factor, 1.f);
769 active_layer_->ReleaseResources();
770 EXPECT_FALSE(active_layer_->tilings());
771 active_layer_->RecreateResources();
772 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
774 SetupDrawPropertiesAndUpdateTiles(active_layer_,
775 6.f, // ideal contents scale
776 3.f, // device scale
777 2.f, // page scale
778 1.f, // maximum animation scale
779 false);
780 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
781 EXPECT_FLOAT_EQ(6.f,
782 active_layer_->tilings()->tiling_at(0)->contents_scale());
783 EXPECT_FLOAT_EQ(6.f * low_res_factor,
784 active_layer_->tilings()->tiling_at(1)->contents_scale());
786 // If we change the page scale factor, then we should get new tilings.
787 SetupDrawPropertiesAndUpdateTiles(active_layer_,
788 6.6f, // ideal contents scale
789 3.f, // device scale
790 2.2f, // page scale
791 1.f, // maximum animation scale
792 false);
793 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
794 EXPECT_FLOAT_EQ(6.6f,
795 active_layer_->tilings()->tiling_at(0)->contents_scale());
796 EXPECT_FLOAT_EQ(6.6f * low_res_factor,
797 active_layer_->tilings()->tiling_at(2)->contents_scale());
799 // If we change the device scale factor, then we should get new tilings.
800 SetupDrawPropertiesAndUpdateTiles(active_layer_,
801 7.26f, // ideal contents scale
802 3.3f, // device scale
803 2.2f, // page scale
804 1.f, // maximum animation scale
805 false);
806 ASSERT_EQ(6u, active_layer_->tilings()->num_tilings());
807 EXPECT_FLOAT_EQ(7.26f,
808 active_layer_->tilings()->tiling_at(0)->contents_scale());
809 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
810 active_layer_->tilings()->tiling_at(3)->contents_scale());
812 // If we change the device scale factor, but end up at the same total scale
813 // factor somehow, then we don't get new tilings.
814 SetupDrawPropertiesAndUpdateTiles(active_layer_,
815 7.26f, // ideal contents scale
816 2.2f, // device scale
817 3.3f, // page scale
818 1.f, // maximum animation scale
819 false);
820 ASSERT_EQ(6u, active_layer_->tilings()->num_tilings());
821 EXPECT_FLOAT_EQ(7.26f,
822 active_layer_->tilings()->tiling_at(0)->contents_scale());
823 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
824 active_layer_->tilings()->tiling_at(3)->contents_scale());
827 TEST_F(PictureLayerImplTest, PendingLayerOnlyHasHighAndLowResTiling) {
828 gfx::Size tile_size(400, 400);
829 gfx::Size layer_bounds(1300, 1900);
831 scoped_refptr<FakePicturePileImpl> pending_pile =
832 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
833 scoped_refptr<FakePicturePileImpl> active_pile =
834 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
836 SetupTrees(pending_pile, active_pile);
838 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
839 EXPECT_LT(low_res_factor, 1.f);
841 pending_layer_->ReleaseResources();
842 EXPECT_FALSE(pending_layer_->tilings());
843 pending_layer_->RecreateResources();
844 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
846 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
847 6.f, // ideal contents scale
848 3.f, // device scale
849 2.f, // page scale
850 1.f, // maximum animation scale
851 false);
852 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
853 EXPECT_FLOAT_EQ(6.f,
854 pending_layer_->tilings()->tiling_at(0)->contents_scale());
855 EXPECT_FLOAT_EQ(6.f * low_res_factor,
856 pending_layer_->tilings()->tiling_at(1)->contents_scale());
858 // If we change the page scale factor, then we should get new tilings.
859 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
860 6.6f, // ideal contents scale
861 3.f, // device scale
862 2.2f, // page scale
863 1.f, // maximum animation scale
864 false);
865 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
866 EXPECT_FLOAT_EQ(6.6f,
867 pending_layer_->tilings()->tiling_at(0)->contents_scale());
868 EXPECT_FLOAT_EQ(6.6f * low_res_factor,
869 pending_layer_->tilings()->tiling_at(1)->contents_scale());
871 // If we change the device scale factor, then we should get new tilings.
872 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
873 7.26f, // ideal contents scale
874 3.3f, // device scale
875 2.2f, // page scale
876 1.f, // maximum animation scale
877 false);
878 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
879 EXPECT_FLOAT_EQ(7.26f,
880 pending_layer_->tilings()->tiling_at(0)->contents_scale());
881 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
882 pending_layer_->tilings()->tiling_at(1)->contents_scale());
884 // If we change the device scale factor, but end up at the same total scale
885 // factor somehow, then we don't get new tilings.
886 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
887 7.26f, // ideal contents scale
888 2.2f, // device scale
889 3.3f, // page scale
890 1.f, // maximum animation scale
891 false);
892 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
893 EXPECT_FLOAT_EQ(7.26f,
894 pending_layer_->tilings()->tiling_at(0)->contents_scale());
895 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
896 pending_layer_->tilings()->tiling_at(1)->contents_scale());
899 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) {
900 // This test makes sure that if a layer can have tilings, then a commit makes
901 // it not able to have tilings (empty size), and then a future commit that
902 // makes it valid again should be able to create tilings.
903 gfx::Size tile_size(400, 400);
904 gfx::Size layer_bounds(1300, 1900);
906 scoped_refptr<FakePicturePileImpl> empty_pile =
907 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
908 scoped_refptr<FakePicturePileImpl> valid_pile =
909 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
911 SetupPendingTree(valid_pile);
912 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
914 ActivateTree();
915 SetupPendingTree(empty_pile);
916 EXPECT_FALSE(pending_layer_->CanHaveTilings());
917 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
918 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
920 ActivateTree();
921 EXPECT_FALSE(active_layer_->CanHaveTilings());
922 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
924 SetupPendingTree(valid_pile);
925 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
926 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
929 TEST_F(PictureLayerImplTest, ZoomOutCrash) {
930 gfx::Size tile_size(400, 400);
931 gfx::Size layer_bounds(1300, 1900);
933 // Set up the high and low res tilings before pinch zoom.
934 scoped_refptr<FakePicturePileImpl> pending_pile =
935 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
936 scoped_refptr<FakePicturePileImpl> active_pile =
937 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
939 SetupTrees(pending_pile, active_pile);
940 ResetTilingsAndRasterScales();
941 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
942 SetContentsScaleOnBothLayers(32.0f, 1.0f, 32.0f, 1.0f, false);
943 EXPECT_EQ(32.f, active_layer_->HighResTiling()->contents_scale());
944 host_impl_.PinchGestureBegin();
945 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false);
946 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false);
947 EXPECT_EQ(active_layer_->tilings()->NumHighResTilings(), 1);
950 TEST_F(PictureLayerImplTest, PinchGestureTilings) {
951 gfx::Size tile_size(400, 400);
952 gfx::Size layer_bounds(1300, 1900);
954 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
956 scoped_refptr<FakePicturePileImpl> pending_pile =
957 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
958 scoped_refptr<FakePicturePileImpl> active_pile =
959 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
961 // Set up the high and low res tilings before pinch zoom.
962 SetupTrees(pending_pile, active_pile);
963 ResetTilingsAndRasterScales();
965 SetContentsScaleOnBothLayers(2.f, 1.0f, 2.f, 1.0f, false);
966 EXPECT_BOTH_EQ(num_tilings(), 2u);
967 EXPECT_BOTH_EQ(tilings()->tiling_at(0)->contents_scale(), 2.f);
968 EXPECT_BOTH_EQ(tilings()->tiling_at(1)->contents_scale(),
969 2.f * low_res_factor);
971 // Ensure UpdateTiles won't remove any tilings.
972 active_layer_->MarkAllTilingsUsed();
974 // Start a pinch gesture.
975 host_impl_.PinchGestureBegin();
977 // Zoom out by a small amount. We should create a tiling at half
978 // the scale (2/kMaxScaleRatioDuringPinch).
979 SetContentsScaleOnBothLayers(1.8f, 1.0f, 1.8f, 1.0f, false);
980 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
981 EXPECT_FLOAT_EQ(2.0f,
982 active_layer_->tilings()->tiling_at(0)->contents_scale());
983 EXPECT_FLOAT_EQ(1.0f,
984 active_layer_->tilings()->tiling_at(1)->contents_scale());
985 EXPECT_FLOAT_EQ(2.0f * low_res_factor,
986 active_layer_->tilings()->tiling_at(2)->contents_scale());
988 // Ensure UpdateTiles won't remove any tilings.
989 active_layer_->MarkAllTilingsUsed();
991 // Zoom out further, close to our low-res scale factor. We should
992 // use that tiling as high-res, and not create a new tiling.
993 SetContentsScaleOnBothLayers(low_res_factor * 2.1f, 1.0f,
994 low_res_factor * 2.1f, 1.0f, false);
995 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
997 // Zoom in a lot now. Since we increase by increments of
998 // kMaxScaleRatioDuringPinch, this will create a new tiling at 4.0.
999 SetContentsScaleOnBothLayers(3.8f, 1.0f, 3.8f, 1.f, false);
1000 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings());
1001 EXPECT_FLOAT_EQ(4.0f,
1002 active_layer_->tilings()->tiling_at(0)->contents_scale());
1005 TEST_F(PictureLayerImplTest, SnappedTilingDuringZoom) {
1006 gfx::Size tile_size(300, 300);
1007 gfx::Size layer_bounds(2600, 3800);
1009 scoped_refptr<FakePicturePileImpl> pending_pile =
1010 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1011 scoped_refptr<FakePicturePileImpl> active_pile =
1012 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1014 SetupTrees(pending_pile, active_pile);
1016 ResetTilingsAndRasterScales();
1017 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1019 // Set up the high and low res tilings before pinch zoom.
1020 SetContentsScaleOnBothLayers(0.24f, 1.0f, 0.24f, 1.0f, false);
1021 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
1022 EXPECT_FLOAT_EQ(0.24f,
1023 active_layer_->tilings()->tiling_at(0)->contents_scale());
1024 EXPECT_FLOAT_EQ(0.0625f,
1025 active_layer_->tilings()->tiling_at(1)->contents_scale());
1027 // Ensure UpdateTiles won't remove any tilings.
1028 active_layer_->MarkAllTilingsUsed();
1030 // Start a pinch gesture.
1031 host_impl_.PinchGestureBegin();
1033 // Zoom out by a small amount. We should create a tiling at half
1034 // the scale (1/kMaxScaleRatioDuringPinch).
1035 SetContentsScaleOnBothLayers(0.2f, 1.0f, 0.2f, 1.0f, false);
1036 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
1037 EXPECT_FLOAT_EQ(0.24f,
1038 active_layer_->tilings()->tiling_at(0)->contents_scale());
1039 EXPECT_FLOAT_EQ(0.12f,
1040 active_layer_->tilings()->tiling_at(1)->contents_scale());
1041 EXPECT_FLOAT_EQ(0.0625,
1042 active_layer_->tilings()->tiling_at(2)->contents_scale());
1044 // Ensure UpdateTiles won't remove any tilings.
1045 active_layer_->MarkAllTilingsUsed();
1047 // Zoom out further, close to our low-res scale factor. We should
1048 // use that tiling as high-res, and not create a new tiling.
1049 SetContentsScaleOnBothLayers(0.1f, 1.0f, 0.1f, 1.0f, false);
1050 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
1052 // Zoom in. 0.25(desired_scale) should be snapped to 0.24 during zoom-in
1053 // because 0.25(desired_scale) is within the ratio(1.2).
1054 SetContentsScaleOnBothLayers(0.25f, 1.0f, 0.25f, 1.0f, false);
1055 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
1057 // Zoom in a lot. Since we move in factors of two, we should get a scale that
1058 // is a power of 2 times 0.24.
1059 SetContentsScaleOnBothLayers(1.f, 1.0f, 1.f, 1.0f, false);
1060 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings());
1061 EXPECT_FLOAT_EQ(1.92f,
1062 active_layer_->tilings()->tiling_at(0)->contents_scale());
1065 TEST_F(PictureLayerImplTest, CleanUpTilings) {
1066 gfx::Size tile_size(400, 400);
1067 gfx::Size layer_bounds(1300, 1900);
1069 scoped_refptr<FakePicturePileImpl> pending_pile =
1070 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1071 scoped_refptr<FakePicturePileImpl> active_pile =
1072 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1074 std::vector<PictureLayerTiling*> used_tilings;
1076 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1077 EXPECT_LT(low_res_factor, 1.f);
1079 float scale = 1.f;
1080 float page_scale = 1.f;
1082 SetupTrees(pending_pile, active_pile);
1083 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
1084 EXPECT_EQ(1.f, active_layer_->HighResTiling()->contents_scale());
1086 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
1087 // |used_tilings| variable, and it's here only to ensure that active_layer_
1088 // won't remove tilings before the test has a chance to verify behavior.
1089 active_layer_->MarkAllTilingsUsed();
1091 // We only have ideal tilings, so they aren't removed.
1092 used_tilings.clear();
1093 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1094 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
1096 host_impl_.PinchGestureBegin();
1098 // Changing the ideal but not creating new tilings.
1099 scale = 1.5f;
1100 page_scale = 1.5f;
1101 SetContentsScaleOnBothLayers(scale, 1.f, page_scale, 1.f, false);
1102 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
1104 // The tilings are still our target scale, so they aren't removed.
1105 used_tilings.clear();
1106 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1107 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
1109 host_impl_.PinchGestureEnd();
1111 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
1112 scale = 1.2f;
1113 page_scale = 1.2f;
1114 SetContentsScaleOnBothLayers(1.2f, 1.f, page_scale, 1.f, false);
1115 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
1116 EXPECT_FLOAT_EQ(
1117 1.f,
1118 active_layer_->tilings()->tiling_at(1)->contents_scale());
1119 EXPECT_FLOAT_EQ(
1120 1.f * low_res_factor,
1121 active_layer_->tilings()->tiling_at(3)->contents_scale());
1123 // Ensure UpdateTiles won't remove any tilings.
1124 active_layer_->MarkAllTilingsUsed();
1126 // Mark the non-ideal tilings as used. They won't be removed.
1127 used_tilings.clear();
1128 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
1129 used_tilings.push_back(active_layer_->tilings()->tiling_at(3));
1130 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1131 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
1133 // Now move the ideal scale to 0.5. Our target stays 1.2.
1134 SetContentsScaleOnBothLayers(0.5f, 1.f, page_scale, 1.f, false);
1136 // The high resolution tiling is between target and ideal, so is not
1137 // removed. The low res tiling for the old ideal=1.0 scale is removed.
1138 used_tilings.clear();
1139 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1140 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1142 // Now move the ideal scale to 1.0. Our target stays 1.2.
1143 SetContentsScaleOnBothLayers(1.f, 1.f, page_scale, 1.f, false);
1145 // All the tilings are between are target and the ideal, so they are not
1146 // removed.
1147 used_tilings.clear();
1148 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1149 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1151 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
1152 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.1f, 1.f, page_scale, 1.f,
1153 false);
1155 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1156 // in the range [1.0,1.2] and are kept.
1157 used_tilings.clear();
1158 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1159 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1161 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1162 // 1.2 still.
1163 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.1f, 1.f, page_scale, 1.f,
1164 false);
1166 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1167 // target raster scale. But it is in our used tilings set, so nothing is
1168 // deleted.
1169 used_tilings.clear();
1170 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
1171 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1172 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1174 // If we remove it from our used tilings set, it is outside the range to keep
1175 // so it is deleted.
1176 used_tilings.clear();
1177 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1178 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
1181 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) {
1182 // Make sure this layer covers multiple tiles, since otherwise low
1183 // res won't get created because it is too small.
1184 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1185 // Avoid max untiled layer size heuristics via fixed tile size.
1186 gfx::Size layer_bounds(tile_size.width() + 1, tile_size.height() + 1);
1187 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1189 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1190 float contents_scale = 1.f;
1191 float device_scale = 1.f;
1192 float page_scale = 1.f;
1193 float maximum_animation_scale = 1.f;
1194 bool animating_transform = true;
1196 ResetTilingsAndRasterScales();
1198 // Animating, so don't create low res even if there isn't one already.
1199 SetContentsScaleOnBothLayers(contents_scale,
1200 device_scale,
1201 page_scale,
1202 maximum_animation_scale,
1203 animating_transform);
1204 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1205 EXPECT_BOTH_EQ(num_tilings(), 1u);
1207 // Stop animating, low res gets created.
1208 animating_transform = false;
1209 SetContentsScaleOnBothLayers(contents_scale,
1210 device_scale,
1211 page_scale,
1212 maximum_animation_scale,
1213 animating_transform);
1214 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1215 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor);
1216 EXPECT_BOTH_EQ(num_tilings(), 2u);
1218 // Ensure UpdateTiles won't remove any tilings.
1219 active_layer_->MarkAllTilingsUsed();
1221 // Page scale animation, new high res, but no low res. We still have
1222 // a tiling at the previous scale, it's just not marked as low res on the
1223 // active layer. The pending layer drops non-ideal tilings.
1224 contents_scale = 2.f;
1225 page_scale = 2.f;
1226 maximum_animation_scale = 2.f;
1227 animating_transform = true;
1228 SetContentsScaleOnBothLayers(contents_scale,
1229 device_scale,
1230 page_scale,
1231 maximum_animation_scale,
1232 animating_transform);
1233 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1234 EXPECT_FALSE(active_layer_->LowResTiling());
1235 EXPECT_FALSE(pending_layer_->LowResTiling());
1236 EXPECT_EQ(3u, active_layer_->num_tilings());
1237 EXPECT_EQ(1u, pending_layer_->num_tilings());
1239 // Stop animating, new low res gets created for final page scale.
1240 animating_transform = false;
1241 SetContentsScaleOnBothLayers(contents_scale,
1242 device_scale,
1243 page_scale,
1244 maximum_animation_scale,
1245 animating_transform);
1246 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1247 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f * low_res_factor);
1248 EXPECT_EQ(4u, active_layer_->num_tilings());
1249 EXPECT_EQ(2u, pending_layer_->num_tilings());
1252 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) {
1253 gfx::Size layer_bounds(host_impl_.settings().default_tile_size);
1254 gfx::Size tile_size(100, 100);
1256 scoped_refptr<FakePicturePileImpl> pending_pile =
1257 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1258 scoped_refptr<FakePicturePileImpl> active_pile =
1259 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1261 SetupTrees(pending_pile, active_pile);
1263 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1264 float device_scale = 1.f;
1265 float page_scale = 1.f;
1266 float maximum_animation_scale = 1.f;
1267 bool animating_transform = false;
1269 // Contents exactly fit on one tile at scale 1, no low res.
1270 float contents_scale = 1.f;
1271 SetContentsScaleOnBothLayers(contents_scale,
1272 device_scale,
1273 page_scale,
1274 maximum_animation_scale,
1275 animating_transform);
1276 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1277 EXPECT_BOTH_EQ(num_tilings(), 1u);
1279 ResetTilingsAndRasterScales();
1281 // Contents that are smaller than one tile, no low res.
1282 contents_scale = 0.123f;
1283 SetContentsScaleOnBothLayers(contents_scale,
1284 device_scale,
1285 page_scale,
1286 maximum_animation_scale,
1287 animating_transform);
1288 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1289 EXPECT_BOTH_EQ(num_tilings(), 1u);
1291 ResetTilingsAndRasterScales();
1293 // Any content bounds that would create more than one tile will
1294 // generate a low res tiling.
1295 contents_scale = 2.5f;
1296 SetContentsScaleOnBothLayers(contents_scale,
1297 device_scale,
1298 page_scale,
1299 maximum_animation_scale,
1300 animating_transform);
1301 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1302 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1303 contents_scale * low_res_factor);
1304 EXPECT_BOTH_EQ(num_tilings(), 2u);
1306 // Mask layers dont create low res since they always fit on one tile.
1307 scoped_ptr<FakePictureLayerImpl> mask =
1308 FakePictureLayerImpl::CreateMaskWithRasterSource(
1309 host_impl_.pending_tree(), 3, pending_pile);
1310 mask->SetBounds(layer_bounds);
1311 mask->SetContentBounds(layer_bounds);
1312 mask->SetDrawsContent(true);
1314 SetupDrawPropertiesAndUpdateTiles(mask.get(), contents_scale, device_scale,
1315 page_scale, maximum_animation_scale,
1316 animating_transform);
1317 EXPECT_EQ(mask->HighResTiling()->contents_scale(), contents_scale);
1318 EXPECT_EQ(mask->num_tilings(), 1u);
1321 TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) {
1322 base::TimeTicks time_ticks;
1323 time_ticks += base::TimeDelta::FromMilliseconds(1);
1324 host_impl_.SetCurrentBeginFrameArgs(
1325 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1327 gfx::Size tile_size(100, 100);
1328 gfx::Size layer_bounds(1000, 1000);
1330 scoped_refptr<FakePicturePileImpl> valid_pile =
1331 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1332 SetupPendingTree(valid_pile);
1334 scoped_ptr<FakePictureLayerImpl> mask_ptr =
1335 FakePictureLayerImpl::CreateMaskWithRasterSource(
1336 host_impl_.pending_tree(), 3, valid_pile);
1337 mask_ptr->SetBounds(layer_bounds);
1338 mask_ptr->SetContentBounds(layer_bounds);
1339 mask_ptr->SetDrawsContent(true);
1340 pending_layer_->SetMaskLayer(mask_ptr.Pass());
1341 pending_layer_->SetHasRenderSurface(true);
1343 time_ticks += base::TimeDelta::FromMilliseconds(1);
1344 host_impl_.SetCurrentBeginFrameArgs(
1345 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1346 bool update_lcd_text = false;
1347 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1349 FakePictureLayerImpl* pending_mask =
1350 static_cast<FakePictureLayerImpl*>(pending_layer_->mask_layer());
1352 EXPECT_EQ(1.f, pending_mask->HighResTiling()->contents_scale());
1353 EXPECT_EQ(1u, pending_mask->num_tilings());
1355 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1356 pending_mask->HighResTiling()->AllTilesForTesting());
1358 ActivateTree();
1360 FakePictureLayerImpl* active_mask =
1361 static_cast<FakePictureLayerImpl*>(active_layer_->mask_layer());
1363 // Mask layers have a tiling with a single tile in it.
1364 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1365 // The mask resource exists.
1366 ResourceProvider::ResourceId mask_resource_id;
1367 gfx::Size mask_texture_size;
1368 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1369 EXPECT_NE(0u, mask_resource_id);
1370 EXPECT_EQ(active_mask->bounds(), mask_texture_size);
1372 // Drop resources and recreate them, still the same.
1373 pending_mask->ReleaseResources();
1374 active_mask->ReleaseResources();
1375 pending_mask->RecreateResources();
1376 active_mask->RecreateResources();
1377 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, false);
1378 active_mask->HighResTiling()->CreateAllTilesForTesting();
1379 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1380 EXPECT_NE(0u, mask_resource_id);
1381 EXPECT_EQ(active_mask->bounds(), mask_texture_size);
1383 // Resize larger than the max texture size.
1384 int max_texture_size = host_impl_.GetRendererCapabilities().max_texture_size;
1385 gfx::Size huge_bounds(max_texture_size + 1, 10);
1386 scoped_refptr<FakePicturePileImpl> huge_pile =
1387 FakePicturePileImpl::CreateFilledPile(tile_size, huge_bounds);
1389 SetupPendingTree(huge_pile);
1390 pending_mask->SetBounds(huge_bounds);
1391 pending_mask->SetContentBounds(huge_bounds);
1392 pending_mask->SetRasterSourceOnPending(huge_pile, Region());
1394 time_ticks += base::TimeDelta::FromMilliseconds(1);
1395 host_impl_.SetCurrentBeginFrameArgs(
1396 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1397 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1399 // The mask tiling gets scaled down.
1400 EXPECT_LT(pending_mask->HighResTiling()->contents_scale(), 1.f);
1401 EXPECT_EQ(1u, pending_mask->num_tilings());
1403 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1404 pending_mask->HighResTiling()->AllTilesForTesting());
1406 ActivateTree();
1408 // Mask layers have a tiling with a single tile in it.
1409 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1410 // The mask resource exists.
1411 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1412 EXPECT_NE(0u, mask_resource_id);
1413 gfx::Size expected_size = active_mask->bounds();
1414 expected_size.SetToMin(gfx::Size(max_texture_size, max_texture_size));
1415 EXPECT_EQ(expected_size, mask_texture_size);
1417 // Drop resources and recreate them, still the same.
1418 pending_mask->ReleaseResources();
1419 active_mask->ReleaseResources();
1420 pending_mask->RecreateResources();
1421 active_mask->RecreateResources();
1422 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, false);
1423 active_mask->HighResTiling()->CreateAllTilesForTesting();
1424 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1425 EXPECT_NE(0u, mask_resource_id);
1426 EXPECT_EQ(expected_size, mask_texture_size);
1428 // Do another activate, the same holds.
1429 SetupPendingTree(huge_pile);
1430 ActivateTree();
1431 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1432 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1433 EXPECT_EQ(expected_size, mask_texture_size);
1434 EXPECT_EQ(0u, mask_resource_id);
1436 // Resize even larger, so that the scale would be smaller than the minimum
1437 // contents scale. Then the layer should no longer have any tiling.
1438 float min_contents_scale = host_impl_.settings().minimum_contents_scale;
1439 gfx::Size extra_huge_bounds(max_texture_size / min_contents_scale + 1, 10);
1440 scoped_refptr<FakePicturePileImpl> extra_huge_pile =
1441 FakePicturePileImpl::CreateFilledPile(tile_size, extra_huge_bounds);
1443 SetupPendingTree(extra_huge_pile);
1444 pending_mask->SetBounds(extra_huge_bounds);
1445 pending_mask->SetContentBounds(extra_huge_bounds);
1446 pending_mask->SetRasterSourceOnPending(extra_huge_pile, Region());
1448 EXPECT_FALSE(pending_mask->CanHaveTilings());
1450 time_ticks += base::TimeDelta::FromMilliseconds(1);
1451 host_impl_.SetCurrentBeginFrameArgs(
1452 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1453 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1455 EXPECT_EQ(0u, pending_mask->num_tilings());
1458 TEST_F(PictureLayerImplTest, ScaledMaskLayer) {
1459 base::TimeTicks time_ticks;
1460 time_ticks += base::TimeDelta::FromMilliseconds(1);
1461 host_impl_.SetCurrentBeginFrameArgs(
1462 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1464 gfx::Size tile_size(100, 100);
1465 gfx::Size layer_bounds(1000, 1000);
1467 host_impl_.SetDeviceScaleFactor(1.3f);
1469 scoped_refptr<FakePicturePileImpl> valid_pile =
1470 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1471 SetupPendingTree(valid_pile);
1473 scoped_ptr<FakePictureLayerImpl> mask_ptr =
1474 FakePictureLayerImpl::CreateMaskWithRasterSource(
1475 host_impl_.pending_tree(), 3, valid_pile);
1476 mask_ptr->SetBounds(layer_bounds);
1477 mask_ptr->SetContentBounds(layer_bounds);
1478 mask_ptr->SetDrawsContent(true);
1479 pending_layer_->SetMaskLayer(mask_ptr.Pass());
1480 pending_layer_->SetHasRenderSurface(true);
1482 time_ticks += base::TimeDelta::FromMilliseconds(1);
1483 host_impl_.SetCurrentBeginFrameArgs(
1484 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1485 bool update_lcd_text = false;
1486 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1488 FakePictureLayerImpl* pending_mask =
1489 static_cast<FakePictureLayerImpl*>(pending_layer_->mask_layer());
1491 // Masks are scaled, and do not have a low res tiling.
1492 EXPECT_EQ(1.3f, pending_mask->HighResTiling()->contents_scale());
1493 EXPECT_EQ(1u, pending_mask->num_tilings());
1495 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1496 pending_mask->HighResTiling()->AllTilesForTesting());
1498 ActivateTree();
1500 FakePictureLayerImpl* active_mask =
1501 static_cast<FakePictureLayerImpl*>(active_layer_->mask_layer());
1503 // Mask layers have a tiling with a single tile in it.
1504 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1505 // The mask resource exists.
1506 ResourceProvider::ResourceId mask_resource_id;
1507 gfx::Size mask_texture_size;
1508 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1509 EXPECT_NE(0u, mask_resource_id);
1510 gfx::Size expected_mask_texture_size =
1511 gfx::ToCeiledSize(gfx::ScaleSize(active_mask->bounds(), 1.3f));
1512 EXPECT_EQ(mask_texture_size, expected_mask_texture_size);
1515 TEST_F(PictureLayerImplTest, ReleaseResources) {
1516 gfx::Size tile_size(400, 400);
1517 gfx::Size layer_bounds(1300, 1900);
1519 scoped_refptr<FakePicturePileImpl> pending_pile =
1520 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1521 scoped_refptr<FakePicturePileImpl> active_pile =
1522 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1524 SetupTrees(pending_pile, active_pile);
1525 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1527 // All tilings should be removed when losing output surface.
1528 active_layer_->ReleaseResources();
1529 EXPECT_FALSE(active_layer_->tilings());
1530 active_layer_->RecreateResources();
1531 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1532 pending_layer_->ReleaseResources();
1533 EXPECT_FALSE(pending_layer_->tilings());
1534 pending_layer_->RecreateResources();
1535 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1537 // This should create new tilings.
1538 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
1539 1.f, // ideal contents scale
1540 1.f, // device scale
1541 1.f, // page scale
1542 1.f, // maximum animation scale
1543 false);
1544 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1547 TEST_F(PictureLayerImplTest, ClampTilesToMaxTileSize) {
1548 // The default max tile size is larger than 400x400.
1549 gfx::Size tile_size(400, 400);
1550 gfx::Size layer_bounds(5000, 5000);
1552 scoped_refptr<FakePicturePileImpl> pending_pile =
1553 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1555 SetupPendingTree(pending_pile);
1556 EXPECT_GE(pending_layer_->tilings()->num_tilings(), 1u);
1558 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1560 // The default value.
1561 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1562 host_impl_.settings().default_tile_size.ToString());
1564 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1565 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1566 tile->content_rect().size().ToString());
1568 ResetTilingsAndRasterScales();
1570 // Change the max texture size on the output surface context.
1571 scoped_ptr<TestWebGraphicsContext3D> context =
1572 TestWebGraphicsContext3D::Create();
1573 context->set_max_texture_size(140);
1574 host_impl_.DidLoseOutputSurface();
1575 host_impl_.InitializeRenderer(
1576 FakeOutputSurface::Create3d(context.Pass()).Pass());
1578 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1579 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1581 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1583 // Verify the tiles are not larger than the context's max texture size.
1584 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1585 EXPECT_GE(140, tile->content_rect().width());
1586 EXPECT_GE(140, tile->content_rect().height());
1589 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) {
1590 // The default max tile size is larger than 400x400.
1591 gfx::Size tile_size(400, 400);
1592 gfx::Size layer_bounds(500, 500);
1594 scoped_refptr<FakePicturePileImpl> pending_pile =
1595 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1596 scoped_refptr<FakePicturePileImpl> active_pile =
1597 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1599 SetupTrees(pending_pile, active_pile);
1600 EXPECT_GE(active_layer_->tilings()->num_tilings(), 1u);
1602 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1604 // The default value. The layer is smaller than this.
1605 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1606 host_impl_.settings().max_untiled_layer_size.ToString());
1608 // There should be a single tile since the layer is small.
1609 PictureLayerTiling* high_res_tiling = active_layer_->tilings()->tiling_at(0);
1610 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size());
1612 ResetTilingsAndRasterScales();
1614 // Change the max texture size on the output surface context.
1615 scoped_ptr<TestWebGraphicsContext3D> context =
1616 TestWebGraphicsContext3D::Create();
1617 context->set_max_texture_size(140);
1618 host_impl_.DidLoseOutputSurface();
1619 host_impl_.InitializeRenderer(
1620 FakeOutputSurface::Create3d(context.Pass()).Pass());
1622 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
1623 ASSERT_LE(1u, active_layer_->tilings()->num_tilings());
1625 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1627 // There should be more than one tile since the max texture size won't cover
1628 // the layer.
1629 high_res_tiling = active_layer_->tilings()->tiling_at(0);
1630 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size());
1632 // Verify the tiles are not larger than the context's max texture size.
1633 Tile* tile = active_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1634 EXPECT_GE(140, tile->content_rect().width());
1635 EXPECT_GE(140, tile->content_rect().height());
1638 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) {
1639 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1641 gfx::Size tile_size(400, 400);
1642 gfx::Size layer_bounds(1300, 1900);
1644 scoped_refptr<FakePicturePileImpl> pending_pile =
1645 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1646 scoped_refptr<FakePicturePileImpl> active_pile =
1647 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1649 gfx::Rect layer_invalidation(150, 200, 30, 180);
1650 SetupTreesWithInvalidation(pending_pile, active_pile, layer_invalidation);
1652 active_layer_->draw_properties().visible_content_rect =
1653 gfx::Rect(layer_bounds);
1655 AppendQuadsData data;
1656 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, nullptr);
1657 active_layer_->AppendQuads(render_pass.get(), &data);
1658 active_layer_->DidDraw(nullptr);
1660 ASSERT_EQ(1U, render_pass->quad_list.size());
1661 EXPECT_EQ(DrawQuad::PICTURE_CONTENT,
1662 render_pass->quad_list.front()->material);
1665 TEST_F(PictureLayerImplTest, SolidColorLayerHasVisibleFullCoverage) {
1666 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1668 gfx::Size tile_size(1000, 1000);
1669 gfx::Size layer_bounds(1500, 1500);
1670 gfx::Rect visible_rect(250, 250, 1000, 1000);
1672 scoped_ptr<FakePicturePile> empty_recording =
1673 FakePicturePile::CreateEmptyPile(tile_size, layer_bounds);
1674 empty_recording->SetIsSolidColor(true);
1676 scoped_refptr<FakePicturePileImpl> pending_pile =
1677 FakePicturePileImpl::CreateFromPile(empty_recording.get(), nullptr);
1678 scoped_refptr<FakePicturePileImpl> active_pile =
1679 FakePicturePileImpl::CreateFromPile(empty_recording.get(), nullptr);
1681 SetupTrees(pending_pile, active_pile);
1683 active_layer_->draw_properties().visible_content_rect = visible_rect;
1685 AppendQuadsData data;
1686 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1687 active_layer_->AppendQuads(render_pass.get(), &data);
1688 active_layer_->DidDraw(nullptr);
1690 Region remaining = visible_rect;
1691 for (const auto& quad : render_pass->quad_list) {
1692 EXPECT_TRUE(visible_rect.Contains(quad->rect));
1693 EXPECT_TRUE(remaining.Contains(quad->rect));
1694 remaining.Subtract(quad->rect);
1697 EXPECT_TRUE(remaining.IsEmpty());
1700 TEST_F(PictureLayerImplTest, TileScalesWithSolidColorPile) {
1701 gfx::Size layer_bounds(200, 200);
1702 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1703 scoped_refptr<FakePicturePileImpl> pending_pile =
1704 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1705 tile_size, layer_bounds, false);
1706 scoped_refptr<FakePicturePileImpl> active_pile =
1707 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1708 tile_size, layer_bounds, true);
1710 SetupTrees(pending_pile, active_pile);
1711 // Solid color pile should not allow tilings at any scale.
1712 EXPECT_FALSE(active_layer_->CanHaveTilings());
1713 EXPECT_EQ(0.f, active_layer_->ideal_contents_scale());
1715 // Activate non-solid-color pending pile makes active layer can have tilings.
1716 ActivateTree();
1717 EXPECT_TRUE(active_layer_->CanHaveTilings());
1718 EXPECT_GT(active_layer_->ideal_contents_scale(), 0.f);
1721 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredOffscreenTiles) {
1722 gfx::Size tile_size(100, 100);
1723 gfx::Size layer_bounds(200, 200);
1725 gfx::Transform transform;
1726 gfx::Transform transform_for_tile_priority;
1727 bool resourceless_software_draw = false;
1728 gfx::Rect viewport(0, 0, 100, 200);
1729 host_impl_.SetExternalDrawConstraints(transform,
1730 viewport,
1731 viewport,
1732 viewport,
1733 transform,
1734 resourceless_software_draw);
1736 scoped_refptr<FakePicturePileImpl> pending_pile =
1737 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1738 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1740 EXPECT_EQ(1u, pending_layer_->num_tilings());
1741 EXPECT_EQ(viewport, pending_layer_->visible_rect_for_tile_priority());
1743 base::TimeTicks time_ticks;
1744 time_ticks += base::TimeDelta::FromMilliseconds(1);
1745 host_impl_.SetCurrentBeginFrameArgs(
1746 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1747 pending_layer_->UpdateTiles(resourceless_software_draw);
1749 int num_visible = 0;
1750 int num_offscreen = 0;
1752 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
1753 pending_layer_->picture_layer_tiling_set(), false));
1754 for (; !queue->IsEmpty(); queue->Pop()) {
1755 const Tile* tile = queue->Top();
1756 DCHECK(tile);
1757 if (tile->priority().distance_to_visible == 0.f) {
1758 EXPECT_TRUE(tile->required_for_activation());
1759 num_visible++;
1760 } else {
1761 EXPECT_FALSE(tile->required_for_activation());
1762 num_offscreen++;
1766 EXPECT_GT(num_visible, 0);
1767 EXPECT_GT(num_offscreen, 0);
1770 TEST_F(NoLowResPictureLayerImplTest,
1771 TileOutsideOfViewportForTilePriorityNotRequired) {
1772 base::TimeTicks time_ticks;
1773 time_ticks += base::TimeDelta::FromMilliseconds(1);
1774 host_impl_.SetCurrentBeginFrameArgs(
1775 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1777 gfx::Size tile_size(100, 100);
1778 gfx::Size layer_bounds(400, 400);
1779 gfx::Rect external_viewport_for_tile_priority(400, 200);
1780 gfx::Rect visible_content_rect(200, 400);
1782 scoped_refptr<FakePicturePileImpl> active_pile =
1783 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1784 scoped_refptr<FakePicturePileImpl> pending_pile =
1785 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1786 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
1788 ASSERT_EQ(1u, pending_layer_->num_tilings());
1789 ASSERT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
1791 // Set external viewport for tile priority.
1792 gfx::Rect viewport = gfx::Rect(layer_bounds);
1793 gfx::Transform transform;
1794 gfx::Transform transform_for_tile_priority;
1795 bool resourceless_software_draw = false;
1796 host_impl_.SetExternalDrawConstraints(transform,
1797 viewport,
1798 viewport,
1799 external_viewport_for_tile_priority,
1800 transform_for_tile_priority,
1801 resourceless_software_draw);
1802 time_ticks += base::TimeDelta::FromMilliseconds(1);
1803 host_impl_.SetCurrentBeginFrameArgs(
1804 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1805 bool update_lcd_text = false;
1806 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
1808 // Set visible content rect that is different from
1809 // external_viewport_for_tile_priority.
1810 pending_layer_->draw_properties().visible_content_rect = visible_content_rect;
1811 time_ticks += base::TimeDelta::FromMilliseconds(200);
1812 host_impl_.SetCurrentBeginFrameArgs(
1813 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1814 pending_layer_->UpdateTiles(resourceless_software_draw);
1816 // Intersect the two rects. Any tile outside should not be required for
1817 // activation.
1818 gfx::Rect viewport_for_tile_priority =
1819 pending_layer_->viewport_rect_for_tile_priority_in_content_space();
1820 viewport_for_tile_priority.Intersect(pending_layer_->visible_content_rect());
1822 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
1824 int num_inside = 0;
1825 int num_outside = 0;
1826 for (PictureLayerTiling::CoverageIterator iter(active_layer_->HighResTiling(),
1827 1.f, gfx::Rect(layer_bounds));
1828 iter; ++iter) {
1829 if (!*iter)
1830 continue;
1831 Tile* tile = *iter;
1832 if (viewport_for_tile_priority.Intersects(iter.geometry_rect())) {
1833 num_inside++;
1834 // Mark everything in viewport for tile priority as ready to draw.
1835 TileDrawInfo& draw_info = tile->draw_info();
1836 draw_info.SetSolidColorForTesting(SK_ColorRED);
1837 } else {
1838 num_outside++;
1839 EXPECT_FALSE(tile->required_for_activation());
1843 EXPECT_GT(num_inside, 0);
1844 EXPECT_GT(num_outside, 0);
1846 // Activate and draw active layer.
1847 host_impl_.ActivateSyncTree();
1848 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
1849 active_layer_->draw_properties().visible_content_rect = visible_content_rect;
1851 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1852 AppendQuadsData data;
1853 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1854 active_layer_->AppendQuads(render_pass.get(), &data);
1855 active_layer_->DidDraw(nullptr);
1857 // All tiles in activation rect is ready to draw.
1858 EXPECT_EQ(0u, data.num_missing_tiles);
1859 EXPECT_EQ(0u, data.num_incomplete_tiles);
1860 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
1863 TEST_F(PictureLayerImplTest, HighResTileIsComplete) {
1864 base::TimeTicks time_ticks;
1865 time_ticks += base::TimeDelta::FromMilliseconds(1);
1866 host_impl_.SetCurrentBeginFrameArgs(
1867 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1869 gfx::Size tile_size(100, 100);
1870 gfx::Size layer_bounds(200, 200);
1872 scoped_refptr<FakePicturePileImpl> pending_pile =
1873 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1875 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1876 ActivateTree();
1878 // All high res tiles have resources.
1879 std::vector<Tile*> tiles =
1880 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
1881 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
1883 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1884 AppendQuadsData data;
1885 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1886 active_layer_->AppendQuads(render_pass.get(), &data);
1887 active_layer_->DidDraw(nullptr);
1889 // All high res tiles drew, nothing was incomplete.
1890 EXPECT_EQ(9u, render_pass->quad_list.size());
1891 EXPECT_EQ(0u, data.num_missing_tiles);
1892 EXPECT_EQ(0u, data.num_incomplete_tiles);
1893 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
1896 TEST_F(PictureLayerImplTest, HighResTileIsIncomplete) {
1897 base::TimeTicks time_ticks;
1898 time_ticks += base::TimeDelta::FromMilliseconds(1);
1899 host_impl_.SetCurrentBeginFrameArgs(
1900 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1902 gfx::Size tile_size(100, 100);
1903 gfx::Size layer_bounds(200, 200);
1905 scoped_refptr<FakePicturePileImpl> pending_pile =
1906 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1907 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1908 ActivateTree();
1910 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1911 AppendQuadsData data;
1912 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1913 active_layer_->AppendQuads(render_pass.get(), &data);
1914 active_layer_->DidDraw(nullptr);
1916 EXPECT_EQ(1u, render_pass->quad_list.size());
1917 EXPECT_EQ(1u, data.num_missing_tiles);
1918 EXPECT_EQ(0u, data.num_incomplete_tiles);
1919 EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads());
1922 TEST_F(PictureLayerImplTest, HighResTileIsIncompleteLowResComplete) {
1923 base::TimeTicks time_ticks;
1924 time_ticks += base::TimeDelta::FromMilliseconds(1);
1925 host_impl_.SetCurrentBeginFrameArgs(
1926 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1928 gfx::Size tile_size(100, 100);
1929 gfx::Size layer_bounds(200, 200);
1931 scoped_refptr<FakePicturePileImpl> pending_pile =
1932 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1933 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1934 ActivateTree();
1936 std::vector<Tile*> low_tiles =
1937 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting();
1938 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles);
1940 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1941 AppendQuadsData data;
1942 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1943 active_layer_->AppendQuads(render_pass.get(), &data);
1944 active_layer_->DidDraw(nullptr);
1946 EXPECT_EQ(1u, render_pass->quad_list.size());
1947 EXPECT_EQ(0u, data.num_missing_tiles);
1948 EXPECT_EQ(1u, data.num_incomplete_tiles);
1949 EXPECT_TRUE(active_layer_->only_used_low_res_last_append_quads());
1952 TEST_F(PictureLayerImplTest, LowResTileIsIncomplete) {
1953 base::TimeTicks time_ticks;
1954 time_ticks += base::TimeDelta::FromMilliseconds(1);
1955 host_impl_.SetCurrentBeginFrameArgs(
1956 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1958 gfx::Size tile_size(100, 100);
1959 gfx::Size layer_bounds(200, 200);
1961 scoped_refptr<FakePicturePileImpl> pending_pile =
1962 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1963 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
1964 ActivateTree();
1966 // All high res tiles have resources except one.
1967 std::vector<Tile*> high_tiles =
1968 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
1969 high_tiles.erase(high_tiles.begin());
1970 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles);
1972 // All low res tiles have resources.
1973 std::vector<Tile*> low_tiles =
1974 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting();
1975 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles);
1977 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1978 AppendQuadsData data;
1979 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
1980 active_layer_->AppendQuads(render_pass.get(), &data);
1981 active_layer_->DidDraw(nullptr);
1983 // The missing high res tile was replaced by a low res tile.
1984 EXPECT_EQ(9u, render_pass->quad_list.size());
1985 EXPECT_EQ(0u, data.num_missing_tiles);
1986 EXPECT_EQ(1u, data.num_incomplete_tiles);
1987 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
1990 TEST_F(PictureLayerImplTest,
1991 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal) {
1992 base::TimeTicks time_ticks;
1993 time_ticks += base::TimeDelta::FromMilliseconds(1);
1994 host_impl_.SetCurrentBeginFrameArgs(
1995 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1997 gfx::Size tile_size(100, 100);
1998 gfx::Size layer_bounds(200, 200);
1999 gfx::Size viewport_size(400, 400);
2001 host_impl_.SetViewportSize(viewport_size);
2002 host_impl_.SetDeviceScaleFactor(2.f);
2004 scoped_refptr<FakePicturePileImpl> pending_pile =
2005 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2006 scoped_refptr<FakePicturePileImpl> active_pile =
2007 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2008 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
2010 // One ideal tile exists, this will get used when drawing.
2011 std::vector<Tile*> ideal_tiles;
2012 EXPECT_EQ(2.f, active_layer_->HighResTiling()->contents_scale());
2013 ideal_tiles.push_back(active_layer_->HighResTiling()->TileAt(0, 0));
2014 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
2015 ideal_tiles);
2017 // Due to layer scale throttling, the raster contents scale is changed to 1,
2018 // while the ideal is still 2.
2019 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
2020 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.f, 1.f, 1.f, 1.f, false);
2022 EXPECT_EQ(1.f, active_layer_->HighResTiling()->contents_scale());
2023 EXPECT_EQ(1.f, active_layer_->raster_contents_scale());
2024 EXPECT_EQ(2.f, active_layer_->ideal_contents_scale());
2026 // Both tilings still exist.
2027 EXPECT_EQ(2.f, active_layer_->tilings()->tiling_at(0)->contents_scale());
2028 EXPECT_EQ(1.f, active_layer_->tilings()->tiling_at(1)->contents_scale());
2030 // All high res tiles have resources.
2031 std::vector<Tile*> high_tiles =
2032 active_layer_->HighResTiling()->AllTilesForTesting();
2033 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles);
2035 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
2036 AppendQuadsData data;
2037 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
2038 active_layer_->AppendQuads(render_pass.get(), &data);
2039 active_layer_->DidDraw(nullptr);
2041 // All high res tiles drew, and the one ideal res tile drew.
2042 ASSERT_GT(render_pass->quad_list.size(), 9u);
2043 EXPECT_EQ(gfx::SizeF(99.f, 99.f),
2044 TileDrawQuad::MaterialCast(render_pass->quad_list.front())
2045 ->tex_coord_rect.size());
2046 EXPECT_EQ(gfx::SizeF(49.5f, 49.5f),
2047 TileDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(1))
2048 ->tex_coord_rect.size());
2050 // Neither the high res nor the ideal tiles were considered as incomplete.
2051 EXPECT_EQ(0u, data.num_missing_tiles);
2052 EXPECT_EQ(0u, data.num_incomplete_tiles);
2053 EXPECT_FALSE(active_layer_->only_used_low_res_last_append_quads());
2056 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveAllReady) {
2057 gfx::Size layer_bounds(400, 400);
2058 gfx::Size tile_size(100, 100);
2060 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size,
2061 gfx::Rect(layer_bounds));
2063 active_layer_->SetAllTilesReady();
2065 // All active tiles ready, so pending can only activate with all high res
2066 // tiles.
2067 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2068 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2070 AssertAllTilesRequired(pending_layer_->HighResTiling());
2071 AssertNoTilesRequired(pending_layer_->LowResTiling());
2074 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) {
2075 gfx::Size layer_bounds(400, 400);
2076 gfx::Size tile_size(100, 100);
2078 // No invalidation.
2079 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
2081 // Verify active tree not ready.
2082 Tile* some_active_tile =
2083 active_layer_->HighResTiling()->AllTilesForTesting()[0];
2084 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
2086 // When high res are required, all tiles in active high res tiling should be
2087 // required for activation.
2088 host_impl_.SetRequiresHighResToDraw();
2090 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2091 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2092 active_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2093 active_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2095 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
2096 EXPECT_TRUE(pending_layer_->LowResTiling()->AllTilesForTesting().empty());
2097 AssertAllTilesRequired(active_layer_->HighResTiling());
2098 AssertNoTilesRequired(active_layer_->LowResTiling());
2101 TEST_F(PictureLayerImplTest, AllHighResRequiredEvenIfNotChanged) {
2102 gfx::Size layer_bounds(400, 400);
2103 gfx::Size tile_size(100, 100);
2105 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
2107 Tile* some_active_tile =
2108 active_layer_->HighResTiling()->AllTilesForTesting()[0];
2109 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
2111 // Since there are no invalidations, pending tree should have no tiles.
2112 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
2113 EXPECT_TRUE(pending_layer_->LowResTiling()->AllTilesForTesting().empty());
2115 active_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2116 active_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2118 AssertAllTilesRequired(active_layer_->HighResTiling());
2119 AssertNoTilesRequired(active_layer_->LowResTiling());
2122 TEST_F(PictureLayerImplTest, DisallowRequiredForActivation) {
2123 gfx::Size layer_bounds(400, 400);
2124 gfx::Size tile_size(100, 100);
2126 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
2128 Tile* some_active_tile =
2129 active_layer_->HighResTiling()->AllTilesForTesting()[0];
2130 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
2132 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
2133 EXPECT_TRUE(pending_layer_->LowResTiling()->AllTilesForTesting().empty());
2134 active_layer_->HighResTiling()->set_can_require_tiles_for_activation(false);
2135 active_layer_->LowResTiling()->set_can_require_tiles_for_activation(false);
2136 pending_layer_->HighResTiling()->set_can_require_tiles_for_activation(false);
2137 pending_layer_->LowResTiling()->set_can_require_tiles_for_activation(false);
2139 // If we disallow required for activation, no tiles can be required.
2140 active_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2141 active_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2143 AssertNoTilesRequired(active_layer_->HighResTiling());
2144 AssertNoTilesRequired(active_layer_->LowResTiling());
2147 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) {
2148 gfx::Size layer_bounds(400, 400);
2149 gfx::Size tile_size(100, 100);
2151 scoped_refptr<FakePicturePileImpl> pending_pile =
2152 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2153 // This pile will create tilings, but has no recordings so will not create any
2154 // tiles. This is attempting to simulate scrolling past the end of recorded
2155 // content on the active layer, where the recordings are so far away that
2156 // no tiles are created.
2157 bool is_solid_color = false;
2158 scoped_refptr<FakePicturePileImpl> active_pile =
2159 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
2160 tile_size, layer_bounds, is_solid_color);
2162 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
2164 // Active layer has tilings, but no tiles due to missing recordings.
2165 EXPECT_TRUE(active_layer_->CanHaveTilings());
2166 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u);
2167 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u);
2169 // Since the active layer has no tiles at all, the pending layer doesn't
2170 // need content in order to activate.
2171 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2172 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2174 AssertNoTilesRequired(pending_layer_->HighResTiling());
2175 AssertNoTilesRequired(pending_layer_->LowResTiling());
2178 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) {
2179 gfx::Size layer_bounds(400, 400);
2180 gfx::Size tile_size(100, 100);
2182 scoped_refptr<FakePicturePileImpl> pending_pile =
2183 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2184 scoped_refptr<FakePicturePileImpl> active_pile =
2185 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
2186 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
2188 // Active layer can't have tiles.
2189 EXPECT_FALSE(active_layer_->CanHaveTilings());
2191 // All high res tiles required. This should be considered identical
2192 // to the case where there is no active layer, to avoid flashing content.
2193 // This can happen if a layer exists for a while and switches from
2194 // not being able to have content to having content.
2195 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2196 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2198 AssertAllTilesRequired(pending_layer_->HighResTiling());
2199 AssertNoTilesRequired(pending_layer_->LowResTiling());
2202 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveHasDifferentBounds) {
2203 gfx::Size pending_layer_bounds(400, 400);
2204 gfx::Size active_layer_bounds(200, 200);
2205 gfx::Size tile_size(100, 100);
2207 scoped_refptr<FakePicturePileImpl> pending_pile =
2208 FakePicturePileImpl::CreateFilledPile(tile_size, pending_layer_bounds);
2209 scoped_refptr<FakePicturePileImpl> active_pile =
2210 FakePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds);
2212 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
2214 // Since the active layer has different bounds, the pending layer needs all
2215 // high res tiles in order to activate.
2216 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2217 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2218 active_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2219 active_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
2221 AssertAllTilesRequired(pending_layer_->HighResTiling());
2222 AssertAllTilesRequired(active_layer_->HighResTiling());
2223 AssertNoTilesRequired(active_layer_->LowResTiling());
2224 // Since the test doesn't invalidate the resized region, we expect that the
2225 // same low res tile would exist (which means we don't create a new one of the
2226 // pending tree).
2227 EXPECT_TRUE(pending_layer_->LowResTiling()->AllTilesForTesting().empty());
2230 TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) {
2231 gfx::Size tile_size(100, 100);
2232 gfx::Size layer_bounds(400, 400);
2233 scoped_refptr<FakePicturePileImpl> pending_pile =
2234 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2236 host_impl_.CreatePendingTree();
2237 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
2239 scoped_ptr<FakePictureLayerImpl> pending_layer =
2240 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, id_,
2241 pending_pile);
2242 pending_layer->SetDrawsContent(true);
2243 pending_tree->SetRootLayer(pending_layer.Pass());
2245 pending_layer_ = static_cast<FakePictureLayerImpl*>(
2246 host_impl_.pending_tree()->LayerById(id_));
2248 // Set some state on the pending layer, make sure it is not clobbered
2249 // by a sync from the active layer. This could happen because if the
2250 // pending layer has not been post-commit initialized it will attempt
2251 // to sync from the active layer.
2252 float raster_page_scale = 10.f * pending_layer_->raster_page_scale();
2253 pending_layer_->set_raster_page_scale(raster_page_scale);
2255 host_impl_.ActivateSyncTree();
2257 active_layer_ = static_cast<FakePictureLayerImpl*>(
2258 host_impl_.active_tree()->LayerById(id_));
2260 EXPECT_EQ(0u, active_layer_->num_tilings());
2261 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale());
2264 TEST_F(PictureLayerImplTest, ShareTilesOnNextFrame) {
2265 gfx::Size layer_bounds(1500, 1500);
2266 gfx::Size tile_size(100, 100);
2268 scoped_refptr<FakePicturePileImpl> pending_pile =
2269 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2271 SetupPendingTree(pending_pile);
2273 PictureLayerTiling* tiling = pending_layer_->HighResTiling();
2274 gfx::Rect first_invalidate = tiling->TilingDataForTesting().TileBounds(0, 0);
2275 first_invalidate.Inset(tiling->TilingDataForTesting().border_texels(),
2276 tiling->TilingDataForTesting().border_texels());
2277 gfx::Rect second_invalidate = tiling->TilingDataForTesting().TileBounds(1, 1);
2278 second_invalidate.Inset(tiling->TilingDataForTesting().border_texels(),
2279 tiling->TilingDataForTesting().border_texels());
2281 ActivateTree();
2283 // Make a pending tree with an invalidated raster tile 0,0.
2284 SetupPendingTreeWithInvalidation(pending_pile, first_invalidate);
2286 // Activate and make a pending tree with an invalidated raster tile 1,1.
2287 ActivateTree();
2289 SetupPendingTreeWithInvalidation(pending_pile, second_invalidate);
2291 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2292 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2294 // pending_tiling->CreateAllTilesForTesting();
2296 // Tile 0,0 not exist on pending, but tile 1,1 should.
2297 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2298 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2299 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2300 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2301 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2302 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2303 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2304 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2305 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
2307 // Drop the tiles on the active tree and recreate them.
2308 active_tiling->ComputeTilePriorityRects(gfx::Rect(), 1.f, 1.0, Occlusion());
2309 EXPECT_TRUE(active_tiling->AllTilesForTesting().empty());
2310 active_tiling->CreateAllTilesForTesting();
2312 // Tile 0,0 not exist on pending, but tile 1,1 should.
2313 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2314 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2315 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2316 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2317 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2318 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2319 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2320 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2321 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
2324 TEST_F(PictureLayerImplTest, PendingHasNoTilesWithNoInvalidation) {
2325 SetupDefaultTrees(gfx::Size(1500, 1500));
2327 EXPECT_GE(active_layer_->num_tilings(), 1u);
2328 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2330 // No invalidation.
2331 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2332 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2333 ASSERT_TRUE(active_tiling);
2334 ASSERT_TRUE(pending_tiling);
2336 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2337 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2338 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2339 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2341 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2342 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2343 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2344 EXPECT_FALSE(pending_tiling->TileAt(1, 1));
2347 TEST_F(PictureLayerImplTest, ShareInvalidActiveTreeTiles) {
2348 gfx::Size tile_size(100, 100);
2349 gfx::Size layer_bounds(1500, 1500);
2351 scoped_refptr<FakePicturePileImpl> pending_pile =
2352 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2353 scoped_refptr<FakePicturePileImpl> active_pile =
2354 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2355 SetupTreesWithInvalidation(pending_pile, active_pile, gfx::Rect(1, 1));
2356 // Activate the invalidation.
2357 ActivateTree();
2358 // Make another pending tree without any invalidation in it.
2359 scoped_refptr<FakePicturePileImpl> pending_pile2 =
2360 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2361 SetupPendingTree(pending_pile2);
2363 EXPECT_GE(active_layer_->num_tilings(), 1u);
2364 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2366 // The active tree invalidation was handled by the active tiles.
2367 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2368 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2369 ASSERT_TRUE(active_tiling);
2370 ASSERT_TRUE(pending_tiling);
2372 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2373 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2374 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2375 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2377 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
2378 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2379 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2380 EXPECT_FALSE(pending_tiling->TileAt(1, 1));
2383 TEST_F(PictureLayerImplTest, RecreateInvalidPendingTreeTiles) {
2384 // Set some invalidation on the pending tree. We should replace raster tiles
2385 // that touch this.
2386 SetupDefaultTreesWithInvalidation(gfx::Size(1500, 1500), gfx::Rect(1, 1));
2388 EXPECT_GE(active_layer_->num_tilings(), 1u);
2389 EXPECT_GE(pending_layer_->num_tilings(), 1u);
2391 // The pending tree invalidation creates tiles on the pending tree.
2392 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2393 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2394 ASSERT_TRUE(active_tiling);
2395 ASSERT_TRUE(pending_tiling);
2397 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2398 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2399 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2400 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2402 EXPECT_TRUE(pending_tiling->TileAt(0, 0));
2403 EXPECT_FALSE(pending_tiling->TileAt(1, 0));
2404 EXPECT_FALSE(pending_tiling->TileAt(0, 1));
2405 EXPECT_FALSE(pending_tiling->TileAt(1, 1));
2407 EXPECT_NE(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2410 TEST_F(PictureLayerImplTest, SyncTilingAfterGpuRasterizationToggles) {
2411 base::TimeTicks time_ticks;
2412 time_ticks += base::TimeDelta::FromMilliseconds(1);
2413 host_impl_.SetCurrentBeginFrameArgs(
2414 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
2416 gfx::Size tile_size(100, 100);
2417 gfx::Size layer_bounds(10, 10);
2419 scoped_refptr<FakePicturePileImpl> pending_pile =
2420 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2421 scoped_refptr<FakePicturePileImpl> active_pile =
2422 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2424 SetupTrees(pending_pile, active_pile);
2426 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2427 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f));
2429 // Gpu rasterization is disabled by default.
2430 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
2431 // Toggling the gpu rasterization clears all tilings on both trees.
2432 host_impl_.SetUseGpuRasterization(true);
2433 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2434 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2436 // Make sure that we can still add tiling to the pending layer,
2437 // that gets synced to the active layer.
2438 time_ticks += base::TimeDelta::FromMilliseconds(1);
2439 host_impl_.SetCurrentBeginFrameArgs(
2440 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
2441 bool update_lcd_text = false;
2442 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
2443 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2445 ActivateTree();
2446 EXPECT_TRUE(active_layer_->tilings()->FindTilingWithScale(1.f));
2448 SetupPendingTree(pending_pile);
2449 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(1.f));
2451 // Toggling the gpu rasterization clears all tilings on both trees.
2452 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2453 host_impl_.SetUseGpuRasterization(false);
2454 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2455 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2458 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) {
2459 gfx::Size tile_size(100, 100);
2461 // Put 0.5 as high res.
2462 host_impl_.SetDeviceScaleFactor(0.5f);
2464 scoped_refptr<FakePicturePileImpl> pending_pile =
2465 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(10, 10));
2466 SetupPendingTree(pending_pile);
2468 // Sanity checks.
2469 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2470 EXPECT_TRUE(pending_layer_->tilings()->FindTilingWithScale(0.5f));
2472 ActivateTree();
2474 // Now, set the bounds to be 1x1, so that minimum contents scale becomes 1.
2475 pending_pile =
2476 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1, 1));
2477 SetupPendingTree(pending_pile);
2479 // Another sanity check.
2480 EXPECT_EQ(1.f, pending_layer_->MinimumContentsScale());
2482 // Since the MinContentsScale is 1, the 0.5 tiling should be replaced by a 1.0
2483 // tiling.
2484 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 0.5f, 1.f, 1.f, 1.f, false);
2486 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2487 PictureLayerTiling* tiling =
2488 pending_layer_->tilings()->FindTilingWithScale(1.0f);
2489 ASSERT_TRUE(tiling);
2490 EXPECT_EQ(HIGH_RESOLUTION, tiling->resolution());
2493 TEST_F(PictureLayerImplTest, LowResTilingWithoutGpuRasterization) {
2494 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
2495 gfx::Size layer_bounds(default_tile_size.width() * 4,
2496 default_tile_size.height() * 4);
2498 host_impl_.SetUseGpuRasterization(false);
2500 SetupDefaultTrees(layer_bounds);
2501 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
2502 // Should have a low-res and a high-res tiling.
2503 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
2506 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) {
2507 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
2508 gfx::Size layer_bounds(default_tile_size.width() * 4,
2509 default_tile_size.height() * 4);
2511 host_impl_.SetUseGpuRasterization(true);
2513 SetupDefaultTrees(layer_bounds);
2514 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2515 // Should only have the high-res tiling.
2516 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2519 TEST_F(PictureLayerImplTest, RequiredTilesWithGpuRasterization) {
2520 host_impl_.SetUseGpuRasterization(true);
2522 gfx::Size viewport_size(1000, 1000);
2523 host_impl_.SetViewportSize(viewport_size);
2525 gfx::Size layer_bounds(4000, 4000);
2526 SetupDefaultTrees(layer_bounds);
2527 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2529 // Should only have the high-res tiling.
2530 EXPECT_EQ(1u, active_layer_->tilings()->num_tilings());
2532 active_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
2534 // High res tiling should have 64 tiles (4x16 tile grid).
2535 EXPECT_EQ(64u, active_layer_->HighResTiling()->AllTilesForTesting().size());
2537 // Visible viewport should be covered by 4 tiles. No other
2538 // tiles should be required for activation.
2539 EXPECT_EQ(4u, NumberOfTilesRequired(active_layer_->HighResTiling()));
2542 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) {
2543 // Set up layers with tilings.
2544 SetupDefaultTrees(gfx::Size(10, 10));
2545 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false);
2546 pending_layer_->PushPropertiesTo(active_layer_);
2547 EXPECT_TRUE(pending_layer_->DrawsContent());
2548 EXPECT_TRUE(pending_layer_->CanHaveTilings());
2549 EXPECT_GE(pending_layer_->num_tilings(), 0u);
2550 EXPECT_GE(active_layer_->num_tilings(), 0u);
2552 // Set content to false, which should make CanHaveTilings return false.
2553 pending_layer_->SetDrawsContent(false);
2554 EXPECT_FALSE(pending_layer_->DrawsContent());
2555 EXPECT_FALSE(pending_layer_->CanHaveTilings());
2557 // No tilings should be pushed to active layer.
2558 pending_layer_->PushPropertiesTo(active_layer_);
2559 EXPECT_EQ(0u, active_layer_->num_tilings());
2562 TEST_F(PictureLayerImplTest, FirstTilingDuringPinch) {
2563 SetupDefaultTrees(gfx::Size(10, 10));
2565 // We start with a tiling at scale 1.
2566 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
2568 // When we scale up by 2.3, we get a new tiling that is a power of 2, in this
2569 // case 4.
2570 host_impl_.PinchGestureBegin();
2571 float high_res_scale = 2.3f;
2572 SetContentsScaleOnBothLayers(high_res_scale, 1.f, 1.f, 1.f, false);
2573 EXPECT_EQ(4.f, pending_layer_->HighResTiling()->contents_scale());
2576 TEST_F(PictureLayerImplTest, PinchingTooSmall) {
2577 SetupDefaultTrees(gfx::Size(10, 10));
2579 // We start with a tiling at scale 1.
2580 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
2582 host_impl_.PinchGestureBegin();
2583 float high_res_scale = 0.0001f;
2584 EXPECT_LT(high_res_scale, pending_layer_->MinimumContentsScale());
2586 SetContentsScaleOnBothLayers(high_res_scale, 1.f, high_res_scale, 1.f, false);
2587 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
2588 pending_layer_->HighResTiling()->contents_scale());
2591 TEST_F(PictureLayerImplTest, PinchingTooSmallWithContentsScale) {
2592 SetupDefaultTrees(gfx::Size(10, 10));
2594 ResetTilingsAndRasterScales();
2596 float contents_scale = 0.15f;
2597 SetContentsScaleOnBothLayers(contents_scale, 1.f, 1.f, 1.f, false);
2599 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2600 EXPECT_FLOAT_EQ(contents_scale,
2601 pending_layer_->HighResTiling()->contents_scale());
2603 host_impl_.PinchGestureBegin();
2605 float page_scale = 0.0001f;
2606 EXPECT_LT(page_scale * contents_scale,
2607 pending_layer_->MinimumContentsScale());
2609 SetContentsScaleOnBothLayers(contents_scale * page_scale, 1.f, page_scale,
2610 1.f, false);
2611 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2612 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
2613 pending_layer_->HighResTiling()->contents_scale());
2616 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForCpuRasterization) {
2617 gfx::Size viewport_size(1000, 1000);
2618 host_impl_.SetViewportSize(viewport_size);
2620 gfx::Size layer_bounds(100, 100);
2621 SetupDefaultTrees(layer_bounds);
2623 float contents_scale = 1.f;
2624 float device_scale = 1.f;
2625 float page_scale = 1.f;
2626 float maximum_animation_scale = 1.f;
2627 bool animating_transform = false;
2629 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2631 // Since we're CPU-rasterizing, starting an animation should cause tiling
2632 // resolution to get set to the maximum animation scale factor.
2633 animating_transform = true;
2634 maximum_animation_scale = 3.f;
2635 contents_scale = 2.f;
2637 SetContentsScaleOnBothLayers(contents_scale,
2638 device_scale,
2639 page_scale,
2640 maximum_animation_scale,
2641 animating_transform);
2642 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2644 // Further changes to scale during the animation should not cause a new
2645 // high-res tiling to get created.
2646 contents_scale = 4.f;
2647 maximum_animation_scale = 5.f;
2649 SetContentsScaleOnBothLayers(contents_scale,
2650 device_scale,
2651 page_scale,
2652 maximum_animation_scale,
2653 animating_transform);
2654 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2656 // Once we stop animating, a new high-res tiling should be created.
2657 animating_transform = false;
2659 SetContentsScaleOnBothLayers(contents_scale,
2660 device_scale,
2661 page_scale,
2662 maximum_animation_scale,
2663 animating_transform);
2664 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2666 // When animating with an unknown maximum animation scale factor, a new
2667 // high-res tiling should be created at a source scale of 1.
2668 animating_transform = true;
2669 contents_scale = 2.f;
2670 maximum_animation_scale = 0.f;
2672 SetContentsScaleOnBothLayers(contents_scale,
2673 device_scale,
2674 page_scale,
2675 maximum_animation_scale,
2676 animating_transform);
2677 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale * device_scale);
2679 // Further changes to scale during the animation should not cause a new
2680 // high-res tiling to get created.
2681 contents_scale = 3.f;
2683 SetContentsScaleOnBothLayers(contents_scale,
2684 device_scale,
2685 page_scale,
2686 maximum_animation_scale,
2687 animating_transform);
2688 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale * device_scale);
2690 // Once we stop animating, a new high-res tiling should be created.
2691 animating_transform = false;
2692 contents_scale = 4.f;
2694 SetContentsScaleOnBothLayers(contents_scale,
2695 device_scale,
2696 page_scale,
2697 maximum_animation_scale,
2698 animating_transform);
2699 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2701 // When animating with a maxmium animation scale factor that is so large
2702 // that the layer grows larger than the viewport at this scale, a new
2703 // high-res tiling should get created at a source scale of 1, not at its
2704 // maximum scale.
2705 animating_transform = true;
2706 contents_scale = 2.f;
2707 maximum_animation_scale = 11.f;
2709 SetContentsScaleOnBothLayers(contents_scale,
2710 device_scale,
2711 page_scale,
2712 maximum_animation_scale,
2713 animating_transform);
2714 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), page_scale * device_scale);
2716 // Once we stop animating, a new high-res tiling should be created.
2717 animating_transform = false;
2718 contents_scale = 11.f;
2720 SetContentsScaleOnBothLayers(contents_scale,
2721 device_scale,
2722 page_scale,
2723 maximum_animation_scale,
2724 animating_transform);
2725 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f);
2727 // When animating with a maxmium animation scale factor that is so large
2728 // that the layer grows larger than the viewport at this scale, and where
2729 // the intial source scale is < 1, a new high-res tiling should get created
2730 // at source scale 1.
2731 animating_transform = true;
2732 contents_scale = 0.1f;
2733 maximum_animation_scale = 11.f;
2735 SetContentsScaleOnBothLayers(contents_scale,
2736 device_scale,
2737 page_scale,
2738 maximum_animation_scale,
2739 animating_transform);
2740 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale * page_scale);
2742 // Once we stop animating, a new high-res tiling should be created.
2743 animating_transform = false;
2744 contents_scale = 12.f;
2746 SetContentsScaleOnBothLayers(contents_scale,
2747 device_scale,
2748 page_scale,
2749 maximum_animation_scale,
2750 animating_transform);
2751 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 12.f);
2753 // When animating toward a smaller scale, but that is still so large that the
2754 // layer grows larger than the viewport at this scale, a new high-res tiling
2755 // should get created at source scale 1.
2756 animating_transform = true;
2757 contents_scale = 11.f;
2758 maximum_animation_scale = 11.f;
2760 SetContentsScaleOnBothLayers(contents_scale,
2761 device_scale,
2762 page_scale,
2763 maximum_animation_scale,
2764 animating_transform);
2765 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale * page_scale);
2767 // Once we stop animating, a new high-res tiling should be created.
2768 animating_transform = false;
2769 contents_scale = 11.f;
2771 SetContentsScaleOnBothLayers(contents_scale,
2772 device_scale,
2773 page_scale,
2774 maximum_animation_scale,
2775 animating_transform);
2776 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f);
2779 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForGpuRasterization) {
2780 gfx::Size layer_bounds(100, 100);
2781 gfx::Size viewport_size(1000, 1000);
2782 SetupDefaultTrees(layer_bounds);
2783 host_impl_.SetViewportSize(viewport_size);
2784 host_impl_.SetUseGpuRasterization(true);
2786 float contents_scale = 1.f;
2787 float device_scale = 1.3f;
2788 float page_scale = 1.4f;
2789 float maximum_animation_scale = 1.f;
2790 bool animating_transform = false;
2792 SetContentsScaleOnBothLayers(contents_scale,
2793 device_scale,
2794 page_scale,
2795 maximum_animation_scale,
2796 animating_transform);
2797 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2799 // Since we're GPU-rasterizing, starting an animation should cause tiling
2800 // resolution to get set to the current contents scale.
2801 animating_transform = true;
2802 contents_scale = 2.f;
2803 maximum_animation_scale = 4.f;
2805 SetContentsScaleOnBothLayers(contents_scale,
2806 device_scale,
2807 page_scale,
2808 maximum_animation_scale,
2809 animating_transform);
2810 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
2812 // Further changes to scale during the animation should cause a new high-res
2813 // tiling to get created.
2814 contents_scale = 3.f;
2816 SetContentsScaleOnBothLayers(contents_scale,
2817 device_scale,
2818 page_scale,
2819 maximum_animation_scale,
2820 animating_transform);
2821 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2823 // Since we're re-rasterizing during the animation, scales smaller than 1
2824 // should be respected.
2825 contents_scale = 0.25f;
2827 SetContentsScaleOnBothLayers(contents_scale,
2828 device_scale,
2829 page_scale,
2830 maximum_animation_scale,
2831 animating_transform);
2832 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.25f);
2834 // Once we stop animating, a new high-res tiling should be created.
2835 contents_scale = 4.f;
2836 animating_transform = false;
2838 SetContentsScaleOnBothLayers(contents_scale,
2839 device_scale,
2840 page_scale,
2841 maximum_animation_scale,
2842 animating_transform);
2843 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2846 TEST_F(PictureLayerImplTest, TilingSetRasterQueue) {
2847 base::TimeTicks time_ticks;
2848 time_ticks += base::TimeDelta::FromMilliseconds(1);
2849 host_impl_.SetCurrentBeginFrameArgs(
2850 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
2852 host_impl_.SetViewportSize(gfx::Size(500, 500));
2854 gfx::Size recording_tile_size(100, 100);
2855 gfx::Size layer_bounds(1000, 1000);
2857 scoped_refptr<FakePicturePileImpl> pending_pile =
2858 FakePicturePileImpl::CreateFilledPile(recording_tile_size, layer_bounds);
2860 SetupPendingTree(pending_pile);
2861 EXPECT_EQ(2u, pending_layer_->num_tilings());
2863 std::set<Tile*> unique_tiles;
2864 bool reached_prepaint = false;
2865 int non_ideal_tile_count = 0u;
2866 int low_res_tile_count = 0u;
2867 int high_res_tile_count = 0u;
2868 int high_res_now_tiles = 0u;
2869 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
2870 pending_layer_->picture_layer_tiling_set(), false));
2871 while (!queue->IsEmpty()) {
2872 Tile* tile = queue->Top();
2873 TilePriority priority = tile->priority();
2875 EXPECT_TRUE(tile);
2877 // Non-high res tiles only get visible tiles. Also, prepaint should only
2878 // come at the end of the iteration.
2879 if (priority.resolution != HIGH_RESOLUTION) {
2880 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
2881 } else if (reached_prepaint) {
2882 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
2883 } else {
2884 reached_prepaint = priority.priority_bin != TilePriority::NOW;
2885 if (!reached_prepaint)
2886 ++high_res_now_tiles;
2889 non_ideal_tile_count += priority.resolution == NON_IDEAL_RESOLUTION;
2890 low_res_tile_count += priority.resolution == LOW_RESOLUTION;
2891 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
2893 unique_tiles.insert(tile);
2894 queue->Pop();
2897 EXPECT_TRUE(reached_prepaint);
2898 EXPECT_EQ(0, non_ideal_tile_count);
2899 EXPECT_EQ(0, low_res_tile_count);
2901 // With layer size being 1000x1000 and default tile size 256x256, we expect to
2902 // see 4 now tiles out of 16 total high res tiles.
2903 EXPECT_EQ(16, high_res_tile_count);
2904 EXPECT_EQ(4, high_res_now_tiles);
2905 EXPECT_EQ(low_res_tile_count + high_res_tile_count + non_ideal_tile_count,
2906 static_cast<int>(unique_tiles.size()));
2908 scoped_ptr<TilingSetRasterQueueRequired> required_queue(
2909 new TilingSetRasterQueueRequired(
2910 pending_layer_->picture_layer_tiling_set(),
2911 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW));
2912 EXPECT_TRUE(required_queue->IsEmpty());
2914 required_queue.reset(new TilingSetRasterQueueRequired(
2915 pending_layer_->picture_layer_tiling_set(),
2916 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION));
2917 EXPECT_FALSE(required_queue->IsEmpty());
2918 int required_for_activation_count = 0;
2919 while (!required_queue->IsEmpty()) {
2920 Tile* tile = required_queue->Top();
2921 EXPECT_TRUE(tile->required_for_activation());
2922 EXPECT_FALSE(tile->IsReadyToDraw());
2923 ++required_for_activation_count;
2924 required_queue->Pop();
2927 // All of the high res tiles should be required for activation, since there is
2928 // no active twin.
2929 EXPECT_EQ(high_res_now_tiles, required_for_activation_count);
2931 // No NOW tiles.
2932 time_ticks += base::TimeDelta::FromMilliseconds(200);
2933 host_impl_.SetCurrentBeginFrameArgs(
2934 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
2936 pending_layer_->draw_properties().visible_content_rect =
2937 gfx::Rect(1100, 1100, 500, 500);
2938 bool resourceless_software_draw = false;
2939 pending_layer_->UpdateTiles(resourceless_software_draw);
2941 unique_tiles.clear();
2942 high_res_tile_count = 0u;
2943 queue.reset(new TilingSetRasterQueueAll(
2944 pending_layer_->picture_layer_tiling_set(), false));
2945 while (!queue->IsEmpty()) {
2946 Tile* tile = queue->Top();
2947 TilePriority priority = tile->priority();
2949 EXPECT_TRUE(tile);
2951 // Non-high res tiles only get visible tiles.
2952 EXPECT_EQ(HIGH_RESOLUTION, priority.resolution);
2953 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
2955 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
2957 unique_tiles.insert(tile);
2958 queue->Pop();
2961 EXPECT_EQ(16, high_res_tile_count);
2962 EXPECT_EQ(high_res_tile_count, static_cast<int>(unique_tiles.size()));
2964 time_ticks += base::TimeDelta::FromMilliseconds(200);
2965 host_impl_.SetCurrentBeginFrameArgs(
2966 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
2968 pending_layer_->draw_properties().visible_content_rect =
2969 gfx::Rect(0, 0, 500, 500);
2970 pending_layer_->UpdateTiles(resourceless_software_draw);
2972 std::vector<Tile*> high_res_tiles =
2973 pending_layer_->HighResTiling()->AllTilesForTesting();
2974 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin();
2975 tile_it != high_res_tiles.end();
2976 ++tile_it) {
2977 Tile* tile = *tile_it;
2978 TileDrawInfo& draw_info = tile->draw_info();
2979 draw_info.SetSolidColorForTesting(SK_ColorRED);
2982 non_ideal_tile_count = 0;
2983 low_res_tile_count = 0;
2984 high_res_tile_count = 0;
2985 queue.reset(new TilingSetRasterQueueAll(
2986 pending_layer_->picture_layer_tiling_set(), true));
2987 while (!queue->IsEmpty()) {
2988 Tile* tile = queue->Top();
2989 TilePriority priority = tile->priority();
2991 EXPECT_TRUE(tile);
2993 non_ideal_tile_count += priority.resolution == NON_IDEAL_RESOLUTION;
2994 low_res_tile_count += priority.resolution == LOW_RESOLUTION;
2995 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
2996 queue->Pop();
2999 EXPECT_EQ(0, non_ideal_tile_count);
3000 EXPECT_EQ(1, low_res_tile_count);
3001 EXPECT_EQ(0, high_res_tile_count);
3004 TEST_F(PictureLayerImplTest, TilingSetRasterQueueActiveTree) {
3005 base::TimeTicks time_ticks;
3006 time_ticks += base::TimeDelta::FromMilliseconds(1);
3007 host_impl_.SetCurrentBeginFrameArgs(
3008 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
3010 host_impl_.SetViewportSize(gfx::Size(500, 500));
3012 gfx::Size tile_size(100, 100);
3013 gfx::Size layer_bounds(1000, 1000);
3015 scoped_refptr<FakePicturePileImpl> pending_pile =
3016 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3018 SetupPendingTree(pending_pile);
3019 ActivateTree();
3020 EXPECT_EQ(2u, active_layer_->num_tilings());
3022 scoped_ptr<TilingSetRasterQueueRequired> queue(
3023 new TilingSetRasterQueueRequired(
3024 active_layer_->picture_layer_tiling_set(),
3025 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW));
3026 EXPECT_FALSE(queue->IsEmpty());
3027 while (!queue->IsEmpty()) {
3028 Tile* tile = queue->Top();
3029 EXPECT_TRUE(tile->required_for_draw());
3030 EXPECT_FALSE(tile->IsReadyToDraw());
3031 queue->Pop();
3034 queue.reset(new TilingSetRasterQueueRequired(
3035 active_layer_->picture_layer_tiling_set(),
3036 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION));
3037 EXPECT_TRUE(queue->IsEmpty());
3040 TEST_F(PictureLayerImplTest, TilingSetRasterQueueRequiredNoHighRes) {
3041 scoped_ptr<FakePicturePile> empty_recording =
3042 FakePicturePile::CreateEmptyPile(gfx::Size(256, 256),
3043 gfx::Size(1024, 1024));
3044 empty_recording->SetIsSolidColor(true);
3046 scoped_refptr<FakePicturePileImpl> pending_pile =
3047 FakePicturePileImpl::CreateFromPile(empty_recording.get(), nullptr);
3049 SetupPendingTree(pending_pile);
3050 EXPECT_FALSE(
3051 pending_layer_->picture_layer_tiling_set()->FindTilingWithResolution(
3052 HIGH_RESOLUTION));
3054 scoped_ptr<TilingSetRasterQueueRequired> queue(
3055 new TilingSetRasterQueueRequired(
3056 pending_layer_->picture_layer_tiling_set(),
3057 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION));
3058 EXPECT_TRUE(queue->IsEmpty());
3061 TEST_F(PictureLayerImplTest, TilingSetEvictionQueue) {
3062 gfx::Size tile_size(100, 100);
3063 gfx::Size layer_bounds(1000, 1000);
3064 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3066 host_impl_.SetViewportSize(gfx::Size(500, 500));
3068 scoped_refptr<FakePicturePileImpl> pending_pile =
3069 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3071 // TODO(vmpstr): Add a test with tilings other than high/low res on the active
3072 // tree.
3073 SetupPendingTree(pending_pile);
3074 EXPECT_EQ(2u, pending_layer_->num_tilings());
3076 std::vector<Tile*> all_tiles;
3077 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3078 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3079 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
3080 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end());
3083 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end());
3085 bool mark_required = false;
3086 size_t number_of_marked_tiles = 0u;
3087 size_t number_of_unmarked_tiles = 0u;
3088 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3089 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3090 for (PictureLayerTiling::CoverageIterator iter(
3091 tiling,
3092 pending_layer_->contents_scale_x(),
3093 pending_layer_->visible_content_rect());
3094 iter;
3095 ++iter) {
3096 if (mark_required) {
3097 number_of_marked_tiles++;
3098 iter->set_required_for_activation(true);
3099 } else {
3100 number_of_unmarked_tiles++;
3102 mark_required = !mark_required;
3106 // Sanity checks.
3107 EXPECT_EQ(17u, all_tiles.size());
3108 EXPECT_EQ(17u, all_tiles_set.size());
3109 EXPECT_GT(number_of_marked_tiles, 1u);
3110 EXPECT_GT(number_of_unmarked_tiles, 1u);
3112 // Tiles don't have resources yet.
3113 scoped_ptr<TilingSetEvictionQueue> queue(new TilingSetEvictionQueue(
3114 pending_layer_->picture_layer_tiling_set(), false));
3115 EXPECT_TRUE(queue->IsEmpty());
3117 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
3119 std::set<Tile*> unique_tiles;
3120 float expected_scales[] = {low_res_factor, 1.f};
3121 size_t scale_index = 0;
3122 bool reached_visible = false;
3123 Tile* last_tile = nullptr;
3124 size_t distance_decreasing = 0;
3125 size_t distance_increasing = 0;
3126 queue.reset(new TilingSetEvictionQueue(
3127 pending_layer_->picture_layer_tiling_set(), false));
3128 while (!queue->IsEmpty()) {
3129 Tile* tile = queue->Top();
3130 if (!last_tile)
3131 last_tile = tile;
3133 EXPECT_TRUE(tile);
3135 TilePriority priority = tile->priority();
3137 if (priority.priority_bin == TilePriority::NOW) {
3138 reached_visible = true;
3139 last_tile = tile;
3140 break;
3143 EXPECT_FALSE(tile->required_for_activation());
3145 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) >
3146 std::numeric_limits<float>::epsilon()) {
3147 ++scale_index;
3148 ASSERT_LT(scale_index, arraysize(expected_scales));
3151 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]);
3152 unique_tiles.insert(tile);
3154 if (tile->required_for_activation() ==
3155 last_tile->required_for_activation() &&
3156 std::abs(tile->contents_scale() - last_tile->contents_scale()) <
3157 std::numeric_limits<float>::epsilon()) {
3158 if (priority.distance_to_visible <=
3159 last_tile->priority().distance_to_visible)
3160 ++distance_decreasing;
3161 else
3162 ++distance_increasing;
3165 last_tile = tile;
3166 queue->Pop();
3169 // 4 high res tiles are inside the viewport, the rest are evicted.
3170 EXPECT_TRUE(reached_visible);
3171 EXPECT_EQ(12u, unique_tiles.size());
3172 EXPECT_EQ(1u, distance_increasing);
3173 EXPECT_EQ(11u, distance_decreasing);
3175 scale_index = 0;
3176 bool reached_required = false;
3177 while (!queue->IsEmpty()) {
3178 Tile* tile = queue->Top();
3179 EXPECT_TRUE(tile);
3181 TilePriority priority = tile->priority();
3182 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
3184 if (reached_required) {
3185 EXPECT_TRUE(tile->required_for_activation());
3186 } else if (tile->required_for_activation()) {
3187 reached_required = true;
3188 scale_index = 0;
3191 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) >
3192 std::numeric_limits<float>::epsilon()) {
3193 ++scale_index;
3194 ASSERT_LT(scale_index, arraysize(expected_scales));
3197 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]);
3198 unique_tiles.insert(tile);
3199 queue->Pop();
3202 EXPECT_TRUE(reached_required);
3203 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size());
3206 TEST_F(PictureLayerImplTest, Occlusion) {
3207 gfx::Size tile_size(102, 102);
3208 gfx::Size layer_bounds(1000, 1000);
3209 gfx::Size viewport_size(1000, 1000);
3211 LayerTestCommon::LayerImplTest impl;
3212 host_impl_.SetViewportSize(viewport_size);
3214 scoped_refptr<FakePicturePileImpl> pending_pile =
3215 FakePicturePileImpl::CreateFilledPile(layer_bounds, layer_bounds);
3216 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
3217 ActivateTree();
3219 std::vector<Tile*> tiles =
3220 active_layer_->HighResTiling()->AllTilesForTesting();
3221 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
3224 SCOPED_TRACE("No occlusion");
3225 gfx::Rect occluded;
3226 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
3228 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
3229 gfx::Rect(layer_bounds));
3230 EXPECT_EQ(100u, impl.quad_list().size());
3234 SCOPED_TRACE("Full occlusion");
3235 gfx::Rect occluded(active_layer_->visible_content_rect());
3236 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
3238 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
3239 EXPECT_EQ(impl.quad_list().size(), 0u);
3243 SCOPED_TRACE("Partial occlusion");
3244 gfx::Rect occluded(150, 0, 200, 1000);
3245 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
3247 size_t partially_occluded_count = 0;
3248 LayerTestCommon::VerifyQuadsAreOccluded(
3249 impl.quad_list(), occluded, &partially_occluded_count);
3250 // The layer outputs one quad, which is partially occluded.
3251 EXPECT_EQ(100u - 10u, impl.quad_list().size());
3252 EXPECT_EQ(10u + 10u, partially_occluded_count);
3256 TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) {
3257 gfx::Size tile_size(host_impl_.settings().default_tile_size);
3258 SetupDefaultTrees(tile_size);
3260 ResetTilingsAndRasterScales();
3262 float contents_scale = 2.f;
3263 float device_scale = 1.f;
3264 float page_scale = 1.f;
3265 float maximum_animation_scale = 1.f;
3266 bool animating_transform = false;
3268 SetContentsScaleOnBothLayers(contents_scale,
3269 device_scale,
3270 page_scale,
3271 maximum_animation_scale,
3272 animating_transform);
3273 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
3275 // Changing the source scale without being in an animation will cause
3276 // the layer to reset its source scale to 1.f.
3277 contents_scale = 3.f;
3279 SetContentsScaleOnBothLayers(contents_scale,
3280 device_scale,
3281 page_scale,
3282 maximum_animation_scale,
3283 animating_transform);
3284 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
3286 // Further changes to the source scale will no longer be reflected in the
3287 // contents scale.
3288 contents_scale = 0.5f;
3290 SetContentsScaleOnBothLayers(contents_scale,
3291 device_scale,
3292 page_scale,
3293 maximum_animation_scale,
3294 animating_transform);
3295 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
3298 TEST_F(PictureLayerImplTest, LowResReadyToDrawNotEnoughToActivate) {
3299 gfx::Size tile_size(100, 100);
3300 gfx::Size layer_bounds(1000, 1000);
3302 // Make sure pending tree has tiles.
3303 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3304 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3306 // All pending layer tiles required are not ready.
3307 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3309 // Initialize all low-res tiles.
3310 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->LowResTiling());
3311 pending_layer_->SetAllTilesReadyInTiling(active_layer_->LowResTiling());
3313 // Low-res tiles should not be enough.
3314 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3316 // Initialize remaining tiles.
3317 pending_layer_->SetAllTilesReady();
3318 active_layer_->SetAllTilesReady();
3320 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
3323 TEST_F(PictureLayerImplTest, HighResReadyToDrawEnoughToActivate) {
3324 gfx::Size tile_size(100, 100);
3325 gfx::Size layer_bounds(1000, 1000);
3327 // Make sure pending tree has tiles.
3328 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3329 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3331 // All pending layer tiles required are not ready.
3332 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3334 // Initialize all high-res tiles.
3335 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
3336 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling());
3338 // High-res tiles should be enough, since they cover everything visible.
3339 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
3342 TEST_F(PictureLayerImplTest,
3343 ActiveHighResReadyAndPendingLowResReadyNotEnoughToActivate) {
3344 gfx::Size tile_size(100, 100);
3345 gfx::Size layer_bounds(1000, 1000);
3347 // Make sure pending tree has tiles.
3348 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3349 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3351 // Initialize all high-res tiles in the active layer.
3352 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling());
3353 // And all the low-res tiles in the pending layer.
3354 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->LowResTiling());
3356 // The pending high-res tiles are not ready, so we cannot activate.
3357 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3359 // When the pending high-res tiles are ready, we can activate.
3360 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
3361 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
3364 TEST_F(PictureLayerImplTest, ActiveHighResReadyNotEnoughToActivate) {
3365 gfx::Size tile_size(100, 100);
3366 gfx::Size layer_bounds(1000, 1000);
3368 // Make sure pending tree has tiles.
3369 gfx::Rect invalidation(gfx::Point(50, 50), tile_size);
3370 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, invalidation);
3372 // Initialize all high-res tiles in the active layer.
3373 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling());
3375 // The pending high-res tiles are not ready, so we cannot activate.
3376 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
3378 // When the pending pending high-res tiles are ready, we can activate.
3379 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
3380 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
3383 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) {
3384 gfx::Size tile_size(400, 400);
3385 gfx::Size layer_bounds(1300, 1900);
3387 scoped_refptr<FakePicturePileImpl> pending_pile =
3388 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3389 scoped_refptr<FakePicturePileImpl> active_pile =
3390 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3392 SetupTrees(pending_pile, active_pile);
3394 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3395 EXPECT_LT(low_res_factor, 1.f);
3397 ResetTilingsAndRasterScales();
3399 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3400 6.f, // ideal contents scale
3401 3.f, // device scale
3402 2.f, // page scale
3403 1.f, // maximum animation scale
3404 false);
3405 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3406 EXPECT_FLOAT_EQ(6.f,
3407 active_layer_->tilings()->tiling_at(0)->contents_scale());
3409 // If we change the page scale factor, then we should get new tilings.
3410 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3411 6.6f, // ideal contents scale
3412 3.f, // device scale
3413 2.2f, // page scale
3414 1.f, // maximum animation scale
3415 false);
3416 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3417 EXPECT_FLOAT_EQ(6.6f,
3418 active_layer_->tilings()->tiling_at(0)->contents_scale());
3420 // If we change the device scale factor, then we should get new tilings.
3421 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3422 7.26f, // ideal contents scale
3423 3.3f, // device scale
3424 2.2f, // page scale
3425 1.f, // maximum animation scale
3426 false);
3427 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
3428 EXPECT_FLOAT_EQ(7.26f,
3429 active_layer_->tilings()->tiling_at(0)->contents_scale());
3431 // If we change the device scale factor, but end up at the same total scale
3432 // factor somehow, then we don't get new tilings.
3433 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3434 7.26f, // ideal contents scale
3435 2.2f, // device scale
3436 3.3f, // page scale
3437 1.f, // maximum animation scale
3438 false);
3439 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
3440 EXPECT_FLOAT_EQ(7.26f,
3441 active_layer_->tilings()->tiling_at(0)->contents_scale());
3444 TEST_F(NoLowResPictureLayerImplTest, PendingLayerOnlyHasHighResTiling) {
3445 gfx::Size tile_size(400, 400);
3446 gfx::Size layer_bounds(1300, 1900);
3448 scoped_refptr<FakePicturePileImpl> pending_pile =
3449 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3450 scoped_refptr<FakePicturePileImpl> active_pile =
3451 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3453 SetupTrees(pending_pile, active_pile);
3455 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3456 EXPECT_LT(low_res_factor, 1.f);
3458 ResetTilingsAndRasterScales();
3460 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3461 6.f, // ideal contents scale
3462 3.f, // device scale
3463 2.f, // page scale
3464 1.f, // maximum animation scale
3465 false);
3466 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3467 EXPECT_FLOAT_EQ(6.f,
3468 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3470 // If we change the page scale factor, then we should get new tilings.
3471 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3472 6.6f, // ideal contents scale
3473 3.f, // device scale
3474 2.2f, // page scale
3475 1.f, // maximum animation scale
3476 false);
3477 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3478 EXPECT_FLOAT_EQ(6.6f,
3479 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3481 // If we change the device scale factor, then we should get new tilings.
3482 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3483 7.26f, // ideal contents scale
3484 3.3f, // device scale
3485 2.2f, // page scale
3486 1.f, // maximum animation scale
3487 false);
3488 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3489 EXPECT_FLOAT_EQ(7.26f,
3490 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3492 // If we change the device scale factor, but end up at the same total scale
3493 // factor somehow, then we don't get new tilings.
3494 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3495 7.26f, // ideal contents scale
3496 2.2f, // device scale
3497 3.3f, // page scale
3498 1.f, // maximum animation scale
3499 false);
3500 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3501 EXPECT_FLOAT_EQ(7.26f,
3502 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3505 TEST_F(NoLowResPictureLayerImplTest, AllHighResRequiredEvenIfNotChanged) {
3506 gfx::Size layer_bounds(400, 400);
3507 gfx::Size tile_size(100, 100);
3509 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
3511 Tile* some_active_tile =
3512 active_layer_->HighResTiling()->AllTilesForTesting()[0];
3513 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
3515 // Since there is no invalidation, pending tree should have no tiles.
3516 EXPECT_TRUE(pending_layer_->HighResTiling()->AllTilesForTesting().empty());
3517 if (host_impl_.settings().create_low_res_tiling)
3518 EXPECT_TRUE(pending_layer_->LowResTiling()->AllTilesForTesting().empty());
3520 active_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
3521 if (host_impl_.settings().create_low_res_tiling)
3522 active_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
3524 AssertAllTilesRequired(active_layer_->HighResTiling());
3525 if (host_impl_.settings().create_low_res_tiling)
3526 AssertNoTilesRequired(active_layer_->LowResTiling());
3529 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) {
3530 gfx::Size layer_bounds(400, 400);
3531 gfx::Size tile_size(100, 100);
3533 scoped_refptr<FakePicturePileImpl> pending_pile =
3534 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3535 // This pile will create tilings, but has no recordings so will not create any
3536 // tiles. This is attempting to simulate scrolling past the end of recorded
3537 // content on the active layer, where the recordings are so far away that
3538 // no tiles are created.
3539 bool is_solid_color = false;
3540 scoped_refptr<FakePicturePileImpl> active_pile =
3541 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
3542 tile_size, layer_bounds, is_solid_color);
3544 SetupTreesWithFixedTileSize(pending_pile, active_pile, tile_size, Region());
3546 // Active layer has tilings, but no tiles due to missing recordings.
3547 EXPECT_TRUE(active_layer_->CanHaveTilings());
3548 EXPECT_EQ(active_layer_->tilings()->num_tilings(),
3549 host_impl_.settings().create_low_res_tiling ? 2u : 1u);
3550 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u);
3552 // Since the active layer has no tiles at all, the pending layer doesn't
3553 // need content in order to activate.
3554 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
3555 if (host_impl_.settings().create_low_res_tiling)
3556 pending_layer_->LowResTiling()->UpdateAllTilePrioritiesForTesting();
3558 AssertNoTilesRequired(pending_layer_->HighResTiling());
3559 if (host_impl_.settings().create_low_res_tiling)
3560 AssertNoTilesRequired(pending_layer_->LowResTiling());
3563 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) {
3564 base::TimeTicks time_ticks;
3565 time_ticks += base::TimeDelta::FromMilliseconds(1);
3566 host_impl_.SetCurrentBeginFrameArgs(
3567 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
3569 gfx::Size tile_size(100, 100);
3570 gfx::Size layer_bounds(400, 400);
3572 scoped_refptr<FakePicturePileImpl> pending_pile =
3573 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3574 scoped_refptr<FakePicturePileImpl> active_pile =
3575 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3577 SetupTreesWithInvalidation(pending_pile, active_pile, Region());
3579 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
3581 // UpdateTiles with valid viewport. Should update tile viewport.
3582 // Note viewport is considered invalid if and only if in resourceless
3583 // software draw.
3584 bool resourceless_software_draw = false;
3585 gfx::Rect viewport = gfx::Rect(layer_bounds);
3586 gfx::Transform transform;
3587 host_impl_.SetExternalDrawConstraints(transform,
3588 viewport,
3589 viewport,
3590 viewport,
3591 transform,
3592 resourceless_software_draw);
3593 active_layer_->draw_properties().visible_content_rect = viewport;
3594 active_layer_->draw_properties().screen_space_transform = transform;
3595 active_layer_->UpdateTiles(resourceless_software_draw);
3597 gfx::Rect visible_rect_for_tile_priority =
3598 active_layer_->visible_rect_for_tile_priority();
3599 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty());
3600 gfx::Transform screen_space_transform_for_tile_priority =
3601 active_layer_->screen_space_transform();
3603 // Expand viewport and set it as invalid for prioritizing tiles.
3604 // Should update viewport and transform, but not update visible rect.
3605 time_ticks += base::TimeDelta::FromMilliseconds(200);
3606 host_impl_.SetCurrentBeginFrameArgs(
3607 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
3608 resourceless_software_draw = true;
3609 viewport = gfx::ScaleToEnclosingRect(viewport, 2);
3610 transform.Translate(1.f, 1.f);
3611 active_layer_->draw_properties().visible_content_rect = viewport;
3612 active_layer_->draw_properties().screen_space_transform = transform;
3613 host_impl_.SetExternalDrawConstraints(transform,
3614 viewport,
3615 viewport,
3616 viewport,
3617 transform,
3618 resourceless_software_draw);
3619 active_layer_->UpdateTiles(resourceless_software_draw);
3621 // Transform for tile priority is updated.
3622 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
3623 active_layer_->screen_space_transform());
3624 // Visible rect for tile priority retains old value.
3625 EXPECT_EQ(visible_rect_for_tile_priority,
3626 active_layer_->visible_rect_for_tile_priority());
3628 // Keep expanded viewport but mark it valid. Should update tile viewport.
3629 time_ticks += base::TimeDelta::FromMilliseconds(200);
3630 host_impl_.SetCurrentBeginFrameArgs(
3631 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
3632 resourceless_software_draw = false;
3633 host_impl_.SetExternalDrawConstraints(transform,
3634 viewport,
3635 viewport,
3636 viewport,
3637 transform,
3638 resourceless_software_draw);
3639 active_layer_->UpdateTiles(resourceless_software_draw);
3641 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
3642 active_layer_->screen_space_transform());
3643 EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority());
3646 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) {
3647 gfx::Size tile_size(400, 400);
3648 gfx::Size layer_bounds(1300, 1900);
3650 scoped_refptr<FakePicturePileImpl> pending_pile =
3651 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3652 scoped_refptr<FakePicturePileImpl> active_pile =
3653 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3655 std::vector<PictureLayerTiling*> used_tilings;
3657 SetupTrees(pending_pile, active_pile);
3659 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3660 EXPECT_LT(low_res_factor, 1.f);
3662 float device_scale = 1.7f;
3663 float page_scale = 3.2f;
3664 float scale = 1.f;
3666 ResetTilingsAndRasterScales();
3668 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false);
3669 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3671 // Ensure UpdateTiles won't remove any tilings. Note this is unrelated to
3672 // |used_tilings| variable, and it's here only to ensure that active_layer_
3673 // won't remove tilings before the test has a chance to verify behavior.
3674 active_layer_->MarkAllTilingsUsed();
3676 // We only have ideal tilings, so they aren't removed.
3677 used_tilings.clear();
3678 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3679 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3681 host_impl_.PinchGestureBegin();
3683 // Changing the ideal but not creating new tilings.
3684 scale *= 1.5f;
3685 page_scale *= 1.5f;
3686 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false);
3687 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3689 // The tilings are still our target scale, so they aren't removed.
3690 used_tilings.clear();
3691 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3692 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3694 host_impl_.PinchGestureEnd();
3696 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
3697 scale /= 4.f;
3698 page_scale /= 4.f;
3699 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, false);
3700 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3701 EXPECT_FLOAT_EQ(1.f,
3702 active_layer_->tilings()->tiling_at(1)->contents_scale());
3704 // Ensure UpdateTiles won't remove any tilings.
3705 active_layer_->MarkAllTilingsUsed();
3707 // Mark the non-ideal tilings as used. They won't be removed.
3708 used_tilings.clear();
3709 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
3710 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3711 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3713 // Now move the ideal scale to 0.5. Our target stays 1.2.
3714 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, false);
3716 // The high resolution tiling is between target and ideal, so is not
3717 // removed. The low res tiling for the old ideal=1.0 scale is removed.
3718 used_tilings.clear();
3719 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3720 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3722 // Now move the ideal scale to 1.0. Our target stays 1.2.
3723 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false);
3725 // All the tilings are between are target and the ideal, so they are not
3726 // removed.
3727 used_tilings.clear();
3728 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3729 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3731 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
3732 SetupDrawPropertiesAndUpdateTiles(
3733 active_layer_, 1.1f, device_scale, page_scale, 1.f, false);
3735 // Because the pending layer's ideal scale is still 1.0, our tilings fall
3736 // in the range [1.0,1.2] and are kept.
3737 used_tilings.clear();
3738 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3739 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3741 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
3742 // 1.2 still.
3743 SetupDrawPropertiesAndUpdateTiles(
3744 pending_layer_, 1.1f, device_scale, page_scale, 1.f, false);
3746 // Our 1.0 tiling now falls outside the range between our ideal scale and our
3747 // target raster scale. But it is in our used tilings set, so nothing is
3748 // deleted.
3749 used_tilings.clear();
3750 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
3751 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3752 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3754 // If we remove it from our used tilings set, it is outside the range to keep
3755 // so it is deleted.
3756 used_tilings.clear();
3757 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3758 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3761 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) {
3762 gfx::Size tile_size(400, 400);
3763 gfx::Size layer_bounds(1300, 1900);
3765 scoped_refptr<FakePicturePileImpl> pending_pile =
3766 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3767 scoped_refptr<FakePicturePileImpl> active_pile =
3768 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3770 SetupTrees(pending_pile, active_pile);
3771 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3772 EXPECT_EQ(1u, active_layer_->tilings()->num_tilings());
3774 // All tilings should be removed when losing output surface.
3775 active_layer_->ReleaseResources();
3776 EXPECT_FALSE(active_layer_->tilings());
3777 active_layer_->RecreateResources();
3778 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
3779 pending_layer_->ReleaseResources();
3780 EXPECT_FALSE(pending_layer_->tilings());
3781 pending_layer_->RecreateResources();
3782 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3784 // This should create new tilings.
3785 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3786 1.3f, // ideal contents scale
3787 2.7f, // device scale
3788 3.2f, // page scale
3789 1.f, // maximum animation scale
3790 false);
3791 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3794 TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) {
3795 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
3797 gfx::Size tile_size(400, 400);
3798 gfx::Size layer_bounds(1000, 2000);
3800 host_impl_.SetViewportSize(gfx::Size(10000, 20000));
3802 scoped_refptr<FakePicturePileImpl> pending_pile =
3803 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3804 scoped_refptr<FakePicturePileImpl> active_pile =
3805 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3807 SetupTrees(pending_pile, active_pile);
3809 ResetTilingsAndRasterScales();
3810 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.5f, 1.f, 1.f, 1.f, false);
3812 float max_contents_scale = active_layer_->MaximumTilingContentsScale();
3813 EXPECT_EQ(2.5f, max_contents_scale);
3815 gfx::Transform scaled_draw_transform = active_layer_->draw_transform();
3816 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale,
3817 SK_MScalar1 / max_contents_scale);
3819 AppendQuadsData data;
3820 active_layer_->AppendQuads(render_pass.get(), &data);
3822 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
3823 EXPECT_EQ(1u, render_pass->shared_quad_state_list.size());
3824 // The content_to_target_transform should be scaled by the
3825 // MaximumTilingContentsScale on the layer.
3826 EXPECT_EQ(scaled_draw_transform.ToString(),
3827 render_pass->shared_quad_state_list.front()
3828 ->content_to_target_transform.ToString());
3829 // The content_bounds should be scaled by the
3830 // MaximumTilingContentsScale on the layer.
3831 EXPECT_EQ(
3832 gfx::Size(2500u, 5000u).ToString(),
3833 render_pass->shared_quad_state_list.front()->content_bounds.ToString());
3834 // The visible_content_rect should be scaled by the
3835 // MaximumTilingContentsScale on the layer.
3836 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
3837 render_pass->shared_quad_state_list.front()
3838 ->visible_content_rect.ToString());
3841 class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest {
3842 public:
3843 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {}
3845 void InitializeRenderer() override {
3846 host_impl_.InitializeRenderer(FakeOutputSurface::CreateDelegating3d());
3850 TEST_F(PictureLayerImplTestWithDelegatingRenderer,
3851 DelegatingRendererWithTileOOM) {
3852 // This test is added for crbug.com/402321, where quad should be produced when
3853 // raster on demand is not allowed and tile is OOM.
3854 gfx::Size tile_size = host_impl_.settings().default_tile_size;
3855 gfx::Size layer_bounds(1000, 1000);
3857 // Create tiles.
3858 scoped_refptr<FakePicturePileImpl> pending_pile =
3859 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3860 SetupPendingTree(pending_pile);
3861 pending_layer_->SetBounds(layer_bounds);
3862 ActivateTree();
3863 bool update_lcd_text = false;
3864 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
3865 std::vector<Tile*> tiles =
3866 active_layer_->HighResTiling()->AllTilesForTesting();
3867 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
3869 // Force tiles after max_tiles to be OOM. TileManager uses
3870 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3871 // directly set state to host_impl_, so we set policy that would change the
3872 // state. We also need to update tree priority separately.
3873 GlobalStateThatImpactsTilePriority state;
3874 size_t max_tiles = 1;
3875 size_t memory_limit = max_tiles * 4 * tile_size.width() * tile_size.height();
3876 size_t resource_limit = max_tiles;
3877 ManagedMemoryPolicy policy(memory_limit,
3878 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
3879 resource_limit);
3880 host_impl_.SetMemoryPolicy(policy);
3881 host_impl_.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES);
3882 host_impl_.PrepareTiles();
3884 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
3885 AppendQuadsData data;
3886 active_layer_->WillDraw(DRAW_MODE_HARDWARE, nullptr);
3887 active_layer_->AppendQuads(render_pass.get(), &data);
3888 active_layer_->DidDraw(nullptr);
3890 // Even when OOM, quads should be produced, and should be different material
3891 // from quads with resource.
3892 EXPECT_LT(max_tiles, render_pass->quad_list.size());
3893 EXPECT_EQ(DrawQuad::Material::TILED_CONTENT,
3894 render_pass->quad_list.front()->material);
3895 EXPECT_EQ(DrawQuad::Material::SOLID_COLOR,
3896 render_pass->quad_list.back()->material);
3899 class OcclusionTrackingSettings : public LowResTilingsSettings {
3900 public:
3901 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; }
3904 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest {
3905 public:
3906 OcclusionTrackingPictureLayerImplTest()
3907 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
3909 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl* layer,
3910 FakePictureLayerImpl* twin_layer,
3911 WhichTree tree,
3912 size_t expected_occluded_tile_count,
3913 int source_line) {
3914 size_t occluded_tile_count = 0u;
3915 Tile* last_tile = nullptr;
3917 scoped_ptr<TilingSetEvictionQueue> queue(new TilingSetEvictionQueue(
3918 layer->picture_layer_tiling_set(), layer && twin_layer));
3919 while (!queue->IsEmpty()) {
3920 Tile* tile = queue->Top();
3921 if (!last_tile)
3922 last_tile = tile;
3924 // The only way we will encounter an occluded tile after an unoccluded
3925 // tile is if the priorty bin decreased, the tile is required for
3926 // activation, or the scale changed.
3927 bool tile_is_occluded = tile->is_occluded();
3928 if (tile_is_occluded) {
3929 occluded_tile_count++;
3931 bool last_tile_is_occluded = last_tile->is_occluded();
3932 if (!last_tile_is_occluded) {
3933 TilePriority::PriorityBin tile_priority_bin =
3934 tile->priority().priority_bin;
3935 TilePriority::PriorityBin last_tile_priority_bin =
3936 last_tile->priority().priority_bin;
3938 EXPECT_TRUE(tile_priority_bin < last_tile_priority_bin ||
3939 tile->required_for_activation() ||
3940 tile->contents_scale() != last_tile->contents_scale())
3941 << "line: " << source_line;
3944 last_tile = tile;
3945 queue->Pop();
3947 EXPECT_EQ(expected_occluded_tile_count, occluded_tile_count)
3948 << "line: " << source_line;
3952 TEST_F(OcclusionTrackingPictureLayerImplTest,
3953 OccludedTilesSkippedDuringRasterization) {
3954 base::TimeTicks time_ticks;
3955 time_ticks += base::TimeDelta::FromMilliseconds(1);
3956 host_impl_.SetCurrentBeginFrameArgs(
3957 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
3959 gfx::Size tile_size(102, 102);
3960 gfx::Size layer_bounds(1000, 1000);
3961 gfx::Size viewport_size(500, 500);
3962 gfx::Point occluding_layer_position(310, 0);
3964 host_impl_.SetViewportSize(viewport_size);
3966 scoped_refptr<FakePicturePileImpl> pending_pile =
3967 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3968 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
3970 // No occlusion.
3971 int unoccluded_tile_count = 0;
3972 scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
3973 pending_layer_->picture_layer_tiling_set(), false));
3974 while (!queue->IsEmpty()) {
3975 Tile* tile = queue->Top();
3977 // Occluded tiles should not be iterated over.
3978 EXPECT_FALSE(tile->is_occluded());
3980 // Some tiles may not be visible (i.e. outside the viewport). The rest are
3981 // visible and at least partially unoccluded, verified by the above expect.
3982 bool tile_is_visible =
3983 tile->content_rect().Intersects(pending_layer_->visible_content_rect());
3984 if (tile_is_visible)
3985 unoccluded_tile_count++;
3986 queue->Pop();
3988 EXPECT_EQ(unoccluded_tile_count, 25);
3990 // Partial occlusion.
3991 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
3992 LayerImpl* layer1 = pending_layer_->children()[0];
3993 layer1->SetBounds(layer_bounds);
3994 layer1->SetContentBounds(layer_bounds);
3995 layer1->SetDrawsContent(true);
3996 layer1->SetContentsOpaque(true);
3997 layer1->SetPosition(occluding_layer_position);
3999 time_ticks += base::TimeDelta::FromMilliseconds(200);
4000 host_impl_.SetCurrentBeginFrameArgs(
4001 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4002 bool update_lcd_text = false;
4003 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4005 unoccluded_tile_count = 0;
4006 queue.reset(new TilingSetRasterQueueAll(
4007 pending_layer_->picture_layer_tiling_set(), false));
4008 while (!queue->IsEmpty()) {
4009 Tile* tile = queue->Top();
4011 EXPECT_FALSE(tile->is_occluded());
4013 bool tile_is_visible =
4014 tile->content_rect().Intersects(pending_layer_->visible_content_rect());
4015 if (tile_is_visible)
4016 unoccluded_tile_count++;
4017 queue->Pop();
4019 EXPECT_EQ(20, unoccluded_tile_count);
4021 // Full occlusion.
4022 layer1->SetPosition(gfx::Point(0, 0));
4024 time_ticks += base::TimeDelta::FromMilliseconds(200);
4025 host_impl_.SetCurrentBeginFrameArgs(
4026 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4027 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4029 unoccluded_tile_count = 0;
4030 queue.reset(new TilingSetRasterQueueAll(
4031 pending_layer_->picture_layer_tiling_set(), false));
4032 while (!queue->IsEmpty()) {
4033 Tile* tile = queue->Top();
4035 EXPECT_FALSE(tile->is_occluded());
4037 bool tile_is_visible =
4038 tile->content_rect().Intersects(pending_layer_->visible_content_rect());
4039 if (tile_is_visible)
4040 unoccluded_tile_count++;
4041 queue->Pop();
4043 EXPECT_EQ(unoccluded_tile_count, 0);
4046 TEST_F(OcclusionTrackingPictureLayerImplTest,
4047 OccludedTilesNotMarkedAsRequired) {
4048 base::TimeTicks time_ticks;
4049 time_ticks += base::TimeDelta::FromMilliseconds(1);
4050 host_impl_.SetCurrentBeginFrameArgs(
4051 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4053 gfx::Size tile_size(102, 102);
4054 gfx::Size layer_bounds(1000, 1000);
4055 gfx::Size viewport_size(500, 500);
4056 gfx::Point occluding_layer_position(310, 0);
4058 host_impl_.SetViewportSize(viewport_size);
4060 scoped_refptr<FakePicturePileImpl> pending_pile =
4061 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4062 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
4064 // No occlusion.
4065 int occluded_tile_count = 0;
4066 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4067 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4068 tiling->UpdateAllTilePrioritiesForTesting();
4070 occluded_tile_count = 0;
4071 for (PictureLayerTiling::CoverageIterator iter(
4072 tiling,
4073 pending_layer_->contents_scale_x(),
4074 gfx::Rect(layer_bounds));
4075 iter;
4076 ++iter) {
4077 if (!*iter)
4078 continue;
4079 const Tile* tile = *iter;
4081 // Fully occluded tiles are not required for activation.
4082 if (tile->is_occluded()) {
4083 EXPECT_FALSE(tile->required_for_activation());
4084 occluded_tile_count++;
4087 EXPECT_EQ(occluded_tile_count, 0);
4090 // Partial occlusion.
4091 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
4092 LayerImpl* layer1 = pending_layer_->children()[0];
4093 layer1->SetBounds(layer_bounds);
4094 layer1->SetContentBounds(layer_bounds);
4095 layer1->SetDrawsContent(true);
4096 layer1->SetContentsOpaque(true);
4097 layer1->SetPosition(occluding_layer_position);
4099 time_ticks += base::TimeDelta::FromMilliseconds(200);
4100 host_impl_.SetCurrentBeginFrameArgs(
4101 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4102 bool update_lcd_text = false;
4103 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4105 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4106 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4107 tiling->UpdateAllTilePrioritiesForTesting();
4109 occluded_tile_count = 0;
4110 for (PictureLayerTiling::CoverageIterator iter(
4111 tiling,
4112 pending_layer_->contents_scale_x(),
4113 gfx::Rect(layer_bounds));
4114 iter;
4115 ++iter) {
4116 if (!*iter)
4117 continue;
4118 const Tile* tile = *iter;
4120 if (tile->is_occluded()) {
4121 EXPECT_FALSE(tile->required_for_activation());
4122 occluded_tile_count++;
4125 switch (i) {
4126 case 0:
4127 EXPECT_EQ(occluded_tile_count, 5);
4128 break;
4129 case 1:
4130 EXPECT_EQ(occluded_tile_count, 2);
4131 break;
4132 default:
4133 NOTREACHED();
4137 // Full occlusion.
4138 layer1->SetPosition(gfx::PointF(0, 0));
4140 time_ticks += base::TimeDelta::FromMilliseconds(200);
4141 host_impl_.SetCurrentBeginFrameArgs(
4142 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4143 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4145 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4146 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4147 tiling->UpdateAllTilePrioritiesForTesting();
4149 occluded_tile_count = 0;
4150 for (PictureLayerTiling::CoverageIterator iter(
4151 tiling,
4152 pending_layer_->contents_scale_x(),
4153 gfx::Rect(layer_bounds));
4154 iter;
4155 ++iter) {
4156 if (!*iter)
4157 continue;
4158 const Tile* tile = *iter;
4160 if (tile->is_occluded()) {
4161 EXPECT_FALSE(tile->required_for_activation());
4162 occluded_tile_count++;
4165 switch (i) {
4166 case 0:
4167 EXPECT_EQ(25, occluded_tile_count);
4168 break;
4169 case 1:
4170 EXPECT_EQ(4, occluded_tile_count);
4171 break;
4172 default:
4173 NOTREACHED();
4178 TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) {
4179 base::TimeTicks time_ticks;
4180 time_ticks += base::TimeDelta::FromMilliseconds(1);
4181 host_impl_.SetCurrentBeginFrameArgs(
4182 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4184 gfx::Size tile_size(102, 102);
4185 gfx::Size layer_bounds(1000, 1000);
4186 gfx::Size viewport_size(500, 500);
4187 gfx::Point occluding_layer_position(310, 0);
4189 scoped_refptr<FakePicturePileImpl> pending_pile =
4190 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4192 host_impl_.SetViewportSize(viewport_size);
4194 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
4195 ASSERT_TRUE(pending_layer_->CanHaveTilings());
4197 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
4198 LayerImpl* layer1 = pending_layer_->children()[0];
4199 layer1->SetBounds(layer_bounds);
4200 layer1->SetContentBounds(layer_bounds);
4201 layer1->SetDrawsContent(true);
4202 layer1->SetContentsOpaque(true);
4203 layer1->SetPosition(occluding_layer_position);
4205 pending_layer_->tilings()->RemoveAllTilings();
4206 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
4207 pending_layer_->AddTiling(low_res_factor);
4208 pending_layer_->AddTiling(0.3f);
4209 pending_layer_->AddTiling(0.7f);
4210 pending_layer_->AddTiling(1.0f);
4211 pending_layer_->AddTiling(2.0f);
4213 time_ticks += base::TimeDelta::FromMilliseconds(1);
4214 host_impl_.SetCurrentBeginFrameArgs(
4215 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4216 // UpdateDrawProperties with the occluding layer.
4217 bool update_lcd_text = false;
4218 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4220 EXPECT_EQ(5u, pending_layer_->num_tilings());
4222 int occluded_tile_count = 0;
4223 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4224 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4225 tiling->UpdateAllTilePrioritiesForTesting();
4226 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
4228 occluded_tile_count = 0;
4229 for (size_t j = 0; j < tiles.size(); ++j) {
4230 if (tiles[j]->is_occluded()) {
4231 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4232 tiles[j]->content_rect(), 1.0f / tiles[j]->contents_scale());
4233 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x());
4234 occluded_tile_count++;
4238 switch (i) {
4239 case 0:
4240 EXPECT_EQ(occluded_tile_count, 30);
4241 break;
4242 case 1:
4243 EXPECT_EQ(occluded_tile_count, 5);
4244 break;
4245 case 2:
4246 EXPECT_EQ(occluded_tile_count, 4);
4247 break;
4248 case 4:
4249 case 3:
4250 EXPECT_EQ(occluded_tile_count, 2);
4251 break;
4252 default:
4253 NOTREACHED();
4258 TEST_F(OcclusionTrackingPictureLayerImplTest, DifferentOcclusionOnTrees) {
4259 gfx::Size tile_size(102, 102);
4260 gfx::Size layer_bounds(1000, 1000);
4261 gfx::Size viewport_size(1000, 1000);
4262 gfx::Point occluding_layer_position(310, 0);
4263 gfx::Rect invalidation_rect(230, 230, 102, 102);
4265 scoped_refptr<FakePicturePileImpl> pending_pile =
4266 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4267 scoped_refptr<FakePicturePileImpl> active_pile =
4268 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4270 host_impl_.SetViewportSize(viewport_size);
4271 SetupPendingTree(active_pile);
4273 // Partially occlude the active layer.
4274 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2));
4275 LayerImpl* layer1 = pending_layer_->children()[0];
4276 layer1->SetBounds(layer_bounds);
4277 layer1->SetContentBounds(layer_bounds);
4278 layer1->SetDrawsContent(true);
4279 layer1->SetContentsOpaque(true);
4280 layer1->SetPosition(occluding_layer_position);
4282 ActivateTree();
4284 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4285 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4286 tiling->UpdateAllTilePrioritiesForTesting();
4288 for (
4289 PictureLayerTiling::CoverageIterator iter(
4290 tiling, active_layer_->contents_scale_x(), gfx::Rect(layer_bounds));
4291 iter; ++iter) {
4292 if (!*iter)
4293 continue;
4294 const Tile* tile = *iter;
4296 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4297 tile->content_rect(), 1.0f / tile->contents_scale());
4298 // Tiles are occluded on the active tree iff they lie beneath the
4299 // occluding layer.
4300 EXPECT_EQ(tile->is_occluded(),
4301 scaled_content_rect.x() >= occluding_layer_position.x());
4305 // Partially invalidate the pending layer.
4306 SetupPendingTreeWithInvalidation(pending_pile, invalidation_rect);
4308 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4309 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4310 tiling->UpdateAllTilePrioritiesForTesting();
4312 for (PictureLayerTiling::CoverageIterator iter(
4313 tiling,
4314 active_layer_->contents_scale_x(),
4315 gfx::Rect(layer_bounds));
4316 iter;
4317 ++iter) {
4318 if (!*iter)
4319 continue;
4320 const Tile* tile = *iter;
4322 // All tiles are unoccluded, because the pending tree has no occlusion.
4323 EXPECT_FALSE(tile->is_occluded());
4324 EXPECT_FALSE(tile->is_occluded());
4326 Tile* twin_tile = active_layer_->GetPendingOrActiveTwinTiling(tiling)
4327 ->TileAt(iter.i(), iter.j());
4328 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4329 tile->content_rect(), 1.0f / tile->contents_scale());
4331 if (scaled_content_rect.Intersects(invalidation_rect)) {
4332 // Tiles inside the invalidation rect exist on both trees.
4333 EXPECT_TRUE(tile);
4334 EXPECT_TRUE(twin_tile);
4335 EXPECT_NE(tile, twin_tile);
4336 } else {
4337 // Tiles outside the invalidation rect only exist on the active tree.
4338 EXPECT_TRUE(tile);
4339 EXPECT_FALSE(twin_tile);
4345 TEST_F(OcclusionTrackingPictureLayerImplTest,
4346 OccludedTilesConsideredDuringEviction) {
4347 base::TimeTicks time_ticks;
4348 time_ticks += base::TimeDelta::FromMilliseconds(1);
4349 host_impl_.SetCurrentBeginFrameArgs(
4350 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4352 gfx::Size tile_size(102, 102);
4353 gfx::Size layer_bounds(1000, 1000);
4354 gfx::Size viewport_size(1000, 1000);
4355 gfx::Point pending_occluding_layer_position(310, 0);
4356 gfx::Point active_occluding_layer_position(0, 310);
4357 gfx::Rect invalidation_rect(230, 230, 152, 152);
4359 host_impl_.SetViewportSize(viewport_size);
4360 host_impl_.SetDeviceScaleFactor(2.f);
4362 scoped_refptr<FakePicturePileImpl> pending_pile =
4363 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4364 scoped_refptr<FakePicturePileImpl> active_pile =
4365 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4367 SetupPendingTreeWithFixedTileSize(active_pile, tile_size, Region());
4369 // Partially occlude the active layer.
4370 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2));
4371 LayerImpl* active_occluding_layer = pending_layer_->children()[0];
4372 active_occluding_layer->SetBounds(layer_bounds);
4373 active_occluding_layer->SetContentBounds(layer_bounds);
4374 active_occluding_layer->SetDrawsContent(true);
4375 active_occluding_layer->SetContentsOpaque(true);
4376 active_occluding_layer->SetPosition(active_occluding_layer_position);
4378 ActivateTree();
4380 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4381 // are created.
4382 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, invalidation_rect);
4384 // Partially occlude the pending layer in a different way.
4385 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 3));
4386 LayerImpl* pending_occluding_layer = pending_layer_->children()[0];
4387 pending_occluding_layer->SetBounds(layer_bounds);
4388 pending_occluding_layer->SetContentBounds(layer_bounds);
4389 pending_occluding_layer->SetDrawsContent(true);
4390 pending_occluding_layer->SetContentsOpaque(true);
4391 pending_occluding_layer->SetPosition(pending_occluding_layer_position);
4393 EXPECT_EQ(2u, pending_layer_->num_tilings());
4394 EXPECT_EQ(2u, active_layer_->num_tilings());
4396 time_ticks += base::TimeDelta::FromMilliseconds(1);
4397 host_impl_.SetCurrentBeginFrameArgs(
4398 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4399 // UpdateDrawProperties with the occluding layer.
4400 bool update_lcd_text = false;
4401 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
4403 // The expected number of occluded tiles on each of the 2 tilings for each of
4404 // the 3 tree priorities.
4405 size_t expected_occluded_tile_count_on_pending[] = {4u, 0u};
4406 size_t expected_occluded_tile_count_on_active[] = {12u, 1u};
4407 size_t total_expected_occluded_tile_count_on_trees[] = {13u, 4u};
4409 // Verify number of occluded tiles on the pending layer for each tiling.
4410 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4411 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4412 tiling->UpdateAllTilePrioritiesForTesting();
4414 size_t occluded_tile_count_on_pending = 0u;
4415 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f,
4416 gfx::Rect(layer_bounds));
4417 iter; ++iter) {
4418 Tile* tile = *iter;
4420 if (invalidation_rect.Intersects(iter.geometry_rect()))
4421 EXPECT_TRUE(tile);
4422 else
4423 EXPECT_FALSE(tile);
4425 if (!tile)
4426 continue;
4427 if (tile->is_occluded())
4428 occluded_tile_count_on_pending++;
4430 EXPECT_EQ(expected_occluded_tile_count_on_pending[i],
4431 occluded_tile_count_on_pending)
4432 << tiling->contents_scale();
4435 // Verify number of occluded tiles on the active layer for each tiling.
4436 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4437 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4438 tiling->UpdateAllTilePrioritiesForTesting();
4440 size_t occluded_tile_count_on_active = 0u;
4441 for (PictureLayerTiling::CoverageIterator iter(
4442 tiling,
4443 pending_layer_->contents_scale_x(),
4444 gfx::Rect(layer_bounds));
4445 iter;
4446 ++iter) {
4447 Tile* tile = *iter;
4449 if (!tile)
4450 continue;
4451 if (tile->is_occluded())
4452 occluded_tile_count_on_active++;
4454 EXPECT_EQ(expected_occluded_tile_count_on_active[i],
4455 occluded_tile_count_on_active)
4456 << i;
4459 std::vector<Tile*> all_tiles;
4460 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4461 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4462 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
4463 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end());
4465 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4466 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4467 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
4468 all_tiles.insert(all_tiles.end(), tiles.begin(), tiles.end());
4471 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
4473 VerifyEvictionConsidersOcclusion(
4474 pending_layer_, active_layer_, PENDING_TREE,
4475 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__);
4476 VerifyEvictionConsidersOcclusion(
4477 active_layer_, pending_layer_, ACTIVE_TREE,
4478 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__);
4480 // Repeat the tests without valid active tree priorities.
4481 active_layer_->set_has_valid_tile_priorities(false);
4482 VerifyEvictionConsidersOcclusion(
4483 pending_layer_, active_layer_, PENDING_TREE,
4484 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__);
4485 VerifyEvictionConsidersOcclusion(
4486 active_layer_, pending_layer_, ACTIVE_TREE,
4487 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__);
4488 active_layer_->set_has_valid_tile_priorities(true);
4490 // Repeat the tests without valid pending tree priorities.
4491 pending_layer_->set_has_valid_tile_priorities(false);
4492 VerifyEvictionConsidersOcclusion(
4493 active_layer_, pending_layer_, ACTIVE_TREE,
4494 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE], __LINE__);
4495 VerifyEvictionConsidersOcclusion(
4496 pending_layer_, active_layer_, PENDING_TREE,
4497 total_expected_occluded_tile_count_on_trees[PENDING_TREE], __LINE__);
4498 pending_layer_->set_has_valid_tile_priorities(true);
4501 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) {
4502 gfx::Size tile_size(102, 102);
4503 gfx::Size layer_bounds(1000, 1000);
4505 scoped_refptr<FakePicturePileImpl> pile =
4506 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4507 SetupPendingTree(pile);
4508 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer());
4510 ActivateTree();
4511 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4513 SetupPendingTree(pile);
4514 EXPECT_TRUE(pending_layer_->GetPendingOrActiveTwinLayer());
4515 EXPECT_TRUE(active_layer_->GetPendingOrActiveTwinLayer());
4516 EXPECT_EQ(pending_layer_, active_layer_->GetPendingOrActiveTwinLayer());
4517 EXPECT_EQ(active_layer_, pending_layer_->GetPendingOrActiveTwinLayer());
4519 ActivateTree();
4520 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4522 // Make an empty pending tree.
4523 host_impl_.CreatePendingTree();
4524 host_impl_.pending_tree()->DetachLayerTree();
4525 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4528 TEST_F(PictureLayerImplTest, RecycledTwinLayer) {
4529 gfx::Size tile_size(102, 102);
4530 gfx::Size layer_bounds(1000, 1000);
4532 scoped_refptr<FakePicturePileImpl> pile =
4533 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4534 SetupPendingTree(pile);
4535 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer());
4537 ActivateTree();
4538 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer());
4539 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer());
4541 SetupPendingTree(pile);
4542 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer());
4543 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer());
4545 ActivateTree();
4546 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer());
4547 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer());
4549 // Make an empty pending tree.
4550 host_impl_.CreatePendingTree();
4551 host_impl_.pending_tree()->DetachLayerTree();
4552 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer());
4555 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) {
4556 base::TimeTicks time_ticks;
4557 time_ticks += base::TimeDelta::FromMilliseconds(1);
4558 host_impl_.SetCurrentBeginFrameArgs(
4559 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4561 gfx::Size tile_size(100, 100);
4562 gfx::Size layer_bounds(200, 200);
4563 gfx::Rect layer_rect(layer_bounds);
4565 FakeContentLayerClient client;
4566 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
4567 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
4568 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client);
4569 host->SetRootLayer(layer);
4570 RecordingSource* recording_source = layer->GetRecordingSourceForTesting();
4572 int frame_number = 0;
4574 client.set_fill_with_nonsolid_color(!test_for_solid);
4576 Region invalidation(layer_rect);
4577 recording_source->UpdateAndExpandInvalidation(
4578 &client, &invalidation, layer_bounds, layer_rect, frame_number++,
4579 RecordingSource::RECORD_NORMALLY);
4581 scoped_refptr<RasterSource> pending_raster_source =
4582 recording_source->CreateRasterSource(true);
4584 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
4585 ActivateTree();
4587 if (test_for_solid) {
4588 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
4589 } else {
4590 ASSERT_TRUE(active_layer_->tilings());
4591 ASSERT_GT(active_layer_->tilings()->num_tilings(), 0u);
4592 std::vector<Tile*> tiles =
4593 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
4594 EXPECT_FALSE(tiles.empty());
4595 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
4598 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
4599 AppendQuadsData data;
4600 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
4601 active_layer_->AppendQuads(render_pass.get(), &data);
4602 active_layer_->DidDraw(nullptr);
4604 DrawQuad::Material expected = test_for_solid
4605 ? DrawQuad::Material::SOLID_COLOR
4606 : DrawQuad::Material::TILED_CONTENT;
4607 EXPECT_EQ(expected, render_pass->quad_list.front()->material);
4610 TEST_F(PictureLayerImplTest, DrawSolidQuads) {
4611 TestQuadsForSolidColor(true);
4614 TEST_F(PictureLayerImplTest, DrawNonSolidQuads) {
4615 TestQuadsForSolidColor(false);
4618 TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) {
4619 base::TimeTicks time_ticks;
4620 time_ticks += base::TimeDelta::FromMilliseconds(1);
4621 host_impl_.SetCurrentBeginFrameArgs(
4622 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4624 gfx::Size tile_size(100, 100);
4625 gfx::Size layer_bounds(200, 200);
4626 gfx::Rect layer_rect(layer_bounds);
4628 FakeContentLayerClient client;
4629 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
4630 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
4631 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client);
4632 host->SetRootLayer(layer);
4633 RecordingSource* recording_source = layer->GetRecordingSourceForTesting();
4635 int frame_number = 0;
4637 client.set_fill_with_nonsolid_color(true);
4639 Region invalidation1(layer_rect);
4640 recording_source->UpdateAndExpandInvalidation(
4641 &client, &invalidation1, layer_bounds, layer_rect, frame_number++,
4642 RecordingSource::RECORD_NORMALLY);
4644 scoped_refptr<RasterSource> raster_source1 =
4645 recording_source->CreateRasterSource(true);
4647 SetupPendingTree(raster_source1);
4648 ActivateTree();
4649 bool update_lcd_text = false;
4650 host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);
4652 // We've started with a solid layer that contains some tilings.
4653 ASSERT_TRUE(active_layer_->tilings());
4654 EXPECT_NE(0u, active_layer_->tilings()->num_tilings());
4656 client.set_fill_with_nonsolid_color(false);
4658 Region invalidation2(layer_rect);
4659 recording_source->UpdateAndExpandInvalidation(
4660 &client, &invalidation2, layer_bounds, layer_rect, frame_number++,
4661 RecordingSource::RECORD_NORMALLY);
4663 scoped_refptr<RasterSource> raster_source2 =
4664 recording_source->CreateRasterSource(true);
4666 SetupPendingTree(raster_source2);
4667 ActivateTree();
4669 // We've switched to a solid color, so we should end up with no tilings.
4670 ASSERT_TRUE(active_layer_->tilings());
4671 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
4674 TEST_F(PictureLayerImplTest, ChangeInViewportAllowsTilingUpdates) {
4675 base::TimeTicks time_ticks;
4676 time_ticks += base::TimeDelta::FromMilliseconds(1);
4677 host_impl_.SetCurrentBeginFrameArgs(
4678 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4680 gfx::Size tile_size(100, 100);
4681 gfx::Size layer_bounds(400, 4000);
4683 scoped_refptr<FakePicturePileImpl> pending_pile =
4684 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4685 scoped_refptr<FakePicturePileImpl> active_pile =
4686 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4688 SetupTrees(pending_pile, active_pile);
4690 Region invalidation;
4691 gfx::Rect viewport = gfx::Rect(0, 0, 100, 100);
4692 gfx::Transform transform;
4694 host_impl_.SetRequiresHighResToDraw();
4696 // Update tiles.
4697 pending_layer_->draw_properties().visible_content_rect = viewport;
4698 pending_layer_->draw_properties().screen_space_transform = transform;
4699 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
4700 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
4702 // Ensure we can't activate.
4703 EXPECT_FALSE(host_impl_.tile_manager()->IsReadyToActivate());
4705 // Now in the same frame, move the viewport (this can happen during
4706 // animation).
4707 viewport = gfx::Rect(0, 2000, 100, 100);
4709 // Update tiles.
4710 pending_layer_->draw_properties().visible_content_rect = viewport;
4711 pending_layer_->draw_properties().screen_space_transform = transform;
4712 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
4713 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
4715 // Make sure all viewport tiles (viewport from the tiling) are ready to draw.
4716 std::vector<Tile*> tiles;
4717 for (PictureLayerTiling::CoverageIterator iter(
4718 pending_layer_->HighResTiling(),
4719 1.f,
4720 pending_layer_->HighResTiling()->GetCurrentVisibleRectForTesting());
4721 iter;
4722 ++iter) {
4723 if (*iter)
4724 tiles.push_back(*iter);
4726 for (PictureLayerTiling::CoverageIterator iter(
4727 active_layer_->HighResTiling(), 1.f,
4728 active_layer_->HighResTiling()->GetCurrentVisibleRectForTesting());
4729 iter; ++iter) {
4730 if (*iter)
4731 tiles.push_back(*iter);
4734 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
4736 // Ensure we can activate.
4737 EXPECT_TRUE(host_impl_.tile_manager()->IsReadyToActivate());
4740 TEST_F(PictureLayerImplTest, CloneMissingRecordings) {
4741 gfx::Size tile_size(100, 100);
4742 gfx::Size layer_bounds(400, 400);
4744 scoped_refptr<FakePicturePileImpl> filled_pile =
4745 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4747 scoped_ptr<FakePicturePile> partial_recording =
4748 FakePicturePile::CreateEmptyPile(tile_size, layer_bounds);
4749 for (int i = 1; i < partial_recording->tiling().num_tiles_x(); ++i) {
4750 for (int j = 1; j < partial_recording->tiling().num_tiles_y(); ++j)
4751 partial_recording->AddRecordingAt(i, j);
4753 scoped_refptr<FakePicturePileImpl> partial_pile =
4754 FakePicturePileImpl::CreateFromPile(partial_recording.get(), nullptr);
4756 SetupPendingTreeWithFixedTileSize(filled_pile, tile_size, Region());
4757 ActivateTree();
4759 PictureLayerTiling* pending_tiling = old_pending_layer_->HighResTiling();
4760 PictureLayerTiling* active_tiling = active_layer_->HighResTiling();
4762 // We should have all tiles on active, and none on pending.
4763 EXPECT_EQ(0u, pending_tiling->AllTilesForTesting().size());
4764 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size());
4766 // Now put a partially-recorded pile on the pending tree (and invalidate
4767 // everything, since the main thread PicturePile will invalidate dropped
4768 // recordings). This will cause us to be missing some tiles.
4769 SetupPendingTreeWithFixedTileSize(partial_pile, tile_size,
4770 Region(gfx::Rect(layer_bounds)));
4771 EXPECT_EQ(3u * 3u, pending_tiling->AllTilesForTesting().size());
4772 EXPECT_FALSE(pending_tiling->TileAt(0, 0));
4773 EXPECT_FALSE(pending_tiling->TileAt(1, 1));
4774 EXPECT_TRUE(pending_tiling->TileAt(2, 2));
4776 // Active is not affected yet.
4777 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size());
4779 // Activate the tree. The same tiles go missing on the active tree.
4780 ActivateTree();
4781 EXPECT_EQ(3u * 3u, active_tiling->AllTilesForTesting().size());
4782 EXPECT_FALSE(active_tiling->TileAt(0, 0));
4783 EXPECT_FALSE(active_tiling->TileAt(1, 1));
4784 EXPECT_TRUE(active_tiling->TileAt(2, 2));
4786 // Now put a full recording on the pending tree again. We'll get all our tiles
4787 // back.
4788 SetupPendingTreeWithFixedTileSize(filled_pile, tile_size,
4789 Region(gfx::Rect(layer_bounds)));
4790 EXPECT_EQ(5u * 5u, pending_tiling->AllTilesForTesting().size());
4791 Tile* tile00 = pending_tiling->TileAt(0, 0);
4792 Tile* tile11 = pending_tiling->TileAt(1, 1);
4793 Tile* tile22 = pending_tiling->TileAt(2, 2);
4795 // Active is not affected yet.
4796 EXPECT_EQ(3u * 3u, active_tiling->AllTilesForTesting().size());
4798 // Activate the tree. The tiles are moved to the active tree.
4799 ActivateTree();
4800 EXPECT_EQ(5u * 5u, active_tiling->AllTilesForTesting().size());
4801 EXPECT_EQ(tile00, active_tiling->TileAt(0, 0));
4802 EXPECT_EQ(tile11, active_tiling->TileAt(1, 1));
4803 EXPECT_EQ(tile22, active_tiling->TileAt(2, 2));
4806 TEST_F(PictureLayerImplTest, ScrollPastLiveTilesRectAndBack) {
4807 base::TimeTicks time_ticks;
4808 time_ticks += base::TimeDelta::FromMilliseconds(1);
4809 host_impl_.SetCurrentBeginFrameArgs(
4810 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4812 gfx::Size tile_size(102, 102);
4813 gfx::Size layer_bounds(100, 100);
4814 gfx::Size viewport_size(100, 100);
4816 host_impl_.SetViewportSize(viewport_size);
4817 host_impl_.SetDeviceScaleFactor(1.f);
4819 scoped_refptr<FakePicturePileImpl> pending_pile =
4820 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4821 scoped_refptr<FakePicturePileImpl> active_pile =
4822 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4824 SetupPendingTreeWithFixedTileSize(active_pile, tile_size, Region());
4826 ActivateTree();
4827 EXPECT_TRUE(active_layer_->HighResTiling()->has_tiles());
4829 host_impl_.SetExternalDrawConstraints(
4830 gfx::Transform(), // transform
4831 gfx::Rect(), // clip
4832 gfx::Rect(), // viewport
4833 gfx::Rect(0, 1000, 100, 100), // viewport_rect_for_tile_priority
4834 gfx::Transform(), // transform_for_tile_priority
4835 false);
4837 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, gfx::Rect());
4839 EXPECT_FALSE(pending_layer_->HighResTiling()->has_tiles());
4840 EXPECT_TRUE(pending_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4841 ActivateTree();
4842 EXPECT_FALSE(active_layer_->HighResTiling()->has_tiles());
4843 EXPECT_TRUE(active_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4845 host_impl_.SetExternalDrawConstraints(
4846 gfx::Transform(), // transform
4847 gfx::Rect(), // clip
4848 gfx::Rect(), // viewport
4849 gfx::Rect(0, 110, 100, 100), // viewport_rect_for_tile_priority
4850 gfx::Transform(), // transform_for_tile_priority
4851 false);
4853 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, gfx::Rect());
4855 EXPECT_FALSE(pending_layer_->HighResTiling()->has_tiles());
4856 EXPECT_FALSE(pending_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4857 ActivateTree();
4858 EXPECT_TRUE(active_layer_->HighResTiling()->has_tiles());
4859 EXPECT_FALSE(active_layer_->HighResTiling()->live_tiles_rect().IsEmpty());
4862 TEST_F(PictureLayerImplTest, UpdateLCDInvalidatesPendingTree) {
4863 base::TimeTicks time_ticks;
4864 time_ticks += base::TimeDelta::FromMilliseconds(1);
4865 host_impl_.SetCurrentBeginFrameArgs(
4866 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
4868 gfx::Size tile_size(102, 102);
4869 gfx::Size layer_bounds(100, 100);
4870 gfx::Size viewport_size(100, 100);
4872 host_impl_.SetViewportSize(viewport_size);
4873 host_impl_.SetDeviceScaleFactor(1.f);
4875 scoped_refptr<FakePicturePileImpl> pending_pile =
4876 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4877 SetupPendingTreeWithFixedTileSize(pending_pile, tile_size, Region());
4879 EXPECT_TRUE(pending_layer_->RasterSourceUsesLCDText());
4880 EXPECT_TRUE(pending_layer_->HighResTiling()->has_tiles());
4881 std::vector<Tile*> tiles =
4882 pending_layer_->HighResTiling()->AllTilesForTesting();
4883 for (Tile* tile : tiles)
4884 EXPECT_EQ(pending_layer_->raster_source(), tile->raster_source());
4886 pending_layer_->draw_properties().can_use_lcd_text = false;
4887 pending_layer_->UpdateCanUseLCDTextAfterCommit();
4889 EXPECT_FALSE(pending_layer_->RasterSourceUsesLCDText());
4890 EXPECT_NE(pending_pile.get(), pending_layer_->raster_source());
4891 EXPECT_TRUE(pending_layer_->HighResTiling()->has_tiles());
4892 tiles = pending_layer_->HighResTiling()->AllTilesForTesting();
4893 for (Tile* tile : tiles)
4894 EXPECT_EQ(pending_layer_->raster_source(), tile->raster_source());
4897 class TileSizeSettings : public ImplSidePaintingSettings {
4898 public:
4899 TileSizeSettings() {
4900 default_tile_size = gfx::Size(100, 100);
4901 max_untiled_layer_size = gfx::Size(200, 200);
4905 class TileSizeTest : public PictureLayerImplTest {
4906 public:
4907 TileSizeTest() : PictureLayerImplTest(TileSizeSettings()) {}
4910 TEST_F(TileSizeTest, TileSizes) {
4911 host_impl_.CreatePendingTree();
4913 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
4914 scoped_ptr<FakePictureLayerImpl> layer =
4915 FakePictureLayerImpl::Create(pending_tree, id_);
4917 host_impl_.SetViewportSize(gfx::Size(1000, 1000));
4918 gfx::Size result;
4920 host_impl_.SetUseGpuRasterization(false);
4922 // Default tile-size for large layers.
4923 result = layer->CalculateTileSize(gfx::Size(10000, 10000));
4924 EXPECT_EQ(result.width(), 100);
4925 EXPECT_EQ(result.height(), 100);
4926 // Don't tile and round-up, when under max_untiled_layer_size.
4927 result = layer->CalculateTileSize(gfx::Size(42, 42));
4928 EXPECT_EQ(result.width(), 64);
4929 EXPECT_EQ(result.height(), 64);
4930 result = layer->CalculateTileSize(gfx::Size(191, 191));
4931 EXPECT_EQ(result.width(), 192);
4932 EXPECT_EQ(result.height(), 192);
4933 result = layer->CalculateTileSize(gfx::Size(199, 199));
4934 EXPECT_EQ(result.width(), 200);
4935 EXPECT_EQ(result.height(), 200);
4937 // Gpu-rasterization uses 25% viewport-height tiles.
4938 // The +2's below are for border texels.
4939 host_impl_.SetUseGpuRasterization(true);
4940 host_impl_.SetViewportSize(gfx::Size(2000, 2000));
4942 layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size());
4943 result = layer->CalculateTileSize(gfx::Size(10000, 10000));
4944 EXPECT_EQ(result.width(), 2000 + 2 * PictureLayerTiling::kBorderTexels);
4945 EXPECT_EQ(result.height(), 500 + 2);
4947 // Clamp and round-up, when smaller than viewport.
4948 // Tile-height doubles to 50% when width shrinks to <= 50%.
4949 host_impl_.SetViewportSize(gfx::Size(1000, 1000));
4950 layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size());
4951 result = layer->CalculateTileSize(gfx::Size(447, 10000));
4952 EXPECT_EQ(result.width(), 448);
4953 EXPECT_EQ(result.height(), 500 + 2);
4955 // Largest layer is 50% of viewport width (rounded up), and
4956 // 50% of viewport in height.
4957 result = layer->CalculateTileSize(gfx::Size(447, 400));
4958 EXPECT_EQ(result.width(), 448);
4959 EXPECT_EQ(result.height(), 448);
4960 result = layer->CalculateTileSize(gfx::Size(500, 499));
4961 EXPECT_EQ(result.width(), 512);
4962 EXPECT_EQ(result.height(), 500 + 2);
4965 } // namespace
4966 } // namespace cc