Waiting for drawn Window耗时过长流程梳理

Android6.0 亮屏灭屏流程(DisplayPowerController、WMS)(一)WMS绘制 亮屏、灭屏流程整个流程涉及的模块比较多,包括PowerManagerService、DisplayPowerControl、WMS、AMS。因此在分析完WMS之后,我们把这块也分析下。 DisplayPowerControl 我们知道灭屏流程的发起是在PowerManagerService中,会通过updatePowerState函数调用updateDisplayPowerStateL 阅读详情

 存在一个问题:负载指纹响应时间衰退达到1秒多,从log中看Waiting for drawn Window 耗时太长

Line 3204: 08-14 14:44:45.929433  1100  5600 I PowerManagerService: Waking up from sleep (uid=10028 reason=android.policy:FINGERPRINT)...
Line 3211: 08-14 14:44:45.939175  1100  1135 I DisplayPowerController: Blocking screen on until initial contents have been drawn.
///Launcher 处于DRAW_PENDING 状态,这是一个surface已经创建但是Window还没draw的状态
Line 3250: 08-14 14:44:46.462380  1100  1121 I WindowManager: Waiting for drawn Window{f9de4b3 u0  com.android.launcher3/com.android.launcher3.Launcher}: removed=false visible=true mHasSurface=true drawState=1
Line 3251: 08-14 14:44:46.462434  1100  1121 I WindowManager: Waiting for drawn Window{18b56d9 u0 StatusBar}: removed=false visible=true mHasSurface=true drawState=1
///StatusBar HAS_DRAWN 完成绘制
Line 3276: 08-14 14:44:46.757318  1100  1176 I WindowManager: Waiting for drawn Window{18b56d9 u0 StatusBar}: removed=false visible=true mHasSurface=true drawState=4
    ....   
///Launcher 绘制完成持续时间比较久,从14:44:46.462380持续到14:44:47.221558,耗时接近800毫秒
Line 3298: 08-14 14:44:47.221558  1100  1176 I WindowManager: Waiting for drawn Window{f9de4b3 u0  com.android.launcher3/com.android.launcher3.Launcher}: removed=false visible=true mHasSurface=true drawState=4
     08-14 14:44:47.221628  1100  1176 D WindowManager: Window drawn win=Window{f9de4b3 u0 com.android.launcher3/com.android.launcher3.Launcher}
     08-14 14:44:47.221644  1100  1176 D WindowManager: All windows drawn!
     08-14 14:44:47.252180  1100  1135 I DisplayPowerController: Unblocked screen on after 1313 ms
     ///这一次power screen on 耗时1.33S
     08-14 14:44:47.257309  1100  1135 W PowerManagerService: Screen on took 1330 ms

 如上log中drawstate有五个状态,一般是从DRAW_PENDING 开始等待到HAS_DRAWN这一段耗时太长。

/frameworks/base/services/core/java/com/android/server/wm/WindowStateAnimator.java
    /** This is set when there is no Surface */
    static final int NO_SURFACE = 0;
    /** This is set after the Surface has been created but before the window has been drawn. During
     * this time the surface is hidden. */
    static final int DRAW_PENDING = 1;
    /** This is set after the window has finished drawing for the first time but before its surface
     * is shown.  The surface will be displayed when the next layout is run. */
    static final int COMMIT_DRAW_PENDING = 2;
    /** This is set during the time after the window's drawing has been committed, and before its
     * surface is actually shown.  It is used to delay showing the surface until all windows in a
     * token are ready to be shown. */
    static final int READY_TO_SHOW = 3;
    /** Set when the window has been shown in the screen the first time. */
    static final int HAS_DRAWN = 4;

往下再看一下DRAW_PENDING和HAS_DRAWN分别是在哪边赋值的。

/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java

    void waitForAllWindowsDrawn() {
        final WindowManagerPolicy policy = mService.mPolicy;
        forAllWindows(w -> {
            final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
            if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
                w.mWinAnimator.mDrawState = DRAW_PENDING;
                // Force add to mResizingWindows.
                w.mLastContentInsets.set(-1, -1, -1, -1);
                mService.mWaitingForDrawn.add(w);
            }
        }, true /* traverseTopToBottom */);
    }

三个调用的点

1.MSG_KEYGUARD_DRAWN_COMPLETE,

2.MSG_KEYGUARD_DRAWN_TIMEOUT,

3.screenTurningOn

----->PhoneWindowManger.finishKeyguardDrawn----->WindowManagerService.waitForAllWindowsDrawn---->DisplayContent.waitForAllWindowsDrawn

