OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2007 Intel Corporation. All Rights Reserved. |
| 3 * |
| 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: |
| 11 * |
| 12 * The above copyright notice and this permission notice (including the |
| 13 * next paragraph) shall be included in all copies or substantial portions |
| 14 * of the Software. |
| 15 * |
| 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. |
| 23 */ |
| 24 |
| 25 #define _GNU_SOURCE 1 |
| 26 #include "va.h" |
| 27 #include "va_backend.h" |
| 28 #include "va_trace.h" |
| 29 #include "va_fool.h" |
| 30 #include "va_android.h" |
| 31 #include "va_dricommon.h" /* needs some helper functions from this file */ |
| 32 #include <stdio.h> |
| 33 #include <stdlib.h> |
| 34 #include <stdarg.h> |
| 35 #include <string.h> |
| 36 #include <unistd.h> |
| 37 #include <sys/types.h> |
| 38 #include <sys/stat.h> |
| 39 #include <fcntl.h> |
| 40 #include <dlfcn.h> |
| 41 #include <errno.h> |
| 42 #ifndef ANDROID |
| 43 #include <libudev.h> |
| 44 #include "drmtest.h" |
| 45 #endif |
| 46 |
| 47 #define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); re
turn VA_STATUS_ERROR_UNKNOWN; } |
| 48 #define DEVICE_NAME "/dev/card0" |
| 49 |
| 50 static int open_device (char *dev_name) |
| 51 { |
| 52 struct stat st; |
| 53 int fd; |
| 54 |
| 55 if (-1 == stat (dev_name, &st)) |
| 56 { |
| 57 printf ("Cannot identify '%s': %d, %s\n", |
| 58 dev_name, errno, strerror (errno)); |
| 59 return -1; |
| 60 } |
| 61 |
| 62 if (!S_ISCHR (st.st_mode)) |
| 63 { |
| 64 printf ("%s is no device\n", dev_name); |
| 65 return -1; |
| 66 } |
| 67 |
| 68 fd = open (dev_name, O_RDWR); |
| 69 |
| 70 if (-1 == fd) |
| 71 { |
| 72 fprintf (stderr, "Cannot open '%s': %d, %s\n", |
| 73 dev_name, errno, strerror (errno)); |
| 74 return -1; |
| 75 } |
| 76 |
| 77 return fd; |
| 78 } |
| 79 |
| 80 static int va_DisplayContextIsValid ( |
| 81 VADisplayContextP pDisplayContext |
| 82 ) |
| 83 { |
| 84 return (pDisplayContext != NULL && |
| 85 pDisplayContext->pDriverContext != NULL); |
| 86 } |
| 87 |
| 88 static void va_DisplayContextDestroy ( |
| 89 VADisplayContextP pDisplayContext |
| 90 ) |
| 91 { |
| 92 struct dri_state *dri_state; |
| 93 |
| 94 if (pDisplayContext == NULL) |
| 95 return; |
| 96 |
| 97 /* close the open-ed DRM fd */ |
| 98 dri_state = (struct dri_state *)pDisplayContext->pDriverContext->dri_state; |
| 99 close(dri_state->fd); |
| 100 |
| 101 free(pDisplayContext->pDriverContext->dri_state); |
| 102 free(pDisplayContext->pDriverContext); |
| 103 free(pDisplayContext); |
| 104 } |
| 105 |
| 106 #ifdef ANDROID |
| 107 static VAStatus va_DisplayContextGetDriverName ( |
| 108 VADisplayContextP pDisplayContext, |
| 109 char **driver_name |
| 110 ) |
| 111 { |
| 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; |
| 116 |
| 117 struct { |
| 118 int vendor_id; |
| 119 int device_id; |
| 120 char driver_name[64]; |
| 121 } devices[] = { |
| 122 { 0x8086, 0x4100, "pvr" }, |
| 123 { 0x8086, 0x0130, "pvr" }, |
| 124 { 0x0, 0x0, "\0" }, |
| 125 }; |
| 126 |
| 127 memset(dri_state, 0, sizeof(*dri_state)); |
| 128 dri_state->fd = open_device((char *)DEVICE_NAME); |
| 129 |
| 130 if (dri_state->fd < 0) { |
| 131 fprintf(stderr,"can't open DRM devices\n"); |
| 132 return VA_STATUS_ERROR_UNKNOWN; |
| 133 } |
| 134 |
| 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); |
| 139 |
| 140 dri_state->driConnectedFlag = VA_DUMMY; |
| 141 |
| 142 return VA_STATUS_SUCCESS; |
| 143 } |
| 144 #else |
| 145 static VAStatus va_DisplayContextGetDriverName ( |
| 146 VADisplayContextP pDisplayContext, |
| 147 char **driver_name |
| 148 ) |
| 149 { |
| 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; |
| 154 int i = 0; |
| 155 |
| 156 struct { |
| 157 int vendor_id; |
| 158 int device_id; |
| 159 char driver_name[64]; |
| 160 } devices[] = { |
| 161 { 0x8086, 0x4100, "pvr" }, |
| 162 { 0x8086, 0x0130, "pvr" }, |
| 163 { 0x0, 0x0, "\0" }, |
| 164 }; |
| 165 |
| 166 memset(dri_state, 0, sizeof(*dri_state)); |
| 167 dri_state->fd = drm_open_any(&vendor_id, &device_id); |
| 168 |
| 169 if (dri_state->fd < 0) { |
| 170 fprintf(stderr,"can't open DRM devices\n"); |
| 171 return VA_STATUS_ERROR_UNKNOWN; |
| 172 } |
| 173 |
| 174 /* TBD: other vendor driver names */ |
| 175 |
| 176 while (devices[i].device_id != 0) { |
| 177 if ((devices[i].vendor_id == vendor_id) && |
| 178 (devices[i].device_id == device_id)) |
| 179 break; |
| 180 i++; |
| 181 } |
| 182 |
| 183 if (devices[i].device_id != 0) |
| 184 *driver_name = strdup(devices[i].driver_name); |
| 185 else { |
| 186 fprintf(stderr,"device (0x%04x:0x%04x) is not supported\n", |
| 187 vendor_id, device_id); |
| 188 |
| 189 return VA_STATUS_ERROR_UNKNOWN; |
| 190 } |
| 191 |
| 192 printf("DRM device is opened, loading driver %s for device 0x%04x:0x%04x\n", |
| 193 driver_name, vendor_id, device_id); |
| 194 |
| 195 dri_state->driConnectedFlag = VA_DUMMY; |
| 196 |
| 197 return VA_STATUS_SUCCESS; |
| 198 } |
| 199 #endif |
| 200 |
| 201 VADisplay vaGetDisplay ( |
| 202 void *native_dpy /* implementation specific */ |
| 203 ) |
| 204 { |
| 205 VADisplay dpy = NULL; |
| 206 VADisplayContextP pDisplayContext; |
| 207 |
| 208 if (!native_dpy) |
| 209 return NULL; |
| 210 |
| 211 if (!dpy) |
| 212 { |
| 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) |
| 220 { |
| 221 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC; |
| 222 |
| 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; |
| 230 } |
| 231 else |
| 232 { |
| 233 if (pDisplayContext) |
| 234 free(pDisplayContext); |
| 235 if (pDriverContext) |
| 236 free(pDriverContext); |
| 237 if (dri_state) |
| 238 free(dri_state); |
| 239 } |
| 240 } |
| 241 |
| 242 return dpy; |
| 243 } |
| 244 |
| 245 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext) |
| 246 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR
_INVALID_DISPLAY; } |
| 247 |
| 248 |
| 249 #ifdef ANDROID |
| 250 extern "C" { |
| 251 extern int fool_postp; /* do nothing for vaPutSurface if set */ |
| 252 extern int trace_flag; /* trace vaPutSurface parameters */ |
| 253 |
| 254 void va_TracePutSurface ( |
| 255 VADisplay dpy, |
| 256 VASurfaceID surface, |
| 257 void *draw, /* the target Drawable */ |
| 258 short srcx, |
| 259 short srcy, |
| 260 unsigned short srcw, |
| 261 unsigned short srch, |
| 262 short destx, |
| 263 short desty, |
| 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 */ |
| 269 ); |
| 270 } |
| 271 |
| 272 VAStatus vaPutSurface ( |
| 273 VADisplay dpy, |
| 274 VASurfaceID surface, |
| 275 sp<ISurface> draw, /* Android Surface/Window */ |
| 276 short srcx, |
| 277 short srcy, |
| 278 unsigned short srcw, |
| 279 unsigned short srch, |
| 280 short destx, |
| 281 short desty, |
| 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 */ |
| 287 ) |
| 288 { |
| 289 VADriverContextP ctx; |
| 290 |
| 291 if (fool_postp) |
| 292 return VA_STATUS_SUCCESS; |
| 293 |
| 294 if (draw == NULL) |
| 295 return VA_STATUS_ERROR_UNKNOWN; |
| 296 |
| 297 CHECK_DISPLAY(dpy); |
| 298 ctx = CTX(dpy); |
| 299 |
| 300 VA_TRACE_LOG(va_TracePutSurface, dpy, surface, static_cast<void*>(&draw), sr
cx, srcy, srcw, srch, |
| 301 destx, desty, destw, desth, |
| 302 cliprects, number_cliprects, flags ); |
| 303 |
| 304 return ctx->vtable->vaPutSurface( ctx, surface, static_cast<void*>(&draw), s
rcx, srcy, srcw, srch, |
| 305 destx, desty, destw, desth, |
| 306 cliprects, number_cliprects, flags ); |
| 307 } |
| 308 #endif |
OLD | NEW |