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; | |
28 using PictureLayerImpl::MaximumTilingContentsScale; | |
29 using PictureLayerImpl::ManageTilings; | |
30 using PictureLayerImpl::DoPostCommitInitializationIfNeeded; | |
31 | 27 |
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(); } | 28 PictureLayerTilingSet* tilings() { return tilings_.get(); } |
42 | 29 |
43 friend class PictureImageLayerImplTest; | 30 friend class PictureImageLayerImplTest; |
44 }; | 31 }; |
45 | 32 |
46 class PictureImageLayerImplTest : public testing::Test { | 33 class PictureImageLayerImplTest : public testing::Test { |
47 public: | 34 public: |
48 PictureImageLayerImplTest() | 35 PictureImageLayerImplTest() |
49 : proxy_(base::MessageLoopProxy::current()), | 36 : proxy_(base::MessageLoopProxy::current()), |
50 host_impl_(ImplSidePaintingSettings(), | 37 host_impl_(ImplSidePaintingSettings(), |
(...skipping 15 matching lines...) Expand all Loading... |
66 case PENDING_TREE: | 53 case PENDING_TREE: |
67 tree = host_impl_.pending_tree(); | 54 tree = host_impl_.pending_tree(); |
68 break; | 55 break; |
69 case NUM_TREES: | 56 case NUM_TREES: |
70 NOTREACHED(); | 57 NOTREACHED(); |
71 break; | 58 break; |
72 } | 59 } |
73 TestablePictureImageLayerImpl* layer = | 60 TestablePictureImageLayerImpl* layer = |
74 new TestablePictureImageLayerImpl(tree, id); | 61 new TestablePictureImageLayerImpl(tree, id); |
75 layer->SetBounds(gfx::Size(100, 200)); | 62 layer->SetBounds(gfx::Size(100, 200)); |
76 layer->SetContentBounds(gfx::Size(100, 200)); | |
77 layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_, | 63 layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_, |
78 layer->bounds())); | 64 layer->bounds())); |
79 layer->pile_ = tiling_client_.pile(); | 65 layer->pile_ = tiling_client_.pile(); |
80 return make_scoped_ptr(layer); | 66 return make_scoped_ptr(layer); |
81 } | 67 } |
82 | 68 |
83 void SetupDrawPropertiesAndManageTilings( | |
84 TestablePictureImageLayerImpl* layer, | |
85 float ideal_contents_scale, | |
86 float device_scale_factor, | |
87 float page_scale_factor, | |
88 float maximum_animation_contents_scale, | |
89 bool animating_transform_to_screen) { | |
90 layer->draw_properties().ideal_contents_scale = ideal_contents_scale; | |
91 layer->draw_properties().device_scale_factor = device_scale_factor; | |
92 layer->draw_properties().page_scale_factor = page_scale_factor; | |
93 layer->draw_properties().maximum_animation_contents_scale = | |
94 maximum_animation_contents_scale; | |
95 layer->draw_properties().screen_space_transform_is_animating = | |
96 animating_transform_to_screen; | |
97 layer->ScaleAndManageTilings(animating_transform_to_screen, | |
98 maximum_animation_contents_scale); | |
99 } | |
100 | |
101 protected: | 69 protected: |
102 FakeImplProxy proxy_; | 70 FakeImplProxy proxy_; |
103 FakeLayerTreeHostImpl host_impl_; | 71 FakeLayerTreeHostImpl host_impl_; |
104 TestSharedBitmapManager shared_bitmap_manager_; | 72 TestSharedBitmapManager shared_bitmap_manager_; |
105 FakePictureLayerTilingClient tiling_client_; | 73 FakePictureLayerTilingClient tiling_client_; |
106 }; | 74 }; |
107 | 75 |
108 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { | 76 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { |
109 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); | 77 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); |
110 layer->SetDrawsContent(true); | 78 layer->SetDrawsContent(true); |
111 | 79 |
112 SetupDrawPropertiesAndManageTilings(layer.get(), 2.f, 3.f, 4.f, 1.f, false); | 80 float contents_scale_x; |
113 | 81 float contents_scale_y; |
114 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_x()); | 82 gfx::Size content_bounds; |
115 EXPECT_FLOAT_EQ(1.f, layer->contents_scale_y()); | 83 layer->CalculateContentsScale(2.f, |
116 EXPECT_FLOAT_EQ(1.f, layer->MaximumTilingContentsScale()); | 84 3.f, |
| 85 4.f, |
| 86 1.f, |
| 87 false, |
| 88 &contents_scale_x, |
| 89 &contents_scale_y, |
| 90 &content_bounds); |
| 91 EXPECT_FLOAT_EQ(1.f, contents_scale_x); |
| 92 EXPECT_FLOAT_EQ(1.f, contents_scale_y); |
| 93 EXPECT_EQ(layer->bounds(), content_bounds); |
117 } | 94 } |
118 | 95 |
119 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { | 96 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { |
120 scoped_ptr<TestablePictureImageLayerImpl> pending_layer( | 97 scoped_ptr<TestablePictureImageLayerImpl> pending_layer( |
121 CreateLayer(1, PENDING_TREE)); | 98 CreateLayer(1, PENDING_TREE)); |
122 pending_layer->SetDrawsContent(true); | 99 pending_layer->SetDrawsContent(true); |
123 | 100 |
124 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal | 101 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal |
125 // to the content scale used by PictureImageLayerImpl. | 102 // to the content scale used by PictureImageLayerImpl. |
126 const float suggested_ideal_contents_scale = 2.f; | 103 const float suggested_ideal_contents_scale = 2.f; |
127 const float device_scale_factor = 3.f; | 104 const float device_scale_factor = 3.f; |
128 const float page_scale_factor = 4.f; | 105 const float page_scale_factor = 4.f; |
129 const float maximum_animation_contents_scale = 1.f; | 106 const float maximum_animation_contents_scale = 1.f; |
130 const bool animating_transform_to_screen = false; | 107 const bool animating_transform_to_screen = false; |
131 SetupDrawPropertiesAndManageTilings(pending_layer.get(), | 108 float contents_scale_x; |
132 suggested_ideal_contents_scale, | 109 float contents_scale_y; |
133 device_scale_factor, | 110 gfx::Size content_bounds; |
134 page_scale_factor, | 111 pending_layer->CalculateContentsScale(suggested_ideal_contents_scale, |
135 maximum_animation_contents_scale, | 112 device_scale_factor, |
136 animating_transform_to_screen); | 113 page_scale_factor, |
| 114 maximum_animation_contents_scale, |
| 115 animating_transform_to_screen, |
| 116 &contents_scale_x, |
| 117 &contents_scale_y, |
| 118 &content_bounds); |
137 | 119 |
138 // Push to active layer. | 120 // Push to active layer. |
139 host_impl_.ActivatePendingTree(); | 121 host_impl_.ActivatePendingTree(); |
140 scoped_ptr<TestablePictureImageLayerImpl> active_layer( | 122 scoped_ptr<TestablePictureImageLayerImpl> active_layer( |
141 CreateLayer(1, ACTIVE_TREE)); | 123 CreateLayer(1, ACTIVE_TREE)); |
142 pending_layer->PushPropertiesTo(active_layer.get()); | 124 pending_layer->PushPropertiesTo(active_layer.get()); |
143 SetupDrawPropertiesAndManageTilings(active_layer.get(), | 125 active_layer->CalculateContentsScale(suggested_ideal_contents_scale, |
144 suggested_ideal_contents_scale, | 126 device_scale_factor, |
145 device_scale_factor, | 127 page_scale_factor, |
146 page_scale_factor, | 128 maximum_animation_contents_scale, |
147 maximum_animation_contents_scale, | 129 animating_transform_to_screen, |
148 animating_transform_to_screen); | 130 &contents_scale_x, |
| 131 &contents_scale_y, |
| 132 &content_bounds); |
149 | 133 |
150 // Create tile and resource. | 134 // Create tile and resource. |
151 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 135 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
152 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( | 136 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( |
153 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); | 137 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); |
154 | 138 |
155 // Draw. | 139 // Draw. |
156 active_layer->draw_properties().visible_content_rect = | 140 active_layer->draw_properties().visible_content_rect = |
157 gfx::Rect(active_layer->bounds()); | 141 gfx::Rect(active_layer->bounds()); |
158 MockQuadCuller quad_culler; | 142 MockQuadCuller quad_culler; |
159 AppendQuadsData data; | 143 AppendQuadsData data; |
160 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL); | 144 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL); |
161 active_layer->AppendQuads(&quad_culler, &data); | 145 active_layer->AppendQuads(&quad_culler, &data); |
162 active_layer->DidDraw(NULL); | 146 active_layer->DidDraw(NULL); |
163 | 147 |
164 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material); | 148 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material); |
165 | 149 |
166 // Tiles are ready at correct scale, so should not set had_incomplete_tile. | 150 // Tiles are ready at correct scale, so should not set had_incomplete_tile. |
167 EXPECT_FALSE(data.had_incomplete_tile); | 151 EXPECT_FALSE(data.had_incomplete_tile); |
168 } | 152 } |
169 | 153 |
170 } // namespace | 154 } // namespace |
171 } // namespace cc | 155 } // namespace cc |
OLD | NEW |