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

Unified Diff: ui/compositor/compositor_vsync_manager.cc

Issue 138903025: Read compositor VSync information from platform, when possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 94f02c61 More piman@ comments. Created 6 years, 10 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: ui/compositor/compositor_vsync_manager.cc
diff --git a/ui/compositor/compositor_vsync_manager.cc b/ui/compositor/compositor_vsync_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..391f13bfa996ea2a9d7efaf8724a03bd11789e24
--- /dev/null
+++ b/ui/compositor/compositor_vsync_manager.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2014 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 "ui/compositor/compositor_vsync_manager.h"
+
+// These constants define a reasonable range for a calculated refresh interval.
+// Calculating refreshes out of this range will be considered a fatal error.
+const int64 kMinVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 400;
+const int64 kMaxVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 10;
+
+namespace ui {
+
+CompositorVSyncManager::CompositorVSyncManager()
+ : observer_list_(new ObserverListThreadSafe<Observer>()),
+ authoritative_vsync_interval_(base::TimeDelta::FromSeconds(0)) {}
+
+CompositorVSyncManager::~CompositorVSyncManager() {}
+
+void CompositorVSyncManager::SetAuthoritativeVSyncInterval(
+ base::TimeDelta interval) {
+ base::AutoLock lock(vsync_parameters_lock_);
+ authoritative_vsync_interval_ = interval;
+ NotifyObservers(last_timebase_, authoritative_vsync_interval_);
piman 2014/02/04 22:52:54 nit: release the lock before NotifyObservers, to m
+}
+
+void CompositorVSyncManager::UpdateVSyncParameters(base::TimeTicks timebase,
+ base::TimeDelta interval) {
+ {
+ base::AutoLock lock(vsync_parameters_lock_);
+ if (authoritative_vsync_interval_ != base::TimeDelta::FromSeconds(0))
+ interval = authoritative_vsync_interval_;
+ }
+ NotifyObservers(timebase, interval);
+}
+
+void CompositorVSyncManager::AddObserver(Observer* observer) {
+ observer_list_->AddObserver(observer);
+ observer->OnUpdateVSyncParameters(last_timebase_, last_interval_);
+}
+
+void CompositorVSyncManager::RemoveObserver(Observer* observer) {
+ observer_list_->RemoveObserver(observer);
+}
+
+void CompositorVSyncManager::NotifyObservers(base::TimeTicks timebase,
+ base::TimeDelta interval) {
+ // The vsync interval reported here controls the repaint rate of the
+ // compositor. If too low, kill the process instead of silently appearing to
+ // hang the UI.
+ if (interval.InMicroseconds() < kMinVsyncIntervalUs ||
+ interval.InMicroseconds() > kMaxVsyncIntervalUs) {
+ LOG(FATAL) << "Calculated bogus refresh interval of "
+ << interval.InMicroseconds() << " us.";
+ }
+
+ last_timebase_ = timebase;
+ last_interval_ = interval;
piman 2014/02/04 22:52:54 acquire lock while modifying these 2.
+ observer_list_->Notify(
+ &CompositorVSyncManager::Observer::OnUpdateVSyncParameters,
+ timebase,
+ interval);
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698