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

Commit 98987166 authored by Liana Kazanova (xWF)'s avatar Liana Kazanova (xWF) Committed by Android (Google) Code Review
Browse files

Revert "Keep source bitmap id for received ashmem bitmaps"

This reverts commit 332540d2.

Reason for revert: DroidMonitor: Potential culprit for http://b/406334585 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.

Change-Id: I19d23c7d469a8b09593634502a6687c563ef3bba
parent 332540d2
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -103,13 +103,12 @@ public final class Bitmap implements Parcelable {

    private static volatile int sDefaultDensity = -1;

    /**
     * This id is not authoritative and can be duplicated if an ashmem bitmap is decoded from a
     * parcel.
     */
    private long mId;

    // source id of the bitmap where this bitmap was created from, e.g.
    // in the case of ashmem bitmap received, mSourceId is the mId of
    // the bitmap from the sender
    private long mSourceId = -1;

    /**
     * For backwards compatibility, allows the app layer to change the default
     * density when running old apps.
@@ -183,7 +182,6 @@ public final class Bitmap implements Parcelable {
        }

        mNativePtr = nativeBitmap;
        mSourceId = nativeGetSourceId(mNativePtr);
        final int allocationByteCount = getAllocationByteCount();
        getRegistry(fromMalloc, allocationByteCount).registerNativeAllocation(this, mNativePtr);

@@ -2592,8 +2590,6 @@ public final class Bitmap implements Parcelable {

    private static native Gainmap nativeExtractGainmap(long nativePtr);
    private static native void nativeSetGainmap(long bitmapPtr, long gainmapPtr);
    private static native long nativeGetSourceId(long nativePtr);
    private static native void nativeSetSourceId(long nativePtr, long sourceId);

    // ---------------- @CriticalNative -------------------

+2 −2
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, const SkImageI
#endif

sk_sp<Bitmap> Bitmap::createFrom(const SkImageInfo& info, size_t rowBytes, int fd, void* addr,
                                 size_t size, bool readOnly) {
                                 size_t size, bool readOnly, int64_t id) {
#ifdef _WIN32 // ashmem not implemented on Windows
     return nullptr;
#else
@@ -281,7 +281,7 @@ sk_sp<Bitmap> Bitmap::createFrom(const SkImageInfo& info, size_t rowBytes, int f
        }
    }

    sk_sp<Bitmap> bitmap(new Bitmap(addr, fd, size, info, rowBytes));
    sk_sp<Bitmap> bitmap(new Bitmap(addr, fd, size, info, rowBytes, id));
    if (readOnly) {
        bitmap->setImmutable();
    }
+3 −8
Original line number Diff line number Diff line
@@ -63,8 +63,6 @@ class PixelStorage;

typedef void (*FreeFunc)(void* addr, void* context);

static constexpr uint64_t UNDEFINED_BITMAP_ID = 0u;

class Bitmap : public SkPixelRef {
public:
    /* The allocate factories not only construct the Bitmap object but also allocate the
@@ -100,7 +98,7 @@ public:
                                    BitmapPalette palette);
#endif
    static sk_sp<Bitmap> createFrom(const SkImageInfo& info, size_t rowBytes, int fd, void* addr,
                                    size_t size, bool readOnly);
                                    size_t size, bool readOnly, int64_t id);
    static sk_sp<Bitmap> createFrom(const SkImageInfo&, SkPixelRef&);

    int rowBytesAsPixels() const { return rowBytes() >> mInfo.shiftPerPixel(); }
@@ -114,9 +112,6 @@ public:
        return mId;
    }

    uint64_t getSourceId() const { return mSourceId; }
    void setSourceId(uint64_t sourceId) { mSourceId = sourceId; }

    void getSkBitmap(SkBitmap* outBitmap);

    SkBitmap getSkBitmap() {
@@ -189,6 +184,8 @@ public:

  static bool compress(const SkBitmap& bitmap, JavaCompressFormat format,
                       int32_t quality, SkWStream* stream);

    static constexpr uint64_t UNDEFINED_BITMAP_ID = 0u;
private:
    static sk_sp<Bitmap> allocateAshmemBitmap(size_t size, const SkImageInfo& i, size_t rowBytes);

@@ -244,8 +241,6 @@ private:
    sk_sp<SkImage> mImage;  // Cache is used only for HW Bitmaps with Skia pipeline.

    uint64_t mId;                // unique ID for this bitmap
    // source Id where this bitmap is orignated from
    uint64_t mSourceId;
    static uint64_t getId(PixelStorageType type);

    // for tracing total number and memory usage of bitmaps
+10 −23
Original line number Diff line number Diff line
@@ -192,7 +192,7 @@ void reinitBitmap(JNIEnv* env, jobject javaBitmap, const SkImageInfo& info,
}

jobject createBitmap(JNIEnv* env, Bitmap* bitmap, int bitmapCreateFlags, jbyteArray ninePatchChunk,
                     jobject ninePatchInsets, int density) {
                     jobject ninePatchInsets, int density, int64_t id) {
    static jmethodID gBitmap_constructorMethodID =
        GetMethodIDOrDie(env, gBitmap_class,
            "<init>", "(JJIIIZ[BLandroid/graphics/NinePatch$InsetStruct;Z)V");
@@ -207,8 +207,9 @@ jobject createBitmap(JNIEnv* env, Bitmap* bitmap, int bitmapCreateFlags, jbyteAr
    if (!isMutable) {
        bitmapWrapper->bitmap().setImmutable();
    }
    int64_t bitmapId = id != Bitmap::UNDEFINED_BITMAP_ID ? id : bitmap->getId();
    jobject obj = env->NewObject(gBitmap_class, gBitmap_constructorMethodID,
                                 static_cast<jlong>(bitmap->getId()),
                                 static_cast<jlong>(bitmapId),
                                 reinterpret_cast<jlong>(bitmapWrapper), bitmap->width(),
                                 bitmap->height(), density, isPremultiplied, ninePatchChunk,
                                 ninePatchInsets, fromMalloc);
@@ -815,8 +816,9 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
                    ALOGW("mmap failed, error %d (%s)", err, strerror(err));
                    return STATUS_NO_MEMORY;
                }
                nativeBitmap = Bitmap::createFrom(imageInfo, rowBytes, fd.release(),
                                                  addr, size, !isMutable);
                nativeBitmap =
                        Bitmap::createFrom(imageInfo, rowBytes, fd.release(), addr, size,
                        !isMutable, sourceId);
                return STATUS_OK;
            });

@@ -831,9 +833,8 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
        return nullptr;
    }

    nativeBitmap->setSourceId(sourceId);
    return createBitmap(env, nativeBitmap.release(), getPremulBitmapCreateFlags(isMutable), nullptr,
                        nullptr, density);
                        nullptr, density, sourceId);
#else
    jniThrowRuntimeException(env, "Cannot use parcels outside of Linux");
    return NULL;
@@ -853,7 +854,6 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject, jlong bitmapHandle, j

    auto bitmapWrapper = reinterpret_cast<BitmapWrapper*>(bitmapHandle);
    bitmapWrapper->getSkBitmap(&bitmap);
    uint64_t id = bitmapWrapper->bitmap().getId();

    p.writeInt32(!bitmap.isImmutable());
    p.writeInt32(bitmap.colorType());
@@ -868,12 +868,12 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject, jlong bitmapHandle, j
    p.writeInt32(bitmap.height());
    p.writeInt32(bitmap.rowBytes());
    p.writeInt32(density);
    p.writeInt64(id);

    // Transfer the underlying ashmem region if we have one and it's immutable.
    binder_status_t status;
    int fd = bitmapWrapper->bitmap().getAshmemFd();
    if (fd >= 0 && p.allowFds() && bitmap.isImmutable()) {
        p.writeInt64(bitmapWrapper->bitmap().getId());
#if DEBUG_PARCEL
        ALOGD("Bitmap.writeToParcel: transferring immutable bitmap's ashmem fd as "
              "immutable blob (fds %s)",
@@ -893,7 +893,8 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject, jlong bitmapHandle, j
    ALOGD("Bitmap.writeToParcel: copying bitmap into new blob (fds %s)",
          p.allowFds() ? "allowed" : "forbidden");
#endif
    status = writeBlob(p.get(), id, bitmap);
    p.writeInt64(Bitmap::UNDEFINED_BITMAP_ID);
    status = writeBlob(p.get(), bitmapWrapper->bitmap().getId(), bitmap);
    if (status) {
        doThrowRE(env, "Could not copy bitmap to parcel blob.");
        return JNI_FALSE;
@@ -1225,18 +1226,6 @@ static void Bitmap_setGainmap(JNIEnv*, jobject, jlong bitmapHandle, jlong gainma
    bitmapHolder->bitmap().setGainmap(sp<uirenderer::Gainmap>::fromExisting(gainmap));
}

static jlong Bitmap_getSourceId(JNIEnv*, jobject, jlong bitmapHandle) {
    LocalScopedBitmap bitmapHolder(bitmapHandle);
    return bitmapHolder.valid() ? bitmapHolder->bitmap().getSourceId() : UNDEFINED_BITMAP_ID;
}

static void Bitmap_setSourceId(JNIEnv*, jobject, jlong bitmapHandle, jlong sourceId) {
    LocalScopedBitmap bitmapHolder(bitmapHandle);
    if (bitmapHolder.valid()) {
        bitmapHolder->bitmap().setSourceId(sourceId);
    }
}

///////////////////////////////////////////////////////////////////////////////

static const JNINativeMethod gBitmapMethods[] = {
@@ -1289,8 +1278,6 @@ static const JNINativeMethod gBitmapMethods[] = {
        {"nativeSetImmutable", "(J)V", (void*)Bitmap_setImmutable},
        {"nativeExtractGainmap", "(J)Landroid/graphics/Gainmap;", (void*)Bitmap_extractGainmap},
        {"nativeSetGainmap", "(JJ)V", (void*)Bitmap_setGainmap},
        {"nativeGetSourceId", "(J)J", (void*)Bitmap_getSourceId},
        {"nativeSetSourceId", "(JJ)V", (void*)Bitmap_setSourceId},

        // ------------ @CriticalNative ----------------
        {"nativeIsImmutable", "(J)Z", (void*)Bitmap_isImmutable},
+3 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <jni.h>
#include <android/bitmap.h>
#include <hwui/Bitmap.h>

struct SkImageInfo;

@@ -35,7 +36,7 @@ enum BitmapCreateFlags {

jobject createBitmap(JNIEnv* env, Bitmap* bitmap, int bitmapCreateFlags,
                     jbyteArray ninePatchChunk = nullptr, jobject ninePatchInsets = nullptr,
                    int density = -1);
                     int density = -1, int64_t id = Bitmap::UNDEFINED_BITMAP_ID);

Bitmap& toBitmap(jlong bitmapHandle);