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"
38
#include <sys/types.h>
43
static VADisplayContextP pDisplayContexts = NULL;
45
static int va_DisplayContextIsValid (
46
VADisplayContextP pDisplayContext
49
VADisplayContextP ctx = pDisplayContexts;
53
if (ctx == pDisplayContext && pDisplayContext->pDriverContext)
60
static void va_DisplayContextDestroy (
61
VADisplayContextP pDisplayContext
64
VADisplayContextP *ctx = &pDisplayContexts;
66
/* Throw away pDisplayContext */
69
if (*ctx == pDisplayContext)
71
*ctx = pDisplayContext->pNext;
72
pDisplayContext->pNext = NULL;
75
ctx = &((*ctx)->pNext);
77
free(pDisplayContext->pDriverContext->dri_state);
78
free(pDisplayContext->pDriverContext);
79
free(pDisplayContext);
83
static VAStatus va_DRI2GetDriverName (
84
VADisplayContextP pDisplayContext,
88
VADriverContextP ctx = pDisplayContext->pDriverContext;
90
if (!isDRI2Connected(ctx, driver_name))
91
return VA_STATUS_ERROR_UNKNOWN;
93
return VA_STATUS_SUCCESS;
96
static VAStatus va_DRIGetDriverName (
97
VADisplayContextP pDisplayContext,
101
VADriverContextP ctx = pDisplayContext->pDriverContext;
103
if (!isDRI1Connected(ctx, driver_name))
104
return VA_STATUS_ERROR_UNKNOWN;
106
return VA_STATUS_SUCCESS;
109
static VAStatus va_NVCTRL_GetDriverName (
110
VADisplayContextP pDisplayContext,
114
VADriverContextP ctx = pDisplayContext->pDriverContext;
115
int direct_capable, driver_major, driver_minor, driver_patch;
118
result = VA_NVCTRLQueryDirectRenderingCapable(ctx->x11_dpy, ctx->x11_screen,
120
if (!result || !direct_capable)
121
return VA_STATUS_ERROR_UNKNOWN;
123
result = VA_NVCTRLGetClientDriverName(ctx->x11_dpy, ctx->x11_screen,
124
&driver_major, &driver_minor,
125
&driver_patch, driver_name);
127
return VA_STATUS_ERROR_UNKNOWN;
129
return VA_STATUS_SUCCESS;
132
static VAStatus va_DisplayContextGetDriverName (
133
VADisplayContextP pDisplayContext,
138
char *driver_name_env;
143
if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL
144
&& geteuid() == getuid())
146
/* don't allow setuid apps to use LIBVA_DRIVER_NAME */
147
*driver_name = strdup(driver_name_env);
148
return VA_STATUS_SUCCESS;
151
vaStatus = va_DRI2GetDriverName(pDisplayContext, driver_name);
152
if (vaStatus != VA_STATUS_SUCCESS)
153
vaStatus = va_DRIGetDriverName(pDisplayContext, driver_name);
154
if (vaStatus != VA_STATUS_SUCCESS)
155
vaStatus = va_NVCTRL_GetDriverName(pDisplayContext, driver_name);
161
VADisplay vaGetDisplay (
162
Display *native_dpy /* implementation specific */
165
VADisplay dpy = NULL;
166
VADisplayContextP pDisplayContext = pDisplayContexts;
171
while (pDisplayContext)
173
if (pDisplayContext->pDriverContext &&
174
pDisplayContext->pDriverContext->x11_dpy == native_dpy)
176
dpy = (VADisplay)pDisplayContext;
179
pDisplayContext = pDisplayContext->pNext;
184
/* create new entry */
185
VADriverContextP pDriverContext;
186
struct dri_state *dri_state;
187
pDisplayContext = calloc(1, sizeof(*pDisplayContext));
188
pDriverContext = calloc(1, sizeof(*pDriverContext));
189
dri_state = calloc(1, sizeof(*dri_state));
190
if (pDisplayContext && pDriverContext && dri_state)
192
pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
194
pDriverContext->x11_dpy = native_dpy;
195
pDisplayContext->pNext = pDisplayContexts;
196
pDisplayContext->pDriverContext = pDriverContext;
197
pDisplayContext->vaIsValid = va_DisplayContextIsValid;
198
pDisplayContext->vaDestroy = va_DisplayContextDestroy;
199
pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
200
pDisplayContexts = pDisplayContext;
201
pDriverContext->dri_state = dri_state;
202
dpy = (VADisplay)pDisplayContext;
207
free(pDisplayContext);
209
free(pDriverContext);