protected void updateSurface() {
    ...
    final ViewRootImpl viewRoot = getViewRootImpl();

    if (viewRoot == null) {
        return;
    }

    if (viewRoot.mSurface == null || !viewRoot.mSurface.isValid()) {
        notifySurfaceDestroyed();
        tryReleaseSurfaces();
        return;
    }
    int myWidth = mRequestedWidth;
    if (myWidth <= 0) myWidth = getWidth();
    int myHeight = mRequestedHeight;
    if (myHeight <= 0) myHeight = getHeight();

    final float alpha = getFixedAlpha();
    final boolean formatChanged = mFormat != mRequestedFormat;
    final boolean visibleChanged = mVisible != mRequestedVisible;
    final boolean alphaChanged = mSurfaceAlpha != alpha;
    final boolean creating = (mSurfaceControl == null || formatChanged || visibleChanged)
            && mRequestedVisible;
    final boolean sizeChanged = mSurfaceWidth != myWidth || mSurfaceHeight != myHeight;
    final boolean windowVisibleChanged = mWindowVisibility != mLastWindowVisibility;
    boolean redrawNeeded = false;
    getLocationInSurface(mLocation);
    final boolean positionChanged = mWindowSpaceLeft != mLocation[0]
        || mWindowSpaceTop != mLocation[1];
    final boolean layoutSizeChanged = getWidth() != mScreenRect.width()
        || getHeight() != mScreenRect.height();

    if (creating || formatChanged || sizeChanged || visibleChanged ||
            (mUseAlpha && alphaChanged) || windowVisibleChanged ||
            positionChanged || layoutSizeChanged) {
        ...
        try {
            mVisible = mRequestedVisible;
            mWindowSpaceLeft = mLocation[0];
            mWindowSpaceTop = mLocation[1];
            mSurfaceWidth = myWidth;
            mSurfaceHeight = myHeight;
            mFormat = mRequestedFormat;
            mLastWindowVisibility = mWindowVisibility;
            mTransformHint = viewRoot.getBufferTransformHint();
            ...
            if (creating) {
                updateOpaqueFlag();
                final String name = "SurfaceView[" + viewRoot.getTitle().toString() + "]";
                if (mUseBlastAdapter) {
                    createBlastSurfaceControls(viewRoot, name, geometryTransaction);
                } else {
                    mDeferredDestroySurfaceControl = createSurfaceControls(viewRoot, name);
                }
            } else if (mSurfaceControl == null) {
                return;
            }

Layer 的层次结构如下所示:

graph TD
  ViewRootImpl.mSurfaceControl
  --> ViewRootImpl.mBoundsLayer
  --> SurfaceView.mSurfaceControl
  
  SurfaceView.mSurfaceControl
  --> SurfaceView.mBlastSurfaceControl

  SurfaceView.mSurfaceControl
  --> SurfaceView.mBackgoundControl
            final boolean realSizeChanged = performSurfaceTransaction(viewRoot,
                    translator, creating, sizeChanged, hintChanged, geometryTransaction);
            final boolean redrawNeeded = sizeChanged || creating || hintChanged
                    || (mVisible && !mDrawFinished);
            try {
                SurfaceHolder.Callback[] callbacks = null;

                final boolean surfaceChanged = creating;
                if (mSurfaceCreated && (surfaceChanged || (!visible && visibleChanged))) {
                    mSurfaceCreated = false;
                    notifySurfaceDestroyed();
                }

                copySurface(creating /* surfaceControlCreated */, sizeChanged);
                if (visible && mSurface.isValid()) {
                    if (!mSurfaceCreated && (surfaceChanged || visibleChanged)) {
                        mSurfaceCreated = true;
                        mIsCreating = true;
                        if (callbacks == null) {
                            callbacks = getSurfaceCallbacks();
                        }
                        for (SurfaceHolder.Callback c : callbacks) {
                            c.surfaceCreated(mSurfaceHolder);
                        }
                    }
                    if (creating || formatChanged || sizeChanged
                            || visibleChanged || realSizeChanged) {
                        if (callbacks == null) {
                            callbacks = getSurfaceCallbacks();
                        }
                        for (SurfaceHolder.Callback c : callbacks) {
                            c.surfaceChanged(mSurfaceHolder, mFormat, myWidth, myHeight);
                        }
                    }
                    if (redrawNeeded) {
                        if (DEBUG) Log.i(TAG, System.identityHashCode(this) + " "
                                + "surfaceRedrawNeeded");
                        if (callbacks == null) {
                            callbacks = getSurfaceCallbacks();
                        }

                        mPendingReportDraws++;
                        viewRoot.drawPending();
                        SurfaceCallbackHelper sch =
                                new SurfaceCallbackHelper(this::onDrawFinished);
                        sch.dispatchSurfaceRedrawNeededAsync(mSurfaceHolder, callbacks);
                    }
                }
            } finally {
                mIsCreating = false;
                if (mSurfaceControl != null && !mSurfaceCreated) {
                    releaseSurfaces();
                }
            }
        } catch (Exception ex) {
            Log.e(TAG, "Exception configuring surface", ex);
        }
    }
}