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