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" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_, | 63 layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_, |
64 layer->bounds())); | 64 layer->bounds())); |
65 layer->pile_ = tiling_client_.pile(); | 65 layer->pile_ = tiling_client_.pile(); |
66 return make_scoped_ptr(layer); | 66 return make_scoped_ptr(layer); |
67 } | 67 } |
68 | 68 |
69 void UpdateDrawProperties() { | 69 void UpdateDrawProperties() { |
70 host_impl_.pending_tree()->UpdateDrawProperties(); | 70 host_impl_.pending_tree()->UpdateDrawProperties(); |
71 } | 71 } |
72 | 72 |
73 void SetupDrawPropertiesAndUpdateTilePriorities( | |
74 TestablePictureImageLayerImpl* layer, | |
75 float ideal_contents_scale, | |
76 float device_scale_factor, | |
77 float page_scale_factor, | |
78 float maximum_animation_contents_scale, | |
79 bool animating_transform_to_screen) { | |
80 layer->draw_properties().ideal_contents_scale = 1.f; | |
81 layer->draw_properties().device_scale = device_scale_factor; | |
82 layer->draw_properties().page_scale = page_scale_factor; | |
83 layer->draw_properties().maximum_animation_contents_scale = | |
84 maximum_animation_contents_scale; | |
85 layer->draw_properties().screen_space_transform_is_animating = | |
86 animating_transform_to_screen; | |
87 layer->UpdateTilePriorities(); | |
88 } | |
89 | |
73 protected: | 90 protected: |
74 FakeImplProxy proxy_; | 91 FakeImplProxy proxy_; |
75 FakeLayerTreeHostImpl host_impl_; | 92 FakeLayerTreeHostImpl host_impl_; |
76 TestSharedBitmapManager shared_bitmap_manager_; | 93 TestSharedBitmapManager shared_bitmap_manager_; |
77 FakePictureLayerTilingClient tiling_client_; | 94 FakePictureLayerTilingClient tiling_client_; |
78 }; | 95 }; |
79 | 96 |
80 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { | |
81 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); | |
82 layer->SetDrawsContent(true); | |
83 | |
84 float contents_scale_x; | |
85 float contents_scale_y; | |
86 gfx::Size content_bounds; | |
87 layer->CalculateContentsScale(2.f, | |
88 3.f, | |
89 4.f, | |
90 1.f, | |
91 false, | |
92 &contents_scale_x, | |
93 &contents_scale_y, | |
94 &content_bounds); | |
95 EXPECT_FLOAT_EQ(1.f, contents_scale_x); | |
danakj
2014/05/21 15:01:00
The equivalent of this test would be to call Setup
| |
96 EXPECT_FLOAT_EQ(1.f, contents_scale_y); | |
97 EXPECT_EQ(layer->bounds(), content_bounds); | |
98 } | |
99 | |
100 TEST_F(PictureImageLayerImplTest, AreVisibleResourcesReady) { | 97 TEST_F(PictureImageLayerImplTest, AreVisibleResourcesReady) { |
101 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); | 98 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE)); |
102 layer->SetBounds(gfx::Size(100, 200)); | 99 layer->SetBounds(gfx::Size(100, 200)); |
103 layer->SetDrawsContent(true); | 100 layer->SetDrawsContent(true); |
104 | 101 |
105 UpdateDrawProperties(); | 102 UpdateDrawProperties(); |
106 | 103 |
107 float contents_scale_x; | 104 SetupDrawPropertiesAndUpdateTilePriorities( |
108 float contents_scale_y; | 105 layer.get(), 2.f, 3.f, 4.f, 1.f, false); |
109 gfx::Size content_bounds; | |
110 layer->CalculateContentsScale(2.f, | |
111 3.f, | |
112 4.f, | |
113 1.f, | |
114 false, | |
115 &contents_scale_x, | |
116 &contents_scale_y, | |
117 &content_bounds); | |
118 layer->UpdateTilePriorities(); | |
119 | 106 |
120 EXPECT_TRUE(layer->AreVisibleResourcesReady()); | 107 EXPECT_TRUE(layer->AreVisibleResourcesReady()); |
121 } | 108 } |
122 | 109 |
123 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { | 110 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) { |
124 scoped_ptr<TestablePictureImageLayerImpl> pending_layer( | 111 scoped_ptr<TestablePictureImageLayerImpl> pending_layer( |
125 CreateLayer(1, PENDING_TREE)); | 112 CreateLayer(1, PENDING_TREE)); |
126 pending_layer->SetDrawsContent(true); | 113 pending_layer->SetDrawsContent(true); |
127 | 114 |
128 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal | 115 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal |
129 // to the content scale used by PictureImageLayerImpl. | 116 // to the content scale used by PictureImageLayerImpl. |
130 const float suggested_ideal_contents_scale = 2.f; | 117 const float suggested_ideal_contents_scale = 2.f; |
131 const float device_scale_factor = 3.f; | 118 const float device_scale_factor = 3.f; |
132 const float page_scale_factor = 4.f; | 119 const float page_scale_factor = 4.f; |
133 const float maximum_animation_contents_scale = 1.f; | 120 const float maximum_animation_contents_scale = 1.f; |
134 const bool animating_transform_to_screen = false; | 121 const bool animating_transform_to_screen = false; |
135 float contents_scale_x; | 122 SetupDrawPropertiesAndUpdateTilePriorities(pending_layer.get(), |
136 float contents_scale_y; | 123 suggested_ideal_contents_scale, |
137 gfx::Size content_bounds; | 124 device_scale_factor, |
138 pending_layer->CalculateContentsScale(suggested_ideal_contents_scale, | 125 page_scale_factor, |
139 device_scale_factor, | 126 maximum_animation_contents_scale, |
140 page_scale_factor, | 127 animating_transform_to_screen); |
141 maximum_animation_contents_scale, | |
142 animating_transform_to_screen, | |
143 &contents_scale_x, | |
144 &contents_scale_y, | |
145 &content_bounds); | |
146 | 128 |
147 // Push to active layer. | 129 // Push to active layer. |
148 host_impl_.ActivatePendingTree(); | 130 host_impl_.ActivatePendingTree(); |
149 scoped_ptr<TestablePictureImageLayerImpl> active_layer( | 131 scoped_ptr<TestablePictureImageLayerImpl> active_layer( |
150 CreateLayer(1, ACTIVE_TREE)); | 132 CreateLayer(1, ACTIVE_TREE)); |
151 pending_layer->PushPropertiesTo(active_layer.get()); | 133 pending_layer->PushPropertiesTo(active_layer.get()); |
152 active_layer->CalculateContentsScale(suggested_ideal_contents_scale, | 134 SetupDrawPropertiesAndUpdateTilePriorities(active_layer.get(), |
153 device_scale_factor, | 135 suggested_ideal_contents_scale, |
154 page_scale_factor, | 136 device_scale_factor, |
155 maximum_animation_contents_scale, | 137 page_scale_factor, |
156 animating_transform_to_screen, | 138 maximum_animation_contents_scale, |
157 &contents_scale_x, | 139 animating_transform_to_screen); |
158 &contents_scale_y, | |
159 &content_bounds); | |
160 | 140 |
161 // Create tile and resource. | 141 // Create tile and resource. |
162 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); | 142 active_layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
163 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( | 143 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( |
164 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); | 144 active_layer->tilings()->tiling_at(0)->AllTilesForTesting()); |
165 | 145 |
166 // Draw. | 146 // Draw. |
147 active_layer->SetContentBounds(active_layer->bounds()); | |
167 active_layer->draw_properties().visible_content_rect = | 148 active_layer->draw_properties().visible_content_rect = |
168 gfx::Rect(active_layer->bounds()); | 149 gfx::Rect(active_layer->bounds()); |
169 MockQuadCuller quad_culler; | 150 MockQuadCuller quad_culler; |
170 AppendQuadsData data; | 151 AppendQuadsData data; |
171 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL); | 152 active_layer->WillDraw(DRAW_MODE_SOFTWARE, NULL); |
172 active_layer->AppendQuads(&quad_culler, &data); | 153 active_layer->AppendQuads(&quad_culler, &data); |
173 active_layer->DidDraw(NULL); | 154 active_layer->DidDraw(NULL); |
174 | 155 |
175 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material); | 156 EXPECT_EQ(DrawQuad::TILED_CONTENT, quad_culler.quad_list()[0]->material); |
176 | 157 |
177 // Tiles are ready at correct scale, so should not set had_incomplete_tile. | 158 // Tiles are ready at correct scale, so should not set had_incomplete_tile. |
178 EXPECT_FALSE(data.had_incomplete_tile); | 159 EXPECT_FALSE(data.had_incomplete_tile); |
179 } | 160 } |
180 | 161 |
181 } // namespace | 162 } // namespace |
182 } // namespace cc | 163 } // namespace cc |
OLD | NEW |