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;
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;
if (*driverName == NULL) {
_XEatData(dpy,
((rep.driverNameLength + 3) & ~3) +
- ((rep.busIdLength + 3) & ~3));
+ ((rep.deviceNameLength + 3) & ~3));
UnlockDisplay(dpy);
SyncHandle();
return False;
_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();
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();
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,
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();
-}
#ifndef _DRI2_H_
#define _DRI2_H_
+#include <X11/extensions/Xfixes.h>
+#include <X11/extensions/dri2tokens.h>
+
typedef struct {
unsigned int attachment;
unsigned int name;
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
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
#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"
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;
}
const __DRIconfig **driver_configs;
const __DRIextension **extensions;
__GLXDRIscreen *psp;
- unsigned int sareaHandle;
- char *driverName, *busID;
+ char *driverName, *deviceName;
drm_magic_t magic;
int i;
/* 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);
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;
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,
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 */
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
(*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 */
}
driBindExtensions(psc, 0);
+ if (psc->driCopySubBuffer)
+ psp->copySubBuffer = driCopySubBuffer;
psp->destroyScreen = driDestroyScreen;
psp->createContext = driCreateContext;
const __GLcontextModes *modes);
void (*swapBuffers)(__GLXDRIdrawable *pdraw);
+ void (*copySubBuffer)(__GLXDRIdrawable *pdraw,
+ int x, int y, int width, int height);
};
struct __GLXDRIcontextRec {
__GLXDRIscreen *driScreen;
#ifdef __DRI_COPY_SUB_BUFFER
- const __DRIcopySubBufferExtension *copySubBuffer;
+ const __DRIcopySubBufferExtension *driCopySubBuffer;
#endif
#ifdef __DRI_SWAP_CONTROL
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;