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

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: Change lastRefreshDurationWeight. Use estimation also when getRefreshRate() is <= 0. 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..70fbd7b44969b0b78f4bceacd2ba8552c5f7d553 100644
--- a/ui/android/java/src/org/chromium/ui/VSyncMonitor.java
+++ b/ui/android/java/src/org/chromium/ui/VSyncMonitor.java
@@ -24,8 +24,14 @@ 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;
jdduke (slow) 2014/10/08 03:17:02 I don't think this is used any longer?
+
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 +47,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 +85,8 @@ public class VSyncMonitor {
mListener = listener;
float refreshRate = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay().getRefreshRate();
+ final boolean useEstimatedRefreshPeriod = refreshRate < 30;
jdduke (slow) 2014/10/08 03:17:02 I see 30 both here and above in the MAX_VALID_VSYN
+
if (refreshRate <= 0) refreshRate = 60;
mRefreshPeriodNano = (long) (NANOSECONDS_PER_SECOND / refreshRate);
@@ -89,6 +97,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 *
jdduke (slow) 2014/10/08 03:17:02 Hmm, I could be wrong, but don't you need to rewei
Sami 2014/10/08 10:14:51 Hmm, I think that reduces to mRefreshPeriodNano =
jdduke (slow) 2014/10/08 13:06:00 Of course, sigh, I should actually read the variab
+ (lastRefreshDurationNano - mRefreshPeriodNano));
+ }
mGoodStartingPointNano = frameTimeNanos;
onVSyncCallback(frameTimeNanos, getCurrentNanoTime());
TraceEvent.end("VSync");
@@ -186,6 +203,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