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_INIT_FUNC "__vaDriverInit_0_31"
42 #define DRIVER_EXTENSION "_drv_video.so"
44 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
45 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
48 #define CHECK_VTABLE(s, ctx, func) if (!va_checkVtable(ctx->vtable.va##func, #func)) s = VA_STATUS_ERROR_UNKNOWN;
49 #define CHECK_MAXIMUM(s, ctx, var) if (!va_checkMaximum(ctx->max_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
50 #define CHECK_STRING(s, ctx, var) if (!va_checkString(ctx->str_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
52 extern int trace_flag;
53 #define VA_TRACE(trace_func,...) \
55 trace_func(__VA_ARGS__); \
59 * read a config "env" for libva.conf or from environment setting
60 * liva.conf has higher priority
61 * return 0: the "env" is set, and the value is copied into env_value
62 * 1: the env is not set
64 int va_parseConfig(char *env, char *env_value)
66 char *token, *value, *saveptr;
74 fp = fopen("/etc/libva.conf", "r");
75 while (fp && (fgets(oneline, 1024, fp) != NULL)) {
76 if (strlen(oneline) == 1)
78 token = strtok_r(oneline, "=\n", &saveptr);
79 value = strtok_r(NULL, "=\n", &saveptr);
81 if (NULL == token || NULL == value)
84 if (strcmp(token, env) == 0) {
86 strncpy(env_value,value, 1024);
96 /* no setting in config file, use env setting */
99 strncpy(env_value, getenv(env), 1024);
107 int vaDisplayIsValid(VADisplay dpy)
109 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
110 return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
113 void va_errorMessage(const char *msg, ...)
117 fprintf(stderr, "libva error: ");
119 vfprintf(stderr, msg, args);
123 void va_infoMessage(const char *msg, ...)
127 fprintf(stderr, "libva: ");
129 vfprintf(stderr, msg, args);
133 static Bool va_checkVtable(void *ptr, char *function)
137 va_errorMessage("No valid vtable entry for va%s\n", function);
143 static Bool va_checkMaximum(int value, char *variable)
147 va_errorMessage("Failed to define max_%s in init\n", variable);
153 static Bool va_checkString(const char* value, char *variable)
157 va_errorMessage("Failed to define str_%s in init\n", variable);
163 static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
165 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
167 return pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
170 static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
172 VADriverContextP ctx = CTX(dpy);
173 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
174 char *search_path = NULL;
178 if (geteuid() == getuid())
180 /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
181 search_path = getenv("LIBVA_DRIVERS_PATH");
185 search_path = VA_DRIVERS_PATH;
188 search_path = strdup((const char *)search_path);
189 driver_dir = strtok_r((const char *)search_path, ":", &saveptr);
193 char *driver_path = (char *) malloc( strlen(driver_dir) +
194 strlen(driver_name) +
195 strlen(DRIVER_EXTENSION) + 2 );
196 strncpy( driver_path, driver_dir, strlen(driver_dir) + 1);
197 strncat( driver_path, "/", strlen("/") );
198 strncat( driver_path, driver_name, strlen(driver_name) );
199 strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
201 va_infoMessage("Trying to open %s\n", driver_path);
203 handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
205 handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
209 /* Don't give errors for non-existing files */
210 if (0 == access( driver_path, F_OK))
212 va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
217 VADriverInit init_func;
218 init_func = (VADriverInit) dlsym(handle, DRIVER_INIT_FUNC);
221 va_errorMessage("%s has no function %s\n", driver_path, DRIVER_INIT_FUNC);
226 vaStatus = (*init_func)(ctx);
228 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)
280 va_errorMessage("%s init failed\n", driver_path);
283 if (VA_STATUS_SUCCESS == vaStatus)
285 ctx->handle = handle;
293 driver_dir = strtok_r(NULL, ":", &saveptr);
301 VAPrivFunc vaGetLibFunc(VADisplay dpy, const char *func)
303 VADriverContextP ctx;
304 if( !vaDisplayIsValid(dpy) )
308 if (NULL == ctx->handle)
311 return (VAPrivFunc) dlsym(ctx->handle, func);
316 * Returns a short english description of error_status
318 const char *vaErrorStr(VAStatus error_status)
322 case VA_STATUS_SUCCESS:
323 return "success (no error)";
324 case VA_STATUS_ERROR_OPERATION_FAILED:
325 return "operation failed";
326 case VA_STATUS_ERROR_ALLOCATION_FAILED:
327 return "resource allocation failed";
328 case VA_STATUS_ERROR_INVALID_DISPLAY:
329 return "invalid VADisplay";
330 case VA_STATUS_ERROR_INVALID_CONFIG:
331 return "invalid VAConfigID";
332 case VA_STATUS_ERROR_INVALID_CONTEXT:
333 return "invalid VAContextID";
334 case VA_STATUS_ERROR_INVALID_SURFACE:
335 return "invalid VASurfaceID";
336 case VA_STATUS_ERROR_INVALID_BUFFER:
337 return "invalid VABufferID";
338 case VA_STATUS_ERROR_INVALID_IMAGE:
339 return "invalid VAImageID";
340 case VA_STATUS_ERROR_INVALID_SUBPICTURE:
341 return "invalid VASubpictureID";
342 case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
343 return "attribute not supported";
344 case VA_STATUS_ERROR_MAX_NUM_EXCEEDED:
345 return "list argument exceeds maximum number";
346 case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
347 return "the requested VAProfile is not supported";
348 case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
349 return "the requested VAEntryPoint is not supported";
350 case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
351 return "the requested RT Format is not supported";
352 case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
353 return "the requested VABufferType is not supported";
354 case VA_STATUS_ERROR_SURFACE_BUSY:
355 return "surface is in use";
356 case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
357 return "flag not supported";
358 case VA_STATUS_ERROR_INVALID_PARAMETER:
359 return "invalid parameter";
360 case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
361 return "resolution not supported";
362 case VA_STATUS_ERROR_UNIMPLEMENTED:
363 return "the requested function is not implemented";
364 case VA_STATUS_ERROR_SURFACE_IN_DISPLAYING:
365 return "surface is in displaying (may by overlay)" ;
366 case VA_STATUS_ERROR_INVALID_IMAGE_FORMAT:
367 return "invalid VAImageFormat";
368 case VA_STATUS_ERROR_UNKNOWN:
369 return "unknown libva error";
371 return "unknown libva error / description missing";
374 VAStatus vaInitialize (
376 int *major_version, /* out */
377 int *minor_version /* out */
380 const char *driver_name_env = NULL;
381 char *driver_name = NULL;
390 va_infoMessage("libva version %s\n", VA_VERSION_S);
392 driver_name_env = getenv("LIBVA_DRIVER_NAME");
393 if (driver_name_env && geteuid() == getuid())
395 /* Don't allow setuid apps to use LIBVA_DRIVER_NAME */
396 driver_name = strdup(driver_name_env);
397 vaStatus = VA_STATUS_SUCCESS;
398 va_infoMessage("User requested driver '%s'\n", driver_name);
402 vaStatus = va_getDriverName(dpy, &driver_name);
403 va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
406 if (VA_STATUS_SUCCESS == vaStatus)
408 vaStatus = va_openDriver(dpy, driver_name);
409 va_infoMessage("va_openDriver() returns %d\n", vaStatus);
411 *major_version = VA_MAJOR_VERSION;
412 *minor_version = VA_MINOR_VERSION;
422 * After this call, all library internal resources will be cleaned up
424 VAStatus vaTerminate (
428 VAStatus vaStatus = VA_STATUS_SUCCESS;
429 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
430 VADriverContextP old_ctx;
437 vaStatus = old_ctx->vtable.vaTerminate(old_ctx);
438 dlclose(old_ctx->handle);
439 old_ctx->handle = NULL;
442 if (VA_STATUS_SUCCESS == vaStatus)
443 pDisplayContext->vaDestroy(pDisplayContext);
453 * vaQueryVendorString returns a pointer to a zero-terminated string
454 * describing some aspects of the VA implemenation on a specific
455 * hardware accelerator. The format of the returned string is:
456 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
457 * e.g. for the Intel GMA500 implementation, an example would be:
458 * "IntelGMA500-1.0-0.2-patch3
460 const char *vaQueryVendorString (
464 if( !vaDisplayIsValid(dpy) )
467 return CTX(dpy)->str_vendor;
471 /* Get maximum number of profiles supported by the implementation */
472 int vaMaxNumProfiles (
476 if( !vaDisplayIsValid(dpy) )
479 return CTX(dpy)->max_profiles;
482 /* Get maximum number of entrypoints supported by the implementation */
483 int vaMaxNumEntrypoints (
487 if( !vaDisplayIsValid(dpy) )
490 return CTX(dpy)->max_entrypoints;
494 /* Get maximum number of attributs supported by the implementation */
495 int vaMaxNumConfigAttributes (
499 if( !vaDisplayIsValid(dpy) )
502 return CTX(dpy)->max_attributes;
505 VAStatus vaQueryConfigEntrypoints (
508 VAEntrypoint *entrypoints, /* out */
509 int *num_entrypoints /* out */
512 VADriverContextP ctx;
516 return ctx->vtable.vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
519 VAStatus vaGetConfigAttributes (
522 VAEntrypoint entrypoint,
523 VAConfigAttrib *attrib_list, /* in/out */
527 VADriverContextP ctx;
531 return ctx->vtable.vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
534 VAStatus vaQueryConfigProfiles (
536 VAProfile *profile_list, /* out */
537 int *num_profiles /* out */
540 VADriverContextP ctx;
544 return ctx->vtable.vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
547 VAStatus vaCreateConfig (
550 VAEntrypoint entrypoint,
551 VAConfigAttrib *attrib_list,
553 VAConfigID *config_id /* out */
556 VADriverContextP ctx;
560 VA_TRACE(va_TraceCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
561 va_FoolCreateConfig(dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
562 return ctx->vtable.vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
565 VAStatus vaDestroyConfig (
570 VADriverContextP ctx;
574 return ctx->vtable.vaDestroyConfig ( ctx, config_id );
577 VAStatus vaQueryConfigAttributes (
579 VAConfigID config_id,
580 VAProfile *profile, /* out */
581 VAEntrypoint *entrypoint, /* out */
582 VAConfigAttrib *attrib_list,/* out */
583 int *num_attribs /* out */
586 VADriverContextP ctx;
590 return ctx->vtable.vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
593 VAStatus vaCreateSurfaces (
599 VASurfaceID *surfaces /* out */
602 VADriverContextP ctx;
607 VA_TRACE(va_TraceCreateSurface, dpy, width, height, format, num_surfaces, surfaces);
609 ret = ctx->vtable.vaCreateSurfaces( ctx, width, height, format, num_surfaces, surfaces );
610 va_FoolCreateSurfaces(dpy, width, height, format, num_surfaces, surfaces);
615 VAStatus vaDestroySurfaces (
617 VASurfaceID *surface_list,
621 VADriverContextP ctx;
625 return ctx->vtable.vaDestroySurfaces( ctx, surface_list, num_surfaces );
628 VAStatus vaCreateContext (
630 VAConfigID config_id,
634 VASurfaceID *render_targets,
635 int num_render_targets,
636 VAContextID *context /* out */
639 VADriverContextP ctx;
643 VA_TRACE(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
644 return ctx->vtable.vaCreateContext( ctx, config_id, picture_width, picture_height,
645 flag, render_targets, num_render_targets, context );
648 VAStatus vaDestroyContext (
653 VADriverContextP ctx;
657 return ctx->vtable.vaDestroyContext( ctx, context );
660 VAStatus vaCreateBuffer (
662 VAContextID context, /* in */
663 VABufferType type, /* in */
664 unsigned int size, /* in */
665 unsigned int num_elements, /* in */
667 VABufferID *buf_id /* out */
670 VADriverContextP ctx;
674 if (va_FoolCreateBuffer(dpy, context, type, size, num_elements, data, buf_id))
675 return VA_STATUS_SUCCESS;
676 return ctx->vtable.vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
679 VAStatus vaBufferSetNumElements (
681 VABufferID buf_id, /* in */
682 unsigned int num_elements /* in */
685 VADriverContextP ctx;
689 return ctx->vtable.vaBufferSetNumElements( ctx, buf_id, num_elements );
693 VAStatus vaMapBuffer (
695 VABufferID buf_id, /* in */
696 void **pbuf /* out */
699 VADriverContextP ctx;
705 if (va_FoolMapBuffer(dpy, buf_id, pbuf))
706 return VA_STATUS_SUCCESS;
707 va_status = ctx->vtable.vaMapBuffer( ctx, buf_id, pbuf );
709 if (va_status == VA_STATUS_SUCCESS)
710 VA_TRACE(va_TraceMapBuffer, dpy, buf_id, pbuf);
715 VAStatus vaUnmapBuffer (
717 VABufferID buf_id /* in */
720 VADriverContextP ctx;
724 if (va_FoolUnmapBuffer(dpy, buf_id))
725 return VA_STATUS_SUCCESS;
726 return ctx->vtable.vaUnmapBuffer( ctx, buf_id );
729 VAStatus vaDestroyBuffer (
734 VADriverContextP ctx;
738 return ctx->vtable.vaDestroyBuffer( ctx, buffer_id );
741 VAStatus vaBufferInfo (
743 VAContextID context, /* in */
744 VABufferID buf_id, /* in */
745 VABufferType *type, /* out */
746 unsigned int *size, /* out */
747 unsigned int *num_elements /* out */
750 VADriverContextP ctx;
754 return ctx->vtable.vaBufferInfo( ctx, context, buf_id, type, size, num_elements );
757 VAStatus vaBeginPicture (
760 VASurfaceID render_target
763 VADriverContextP ctx;
767 VA_TRACE(va_TraceBeginPicture, dpy, context, render_target);
769 if (va_FoolBeginPicture(dpy, context, render_target))
770 return VA_STATUS_SUCCESS;
772 return ctx->vtable.vaBeginPicture( ctx, context, render_target );
775 VAStatus vaRenderPicture (
782 VADriverContextP ctx;
786 if (va_FoolRenderPicture(dpy, context, buffers, num_buffers))
787 return VA_STATUS_SUCCESS;
789 VA_TRACE(va_TraceRenderPicture, dpy, context, buffers, num_buffers);
791 return ctx->vtable.vaRenderPicture( ctx, context, buffers, num_buffers );
794 VAStatus vaEndPicture (
800 VADriverContextP ctx;
804 if (va_FoolEndPicture(dpy, context)) {
805 VA_TRACE(va_TraceEndPicture, dpy, context);
806 return VA_STATUS_SUCCESS;
809 va_status = ctx->vtable.vaEndPicture( ctx, context );
811 VA_TRACE(va_TraceEndPicture, dpy, context);
816 VAStatus vaSyncSurface (
818 VASurfaceID render_target
821 VADriverContextP ctx;
825 if (va_FoolSyncSurface( dpy, render_target))
826 return VA_STATUS_SUCCESS;
828 return ctx->vtable.vaSyncSurface( ctx, render_target );
831 VAStatus vaQuerySurfaceStatus (
833 VASurfaceID render_target,
834 VASurfaceStatus *status /* out */
837 VADriverContextP ctx;
841 return ctx->vtable.vaQuerySurfaceStatus( ctx, render_target, status );
844 /* Get maximum number of image formats supported by the implementation */
845 int vaMaxNumImageFormats (
849 if( !vaDisplayIsValid(dpy) )
852 return CTX(dpy)->max_image_formats;
855 VAStatus vaQueryImageFormats (
857 VAImageFormat *format_list, /* out */
858 int *num_formats /* out */
861 VADriverContextP ctx;
865 return ctx->vtable.vaQueryImageFormats ( ctx, format_list, num_formats);
869 * The width and height fields returned in the VAImage structure may get
870 * enlarged for some YUV formats. The size of the data buffer that needs
871 * to be allocated will be given in the "data_size" field in VAImage.
872 * Image data is not allocated by this function. The client should
873 * allocate the memory and fill in the VAImage structure's data field
874 * after looking at "data_size" returned from the library.
876 VAStatus vaCreateImage (
878 VAImageFormat *format,
881 VAImage *image /* out */
884 VADriverContextP ctx;
888 return ctx->vtable.vaCreateImage ( ctx, format, width, height, image);
892 * Should call DestroyImage before destroying the surface it is bound to
894 VAStatus vaDestroyImage (
899 VADriverContextP ctx;
903 return ctx->vtable.vaDestroyImage ( ctx, image);
906 VAStatus vaSetImagePalette (
909 unsigned char *palette
912 VADriverContextP ctx;
916 return ctx->vtable.vaSetImagePalette ( ctx, image, palette);
920 * Retrieve surface data into a VAImage
921 * Image must be in a format supported by the implementation
923 VAStatus vaGetImage (
926 int x, /* coordinates of the upper left source pixel */
928 unsigned int width, /* width and height of the region */
933 VADriverContextP ctx;
937 return ctx->vtable.vaGetImage ( ctx, surface, x, y, width, height, image);
941 * Copy data from a VAImage to a surface
942 * Image must be in a format supported by the implementation
944 VAStatus vaPutImage (
950 unsigned int src_width,
951 unsigned int src_height,
954 unsigned int dest_width,
955 unsigned int dest_height
958 VADriverContextP ctx;
962 return ctx->vtable.vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
966 * Derive an VAImage from an existing surface.
967 * This interface will derive a VAImage and corresponding image buffer from
968 * an existing VA Surface. The image buffer can then be mapped/unmapped for
969 * direct CPU access. This operation is only possible on implementations with
970 * direct rendering capabilities and internal surface formats that can be
971 * represented with a VAImage. When the operation is not possible this interface
972 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
973 * to using vaCreateImage + vaPutImage to accomplish the same task in an
976 * Implementations should only return success when the resulting image buffer
977 * would be useable with vaMap/Unmap.
979 * When directly accessing a surface special care must be taken to insure
980 * proper synchronization with the graphics hardware. Clients should call
981 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
982 * rendering or currently being displayed by an overlay.
984 * Additionally nothing about the contents of a surface should be assumed
985 * following a vaPutSurface. Implementations are free to modify the surface for
986 * scaling or subpicture blending within a call to vaPutImage.
988 * Calls to vaPutImage or vaGetImage using the same surface from which the image
989 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
990 * vaGetImage with other surfaces is supported.
992 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
993 * image and image buffer structures will be destroyed; however, the underlying
994 * surface will remain unchanged until freed with vaDestroySurfaces.
996 VAStatus vaDeriveImage (
999 VAImage *image /* out */
1002 VADriverContextP ctx;
1006 return ctx->vtable.vaDeriveImage ( ctx, surface, image );
1010 /* Get maximum number of subpicture formats supported by the implementation */
1011 int vaMaxNumSubpictureFormats (
1015 if( !vaDisplayIsValid(dpy) )
1018 return CTX(dpy)->max_subpic_formats;
1022 * Query supported subpicture formats
1023 * The caller must provide a "format_list" array that can hold at
1024 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1025 * for each format to indicate additional capabilities for that format. The actual
1026 * number of formats returned in "format_list" is returned in "num_formats".
1028 VAStatus vaQuerySubpictureFormats (
1030 VAImageFormat *format_list, /* out */
1031 unsigned int *flags, /* out */
1032 unsigned int *num_formats /* out */
1035 VADriverContextP ctx;
1039 if (va_FoolQuerySubpictureFormats(dpy, format_list, flags, num_formats))
1040 return VA_STATUS_SUCCESS;
1041 return ctx->vtable.vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
1045 * Subpictures are created with an image associated.
1047 VAStatus vaCreateSubpicture (
1050 VASubpictureID *subpicture /* out */
1053 VADriverContextP ctx;
1057 return ctx->vtable.vaCreateSubpicture ( ctx, image, subpicture );
1061 * Destroy the subpicture before destroying the image it is assocated to
1063 VAStatus vaDestroySubpicture (
1065 VASubpictureID subpicture
1068 VADriverContextP ctx;
1072 return ctx->vtable.vaDestroySubpicture ( ctx, subpicture);
1075 VAStatus vaSetSubpictureImage (
1077 VASubpictureID subpicture,
1081 VADriverContextP ctx;
1085 return ctx->vtable.vaSetSubpictureImage ( ctx, subpicture, image);
1090 * If chromakey is enabled, then the area where the source value falls within
1091 * the chromakey [min, max] range is transparent
1093 VAStatus vaSetSubpictureChromakey (
1095 VASubpictureID subpicture,
1096 unsigned int chromakey_min,
1097 unsigned int chromakey_max,
1098 unsigned int chromakey_mask
1101 VADriverContextP ctx;
1105 return ctx->vtable.vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
1110 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1111 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1112 * the overall alpha is per-pixel alpha multiplied by the global alpha
1114 VAStatus vaSetSubpictureGlobalAlpha (
1116 VASubpictureID subpicture,
1120 VADriverContextP ctx;
1124 return ctx->vtable.vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
1128 vaAssociateSubpicture associates the subpicture with the target_surface.
1129 It defines the region mapping between the subpicture and the target
1130 surface through source and destination rectangles (with the same width and height).
1131 Both will be displayed at the next call to vaPutSurface. Additional
1132 associations before the call to vaPutSurface simply overrides the association.
1134 VAStatus vaAssociateSubpicture (
1136 VASubpictureID subpicture,
1137 VASurfaceID *target_surfaces,
1139 short src_x, /* upper left offset in subpicture */
1141 unsigned short src_width,
1142 unsigned short src_height,
1143 short dest_x, /* upper left offset in surface */
1145 unsigned short dest_width,
1146 unsigned short dest_height,
1148 * whether to enable chroma-keying or global-alpha
1149 * see VA_SUBPICTURE_XXX values
1154 VADriverContextP ctx;
1158 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 );
1162 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1164 VAStatus vaDeassociateSubpicture (
1166 VASubpictureID subpicture,
1167 VASurfaceID *target_surfaces,
1171 VADriverContextP ctx;
1175 return ctx->vtable.vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
1179 /* Get maximum number of display attributes supported by the implementation */
1180 int vaMaxNumDisplayAttributes (
1186 if( !vaDisplayIsValid(dpy) )
1189 tmp = CTX(dpy)->max_display_attributes;
1191 VA_TRACE(va_TraceMaxNumDisplayAttributes, dpy, tmp);
1197 * Query display attributes
1198 * The caller must provide a "attr_list" array that can hold at
1199 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1200 * returned in "attr_list" is returned in "num_attributes".
1202 VAStatus vaQueryDisplayAttributes (
1204 VADisplayAttribute *attr_list, /* out */
1205 int *num_attributes /* out */
1208 VADriverContextP ctx;
1214 va_status = ctx->vtable.vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
1216 VA_TRACE(va_TraceQueryDisplayAttributes, dpy, attr_list, num_attributes);
1223 * Get display attributes
1224 * This function returns the current attribute values in "attr_list".
1225 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1226 * from vaQueryDisplayAttributes() can have their values retrieved.
1228 VAStatus vaGetDisplayAttributes (
1230 VADisplayAttribute *attr_list, /* in/out */
1234 VADriverContextP ctx;
1240 va_status = ctx->vtable.vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
1242 VA_TRACE(va_TraceGetDisplayAttributes, dpy, attr_list, num_attributes);
1248 * Set display attributes
1249 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1250 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1251 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1253 VAStatus vaSetDisplayAttributes (
1255 VADisplayAttribute *attr_list,
1259 VADriverContextP ctx;
1263 VA_TRACE(va_TraceSetDisplayAttributes, dpy, attr_list, num_attributes);
1266 return ctx->vtable.vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
1269 VAStatus vaLockSurface(VADisplay dpy,
1270 VASurfaceID surface,
1271 unsigned int *fourcc, /* following are output argument */
1272 unsigned int *luma_stride,
1273 unsigned int *chroma_u_stride,
1274 unsigned int *chroma_v_stride,
1275 unsigned int *luma_offset,
1276 unsigned int *chroma_u_offset,
1277 unsigned int *chroma_v_offset,
1278 unsigned int *buffer_name,
1282 VADriverContextP ctx;
1286 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);
1290 VAStatus vaUnlockSurface(VADisplay dpy,
1294 VADriverContextP ctx;
1298 return ctx->vtable.vaUnlockSurface( ctx, surface );