Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / glx / x11 / glx_query.c
1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
2 /*
3 * (C) Copyright IBM Corporation 2004
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file glx_query.c
28 * Generic utility functions to query internal data from the server.
29 *
30 * \author Ian Romanick <idr@us.ibm.com>
31 */
32
33 #include "glxclient.h"
34
35 /**
36 * GLX protocol structure for the ficticious "GXLGenericGetString" request.
37 *
38 * This is a non-existant protocol packet. It just so happens that all of
39 * the real protocol packets used to request a string from the server have
40 * an identical binary layout. The only difference between them is the
41 * meaning of the \c for_whom field and the value of the \c glxCode.
42 */
43 typedef struct GLXGenericGetString
44 {
45 CARD8 reqType;
46 CARD8 glxCode;
47 CARD16 length B16;
48 CARD32 for_whom B32;
49 CARD32 name B32;
50 } xGLXGenericGetStringReq;
51
52 /* These defines are only needed to make the GetReq macro happy.
53 */
54 #define sz_xGLXGenericGetStringReq 12
55 #define X_GLXGenericGetString 0
56
57 /**
58 * Query the Server GLX string.
59 * This routine will allocate the necessay space for the string.
60 */
61 char *
62 __glXGetStringFromServer(Display * dpy, int opcode, CARD32 glxCode,
63 CARD32 for_whom, CARD32 name)
64 {
65 xGLXGenericGetStringReq *req;
66 xGLXSingleReply reply;
67 int length;
68 int numbytes;
69 char *buf;
70
71
72 LockDisplay(dpy);
73
74
75 /* All of the GLX protocol requests for getting a string from the server
76 * look the same. The exact meaning of the for_whom field is usually
77 * either the screen number (for glXQueryServerString) or the context tag
78 * (for GLXSingle).
79 */
80
81 GetReq(GLXGenericGetString, req);
82 req->reqType = opcode;
83 req->glxCode = glxCode;
84 req->for_whom = for_whom;
85 req->name = name;
86
87 _XReply(dpy, (xReply *) & reply, 0, False);
88
89 length = reply.length * 4;
90 numbytes = reply.size;
91
92 buf = (char *) Xmalloc(numbytes);
93 if (buf != NULL) {
94 _XRead(dpy, buf, numbytes);
95 length -= numbytes;
96 }
97
98 _XEatData(dpy, length);
99
100 UnlockDisplay(dpy);
101 SyncHandle();
102
103 return buf;
104 }