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

Commit 82f8f3e0 authored by Sergei Vasilinetc's avatar Sergei Vasilinetc Committed by Android (Google) Code Review
Browse files

Merge "Prohibit Config.HARDWARE in factory methods, that create mutable bitmaps"

parents d194a782 9fbb0b5a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11791,6 +11791,7 @@ package android.graphics {
    enum_constant public static final android.graphics.Bitmap.Config ALPHA_8;
    enum_constant public static final deprecated android.graphics.Bitmap.Config ARGB_4444;
    enum_constant public static final android.graphics.Bitmap.Config ARGB_8888;
    enum_constant public static final android.graphics.Bitmap.Config HARDWARE;
    enum_constant public static final android.graphics.Bitmap.Config RGB_565;
  }
+1 −0
Original line number Diff line number Diff line
@@ -12281,6 +12281,7 @@ package android.graphics {
    enum_constant public static final android.graphics.Bitmap.Config ALPHA_8;
    enum_constant public static final deprecated android.graphics.Bitmap.Config ARGB_4444;
    enum_constant public static final android.graphics.Bitmap.Config ARGB_8888;
    enum_constant public static final android.graphics.Bitmap.Config HARDWARE;
    enum_constant public static final android.graphics.Bitmap.Config RGB_565;
  }
+1 −0
Original line number Diff line number Diff line
@@ -11822,6 +11822,7 @@ package android.graphics {
    enum_constant public static final android.graphics.Bitmap.Config ALPHA_8;
    enum_constant public static final deprecated android.graphics.Bitmap.Config ARGB_4444;
    enum_constant public static final android.graphics.Bitmap.Config ARGB_8888;
    enum_constant public static final android.graphics.Bitmap.Config HARDWARE;
    enum_constant public static final android.graphics.Bitmap.Config RGB_565;
  }
+5 −0
Original line number Diff line number Diff line
@@ -276,6 +276,11 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
        }
    }

    if (isMutable && isHardware) {
        doThrowIAE(env, "Bitmaps with Config.HARWARE are always immutable");
        return nullObjectReturn("Cannot create mutable hardware bitmap");
    }

    // Create the codec.
    NinePatchPeeker peeker;
    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(streamDeleter.release(),
+16 −5
Original line number Diff line number Diff line
@@ -467,7 +467,11 @@ public final class Bitmap implements Parcelable {


        /**
          * @hide
         * Special configuration, when bitmap is stored only in graphic memory.
         * Bitmaps in this configuration are always immutable.
         *
         * It is optimal for cases, when the only operation with the bitmap is to draw it on a
         * screen.
         */
        HARDWARE    (6);

@@ -810,7 +814,8 @@ public final class Bitmap implements Parcelable {
     * @param width    The width of the bitmap
     * @param height   The height of the bitmap
     * @param config   The bitmap config to create.
     * @throws IllegalArgumentException if the width or height are <= 0
     * @throws IllegalArgumentException if the width or height are <= 0, or if
     *         Config is Config.HARDWARE, because hardware bitmaps are always immutable
     */
    public static Bitmap createBitmap(int width, int height, Config config) {
        return createBitmap(width, height, config, true);
@@ -825,7 +830,8 @@ public final class Bitmap implements Parcelable {
     * @param width    The width of the bitmap
     * @param height   The height of the bitmap
     * @param config   The bitmap config to create.
     * @throws IllegalArgumentException if the width or height are <= 0
     * @throws IllegalArgumentException if the width or height are <= 0, or if
     *         Config is Config.HARDWARE, because hardware bitmaps are always immutable
     */
    public static Bitmap createBitmap(DisplayMetrics display, int width,
            int height, Config config) {
@@ -843,7 +849,8 @@ public final class Bitmap implements Parcelable {
     *                 bitmap as opaque. Doing so will clear the bitmap in black
     *                 instead of transparent.
     *
     * @throws IllegalArgumentException if the width or height are <= 0
     * @throws IllegalArgumentException if the width or height are <= 0, or if
     *         Config is Config.HARDWARE, because hardware bitmaps are always immutable
     */
    private static Bitmap createBitmap(int width, int height, Config config, boolean hasAlpha) {
        return createBitmap(null, width, height, config, hasAlpha);
@@ -862,13 +869,17 @@ public final class Bitmap implements Parcelable {
     *                 bitmap as opaque. Doing so will clear the bitmap in black
     *                 instead of transparent.
     *
     * @throws IllegalArgumentException if the width or height are <= 0
     * @throws IllegalArgumentException if the width or height are <= 0, or if
     *         Config is Config.HARDWARE, because hardware bitmaps are always immutable
     */
    private static Bitmap createBitmap(DisplayMetrics display, int width, int height,
            Config config, boolean hasAlpha) {
        if (width <= 0 || height <= 0) {
            throw new IllegalArgumentException("width and height must be > 0");
        }
        if (config == Config.HARDWARE) {
            throw new IllegalArgumentException("can't create mutable bitmap with Config.HARDWARE");
        }
        Bitmap bm = nativeCreate(null, 0, width, width, height, config.nativeInt, true);
        if (display != null) {
            bm.mDensity = display.densityDpi;
Loading