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

Side by Side Diff: Source/WebKit/chromium/tests/CCSchedulerTest.cpp

Issue 9950004: Merge 112446 - [chromium] Scheduler should not tell FrameRateController to begin a frame when we do… (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1084/
Patch Set: Created 8 years, 8 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 | « Source/WebKit/chromium/ChangeLog ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 27 matching lines...) Expand all
38 namespace { 38 namespace {
39 39
40 class FakeCCSchedulerClient : public CCSchedulerClient { 40 class FakeCCSchedulerClient : public CCSchedulerClient {
41 public: 41 public:
42 FakeCCSchedulerClient() { reset(); } 42 FakeCCSchedulerClient() { reset(); }
43 void reset() 43 void reset()
44 { 44 {
45 m_actions.clear(); 45 m_actions.clear();
46 m_hasMoreResourceUpdates = false; 46 m_hasMoreResourceUpdates = false;
47 m_canDraw = true; 47 m_canDraw = true;
48 m_drawSuccess = true; 48 m_drawWillHappen = true;
49 m_swapWillHappenIfDrawHappens = true;
49 m_numDraws = 0; 50 m_numDraws = 0;
50 } 51 }
51 52
52 void setHasMoreResourceUpdates(bool b) { m_hasMoreResourceUpdates = b; } 53 void setHasMoreResourceUpdates(bool b) { m_hasMoreResourceUpdates = b; }
53 void setCanDraw(bool b) { m_canDraw = b; } 54 void setCanDraw(bool b) { m_canDraw = b; }
54 55
55 int numDraws() const { return m_numDraws; } 56 int numDraws() const { return m_numDraws; }
56 int numActions() const { return static_cast<int>(m_actions.size()); } 57 int numActions() const { return static_cast<int>(m_actions.size()); }
57 const char* action(int i) const { return m_actions[i]; } 58 const char* action(int i) const { return m_actions[i]; }
58 59
60 bool hasAction(const char* action) const
61 {
62 for (size_t i = 0; i < m_actions.size(); i++)
63 if (!strcmp(m_actions[i], action))
64 return true;
65 return false;
66 }
67
59 virtual bool canDraw() { return m_canDraw; } 68 virtual bool canDraw() { return m_canDraw; }
60 virtual bool hasMoreResourceUpdates() const { return m_hasMoreResourceUpdate s; } 69 virtual bool hasMoreResourceUpdates() const { return m_hasMoreResourceUpdate s; }
61 virtual void scheduledActionBeginFrame() { m_actions.push_back("scheduledAct ionBeginFrame"); } 70 virtual void scheduledActionBeginFrame() { m_actions.push_back("scheduledAct ionBeginFrame"); }
62 virtual bool scheduledActionDrawAndSwapIfPossible() 71 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossi ble()
63 { 72 {
64 m_actions.push_back("scheduledActionDrawAndSwapIfPossible"); 73 m_actions.push_back("scheduledActionDrawAndSwapIfPossible");
65 m_numDraws++; 74 m_numDraws++;
66 return m_drawSuccess; 75 return CCScheduledActionDrawAndSwapResult(m_drawWillHappen, m_drawWillHa ppen && m_swapWillHappenIfDrawHappens);
67 } 76 }
68 77
69 virtual void scheduledActionDrawAndSwapForced() 78 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced( )
70 { 79 {
71 m_actions.push_back("scheduledActionDrawAndSwapForced"); 80 m_actions.push_back("scheduledActionDrawAndSwapForced");
72 m_numDraws++; 81 return CCScheduledActionDrawAndSwapResult(true, m_swapWillHappenIfDrawHa ppens);
73 } 82 }
74 83
75 virtual void scheduledActionUpdateMoreResources() { m_actions.push_back("sch eduledActionUpdateMoreResources"); } 84 virtual void scheduledActionUpdateMoreResources() { m_actions.push_back("sch eduledActionUpdateMoreResources"); }
76 virtual void scheduledActionCommit() { m_actions.push_back("scheduledActionC ommit"); } 85 virtual void scheduledActionCommit() { m_actions.push_back("scheduledActionC ommit"); }
77 virtual void scheduledActionBeginContextRecreation() { m_actions.push_back(" scheduledActionBeginContextRecreation"); } 86 virtual void scheduledActionBeginContextRecreation() { m_actions.push_back(" scheduledActionBeginContextRecreation"); }
78 87
79 void setDrawSuccess(bool drawSuccess) { m_drawSuccess = drawSuccess; } 88 void setDrawWillHappen(bool drawWillHappen) { m_drawWillHappen = drawWillHap pen; }
89 void setSwapWillHappenIfDrawHappens(bool swapWillHappenIfDrawHappens) { m_sw apWillHappenIfDrawHappens = swapWillHappenIfDrawHappens; }
80 90
81 protected: 91 protected:
82 bool m_hasMoreResourceUpdates; 92 bool m_hasMoreResourceUpdates;
83 bool m_canDraw; 93 bool m_canDraw;
84 bool m_drawSuccess; 94 bool m_drawWillHappen;
95 bool m_swapWillHappenIfDrawHappens;
85 int m_numDraws; 96 int m_numDraws;
86 std::vector<const char*> m_actions; 97 std::vector<const char*> m_actions;
87 }; 98 };
88 99
89 TEST(CCSchedulerTest, RequestCommit) 100 TEST(CCSchedulerTest, RequestCommit)
90 { 101 {
91 FakeCCSchedulerClient client; 102 FakeCCSchedulerClient client;
92 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); 103 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource());
93 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC FrameRateController(timeSource))); 104 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC FrameRateController(timeSource)));
94 scheduler->setVisible(true); 105 scheduler->setVisible(true);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 167 }
157 168
158 class SchedulerClientThatSetNeedsDrawInsideDraw : public FakeCCSchedulerClient { 169 class SchedulerClientThatSetNeedsDrawInsideDraw : public FakeCCSchedulerClient {
159 public: 170 public:
160 SchedulerClientThatSetNeedsDrawInsideDraw() 171 SchedulerClientThatSetNeedsDrawInsideDraw()
161 : m_scheduler(0) { } 172 : m_scheduler(0) { }
162 173
163 void setScheduler(CCScheduler* scheduler) { m_scheduler = scheduler; } 174 void setScheduler(CCScheduler* scheduler) { m_scheduler = scheduler; }
164 175
165 virtual void scheduledActionBeginFrame() { } 176 virtual void scheduledActionBeginFrame() { }
166 virtual bool scheduledActionDrawAndSwapIfPossible() 177 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossi ble()
167 { 178 {
168 // Only setNeedsRedraw the first time this is called 179 // Only setNeedsRedraw the first time this is called
169 if (!m_numDraws) 180 if (!m_numDraws)
170 m_scheduler->setNeedsRedraw(); 181 m_scheduler->setNeedsRedraw();
171 return FakeCCSchedulerClient::scheduledActionDrawAndSwapIfPossible(); 182 return FakeCCSchedulerClient::scheduledActionDrawAndSwapIfPossible();
172 } 183 }
173 184
174 virtual void scheduledActionDrawAndSwapForced() { } 185 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced( )
186 {
187 ASSERT_NOT_REACHED();
188 return CCScheduledActionDrawAndSwapResult(true, true);
189 }
190
175 virtual void scheduledActionUpdateMoreResources() { } 191 virtual void scheduledActionUpdateMoreResources() { }
176 virtual void scheduledActionCommit() { } 192 virtual void scheduledActionCommit() { }
177 virtual void scheduledActionBeginContextRecreation() { } 193 virtual void scheduledActionBeginContextRecreation() { }
178 194
179 protected: 195 protected:
180 CCScheduler* m_scheduler; 196 CCScheduler* m_scheduler;
181 }; 197 };
182 198
183 // Tests for two different situations: 199 // Tests for two different situations:
184 // 1. the scheduler dropping setNeedsRedraw requests that happen inside 200 // 1. the scheduler dropping setNeedsRedraw requests that happen inside
(...skipping 24 matching lines...) Expand all
209 } 225 }
210 226
211 // Test that requesting redraw inside a failed draw doesn't lose the request. 227 // Test that requesting redraw inside a failed draw doesn't lose the request.
212 TEST(CCSchedulerTest, RequestRedrawInsideFailedDraw) 228 TEST(CCSchedulerTest, RequestRedrawInsideFailedDraw)
213 { 229 {
214 SchedulerClientThatSetNeedsDrawInsideDraw client; 230 SchedulerClientThatSetNeedsDrawInsideDraw client;
215 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); 231 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource());
216 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC FrameRateController(timeSource))); 232 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC FrameRateController(timeSource)));
217 client.setScheduler(scheduler.get()); 233 client.setScheduler(scheduler.get());
218 scheduler->setVisible(true); 234 scheduler->setVisible(true);
219 client.setDrawSuccess(false); 235 client.setDrawWillHappen(false);
220 236
221 scheduler->setNeedsRedraw(); 237 scheduler->setNeedsRedraw();
222 EXPECT_TRUE(scheduler->redrawPending()); 238 EXPECT_TRUE(scheduler->redrawPending());
223 EXPECT_TRUE(timeSource->active()); 239 EXPECT_TRUE(timeSource->active());
224 EXPECT_EQ(0, client.numDraws()); 240 EXPECT_EQ(0, client.numDraws());
225 241
226 // Fail the draw. 242 // Fail the draw.
227 timeSource->tick(); 243 timeSource->tick();
228 EXPECT_EQ(1, client.numDraws()); 244 EXPECT_EQ(1, client.numDraws());
229 245
230 // We have a commit pending and the draw failed, and we didn't lose the redr aw request. 246 // We have a commit pending and the draw failed, and we didn't lose the redr aw request.
231 EXPECT_TRUE(scheduler->commitPending()); 247 EXPECT_TRUE(scheduler->commitPending());
232 EXPECT_TRUE(scheduler->redrawPending()); 248 EXPECT_TRUE(scheduler->redrawPending());
233 EXPECT_TRUE(timeSource->active()); 249 EXPECT_TRUE(timeSource->active());
234 250
235 // Fail the draw again. 251 // Fail the draw again.
236 timeSource->tick(); 252 timeSource->tick();
237 EXPECT_EQ(2, client.numDraws()); 253 EXPECT_EQ(2, client.numDraws());
238 EXPECT_TRUE(scheduler->commitPending()); 254 EXPECT_TRUE(scheduler->commitPending());
239 EXPECT_TRUE(scheduler->redrawPending()); 255 EXPECT_TRUE(scheduler->redrawPending());
240 EXPECT_TRUE(timeSource->active()); 256 EXPECT_TRUE(timeSource->active());
241 257
242 // Draw successfully. 258 // Draw successfully.
243 client.setDrawSuccess(true); 259 client.setDrawWillHappen(true);
244 timeSource->tick(); 260 timeSource->tick();
245 EXPECT_EQ(3, client.numDraws()); 261 EXPECT_EQ(3, client.numDraws());
246 EXPECT_TRUE(scheduler->commitPending()); 262 EXPECT_TRUE(scheduler->commitPending());
247 EXPECT_FALSE(scheduler->redrawPending()); 263 EXPECT_FALSE(scheduler->redrawPending());
248 EXPECT_FALSE(timeSource->active()); 264 EXPECT_FALSE(timeSource->active());
249 } 265 }
250 266
251 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeCCSchedulerClient { 267 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeCCSchedulerClient {
252 public: 268 public:
253 SchedulerClientThatSetNeedsCommitInsideDraw() 269 SchedulerClientThatSetNeedsCommitInsideDraw()
254 : m_scheduler(0) { } 270 : m_scheduler(0) { }
255 271
256 void setScheduler(CCScheduler* scheduler) { m_scheduler = scheduler; } 272 void setScheduler(CCScheduler* scheduler) { m_scheduler = scheduler; }
257 273
258 virtual void scheduledActionBeginFrame() { } 274 virtual void scheduledActionBeginFrame() { }
259 virtual bool scheduledActionDrawAndSwapIfPossible() 275 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossi ble()
260 { 276 {
261 // Only setNeedsCommit the first time this is called 277 // Only setNeedsCommit the first time this is called
262 if (!m_numDraws) 278 if (!m_numDraws)
263 m_scheduler->setNeedsCommit(); 279 m_scheduler->setNeedsCommit();
264 return FakeCCSchedulerClient::scheduledActionDrawAndSwapIfPossible(); 280 return FakeCCSchedulerClient::scheduledActionDrawAndSwapIfPossible();
265 } 281 }
266 282
267 virtual void scheduledActionDrawAndSwapForced() { } 283 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced( )
284 {
285 ASSERT_NOT_REACHED();
286 return CCScheduledActionDrawAndSwapResult(true, true);
287 }
288
268 virtual void scheduledActionUpdateMoreResources() { } 289 virtual void scheduledActionUpdateMoreResources() { }
269 virtual void scheduledActionCommit() { } 290 virtual void scheduledActionCommit() { }
270 virtual void scheduledActionBeginContextRecreation() { } 291 virtual void scheduledActionBeginContextRecreation() { }
271 292
272 protected: 293 protected:
273 CCScheduler* m_scheduler; 294 CCScheduler* m_scheduler;
274 }; 295 };
275 296
276 // Tests for the scheduler infinite-looping on setNeedsCommit requests that 297 // Tests for the scheduler infinite-looping on setNeedsCommit requests that
277 // happen inside a scheduledActionDrawAndSwap 298 // happen inside a scheduledActionDrawAndSwap
(...skipping 23 matching lines...) Expand all
301 } 322 }
302 323
303 // Tests that when a draw fails then the pending commit should not be dropped. 324 // Tests that when a draw fails then the pending commit should not be dropped.
304 TEST(CCSchedulerTest, RequestCommitInsideFailedDraw) 325 TEST(CCSchedulerTest, RequestCommitInsideFailedDraw)
305 { 326 {
306 SchedulerClientThatSetNeedsDrawInsideDraw client; 327 SchedulerClientThatSetNeedsDrawInsideDraw client;
307 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); 328 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource());
308 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC FrameRateController(timeSource))); 329 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC FrameRateController(timeSource)));
309 client.setScheduler(scheduler.get()); 330 client.setScheduler(scheduler.get());
310 scheduler->setVisible(true); 331 scheduler->setVisible(true);
311 client.setDrawSuccess(false); 332 client.setDrawWillHappen(false);
312 333
313 scheduler->setNeedsRedraw(); 334 scheduler->setNeedsRedraw();
314 EXPECT_TRUE(scheduler->redrawPending()); 335 EXPECT_TRUE(scheduler->redrawPending());
315 EXPECT_TRUE(timeSource->active()); 336 EXPECT_TRUE(timeSource->active());
316 EXPECT_EQ(0, client.numDraws()); 337 EXPECT_EQ(0, client.numDraws());
317 338
318 // Fail the draw. 339 // Fail the draw.
319 timeSource->tick(); 340 timeSource->tick();
320 EXPECT_EQ(1, client.numDraws()); 341 EXPECT_EQ(1, client.numDraws());
321 342
322 // We have a commit pending and the draw failed, and we didn't lose the comm it request. 343 // We have a commit pending and the draw failed, and we didn't lose the comm it request.
323 EXPECT_TRUE(scheduler->commitPending()); 344 EXPECT_TRUE(scheduler->commitPending());
324 EXPECT_TRUE(scheduler->redrawPending()); 345 EXPECT_TRUE(scheduler->redrawPending());
325 EXPECT_TRUE(timeSource->active()); 346 EXPECT_TRUE(timeSource->active());
326 347
327 // Fail the draw again. 348 // Fail the draw again.
328 timeSource->tick(); 349 timeSource->tick();
329 EXPECT_EQ(2, client.numDraws()); 350 EXPECT_EQ(2, client.numDraws());
330 EXPECT_TRUE(scheduler->commitPending()); 351 EXPECT_TRUE(scheduler->commitPending());
331 EXPECT_TRUE(scheduler->redrawPending()); 352 EXPECT_TRUE(scheduler->redrawPending());
332 EXPECT_TRUE(timeSource->active()); 353 EXPECT_TRUE(timeSource->active());
333 354
334 // Draw successfully. 355 // Draw successfully.
335 client.setDrawSuccess(true); 356 client.setDrawWillHappen(true);
336 timeSource->tick(); 357 timeSource->tick();
337 EXPECT_EQ(3, client.numDraws()); 358 EXPECT_EQ(3, client.numDraws());
338 EXPECT_TRUE(scheduler->commitPending()); 359 EXPECT_TRUE(scheduler->commitPending());
339 EXPECT_FALSE(scheduler->redrawPending()); 360 EXPECT_FALSE(scheduler->redrawPending());
340 EXPECT_FALSE(timeSource->active()); 361 EXPECT_FALSE(timeSource->active());
341 } 362 }
342 363
343 TEST(CCSchedulerTest, NoBeginFrameWhenDrawFails) 364 TEST(CCSchedulerTest, NoBeginFrameWhenDrawFails)
344 { 365 {
345 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); 366 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource());
(...skipping 27 matching lines...) Expand all
373 EXPECT_EQ(2, client.numDraws()); 394 EXPECT_EQ(2, client.numDraws());
374 EXPECT_EQ(1, controllerPtr->numFramesPending()); 395 EXPECT_EQ(1, controllerPtr->numFramesPending());
375 scheduler->didSwapBuffersComplete(); 396 scheduler->didSwapBuffersComplete();
376 EXPECT_EQ(0, controllerPtr->numFramesPending()); 397 EXPECT_EQ(0, controllerPtr->numFramesPending());
377 398
378 scheduler->setNeedsRedraw(); 399 scheduler->setNeedsRedraw();
379 EXPECT_TRUE(scheduler->redrawPending()); 400 EXPECT_TRUE(scheduler->redrawPending());
380 EXPECT_TRUE(timeSource->active()); 401 EXPECT_TRUE(timeSource->active());
381 402
382 // Fail to draw, this should not start a frame. 403 // Fail to draw, this should not start a frame.
383 client.setDrawSuccess(false); 404 client.setDrawWillHappen(false);
384 timeSource->tick(); 405 timeSource->tick();
385 EXPECT_EQ(3, client.numDraws()); 406 EXPECT_EQ(3, client.numDraws());
386 EXPECT_EQ(0, controllerPtr->numFramesPending()); 407 EXPECT_EQ(0, controllerPtr->numFramesPending());
387 } 408 }
388 409
410 TEST(CCSchedulerTest, NoBeginFrameWhenSwapFailsDuringForcedCommit)
411 {
412 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource());
413 FakeCCSchedulerClient client;
414 OwnPtr<FakeCCFrameRateController> controller = adoptPtr(new FakeCCFrameRateC ontroller(timeSource));
415 FakeCCFrameRateController* controllerPtr = controller.get();
416 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, controller.rele ase());
417
418 EXPECT_EQ(0, controllerPtr->numFramesPending());
419
420 // Tell the client that it will fail to swap.
421 client.setDrawWillHappen(true);
422 client.setSwapWillHappenIfDrawHappens(false);
423
424 // Get the compositor to do a scheduledActionDrawAndSwapForced.
425 scheduler->setNeedsRedraw();
426 scheduler->setNeedsForcedRedraw();
427 EXPECT_TRUE(client.hasAction("scheduledActionDrawAndSwapForced"));
428
429 // We should not have told the frame rate controller that we began a frame.
430 EXPECT_EQ(0, controllerPtr->numFramesPending());
389 } 431 }
432
433 }
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/ChangeLog ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698