Bool DRI2Authenticate(Display * dpy, XID window, drm_magic_t magic) { XExtDisplayInfo *info = DRI2FindDisplay(dpy); xDRI2AuthenticateReq *req; xDRI2AuthenticateReply rep; XextCheckExtension(dpy, info, dri2ExtensionName, False); LockDisplay(dpy); GetReq(DRI2Authenticate, req); req->reqType = info->codes->major_opcode; req->dri2ReqType = X_DRI2Authenticate; req->window = window; req->magic = magic; if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } UnlockDisplay(dpy); SyncHandle(); return rep.authenticated; }
Bool _vdp_DRI2QueryVersion(Display * dpy, int *major, int *minor) { XExtDisplayInfo *info = DRI2FindDisplay(dpy); xDRI2QueryVersionReply rep; xDRI2QueryVersionReq *req; XextCheckExtension(dpy, info, dri2ExtensionName, False); LockDisplay(dpy); GetReq(DRI2QueryVersion, req); req->reqType = info->codes->major_opcode; req->dri2ReqType = X_DRI2QueryVersion; req->majorVersion = DRI2_MAJOR; req->minorVersion = DRI2_MINOR; if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } *major = rep.majorVersion; *minor = rep.minorVersion; UnlockDisplay(dpy); SyncHandle(); return True; }
Status XcupQueryVersion( Display* dpy, int* major_version_return, int* minor_version_return) { XExtDisplayInfo *info = find_display (dpy); xXcupQueryVersionReply rep; xXcupQueryVersionReq *req; XextCheckExtension (dpy, info, xcup_extension_name, False); LockDisplay(dpy); GetReq(XcupQueryVersion, req); req->reqType = info->codes->major_opcode; req->xcupReqType = X_XcupQueryVersion; req->client_major_version = XCUP_MAJOR_VERSION; req->client_minor_version = XCUP_MINOR_VERSION; if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) { UnlockDisplay(dpy); SyncHandle(); return False; } *major_version_return = rep.server_major_version; *minor_version_return = rep.server_minor_version; UnlockDisplay(dpy); SyncHandle(); return True; }
DRI2Buffer * DRI2GetBuffersWithFormat(Display * dpy, XID drawable, int *width, int *height, unsigned int *attachments, int count, int *outCount) { XExtDisplayInfo *info = DRI2FindDisplay(dpy); xDRI2GetBuffersReply rep; xDRI2GetBuffersReq *req; DRI2Buffer *buffers; xDRI2Buffer repBuffer; CARD32 *p; int i; XextCheckExtension(dpy, info, dri2ExtensionName, False); LockDisplay(dpy); GetReqExtra(DRI2GetBuffers, count * (4 * 2), req); req->reqType = info->codes->major_opcode; req->dri2ReqType = X_DRI2GetBuffersWithFormat; req->drawable = drawable; req->count = count; p = (CARD32 *) & req[1]; for (i = 0; i < (count * 2); i++) p[i] = attachments[i]; if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { fprintf(stderr, "GetBuffersWithFormat fails\n"); UnlockDisplay(dpy); SyncHandle(); return NULL; } *width = rep.width; *height = rep.height; *outCount = rep.count; buffers = Xmalloc(rep.count * sizeof buffers[0]); if (buffers == NULL) { _XEatData(dpy, rep.count * sizeof repBuffer); UnlockDisplay(dpy); SyncHandle(); return NULL; } for (i = 0; i < rep.count; i++) { _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer); buffers[i].attachment = repBuffer.attachment; buffers[i].name = repBuffer.name; buffers[i].pitch = repBuffer.pitch; buffers[i].cpp = repBuffer.cpp; buffers[i].flags = repBuffer.flags; } UnlockDisplay(dpy); SyncHandle(); return buffers; }
static Bool DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire) { #if 0 XExtDisplayInfo *info = DRI2FindDisplay(dpy); XExtDisplayInfo *glx_info = glXFindDisplay(dpy); XextCheckExtension(dpy, info, dri2ExtensionName, False); switch ((wire->u.u.type & 0x7f) - info->codes->first_event) { #ifdef X_DRI2SwapBuffers case DRI2_BufferSwapComplete: { GLXBufferSwapComplete *aevent = (GLXBufferSwapComplete *)event; xDRI2BufferSwapComplete *awire = (xDRI2BufferSwapComplete *)wire; aevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire); aevent->type = (glx_info->codes->first_event + GLX_BufferSwapComplete) & 0x75; aevent->send_event = (awire->type & 0x80) != 0; aevent->display = dpy; aevent->drawable = awire->drawable; switch (awire->event_type) { case DRI2_EXCHANGE_COMPLETE: aevent->event_type = GLX_EXCHANGE_COMPLETE_INTEL; break; case DRI2_BLIT_COMPLETE: aevent->event_type = GLX_BLIT_COMPLETE_INTEL; break; case DRI2_FLIP_COMPLETE: aevent->event_type = GLX_FLIP_COMPLETE_INTEL; break; default: /* unknown swap completion type */ return False; } aevent->ust = ((CARD64)awire->ust_hi << 32) | awire->ust_lo; aevent->msc = ((CARD64)awire->msc_hi << 32) | awire->msc_lo; aevent->sbc = ((CARD64)awire->sbc_hi << 32) | awire->sbc_lo; return True; } #endif #ifdef DRI2_InvalidateBuffers case DRI2_InvalidateBuffers: { xDRI2InvalidateBuffers *awire = (xDRI2InvalidateBuffers *)wire; dri2InvalidateBuffers(dpy, awire->drawable); return False; } #endif default: /* client doesn't support server event */ break; } #endif return False; }
Bool _vdp_DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName) { XExtDisplayInfo *info = DRI2FindDisplay(dpy); xDRI2ConnectReply rep; xDRI2ConnectReq *req; XextCheckExtension(dpy, info, dri2ExtensionName, False); LockDisplay(dpy); GetReq(DRI2Connect, req); req->reqType = info->codes->major_opcode; req->dri2ReqType = X_DRI2Connect; req->window = window; req->driverType = DRI2DriverVDPAU; if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) { UnlockDisplay(dpy); SyncHandle(); return False; } *driverName = Xmalloc(rep.driverNameLength + 1); if (*driverName == NULL) { _XEatData(dpy, ((rep.driverNameLength + 3) & ~3) + ((rep.deviceNameLength + 3) & ~3)); UnlockDisplay(dpy); SyncHandle(); return False; } _XReadPad(dpy, *driverName, rep.driverNameLength); (*driverName)[rep.driverNameLength] = '\0'; *deviceName = Xmalloc(rep.deviceNameLength + 1); if (*deviceName == NULL) { Xfree(*driverName); _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3)); UnlockDisplay(dpy); SyncHandle(); return False; } _XReadPad(dpy, *deviceName, rep.deviceNameLength); (*deviceName)[rep.deviceNameLength] = '\0'; UnlockDisplay(dpy); SyncHandle(); return True; }
/* We don't actually support this. It doesn't make sense for clients to * send each other DRI2 events. */ static Status DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire) { XExtDisplayInfo *info = DRI2FindDisplay(dpy); XextCheckExtension(dpy, info, dri2ExtensionName, False); switch (event->type) { default: /* client doesn't support server event */ break; } return Success; }
Bool DRI2QueryVersion(Display * dpy, int *major, int *minor) { XExtDisplayInfo *info = DRI2FindDisplay(dpy); xDRI2QueryVersionReply rep; xDRI2QueryVersionReq *req; int i, nevents; XextCheckExtension(dpy, info, dri2ExtensionName, False); LockDisplay(dpy); GetReq(DRI2QueryVersion, req); req->reqType = info->codes->major_opcode; req->dri2ReqType = X_DRI2QueryVersion; req->majorVersion = DRI2_MAJOR; req->minorVersion = DRI2_MINOR; if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } *major = rep.majorVersion; *minor = rep.minorVersion; UnlockDisplay(dpy); SyncHandle(); switch (rep.minorVersion) { case 1: nevents = 0; break; case 2: nevents = 1; break; case 3: default: nevents = 2; break; } for (i = 0; i < nevents; i++) { XESetWireToEvent (dpy, info->codes->first_event + i, DRI2WireToEvent); XESetEventToWire (dpy, info->codes->first_event + i, DRI2EventToWire); } return True; }
Status XevieEnd(Display *dpy) { XExtDisplayInfo *info = find_display (dpy); xXevieEndReply rep; xXevieEndReq *req; XextCheckExtension (dpy, info, xevie_extension_name, False); LockDisplay(dpy); GetReq(XevieEnd, req); req->reqType = info->codes->major_opcode; req->xevieReqType = X_XevieEnd; if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { } UnlockDisplay(dpy); SyncHandle(); return True; }
static Bool DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire) { XExtDisplayInfo *info = DRI2FindDisplay(dpy); struct glx_drawable *glxDraw; XextCheckExtension(dpy, info, dri2ExtensionName, False); switch ((wire->u.u.type & 0x7f) - info->codes->first_event) { #ifdef X_DRI2SwapBuffers case DRI2_BufferSwapComplete: { GLXBufferSwapComplete *aevent = (GLXBufferSwapComplete *)event; xDRI2BufferSwapComplete2 *awire = (xDRI2BufferSwapComplete2 *)wire; __GLXDRIdrawable *pdraw; pdraw = dri2GetGlxDrawableFromXDrawableId(dpy, awire->drawable); if (pdraw == NULL) return False; /* Ignore swap events if we're not looking for them */ aevent->type = dri2GetSwapEventType(dpy, awire->drawable); if(!aevent->type) return False; aevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire); aevent->send_event = (awire->type & 0x80) != 0; aevent->display = dpy; aevent->drawable = awire->drawable; switch (awire->event_type) { case DRI2_EXCHANGE_COMPLETE: aevent->event_type = GLX_EXCHANGE_COMPLETE_INTEL; break; case DRI2_BLIT_COMPLETE: aevent->event_type = GLX_COPY_COMPLETE_INTEL; break; case DRI2_FLIP_COMPLETE: aevent->event_type = GLX_FLIP_COMPLETE_INTEL; break; default: /* unknown swap completion type */ return False; } aevent->ust = ((CARD64)awire->ust_hi << 32) | awire->ust_lo; aevent->msc = ((CARD64)awire->msc_hi << 32) | awire->msc_lo; glxDraw = GetGLXDrawable(dpy, pdraw->drawable); if (glxDraw != NULL) { if (awire->sbc < glxDraw->lastEventSbc) glxDraw->eventSbcWrap += 0x100000000; glxDraw->lastEventSbc = awire->sbc; aevent->sbc = awire->sbc + glxDraw->eventSbcWrap; } else { aevent->sbc = awire->sbc; } return True; } #endif #ifdef DRI2_InvalidateBuffers case DRI2_InvalidateBuffers: { xDRI2InvalidateBuffers *awire = (xDRI2InvalidateBuffers *)wire; dri2InvalidateBuffers(dpy, awire->drawable); return False; } #endif default: /* client doesn't support server event */ break; } return False; }
Bool DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName) { XExtDisplayInfo *info = DRI2FindDisplay(dpy); xDRI2ConnectReply rep; xDRI2ConnectReq *req; XextCheckExtension(dpy, info, dri2ExtensionName, False); LockDisplay(dpy); GetReq(DRI2Connect, req); req->reqType = info->codes->major_opcode; req->dri2ReqType = X_DRI2Connect; req->window = window; req->driverType = DRI2DriverDRI; #ifdef DRI2DriverPrimeShift { char *prime = getenv("DRI_PRIME"); if (prime) { uint32_t primeid; errno = 0; primeid = strtoul(prime, NULL, 0); if (errno == 0) req->driverType |= ((primeid & DRI2DriverPrimeMask) << DRI2DriverPrimeShift); } } #endif if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) { UnlockDisplay(dpy); SyncHandle(); return False; } *driverName = malloc(rep.driverNameLength + 1); if (*driverName == NULL) { _XEatData(dpy, ((rep.driverNameLength + 3) & ~3) + ((rep.deviceNameLength + 3) & ~3)); UnlockDisplay(dpy); SyncHandle(); return False; } _XReadPad(dpy, *driverName, rep.driverNameLength); (*driverName)[rep.driverNameLength] = '\0'; *deviceName = malloc(rep.deviceNameLength + 1); if (*deviceName == NULL) { free(*driverName); _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3)); UnlockDisplay(dpy); SyncHandle(); return False; } _XReadPad(dpy, *deviceName, rep.deviceNameLength); (*deviceName)[rep.deviceNameLength] = '\0'; UnlockDisplay(dpy); SyncHandle(); return True; }
Status XcupStoreColors( Display* dpy, Colormap colormap, XColor* colors_in_out, int ncolors) { XExtDisplayInfo *info = find_display (dpy); xXcupStoreColorsReply rep; xXcupStoreColorsReq *req; xColorItem rbuf[256]; xColorItem citem; int i; XColor* xcp; XextCheckExtension (dpy, info, xcup_extension_name, False); LockDisplay(dpy); GetReq(XcupStoreColors, req); req->reqType = info->codes->major_opcode; req->xcupReqType = X_XcupStoreColors; req->cmap = colormap; req->length += (ncolors * SIZEOF(xColorItem)) >> 2; for (i = 0, xcp = colors_in_out; i < ncolors; i++, xcp++) { citem.pixel = xcp->pixel; citem.red = xcp->red; citem.green = xcp->green; citem.blue = xcp->blue; /* note that xColorItem doesn't contain all 16-bit quantities, so we can't use Data16 */ Data(dpy, (char *)&citem, (long) SIZEOF(xColorItem)); } if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { long nbytes; xColorItem* rbufp; xColorItem* cs; int nentries = rep.length / 3; nbytes = nentries * SIZEOF (xColorItem); if (nentries != ncolors) { _XEatData (dpy, (unsigned long) nbytes); UnlockDisplay (dpy); SyncHandle (); return False; } if (ncolors > 256) rbufp = (xColorItem*) Xmalloc (nbytes); else rbufp = rbuf; if (rbufp == NULL) { _XEatData (dpy, (unsigned long) nbytes); UnlockDisplay (dpy); SyncHandle (); return False; } _XRead (dpy, (char*) rbufp, nbytes); for (i = 0, xcp = colors_in_out, cs = rbufp; i < ncolors; i++, xcp++, cs++) { xcp->pixel = cs->pixel; xcp->red = cs->red; xcp->green = cs->green; xcp->blue = cs->blue; xcp->flags = cs->flags; } if (rbufp != rbuf) XFree ((char*)rbufp); UnlockDisplay(dpy); SyncHandle(); return True; } UnlockDisplay(dpy); SyncHandle(); return False; }
Status XcupGetReservedColormapEntries( Display* dpy, int screen, XColor** colors_out, int* ncolors) { XExtDisplayInfo *info = find_display (dpy); xXcupGetReservedColormapEntriesReply rep; xXcupGetReservedColormapEntriesReq *req; xColorItem rbuf[TYP_RESERVED_ENTRIES]; *ncolors = 0; XextCheckExtension (dpy, info, xcup_extension_name, False); LockDisplay(dpy); GetReq(XcupGetReservedColormapEntries, req); req->reqType = info->codes->major_opcode; req->xcupReqType = X_XcupGetReservedColormapEntries; req->screen = screen; if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { long nbytes; xColorItem* rbufp; int nentries = rep.length / 3; nbytes = nentries * SIZEOF (xColorItem); if (nentries > TYP_RESERVED_ENTRIES) rbufp = (xColorItem*) Xmalloc (nbytes); else rbufp = rbuf; if (rbufp == NULL) { _XEatData (dpy, (unsigned long) nbytes); UnlockDisplay (dpy); SyncHandle (); return False; } _XRead (dpy, (char*) rbufp, nbytes); *colors_out = (XColor*) Xmalloc (nentries * sizeof (XColor)); if (*colors_out) { xColorItem* cs = (xColorItem *) rbufp; XColor* cd = *colors_out; int i; *ncolors = nentries; for (i = 0; i < *ncolors; i++, cd++) { cd->pixel = cs->pixel; cd->red = cs->red; cd->green = cs->green; cd->blue = cs->blue; cs = (xColorItem*) (((char*) cs) + SIZEOF(xColorItem)); } if (rbufp != rbuf) XFree ((char*) rbufp); UnlockDisplay(dpy); SyncHandle(); return True; } if (rbufp != rbuf) XFree ((char*) rbufp); } UnlockDisplay(dpy); SyncHandle(); return False; }