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