| 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 "cc/scheduler/frame_rate_controller.h" | 5 #include "cc/scheduler/frame_rate_controller.h" |
| 6 | 6 |
| 7 #include "cc/test/scheduler_test_common.h" | 7 #include "cc/test/scheduler_test_common.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 class FakeFrameRateControllerClient : public cc::FrameRateControllerClient { | 13 class FakeFrameRateControllerClient : public cc::FrameRateControllerClient { |
| 14 public: | 14 public: |
| 15 FakeFrameRateControllerClient() { Reset(); } | 15 FakeFrameRateControllerClient() { Reset(); } |
| 16 | 16 |
| 17 void Reset() { began_frame_ = false; } | 17 void Reset() { began_frame_ = false; } |
| 18 bool BeganFrame() const { return began_frame_; } | 18 bool BeganFrame() const { return began_frame_; } |
| 19 | 19 |
| 20 virtual void BeginFrame(bool throttled) OVERRIDE { | 20 virtual void FrameRateControllerTick(bool throttled) OVERRIDE { |
| 21 began_frame_ = !throttled; | 21 began_frame_ = !throttled; |
| 22 } | 22 } |
| 23 | 23 |
| 24 protected: | 24 protected: |
| 25 bool began_frame_; | 25 bool began_frame_; |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 TEST(FrameRateControllerTest, TestFrameThrottling_ImmediateAck) { | 28 TEST(FrameRateControllerTest, TestFrameThrottling_ImmediateAck) { |
| 29 FakeThread thread; | 29 FakeThread thread; |
| 30 FakeFrameRateControllerClient client; | 30 FakeFrameRateControllerClient client; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 FakeThread thread; | 67 FakeThread thread; |
| 68 FakeFrameRateControllerClient client; | 68 FakeFrameRateControllerClient client; |
| 69 base::TimeDelta interval = base::TimeDelta::FromMicroseconds( | 69 base::TimeDelta interval = base::TimeDelta::FromMicroseconds( |
| 70 base::Time::kMicrosecondsPerSecond / 60); | 70 base::Time::kMicrosecondsPerSecond / 60); |
| 71 scoped_refptr<FakeDelayBasedTimeSource> time_source = | 71 scoped_refptr<FakeDelayBasedTimeSource> time_source = |
| 72 FakeDelayBasedTimeSource::Create(interval, &thread); | 72 FakeDelayBasedTimeSource::Create(interval, &thread); |
| 73 FrameRateController controller(time_source); | 73 FrameRateController controller(time_source); |
| 74 | 74 |
| 75 controller.SetClient(&client); | 75 controller.SetClient(&client); |
| 76 controller.SetActive(true); | 76 controller.SetActive(true); |
| 77 controller.SetMaxFramesPending(2); | 77 controller.SetMaxSwapsPending(2); |
| 78 | 78 |
| 79 base::TimeTicks elapsed; // Muck around with time a bit | 79 base::TimeTicks elapsed; // Muck around with time a bit |
| 80 | 80 |
| 81 // Trigger one frame, make sure the BeginFrame callback is called | 81 // Trigger one frame, make sure the BeginFrame callback is called |
| 82 elapsed += base::TimeDelta::FromMilliseconds(thread.PendingDelayMs()); | 82 elapsed += base::TimeDelta::FromMilliseconds(thread.PendingDelayMs()); |
| 83 time_source->SetNow(elapsed); | 83 time_source->SetNow(elapsed); |
| 84 thread.RunPendingTask(); | 84 thread.RunPendingTask(); |
| 85 EXPECT_TRUE(client.BeganFrame()); | 85 EXPECT_TRUE(client.BeganFrame()); |
| 86 client.Reset(); | 86 client.Reset(); |
| 87 | 87 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 thread.RunPendingTask(); | 125 thread.RunPendingTask(); |
| 126 EXPECT_TRUE(client.BeganFrame()); | 126 EXPECT_TRUE(client.BeganFrame()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 TEST(FrameRateControllerTest, TestFrameThrottling_Unthrottled) { | 129 TEST(FrameRateControllerTest, TestFrameThrottling_Unthrottled) { |
| 130 FakeThread thread; | 130 FakeThread thread; |
| 131 FakeFrameRateControllerClient client; | 131 FakeFrameRateControllerClient client; |
| 132 FrameRateController controller(&thread); | 132 FrameRateController controller(&thread); |
| 133 | 133 |
| 134 controller.SetClient(&client); | 134 controller.SetClient(&client); |
| 135 controller.SetMaxFramesPending(2); | 135 controller.SetMaxSwapsPending(2); |
| 136 | 136 |
| 137 // SetActive triggers 1st frame, make sure the BeginFrame callback | 137 // SetActive triggers 1st frame, make sure the BeginFrame callback |
| 138 // is called | 138 // is called |
| 139 controller.SetActive(true); | 139 controller.SetActive(true); |
| 140 thread.RunPendingTask(); | 140 thread.RunPendingTask(); |
| 141 EXPECT_TRUE(client.BeganFrame()); | 141 EXPECT_TRUE(client.BeganFrame()); |
| 142 client.Reset(); | 142 client.Reset(); |
| 143 | 143 |
| 144 // Even if we don't call DidSwapBuffers, FrameRateController should | 144 // Even if we don't call DidSwapBuffers, FrameRateController should |
| 145 // still attempt to tick multiple times until it does result in | 145 // still attempt to tick multiple times until it does result in |
| (...skipping 26 matching lines...) Expand all Loading... |
| 172 | 172 |
| 173 // DidSwapBuffersComplete triggers a frame, make sure the BeginFrame | 173 // DidSwapBuffersComplete triggers a frame, make sure the BeginFrame |
| 174 // callback is called | 174 // callback is called |
| 175 controller.DidSwapBuffersComplete(); | 175 controller.DidSwapBuffersComplete(); |
| 176 thread.RunPendingTask(); | 176 thread.RunPendingTask(); |
| 177 EXPECT_TRUE(client.BeganFrame()); | 177 EXPECT_TRUE(client.BeganFrame()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 } // namespace | 180 } // namespace |
| 181 } // namespace cc | 181 } // namespace cc |
| OLD | NEW |