Merge "Remove FD from the right Looper" into nyc-dev

This commit is contained in:
John Reck
2016-06-23 18:32:08 +00:00
committed by Android (Google) Code Review
3 changed files with 17 additions and 5 deletions

View File

@@ -232,6 +232,19 @@ public final class Choreographer {
return sThreadInstance.get(); return sThreadInstance.get();
} }
/** Destroys the calling thread's choreographer
* @hide
*/
public static void releaseInstance() {
Choreographer old = sThreadInstance.get();
sThreadInstance.remove();
old.dispose();
}
private void dispose() {
mDisplayEventReceiver.dispose();
}
/** /**
* The amount of time, in milliseconds, between each frame of the animation. * The amount of time, in milliseconds, between each frame of the animation.
* <p> * <p>

View File

@@ -217,6 +217,7 @@ public class BackdropFrameRenderer extends Thread implements Choreographer.Frame
synchronized (this) { synchronized (this) {
// Make sure no more messages are being sent. // Make sure no more messages are being sent.
mChoreographer = null; mChoreographer = null;
Choreographer.releaseInstance();
} }
} }

View File

@@ -81,14 +81,12 @@ NativeDisplayEventReceiver::NativeDisplayEventReceiver(JNIEnv* env,
NativeDisplayEventReceiver::~NativeDisplayEventReceiver() { NativeDisplayEventReceiver::~NativeDisplayEventReceiver() {
JNIEnv* env = AndroidRuntime::getJNIEnv(); JNIEnv* env = AndroidRuntime::getJNIEnv();
env->DeleteGlobalRef(mReceiverWeakGlobal); env->DeleteGlobalRef(mReceiverWeakGlobal);
ALOGV("receiver %p ~ dtor display event receiver.", this);
} }
void NativeDisplayEventReceiver::dispose() { void NativeDisplayEventReceiver::dispose() {
ALOGV("receiver %p ~ Disposing display event receiver.", this); ALOGV("receiver %p ~ Disposing display event receiver.", this);
DisplayEventDispatcher::dispose();
if (!mReceiver.initCheck()) {
mMessageQueue->getLooper()->removeFd(mReceiver.getFd());
}
} }
void NativeDisplayEventReceiver::dispatchVsync(nsecs_t timestamp, int32_t id, uint32_t count) { void NativeDisplayEventReceiver::dispatchVsync(nsecs_t timestamp, int32_t id, uint32_t count) {
@@ -143,7 +141,7 @@ static jlong nativeInit(JNIEnv* env, jclass clazz, jobject receiverWeak,
} }
static void nativeDispose(JNIEnv* env, jclass clazz, jlong receiverPtr) { static void nativeDispose(JNIEnv* env, jclass clazz, jlong receiverPtr) {
sp<NativeDisplayEventReceiver> receiver = NativeDisplayEventReceiver* receiver =
reinterpret_cast<NativeDisplayEventReceiver*>(receiverPtr); reinterpret_cast<NativeDisplayEventReceiver*>(receiverPtr);
receiver->dispose(); receiver->dispose();
receiver->decStrong(gDisplayEventReceiverClassInfo.clazz); // drop reference held by the object receiver->decStrong(gDisplayEventReceiverClassInfo.clazz); // drop reference held by the object