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"
44 #define DRIVER_INIT_FUNC "__vaDriverInit_0_31"
46 #define DRIVER_EXTENSION "_drv_video.so"
48 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
49 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
52 #define CHECK_VTABLE(s, ctx, func) if (!va_checkVtable(ctx->vtable.va##func, #func)) s = VA_STATUS_ERROR_UNKNOWN;
53 #define CHECK_MAXIMUM(s, ctx, var) if (!va_checkMaximum(ctx->max_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
54 #define CHECK_STRING(s, ctx, var) if (!va_checkString(ctx->str_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
56 extern int trace_flag;
57 #define VA_TRACE(trace_func,...) \
59 va_TraceMsg("========%s========\n", __func__); \
60 trace_func(__VA_ARGS__); \
63 #define VA_MAJOR_VERSION (0)
64 #define VA_MINOR_VERSION (31)
65 #define VA_VERSION_S "0.31.1"
67 static int vaDisplayIsValid(VADisplay dpy)
69 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
70 return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
73 static void va_errorMessage(const char *msg, ...)
77 fprintf(stderr, "libva error: ");
79 vfprintf(stderr, msg, args);
83 static void va_infoMessage(const char *msg, ...)
87 fprintf(stderr, "libva: ");
89 vfprintf(stderr, msg, args);
93 static Bool va_checkVtable(void *ptr, char *function)
97 va_errorMessage("No valid vtable entry for va%s\n", function);
103 static Bool va_checkMaximum(int value, char *variable)
107 va_errorMessage("Failed to define max_%s in init\n", variable);
113 static Bool va_checkString(const char* value, char *variable)
117 va_errorMessage("Failed to define str_%s in init\n", variable);
123 static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
125 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
127 return pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
130 static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
132 VADriverContextP ctx = CTX(dpy);
133 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
134 char *search_path = NULL;
138 if (geteuid() == getuid())
140 /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
141 search_path = getenv("LIBVA_DRIVERS_PATH");
144 search_path = getenv("LIBGL_DRIVERS_PATH");
149 search_path = VA_DRIVERS_PATH;
152 search_path = strdup((const char *)search_path);
153 driver_dir = strtok_r((const char *)search_path, ":", &saveptr);
157 char *driver_path = (char *) malloc( strlen(driver_dir) +
158 strlen(driver_name) +
159 strlen(DRIVER_EXTENSION) + 2 );
160 strncpy( driver_path, driver_dir, strlen(driver_dir) + 1);
161 strncat( driver_path, "/", strlen("/") );
162 strncat( driver_path, driver_name, strlen(driver_name) );
163 strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
165 va_infoMessage("Trying to open %s\n", driver_path);
167 handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
169 handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
173 /* Don't give errors for non-existing files */
174 if (0 == access( driver_path, F_OK))
176 va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
181 VADriverInit init_func;
182 init_func = (VADriverInit) dlsym(handle, DRIVER_INIT_FUNC);
185 va_errorMessage("%s has no function %s\n", driver_path, DRIVER_INIT_FUNC);
190 vaStatus = (*init_func)(ctx);
192 if (VA_STATUS_SUCCESS == vaStatus)
194 CHECK_MAXIMUM(vaStatus, ctx, profiles);
195 CHECK_MAXIMUM(vaStatus, ctx, entrypoints);
196 CHECK_MAXIMUM(vaStatus, ctx, attributes);
197 CHECK_MAXIMUM(vaStatus, ctx, image_formats);
198 CHECK_MAXIMUM(vaStatus, ctx, subpic_formats);
199 CHECK_MAXIMUM(vaStatus, ctx, display_attributes);
200 CHECK_STRING(vaStatus, ctx, vendor);
201 CHECK_VTABLE(vaStatus, ctx, Terminate);
202 CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles);
203 CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints);
204 CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes);
205 CHECK_VTABLE(vaStatus, ctx, CreateConfig);
206 CHECK_VTABLE(vaStatus, ctx, DestroyConfig);
207 CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes);
208 CHECK_VTABLE(vaStatus, ctx, CreateSurfaces);
209 CHECK_VTABLE(vaStatus, ctx, DestroySurfaces);
210 CHECK_VTABLE(vaStatus, ctx, CreateContext);
211 CHECK_VTABLE(vaStatus, ctx, DestroyContext);
212 CHECK_VTABLE(vaStatus, ctx, CreateBuffer);
213 CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements);
214 CHECK_VTABLE(vaStatus, ctx, MapBuffer);
215 CHECK_VTABLE(vaStatus, ctx, UnmapBuffer);
216 CHECK_VTABLE(vaStatus, ctx, DestroyBuffer);
217 CHECK_VTABLE(vaStatus, ctx, BeginPicture);
218 CHECK_VTABLE(vaStatus, ctx, RenderPicture);
219 CHECK_VTABLE(vaStatus, ctx, EndPicture);
220 CHECK_VTABLE(vaStatus, ctx, SyncSurface);
221 CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus);
222 CHECK_VTABLE(vaStatus, ctx, PutSurface);
223 CHECK_VTABLE(vaStatus, ctx, QueryImageFormats);
224 CHECK_VTABLE(vaStatus, ctx, CreateImage);
225 CHECK_VTABLE(vaStatus, ctx, DeriveImage);
226 CHECK_VTABLE(vaStatus, ctx, DestroyImage);
227 CHECK_VTABLE(vaStatus, ctx, SetImagePalette);
228 CHECK_VTABLE(vaStatus, ctx, GetImage);
229 CHECK_VTABLE(vaStatus, ctx, PutImage);
230 CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats);
231 CHECK_VTABLE(vaStatus, ctx, CreateSubpicture);
232 CHECK_VTABLE(vaStatus, ctx, DestroySubpicture);
233 CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage);
234 CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey);
235 CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha);
236 CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture);
237 CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture);
238 CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes);
239 CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes);
240 CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes);
242 if (VA_STATUS_SUCCESS != vaStatus)
244 va_errorMessage("%s init failed\n", driver_path);
247 if (VA_STATUS_SUCCESS == vaStatus)
249 ctx->handle = handle;
257 driver_dir = strtok_r(NULL, ":", &saveptr);
265 VAPrivFunc vaGetLibFunc(VADisplay dpy, const char *func)
267 VADriverContextP ctx;
268 if( !vaDisplayIsValid(dpy) )
272 if (NULL == ctx->handle)
275 return (VAPrivFunc) dlsym(ctx->handle, func);
280 * Returns a short english description of error_status
282 const char *vaErrorStr(VAStatus error_status)
286 case VA_STATUS_SUCCESS:
287 return "success (no error)";
288 case VA_STATUS_ERROR_OPERATION_FAILED:
289 return "operation failed";
290 case VA_STATUS_ERROR_ALLOCATION_FAILED:
291 return "resource allocation failed";
292 case VA_STATUS_ERROR_INVALID_DISPLAY:
293 return "invalid VADisplay";
294 case VA_STATUS_ERROR_INVALID_CONFIG:
295 return "invalid VAConfigID";
296 case VA_STATUS_ERROR_INVALID_CONTEXT:
297 return "invalid VAContextID";
298 case VA_STATUS_ERROR_INVALID_SURFACE:
299 return "invalid VASurfaceID";
300 case VA_STATUS_ERROR_INVALID_BUFFER:
301 return "invalid VABufferID";
302 case VA_STATUS_ERROR_INVALID_IMAGE:
303 return "invalid VAImageID";
304 case VA_STATUS_ERROR_INVALID_SUBPICTURE:
305 return "invalid VASubpictureID";
306 case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
307 return "attribute not supported";
308 case VA_STATUS_ERROR_MAX_NUM_EXCEEDED:
309 return "list argument exceeds maximum number";
310 case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
311 return "the requested VAProfile is not supported";
312 case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
313 return "the requested VAEntryPoint is not supported";
314 case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
315 return "the requested RT Format is not supported";
316 case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
317 return "the requested VABufferType is not supported";
318 case VA_STATUS_ERROR_SURFACE_BUSY:
319 return "surface is in use";
320 case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
321 return "flag not supported";
322 case VA_STATUS_ERROR_INVALID_PARAMETER:
323 return "invalid parameter";
324 case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
325 return "resolution not supported";
326 case VA_STATUS_ERROR_UNIMPLEMENTED:
327 return "the requested function is not implemented";
328 case VA_STATUS_ERROR_SURFACE_IN_DISPLAYING:
329 return "surface is in displaying (may by overlay)" ;
330 case VA_STATUS_ERROR_UNKNOWN:
331 return "unknown libva error";
333 return "unknown libva error / description missing";
336 VAStatus vaInitialize (
338 int *major_version, /* out */
339 int *minor_version /* out */
342 char *driver_name = NULL;
349 va_infoMessage("libva version %s\n", VA_VERSION_S);
351 vaStatus = va_getDriverName(dpy, &driver_name);
352 va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
354 if (VA_STATUS_SUCCESS == vaStatus)
356 vaStatus = va_openDriver(dpy, driver_name);
357 va_infoMessage("va_openDriver() returns %d\n", vaStatus);
359 *major_version = VA_MAJOR_VERSION;
360 *minor_version = VA_MINOR_VERSION;
370 * After this call, all library internal resources will be cleaned up
372 VAStatus vaTerminate (
376 VAStatus vaStatus = VA_STATUS_SUCCESS;
377 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
378 VADriverContextP old_ctx;
385 vaStatus = old_ctx->vtable.vaTerminate(old_ctx);
386 dlclose(old_ctx->handle);
387 old_ctx->handle = NULL;
390 if (VA_STATUS_SUCCESS == vaStatus)
391 pDisplayContext->vaDestroy(pDisplayContext);
399 * vaQueryVendorString returns a pointer to a zero-terminated string
400 * describing some aspects of the VA implemenation on a specific
401 * hardware accelerator. The format of the returned string is:
402 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
403 * e.g. for the Intel GMA500 implementation, an example would be:
404 * "IntelGMA500-1.0-0.2-patch3
406 const char *vaQueryVendorString (
410 if( !vaDisplayIsValid(dpy) )
413 return CTX(dpy)->str_vendor;
417 /* Get maximum number of profiles supported by the implementation */
418 int vaMaxNumProfiles (
422 if( !vaDisplayIsValid(dpy) )
425 return CTX(dpy)->max_profiles;
428 /* Get maximum number of entrypoints supported by the implementation */
429 int vaMaxNumEntrypoints (
433 if( !vaDisplayIsValid(dpy) )
436 return CTX(dpy)->max_entrypoints;
440 /* Get maximum number of attributs supported by the implementation */
441 int vaMaxNumConfigAttributes (
445 if( !vaDisplayIsValid(dpy) )
448 return CTX(dpy)->max_attributes;
451 VAStatus vaQueryConfigEntrypoints (
454 VAEntrypoint *entrypoints, /* out */
455 int *num_entrypoints /* out */
458 VADriverContextP ctx;
462 return ctx->vtable.vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
465 VAStatus vaGetConfigAttributes (
468 VAEntrypoint entrypoint,
469 VAConfigAttrib *attrib_list, /* in/out */
473 VADriverContextP ctx;
477 return ctx->vtable.vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
480 VAStatus vaQueryConfigProfiles (
482 VAProfile *profile_list, /* out */
483 int *num_profiles /* out */
486 VADriverContextP ctx;
490 return ctx->vtable.vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
493 VAStatus vaCreateConfig (
496 VAEntrypoint entrypoint,
497 VAConfigAttrib *attrib_list,
499 VAConfigID *config_id /* out */
502 VADriverContextP ctx;
506 VA_TRACE(va_TraceCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
507 return ctx->vtable.vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
510 VAStatus vaDestroyConfig (
515 VADriverContextP ctx;
519 return ctx->vtable.vaDestroyConfig ( ctx, config_id );
522 VAStatus vaQueryConfigAttributes (
524 VAConfigID config_id,
525 VAProfile *profile, /* out */
526 VAEntrypoint *entrypoint, /* out */
527 VAConfigAttrib *attrib_list,/* out */
528 int *num_attribs /* out */
531 VADriverContextP ctx;
535 return ctx->vtable.vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
538 VAStatus vaCreateSurfaces (
544 VASurfaceID *surfaces /* out */
547 VADriverContextP ctx;
551 VA_TRACE(va_TraceCreateSurface, dpy, width, height, format, num_surfaces, surfaces);
552 return ctx->vtable.vaCreateSurfaces( ctx, width, height, format, num_surfaces, surfaces );
556 VAStatus vaDestroySurfaces (
558 VASurfaceID *surface_list,
562 VADriverContextP ctx;
566 return ctx->vtable.vaDestroySurfaces( ctx, surface_list, num_surfaces );
569 VAStatus vaCreateContext (
571 VAConfigID config_id,
575 VASurfaceID *render_targets,
576 int num_render_targets,
577 VAContextID *context /* out */
580 VADriverContextP ctx;
584 VA_TRACE(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
585 return ctx->vtable.vaCreateContext( ctx, config_id, picture_width, picture_height,
586 flag, render_targets, num_render_targets, context );
589 VAStatus vaDestroyContext (
594 VADriverContextP ctx;
598 return ctx->vtable.vaDestroyContext( ctx, context );
601 VAStatus vaCreateBuffer (
603 VAContextID context, /* in */
604 VABufferType type, /* in */
605 unsigned int size, /* in */
606 unsigned int num_elements, /* in */
608 VABufferID *buf_id /* out */
611 VADriverContextP ctx;
615 return ctx->vtable.vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
618 VAStatus vaBufferSetNumElements (
620 VABufferID buf_id, /* in */
621 unsigned int num_elements /* in */
624 VADriverContextP ctx;
628 return ctx->vtable.vaBufferSetNumElements( ctx, buf_id, num_elements );
632 VAStatus vaMapBuffer (
634 VABufferID buf_id, /* in */
635 void **pbuf /* out */
638 VADriverContextP ctx;
642 return ctx->vtable.vaMapBuffer( ctx, buf_id, pbuf );
645 VAStatus vaUnmapBuffer (
647 VABufferID buf_id /* in */
650 VADriverContextP ctx;
654 return ctx->vtable.vaUnmapBuffer( ctx, buf_id );
657 VAStatus vaDestroyBuffer (
662 VADriverContextP ctx;
666 return ctx->vtable.vaDestroyBuffer( ctx, buffer_id );
669 VAStatus vaBufferInfo (
671 VAContextID context, /* in */
672 VABufferID buf_id, /* in */
673 VABufferType *type, /* out */
674 unsigned int *size, /* out */
675 unsigned int *num_elements /* out */
678 VADriverContextP ctx;
682 if (ctx->vtable.vaBufferInfo)
683 return ctx->vtable.vaBufferInfo( ctx, context, buf_id, type, size, num_elements );
685 return VA_STATUS_ERROR_UNIMPLEMENTED;
688 VAStatus vaBeginPicture (
691 VASurfaceID render_target
694 VADriverContextP ctx;
698 VA_TRACE(va_TraceBeginPicture, ctx, context, render_target);
699 return ctx->vtable.vaBeginPicture( ctx, context, render_target );
702 VAStatus vaRenderPicture (
709 VADriverContextP ctx;
713 VA_TRACE(va_TraceRenderPicture, dpy, context, buffers, num_buffers);
714 return ctx->vtable.vaRenderPicture( ctx, context, buffers, num_buffers );
717 VAStatus vaEndPicture (
722 VADriverContextP ctx;
726 VA_TRACE(va_TraceEndPicture, dpy, context);
727 return ctx->vtable.vaEndPicture( ctx, context );
730 VAStatus vaSyncSurface (
732 VASurfaceID render_target
735 VADriverContextP ctx;
739 return ctx->vtable.vaSyncSurface( ctx, render_target );
742 VAStatus vaQuerySurfaceStatus (
744 VASurfaceID render_target,
745 VASurfaceStatus *status /* out */
748 VADriverContextP ctx;
752 return ctx->vtable.vaQuerySurfaceStatus( ctx, render_target, status );
755 /* Get maximum number of image formats supported by the implementation */
756 int vaMaxNumImageFormats (
760 if( !vaDisplayIsValid(dpy) )
763 return CTX(dpy)->max_image_formats;
766 VAStatus vaQueryImageFormats (
768 VAImageFormat *format_list, /* out */
769 int *num_formats /* out */
772 VADriverContextP ctx;
776 return ctx->vtable.vaQueryImageFormats ( ctx, format_list, num_formats);
780 * The width and height fields returned in the VAImage structure may get
781 * enlarged for some YUV formats. The size of the data buffer that needs
782 * to be allocated will be given in the "data_size" field in VAImage.
783 * Image data is not allocated by this function. The client should
784 * allocate the memory and fill in the VAImage structure's data field
785 * after looking at "data_size" returned from the library.
787 VAStatus vaCreateImage (
789 VAImageFormat *format,
792 VAImage *image /* out */
795 VADriverContextP ctx;
799 return ctx->vtable.vaCreateImage ( ctx, format, width, height, image);
803 * Should call DestroyImage before destroying the surface it is bound to
805 VAStatus vaDestroyImage (
810 VADriverContextP ctx;
814 return ctx->vtable.vaDestroyImage ( ctx, image);
817 VAStatus vaSetImagePalette (
820 unsigned char *palette
823 VADriverContextP ctx;
827 return ctx->vtable.vaSetImagePalette ( ctx, image, palette);
831 * Retrieve surface data into a VAImage
832 * Image must be in a format supported by the implementation
834 VAStatus vaGetImage (
837 int x, /* coordinates of the upper left source pixel */
839 unsigned int width, /* width and height of the region */
844 VADriverContextP ctx;
848 return ctx->vtable.vaGetImage ( ctx, surface, x, y, width, height, image);
852 * Copy data from a VAImage to a surface
853 * Image must be in a format supported by the implementation
855 VAStatus vaPutImage (
861 unsigned int src_width,
862 unsigned int src_height,
865 unsigned int dest_width,
866 unsigned int dest_height
869 VADriverContextP ctx;
873 return ctx->vtable.vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
877 * Derive an VAImage from an existing surface.
878 * This interface will derive a VAImage and corresponding image buffer from
879 * an existing VA Surface. The image buffer can then be mapped/unmapped for
880 * direct CPU access. This operation is only possible on implementations with
881 * direct rendering capabilities and internal surface formats that can be
882 * represented with a VAImage. When the operation is not possible this interface
883 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
884 * to using vaCreateImage + vaPutImage to accomplish the same task in an
887 * Implementations should only return success when the resulting image buffer
888 * would be useable with vaMap/Unmap.
890 * When directly accessing a surface special care must be taken to insure
891 * proper synchronization with the graphics hardware. Clients should call
892 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
893 * rendering or currently being displayed by an overlay.
895 * Additionally nothing about the contents of a surface should be assumed
896 * following a vaPutSurface. Implementations are free to modify the surface for
897 * scaling or subpicture blending within a call to vaPutImage.
899 * Calls to vaPutImage or vaGetImage using the same surface from which the image
900 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
901 * vaGetImage with other surfaces is supported.
903 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
904 * image and image buffer structures will be destroyed; however, the underlying
905 * surface will remain unchanged until freed with vaDestroySurfaces.
907 VAStatus vaDeriveImage (
910 VAImage *image /* out */
913 VADriverContextP ctx;
917 return ctx->vtable.vaDeriveImage ( ctx, surface, image );
921 /* Get maximum number of subpicture formats supported by the implementation */
922 int vaMaxNumSubpictureFormats (
926 if( !vaDisplayIsValid(dpy) )
929 return CTX(dpy)->max_subpic_formats;
933 * Query supported subpicture formats
934 * The caller must provide a "format_list" array that can hold at
935 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
936 * for each format to indicate additional capabilities for that format. The actual
937 * number of formats returned in "format_list" is returned in "num_formats".
939 VAStatus vaQuerySubpictureFormats (
941 VAImageFormat *format_list, /* out */
942 unsigned int *flags, /* out */
943 unsigned int *num_formats /* out */
946 VADriverContextP ctx;
950 return ctx->vtable.vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
954 * Subpictures are created with an image associated.
956 VAStatus vaCreateSubpicture (
959 VASubpictureID *subpicture /* out */
962 VADriverContextP ctx;
966 return ctx->vtable.vaCreateSubpicture ( ctx, image, subpicture );
970 * Destroy the subpicture before destroying the image it is assocated to
972 VAStatus vaDestroySubpicture (
974 VASubpictureID subpicture
977 VADriverContextP ctx;
981 return ctx->vtable.vaDestroySubpicture ( ctx, subpicture);
984 VAStatus vaSetSubpictureImage (
986 VASubpictureID subpicture,
990 VADriverContextP ctx;
994 return ctx->vtable.vaSetSubpictureImage ( ctx, subpicture, image);
999 * If chromakey is enabled, then the area where the source value falls within
1000 * the chromakey [min, max] range is transparent
1002 VAStatus vaSetSubpictureChromakey (
1004 VASubpictureID subpicture,
1005 unsigned int chromakey_min,
1006 unsigned int chromakey_max,
1007 unsigned int chromakey_mask
1010 VADriverContextP ctx;
1014 return ctx->vtable.vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
1019 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1020 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1021 * the overall alpha is per-pixel alpha multiplied by the global alpha
1023 VAStatus vaSetSubpictureGlobalAlpha (
1025 VASubpictureID subpicture,
1029 VADriverContextP ctx;
1033 return ctx->vtable.vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
1037 vaAssociateSubpicture associates the subpicture with the target_surface.
1038 It defines the region mapping between the subpicture and the target
1039 surface through source and destination rectangles (with the same width and height).
1040 Both will be displayed at the next call to vaPutSurface. Additional
1041 associations before the call to vaPutSurface simply overrides the association.
1043 VAStatus vaAssociateSubpicture (
1045 VASubpictureID subpicture,
1046 VASurfaceID *target_surfaces,
1048 short src_x, /* upper left offset in subpicture */
1050 unsigned short src_width,
1051 unsigned short src_height,
1052 short dest_x, /* upper left offset in surface */
1054 unsigned short dest_width,
1055 unsigned short dest_height,
1057 * whether to enable chroma-keying or global-alpha
1058 * see VA_SUBPICTURE_XXX values
1063 VADriverContextP ctx;
1067 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 );
1071 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1073 VAStatus vaDeassociateSubpicture (
1075 VASubpictureID subpicture,
1076 VASurfaceID *target_surfaces,
1080 VADriverContextP ctx;
1084 return ctx->vtable.vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
1088 /* Get maximum number of display attributes supported by the implementation */
1089 int vaMaxNumDisplayAttributes (
1093 if( !vaDisplayIsValid(dpy) )
1096 return CTX(dpy)->max_display_attributes;
1100 * Query display attributes
1101 * The caller must provide a "attr_list" array that can hold at
1102 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1103 * returned in "attr_list" is returned in "num_attributes".
1105 VAStatus vaQueryDisplayAttributes (
1107 VADisplayAttribute *attr_list, /* out */
1108 int *num_attributes /* out */
1111 VADriverContextP ctx;
1115 return ctx->vtable.vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
1119 * Get display attributes
1120 * This function returns the current attribute values in "attr_list".
1121 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1122 * from vaQueryDisplayAttributes() can have their values retrieved.
1124 VAStatus vaGetDisplayAttributes (
1126 VADisplayAttribute *attr_list, /* in/out */
1130 VADriverContextP ctx;
1134 return ctx->vtable.vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
1138 * Set display attributes
1139 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1140 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1141 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1143 VAStatus vaSetDisplayAttributes (
1145 VADisplayAttribute *attr_list,
1149 VADriverContextP ctx;
1153 return ctx->vtable.vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
1156 /* Wrap a CI (camera imaging) frame as a VA surface to share captured video between camear
1157 * and VA encode. With frame_id, VA driver need to call CI interfaces to get the information
1158 * of the frame, and to determine if the frame can be wrapped as a VA surface
1160 * Application should make sure the frame is idle before the frame is passed into VA stack
1161 * and also a vaSyncSurface should be called before application tries to access the frame
1164 VAStatus vaCreateSurfaceFromCIFrame (
1166 unsigned long frame_id,
1167 VASurfaceID *surface /* out */
1170 VADriverContextP ctx;
1174 if (ctx->vtable.vaCreateSurfaceFromCIFrame)
1175 return ctx->vtable.vaCreateSurfaceFromCIFrame( ctx, frame_id, surface );
1177 return VA_STATUS_ERROR_UNIMPLEMENTED;
1181 /* Wrap a V4L2 buffer as a VA surface, so that V4L2 camera, VA encode
1182 * can share the data without copy
1183 * The VA driver should query the camera device from v4l2_fd to see
1184 * if camera device memory/buffer can be wrapped into a VA surface
1185 * Buffer information is passed in by v4l2_fmt and v4l2_buf structure,
1186 * VA driver also needs do further check if the buffer can meet encode
1187 * hardware requirement, such as dimension, fourcc, stride, etc
1189 * Application should make sure the buffer is idle before the frame into VA stack
1190 * and also a vaSyncSurface should be called before application tries to access the frame
1193 VAStatus vaCreateSurfaceFromV4L2Buf(
1195 int v4l2_fd, /* file descriptor of V4L2 device */
1196 struct v4l2_format *v4l2_fmt, /* format of V4L2 */
1197 struct v4l2_buffer *v4l2_buf, /* V4L2 buffer */
1198 VASurfaceID *surface /* out */
1201 VADriverContextP ctx;
1205 if (ctx->vtable.vaCreateSurfaceFromV4L2Buf)
1206 return ctx->vtable.vaCreateSurfaceFromV4L2Buf( ctx, v4l2_fd, v4l2_fmt, v4l2_buf, surface );
1208 return VA_STATUS_ERROR_UNKNOWN;
1211 /* It is a debug interface, and isn't exported in core VAAPI
1212 * It is used to dump surface data into system memory
1213 * Application should explicitly call free to release the buffer memory
1216 VAStatus vaCopySurfaceToBuffer(VADisplay dpy,
1217 VASurfaceID surface,
1218 unsigned int *fourcc, /* following are output argument */
1219 unsigned int *luma_stride,
1220 unsigned int *chroma_u_stride,
1221 unsigned int *chroma_v_stride,
1222 unsigned int *luma_offset,
1223 unsigned int *chroma_u_offset,
1224 unsigned int *chroma_v_offset,
1228 VADriverContextP ctx;
1232 if (ctx->vtable.vaCopySurfaceToBuffer)
1233 return ctx->vtable.vaCopySurfaceToBuffer( ctx, surface, fourcc, luma_stride, chroma_u_stride, chroma_v_stride, luma_offset, chroma_u_offset, chroma_v_offset, buffer);
1235 return VA_STATUS_ERROR_UNIMPLEMENTED;