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.
28 #include "va_backend.h"
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;
55 * read a config "env" for libva.conf or from environment setting
56 * liva.conf has higher priority
57 * return 0: the "env" is set, and the value is copied into env_value
58 * 1: the env is not set
60 int va_parseConfig(char *env, char *env_value)
62 char *token, *value, *saveptr;
69 fp = fopen("/etc/libva.conf", "r");
70 while (fp && (fgets(oneline, 1024, fp) != NULL)) {
71 if (strlen(oneline) == 1)
73 token = strtok_r(oneline, "=\n", &saveptr);
74 value = strtok_r(NULL, "=\n", &saveptr);
76 if (NULL == token || NULL == value)
79 if (strcmp(token, env) == 0) {
81 strncpy(env_value,value, 1024);
91 /* no setting in config file, use env setting */
94 strncpy(env_value, getenv(env), 1024);
102 int vaDisplayIsValid(VADisplay dpy)
104 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
105 return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
108 void va_errorMessage(const char *msg, ...)
112 fprintf(stderr, "libva error: ");
114 vfprintf(stderr, msg, args);
118 void va_infoMessage(const char *msg, ...)
122 fprintf(stderr, "libva: ");
124 vfprintf(stderr, msg, args);
128 static Bool va_checkVtable(void *ptr, char *function)
131 va_errorMessage("No valid vtable entry for va%s\n", function);
137 static Bool va_checkMaximum(int value, char *variable)
140 va_errorMessage("Failed to define max_%s in init\n", variable);
146 static Bool va_checkString(const char* value, char *variable)
149 va_errorMessage("Failed to define str_%s in init\n", variable);
156 va_getDriverInitName(char *name, int namelen, int major, int minor)
158 int ret = snprintf(name, namelen, "__vaDriverInit_%d_%d", major, minor);
159 return ret > 0 && ret < namelen;
162 static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
164 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
166 return pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
169 static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
171 VADriverContextP ctx = CTX(dpy);
172 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
173 char *search_path = NULL;
177 if (geteuid() == getuid())
178 /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
179 search_path = getenv("LIBVA_DRIVERS_PATH");
181 search_path = VA_DRIVERS_PATH;
183 search_path = strdup((const char *)search_path);
184 driver_dir = strtok_r(search_path, ":", &saveptr);
187 char *driver_path = (char *) malloc( strlen(driver_dir) +
188 strlen(driver_name) +
189 strlen(DRIVER_EXTENSION) + 2 );
190 strncpy( driver_path, driver_dir, strlen(driver_dir) + 1);
191 strncat( driver_path, "/", strlen("/") );
192 strncat( driver_path, driver_name, strlen(driver_name) );
193 strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
195 va_infoMessage("Trying to open %s\n", driver_path);
197 handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
199 handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
202 /* Don't give errors for non-existing files */
203 if (0 == access( driver_path, F_OK))
204 va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
206 VADriverInit init_func = NULL;
207 char init_func_s[256];
208 if (va_getDriverInitName(init_func_s, sizeof(init_func_s),
209 VA_MAJOR_VERSION, VA_MINOR_VERSION))
210 init_func = (VADriverInit) dlsym(handle, init_func_s);
212 va_errorMessage("%s has no function %s\n",
213 driver_path, init_func_s);
216 struct VADriverVTable *vtable = ctx->vtable;
218 vaStatus = VA_STATUS_SUCCESS;
220 vtable = calloc(1, sizeof(*vtable));
222 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
224 ctx->vtable = vtable;
226 if (VA_STATUS_SUCCESS == vaStatus)
227 vaStatus = (*init_func)(ctx);
229 if (VA_STATUS_SUCCESS == vaStatus) {
230 CHECK_MAXIMUM(vaStatus, ctx, profiles);
231 CHECK_MAXIMUM(vaStatus, ctx, entrypoints);
232 CHECK_MAXIMUM(vaStatus, ctx, attributes);
233 CHECK_MAXIMUM(vaStatus, ctx, image_formats);
234 CHECK_MAXIMUM(vaStatus, ctx, subpic_formats);
235 CHECK_MAXIMUM(vaStatus, ctx, display_attributes);
236 CHECK_STRING(vaStatus, ctx, vendor);
237 CHECK_VTABLE(vaStatus, ctx, Terminate);
238 CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles);
239 CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints);
240 CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes);
241 CHECK_VTABLE(vaStatus, ctx, CreateConfig);
242 CHECK_VTABLE(vaStatus, ctx, DestroyConfig);
243 CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes);
244 CHECK_VTABLE(vaStatus, ctx, CreateSurfaces);
245 CHECK_VTABLE(vaStatus, ctx, DestroySurfaces);
246 CHECK_VTABLE(vaStatus, ctx, CreateContext);
247 CHECK_VTABLE(vaStatus, ctx, DestroyContext);
248 CHECK_VTABLE(vaStatus, ctx, CreateBuffer);
249 CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements);
250 CHECK_VTABLE(vaStatus, ctx, MapBuffer);
251 CHECK_VTABLE(vaStatus, ctx, UnmapBuffer);
252 CHECK_VTABLE(vaStatus, ctx, DestroyBuffer);
253 CHECK_VTABLE(vaStatus, ctx, BeginPicture);
254 CHECK_VTABLE(vaStatus, ctx, RenderPicture);
255 CHECK_VTABLE(vaStatus, ctx, EndPicture);
256 CHECK_VTABLE(vaStatus, ctx, SyncSurface);
257 CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus);
258 CHECK_VTABLE(vaStatus, ctx, PutSurface);
259 CHECK_VTABLE(vaStatus, ctx, QueryImageFormats);
260 CHECK_VTABLE(vaStatus, ctx, CreateImage);
261 CHECK_VTABLE(vaStatus, ctx, DeriveImage);
262 CHECK_VTABLE(vaStatus, ctx, DestroyImage);
263 CHECK_VTABLE(vaStatus, ctx, SetImagePalette);
264 CHECK_VTABLE(vaStatus, ctx, GetImage);
265 CHECK_VTABLE(vaStatus, ctx, PutImage);
266 CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats);
267 CHECK_VTABLE(vaStatus, ctx, CreateSubpicture);
268 CHECK_VTABLE(vaStatus, ctx, DestroySubpicture);
269 CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage);
270 CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey);
271 CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha);
272 CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture);
273 CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture);
274 CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes);
275 CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes);
276 CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes);
278 if (VA_STATUS_SUCCESS != vaStatus) {
279 va_errorMessage("%s init failed\n", driver_path);
282 if (VA_STATUS_SUCCESS == vaStatus)
283 ctx->handle = handle;
290 driver_dir = strtok_r(NULL, ":", &saveptr);
298 VAPrivFunc vaGetLibFunc(VADisplay dpy, const char *func)
300 VADriverContextP ctx;
301 if (!vaDisplayIsValid(dpy))
305 if (NULL == ctx->handle)
308 return (VAPrivFunc) dlsym(ctx->handle, func);
313 * Returns a short english description of error_status
315 const char *vaErrorStr(VAStatus error_status)
317 switch(error_status) {
318 case VA_STATUS_SUCCESS:
319 return "success (no error)";
320 case VA_STATUS_ERROR_OPERATION_FAILED:
321 return "operation failed";
322 case VA_STATUS_ERROR_ALLOCATION_FAILED:
323 return "resource allocation failed";
324 case VA_STATUS_ERROR_INVALID_DISPLAY:
325 return "invalid VADisplay";
326 case VA_STATUS_ERROR_INVALID_CONFIG:
327 return "invalid VAConfigID";
328 case VA_STATUS_ERROR_INVALID_CONTEXT:
329 return "invalid VAContextID";
330 case VA_STATUS_ERROR_INVALID_SURFACE:
331 return "invalid VASurfaceID";
332 case VA_STATUS_ERROR_INVALID_BUFFER:
333 return "invalid VABufferID";
334 case VA_STATUS_ERROR_INVALID_IMAGE:
335 return "invalid VAImageID";
336 case VA_STATUS_ERROR_INVALID_SUBPICTURE:
337 return "invalid VASubpictureID";
338 case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
339 return "attribute not supported";
340 case VA_STATUS_ERROR_MAX_NUM_EXCEEDED:
341 return "list argument exceeds maximum number";
342 case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
343 return "the requested VAProfile is not supported";
344 case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
345 return "the requested VAEntryPoint is not supported";
346 case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
347 return "the requested RT Format is not supported";
348 case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
349 return "the requested VABufferType is not supported";
350 case VA_STATUS_ERROR_SURFACE_BUSY:
351 return "surface is in use";
352 case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
353 return "flag not supported";
354 case VA_STATUS_ERROR_INVALID_PARAMETER:
355 return "invalid parameter";
356 case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
357 return "resolution not supported";
358 case VA_STATUS_ERROR_UNIMPLEMENTED:
359 return "the requested function is not implemented";
360 case VA_STATUS_ERROR_SURFACE_IN_DISPLAYING:
361 return "surface is in displaying (may by overlay)" ;
362 case VA_STATUS_ERROR_INVALID_IMAGE_FORMAT:
363 return "invalid VAImageFormat";
364 case VA_STATUS_ERROR_UNKNOWN:
365 return "unknown libva error";
367 return "unknown libva error / description missing";
370 VAStatus vaInitialize (
372 int *major_version, /* out */
373 int *minor_version /* out */
376 const char *driver_name_env = NULL;
377 char *driver_name = NULL;
386 va_infoMessage("VA-API version %s\n", VA_VERSION_S);
388 driver_name_env = getenv("LIBVA_DRIVER_NAME");
389 if (driver_name_env && geteuid() == getuid()) {
390 /* Don't allow setuid apps to use LIBVA_DRIVER_NAME */
391 driver_name = strdup(driver_name_env);
392 vaStatus = VA_STATUS_SUCCESS;
393 va_infoMessage("User requested driver '%s'\n", driver_name);
395 vaStatus = va_getDriverName(dpy, &driver_name);
396 va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
399 if (VA_STATUS_SUCCESS == vaStatus) {
400 vaStatus = va_openDriver(dpy, driver_name);
401 va_infoMessage("va_openDriver() returns %d\n", vaStatus);
403 *major_version = VA_MAJOR_VERSION;
404 *minor_version = VA_MINOR_VERSION;
410 VA_TRACE_LOG(va_TraceInitialize, dpy, major_version, minor_version);
417 * After this call, all library internal resources will be cleaned up
419 VAStatus vaTerminate (
423 VAStatus vaStatus = VA_STATUS_SUCCESS;
424 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
425 VADriverContextP old_ctx;
430 if (old_ctx->handle) {
431 vaStatus = old_ctx->vtable->vaTerminate(old_ctx);
432 dlclose(old_ctx->handle);
433 old_ctx->handle = NULL;
435 free(old_ctx->vtable);
436 old_ctx->vtable = NULL;
438 if (VA_STATUS_SUCCESS == vaStatus)
439 pDisplayContext->vaDestroy(pDisplayContext);
441 VA_TRACE_LOG(va_TraceTerminate, dpy);
451 * vaQueryVendorString returns a pointer to a zero-terminated string
452 * describing some aspects of the VA implemenation on a specific
453 * hardware accelerator. The format of the returned string is:
454 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
455 * e.g. for the Intel GMA500 implementation, an example would be:
456 * "IntelGMA500-1.0-0.2-patch3
458 const char *vaQueryVendorString (
462 if (!vaDisplayIsValid(dpy))
465 return CTX(dpy)->str_vendor;
469 /* Get maximum number of profiles supported by the implementation */
470 int vaMaxNumProfiles (
474 if (!vaDisplayIsValid(dpy))
477 return CTX(dpy)->max_profiles;
480 /* Get maximum number of entrypoints supported by the implementation */
481 int vaMaxNumEntrypoints (
485 if (!vaDisplayIsValid(dpy))
488 return CTX(dpy)->max_entrypoints;
492 /* Get maximum number of attributs supported by the implementation */
493 int vaMaxNumConfigAttributes (
497 if (!vaDisplayIsValid(dpy))
500 return CTX(dpy)->max_attributes;
503 VAStatus vaQueryConfigEntrypoints (
506 VAEntrypoint *entrypoints, /* out */
507 int *num_entrypoints /* out */
510 VADriverContextP ctx;
514 return ctx->vtable->vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
517 VAStatus vaGetConfigAttributes (
520 VAEntrypoint entrypoint,
521 VAConfigAttrib *attrib_list, /* in/out */
525 VADriverContextP ctx;
529 return ctx->vtable->vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
532 VAStatus vaQueryConfigProfiles (
534 VAProfile *profile_list, /* out */
535 int *num_profiles /* out */
538 VADriverContextP ctx;
542 return ctx->vtable->vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
545 VAStatus vaCreateConfig (
548 VAEntrypoint entrypoint,
549 VAConfigAttrib *attrib_list,
551 VAConfigID *config_id /* out */
554 VADriverContextP ctx;
555 VAStatus vaStatus = VA_STATUS_SUCCESS;
561 vaStatus = ctx->vtable->vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
563 /* record the current entrypoint for further trace/fool determination */
564 VA_TRACE_FUNC(va_TraceCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
565 VA_FOOL_FUNC(va_FoolCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
570 VAStatus vaDestroyConfig (
575 VADriverContextP ctx;
579 return ctx->vtable->vaDestroyConfig ( ctx, config_id );
582 VAStatus vaQueryConfigAttributes (
584 VAConfigID config_id,
585 VAProfile *profile, /* out */
586 VAEntrypoint *entrypoint, /* out */
587 VAConfigAttrib *attrib_list,/* out */
588 int *num_attribs /* out */
591 VADriverContextP ctx;
595 return ctx->vtable->vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
598 VAStatus vaCreateSurfaces (
604 VASurfaceID *surfaces /* out */
607 VADriverContextP ctx;
613 vaStatus = ctx->vtable->vaCreateSurfaces( ctx, width, height, format, num_surfaces, surfaces );
615 VA_TRACE_LOG(va_TraceCreateSurface, dpy, width, height, format, num_surfaces, surfaces);
621 VAStatus vaDestroySurfaces (
623 VASurfaceID *surface_list,
627 VADriverContextP ctx;
631 return ctx->vtable->vaDestroySurfaces( ctx, surface_list, num_surfaces );
634 VAStatus vaCreateContext (
636 VAConfigID config_id,
640 VASurfaceID *render_targets,
641 int num_render_targets,
642 VAContextID *context /* out */
645 VADriverContextP ctx;
651 vaStatus = ctx->vtable->vaCreateContext( ctx, config_id, picture_width, picture_height,
652 flag, render_targets, num_render_targets, context );
654 /* keep current encode/decode resoluton */
655 VA_TRACE_FUNC(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
660 VAStatus vaDestroyContext (
665 VADriverContextP ctx;
669 return ctx->vtable->vaDestroyContext( ctx, context );
672 VAStatus vaCreateBuffer (
674 VAContextID context, /* in */
675 VABufferType type, /* in */
676 unsigned int size, /* in */
677 unsigned int num_elements, /* in */
679 VABufferID *buf_id /* out */
682 VADriverContextP ctx;
687 VA_FOOL_FUNC(va_FoolCreateBuffer, dpy, context, type, size, num_elements, data, buf_id);
689 return VA_STATUS_SUCCESS;
691 return ctx->vtable->vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
694 VAStatus vaBufferSetNumElements (
696 VABufferID buf_id, /* in */
697 unsigned int num_elements /* in */
700 VADriverContextP ctx;
706 return ctx->vtable->vaBufferSetNumElements( ctx, buf_id, num_elements );
710 VAStatus vaMapBuffer (
712 VABufferID buf_id, /* in */
713 void **pbuf /* out */
716 VADriverContextP ctx;
723 VA_FOOL_FUNC(va_FoolMapBuffer, dpy, buf_id, pbuf);
725 return VA_STATUS_SUCCESS;
727 va_status = ctx->vtable->vaMapBuffer( ctx, buf_id, pbuf );
729 VA_TRACE_LOG(va_TraceMapBuffer, dpy, buf_id, pbuf);
734 VAStatus vaUnmapBuffer (
736 VABufferID buf_id /* in */
739 VADriverContextP ctx;
744 VA_FOOL_FUNC(va_FoolUnmapBuffer, dpy, buf_id);
746 return VA_STATUS_SUCCESS;
748 return ctx->vtable->vaUnmapBuffer( ctx, buf_id );
751 VAStatus vaDestroyBuffer (
756 VADriverContextP ctx;
762 return ctx->vtable->vaDestroyBuffer( ctx, buffer_id );
765 VAStatus vaBufferInfo (
767 VAContextID context, /* in */
768 VABufferID buf_id, /* in */
769 VABufferType *type, /* out */
770 unsigned int *size, /* out */
771 unsigned int *num_elements /* out */
774 VADriverContextP ctx;
780 VA_FOOL_FUNC(va_FoolBufferInfo, dpy, buf_id, type, size, num_elements);
782 return VA_STATUS_SUCCESS;
784 return ctx->vtable->vaBufferInfo( ctx, buf_id, type, size, num_elements );
787 VAStatus vaBeginPicture (
790 VASurfaceID render_target
793 VADriverContextP ctx;
799 VA_TRACE_FUNC(va_TraceBeginPicture, dpy, context, render_target);
802 va_status = ctx->vtable->vaBeginPicture( ctx, context, render_target );
807 VAStatus vaRenderPicture (
814 VADriverContextP ctx;
819 VA_TRACE_LOG(va_TraceRenderPicture, dpy, context, buffers, num_buffers);
822 return ctx->vtable->vaRenderPicture( ctx, context, buffers, num_buffers );
825 VAStatus vaEndPicture (
831 VADriverContextP ctx;
836 /* dump encode source surface */
837 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 0);
838 /* return directly if do dummy operation */
841 va_status = ctx->vtable->vaEndPicture( ctx, context );
842 /* dump decode dest surface */
843 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 1);
848 VAStatus vaSyncSurface (
850 VASurfaceID render_target
854 VADriverContextP ctx;
859 va_status = ctx->vtable->vaSyncSurface( ctx, render_target );
860 VA_TRACE_LOG(va_TraceSyncSurface, dpy, render_target);
865 VAStatus vaQuerySurfaceStatus (
867 VASurfaceID render_target,
868 VASurfaceStatus *status /* out */
872 VADriverContextP ctx;
876 va_status = ctx->vtable->vaQuerySurfaceStatus( ctx, render_target, status );
878 VA_TRACE_LOG(va_TraceQuerySurfaceStatus, dpy, render_target, status);
883 VAStatus vaQuerySurfaceError (
886 VAStatus error_status,
887 void **error_info /*out*/
891 VADriverContextP ctx;
895 va_status = ctx->vtable->vaQuerySurfaceError( ctx, surface, error_status, error_info );
897 VA_TRACE_LOG(va_TraceQuerySurfaceError, dpy, surface, error_status, error_info);
902 /* Get maximum number of image formats supported by the implementation */
903 int vaMaxNumImageFormats (
907 if (!vaDisplayIsValid(dpy))
910 return CTX(dpy)->max_image_formats;
913 VAStatus vaQueryImageFormats (
915 VAImageFormat *format_list, /* out */
916 int *num_formats /* out */
919 VADriverContextP ctx;
923 return ctx->vtable->vaQueryImageFormats ( ctx, format_list, num_formats);
927 * The width and height fields returned in the VAImage structure may get
928 * enlarged for some YUV formats. The size of the data buffer that needs
929 * to be allocated will be given in the "data_size" field in VAImage.
930 * Image data is not allocated by this function. The client should
931 * allocate the memory and fill in the VAImage structure's data field
932 * after looking at "data_size" returned from the library.
934 VAStatus vaCreateImage (
936 VAImageFormat *format,
939 VAImage *image /* out */
942 VADriverContextP ctx;
946 return ctx->vtable->vaCreateImage ( ctx, format, width, height, image);
950 * Should call DestroyImage before destroying the surface it is bound to
952 VAStatus vaDestroyImage (
957 VADriverContextP ctx;
961 return ctx->vtable->vaDestroyImage ( ctx, image);
964 VAStatus vaSetImagePalette (
967 unsigned char *palette
970 VADriverContextP ctx;
974 return ctx->vtable->vaSetImagePalette ( ctx, image, palette);
978 * Retrieve surface data into a VAImage
979 * Image must be in a format supported by the implementation
981 VAStatus vaGetImage (
984 int x, /* coordinates of the upper left source pixel */
986 unsigned int width, /* width and height of the region */
991 VADriverContextP ctx;
995 return ctx->vtable->vaGetImage ( ctx, surface, x, y, width, height, image);
999 * Copy data from a VAImage to a surface
1000 * Image must be in a format supported by the implementation
1002 VAStatus vaPutImage (
1004 VASurfaceID surface,
1008 unsigned int src_width,
1009 unsigned int src_height,
1012 unsigned int dest_width,
1013 unsigned int dest_height
1016 VADriverContextP ctx;
1020 return ctx->vtable->vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
1024 * Derive an VAImage from an existing surface.
1025 * This interface will derive a VAImage and corresponding image buffer from
1026 * an existing VA Surface. The image buffer can then be mapped/unmapped for
1027 * direct CPU access. This operation is only possible on implementations with
1028 * direct rendering capabilities and internal surface formats that can be
1029 * represented with a VAImage. When the operation is not possible this interface
1030 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
1031 * to using vaCreateImage + vaPutImage to accomplish the same task in an
1034 * Implementations should only return success when the resulting image buffer
1035 * would be useable with vaMap/Unmap.
1037 * When directly accessing a surface special care must be taken to insure
1038 * proper synchronization with the graphics hardware. Clients should call
1039 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
1040 * rendering or currently being displayed by an overlay.
1042 * Additionally nothing about the contents of a surface should be assumed
1043 * following a vaPutSurface. Implementations are free to modify the surface for
1044 * scaling or subpicture blending within a call to vaPutImage.
1046 * Calls to vaPutImage or vaGetImage using the same surface from which the image
1047 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
1048 * vaGetImage with other surfaces is supported.
1050 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
1051 * image and image buffer structures will be destroyed; however, the underlying
1052 * surface will remain unchanged until freed with vaDestroySurfaces.
1054 VAStatus vaDeriveImage (
1056 VASurfaceID surface,
1057 VAImage *image /* out */
1060 VADriverContextP ctx;
1064 return ctx->vtable->vaDeriveImage ( ctx, surface, image );
1068 /* Get maximum number of subpicture formats supported by the implementation */
1069 int vaMaxNumSubpictureFormats (
1073 if (!vaDisplayIsValid(dpy))
1076 return CTX(dpy)->max_subpic_formats;
1080 * Query supported subpicture formats
1081 * The caller must provide a "format_list" array that can hold at
1082 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1083 * for each format to indicate additional capabilities for that format. The actual
1084 * number of formats returned in "format_list" is returned in "num_formats".
1086 VAStatus vaQuerySubpictureFormats (
1088 VAImageFormat *format_list, /* out */
1089 unsigned int *flags, /* out */
1090 unsigned int *num_formats /* out */
1093 VADriverContextP ctx;
1098 return ctx->vtable->vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
1102 * Subpictures are created with an image associated.
1104 VAStatus vaCreateSubpicture (
1107 VASubpictureID *subpicture /* out */
1110 VADriverContextP ctx;
1114 return ctx->vtable->vaCreateSubpicture ( ctx, image, subpicture );
1118 * Destroy the subpicture before destroying the image it is assocated to
1120 VAStatus vaDestroySubpicture (
1122 VASubpictureID subpicture
1125 VADriverContextP ctx;
1129 return ctx->vtable->vaDestroySubpicture ( ctx, subpicture);
1132 VAStatus vaSetSubpictureImage (
1134 VASubpictureID subpicture,
1138 VADriverContextP ctx;
1142 return ctx->vtable->vaSetSubpictureImage ( ctx, subpicture, image);
1147 * If chromakey is enabled, then the area where the source value falls within
1148 * the chromakey [min, max] range is transparent
1150 VAStatus vaSetSubpictureChromakey (
1152 VASubpictureID subpicture,
1153 unsigned int chromakey_min,
1154 unsigned int chromakey_max,
1155 unsigned int chromakey_mask
1158 VADriverContextP ctx;
1162 return ctx->vtable->vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
1167 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1168 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1169 * the overall alpha is per-pixel alpha multiplied by the global alpha
1171 VAStatus vaSetSubpictureGlobalAlpha (
1173 VASubpictureID subpicture,
1177 VADriverContextP ctx;
1181 return ctx->vtable->vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
1185 vaAssociateSubpicture associates the subpicture with the target_surface.
1186 It defines the region mapping between the subpicture and the target
1187 surface through source and destination rectangles (with the same width and height).
1188 Both will be displayed at the next call to vaPutSurface. Additional
1189 associations before the call to vaPutSurface simply overrides the association.
1191 VAStatus vaAssociateSubpicture (
1193 VASubpictureID subpicture,
1194 VASurfaceID *target_surfaces,
1196 short src_x, /* upper left offset in subpicture */
1198 unsigned short src_width,
1199 unsigned short src_height,
1200 short dest_x, /* upper left offset in surface */
1202 unsigned short dest_width,
1203 unsigned short dest_height,
1205 * whether to enable chroma-keying or global-alpha
1206 * see VA_SUBPICTURE_XXX values
1211 VADriverContextP ctx;
1215 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 );
1219 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1221 VAStatus vaDeassociateSubpicture (
1223 VASubpictureID subpicture,
1224 VASurfaceID *target_surfaces,
1228 VADriverContextP ctx;
1232 return ctx->vtable->vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
1236 /* Get maximum number of display attributes supported by the implementation */
1237 int vaMaxNumDisplayAttributes (
1243 if (!vaDisplayIsValid(dpy))
1246 tmp = CTX(dpy)->max_display_attributes;
1248 VA_TRACE_LOG(va_TraceMaxNumDisplayAttributes, dpy, tmp);
1254 * Query display attributes
1255 * The caller must provide a "attr_list" array that can hold at
1256 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1257 * returned in "attr_list" is returned in "num_attributes".
1259 VAStatus vaQueryDisplayAttributes (
1261 VADisplayAttribute *attr_list, /* out */
1262 int *num_attributes /* out */
1265 VADriverContextP ctx;
1270 va_status = ctx->vtable->vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
1272 VA_TRACE_LOG(va_TraceQueryDisplayAttributes, dpy, attr_list, num_attributes);
1279 * Get display attributes
1280 * This function returns the current attribute values in "attr_list".
1281 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1282 * from vaQueryDisplayAttributes() can have their values retrieved.
1284 VAStatus vaGetDisplayAttributes (
1286 VADisplayAttribute *attr_list, /* in/out */
1290 VADriverContextP ctx;
1295 va_status = ctx->vtable->vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
1297 VA_TRACE_LOG(va_TraceGetDisplayAttributes, dpy, attr_list, num_attributes);
1303 * Set display attributes
1304 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1305 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1306 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1308 VAStatus vaSetDisplayAttributes (
1310 VADisplayAttribute *attr_list,
1314 VADriverContextP ctx;
1319 va_status = ctx->vtable->vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
1320 VA_TRACE_LOG(va_TraceSetDisplayAttributes, dpy, attr_list, num_attributes);
1325 VAStatus vaLockSurface(VADisplay dpy,
1326 VASurfaceID surface,
1327 unsigned int *fourcc, /* following are output argument */
1328 unsigned int *luma_stride,
1329 unsigned int *chroma_u_stride,
1330 unsigned int *chroma_v_stride,
1331 unsigned int *luma_offset,
1332 unsigned int *chroma_u_offset,
1333 unsigned int *chroma_v_offset,
1334 unsigned int *buffer_name,
1338 VADriverContextP ctx;
1342 return ctx->vtable->vaLockSurface( ctx, surface, fourcc, luma_stride, chroma_u_stride, chroma_v_stride, luma_offset, chroma_u_offset, chroma_v_offset, buffer_name, buffer);
1346 VAStatus vaUnlockSurface(VADisplay dpy,
1350 VADriverContextP ctx;
1354 return ctx->vtable->vaUnlockSurface( ctx, surface );