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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 2123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 scoped_refptr<FakeRasterSource> pending_raster_source = | 2134 scoped_refptr<FakeRasterSource> pending_raster_source = |
2135 FakeRasterSource::CreateFilled(layer_bounds); | 2135 FakeRasterSource::CreateFilled(layer_bounds); |
2136 | 2136 |
2137 host_impl()->CreatePendingTree(); | 2137 host_impl()->CreatePendingTree(); |
2138 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); | 2138 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); |
2139 | 2139 |
2140 std::unique_ptr<FakePictureLayerImpl> pending_layer = | 2140 std::unique_ptr<FakePictureLayerImpl> pending_layer = |
2141 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, layer_id(), | 2141 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, layer_id(), |
2142 pending_raster_source); | 2142 pending_raster_source); |
2143 pending_layer->SetDrawsContent(true); | 2143 pending_layer->SetDrawsContent(true); |
2144 pending_tree->SetRootLayer(std::move(pending_layer)); | 2144 pending_tree->SetRootLayerForTesting(std::move(pending_layer)); |
2145 pending_tree->BuildLayerListForTesting(); | 2145 pending_tree->BuildLayerListForTesting(); |
2146 | 2146 |
2147 FakePictureLayerImpl* raw_pending_layer = static_cast<FakePictureLayerImpl*>( | 2147 FakePictureLayerImpl* raw_pending_layer = static_cast<FakePictureLayerImpl*>( |
2148 host_impl()->pending_tree()->LayerById(layer_id())); | 2148 host_impl()->pending_tree()->LayerById(layer_id())); |
2149 | 2149 |
2150 // Set some state on the pending layer, make sure it is not clobbered | 2150 // Set some state on the pending layer, make sure it is not clobbered |
2151 // by a sync from the active layer. This could happen because if the | 2151 // by a sync from the active layer. This could happen because if the |
2152 // pending layer has not been post-commit initialized it will attempt | 2152 // pending layer has not been post-commit initialized it will attempt |
2153 // to sync from the active layer. | 2153 // to sync from the active layer. |
2154 float raster_page_scale = 10.f * raw_pending_layer->raster_page_scale(); | 2154 float raster_page_scale = 10.f * raw_pending_layer->raster_page_scale(); |
(...skipping 2714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4869 | 4869 |
4870 host_impl()->CreatePendingTree(); | 4870 host_impl()->CreatePendingTree(); |
4871 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); | 4871 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); |
4872 | 4872 |
4873 std::unique_ptr<FakePictureLayerImpl> pending_layer = | 4873 std::unique_ptr<FakePictureLayerImpl> pending_layer = |
4874 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, layer_id(), | 4874 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, layer_id(), |
4875 pending_raster_source); | 4875 pending_raster_source); |
4876 pending_layer->set_is_directly_composited_image(true); | 4876 pending_layer->set_is_directly_composited_image(true); |
4877 pending_layer->SetDrawsContent(true); | 4877 pending_layer->SetDrawsContent(true); |
4878 FakePictureLayerImpl* pending_layer_ptr = pending_layer.get(); | 4878 FakePictureLayerImpl* pending_layer_ptr = pending_layer.get(); |
4879 pending_tree->SetRootLayer(std::move(pending_layer)); | 4879 pending_tree->SetRootLayerForTesting(std::move(pending_layer)); |
4880 pending_tree->BuildLayerListAndPropertyTreesForTesting(); | 4880 pending_tree->BuildLayerListAndPropertyTreesForTesting(); |
4881 | 4881 |
4882 SetupDrawPropertiesAndUpdateTiles(pending_layer_ptr, 2.f, 3.f, 4.f, 1.f, 1.f, | 4882 SetupDrawPropertiesAndUpdateTiles(pending_layer_ptr, 2.f, 3.f, 4.f, 1.f, 1.f, |
4883 false); | 4883 false); |
4884 EXPECT_FLOAT_EQ(1.f, pending_layer_ptr->MaximumTilingContentsScale()); | 4884 EXPECT_FLOAT_EQ(1.f, pending_layer_ptr->MaximumTilingContentsScale()); |
4885 } | 4885 } |
4886 | 4886 |
4887 TEST_F(PictureLayerImplTest, CompositedImageIgnoreIdealContentsScale) { | 4887 TEST_F(PictureLayerImplTest, CompositedImageIgnoreIdealContentsScale) { |
4888 gfx::Size layer_bounds(400, 400); | 4888 gfx::Size layer_bounds(400, 400); |
4889 scoped_refptr<FakeRasterSource> pending_raster_source = | 4889 scoped_refptr<FakeRasterSource> pending_raster_source = |
4890 FakeRasterSource::CreateFilled(layer_bounds); | 4890 FakeRasterSource::CreateFilled(layer_bounds); |
4891 | 4891 |
4892 host_impl()->SetViewportSize(layer_bounds); | 4892 host_impl()->SetViewportSize(layer_bounds); |
4893 host_impl()->CreatePendingTree(); | 4893 host_impl()->CreatePendingTree(); |
4894 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); | 4894 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); |
4895 | 4895 |
4896 std::unique_ptr<FakePictureLayerImpl> pending_layer = | 4896 std::unique_ptr<FakePictureLayerImpl> pending_layer = |
4897 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, layer_id(), | 4897 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, layer_id(), |
4898 pending_raster_source); | 4898 pending_raster_source); |
4899 pending_layer->set_is_directly_composited_image(true); | 4899 pending_layer->set_is_directly_composited_image(true); |
4900 pending_layer->SetDrawsContent(true); | 4900 pending_layer->SetDrawsContent(true); |
4901 FakePictureLayerImpl* pending_layer_ptr = pending_layer.get(); | 4901 FakePictureLayerImpl* pending_layer_ptr = pending_layer.get(); |
4902 pending_tree->SetRootLayer(std::move(pending_layer)); | 4902 pending_tree->SetRootLayerForTesting(std::move(pending_layer)); |
4903 pending_tree->BuildLayerListAndPropertyTreesForTesting(); | 4903 pending_tree->BuildLayerListAndPropertyTreesForTesting(); |
4904 | 4904 |
4905 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f. | 4905 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f. |
4906 const float suggested_ideal_contents_scale = 2.f; | 4906 const float suggested_ideal_contents_scale = 2.f; |
4907 const float device_scale_factor = 3.f; | 4907 const float device_scale_factor = 3.f; |
4908 const float page_scale_factor = 4.f; | 4908 const float page_scale_factor = 4.f; |
4909 const float animation_contents_scale = 1.f; | 4909 const float animation_contents_scale = 1.f; |
4910 const bool animating_transform_to_screen = false; | 4910 const bool animating_transform_to_screen = false; |
4911 SetupDrawPropertiesAndUpdateTiles( | 4911 SetupDrawPropertiesAndUpdateTiles( |
4912 pending_layer_ptr, suggested_ideal_contents_scale, device_scale_factor, | 4912 pending_layer_ptr, suggested_ideal_contents_scale, device_scale_factor, |
4913 page_scale_factor, animation_contents_scale, animation_contents_scale, | 4913 page_scale_factor, animation_contents_scale, animation_contents_scale, |
4914 animating_transform_to_screen); | 4914 animating_transform_to_screen); |
4915 EXPECT_EQ(1.f, pending_layer_ptr->tilings()->tiling_at(0)->contents_scale()); | 4915 EXPECT_EQ(1.f, pending_layer_ptr->tilings()->tiling_at(0)->contents_scale()); |
4916 | 4916 |
4917 // Push to active layer. | 4917 // Push to active layer. |
4918 host_impl()->ActivateSyncTree(); | 4918 host_impl()->ActivateSyncTree(); |
4919 | 4919 |
4920 FakePictureLayerImpl* active_layer = static_cast<FakePictureLayerImpl*>( | 4920 FakePictureLayerImpl* active_layer = static_cast<FakePictureLayerImpl*>( |
4921 host_impl()->active_tree()->root_layer()); | 4921 host_impl()->active_tree()->root_layer_for_testing()); |
4922 SetupDrawPropertiesAndUpdateTiles( | 4922 SetupDrawPropertiesAndUpdateTiles( |
4923 active_layer, suggested_ideal_contents_scale, device_scale_factor, | 4923 active_layer, suggested_ideal_contents_scale, device_scale_factor, |
4924 page_scale_factor, animation_contents_scale, animation_contents_scale, | 4924 page_scale_factor, animation_contents_scale, animation_contents_scale, |
4925 animating_transform_to_screen); | 4925 animating_transform_to_screen); |
4926 EXPECT_EQ(1.f, active_layer->tilings()->tiling_at(0)->contents_scale()); | 4926 EXPECT_EQ(1.f, active_layer->tilings()->tiling_at(0)->contents_scale()); |
4927 active_layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | 4927 active_layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
4928 | 4928 |
4929 // Create resources for the tiles. | 4929 // Create resources for the tiles. |
4930 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( | 4930 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( |
4931 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); | 4931 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); |
(...skipping 19 matching lines...) Expand all Loading... |
4951 | 4951 |
4952 host_impl()->CreatePendingTree(); | 4952 host_impl()->CreatePendingTree(); |
4953 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); | 4953 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); |
4954 | 4954 |
4955 std::unique_ptr<FakePictureLayerImpl> pending_layer = | 4955 std::unique_ptr<FakePictureLayerImpl> pending_layer = |
4956 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, layer_id(), | 4956 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, layer_id(), |
4957 pending_raster_source); | 4957 pending_raster_source); |
4958 pending_layer->set_is_directly_composited_image(true); | 4958 pending_layer->set_is_directly_composited_image(true); |
4959 pending_layer->SetDrawsContent(true); | 4959 pending_layer->SetDrawsContent(true); |
4960 FakePictureLayerImpl* pending_layer_ptr = pending_layer.get(); | 4960 FakePictureLayerImpl* pending_layer_ptr = pending_layer.get(); |
4961 pending_tree->SetRootLayer(std::move(pending_layer)); | 4961 pending_tree->SetRootLayerForTesting(std::move(pending_layer)); |
4962 pending_tree->BuildLayerListAndPropertyTreesForTesting(); | 4962 pending_tree->BuildLayerListAndPropertyTreesForTesting(); |
4963 | 4963 |
4964 float expected_contents_scale = 0.25f; | 4964 float expected_contents_scale = 0.25f; |
4965 for (int i = 1; i < 30; ++i) { | 4965 for (int i = 1; i < 30; ++i) { |
4966 float ideal_contents_scale = 0.1f * i - 1e-6; | 4966 float ideal_contents_scale = 0.1f * i - 1e-6; |
4967 switch (i) { | 4967 switch (i) { |
4968 // Scale 0.3. | 4968 // Scale 0.3. |
4969 case 3: | 4969 case 3: |
4970 expected_contents_scale = 0.5f; | 4970 expected_contents_scale = 0.5f; |
4971 break; | 4971 break; |
(...skipping 29 matching lines...) Expand all Loading... |
5001 EXPECT_FLOAT_EQ(expected_contents_scale, | 5001 EXPECT_FLOAT_EQ(expected_contents_scale, |
5002 pending_layer_ptr->picture_layer_tiling_set() | 5002 pending_layer_ptr->picture_layer_tiling_set() |
5003 ->FindTilingWithResolution(HIGH_RESOLUTION) | 5003 ->FindTilingWithResolution(HIGH_RESOLUTION) |
5004 ->contents_scale()) | 5004 ->contents_scale()) |
5005 << "ideal_contents_scale: " << ideal_contents_scale; | 5005 << "ideal_contents_scale: " << ideal_contents_scale; |
5006 } | 5006 } |
5007 } | 5007 } |
5008 | 5008 |
5009 } // namespace | 5009 } // namespace |
5010 } // namespace cc | 5010 } // namespace cc |
OLD | NEW |