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"
40 #include <sys/types.h>
45 static VADisplayContextP pDisplayContexts = NULL;
47 static int va_DisplayContextIsValid (
48 VADisplayContextP pDisplayContext
51 VADisplayContextP ctx = pDisplayContexts;
55 if (ctx == pDisplayContext && pDisplayContext->pDriverContext)
62 static void va_DisplayContextDestroy (
63 VADisplayContextP pDisplayContext
66 VADisplayContextP *ctx = &pDisplayContexts;
68 /* Throw away pDisplayContext */
71 if (*ctx == pDisplayContext)
73 *ctx = pDisplayContext->pNext;
74 pDisplayContext->pNext = NULL;
77 ctx = &((*ctx)->pNext);
79 free(pDisplayContext->pDriverContext->dri_state);
80 free(pDisplayContext->pDriverContext);
81 free(pDisplayContext);
85 static VAStatus va_DRI2GetDriverName (
86 VADisplayContextP pDisplayContext,
90 VADriverContextP ctx = pDisplayContext->pDriverContext;
92 if (!isDRI2Connected(ctx, driver_name))
93 return VA_STATUS_ERROR_UNKNOWN;
95 return VA_STATUS_SUCCESS;
98 static VAStatus va_DRIGetDriverName (
99 VADisplayContextP pDisplayContext,
103 VADriverContextP ctx = pDisplayContext->pDriverContext;
105 if (!isDRI1Connected(ctx, driver_name))
106 return VA_STATUS_ERROR_UNKNOWN;
108 return VA_STATUS_SUCCESS;
111 static VAStatus va_NVCTRL_GetDriverName (
112 VADisplayContextP pDisplayContext,
116 VADriverContextP ctx = pDisplayContext->pDriverContext;
117 int direct_capable, driver_major, driver_minor, driver_patch;
120 result = VA_NVCTRLQueryDirectRenderingCapable((Display *)ctx->native_dpy, ctx->x11_screen,
122 if (!result || !direct_capable)
123 return VA_STATUS_ERROR_UNKNOWN;
125 result = VA_NVCTRLGetClientDriverName((Display *)ctx->native_dpy, ctx->x11_screen,
126 &driver_major, &driver_minor,
127 &driver_patch, driver_name);
129 return VA_STATUS_ERROR_UNKNOWN;
131 return VA_STATUS_SUCCESS;
134 static VAStatus va_FGLRX_GetDriverName (
135 VADisplayContextP pDisplayContext,
139 VADriverContextP ctx = pDisplayContext->pDriverContext;
140 int driver_major, driver_minor, driver_patch;
143 result = VA_FGLRXGetClientDriverName(ctx->native_dpy, ctx->x11_screen,
144 &driver_major, &driver_minor,
145 &driver_patch, driver_name);
147 return VA_STATUS_ERROR_UNKNOWN;
149 return VA_STATUS_SUCCESS;
152 static VAStatus va_DisplayContextGetDriverName (
153 VADisplayContextP pDisplayContext,
162 vaStatus = va_DRI2GetDriverName(pDisplayContext, driver_name);
163 if (vaStatus != VA_STATUS_SUCCESS)
164 vaStatus = va_DRIGetDriverName(pDisplayContext, driver_name);
165 if (vaStatus != VA_STATUS_SUCCESS)
166 vaStatus = va_NVCTRL_GetDriverName(pDisplayContext, driver_name);
167 if (vaStatus != VA_STATUS_SUCCESS)
168 vaStatus = va_FGLRX_GetDriverName(pDisplayContext, driver_name);
173 VADisplay vaGetDisplay (
174 Display *native_dpy /* implementation specific */
177 VADisplay dpy = NULL;
178 VADisplayContextP pDisplayContext = pDisplayContexts;
183 while (pDisplayContext)
185 if (pDisplayContext->pDriverContext &&
186 pDisplayContext->pDriverContext->native_dpy == (void *)native_dpy)
188 dpy = (VADisplay)pDisplayContext;
191 pDisplayContext = pDisplayContext->pNext;
196 /* create new entry */
197 VADriverContextP pDriverContext;
198 struct dri_state *dri_state;
199 pDisplayContext = calloc(1, sizeof(*pDisplayContext));
200 pDriverContext = calloc(1, sizeof(*pDriverContext));
201 dri_state = calloc(1, sizeof(*dri_state));
202 if (pDisplayContext && pDriverContext && dri_state)
204 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
206 pDriverContext->native_dpy = (void *)native_dpy;
207 pDisplayContext->pNext = pDisplayContexts;
208 pDisplayContext->pDriverContext = pDriverContext;
209 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
210 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
211 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
212 pDisplayContext->opaque = NULL;
213 pDisplayContexts = pDisplayContext;
214 pDriverContext->dri_state = dri_state;
215 dpy = (VADisplay)pDisplayContext;
220 free(pDisplayContext);
222 free(pDriverContext);
231 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
232 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
234 extern int fool_postp; /* do nothing for vaPutSurface if set */
235 extern int trace_flag; /* trace vaPutSurface parameters */
236 #define VA_TRACE(trace_func,...) \
238 trace_func(__VA_ARGS__); \
241 void va_TracePutSurface (
244 void *draw, /* the target Drawable */
251 unsigned short destw,
252 unsigned short desth,
253 VARectangle *cliprects, /* client supplied clip list */
254 unsigned int number_cliprects, /* number of clip rects in the clip list */
255 unsigned int flags /* de-interlacing flags */
259 VAStatus vaPutSurface (
262 Drawable draw, /* X Drawable */
269 unsigned short destw,
270 unsigned short desth,
271 VARectangle *cliprects, /* client supplied clip list */
272 unsigned int number_cliprects, /* number of clip rects in the clip list */
273 unsigned int flags /* de-interlacing flags */
276 VADriverContextP ctx;
279 return VA_STATUS_SUCCESS;
284 VA_TRACE(va_TracePutSurface, dpy, surface, (void *)draw, srcx, srcy, srcw, srch,
285 destx, desty, destw, desth,
286 cliprects, number_cliprects, flags );
288 return ctx->vtable.vaPutSurface( ctx, surface, (void *)draw, srcx, srcy, srcw, srch,
289 destx, desty, destw, desth,
290 cliprects, number_cliprects, flags );