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/delay_based_time_source.h" | 5 #include "cc/scheduler/delay_based_time_source.h" |
6 | 6 |
| 7 #include "base/basictypes.h" |
7 #include "cc/base/thread.h" | 8 #include "cc/base/thread.h" |
8 #include "cc/test/scheduler_test_common.h" | 9 #include "cc/test/scheduler_test_common.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 namespace cc { | 12 namespace cc { |
12 namespace { | 13 namespace { |
13 | 14 |
14 base::TimeDelta Interval() { | 15 base::TimeDelta Interval() { |
15 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond / | 16 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond / |
16 60); | 17 60); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 297 |
297 FakeThread thread; | 298 FakeThread thread; |
298 FakeTimeSourceClient client; | 299 FakeTimeSourceClient client; |
299 scoped_refptr<FakeDelayBasedTimeSource> timer = | 300 scoped_refptr<FakeDelayBasedTimeSource> timer = |
300 FakeDelayBasedTimeSource::Create(Interval(), &thread); | 301 FakeDelayBasedTimeSource::Create(Interval(), &thread); |
301 timer->SetClient(&client); | 302 timer->SetClient(&client); |
302 timer->SetActive(true); | 303 timer->SetActive(true); |
303 | 304 |
304 double total_frame_time = 0.0; | 305 double total_frame_time = 0.0; |
305 for (int i = 0; i < num_iterations; ++i) { | 306 for (int i = 0; i < num_iterations; ++i) { |
306 long long delay_ms = thread.PendingDelayMs(); | 307 int64 delay_ms = thread.PendingDelayMs(); |
307 | 308 |
308 // accumulate the "delay" | 309 // accumulate the "delay" |
309 total_frame_time += delay_ms / 1000.0; | 310 total_frame_time += delay_ms / 1000.0; |
310 | 311 |
311 // Run the callback exactly when asked | 312 // Run the callback exactly when asked |
312 timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(delay_ms)); | 313 timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(delay_ms)); |
313 thread.RunPendingTask(); | 314 thread.RunPendingTask(); |
314 } | 315 } |
315 double average_interval = | 316 double average_interval = |
316 total_frame_time / static_cast<double>(num_iterations); | 317 total_frame_time / static_cast<double>(num_iterations); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 373 |
373 // Start the timer again, but before the next tick time the timer previously | 374 // Start the timer again, but before the next tick time the timer previously |
374 // planned on using. That same tick time should still be targeted. | 375 // planned on using. That same tick time should still be targeted. |
375 timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(20)); | 376 timer->SetNow(timer->Now() + base::TimeDelta::FromMilliseconds(20)); |
376 timer->SetActive(true); | 377 timer->SetActive(true); |
377 EXPECT_EQ(13, thread.PendingDelayMs()); | 378 EXPECT_EQ(13, thread.PendingDelayMs()); |
378 } | 379 } |
379 | 380 |
380 } // namespace | 381 } // namespace |
381 } // namespace cc | 382 } // namespace cc |
OLD | NEW |