diff options
author | Zhenyu Wang <zhenyu.z.wang@intel.com> | 2007-09-26 13:45:42 +0800 |
---|---|---|
committer | Zhenyu Wang <zhenyu.z.wang@intel.com> | 2007-09-26 13:45:42 +0800 |
commit | 513e8a2f8abde1b11b8058e94a650796fd51779b (patch) | |
tree | de56a5cfaf0c41c669b0160864fac9344ec04d70 /src | |
parent | 798448e4641acf241b7cbae0d6c243ae383da9f4 (diff) |
Create xvmc driver interface
convert i915 to new xvmc driver interface
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/i830_driver.c | 10 | ||||
-rw-r--r-- | src/i830_hwmc.c | 106 | ||||
-rw-r--r-- | src/i830_hwmc.h | 58 | ||||
-rw-r--r-- | src/i830_video.c | 19 | ||||
-rw-r--r-- | src/i915_hwmc.c | 78 |
6 files changed, 209 insertions, 64 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 1c29a1e6..c62b8250 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -59,6 +59,8 @@ INTEL_DRI_SRCS = \ i810_dri.h \ i830_dri.c \ i810_hwmc.c \ + i830_hwmc.h \ + i830_hwmc.c \ i915_hwmc.c \ i915_hwmc.h \ i830_dri.h diff --git a/src/i830_driver.c b/src/i830_driver.c index 5a242b43..7f8921ac 100644 --- a/src/i830_driver.c +++ b/src/i830_driver.c @@ -197,6 +197,10 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #include "i830_debug.h" #include "i830_bios.h" +#ifdef XvMCExtension +#include "i830_hwmc.h" +#endif + #ifdef XF86DRI #include "dri.h" #include <sys/ioctl.h> @@ -2970,6 +2974,12 @@ i830AdjustFrame(int scrnIndex, int x, int y, int flags) static void I830FreeScreen(int scrnIndex, int flags) { +#ifdef XvMCExtension + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + I830Ptr pI830 = I830PTR(pScrn); + if (pI830->XvMCEnabled) + intel_xvmc_finish(xf86Screens[scrnIndex]); +#endif I830FreeRec(xf86Screens[scrnIndex]); if (xf86LoaderCheckSymbol("vgaHWFreeHWRec")) vgaHWFreeHWRec(xf86Screens[scrnIndex]); diff --git a/src/i830_hwmc.c b/src/i830_hwmc.c new file mode 100644 index 00000000..e51445b6 --- /dev/null +++ b/src/i830_hwmc.c @@ -0,0 +1,106 @@ +/* + * Copyright © 2007 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Authors: + * Zhenyu Wang <zhenyu.z.wang@intel.com> + * + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "i830.h" +#include "i830_hwmc.h" + +struct intel_xvmc_driver *xvmc_driver; + +/* set global current driver for xvmc */ +Bool intel_xvmc_set_driver(struct intel_xvmc_driver *d) +{ + if (xvmc_driver) { + ErrorF("XvMC driver already set!\n"); + return FALSE; + } else + xvmc_driver = d; + return TRUE; +} + +/* check chip type and load xvmc driver */ +/* This must be first called! */ +Bool intel_xvmc_probe(ScrnInfoPtr pScrn) +{ + I830Ptr pI830 = I830PTR(pScrn); + Bool ret = FALSE; + + if (IS_I9XX(pI830)) { + if (!IS_I965G(pI830)) + ret = intel_xvmc_set_driver(&i915_xvmc_driver); + else + ret = intel_xvmc_set_driver(&i965_xvmc_driver); + if (ret) + pI830->XvMCEnabled = TRUE; + } else { + ErrorF("Your chipset doesn't support XvMC.\n"); + return FALSE; + } + return TRUE; +} + +void intel_xvmc_finish(ScrnInfoPtr pScrn) +{ + if (!xvmc_driver) + return; + (*xvmc_driver->fini)(pScrn); +} + +Bool intel_xvmc_init(ScreenPtr pScreen, XF86VideoAdaptorPtr xv_adaptor) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + I830Ptr pI830 = I830PTR(pScrn); + + if (!xvmc_driver) { + ErrorF("Failed to probe XvMC driver.\n"); + return FALSE; + } + + if (!(*xvmc_driver->init)(pScrn, xv_adaptor)) { + ErrorF("XvMC driver initialize failed.\n"); + return FALSE; + } + + if (xf86XvMCScreenInit(pScreen, 1, &xvmc_driver->adaptor)) { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "[XvMC] Initialized XvMC.\n"); + } else { + intel_xvmc_finish(pScrn); + pI830->XvMCEnabled = FALSE; + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "[XvMC] Failed to initialize XvMC.\n"); + return FALSE; + } + return TRUE; +} + +int intel_xvmc_putimage_size(ScrnInfoPtr pScrn) +{ + return (*xvmc_driver->putimage_size)(pScrn); +} diff --git a/src/i830_hwmc.h b/src/i830_hwmc.h new file mode 100644 index 00000000..a316af22 --- /dev/null +++ b/src/i830_hwmc.h @@ -0,0 +1,58 @@ +/* + * Copyright © 2007 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Authors: + * Zhenyu Wang <zhenyu.z.wang@intel.com> + * + */ +#ifndef I830_HWMC_H +#define I830_HWMC_H + +#include <xf86xvmc.h> + +#define XVMC_DRIVER_MPEG2_MC 0x0001 +#define XVMC_DRIVER_MPEG2_VLD 0x0002 +#define XVMC_DRIVER_H264_MC 0x0004 +#define XVMC_DRIVER_H264_VLD 0x0008 + +struct intel_xvmc_driver { + char *name; + XF86MCAdaptorPtr adaptor; + unsigned int flag; + /* more items for xvmv surface manage? */ + Bool (*init)(ScrnInfoPtr, XF86VideoAdaptorPtr); + void (*fini)(ScrnInfoPtr); + int (*putimage_size)(ScrnInfoPtr); + void* devPrivate; +}; + +extern struct intel_xvmc_driver *xvmc_driver; +extern struct intel_xvmc_driver i915_xvmc_driver; +extern struct intel_xvmc_driver i965_xvmc_driver; + +extern Bool intel_xvmc_set_driver(struct intel_xvmc_driver *); +extern Bool intel_xvmc_probe(ScrnInfoPtr); +extern Bool intel_xvmc_init(ScreenPtr, XF86VideoAdaptorPtr); +extern void intel_xvmc_finish(ScrnInfoPtr); +extern int intel_xvmc_putimage_size(ScrnInfoPtr); + +#endif diff --git a/src/i830_video.c b/src/i830_video.c index ff12fa8d..b0d42f0d 100644 --- a/src/i830_video.c +++ b/src/i830_video.c @@ -74,7 +74,10 @@ #include "dixstruct.h" #include "fourcc.h" +#ifdef XvMCExtension +#include "i830_hwmc.h" #include "i915_hwmc.h" +#endif #ifndef USE_USLEEP_FOR_VIDEO #define USE_USLEEP_FOR_VIDEO 0 @@ -557,7 +560,6 @@ I830InitVideo(ScreenPtr pScreen) XF86VideoAdaptorPtr *adaptors, *newAdaptors = NULL; XF86VideoAdaptorPtr overlayAdaptor = NULL, texturedAdaptor = NULL; int num_adaptors; - Bool xvmc_init = FALSE; #if 0 { @@ -621,18 +623,16 @@ I830InitVideo(ScreenPtr pScreen) I830InitOffscreenImages(pScreen); } -#ifdef XvMCExtension - if (texturedAdaptor) - xvmc_init = I915XvMCInit(pScreen, texturedAdaptor); -#endif if (num_adaptors) xf86XVScreenInit(pScreen, adaptors, num_adaptors); - xfree(adaptors); #ifdef XvMCExtension - if (xvmc_init) - I915XvMCScreenInit(pScreen); + if (intel_xvmc_probe(pScrn)) { + if (texturedAdaptor) + intel_xvmc_init(pScreen, texturedAdaptor); + } #endif + xfree(adaptors); } static void @@ -2283,6 +2283,7 @@ I830PutImage(ScrnInfoPtr pScrn, switch (id) { case FOURCC_YV12: case FOURCC_I420: + //XXX if (pI830->IsXvMCSurface) { srcPitch = (width + 0x3ff) & ~0x3ff; srcPitch2 = ((width >> 1) + 0x3ff) & ~0x3ff; @@ -2546,7 +2547,7 @@ I830QueryImageAttributes(ScrnInfoPtr pScrn, break; case FOURCC_XVMC: *h = (*h + 1) & ~1; - size = I915XvMCPutImageSize(pScrn); + size = intel_xvmc_putimage_size(pScrn); if (pitches) pitches[0] = size; break; diff --git a/src/i915_hwmc.c b/src/i915_hwmc.c index 7a8a0730..32a08795 100644 --- a/src/i915_hwmc.c +++ b/src/i915_hwmc.c @@ -55,6 +55,7 @@ #include "xf86xvpriv.h" #endif +#include "i830_hwmc.h" #include "i915_hwmc.h" #define I915_XVMC_MAX_BUFFERS 2 @@ -195,11 +196,6 @@ static XF86MCAdaptorRec pAdapt = (xf86XvMCDestroySubpictureProcPtr)I915XvMCDestroySubpicture }; -static XF86MCAdaptorPtr ppAdapt[1] = -{ - (XF86MCAdaptorPtr)&pAdapt -}; - /* * Init and clean up the screen private parts of XvMC. */ @@ -220,14 +216,12 @@ static void initI915XvMC(I915XvMCPtr xvmc) xvmc->nsurfaces = 0; } -//XXX -static void cleanupI915XvMC(I915XvMCPtr xvmc, XF86VideoAdaptorPtr * XvAdaptors, int XvAdaptorCount) +static void cleanupI915XvMC(I915XvMCPtr xvmc) { - unsigned int i; + int i; for (i = 0; i < I915_XVMC_MAX_CONTEXTS; i++) { xvmc->contexts[i] = 0; - if (xvmc->ctxprivs[i]) { xfree(xvmc->ctxprivs[i]); xvmc->ctxprivs[i] = NULL; @@ -236,7 +230,6 @@ static void cleanupI915XvMC(I915XvMCPtr xvmc, XF86VideoAdaptorPtr * XvAdaptors, for (i = 0; i < I915_XVMC_MAX_SURFACES; i++) { xvmc->surfaces[i] = 0; - if (xvmc->sfprivs[i]) { xfree(xvmc->sfprivs[i]); xvmc->sfprivs[i] = NULL; @@ -857,36 +850,22 @@ static int I915XvMCPutImage(ScrnInfoPtr pScrn, short src_x, short src_y, return ret; } -/*********************************** Public Function **************************************/ - -/************************************************************************** - * - * I915InitMC - * - * Inputs: - * Screen pointer - * - * Outputs: - * None - * - **************************************************************************/ +static int i915_xvmc_putimage_size(ScrnInfoPtr pScrn) +{ + return sizeof(I915XvMCCommandBuffer); +} -Bool I915XvMCInit(ScreenPtr pScreen, XF86VideoAdaptorPtr XvAdapt) +static Bool i915_xvmc_init(ScrnInfoPtr pScrn, XF86VideoAdaptorPtr XvAdapt) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - I830Ptr pI830 = I830PTR(pScrn); I915XvMCPtr pXvMC; - if (!IS_I9XX(pI830) || IS_I965G(pI830)) - return FALSE; - pXvMC = (I915XvMCPtr)xcalloc(1, sizeof(I915XvMC)); if (!pXvMC) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "[XvMC] alloc driver private failed!\n"); return FALSE; } - pI830->xvmc = pXvMC; + xvmc_driver->devPrivate = (void*)pXvMC; initI915XvMC(pXvMC); /* set up wrappers */ @@ -895,32 +874,21 @@ Bool I915XvMCInit(ScreenPtr pScreen, XF86VideoAdaptorPtr XvAdapt) return TRUE; } -Bool I915XvMCScreenInit(ScreenPtr pScreen) +static void i915_xvmc_fini(ScrnInfoPtr pScrn) { - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - I830Ptr pI830 = I830PTR(pScrn); + I915XvMCPtr pXvMC = (I915XvMCPtr)xvmc_driver->devPrivate; - if (xf86XvMCScreenInit(pScreen, 1, ppAdapt)) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "[XvMC] Initialized XvMC.\n"); - pI830->XvMCEnabled = TRUE; - } else { - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "[XvMC] xf86 XvMC initial failed\n"); - pI830->XvMCEnabled = FALSE; - xfree(pI830->xvmc); - pI830->xvmc = NULL; - return FALSE; - } - return TRUE; + cleanupI915XvMC(pXvMC); + xfree(xvmc_driver->devPrivate); } -unsigned long I915XvMCPutImageSize(ScrnInfoPtr pScrn) -{ - I830Ptr pI830 = I830PTR(pScrn); - - if (pI830->XvMCEnabled) - return sizeof(I915XvMCCommandBuffer); - - return 0; -} +/* new xvmc driver interface */ +struct intel_xvmc_driver i915_xvmc_driver = { + "i915_xvmc", + &pAdapt, + XVMC_DRIVER_MPEG2_MC, + i915_xvmc_init, + i915_xvmc_fini, + i915_xvmc_putimage_size, + NULL +}; |