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

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: 4b969456 piman@ comments; refactor logic into CompositorVSyncManager Created 6 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: 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..33436ef42a13c768082d22d343cdfe0d9be23c57
--- /dev/null
+++ b/ui/compositor/compositor_vsync_manager.cc
@@ -0,0 +1,57 @@
+// 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;
piman 2014/02/04 04:51:01 nit: I think we should update the observers at thi
sheu 2014/02/04 22:01:45 Sure, we'll do that.
+}
+
+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_;
+ }
+
+ // 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.
sheu 2014/02/04 03:23:21 This is probably not the best place to kill the pr
piman 2014/02/04 04:51:01 If anything, the assert should go to SetAuthoritat
sheu 2014/02/04 22:01:45 I've moved the check so that it's run in both this
piman 2014/02/04 22:52:54 I don't think we want to kill the browser process
+ if (interval.InMicroseconds() < kMinVsyncIntervalUs ||
+ interval.InMicroseconds() > kMaxVsyncIntervalUs) {
+ LOG(FATAL) << "Calculated bogus refresh interval of "
+ << interval.InMicroseconds() << " us.";
+ }
+
+ observer_list_->Notify(
+ &CompositorVSyncManager::Observer::OnUpdateVSyncParameters,
+ timebase,
+ interval);
+}
+
+void CompositorVSyncManager::AddObserver(Observer* observer) {
+ observer_list_->AddObserver(observer);
piman 2014/02/04 04:51:01 It would be reasonable to Notify the observer here
sheu 2014/02/04 22:01:45 Done.
+}
+
+void CompositorVSyncManager::RemoveObserver(Observer* observer) {
+ observer_list_->RemoveObserver(observer);
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698