android 动画原理分析

android 动画分为app内的view动画和系统动画

基本原理都是监听Choreographer的doframe回调

app端的实现是主要通过AnimationUtils来实现具体属性的变化通过invilate来驱动

wms来进行更新。这个流程是在app进程完成

这里不是我分析的重点

直接来看下系统动画里面的本地动画:app启动动画,这个流程是在系统进程完成

这里分成三个部分的流程:

动画的触发,动画的加载,动画的启动,动画的关闭。

这里大概写下流程,下面有具体的调用堆栈

1 触发 ams.attachapplicaton---activitystack.minimalresumeactivitylocked---rootwindowcontainner--displaycontent

---wms.requestTraversal--mService.mAnimationHandler.post(mPerformSurfacePlacement);(post 一个runnable消息给wms)

2 启动

---rootwindowcontainer---performsurfaceplacementnotrace------apptransitioncontroller.applyanimations---

---windowcontainer.applyanimationunchecked -----surfaceanimator.startanimation--(创建leash然后Transaction.reparent(surface,leash))

---localanimationadapter(animationadapter的父类)---surfaceanimationrunner.startanimation--mChoreographer.postFramecallback

3 关闭

windowcontainer循环完后,调用wms的onAnimationfinished。

详细动画执行流程

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.SurfaceAnimationRunner.startAnimation(SurfaceAnimationRunner.java:139)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.LocalAnimationAdapter.startAnimation(LocalAnimationAdapter.java:55)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.SurfaceAnimator.startAnimation(SurfaceAnimator.java:160)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowContainer.startAnimation(WindowContainer.java:2128)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowState.startAnimation(WindowState.java:5222)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowState.startMoveAnimation(WindowState.java:5218)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowState.handleWindowMovedIfNeeded(WindowState.java:2090)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.DisplayContent.lambda$new8DisplayContent(DisplayContent.java:884)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.-$$LambdaDisplayContentqxt4izS31fb0LF2uo_OF9DMa7gc.accept(Unknown Source:4)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowContainer$ForAllWindowsConsumerWrapper.apply(WindowContainer.java:2003)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowContainer$ForAllWindowsConsumerWrapper.apply(WindowContainer.java:1993)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowState.applyInOrderWithImeWindows(WindowState.java:4672)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowState.forAllWindows(WindowState.java:4571)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1310)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.ActivityRecord.forAllWindowsUnchecked(ActivityRecord.java:3632)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.ActivityRecord.forAllWindows(ActivityRecord.java:3627)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1310)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1310)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1310)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.TaskDisplayArea.forAllWindows(TaskDisplayArea.java:511)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1310)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1310)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1310)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:1327)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.DisplayContent.applySurfaceChangesTransaction(DisplayContent.java:4010)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.RootWindowContainer.applySurfaceChangesTransaction(RootWindowContainer.java:1074)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.RootWindowContainer.performSurfacePlacementNoTrace(RootWindowContainer.java:854)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.RootWindowContainer.performSurfacePlacement(RootWindowContainer.java:811)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop(WindowSurfacePlacer.java:178)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:127)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:116)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.DisplayContent.layoutAndAssignWindowLayersIfNeeded(DisplayContent.java:3384)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.wm.WindowManagerService$H.handleMessage(WindowManagerService.java:5268)

01-01 14:48:34.775 1039 1153 I yang111 : at android.os.Handler.dispatchMessage(Handler.java:106)

01-01 14:48:34.775 1039 1153 I yang111 : at android.os.Looper.loop(Looper.java:223)

01-01 14:48:34.775 1039 1153 I yang111 : at android.os.HandlerThread.run(HandlerThread.java:67)

01-01 14:48:34.775 1039 1153 I yang111 : at com.android.server.ServiceThread.run(ServiceThread.java:44)

二 动画执行循环流程

01-01 14:39:38.477 1079 1150 I yang : at com.android.server.wm.SurfaceAnimationRunner.startAnimationLocked(SurfaceAnimationRunner.java:182)

01-01 14:39:38.477 1079 1150 I yang : at com.android.server.wm.SurfaceAnimationRunner.startPendingAnimationsLocked(SurfaceAnimationRunner.java:173)

01-01 14:39:38.477 1079 1150 I yang : at com.android.server.wm.SurfaceAnimationRunner.startAnimations(SurfaceAnimationRunner.java:248)

01-01 14:39:38.477 1079 1150 I yang : at com.android.server.wm.SurfaceAnimationRunner.lambda$9Wa9MhcrSX12liOouHtYXEkDU60(Unknown Source:0)

01-01 14:39:38.477 1079 1150 I yang : at com.android.server.wm.-$$Lambda$SurfaceAnimationRunner$9Wa9MhcrSX12liOouHtYXEkDU60.doFrame(Unknown Source:2)

01-01 14:39:38.477 1079 1150 I yang : at android.view.Choreographer$CallbackRecord.run(Choreographer.java:970)

01-01 14:39:38.477 1079 1150 I yang : at android.view.Choreographer.doCallbacks(Choreographer.java:796)

01-01 14:39:38.477 1079 1150 I yang : at android.view.Choreographer.doFrame(Choreographer.java:727)

01-01 14:39:38.477 1079 1150 I yang : at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)

01-01 14:39:38.477 1079 1150 I yang : at android.os.Handler.handleCallback(Handler.java:938)

01-01 14:39:38.477 1079 1150 I yang : at android.os.Handler.dispatchMessage(Handler.java:99)

01-01 14:39:38.477 1079 1150 I yang : at android.os.Looper.loop(Looper.java:223)

01-01 14:39:38.477 1079 1150 I yang : at android.os.HandlerThread.run(HandlerThread.java:67)

01-01 14:39:38.477 1079 1150 I yang : at com.android.server.ServiceThread.run(ServiceThread.java:44)

相关推荐
sunly_2 小时前
Flutter:AnimatedPadding动态修改padding
android·flutter
诸神黄昏EX2 小时前
Android 常用命令和工具解析之GPU相关
android
顾北川_野2 小时前
Android 布局菜单或按钮图标或Menu/Item设置可见和不可见
android
别拿曾经看以后~2 小时前
原生Android调用uniapp项目中的方法
android·vue.js·uni-app
Winston Wood2 小时前
Android Binder技术概览
android·binder·进程通信
踏雪羽翼2 小时前
android 使用实现音效--Equalizer
android·音效·eqequalizer·bassboost·presetreverb
老码沉思录2 小时前
Android开发实战班 - Android开发基础之 Kotlin语言基础与特性
android·微信·kotlin
峥嵘life3 小时前
Android adb shell dumpsys audio 信息查看分析详解
android·adb
standxy4 小时前
集成金蝶云星空数据至MySQL的完整案例解析
android·数据库·mysql