OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 "cc/scheduler/vsync_time_source.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 namespace cc { | |
10 | |
11 scoped_refptr<VSyncTimeSource> VSyncTimeSource::Create( | |
12 VSyncProvider* vsync_provider, NotificationDisableOption option) { | |
13 return make_scoped_refptr(new VSyncTimeSource(vsync_provider, option)); | |
14 } | |
15 | |
16 VSyncTimeSource::VSyncTimeSource( | |
17 VSyncProvider* vsync_provider, NotificationDisableOption option) | |
18 : active_(false), | |
19 notification_requested_(false), | |
20 vsync_provider_(vsync_provider), | |
21 client_(NULL), | |
22 disable_option_(option) {} | |
23 | |
24 VSyncTimeSource::~VSyncTimeSource() {} | |
25 | |
26 void VSyncTimeSource::SetClient(TimeSourceClient* client) { | |
27 client_ = client; | |
28 } | |
29 | |
30 void VSyncTimeSource::SetActive(bool active) { | |
31 if (active_ == active) | |
32 return; | |
33 active_ = active; | |
34 if (active_ && !notification_requested_) { | |
35 notification_requested_ = true; | |
36 vsync_provider_->RequestVSyncNotification(this); | |
37 } | |
38 if (!active_ && disable_option_ == DISABLE_SYNCHRONOUSLY) { | |
39 notification_requested_ = false; | |
40 vsync_provider_->RequestVSyncNotification(NULL); | |
41 } | |
42 } | |
43 | |
44 bool VSyncTimeSource::Active() const { | |
45 return active_; | |
46 } | |
47 | |
48 base::TimeTicks VSyncTimeSource::LastTickTime() { | |
49 return last_tick_time_; | |
50 } | |
51 | |
52 base::TimeTicks VSyncTimeSource::NextTickTime() { | |
53 return Active() ? last_tick_time_ + interval_ : base::TimeTicks(); | |
54 } | |
55 | |
56 void VSyncTimeSource::SetTimebaseAndInterval(base::TimeTicks, | |
57 base::TimeDelta interval) { | |
58 interval_ = interval; | |
59 } | |
60 | |
61 void VSyncTimeSource::DidVSync(base::TimeTicks frame_time) { | |
62 last_tick_time_ = frame_time; | |
63 if (disable_option_ == DISABLE_SYNCHRONOUSLY) { | |
64 DCHECK(active_); | |
65 } else if (!active_) { | |
66 if (notification_requested_) { | |
67 notification_requested_ = false; | |
68 vsync_provider_->RequestVSyncNotification(NULL); | |
69 } | |
70 return; | |
71 } | |
72 if (client_) | |
73 client_->OnTimerTick(); | |
74 } | |
75 | |
76 } // namespace cc | |
OLD | NEW |