Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / cc / layers / picture_layer_impl_unittest.cc
blob114c8a9bae3355a225ded8f2b318cbc603033559
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/layers/append_quads_data.h"
13 #include "cc/layers/picture_layer.h"
14 #include "cc/test/fake_content_layer_client.h"
15 #include "cc/test/fake_impl_proxy.h"
16 #include "cc/test/fake_layer_tree_host_impl.h"
17 #include "cc/test/fake_output_surface.h"
18 #include "cc/test/fake_picture_layer_impl.h"
19 #include "cc/test/fake_picture_pile_impl.h"
20 #include "cc/test/geometry_test_utils.h"
21 #include "cc/test/impl_side_painting_settings.h"
22 #include "cc/test/layer_test_common.h"
23 #include "cc/test/mock_quad_culler.h"
24 #include "cc/test/test_shared_bitmap_manager.h"
25 #include "cc/test/test_web_graphics_context_3d.h"
26 #include "cc/trees/layer_tree_impl.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gfx/rect_conversions.h"
30 namespace cc {
31 namespace {
33 class MockCanvas : public SkCanvas {
34 public:
35 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {}
37 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE {
38 // Capture calls before SkCanvas quickReject() kicks in.
39 rects_.push_back(rect);
42 std::vector<SkRect> rects_;
45 class PictureLayerImplTest : public testing::Test {
46 public:
47 PictureLayerImplTest()
48 : proxy_(base::MessageLoopProxy::current()),
49 host_impl_(ImplSidePaintingSettings(),
50 &proxy_,
51 &shared_bitmap_manager_),
52 id_(7) {}
54 explicit PictureLayerImplTest(const LayerTreeSettings& settings)
55 : proxy_(base::MessageLoopProxy::current()),
56 host_impl_(settings, &proxy_, &shared_bitmap_manager_),
57 id_(7) {}
59 virtual ~PictureLayerImplTest() {
62 virtual void SetUp() OVERRIDE {
63 InitializeRenderer();
66 virtual void InitializeRenderer() {
67 host_impl_.InitializeRenderer(
68 FakeOutputSurface::Create3d().PassAs<OutputSurface>());
71 void SetupDefaultTrees(const gfx::Size& layer_bounds) {
72 gfx::Size tile_size(100, 100);
74 scoped_refptr<FakePicturePileImpl> pending_pile =
75 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
76 scoped_refptr<FakePicturePileImpl> active_pile =
77 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
79 SetupTrees(pending_pile, active_pile);
82 void ActivateTree() {
83 host_impl_.ActivatePendingTree();
84 CHECK(!host_impl_.pending_tree());
85 pending_layer_ = NULL;
86 active_layer_ = static_cast<FakePictureLayerImpl*>(
87 host_impl_.active_tree()->LayerById(id_));
90 void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds,
91 const gfx::Size& tile_size) {
92 SetupDefaultTrees(layer_bounds);
93 pending_layer_->set_fixed_tile_size(tile_size);
94 active_layer_->set_fixed_tile_size(tile_size);
97 void SetupTrees(
98 scoped_refptr<PicturePileImpl> pending_pile,
99 scoped_refptr<PicturePileImpl> active_pile) {
100 SetupPendingTree(active_pile);
101 ActivateTree();
102 SetupPendingTree(pending_pile);
103 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(1.f, 0.25f, 100.f);
104 host_impl_.active_tree()->SetPageScaleFactorAndLimits(1.f, 0.25f, 100.f);
107 void CreateHighLowResAndSetAllTilesVisible() {
108 // Active layer must get updated first so pending layer can share from it.
109 active_layer_->CreateDefaultTilingsAndTiles();
110 active_layer_->SetAllTilesVisible();
111 pending_layer_->CreateDefaultTilingsAndTiles();
112 pending_layer_->SetAllTilesVisible();
115 void AddDefaultTilingsWithInvalidation(const Region& invalidation) {
116 active_layer_->AddTiling(2.3f);
117 active_layer_->AddTiling(1.0f);
118 active_layer_->AddTiling(0.5f);
119 for (size_t i = 0; i < active_layer_->tilings()->num_tilings(); ++i)
120 active_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting();
121 pending_layer_->set_invalidation(invalidation);
122 for (size_t i = 0; i < pending_layer_->tilings()->num_tilings(); ++i)
123 pending_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting();
126 void SetupPendingTree(scoped_refptr<PicturePileImpl> pile) {
127 host_impl_.CreatePendingTree();
128 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
129 // Clear recycled tree.
130 pending_tree->DetachLayerTree();
132 scoped_ptr<FakePictureLayerImpl> pending_layer =
133 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile);
134 pending_layer->SetDrawsContent(true);
135 pending_layer->SetAnchorPoint(gfx::PointF());
136 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>());
138 pending_layer_ = static_cast<FakePictureLayerImpl*>(
139 host_impl_.pending_tree()->LayerById(id_));
140 pending_layer_->DoPostCommitInitializationIfNeeded();
143 static void VerifyAllTilesExistAndHavePile(
144 const PictureLayerTiling* tiling,
145 PicturePileImpl* pile) {
146 for (PictureLayerTiling::CoverageIterator iter(
147 tiling, tiling->contents_scale(), tiling->TilingRect());
148 iter;
149 ++iter) {
150 EXPECT_TRUE(*iter);
151 EXPECT_EQ(pile, iter->picture_pile());
155 void SetContentsScaleOnBothLayers(float contents_scale,
156 float device_scale_factor,
157 float page_scale_factor,
158 float maximum_animation_contents_scale,
159 bool animating_transform) {
160 float result_scale_x, result_scale_y;
161 gfx::Size result_bounds;
162 pending_layer_->CalculateContentsScale(contents_scale,
163 device_scale_factor,
164 page_scale_factor,
165 maximum_animation_contents_scale,
166 animating_transform,
167 &result_scale_x,
168 &result_scale_y,
169 &result_bounds);
170 active_layer_->CalculateContentsScale(contents_scale,
171 device_scale_factor,
172 page_scale_factor,
173 maximum_animation_contents_scale,
174 animating_transform,
175 &result_scale_x,
176 &result_scale_y,
177 &result_bounds);
180 void ResetTilingsAndRasterScales() {
181 pending_layer_->ReleaseResources();
182 active_layer_->ReleaseResources();
185 void AssertAllTilesRequired(PictureLayerTiling* tiling) {
186 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
187 for (size_t i = 0; i < tiles.size(); ++i)
188 EXPECT_TRUE(tiles[i]->required_for_activation()) << "i: " << i;
189 EXPECT_GT(tiles.size(), 0u);
192 void AssertNoTilesRequired(PictureLayerTiling* tiling) {
193 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
194 for (size_t i = 0; i < tiles.size(); ++i)
195 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i;
196 EXPECT_GT(tiles.size(), 0u);
199 protected:
200 void TestTileGridAlignmentCommon() {
201 // Layer to span 4 raster tiles in x and in y
202 ImplSidePaintingSettings settings;
203 gfx::Size layer_size(
204 settings.default_tile_size.width() * 7 / 2,
205 settings.default_tile_size.height() * 7 / 2);
207 scoped_refptr<FakePicturePileImpl> pending_pile =
208 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
209 scoped_refptr<FakePicturePileImpl> active_pile =
210 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
212 SetupTrees(pending_pile, active_pile);
214 float result_scale_x, result_scale_y;
215 gfx::Size result_bounds;
216 active_layer_->CalculateContentsScale(1.f,
217 1.f,
218 1.f,
219 1.f,
220 false,
221 &result_scale_x,
222 &result_scale_y,
223 &result_bounds);
225 // Add 1x1 rects at the centers of each tile, then re-record pile contents
226 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
227 std::vector<Tile*> tiles =
228 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
229 EXPECT_EQ(16u, tiles.size());
230 std::vector<SkRect> rects;
231 std::vector<Tile*>::const_iterator tile_iter;
232 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
233 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint();
234 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1);
235 active_pile->add_draw_rect(rect);
236 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1));
238 // Force re-record with newly injected content
239 active_pile->RemoveRecordingAt(0, 0);
240 active_pile->AddRecordingAt(0, 0);
242 std::vector<SkRect>::const_iterator rect_iter = rects.begin();
243 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
244 MockCanvas mock_canvas(1000, 1000);
245 active_pile->RasterDirect(
246 &mock_canvas, (*tile_iter)->content_rect(), 1.0f, NULL);
248 // This test verifies that when drawing the contents of a specific tile
249 // at content scale 1.0, the playback canvas never receives content from
250 // neighboring tiles which indicates that the tile grid embedded in
251 // SkPicture is perfectly aligned with the compositor's tiles.
252 EXPECT_EQ(1u, mock_canvas.rects_.size());
253 EXPECT_RECT_EQ(*rect_iter, mock_canvas.rects_[0]);
254 rect_iter++;
258 FakeImplProxy proxy_;
259 TestSharedBitmapManager shared_bitmap_manager_;
260 FakeLayerTreeHostImpl host_impl_;
261 int id_;
262 FakePictureLayerImpl* pending_layer_;
263 FakePictureLayerImpl* active_layer_;
265 private:
266 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest);
269 TEST_F(PictureLayerImplTest, TileGridAlignment) {
270 host_impl_.SetDeviceScaleFactor(1.f);
271 TestTileGridAlignmentCommon();
274 TEST_F(PictureLayerImplTest, TileGridAlignmentHiDPI) {
275 host_impl_.SetDeviceScaleFactor(2.f);
276 TestTileGridAlignmentCommon();
279 TEST_F(PictureLayerImplTest, CloneNoInvalidation) {
280 gfx::Size tile_size(100, 100);
281 gfx::Size layer_bounds(400, 400);
283 scoped_refptr<FakePicturePileImpl> pending_pile =
284 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
285 scoped_refptr<FakePicturePileImpl> active_pile =
286 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
288 SetupTrees(pending_pile, active_pile);
290 Region invalidation;
291 AddDefaultTilingsWithInvalidation(invalidation);
293 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
294 active_layer_->tilings()->num_tilings());
296 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
297 EXPECT_GT(tilings->num_tilings(), 0u);
298 for (size_t i = 0; i < tilings->num_tilings(); ++i)
299 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), active_pile.get());
302 TEST_F(PictureLayerImplTest, TileManagerRegisterUnregister) {
303 gfx::Size tile_size(100, 100);
304 gfx::Size layer_bounds(400, 400);
306 scoped_refptr<FakePicturePileImpl> pending_pile =
307 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
308 scoped_refptr<FakePicturePileImpl> active_pile =
309 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
311 SetupTrees(pending_pile, active_pile);
313 std::vector<TileManager::PairedPictureLayer> paired_layers;
314 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
315 EXPECT_EQ(0u, paired_layers.size());
317 // Update tile priorities will force the layer to register itself.
318 float dummy_contents_scale_x;
319 float dummy_contents_scale_y;
320 gfx::Size dummy_content_bounds;
321 active_layer_->CalculateContentsScale(1.f,
322 1.f,
323 1.f,
324 1.f,
325 false,
326 &dummy_contents_scale_x,
327 &dummy_contents_scale_y,
328 &dummy_content_bounds);
329 active_layer_->UpdateTilePriorities();
330 host_impl_.pending_tree()->UpdateDrawProperties();
331 pending_layer_->CalculateContentsScale(1.f,
332 1.f,
333 1.f,
334 1.f,
335 false,
336 &dummy_contents_scale_x,
337 &dummy_contents_scale_y,
338 &dummy_content_bounds);
339 pending_layer_->UpdateTilePriorities();
341 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
342 EXPECT_EQ(1u, paired_layers.size());
343 EXPECT_EQ(active_layer_, paired_layers[0].active_layer);
344 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer);
346 // Destroy and recreate tile manager.
347 host_impl_.DidLoseOutputSurface();
348 scoped_ptr<TestWebGraphicsContext3D> context =
349 TestWebGraphicsContext3D::Create();
350 host_impl_.InitializeRenderer(
351 FakeOutputSurface::Create3d(context.Pass()).PassAs<OutputSurface>());
353 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
354 EXPECT_EQ(0u, paired_layers.size());
356 active_layer_->CalculateContentsScale(1.f,
357 1.f,
358 1.f,
359 1.f,
360 false,
361 &dummy_contents_scale_x,
362 &dummy_contents_scale_y,
363 &dummy_content_bounds);
364 active_layer_->UpdateTilePriorities();
365 host_impl_.pending_tree()->UpdateDrawProperties();
366 pending_layer_->CalculateContentsScale(1.f,
367 1.f,
368 1.f,
369 1.f,
370 false,
371 &dummy_contents_scale_x,
372 &dummy_contents_scale_y,
373 &dummy_content_bounds);
374 pending_layer_->UpdateTilePriorities();
376 host_impl_.tile_manager()->GetPairedPictureLayers(&paired_layers);
377 EXPECT_EQ(1u, paired_layers.size());
378 EXPECT_EQ(active_layer_, paired_layers[0].active_layer);
379 EXPECT_EQ(pending_layer_, paired_layers[0].pending_layer);
382 TEST_F(PictureLayerImplTest, InvalidViewportForPrioritizingTiles) {
383 base::TimeTicks time_ticks;
384 host_impl_.SetCurrentFrameTimeTicks(time_ticks);
386 gfx::Size tile_size(100, 100);
387 gfx::Size layer_bounds(400, 400);
389 scoped_refptr<FakePicturePileImpl> pending_pile =
390 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
391 scoped_refptr<FakePicturePileImpl> active_pile =
392 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
394 SetupTrees(pending_pile, active_pile);
396 Region invalidation;
397 AddDefaultTilingsWithInvalidation(invalidation);
398 float dummy_contents_scale_x;
399 float dummy_contents_scale_y;
400 gfx::Size dummy_content_bounds;
401 active_layer_->CalculateContentsScale(1.f,
402 1.f,
403 1.f,
404 1.f,
405 false,
406 &dummy_contents_scale_x,
407 &dummy_contents_scale_y,
408 &dummy_content_bounds);
410 // UpdateTilePriorities with valid viewport. Should update tile viewport.
411 bool valid_for_tile_management = true;
412 gfx::Rect viewport = gfx::Rect(layer_bounds);
413 gfx::Transform transform;
414 host_impl_.SetExternalDrawConstraints(
415 transform, viewport, viewport, valid_for_tile_management);
416 active_layer_->draw_properties().visible_content_rect = viewport;
417 active_layer_->draw_properties().screen_space_transform = transform;
418 active_layer_->UpdateTilePriorities();
420 gfx::Rect visible_rect_for_tile_priority =
421 active_layer_->visible_rect_for_tile_priority();
422 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty());
423 gfx::Size viewport_size_for_tile_priority =
424 active_layer_->viewport_size_for_tile_priority();
425 EXPECT_FALSE(viewport_size_for_tile_priority.IsEmpty());
426 gfx::Transform screen_space_transform_for_tile_priority =
427 active_layer_->screen_space_transform_for_tile_priority();
429 // Expand viewport and set it as invalid for prioritizing tiles.
430 // Should not update tile viewport.
431 time_ticks += base::TimeDelta::FromMilliseconds(200);
432 host_impl_.SetCurrentFrameTimeTicks(time_ticks);
433 valid_for_tile_management = false;
434 viewport = gfx::ScaleToEnclosingRect(viewport, 2);
435 transform.Translate(1.f, 1.f);
436 active_layer_->draw_properties().visible_content_rect = viewport;
437 active_layer_->draw_properties().screen_space_transform = transform;
438 host_impl_.SetExternalDrawConstraints(
439 transform, viewport, viewport, valid_for_tile_management);
440 active_layer_->UpdateTilePriorities();
442 EXPECT_RECT_EQ(visible_rect_for_tile_priority,
443 active_layer_->visible_rect_for_tile_priority());
444 EXPECT_SIZE_EQ(viewport_size_for_tile_priority,
445 active_layer_->viewport_size_for_tile_priority());
446 EXPECT_TRANSFORMATION_MATRIX_EQ(
447 screen_space_transform_for_tile_priority,
448 active_layer_->screen_space_transform_for_tile_priority());
450 // Keep expanded viewport but mark it valid. Should update tile viewport.
451 time_ticks += base::TimeDelta::FromMilliseconds(200);
452 host_impl_.SetCurrentFrameTimeTicks(time_ticks);
453 valid_for_tile_management = true;
454 host_impl_.SetExternalDrawConstraints(
455 transform, viewport, viewport, valid_for_tile_management);
456 active_layer_->UpdateTilePriorities();
458 EXPECT_FALSE(visible_rect_for_tile_priority ==
459 active_layer_->visible_rect_for_tile_priority());
460 EXPECT_FALSE(viewport_size_for_tile_priority ==
461 active_layer_->viewport_size_for_tile_priority());
462 EXPECT_FALSE(screen_space_transform_for_tile_priority ==
463 active_layer_->screen_space_transform_for_tile_priority());
466 TEST_F(PictureLayerImplTest, InvalidViewportAfterReleaseResources) {
467 base::TimeTicks time_ticks;
468 host_impl_.SetCurrentFrameTimeTicks(time_ticks);
470 gfx::Size tile_size(100, 100);
471 gfx::Size layer_bounds(400, 400);
473 scoped_refptr<FakePicturePileImpl> pending_pile =
474 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
475 scoped_refptr<FakePicturePileImpl> active_pile =
476 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
478 SetupTrees(pending_pile, active_pile);
480 Region invalidation;
481 AddDefaultTilingsWithInvalidation(invalidation);
483 bool valid_for_tile_management = false;
484 gfx::Rect viewport = gfx::Rect(layer_bounds);
485 host_impl_.SetExternalDrawConstraints(
486 gfx::Transform(), viewport, viewport, valid_for_tile_management);
487 ResetTilingsAndRasterScales();
488 host_impl_.pending_tree()->UpdateDrawProperties();
489 host_impl_.active_tree()->UpdateDrawProperties();
490 EXPECT_TRUE(active_layer_->HighResTiling());
492 size_t num_tilings = active_layer_->num_tilings();
493 active_layer_->UpdateTilePriorities();
494 pending_layer_->AddTiling(0.5f);
495 EXPECT_EQ(num_tilings + 1, active_layer_->num_tilings());
498 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) {
499 gfx::Size tile_size(100, 100);
500 gfx::Size layer_bounds(400, 400);
501 gfx::Rect layer_invalidation(150, 200, 30, 180);
503 scoped_refptr<FakePicturePileImpl> pending_pile =
504 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
505 scoped_refptr<FakePicturePileImpl> active_pile =
506 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
508 SetupTrees(pending_pile, active_pile);
510 Region invalidation(layer_invalidation);
511 AddDefaultTilingsWithInvalidation(invalidation);
513 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
514 EXPECT_GT(tilings->num_tilings(), 0u);
515 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
516 const PictureLayerTiling* tiling = tilings->tiling_at(i);
517 gfx::Rect content_invalidation = gfx::ScaleToEnclosingRect(
518 layer_invalidation,
519 tiling->contents_scale());
520 for (PictureLayerTiling::CoverageIterator iter(
521 tiling, tiling->contents_scale(), tiling->TilingRect());
522 iter;
523 ++iter) {
524 EXPECT_TRUE(*iter);
525 EXPECT_FALSE(iter.geometry_rect().IsEmpty());
526 if (iter.geometry_rect().Intersects(content_invalidation))
527 EXPECT_EQ(pending_pile, iter->picture_pile());
528 else
529 EXPECT_EQ(active_pile, iter->picture_pile());
534 TEST_F(PictureLayerImplTest, CloneFullInvalidation) {
535 gfx::Size tile_size(90, 80);
536 gfx::Size layer_bounds(300, 500);
538 scoped_refptr<FakePicturePileImpl> pending_pile =
539 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
540 scoped_refptr<FakePicturePileImpl> active_pile =
541 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
543 SetupTrees(pending_pile, active_pile);
545 Region invalidation((gfx::Rect(layer_bounds)));
546 AddDefaultTilingsWithInvalidation(invalidation);
548 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
549 active_layer_->tilings()->num_tilings());
551 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
552 EXPECT_GT(tilings->num_tilings(), 0u);
553 for (size_t i = 0; i < tilings->num_tilings(); ++i)
554 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), pending_pile.get());
557 TEST_F(PictureLayerImplTest, NoInvalidationBoundsChange) {
558 gfx::Size tile_size(90, 80);
559 gfx::Size active_layer_bounds(300, 500);
560 gfx::Size pending_layer_bounds(400, 800);
562 scoped_refptr<FakePicturePileImpl> pending_pile =
563 FakePicturePileImpl::CreateFilledPile(tile_size,
564 pending_layer_bounds);
565 scoped_refptr<FakePicturePileImpl> active_pile =
566 FakePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds);
568 SetupTrees(pending_pile, active_pile);
569 pending_layer_->set_fixed_tile_size(gfx::Size(100, 100));
571 Region invalidation;
572 AddDefaultTilingsWithInvalidation(invalidation);
574 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
575 EXPECT_GT(tilings->num_tilings(), 0u);
576 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
577 const PictureLayerTiling* tiling = tilings->tiling_at(i);
578 gfx::Rect active_content_bounds = gfx::ScaleToEnclosingRect(
579 gfx::Rect(active_layer_bounds),
580 tiling->contents_scale());
581 for (PictureLayerTiling::CoverageIterator iter(
582 tiling, tiling->contents_scale(), tiling->TilingRect());
583 iter;
584 ++iter) {
585 EXPECT_TRUE(*iter);
586 EXPECT_FALSE(iter.geometry_rect().IsEmpty());
587 std::vector<Tile*> active_tiles =
588 active_layer_->tilings()->tiling_at(i)->AllTilesForTesting();
589 std::vector<Tile*> pending_tiles = tiling->AllTilesForTesting();
590 if (iter.geometry_rect().right() >= active_content_bounds.width() ||
591 iter.geometry_rect().bottom() >= active_content_bounds.height() ||
592 active_tiles[0]->content_rect().size() !=
593 pending_tiles[0]->content_rect().size()) {
594 EXPECT_EQ(pending_pile, iter->picture_pile());
595 } else {
596 EXPECT_EQ(active_pile, iter->picture_pile());
602 TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) {
603 gfx::Size tile_size(400, 400);
604 gfx::Size layer_bounds(1300, 1900);
606 scoped_refptr<FakePicturePileImpl> pending_pile =
607 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
608 scoped_refptr<FakePicturePileImpl> active_pile =
609 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
611 // Fill in some of active pile, but more of pending pile.
612 int hole_count = 0;
613 for (int x = 0; x < active_pile->tiling().num_tiles_x(); ++x) {
614 for (int y = 0; y < active_pile->tiling().num_tiles_y(); ++y) {
615 if ((x + y) % 2) {
616 pending_pile->AddRecordingAt(x, y);
617 active_pile->AddRecordingAt(x, y);
618 } else {
619 hole_count++;
620 if (hole_count % 2)
621 pending_pile->AddRecordingAt(x, y);
626 SetupTrees(pending_pile, active_pile);
627 Region invalidation;
628 AddDefaultTilingsWithInvalidation(invalidation);
630 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
631 EXPECT_GT(tilings->num_tilings(), 0u);
632 for (size_t i = 0; i < tilings->num_tilings(); ++i) {
633 const PictureLayerTiling* tiling = tilings->tiling_at(i);
635 for (PictureLayerTiling::CoverageIterator iter(
636 tiling, tiling->contents_scale(), tiling->TilingRect());
637 iter;
638 ++iter) {
639 EXPECT_FALSE(iter.full_tile_geometry_rect().IsEmpty());
640 // Ensure there is a recording for this tile.
641 bool in_pending = pending_pile->CanRaster(tiling->contents_scale(),
642 iter.full_tile_geometry_rect());
643 bool in_active = active_pile->CanRaster(tiling->contents_scale(),
644 iter.full_tile_geometry_rect());
646 if (in_pending && !in_active)
647 EXPECT_EQ(pending_pile, iter->picture_pile());
648 else if (in_active)
649 EXPECT_EQ(active_pile, iter->picture_pile());
650 else
651 EXPECT_FALSE(*iter);
656 TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) {
657 gfx::Size tile_size(400, 400);
658 gfx::Size layer_bounds(1300, 1900);
660 scoped_refptr<FakePicturePileImpl> pending_pile =
661 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
662 scoped_refptr<FakePicturePileImpl> active_pile =
663 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
665 float result_scale_x, result_scale_y;
666 gfx::Size result_bounds;
668 SetupTrees(pending_pile, active_pile);
670 pending_layer_->CalculateContentsScale(1.f,
671 1.f,
672 1.f,
673 1.f,
674 false,
675 &result_scale_x,
676 &result_scale_y,
677 &result_bounds);
679 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
682 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) {
683 gfx::Size tile_size(400, 400);
684 gfx::Size layer_bounds(1300, 1900);
686 scoped_refptr<FakePicturePileImpl> pending_pile =
687 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
688 scoped_refptr<FakePicturePileImpl> active_pile =
689 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
691 float result_scale_x, result_scale_y;
692 gfx::Size result_bounds;
694 SetupTrees(pending_pile, active_pile);
695 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
697 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
698 EXPECT_LT(low_res_factor, 1.f);
700 pending_layer_->CalculateContentsScale(6.f, // ideal contents scale
701 3.f, // device scale
702 2.f, // page scale
703 1.f, // maximum animation scale
704 false,
705 &result_scale_x,
706 &result_scale_y,
707 &result_bounds);
708 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
709 EXPECT_FLOAT_EQ(6.f,
710 pending_layer_->tilings()->tiling_at(0)->contents_scale());
711 EXPECT_FLOAT_EQ(6.f * low_res_factor,
712 pending_layer_->tilings()->tiling_at(1)->contents_scale());
714 // If we change the page scale factor, then we should get new tilings.
715 pending_layer_->CalculateContentsScale(6.6f, // ideal contents scale
716 3.f, // device scale
717 2.2f, // page scale
718 1.f, // maximum animation scale
719 false,
720 &result_scale_x,
721 &result_scale_y,
722 &result_bounds);
723 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings());
724 EXPECT_FLOAT_EQ(6.6f,
725 pending_layer_->tilings()->tiling_at(0)->contents_scale());
726 EXPECT_FLOAT_EQ(6.6f * low_res_factor,
727 pending_layer_->tilings()->tiling_at(2)->contents_scale());
729 // If we change the device scale factor, then we should get new tilings.
730 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale
731 3.3f, // device scale
732 2.2f, // page scale
733 1.f, // maximum animation scale
734 false,
735 &result_scale_x,
736 &result_scale_y,
737 &result_bounds);
738 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings());
739 EXPECT_FLOAT_EQ(7.26f,
740 pending_layer_->tilings()->tiling_at(0)->contents_scale());
741 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
742 pending_layer_->tilings()->tiling_at(3)->contents_scale());
744 // If we change the device scale factor, but end up at the same total scale
745 // factor somehow, then we don't get new tilings.
746 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale
747 2.2f, // device scale
748 3.3f, // page scale
749 1.f, // maximum animation scale
750 false,
751 &result_scale_x,
752 &result_scale_y,
753 &result_bounds);
754 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings());
755 EXPECT_FLOAT_EQ(7.26f,
756 pending_layer_->tilings()->tiling_at(0)->contents_scale());
757 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
758 pending_layer_->tilings()->tiling_at(3)->contents_scale());
761 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) {
762 // This test makes sure that if a layer can have tilings, then a commit makes
763 // it not able to have tilings (empty size), and then a future commit that
764 // makes it valid again should be able to create tilings.
765 gfx::Size tile_size(400, 400);
766 gfx::Size layer_bounds(1300, 1900);
768 scoped_refptr<FakePicturePileImpl> empty_pile =
769 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
770 scoped_refptr<FakePicturePileImpl> valid_pile =
771 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
773 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
774 EXPECT_LT(low_res_factor, 1.f);
776 float high_res_scale = 1.3f;
777 float low_res_scale = high_res_scale * low_res_factor;
778 float device_scale = 1.7f;
779 float page_scale = 3.2f;
780 float maximum_animation_scale = 1.f;
781 float result_scale_x, result_scale_y;
782 gfx::Size result_bounds;
784 SetupPendingTree(valid_pile);
785 pending_layer_->CalculateContentsScale(high_res_scale,
786 device_scale,
787 page_scale,
788 maximum_animation_scale,
789 false,
790 &result_scale_x,
791 &result_scale_y,
792 &result_bounds);
793 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
794 EXPECT_FLOAT_EQ(high_res_scale,
795 pending_layer_->HighResTiling()->contents_scale());
796 EXPECT_FLOAT_EQ(low_res_scale,
797 pending_layer_->LowResTiling()->contents_scale());
799 ActivateTree();
800 SetupPendingTree(empty_pile);
801 pending_layer_->CalculateContentsScale(high_res_scale,
802 device_scale,
803 page_scale,
804 maximum_animation_scale,
805 false,
806 &result_scale_x,
807 &result_scale_y,
808 &result_bounds);
809 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
810 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
812 ActivateTree();
813 active_layer_->CalculateContentsScale(high_res_scale,
814 device_scale,
815 page_scale,
816 maximum_animation_scale,
817 false,
818 &result_scale_x,
819 &result_scale_y,
820 &result_bounds);
821 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
823 SetupPendingTree(valid_pile);
824 pending_layer_->CalculateContentsScale(high_res_scale,
825 device_scale,
826 page_scale,
827 maximum_animation_scale,
828 false,
829 &result_scale_x,
830 &result_scale_y,
831 &result_bounds);
832 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
833 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
834 EXPECT_FLOAT_EQ(high_res_scale,
835 pending_layer_->HighResTiling()->contents_scale());
836 EXPECT_FLOAT_EQ(low_res_scale,
837 pending_layer_->LowResTiling()->contents_scale());
840 TEST_F(PictureLayerImplTest, ZoomOutCrash) {
841 gfx::Size tile_size(400, 400);
842 gfx::Size layer_bounds(1300, 1900);
844 // Set up the high and low res tilings before pinch zoom.
845 scoped_refptr<FakePicturePileImpl> pending_pile =
846 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
847 scoped_refptr<FakePicturePileImpl> active_pile =
848 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
850 SetupTrees(pending_pile, active_pile);
851 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
852 SetContentsScaleOnBothLayers(32.0f, 1.0f, 32.0f, 1.0f, false);
853 host_impl_.PinchGestureBegin();
854 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false);
855 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, 1.0f, false);
856 EXPECT_EQ(active_layer_->tilings()->NumHighResTilings(), 1);
859 TEST_F(PictureLayerImplTest, PinchGestureTilings) {
860 gfx::Size tile_size(400, 400);
861 gfx::Size layer_bounds(1300, 1900);
863 scoped_refptr<FakePicturePileImpl> pending_pile =
864 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
865 scoped_refptr<FakePicturePileImpl> active_pile =
866 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
868 // Set up the high and low res tilings before pinch zoom.
869 SetupTrees(pending_pile, active_pile);
870 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
871 SetContentsScaleOnBothLayers(2.0f, 1.0f, 1.0f, 1.0f, false);
872 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
873 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings());
874 EXPECT_FLOAT_EQ(2.0f,
875 active_layer_->tilings()->tiling_at(0)->contents_scale());
876 EXPECT_FLOAT_EQ(2.0f * low_res_factor,
877 active_layer_->tilings()->tiling_at(1)->contents_scale());
879 // Start a pinch gesture.
880 host_impl_.PinchGestureBegin();
882 // Zoom out by a small amount. We should create a tiling at half
883 // the scale (2/kMaxScaleRatioDuringPinch).
884 SetContentsScaleOnBothLayers(1.8f, 1.0f, 0.9f, 1.0f, false);
885 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
886 EXPECT_FLOAT_EQ(2.0f,
887 active_layer_->tilings()->tiling_at(0)->contents_scale());
888 EXPECT_FLOAT_EQ(1.0f,
889 active_layer_->tilings()->tiling_at(1)->contents_scale());
890 EXPECT_FLOAT_EQ(2.0f * low_res_factor,
891 active_layer_->tilings()->tiling_at(2)->contents_scale());
893 // Zoom out further, close to our low-res scale factor. We should
894 // use that tiling as high-res, and not create a new tiling.
895 SetContentsScaleOnBothLayers(
896 low_res_factor, 1.0f, low_res_factor / 2.0f, 1.0f, false);
897 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
899 // Zoom in a lot now. Since we increase by increments of
900 // kMaxScaleRatioDuringPinch, this will first use 1.0, then 2.0
901 // and then finally create a new tiling at 4.0.
902 SetContentsScaleOnBothLayers(4.2f, 1.0f, 2.1f, 1.f, false);
903 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
904 SetContentsScaleOnBothLayers(4.2f, 1.0f, 2.1f, 1.f, false);
905 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings());
906 SetContentsScaleOnBothLayers(4.2f, 1.0f, 2.1f, 1.f, false);
907 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings());
908 EXPECT_FLOAT_EQ(4.0f,
909 active_layer_->tilings()->tiling_at(0)->contents_scale());
912 TEST_F(PictureLayerImplTest, CleanUpTilings) {
913 gfx::Size tile_size(400, 400);
914 gfx::Size layer_bounds(1300, 1900);
916 scoped_refptr<FakePicturePileImpl> pending_pile =
917 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
918 scoped_refptr<FakePicturePileImpl> active_pile =
919 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
921 float result_scale_x, result_scale_y;
922 gfx::Size result_bounds;
923 std::vector<PictureLayerTiling*> used_tilings;
925 SetupTrees(pending_pile, active_pile);
926 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
928 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
929 EXPECT_LT(low_res_factor, 1.f);
931 float device_scale = 1.7f;
932 float page_scale = 3.2f;
933 float scale = 1.f;
935 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false);
936 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
938 // We only have ideal tilings, so they aren't removed.
939 used_tilings.clear();
940 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
941 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
943 host_impl_.PinchGestureBegin();
945 // Changing the ideal but not creating new tilings.
946 scale *= 1.5f;
947 page_scale *= 1.5f;
948 SetContentsScaleOnBothLayers(scale, device_scale, page_scale, 1.f, false);
949 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
951 // The tilings are still our target scale, so they aren't removed.
952 used_tilings.clear();
953 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
954 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
956 host_impl_.PinchGestureEnd();
958 // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2.
959 scale /= 4.f;
960 page_scale /= 4.f;
961 SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, false);
962 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
963 EXPECT_FLOAT_EQ(
964 1.f,
965 active_layer_->tilings()->tiling_at(1)->contents_scale());
966 EXPECT_FLOAT_EQ(
967 1.f * low_res_factor,
968 active_layer_->tilings()->tiling_at(3)->contents_scale());
970 // Mark the non-ideal tilings as used. They won't be removed.
971 used_tilings.clear();
972 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
973 used_tilings.push_back(active_layer_->tilings()->tiling_at(3));
974 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
975 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
977 // Now move the ideal scale to 0.5. Our target stays 1.2.
978 SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, false);
980 // The high resolution tiling is between target and ideal, so is not
981 // removed. The low res tiling for the old ideal=1.0 scale is removed.
982 used_tilings.clear();
983 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
984 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
986 // Now move the ideal scale to 1.0. Our target stays 1.2.
987 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false);
989 // All the tilings are between are target and the ideal, so they are not
990 // removed.
991 used_tilings.clear();
992 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
993 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
995 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
996 active_layer_->CalculateContentsScale(1.1f,
997 device_scale,
998 page_scale,
999 1.f,
1000 false,
1001 &result_scale_x,
1002 &result_scale_y,
1003 &result_bounds);
1005 // Because the pending layer's ideal scale is still 1.0, our tilings fall
1006 // in the range [1.0,1.2] and are kept.
1007 used_tilings.clear();
1008 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1009 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1011 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
1012 // 1.2 still.
1013 pending_layer_->CalculateContentsScale(1.1f,
1014 device_scale,
1015 page_scale,
1016 1.f,
1017 false,
1018 &result_scale_x,
1019 &result_scale_y,
1020 &result_bounds);
1022 // Our 1.0 tiling now falls outside the range between our ideal scale and our
1023 // target raster scale. But it is in our used tilings set, so nothing is
1024 // deleted.
1025 used_tilings.clear();
1026 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
1027 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1028 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1030 // If we remove it from our used tilings set, it is outside the range to keep
1031 // so it is deleted.
1032 used_tilings.clear();
1033 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1034 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
1037 #define EXPECT_BOTH_EQ(expression, x) \
1038 do { \
1039 EXPECT_EQ(x, pending_layer_->expression); \
1040 EXPECT_EQ(x, active_layer_->expression); \
1041 } while (false)
1043 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) {
1044 // Make sure this layer covers multiple tiles, since otherwise low
1045 // res won't get created because it is too small.
1046 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1047 SetupDefaultTrees(gfx::Size(tile_size.width() + 1, tile_size.height() + 1));
1048 // Avoid max untiled layer size heuristics via fixed tile size.
1049 pending_layer_->set_fixed_tile_size(tile_size);
1050 active_layer_->set_fixed_tile_size(tile_size);
1052 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1053 float contents_scale = 1.f;
1054 float device_scale = 1.f;
1055 float page_scale = 1.f;
1056 float maximum_animation_scale = 1.f;
1057 bool animating_transform = true;
1059 // Animating, so don't create low res even if there isn't one already.
1060 SetContentsScaleOnBothLayers(contents_scale,
1061 device_scale,
1062 page_scale,
1063 maximum_animation_scale,
1064 animating_transform);
1065 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1066 EXPECT_BOTH_EQ(num_tilings(), 1u);
1068 // Stop animating, low res gets created.
1069 animating_transform = false;
1070 SetContentsScaleOnBothLayers(contents_scale,
1071 device_scale,
1072 page_scale,
1073 maximum_animation_scale,
1074 animating_transform);
1075 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1076 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor);
1077 EXPECT_BOTH_EQ(num_tilings(), 2u);
1079 // Page scale animation, new high res, but not new low res because animating.
1080 contents_scale = 2.f;
1081 page_scale = 2.f;
1082 animating_transform = true;
1083 SetContentsScaleOnBothLayers(contents_scale,
1084 device_scale,
1085 page_scale,
1086 maximum_animation_scale,
1087 animating_transform);
1088 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1089 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), low_res_factor);
1090 EXPECT_BOTH_EQ(num_tilings(), 3u);
1092 // Stop animating, new low res gets created for final page scale.
1093 animating_transform = false;
1094 SetContentsScaleOnBothLayers(contents_scale,
1095 device_scale,
1096 page_scale,
1097 maximum_animation_scale,
1098 animating_transform);
1099 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1100 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 2.f * low_res_factor);
1101 EXPECT_BOTH_EQ(num_tilings(), 4u);
1104 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) {
1105 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1106 SetupDefaultTrees(tile_size);
1108 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1109 float device_scale = 1.f;
1110 float page_scale = 1.f;
1111 float maximum_animation_scale = 1.f;
1112 bool animating_transform = false;
1114 // Contents exactly fit on one tile at scale 1, no low res.
1115 float contents_scale = 1.f;
1116 SetContentsScaleOnBothLayers(contents_scale,
1117 device_scale,
1118 page_scale,
1119 maximum_animation_scale,
1120 animating_transform);
1121 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1122 EXPECT_BOTH_EQ(num_tilings(), 1u);
1124 ResetTilingsAndRasterScales();
1126 // Contents that are smaller than one tile, no low res.
1127 contents_scale = 0.123f;
1128 SetContentsScaleOnBothLayers(contents_scale,
1129 device_scale,
1130 page_scale,
1131 maximum_animation_scale,
1132 animating_transform);
1133 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1134 EXPECT_BOTH_EQ(num_tilings(), 1u);
1136 ResetTilingsAndRasterScales();
1138 // Any content bounds that would create more than one tile will
1139 // generate a low res tiling.
1140 contents_scale = 2.5f;
1141 SetContentsScaleOnBothLayers(contents_scale,
1142 device_scale,
1143 page_scale,
1144 maximum_animation_scale,
1145 animating_transform);
1146 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1147 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1148 contents_scale * low_res_factor);
1149 EXPECT_BOTH_EQ(num_tilings(), 2u);
1151 ResetTilingsAndRasterScales();
1153 // Mask layers dont create low res since they always fit on one tile.
1154 pending_layer_->SetIsMask(true);
1155 active_layer_->SetIsMask(true);
1156 SetContentsScaleOnBothLayers(contents_scale,
1157 device_scale,
1158 page_scale,
1159 maximum_animation_scale,
1160 animating_transform);
1161 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1162 EXPECT_BOTH_EQ(num_tilings(), 1u);
1165 TEST_F(PictureLayerImplTest, ReleaseResources) {
1166 gfx::Size tile_size(400, 400);
1167 gfx::Size layer_bounds(1300, 1900);
1169 scoped_refptr<FakePicturePileImpl> pending_pile =
1170 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1171 scoped_refptr<FakePicturePileImpl> active_pile =
1172 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1174 float result_scale_x, result_scale_y;
1175 gfx::Size result_bounds;
1177 SetupTrees(pending_pile, active_pile);
1178 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1180 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale
1181 2.7f, // device scale
1182 3.2f, // page scale
1183 1.f, // maximum animation scale
1184 false,
1185 &result_scale_x,
1186 &result_scale_y,
1187 &result_bounds);
1188 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1190 // All tilings should be removed when losing output surface.
1191 active_layer_->ReleaseResources();
1192 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1193 pending_layer_->ReleaseResources();
1194 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1196 // This should create new tilings.
1197 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale
1198 2.7f, // device scale
1199 3.2f, // page scale
1200 1.f, // maximum animation scale
1201 false,
1202 &result_scale_x,
1203 &result_scale_y,
1204 &result_bounds);
1205 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1208 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) {
1209 // The default max tile size is larger than 400x400.
1210 gfx::Size tile_size(400, 400);
1211 gfx::Size layer_bounds(5000, 5000);
1213 scoped_refptr<FakePicturePileImpl> pending_pile =
1214 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1215 scoped_refptr<FakePicturePileImpl> active_pile =
1216 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1218 float result_scale_x, result_scale_y;
1219 gfx::Size result_bounds;
1221 SetupTrees(pending_pile, active_pile);
1222 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1224 pending_layer_->CalculateContentsScale(1.f,
1225 1.f,
1226 1.f,
1227 1.f,
1228 false,
1229 &result_scale_x,
1230 &result_scale_y,
1231 &result_bounds);
1232 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1234 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1236 // The default value.
1237 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1238 host_impl_.settings().default_tile_size.ToString());
1240 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1241 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1242 tile->content_rect().size().ToString());
1244 pending_layer_->ReleaseResources();
1246 // Change the max texture size on the output surface context.
1247 scoped_ptr<TestWebGraphicsContext3D> context =
1248 TestWebGraphicsContext3D::Create();
1249 context->set_max_texture_size(140);
1250 host_impl_.DidLoseOutputSurface();
1251 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d(
1252 context.Pass()).PassAs<OutputSurface>());
1254 pending_layer_->CalculateContentsScale(1.f,
1255 1.f,
1256 1.f,
1257 1.f,
1258 false,
1259 &result_scale_x,
1260 &result_scale_y,
1261 &result_bounds);
1262 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1264 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1266 // Verify the tiles are not larger than the context's max texture size.
1267 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1268 EXPECT_GE(140, tile->content_rect().width());
1269 EXPECT_GE(140, tile->content_rect().height());
1272 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) {
1273 // The default max tile size is larger than 400x400.
1274 gfx::Size tile_size(400, 400);
1275 gfx::Size layer_bounds(500, 500);
1277 scoped_refptr<FakePicturePileImpl> pending_pile =
1278 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1279 scoped_refptr<FakePicturePileImpl> active_pile =
1280 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1282 float result_scale_x, result_scale_y;
1283 gfx::Size result_bounds;
1285 SetupTrees(pending_pile, active_pile);
1286 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1288 pending_layer_->CalculateContentsScale(1.f,
1289 1.f,
1290 1.f,
1291 1.f,
1292 false,
1293 &result_scale_x,
1294 &result_scale_y,
1295 &result_bounds);
1296 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings());
1298 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1300 // The default value. The layer is smaller than this.
1301 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1302 host_impl_.settings().max_untiled_layer_size.ToString());
1304 // There should be a single tile since the layer is small.
1305 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0);
1306 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size());
1308 pending_layer_->ReleaseResources();
1310 // Change the max texture size on the output surface context.
1311 scoped_ptr<TestWebGraphicsContext3D> context =
1312 TestWebGraphicsContext3D::Create();
1313 context->set_max_texture_size(140);
1314 host_impl_.DidLoseOutputSurface();
1315 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d(
1316 context.Pass()).PassAs<OutputSurface>());
1318 pending_layer_->CalculateContentsScale(1.f,
1319 1.f,
1320 1.f,
1321 1.f,
1322 false,
1323 &result_scale_x,
1324 &result_scale_y,
1325 &result_bounds);
1326 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings());
1328 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1330 // There should be more than one tile since the max texture size won't cover
1331 // the layer.
1332 high_res_tiling = pending_layer_->tilings()->tiling_at(0);
1333 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size());
1335 // Verify the tiles are not larger than the context's max texture size.
1336 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1337 EXPECT_GE(140, tile->content_rect().width());
1338 EXPECT_GE(140, tile->content_rect().height());
1341 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) {
1342 MockQuadCuller quad_culler;
1344 gfx::Size tile_size(400, 400);
1345 gfx::Size layer_bounds(1300, 1900);
1347 scoped_refptr<FakePicturePileImpl> pending_pile =
1348 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1349 scoped_refptr<FakePicturePileImpl> active_pile =
1350 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1352 SetupTrees(pending_pile, active_pile);
1354 active_layer_->SetContentBounds(layer_bounds);
1355 active_layer_->draw_properties().visible_content_rect =
1356 gfx::Rect(layer_bounds);
1358 gfx::Rect layer_invalidation(150, 200, 30, 180);
1359 Region invalidation(layer_invalidation);
1360 AddDefaultTilingsWithInvalidation(invalidation);
1362 AppendQuadsData data;
1363 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, NULL);
1364 active_layer_->AppendQuads(&quad_culler, &data);
1365 active_layer_->DidDraw(NULL);
1367 ASSERT_EQ(1U, quad_culler.quad_list().size());
1368 EXPECT_EQ(DrawQuad::PICTURE_CONTENT, quad_culler.quad_list()[0]->material);
1371 TEST_F(PictureLayerImplTest, MarkRequiredNullTiles) {
1372 gfx::Size tile_size(100, 100);
1373 gfx::Size layer_bounds(1000, 1000);
1375 scoped_refptr<FakePicturePileImpl> pending_pile =
1376 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
1377 // Layers with entirely empty piles can't get tilings.
1378 pending_pile->AddRecordingAt(0, 0);
1380 SetupPendingTree(pending_pile);
1382 ASSERT_TRUE(pending_layer_->CanHaveTilings());
1383 pending_layer_->AddTiling(1.0f);
1384 pending_layer_->AddTiling(2.0f);
1386 // It should be safe to call this (and MarkVisibleResourcesAsRequired)
1387 // on a layer with no recordings.
1388 host_impl_.pending_tree()->UpdateDrawProperties();
1389 pending_layer_->MarkVisibleResourcesAsRequired();
1392 TEST_F(PictureLayerImplTest, MarkRequiredOffscreenTiles) {
1393 gfx::Size tile_size(100, 100);
1394 gfx::Size layer_bounds(200, 200);
1396 scoped_refptr<FakePicturePileImpl> pending_pile =
1397 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1398 SetupPendingTree(pending_pile);
1400 pending_layer_->set_fixed_tile_size(tile_size);
1401 ASSERT_TRUE(pending_layer_->CanHaveTilings());
1402 PictureLayerTiling* tiling = pending_layer_->AddTiling(1.f);
1403 host_impl_.pending_tree()->UpdateDrawProperties();
1404 EXPECT_EQ(tiling->resolution(), HIGH_RESOLUTION);
1406 pending_layer_->draw_properties().visible_content_rect =
1407 gfx::Rect(0, 0, 100, 200);
1409 // Fake set priorities.
1410 for (PictureLayerTiling::CoverageIterator iter(
1411 tiling, pending_layer_->contents_scale_x(), gfx::Rect(layer_bounds));
1412 iter;
1413 ++iter) {
1414 if (!*iter)
1415 continue;
1416 Tile* tile = *iter;
1417 TilePriority priority;
1418 priority.resolution = HIGH_RESOLUTION;
1419 gfx::Rect tile_bounds = iter.geometry_rect();
1420 if (pending_layer_->visible_content_rect().Intersects(tile_bounds)) {
1421 priority.priority_bin = TilePriority::NOW;
1422 priority.distance_to_visible = 0.f;
1423 } else {
1424 priority.priority_bin = TilePriority::SOON;
1425 priority.distance_to_visible = 1.f;
1427 tile->SetPriority(PENDING_TREE, priority);
1430 pending_layer_->MarkVisibleResourcesAsRequired();
1432 int num_visible = 0;
1433 int num_offscreen = 0;
1435 for (PictureLayerTiling::CoverageIterator iter(
1436 tiling, pending_layer_->contents_scale_x(), gfx::Rect(layer_bounds));
1437 iter;
1438 ++iter) {
1439 if (!*iter)
1440 continue;
1441 const Tile* tile = *iter;
1442 if (tile->priority(PENDING_TREE).distance_to_visible == 0.f) {
1443 EXPECT_TRUE(tile->required_for_activation());
1444 num_visible++;
1445 } else {
1446 EXPECT_FALSE(tile->required_for_activation());
1447 num_offscreen++;
1451 EXPECT_GT(num_visible, 0);
1452 EXPECT_GT(num_offscreen, 0);
1455 TEST_F(PictureLayerImplTest, HighResRequiredWhenUnsharedActiveAllReady) {
1456 gfx::Size layer_bounds(400, 400);
1457 gfx::Size tile_size(100, 100);
1458 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
1460 // No tiles shared.
1461 pending_layer_->set_invalidation(gfx::Rect(layer_bounds));
1463 CreateHighLowResAndSetAllTilesVisible();
1465 active_layer_->SetAllTilesReady();
1467 // No shared tiles and all active tiles ready, so pending can only
1468 // activate with all high res tiles.
1469 pending_layer_->MarkVisibleResourcesAsRequired();
1470 AssertAllTilesRequired(pending_layer_->HighResTiling());
1471 AssertNoTilesRequired(pending_layer_->LowResTiling());
1474 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) {
1475 gfx::Size layer_bounds(400, 400);
1476 gfx::Size tile_size(100, 100);
1477 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
1479 // All tiles shared (no invalidation).
1480 CreateHighLowResAndSetAllTilesVisible();
1482 // Verify active tree not ready.
1483 Tile* some_active_tile =
1484 active_layer_->HighResTiling()->AllTilesForTesting()[0];
1485 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
1487 // When high res are required, even if the active tree is not ready,
1488 // the high res tiles must be ready.
1489 host_impl_.active_tree()->SetRequiresHighResToDraw();
1490 pending_layer_->MarkVisibleResourcesAsRequired();
1491 AssertAllTilesRequired(pending_layer_->HighResTiling());
1492 AssertNoTilesRequired(pending_layer_->LowResTiling());
1495 TEST_F(PictureLayerImplTest, NothingRequiredIfAllHighResTilesShared) {
1496 gfx::Size layer_bounds(400, 400);
1497 gfx::Size tile_size(100, 100);
1498 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
1500 CreateHighLowResAndSetAllTilesVisible();
1502 Tile* some_active_tile =
1503 active_layer_->HighResTiling()->AllTilesForTesting()[0];
1504 EXPECT_FALSE(some_active_tile->IsReadyToDraw());
1506 // All tiles shared (no invalidation), so even though the active tree's
1507 // tiles aren't ready, there is nothing required.
1508 pending_layer_->MarkVisibleResourcesAsRequired();
1509 AssertNoTilesRequired(pending_layer_->HighResTiling());
1510 AssertNoTilesRequired(pending_layer_->LowResTiling());
1513 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) {
1514 gfx::Size layer_bounds(400, 400);
1515 gfx::Size tile_size(100, 100);
1516 scoped_refptr<FakePicturePileImpl> pending_pile =
1517 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1518 // This pile will create tilings, but has no recordings so will not create any
1519 // tiles. This is attempting to simulate scrolling past the end of recorded
1520 // content on the active layer, where the recordings are so far away that
1521 // no tiles are created.
1522 scoped_refptr<FakePicturePileImpl> active_pile =
1523 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
1524 tile_size, layer_bounds);
1525 SetupTrees(pending_pile, active_pile);
1526 pending_layer_->set_fixed_tile_size(tile_size);
1527 active_layer_->set_fixed_tile_size(tile_size);
1529 CreateHighLowResAndSetAllTilesVisible();
1531 // Active layer has tilings, but no tiles due to missing recordings.
1532 EXPECT_TRUE(active_layer_->CanHaveTilings());
1533 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u);
1534 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u);
1536 // Since the active layer has no tiles at all, the pending layer doesn't
1537 // need content in order to activate.
1538 pending_layer_->MarkVisibleResourcesAsRequired();
1539 AssertNoTilesRequired(pending_layer_->HighResTiling());
1540 AssertNoTilesRequired(pending_layer_->LowResTiling());
1543 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) {
1544 gfx::Size layer_bounds(400, 400);
1545 gfx::Size tile_size(100, 100);
1546 scoped_refptr<FakePicturePileImpl> pending_pile =
1547 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1548 scoped_refptr<FakePicturePileImpl> active_pile =
1549 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
1550 SetupTrees(pending_pile, active_pile);
1551 pending_layer_->set_fixed_tile_size(tile_size);
1552 active_layer_->set_fixed_tile_size(tile_size);
1554 CreateHighLowResAndSetAllTilesVisible();
1556 // Active layer can't have tiles.
1557 EXPECT_FALSE(active_layer_->CanHaveTilings());
1559 // All high res tiles required. This should be considered identical
1560 // to the case where there is no active layer, to avoid flashing content.
1561 // This can happen if a layer exists for a while and switches from
1562 // not being able to have content to having content.
1563 pending_layer_->MarkVisibleResourcesAsRequired();
1564 AssertAllTilesRequired(pending_layer_->HighResTiling());
1565 AssertNoTilesRequired(pending_layer_->LowResTiling());
1568 TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) {
1569 gfx::Size tile_size(100, 100);
1570 gfx::Size layer_bounds(400, 400);
1571 scoped_refptr<FakePicturePileImpl> pending_pile =
1572 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1574 host_impl_.CreatePendingTree();
1575 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
1577 scoped_ptr<FakePictureLayerImpl> pending_layer =
1578 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pending_pile);
1579 pending_layer->SetDrawsContent(true);
1580 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>());
1582 pending_layer_ = static_cast<FakePictureLayerImpl*>(
1583 host_impl_.pending_tree()->LayerById(id_));
1585 // Set some state on the pending layer, make sure it is not clobbered
1586 // by a sync from the active layer. This could happen because if the
1587 // pending layer has not been post-commit initialized it will attempt
1588 // to sync from the active layer.
1589 bool default_lcd_text_setting = pending_layer_->is_using_lcd_text();
1590 pending_layer_->force_set_lcd_text(!default_lcd_text_setting);
1591 EXPECT_TRUE(pending_layer_->needs_post_commit_initialization());
1593 host_impl_.ActivatePendingTree();
1595 active_layer_ = static_cast<FakePictureLayerImpl*>(
1596 host_impl_.active_tree()->LayerById(id_));
1598 EXPECT_EQ(0u, active_layer_->num_tilings());
1599 EXPECT_EQ(!default_lcd_text_setting, active_layer_->is_using_lcd_text());
1600 EXPECT_FALSE(active_layer_->needs_post_commit_initialization());
1603 TEST_F(PictureLayerImplTest, RemoveInvalidTilesOnActivation) {
1604 SetupDefaultTrees(gfx::Size(1500, 1500));
1605 AddDefaultTilingsWithInvalidation(gfx::Rect(0, 0, 1, 1));
1607 FakePictureLayerImpl* recycled_layer = pending_layer_;
1608 host_impl_.ActivatePendingTree();
1610 active_layer_ = static_cast<FakePictureLayerImpl*>(
1611 host_impl_.active_tree()->LayerById(id_));
1613 EXPECT_EQ(3u, active_layer_->num_tilings());
1614 EXPECT_EQ(3u, recycled_layer->num_tilings());
1615 EXPECT_FALSE(host_impl_.pending_tree());
1616 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
1617 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(i);
1618 PictureLayerTiling* recycled_tiling =
1619 recycled_layer->tilings()->tiling_at(i);
1621 ASSERT_TRUE(active_tiling);
1622 ASSERT_TRUE(recycled_tiling);
1624 EXPECT_TRUE(active_tiling->TileAt(0, 0));
1625 EXPECT_TRUE(active_tiling->TileAt(1, 0));
1626 EXPECT_TRUE(active_tiling->TileAt(0, 1));
1627 EXPECT_TRUE(active_tiling->TileAt(1, 1));
1629 EXPECT_FALSE(recycled_tiling->TileAt(0, 0));
1630 EXPECT_TRUE(recycled_tiling->TileAt(1, 0));
1631 EXPECT_TRUE(recycled_tiling->TileAt(0, 1));
1632 EXPECT_TRUE(recycled_tiling->TileAt(1, 1));
1634 EXPECT_EQ(active_tiling->TileAt(1, 0), recycled_tiling->TileAt(1, 0));
1635 EXPECT_EQ(active_tiling->TileAt(0, 1), recycled_tiling->TileAt(0, 1));
1636 EXPECT_EQ(active_tiling->TileAt(1, 1), recycled_tiling->TileAt(1, 1));
1640 TEST_F(PictureLayerImplTest, SyncTilingAfterReleaseResource) {
1641 SetupDefaultTrees(gfx::Size(10, 10));
1642 host_impl_.active_tree()->UpdateDrawProperties();
1643 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties());
1645 // Contrived unit test of a real crash. A layer is transparent during a
1646 // context loss, and later becomes opaque, causing active layer SyncTiling to
1647 // be called.
1648 float new_scale = 1.f;
1649 active_layer_->ReleaseResources();
1650 pending_layer_->ReleaseResources();
1651 EXPECT_FALSE(active_layer_->tilings()->TilingAtScale(new_scale));
1652 pending_layer_->AddTiling(new_scale);
1653 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(new_scale));
1655 // UpdateDrawProperties early-outs if the tree doesn't need it. It is also
1656 // responsible for calling ManageTilings. These checks verify that
1657 // ReleaseResources has set needs update draw properties so that the
1658 // new tiling gets the appropriate resolution set in ManageTilings.
1659 EXPECT_TRUE(host_impl_.active_tree()->needs_update_draw_properties());
1660 host_impl_.active_tree()->UpdateDrawProperties();
1661 PictureLayerTiling* high_res =
1662 active_layer_->tilings()->TilingAtScale(new_scale);
1663 ASSERT_TRUE(!!high_res);
1664 EXPECT_EQ(HIGH_RESOLUTION, high_res->resolution());
1667 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) {
1668 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
1669 gfx::Size layer_bounds(default_tile_size.width() * 4,
1670 default_tile_size.height() * 4);
1671 float result_scale_x, result_scale_y;
1672 gfx::Size result_bounds;
1674 SetupDefaultTrees(layer_bounds);
1675 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization());
1676 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1677 pending_layer_->CalculateContentsScale(1.f,
1678 1.f,
1679 1.f,
1680 1.f,
1681 false,
1682 &result_scale_x,
1683 &result_scale_y,
1684 &result_bounds);
1685 // Should have a low-res and a high-res tiling.
1686 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1688 pending_layer_->SetUseGpuRasterization(true);
1689 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization());
1690 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1691 pending_layer_->CalculateContentsScale(1.f,
1692 1.f,
1693 1.f,
1694 1.f,
1695 false,
1696 &result_scale_x,
1697 &result_scale_y,
1698 &result_bounds);
1699 // Should only have the high-res tiling.
1700 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
1703 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) {
1704 // Set up layers with tilings.
1705 SetupDefaultTrees(gfx::Size(10, 10));
1706 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false);
1707 pending_layer_->PushPropertiesTo(active_layer_);
1708 EXPECT_TRUE(pending_layer_->DrawsContent());
1709 EXPECT_TRUE(pending_layer_->CanHaveTilings());
1710 EXPECT_GE(pending_layer_->num_tilings(), 0u);
1711 EXPECT_GE(active_layer_->num_tilings(), 0u);
1713 // Set content to false, which should make CanHaveTilings return false.
1714 pending_layer_->SetDrawsContent(false);
1715 EXPECT_FALSE(pending_layer_->DrawsContent());
1716 EXPECT_FALSE(pending_layer_->CanHaveTilings());
1718 // No tilings should be pushed to active layer.
1719 pending_layer_->PushPropertiesTo(active_layer_);
1720 EXPECT_EQ(0u, active_layer_->num_tilings());
1723 TEST_F(PictureLayerImplTest, FirstTilingDuringPinch) {
1724 SetupDefaultTrees(gfx::Size(10, 10));
1725 host_impl_.PinchGestureBegin();
1726 float high_res_scale = 2.3f;
1727 SetContentsScaleOnBothLayers(high_res_scale, 1.f, 1.f, 1.f, false);
1729 ASSERT_GE(pending_layer_->num_tilings(), 0u);
1730 EXPECT_FLOAT_EQ(high_res_scale,
1731 pending_layer_->HighResTiling()->contents_scale());
1734 TEST_F(PictureLayerImplTest, FirstTilingTooSmall) {
1735 SetupDefaultTrees(gfx::Size(10, 10));
1736 host_impl_.PinchGestureBegin();
1737 float high_res_scale = 0.0001f;
1738 EXPECT_GT(pending_layer_->MinimumContentsScale(), high_res_scale);
1740 SetContentsScaleOnBothLayers(high_res_scale, 1.f, 1.f, 1.f, false);
1742 ASSERT_GE(pending_layer_->num_tilings(), 0u);
1743 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
1744 pending_layer_->HighResTiling()->contents_scale());
1747 TEST_F(PictureLayerImplTest, PinchingTooSmall) {
1748 SetupDefaultTrees(gfx::Size(10, 10));
1750 float contents_scale = 0.15f;
1751 SetContentsScaleOnBothLayers(contents_scale, 1.f, 1.f, 1.f, false);
1753 ASSERT_GE(pending_layer_->num_tilings(), 0u);
1754 EXPECT_FLOAT_EQ(contents_scale,
1755 pending_layer_->HighResTiling()->contents_scale());
1757 host_impl_.PinchGestureBegin();
1759 float page_scale = 0.0001f;
1760 EXPECT_LT(page_scale * contents_scale,
1761 pending_layer_->MinimumContentsScale());
1763 SetContentsScaleOnBothLayers(contents_scale, 1.f, page_scale, 1.f, false);
1764 ASSERT_GE(pending_layer_->num_tilings(), 0u);
1765 EXPECT_FLOAT_EQ(pending_layer_->MinimumContentsScale(),
1766 pending_layer_->HighResTiling()->contents_scale());
1769 class DeferredInitPictureLayerImplTest : public PictureLayerImplTest {
1770 public:
1771 virtual void InitializeRenderer() OVERRIDE {
1772 host_impl_.InitializeRenderer(FakeOutputSurface::CreateDeferredGL(
1773 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice))
1774 .PassAs<OutputSurface>());
1777 virtual void SetUp() OVERRIDE {
1778 PictureLayerImplTest::SetUp();
1780 // Create some default active and pending trees.
1781 gfx::Size tile_size(100, 100);
1782 gfx::Size layer_bounds(400, 400);
1784 scoped_refptr<FakePicturePileImpl> pending_pile =
1785 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1786 scoped_refptr<FakePicturePileImpl> active_pile =
1787 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1789 SetupTrees(pending_pile, active_pile);
1793 // This test is really a LayerTreeHostImpl test, in that it makes sure
1794 // that trees need update draw properties after deferred initialization.
1795 // However, this is also a regression test for PictureLayerImpl in that
1796 // not having this update will cause a crash.
1797 TEST_F(DeferredInitPictureLayerImplTest,
1798 PreventUpdateTilePrioritiesDuringLostContext) {
1799 host_impl_.pending_tree()->UpdateDrawProperties();
1800 host_impl_.active_tree()->UpdateDrawProperties();
1801 EXPECT_FALSE(host_impl_.pending_tree()->needs_update_draw_properties());
1802 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties());
1804 FakeOutputSurface* fake_output_surface =
1805 static_cast<FakeOutputSurface*>(host_impl_.output_surface());
1806 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d(
1807 TestContextProvider::Create()));
1809 // These will crash PictureLayerImpl if this is not true.
1810 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties());
1811 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties());
1812 host_impl_.active_tree()->UpdateDrawProperties();
1815 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForCpuRasterization) {
1816 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1817 SetupDefaultTrees(tile_size);
1819 float contents_scale = 1.f;
1820 float device_scale = 1.3f;
1821 float page_scale = 1.4f;
1822 float maximum_animation_scale = 1.f;
1823 bool animating_transform = false;
1825 SetContentsScaleOnBothLayers(contents_scale,
1826 device_scale,
1827 page_scale,
1828 maximum_animation_scale,
1829 animating_transform);
1830 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1832 // Since we're CPU-rasterizing, starting an animation should cause tiling
1833 // resolution to get set to the maximum animation scale factor.
1834 animating_transform = true;
1835 maximum_animation_scale = 3.f;
1836 contents_scale = 2.f;
1838 SetContentsScaleOnBothLayers(contents_scale,
1839 device_scale,
1840 page_scale,
1841 maximum_animation_scale,
1842 animating_transform);
1843 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
1845 // Further changes to scale during the animation should not cause a new
1846 // high-res tiling to get created.
1847 contents_scale = 4.f;
1848 maximum_animation_scale = 5.f;
1850 SetContentsScaleOnBothLayers(contents_scale,
1851 device_scale,
1852 page_scale,
1853 maximum_animation_scale,
1854 animating_transform);
1855 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f);
1857 // Once we stop animating, a new high-res tiling should be created.
1858 animating_transform = false;
1860 SetContentsScaleOnBothLayers(contents_scale,
1861 device_scale,
1862 page_scale,
1863 maximum_animation_scale,
1864 animating_transform);
1865 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
1867 // When animating with an unknown maximum animation scale factor, a new
1868 // high-res tiling should be created at the animation's initial scale.
1869 animating_transform = true;
1870 contents_scale = 2.f;
1871 maximum_animation_scale = 0.f;
1873 SetContentsScaleOnBothLayers(contents_scale,
1874 device_scale,
1875 page_scale,
1876 maximum_animation_scale,
1877 animating_transform);
1878 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1880 // Further changes to scale during the animation should not cause a new
1881 // high-res tiling to get created.
1882 contents_scale = 3.f;
1884 SetContentsScaleOnBothLayers(contents_scale,
1885 device_scale,
1886 page_scale,
1887 maximum_animation_scale,
1888 animating_transform);
1889 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1891 // Once we stop animating, a new high-res tiling should be created.
1892 animating_transform = false;
1893 contents_scale = 4.f;
1895 SetContentsScaleOnBothLayers(contents_scale,
1896 device_scale,
1897 page_scale,
1898 maximum_animation_scale,
1899 animating_transform);
1900 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
1903 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForGpuRasterization) {
1904 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1905 SetupDefaultTrees(tile_size);
1906 pending_layer_->SetUseGpuRasterization(true);
1907 active_layer_->SetUseGpuRasterization(true);
1909 float contents_scale = 1.f;
1910 float device_scale = 1.f;
1911 float page_scale = 1.f;
1912 float maximum_animation_scale = 1.f;
1913 bool animating_transform = false;
1915 SetContentsScaleOnBothLayers(contents_scale,
1916 device_scale,
1917 page_scale,
1918 maximum_animation_scale,
1919 animating_transform);
1920 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
1922 // Changing contents scale during an animation should cause tiling resolution
1923 // to change, since we're GPU-rasterizing. The maximum animation scale should
1924 // not have any effect.
1925 animating_transform = true;
1926 contents_scale = 2.f;
1927 maximum_animation_scale = 4.f;
1929 SetContentsScaleOnBothLayers(contents_scale,
1930 device_scale,
1931 page_scale,
1932 maximum_animation_scale,
1933 animating_transform);
1934 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1936 // Since we're re-rasterizing during the animation, scales smaller than 1
1937 // should be respected.
1938 contents_scale = 0.5f;
1939 SetContentsScaleOnBothLayers(contents_scale,
1940 device_scale,
1941 page_scale,
1942 maximum_animation_scale,
1943 animating_transform);
1944 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.5f);
1946 // Tiling resolution should also update once we stop animating.
1947 contents_scale = 4.f;
1948 animating_transform = false;
1949 SetContentsScaleOnBothLayers(contents_scale,
1950 device_scale,
1951 page_scale,
1952 maximum_animation_scale,
1953 animating_transform);
1954 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
1957 TEST_F(PictureLayerImplTest, LayerRasterTileIterator) {
1958 gfx::Size tile_size(100, 100);
1959 gfx::Size layer_bounds(1000, 1000);
1961 scoped_refptr<FakePicturePileImpl> pending_pile =
1962 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1964 SetupPendingTree(pending_pile);
1966 ASSERT_TRUE(pending_layer_->CanHaveTilings());
1968 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
1970 // Empty iterator
1971 PictureLayerImpl::LayerRasterTileIterator it;
1972 EXPECT_FALSE(it);
1974 // No tilings.
1975 it = PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
1976 EXPECT_FALSE(it);
1978 pending_layer_->AddTiling(low_res_factor);
1979 pending_layer_->AddTiling(0.3f);
1980 pending_layer_->AddTiling(0.7f);
1981 PictureLayerTiling* high_res_tiling = pending_layer_->AddTiling(1.0f);
1982 pending_layer_->AddTiling(2.0f);
1984 host_impl_.SetViewportSize(gfx::Size(500, 500));
1985 host_impl_.pending_tree()->UpdateDrawProperties();
1987 std::set<Tile*> unique_tiles;
1988 bool reached_prepaint = false;
1989 size_t non_ideal_tile_count = 0u;
1990 size_t low_res_tile_count = 0u;
1991 size_t high_res_tile_count = 0u;
1992 for (it = PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
1994 ++it) {
1995 Tile* tile = *it;
1996 TilePriority priority = tile->priority(PENDING_TREE);
1998 EXPECT_TRUE(tile);
2000 // Non-high res tiles only get visible tiles. Also, prepaint should only
2001 // come at the end of the iteration.
2002 if (priority.resolution != HIGH_RESOLUTION)
2003 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
2004 else if (reached_prepaint)
2005 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
2006 else
2007 reached_prepaint = priority.priority_bin != TilePriority::NOW;
2009 non_ideal_tile_count += priority.resolution == NON_IDEAL_RESOLUTION;
2010 low_res_tile_count += priority.resolution == LOW_RESOLUTION;
2011 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
2013 unique_tiles.insert(tile);
2016 EXPECT_TRUE(reached_prepaint);
2017 EXPECT_EQ(0u, non_ideal_tile_count);
2018 EXPECT_EQ(1u, low_res_tile_count);
2019 EXPECT_EQ(16u, high_res_tile_count);
2020 EXPECT_EQ(low_res_tile_count + high_res_tile_count + non_ideal_tile_count,
2021 unique_tiles.size());
2023 std::vector<Tile*> high_res_tiles = high_res_tiling->AllTilesForTesting();
2024 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin();
2025 tile_it != high_res_tiles.end();
2026 ++tile_it) {
2027 Tile* tile = *tile_it;
2028 ManagedTileState::TileVersion& tile_version =
2029 tile->GetTileVersionForTesting(
2030 tile->DetermineRasterModeForTree(ACTIVE_TREE));
2031 tile_version.SetSolidColorForTesting(SK_ColorRED);
2034 non_ideal_tile_count = 0;
2035 low_res_tile_count = 0;
2036 high_res_tile_count = 0;
2037 for (it = PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
2039 ++it) {
2040 Tile* tile = *it;
2041 TilePriority priority = tile->priority(PENDING_TREE);
2043 EXPECT_TRUE(tile);
2045 non_ideal_tile_count += priority.resolution == NON_IDEAL_RESOLUTION;
2046 low_res_tile_count += priority.resolution == LOW_RESOLUTION;
2047 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
2050 EXPECT_EQ(0u, non_ideal_tile_count);
2051 EXPECT_EQ(1u, low_res_tile_count);
2052 EXPECT_EQ(0u, high_res_tile_count);
2055 TEST_F(PictureLayerImplTest, LayerEvictionTileIterator) {
2056 gfx::Size tile_size(100, 100);
2057 gfx::Size layer_bounds(1000, 1000);
2059 scoped_refptr<FakePicturePileImpl> pending_pile =
2060 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2062 SetupPendingTree(pending_pile);
2064 ASSERT_TRUE(pending_layer_->CanHaveTilings());
2066 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2068 std::vector<PictureLayerTiling*> tilings;
2069 tilings.push_back(pending_layer_->AddTiling(low_res_factor));
2070 tilings.push_back(pending_layer_->AddTiling(0.3f));
2071 tilings.push_back(pending_layer_->AddTiling(0.7f));
2072 tilings.push_back(pending_layer_->AddTiling(1.0f));
2073 tilings.push_back(pending_layer_->AddTiling(2.0f));
2075 host_impl_.SetViewportSize(gfx::Size(500, 500));
2076 host_impl_.pending_tree()->UpdateDrawProperties();
2078 std::vector<Tile*> all_tiles;
2079 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator =
2080 tilings.begin();
2081 tiling_iterator != tilings.end();
2082 ++tiling_iterator) {
2083 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting();
2084 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles));
2087 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end());
2089 bool mark_required = false;
2090 for (std::vector<Tile*>::iterator it = all_tiles.begin();
2091 it != all_tiles.end();
2092 ++it) {
2093 Tile* tile = *it;
2094 if (mark_required)
2095 tile->MarkRequiredForActivation();
2096 mark_required = !mark_required;
2099 // Sanity checks.
2100 EXPECT_EQ(91u, all_tiles.size());
2101 EXPECT_EQ(91u, all_tiles_set.size());
2103 // Empty iterator.
2104 PictureLayerImpl::LayerEvictionTileIterator it;
2105 EXPECT_FALSE(it);
2107 // Tiles don't have resources yet.
2108 it = PictureLayerImpl::LayerEvictionTileIterator(
2109 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES);
2110 EXPECT_FALSE(it);
2112 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
2114 std::set<Tile*> unique_tiles;
2115 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f};
2116 size_t scale_index = 0;
2117 bool reached_visible = false;
2118 bool reached_required = false;
2119 Tile* last_tile = NULL;
2120 for (it = PictureLayerImpl::LayerEvictionTileIterator(
2121 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES);
2123 ++it) {
2124 Tile* tile = *it;
2125 if (!last_tile)
2126 last_tile = tile;
2128 EXPECT_TRUE(tile);
2130 TilePriority priority = tile->priority(PENDING_TREE);
2132 if (priority.priority_bin == TilePriority::NOW) {
2133 reached_visible = true;
2134 last_tile = tile;
2135 break;
2138 if (reached_required) {
2139 EXPECT_TRUE(tile->required_for_activation());
2140 } else if (tile->required_for_activation()) {
2141 reached_required = true;
2142 scale_index = 0;
2145 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) >
2146 std::numeric_limits<float>::epsilon()) {
2147 ++scale_index;
2148 ASSERT_LT(scale_index, arraysize(expected_scales));
2151 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]);
2152 unique_tiles.insert(tile);
2154 // If the tile is the same rough bin as last tile (same activation, bin, and
2155 // scale), then distance should be decreasing.
2156 if (tile->required_for_activation() ==
2157 last_tile->required_for_activation() &&
2158 priority.priority_bin ==
2159 last_tile->priority(PENDING_TREE).priority_bin &&
2160 std::abs(tile->contents_scale() - last_tile->contents_scale()) <
2161 std::numeric_limits<float>::epsilon()) {
2162 EXPECT_LE(priority.distance_to_visible,
2163 last_tile->priority(PENDING_TREE).distance_to_visible);
2166 last_tile = tile;
2169 EXPECT_TRUE(reached_visible);
2170 EXPECT_TRUE(reached_required);
2171 EXPECT_EQ(65u, unique_tiles.size());
2173 scale_index = 0;
2174 reached_required = false;
2175 for (; it; ++it) {
2176 Tile* tile = *it;
2177 EXPECT_TRUE(tile);
2179 TilePriority priority = tile->priority(PENDING_TREE);
2180 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
2182 if (reached_required) {
2183 EXPECT_TRUE(tile->required_for_activation());
2184 } else if (tile->required_for_activation()) {
2185 reached_required = true;
2186 scale_index = 0;
2189 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) >
2190 std::numeric_limits<float>::epsilon()) {
2191 ++scale_index;
2192 ASSERT_LT(scale_index, arraysize(expected_scales));
2195 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]);
2196 unique_tiles.insert(tile);
2199 EXPECT_TRUE(reached_required);
2200 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size());
2203 TEST_F(PictureLayerImplTest, Occlusion) {
2204 gfx::Size tile_size(102, 102);
2205 gfx::Size layer_bounds(1000, 1000);
2206 gfx::Size viewport_size(1000, 1000);
2208 LayerTestCommon::LayerImplTest impl;
2210 scoped_refptr<FakePicturePileImpl> pending_pile =
2211 FakePicturePileImpl::CreateFilledPile(layer_bounds, layer_bounds);
2212 SetupPendingTree(pending_pile);
2213 pending_layer_->SetBounds(layer_bounds);
2214 ActivateTree();
2215 active_layer_->set_fixed_tile_size(tile_size);
2217 host_impl_.SetViewportSize(viewport_size);
2218 host_impl_.active_tree()->UpdateDrawProperties();
2220 std::vector<Tile*> tiles =
2221 active_layer_->HighResTiling()->AllTilesForTesting();
2222 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
2225 SCOPED_TRACE("No occlusion");
2226 gfx::Rect occluded;
2227 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
2229 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
2230 gfx::Rect(layer_bounds));
2231 EXPECT_EQ(100u, impl.quad_list().size());
2235 SCOPED_TRACE("Full occlusion");
2236 gfx::Rect occluded(active_layer_->visible_content_rect());
2237 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
2239 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
2240 EXPECT_EQ(impl.quad_list().size(), 0u);
2244 SCOPED_TRACE("Partial occlusion");
2245 gfx::Rect occluded(150, 0, 200, 1000);
2246 impl.AppendQuadsWithOcclusion(active_layer_, occluded);
2248 size_t partially_occluded_count = 0;
2249 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion(
2250 impl.quad_list(),
2251 gfx::Rect(layer_bounds),
2252 occluded,
2253 &partially_occluded_count);
2254 // The layer outputs one quad, which is partially occluded.
2255 EXPECT_EQ(100u - 10u, impl.quad_list().size());
2256 EXPECT_EQ(10u + 10u, partially_occluded_count);
2260 TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) {
2261 gfx::Size tile_size(host_impl_.settings().default_tile_size);
2262 SetupDefaultTrees(tile_size);
2264 float contents_scale = 2.f;
2265 float device_scale = 1.f;
2266 float page_scale = 1.f;
2267 float maximum_animation_scale = 1.f;
2268 bool animating_transform = false;
2270 SetContentsScaleOnBothLayers(contents_scale,
2271 device_scale,
2272 page_scale,
2273 maximum_animation_scale,
2274 animating_transform);
2275 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
2277 // Changing the source scale without being in an animation will cause
2278 // the layer to reset its source scale to 1.f.
2279 contents_scale = 3.f;
2281 SetContentsScaleOnBothLayers(contents_scale,
2282 device_scale,
2283 page_scale,
2284 maximum_animation_scale,
2285 animating_transform);
2286 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2288 // Further changes to the source scale will no longer be reflected in the
2289 // contents scale.
2290 contents_scale = 0.5f;
2292 SetContentsScaleOnBothLayers(contents_scale,
2293 device_scale,
2294 page_scale,
2295 maximum_animation_scale,
2296 animating_transform);
2297 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 1.f);
2300 } // namespace
2301 } // namespace cc