[GCM] Investigatory CHECKs for crash in parsing stream
[chromium-blink-merge.git] / cc / layers / picture_layer_impl_unittest.cc
blob4406450b165448c014e6b7d2ce88fb940520c06b
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 "cc/base/math_util.h"
13 #include "cc/layers/append_quads_data.h"
14 #include "cc/layers/picture_layer.h"
15 #include "cc/quads/draw_quad.h"
16 #include "cc/quads/tile_draw_quad.h"
17 #include "cc/test/begin_frame_args_test.h"
18 #include "cc/test/fake_content_layer_client.h"
19 #include "cc/test/fake_impl_proxy.h"
20 #include "cc/test/fake_layer_tree_host_impl.h"
21 #include "cc/test/fake_output_surface.h"
22 #include "cc/test/fake_picture_layer_impl.h"
23 #include "cc/test/fake_picture_pile_impl.h"
24 #include "cc/test/geometry_test_utils.h"
25 #include "cc/test/impl_side_painting_settings.h"
26 #include "cc/test/layer_test_common.h"
27 #include "cc/test/test_shared_bitmap_manager.h"
28 #include "cc/test/test_web_graphics_context_3d.h"
29 #include "cc/trees/layer_tree_impl.h"
30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/gfx/rect_conversions.h"
32 #include "ui/gfx/size_conversions.h"
34 namespace cc {
35 namespace {
37 class MockCanvas : public SkCanvas {
38 public:
39 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {}
41 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE {
42 // Capture calls before SkCanvas quickReject() kicks in.
43 rects_.push_back(rect);
46 std::vector<SkRect> rects_;
49 class NoLowResTilingsSettings : public ImplSidePaintingSettings {};
51 class LowResTilingsSettings : public ImplSidePaintingSettings {
52 public:
53 LowResTilingsSettings() { create_low_res_tiling = true; }
56 class PictureLayerImplTest : public testing::Test {
57 public:
58 PictureLayerImplTest()
59 : proxy_(base::MessageLoopProxy::current()),
60 host_impl_(LowResTilingsSettings(), &proxy_, &shared_bitmap_manager_),
61 id_(7),
62 pending_layer_(NULL),
63 old_pending_layer_(NULL),
64 active_layer_(NULL) {}
66 explicit PictureLayerImplTest(const LayerTreeSettings& settings)
67 : proxy_(base::MessageLoopProxy::current()),
68 host_impl_(settings, &proxy_, &shared_bitmap_manager_),
69 id_(7) {}
71 virtual ~PictureLayerImplTest() {
74 virtual void SetUp() OVERRIDE {
75 InitializeRenderer();
78 virtual void InitializeRenderer() {
79 host_impl_.InitializeRenderer(
80 FakeOutputSurface::Create3d().PassAs<OutputSurface>());
83 void SetupDefaultTrees(const gfx::Size& layer_bounds) {
84 gfx::Size tile_size(100, 100);
86 scoped_refptr<FakePicturePileImpl> pending_pile =
87 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
88 scoped_refptr<FakePicturePileImpl> active_pile =
89 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
91 SetupTrees(pending_pile, active_pile);
94 void ActivateTree() {
95 host_impl_.ActivateSyncTree();
96 CHECK(!host_impl_.pending_tree());
97 CHECK(host_impl_.recycle_tree());
98 old_pending_layer_ = pending_layer_;
99 pending_layer_ = NULL;
100 active_layer_ = static_cast<FakePictureLayerImpl*>(
101 host_impl_.active_tree()->LayerById(id_));
104 void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds,
105 const gfx::Size& tile_size) {
106 SetupDefaultTrees(layer_bounds);
107 pending_layer_->set_fixed_tile_size(tile_size);
108 active_layer_->set_fixed_tile_size(tile_size);
111 void SetupTrees(
112 scoped_refptr<PicturePileImpl> pending_pile,
113 scoped_refptr<PicturePileImpl> active_pile) {
114 SetupPendingTree(active_pile);
115 ActivateTree();
116 SetupPendingTree(pending_pile);
119 void CreateHighLowResAndSetAllTilesVisible() {
120 // Active layer must get updated first so pending layer can share from it.
121 active_layer_->CreateDefaultTilingsAndTiles();
122 active_layer_->SetAllTilesVisible();
123 pending_layer_->CreateDefaultTilingsAndTiles();
124 pending_layer_->SetAllTilesVisible();
127 void AddDefaultTilingsWithInvalidation(const Region& invalidation) {
128 active_layer_->AddTiling(2.3f);
129 active_layer_->AddTiling(1.0f);
130 active_layer_->AddTiling(0.5f);
131 for (size_t i = 0; i < active_layer_->tilings()->num_tilings(); ++i)
132 active_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting();
133 pending_layer_->set_invalidation(invalidation);
134 for (size_t i = 0; i < pending_layer_->tilings()->num_tilings(); ++i)
135 pending_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting();
138 void SetupPendingTree(scoped_refptr<PicturePileImpl> pile) {
139 host_impl_.CreatePendingTree();
140 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(1.f, 0.25f, 100.f);
141 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
142 // Clear recycled tree.
143 pending_tree->DetachLayerTree();
145 scoped_ptr<FakePictureLayerImpl> pending_layer =
146 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile);
147 pending_layer->SetDrawsContent(true);
148 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>());
150 pending_layer_ = static_cast<FakePictureLayerImpl*>(
151 host_impl_.pending_tree()->LayerById(id_));
152 pending_layer_->DoPostCommitInitializationIfNeeded();
155 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer,
156 float ideal_contents_scale,
157 float device_scale_factor,
158 float page_scale_factor,
159 float maximum_animation_contents_scale,
160 bool animating_transform_to_screen) {
161 layer->draw_properties().ideal_contents_scale = ideal_contents_scale;
162 layer->draw_properties().device_scale_factor = device_scale_factor;
163 layer->draw_properties().page_scale_factor = page_scale_factor;
164 layer->draw_properties().maximum_animation_contents_scale =
165 maximum_animation_contents_scale;
166 layer->draw_properties().screen_space_transform_is_animating =
167 animating_transform_to_screen;
168 layer->UpdateTiles(Occlusion());
170 static void VerifyAllTilesExistAndHavePile(
171 const PictureLayerTiling* tiling,
172 PicturePileImpl* pile) {
173 for (PictureLayerTiling::CoverageIterator iter(
174 tiling,
175 tiling->contents_scale(),
176 gfx::Rect(tiling->tiling_size()));
177 iter;
178 ++iter) {
179 EXPECT_TRUE(*iter);
180 EXPECT_EQ(pile, iter->picture_pile());
184 void SetContentsScaleOnBothLayers(float contents_scale,
185 float device_scale_factor,
186 float page_scale_factor,
187 float maximum_animation_contents_scale,
188 bool animating_transform) {
189 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
190 contents_scale,
191 device_scale_factor,
192 page_scale_factor,
193 maximum_animation_contents_scale,
194 animating_transform);
196 SetupDrawPropertiesAndUpdateTiles(active_layer_,
197 contents_scale,
198 device_scale_factor,
199 page_scale_factor,
200 maximum_animation_contents_scale,
201 animating_transform);
204 void ResetTilingsAndRasterScales() {
205 pending_layer_->ReleaseResources();
206 active_layer_->ReleaseResources();
209 void AssertAllTilesRequired(PictureLayerTiling* tiling) {
210 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
211 for (size_t i = 0; i < tiles.size(); ++i)
212 EXPECT_TRUE(tiles[i]->required_for_activation()) << "i: " << i;
213 EXPECT_GT(tiles.size(), 0u);
216 void AssertNoTilesRequired(PictureLayerTiling* tiling) {
217 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
218 for (size_t i = 0; i < tiles.size(); ++i)
219 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i;
220 EXPECT_GT(tiles.size(), 0u);
223 protected:
224 void TestTileGridAlignmentCommon() {
225 // Layer to span 4 raster tiles in x and in y
226 ImplSidePaintingSettings settings;
227 gfx::Size layer_size(
228 settings.default_tile_size.width() * 7 / 2,
229 settings.default_tile_size.height() * 7 / 2);
231 scoped_refptr<FakePicturePileImpl> pending_pile =
232 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
233 scoped_refptr<FakePicturePileImpl> active_pile =
234 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
236 SetupTrees(pending_pile, active_pile);
238 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
240 // Add 1x1 rects at the centers of each tile, then re-record pile contents
241 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
242 std::vector<Tile*> tiles =
243 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
244 EXPECT_EQ(16u, tiles.size());
245 std::vector<SkRect> rects;
246 std::vector<Tile*>::const_iterator tile_iter;
247 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
248 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint();
249 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1);
250 active_pile->add_draw_rect(rect);
251 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1));
253 // Force re-record with newly injected content
254 active_pile->RemoveRecordingAt(0, 0);
255 active_pile->AddRecordingAt(0, 0);
257 std::vector<SkRect>::const_iterator rect_iter = rects.begin();
258 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
259 MockCanvas mock_canvas(1000, 1000);
260 active_pile->RasterDirect(
261 &mock_canvas, (*tile_iter)->content_rect(), 1.0f, NULL);
263 // This test verifies that when drawing the contents of a specific tile
264 // at content scale 1.0, the playback canvas never receives content from
265 // neighboring tiles which indicates that the tile grid embedded in
266 // SkPicture is perfectly aligned with the compositor's tiles.
267 EXPECT_EQ(1u, mock_canvas.rects_.size());
268 EXPECT_RECT_EQ(*rect_iter, mock_canvas.rects_[0]);
269 rect_iter++;
273 void TestQuadsForSolidColor(bool test_for_solid);
275 FakeImplProxy proxy_;
276 TestSharedBitmapManager shared_bitmap_manager_;
277 FakeLayerTreeHostImpl host_impl_;
278 int id_;
279 FakePictureLayerImpl* pending_layer_;
280 FakePictureLayerImpl* old_pending_layer_;
281 FakePictureLayerImpl* active_layer_;
283 private:
284 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest);
287 TEST_F(PictureLayerImplTest, TileGridAlignment) {
288 host_impl_.SetDeviceScaleFactor(1.f);
289 TestTileGridAlignmentCommon();
292 TEST_F(PictureLayerImplTest, TileGridAlignmentHiDPI) {
293 host_impl_.SetDeviceScaleFactor(2.f);
294 TestTileGridAlignmentCommon();
297 TEST_F(PictureLayerImplTest, CloneNoInvalidation) {
298 gfx::Size tile_size(100, 100);
299 gfx::Size layer_bounds(400, 400);
301 scoped_refptr<FakePicturePileImpl> pending_pile =
302 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
303 scoped_refptr<FakePicturePileImpl> active_pile =
304 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
306 SetupTrees(pending_pile, active_pile);
308 Region invalidation;
309 AddDefaultTilingsWithInvalidation(invalidation);
311 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
312 active_layer_->tilings()->num_tilings());
314 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
315 EXPECT_GT(tilings->num_tilings(), 0u);
316 for (size_t i = 0; i < tilings->num_tilings(); ++i)
317 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), active_pile.get());
320 TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) {
321 base::TimeTicks time_ticks;
322 time_ticks += base::TimeDelta::FromMilliseconds(1);
323 host_impl_.SetCurrentBeginFrameArgs(
324 CreateBeginFrameArgsForTesting(time_ticks));
325 gfx::Size tile_size(100, 100);
326 gfx::Size layer_bounds(400, 400);
328 scoped_refptr<FakePicturePileImpl> pending_pile =
329 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
330 scoped_refptr<FakePicturePileImpl> active_pile =
331 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
333 SetupTrees(pending_pile, active_pile);
335 Region invalidation;
336 AddDefaultTilingsWithInvalidation(invalidation);
337 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
339 time_ticks += base::TimeDelta::FromMilliseconds(200);
340 host_impl_.SetCurrentBeginFrameArgs(
341 CreateBeginFrameArgsForTesting(time_ticks));
343 // Update tiles with viewport for tile priority as (0, 0, 100, 100) and the
344 // identify transform for tile priority.
345 bool resourceless_software_draw = false;
346 gfx::Rect viewport = gfx::Rect(layer_bounds),
347 viewport_rect_for_tile_priority = gfx::Rect(0, 0, 100, 100);
348 gfx::Transform transform, transform_for_tile_priority;
350 host_impl_.SetExternalDrawConstraints(transform,
351 viewport,
352 viewport,
353 viewport_rect_for_tile_priority,
354 transform_for_tile_priority,
355 resourceless_software_draw);
356 active_layer_->draw_properties().visible_content_rect = viewport;
357 active_layer_->draw_properties().screen_space_transform = transform;
358 active_layer_->UpdateTiles(Occlusion());
360 gfx::Rect viewport_rect_for_tile_priority_in_view_space =
361 viewport_rect_for_tile_priority;
363 // Verify the viewport rect for tile priority is used in picture layer impl.
364 EXPECT_EQ(active_layer_->viewport_rect_for_tile_priority(),
365 viewport_rect_for_tile_priority_in_view_space);
367 // Verify the viewport rect for tile priority is used in picture layer tiling.
368 PictureLayerTilingSet* tilings = active_layer_->tilings();
369 for (size_t i = 0; i < tilings->num_tilings(); i++) {
370 PictureLayerTiling* tiling = tilings->tiling_at(i);
371 EXPECT_EQ(
372 tiling->GetCurrentVisibleRectForTesting(),
373 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space,
374 tiling->contents_scale()));
377 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in
378 // screen space and the transform for tile priority is translated and
379 // rotated. The actual viewport for tile priority used by PictureLayerImpl
380 // should be (200, 200, 100, 100) applied with the said transform.
381 time_ticks += base::TimeDelta::FromMilliseconds(200);
382 host_impl_.SetCurrentBeginFrameArgs(
383 CreateBeginFrameArgsForTesting(time_ticks));
385 viewport_rect_for_tile_priority = gfx::Rect(200, 200, 100, 100);
386 transform_for_tile_priority.Translate(100, 100);
387 transform_for_tile_priority.Rotate(45);
388 host_impl_.SetExternalDrawConstraints(transform,
389 viewport,
390 viewport,
391 viewport_rect_for_tile_priority,
392 transform_for_tile_priority,
393 resourceless_software_draw);
394 active_layer_->draw_properties().visible_content_rect = viewport;
395 active_layer_->draw_properties().screen_space_transform = transform;
396 active_layer_->UpdateTiles(Occlusion());
398 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization);
399 bool success = transform_for_tile_priority.GetInverse(&screen_to_view);
400 EXPECT_TRUE(success);
402 // Note that we don't clip this to the layer bounds, since it is expected that
403 // the rect will sometimes be outside of the layer bounds. If we clip to
404 // bounds, then tile priorities will end up being incorrect in cases of fully
405 // offscreen layer.
406 viewport_rect_for_tile_priority_in_view_space =
407 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
408 screen_to_view, viewport_rect_for_tile_priority));
410 // Verify the viewport rect for tile priority is used in PictureLayerImpl.
411 EXPECT_EQ(active_layer_->viewport_rect_for_tile_priority(),
412 viewport_rect_for_tile_priority_in_view_space);
414 tilings = active_layer_->tilings();
415 for (size_t i = 0; i < tilings->num_tilings(); i++) {
416 PictureLayerTiling* tiling = tilings->tiling_at(i);
417 EXPECT_EQ(
418 tiling->GetCurrentVisibleRectForTesting(),
419 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space,
420 tiling->contents_scale()));
424 TEST_F(PictureLayerImplTest,
425 ResourcelessSoftwareDrawHasValidViewportForTilePriority) {
426 base::TimeTicks time_ticks;
427 time_ticks += base::TimeDelta::FromMilliseconds(1);
428 host_impl_.SetCurrentBeginFrameArgs(
429 CreateBeginFrameArgsForTesting(time_ticks));
431 gfx::Size tile_size(100, 100);
432 gfx::Size layer_bounds(400, 400);
434 scoped_refptr<FakePicturePileImpl> pending_pile =
435 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
436 scoped_refptr<FakePicturePileImpl> active_pile =
437 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
439 SetupTrees(pending_pile, active_pile);
441 Region invalidation;
442 AddDefaultTilingsWithInvalidation(invalidation);
443 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
445 // UpdateTiles with valid viewport. Should update tile viewport.
446 bool resourceless_software_draw = false;
447 gfx::Rect viewport = gfx::Rect(layer_bounds);
448 gfx::Transform transform;
449 host_impl_.SetExternalDrawConstraints(transform,
450 viewport,
451 viewport,
452 viewport,
453 transform,
454 resourceless_software_draw);
455 active_layer_->draw_properties().visible_content_rect = viewport;
456 active_layer_->draw_properties().screen_space_transform = transform;
457 active_layer_->UpdateTiles(Occlusion());
459 gfx::Rect visible_rect_for_tile_priority =
460 active_layer_->visible_rect_for_tile_priority();
461 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty());
462 gfx::Rect viewport_rect_for_tile_priority =
463 active_layer_->viewport_rect_for_tile_priority();
464 EXPECT_FALSE(viewport_rect_for_tile_priority.IsEmpty());
465 gfx::Transform screen_space_transform_for_tile_priority =
466 active_layer_->screen_space_transform_for_tile_priority();
468 // PictureLayerImpl does not make a special case for
469 // resource_less_software_draw, so the tile viewport and matrix should be
470 // respected.
471 time_ticks += base::TimeDelta::FromMilliseconds(200);
472 host_impl_.SetCurrentBeginFrameArgs(
473 CreateBeginFrameArgsForTesting(time_ticks));
474 resourceless_software_draw = true;
475 viewport = gfx::ScaleToEnclosingRect(viewport, 2);
476 transform.Translate(1.f, 1.f);
477 active_layer_->draw_properties().visible_content_rect = viewport;
478 active_layer_->draw_properties().screen_space_transform = transform;
479 host_impl_.SetExternalDrawConstraints(transform,
480 viewport,
481 viewport,
482 viewport,
483 transform,
484 resourceless_software_draw);
485 active_layer_->UpdateTiles(Occlusion());
487 visible_rect_for_tile_priority =
488 gfx::ScaleToEnclosingRect(visible_rect_for_tile_priority, 2);
489 viewport_rect_for_tile_priority =
490 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority, 2);
491 screen_space_transform_for_tile_priority = transform;
492 EXPECT_RECT_EQ(visible_rect_for_tile_priority,
493 active_layer_->visible_rect_for_tile_priority());
494 EXPECT_RECT_EQ(viewport_rect_for_tile_priority,
495 active_layer_->viewport_rect_for_tile_priority());
496 EXPECT_TRANSFORMATION_MATRIX_EQ(
497 screen_space_transform_for_tile_priority,
498 active_layer_->screen_space_transform_for_tile_priority());
501 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) {
502 gfx::Size tile_size(100, 100);
503 gfx::Size layer_bounds(400, 400);
504 gfx::Rect layer_invalidation(150, 200, 30, 180);
506 scoped_refptr<FakePicturePileImpl> pending_pile =
507 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
508 scoped_refptr<FakePicturePileImpl> active_pile =
509 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
511 SetupTrees(pending_pile, active_pile);
513 Region invalidation(layer_invalidation);
514 AddDefaultTilingsWithInvalidation(invalidation);
516 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
517 EXPECT_GT(tilings->num_tilings(), 0u);
518 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
519 const PictureLayerTiling* tiling = tilings->tiling_at(i);
520 gfx::Rect content_invalidation = gfx::ScaleToEnclosingRect(
521 layer_invalidation,
522 tiling->contents_scale());
523 for (PictureLayerTiling::CoverageIterator iter(
524 tiling,
525 tiling->contents_scale(),
526 gfx::Rect(tiling->tiling_size()));
527 iter;
528 ++iter) {
529 EXPECT_TRUE(*iter);
530 EXPECT_FALSE(iter.geometry_rect().IsEmpty());
531 if (iter.geometry_rect().Intersects(content_invalidation))
532 EXPECT_EQ(pending_pile.get(), iter->picture_pile());
533 else
534 EXPECT_EQ(active_pile.get(), iter->picture_pile());
539 TEST_F(PictureLayerImplTest, CloneFullInvalidation) {
540 gfx::Size tile_size(90, 80);
541 gfx::Size layer_bounds(300, 500);
543 scoped_refptr<FakePicturePileImpl> pending_pile =
544 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
545 scoped_refptr<FakePicturePileImpl> active_pile =
546 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
548 SetupTrees(pending_pile, active_pile);
550 Region invalidation((gfx::Rect(layer_bounds)));
551 AddDefaultTilingsWithInvalidation(invalidation);
553 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
554 active_layer_->tilings()->num_tilings());
556 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
557 EXPECT_GT(tilings->num_tilings(), 0u);
558 for (size_t i = 0; i < tilings->num_tilings(); ++i)
559 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), pending_pile.get());
562 TEST_F(PictureLayerImplTest, NoInvalidationBoundsChange) {
563 gfx::Size tile_size(90, 80);
564 gfx::Size active_layer_bounds(300, 500);
565 gfx::Size pending_layer_bounds(400, 800);
567 scoped_refptr<FakePicturePileImpl> pending_pile =
568 FakePicturePileImpl::CreateFilledPile(tile_size,
569 pending_layer_bounds);
570 scoped_refptr<FakePicturePileImpl> active_pile =
571 FakePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds);
573 SetupTrees(pending_pile, active_pile);
574 pending_layer_->set_fixed_tile_size(gfx::Size(100, 100));
576 Region invalidation;
577 AddDefaultTilingsWithInvalidation(invalidation);
579 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
580 EXPECT_GT(tilings->num_tilings(), 0u);
581 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
582 const PictureLayerTiling* tiling = tilings->tiling_at(i);
583 gfx::Rect active_content_bounds = gfx::ScaleToEnclosingRect(
584 gfx::Rect(active_layer_bounds),
585 tiling->contents_scale());
586 for (PictureLayerTiling::CoverageIterator iter(
587 tiling,
588 tiling->contents_scale(),
589 gfx::Rect(tiling->tiling_size()));
590 iter;
591 ++iter) {
592 EXPECT_TRUE(*iter);
593 EXPECT_FALSE(iter.geometry_rect().IsEmpty());
594 std::vector<Tile*> active_tiles =
595 active_layer_->tilings()->tiling_at(i)->AllTilesForTesting();
596 std::vector<Tile*> pending_tiles = tiling->AllTilesForTesting();
597 if (iter.geometry_rect().right() >= active_content_bounds.width() ||
598 iter.geometry_rect().bottom() >= active_content_bounds.height() ||
599 active_tiles[0]->content_rect().size() !=
600 pending_tiles[0]->content_rect().size()) {
601 EXPECT_EQ(pending_pile.get(), iter->picture_pile());
602 } else {
603 EXPECT_EQ(active_pile.get(), iter->picture_pile());
609 TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) {
610 gfx::Size tile_size(400, 400);
611 gfx::Size layer_bounds(1300, 1900);
613 scoped_refptr<FakePicturePileImpl> pending_pile =
614 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
615 scoped_refptr<FakePicturePileImpl> active_pile =
616 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
618 // Fill in some of active pile, but more of pending pile.
619 int hole_count = 0;
620 for (int x = 0; x < active_pile->tiling().num_tiles_x(); ++x) {
621 for (int y = 0; y < active_pile->tiling().num_tiles_y(); ++y) {
622 if ((x + y) % 2) {
623 pending_pile->AddRecordingAt(x, y);
624 active_pile->AddRecordingAt(x, y);
625 } else {
626 hole_count++;
627 if (hole_count % 2)
628 pending_pile->AddRecordingAt(x, y);
633 SetupTrees(pending_pile, active_pile);
634 Region invalidation;
635 AddDefaultTilingsWithInvalidation(invalidation);
637 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
638 EXPECT_GT(tilings->num_tilings(), 0u);
639 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
640 const PictureLayerTiling* tiling = tilings->tiling_at(i);
642 for (PictureLayerTiling::CoverageIterator iter(
643 tiling,
644 tiling->contents_scale(),
645 gfx::Rect(tiling->tiling_size()));
646 iter;
647 ++iter) {
648 EXPECT_FALSE(iter.full_tile_geometry_rect().IsEmpty());
649 // Ensure there is a recording for this tile.
650 bool in_pending = pending_pile->CanRaster(tiling->contents_scale(),
651 iter.full_tile_geometry_rect());
652 bool in_active = active_pile->CanRaster(tiling->contents_scale(),
653 iter.full_tile_geometry_rect());
655 if (in_pending && !in_active)
656 EXPECT_EQ(pending_pile.get(), iter->picture_pile());
657 else if (in_active)
658 EXPECT_EQ(active_pile.get(), iter->picture_pile());
659 else
660 EXPECT_FALSE(*iter);
665 TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) {
666 gfx::Size tile_size(400, 400);
667 gfx::Size layer_bounds(1300, 1900);
669 scoped_refptr<FakePicturePileImpl> pending_pile =
670 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
671 scoped_refptr<FakePicturePileImpl> active_pile =
672 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
674 SetupTrees(pending_pile, active_pile);
676 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
678 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
681 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) {
682 gfx::Size tile_size(400, 400);
683 gfx::Size layer_bounds(1300, 1900);
685 scoped_refptr<FakePicturePileImpl> pending_pile =
686 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
687 scoped_refptr<FakePicturePileImpl> active_pile =
688 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
690 SetupTrees(pending_pile, active_pile);
691 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
693 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
694 EXPECT_LT(low_res_factor, 1.f);
696 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
697 6.f, // ideal contents scale
698 3.f, // device scale
699 2.f, // page scale
700 1.f, // maximum animation scale
701 false);
702 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
703 EXPECT_FLOAT_EQ(6.f,
704 pending_layer_->tilings()->tiling_at(0)->contents_scale());
705 EXPECT_FLOAT_EQ(6.f * low_res_factor,
706 pending_layer_->tilings()->tiling_at(1)->contents_scale());
708 // If we change the page scale factor, then we should get new tilings.
709 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
710 6.6f, // ideal contents scale
711 3.f, // device scale
712 2.2f, // page scale
713 1.f, // maximum animation scale
714 false);
715 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings());
716 EXPECT_FLOAT_EQ(6.6f,
717 pending_layer_->tilings()->tiling_at(0)->contents_scale());
718 EXPECT_FLOAT_EQ(6.6f * low_res_factor,
719 pending_layer_->tilings()->tiling_at(2)->contents_scale());
721 // If we change the device scale factor, then we should get new tilings.
722 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
723 7.26f, // ideal contents scale
724 3.3f, // device scale
725 2.2f, // page scale
726 1.f, // maximum animation scale
727 false);
728 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings());
729 EXPECT_FLOAT_EQ(7.26f,
730 pending_layer_->tilings()->tiling_at(0)->contents_scale());
731 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
732 pending_layer_->tilings()->tiling_at(3)->contents_scale());
734 // If we change the device scale factor, but end up at the same total scale
735 // factor somehow, then we don't get new tilings.
736 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
737 7.26f, // ideal contents scale
738 2.2f, // device scale
739 3.3f, // page scale
740 1.f, // maximum animation scale
741 false);
742 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings());
743 EXPECT_FLOAT_EQ(7.26f,
744 pending_layer_->tilings()->tiling_at(0)->contents_scale());
745 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
746 pending_layer_->tilings()->tiling_at(3)->contents_scale());
749 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) {
750 // This test makes sure that if a layer can have tilings, then a commit makes
751 // it not able to have tilings (empty size), and then a future commit that
752 // makes it valid again should be able to create tilings.
753 gfx::Size tile_size(400, 400);
754 gfx::Size layer_bounds(1300, 1900);
756 scoped_refptr<FakePicturePileImpl> empty_pile =
757 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
758 scoped_refptr<FakePicturePileImpl> valid_pile =
759 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
761 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
762 EXPECT_LT(low_res_factor, 1.f);
764 float high_res_scale = 1.3f;
765 float low_res_scale = high_res_scale * low_res_factor;
766 float device_scale = 1.7f;
767 float page_scale = 3.2f;
768 float maximum_animation_scale = 1.f;
770 SetupPendingTree(valid_pile);
771 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
772 high_res_scale,
773 device_scale,
774 page_scale,
775 maximum_animation_scale,
776 false);
777 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
778 EXPECT_FLOAT_EQ(high_res_scale,
779 pending_layer_->HighResTiling()->contents_scale());
780 EXPECT_FLOAT_EQ(low_res_scale,
781 pending_layer_->LowResTiling()->contents_scale());
783 ActivateTree();
784 SetupPendingTree(empty_pile);
785 EXPECT_FALSE(pending_layer_->CanHaveTilings());
786 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
787 high_res_scale,
788 device_scale,
789 page_scale,
790 maximum_animation_scale,
791 false);
792 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
793 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
795 ActivateTree();
796 EXPECT_FALSE(active_layer_->CanHaveTilings());
797 SetupDrawPropertiesAndUpdateTiles(active_layer_,
798 high_res_scale,
799 device_scale,
800 page_scale,
801 maximum_animation_scale,
802 false);
803 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
805 SetupPendingTree(valid_pile);
806 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
807 high_res_scale,
808 device_scale,
809 page_scale,
810 maximum_animation_scale,
811 false);
812 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
813 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
814 EXPECT_FLOAT_EQ(high_res_scale,
815 pending_layer_->HighResTiling()->contents_scale());
816 EXPECT_FLOAT_EQ(low_res_scale,
817 pending_layer_->LowResTiling()->contents_scale());
820 TEST_F(PictureLayerImplTest, ZoomOutCrash) {
821 gfx::Size tile_size(400, 400);
822 gfx::Size layer_bounds(1300, 1900);
824 // Set up the high and low res tilings before pinch zoom.
825 scoped_refptr<FakePicturePileImpl> pending_pile =
826 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
827 scoped_refptr<FakePicturePileImpl> active_pile =
828 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
830 SetupTrees(pending_pile, active_pile);
831 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
832 SetContentsScaleOnBothLayers(32.0f, 1.0f, 32.0f, 1.0f, false);
833 host_impl_.PinchGestureBegin();
834 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false);
835 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false);
836 EXPECT_EQ(active_layer_->tilings()->NumHighResTilings(), 1);
839 TEST_F(PictureLayerImplTest, PinchGestureTilings) {
840 gfx::Size tile_size(400, 400);
841 gfx::Size layer_bounds(1300, 1900);
843 scoped_refptr<FakePicturePileImpl> pending_pile =
844 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
845 scoped_refptr<FakePicturePileImpl> active_pile =
846 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
848 // Set up the high and low res tilings before pinch zoom.
849 SetupTrees(pending_pile, active_pile);
850 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
851 SetContentsScaleOnBothLayers(2.0f, 1.0f, 1.0f, 1.0f, false);
852 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
853 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
854 EXPECT_FLOAT_EQ(2.0f,
855 active_layer_->tilings()->tiling_at(0)->contents_scale());
856 EXPECT_FLOAT_EQ(2.0f * low_res_factor,
857 active_layer_->tilings()->tiling_at(1)->contents_scale());
859 // Start a pinch gesture.
860 host_impl_.PinchGestureBegin();
862 // Zoom out by a small amount. We should create a tiling at half
863 // the scale (2/kMaxScaleRatioDuringPinch).
864 SetContentsScaleOnBothLayers(1.8f, 1.0f, 0.9f, 1.0f, false);
865 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
866 EXPECT_FLOAT_EQ(2.0f,
867 active_layer_->tilings()->tiling_at(0)->contents_scale());
868 EXPECT_FLOAT_EQ(1.0f,
869 active_layer_->tilings()->tiling_at(1)->contents_scale());
870 EXPECT_FLOAT_EQ(2.0f * low_res_factor,
871 active_layer_->tilings()->tiling_at(2)->contents_scale());
873 // Zoom out further, close to our low-res scale factor. We should
874 // use that tiling as high-res, and not create a new tiling.
875 SetContentsScaleOnBothLayers(
876 low_res_factor, 1.0f, low_res_factor / 2.0f, 1.0f, false);
877 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
879 // Zoom in a lot now. Since we increase by increments of
880 // kMaxScaleRatioDuringPinch, this will first use 1.0, then 2.0
881 // and then finally create a new tiling at 4.0.
882 SetContentsScaleOnBothLayers(4.2f, 1.0f, 2.1f, 1.f, false);
883 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
884 SetContentsScaleOnBothLayers(4.2f, 1.0f, 2.1f, 1.f, false);
885 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
886 SetContentsScaleOnBothLayers(4.2f, 1.0f, 2.1f, 1.f, false);
887 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings());
888 EXPECT_FLOAT_EQ(4.0f,
889 active_layer_->tilings()->tiling_at(0)->contents_scale());
892 TEST_F(PictureLayerImplTest, SnappedTilingDuringZoom) {
893 gfx::Size tile_size(300, 300);
894 gfx::Size layer_bounds(2600, 3800);
896 scoped_refptr<FakePicturePileImpl> pending_pile =
897 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
898 scoped_refptr<FakePicturePileImpl> active_pile =
899 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
901 // Set up the high and low res tilings before pinch zoom.
902 SetupTrees(pending_pile, active_pile);
903 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
904 SetContentsScaleOnBothLayers(0.24f, 1.0f, 0.24f, 1.0f, false);
905 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
906 EXPECT_FLOAT_EQ(0.24f,
907 active_layer_->tilings()->tiling_at(0)->contents_scale());
908 EXPECT_FLOAT_EQ(0.0625f,
909 active_layer_->tilings()->tiling_at(1)->contents_scale());
911 // Start a pinch gesture.
912 host_impl_.PinchGestureBegin();
914 // Zoom out by a small amount. We should create a tiling at half
915 // the scale (1/kMaxScaleRatioDuringPinch).
916 SetContentsScaleOnBothLayers(0.2f, 1.0f, 0.2f, 1.0f, false);
917 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
918 EXPECT_FLOAT_EQ(0.24f,
919 active_layer_->tilings()->tiling_at(0)->contents_scale());
920 EXPECT_FLOAT_EQ(0.12f,
921 active_layer_->tilings()->tiling_at(1)->contents_scale());
922 EXPECT_FLOAT_EQ(0.0625,
923 active_layer_->tilings()->tiling_at(2)->contents_scale());
925 // Zoom out further, close to our low-res scale factor. We should
926 // use that tiling as high-res, and not create a new tiling.
927 SetContentsScaleOnBothLayers(0.1f, 1.0f, 0.1f, 1.0f, false);
928 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
930 // Zoom in. 0.125(desired_scale) should be snapped to 0.12 during zoom-in
931 // because 0.125(desired_scale) is within the ratio(1.2)
932 SetContentsScaleOnBothLayers(0.5f, 1.0f, 0.5f, 1.0f, false);
933 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
936 TEST_F(PictureLayerImplTest, CleanUpTilings) {
937 gfx::Size tile_size(400, 400);
938 gfx::Size layer_bounds(1300, 1900);
940 scoped_refptr<FakePicturePileImpl> pending_pile =
941 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
942 scoped_refptr<FakePicturePileImpl> active_pile =
943 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
945 std::vector<PictureLayerTiling*> used_tilings;
947 SetupTrees(pending_pile, active_pile);
948 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
950 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
951 EXPECT_LT(low_res_factor, 1.f);
953 float device_scale = 1.7f;
954 float page_scale = 3.2f;
955 float scale = 1.f;
957 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false);
958 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
960 // We only have ideal tilings, so they aren't removed.
961 used_tilings.clear();
962 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
963 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
965 host_impl_.PinchGestureBegin();
967 // Changing the ideal but not creating new tilings.
968 scale *= 1.5f;
969 page_scale *= 1.5f;
970 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false);
971 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
973 // The tilings are still our target scale, so they aren't removed.
974 used_tilings.clear();
975 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
976 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
978 host_impl_.PinchGestureEnd();
980 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
981 scale /= 4.f;
982 page_scale /= 4.f;
983 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, false);
984 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
985 EXPECT_FLOAT_EQ(
986 1.f,
987 active_layer_->tilings()->tiling_at(1)->contents_scale());
988 EXPECT_FLOAT_EQ(
989 1.f * low_res_factor,
990 active_layer_->tilings()->tiling_at(3)->contents_scale());
992 // Mark the non-ideal tilings as used. They won't be removed.
993 used_tilings.clear();
994 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
995 used_tilings.push_back(active_layer_->tilings()->tiling_at(3));
996 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
997 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
999 // Now move the ideal scale to 0.5. Our target stays 1.2.
1000 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, false);
1002 // The high resolution tiling is between target and ideal, so is not
1003 // removed. The low res tiling for the old ideal=1.0 scale is removed.
1004 used_tilings.clear();
1005 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1006 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1008 // Now move the ideal scale to 1.0. Our target stays 1.2.
1009 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false);
1011 // All the tilings are between are target and the ideal, so they are not
1012 // removed.
1013 used_tilings.clear();
1014 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1015 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1017 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
1018 SetupDrawPropertiesAndUpdateTiles(
1019 active_layer_, 1.1f, device_scale, page_scale, 1.f, false);
1021 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1022 // in the range [1.0,1.2] and are kept.
1023 used_tilings.clear();
1024 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1025 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1027 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1028 // 1.2 still.
1029 SetupDrawPropertiesAndUpdateTiles(
1030 pending_layer_, 1.1f, device_scale, page_scale, 1.f, false);
1032 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1033 // target raster scale. But it is in our used tilings set, so nothing is
1034 // deleted.
1035 used_tilings.clear();
1036 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
1037 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1038 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1040 // If we remove it from our used tilings set, it is outside the range to keep
1041 // so it is deleted.
1042 used_tilings.clear();
1043 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1044 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
1047 #define EXPECT_BOTH_EQ(expression, x) \
1048 do { \
1049 EXPECT_EQ(x, pending_layer_->expression); \
1050 EXPECT_EQ(x, active_layer_->expression); \
1051 } while (false)
1053 #define EXPECT_BOTH_NE(expression, x) \
1054 do { \
1055 EXPECT_NE(x, pending_layer_->expression); \
1056 EXPECT_NE(x, active_layer_->expression); \
1057 } while (false)
1059 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) {
1060 // Make sure this layer covers multiple tiles, since otherwise low
1061 // res won't get created because it is too small.
1062 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1063 SetupDefaultTrees(gfx::Size(tile_size.width() + 1, tile_size.height() + 1));
1064 // Avoid max untiled layer size heuristics via fixed tile size.
1065 pending_layer_->set_fixed_tile_size(tile_size);
1066 active_layer_->set_fixed_tile_size(tile_size);
1068 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1069 float contents_scale = 1.f;
1070 float device_scale = 1.f;
1071 float page_scale = 1.f;
1072 float maximum_animation_scale = 1.f;
1073 bool animating_transform = true;
1075 // Animating, so don't create low res even if there isn't one already.
1076 SetContentsScaleOnBothLayers(contents_scale,
1077 device_scale,
1078 page_scale,
1079 maximum_animation_scale,
1080 animating_transform);
1081 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1082 EXPECT_BOTH_EQ(num_tilings(), 1u);
1084 // Stop animating, low res gets created.
1085 animating_transform = false;
1086 SetContentsScaleOnBothLayers(contents_scale,
1087 device_scale,
1088 page_scale,
1089 maximum_animation_scale,
1090 animating_transform);
1091 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1092 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor);
1093 EXPECT_BOTH_EQ(num_tilings(), 2u);
1095 // Page scale animation, new high res, but not new low res because animating.
1096 contents_scale = 2.f;
1097 page_scale = 2.f;
1098 animating_transform = true;
1099 SetContentsScaleOnBothLayers(contents_scale,
1100 device_scale,
1101 page_scale,
1102 maximum_animation_scale,
1103 animating_transform);
1104 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1105 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor);
1106 EXPECT_BOTH_EQ(num_tilings(), 3u);
1108 // Stop animating, new low res gets created for final page scale.
1109 animating_transform = false;
1110 SetContentsScaleOnBothLayers(contents_scale,
1111 device_scale,
1112 page_scale,
1113 maximum_animation_scale,
1114 animating_transform);
1115 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1116 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f * low_res_factor);
1117 EXPECT_BOTH_EQ(num_tilings(), 4u);
1120 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) {
1121 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1122 SetupDefaultTrees(tile_size);
1124 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1125 float device_scale = 1.f;
1126 float page_scale = 1.f;
1127 float maximum_animation_scale = 1.f;
1128 bool animating_transform = false;
1130 // Contents exactly fit on one tile at scale 1, no low res.
1131 float contents_scale = 1.f;
1132 SetContentsScaleOnBothLayers(contents_scale,
1133 device_scale,
1134 page_scale,
1135 maximum_animation_scale,
1136 animating_transform);
1137 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1138 EXPECT_BOTH_EQ(num_tilings(), 1u);
1140 ResetTilingsAndRasterScales();
1142 // Contents that are smaller than one tile, no low res.
1143 contents_scale = 0.123f;
1144 SetContentsScaleOnBothLayers(contents_scale,
1145 device_scale,
1146 page_scale,
1147 maximum_animation_scale,
1148 animating_transform);
1149 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1150 EXPECT_BOTH_EQ(num_tilings(), 1u);
1152 ResetTilingsAndRasterScales();
1154 // Any content bounds that would create more than one tile will
1155 // generate a low res tiling.
1156 contents_scale = 2.5f;
1157 SetContentsScaleOnBothLayers(contents_scale,
1158 device_scale,
1159 page_scale,
1160 maximum_animation_scale,
1161 animating_transform);
1162 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1163 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1164 contents_scale * low_res_factor);
1165 EXPECT_BOTH_EQ(num_tilings(), 2u);
1167 ResetTilingsAndRasterScales();
1169 // Mask layers dont create low res since they always fit on one tile.
1170 pending_layer_->pile()->set_is_mask(true);
1171 active_layer_->pile()->set_is_mask(true);
1172 SetContentsScaleOnBothLayers(contents_scale,
1173 device_scale,
1174 page_scale,
1175 maximum_animation_scale,
1176 animating_transform);
1177 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1178 EXPECT_BOTH_EQ(num_tilings(), 1u);
1181 TEST_F(PictureLayerImplTest, HugeMasksDontGetTiles) {
1182 gfx::Size tile_size(100, 100);
1184 scoped_refptr<FakePicturePileImpl> valid_pile =
1185 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1000, 1000));
1186 valid_pile->set_is_mask(true);
1187 SetupPendingTree(valid_pile);
1189 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1190 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
1191 EXPECT_EQ(1u, pending_layer_->num_tilings());
1193 pending_layer_->HighResTiling()->CreateAllTilesForTesting();
1194 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1195 pending_layer_->HighResTiling()->AllTilesForTesting());
1197 ActivateTree();
1199 // Mask layers have a tiling with a single tile in it.
1200 EXPECT_EQ(1u, active_layer_->HighResTiling()->AllTilesForTesting().size());
1201 // The mask resource exists.
1202 EXPECT_NE(0u, active_layer_->ContentsResourceId());
1204 // Resize larger than the max texture size.
1205 int max_texture_size = host_impl_.GetRendererCapabilities().max_texture_size;
1206 scoped_refptr<FakePicturePileImpl> huge_pile =
1207 FakePicturePileImpl::CreateFilledPile(
1208 tile_size, gfx::Size(max_texture_size + 1, 10));
1209 huge_pile->set_is_mask(true);
1210 SetupPendingTree(huge_pile);
1212 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1213 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
1214 EXPECT_EQ(1u, pending_layer_->num_tilings());
1216 pending_layer_->HighResTiling()->CreateAllTilesForTesting();
1217 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1218 pending_layer_->HighResTiling()->AllTilesForTesting());
1220 ActivateTree();
1222 // Mask layers have a tiling, but there should be no tiles in it.
1223 EXPECT_EQ(0u, active_layer_->HighResTiling()->AllTilesForTesting().size());
1224 // The mask resource is empty.
1225 EXPECT_EQ(0u, active_layer_->ContentsResourceId());
1228 TEST_F(PictureLayerImplTest, ReleaseResources) {
1229 gfx::Size tile_size(400, 400);
1230 gfx::Size layer_bounds(1300, 1900);
1232 scoped_refptr<FakePicturePileImpl> pending_pile =
1233 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1234 scoped_refptr<FakePicturePileImpl> active_pile =
1235 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1237 SetupTrees(pending_pile, active_pile);
1238 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1240 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
1241 1.3f, // ideal contents scale
1242 2.7f, // device scale
1243 3.2f, // page scale
1244 1.f, // maximum animation scale
1245 false);
1246 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1248 // All tilings should be removed when losing output surface.
1249 active_layer_->ReleaseResources();
1250 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1251 pending_layer_->ReleaseResources();
1252 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1254 // This should create new tilings.
1255 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
1256 1.3f, // ideal contents scale
1257 2.7f, // device scale
1258 3.2f, // page scale
1259 1.f, // maximum animation scale
1260 false);
1261 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1264 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) {
1265 // The default max tile size is larger than 400x400.
1266 gfx::Size tile_size(400, 400);
1267 gfx::Size layer_bounds(5000, 5000);
1269 scoped_refptr<FakePicturePileImpl> pending_pile =
1270 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1271 scoped_refptr<FakePicturePileImpl> active_pile =
1272 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1274 SetupTrees(pending_pile, active_pile);
1275 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1277 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1278 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1280 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1282 // The default value.
1283 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1284 host_impl_.settings().default_tile_size.ToString());
1286 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1287 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1288 tile->content_rect().size().ToString());
1290 pending_layer_->ReleaseResources();
1292 // Change the max texture size on the output surface context.
1293 scoped_ptr<TestWebGraphicsContext3D> context =
1294 TestWebGraphicsContext3D::Create();
1295 context->set_max_texture_size(140);
1296 host_impl_.DidLoseOutputSurface();
1297 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d(
1298 context.Pass()).PassAs<OutputSurface>());
1300 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1301 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1303 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1305 // Verify the tiles are not larger than the context's max texture size.
1306 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1307 EXPECT_GE(140, tile->content_rect().width());
1308 EXPECT_GE(140, tile->content_rect().height());
1311 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) {
1312 // The default max tile size is larger than 400x400.
1313 gfx::Size tile_size(400, 400);
1314 gfx::Size layer_bounds(500, 500);
1316 scoped_refptr<FakePicturePileImpl> pending_pile =
1317 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1318 scoped_refptr<FakePicturePileImpl> active_pile =
1319 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1321 SetupTrees(pending_pile, active_pile);
1322 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1324 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1325 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings());
1327 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1329 // The default value. The layer is smaller than this.
1330 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1331 host_impl_.settings().max_untiled_layer_size.ToString());
1333 // There should be a single tile since the layer is small.
1334 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0);
1335 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size());
1337 pending_layer_->ReleaseResources();
1339 // Change the max texture size on the output surface context.
1340 scoped_ptr<TestWebGraphicsContext3D> context =
1341 TestWebGraphicsContext3D::Create();
1342 context->set_max_texture_size(140);
1343 host_impl_.DidLoseOutputSurface();
1344 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d(
1345 context.Pass()).PassAs<OutputSurface>());
1347 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1348 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings());
1350 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1352 // There should be more than one tile since the max texture size won't cover
1353 // the layer.
1354 high_res_tiling = pending_layer_->tilings()->tiling_at(0);
1355 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size());
1357 // Verify the tiles are not larger than the context's max texture size.
1358 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1359 EXPECT_GE(140, tile->content_rect().width());
1360 EXPECT_GE(140, tile->content_rect().height());
1363 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) {
1364 MockOcclusionTracker<LayerImpl> occlusion_tracker;
1365 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1367 gfx::Size tile_size(400, 400);
1368 gfx::Size layer_bounds(1300, 1900);
1370 scoped_refptr<FakePicturePileImpl> pending_pile =
1371 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1372 scoped_refptr<FakePicturePileImpl> active_pile =
1373 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1375 SetupTrees(pending_pile, active_pile);
1377 active_layer_->draw_properties().visible_content_rect =
1378 gfx::Rect(layer_bounds);
1380 gfx::Rect layer_invalidation(150, 200, 30, 180);
1381 Region invalidation(layer_invalidation);
1382 AddDefaultTilingsWithInvalidation(invalidation);
1384 AppendQuadsData data;
1385 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, NULL);
1386 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data);
1387 active_layer_->DidDraw(NULL);
1389 ASSERT_EQ(1U, render_pass->quad_list.size());
1390 EXPECT_EQ(DrawQuad::PICTURE_CONTENT, render_pass->quad_list[0]->material);
1393 TEST_F(PictureLayerImplTest, MarkRequiredNullTiles) {
1394 gfx::Size tile_size(100, 100);
1395 gfx::Size layer_bounds(1000, 1000);
1397 scoped_refptr<FakePicturePileImpl> pending_pile =
1398 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
1399 // Layers with entirely empty piles can't get tilings.
1400 pending_pile->AddRecordingAt(0, 0);
1402 SetupPendingTree(pending_pile);
1404 ASSERT_TRUE(pending_layer_->CanHaveTilings());
1405 pending_layer_->AddTiling(1.0f);
1406 pending_layer_->AddTiling(2.0f);
1408 // It should be safe to call this (and MarkVisibleResourcesAsRequired)
1409 // on a layer with no recordings.
1410 host_impl_.pending_tree()->UpdateDrawProperties();
1411 pending_layer_->MarkVisibleResourcesAsRequired();
1414 TEST_F(PictureLayerImplTest, MarkRequiredOffscreenTiles) {
1415 gfx::Size tile_size(100, 100);
1416 gfx::Size layer_bounds(200, 200);
1418 scoped_refptr<FakePicturePileImpl> pending_pile =
1419 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1420 SetupPendingTree(pending_pile);
1422 pending_layer_->set_fixed_tile_size(tile_size);
1423 ASSERT_TRUE(pending_layer_->CanHaveTilings());
1424 PictureLayerTiling* tiling = pending_layer_->AddTiling(1.f);
1425 host_impl_.pending_tree()->UpdateDrawProperties();
1426 EXPECT_EQ(tiling->resolution(), HIGH_RESOLUTION);
1428 pending_layer_->draw_properties().visible_content_rect =
1429 gfx::Rect(0, 0, 100, 200);
1431 // Fake set priorities.
1432 for (PictureLayerTiling::CoverageIterator iter(
1433 tiling, pending_layer_->contents_scale_x(), gfx::Rect(layer_bounds));
1434 iter;
1435 ++iter) {
1436 if (!*iter)
1437 continue;
1438 Tile* tile = *iter;
1439 TilePriority priority;
1440 priority.resolution = HIGH_RESOLUTION;
1441 gfx::Rect tile_bounds = iter.geometry_rect();
1442 if (pending_layer_->visible_content_rect().Intersects(tile_bounds)) {
1443 priority.priority_bin = TilePriority::NOW;
1444 priority.distance_to_visible = 0.f;
1445 } else {
1446 priority.priority_bin = TilePriority::SOON;
1447 priority.distance_to_visible = 1.f;
1449 tile->SetPriority(PENDING_TREE, priority);
1452 pending_layer_->MarkVisibleResourcesAsRequired();
1454 int num_visible = 0;
1455 int num_offscreen = 0;
1457 for (PictureLayerTiling::CoverageIterator iter(
1458 tiling, pending_layer_->contents_scale_x(), gfx::Rect(layer_bounds));
1459 iter;
1460 ++iter) {
1461 if (!*iter)
1462 continue;
1463 const Tile* tile = *iter;
1464 if (tile->priority(PENDING_TREE).distance_to_visible == 0.f) {
1465 EXPECT_TRUE(tile->required_for_activation());
1466 num_visible++;
1467 } else {
1468 EXPECT_FALSE(tile->required_for_activation());
1469 num_offscreen++;
1473 EXPECT_GT(num_visible, 0);
1474 EXPECT_GT(num_offscreen, 0);
1477 TEST_F(PictureLayerImplTest, TileOutsideOfViewportForTilePriorityNotRequired) {
1478 base::TimeTicks time_ticks;
1479 time_ticks += base::TimeDelta::FromMilliseconds(1);
1480 host_impl_.SetCurrentBeginFrameArgs(
1481 CreateBeginFrameArgsForTesting(time_ticks));
1483 gfx::Size tile_size(100, 100);
1484 gfx::Size layer_bounds(400, 400);
1485 gfx::Rect external_viewport_for_tile_priority(400, 200);
1486 gfx::Rect visible_content_rect(200, 400);
1488 scoped_refptr<FakePicturePileImpl> active_pile =
1489 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1490 scoped_refptr<FakePicturePileImpl> pending_pile =
1491 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1492 SetupTrees(pending_pile, active_pile);
1494 active_layer_->set_fixed_tile_size(tile_size);
1495 pending_layer_->set_fixed_tile_size(tile_size);
1496 ASSERT_TRUE(pending_layer_->CanHaveTilings());
1497 PictureLayerTiling* tiling = pending_layer_->AddTiling(1.f);
1499 // Set external viewport for tile priority.
1500 gfx::Rect viewport = gfx::Rect(layer_bounds);
1501 gfx::Transform transform;
1502 gfx::Transform transform_for_tile_priority;
1503 bool resourceless_software_draw = false;
1504 host_impl_.SetExternalDrawConstraints(transform,
1505 viewport,
1506 viewport,
1507 external_viewport_for_tile_priority,
1508 transform_for_tile_priority,
1509 resourceless_software_draw);
1510 host_impl_.pending_tree()->UpdateDrawProperties();
1512 // Set visible content rect that is different from
1513 // external_viewport_for_tile_priority.
1514 pending_layer_->draw_properties().visible_content_rect = visible_content_rect;
1515 time_ticks += base::TimeDelta::FromMilliseconds(200);
1516 host_impl_.SetCurrentBeginFrameArgs(
1517 CreateBeginFrameArgsForTesting(time_ticks));
1518 pending_layer_->UpdateTiles(Occlusion());
1520 pending_layer_->MarkVisibleResourcesAsRequired();
1522 // Intersect the two rects. Any tile outside should not be required for
1523 // activation.
1524 gfx::Rect viewport_for_tile_priority =
1525 pending_layer_->GetViewportForTilePriorityInContentSpace();
1526 viewport_for_tile_priority.Intersect(pending_layer_->visible_content_rect());
1528 int num_inside = 0;
1529 int num_outside = 0;
1530 for (PictureLayerTiling::CoverageIterator iter(
1531 tiling, pending_layer_->contents_scale_x(), gfx::Rect(layer_bounds));
1532 iter;
1533 ++iter) {
1534 if (!*iter)
1535 continue;
1536 Tile* tile = *iter;
1537 if (viewport_for_tile_priority.Intersects(iter.geometry_rect())) {
1538 num_inside++;
1539 // Mark everything in viewport for tile priority as ready to draw.
1540 ManagedTileState::TileVersion& tile_version =
1541 tile->GetTileVersionForTesting(
1542 tile->DetermineRasterModeForTree(PENDING_TREE));
1543 tile_version.SetSolidColorForTesting(SK_ColorRED);
1544 } else {
1545 num_outside++;
1546 EXPECT_FALSE(tile->required_for_activation());
1550 EXPECT_GT(num_inside, 0);
1551 EXPECT_GT(num_outside, 0);
1553 // Activate and draw active layer.
1554 host_impl_.ActivateSyncTree();
1555 host_impl_.active_tree()->UpdateDrawProperties();
1556 active_layer_->draw_properties().visible_content_rect = visible_content_rect;
1558 MockOcclusionTracker<LayerImpl> occlusion_tracker;
1559 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1560 AppendQuadsData data;
1561 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, NULL);
1562 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data);
1563 active_layer_->DidDraw(NULL);
1565 // All tiles in activation rect is ready to draw.
1566 EXPECT_EQ(0u, data.num_missing_tiles);
1567 EXPECT_EQ(0u, data.num_incomplete_tiles);
1570 TEST_F(PictureLayerImplTest, HighResTileIsComplete) {
1571 base::TimeTicks time_ticks;
1572 time_ticks += base::TimeDelta::FromMilliseconds(1);
1573 host_impl_.SetCurrentBeginFrameArgs(
1574 CreateBeginFrameArgsForTesting(time_ticks));
1576 gfx::Size tile_size(100, 100);
1577 gfx::Size layer_bounds(200, 200);
1579 host_impl_.SetViewportSize(layer_bounds);
1581 scoped_refptr<FakePicturePileImpl> pending_pile =
1582 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1583 SetupPendingTree(pending_pile);
1584 ActivateTree();
1586 // All high res tiles have resources.
1587 active_layer_->set_fixed_tile_size(tile_size);
1588 host_impl_.active_tree()->UpdateDrawProperties();
1589 std::vector<Tile*> tiles =
1590 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
1591 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
1593 MockOcclusionTracker<LayerImpl> occlusion_tracker;
1594 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1595 AppendQuadsData data;
1596 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, NULL);
1597 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data);
1598 active_layer_->DidDraw(NULL);
1600 // All high res tiles drew, nothing was incomplete.
1601 EXPECT_EQ(9u, render_pass->quad_list.size());
1602 EXPECT_EQ(0u, data.num_missing_tiles);
1603 EXPECT_EQ(0u, data.num_incomplete_tiles);
1606 TEST_F(PictureLayerImplTest, LowResTileIsIncomplete) {
1607 base::TimeTicks time_ticks;
1608 time_ticks += base::TimeDelta::FromMilliseconds(1);
1609 host_impl_.SetCurrentBeginFrameArgs(
1610 CreateBeginFrameArgsForTesting(time_ticks));
1612 gfx::Size tile_size(100, 100);
1613 gfx::Size layer_bounds(200, 200);
1615 host_impl_.SetViewportSize(layer_bounds);
1617 scoped_refptr<FakePicturePileImpl> pending_pile =
1618 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1619 SetupPendingTree(pending_pile);
1620 ActivateTree();
1622 // All high res tiles have resources except one.
1623 active_layer_->set_fixed_tile_size(tile_size);
1624 host_impl_.active_tree()->UpdateDrawProperties();
1625 std::vector<Tile*> high_tiles =
1626 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
1627 high_tiles.erase(high_tiles.begin());
1628 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles);
1630 // All low res tiles have resources.
1631 std::vector<Tile*> low_tiles =
1632 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting();
1633 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles);
1635 MockOcclusionTracker<LayerImpl> occlusion_tracker;
1636 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1637 AppendQuadsData data;
1638 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, NULL);
1639 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data);
1640 active_layer_->DidDraw(NULL);
1642 // The missing high res tile was replaced by a low res tile.
1643 EXPECT_EQ(9u, render_pass->quad_list.size());
1644 EXPECT_EQ(0u, data.num_missing_tiles);
1645 EXPECT_EQ(1u, data.num_incomplete_tiles);
1648 TEST_F(PictureLayerImplTest,
1649 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal) {
1650 base::TimeTicks time_ticks;
1651 time_ticks += base::TimeDelta::FromMilliseconds(1);
1652 host_impl_.SetCurrentBeginFrameArgs(
1653 CreateBeginFrameArgsForTesting(time_ticks));
1655 gfx::Size tile_size(100, 100);
1656 gfx::Size layer_bounds(200, 200);
1658 host_impl_.SetViewportSize(layer_bounds);
1660 scoped_refptr<FakePicturePileImpl> pending_pile =
1661 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1662 scoped_refptr<FakePicturePileImpl> active_pile =
1663 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1664 SetupTrees(pending_pile, active_pile);
1666 active_layer_->set_fixed_tile_size(tile_size);
1668 active_layer_->draw_properties().visible_content_rect =
1669 gfx::Rect(layer_bounds);
1670 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.f, 1.f, 1.f, 1.f, false);
1672 // One ideal tile exists, this will get used when drawing.
1673 std::vector<Tile*> ideal_tiles;
1674 EXPECT_EQ(2.f, active_layer_->HighResTiling()->contents_scale());
1675 ideal_tiles.push_back(active_layer_->HighResTiling()->TileAt(0, 0));
1676 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1677 ideal_tiles);
1679 // Due to layer scale throttling, the raster contents scale is changed to 1,
1680 // while the ideal is still 2.
1681 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
1682 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.f, 1.f, 1.f, 1.f, false);
1684 EXPECT_EQ(1.f, active_layer_->HighResTiling()->contents_scale());
1685 EXPECT_EQ(1.f, active_layer_->raster_contents_scale());
1686 EXPECT_EQ(2.f, active_layer_->ideal_contents_scale());
1688 // Both tilings still exist.
1689 EXPECT_EQ(2.f, active_layer_->tilings()->tiling_at(0)->contents_scale());
1690 EXPECT_EQ(1.f, active_layer_->tilings()->tiling_at(1)->contents_scale());
1692 // All high res tiles have resources.
1693 std::vector<Tile*> high_tiles =
1694 active_layer_->HighResTiling()->AllTilesForTesting();
1695 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles);
1697 MockOcclusionTracker<LayerImpl> occlusion_tracker;
1698 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
1699 AppendQuadsData data;
1700 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, NULL);
1701 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data);
1702 active_layer_->DidDraw(NULL);
1704 // All high res tiles drew, and the one ideal res tile drew.
1705 ASSERT_GT(render_pass->quad_list.size(), 9u);
1706 EXPECT_EQ(gfx::SizeF(99.f, 99.f),
1707 TileDrawQuad::MaterialCast(render_pass->quad_list[0])
1708 ->tex_coord_rect.size());
1709 EXPECT_EQ(gfx::SizeF(49.5f, 49.5f),
1710 TileDrawQuad::MaterialCast(render_pass->quad_list[1])
1711 ->tex_coord_rect.size());
1713 // Neither the high res nor the ideal tiles were considered as incomplete.
1714 EXPECT_EQ(0u, data.num_missing_tiles);
1715 EXPECT_EQ(0u, data.num_incomplete_tiles);
1718 TEST_F(PictureLayerImplTest, HighResRequiredWhenUnsharedActiveAllReady) {
1719 gfx::Size layer_bounds(400, 400);
1720 gfx::Size tile_size(100, 100);
1721 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
1723 // No tiles shared.
1724 pending_layer_->set_invalidation(gfx::Rect(layer_bounds));
1726 CreateHighLowResAndSetAllTilesVisible();
1728 active_layer_->SetAllTilesReady();
1730 // No shared tiles and all active tiles ready, so pending can only
1731 // activate with all high res tiles.
1732 pending_layer_->MarkVisibleResourcesAsRequired();
1733 AssertAllTilesRequired(pending_layer_->HighResTiling());
1734 AssertNoTilesRequired(pending_layer_->LowResTiling());
1737 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) {
1738 gfx::Size layer_bounds(400, 400);
1739 gfx::Size tile_size(100, 100);
1740 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
1742 // All tiles shared (no invalidation).
1743 CreateHighLowResAndSetAllTilesVisible();
1745 // Verify active tree not ready.
1746 Tile* some_active_tile =
1747 active_layer_->HighResTiling()->AllTilesForTesting()[0];
1748 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
1750 // When high res are required, even if the active tree is not ready,
1751 // the high res tiles must be ready.
1752 host_impl_.active_tree()->SetRequiresHighResToDraw();
1753 pending_layer_->MarkVisibleResourcesAsRequired();
1754 AssertAllTilesRequired(pending_layer_->HighResTiling());
1755 AssertNoTilesRequired(pending_layer_->LowResTiling());
1758 TEST_F(PictureLayerImplTest, NothingRequiredIfAllHighResTilesShared) {
1759 gfx::Size layer_bounds(400, 400);
1760 gfx::Size tile_size(100, 100);
1761 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
1763 CreateHighLowResAndSetAllTilesVisible();
1765 Tile* some_active_tile =
1766 active_layer_->HighResTiling()->AllTilesForTesting()[0];
1767 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
1769 // All tiles shared (no invalidation), so even though the active tree's
1770 // tiles aren't ready, there is nothing required.
1771 pending_layer_->MarkVisibleResourcesAsRequired();
1772 AssertNoTilesRequired(pending_layer_->HighResTiling());
1773 AssertNoTilesRequired(pending_layer_->LowResTiling());
1776 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) {
1777 gfx::Size layer_bounds(400, 400);
1778 gfx::Size tile_size(100, 100);
1779 scoped_refptr<FakePicturePileImpl> pending_pile =
1780 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1781 // This pile will create tilings, but has no recordings so will not create any
1782 // tiles. This is attempting to simulate scrolling past the end of recorded
1783 // content on the active layer, where the recordings are so far away that
1784 // no tiles are created.
1785 scoped_refptr<FakePicturePileImpl> active_pile =
1786 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1787 tile_size, layer_bounds);
1788 SetupTrees(pending_pile, active_pile);
1789 pending_layer_->set_fixed_tile_size(tile_size);
1790 active_layer_->set_fixed_tile_size(tile_size);
1792 CreateHighLowResAndSetAllTilesVisible();
1794 // Active layer has tilings, but no tiles due to missing recordings.
1795 EXPECT_TRUE(active_layer_->CanHaveTilings());
1796 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u);
1797 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u);
1799 // Since the active layer has no tiles at all, the pending layer doesn't
1800 // need content in order to activate.
1801 pending_layer_->MarkVisibleResourcesAsRequired();
1802 AssertNoTilesRequired(pending_layer_->HighResTiling());
1803 AssertNoTilesRequired(pending_layer_->LowResTiling());
1806 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) {
1807 gfx::Size layer_bounds(400, 400);
1808 gfx::Size tile_size(100, 100);
1809 scoped_refptr<FakePicturePileImpl> pending_pile =
1810 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1811 scoped_refptr<FakePicturePileImpl> active_pile =
1812 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
1813 SetupTrees(pending_pile, active_pile);
1814 pending_layer_->set_fixed_tile_size(tile_size);
1815 active_layer_->set_fixed_tile_size(tile_size);
1817 CreateHighLowResAndSetAllTilesVisible();
1819 // Active layer can't have tiles.
1820 EXPECT_FALSE(active_layer_->CanHaveTilings());
1822 // All high res tiles required. This should be considered identical
1823 // to the case where there is no active layer, to avoid flashing content.
1824 // This can happen if a layer exists for a while and switches from
1825 // not being able to have content to having content.
1826 pending_layer_->MarkVisibleResourcesAsRequired();
1827 AssertAllTilesRequired(pending_layer_->HighResTiling());
1828 AssertNoTilesRequired(pending_layer_->LowResTiling());
1831 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveHasDifferentBounds) {
1832 gfx::Size layer_bounds(200, 200);
1833 gfx::Size tile_size(100, 100);
1834 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
1836 gfx::Size pending_layer_bounds(400, 400);
1837 pending_layer_->SetBounds(pending_layer_bounds);
1839 CreateHighLowResAndSetAllTilesVisible();
1841 active_layer_->SetAllTilesReady();
1843 // Since the active layer has different bounds, the pending layer needs all
1844 // high res tiles in order to activate.
1845 pending_layer_->MarkVisibleResourcesAsRequired();
1846 AssertAllTilesRequired(pending_layer_->HighResTiling());
1847 AssertNoTilesRequired(pending_layer_->LowResTiling());
1850 TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) {
1851 gfx::Size tile_size(100, 100);
1852 gfx::Size layer_bounds(400, 400);
1853 scoped_refptr<FakePicturePileImpl> pending_pile =
1854 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1856 host_impl_.CreatePendingTree();
1857 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
1859 scoped_ptr<FakePictureLayerImpl> pending_layer =
1860 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pending_pile);
1861 pending_layer->SetDrawsContent(true);
1862 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>());
1864 pending_layer_ = static_cast<FakePictureLayerImpl*>(
1865 host_impl_.pending_tree()->LayerById(id_));
1867 // Set some state on the pending layer, make sure it is not clobbered
1868 // by a sync from the active layer. This could happen because if the
1869 // pending layer has not been post-commit initialized it will attempt
1870 // to sync from the active layer.
1871 float raster_page_scale = 10.f * pending_layer_->raster_page_scale();
1872 pending_layer_->set_raster_page_scale(raster_page_scale);
1873 EXPECT_TRUE(pending_layer_->needs_post_commit_initialization());
1875 host_impl_.ActivateSyncTree();
1877 active_layer_ = static_cast<FakePictureLayerImpl*>(
1878 host_impl_.active_tree()->LayerById(id_));
1880 EXPECT_EQ(0u, active_layer_->num_tilings());
1881 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale());
1882 EXPECT_FALSE(active_layer_->needs_post_commit_initialization());
1885 TEST_F(PictureLayerImplTest, ShareTilesOnSync) {
1886 SetupDefaultTrees(gfx::Size(1500, 1500));
1887 AddDefaultTilingsWithInvalidation(gfx::Rect());
1889 host_impl_.ActivateSyncTree();
1890 host_impl_.CreatePendingTree();
1891 active_layer_ = static_cast<FakePictureLayerImpl*>(
1892 host_impl_.active_tree()->LayerById(id_));
1894 // Force the active tree to sync to the pending tree "post-commit".
1895 pending_layer_->DoPostCommitInitializationIfNeeded();
1897 // Both invalidations should drop tiles from the pending tree.
1898 EXPECT_EQ(3u, active_layer_->num_tilings());
1899 EXPECT_EQ(3u, pending_layer_->num_tilings());
1900 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
1901 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i);
1902 PictureLayerTiling* pending_tiling =
1903 pending_layer_->tilings()->tiling_at(i);
1905 ASSERT_TRUE(active_tiling);
1906 ASSERT_TRUE(pending_tiling);
1908 EXPECT_TRUE(active_tiling->TileAt(0, 0));
1909 EXPECT_TRUE(active_tiling->TileAt(1, 0));
1910 EXPECT_TRUE(active_tiling->TileAt(0, 1));
1911 EXPECT_TRUE(active_tiling->TileAt(1, 1));
1913 EXPECT_TRUE(pending_tiling->TileAt(0, 0));
1914 EXPECT_TRUE(pending_tiling->TileAt(1, 0));
1915 EXPECT_TRUE(pending_tiling->TileAt(0, 1));
1916 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
1918 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
1919 EXPECT_TRUE(active_tiling->TileAt(0, 0)->is_shared());
1920 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0));
1921 EXPECT_TRUE(active_tiling->TileAt(1, 0)->is_shared());
1922 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
1923 EXPECT_TRUE(active_tiling->TileAt(0, 1)->is_shared());
1924 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
1925 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
1929 TEST_F(PictureLayerImplTest, ShareInvalidActiveTreeTilesOnSync) {
1930 SetupDefaultTrees(gfx::Size(1500, 1500));
1931 AddDefaultTilingsWithInvalidation(gfx::Rect(0, 0, 1, 1));
1933 // This activates the 0,0,1,1 invalidation.
1934 host_impl_.ActivateSyncTree();
1935 host_impl_.CreatePendingTree();
1936 active_layer_ = static_cast<FakePictureLayerImpl*>(
1937 host_impl_.active_tree()->LayerById(id_));
1939 // Force the active tree to sync to the pending tree "post-commit".
1940 pending_layer_->DoPostCommitInitializationIfNeeded();
1942 // The active tree invalidation was handled by the active tiles, so they
1943 // can be shared with the pending tree.
1944 EXPECT_EQ(3u, active_layer_->num_tilings());
1945 EXPECT_EQ(3u, pending_layer_->num_tilings());
1946 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
1947 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i);
1948 PictureLayerTiling* pending_tiling =
1949 pending_layer_->tilings()->tiling_at(i);
1951 ASSERT_TRUE(active_tiling);
1952 ASSERT_TRUE(pending_tiling);
1954 EXPECT_TRUE(active_tiling->TileAt(0, 0));
1955 EXPECT_TRUE(active_tiling->TileAt(1, 0));
1956 EXPECT_TRUE(active_tiling->TileAt(0, 1));
1957 EXPECT_TRUE(active_tiling->TileAt(1, 1));
1959 EXPECT_TRUE(pending_tiling->TileAt(0, 0));
1960 EXPECT_TRUE(pending_tiling->TileAt(1, 0));
1961 EXPECT_TRUE(pending_tiling->TileAt(0, 1));
1962 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
1964 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
1965 EXPECT_TRUE(active_tiling->TileAt(0, 0)->is_shared());
1966 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0));
1967 EXPECT_TRUE(active_tiling->TileAt(1, 0)->is_shared());
1968 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
1969 EXPECT_TRUE(active_tiling->TileAt(0, 1)->is_shared());
1970 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
1971 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
1975 TEST_F(PictureLayerImplTest, RemoveInvalidPendingTreeTilesOnSync) {
1976 SetupDefaultTrees(gfx::Size(1500, 1500));
1977 AddDefaultTilingsWithInvalidation(gfx::Rect());
1979 host_impl_.ActivateSyncTree();
1980 host_impl_.CreatePendingTree();
1981 active_layer_ = static_cast<FakePictureLayerImpl*>(
1982 host_impl_.active_tree()->LayerById(id_));
1984 // Set some invalidation on the pending tree "during commit". We should
1985 // replace raster tiles that touch this.
1986 pending_layer_->set_invalidation(gfx::Rect(1, 1));
1988 // Force the active tree to sync to the pending tree "post-commit".
1989 pending_layer_->DoPostCommitInitializationIfNeeded();
1991 // The pending tree invalidation means tiles can not be shared with the
1992 // active tree.
1993 EXPECT_EQ(3u, active_layer_->num_tilings());
1994 EXPECT_EQ(3u, pending_layer_->num_tilings());
1995 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
1996 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i);
1997 PictureLayerTiling* pending_tiling =
1998 pending_layer_->tilings()->tiling_at(i);
2000 ASSERT_TRUE(active_tiling);
2001 ASSERT_TRUE(pending_tiling);
2003 EXPECT_TRUE(active_tiling->TileAt(0, 0));
2004 EXPECT_TRUE(active_tiling->TileAt(1, 0));
2005 EXPECT_TRUE(active_tiling->TileAt(0, 1));
2006 EXPECT_TRUE(active_tiling->TileAt(1, 1));
2008 EXPECT_TRUE(pending_tiling->TileAt(0, 0));
2009 EXPECT_TRUE(pending_tiling->TileAt(1, 0));
2010 EXPECT_TRUE(pending_tiling->TileAt(0, 1));
2011 EXPECT_TRUE(pending_tiling->TileAt(1, 1));
2013 EXPECT_NE(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2014 EXPECT_FALSE(active_tiling->TileAt(0, 0)->is_shared());
2015 EXPECT_FALSE(pending_tiling->TileAt(0, 0)->is_shared());
2016 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0));
2017 EXPECT_TRUE(active_tiling->TileAt(1, 0)->is_shared());
2018 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
2019 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
2020 EXPECT_EQ(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2021 EXPECT_TRUE(active_tiling->TileAt(1, 1)->is_shared());
2025 TEST_F(PictureLayerImplTest, SyncTilingAfterReleaseResource) {
2026 SetupDefaultTrees(gfx::Size(10, 10));
2027 host_impl_.active_tree()->UpdateDrawProperties();
2028 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties());
2030 // Contrived unit test of a real crash. A layer is transparent during a
2031 // context loss, and later becomes opaque, causing active layer SyncTiling to
2032 // be called.
2033 float new_scale = 1.f;
2034 active_layer_->ReleaseResources();
2035 pending_layer_->ReleaseResources();
2036 EXPECT_FALSE(active_layer_->tilings()->TilingAtScale(new_scale));
2037 pending_layer_->AddTiling(new_scale);
2038 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(new_scale));
2040 // UpdateDrawProperties early-outs if the tree doesn't need it. It is also
2041 // responsible for calling ManageTilings. These checks verify that
2042 // ReleaseResources has set needs update draw properties so that the
2043 // new tiling gets the appropriate resolution set in ManageTilings.
2044 EXPECT_TRUE(host_impl_.active_tree()->needs_update_draw_properties());
2045 host_impl_.active_tree()->UpdateDrawProperties();
2046 PictureLayerTiling* high_res =
2047 active_layer_->tilings()->TilingAtScale(new_scale);
2048 ASSERT_TRUE(!!high_res);
2049 EXPECT_EQ(HIGH_RESOLUTION, high_res->resolution());
2052 TEST_F(PictureLayerImplTest, SyncTilingAfterGpuRasterizationToggles) {
2053 SetupDefaultTrees(gfx::Size(10, 10));
2055 const float kScale = 1.f;
2056 pending_layer_->AddTiling(kScale);
2057 EXPECT_TRUE(pending_layer_->tilings()->TilingAtScale(kScale));
2058 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(kScale));
2060 // Gpu rasterization is disabled by default.
2061 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
2062 // Toggling the gpu rasterization clears all tilings on both trees.
2063 host_impl_.SetUseGpuRasterization(true);
2064 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2065 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2067 // Make sure that we can still add tiling to the pending layer,
2068 // that gets synced to the active layer.
2069 pending_layer_->AddTiling(kScale);
2070 EXPECT_TRUE(pending_layer_->tilings()->TilingAtScale(kScale));
2071 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(kScale));
2073 // Toggling the gpu rasterization clears all tilings on both trees.
2074 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2075 host_impl_.SetUseGpuRasterization(false);
2076 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2077 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2080 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) {
2081 SetupDefaultTrees(gfx::Size(10, 10));
2082 host_impl_.active_tree()->UpdateDrawProperties();
2083 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties());
2085 SetupDrawPropertiesAndUpdateTiles(
2086 active_layer_, 0.5f, 0.5f, 0.5f, 0.5f, false);
2087 active_layer_->tilings()->RemoveAllTilings();
2088 PictureLayerTiling* tiling = active_layer_->tilings()->AddTiling(0.5f);
2089 active_layer_->tilings()->AddTiling(1.5f);
2090 active_layer_->tilings()->AddTiling(0.25f);
2091 tiling->set_resolution(HIGH_RESOLUTION);
2093 // Sanity checks.
2094 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
2095 ASSERT_EQ(tiling, active_layer_->tilings()->TilingAtScale(0.5f));
2097 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes
2098 // 1.0f). Note that we should also ensure that the pending layer needs post
2099 // commit initialization, since this is what would happen during commit. In
2100 // other words we want the pending layer to sync from the active layer.
2101 pending_layer_->SetBounds(gfx::Size(1, 1));
2102 pending_layer_->SetNeedsPostCommitInitialization();
2103 pending_layer_->set_twin_layer(NULL);
2104 active_layer_->set_twin_layer(NULL);
2105 EXPECT_TRUE(pending_layer_->needs_post_commit_initialization());
2107 // Update the draw properties: sync from active tree should happen here.
2108 host_impl_.pending_tree()->UpdateDrawProperties();
2110 // Another sanity check.
2111 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale());
2113 // Now we should've synced 1.5f tiling, since that's the only one that doesn't
2114 // violate minimum contents scale. At the same time, we should've created a
2115 // new high res tiling at scale 1.0f.
2116 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
2117 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.0f));
2118 EXPECT_EQ(HIGH_RESOLUTION,
2119 pending_layer_->tilings()->TilingAtScale(1.0f)->resolution());
2120 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.5f));
2121 EXPECT_EQ(NON_IDEAL_RESOLUTION,
2122 pending_layer_->tilings()->TilingAtScale(1.5f)->resolution());
2125 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) {
2126 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
2127 gfx::Size layer_bounds(default_tile_size.width() * 4,
2128 default_tile_size.height() * 4);
2130 SetupDefaultTrees(layer_bounds);
2131 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
2132 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2133 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
2134 // Should have a low-res and a high-res tiling.
2135 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
2137 ResetTilingsAndRasterScales();
2139 host_impl_.SetUseGpuRasterization(true);
2140 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
2141 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
2143 // Should only have the high-res tiling.
2144 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
2147 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) {
2148 // Set up layers with tilings.
2149 SetupDefaultTrees(gfx::Size(10, 10));
2150 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false);
2151 pending_layer_->PushPropertiesTo(active_layer_);
2152 EXPECT_TRUE(pending_layer_->DrawsContent());
2153 EXPECT_TRUE(pending_layer_->CanHaveTilings());
2154 EXPECT_GE(pending_layer_->num_tilings(), 0u);
2155 EXPECT_GE(active_layer_->num_tilings(), 0u);
2157 // Set content to false, which should make CanHaveTilings return false.
2158 pending_layer_->SetDrawsContent(false);
2159 EXPECT_FALSE(pending_layer_->DrawsContent());
2160 EXPECT_FALSE(pending_layer_->CanHaveTilings());
2162 // No tilings should be pushed to active layer.
2163 pending_layer_->PushPropertiesTo(active_layer_);
2164 EXPECT_EQ(0u, active_layer_->num_tilings());
2167 TEST_F(PictureLayerImplTest, FirstTilingDuringPinch) {
2168 SetupDefaultTrees(gfx::Size(10, 10));
2169 host_impl_.PinchGestureBegin();
2170 float high_res_scale = 2.3f;
2171 SetContentsScaleOnBothLayers(high_res_scale, 1.f, 1.f, 1.f, false);
2173 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2174 EXPECT_FLOAT_EQ(high_res_scale,
2175 pending_layer_->HighResTiling()->contents_scale());
2178 TEST_F(PictureLayerImplTest, FirstTilingTooSmall) {
2179 SetupDefaultTrees(gfx::Size(10, 10));
2180 host_impl_.PinchGestureBegin();
2181 float high_res_scale = 0.0001f;
2182 EXPECT_GT(pending_layer_->MinimumContentsScale(), high_res_scale);
2184 SetContentsScaleOnBothLayers(high_res_scale, 1.f, 1.f, 1.f, false);
2186 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2187 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
2188 pending_layer_->HighResTiling()->contents_scale());
2191 TEST_F(PictureLayerImplTest, PinchingTooSmall) {
2192 SetupDefaultTrees(gfx::Size(10, 10));
2194 float contents_scale = 0.15f;
2195 SetContentsScaleOnBothLayers(contents_scale, 1.f, 1.f, 1.f, false);
2197 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2198 EXPECT_FLOAT_EQ(contents_scale,
2199 pending_layer_->HighResTiling()->contents_scale());
2201 host_impl_.PinchGestureBegin();
2203 float page_scale = 0.0001f;
2204 EXPECT_LT(page_scale * contents_scale,
2205 pending_layer_->MinimumContentsScale());
2207 SetContentsScaleOnBothLayers(contents_scale, 1.f, page_scale, 1.f, false);
2208 ASSERT_GE(pending_layer_->num_tilings(), 0u);
2209 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
2210 pending_layer_->HighResTiling()->contents_scale());
2213 class DeferredInitPictureLayerImplTest : public PictureLayerImplTest {
2214 public:
2215 virtual void InitializeRenderer() OVERRIDE {
2216 bool delegated_rendering = false;
2217 host_impl_.InitializeRenderer(
2218 FakeOutputSurface::CreateDeferredGL(
2219 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice),
2220 delegated_rendering).PassAs<OutputSurface>());
2223 virtual void SetUp() OVERRIDE {
2224 PictureLayerImplTest::SetUp();
2226 // Create some default active and pending trees.
2227 gfx::Size tile_size(100, 100);
2228 gfx::Size layer_bounds(400, 400);
2230 scoped_refptr<FakePicturePileImpl> pending_pile =
2231 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2232 scoped_refptr<FakePicturePileImpl> active_pile =
2233 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2235 SetupTrees(pending_pile, active_pile);
2239 // This test is really a LayerTreeHostImpl test, in that it makes sure
2240 // that trees need update draw properties after deferred initialization.
2241 // However, this is also a regression test for PictureLayerImpl in that
2242 // not having this update will cause a crash.
2243 TEST_F(DeferredInitPictureLayerImplTest, PreventUpdateTilesDuringLostContext) {
2244 host_impl_.pending_tree()->UpdateDrawProperties();
2245 host_impl_.active_tree()->UpdateDrawProperties();
2246 EXPECT_FALSE(host_impl_.pending_tree()->needs_update_draw_properties());
2247 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties());
2249 FakeOutputSurface* fake_output_surface =
2250 static_cast<FakeOutputSurface*>(host_impl_.output_surface());
2251 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d(
2252 TestContextProvider::Create()));
2254 // These will crash PictureLayerImpl if this is not true.
2255 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties());
2256 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties());
2257 host_impl_.active_tree()->UpdateDrawProperties();
2260 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForCpuRasterization) {
2261 gfx::Size layer_bounds(100, 100);
2262 gfx::Size viewport_size(1000, 1000);
2263 SetupDefaultTrees(layer_bounds);
2264 host_impl_.SetViewportSize(viewport_size);
2266 float contents_scale = 1.f;
2267 float device_scale = 1.3f;
2268 float page_scale = 1.4f;
2269 float maximum_animation_scale = 1.f;
2270 bool animating_transform = false;
2272 SetContentsScaleOnBothLayers(contents_scale,
2273 device_scale,
2274 page_scale,
2275 maximum_animation_scale,
2276 animating_transform);
2277 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2279 // Since we're CPU-rasterizing, starting an animation should cause tiling
2280 // resolution to get set to the maximum animation scale factor.
2281 animating_transform = true;
2282 maximum_animation_scale = 3.f;
2283 contents_scale = 2.f;
2285 SetContentsScaleOnBothLayers(contents_scale,
2286 device_scale,
2287 page_scale,
2288 maximum_animation_scale,
2289 animating_transform);
2290 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2292 // Further changes to scale during the animation should not cause a new
2293 // high-res tiling to get created.
2294 contents_scale = 4.f;
2295 maximum_animation_scale = 5.f;
2297 SetContentsScaleOnBothLayers(contents_scale,
2298 device_scale,
2299 page_scale,
2300 maximum_animation_scale,
2301 animating_transform);
2302 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2304 // Once we stop animating, a new high-res tiling should be created.
2305 animating_transform = false;
2307 SetContentsScaleOnBothLayers(contents_scale,
2308 device_scale,
2309 page_scale,
2310 maximum_animation_scale,
2311 animating_transform);
2312 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2314 // When animating with an unknown maximum animation scale factor, a new
2315 // high-res tiling should be created at the animation's initial scale.
2316 animating_transform = true;
2317 contents_scale = 2.f;
2318 maximum_animation_scale = 0.f;
2320 SetContentsScaleOnBothLayers(contents_scale,
2321 device_scale,
2322 page_scale,
2323 maximum_animation_scale,
2324 animating_transform);
2325 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
2327 // Further changes to scale during the animation should not cause a new
2328 // high-res tiling to get created.
2329 contents_scale = 3.f;
2331 SetContentsScaleOnBothLayers(contents_scale,
2332 device_scale,
2333 page_scale,
2334 maximum_animation_scale,
2335 animating_transform);
2336 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
2338 // Once we stop animating, a new high-res tiling should be created.
2339 animating_transform = false;
2340 contents_scale = 4.f;
2342 SetContentsScaleOnBothLayers(contents_scale,
2343 device_scale,
2344 page_scale,
2345 maximum_animation_scale,
2346 animating_transform);
2347 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2349 // When animating with a maxmium animation scale factor that is so large
2350 // that the layer grows larger than the viewport at this scale, a new
2351 // high-res tiling should get created at the animation's initial scale, not
2352 // at its maximum scale.
2353 animating_transform = true;
2354 contents_scale = 2.f;
2355 maximum_animation_scale = 11.f;
2357 SetContentsScaleOnBothLayers(contents_scale,
2358 device_scale,
2359 page_scale,
2360 maximum_animation_scale,
2361 animating_transform);
2362 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
2364 // Once we stop animating, a new high-res tiling should be created.
2365 animating_transform = false;
2366 contents_scale = 11.f;
2368 SetContentsScaleOnBothLayers(contents_scale,
2369 device_scale,
2370 page_scale,
2371 maximum_animation_scale,
2372 animating_transform);
2373 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f);
2375 // When animating with a maxmium animation scale factor that is so large
2376 // that the layer grows larger than the viewport at this scale, and where
2377 // the intial source scale is < 1, a new high-res tiling should get created
2378 // at source scale 1.
2379 animating_transform = true;
2380 contents_scale = 0.1f;
2381 maximum_animation_scale = 11.f;
2383 SetContentsScaleOnBothLayers(contents_scale,
2384 device_scale,
2385 page_scale,
2386 maximum_animation_scale,
2387 animating_transform);
2388 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), device_scale * page_scale);
2390 // Once we stop animating, a new high-res tiling should be created.
2391 animating_transform = false;
2392 contents_scale = 11.f;
2394 SetContentsScaleOnBothLayers(contents_scale,
2395 device_scale,
2396 page_scale,
2397 maximum_animation_scale,
2398 animating_transform);
2399 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 11.f);
2402 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForGpuRasterization) {
2403 gfx::Size layer_bounds(100, 100);
2404 gfx::Size viewport_size(1000, 1000);
2405 SetupDefaultTrees(layer_bounds);
2406 host_impl_.SetViewportSize(viewport_size);
2407 host_impl_.SetUseGpuRasterization(true);
2409 float contents_scale = 1.f;
2410 float device_scale = 1.3f;
2411 float page_scale = 1.4f;
2412 float maximum_animation_scale = 1.f;
2413 bool animating_transform = false;
2415 SetContentsScaleOnBothLayers(contents_scale,
2416 device_scale,
2417 page_scale,
2418 maximum_animation_scale,
2419 animating_transform);
2420 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2422 // Since we're GPU-rasterizing, starting an animation should cause tiling
2423 // resolution to get set to the current contents scale.
2424 animating_transform = true;
2425 contents_scale = 2.f;
2426 maximum_animation_scale = 4.f;
2428 SetContentsScaleOnBothLayers(contents_scale,
2429 device_scale,
2430 page_scale,
2431 maximum_animation_scale,
2432 animating_transform);
2433 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
2435 // Further changes to scale during the animation should cause a new high-res
2436 // tiling to get created.
2437 contents_scale = 3.f;
2439 SetContentsScaleOnBothLayers(contents_scale,
2440 device_scale,
2441 page_scale,
2442 maximum_animation_scale,
2443 animating_transform);
2444 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2446 // Since we're re-rasterizing during the animation, scales smaller than 1
2447 // should be respected.
2448 contents_scale = 0.25f;
2450 SetContentsScaleOnBothLayers(contents_scale,
2451 device_scale,
2452 page_scale,
2453 maximum_animation_scale,
2454 animating_transform);
2455 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.25f);
2457 // Once we stop animating, a new high-res tiling should be created.
2458 contents_scale = 4.f;
2459 animating_transform = false;
2461 SetContentsScaleOnBothLayers(contents_scale,
2462 device_scale,
2463 page_scale,
2464 maximum_animation_scale,
2465 animating_transform);
2466 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2468 static_cast<FakePicturePileImpl*>(pending_layer_->pile())->set_has_text(true);
2469 static_cast<FakePicturePileImpl*>(active_layer_->pile())->set_has_text(true);
2471 // Since we're GPU-rasterizing but have text, starting an animation should
2472 // cause tiling resolution to get set to the maximum animation scale.
2473 animating_transform = true;
2474 contents_scale = 2.f;
2475 maximum_animation_scale = 3.f;
2477 SetContentsScaleOnBothLayers(contents_scale,
2478 device_scale,
2479 page_scale,
2480 maximum_animation_scale,
2481 animating_transform);
2482 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2484 // Further changes to scale during the animation should not cause a new
2485 // high-res tiling to get created.
2486 contents_scale = 4.f;
2487 maximum_animation_scale = 5.f;
2489 SetContentsScaleOnBothLayers(contents_scale,
2490 device_scale,
2491 page_scale,
2492 maximum_animation_scale,
2493 animating_transform);
2494 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
2496 // Once we stop animating, a new high-res tiling should be created.
2497 animating_transform = false;
2499 SetContentsScaleOnBothLayers(contents_scale,
2500 device_scale,
2501 page_scale,
2502 maximum_animation_scale,
2503 animating_transform);
2504 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2507 TEST_F(PictureLayerImplTest, LayerRasterTileIterator) {
2508 base::TimeTicks time_ticks;
2509 time_ticks += base::TimeDelta::FromMilliseconds(1);
2510 host_impl_.SetCurrentBeginFrameArgs(
2511 CreateBeginFrameArgsForTesting(time_ticks));
2513 gfx::Size tile_size(100, 100);
2514 gfx::Size layer_bounds(1000, 1000);
2516 scoped_refptr<FakePicturePileImpl> pending_pile =
2517 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2519 SetupPendingTree(pending_pile);
2521 ASSERT_TRUE(pending_layer_->CanHaveTilings());
2523 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2525 // Empty iterator
2526 PictureLayerImpl::LayerRasterTileIterator it;
2527 EXPECT_FALSE(it);
2529 // No tilings.
2530 it = PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
2531 EXPECT_FALSE(it);
2533 pending_layer_->AddTiling(low_res_factor);
2534 pending_layer_->AddTiling(0.3f);
2535 pending_layer_->AddTiling(0.7f);
2536 PictureLayerTiling* high_res_tiling = pending_layer_->AddTiling(1.0f);
2537 pending_layer_->AddTiling(2.0f);
2539 host_impl_.SetViewportSize(gfx::Size(500, 500));
2540 host_impl_.pending_tree()->UpdateDrawProperties();
2542 std::set<Tile*> unique_tiles;
2543 bool reached_prepaint = false;
2544 size_t non_ideal_tile_count = 0u;
2545 size_t low_res_tile_count = 0u;
2546 size_t high_res_tile_count = 0u;
2547 for (it = PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
2549 ++it) {
2550 Tile* tile = *it;
2551 TilePriority priority = tile->priority(PENDING_TREE);
2553 EXPECT_TRUE(tile);
2555 // Non-high res tiles only get visible tiles. Also, prepaint should only
2556 // come at the end of the iteration.
2557 if (priority.resolution != HIGH_RESOLUTION)
2558 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
2559 else if (reached_prepaint)
2560 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
2561 else
2562 reached_prepaint = priority.priority_bin != TilePriority::NOW;
2564 non_ideal_tile_count += priority.resolution == NON_IDEAL_RESOLUTION;
2565 low_res_tile_count += priority.resolution == LOW_RESOLUTION;
2566 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
2568 unique_tiles.insert(tile);
2571 EXPECT_TRUE(reached_prepaint);
2572 EXPECT_EQ(0u, non_ideal_tile_count);
2573 EXPECT_EQ(1u, low_res_tile_count);
2574 EXPECT_EQ(16u, high_res_tile_count);
2575 EXPECT_EQ(low_res_tile_count + high_res_tile_count + non_ideal_tile_count,
2576 unique_tiles.size());
2578 // No NOW tiles.
2579 time_ticks += base::TimeDelta::FromMilliseconds(200);
2580 host_impl_.SetCurrentBeginFrameArgs(
2581 CreateBeginFrameArgsForTesting(time_ticks));
2583 pending_layer_->draw_properties().visible_content_rect =
2584 gfx::Rect(1100, 1100, 500, 500);
2585 pending_layer_->UpdateTiles(Occlusion());
2587 unique_tiles.clear();
2588 high_res_tile_count = 0u;
2589 for (it = PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
2591 ++it) {
2592 Tile* tile = *it;
2593 TilePriority priority = tile->priority(PENDING_TREE);
2595 EXPECT_TRUE(tile);
2597 // Non-high res tiles only get visible tiles.
2598 EXPECT_EQ(HIGH_RESOLUTION, priority.resolution);
2599 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
2601 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
2603 unique_tiles.insert(tile);
2606 EXPECT_EQ(16u, high_res_tile_count);
2607 EXPECT_EQ(high_res_tile_count, unique_tiles.size());
2609 time_ticks += base::TimeDelta::FromMilliseconds(200);
2610 host_impl_.SetCurrentBeginFrameArgs(
2611 CreateBeginFrameArgsForTesting(time_ticks));
2613 pending_layer_->draw_properties().visible_content_rect =
2614 gfx::Rect(0, 0, 500, 500);
2615 pending_layer_->UpdateTiles(Occlusion());
2617 std::vector<Tile*> high_res_tiles = high_res_tiling->AllTilesForTesting();
2618 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin();
2619 tile_it != high_res_tiles.end();
2620 ++tile_it) {
2621 Tile* tile = *tile_it;
2622 ManagedTileState::TileVersion& tile_version =
2623 tile->GetTileVersionForTesting(
2624 tile->DetermineRasterModeForTree(ACTIVE_TREE));
2625 tile_version.SetSolidColorForTesting(SK_ColorRED);
2628 non_ideal_tile_count = 0;
2629 low_res_tile_count = 0;
2630 high_res_tile_count = 0;
2631 for (it = PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
2633 ++it) {
2634 Tile* tile = *it;
2635 TilePriority priority = tile->priority(PENDING_TREE);
2637 EXPECT_TRUE(tile);
2639 non_ideal_tile_count += priority.resolution == NON_IDEAL_RESOLUTION;
2640 low_res_tile_count += priority.resolution == LOW_RESOLUTION;
2641 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
2644 EXPECT_EQ(0u, non_ideal_tile_count);
2645 EXPECT_EQ(1u, low_res_tile_count);
2646 EXPECT_EQ(0u, high_res_tile_count);
2649 TEST_F(PictureLayerImplTest, LayerEvictionTileIterator) {
2650 gfx::Size tile_size(100, 100);
2651 gfx::Size layer_bounds(1000, 1000);
2653 scoped_refptr<FakePicturePileImpl> pending_pile =
2654 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2656 SetupPendingTree(pending_pile);
2658 ASSERT_TRUE(pending_layer_->CanHaveTilings());
2660 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2662 std::vector<PictureLayerTiling*> tilings;
2663 tilings.push_back(pending_layer_->AddTiling(low_res_factor));
2664 tilings.push_back(pending_layer_->AddTiling(0.3f));
2665 tilings.push_back(pending_layer_->AddTiling(0.7f));
2666 tilings.push_back(pending_layer_->AddTiling(1.0f));
2667 tilings.push_back(pending_layer_->AddTiling(2.0f));
2669 host_impl_.SetViewportSize(gfx::Size(500, 500));
2670 host_impl_.pending_tree()->UpdateDrawProperties();
2672 std::vector<Tile*> all_tiles;
2673 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator =
2674 tilings.begin();
2675 tiling_iterator != tilings.end();
2676 ++tiling_iterator) {
2677 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting();
2678 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles));
2681 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end());
2683 bool mark_required = false;
2684 size_t number_of_marked_tiles = 0u;
2685 size_t number_of_unmarked_tiles = 0u;
2686 for (size_t i = 0; i < tilings.size(); ++i) {
2687 PictureLayerTiling* tiling = tilings.at(i);
2688 for (PictureLayerTiling::CoverageIterator iter(
2689 tiling,
2690 pending_layer_->contents_scale_x(),
2691 pending_layer_->visible_content_rect());
2692 iter;
2693 ++iter) {
2694 if (mark_required) {
2695 number_of_marked_tiles++;
2696 iter->MarkRequiredForActivation();
2697 } else {
2698 number_of_unmarked_tiles++;
2700 mark_required = !mark_required;
2704 // Sanity checks.
2705 EXPECT_EQ(91u, all_tiles.size());
2706 EXPECT_EQ(91u, all_tiles_set.size());
2707 EXPECT_GT(number_of_marked_tiles, 1u);
2708 EXPECT_GT(number_of_unmarked_tiles, 1u);
2710 // Empty iterator.
2711 PictureLayerImpl::LayerEvictionTileIterator it;
2712 EXPECT_FALSE(it);
2714 // Tiles don't have resources yet.
2715 it = PictureLayerImpl::LayerEvictionTileIterator(
2716 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES);
2717 EXPECT_FALSE(it);
2719 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
2721 std::set<Tile*> unique_tiles;
2722 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f};
2723 size_t scale_index = 0;
2724 bool reached_visible = false;
2725 Tile* last_tile = NULL;
2726 for (it = PictureLayerImpl::LayerEvictionTileIterator(
2727 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES);
2729 ++it) {
2730 Tile* tile = *it;
2731 if (!last_tile)
2732 last_tile = tile;
2734 EXPECT_TRUE(tile);
2736 TilePriority priority = tile->priority(PENDING_TREE);
2738 if (priority.priority_bin == TilePriority::NOW) {
2739 reached_visible = true;
2740 last_tile = tile;
2741 break;
2744 EXPECT_FALSE(tile->required_for_activation());
2746 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) >
2747 std::numeric_limits<float>::epsilon()) {
2748 ++scale_index;
2749 ASSERT_LT(scale_index, arraysize(expected_scales));
2752 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]);
2753 unique_tiles.insert(tile);
2755 // If the tile is the same rough bin as last tile (same activation, bin, and
2756 // scale), then distance should be decreasing.
2757 if (tile->required_for_activation() ==
2758 last_tile->required_for_activation() &&
2759 priority.priority_bin ==
2760 last_tile->priority(PENDING_TREE).priority_bin &&
2761 std::abs(tile->contents_scale() - last_tile->contents_scale()) <
2762 std::numeric_limits<float>::epsilon()) {
2763 EXPECT_LE(priority.distance_to_visible,
2764 last_tile->priority(PENDING_TREE).distance_to_visible);
2767 last_tile = tile;
2770 EXPECT_TRUE(reached_visible);
2771 EXPECT_EQ(65u, unique_tiles.size());
2773 scale_index = 0;
2774 bool reached_required = false;
2775 for (; it; ++it) {
2776 Tile* tile = *it;
2777 EXPECT_TRUE(tile);
2779 TilePriority priority = tile->priority(PENDING_TREE);
2780 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
2782 if (reached_required) {
2783 EXPECT_TRUE(tile->required_for_activation());
2784 } else if (tile->required_for_activation()) {
2785 reached_required = true;
2786 scale_index = 0;
2789 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) >
2790 std::numeric_limits<float>::epsilon()) {
2791 ++scale_index;
2792 ASSERT_LT(scale_index, arraysize(expected_scales));
2795 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]);
2796 unique_tiles.insert(tile);
2799 EXPECT_TRUE(reached_required);
2800 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size());
2803 TEST_F(PictureLayerImplTest, Occlusion) {
2804 gfx::Size tile_size(102, 102);
2805 gfx::Size layer_bounds(1000, 1000);
2806 gfx::Size viewport_size(1000, 1000);
2808 LayerTestCommon::LayerImplTest impl;
2810 scoped_refptr<FakePicturePileImpl> pending_pile =
2811 FakePicturePileImpl::CreateFilledPile(layer_bounds, layer_bounds);
2812 SetupPendingTree(pending_pile);
2813 pending_layer_->SetBounds(layer_bounds);
2814 ActivateTree();
2815 active_layer_->set_fixed_tile_size(tile_size);
2817 host_impl_.SetViewportSize(viewport_size);
2818 host_impl_.active_tree()->UpdateDrawProperties();
2820 std::vector<Tile*> tiles =
2821 active_layer_->HighResTiling()->AllTilesForTesting();
2822 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
2825 SCOPED_TRACE("No occlusion");
2826 gfx::Rect occluded;
2827 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
2829 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
2830 gfx::Rect(layer_bounds));
2831 EXPECT_EQ(100u, impl.quad_list().size());
2835 SCOPED_TRACE("Full occlusion");
2836 gfx::Rect occluded(active_layer_->visible_content_rect());
2837 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
2839 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
2840 EXPECT_EQ(impl.quad_list().size(), 0u);
2844 SCOPED_TRACE("Partial occlusion");
2845 gfx::Rect occluded(150, 0, 200, 1000);
2846 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
2848 size_t partially_occluded_count = 0;
2849 LayerTestCommon::VerifyQuadsAreOccluded(
2850 impl.quad_list(), occluded, &partially_occluded_count);
2851 // The layer outputs one quad, which is partially occluded.
2852 EXPECT_EQ(100u - 10u, impl.quad_list().size());
2853 EXPECT_EQ(10u + 10u, partially_occluded_count);
2857 TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) {
2858 gfx::Size tile_size(host_impl_.settings().default_tile_size);
2859 SetupDefaultTrees(tile_size);
2861 float contents_scale = 2.f;
2862 float device_scale = 1.f;
2863 float page_scale = 1.f;
2864 float maximum_animation_scale = 1.f;
2865 bool animating_transform = false;
2867 SetContentsScaleOnBothLayers(contents_scale,
2868 device_scale,
2869 page_scale,
2870 maximum_animation_scale,
2871 animating_transform);
2872 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
2874 // Changing the source scale without being in an animation will cause
2875 // the layer to reset its source scale to 1.f.
2876 contents_scale = 3.f;
2878 SetContentsScaleOnBothLayers(contents_scale,
2879 device_scale,
2880 page_scale,
2881 maximum_animation_scale,
2882 animating_transform);
2883 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2885 // Further changes to the source scale will no longer be reflected in the
2886 // contents scale.
2887 contents_scale = 0.5f;
2889 SetContentsScaleOnBothLayers(contents_scale,
2890 device_scale,
2891 page_scale,
2892 maximum_animation_scale,
2893 animating_transform);
2894 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2897 TEST_F(PictureLayerImplTest, LowResReadyToDrawNotEnoughToActivate) {
2898 gfx::Size tile_size(100, 100);
2899 gfx::Size layer_bounds(1000, 1000);
2901 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
2903 // Make sure some tiles are not shared.
2904 pending_layer_->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size));
2906 CreateHighLowResAndSetAllTilesVisible();
2907 active_layer_->SetAllTilesReady();
2908 pending_layer_->MarkVisibleResourcesAsRequired();
2910 // All pending layer tiles required are not ready.
2911 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
2913 // Initialize all low-res tiles.
2914 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->LowResTiling());
2916 // Low-res tiles should not be enough.
2917 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
2919 // Initialize remaining tiles.
2920 pending_layer_->SetAllTilesReady();
2922 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
2925 TEST_F(PictureLayerImplTest, HighResReadyToDrawEnoughToActivate) {
2926 gfx::Size tile_size(100, 100);
2927 gfx::Size layer_bounds(1000, 1000);
2929 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
2931 // Make sure some tiles are not shared.
2932 pending_layer_->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size));
2934 CreateHighLowResAndSetAllTilesVisible();
2935 active_layer_->SetAllTilesReady();
2936 pending_layer_->MarkVisibleResourcesAsRequired();
2938 // All pending layer tiles required are not ready.
2939 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
2941 // Initialize all high-res tiles.
2942 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
2944 // High-res tiles should be enough, since they cover everything visible.
2945 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
2948 TEST_F(PictureLayerImplTest,
2949 SharedActiveHighResReadyAndPendingLowResReadyNotEnoughToActivate) {
2950 gfx::Size tile_size(100, 100);
2951 gfx::Size layer_bounds(1000, 1000);
2953 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
2955 // Make sure some tiles are not shared.
2956 pending_layer_->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size));
2958 CreateHighLowResAndSetAllTilesVisible();
2960 // Initialize all high-res tiles in the active layer.
2961 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling());
2962 // And all the low-res tiles in the pending layer.
2963 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->LowResTiling());
2965 pending_layer_->MarkVisibleResourcesAsRequired();
2967 // The unshared high-res tiles are not ready, so we cannot activate.
2968 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
2970 // When the unshared pending high-res tiles are ready, we can activate.
2971 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
2972 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
2975 TEST_F(PictureLayerImplTest, SharedActiveHighResReadyNotEnoughToActivate) {
2976 gfx::Size tile_size(100, 100);
2977 gfx::Size layer_bounds(1000, 1000);
2979 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
2981 // Make sure some tiles are not shared.
2982 pending_layer_->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size));
2984 CreateHighLowResAndSetAllTilesVisible();
2986 // Initialize all high-res tiles in the active layer.
2987 active_layer_->SetAllTilesReadyInTiling(active_layer_->HighResTiling());
2989 pending_layer_->MarkVisibleResourcesAsRequired();
2991 // The unshared high-res tiles are not ready, so we cannot activate.
2992 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
2994 // When the unshared pending high-res tiles are ready, we can activate.
2995 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling());
2996 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
2999 class NoLowResPictureLayerImplTest : public PictureLayerImplTest {
3000 public:
3001 NoLowResPictureLayerImplTest()
3002 : PictureLayerImplTest(NoLowResTilingsSettings()) {}
3005 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) {
3006 gfx::Size tile_size(400, 400);
3007 gfx::Size layer_bounds(1300, 1900);
3009 scoped_refptr<FakePicturePileImpl> pending_pile =
3010 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3011 scoped_refptr<FakePicturePileImpl> active_pile =
3012 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3014 SetupTrees(pending_pile, active_pile);
3015 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3017 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3018 EXPECT_LT(low_res_factor, 1.f);
3020 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3021 6.f, // ideal contents scale
3022 3.f, // device scale
3023 2.f, // page scale
3024 1.f, // maximum animation scale
3025 false);
3026 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
3027 EXPECT_FLOAT_EQ(6.f,
3028 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3030 // If we change the page scale factor, then we should get new tilings.
3031 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3032 6.6f, // ideal contents scale
3033 3.f, // device scale
3034 2.2f, // page scale
3035 1.f, // maximum animation scale
3036 false);
3037 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
3038 EXPECT_FLOAT_EQ(6.6f,
3039 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3041 // If we change the device scale factor, then we should get new tilings.
3042 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3043 7.26f, // ideal contents scale
3044 3.3f, // device scale
3045 2.2f, // page scale
3046 1.f, // maximum animation scale
3047 false);
3048 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings());
3049 EXPECT_FLOAT_EQ(7.26f,
3050 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3052 // If we change the device scale factor, but end up at the same total scale
3053 // factor somehow, then we don't get new tilings.
3054 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3055 7.26f, // ideal contents scale
3056 2.2f, // device scale
3057 3.3f, // page scale
3058 1.f, // maximum animation scale
3059 false);
3060 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings());
3061 EXPECT_FLOAT_EQ(7.26f,
3062 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3065 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredNullTiles) {
3066 gfx::Size tile_size(100, 100);
3067 gfx::Size layer_bounds(1000, 1000);
3069 scoped_refptr<FakePicturePileImpl> pending_pile =
3070 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
3071 // Layers with entirely empty piles can't get tilings.
3072 pending_pile->AddRecordingAt(0, 0);
3074 SetupPendingTree(pending_pile);
3076 ASSERT_TRUE(pending_layer_->CanHaveTilings());
3077 pending_layer_->AddTiling(1.0f);
3078 pending_layer_->AddTiling(2.0f);
3080 // It should be safe to call this (and MarkVisibleResourcesAsRequired)
3081 // on a layer with no recordings.
3082 host_impl_.pending_tree()->UpdateDrawProperties();
3083 pending_layer_->MarkVisibleResourcesAsRequired();
3086 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfAllHighResTilesShared) {
3087 gfx::Size layer_bounds(400, 400);
3088 gfx::Size tile_size(100, 100);
3089 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
3091 CreateHighLowResAndSetAllTilesVisible();
3093 Tile* some_active_tile =
3094 active_layer_->HighResTiling()->AllTilesForTesting()[0];
3095 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
3097 // All tiles shared (no invalidation), so even though the active tree's
3098 // tiles aren't ready, there is nothing required.
3099 pending_layer_->MarkVisibleResourcesAsRequired();
3100 AssertNoTilesRequired(pending_layer_->HighResTiling());
3101 if (host_impl_.settings().create_low_res_tiling) {
3102 AssertNoTilesRequired(pending_layer_->LowResTiling());
3106 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) {
3107 gfx::Size layer_bounds(400, 400);
3108 gfx::Size tile_size(100, 100);
3109 scoped_refptr<FakePicturePileImpl> pending_pile =
3110 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3111 // This pile will create tilings, but has no recordings so will not create any
3112 // tiles. This is attempting to simulate scrolling past the end of recorded
3113 // content on the active layer, where the recordings are so far away that
3114 // no tiles are created.
3115 scoped_refptr<FakePicturePileImpl> active_pile =
3116 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
3117 tile_size, layer_bounds);
3118 SetupTrees(pending_pile, active_pile);
3119 pending_layer_->set_fixed_tile_size(tile_size);
3120 active_layer_->set_fixed_tile_size(tile_size);
3122 CreateHighLowResAndSetAllTilesVisible();
3124 // Active layer has tilings, but no tiles due to missing recordings.
3125 EXPECT_TRUE(active_layer_->CanHaveTilings());
3126 EXPECT_EQ(active_layer_->tilings()->num_tilings(),
3127 host_impl_.settings().create_low_res_tiling ? 2u : 1u);
3128 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u);
3130 // Since the active layer has no tiles at all, the pending layer doesn't
3131 // need content in order to activate.
3132 pending_layer_->MarkVisibleResourcesAsRequired();
3133 AssertNoTilesRequired(pending_layer_->HighResTiling());
3134 if (host_impl_.settings().create_low_res_tiling)
3135 AssertNoTilesRequired(pending_layer_->LowResTiling());
3138 TEST_F(NoLowResPictureLayerImplTest,
3139 ResourcelessSoftwareDrawHasValidViewportForTilePriority) {
3140 base::TimeTicks time_ticks;
3141 time_ticks += base::TimeDelta::FromMilliseconds(1);
3142 host_impl_.SetCurrentBeginFrameArgs(
3143 CreateBeginFrameArgsForTesting(time_ticks));
3145 gfx::Size tile_size(100, 100);
3146 gfx::Size layer_bounds(400, 400);
3148 scoped_refptr<FakePicturePileImpl> pending_pile =
3149 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3150 scoped_refptr<FakePicturePileImpl> active_pile =
3151 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3153 SetupTrees(pending_pile, active_pile);
3155 Region invalidation;
3156 AddDefaultTilingsWithInvalidation(invalidation);
3157 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false);
3159 // UpdateTiles with valid viewport. Should update tile viewport.
3160 bool resourceless_software_draw = false;
3161 gfx::Rect viewport = gfx::Rect(layer_bounds);
3162 gfx::Transform transform;
3163 host_impl_.SetExternalDrawConstraints(transform,
3164 viewport,
3165 viewport,
3166 viewport,
3167 transform,
3168 resourceless_software_draw);
3169 active_layer_->draw_properties().visible_content_rect = viewport;
3170 active_layer_->draw_properties().screen_space_transform = transform;
3171 active_layer_->UpdateTiles(Occlusion());
3173 gfx::Rect visible_rect_for_tile_priority =
3174 active_layer_->visible_rect_for_tile_priority();
3175 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty());
3176 gfx::Rect viewport_rect_for_tile_priority =
3177 active_layer_->viewport_rect_for_tile_priority();
3178 EXPECT_FALSE(viewport_rect_for_tile_priority.IsEmpty());
3179 gfx::Transform screen_space_transform_for_tile_priority =
3180 active_layer_->screen_space_transform_for_tile_priority();
3182 // PictureLayerImpl does not make a special case for
3183 // resource_less_software_draw, so the tile viewport and matrix should be
3184 // respected.
3185 time_ticks += base::TimeDelta::FromMilliseconds(200);
3186 host_impl_.SetCurrentBeginFrameArgs(
3187 CreateBeginFrameArgsForTesting(time_ticks));
3188 resourceless_software_draw = true;
3189 viewport = gfx::ScaleToEnclosingRect(viewport, 2);
3190 transform.Translate(1.f, 1.f);
3191 active_layer_->draw_properties().visible_content_rect = viewport;
3192 active_layer_->draw_properties().screen_space_transform = transform;
3193 host_impl_.SetExternalDrawConstraints(transform,
3194 viewport,
3195 viewport,
3196 viewport,
3197 transform,
3198 resourceless_software_draw);
3199 active_layer_->UpdateTiles(Occlusion());
3201 visible_rect_for_tile_priority =
3202 gfx::ScaleToEnclosingRect(visible_rect_for_tile_priority, 2);
3203 viewport_rect_for_tile_priority =
3204 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority, 2);
3205 screen_space_transform_for_tile_priority = transform;
3207 EXPECT_RECT_EQ(visible_rect_for_tile_priority,
3208 active_layer_->visible_rect_for_tile_priority());
3209 EXPECT_RECT_EQ(viewport_rect_for_tile_priority,
3210 active_layer_->viewport_rect_for_tile_priority());
3211 EXPECT_TRANSFORMATION_MATRIX_EQ(
3212 screen_space_transform_for_tile_priority,
3213 active_layer_->screen_space_transform_for_tile_priority());
3216 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) {
3217 gfx::Size tile_size(400, 400);
3218 gfx::Size layer_bounds(1300, 1900);
3220 scoped_refptr<FakePicturePileImpl> pending_pile =
3221 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3222 scoped_refptr<FakePicturePileImpl> active_pile =
3223 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3225 std::vector<PictureLayerTiling*> used_tilings;
3227 SetupTrees(pending_pile, active_pile);
3228 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3230 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3231 EXPECT_LT(low_res_factor, 1.f);
3233 float device_scale = 1.7f;
3234 float page_scale = 3.2f;
3235 float scale = 1.f;
3237 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false);
3238 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3240 // We only have ideal tilings, so they aren't removed.
3241 used_tilings.clear();
3242 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3243 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3245 host_impl_.PinchGestureBegin();
3247 // Changing the ideal but not creating new tilings.
3248 scale *= 1.5f;
3249 page_scale *= 1.5f;
3250 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false);
3251 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3253 // The tilings are still our target scale, so they aren't removed.
3254 used_tilings.clear();
3255 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3256 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3258 host_impl_.PinchGestureEnd();
3260 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
3261 scale /= 4.f;
3262 page_scale /= 4.f;
3263 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, false);
3264 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3265 EXPECT_FLOAT_EQ(1.f,
3266 active_layer_->tilings()->tiling_at(1)->contents_scale());
3268 // Mark the non-ideal tilings as used. They won't be removed.
3269 used_tilings.clear();
3270 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
3271 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3272 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3274 // Now move the ideal scale to 0.5. Our target stays 1.2.
3275 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, false);
3277 // The high resolution tiling is between target and ideal, so is not
3278 // removed. The low res tiling for the old ideal=1.0 scale is removed.
3279 used_tilings.clear();
3280 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3281 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3283 // Now move the ideal scale to 1.0. Our target stays 1.2.
3284 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false);
3286 // All the tilings are between are target and the ideal, so they are not
3287 // removed.
3288 used_tilings.clear();
3289 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3290 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3292 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
3293 SetupDrawPropertiesAndUpdateTiles(
3294 active_layer_, 1.1f, device_scale, page_scale, 1.f, false);
3296 // Because the pending layer's ideal scale is still 1.0, our tilings fall
3297 // in the range [1.0,1.2] and are kept.
3298 used_tilings.clear();
3299 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3300 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3302 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
3303 // 1.2 still.
3304 SetupDrawPropertiesAndUpdateTiles(
3305 pending_layer_, 1.1f, device_scale, page_scale, 1.f, false);
3307 // Our 1.0 tiling now falls outside the range between our ideal scale and our
3308 // target raster scale. But it is in our used tilings set, so nothing is
3309 // deleted.
3310 used_tilings.clear();
3311 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
3312 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3313 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
3315 // If we remove it from our used tilings set, it is outside the range to keep
3316 // so it is deleted.
3317 used_tilings.clear();
3318 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3319 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
3322 TEST_F(PictureLayerImplTest, ScaleCollision) {
3323 gfx::Size tile_size(400, 400);
3324 gfx::Size layer_bounds(1300, 1900);
3326 scoped_refptr<FakePicturePileImpl> pending_pile =
3327 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3328 scoped_refptr<FakePicturePileImpl> active_pile =
3329 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3331 std::vector<PictureLayerTiling*> used_tilings;
3333 SetupTrees(pending_pile, active_pile);
3335 float pending_contents_scale = 1.f;
3336 float active_contents_scale = 2.f;
3337 float device_scale_factor = 1.f;
3338 float page_scale_factor = 1.f;
3339 float maximum_animation_contents_scale = 1.f;
3340 bool animating_transform = false;
3342 EXPECT_TRUE(host_impl_.settings().create_low_res_tiling);
3343 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3344 EXPECT_LT(low_res_factor, 1.f);
3346 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3347 pending_contents_scale,
3348 device_scale_factor,
3349 page_scale_factor,
3350 maximum_animation_contents_scale,
3351 animating_transform);
3352 SetupDrawPropertiesAndUpdateTiles(active_layer_,
3353 active_contents_scale,
3354 device_scale_factor,
3355 page_scale_factor,
3356 maximum_animation_contents_scale,
3357 animating_transform);
3359 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings());
3360 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
3362 EXPECT_EQ(active_contents_scale,
3363 pending_layer_->tilings()->tiling_at(0)->contents_scale());
3364 EXPECT_EQ(pending_contents_scale,
3365 pending_layer_->tilings()->tiling_at(1)->contents_scale());
3366 EXPECT_EQ(active_contents_scale * low_res_factor,
3367 pending_layer_->tilings()->tiling_at(2)->contents_scale());
3368 EXPECT_EQ(pending_contents_scale * low_res_factor,
3369 pending_layer_->tilings()->tiling_at(3)->contents_scale());
3371 EXPECT_EQ(active_contents_scale,
3372 active_layer_->tilings()->tiling_at(0)->contents_scale());
3373 EXPECT_EQ(pending_contents_scale,
3374 active_layer_->tilings()->tiling_at(1)->contents_scale());
3375 EXPECT_EQ(active_contents_scale * low_res_factor,
3376 active_layer_->tilings()->tiling_at(2)->contents_scale());
3377 EXPECT_EQ(pending_contents_scale * low_res_factor,
3378 active_layer_->tilings()->tiling_at(3)->contents_scale());
3380 // The unused low res tiling from the pending tree must be kept or we may add
3381 // it again on the active tree and collide with the pending tree.
3382 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
3383 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
3384 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
3386 EXPECT_EQ(active_contents_scale,
3387 active_layer_->tilings()->tiling_at(0)->contents_scale());
3388 EXPECT_EQ(pending_contents_scale,
3389 active_layer_->tilings()->tiling_at(1)->contents_scale());
3390 EXPECT_EQ(active_contents_scale * low_res_factor,
3391 active_layer_->tilings()->tiling_at(2)->contents_scale());
3392 EXPECT_EQ(pending_contents_scale * low_res_factor,
3393 active_layer_->tilings()->tiling_at(3)->contents_scale());
3396 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) {
3397 gfx::Size tile_size(400, 400);
3398 gfx::Size layer_bounds(1300, 1900);
3400 scoped_refptr<FakePicturePileImpl> pending_pile =
3401 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3402 scoped_refptr<FakePicturePileImpl> active_pile =
3403 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3405 SetupTrees(pending_pile, active_pile);
3406 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3408 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3409 1.3f, // ideal contents scale
3410 2.7f, // device scale
3411 3.2f, // page scale
3412 1.f, // maximum animation scale
3413 false);
3414 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3416 // All tilings should be removed when losing output surface.
3417 active_layer_->ReleaseResources();
3418 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
3419 pending_layer_->ReleaseResources();
3420 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
3422 // This should create new tilings.
3423 SetupDrawPropertiesAndUpdateTiles(pending_layer_,
3424 1.3f, // ideal contents scale
3425 2.7f, // device scale
3426 3.2f, // page scale
3427 1.f, // maximum animation scale
3428 false);
3429 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
3432 TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) {
3433 MockOcclusionTracker<LayerImpl> occlusion_tracker;
3434 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
3436 gfx::Size tile_size(400, 400);
3437 gfx::Size layer_bounds(1000, 2000);
3439 scoped_refptr<FakePicturePileImpl> pending_pile =
3440 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3441 scoped_refptr<FakePicturePileImpl> active_pile =
3442 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3444 SetupTrees(pending_pile, active_pile);
3446 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 2.5f, 1.f, 1.f, 1.f, false);
3447 host_impl_.pending_tree()->UpdateDrawProperties();
3449 active_layer_->draw_properties().visible_content_rect =
3450 gfx::Rect(layer_bounds);
3451 host_impl_.active_tree()->UpdateDrawProperties();
3453 float max_contents_scale = active_layer_->MaximumTilingContentsScale();
3454 gfx::Transform scaled_draw_transform = active_layer_->draw_transform();
3455 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale,
3456 SK_MScalar1 / max_contents_scale);
3458 AppendQuadsData data;
3459 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data);
3461 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
3462 EXPECT_EQ(1u, render_pass->shared_quad_state_list.size());
3463 // The content_to_target_transform should be scaled by the
3464 // MaximumTilingContentsScale on the layer.
3465 EXPECT_EQ(scaled_draw_transform.ToString(),
3466 render_pass->shared_quad_state_list[0]
3467 ->content_to_target_transform.ToString());
3468 // The content_bounds should be scaled by the
3469 // MaximumTilingContentsScale on the layer.
3470 EXPECT_EQ(gfx::Size(2500u, 5000u).ToString(),
3471 render_pass->shared_quad_state_list[0]->content_bounds.ToString());
3472 // The visible_content_rect should be scaled by the
3473 // MaximumTilingContentsScale on the layer.
3474 EXPECT_EQ(
3475 gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
3476 render_pass->shared_quad_state_list[0]->visible_content_rect.ToString());
3479 TEST_F(PictureLayerImplTest, UpdateTilesForMasksWithNoVisibleContent) {
3480 gfx::Size tile_size(400, 400);
3481 gfx::Size bounds(100000, 100);
3483 host_impl_.CreatePendingTree();
3485 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_.pending_tree(), 1);
3487 scoped_ptr<FakePictureLayerImpl> layer_with_mask =
3488 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 2);
3490 layer_with_mask->SetBounds(bounds);
3491 layer_with_mask->SetContentBounds(bounds);
3493 scoped_refptr<FakePicturePileImpl> pending_pile =
3494 FakePicturePileImpl::CreateFilledPile(tile_size, bounds);
3495 pending_pile->set_is_mask(true);
3496 scoped_ptr<FakePictureLayerImpl> mask = FakePictureLayerImpl::CreateWithPile(
3497 host_impl_.pending_tree(), 3, pending_pile);
3499 mask->SetBounds(bounds);
3500 mask->SetContentBounds(bounds);
3501 mask->SetDrawsContent(true);
3503 FakePictureLayerImpl* pending_mask_content = mask.get();
3504 layer_with_mask->SetMaskLayer(mask.PassAs<LayerImpl>());
3506 scoped_ptr<FakePictureLayerImpl> child_of_layer_with_mask =
3507 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 4);
3509 child_of_layer_with_mask->SetBounds(bounds);
3510 child_of_layer_with_mask->SetContentBounds(bounds);
3511 child_of_layer_with_mask->SetDrawsContent(true);
3513 layer_with_mask->AddChild(child_of_layer_with_mask.PassAs<LayerImpl>());
3515 root->AddChild(layer_with_mask.PassAs<LayerImpl>());
3517 host_impl_.pending_tree()->SetRootLayer(root.Pass());
3519 EXPECT_FALSE(pending_mask_content->tilings());
3520 host_impl_.pending_tree()->UpdateDrawProperties();
3521 EXPECT_NE(0u, pending_mask_content->num_tilings());
3524 class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest {
3525 public:
3526 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {}
3528 virtual void InitializeRenderer() OVERRIDE {
3529 host_impl_.InitializeRenderer(
3530 FakeOutputSurface::CreateDelegating3d().PassAs<OutputSurface>());
3534 TEST_F(PictureLayerImplTestWithDelegatingRenderer,
3535 DelegatingRendererWithTileOOM) {
3536 // This test is added for crbug.com/402321, where quad should be produced when
3537 // raster on demand is not allowed and tile is OOM.
3538 gfx::Size tile_size = host_impl_.settings().default_tile_size;
3539 gfx::Size layer_bounds(1000, 1000);
3541 // Create tiles.
3542 scoped_refptr<FakePicturePileImpl> pending_pile =
3543 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3544 SetupPendingTree(pending_pile);
3545 pending_layer_->SetBounds(layer_bounds);
3546 host_impl_.SetViewportSize(layer_bounds);
3547 ActivateTree();
3548 host_impl_.active_tree()->UpdateDrawProperties();
3549 std::vector<Tile*> tiles =
3550 active_layer_->HighResTiling()->AllTilesForTesting();
3551 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
3553 // Force tiles after max_tiles to be OOM. TileManager uses
3554 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3555 // directly set state to host_impl_, so we set policy that would change the
3556 // state. We also need to update tree priority separately.
3557 GlobalStateThatImpactsTilePriority state;
3558 size_t max_tiles = 1;
3559 size_t memory_limit = max_tiles * 4 * tile_size.width() * tile_size.height();
3560 size_t resource_limit = max_tiles;
3561 ManagedMemoryPolicy policy(memory_limit,
3562 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
3563 resource_limit);
3564 host_impl_.SetMemoryPolicy(policy);
3565 host_impl_.SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES);
3566 host_impl_.ManageTiles();
3568 MockOcclusionTracker<LayerImpl> occlusion_tracker;
3569 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
3570 AppendQuadsData data;
3571 active_layer_->WillDraw(DRAW_MODE_HARDWARE, NULL);
3572 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data);
3573 active_layer_->DidDraw(NULL);
3575 // Even when OOM, quads should be produced, and should be different material
3576 // from quads with resource.
3577 EXPECT_LT(max_tiles, render_pass->quad_list.size());
3578 EXPECT_EQ(DrawQuad::Material::TILED_CONTENT,
3579 render_pass->quad_list.front()->material);
3580 EXPECT_EQ(DrawQuad::Material::SOLID_COLOR,
3581 render_pass->quad_list.back()->material);
3584 class OcclusionTrackingSettings : public LowResTilingsSettings {
3585 public:
3586 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; }
3589 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest {
3590 public:
3591 OcclusionTrackingPictureLayerImplTest()
3592 : PictureLayerImplTest(OcclusionTrackingSettings()) {}
3594 void VerifyEvictionConsidersOcclusion(
3595 PictureLayerImpl* layer,
3596 size_t expected_occluded_tile_count[NUM_TREE_PRIORITIES]) {
3597 for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES;
3598 ++priority_count) {
3599 TreePriority tree_priority = static_cast<TreePriority>(priority_count);
3600 size_t occluded_tile_count = 0u;
3601 Tile* last_tile = NULL;
3603 for (PictureLayerImpl::LayerEvictionTileIterator it =
3604 PictureLayerImpl::LayerEvictionTileIterator(layer,
3605 tree_priority);
3607 ++it) {
3608 Tile* tile = *it;
3609 if (!last_tile)
3610 last_tile = tile;
3612 // The only way we will encounter an occluded tile after an unoccluded
3613 // tile is if the priorty bin decreased, the tile is required for
3614 // activation, or the scale changed.
3615 bool tile_is_occluded =
3616 tile->is_occluded_for_tree_priority(tree_priority);
3617 if (tile_is_occluded) {
3618 occluded_tile_count++;
3620 bool last_tile_is_occluded =
3621 last_tile->is_occluded_for_tree_priority(tree_priority);
3622 if (!last_tile_is_occluded) {
3623 TilePriority::PriorityBin tile_priority_bin =
3624 tile->priority_for_tree_priority(tree_priority).priority_bin;
3625 TilePriority::PriorityBin last_tile_priority_bin =
3626 last_tile->priority_for_tree_priority(tree_priority)
3627 .priority_bin;
3629 EXPECT_TRUE(
3630 (tile_priority_bin < last_tile_priority_bin) ||
3631 tile->required_for_activation() ||
3632 (tile->contents_scale() != last_tile->contents_scale()));
3635 last_tile = tile;
3637 EXPECT_EQ(expected_occluded_tile_count[priority_count],
3638 occluded_tile_count);
3643 TEST_F(OcclusionTrackingPictureLayerImplTest,
3644 OccludedTilesSkippedDuringRasterization) {
3645 base::TimeTicks time_ticks;
3646 time_ticks += base::TimeDelta::FromMilliseconds(1);
3647 host_impl_.SetCurrentBeginFrameArgs(
3648 CreateBeginFrameArgsForTesting(time_ticks));
3650 gfx::Size tile_size(102, 102);
3651 gfx::Size layer_bounds(1000, 1000);
3652 gfx::Size viewport_size(500, 500);
3653 gfx::Point occluding_layer_position(310, 0);
3655 scoped_refptr<FakePicturePileImpl> pending_pile =
3656 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3657 SetupPendingTree(pending_pile);
3658 pending_layer_->set_fixed_tile_size(tile_size);
3660 host_impl_.SetViewportSize(viewport_size);
3661 host_impl_.pending_tree()->UpdateDrawProperties();
3663 // No occlusion.
3664 int unoccluded_tile_count = 0;
3665 for (PictureLayerImpl::LayerRasterTileIterator it =
3666 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
3668 ++it) {
3669 Tile* tile = *it;
3671 // Occluded tiles should not be iterated over.
3672 EXPECT_FALSE(tile->is_occluded(PENDING_TREE));
3674 // Some tiles may not be visible (i.e. outside the viewport). The rest are
3675 // visible and at least partially unoccluded, verified by the above expect.
3676 bool tile_is_visible =
3677 tile->content_rect().Intersects(pending_layer_->visible_content_rect());
3678 if (tile_is_visible)
3679 unoccluded_tile_count++;
3681 EXPECT_EQ(unoccluded_tile_count, 25 + 4);
3683 // Partial occlusion.
3684 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
3685 LayerImpl* layer1 = pending_layer_->children()[0];
3686 layer1->SetBounds(layer_bounds);
3687 layer1->SetContentBounds(layer_bounds);
3688 layer1->SetDrawsContent(true);
3689 layer1->SetContentsOpaque(true);
3690 layer1->SetPosition(occluding_layer_position);
3692 time_ticks += base::TimeDelta::FromMilliseconds(200);
3693 host_impl_.SetCurrentBeginFrameArgs(
3694 CreateBeginFrameArgsForTesting(time_ticks));
3695 host_impl_.pending_tree()->UpdateDrawProperties();
3697 unoccluded_tile_count = 0;
3698 for (PictureLayerImpl::LayerRasterTileIterator it =
3699 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
3701 ++it) {
3702 Tile* tile = *it;
3704 EXPECT_FALSE(tile->is_occluded(PENDING_TREE));
3706 bool tile_is_visible =
3707 tile->content_rect().Intersects(pending_layer_->visible_content_rect());
3708 if (tile_is_visible)
3709 unoccluded_tile_count++;
3711 EXPECT_EQ(unoccluded_tile_count, 20 + 2);
3713 // Full occlusion.
3714 layer1->SetPosition(gfx::Point(0, 0));
3716 time_ticks += base::TimeDelta::FromMilliseconds(200);
3717 host_impl_.SetCurrentBeginFrameArgs(
3718 CreateBeginFrameArgsForTesting(time_ticks));
3719 host_impl_.pending_tree()->UpdateDrawProperties();
3721 unoccluded_tile_count = 0;
3722 for (PictureLayerImpl::LayerRasterTileIterator it =
3723 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
3725 ++it) {
3726 Tile* tile = *it;
3728 EXPECT_FALSE(tile->is_occluded(PENDING_TREE));
3730 bool tile_is_visible =
3731 tile->content_rect().Intersects(pending_layer_->visible_content_rect());
3732 if (tile_is_visible)
3733 unoccluded_tile_count++;
3735 EXPECT_EQ(unoccluded_tile_count, 0);
3738 TEST_F(OcclusionTrackingPictureLayerImplTest,
3739 OccludedTilesNotMarkedAsRequired) {
3740 base::TimeTicks time_ticks;
3741 time_ticks += base::TimeDelta::FromMilliseconds(1);
3742 host_impl_.SetCurrentBeginFrameArgs(
3743 CreateBeginFrameArgsForTesting(time_ticks));
3745 gfx::Size tile_size(102, 102);
3746 gfx::Size layer_bounds(1000, 1000);
3747 gfx::Size viewport_size(500, 500);
3748 gfx::Point occluding_layer_position(310, 0);
3750 scoped_refptr<FakePicturePileImpl> pending_pile =
3751 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3752 SetupPendingTree(pending_pile);
3753 pending_layer_->set_fixed_tile_size(tile_size);
3755 host_impl_.SetViewportSize(viewport_size);
3756 host_impl_.pending_tree()->UpdateDrawProperties();
3758 // No occlusion.
3759 int occluded_tile_count = 0;
3760 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3761 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3763 occluded_tile_count = 0;
3764 for (PictureLayerTiling::CoverageIterator iter(
3765 tiling,
3766 pending_layer_->contents_scale_x(),
3767 gfx::Rect(layer_bounds));
3768 iter;
3769 ++iter) {
3770 if (!*iter)
3771 continue;
3772 const Tile* tile = *iter;
3774 // Fully occluded tiles are not required for activation.
3775 if (tile->is_occluded(PENDING_TREE)) {
3776 EXPECT_FALSE(tile->required_for_activation());
3777 occluded_tile_count++;
3780 EXPECT_EQ(occluded_tile_count, 0);
3783 // Partial occlusion.
3784 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
3785 LayerImpl* layer1 = pending_layer_->children()[0];
3786 layer1->SetBounds(layer_bounds);
3787 layer1->SetContentBounds(layer_bounds);
3788 layer1->SetDrawsContent(true);
3789 layer1->SetContentsOpaque(true);
3790 layer1->SetPosition(occluding_layer_position);
3792 time_ticks += base::TimeDelta::FromMilliseconds(200);
3793 host_impl_.SetCurrentBeginFrameArgs(
3794 CreateBeginFrameArgsForTesting(time_ticks));
3795 host_impl_.pending_tree()->UpdateDrawProperties();
3797 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3798 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3800 occluded_tile_count = 0;
3801 for (PictureLayerTiling::CoverageIterator iter(
3802 tiling,
3803 pending_layer_->contents_scale_x(),
3804 gfx::Rect(layer_bounds));
3805 iter;
3806 ++iter) {
3807 if (!*iter)
3808 continue;
3809 const Tile* tile = *iter;
3811 if (tile->is_occluded(PENDING_TREE)) {
3812 EXPECT_FALSE(tile->required_for_activation());
3813 occluded_tile_count++;
3816 switch (i) {
3817 case 0:
3818 EXPECT_EQ(occluded_tile_count, 5);
3819 break;
3820 case 1:
3821 EXPECT_EQ(occluded_tile_count, 2);
3822 break;
3823 default:
3824 NOTREACHED();
3828 // Full occlusion.
3829 layer1->SetPosition(gfx::PointF(0, 0));
3831 time_ticks += base::TimeDelta::FromMilliseconds(200);
3832 host_impl_.SetCurrentBeginFrameArgs(
3833 CreateBeginFrameArgsForTesting(time_ticks));
3834 host_impl_.pending_tree()->UpdateDrawProperties();
3836 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3837 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3839 occluded_tile_count = 0;
3840 for (PictureLayerTiling::CoverageIterator iter(
3841 tiling,
3842 pending_layer_->contents_scale_x(),
3843 gfx::Rect(layer_bounds));
3844 iter;
3845 ++iter) {
3846 if (!*iter)
3847 continue;
3848 const Tile* tile = *iter;
3850 if (tile->is_occluded(PENDING_TREE)) {
3851 EXPECT_FALSE(tile->required_for_activation());
3852 occluded_tile_count++;
3855 switch (i) {
3856 case 0:
3857 EXPECT_EQ(occluded_tile_count, 25);
3858 break;
3859 case 1:
3860 EXPECT_EQ(occluded_tile_count, 4);
3861 break;
3862 default:
3863 NOTREACHED();
3868 TEST_F(OcclusionTrackingPictureLayerImplTest, OcclusionForDifferentScales) {
3869 gfx::Size tile_size(102, 102);
3870 gfx::Size layer_bounds(1000, 1000);
3871 gfx::Size viewport_size(500, 500);
3872 gfx::Point occluding_layer_position(310, 0);
3874 scoped_refptr<FakePicturePileImpl> pending_pile =
3875 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3876 SetupPendingTree(pending_pile);
3877 pending_layer_->set_fixed_tile_size(tile_size);
3879 ASSERT_TRUE(pending_layer_->CanHaveTilings());
3881 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
3883 std::vector<PictureLayerTiling*> tilings;
3884 tilings.push_back(pending_layer_->AddTiling(low_res_factor));
3885 tilings.push_back(pending_layer_->AddTiling(0.3f));
3886 tilings.push_back(pending_layer_->AddTiling(0.7f));
3887 tilings.push_back(pending_layer_->AddTiling(1.0f));
3888 tilings.push_back(pending_layer_->AddTiling(2.0f));
3890 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
3891 LayerImpl* layer1 = pending_layer_->children()[0];
3892 layer1->SetBounds(layer_bounds);
3893 layer1->SetContentBounds(layer_bounds);
3894 layer1->SetDrawsContent(true);
3895 layer1->SetContentsOpaque(true);
3896 layer1->SetPosition(occluding_layer_position);
3898 host_impl_.SetViewportSize(viewport_size);
3899 host_impl_.pending_tree()->UpdateDrawProperties();
3901 int tiling_count = 0;
3902 int occluded_tile_count = 0;
3903 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator =
3904 tilings.begin();
3905 tiling_iterator != tilings.end();
3906 ++tiling_iterator) {
3907 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting();
3909 occluded_tile_count = 0;
3910 for (size_t i = 0; i < tiles.size(); ++i) {
3911 if (tiles[i]->is_occluded(PENDING_TREE)) {
3912 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
3913 tiles[i]->content_rect(), 1.0f / tiles[i]->contents_scale());
3914 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x());
3915 occluded_tile_count++;
3918 switch (tiling_count) {
3919 case 0:
3920 case 1:
3921 EXPECT_EQ(occluded_tile_count, 2);
3922 break;
3923 case 2:
3924 EXPECT_EQ(occluded_tile_count, 4);
3925 break;
3926 case 3:
3927 EXPECT_EQ(occluded_tile_count, 5);
3928 break;
3929 case 4:
3930 EXPECT_EQ(occluded_tile_count, 30);
3931 break;
3932 default:
3933 NOTREACHED();
3936 tiling_count++;
3939 EXPECT_EQ(tiling_count, 5);
3942 TEST_F(OcclusionTrackingPictureLayerImplTest, DifferentOcclusionOnTrees) {
3943 gfx::Size tile_size(102, 102);
3944 gfx::Size layer_bounds(1000, 1000);
3945 gfx::Size viewport_size(1000, 1000);
3946 gfx::Point occluding_layer_position(310, 0);
3947 gfx::Rect invalidation_rect(230, 230, 102, 102);
3949 scoped_refptr<FakePicturePileImpl> pending_pile =
3950 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3951 scoped_refptr<FakePicturePileImpl> active_pile =
3952 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
3953 SetupTrees(pending_pile, active_pile);
3955 // Partially occlude the active layer.
3956 active_layer_->AddChild(LayerImpl::Create(host_impl_.active_tree(), 2));
3957 LayerImpl* layer1 = active_layer_->children()[0];
3958 layer1->SetBounds(layer_bounds);
3959 layer1->SetContentBounds(layer_bounds);
3960 layer1->SetDrawsContent(true);
3961 layer1->SetContentsOpaque(true);
3962 layer1->SetPosition(occluding_layer_position);
3964 // Partially invalidate the pending layer.
3965 pending_layer_->set_invalidation(invalidation_rect);
3967 host_impl_.SetViewportSize(viewport_size);
3969 active_layer_->CreateDefaultTilingsAndTiles();
3970 pending_layer_->CreateDefaultTilingsAndTiles();
3972 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
3973 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
3975 for (PictureLayerTiling::CoverageIterator iter(
3976 tiling,
3977 pending_layer_->contents_scale_x(),
3978 gfx::Rect(layer_bounds));
3979 iter;
3980 ++iter) {
3981 if (!*iter)
3982 continue;
3983 const Tile* tile = *iter;
3985 // All tiles are unoccluded on the pending tree.
3986 EXPECT_FALSE(tile->is_occluded(PENDING_TREE));
3988 Tile* twin_tile =
3989 pending_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j());
3990 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
3991 tile->content_rect(), 1.0f / tile->contents_scale());
3993 if (scaled_content_rect.Intersects(invalidation_rect)) {
3994 // Tiles inside the invalidation rect are only on the pending tree.
3995 EXPECT_NE(tile, twin_tile);
3997 // Unshared tiles should be unoccluded on the active tree by default.
3998 EXPECT_FALSE(tile->is_occluded(ACTIVE_TREE));
3999 } else {
4000 // Tiles outside the invalidation rect are shared between both trees.
4001 EXPECT_EQ(tile, twin_tile);
4002 // Shared tiles are occluded on the active tree iff they lie beneath the
4003 // occluding layer.
4004 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE),
4005 scaled_content_rect.x() >= occluding_layer_position.x());
4010 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4011 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4013 for (PictureLayerTiling::CoverageIterator iter(
4014 tiling,
4015 active_layer_->contents_scale_x(),
4016 gfx::Rect(layer_bounds));
4017 iter;
4018 ++iter) {
4019 if (!*iter)
4020 continue;
4021 const Tile* tile = *iter;
4023 Tile* twin_tile =
4024 active_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j());
4025 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4026 tile->content_rect(), 1.0f / tile->contents_scale());
4028 // Since we've already checked the shared tiles, only consider tiles in
4029 // the invalidation rect.
4030 if (scaled_content_rect.Intersects(invalidation_rect)) {
4031 // Tiles inside the invalidation rect are only on the active tree.
4032 EXPECT_NE(tile, twin_tile);
4034 // Unshared tiles should be unoccluded on the pending tree by default.
4035 EXPECT_FALSE(tile->is_occluded(PENDING_TREE));
4037 // Unshared tiles are occluded on the active tree iff they lie beneath
4038 // the occluding layer.
4039 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE),
4040 scaled_content_rect.x() >= occluding_layer_position.x());
4046 TEST_F(OcclusionTrackingPictureLayerImplTest,
4047 OccludedTilesConsideredDuringEviction) {
4048 gfx::Size tile_size(102, 102);
4049 gfx::Size layer_bounds(1000, 1000);
4050 gfx::Size viewport_size(500, 500);
4051 gfx::Point pending_occluding_layer_position(310, 0);
4052 gfx::Point active_occluding_layer_position(0, 310);
4053 gfx::Rect invalidation_rect(230, 230, 102, 102);
4055 scoped_refptr<FakePicturePileImpl> pending_pile =
4056 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4057 scoped_refptr<FakePicturePileImpl> active_pile =
4058 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4059 SetupTrees(pending_pile, active_pile);
4061 pending_layer_->set_fixed_tile_size(tile_size);
4062 active_layer_->set_fixed_tile_size(tile_size);
4064 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
4066 std::vector<PictureLayerTiling*> tilings;
4067 tilings.push_back(pending_layer_->AddTiling(low_res_factor));
4068 tilings.push_back(pending_layer_->AddTiling(0.3f));
4069 tilings.push_back(pending_layer_->AddTiling(0.7f));
4070 tilings.push_back(pending_layer_->AddTiling(1.0f));
4071 tilings.push_back(pending_layer_->AddTiling(2.0f));
4073 EXPECT_EQ(5u, pending_layer_->num_tilings());
4074 EXPECT_EQ(5u, active_layer_->num_tilings());
4076 // Partially occlude the pending layer.
4077 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
4078 LayerImpl* pending_occluding_layer = pending_layer_->children()[0];
4079 pending_occluding_layer->SetBounds(layer_bounds);
4080 pending_occluding_layer->SetContentBounds(layer_bounds);
4081 pending_occluding_layer->SetDrawsContent(true);
4082 pending_occluding_layer->SetContentsOpaque(true);
4083 pending_occluding_layer->SetPosition(pending_occluding_layer_position);
4085 // Partially occlude the active layer.
4086 active_layer_->AddChild(LayerImpl::Create(host_impl_.active_tree(), 2));
4087 LayerImpl* active_occluding_layer = active_layer_->children()[0];
4088 active_occluding_layer->SetBounds(layer_bounds);
4089 active_occluding_layer->SetContentBounds(layer_bounds);
4090 active_occluding_layer->SetDrawsContent(true);
4091 active_occluding_layer->SetContentsOpaque(true);
4092 active_occluding_layer->SetPosition(active_occluding_layer_position);
4094 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4095 // are not shared between trees.
4096 pending_layer_->set_invalidation(invalidation_rect);
4098 host_impl_.SetViewportSize(viewport_size);
4099 host_impl_.active_tree()->UpdateDrawProperties();
4100 host_impl_.pending_tree()->UpdateDrawProperties();
4102 // The expected number of occluded tiles on each of the 5 tilings for each of
4103 // the 3 tree priorities.
4104 size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u};
4105 size_t expected_occluded_tile_count_on_active[] = {30u, 5u, 4u, 2u, 2u};
4106 size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u};
4108 // The total expected number of occluded tiles on all tilings for each of the
4109 // 3 tree priorities.
4110 size_t total_expected_occluded_tile_count[] = {13u, 43u, 43u};
4112 ASSERT_EQ(arraysize(total_expected_occluded_tile_count), NUM_TREE_PRIORITIES);
4114 // Verify number of occluded tiles on the pending layer for each tiling.
4115 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) {
4116 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i);
4117 tiling->CreateAllTilesForTesting();
4119 size_t occluded_tile_count_on_pending = 0u;
4120 size_t occluded_tile_count_on_active = 0u;
4121 size_t occluded_tile_count_on_both = 0u;
4122 for (PictureLayerTiling::CoverageIterator iter(
4123 tiling,
4124 pending_layer_->contents_scale_x(),
4125 gfx::Rect(layer_bounds));
4126 iter;
4127 ++iter) {
4128 Tile* tile = *iter;
4130 if (tile->is_occluded(PENDING_TREE))
4131 occluded_tile_count_on_pending++;
4132 if (tile->is_occluded(ACTIVE_TREE))
4133 occluded_tile_count_on_active++;
4134 if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE))
4135 occluded_tile_count_on_both++;
4137 EXPECT_EQ(expected_occluded_tile_count_on_pending[i],
4138 occluded_tile_count_on_pending)
4139 << i;
4140 EXPECT_EQ(expected_occluded_tile_count_on_active[i],
4141 occluded_tile_count_on_active)
4142 << i;
4143 EXPECT_EQ(expected_occluded_tile_count_on_both[i],
4144 occluded_tile_count_on_both)
4145 << i;
4148 // Verify number of occluded tiles on the active layer for each tiling.
4149 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4150 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4151 tiling->CreateAllTilesForTesting();
4153 size_t occluded_tile_count_on_pending = 0u;
4154 size_t occluded_tile_count_on_active = 0u;
4155 size_t occluded_tile_count_on_both = 0u;
4156 for (PictureLayerTiling::CoverageIterator iter(
4157 tiling,
4158 pending_layer_->contents_scale_x(),
4159 gfx::Rect(layer_bounds));
4160 iter;
4161 ++iter) {
4162 Tile* tile = *iter;
4164 if (tile->is_occluded(PENDING_TREE))
4165 occluded_tile_count_on_pending++;
4166 if (tile->is_occluded(ACTIVE_TREE))
4167 occluded_tile_count_on_active++;
4168 if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE))
4169 occluded_tile_count_on_both++;
4171 EXPECT_EQ(expected_occluded_tile_count_on_pending[i],
4172 occluded_tile_count_on_pending)
4173 << i;
4174 EXPECT_EQ(expected_occluded_tile_count_on_active[i],
4175 occluded_tile_count_on_active)
4176 << i;
4177 EXPECT_EQ(expected_occluded_tile_count_on_both[i],
4178 occluded_tile_count_on_both)
4179 << i;
4182 std::vector<Tile*> all_tiles;
4183 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator =
4184 tilings.begin();
4185 tiling_iterator != tilings.end();
4186 ++tiling_iterator) {
4187 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting();
4188 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles));
4191 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
4193 VerifyEvictionConsidersOcclusion(pending_layer_,
4194 total_expected_occluded_tile_count);
4195 VerifyEvictionConsidersOcclusion(active_layer_,
4196 total_expected_occluded_tile_count);
4199 TEST_F(PictureLayerImplTest, RecycledTwinLayer) {
4200 gfx::Size tile_size(102, 102);
4201 gfx::Size layer_bounds(1000, 1000);
4203 scoped_refptr<FakePicturePileImpl> pile =
4204 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4205 SetupPendingTree(pile);
4206 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer());
4208 ActivateTree();
4209 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer());
4210 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer());
4212 SetupPendingTree(pile);
4213 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer());
4214 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer());
4216 ActivateTree();
4217 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer());
4218 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer());
4220 host_impl_.ResetRecycleTreeForTesting();
4221 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer());
4224 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) {
4225 base::TimeTicks time_ticks;
4226 time_ticks += base::TimeDelta::FromMilliseconds(1);
4227 host_impl_.SetCurrentBeginFrameArgs(
4228 CreateBeginFrameArgsForTesting(time_ticks));
4230 gfx::Size tile_size(100, 100);
4231 gfx::Size layer_bounds(200, 200);
4232 gfx::Rect layer_rect(layer_bounds);
4234 FakeContentLayerClient client;
4235 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
4236 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4237 host->SetRootLayer(layer);
4238 PicturePile* pile = layer->GetPicturePileForTesting();
4240 host_impl_.SetViewportSize(layer_bounds);
4242 int frame_number = 0;
4243 FakeRenderingStatsInstrumentation stats_instrumentation;
4245 client.set_fill_with_nonsolid_color(!test_for_solid);
4247 Region invalidation(layer_rect);
4248 pile->UpdateAndExpandInvalidation(&client,
4249 &invalidation,
4250 SK_ColorWHITE,
4251 false,
4252 false,
4253 layer_bounds,
4254 layer_rect,
4255 frame_number++,
4256 Picture::RECORD_NORMALLY,
4257 &stats_instrumentation);
4259 scoped_refptr<PicturePileImpl> pending_pile =
4260 PicturePileImpl::CreateFromOther(pile);
4262 SetupPendingTree(pending_pile);
4263 ActivateTree();
4265 if (test_for_solid) {
4266 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
4267 } else {
4268 ASSERT_TRUE(active_layer_->tilings());
4269 active_layer_->set_fixed_tile_size(tile_size);
4270 host_impl_.active_tree()->UpdateDrawProperties();
4271 ASSERT_GT(active_layer_->tilings()->num_tilings(), 0u);
4272 std::vector<Tile*> tiles =
4273 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
4274 EXPECT_FALSE(tiles.empty());
4275 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
4278 MockOcclusionTracker<LayerImpl> occlusion_tracker;
4279 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
4280 AppendQuadsData data;
4281 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, NULL);
4282 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data);
4283 active_layer_->DidDraw(NULL);
4285 DrawQuad::Material expected = test_for_solid
4286 ? DrawQuad::Material::SOLID_COLOR
4287 : DrawQuad::Material::TILED_CONTENT;
4288 EXPECT_EQ(expected, render_pass->quad_list.front()->material);
4291 TEST_F(PictureLayerImplTest, DrawSolidQuads) {
4292 TestQuadsForSolidColor(true);
4295 TEST_F(PictureLayerImplTest, DrawNonSolidQuads) {
4296 TestQuadsForSolidColor(false);
4299 TEST_F(PictureLayerImplTest, NonSolidToSolidNoTilings) {
4300 base::TimeTicks time_ticks;
4301 time_ticks += base::TimeDelta::FromMilliseconds(1);
4302 host_impl_.SetCurrentBeginFrameArgs(
4303 CreateBeginFrameArgsForTesting(time_ticks));
4305 gfx::Size tile_size(100, 100);
4306 gfx::Size layer_bounds(200, 200);
4307 gfx::Rect layer_rect(layer_bounds);
4309 FakeContentLayerClient client;
4310 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
4311 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
4312 host->SetRootLayer(layer);
4313 PicturePile* pile = layer->GetPicturePileForTesting();
4315 host_impl_.SetViewportSize(layer_bounds);
4317 int frame_number = 0;
4318 FakeRenderingStatsInstrumentation stats_instrumentation;
4320 client.set_fill_with_nonsolid_color(true);
4322 Region invalidation1(layer_rect);
4323 pile->UpdateAndExpandInvalidation(&client,
4324 &invalidation1,
4325 SK_ColorWHITE,
4326 false,
4327 false,
4328 layer_bounds,
4329 layer_rect,
4330 frame_number++,
4331 Picture::RECORD_NORMALLY,
4332 &stats_instrumentation);
4334 scoped_refptr<PicturePileImpl> pending_pile1 =
4335 PicturePileImpl::CreateFromOther(pile);
4337 SetupPendingTree(pending_pile1);
4338 ActivateTree();
4339 host_impl_.active_tree()->UpdateDrawProperties();
4341 // We've started with a solid layer that contains some tilings.
4342 ASSERT_TRUE(active_layer_->tilings());
4343 EXPECT_NE(0u, active_layer_->tilings()->num_tilings());
4345 client.set_fill_with_nonsolid_color(false);
4347 Region invalidation2(layer_rect);
4348 pile->UpdateAndExpandInvalidation(&client,
4349 &invalidation2,
4350 SK_ColorWHITE,
4351 false,
4352 false,
4353 layer_bounds,
4354 layer_rect,
4355 frame_number++,
4356 Picture::RECORD_NORMALLY,
4357 &stats_instrumentation);
4359 scoped_refptr<PicturePileImpl> pending_pile2 =
4360 PicturePileImpl::CreateFromOther(pile);
4362 SetupPendingTree(pending_pile2);
4363 ActivateTree();
4365 // We've switched to a solid color, so we should end up with no tilings.
4366 ASSERT_TRUE(active_layer_->tilings());
4367 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
4370 } // namespace
4371 } // namespace cc