| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/containers/scoped_ptr_hash_map.h" | 12 #include "base/containers/scoped_ptr_hash_map.h" |
| 13 #include "cc/animation/scrollbar_animation_controller_thinning.h" | 13 #include "cc/animation/scrollbar_animation_controller_thinning.h" |
| 14 #include "cc/base/latency_info_swap_promise.h" | 14 #include "cc/base/latency_info_swap_promise.h" |
| 15 #include "cc/base/math_util.h" | 15 #include "cc/base/math_util.h" |
| 16 #include "cc/input/page_scale_animation.h" |
| 16 #include "cc/input/top_controls_manager.h" | 17 #include "cc/input/top_controls_manager.h" |
| 17 #include "cc/layers/append_quads_data.h" | 18 #include "cc/layers/append_quads_data.h" |
| 18 #include "cc/layers/delegated_renderer_layer_impl.h" | 19 #include "cc/layers/delegated_renderer_layer_impl.h" |
| 19 #include "cc/layers/heads_up_display_layer_impl.h" | 20 #include "cc/layers/heads_up_display_layer_impl.h" |
| 20 #include "cc/layers/io_surface_layer_impl.h" | 21 #include "cc/layers/io_surface_layer_impl.h" |
| 21 #include "cc/layers/layer_impl.h" | 22 #include "cc/layers/layer_impl.h" |
| 22 #include "cc/layers/painted_scrollbar_layer_impl.h" | 23 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| 23 #include "cc/layers/render_surface_impl.h" | 24 #include "cc/layers/render_surface_impl.h" |
| 24 #include "cc/layers/solid_color_layer_impl.h" | 25 #include "cc/layers/solid_color_layer_impl.h" |
| 25 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 26 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
| (...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 | 1148 |
| 1148 // Non-anchor zoom-in | 1149 // Non-anchor zoom-in |
| 1149 { | 1150 { |
| 1150 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 1151 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
| 1151 min_page_scale, | 1152 min_page_scale, |
| 1152 max_page_scale); | 1153 max_page_scale); |
| 1153 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); | 1154 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); |
| 1154 | 1155 |
| 1155 did_request_redraw_ = false; | 1156 did_request_redraw_ = false; |
| 1156 did_request_animate_ = false; | 1157 did_request_animate_ = false; |
| 1157 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), false, 2.f, duration); | 1158 host_impl_->active_tree()->SetPageScaleAnimation( |
| 1159 gfx::Vector2d(), |
| 1160 false, |
| 1161 2.f, |
| 1162 duration); |
| 1163 host_impl_->ActivateSyncTree(); |
| 1158 EXPECT_FALSE(did_request_redraw_); | 1164 EXPECT_FALSE(did_request_redraw_); |
| 1159 EXPECT_TRUE(did_request_animate_); | 1165 EXPECT_TRUE(did_request_animate_); |
| 1160 | 1166 |
| 1161 did_request_redraw_ = false; | 1167 did_request_redraw_ = false; |
| 1162 did_request_animate_ = false; | 1168 did_request_animate_ = false; |
| 1163 host_impl_->Animate(start_time); | 1169 host_impl_->Animate(start_time); |
| 1164 EXPECT_TRUE(did_request_redraw_); | 1170 EXPECT_TRUE(did_request_redraw_); |
| 1165 EXPECT_TRUE(did_request_animate_); | 1171 EXPECT_TRUE(did_request_animate_); |
| 1166 | 1172 |
| 1167 did_request_redraw_ = false; | 1173 did_request_redraw_ = false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1185 | 1191 |
| 1186 // Anchor zoom-out | 1192 // Anchor zoom-out |
| 1187 { | 1193 { |
| 1188 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 1194 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
| 1189 min_page_scale, | 1195 min_page_scale, |
| 1190 max_page_scale); | 1196 max_page_scale); |
| 1191 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); | 1197 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); |
| 1192 | 1198 |
| 1193 did_request_redraw_ = false; | 1199 did_request_redraw_ = false; |
| 1194 did_request_animate_ = false; | 1200 did_request_animate_ = false; |
| 1195 host_impl_->StartPageScaleAnimation( | 1201 host_impl_->active_tree()->SetPageScaleAnimation( |
| 1196 gfx::Vector2d(25, 25), true, min_page_scale, duration); | 1202 gfx::Vector2d(25, 25), true, min_page_scale, duration); |
| 1203 host_impl_->ActivateSyncTree(); |
| 1197 EXPECT_FALSE(did_request_redraw_); | 1204 EXPECT_FALSE(did_request_redraw_); |
| 1198 EXPECT_TRUE(did_request_animate_); | 1205 EXPECT_TRUE(did_request_animate_); |
| 1199 | 1206 |
| 1200 did_request_redraw_ = false; | 1207 did_request_redraw_ = false; |
| 1201 did_request_animate_ = false; | 1208 did_request_animate_ = false; |
| 1202 host_impl_->Animate(start_time); | 1209 host_impl_->Animate(start_time); |
| 1203 EXPECT_TRUE(did_request_redraw_); | 1210 EXPECT_TRUE(did_request_redraw_); |
| 1204 EXPECT_TRUE(did_request_animate_); | 1211 EXPECT_TRUE(did_request_animate_); |
| 1205 | 1212 |
| 1206 did_request_redraw_ = false; | 1213 did_request_redraw_ = false; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1235 base::TimeTicks halfway_through_animation = start_time + duration / 2; | 1242 base::TimeTicks halfway_through_animation = start_time + duration / 2; |
| 1236 base::TimeTicks end_time = start_time + duration; | 1243 base::TimeTicks end_time = start_time + duration; |
| 1237 | 1244 |
| 1238 // Anchor zoom with unchanged page scale should not change scroll or scale. | 1245 // Anchor zoom with unchanged page scale should not change scroll or scale. |
| 1239 { | 1246 { |
| 1240 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 1247 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
| 1241 min_page_scale, | 1248 min_page_scale, |
| 1242 max_page_scale); | 1249 max_page_scale); |
| 1243 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); | 1250 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); |
| 1244 | 1251 |
| 1245 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), true, 1.f, duration); | 1252 host_impl_->active_tree()->SetPageScaleAnimation( |
| 1253 gfx::Vector2d(), |
| 1254 true, |
| 1255 1.f, |
| 1256 duration); |
| 1257 host_impl_->ActivateSyncTree(); |
| 1246 host_impl_->Animate(start_time); | 1258 host_impl_->Animate(start_time); |
| 1247 host_impl_->Animate(halfway_through_animation); | 1259 host_impl_->Animate(halfway_through_animation); |
| 1248 EXPECT_TRUE(did_request_redraw_); | 1260 EXPECT_TRUE(did_request_redraw_); |
| 1249 host_impl_->Animate(end_time); | 1261 host_impl_->Animate(end_time); |
| 1250 EXPECT_TRUE(did_request_commit_); | 1262 EXPECT_TRUE(did_request_commit_); |
| 1251 | 1263 |
| 1252 scoped_ptr<ScrollAndScaleSet> scroll_info = | 1264 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 1253 host_impl_->ProcessScrollDeltas(); | 1265 host_impl_->ProcessScrollDeltas(); |
| 1254 EXPECT_EQ(scroll_info->page_scale_delta, 1); | 1266 EXPECT_EQ(scroll_info->page_scale_delta, 1); |
| 1255 ExpectNone(*scroll_info, scroll_layer->id()); | 1267 ExpectNone(*scroll_info, scroll_layer->id()); |
| 1256 } | 1268 } |
| 1257 } | 1269 } |
| 1258 | 1270 |
| 1271 TEST_F(LayerTreeHostImplTest, PageScaleAnimationTransferedOnSyncTreeActivate) { |
| 1272 host_impl_->CreatePendingTree(); |
| 1273 CreateScrollAndContentsLayers( |
| 1274 host_impl_->pending_tree(), |
| 1275 gfx::Size(100, 100)); |
| 1276 host_impl_->ActivateSyncTree(); |
| 1277 DrawFrame(); |
| 1278 |
| 1279 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 1280 DCHECK(scroll_layer); |
| 1281 |
| 1282 float min_page_scale = 0.5f; |
| 1283 float max_page_scale = 4.f; |
| 1284 host_impl_->sync_tree()->SetPageScaleFactorAndLimits(1.f, |
| 1285 min_page_scale, |
| 1286 max_page_scale); |
| 1287 host_impl_->ActivateSyncTree(); |
| 1288 |
| 1289 base::TimeTicks start_time = base::TimeTicks() + |
| 1290 base::TimeDelta::FromSeconds(1); |
| 1291 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 1292 base::TimeTicks halfway_through_animation = start_time + duration / 2; |
| 1293 base::TimeTicks end_time = start_time + duration; |
| 1294 float target_scale = 2.f; |
| 1295 |
| 1296 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); |
| 1297 |
| 1298 // Make sure TakePageScaleAnimation works properly. |
| 1299 host_impl_->sync_tree()->SetPageScaleAnimation( |
| 1300 gfx::Vector2d(), |
| 1301 false, |
| 1302 target_scale, |
| 1303 duration); |
| 1304 scoped_ptr<PageScaleAnimation> psa = |
| 1305 host_impl_->sync_tree()->TakePageScaleAnimation(); |
| 1306 EXPECT_EQ(target_scale, psa->target_page_scale_factor()); |
| 1307 EXPECT_EQ(duration, psa->duration()); |
| 1308 EXPECT_EQ(nullptr, host_impl_->sync_tree()->TakePageScaleAnimation()); |
| 1309 |
| 1310 // Recreate the PSA. Nothing should happen here since the tree containing the |
| 1311 // PSA hasn't been activated yet. |
| 1312 did_request_redraw_ = false; |
| 1313 did_request_animate_ = false; |
| 1314 host_impl_->sync_tree()->SetPageScaleAnimation( |
| 1315 gfx::Vector2d(), |
| 1316 false, |
| 1317 target_scale, |
| 1318 duration); |
| 1319 host_impl_->Animate(halfway_through_animation); |
| 1320 EXPECT_FALSE(did_request_animate_); |
| 1321 EXPECT_FALSE(did_request_redraw_); |
| 1322 |
| 1323 // Activate the sync tree. This should cause the animation to become enabled. |
| 1324 // It should also clear the pointer on the sync tree. |
| 1325 host_impl_->ActivateSyncTree(); |
| 1326 EXPECT_EQ(nullptr, host_impl_->sync_tree()->TakePageScaleAnimation().get()); |
| 1327 EXPECT_FALSE(did_request_redraw_); |
| 1328 EXPECT_TRUE(did_request_animate_); |
| 1329 |
| 1330 // From here on, make sure the animation runs as normal. |
| 1331 did_request_redraw_ = false; |
| 1332 did_request_animate_ = false; |
| 1333 host_impl_->Animate(start_time); |
| 1334 EXPECT_TRUE(did_request_redraw_); |
| 1335 EXPECT_TRUE(did_request_animate_); |
| 1336 |
| 1337 did_request_redraw_ = false; |
| 1338 did_request_animate_ = false; |
| 1339 host_impl_->Animate(halfway_through_animation); |
| 1340 EXPECT_TRUE(did_request_redraw_); |
| 1341 EXPECT_TRUE(did_request_animate_); |
| 1342 |
| 1343 did_request_redraw_ = false; |
| 1344 did_request_animate_ = false; |
| 1345 did_request_commit_ = false; |
| 1346 host_impl_->Animate(end_time); |
| 1347 EXPECT_TRUE(did_request_commit_); |
| 1348 EXPECT_FALSE(did_request_animate_); |
| 1349 |
| 1350 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 1351 host_impl_->ProcessScrollDeltas(); |
| 1352 EXPECT_EQ(scroll_info->page_scale_delta, target_scale); |
| 1353 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); |
| 1354 } |
| 1355 |
| 1259 class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { | 1356 class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { |
| 1260 public: | 1357 public: |
| 1261 LayerTreeHostImplOverridePhysicalTime( | 1358 LayerTreeHostImplOverridePhysicalTime( |
| 1262 const LayerTreeSettings& settings, | 1359 const LayerTreeSettings& settings, |
| 1263 LayerTreeHostImplClient* client, | 1360 LayerTreeHostImplClient* client, |
| 1264 Proxy* proxy, | 1361 Proxy* proxy, |
| 1265 SharedBitmapManager* manager, | 1362 SharedBitmapManager* manager, |
| 1266 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 1363 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 1267 : LayerTreeHostImpl(settings, | 1364 : LayerTreeHostImpl(settings, |
| 1268 client, | 1365 client, |
| (...skipping 5900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7169 // surface. | 7266 // surface. |
| 7170 EXPECT_EQ(0, num_lost_surfaces_); | 7267 EXPECT_EQ(0, num_lost_surfaces_); |
| 7171 host_impl_->DidLoseOutputSurface(); | 7268 host_impl_->DidLoseOutputSurface(); |
| 7172 EXPECT_EQ(1, num_lost_surfaces_); | 7269 EXPECT_EQ(1, num_lost_surfaces_); |
| 7173 host_impl_->DidLoseOutputSurface(); | 7270 host_impl_->DidLoseOutputSurface(); |
| 7174 EXPECT_LE(1, num_lost_surfaces_); | 7271 EXPECT_LE(1, num_lost_surfaces_); |
| 7175 } | 7272 } |
| 7176 | 7273 |
| 7177 } // namespace | 7274 } // namespace |
| 7178 } // namespace cc | 7275 } // namespace cc |
| OLD | NEW |