summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2008-10-11 20:41:14 -0400
committerAlan Hourihane <alanh@tungstengraphics.com>2008-10-15 11:18:05 +0100
commitd533a5d00ae2d0669e9da41718ee847de0c343aa (patch)
tree3d5cf489a68979fa1c117532d25cdeabacb5f25d
parente5ef0beb0549b2b613c379553cc51f9f1ae72299 (diff)
Update DRI2 implementation according to new specification.
-rw-r--r--src/glx/x11/dri2.c92
-rw-r--r--src/glx/x11/dri2.h14
-rw-r--r--src/glx/x11/dri2_glx.c42
-rw-r--r--src/glx/x11/dri_common.c2
-rw-r--r--src/glx/x11/dri_glx.c9
-rw-r--r--src/glx/x11/glxclient.h4
-rw-r--r--src/glx/x11/glxcmds.c7
7 files changed, 101 insertions, 69 deletions
diff --git a/src/glx/x11/dri2.c b/src/glx/x11/dri2.c
index edd80dc58f..91a9c2af93 100644
--- a/src/glx/x11/dri2.c
+++ b/src/glx/x11/dri2.c
@@ -102,8 +102,8 @@ Bool DRI2QueryVersion(Display *dpy, int *major, int *minor)
return True;
}
-Bool DRI2Connect(Display *dpy, int screen,
- char **driverName, char **busId, unsigned int *sareaHandle)
+Bool DRI2Connect(Display *dpy, XID window,
+ char **driverName, char **deviceName)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
xDRI2ConnectReply rep;
@@ -115,14 +115,15 @@ Bool DRI2Connect(Display *dpy, int screen,
GetReq(DRI2Connect, req);
req->reqType = info->codes->major_opcode;
req->dri2ReqType = X_DRI2Connect;
- req->screen = screen;
+ req->window = window;
+ req->driverType = DRI2DriverDRI;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
- if (rep.driverNameLength == 0 && rep.busIdLength == 0) {
+ if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) {
UnlockDisplay(dpy);
SyncHandle();
return False;
@@ -132,7 +133,7 @@ Bool DRI2Connect(Display *dpy, int screen,
if (*driverName == NULL) {
_XEatData(dpy,
((rep.driverNameLength + 3) & ~3) +
- ((rep.busIdLength + 3) & ~3));
+ ((rep.deviceNameLength + 3) & ~3));
UnlockDisplay(dpy);
SyncHandle();
return False;
@@ -140,16 +141,16 @@ Bool DRI2Connect(Display *dpy, int screen,
_XReadPad(dpy, *driverName, rep.driverNameLength);
(*driverName)[rep.driverNameLength] = '\0';
- *busId = Xmalloc(rep.busIdLength + 1);
- if (*busId == NULL) {
+ *deviceName = Xmalloc(rep.deviceNameLength + 1);
+ if (*deviceName == NULL) {
Xfree(*driverName);
- _XEatData(dpy, ((rep.busIdLength + 3) & ~3));
+ _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3));
UnlockDisplay(dpy);
SyncHandle();
return False;
}
- _XReadPad(dpy, *busId, rep.busIdLength);
- (*busId)[rep.busIdLength] = '\0';
+ _XReadPad(dpy, *deviceName, rep.deviceNameLength);
+ (*deviceName)[rep.deviceNameLength] = '\0';
UnlockDisplay(dpy);
SyncHandle();
@@ -157,26 +158,27 @@ Bool DRI2Connect(Display *dpy, int screen,
return True;
}
-Bool DRI2AuthConnection(Display *dpy, int screen, drm_magic_t magic)
+Bool DRI2Authenticate(Display *dpy, XID window, drm_magic_t magic)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
- xDRI2AuthConnectionReq *req;
- xDRI2AuthConnectionReply rep;
+ xDRI2AuthenticateReq *req;
+ xDRI2AuthenticateReply rep;
XextCheckExtension (dpy, info, dri2ExtensionName, False);
LockDisplay(dpy);
- GetReq(DRI2AuthConnection, req);
+ GetReq(DRI2Authenticate, req);
req->reqType = info->codes->major_opcode;
- req->dri2ReqType = X_DRI2AuthConnection;
- req->screen = screen;
+ req->dri2ReqType = X_DRI2Authenticate;
+ req->window = window;
req->magic = magic;
- rep.authenticated = 0;
+
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
+
UnlockDisplay(dpy);
SyncHandle();
@@ -199,6 +201,24 @@ void DRI2CreateDrawable(Display *dpy, XID drawable)
SyncHandle();
}
+void DRI2DestroyDrawable(Display *dpy, XID drawable)
+{
+ XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+ xDRI2DestroyDrawableReq *req;
+
+ XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
+
+ XSync(dpy, False);
+
+ LockDisplay(dpy);
+ GetReq(DRI2DestroyDrawable, req);
+ req->reqType = info->codes->major_opcode;
+ req->dri2ReqType = X_DRI2DestroyDrawable;
+ req->drawable = drawable;
+ UnlockDisplay(dpy);
+ SyncHandle();
+}
+
DRI2Buffer *DRI2GetBuffers(Display *dpy, XID drawable,
int *width, int *height,
unsigned int *attachments, int count,
@@ -257,45 +277,27 @@ DRI2Buffer *DRI2GetBuffers(Display *dpy, XID drawable,
return buffers;
}
-void DRI2SwapBuffers(Display *dpy, XID drawable,
- int x, int y, int width, int height)
+void DRI2CopyRegion(Display *dpy, XID drawable, XserverRegion region,
+ CARD32 dest, CARD32 src)
{
XExtDisplayInfo *info = DRI2FindDisplay(dpy);
- xDRI2SwapBuffersReq *req;
- xDRI2SwapBuffersReply rep;
+ xDRI2CopyRegionReq *req;
+ xDRI2CopyRegionReply rep;
XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
LockDisplay(dpy);
- GetReq(DRI2SwapBuffers, req);
+ GetReq(DRI2CopyRegion, req);
req->reqType = info->codes->major_opcode;
- req->dri2ReqType = X_DRI2SwapBuffers;
+ req->dri2ReqType = X_DRI2CopyRegion;
req->drawable = drawable;
- req->x = x;
- req->y = y;
- req->width = width;
- req->height = height;
+ req->region = region;
+ req->dest = dest;
+ req->src = src;
+ req->bitmask = 0;
_XReply(dpy, (xReply *)&rep, 0, xFalse);
UnlockDisplay(dpy);
SyncHandle();
}
-
-void DRI2DestroyDrawable(Display *dpy, XID drawable)
-{
- XExtDisplayInfo *info = DRI2FindDisplay(dpy);
- xDRI2DestroyDrawableReq *req;
-
- XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
-
- XSync(dpy, False);
-
- LockDisplay(dpy);
- GetReq(DRI2DestroyDrawable, req);
- req->reqType = info->codes->major_opcode;
- req->dri2ReqType = X_DRI2DestroyDrawable;
- req->drawable = drawable;
- UnlockDisplay(dpy);
- SyncHandle();
-}
diff --git a/src/glx/x11/dri2.h b/src/glx/x11/dri2.h
index 25212f99e5..c1bfa664bb 100644
--- a/src/glx/x11/dri2.h
+++ b/src/glx/x11/dri2.h
@@ -34,6 +34,9 @@
#ifndef _DRI2_H_
#define _DRI2_H_
+#include <X11/extensions/Xfixes.h>
+#include <X11/extensions/dri2tokens.h>
+
typedef struct {
unsigned int attachment;
unsigned int name;
@@ -47,10 +50,10 @@ DRI2QueryExtension(Display *display, int *eventBase, int *errorBase);
extern Bool
DRI2QueryVersion(Display *display, int *major, int *minor);
extern Bool
-DRI2Connect(Display *display, int screen,
- char **driverName, char **busId, unsigned int *sareaHandle);
+DRI2Connect(Display *display, XID window,
+ char **driverName, char **deviceName);
extern Bool
-DRI2AuthConnection(Display *display, int screen, drm_magic_t magic);
+DRI2Authenticate(Display *display, XID window, drm_magic_t magic);
extern void
DRI2CreateDrawable(Display *display, XID drawable);
extern void
@@ -60,8 +63,9 @@ DRI2GetBuffers(Display *dpy, XID drawable,
int *width, int *height,
unsigned int *attachments, int count,
int *outCount);
+
extern void
-DRI2SwapBuffers(Display *dpy, XID drawable,
- int x, int y, int width, int height);
+DRI2CopyRegion(Display *dpy, XID drawable, XserverRegion region,
+ CARD32 dest, CARD32 src);
#endif
diff --git a/src/glx/x11/dri2_glx.c b/src/glx/x11/dri2_glx.c
index 39b618e718..bf76d1899b 100644
--- a/src/glx/x11/dri2_glx.c
+++ b/src/glx/x11/dri2_glx.c
@@ -39,8 +39,9 @@
#include "glxclient.h"
#include "glcontextmodes.h"
#include "xf86dri.h"
-#include "sarea.h"
#include <dlfcn.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include "xf86drm.h"
@@ -183,19 +184,35 @@ static __GLXDRIdrawable *dri2CreateDrawable(__GLXscreenConfigs *psc,
return &pdraw->base;
}
+static void dri2CopySubBuffer(__GLXDRIdrawable *pdraw,
+ int x, int y, int width, int height)
+{
+ XRectangle xrect;
+ XserverRegion region;
+
+ xrect.x = x;
+ xrect.y = y;
+ xrect.width = width;
+ xrect.height = height;
+
+ region = XFixesCreateRegion(pdraw->psc->dpy, &xrect, 1);
+ DRI2CopyRegion(pdraw->psc->dpy, pdraw->drawable, region,
+ DRI2BufferFrontLeft, DRI2BufferBackLeft);
+ XFixesDestroyRegion(pdraw->psc->dpy, region);
+}
+
static void dri2SwapBuffers(__GLXDRIdrawable *pdraw)
{
__GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
- DRI2SwapBuffers(pdraw->psc->dpy, pdraw->drawable,
- 0, 0, priv->width, priv->height);
+ dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height);
}
static void dri2DestroyScreen(__GLXscreenConfigs *psc)
{
/* Free the direct rendering per screen data */
(*psc->core->destroyScreen)(psc->__driScreen);
- drmClose(psc->fd);
+ close(psc->fd);
psc->__driScreen = NULL;
}
@@ -249,8 +266,7 @@ static __GLXDRIscreen *dri2CreateScreen(__GLXscreenConfigs *psc, int screen,
const __DRIconfig **driver_configs;
const __DRIextension **extensions;
__GLXDRIscreen *psp;
- unsigned int sareaHandle;
- char *driverName, *busID;
+ char *driverName, *deviceName;
drm_magic_t magic;
int i;
@@ -261,7 +277,8 @@ static __GLXDRIscreen *dri2CreateScreen(__GLXscreenConfigs *psc, int screen,
/* Initialize per screen dynamic client GLX extensions */
psc->ext_list_first_time = GL_TRUE;
- if (!DRI2Connect(psc->dpy, screen, &driverName, &busID, &sareaHandle))
+ if (!DRI2Connect(psc->dpy, RootWindow(psc->dpy, screen),
+ &driverName, &deviceName))
return NULL;
psc->driver = driOpenDriver(driverName);
@@ -286,7 +303,7 @@ static __GLXDRIscreen *dri2CreateScreen(__GLXscreenConfigs *psc, int screen,
goto handle_error;
}
- psc->fd = drmOpen(NULL, busID);
+ psc->fd = open(deviceName, O_RDWR);
if (psc->fd < 0) {
ErrorMessageF("failed to open drm device: %s\n", strerror(errno));
return NULL;
@@ -295,10 +312,8 @@ static __GLXDRIscreen *dri2CreateScreen(__GLXscreenConfigs *psc, int screen,
if (drmGetMagic(psc->fd, &magic))
return NULL;
- if (!DRI2AuthConnection(psc->dpy, screen, magic)) {
- ErrorMessageF("failed to authenticate drm access\n");
+ if (!DRI2Authenticate(psc->dpy, RootWindow(psc->dpy, screen), magic))
return NULL;
- }
psc->__driScreen =
psc->dri2->createNewScreen(screen, psc->fd,
@@ -317,15 +332,16 @@ static __GLXDRIscreen *dri2CreateScreen(__GLXscreenConfigs *psc, int screen,
psp->createContext = dri2CreateContext;
psp->createDrawable = dri2CreateDrawable;
psp->swapBuffers = dri2SwapBuffers;
+ psp->copySubBuffer = dri2CopySubBuffer;
Xfree(driverName);
- Xfree(busID);
+ Xfree(deviceName);
return psp;
handle_error:
Xfree(driverName);
- Xfree(busID);
+ Xfree(deviceName);
/* FIXME: clean up here */
diff --git a/src/glx/x11/dri_common.c b/src/glx/x11/dri_common.c
index 4e535d5f10..f6e16fa856 100644
--- a/src/glx/x11/dri_common.c
+++ b/src/glx/x11/dri_common.c
@@ -340,7 +340,7 @@ driBindExtensions(__GLXscreenConfigs *psc, int dri2)
for (i = 0; extensions[i]; i++) {
#ifdef __DRI_COPY_SUB_BUFFER
if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) {
- psc->copySubBuffer = (__DRIcopySubBufferExtension *) extensions[i];
+ psc->driCopySubBuffer = (__DRIcopySubBufferExtension *) extensions[i];
__glXEnableDirectExtension(psc, "GLX_MESA_copy_sub_buffer_bit");
}
#endif
diff --git a/src/glx/x11/dri_glx.c b/src/glx/x11/dri_glx.c
index 290b87c62e..7aa97b9ee9 100644
--- a/src/glx/x11/dri_glx.c
+++ b/src/glx/x11/dri_glx.c
@@ -575,6 +575,13 @@ static void driSwapBuffers(__GLXDRIdrawable *pdraw)
(*pdraw->psc->core->swapBuffers)(pdraw->driDrawable);
}
+static void driCopySubBuffer(__GLXDRIdrawable *pdraw,
+ int x, int y, int width, int height)
+{
+ (*pdraw->psc->driCopySubBuffer->copySubBuffer)(pdraw->driDrawable,
+ x, y, width, height);
+}
+
static void driDestroyScreen(__GLXscreenConfigs *psc)
{
/* Free the direct rendering per screen data */
@@ -642,6 +649,8 @@ static __GLXDRIscreen *driCreateScreen(__GLXscreenConfigs *psc, int screen,
}
driBindExtensions(psc, 0);
+ if (psc->driCopySubBuffer)
+ psp->copySubBuffer = driCopySubBuffer;
psp->destroyScreen = driDestroyScreen;
psp->createContext = driCreateContext;
diff --git a/src/glx/x11/glxclient.h b/src/glx/x11/glxclient.h
index 2d530eabdb..80f28332b7 100644
--- a/src/glx/x11/glxclient.h
+++ b/src/glx/x11/glxclient.h
@@ -138,6 +138,8 @@ struct __GLXDRIscreenRec {
const __GLcontextModes *modes);
void (*swapBuffers)(__GLXDRIdrawable *pdraw);
+ void (*copySubBuffer)(__GLXDRIdrawable *pdraw,
+ int x, int y, int width, int height);
};
struct __GLXDRIcontextRec {
@@ -493,7 +495,7 @@ struct __GLXscreenConfigsRec {
__GLXDRIscreen *driScreen;
#ifdef __DRI_COPY_SUB_BUFFER
- const __DRIcopySubBufferExtension *copySubBuffer;
+ const __DRIcopySubBufferExtension *driCopySubBuffer;
#endif
#ifdef __DRI_SWAP_CONTROL
diff --git a/src/glx/x11/glxcmds.c b/src/glx/x11/glxcmds.c
index 72ab48929d..ff04853e93 100644
--- a/src/glx/x11/glxcmds.c
+++ b/src/glx/x11/glxcmds.c
@@ -2499,10 +2499,9 @@ static void __glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable,
int screen;
__GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
if ( pdraw != NULL ) {
- __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
- if (psc->copySubBuffer != NULL) {
- (*psc->copySubBuffer->copySubBuffer)(pdraw->driDrawable,
- x, y, width, height);
+ __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
+ if (psc->driScreen->copySubBuffer != NULL) {
+ (*psc->driScreen->copySubBuffer)(pdraw, x, y, width, height);
}
return;