Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(830)

Unified Diff: content/browser/compositor/gpu_vsync_begin_frame_source.cc

Issue 2555173003: [Do not submit] D3DKMTWaitForVerticalBlankEvent VSync prototype (Closed)
Patch Set: Added command line switch and experiment support Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/compositor/gpu_vsync_begin_frame_source.cc
diff --git a/content/browser/compositor/gpu_vsync_begin_frame_source.cc b/content/browser/compositor/gpu_vsync_begin_frame_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d0a8df9c39b0ff61ade7b44765a7a75c0febac92
--- /dev/null
+++ b/content/browser/compositor/gpu_vsync_begin_frame_source.cc
@@ -0,0 +1,114 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/compositor/gpu_vsync_begin_frame_source.h"
+
+namespace content {
+
+GpuVSyncBeginFrameSource::GpuVSyncBeginFrameSource(
+ GpuVSyncControl* vsync_control)
+ : vsync_control_(vsync_control),
+ enabled_(false),
+ next_sequence_number_(cc::BeginFrameArgs::kStartingFrameNumber) {
+ DCHECK(vsync_control);
+}
+
+GpuVSyncBeginFrameSource::~GpuVSyncBeginFrameSource() = default;
+
+void GpuVSyncBeginFrameSource::AddObserver(cc::BeginFrameObserver* obs) {
+ DCHECK(obs);
+ DCHECK(observers_.find(obs) == observers_.end());
+
+ obs->OnBeginFrameSourcePausedChanged(false);
+
+ bool observers_was_empty = observers_.empty();
+ observers_.insert(obs);
+ if (observers_was_empty)
+ EnableVSync(true);
+
+ // Send a MISSED begin frame if necessary.
+ if (previous_begin_frame_args_.IsValid()) {
+ cc::BeginFrameArgs last_args = obs->LastUsedBeginFrameArgs();
+ if (!last_args.IsValid() ||
+ (previous_begin_frame_args_.frame_time > last_args.frame_time)) {
+ DCHECK((previous_begin_frame_args_.source_id != last_args.source_id) ||
+ (previous_begin_frame_args_.sequence_number >
+ last_args.sequence_number));
+
+ previous_begin_frame_args_.type = cc::BeginFrameArgs::MISSED;
+ OnBeginFrame(obs, previous_begin_frame_args_);
+ }
+ }
+}
+
+void GpuVSyncBeginFrameSource::RemoveObserver(cc::BeginFrameObserver* obs) {
+ DCHECK(obs);
+ DCHECK(observers_.find(obs) != observers_.end());
+
+ observers_.erase(obs);
+ if (observers_.empty()) {
+ previous_begin_frame_args_ = cc::BeginFrameArgs();
+ EnableVSync(false);
+ }
+}
+
+void GpuVSyncBeginFrameSource::DidFinishFrame(cc::BeginFrameObserver* obs,
+ const cc::BeginFrameAck& ack) {}
+
+bool GpuVSyncBeginFrameSource::IsThrottled() const {
+ return true;
+}
+
+void GpuVSyncBeginFrameSource::OnUpdateVSyncParameters(
+ base::TimeTicks timebase,
+ base::TimeDelta interval) {
+ if (!enabled_)
+ return;
+
+ base::TimeTicks now = base::TimeTicks::Now();
+ base::TimeTicks deadline = now.SnappedToNextTick(timebase, interval);
+
+ TRACE_EVENT1("cc", "GpuVSyncBeginFrameSource::OnUpdateVSyncParameters",
+ "vsync_delay", (now - timebase).ToInternalValue());
+
+ next_sequence_number_++;
+ OnBeginFrame(cc::BeginFrameArgs::Create(
+ BEGINFRAME_FROM_HERE, source_id(), next_sequence_number_, timebase,
+ deadline, interval, cc::BeginFrameArgs::NORMAL));
+}
+
+void GpuVSyncBeginFrameSource::SetAuthoritativeVSyncInterval(
+ base::TimeDelta interval) {
+ NOTREACHED();
+}
+
+void GpuVSyncBeginFrameSource::OnBeginFrame(const cc::BeginFrameArgs& args) {
+ previous_begin_frame_args_ = args;
+ std::unordered_set<cc::BeginFrameObserver*> observers(observers_);
+ for (auto* obs : observers)
+ OnBeginFrame(obs, args);
+}
+
+/* static */
+void GpuVSyncBeginFrameSource::OnBeginFrame(cc::BeginFrameObserver* obs,
+ const cc::BeginFrameArgs& args) {
+ cc::BeginFrameArgs last_args = obs->LastUsedBeginFrameArgs();
+
+ if (last_args.IsValid()) {
+ base::TimeDelta delta = args.frame_time - last_args.frame_time;
+ if (delta < args.interval / 2.0) {
stanisc 2017/01/12 00:52:50 TODO: this needs logic similar to DelayBasedBeginF
+ TRACE_EVENT1("cc", "GpuVSyncBeginFrameSource::OnBeginFrame", "delta",
+ delta.ToInternalValue());
+ }
+ }
+
+ obs->OnBeginFrame(args);
+}
+
+void GpuVSyncBeginFrameSource::EnableVSync(bool enabled) {
+ enabled_ = enabled;
+ vsync_control_->EnableVSync(enabled);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698