| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 | |
| 7 #include "CCFrameRateController.h" | |
| 8 | |
| 9 #include "CCSchedulerTestCommon.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 using namespace cc; | |
| 13 using namespace WebKitTests; | |
| 14 using namespace WTF; | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class FakeCCFrameRateControllerClient : public cc::CCFrameRateControllerClient { | |
| 19 public: | |
| 20 FakeCCFrameRateControllerClient() { reset(); } | |
| 21 | |
| 22 void reset() { m_vsyncTicked = false; } | |
| 23 bool vsyncTicked() const { return m_vsyncTicked; } | |
| 24 | |
| 25 virtual void vsyncTick(bool throttled) { m_vsyncTicked = !throttled; } | |
| 26 | |
| 27 protected: | |
| 28 bool m_vsyncTicked; | |
| 29 }; | |
| 30 | |
| 31 | |
| 32 TEST(CCFrameRateControllerTest, TestFrameThrottling_ImmediateAck) | |
| 33 { | |
| 34 FakeCCThread thread; | |
| 35 FakeCCFrameRateControllerClient client; | |
| 36 base::TimeDelta interval = base::TimeDelta::FromMicroseconds(base::Time::kMi
crosecondsPerSecond / 60); | |
| 37 RefPtr<FakeCCDelayBasedTimeSource> timeSource = FakeCCDelayBasedTimeSource::
create(interval, &thread); | |
| 38 CCFrameRateController controller(timeSource); | |
| 39 | |
| 40 controller.setClient(&client); | |
| 41 controller.setActive(true); | |
| 42 | |
| 43 base::TimeTicks elapsed; // Muck around with time a bit | |
| 44 | |
| 45 // Trigger one frame, make sure the vsync callback is called | |
| 46 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); | |
| 47 timeSource->setNow(elapsed); | |
| 48 thread.runPendingTask(); | |
| 49 EXPECT_TRUE(client.vsyncTicked()); | |
| 50 client.reset(); | |
| 51 | |
| 52 // Tell the controller we drew | |
| 53 controller.didBeginFrame(); | |
| 54 | |
| 55 // Tell the controller the frame ended 5ms later | |
| 56 timeSource->setNow(timeSource->now() + base::TimeDelta::FromMilliseconds(5))
; | |
| 57 controller.didFinishFrame(); | |
| 58 | |
| 59 // Trigger another frame, make sure vsync runs again | |
| 60 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); | |
| 61 EXPECT_TRUE(elapsed >= timeSource->now()); // Sanity check that previous cod
e didn't move time backward. | |
| 62 timeSource->setNow(elapsed); | |
| 63 thread.runPendingTask(); | |
| 64 EXPECT_TRUE(client.vsyncTicked()); | |
| 65 } | |
| 66 | |
| 67 TEST(CCFrameRateControllerTest, TestFrameThrottling_TwoFramesInFlight) | |
| 68 { | |
| 69 FakeCCThread thread; | |
| 70 FakeCCFrameRateControllerClient client; | |
| 71 base::TimeDelta interval = base::TimeDelta::FromMicroseconds(base::Time::kMi
crosecondsPerSecond / 60); | |
| 72 RefPtr<FakeCCDelayBasedTimeSource> timeSource = FakeCCDelayBasedTimeSource::
create(interval, &thread); | |
| 73 CCFrameRateController controller(timeSource); | |
| 74 | |
| 75 controller.setClient(&client); | |
| 76 controller.setActive(true); | |
| 77 controller.setMaxFramesPending(2); | |
| 78 | |
| 79 base::TimeTicks elapsed; // Muck around with time a bit | |
| 80 | |
| 81 // Trigger one frame, make sure the vsync callback is called | |
| 82 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); | |
| 83 timeSource->setNow(elapsed); | |
| 84 thread.runPendingTask(); | |
| 85 EXPECT_TRUE(client.vsyncTicked()); | |
| 86 client.reset(); | |
| 87 | |
| 88 // Tell the controller we drew | |
| 89 controller.didBeginFrame(); | |
| 90 | |
| 91 // Trigger another frame, make sure vsync callback runs again | |
| 92 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); | |
| 93 EXPECT_TRUE(elapsed >= timeSource->now()); // Sanity check that previous cod
e didn't move time backward. | |
| 94 timeSource->setNow(elapsed); | |
| 95 thread.runPendingTask(); | |
| 96 EXPECT_TRUE(client.vsyncTicked()); | |
| 97 client.reset(); | |
| 98 | |
| 99 // Tell the controller we drew, again. | |
| 100 controller.didBeginFrame(); | |
| 101 | |
| 102 // Trigger another frame. Since two frames are pending, we should not draw. | |
| 103 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); | |
| 104 EXPECT_TRUE(elapsed >= timeSource->now()); // Sanity check that previous cod
e didn't move time backward. | |
| 105 timeSource->setNow(elapsed); | |
| 106 thread.runPendingTask(); | |
| 107 EXPECT_FALSE(client.vsyncTicked()); | |
| 108 | |
| 109 // Tell the controller the first frame ended 5ms later | |
| 110 timeSource->setNow(timeSource->now() + base::TimeDelta::FromMilliseconds(5))
; | |
| 111 controller.didFinishFrame(); | |
| 112 | |
| 113 // Tick should not have been called | |
| 114 EXPECT_FALSE(client.vsyncTicked()); | |
| 115 | |
| 116 // Trigger yet another frame. Since one frames is pending, another vsync cal
lback should run. | |
| 117 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); | |
| 118 EXPECT_TRUE(elapsed >= timeSource->now()); // Sanity check that previous cod
e didn't move time backward. | |
| 119 timeSource->setNow(elapsed); | |
| 120 thread.runPendingTask(); | |
| 121 EXPECT_TRUE(client.vsyncTicked()); | |
| 122 } | |
| 123 | |
| 124 TEST(CCFrameRateControllerTest, TestFrameThrottling_Unthrottled) | |
| 125 { | |
| 126 FakeCCThread thread; | |
| 127 FakeCCFrameRateControllerClient client; | |
| 128 CCFrameRateController controller(&thread); | |
| 129 | |
| 130 controller.setClient(&client); | |
| 131 controller.setMaxFramesPending(2); | |
| 132 | |
| 133 // setActive triggers 1st frame, make sure the vsync callback is called | |
| 134 controller.setActive(true); | |
| 135 thread.runPendingTask(); | |
| 136 EXPECT_TRUE(client.vsyncTicked()); | |
| 137 client.reset(); | |
| 138 | |
| 139 // Even if we don't call didBeginFrame, CCFrameRateController should | |
| 140 // still attempt to vsync tick multiple times until it does result in | |
| 141 // a didBeginFrame. | |
| 142 thread.runPendingTask(); | |
| 143 EXPECT_TRUE(client.vsyncTicked()); | |
| 144 client.reset(); | |
| 145 | |
| 146 thread.runPendingTask(); | |
| 147 EXPECT_TRUE(client.vsyncTicked()); | |
| 148 client.reset(); | |
| 149 | |
| 150 // didBeginFrame triggers 2nd frame, make sure the vsync callback is called | |
| 151 controller.didBeginFrame(); | |
| 152 thread.runPendingTask(); | |
| 153 EXPECT_TRUE(client.vsyncTicked()); | |
| 154 client.reset(); | |
| 155 | |
| 156 // didBeginFrame triggers 3rd frame (> maxFramesPending), make sure the vsyn
c callback is NOT called | |
| 157 controller.didBeginFrame(); | |
| 158 thread.runPendingTask(); | |
| 159 EXPECT_FALSE(client.vsyncTicked()); | |
| 160 client.reset(); | |
| 161 | |
| 162 // Make sure there is no pending task since we can't do anything until we re
ceive a didFinishFrame anyway. | |
| 163 EXPECT_FALSE(thread.hasPendingTask()); | |
| 164 | |
| 165 // didFinishFrame triggers a frame, make sure the vsync callback is called | |
| 166 controller.didFinishFrame(); | |
| 167 thread.runPendingTask(); | |
| 168 EXPECT_TRUE(client.vsyncTicked()); | |
| 169 } | |
| 170 | |
| 171 } | |
| OLD | NEW |