| 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, NotificationDisableOption option) { |
| 11 return make_scoped_refptr(new VSyncTimeSource(vsync_provider)); | 13 return make_scoped_refptr(new VSyncTimeSource(vsync_provider, option)); |
| 12 } | 14 } |
| 13 | 15 |
| 14 VSyncTimeSource::VSyncTimeSource(VSyncProvider* vsync_provider) | 16 VSyncTimeSource::VSyncTimeSource( |
| 17 VSyncProvider* vsync_provider, NotificationDisableOption option) |
| 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 disable_option_(option) {} |
| 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 | |
| 31 // we get notified of the frame immediately following a quick on-off-on | |
| 32 // transition. | |
| 33 if (active_ && !notification_requested_) { | 34 if (active_ && !notification_requested_) { |
| 34 notification_requested_ = true; | 35 notification_requested_ = true; |
| 35 vsync_provider_->RequestVSyncNotification(this); | 36 vsync_provider_->RequestVSyncNotification(this); |
| 36 } | 37 } |
| 38 if (!active_ && disable_option_ == DISABLE_SYNCHRONOUSLY) { |
| 39 notification_requested_ = false; |
| 40 vsync_provider_->RequestVSyncNotification(NULL); |
| 41 } |
| 37 } | 42 } |
| 38 | 43 |
| 39 bool VSyncTimeSource::Active() const { | 44 bool VSyncTimeSource::Active() const { |
| 40 return active_; | 45 return active_; |
| 41 } | 46 } |
| 42 | 47 |
| 43 base::TimeTicks VSyncTimeSource::LastTickTime() { | 48 base::TimeTicks VSyncTimeSource::LastTickTime() { |
| 44 return last_tick_time_; | 49 return last_tick_time_; |
| 45 } | 50 } |
| 46 | 51 |
| 47 base::TimeTicks VSyncTimeSource::NextTickTime() { | 52 base::TimeTicks VSyncTimeSource::NextTickTime() { |
| 48 return Active() ? last_tick_time_ + interval_ : base::TimeTicks(); | 53 return Active() ? last_tick_time_ + interval_ : base::TimeTicks(); |
| 49 } | 54 } |
| 50 | 55 |
| 51 void VSyncTimeSource::SetTimebaseAndInterval(base::TimeTicks, | 56 void VSyncTimeSource::SetTimebaseAndInterval(base::TimeTicks, |
| 52 base::TimeDelta interval) { | 57 base::TimeDelta interval) { |
| 53 interval_ = interval; | 58 interval_ = interval; |
| 54 } | 59 } |
| 55 | 60 |
| 56 void VSyncTimeSource::DidVSync(base::TimeTicks frame_time) { | 61 void VSyncTimeSource::DidVSync(base::TimeTicks frame_time) { |
| 57 last_tick_time_ = frame_time; | 62 last_tick_time_ = frame_time; |
| 58 if (!active_) { | 63 if (disable_option_ == DISABLE_SYNCHRONOUSLY) { |
| 64 DCHECK(active_); |
| 65 } else if (!active_) { |
| 59 if (notification_requested_) { | 66 if (notification_requested_) { |
| 60 notification_requested_ = false; | 67 notification_requested_ = false; |
| 61 vsync_provider_->RequestVSyncNotification(NULL); | 68 vsync_provider_->RequestVSyncNotification(NULL); |
| 62 } | 69 } |
| 63 return; | 70 return; |
| 64 } | 71 } |
| 65 if (client_) | 72 if (client_) |
| 66 client_->OnTimerTick(); | 73 client_->OnTimerTick(); |
| 67 } | 74 } |
| 68 | 75 |
| 69 } // namespace cc | 76 } // namespace cc |
| OLD | NEW |