| OLD | NEW |
| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 bool m_swapWillHappenIfDrawHappens; | 95 bool m_swapWillHappenIfDrawHappens; |
| 96 int m_numDraws; | 96 int m_numDraws; |
| 97 std::vector<const char*> m_actions; | 97 std::vector<const char*> m_actions; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 TEST(CCSchedulerTest, RequestCommit) | 100 TEST(CCSchedulerTest, RequestCommit) |
| 101 { | 101 { |
| 102 FakeCCSchedulerClient client; | 102 FakeCCSchedulerClient client; |
| 103 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); | 103 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); |
| 104 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); | 104 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); |
| 105 scheduler->setCanBeginFrame(true); |
| 105 scheduler->setVisible(true); | 106 scheduler->setVisible(true); |
| 106 | 107 |
| 107 // SetNeedsCommit should begin the frame. | 108 // SetNeedsCommit should begin the frame. |
| 108 scheduler->setNeedsCommit(); | 109 scheduler->setNeedsCommit(); |
| 109 EXPECT_EQ(1, client.numActions()); | 110 EXPECT_EQ(1, client.numActions()); |
| 110 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); | 111 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); |
| 111 EXPECT_FALSE(timeSource->active()); | 112 EXPECT_FALSE(timeSource->active()); |
| 112 client.reset(); | 113 client.reset(); |
| 113 | 114 |
| 114 // Since, hasMoreResourceUpdates is set to false, | 115 // Since, hasMoreResourceUpdates is set to false, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 130 | 131 |
| 131 // Timer should be off. | 132 // Timer should be off. |
| 132 EXPECT_FALSE(timeSource->active()); | 133 EXPECT_FALSE(timeSource->active()); |
| 133 } | 134 } |
| 134 | 135 |
| 135 TEST(CCSchedulerTest, RequestCommitAfterBeginFrame) | 136 TEST(CCSchedulerTest, RequestCommitAfterBeginFrame) |
| 136 { | 137 { |
| 137 FakeCCSchedulerClient client; | 138 FakeCCSchedulerClient client; |
| 138 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); | 139 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); |
| 139 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); | 140 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); |
| 141 scheduler->setCanBeginFrame(true); |
| 140 scheduler->setVisible(true); | 142 scheduler->setVisible(true); |
| 141 | 143 |
| 142 // SetNedsCommit should begin the frame. | 144 // SetNedsCommit should begin the frame. |
| 143 scheduler->setNeedsCommit(); | 145 scheduler->setNeedsCommit(); |
| 144 EXPECT_EQ(1, client.numActions()); | 146 EXPECT_EQ(1, client.numActions()); |
| 145 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); | 147 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); |
| 146 client.reset(); | 148 client.reset(); |
| 147 | 149 |
| 148 // Now setNeedsCommit again. Calling here means we need a second frame. | 150 // Now setNeedsCommit again. Calling here means we need a second frame. |
| 149 scheduler->setNeedsCommit(); | 151 scheduler->setNeedsCommit(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // Tests for two different situations: | 201 // Tests for two different situations: |
| 200 // 1. the scheduler dropping setNeedsRedraw requests that happen inside | 202 // 1. the scheduler dropping setNeedsRedraw requests that happen inside |
| 201 // a scheduledActionDrawAndSwap | 203 // a scheduledActionDrawAndSwap |
| 202 // 2. the scheduler drawing twice inside a single tick | 204 // 2. the scheduler drawing twice inside a single tick |
| 203 TEST(CCSchedulerTest, RequestRedrawInsideDraw) | 205 TEST(CCSchedulerTest, RequestRedrawInsideDraw) |
| 204 { | 206 { |
| 205 SchedulerClientThatSetNeedsDrawInsideDraw client; | 207 SchedulerClientThatSetNeedsDrawInsideDraw client; |
| 206 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); | 208 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); |
| 207 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); | 209 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); |
| 208 client.setScheduler(scheduler.get()); | 210 client.setScheduler(scheduler.get()); |
| 211 scheduler->setCanBeginFrame(true); |
| 209 scheduler->setVisible(true); | 212 scheduler->setVisible(true); |
| 210 | 213 |
| 211 scheduler->setNeedsRedraw(); | 214 scheduler->setNeedsRedraw(); |
| 212 EXPECT_TRUE(scheduler->redrawPending()); | 215 EXPECT_TRUE(scheduler->redrawPending()); |
| 213 EXPECT_TRUE(timeSource->active()); | 216 EXPECT_TRUE(timeSource->active()); |
| 214 EXPECT_EQ(0, client.numDraws()); | 217 EXPECT_EQ(0, client.numDraws()); |
| 215 | 218 |
| 216 timeSource->tick(); | 219 timeSource->tick(); |
| 217 EXPECT_EQ(1, client.numDraws()); | 220 EXPECT_EQ(1, client.numDraws()); |
| 218 EXPECT_TRUE(scheduler->redrawPending()); | 221 EXPECT_TRUE(scheduler->redrawPending()); |
| 219 EXPECT_TRUE(timeSource->active()); | 222 EXPECT_TRUE(timeSource->active()); |
| 220 | 223 |
| 221 timeSource->tick(); | 224 timeSource->tick(); |
| 222 EXPECT_EQ(2, client.numDraws()); | 225 EXPECT_EQ(2, client.numDraws()); |
| 223 EXPECT_FALSE(scheduler->redrawPending()); | 226 EXPECT_FALSE(scheduler->redrawPending()); |
| 224 EXPECT_FALSE(timeSource->active()); | 227 EXPECT_FALSE(timeSource->active()); |
| 225 } | 228 } |
| 226 | 229 |
| 227 // Test that requesting redraw inside a failed draw doesn't lose the request. | 230 // Test that requesting redraw inside a failed draw doesn't lose the request. |
| 228 TEST(CCSchedulerTest, RequestRedrawInsideFailedDraw) | 231 TEST(CCSchedulerTest, RequestRedrawInsideFailedDraw) |
| 229 { | 232 { |
| 230 SchedulerClientThatSetNeedsDrawInsideDraw client; | 233 SchedulerClientThatSetNeedsDrawInsideDraw client; |
| 231 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); | 234 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); |
| 232 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); | 235 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); |
| 233 client.setScheduler(scheduler.get()); | 236 client.setScheduler(scheduler.get()); |
| 237 scheduler->setCanBeginFrame(true); |
| 234 scheduler->setVisible(true); | 238 scheduler->setVisible(true); |
| 235 client.setDrawWillHappen(false); | 239 client.setDrawWillHappen(false); |
| 236 | 240 |
| 237 scheduler->setNeedsRedraw(); | 241 scheduler->setNeedsRedraw(); |
| 238 EXPECT_TRUE(scheduler->redrawPending()); | 242 EXPECT_TRUE(scheduler->redrawPending()); |
| 239 EXPECT_TRUE(timeSource->active()); | 243 EXPECT_TRUE(timeSource->active()); |
| 240 EXPECT_EQ(0, client.numDraws()); | 244 EXPECT_EQ(0, client.numDraws()); |
| 241 | 245 |
| 242 // Fail the draw. | 246 // Fail the draw. |
| 243 timeSource->tick(); | 247 timeSource->tick(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 }; | 299 }; |
| 296 | 300 |
| 297 // Tests for the scheduler infinite-looping on setNeedsCommit requests that | 301 // Tests for the scheduler infinite-looping on setNeedsCommit requests that |
| 298 // happen inside a scheduledActionDrawAndSwap | 302 // happen inside a scheduledActionDrawAndSwap |
| 299 TEST(CCSchedulerTest, RequestCommitInsideDraw) | 303 TEST(CCSchedulerTest, RequestCommitInsideDraw) |
| 300 { | 304 { |
| 301 SchedulerClientThatSetNeedsCommitInsideDraw client; | 305 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 302 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); | 306 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); |
| 303 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); | 307 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); |
| 304 client.setScheduler(scheduler.get()); | 308 client.setScheduler(scheduler.get()); |
| 309 scheduler->setCanBeginFrame(true); |
| 305 scheduler->setVisible(true); | 310 scheduler->setVisible(true); |
| 306 | 311 |
| 307 scheduler->setNeedsRedraw(); | 312 scheduler->setNeedsRedraw(); |
| 308 EXPECT_TRUE(scheduler->redrawPending()); | 313 EXPECT_TRUE(scheduler->redrawPending()); |
| 309 EXPECT_EQ(0, client.numDraws()); | 314 EXPECT_EQ(0, client.numDraws()); |
| 310 EXPECT_TRUE(timeSource->active()); | 315 EXPECT_TRUE(timeSource->active()); |
| 311 | 316 |
| 312 timeSource->tick(); | 317 timeSource->tick(); |
| 313 EXPECT_FALSE(timeSource->active()); | 318 EXPECT_FALSE(timeSource->active()); |
| 314 EXPECT_EQ(1, client.numDraws()); | 319 EXPECT_EQ(1, client.numDraws()); |
| 315 EXPECT_TRUE(scheduler->commitPending()); | 320 EXPECT_TRUE(scheduler->commitPending()); |
| 316 scheduler->beginFrameComplete(); | 321 scheduler->beginFrameComplete(); |
| 317 | 322 |
| 318 timeSource->tick(); | 323 timeSource->tick(); |
| 319 EXPECT_EQ(2, client.numDraws()); | 324 EXPECT_EQ(2, client.numDraws()); |
| 320 EXPECT_FALSE(timeSource->active()); | 325 EXPECT_FALSE(timeSource->active()); |
| 321 EXPECT_FALSE(scheduler->redrawPending()); | 326 EXPECT_FALSE(scheduler->redrawPending()); |
| 322 } | 327 } |
| 323 | 328 |
| 324 // Tests that when a draw fails then the pending commit should not be dropped. | 329 // Tests that when a draw fails then the pending commit should not be dropped. |
| 325 TEST(CCSchedulerTest, RequestCommitInsideFailedDraw) | 330 TEST(CCSchedulerTest, RequestCommitInsideFailedDraw) |
| 326 { | 331 { |
| 327 SchedulerClientThatSetNeedsDrawInsideDraw client; | 332 SchedulerClientThatSetNeedsDrawInsideDraw client; |
| 328 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); | 333 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); |
| 329 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); | 334 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); |
| 330 client.setScheduler(scheduler.get()); | 335 client.setScheduler(scheduler.get()); |
| 336 scheduler->setCanBeginFrame(true); |
| 331 scheduler->setVisible(true); | 337 scheduler->setVisible(true); |
| 332 client.setDrawWillHappen(false); | 338 client.setDrawWillHappen(false); |
| 333 | 339 |
| 334 scheduler->setNeedsRedraw(); | 340 scheduler->setNeedsRedraw(); |
| 335 EXPECT_TRUE(scheduler->redrawPending()); | 341 EXPECT_TRUE(scheduler->redrawPending()); |
| 336 EXPECT_TRUE(timeSource->active()); | 342 EXPECT_TRUE(timeSource->active()); |
| 337 EXPECT_EQ(0, client.numDraws()); | 343 EXPECT_EQ(0, client.numDraws()); |
| 338 | 344 |
| 339 // Fail the draw. | 345 // Fail the draw. |
| 340 timeSource->tick(); | 346 timeSource->tick(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 362 } | 368 } |
| 363 | 369 |
| 364 TEST(CCSchedulerTest, NoBeginFrameWhenDrawFails) | 370 TEST(CCSchedulerTest, NoBeginFrameWhenDrawFails) |
| 365 { | 371 { |
| 366 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); | 372 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); |
| 367 SchedulerClientThatSetNeedsCommitInsideDraw client; | 373 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 368 OwnPtr<FakeCCFrameRateController> controller = adoptPtr(new FakeCCFrameRateC
ontroller(timeSource)); | 374 OwnPtr<FakeCCFrameRateController> controller = adoptPtr(new FakeCCFrameRateC
ontroller(timeSource)); |
| 369 FakeCCFrameRateController* controllerPtr = controller.get(); | 375 FakeCCFrameRateController* controllerPtr = controller.get(); |
| 370 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, controller.rele
ase()); | 376 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, controller.rele
ase()); |
| 371 client.setScheduler(scheduler.get()); | 377 client.setScheduler(scheduler.get()); |
| 378 scheduler->setCanBeginFrame(true); |
| 372 scheduler->setVisible(true); | 379 scheduler->setVisible(true); |
| 373 | 380 |
| 374 EXPECT_EQ(0, controllerPtr->numFramesPending()); | 381 EXPECT_EQ(0, controllerPtr->numFramesPending()); |
| 375 | 382 |
| 376 scheduler->setNeedsRedraw(); | 383 scheduler->setNeedsRedraw(); |
| 377 EXPECT_TRUE(scheduler->redrawPending()); | 384 EXPECT_TRUE(scheduler->redrawPending()); |
| 378 EXPECT_TRUE(timeSource->active()); | 385 EXPECT_TRUE(timeSource->active()); |
| 379 EXPECT_EQ(0, client.numDraws()); | 386 EXPECT_EQ(0, client.numDraws()); |
| 380 | 387 |
| 381 // Draw successfully, this starts a new frame. | 388 // Draw successfully, this starts a new frame. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 // Get the compositor to do a scheduledActionDrawAndSwapForced. | 431 // Get the compositor to do a scheduledActionDrawAndSwapForced. |
| 425 scheduler->setNeedsRedraw(); | 432 scheduler->setNeedsRedraw(); |
| 426 scheduler->setNeedsForcedRedraw(); | 433 scheduler->setNeedsForcedRedraw(); |
| 427 EXPECT_TRUE(client.hasAction("scheduledActionDrawAndSwapForced")); | 434 EXPECT_TRUE(client.hasAction("scheduledActionDrawAndSwapForced")); |
| 428 | 435 |
| 429 // We should not have told the frame rate controller that we began a frame. | 436 // We should not have told the frame rate controller that we began a frame. |
| 430 EXPECT_EQ(0, controllerPtr->numFramesPending()); | 437 EXPECT_EQ(0, controllerPtr->numFramesPending()); |
| 431 } | 438 } |
| 432 | 439 |
| 433 } | 440 } |
| OLD | NEW |