summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuc Verhaegen <libv@skynet.be>2009-07-29 16:19:21 +0200
committerLuc Verhaegen <libv@skynet.be>2009-11-04 15:13:00 +0100
commit80817b84134067ee14403dccb967aca69e7233f8 (patch)
treeb9f076a7e103b893b502b14c0423db52235e47f1
parent4f0284bc6f77bf8b5367cc1cdbeb47e0a2b5e716 (diff)
XvMC: Start filling out XvMCCreateContext.
Add some initial code for the _further_ X extension.
-rw-r--r--lib/xvmc/Makefile.am6
-rw-r--r--lib/xvmc/xvmc_unichrome.c78
-rw-r--r--lib/xvmc/xvmce.c133
-rw-r--r--lib/xvmc/xvmce.h29
-rw-r--r--lib/xvmc/xvmce_proto.h61
-rw-r--r--src/via_xvmc.c124
6 files changed, 428 insertions, 3 deletions
diff --git a/lib/xvmc/Makefile.am b/lib/xvmc/Makefile.am
index a2291b0..471391e 100644
--- a/lib/xvmc/Makefile.am
+++ b/lib/xvmc/Makefile.am
@@ -1,6 +1,10 @@
lib_LTLIBRARIES = libXvMCunichrome.la
-libXvMCunichrome_la_SOURCES = xvmc_unichrome.c
+libXvMCunichrome_la_SOURCES = \
+ xvmce.c \
+ xvmce.h \
+ xvmce_proto.h \
+ xvmc_unichrome.c
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libXvMCunichrome.pc
diff --git a/lib/xvmc/xvmc_unichrome.c b/lib/xvmc/xvmc_unichrome.c
index 6cee12f..9738ad3 100644
--- a/lib/xvmc/xvmc_unichrome.c
+++ b/lib/xvmc/xvmc_unichrome.c
@@ -24,14 +24,43 @@
#include <stdio.h>
#include <X11/Xlibint.h>
+#include <X11/extensions/Xv.h>
+#include <X11/extensions/Xvlib.h>
#include <X11/extensions/Xvproto.h>
+#include <X11/extensions/XvMC.h>
#include <X11/extensions/XvMCproto.h>
#include <X11/extensions/XvMClib.h>
#include <X11/extensions/Xext.h>
#include <X11/extensions/extutil.h>
-#include <X11/extensions/Xv.h>
#include <X11/extensions/vldXvMC.h>
+#include "xvmce.h"
+
+/* Oh you must be kidding me. What a bunch of clueless idiots. */
+extern Status _xvmc_create_context(Display *dpy, XvMCContext *context,
+ int *priv_count, CARD32 **priv_data);
+
+extern Status _xvmc_destroy_context(Display *dpy, XvMCContext *context);
+
+extern Status _xvmc_create_surface(Display *dpy, XvMCContext *context,
+ XvMCSurface *surface, int *priv_count,
+ CARD32 **priv_data);
+
+extern Status _xvmc_destroy_surface(Display *dpy, XvMCSurface *surface);
+
+extern Status _xvmc_create_subpicture(Display *dpy, XvMCContext *context,
+ XvMCSubpicture *subpicture,
+ int *priv_count, uint **priv_data);
+
+extern Status _xvmc_destroy_subpicture(Display *dpy,
+ XvMCSubpicture *subpicture);
+
+
+static int XvMC_EventBase;
+static int XvMC_ErrorBase;
+static int XvMCE_EventBase;
+static int XvMCE_ErrorBase;
+
/*
*
*/
@@ -39,8 +68,52 @@ _X_EXPORT Status
XvMCCreateContext(Display *display, XvPortID port, int surface_type_id,
int width, int height, int flags, XvMCContext *context)
{
+ Status status;
+ int major, minor;
+ int priv_count;
+ CARD32 *priv_data = NULL;
+
printf("%s\n", __func__);
+ if (!display || !context)
+ return BadValue;
+
+ /* First, check XvMC. */
+ if (!XvMCQueryExtension(display, &XvMC_EventBase, &XvMC_ErrorBase)) {
+ printf("%s: XvMC extension is missing.\n", __func__);
+ return BadRequest;
+ }
+
+ status = XvMCQueryVersion(display, &major, &minor);
+ if (status != Success) {
+ printf("%s: XvMCQueryVersion failed: %d\n", __func__, status);
+ return BadImplementation;
+ }
+ printf("Found XvMC Extension version %d.%d.\n", major, minor);
+
+ /* Now, check our own extension */
+ status = XvMCEQueryExtension(display, &major, &minor,
+ &XvMCE_EventBase, &XvMCE_ErrorBase);
+ if (status != Success) {
+ printf("%s: XvMCEQueryExtension failed: %d\n", __func__, status);
+ return status;
+ }
+ printf("Found Unichrome XvMCE Extension version %d.%d.\n", major, minor);
+
+ /* Only now, we can go and try to create a context, with a twist. */
+ context->surface_type_id = surface_type_id;
+ context->width = width; /* this better be correct, or we die */
+ context->height = height;
+ context->flags = flags;
+ context->port = port;
+
+ /* now call the old, raped X extension hooks */
+ status =_xvmc_create_context(display, context, &priv_count, &priv_data);
+ if (status != Success) {
+ printf("%s: _xvmc_create_context failed: %d\n", __func__, status);
+ return status;
+ }
+
return BadImplementation;
}
@@ -53,6 +126,9 @@ XvMCDestroyContext(Display *display, XvMCContext *context)
{
printf("%s\n", __func__);
+ if (!display || !context)
+ return BadValue;
+
return Success;
}
diff --git a/lib/xvmc/xvmce.c b/lib/xvmc/xvmce.c
new file mode 100644
index 0000000..0576e60
--- /dev/null
+++ b/lib/xvmc/xvmce.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2006-2009 Luc Verhaegen.
+ *
+ * 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, sub license,
+ * 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 NON-INFRINGEMENT. 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.
+ */
+
+/*
+ * Our own X extension to push mpeg-2 data over the X protocol.
+ *
+ * People are blind and stupid, and infatuated with DRM, and therefor
+ * completely messed up XvMC.
+ */
+#include <X11/Xlib.h>
+#include <X11/extensions/Xv.h>
+#include <X11/extensions/Xvlib.h>
+
+#include <stdio.h>
+
+#include <X11/Xlibint.h>
+#include <X11/Xproto.h>
+#include <X11/Intrinsic.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+
+#include "xvmce_proto.h"
+#include "xvmce.h"
+
+#define XvMCECheckExtension(dpy, info, val) \
+ XextCheckExtension(dpy, info, XVMCE_EXT_NAME, val)
+
+static XExtensionInfo *XvMCEExtInfo = NULL;
+
+static int XvMCEExtCloseDisplay(Display *dpy, XExtCodes *codes);
+XEXT_GENERATE_CLOSE_DISPLAY(XvMCEExtCloseDisplay, XvMCEExtInfo)
+
+XExtDisplayInfo *XvMCEFindDisplay(Display *dpy);
+static XExtensionHooks XvMCEExtHooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ XvMCEExtCloseDisplay,
+ NULL, /* wire_to_event */
+ NULL, /* event_to_wire */
+ NULL, /* error */
+ NULL, /* error_string */
+};
+XEXT_GENERATE_FIND_DISPLAY(XvMCEFindDisplay, XvMCEExtInfo, XVMCE_EXT_NAME,
+ &XvMCEExtHooks, 0, NULL)
+
+#define XvMCEGetReq(name, req) \
+ WORD64ALIGN\
+ if ((dpy->bufptr + SIZEOF(xvmce##name##Req)) > dpy->bufmax)\
+ _XFlush(dpy);\
+ req = (xvmce##name##Req *)(dpy->last_req = dpy->bufptr);\
+ req->reqType = info->codes->major_opcode;\
+ req->xvmceReqType = xvmce_##name; \
+ req->length = (SIZEOF(xvmce##name##Req))>>2;\
+ dpy->bufptr += SIZEOF(xvmce##name##Req);\
+ dpy->request++
+
+#define XvmceGetReqExtra(name, req, len) \
+ WORD64ALIGN\
+ if ((dpy->bufptr + SIZEOF(xvmce##name##Req)) > dpy->bufmax)\
+ _XFlush(dpy);\
+ req = (xvmce##name##Req *)(dpy->last_req = dpy->bufptr);\
+ req->reqType = info->codes->major_opcode;\
+ req->xvmceReqType = xvmce_##name; \
+ req->length = (SIZEOF(xvmce##name##Req) + len + 3)>>2;\
+ dpy->bufptr += SIZEOF(xvmce##name##Req);\
+ dpy->request++
+
+/*
+ *
+ */
+Status
+XvMCEQueryExtension(Display *dpy, int *Version, int *Release,
+ int *event_basep, int *error_basep)
+{
+ XExtDisplayInfo *info = XvMCEFindDisplay(dpy);
+ xvmceQueryExtensionReq *req;
+ xvmceQueryExtensionReply reply;
+ Status status;
+
+ XvMCECheckExtension(dpy, info, BadImplementation);
+
+ LockDisplay(dpy);
+
+ XvMCEGetReq(QueryExtension, req);
+
+ if (_XReply(dpy, (xReply *)&reply, 0, xFalse)) {
+ *Version = reply.Version;
+ *Release = reply.Release;
+
+ if ((*Version != XVMCE_VERSION) || (*Release < XVMCE_RELEASE)) {
+ fprintf(stderr, "Incompatible %s version found.\n", XVMCE_EXT_NAME);
+
+ status = BadImplementation;
+ }
+
+ *event_basep = info->codes->first_event;
+ *error_basep = info->codes->first_error;
+
+ status = Success;
+ } else {
+ fprintf(stderr, "%s; Xreply failed.\n", __func__);
+ status = BadAccess;
+ }
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+
+ return status;
+}
diff --git a/lib/xvmc/xvmce.h b/lib/xvmc/xvmce.h
new file mode 100644
index 0000000..b196faf
--- /dev/null
+++ b/lib/xvmc/xvmce.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009 Luc Verhaegen.
+ *
+ * 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, sub license,
+ * 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 NON-INFRINGEMENT. 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.
+ */
+
+#ifndef XVMCE_H
+#define XVMCE_H
+
+Status XvMCEQueryExtension(Display *dpy, int *Version, int *Release, int *event_basep, int *error_basep);
+
+#endif /* XVMCE_H */
diff --git a/lib/xvmc/xvmce_proto.h b/lib/xvmc/xvmce_proto.h
new file mode 100644
index 0000000..38c42d6
--- /dev/null
+++ b/lib/xvmc/xvmce_proto.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2006-2009 Luc Verhaegen.
+ *
+ * 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, sub license,
+ * 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 NON-INFRINGEMENT. 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.
+ */
+
+/*
+ * Protocol definition for unichrome xvmce.
+ */
+#ifndef XVMCE_PROTO_H
+#define XVMCE_PROTO_H
+
+#define XVMCE_EXT_NAME "Unichrome XvMC-E"
+
+#define XVMCE_VERSION 0
+#define XVMCE_RELEASE 0
+
+#define xvmce_QueryExtension 0
+
+/*
+ * Version, are we compatible?
+ */
+typedef struct {
+ CARD8 reqType;
+ CARD8 xvmceReqType; /* xvmce_QueryExtension */
+ CARD16 length B16;
+} xvmceQueryExtensionReq;
+#define sz_xvmceQueryExtensionReq 4
+
+typedef struct {
+ BYTE type; /* X_Reply */
+ BYTE pad0;
+ CARD16 sequenceNumber B16;
+ CARD32 length B32;
+ CARD32 Version B32;
+ CARD32 Release B32;
+ CARD32 pad2 B32;
+ CARD32 pad3 B32;
+ CARD32 pad4 B32;
+ CARD32 pad5 B32;
+} xvmceQueryExtensionReply;
+#define sz_xvmceQueryExtensionReply 32
+
+#endif /* XVMCE_PROTO_H */
diff --git a/src/via_xvmc.c b/src/via_xvmc.c
index 50a0e06..c98dab2 100644
--- a/src/via_xvmc.c
+++ b/src/via_xvmc.c
@@ -34,6 +34,118 @@
#include "via_driver.h"
#include "via_video.h"
+/*
+ *
+ * First, our own X protocol to make XvMC less brainless.
+ *
+ */
+#include <extnsionst.h>
+#include <dixstruct.h>
+#include "lib/xvmc/xvmce_proto.h"
+
+struct XvMCEPrivates
+{
+ int scrnIndex;
+};
+
+/*
+ *
+ */
+static int
+XvMCEProcQueryExtension(ClientPtr client)
+{
+ ExtensionEntry *MPEGExt;
+ xvmceQueryExtensionReply rep;
+
+ REQUEST_SIZE_MATCH(xvmceQueryExtensionReq);
+
+ MPEGExt = CheckExtension(XVMCE_EXT_NAME);
+ if(!MPEGExt || !MPEGExt->extPrivate)
+ return BadMatch;
+
+ rep.type = X_Reply;
+ rep.sequenceNumber = client->sequence;
+ rep.length =
+ (sizeof(xvmceQueryExtensionReply) - sizeof(xGenericReply)) >> 2;
+ rep.Version = XVMCE_VERSION;
+ rep.Release = XVMCE_RELEASE;
+
+ WriteToClient(client, sizeof(xvmceQueryExtensionReply), (char *)&rep);
+ return (client->noClientException);
+}
+
+/*
+ *
+ */
+static int
+XvMCEHandler(ClientPtr client)
+{
+ REQUEST(xReq);
+
+ switch (stuff->data) {
+ case xvmce_QueryExtension:
+ return XvMCEProcQueryExtension(client);
+ default:
+ break;
+ }
+
+ return BadRequest;
+}
+
+/*
+ *
+ */
+static int
+XvMCESHandler(ClientPtr client)
+{
+ ErrorF("%s is not implemented.\n", __func__);
+
+ return BadRequest;
+}
+
+/*
+ *
+ */
+static void
+XvMCEClose(ExtensionEntry *MPEGExt)
+{
+ if (MPEGExt->extPrivate) {
+ xfree(MPEGExt->extPrivate);
+ MPEGExt->extPrivate = NULL;
+ }
+}
+
+/*
+ *
+ */
+static Bool
+XvMCEInit(ScrnInfoPtr pScrn)
+{
+ ExtensionEntry *XvMCE_Ext;
+ struct XvMCEPrivates *Private;
+
+ VIAFUNC(pScrn);
+
+ XvMCE_Ext = AddExtension(XVMCE_EXT_NAME, 0, 0, XvMCEHandler, XvMCESHandler,
+ XvMCEClose, StandardMinorOpcode);
+ if (!XvMCE_Ext) {
+ xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "%s: Failed to add %s.\n",
+ __func__, XVMCE_EXT_NAME);
+ return FALSE;
+ }
+
+ Private = xnfcalloc(sizeof(struct XvMCEPrivates), 1);
+ Private->scrnIndex = pScrn->scrnIndex;
+ XvMCE_Ext->extPrivate = Private;
+
+ return TRUE;
+}
+
+/*
+ *
+ * Now, use what is somewhat useable from XvMC.
+ *
+ */
static int ViaMCImageIDs[2] = {FOURCC_AI44, FOURCC_IA44};
static XF86MCImageIDList ViaMCImageIDList = {2, ViaMCImageIDs};
@@ -63,7 +175,11 @@ ViaMCCreateContext(ScrnInfoPtr pScrn, XvMCContextPtr context,
{
VIAFUNC(pScrn);
- return BadAlloc;
+ ViaDebug(pScrn->scrnIndex, "%s: adapter %d, surfaceid %08X (%dx%d); %08X\n",
+ __func__, context->adapt_num, context->surface_type_id,
+ context->width, context->height, context->flags);
+
+ return Success;
}
/*
@@ -138,6 +254,12 @@ ViaMCInit(ScrnInfoPtr pScrn, ScreenPtr pScreen)
{
VIAFUNC(pScrn);
+ if (!XvMCEInit(pScrn)) {
+ xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+ "%s: Failed to initialise XvMCE extension.\n", __func__);
+ return FALSE;
+ }
+
if (!xf86XvMCScreenInit(pScreen, 1, ViaMCAdaptors)) {
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"%s: Failed to initialise XvMC.\n", __func__);