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

Commit aed7f58f authored by sergeyv's avatar sergeyv
Browse files

Pass Bitmap instead of SkBitmap in canvas.drawBitmap(Bitmap, float,float,Paint)

Test: refactoring cl.
bug:32216791

Change-Id: If9f9fbc19e683b14cce6c3c268258bd832d495d2
parent c1c54062
Loading
Loading
Loading
Loading
+11 −9
Original line number Original line Diff line number Diff line
@@ -55,7 +55,10 @@ public:
        return !!mBitmap;
        return !!mBitmap;
    }
    }


    Bitmap* bitmap() { return mBitmap.get(); }
    Bitmap& bitmap() {
        assertValid();
        return *mBitmap;
    }


    void assertValid() {
    void assertValid() {
        LOG_ALWAYS_FATAL_IF(!valid(), "Error, cannot access an invalid/free'd bitmap here!");
        LOG_ALWAYS_FATAL_IF(!valid(), "Error, cannot access an invalid/free'd bitmap here!");
@@ -134,7 +137,7 @@ public:
    }
    }


    void* pixels() {
    void* pixels() {
        return mBitmapWrapper->bitmap()->pixels();
        return mBitmapWrapper->bitmap().pixels();
    }
    }


    bool valid() {
    bool valid() {
@@ -200,13 +203,12 @@ void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap) {
    bitmap->getSkBitmap(outBitmap);
    bitmap->getSkBitmap(outBitmap);
}
}


Bitmap* toBitmap(JNIEnv* env, jobject bitmap) {
Bitmap& toBitmap(JNIEnv* env, jobject bitmap) {
    SkASSERT(env);
    SkASSERT(env);
    SkASSERT(bitmap);
    SkASSERT(bitmap);
    SkASSERT(env->IsInstanceOf(bitmap, gBitmap_class));
    SkASSERT(env->IsInstanceOf(bitmap, gBitmap_class));
    jlong bitmapHandle = env->GetLongField(bitmap, gBitmap_nativePtr);
    jlong bitmapHandle = env->GetLongField(bitmap, gBitmap_nativePtr);
    LocalScopedBitmap localBitmap(bitmapHandle);
    LocalScopedBitmap localBitmap(bitmapHandle);
    localBitmap->assertValid();
    return localBitmap->bitmap();
    return localBitmap->bitmap();
}
}


@@ -646,7 +648,7 @@ static void Bitmap_reconfigure(JNIEnv* env, jobject clazz, jlong bitmapHandle,
        // Otherwise respect the premultiplied request.
        // Otherwise respect the premultiplied request.
        alphaType = requestPremul ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
        alphaType = requestPremul ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
    }
    }
    bitmap->bitmap()->reconfigure(SkImageInfo::Make(width, height, colorType, alphaType,
    bitmap->bitmap().reconfigure(SkImageInfo::Make(width, height, colorType, alphaType,
            sk_sp<SkColorSpace>(bitmap->info().colorSpace())));
            sk_sp<SkColorSpace>(bitmap->info().colorSpace())));
}
}


