Android4.4 Surface从java到native的创建过程

研究Surface的创建流程需要一个精简的流程,不然跳转太多,脑子都乱了。先讲一个大致的过程:ViewRootImpl在构造时会new一个Surface,在relayoutWindow方法中传入mSurface,这个跨进程的调用会在binderserver端新构造一个Surface,在WMS中构造SurfaceControl,然后将生成的SurfaceControl传入binderserver端的Surface,最后把这个binderserver端的Surface返回到调用进程,即ViewRootImpl中。下面是调用关键方法:

1.ViewRootImpl的relayoutWindow方法中调用Session的relayout方法来设置mSurface
 private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility,
            boolean insetsPending) throws RemoteException {
......
        int relayoutResult = mWindowSession.relayout(
                mWindow, mSeq, params,
                (int) (mView.getMeasuredWidth() * appScale + 0.5f),
                (int) (mView.getMeasuredHeight() * appScale + 0.5f),
                viewVisibility, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0,
                mWinFrame, mPendingOverscanInsets, mPendingContentInsets, mPendingVisibleInsets,
                mPendingConfiguration, mSurface);
......
        return relayoutResult;
    }

调用mWindowSession的relayout方法,注意这是个binder调用。

2.onTranct中返回一个新构造的Surface

case TRANSACTION_relayout:
{
......
android.view.Surface _arg12;
_arg12 = new android.view.Surface();//构造一个新的Surface
int _result = this.relayout(_arg0, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12);
......
if ((_arg12!=null)) {
reply.writeInt(1);
_arg12.writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
}
return true;
}

3.在Session调用WMS的relayout方法

    public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
            int requestedWidth, int requestedHeight, int viewFlags,
            int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
            Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
        int res = mService.relayoutWindow(this, window, seq, attrs,
                requestedWidth, requestedHeight, viewFlags, flags,
                outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
                outConfig, outSurface);
        return res;
    }

4.WMS的relayout方法中构造SurfaceControl,并用这个SurfaceControl构造传入的Surface

SurfaceControl surfaceControl = winAnimator.createSurfaceLocked();//创建SurfaceControl
                    if (surfaceControl != null) {
                        outSurface.copyFrom(surfaceControl);//通过SurfaceControl设置Surface
                        if (SHOW_TRANSACTIONS) Slog.i(TAG,
                                "  OUT SURFACE " + outSurface + ": copied");
                    } else {
                        // For some reason there isn't a surface.  Clear the
                        // caller's object so they see the same state.
                        outSurface.release();
                    }
5.winAnimator的createSurfaceLocked方法中生成SurfaceControl 
  mSurfaceControl = new SurfaceControl(
                        mSession.mSurfaceSession,
                        attrs.getTitle().toString(),
                        w, h, format, flags);
6.将生成的Surface传回ViewRootImpl
public int relayout(android.view.IWindow window, int seq, android.view.WindowManager.LayoutParams attrs, int requestedWidth, int requestedHeight, int viewVisibility, int flags, android.graphics.Rect outFrame, android.graphics.Rect outOverscanInsets, android.graphics.Rect outCo
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值