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

Commit f6210091 authored by Hongwei Wang's avatar Hongwei Wang Committed by Android (Google) Code Review
Browse files

Merge "[PiP2] Cleanup Bitmap and buffer after setting up" into main

parents 2f019322 2147a534
Loading
Loading
Loading
Loading
+9 −16
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.hardware.HardwareBuffer;
import android.util.TypedValue;
import android.view.SurfaceControl;

@@ -39,7 +40,6 @@ public final class PipAppIconOverlay extends PipContentOverlay {

    private final Context mContext;
    private final int mAppIconSizePx;
    private final Rect mAppBounds;
    private final int mOverlayHalfSize;
    private final Matrix mTmpTransform = new Matrix();
    private final float[] mTmpFloat9 = new float[9];
@@ -56,10 +56,6 @@ public final class PipAppIconOverlay extends PipContentOverlay {
        final int overlaySize = getOverlaySize(appBounds, destinationBounds);
        mOverlayHalfSize = overlaySize >> 1;

        // When the activity is in the secondary split, make sure the scaling center is not
        // offset.
        mAppBounds = new Rect(0, 0, appBounds.width(), appBounds.height());

        mBitmap = Bitmap.createBitmap(overlaySize, overlaySize, Bitmap.Config.ARGB_8888);
        prepareAppIconOverlay(appIcon);
        mLeash = new SurfaceControl.Builder()
@@ -85,12 +81,17 @@ public final class PipAppIconOverlay extends PipContentOverlay {

    @Override
    public void attach(SurfaceControl.Transaction tx, SurfaceControl parentLeash) {
        final HardwareBuffer buffer = mBitmap.getHardwareBuffer();
        tx.show(mLeash);
        tx.setLayer(mLeash, Integer.MAX_VALUE);
        tx.setBuffer(mLeash, mBitmap.getHardwareBuffer());
        tx.setBuffer(mLeash, buffer);
        tx.setAlpha(mLeash, 0f);
        tx.reparent(mLeash, parentLeash);
        tx.apply();
        // Cleanup the bitmap and buffer after setting up the leash
        mBitmap.recycle();
        mBitmap = null;
        buffer.close();
    }

    @Override
@@ -108,16 +109,6 @@ public final class PipAppIconOverlay extends PipContentOverlay {
                .setAlpha(mLeash, fraction < 0.5f ? 0 : (fraction - 0.5f) * 2);
    }



    @Override
    public void detach(SurfaceControl.Transaction tx) {
        super.detach(tx);
        if (mBitmap != null && !mBitmap.isRecycled()) {
            mBitmap.recycle();
        }
    }

    private void prepareAppIconOverlay(Drawable appIcon) {
        final Canvas canvas = new Canvas();
        canvas.setBitmap(mBitmap);
@@ -139,6 +130,8 @@ public final class PipAppIconOverlay extends PipContentOverlay {
                mOverlayHalfSize + mAppIconSizePx / 2);
        appIcon.setBounds(appIconBounds);
        appIcon.draw(canvas);
        Bitmap oldBitmap = mBitmap;
        mBitmap = mBitmap.copy(Bitmap.Config.HARDWARE, false /* mutable */);
        oldBitmap.recycle();
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -72,7 +72,6 @@ import com.android.wm.shell.pip2.animation.PipAlphaAnimator;
import com.android.wm.shell.pip2.animation.PipEnterAnimator;
import com.android.wm.shell.pip2.animation.PipExpandAnimator;
import com.android.wm.shell.shared.TransitionUtil;
import com.android.wm.shell.shared.pip.PipContentOverlay;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;

@@ -422,7 +421,7 @@ public class PipTransition extends PipTransitionController implements
        final Rect destinationBounds = pipChange.getEndAbsBounds();
        final SurfaceControl swipePipToHomeOverlay = mPipTransitionState.getSwipePipToHomeOverlay();
        if (swipePipToHomeOverlay != null) {
            final int overlaySize = PipContentOverlay.PipAppIconOverlay.getOverlaySize(
            final int overlaySize = PipAppIconOverlay.getOverlaySize(
                    mPipTransitionState.getSwipePipToHomeAppBounds(), destinationBounds);
            // It is possible we reparent the PIP activity to a new PIP task (in multi-activity
            // apps), so we should also reparent the overlay to the final PIP task.