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"
32 #include "va_dricommon.h"
33 #include "va_nvctrl.h"
39 #include <sys/types.h>
44 static VADisplayContextP pDisplayContexts = NULL;
46 static int va_DisplayContextIsValid (
47 VADisplayContextP pDisplayContext
50 VADisplayContextP ctx = pDisplayContexts;
54 if (ctx == pDisplayContext && pDisplayContext->pDriverContext)
61 static void va_DisplayContextDestroy (
62 VADisplayContextP pDisplayContext
65 VADisplayContextP *ctx = &pDisplayContexts;
67 /* Throw away pDisplayContext */
70 if (*ctx == pDisplayContext)
72 *ctx = pDisplayContext->pNext;
73 pDisplayContext->pNext = NULL;
76 ctx = &((*ctx)->pNext);
78 free(pDisplayContext->pDriverContext->dri_state);
79 free(pDisplayContext->pDriverContext);
80 free(pDisplayContext);
84 static VAStatus va_DRI2GetDriverName (
85 VADisplayContextP pDisplayContext,
89 VADriverContextP ctx = pDisplayContext->pDriverContext;
91 if (!isDRI2Connected(ctx, driver_name))
92 return VA_STATUS_ERROR_UNKNOWN;
94 return VA_STATUS_SUCCESS;
97 static VAStatus va_DRIGetDriverName (
98 VADisplayContextP pDisplayContext,
102 VADriverContextP ctx = pDisplayContext->pDriverContext;
104 if (!isDRI1Connected(ctx, driver_name))
105 return VA_STATUS_ERROR_UNKNOWN;
107 return VA_STATUS_SUCCESS;
110 static VAStatus va_NVCTRL_GetDriverName (
111 VADisplayContextP pDisplayContext,
115 VADriverContextP ctx = pDisplayContext->pDriverContext;
116 int direct_capable, driver_major, driver_minor, driver_patch;
119 result = VA_NVCTRLQueryDirectRenderingCapable((Display *)ctx->native_dpy, ctx->x11_screen,
121 if (!result || !direct_capable)
122 return VA_STATUS_ERROR_UNKNOWN;
124 result = VA_NVCTRLGetClientDriverName((Display *)ctx->native_dpy, ctx->x11_screen,
125 &driver_major, &driver_minor,
126 &driver_patch, driver_name);
128 return VA_STATUS_ERROR_UNKNOWN;
130 return VA_STATUS_SUCCESS;
133 static VAStatus va_DisplayContextGetDriverName (
134 VADisplayContextP pDisplayContext,
139 char *driver_name_env;
144 if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL
145 && geteuid() == getuid())
147 /* don't allow setuid apps to use LIBVA_DRIVER_NAME */
148 *driver_name = strdup(driver_name_env);
149 return VA_STATUS_SUCCESS;
152 vaStatus = va_DRI2GetDriverName(pDisplayContext, driver_name);
153 if (vaStatus != VA_STATUS_SUCCESS)
154 vaStatus = va_DRIGetDriverName(pDisplayContext, driver_name);
155 if (vaStatus != VA_STATUS_SUCCESS)
156 vaStatus = va_NVCTRL_GetDriverName(pDisplayContext, driver_name);
162 VADisplay vaGetDisplay (
163 Display *native_dpy /* implementation specific */
166 VADisplay dpy = NULL;
167 VADisplayContextP pDisplayContext = pDisplayContexts;
172 while (pDisplayContext)
174 if (pDisplayContext->pDriverContext &&
175 pDisplayContext->pDriverContext->native_dpy == (void *)native_dpy)
177 dpy = (VADisplay)pDisplayContext;
180 pDisplayContext = pDisplayContext->pNext;
185 /* create new entry */
186 VADriverContextP pDriverContext;
187 struct dri_state *dri_state;
188 pDisplayContext = calloc(1, sizeof(*pDisplayContext));
189 pDriverContext = calloc(1, sizeof(*pDriverContext));
190 dri_state = calloc(1, sizeof(*dri_state));
191 if (pDisplayContext && pDriverContext && dri_state)
193 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
195 pDriverContext->native_dpy = (void *)native_dpy;
196 pDisplayContext->pNext = pDisplayContexts;
197 pDisplayContext->pDriverContext = pDriverContext;
198 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
199 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
200 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
201 pDisplayContexts = pDisplayContext;
202 pDriverContext->dri_state = dri_state;
203 dpy = (VADisplay)pDisplayContext;
208 free(pDisplayContext);
210 free(pDriverContext);