1#ifdef HAVE_DIX_CONFIG_H 2#include <dix-config.h> 3#endif 4 5#ifndef _GLX_server_h_ 6#define _GLX_server_h_ 7 8/* 9 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 10 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 11 * 12 * Permission is hereby granted, free of charge, to any person obtaining a 13 * copy of this software and associated documentation files (the "Software"), 14 * to deal in the Software without restriction, including without limitation 15 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 * and/or sell copies of the Software, and to permit persons to whom the 17 * Software is furnished to do so, subject to the following conditions: 18 * 19 * The above copyright notice including the dates of first publication and 20 * either this permission notice or a reference to 21 * http://oss.sgi.com/projects/FreeB/ 22 * shall be included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 27 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 28 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 29 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * SOFTWARE. 31 * 32 * Except as contained in this notice, the name of Silicon Graphics, Inc. 33 * shall not be used in advertising or otherwise to promote the sale, use or 34 * other dealings in this Software without prior written authorization from 35 * Silicon Graphics, Inc. 36 */ 37 38#include <X11/X.h> 39#include <X11/Xproto.h> 40#include <X11/Xmd.h> 41#include <misc.h> 42#include <dixstruct.h> 43#include <pixmapstr.h> 44#include <gcstruct.h> 45#include <extnsionst.h> 46#include <resource.h> 47#include <scrnintstr.h> 48 49/* 50** The X header misc.h defines these math functions. 51*/ 52#undef abs 53#undef fabs 54 55#define GL_GLEXT_PROTOTYPES /* we want prototypes */ 56#include <GL/gl.h> 57#include <GL/glxproto.h> 58 59/* 60** GLX resources. 61*/ 62typedef XID GLXContextID; 63typedef XID GLXPixmap; 64typedef XID GLXDrawable; 65 66typedef struct __GLXclientStateRec __GLXclientState; 67typedef struct __GLXdrawable __GLXdrawable; 68typedef struct __GLXcontext __GLXcontext; 69 70#include "glxscreens.h" 71#include "glxdrawable.h" 72#include "glxcontext.h" 73 74#ifndef True 75#define True 1 76#endif 77#ifndef False 78#define False 0 79#endif 80 81extern __GLXscreen *glxGetScreen(ScreenPtr pScreen); 82extern __GLXclientState *glxGetClient(ClientPtr pClient); 83 84/************************************************************************/ 85 86void GlxExtensionInit(void); 87 88void GlxSetVisualConfigs(int nconfigs, 89 void *configs, void **privates); 90 91void __glXScreenInitVisuals(__GLXscreen *screen); 92 93/* 94** The last context used (from the server's persective) is cached. 95*/ 96extern __GLXcontext *__glXLastContext; 97extern __GLXcontext *__glXForceCurrent(__GLXclientState*, GLXContextTag, int*); 98 99extern ClientPtr __pGlxClient; 100 101int __glXError(int error); 102 103/* 104** Macros to set, unset, and retrieve the flag that says whether a context 105** has unflushed commands. 106*/ 107#define __GLX_NOTE_UNFLUSHED_CMDS(glxc) glxc->hasUnflushedCommands = GL_TRUE 108#define __GLX_NOTE_FLUSHED_CMDS(glxc) glxc->hasUnflushedCommands = GL_FALSE 109#define __GLX_HAS_UNFLUSHED_CMDS(glxc) (glxc->hasUnflushedCommands) 110 111/************************************************************************/ 112 113typedef struct __GLXprovider __GLXprovider; 114struct __GLXprovider { 115 __GLXscreen *(*screenProbe)(ScreenPtr pScreen); 116 const char *name; 117 __GLXprovider *next; 118}; 119 120void GlxPushProvider(__GLXprovider *provider); 121 122enum { 123 GLX_MINIMAL_VISUALS, 124 GLX_TYPICAL_VISUALS, 125 GLX_ALL_VISUALS 126}; 127 128void __glXsetEnterLeaveServerFuncs(void (*enter)(GLboolean), 129 void (*leave)(GLboolean)); 130void __glXenterServer(GLboolean rendering); 131void __glXleaveServer(GLboolean rendering); 132 133void glxSuspendClients(void); 134void glxResumeClients(void); 135 136/* 137** State kept per client. 138*/ 139struct __GLXclientStateRec { 140 /* 141 ** Whether this structure is currently being used to support a client. 142 */ 143 Bool inUse; 144 145 /* 146 ** Buffer for returned data. 147 */ 148 GLbyte *returnBuf; 149 GLint returnBufSize; 150 151 /* 152 ** Keep track of large rendering commands, which span multiple requests. 153 */ 154 GLint largeCmdBytesSoFar; /* bytes received so far */ 155 GLint largeCmdBytesTotal; /* total bytes expected */ 156 GLint largeCmdRequestsSoFar; /* requests received so far */ 157 GLint largeCmdRequestsTotal; /* total requests expected */ 158 GLbyte *largeCmdBuf; 159 GLint largeCmdBufSize; 160 161 /* Back pointer to X client record */ 162 ClientPtr client; 163 164 int GLClientmajorVersion; 165 int GLClientminorVersion; 166 char *GLClientextensions; 167}; 168 169/************************************************************************/ 170 171/* 172** Dispatch tables. 173*/ 174typedef void (*__GLXdispatchRenderProcPtr)(GLbyte *); 175typedef int (*__GLXdispatchSingleProcPtr)(__GLXclientState *, GLbyte *); 176typedef int (*__GLXdispatchVendorPrivProcPtr)(__GLXclientState *, GLbyte *); 177 178/* 179 * Dispatch for GLX commands. 180 */ 181typedef int (*__GLXprocPtr)(__GLXclientState *, char *pc); 182 183/* 184 * Tables for computing the size of each rendering command. 185 */ 186typedef int (*gl_proto_size_func)(const GLbyte *, Bool, int); 187 188typedef struct { 189 int bytes; 190 gl_proto_size_func varsize; 191} __GLXrenderSizeData; 192 193/************************************************************************/ 194 195/* 196** X resources. 197*/ 198extern RESTYPE __glXContextRes; 199extern RESTYPE __glXClientRes; 200extern RESTYPE __glXPixmapRes; 201extern RESTYPE __glXDrawableRes; 202 203/************************************************************************/ 204 205/* 206** Prototypes. 207*/ 208 209extern char *__glXcombine_strings(const char *, const char *); 210 211/* 212** Routines for sending swapped replies. 213*/ 214 215extern void __glXSwapMakeCurrentReply(ClientPtr client, 216 xGLXMakeCurrentReply *reply); 217extern void __glXSwapIsDirectReply(ClientPtr client, 218 xGLXIsDirectReply *reply); 219extern void __glXSwapQueryVersionReply(ClientPtr client, 220 xGLXQueryVersionReply *reply); 221extern void __glXSwapQueryContextInfoEXTReply(ClientPtr client, 222 xGLXQueryContextInfoEXTReply *reply, 223 int *buf); 224extern void __glXSwapGetDrawableAttributesReply(ClientPtr client, 225 xGLXGetDrawableAttributesReply *reply, CARD32 *buf); 226extern void glxSwapQueryExtensionsStringReply(ClientPtr client, 227 xGLXQueryExtensionsStringReply *reply, char *buf); 228extern void glxSwapQueryServerStringReply(ClientPtr client, 229 xGLXQueryServerStringReply *reply, char *buf); 230 231 232/* 233 * Routines for computing the size of variably-sized rendering commands. 234 */ 235 236static _X_INLINE int 237safe_add(int a, int b) 238{ 239 if (a < 0 || b < 0) 240 return -1; 241 242 if (INT_MAX - a < b) 243 return -1; 244 245 return a + b; 246} 247 248static _X_INLINE int 249safe_mul(int a, int b) 250{ 251 if (a < 0 || b < 0) 252 return -1; 253 254 if (a == 0 || b == 0) 255 return 0; 256 257 if (a > INT_MAX / b) 258 return -1; 259 260 return a * b; 261} 262 263static _X_INLINE int 264safe_pad(int a) 265{ 266 int ret; 267 268 if (a < 0) 269 return -1; 270 271 if ((ret = safe_add(a, 3)) < 0) 272 return -1; 273 274 return ret & (GLuint)~3; 275} 276 277extern int __glXTypeSize(GLenum enm); 278extern int __glXImageSize(GLenum format, GLenum type, 279 GLenum target, GLsizei w, GLsizei h, GLsizei d, 280 GLint imageHeight, GLint rowLength, GLint skipImages, GLint skipRows, 281 GLint alignment); 282 283extern unsigned glxMajorVersion; 284extern unsigned glxMinorVersion; 285 286extern int __glXEventBase; 287 288#endif /* !__GLX_server_h__ */ 289