| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/vsync_time_source.h" | 5 #include "cc/scheduler/vsync_time_source.h" |
| 6 | 6 |
| 7 #include "base/logging.h" |
| 8 |
| 7 namespace cc { | 9 namespace cc { |
| 8 | 10 |
| 9 scoped_refptr<VSyncTimeSource> VSyncTimeSource::Create( | 11 scoped_refptr<VSyncTimeSource> VSyncTimeSource::Create( |
| 10 VSyncProvider* vsync_provider) { | 12 VSyncProvider* vsync_provider, bool lazy_disable) { |
| 11 return make_scoped_refptr(new VSyncTimeSource(vsync_provider)); | 13 return make_scoped_refptr(new VSyncTimeSource(vsync_provider, lazy_disable)); |
| 12 } | 14 } |
| 13 | 15 |
| 14 VSyncTimeSource::VSyncTimeSource(VSyncProvider* vsync_provider) | 16 VSyncTimeSource::VSyncTimeSource( |
| 17 VSyncProvider* vsync_provider, bool lazy_disable) |
| 15 : active_(false), | 18 : active_(false), |
| 16 notification_requested_(false), | 19 notification_requested_(false), |
| 17 vsync_provider_(vsync_provider), | 20 vsync_provider_(vsync_provider), |
| 18 client_(NULL) {} | 21 client_(NULL), |
| 22 lazy_disable_(lazy_disable) {} |
| 19 | 23 |
| 20 VSyncTimeSource::~VSyncTimeSource() {} | 24 VSyncTimeSource::~VSyncTimeSource() {} |
| 21 | 25 |
| 22 void VSyncTimeSource::SetClient(TimeSourceClient* client) { | 26 void VSyncTimeSource::SetClient(TimeSourceClient* client) { |
| 23 client_ = client; | 27 client_ = client; |
| 24 } | 28 } |
| 25 | 29 |
| 26 void VSyncTimeSource::SetActive(bool active) { | 30 void VSyncTimeSource::SetActive(bool active) { |
| 27 if (active_ == active) | 31 if (active_ == active) |
| 28 return; | 32 return; |
| 29 active_ = active; | 33 active_ = active; |
| 30 // The notification will be lazily disabled in the callback to ensure | 34 // The notification will be lazily disabled in the callback to ensure |
| 31 // we get notified of the frame immediately following a quick on-off-on | 35 // we get notified of the frame immediately following a quick on-off-on |
| 32 // transition. | 36 // transition. |
| 33 if (active_ && !notification_requested_) { | 37 if (active_ && !notification_requested_) { |
| 34 notification_requested_ = true; | 38 notification_requested_ = true; |
| 35 vsync_provider_->RequestVSyncNotification(this); | 39 vsync_provider_->RequestVSyncNotification(this); |
| 36 } | 40 } |
| 41 if (!active_ && !lazy_disable_) { |
| 42 notification_requested_ = false; |
| 43 vsync_provider_->RequestVSyncNotification(NULL); |
| 44 } |
| 37 } | 45 } |
| 38 | 46 |
| 39 bool VSyncTimeSource::Active() const { | 47 bool VSyncTimeSource::Active() const { |
| 40 return active_; | 48 return active_; |
| 41 } | 49 } |
| 42 | 50 |
| 43 base::TimeTicks VSyncTimeSource::LastTickTime() { | 51 base::TimeTicks VSyncTimeSource::LastTickTime() { |
| 44 return last_tick_time_; | 52 return last_tick_time_; |
| 45 } | 53 } |
| 46 | 54 |
| 47 base::TimeTicks VSyncTimeSource::NextTickTime() { | 55 base::TimeTicks VSyncTimeSource::NextTickTime() { |
| 48 return Active() ? last_tick_time_ + interval_ : base::TimeTicks(); | 56 return Active() ? last_tick_time_ + interval_ : base::TimeTicks(); |
| 49 } | 57 } |
| 50 | 58 |
| 51 void VSyncTimeSource::SetTimebaseAndInterval(base::TimeTicks, | 59 void VSyncTimeSource::SetTimebaseAndInterval(base::TimeTicks, |
| 52 base::TimeDelta interval) { | 60 base::TimeDelta interval) { |
| 53 interval_ = interval; | 61 interval_ = interval; |
| 54 } | 62 } |
| 55 | 63 |
| 56 void VSyncTimeSource::DidVSync(base::TimeTicks frame_time) { | 64 void VSyncTimeSource::DidVSync(base::TimeTicks frame_time) { |
| 57 last_tick_time_ = frame_time; | 65 last_tick_time_ = frame_time; |
| 58 if (!active_) { | 66 if (!lazy_disable_) { |
| 67 DCHECK(active_); |
| 68 } else if (!active_) { |
| 59 if (notification_requested_) { | 69 if (notification_requested_) { |
| 60 notification_requested_ = false; | 70 notification_requested_ = false; |
| 61 vsync_provider_->RequestVSyncNotification(NULL); | 71 vsync_provider_->RequestVSyncNotification(NULL); |
| 62 } | 72 } |
| 63 return; | 73 return; |
| 64 } | 74 } |
| 65 if (client_) | 75 if (client_) |
| 66 client_->OnTimerTick(); | 76 client_->OnTimerTick(); |
| 67 } | 77 } |
| 68 | 78 |
| 69 } // namespace cc | 79 } // namespace cc |
| OLD | NEW |