Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
/**
 * Read new data in the image structure.
 *
 * @param dpy X11 display to grab from
 * @param d
 * @param image Image where the grab will be put
 * @param x Top-Left grabbing rectangle horizontal coordinate
 * @param y Top-Left grabbing rectangle vertical coordinate
 * @return 0 if error, !0 if successful
 */
static int xget_zpixmap(Display *dpy, Drawable d, XImage *image, int x, int y)
{
    xGetImageReply rep;
    xGetImageReq *req;
    long nbytes;

    if (!image)
        return 0;

    LockDisplay(dpy);
    GetReq(GetImage, req);

    /* First set up the standard stuff in the request */
    req->drawable  = d;
    req->x         = x;
    req->y         = y;
    req->width     = image->width;
    req->height    = image->height;
    req->planeMask = (unsigned int)AllPlanes;
    req->format    = ZPixmap;

    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.length) {
        UnlockDisplay(dpy);
        SyncHandle();
        return 0;
    }

    nbytes = (long)rep.length << 2;
    _XReadPad(dpy, image->data, nbytes);

    UnlockDisplay(dpy);
    SyncHandle();
    return 1;
}
Exemplo n.º 3
0
const char *
XFixesGetCursorName (Display *dpy, Cursor cursor, Atom *atom)
{
    XFixesExtDisplayInfo	*info = XFixesFindDisplay (dpy);
    xXFixesGetCursorNameReq	*req;
    xXFixesGetCursorNameReply	rep;
    char			*name;

    XFixesCheckExtension (dpy, info, NULL);
    if (info->major_version < 2)
	return NULL;
    LockDisplay (dpy);
    GetReq (XFixesGetCursorName, req);
    req->reqType = info->codes->major_opcode;
    req->xfixesReqType = X_XFixesGetCursorName;
    req->cursor = cursor;
    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
    {
	UnlockDisplay (dpy);
	SyncHandle ();
	return NULL;
    }
    *atom = rep.atom;
    if ((name = (char *) Xmalloc(rep.nbytes+1))) {
	_XReadPad(dpy, name, (long)rep.nbytes);
	name[rep.nbytes] = '\0';
    } else {
	_XEatData(dpy, (unsigned long) (rep.nbytes + 3) & ~3);
	name = (char *) NULL;
    }
    UnlockDisplay(dpy);
    SyncHandle();
    return(name);
}
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;
}
Exemplo n.º 5
0
char *
XpGetAttributes (
    Display       *dpy,
    XPContext     print_context,
    XPAttributes  type
)
{
    char *buf;

    xPrintGetAttributesReq     *req;
    xPrintGetAttributesReply   rep;
    XExtensionVersion          *ext;
    XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);


    if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
        return( (char *) NULL ); /* No such extension */

    LockDisplay (dpy);

    GetReq(PrintGetAttributes,req);
    req->reqType = info->codes->major_opcode;
    req->printReqType = X_PrintGetAttributes;
    req->printContext = print_context;
    req->type = type;

    if (! _XReply (dpy, (xReply *) &rep, 0, xFalse)) {
        UnlockDisplay(dpy);
        SyncHandle();
        return( (char *) NULL ); /* No such extension */
    }

    /*
     * Read pool and return to caller.
     */
    buf = Xmalloc( (unsigned) rep.stringLen + 1 );

    if (!buf) {
        UnlockDisplay(dpy);
        SyncHandle();
        return( (char *) NULL ); /* malloc error */
    }

    _XReadPad (dpy, (char *) buf, (long) rep.stringLen );

    buf[rep.stringLen] = 0;

    UnlockDisplay(dpy);
    SyncHandle();

    return( buf );
}
Exemplo n.º 6
0
int
XiGMiscQueryResolutions(Display * dpy, int screen, int view, int *pactive,
                        XiGMiscResolutionInfo ** presolutions)
{
    int n, size;
    XiGMiscResolutionInfo *resolutions;
    xXiGMiscQueryResolutionsReq *req;
    xXiGMiscQueryResolutionsReply rep;
    XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
    XiGMiscCheckExtension(dpy, info, 0);

    LockDisplay(dpy);
    XiGMiscGetReq(XiGMiscQueryResolutions, req, info);
    req->screen = screen;
    req->view = view;

    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
        UnlockDisplay(dpy);
        SyncHandle();
        return 0;
    }

    n = rep.nresolutions;

    if (n > 0) {
        size = sizeof(XiGMiscResolutionInfo) * n;
        resolutions = (XiGMiscResolutionInfo *) Xmalloc(size);
        if (!resolutions) {
            _XEatData(dpy, (unsigned long) size);
            UnlockDisplay(dpy);
            SyncHandle();
            return 0;
        }

        _XReadPad(dpy, (void *) resolutions, size);

        *presolutions = resolutions;
        *pactive = rep.active;
    }

    UnlockDisplay(dpy);
    SyncHandle();

    return n;
}
Exemplo n.º 7
0
int
XiGMiscQueryViews(Display * dpy, int screen, XiGMiscViewInfo ** pviews)
{
    int n, size;
    XiGMiscViewInfo *views;
    xXiGMiscQueryViewsReq *req;
    xXiGMiscQueryViewsReply rep;
    XExtDisplayInfo *info = XiGMiscFindDisplay(dpy);
    XiGMiscCheckExtension(dpy, info, 0);

    LockDisplay(dpy);
    XiGMiscGetReq(XiGMiscQueryViews, req, info);
    req->screen = screen;

    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
        UnlockDisplay(dpy);
        SyncHandle();
        return 0;
    }

    n = rep.nviews;

    if (n > 0) {
        size = sizeof(XiGMiscViewInfo) * n;
        views = (XiGMiscViewInfo *) Xmalloc(size);
        if (!views) {
            _XEatData(dpy, (unsigned long) size);
            UnlockDisplay(dpy);
            SyncHandle();
            return 0;
        }

        _XReadPad(dpy, (void *) views, size);

        *pviews = views;
    }

    UnlockDisplay(dpy);
    SyncHandle();

    return n;
}
Exemplo n.º 8
0
XModifierKeymap *
XGetDeviceModifierMapping(
    register Display	*dpy,
    XDevice		*dev)
{
    unsigned long nbytes;
    XModifierKeymap *res;
    xGetDeviceModifierMappingReq *req;
    xGetDeviceModifierMappingReply rep;
    XExtDisplayInfo *info = XInput_find_display(dpy);

    LockDisplay(dpy);
    if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1)
	return ((XModifierKeymap *) NoSuchExtension);

    GetReq(GetDeviceModifierMapping, req);
    req->reqType = info->codes->major_opcode;
    req->ReqType = X_GetDeviceModifierMapping;
    req->deviceid = dev->device_id;

    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
	UnlockDisplay(dpy);
	SyncHandle();
	return (XModifierKeymap *) NULL;
    }
    nbytes = (unsigned long)rep.length << 2;
    res = (XModifierKeymap *) Xmalloc(sizeof(XModifierKeymap));
    if (res) {
	res->modifiermap = (KeyCode *) Xmalloc(nbytes);
	if (res->modifiermap)
	    _XReadPad(dpy, (char *)res->modifiermap, nbytes);
	else
	    _XEatData(dpy, (unsigned long)nbytes);
	res->max_keypermod = rep.numKeyPerModifier;
    }

    UnlockDisplay(dpy);
    SyncHandle();
    return (res);
}
Exemplo n.º 9
0
char *
XpGetOneAttribute (
    Display       *dpy,
    XPContext     print_context,
    XPAttributes  type,
    char          *attribute_name
)
{
    int     buflen = 0;
    char    *buf;

    xPrintGetOneAttributeReq     *req;
    xPrintGetOneAttributeReply   rep;
    XExtensionVersion          *ext;
    XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);


    if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
        return( (char *) NULL ); /* No such extension */

    LockDisplay (dpy);

    GetReq(PrintGetOneAttribute,req);
    req->reqType = info->codes->major_opcode;
    req->printReqType = X_PrintGetOneAttribute;
    req->type = type;
    req->printContext = print_context;
    req->nameLen = strlen( attribute_name );

    /*
     * Attach variable data and adjust request length.
     */
    req->length += _XpPadOut(req->nameLen) >> 2 ;
    Data( dpy, (char *) attribute_name, req->nameLen );    /* n bytes + pad */

    if (! _XReply (dpy, (xReply *) &rep, 0, xFalse)) {
        UnlockDisplay(dpy);
        SyncHandle();
        return( (char *) NULL ); /* No such extension */
    }

    /*
     * Read variable answer.
     */
    buf = Xmalloc( (unsigned) rep.valueLen + 1 );

    if (!buf) {
        UnlockDisplay(dpy);
        SyncHandle();
        return( (char *) NULL ); /* malloc error */
    }

    buf[rep.valueLen] = 0;

    _XReadPad (dpy, (char *) buf, (long) rep.valueLen );
    buf[rep.valueLen] = 0;

    UnlockDisplay(dpy);
    SyncHandle();

    return( buf );
}
Exemplo n.º 10
0
static void
CalcServerVersionAndExtensions(void)
{
    int s;
    char **be_extensions;
    char *ext;
    char *denied_extensions;

    /*
     * set the server glx version to be the minimum version
     * supported by all back-end servers
     */
    __glXVersionMajor = 0;
    __glXVersionMinor = 0;
    for (s = 0; s < __glXNumActiveScreens; s++) {
        DMXScreenInfo *dmxScreen = &dmxScreens[s];
        Display *dpy = dmxScreen->beDisplay;
        xGLXQueryVersionReq *req;
        xGLXQueryVersionReply reply;

        /* Send the glXQueryVersion request */
        LockDisplay(dpy);
        GetReq(GLXQueryVersion, req);
        req->reqType = dmxScreen->glxMajorOpcode;
        req->glxCode = X_GLXQueryVersion;
        req->majorVersion = GLX_SERVER_MAJOR_VERSION;
        req->minorVersion = GLX_SERVER_MINOR_VERSION;
        _XReply(dpy, (xReply *) &reply, 0, False);
        UnlockDisplay(dpy);
        SyncHandle();

        if (s == 0) {
            __glXVersionMajor = reply.majorVersion;
            __glXVersionMinor = reply.minorVersion;
        }
        else {
            if (reply.majorVersion < __glXVersionMajor) {
                __glXVersionMajor = reply.majorVersion;
                __glXVersionMinor = reply.minorVersion;
            }
            else if ((reply.majorVersion == __glXVersionMajor) &&
                     (reply.minorVersion < __glXVersionMinor)) {
                __glXVersionMinor = reply.minorVersion;
            }
        }

    }

    if (GLX_SERVER_MAJOR_VERSION < __glXVersionMajor) {
        __glXVersionMajor = GLX_SERVER_MAJOR_VERSION;
        __glXVersionMinor = GLX_SERVER_MINOR_VERSION;
    }
    else if ((GLX_SERVER_MAJOR_VERSION == __glXVersionMajor) &&
             (GLX_SERVER_MINOR_VERSION < __glXVersionMinor)) {
        __glXVersionMinor = GLX_SERVER_MINOR_VERSION;
    }

    snprintf(GLXServerVersion, sizeof(GLXServerVersion),
             "%d.%d DMX %d back-end server(s)",
             __glXVersionMajor, __glXVersionMinor, __glXNumActiveScreens);
    /*
     * set the ExtensionsString to the minimum extensions string
     */
    ExtensionsString[0] = '\0';

    /*
     * read extensions strings of all back-end servers
     */
    be_extensions = (char **) malloc(__glXNumActiveScreens * sizeof(char *));
    if (!be_extensions)
        return;

    for (s = 0; s < __glXNumActiveScreens; s++) {
        DMXScreenInfo *dmxScreen = &dmxScreens[s];
        Display *dpy = dmxScreen->beDisplay;
        xGLXQueryServerStringReq *req;
        xGLXQueryServerStringReply reply;
        int length, numbytes;

        /* Send the glXQueryServerString request */
        LockDisplay(dpy);
        GetReq(GLXQueryServerString, req);
        req->reqType = dmxScreen->glxMajorOpcode;
        req->glxCode = X_GLXQueryServerString;
        req->screen = DefaultScreen(dpy);
        req->name = GLX_EXTENSIONS;
        _XReply(dpy, (xReply *) &reply, 0, False);

        length = (int) reply.length;
        numbytes = (int) reply.n;
        be_extensions[s] = (char *) malloc(numbytes);
        if (!be_extensions[s]) {
            /* Throw data on the floor */
            _XEatDataWords(dpy, length);
        }
        else {
            _XReadPad(dpy, (char *) be_extensions[s], numbytes);
        }
        UnlockDisplay(dpy);
        SyncHandle();
    }

    /*
     * extensions string will include only extensions that our
     * server supports as well as all back-end servers supports.
     * extensions that are in the DMX_DENY_EXTENSIONS string will
     * not be supported.
     */
    denied_extensions = getenv("DMX_DENY_GLX_EXTENSIONS");
    ext = strtok(GLXServerExtensions, " ");
    while (ext) {
        int supported = 1;

        if (denied_extensions && strstr(denied_extensions, ext)) {
            supported = 0;
        }
        else {
            for (s = 0; s < __glXNumActiveScreens && supported; s++) {
                if (!strstr(be_extensions[s], ext)) {
                    supported = 0;
                }
            }
        }

        if (supported) {
            strcat(ExtensionsString, ext);
            strcat(ExtensionsString, " ");
        }

        ext = strtok(NULL, " ");
    }

    /*
     * release temporary storage
     */
    for (s = 0; s < __glXNumActiveScreens; s++) {
        free(be_extensions[s]);
    }
    free(be_extensions);

    if (dmxGLXSwapGroupSupport) {
        if (!denied_extensions ||
            !strstr(denied_extensions, "GLX_SGIX_swap_group")) {
            strcat(ExtensionsString, "GLX_SGIX_swap_group");
            if (!denied_extensions ||
                !strstr(denied_extensions, "GLX_SGIX_swap_barrier")) {
                strcat(ExtensionsString, " GLX_SGIX_swap_barrier");
            }
        }
    }

}
Exemplo n.º 11
0
Arquivo: XpPrinter.c Projeto: aosm/X11
XPPrinterList
XpGetPrinterList (
    Display     *dpy,
    char        *printer_name,
    int         *list_count             /* return value */
)
{
    xPrintGetPrinterListReq     *req;
    xPrintGetPrinterListReply   rep;

    int		printer_name_len, locale_len;
    char        *locale;

    /* For decoding the variable portion of Reply */
    long	dataLenVR;
    CARD8	*dataVR;	/* aka STRING8 */

    XPPrinterList ptr_list;

    XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);

    /* For converting root winID to corresponding ScreenPtr */
    int    i;


    if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
        return ( (XPPrinterList) NULL ); /* No such extension */

    /*
     * Fetch locale information. Note: XpGetLocaleNetString has
     * a thread-safe mutex on _Xglobal_lock.
     */
    locale = XpGetLocaleNetString();

    LockDisplay (dpy);

    GetReq(PrintGetPrinterList,req);
    req->reqType = info->codes->major_opcode;
    req->printReqType = X_PrintGetPrinterList;

    /*
     * Compute lengths of variable portions.
     */
    if ( printer_name == (char *) NULL )
	req->printerNameLen = 0;
    else if ( *printer_name == (char) NULL )
	req->printerNameLen = 0;
    else {
	printer_name_len    = strlen( printer_name );
	req->length        += _XpPadOut(printer_name_len) >> 2;
	req->printerNameLen = (unsigned long) printer_name_len;
    }

    if ( locale == (char *) NULL )
	req->localeLen = 0;
    else if ( *locale == (char) NULL )
	req->localeLen = 0;
    else {
	locale_len     = strlen( locale );
	req->length   += _XpPadOut(locale_len) >> 2;
	req->localeLen = (unsigned long) locale_len;
    }

    /*
     * Attach variable data.
     */
    if (req->printerNameLen)
	Data( dpy, (char *) printer_name, (long) req->printerNameLen );

    if (req->localeLen)
	Data( dpy, (char *) locale, (long) req->localeLen );

    if (! _XReply (dpy, (xReply *) &rep, 0, xFalse)) {
        UnlockDisplay(dpy);
        SyncHandle();
        return ( (XPPrinterList) NULL ); /* error */
    }

    XFree(locale);

    *list_count = rep.listCount;

    if (*list_count) {
	ptr_list = (XPPrinterList)
		Xmalloc( (unsigned) (sizeof(XPPrinterRec) * (*list_count + 1)));

	if (!ptr_list) {
            UnlockDisplay(dpy);
            SyncHandle();
            return ( (XPPrinterList) NULL ); /* malloc error */
	}

	/*
	 * NULL last entry so XpFreePrinterList can work without a list_count
	 */
	ptr_list[*list_count].name = (char *) NULL;
	ptr_list[*list_count].desc = (char *) NULL;

	for ( i = 0; i < *list_count; i++ ) {
	    /*
	     * Pull printer length and then name.
	     */
	    _XRead32 (dpy, &dataLenVR, (long) sizeof(CARD32) );

	    if (dataLenVR) {
		dataVR = (CARD8 *) Xmalloc( (unsigned) dataLenVR + 1 );

		if (!dataVR) {
		    UnlockDisplay(dpy);
		    SyncHandle();
		    return ( (XPPrinterList) NULL ); /* malloc error */
		}

		_XReadPad (dpy, (char *) dataVR, (long) dataLenVR);
		dataVR[dataLenVR] = 0;
		ptr_list[i].name = (char *) dataVR;
	    }
	    else {
		ptr_list[i].name = (char *) NULL;
	    }

	    /*
	     * Pull localized description length and then description.
	     */
	    _XRead32 (dpy, &dataLenVR, (long) sizeof(CARD32) );

	    if (dataLenVR) {
		dataVR = (CARD8 *) Xmalloc( (unsigned) dataLenVR + 1 );

		if (!dataVR) {
		    UnlockDisplay(dpy);
		    SyncHandle();
		    return ( (XPPrinterList) NULL ); /* malloc error */
		}

		_XReadPad (dpy, (char *) dataVR, (long) dataLenVR);
		dataVR[dataLenVR] = 0;
		ptr_list[i].desc = (char *) dataVR;
	    }
	    else {
		ptr_list[i].desc = (char *) NULL;
	    }
	}
    }
    else {
	ptr_list = (XPPrinterList) NULL;
    }

    UnlockDisplay(dpy);
    SyncHandle();

    return ( ptr_list );
}
Exemplo n.º 12
0
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;
}
uint32_t *GetX11(uint16_t x, uint16_t y, uint16_t *w, uint16_t *h){
	xGetImageReply rep;
	xGetImageReq *req;
	long nbytes;

	if(!image){
		return 0;
	}
	XGetWindowAttributes(dpy, CaptureWin, &gwa);

	if(image->width != gwa.width || image->height != gwa.height){
		printf("X11 Window: Changed W/H\n");
		*w = gwa.width;
		*h = gwa.height;
		XFree(image);
#ifdef X11_USE_XSHM_
		if(use_shm) {
			int scr = XDefaultScreen(dpy);
			image = XShmCreateImage(dpy,
						DefaultVisual(dpy, scr),
						DefaultDepth(dpy, scr),
						ZPixmap,
						NULL,
						&shminfo,
						w, h);
			shminfo.shmid = shmget(	IPC_PRIVATE,
						image->bytes_per_line * image->height,
						IPC_CREAT|0777);
			if(shminfo.shmid == -1){
				printf("shminfo.shmid == -1\n");
				return 0;
			}
			shminfo.shmaddr = image->data = (char*) shmat(shminfo.shmid, 0, 0);
			shminfo.readOnly = False;

			if(!XShmAttach(dpy, &shminfo)){
				printf("!XShmAttach(dpy, &shminfo)\n");
				return 0;
			}
		}
		else{
#endif /*X11_USE_XSHM_*/
			image = XGetImage(dpy, CaptureWin,
					  x,y,
					  gwa.width,gwa.height,
					  AllPlanes, ZPixmap);
#ifdef X11_USE_XSHM_
		}
#endif /*X11_USE_XSHM_*/
	}

	/* Here i should add a check to be sure that the window is still open */
	LockDisplay(dpy);
	GetReq(GetImage, req);

	req->drawable = CaptureWin;
	req->x = x;
	req->y = y;
	req->width = gwa.width;
	req->height = gwa.height;
	req->planeMask = (unsigned int)AllPlanes;
	req->format = ZPixmap;

	if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.length) {
		UnlockDisplay(dpy);
		SyncHandle();
		return 0;
	}

	nbytes = (long)rep.length << 2;
	_XReadPad(dpy, image->data, nbytes);

	UnlockDisplay(dpy);
	SyncHandle();

	return (uint32_t*) image->data;
}
Exemplo n.º 14
0
Arquivo: dri3.c Projeto: sarnex/wine
static BOOL
DRI2Connect(Display *dpy,
            XID window,
            unsigned driver_type,
            char **device )
{
    XExtDisplayInfo *info = find_display(dpy);
    xDRI2ConnectReply rep;
    xDRI2ConnectReq *req;
    int dev_len, driv_len;
    char *driver;

    DRI2CheckExtension(dpy, info, False);

    LockDisplay(dpy);
    GetReq(DRI2Connect, req);
    req->reqType = info->codes->major_opcode;
    req->dri2ReqType = X_DRI2Connect;
    req->window = window;
    req->driverType = driver_type;
    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
        UnlockDisplay(dpy);
        SyncHandle();
        return False;
    }

    /* check string lengths */
    dev_len = rep.deviceNameLength;
    driv_len = rep.driverNameLength;
    if (dev_len == 0 || driv_len == 0) {
        _XEatData(dpy, XALIGN(dev_len) + XALIGN(driv_len));
        UnlockDisplay(dpy);
        SyncHandle();
        return False;
    }

    /* read out driver */
    driver = HeapAlloc(GetProcessHeap(), 0, driv_len + 1);
    if (!driver) {
        _XEatData(dpy, XALIGN(dev_len) + XALIGN(driv_len));
        UnlockDisplay(dpy);
        SyncHandle();
        return False;
    }
    _XReadPad(dpy, driver, driv_len);
    HeapFree(GetProcessHeap(), 0, driver); /* we don't need the driver */

    /* read out device */
    *device = HeapAlloc(GetProcessHeap(), 0, dev_len + 1);
    if (!*device) {
        _XEatData(dpy, XALIGN(dev_len));
        UnlockDisplay(dpy);
        SyncHandle();
        return False;
    }
    _XReadPad(dpy, *device, dev_len);
    (*device)[dev_len] = '\0';

    UnlockDisplay(dpy);
    SyncHandle();

    return True;
}