Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: cc/scheduler_state_machine_unittest.cc

Issue 11830040: cc: Do not request redraw on commit when impl-side painting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@decouple_draw3
Patch Set: Use CC_EXPORT Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/scheduler_state_machine.cc ('k') | cc/scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_state_machine.h" 5 #include "cc/scheduler_state_machine.h"
6 6
7 #include "cc/scheduler.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 9
9 namespace cc { 10 namespace cc {
11
10 namespace { 12 namespace {
11 13
12 const SchedulerStateMachine::CommitState allCommitStates[] = { 14 const SchedulerStateMachine::CommitState allCommitStates[] = {
13 SchedulerStateMachine::COMMIT_STATE_IDLE, 15 SchedulerStateMachine::COMMIT_STATE_IDLE,
14 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 16 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
15 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 17 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
16 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW 18 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW
17 }; 19 };
18 20
19 // Exposes the protected state fields of the SchedulerStateMachine for testing 21 // Exposes the protected state fields of the SchedulerStateMachine for testing
20 class StateMachine : public SchedulerStateMachine { 22 class StateMachine : public SchedulerStateMachine {
21 public: 23 public:
24 StateMachine(const SchedulerSettings& schedulerSettings)
25 : SchedulerStateMachine(schedulerSettings) { }
22 void setCommitState(CommitState cs) { m_commitState = cs; } 26 void setCommitState(CommitState cs) { m_commitState = cs; }
23 CommitState commitState() const { return m_commitState; } 27 CommitState commitState() const { return m_commitState; }
24 28
25 bool needsCommit() const { return m_needsCommit; } 29 bool needsCommit() const { return m_needsCommit; }
26 30
27 void setNeedsRedraw(bool b) { m_needsRedraw = b; } 31 void setNeedsRedraw(bool b) { m_needsRedraw = b; }
28 bool needsRedraw() const { return m_needsRedraw; } 32 bool needsRedraw() const { return m_needsRedraw; }
29 33
30 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; } 34 void setNeedsForcedRedraw(bool b) { m_needsForcedRedraw = b; }
31 bool needsForcedRedraw() const { return m_needsForcedRedraw; } 35 bool needsForcedRedraw() const { return m_needsForcedRedraw; }
32 36
33 bool canDraw() const { return m_canDraw; } 37 bool canDraw() const { return m_canDraw; }
34 bool insideVSync() const { return m_insideVSync; } 38 bool insideVSync() const { return m_insideVSync; }
35 bool visible() const { return m_visible; } 39 bool visible() const { return m_visible; }
36 }; 40 };
37 41
38 TEST(SchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded) 42 TEST(SchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded)
39 { 43 {
44 SchedulerSettings defaultSchedulerSettings;
45
40 // If no commit needed, do nothing 46 // If no commit needed, do nothing
41 { 47 {
42 StateMachine state; 48 StateMachine state(defaultSchedulerSettings);
43 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 49 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
44 state.setCanBeginFrame(true); 50 state.setCanBeginFrame(true);
45 state.setNeedsRedraw(false); 51 state.setNeedsRedraw(false);
46 state.setVisible(true); 52 state.setVisible(true);
47 53
48 EXPECT_FALSE(state.vsyncCallbackNeeded()); 54 EXPECT_FALSE(state.vsyncCallbackNeeded());
49 55
50 state.didLeaveVSync(); 56 state.didLeaveVSync();
51 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 57 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
52 EXPECT_FALSE(state.vsyncCallbackNeeded()); 58 EXPECT_FALSE(state.vsyncCallbackNeeded());
53 state.didEnterVSync(); 59 state.didEnterVSync();
54 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 60 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
55 } 61 }
56 62
57 // If commit requested but canBeginFrame is still false, do nothing. 63 // If commit requested but canBeginFrame is still false, do nothing.
58 { 64 {
59 StateMachine state; 65 StateMachine state(defaultSchedulerSettings);
60 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 66 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
61 state.setNeedsRedraw(false); 67 state.setNeedsRedraw(false);
62 state.setVisible(true); 68 state.setVisible(true);
63 69
64 EXPECT_FALSE(state.vsyncCallbackNeeded()); 70 EXPECT_FALSE(state.vsyncCallbackNeeded());
65 71
66 state.didLeaveVSync(); 72 state.didLeaveVSync();
67 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 73 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
68 EXPECT_FALSE(state.vsyncCallbackNeeded()); 74 EXPECT_FALSE(state.vsyncCallbackNeeded());
69 state.didEnterVSync(); 75 state.didEnterVSync();
70 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 76 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
71 } 77 }
72 78
73 79
74 // If commit requested, begin a frame 80 // If commit requested, begin a frame
75 { 81 {
76 StateMachine state; 82 StateMachine state(defaultSchedulerSettings);
77 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 83 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
78 state.setCanBeginFrame(true); 84 state.setCanBeginFrame(true);
79 state.setNeedsRedraw(false); 85 state.setNeedsRedraw(false);
80 state.setVisible(true); 86 state.setVisible(true);
81 EXPECT_FALSE(state.vsyncCallbackNeeded()); 87 EXPECT_FALSE(state.vsyncCallbackNeeded());
82 } 88 }
83 89
84 // Begin the frame, make sure needsCommit and commitState update correctly. 90 // Begin the frame, make sure needsCommit and commitState update correctly.
85 { 91 {
86 StateMachine state; 92 StateMachine state(defaultSchedulerSettings);
87 state.setCanBeginFrame(true); 93 state.setCanBeginFrame(true);
88 state.setVisible(true); 94 state.setVisible(true);
89 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 95 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
90 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.c ommitState()); 96 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.c ommitState());
91 EXPECT_FALSE(state.needsCommit()); 97 EXPECT_FALSE(state.needsCommit());
92 EXPECT_FALSE(state.vsyncCallbackNeeded()); 98 EXPECT_FALSE(state.vsyncCallbackNeeded());
93 } 99 }
94 } 100 }
95 101
96 TEST(SchedulerStateMachineTest, TestSetForcedRedrawDoesNotSetsNormalRedraw) 102 TEST(SchedulerStateMachineTest, TestSetForcedRedrawDoesNotSetsNormalRedraw)
97 { 103 {
98 SchedulerStateMachine state; 104 SchedulerSettings defaultSchedulerSettings;
105 SchedulerStateMachine state(defaultSchedulerSettings);
99 state.setCanDraw(true); 106 state.setCanDraw(true);
100 state.setNeedsForcedRedraw(); 107 state.setNeedsForcedRedraw();
101 EXPECT_FALSE(state.redrawPending()); 108 EXPECT_FALSE(state.redrawPending());
102 EXPECT_TRUE(state.vsyncCallbackNeeded()); 109 EXPECT_TRUE(state.vsyncCallbackNeeded());
103 } 110 }
104 111
105 TEST(SchedulerStateMachineTest, TestFailedDrawSetsNeedsCommitAndDoesNotDrawAgain ) 112 TEST(SchedulerStateMachineTest, TestFailedDrawSetsNeedsCommitAndDoesNotDrawAgain )
106 { 113 {
107 SchedulerStateMachine state; 114 SchedulerSettings defaultSchedulerSettings;
115 SchedulerStateMachine state(defaultSchedulerSettings);
108 state.setCanBeginFrame(true); 116 state.setCanBeginFrame(true);
109 state.setVisible(true); 117 state.setVisible(true);
110 state.setCanDraw(true); 118 state.setCanDraw(true);
111 state.setNeedsRedraw(); 119 state.setNeedsRedraw();
112 EXPECT_TRUE(state.redrawPending()); 120 EXPECT_TRUE(state.redrawPending());
113 EXPECT_TRUE(state.vsyncCallbackNeeded()); 121 EXPECT_TRUE(state.vsyncCallbackNeeded());
114 state.didEnterVSync(); 122 state.didEnterVSync();
115 123
116 // We're drawing now. 124 // We're drawing now.
117 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 125 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
118 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 126 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
119 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 127 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
120 EXPECT_FALSE(state.redrawPending()); 128 EXPECT_FALSE(state.redrawPending());
121 EXPECT_FALSE(state.commitPending()); 129 EXPECT_FALSE(state.commitPending());
122 130
123 // Failing the draw makes us require a commit. 131 // Failing the draw makes us require a commit.
124 state.didDrawIfPossibleCompleted(false); 132 state.didDrawIfPossibleCompleted(false);
125 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 133 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
126 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 134 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
127 EXPECT_TRUE(state.redrawPending()); 135 EXPECT_TRUE(state.redrawPending());
128 EXPECT_TRUE(state.commitPending()); 136 EXPECT_TRUE(state.commitPending());
129 } 137 }
130 138
131 TEST(SchedulerStateMachineTest, TestSetNeedsRedrawDuringFailedDrawDoesNotRemoveN eedsRedraw) 139 TEST(SchedulerStateMachineTest, TestSetNeedsRedrawDuringFailedDrawDoesNotRemoveN eedsRedraw)
132 { 140 {
133 SchedulerStateMachine state; 141 SchedulerSettings defaultSchedulerSettings;
142 SchedulerStateMachine state(defaultSchedulerSettings);
134 state.setCanBeginFrame(true); 143 state.setCanBeginFrame(true);
135 state.setVisible(true); 144 state.setVisible(true);
136 state.setCanDraw(true); 145 state.setCanDraw(true);
137 state.setNeedsRedraw(); 146 state.setNeedsRedraw();
138 EXPECT_TRUE(state.redrawPending()); 147 EXPECT_TRUE(state.redrawPending());
139 EXPECT_TRUE(state.vsyncCallbackNeeded()); 148 EXPECT_TRUE(state.vsyncCallbackNeeded());
140 state.didEnterVSync(); 149 state.didEnterVSync();
141 150
142 // We're drawing now. 151 // We're drawing now.
143 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 152 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
144 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 153 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
145 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 154 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
146 EXPECT_FALSE(state.redrawPending()); 155 EXPECT_FALSE(state.redrawPending());
147 EXPECT_FALSE(state.commitPending()); 156 EXPECT_FALSE(state.commitPending());
148 157
149 // While still in the same vsync callback, set needs redraw again. 158 // While still in the same vsync callback, set needs redraw again.
150 // This should not redraw. 159 // This should not redraw.
151 state.setNeedsRedraw(); 160 state.setNeedsRedraw();
152 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 161 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
153 162
154 // Failing the draw makes us require a commit. 163 // Failing the draw makes us require a commit.
155 state.didDrawIfPossibleCompleted(false); 164 state.didDrawIfPossibleCompleted(false);
156 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 165 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
157 EXPECT_TRUE(state.redrawPending()); 166 EXPECT_TRUE(state.redrawPending());
158 } 167 }
159 168
160 TEST(SchedulerStateMachineTest, TestCommitAfterFailedDrawAllowsDrawInSameFrame) 169 TEST(SchedulerStateMachineTest, TestCommitAfterFailedDrawAllowsDrawInSameFrame)
161 { 170 {
162 SchedulerStateMachine state; 171 SchedulerSettings defaultSchedulerSettings;
172 SchedulerStateMachine state(defaultSchedulerSettings);
163 state.setCanBeginFrame(true); 173 state.setCanBeginFrame(true);
164 state.setVisible(true); 174 state.setVisible(true);
165 state.setCanDraw(true); 175 state.setCanDraw(true);
166 176
167 // Start a commit. 177 // Start a commit.
168 state.setNeedsCommit(); 178 state.setNeedsCommit();
169 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 179 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
170 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 180 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
171 EXPECT_TRUE(state.commitPending()); 181 EXPECT_TRUE(state.commitPending());
172 182
(...skipping 17 matching lines...) Expand all
190 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); 200 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
191 state.updateState(SchedulerStateMachine::ACTION_COMMIT); 201 state.updateState(SchedulerStateMachine::ACTION_COMMIT);
192 EXPECT_TRUE(state.redrawPending()); 202 EXPECT_TRUE(state.redrawPending());
193 203
194 // And we should be allowed to draw again. 204 // And we should be allowed to draw again.
195 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 205 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
196 } 206 }
197 207
198 TEST(SchedulerStateMachineTest, TestCommitAfterFailedAndSuccessfulDrawDoesNotAll owDrawInSameFrame) 208 TEST(SchedulerStateMachineTest, TestCommitAfterFailedAndSuccessfulDrawDoesNotAll owDrawInSameFrame)
199 { 209 {
200 SchedulerStateMachine state; 210 SchedulerSettings defaultSchedulerSettings;
211 SchedulerStateMachine state(defaultSchedulerSettings);
201 state.setCanBeginFrame(true); 212 state.setCanBeginFrame(true);
202 state.setVisible(true); 213 state.setVisible(true);
203 state.setCanDraw(true); 214 state.setCanDraw(true);
204 215
205 // Start a commit. 216 // Start a commit.
206 state.setNeedsCommit(); 217 state.setNeedsCommit();
207 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 218 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
208 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 219 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
209 EXPECT_TRUE(state.commitPending()); 220 EXPECT_TRUE(state.commitPending());
210 221
(...skipping 28 matching lines...) Expand all
239 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); 250 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
240 state.updateState(SchedulerStateMachine::ACTION_COMMIT); 251 state.updateState(SchedulerStateMachine::ACTION_COMMIT);
241 EXPECT_TRUE(state.redrawPending()); 252 EXPECT_TRUE(state.redrawPending());
242 253
243 // And we should not be allowed to draw again in the same frame.. 254 // And we should not be allowed to draw again in the same frame..
244 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 255 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
245 } 256 }
246 257
247 TEST(SchedulerStateMachineTest, TestFailedDrawsWillEventuallyForceADrawAfterTheN extCommit) 258 TEST(SchedulerStateMachineTest, TestFailedDrawsWillEventuallyForceADrawAfterTheN extCommit)
248 { 259 {
249 SchedulerStateMachine state; 260 SchedulerSettings defaultSchedulerSettings;
261 SchedulerStateMachine state(defaultSchedulerSettings);
250 state.setCanBeginFrame(true); 262 state.setCanBeginFrame(true);
251 state.setVisible(true); 263 state.setVisible(true);
252 state.setCanDraw(true); 264 state.setCanDraw(true);
253 state.setMaximumNumberOfFailedDrawsBeforeDrawIsForced(1); 265 state.setMaximumNumberOfFailedDrawsBeforeDrawIsForced(1);
254 266
255 // Start a commit. 267 // Start a commit.
256 state.setNeedsCommit(); 268 state.setNeedsCommit();
257 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 269 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
258 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 270 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
259 EXPECT_TRUE(state.commitPending()); 271 EXPECT_TRUE(state.commitPending());
(...skipping 19 matching lines...) Expand all
279 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); 291 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
280 state.updateState(SchedulerStateMachine::ACTION_COMMIT); 292 state.updateState(SchedulerStateMachine::ACTION_COMMIT);
281 EXPECT_TRUE(state.redrawPending()); 293 EXPECT_TRUE(state.redrawPending());
282 294
283 // The redraw should be forced in this case. 295 // The redraw should be forced in this case.
284 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); 296 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction());
285 } 297 }
286 298
287 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedNextVSync) 299 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedNextVSync)
288 { 300 {
289 SchedulerStateMachine state; 301 SchedulerSettings defaultSchedulerSettings;
302 SchedulerStateMachine state(defaultSchedulerSettings);
290 state.setCanBeginFrame(true); 303 state.setCanBeginFrame(true);
291 state.setVisible(true); 304 state.setVisible(true);
292 state.setCanDraw(true); 305 state.setCanDraw(true);
293 306
294 // Start a draw. 307 // Start a draw.
295 state.setNeedsRedraw(); 308 state.setNeedsRedraw();
296 EXPECT_TRUE(state.vsyncCallbackNeeded()); 309 EXPECT_TRUE(state.vsyncCallbackNeeded());
297 state.didEnterVSync(); 310 state.didEnterVSync();
298 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 311 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
299 EXPECT_TRUE(state.redrawPending()); 312 EXPECT_TRUE(state.redrawPending());
(...skipping 10 matching lines...) Expand all
310 state.didLeaveVSync(); 323 state.didLeaveVSync();
311 EXPECT_TRUE(state.vsyncCallbackNeeded()); 324 EXPECT_TRUE(state.vsyncCallbackNeeded());
312 state.didEnterVSync(); 325 state.didEnterVSync();
313 326
314 // We should try draw again in the next vsync. 327 // We should try draw again in the next vsync.
315 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 328 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
316 } 329 }
317 330
318 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) 331 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame)
319 { 332 {
320 SchedulerStateMachine state; 333 SchedulerSettings defaultSchedulerSettings;
334 SchedulerStateMachine state(defaultSchedulerSettings);
321 state.setVisible(true); 335 state.setVisible(true);
322 state.setCanDraw(true); 336 state.setCanDraw(true);
323 state.setNeedsRedraw(); 337 state.setNeedsRedraw();
324 EXPECT_TRUE(state.vsyncCallbackNeeded()); 338 EXPECT_TRUE(state.vsyncCallbackNeeded());
325 state.didEnterVSync(); 339 state.didEnterVSync();
326 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 340 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
327 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 341 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
328 342
329 // While still in the same vsync callback, set needs redraw again. 343 // While still in the same vsync callback, set needs redraw again.
330 // This should not redraw. 344 // This should not redraw.
331 state.setNeedsRedraw(); 345 state.setNeedsRedraw();
332 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 346 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
333 347
334 // Move to another frame. This should now draw. 348 // Move to another frame. This should now draw.
335 state.didDrawIfPossibleCompleted(true); 349 state.didDrawIfPossibleCompleted(true);
336 state.didLeaveVSync(); 350 state.didLeaveVSync();
337 EXPECT_TRUE(state.vsyncCallbackNeeded()); 351 EXPECT_TRUE(state.vsyncCallbackNeeded());
338 state.didEnterVSync(); 352 state.didEnterVSync();
339 353
340 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 354 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
341 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 355 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
342 state.didDrawIfPossibleCompleted(true); 356 state.didDrawIfPossibleCompleted(true);
343 EXPECT_FALSE(state.vsyncCallbackNeeded()); 357 EXPECT_FALSE(state.vsyncCallbackNeeded());
344 } 358 }
345 359
346 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnVSync) 360 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnVSync)
347 { 361 {
362 SchedulerSettings defaultSchedulerSettings;
363
348 // When not on vsync, or on vsync but not visible, don't draw. 364 // When not on vsync, or on vsync but not visible, don't draw.
349 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach ine::CommitState); 365 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach ine::CommitState);
350 for (size_t i = 0; i < numCommitStates; ++i) { 366 for (size_t i = 0; i < numCommitStates; ++i) {
351 for (unsigned j = 0; j < 2; ++j) { 367 for (unsigned j = 0; j < 2; ++j) {
352 StateMachine state; 368 StateMachine state(defaultSchedulerSettings);
353 state.setCommitState(allCommitStates[i]); 369 state.setCommitState(allCommitStates[i]);
354 bool visible = j; 370 bool visible = j;
355 if (!visible) { 371 if (!visible) {
356 state.didEnterVSync(); 372 state.didEnterVSync();
357 state.setVisible(false); 373 state.setVisible(false);
358 } else 374 } else
359 state.setVisible(true); 375 state.setVisible(true);
360 376
361 // Case 1: needsCommit=false 377 // Case 1: needsCommit=false
362 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action()); 378 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action());
363 379
364 // Case 2: needsCommit=true 380 // Case 2: needsCommit=true
365 state.setNeedsCommit(); 381 state.setNeedsCommit();
366 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action()); 382 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action());
367 } 383 }
368 } 384 }
369 385
370 // When on vsync, or not on vsync but needsForcedRedraw set, should always d raw except if you're ready to commit, in which case commit. 386 // When on vsync, or not on vsync but needsForcedRedraw set, should always d raw except if you're ready to commit, in which case commit.
371 for (size_t i = 0; i < numCommitStates; ++i) { 387 for (size_t i = 0; i < numCommitStates; ++i) {
372 for (unsigned j = 0; j < 2; ++j) { 388 for (unsigned j = 0; j < 2; ++j) {
373 StateMachine state; 389 StateMachine state(defaultSchedulerSettings);
374 state.setCanDraw(true); 390 state.setCanDraw(true);
375 state.setCommitState(allCommitStates[i]); 391 state.setCommitState(allCommitStates[i]);
376 bool forcedDraw = j; 392 bool forcedDraw = j;
377 if (!forcedDraw) { 393 if (!forcedDraw) {
378 state.didEnterVSync(); 394 state.didEnterVSync();
379 state.setNeedsRedraw(true); 395 state.setNeedsRedraw(true);
380 state.setVisible(true); 396 state.setVisible(true);
381 } else 397 } else
382 state.setNeedsForcedRedraw(true); 398 state.setNeedsForcedRedraw(true);
383 399
(...skipping 10 matching lines...) Expand all
394 // Case 2: needsCommit=true. 410 // Case 2: needsCommit=true.
395 state.setNeedsCommit(); 411 state.setNeedsCommit();
396 EXPECT_TRUE(state.vsyncCallbackNeeded()); 412 EXPECT_TRUE(state.vsyncCallbackNeeded());
397 EXPECT_EQ(expectedAction, state.nextAction()); 413 EXPECT_EQ(expectedAction, state.nextAction());
398 } 414 }
399 } 415 }
400 } 416 }
401 417
402 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) 418 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible)
403 { 419 {
420 SchedulerSettings defaultSchedulerSettings;
421
404 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach ine::CommitState); 422 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach ine::CommitState);
405 for (size_t i = 0; i < numCommitStates; ++i) { 423 for (size_t i = 0; i < numCommitStates; ++i) {
406 // There shouldn't be any drawing regardless of vsync. 424 // There shouldn't be any drawing regardless of vsync.
407 for (unsigned j = 0; j < 2; ++j) { 425 for (unsigned j = 0; j < 2; ++j) {
408 StateMachine state; 426 StateMachine state(defaultSchedulerSettings);
409 state.setCommitState(allCommitStates[i]); 427 state.setCommitState(allCommitStates[i]);
410 state.setVisible(false); 428 state.setVisible(false);
411 state.setNeedsRedraw(true); 429 state.setNeedsRedraw(true);
412 state.setNeedsForcedRedraw(false); 430 state.setNeedsForcedRedraw(false);
413 if (j == 1) 431 if (j == 1)
414 state.didEnterVSync(); 432 state.didEnterVSync();
415 433
416 // Case 1: needsCommit=false. 434 // Case 1: needsCommit=false.
417 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action()); 435 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action());
418 436
419 // Case 2: needsCommit=true. 437 // Case 2: needsCommit=true.
420 state.setNeedsCommit(); 438 state.setNeedsCommit();
421 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action()); 439 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action());
422 } 440 }
423 } 441 }
424 } 442 }
425 443
426 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) 444 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw)
427 { 445 {
446 SchedulerSettings defaultSchedulerSettings;
447
428 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach ine::CommitState); 448 size_t numCommitStates = sizeof(allCommitStates) / sizeof(SchedulerStateMach ine::CommitState);
429 for (size_t i = 0; i < numCommitStates; ++i) { 449 for (size_t i = 0; i < numCommitStates; ++i) {
430 // There shouldn't be any drawing regardless of vsync. 450 // There shouldn't be any drawing regardless of vsync.
431 for (unsigned j = 0; j < 2; ++j) { 451 for (unsigned j = 0; j < 2; ++j) {
432 StateMachine state; 452 StateMachine state(defaultSchedulerSettings);
433 state.setCommitState(allCommitStates[i]); 453 state.setCommitState(allCommitStates[i]);
434 state.setVisible(false); 454 state.setVisible(false);
435 state.setNeedsRedraw(true); 455 state.setNeedsRedraw(true);
436 state.setNeedsForcedRedraw(false); 456 state.setNeedsForcedRedraw(false);
437 if (j == 1) 457 if (j == 1)
438 state.didEnterVSync(); 458 state.didEnterVSync();
439 459
440 state.setCanDraw(false); 460 state.setCanDraw(false);
441 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action()); 461 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.next Action());
442 } 462 }
443 } 463 }
444 } 464 }
445 465
446 TEST(SchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgres s) 466 TEST(SchedulerStateMachineTest, TestCanRedrawWithWaitingForFirstDrawMakesProgres s)
447 { 467 {
448 StateMachine state; 468 SchedulerSettings defaultSchedulerSettings;
469 StateMachine state(defaultSchedulerSettings);
449 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_D RAW); 470 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_D RAW);
450 state.setCanBeginFrame(true); 471 state.setCanBeginFrame(true);
451 state.setNeedsCommit(); 472 state.setNeedsCommit();
452 state.setNeedsRedraw(true); 473 state.setNeedsRedraw(true);
453 state.setVisible(true); 474 state.setVisible(true);
454 state.setCanDraw(false); 475 state.setCanDraw(false);
455 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 476 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
456 } 477 }
457 478
458 TEST(SchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) 479 TEST(SchedulerStateMachineTest, TestSetNeedsCommitIsNotLost)
459 { 480 {
460 StateMachine state; 481 SchedulerSettings defaultSchedulerSettings;
482 StateMachine state(defaultSchedulerSettings);
461 state.setCanBeginFrame(true); 483 state.setCanBeginFrame(true);
462 state.setNeedsCommit(); 484 state.setNeedsCommit();
463 state.setVisible(true); 485 state.setVisible(true);
464 state.setCanDraw(true); 486 state.setCanDraw(true);
465 487
466 // Begin the frame. 488 // Begin the frame.
467 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 489 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
468 state.updateState(state.nextAction()); 490 state.updateState(state.nextAction());
469 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState()); 491 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState());
470 492
(...skipping 18 matching lines...) Expand all
489 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE); 511 state.updateState(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
490 state.didDrawIfPossibleCompleted(true); 512 state.didDrawIfPossibleCompleted(true);
491 513
492 // Verify that another commit will begin. 514 // Verify that another commit will begin.
493 state.didLeaveVSync(); 515 state.didLeaveVSync();
494 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 516 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
495 } 517 }
496 518
497 TEST(SchedulerStateMachineTest, TestFullCycle) 519 TEST(SchedulerStateMachineTest, TestFullCycle)
498 { 520 {
499 StateMachine state; 521 SchedulerSettings defaultSchedulerSettings;
522 StateMachine state(defaultSchedulerSettings);
500 state.setCanBeginFrame(true); 523 state.setCanBeginFrame(true);
501 state.setVisible(true); 524 state.setVisible(true);
502 state.setCanDraw(true); 525 state.setCanDraw(true);
503 526
504 // Start clean and set commit. 527 // Start clean and set commit.
505 state.setNeedsCommit(); 528 state.setNeedsCommit();
506 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 529 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
507 530
508 // Begin the frame. 531 // Begin the frame.
509 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 532 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
(...skipping 22 matching lines...) Expand all
532 state.didLeaveVSync(); 555 state.didLeaveVSync();
533 556
534 // Should be synchronized, no draw needed, no action needed. 557 // Should be synchronized, no draw needed, no action needed.
535 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); 558 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState());
536 EXPECT_FALSE(state.needsRedraw()); 559 EXPECT_FALSE(state.needsRedraw());
537 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 560 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
538 } 561 }
539 562
540 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) 563 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween)
541 { 564 {
542 StateMachine state; 565 SchedulerSettings defaultSchedulerSettings;
566 StateMachine state(defaultSchedulerSettings);
543 state.setCanBeginFrame(true); 567 state.setCanBeginFrame(true);
544 state.setVisible(true); 568 state.setVisible(true);
545 state.setCanDraw(true); 569 state.setCanDraw(true);
546 570
547 // Start clean and set commit. 571 // Start clean and set commit.
548 state.setNeedsCommit(); 572 state.setNeedsCommit();
549 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 573 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
550 574
551 // Begin the frame. 575 // Begin the frame.
552 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 576 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
(...skipping 26 matching lines...) Expand all
579 state.didLeaveVSync(); 603 state.didLeaveVSync();
580 604
581 // Should be synchronized, no draw needed, no action needed. 605 // Should be synchronized, no draw needed, no action needed.
582 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); 606 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState());
583 EXPECT_FALSE(state.needsRedraw()); 607 EXPECT_FALSE(state.needsRedraw());
584 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 608 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
585 } 609 }
586 610
587 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) 611 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible)
588 { 612 {
589 StateMachine state; 613 SchedulerSettings defaultSchedulerSettings;
614 StateMachine state(defaultSchedulerSettings);
590 state.setNeedsCommit(); 615 state.setNeedsCommit();
591 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 616 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
592 } 617 }
593 618
594 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeBeginFrameCompletes) 619 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeBeginFrameCompletes)
595 { 620 {
596 StateMachine state; 621 SchedulerSettings defaultSchedulerSettings;
622 StateMachine state(defaultSchedulerSettings);
597 state.setCanBeginFrame(true); 623 state.setCanBeginFrame(true);
598 state.setVisible(true); 624 state.setVisible(true);
599 state.setCanDraw(true); 625 state.setCanDraw(true);
600 626
601 // Start clean and set commit. 627 // Start clean and set commit.
602 state.setNeedsCommit(); 628 state.setNeedsCommit();
603 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 629 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
604 630
605 // Begin the frame while visible. 631 // Begin the frame while visible.
606 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME); 632 state.updateState(SchedulerStateMachine::ACTION_BEGIN_FRAME);
(...skipping 18 matching lines...) Expand all
625 651
626 // Begin the frame 652 // Begin the frame
627 state.updateState(state.nextAction()); 653 state.updateState(state.nextAction());
628 654
629 // We should be starting the commit now 655 // We should be starting the commit now
630 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState()); 656 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState());
631 } 657 }
632 658
633 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) 659 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle)
634 { 660 {
635 StateMachine state; 661 SchedulerSettings defaultSchedulerSettings;
662 StateMachine state(defaultSchedulerSettings);
636 state.setCanBeginFrame(true); 663 state.setCanBeginFrame(true);
637 state.setVisible(true); 664 state.setVisible(true);
638 state.setCanDraw(true); 665 state.setCanDraw(true);
639 666
640 state.didLoseOutputSurface(); 667 state.didLoseOutputSurface();
641 668
642 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction()); 669 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction());
643 state.updateState(state.nextAction()); 670 state.updateState(state.nextAction());
644 671
645 // Once context recreation begins, nothing should happen. 672 // Once context recreation begins, nothing should happen.
646 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 673 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
647 674
648 // Recreate the context 675 // Recreate the context
649 state.didRecreateOutputSurface(); 676 state.didRecreateOutputSurface();
650 677
651 // When the context is recreated, we should begin a commit 678 // When the context is recreated, we should begin a commit
652 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 679 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
653 state.updateState(state.nextAction()); 680 state.updateState(state.nextAction());
654 } 681 }
655 682
656 TEST(SchedulerStateMachineTest, TestContextLostWhenIdleAndCommitRequestedWhileRe creating) 683 TEST(SchedulerStateMachineTest, TestContextLostWhenIdleAndCommitRequestedWhileRe creating)
657 { 684 {
658 StateMachine state; 685 SchedulerSettings defaultSchedulerSettings;
686 StateMachine state(defaultSchedulerSettings);
659 state.setCanBeginFrame(true); 687 state.setCanBeginFrame(true);
660 state.setVisible(true); 688 state.setVisible(true);
661 state.setCanDraw(true); 689 state.setCanDraw(true);
662 690
663 state.didLoseOutputSurface(); 691 state.didLoseOutputSurface();
664 692
665 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction()); 693 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction());
666 state.updateState(state.nextAction()); 694 state.updateState(state.nextAction());
667 695
668 // Once context recreation begins, nothing should happen. 696 // Once context recreation begins, nothing should happen.
(...skipping 16 matching lines...) Expand all
685 state.didEnterVSync(); 713 state.didEnterVSync();
686 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() ); 714 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction() );
687 state.setCanDraw(false); 715 state.setCanDraw(false);
688 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 716 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
689 state.setCanDraw(true); 717 state.setCanDraw(true);
690 state.didLeaveVSync(); 718 state.didLeaveVSync();
691 } 719 }
692 720
693 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) 721 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress)
694 { 722 {
695 StateMachine state; 723 SchedulerSettings defaultSchedulerSettings;
724 StateMachine state(defaultSchedulerSettings);
696 state.setCanBeginFrame(true); 725 state.setCanBeginFrame(true);
697 state.setVisible(true); 726 state.setVisible(true);
698 state.setCanDraw(true); 727 state.setCanDraw(true);
699 728
700 // Get a commit in flight. 729 // Get a commit in flight.
701 state.setNeedsCommit(); 730 state.setNeedsCommit();
702 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 731 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
703 state.updateState(state.nextAction()); 732 state.updateState(state.nextAction());
704 733
705 // Set damage and expect a draw. 734 // Set damage and expect a draw.
(...skipping 22 matching lines...) Expand all
728 757
729 // Expect to be told to begin context recreation, independent of vsync state 758 // Expect to be told to begin context recreation, independent of vsync state
730 state.didEnterVSync(); 759 state.didEnterVSync();
731 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction()); 760 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction());
732 state.didLeaveVSync(); 761 state.didLeaveVSync();
733 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction()); 762 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction());
734 } 763 }
735 764
736 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgressAndAnotherCo mmitRequested) 765 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgressAndAnotherCo mmitRequested)
737 { 766 {
738 StateMachine state; 767 SchedulerSettings defaultSchedulerSettings;
768 StateMachine state(defaultSchedulerSettings);
739 state.setCanBeginFrame(true); 769 state.setCanBeginFrame(true);
740 state.setVisible(true); 770 state.setVisible(true);
741 state.setCanDraw(true); 771 state.setCanDraw(true);
742 772
743 // Get a commit in flight. 773 // Get a commit in flight.
744 state.setNeedsCommit(); 774 state.setNeedsCommit();
745 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 775 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
746 state.updateState(state.nextAction()); 776 state.updateState(state.nextAction());
747 777
748 // Set damage and expect a draw. 778 // Set damage and expect a draw.
(...skipping 24 matching lines...) Expand all
773 // Expect to be told to begin context recreation, independent of vsync state 803 // Expect to be told to begin context recreation, independent of vsync state
774 state.didEnterVSync(); 804 state.didEnterVSync();
775 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction()); 805 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction());
776 state.didLeaveVSync(); 806 state.didLeaveVSync();
777 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction()); 807 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction());
778 } 808 }
779 809
780 810
781 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) 811 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost)
782 { 812 {
783 StateMachine state; 813 SchedulerSettings defaultSchedulerSettings;
814 StateMachine state(defaultSchedulerSettings);
784 state.setVisible(true); 815 state.setVisible(true);
785 state.setCanDraw(true); 816 state.setCanDraw(true);
786 817
787 // Cause a lost context lost. 818 // Cause a lost context lost.
788 state.didLoseOutputSurface(); 819 state.didLoseOutputSurface();
789 820
790 // Ask a forced redraw and verify it ocurrs. 821 // Ask a forced redraw and verify it ocurrs.
791 state.setNeedsForcedRedraw(true); 822 state.setNeedsForcedRedraw(true);
792 state.didEnterVSync(); 823 state.didEnterVSync();
793 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); 824 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction());
794 state.didLeaveVSync(); 825 state.didLeaveVSync();
795 826
796 // Clear the forced redraw bit. 827 // Clear the forced redraw bit.
797 state.setNeedsForcedRedraw(false); 828 state.setNeedsForcedRedraw(false);
798 829
799 // Expect to be told to begin context recreation, independent of vsync state 830 // Expect to be told to begin context recreation, independent of vsync state
800 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction()); 831 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_RECREATION, sta te.nextAction());
801 state.updateState(state.nextAction()); 832 state.updateState(state.nextAction());
802 833
803 // Ask a forced redraw and verify it ocurrs. 834 // Ask a forced redraw and verify it ocurrs.
804 state.setNeedsForcedRedraw(true); 835 state.setNeedsForcedRedraw(true);
805 state.didEnterVSync(); 836 state.didEnterVSync();
806 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); 837 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction());
807 state.didLeaveVSync(); 838 state.didLeaveVSync();
808 } 839 }
809 840
810 TEST(SchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit) 841 TEST(SchedulerStateMachineTest, TestBeginFrameWhenInvisibleAndForceCommit)
811 { 842 {
812 StateMachine state; 843 SchedulerSettings defaultSchedulerSettings;
844 StateMachine state(defaultSchedulerSettings);
813 state.setCanBeginFrame(true); 845 state.setCanBeginFrame(true);
814 state.setVisible(false); 846 state.setVisible(false);
815 state.setNeedsCommit(); 847 state.setNeedsCommit();
816 state.setNeedsForcedCommit(); 848 state.setNeedsForcedCommit();
817 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 849 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
818 } 850 }
819 851
820 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCanBeginFrameFalseAndForceComm it) 852 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCanBeginFrameFalseAndForceComm it)
821 { 853 {
822 StateMachine state; 854 SchedulerSettings defaultSchedulerSettings;
855 StateMachine state(defaultSchedulerSettings);
823 state.setVisible(true); 856 state.setVisible(true);
824 state.setCanDraw(true); 857 state.setCanDraw(true);
825 state.setNeedsCommit(); 858 state.setNeedsCommit();
826 state.setNeedsForcedCommit(); 859 state.setNeedsForcedCommit();
827 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 860 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
828 } 861 }
829 862
830 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress) 863 TEST(SchedulerStateMachineTest, TestBeginFrameWhenCommitInProgress)
831 { 864 {
832 StateMachine state; 865 SchedulerSettings defaultSchedulerSettings;
866 StateMachine state(defaultSchedulerSettings);
833 state.setCanBeginFrame(true); 867 state.setCanBeginFrame(true);
834 state.setVisible(false); 868 state.setVisible(false);
835 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 869 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
836 state.setNeedsCommit(); 870 state.setNeedsCommit();
837 871
838 state.beginFrameComplete(); 872 state.beginFrameComplete();
839 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); 873 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
840 state.updateState(state.nextAction()); 874 state.updateState(state.nextAction());
841 875
842 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state. commitState()); 876 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, state. commitState());
843 877
844 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 878 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
845 } 879 }
846 880
847 TEST(SchedulerStateMachineTest, TestBeginFrameWhenForcedCommitInProgress) 881 TEST(SchedulerStateMachineTest, TestBeginFrameWhenForcedCommitInProgress)
848 { 882 {
849 StateMachine state; 883 SchedulerSettings defaultSchedulerSettings;
884 StateMachine state(defaultSchedulerSettings);
850 state.setCanBeginFrame(true); 885 state.setCanBeginFrame(true);
851 state.setVisible(false); 886 state.setVisible(false);
852 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 887 state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
853 state.setNeedsCommit(); 888 state.setNeedsCommit();
854 state.setNeedsForcedCommit(); 889 state.setNeedsForcedCommit();
855 890
856 state.beginFrameComplete(); 891 state.beginFrameComplete();
857 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); 892 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
858 state.updateState(state.nextAction()); 893 state.updateState(state.nextAction());
859 894
860 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, state.commitState()); 895 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, state.commitState());
861 896
862 // If we are waiting for forced draw then we know a begin frame is already i n flight. 897 // If we are waiting for forced draw then we know a begin frame is already i n flight.
863 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 898 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
864 } 899 }
865 900
866 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost) 901 TEST(SchedulerStateMachineTest, TestBeginFrameWhenContextLost)
867 { 902 {
868 StateMachine state; 903 SchedulerSettings defaultSchedulerSettings;
904 StateMachine state(defaultSchedulerSettings);
869 state.setCanBeginFrame(true); 905 state.setCanBeginFrame(true);
870 state.setVisible(true); 906 state.setVisible(true);
871 state.setCanDraw(true); 907 state.setCanDraw(true);
872 state.setNeedsCommit(); 908 state.setNeedsCommit();
873 state.setNeedsForcedCommit(); 909 state.setNeedsForcedCommit();
874 state.didLoseOutputSurface(); 910 state.didLoseOutputSurface();
875 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction()); 911 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
876 } 912 }
877 913
878 TEST(SchedulerStateMachineTest, TestImmediateBeginFrame) 914 TEST(SchedulerStateMachineTest, TestImmediateBeginFrame)
879 { 915 {
880 StateMachine state; 916 SchedulerSettings defaultSchedulerSettings;
917 StateMachine state(defaultSchedulerSettings);
881 state.setCanBeginFrame(true); 918 state.setCanBeginFrame(true);
882 state.setVisible(true); 919 state.setVisible(true);
883 state.setCanDraw(true); 920 state.setCanDraw(true);
884 921
885 // Schedule a forced frame, commit it, draw it. 922 // Schedule a forced frame, commit it, draw it.
886 state.setNeedsCommit(); 923 state.setNeedsCommit();
887 state.setNeedsForcedCommit(); 924 state.setNeedsForcedCommit();
888 state.updateState(state.nextAction()); 925 state.updateState(state.nextAction());
889 state.beginFrameComplete(); 926 state.beginFrameComplete();
890 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); 927 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
891 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS tate()); 928 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS tate());
892 state.updateState(state.nextAction()); 929 state.updateState(state.nextAction());
893 930
894 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, state.commitState()); 931 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, state.commitState());
895 932
896 state.didEnterVSync(); 933 state.didEnterVSync();
897 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 934 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
898 state.setNeedsForcedRedraw(true); 935 state.setNeedsForcedRedraw(true);
899 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); 936 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction());
900 state.updateState(state.nextAction()); 937 state.updateState(state.nextAction());
901 state.didDrawIfPossibleCompleted(true); 938 state.didDrawIfPossibleCompleted(true);
902 state.didLeaveVSync(); 939 state.didLeaveVSync();
903 940
904 // Should be waiting for the normal begin frame 941 // Should be waiting for the normal begin frame
905 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState()); 942 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState());
906 } 943 }
907 944
908 TEST(SchedulerStateMachineTest, TestImmediateBeginFrameDuringCommit) 945 TEST(SchedulerStateMachineTest, TestImmediateBeginFrameDuringCommit)
909 { 946 {
910 StateMachine state; 947 SchedulerSettings defaultSchedulerSettings;
948 StateMachine state(defaultSchedulerSettings);
911 state.setCanBeginFrame(true); 949 state.setCanBeginFrame(true);
912 state.setVisible(true); 950 state.setVisible(true);
913 state.setCanDraw(true); 951 state.setCanDraw(true);
914 952
915 // Start a normal commit. 953 // Start a normal commit.
916 state.setNeedsCommit(); 954 state.setNeedsCommit();
917 state.updateState(state.nextAction()); 955 state.updateState(state.nextAction());
918 956
919 // Schedule a forced frame, commit it, draw it. 957 // Schedule a forced frame, commit it, draw it.
920 state.setNeedsCommit(); 958 state.setNeedsCommit();
(...skipping 13 matching lines...) Expand all
934 state.updateState(state.nextAction()); 972 state.updateState(state.nextAction());
935 state.didDrawIfPossibleCompleted(true); 973 state.didDrawIfPossibleCompleted(true);
936 state.didLeaveVSync(); 974 state.didLeaveVSync();
937 975
938 // Should be waiting for the normal begin frame 976 // Should be waiting for the normal begin frame
939 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState()) << state.toString(); 977 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commi tState()) << state.toString();
940 } 978 }
941 979
942 TEST(SchedulerStateMachineTest, ImmediateBeginFrameWhileInvisible) 980 TEST(SchedulerStateMachineTest, ImmediateBeginFrameWhileInvisible)
943 { 981 {
944 StateMachine state; 982 SchedulerSettings defaultSchedulerSettings;
983 StateMachine state(defaultSchedulerSettings);
945 state.setCanBeginFrame(true); 984 state.setCanBeginFrame(true);
946 state.setVisible(true); 985 state.setVisible(true);
947 state.setCanDraw(true); 986 state.setCanDraw(true);
948 987
949 state.setNeedsCommit(); 988 state.setNeedsCommit();
950 state.updateState(state.nextAction()); 989 state.updateState(state.nextAction());
951 990
952 state.setNeedsCommit(); 991 state.setNeedsCommit();
953 state.setNeedsForcedCommit(); 992 state.setNeedsForcedCommit();
954 state.updateState(state.nextAction()); 993 state.updateState(state.nextAction());
(...skipping 21 matching lines...) Expand all
976 state.setVisible(false); 1015 state.setVisible(false);
977 state.beginFrameAborted(); 1016 state.beginFrameAborted();
978 1017
979 // Should be back in the idle state, but needing a commit. 1018 // Should be back in the idle state, but needing a commit.
980 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState()); 1019 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState());
981 EXPECT_TRUE(state.needsCommit()); 1020 EXPECT_TRUE(state.needsCommit());
982 } 1021 }
983 1022
984 TEST(SchedulerStateMachineTest, ImmediateBeginFrameWhileCantDraw) 1023 TEST(SchedulerStateMachineTest, ImmediateBeginFrameWhileCantDraw)
985 { 1024 {
986 StateMachine state; 1025 SchedulerSettings defaultSchedulerSettings;
1026 StateMachine state(defaultSchedulerSettings);
987 state.setCanBeginFrame(true); 1027 state.setCanBeginFrame(true);
988 state.setVisible(true); 1028 state.setVisible(true);
989 state.setCanDraw(false); 1029 state.setCanDraw(false);
990 1030
991 state.setNeedsCommit(); 1031 state.setNeedsCommit();
992 state.updateState(state.nextAction()); 1032 state.updateState(state.nextAction());
993 1033
994 state.setNeedsCommit(); 1034 state.setNeedsCommit();
995 state.setNeedsForcedCommit(); 1035 state.setNeedsForcedCommit();
996 state.updateState(state.nextAction()); 1036 state.updateState(state.nextAction());
997 state.beginFrameComplete(); 1037 state.beginFrameComplete();
998 1038
999 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction()); 1039 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
1000 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS tate()); 1040 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitS tate());
1001 state.updateState(state.nextAction()); 1041 state.updateState(state.nextAction());
1002 1042
1003 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, state.commitState()); 1043 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW, state.commitState());
1004 1044
1005 state.didEnterVSync(); 1045 state.didEnterVSync();
1006 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction()); 1046 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
1007 state.setNeedsForcedRedraw(true); 1047 state.setNeedsForcedRedraw(true);
1008 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction()); 1048 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_FORCED, state.nextAction());
1009 state.updateState(state.nextAction()); 1049 state.updateState(state.nextAction());
1010 state.didDrawIfPossibleCompleted(true); 1050 state.didDrawIfPossibleCompleted(true);
1011 state.didLeaveVSync(); 1051 state.didLeaveVSync();
1012 } 1052 }
1013 1053
1014 } // namespace 1054 } // namespace
1015 } // namespace cc 1055 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler_state_machine.cc ('k') | cc/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698