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

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

Issue 2769213006: cc: If SetDeferCommits(true) happens inside the main frame, abort it. (Closed)
Patch Set: defer-inside-mainframe: comments Created 3 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 | « no previous file | cc/trees/proxy_main.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.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 2676 matching lines...) Expand 10 before | Expand all | Expand 10 after
2687 FakeContentLayerClient client_; 2687 FakeContentLayerClient client_;
2688 scoped_refptr<Layer> layer_; 2688 scoped_refptr<Layer> layer_;
2689 int num_commit_complete_; 2689 int num_commit_complete_;
2690 int num_draw_layers_; 2690 int num_draw_layers_;
2691 }; 2691 };
2692 2692
2693 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate); 2693 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate);
2694 2694
2695 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { 2695 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest {
2696 public: 2696 public:
2697 LayerTreeHostTestDeferCommits() 2697 LayerTreeHostTestDeferCommits() = default;
2698 : num_will_begin_impl_frame_(0), num_send_begin_main_frame_(0) {}
2699 2698
2700 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2699 void BeginTest() override {
2700 // Start with commits deferred.
2701 PostSetDeferCommitsToMainThread(true);
2702 PostSetNeedsCommitToMainThread();
2703 }
2701 2704
2702 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, 2705 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl,
2703 const BeginFrameArgs& args) override { 2706 const BeginFrameArgs& args) override {
2707 // Impl frames happen while commits are deferred.
2704 num_will_begin_impl_frame_++; 2708 num_will_begin_impl_frame_++;
2705 switch (num_will_begin_impl_frame_) { 2709 switch (num_will_begin_impl_frame_) {
2706 case 1: 2710 case 1:
2707 break;
2708 case 2: 2711 case 2:
2709 case 3: 2712 case 3:
2710 case 4: 2713 case 4:
2711 // Post a number of frames to increase the chance that, if there exist 2714 // Post a number of frames to increase the chance that, if there exist
2712 // bugs, an unexpected BeginMainFrame will be issued. 2715 // bugs, an unexpected BeginMainFrame will be issued.
2713 PostSetNeedsCommitToMainThread(); 2716 PostSetNeedsCommitToMainThread();
2714 PostSetNeedsRedrawToMainThread(); 2717 PostSetNeedsRedrawToMainThread();
2715 break; 2718 break;
2716 case 5: 2719 case 5:
2717 PostSetDeferCommitsToMainThread(false); 2720 MainThreadTaskRunner()->PostTask(
2721 FROM_HERE,
2722 // Unretained because the test should not end before allowing
2723 // commits via this running.
2724 base::Bind(&LayerTreeHostTestDeferCommits::AllowCommits,
2725 base::Unretained(this)));
2718 break; 2726 break;
2719 default: 2727 default:
2720 // Sometimes |num_will_begin_impl_frame_| will be greater than 5 if the 2728 // Sometimes |num_will_begin_impl_frame_| will be greater than 5 if the
2721 // main thread is slow to respond. 2729 // main thread is slow to respond.
2722 break; 2730 break;
2723 } 2731 }
2724 } 2732 }
2725 2733
2726 void WillBeginMainFrame() override { 2734 void WillBeginMainFrame() override {
2735 EXPECT_TRUE(allow_commits_);
2727 num_send_begin_main_frame_++; 2736 num_send_begin_main_frame_++;
2728 switch (num_send_begin_main_frame_) { 2737 EndTest();
2729 case 1: 2738 }
2730 layer_tree_host()->SetDeferCommits(true); 2739
2731 break; 2740 void AllowCommits() {
2732 case 2: 2741 allow_commits_ = true;
2733 EndTest(); 2742 layer_tree_host()->SetDeferCommits(false);
2734 break;
2735 default:
2736 NOTREACHED();
2737 break;
2738 }
2739 } 2743 }
2740 2744
2741 void AfterTest() override { 2745 void AfterTest() override {
2742 EXPECT_GE(num_will_begin_impl_frame_, 5); 2746 EXPECT_GE(num_will_begin_impl_frame_, 5);
2743 EXPECT_EQ(2, num_send_begin_main_frame_); 2747 EXPECT_EQ(1, num_send_begin_main_frame_);
2744 } 2748 }
2745 2749
2746 private: 2750 private:
2747 int num_will_begin_impl_frame_; 2751 bool allow_commits_ = false;
2748 int num_send_begin_main_frame_; 2752 int num_will_begin_impl_frame_ = 0;
2753 int num_send_begin_main_frame_ = 0;
2749 }; 2754 };
2750 2755
2751 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); 2756 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits);
2752 2757
2758 // This verifies that we can abort a commit inside the main frame, and
2759 // we don't leave any weird states around if we never allow the commit
enne (OOO) 2017/03/26 23:50:06 Thanks for testing both of these states. :D
2760 // to happen.
2761 class LayerTreeHostTestDeferCommitsInsideBeginMainFrame
2762 : public LayerTreeHostTest {
2763 public:
2764 LayerTreeHostTestDeferCommitsInsideBeginMainFrame() = default;
2765
2766 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2767
2768 void WillBeginMainFrame() override {
2769 ++begin_main_frame_count_;
2770 if (allow_commits_)
2771 return;
2772
2773 // This should prevent the commit from happening.
2774 layer_tree_host()->SetDeferCommits(true);
2775 // Wait to see if the commit happens. It's possible the deferred
enne (OOO) 2017/03/26 23:50:06 I looked at TestHooks and LayerTreeTest, but it do
2776 // commit happens when it shouldn't but takes long enough that
2777 // this passes. But it won't fail when it shouldn't.
2778 MainThreadTaskRunner()->PostDelayedTask(
2779 FROM_HERE,
2780 // Unretained because the test doesn't end before this runs.
2781 base::Bind(&LayerTreeTest::EndTest, base::Unretained(this)),
2782 base::TimeDelta::FromMilliseconds(100));
2783 }
2784
2785 void DidCommit() override { ++commit_count_; }
2786
2787 void AfterTest() override {
2788 EXPECT_EQ(0, commit_count_);
2789 EXPECT_EQ(1, begin_main_frame_count_);
2790 }
2791
2792 private:
2793 bool allow_commits_ = false;
2794 int commit_count_ = 0;
2795 int begin_main_frame_count_ = 0;
2796 };
2797
2798 SINGLE_AND_MULTI_THREAD_TEST_F(
2799 LayerTreeHostTestDeferCommitsInsideBeginMainFrame);
2800
2801 // This verifies that we can abort a commit inside the main frame, and
2802 // we will finish the commit once it is allowed.
2803 class LayerTreeHostTestDeferCommitsInsideBeginMainFrameWithCommitAfter
2804 : public LayerTreeHostTest {
2805 public:
2806 LayerTreeHostTestDeferCommitsInsideBeginMainFrameWithCommitAfter() = default;
2807
2808 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2809
2810 void WillBeginMainFrame() override {
2811 ++begin_main_frame_count_;
2812 if (allow_commits_)
2813 return;
2814
2815 // This should prevent the commit from happening.
2816 layer_tree_host()->SetDeferCommits(true);
2817 // Wait to see if the commit happens. It's possible the deferred
2818 // commit happens when it shouldn't but takes long enough that
2819 // this passes. But it won't fail when it shouldn't.
2820 MainThreadTaskRunner()->PostDelayedTask(
2821 FROM_HERE,
2822 // Unretained because the test doesn't end before this runs.
2823 base::Bind(
2824 &LayerTreeHostTestDeferCommitsInsideBeginMainFrameWithCommitAfter::
2825 AllowCommits,
2826 base::Unretained(this)),
2827 base::TimeDelta::FromMilliseconds(100));
2828 }
2829
2830 void AllowCommits() {
2831 // Once we've waited and seen that commit did not happen, we
2832 // allow commits and should see this one go through.
2833 allow_commits_ = true;
2834 layer_tree_host()->SetDeferCommits(false);
2835 }
2836
2837 void DidCommit() override {
2838 ++commit_count_;
2839 EXPECT_TRUE(allow_commits_);
2840 EndTest();
2841 }
2842
2843 void AfterTest() override {
2844 EXPECT_EQ(1, commit_count_);
2845 EXPECT_EQ(2, begin_main_frame_count_);
2846 }
2847
2848 private:
2849 bool allow_commits_ = false;
2850 int commit_count_ = 0;
2851 int begin_main_frame_count_ = 0;
2852 };
2853
2854 SINGLE_AND_MULTI_THREAD_TEST_F(
2855 LayerTreeHostTestDeferCommitsInsideBeginMainFrameWithCommitAfter);
2856
2753 class LayerTreeHostTestCompositeImmediatelyStateTransitions 2857 class LayerTreeHostTestCompositeImmediatelyStateTransitions
2754 : public LayerTreeHostTest { 2858 : public LayerTreeHostTest {
2755 public: 2859 public:
2756 enum { 2860 enum {
2757 kInvalid, 2861 kInvalid,
2758 kStartedTest, 2862 kStartedTest,
2759 kStartedImplFrame, 2863 kStartedImplFrame,
2760 kStartedMainFrame, 2864 kStartedMainFrame,
2761 kStartedCommit, 2865 kStartedCommit,
2762 kCompletedCommit, 2866 kCompletedCommit,
(...skipping 4430 matching lines...) Expand 10 before | Expand all | Expand 10 after
7193 7297
7194 private: 7298 private:
7195 bool first_ = true; 7299 bool first_ = true;
7196 SkBitmap bitmap_; 7300 SkBitmap bitmap_;
7197 }; 7301 };
7198 7302
7199 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestQueueImageDecodeNonLazy); 7303 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestQueueImageDecodeNonLazy);
7200 7304
7201 } // namespace 7305 } // namespace
7202 } // namespace cc 7306 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/trees/proxy_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698