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

Side by Side 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: Fix bug with calling SetNeedsAnimate after SetNeedsCommit. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « cc/trees/layer_tree_host_perftest.cc ('k') | cc/trees/thread_proxy.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "cc/animation/animation_curve.h" 7 #include "cc/animation/animation_curve.h"
8 #include "cc/animation/layer_animation_controller.h" 8 #include "cc/animation/layer_animation_controller.h"
9 #include "cc/animation/scroll_offset_animation_curve.h" 9 #include "cc/animation/scroll_offset_animation_curve.h"
10 #include "cc/animation/timing_function.h" 10 #include "cc/animation/timing_function.h"
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount); 776 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount);
777 777
778 class LayerTreeHostAnimationTestContinuousAnimate 778 class LayerTreeHostAnimationTestContinuousAnimate
779 : public LayerTreeHostAnimationTest { 779 : public LayerTreeHostAnimationTest {
780 public: 780 public:
781 LayerTreeHostAnimationTestContinuousAnimate() 781 LayerTreeHostAnimationTestContinuousAnimate()
782 : num_commit_complete_(0), 782 : num_commit_complete_(0),
783 num_draw_layers_(0) { 783 num_draw_layers_(0) {
784 } 784 }
785 785
786 virtual void SetupTree() OVERRIDE {
787 LayerTreeHostAnimationTest::SetupTree();
788 // Create a fake content layer so we actually produce new content for every
789 // animation frame.
790 content_ = FakeContentLayer::Create(&client_);
791 content_->set_always_update_resources(true);
792 layer_tree_host()->root_layer()->AddChild(content_);
793 }
794
786 virtual void BeginTest() OVERRIDE { 795 virtual void BeginTest() OVERRIDE {
787 PostSetNeedsCommitToMainThread(); 796 PostSetNeedsCommitToMainThread();
788 } 797 }
789 798
790 virtual void Animate(base::TimeTicks) OVERRIDE { 799 virtual void Animate(base::TimeTicks) OVERRIDE {
791 if (num_draw_layers_ == 2) 800 if (num_draw_layers_ == 2)
792 return; 801 return;
793 layer_tree_host()->SetNeedsAnimate(); 802 layer_tree_host()->SetNeedsAnimate();
794 } 803 }
795 804
(...skipping 13 matching lines...) Expand all
809 } 818 }
810 819
811 virtual void AfterTest() OVERRIDE { 820 virtual void AfterTest() OVERRIDE {
812 // Check that we didn't commit twice between first and second draw. 821 // Check that we didn't commit twice between first and second draw.
813 EXPECT_EQ(1, num_commit_complete_); 822 EXPECT_EQ(1, num_commit_complete_);
814 } 823 }
815 824
816 private: 825 private:
817 int num_commit_complete_; 826 int num_commit_complete_;
818 int num_draw_layers_; 827 int num_draw_layers_;
828 FakeContentLayerClient client_;
829 scoped_refptr<FakeContentLayer> content_;
819 }; 830 };
820 831
821 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate); 832 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate);
822 833
834 class LayerTreeHostAnimationTestCancelAnimateCommit
835 : public LayerTreeHostAnimationTest {
836 public:
837 LayerTreeHostAnimationTestCancelAnimateCommit() : num_animate_calls_(0) {}
838
839 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
840
841 virtual void Animate(base::TimeTicks) OVERRIDE {
842 // No-op animate will cancel the commit.
843 if (++num_animate_calls_ == 2) {
844 EndTest();
845 return;
846 }
847 layer_tree_host()->SetNeedsAnimate();
848 }
849
850 virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE {
851 if (num_animate_calls_ > 1)
852 FAIL() << "Commit should have been canceled.";
853 }
854
855 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
856 if (num_animate_calls_ > 1)
857 FAIL() << "Draw should have been canceled.";
858 }
859
860 virtual void AfterTest() OVERRIDE { EXPECT_EQ(2, num_animate_calls_); }
861
862 private:
863 int num_animate_calls_;
864 FakeContentLayerClient client_;
865 scoped_refptr<FakeContentLayer> content_;
866 };
867
868 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCancelAnimateCommit);
869
870 class LayerTreeHostAnimationTestForceRedraw
871 : public LayerTreeHostAnimationTest {
872 public:
873 LayerTreeHostAnimationTestForceRedraw()
874 : num_animate_(0), num_draw_layers_(0) {}
875
876 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
877
878 virtual void Animate(base::TimeTicks) OVERRIDE {
879 if (++num_animate_ < 2)
880 layer_tree_host()->SetNeedsAnimate();
881 }
882
883 virtual void Layout() OVERRIDE {
884 layer_tree_host()->SetNextCommitForcesRedraw();
885 }
886
887 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
888 if (++num_draw_layers_ == 2)
889 EndTest();
890 }
891
892 virtual void AfterTest() OVERRIDE {
893 // The first commit will always draw; make sure the second draw triggered
894 // by the animation was not cancelled.
895 EXPECT_EQ(2, num_draw_layers_);
896 EXPECT_EQ(2, num_animate_);
897 }
898
899 private:
900 int num_animate_;
901 int num_draw_layers_;
902 };
903
904 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestForceRedraw);
905
906 class LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit
907 : public LayerTreeHostAnimationTest {
908 public:
909 LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit()
910 : num_animate_(0), num_draw_layers_(0) {}
911
912 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
913
914 virtual void Animate(base::TimeTicks) OVERRIDE {
915 if (++num_animate_ <= 2) {
916 layer_tree_host()->SetNeedsCommit();
917 layer_tree_host()->SetNeedsAnimate();
918 }
919 }
920
921 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
922 if (++num_draw_layers_ == 2)
923 EndTest();
924 }
925
926 virtual void AfterTest() OVERRIDE {
927 // The first commit will always draw; make sure the second draw triggered
928 // by the SetNeedsCommit was not cancelled.
929 EXPECT_EQ(2, num_draw_layers_);
930 EXPECT_EQ(3, num_animate_);
danakj 2014/03/03 16:41:46 Can you test >= 2 instead of == 3 here? If the tes
931 }
932
933 private:
934 int num_animate_;
935 int num_draw_layers_;
936 };
937
938 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit);
939
823 // Make sure the main thread can still execute animations when CanDraw() is not 940 // Make sure the main thread can still execute animations when CanDraw() is not
824 // true. 941 // true.
825 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw 942 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw
826 : public LayerTreeHostAnimationTest { 943 : public LayerTreeHostAnimationTest {
827 public: 944 public:
828 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} 945 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {}
829 946
830 virtual void SetupTree() OVERRIDE { 947 virtual void SetupTree() OVERRIDE {
831 LayerTreeHostAnimationTest::SetupTree(); 948 LayerTreeHostAnimationTest::SetupTree();
832 content_ = FakeContentLayer::Create(&client_); 949 content_ = FakeContentLayer::Create(&client_);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 int num_draw_attempts_; 1239 int num_draw_attempts_;
1123 base::TimeTicks last_main_thread_tick_time_; 1240 base::TimeTicks last_main_thread_tick_time_;
1124 base::TimeTicks expected_impl_tick_time_; 1241 base::TimeTicks expected_impl_tick_time_;
1125 }; 1242 };
1126 1243
1127 // Only the non-impl-paint multi-threaded compositor freezes animations. 1244 // Only the non-impl-paint multi-threaded compositor freezes animations.
1128 MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostAnimationTestFrozenAnimationTickTime); 1245 MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostAnimationTestFrozenAnimationTickTime);
1129 1246
1130 } // namespace 1247 } // namespace
1131 } // namespace cc 1248 } // namespace cc
OLDNEW
« 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