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.
27 #include "va_backend.h"
28 #include "va_android.h"
29 #include "va_dricommon.h" /* needs some helper functions from this file */
35 #include <sys/types.h>
45 #define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; }
46 #define DEVICE_NAME "/dev/card0"
48 static VADisplayContextP pDisplayContexts = NULL;
50 static int open_device (char *dev_name)
55 if (-1 == stat (dev_name, &st))
57 printf ("Cannot identify '%s': %d, %s\n",
58 dev_name, errno, strerror (errno));
62 if (!S_ISCHR (st.st_mode))
64 printf ("%s is no device\n", dev_name);
68 fd = open (dev_name, O_RDWR);
72 fprintf (stderr, "Cannot open '%s': %d, %s\n",
73 dev_name, errno, strerror (errno));
80 static int va_DisplayContextIsValid (
81 VADisplayContextP pDisplayContext
84 VADisplayContextP ctx = pDisplayContexts;
88 if (ctx == pDisplayContext && pDisplayContext->pDriverContext)
95 static void va_DisplayContextDestroy (
96 VADisplayContextP pDisplayContext
99 VADisplayContextP *ctx = &pDisplayContexts;
101 /* Throw away pDisplayContext */
104 if (*ctx == pDisplayContext)
106 *ctx = pDisplayContext->pNext;
107 pDisplayContext->pNext = NULL;
110 ctx = &((*ctx)->pNext);
112 free(pDisplayContext->pDriverContext->dri_state);
113 free(pDisplayContext->pDriverContext);
114 free(pDisplayContext);
118 static VAStatus va_DisplayContextGetDriverName (
119 VADisplayContextP pDisplayContext,
123 VADriverContextP ctx = pDisplayContext->pDriverContext;
124 struct dri_state *dri_state = (struct dri_state *)ctx->dri_state;
125 char *driver_name_env;
126 int vendor_id, device_id;
131 char driver_name[64];
133 { 0x8086, 0x4100, "pvr" },
134 { 0x8086, 0x0130, "pvr" },
138 memset(dri_state, 0, sizeof(*dri_state));
139 dri_state->fd = open_device(DEVICE_NAME);
141 if (dri_state->fd < 0) {
142 fprintf(stderr,"can't open DRM devices\n");
143 return VA_STATUS_ERROR_UNKNOWN;
146 /* TBD: other vendor driver names */
147 vendor_id = devices[0].vendor_id;
148 device_id = devices[0].device_id;
149 *driver_name = strdup(devices[0].driver_name);
151 dri_state->driConnectedFlag = VA_DUMMY;
153 return VA_STATUS_SUCCESS;
156 static VAStatus va_DisplayContextGetDriverName (
157 VADisplayContextP pDisplayContext,
161 VADriverContextP ctx = pDisplayContext->pDriverContext;
162 struct dri_state *dri_state = (struct dri_state *)ctx->dri_state;
163 char *driver_name_env;
164 int vendor_id, device_id;
170 char driver_name[64];
172 { 0x8086, 0x4100, "pvr" },
173 { 0x8086, 0x0130, "pvr" },
177 memset(dri_state, 0, sizeof(*dri_state));
178 dri_state->fd = drm_open_any(&vendor_id, &device_id);
180 if (dri_state->fd < 0) {
181 fprintf(stderr,"can't open DRM devices\n");
182 return VA_STATUS_ERROR_UNKNOWN;
185 /* TBD: other vendor driver names */
187 while (devices[i].device_id != 0) {
188 if ((devices[i].vendor_id == vendor_id) &&
189 (devices[i].device_id == device_id))
194 if (devices[i].device_id != 0)
195 *driver_name = strdup(devices[i].driver_name);
197 fprintf(stderr,"device (0x%04x:0x%04x) is not supported\n",
198 vendor_id, device_id);
200 return VA_STATUS_ERROR_UNKNOWN;
203 printf("DRM device is opened, loading driver %s for device 0x%04x:0x%04x\n",
204 driver_name, vendor_id, device_id);
206 dri_state->driConnectedFlag = VA_DUMMY;
208 return VA_STATUS_SUCCESS;
212 VADisplay vaGetDisplay (
213 void *native_dpy /* implementation specific */
216 VADisplay dpy = NULL;
217 VADisplayContextP pDisplayContext = pDisplayContexts;
222 while (pDisplayContext)
224 if (pDisplayContext->pDriverContext &&
225 pDisplayContext->pDriverContext->native_dpy == (void *)native_dpy)
227 dpy = (VADisplay)pDisplayContext;
230 pDisplayContext = pDisplayContext->pNext;
236 /* create new entry */
237 VADriverContextP pDriverContext;
238 struct dri_state *dri_state;
239 pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext));
240 pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext));
241 dri_state = (struct dri_state*)calloc(1, sizeof(*dri_state));
242 if (pDisplayContext && pDriverContext && dri_state)
244 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
246 pDriverContext->native_dpy = (void *)native_dpy;
247 pDisplayContext->pNext = pDisplayContexts;
248 pDisplayContext->pDriverContext = pDriverContext;
249 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
250 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
251 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
252 pDisplayContexts = pDisplayContext;
253 pDriverContext->dri_state = dri_state;
254 dpy = (VADisplay)pDisplayContext;
259 free(pDisplayContext);
261 free(pDriverContext);
270 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
271 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
276 extern int fool_postp; /* do nothing for vaPutSurface if set */
277 extern int trace_flag; /* trace vaPutSurface parameters */
279 void va_TracePutSurface (
282 void *draw, /* the target Drawable */
289 unsigned short destw,
290 unsigned short desth,
291 VARectangle *cliprects, /* client supplied clip list */
292 unsigned int number_cliprects, /* number of clip rects in the clip list */
293 unsigned int flags /* de-interlacing flags */
297 #define VA_TRACE(trace_func,...) \
299 trace_func(__VA_ARGS__); \
302 VAStatus vaPutSurface (
305 sp<ISurface> draw, /* Android Surface/Window */
312 unsigned short destw,
313 unsigned short desth,
314 VARectangle *cliprects, /* client supplied clip list */
315 unsigned int number_cliprects, /* number of clip rects in the clip list */
316 unsigned int flags /* de-interlacing flags */
319 VADriverContextP ctx;
322 return VA_STATUS_SUCCESS;
327 VA_TRACE(va_TracePutSurface, dpy, surface, static_cast<void*>(&draw), srcx, srcy, srcw, srch,
328 destx, desty, destw, desth,
329 cliprects, number_cliprects, flags );
331 return ctx->vtable.vaPutSurface( ctx, surface, static_cast<void*>(&draw), srcx, srcy, srcw, srch,
332 destx, desty, destw, desth,
333 cliprects, number_cliprects, flags );