Chromium Code Reviews| 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/output/begin_frame_args.h" | |
| 10 #include "cc/scheduler/scheduler.h" | 11 #include "cc/scheduler/scheduler.h" |
| 11 #include "cc/test/begin_frame_args_test.h" | 12 #include "cc/test/begin_frame_args_test.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 // Macro to compare two enum values and get nice output. | 15 // Macro to compare two enum values and get nice output. |
| 15 // Without: | 16 // Without: |
| 16 // Value of: actual() Actual: 7 | 17 // Value of: actual() Actual: 7 |
| 17 // Expected: expected() Which is: 0 | 18 // Expected: expected() Which is: 0 |
| 18 // With: | 19 // With: |
| 19 // Value of: actual() Actual: "ACTION_DRAW" | 20 // Value of: actual() Actual: "ACTION_DRAW" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 public: | 80 public: |
| 80 explicit StateMachine(const SchedulerSettings& scheduler_settings) | 81 explicit StateMachine(const SchedulerSettings& scheduler_settings) |
| 81 : SchedulerStateMachine(scheduler_settings), | 82 : SchedulerStateMachine(scheduler_settings), |
| 82 draw_result_for_test_(DRAW_SUCCESS) {} | 83 draw_result_for_test_(DRAW_SUCCESS) {} |
| 83 | 84 |
| 84 void CreateAndInitializeCompositorFrameSinkWithActivatedCommit() { | 85 void CreateAndInitializeCompositorFrameSinkWithActivatedCommit() { |
| 85 DidCreateAndInitializeCompositorFrameSink(); | 86 DidCreateAndInitializeCompositorFrameSink(); |
| 86 compositor_frame_sink_state_ = COMPOSITOR_FRAME_SINK_ACTIVE; | 87 compositor_frame_sink_state_ = COMPOSITOR_FRAME_SINK_ACTIVE; |
| 87 } | 88 } |
| 88 | 89 |
| 90 void OnBeginImplFrame() { OnBeginImplFrame(0, next_begin_frame_number_++); } | |
| 91 | |
| 89 void SetBeginMainFrameState(BeginMainFrameState cs) { | 92 void SetBeginMainFrameState(BeginMainFrameState cs) { |
| 90 begin_main_frame_state_ = cs; | 93 begin_main_frame_state_ = cs; |
| 91 } | 94 } |
| 92 BeginMainFrameState BeginMainFrameState() const { | 95 BeginMainFrameState BeginMainFrameState() const { |
| 93 return begin_main_frame_state_; | 96 return begin_main_frame_state_; |
| 94 } | 97 } |
| 95 | 98 |
| 96 ForcedRedrawOnTimeoutState ForcedRedrawState() const { | 99 ForcedRedrawOnTimeoutState ForcedRedrawState() const { |
| 97 return forced_redraw_state_; | 100 return forced_redraw_state_; |
| 98 } | 101 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 | 146 |
| 144 bool PendingActivationsShouldBeForced() const { | 147 bool PendingActivationsShouldBeForced() const { |
| 145 return SchedulerStateMachine::PendingActivationsShouldBeForced(); | 148 return SchedulerStateMachine::PendingActivationsShouldBeForced(); |
| 146 } | 149 } |
| 147 | 150 |
| 148 bool has_pending_tree() const { return has_pending_tree_; } | 151 bool has_pending_tree() const { return has_pending_tree_; } |
| 149 void SetHasPendingTree(bool has_pending_tree) { | 152 void SetHasPendingTree(bool has_pending_tree) { |
| 150 has_pending_tree_ = has_pending_tree; | 153 has_pending_tree_ = has_pending_tree; |
| 151 } | 154 } |
| 152 | 155 |
| 156 uint64_t last_frame_number_pending_tree_was_fresh() const { | |
| 157 return last_frame_number_pending_tree_was_fresh_; | |
| 158 } | |
| 159 uint64_t last_frame_number_active_tree_was_fresh() const { | |
| 160 return last_frame_number_active_tree_was_fresh_; | |
| 161 } | |
| 162 | |
| 153 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately; | 163 using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately; |
| 154 using SchedulerStateMachine::ProactiveBeginFrameWanted; | 164 using SchedulerStateMachine::ProactiveBeginFrameWanted; |
| 155 using SchedulerStateMachine::WillCommit; | 165 using SchedulerStateMachine::WillCommit; |
| 166 using SchedulerStateMachine::OnBeginImplFrame; | |
| 156 | 167 |
| 157 protected: | 168 protected: |
| 158 DrawResult draw_result_for_test_; | 169 DrawResult draw_result_for_test_; |
| 170 uint64_t next_begin_frame_number_ = BeginFrameArgs::kStartingFrameNumber; | |
| 159 }; | 171 }; |
| 160 | 172 |
| 161 void PerformAction(StateMachine* sm, SchedulerStateMachine::Action action) { | 173 void PerformAction(StateMachine* sm, SchedulerStateMachine::Action action) { |
| 162 switch (action) { | 174 switch (action) { |
| 163 case SchedulerStateMachine::ACTION_NONE: | 175 case SchedulerStateMachine::ACTION_NONE: |
| 164 return; | 176 return; |
| 165 | 177 |
| 166 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE: | 178 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE: |
| 167 sm->WillActivate(); | 179 sm->WillActivate(); |
| 168 return; | 180 return; |
| (...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2143 | 2155 |
| 2144 // Cycle through the frame stages to clear the scheduler state. | 2156 // Cycle through the frame stages to clear the scheduler state. |
| 2145 state.OnBeginImplFrameDeadline(); | 2157 state.OnBeginImplFrameDeadline(); |
| 2146 state.OnBeginImplFrameIdle(); | 2158 state.OnBeginImplFrameIdle(); |
| 2147 | 2159 |
| 2148 // The scheduler should begin the CompositorFrameSink creation now. | 2160 // The scheduler should begin the CompositorFrameSink creation now. |
| 2149 EXPECT_ACTION_UPDATE_STATE( | 2161 EXPECT_ACTION_UPDATE_STATE( |
| 2150 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); | 2162 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); |
| 2151 } | 2163 } |
| 2152 | 2164 |
| 2165 TEST(SchedulerStateMachineTest, TestFrameNumbering) { | |
| 2166 SchedulerSettings default_scheduler_settings; | |
| 2167 | |
| 2168 { | |
|
Sami
2017/01/16 10:41:02
nit: Consider splitting each scope to a separate u
Eric Seckler
2017/01/16 14:33:01
Done.
| |
| 2169 // Initially, we report a valid current frame number, but invalid frame | |
| 2170 // numbers for freshness. | |
| 2171 StateMachine state(default_scheduler_settings); | |
| 2172 SET_UP_STATE(state) | |
| 2173 EXPECT_EQ(BeginFrameArgs::kStartingFrameNumber, | |
| 2174 state.current_frame_number()); | |
| 2175 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2176 state.last_frame_number_pending_tree_was_fresh()); | |
| 2177 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2178 state.last_frame_number_active_tree_was_fresh()); | |
| 2179 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2180 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2181 } | |
| 2182 | |
| 2183 { | |
| 2184 // Setup without any requested updates. | |
| 2185 StateMachine state(default_scheduler_settings); | |
| 2186 SET_UP_STATE(state) | |
| 2187 state.SetNeedsRedraw(false); | |
| 2188 EXPECT_FALSE(state.RedrawPending()); | |
| 2189 EXPECT_FALSE(state.NeedsCommit()); | |
| 2190 | |
| 2191 // OnBeginImplFrame() updates the current frame number. | |
| 2192 state.OnBeginImplFrame(0, 10); | |
| 2193 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2194 EXPECT_EQ(10u, state.current_frame_number()); | |
| 2195 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2196 state.last_frame_number_pending_tree_was_fresh()); | |
| 2197 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2198 state.last_frame_number_active_tree_was_fresh()); | |
| 2199 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2200 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2201 | |
| 2202 // When no updates are required, OnBeginImplFrameDeadline() updates active | |
| 2203 // tree and compositor frame freshness. | |
| 2204 state.OnBeginImplFrameDeadline(); | |
| 2205 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2206 EXPECT_EQ(10u, state.current_frame_number()); | |
| 2207 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2208 state.last_frame_number_pending_tree_was_fresh()); | |
| 2209 EXPECT_EQ(10u, state.last_frame_number_active_tree_was_fresh()); | |
| 2210 EXPECT_EQ(10u, state.last_frame_number_compositor_frame_was_fresh()); | |
| 2211 state.OnBeginImplFrameIdle(); | |
| 2212 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2213 } | |
| 2214 | |
| 2215 { | |
| 2216 // Setup with an impl-thread draw requested. | |
| 2217 StateMachine state(default_scheduler_settings); | |
| 2218 SET_UP_STATE(state) | |
| 2219 state.SetNeedsRedraw(true); | |
| 2220 EXPECT_TRUE(state.RedrawPending()); | |
| 2221 EXPECT_FALSE(state.NeedsCommit()); | |
| 2222 | |
| 2223 // OnBeginImplFrame() updates the current frame number. | |
| 2224 state.OnBeginImplFrame(0, 10); | |
| 2225 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2226 EXPECT_EQ(10u, state.current_frame_number()); | |
| 2227 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2228 state.last_frame_number_pending_tree_was_fresh()); | |
| 2229 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2230 state.last_frame_number_active_tree_was_fresh()); | |
| 2231 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2232 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2233 | |
| 2234 // With only an impl-thread draw requested, OnBeginImplFrameDeadline() | |
| 2235 // updates the active tree freshness. | |
| 2236 state.OnBeginImplFrameDeadline(); | |
| 2237 EXPECT_EQ(10u, state.current_frame_number()); | |
| 2238 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2239 state.last_frame_number_pending_tree_was_fresh()); | |
| 2240 EXPECT_EQ(10u, state.last_frame_number_active_tree_was_fresh()); | |
| 2241 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2242 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2243 | |
| 2244 // Compositor frame freshness is updated when active tree is drawn. | |
| 2245 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
| 2246 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2247 EXPECT_FALSE(state.RedrawPending()); | |
| 2248 state.DidSubmitCompositorFrame(); | |
| 2249 state.DidReceiveCompositorFrameAck(); | |
| 2250 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2251 EXPECT_EQ(10u, state.current_frame_number()); | |
| 2252 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2253 state.last_frame_number_pending_tree_was_fresh()); | |
| 2254 EXPECT_EQ(10u, state.last_frame_number_active_tree_was_fresh()); | |
| 2255 EXPECT_EQ(10u, state.last_frame_number_compositor_frame_was_fresh()); | |
| 2256 state.OnBeginImplFrameIdle(); | |
| 2257 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2258 } | |
| 2259 | |
| 2260 { | |
| 2261 // Setup with a BeginMainFrame requested. | |
| 2262 StateMachine state(default_scheduler_settings); | |
| 2263 SET_UP_STATE(state) | |
| 2264 state.SetNeedsRedraw(false); | |
| 2265 state.SetNeedsBeginMainFrameForTest(true); | |
| 2266 EXPECT_FALSE(state.RedrawPending()); | |
| 2267 EXPECT_TRUE(state.NeedsCommit()); | |
| 2268 | |
| 2269 // OnBeginImplFrame() updates the current frame number. | |
| 2270 state.OnBeginImplFrame(0, 10); | |
| 2271 EXPECT_ACTION_UPDATE_STATE( | |
| 2272 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
| 2273 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2274 EXPECT_FALSE(state.NeedsCommit()); | |
| 2275 EXPECT_TRUE(state.CommitPending()); | |
| 2276 EXPECT_EQ(10u, state.current_frame_number()); | |
| 2277 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2278 state.last_frame_number_pending_tree_was_fresh()); | |
| 2279 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2280 state.last_frame_number_active_tree_was_fresh()); | |
| 2281 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2282 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2283 | |
| 2284 // When a BeginMainFrame is needed, OnBeginImplFrameDeadline() updates no | |
| 2285 // freshness numbers. | |
| 2286 state.OnBeginImplFrameDeadline(); | |
| 2287 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2288 EXPECT_EQ(10u, state.current_frame_number()); | |
| 2289 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2290 state.last_frame_number_pending_tree_was_fresh()); | |
| 2291 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2292 state.last_frame_number_active_tree_was_fresh()); | |
| 2293 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2294 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2295 state.OnBeginImplFrameIdle(); | |
| 2296 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2297 | |
| 2298 // When a main frame is in progress, OnBeginImplFrameDeadline() updates no | |
| 2299 // freshness numbers. | |
| 2300 state.NotifyBeginMainFrameStarted(); | |
| 2301 state.OnBeginImplFrame(0, 11); | |
| 2302 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2303 state.OnBeginImplFrameDeadline(); | |
| 2304 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2305 EXPECT_EQ(11u, state.current_frame_number()); | |
| 2306 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2307 state.last_frame_number_pending_tree_was_fresh()); | |
| 2308 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2309 state.last_frame_number_active_tree_was_fresh()); | |
| 2310 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2311 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2312 state.OnBeginImplFrameIdle(); | |
| 2313 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2314 | |
| 2315 // Pending tree freshness is updated when the new pending tree is committed. | |
| 2316 state.NotifyReadyToCommit(); | |
| 2317 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); | |
| 2318 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2319 EXPECT_FALSE(state.CommitPending()); | |
| 2320 EXPECT_TRUE(state.has_pending_tree()); | |
| 2321 EXPECT_EQ(11u, state.current_frame_number()); | |
| 2322 EXPECT_EQ(10u, state.last_frame_number_pending_tree_was_fresh()); | |
| 2323 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2324 state.last_frame_number_active_tree_was_fresh()); | |
| 2325 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2326 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2327 | |
| 2328 // If no further BeginMainFrame is needed, OnBeginFrameImplDeadline() | |
| 2329 // updates the pending tree's frame number. | |
| 2330 state.OnBeginImplFrame(0, 12); | |
| 2331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2332 state.OnBeginImplFrameDeadline(); | |
| 2333 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2334 EXPECT_EQ(12u, state.current_frame_number()); | |
| 2335 EXPECT_EQ(12u, state.last_frame_number_pending_tree_was_fresh()); | |
| 2336 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2337 state.last_frame_number_active_tree_was_fresh()); | |
| 2338 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2339 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2340 state.OnBeginImplFrameIdle(); | |
| 2341 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2342 | |
| 2343 // If a further BeginMainFrame is needed, OnBeginFrameImplDeadline() | |
| 2344 // updates no freshness numbers. | |
| 2345 state.SetNeedsBeginMainFrameForTest(true); | |
| 2346 EXPECT_TRUE(state.NeedsCommit()); | |
| 2347 state.OnBeginImplFrame(0, 13); | |
| 2348 // BMF will be sent only after pending_tree activation. | |
| 2349 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2350 state.OnBeginImplFrameDeadline(); | |
| 2351 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2352 EXPECT_EQ(13u, state.current_frame_number()); | |
| 2353 EXPECT_EQ(12u, state.last_frame_number_pending_tree_was_fresh()); | |
| 2354 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2355 state.last_frame_number_active_tree_was_fresh()); | |
| 2356 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2357 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2358 state.OnBeginImplFrameIdle(); | |
| 2359 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2360 | |
| 2361 // Active tree freshness is updated when pending frame is activated. | |
| 2362 state.NotifyReadyToActivate(); | |
| 2363 EXPECT_ACTION_UPDATE_STATE( | |
| 2364 SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); | |
| 2365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2366 EXPECT_FALSE(state.has_pending_tree()); | |
| 2367 EXPECT_EQ(13u, state.current_frame_number()); | |
| 2368 EXPECT_EQ(12u, state.last_frame_number_pending_tree_was_fresh()); | |
| 2369 EXPECT_EQ(12u, state.last_frame_number_active_tree_was_fresh()); | |
| 2370 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2371 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2372 EXPECT_TRUE(state.RedrawPending()); | |
| 2373 | |
| 2374 // BMF requested above will be sent after activation. | |
| 2375 state.OnBeginImplFrame(0, 14); | |
| 2376 EXPECT_ACTION_UPDATE_STATE( | |
| 2377 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
| 2378 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2379 | |
| 2380 // Active tree freshness is updated when commit didn't have updates. | |
| 2381 state.NotifyBeginMainFrameStarted(); | |
| 2382 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); | |
| 2383 EXPECT_EQ(14u, state.current_frame_number()); | |
| 2384 EXPECT_EQ(12u, state.last_frame_number_pending_tree_was_fresh()); | |
| 2385 EXPECT_EQ(14u, state.last_frame_number_active_tree_was_fresh()); | |
| 2386 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2387 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2388 | |
| 2389 // Compositor frame freshness is updated when active tree is drawn. | |
| 2390 state.OnBeginImplFrameDeadline(); | |
| 2391 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); | |
| 2392 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2393 EXPECT_FALSE(state.RedrawPending()); | |
| 2394 state.DidSubmitCompositorFrame(); | |
| 2395 state.DidReceiveCompositorFrameAck(); | |
| 2396 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2397 EXPECT_EQ(14u, state.current_frame_number()); | |
| 2398 EXPECT_EQ(12u, state.last_frame_number_pending_tree_was_fresh()); | |
| 2399 EXPECT_EQ(14u, state.last_frame_number_active_tree_was_fresh()); | |
| 2400 EXPECT_EQ(14u, state.last_frame_number_compositor_frame_was_fresh()); | |
| 2401 state.OnBeginImplFrameIdle(); | |
| 2402 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2403 | |
| 2404 // When no updates are required, OnBeginImplFrameDeadline() updates active | |
| 2405 // tree and compositor frame freshness. | |
| 2406 state.OnBeginImplFrame(0, 15); | |
| 2407 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2408 state.OnBeginImplFrameDeadline(); | |
| 2409 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2410 EXPECT_EQ(15u, state.current_frame_number()); | |
| 2411 EXPECT_EQ(12u, state.last_frame_number_pending_tree_was_fresh()); | |
| 2412 EXPECT_EQ(15u, state.last_frame_number_active_tree_was_fresh()); | |
| 2413 EXPECT_EQ(15u, state.last_frame_number_compositor_frame_was_fresh()); | |
| 2414 state.OnBeginImplFrameIdle(); | |
| 2415 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2416 | |
| 2417 // When the source changes, the current frame number is updated and frame | |
| 2418 // numbers for freshness are reset to the prior frame number of the source. | |
| 2419 state.OnBeginImplFrame(1, 5); | |
| 2420 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2421 EXPECT_EQ(5u, state.current_frame_number()); | |
| 2422 EXPECT_EQ(4u, state.last_frame_number_pending_tree_was_fresh()); | |
| 2423 EXPECT_EQ(4u, state.last_frame_number_active_tree_was_fresh()); | |
| 2424 EXPECT_EQ(4u, state.last_frame_number_compositor_frame_was_fresh()); | |
| 2425 | |
| 2426 // When no updates are required, OnBeginImplFrameDeadline() updates active | |
| 2427 // tree and compositor frame freshness. | |
| 2428 state.OnBeginImplFrameDeadline(); | |
| 2429 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2430 EXPECT_EQ(5u, state.current_frame_number()); | |
| 2431 EXPECT_EQ(4u, state.last_frame_number_pending_tree_was_fresh()); | |
| 2432 EXPECT_EQ(5u, state.last_frame_number_active_tree_was_fresh()); | |
| 2433 EXPECT_EQ(5u, state.last_frame_number_compositor_frame_was_fresh()); | |
| 2434 state.OnBeginImplFrameIdle(); | |
| 2435 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2436 } | |
| 2437 | |
| 2438 { | |
| 2439 // Setup with main_frame_before_activation_enabled, a pending tree, and a | |
| 2440 // new BeginMainFrame requested. | |
| 2441 SchedulerSettings settings; | |
| 2442 settings.main_frame_before_activation_enabled = true; | |
| 2443 StateMachine state(settings); | |
| 2444 SET_UP_STATE(state) | |
| 2445 state.SetHasPendingTree(true); | |
| 2446 state.SetNeedsRedraw(false); | |
| 2447 state.SetNeedsBeginMainFrameForTest(true); | |
| 2448 EXPECT_FALSE(state.RedrawPending()); | |
| 2449 EXPECT_TRUE(state.NeedsCommit()); | |
| 2450 | |
| 2451 // OnBeginImplFrame() updates the current frame number. | |
| 2452 state.OnBeginImplFrame(0, 10); | |
| 2453 EXPECT_ACTION_UPDATE_STATE( | |
| 2454 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); | |
| 2455 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2456 EXPECT_FALSE(state.NeedsCommit()); | |
| 2457 EXPECT_TRUE(state.CommitPending()); | |
| 2458 EXPECT_EQ(10u, state.current_frame_number()); | |
| 2459 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2460 state.last_frame_number_pending_tree_was_fresh()); | |
| 2461 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2462 state.last_frame_number_active_tree_was_fresh()); | |
| 2463 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2464 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2465 | |
| 2466 // Pending tree freshness is updated when commit didn't have updates, but an | |
| 2467 // older pending tree is still pending. | |
| 2468 state.NotifyBeginMainFrameStarted(); | |
| 2469 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); | |
| 2470 EXPECT_EQ(10u, state.current_frame_number()); | |
| 2471 EXPECT_EQ(10u, state.last_frame_number_pending_tree_was_fresh()); | |
| 2472 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2473 state.last_frame_number_active_tree_was_fresh()); | |
| 2474 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2475 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2476 | |
| 2477 // As no further BeginMainFrame is needed, OnBeginFrameImplDeadline() | |
| 2478 // updates the pending tree's frame number, but without any visible change. | |
| 2479 state.OnBeginImplFrameDeadline(); | |
| 2480 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2481 EXPECT_EQ(10u, state.current_frame_number()); | |
| 2482 EXPECT_EQ(10u, state.last_frame_number_pending_tree_was_fresh()); | |
| 2483 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2484 state.last_frame_number_active_tree_was_fresh()); | |
| 2485 EXPECT_EQ(BeginFrameArgs::kInvalidFrameNumber, | |
| 2486 state.last_frame_number_compositor_frame_was_fresh()); | |
| 2487 state.OnBeginImplFrameIdle(); | |
| 2488 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); | |
| 2489 } | |
| 2490 } | |
| 2491 | |
| 2153 } // namespace | 2492 } // namespace |
| 2154 } // namespace cc | 2493 } // namespace cc |
| OLD | NEW |