Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tài liệu tham khảo về cấu trúc vr_module
#include <
vr.h
>
Triển khai HAL này để nhận lệnh gọi lại khi đang sử dụng ứng dụng thực tế ảo (VR). Các ứng dụng VR thường có một số yêu cầu đặc biệt về hiệu suất và màn hình, bao gồm:
-
Độ trễ cảm biến thấp – Tổng độ trễ từ đầu đến cuối từ IMU, gia tốc kế và con quay hồi chuyển đến lệnh gọi lại hiển thị trong ứng dụng phải cực thấp (thường là <5 mili giây). Đây là yêu cầu để hỗ trợ cảm biến HIFI.
-
Độ trễ hiển thị thấp – Tổng độ trễ từ đầu đến cuối từ lệnh gọi vẽ GPU đến bản cập nhật hiển thị thực tế phải thấp nhất có thể. Điều này được thực hiện bằng cách sử dụng SurfaceFlinger ở chế độ một vùng đệm và đảm bảo rằng các lệnh gọi vẽ được đồng bộ hoá chính xác với quá trình quét màn hình. Hành vi này được hiển thị thông qua một tiện ích EGL cho các ứng dụng. Hãy xem phần dưới đây để biết các tiện ích EGL cần thiết cho việc này.
-
Màn hình có độ bền thấp – Bạn phải đặt chế độ cài đặt độ bền của màn hình ở mức thấp nhất có thể trong khi vẫn duy trì độ sáng hợp lý. Đối với màn hình thông thường chạy ở tốc độ 60Hz, các pixel phải được chiếu sáng trong thời gian <=3,5 mili giây thì mới được coi là có độ bền thấp. Điều này giúp tránh hiện tượng bóng ma trong khi di chuyển ở chế độ VR và bạn nên bật tính năng này từ HAL
lights.h
khi đặt BRIGHTNESS_MODE_LOW_PERSISTENCE.
-
Hiệu suất nhất quán của GPU và CPU – Khi được cung cấp khối lượng công việc GPU/CPU kết hợp cho một ứng dụng VR với các đợt công việc theo chu kỳ đều đặn vài lần một khung hình, việc lập lịch biểu CPU phải đảm bảo rằng công việc của luồng kết xuất ứng dụng chạy nhất quán trong vòng 1 mili giây kể từ thời điểm được lên lịch và hoàn tất trước khi kết thúc cửa sổ vẽ. Để đạt được mục tiêu này, bạn phải dành riêng một lõi CPU cho luồng kết xuất của ứng dụng thực tế ảo đang chạy trong chế độ thực tế ảo và cung cấp luồng này trong cpuset "top-app". Tương tự, bạn phải duy trì tốc độ xung nhịp CPU, GPU và bus thích hợp để đảm bảo khối lượng công việc kết xuất hoàn tất trong thời gian được phân bổ để kết xuất từng khung hình khi cờ POWER_HINT_SUSTAINED_PERFORMANCE được đặt trong
power.h
HAL khi ở chế độ VR khi thiết bị không bị điều tiết nhiệt.
-
Phải có các tiện ích EGL bắt buộc – Bất kỳ chế độ cài đặt GPU nào cần thiết để cho phép các chức năng trên đều bắt buộc, bao gồm cả các tiện ích 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 và EGL_KHR_wait_sync.
-
Báo cáo nhiệt chính xác – Nhiệt độ và giới hạn nhiệt chính xác phải được báo cáo trong HAL
thermal.h
. Cụ thể, nhiệt độ bề mặt hiện tại phải được báo cáo chính xác cho DEVICE_TEMPERATURE_SKIN và vr_throttling_threshold được báo cáo cho thiết bị này phải báo cáo chính xác giới hạn nhiệt độ mà trên đó trình quản lý nhiệt của thiết bị sẽ điều tiết CPU, GPU và/hoặc tốc độ xung nhịp của bus xuống dưới mức tối thiểu cần thiết để đạt được hiệu suất nhất quán (xem dấu đầu dòng trước đó).
Nhìn chung, các nhà cung cấp triển khai HAL này dự kiến sẽ sử dụng set_vr_mode làm gợi ý để bật tính năng điều chỉnh hiệu suất dành riêng cho VR cần thiết cho bất kỳ yêu cầu nào ở trên và bật mọi tính năng thiết bị tối ưu cho chế độ hiển thị VR. Lệnh gọi set_vr_mode có thể không làm gì cả nếu không có hoặc không cần tối ưu hoá để đáp ứng các yêu cầu trên.
Không có phương thức nào trong HAL này được gọi đồng thời từ khung Android.
Định nghĩa tại dòng
82
của tệp
VR.h
.
Các phương thức phổ biến của mô-đun.
này
phải
là thành viên đầu tiên của
vr_module
vì người dùng cấu trúc này có thể truyền một
hw_module_t
đến một
vr_module
con trỏ trong ngữ cảnh mà người dùng biết rằng
hw_module_t
tham chiếu đến một
vr_module
.
Định nghĩa tại dòng
89
của tệp
VR.h
.
Phương thức thuận tiện để triển khai HAL nhằm thiết lập mọi trạng thái cần thiết khi khởi động thời gian chạy. Phương thức này được gọi một lần từ VrManagerService trong giai đoạn khởi động. Không có phương thức nào từ HAL này sẽ được gọi trước khi khởi tạo.
Định nghĩa tại dòng
96
của tệp
VR.h
.
Định nghĩa tại dòng
110
của tệp
VR.h
.
void(* set_vr_mode)(struct
vr_module
*module, bool enabled)
|
Đặt trạng thái chế độ VR. Các trạng thái có thể có của thông số đã bật là: false – chế độ VR bị tắt, tắt tất cả chế độ cài đặt dành riêng cho VR. true – chế độ VR được bật, bật tất cả chế độ cài đặt dành riêng cho VR.
Phương thức này được gọi bất cứ khi nào hệ thống Android chuyển sang hoặc thoát khỏi chế độ VR. Điều này thường xảy ra khi người dùng chuyển sang hoặc từ một ứng dụng VR đang kết xuất hình ảnh ba chiều.
Định nghĩa tại dòng
107
của tệp
VR.h
.
Tài liệu cho cấu trúc này được tạo từ tệp sau:
-
hardware/libhardware/include/hardware/
vr.h
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[],[],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)"]]