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

Commit 950c769c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Convert screenshot hw Bitmap to sw Bitmap for screenshot preview."

parents 94ad07d0 1da9cd9b
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -1149,7 +1149,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
@@ -1174,7 +1176,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.
     */
@@ -1202,7 +1204,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.
     *
@@ -1259,7 +1261,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);