Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 1782433002: CC Animation: Erase old animation system. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@erasetests
Patch Set: Remove vtbl in LayerAnimationController. Fix formatting. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 host_impl_->SetVisible(true); 202 host_impl_->SetVisible(true);
203 bool init = host_impl_->InitializeRenderer(output_surface_.get()); 203 bool init = host_impl_->InitializeRenderer(output_surface_.get());
204 host_impl_->SetViewportSize(gfx::Size(10, 10)); 204 host_impl_->SetViewportSize(gfx::Size(10, 10));
205 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); 205 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f);
206 // Set the BeginFrameArgs so that methods which use it are able to. 206 // Set the BeginFrameArgs so that methods which use it are able to.
207 host_impl_->WillBeginImplFrame(CreateBeginFrameArgsForTesting( 207 host_impl_->WillBeginImplFrame(CreateBeginFrameArgsForTesting(
208 BEGINFRAME_FROM_HERE, 208 BEGINFRAME_FROM_HERE,
209 base::TimeTicks() + base::TimeDelta::FromMilliseconds(1))); 209 base::TimeTicks() + base::TimeDelta::FromMilliseconds(1)));
210 host_impl_->DidFinishImplFrame(); 210 host_impl_->DidFinishImplFrame();
211 211
212 if (host_impl_->settings().use_compositor_animation_timelines) { 212 timeline_ =
213 timeline_ = 213 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
214 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); 214 host_impl_->animation_host()->AddAnimationTimeline(timeline_);
215 host_impl_->animation_host()->AddAnimationTimeline(timeline_);
216 }
217 215
218 return init; 216 return init;
219 } 217 }
220 218
221 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) { 219 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) {
222 root->SetPosition(gfx::PointF()); 220 root->SetPosition(gfx::PointF());
223 root->SetBounds(gfx::Size(10, 10)); 221 root->SetBounds(gfx::Size(10, 10));
224 root->SetDrawsContent(true); 222 root->SetDrawsContent(true);
225 root->draw_properties().visible_layer_rect = gfx::Rect(0, 0, 10, 10); 223 root->draw_properties().visible_layer_rect = gfx::Rect(0, 0, 10, 10);
226 root->SetForceRenderSurface(true); 224 root->SetForceRenderSurface(true);
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 LayerImpl::Create(host_impl_->pending_tree(), 1)); 1189 LayerImpl::Create(host_impl_->pending_tree(), 1));
1192 LayerImpl* root = host_impl_->pending_tree()->root_layer(); 1190 LayerImpl* root = host_impl_->pending_tree()->root_layer();
1193 root->SetBounds(gfx::Size(50, 50)); 1191 root->SetBounds(gfx::Size(50, 50));
1194 root->SetForceRenderSurface(true); 1192 root->SetForceRenderSurface(true);
1195 1193
1196 root->AddChild(LayerImpl::Create(host_impl_->pending_tree(), 2)); 1194 root->AddChild(LayerImpl::Create(host_impl_->pending_tree(), 2));
1197 LayerImpl* child = root->children()[0].get(); 1195 LayerImpl* child = root->children()[0].get();
1198 child->SetBounds(gfx::Size(10, 10)); 1196 child->SetBounds(gfx::Size(10, 10));
1199 child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); 1197 child->draw_properties().visible_layer_rect = gfx::Rect(10, 10);
1200 child->SetDrawsContent(true); 1198 child->SetDrawsContent(true);
1201 if (host_impl_->settings().use_compositor_animation_timelines) { 1199 AddAnimatedTransformToLayerWithPlayer(child->id(), timeline(), 10.0, 3, 0);
1202 AddAnimatedTransformToLayerWithPlayer(child->id(), timeline(), 10.0, 3, 0);
1203 } else {
1204 AddAnimatedTransformToLayer(child, 10.0, 3, 0);
1205 }
1206 1200
1207 EXPECT_FALSE(did_request_next_frame_); 1201 EXPECT_FALSE(did_request_next_frame_);
1208 EXPECT_FALSE(did_request_redraw_); 1202 EXPECT_FALSE(did_request_redraw_);
1209 EXPECT_FALSE(did_request_commit_); 1203 EXPECT_FALSE(did_request_commit_);
1210 1204
1211 host_impl_->AnimatePendingTreeAfterCommit(); 1205 host_impl_->AnimatePendingTreeAfterCommit();
1212 1206
1213 // An animation exists on the pending layer. Doing 1207 // An animation exists on the pending layer. Doing
1214 // AnimatePendingTreeAfterCommit() requests another frame. 1208 // AnimatePendingTreeAfterCommit() requests another frame.
1215 // In reality, animations without has_set_start_time() == true do not need to 1209 // In reality, animations without has_set_start_time() == true do not need to
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 LayerImpl* child = root->children()[0].get(); 1245 LayerImpl* child = root->children()[0].get();
1252 child->SetBounds(gfx::Size(10, 10)); 1246 child->SetBounds(gfx::Size(10, 10));
1253 child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); 1247 child->draw_properties().visible_layer_rect = gfx::Rect(10, 10);
1254 child->SetDrawsContent(true); 1248 child->SetDrawsContent(true);
1255 1249
1256 // Add a translate from 6,7 to 8,9. 1250 // Add a translate from 6,7 to 8,9.
1257 TransformOperations start; 1251 TransformOperations start;
1258 start.AppendTranslate(6.f, 7.f, 0.f); 1252 start.AppendTranslate(6.f, 7.f, 0.f);
1259 TransformOperations end; 1253 TransformOperations end;
1260 end.AppendTranslate(8.f, 9.f, 0.f); 1254 end.AppendTranslate(8.f, 9.f, 0.f);
1261 if (host_impl_->settings().use_compositor_animation_timelines) { 1255 AddAnimatedTransformToLayerWithPlayer(child->id(), timeline(), 4.0, start,
1262 AddAnimatedTransformToLayerWithPlayer(child->id(), timeline(), 4.0, start, 1256 end);
1263 end);
1264 } else {
1265 AddAnimatedTransformToLayer(child, 4.0, start, end);
1266 }
1267 1257
1268 base::TimeTicks now = base::TimeTicks::Now(); 1258 base::TimeTicks now = base::TimeTicks::Now();
1269 host_impl_->WillBeginImplFrame( 1259 host_impl_->WillBeginImplFrame(
1270 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now)); 1260 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now));
1271 1261
1272 // TODO(crbug.com/551134): We always request a new frame and a draw for 1262 // TODO(crbug.com/551134): We always request a new frame and a draw for
1273 // animations that are on the pending tree, but we don't need to do that 1263 // animations that are on the pending tree, but we don't need to do that
1274 // unless they are waiting for some future time to start. 1264 // unless they are waiting for some future time to start.
1275 EXPECT_TRUE(did_request_next_frame_); 1265 EXPECT_TRUE(did_request_next_frame_);
1276 EXPECT_TRUE(did_request_redraw_); 1266 EXPECT_TRUE(did_request_redraw_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 LayerImpl::Create(host_impl_->active_tree(), 1)); 1303 LayerImpl::Create(host_impl_->active_tree(), 1));
1314 LayerImpl* root = host_impl_->active_tree()->root_layer(); 1304 LayerImpl* root = host_impl_->active_tree()->root_layer();
1315 root->SetBounds(gfx::Size(50, 50)); 1305 root->SetBounds(gfx::Size(50, 50));
1316 root->SetHasRenderSurface(true); 1306 root->SetHasRenderSurface(true);
1317 1307
1318 root->AddChild(LayerImpl::Create(host_impl_->active_tree(), 2)); 1308 root->AddChild(LayerImpl::Create(host_impl_->active_tree(), 2));
1319 LayerImpl* child = root->children()[0].get(); 1309 LayerImpl* child = root->children()[0].get();
1320 child->SetBounds(gfx::Size(10, 10)); 1310 child->SetBounds(gfx::Size(10, 10));
1321 child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); 1311 child->draw_properties().visible_layer_rect = gfx::Rect(10, 10);
1322 child->SetDrawsContent(true); 1312 child->SetDrawsContent(true);
1323 if (host_impl_->settings().use_compositor_animation_timelines) { 1313 AddAnimatedTransformToLayerWithPlayer(child->id(), timeline(), 10.0, 3, 0);
1324 AddAnimatedTransformToLayerWithPlayer(child->id(), timeline(), 10.0, 3, 0);
1325 } else {
1326 AddAnimatedTransformToLayer(child, 10.0, 3, 0);
1327 }
1328 1314
1329 // Set up the property trees so that UpdateDrawProperties will work in 1315 // Set up the property trees so that UpdateDrawProperties will work in
1330 // CommitComplete below. 1316 // CommitComplete below.
1331 LayerImplList list; 1317 LayerImplList list;
1332 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 1318 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1333 root, gfx::Size(50, 50), &list, 0); 1319 root, gfx::Size(50, 50), &list, 0);
1334 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 1320 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1335 1321
1336 EXPECT_FALSE(did_request_next_frame_); 1322 EXPECT_FALSE(did_request_next_frame_);
1337 EXPECT_FALSE(did_request_redraw_); 1323 EXPECT_FALSE(did_request_redraw_);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); 1370 child->draw_properties().visible_layer_rect = gfx::Rect(10, 10);
1385 child->SetDrawsContent(true); 1371 child->SetDrawsContent(true);
1386 1372
1387 EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation()); 1373 EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation());
1388 1374
1389 // Add a translate from 6,7 to 8,9. 1375 // Add a translate from 6,7 to 8,9.
1390 TransformOperations start; 1376 TransformOperations start;
1391 start.AppendTranslate(6.f, 7.f, 0.f); 1377 start.AppendTranslate(6.f, 7.f, 0.f);
1392 TransformOperations end; 1378 TransformOperations end;
1393 end.AppendTranslate(8.f, 9.f, 0.f); 1379 end.AppendTranslate(8.f, 9.f, 0.f);
1394 int animation_id; 1380 int animation_id = AddAnimatedTransformToLayerWithPlayer(
1395 if (host_impl_->settings().use_compositor_animation_timelines) { 1381 child->id(), timeline(), 4.0, start, end);
1396 animation_id = AddAnimatedTransformToLayerWithPlayer(
1397 child->id(), timeline(), 4.0, start, end);
1398 } else {
1399 animation_id = AddAnimatedTransformToLayer(child, 4.0, start, end);
1400 }
1401 1382
1402 base::TimeTicks now = base::TimeTicks::Now(); 1383 base::TimeTicks now = base::TimeTicks::Now();
1403 host_impl_->WillBeginImplFrame( 1384 host_impl_->WillBeginImplFrame(
1404 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now)); 1385 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now));
1405 1386
1406 host_impl_->ActivateAnimations(); 1387 host_impl_->ActivateAnimations();
1407 host_impl_->Animate(); 1388 host_impl_->Animate();
1408 1389
1409 EXPECT_FALSE(child->was_ever_ready_since_last_transform_animation()); 1390 EXPECT_FALSE(child->was_ever_ready_since_last_transform_animation());
1410 1391
(...skipping 10 matching lines...) Expand all
1421 child->set_has_missing_tiles(false); 1402 child->set_has_missing_tiles(false);
1422 1403
1423 // Child layer has an animating and no missing tiles. 1404 // Child layer has an animating and no missing tiles.
1424 result = host_impl_->PrepareToDraw(&frame); 1405 result = host_impl_->PrepareToDraw(&frame);
1425 EXPECT_EQ(DRAW_SUCCESS, result); 1406 EXPECT_EQ(DRAW_SUCCESS, result);
1426 EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation()); 1407 EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation());
1427 host_impl_->DidDrawAllLayers(frame); 1408 host_impl_->DidDrawAllLayers(frame);
1428 1409
1429 // Remove the animation. 1410 // Remove the animation.
1430 child->set_has_missing_tiles(true); 1411 child->set_has_missing_tiles(true);
1431 if (host_impl_->settings().use_compositor_animation_timelines) { 1412 RemoveAnimationFromLayerWithExistingPlayer(child->id(), timeline(),
1432 RemoveAnimationFromLayerWithExistingPlayer(child->id(), timeline(), 1413 animation_id);
1433 animation_id);
1434 } else {
1435 child->layer_animation_controller()->RemoveAnimation(animation_id);
1436 }
1437 child->draw_properties().screen_space_transform_is_animating = false; 1414 child->draw_properties().screen_space_transform_is_animating = false;
1438 1415
1439 // Child layer doesn't have an animation, but was never ready since the last 1416 // Child layer doesn't have an animation, but was never ready since the last
1440 // time it animated (and has missing tiles). 1417 // time it animated (and has missing tiles).
1441 result = host_impl_->PrepareToDraw(&frame); 1418 result = host_impl_->PrepareToDraw(&frame);
1442 EXPECT_EQ(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS, result); 1419 EXPECT_EQ(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS, result);
1443 EXPECT_FALSE(child->was_ever_ready_since_last_transform_animation()); 1420 EXPECT_FALSE(child->was_ever_ready_since_last_transform_animation());
1444 host_impl_->DidDrawAllLayers(frame); 1421 host_impl_->DidDrawAllLayers(frame);
1445 1422
1446 child->set_has_missing_tiles(false); 1423 child->set_has_missing_tiles(false);
(...skipping 1944 matching lines...) Expand 10 before | Expand all | Expand 10 after
3391 MissingTextureAnimatingLayer(LayerTreeImpl* tree_impl, 3368 MissingTextureAnimatingLayer(LayerTreeImpl* tree_impl,
3392 int id, 3369 int id,
3393 bool tile_missing, 3370 bool tile_missing,
3394 bool had_incomplete_tile, 3371 bool had_incomplete_tile,
3395 bool animating, 3372 bool animating,
3396 ResourceProvider* resource_provider, 3373 ResourceProvider* resource_provider,
3397 scoped_refptr<AnimationTimeline> timeline) 3374 scoped_refptr<AnimationTimeline> timeline)
3398 : DidDrawCheckLayer(tree_impl, id), 3375 : DidDrawCheckLayer(tree_impl, id),
3399 tile_missing_(tile_missing), 3376 tile_missing_(tile_missing),
3400 had_incomplete_tile_(had_incomplete_tile) { 3377 had_incomplete_tile_(had_incomplete_tile) {
3401 if (animating) { 3378 if (animating)
3402 if (tree_impl->settings().use_compositor_animation_timelines) { 3379 AddAnimatedTransformToLayerWithPlayer(this->id(), timeline, 10.0, 3, 0);
3403 AddAnimatedTransformToLayerWithPlayer(this->id(), timeline, 10.0, 3, 0);
3404 } else {
3405 AddAnimatedTransformToLayer(this, 10.0, 3, 0);
3406 }
3407 }
3408 } 3380 }
3409 3381
3410 bool tile_missing_; 3382 bool tile_missing_;
3411 bool had_incomplete_tile_; 3383 bool had_incomplete_tile_;
3412 }; 3384 };
3413 3385
3414 struct PrepareToDrawSuccessTestCase { 3386 struct PrepareToDrawSuccessTestCase {
3415 struct State { 3387 struct State {
3416 bool has_missing_tile = false; 3388 bool has_missing_tile = false;
3417 bool has_incomplete_tile = false; 3389 bool has_incomplete_tile = false;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
3513 host_impl_->SwapBuffers(frame); 3485 host_impl_->SwapBuffers(frame);
3514 3486
3515 for (size_t i = 0; i < cases.size(); ++i) { 3487 for (size_t i = 0; i < cases.size(); ++i) {
3516 // Clean up host_impl_ state. 3488 // Clean up host_impl_ state.
3517 const auto& testcase = cases[i]; 3489 const auto& testcase = cases[i];
3518 std::vector<LayerImpl*> to_remove; 3490 std::vector<LayerImpl*> to_remove;
3519 for (const auto& child : root->children()) 3491 for (const auto& child : root->children())
3520 to_remove.push_back(child.get()); 3492 to_remove.push_back(child.get());
3521 for (auto* child : to_remove) 3493 for (auto* child : to_remove)
3522 root->RemoveChild(child); 3494 root->RemoveChild(child);
3523 if (host_impl_->settings().use_compositor_animation_timelines) 3495 timeline()->ClearPlayers();
3524 timeline()->ClearPlayers();
3525 3496
3526 std::ostringstream scope; 3497 std::ostringstream scope;
3527 scope << "Test case: " << i; 3498 scope << "Test case: " << i;
3528 SCOPED_TRACE(scope.str()); 3499 SCOPED_TRACE(scope.str());
3529 3500
3530 root->AddChild(MissingTextureAnimatingLayer::Create( 3501 root->AddChild(MissingTextureAnimatingLayer::Create(
3531 host_impl_->active_tree(), 2, testcase.layer_before.has_missing_tile, 3502 host_impl_->active_tree(), 2, testcase.layer_before.has_missing_tile,
3532 testcase.layer_before.has_incomplete_tile, 3503 testcase.layer_before.has_incomplete_tile,
3533 testcase.layer_before.is_animating, host_impl_->resource_provider(), 3504 testcase.layer_before.is_animating, host_impl_->resource_provider(),
3534 timeline())); 3505 timeline()));
(...skipping 6683 matching lines...) Expand 10 before | Expand all | Expand 10 after
10218 // There should not be any jitter measured till we hit the fixed point hits 10189 // There should not be any jitter measured till we hit the fixed point hits
10219 // threshold. 10190 // threshold.
10220 float expected_jitter = 10191 float expected_jitter =
10221 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; 10192 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0;
10222 EXPECT_EQ(jitter, expected_jitter); 10193 EXPECT_EQ(jitter, expected_jitter);
10223 } 10194 }
10224 } 10195 }
10225 10196
10226 } // namespace 10197 } // namespace
10227 } // namespace cc 10198 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698