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, NoImplSideInvalidationsWhileInvisible) { |
| 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 state.OnBeginImplFrame(); |
| 2143 state.OnBeginImplFrameDeadline(); |
| 2144 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2145 } |
| 2146 |
| 2147 TEST(SchedulerStateMachineTest, |
| 2148 NoImplSideInvalidationsWhenBeginFrameSourcePaused) { |
| 2149 SchedulerSettings settings; |
| 2150 StateMachine state(settings); |
| 2151 SET_UP_STATE(state); |
| 2152 |
| 2153 // No impl-side invalidations should be performed while we can not make impl |
| 2154 // frames. |
| 2155 state.SetBeginFrameSourcePaused(true); |
| 2156 state.SetNeedsImplSideInvalidation(); |
| 2157 state.OnBeginImplFrame(); |
| 2158 state.OnBeginImplFrameDeadline(); |
| 2159 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2160 } |
| 2161 |
| 2162 TEST(SchedulerStateMachineTest, ImplSideInvalidationOnlyInsideDeadline) { |
| 2163 SchedulerSettings settings; |
| 2164 StateMachine state(settings); |
| 2165 SET_UP_STATE(state); |
| 2166 |
| 2167 state.SetNeedsImplSideInvalidation(); |
| 2168 state.OnBeginImplFrame(); |
| 2169 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2170 state.OnBeginImplFrameDeadline(); |
| 2171 EXPECT_ACTION_UPDATE_STATE( |
| 2172 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); |
| 2173 } |
| 2174 |
| 2175 TEST(SchedulerStateMachineTest, |
| 2176 NoImplSideInvalidationWithoutCompositorFrameSink) { |
| 2177 SchedulerSettings settings; |
| 2178 StateMachine state(settings); |
| 2179 SET_UP_STATE(state); |
| 2180 |
| 2181 // Impl-side invalidations should not be triggered till the frame sink is |
| 2182 // initialized. |
| 2183 state.DidLoseCompositorFrameSink(); |
| 2184 EXPECT_ACTION_UPDATE_STATE( |
| 2185 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); |
| 2186 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2187 |
| 2188 // No impl-side invalidations should be performed during frame sink creation. |
| 2189 state.SetNeedsImplSideInvalidation(); |
| 2190 state.OnBeginImplFrame(); |
| 2191 state.OnBeginImplFrameDeadline(); |
| 2192 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2193 |
| 2194 // Initializing the CompositorFrameSink puts us in a state waiting for the |
| 2195 // first commit. |
| 2196 state.DidCreateAndInitializeCompositorFrameSink(); |
| 2197 state.OnBeginImplFrame(); |
| 2198 EXPECT_ACTION_UPDATE_STATE( |
| 2199 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 2200 state.NotifyBeginMainFrameStarted(); |
| 2201 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); |
| 2202 state.OnBeginImplFrameDeadline(); |
| 2203 EXPECT_ACTION_UPDATE_STATE( |
| 2204 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); |
| 2205 } |
| 2206 |
| 2207 TEST(SchedulerStateMachineTest, ImplSideInvalidationWhenPendingTreeExists) { |
| 2208 SchedulerSettings settings; |
| 2209 StateMachine state(settings); |
| 2210 SET_UP_STATE(state); |
| 2211 |
| 2212 // Set up request for the main frame, commit and create the pending tree. |
| 2213 state.SetNeedsBeginMainFrame(); |
| 2214 state.OnBeginImplFrame(); |
| 2215 EXPECT_ACTION_UPDATE_STATE( |
| 2216 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 2217 state.NotifyBeginMainFrameStarted(); |
| 2218 state.NotifyReadyToCommit(); |
| 2219 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 2220 |
| 2221 // Request an impl-side invalidation after the commit. The request should wait |
| 2222 // till the current pending tree is activated. |
| 2223 state.SetNeedsImplSideInvalidation(); |
| 2224 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2225 |
| 2226 // Activate the pending tree. Since the commit fills the impl-side |
| 2227 // invalidation funnel as well, the request should wait until the next |
| 2228 // BeginFrame. |
| 2229 state.NotifyReadyToActivate(); |
| 2230 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); |
| 2231 state.OnBeginImplFrameDeadline(); |
| 2232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 2233 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2234 |
| 2235 // Since there is no main frame request, this should perform impl-side |
| 2236 // invalidations. |
| 2237 state.OnBeginImplFrame(); |
| 2238 state.OnBeginImplFrameDeadline(); |
| 2239 EXPECT_ACTION_UPDATE_STATE( |
| 2240 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); |
| 2241 } |
| 2242 |
| 2243 TEST(SchedulerStateMachineTest, ImplSideInvalidationWhileReadyToCommit) { |
| 2244 SchedulerSettings settings; |
| 2245 StateMachine state(settings); |
| 2246 SET_UP_STATE(state); |
| 2247 |
| 2248 // Set up request for the main frame. |
| 2249 state.SetNeedsBeginMainFrame(); |
| 2250 state.OnBeginImplFrame(); |
| 2251 EXPECT_ACTION_UPDATE_STATE( |
| 2252 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 2253 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2254 |
| 2255 // Request an impl-side invalidation. The request should wait till a response |
| 2256 // is received from the main thread. |
| 2257 state.SetNeedsImplSideInvalidation(); |
| 2258 EXPECT_TRUE(state.needs_impl_side_invalidation()); |
| 2259 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2260 |
| 2261 // Perform a commit, the impl-side invalidation request should be reset since |
| 2262 // they will be merged with the commit. |
| 2263 state.NotifyBeginMainFrameStarted(); |
| 2264 state.NotifyReadyToCommit(); |
| 2265 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 2266 EXPECT_FALSE(state.needs_impl_side_invalidation()); |
| 2267 |
| 2268 // Deadline. |
| 2269 state.OnBeginImplFrameDeadline(); |
| 2270 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2271 } |
| 2272 |
| 2273 TEST(SchedulerStateMachineTest, |
| 2274 ConsecutiveImplSideInvalidationsWaitForBeginFrame) { |
| 2275 SchedulerSettings settings; |
| 2276 StateMachine state(settings); |
| 2277 SET_UP_STATE(state); |
| 2278 |
| 2279 // Set up a request for impl-side invalidation. |
| 2280 state.SetNeedsImplSideInvalidation(); |
| 2281 state.OnBeginImplFrame(); |
| 2282 state.OnBeginImplFrameDeadline(); |
| 2283 EXPECT_ACTION_UPDATE_STATE( |
| 2284 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); |
| 2285 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2286 |
| 2287 // Request another invalidation, which should wait until the pending tree is |
| 2288 // activated *and* we start the next BeginFrame. |
| 2289 state.SetNeedsImplSideInvalidation(); |
| 2290 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2291 state.NotifyReadyToActivate(); |
| 2292 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); |
| 2293 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2294 |
| 2295 // Now start the next frame, which will first draw the active tree and then |
| 2296 // perform the pending impl-side invalidation request. |
| 2297 state.OnBeginImplFrame(); |
| 2298 state.OnBeginImplFrameDeadline(); |
| 2299 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 2300 EXPECT_ACTION_UPDATE_STATE( |
| 2301 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); |
| 2302 } |
| 2303 |
| 2304 TEST(SchedulerStateMachineTest, ImplSideInvalidationsThrottledOnDraw) { |
| 2305 // In commit_to_active_tree mode, performing the next invalidation should be |
| 2306 // throttled on the active tree being drawn. |
| 2307 SchedulerSettings settings; |
| 2308 settings.commit_to_active_tree = true; |
| 2309 StateMachine state(settings); |
| 2310 SET_UP_STATE(state); |
| 2311 |
| 2312 // Commit to the sync tree, activate and draw. |
| 2313 state.SetNeedsBeginMainFrame(); |
| 2314 state.OnBeginImplFrame(); |
| 2315 EXPECT_ACTION_UPDATE_STATE( |
| 2316 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 2317 state.NotifyBeginMainFrameStarted(); |
| 2318 state.NotifyReadyToCommit(); |
| 2319 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); |
| 2320 state.NotifyReadyToActivate(); |
| 2321 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); |
| 2322 state.NotifyReadyToDraw(); |
| 2323 state.OnBeginImplFrameDeadline(); |
| 2324 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); |
| 2325 state.DidSubmitCompositorFrame(); |
| 2326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2327 |
| 2328 // Request impl-side invalidation and start a new frame, which should be |
| 2329 // blocked on the ack for the previous frame. |
| 2330 state.SetNeedsImplSideInvalidation(); |
| 2331 state.OnBeginImplFrame(); |
| 2332 state.OnBeginImplFrameDeadline(); |
| 2333 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2334 |
| 2335 // Ack the previous frame and begin impl frame, which should perform the |
| 2336 // invalidation now. |
| 2337 state.DidReceiveCompositorFrameAck(); |
| 2338 state.OnBeginImplFrame(); |
| 2339 state.OnBeginImplFrameDeadline(); |
| 2340 EXPECT_ACTION_UPDATE_STATE( |
| 2341 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); |
| 2342 } |
| 2343 |
| 2344 TEST(SchedulerStateMachineTest, |
| 2345 ImplSideInvalidationsWhenMainFrameRequestIsPending) { |
| 2346 SchedulerSettings settings; |
| 2347 StateMachine state(settings); |
| 2348 SET_UP_STATE(state); |
| 2349 |
| 2350 // Set up request for the main frame. |
| 2351 state.SetNeedsBeginMainFrame(); |
| 2352 state.OnBeginImplFrame(); |
| 2353 EXPECT_ACTION_UPDATE_STATE( |
| 2354 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); |
| 2355 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2356 |
| 2357 // Request an impl-side invalidation and trigger the deadline, the |
| 2358 // invalidation should run if the request is still pending when we enter the |
| 2359 // deadline. |
| 2360 state.SetNeedsImplSideInvalidation(); |
| 2361 state.OnBeginImplFrameDeadline(); |
| 2362 EXPECT_ACTION_UPDATE_STATE( |
| 2363 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); |
| 2364 } |
| 2365 |
| 2366 TEST(SchedulerStateMachineTest, PrepareTilesWaitForImplSideInvalidation) { |
| 2367 // PrepareTiles |
| 2368 SchedulerSettings settings; |
| 2369 StateMachine state(settings); |
| 2370 SET_UP_STATE(state); |
| 2371 |
| 2372 // Request a PrepareTiles and impl-side invalidation. The impl-side |
| 2373 // invalidation should run first, since it will perform PrepareTiles as well. |
| 2374 state.SetNeedsImplSideInvalidation(); |
| 2375 state.SetNeedsPrepareTiles(); |
| 2376 state.OnBeginImplFrame(); |
| 2377 state.OnBeginImplFrameDeadline(); |
| 2378 EXPECT_ACTION_UPDATE_STATE( |
| 2379 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); |
| 2380 state.DidPrepareTiles(); |
| 2381 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); |
| 2382 } |
| 2383 |
2126 } // namespace | 2384 } // namespace |
2127 } // namespace cc | 2385 } // namespace cc |
OLD | NEW |