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

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: Review follow-up Created 6 years, 3 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..6f3beafdbe22b5b429de879c02afa408cd28676c 100644
--- a/ui/android/java/src/org/chromium/ui/VSyncMonitor.java
+++ b/ui/android/java/src/org/chromium/ui/VSyncMonitor.java
@@ -24,6 +24,8 @@ public class VSyncMonitor {
private static final long NANOSECONDS_PER_MILLISECOND = 1000000;
private static final long NANOSECONDS_PER_MICROSECOND = 1000;
+ private static final long PERIOD_THRESHOLD_NANOSECONDS = NANOSECONDS_PER_SECOND / 30;
Sami 2014/10/01 11:42:49 nit: Maybe call this something like MAX_VALID_VSYN
+
private boolean mInsideVSync = false;
/**
@@ -41,7 +43,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 +87,21 @@ 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 > PERIOD_THRESHOLD_NANOSECONDS;
mVSyncFrameCallback = new Choreographer.FrameCallback() {
@Override
public void doFrame(long frameTimeNanos) {
TraceEvent.begin("VSync");
+ if (useEstimatedRefreshPeriod) {
+ // 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;
+ if (lastRefreshDurationNano <= PERIOD_THRESHOLD_NANOSECONDS) {
+ mRefreshPeriodNano = (mRefreshPeriodNano + lastRefreshDurationNano) / 2;
+ }
+ }
mGoodStartingPointNano = frameTimeNanos;
onVSyncCallback(frameTimeNanos, getCurrentNanoTime());
TraceEvent.end("VSync");
@@ -132,7 +145,7 @@ public class VSyncMonitor {
/**
* Determine whether a true vsync signal is available on this platform.
*/
- private boolean isVSyncSignalAvailable() {
+ public boolean isVSyncSignalAvailable() {
Sami 2014/10/01 11:42:49 Not needed?
return mChoreographer != null;
}

Powered by Google App Engine
This is Rietveld 408576698