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 "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
8 #include "cc/test/scheduler_test_common.h" | 8 #include "cc/test/scheduler_test_common.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace cc { | 11 namespace cc { |
12 namespace { | 12 namespace { |
13 | 13 |
14 class FakeFrameRateControllerClient : public cc::FrameRateControllerClient { | 14 class FakeFrameRateControllerClient : public cc::FrameRateControllerClient { |
15 public: | 15 public: |
16 FakeFrameRateControllerClient() { Reset(); } | 16 FakeFrameRateControllerClient() { Reset(); } |
17 | 17 |
18 void Reset() { began_frame_ = false; } | 18 void Reset() { frame_count_ = 0; } |
19 bool BeganFrame() const { return began_frame_; } | 19 bool BeganFrame() const { return frame_count_ > 0; } |
| 20 int frame_count() const { return frame_count_; } |
20 | 21 |
21 virtual void FrameRateControllerTick( | 22 virtual void FrameRateControllerTick( |
22 bool throttled, const BeginFrameArgs& args) OVERRIDE { | 23 bool throttled, const BeginFrameArgs& args) OVERRIDE { |
23 began_frame_ = !throttled; | 24 frame_count_ += throttled ? 0 : 1; |
24 } | 25 } |
25 | 26 |
26 protected: | 27 protected: |
27 bool began_frame_; | 28 int frame_count_; |
28 }; | 29 }; |
29 | 30 |
30 TEST(FrameRateControllerTest, TestFrameThrottling_ImmediateAck) { | 31 TEST(FrameRateControllerTest, TestFrameThrottling_ImmediateAck) { |
31 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | 32 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
32 new base::TestSimpleTaskRunner; | 33 new base::TestSimpleTaskRunner; |
33 FakeFrameRateControllerClient client; | 34 FakeFrameRateControllerClient client; |
34 base::TimeDelta interval = base::TimeDelta::FromMicroseconds( | 35 base::TimeDelta interval = base::TimeDelta::FromMicroseconds( |
35 base::Time::kMicrosecondsPerSecond / 60); | 36 base::Time::kMicrosecondsPerSecond / 60); |
36 scoped_refptr<FakeDelayBasedTimeSource> time_source = | 37 scoped_refptr<FakeDelayBasedTimeSource> time_source = |
37 FakeDelayBasedTimeSource::Create(interval, task_runner.get()); | 38 FakeDelayBasedTimeSource::Create(interval, task_runner.get()); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // receive a DidSwapBuffersComplete anyway. | 176 // receive a DidSwapBuffersComplete anyway. |
176 EXPECT_FALSE(task_runner->HasPendingTask()); | 177 EXPECT_FALSE(task_runner->HasPendingTask()); |
177 | 178 |
178 // DidSwapBuffersComplete triggers a frame, make sure the BeginFrame | 179 // DidSwapBuffersComplete triggers a frame, make sure the BeginFrame |
179 // callback is called | 180 // callback is called |
180 controller.DidSwapBuffersComplete(); | 181 controller.DidSwapBuffersComplete(); |
181 task_runner->RunPendingTasks(); | 182 task_runner->RunPendingTasks(); |
182 EXPECT_TRUE(client.BeganFrame()); | 183 EXPECT_TRUE(client.BeganFrame()); |
183 } | 184 } |
184 | 185 |
| 186 TEST(FrameRateControllerTest, TestFrameThrottling_NoDoubleTicking) { |
| 187 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
| 188 new base::TestSimpleTaskRunner; |
| 189 FakeFrameRateControllerClient client; |
| 190 FrameRateController controller(task_runner.get()); |
| 191 controller.SetClient(&client); |
| 192 |
| 193 // SetActive triggers 1st frame and queues another tick task since the time |
| 194 // source isn't throttling. |
| 195 controller.SetActive(true); |
| 196 task_runner->RunPendingTasks(); |
| 197 EXPECT_TRUE(client.BeganFrame()); |
| 198 client.Reset(); |
| 199 EXPECT_TRUE(task_runner->HasPendingTask()); |
| 200 |
| 201 // Simulate a frame swap. This shouldn't queue a second tick task. |
| 202 controller.DidSwapBuffers(); |
| 203 controller.DidSwapBuffersComplete(); |
| 204 |
| 205 // The client should only be ticked once. |
| 206 task_runner->RunPendingTasks(); |
| 207 EXPECT_EQ(1, client.frame_count()); |
| 208 } |
| 209 |
185 } // namespace | 210 } // namespace |
186 } // namespace cc | 211 } // namespace cc |
OLD | NEW |