Index: cc/layers/picture_layer_impl_unittest.cc |
diff --git a/cc/layers/picture_layer_impl_unittest.cc b/cc/layers/picture_layer_impl_unittest.cc |
index c7a5900ca2e7b10a12a82dc43b215a39b08c3e0d..de6c6b9a6c724b33f8f85359aa73b5d0a37d8738 100644 |
--- a/cc/layers/picture_layer_impl_unittest.cc |
+++ b/cc/layers/picture_layer_impl_unittest.cc |
@@ -14,6 +14,7 @@ |
#include "cc/test/fake_content_layer_client.h" |
#include "cc/test/fake_impl_proxy.h" |
#include "cc/test/fake_layer_tree_host_impl.h" |
+#include "cc/test/fake_layer_tree_settings.h" |
#include "cc/test/fake_output_surface.h" |
#include "cc/test/fake_picture_layer_impl.h" |
#include "cc/test/fake_picture_pile_impl.h" |
@@ -46,7 +47,7 @@ class PictureLayerImplTest : public testing::Test { |
public: |
PictureLayerImplTest() |
: proxy_(base::MessageLoopProxy::current()), |
- host_impl_(ImplSidePaintingSettings(), |
+ host_impl_(FakeLayerTreeSettings(), |
&proxy_, |
&shared_bitmap_manager_), |
id_(7) {} |
@@ -197,7 +198,7 @@ class PictureLayerImplTest : public testing::Test { |
protected: |
void TestTileGridAlignmentCommon() { |
// Layer to span 4 raster tiles in x and in y |
- ImplSidePaintingSettings settings; |
+ FakeLayerTreeSettings settings; |
gfx::Size layer_size( |
settings.default_tile_size.width() * 7 / 2, |
settings.default_tile_size.height() * 7 / 2); |
@@ -2279,5 +2280,259 @@ TEST_F(PictureLayerImplTest, Occlusion) { |
} |
} |
+class NoLowResPictureLayerImplTest : public PictureLayerImplTest { |
+ public: |
+ NoLowResPictureLayerImplTest() |
+ : PictureLayerImplTest(FakeLayerTreeSettings(false)) |
+ {} |
+}; |
+ |
+TEST_F(NoLowResPictureLayerImplTest, ManageTilingsCreatesTilings) { |
+ gfx::Size tile_size(400, 400); |
+ gfx::Size layer_bounds(1300, 1900); |
+ |
+ scoped_refptr<FakePicturePileImpl> pending_pile = |
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
+ scoped_refptr<FakePicturePileImpl> active_pile = |
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
+ |
+ float result_scale_x, result_scale_y; |
+ gfx::Size result_bounds; |
+ |
+ SetupTrees(pending_pile, active_pile); |
+ EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
+ |
+ float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
+ EXPECT_LT(low_res_factor, 1.f); |
+ |
+ pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale |
+ 1.7f, // device scale |
+ 3.2f, // page scale |
+ 1.f, // maximum animation scale |
+ false, |
+ &result_scale_x, |
+ &result_scale_y, |
+ &result_bounds); |
+ ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
+ EXPECT_FLOAT_EQ( |
+ 1.3f, |
+ pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
+ |
+ // If we change the layer's CSS scale factor, then we should not get new |
+ // tilings. |
+ pending_layer_->CalculateContentsScale(1.8f, // ideal contents scale |
+ 1.7f, // device scale |
+ 3.2f, // page scale |
+ 1.f, // maximum animation scale |
+ false, |
+ &result_scale_x, |
+ &result_scale_y, |
+ &result_bounds); |
+ ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
+ EXPECT_FLOAT_EQ( |
+ 1.3f, |
+ pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
+ |
+ // If we change the page scale factor, then we should get new tilings. |
+ pending_layer_->CalculateContentsScale(1.8f, // ideal contents scale |
+ 1.7f, // device scale |
+ 2.2f, // page scale |
+ 1.f, // maximum animation scale |
+ false, |
+ &result_scale_x, |
+ &result_scale_y, |
+ &result_bounds); |
+ ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
+ EXPECT_FLOAT_EQ( |
+ 1.8f, |
+ pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
+ |
+ // If we change the device scale factor, then we should get new tilings. |
+ pending_layer_->CalculateContentsScale(1.9f, // ideal contents scale |
+ 1.4f, // device scale |
+ 2.2f, // page scale |
+ 1.f, // maximum animation scale |
+ false, |
+ &result_scale_x, |
+ &result_scale_y, |
+ &result_bounds); |
+ ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); |
+ EXPECT_FLOAT_EQ( |
+ 1.9f, |
+ pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
+ |
+ // If we change the device scale factor, but end up at the same total scale |
+ // factor somehow, then we don't get new tilings. |
+ pending_layer_->CalculateContentsScale(1.9f, // ideal contents scale |
+ 2.2f, // device scale |
+ 1.4f, // page scale |
+ 1.f, // maximum animation scale |
+ false, |
+ &result_scale_x, |
+ &result_scale_y, |
+ &result_bounds); |
+ ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); |
+ EXPECT_FLOAT_EQ( |
+ 1.9f, |
+ pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
+} |
+ |
+TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) { |
+ gfx::Size tile_size(400, 400); |
+ gfx::Size layer_bounds(1300, 1900); |
+ |
+ scoped_refptr<FakePicturePileImpl> pending_pile = |
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
+ scoped_refptr<FakePicturePileImpl> active_pile = |
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
+ |
+ float result_scale_x, result_scale_y; |
+ gfx::Size result_bounds; |
+ std::vector<PictureLayerTiling*> used_tilings; |
+ |
+ SetupTrees(pending_pile, active_pile); |
+ EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
+ |
+ float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
+ EXPECT_LT(low_res_factor, 1.f); |
+ |
+ float device_scale = 1.7f; |
+ float page_scale = 3.2f; |
+ |
+ SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); |
+ ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); |
+ |
+ // We only have ideal tilings, so they aren't removed. |
+ used_tilings.clear(); |
+ active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
+ ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); |
+ |
+ // Changing the ideal but not creating new tilings. |
+ SetContentsScaleOnBothLayers(1.5f, device_scale, page_scale, 1.f, false); |
+ ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); |
+ |
+ // The tilings are still our target scale, so they aren't removed. |
+ used_tilings.clear(); |
+ active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
+ ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); |
+ |
+ // Create a 1.2 scale tiling. Now we have 1.0 and 1.2 tilings. Ideal = 1.2. |
+ page_scale = 1.2f; |
+ SetContentsScaleOnBothLayers(1.2f, device_scale, page_scale, 1.f, false); |
+ ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
+ EXPECT_FLOAT_EQ( |
+ 1.f, |
+ active_layer_->tilings()->tiling_at(1)->contents_scale()); |
+ |
+ // Mark the non-ideal tilings as used. They won't be removed. |
+ used_tilings.clear(); |
+ used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); |
+ used_tilings.push_back(active_layer_->tilings()->tiling_at(3)); |
+ active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
+ ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
+ |
+ // Now move the ideal scale to 0.5. Our target stays 1.2. |
+ SetContentsScaleOnBothLayers(0.5f, device_scale, page_scale, 1.f, false); |
+ |
+ // The high resolution tiling is between target and ideal, so is not |
+ // removed. The low res tiling for the old ideal=1.0 scale is removed. |
+ used_tilings.clear(); |
+ active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
+ ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
+ |
+ // Now move the ideal scale to 1.0. Our target stays 1.2. |
+ SetContentsScaleOnBothLayers(1.f, device_scale, page_scale, 1.f, false); |
+ |
+ // All the tilings are between are target and the ideal, so they are not |
+ // removed. |
+ used_tilings.clear(); |
+ active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
+ ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
+ |
+ // Now move the ideal scale to 1.1 on the active layer. Our target stays 1.2. |
+ active_layer_->CalculateContentsScale(1.1f, |
+ device_scale, |
+ page_scale, |
+ 1.f, |
+ false, |
+ &result_scale_x, |
+ &result_scale_y, |
+ &result_bounds); |
+ |
+ // Because the pending layer's ideal scale is still 1.0, our tilings fall |
+ // in the range [1.0,1.2] and are kept. |
+ used_tilings.clear(); |
+ active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
+ ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
+ |
+ // Move the ideal scale on the pending layer to 1.1 as well. Our target stays |
+ // 1.2 still. |
+ pending_layer_->CalculateContentsScale(1.1f, |
+ device_scale, |
+ page_scale, |
+ 1.f, |
+ false, |
+ &result_scale_x, |
+ &result_scale_y, |
+ &result_bounds); |
+ |
+ // Our 1.0 tiling now falls outside the range between our ideal scale and our |
+ // target raster scale. But it is in our used tilings set, so nothing is |
+ // deleted. |
+ used_tilings.clear(); |
+ used_tilings.push_back(active_layer_->tilings()->tiling_at(1)); |
+ active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
+ ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); |
+ |
+ // If we remove it from our used tilings set, it is outside the range to keep |
+ // so it is deleted. |
+ used_tilings.clear(); |
+ active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
+ ASSERT_EQ(1u, active_layer_->tilings()->num_tilings()); |
+} |
+ |
+TEST_F(NoLowResPictureLayerImplTest, ReleaseResources) { |
+ gfx::Size tile_size(400, 400); |
+ gfx::Size layer_bounds(1300, 1900); |
+ |
+ scoped_refptr<FakePicturePileImpl> pending_pile = |
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
+ scoped_refptr<FakePicturePileImpl> active_pile = |
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
+ |
+ float result_scale_x, result_scale_y; |
+ gfx::Size result_bounds; |
+ |
+ SetupTrees(pending_pile, active_pile); |
+ EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
+ |
+ pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale |
+ 2.7f, // device scale |
+ 3.2f, // page scale |
+ 1.f, // maximum animation scale |
+ false, |
+ &result_scale_x, |
+ &result_scale_y, |
+ &result_bounds); |
+ EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
+ |
+ // All tilings should be removed when losing output surface. |
+ active_layer_->ReleaseResources(); |
+ EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); |
+ pending_layer_->ReleaseResources(); |
+ EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
+ |
+ // This should create new tilings. |
+ pending_layer_->CalculateContentsScale(1.3f, // ideal contents scale |
+ 2.7f, // device scale |
+ 3.2f, // page scale |
+ 1.f, // maximum animation scale |
+ false, |
+ &result_scale_x, |
+ &result_scale_y, |
+ &result_bounds); |
+ EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
+} |
+ |
} // namespace |
} // namespace cc |