dvr_api.h revision 5b5d4e11949ae5fbd370927e721480f91c079857
1#ifndef ANDROID_DVR_API_H_ 2#define ANDROID_DVR_API_H_ 3 4#include <stdbool.h> 5#include <stddef.h> 6#include <stdint.h> 7#include <unistd.h> 8#include <cstdio> 9 10#include <dvr/dvr_display_types.h> 11#include <dvr/dvr_hardware_composer_types.h> 12#include <dvr/dvr_pose.h> 13 14#ifdef __cplusplus 15extern "C" { 16#endif 17 18typedef struct ANativeWindow ANativeWindow; 19 20typedef struct DvrPoseAsync DvrPoseAsync; 21 22typedef uint64_t DvrSurfaceUpdateFlags; 23typedef struct DvrDisplayManager DvrDisplayManager; 24typedef struct DvrSurfaceState DvrSurfaceState; 25typedef struct DvrPoseClient DvrPoseClient; 26typedef struct DvrVSyncClient DvrVSyncClient; 27typedef struct DvrVirtualTouchpad DvrVirtualTouchpad; 28 29typedef struct DvrBuffer DvrBuffer; 30typedef struct DvrWriteBuffer DvrWriteBuffer; 31typedef struct DvrReadBuffer DvrReadBuffer; 32typedef struct AHardwareBuffer AHardwareBuffer; 33 34typedef struct DvrReadBufferQueue DvrReadBufferQueue; 35typedef struct DvrWriteBufferQueue DvrWriteBufferQueue; 36 37typedef struct DvrSurface DvrSurface; 38typedef uint64_t DvrSurfaceAttributeType; 39typedef int32_t DvrSurfaceAttributeKey; 40typedef int32_t DvrGlobalBufferKey; 41 42typedef struct DvrSurfaceAttributeValue DvrSurfaceAttributeValue; 43typedef struct DvrSurfaceAttribute DvrSurfaceAttribute; 44 45// Note: To avoid breaking others during active development, only modify this 46// struct by appending elements to the end. 47// If you do feel we should to re-arrange or remove elements, please make a 48// note of it, and wait until we're about to finalize for an API release to do 49// so. 50typedef struct DvrNativeDisplayMetrics { 51 uint32_t display_width; 52 uint32_t display_height; 53 uint32_t display_x_dpi; 54 uint32_t display_y_dpi; 55 uint32_t vsync_period_ns; 56} DvrNativeDisplayMetrics; 57 58// native_handle contains the fds for the underlying ION allocations inside 59// the gralloc buffer. This is needed temporarily while GPU vendors work on 60// better support for AHardwareBuffer via glBindSharedBuffer APIs. See 61// b/37207909. For now we can declare the native_handle struct where it is 62// used for GPU late latching. See cutils/native_handle.h for the struct layout. 63struct native_handle; 64 65// Device metrics data type enums. 66enum { 67 // Request the device lens metrics protobuf. This matches cardboard protos. 68 DVR_CONFIGURATION_DATA_LENS_METRICS = 0, 69 // Request the device metrics protobuf. 70 DVR_CONFIGURATION_DATA_DEVICE_METRICS = 1, 71 // Request the per device configuration data file. 72 DVR_CONFIGURATION_DATA_DEVICE_CONFIG = 2, 73}; 74 75// dvr_display_manager.h 76typedef int (*DvrDisplayManagerCreatePtr)(DvrDisplayManager** client_out); 77typedef void (*DvrDisplayManagerDestroyPtr)(DvrDisplayManager* client); 78typedef int (*DvrDisplayManagerGetEventFdPtr)(DvrDisplayManager* client); 79typedef int (*DvrDisplayManagerTranslateEpollEventMaskPtr)( 80 DvrDisplayManager* client, int in_events, int* out_events); 81typedef int (*DvrDisplayManagerGetSurfaceStatePtr)( 82 DvrDisplayManager* client, DvrSurfaceState* surface_state); 83typedef int (*DvrDisplayManagerGetReadBufferQueuePtr)( 84 DvrDisplayManager* client, int surface_id, int queue_id, 85 DvrReadBufferQueue** queue_out); 86typedef int (*DvrConfigurationDataGetPtr)(int config_type, uint8_t** data, 87 size_t* data_size); 88typedef void (*DvrConfigurationDataDestroyPtr)(uint8_t* data); 89typedef int (*DvrSurfaceStateCreatePtr)(DvrSurfaceState** surface_state); 90typedef void (*DvrSurfaceStateDestroyPtr)(DvrSurfaceState* surface_state); 91typedef int (*DvrSurfaceStateGetSurfaceCountPtr)(DvrSurfaceState* surface_state, 92 size_t* count_out); 93typedef int (*DvrSurfaceStateGetUpdateFlagsPtr)( 94 DvrSurfaceState* surface_state, size_t surface_index, 95 DvrSurfaceUpdateFlags* flags_out); 96typedef int (*DvrSurfaceStateGetSurfaceIdPtr)(DvrSurfaceState* surface_state, 97 size_t surface_index, 98 int* surface_id_out); 99typedef int (*DvrSurfaceStateGetProcessIdPtr)(DvrSurfaceState* surface_state, 100 size_t surface_index, 101 int* process_id_out); 102typedef int (*DvrSurfaceStateGetQueueCountPtr)(DvrSurfaceState* surface_state, 103 size_t surface_index, 104 size_t* count_out); 105typedef ssize_t (*DvrSurfaceStateGetQueueIdsPtr)(DvrSurfaceState* surface_state, 106 size_t surface_index, 107 int* queue_ids, 108 size_t max_count); 109typedef int (*DvrSurfaceStateGetZOrderPtr)(DvrSurfaceState* surface_state, 110 size_t surface_index, 111 int* z_order_out); 112typedef int (*DvrSurfaceStateGetVisiblePtr)(DvrSurfaceState* surface_state, 113 size_t surface_index, 114 bool* visible_out); 115typedef int (*DvrSurfaceStateGetAttributeCountPtr)( 116 DvrSurfaceState* surface_state, size_t surface_index, size_t* count_out); 117typedef ssize_t (*DvrSurfaceStateGetAttributesPtr)( 118 DvrSurfaceState* surface_state, size_t surface_index, 119 DvrSurfaceAttribute* attributes, size_t max_attribute_count); 120 121// dvr_buffer.h 122typedef void (*DvrWriteBufferCreateEmptyPtr)(DvrWriteBuffer** write_buffer_out); 123typedef void (*DvrWriteBufferDestroyPtr)(DvrWriteBuffer* write_buffer); 124typedef int (*DvrWriteBufferIsValidPtr)(DvrWriteBuffer* write_buffer); 125typedef int (*DvrWriteBufferClearPtr)(DvrWriteBuffer* write_buffer); 126typedef int (*DvrWriteBufferGetIdPtr)(DvrWriteBuffer* write_buffer); 127typedef int (*DvrWriteBufferGetAHardwareBufferPtr)( 128 DvrWriteBuffer* write_buffer, AHardwareBuffer** hardware_buffer); 129typedef int (*DvrWriteBufferPostPtr)(DvrWriteBuffer* write_buffer, 130 int ready_fence_fd, const void* meta, 131 size_t meta_size_bytes); 132typedef int (*DvrWriteBufferGainPtr)(DvrWriteBuffer* write_buffer, 133 int* release_fence_fd); 134typedef int (*DvrWriteBufferGainAsyncPtr)(DvrWriteBuffer* write_buffer); 135typedef const struct native_handle* (*DvrWriteBufferGetNativeHandlePtr)( 136 DvrWriteBuffer* write_buffer); 137 138typedef void (*DvrReadBufferCreateEmptyPtr)(DvrReadBuffer** read_buffer_out); 139typedef void (*DvrReadBufferDestroyPtr)(DvrReadBuffer* read_buffer); 140typedef int (*DvrReadBufferIsValidPtr)(DvrReadBuffer* read_buffer); 141typedef int (*DvrReadBufferClearPtr)(DvrReadBuffer* read_buffer); 142typedef int (*DvrReadBufferGetIdPtr)(DvrReadBuffer* read_buffer); 143typedef int (*DvrReadBufferGetAHardwareBufferPtr)( 144 DvrReadBuffer* read_buffer, AHardwareBuffer** hardware_buffer); 145typedef int (*DvrReadBufferAcquirePtr)(DvrReadBuffer* read_buffer, 146 int* ready_fence_fd, void* meta, 147 size_t meta_size_bytes); 148typedef int (*DvrReadBufferReleasePtr)(DvrReadBuffer* read_buffer, 149 int release_fence_fd); 150typedef int (*DvrReadBufferReleaseAsyncPtr)(DvrReadBuffer* read_buffer); 151typedef const struct native_handle* (*DvrReadBufferGetNativeHandlePtr)( 152 DvrReadBuffer* read_buffer); 153 154typedef void (*DvrBufferDestroyPtr)(DvrBuffer* buffer); 155typedef int (*DvrBufferGetAHardwareBufferPtr)( 156 DvrBuffer* buffer, AHardwareBuffer** hardware_buffer); 157typedef int (*DvrBufferGlobalLayoutVersionGetPtr)(); 158typedef const struct native_handle* (*DvrBufferGetNativeHandlePtr)( 159 DvrBuffer* buffer); 160 161// dvr_buffer_queue.h 162typedef int (*DvrWriteBufferQueueCreatePtr)(uint32_t width, uint32_t height, 163 uint32_t format, 164 uint32_t layer_count, 165 uint64_t usage, size_t capacity, 166 size_t metadata_size, 167 DvrWriteBufferQueue** queue_out); 168typedef void (*DvrWriteBufferQueueDestroyPtr)(DvrWriteBufferQueue* write_queue); 169typedef ssize_t (*DvrWriteBufferQueueGetCapacityPtr)( 170 DvrWriteBufferQueue* write_queue); 171typedef int (*DvrWriteBufferQueueGetIdPtr)(DvrWriteBufferQueue* write_queue); 172typedef int (*DvrWriteBufferQueueGetExternalSurfacePtr)( 173 DvrWriteBufferQueue* write_queue, ANativeWindow** out_window); 174typedef int (*DvrWriteBufferQueueGetANativeWindowPtr)( 175 DvrWriteBufferQueue* write_queue, ANativeWindow** out_window); 176typedef int (*DvrWriteBufferQueueCreateReadQueuePtr)( 177 DvrWriteBufferQueue* write_queue, DvrReadBufferQueue** out_read_queue); 178typedef int (*DvrWriteBufferQueueDequeuePtr)(DvrWriteBufferQueue* write_queue, 179 int timeout, 180 DvrWriteBuffer* out_buffer, 181 int* out_fence_fd); 182typedef int (*DvrWriteBufferQueueResizeBufferPtr)( 183 DvrWriteBufferQueue* write_queue, uint32_t width, uint32_t height); 184typedef void (*DvrReadBufferQueueDestroyPtr)(DvrReadBufferQueue* read_queue); 185typedef ssize_t (*DvrReadBufferQueueGetCapacityPtr)( 186 DvrReadBufferQueue* read_queue); 187typedef int (*DvrReadBufferQueueGetIdPtr)(DvrReadBufferQueue* read_queue); 188typedef int (*DvrReadBufferQueueGetEventFdPtr)(DvrReadBufferQueue* read_queue); 189typedef int (*DvrReadBufferQueueCreateReadQueuePtr)( 190 DvrReadBufferQueue* read_queue, DvrReadBufferQueue** out_read_queue); 191typedef int (*DvrReadBufferQueueDequeuePtr)(DvrReadBufferQueue* read_queue, 192 int timeout, 193 DvrReadBuffer* out_buffer, 194 int* out_fence_fd, void* out_meta, 195 size_t meta_size_bytes); 196typedef void (*DvrReadBufferQueueBufferAvailableCallback)(void* context); 197typedef int (*DvrReadBufferQueueSetBufferAvailableCallbackPtr)( 198 DvrReadBufferQueue* read_queue, 199 DvrReadBufferQueueBufferAvailableCallback callback, void* context); 200typedef void (*DvrReadBufferQueueBufferRemovedCallback)(DvrReadBuffer* buffer, 201 void* context); 202typedef int (*DvrReadBufferQueueSetBufferRemovedCallbackPtr)( 203 DvrReadBufferQueue* read_queue, 204 DvrReadBufferQueueBufferRemovedCallback callback, void* context); 205typedef int (*DvrReadBufferQueueHandleEventsPtr)( 206 DvrReadBufferQueue* read_queue); 207 208// dvr_surface.h 209typedef int (*DvrSetupGlobalBufferPtr)(DvrGlobalBufferKey key, size_t size, 210 uint64_t usage, DvrBuffer** buffer_out); 211typedef int (*DvrDeleteGlobalBufferPtr)(DvrGlobalBufferKey key); 212typedef int (*DvrGetGlobalBufferPtr)(DvrGlobalBufferKey key, 213 DvrBuffer** out_buffer); 214typedef int (*DvrSurfaceCreatePtr)(const DvrSurfaceAttribute* attributes, 215 size_t attribute_count, 216 DvrSurface** surface_out); 217typedef void (*DvrSurfaceDestroyPtr)(DvrSurface* surface); 218typedef int (*DvrSurfaceGetIdPtr)(DvrSurface* surface); 219typedef int (*DvrSurfaceSetAttributesPtr)(DvrSurface* surface, 220 const DvrSurfaceAttribute* attributes, 221 size_t attribute_count); 222typedef int (*DvrSurfaceCreateWriteBufferQueuePtr)( 223 DvrSurface* surface, uint32_t width, uint32_t height, uint32_t format, 224 uint32_t layer_count, uint64_t usage, size_t capacity, size_t metadata_size, 225 DvrWriteBufferQueue** queue_out); 226typedef int (*DvrGetNativeDisplayMetricsPtr)(size_t sizeof_metrics, 227 DvrNativeDisplayMetrics* metrics); 228 229// dvr_vsync.h 230typedef int (*DvrVSyncClientCreatePtr)(DvrVSyncClient** client_out); 231typedef void (*DvrVSyncClientDestroyPtr)(DvrVSyncClient* client); 232typedef int (*DvrVSyncClientGetSchedInfoPtr)(DvrVSyncClient* client, 233 int64_t* vsync_period_ns, 234 int64_t* next_timestamp_ns, 235 uint32_t* next_vsync_count); 236 237// libs/vr/libvrsensor/include/dvr/pose_client.h 238typedef DvrPoseClient* (*DvrPoseClientCreatePtr)(); 239typedef void (*DvrPoseClientDestroyPtr)(DvrPoseClient* client); 240typedef int (*DvrPoseClientGetPtr)(DvrPoseClient* client, uint32_t vsync_count, 241 DvrPoseAsync* out_pose); 242typedef uint32_t (*DvrPoseClientGetVsyncCountPtr)(DvrPoseClient* client); 243typedef int (*DvrPoseClientGetControllerPtr)(DvrPoseClient* client, 244 int32_t controller_id, 245 uint32_t vsync_count, 246 DvrPoseAsync* out_pose); 247typedef int (*DvrPoseClientSensorsEnablePtr)(DvrPoseClient* client, 248 bool enabled); 249 250// services/vr/virtual_touchpad/include/dvr/virtual_touchpad_client.h 251 252// Touchpad IDs for *Touch*() and *ButtonState*() calls. 253enum { 254 DVR_VIRTUAL_TOUCHPAD_PRIMARY = 0, 255 DVR_VIRTUAL_TOUCHPAD_VIRTUAL = 1, 256}; 257typedef DvrVirtualTouchpad* (*DvrVirtualTouchpadCreatePtr)(); 258typedef void (*DvrVirtualTouchpadDestroyPtr)(DvrVirtualTouchpad* client); 259typedef int (*DvrVirtualTouchpadAttachPtr)(DvrVirtualTouchpad* client); 260typedef int (*DvrVirtualTouchpadDetachPtr)(DvrVirtualTouchpad* client); 261typedef int (*DvrVirtualTouchpadTouchPtr)(DvrVirtualTouchpad* client, 262 int touchpad, float x, float y, 263 float pressure); 264typedef int (*DvrVirtualTouchpadButtonStatePtr)(DvrVirtualTouchpad* client, 265 int touchpad, int buttons); 266typedef int (*DvrVirtualTouchpadScrollPtr)(DvrVirtualTouchpad* client, 267 int touchpad, float x, float y); 268 269// dvr_hardware_composer_client.h 270typedef struct DvrHwcClient DvrHwcClient; 271typedef struct DvrHwcFrame DvrHwcFrame; 272typedef int (*DvrHwcOnFrameCallback)(void* client_state, DvrHwcFrame* frame); 273typedef DvrHwcClient* (*DvrHwcClientCreatePtr)(DvrHwcOnFrameCallback callback, 274 void* client_state); 275typedef void (*DvrHwcClientDestroyPtr)(DvrHwcClient* client); 276typedef void (*DvrHwcFrameDestroyPtr)(DvrHwcFrame* frame); 277typedef DvrHwcDisplay (*DvrHwcFrameGetDisplayIdPtr)(DvrHwcFrame* frame); 278typedef int32_t (*DvrHwcFrameGetDisplayWidthPtr)(DvrHwcFrame* frame); 279typedef int32_t (*DvrHwcFrameGetDisplayHeightPtr)(DvrHwcFrame* frame); 280typedef bool (*DvrHwcFrameGetDisplayRemovedPtr)(DvrHwcFrame* frame); 281typedef size_t (*DvrHwcFrameGetLayerCountPtr)(DvrHwcFrame* frame); 282typedef DvrHwcLayer (*DvrHwcFrameGetLayerIdPtr)(DvrHwcFrame* frame, 283 size_t layer_index); 284typedef uint32_t (*DvrHwcFrameGetActiveConfigPtr)(DvrHwcFrame* frame); 285typedef uint32_t (*DvrHwcFrameGetColorModePtr)(DvrHwcFrame* frame); 286typedef void (*DvrHwcFrameGetColorTransformPtr)(DvrHwcFrame* frame, 287 float* out_matrix, 288 int32_t* out_hint); 289typedef uint32_t (*DvrHwcFrameGetPowerModePtr)(DvrHwcFrame* frame); 290typedef uint32_t (*DvrHwcFrameGetVsyncEnabledPtr)(DvrHwcFrame* frame); 291typedef AHardwareBuffer* (*DvrHwcFrameGetLayerBufferPtr)(DvrHwcFrame* frame, 292 size_t layer_index); 293typedef int (*DvrHwcFrameGetLayerFencePtr)(DvrHwcFrame* frame, 294 size_t layer_index); 295typedef DvrHwcRecti (*DvrHwcFrameGetLayerDisplayFramePtr)(DvrHwcFrame* frame, 296 size_t layer_index); 297typedef DvrHwcRectf (*DvrHwcFrameGetLayerCropPtr)(DvrHwcFrame* frame, 298 size_t layer_index); 299typedef DvrHwcBlendMode (*DvrHwcFrameGetLayerBlendModePtr)(DvrHwcFrame* frame, 300 size_t layer_index); 301typedef float (*DvrHwcFrameGetLayerAlphaPtr)(DvrHwcFrame* frame, 302 size_t layer_index); 303typedef uint32_t (*DvrHwcFrameGetLayerTypePtr)(DvrHwcFrame* frame, 304 size_t layer_index); 305typedef uint32_t (*DvrHwcFrameGetLayerApplicationIdPtr)(DvrHwcFrame* frame, 306 size_t layer_index); 307typedef uint32_t (*DvrHwcFrameGetLayerZOrderPtr)(DvrHwcFrame* frame, 308 size_t layer_index); 309 310typedef void (*DvrHwcFrameGetLayerCursorPtr)(DvrHwcFrame* frame, 311 size_t layer_index, int32_t* out_x, 312 int32_t* out_y); 313 314typedef uint32_t (*DvrHwcFrameGetLayerTransformPtr)(DvrHwcFrame* frame, 315 size_t layer_index); 316 317typedef uint32_t (*DvrHwcFrameGetLayerDataspacePtr)(DvrHwcFrame* frame, 318 size_t layer_index); 319 320typedef uint32_t (*DvrHwcFrameGetLayerColorPtr)(DvrHwcFrame* frame, 321 size_t layer_index); 322 323typedef uint32_t (*DvrHwcFrameGetLayerNumVisibleRegionsPtr)(DvrHwcFrame* frame, 324 size_t layer_index); 325typedef DvrHwcRecti (*DvrHwcFrameGetLayerVisibleRegionPtr)(DvrHwcFrame* frame, 326 size_t layer_index, 327 size_t index); 328 329typedef uint32_t (*DvrHwcFrameGetLayerNumDamagedRegionsPtr)(DvrHwcFrame* frame, 330 size_t layer_index); 331typedef DvrHwcRecti (*DvrHwcFrameGetLayerDamagedRegionPtr)(DvrHwcFrame* frame, 332 size_t layer_index, 333 size_t index); 334 335// dvr_performance.h 336typedef int (*DvrPerformanceSetSchedulerPolicyPtr)( 337 pid_t task_id, const char* scheduler_policy); 338 339// The buffer metadata that an Android Surface (a.k.a. ANativeWindow) 340// will populate. A DvrWriteBufferQueue must be created with this metadata iff 341// ANativeWindow access is needed. Please do not remove, modify, or reorder 342// existing data members. If new fields need to be added, please take extra care 343// to make sure that new data field is padded properly the size of the struct 344// stays same. 345struct DvrNativeBufferMetadata { 346 // Timestamp of the frame. 347 int64_t timestamp; 348 349 // Whether the buffer is using auto timestamp. 350 int32_t is_auto_timestamp; 351 352 // Must be one of the HAL_DATASPACE_XXX value defined in system/graphics.h 353 int32_t dataspace; 354 355 // Crop extracted from an ACrop or android::Crop object. 356 int32_t crop_left; 357 int32_t crop_top; 358 int32_t crop_right; 359 int32_t crop_bottom; 360 361 // Must be one of the NATIVE_WINDOW_SCALING_MODE_XXX value defined in 362 // system/window.h. 363 int32_t scaling_mode; 364 365 // Must be one of the ANATIVEWINDOW_TRANSFORM_XXX value defined in 366 // android/native_window.h 367 int32_t transform; 368 369 // Reserved bytes for so that the struct is forward compatible. 370 int32_t reserved[16]; 371}; 372 373struct DvrApi_v1 { 374// Defines an API entry for V1 (no version suffix). 375#define DVR_V1_API_ENTRY(name) Dvr##name##Ptr name 376 377#include "dvr_api_entries.h" 378 379// Undefine macro definitions to play nice with Google3 style rules. 380#undef DVR_V1_API_ENTRY 381}; 382 383int dvrGetApi(void* api, size_t struct_size, int version); 384 385#ifdef __cplusplus 386} // extern "C" 387#endif 388 389#endif // ANDROID_DVR_API_H_ 390