Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b037f72 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

Consolidate ViewRootImpl callbacks for SurfaceView

Use ViewRootImpl surface created and destroyed callbacks to set window stopped state
and update the SurfaceView visibility accordingly.

Bug: 132205507
Test: go/wm-smoke
Change-Id: Ie43e3cc81729a153e36fffbefe242d78d8e38222
parent 49230c42
Loading
Loading
Loading
Loading
+33 −6
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ import java.util.concurrent.locks.ReentrantLock;
 * artifacts may occur on previous versions of the platform when its window is
 * positioned asynchronously.</p>
 */
public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallback {
public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCallback {
    private static final String TAG = "SurfaceView";
    private static final boolean DEBUG = false;
    private static final boolean DEBUG_POSITION = false;
@@ -227,9 +227,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
        mRequestedVisible = mViewVisibility && mWindowVisibility && !mWindowStopped;
    }

    /** @hide */
    @Override
    public void windowStopped(boolean stopped) {
    private void setWindowStopped(boolean stopped) {
        mWindowStopped = stopped;
        updateRequestedVisibility();
        updateSurface();
@@ -239,7 +237,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();

        getViewRootImpl().addWindowStoppedCallback(this);
        getViewRootImpl().addSurfaceChangedCallback(this);
        mWindowStopped = false;

        mViewVisibility = getVisibility() == VISIBLE;
@@ -459,7 +457,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
        // the lifecycle. Instead of attaching it to a view, he/she can just pass
        // the SurfaceHolder forward, most live wallpapers do it.
        if (viewRoot != null) {
            viewRoot.removeWindowStoppedCallback(this);
            viewRoot.removeSurfaceChangedCallback(this);
        }

        mAttachedToWindow = false;
@@ -1349,4 +1347,33 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
    public SurfaceControl getSurfaceControl() {
        return mSurfaceControl;
    }

    /**
     * Set window stopped to false and update surface visibility when ViewRootImpl surface is
     * created.
     * @hide
     */
    @Override
    public void surfaceCreated(SurfaceControl.Transaction t) {
        setWindowStopped(false);
    }

    /**
     * Set window stopped to true and update surface visibility when ViewRootImpl surface is
     * destroyed.
     * @hide
     */
    @Override
    public void surfaceDestroyed() {
        setWindowStopped(true);
    }

    /**
     * Called when a valid ViewRootImpl surface is replaced by another valid surface.
     * @hide
     */
    @Override
    public void surfaceReplaced(SurfaceControl.Transaction t) {

    }
}
+0 −19
Original line number Diff line number Diff line
@@ -1547,19 +1547,6 @@ public final class ViewRootImpl implements ViewParent,
        mIsAmbientMode = ambient;
    }

    interface WindowStoppedCallback {
        public void windowStopped(boolean stopped);
    }
    private final ArrayList<WindowStoppedCallback> mWindowStoppedCallbacks =  new ArrayList<>();

    void addWindowStoppedCallback(WindowStoppedCallback c) {
        mWindowStoppedCallbacks.add(c);
    }

    void removeWindowStoppedCallback(WindowStoppedCallback c) {
        mWindowStoppedCallbacks.remove(c);
    }

    void setWindowStopped(boolean stopped) {
        checkThread();
        if (mStopped != stopped) {
@@ -1576,13 +1563,7 @@ public final class ViewRootImpl implements ViewParent,
                if (renderer != null) {
                    renderer.destroyHardwareResources(mView);
                }
            }

            for (int i = 0; i < mWindowStoppedCallbacks.size(); i++) {
                mWindowStoppedCallbacks.get(i).windowStopped(stopped);
            }

            if (mStopped) {
                if (mSurface.isValid()) {
                    if (mSurfaceHolder != null) {
                        notifyHolderSurfaceDestroyed();
+1 −1
Original line number Diff line number Diff line
@@ -1299,7 +1299,7 @@ class WindowStateAnimator {
                    mSurfaceController.mSurfaceControl);
        }

        mPostDrawTransaction.apply();
        SurfaceControl.mergeToGlobalTransaction(mPostDrawTransaction);
        return true;
    }