xref: /aosp_15_r20/external/libva/va/va_backend.h (revision 54e60f844a168e9a219354de272cd517ee8cd4b7)
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/DRM API is used, with a render-node device path */
51     VA_DISPLAY_DRM_RENDERNODES = (VA_DISPLAY_DRM | (1 << 0)),
52     /** \brief VA/Wayland API is used, through vaGetDisplayWl() entry-point. */
53     VA_DISPLAY_WAYLAND  = 0x40,
54     /** \brief VA/Win32 API is used, through vaGetDisplayWin32() entry-point. */
55     VA_DISPLAY_WIN32 = 0x80,
56 };
57 
58 struct VADriverVTable {
59     VAStatus(*vaTerminate)(VADriverContextP ctx);
60 
61     VAStatus(*vaQueryConfigProfiles)(
62         VADriverContextP ctx,
63         VAProfile *profile_list,    /* out */
64         int *num_profiles           /* out */
65     );
66 
67     VAStatus(*vaQueryConfigEntrypoints)(
68         VADriverContextP ctx,
69         VAProfile profile,
70         VAEntrypoint  *entrypoint_list, /* out */
71         int *num_entrypoints            /* out */
72     );
73 
74     VAStatus(*vaGetConfigAttributes)(
75         VADriverContextP ctx,
76         VAProfile profile,
77         VAEntrypoint entrypoint,
78         VAConfigAttrib *attrib_list,    /* in/out */
79         int num_attribs
80     );
81 
82     VAStatus(*vaCreateConfig)(
83         VADriverContextP ctx,
84         VAProfile profile,
85         VAEntrypoint entrypoint,
86         VAConfigAttrib *attrib_list,
87         int num_attribs,
88         VAConfigID *config_id       /* out */
89     );
90 
91     VAStatus(*vaDestroyConfig)(
92         VADriverContextP ctx,
93         VAConfigID config_id
94     );
95 
96     VAStatus(*vaQueryConfigAttributes)(
97         VADriverContextP ctx,
98         VAConfigID config_id,
99         VAProfile *profile,     /* out */
100         VAEntrypoint *entrypoint,   /* out */
101         VAConfigAttrib *attrib_list,    /* out */
102         int *num_attribs        /* out */
103     );
104 
105     VAStatus(*vaCreateSurfaces)(
106         VADriverContextP ctx,
107         int width,
108         int height,
109         int format,
110         int num_surfaces,
111         VASurfaceID *surfaces       /* out */
112     );
113 
114     VAStatus(*vaDestroySurfaces)(
115         VADriverContextP ctx,
116         VASurfaceID *surface_list,
117         int num_surfaces
118     );
119 
120     VAStatus(*vaCreateContext)(
121         VADriverContextP ctx,
122         VAConfigID config_id,
123         int picture_width,
124         int picture_height,
125         int flag,
126         VASurfaceID *render_targets,
127         int num_render_targets,
128         VAContextID *context        /* out */
129     );
130 
131     VAStatus(*vaDestroyContext)(
132         VADriverContextP ctx,
133         VAContextID context
134     );
135 
136     VAStatus(*vaCreateBuffer)(
137         VADriverContextP ctx,
138         VAContextID context,        /* in */
139         VABufferType type,      /* in */
140         unsigned int size,      /* in */
141         unsigned int num_elements,  /* in */
142         void *data,         /* in */
143         VABufferID *buf_id
144     );
145 
146     VAStatus(*vaBufferSetNumElements)(
147         VADriverContextP ctx,
148         VABufferID buf_id,  /* in */
149         unsigned int num_elements   /* in */
150     );
151 
152     VAStatus(*vaMapBuffer)(
153         VADriverContextP ctx,
154         VABufferID buf_id,  /* in */
155         void **pbuf         /* out */
156     );
157 
158     VAStatus(*vaUnmapBuffer)(
159         VADriverContextP ctx,
160         VABufferID buf_id   /* in */
161     );
162 
163     VAStatus(*vaDestroyBuffer)(
164         VADriverContextP ctx,
165         VABufferID buffer_id
166     );
167 
168     VAStatus(*vaBeginPicture)(
169         VADriverContextP ctx,
170         VAContextID context,
171         VASurfaceID render_target
172     );
173 
174     VAStatus(*vaRenderPicture)(
175         VADriverContextP ctx,
176         VAContextID context,
177         VABufferID *buffers,
178         int num_buffers
179     );
180 
181     VAStatus(*vaEndPicture)(
182         VADriverContextP ctx,
183         VAContextID context
184     );
185 
186     VAStatus(*vaSyncSurface)(
187         VADriverContextP ctx,
188         VASurfaceID render_target
189     );
190 
191     VAStatus(*vaQuerySurfaceStatus)(
192         VADriverContextP ctx,
193         VASurfaceID render_target,
194         VASurfaceStatus *status /* out */
195     );
196 
197     VAStatus(*vaQuerySurfaceError)(
198         VADriverContextP ctx,
199         VASurfaceID render_target,
200         VAStatus error_status,
201         void **error_info /*out*/
202     );
203 
204     VAStatus(*vaPutSurface)(
205         VADriverContextP ctx,
206         VASurfaceID surface,
207         void* draw, /* Drawable of window system */
208         short srcx,
209         short srcy,
210         unsigned short srcw,
211         unsigned short srch,
212         short destx,
213         short desty,
214         unsigned short destw,
215         unsigned short desth,
216         VARectangle *cliprects, /* client supplied clip list */
217         unsigned int number_cliprects, /* number of clip rects in the clip list */
218         unsigned int flags /* de-interlacing flags */
219     );
220 
221     VAStatus(*vaQueryImageFormats)(
222         VADriverContextP ctx,
223         VAImageFormat *format_list,        /* out */
224         int *num_formats           /* out */
225     );
226 
227     VAStatus(*vaCreateImage)(
228         VADriverContextP ctx,
229         VAImageFormat *format,
230         int width,
231         int height,
232         VAImage *image     /* out */
233     );
234 
235     VAStatus(*vaDeriveImage)(
236         VADriverContextP ctx,
237         VASurfaceID surface,
238         VAImage *image     /* out */
239     );
240 
241     VAStatus(*vaDestroyImage)(
242         VADriverContextP ctx,
243         VAImageID image
244     );
245 
246     VAStatus(*vaSetImagePalette)(
247         VADriverContextP ctx,
248         VAImageID image,
249         /*
250              * pointer to an array holding the palette data.  The size of the array is
251              * num_palette_entries * entry_bytes in size.  The order of the components
252              * in the palette is described by the component_order in VAImage struct
253              */
254         unsigned char *palette
255     );
256 
257     VAStatus(*vaGetImage)(
258         VADriverContextP ctx,
259         VASurfaceID surface,
260         int x,     /* coordinates of the upper left source pixel */
261         int y,
262         unsigned int width, /* width and height of the region */
263         unsigned int height,
264         VAImageID image
265     );
266 
267     VAStatus(*vaPutImage)(
268         VADriverContextP ctx,
269         VASurfaceID surface,
270         VAImageID image,
271         int src_x,
272         int src_y,
273         unsigned int src_width,
274         unsigned int src_height,
275         int dest_x,
276         int dest_y,
277         unsigned int dest_width,
278         unsigned int dest_height
279     );
280 
281     VAStatus(*vaQuerySubpictureFormats)(
282         VADriverContextP ctx,
283         VAImageFormat *format_list,        /* out */
284         unsigned int *flags,       /* out */
285         unsigned int *num_formats  /* out */
286     );
287 
288     VAStatus(*vaCreateSubpicture)(
289         VADriverContextP ctx,
290         VAImageID image,
291         VASubpictureID *subpicture   /* out */
292     );
293 
294     VAStatus(*vaDestroySubpicture)(
295         VADriverContextP ctx,
296         VASubpictureID subpicture
297     );
298 
299     VAStatus(*vaSetSubpictureImage)(
300         VADriverContextP ctx,
301         VASubpictureID subpicture,
302         VAImageID image
303     );
304 
305     VAStatus(*vaSetSubpictureChromakey)(
306         VADriverContextP ctx,
307         VASubpictureID subpicture,
308         unsigned int chromakey_min,
309         unsigned int chromakey_max,
310         unsigned int chromakey_mask
311     );
312 
313     VAStatus(*vaSetSubpictureGlobalAlpha)(
314         VADriverContextP ctx,
315         VASubpictureID subpicture,
316         float global_alpha
317     );
318 
319     VAStatus(*vaAssociateSubpicture)(
320         VADriverContextP ctx,
321         VASubpictureID subpicture,
322         VASurfaceID *target_surfaces,
323         int num_surfaces,
324         short src_x, /* upper left offset in subpicture */
325         short src_y,
326         unsigned short src_width,
327         unsigned short src_height,
328         short dest_x, /* upper left offset in surface */
329         short dest_y,
330         unsigned short dest_width,
331         unsigned short dest_height,
332         /*
333          * whether to enable chroma-keying or global-alpha
334          * see VA_SUBPICTURE_XXX values
335          */
336         unsigned int flags
337     );
338 
339     VAStatus(*vaDeassociateSubpicture)(
340         VADriverContextP ctx,
341         VASubpictureID subpicture,
342         VASurfaceID *target_surfaces,
343         int num_surfaces
344     );
345 
346     VAStatus(*vaQueryDisplayAttributes)(
347         VADriverContextP ctx,
348         VADisplayAttribute *attr_list,  /* out */
349         int *num_attributes     /* out */
350     );
351 
352     VAStatus(*vaGetDisplayAttributes)(
353         VADriverContextP ctx,
354         VADisplayAttribute *attr_list,  /* in/out */
355         int num_attributes
356     );
357 
358     VAStatus(*vaSetDisplayAttributes)(
359         VADriverContextP ctx,
360         VADisplayAttribute *attr_list,
361         int num_attributes
362     );
363 
364     /* used by va trace */
365     VAStatus(*vaBufferInfo)(
366         VADriverContextP ctx,      /* in */
367         VABufferID buf_id,         /* in */
368         VABufferType *type,        /* out */
369         unsigned int *size,        /* out */
370         unsigned int *num_elements /* out */
371     );
372 
373     /* lock/unlock surface for external access */
374     VAStatus(*vaLockSurface)(
375         VADriverContextP ctx,
376         VASurfaceID surface,
377         unsigned int *fourcc, /* out  for follow argument */
378         unsigned int *luma_stride,
379         unsigned int *chroma_u_stride,
380         unsigned int *chroma_v_stride,
381         unsigned int *luma_offset,
382         unsigned int *chroma_u_offset,
383         unsigned int *chroma_v_offset,
384         unsigned int *buffer_name, /* if it is not NULL, assign the low lever
385                                             * surface buffer name
386                                             */
387         void **buffer /* if it is not NULL, map the surface buffer for
388                                 * CPU access
389                                 */
390     );
391 
392     VAStatus(*vaUnlockSurface)(
393         VADriverContextP ctx,
394         VASurfaceID surface
395     );
396 
397     /* DEPRECATED */
398     VAStatus
399     (*vaGetSurfaceAttributes)(
400         VADriverContextP    dpy,
401         VAConfigID          config,
402         VASurfaceAttrib    *attrib_list,
403         unsigned int        num_attribs
404     );
405 
406     VAStatus
407     (*vaCreateSurfaces2)(
408         VADriverContextP    ctx,
409         unsigned int        format,
410         unsigned int        width,
411         unsigned int        height,
412         VASurfaceID        *surfaces,
413         unsigned int        num_surfaces,
414         VASurfaceAttrib    *attrib_list,
415         unsigned int        num_attribs
416     );
417 
418     VAStatus
419     (*vaQuerySurfaceAttributes)(
420         VADriverContextP    dpy,
421         VAConfigID          config,
422         VASurfaceAttrib    *attrib_list,
423         unsigned int       *num_attribs
424     );
425 
426     VAStatus
427     (*vaAcquireBufferHandle)(
428         VADriverContextP    ctx,
429         VABufferID          buf_id,         /* in */
430         VABufferInfo *      buf_info        /* in/out */
431     );
432 
433     VAStatus
434     (*vaReleaseBufferHandle)(
435         VADriverContextP    ctx,
436         VABufferID          buf_id          /* in */
437     );
438 
439     VAStatus(*vaCreateMFContext)(
440         VADriverContextP ctx,
441         VAMFContextID *mfe_context    /* out */
442     );
443 
444     VAStatus(*vaMFAddContext)(
445         VADriverContextP ctx,
446         VAMFContextID mf_context,
447         VAContextID context
448     );
449 
450     VAStatus(*vaMFReleaseContext)(
451         VADriverContextP ctx,
452         VAMFContextID mf_context,
453         VAContextID context
454     );
455 
456     VAStatus(*vaMFSubmit)(
457         VADriverContextP ctx,
458         VAMFContextID mf_context,
459         VAContextID *contexts,
460         int num_contexts
461     );
462     VAStatus(*vaCreateBuffer2)(
463         VADriverContextP ctx,
464         VAContextID context,                /* in */
465         VABufferType type,                  /* in */
466         unsigned int width,                 /* in */
467         unsigned int height,                /* in */
468         unsigned int *unit_size,            /* out */
469         unsigned int *pitch,                /* out */
470         VABufferID *buf_id                  /* out */
471     );
472 
473     VAStatus(*vaQueryProcessingRate)(
474         VADriverContextP ctx,               /* in */
475         VAConfigID config_id,               /* in */
476         VAProcessingRateParameter *proc_buf,/* in */
477         unsigned int *processing_rate   /* out */
478     );
479 
480     VAStatus
481     (*vaExportSurfaceHandle)(
482         VADriverContextP    ctx,
483         VASurfaceID         surface_id,     /* in */
484         uint32_t            mem_type,       /* in */
485         uint32_t            flags,          /* in */
486         void               *descriptor      /* out */
487     );
488     VAStatus(*vaSyncSurface2)(
489         VADriverContextP ctx,
490         VASurfaceID surface,
491         uint64_t timeout_ns
492     );
493 
494     VAStatus(*vaSyncBuffer)(
495         VADriverContextP ctx,
496         VABufferID buf_id,
497         uint64_t timeout_ns
498     );
499 
500     VAStatus
501     (*vaCopy)(
502         VADriverContextP    ctx,            /* in */
503         VACopyObject        *dst,           /* in */
504         VACopyObject        *src,           /* in */
505         VACopyOption        option          /* in */
506     );
507 
508     VAStatus(*vaMapBuffer2)(
509         VADriverContextP ctx,
510         VABufferID buf_id,                  /* in */
511         void **pbuf,                        /* out */
512         uint32_t flags                      /* in */
513     );
514     /** \brief Reserved bytes for future use, must be zero */
515     unsigned long reserved[53];
516 
517 };
518 
519 struct VADriverContext {
520     void *pDriverData;
521 
522     /**
523      * The core VA implementation hooks.
524      *
525      * This structure is allocated from libva with calloc().
526      */
527     struct VADriverVTable *vtable;
528 
529     /**
530      * The VA/GLX implementation hooks.
531      *
532      * This structure is intended for drivers that implement the
533      * VA/GLX API. The driver implementation is responsible for the
534      * allocation and deallocation of this structure.
535      */
536     struct VADriverVTableGLX *vtable_glx;
537 
538     /**
539      * The VA/EGL implementation hooks.
540      *
541      * This structure is intended for drivers that implement the
542      * VA/EGL API. The driver implementation is responsible for the
543      * allocation and deallocation of this structure.
544      */
545     struct VADriverVTableEGL *vtable_egl;
546 
547     /**
548      * The third-party/private implementation hooks.
549      *
550      * This structure is intended for drivers that implement the
551      * private API. The driver implementation is responsible for the
552      * allocation and deallocation of this structure.
553      */
554     void *vtable_tpi;
555 
556     void *native_dpy;
557     int x11_screen;
558     int version_major;
559     int version_minor;
560     int max_profiles;
561     int max_entrypoints;
562     int max_attributes;
563     int max_image_formats;
564     int max_subpic_formats;
565     int max_display_attributes;
566     const char *str_vendor;
567 
568     void *handle;           /* dlopen handle */
569 
570     /**
571      * \brief DRM state.
572      *
573      * This field holds driver specific data for DRM-based
574      * drivers. This structure is allocated from libva with
575      * calloc(). Do not deallocate from within VA driver
576      * implementations.
577      *
578      * All structures shall be derived from struct drm_state. So, for
579      * instance, this field holds a dri_state structure for VA/X11
580      * drivers that use the DRM protocol.
581      */
582     void *drm_state;
583 
584     void *glx;              /* opaque for GLX code */
585 
586     /** \brief VA display type. */
587     unsigned long display_type;
588 
589     /**
590      * The VA/Wayland implementation hooks.
591      *
592      * This structure is intended for drivers that implement the
593      * VA/Wayland API. libVA allocates this structure with calloc()
594      * and owns the resulting memory.
595      */
596     struct VADriverVTableWayland *vtable_wayland;
597 
598     /**
599      * \brief The VA/VPP implementation hooks.
600      *
601      * This structure is allocated from libva with calloc().
602      */
603     struct VADriverVTableVPP *vtable_vpp;
604 
605     char *override_driver_name;
606 
607     void *pDisplayContext;
608 
609     /**
610      * Error callback.
611      *
612      * This is set by libva when the driver is opened, and will not be
613      * changed thereafter.  The driver can call it with an error message,
614      * which will be propagated to the API user through their error
615      * callbacks, or sent to a default output if no callback is available.
616      *
617      * It is expected that end users will always be able to see these
618      * messages, so it should be called only for serious errors.  For
619      * example, hardware problems or fatal configuration errors.
620      *
621      * @param pDriverContext  Pointer to the driver context structure
622      *                        being used by the current driver.
623      * @param message  Message to send to the API user.  This must be a
624      *                 null-terminated string.
625      */
626     void (*error_callback)(VADriverContextP pDriverContext,
627                            const char *message);
628     /**
629      * Info callback.
630      *
631      * This has the same behaviour as the error callback, but has its
632      * own set of callbacks to the API user.
633      *
634      * It should be used for informational messages which may be useful
635      * for an application programmer or for debugging.  For example, minor
636      * configuration errors, or information about the reason when another
637      * API call generates an error return.  It is not expected that end
638      * users will see these messages.
639      *
640      * @param pDriverContext  Pointer to the driver context structure
641      *                        being used by the current driver.
642      * @param message  Message to send to the API user.  This must be a
643      *                 null-terminated string.
644      */
645     void (*info_callback)(VADriverContextP pDriverContext,
646                           const char *message);
647 
648     /**
649      * \brief The VA/Protected implementation hooks.
650      *
651      * This structure is allocated from libva with calloc().
652      */
653     struct VADriverVTableProt *vtable_prot;
654 
655     unsigned long reserved[37];         /* reserve for future add-ins, decrease the subscript accordingly */
656 };
657 
658 #define VA_DISPLAY_MAGIC 0x56414430 /* VAD0 */
659 struct VADisplayContext {
660     int vadpy_magic;
661 
662     VADisplayContextP pNext;
663     VADriverContextP pDriverContext;
664 
665     /* Deprecated */
666     int (*vaIsValid)(
667         VADisplayContextP ctx
668     );
669 
670     void (*vaDestroy)(
671         VADisplayContextP ctx
672     );
673 
674     /* Deprecated */
675     VAStatus(*vaGetDriverName)(
676         VADisplayContextP ctx,
677         char **driver_name
678     );
679 
680     void *opaque; /* opaque for display extensions (e.g. GLX) */
681     void *vatrace; /* opaque for VA trace context */
682     /* Deprecated */
683     void *vafool; /* opaque for VA fool context */
684 
685     VAMessageCallback error_callback;
686     void *error_callback_user_context;
687     VAMessageCallback info_callback;
688     void *info_callback_user_context;
689 
690     /* Deprecated */
691     VAStatus(*vaGetNumCandidates)(
692         VADisplayContextP ctx,
693         int * num_candidates
694     );
695 
696     /* Deprecated */
697     VAStatus(*vaGetDriverNameByIndex)(
698         VADisplayContextP ctx,
699         char **driver_name,
700         int  candidate_index
701     );
702 
703     /**
704      * \brief Callback to get an array of driver names.
705      *
706      *
707      * The caller must provide a num_drivers
708      * This structure is allocated from libva with calloc().
709      *
710      * @param drivers  An num_drivers sized array of null terminated strings.
711      *                 The array is managed my the caller. The callee will
712      *                 populate the individual driver name strings and the
713      *                 caller must free them.
714      * @param num_driver The number of driver strings contained within drivers.
715      *                   The caller must set that to the size of the drivers
716      *                   array, where the callee will update the value to
717      *                   min(caller num_driver, num_drivers_support).
718      */
719     VAStatus(*vaGetDriverNames)(
720         VADisplayContextP ctx,
721         char **drivers,
722         unsigned *num_drivers
723     );
724 
725     /** \brief Reserved bytes for future use, must be zero */
726     unsigned long reserved[29];
727 };
728 
729 typedef VAStatus(*VADriverInit)(
730     VADriverContextP driver_context
731 );
732 
733 #endif /* _VA_BACKEND_H_ */
734