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

Commit 15f6810d authored by Andreas Gampe's avatar Andreas Gampe Committed by Android (Google) Code Review
Browse files

Merge "Frameworks/base: Refactor Paint & Canvas native allocation support" into nyc-dev

parents 6ac25c56 f6765f39
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -91,8 +91,11 @@ public class Canvas {
    // a Canvas object.
    private static final long NATIVE_ALLOCATION_SIZE = 525;

    private static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry(
    // Use a Holder to allow static initialization of Canvas in the boot image.
    private static class NoImagePreloadHolder {
        public static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry(
                getNativeFinalizer(), NATIVE_ALLOCATION_SIZE);
    }

    // This field is used to finalize the native Canvas properly
    private Runnable mFinalizer;
@@ -107,7 +110,8 @@ public class Canvas {
        if (!isHardwareAccelerated()) {
            // 0 means no native bitmap
            mNativeCanvasWrapper = initRaster(null);
            mFinalizer = sRegistry.registerNativeAllocation(this, mNativeCanvasWrapper);
            mFinalizer = NoImagePreloadHolder.sRegistry.registerNativeAllocation(
                    this, mNativeCanvasWrapper);
        } else {
            mFinalizer = null;
        }
@@ -128,7 +132,8 @@ public class Canvas {
        }
        throwIfCannotDraw(bitmap);
        mNativeCanvasWrapper = initRaster(bitmap);
        mFinalizer = sRegistry.registerNativeAllocation(this, mNativeCanvasWrapper);
        mFinalizer = NoImagePreloadHolder.sRegistry.registerNativeAllocation(
                this, mNativeCanvasWrapper);
        mBitmap = bitmap;
        mDensity = bitmap.mDensity;
    }
@@ -139,7 +144,8 @@ public class Canvas {
            throw new IllegalStateException();
        }
        mNativeCanvasWrapper = nativeCanvas;
        mFinalizer = sRegistry.registerNativeAllocation(this, mNativeCanvasWrapper);
        mFinalizer = NoImagePreloadHolder.sRegistry.registerNativeAllocation(
                this, mNativeCanvasWrapper);
        mDensity = Bitmap.getDefaultDensity();
    }

+7 −4
Original line number Diff line number Diff line
@@ -44,8 +44,11 @@ public class Paint {
    // The approximate size of a native paint object.
    private static final long NATIVE_PAINT_SIZE = 98;

    private static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry(
    // Use a Holder to allow static initialization of Paint in the boot image.
    private static class NoImagePreloadHolder {
        public static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry(
                nGetNativeFinalizer(), NATIVE_PAINT_SIZE);
    }

    /**
     * @hide
@@ -452,7 +455,7 @@ public class Paint {
     */
    public Paint(int flags) {
        mNativePaint = nInit();
        sRegistry.registerNativeAllocation(this, mNativePaint);
        NoImagePreloadHolder.sRegistry.registerNativeAllocation(this, mNativePaint);
        setFlags(flags | HIDDEN_DEFAULT_PAINT_FLAGS);
        // TODO: Turning off hinting has undesirable side effects, we need to
        //       revisit hinting once we add support for subpixel positioning
@@ -471,7 +474,7 @@ public class Paint {
     */
    public Paint(Paint paint) {
        mNativePaint = nInitWithPaint(paint.getNativeInstance());
        sRegistry.registerNativeAllocation(this, mNativePaint);
        NoImagePreloadHolder.sRegistry.registerNativeAllocation(this, mNativePaint);
        setClassVariablesFrom(paint);
    }