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