Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/compositor/gpu_vsync_begin_frame_source.h" | 5 #include "content/browser/compositor/gpu_vsync_begin_frame_source.h" |
| 6 | 6 |
| 7 namespace content { | 7 namespace content { |
| 8 | 8 |
| 9 GpuVSyncBeginFrameSource::GpuVSyncBeginFrameSource( | 9 GpuVSyncBeginFrameSource::GpuVSyncBeginFrameSource( |
| 10 GpuVSyncControl* vsync_control) | 10 GpuVSyncControl* vsync_control) |
| 11 : cc::ExternalBeginFrameSource(this), | 11 : cc::ExternalBeginFrameSource(this), |
| 12 vsync_control_(vsync_control), | 12 vsync_control_(vsync_control), |
| 13 needs_begin_frames_(false), | 13 needs_begin_frames_(false), |
| 14 next_sequence_number_(cc::BeginFrameArgs::kStartingFrameNumber) { | 14 next_sequence_number_(cc::BeginFrameArgs::kStartingFrameNumber) { |
| 15 DCHECK(vsync_control); | 15 DCHECK(vsync_control); |
| 16 } | 16 } |
| 17 | 17 |
| 18 GpuVSyncBeginFrameSource::~GpuVSyncBeginFrameSource() = default; | 18 GpuVSyncBeginFrameSource::~GpuVSyncBeginFrameSource() = default; |
| 19 | 19 |
| 20 void GpuVSyncBeginFrameSource::OnVSync(base::TimeTicks timestamp, | 20 void GpuVSyncBeginFrameSource::OnVSync(base::TimeTicks timestamp, |
| 21 base::TimeDelta interval) { | 21 base::TimeDelta interval) { |
| 22 if (!needs_begin_frames_) | 22 if (!needs_begin_frames_) |
| 23 return; | 23 return; |
| 24 | 24 |
| 25 base::TimeTicks now = base::TimeTicks::Now(); | 25 base::TimeTicks now = Now(); |
| 26 base::TimeTicks deadline = now.SnappedToNextTick(timestamp, interval); | 26 base::TimeTicks deadline = now.SnappedToNextTick(timestamp, interval); |
| 27 | 27 |
| 28 TRACE_EVENT1("cc", "GpuVSyncBeginFrameSource::OnVSync", "latency", | 28 TRACE_EVENT1("cc", "GpuVSyncBeginFrameSource::OnVSync", "latency", |
| 29 (now - timestamp).ToInternalValue()); | 29 (now - timestamp).ToInternalValue()); |
| 30 | 30 |
| 31 next_sequence_number_++; | 31 next_sequence_number_++; |
| 32 OnBeginFrame(cc::BeginFrameArgs::Create( | 32 OnBeginFrame(cc::BeginFrameArgs::Create( |
| 33 BEGINFRAME_FROM_HERE, source_id(), next_sequence_number_, timestamp, | 33 BEGINFRAME_FROM_HERE, source_id(), next_sequence_number_, timestamp, |
| 34 deadline, interval, cc::BeginFrameArgs::NORMAL)); | 34 deadline, interval, cc::BeginFrameArgs::NORMAL)); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void GpuVSyncBeginFrameSource::OnNeedsBeginFrames(bool needs_begin_frames) { | 37 void GpuVSyncBeginFrameSource::OnNeedsBeginFrames(bool needs_begin_frames) { |
| 38 needs_begin_frames_ = needs_begin_frames; | 38 needs_begin_frames_ = needs_begin_frames; |
| 39 vsync_control_->SetNeedsVSync(needs_begin_frames); | 39 vsync_control_->SetNeedsVSync(needs_begin_frames); |
| 40 } | 40 } |
| 41 | 41 |
| 42 base::TimeTicks GpuVSyncBeginFrameSource::Now() const { | |
| 43 return base::TimeTicks::Now(); | |
| 44 } | |
| 45 | |
| 46 bool GpuVSyncBeginFrameSource::GetMissedBeginFrameArgs( | |
| 47 cc::BeginFrameObserver* obs, | |
| 48 cc::BeginFrameArgs* missed_args) { | |
| 49 const cc::BeginFrameArgs& last_observer_args = obs->LastUsedBeginFrameArgs(); | |
| 50 if (!last_begin_frame_args_.IsValid()) { | |
| 51 // This is the case when all observers were removed from this BFS. | |
| 52 if (!last_observer_args.IsValid()) | |
|
sunnyps
2017/05/30 22:13:17
nit: Remove this workaround after removing the "la
stanisc
2017/05/31 01:17:53
Done.
| |
| 53 return false; | |
| 54 | |
| 55 last_begin_frame_args_ = last_observer_args; | |
| 56 } | |
| 57 | |
| 58 base::TimeTicks now = Now(); | |
| 59 base::TimeTicks estimated_next_timestamp = now.SnappedToNextTick( | |
| 60 last_begin_frame_args_.frame_time, last_begin_frame_args_.interval); | |
| 61 base::TimeTicks missed_timestamp = | |
| 62 estimated_next_timestamp - last_begin_frame_args_.interval; | |
| 63 | |
| 64 if (missed_timestamp > last_begin_frame_args_.frame_time) { | |
| 65 // The projected missed timestamp is newer than the last known timestamp. | |
| 66 // In this case create BeginFrameArgs with a new sequence number. | |
| 67 next_sequence_number_++; | |
| 68 last_begin_frame_args_ = cc::BeginFrameArgs::Create( | |
| 69 BEGINFRAME_FROM_HERE, source_id(), next_sequence_number_, | |
| 70 missed_timestamp, estimated_next_timestamp, | |
| 71 last_begin_frame_args_.interval, cc::BeginFrameArgs::MISSED); | |
| 72 } else { | |
| 73 // The last known args object is up-to-date. Skip sending notification | |
| 74 // if the observer has already seen it. | |
| 75 if (last_observer_args.IsValid() && | |
| 76 last_begin_frame_args_.frame_time <= last_observer_args.frame_time) { | |
| 77 return false; | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 *missed_args = last_begin_frame_args_; | |
| 82 missed_args->type = cc::BeginFrameArgs::MISSED; | |
| 83 return true; | |
| 84 } | |
| 85 | |
| 42 } // namespace content | 86 } // namespace content |
| OLD | NEW |