1848b8605Smrg/*
2848b8605Smrg * (C) Copyright IBM Corporation 2004
3848b8605Smrg * All Rights Reserved.
4848b8605Smrg *
5848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6848b8605Smrg * copy of this software and associated documentation files (the "Software"),
7848b8605Smrg * to deal in the Software without restriction, including without limitation
8848b8605Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
9848b8605Smrg * license, and/or sell copies of the Software, and to permit persons to whom
10848b8605Smrg * the Software is furnished to do so, subject to the following conditions:
11848b8605Smrg *
12848b8605Smrg * The above copyright notice and this permission notice (including the next
13848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the
14848b8605Smrg * Software.
15848b8605Smrg *
16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19848b8605Smrg * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20848b8605Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21848b8605Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22848b8605Smrg * DEALINGS IN THE SOFTWARE.
23848b8605Smrg */
24848b8605Smrg
25848b8605Smrg/**
26848b8605Smrg * \file glx_query.c
27848b8605Smrg * Generic utility functions to query internal data from the server.
28848b8605Smrg *
29848b8605Smrg * \author Ian Romanick <idr@us.ibm.com>
30848b8605Smrg */
31848b8605Smrg
32848b8605Smrg#include "glxclient.h"
33848b8605Smrg
34848b8605Smrg# include <X11/Xlib-xcb.h>
35848b8605Smrg# include <xcb/xcb.h>
36848b8605Smrg# include <xcb/glx.h>
37848b8605Smrg
38848b8605Smrg
39848b8605Smrg/**
40848b8605Smrg * Exchange a protocol request for glXQueryServerString.
41848b8605Smrg */
42848b8605Smrgchar *
43848b8605Smrg__glXQueryServerString(Display * dpy, int opcode, CARD32 screen, CARD32 name)
44848b8605Smrg{
45848b8605Smrg   xcb_connection_t *c = XGetXCBConnection(dpy);
46848b8605Smrg   xcb_glx_query_server_string_reply_t *reply =
47848b8605Smrg      xcb_glx_query_server_string_reply(c,
48848b8605Smrg                                        xcb_glx_query_server_string(c,
49848b8605Smrg                                                                    screen,
50848b8605Smrg                                                                    name),
51848b8605Smrg                                        NULL);
52848b8605Smrg
53b8e80941Smrg   if (!reply)
54b8e80941Smrg      return NULL;
55b8e80941Smrg
56848b8605Smrg   /* The spec doesn't mention this, but the Xorg server replies with
57848b8605Smrg    * a string already terminated with '\0'. */
58848b8605Smrg   uint32_t len = xcb_glx_query_server_string_string_length(reply);
59848b8605Smrg   char *buf = malloc(len);
60848b8605Smrg   memcpy(buf, xcb_glx_query_server_string_string(reply), len);
61848b8605Smrg   free(reply);
62848b8605Smrg
63848b8605Smrg   return buf;
64848b8605Smrg}
65848b8605Smrg
66848b8605Smrg/**
67848b8605Smrg * Exchange a protocol request for glGetString.
68848b8605Smrg */
69848b8605Smrgchar *
70848b8605Smrg__glXGetString(Display * dpy, int opcode, CARD32 contextTag, CARD32 name)
71848b8605Smrg{
72848b8605Smrg   xcb_connection_t *c = XGetXCBConnection(dpy);
73848b8605Smrg   xcb_glx_get_string_reply_t *reply = xcb_glx_get_string_reply(c,
74848b8605Smrg                                                                xcb_glx_get_string
75848b8605Smrg                                                                (c,
76848b8605Smrg                                                                 contextTag,
77848b8605Smrg                                                                 name),
78848b8605Smrg                                                                NULL);
79848b8605Smrg
80b8e80941Smrg   if (!reply)
81b8e80941Smrg      return NULL;
82b8e80941Smrg
83848b8605Smrg   /* The spec doesn't mention this, but the Xorg server replies with
84848b8605Smrg    * a string already terminated with '\0'. */
85848b8605Smrg   uint32_t len = xcb_glx_get_string_string_length(reply);
86848b8605Smrg   char *buf = malloc(len);
87848b8605Smrg   memcpy(buf, xcb_glx_get_string_string(reply), len);
88848b8605Smrg   free(reply);
89848b8605Smrg
90848b8605Smrg   return buf;
91848b8605Smrg}
92848b8605Smrg
93