aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Perez <diegoperez@google.com>2017-07-10 16:03:53 +0100
committerDiego Perez <diegoperez@google.com>2017-07-10 16:03:53 +0100
commit67f948f353b652d3373c7bdb0c2a8715e8b4e9f6 (patch)
tree9dab5f30c79f24037113ddace361ae8abdee29cf
parent6f28054ccab0206286d231726d91fedb90b68002 (diff)
downloadlayoutlib-67f948f353b652d3373c7bdb0c2a8715e8b4e9f6.tar.gz
Fixes animated vector drawable test
The frame cleanup in the Choreographer was not cleaning the AnimationHandler. Test: Fixes existing test Change-Id: I3f80d3518c7aab1ffebd6f3f2045874be3d32daf
-rw-r--r--bridge/src/android/view/Choreographer_Delegate.java47
-rw-r--r--bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java6
2 files changed, 26 insertions, 27 deletions
diff --git a/bridge/src/android/view/Choreographer_Delegate.java b/bridge/src/android/view/Choreographer_Delegate.java
index 453d59edd4..1dc777885b 100644
--- a/bridge/src/android/view/Choreographer_Delegate.java
+++ b/bridge/src/android/view/Choreographer_Delegate.java
@@ -15,12 +15,12 @@
*/
package android.view;
-import com.android.ide.common.rendering.api.LayoutLog;
-import com.android.layoutlib.bridge.Bridge;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
-import com.android.tools.layoutlib.java.System_Delegate;
-import java.lang.reflect.Field;
+import android.animation.AnimationHandler;
+import android.util.TimeUtils;
+import android.view.animation.AnimationUtils;
+
import java.util.concurrent.atomic.AtomicReference;
/**
@@ -55,18 +55,23 @@ public class Choreographer_Delegate {
public static void doFrame(long frameTimeNanos) {
Choreographer thisChoreographer = Choreographer.getInstance();
- thisChoreographer.mLastFrameTimeNanos = frameTimeNanos - thisChoreographer
- .getFrameIntervalNanos();
- thisChoreographer.mFrameInfo.markInputHandlingStart();
- thisChoreographer.doCallbacks(Choreographer.CALLBACK_INPUT, frameTimeNanos);
+ AnimationUtils.lockAnimationClock(frameTimeNanos / TimeUtils.NANOS_PER_MS);
+
+ try {
+ thisChoreographer.mLastFrameTimeNanos = frameTimeNanos - thisChoreographer.getFrameIntervalNanos();
+ thisChoreographer.mFrameInfo.markInputHandlingStart();
+ thisChoreographer.doCallbacks(Choreographer.CALLBACK_INPUT, frameTimeNanos);
- thisChoreographer.mFrameInfo.markAnimationsStart();
- thisChoreographer.doCallbacks(Choreographer.CALLBACK_ANIMATION, frameTimeNanos);
+ thisChoreographer.mFrameInfo.markAnimationsStart();
+ thisChoreographer.doCallbacks(Choreographer.CALLBACK_ANIMATION, frameTimeNanos);
- thisChoreographer.mFrameInfo.markPerformTraversalsStart();
- thisChoreographer.doCallbacks(Choreographer.CALLBACK_TRAVERSAL, frameTimeNanos);
+ thisChoreographer.mFrameInfo.markPerformTraversalsStart();
+ thisChoreographer.doCallbacks(Choreographer.CALLBACK_TRAVERSAL, frameTimeNanos);
- thisChoreographer.doCallbacks(Choreographer.CALLBACK_COMMIT, frameTimeNanos);
+ thisChoreographer.doCallbacks(Choreographer.CALLBACK_COMMIT, frameTimeNanos);
+ } finally {
+ AnimationUtils.unlockAnimationClock();
+ }
}
public static void clearFrames() {
@@ -76,19 +81,13 @@ public class Choreographer_Delegate {
thisChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, null, null);
thisChoreographer.removeCallbacks(Choreographer.CALLBACK_TRAVERSAL, null, null);
thisChoreographer.removeCallbacks(Choreographer.CALLBACK_COMMIT, null, null);
+
+ // Release animation handler instance since it holds references to the callbacks
+ AnimationHandler.sAnimatorHandler.set(null);
}
public static void dispose() {
- try {
- Field threadInstanceField = Choreographer.class.getDeclaredField("sThreadInstance");
- threadInstanceField.setAccessible(true);
- @SuppressWarnings("unchecked") ThreadLocal<Choreographer> threadInstance =
- (ThreadLocal<Choreographer>) threadInstanceField.get(null);
- threadInstance.remove();
- } catch (ReflectiveOperationException e) {
- assert false;
- Bridge.getLog().error(LayoutLog.TAG_BROKEN,
- "Unable to clear Choreographer memory.", e, null);
- }
+ clearFrames();
+ Choreographer.releaseInstance();
}
}
diff --git a/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index 56665044a9..2e31980a47 100644
--- a/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -348,6 +348,8 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
visitAllChildren(mViewRoot, 0, 0, params.getExtendedViewInfoMode(),
false);
+ Choreographer_Delegate.clearFrames();
+
return SUCCESS.createResult();
} catch (PostInflateException e) {
return ERROR_INFLATION.createResult(e.getMessage(), e);
@@ -552,8 +554,6 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
visitAllChildren(mViewRoot, 0, 0, params.getExtendedViewInfoMode(),
false);
- Choreographer_Delegate.clearFrames();
-
// success!
return renderResult;
} catch (Throwable e) {
@@ -1135,8 +1135,8 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
mContentRoot = null;
if (createdLooper) {
- Bridge.cleanupThread();
Choreographer_Delegate.dispose();
+ Bridge.cleanupThread();
}
}
}