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;
52 * read a config "env" for libva.conf or from environment setting
53 * liva.conf has higher priority
54 * return 0: the "env" is set, and the value is copied into env_value
55 * 1: the env is not set
57 int va_parseConfig(char *env, char *env_value)
59 char *token, *value, *saveptr;
66 fp = fopen("/etc/libva.conf", "r");
67 while (fp && (fgets(oneline, 1024, fp) != NULL)) {
68 if (strlen(oneline) == 1)
70 token = strtok_r(oneline, "=\n", &saveptr);
71 value = strtok_r(NULL, "=\n", &saveptr);
73 if (NULL == token || NULL == value)
76 if (strcmp(token, env) == 0) {
78 strncpy(env_value,value, 1024);
88 /* no setting in config file, use env setting */
91 strncpy(env_value, getenv(env), 1024);
99 int vaDisplayIsValid(VADisplay dpy)
101 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
102 return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
105 void va_errorMessage(const char *msg, ...)
109 fprintf(stderr, "libva error: ");
111 vfprintf(stderr, msg, args);
115 void va_infoMessage(const char *msg, ...)
119 fprintf(stderr, "libva: ");
121 vfprintf(stderr, msg, args);
125 static Bool va_checkVtable(void *ptr, char *function)
128 va_errorMessage("No valid vtable entry for va%s\n", function);
134 static Bool va_checkMaximum(int value, char *variable)
137 va_errorMessage("Failed to define max_%s in init\n", variable);
143 static Bool va_checkString(const char* value, char *variable)
146 va_errorMessage("Failed to define str_%s in init\n", variable);
153 va_getDriverInitName(char *name, int namelen, int major, int minor)
155 int ret = snprintf(name, namelen, "__vaDriverInit_%d_%d", major, minor);
156 return ret > 0 && ret < namelen;
159 static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
161 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
163 return pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
166 static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
168 VADriverContextP ctx = CTX(dpy);
169 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
170 char *search_path = NULL;
174 if (geteuid() == getuid())
175 /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
176 search_path = getenv("LIBVA_DRIVERS_PATH");
178 search_path = VA_DRIVERS_PATH;
180 search_path = strdup((const char *)search_path);
181 driver_dir = strtok_r(search_path, ":", &saveptr);
184 char *driver_path = (char *) malloc( strlen(driver_dir) +
185 strlen(driver_name) +
186 strlen(DRIVER_EXTENSION) + 2 );
187 strncpy( driver_path, driver_dir, strlen(driver_dir) + 1);
188 strncat( driver_path, "/", strlen("/") );
189 strncat( driver_path, driver_name, strlen(driver_name) );
190 strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
192 va_infoMessage("Trying to open %s\n", driver_path);
194 handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
196 handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
199 /* Don't give errors for non-existing files */
200 if (0 == access( driver_path, F_OK))
201 va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
203 VADriverInit init_func = NULL;
204 char init_func_s[256];
205 if (va_getDriverInitName(init_func_s, sizeof(init_func_s),
206 VA_MAJOR_VERSION, VA_MINOR_VERSION))
207 init_func = (VADriverInit) dlsym(handle, init_func_s);
209 va_errorMessage("%s has no function %s\n",
210 driver_path, init_func_s);
213 struct VADriverVTable *vtable = ctx->vtable;
215 vaStatus = VA_STATUS_SUCCESS;
217 vtable = calloc(1, sizeof(*vtable));
219 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
221 ctx->vtable = vtable;
223 if (VA_STATUS_SUCCESS == vaStatus)
224 vaStatus = (*init_func)(ctx);
226 if (VA_STATUS_SUCCESS == vaStatus) {
227 CHECK_MAXIMUM(vaStatus, ctx, profiles);
228 CHECK_MAXIMUM(vaStatus, ctx, entrypoints);
229 CHECK_MAXIMUM(vaStatus, ctx, attributes);
230 CHECK_MAXIMUM(vaStatus, ctx, image_formats);
231 CHECK_MAXIMUM(vaStatus, ctx, subpic_formats);
232 CHECK_MAXIMUM(vaStatus, ctx, display_attributes);
233 CHECK_STRING(vaStatus, ctx, vendor);
234 CHECK_VTABLE(vaStatus, ctx, Terminate);
235 CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles);
236 CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints);
237 CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes);
238 CHECK_VTABLE(vaStatus, ctx, CreateConfig);
239 CHECK_VTABLE(vaStatus, ctx, DestroyConfig);
240 CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes);
241 CHECK_VTABLE(vaStatus, ctx, CreateSurfaces);
242 CHECK_VTABLE(vaStatus, ctx, DestroySurfaces);
243 CHECK_VTABLE(vaStatus, ctx, CreateContext);
244 CHECK_VTABLE(vaStatus, ctx, DestroyContext);
245 CHECK_VTABLE(vaStatus, ctx, CreateBuffer);
246 CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements);
247 CHECK_VTABLE(vaStatus, ctx, MapBuffer);
248 CHECK_VTABLE(vaStatus, ctx, UnmapBuffer);
249 CHECK_VTABLE(vaStatus, ctx, DestroyBuffer);
250 CHECK_VTABLE(vaStatus, ctx, BeginPicture);
251 CHECK_VTABLE(vaStatus, ctx, RenderPicture);
252 CHECK_VTABLE(vaStatus, ctx, EndPicture);
253 CHECK_VTABLE(vaStatus, ctx, SyncSurface);
254 CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus);
255 CHECK_VTABLE(vaStatus, ctx, PutSurface);
256 CHECK_VTABLE(vaStatus, ctx, QueryImageFormats);
257 CHECK_VTABLE(vaStatus, ctx, CreateImage);
258 CHECK_VTABLE(vaStatus, ctx, DeriveImage);
259 CHECK_VTABLE(vaStatus, ctx, DestroyImage);
260 CHECK_VTABLE(vaStatus, ctx, SetImagePalette);
261 CHECK_VTABLE(vaStatus, ctx, GetImage);
262 CHECK_VTABLE(vaStatus, ctx, PutImage);
263 CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats);
264 CHECK_VTABLE(vaStatus, ctx, CreateSubpicture);
265 CHECK_VTABLE(vaStatus, ctx, DestroySubpicture);
266 CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage);
267 CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey);
268 CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha);
269 CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture);
270 CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture);
271 CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes);
272 CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes);
273 CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes);
275 if (VA_STATUS_SUCCESS != vaStatus) {
276 va_errorMessage("%s init failed\n", driver_path);
279 if (VA_STATUS_SUCCESS == vaStatus)
280 ctx->handle = handle;
287 driver_dir = strtok_r(NULL, ":", &saveptr);
295 VAPrivFunc vaGetLibFunc(VADisplay dpy, const char *func)
297 VADriverContextP ctx;
298 if (!vaDisplayIsValid(dpy))
302 if (NULL == ctx->handle)
305 return (VAPrivFunc) dlsym(ctx->handle, func);
310 * Returns a short english description of error_status
312 const char *vaErrorStr(VAStatus error_status)
314 switch(error_status) {
315 case VA_STATUS_SUCCESS:
316 return "success (no error)";
317 case VA_STATUS_ERROR_OPERATION_FAILED:
318 return "operation failed";
319 case VA_STATUS_ERROR_ALLOCATION_FAILED:
320 return "resource allocation failed";
321 case VA_STATUS_ERROR_INVALID_DISPLAY:
322 return "invalid VADisplay";
323 case VA_STATUS_ERROR_INVALID_CONFIG:
324 return "invalid VAConfigID";
325 case VA_STATUS_ERROR_INVALID_CONTEXT:
326 return "invalid VAContextID";
327 case VA_STATUS_ERROR_INVALID_SURFACE:
328 return "invalid VASurfaceID";
329 case VA_STATUS_ERROR_INVALID_BUFFER:
330 return "invalid VABufferID";
331 case VA_STATUS_ERROR_INVALID_IMAGE:
332 return "invalid VAImageID";
333 case VA_STATUS_ERROR_INVALID_SUBPICTURE:
334 return "invalid VASubpictureID";
335 case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
336 return "attribute not supported";
337 case VA_STATUS_ERROR_MAX_NUM_EXCEEDED:
338 return "list argument exceeds maximum number";
339 case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
340 return "the requested VAProfile is not supported";
341 case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
342 return "the requested VAEntryPoint is not supported";
343 case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
344 return "the requested RT Format is not supported";
345 case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
346 return "the requested VABufferType is not supported";
347 case VA_STATUS_ERROR_SURFACE_BUSY:
348 return "surface is in use";
349 case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
350 return "flag not supported";
351 case VA_STATUS_ERROR_INVALID_PARAMETER:
352 return "invalid parameter";
353 case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
354 return "resolution not supported";
355 case VA_STATUS_ERROR_UNIMPLEMENTED:
356 return "the requested function is not implemented";
357 case VA_STATUS_ERROR_SURFACE_IN_DISPLAYING:
358 return "surface is in displaying (may by overlay)" ;
359 case VA_STATUS_ERROR_INVALID_IMAGE_FORMAT:
360 return "invalid VAImageFormat";
361 case VA_STATUS_ERROR_UNKNOWN:
362 return "unknown libva error";
364 return "unknown libva error / description missing";
367 VAStatus vaInitialize (
369 int *major_version, /* out */
370 int *minor_version /* out */
373 const char *driver_name_env = NULL;
374 char *driver_name = NULL;
383 va_infoMessage("libva version %s\n", VA_VERSION_S);
385 driver_name_env = getenv("LIBVA_DRIVER_NAME");
386 if (driver_name_env && geteuid() == getuid()) {
387 /* Don't allow setuid apps to use LIBVA_DRIVER_NAME */
388 driver_name = strdup(driver_name_env);
389 vaStatus = VA_STATUS_SUCCESS;
390 va_infoMessage("User requested driver '%s'\n", driver_name);
392 vaStatus = va_getDriverName(dpy, &driver_name);
393 va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
396 if (VA_STATUS_SUCCESS == vaStatus) {
397 vaStatus = va_openDriver(dpy, driver_name);
398 va_infoMessage("va_openDriver() returns %d\n", vaStatus);
400 *major_version = VA_MAJOR_VERSION;
401 *minor_version = VA_MINOR_VERSION;
407 VA_TRACE_LOG(va_TraceInitialize, dpy, major_version, minor_version);
414 * After this call, all library internal resources will be cleaned up
416 VAStatus vaTerminate (
420 VAStatus vaStatus = VA_STATUS_SUCCESS;
421 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
422 VADriverContextP old_ctx;
427 if (old_ctx->handle) {
428 vaStatus = old_ctx->vtable->vaTerminate(old_ctx);
429 dlclose(old_ctx->handle);
430 old_ctx->handle = NULL;
432 free(old_ctx->vtable);
433 old_ctx->vtable = NULL;
435 if (VA_STATUS_SUCCESS == vaStatus)
436 pDisplayContext->vaDestroy(pDisplayContext);
438 VA_TRACE_LOG(va_TraceTerminate, dpy);
448 * vaQueryVendorString returns a pointer to a zero-terminated string
449 * describing some aspects of the VA implemenation on a specific
450 * hardware accelerator. The format of the returned string is:
451 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
452 * e.g. for the Intel GMA500 implementation, an example would be:
453 * "IntelGMA500-1.0-0.2-patch3
455 const char *vaQueryVendorString (
459 if (!vaDisplayIsValid(dpy))
462 return CTX(dpy)->str_vendor;
466 /* Get maximum number of profiles supported by the implementation */
467 int vaMaxNumProfiles (
471 if (!vaDisplayIsValid(dpy))
474 return CTX(dpy)->max_profiles;
477 /* Get maximum number of entrypoints supported by the implementation */
478 int vaMaxNumEntrypoints (
482 if (!vaDisplayIsValid(dpy))
485 return CTX(dpy)->max_entrypoints;
489 /* Get maximum number of attributs supported by the implementation */
490 int vaMaxNumConfigAttributes (
494 if (!vaDisplayIsValid(dpy))
497 return CTX(dpy)->max_attributes;
500 VAStatus vaQueryConfigEntrypoints (
503 VAEntrypoint *entrypoints, /* out */
504 int *num_entrypoints /* out */
507 VADriverContextP ctx;
511 return ctx->vtable->vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
514 VAStatus vaGetConfigAttributes (
517 VAEntrypoint entrypoint,
518 VAConfigAttrib *attrib_list, /* in/out */
522 VADriverContextP ctx;
526 return ctx->vtable->vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
529 VAStatus vaQueryConfigProfiles (
531 VAProfile *profile_list, /* out */
532 int *num_profiles /* out */
535 VADriverContextP ctx;
539 return ctx->vtable->vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
542 VAStatus vaCreateConfig (
545 VAEntrypoint entrypoint,
546 VAConfigAttrib *attrib_list,
548 VAConfigID *config_id /* out */
551 VADriverContextP ctx;
552 VAStatus vaStatus = VA_STATUS_SUCCESS;
558 vaStatus = ctx->vtable->vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
560 /* record the current entrypoint for further trace/fool determination */
561 VA_TRACE_FUNC(va_TraceCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
562 VA_FOOL_FUNC(va_FoolCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
567 VAStatus vaDestroyConfig (
572 VADriverContextP ctx;
576 return ctx->vtable->vaDestroyConfig ( ctx, config_id );
579 VAStatus vaQueryConfigAttributes (
581 VAConfigID config_id,
582 VAProfile *profile, /* out */
583 VAEntrypoint *entrypoint, /* out */
584 VAConfigAttrib *attrib_list,/* out */
585 int *num_attribs /* out */
588 VADriverContextP ctx;
592 return ctx->vtable->vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
595 VAStatus vaCreateSurfaces (
601 VASurfaceID *surfaces /* out */
604 VADriverContextP ctx;
611 vaStatus = ctx->vtable->vaCreateSurfaces( ctx, width, height, format, num_surfaces, surfaces );
613 VA_TRACE_LOG(va_TraceCreateSurface, dpy, width, height, format, num_surfaces, surfaces);
619 VAStatus vaDestroySurfaces (
621 VASurfaceID *surface_list,
625 VADriverContextP ctx;
629 return ctx->vtable->vaDestroySurfaces( ctx, surface_list, num_surfaces );
632 VAStatus vaCreateContext (
634 VAConfigID config_id,
638 VASurfaceID *render_targets,
639 int num_render_targets,
640 VAContextID *context /* out */
643 VADriverContextP ctx;
649 vaStatus = ctx->vtable->vaCreateContext( ctx, config_id, picture_width, picture_height,
650 flag, render_targets, num_render_targets, context );
652 /* keep current encode/decode resoluton */
653 VA_TRACE_FUNC(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
658 VAStatus vaDestroyContext (
663 VADriverContextP ctx;
667 return ctx->vtable->vaDestroyContext( ctx, context );
670 VAStatus vaCreateBuffer (
672 VAContextID context, /* in */
673 VABufferType type, /* in */
674 unsigned int size, /* in */
675 unsigned int num_elements, /* in */
677 VABufferID *buf_id /* out */
680 VADriverContextP ctx;
685 VA_FOOL_FUNC(va_FoolCreateBuffer, dpy, context, type, size, num_elements, data, buf_id);
687 return VA_STATUS_SUCCESS;
689 return ctx->vtable->vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
692 VAStatus vaBufferSetNumElements (
694 VABufferID buf_id, /* in */
695 unsigned int num_elements /* in */
698 VADriverContextP ctx;
704 return ctx->vtable->vaBufferSetNumElements( ctx, buf_id, num_elements );
708 VAStatus vaMapBuffer (
710 VABufferID buf_id, /* in */
711 void **pbuf /* out */
714 VADriverContextP ctx;
721 VA_FOOL_FUNC(va_FoolMapBuffer, dpy, buf_id, pbuf);
723 return VA_STATUS_SUCCESS;
725 va_status = ctx->vtable->vaMapBuffer( ctx, buf_id, pbuf );
727 VA_TRACE_LOG(va_TraceMapBuffer, dpy, buf_id, pbuf);
732 VAStatus vaUnmapBuffer (
734 VABufferID buf_id /* in */
737 VADriverContextP ctx;
742 VA_FOOL_FUNC(va_FoolUnmapBuffer, dpy, buf_id);
744 return VA_STATUS_SUCCESS;
746 return ctx->vtable->vaUnmapBuffer( ctx, buf_id );
749 VAStatus vaDestroyBuffer (
754 VADriverContextP ctx;
760 return ctx->vtable->vaDestroyBuffer( ctx, buffer_id );
763 VAStatus vaBufferInfo (
765 VAContextID context, /* in */
766 VABufferID buf_id, /* in */
767 VABufferType *type, /* out */
768 unsigned int *size, /* out */
769 unsigned int *num_elements /* out */
772 VADriverContextP ctx;
778 VA_FOOL_FUNC(va_FoolBufferInfo, dpy, buf_id, type, size, num_elements);
780 return VA_STATUS_SUCCESS;
782 return ctx->vtable->vaBufferInfo( ctx, buf_id, type, size, num_elements );
785 VAStatus vaBeginPicture (
788 VASurfaceID render_target
791 VADriverContextP ctx;
798 VA_TRACE_FUNC(va_TraceBeginPicture, dpy, context, render_target);
801 va_status = ctx->vtable->vaBeginPicture( ctx, context, render_target );
806 VAStatus vaRenderPicture (
813 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;
837 /* dump encode source surface */
838 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 0);
839 /* return directly if do dummy operation */
842 va_status = ctx->vtable->vaEndPicture( ctx, context );
843 /* dump decode dest surface */
844 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 1);
849 VAStatus vaSyncSurface (
851 VASurfaceID render_target
855 VADriverContextP ctx;
861 va_status = ctx->vtable->vaSyncSurface( ctx, render_target );
862 VA_TRACE_LOG(va_TraceSyncSurface, dpy, render_target);
867 VAStatus vaQuerySurfaceStatus (
869 VASurfaceID render_target,
870 VASurfaceStatus *status /* out */
874 VADriverContextP ctx;
878 va_status = ctx->vtable->vaQuerySurfaceStatus( ctx, render_target, status );
880 VA_TRACE_LOG(va_TraceQuerySurfaceStatus, dpy, render_target, status);
885 VAStatus vaQuerySurfaceError (
888 VAStatus error_status,
889 void **error_info /*out*/
893 VADriverContextP ctx;
897 va_status = ctx->vtable->vaQuerySurfaceError( ctx, surface, error_status, error_info );
899 VA_TRACE_LOG(va_TraceQuerySurfaceError, dpy, surface, error_status, error_info);
904 /* Get maximum number of image formats supported by the implementation */
905 int vaMaxNumImageFormats (
909 if (!vaDisplayIsValid(dpy))
912 return CTX(dpy)->max_image_formats;
915 VAStatus vaQueryImageFormats (
917 VAImageFormat *format_list, /* out */
918 int *num_formats /* out */
921 VADriverContextP ctx;
925 return ctx->vtable->vaQueryImageFormats ( ctx, format_list, num_formats);
929 * The width and height fields returned in the VAImage structure may get
930 * enlarged for some YUV formats. The size of the data buffer that needs
931 * to be allocated will be given in the "data_size" field in VAImage.
932 * Image data is not allocated by this function. The client should
933 * allocate the memory and fill in the VAImage structure's data field
934 * after looking at "data_size" returned from the library.
936 VAStatus vaCreateImage (
938 VAImageFormat *format,
941 VAImage *image /* out */
944 VADriverContextP ctx;
948 return ctx->vtable->vaCreateImage ( ctx, format, width, height, image);
952 * Should call DestroyImage before destroying the surface it is bound to
954 VAStatus vaDestroyImage (
959 VADriverContextP ctx;
963 return ctx->vtable->vaDestroyImage ( ctx, image);
966 VAStatus vaSetImagePalette (
969 unsigned char *palette
972 VADriverContextP ctx;
976 return ctx->vtable->vaSetImagePalette ( ctx, image, palette);
980 * Retrieve surface data into a VAImage
981 * Image must be in a format supported by the implementation
983 VAStatus vaGetImage (
986 int x, /* coordinates of the upper left source pixel */
988 unsigned int width, /* width and height of the region */
993 VADriverContextP ctx;
997 return ctx->vtable->vaGetImage ( ctx, surface, x, y, width, height, image);
1001 * Copy data from a VAImage to a surface
1002 * Image must be in a format supported by the implementation
1004 VAStatus vaPutImage (
1006 VASurfaceID surface,
1010 unsigned int src_width,
1011 unsigned int src_height,
1014 unsigned int dest_width,
1015 unsigned int dest_height
1018 VADriverContextP ctx;
1022 return ctx->vtable->vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
1026 * Derive an VAImage from an existing surface.
1027 * This interface will derive a VAImage and corresponding image buffer from
1028 * an existing VA Surface. The image buffer can then be mapped/unmapped for
1029 * direct CPU access. This operation is only possible on implementations with
1030 * direct rendering capabilities and internal surface formats that can be
1031 * represented with a VAImage. When the operation is not possible this interface
1032 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
1033 * to using vaCreateImage + vaPutImage to accomplish the same task in an
1036 * Implementations should only return success when the resulting image buffer
1037 * would be useable with vaMap/Unmap.
1039 * When directly accessing a surface special care must be taken to insure
1040 * proper synchronization with the graphics hardware. Clients should call
1041 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
1042 * rendering or currently being displayed by an overlay.
1044 * Additionally nothing about the contents of a surface should be assumed
1045 * following a vaPutSurface. Implementations are free to modify the surface for
1046 * scaling or subpicture blending within a call to vaPutImage.
1048 * Calls to vaPutImage or vaGetImage using the same surface from which the image
1049 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
1050 * vaGetImage with other surfaces is supported.
1052 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
1053 * image and image buffer structures will be destroyed; however, the underlying
1054 * surface will remain unchanged until freed with vaDestroySurfaces.
1056 VAStatus vaDeriveImage (
1058 VASurfaceID surface,
1059 VAImage *image /* out */
1062 VADriverContextP ctx;
1066 return ctx->vtable->vaDeriveImage ( ctx, surface, image );
1070 /* Get maximum number of subpicture formats supported by the implementation */
1071 int vaMaxNumSubpictureFormats (
1075 if (!vaDisplayIsValid(dpy))
1078 return CTX(dpy)->max_subpic_formats;
1082 * Query supported subpicture formats
1083 * The caller must provide a "format_list" array that can hold at
1084 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1085 * for each format to indicate additional capabilities for that format. The actual
1086 * number of formats returned in "format_list" is returned in "num_formats".
1088 VAStatus vaQuerySubpictureFormats (
1090 VAImageFormat *format_list, /* out */
1091 unsigned int *flags, /* out */
1092 unsigned int *num_formats /* out */
1095 VADriverContextP ctx;
1101 return ctx->vtable->vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
1105 * Subpictures are created with an image associated.
1107 VAStatus vaCreateSubpicture (
1110 VASubpictureID *subpicture /* out */
1113 VADriverContextP ctx;
1117 return ctx->vtable->vaCreateSubpicture ( ctx, image, subpicture );
1121 * Destroy the subpicture before destroying the image it is assocated to
1123 VAStatus vaDestroySubpicture (
1125 VASubpictureID subpicture
1128 VADriverContextP ctx;
1132 return ctx->vtable->vaDestroySubpicture ( ctx, subpicture);
1135 VAStatus vaSetSubpictureImage (
1137 VASubpictureID subpicture,
1141 VADriverContextP ctx;
1145 return ctx->vtable->vaSetSubpictureImage ( ctx, subpicture, image);
1150 * If chromakey is enabled, then the area where the source value falls within
1151 * the chromakey [min, max] range is transparent
1153 VAStatus vaSetSubpictureChromakey (
1155 VASubpictureID subpicture,
1156 unsigned int chromakey_min,
1157 unsigned int chromakey_max,
1158 unsigned int chromakey_mask
1161 VADriverContextP ctx;
1165 return ctx->vtable->vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
1170 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1171 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1172 * the overall alpha is per-pixel alpha multiplied by the global alpha
1174 VAStatus vaSetSubpictureGlobalAlpha (
1176 VASubpictureID subpicture,
1180 VADriverContextP ctx;
1184 return ctx->vtable->vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
1188 vaAssociateSubpicture associates the subpicture with the target_surface.
1189 It defines the region mapping between the subpicture and the target
1190 surface through source and destination rectangles (with the same width and height).
1191 Both will be displayed at the next call to vaPutSurface. Additional
1192 associations before the call to vaPutSurface simply overrides the association.
1194 VAStatus vaAssociateSubpicture (
1196 VASubpictureID subpicture,
1197 VASurfaceID *target_surfaces,
1199 short src_x, /* upper left offset in subpicture */
1201 unsigned short src_width,
1202 unsigned short src_height,
1203 short dest_x, /* upper left offset in surface */
1205 unsigned short dest_width,
1206 unsigned short dest_height,
1208 * whether to enable chroma-keying or global-alpha
1209 * see VA_SUBPICTURE_XXX values
1214 VADriverContextP ctx;
1218 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 );
1222 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1224 VAStatus vaDeassociateSubpicture (
1226 VASubpictureID subpicture,
1227 VASurfaceID *target_surfaces,
1231 VADriverContextP ctx;
1235 return ctx->vtable->vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
1239 /* Get maximum number of display attributes supported by the implementation */
1240 int vaMaxNumDisplayAttributes (
1246 if (!vaDisplayIsValid(dpy))
1249 tmp = CTX(dpy)->max_display_attributes;
1251 VA_TRACE_LOG(va_TraceMaxNumDisplayAttributes, dpy, tmp);
1257 * Query display attributes
1258 * The caller must provide a "attr_list" array that can hold at
1259 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1260 * returned in "attr_list" is returned in "num_attributes".
1262 VAStatus vaQueryDisplayAttributes (
1264 VADisplayAttribute *attr_list, /* out */
1265 int *num_attributes /* out */
1268 VADriverContextP ctx;
1273 va_status = ctx->vtable->vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
1275 VA_TRACE_LOG(va_TraceQueryDisplayAttributes, dpy, attr_list, num_attributes);
1282 * Get display attributes
1283 * This function returns the current attribute values in "attr_list".
1284 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1285 * from vaQueryDisplayAttributes() can have their values retrieved.
1287 VAStatus vaGetDisplayAttributes (
1289 VADisplayAttribute *attr_list, /* in/out */
1293 VADriverContextP ctx;
1298 va_status = ctx->vtable->vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
1300 VA_TRACE_LOG(va_TraceGetDisplayAttributes, dpy, attr_list, num_attributes);
1306 * Set display attributes
1307 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1308 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1309 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1311 VAStatus vaSetDisplayAttributes (
1313 VADisplayAttribute *attr_list,
1317 VADriverContextP ctx;
1322 va_status = ctx->vtable->vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
1323 VA_TRACE_LOG(va_TraceSetDisplayAttributes, dpy, attr_list, num_attributes);
1328 VAStatus vaLockSurface(VADisplay dpy,
1329 VASurfaceID surface,
1330 unsigned int *fourcc, /* following are output argument */
1331 unsigned int *luma_stride,
1332 unsigned int *chroma_u_stride,
1333 unsigned int *chroma_v_stride,
1334 unsigned int *luma_offset,
1335 unsigned int *chroma_u_offset,
1336 unsigned int *chroma_v_offset,
1337 unsigned int *buffer_name,
1341 VADriverContextP ctx;
1345 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);
1349 VAStatus vaUnlockSurface(VADisplay dpy,
1353 VADriverContextP ctx;
1357 return ctx->vtable->vaUnlockSurface( ctx, surface );