| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCFrameRateController.h" | 7 #include "CCFrameRateController.h" |
| 8 | 8 |
| 9 #include "CCSchedulerTestCommon.h" | 9 #include "CCSchedulerTestCommon.h" |
| 10 #include <gtest/gtest.h> | 10 #include <gtest/gtest.h> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 protected: | 27 protected: |
| 28 bool m_vsyncTicked; | 28 bool m_vsyncTicked; |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 | 31 |
| 32 TEST(CCFrameRateControllerTest, TestFrameThrottling_ImmediateAck) | 32 TEST(CCFrameRateControllerTest, TestFrameThrottling_ImmediateAck) |
| 33 { | 33 { |
| 34 FakeCCThread thread; | 34 FakeCCThread thread; |
| 35 FakeCCFrameRateControllerClient client; | 35 FakeCCFrameRateControllerClient client; |
| 36 RefPtr<FakeCCDelayBasedTimeSource> timeSource = FakeCCDelayBasedTimeSource::
create(1.0 / 60.0, &thread); | 36 base::TimeDelta interval = base::TimeDelta::FromMicroseconds(base::Time::kMi
crosecondsPerSecond / 60); |
| 37 RefPtr<FakeCCDelayBasedTimeSource> timeSource = FakeCCDelayBasedTimeSource::
create(interval, &thread); |
| 37 CCFrameRateController controller(timeSource); | 38 CCFrameRateController controller(timeSource); |
| 38 | 39 |
| 39 controller.setClient(&client); | 40 controller.setClient(&client); |
| 40 controller.setActive(true); | 41 controller.setActive(true); |
| 41 | 42 |
| 42 double elapsed = 0; // Muck around with time a bit | 43 base::TimeTicks elapsed; // Muck around with time a bit |
| 43 | 44 |
| 44 // Trigger one frame, make sure the vsync callback is called | 45 // Trigger one frame, make sure the vsync callback is called |
| 45 elapsed += thread.pendingDelayMs() / 1000.0; | 46 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); |
| 46 timeSource->setMonotonicTimeNow(elapsed); | 47 timeSource->setNow(elapsed); |
| 47 thread.runPendingTask(); | 48 thread.runPendingTask(); |
| 48 EXPECT_TRUE(client.vsyncTicked()); | 49 EXPECT_TRUE(client.vsyncTicked()); |
| 49 client.reset(); | 50 client.reset(); |
| 50 | 51 |
| 51 // Tell the controller we drew | 52 // Tell the controller we drew |
| 52 controller.didBeginFrame(); | 53 controller.didBeginFrame(); |
| 53 | 54 |
| 54 // Tell the controller the frame ended 5ms later | 55 // Tell the controller the frame ended 5ms later |
| 55 timeSource->setMonotonicTimeNow(timeSource->monotonicTimeNow() + 0.005); | 56 timeSource->setNow(timeSource->now() + base::TimeDelta::FromMilliseconds(5))
; |
| 56 controller.didFinishFrame(); | 57 controller.didFinishFrame(); |
| 57 | 58 |
| 58 // Trigger another frame, make sure vsync runs again | 59 // Trigger another frame, make sure vsync runs again |
| 59 elapsed += thread.pendingDelayMs() / 1000.0; | 60 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); |
| 60 EXPECT_TRUE(elapsed >= timeSource->monotonicTimeNow()); // Sanity check that
previous code didn't move time backward. | 61 EXPECT_TRUE(elapsed >= timeSource->now()); // Sanity check that previous cod
e didn't move time backward. |
| 61 timeSource->setMonotonicTimeNow(elapsed); | 62 timeSource->setNow(elapsed); |
| 62 thread.runPendingTask(); | 63 thread.runPendingTask(); |
| 63 EXPECT_TRUE(client.vsyncTicked()); | 64 EXPECT_TRUE(client.vsyncTicked()); |
| 64 } | 65 } |
| 65 | 66 |
| 66 TEST(CCFrameRateControllerTest, TestFrameThrottling_TwoFramesInFlight) | 67 TEST(CCFrameRateControllerTest, TestFrameThrottling_TwoFramesInFlight) |
| 67 { | 68 { |
| 68 FakeCCThread thread; | 69 FakeCCThread thread; |
| 69 FakeCCFrameRateControllerClient client; | 70 FakeCCFrameRateControllerClient client; |
| 70 RefPtr<FakeCCDelayBasedTimeSource> timeSource = FakeCCDelayBasedTimeSource::
create(1.0 / 60.0, &thread); | 71 base::TimeDelta interval = base::TimeDelta::FromMicroseconds(base::Time::kMi
crosecondsPerSecond / 60); |
| 72 RefPtr<FakeCCDelayBasedTimeSource> timeSource = FakeCCDelayBasedTimeSource::
create(interval, &thread); |
| 71 CCFrameRateController controller(timeSource); | 73 CCFrameRateController controller(timeSource); |
| 72 | 74 |
| 73 controller.setClient(&client); | 75 controller.setClient(&client); |
| 74 controller.setActive(true); | 76 controller.setActive(true); |
| 75 controller.setMaxFramesPending(2); | 77 controller.setMaxFramesPending(2); |
| 76 | 78 |
| 77 double elapsed = 0; // Muck around with time a bit | 79 base::TimeTicks elapsed; // Muck around with time a bit |
| 78 | 80 |
| 79 // Trigger one frame, make sure the vsync callback is called | 81 // Trigger one frame, make sure the vsync callback is called |
| 80 elapsed += thread.pendingDelayMs() / 1000.0; | 82 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); |
| 81 timeSource->setMonotonicTimeNow(elapsed); | 83 timeSource->setNow(elapsed); |
| 82 thread.runPendingTask(); | 84 thread.runPendingTask(); |
| 83 EXPECT_TRUE(client.vsyncTicked()); | 85 EXPECT_TRUE(client.vsyncTicked()); |
| 84 client.reset(); | 86 client.reset(); |
| 85 | 87 |
| 86 // Tell the controller we drew | 88 // Tell the controller we drew |
| 87 controller.didBeginFrame(); | 89 controller.didBeginFrame(); |
| 88 | 90 |
| 89 // Trigger another frame, make sure vsync callback runs again | 91 // Trigger another frame, make sure vsync callback runs again |
| 90 elapsed += thread.pendingDelayMs() / 1000.0; | 92 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); |
| 91 EXPECT_TRUE(elapsed >= timeSource->monotonicTimeNow()); // Sanity check that
previous code didn't move time backward. | 93 EXPECT_TRUE(elapsed >= timeSource->now()); // Sanity check that previous cod
e didn't move time backward. |
| 92 timeSource->setMonotonicTimeNow(elapsed); | 94 timeSource->setNow(elapsed); |
| 93 thread.runPendingTask(); | 95 thread.runPendingTask(); |
| 94 EXPECT_TRUE(client.vsyncTicked()); | 96 EXPECT_TRUE(client.vsyncTicked()); |
| 95 client.reset(); | 97 client.reset(); |
| 96 | 98 |
| 97 // Tell the controller we drew, again. | 99 // Tell the controller we drew, again. |
| 98 controller.didBeginFrame(); | 100 controller.didBeginFrame(); |
| 99 | 101 |
| 100 // Trigger another frame. Since two frames are pending, we should not draw. | 102 // Trigger another frame. Since two frames are pending, we should not draw. |
| 101 elapsed += thread.pendingDelayMs() / 1000.0; | 103 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); |
| 102 EXPECT_TRUE(elapsed >= timeSource->monotonicTimeNow()); // Sanity check that
previous code didn't move time backward. | 104 EXPECT_TRUE(elapsed >= timeSource->now()); // Sanity check that previous cod
e didn't move time backward. |
| 103 timeSource->setMonotonicTimeNow(elapsed); | 105 timeSource->setNow(elapsed); |
| 104 thread.runPendingTask(); | 106 thread.runPendingTask(); |
| 105 EXPECT_FALSE(client.vsyncTicked()); | 107 EXPECT_FALSE(client.vsyncTicked()); |
| 106 | 108 |
| 107 // Tell the controller the first frame ended 5ms later | 109 // Tell the controller the first frame ended 5ms later |
| 108 timeSource->setMonotonicTimeNow(timeSource->monotonicTimeNow() + 0.005); | 110 timeSource->setNow(timeSource->now() + base::TimeDelta::FromMilliseconds(5))
; |
| 109 controller.didFinishFrame(); | 111 controller.didFinishFrame(); |
| 110 | 112 |
| 111 // Tick should not have been called | 113 // Tick should not have been called |
| 112 EXPECT_FALSE(client.vsyncTicked()); | 114 EXPECT_FALSE(client.vsyncTicked()); |
| 113 | 115 |
| 114 // Trigger yet another frame. Since one frames is pending, another vsync cal
lback should run. | 116 // Trigger yet another frame. Since one frames is pending, another vsync cal
lback should run. |
| 115 elapsed += thread.pendingDelayMs() / 1000.0; | 117 elapsed += base::TimeDelta::FromMilliseconds(thread.pendingDelayMs()); |
| 116 EXPECT_TRUE(elapsed >= timeSource->monotonicTimeNow()); // Sanity check that
previous code didn't move time backward. | 118 EXPECT_TRUE(elapsed >= timeSource->now()); // Sanity check that previous cod
e didn't move time backward. |
| 117 timeSource->setMonotonicTimeNow(elapsed); | 119 timeSource->setNow(elapsed); |
| 118 thread.runPendingTask(); | 120 thread.runPendingTask(); |
| 119 EXPECT_TRUE(client.vsyncTicked()); | 121 EXPECT_TRUE(client.vsyncTicked()); |
| 120 } | 122 } |
| 121 | 123 |
| 122 TEST(CCFrameRateControllerTest, TestFrameThrottling_Unthrottled) | 124 TEST(CCFrameRateControllerTest, TestFrameThrottling_Unthrottled) |
| 123 { | 125 { |
| 124 FakeCCThread thread; | 126 FakeCCThread thread; |
| 125 FakeCCFrameRateControllerClient client; | 127 FakeCCFrameRateControllerClient client; |
| 126 CCFrameRateController controller(&thread); | 128 CCFrameRateController controller(&thread); |
| 127 | 129 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 // Make sure there is no pending task since we can't do anything until we re
ceive a didFinishFrame anyway. | 162 // Make sure there is no pending task since we can't do anything until we re
ceive a didFinishFrame anyway. |
| 161 EXPECT_FALSE(thread.hasPendingTask()); | 163 EXPECT_FALSE(thread.hasPendingTask()); |
| 162 | 164 |
| 163 // didFinishFrame triggers a frame, make sure the vsync callback is called | 165 // didFinishFrame triggers a frame, make sure the vsync callback is called |
| 164 controller.didFinishFrame(); | 166 controller.didFinishFrame(); |
| 165 thread.runPendingTask(); | 167 thread.runPendingTask(); |
| 166 EXPECT_TRUE(client.vsyncTicked()); | 168 EXPECT_TRUE(client.vsyncTicked()); |
| 167 } | 169 } |
| 168 | 170 |
| 169 } | 171 } |
| OLD | NEW |