自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
vr_module 结构体参考文档
#include <
vr.h
>
实现此 HAL 可在使用虚拟现实 (VR) 应用时接收回调。VR 应用通常具有一系列特殊的显示和性能要求,包括:
-
传感器延迟时间短 - 从 IMU、加速度计和陀螺仪到应用可见回调的端到端总延迟时间必须极短(通常小于 5 毫秒)。这是支持 HIFI 传感器的必备条件。
-
显示延迟时间短 - 从 GPU 绘制调用到实际显示更新的端到端总延迟时间必须尽可能短。为此,您需要在单缓冲区模式下使用 SurfaceFlinger,并确保绘制调用与显示屏扫描正确同步。此行为会通过 EGL 扩展公开给应用。如需了解为此所需的 EGL 扩展,请参阅下文。
-
低持久性显示屏 - 必须将显示屏持久性设置设为尽可能低,同时仍保持合理的亮度。对于以 60Hz 运行的典型显示屏,像素的亮起时间应小于等于 3.5 毫秒,才能被视为低持久性。这样可以避免在 VR 设置中移动时出现重影,并且在设置 BRIGHTNESS_MODE_LOW_PERSISTENCE 时,应从
lights.h
HAL 启用此功能。
-
GPU 和 CPU 的性能一致 - 当 VR 应用具有混合 GPU/CPU 工作负载且每帧有几次定期的工作突发时,CPU 调度应确保应用渲染线程工作在调度后的 1 毫秒内一致运行,并在绘制窗口结束前完成。为此,在 VR 模式下,必须将单个 CPU 核心专用于当前正在运行的 VR 应用的渲染线程,并在“top-app”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 会调用此方法一次。在 init 之前,系统不会调用此 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 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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)"]]