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