Bug 1501748 - Avoid synchronous wait when creating VsyncSource. r=droeh, a=RyanVM FENNEC_65_0b9_BUILD2 FENNEC_65_0b9_RELEASE
authorJames Willcox <snorp@snorp.net>
Fri, 04 Jan 2019 23:24:44 +0000
changeset 509338 f7c20de04f4d0a6966e43a77dab3a44fea733622
parent 509337 7a3852d4612f8b9fa8cadce3ee58b337fd831d97
child 509339 473b0256e63804400d67eac5cc3a005609f4c345
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdroeh, RyanVM
bugs1501748
milestone65.0
Bug 1501748 - Avoid synchronous wait when creating VsyncSource. r=droeh, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D15747
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/VsyncSource.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/VsyncSource.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/VsyncSource.java
@@ -22,41 +22,26 @@ import org.mozilla.gecko.GeckoAppShell;
 
     @WrapForJNI
     private static final VsyncSource INSTANCE = new VsyncSource();
 
     /* package */ Choreographer mChoreographer;
     private volatile boolean mObservingVsync;
 
     private VsyncSource() {
-        // Use a dedicated lock object because |mainHandler| might synchronize
-        // on itself internally and we don't want to risk getting stuck for such
-        // a silly reason.
-        final Object lock = new Object();
-
         Handler mainHandler = new Handler(Looper.getMainLooper());
         mainHandler.post(new Runnable() {
             @Override
             public void run() {
-                synchronized (lock) {
-                    mChoreographer = Choreographer.getInstance();
-                    lock.notifyAll();
+                mChoreographer = Choreographer.getInstance();
+                if (mObservingVsync) {
+                    mChoreographer.postFrameCallback(VsyncSource.this);
                 }
             }
         });
-
-        synchronized (lock) {
-            while (mChoreographer == null) {
-                try {
-                    lock.wait();
-                } catch (final InterruptedException e) {
-                    // Ignore
-                }
-            }
-        }
     }
 
     @WrapForJNI(stubName = "NotifyVsync")
     private static native void nativeNotifyVsync();
 
     // Choreographer callback implementation.
     public void doFrame(long frameTimeNanos) {
         if (mObservingVsync) {
@@ -69,20 +54,23 @@ import org.mozilla.gecko.GeckoAppShell;
      * Start/stop observing Vsync event.
      * @param enable true to start observing; false to stop.
      * @return true if observing and false if not.
      */
     @WrapForJNI
     public synchronized boolean observeVsync(boolean enable) {
         if (mObservingVsync != enable) {
             mObservingVsync = enable;
-            if (enable) {
-                mChoreographer.postFrameCallback(this);
-            } else {
-                mChoreographer.removeFrameCallback(this);
+
+            if (mChoreographer != null) {
+                if (enable) {
+                    mChoreographer.postFrameCallback(this);
+                } else {
+                    mChoreographer.removeFrameCallback(this);
+                }
             }
         }
         return mObservingVsync;
     }
 
     /** Gets the refresh rate of default display in frames per second. */
     @WrapForJNI
     public float getRefreshRate() {