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 "va_dricommon.h"
35 #include "va_nvctrl.h"
42 #include <sys/types.h>
46 #include <X11/extensions/Xfixes.h>
47 #include <X11/extensions/Xdamage.h>
49 static int va_DisplayContextIsValid (
50 VADisplayContextP pDisplayContext
53 return (pDisplayContext != NULL &&
54 pDisplayContext->pDriverContext != NULL);
57 static void va_DisplayContextDestroy (
58 VADisplayContextP pDisplayContext
62 struct dri_state *dri_state;
64 if (pDisplayContext == NULL)
67 ctx = pDisplayContext->pDriverContext;
68 dri_state = ctx->drm_state;
70 if (dri_state && dri_state->close)
71 dri_state->close(ctx);
73 free(pDisplayContext->pDriverContext->drm_state);
74 free(pDisplayContext->pDriverContext);
75 free(pDisplayContext);
79 static VAStatus va_DRI2GetDriverName (
80 VADisplayContextP pDisplayContext,
84 VADriverContextP ctx = pDisplayContext->pDriverContext;
86 if (!isDRI2Connected(ctx, driver_name))
87 return VA_STATUS_ERROR_UNKNOWN;
89 return VA_STATUS_SUCCESS;
92 static VAStatus va_DRIGetDriverName (
93 VADisplayContextP pDisplayContext,
97 VADriverContextP ctx = pDisplayContext->pDriverContext;
99 if (!isDRI1Connected(ctx, driver_name))
100 return VA_STATUS_ERROR_UNKNOWN;
102 return VA_STATUS_SUCCESS;
105 static VAStatus va_NVCTRL_GetDriverName (
106 VADisplayContextP pDisplayContext,
110 VADriverContextP ctx = pDisplayContext->pDriverContext;
111 int direct_capable, driver_major, driver_minor, driver_patch;
114 result = VA_NVCTRLQueryDirectRenderingCapable(ctx->native_dpy, ctx->x11_screen,
116 if (!result || !direct_capable)
117 return VA_STATUS_ERROR_UNKNOWN;
119 result = VA_NVCTRLGetClientDriverName(ctx->native_dpy, ctx->x11_screen,
120 &driver_major, &driver_minor,
121 &driver_patch, driver_name);
123 return VA_STATUS_ERROR_UNKNOWN;
125 return VA_STATUS_SUCCESS;
128 static VAStatus va_FGLRX_GetDriverName (
129 VADisplayContextP pDisplayContext,
133 VADriverContextP ctx = pDisplayContext->pDriverContext;
134 int driver_major, driver_minor, driver_patch;
137 result = VA_FGLRXGetClientDriverName(ctx->native_dpy, ctx->x11_screen,
138 &driver_major, &driver_minor,
139 &driver_patch, driver_name);
141 return VA_STATUS_ERROR_UNKNOWN;
143 return VA_STATUS_SUCCESS;
146 static VAStatus va_DisplayContextGetDriverName (
147 VADisplayContextP pDisplayContext,
156 return VA_STATUS_ERROR_UNKNOWN;
158 vaStatus = va_DRI2GetDriverName(pDisplayContext, driver_name);
159 if (vaStatus != VA_STATUS_SUCCESS)
160 vaStatus = va_DRIGetDriverName(pDisplayContext, driver_name);
161 if (vaStatus != VA_STATUS_SUCCESS)
162 vaStatus = va_NVCTRL_GetDriverName(pDisplayContext, driver_name);
163 if (vaStatus != VA_STATUS_SUCCESS)
164 vaStatus = va_FGLRX_GetDriverName(pDisplayContext, driver_name);
169 VADisplay vaGetDisplay (
170 Display *native_dpy /* implementation specific */
173 VADisplay dpy = NULL;
174 VADisplayContextP pDisplayContext;
181 /* create new entry */
182 VADriverContextP pDriverContext;
183 struct dri_state *dri_state;
184 pDisplayContext = calloc(1, sizeof(*pDisplayContext));
185 pDriverContext = calloc(1, sizeof(*pDriverContext));
186 dri_state = calloc(1, sizeof(*dri_state));
187 if (pDisplayContext && pDriverContext && dri_state)
189 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
191 pDriverContext->native_dpy = (void *)native_dpy;
192 pDriverContext->display_type = VA_DISPLAY_X11;
193 pDisplayContext->pDriverContext = pDriverContext;
194 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
195 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
196 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
197 pDisplayContext->opaque = NULL;
198 pDriverContext->drm_state = dri_state;
199 dpy = (VADisplay)pDisplayContext;
204 free(pDisplayContext);
206 free(pDriverContext);
215 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
216 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
218 void va_TracePutSurface (
221 void *draw, /* the target Drawable */
228 unsigned short destw,
229 unsigned short desth,
230 VARectangle *cliprects, /* client supplied clip list */
231 unsigned int number_cliprects, /* number of clip rects in the clip list */
232 unsigned int flags /* de-interlacing flags */
235 static void va_report_damage(VADriverContextP ctx, Drawable draw, int x, int y, int width, int height)
238 XserverRegion region;
243 xrect.height = height;
245 region = XFixesCreateRegion(ctx->native_dpy, &xrect, 1);
246 XDamageAdd(ctx->native_dpy, draw, region);
247 XFixesDestroyRegion(ctx->native_dpy, region);
248 XFlush(ctx->native_dpy);
250 VAStatus vaPutSurface (
253 Drawable draw, /* X Drawable */
260 unsigned short destw,
261 unsigned short desth,
262 VARectangle *cliprects, /* client supplied clip list */
263 unsigned int number_cliprects, /* number of clip rects in the clip list */
264 unsigned int flags /* de-interlacing flags */
267 VADriverContextP ctx;
272 return VA_STATUS_SUCCESS;
277 VA_TRACE_FUNC(va_TracePutSurface, dpy, surface, (void *)draw, srcx, srcy, srcw, srch,
278 destx, desty, destw, desth,
279 cliprects, number_cliprects, flags );
281 status = ctx->vtable->vaPutSurface( ctx, surface, (void *)draw, srcx, srcy, srcw, srch,
282 destx, desty, destw, desth,
283 cliprects, number_cliprects, flags );
285 va_report_damage(ctx, draw, destx, desty, destw, desth);