在WindowManagerService的waitForAllWindowsDrawn中

        @Override
        public void waitForAllWindowsDrawn(Runnable callback, long timeout) {
            boolean allWindowsDrawn = false;
            synchronized (mWindowMap) {
                mWaitingForDrawnCallback = callback;
                 //即对应的DisplayContent的waitForAllWindowsDrawn
                getDefaultDisplayContentLocked().waitForAllWindowsDrawn();
//AnimationThread 线程post了一个mPerformSurfacePlacement Runnable,
//mAnimationHandler收到这个消息后,performSurfacePlacement()方法就会 
//执行,接着调用 performSurfacePlacementLoop->RootWindowContainer.performSurfacePlacement,
//AnimationThread 继承 HandlerThread 一个带Looper 的Thread
                mWindowPlacerLocked.requestTraversal();
                mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT);
                if (mWaitingForDrawn.isEmpty()) {
                    allWindowsDrawn = true;
                } else {
                    mH.sendEmptyMessageDelayed(H.WAITING_FOR_DRAWN_TIMEOUT, timeout);
                    checkDrawnWindowsLocked();
                }
            }
            if (allWindowsDrawn) {
                callback.run();
            }
        }
//WindowSurfacePlacer.java

    void requestTraversal() {
        if (!mTraversalScheduled) {
            mTraversalScheduled = true;
            mService.mAnimationHandler.post(mPerformSurfacePlacement);
        }
    }

其中等待绘制的界面不为空走checkDrawnWindowsLocked

    void checkDrawnWindowsLocked() {
        if (mWaitingForDrawn.isEmpty() || mWaitingForDrawnCallback == null) {
            return;
        }
        for (int j = mWaitingForDrawn.size() - 1; j >= 0; j--) {
            WindowState win = mWaitingForDrawn.get(j);
            if (DEBUG_SCREEN_ON) Slog.i(TAG_WM, "Waiting for drawn " + win +
                    ": removed=" + win.mRemoved + " visible=" + win.isVisibleLw() +
                    " mHasSurface=" + win.mHasSurface +
                    " drawState=" + win.mWinAnimator.mDrawState);
            if (win.mRemoved || !win.mHasSurface || !win.mPolicyVisibility) {
                // Window has been removed or hidden; no draw will now happen, so stop waiting.
                if (DEBUG_SCREEN_ON) Slog.w(TAG_WM, "Aborted waiting for drawn: " + win);
                mWaitingForDrawn.remove(win);
            } else if (win.hasDrawnLw()) {//即等于HAS_DRAWN状态会将win删除
                // Window is now drawn (and shown).
                if (DEBUG_SCREEN_ON) Slog.d(TAG_WM, "Window drawn win=" + win);
                mWaitingForDrawn.remove(win);
            }
        }
        if (mWaitingForDrawn.isEmpty()) {
            if (DEBUG_SCREEN_ON) Slog.d(TAG_WM, "All windows drawn!");
            mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT);
            mH.sendEmptyMessage(H.ALL_WINDOWS_DRAWN);
        }
    }

而HAS_DRAWN在frameworks/base/services/core/java/com/android/server/wm/WindowState.java

    // This must be called while inside a transaction.
    boolean performShowLocked() {
        if (isHiddenFromUserLocked()) {
            if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
            hideLw(false);
            return false;
        }

        logPerformShow("performShow on ");

        final int drawState = mWinAnimator.mDrawState;
        if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
                && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
            mAppToken.onFirstWindowDrawn(this, mWinAnimator);
        }

        if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
            return false;
        }

        logPerformShow("Showing ");

        mService.enableScreenIfNeededLocked();
        mWinAnimator.applyEnterAnimationLocked();

        // Force the show in the next prepareSurfaceLocked() call.
        mWinAnimator.mLastAlpha = -1;
        if (DEBUG_ANIM) Slog.v(TAG,
                "performShowLocked: mDrawState=HAS_DRAWN in " + this);
        mWinAnimator.mDrawState = HAS_DRAWN;
        mService.scheduleAnimationLocked();

        if (mHidden) {
            mHidden = false;
            final DisplayContent displayContent = getDisplayContent();

            for (int i = mChildren.size() - 1; i >= 0; --i) {
                final WindowState c = mChildren.get(i);
                if (c.mWinAnimator.mSurfaceController != null) {
                    c.performShowLocked();
                    // It hadn't been shown, which means layout not performed on it, so now we
                    // want to make sure to do a layout.  If called from within the transaction
                    // loop, this will cause it to restart with a new layout.
                    if (displayContent != null) {
                        displayContent.setLayoutNeeded();
                    }
                }
            }
        }

        if (mAttrs.type == TYPE_INPUT_METHOD) {
            getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
        }

        return true;
    }

HAS_DRAWN打印的堆栈 

