Add vaPutSurfaceBuf for Android
[profile/ivi/libva.git] / va / va_backend.h
1 /*
2  * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  * 
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 /*
26  * Video Decode Acceleration -Backend API
27  */
28
29 #ifndef _VA_BACKEND_H_
30 #define _VA_BACKEND_H_
31
32 #include <va/va.h>
33 #include <X11/Xlib.h>
34 #include <linux/videodev2.h>
35
36 typedef struct VADriverContext *VADriverContextP;
37 typedef struct VADisplayContext *VADisplayContextP;
38
39 struct VADriverVTable
40 {
41         VAStatus (*vaTerminate) ( VADriverContextP ctx );
42
43         VAStatus (*vaQueryConfigProfiles) (
44                 VADriverContextP ctx,
45                 VAProfile *profile_list,        /* out */
46                 int *num_profiles                       /* out */
47         );
48
49         VAStatus (*vaQueryConfigEntrypoints) (
50                 VADriverContextP ctx,
51                 VAProfile profile,
52                 VAEntrypoint  *entrypoint_list, /* out */
53                 int *num_entrypoints                    /* out */
54         );
55
56         VAStatus (*vaGetConfigAttributes) (
57                 VADriverContextP ctx,
58                 VAProfile profile,
59                 VAEntrypoint entrypoint,
60                 VAConfigAttrib *attrib_list,    /* in/out */
61                 int num_attribs
62         );
63
64         VAStatus (*vaCreateConfig) (
65                 VADriverContextP ctx,
66                 VAProfile profile, 
67                 VAEntrypoint entrypoint, 
68                 VAConfigAttrib *attrib_list,
69                 int num_attribs,
70                 VAConfigID *config_id           /* out */
71         );
72
73         VAStatus (*vaDestroyConfig) (
74                 VADriverContextP ctx,
75                 VAConfigID config_id
76         );
77
78         VAStatus (*vaQueryConfigAttributes) (
79                 VADriverContextP ctx,
80                 VAConfigID config_id, 
81                 VAProfile *profile,             /* out */
82                 VAEntrypoint *entrypoint,       /* out */
83                 VAConfigAttrib *attrib_list,    /* out */
84                 int *num_attribs                /* out */
85         );
86
87         VAStatus (*vaCreateSurfaces) (
88                 VADriverContextP ctx,
89                 int width,
90                 int height,
91                 int format,
92                 int num_surfaces,
93                 VASurfaceID *surfaces           /* out */
94         );
95
96         VAStatus (*vaDestroySurfaces) (
97                 VADriverContextP ctx,
98                 VASurfaceID *surface_list,
99                 int num_surfaces
100         );
101
102         VAStatus (*vaCreateContext) (
103                 VADriverContextP ctx,
104                 VAConfigID config_id,
105                 int picture_width,
106                 int picture_height,
107                 int flag,
108                 VASurfaceID *render_targets,
109                 int num_render_targets,
110                 VAContextID *context            /* out */
111         );
112
113         VAStatus (*vaDestroyContext) (
114                 VADriverContextP ctx,
115                 VAContextID context
116         );
117
118         VAStatus (*vaCreateBuffer) (
119                 VADriverContextP ctx,
120                 VAContextID context,            /* in */
121                 VABufferType type,              /* in */
122                 unsigned int size,              /* in */
123                 unsigned int num_elements,      /* in */
124                 void *data,                     /* in */
125                 VABufferID *buf_id              /* out */
126         );
127
128         VAStatus (*vaBufferSetNumElements) (
129                 VADriverContextP ctx,
130                 VABufferID buf_id,      /* in */
131                 unsigned int num_elements       /* in */
132         );
133
134         VAStatus (*vaMapBuffer) (
135                 VADriverContextP ctx,
136                 VABufferID buf_id,      /* in */
137                 void **pbuf         /* out */
138         );
139
140         VAStatus (*vaUnmapBuffer) (
141                 VADriverContextP ctx,
142                 VABufferID buf_id       /* in */
143         );
144
145         VAStatus (*vaDestroyBuffer) (
146                 VADriverContextP ctx,
147                 VABufferID buffer_id
148         );
149
150         VAStatus (*vaBeginPicture) (
151                 VADriverContextP ctx,
152                 VAContextID context,
153                 VASurfaceID render_target
154         );
155
156         VAStatus (*vaRenderPicture) (
157                 VADriverContextP ctx,
158                 VAContextID context,
159                 VABufferID *buffers,
160                 int num_buffers
161         );
162
163         VAStatus (*vaEndPicture) (
164                 VADriverContextP ctx,
165                 VAContextID context
166         );
167
168         VAStatus (*vaSyncSurface) (
169                 VADriverContextP ctx,
170                 VASurfaceID render_target
171         );
172
173         VAStatus (*vaQuerySurfaceStatus) (
174                 VADriverContextP ctx,
175                 VASurfaceID render_target,
176                 VASurfaceStatus *status /* out */
177         );
178
179         VAStatus (*vaPutSurface) (
180                 VADriverContextP ctx,
181                 VASurfaceID surface,
182                 void* draw, /* X Drawable */
183                 short srcx,
184                 short srcy,
185                 unsigned short srcw,
186                 unsigned short srch,
187                 short destx,
188                 short desty,
189                 unsigned short destw,
190                 unsigned short desth,
191                 VARectangle *cliprects, /* client supplied clip list */
192                 unsigned int number_cliprects, /* number of clip rects in the clip list */
193                 unsigned int flags /* de-interlacing flags */
194         );
195
196         VAStatus (*vaPutSurfaceBuf) (
197                 VADriverContextP ctx,
198                 VASurfaceID surface,
199                 Drawable draw, /* X Drawable */
200                 unsigned char* data,
201                 int* data_len,
202                 short srcx,
203                 short srcy,
204                 unsigned short srcw,
205                 unsigned short srch,
206                 short destx,
207                 short desty,
208                 unsigned short destw,
209                 unsigned short desth,
210                 VARectangle *cliprects, /* client supplied clip list */
211                 unsigned int number_cliprects, /* number of clip rects in the clip list */
212                 unsigned int flags /* de-interlacing flags */
213         );
214
215         VAStatus (*vaQueryImageFormats) (
216                 VADriverContextP ctx,
217                 VAImageFormat *format_list,        /* out */
218                 int *num_formats           /* out */
219         );
220
221         VAStatus (*vaCreateImage) (
222                 VADriverContextP ctx,
223                 VAImageFormat *format,
224                 int width,
225                 int height,
226                 VAImage *image     /* out */
227         );
228
229         VAStatus (*vaDeriveImage) (
230                 VADriverContextP ctx,
231                 VASurfaceID surface,
232                 VAImage *image     /* out */
233         );
234
235         VAStatus (*vaDestroyImage) (
236                 VADriverContextP ctx,
237                 VAImageID image
238         );
239         
240         VAStatus (*vaSetImagePalette) (
241                 VADriverContextP ctx,
242                 VAImageID image,
243                 /*
244                  * pointer to an array holding the palette data.  The size of the array is
245                  * num_palette_entries * entry_bytes in size.  The order of the components
246                  * in the palette is described by the component_order in VAImage struct
247                  */
248                 unsigned char *palette
249         );
250         
251         VAStatus (*vaGetImage) (
252                 VADriverContextP ctx,
253                 VASurfaceID surface,
254                 int x,     /* coordinates of the upper left source pixel */
255                 int y,
256                 unsigned int width, /* width and height of the region */
257                 unsigned int height,
258                 VAImageID image
259         );
260
261         VAStatus (*vaPutImage) (
262                 VADriverContextP ctx,
263                 VASurfaceID surface,
264                 VAImageID image,
265                 int src_x,
266                 int src_y,
267                 unsigned int src_width,
268                 unsigned int src_height,
269                 int dest_x,
270                 int dest_y,
271                 unsigned int dest_width,
272                 unsigned int dest_height
273         );
274
275         VAStatus (*vaQuerySubpictureFormats) (
276                 VADriverContextP ctx,
277                 VAImageFormat *format_list,        /* out */
278                 unsigned int *flags,       /* out */
279                 unsigned int *num_formats  /* out */
280         );
281
282         VAStatus (*vaCreateSubpicture) (
283                 VADriverContextP ctx,
284                 VAImageID image,
285                 VASubpictureID *subpicture   /* out */
286         );
287
288         VAStatus (*vaDestroySubpicture) (
289                 VADriverContextP ctx,
290                 VASubpictureID subpicture
291         );
292
293         VAStatus (*vaSetSubpictureImage) (
294                 VADriverContextP ctx,
295                 VASubpictureID subpicture,
296                 VAImageID image
297         );
298
299         VAStatus (*vaSetSubpictureChromakey) (
300                 VADriverContextP ctx,
301                 VASubpictureID subpicture,
302                 unsigned int chromakey_min,
303                 unsigned int chromakey_max,
304                 unsigned int chromakey_mask
305         );
306
307         VAStatus (*vaSetSubpictureGlobalAlpha) (
308                 VADriverContextP ctx,
309                 VASubpictureID subpicture,
310                 float global_alpha 
311         );
312
313         VAStatus (*vaAssociateSubpicture) (
314                 VADriverContextP ctx,
315                 VASubpictureID subpicture,
316                 VASurfaceID *target_surfaces,
317                 int num_surfaces,
318                 short src_x, /* upper left offset in subpicture */
319                 short src_y,
320                 unsigned short src_width,
321                 unsigned short src_height,
322                 short dest_x, /* upper left offset in surface */
323                 short dest_y,
324                 unsigned short dest_width,
325                 unsigned short dest_height,
326                 /*
327                  * whether to enable chroma-keying or global-alpha
328                  * see VA_SUBPICTURE_XXX values
329                  */
330                 unsigned int flags
331         );
332
333         VAStatus (*vaDeassociateSubpicture) (
334                 VADriverContextP ctx,
335                 VASubpictureID subpicture,
336                 VASurfaceID *target_surfaces,
337                 int num_surfaces
338         );
339
340         VAStatus (*vaQueryDisplayAttributes) (
341                 VADriverContextP ctx,
342                 VADisplayAttribute *attr_list,  /* out */
343                 int *num_attributes             /* out */
344         );
345
346         VAStatus (*vaGetDisplayAttributes) (
347                 VADriverContextP ctx,
348                 VADisplayAttribute *attr_list,  /* in/out */
349                 int num_attributes
350         );
351         
352         VAStatus (*vaSetDisplayAttributes) (
353                 VADriverContextP ctx,
354                 VADisplayAttribute *attr_list,
355                 int num_attributes
356         );
357
358         /* device specific */
359         VAStatus (*vaCreateSurfaceFromCIFrame) (
360                 VADriverContextP ctx,
361                 unsigned long frame_id,
362                 VASurfaceID *surface            /* out */
363         );
364     
365     
366         VAStatus (*vaCreateSurfaceFromV4L2Buf) (
367                 VADriverContextP ctx,
368                 int v4l2_fd,         /* file descriptor of V4L2 device */
369                 struct v4l2_format *v4l2_fmt,       /* format of V4L2 */
370                 struct v4l2_buffer *v4l2_buf,       /* V4L2 buffer */
371                 VASurfaceID *surface               /* out */
372         );
373
374         VAStatus (*vaBufferInfo) (
375                    VADriverContextP ctx,
376                    VAContextID context, /* in */
377                    VABufferID buf_id, /* in */
378                    VABufferType *type,    /* out */
379                    unsigned int *size,    /* out */
380                    unsigned int *num_elements /* out */
381         );
382
383     
384         VAStatus (*vaCopySurfaceToBuffer) (
385                 VADriverContextP ctx,
386                 VASurfaceID surface,
387                 unsigned int *fourcc, /* out  for follow argument */
388                 unsigned int *luma_stride,
389                 unsigned int *chroma_u_stride,
390                 unsigned int *chroma_v_stride,
391                 unsigned int *luma_offset,
392                 unsigned int *chroma_u_offset,
393                 unsigned int *chroma_v_offset,
394                 void **buffer
395         );
396 };
397
398 struct VADriverContext
399 {
400     void *pDriverData;
401     struct VADriverVTable vtable;
402
403     void *native_dpy;
404     int x11_screen;
405     int version_major;
406     int version_minor;
407     int max_profiles;
408     int max_entrypoints;
409     int max_attributes;
410     int max_image_formats;
411     int max_subpic_formats;
412     int max_display_attributes;
413     const char *str_vendor;
414
415     void *handle;                       /* dlopen handle */
416     
417     void *dri_state;
418 };
419
420 #define VA_DISPLAY_MAGIC 0x56414430 /* VAD0 */
421 struct VADisplayContext
422 {
423     int vadpy_magic;
424     
425     VADisplayContextP pNext;
426     VADriverContextP pDriverContext;
427
428     int (*vaIsValid) (
429         VADisplayContextP ctx
430     );
431
432     void (*vaDestroy) (
433         VADisplayContextP ctx
434     );
435
436     VAStatus (*vaGetDriverName) (
437         VADisplayContextP ctx,
438         char **driver_name
439     );
440 };
441
442 typedef VAStatus (*VADriverInit) (
443     VADriverContextP driver_context
444 );
445
446
447 #endif /* _VA_BACKEND_H_ */