2 * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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.
27 #include "va_backend.h"
38 #define DRIVER_INIT_FUNC "__vaDriverInit_0_31"
40 #define DRIVER_EXTENSION "_drv_video.so"
42 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
43 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
46 #define CHECK_VTABLE(s, ctx, func) if (!va_checkVtable(ctx->vtable.va##func, #func)) s = VA_STATUS_ERROR_UNKNOWN;
47 #define CHECK_MAXIMUM(s, ctx, var) if (!va_checkMaximum(ctx->max_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
48 #define CHECK_STRING(s, ctx, var) if (!va_checkString(ctx->str_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
50 extern int trace_flag;
51 #define VA_TRACE(trace_func,...) \
53 va_TraceMsg("========%s========\n", __func__); \
54 trace_func(__VA_ARGS__); \
57 static int vaDisplayIsValid(VADisplay dpy)
59 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
60 return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
63 static void va_errorMessage(const char *msg, ...)
67 fprintf(stderr, "libva error: ");
69 vfprintf(stderr, msg, args);
73 static void va_infoMessage(const char *msg, ...)
77 fprintf(stderr, "libva: ");
79 vfprintf(stderr, msg, args);
83 static Bool va_checkVtable(void *ptr, char *function)
87 va_errorMessage("No valid vtable entry for va%s\n", function);
93 static Bool va_checkMaximum(int value, char *variable)
97 va_errorMessage("Failed to define max_%s in init\n", variable);
103 static Bool va_checkString(const char* value, char *variable)
107 va_errorMessage("Failed to define str_%s in init\n", variable);
113 static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
115 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
117 return pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
120 static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
122 VADriverContextP ctx = CTX(dpy);
123 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
124 char *search_path = NULL;
128 if (geteuid() == getuid())
130 /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
131 search_path = getenv("LIBVA_DRIVERS_PATH");
134 search_path = getenv("LIBGL_DRIVERS_PATH");
139 search_path = VA_DRIVERS_PATH;
142 search_path = strdup((const char *)search_path);
143 driver_dir = strtok_r((const char *)search_path, ":", &saveptr);
147 char *driver_path = (char *) malloc( strlen(driver_dir) +
148 strlen(driver_name) +
149 strlen(DRIVER_EXTENSION) + 2 );
150 strncpy( driver_path, driver_dir, strlen(driver_dir) + 1);
151 strncat( driver_path, "/", strlen("/") );
152 strncat( driver_path, driver_name, strlen(driver_name) );
153 strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
155 va_infoMessage("Trying to open %s\n", driver_path);
157 handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
160 /* Don't give errors for non-existing files */
161 if (0 == access( driver_path, F_OK))
163 va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
168 VADriverInit init_func;
169 init_func = (VADriverInit) dlsym(handle, DRIVER_INIT_FUNC);
172 va_errorMessage("%s has no function %s\n", driver_path, DRIVER_INIT_FUNC);
177 vaStatus = (*init_func)(ctx);
179 if (VA_STATUS_SUCCESS == vaStatus)
181 CHECK_MAXIMUM(vaStatus, ctx, profiles);
182 CHECK_MAXIMUM(vaStatus, ctx, entrypoints);
183 CHECK_MAXIMUM(vaStatus, ctx, attributes);
184 CHECK_MAXIMUM(vaStatus, ctx, image_formats);
185 CHECK_MAXIMUM(vaStatus, ctx, subpic_formats);
186 CHECK_MAXIMUM(vaStatus, ctx, display_attributes);
187 CHECK_STRING(vaStatus, ctx, vendor);
188 CHECK_VTABLE(vaStatus, ctx, Terminate);
189 CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles);
190 CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints);
191 CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes);
192 CHECK_VTABLE(vaStatus, ctx, CreateConfig);
193 CHECK_VTABLE(vaStatus, ctx, DestroyConfig);
194 CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes);
195 CHECK_VTABLE(vaStatus, ctx, CreateSurfaces);
196 CHECK_VTABLE(vaStatus, ctx, DestroySurfaces);
197 CHECK_VTABLE(vaStatus, ctx, CreateContext);
198 CHECK_VTABLE(vaStatus, ctx, DestroyContext);
199 CHECK_VTABLE(vaStatus, ctx, CreateBuffer);
200 CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements);
201 CHECK_VTABLE(vaStatus, ctx, MapBuffer);
202 CHECK_VTABLE(vaStatus, ctx, UnmapBuffer);
203 CHECK_VTABLE(vaStatus, ctx, DestroyBuffer);
204 CHECK_VTABLE(vaStatus, ctx, BeginPicture);
205 CHECK_VTABLE(vaStatus, ctx, RenderPicture);
206 CHECK_VTABLE(vaStatus, ctx, EndPicture);
207 CHECK_VTABLE(vaStatus, ctx, SyncSurface);
208 CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus);
209 CHECK_VTABLE(vaStatus, ctx, PutSurface);
210 CHECK_VTABLE(vaStatus, ctx, QueryImageFormats);
211 CHECK_VTABLE(vaStatus, ctx, CreateImage);
212 CHECK_VTABLE(vaStatus, ctx, DeriveImage);
213 CHECK_VTABLE(vaStatus, ctx, DestroyImage);
214 CHECK_VTABLE(vaStatus, ctx, SetImagePalette);
215 CHECK_VTABLE(vaStatus, ctx, GetImage);
216 CHECK_VTABLE(vaStatus, ctx, PutImage);
217 CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats);
218 CHECK_VTABLE(vaStatus, ctx, CreateSubpicture);
219 CHECK_VTABLE(vaStatus, ctx, DestroySubpicture);
220 CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage);
221 CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey);
222 CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha);
223 CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture);
224 CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture);
225 CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes);
226 CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes);
227 CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes);
229 if (VA_STATUS_SUCCESS != vaStatus)
231 va_errorMessage("%s init failed\n", driver_path);
234 if (VA_STATUS_SUCCESS == vaStatus)
236 ctx->handle = handle;
244 driver_dir = strtok_r(NULL, ":", &saveptr);
252 VAPrivFunc vaGetLibFunc(VADisplay dpy, const char *func)
254 VADriverContextP ctx;
255 if( !vaDisplayIsValid(dpy) )
259 if (NULL == ctx->handle)
262 return (VAPrivFunc) dlsym(ctx->handle, func);
267 * Returns a short english description of error_status
269 const char *vaErrorStr(VAStatus error_status)
273 case VA_STATUS_SUCCESS:
274 return "success (no error)";
275 case VA_STATUS_ERROR_OPERATION_FAILED:
276 return "operation failed";
277 case VA_STATUS_ERROR_ALLOCATION_FAILED:
278 return "resource allocation failed";
279 case VA_STATUS_ERROR_INVALID_DISPLAY:
280 return "invalid VADisplay";
281 case VA_STATUS_ERROR_INVALID_CONFIG:
282 return "invalid VAConfigID";
283 case VA_STATUS_ERROR_INVALID_CONTEXT:
284 return "invalid VAContextID";
285 case VA_STATUS_ERROR_INVALID_SURFACE:
286 return "invalid VASurfaceID";
287 case VA_STATUS_ERROR_INVALID_BUFFER:
288 return "invalid VABufferID";
289 case VA_STATUS_ERROR_INVALID_IMAGE:
290 return "invalid VAImageID";
291 case VA_STATUS_ERROR_INVALID_SUBPICTURE:
292 return "invalid VASubpictureID";
293 case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
294 return "attribute not supported";
295 case VA_STATUS_ERROR_MAX_NUM_EXCEEDED:
296 return "list argument exceeds maximum number";
297 case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
298 return "the requested VAProfile is not supported";
299 case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
300 return "the requested VAEntryPoint is not supported";
301 case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
302 return "the requested RT Format is not supported";
303 case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
304 return "the requested VABufferType is not supported";
305 case VA_STATUS_ERROR_SURFACE_BUSY:
306 return "surface is in use";
307 case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
308 return "flag not supported";
309 case VA_STATUS_ERROR_INVALID_PARAMETER:
310 return "invalid parameter";
311 case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
312 return "resolution not supported";
313 case VA_STATUS_ERROR_UNIMPLEMENTED:
314 return "the requested function is not implemented";
315 case VA_STATUS_ERROR_SURFACE_IN_DISPLAYING:
316 return "surface is in displaying (may by overlay)" ;
317 case VA_STATUS_ERROR_UNKNOWN:
318 return "unknown libva error";
320 return "unknown libva error / description missing";
323 VAStatus vaInitialize (
325 int *major_version, /* out */
326 int *minor_version /* out */
329 char *driver_name = NULL;
336 va_infoMessage("libva version %s\n", VA_VERSION_S);
338 vaStatus = va_getDriverName(dpy, &driver_name);
339 va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
341 if (VA_STATUS_SUCCESS == vaStatus)
343 vaStatus = va_openDriver(dpy, driver_name);
344 va_infoMessage("va_openDriver() returns %d\n", vaStatus);
346 *major_version = VA_MAJOR_VERSION;
347 *minor_version = VA_MINOR_VERSION;
357 * After this call, all library internal resources will be cleaned up
359 VAStatus vaTerminate (
363 VAStatus vaStatus = VA_STATUS_SUCCESS;
364 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
365 VADriverContextP old_ctx;
372 vaStatus = old_ctx->vtable.vaTerminate(old_ctx);
373 dlclose(old_ctx->handle);
374 old_ctx->handle = NULL;
377 if (VA_STATUS_SUCCESS == vaStatus)
378 pDisplayContext->vaDestroy(pDisplayContext);
386 * vaQueryVendorString returns a pointer to a zero-terminated string
387 * describing some aspects of the VA implemenation on a specific
388 * hardware accelerator. The format of the returned string is:
389 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
390 * e.g. for the Intel GMA500 implementation, an example would be:
391 * "IntelGMA500-1.0-0.2-patch3
393 const char *vaQueryVendorString (
397 if( !vaDisplayIsValid(dpy) )
400 return CTX(dpy)->str_vendor;
404 /* Get maximum number of profiles supported by the implementation */
405 int vaMaxNumProfiles (
409 if( !vaDisplayIsValid(dpy) )
412 return CTX(dpy)->max_profiles;
415 /* Get maximum number of entrypoints supported by the implementation */
416 int vaMaxNumEntrypoints (
420 if( !vaDisplayIsValid(dpy) )
423 return CTX(dpy)->max_entrypoints;
427 /* Get maximum number of attributs supported by the implementation */
428 int vaMaxNumConfigAttributes (
432 if( !vaDisplayIsValid(dpy) )
435 return CTX(dpy)->max_attributes;
438 VAStatus vaQueryConfigEntrypoints (
441 VAEntrypoint *entrypoints, /* out */
442 int *num_entrypoints /* out */
445 VADriverContextP ctx;
449 return ctx->vtable.vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
452 VAStatus vaGetConfigAttributes (
455 VAEntrypoint entrypoint,
456 VAConfigAttrib *attrib_list, /* in/out */
460 VADriverContextP ctx;
464 return ctx->vtable.vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
467 VAStatus vaQueryConfigProfiles (
469 VAProfile *profile_list, /* out */
470 int *num_profiles /* out */
473 VADriverContextP ctx;
477 return ctx->vtable.vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
480 VAStatus vaCreateConfig (
483 VAEntrypoint entrypoint,
484 VAConfigAttrib *attrib_list,
486 VAConfigID *config_id /* out */
489 VADriverContextP ctx;
493 VA_TRACE(va_TraceCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
494 return ctx->vtable.vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
497 VAStatus vaDestroyConfig (
502 VADriverContextP ctx;
506 return ctx->vtable.vaDestroyConfig ( ctx, config_id );
509 VAStatus vaQueryConfigAttributes (
511 VAConfigID config_id,
512 VAProfile *profile, /* out */
513 VAEntrypoint *entrypoint, /* out */
514 VAConfigAttrib *attrib_list,/* out */
515 int *num_attribs /* out */
518 VADriverContextP ctx;
522 return ctx->vtable.vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
525 VAStatus vaCreateSurfaces (
531 VASurfaceID *surfaces /* out */
534 VADriverContextP ctx;
538 VA_TRACE(va_TraceCreateSurface, dpy, width, height, format, num_surfaces, surfaces);
539 return ctx->vtable.vaCreateSurfaces( ctx, width, height, format, num_surfaces, surfaces );
543 VAStatus vaDestroySurfaces (
545 VASurfaceID *surface_list,
549 VADriverContextP ctx;
553 return ctx->vtable.vaDestroySurfaces( ctx, surface_list, num_surfaces );
556 VAStatus vaCreateContext (
558 VAConfigID config_id,
562 VASurfaceID *render_targets,
563 int num_render_targets,
564 VAContextID *context /* out */
567 VADriverContextP ctx;
571 VA_TRACE(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
572 return ctx->vtable.vaCreateContext( ctx, config_id, picture_width, picture_height,
573 flag, render_targets, num_render_targets, context );
576 VAStatus vaDestroyContext (
581 VADriverContextP ctx;
585 return ctx->vtable.vaDestroyContext( ctx, context );
588 VAStatus vaCreateBuffer (
590 VAContextID context, /* in */
591 VABufferType type, /* in */
592 unsigned int size, /* in */
593 unsigned int num_elements, /* in */
595 VABufferID *buf_id /* out */
598 VADriverContextP ctx;
602 return ctx->vtable.vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
605 VAStatus vaBufferSetNumElements (
607 VABufferID buf_id, /* in */
608 unsigned int num_elements /* in */
611 VADriverContextP ctx;
615 return ctx->vtable.vaBufferSetNumElements( ctx, buf_id, num_elements );
619 VAStatus vaMapBuffer (
621 VABufferID buf_id, /* in */
622 void **pbuf /* out */
625 VADriverContextP ctx;
629 return ctx->vtable.vaMapBuffer( ctx, buf_id, pbuf );
632 VAStatus vaUnmapBuffer (
634 VABufferID buf_id /* in */
637 VADriverContextP ctx;
641 return ctx->vtable.vaUnmapBuffer( ctx, buf_id );
644 VAStatus vaDestroyBuffer (
649 VADriverContextP ctx;
653 return ctx->vtable.vaDestroyBuffer( ctx, buffer_id );
656 VAStatus vaBufferInfo (
658 VAContextID context, /* in */
659 VABufferID buf_id, /* in */
660 VABufferType *type, /* out */
661 unsigned int *size, /* out */
662 unsigned int *num_elements /* out */
665 VADriverContextP ctx;
669 if (ctx->vtable.vaBufferInfo)
670 return ctx->vtable.vaBufferInfo( ctx, context, buf_id, type, size, num_elements );
672 return VA_STATUS_ERROR_UNIMPLEMENTED;
675 VAStatus vaBeginPicture (
678 VASurfaceID render_target
681 VADriverContextP ctx;
685 VA_TRACE(va_TraceBeginPicture, ctx, context, render_target);
686 return ctx->vtable.vaBeginPicture( ctx, context, render_target );
689 VAStatus vaRenderPicture (
696 VADriverContextP ctx;
700 VA_TRACE(va_TraceRenderPicture, dpy, context, buffers, num_buffers);
701 return ctx->vtable.vaRenderPicture( ctx, context, buffers, num_buffers );
704 VAStatus vaEndPicture (
709 VADriverContextP ctx;
713 VA_TRACE(va_TraceEndPicture, dpy, context);
714 return ctx->vtable.vaEndPicture( ctx, context );
717 VAStatus vaSyncSurface (
719 VASurfaceID render_target
722 VADriverContextP ctx;
726 return ctx->vtable.vaSyncSurface( ctx, render_target );
729 VAStatus vaQuerySurfaceStatus (
731 VASurfaceID render_target,
732 VASurfaceStatus *status /* out */
735 VADriverContextP ctx;
739 return ctx->vtable.vaQuerySurfaceStatus( ctx, render_target, status );
742 /* Get maximum number of image formats supported by the implementation */
743 int vaMaxNumImageFormats (
747 if( !vaDisplayIsValid(dpy) )
750 return CTX(dpy)->max_image_formats;
753 VAStatus vaQueryImageFormats (
755 VAImageFormat *format_list, /* out */
756 int *num_formats /* out */
759 VADriverContextP ctx;
763 return ctx->vtable.vaQueryImageFormats ( ctx, format_list, num_formats);
767 * The width and height fields returned in the VAImage structure may get
768 * enlarged for some YUV formats. The size of the data buffer that needs
769 * to be allocated will be given in the "data_size" field in VAImage.
770 * Image data is not allocated by this function. The client should
771 * allocate the memory and fill in the VAImage structure's data field
772 * after looking at "data_size" returned from the library.
774 VAStatus vaCreateImage (
776 VAImageFormat *format,
779 VAImage *image /* out */
782 VADriverContextP ctx;
786 return ctx->vtable.vaCreateImage ( ctx, format, width, height, image);
790 * Should call DestroyImage before destroying the surface it is bound to
792 VAStatus vaDestroyImage (
797 VADriverContextP ctx;
801 return ctx->vtable.vaDestroyImage ( ctx, image);
804 VAStatus vaSetImagePalette (
807 unsigned char *palette
810 VADriverContextP ctx;
814 return ctx->vtable.vaSetImagePalette ( ctx, image, palette);
818 * Retrieve surface data into a VAImage
819 * Image must be in a format supported by the implementation
821 VAStatus vaGetImage (
824 int x, /* coordinates of the upper left source pixel */
826 unsigned int width, /* width and height of the region */
831 VADriverContextP ctx;
835 return ctx->vtable.vaGetImage ( ctx, surface, x, y, width, height, image);
839 * Copy data from a VAImage to a surface
840 * Image must be in a format supported by the implementation
842 VAStatus vaPutImage (
848 unsigned int src_width,
849 unsigned int src_height,
852 unsigned int dest_width,
853 unsigned int dest_height
856 VADriverContextP ctx;
860 return ctx->vtable.vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
864 * Derive an VAImage from an existing surface.
865 * This interface will derive a VAImage and corresponding image buffer from
866 * an existing VA Surface. The image buffer can then be mapped/unmapped for
867 * direct CPU access. This operation is only possible on implementations with
868 * direct rendering capabilities and internal surface formats that can be
869 * represented with a VAImage. When the operation is not possible this interface
870 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
871 * to using vaCreateImage + vaPutImage to accomplish the same task in an
874 * Implementations should only return success when the resulting image buffer
875 * would be useable with vaMap/Unmap.
877 * When directly accessing a surface special care must be taken to insure
878 * proper synchronization with the graphics hardware. Clients should call
879 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
880 * rendering or currently being displayed by an overlay.
882 * Additionally nothing about the contents of a surface should be assumed
883 * following a vaPutSurface. Implementations are free to modify the surface for
884 * scaling or subpicture blending within a call to vaPutImage.
886 * Calls to vaPutImage or vaGetImage using the same surface from which the image
887 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
888 * vaGetImage with other surfaces is supported.
890 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
891 * image and image buffer structures will be destroyed; however, the underlying
892 * surface will remain unchanged until freed with vaDestroySurfaces.
894 VAStatus vaDeriveImage (
897 VAImage *image /* out */
900 VADriverContextP ctx;
904 return ctx->vtable.vaDeriveImage ( ctx, surface, image );
908 /* Get maximum number of subpicture formats supported by the implementation */
909 int vaMaxNumSubpictureFormats (
913 if( !vaDisplayIsValid(dpy) )
916 return CTX(dpy)->max_subpic_formats;
920 * Query supported subpicture formats
921 * The caller must provide a "format_list" array that can hold at
922 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
923 * for each format to indicate additional capabilities for that format. The actual
924 * number of formats returned in "format_list" is returned in "num_formats".
926 VAStatus vaQuerySubpictureFormats (
928 VAImageFormat *format_list, /* out */
929 unsigned int *flags, /* out */
930 unsigned int *num_formats /* out */
933 VADriverContextP ctx;
937 return ctx->vtable.vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
941 * Subpictures are created with an image associated.
943 VAStatus vaCreateSubpicture (
946 VASubpictureID *subpicture /* out */
949 VADriverContextP ctx;
953 return ctx->vtable.vaCreateSubpicture ( ctx, image, subpicture );
957 * Destroy the subpicture before destroying the image it is assocated to
959 VAStatus vaDestroySubpicture (
961 VASubpictureID subpicture
964 VADriverContextP ctx;
968 return ctx->vtable.vaDestroySubpicture ( ctx, subpicture);
971 VAStatus vaSetSubpictureImage (
973 VASubpictureID subpicture,
977 VADriverContextP ctx;
981 return ctx->vtable.vaSetSubpictureImage ( ctx, subpicture, image);
986 * If chromakey is enabled, then the area where the source value falls within
987 * the chromakey [min, max] range is transparent
989 VAStatus vaSetSubpictureChromakey (
991 VASubpictureID subpicture,
992 unsigned int chromakey_min,
993 unsigned int chromakey_max,
994 unsigned int chromakey_mask
997 VADriverContextP ctx;
1001 return ctx->vtable.vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
1006 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1007 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1008 * the overall alpha is per-pixel alpha multiplied by the global alpha
1010 VAStatus vaSetSubpictureGlobalAlpha (
1012 VASubpictureID subpicture,
1016 VADriverContextP ctx;
1020 return ctx->vtable.vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
1024 vaAssociateSubpicture associates the subpicture with the target_surface.
1025 It defines the region mapping between the subpicture and the target
1026 surface through source and destination rectangles (with the same width and height).
1027 Both will be displayed at the next call to vaPutSurface. Additional
1028 associations before the call to vaPutSurface simply overrides the association.
1030 VAStatus vaAssociateSubpicture (
1032 VASubpictureID subpicture,
1033 VASurfaceID *target_surfaces,
1035 short src_x, /* upper left offset in subpicture */
1037 unsigned short src_width,
1038 unsigned short src_height,
1039 short dest_x, /* upper left offset in surface */
1041 unsigned short dest_width,
1042 unsigned short dest_height,
1044 * whether to enable chroma-keying or global-alpha
1045 * see VA_SUBPICTURE_XXX values
1050 VADriverContextP ctx;
1054 return ctx->vtable.vaAssociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height, flags );
1058 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1060 VAStatus vaDeassociateSubpicture (
1062 VASubpictureID subpicture,
1063 VASurfaceID *target_surfaces,
1067 VADriverContextP ctx;
1071 return ctx->vtable.vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
1075 /* Get maximum number of display attributes supported by the implementation */
1076 int vaMaxNumDisplayAttributes (
1080 if( !vaDisplayIsValid(dpy) )
1083 return CTX(dpy)->max_display_attributes;
1087 * Query display attributes
1088 * The caller must provide a "attr_list" array that can hold at
1089 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1090 * returned in "attr_list" is returned in "num_attributes".
1092 VAStatus vaQueryDisplayAttributes (
1094 VADisplayAttribute *attr_list, /* out */
1095 int *num_attributes /* out */
1098 VADriverContextP ctx;
1102 return ctx->vtable.vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
1106 * Get display attributes
1107 * This function returns the current attribute values in "attr_list".
1108 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1109 * from vaQueryDisplayAttributes() can have their values retrieved.
1111 VAStatus vaGetDisplayAttributes (
1113 VADisplayAttribute *attr_list, /* in/out */
1117 VADriverContextP ctx;
1121 return ctx->vtable.vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
1125 * Set display attributes
1126 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1127 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1128 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1130 VAStatus vaSetDisplayAttributes (
1132 VADisplayAttribute *attr_list,
1136 VADriverContextP ctx;
1140 return ctx->vtable.vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
1143 /* Wrap a CI (camera imaging) frame as a VA surface to share captured video between camear
1144 * and VA encode. With frame_id, VA driver need to call CI interfaces to get the information
1145 * of the frame, and to determine if the frame can be wrapped as a VA surface
1147 * Application should make sure the frame is idle before the frame is passed into VA stack
1148 * and also a vaSyncSurface should be called before application tries to access the frame
1151 VAStatus vaCreateSurfaceFromCIFrame (
1153 unsigned long frame_id,
1154 VASurfaceID *surface /* out */
1157 VADriverContextP ctx;
1161 if (ctx->vtable.vaCreateSurfaceFromCIFrame)
1162 return ctx->vtable.vaCreateSurfaceFromCIFrame( ctx, frame_id, surface );
1164 return VA_STATUS_ERROR_UNIMPLEMENTED;
1168 /* Wrap a V4L2 buffer as a VA surface, so that V4L2 camera, VA encode
1169 * can share the data without copy
1170 * The VA driver should query the camera device from v4l2_fd to see
1171 * if camera device memory/buffer can be wrapped into a VA surface
1172 * Buffer information is passed in by v4l2_fmt and v4l2_buf structure,
1173 * VA driver also needs do further check if the buffer can meet encode
1174 * hardware requirement, such as dimension, fourcc, stride, etc
1176 * Application should make sure the buffer is idle before the frame into VA stack
1177 * and also a vaSyncSurface should be called before application tries to access the frame
1180 VAStatus vaCreateSurfaceFromV4L2Buf(
1182 int v4l2_fd, /* file descriptor of V4L2 device */
1183 struct v4l2_format *v4l2_fmt, /* format of V4L2 */
1184 struct v4l2_buffer *v4l2_buf, /* V4L2 buffer */
1185 VASurfaceID *surface /* out */
1188 VADriverContextP ctx;
1192 if (ctx->vtable.vaCreateSurfaceFromV4L2Buf)
1193 return ctx->vtable.vaCreateSurfaceFromV4L2Buf( ctx, v4l2_fd, v4l2_fmt, v4l2_buf, surface );
1195 return VA_STATUS_ERROR_UNKNOWN;
1198 /* It is a debug interface, and isn't exported in core VAAPI
1199 * It is used to dump surface data into system memory
1200 * Application should explicitly call free to release the buffer memory
1203 VAStatus vaCopySurfaceToBuffer(VADisplay dpy,
1204 VASurfaceID surface,
1205 unsigned int *fourcc, /* following are output argument */
1206 unsigned int *luma_stride,
1207 unsigned int *chroma_u_stride,
1208 unsigned int *chroma_v_stride,
1209 unsigned int *luma_offset,
1210 unsigned int *chroma_u_offset,
1211 unsigned int *chroma_v_offset,
1215 VADriverContextP ctx;
1219 if (ctx->vtable.vaCopySurfaceToBuffer)
1220 return ctx->vtable.vaCopySurfaceToBuffer( ctx, surface, fourcc, luma_stride, chroma_u_stride, chroma_v_stride, luma_offset, chroma_u_offset, chroma_v_offset, buffer);
1222 return VA_STATUS_ERROR_UNIMPLEMENTED;