1706f2543Smrg#ifdef HAVE_DIX_CONFIG_H
2706f2543Smrg#include <dix-config.h>
3706f2543Smrg#endif
4706f2543Smrg
5706f2543Smrg#ifndef _GLX_server_h_
6706f2543Smrg#define _GLX_server_h_
7706f2543Smrg
8706f2543Smrg/*
9706f2543Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
10706f2543Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
11706f2543Smrg *
12706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a
13706f2543Smrg * copy of this software and associated documentation files (the "Software"),
14706f2543Smrg * to deal in the Software without restriction, including without limitation
15706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the
17706f2543Smrg * Software is furnished to do so, subject to the following conditions:
18706f2543Smrg *
19706f2543Smrg * The above copyright notice including the dates of first publication and
20706f2543Smrg * either this permission notice or a reference to
21706f2543Smrg * http://oss.sgi.com/projects/FreeB/
22706f2543Smrg * shall be included in all copies or substantial portions of the Software.
23706f2543Smrg *
24706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25706f2543Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27706f2543Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28706f2543Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
29706f2543Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30706f2543Smrg * SOFTWARE.
31706f2543Smrg *
32706f2543Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc.
33706f2543Smrg * shall not be used in advertising or otherwise to promote the sale, use or
34706f2543Smrg * other dealings in this Software without prior written authorization from
35706f2543Smrg * Silicon Graphics, Inc.
36706f2543Smrg */
37706f2543Smrg
38706f2543Smrg#include <X11/X.h>
39706f2543Smrg#include <X11/Xproto.h>
40706f2543Smrg#include <X11/Xmd.h>
41706f2543Smrg#include <misc.h>
42706f2543Smrg#include <dixstruct.h>
43706f2543Smrg#include <pixmapstr.h>
44706f2543Smrg#include <gcstruct.h>
45706f2543Smrg#include <extnsionst.h>
46706f2543Smrg#include <resource.h>
47706f2543Smrg#include <scrnintstr.h>
48706f2543Smrg
49706f2543Smrg/*
50706f2543Smrg** The X header misc.h defines these math functions.
51706f2543Smrg*/
52706f2543Smrg#undef abs
53706f2543Smrg#undef fabs
54706f2543Smrg
55706f2543Smrg#define GL_GLEXT_PROTOTYPES /* we want prototypes */
56706f2543Smrg#include <GL/gl.h>
57706f2543Smrg#include <GL/glxproto.h>
58706f2543Smrg
59706f2543Smrg/*
60706f2543Smrg** GLX resources.
61706f2543Smrg*/
62706f2543Smrgtypedef XID GLXContextID;
63706f2543Smrgtypedef XID GLXPixmap;
64706f2543Smrgtypedef XID GLXDrawable;
65706f2543Smrg
66706f2543Smrgtypedef struct __GLXclientStateRec __GLXclientState;
67706f2543Smrgtypedef struct __GLXdrawable __GLXdrawable;
68706f2543Smrgtypedef struct __GLXcontext __GLXcontext;
69706f2543Smrg
70706f2543Smrg#include "glxscreens.h"
71706f2543Smrg#include "glxdrawable.h"
72706f2543Smrg#include "glxcontext.h"
73706f2543Smrg
74706f2543Smrg#ifndef True
75706f2543Smrg#define True 1
76706f2543Smrg#endif
77706f2543Smrg#ifndef False
78706f2543Smrg#define False 0
79706f2543Smrg#endif
80706f2543Smrg
81706f2543Smrgextern __GLXscreen *glxGetScreen(ScreenPtr pScreen);
82706f2543Smrgextern __GLXclientState *glxGetClient(ClientPtr pClient);
83706f2543Smrg
84706f2543Smrg/************************************************************************/
85706f2543Smrg
86706f2543Smrgvoid GlxExtensionInit(void);
87706f2543Smrg
88706f2543Smrgvoid GlxSetVisualConfigs(int nconfigs,
89706f2543Smrg                         void *configs, void **privates);
90706f2543Smrg
91706f2543Smrgvoid __glXScreenInitVisuals(__GLXscreen *screen);
92706f2543Smrg
93706f2543Smrg/*
94706f2543Smrg** The last context used (from the server's persective) is cached.
95706f2543Smrg*/
96706f2543Smrgextern __GLXcontext *__glXLastContext;
97706f2543Smrgextern __GLXcontext *__glXForceCurrent(__GLXclientState*, GLXContextTag, int*);
98706f2543Smrg
99706f2543Smrgextern ClientPtr __pGlxClient;
100706f2543Smrg
101706f2543Smrgint __glXError(int error);
102706f2543Smrg
103706f2543Smrg/*
104706f2543Smrg** Macros to set, unset, and retrieve the flag that says whether a context
105706f2543Smrg** has unflushed commands.
106706f2543Smrg*/
107706f2543Smrg#define __GLX_NOTE_UNFLUSHED_CMDS(glxc) glxc->hasUnflushedCommands = GL_TRUE
108706f2543Smrg#define __GLX_NOTE_FLUSHED_CMDS(glxc) glxc->hasUnflushedCommands = GL_FALSE
109706f2543Smrg#define __GLX_HAS_UNFLUSHED_CMDS(glxc) (glxc->hasUnflushedCommands)
110706f2543Smrg
111706f2543Smrg/************************************************************************/
112706f2543Smrg
113706f2543Smrgtypedef struct __GLXprovider __GLXprovider;
114706f2543Smrgstruct __GLXprovider {
115706f2543Smrg    __GLXscreen *(*screenProbe)(ScreenPtr pScreen);
116706f2543Smrg    const char    *name;
117706f2543Smrg    __GLXprovider *next;
118706f2543Smrg};
119706f2543Smrg
120706f2543Smrgvoid GlxPushProvider(__GLXprovider *provider);
121706f2543Smrg
122706f2543Smrgenum {
123706f2543Smrg    GLX_MINIMAL_VISUALS,
124706f2543Smrg    GLX_TYPICAL_VISUALS,
125706f2543Smrg    GLX_ALL_VISUALS
126706f2543Smrg};
127706f2543Smrg
128706f2543Smrgvoid __glXsetEnterLeaveServerFuncs(void (*enter)(GLboolean),
129706f2543Smrg				   void (*leave)(GLboolean));
130706f2543Smrgvoid __glXenterServer(GLboolean rendering);
131706f2543Smrgvoid __glXleaveServer(GLboolean rendering);
132706f2543Smrg
133706f2543Smrgvoid glxSuspendClients(void);
134706f2543Smrgvoid glxResumeClients(void);
135706f2543Smrg
136706f2543Smrg/*
137706f2543Smrg** State kept per client.
138706f2543Smrg*/
139706f2543Smrgstruct __GLXclientStateRec {
140706f2543Smrg    /*
141706f2543Smrg    ** Whether this structure is currently being used to support a client.
142706f2543Smrg    */
143706f2543Smrg    Bool inUse;
144706f2543Smrg
145706f2543Smrg    /*
146706f2543Smrg    ** Buffer for returned data.
147706f2543Smrg    */
148706f2543Smrg    GLbyte *returnBuf;
149706f2543Smrg    GLint returnBufSize;
150706f2543Smrg
151706f2543Smrg    /*
152706f2543Smrg    ** Keep track of large rendering commands, which span multiple requests.
153706f2543Smrg    */
154706f2543Smrg    GLint largeCmdBytesSoFar;		/* bytes received so far	*/
155706f2543Smrg    GLint largeCmdBytesTotal;		/* total bytes expected		*/
156706f2543Smrg    GLint largeCmdRequestsSoFar;	/* requests received so far	*/
157706f2543Smrg    GLint largeCmdRequestsTotal;	/* total requests expected	*/
158706f2543Smrg    GLbyte *largeCmdBuf;
159706f2543Smrg    GLint largeCmdBufSize;
160706f2543Smrg
161706f2543Smrg    /* Back pointer to X client record */
162706f2543Smrg    ClientPtr client;
163706f2543Smrg
164706f2543Smrg    int GLClientmajorVersion;
165706f2543Smrg    int GLClientminorVersion;
166706f2543Smrg    char *GLClientextensions;
167706f2543Smrg};
168706f2543Smrg
169706f2543Smrg/************************************************************************/
170706f2543Smrg
171706f2543Smrg/*
172706f2543Smrg** Dispatch tables.
173706f2543Smrg*/
174706f2543Smrgtypedef void (*__GLXdispatchRenderProcPtr)(GLbyte *);
175706f2543Smrgtypedef int (*__GLXdispatchSingleProcPtr)(__GLXclientState *, GLbyte *);
176706f2543Smrgtypedef int (*__GLXdispatchVendorPrivProcPtr)(__GLXclientState *, GLbyte *);
177706f2543Smrg
178706f2543Smrg/*
179706f2543Smrg * Dispatch for GLX commands.
180706f2543Smrg */
181706f2543Smrgtypedef int (*__GLXprocPtr)(__GLXclientState *, char *pc);
182706f2543Smrg
183706f2543Smrg/*
184706f2543Smrg * Tables for computing the size of each rendering command.
185706f2543Smrg */
186706f2543Smrgtypedef int (*gl_proto_size_func)(const GLbyte *, Bool, int);
187706f2543Smrg
188706f2543Smrgtypedef struct {
189706f2543Smrg    int bytes;
190706f2543Smrg    gl_proto_size_func varsize;
191706f2543Smrg} __GLXrenderSizeData;
192706f2543Smrg
193706f2543Smrg/************************************************************************/
194706f2543Smrg
195706f2543Smrg/*
196706f2543Smrg** X resources.
197706f2543Smrg*/
198706f2543Smrgextern RESTYPE __glXContextRes;
199706f2543Smrgextern RESTYPE __glXClientRes;
200706f2543Smrgextern RESTYPE __glXPixmapRes;
201706f2543Smrgextern RESTYPE __glXDrawableRes;
202706f2543Smrg
203706f2543Smrg/************************************************************************/
204706f2543Smrg
205706f2543Smrg/*
206706f2543Smrg** Prototypes.
207706f2543Smrg*/
208706f2543Smrg
209706f2543Smrgextern char *__glXcombine_strings(const char *, const char *);
210706f2543Smrg
211706f2543Smrg/*
212706f2543Smrg** Routines for sending swapped replies.
213706f2543Smrg*/
214706f2543Smrg
215706f2543Smrgextern void __glXSwapMakeCurrentReply(ClientPtr client,
216706f2543Smrg				      xGLXMakeCurrentReply *reply);
217706f2543Smrgextern void __glXSwapIsDirectReply(ClientPtr client,
218706f2543Smrg				   xGLXIsDirectReply *reply);
219706f2543Smrgextern void __glXSwapQueryVersionReply(ClientPtr client,
220706f2543Smrg				       xGLXQueryVersionReply *reply);
221706f2543Smrgextern void __glXSwapQueryContextInfoEXTReply(ClientPtr client,
222706f2543Smrg					      xGLXQueryContextInfoEXTReply *reply,
223706f2543Smrg					      int *buf);
224706f2543Smrgextern void __glXSwapGetDrawableAttributesReply(ClientPtr client,
225706f2543Smrg						xGLXGetDrawableAttributesReply *reply, CARD32 *buf);
226706f2543Smrgextern void glxSwapQueryExtensionsStringReply(ClientPtr client,
227706f2543Smrg				xGLXQueryExtensionsStringReply *reply, char *buf);
228706f2543Smrgextern void glxSwapQueryServerStringReply(ClientPtr client,
229706f2543Smrg				xGLXQueryServerStringReply *reply, char *buf);
230706f2543Smrg
231706f2543Smrg
232706f2543Smrg/*
233706f2543Smrg * Routines for computing the size of variably-sized rendering commands.
234706f2543Smrg */
235706f2543Smrg
236706f2543Smrgstatic _X_INLINE int
237706f2543Smrgsafe_add(int a, int b)
238706f2543Smrg{
239706f2543Smrg    if (a < 0 || b < 0)
240706f2543Smrg        return -1;
241706f2543Smrg
242706f2543Smrg    if (INT_MAX - a < b)
243706f2543Smrg        return -1;
244706f2543Smrg
245706f2543Smrg    return a + b;
246706f2543Smrg}
247706f2543Smrg
248706f2543Smrgstatic _X_INLINE int
249706f2543Smrgsafe_mul(int a, int b)
250706f2543Smrg{
251706f2543Smrg    if (a < 0 || b < 0)
252706f2543Smrg        return -1;
253706f2543Smrg
254706f2543Smrg    if (a == 0 || b == 0)
255706f2543Smrg        return 0;
256706f2543Smrg
257706f2543Smrg    if (a > INT_MAX / b)
258706f2543Smrg        return -1;
259706f2543Smrg
260706f2543Smrg    return a * b;
261706f2543Smrg}
262706f2543Smrg
263706f2543Smrgstatic _X_INLINE int
264706f2543Smrgsafe_pad(int a)
265706f2543Smrg{
266706f2543Smrg    int ret;
267706f2543Smrg
268706f2543Smrg    if (a < 0)
269706f2543Smrg        return -1;
270706f2543Smrg
271706f2543Smrg    if ((ret = safe_add(a, 3)) < 0)
272706f2543Smrg        return -1;
273706f2543Smrg
274706f2543Smrg    return ret & (GLuint)~3;
275706f2543Smrg}
276706f2543Smrg
277706f2543Smrgextern int __glXTypeSize(GLenum enm);
278706f2543Smrgextern int __glXImageSize(GLenum format, GLenum type,
279706f2543Smrg    GLenum target, GLsizei w, GLsizei h, GLsizei d,
280706f2543Smrg    GLint imageHeight, GLint rowLength, GLint skipImages, GLint skipRows,
281706f2543Smrg    GLint alignment);
282706f2543Smrg
283706f2543Smrgextern unsigned glxMajorVersion;
284706f2543Smrgextern unsigned glxMinorVersion;
285706f2543Smrg
286706f2543Smrgextern int __glXEventBase;
287706f2543Smrg
288706f2543Smrg#endif /* !__GLX_server_h__ */
289