Switch back to NativeAllocationRegistry
Bug: 32881864
Partial revert of 3acf0382da
Test: none
Change-Id: Ie749e0ef0a84ff820b1ea445422cf28112d62209
This commit is contained in:
@@ -26,6 +26,8 @@ import android.graphics.drawable.AnimatedVectorDrawable;
|
||||
|
||||
import dalvik.annotation.optimization.FastNative;
|
||||
|
||||
import libcore.util.NativeAllocationRegistry;
|
||||
|
||||
/**
|
||||
* <p>A display list records a series of graphics related operations and can replay
|
||||
* them later. Display lists are usually built by recording operations on a
|
||||
@@ -130,13 +132,20 @@ import dalvik.annotation.optimization.FastNative;
|
||||
*/
|
||||
public class RenderNode {
|
||||
|
||||
// Use a Holder to allow static initialization in the boot image.
|
||||
private static class NoImagePreloadHolder {
|
||||
public static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry(
|
||||
RenderNode.class.getClassLoader(), nGetNativeFinalizer(), 1024);
|
||||
}
|
||||
|
||||
private boolean mValid;
|
||||
// Do not access directly unless you are ThreadedRenderer
|
||||
long mNativeRenderNode;
|
||||
final long mNativeRenderNode;
|
||||
private final View mOwningView;
|
||||
|
||||
private RenderNode(String name, View owningView) {
|
||||
mNativeRenderNode = nCreate(name);
|
||||
NoImagePreloadHolder.sRegistry.registerNativeAllocation(this, mNativeRenderNode);
|
||||
mOwningView = owningView;
|
||||
}
|
||||
|
||||
@@ -145,6 +154,7 @@ public class RenderNode {
|
||||
*/
|
||||
private RenderNode(long nativePtr) {
|
||||
mNativeRenderNode = nativePtr;
|
||||
NoImagePreloadHolder.sRegistry.registerNativeAllocation(this, mNativeRenderNode);
|
||||
mOwningView = null;
|
||||
}
|
||||
|
||||
@@ -154,19 +164,7 @@ public class RenderNode {
|
||||
* is not feasible.
|
||||
*/
|
||||
public void destroy() {
|
||||
if (mNativeRenderNode != 0) {
|
||||
nFinalize(mNativeRenderNode);
|
||||
mNativeRenderNode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
destroy();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
// TODO: Removed temporarily
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -835,7 +833,6 @@ public class RenderNode {
|
||||
|
||||
// Intentionally not static because it acquires a reference to 'this'
|
||||
private native long nCreate(String name);
|
||||
private native void nFinalize(long renderNode);
|
||||
|
||||
private static native long nGetNativeFinalizer();
|
||||
private static native void nSetDisplayList(long renderNode, long newData);
|
||||
|
||||
@@ -124,10 +124,6 @@ static void releaseRenderNode(RenderNode* renderNode) {
|
||||
renderNode->decStrong(0);
|
||||
}
|
||||
|
||||
static void android_view_RenderNode_finalize(JNIEnv* env, jobject clazz, jlong renderNodePtr) {
|
||||
releaseRenderNode(reinterpret_cast<RenderNode*>(renderNodePtr));
|
||||
}
|
||||
|
||||
static jlong android_view_RenderNode_getNativeFinalizer(JNIEnv* env,
|
||||
jobject clazz) {
|
||||
return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseRenderNode));
|
||||
@@ -654,7 +650,6 @@ static const JNINativeMethod gMethods[] = {
|
||||
// Regular JNI
|
||||
// ----------------------------------------------------------------------------
|
||||
{ "nCreate", "(Ljava/lang/String;)J", (void*) android_view_RenderNode_create },
|
||||
{ "nFinalize", "(J)V", (void*) android_view_RenderNode_finalize },
|
||||
{ "nGetNativeFinalizer", "()J", (void*) android_view_RenderNode_getNativeFinalizer },
|
||||
{ "nSetDisplayList", "(JJ)V", (void*) android_view_RenderNode_setDisplayList },
|
||||
{ "nOutput", "(J)V", (void*) android_view_RenderNode_output },
|
||||
|
||||
Reference in New Issue
Block a user