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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "cc/layers/append_quads_data.h" | 9 #include "cc/layers/append_quads_data.h" |
10 #include "cc/layers/picture_layer.h" | 10 #include "cc/layers/picture_layer.h" |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 &result_bounds); | 584 &result_bounds); |
585 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); | 585 ASSERT_EQ(6u, pending_layer_->tilings()->num_tilings()); |
586 EXPECT_FLOAT_EQ( | 586 EXPECT_FLOAT_EQ( |
587 1.9f, | 587 1.9f, |
588 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | 588 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
589 EXPECT_FLOAT_EQ( | 589 EXPECT_FLOAT_EQ( |
590 1.9f * low_res_factor, | 590 1.9f * low_res_factor, |
591 pending_layer_->tilings()->tiling_at(3)->contents_scale()); | 591 pending_layer_->tilings()->tiling_at(3)->contents_scale()); |
592 } | 592 } |
593 | 593 |
| 594 TEST_F(PictureLayerImplTest, ZoomOutCrash) { |
| 595 gfx::Size tile_size(400, 400); |
| 596 gfx::Size layer_bounds(1300, 1900); |
| 597 |
| 598 // Set up the high and low res tilings before pinch zoom. |
| 599 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 600 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 601 scoped_refptr<FakePicturePileImpl> active_pile = |
| 602 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 603 |
| 604 SetupTrees(pending_pile, active_pile); |
| 605 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
| 606 SetContentsScaleOnBothLayers(32.0f, 1.0f, 32.0f, false); |
| 607 host_impl_.PinchGestureBegin(); |
| 608 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, false); |
| 609 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, false); |
| 610 EXPECT_EQ(active_layer_->tilings()->NumHighResTilings(), 1); |
| 611 } |
| 612 |
| 613 TEST_F(PictureLayerImplTest, PinchGestureTilings) { |
| 614 gfx::Size tile_size(400, 400); |
| 615 gfx::Size layer_bounds(1300, 1900); |
| 616 |
| 617 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 618 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 619 scoped_refptr<FakePicturePileImpl> active_pile = |
| 620 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 621 |
| 622 // Set up the high and low res tilings before pinch zoom. |
| 623 SetupTrees(pending_pile, active_pile); |
| 624 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
| 625 SetContentsScaleOnBothLayers(1.0f, 1.0f, 1.0f, false); |
| 626 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
| 627 EXPECT_EQ(2u, active_layer_->tilings()->num_tilings()); |
| 628 EXPECT_FLOAT_EQ( |
| 629 1.0f, |
| 630 active_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 631 EXPECT_FLOAT_EQ( |
| 632 1.0f * low_res_factor, |
| 633 active_layer_->tilings()->tiling_at(1)->contents_scale()); |
| 634 |
| 635 // Start a pinch gesture. |
| 636 host_impl_.PinchGestureBegin(); |
| 637 |
| 638 // Zoom out by a small amount. We should create a tiling at half |
| 639 // the scale (1/kMaxScaleRatioDuringPinch). |
| 640 SetContentsScaleOnBothLayers(0.90f, 1.0f, 0.9f, false); |
| 641 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings()); |
| 642 EXPECT_FLOAT_EQ( |
| 643 1.0f, |
| 644 active_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 645 EXPECT_FLOAT_EQ( |
| 646 0.5f, |
| 647 active_layer_->tilings()->tiling_at(1)->contents_scale()); |
| 648 EXPECT_FLOAT_EQ( |
| 649 1.0f * low_res_factor, |
| 650 active_layer_->tilings()->tiling_at(2)->contents_scale()); |
| 651 |
| 652 // Zoom out further, close to our old low-res scale factor. We should |
| 653 // use that tiling as high-res, and not create a new tiling. |
| 654 SetContentsScaleOnBothLayers(low_res_factor, 1.0f, low_res_factor, false); |
| 655 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings()); |
| 656 |
| 657 // Zoom in a lot now. Since we increase by increments of |
| 658 // kMaxScaleRatioDuringPinch, this will first use 0.5, then 1.0 |
| 659 // and then finally create a new tiling at 2.0. |
| 660 SetContentsScaleOnBothLayers(2.1f, 1.0f, 2.1f, false); |
| 661 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings()); |
| 662 SetContentsScaleOnBothLayers(2.1f, 1.0f, 2.1f, false); |
| 663 EXPECT_EQ(3u, active_layer_->tilings()->num_tilings()); |
| 664 SetContentsScaleOnBothLayers(2.1f, 1.0f, 2.1f, false); |
| 665 EXPECT_EQ(4u, active_layer_->tilings()->num_tilings()); |
| 666 EXPECT_FLOAT_EQ( |
| 667 2.0f, |
| 668 active_layer_->tilings()->tiling_at(0)->contents_scale()); |
| 669 } |
| 670 |
594 TEST_F(PictureLayerImplTest, CleanUpTilings) { | 671 TEST_F(PictureLayerImplTest, CleanUpTilings) { |
595 gfx::Size tile_size(400, 400); | 672 gfx::Size tile_size(400, 400); |
596 gfx::Size layer_bounds(1300, 1900); | 673 gfx::Size layer_bounds(1300, 1900); |
597 | 674 |
598 scoped_refptr<FakePicturePileImpl> pending_pile = | 675 scoped_refptr<FakePicturePileImpl> pending_pile = |
599 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 676 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
600 scoped_refptr<FakePicturePileImpl> active_pile = | 677 scoped_refptr<FakePicturePileImpl> active_pile = |
601 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 678 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
602 | 679 |
603 float result_scale_x, result_scale_y; | 680 float result_scale_x, result_scale_y; |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 TestContextProvider::Create(), NULL)); | 1262 TestContextProvider::Create(), NULL)); |
1186 | 1263 |
1187 // These will crash PictureLayerImpl if this is not true. | 1264 // These will crash PictureLayerImpl if this is not true. |
1188 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); | 1265 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); |
1189 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); | 1266 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); |
1190 host_impl_.active_tree()->UpdateDrawProperties(); | 1267 host_impl_.active_tree()->UpdateDrawProperties(); |
1191 } | 1268 } |
1192 | 1269 |
1193 } // namespace | 1270 } // namespace |
1194 } // namespace cc | 1271 } // namespace cc |
OLD | NEW |