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

Commit 1da9cd9b authored by chaviw's avatar chaviw
Browse files

Convert screenshot hw Bitmap to sw Bitmap for screenshot preview.

Bitmaps created from SurfaceControl.screenshot are hardware Bitmaps. In
order to update the size for the screenshot preview, the Bitmaps need to
be converted to software Bitmaps first.

Also updated the SurfaceControl docs to make this clear.

Fixes: 69929720
Test: Notifications from lock screen and status bar show the screenshot
preview.

Change-Id: Iebc4a261216f3d965e1c98a77c27cc0cb2e442af
parent bb91f5fe
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -1126,7 +1126,9 @@ public class SurfaceControl implements Parcelable {
    }

    /**
     * Copy the current screen contents into a bitmap and return it.
     * Copy the current screen contents into a hardware bitmap and return it.
     * Note: If you want to modify the Bitmap in software, you will need to copy the Bitmap into
     * a software Bitmap using {@link Bitmap#copy(Bitmap.Config, boolean)}
     *
     * CAVEAT: Versions of screenshot that return a {@link Bitmap} can
     * be extremely slow; avoid use unless absolutely necessary; prefer
@@ -1151,7 +1153,7 @@ public class SurfaceControl implements Parcelable {
     * screenshots in its native portrait orientation by default, so this is
     * useful for returning screenshots that are independent of device
     * orientation.
     * @return Returns a Bitmap containing the screen contents, or null
     * @return Returns a hardware Bitmap containing the screen contents, or null
     * if an error occurs. Make sure to call Bitmap.recycle() as soon as
     * possible, once its content is not needed anymore.
     */
@@ -1179,7 +1181,7 @@ public class SurfaceControl implements Parcelable {
    }

    /**
     * Like {@link SurfaceControl#screenshot(int, int, int, int, boolean)} but
     * Like {@link SurfaceControl#screenshot(Rect, int, int, int, int, boolean, int)} but
     * includes all Surfaces in the screenshot. This will also update the orientation so it
     * sends the correct coordinates to SF based on the rotation value.
     *
@@ -1236,7 +1238,7 @@ public class SurfaceControl implements Parcelable {
    }

    /**
     * Captures a layer and its children into the provided {@link Surface}.
     * Captures a layer and its children and returns a {@link GraphicBuffer} with the content.
     *
     * @param layerHandleToken The root layer to capture.
     * @param sourceCrop       The portion of the root surface to capture; caller may pass in 'new
+6 −2
Original line number Diff line number Diff line
@@ -161,10 +161,14 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        Matrix matrix = new Matrix();
        int overlayColor = 0x40FFFFFF;

        // Bitmaps created for screenshots are hardware bitmaps. Copy to a software bitmap in order
        // to update size for previews.
        Bitmap swBitmap = data.image.copy(Bitmap.Config.ARGB_8888, true);

        Bitmap picture = Bitmap.createBitmap(previewWidth, previewHeight, Bitmap.Config.ARGB_8888);
        matrix.setTranslate((previewWidth - mImageWidth) / 2, (previewHeight - mImageHeight) / 2);
        c.setBitmap(picture);
        c.drawBitmap(data.image, matrix, paint);
        c.drawBitmap(swBitmap, matrix, paint);
        c.drawColor(overlayColor);
        c.setBitmap(null);

@@ -175,7 +179,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        matrix.postTranslate((iconSize - (scale * mImageWidth)) / 2,
                (iconSize - (scale * mImageHeight)) / 2);
        c.setBitmap(icon);
        c.drawBitmap(data.image, matrix, paint);
        c.drawBitmap(swBitmap, matrix, paint);
        c.drawColor(overlayColor);
        c.setBitmap(null);