| 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_image_layer_impl.h" | 5 #include "cc/layers/picture_image_layer_impl.h" |
| 6 | 6 |
| 7 #include "cc/layers/append_quads_data.h" | 7 #include "cc/layers/append_quads_data.h" |
| 8 #include "cc/resources/tile_priority.h" | 8 #include "cc/resources/tile_priority.h" |
| 9 #include "cc/test/fake_impl_proxy.h" | 9 #include "cc/test/fake_impl_proxy.h" |
| 10 #include "cc/test/fake_layer_tree_host_impl.h" | 10 #include "cc/test/fake_layer_tree_host_impl.h" |
| 11 #include "cc/test/fake_output_surface.h" | 11 #include "cc/test/fake_output_surface.h" |
| 12 #include "cc/test/fake_picture_layer_tiling_client.h" | 12 #include "cc/test/fake_picture_layer_tiling_client.h" |
| 13 #include "cc/test/impl_side_painting_settings.h" | 13 #include "cc/test/impl_side_painting_settings.h" |
| 14 #include "cc/test/mock_quad_culler.h" | 14 #include "cc/test/mock_quad_culler.h" |
| 15 #include "cc/test/test_shared_bitmap_manager.h" | 15 #include "cc/test/test_shared_bitmap_manager.h" |
| 16 #include "cc/trees/layer_tree_impl.h" | 16 #include "cc/trees/layer_tree_impl.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class TestablePictureImageLayerImpl : public PictureImageLayerImpl { | 22 class TestablePictureImageLayerImpl : public PictureImageLayerImpl { |
| 23 public: | 23 public: |
| 24 TestablePictureImageLayerImpl(LayerTreeImpl* tree_impl, int id) | 24 TestablePictureImageLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 25 : PictureImageLayerImpl(tree_impl, id) { | 25 : PictureImageLayerImpl(tree_impl, id) { |
| 26 } | 26 } |
| 27 using PictureLayerImpl::UpdateIdealScales; | 27 using PictureLayerImpl::UpdateIdealScales; |
| 28 using PictureLayerImpl::MaximumTilingContentsScale; | 28 using PictureLayerImpl::MaximumTilingContentsScale; |
| 29 using PictureLayerImpl::ManageTilings; | |
| 30 using PictureLayerImpl::DoPostCommitInitializationIfNeeded; | 29 using PictureLayerImpl::DoPostCommitInitializationIfNeeded; |
| 31 | 30 |
| 32 void ScaleAndManageTilings(bool animating_transform_to_screen, | |
| 33 float maximum_animation_contents_scale) { | |
| 34 DoPostCommitInitializationIfNeeded(); | |
| 35 UpdateIdealScales(); | |
| 36 if (CanHaveTilings()) { | |
| 37 ManageTilings(animating_transform_to_screen, | |
| 38 maximum_animation_contents_scale); | |
| 39 } | |
| 40 } | |
| 41 PictureLayerTilingSet* tilings() { return tilings_.get(); } | 31 PictureLayerTilingSet* tilings() { return tilings_.get(); } |
| 42 | 32 |
| 43 friend class PictureImageLayerImplTest; | 33 friend class PictureImageLayerImplTest; |
| 44 }; | 34 }; |
| 45 | 35 |
| 46 class PictureImageLayerImplTest : public testing::Test { | 36 class PictureImageLayerImplTest : public testing::Test { |
| 47 public: | 37 public: |
| 48 PictureImageLayerImplTest() | 38 PictureImageLayerImplTest() |
| 49 : proxy_(base::MessageLoopProxy::current()), | 39 : proxy_(base::MessageLoopProxy::current()), |
| 50 host_impl_(ImplSidePaintingSettings(), | 40 host_impl_(ImplSidePaintingSettings(), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 73 TestablePictureImageLayerImpl* layer = | 63 TestablePictureImageLayerImpl* layer = |
| 74 new TestablePictureImageLayerImpl(tree, id); | 64 new TestablePictureImageLayerImpl(tree, id); |
| 75 layer->SetBounds(gfx::Size(100, 200)); | 65 layer->SetBounds(gfx::Size(100, 200)); |
| 76 layer->SetContentBounds(gfx::Size(100, 200)); | 66 layer->SetContentBounds(gfx::Size(100, 200)); |
| 77 layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_, | 67 layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_, |
| 78 layer->bounds())); | 68 layer->bounds())); |
| 79 layer->pile_ = tiling_client_.pile(); | 69 layer->pile_ = tiling_client_.pile(); |
| 80 return make_scoped_ptr(layer); | 70 return make_scoped_ptr(layer); |
| 81 } | 71 } |
| 82 | 72 |
| 83 void SetupDrawPropertiesAndManageTilings( | 73 void SetupDrawPropertiesAndUpdateTiles(TestablePictureImageLayerImpl* layer, |
| 84 TestablePictureImageLayerImpl* layer, | 74 float ideal_contents_scale, |
| 85 float ideal_contents_scale, | 75 float device_scale_factor, |
| 86 float device_scale_factor, | 76 float page_scale_factor, |
| 87 float page_scale_factor, | 77 float maximum_animation_contents_scale, |
| 88 float maximum_animation_contents_scale, | 78 bool animating_transform_to_screen) { |
| 89 bool animating_transform_to_screen) { | |
| 90 layer->draw_properties().ideal_contents_scale = ideal_contents_scale; | 79 layer->draw_properties().ideal_contents_scale = ideal_contents_scale; |
| 91 layer->draw_properties().device_scale_factor = device_scale_factor; | 80 layer->draw_properties().device_scale_factor = device_scale_factor; |
| 92 layer->draw_properties().page_scale_factor = page_scale_factor; | 81 layer->draw_properties().page_scale_factor = page_scale_factor; |
| 93 layer->draw_properties().maximum_animation_contents_scale = | 82 layer->draw_properties().maximum_animation_contents_scale = |
| 94 maximum_animation_contents_scale; | 83 maximum_animation_contents_scale; |
| 95 layer->draw_properties().screen_space_transform_is_animating = | 84 layer->draw_properties().screen_space_transform_is_animating = |
| 96 animating_transform_to_screen; | 85 animating_transform_to_screen; |
| 97 layer->ScaleAndManageTilings(animating_transform_to_screen, | 86 layer->UpdateTiles(); |
| 98 maximum_animation_contents_scale); | |
| 99 } | 87 } |
| 100 | 88 |
| 101 protected: | 89 protected: |
| 102 FakeImplProxy proxy_; | 90 FakeImplProxy proxy_; |
| 103 FakeLayerTreeHostImpl host_impl_; | 91 FakeLayerTreeHostImpl host_impl_; |
| 104 TestSharedBitmapManager shared_bitmap_manager_; | 92 TestSharedBitmapManager shared_bitmap_manager_; |
| 105 FakePictureLayerTilingClient tiling_client_; | 93 FakePictureLayerTilingClient tiling_client_; |
| 106 }; | 94 }; |
| 107 | 95 |
| 108 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { | 96 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { |
| 109 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); | 97 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); |
| 110 layer->SetDrawsContent(true); | 98 layer->SetDrawsContent(true); |
| 111 | 99 |
| 112 SetupDrawPropertiesAndManageTilings(layer.get(), 2.f, 3.f, 4.f, 1.f, false); | 100 SetupDrawPropertiesAndUpdateTiles(layer.get(), 2.f, 3.f, 4.f, 1.f, false); |
| 113 | 101 |
| 114 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_x()); | 102 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_x()); |
| 115 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_y()); | 103 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_y()); |
| 116 EXPECT_FLOAT_EQ(1.f, layer->MaximumTilingContentsScale()); | 104 EXPECT_FLOAT_EQ(1.f, layer->MaximumTilingContentsScale()); |
| 117 } | 105 } |
| 118 | 106 |
| 119 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { | 107 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { |
| 120 scoped_ptr<TestablePictureImageLayerImpl> pending_layer( | 108 scoped_ptr<TestablePictureImageLayerImpl> pending_layer( |
| 121 CreateLayer(1, PENDING_TREE)); | 109 CreateLayer(1, PENDING_TREE)); |
| 122 pending_layer->SetDrawsContent(true); | 110 pending_layer->SetDrawsContent(true); |
| 123 | 111 |
| 124 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal | 112 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal |
| 125 // to the content scale used by PictureImageLayerImpl. | 113 // to the content scale used by PictureImageLayerImpl. |
| 126 const float suggested_ideal_contents_scale = 2.f; | 114 const float suggested_ideal_contents_scale = 2.f; |
| 127 const float device_scale_factor = 3.f; | 115 const float device_scale_factor = 3.f; |
| 128 const float page_scale_factor = 4.f; | 116 const float page_scale_factor = 4.f; |
| 129 const float maximum_animation_contents_scale = 1.f; | 117 const float maximum_animation_contents_scale = 1.f; |
| 130 const bool animating_transform_to_screen = false; | 118 const bool animating_transform_to_screen = false; |
| 131 SetupDrawPropertiesAndManageTilings(pending_layer.get(), | 119 SetupDrawPropertiesAndUpdateTiles(pending_layer.get(), |
| 132 suggested_ideal_contents_scale, | 120 suggested_ideal_contents_scale, |
| 133 device_scale_factor, | 121 device_scale_factor, |
| 134 page_scale_factor, | 122 page_scale_factor, |
| 135 maximum_animation_contents_scale, | 123 maximum_animation_contents_scale, |
| 136 animating_transform_to_screen); | 124 animating_transform_to_screen); |
| 125 EXPECT_EQ(1.f, pending_layer->tilings()->tiling_at(0)->contents_scale()); |
| 137 | 126 |
| 138 // Push to active layer. | 127 // Push to active layer. |
| 128 host_impl_.pending_tree()->SetRootLayer(pending_layer.PassAs<LayerImpl>()); |
| 139 host_impl_.ActivatePendingTree(); | 129 host_impl_.ActivatePendingTree(); |
| 140 scoped_ptr<TestablePictureImageLayerImpl> active_layer( | 130 TestablePictureImageLayerImpl* active_layer = |
| 141 CreateLayer(1, ACTIVE_TREE)); | 131 static_cast<TestablePictureImageLayerImpl*>( |
| 142 pending_layer->PushPropertiesTo(active_layer.get()); | 132 host_impl_.active_tree()->root_layer()); |
| 143 SetupDrawPropertiesAndManageTilings(active_layer.get(), | 133 SetupDrawPropertiesAndUpdateTiles(active_layer, |
| 144 suggested_ideal_contents_scale, | 134 suggested_ideal_contents_scale, |
| 145 device_scale_factor, | 135 device_scale_factor, |
| 146 page_scale_factor, | 136 page_scale_factor, |
| 147 maximum_animation_contents_scale, | 137 maximum_animation_contents_scale, |
| 148 animating_transform_to_screen); | 138 animating_transform_to_screen); |
| 139 EXPECT_EQ(1.f, active_layer->tilings()->tiling_at(0)->contents_scale()); |
| 149 | 140 |
| 150 // Create tile and resource. | 141 // Create tile and resource. |
| 151 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 142 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
| 152 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( | 143 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( |
| 153 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); | 144 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); |
| 154 | 145 |
| 155 // Draw. | 146 // Draw. |
| 156 active_layer->draw_properties().visible_content_rect = | 147 active_layer->draw_properties().visible_content_rect = |
| 157 gfx::Rect(active_layer->bounds()); | 148 gfx::Rect(active_layer->bounds()); |
| 158 MockOcclusionTracker<LayerImpl> occlusion_tracker; | 149 MockOcclusionTracker<LayerImpl> occlusion_tracker; |
| 159 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 150 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 160 MockQuadCuller quad_culler(render_pass.get(), &occlusion_tracker); | 151 MockQuadCuller quad_culler(render_pass.get(), &occlusion_tracker); |
| 161 AppendQuadsData data; | 152 AppendQuadsData data; |
| 162 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL); | 153 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL); |
| 163 active_layer->AppendQuads(&quad_culler, &data); | 154 active_layer->AppendQuads(&quad_culler, &data); |
| 164 active_layer->DidDraw(NULL); | 155 active_layer->DidDraw(NULL); |
| 165 | 156 |
| 166 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material); | 157 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material); |
| 167 | 158 |
| 168 // Tiles are ready at correct scale, so should not set had_incomplete_tile. | 159 // Tiles are ready at correct scale, so should not set had_incomplete_tile. |
| 169 EXPECT_FALSE(data.had_incomplete_tile); | 160 EXPECT_FALSE(data.had_incomplete_tile); |
| 170 } | 161 } |
| 171 | 162 |
| 172 } // namespace | 163 } // namespace |
| 173 } // namespace cc | 164 } // namespace cc |
| OLD | NEW |