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

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: Remove unused constant 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..e717851aa23d86d7fb474f67076f4549c3dd01a2 100644
--- a/ui/android/java/src/org/chromium/ui/VSyncMonitor.java
+++ b/ui/android/java/src/org/chromium/ui/VSyncMonitor.java
@@ -26,6 +26,10 @@ public class VSyncMonitor {
private boolean mInsideVSync = false;
+ // Conservative guess about vsync's consecutivity.
+ // If true, next tick is guaranteed to be consecutive.
+ private boolean mConsecutiveVSync = false;
+
/**
* VSync listener class
*/
@@ -41,7 +45,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;
@@ -79,6 +83,8 @@ public class VSyncMonitor {
mListener = listener;
float refreshRate = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay().getRefreshRate();
+ final boolean useEstimatedRefreshPeriod = refreshRate < 30;
+
if (refreshRate <= 0) refreshRate = 60;
mRefreshPeriodNano = (long) (NANOSECONDS_PER_SECOND / refreshRate);
@@ -89,6 +95,15 @@ public class VSyncMonitor {
@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.1f;
+ mRefreshPeriodNano += (long) (lastRefreshDurationWeight *
+ (lastRefreshDurationNano - mRefreshPeriodNano));
+ }
mGoodStartingPointNano = frameTimeNanos;
onVSyncCallback(frameTimeNanos, getCurrentNanoTime());
TraceEvent.end("VSync");
@@ -186,6 +201,7 @@ public class VSyncMonitor {
mHaveRequestInFlight = true;
if (postSyntheticVSync()) return;
if (isVSyncSignalAvailable()) {
+ mConsecutiveVSync = mInsideVSync;
mChoreographer.postFrameCallback(mVSyncFrameCallback);
} else {
postRunnableCallback();

Powered by Google App Engine
This is Rietveld 408576698