自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
硬體 Composer HAL
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
硬體編寫器 (HWC) HAL 會判斷最有效率的方式,將緩衝區與可用的硬體進行合成。由於 HAL 是裝置專屬,因此通常由顯示器硬體 OEM 執行。
只要考量疊加平面 (在顯示硬體而非 GPU 中合成的多個緩衝區),就能輕鬆瞭解這種做法的價值。舉例來說,以一般 Android 手機的直向模式為例,頂端有狀態列,底部有導覽列,其他地方則是應用程式內容。每個圖層的內容都位於不同的緩衝區中。您可以使用下列任一方法處理組合:
- 將應用程式內容轉譯至暫存緩衝區,然後在其上方轉譯狀態列,再在其上方轉譯導覽列,最後將暫存緩衝區傳遞至顯示硬體。
- 將所有三個緩衝區傳遞至顯示硬體,並指示硬體從不同緩衝區讀取螢幕不同部分的資料。
後者方法的效率可能會大幅提升。
顯示處理器的功能差異很大。疊加層數、圖層是否可旋轉或混合,以及位置和重疊的限制,都很難透過 API 表達。為了支援這些選項,HWC 會執行下列計算:
- SurfaceFlinger 會向 HWC 提供完整的圖層清單,並詢問「您要如何處理這個問題?」
- HWC 會回應,將每個圖層標示為裝置或用戶端組合。
- SurfaceFlinger 會處理任何用戶端,將輸出緩衝區傳遞至 HWC,並讓 HWC 處理其餘工作。
硬體供應商可以自訂決策程式碼,因此可發揮每部裝置的最佳效能。
當畫面上沒有任何變化時,疊加平面可能比 GL 合成效率低。當疊加內容含有透明像素,且重疊的圖層經過混合時,這種情況尤其明顯。在這種情況下,HWC 可以針對部分或所有圖層要求 GLES 合成作業,並保留已合成的緩衝區。如果 SurfaceFlinger 要求合成相同的緩衝區集合,HWC 可以顯示先前合成的暫存緩衝區。這麼做可以延長閒置裝置的電池續航力。
Android 裝置通常支援四個疊加層。如果嘗試合成的圖層數量超過疊加層,系統會針對其中部分圖層使用 GLES 合成,這表示應用程式使用的圖層數量可能會對耗電量和效能造成可測量的影響。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# Hardware Composer HAL\n\nThe Hardware Composer (HWC) HAL determines the most efficient\nway to composite buffers with the available hardware. As a HAL, its\nimplementation is device-specific and usually done by the display hardware OEM.\n\nThe value of this approach is easy to recognize when you consider *overlay\nplanes*, which composite multiple buffers in\nthe display hardware rather than the GPU. For example, consider a typical\nAndroid phone in portrait orientation, with the status bar on top, navigation\nbar at the bottom, and app content everywhere else. The contents for each layer\nare in separate buffers. You can handle composition using either of the\nfollowing methods:\n\n- Rendering the app content into a scratch buffer, then rendering the status bar over it, the navigation bar on top of that, and finally passing the scratch buffer to the display hardware.\n- Passing all three buffers to the display hardware and instructing it to read data from different buffers for different parts of the screen.\n\nThe latter approach can be significantly more efficient.\n\nDisplay processor capabilities vary significantly. The number of overlays,\nwhether layers can be rotated or blended, and restrictions on positioning and\noverlap can be difficult to express through an API. To accommodate these options, the HWC performs\nfollowing calculations:\n\n1. SurfaceFlinger provides HWC with a full list of layers and asks, \"How do you want to handle this?\"\n2. HWC responds by marking each layer as device or client composition.\n3. SurfaceFlinger takes care of any client, passing the output buffer to HWC, and lets HWC handle the rest.\n\nBecause hardware vendors can custom tailor decision-making code, it's possible\nto get the best performance out of every device.\n\nOverlay planes may be less efficient than GL composition when nothing on the\nscreen is changing. This is particularly true when overlay contents have\ntransparent pixels and overlapping layers are blended. In such cases,\nthe HWC can request GLES composition for some or all layers and retain\nthe composited buffer. If SurfaceFlinger asks to composite the same\nset of buffers, the HWC can show the previously composited scratch\nbuffer. This can improve the battery life of an idle device.\n\nAndroid devices typically support four overlay planes.\nAttempting to composite more layers than overlays causes the system to use GLES\ncomposition for some of them, meaning the number of layers used by an app can\nhave a measurable impact on power consumption and performance."]]