Merge "Frameworks/base: Refactor Paint & Canvas native allocation support" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
15f6810d9e
@@ -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(
|
||||
getNativeFinalizer(), NATIVE_ALLOCATION_SIZE);
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
nGetNativeFinalizer(), NATIVE_PAINT_SIZE);
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user