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

Unified Diff: cc/trees/layer_tree_host_unittest_animation.cc

Issue 178123003: Make it possible to cancel commits following an animation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made test less strict. Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/trees/layer_tree_host_perftest.cc ('k') | cc/trees/thread_proxy.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/layer_tree_host_unittest_animation.cc
diff --git a/cc/trees/layer_tree_host_unittest_animation.cc b/cc/trees/layer_tree_host_unittest_animation.cc
index 165d30b6df17b26288c49418b55905d652c04276..ee12e5cf596108d96d4bc4ff80faa8e120ebaa5d 100644
--- a/cc/trees/layer_tree_host_unittest_animation.cc
+++ b/cc/trees/layer_tree_host_unittest_animation.cc
@@ -783,6 +783,15 @@ class LayerTreeHostAnimationTestContinuousAnimate
num_draw_layers_(0) {
}
+ virtual void SetupTree() OVERRIDE {
+ LayerTreeHostAnimationTest::SetupTree();
+ // Create a fake content layer so we actually produce new content for every
+ // animation frame.
+ content_ = FakeContentLayer::Create(&client_);
+ content_->set_always_update_resources(true);
+ layer_tree_host()->root_layer()->AddChild(content_);
+ }
+
virtual void BeginTest() OVERRIDE {
PostSetNeedsCommitToMainThread();
}
@@ -816,10 +825,118 @@ class LayerTreeHostAnimationTestContinuousAnimate
private:
int num_commit_complete_;
int num_draw_layers_;
+ FakeContentLayerClient client_;
+ scoped_refptr<FakeContentLayer> content_;
};
MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate);
+class LayerTreeHostAnimationTestCancelAnimateCommit
+ : public LayerTreeHostAnimationTest {
+ public:
+ LayerTreeHostAnimationTestCancelAnimateCommit() : num_animate_calls_(0) {}
+
+ virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
+
+ virtual void Animate(base::TimeTicks) OVERRIDE {
+ // No-op animate will cancel the commit.
+ if (++num_animate_calls_ == 2) {
+ EndTest();
+ return;
+ }
+ layer_tree_host()->SetNeedsAnimate();
+ }
+
+ virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE {
+ if (num_animate_calls_ > 1)
+ FAIL() << "Commit should have been canceled.";
+ }
+
+ virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
+ if (num_animate_calls_ > 1)
+ FAIL() << "Draw should have been canceled.";
+ }
+
+ virtual void AfterTest() OVERRIDE { EXPECT_EQ(2, num_animate_calls_); }
+
+ private:
+ int num_animate_calls_;
+ FakeContentLayerClient client_;
+ scoped_refptr<FakeContentLayer> content_;
+};
+
+MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCancelAnimateCommit);
+
+class LayerTreeHostAnimationTestForceRedraw
+ : public LayerTreeHostAnimationTest {
+ public:
+ LayerTreeHostAnimationTestForceRedraw()
+ : num_animate_(0), num_draw_layers_(0) {}
+
+ virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
+
+ virtual void Animate(base::TimeTicks) OVERRIDE {
+ if (++num_animate_ < 2)
+ layer_tree_host()->SetNeedsAnimate();
+ }
+
+ virtual void Layout() OVERRIDE {
+ layer_tree_host()->SetNextCommitForcesRedraw();
+ }
+
+ virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
+ if (++num_draw_layers_ == 2)
+ EndTest();
+ }
+
+ virtual void AfterTest() OVERRIDE {
+ // The first commit will always draw; make sure the second draw triggered
+ // by the animation was not cancelled.
+ EXPECT_EQ(2, num_draw_layers_);
+ EXPECT_EQ(2, num_animate_);
+ }
+
+ private:
+ int num_animate_;
+ int num_draw_layers_;
+};
+
+MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestForceRedraw);
+
+class LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit
+ : public LayerTreeHostAnimationTest {
+ public:
+ LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit()
+ : num_animate_(0), num_draw_layers_(0) {}
+
+ virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
+
+ virtual void Animate(base::TimeTicks) OVERRIDE {
+ if (++num_animate_ <= 2) {
+ layer_tree_host()->SetNeedsCommit();
+ layer_tree_host()->SetNeedsAnimate();
+ }
+ }
+
+ virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
+ if (++num_draw_layers_ == 2)
+ EndTest();
+ }
+
+ virtual void AfterTest() OVERRIDE {
+ // The first commit will always draw; make sure the second draw triggered
+ // by the SetNeedsCommit was not cancelled.
+ EXPECT_EQ(2, num_draw_layers_);
+ EXPECT_GE(num_animate_, 2);
+ }
+
+ private:
+ int num_animate_;
+ int num_draw_layers_;
+};
+
+MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit);
+
// Make sure the main thread can still execute animations when CanDraw() is not
// true.
class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw
« no previous file with comments | « cc/trees/layer_tree_host_perftest.cc ('k') | cc/trees/thread_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698