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