11-07 07:34:46.279 V/WindowManager( 1039): performShowLocked: mDrawState=HAS_DRAWN in Window{b848e17 u0 StatusBar}
11-07 07:34:46.279 V/WindowManager( 1039): java.lang.Throwable
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowState.performShowLocked(WindowState.java:3995)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowStateAnimator.commitFinishDrawingLocked(WindowStateAnimator.java:357)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.DisplayContent.lambda$new$8$DisplayContent(DisplayContent.java:843)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.-$$Lambda$DisplayContent$qxt4izS31fb0LF2uo_OF9DMa7gc.accept(Unknown Source:4)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowContainer$ForAllWindowsConsumerWrapper.apply(WindowContainer.java:1184)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowContainer$ForAllWindowsConsumerWrapper.apply(WindowContainer.java:1174)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowState.applyInOrderWithImeWindows(WindowState.java:4194)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowState.forAllWindows(WindowState.java:4093)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:883)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:883)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.DisplayContent.forAllWindows(DisplayContent.java:2149)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:900)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.DisplayContent.applySurfaceChangesTransaction(DisplayContent.java:3778)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.RootWindowContainer.applySurfaceChangesTransaction(RootWindowContainer.java:834)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.RootWindowContainer.performSurfacePlacementNoTrace(RootWindowContainer.java:611)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.RootWindowContainer.performSurfacePlacement(RootWindowContainer.java:568)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop(WindowSurfacePlacer.java:159)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:105)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:95)
11-07 07:34:46.279 V/WindowManager( 1039): 	at com.android.server.wm.WindowSurfacePlacer.lambda$new$0$WindowSurfacePlacer(WindowSurfacePlacer.java:62)

WindowAnimator.animate----->WindowContainer.checkAppWindowsReadyToShow--->AppWindowToken.checkAppWindowsReadyToShow--->AppWindowToken.showAllWindowsLocked---->WindowState.performShowLocked

    /** Checks if all windows in an app are all drawn and shows them if needed. */
    void checkAppWindowsReadyToShow() {
        for (int i = mChildren.size() - 1; i >= 0; --i) {
            final WindowContainer wc = mChildren.get(i);
            wc.checkAppWindowsReadyToShow();
        }
    }
    /**
     * DO NOT HOLD THE WINDOW MANAGER LOCK WHILE CALLING THIS METHOD. Reason: the method closes
     * an animation transaction, that might be blocking until the next sf-vsync, so we want to make
     * sure other threads can make progress if this happens.
     */
    private void animate(long frameTimeNs) {
....
        synchronized (mService.mWindowMap) {
             if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION animate");
             mService.openSurfaceTransaction();
.....
                final int numDisplays = mDisplayContentsAnimators.size();
                for (int i = 0; i < numDisplays; i++) {
                    final int displayId = mDisplayContentsAnimators.keyAt(i);
                    final DisplayContent dc = mService.mRoot.getDisplayContent(displayId);
                    DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i);

                    final ScreenRotationAnimation screenRotationAnimation =
                            displayAnimator.mScreenRotationAnimation;
                    if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
                        if (screenRotationAnimation.stepAnimationLocked(mCurrentTime)) {
                            setAnimating(true);
                        } else {
                            mBulkUpdateParams |= SET_UPDATE_ROTATION;
                            screenRotationAnimation.kill();
                            displayAnimator.mScreenRotationAnimation = null;

                            //TODO (multidisplay): Accessibility supported only for the default
                            // display.
                            if (accessibilityController != null && dc.isDefaultDisplay) {
                                // We just finished rotation animation which means we did not
                                // announce the rotation and waited for it to end, announce now.
                                accessibilityController.onRotationChangedLocked(
                                        mService.getDefaultDisplayContentLocked());
                            }
                        }
                    }
                    // Update animations of all applications, including those
                    // associated with exiting/removed apps
                    ++mAnimTransactionSequence;
                    dc.updateWindowsForAnimator(this);
                    dc.updateWallpaperForAnimator(this);
                    dc.prepareSurfaces();
                }
....
                for (int i = 0; i < numDisplays; i++) {
                    final int displayId = mDisplayContentsAnimators.keyAt(i);
                    final DisplayContent dc = mService.mRoot.getDisplayContent(displayId);

                    dc.checkAppWindowsReadyToShow();

                    final ScreenRotationAnimation screenRotationAnimation =
                            mDisplayContentsAnimators.valueAt(i).mScreenRotationAnimation;
                    if (screenRotationAnimation != null) {
                        screenRotationAnimation.updateSurfaces(mTransaction);
                    }
                    orAnimating(dc.getDockedDividerController().animate(mCurrentTime));
                    //TODO (multidisplay): Magnification is supported only for the default display.
                    if (accessibilityController != null && dc.isDefaultDisplay) {
                        accessibilityController.drawMagnifiedRegionBorderIfNeededLocked();
                    }
                }
                if (!mAnimating) {
                    cancelAnimation();
                }

                if (mService.mWatermark != null) {
                    mService.mWatermark.drawIfNeeded();
                }

                SurfaceControl.mergeToGlobalTransaction(mTransaction);
           }finally {
                  mService.closeSurfaceTransaction("WindowAnimator");
                  if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION animate");
              }
