自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
使用 AutoSingleLayer 的未信號緩衝區 Latch
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 13 新增了名為 AutoSingleLayer
的新設定,用於鎖定未發出訊號的緩衝區。這項設定可讓 SurfaceFlinger 在只有單一圖層更新時鎖定未發出信號的緩衝區,但不適用於跨圖層發生的情況,例如幾何圖形變更或同步交易。
在 Android 13 之前,AOSP 中的 debug.sf.latch_unsignaled
標記可讓 SurfaceFlinger 鎖定所有未發出信號的緩衝區,無論用途為何。啟用這項設定後,會產生不必要的副作用,例如在等待不完整緩衝區時,中斷同步交易並凍結整個顯示畫面。
在 AutoSingleLayer
模式下,只有單一途徑的緩衝區會在影格中更新。這個模式可讓遊戲和其他全螢幕應用程式享有鎖定未發出信號的緩衝區,並減少應用程式卡頓的優點,同時不會受到螢幕凍結的影響。
AutoSingleLayer 模式設定
在 Android 13 中,AutoSingleLayer
是鎖定未發出信號緩衝區功能的預設模式。這個模式由系統屬性 debug.sf.auto_latch_unsignaled
控制。
SurfaceFlinger 會在啟動時讀取 LatchUnsignaledConfig
。以下是可能的設定:
測試 AutoSingleLayer
如要測試緩衝器是否已鎖定未發出信號,請在 Perfetto 中查看 SurfaceFlinger 的以下追蹤記錄:
圖 1. Perfetto 中未發出信號的緩衝區記錄
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Unsignaled buffer latching with AutoSingleLayer\n\nAndroid 13 adds a new configuration called\n[`AutoSingleLayer`](https://android.googlesource.com/platform/frameworks/native/+/refs/heads/android16-release/services/surfaceflinger/SurfaceFlinger.h#160) for latching\nunsignaled buffers. This configuration lets SurfaceFlinger latch an unsignaled\nbuffer when only a single layer is updating, and not for the cases that occur\nacross layers, such as geometry changes or sync transactions.\n\nBefore Android 13, the `debug.sf.latch_unsignaled` flag\nin AOSP lets SurfaceFlinger latch all unsignaled buffers, regardless of the use\ncase. When this configuration is enabled, there are undesired side effects, such\nas breaking sync transactions and freezing the entire display while waiting on\nincomplete buffers.\n\nWith the `AutoSingleLayer` mode, only a buffer of a single surface is updated\nin a frame. This mode enables games and other fullscreen apps to get the benefit\nof latching unsignaled buffers and reducing app jank while remaining unaffected\nby display freezes.\n\nAutoSingleLayer mode settings\n-----------------------------\n\nIn Android 13,\n[`AutoSingleLayer`](https://android.googlesource.com/platform/frameworks/native/+/refs/heads/android16-release/services/surfaceflinger/SurfaceFlinger.h#160) is the default\nmode for the latch unsignaled buffer feature. This mode is controlled by the\nsystem property [`debug.sf.auto_latch_unsignaled`](https://android.googlesource.com/platform/frameworks/native/+/refs/heads/android16-release/services/surfaceflinger/SurfaceFlinger.cpp#454).\n\nSurfaceFlinger reads [`LatchUnsignaledConfig`](https://android.googlesource.com/platform/frameworks/native/+/refs/heads/android16-release/services/surfaceflinger/SurfaceFlinger.cpp#449) on boot.\nHere are the possible configurations:\n\n- `LatchUnsignaledConfig::AutoSingleLayer`\n\n In this AOSP default mode, latching unsignaled buffers is permitted when a\n single layer is updated in a frame, and the update includes just a buffer\n update with no sync transactions or geometry changes. In this mode, [`debug.sf.auto_latch_unsignaled`](https://android.googlesource.com/platform/frameworks/native/+/refs/heads/android16-release/services/surfaceflinger/SurfaceFlinger.cpp#454)\n is set to `true` by default.\n- `LatchUnsignaledConfig::Disabled`\n\n This mode disables the latch unsignaled behavior and latches only signaled\n transactions. This mode also disables the `AutoSingleLayer` mode. To\n configure this mode, set [`debug.sf.latch_unsignaled`](https://android.googlesource.com/platform/frameworks/native/+/refs/heads/android16-release/services/surfaceflinger/SurfaceFlinger.cpp#450) and\n [`debug.sf.auto_latch_unsignaled`](https://android.googlesource.com/platform/frameworks/native/+/refs/heads/android16-release/services/surfaceflinger/SurfaceFlinger.cpp#454) to `false`.\n- `LatchUnsignaledConfig::Always`\n\n In this mode, all buffers are latched unsignaled. To configure this mode, set\n [`debug.sf.latch_unsignaled`](https://android.googlesource.com/platform/frameworks/native/+/refs/heads/android16-release/services/surfaceflinger/SurfaceFlinger.cpp#450) to `true`.\n | **Note:** This mode takes priority over setting `AutoSingleLayer` but can cause display freezing and other undesired effects. This mode might be deprecated in future releases.\n\nTest `AutoSingleLayer`\n----------------------\n\nTo test whether a buffer is latched unsignaled, look for the following traces\nfrom SurfaceFlinger in [Perfetto](https://developer.android.com/topic/performance/tracing):\n\n**Figure 1.** Trace of a latched unsignaled buffer in Perfetto"]]