@@ -941,7 +943,7 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,


    // Transfer the underlying ashmem region if we have one and it's immutable.
    // Transfer the underlying ashmem region if we have one and it's immutable.
    android::status_t status;
    android::status_t status;
    int fd = bitmapWrapper->bitmap()->getAshmemFd();
    int fd = bitmapWrapper->bitmap().getAshmemFd();
    if (fd >= 0 && !isMutable && p->allowFds()) {
    if (fd >= 0 && !isMutable && p->allowFds()) {
#if DEBUG_PARCEL
#if DEBUG_PARCEL
        ALOGD("Bitmap.writeToParcel: transferring immutable bitmap's ashmem fd as "
        ALOGD("Bitmap.writeToParcel: transferring immutable bitmap's ashmem fd as "
@@ -1189,9 +1191,9 @@ static jboolean Bitmap_sameAs(JNIEnv* env, jobject, jlong bm0Handle,


static jlong Bitmap_refPixelRef(JNIEnv* env, jobject, jlong bitmapHandle) {
static jlong Bitmap_refPixelRef(JNIEnv* env, jobject, jlong bitmapHandle) {
    LocalScopedBitmap bitmap(bitmapHandle);
    LocalScopedBitmap bitmap(bitmapHandle);
    SkPixelRef* pixelRef = bitmap->bitmap();
    SkPixelRef& pixelRef = bitmap->bitmap();
    SkSafeRef(pixelRef);
    pixelRef.ref();
    return reinterpret_cast<jlong>(pixelRef);
    return reinterpret_cast<jlong>(&pixelRef);
}
}


static void Bitmap_prepareToDraw(JNIEnv* env, jobject, jlong bitmapPtr) {
static void Bitmap_prepareToDraw(JNIEnv* env, jobject, jlong bitmapPtr) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -41,7 +41,7 @@ jobject createBitmap(JNIEnv* env, Bitmap* bitmap,


void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap);
void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap);


Bitmap* toBitmap(JNIEnv* env, jobject bitmap);
Bitmap& toBitmap(JNIEnv* env, jobject bitmap);


/** Reinitialize a bitmap. bitmap must already have its SkAlphaType set in
/** Reinitialize a bitmap. bitmap must already have its SkAlphaType set in
    sync with isPremultiplied
    sync with isPremultiplied
+1 −1
Original line number Original line Diff line number Diff line
@@ -330,7 +330,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
    android::Bitmap* reuseBitmap = nullptr;
    android::Bitmap* reuseBitmap = nullptr;
    unsigned int existingBufferSize = 0;
    unsigned int existingBufferSize = 0;
    if (javaBitmap != NULL) {
    if (javaBitmap != NULL) {
        reuseBitmap = bitmap::toBitmap(env, javaBitmap);
        reuseBitmap = &bitmap::toBitmap(env, javaBitmap);
        if (reuseBitmap->isImmutable()) {
        if (reuseBitmap->isImmutable()) {
            ALOGW("Unable to reuse an immutable bitmap as an image decoder target.");
            ALOGW("Unable to reuse an immutable bitmap as an image decoder target.");
            javaBitmap = NULL;
            javaBitmap = NULL;
+1 −1
Original line number Original line Diff line number Diff line
@@ -151,7 +151,7 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in
    android::Bitmap* recycledBitmap = nullptr;
    android::Bitmap* recycledBitmap = nullptr;
    size_t recycledBytes = 0;
    size_t recycledBytes = 0;
    if (javaBitmap) {
    if (javaBitmap) {
        recycledBitmap = bitmap::toBitmap(env, javaBitmap);
        recycledBitmap = &bitmap::toBitmap(env, javaBitmap);
        if (recycledBitmap->isImmutable()) {
        if (recycledBitmap->isImmutable()) {
            ALOGW("Warning: Reusing an immutable bitmap as an image decoder target.");
            ALOGW("Warning: Reusing an immutable bitmap as an image decoder target.");
        }
        }
+5 −5
Original line number Original line Diff line number Diff line
@@ -337,13 +337,13 @@ SkColorType GraphicsJNI::legacyBitmapConfigToColorType(jint legacyConfig) {
}
}


void GraphicsJNI::getSkBitmap(JNIEnv* env, jobject bitmap, SkBitmap* outBitmap) {
void GraphicsJNI::getSkBitmap(JNIEnv* env, jobject bitmap, SkBitmap* outBitmap) {
    android::bitmap::toBitmap(env, bitmap)->getSkBitmap(outBitmap);
    android::bitmap::toBitmap(env, bitmap).getSkBitmap(outBitmap);
}
}


SkPixelRef* GraphicsJNI::refSkPixelRef(JNIEnv* env, jobject bitmap) {
SkPixelRef* GraphicsJNI::refSkPixelRef(JNIEnv* env, jobject jbitmap) {
    SkPixelRef* pixelRef = android::bitmap::toBitmap(env, bitmap);
    android::Bitmap& bitmap = android::bitmap::toBitmap(env, jbitmap);
    pixelRef->ref();
    bitmap.ref();
    return pixelRef;
    return &bitmap;
}
}
SkColorType GraphicsJNI::getNativeBitmapColorType(JNIEnv* env, jobject jconfig) {
SkColorType GraphicsJNI::getNativeBitmapColorType(JNIEnv* env, jobject jconfig) {
    SkASSERT(env);
    SkASSERT(env);
Loading