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->WillPerformImplSideInvalidation(); | |
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) { | |
brianderson
2017/02/21 23:34:59
Invsible -> Invisible
Khushal
2017/02/22 20:24:02
Done.
| |
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. | |
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); | |
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 | |
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 settings.main_frame_before_activation_enabled = true; | |
2318 StateMachine state(settings); | |
2319 SET_UP_STATE(state); | |
2320 | |
2321 // Set up request for the main frame. | |
2322 state.SetNeedsBeginMainFrame(); | |
2323 state.OnBeginImplFrame(); | |
2324 EXPECT_ACTION_UPDATE_STATE( | |
2325 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2327 | |
2328 // Request an impl-side invalidation, which should wait until a response is | |
2329 // received for the BeginMainFrame. | |
2330 state.SetNeedsImplSideInvalidation(); | |
2331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2332 | |
2333 // Request another main frame, and abort the sent BeginMainFrame. Aborting | |
2334 // this frame should create a pending tree for impl-side invalidation. | |
2335 state.SetNeedsBeginMainFrame(); | |
2336 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2337 state.NotifyBeginMainFrameStarted(); | |
2338 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); | |
2339 EXPECT_ACTION_UPDATE_STATE( | |
2340 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2341 | |
2342 // Trigger the frame deadline, this should send the BeginMainFrame since MFBA | |
2343 // is enabled. | |
2344 state.OnBeginImplFrameDeadline(); | |
2345 state.OnBeginImplFrame(); | |
2346 EXPECT_ACTION_UPDATE_STATE( | |
2347 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2348 } | |
2349 | |
2350 TEST(SchedulerStateMachineTest, | |
2351 ImplSideInvalidationsBlockedOnSendingBeginMainFrame) { | |
2352 SchedulerSettings settings; | |
2353 StateMachine state(settings); | |
2354 SET_UP_STATE(state); | |
2355 | |
2356 // BeginMainFrame, commit and activate the sync tree. | |
2357 state.SetNeedsBeginMainFrame(); | |
2358 state.OnBeginImplFrame(); | |
2359 EXPECT_ACTION_UPDATE_STATE( | |
2360 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2361 state.NotifyBeginMainFrameStarted(); | |
2362 state.NotifyReadyToCommit(); | |
2363 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
2364 state.NotifyReadyToActivate(); | |
2365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); | |
2366 | |
2367 // Set the tree priority to smoothness mode and request a main frame and | |
2368 // impl-side invalidations. | |
2369 state.OnBeginImplFrameDeadline(); | |
2370 state.OnBeginImplFrame(); | |
2371 state.SetTreePrioritiesAndScrollState( | |
2372 TreePriority::SMOOTHNESS_TAKES_PRIORITY, | |
2373 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER); | |
2374 state.SetNeedsBeginMainFrame(); | |
2375 state.SetNeedsImplSideInvalidation(); | |
2376 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2377 | |
2378 // The impl-side invalidations should wait until BeginMainFrame is sent and | |
2379 // a response is received. | |
2380 state.SetTreePrioritiesAndScrollState( | |
2381 TreePriority::SMOOTHNESS_TAKES_PRIORITY, | |
2382 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER); | |
2383 EXPECT_ACTION_UPDATE_STATE( | |
2384 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2385 state.NotifyBeginMainFrameStarted(); | |
2386 state.NotifyReadyToCommit(); | |
2387 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
2388 EXPECT_FALSE(state.needs_impl_side_invalidation()); | |
2389 } | |
2390 | |
2391 TEST(SchedulerStateMachineTest, BeginMainFrameAfterImplSideInvalidation) { | |
2392 // A BeginMainFrame should be sent, if the request is received after an | |
2393 // impl-side invalidation. | |
2394 SchedulerSettings settings; | |
2395 settings.main_frame_before_activation_enabled = true; | |
2396 StateMachine state(settings); | |
2397 SET_UP_STATE(state); | |
2398 | |
2399 // Request an impl side invalidation and perform the action. | |
2400 state.SetNeedsImplSideInvalidation(); | |
2401 state.OnBeginImplFrame(); | |
2402 EXPECT_ACTION_UPDATE_STATE( | |
2403 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2404 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2405 | |
2406 // Request a main frame, which should be sent within the same BeginFrame in | |
2407 // MFBA mode. | |
2408 state.SetNeedsBeginMainFrame(); | |
2409 EXPECT_ACTION_UPDATE_STATE( | |
2410 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2411 } | |
2412 | |
2126 } // namespace | 2413 } // namespace |
2127 } // namespace cc | 2414 } // namespace cc |
OLD | NEW |