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. | |
sunnyps
2017/02/23 00:33:21
Can you trigger the deadline here and activate in
Khushal
2017/02/23 01:25:43
Hmmm, in fact I wanted to activate within this fra
| |
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, ImplSideInvalidationWhileMainFramePending) { | |
sunnyps
2017/02/23 00:33:21
nit: WhileReadyToCommit?
Khushal
2017/02/23 01:25:43
Done.
| |
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); | |
sunnyps
2017/02/23 00:33:21
We should check for invalidation in the deadline.
Khushal
2017/02/23 01:25:43
Done.
| |
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 | |
2269 TEST(SchedulerStateMachineTest, | |
2270 ConsecutiveImplSideInvalidationsWaitForBeginFrame) { | |
2271 SchedulerSettings settings; | |
2272 StateMachine state(settings); | |
2273 SET_UP_STATE(state); | |
2274 | |
2275 // Set up a request for impl-side invalidation. | |
2276 state.SetNeedsImplSideInvalidation(); | |
2277 state.OnBeginImplFrame(); | |
2278 state.OnBeginImplFrameDeadline(); | |
2279 EXPECT_ACTION_UPDATE_STATE( | |
2280 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2281 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2282 | |
2283 // Request another invalidation, which should wait until the pending tree is | |
2284 // activated *and* we start the next BeginFrame. | |
2285 state.SetNeedsImplSideInvalidation(); | |
2286 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2287 state.NotifyReadyToActivate(); | |
2288 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); | |
2289 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2290 | |
2291 // Now start the next frame, which will first draw the active tree and then | |
2292 // perform the pending impl-side invalidation request. | |
2293 state.OnBeginImplFrame(); | |
2294 state.OnBeginImplFrameDeadline(); | |
2295 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
2296 EXPECT_ACTION_UPDATE_STATE( | |
2297 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2298 } | |
2299 | |
2300 TEST(SchedulerStateMachineTest, ImplSideInvalidationsThrottledOnDraw) { | |
2301 // In commit_to_active_tree mode, performing the next invalidation should be | |
2302 // throttled on the active tree being drawn. | |
2303 SchedulerSettings settings; | |
2304 settings.commit_to_active_tree = true; | |
2305 StateMachine state(settings); | |
2306 SET_UP_STATE(state); | |
2307 | |
2308 // Commit to the sync tree, activate and draw. | |
2309 state.SetNeedsBeginMainFrame(); | |
2310 state.OnBeginImplFrame(); | |
2311 EXPECT_ACTION_UPDATE_STATE( | |
2312 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2313 state.NotifyBeginMainFrameStarted(); | |
2314 state.NotifyReadyToCommit(); | |
2315 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
2316 state.NotifyReadyToActivate(); | |
2317 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); | |
2318 state.NotifyReadyToDraw(); | |
2319 state.OnBeginImplFrameDeadline(); | |
2320 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
2321 state.DidSubmitCompositorFrame(); | |
2322 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2323 | |
2324 // Request impl-side invalidation and start a new frame, which should be | |
2325 // blocked on the ack for the previous frame. | |
2326 state.SetNeedsImplSideInvalidation(); | |
2327 state.OnBeginImplFrame(); | |
2328 state.OnBeginImplFrameDeadline(); | |
2329 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2330 | |
2331 // Ack the previous frame and begin impl frame, which shoul perrform the | |
sunnyps
2017/02/23 00:33:21
nit: should perform
Khushal
2017/02/23 01:25:43
Done.
| |
2332 // invalidation now. | |
2333 state.DidReceiveCompositorFrameAck(); | |
2334 state.OnBeginImplFrame(); | |
2335 state.OnBeginImplFrameDeadline(); | |
2336 EXPECT_ACTION_UPDATE_STATE( | |
2337 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2338 } | |
2339 | |
2340 TEST(SchedulerStateMachineTest, ImplSideInvalidationsAfterAbortedCommits) { | |
2341 SchedulerSettings settings; | |
2342 StateMachine state(settings); | |
2343 SET_UP_STATE(state); | |
2344 | |
2345 // Set up request for the main frame. | |
2346 state.SetNeedsBeginMainFrame(); | |
2347 state.OnBeginImplFrame(); | |
2348 EXPECT_ACTION_UPDATE_STATE( | |
2349 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
2350 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2351 | |
2352 // Request an impl-side invalidation, which should wait until a response is | |
2353 // received for the BeginMainFrame. | |
2354 state.SetNeedsImplSideInvalidation(); | |
2355 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
sunnyps
2017/02/23 00:33:21
Check for invalidation in deadline.
Khushal
2017/02/23 01:25:43
Actually, I don't know if the test makes sense any
| |
2356 | |
2357 // Request another main frame, and abort the sent BeginMainFrame. Aborting | |
2358 // this frame should create a pending tree for impl-side invalidation. | |
2359 state.SetNeedsBeginMainFrame(); | |
2360 state.NotifyBeginMainFrameStarted(); | |
2361 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); | |
2362 state.OnBeginImplFrameDeadline(); | |
2363 EXPECT_ACTION_UPDATE_STATE( | |
2364 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2365 } | |
2366 | |
2367 TEST(SchedulerStateMachineTest, PrepareTilesWaitForImplSideInvalidation) { | |
2368 // PrepareTiles | |
2369 SchedulerSettings settings; | |
2370 StateMachine state(settings); | |
2371 SET_UP_STATE(state); | |
2372 | |
2373 // Request a PrepareTiles and impl-side invalidation. The impl-side | |
2374 // invalidation should run first, since it will perform PrepareTiles as well. | |
2375 state.SetNeedsImplSideInvalidation(); | |
2376 state.SetNeedsPrepareTiles(); | |
2377 state.OnBeginImplFrame(); | |
2378 state.OnBeginImplFrameDeadline(); | |
2379 EXPECT_ACTION_UPDATE_STATE( | |
2380 SchedulerStateMachine::ACTION_PERFORM_IMPL_SIDE_INVALIDATION); | |
2381 state.DidPrepareTiles(); | |
2382 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
2383 } | |
2384 | |
2126 } // namespace | 2385 } // namespace |
2127 } // namespace cc | 2386 } // namespace cc |
OLD | NEW |