....
}
....

   }

READY_TO_SHOW的赋值点

1.WindowSurfacePlacer.performSurfacePlacementLoop(){ 
  mService.mRoot.performSurfacePlacement(recoveringMemory);
} 
2.DisplayContent.updateFocusedWindowLocked(){
   mWmService.mRoot.performSurfacePlacement(false);
}
///
RootWindowContainer.performSurfacePlacement(boolean recoveringMemory)-->
RootWindowContainer.performSurfacePlacementNoTrace{ applySurfaceChangesTransaction(recoveringMemory);}
-->
RootWindowContainer.applySurfaceChangesTransaction{
830          final int count = mChildren.size();
831          for (int j = 0; j < count; ++j) {
832              final DisplayContent dc = mChildren.get(j);
833              dc.applySurfaceChangesTransaction(recoveringMemory);
834          }
}
-->
DisplayContent.applySurfaceChangesTransaction{forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);}
-->
DisplayContent.mApplySurfaceChangesTransaction = w -> 
-->
WindowStateAnimator.commitFinishDrawingLocked{ mDrawState = READY_TO_SHOW;}
--->
WindowState.performShowLocked { mDrawState=HAS_DRAWN }--->

 READY_TO_SHOW打印的堆栈

11-07 07:34:46.274 I/WindowManager( 1039): commitFinishDrawingLocked: mDrawState=READY_TO_SHOW Surface(name=StatusBar)/@0x1e834ef
11-07 07:34:46.274 I/WindowManager( 1039): java.lang.Throwable
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowStateAnimator.commitFinishDrawingLocked(WindowStateAnimator.java:350)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.DisplayContent.lambda$new$8$DisplayContent(DisplayContent.java:843)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.-$$Lambda$DisplayContent$qxt4izS31fb0LF2uo_OF9DMa7gc.accept(Unknown Source:4)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowContainer$ForAllWindowsConsumerWrapper.apply(WindowContainer.java:1184)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowContainer$ForAllWindowsConsumerWrapper.apply(WindowContainer.java:1174)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowState.applyInOrderWithImeWindows(WindowState.java:4194)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowState.forAllWindows(WindowState.java:4093)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:883)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:883)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.DisplayContent.forAllWindows(DisplayContent.java:2149)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowContainer.forAllWindows(WindowContainer.java:900)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.DisplayContent.applySurfaceChangesTransaction(DisplayContent.java:3778)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.RootWindowContainer.applySurfaceChangesTransaction(RootWindowContainer.java:834)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.RootWindowContainer.performSurfacePlacementNoTrace(RootWindowContainer.java:611)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.RootWindowContainer.performSurfacePlacement(RootWindowContainer.java:568)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop(WindowSurfacePlacer.java:159)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:105)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:95)
11-07 07:34:46.274 I/WindowManager( 1039): 	at com.android.server.wm.WindowSurfacePlacer.lambda$new$0$WindowSurfacePlacer(WindowSurfacePlacer.java:62)

一个有锁屏界面按Power键亮屏的界面绘制流程log 

