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"
30 #include "va_android.h"
31 #include "va_dricommon.h" /* needs some helper functions from this file */
37 #include <sys/types.h>
47 #define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; }
48 #define DEVICE_NAME "/dev/card0"
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 return (pDisplayContext != NULL &&
85 pDisplayContext->pDriverContext != NULL);
88 static void va_DisplayContextDestroy (
89 VADisplayContextP pDisplayContext
92 struct dri_state *dri_state;
94 if (pDisplayContext == NULL)
97 /* close the open-ed DRM fd */
98 dri_state = (struct dri_state *)pDisplayContext->pDriverContext->dri_state;
101 free(pDisplayContext->pDriverContext->dri_state);
102 free(pDisplayContext->pDriverContext);
103 free(pDisplayContext);
107 static VAStatus va_DisplayContextGetDriverName (
108 VADisplayContextP pDisplayContext,
112 VADriverContextP ctx = pDisplayContext->pDriverContext;
113 struct dri_state *dri_state = (struct dri_state *)ctx->dri_state;
114 char *driver_name_env;
115 int vendor_id, device_id;
120 char driver_name[64];
122 { 0x8086, 0x4100, "pvr" },
123 { 0x8086, 0x0130, "pvr" },
127 memset(dri_state, 0, sizeof(*dri_state));
128 dri_state->fd = open_device((char *)DEVICE_NAME);
130 if (dri_state->fd < 0) {
131 fprintf(stderr,"can't open DRM devices\n");
132 return VA_STATUS_ERROR_UNKNOWN;
135 /* TBD: other vendor driver names */
136 vendor_id = devices[0].vendor_id;
137 device_id = devices[0].device_id;
138 *driver_name = strdup(devices[0].driver_name);
140 dri_state->driConnectedFlag = VA_DUMMY;
142 return VA_STATUS_SUCCESS;
145 static VAStatus va_DisplayContextGetDriverName (
146 VADisplayContextP pDisplayContext,
150 VADriverContextP ctx = pDisplayContext->pDriverContext;
151 struct dri_state *dri_state = (struct dri_state *)ctx->dri_state;
152 char *driver_name_env;
153 int vendor_id, device_id;
159 char driver_name[64];
161 { 0x8086, 0x4100, "pvr" },
162 { 0x8086, 0x0130, "pvr" },
166 memset(dri_state, 0, sizeof(*dri_state));
167 dri_state->fd = drm_open_any(&vendor_id, &device_id);
169 if (dri_state->fd < 0) {
170 fprintf(stderr,"can't open DRM devices\n");
171 return VA_STATUS_ERROR_UNKNOWN;
174 /* TBD: other vendor driver names */
176 while (devices[i].device_id != 0) {
177 if ((devices[i].vendor_id == vendor_id) &&
178 (devices[i].device_id == device_id))
183 if (devices[i].device_id != 0)
184 *driver_name = strdup(devices[i].driver_name);
186 fprintf(stderr,"device (0x%04x:0x%04x) is not supported\n",
187 vendor_id, device_id);
189 return VA_STATUS_ERROR_UNKNOWN;
192 printf("DRM device is opened, loading driver %s for device 0x%04x:0x%04x\n",
193 driver_name, vendor_id, device_id);
195 dri_state->driConnectedFlag = VA_DUMMY;
197 return VA_STATUS_SUCCESS;
201 VADisplay vaGetDisplay (
202 void *native_dpy /* implementation specific */
205 VADisplay dpy = NULL;
206 VADisplayContextP pDisplayContext;
213 /* create new entry */
214 VADriverContextP pDriverContext;
215 struct dri_state *dri_state;
216 pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext));
217 pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext));
218 dri_state = (struct dri_state*)calloc(1, sizeof(*dri_state));
219 if (pDisplayContext && pDriverContext && dri_state)
221 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
223 pDriverContext->native_dpy = (void *)native_dpy;
224 pDisplayContext->pDriverContext = pDriverContext;
225 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
226 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
227 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
228 pDriverContext->dri_state = dri_state;
229 dpy = (VADisplay)pDisplayContext;
234 free(pDisplayContext);
236 free(pDriverContext);
245 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
246 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
251 extern int fool_postp; /* do nothing for vaPutSurface if set */
252 extern int trace_flag; /* trace vaPutSurface parameters */
254 void va_TracePutSurface (
257 void *draw, /* the target Drawable */
264 unsigned short destw,
265 unsigned short desth,
266 VARectangle *cliprects, /* client supplied clip list */
267 unsigned int number_cliprects, /* number of clip rects in the clip list */
268 unsigned int flags /* de-interlacing flags */
272 VAStatus vaPutSurface (
275 sp<ISurface> draw, /* Android Surface/Window */
282 unsigned short destw,
283 unsigned short desth,
284 VARectangle *cliprects, /* client supplied clip list */
285 unsigned int number_cliprects, /* number of clip rects in the clip list */
286 unsigned int flags /* de-interlacing flags */
289 VADriverContextP ctx;
292 return VA_STATUS_SUCCESS;
295 return VA_STATUS_ERROR_UNKNOWN;
300 VA_TRACE_LOG(va_TracePutSurface, dpy, surface, static_cast<void*>(&draw), srcx, srcy, srcw, srch,
301 destx, desty, destw, desth,
302 cliprects, number_cliprects, flags );
304 return ctx->vtable->vaPutSurface( ctx, surface, static_cast<void*>(&draw), srcx, srcy, srcw, srch,
305 destx, desty, destw, desth,
306 cliprects, number_cliprects, flags );