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

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

Issue 1109963003: Remove ICS support in VSyncMonitor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove lint suppression Created 5 years, 8 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
« no previous file with comments | « content/public/android/javatests/src/org/chromium/content/browser/VSyncMonitorTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8974b99c795cabb45440c9fb4a791067ec956d05..83d02d91da79382fb2f70035d1b041b27bbc6735 100644
--- a/ui/android/java/src/org/chromium/ui/VSyncMonitor.java
+++ b/ui/android/java/src/org/chromium/ui/VSyncMonitor.java
@@ -4,9 +4,7 @@
package org.chromium.ui;
-import android.annotation.SuppressLint;
import android.content.Context;
-import android.os.Build;
import android.os.Handler;
import android.view.Choreographer;
import android.view.WindowManager;
@@ -15,13 +13,9 @@ import org.chromium.base.TraceEvent;
/**
* Notifies clients of the default displays's vertical sync pulses.
- * On ICS, VSyncMonitor relies on setVSyncPointForICS() being called to set a reasonable
- * approximation of a vertical sync starting point; see also http://crbug.com/156397.
*/
-@SuppressLint("NewApi")
public class VSyncMonitor {
private static final long NANOSECONDS_PER_SECOND = 1000000000;
- private static final long NANOSECONDS_PER_MILLISECOND = 1000000;
private static final long NANOSECONDS_PER_MICROSECOND = 1000;
private boolean mInsideVSync = false;
@@ -49,14 +43,9 @@ public class VSyncMonitor {
private boolean mHaveRequestInFlight;
- // Choreographer is used to detect vsync on >= JB.
private final Choreographer mChoreographer;
private final Choreographer.FrameCallback mVSyncFrameCallback;
-
- // On ICS we just post a task through the handler (http://crbug.com/156397)
- private final Runnable mVSyncRunnableCallback;
private long mGoodStartingPointNano;
- private long mLastPostedNano;
// If the monitor is activated after having been idle, we synthesize the first vsync to reduce
// latency.
@@ -70,16 +59,6 @@ public class VSyncMonitor {
* @param listener The listener receiving VSync notifications.
*/
public VSyncMonitor(Context context, VSyncMonitor.Listener listener) {
- this(context, listener, true);
- }
-
- /**
- * Constructs a VSyncMonitor
- * @param context The application context.
- * @param listener The listener receiving VSync notifications.
- * @param enableJBVsync Whether to allow Choreographer-based notifications on JB and up.
- */
- public VSyncMonitor(Context context, VSyncMonitor.Listener listener, boolean enableJBVSync) {
mListener = listener;
float refreshRate = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay().getRefreshRate();
@@ -88,43 +67,25 @@ public class VSyncMonitor {
if (refreshRate <= 0) refreshRate = 60;
mRefreshPeriodNano = (long) (NANOSECONDS_PER_SECOND / refreshRate);
- if (enableJBVSync && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- // Use Choreographer on JB+ to get notified of vsync.
- mChoreographer = Choreographer.getInstance();
- 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.1f;
- mRefreshPeriodNano += (long) (lastRefreshDurationWeight
- * (lastRefreshDurationNano - mRefreshPeriodNano));
- }
- mGoodStartingPointNano = frameTimeNanos;
- onVSyncCallback(frameTimeNanos, getCurrentNanoTime());
- TraceEvent.end("VSync");
- }
- };
- mVSyncRunnableCallback = null;
- } else {
- // On ICS we just hope that running tasks is relatively predictable.
- mChoreographer = null;
- mVSyncFrameCallback = null;
- mVSyncRunnableCallback = new Runnable() {
- @Override
- public void run() {
- TraceEvent.begin("VSyncTimer");
- final long currentTime = getCurrentNanoTime();
- onVSyncCallback(currentTime, currentTime);
- TraceEvent.end("VSyncTimer");
+ mChoreographer = Choreographer.getInstance();
+ 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.1f;
+ mRefreshPeriodNano += (long) (lastRefreshDurationWeight
+ * (lastRefreshDurationNano - mRefreshPeriodNano));
}
- };
- mLastPostedNano = 0;
- }
+ mGoodStartingPointNano = frameTimeNanos;
+ onVSyncCallback(frameTimeNanos, getCurrentNanoTime());
+ TraceEvent.end("VSync");
+ }
+ };
mSyntheticVSyncRunnable = new Runnable() {
@Override
public void run() {
@@ -145,13 +106,6 @@ public class VSyncMonitor {
}
/**
- * Determine whether a true vsync signal is available on this platform.
- */
- private boolean isVSyncSignalAvailable() {
- return mChoreographer != null;
- }
-
- /**
* Request to be notified of the closest display vsync events.
* Listener.onVSync() will be called soon after the upcoming vsync pulses.
*/
@@ -160,14 +114,6 @@ public class VSyncMonitor {
}
/**
- * Set the best guess of the point in the past when the vsync has happened.
- * @param goodStartingPointNano Known vsync point in the past.
- */
- public void setVSyncPointForICS(long goodStartingPointNano) {
- mGoodStartingPointNano = goodStartingPointNano;
- }
-
- /**
* @return true if onVSync handler is executing. If onVSync handler
* introduces invalidations, View#invalidate() should be called. If
* View#postInvalidateOnAnimation is called instead, the corresponding onDraw
@@ -200,12 +146,8 @@ public class VSyncMonitor {
if (mHaveRequestInFlight) return;
mHaveRequestInFlight = true;
if (postSyntheticVSync()) return;
- if (isVSyncSignalAvailable()) {
- mConsecutiveVSync = mInsideVSync;
- mChoreographer.postFrameCallback(mVSyncFrameCallback);
- } else {
- postRunnableCallback();
- }
+ mConsecutiveVSync = mInsideVSync;
+ mChoreographer.postFrameCallback(mVSyncFrameCallback);
}
private boolean postSyntheticVSync() {
@@ -224,20 +166,4 @@ public class VSyncMonitor {
* mRefreshPeriodNano;
return lastRefreshTime;
}
-
- private void postRunnableCallback() {
- assert !isVSyncSignalAvailable();
- final long currentTime = getCurrentNanoTime();
- final long lastRefreshTime = estimateLastVSyncTime(currentTime);
- long delay = (lastRefreshTime + mRefreshPeriodNano) - currentTime;
- assert delay > 0 && delay <= mRefreshPeriodNano;
-
- if (currentTime + delay <= mLastPostedNano + mRefreshPeriodNano / 2) {
- delay += mRefreshPeriodNano;
- }
-
- mLastPostedNano = currentTime + delay;
- if (delay == 0) mHandler.post(mVSyncRunnableCallback);
- else mHandler.postDelayed(mVSyncRunnableCallback, delay / NANOSECONDS_PER_MILLISECOND);
- }
}
« no previous file with comments | « content/public/android/javatests/src/org/chromium/content/browser/VSyncMonitorTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698