Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Side by Side Diff: cc/layers/picture_layer_impl_unittest.cc

Issue 338653002: Revert of cc: Move tiling management out of draw properties calculation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/resources/picture_layer_tiling_set.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/picture_layer_impl.h" 5 #include "cc/layers/picture_layer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
11 11
12 #include "cc/layers/append_quads_data.h" 12 #include "cc/layers/append_quads_data.h"
13 #include "cc/layers/picture_layer.h" 13 #include "cc/layers/picture_layer.h"
14 #include "cc/test/fake_content_layer_client.h" 14 #include "cc/test/fake_content_layer_client.h"
15 #include "cc/test/fake_impl_proxy.h" 15 #include "cc/test/fake_impl_proxy.h"
16 #include "cc/test/fake_layer_tree_host_impl.h" 16 #include "cc/test/fake_layer_tree_host_impl.h"
17 #include "cc/test/fake_output_surface.h" 17 #include "cc/test/fake_output_surface.h"
18 #include "cc/test/fake_picture_layer_impl.h" 18 #include "cc/test/fake_picture_layer_impl.h"
19 #include "cc/test/fake_picture_pile_impl.h" 19 #include "cc/test/fake_picture_pile_impl.h"
20 #include "cc/test/geometry_test_utils.h" 20 #include "cc/test/geometry_test_utils.h"
21 #include "cc/test/impl_side_painting_settings.h" 21 #include "cc/test/impl_side_painting_settings.h"
22 #include "cc/test/layer_test_common.h" 22 #include "cc/test/layer_test_common.h"
23 #include "cc/test/mock_quad_culler.h" 23 #include "cc/test/mock_quad_culler.h"
24 #include "cc/test/test_shared_bitmap_manager.h" 24 #include "cc/test/test_shared_bitmap_manager.h"
25 #include "cc/test/test_web_graphics_context_3d.h" 25 #include "cc/test/test_web_graphics_context_3d.h"
26 #include "cc/trees/layer_tree_impl.h" 26 #include "cc/trees/layer_tree_impl.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gfx/rect_conversions.h" 28 #include "ui/gfx/rect_conversions.h"
29 #include "ui/gfx/size_conversions.h"
30 29
31 namespace cc { 30 namespace cc {
32 namespace { 31 namespace {
33 32
34 class MockCanvas : public SkCanvas { 33 class MockCanvas : public SkCanvas {
35 public: 34 public:
36 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {} 35 explicit MockCanvas(int w, int h) : SkCanvas(w, h) {}
37 36
38 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { 37 virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE {
39 // Capture calls before SkCanvas quickReject() kicks in. 38 // Capture calls before SkCanvas quickReject() kicks in.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 scoped_ptr<FakePictureLayerImpl> pending_layer = 132 scoped_ptr<FakePictureLayerImpl> pending_layer =
134 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile); 133 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile);
135 pending_layer->SetDrawsContent(true); 134 pending_layer->SetDrawsContent(true);
136 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>()); 135 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>());
137 136
138 pending_layer_ = static_cast<FakePictureLayerImpl*>( 137 pending_layer_ = static_cast<FakePictureLayerImpl*>(
139 host_impl_.pending_tree()->LayerById(id_)); 138 host_impl_.pending_tree()->LayerById(id_));
140 pending_layer_->DoPostCommitInitializationIfNeeded(); 139 pending_layer_->DoPostCommitInitializationIfNeeded();
141 } 140 }
142 141
143 void SetupDrawPropertiesAndManageTilings(
144 FakePictureLayerImpl* layer,
145 float ideal_contents_scale,
146 float device_scale_factor,
147 float page_scale_factor,
148 float maximum_animation_contents_scale,
149 bool animating_transform_to_screen) {
150 layer->draw_properties().ideal_contents_scale = ideal_contents_scale;
151 layer->draw_properties().device_scale_factor = device_scale_factor;
152 layer->draw_properties().page_scale_factor = page_scale_factor;
153 layer->draw_properties().maximum_animation_contents_scale =
154 maximum_animation_contents_scale;
155 layer->draw_properties().screen_space_transform_is_animating =
156 animating_transform_to_screen;
157 layer->ScaleAndManageTilings(animating_transform_to_screen,
158 maximum_animation_contents_scale);
159 }
160 static void VerifyAllTilesExistAndHavePile( 142 static void VerifyAllTilesExistAndHavePile(
161 const PictureLayerTiling* tiling, 143 const PictureLayerTiling* tiling,
162 PicturePileImpl* pile) { 144 PicturePileImpl* pile) {
163 for (PictureLayerTiling::CoverageIterator iter( 145 for (PictureLayerTiling::CoverageIterator iter(
164 tiling, tiling->contents_scale(), tiling->TilingRect()); 146 tiling, tiling->contents_scale(), tiling->TilingRect());
165 iter; 147 iter;
166 ++iter) { 148 ++iter) {
167 EXPECT_TRUE(*iter); 149 EXPECT_TRUE(*iter);
168 EXPECT_EQ(pile, iter->picture_pile()); 150 EXPECT_EQ(pile, iter->picture_pile());
169 } 151 }
170 } 152 }
171 153
172 void SetContentsScaleOnBothLayers(float contents_scale, 154 void SetContentsScaleOnBothLayers(float contents_scale,
173 float device_scale_factor, 155 float device_scale_factor,
174 float page_scale_factor, 156 float page_scale_factor,
175 float maximum_animation_contents_scale, 157 float maximum_animation_contents_scale,
176 bool animating_transform) { 158 bool animating_transform) {
177 SetupDrawPropertiesAndManageTilings(pending_layer_, 159 float result_scale_x, result_scale_y;
178 contents_scale, 160 gfx::Size result_bounds;
179 device_scale_factor, 161 pending_layer_->CalculateContentsScale(contents_scale,
180 page_scale_factor, 162 device_scale_factor,
181 maximum_animation_contents_scale, 163 page_scale_factor,
182 animating_transform); 164 maximum_animation_contents_scale,
183 165 animating_transform,
184 SetupDrawPropertiesAndManageTilings(active_layer_, 166 &result_scale_x,
185 contents_scale, 167 &result_scale_y,
186 device_scale_factor, 168 &result_bounds);
187 page_scale_factor, 169 active_layer_->CalculateContentsScale(contents_scale,
188 maximum_animation_contents_scale, 170 device_scale_factor,
189 animating_transform); 171 page_scale_factor,
172 maximum_animation_contents_scale,
173 animating_transform,
174 &result_scale_x,
175 &result_scale_y,
176 &result_bounds);
190 } 177 }
191 178
192 void ResetTilingsAndRasterScales() { 179 void ResetTilingsAndRasterScales() {
193 pending_layer_->ReleaseResources(); 180 pending_layer_->ReleaseResources();
194 active_layer_->ReleaseResources(); 181 active_layer_->ReleaseResources();
195 } 182 }
196 183
197 void AssertAllTilesRequired(PictureLayerTiling* tiling) { 184 void AssertAllTilesRequired(PictureLayerTiling* tiling) {
198 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 185 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
199 for (size_t i = 0; i < tiles.size(); ++i) 186 for (size_t i = 0; i < tiles.size(); ++i)
(...skipping 16 matching lines...) Expand all
216 settings.default_tile_size.width() * 7 / 2, 203 settings.default_tile_size.width() * 7 / 2,
217 settings.default_tile_size.height() * 7 / 2); 204 settings.default_tile_size.height() * 7 / 2);
218 205
219 scoped_refptr<FakePicturePileImpl> pending_pile = 206 scoped_refptr<FakePicturePileImpl> pending_pile =
220 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); 207 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
221 scoped_refptr<FakePicturePileImpl> active_pile = 208 scoped_refptr<FakePicturePileImpl> active_pile =
222 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size); 209 FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
223 210
224 SetupTrees(pending_pile, active_pile); 211 SetupTrees(pending_pile, active_pile);
225 212
226 SetupDrawPropertiesAndManageTilings( 213 float result_scale_x, result_scale_y;
227 active_layer_, 1.f, 1.f, 1.f, 1.f, false); 214 gfx::Size result_bounds;
215 active_layer_->CalculateContentsScale(1.f,
216 1.f,
217 1.f,
218 1.f,
219 false,
220 &result_scale_x,
221 &result_scale_y,
222 &result_bounds);
228 223
229 // Add 1x1 rects at the centers of each tile, then re-record pile contents 224 // Add 1x1 rects at the centers of each tile, then re-record pile contents
230 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 225 active_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
231 std::vector<Tile*> tiles = 226 std::vector<Tile*> tiles =
232 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting(); 227 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting();
233 EXPECT_EQ(16u, tiles.size()); 228 EXPECT_EQ(16u, tiles.size());
234 std::vector<SkRect> rects; 229 std::vector<SkRect> rects;
235 std::vector<Tile*>::const_iterator tile_iter; 230 std::vector<Tile*>::const_iterator tile_iter;
236 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { 231 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
237 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint(); 232 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 307
313 scoped_refptr<FakePicturePileImpl> pending_pile = 308 scoped_refptr<FakePicturePileImpl> pending_pile =
314 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 309 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
315 scoped_refptr<FakePicturePileImpl> active_pile = 310 scoped_refptr<FakePicturePileImpl> active_pile =
316 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 311 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
317 312
318 SetupTrees(pending_pile, active_pile); 313 SetupTrees(pending_pile, active_pile);
319 314
320 Region invalidation; 315 Region invalidation;
321 AddDefaultTilingsWithInvalidation(invalidation); 316 AddDefaultTilingsWithInvalidation(invalidation);
322 SetupDrawPropertiesAndManageTilings(active_layer_, 1.f, 1.f, 1.f, 1.f, false); 317 float dummy_contents_scale_x;
318 float dummy_contents_scale_y;
319 gfx::Size dummy_content_bounds;
320 active_layer_->CalculateContentsScale(1.f,
321 1.f,
322 1.f,
323 1.f,
324 false,
325 &dummy_contents_scale_x,
326 &dummy_contents_scale_y,
327 &dummy_content_bounds);
323 328
324 // UpdateTilePriorities with valid viewport. Should update tile viewport. 329 // UpdateTilePriorities with valid viewport. Should update tile viewport.
325 bool valid_for_tile_management = true; 330 bool valid_for_tile_management = true;
326 gfx::Rect viewport = gfx::Rect(layer_bounds); 331 gfx::Rect viewport = gfx::Rect(layer_bounds);
327 gfx::Transform transform; 332 gfx::Transform transform;
328 host_impl_.SetExternalDrawConstraints( 333 host_impl_.SetExternalDrawConstraints(
329 transform, viewport, viewport, valid_for_tile_management); 334 transform, viewport, viewport, valid_for_tile_management);
330 active_layer_->draw_properties().visible_content_rect = viewport; 335 active_layer_->draw_properties().visible_content_rect = viewport;
331 active_layer_->draw_properties().screen_space_transform = transform; 336 active_layer_->draw_properties().screen_space_transform = transform;
332 active_layer_->UpdateTilePriorities(); 337 active_layer_->UpdateTilePriorities();
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 574
570 TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) { 575 TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) {
571 gfx::Size tile_size(400, 400); 576 gfx::Size tile_size(400, 400);
572 gfx::Size layer_bounds(1300, 1900); 577 gfx::Size layer_bounds(1300, 1900);
573 578
574 scoped_refptr<FakePicturePileImpl> pending_pile = 579 scoped_refptr<FakePicturePileImpl> pending_pile =
575 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); 580 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
576 scoped_refptr<FakePicturePileImpl> active_pile = 581 scoped_refptr<FakePicturePileImpl> active_pile =
577 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); 582 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
578 583
584 float result_scale_x, result_scale_y;
585 gfx::Size result_bounds;
586
579 SetupTrees(pending_pile, active_pile); 587 SetupTrees(pending_pile, active_pile);
580 588
581 SetupDrawPropertiesAndManageTilings( 589 pending_layer_->CalculateContentsScale(1.f,
582 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); 590 1.f,
591 1.f,
592 1.f,
593 false,
594 &result_scale_x,
595 &result_scale_y,
596 &result_bounds);
583 597
584 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 598 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
585 } 599 }
586 600
587 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) { 601 TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) {
588 gfx::Size tile_size(400, 400); 602 gfx::Size tile_size(400, 400);
589 gfx::Size layer_bounds(1300, 1900); 603 gfx::Size layer_bounds(1300, 1900);
590 604
591 scoped_refptr<FakePicturePileImpl> pending_pile = 605 scoped_refptr<FakePicturePileImpl> pending_pile =
592 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 606 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
593 scoped_refptr<FakePicturePileImpl> active_pile = 607 scoped_refptr<FakePicturePileImpl> active_pile =
594 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 608 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
595 609
610 float result_scale_x, result_scale_y;
611 gfx::Size result_bounds;
612
596 SetupTrees(pending_pile, active_pile); 613 SetupTrees(pending_pile, active_pile);
597 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 614 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
598 615
599 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 616 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
600 EXPECT_LT(low_res_factor, 1.f); 617 EXPECT_LT(low_res_factor, 1.f);
601 618
602 SetupDrawPropertiesAndManageTilings(pending_layer_, 619 pending_layer_->CalculateContentsScale(6.f, // ideal contents scale
603 6.f, // ideal contents scale 620 3.f, // device scale
604 3.f, // device scale 621 2.f, // page scale
605 2.f, // page scale 622 1.f, // maximum animation scale
606 1.f, // maximum animation scale 623 false,
607 false); 624 &result_scale_x,
625 &result_scale_y,
626 &result_bounds);
608 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 627 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
609 EXPECT_FLOAT_EQ(6.f, 628 EXPECT_FLOAT_EQ(6.f,
610 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 629 pending_layer_->tilings()->tiling_at(0)->contents_scale());
611 EXPECT_FLOAT_EQ(6.f * low_res_factor, 630 EXPECT_FLOAT_EQ(6.f * low_res_factor,
612 pending_layer_->tilings()->tiling_at(1)->contents_scale()); 631 pending_layer_->tilings()->tiling_at(1)->contents_scale());
613 632
614 // If we change the page scale factor, then we should get new tilings. 633 // If we change the page scale factor, then we should get new tilings.
615 SetupDrawPropertiesAndManageTilings(pending_layer_, 634 pending_layer_->CalculateContentsScale(6.6f, // ideal contents scale
616 6.6f, // ideal contents scale 635 3.f, // device scale
617 3.f, // device scale 636 2.2f, // page scale
618 2.2f, // page scale 637 1.f, // maximum animation scale
619 1.f, // maximum animation scale 638 false,
620 false); 639 &result_scale_x,
640 &result_scale_y,
641 &result_bounds);
621 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings()); 642 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings());
622 EXPECT_FLOAT_EQ(6.6f, 643 EXPECT_FLOAT_EQ(6.6f,
623 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 644 pending_layer_->tilings()->tiling_at(0)->contents_scale());
624 EXPECT_FLOAT_EQ(6.6f * low_res_factor, 645 EXPECT_FLOAT_EQ(6.6f * low_res_factor,
625 pending_layer_->tilings()->tiling_at(2)->contents_scale()); 646 pending_layer_->tilings()->tiling_at(2)->contents_scale());
626 647
627 // If we change the device scale factor, then we should get new tilings. 648 // If we change the device scale factor, then we should get new tilings.
628 SetupDrawPropertiesAndManageTilings(pending_layer_, 649 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale
629 7.26f, // ideal contents scale 650 3.3f, // device scale
630 3.3f, // device scale 651 2.2f, // page scale
631 2.2f, // page scale 652 1.f, // maximum animation scale
632 1.f, // maximum animation scale 653 false,
633 false); 654 &result_scale_x,
655 &result_scale_y,
656 &result_bounds);
634 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); 657 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings());
635 EXPECT_FLOAT_EQ(7.26f, 658 EXPECT_FLOAT_EQ(7.26f,
636 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 659 pending_layer_->tilings()->tiling_at(0)->contents_scale());
637 EXPECT_FLOAT_EQ(7.26f * low_res_factor, 660 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
638 pending_layer_->tilings()->tiling_at(3)->contents_scale()); 661 pending_layer_->tilings()->tiling_at(3)->contents_scale());
639 662
640 // If we change the device scale factor, but end up at the same total scale 663 // If we change the device scale factor, but end up at the same total scale
641 // factor somehow, then we don't get new tilings. 664 // factor somehow, then we don't get new tilings.
642 SetupDrawPropertiesAndManageTilings(pending_layer_, 665 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale
643 7.26f, // ideal contents scale 666 2.2f, // device scale
644 2.2f, // device scale 667 3.3f, // page scale
645 3.3f, // page scale 668 1.f, // maximum animation scale
646 1.f, // maximum animation scale 669 false,
647 false); 670 &result_scale_x,
671 &result_scale_y,
672 &result_bounds);
648 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); 673 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings());
649 EXPECT_FLOAT_EQ(7.26f, 674 EXPECT_FLOAT_EQ(7.26f,
650 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 675 pending_layer_->tilings()->tiling_at(0)->contents_scale());
651 EXPECT_FLOAT_EQ(7.26f * low_res_factor, 676 EXPECT_FLOAT_EQ(7.26f * low_res_factor,
652 pending_layer_->tilings()->tiling_at(3)->contents_scale()); 677 pending_layer_->tilings()->tiling_at(3)->contents_scale());
653 } 678 }
654 679
655 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) { 680 TEST_F(PictureLayerImplTest, CreateTilingsEvenIfTwinHasNone) {
656 // This test makes sure that if a layer can have tilings, then a commit makes 681 // This test makes sure that if a layer can have tilings, then a commit makes
657 // it not able to have tilings (empty size), and then a future commit that 682 // it not able to have tilings (empty size), and then a future commit that
658 // makes it valid again should be able to create tilings. 683 // makes it valid again should be able to create tilings.
659 gfx::Size tile_size(400, 400); 684 gfx::Size tile_size(400, 400);
660 gfx::Size layer_bounds(1300, 1900); 685 gfx::Size layer_bounds(1300, 1900);
661 686
662 scoped_refptr<FakePicturePileImpl> empty_pile = 687 scoped_refptr<FakePicturePileImpl> empty_pile =
663 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); 688 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
664 scoped_refptr<FakePicturePileImpl> valid_pile = 689 scoped_refptr<FakePicturePileImpl> valid_pile =
665 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 690 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
666 691
667 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 692 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
668 EXPECT_LT(low_res_factor, 1.f); 693 EXPECT_LT(low_res_factor, 1.f);
669 694
670 float high_res_scale = 1.3f; 695 float high_res_scale = 1.3f;
671 float low_res_scale = high_res_scale * low_res_factor; 696 float low_res_scale = high_res_scale * low_res_factor;
672 float device_scale = 1.7f; 697 float device_scale = 1.7f;
673 float page_scale = 3.2f; 698 float page_scale = 3.2f;
674 float maximum_animation_scale = 1.f; 699 float maximum_animation_scale = 1.f;
700 float result_scale_x, result_scale_y;
701 gfx::Size result_bounds;
675 702
676 SetupPendingTree(valid_pile); 703 SetupPendingTree(valid_pile);
677 SetupDrawPropertiesAndManageTilings(pending_layer_, 704 pending_layer_->CalculateContentsScale(high_res_scale,
678 high_res_scale, 705 device_scale,
679 device_scale, 706 page_scale,
680 page_scale, 707 maximum_animation_scale,
681 maximum_animation_scale, 708 false,
682 false); 709 &result_scale_x,
710 &result_scale_y,
711 &result_bounds);
683 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 712 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
684 EXPECT_FLOAT_EQ(high_res_scale, 713 EXPECT_FLOAT_EQ(high_res_scale,
685 pending_layer_->HighResTiling()->contents_scale()); 714 pending_layer_->HighResTiling()->contents_scale());
686 EXPECT_FLOAT_EQ(low_res_scale, 715 EXPECT_FLOAT_EQ(low_res_scale,
687 pending_layer_->LowResTiling()->contents_scale()); 716 pending_layer_->LowResTiling()->contents_scale());
688 717
689 ActivateTree(); 718 ActivateTree();
690 SetupPendingTree(empty_pile); 719 SetupPendingTree(empty_pile);
691 SetupDrawPropertiesAndManageTilings(pending_layer_, 720 pending_layer_->CalculateContentsScale(high_res_scale,
692 high_res_scale, 721 device_scale,
693 device_scale, 722 page_scale,
694 page_scale, 723 maximum_animation_scale,
695 maximum_animation_scale, 724 false,
696 false); 725 &result_scale_x,
726 &result_scale_y,
727 &result_bounds);
697 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 728 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
698 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings()); 729 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
699 730
700 ActivateTree(); 731 ActivateTree();
701 SetupDrawPropertiesAndManageTilings(active_layer_, 732 active_layer_->CalculateContentsScale(high_res_scale,
702 high_res_scale, 733 device_scale,
703 device_scale, 734 page_scale,
704 page_scale, 735 maximum_animation_scale,
705 maximum_animation_scale, 736 false,
706 false); 737 &result_scale_x,
738 &result_scale_y,
739 &result_bounds);
707 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); 740 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
708 741
709 SetupPendingTree(valid_pile); 742 SetupPendingTree(valid_pile);
710 SetupDrawPropertiesAndManageTilings(pending_layer_, 743 pending_layer_->CalculateContentsScale(high_res_scale,
711 high_res_scale, 744 device_scale,
712 device_scale, 745 page_scale,
713 page_scale, 746 maximum_animation_scale,
714 maximum_animation_scale, 747 false,
715 false); 748 &result_scale_x,
749 &result_scale_y,
750 &result_bounds);
716 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 751 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
717 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings()); 752 ASSERT_EQ(0u, active_layer_->tilings()->num_tilings());
718 EXPECT_FLOAT_EQ(high_res_scale, 753 EXPECT_FLOAT_EQ(high_res_scale,
719 pending_layer_->HighResTiling()->contents_scale()); 754 pending_layer_->HighResTiling()->contents_scale());
720 EXPECT_FLOAT_EQ(low_res_scale, 755 EXPECT_FLOAT_EQ(low_res_scale,
721 pending_layer_->LowResTiling()->contents_scale()); 756 pending_layer_->LowResTiling()->contents_scale());
722 } 757 }
723 758
724 TEST_F(PictureLayerImplTest, ZoomOutCrash) { 759 TEST_F(PictureLayerImplTest, ZoomOutCrash) {
725 gfx::Size tile_size(400, 400); 760 gfx::Size tile_size(400, 400);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 874
840 TEST_F(PictureLayerImplTest, CleanUpTilings) { 875 TEST_F(PictureLayerImplTest, CleanUpTilings) {
841 gfx::Size tile_size(400, 400); 876 gfx::Size tile_size(400, 400);
842 gfx::Size layer_bounds(1300, 1900); 877 gfx::Size layer_bounds(1300, 1900);
843 878
844 scoped_refptr<FakePicturePileImpl> pending_pile = 879 scoped_refptr<FakePicturePileImpl> pending_pile =
845 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 880 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
846 scoped_refptr<FakePicturePileImpl> active_pile = 881 scoped_refptr<FakePicturePileImpl> active_pile =
847 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 882 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
848 883
884 float result_scale_x, result_scale_y;
885 gfx::Size result_bounds;
849 std::vector<PictureLayerTiling*> used_tilings; 886 std::vector<PictureLayerTiling*> used_tilings;
850 887
851 SetupTrees(pending_pile, active_pile); 888 SetupTrees(pending_pile, active_pile);
852 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 889 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
853 890
854 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 891 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
855 EXPECT_LT(low_res_factor, 1.f); 892 EXPECT_LT(low_res_factor, 1.f);
856 893
857 float device_scale = 1.7f; 894 float device_scale = 1.7f;
858 float page_scale = 3.2f; 895 float page_scale = 3.2f;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 // Now move the ideal scale to 1.0. Our target stays 1.2. 949 // Now move the ideal scale to 1.0. Our target stays 1.2.
913 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); 950 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false);
914 951
915 // All the tilings are between are target and the ideal, so they are not 952 // All the tilings are between are target and the ideal, so they are not
916 // removed. 953 // removed.
917 used_tilings.clear(); 954 used_tilings.clear();
918 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 955 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
919 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 956 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
920 957
921 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. 958 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
922 SetupDrawPropertiesAndManageTilings( 959 active_layer_->CalculateContentsScale(1.1f,
923 active_layer_, 1.1f, device_scale, page_scale, 1.f, false); 960 device_scale,
961 page_scale,
962 1.f,
963 false,
964 &result_scale_x,
965 &result_scale_y,
966 &result_bounds);
924 967
925 // Because the pending layer's ideal scale is still 1.0, our tilings fall 968 // Because the pending layer's ideal scale is still 1.0, our tilings fall
926 // in the range [1.0,1.2] and are kept. 969 // in the range [1.0,1.2] and are kept.
927 used_tilings.clear(); 970 used_tilings.clear();
928 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 971 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
929 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 972 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
930 973
931 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays 974 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
932 // 1.2 still. 975 // 1.2 still.
933 SetupDrawPropertiesAndManageTilings( 976 pending_layer_->CalculateContentsScale(1.1f,
934 pending_layer_, 1.1f, device_scale, page_scale, 1.f, false); 977 device_scale,
978 page_scale,
979 1.f,
980 false,
981 &result_scale_x,
982 &result_scale_y,
983 &result_bounds);
935 984
936 // Our 1.0 tiling now falls outside the range between our ideal scale and our 985 // Our 1.0 tiling now falls outside the range between our ideal scale and our
937 // target raster scale. But it is in our used tilings set, so nothing is 986 // target raster scale. But it is in our used tilings set, so nothing is
938 // deleted. 987 // deleted.
939 used_tilings.clear(); 988 used_tilings.clear();
940 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); 989 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
941 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 990 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
942 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 991 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
943 992
944 // If we remove it from our used tilings set, it is outside the range to keep 993 // If we remove it from our used tilings set, it is outside the range to keep
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 1127
1079 TEST_F(PictureLayerImplTest, ReleaseResources) { 1128 TEST_F(PictureLayerImplTest, ReleaseResources) {
1080 gfx::Size tile_size(400, 400); 1129 gfx::Size tile_size(400, 400);
1081 gfx::Size layer_bounds(1300, 1900); 1130 gfx::Size layer_bounds(1300, 1900);
1082 1131
1083 scoped_refptr<FakePicturePileImpl> pending_pile = 1132 scoped_refptr<FakePicturePileImpl> pending_pile =
1084 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1133 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1085 scoped_refptr<FakePicturePileImpl> active_pile = 1134 scoped_refptr<FakePicturePileImpl> active_pile =
1086 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1135 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1087 1136
1137 float result_scale_x, result_scale_y;
1138 gfx::Size result_bounds;
1139
1088 SetupTrees(pending_pile, active_pile); 1140 SetupTrees(pending_pile, active_pile);
1089 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1141 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1090 1142
1091 SetupDrawPropertiesAndManageTilings(pending_layer_, 1143 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale
1092 1.3f, // ideal contents scale 1144 2.7f, // device scale
1093 2.7f, // device scale 1145 3.2f, // page scale
1094 3.2f, // page scale 1146 1.f, // maximum animation scale
1095 1.f, // maximum animation scale 1147 false,
1096 false); 1148 &result_scale_x,
1149 &result_scale_y,
1150 &result_bounds);
1097 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1151 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1098 1152
1099 // All tilings should be removed when losing output surface. 1153 // All tilings should be removed when losing output surface.
1100 active_layer_->ReleaseResources(); 1154 active_layer_->ReleaseResources();
1101 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 1155 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1102 pending_layer_->ReleaseResources(); 1156 pending_layer_->ReleaseResources();
1103 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1157 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1104 1158
1105 // This should create new tilings. 1159 // This should create new tilings.
1106 SetupDrawPropertiesAndManageTilings(pending_layer_, 1160 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale
1107 1.3f, // ideal contents scale 1161 2.7f, // device scale
1108 2.7f, // device scale 1162 3.2f, // page scale
1109 3.2f, // page scale 1163 1.f, // maximum animation scale
1110 1.f, // maximum animation scale 1164 false,
1111 false); 1165 &result_scale_x,
1166 &result_scale_y,
1167 &result_bounds);
1112 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1168 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
1113 } 1169 }
1114 1170
1115 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) { 1171 TEST_F(PictureLayerImplTest, ClampTilesToToMaxTileSize) {
1116 // The default max tile size is larger than 400x400. 1172 // The default max tile size is larger than 400x400.
1117 gfx::Size tile_size(400, 400); 1173 gfx::Size tile_size(400, 400);
1118 gfx::Size layer_bounds(5000, 5000); 1174 gfx::Size layer_bounds(5000, 5000);
1119 1175
1120 scoped_refptr<FakePicturePileImpl> pending_pile = 1176 scoped_refptr<FakePicturePileImpl> pending_pile =
1121 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1177 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1122 scoped_refptr<FakePicturePileImpl> active_pile = 1178 scoped_refptr<FakePicturePileImpl> active_pile =
1123 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1179 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1124 1180
1181 float result_scale_x, result_scale_y;
1182 gfx::Size result_bounds;
1183
1125 SetupTrees(pending_pile, active_pile); 1184 SetupTrees(pending_pile, active_pile);
1126 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1185 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1127 1186
1128 SetupDrawPropertiesAndManageTilings( 1187 pending_layer_->CalculateContentsScale(1.f,
1129 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); 1188 1.f,
1189 1.f,
1190 1.f,
1191 false,
1192 &result_scale_x,
1193 &result_scale_y,
1194 &result_bounds);
1130 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1195 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1131 1196
1132 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1197 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1133 1198
1134 // The default value. 1199 // The default value.
1135 EXPECT_EQ(gfx::Size(256, 256).ToString(), 1200 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1136 host_impl_.settings().default_tile_size.ToString()); 1201 host_impl_.settings().default_tile_size.ToString());
1137 1202
1138 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; 1203 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1139 EXPECT_EQ(gfx::Size(256, 256).ToString(), 1204 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1140 tile->content_rect().size().ToString()); 1205 tile->content_rect().size().ToString());
1141 1206
1142 pending_layer_->ReleaseResources(); 1207 pending_layer_->ReleaseResources();
1143 1208
1144 // Change the max texture size on the output surface context. 1209 // Change the max texture size on the output surface context.
1145 scoped_ptr<TestWebGraphicsContext3D> context = 1210 scoped_ptr<TestWebGraphicsContext3D> context =
1146 TestWebGraphicsContext3D::Create(); 1211 TestWebGraphicsContext3D::Create();
1147 context->set_max_texture_size(140); 1212 context->set_max_texture_size(140);
1148 host_impl_.DidLoseOutputSurface(); 1213 host_impl_.DidLoseOutputSurface();
1149 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( 1214 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d(
1150 context.Pass()).PassAs<OutputSurface>()); 1215 context.Pass()).PassAs<OutputSurface>());
1151 1216
1152 SetupDrawPropertiesAndManageTilings( 1217 pending_layer_->CalculateContentsScale(1.f,
1153 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); 1218 1.f,
1219 1.f,
1220 1.f,
1221 false,
1222 &result_scale_x,
1223 &result_scale_y,
1224 &result_bounds);
1154 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1225 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1155 1226
1156 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1227 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1157 1228
1158 // Verify the tiles are not larger than the context's max texture size. 1229 // Verify the tiles are not larger than the context's max texture size.
1159 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; 1230 tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1160 EXPECT_GE(140, tile->content_rect().width()); 1231 EXPECT_GE(140, tile->content_rect().width());
1161 EXPECT_GE(140, tile->content_rect().height()); 1232 EXPECT_GE(140, tile->content_rect().height());
1162 } 1233 }
1163 1234
1164 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) { 1235 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) {
1165 // The default max tile size is larger than 400x400. 1236 // The default max tile size is larger than 400x400.
1166 gfx::Size tile_size(400, 400); 1237 gfx::Size tile_size(400, 400);
1167 gfx::Size layer_bounds(500, 500); 1238 gfx::Size layer_bounds(500, 500);
1168 1239
1169 scoped_refptr<FakePicturePileImpl> pending_pile = 1240 scoped_refptr<FakePicturePileImpl> pending_pile =
1170 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1241 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1171 scoped_refptr<FakePicturePileImpl> active_pile = 1242 scoped_refptr<FakePicturePileImpl> active_pile =
1172 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1243 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1173 1244
1245 float result_scale_x, result_scale_y;
1246 gfx::Size result_bounds;
1247
1174 SetupTrees(pending_pile, active_pile); 1248 SetupTrees(pending_pile, active_pile);
1175 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1249 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1176 1250
1177 SetupDrawPropertiesAndManageTilings( 1251 pending_layer_->CalculateContentsScale(1.f,
1178 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); 1252 1.f,
1253 1.f,
1254 1.f,
1255 false,
1256 &result_scale_x,
1257 &result_scale_y,
1258 &result_bounds);
1179 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings()); 1259 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings());
1180 1260
1181 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1261 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1182 1262
1183 // The default value. The layer is smaller than this. 1263 // The default value. The layer is smaller than this.
1184 EXPECT_EQ(gfx::Size(512, 512).ToString(), 1264 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1185 host_impl_.settings().max_untiled_layer_size.ToString()); 1265 host_impl_.settings().max_untiled_layer_size.ToString());
1186 1266
1187 // There should be a single tile since the layer is small. 1267 // There should be a single tile since the layer is small.
1188 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0); 1268 PictureLayerTiling* high_res_tiling = pending_layer_->tilings()->tiling_at(0);
1189 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size()); 1269 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size());
1190 1270
1191 pending_layer_->ReleaseResources(); 1271 pending_layer_->ReleaseResources();
1192 1272
1193 // Change the max texture size on the output surface context. 1273 // Change the max texture size on the output surface context.
1194 scoped_ptr<TestWebGraphicsContext3D> context = 1274 scoped_ptr<TestWebGraphicsContext3D> context =
1195 TestWebGraphicsContext3D::Create(); 1275 TestWebGraphicsContext3D::Create();
1196 context->set_max_texture_size(140); 1276 context->set_max_texture_size(140);
1197 host_impl_.DidLoseOutputSurface(); 1277 host_impl_.DidLoseOutputSurface();
1198 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d( 1278 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d(
1199 context.Pass()).PassAs<OutputSurface>()); 1279 context.Pass()).PassAs<OutputSurface>());
1200 1280
1201 SetupDrawPropertiesAndManageTilings( 1281 pending_layer_->CalculateContentsScale(1.f,
1202 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); 1282 1.f,
1283 1.f,
1284 1.f,
1285 false,
1286 &result_scale_x,
1287 &result_scale_y,
1288 &result_bounds);
1203 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings()); 1289 ASSERT_LE(1u, pending_layer_->tilings()->num_tilings());
1204 1290
1205 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1291 pending_layer_->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1206 1292
1207 // There should be more than one tile since the max texture size won't cover 1293 // There should be more than one tile since the max texture size won't cover
1208 // the layer. 1294 // the layer.
1209 high_res_tiling = pending_layer_->tilings()->tiling_at(0); 1295 high_res_tiling = pending_layer_->tilings()->tiling_at(0);
1210 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size()); 1296 EXPECT_LT(1u, high_res_tiling->AllTilesForTesting().size());
1211 1297
1212 // Verify the tiles are not larger than the context's max texture size. 1298 // Verify the tiles are not larger than the context's max texture size.
1213 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0]; 1299 Tile* tile = pending_layer_->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1214 EXPECT_GE(140, tile->content_rect().width()); 1300 EXPECT_GE(140, tile->content_rect().width());
1215 EXPECT_GE(140, tile->content_rect().height()); 1301 EXPECT_GE(140, tile->content_rect().height());
1216 } 1302 }
1217 1303
1218 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) { 1304 TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) {
1219 MockQuadCuller quad_culler; 1305 MockQuadCuller quad_culler;
1220 1306
1221 gfx::Size tile_size(400, 400); 1307 gfx::Size tile_size(400, 400);
1222 gfx::Size layer_bounds(1300, 1900); 1308 gfx::Size layer_bounds(1300, 1900);
1223 1309
1224 scoped_refptr<FakePicturePileImpl> pending_pile = 1310 scoped_refptr<FakePicturePileImpl> pending_pile =
1225 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1311 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1226 scoped_refptr<FakePicturePileImpl> active_pile = 1312 scoped_refptr<FakePicturePileImpl> active_pile =
1227 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1313 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1228 1314
1229 SetupTrees(pending_pile, active_pile); 1315 SetupTrees(pending_pile, active_pile);
1230 1316
1317 active_layer_->SetContentBounds(layer_bounds);
1231 active_layer_->draw_properties().visible_content_rect = 1318 active_layer_->draw_properties().visible_content_rect =
1232 gfx::Rect(layer_bounds); 1319 gfx::Rect(layer_bounds);
1233 1320
1234 gfx::Rect layer_invalidation(150, 200, 30, 180); 1321 gfx::Rect layer_invalidation(150, 200, 30, 180);
1235 Region invalidation(layer_invalidation); 1322 Region invalidation(layer_invalidation);
1236 AddDefaultTilingsWithInvalidation(invalidation); 1323 AddDefaultTilingsWithInvalidation(invalidation);
1237 1324
1238 AppendQuadsData data; 1325 AppendQuadsData data;
1239 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, NULL); 1326 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, NULL);
1240 active_layer_->AppendQuads(&quad_culler, &data); 1327 active_layer_->AppendQuads(&quad_culler, &data);
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 host_impl_.SetUseGpuRasterization(false); 1672 host_impl_.SetUseGpuRasterization(false);
1586 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1673 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1587 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 1674 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
1588 } 1675 }
1589 1676
1590 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) { 1677 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) {
1591 SetupDefaultTrees(gfx::Size(10, 10)); 1678 SetupDefaultTrees(gfx::Size(10, 10));
1592 host_impl_.active_tree()->UpdateDrawProperties(); 1679 host_impl_.active_tree()->UpdateDrawProperties();
1593 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties()); 1680 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties());
1594 1681
1595 SetupDrawPropertiesAndManageTilings( 1682 float result_scale_x;
1596 active_layer_, 0.5f, 0.5f, 0.5f, 0.5f, false); 1683 float result_scale_y;
1684 gfx::Size result_bounds;
1685 active_layer_->CalculateContentsScale(0.5f,
1686 0.5f,
1687 0.5f,
1688 0.5f,
1689 false,
1690 &result_scale_x,
1691 &result_scale_y,
1692 &result_bounds);
1597 active_layer_->tilings()->RemoveAllTilings(); 1693 active_layer_->tilings()->RemoveAllTilings();
1598 PictureLayerTiling* tiling = active_layer_->tilings()->AddTiling(0.5f); 1694 PictureLayerTiling* tiling = active_layer_->tilings()->AddTiling(0.5f);
1599 active_layer_->tilings()->AddTiling(1.5f); 1695 active_layer_->tilings()->AddTiling(1.5f);
1600 active_layer_->tilings()->AddTiling(0.25f); 1696 active_layer_->tilings()->AddTiling(0.25f);
1601 tiling->set_resolution(HIGH_RESOLUTION); 1697 tiling->set_resolution(HIGH_RESOLUTION);
1602 1698
1603 // Sanity checks. 1699 // Sanity checks.
1604 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 1700 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
1605 ASSERT_EQ(tiling, active_layer_->tilings()->TilingAtScale(0.5f)); 1701 ASSERT_EQ(tiling, active_layer_->tilings()->TilingAtScale(0.5f));
1606 1702
(...skipping 22 matching lines...) Expand all
1629 pending_layer_->tilings()->TilingAtScale(1.0f)->resolution()); 1725 pending_layer_->tilings()->TilingAtScale(1.0f)->resolution());
1630 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.5f)); 1726 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.5f));
1631 EXPECT_EQ(NON_IDEAL_RESOLUTION, 1727 EXPECT_EQ(NON_IDEAL_RESOLUTION,
1632 pending_layer_->tilings()->TilingAtScale(1.5f)->resolution()); 1728 pending_layer_->tilings()->TilingAtScale(1.5f)->resolution());
1633 } 1729 }
1634 1730
1635 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { 1731 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) {
1636 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); 1732 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
1637 gfx::Size layer_bounds(default_tile_size.width() * 4, 1733 gfx::Size layer_bounds(default_tile_size.width() * 4,
1638 default_tile_size.height() * 4); 1734 default_tile_size.height() * 4);
1735 float result_scale_x, result_scale_y;
1736 gfx::Size result_bounds;
1639 1737
1640 SetupDefaultTrees(layer_bounds); 1738 SetupDefaultTrees(layer_bounds);
1641 EXPECT_FALSE(host_impl_.use_gpu_rasterization()); 1739 EXPECT_FALSE(host_impl_.use_gpu_rasterization());
1642 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1740 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1643 SetupDrawPropertiesAndManageTilings( 1741 pending_layer_->CalculateContentsScale(1.f,
1644 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); 1742 1.f,
1743 1.f,
1744 1.f,
1745 false,
1746 &result_scale_x,
1747 &result_scale_y,
1748 &result_bounds);
1645 // Should have a low-res and a high-res tiling. 1749 // Should have a low-res and a high-res tiling.
1646 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1750 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1647 1751
1648 ResetTilingsAndRasterScales(); 1752 ResetTilingsAndRasterScales();
1649 1753
1650 host_impl_.SetUseGpuRasterization(true); 1754 host_impl_.SetUseGpuRasterization(true);
1651 EXPECT_TRUE(host_impl_.use_gpu_rasterization()); 1755 EXPECT_TRUE(host_impl_.use_gpu_rasterization());
1652 SetupDrawPropertiesAndManageTilings( 1756 pending_layer_->CalculateContentsScale(1.f,
1653 pending_layer_, 1.f, 1.f, 1.f, 1.f, false); 1757 1.f,
1654 1758 1.f,
1759 1.f,
1760 false,
1761 &result_scale_x,
1762 &result_scale_y,
1763 &result_bounds);
1655 // Should only have the high-res tiling. 1764 // Should only have the high-res tiling.
1656 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); 1765 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
1657 } 1766 }
1658 1767
1659 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { 1768 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) {
1660 // Set up layers with tilings. 1769 // Set up layers with tilings.
1661 SetupDefaultTrees(gfx::Size(10, 10)); 1770 SetupDefaultTrees(gfx::Size(10, 10));
1662 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false); 1771 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false);
1663 pending_layer_->PushPropertiesTo(active_layer_); 1772 pending_layer_->PushPropertiesTo(active_layer_);
1664 EXPECT_TRUE(pending_layer_->DrawsContent()); 1773 EXPECT_TRUE(pending_layer_->DrawsContent());
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
2270 2379
2271 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) { 2380 TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) {
2272 gfx::Size tile_size(400, 400); 2381 gfx::Size tile_size(400, 400);
2273 gfx::Size layer_bounds(1300, 1900); 2382 gfx::Size layer_bounds(1300, 1900);
2274 2383
2275 scoped_refptr<FakePicturePileImpl> pending_pile = 2384 scoped_refptr<FakePicturePileImpl> pending_pile =
2276 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2385 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2277 scoped_refptr<FakePicturePileImpl> active_pile = 2386 scoped_refptr<FakePicturePileImpl> active_pile =
2278 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2387 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2279 2388
2389 float result_scale_x, result_scale_y;
2390 gfx::Size result_bounds;
2391
2280 SetupTrees(pending_pile, active_pile); 2392 SetupTrees(pending_pile, active_pile);
2281 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2393 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2282 2394
2283 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 2395 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2284 EXPECT_LT(low_res_factor, 1.f); 2396 EXPECT_LT(low_res_factor, 1.f);
2285 2397
2286 SetupDrawPropertiesAndManageTilings(pending_layer_, 2398 pending_layer_->CalculateContentsScale(6.f, // ideal contents scale
2287 6.f, // ideal contents scale 2399 3.f, // device scale
2288 3.f, // device scale 2400 2.f, // page scale
2289 2.f, // page scale 2401 1.f, // maximum animation scale
2290 1.f, // maximum animation scale 2402 false,
2291 false); 2403 &result_scale_x,
2404 &result_scale_y,
2405 &result_bounds);
2292 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); 2406 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
2293 EXPECT_FLOAT_EQ(6.f, 2407 EXPECT_FLOAT_EQ(6.f,
2294 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 2408 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2295 2409
2296 // If we change the page scale factor, then we should get new tilings. 2410 // If we change the page scale factor, then we should get new tilings.
2297 SetupDrawPropertiesAndManageTilings(pending_layer_, 2411 pending_layer_->CalculateContentsScale(6.6f, // ideal contents scale
2298 6.6f, // ideal contents scale 2412 3.f, // device scale
2299 3.f, // device scale 2413 2.2f, // page scale
2300 2.2f, // page scale 2414 1.f, // maximum animation scale
2301 1.f, // maximum animation scale 2415 false,
2302 false); 2416 &result_scale_x,
2417 &result_scale_y,
2418 &result_bounds);
2303 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 2419 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
2304 EXPECT_FLOAT_EQ(6.6f, 2420 EXPECT_FLOAT_EQ(6.6f,
2305 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 2421 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2306 2422
2307 // If we change the device scale factor, then we should get new tilings. 2423 // If we change the device scale factor, then we should get new tilings.
2308 SetupDrawPropertiesAndManageTilings(pending_layer_, 2424 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale
2309 7.26f, // ideal contents scale 2425 3.3f, // device scale
2310 3.3f, // device scale 2426 2.2f, // page scale
2311 2.2f, // page scale 2427 1.f, // maximum animation scale
2312 1.f, // maximum animation scale 2428 false,
2313 false); 2429 &result_scale_x,
2430 &result_scale_y,
2431 &result_bounds);
2314 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); 2432 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings());
2315 EXPECT_FLOAT_EQ(7.26f, 2433 EXPECT_FLOAT_EQ(7.26f,
2316 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 2434 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2317 2435
2318 // If we change the device scale factor, but end up at the same total scale 2436 // If we change the device scale factor, but end up at the same total scale
2319 // factor somehow, then we don't get new tilings. 2437 // factor somehow, then we don't get new tilings.
2320 SetupDrawPropertiesAndManageTilings(pending_layer_, 2438 pending_layer_->CalculateContentsScale(7.26f, // ideal contents scale
2321 7.26f, // ideal contents scale 2439 2.2f, // device scale
2322 2.2f, // device scale 2440 3.3f, // page scale
2323 3.3f, // page scale 2441 1.f, // maximum animation scale
2324 1.f, // maximum animation scale 2442 false,
2325 false); 2443 &result_scale_x,
2444 &result_scale_y,
2445 &result_bounds);
2326 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); 2446 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings());
2327 EXPECT_FLOAT_EQ(7.26f, 2447 EXPECT_FLOAT_EQ(7.26f,
2328 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 2448 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2329 } 2449 }
2330 2450
2331 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredNullTiles) { 2451 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredNullTiles) {
2332 gfx::Size tile_size(100, 100); 2452 gfx::Size tile_size(100, 100);
2333 gfx::Size layer_bounds(1000, 1000); 2453 gfx::Size layer_bounds(1000, 1000);
2334 2454
2335 scoped_refptr<FakePicturePileImpl> pending_pile = 2455 scoped_refptr<FakePicturePileImpl> pending_pile =
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 2530
2411 scoped_refptr<FakePicturePileImpl> pending_pile = 2531 scoped_refptr<FakePicturePileImpl> pending_pile =
2412 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2532 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2413 scoped_refptr<FakePicturePileImpl> active_pile = 2533 scoped_refptr<FakePicturePileImpl> active_pile =
2414 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2534 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2415 2535
2416 SetupTrees(pending_pile, active_pile); 2536 SetupTrees(pending_pile, active_pile);
2417 2537
2418 Region invalidation; 2538 Region invalidation;
2419 AddDefaultTilingsWithInvalidation(invalidation); 2539 AddDefaultTilingsWithInvalidation(invalidation);
2420 SetupDrawPropertiesAndManageTilings(active_layer_, 1.f, 1.f, 1.f, 1.f, false); 2540 float dummy_contents_scale_x;
2541 float dummy_contents_scale_y;
2542 gfx::Size dummy_content_bounds;
2543 active_layer_->CalculateContentsScale(1.f,
2544 1.f,
2545 1.f,
2546 1.f,
2547 false,
2548 &dummy_contents_scale_x,
2549 &dummy_contents_scale_y,
2550 &dummy_content_bounds);
2421 2551
2422 // UpdateTilePriorities with valid viewport. Should update tile viewport. 2552 // UpdateTilePriorities with valid viewport. Should update tile viewport.
2423 bool valid_for_tile_management = true; 2553 bool valid_for_tile_management = true;
2424 gfx::Rect viewport = gfx::Rect(layer_bounds); 2554 gfx::Rect viewport = gfx::Rect(layer_bounds);
2425 gfx::Transform transform; 2555 gfx::Transform transform;
2426 host_impl_.SetExternalDrawConstraints( 2556 host_impl_.SetExternalDrawConstraints(
2427 transform, viewport, viewport, valid_for_tile_management); 2557 transform, viewport, viewport, valid_for_tile_management);
2428 active_layer_->draw_properties().visible_content_rect = viewport; 2558 active_layer_->draw_properties().visible_content_rect = viewport;
2429 active_layer_->draw_properties().screen_space_transform = transform; 2559 active_layer_->draw_properties().screen_space_transform = transform;
2430 active_layer_->UpdateTilePriorities(); 2560 active_layer_->UpdateTilePriorities();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2509 2639
2510 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) { 2640 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) {
2511 gfx::Size tile_size(400, 400); 2641 gfx::Size tile_size(400, 400);
2512 gfx::Size layer_bounds(1300, 1900); 2642 gfx::Size layer_bounds(1300, 1900);
2513 2643
2514 scoped_refptr<FakePicturePileImpl> pending_pile = 2644 scoped_refptr<FakePicturePileImpl> pending_pile =
2515 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2645 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2516 scoped_refptr<FakePicturePileImpl> active_pile = 2646 scoped_refptr<FakePicturePileImpl> active_pile =
2517 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2647 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2518 2648
2649 float result_scale_x, result_scale_y;
2650 gfx::Size result_bounds;
2519 std::vector<PictureLayerTiling*> used_tilings; 2651 std::vector<PictureLayerTiling*> used_tilings;
2520 2652
2521 SetupTrees(pending_pile, active_pile); 2653 SetupTrees(pending_pile, active_pile);
2522 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2654 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2523 2655
2524 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 2656 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2525 EXPECT_LT(low_res_factor, 1.f); 2657 EXPECT_LT(low_res_factor, 1.f);
2526 2658
2527 float device_scale = 1.7f; 2659 float device_scale = 1.7f;
2528 float page_scale = 3.2f; 2660 float page_scale = 3.2f;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2577 // Now move the ideal scale to 1.0. Our target stays 1.2. 2709 // Now move the ideal scale to 1.0. Our target stays 1.2.
2578 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); 2710 SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false);
2579 2711
2580 // All the tilings are between are target and the ideal, so they are not 2712 // All the tilings are between are target and the ideal, so they are not
2581 // removed. 2713 // removed.
2582 used_tilings.clear(); 2714 used_tilings.clear();
2583 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 2715 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2584 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 2716 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2585 2717
2586 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. 2718 // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2.
2587 SetupDrawPropertiesAndManageTilings( 2719 active_layer_->CalculateContentsScale(1.1f,
2588 active_layer_, 1.1f, device_scale, page_scale, 1.f, false); 2720 device_scale,
2721 page_scale,
2722 1.f,
2723 false,
2724 &result_scale_x,
2725 &result_scale_y,
2726 &result_bounds);
2589 2727
2590 // Because the pending layer's ideal scale is still 1.0, our tilings fall 2728 // Because the pending layer's ideal scale is still 1.0, our tilings fall
2591 // in the range [1.0,1.2] and are kept. 2729 // in the range [1.0,1.2] and are kept.
2592 used_tilings.clear(); 2730 used_tilings.clear();
2593 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 2731 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2594 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 2732 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2595 2733
2596 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays 2734 // Move the ideal scale on the pending layer to 1.1 as well. Our target stays
2597 // 1.2 still. 2735 // 1.2 still.
2598 SetupDrawPropertiesAndManageTilings( 2736 pending_layer_->CalculateContentsScale(1.1f,
2599 pending_layer_, 1.1f, device_scale, page_scale, 1.f, false); 2737 device_scale,
2738 page_scale,
2739 1.f,
2740 false,
2741 &result_scale_x,
2742 &result_scale_y,
2743 &result_bounds);
2600 2744
2601 // Our 1.0 tiling now falls outside the range between our ideal scale and our 2745 // Our 1.0 tiling now falls outside the range between our ideal scale and our
2602 // target raster scale. But it is in our used tilings set, so nothing is 2746 // target raster scale. But it is in our used tilings set, so nothing is
2603 // deleted. 2747 // deleted.
2604 used_tilings.clear(); 2748 used_tilings.clear();
2605 used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); 2749 used_tilings.push_back(active_layer_->tilings()->tiling_at(1));
2606 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 2750 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2607 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 2751 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
2608 2752
2609 // If we remove it from our used tilings set, it is outside the range to keep 2753 // If we remove it from our used tilings set, it is outside the range to keep
2610 // so it is deleted. 2754 // so it is deleted.
2611 used_tilings.clear(); 2755 used_tilings.clear();
2612 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 2756 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
2613 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); 2757 ASSERT_EQ(1u, active_layer_->tilings()->num_tilings());
2614 } 2758 }
2615 2759
2616 TEST_F(PictureLayerImplTest, ScaleCollision) { 2760 TEST_F(PictureLayerImplTest, ScaleCollision) {
2617 gfx::Size tile_size(400, 400); 2761 gfx::Size tile_size(400, 400);
2618 gfx::Size layer_bounds(1300, 1900); 2762 gfx::Size layer_bounds(1300, 1900);
2619 2763
2620 scoped_refptr<FakePicturePileImpl> pending_pile = 2764 scoped_refptr<FakePicturePileImpl> pending_pile =
2621 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2765 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2622 scoped_refptr<FakePicturePileImpl> active_pile = 2766 scoped_refptr<FakePicturePileImpl> active_pile =
2623 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2767 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2624 2768
2769 float result_scale_x, result_scale_y;
2770 gfx::Size result_bounds;
2625 std::vector<PictureLayerTiling*> used_tilings; 2771 std::vector<PictureLayerTiling*> used_tilings;
2626 2772
2627 SetupTrees(pending_pile, active_pile); 2773 SetupTrees(pending_pile, active_pile);
2628 2774
2629 float pending_contents_scale = 1.f; 2775 float pending_contents_scale = 1.f;
2630 float active_contents_scale = 2.f; 2776 float active_contents_scale = 2.f;
2631 float device_scale_factor = 1.f; 2777 float device_scale_factor = 1.f;
2632 float page_scale_factor = 1.f; 2778 float page_scale_factor = 1.f;
2633 float maximum_animation_contents_scale = 1.f; 2779 float maximum_animation_contents_scale = 1.f;
2634 bool animating_transform = false; 2780 bool animating_transform = false;
2635 2781
2636 EXPECT_TRUE(host_impl_.settings().create_low_res_tiling); 2782 EXPECT_TRUE(host_impl_.settings().create_low_res_tiling);
2637 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 2783 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
2638 EXPECT_LT(low_res_factor, 1.f); 2784 EXPECT_LT(low_res_factor, 1.f);
2639 2785
2640 SetupDrawPropertiesAndManageTilings(pending_layer_, 2786 pending_layer_->CalculateContentsScale(pending_contents_scale,
2641 pending_contents_scale, 2787 device_scale_factor,
2642 device_scale_factor, 2788 page_scale_factor,
2643 page_scale_factor, 2789 maximum_animation_contents_scale,
2644 maximum_animation_contents_scale, 2790 animating_transform,
2645 animating_transform); 2791 &result_scale_x,
2646 SetupDrawPropertiesAndManageTilings(active_layer_, 2792 &result_scale_y,
2647 active_contents_scale, 2793 &result_bounds);
2648 device_scale_factor, 2794 active_layer_->CalculateContentsScale(active_contents_scale,
2649 page_scale_factor, 2795 device_scale_factor,
2650 maximum_animation_contents_scale, 2796 page_scale_factor,
2651 animating_transform); 2797 maximum_animation_contents_scale,
2798 animating_transform,
2799 &result_scale_x,
2800 &result_scale_y,
2801 &result_bounds);
2652 2802
2653 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings()); 2803 ASSERT_EQ(4u, pending_layer_->tilings()->num_tilings());
2654 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings()); 2804 ASSERT_EQ(4u, active_layer_->tilings()->num_tilings());
2655 2805
2656 EXPECT_EQ(active_contents_scale, 2806 EXPECT_EQ(active_contents_scale,
2657 pending_layer_->tilings()->tiling_at(0)->contents_scale()); 2807 pending_layer_->tilings()->tiling_at(0)->contents_scale());
2658 EXPECT_EQ(pending_contents_scale, 2808 EXPECT_EQ(pending_contents_scale,
2659 pending_layer_->tilings()->tiling_at(1)->contents_scale()); 2809 pending_layer_->tilings()->tiling_at(1)->contents_scale());
2660 EXPECT_EQ(active_contents_scale * low_res_factor, 2810 EXPECT_EQ(active_contents_scale * low_res_factor,
2661 pending_layer_->tilings()->tiling_at(2)->contents_scale()); 2811 pending_layer_->tilings()->tiling_at(2)->contents_scale());
(...skipping 27 matching lines...) Expand all
2689 2839
2690 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) { 2840 TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) {
2691 gfx::Size tile_size(400, 400); 2841 gfx::Size tile_size(400, 400);
2692 gfx::Size layer_bounds(1300, 1900); 2842 gfx::Size layer_bounds(1300, 1900);
2693 2843
2694 scoped_refptr<FakePicturePileImpl> pending_pile = 2844 scoped_refptr<FakePicturePileImpl> pending_pile =
2695 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2845 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2696 scoped_refptr<FakePicturePileImpl> active_pile = 2846 scoped_refptr<FakePicturePileImpl> active_pile =
2697 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 2847 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2698 2848
2849 float result_scale_x, result_scale_y;
2850 gfx::Size result_bounds;
2851
2699 SetupTrees(pending_pile, active_pile); 2852 SetupTrees(pending_pile, active_pile);
2700 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2853 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2701 2854
2702 SetupDrawPropertiesAndManageTilings(pending_layer_, 2855 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale
2703 1.3f, // ideal contents scale 2856 2.7f, // device scale
2704 2.7f, // device scale 2857 3.2f, // page scale
2705 3.2f, // page scale 2858 1.f, // maximum animation scale
2706 1.f, // maximum animation scale 2859 false,
2707 false); 2860 &result_scale_x,
2861 &result_scale_y,
2862 &result_bounds);
2708 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); 2863 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2709 2864
2710 // All tilings should be removed when losing output surface. 2865 // All tilings should be removed when losing output surface.
2711 active_layer_->ReleaseResources(); 2866 active_layer_->ReleaseResources();
2712 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 2867 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2713 pending_layer_->ReleaseResources(); 2868 pending_layer_->ReleaseResources();
2714 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2869 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
2715 2870
2716 // This should create new tilings. 2871 // This should create new tilings.
2717 SetupDrawPropertiesAndManageTilings(pending_layer_, 2872 pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale
2718 1.3f, // ideal contents scale 2873 2.7f, // device scale
2719 2.7f, // device scale 2874 3.2f, // page scale
2720 3.2f, // page scale 2875 1.f, // maximum animation scale
2721 1.f, // maximum animation scale 2876 false,
2722 false); 2877 &result_scale_x,
2878 &result_scale_y,
2879 &result_bounds);
2723 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); 2880 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
2724 } 2881 }
2725 2882
2726 TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) {
2727 MockQuadCuller quad_culler;
2728
2729 gfx::Size tile_size(400, 400);
2730 gfx::Size layer_bounds(1000, 2000);
2731
2732 scoped_refptr<FakePicturePileImpl> pending_pile =
2733 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2734 scoped_refptr<FakePicturePileImpl> active_pile =
2735 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2736
2737 SetupTrees(pending_pile, active_pile);
2738
2739 SetupDrawPropertiesAndManageTilings(
2740 pending_layer_, 2.5f, 1.f, 1.f, 1.f, false);
2741 host_impl_.pending_tree()->UpdateDrawProperties();
2742
2743 active_layer_->draw_properties().visible_content_rect =
2744 gfx::Rect(layer_bounds);
2745 host_impl_.active_tree()->UpdateDrawProperties();
2746
2747 float max_contents_scale = active_layer_->MaximumTilingContentsScale();
2748 gfx::Transform scaled_draw_transform = active_layer_->draw_transform();
2749 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale,
2750 SK_MScalar1 / max_contents_scale);
2751
2752 AppendQuadsData data;
2753 active_layer_->AppendQuads(&quad_culler, &data);
2754
2755 // SharedQuadState should have be of size 1, as we are doing AppenQuad once.
2756 EXPECT_EQ(1u, quad_culler.shared_quad_state_list().size());
2757 // The content_to_target_transform should be scaled by the
2758 // MaximumTilingContentsScale on the layer.
2759 EXPECT_EQ(scaled_draw_transform.ToString(),
2760 quad_culler.shared_quad_state_list()[0]
2761 ->content_to_target_transform.ToString());
2762 // The content_bounds should be scaled by the
2763 // MaximumTilingContentsScale on the layer.
2764 EXPECT_EQ(gfx::Size(2500u, 5000u).ToString(),
2765 quad_culler.shared_quad_state_list()[0]->content_bounds.ToString());
2766 // The visible_content_rect should be scaled by the
2767 // MaximumTilingContentsScale on the layer.
2768 EXPECT_EQ(
2769 gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
2770 quad_culler.shared_quad_state_list()[0]->visible_content_rect.ToString());
2771 }
2772
2773 } // namespace 2883 } // namespace
2774 } // namespace cc 2884 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/resources/picture_layer_tiling_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698