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

Commit bd7e0bc7 authored by Priyanka Advani (xWF)'s avatar Priyanka Advani (xWF) Committed by Android (Google) Code Review
Browse files

Revert "Update native allocation size in Bitmap#recycle()"

This reverts commit cc4d532c.

Reason for revert: Droidmonitor created revert due to b/441804951. This CL is just for testing purpose.

Fix: 441804951
Change-Id: I120004daca4324db38acb70f48d698e5f3474362
parent cc4d532c
Loading
Loading
Loading
Loading
+8 −39
Original line number Diff line number Diff line
@@ -139,47 +139,19 @@ public final class Bitmap implements Parcelable {
    private static final WeakHashMap<Bitmap, Void> sAllBitmaps = new WeakHashMap<>();

    /**
     * Two NativeAllocationRegistry instances are used to register the native
     * allocation for each bitmap:
     *
     *   1. One with a no-op free function for updating the native allocation
     *      size of the pixel data only, without actually releasing the native
     *      object that's associated with the bitmap instance.
     *
     *   2. sRegistry is the other static one with a valid freeFunction and a
     *      default (estimated) size to actually release the native object
     *      associated with this bitmap.
     *
     *  mRecycler is the cleaner runner from #1, and is used in Bitmap#recycle()
     *  to update the native allocation size associated with the pixel data
     *  released.
     * @hide
     */
    private static NativeAllocationRegistry sRegistry = null;

    private Runnable mRecycler;

    private void registerNativeAllocation(boolean malloc) {
    private static NativeAllocationRegistry getRegistry(boolean malloc, long size) {
        final long free = nativeGetNativeFinalizer();
        final long noop = nativeGetNativeNoop();
        final int size = getAllocationByteCount();
        NativeAllocationRegistry registry;
        if (com.android.libcore.readonly.Flags.nativeMetrics()) {
            Class cls = Bitmap.class;
            if (sRegistry == null) {
                sRegistry = NativeAllocationRegistry.createMalloced(cls, free);
            }
            registry = malloc ? NativeAllocationRegistry.createMalloced(cls, noop, size)
                              : NativeAllocationRegistry.createNonmalloced(cls, noop, size);
            return malloc ? NativeAllocationRegistry.createMalloced(cls, free, size)
                          : NativeAllocationRegistry.createNonmalloced(cls, free, size);
        } else {
            ClassLoader loader = Bitmap.class.getClassLoader();
            if (sRegistry == null) {
                sRegistry = NativeAllocationRegistry.createMalloced(loader, free);
            return malloc ? NativeAllocationRegistry.createMalloced(loader, free, size)
                          : NativeAllocationRegistry.createNonmalloced(loader, free, size);
        }
            registry = malloc ? NativeAllocationRegistry.createMalloced(loader, noop, size)
                              : NativeAllocationRegistry.createNonmalloced(loader, noop, size);
        }
        mRecycler = registry.registerNativeAllocation(this, mNativePtr);
        sRegistry.registerNativeAllocation(this, mNativePtr);
    }

    /**
@@ -215,7 +187,8 @@ public final class Bitmap implements Parcelable {

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

        synchronized (Bitmap.class) {
          sAllBitmaps.put(this, null);
@@ -432,9 +405,6 @@ public final class Bitmap implements Parcelable {
            mNinePatchChunk = null;
            mRecycled = true;
            mHardwareBuffer = null;
            if (mRecycler != null) {
                mRecycler.run();
            }
        }
    }

@@ -2633,7 +2603,6 @@ public final class Bitmap implements Parcelable {
    private static native Bitmap nativeCopyAshmemConfig(long nativeSrcBitmap, int nativeConfig);
    private static native int nativeGetAshmemFD(long nativeBitmap);
    private static native long nativeGetNativeFinalizer();
    private static native long nativeGetNativeNoop();
    private static native void nativeRecycle(long nativeBitmap);
    @UnsupportedAppUsage
    private static native void nativeReconfigure(long nativeBitmap, int width, int height,
+0 −8
Original line number Diff line number Diff line
@@ -563,13 +563,6 @@ static void Bitmap_recycle(JNIEnv* env, jobject, jlong bitmapHandle) {
    bitmap->freePixels();
}

static void Bitmap_noop(BitmapWrapper* bitmap) {
}

static jlong Bitmap_getNativeNoop(JNIEnv*, jobject) {
    return static_cast<jlong>(reinterpret_cast<uintptr_t>(&Bitmap_noop));
}

static void Bitmap_reconfigure(JNIEnv* env, jobject clazz, jlong bitmapHandle,
        jint width, jint height, jint configHandle, jboolean requestPremul) {
    LocalScopedBitmap bitmap(bitmapHandle);
@@ -1426,7 +1419,6 @@ static const JNINativeMethod gBitmapMethods[] = {
        {"nativeCopyAshmemConfig", "(JI)Landroid/graphics/Bitmap;", (void*)Bitmap_copyAshmemConfig},
        {"nativeGetAshmemFD", "(J)I", (void*)Bitmap_getAshmemFd},
        {"nativeGetNativeFinalizer", "()J", (void*)Bitmap_getNativeFinalizer},
        {"nativeGetNativeNoop", "()J", (void*)Bitmap_getNativeNoop},
        {"nativeRecycle", "(J)V", (void*)Bitmap_recycle},
        {"nativeReconfigure", "(JIIIZ)V", (void*)Bitmap_reconfigure},
        {"nativeCompress", "(JIILjava/io/OutputStream;[B)Z", (void*)Bitmap_compress},