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

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

Issue 2717553005: cc: Glue LTHI and Scheduler changes for checker-imaging. (Closed)
Patch Set: .. 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 | « cc/trees/layer_tree_host_unittest_checkerimaging.cc ('k') | cc/trees/layer_tree_settings.h » ('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 "base/location.h" 7 #include "base/location.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "cc/animation/animation_host.h" 12 #include "cc/animation/animation_host.h"
13 #include "cc/base/completion_event.h"
13 #include "cc/input/main_thread_scrolling_reason.h" 14 #include "cc/input/main_thread_scrolling_reason.h"
14 #include "cc/input/scroll_elasticity_helper.h" 15 #include "cc/input/scroll_elasticity_helper.h"
15 #include "cc/layers/layer.h" 16 #include "cc/layers/layer.h"
16 #include "cc/layers/layer_impl.h" 17 #include "cc/layers/layer_impl.h"
17 #include "cc/layers/picture_layer.h" 18 #include "cc/layers/picture_layer.h"
18 #include "cc/scheduler/begin_frame_source.h" 19 #include "cc/scheduler/begin_frame_source.h"
19 #include "cc/test/fake_content_layer_client.h" 20 #include "cc/test/fake_content_layer_client.h"
20 #include "cc/test/fake_layer_tree_host_client.h" 21 #include "cc/test/fake_layer_tree_host_client.h"
21 #include "cc/test/fake_picture_layer.h" 22 #include "cc/test/fake_picture_layer.h"
22 #include "cc/test/fake_picture_layer_impl.h" 23 #include "cc/test/fake_picture_layer_impl.h"
(...skipping 2040 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 void AfterTest() override {} 2064 void AfterTest() override {}
2064 2065
2065 private: 2066 private:
2066 gfx::ScrollOffset initial_scroll_; 2067 gfx::ScrollOffset initial_scroll_;
2067 gfx::ScrollOffset second_scroll_; 2068 gfx::ScrollOffset second_scroll_;
2068 gfx::Vector2dF scroll_amount_; 2069 gfx::Vector2dF scroll_amount_;
2069 }; 2070 };
2070 2071
2071 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostScrollTestPropertyTreeUpdate); 2072 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostScrollTestPropertyTreeUpdate);
2072 2073
2074 class LayerTreeHostScrollTestImplSideInvalidation
2075 : public LayerTreeHostScrollTest {
2076 void BeginTest() override {
2077 layer_tree_host()->outer_viewport_scroll_layer()->set_did_scroll_callback(
2078 base::Bind(&LayerTreeHostScrollTestImplSideInvalidation::
2079 DidScrollOuterViewport,
2080 base::Unretained(this)));
2081 PostSetNeedsCommitToMainThread();
2082 }
2083
2084 void DidScrollOuterViewport(const gfx::ScrollOffset& offset) {
2085 // Defer responding to the main frame until an impl-side pending tree is
2086 // created for the invalidation request.
2087 {
2088 CompletionEvent completion;
2089 task_runner_provider()->ImplThreadTaskRunner()->PostTask(
2090 FROM_HERE,
2091 base::Bind(&LayerTreeHostScrollTestImplSideInvalidation::
2092 WaitForInvalidationOnImplThread,
2093 base::Unretained(this), &completion));
2094 completion.Wait();
2095 }
2096
2097 switch (++num_of_deltas_) {
2098 case 1: {
2099 // First set of deltas is here. The impl thread will scroll to the
2100 // second case on activation, so add a delta from the main thread that
2101 // takes us to the final value.
2102 Layer* outer_viewport_layer =
2103 layer_tree_host()->outer_viewport_scroll_layer();
2104 gfx::ScrollOffset delta_to_send =
2105 outer_viewport_offsets_[2] - outer_viewport_offsets_[1];
2106 outer_viewport_layer->SetScrollOffset(
2107 outer_viewport_layer->scroll_offset() + delta_to_send);
2108 } break;
2109 case 2:
2110 // Let the commit abort for the second set of deltas.
2111 break;
2112 default:
2113 NOTREACHED();
2114 }
2115 }
2116
2117 void WaitForInvalidationOnImplThread(CompletionEvent* completion) {
2118 impl_side_invalidation_event_ = completion;
2119 SignalCompletionIfPossible();
2120 }
2121
2122 void DidInvalidateContentOnImplSide(LayerTreeHostImpl* host_impl) override {
2123 invalidated_on_impl_thread_ = true;
2124 SignalCompletionIfPossible();
2125 }
2126
2127 void SignalCompletionIfPossible() {
2128 if (!invalidated_on_impl_thread_ || !impl_side_invalidation_event_)
2129 return;
2130
2131 impl_side_invalidation_event_->Signal();
2132 impl_side_invalidation_event_ = nullptr;
2133 invalidated_on_impl_thread_ = false;
2134 }
2135
2136 void DidSendBeginMainFrameOnThread(LayerTreeHostImpl* host_impl) override {
2137 switch (++num_of_main_frames_) {
2138 case 1:
2139 // Do nothing for the first BeginMainFrame.
2140 break;
2141 case 2:
2142 // Add some more delta to the active tree state of the scroll offset and
2143 // a commit to send this additional delta to the main thread.
2144 host_impl->active_tree()
2145 ->OuterViewportScrollLayer()
2146 ->SetCurrentScrollOffset(outer_viewport_offsets_[1]);
2147 host_impl->SetNeedsCommit();
2148
2149 // Request an impl-side invalidation to create an impl-side pending
2150 // tree.
2151 host_impl->RequestImplSideInvalidation();
2152 break;
2153 case 3:
2154 // Request another impl-side invalidation so the aborted commit comes
2155 // after this tree is activated.
2156 host_impl->RequestImplSideInvalidation();
2157 break;
2158 default:
2159 NOTREACHED();
2160 }
2161 }
2162
2163 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
2164 CommitEarlyOutReason reason) override {
2165 // The aborted main frame is bound to come after the fourth activation,
2166 // since the activation should occur synchronously after the impl-side
2167 // invalidation, and the main thread is released after this activation. It
2168 // should leave the scroll offset unchanged.
2169 EXPECT_EQ(reason, CommitEarlyOutReason::FINISHED_NO_UPDATES);
2170 EXPECT_EQ(num_of_activations_, 4);
2171 EXPECT_EQ(num_of_main_frames_, 3);
2172 EXPECT_EQ(host_impl->active_tree()
2173 ->OuterViewportScrollLayer()
2174 ->CurrentScrollOffset(),
2175 outer_viewport_offsets_[2]);
2176 EndTest();
2177 }
2178
2179 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
2180 switch (++num_of_activations_) {
2181 case 1:
2182 // Now that we have the active tree, scroll a layer and ask for a commit
2183 // to send a BeginMainFrame with the scroll delta to the main thread.
2184 host_impl->active_tree()
2185 ->OuterViewportScrollLayer()
2186 ->SetCurrentScrollOffset(outer_viewport_offsets_[0]);
2187 host_impl->SetNeedsCommit();
2188 break;
2189 case 2:
2190 // The second activation is from an impl-side pending tree so the source
2191 // frame number on the active tree remains unchanged, and the scroll
2192 // offset on the active tree should also remain unchanged.
2193 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 0);
2194 EXPECT_EQ(host_impl->active_tree()
2195 ->OuterViewportScrollLayer()
2196 ->CurrentScrollOffset(),
2197 outer_viewport_offsets_[1]);
2198 break;
2199 case 3:
2200 // The third activation is from a commit. The scroll offset on the
2201 // active tree should include deltas sent from the main thread.
2202 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 1);
2203 EXPECT_EQ(host_impl->active_tree()
2204 ->OuterViewportScrollLayer()
2205 ->CurrentScrollOffset(),
2206 outer_viewport_offsets_[2]);
2207 break;
2208 case 4:
2209 // The fourth activation is from an impl-side pending tree, which should
2210 // leave the scroll offset unchanged.
2211 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 1);
2212 EXPECT_EQ(host_impl->active_tree()
2213 ->OuterViewportScrollLayer()
2214 ->CurrentScrollOffset(),
2215 outer_viewport_offsets_[2]);
2216 break;
2217 default:
2218 NOTREACHED();
2219 }
2220 }
2221
2222 void AfterTest() override {
2223 EXPECT_EQ(num_of_activations_, 4);
2224 EXPECT_EQ(num_of_deltas_, 2);
2225 EXPECT_EQ(num_of_main_frames_, 3);
2226 }
2227
2228 const gfx::ScrollOffset outer_viewport_offsets_[3] = {
2229 gfx::ScrollOffset(20, 20), gfx::ScrollOffset(50, 50),
2230 gfx::ScrollOffset(70, 70)};
2231
2232 // Impl thread.
2233 int num_of_activations_ = 0;
2234 int num_of_main_frames_ = 0;
2235 bool invalidated_on_impl_thread_ = false;
2236 CompletionEvent* impl_side_invalidation_event_ = nullptr;
2237
2238 // Main thread.
2239 int num_of_deltas_ = 0;
2240 };
2241
2242 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestImplSideInvalidation);
2243
2073 } // namespace 2244 } // namespace
2074 } // namespace cc 2245 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_checkerimaging.cc ('k') | cc/trees/layer_tree_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698