Bug 1501748 - Avoid synchronous wait when creating VsyncSource r=geckoview-reviewers,droeh#geckoview-reviewers
authorJames Willcox <snorp@snorp.net>
Fri, 04 Jan 2019 23:24:44 +0000
changeset 509814 d3b95f808e2878849127b8f4fc43527202eecf2a
parent 509813 a3967ba7881354f52a71d1074d4c2f010113a567
child 509815 6a7b315a82b2ebc9402166d886fa8c93d805df10
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, droeh
bugs1501748
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1501748 - Avoid synchronous wait when creating VsyncSource r=geckoview-reviewers,droeh#geckoview-reviewers 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
@@ -24,41 +24,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) {
@@ -71,20 +56,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.
      *