diff options
Diffstat (limited to 'src/xvmc/intel_xvmc.c')
-rw-r--r-- | src/xvmc/intel_xvmc.c | 146 |
1 files changed, 58 insertions, 88 deletions
diff --git a/src/xvmc/intel_xvmc.c b/src/xvmc/intel_xvmc.c index 76302d92..71ae77b4 100644 --- a/src/xvmc/intel_xvmc.c +++ b/src/xvmc/intel_xvmc.c @@ -100,21 +100,12 @@ unsigned int mb_bytes_420[] = { int DEBUG; -static int error_base; -static int event_base; - static void intel_xvmc_debug_init(void) { if (getenv("INTEL_XVMC_DEBUG")) DEBUG = 1; } -/* locking */ -static void intel_xvmc_try_heavy_lock(drm_context_t ctx) -{ - drmGetLock(xvmc_driver->fd, ctx, 0); -} - void LOCK_HARDWARE(drm_context_t ctx) { char __ret = 0; @@ -122,19 +113,13 @@ void LOCK_HARDWARE(drm_context_t ctx) PPTHREAD_MUTEX_LOCK(); assert(!xvmc_driver->locked); - DRM_CAS(xvmc_driver->driHwLock, ctx, - (DRM_LOCK_HELD | ctx), __ret); - - if (__ret) - intel_xvmc_try_heavy_lock(ctx); - xvmc_driver->locked = 1; } void UNLOCK_HARDWARE(drm_context_t ctx) { xvmc_driver->locked = 0; - DRM_UNLOCK(xvmc_driver->fd, xvmc_driver->driHwLock, ctx); + PPTHREAD_MUTEX_UNLOCK(); } @@ -269,17 +254,18 @@ _X_EXPORT Status XvMCCreateContext(Display *display, XvPortID port, int flags, XvMCContext *context) { Status ret; - drm_sarea_t *pSAREA; - char *curBusID; CARD32 *priv_data = NULL; struct _intel_xvmc_common *comm; drm_magic_t magic; int major, minor; + int error_base; + int event_base; int priv_count; int isCapable; int screen = DefaultScreen(display); intel_xvmc_context_ptr intel_ctx; int fd; + char *driverName = NULL, *deviceName = NULL; /* Verify Obvious things first */ if (!display || !context) @@ -356,7 +342,6 @@ _X_EXPORT Status XvMCCreateContext(Display *display, XvPortID port, XVMC_INFO("decoder type is %s", intel_xvmc_decoder_string(comm->type)); - xvmc_driver->sarea_size = comm->sarea_size; xvmc_driver->batchbuffer.handle = comm->batchbuffer.handle; xvmc_driver->batchbuffer.offset = comm->batchbuffer.offset; xvmc_driver->batchbuffer.size = comm->batchbuffer.size; @@ -369,70 +354,60 @@ _X_EXPORT Status XvMCCreateContext(Display *display, XvPortID port, } intel_ctx->context = context; - ret = uniDRIQueryDirectRenderingCapable(display, screen, - &isCapable); - if (!ret || !isCapable) { - XVMC_ERR("Direct Rendering is not available on this system!"); - XFree(priv_data); - return BadValue; - } + /* check DRI2 */ + ret = Success; + xvmc_driver->fd = -1; - if (!uniDRIOpenConnection(display, screen, - &xvmc_driver->hsarea, &curBusID)) { - XVMC_ERR("Could not open DRI connection to X server!"); - XFree(priv_data); - return BadValue; - } + do { + if (!DRI2QueryExtension(display, &event_base, &error_base)) { + ret = BadValue; + break; + } + + if (!DRI2QueryVersion(display, &major, &minor)) { + ret = BadValue; + break; + } + + if (!DRI2Connect(display, RootWindow(display, screen), + &driverName, &deviceName)) { + ret = BadValue; + break; + } + + xvmc_driver->fd = open(deviceName, O_RDWR); + + if (xvmc_driver->fd < 0) { + XVMC_ERR("Failed to open drm device: %s\n", strerror(errno)); + ret = BadValue; + break; + } + + if (drmGetMagic(xvmc_driver->fd, &magic)) { + XVMC_ERR("Failed to get magic\n"); + ret = BadValue; + break; + } + + if (!DRI2Authenticate(display, RootWindow(display, screen), magic)) { + XVMC_ERR("Failed to authenticate magic %d\n", magic); + ret = BadValue; + break; + } + } while (0); + + XFree(driverName); + XFree(deviceName); - /* Open DRI Device */ - if((fd = drmOpen("i915", curBusID)) < 0) { - XVMC_ERR("DRM Device could not be opened."); + if (ret != Success) { XFree(priv_data); - XFree(curBusID); - return BadValue; - } - - xvmc_driver->fd = fd; - - strncpy(xvmc_driver->busID, curBusID, 20); - xvmc_driver->busID[20] = '\0'; - XFree(curBusID); - - /* Get magic number */ - drmGetMagic(xvmc_driver->fd, &magic); - // context->flags = (unsigned long)magic; - - if (!uniDRIAuthConnection(display, screen, magic)) { - XVMC_ERR("[XvMC]: X server did not allow DRI. Check permissions."); - xvmc_driver = NULL; - XFree(priv_data); - return BadAlloc; - } + context->privData = NULL; - /* - * Map DRI Sarea. we always want it right? - */ - if (drmMap(xvmc_driver->fd, xvmc_driver->hsarea, - xvmc_driver->sarea_size, &xvmc_driver->sarea_address) < 0) { - XVMC_ERR("Unable to map DRI SAREA.\n"); - xvmc_driver = NULL; - XFree(priv_data); - return BadAlloc; - } - pSAREA = (drm_sarea_t *)xvmc_driver->sarea_address; - xvmc_driver->driHwLock = (drmLock *)&pSAREA->lock; - pthread_mutex_init(&xvmc_driver->ctxmutex, NULL); + if (xvmc_driver->fd >= 0) + close(xvmc_driver->fd); - /* context_id is alloc in _xvmc_create_context */ - if (!uniDRICreateContext(display, screen, DefaultVisual(display, screen), - context->context_id, - &intel_ctx->hw_context)) { - XVMC_ERR("Could not create DRI context for xvmc ctx %d.", - (int)context->context_id); - XFree(priv_data); - context->privData = NULL; - drmUnmap(xvmc_driver->sarea_address, xvmc_driver->sarea_size); - return BadAlloc; + xvmc_driver = NULL; + return ret; } /* call driver hook. @@ -441,12 +416,13 @@ _X_EXPORT Status XvMCCreateContext(Display *display, XvPortID port, if (ret) { XVMC_ERR("driver create context failed\n"); XFree(priv_data); - drmUnmap(xvmc_driver->sarea_address, xvmc_driver->sarea_size); + context->privData = NULL; + xvmc_driver = NULL; return ret; } + pthread_mutex_init(&xvmc_driver->ctxmutex, NULL); intelInitBatchBuffer(); - intel_xvmc_dump_open(); return Success; @@ -475,7 +451,6 @@ _X_EXPORT Status XvMCDestroyContext(Display *display, XvMCContext *context) return ret; } - uniDRIDestroyContext(display, screen, context->context_id); intel_xvmc_free_context(context->context_id); ret = _xvmc_destroy_context(display, context); @@ -485,18 +460,13 @@ _X_EXPORT Status XvMCDestroyContext(Display *display, XvMCContext *context) } if (xvmc_driver->num_ctx == 0) { - uniDRICloseConnection(display, screen); - pthread_mutex_destroy(&xvmc_driver->ctxmutex); - drmUnmap(xvmc_driver->sarea_address, xvmc_driver->sarea_size); - if (xvmc_driver->fd >= 0) - drmClose(xvmc_driver->fd); + close(xvmc_driver->fd); + xvmc_driver->fd = -1; - intelFiniBatchBuffer(); - intel_xvmc_dump_close(); } return Success; |