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"
41 #define DRIVER_EXTENSION "_drv_video.so"
43 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
44 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
47 #define CHECK_VTABLE(s, ctx, func) if (!va_checkVtable(ctx->vtable->va##func, #func)) s = VA_STATUS_ERROR_UNKNOWN;
48 #define CHECK_MAXIMUM(s, ctx, var) if (!va_checkMaximum(ctx->max_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
49 #define CHECK_STRING(s, ctx, var) if (!va_checkString(ctx->str_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
51 extern int trace_flag;
52 #define VA_TRACE(trace_func,...) \
54 trace_func(__VA_ARGS__); \
57 extern int fool_decode;
58 extern int fool_encode;
59 #define VA_FOOL(fool_func,...) \
60 if (fool_decode || fool_encode) { \
61 ret = fool_func(__VA_ARGS__); \
65 * read a config "env" for libva.conf or from environment setting
66 * liva.conf has higher priority
67 * return 0: the "env" is set, and the value is copied into env_value
68 * 1: the env is not set
70 int va_parseConfig(char *env, char *env_value)
72 char *token, *value, *saveptr;
80 fp = fopen("/etc/libva.conf", "r");
81 while (fp && (fgets(oneline, 1024, fp) != NULL)) {
82 if (strlen(oneline) == 1)
84 token = strtok_r(oneline, "=\n", &saveptr);
85 value = strtok_r(NULL, "=\n", &saveptr);
87 if (NULL == token || NULL == value)
90 if (strcmp(token, env) == 0) {
92 strncpy(env_value,value, 1024);
102 /* no setting in config file, use env setting */
105 strncpy(env_value, getenv(env), 1024);
113 int vaDisplayIsValid(VADisplay dpy)
115 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
116 return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
119 void va_errorMessage(const char *msg, ...)
123 fprintf(stderr, "libva error: ");
125 vfprintf(stderr, msg, args);
129 void va_infoMessage(const char *msg, ...)
133 fprintf(stderr, "libva: ");
135 vfprintf(stderr, msg, args);
139 static Bool va_checkVtable(void *ptr, char *function)
143 va_errorMessage("No valid vtable entry for va%s\n", function);
149 static Bool va_checkMaximum(int value, char *variable)
153 va_errorMessage("Failed to define max_%s in init\n", variable);
159 static Bool va_checkString(const char* value, char *variable)
163 va_errorMessage("Failed to define str_%s in init\n", variable);
169 static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
171 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
173 return pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
176 static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
178 VADriverContextP ctx = CTX(dpy);
179 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
180 char *search_path = NULL;
184 if (geteuid() == getuid())
186 /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
187 search_path = getenv("LIBVA_DRIVERS_PATH");
191 search_path = VA_DRIVERS_PATH;
194 search_path = strdup((const char *)search_path);
195 driver_dir = strtok_r((const char *)search_path, ":", &saveptr);
199 char *driver_path = (char *) malloc( strlen(driver_dir) +
200 strlen(driver_name) +
201 strlen(DRIVER_EXTENSION) + 2 );
202 strncpy( driver_path, driver_dir, strlen(driver_dir) + 1);
203 strncat( driver_path, "/", strlen("/") );
204 strncat( driver_path, driver_name, strlen(driver_name) );
205 strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
207 va_infoMessage("Trying to open %s\n", driver_path);
209 handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
211 handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
215 /* Don't give errors for non-existing files */
216 if (0 == access( driver_path, F_OK))
218 va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
223 VADriverInit init_func;
224 init_func = (VADriverInit) dlsym(handle, VA_DRIVER_INIT_FUNC_S);
227 va_errorMessage("%s has no function %s\n", driver_path, VA_DRIVER_INIT_FUNC_S);
232 struct VADriverVTable *vtable = ctx->vtable;
234 vaStatus = VA_STATUS_SUCCESS;
236 vtable = calloc(1, sizeof(*vtable));
238 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
240 ctx->vtable = vtable;
242 if (VA_STATUS_SUCCESS == vaStatus)
243 vaStatus = (*init_func)(ctx);
245 if (VA_STATUS_SUCCESS == vaStatus)
247 CHECK_MAXIMUM(vaStatus, ctx, profiles);
248 CHECK_MAXIMUM(vaStatus, ctx, entrypoints);
249 CHECK_MAXIMUM(vaStatus, ctx, attributes);
250 CHECK_MAXIMUM(vaStatus, ctx, image_formats);
251 CHECK_MAXIMUM(vaStatus, ctx, subpic_formats);
252 CHECK_MAXIMUM(vaStatus, ctx, display_attributes);
253 CHECK_STRING(vaStatus, ctx, vendor);
254 CHECK_VTABLE(vaStatus, ctx, Terminate);
255 CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles);
256 CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints);
257 CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes);
258 CHECK_VTABLE(vaStatus, ctx, CreateConfig);
259 CHECK_VTABLE(vaStatus, ctx, DestroyConfig);
260 CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes);
261 CHECK_VTABLE(vaStatus, ctx, CreateSurfaces);
262 CHECK_VTABLE(vaStatus, ctx, DestroySurfaces);
263 CHECK_VTABLE(vaStatus, ctx, CreateContext);
264 CHECK_VTABLE(vaStatus, ctx, DestroyContext);
265 CHECK_VTABLE(vaStatus, ctx, CreateBuffer);
266 CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements);
267 CHECK_VTABLE(vaStatus, ctx, MapBuffer);
268 CHECK_VTABLE(vaStatus, ctx, UnmapBuffer);
269 CHECK_VTABLE(vaStatus, ctx, DestroyBuffer);
270 CHECK_VTABLE(vaStatus, ctx, BeginPicture);
271 CHECK_VTABLE(vaStatus, ctx, RenderPicture);
272 CHECK_VTABLE(vaStatus, ctx, EndPicture);
273 CHECK_VTABLE(vaStatus, ctx, SyncSurface);
274 CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus);
275 CHECK_VTABLE(vaStatus, ctx, PutSurface);
276 CHECK_VTABLE(vaStatus, ctx, QueryImageFormats);
277 CHECK_VTABLE(vaStatus, ctx, CreateImage);
278 CHECK_VTABLE(vaStatus, ctx, DeriveImage);
279 CHECK_VTABLE(vaStatus, ctx, DestroyImage);
280 CHECK_VTABLE(vaStatus, ctx, SetImagePalette);
281 CHECK_VTABLE(vaStatus, ctx, GetImage);
282 CHECK_VTABLE(vaStatus, ctx, PutImage);
283 CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats);
284 CHECK_VTABLE(vaStatus, ctx, CreateSubpicture);
285 CHECK_VTABLE(vaStatus, ctx, DestroySubpicture);
286 CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage);
287 CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey);
288 CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha);
289 CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture);
290 CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture);
291 CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes);
292 CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes);
293 CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes);
295 if (VA_STATUS_SUCCESS != vaStatus)
297 va_errorMessage("%s init failed\n", driver_path);
300 if (VA_STATUS_SUCCESS == vaStatus)
302 ctx->handle = handle;
310 driver_dir = strtok_r(NULL, ":", &saveptr);
318 VAPrivFunc vaGetLibFunc(VADisplay dpy, const char *func)
320 VADriverContextP ctx;
321 if( !vaDisplayIsValid(dpy) )
325 if (NULL == ctx->handle)
328 return (VAPrivFunc) dlsym(ctx->handle, func);
333 * Returns a short english description of error_status
335 const char *vaErrorStr(VAStatus error_status)
339 case VA_STATUS_SUCCESS:
340 return "success (no error)";
341 case VA_STATUS_ERROR_OPERATION_FAILED:
342 return "operation failed";
343 case VA_STATUS_ERROR_ALLOCATION_FAILED:
344 return "resource allocation failed";
345 case VA_STATUS_ERROR_INVALID_DISPLAY:
346 return "invalid VADisplay";
347 case VA_STATUS_ERROR_INVALID_CONFIG:
348 return "invalid VAConfigID";
349 case VA_STATUS_ERROR_INVALID_CONTEXT:
350 return "invalid VAContextID";
351 case VA_STATUS_ERROR_INVALID_SURFACE:
352 return "invalid VASurfaceID";
353 case VA_STATUS_ERROR_INVALID_BUFFER:
354 return "invalid VABufferID";
355 case VA_STATUS_ERROR_INVALID_IMAGE:
356 return "invalid VAImageID";
357 case VA_STATUS_ERROR_INVALID_SUBPICTURE:
358 return "invalid VASubpictureID";
359 case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
360 return "attribute not supported";
361 case VA_STATUS_ERROR_MAX_NUM_EXCEEDED:
362 return "list argument exceeds maximum number";
363 case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
364 return "the requested VAProfile is not supported";
365 case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
366 return "the requested VAEntryPoint is not supported";
367 case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
368 return "the requested RT Format is not supported";
369 case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
370 return "the requested VABufferType is not supported";
371 case VA_STATUS_ERROR_SURFACE_BUSY:
372 return "surface is in use";
373 case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
374 return "flag not supported";
375 case VA_STATUS_ERROR_INVALID_PARAMETER:
376 return "invalid parameter";
377 case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
378 return "resolution not supported";
379 case VA_STATUS_ERROR_UNIMPLEMENTED:
380 return "the requested function is not implemented";
381 case VA_STATUS_ERROR_SURFACE_IN_DISPLAYING:
382 return "surface is in displaying (may by overlay)" ;
383 case VA_STATUS_ERROR_INVALID_IMAGE_FORMAT:
384 return "invalid VAImageFormat";
385 case VA_STATUS_ERROR_UNKNOWN:
386 return "unknown libva error";
388 return "unknown libva error / description missing";
391 VAStatus vaInitialize (
393 int *major_version, /* out */
394 int *minor_version /* out */
397 const char *driver_name_env = NULL;
398 char *driver_name = NULL;
407 va_infoMessage("libva version %s\n", VA_VERSION_S);
409 driver_name_env = getenv("LIBVA_DRIVER_NAME");
410 if (driver_name_env && geteuid() == getuid())
412 /* Don't allow setuid apps to use LIBVA_DRIVER_NAME */
413 driver_name = strdup(driver_name_env);
414 vaStatus = VA_STATUS_SUCCESS;
415 va_infoMessage("User requested driver '%s'\n", driver_name);
419 vaStatus = va_getDriverName(dpy, &driver_name);
420 va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
423 if (VA_STATUS_SUCCESS == vaStatus)
425 vaStatus = va_openDriver(dpy, driver_name);
426 va_infoMessage("va_openDriver() returns %d\n", vaStatus);
428 *major_version = VA_MAJOR_VERSION;
429 *minor_version = VA_MINOR_VERSION;
435 VA_TRACE(va_TraceInitialize, dpy, major_version, minor_version);
442 * After this call, all library internal resources will be cleaned up
444 VAStatus vaTerminate (
448 VAStatus vaStatus = VA_STATUS_SUCCESS;
449 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
450 VADriverContextP old_ctx;
455 if (old_ctx->handle) {
456 vaStatus = old_ctx->vtable->vaTerminate(old_ctx);
457 dlclose(old_ctx->handle);
458 old_ctx->handle = NULL;
460 free(old_ctx->vtable);
461 old_ctx->vtable = NULL;
463 if (VA_STATUS_SUCCESS == vaStatus)
464 pDisplayContext->vaDestroy(pDisplayContext);
466 VA_TRACE(va_TraceTerminate, dpy);
476 * vaQueryVendorString returns a pointer to a zero-terminated string
477 * describing some aspects of the VA implemenation on a specific
478 * hardware accelerator. The format of the returned string is:
479 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
480 * e.g. for the Intel GMA500 implementation, an example would be:
481 * "IntelGMA500-1.0-0.2-patch3
483 const char *vaQueryVendorString (
487 if( !vaDisplayIsValid(dpy) )
490 return CTX(dpy)->str_vendor;
494 /* Get maximum number of profiles supported by the implementation */
495 int vaMaxNumProfiles (
499 if( !vaDisplayIsValid(dpy) )
502 return CTX(dpy)->max_profiles;
505 /* Get maximum number of entrypoints supported by the implementation */
506 int vaMaxNumEntrypoints (
510 if( !vaDisplayIsValid(dpy) )
513 return CTX(dpy)->max_entrypoints;
517 /* Get maximum number of attributs supported by the implementation */
518 int vaMaxNumConfigAttributes (
522 if( !vaDisplayIsValid(dpy) )
525 return CTX(dpy)->max_attributes;
528 VAStatus vaQueryConfigEntrypoints (
531 VAEntrypoint *entrypoints, /* out */
532 int *num_entrypoints /* out */
535 VADriverContextP ctx;
539 return ctx->vtable->vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
542 VAStatus vaGetConfigAttributes (
545 VAEntrypoint entrypoint,
546 VAConfigAttrib *attrib_list, /* in/out */
550 VADriverContextP ctx;
554 return ctx->vtable->vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
557 VAStatus vaQueryConfigProfiles (
559 VAProfile *profile_list, /* out */
560 int *num_profiles /* out */
563 VADriverContextP ctx;
567 return ctx->vtable->vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
570 VAStatus vaCreateConfig (
573 VAEntrypoint entrypoint,
574 VAConfigAttrib *attrib_list,
576 VAConfigID *config_id /* out */
579 VADriverContextP ctx;
580 VAStatus vaStatus = VA_STATUS_SUCCESS;
586 VA_FOOL(va_FoolCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
588 vaStatus = ctx->vtable->vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
590 VA_TRACE(va_TraceCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
595 VAStatus vaDestroyConfig (
600 VADriverContextP ctx;
604 return ctx->vtable->vaDestroyConfig ( ctx, config_id );
607 VAStatus vaQueryConfigAttributes (
609 VAConfigID config_id,
610 VAProfile *profile, /* out */
611 VAEntrypoint *entrypoint, /* out */
612 VAConfigAttrib *attrib_list,/* out */
613 int *num_attribs /* out */
616 VADriverContextP ctx;
620 return ctx->vtable->vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
623 VAStatus vaCreateSurfaces (
629 VASurfaceID *surfaces /* out */
632 VADriverContextP ctx;
639 vaStatus = ctx->vtable->vaCreateSurfaces( ctx, width, height, format, num_surfaces, surfaces );
641 VA_TRACE(va_TraceCreateSurface, dpy, width, height, format, num_surfaces, surfaces);
643 VA_FOOL(va_FoolCreateSurfaces, dpy, width, height, format, num_surfaces, surfaces);
649 VAStatus vaDestroySurfaces (
651 VASurfaceID *surface_list,
655 VADriverContextP ctx;
659 return ctx->vtable->vaDestroySurfaces( ctx, surface_list, num_surfaces );
662 VAStatus vaCreateContext (
664 VAConfigID config_id,
668 VASurfaceID *render_targets,
669 int num_render_targets,
670 VAContextID *context /* out */
673 VADriverContextP ctx;
679 vaStatus = ctx->vtable->vaCreateContext( ctx, config_id, picture_width, picture_height,
680 flag, render_targets, num_render_targets, context );
682 VA_TRACE(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
687 VAStatus vaDestroyContext (
692 VADriverContextP ctx;
696 return ctx->vtable->vaDestroyContext( ctx, context );
699 VAStatus vaCreateBuffer (
701 VAContextID context, /* in */
702 VABufferType type, /* in */
703 unsigned int size, /* in */
704 unsigned int num_elements, /* in */
706 VABufferID *buf_id /* out */
709 VADriverContextP ctx;
714 VA_FOOL(va_FoolCreateBuffer, dpy, context, type, size, num_elements, data, buf_id);
716 return VA_STATUS_SUCCESS;
718 return ctx->vtable->vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
721 VAStatus vaBufferSetNumElements (
723 VABufferID buf_id, /* in */
724 unsigned int num_elements /* in */
727 VADriverContextP ctx;
731 return ctx->vtable->vaBufferSetNumElements( ctx, buf_id, num_elements );
735 VAStatus vaMapBuffer (
737 VABufferID buf_id, /* in */
738 void **pbuf /* out */
741 VADriverContextP ctx;
748 VA_FOOL(va_FoolMapBuffer, dpy, buf_id, pbuf);
750 return VA_STATUS_SUCCESS;
752 va_status = ctx->vtable->vaMapBuffer( ctx, buf_id, pbuf );
754 if (va_status == VA_STATUS_SUCCESS)
755 VA_TRACE(va_TraceMapBuffer, dpy, buf_id, pbuf);
760 VAStatus vaUnmapBuffer (
762 VABufferID buf_id /* in */
765 VADriverContextP ctx;
770 VA_FOOL(va_FoolUnmapBuffer, dpy, buf_id);
772 return VA_STATUS_SUCCESS;
774 return ctx->vtable->vaUnmapBuffer( ctx, buf_id );
777 VAStatus vaDestroyBuffer (
782 VADriverContextP ctx;
786 return ctx->vtable->vaDestroyBuffer( ctx, buffer_id );
789 VAStatus vaBufferInfo (
791 VAContextID context, /* in */
792 VABufferID buf_id, /* in */
793 VABufferType *type, /* out */
794 unsigned int *size, /* out */
795 unsigned int *num_elements /* out */
798 VADriverContextP ctx;
802 return ctx->vtable->vaBufferInfo( ctx, context, buf_id, type, size, num_elements );
805 VAStatus vaBeginPicture (
808 VASurfaceID render_target
811 VADriverContextP ctx;
817 VA_TRACE(va_TraceBeginPicture, dpy, context, render_target);
819 VA_FOOL(va_FoolBeginPicture, dpy, context, render_target);
821 return VA_STATUS_SUCCESS;
823 return ctx->vtable->vaBeginPicture( ctx, context, render_target );
826 VAStatus vaRenderPicture (
833 VADriverContextP ctx;
839 VA_FOOL(va_FoolRenderPicture, dpy, context, buffers, num_buffers);
841 return VA_STATUS_SUCCESS;
843 VA_TRACE(va_TraceRenderPicture, dpy, context, buffers, num_buffers);
845 return ctx->vtable->vaRenderPicture( ctx, context, buffers, num_buffers );
848 VAStatus vaEndPicture (
854 VADriverContextP ctx;
860 VA_FOOL(va_FoolEndPicture, dpy, context);
862 VA_TRACE(va_TraceEndPicture, dpy, context);
863 return VA_STATUS_SUCCESS;
866 va_status = ctx->vtable->vaEndPicture( ctx, context );
868 VA_TRACE(va_TraceEndPicture, dpy, context);
873 VAStatus vaSyncSurface (
875 VASurfaceID render_target
879 VADriverContextP ctx;
885 VA_FOOL(va_FoolSyncSurface, dpy, render_target);
887 return VA_STATUS_SUCCESS;
889 va_status = ctx->vtable->vaSyncSurface( ctx, render_target );
890 VA_TRACE(va_TraceSyncSurface, dpy, render_target);
895 VAStatus vaQuerySurfaceStatus (
897 VASurfaceID render_target,
898 VASurfaceStatus *status /* out */
902 VADriverContextP ctx;
906 va_status = ctx->vtable->vaQuerySurfaceStatus( ctx, render_target, status );
908 VA_TRACE(va_TraceQuerySurfaceStatus, dpy, render_target, status);
913 VAStatus vaQuerySurfaceError (
916 VAStatus error_status,
917 void **error_info /*out*/
921 VADriverContextP ctx;
925 va_status = ctx->vtable->vaQuerySurfaceError( ctx, surface, error_status, error_info );
927 VA_TRACE(va_TraceQuerySurfaceError, dpy, surface, error_status, error_info);
932 /* Get maximum number of image formats supported by the implementation */
933 int vaMaxNumImageFormats (
937 if( !vaDisplayIsValid(dpy) )
940 return CTX(dpy)->max_image_formats;
943 VAStatus vaQueryImageFormats (
945 VAImageFormat *format_list, /* out */
946 int *num_formats /* out */
949 VADriverContextP ctx;
953 return ctx->vtable->vaQueryImageFormats ( ctx, format_list, num_formats);
957 * The width and height fields returned in the VAImage structure may get
958 * enlarged for some YUV formats. The size of the data buffer that needs
959 * to be allocated will be given in the "data_size" field in VAImage.
960 * Image data is not allocated by this function. The client should
961 * allocate the memory and fill in the VAImage structure's data field
962 * after looking at "data_size" returned from the library.
964 VAStatus vaCreateImage (
966 VAImageFormat *format,
969 VAImage *image /* out */
972 VADriverContextP ctx;
976 return ctx->vtable->vaCreateImage ( ctx, format, width, height, image);
980 * Should call DestroyImage before destroying the surface it is bound to
982 VAStatus vaDestroyImage (
987 VADriverContextP ctx;
991 return ctx->vtable->vaDestroyImage ( ctx, image);
994 VAStatus vaSetImagePalette (
997 unsigned char *palette
1000 VADriverContextP ctx;
1004 return ctx->vtable->vaSetImagePalette ( ctx, image, palette);
1008 * Retrieve surface data into a VAImage
1009 * Image must be in a format supported by the implementation
1011 VAStatus vaGetImage (
1013 VASurfaceID surface,
1014 int x, /* coordinates of the upper left source pixel */
1016 unsigned int width, /* width and height of the region */
1017 unsigned int height,
1021 VADriverContextP ctx;
1025 return ctx->vtable->vaGetImage ( ctx, surface, x, y, width, height, image);
1029 * Copy data from a VAImage to a surface
1030 * Image must be in a format supported by the implementation
1032 VAStatus vaPutImage (
1034 VASurfaceID surface,
1038 unsigned int src_width,
1039 unsigned int src_height,
1042 unsigned int dest_width,
1043 unsigned int dest_height
1046 VADriverContextP ctx;
1050 return ctx->vtable->vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
1054 * Derive an VAImage from an existing surface.
1055 * This interface will derive a VAImage and corresponding image buffer from
1056 * an existing VA Surface. The image buffer can then be mapped/unmapped for
1057 * direct CPU access. This operation is only possible on implementations with
1058 * direct rendering capabilities and internal surface formats that can be
1059 * represented with a VAImage. When the operation is not possible this interface
1060 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
1061 * to using vaCreateImage + vaPutImage to accomplish the same task in an
1064 * Implementations should only return success when the resulting image buffer
1065 * would be useable with vaMap/Unmap.
1067 * When directly accessing a surface special care must be taken to insure
1068 * proper synchronization with the graphics hardware. Clients should call
1069 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
1070 * rendering or currently being displayed by an overlay.
1072 * Additionally nothing about the contents of a surface should be assumed
1073 * following a vaPutSurface. Implementations are free to modify the surface for
1074 * scaling or subpicture blending within a call to vaPutImage.
1076 * Calls to vaPutImage or vaGetImage using the same surface from which the image
1077 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
1078 * vaGetImage with other surfaces is supported.
1080 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
1081 * image and image buffer structures will be destroyed; however, the underlying
1082 * surface will remain unchanged until freed with vaDestroySurfaces.
1084 VAStatus vaDeriveImage (
1086 VASurfaceID surface,
1087 VAImage *image /* out */
1090 VADriverContextP ctx;
1094 return ctx->vtable->vaDeriveImage ( ctx, surface, image );
1098 /* Get maximum number of subpicture formats supported by the implementation */
1099 int vaMaxNumSubpictureFormats (
1103 if( !vaDisplayIsValid(dpy) )
1106 return CTX(dpy)->max_subpic_formats;
1110 * Query supported subpicture formats
1111 * The caller must provide a "format_list" array that can hold at
1112 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1113 * for each format to indicate additional capabilities for that format. The actual
1114 * number of formats returned in "format_list" is returned in "num_formats".
1116 VAStatus vaQuerySubpictureFormats (
1118 VAImageFormat *format_list, /* out */
1119 unsigned int *flags, /* out */
1120 unsigned int *num_formats /* out */
1123 VADriverContextP ctx;
1129 VA_FOOL(va_FoolQuerySubpictureFormats, dpy, format_list, flags, num_formats);
1131 return VA_STATUS_SUCCESS;
1133 return ctx->vtable->vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
1137 * Subpictures are created with an image associated.
1139 VAStatus vaCreateSubpicture (
1142 VASubpictureID *subpicture /* out */
1145 VADriverContextP ctx;
1149 return ctx->vtable->vaCreateSubpicture ( ctx, image, subpicture );
1153 * Destroy the subpicture before destroying the image it is assocated to
1155 VAStatus vaDestroySubpicture (
1157 VASubpictureID subpicture
1160 VADriverContextP ctx;
1164 return ctx->vtable->vaDestroySubpicture ( ctx, subpicture);
1167 VAStatus vaSetSubpictureImage (
1169 VASubpictureID subpicture,
1173 VADriverContextP ctx;
1177 return ctx->vtable->vaSetSubpictureImage ( ctx, subpicture, image);
1182 * If chromakey is enabled, then the area where the source value falls within
1183 * the chromakey [min, max] range is transparent
1185 VAStatus vaSetSubpictureChromakey (
1187 VASubpictureID subpicture,
1188 unsigned int chromakey_min,
1189 unsigned int chromakey_max,
1190 unsigned int chromakey_mask
1193 VADriverContextP ctx;
1197 return ctx->vtable->vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
1202 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1203 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1204 * the overall alpha is per-pixel alpha multiplied by the global alpha
1206 VAStatus vaSetSubpictureGlobalAlpha (
1208 VASubpictureID subpicture,
1212 VADriverContextP ctx;
1216 return ctx->vtable->vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
1220 vaAssociateSubpicture associates the subpicture with the target_surface.
1221 It defines the region mapping between the subpicture and the target
1222 surface through source and destination rectangles (with the same width and height).
1223 Both will be displayed at the next call to vaPutSurface. Additional
1224 associations before the call to vaPutSurface simply overrides the association.
1226 VAStatus vaAssociateSubpicture (
1228 VASubpictureID subpicture,
1229 VASurfaceID *target_surfaces,
1231 short src_x, /* upper left offset in subpicture */
1233 unsigned short src_width,
1234 unsigned short src_height,
1235 short dest_x, /* upper left offset in surface */
1237 unsigned short dest_width,
1238 unsigned short dest_height,
1240 * whether to enable chroma-keying or global-alpha
1241 * see VA_SUBPICTURE_XXX values
1246 VADriverContextP ctx;
1250 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 );
1254 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1256 VAStatus vaDeassociateSubpicture (
1258 VASubpictureID subpicture,
1259 VASurfaceID *target_surfaces,
1263 VADriverContextP ctx;
1267 return ctx->vtable->vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
1271 /* Get maximum number of display attributes supported by the implementation */
1272 int vaMaxNumDisplayAttributes (
1278 if( !vaDisplayIsValid(dpy) )
1281 tmp = CTX(dpy)->max_display_attributes;
1283 VA_TRACE(va_TraceMaxNumDisplayAttributes, dpy, tmp);
1289 * Query display attributes
1290 * The caller must provide a "attr_list" array that can hold at
1291 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1292 * returned in "attr_list" is returned in "num_attributes".
1294 VAStatus vaQueryDisplayAttributes (
1296 VADisplayAttribute *attr_list, /* out */
1297 int *num_attributes /* out */
1300 VADriverContextP ctx;
1306 va_status = ctx->vtable->vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
1308 VA_TRACE(va_TraceQueryDisplayAttributes, dpy, attr_list, num_attributes);
1315 * Get display attributes
1316 * This function returns the current attribute values in "attr_list".
1317 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1318 * from vaQueryDisplayAttributes() can have their values retrieved.
1320 VAStatus vaGetDisplayAttributes (
1322 VADisplayAttribute *attr_list, /* in/out */
1326 VADriverContextP ctx;
1332 va_status = ctx->vtable->vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
1334 VA_TRACE(va_TraceGetDisplayAttributes, dpy, attr_list, num_attributes);
1340 * Set display attributes
1341 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1342 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1343 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1345 VAStatus vaSetDisplayAttributes (
1347 VADisplayAttribute *attr_list,
1351 VADriverContextP ctx;
1355 VA_TRACE(va_TraceSetDisplayAttributes, dpy, attr_list, num_attributes);
1358 return ctx->vtable->vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
1361 VAStatus vaLockSurface(VADisplay dpy,
1362 VASurfaceID surface,
1363 unsigned int *fourcc, /* following are output argument */
1364 unsigned int *luma_stride,
1365 unsigned int *chroma_u_stride,
1366 unsigned int *chroma_v_stride,
1367 unsigned int *luma_offset,
1368 unsigned int *chroma_u_offset,
1369 unsigned int *chroma_v_offset,
1370 unsigned int *buffer_name,
1374 VADriverContextP ctx;
1378 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);
1382 VAStatus vaUnlockSurface(VADisplay dpy,
1386 VADriverContextP ctx;
1390 return ctx->vtable->vaUnlockSurface( ctx, surface );