2 * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "va_backend.h"
37 #define VA_MAJOR_VERSION 0
38 #define VA_MINOR_VERSION 29
39 #define DRIVER_INIT_FUNC "__vaDriverInit_0_30"
41 #define DEFAULT_DRIVER_DIR "/usr/X11R6/lib/modules/dri"
42 #define DRIVER_EXTENSION "_drv_video.so"
44 #define CTX(dpy) ((VADriverContextP) dpy );
45 #define CHECK_CONTEXT(dpy) if( !vaContextIsValid(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 #define TRACE(func) if (va_debug_trace) va_infoMessage("[TR] %s\n", #func);
53 static VADriverContextP pDriverContexts = NULL;
54 static int va_debug_trace = 0;
56 static Bool vaContextIsValid(VADriverContextP arg_ctx)
58 VADriverContextP ctx = pDriverContexts;
71 VADisplay vaGetDisplay (
72 NativeDisplay native_dpy /* implementation specific */
76 VADriverContextP ctx = pDriverContexts;
85 if (ctx->x11_dpy == (Display *)native_dpy)
87 dpy = (VADisplay) ctx;
95 /* create new entry */
96 ctx = (VADriverContextP) calloc(1, sizeof(struct VADriverContext));
97 ctx->pNext = pDriverContexts;
98 ctx->x11_dpy = (Display *) native_dpy;
99 pDriverContexts = ctx;
100 dpy = (VADisplay) ctx;
106 static void va_errorMessage(const char *msg, ...)
110 fprintf(stderr, "libva error: ");
112 vfprintf(stderr, msg, args);
116 static void va_infoMessage(const char *msg, ...)
120 fprintf(stderr, "libva: ");
122 vfprintf(stderr, msg, args);
126 static Bool va_checkVtable(void *ptr, char *function)
130 va_errorMessage("No valid vtable entry for va%s\n", function);
136 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)
150 va_errorMessage("Failed to define str_%s in init\n", variable);
156 static VAStatus va_getDriverName(VADriverContextP ctx, char **driver_name)
158 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
166 if (geteuid() == getuid())
168 /* don't allow setuid apps to use LIBVA_DRIVER_NAME */
169 if (getenv("LIBVA_DRIVER_NAME"))
171 /* For easier debugging */
172 *driver_name = strdup(getenv("LIBVA_DRIVER_NAME"));
173 return VA_STATUS_SUCCESS;
178 result = VA_DRIQueryDirectRenderingCapable(ctx->x11_dpy, ctx->x11_screen, &direct_capable);
181 va_errorMessage("VA_DRIQueryDirectRenderingCapable failed\n");
186 result = direct_capable;
189 va_errorMessage("VA_DRIQueryDirectRenderingCapable returned false\n");
194 result = VA_DRIGetClientDriverName(ctx->x11_dpy, ctx->x11_screen, &driver_major, &driver_minor,
195 &driver_patch, driver_name);
198 va_errorMessage("VA_DRIGetClientDriverName returned false\n");
203 vaStatus = VA_STATUS_SUCCESS;
204 va_infoMessage("VA_DRIGetClientDriverName: %d.%d.%d %s (screen %d)\n",
205 driver_major, driver_minor, driver_patch, *driver_name, ctx->x11_screen);
211 static VAStatus va_openDriver(VADriverContextP ctx, char *driver_name)
213 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
214 char *search_path = NULL;
218 if (geteuid() == getuid())
220 /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
221 search_path = getenv("LIBVA_DRIVERS_PATH");
224 search_path = getenv("LIBGL_DRIVERS_PATH");
229 search_path = DEFAULT_DRIVER_DIR;
232 search_path = strdup(search_path);
233 driver_dir = strtok_r(search_path, ":", &saveptr);
237 char *driver_path = (char *) malloc( strlen(driver_dir) +
238 strlen(driver_name) +
239 strlen(DRIVER_EXTENSION) + 2 );
240 strcpy( driver_path, driver_dir );
241 strcat( driver_path, "/" );
242 strcat( driver_path, driver_name );
243 strcat( driver_path, DRIVER_EXTENSION );
245 va_infoMessage("Trying to open %s\n", driver_path);
247 handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL );
250 /* Don't give errors for non-existing files */
251 if (0 == access( driver_path, F_OK))
253 va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
258 VADriverInit init_func;
259 init_func = (VADriverInit) dlsym(handle, DRIVER_INIT_FUNC);
262 va_errorMessage("%s has no function %s\n", driver_path, DRIVER_INIT_FUNC);
267 vaStatus = (*init_func)(ctx);
269 if (VA_STATUS_SUCCESS == vaStatus)
271 CHECK_MAXIMUM(vaStatus, ctx, profiles);
272 CHECK_MAXIMUM(vaStatus, ctx, entrypoints);
273 CHECK_MAXIMUM(vaStatus, ctx, attributes);
274 CHECK_MAXIMUM(vaStatus, ctx, image_formats);
275 CHECK_MAXIMUM(vaStatus, ctx, subpic_formats);
276 CHECK_MAXIMUM(vaStatus, ctx, display_attributes);
277 CHECK_STRING(vaStatus, ctx, vendor);
278 CHECK_VTABLE(vaStatus, ctx, Terminate);
279 CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles);
280 CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints);
281 CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes);
282 CHECK_VTABLE(vaStatus, ctx, CreateConfig);
283 CHECK_VTABLE(vaStatus, ctx, DestroyConfig);
284 CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes);
285 CHECK_VTABLE(vaStatus, ctx, CreateSurfaces);
286 CHECK_VTABLE(vaStatus, ctx, DestroySurfaces);
287 CHECK_VTABLE(vaStatus, ctx, CreateContext);
288 CHECK_VTABLE(vaStatus, ctx, DestroyContext);
289 CHECK_VTABLE(vaStatus, ctx, CreateBuffer);
290 CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements);
291 CHECK_VTABLE(vaStatus, ctx, MapBuffer);
292 CHECK_VTABLE(vaStatus, ctx, UnmapBuffer);
293 CHECK_VTABLE(vaStatus, ctx, DestroyBuffer);
294 CHECK_VTABLE(vaStatus, ctx, BeginPicture);
295 CHECK_VTABLE(vaStatus, ctx, RenderPicture);
296 CHECK_VTABLE(vaStatus, ctx, EndPicture);
297 CHECK_VTABLE(vaStatus, ctx, SyncSurface);
298 CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus);
299 CHECK_VTABLE(vaStatus, ctx, PutSurface);
300 CHECK_VTABLE(vaStatus, ctx, QueryImageFormats);
301 CHECK_VTABLE(vaStatus, ctx, CreateImage);
302 CHECK_VTABLE(vaStatus, ctx, DeriveImage);
303 CHECK_VTABLE(vaStatus, ctx, DestroyImage);
304 CHECK_VTABLE(vaStatus, ctx, SetImagePalette);
305 CHECK_VTABLE(vaStatus, ctx, GetImage);
306 CHECK_VTABLE(vaStatus, ctx, PutImage);
307 CHECK_VTABLE(vaStatus, ctx, PutImage2);
308 CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats);
309 CHECK_VTABLE(vaStatus, ctx, CreateSubpicture);
310 CHECK_VTABLE(vaStatus, ctx, DestroySubpicture);
311 CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage);
312 CHECK_VTABLE(vaStatus, ctx, SetSubpicturePalette);
313 CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey);
314 CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha);
315 CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture);
316 CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture2);
317 CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture);
318 CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes);
319 CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes);
320 CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes);
321 CHECK_VTABLE(vaStatus, ctx, DbgCopySurfaceToBuffer);
323 if (VA_STATUS_SUCCESS != vaStatus)
325 va_errorMessage("%s init failed\n", driver_path);
328 if (VA_STATUS_SUCCESS == vaStatus)
330 ctx->handle = handle;
338 driver_dir = strtok_r(NULL, ":", &saveptr);
346 VAPrivFunc vaGetLibFunc(VADisplay dpy, const char *func)
348 VADriverContextP ctx = CTX(dpy);
349 if( !vaContextIsValid(ctx) )
352 if (NULL == ctx->handle)
355 return (VAPrivFunc) dlsym(ctx->handle, func);
360 * Returns a short english description of error_status
362 const char *vaErrorStr(VAStatus error_status)
366 case VA_STATUS_SUCCESS:
367 return "success (no error)";
368 case VA_STATUS_ERROR_OPERATION_FAILED:
369 return "operation failed";
370 case VA_STATUS_ERROR_ALLOCATION_FAILED:
371 return "resource allocation failed";
372 case VA_STATUS_ERROR_INVALID_DISPLAY:
373 return "invalid VADisplay";
374 case VA_STATUS_ERROR_INVALID_CONFIG:
375 return "invalid VAConfigID";
376 case VA_STATUS_ERROR_INVALID_CONTEXT:
377 return "invalid VAContextID";
378 case VA_STATUS_ERROR_INVALID_SURFACE:
379 return "invalid VASurfaceID";
380 case VA_STATUS_ERROR_INVALID_BUFFER:
381 return "invalid VABufferID";
382 case VA_STATUS_ERROR_INVALID_IMAGE:
383 return "invalid VAImageID";
384 case VA_STATUS_ERROR_INVALID_SUBPICTURE:
385 return "invalid VASubpictureID";
386 case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
387 return "attribute not supported";
388 case VA_STATUS_ERROR_MAX_NUM_EXCEEDED:
389 return "list argument exceeds maximum number";
390 case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
391 return "the requested VAProfile is not supported";
392 case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
393 return "the requested VAEntryPoint is not supported";
394 case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
395 return "the requested RT Format is not supported";
396 case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
397 return "the requested VABufferType is not supported";
398 case VA_STATUS_ERROR_SURFACE_BUSY:
399 return "surface is in use";
400 case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
401 return "flag not supported";
402 case VA_STATUS_ERROR_INVALID_PARAMETER:
403 return "invalid parameter";
404 case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
405 return "resolution not supported";
406 case VA_STATUS_ERROR_UNKNOWN:
407 return "unknown libva error";
409 return "unknown libva error / description missing";
412 VAStatus vaInitialize (
414 int *major_version, /* out */
415 int *minor_version /* out */
418 VADriverContextP ctx = CTX(dpy);
419 char *driver_name = NULL;
424 va_debug_trace = (getenv("LIBVA_DEBUG_TRACE") != NULL);
426 vaStatus = va_getDriverName(ctx, &driver_name);
427 va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
429 if (VA_STATUS_SUCCESS == vaStatus)
431 vaStatus = va_openDriver(ctx, driver_name);
432 va_infoMessage("va_openDriver() returns %d\n", vaStatus);
434 *major_version = VA_MAJOR_VERSION;
435 *minor_version = VA_MINOR_VERSION;
447 * After this call, all library internal resources will be cleaned up
449 VAStatus vaTerminate (
453 VAStatus vaStatus = VA_STATUS_SUCCESS;
454 VADriverContextP old_ctx = CTX(dpy);
455 CHECK_CONTEXT(old_ctx);
459 vaStatus = old_ctx->vtable.vaTerminate(old_ctx);
460 dlclose(old_ctx->handle);
461 old_ctx->handle = NULL;
464 if (VA_STATUS_SUCCESS == vaStatus)
466 VADriverContextP *ctx = &pDriverContexts;
468 /* Throw away old_ctx */
473 *ctx = old_ctx->pNext;
474 old_ctx->pNext = NULL;
477 ctx = &((*ctx)->pNext);
485 * vaQueryVendorString returns a pointer to a zero-terminated string
486 * describing some aspects of the VA implemenation on a specific
487 * hardware accelerator. The format of the returned string is:
488 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
489 * e.g. for the Intel GMA500 implementation, an example would be:
490 * "IntelGMA500-1.0-0.2-patch3
492 const char *vaQueryVendorString (
496 VADriverContextP ctx = CTX(dpy);
497 if( !vaContextIsValid(ctx) )
502 return ctx->str_vendor;
506 /* Get maximum number of profiles supported by the implementation */
507 int vaMaxNumProfiles (
511 VADriverContextP ctx = CTX(dpy);
512 if( !vaContextIsValid(ctx) )
517 return ctx->max_profiles;
520 /* Get maximum number of entrypoints supported by the implementation */
521 int vaMaxNumEntrypoints (
525 VADriverContextP ctx = CTX(dpy);
526 if( !vaContextIsValid(ctx) )
531 return ctx->max_entrypoints;
535 /* Get maximum number of attributs supported by the implementation */
536 int vaMaxNumConfigAttributes (
540 VADriverContextP ctx = CTX(dpy);
541 if( !vaContextIsValid(ctx) )
546 return ctx->max_attributes;
549 VAStatus vaQueryConfigEntrypoints (
552 VAEntrypoint *entrypoints, /* out */
553 int *num_entrypoints /* out */
556 VADriverContextP ctx = CTX(dpy);
559 TRACE(vaQueryConfigEntrypoints);
560 return ctx->vtable.vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
563 VAStatus vaGetConfigAttributes (
566 VAEntrypoint entrypoint,
567 VAConfigAttrib *attrib_list, /* in/out */
571 VADriverContextP ctx = CTX(dpy);
574 TRACE(vaGetConfigAttributes);
575 return ctx->vtable.vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
578 VAStatus vaQueryConfigProfiles (
580 VAProfile *profile_list, /* out */
581 int *num_profiles /* out */
584 VADriverContextP ctx = CTX(dpy);
587 TRACE(vaQueryConfigProfiles);
588 return ctx->vtable.vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
591 VAStatus vaCreateConfig (
594 VAEntrypoint entrypoint,
595 VAConfigAttrib *attrib_list,
597 VAConfigID *config_id /* out */
600 VADriverContextP ctx = CTX(dpy);
603 TRACE(vaCreateConfig);
604 return ctx->vtable.vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
607 VAStatus vaDestroyConfig (
612 VADriverContextP ctx = CTX(dpy);
615 TRACE(vaDestroyConfig);
616 return ctx->vtable.vaDestroyConfig ( ctx, config_id );
619 VAStatus vaQueryConfigAttributes (
621 VAConfigID config_id,
622 VAProfile *profile, /* out */
623 VAEntrypoint *entrypoint, /* out */
624 VAConfigAttrib *attrib_list,/* out */
625 int *num_attribs /* out */
628 VADriverContextP ctx = CTX(dpy);
631 TRACE(vaQueryConfigAttributes);
632 return ctx->vtable.vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
635 VAStatus vaCreateSurfaces (
641 VASurfaceID *surfaces /* out */
644 VADriverContextP ctx = CTX(dpy);
647 TRACE(vaCreateSurfaces);
648 return ctx->vtable.vaCreateSurfaces( ctx, width, height, format, num_surfaces, surfaces );
651 VAStatus vaDestroySurfaces (
653 VASurfaceID *surface_list,
657 VADriverContextP ctx = CTX(dpy);
660 TRACE(vaDestroySurfaces);
661 return ctx->vtable.vaDestroySurfaces( ctx, surface_list, num_surfaces );
664 VAStatus vaCreateContext (
666 VAConfigID config_id,
670 VASurfaceID *render_targets,
671 int num_render_targets,
672 VAContextID *context /* out */
675 VADriverContextP ctx = CTX(dpy);
678 TRACE(vaCreateContext);
679 return ctx->vtable.vaCreateContext( ctx, config_id, picture_width, picture_height,
680 flag, render_targets, num_render_targets, context );
683 VAStatus vaDestroyContext (
688 VADriverContextP ctx = CTX(dpy);
691 TRACE(vaDestroyContext);
692 return ctx->vtable.vaDestroyContext( ctx, context );
695 VAStatus vaCreateBuffer (
697 VAContextID context, /* in */
698 VABufferType type, /* in */
699 unsigned int size, /* in */
700 unsigned int num_elements, /* in */
702 VABufferID *buf_id /* out */
705 VADriverContextP ctx = CTX(dpy);
708 TRACE(vaCreateBuffer);
709 return ctx->vtable.vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
712 VAStatus vaBufferSetNumElements (
714 VABufferID buf_id, /* in */
715 unsigned int num_elements /* in */
718 VADriverContextP ctx = CTX(dpy);
721 TRACE(vaBufferSetNumElements);
722 return ctx->vtable.vaBufferSetNumElements( ctx, buf_id, num_elements );
726 VAStatus vaMapBuffer (
728 VABufferID buf_id, /* in */
729 void **pbuf /* out */
732 VADriverContextP ctx = CTX(dpy);
736 return ctx->vtable.vaMapBuffer( ctx, buf_id, pbuf );
739 VAStatus vaUnmapBuffer (
741 VABufferID buf_id /* in */
744 VADriverContextP ctx = CTX(dpy);
747 TRACE(vaUnmapBuffer);
748 return ctx->vtable.vaUnmapBuffer( ctx, buf_id );
751 VAStatus vaDestroyBuffer (
756 VADriverContextP ctx = CTX(dpy);
759 TRACE(vaDestroyBuffer);
760 return ctx->vtable.vaDestroyBuffer( ctx, buffer_id );
763 VAStatus vaBeginPicture (
766 VASurfaceID render_target
769 VADriverContextP ctx = CTX(dpy);
772 TRACE(vaBeginPicture);
773 return ctx->vtable.vaBeginPicture( ctx, context, render_target );
776 VAStatus vaRenderPicture (
783 VADriverContextP ctx = CTX(dpy);
786 TRACE(vaRenderPicture);
787 return ctx->vtable.vaRenderPicture( ctx, context, buffers, num_buffers );
790 VAStatus vaEndPicture (
795 VADriverContextP ctx = CTX(dpy);
799 return ctx->vtable.vaEndPicture( ctx, context );
802 VAStatus vaSyncSurface (
805 VASurfaceID render_target
808 VADriverContextP ctx = CTX(dpy);
811 TRACE(vaSyncSurface);
812 return ctx->vtable.vaSyncSurface( ctx, context, render_target );
815 VAStatus vaQuerySurfaceStatus (
817 VASurfaceID render_target,
818 VASurfaceStatus *status /* out */
821 VADriverContextP ctx = CTX(dpy);
824 TRACE(vaQuerySurfaceStatus);
825 return ctx->vtable.vaQuerySurfaceStatus( ctx, render_target, status );
828 VAStatus vaPutSurface (
831 Drawable draw, /* X Drawable */
838 unsigned short destw,
839 unsigned short desth,
840 VARectangle *cliprects, /* client supplied clip list */
841 unsigned int number_cliprects, /* number of clip rects in the clip list */
842 unsigned int flags /* de-interlacing flags */
845 VADriverContextP ctx = CTX(dpy);
849 return ctx->vtable.vaPutSurface( ctx, surface, draw, srcx, srcy, srcw, srch,
850 destx, desty, destw, desth,
851 cliprects, number_cliprects, flags );
854 /* Get maximum number of image formats supported by the implementation */
855 int vaMaxNumImageFormats (
859 VADriverContextP ctx = CTX(dpy);
860 if( !vaContextIsValid(ctx) )
865 return ctx->max_image_formats;
868 VAStatus vaQueryImageFormats (
870 VAImageFormat *format_list, /* out */
871 int *num_formats /* out */
874 VADriverContextP ctx = CTX(dpy);
877 TRACE(vaQueryImageFormats);
878 return ctx->vtable.vaQueryImageFormats ( ctx, format_list, num_formats);
882 * The width and height fields returned in the VAImage structure may get
883 * enlarged for some YUV formats. The size of the data buffer that needs
884 * to be allocated will be given in the "data_size" field in VAImage.
885 * Image data is not allocated by this function. The client should
886 * allocate the memory and fill in the VAImage structure's data field
887 * after looking at "data_size" returned from the library.
889 VAStatus vaCreateImage (
891 VAImageFormat *format,
894 VAImage *image /* out */
897 VADriverContextP ctx = CTX(dpy);
900 TRACE(vaCreateImage);
901 return ctx->vtable.vaCreateImage ( ctx, format, width, height, image);
905 * Should call DestroyImage before destroying the surface it is bound to
907 VAStatus vaDestroyImage (
912 VADriverContextP ctx = CTX(dpy);
915 TRACE(vaDestroyImage);
916 return ctx->vtable.vaDestroyImage ( ctx, image);
919 VAStatus vaSetImagePalette (
922 unsigned char *palette
925 VADriverContextP ctx = CTX(dpy);
928 TRACE(vaSetImagePalette);
929 return ctx->vtable.vaSetImagePalette ( ctx, image, palette);
933 * Retrieve surface data into a VAImage
934 * Image must be in a format supported by the implementation
936 VAStatus vaGetImage (
939 int x, /* coordinates of the upper left source pixel */
941 unsigned int width, /* width and height of the region */
946 VADriverContextP ctx = CTX(dpy);
950 return ctx->vtable.vaGetImage ( ctx, surface, x, y, width, height, image);
954 * Copy data from a VAImage to a surface
955 * Image must be in a format supported by the implementation
957 VAStatus vaPutImage (
969 VADriverContextP ctx = CTX(dpy);
973 return ctx->vtable.vaPutImage ( ctx, surface, image, src_x, src_y, width, height, dest_x, dest_y );
977 * Similar to vaPutImage but with additional destination width
978 * and height arguments to enable scaling
980 VAStatus vaPutImage2 (
986 unsigned int src_width,
987 unsigned int src_height,
990 unsigned int dest_width,
991 unsigned int dest_height
994 VADriverContextP ctx = CTX(dpy);
998 return ctx->vtable.vaPutImage2 ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
1002 * Derive an VAImage from an existing surface.
1003 * This interface will derive a VAImage and corresponding image buffer from
1004 * an existing VA Surface. The image buffer can then be mapped/unmapped for
1005 * direct CPU access. This operation is only possible on implementations with
1006 * direct rendering capabilities and internal surface formats that can be
1007 * represented with a VAImage. When the operation is not possible this interface
1008 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
1009 * to using vaCreateImage + vaPutImage to accomplish the same task in an
1012 * Implementations should only return success when the resulting image buffer
1013 * would be useable with vaMap/Unmap.
1015 * When directly accessing a surface special care must be taken to insure
1016 * proper synchronization with the graphics hardware. Clients should call
1017 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
1018 * rendering or currently being displayed by an overlay.
1020 * Additionally nothing about the contents of a surface should be assumed
1021 * following a vaPutSurface. Implementations are free to modify the surface for
1022 * scaling or subpicture blending within a call to vaPutImage.
1024 * Calls to vaPutImage or vaGetImage using the same surface from which the image
1025 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
1026 * vaGetImage with other surfaces is supported.
1028 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
1029 * image and image buffer structures will be destroyed; however, the underlying
1030 * surface will remain unchanged until freed with vaDestroySurfaces.
1032 VAStatus vaDeriveImage (
1034 VASurfaceID surface,
1035 VAImage *image /* out */
1038 VADriverContextP ctx = CTX(dpy);
1041 TRACE(vaDeriveImage);
1042 return ctx->vtable.vaDeriveImage ( ctx, surface, image );
1046 /* Get maximum number of subpicture formats supported by the implementation */
1047 int vaMaxNumSubpictureFormats (
1051 VADriverContextP ctx = CTX(dpy);
1052 if( !vaContextIsValid(ctx) )
1057 return ctx->max_subpic_formats;
1061 * Query supported subpicture formats
1062 * The caller must provide a "format_list" array that can hold at
1063 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1064 * for each format to indicate additional capabilities for that format. The actual
1065 * number of formats returned in "format_list" is returned in "num_formats".
1067 VAStatus vaQuerySubpictureFormats (
1069 VAImageFormat *format_list, /* out */
1070 unsigned int *flags, /* out */
1071 unsigned int *num_formats /* out */
1074 VADriverContextP ctx = CTX(dpy);
1077 TRACE(vaQuerySubpictureFormats);
1078 return ctx->vtable.vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
1082 * Subpictures are created with an image associated.
1084 VAStatus vaCreateSubpicture (
1087 VASubpictureID *subpicture /* out */
1090 VADriverContextP ctx = CTX(dpy);
1093 TRACE(vaCreateSubpicture);
1094 return ctx->vtable.vaCreateSubpicture ( ctx, image, subpicture );
1098 * Destroy the subpicture before destroying the image it is assocated to
1100 VAStatus vaDestroySubpicture (
1102 VASubpictureID subpicture
1105 VADriverContextP ctx = CTX(dpy);
1108 TRACE(vaDestroySubpicture);
1109 return ctx->vtable.vaDestroySubpicture ( ctx, subpicture);
1112 VAStatus vaSetSubpictureImage (
1114 VASubpictureID subpicture,
1118 VADriverContextP ctx = CTX(dpy);
1121 TRACE(vaSetSubpictureImage);
1122 return ctx->vtable.vaSetSubpictureImage ( ctx, subpicture, image);
1125 #warning TODO: Remove vaSetSubpicturePalette in rev 0.29
1126 VAStatus vaSetSubpicturePalette (
1128 VASubpictureID subpicture,
1130 * pointer to an array holding the palette data. The size of the array is
1131 * num_palette_entries * entry_bytes in size. The order of the components
1132 * in the palette is described by the component_order in VASubpicture struct
1134 unsigned char *palette
1137 VADriverContextP ctx = CTX(dpy);
1140 TRACE(vaSetSubpicturePalette);
1141 return ctx->vtable.vaSetSubpicturePalette ( ctx, subpicture, palette);
1145 * If chromakey is enabled, then the area where the source value falls within
1146 * the chromakey [min, max] range is transparent
1148 VAStatus vaSetSubpictureChromakey (
1150 VASubpictureID subpicture,
1151 unsigned int chromakey_min,
1152 unsigned int chromakey_max,
1153 unsigned int chromakey_mask
1156 VADriverContextP ctx = CTX(dpy);
1159 TRACE(vaSetSubpictureChromakey);
1160 return ctx->vtable.vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
1165 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1166 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1167 * the overall alpha is per-pixel alpha multiplied by the global alpha
1169 VAStatus vaSetSubpictureGlobalAlpha (
1171 VASubpictureID subpicture,
1175 VADriverContextP ctx = CTX(dpy);
1178 TRACE(vaSetSubpictureGlobalAlpha);
1179 return ctx->vtable.vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
1183 vaAssociateSubpicture associates the subpicture with the target_surface.
1184 It defines the region mapping between the subpicture and the target
1185 surface through source and destination rectangles (with the same width and height).
1186 Both will be displayed at the next call to vaPutSurface. Additional
1187 associations before the call to vaPutSurface simply overrides the association.
1189 VAStatus vaAssociateSubpicture (
1191 VASubpictureID subpicture,
1192 VASurfaceID *target_surfaces,
1194 short src_x, /* upper left offset in subpicture */
1196 short dest_x, /* upper left offset in surface */
1198 unsigned short width,
1199 unsigned short height,
1201 * whether to enable chroma-keying or global-alpha
1202 * see VA_SUBPICTURE_XXX values
1207 VADriverContextP ctx = CTX(dpy);
1210 TRACE(vaAssociateSubpicture);
1211 return ctx->vtable.vaAssociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces, src_x, src_y, dest_x, dest_y, width, height, flags );
1214 VAStatus vaAssociateSubpicture2 (
1216 VASubpictureID subpicture,
1217 VASurfaceID *target_surfaces,
1219 short src_x, /* upper left offset in subpicture */
1221 unsigned short src_width,
1222 unsigned short src_height,
1223 short dest_x, /* upper left offset in surface */
1225 unsigned short dest_width,
1226 unsigned short dest_height,
1228 * whether to enable chroma-keying or global-alpha
1229 * see VA_SUBPICTURE_XXX values
1234 VADriverContextP ctx = CTX(dpy);
1237 TRACE(vaAssociateSubpicture2);
1238 return ctx->vtable.vaAssociateSubpicture2 ( ctx, subpicture, target_surfaces, num_surfaces, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height, flags );
1242 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1244 VAStatus vaDeassociateSubpicture (
1246 VASubpictureID subpicture,
1247 VASurfaceID *target_surfaces,
1251 VADriverContextP ctx = CTX(dpy);
1254 TRACE(vaDeassociateSubpicture);
1255 return ctx->vtable.vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
1259 /* Get maximum number of display attributes supported by the implementation */
1260 int vaMaxNumDisplayAttributes (
1264 VADriverContextP ctx = CTX(dpy);
1265 if( !vaContextIsValid(ctx) )
1270 return ctx->max_display_attributes;
1274 * Query display attributes
1275 * The caller must provide a "attr_list" array that can hold at
1276 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1277 * returned in "attr_list" is returned in "num_attributes".
1279 VAStatus vaQueryDisplayAttributes (
1281 VADisplayAttribute *attr_list, /* out */
1282 int *num_attributes /* out */
1285 VADriverContextP ctx = CTX(dpy);
1288 TRACE(vaQueryDisplayAttributes);
1289 return ctx->vtable.vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
1293 * Get display attributes
1294 * This function returns the current attribute values in "attr_list".
1295 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1296 * from vaQueryDisplayAttributes() can have their values retrieved.
1298 VAStatus vaGetDisplayAttributes (
1300 VADisplayAttribute *attr_list, /* in/out */
1304 VADriverContextP ctx = CTX(dpy);
1307 TRACE(vaGetDisplayAttributes);
1308 return ctx->vtable.vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
1312 * Set display attributes
1313 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1314 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1315 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1317 VAStatus vaSetDisplayAttributes (
1319 VADisplayAttribute *attr_list,
1323 VADriverContextP ctx = CTX(dpy);
1326 TRACE(vaSetDisplayAttributes);
1327 return ctx->vtable.vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
1331 #warning TODO: Remove vaDbgCopySurfaceToBuffer in rev 0.29
1332 VAStatus vaDbgCopySurfaceToBuffer(VADisplay dpy,
1333 VASurfaceID surface,
1334 void **buffer, /* out */
1335 unsigned int *stride /* out */
1338 VADriverContextP ctx = CTX(dpy);
1341 TRACE(vaDbgCopySurfaceToBuffer);
1342 return ctx->vtable.vaDbgCopySurfaceToBuffer( ctx, surface, buffer, stride );