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

Commit 31f4b099 authored by Eric Miao's avatar Eric Miao Committed by Android (Google) Code Review
Browse files

Merge "Track HardwareBuffer native allocations" into main

parents ad0012cb 13c4422e
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -277,6 +277,17 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
        return new HardwareBuffer(nativeObject);
    }

    /**
     * @hide
     */
    private static NativeAllocationRegistry getRegistry(long size) {
        final long func = nGetNativeFinalizer();
        final Class cls = HardwareBuffer.class;
        return com.android.libcore.Flags.nativeMetrics()
            ? NativeAllocationRegistry.createNonmalloced(cls, func, size)
            : NativeAllocationRegistry.createNonmalloced(cls.getClassLoader(), func, size);
    }

    /**
     * Private use only. See {@link #create(int, int, int, int, long)}. May also be
     * called from JNI using an already allocated native <code>HardwareBuffer</code>.
@@ -285,10 +296,7 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
    private HardwareBuffer(long nativeObject) {
        mNativeObject = nativeObject;
        long bufferSize = nEstimateSize(nativeObject);
        ClassLoader loader = HardwareBuffer.class.getClassLoader();
        NativeAllocationRegistry registry = new NativeAllocationRegistry(
                loader, nGetNativeFinalizer(), bufferSize);
        mCleaner = registry.registerNativeAllocation(this, mNativeObject);
        mCleaner = getRegistry(bufferSize).registerNativeAllocation(this, mNativeObject);
        mCloseGuard.open("HardwareBuffer.close");
    }