Chromium Code Reviews| 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..962f3eda14df67ee182fb5101d601293efa8f312 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 MAX_VALID_VSYNC_PERIOD_NANOSECONDS = NANOSECONDS_PER_SECOND / 30; |
| + |
| 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 > MAX_VALID_VSYNC_PERIOD_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; |
|
no sievers
2014/10/01 17:48:09
+1 to what Sami said. Only doing the adjustments w
|
| + if (lastRefreshDurationNano <= MAX_VALID_VSYNC_PERIOD_NANOSECONDS) { |
| + mRefreshPeriodNano = (mRefreshPeriodNano + lastRefreshDurationNano) / 2; |
|
no sievers
2014/10/01 17:48:09
Do you maybe want to use a bigger weight than 0.5
jmanko
2014/10/02 12:02:29
Sure, I can change that. Would 0.75 be enough?
no sievers
2014/10/02 19:51:42
If you make sure that we don't have outliers (see
jmanko
2014/10/03 09:10:54
That's already been done, the period is only updat
|
| + } |
| + } |
| mGoodStartingPointNano = frameTimeNanos; |
| onVSyncCallback(frameTimeNanos, getCurrentNanoTime()); |
| TraceEvent.end("VSync"); |