OLD | NEW |
---|---|
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/scheduler/scheduler_state_machine.h" | 5 #include "cc/scheduler/scheduler_state_machine.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "cc/scheduler/scheduler.h" | 10 #include "cc/scheduler/scheduler.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 | 143 |
144 bool PendingActivationsShouldBeForced() const { | 144 bool PendingActivationsShouldBeForced() const { |
145 return SchedulerStateMachine::PendingActivationsShouldBeForced(); | 145 return SchedulerStateMachine::PendingActivationsShouldBeForced(); |
146 } | 146 } |
147 | 147 |
148 bool has_pending_tree() const { return has_pending_tree_; } | 148 bool has_pending_tree() const { return has_pending_tree_; } |
149 void SetHasPendingTree(bool has_pending_tree) { | 149 void SetHasPendingTree(bool has_pending_tree) { |
150 has_pending_tree_ = has_pending_tree; | 150 has_pending_tree_ = has_pending_tree; |
151 } | 151 } |
152 | 152 |
153 bool needs_impl_side_invalidation() const { | |
154 return needs_impl_side_invalidation_; | |
155 } | |
156 | |
153 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately; | 157 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately; |
154 using SchedulerStateMachine::ProactiveBeginFrameWanted; | 158 using SchedulerStateMachine::ProactiveBeginFrameWanted; |
155 using SchedulerStateMachine::WillCommit; | 159 using SchedulerStateMachine::WillCommit; |
156 | 160 |
157 protected: | 161 protected: |
158 DrawResult draw_result_for_test_; | 162 DrawResult draw_result_for_test_; |
159 }; | 163 }; |
160 | 164 |
161 void PerformAction(StateMachine* sm, SchedulerStateMachine::Action action) { | 165 void PerformAction(StateMachine* sm, SchedulerStateMachine::Action action) { |
162 switch (action) { | 166 switch (action) { |
(...skipping 30 matching lines...) Expand all Loading... | |
193 sm->WillBeginCompositorFrameSinkCreation(); | 197 sm->WillBeginCompositorFrameSinkCreation(); |
194 return; | 198 return; |
195 | 199 |
196 case SchedulerStateMachine::ACTION_PREPARE_TILES: | 200 case SchedulerStateMachine::ACTION_PREPARE_TILES: |
197 sm->WillPrepareTiles(); | 201 sm->WillPrepareTiles(); |
198 return; | 202 return; |
199 | 203 |
200 case SchedulerStateMachine::ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK: | 204 case SchedulerStateMachine::ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK: |
201 sm->WillInvalidateCompositorFrameSink(); | 205 sm->WillInvalidateCompositorFrameSink(); |
202 return; | 206 return; |
207 | |
208 case SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION: | |
209 sm->WillRunImplSideInvalidation(); | |
210 return; | |
203 } | 211 } |
204 } | 212 } |
205 | 213 |
206 TEST(SchedulerStateMachineTest, BeginFrameNeeded) { | 214 TEST(SchedulerStateMachineTest, BeginFrameNeeded) { |
207 SchedulerSettings default_scheduler_settings; | 215 SchedulerSettings default_scheduler_settings; |
208 StateMachine state(default_scheduler_settings); | 216 StateMachine state(default_scheduler_settings); |
209 state.SetVisible(true); | 217 state.SetVisible(true); |
210 EXPECT_ACTION_UPDATE_STATE( | 218 EXPECT_ACTION_UPDATE_STATE( |
211 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); | 219 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); |
212 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | 220 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
(...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2116 // to release the CompositorFrameSink. | 2124 // to release the CompositorFrameSink. |
2117 state.NotifyBeginMainFrameStarted(); | 2125 state.NotifyBeginMainFrameStarted(); |
2118 state.BeginMainFrameAborted( | 2126 state.BeginMainFrameAborted( |
2119 CommitEarlyOutReason::ABORTED_COMPOSITOR_FRAME_SINK_LOST); | 2127 CommitEarlyOutReason::ABORTED_COMPOSITOR_FRAME_SINK_LOST); |
2120 | 2128 |
2121 // The scheduler should begin the CompositorFrameSink creation now. | 2129 // The scheduler should begin the CompositorFrameSink creation now. |
2122 EXPECT_ACTION_UPDATE_STATE( | 2130 EXPECT_ACTION_UPDATE_STATE( |
2123 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); | 2131 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); |
2124 } | 2132 } |
2125 | 2133 |
2134 TEST(SchedulerStateMachineTest, NoImplSideInvalidationsWhileInvsible) { | |
2135 SchedulerSettings settings; | |
2136 StateMachine state(settings); | |
2137 SET_UP_STATE(state); | |
2138 | |
2139 // No impl-side invalidations should be performed while we are not visible. | |
sunnyps
2017/02/14 21:40:18
You should start a BeginFrame before testing inval
Khushal
2017/02/15 00:56:33
I'm not sure I followed this. The |impl_side_inval
sunnyps
2017/02/20 23:19:22
Ah, I assumed that the funnel is initialized to tr
| |
2140 state.SetVisible(false); | |
2141 state.SetNeedsImplSideInvalidation(); | |
2142 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2143 } | |
2144 | |
2145 TEST(SchedulerStateMachineTest, | |
2146 NoImplSideInvalidationsWhenBeginFrameSourcePaused) { | |
2147 SchedulerSettings settings; | |
2148 StateMachine state(settings); | |
2149 SET_UP_STATE(state); | |
2150 | |
2151 // No impl-side invalidations should be performed while we can not make impl | |
2152 // frames. | |
2153 state.SetBeginFrameSourcePaused(true); | |
sunnyps
2017/02/14 21:40:19
Same here.
| |
2154 state.SetNeedsImplSideInvalidation(); | |
2155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2156 } | |
2157 | |
2158 TEST(SchedulerStateMachineTest, | |
2159 NoImplSideInvalidationWithoutCompositorFrameSink) { | |
2160 SchedulerSettings settings; | |
2161 StateMachine state(settings); | |
2162 SET_UP_STATE(state); | |
2163 | |
2164 // Impl-side invalidations should not be triggered till the frame sink is | |
sunnyps
2017/02/14 21:40:19
Same here.
| |
2165 // initialized. | |
2166 state.DidLoseCompositorFrameSink(); | |
2167 EXPECT_ACTION_UPDATE_STATE( | |
2168 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); | |
2169 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2170 | |
2171 // No impl-side invalidations should be performed during frame sink creation. | |
2172 state.OnBeginImplFrame(); | |
2173 state.SetNeedsImplSideInvalidation(); | |
2174 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2175 | |
2176 // Initializing the CompositorFrameSink puts us in a state waiting for the | |
2177 // first commit. | |
2178 state.DidCreateAndInitializeCompositorFrameSink(); | |
2179 EXPECT_ACTION_UPDATE_STATE( | |
2180 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2181 state.NotifyBeginMainFrameStarted(); | |
2182 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); | |
2183 EXPECT_ACTION_UPDATE_STATE( | |
2184 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2185 } | |
2186 | |
2187 TEST(SchedulerStateMachineTest, ImplSideInvalidationWhenPendingTreeExists) { | |
2188 SchedulerSettings settings; | |
2189 StateMachine state(settings); | |
2190 SET_UP_STATE(state); | |
2191 | |
2192 // Set up request for the main frame, commit and create the pending tree. | |
2193 state.SetNeedsBeginMainFrame(); | |
2194 state.OnBeginImplFrame(); | |
2195 EXPECT_ACTION_UPDATE_STATE( | |
2196 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2197 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2198 state.NotifyBeginMainFrameStarted(); | |
2199 state.NotifyReadyToCommit(); | |
2200 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
2201 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2202 | |
2203 // Request an impl-side invalidation after the commit. The request should wait | |
2204 // till the current pending tree is activated. | |
2205 state.SetNeedsImplSideInvalidation(); | |
2206 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2207 | |
2208 // Activate the pending tree. Since the commit fills the impl-side | |
2209 // invalidation funnel as well, the request should wait until the next | |
2210 // BeginFrame. | |
2211 state.NotifyReadyToActivate(); | |
2212 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); | |
2213 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2214 | |
2215 // Since there is no main frame request, this should perform impl-side | |
2216 // invalidations. | |
2217 state.OnBeginImplFrame(); | |
2218 EXPECT_ACTION_UPDATE_STATE( | |
2219 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2220 } | |
2221 | |
2222 TEST(SchedulerStateMachineTest, ImplSideInvalidationWhileMainFramePending) { | |
2223 SchedulerSettings settings; | |
2224 StateMachine state(settings); | |
2225 SET_UP_STATE(state); | |
2226 | |
2227 // Set up request for the main frame. | |
2228 state.SetNeedsBeginMainFrame(); | |
2229 state.OnBeginImplFrame(); | |
2230 EXPECT_ACTION_UPDATE_STATE( | |
2231 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2233 | |
2234 // Request an impl-side invalidation. The request should wait till a response | |
2235 // is received from the main thread. | |
2236 state.SetNeedsImplSideInvalidation(); | |
2237 EXPECT_TRUE(state.needs_impl_side_invalidation()); | |
2238 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2239 | |
2240 // Perform a commit, the impl-side invalidation request should be reset since | |
2241 // they will be merged with the commit. | |
2242 state.NotifyBeginMainFrameStarted(); | |
2243 state.NotifyReadyToCommit(); | |
2244 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
2245 EXPECT_FALSE(state.needs_impl_side_invalidation()); | |
2246 } | |
2247 | |
2248 TEST(SchedulerStateMachineTest, | |
2249 ConsecutiveImplSideInvalidationsWaitForBeginFrame) { | |
2250 SchedulerSettings settings; | |
2251 StateMachine state(settings); | |
2252 SET_UP_STATE(state); | |
2253 | |
2254 // Set up a request for impl-side invalidation. | |
2255 state.SetNeedsImplSideInvalidation(); | |
2256 state.OnBeginImplFrame(); | |
2257 EXPECT_ACTION_UPDATE_STATE( | |
2258 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2259 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2260 | |
2261 // Request another invalidation before the pending tree is activated. The | |
2262 // request should wait until the next BeginFrame. | |
2263 state.SetNeedsImplSideInvalidation(); | |
2264 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2265 state.NotifyReadyToActivate(); | |
2266 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); | |
2267 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2268 state.OnBeginImplFrame(); | |
2269 EXPECT_ACTION_UPDATE_STATE( | |
2270 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2271 } | |
2272 | |
2273 TEST(SchedulerStateMachineTest, ImplSideInvalidationsThrottledOnDraw) { | |
2274 // In commit_to_active_tree mode, performing the next invalidation should be | |
2275 // throttled on the active tree being drawn. | |
2276 SchedulerSettings settings; | |
2277 settings.commit_to_active_tree = true; | |
2278 StateMachine state(settings); | |
2279 SET_UP_STATE(state); | |
2280 | |
2281 // Commit to the sync tree and activate. | |
2282 state.SetNeedsBeginMainFrame(); | |
2283 state.OnBeginImplFrame(); | |
2284 EXPECT_ACTION_UPDATE_STATE( | |
2285 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2286 state.NotifyBeginMainFrameStarted(); | |
2287 state.NotifyReadyToCommit(); | |
2288 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
2289 state.NotifyReadyToActivate(); | |
2290 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); | |
2291 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2292 | |
2293 // BeginImplFrame deadline, the draw is blocked on NotifyReadyToDraw. | |
2294 state.OnBeginImplFrameDeadline(); | |
2295 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2296 | |
2297 // Request impl-side invalidation which should be blocked on the active tree | |
2298 // being drawn and submitted. | |
2299 state.SetNeedsImplSideInvalidation(); | |
2300 state.OnBeginImplFrame(); | |
2301 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2302 state.NotifyReadyToDraw(); | |
2303 state.OnBeginImplFrameDeadline(); | |
2304 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
2305 state.DidSubmitCompositorFrame(); | |
2306 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2307 state.DidReceiveCompositorFrameAck(); | |
2308 | |
2309 // The frame being acked should perform impl-side invalidation. | |
2310 EXPECT_ACTION_UPDATE_STATE( | |
2311 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2312 } | |
2313 | |
2314 TEST(SchedulerStateMachineTest, | |
2315 ImplSideInvalidationsTakePriorityForAbortedCommits) { | |
2316 SchedulerSettings settings; | |
2317 StateMachine state(settings); | |
2318 SET_UP_STATE(state); | |
2319 | |
2320 // Set up request for the main frame. | |
2321 state.SetNeedsBeginMainFrame(); | |
2322 state.OnBeginImplFrame(); | |
2323 EXPECT_ACTION_UPDATE_STATE( | |
2324 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2325 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2326 | |
2327 // Request an impl-side invalidation, which should wait until a response is | |
2328 // received for the BeginMainFrame. | |
2329 state.SetNeedsImplSideInvalidation(); | |
2330 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2331 | |
2332 // Request another main frame, and abort the sent BeginMainFrame. Aborting | |
2333 // this frame should create a pending tree for impl-side invalidation. | |
2334 state.SetNeedsBeginMainFrame(); | |
2335 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2336 state.NotifyBeginMainFrameStarted(); | |
2337 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); | |
sunnyps
2017/02/14 21:40:18
After aborting the commit send BeginMainFrame agai
Khushal
2017/02/15 00:56:33
Done.
Khushal
2017/02/15 03:23:52
Actually, while adding the SchedulerTest for this,
| |
2338 EXPECT_ACTION_UPDATE_STATE( | |
2339 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2340 } | |
2341 | |
2342 TEST(SchedulerStateMachineTest, | |
2343 ImplSideInvalidationsBlockedOnSendingBeginMainFrame) { | |
2344 SchedulerSettings settings; | |
2345 StateMachine state(settings); | |
2346 SET_UP_STATE(state); | |
2347 | |
2348 // BeginMainFrame, commit and activate the sync tree. | |
2349 state.SetNeedsBeginMainFrame(); | |
2350 state.OnBeginImplFrame(); | |
2351 EXPECT_ACTION_UPDATE_STATE( | |
2352 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2353 state.NotifyBeginMainFrameStarted(); | |
2354 state.NotifyReadyToCommit(); | |
2355 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
2356 state.NotifyReadyToActivate(); | |
2357 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); | |
2358 | |
2359 // Set the tree priority to smoothness mode and request a main frame and | |
2360 // impl-side invalidations. | |
sunnyps
2017/02/14 21:40:19
Can you explain what tree priority has to do with
Khushal
2017/02/15 00:56:33
This was just to get a case for:
if (CouldSendBe
| |
2361 state.OnBeginImplFrameDeadline(); | |
2362 state.OnBeginImplFrame(); | |
2363 state.SetTreePrioritiesAndScrollState( | |
2364 TreePriority::SMOOTHNESS_TAKES_PRIORITY, | |
2365 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER); | |
2366 state.SetNeedsBeginMainFrame(); | |
2367 state.SetNeedsImplSideInvalidation(); | |
2368 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2369 | |
2370 // The impl-side invalidations should wait until BeginMainFrame is sent and | |
2371 // a response is received. | |
2372 state.SetTreePrioritiesAndScrollState( | |
2373 TreePriority::SMOOTHNESS_TAKES_PRIORITY, | |
2374 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER); | |
2375 EXPECT_ACTION_UPDATE_STATE( | |
2376 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2377 state.NotifyBeginMainFrameStarted(); | |
2378 state.NotifyReadyToCommit(); | |
2379 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
2380 EXPECT_FALSE(state.needs_impl_side_invalidation()); | |
2381 } | |
2382 | |
2126 } // namespace | 2383 } // namespace |
2127 } // namespace cc | 2384 } // namespace cc |
OLD | NEW |