glx_query.c revision af69d88d
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 *
43cdc920a0Smrg__glXQueryServerString(Display * dpy, int opcode, 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
53cdc920a0Smrg   /* The spec doesn't mention this, but the Xorg server replies with
54cdc920a0Smrg    * a string already terminated with '\0'. */
55cdc920a0Smrg   uint32_t len = xcb_glx_query_server_string_string_length(reply);
56af69d88dSmrg   char *buf = malloc(len);
57cdc920a0Smrg   memcpy(buf, xcb_glx_query_server_string_string(reply), len);
58cdc920a0Smrg   free(reply);
59cdc920a0Smrg
60cdc920a0Smrg   return buf;
61cdc920a0Smrg}
62cdc920a0Smrg
63cdc920a0Smrg/**
64cdc920a0Smrg * Exchange a protocol request for glGetString.
65cdc920a0Smrg */
66cdc920a0Smrgchar *
67cdc920a0Smrg__glXGetString(Display * dpy, int opcode, CARD32 contextTag, CARD32 name)
68cdc920a0Smrg{
69cdc920a0Smrg   xcb_connection_t *c = XGetXCBConnection(dpy);
70cdc920a0Smrg   xcb_glx_get_string_reply_t *reply = xcb_glx_get_string_reply(c,
71cdc920a0Smrg                                                                xcb_glx_get_string
72cdc920a0Smrg                                                                (c,
73cdc920a0Smrg                                                                 contextTag,
74cdc920a0Smrg                                                                 name),
75cdc920a0Smrg                                                                NULL);
76cdc920a0Smrg
77cdc920a0Smrg   /* The spec doesn't mention this, but the Xorg server replies with
78cdc920a0Smrg    * a string already terminated with '\0'. */
79cdc920a0Smrg   uint32_t len = xcb_glx_get_string_string_length(reply);
80af69d88dSmrg   char *buf = malloc(len);
81cdc920a0Smrg   memcpy(buf, xcb_glx_get_string_string(reply), len);
82cdc920a0Smrg   free(reply);
83cdc920a0Smrg
84cdc920a0Smrg   return buf;
85cdc920a0Smrg}
86cdc920a0Smrg
87