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

Commit 2a6ecae9 authored by Derek Sollenberger's avatar Derek Sollenberger Committed by Android (Google) Code Review
Browse files

Fix Skia assertions where we were allowing immutable bitmaps to be written to.

bug: 7092330
Change-Id: I4a9d1d299244d46172562080c56c8360f5e4af02
parent 1cf42893
Loading
Loading
Loading
Loading
+13 −4
Original line number Original line Diff line number Diff line
@@ -210,19 +210,28 @@ static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding,
    JavaPixelAllocator javaAllocator(env);
    JavaPixelAllocator javaAllocator(env);


    SkBitmap* bitmap;
    SkBitmap* bitmap;
    bool useExistingBitmap = false;
    if (javaBitmap == NULL) {
    if (javaBitmap == NULL) {
        bitmap = new SkBitmap;
        bitmap = new SkBitmap;
    } else {
    } else {
        if (sampleSize != 1) {
        if (sampleSize != 1) {
            return nullObjectReturn("SkImageDecoder: Cannot reuse bitmap with sampleSize != 1");
            return nullObjectReturn("SkImageDecoder: Cannot reuse bitmap with sampleSize != 1");
        }
        }

        bitmap = (SkBitmap*) env->GetIntField(javaBitmap, gBitmap_nativeBitmapFieldID);
        bitmap = (SkBitmap*) env->GetIntField(javaBitmap, gBitmap_nativeBitmapFieldID);
        // only reuse the provided bitmap if it is immutable
        if (!bitmap->isImmutable()) {
            useExistingBitmap = true;
            // config of supplied bitmap overrules config set in options
            // config of supplied bitmap overrules config set in options
            prefConfig = bitmap->getConfig();
            prefConfig = bitmap->getConfig();
        } else {
            ALOGW("Unable to reuse an immutable bitmap as an image decoder target.");
            bitmap = new SkBitmap;
        }
    }
    }


    SkAutoTDelete<SkImageDecoder> add(decoder);
    SkAutoTDelete<SkImageDecoder> add(decoder);
    SkAutoTDelete<SkBitmap> adb(bitmap, javaBitmap == NULL);
    SkAutoTDelete<SkBitmap> adb(bitmap, !useExistingBitmap);


    decoder->setPeeker(&peeker);
    decoder->setPeeker(&peeker);
    if (!isPurgeable) {
    if (!isPurgeable) {
@@ -381,7 +390,7 @@ static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding,
    // detach bitmap from its autodeleter, since we want to own it now
    // detach bitmap from its autodeleter, since we want to own it now
    adb.detach();
    adb.detach();


    if (javaBitmap != NULL) {
    if (useExistingBitmap) {
        // If a java bitmap was passed in for reuse, pass it back
        // If a java bitmap was passed in for reuse, pass it back
        return javaBitmap;
        return javaBitmap;
    }
    }