Merge branch 'master' of ssh://git@moblin.intel.com/umg-moorestown-libva
[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 (*vaQueryImageFormats) (
197                 VADriverContextP ctx,
198                 VAImageFormat *format_list,        /* out */
199                 int *num_formats           /* out */
200         );
201
202         VAStatus (*vaCreateImage) (
203                 VADriverContextP ctx,
204                 VAImageFormat *format,
205                 int width,
206                 int height,
207                 VAImage *image     /* out */
208         );
209
210         VAStatus (*vaDeriveImage) (
211                 VADriverContextP ctx,
212                 VASurfaceID surface,
213                 VAImage *image     /* out */
214         );
215
216         VAStatus (*vaDestroyImage) (
217                 VADriverContextP ctx,
218                 VAImageID image
219         );
220         
221         VAStatus (*vaSetImagePalette) (
222                 VADriverContextP ctx,
223                 VAImageID image,
224                 /*
225                  * pointer to an array holding the palette data.  The size of the array is
226                  * num_palette_entries * entry_bytes in size.  The order of the components
227                  * in the palette is described by the component_order in VAImage struct
228                  */
229                 unsigned char *palette
230         );
231         
232         VAStatus (*vaGetImage) (
233                 VADriverContextP ctx,
234                 VASurfaceID surface,
235                 int x,     /* coordinates of the upper left source pixel */
236                 int y,
237                 unsigned int width, /* width and height of the region */
238                 unsigned int height,
239                 VAImageID image
240         );
241
242         VAStatus (*vaPutImage) (
243                 VADriverContextP ctx,
244                 VASurfaceID surface,
245                 VAImageID image,
246                 int src_x,
247                 int src_y,
248                 unsigned int src_width,
249                 unsigned int src_height,
250                 int dest_x,
251                 int dest_y,
252                 unsigned int dest_width,
253                 unsigned int dest_height
254         );
255
256         VAStatus (*vaQuerySubpictureFormats) (
257                 VADriverContextP ctx,
258                 VAImageFormat *format_list,        /* out */
259                 unsigned int *flags,       /* out */
260                 unsigned int *num_formats  /* out */
261         );
262
263         VAStatus (*vaCreateSubpicture) (
264                 VADriverContextP ctx,
265                 VAImageID image,
266                 VASubpictureID *subpicture   /* out */
267         );
268
269         VAStatus (*vaDestroySubpicture) (
270                 VADriverContextP ctx,
271                 VASubpictureID subpicture
272         );
273
274         VAStatus (*vaSetSubpictureImage) (
275                 VADriverContextP ctx,
276                 VASubpictureID subpicture,
277                 VAImageID image
278         );
279
280         VAStatus (*vaSetSubpictureChromakey) (
281                 VADriverContextP ctx,
282                 VASubpictureID subpicture,
283                 unsigned int chromakey_min,
284                 unsigned int chromakey_max,
285                 unsigned int chromakey_mask
286         );
287
288         VAStatus (*vaSetSubpictureGlobalAlpha) (
289                 VADriverContextP ctx,
290                 VASubpictureID subpicture,
291                 float global_alpha 
292         );
293
294         VAStatus (*vaAssociateSubpicture) (
295                 VADriverContextP ctx,
296                 VASubpictureID subpicture,
297                 VASurfaceID *target_surfaces,
298                 int num_surfaces,
299                 short src_x, /* upper left offset in subpicture */
300                 short src_y,
301                 unsigned short src_width,
302                 unsigned short src_height,
303                 short dest_x, /* upper left offset in surface */
304                 short dest_y,
305                 unsigned short dest_width,
306                 unsigned short dest_height,
307                 /*
308                  * whether to enable chroma-keying or global-alpha
309                  * see VA_SUBPICTURE_XXX values
310                  */
311                 unsigned int flags
312         );
313
314         VAStatus (*vaDeassociateSubpicture) (
315                 VADriverContextP ctx,
316                 VASubpictureID subpicture,
317                 VASurfaceID *target_surfaces,
318                 int num_surfaces
319         );
320
321         VAStatus (*vaQueryDisplayAttributes) (
322                 VADriverContextP ctx,
323                 VADisplayAttribute *attr_list,  /* out */
324                 int *num_attributes             /* out */
325         );
326
327         VAStatus (*vaGetDisplayAttributes) (
328                 VADriverContextP ctx,
329                 VADisplayAttribute *attr_list,  /* in/out */
330                 int num_attributes
331         );
332         
333         VAStatus (*vaSetDisplayAttributes) (
334                 VADriverContextP ctx,
335                 VADisplayAttribute *attr_list,
336                 int num_attributes
337         );
338
339         /* device specific */
340         VAStatus (*vaCreateSurfaceFromCIFrame) (
341                 VADriverContextP ctx,
342                 unsigned long frame_id,
343                 VASurfaceID *surface            /* out */
344         );
345     
346     
347         VAStatus (*vaCreateSurfaceFromV4L2Buf) (
348                 VADriverContextP ctx,
349                 int v4l2_fd,         /* file descriptor of V4L2 device */
350                 struct v4l2_format *v4l2_fmt,       /* format of V4L2 */
351                 struct v4l2_buffer *v4l2_buf,       /* V4L2 buffer */
352                 VASurfaceID *surface               /* out */
353         );
354
355         VAStatus (*vaBufferInfo) (
356                    VADriverContextP ctx,
357                    VAContextID context, /* in */
358                    VABufferID buf_id, /* in */
359                    VABufferType *type,    /* out */
360                    unsigned int *size,    /* out */
361                    unsigned int *num_elements /* out */
362         );
363
364     
365         VAStatus (*vaCopySurfaceToBuffer) (
366                 VADriverContextP ctx,
367                 VASurfaceID surface,
368                 unsigned int *fourcc, /* out  for follow argument */
369                 unsigned int *luma_stride,
370                 unsigned int *chroma_u_stride,
371                 unsigned int *chroma_v_stride,
372                 unsigned int *luma_offset,
373                 unsigned int *chroma_u_offset,
374                 unsigned int *chroma_v_offset,
375                 void **buffer
376         );
377 };
378
379 struct VADriverContext
380 {
381     void *pDriverData;
382     struct VADriverVTable vtable;
383
384     void *native_dpy;
385     int x11_screen;
386     int version_major;
387     int version_minor;
388     int max_profiles;
389     int max_entrypoints;
390     int max_attributes;
391     int max_image_formats;
392     int max_subpic_formats;
393     int max_display_attributes;
394     const char *str_vendor;
395
396     void *handle;                       /* dlopen handle */
397     
398     void *dri_state;
399 };
400
401 #define VA_DISPLAY_MAGIC 0x56414430 /* VAD0 */
402 struct VADisplayContext
403 {
404     int vadpy_magic;
405     
406     VADisplayContextP pNext;
407     VADriverContextP pDriverContext;
408
409     int (*vaIsValid) (
410         VADisplayContextP ctx
411     );
412
413     void (*vaDestroy) (
414         VADisplayContextP ctx
415     );
416
417     VAStatus (*vaGetDriverName) (
418         VADisplayContextP ctx,
419         char **driver_name
420     );
421 };
422
423 typedef VAStatus (*VADriverInit) (
424     VADriverContextP driver_context
425 );
426
427
428 #endif /* _VA_BACKEND_H_ */