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"
34 #include <sys/types.h>
39 static VADisplayContextP pDisplayContexts = NULL;
41 static int va_DisplayContextIsValid (
42 VADisplayContextP pDisplayContext
45 VADisplayContextP ctx = pDisplayContexts;
49 if (ctx == pDisplayContext && pDisplayContext->pDriverContext)
56 static void va_DisplayContextDestroy (
57 VADisplayContextP pDisplayContext
60 VADisplayContextP *ctx = &pDisplayContexts;
62 /* Throw away pDisplayContext */
65 if (*ctx == pDisplayContext)
67 *ctx = pDisplayContext->pNext;
68 pDisplayContext->pNext = NULL;
71 ctx = &((*ctx)->pNext);
73 free(pDisplayContext->pDriverContext->dri_state);
74 free(pDisplayContext->pDriverContext);
75 free(pDisplayContext);
79 static VAStatus va_DisplayContextGetDriverName (
80 VADisplayContextP pDisplayContext,
84 VAStatus vaStatus VA_STATUS_SUCCESS;
85 char *driver_name_env;
87 unsigned int verndor_id;
88 unsigned int device_id;
91 { 0x8086, 0x4100, "pvr" },
97 if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL
98 && geteuid() == getuid())
100 /* don't allow setuid apps to use LIBVA_DRIVER_NAME */
101 *driver_name = strdup(driver_name_env);
102 return VA_STATUS_SUCCESS;
105 *driver_name = strdup(devices[0].driver_name);
111 VADisplay vaGetDisplay (
112 Display *native_dpy /* implementation specific */
115 VADisplay dpy = NULL;
116 VADisplayContextP pDisplayContext = pDisplayContexts;
121 while (pDisplayContext)
123 if (pDisplayContext->pDriverContext &&
124 pDisplayContext->pDriverContext->native_dpy == (void *)native_dpy)
126 dpy = (VADisplay)pDisplayContext;
129 pDisplayContext = pDisplayContext->pNext;
134 /* create new entry */
135 VADriverContextP pDriverContext;
136 struct dri_state *dri_state;
137 pDisplayContext = calloc(1, sizeof(*pDisplayContext));
138 pDriverContext = calloc(1, sizeof(*pDriverContext));
139 if (pDisplayContext && pDriverContext && dri_state)
141 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
143 pDriverContext->native_dpy = (void *)native_dpy;
144 pDisplayContext->pNext = pDisplayContexts;
145 pDisplayContext->pDriverContext = pDriverContext;
146 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
147 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
148 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
149 pDisplayContexts = pDisplayContext;
150 pDriverContext->dri_state = dri_state;
151 dpy = (VADisplay)pDisplayContext;
156 free(pDisplayContext);
158 free(pDriverContext);