OSDN Git Service

API: add support for raw DRM.
[android-x86/hardware-intel-common-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 <linux/videodev2.h>
34
35 typedef struct VADriverContext *VADriverContextP;
36 typedef struct VADisplayContext *VADisplayContextP;
37
38 /** \brief VA display types. */
39 enum {
40     /** \brief Mask to major identifier for VA display type. */
41     VA_DISPLAY_MAJOR_MASK = 0xf0,
42
43     /** \brief VA/X11 API is used, through vaGetDisplay() entry-point. */
44     VA_DISPLAY_X11      = 0x10,
45     /** \brief VA/GLX API is used, through vaGetDisplayGLX() entry-point. */
46     VA_DISPLAY_GLX      = (VA_DISPLAY_X11 | (1 << 0)),
47     /** \brief VA/Android API is used, through vaGetDisplay() entry-point. */
48     VA_DISPLAY_ANDROID  = 0x20,
49     /** \brief VA/DRM API is used, through vaGetDisplayDRM() entry-point. */
50     VA_DISPLAY_DRM      = 0x30,
51 };
52
53 struct VADriverVTable
54 {
55         VAStatus (*vaTerminate) ( VADriverContextP ctx );
56
57         VAStatus (*vaQueryConfigProfiles) (
58                 VADriverContextP ctx,
59                 VAProfile *profile_list,        /* out */
60                 int *num_profiles                       /* out */
61         );
62
63         VAStatus (*vaQueryConfigEntrypoints) (
64                 VADriverContextP ctx,
65                 VAProfile profile,
66                 VAEntrypoint  *entrypoint_list, /* out */
67                 int *num_entrypoints                    /* out */
68         );
69
70         VAStatus (*vaGetConfigAttributes) (
71                 VADriverContextP ctx,
72                 VAProfile profile,
73                 VAEntrypoint entrypoint,
74                 VAConfigAttrib *attrib_list,    /* in/out */
75                 int num_attribs
76         );
77
78         VAStatus (*vaCreateConfig) (
79                 VADriverContextP ctx,
80                 VAProfile profile, 
81                 VAEntrypoint entrypoint, 
82                 VAConfigAttrib *attrib_list,
83                 int num_attribs,
84                 VAConfigID *config_id           /* out */
85         );
86
87         VAStatus (*vaDestroyConfig) (
88                 VADriverContextP ctx,
89                 VAConfigID config_id
90         );
91
92         VAStatus (*vaQueryConfigAttributes) (
93                 VADriverContextP ctx,
94                 VAConfigID config_id, 
95                 VAProfile *profile,             /* out */
96                 VAEntrypoint *entrypoint,       /* out */
97                 VAConfigAttrib *attrib_list,    /* out */
98                 int *num_attribs                /* out */
99         );
100
101         VAStatus (*vaCreateSurfaces) (
102                 VADriverContextP ctx,
103                 int width,
104                 int height,
105                 int format,
106                 int num_surfaces,
107                 VASurfaceID *surfaces           /* out */
108         );
109
110         VAStatus (*vaDestroySurfaces) (
111                 VADriverContextP ctx,
112                 VASurfaceID *surface_list,
113                 int num_surfaces
114         );
115
116         VAStatus (*vaCreateContext) (
117                 VADriverContextP ctx,
118                 VAConfigID config_id,
119                 int picture_width,
120                 int picture_height,
121                 int flag,
122                 VASurfaceID *render_targets,
123                 int num_render_targets,
124                 VAContextID *context            /* out */
125         );
126
127         VAStatus (*vaDestroyContext) (
128                 VADriverContextP ctx,
129                 VAContextID context
130         );
131
132         VAStatus (*vaCreateBuffer) (
133                 VADriverContextP ctx,
134                 VAContextID context,            /* in */
135                 VABufferType type,              /* in */
136                 unsigned int size,              /* in */
137                 unsigned int num_elements,      /* in */
138                 void *data,                     /* in */
139                 VABufferID *buf_id              /* out */
140         );
141
142         VAStatus (*vaBufferSetNumElements) (
143                 VADriverContextP ctx,
144                 VABufferID buf_id,      /* in */
145                 unsigned int num_elements       /* in */
146         );
147
148         VAStatus (*vaMapBuffer) (
149                 VADriverContextP ctx,
150                 VABufferID buf_id,      /* in */
151                 void **pbuf         /* out */
152         );
153
154         VAStatus (*vaUnmapBuffer) (
155                 VADriverContextP ctx,
156                 VABufferID buf_id       /* in */
157         );
158
159         VAStatus (*vaDestroyBuffer) (
160                 VADriverContextP ctx,
161                 VABufferID buffer_id
162         );
163
164         VAStatus (*vaBeginPicture) (
165                 VADriverContextP ctx,
166                 VAContextID context,
167                 VASurfaceID render_target
168         );
169
170         VAStatus (*vaRenderPicture) (
171                 VADriverContextP ctx,
172                 VAContextID context,
173                 VABufferID *buffers,
174                 int num_buffers
175         );
176
177         VAStatus (*vaEndPicture) (
178                 VADriverContextP ctx,
179                 VAContextID context
180         );
181
182         VAStatus (*vaSyncSurface) (
183                 VADriverContextP ctx,
184                 VASurfaceID render_target
185         );
186
187         VAStatus (*vaQuerySurfaceStatus) (
188                 VADriverContextP ctx,
189                 VASurfaceID render_target,
190                 VASurfaceStatus *status /* out */
191         );
192
193         VAStatus (*vaQuerySurfaceError) (
194                 VADriverContextP ctx,
195                 VASurfaceID render_target,
196                 VAStatus error_status,
197                 void **error_info /*out*/
198         );
199
200         VAStatus (*vaPutSurface) (
201                 VADriverContextP ctx,
202                 VASurfaceID surface,
203                 void* draw, /* Drawable of window system */
204                 short srcx,
205                 short srcy,
206                 unsigned short srcw,
207                 unsigned short srch,
208                 short destx,
209                 short desty,
210                 unsigned short destw,
211                 unsigned short desth,
212                 VARectangle *cliprects, /* client supplied clip list */
213                 unsigned int number_cliprects, /* number of clip rects in the clip list */
214                 unsigned int flags /* de-interlacing flags */
215         );
216
217         VAStatus (*vaQueryImageFormats) (
218                 VADriverContextP ctx,
219                 VAImageFormat *format_list,        /* out */
220                 int *num_formats           /* out */
221         );
222
223         VAStatus (*vaCreateImage) (
224                 VADriverContextP ctx,
225                 VAImageFormat *format,
226                 int width,
227                 int height,
228                 VAImage *image     /* out */
229         );
230
231         VAStatus (*vaDeriveImage) (
232                 VADriverContextP ctx,
233                 VASurfaceID surface,
234                 VAImage *image     /* out */
235         );
236
237         VAStatus (*vaDestroyImage) (
238                 VADriverContextP ctx,
239                 VAImageID image
240         );
241         
242         VAStatus (*vaSetImagePalette) (
243                 VADriverContextP ctx,
244                 VAImageID image,
245                 /*
246                  * pointer to an array holding the palette data.  The size of the array is
247                  * num_palette_entries * entry_bytes in size.  The order of the components
248                  * in the palette is described by the component_order in VAImage struct
249                  */
250                 unsigned char *palette
251         );
252         
253         VAStatus (*vaGetImage) (
254                 VADriverContextP ctx,
255                 VASurfaceID surface,
256                 int x,     /* coordinates of the upper left source pixel */
257                 int y,
258                 unsigned int width, /* width and height of the region */
259                 unsigned int height,
260                 VAImageID image
261         );
262
263         VAStatus (*vaPutImage) (
264                 VADriverContextP ctx,
265                 VASurfaceID surface,
266                 VAImageID image,
267                 int src_x,
268                 int src_y,
269                 unsigned int src_width,
270                 unsigned int src_height,
271                 int dest_x,
272                 int dest_y,
273                 unsigned int dest_width,
274                 unsigned int dest_height
275         );
276
277         VAStatus (*vaQuerySubpictureFormats) (
278                 VADriverContextP ctx,
279                 VAImageFormat *format_list,        /* out */
280                 unsigned int *flags,       /* out */
281                 unsigned int *num_formats  /* out */
282         );
283
284         VAStatus (*vaCreateSubpicture) (
285                 VADriverContextP ctx,
286                 VAImageID image,
287                 VASubpictureID *subpicture   /* out */
288         );
289
290         VAStatus (*vaDestroySubpicture) (
291                 VADriverContextP ctx,
292                 VASubpictureID subpicture
293         );
294
295         VAStatus (*vaSetSubpictureImage) (
296                 VADriverContextP ctx,
297                 VASubpictureID subpicture,
298                 VAImageID image
299         );
300
301         VAStatus (*vaSetSubpictureChromakey) (
302                 VADriverContextP ctx,
303                 VASubpictureID subpicture,
304                 unsigned int chromakey_min,
305                 unsigned int chromakey_max,
306                 unsigned int chromakey_mask
307         );
308
309         VAStatus (*vaSetSubpictureGlobalAlpha) (
310                 VADriverContextP ctx,
311                 VASubpictureID subpicture,
312                 float global_alpha 
313         );
314
315         VAStatus (*vaAssociateSubpicture) (
316                 VADriverContextP ctx,
317                 VASubpictureID subpicture,
318                 VASurfaceID *target_surfaces,
319                 int num_surfaces,
320                 short src_x, /* upper left offset in subpicture */
321                 short src_y,
322                 unsigned short src_width,
323                 unsigned short src_height,
324                 short dest_x, /* upper left offset in surface */
325                 short dest_y,
326                 unsigned short dest_width,
327                 unsigned short dest_height,
328                 /*
329                  * whether to enable chroma-keying or global-alpha
330                  * see VA_SUBPICTURE_XXX values
331                  */
332                 unsigned int flags
333         );
334
335         VAStatus (*vaDeassociateSubpicture) (
336                 VADriverContextP ctx,
337                 VASubpictureID subpicture,
338                 VASurfaceID *target_surfaces,
339                 int num_surfaces
340         );
341
342         VAStatus (*vaQueryDisplayAttributes) (
343                 VADriverContextP ctx,
344                 VADisplayAttribute *attr_list,  /* out */
345                 int *num_attributes             /* out */
346         );
347
348         VAStatus (*vaGetDisplayAttributes) (
349                 VADriverContextP ctx,
350                 VADisplayAttribute *attr_list,  /* in/out */
351                 int num_attributes
352         );
353         
354         VAStatus (*vaSetDisplayAttributes) (
355                 VADriverContextP ctx,
356                 VADisplayAttribute *attr_list,
357                 int num_attributes
358         );
359
360         /* used by va trace */        
361         VAStatus (*vaBufferInfo) (
362                    VADriverContextP ctx,      /* in */
363                    VABufferID buf_id,         /* in */
364                    VABufferType *type,        /* out */
365                    unsigned int *size,        /* out */
366                    unsigned int *num_elements /* out */
367         );
368
369         /* lock/unlock surface for external access */    
370         VAStatus (*vaLockSurface) (
371                 VADriverContextP ctx,
372                 VASurfaceID surface,
373                 unsigned int *fourcc, /* out  for follow argument */
374                 unsigned int *luma_stride,
375                 unsigned int *chroma_u_stride,
376                 unsigned int *chroma_v_stride,
377                 unsigned int *luma_offset,
378                 unsigned int *chroma_u_offset,
379                 unsigned int *chroma_v_offset,
380                 unsigned int *buffer_name, /* if it is not NULL, assign the low lever
381                                             * surface buffer name
382                                             */
383                 void **buffer /* if it is not NULL, map the surface buffer for
384                                 * CPU access
385                                 */
386         );
387     
388         VAStatus (*vaUnlockSurface) (
389                 VADriverContextP ctx,
390                 VASurfaceID surface
391         );
392 };
393
394 struct VADriverContext
395 {
396     void *pDriverData;
397
398     /**
399      * The core VA implementation hooks.
400      *
401      * This structure is allocated from libva with calloc().
402      */
403     struct VADriverVTable *vtable;
404
405     /**
406      * The VA/GLX implementation hooks.
407      *
408      * This structure is intended for drivers that implement the
409      * VA/GLX API. The driver implementation is responsible for the
410      * allocation and deallocation of this structure.
411      */
412     struct VADriverVTableGLX *vtable_glx;
413
414     /**
415      * The VA/EGL implementation hooks.
416      *
417      * This structure is intended for drivers that implement the
418      * VA/EGL API. The driver implementation is responsible for the
419      * allocation and deallocation of this structure.
420      */
421     struct VADriverVTableEGL *vtable_egl;
422
423     /**
424      * The third-party/private implementation hooks.
425      *
426      * This structure is intended for drivers that implement the
427      * private API. The driver implementation is responsible for the
428      * allocation and deallocation of this structure.
429      */
430     void *vtable_tpi;
431
432     void *native_dpy;
433     int x11_screen;
434     int version_major;
435     int version_minor;
436     int max_profiles;
437     int max_entrypoints;
438     int max_attributes;
439     int max_image_formats;
440     int max_subpic_formats;
441     int max_display_attributes;
442     const char *str_vendor;
443
444     void *handle;                       /* dlopen handle */
445
446     /**
447      * \brief DRM state.
448      *
449      * This field holds driver specific data for DRM-based
450      * drivers. This structure is allocated from libva with
451      * calloc(). Do not deallocate from within VA driver
452      * implementations.
453      *
454      * All structures shall be derived from struct drm_state. So, for
455      * instance, this field holds a dri_state structure for VA/X11
456      * drivers that use the DRM protocol.
457      */
458     void *drm_state;
459
460     void *glx;                          /* opaque for GLX code */
461
462     /** \brief VA display type. */
463     unsigned long display_type;
464
465     unsigned long reserved[44];         /* reserve for future add-ins, decrease the subscript accordingly */
466 };
467
468 #define VA_DISPLAY_MAGIC 0x56414430 /* VAD0 */
469 struct VADisplayContext
470 {
471     int vadpy_magic;
472     
473     VADisplayContextP pNext;
474     VADriverContextP pDriverContext;
475
476     int (*vaIsValid) (
477         VADisplayContextP ctx
478     );
479
480     void (*vaDestroy) (
481         VADisplayContextP ctx
482     );
483
484     VAStatus (*vaGetDriverName) (
485         VADisplayContextP ctx,
486         char **driver_name
487     );
488
489     void *opaque; /* opaque for display extensions (e.g. GLX) */
490 };
491
492 typedef VAStatus (*VADriverInit) (
493     VADriverContextP driver_context
494 );
495
496 #endif /* _VA_BACKEND_H_ */