Ref count the nodes in VectorDrawable

Also added API check so that for pre-N we ignore invalid VD animation,
in order to avoid breaking old apps.

Bug: 26975469
Bug: 26949340
Change-Id: I498539ad6a05de3d886e7dcdc8a167e78333ab11
This commit is contained in:
Doris Liu
2016-02-04 16:16:27 -08:00
parent 766431aa57
commit ef062ebd20
5 changed files with 64 additions and 55 deletions

View File

@@ -924,8 +924,11 @@ public class VectorDrawable extends Drawable {
private int mChangingConfigurations;
private int[] mThemeAttrs;
private String mGroupName = null;
private long mNativePtr = 0;
// The native object will be created in the constructor and will be destroyed in native
// when the neither java nor native has ref to the tree. This pointer should be valid
// throughout this VGroup Java object's life.
private final long mNativePtr;
public VGroup(VGroup copy, ArrayMap<String, Object> targetsMap) {
mIsStateful = copy.mIsStateful;
@@ -1064,16 +1067,6 @@ public class VectorDrawable extends Drawable {
return false;
}
@Override
protected void finalize() throws Throwable {
if (mNativePtr != 0) {
nDestroy(mNativePtr);
mNativePtr = 0;
}
super.finalize();
}
@Override
public void applyTheme(Theme t) {
if (mThemeAttrs != null) {
@@ -1208,10 +1201,10 @@ public class VectorDrawable extends Drawable {
* Clip path, which only has name and pathData.
*/
private static class VClipPath extends VPath {
long mNativePtr = 0;
private final long mNativePtr;
public VClipPath() {
mNativePtr = nCreateClipPath();
// Empty constructor.
}
public VClipPath(VClipPath copy) {
@@ -1224,14 +1217,6 @@ public class VectorDrawable extends Drawable {
return mNativePtr;
}
@Override
protected void finalize() throws Throwable {
if (mNativePtr != 0) {
nDestroy(mNativePtr);
mNativePtr = 0;
}
super.finalize();
}
@Override
public void inflate(Resources r, AttributeSet attrs, Theme theme) {
final TypedArray a = obtainAttributes(r, theme, attrs,
@@ -1317,10 +1302,9 @@ public class VectorDrawable extends Drawable {
ComplexColor mStrokeColors = null;
ComplexColor mFillColors = null;
private long mNativePtr = 0;
private final long mNativePtr;
public VFullPath() {
// Empty constructor.
mNativePtr = nCreateFullPath();
}
@@ -1384,15 +1368,6 @@ public class VectorDrawable extends Drawable {
a.recycle();
}
@Override
protected void finalize() throws Throwable {
if (mNativePtr != 0) {
nDestroy(mNativePtr);
mNativePtr = 0;
}
super.finalize();
}
private void updateStateFromTypedArray(TypedArray a) {
int byteCount = TOTAL_PROPERTY_COUNT * 4;
if (mPropertyData == null) {
@@ -1647,7 +1622,7 @@ public class VectorDrawable extends Drawable {
private static native void nDraw(long rendererPtr, long canvasWrapperPtr,
long colorFilterPtr, Rect bounds, boolean needsMirroring, boolean canReuseCache);
private static native long nCreateFullPath();
private static native long nCreateFullPath(long mNativeFullPathPtr);
private static native long nCreateFullPath(long nativeFullPathPtr);
private static native boolean nGetFullPathProperties(long pathPtr, byte[] properties,
int length);
@@ -1663,7 +1638,6 @@ public class VectorDrawable extends Drawable {
private static native long nCreateGroup();
private static native long nCreateGroup(long groupPtr);
private static native void nDestroy(long nodePtr);
private static native void nSetName(long nodePtr, String name);
private static native boolean nGetGroupProperties(long groupPtr, float[] properties,
int length);