X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=va%2Fandroid%2Fva_android.cpp;h=6f0324bd545289f062dafc2cfc7ae138564387c7;hb=b1aa5568ad619eb5f526f653a15154c03f3bcb87;hp=11d193582612bf0a102313cd537304c2a6bedc63;hpb=085f5e3b74c3db11d5d8a769d4cc57c2a022bc86;p=android-x86%2Fhardware-intel-common-libva.git diff --git a/va/android/va_android.cpp b/va/android/va_android.cpp index 11d1935..6f0324b 100644 --- a/va/android/va_android.cpp +++ b/va/android/va_android.cpp @@ -23,276 +23,178 @@ */ #define _GNU_SOURCE 1 +#include "sysdeps.h" #include "va.h" #include "va_backend.h" +#include "va_trace.h" +#include "va_fool.h" #include "va_android.h" -#include "va_dricommon.h" /* needs some helper functions from this file */ -#include -#include +#include "va_drmcommon.h" +#include "va_drm_utils.h" #include -#include #include #include #include #include #include #include -#ifndef ANDROID -#include -#include "drm_test.h" -#endif -#define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; } -#define DEVICE_NAME "/dev/dri/card0" -static VADisplayContextP pDisplayContexts = NULL; +#define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; } +#define DEVICE_NAME "/dev/dri/renderD128" static int open_device (char *dev_name) { - struct stat st; - int fd; + struct stat st; + int fd; - if (-1 == stat (dev_name, &st)) + if (-1 == stat (dev_name, &st)) { - printf ("Cannot identify '%s': %d, %s\n", - dev_name, errno, strerror (errno)); - return -1; + printf ("Cannot identify '%s': %d, %s\n", + dev_name, errno, strerror (errno)); + return -1; } - if (!S_ISCHR (st.st_mode)) + if (!S_ISCHR (st.st_mode)) { - printf ("%s is no device\n", dev_name); - return -1; + printf ("%s is no device\n", dev_name); + return -1; } - fd = open (dev_name, O_RDWR); + fd = open (dev_name, O_RDWR); - if (-1 == fd) + if (-1 == fd) { - fprintf (stderr, "Cannot open '%s': %d, %s\n", - dev_name, errno, strerror (errno)); - return -1; + fprintf (stderr, "Cannot open '%s': %d, %s\n", + dev_name, errno, strerror (errno)); + return -1; } - return fd; + return fd; } static int va_DisplayContextIsValid ( VADisplayContextP pDisplayContext -) + ) { - VADisplayContextP ctx = pDisplayContexts; - - while (ctx) - { - if (ctx == pDisplayContext && pDisplayContext->pDriverContext) - return 1; - ctx = ctx->pNext; - } - return 0; + return (pDisplayContext != NULL && + pDisplayContext->pDriverContext != NULL); } static void va_DisplayContextDestroy ( VADisplayContextP pDisplayContext ) { - VADisplayContextP *ctx = &pDisplayContexts; + struct drm_state *drm_state; - /* Throw away pDisplayContext */ - while (*ctx) - { - if (*ctx == pDisplayContext) - { - *ctx = pDisplayContext->pNext; - pDisplayContext->pNext = NULL; - break; - } - ctx = &((*ctx)->pNext); - } - free(pDisplayContext->pDriverContext->dri_state); + if (pDisplayContext == NULL) + return; + + /* close the open-ed DRM fd */ + drm_state = (struct drm_state *)pDisplayContext->pDriverContext->drm_state; + close(drm_state->fd); + + free(pDisplayContext->pDriverContext->drm_state); free(pDisplayContext->pDriverContext); free(pDisplayContext); } -#ifdef ANDROID static VAStatus va_DisplayContextGetDriverName ( VADisplayContextP pDisplayContext, char **driver_name ) { - VADriverContextP ctx = pDisplayContext->pDriverContext; - struct dri_state *dri_state = (struct dri_state *)ctx->dri_state; - char *driver_name_env; - int vendor_id, device_id; - - struct { - int vendor_id; - int device_id; - char driver_name[64]; - } devices[] = { - { 0x8086, 0x4100, "pvr" }, - { 0x8086, 0x0130, "pvr" }, - { 0x0, 0x0, "\0" }, - }; - - memset(dri_state, 0, sizeof(*dri_state)); - dri_state->fd = open_device(DEVICE_NAME); - - if (dri_state->fd < 0) { - fprintf(stderr,"can't open DRM devices\n"); - return VA_STATUS_ERROR_UNKNOWN; - } + VADriverContextP const ctx = pDisplayContext->pDriverContext; + struct drm_state * drm_state = (struct drm_state *)ctx->drm_state; - if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL - && geteuid() == getuid()) { - /* don't allow setuid apps to use LIBVA_DRIVER_NAME */ - *driver_name = strdup(driver_name_env); - return VA_STATUS_SUCCESS; - } else { /* TBD: other vendor driver names */ - vendor_id = devices[0].vendor_id; - device_id = devices[0].device_id; - *driver_name = strdup(devices[0].driver_name); - } + memset(drm_state, 0, sizeof(*drm_state)); + drm_state->fd = open_device((char *)DEVICE_NAME); - dri_state->driConnectedFlag = VA_DUMMY; - - return VA_STATUS_SUCCESS; -} -#else -static VAStatus va_DisplayContextGetDriverName ( - VADisplayContextP pDisplayContext, - char **driver_name -) -{ - VADriverContextP ctx = pDisplayContext->pDriverContext; - struct dri_state *dri_state = (struct dri_state *)ctx->dri_state; - char *driver_name_env; - int vendor_id, device_id; - - struct { - int vendor_id; - int device_id; - char driver_name[64]; - } devices[] = { - { 0x8086, 0x4100, "pvr" }, - { 0x8086, 0x0130, "pvr" }, - { 0x0, 0x0, "\0" }, - }; - - memset(dri_state, 0, sizeof(*dri_state)); - dri_state->fd = drm_open_any(&vendor_id, &device_id); - - if (dri_state->fd < 0) { + if (drm_state->fd < 0) { fprintf(stderr,"can't open DRM devices\n"); return VA_STATUS_ERROR_UNKNOWN; } - - if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL - && geteuid() == getuid()) { - /* don't allow setuid apps to use LIBVA_DRIVER_NAME */ - *driver_name = strdup(driver_name_env); - return VA_STATUS_SUCCESS; - } else { /* TBD: other vendor driver names */ - int i = 0; - - while (devices[i].device_id != 0) { - if ((devices[i].vendor_id == vendor_id) && - (devices[i].device_id == device_id)) - break; - i++; - } - - if (devices[i].device_id != 0) - *driver_name = strdup(devices[i].driver_name); - else { - fprintf(stderr,"device (0x%04x:0x%04x) is not supported\n", - vendor_id, device_id); - - return VA_STATUS_ERROR_UNKNOWN; - } - } + drm_state->auth_type = VA_DRM_AUTH_CUSTOM; - printf("DRM device is opened, loading driver %s for device 0x%04x:0x%04x\n", - driver_name, vendor_id, device_id); - - dri_state->driConnectedFlag = VA_DUMMY; - - return VA_STATUS_SUCCESS; + return VA_DRM_GetDriverName(ctx, driver_name); } -#endif + VADisplay vaGetDisplay ( void *native_dpy /* implementation specific */ ) { - VADisplay dpy = NULL; - VADisplayContextP pDisplayContext = pDisplayContexts; - - if (!native_dpy) - return NULL; - - while (pDisplayContext) - { - if (pDisplayContext->pDriverContext && - pDisplayContext->pDriverContext->native_dpy == (void *)native_dpy) - { - dpy = (VADisplay)pDisplayContext; - break; - } - pDisplayContext = pDisplayContext->pNext; - } - - - if (!dpy) - { - /* create new entry */ - VADriverContextP pDriverContext; - struct dri_state *dri_state; - pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext)); - pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext)); - dri_state = (struct dri_state*)calloc(1, sizeof(*dri_state)); - if (pDisplayContext && pDriverContext && dri_state) - { - pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC; - - pDriverContext->native_dpy = (void *)native_dpy; - pDisplayContext->pNext = pDisplayContexts; - pDisplayContext->pDriverContext = pDriverContext; - pDisplayContext->vaIsValid = va_DisplayContextIsValid; - pDisplayContext->vaDestroy = va_DisplayContextDestroy; - pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; - pDisplayContexts = pDisplayContext; - pDriverContext->dri_state = dri_state; - dpy = (VADisplay)pDisplayContext; - } - else - { - if (pDisplayContext) - free(pDisplayContext); - if (pDriverContext) - free(pDriverContext); - if (dri_state) - free(dri_state); - } - } + VADisplay dpy = NULL; + VADisplayContextP pDisplayContext; + + if (!native_dpy) + return NULL; + + if (!dpy) + { + /* create new entry */ + VADriverContextP pDriverContext = 0; + struct drm_state *drm_state = 0; + pDisplayContext = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext)); + pDriverContext = (VADriverContextP)calloc(1, sizeof(*pDriverContext)); + drm_state = (struct drm_state*)calloc(1, sizeof(*drm_state)); + if (pDisplayContext && pDriverContext && drm_state) + { + pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC; + + pDriverContext->native_dpy = (void *)native_dpy; + pDriverContext->display_type = VA_DISPLAY_ANDROID; + pDisplayContext->pDriverContext = pDriverContext; + pDisplayContext->vaIsValid = va_DisplayContextIsValid; + pDisplayContext->vaDestroy = va_DisplayContextDestroy; + pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; + pDriverContext->drm_state = drm_state; + dpy = (VADisplay)pDisplayContext; + } + else + { + if (pDisplayContext) + free(pDisplayContext); + if (pDriverContext) + free(pDriverContext); + if (drm_state) + free(drm_state); + } + } - return dpy; + return dpy; } #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext) #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; } -static int vaDisplayIsValid(VADisplay dpy) -{ - VADisplayContextP pDisplayContext = (VADisplayContextP)dpy; - return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext); + +extern "C" { + extern int fool_postp; /* do nothing for vaPutSurface if set */ + extern int trace_flag; /* trace vaPutSurface parameters */ + + void va_TracePutSurface ( + VADisplay dpy, + VASurfaceID surface, + void *draw, /* the target Drawable */ + short srcx, + short srcy, + unsigned short srcw, + unsigned short srch, + short destx, + short desty, + unsigned short destw, + unsigned short desth, + VARectangle *cliprects, /* client supplied clip list */ + unsigned int number_cliprects, /* number of clip rects in the clip list */ + unsigned int flags /* de-interlacing flags */ + ); } -#ifdef ANDROID VAStatus vaPutSurface ( VADisplay dpy, VASurfaceID surface, - sp draw, /* Android Surface/Window */ + sp draw, /* Android Native Window */ short srcx, short srcy, unsigned short srcw, @@ -306,13 +208,22 @@ VAStatus vaPutSurface ( unsigned int flags /* de-interlacing flags */ ) { - VADriverContextP ctx; + VADriverContextP ctx; - CHECK_DISPLAY(dpy); - ctx = CTX(dpy); - return ctx->vtable.vaPutSurface( ctx, surface, static_cast(&draw), srcx, srcy, srcw, srch, - destx, desty, destw, desth, - cliprects, number_cliprects, flags ); -} + if (fool_postp) + return VA_STATUS_SUCCESS; + + if (draw == NULL) + return VA_STATUS_ERROR_UNKNOWN; -#endif + CHECK_DISPLAY(dpy); + ctx = CTX(dpy); + + VA_TRACE_LOG(va_TracePutSurface, dpy, surface, static_cast(&draw), srcx, srcy, srcw, srch, + destx, desty, destw, desth, + cliprects, number_cliprects, flags ); + + return ctx->vtable->vaPutSurface( ctx, surface, static_cast(&draw), srcx, srcy, srcw, srch, + destx, desty, destw, desth, + cliprects, number_cliprects, flags ); +}