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

Commit cd4aeef8 authored by Robert Carr's avatar Robert Carr
Browse files

Modify SurfaceView to use SurfaceFlinger child surfaces.

Here we have SurfaceView bypass the WindowManager and speak
directly to SurfaceFlinger using child surfaces. We also
implement some logic in the WM to handle child surfaces
in various Surface replacement scenarios.

For those following along in the revert Saga, this
also includes the follow up CLs to the original CL.
- Surface inset calculation
- Animation fixes.

The error causing revert was a deferTransactionUntil(-1)...-1
cast to uint, defer transaction until MAX_UINT.

Bug: 28858420
Bug: 31518219
Bug: 34888808
Bug: 35588318
Bug: 35396882
Test: Existing tests still pass (except for the ones that don't and will be deleted).
Change-Id: Ib37236950a1dd3c4f9f4b58fd41ef9003c0557ef
parent 1ec752f2
Loading
Loading
Loading
Loading
+22 −1
Original line number Original line Diff line number Diff line
@@ -95,6 +95,11 @@ public class SurfaceControl {
            IBinder displayToken, int mode);
            IBinder displayToken, int mode);
    private static native void nativeDeferTransactionUntil(long nativeObject,
    private static native void nativeDeferTransactionUntil(long nativeObject,
            IBinder handle, long frame);
            IBinder handle, long frame);
    private static native void nativeDeferTransactionUntilSurface(long nativeObject,
            long surfaceObject, long frame);
    private static native void nativeReparentChildren(long nativeObject,
            IBinder handle);
    private static native void nativeSeverChildren(long nativeObject);
    private static native void nativeSetOverrideScalingMode(long nativeObject,
    private static native void nativeSetOverrideScalingMode(long nativeObject,
            int scalingMode);
            int scalingMode);
    private static native IBinder nativeGetHandle(long nativeObject);
    private static native IBinder nativeGetHandle(long nativeObject);
@@ -418,8 +423,24 @@ public class SurfaceControl {
    }
    }


    public void deferTransactionUntil(IBinder handle, long frame) {
    public void deferTransactionUntil(IBinder handle, long frame) {
        if (frame > 0) {
            nativeDeferTransactionUntil(mNativeObject, handle, frame);
            nativeDeferTransactionUntil(mNativeObject, handle, frame);
        }
        }
    }

    public void deferTransactionUntil(Surface barrier, long frame) {
        if (frame > 0) {
            nativeDeferTransactionUntilSurface(mNativeObject, barrier.mNativeObject, frame);
        }
    }

    public void reparentChildren(IBinder newParentHandle) {
        nativeReparentChildren(mNativeObject, newParentHandle);
    }

    public void detachChildren() {
        nativeSeverChildren(mNativeObject);
    }


    public void setOverrideScalingMode(int scalingMode) {
    public void setOverrideScalingMode(int scalingMode) {
        checkNotReleased();
        checkNotReleased();
+5 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ public final class SurfaceSession {
    private long mNativeClient; // SurfaceComposerClient*
    private long mNativeClient; // SurfaceComposerClient*


    private static native long nativeCreate();
    private static native long nativeCreate();
    private static native long nativeCreateScoped(long surfacePtr);
    private static native void nativeDestroy(long ptr);
    private static native void nativeDestroy(long ptr);
    private static native void nativeKill(long ptr);
    private static native void nativeKill(long ptr);


@@ -35,6 +36,10 @@ public final class SurfaceSession {
        mNativeClient = nativeCreate();
        mNativeClient = nativeCreate();
    }
    }


    public SurfaceSession(Surface root) {
        mNativeClient = nativeCreateScoped(root.mNativeObject);
    }

    /* no user serviceable parts here ... */
    /* no user serviceable parts here ... */
    @Override
    @Override
    protected void finalize() throws Throwable {
    protected void finalize() throws Throwable {
+184 −267

File changed.

Preview size limit exceeded, changes collapsed.

+9 −1
Original line number Original line Diff line number Diff line
@@ -2632,6 +2632,14 @@ public final class ViewRootImpl implements ViewParent,
        }
        }
    }
    }


    private void onDrawFinished() {
        try {
            mWindowSession.finishDrawing(mWindow);
        } catch (RemoteException e) {
            // Have fun!
        }
    }

    private void performDraw() {
    private void performDraw() {
        if (mAttachInfo.mDisplayState == Display.STATE_OFF && !mReportNextDraw) {
        if (mAttachInfo.mDisplayState == Display.STATE_OFF && !mReportNextDraw) {
            return;
            return;
@@ -2682,7 +2690,7 @@ public final class ViewRootImpl implements ViewParent,
            }
            }


            if (mSurfaceHolder != null && mSurface.isValid()) {
            if (mSurfaceHolder != null && mSurface.isValid()) {
                SurfaceCallbackHelper sch = new SurfaceCallbackHelper(mWindowSession, mWindow);
                SurfaceCallbackHelper sch = new SurfaceCallbackHelper(this::onDrawFinished);
                SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
                SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();


                sch.dispatchSurfaceRedrawNeededAsync(mSurfaceHolder, callbacks);
                sch.dispatchSurfaceRedrawNeededAsync(mSurfaceHolder, callbacks);
+5 −16
Original line number Original line Diff line number Diff line
@@ -17,14 +17,11 @@
package com.android.internal.view;
package com.android.internal.view;


import android.os.RemoteException;
import android.os.RemoteException;
import android.view.IWindow;
import android.view.IWindowSession;
import android.view.Surface;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder;


public class SurfaceCallbackHelper {
public class SurfaceCallbackHelper {
    IWindowSession mSession;
    Runnable mRunnable;
    IWindow.Stub mWindow;


    int mFinishDrawingCollected = 0;
    int mFinishDrawingCollected = 0;
    int mFinishDrawingExpected = 0;
    int mFinishDrawingExpected = 0;
@@ -37,26 +34,18 @@ public class SurfaceCallbackHelper {
                    if (mFinishDrawingCollected < mFinishDrawingExpected) {
                    if (mFinishDrawingCollected < mFinishDrawingExpected) {
                        return;
                        return;
                    }
                    }
                    try {
                    mRunnable.run();
                        mSession.finishDrawing(mWindow);
                    } catch (RemoteException e) {
                    }
                }
                }
            }
            }
    };
    };


    public SurfaceCallbackHelper(IWindowSession session,
    public SurfaceCallbackHelper(Runnable callbacksCollected) {
            IWindow.Stub window) {
        mRunnable = callbacksCollected;
        mSession = session;
        mWindow = window;
    }
    }


    public void dispatchSurfaceRedrawNeededAsync(SurfaceHolder holder, SurfaceHolder.Callback callbacks[]) {
    public void dispatchSurfaceRedrawNeededAsync(SurfaceHolder holder, SurfaceHolder.Callback callbacks[]) {
        if (callbacks == null || callbacks.length == 0) {
        if (callbacks == null || callbacks.length == 0) {
            try {
            mRunnable.run();
                mSession.finishDrawing(mWindow);
            } catch (RemoteException e) {
            }
            return;
            return;
        }
        }


Loading