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;
51 * read a config "env" for libva.conf or from environment setting
52 * liva.conf has higher priority
53 * return 0: the "env" is set, and the value is copied into env_value
54 * 1: the env is not set
56 int va_parseConfig(char *env, char *env_value)
58 char *token, *value, *saveptr;
65 fp = fopen("/etc/libva.conf", "r");
66 while (fp && (fgets(oneline, 1024, fp) != NULL)) {
67 if (strlen(oneline) == 1)
69 token = strtok_r(oneline, "=\n", &saveptr);
70 value = strtok_r(NULL, "=\n", &saveptr);
72 if (NULL == token || NULL == value)
75 if (strcmp(token, env) == 0) {
77 strncpy(env_value,value, 1024);
87 /* no setting in config file, use env setting */
90 strncpy(env_value, getenv(env), 1024);
98 int vaDisplayIsValid(VADisplay dpy)
100 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
101 return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
104 void va_errorMessage(const char *msg, ...)
108 fprintf(stderr, "libva error: ");
110 vfprintf(stderr, msg, args);
114 void va_infoMessage(const char *msg, ...)
118 fprintf(stderr, "libva: ");
120 vfprintf(stderr, msg, args);
124 static bool va_checkVtable(void *ptr, char *function)
127 va_errorMessage("No valid vtable entry for va%s\n", function);
133 static bool va_checkMaximum(int value, char *variable)
136 va_errorMessage("Failed to define max_%s in init\n", variable);
142 static bool va_checkString(const char* value, char *variable)
145 va_errorMessage("Failed to define str_%s in init\n", variable);
152 va_getDriverInitName(char *name, int namelen, int major, int minor)
154 int ret = snprintf(name, namelen, "__vaDriverInit_%d_%d", major, minor);
155 return ret > 0 && ret < namelen;
158 static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
160 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
162 return pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
165 static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
167 VADriverContextP ctx = CTX(dpy);
168 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
169 char *search_path = NULL;
173 if (geteuid() == getuid())
174 /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
175 search_path = getenv("LIBVA_DRIVERS_PATH");
177 search_path = VA_DRIVERS_PATH;
179 search_path = strdup((const char *)search_path);
180 driver_dir = strtok_r(search_path, ":", &saveptr);
183 char *driver_path = (char *) malloc( strlen(driver_dir) +
184 strlen(driver_name) +
185 strlen(DRIVER_EXTENSION) + 2 );
186 strncpy( driver_path, driver_dir, strlen(driver_dir) + 1);
187 strncat( driver_path, "/", strlen("/") );
188 strncat( driver_path, driver_name, strlen(driver_name) );
189 strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
191 va_infoMessage("Trying to open %s\n", driver_path);
193 handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
195 handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
198 /* Don't give errors for non-existing files */
199 if (0 == access( driver_path, F_OK))
200 va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
202 VADriverInit init_func = NULL;
203 char init_func_s[256];
206 static const struct {
209 } compatible_versions[] = {
210 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
215 for (i = 0; compatible_versions[i].major >= 0; i++) {
216 if (va_getDriverInitName(init_func_s, sizeof(init_func_s),
217 compatible_versions[i].major,
218 compatible_versions[i].minor)) {
219 init_func = (VADriverInit)dlsym(handle, init_func_s);
221 va_infoMessage("Found init function %s\n", init_func_s);
227 if (compatible_versions[i].major < 0) {
228 va_errorMessage("%s has no function %s\n",
229 driver_path, 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) {
246 CHECK_MAXIMUM(vaStatus, ctx, profiles);
247 CHECK_MAXIMUM(vaStatus, ctx, entrypoints);
248 CHECK_MAXIMUM(vaStatus, ctx, attributes);
249 CHECK_MAXIMUM(vaStatus, ctx, image_formats);
250 CHECK_MAXIMUM(vaStatus, ctx, subpic_formats);
251 CHECK_MAXIMUM(vaStatus, ctx, display_attributes);
252 CHECK_STRING(vaStatus, ctx, vendor);
253 CHECK_VTABLE(vaStatus, ctx, Terminate);
254 CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles);
255 CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints);
256 CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes);
257 CHECK_VTABLE(vaStatus, ctx, CreateConfig);
258 CHECK_VTABLE(vaStatus, ctx, DestroyConfig);
259 CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes);
260 CHECK_VTABLE(vaStatus, ctx, CreateSurfaces);
261 CHECK_VTABLE(vaStatus, ctx, DestroySurfaces);
262 CHECK_VTABLE(vaStatus, ctx, CreateContext);
263 CHECK_VTABLE(vaStatus, ctx, DestroyContext);
264 CHECK_VTABLE(vaStatus, ctx, CreateBuffer);
265 CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements);
266 CHECK_VTABLE(vaStatus, ctx, MapBuffer);
267 CHECK_VTABLE(vaStatus, ctx, UnmapBuffer);
268 CHECK_VTABLE(vaStatus, ctx, DestroyBuffer);
269 CHECK_VTABLE(vaStatus, ctx, BeginPicture);
270 CHECK_VTABLE(vaStatus, ctx, RenderPicture);
271 CHECK_VTABLE(vaStatus, ctx, EndPicture);
272 CHECK_VTABLE(vaStatus, ctx, SyncSurface);
273 CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus);
274 CHECK_VTABLE(vaStatus, ctx, PutSurface);
275 CHECK_VTABLE(vaStatus, ctx, QueryImageFormats);
276 CHECK_VTABLE(vaStatus, ctx, CreateImage);
277 CHECK_VTABLE(vaStatus, ctx, DeriveImage);
278 CHECK_VTABLE(vaStatus, ctx, DestroyImage);
279 CHECK_VTABLE(vaStatus, ctx, SetImagePalette);
280 CHECK_VTABLE(vaStatus, ctx, GetImage);
281 CHECK_VTABLE(vaStatus, ctx, PutImage);
282 CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats);
283 CHECK_VTABLE(vaStatus, ctx, CreateSubpicture);
284 CHECK_VTABLE(vaStatus, ctx, DestroySubpicture);
285 CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage);
286 CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey);
287 CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha);
288 CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture);
289 CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture);
290 CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes);
291 CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes);
292 CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes);
294 if (VA_STATUS_SUCCESS != vaStatus) {
295 va_errorMessage("%s init failed\n", driver_path);
298 if (VA_STATUS_SUCCESS == vaStatus)
299 ctx->handle = handle;
306 driver_dir = strtok_r(NULL, ":", &saveptr);
314 VAPrivFunc vaGetLibFunc(VADisplay dpy, const char *func)
316 VADriverContextP ctx;
317 if (!vaDisplayIsValid(dpy))
321 if (NULL == ctx->handle)
324 return (VAPrivFunc) dlsym(ctx->handle, func);
329 * Returns a short english description of error_status
331 const char *vaErrorStr(VAStatus error_status)
333 switch(error_status) {
334 case VA_STATUS_SUCCESS:
335 return "success (no error)";
336 case VA_STATUS_ERROR_OPERATION_FAILED:
337 return "operation failed";
338 case VA_STATUS_ERROR_ALLOCATION_FAILED:
339 return "resource allocation failed";
340 case VA_STATUS_ERROR_INVALID_DISPLAY:
341 return "invalid VADisplay";
342 case VA_STATUS_ERROR_INVALID_CONFIG:
343 return "invalid VAConfigID";
344 case VA_STATUS_ERROR_INVALID_CONTEXT:
345 return "invalid VAContextID";
346 case VA_STATUS_ERROR_INVALID_SURFACE:
347 return "invalid VASurfaceID";
348 case VA_STATUS_ERROR_INVALID_BUFFER:
349 return "invalid VABufferID";
350 case VA_STATUS_ERROR_INVALID_IMAGE:
351 return "invalid VAImageID";
352 case VA_STATUS_ERROR_INVALID_SUBPICTURE:
353 return "invalid VASubpictureID";
354 case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
355 return "attribute not supported";
356 case VA_STATUS_ERROR_MAX_NUM_EXCEEDED:
357 return "list argument exceeds maximum number";
358 case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
359 return "the requested VAProfile is not supported";
360 case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
361 return "the requested VAEntryPoint is not supported";
362 case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
363 return "the requested RT Format is not supported";
364 case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
365 return "the requested VABufferType is not supported";
366 case VA_STATUS_ERROR_SURFACE_BUSY:
367 return "surface is in use";
368 case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
369 return "flag not supported";
370 case VA_STATUS_ERROR_INVALID_PARAMETER:
371 return "invalid parameter";
372 case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
373 return "resolution not supported";
374 case VA_STATUS_ERROR_UNIMPLEMENTED:
375 return "the requested function is not implemented";
376 case VA_STATUS_ERROR_SURFACE_IN_DISPLAYING:
377 return "surface is in displaying (may by overlay)" ;
378 case VA_STATUS_ERROR_INVALID_IMAGE_FORMAT:
379 return "invalid VAImageFormat";
380 case VA_STATUS_ERROR_UNKNOWN:
381 return "unknown libva error";
383 return "unknown libva error / description missing";
386 VAStatus vaInitialize (
388 int *major_version, /* out */
389 int *minor_version /* out */
392 const char *driver_name_env = NULL;
393 char *driver_name = NULL;
402 va_infoMessage("VA-API version %s\n", VA_VERSION_S);
404 driver_name_env = getenv("LIBVA_DRIVER_NAME");
405 if (driver_name_env && geteuid() == getuid()) {
406 /* Don't allow setuid apps to use LIBVA_DRIVER_NAME */
407 driver_name = strdup(driver_name_env);
408 vaStatus = VA_STATUS_SUCCESS;
409 va_infoMessage("User requested driver '%s'\n", driver_name);
411 vaStatus = va_getDriverName(dpy, &driver_name);
412 va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
415 if (VA_STATUS_SUCCESS == vaStatus) {
416 vaStatus = va_openDriver(dpy, driver_name);
417 va_infoMessage("va_openDriver() returns %d\n", vaStatus);
419 *major_version = VA_MAJOR_VERSION;
420 *minor_version = VA_MINOR_VERSION;
426 VA_TRACE_LOG(va_TraceInitialize, dpy, major_version, minor_version);
433 * After this call, all library internal resources will be cleaned up
435 VAStatus vaTerminate (
439 VAStatus vaStatus = VA_STATUS_SUCCESS;
440 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
441 VADriverContextP old_ctx;
446 if (old_ctx->handle) {
447 vaStatus = old_ctx->vtable->vaTerminate(old_ctx);
448 dlclose(old_ctx->handle);
449 old_ctx->handle = NULL;
451 free(old_ctx->vtable);
452 old_ctx->vtable = NULL;
454 if (VA_STATUS_SUCCESS == vaStatus)
455 pDisplayContext->vaDestroy(pDisplayContext);
457 VA_TRACE_LOG(va_TraceTerminate, dpy);
467 * vaQueryVendorString returns a pointer to a zero-terminated string
468 * describing some aspects of the VA implemenation on a specific
469 * hardware accelerator. The format of the returned string is:
470 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
471 * e.g. for the Intel GMA500 implementation, an example would be:
472 * "IntelGMA500-1.0-0.2-patch3
474 const char *vaQueryVendorString (
478 if (!vaDisplayIsValid(dpy))
481 return CTX(dpy)->str_vendor;
485 /* Get maximum number of profiles supported by the implementation */
486 int vaMaxNumProfiles (
490 if (!vaDisplayIsValid(dpy))
493 return CTX(dpy)->max_profiles;
496 /* Get maximum number of entrypoints supported by the implementation */
497 int vaMaxNumEntrypoints (
501 if (!vaDisplayIsValid(dpy))
504 return CTX(dpy)->max_entrypoints;
508 /* Get maximum number of attributs supported by the implementation */
509 int vaMaxNumConfigAttributes (
513 if (!vaDisplayIsValid(dpy))
516 return CTX(dpy)->max_attributes;
519 VAStatus vaQueryConfigEntrypoints (
522 VAEntrypoint *entrypoints, /* out */
523 int *num_entrypoints /* out */
526 VADriverContextP ctx;
530 return ctx->vtable->vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
533 VAStatus vaGetConfigAttributes (
536 VAEntrypoint entrypoint,
537 VAConfigAttrib *attrib_list, /* in/out */
541 VADriverContextP ctx;
545 return ctx->vtable->vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
548 VAStatus vaQueryConfigProfiles (
550 VAProfile *profile_list, /* out */
551 int *num_profiles /* out */
554 VADriverContextP ctx;
558 return ctx->vtable->vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
561 VAStatus vaCreateConfig (
564 VAEntrypoint entrypoint,
565 VAConfigAttrib *attrib_list,
567 VAConfigID *config_id /* out */
570 VADriverContextP ctx;
571 VAStatus vaStatus = VA_STATUS_SUCCESS;
577 vaStatus = ctx->vtable->vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
579 /* record the current entrypoint for further trace/fool determination */
580 VA_TRACE_FUNC(va_TraceCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
581 VA_FOOL_FUNC(va_FoolCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
586 VAStatus vaDestroyConfig (
591 VADriverContextP ctx;
595 return ctx->vtable->vaDestroyConfig ( ctx, config_id );
598 VAStatus vaQueryConfigAttributes (
600 VAConfigID config_id,
601 VAProfile *profile, /* out */
602 VAEntrypoint *entrypoint, /* out */
603 VAConfigAttrib *attrib_list,/* out */
604 int *num_attribs /* out */
607 VADriverContextP ctx;
611 return ctx->vtable->vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
614 VAStatus vaCreateSurfaces (
620 VASurfaceID *surfaces /* out */
623 VADriverContextP ctx;
629 vaStatus = ctx->vtable->vaCreateSurfaces( ctx, width, height, format, num_surfaces, surfaces );
631 VA_TRACE_LOG(va_TraceCreateSurface, dpy, width, height, format, num_surfaces, surfaces);
637 VAStatus vaDestroySurfaces (
639 VASurfaceID *surface_list,
643 VADriverContextP ctx;
647 return ctx->vtable->vaDestroySurfaces( ctx, surface_list, num_surfaces );
650 VAStatus vaCreateContext (
652 VAConfigID config_id,
656 VASurfaceID *render_targets,
657 int num_render_targets,
658 VAContextID *context /* out */
661 VADriverContextP ctx;
667 vaStatus = ctx->vtable->vaCreateContext( ctx, config_id, picture_width, picture_height,
668 flag, render_targets, num_render_targets, context );
670 /* keep current encode/decode resoluton */
671 VA_TRACE_FUNC(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
676 VAStatus vaDestroyContext (
681 VADriverContextP ctx;
685 return ctx->vtable->vaDestroyContext( ctx, context );
688 VAStatus vaCreateBuffer (
690 VAContextID context, /* in */
691 VABufferType type, /* in */
692 unsigned int size, /* in */
693 unsigned int num_elements, /* in */
695 VABufferID *buf_id /* out */
698 VADriverContextP ctx;
703 VA_FOOL_FUNC(va_FoolCreateBuffer, dpy, context, type, size, num_elements, data, buf_id);
705 return VA_STATUS_SUCCESS;
707 return ctx->vtable->vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
710 VAStatus vaBufferSetNumElements (
712 VABufferID buf_id, /* in */
713 unsigned int num_elements /* in */
716 VADriverContextP ctx;
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;
739 VA_FOOL_FUNC(va_FoolMapBuffer, dpy, buf_id, pbuf);
741 return VA_STATUS_SUCCESS;
743 va_status = ctx->vtable->vaMapBuffer( ctx, buf_id, pbuf );
745 VA_TRACE_LOG(va_TraceMapBuffer, dpy, buf_id, pbuf);
750 VAStatus vaUnmapBuffer (
752 VABufferID buf_id /* in */
755 VADriverContextP ctx;
760 VA_FOOL_FUNC(va_FoolUnmapBuffer, dpy, buf_id);
762 return VA_STATUS_SUCCESS;
764 return ctx->vtable->vaUnmapBuffer( ctx, buf_id );
767 VAStatus vaDestroyBuffer (
772 VADriverContextP ctx;
778 return ctx->vtable->vaDestroyBuffer( ctx, buffer_id );
781 VAStatus vaBufferInfo (
783 VAContextID context, /* in */
784 VABufferID buf_id, /* in */
785 VABufferType *type, /* out */
786 unsigned int *size, /* out */
787 unsigned int *num_elements /* out */
790 VADriverContextP ctx;
796 VA_FOOL_FUNC(va_FoolBufferInfo, dpy, buf_id, type, size, num_elements);
798 return VA_STATUS_SUCCESS;
800 return ctx->vtable->vaBufferInfo( ctx, buf_id, type, size, num_elements );
803 VAStatus vaBeginPicture (
806 VASurfaceID render_target
809 VADriverContextP ctx;
815 VA_TRACE_FUNC(va_TraceBeginPicture, dpy, context, render_target);
818 va_status = ctx->vtable->vaBeginPicture( ctx, context, render_target );
823 VAStatus vaRenderPicture (
830 VADriverContextP ctx;
835 VA_TRACE_LOG(va_TraceRenderPicture, dpy, context, buffers, num_buffers);
838 return ctx->vtable->vaRenderPicture( ctx, context, buffers, num_buffers );
841 VAStatus vaEndPicture (
847 VADriverContextP ctx;
852 /* dump encode source surface */
853 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 0);
854 /* return directly if do dummy operation */
857 va_status = ctx->vtable->vaEndPicture( ctx, context );
858 /* dump decode dest surface */
859 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 1);
864 VAStatus vaSyncSurface (
866 VASurfaceID render_target
870 VADriverContextP ctx;
875 va_status = ctx->vtable->vaSyncSurface( ctx, render_target );
876 VA_TRACE_LOG(va_TraceSyncSurface, dpy, render_target);
881 VAStatus vaQuerySurfaceStatus (
883 VASurfaceID render_target,
884 VASurfaceStatus *status /* out */
888 VADriverContextP ctx;
892 va_status = ctx->vtable->vaQuerySurfaceStatus( ctx, render_target, status );
894 VA_TRACE_LOG(va_TraceQuerySurfaceStatus, dpy, render_target, status);
899 VAStatus vaQuerySurfaceError (
902 VAStatus error_status,
903 void **error_info /*out*/
907 VADriverContextP ctx;
911 va_status = ctx->vtable->vaQuerySurfaceError( ctx, surface, error_status, error_info );
913 VA_TRACE_LOG(va_TraceQuerySurfaceError, dpy, surface, error_status, error_info);
918 /* Get maximum number of image formats supported by the implementation */
919 int vaMaxNumImageFormats (
923 if (!vaDisplayIsValid(dpy))
926 return CTX(dpy)->max_image_formats;
929 VAStatus vaQueryImageFormats (
931 VAImageFormat *format_list, /* out */
932 int *num_formats /* out */
935 VADriverContextP ctx;
939 return ctx->vtable->vaQueryImageFormats ( ctx, format_list, num_formats);
943 * The width and height fields returned in the VAImage structure may get
944 * enlarged for some YUV formats. The size of the data buffer that needs
945 * to be allocated will be given in the "data_size" field in VAImage.
946 * Image data is not allocated by this function. The client should
947 * allocate the memory and fill in the VAImage structure's data field
948 * after looking at "data_size" returned from the library.
950 VAStatus vaCreateImage (
952 VAImageFormat *format,
955 VAImage *image /* out */
958 VADriverContextP ctx;
962 return ctx->vtable->vaCreateImage ( ctx, format, width, height, image);
966 * Should call DestroyImage before destroying the surface it is bound to
968 VAStatus vaDestroyImage (
973 VADriverContextP ctx;
977 return ctx->vtable->vaDestroyImage ( ctx, image);
980 VAStatus vaSetImagePalette (
983 unsigned char *palette
986 VADriverContextP ctx;
990 return ctx->vtable->vaSetImagePalette ( ctx, image, palette);
994 * Retrieve surface data into a VAImage
995 * Image must be in a format supported by the implementation
997 VAStatus vaGetImage (
1000 int x, /* coordinates of the upper left source pixel */
1002 unsigned int width, /* width and height of the region */
1003 unsigned int height,
1007 VADriverContextP ctx;
1011 return ctx->vtable->vaGetImage ( ctx, surface, x, y, width, height, image);
1015 * Copy data from a VAImage to a surface
1016 * Image must be in a format supported by the implementation
1018 VAStatus vaPutImage (
1020 VASurfaceID surface,
1024 unsigned int src_width,
1025 unsigned int src_height,
1028 unsigned int dest_width,
1029 unsigned int dest_height
1032 VADriverContextP ctx;
1036 return ctx->vtable->vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
1040 * Derive an VAImage from an existing surface.
1041 * This interface will derive a VAImage and corresponding image buffer from
1042 * an existing VA Surface. The image buffer can then be mapped/unmapped for
1043 * direct CPU access. This operation is only possible on implementations with
1044 * direct rendering capabilities and internal surface formats that can be
1045 * represented with a VAImage. When the operation is not possible this interface
1046 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
1047 * to using vaCreateImage + vaPutImage to accomplish the same task in an
1050 * Implementations should only return success when the resulting image buffer
1051 * would be useable with vaMap/Unmap.
1053 * When directly accessing a surface special care must be taken to insure
1054 * proper synchronization with the graphics hardware. Clients should call
1055 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
1056 * rendering or currently being displayed by an overlay.
1058 * Additionally nothing about the contents of a surface should be assumed
1059 * following a vaPutSurface. Implementations are free to modify the surface for
1060 * scaling or subpicture blending within a call to vaPutImage.
1062 * Calls to vaPutImage or vaGetImage using the same surface from which the image
1063 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
1064 * vaGetImage with other surfaces is supported.
1066 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
1067 * image and image buffer structures will be destroyed; however, the underlying
1068 * surface will remain unchanged until freed with vaDestroySurfaces.
1070 VAStatus vaDeriveImage (
1072 VASurfaceID surface,
1073 VAImage *image /* out */
1076 VADriverContextP ctx;
1080 return ctx->vtable->vaDeriveImage ( ctx, surface, image );
1084 /* Get maximum number of subpicture formats supported by the implementation */
1085 int vaMaxNumSubpictureFormats (
1089 if (!vaDisplayIsValid(dpy))
1092 return CTX(dpy)->max_subpic_formats;
1096 * Query supported subpicture formats
1097 * The caller must provide a "format_list" array that can hold at
1098 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1099 * for each format to indicate additional capabilities for that format. The actual
1100 * number of formats returned in "format_list" is returned in "num_formats".
1102 VAStatus vaQuerySubpictureFormats (
1104 VAImageFormat *format_list, /* out */
1105 unsigned int *flags, /* out */
1106 unsigned int *num_formats /* out */
1109 VADriverContextP ctx;
1114 return ctx->vtable->vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
1118 * Subpictures are created with an image associated.
1120 VAStatus vaCreateSubpicture (
1123 VASubpictureID *subpicture /* out */
1126 VADriverContextP ctx;
1130 return ctx->vtable->vaCreateSubpicture ( ctx, image, subpicture );
1134 * Destroy the subpicture before destroying the image it is assocated to
1136 VAStatus vaDestroySubpicture (
1138 VASubpictureID subpicture
1141 VADriverContextP ctx;
1145 return ctx->vtable->vaDestroySubpicture ( ctx, subpicture);
1148 VAStatus vaSetSubpictureImage (
1150 VASubpictureID subpicture,
1154 VADriverContextP ctx;
1158 return ctx->vtable->vaSetSubpictureImage ( ctx, subpicture, image);
1163 * If chromakey is enabled, then the area where the source value falls within
1164 * the chromakey [min, max] range is transparent
1166 VAStatus vaSetSubpictureChromakey (
1168 VASubpictureID subpicture,
1169 unsigned int chromakey_min,
1170 unsigned int chromakey_max,
1171 unsigned int chromakey_mask
1174 VADriverContextP ctx;
1178 return ctx->vtable->vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
1183 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1184 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1185 * the overall alpha is per-pixel alpha multiplied by the global alpha
1187 VAStatus vaSetSubpictureGlobalAlpha (
1189 VASubpictureID subpicture,
1193 VADriverContextP ctx;
1197 return ctx->vtable->vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
1201 vaAssociateSubpicture associates the subpicture with the target_surface.
1202 It defines the region mapping between the subpicture and the target
1203 surface through source and destination rectangles (with the same width and height).
1204 Both will be displayed at the next call to vaPutSurface. Additional
1205 associations before the call to vaPutSurface simply overrides the association.
1207 VAStatus vaAssociateSubpicture (
1209 VASubpictureID subpicture,
1210 VASurfaceID *target_surfaces,
1212 short src_x, /* upper left offset in subpicture */
1214 unsigned short src_width,
1215 unsigned short src_height,
1216 short dest_x, /* upper left offset in surface */
1218 unsigned short dest_width,
1219 unsigned short dest_height,
1221 * whether to enable chroma-keying or global-alpha
1222 * see VA_SUBPICTURE_XXX values
1227 VADriverContextP ctx;
1231 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 );
1235 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1237 VAStatus vaDeassociateSubpicture (
1239 VASubpictureID subpicture,
1240 VASurfaceID *target_surfaces,
1244 VADriverContextP ctx;
1248 return ctx->vtable->vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
1252 /* Get maximum number of display attributes supported by the implementation */
1253 int vaMaxNumDisplayAttributes (
1259 if (!vaDisplayIsValid(dpy))
1262 tmp = CTX(dpy)->max_display_attributes;
1264 VA_TRACE_LOG(va_TraceMaxNumDisplayAttributes, dpy, tmp);
1270 * Query display attributes
1271 * The caller must provide a "attr_list" array that can hold at
1272 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1273 * returned in "attr_list" is returned in "num_attributes".
1275 VAStatus vaQueryDisplayAttributes (
1277 VADisplayAttribute *attr_list, /* out */
1278 int *num_attributes /* out */
1281 VADriverContextP ctx;
1286 va_status = ctx->vtable->vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
1288 VA_TRACE_LOG(va_TraceQueryDisplayAttributes, dpy, attr_list, num_attributes);
1295 * Get display attributes
1296 * This function returns the current attribute values in "attr_list".
1297 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1298 * from vaQueryDisplayAttributes() can have their values retrieved.
1300 VAStatus vaGetDisplayAttributes (
1302 VADisplayAttribute *attr_list, /* in/out */
1306 VADriverContextP ctx;
1311 va_status = ctx->vtable->vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
1313 VA_TRACE_LOG(va_TraceGetDisplayAttributes, dpy, attr_list, num_attributes);
1319 * Set display attributes
1320 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1321 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1322 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1324 VAStatus vaSetDisplayAttributes (
1326 VADisplayAttribute *attr_list,
1330 VADriverContextP ctx;
1335 va_status = ctx->vtable->vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
1336 VA_TRACE_LOG(va_TraceSetDisplayAttributes, dpy, attr_list, num_attributes);
1341 VAStatus vaLockSurface(VADisplay dpy,
1342 VASurfaceID surface,
1343 unsigned int *fourcc, /* following are output argument */
1344 unsigned int *luma_stride,
1345 unsigned int *chroma_u_stride,
1346 unsigned int *chroma_v_stride,
1347 unsigned int *luma_offset,
1348 unsigned int *chroma_u_offset,
1349 unsigned int *chroma_v_offset,
1350 unsigned int *buffer_name,
1354 VADriverContextP ctx;
1358 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);
1362 VAStatus vaUnlockSurface(VADisplay dpy,
1366 VADriverContextP ctx;
1370 return ctx->vtable->vaUnlockSurface( ctx, surface );