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

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

Merge "Cleanup Bitmap and buffer after setting up leash" into main

parents 9ead725a 26297cac
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -28,6 +28,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;
import android.window.TaskSnapshot;
@@ -225,12 +226,17 @@ public abstract class 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
@@ -253,14 +259,6 @@ public abstract class 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);
@@ -282,7 +280,9 @@ public abstract class PipContentOverlay {
                    mOverlayHalfSize + mAppIconSizePx / 2);
            appIcon.setBounds(appIconBounds);
            appIcon.draw(canvas);
            Bitmap oldBitmap = mBitmap;
            mBitmap = mBitmap.copy(Bitmap.Config.HARDWARE, false /* mutable */);
            oldBitmap.recycle();
        }
    }
}