自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
vr_module 結構體參考資料
#include <
vr.h
>
實作此 HAL 時,請在使用虛擬實境 (VR) 應用程式時接收回呼。VR 應用程式通常具有許多特殊的顯示和效能需求,包括:
-
低感應器延遲:從 IMU、加速計和陀螺儀到應用程式可見回呼的總端對端延遲時間必須極低 (通常小於 5 毫秒)。這是支援 HIFI 感應器的必要條件。
-
低延遲顯示:從 GPU 繪圖呼叫到實際顯示更新的總端對端延遲時間必須盡可能低。這項功能是透過在單緩衝模式下使用 SurfaceFlinger,並確保繪圖呼叫與顯示掃描輸出正確同步,這項行為會透過 EGL 擴充功能公開給應用程式。請參閱下文,瞭解這項作業所需的 EGL 擴充功能。
-
低延遲螢幕:螢幕延遲設定必須盡可能調低,同時維持合理的亮度。對於以 60Hz 運作的一般螢幕,像素亮度應低於 3.5ms,才能算是低延遲。這可避免在 VR 設定中移動時出現重影,並應在設定 BRIGHTNESS_MODE_LOW_PERSISTENCE 時,從
lights.h
HAL 啟用。
-
GPU 和 CPU 的一致效能:如果 VR 應用程式有混合 GPU/CPU 工作負載,且工作會在每個影格內以規律間隔多次爆發,CPU 排程應確保應用程式轉譯執行緒的工作在排程後 1 毫秒內持續執行,並在繪圖視窗結束前完成。為此,在 VR 模式下,必須為目前執行中的 VR 應用程式算繪執行緒保留單一 CPU 核心,並在「頂層應用程式」cpuset 中提供。同樣地,在裝置未受到熱力限制的情況下,如果在 VR 模式下在
power.h
HAL 中設定 POWER_HINT_SUSTAINED_PERFORMANCE 標記,則必須維持適當的 CPU、GPU 和匯流排時脈,確保算繪工作負載在每個影格可用的時間內完成。
-
必須提供必要的 EGL 擴充功能 - 您必須提供所有允許上述功能的 GPU 設定,包括 EGL 擴充功能:EGL_ANDROID_create_native_client_buffer、EGL_ANDROID_front_buffer_auto_refresh、EGL_EXT_protected_content、EGL_KHR_mutable_render_buffer、EGL_KHR_reusable_sync 和 EGL_KHR_wait_sync。
-
準確的熱能回報 - 必須在
thermal.h
HAL 中回報準確的熱能溫度和限制。具體來說,必須準確回報 DEVICE_TEMPERATURE_SKIN 的目前皮膚溫度,以及這部裝置回報的 vr_throttling_threshold,以便準確回報溫度上限,超過該上限時,裝置的溫度控制器會將 CPU、GPU 和/或匯流排時脈降至維持穩定效能的最低必要值 (請參閱前述項目)。
一般來說,實作此 HAL 的供應商應使用 set_vr_mode 做為提示,啟用 VR 專屬的效能調整功能,以符合上述任何一項需求,並開啟任何最適合 VR 顯示模式的裝置功能。如果沒有可用或必要的最佳化方式來滿足上述要求,set_vr_mode 呼叫可能什麼也不做。
系統不會從 Android 架構同時呼叫這個 HAL 中的任何方法。
定義位於檔案
vr.h
的
82
行。
方便實作 HAL 的方法,可在執行階段啟動時設定所需的任何狀態。在 VrManagerService 的啟動階段,這個方法會從中呼叫一次。在初始化之前,系統不會呼叫這個 HAL 的任何方法。
定義位於檔案
vr.h
的
96
行。
void(* set_vr_mode)(struct
vr_module
*module, bool enabled)
|
設定 VR 模式狀態。enabled 參數的可能狀態如下:false - 已停用 VR 模式,請關閉所有 VR 專屬設定。true - 已啟用 VR 模式,請開啟所有 VR 專屬設定。
每當 Android 系統進入或退出 VR 模式時,就會呼叫這個方法。這種情況通常會發生在使用者切換至或離開正在執行立體渲染的 VR 應用程式時。
定義位於檔案
vr.h
的
107
行。
這個結構體的說明文件是由下列檔案產生:
-
hardware/libhardware/include/hardware/
vr.h
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","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-26 (世界標準時間)。"],[],[],null,["# Android Hardware Abstraction Layer: vr_module Struct Reference\n\nvr_module Struct Reference\n==========================\n\n[Data Fields](#pub-attribs) \nvr_module Struct Reference \n\n`\n#include \u003c\n`[vr.h](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)`\n\u003e\n`\n\n|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Data Fields ----------- ||\n| struct [hw_module_t](/reference/hal/structhw__module__t) | [common](/reference/hal/structvr__module#a71ea01183b3998cad6a2301a37a42fc7) |\n| ||\n| void(\\* | [init](/reference/hal/structvr__module#a1621887a15b003a1ba7be81d52b0abb0) )(struct [vr_module](/reference/hal/structvr__module) \\*module) |\n| ||\n| void(\\* | [set_vr_mode](/reference/hal/structvr__module#a8c9e8990b6b65b068703cd615be68fb5) )(struct [vr_module](/reference/hal/structvr__module) \\*module, bool enabled) |\n| ||\n| void \\* | [reserved](/reference/hal/structvr__module#aa1a42885ba14c2168dc14d3f219b5e99) \\[8-2\\] |\n| ||\n\n\nDetailed Description\n--------------------\n\n\nImplement this HAL to receive callbacks when a virtual reality (VR) application is being used. VR applications characteristically have a number of special display and performance requirements, including:\n\n- Low sensor latency - Total end-to-end latency from the IMU, accelerometer, and gyro to an application-visible callback must be extremely low (\\\u003c5ms typically). This is required for HIFI sensor support.\n- Low display latency - Total end-to-end latency from the GPU draw calls to the actual display update must be as low as possible. This is achieved by using SurfaceFlinger in a single-buffered mode, and assuring that draw calls are synchronized with the display scanout correctly. This behavior is exposed via an EGL extension to applications. See below for the EGL extensions needed for this.\n- Low-persistence display - Display persistence settings must be set as low as possible while still maintaining a reasonable brightness. For a typical display running at 60Hz, pixels should be illuminated for \\\u003c=3.5ms to be considered low-persistence. This avoids ghosting during movements in a VR setting, and should be enabled from the [lights.h](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/lights.h) HAL when BRIGHTNESS_MODE_LOW_PERSISTENCE is set.\n- Consistent performance of the GPU and CPU - When given a mixed GPU/CPU workload for a VR application with bursts of work at regular intervals several times a frame, the CPU scheduling should ensure that the application render thread work is run consistently within 1ms of when scheduled, and completed before the end of the draw window. To this end, a single CPU core must be reserved for solely for the currently running VR application's render thread while in VR mode, and made available in the \"top-app\" cpuset. Likewise, an appropriate CPU, GPU, and bus clockrate must be maintained to ensure that the rendering workload finishes within the time allotted to render each frame when the POWER_HINT_SUSTAINED_PERFORMANCE flag has been set in the [power.h](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/power.h) HAL while in VR mode when the device is not being thermally throttled.\n- Required EGL extensions must be present - Any GPU settings required to allow the above capabilities are required, including the EGL extensions: EGL_ANDROID_create_native_client_buffer, EGL_ANDROID_front_buffer_auto_refresh, EGL_EXT_protected_content, EGL_KHR_mutable_render_buffer, EGL_KHR_reusable_sync, and EGL_KHR_wait_sync.\n- Accurate thermal reporting - Accurate thermal temperatures and limits must be reported in the [thermal.h](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/thermal.h) HAL. Specifically, the current skin temperature must accurately be reported for DEVICE_TEMPERATURE_SKIN and the vr_throttling_threshold reported for this device must accurately report the temperature limit above which the device's thermal governor throttles the CPU, GPU, and/or bus clockrates below the minimum necessary for consistent performance (see previous bullet point).\n\n\nIn general, vendors implementing this HAL are expected to use set_vr_mode as a hint to enable VR-specific performance tuning needed for any of the above requirements, and to turn on any device features optimal for VR display modes. The set_vr_mode call may simply do nothing if no optimizations are available or necessary to meet the above requirements.\n\n\nNo methods in this HAL will be called concurrently from the Android framework.\n\n\nDefinition at line\n[82](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)\nof file\n[vr.h](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)\n.\n\nField Documentation\n-------------------\n\n\n|-----------------------------------------------------------------|\n| struct [hw_module_t](/reference/hal/structhw__module__t) common |\n\n\nCommon methods of the module. This\n*must*\nbe the first member of\n[vr_module](/reference/hal/structvr__module)\nas users of this structure may cast a\n[hw_module_t](/reference/hal/structhw__module__t)\nto a\n[vr_module](/reference/hal/structvr__module)\npointer in contexts where it's known that the\n[hw_module_t](/reference/hal/structhw__module__t)\nreferences a\n[vr_module](/reference/hal/structvr__module)\n.\n\n\nDefinition at line\n[89](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)\nof file\n[vr.h](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)\n.\n\n|-----------------------------------------------------------------------------|\n| void(\\* init)(struct [vr_module](/reference/hal/structvr__module) \\*module) |\n\n\nConvenience method for the HAL implementation to set up any state needed at runtime startup. This is called once from the VrManagerService during its boot phase. No methods from this HAL will be called before init.\n\n\nDefinition at line\n[96](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)\nof file\n[vr.h](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)\n.\n\n|------------------------|\n| void\\* reserved\\[8-2\\] |\n\n\nDefinition at line\n[110](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)\nof file\n[vr.h](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)\n.\n\n|--------------------------------------------------------------------------------------------------|\n| void(\\* set_vr_mode)(struct [vr_module](/reference/hal/structvr__module) \\*module, bool enabled) |\n\n\nSet the VR mode state. Possible states of the enabled parameter are: false - VR mode is disabled, turn off all VR-specific settings. true - VR mode is enabled, turn on all VR-specific settings.\n\n\nThis is called whenever the the Android system enters or leaves VR mode. This will typically occur when the user switches to or from a VR application that is doing stereoscopic rendering.\n\n\nDefinition at line\n[107](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)\nof file\n[vr.h](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)\n.\n\n*** ** * ** ***\n\nThe documentation for this struct was generated from the following file:\n\n- hardware/libhardware/include/hardware/ [vr.h](https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/vr.h)"]]