08-21 03:04:57.616 I/PowerManagerService( 1025): Waking up from sleep (uid=1000 reason=android.policy:POWER)...
08-21 03:04:57.619 I/DisplayPowerController( 1025): Blocking screen on until initial contents have been drawn.
08-21 03:04:57.703 I/WindowManager( 1025): Waiting for drawn Window{94a4fbd u0 StatusBar}: removed=false visible=true mHasSurface=true drawState=1
....
08-21 03:04:57.736 I/WindowManager( 1025): Waiting for drawn Window{94a4fbd u0 StatusBar}: removed=false visible=true mHasSurface=true drawState=1
08-21 03:04:57.746 D/WindowManager( 1025): finishDrawingWindow: Window{c72bd2b u0 SmartPanel_SliderView} mDrawState=HAS_DRAWN
08-21 03:04:57.765 D/WindowManager( 1025): finishDrawingWindow: Window{94a4fbd u0 StatusBar} mDrawState=DRAW_PENDING
08-21 03:04:57.766 W/WindowManager( 1025): setLayoutNeeded: callers=com.android.server.wm.WindowState.setDisplayLayoutNeeded:2312 com.android.server.wm.WindowManagerService.finishDrawingWindow:2441 com.android.server.wm.Session.finishDrawing:282 
08-21 03:04:57.766 V/WindowManager( 1025): performSurfacePlacementInner: entry. Called by com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop:208 com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement:156 com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement:146 
08-21 03:04:57.766 I/WindowManager( 1025): >>> OPEN TRANSACTION performLayoutAndPlaceSurfaces
....
08-21 03:04:57.772 I/WindowManager( 1025): commitFinishDrawingLocked: mDrawState=READY_TO_SHOW Surface(name=StatusBar)/@0x6490d9c
08-21 03:04:57.772 V/WindowManager( 1025): performShow on Window{94a4fbd u0 StatusBar}: mDrawState=READY_TO_SHOW readyForDisplay=true starting=false during animation: policyVis=true parentHidden=false tok.hiddenRequested=false tok.hidden=false animationSet=false tok animating=false Callers=com.android.server.wm.WindowState.performShowLocked:3891
....
08-21 03:04:57.773 V/WindowManager( 1025): applyAnimation: win=WindowStateAnimator{f7df172 StatusBar} anim=-1 attr=0xffffffff a=null transit=3 isEntrance=true Callers 
08-21 03:04:57.773 V/WindowManager( 1025): performShowLocked: mDrawState=HAS_DRAWN in Window{94a4fbd u0 StatusBar}
...
08-21 03:04:57.776 I/WindowManager( 1025): <<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces
...
08-21 03:04:57.777 I/WindowManager( 1025): Waiting for drawn Window{94a4fbd u0 StatusBar}: removed=false visible=true mHasSurface=true drawState=4
08-21 03:04:57.885 W/PowerManagerService( 1025): Screen on took 278 ms

 log中>>> OPEN TRANSACTION performLayoutAndPlaceSurfaces和<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces对应的是

/frameworks/base/services/core/java/com/android/server/wm/RootWindowContainer.java
  void performSurfacePlacement(boolean recoveringMemory) {
.....

        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
        mService.openSurfaceTransaction();
        try {
            applySurfaceChangesTransaction(recoveringMemory, defaultDw, defaultDh);
        } catch (RuntimeException e) {
            Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
        } finally {
            mService.closeSurfaceTransaction("performLayoutAndPlaceSurfaces");
            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                    "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
        }
....
        mService.mAnimator.executeAfterPrepareSurfacesRunnables();

        final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;

        // If we are ready to perform an app transition, check through all of the app tokens to be
        // shown and see if they are ready to go.
        if (mService.mAppTransition.isReady()) {
            // This needs to be split into two expressions, as handleAppTransitionReadyLocked may
            // modify dc.pendingLayoutChanges, which would get lost when writing
            // defaultDisplay.pendingLayoutChanges |= handleAppTransitionReadyLocked()
            final int layoutChanges = surfacePlacer.handleAppTransitionReadyLocked();
            defaultDisplay.pendingLayoutChanges |= layoutChanges;
            if (DEBUG_LAYOUT_REPEATS)
                surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
                        defaultDisplay.pendingLayoutChanges);
        }
....

....

 }
