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"
34 static VADisplayContextP pDisplayContexts = NULL;
36 static void va_errorMessage(const char *msg, ...)
40 fprintf(stderr, "libva error: ");
42 vfprintf(stderr, msg, args);
46 static void va_infoMessage(const char *msg, ...)
50 fprintf(stderr, "libva: ");
52 vfprintf(stderr, msg, args);
56 static int va_DisplayContextIsValid (
57 VADisplayContextP pDisplayContext
60 VADisplayContextP ctx = pDisplayContexts;
64 if (ctx == pDisplayContext && pDisplayContext->pDriverContext)
71 static void va_DisplayContextDestroy (
72 VADisplayContextP pDisplayContext
75 VADisplayContextP *ctx = &pDisplayContexts;
77 /* Throw away pDisplayContext */
80 if (*ctx == pDisplayContext)
82 *ctx = pDisplayContext->pNext;
83 pDisplayContext->pNext = NULL;
86 ctx = &((*ctx)->pNext);
88 free(pDisplayContext->pDriverContext);
89 free(pDisplayContext);
92 static VAStatus va_DisplayContextGetDriverName (
93 VADisplayContextP pDisplayContext,
97 VADriverContextP ctx = pDisplayContext->pDriverContext;
98 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
104 char *x_driver_name = NULL;
108 if (geteuid() == getuid())
110 /* don't allow setuid apps to use LIBVA_DRIVER_NAME */
111 if (getenv("LIBVA_DRIVER_NAME"))
113 /* For easier debugging */
114 *driver_name = strdup(getenv("LIBVA_DRIVER_NAME"));
115 return VA_STATUS_SUCCESS;
120 result = VA_DRIQueryDirectRenderingCapable(ctx->x11_dpy, ctx->x11_screen, &direct_capable);
123 va_errorMessage("VA_DRIQueryDirectRenderingCapable failed\n");
128 result = direct_capable;
131 va_errorMessage("VA_DRIQueryDirectRenderingCapable returned false\n");
136 result = VA_DRIGetClientDriverName(ctx->x11_dpy, ctx->x11_screen, &driver_major, &driver_minor,
137 &driver_patch, &x_driver_name);
140 va_errorMessage("VA_DRIGetClientDriverName returned false\n");
145 vaStatus = VA_STATUS_SUCCESS;
146 va_infoMessage("VA_DRIGetClientDriverName: %d.%d.%d %s (screen %d)\n",
147 driver_major, driver_minor, driver_patch, x_driver_name, ctx->x11_screen);
149 *driver_name = strdup(x_driver_name);
152 XFree(x_driver_name);
157 VADisplay vaGetDisplay (
161 VADisplay dpy = NULL;
162 VADisplayContextP pDisplayContext = pDisplayContexts;
167 while (pDisplayContext)
169 if (pDisplayContext->pDriverContext &&
170 pDisplayContext->pDriverContext->x11_dpy == native_dpy)
172 dpy = (VADisplay)pDisplayContext;
175 pDisplayContext = pDisplayContext->pNext;
180 /* create new entry */
181 VADriverContextP pDriverContext;
182 pDisplayContext = calloc(1, sizeof(*pDisplayContext));
183 pDriverContext = calloc(1, sizeof(*pDriverContext));
184 if (pDisplayContext && pDriverContext)
186 pDriverContext->old_pNext = (void *)(unsigned long)0xdeadbeef;
187 pDriverContext->x11_dpy = native_dpy;
188 pDisplayContext->pNext = pDisplayContexts;
189 pDisplayContext->pDriverContext = pDriverContext;
190 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
191 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
192 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
193 pDisplayContexts = pDisplayContext;
194 dpy = (VADisplay)pDisplayContext;
199 free(pDisplayContext);
201 free(pDriverContext);