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

Unified Diff: ui/android/java/src/org/chromium/ui/VSyncMonitor.java

Issue 611313003: Use estimated vsync period on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only update refresh period during consecutive vsyncs Created 6 years, 2 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/android/java/src/org/chromium/ui/VSyncMonitor.java
diff --git a/ui/android/java/src/org/chromium/ui/VSyncMonitor.java b/ui/android/java/src/org/chromium/ui/VSyncMonitor.java
index af8f87b5ffd898c832a1fa2f0db7cd590e50ca89..9c421aa14546db038c7530c5c963b236d9ce68de 100644
--- a/ui/android/java/src/org/chromium/ui/VSyncMonitor.java
+++ b/ui/android/java/src/org/chromium/ui/VSyncMonitor.java
@@ -24,7 +24,10 @@ public class VSyncMonitor {
private static final long NANOSECONDS_PER_MILLISECOND = 1000000;
private static final long NANOSECONDS_PER_MICROSECOND = 1000;
+ private static final long MAX_VALID_VSYNC_PERIOD_NANOSECONDS = NANOSECONDS_PER_SECOND / 30;
+
private boolean mInsideVSync = false;
+ private boolean mConsecutiveVSync = false;
/**
* VSync listener class
@@ -41,7 +44,7 @@ public class VSyncMonitor {
private Listener mListener;
// Display refresh rate as reported by the system.
- private final long mRefreshPeriodNano;
+ private long mRefreshPeriodNano;
private boolean mHaveRequestInFlight;
@@ -85,10 +88,22 @@ public class VSyncMonitor {
if (enableJBVSync && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
// Use Choreographer on JB+ to get notified of vsync.
mChoreographer = Choreographer.getInstance();
+ final boolean useEstimatedRefreshPeriod =
+ mRefreshPeriodNano > MAX_VALID_VSYNC_PERIOD_NANOSECONDS;
Sami 2014/10/02 15:52:31 Indent by +4 spaces.
mVSyncFrameCallback = new Choreographer.FrameCallback() {
@Override
public void doFrame(long frameTimeNanos) {
TraceEvent.begin("VSync");
+ if (useEstimatedRefreshPeriod && mConsecutiveVSync) {
+ // Display.getRefreshRate() is unreliable on some platforms.
+ // Adjust refresh period- initial value is based on Display.getRefreshRate()
+ // after that it asymptotically approaches the real value.
+ long lastRefreshDurationNano = frameTimeNanos - mGoodStartingPointNano;
+ float lastRefreshDurationWeight = 0.75;
+ mRefreshPeriodNano = (long) (
Sami 2014/10/02 15:52:31 nit: This would be slightly more efficient as:
+ mRefreshPeriodNano * (1.0f - lastRefreshDurationWeight) +
+ lastRefreshDurationNano * lastRefreshDurationWeight);
+ }
mGoodStartingPointNano = frameTimeNanos;
onVSyncCallback(frameTimeNanos, getCurrentNanoTime());
TraceEvent.end("VSync");
@@ -186,6 +201,7 @@ public class VSyncMonitor {
mHaveRequestInFlight = true;
if (postSyntheticVSync()) return;
if (isVSyncSignalAvailable()) {
+ mConsecutiveVSync = mInsideVSync;
Sami 2014/10/02 15:52:31 This can have some false negatives if the next fra
mChoreographer.postFrameCallback(mVSyncFrameCallback);
} else {
postRunnableCallback();

Powered by Google App Engine
This is Rietveld 408576698