ViewRootImpl.scheduleTraversals(-->
mTraversalRunnable-->
ViewRootImpl.performTraversals-->
ViewRootImpl.performDraw--->
ViewRootImpl.pendingDrawFinished---->
ViewRootImpl.reportDrawFinished--->
mWindowSession.finishDrawing(mWindow)--->
Session.finishDrawing---->
WindowManagerService.finishDrawingWindow--->

    void finishDrawingWindow(Session session, IWindow client) {
        final long origId = Binder.clearCallingIdentity();
        try {
            synchronized (mWindowMap) {
                WindowState win = windowForClientLocked(session, client, false);
                if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "finishDrawingWindow: " + win + " mDrawState="
                        + (win != null ? win.mWinAnimator.drawStateToString() : "null"));
                if (win != null && win.mWinAnimator.finishDrawingLocked()) {
                    if ((win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
                        win.getDisplayContent().pendingLayoutChanges |=
                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
                    }
                    win.setDisplayLayoutNeeded();
                    mWindowPlacerLocked.requestTraversal();
                }
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
    }

 

Android之WMS篇(五)窗口绘制的过程 WindowSurfaceController才是用来绘制的的SurfaceControl.前边的博客中讲过在addChild的过程中Window会创建对应的SurfaceControll这些SurfaceControl都是CONTAINER类型,只有这里的WindowSurfaceController它是BLAST用于绘制的。在上篇博客中提到WMS的addWindow方法中将Window对应的WindowToken和WindowState挂载到窗口层级树上,它们只是内存中的对象并没有做窗口绘制的动作。 阅读详情

相关推荐

Android rotation 转屏过程分析

最近刚好解了几个转屏的bug。刚好将转屏的这一部分代码简单分析了一下,  转屏的代码逻辑主要在WMS(窗口管理)这一块。 整个转屏过程可以分为以下几个步骤: 1。 2。 3。 下面是调用的流程图   一开始当然是Sensor 从驱动传上来值,然后上层来判断要不要转屏, 这部分代码位WindowOrientationListener, WindowOr

yunnywucy的专栏 3326

Android Framework(六)WMS-窗口显示流程——窗口内容绘制与显示

这个流程触发的地方非常多,只是当前 finishDrawingWindow 会主动触发一次罢了。这一部分的逻辑有点绕,不过目前分析的是主流程,所以这块逻辑以上的描述当黑盒理解这段的调用: View 绘制结束后就会在 4.2 出触发 4.1 内部的执行,进入触发 finishDrawingWindow 流程即可。这一步执行完后,应用端就可以开始绘制 View 树了,绘制完成后,需要把内容显示到屏幕上,也就是现在这个 Surface ,这一步就是本篇分析的内容:finishDrawingWindow 流程。

芸兮的博客 3690

AI漫剧制作全流程:从提示词工程到视频剪辑的实战指南

在人工智能内容生成领域,提示词工程是连接人类创意与机器执行的核心桥梁。其原理在于将自然语言指令转化为模型可解析的向量表示,通过控制生成过程中的随机性,实现稳定、可控的输出。这项技术的价值在于大幅降低了视觉内容创作的门槛,使非专业用户也能高效生产符合预期的图像与视频。在漫画、短视频、动态叙事等应用场景中,稳定的角色一致性和画面连贯性是关键挑战。本文聚焦AI漫剧制作,深入拆解如何通过结构化分镜脚本、精准的视觉词汇选择以及Stable Diffusion等工具的组合应用,构建一套可复用、可迭代的创作工作流,并特别

weixin_30896825的博客 561

Android 7.1 GUI系统-窗口管理WMS-Surface管理(四)

Surface的管理 Surface是窗口能真正显示到物理屏幕上的基础,由surfaceflinger管理,可以通过WindowStateAnimator.java中的变量mDrawState来查看每个窗口相关的surface的状态。 surface有5中状态: WindowStateAnimator.java //Surface还没有创建。 staticfinal int NO_SUR

lin20080410的专栏 4433

【信息科学与工程学】【数据中心】【智算中心】第三十篇 智算中心建设05

编号类型领域子领域问题问题类型·子问题详细的数学分析(逐步推理的数学表达式 + 组合数学约束方程式)参数列表及数值范围及边界条件关联知识加工工具及软硬件及机床装备及部署模式N-3511实施智算中心空调冷媒管焊接时未抽真空导致冰堵管内残留水分结冰堵塞膨胀阀,制冷失效可靠性·Vacuum Not Drawn · 实施Step1: 冰堵概率 Pblock​=0.8,制冷量降为0。组合数学约束:系统可用性要求 A>0.999,若冰堵导致停机 Trepair​=4h,MTBF=1000h,则 A=1−4/1000=0

weixin_49199313的博客 313

新手必看!BUUCTF-PWN题实战:从零搭建Kali环境到成功RIP栈溢出

本文为CTF二进制安全新手提供了一份详实的BUUCTF-PWN入门指南。内容涵盖从零搭建Kali Linux环境、安装配置pwntools等核心工具,到深入浅出地讲解栈溢出原理与汇编基础,并手把手带领读者完成一道名为“rip”的经典栈溢出题目实战,成功利用漏洞获取系统权限。

t8u9v0w1x的博客 508

Android T startingwindow流程梳理

startingwindow的一些流程梳理

yimelancholy的博客 7216

Windows加域迁移避坑指南:Profwiz工具实战中的5个常见问题与解决方案

本文详细解析了使用Profwiz工具进行Windows加域迁移时的5个常见问题及解决方案,包括临时配置文件生成、密码策略冲突、SID冲突等。通过实战案例和优化技巧,帮助IT运维团队高效完成账户配置文件迁移,确保Active Directory环境下的数据完整性和权限无缝衔接。

q9r0s的博客 535

Stable Diffusion 提示词工程:从结构、权重到CFG的全链路实战指南

提示词工程(Prompt Engineering)是生成式AI落地的核心能力,本质是理解大模型文本编码器(如CLIP)如何将自然语言映射为潜在空间语义。其原理根植于token位置加权、语法依存结构与扩散过程中的噪声引导机制。技术价值在于提升生成稳定性、细节可控性与跨模型复用性,广泛应用于AIGC内容生产、产品原型设计、营销素材批量生成等场景。本文聚焦Stable Diffusion生态,系统拆解提示词结构设计、正负向权重配置、标点语义功能及CFG Scale调优逻辑,深度融合AI提示工程与实际图像生成效果验

weixin_30603633的博客 423

从零到一:基于JasperGold的FPV实战入门与避坑指南

本文详细介绍了基于JasperGold的形式化验证(FPV)实战入门指南,涵盖环境搭建、SVA断言编写、TCL脚本调试等关键步骤。通过实际案例解析,帮助IC设计工程师掌握FPV技术,有效验证RTL设计中的复杂逻辑和corner case,提升验证效率与质量。

weixin_30899023的博客 387

SAP 合并报表(EC-CS)完整方法论 + 全业务操作步骤

SAP合并报表(EC-CS)方法论与操作指南摘要 SAP EC-CS模块提供完整的集团合并解决方案,其核心方法论基于会计准则和集团管控逻辑,通过6大维度构建标准化合并体系:组织架构标准化、数据采集标准化、外币换算规则化、内部交易自动化抵消、股权与商誉规范化、报表出具灵活化。 实施过程分为两个阶段: 上线前配置阶段(12个步骤):包括合并架构搭建、科目表配置、外币规则设定、抵消规则定义等基础工作 日常操作阶段(10个步骤):涵盖数据报送、外币换算、内部对账、自动抵消、调整分录等月结流程 系统优势包括: 支持多

金牌架构师 1384

binyuan_krea2_v2.5:ComfyUI部署与SDXL Turbo调参

Stable Diffusion 生态中,底模决定了生成模型的基本能力,而垂直微调模型则让特定场景的输出更稳定。SDXL Turbo 通过对抗性蒸馏,将采样步数压缩至 1-4 步,同时需要极低的 CFG 值,这与传统 SDXL 模型 20-30 步、CFG 6-8 的使用习惯完全不同。在 ComfyUI 中部署这类 turbo 底模时,正确的参数配置是出图质量的关键。binyuan_krea2_v2.5 作为社区热门的亚洲人像微调模型,结合了 SDXL Turbo 的高速生成优势与亚洲人像的稳定性,但只有理

weixin_34319111的博客 454

Qt Creator 启动慢、卡顿、无响应 终极解决教程

<think>我们需根据内容生成≤150字的摘要。摘要要涵盖问题、原因、解决方案和效果。注意字数限制。</think>Qt Creator启动慢、卡顿、无响应,主因是配置文件QtCreator.ini膨胀至数十MB(正常<100KB)。删除%APPDATA%\QtProject下的膨胀配置、崩溃备份及qtcreator.db即可,启动从几十秒降至几秒,内存占用恢复正常。辅助优化:关闭有道词典取词、禁用无用插件、调整clangd设置。定期检查配置文件大小,避免多版本共用配置。

Qt历险记,专注Qt技术,三年医疗设备研发经验,1年机器视觉研发经验,半年柔性传感研发经验。 89

本地部署AI数字人:从Stable Diffusion到SadTalker的完整技术栈实践

AI图像生成与视频合成技术正推动数字人内容创作的普及。其核心原理基于深度学习模型,通过学习海量数据,实现从文本描述生成高真实感图像,并驱动静态图像生成口型同步的动态视频。这项技术的价值在于大幅降低了高质量视觉内容的生产门槛,为个性化内容创作、虚拟形象打造和教育视频制作等场景提供了高效工具。通过整合如Stable Diffusion和SadTalker等开源模型,开发者可以在本地构建完整的生成流水线。本文聚焦于实现这一目标的具体路径,详细拆解了包括模型选择、本地部署、API集成与批量处理在内的全链路实践方案,

weixin_34221036的博客 373

【Python办公】剪贴板记录工具(记录文本 + 图片防重复)

本文介绍了一个用Python开发的剪贴板记录工具,能够自动记录复制过的文本和图片内容。该工具使用tkinter构建GUI界面,通过后台线程实时监控剪贴板变化,具有文本记录、图片保存(自动去重)功能。核心代码采用pyperclip访问剪贴板,PIL处理图片,hashlib计算图片哈希值实现去重。运行程序后,文本内容直接显示在界面,图片保存为PNG文件并记录路径。工具还提供清空历史记录功能,适合日常办公中需要追踪剪贴板历史的使用场景。

weixin_42636075的博客 244

matlab RANSAC拟合圆柱【2025最新版】

RANSAC拟合圆柱

点云侠的博客 3140

黑屏分析~

这里对应的Window为应用界面,上面信息描述了该窗口的基本信息,重点需要关注mDrawState=HAS_DRAWN,mDrawState为窗口的绘制状态,HAS_DRAWN表示WMS已经完成该窗口的显示流程。当一个窗口刚刚被WMS执行addWindow()方法创建的时候,WindowStateAnimator在WindowState的构造函数中一起被创建,在relayoutWindow之前,窗口是没有Surface的,所以不可能被显示出来,此时状态就是NO_SURFACE。请求添加窗口记录,会在。

qq_37721987的博客 863

【机器学习|评价指标8】混淆矩阵(Confusion Matrix)、Cohen‘s Kappa 系数、详解,平均交并比(mIoU)、列联表(Contingency Table)附代码。

【机器学习|评价指标8】混淆矩阵(Confusion Matrix)、Cohen's Kappa 系数、详解,平均交并比(mIoU)、列联表(Contingency Table)附代码。

2401_89898861的博客 1447

android 亮灭屏流程

frameworks\base\services\core\java\com\android\server\display\DisplayPowerController.java final class DisplayPowerController implements AutomaticBrightnessController.Callbacks 实现回调接口updateBrightness 显示状态管理,与pms 独立,与传感器相关,异步回调通知PM状态改变 ...

lei7143的专栏 3082

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Android7.0 PowerManagerService亮灭屏分析(二)

    在PowerManagerService中对各种状态进行判断后,将其数值封装进DisplayPowerRequest中传入DisplayPowerController中进一步处理。在亮屏过程中DisplayPowerController会根据传过来的数值来设置新的电源状态为亮屏,然后调用DisplayPowerState来对状态进行设置,在分析DisplayPowerState时会具体讲解...

宇落 生命不息,奋斗不止...... 1万+

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Android 亮屏慢问题处理

问题: 【指纹】灭屏下使用正确的指纹解锁,解锁成功背光亮但屏幕没亮 【偶现】滑动解锁后只显示壁纸,图标在4S后加载出来 抖音有个activity在灭屏的时候都会启动,如果出现如下情况: 06-25 13:08:14.489 980 2799 I am_create_activity:[0,150997160,80,com.ss.android.ugc.aweme/com.ss.an...

一杯咖啡的专栏 9399

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Android T WMS窗口相关流程

什么是窗口 窗口即是屏幕上的一块用于绘制各种UI元素并可以响应用户输入的一个矩形区域。从原理上讲,窗口的概念是独自占有一个Surface实例的显示区域(我们在屏幕上看到的图形都需要绘制在Surface上)。 Window是个抽象类其实现类为PhoneWindow。

yimelancholy的博客 1万+

亮屏keyguand 与statusbar 绘制超时

WindowManager: Keyguard drawn timeout. Setting mKeyguardDrawComplete WindowManager: Timeout waiting for drawn: undrawn=[Window{246666e u0 StatusBar}] 02-07 16:17:08.592101   750  6123 D Po

lei7143的专栏 1347

Android中Graphic的理解

APP进程private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility, boolean insetsPending) throws RemoteException { float appScale = mAttachInfo.mApplicationScale

羊之草叶的专栏 1145

Android Framework(五)WMS-窗口显示流程——窗口布局与计算

1、WindowState 本身对应的是“容器”类型的 Surface ,在“addWindow流程”就创建了,而 relayoutWindow 创建的是一个“BufferStateLayer”类型的 Surface 这个也是被 copy 到应用层的Surface ,说明应用层的数据是被绘制在这个 Surface上 的。于是 dump 了层级树的信息。其实 WMS 对窗口的管理也是和 View 管理的一样的,窗口有添加移除,或者屏幕旋转等场景,为了确保手机屏幕上各个窗口处在正确的位置,显示正确的大小。

芸兮的博客 4203

Android 常见dumpsys方法与黑屏问题分析处理总结

黑屏问题是显示相关的综合性问题,涉及Android应用层、框架层和底层SurfaceFlinger、屏显等多个领域。下面有一些基础的判断来定位黑屏问题的归属:(1) 屏幕没有亮屏、背光为0则需先从power、屏显角度分析(2) 屏幕黑屏,但可以进行三指截屏、power键+音量下键截屏,并且截图正常显示(非黑图),则需先从屏显角度分析(3) 视频类、相机类显示黑屏,需要先确认编解码、阅览显示问题(4) 应用界面局部性黑块,某个控件黑,确认应用的view问题。

yimelancholy的博客 1万+
上一篇: ViewRootImpl.setView之后的relayout流程
下一篇: ftrace的一些操作方法
Aven-Chi
博客等级 码龄16年 185粉丝 99原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值