背景:
以前分屏pip课程时候讲解过pip由小变大时候有使用到一个方式方式叫做同步事务,这个之前课程也讲解了他的使用方式和作用及表面原理,并没有深入到BLASTBufferQueue部分讲解。
刚好这次需要讲解BLASTBufferQueue的新特性,刚好以这个为案例进行分析。
服务端部分sync逻辑
回忆一下当时代码同步事务调用代码:
可以看到这里先调用了的是
SyncTransactionQueued.queue方法,传递的参数是WindowContainerTransaction类型,主要是记录某个WindowContainer的相关操作事务。
进行queue动作完成后,紧接着就是runInSync执行,这个方法参数非常关键,代表是一个同步事务等待同步后进行回调执行的部分,而且这个时候会有一个Transaction的参数,里面就包含了相关WindowContainer的绘制相关事务。
下面就来分析一下关键的queue方法:
/**
* Queues a sync transaction to be sent serially to WM.
*/
public void queue(WindowContainerTransaction wct) {
SyncCallback cb = new SyncCallback(wct);//基于wct入参创建一个SyncCallback
synchronized (mQueue) {
mQueue.add(cb);//添加到mQueue
if (mQueue.size() == 1) {
cb.send();//调用SyncCallback的send
}
}
}
// Must be sychronized on mQueue
void send() {
if (mLegacyTransition != null) {
} else {
mId = new WindowOrganizer().applySyncTransaction(mWCT, this);//这里直接调用了applySyncTransaction方法
}
}
这里applySyncTransaction入参有两个一个是最前面传递的windowcontainertransition和一个CallBack就是SyncCallback
下面是applySyncTransaction相关调用堆栈:
01-02 19:25:16.991 12004 12004 I lsm2222 : java.lang.Exception
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.window.WindowOrganizer.applySyncTransaction(WindowOrganizer.java:79)
01-02 19:25:16.991 12004 12004 I lsm2222 : at com.android.wm.shell.common.SyncTransactionQueue$SyncCallback.send(SyncTransactionQueue.java:42)
01-02 19:25:16.991 12004 12004 I lsm2222 : at com.android.wm.shell.common.SyncTransactionQueue.queue(SyncTransactionQueue.java:29)
01-02 19:25:16.991 12004 12004 I lsm2222 : at com.android.wm.shell.pip.PipTaskOrganizer.exitPip(PipTaskOrganizer.java:246)
01-02 19:25:16.991 12004 12004 I lsm2222 : at com.android.wm.shell.pip.phone.PipMotionHelper.expandLeavePip(PipMotionHelper.java:16)
01-02 19:25:16.991 12004 12004 I lsm2222 : at com.android.wm.shell.pip.phone.PipTouchHandler$PipMenuListener.onPipExpand(PipTouchHandler.java:5)
01-02 19:25:16.991 12004 12004 I lsm2222 : at com.android.wm.shell.pip.phone.PhonePipMenuController$$ExternalSyntheticLambda2.accept(Unknown Source:8)
01-02 19:25:16.991 12004 12004 I lsm2222 : at java.util.ArrayList.forEach(ArrayList.java:1262)
01-02 19:25:16.991 12004 12004 I lsm2222 : at com.android.wm.shell.pip.phone.PipMenuView$$ExternalSyntheticLambda7.run(R8$$SyntheticClass:54)
01-02 19:25:16.991 12004 12004 I lsm2222 : at com.android.wm.shell.pip.phone.PipMenuView$4.onAnimationEnd(PipMenuView.java:55)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:600)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.animation.AnimatorSet.endAnimation(AnimatorSet.java:1301)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.animation.AnimatorSet.doAnimationFrame(AnimatorSet.java:1086)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:307)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.animation.AnimationHandler.-$$Nest$mdoAnimationFrame(Unknown Source:0)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:86)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1229)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.view.Choreographer.doCallbacks(Choreographer.java:899)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.view.Choreographer.doFrame(Choreographer.java:827)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.os.Handler.handleCallback(Handler.java:942)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 19:25:16.991 12004 12004 I lsm2222 : at android.os.Looper.loopOnce(Looper.java:201)
01-02 19:25:16.991 12004 12004 I lsm2222