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