1cdc920a0Smrg/* 2cdc920a0Smrg * (C) Copyright IBM Corporation 2004 3cdc920a0Smrg * All Rights Reserved. 4cdc920a0Smrg * 5cdc920a0Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6cdc920a0Smrg * copy of this software and associated documentation files (the "Software"), 7cdc920a0Smrg * to deal in the Software without restriction, including without limitation 8cdc920a0Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 9cdc920a0Smrg * license, and/or sell copies of the Software, and to permit persons to whom 10cdc920a0Smrg * the Software is furnished to do so, subject to the following conditions: 11cdc920a0Smrg * 12cdc920a0Smrg * The above copyright notice and this permission notice (including the next 13cdc920a0Smrg * paragraph) shall be included in all copies or substantial portions of the 14cdc920a0Smrg * Software. 15cdc920a0Smrg * 16cdc920a0Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17cdc920a0Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18cdc920a0Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19cdc920a0Smrg * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20cdc920a0Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21cdc920a0Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22cdc920a0Smrg * DEALINGS IN THE SOFTWARE. 23cdc920a0Smrg */ 24cdc920a0Smrg 25cdc920a0Smrg/** 26cdc920a0Smrg * \file glx_query.c 27cdc920a0Smrg * Generic utility functions to query internal data from the server. 28cdc920a0Smrg * 29cdc920a0Smrg * \author Ian Romanick <idr@us.ibm.com> 30cdc920a0Smrg */ 31cdc920a0Smrg 32cdc920a0Smrg#include "glxclient.h" 33cdc920a0Smrg 34cdc920a0Smrg# include <X11/Xlib-xcb.h> 35cdc920a0Smrg# include <xcb/xcb.h> 36cdc920a0Smrg# include <xcb/glx.h> 37cdc920a0Smrg 38cdc920a0Smrg 39cdc920a0Smrg/** 40cdc920a0Smrg * Exchange a protocol request for glXQueryServerString. 41cdc920a0Smrg */ 42cdc920a0Smrgchar * 437ec681f3Smrg__glXQueryServerString(Display * dpy, CARD32 screen, CARD32 name) 44cdc920a0Smrg{ 45cdc920a0Smrg xcb_connection_t *c = XGetXCBConnection(dpy); 46cdc920a0Smrg xcb_glx_query_server_string_reply_t *reply = 47cdc920a0Smrg xcb_glx_query_server_string_reply(c, 48cdc920a0Smrg xcb_glx_query_server_string(c, 49cdc920a0Smrg screen, 50cdc920a0Smrg name), 51cdc920a0Smrg NULL); 52cdc920a0Smrg 539f464c52Smaya if (!reply) 549f464c52Smaya return NULL; 559f464c52Smaya 56cdc920a0Smrg /* The spec doesn't mention this, but the Xorg server replies with 57cdc920a0Smrg * a string already terminated with '\0'. */ 58cdc920a0Smrg uint32_t len = xcb_glx_query_server_string_string_length(reply); 59af69d88dSmrg char *buf = malloc(len); 60cdc920a0Smrg memcpy(buf, xcb_glx_query_server_string_string(reply), len); 61cdc920a0Smrg free(reply); 62cdc920a0Smrg 63cdc920a0Smrg return buf; 64cdc920a0Smrg} 65cdc920a0Smrg 66cdc920a0Smrg/** 67cdc920a0Smrg * Exchange a protocol request for glGetString. 68cdc920a0Smrg */ 69cdc920a0Smrgchar * 707ec681f3Smrg__glXGetString(Display * dpy, CARD32 contextTag, CARD32 name) 71cdc920a0Smrg{ 72cdc920a0Smrg xcb_connection_t *c = XGetXCBConnection(dpy); 73cdc920a0Smrg xcb_glx_get_string_reply_t *reply = xcb_glx_get_string_reply(c, 74cdc920a0Smrg xcb_glx_get_string 75cdc920a0Smrg (c, 76cdc920a0Smrg contextTag, 77cdc920a0Smrg name), 78cdc920a0Smrg NULL); 79cdc920a0Smrg 809f464c52Smaya if (!reply) 819f464c52Smaya return NULL; 829f464c52Smaya 83cdc920a0Smrg /* The spec doesn't mention this, but the Xorg server replies with 84cdc920a0Smrg * a string already terminated with '\0'. */ 85cdc920a0Smrg uint32_t len = xcb_glx_get_string_string_length(reply); 86af69d88dSmrg char *buf = malloc(len); 87cdc920a0Smrg memcpy(buf, xcb_glx_get_string_string(reply), len); 88cdc920a0Smrg free(reply); 89cdc920a0Smrg 90cdc920a0Smrg return buf; 91cdc920a0Smrg} 92cdc920a0Smrg 93