xref: /OK3568_Linux_fs/external/xserver/hw/xquartz/GL/glcontextmodes.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright IBM Corporation 2003
3*4882a593Smuzhiyun  * All Rights Reserved.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
6*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
7*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
8*4882a593Smuzhiyun  * on the rights to use, copy, modify, merge, publish, distribute, sub
9*4882a593Smuzhiyun  * license, and/or sell copies of the Software, and to permit persons to whom
10*4882a593Smuzhiyun  * the Software is furnished to do so, subject to the following conditions:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the next
13*4882a593Smuzhiyun  * paragraph) shall be included in all copies or substantial portions of the
14*4882a593Smuzhiyun  * Software.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19*4882a593Smuzhiyun  * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20*4882a593Smuzhiyun  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21*4882a593Smuzhiyun  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22*4882a593Smuzhiyun  * USE OR OTHER DEALINGS IN THE SOFTWARE.
23*4882a593Smuzhiyun  */
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /**
26*4882a593Smuzhiyun  * \file glcontextmodes.c
27*4882a593Smuzhiyun  * Utility routines for working with \c __GLcontextModes structures.  At
28*4882a593Smuzhiyun  * some point most or all of these functions will be moved to the Mesa
29*4882a593Smuzhiyun  * code base.
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  * \author Ian Romanick <idr@us.ibm.com>
32*4882a593Smuzhiyun  */
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #if defined(IN_MINI_GLX)
35*4882a593Smuzhiyun #include <GL/gl.h>
36*4882a593Smuzhiyun #else
37*4882a593Smuzhiyun #if defined(HAVE_DIX_CONFIG_H)
38*4882a593Smuzhiyun #include <dix-config.h>
39*4882a593Smuzhiyun #endif
40*4882a593Smuzhiyun #include <X11/X.h>
41*4882a593Smuzhiyun #include <GL/glx.h>
42*4882a593Smuzhiyun #include "GL/glxint.h"
43*4882a593Smuzhiyun #endif
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /* Memory macros */
46*4882a593Smuzhiyun #if defined(IN_MINI_GLX)
47*4882a593Smuzhiyun #include <stdlib.h>
48*4882a593Smuzhiyun #include <string.h>
49*4882a593Smuzhiyun #define _mesa_malloc(b) malloc(b)
50*4882a593Smuzhiyun #define _mesa_free(m)   free(m)
51*4882a593Smuzhiyun #define _mesa_memset memset
52*4882a593Smuzhiyun #else
53*4882a593Smuzhiyun #ifdef XFree86Server
54*4882a593Smuzhiyun #include <os.h>
55*4882a593Smuzhiyun #include <string.h>
56*4882a593Smuzhiyun #define _mesa_malloc(b) malloc(b)
57*4882a593Smuzhiyun #define _mesa_free(m)   free(m)
58*4882a593Smuzhiyun #define _mesa_memset memset
59*4882a593Smuzhiyun #else
60*4882a593Smuzhiyun #include <X11/Xlibint.h>
61*4882a593Smuzhiyun #define _mesa_memset memset
62*4882a593Smuzhiyun #define _mesa_malloc(b) Xmalloc(b)
63*4882a593Smuzhiyun #define _mesa_free(m)   free(m)
64*4882a593Smuzhiyun #endif  /* XFree86Server */
65*4882a593Smuzhiyun #endif /* !defined(IN_MINI_GLX) */
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #include "glcontextmodes.h"
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun #if !defined(IN_MINI_GLX)
70*4882a593Smuzhiyun #define NUM_VISUAL_TYPES 6
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /**
73*4882a593Smuzhiyun  * Convert an X visual type to a GLX visual type.
74*4882a593Smuzhiyun  *
75*4882a593Smuzhiyun  * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.)
76*4882a593Smuzhiyun  *        to be converted.
77*4882a593Smuzhiyun  * \return If \c visualType is a valid X visual type, a GLX visual type will
78*4882a593Smuzhiyun  *         be returned.  Otherwise \c GLX_NONE will be returned.
79*4882a593Smuzhiyun  */
80*4882a593Smuzhiyun GLint
_gl_convert_from_x_visual_type(int visualType)81*4882a593Smuzhiyun _gl_convert_from_x_visual_type(int visualType)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun     static const int glx_visual_types[NUM_VISUAL_TYPES] = {
84*4882a593Smuzhiyun         GLX_STATIC_GRAY,  GLX_GRAY_SCALE,
85*4882a593Smuzhiyun         GLX_STATIC_COLOR, GLX_PSEUDO_COLOR,
86*4882a593Smuzhiyun         GLX_TRUE_COLOR,   GLX_DIRECT_COLOR
87*4882a593Smuzhiyun     };
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun     return ((unsigned)visualType < NUM_VISUAL_TYPES)
90*4882a593Smuzhiyun            ? glx_visual_types[visualType] : GLX_NONE;
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /**
94*4882a593Smuzhiyun  * Convert a GLX visual type to an X visual type.
95*4882a593Smuzhiyun  *
96*4882a593Smuzhiyun  * \param visualType GLX visual type (i.e., \c GLX_TRUE_COLOR,
97*4882a593Smuzhiyun  *                   \c GLX_STATIC_GRAY, etc.) to be converted.
98*4882a593Smuzhiyun  * \return If \c visualType is a valid GLX visual type, an X visual type will
99*4882a593Smuzhiyun  *         be returned.  Otherwise -1 will be returned.
100*4882a593Smuzhiyun  */
101*4882a593Smuzhiyun GLint
_gl_convert_to_x_visual_type(int visualType)102*4882a593Smuzhiyun _gl_convert_to_x_visual_type(int visualType)
103*4882a593Smuzhiyun {
104*4882a593Smuzhiyun     static const int x_visual_types[NUM_VISUAL_TYPES] = {
105*4882a593Smuzhiyun         TrueColor,   DirectColor,
106*4882a593Smuzhiyun         PseudoColor, StaticColor,
107*4882a593Smuzhiyun         GrayScale,   StaticGray
108*4882a593Smuzhiyun     };
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun     return ((unsigned)(visualType - GLX_TRUE_COLOR) < NUM_VISUAL_TYPES)
111*4882a593Smuzhiyun            ? x_visual_types[visualType - GLX_TRUE_COLOR] : -1;
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun /**
115*4882a593Smuzhiyun  * Copy a GLX visual config structure to a GL context mode structure.  All
116*4882a593Smuzhiyun  * of the fields in \c config are copied to \c mode.  Additional fields in
117*4882a593Smuzhiyun  * \c mode that can be derived from the fields of \c config (i.e.,
118*4882a593Smuzhiyun  * \c haveDepthBuffer) are also filled in.  The remaining fields in \c mode
119*4882a593Smuzhiyun  * that cannot be derived are set to default values.
120*4882a593Smuzhiyun  *
121*4882a593Smuzhiyun  * \param mode   Destination GL context mode.
122*4882a593Smuzhiyun  * \param config Source GLX visual config.
123*4882a593Smuzhiyun  *
124*4882a593Smuzhiyun  * \note
125*4882a593Smuzhiyun  * The \c fbconfigID and \c visualID fields of the \c __GLcontextModes
126*4882a593Smuzhiyun  * structure will be set to the \c vid of the \c __GLXvisualConfig structure.
127*4882a593Smuzhiyun  */
128*4882a593Smuzhiyun void
_gl_copy_visual_to_context_mode(__GLcontextModes * mode,const __GLXvisualConfig * config)129*4882a593Smuzhiyun _gl_copy_visual_to_context_mode(__GLcontextModes * mode,
130*4882a593Smuzhiyun                                 const __GLXvisualConfig * config)
131*4882a593Smuzhiyun {
132*4882a593Smuzhiyun     __GLcontextModes * const next = mode->next;
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun     (void)_mesa_memset(mode, 0, sizeof(__GLcontextModes));
135*4882a593Smuzhiyun     mode->next = next;
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun     mode->visualID = config->vid;
138*4882a593Smuzhiyun     mode->visualType = _gl_convert_from_x_visual_type(config->class);
139*4882a593Smuzhiyun     mode->fbconfigID = config->vid;
140*4882a593Smuzhiyun     mode->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT;
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun     mode->rgbMode = (config->rgba != 0);
143*4882a593Smuzhiyun     mode->renderType = (mode->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun     mode->colorIndexMode = !(mode->rgbMode);
146*4882a593Smuzhiyun     mode->doubleBufferMode = (config->doubleBuffer != 0);
147*4882a593Smuzhiyun     mode->stereoMode = (config->stereo != 0);
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun     mode->haveAccumBuffer = ((config->accumRedSize +
150*4882a593Smuzhiyun                               config->accumGreenSize +
151*4882a593Smuzhiyun                               config->accumBlueSize +
152*4882a593Smuzhiyun                               config->accumAlphaSize) > 0);
153*4882a593Smuzhiyun     mode->haveDepthBuffer = (config->depthSize > 0);
154*4882a593Smuzhiyun     mode->haveStencilBuffer = (config->stencilSize > 0);
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun     mode->redBits = config->redSize;
157*4882a593Smuzhiyun     mode->greenBits = config->greenSize;
158*4882a593Smuzhiyun     mode->blueBits = config->blueSize;
159*4882a593Smuzhiyun     mode->alphaBits = config->alphaSize;
160*4882a593Smuzhiyun     mode->redMask = config->redMask;
161*4882a593Smuzhiyun     mode->greenMask = config->greenMask;
162*4882a593Smuzhiyun     mode->blueMask = config->blueMask;
163*4882a593Smuzhiyun     mode->alphaMask = config->alphaMask;
164*4882a593Smuzhiyun     mode->rgbBits = mode->rgbMode ? config->bufferSize : 0;
165*4882a593Smuzhiyun     mode->indexBits = mode->colorIndexMode ? config->bufferSize : 0;
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun     mode->accumRedBits = config->accumRedSize;
168*4882a593Smuzhiyun     mode->accumGreenBits = config->accumGreenSize;
169*4882a593Smuzhiyun     mode->accumBlueBits = config->accumBlueSize;
170*4882a593Smuzhiyun     mode->accumAlphaBits = config->accumAlphaSize;
171*4882a593Smuzhiyun     mode->depthBits = config->depthSize;
172*4882a593Smuzhiyun     mode->stencilBits = config->stencilSize;
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun     mode->numAuxBuffers = config->auxBuffers;
175*4882a593Smuzhiyun     mode->level = config->level;
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun     mode->visualRating = config->visualRating;
178*4882a593Smuzhiyun     mode->transparentPixel = config->transparentPixel;
179*4882a593Smuzhiyun     mode->transparentRed = config->transparentRed;
180*4882a593Smuzhiyun     mode->transparentGreen = config->transparentGreen;
181*4882a593Smuzhiyun     mode->transparentBlue = config->transparentBlue;
182*4882a593Smuzhiyun     mode->transparentAlpha = config->transparentAlpha;
183*4882a593Smuzhiyun     mode->transparentIndex = config->transparentIndex;
184*4882a593Smuzhiyun     mode->samples = config->multiSampleSize;
185*4882a593Smuzhiyun     mode->sampleBuffers = config->nMultiSampleBuffers;
186*4882a593Smuzhiyun     /* mode->visualSelectGroup = config->visualSelectGroup; ? */
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun     mode->swapMethod = GLX_SWAP_UNDEFINED_OML;
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun     mode->bindToTextureRgb = (mode->rgbMode) ? GL_TRUE : GL_FALSE;
191*4882a593Smuzhiyun     mode->bindToTextureRgba = (mode->rgbMode && mode->alphaBits) ?
192*4882a593Smuzhiyun                               GL_TRUE : GL_FALSE;
193*4882a593Smuzhiyun     mode->bindToMipmapTexture = mode->rgbMode ? GL_TRUE : GL_FALSE;
194*4882a593Smuzhiyun     mode->bindToTextureTargets = mode->rgbMode ?
195*4882a593Smuzhiyun                                  GLX_TEXTURE_1D_BIT_EXT |
196*4882a593Smuzhiyun                                  GLX_TEXTURE_2D_BIT_EXT |
197*4882a593Smuzhiyun                                  GLX_TEXTURE_RECTANGLE_BIT_EXT : 0;
198*4882a593Smuzhiyun     mode->yInverted = GL_FALSE;
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun /**
202*4882a593Smuzhiyun  * Get data from a GL context mode.
203*4882a593Smuzhiyun  *
204*4882a593Smuzhiyun  * \param mode         GL context mode whose data is to be returned.
205*4882a593Smuzhiyun  * \param attribute    Attribute of \c mode that is to be returned.
206*4882a593Smuzhiyun  * \param value_return Location to store the data member of \c mode.
207*4882a593Smuzhiyun  * \return  If \c attribute is a valid attribute of \c mode, zero is
208*4882a593Smuzhiyun  *          returned.  Otherwise \c GLX_BAD_ATTRIBUTE is returned.
209*4882a593Smuzhiyun  */
210*4882a593Smuzhiyun int
_gl_get_context_mode_data(const __GLcontextModes * mode,int attribute,int * value_return)211*4882a593Smuzhiyun _gl_get_context_mode_data(const __GLcontextModes *mode, int attribute,
212*4882a593Smuzhiyun                           int *value_return)
213*4882a593Smuzhiyun {
214*4882a593Smuzhiyun     switch (attribute) {
215*4882a593Smuzhiyun     case GLX_USE_GL:
216*4882a593Smuzhiyun         *value_return = GL_TRUE;
217*4882a593Smuzhiyun         return 0;
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun     case GLX_BUFFER_SIZE:
220*4882a593Smuzhiyun         *value_return = mode->rgbBits;
221*4882a593Smuzhiyun         return 0;
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun     case GLX_RGBA:
224*4882a593Smuzhiyun         *value_return = mode->rgbMode;
225*4882a593Smuzhiyun         return 0;
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun     case GLX_RED_SIZE:
228*4882a593Smuzhiyun         *value_return = mode->redBits;
229*4882a593Smuzhiyun         return 0;
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun     case GLX_GREEN_SIZE:
232*4882a593Smuzhiyun         *value_return = mode->greenBits;
233*4882a593Smuzhiyun         return 0;
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun     case GLX_BLUE_SIZE:
236*4882a593Smuzhiyun         *value_return = mode->blueBits;
237*4882a593Smuzhiyun         return 0;
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun     case GLX_ALPHA_SIZE:
240*4882a593Smuzhiyun         *value_return = mode->alphaBits;
241*4882a593Smuzhiyun         return 0;
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun     case GLX_DOUBLEBUFFER:
244*4882a593Smuzhiyun         *value_return = mode->doubleBufferMode;
245*4882a593Smuzhiyun         return 0;
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun     case GLX_STEREO:
248*4882a593Smuzhiyun         *value_return = mode->stereoMode;
249*4882a593Smuzhiyun         return 0;
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun     case GLX_AUX_BUFFERS:
252*4882a593Smuzhiyun         *value_return = mode->numAuxBuffers;
253*4882a593Smuzhiyun         return 0;
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun     case GLX_DEPTH_SIZE:
256*4882a593Smuzhiyun         *value_return = mode->depthBits;
257*4882a593Smuzhiyun         return 0;
258*4882a593Smuzhiyun 
259*4882a593Smuzhiyun     case GLX_STENCIL_SIZE:
260*4882a593Smuzhiyun         *value_return = mode->stencilBits;
261*4882a593Smuzhiyun         return 0;
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun     case GLX_ACCUM_RED_SIZE:
264*4882a593Smuzhiyun         *value_return = mode->accumRedBits;
265*4882a593Smuzhiyun         return 0;
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun     case GLX_ACCUM_GREEN_SIZE:
268*4882a593Smuzhiyun         *value_return = mode->accumGreenBits;
269*4882a593Smuzhiyun         return 0;
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun     case GLX_ACCUM_BLUE_SIZE:
272*4882a593Smuzhiyun         *value_return = mode->accumBlueBits;
273*4882a593Smuzhiyun         return 0;
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun     case GLX_ACCUM_ALPHA_SIZE:
276*4882a593Smuzhiyun         *value_return = mode->accumAlphaBits;
277*4882a593Smuzhiyun         return 0;
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun     case GLX_LEVEL:
280*4882a593Smuzhiyun         *value_return = mode->level;
281*4882a593Smuzhiyun         return 0;
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun     case GLX_TRANSPARENT_TYPE_EXT:
284*4882a593Smuzhiyun         *value_return = mode->transparentPixel;
285*4882a593Smuzhiyun         return 0;
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun     case GLX_TRANSPARENT_RED_VALUE:
288*4882a593Smuzhiyun         *value_return = mode->transparentRed;
289*4882a593Smuzhiyun         return 0;
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun     case GLX_TRANSPARENT_GREEN_VALUE:
292*4882a593Smuzhiyun         *value_return = mode->transparentGreen;
293*4882a593Smuzhiyun         return 0;
294*4882a593Smuzhiyun 
295*4882a593Smuzhiyun     case GLX_TRANSPARENT_BLUE_VALUE:
296*4882a593Smuzhiyun         *value_return = mode->transparentBlue;
297*4882a593Smuzhiyun         return 0;
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun     case GLX_TRANSPARENT_ALPHA_VALUE:
300*4882a593Smuzhiyun         *value_return = mode->transparentAlpha;
301*4882a593Smuzhiyun         return 0;
302*4882a593Smuzhiyun 
303*4882a593Smuzhiyun     case GLX_TRANSPARENT_INDEX_VALUE:
304*4882a593Smuzhiyun         *value_return = mode->transparentIndex;
305*4882a593Smuzhiyun         return 0;
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun     case GLX_X_VISUAL_TYPE:
308*4882a593Smuzhiyun         *value_return = mode->visualType;
309*4882a593Smuzhiyun         return 0;
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun     case GLX_CONFIG_CAVEAT:
312*4882a593Smuzhiyun         *value_return = mode->visualRating;
313*4882a593Smuzhiyun         return 0;
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun     case GLX_VISUAL_ID:
316*4882a593Smuzhiyun         *value_return = mode->visualID;
317*4882a593Smuzhiyun         return 0;
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun     case GLX_DRAWABLE_TYPE:
320*4882a593Smuzhiyun         *value_return = mode->drawableType;
321*4882a593Smuzhiyun         return 0;
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun     case GLX_RENDER_TYPE:
324*4882a593Smuzhiyun         *value_return = mode->renderType;
325*4882a593Smuzhiyun         return 0;
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun     case GLX_X_RENDERABLE:
328*4882a593Smuzhiyun         *value_return = mode->xRenderable;
329*4882a593Smuzhiyun         return 0;
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun     case GLX_FBCONFIG_ID:
332*4882a593Smuzhiyun         *value_return = mode->fbconfigID;
333*4882a593Smuzhiyun         return 0;
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun     case GLX_MAX_PBUFFER_WIDTH:
336*4882a593Smuzhiyun         *value_return = mode->maxPbufferWidth;
337*4882a593Smuzhiyun         return 0;
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun     case GLX_MAX_PBUFFER_HEIGHT:
340*4882a593Smuzhiyun         *value_return = mode->maxPbufferHeight;
341*4882a593Smuzhiyun         return 0;
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun     case GLX_MAX_PBUFFER_PIXELS:
344*4882a593Smuzhiyun         *value_return = mode->maxPbufferPixels;
345*4882a593Smuzhiyun         return 0;
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun     case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX:
348*4882a593Smuzhiyun         *value_return = mode->optimalPbufferWidth;
349*4882a593Smuzhiyun         return 0;
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun     case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX:
352*4882a593Smuzhiyun         *value_return = mode->optimalPbufferHeight;
353*4882a593Smuzhiyun         return 0;
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun     case GLX_SWAP_METHOD_OML:
356*4882a593Smuzhiyun         *value_return = mode->swapMethod;
357*4882a593Smuzhiyun         return 0;
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun     case GLX_SAMPLE_BUFFERS_SGIS:
360*4882a593Smuzhiyun         *value_return = mode->sampleBuffers;
361*4882a593Smuzhiyun         return 0;
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun     case GLX_SAMPLES_SGIS:
364*4882a593Smuzhiyun         *value_return = mode->samples;
365*4882a593Smuzhiyun         return 0;
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun     case GLX_BIND_TO_TEXTURE_RGB_EXT:
368*4882a593Smuzhiyun         *value_return = mode->bindToTextureRgb;
369*4882a593Smuzhiyun         return 0;
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun     case GLX_BIND_TO_TEXTURE_RGBA_EXT:
372*4882a593Smuzhiyun         *value_return = mode->bindToTextureRgba;
373*4882a593Smuzhiyun         return 0;
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun     case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
376*4882a593Smuzhiyun         *value_return = mode->bindToMipmapTexture == GL_TRUE ? GL_TRUE :
377*4882a593Smuzhiyun                         GL_FALSE;
378*4882a593Smuzhiyun         return 0;
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun     case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
381*4882a593Smuzhiyun         *value_return = mode->bindToTextureTargets;
382*4882a593Smuzhiyun         return 0;
383*4882a593Smuzhiyun 
384*4882a593Smuzhiyun     case GLX_Y_INVERTED_EXT:
385*4882a593Smuzhiyun         *value_return = mode->yInverted;
386*4882a593Smuzhiyun         return 0;
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun     /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX.
389*4882a593Smuzhiyun      * It is ONLY for communication between the GLX client and the GLX
390*4882a593Smuzhiyun      * server.
391*4882a593Smuzhiyun      */
392*4882a593Smuzhiyun     case GLX_VISUAL_SELECT_GROUP_SGIX:
393*4882a593Smuzhiyun     default:
394*4882a593Smuzhiyun         return GLX_BAD_ATTRIBUTE;
395*4882a593Smuzhiyun     }
396*4882a593Smuzhiyun }
397*4882a593Smuzhiyun #endif /* !defined(IN_MINI_GLX) */
398*4882a593Smuzhiyun 
399*4882a593Smuzhiyun /**
400*4882a593Smuzhiyun  * Allocate a linked list of \c __GLcontextModes structures.  The fields of
401*4882a593Smuzhiyun  * each structure will be initialized to "reasonable" default values.  In
402*4882a593Smuzhiyun  * most cases this is the default value defined by table 3.4 of the GLX
403*4882a593Smuzhiyun  * 1.3 specification.  This means that most values are either initialized to
404*4882a593Smuzhiyun  * zero or \c GLX_DONT_CARE (which is -1).  As support for additional
405*4882a593Smuzhiyun  * extensions is added, the new values will be initialized to appropriate
406*4882a593Smuzhiyun  * values from the extension specification.
407*4882a593Smuzhiyun  *
408*4882a593Smuzhiyun  * \param count         Number of structures to allocate.
409*4882a593Smuzhiyun  * \param minimum_size  Minimum size of a structure to allocate.  This allows
410*4882a593Smuzhiyun  *                      for differences in the version of the
411*4882a593Smuzhiyun  *                      \c __GLcontextModes structure used in libGL and in a
412*4882a593Smuzhiyun  *                      DRI-based driver.
413*4882a593Smuzhiyun  * \returns A pointer to the first element in a linked list of \c count
414*4882a593Smuzhiyun  *          structures on success, or \c NULL on failure.
415*4882a593Smuzhiyun  *
416*4882a593Smuzhiyun  * \warning Use of \c minimum_size does \b not guarantee binary compatibility.
417*4882a593Smuzhiyun  *          The fundamental assumption is that if the \c minimum_size
418*4882a593Smuzhiyun  *          specified by the driver and the size of the \c __GLcontextModes
419*4882a593Smuzhiyun  *          structure in libGL is the same, then the meaning of each byte in
420*4882a593Smuzhiyun  *          the structure is the same in both places.  \b Be \b careful!
421*4882a593Smuzhiyun  *          Basically this means that fields have to be added in libGL and
422*4882a593Smuzhiyun  *          then propagated to drivers.  Drivers should \b never arbitrarilly
423*4882a593Smuzhiyun  *          extend the \c __GLcontextModes data-structure.
424*4882a593Smuzhiyun  */
425*4882a593Smuzhiyun __GLcontextModes *
_gl_context_modes_create(unsigned count,size_t minimum_size)426*4882a593Smuzhiyun _gl_context_modes_create(unsigned count, size_t minimum_size)
427*4882a593Smuzhiyun {
428*4882a593Smuzhiyun     const size_t size = (minimum_size > sizeof(__GLcontextModes))
429*4882a593Smuzhiyun                         ? minimum_size : sizeof(__GLcontextModes);
430*4882a593Smuzhiyun     __GLcontextModes * base = NULL;
431*4882a593Smuzhiyun     __GLcontextModes ** next;
432*4882a593Smuzhiyun     unsigned i;
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun     next = &base;
435*4882a593Smuzhiyun     for (i = 0; i < count; i++) {
436*4882a593Smuzhiyun         *next = (__GLcontextModes *)_mesa_malloc(size);
437*4882a593Smuzhiyun         if (*next == NULL) {
438*4882a593Smuzhiyun             _gl_context_modes_destroy(base);
439*4882a593Smuzhiyun             base = NULL;
440*4882a593Smuzhiyun             break;
441*4882a593Smuzhiyun         }
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun         (void)_mesa_memset(*next, 0, size);
444*4882a593Smuzhiyun         (*next)->visualID = GLX_DONT_CARE;
445*4882a593Smuzhiyun         (*next)->visualType = GLX_DONT_CARE;
446*4882a593Smuzhiyun         (*next)->visualRating = GLX_NONE;
447*4882a593Smuzhiyun         (*next)->transparentPixel = GLX_NONE;
448*4882a593Smuzhiyun         (*next)->transparentRed = GLX_DONT_CARE;
449*4882a593Smuzhiyun         (*next)->transparentGreen = GLX_DONT_CARE;
450*4882a593Smuzhiyun         (*next)->transparentBlue = GLX_DONT_CARE;
451*4882a593Smuzhiyun         (*next)->transparentAlpha = GLX_DONT_CARE;
452*4882a593Smuzhiyun         (*next)->transparentIndex = GLX_DONT_CARE;
453*4882a593Smuzhiyun         (*next)->xRenderable = GLX_DONT_CARE;
454*4882a593Smuzhiyun         (*next)->fbconfigID = GLX_DONT_CARE;
455*4882a593Smuzhiyun         (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML;
456*4882a593Smuzhiyun         (*next)->bindToTextureRgb = GLX_DONT_CARE;
457*4882a593Smuzhiyun         (*next)->bindToTextureRgba = GLX_DONT_CARE;
458*4882a593Smuzhiyun         (*next)->bindToMipmapTexture = GLX_DONT_CARE;
459*4882a593Smuzhiyun         (*next)->bindToTextureTargets = GLX_DONT_CARE;
460*4882a593Smuzhiyun         (*next)->yInverted = GLX_DONT_CARE;
461*4882a593Smuzhiyun 
462*4882a593Smuzhiyun         next = &((*next)->next);
463*4882a593Smuzhiyun     }
464*4882a593Smuzhiyun 
465*4882a593Smuzhiyun     return base;
466*4882a593Smuzhiyun }
467*4882a593Smuzhiyun 
468*4882a593Smuzhiyun /**
469*4882a593Smuzhiyun  * Destroy a linked list of \c __GLcontextModes structures created by
470*4882a593Smuzhiyun  * \c _gl_context_modes_create.
471*4882a593Smuzhiyun  *
472*4882a593Smuzhiyun  * \param modes  Linked list of structures to be destroyed.  All structures
473*4882a593Smuzhiyun  *               in the list will be freed.
474*4882a593Smuzhiyun  */
475*4882a593Smuzhiyun void
_gl_context_modes_destroy(__GLcontextModes * modes)476*4882a593Smuzhiyun _gl_context_modes_destroy(__GLcontextModes * modes)
477*4882a593Smuzhiyun {
478*4882a593Smuzhiyun     while (modes != NULL) {
479*4882a593Smuzhiyun         __GLcontextModes * const next = modes->next;
480*4882a593Smuzhiyun 
481*4882a593Smuzhiyun         _mesa_free(modes);
482*4882a593Smuzhiyun         modes = next;
483*4882a593Smuzhiyun     }
484*4882a593Smuzhiyun }
485*4882a593Smuzhiyun 
486*4882a593Smuzhiyun /**
487*4882a593Smuzhiyun  * Find a context mode matching a Visual ID.
488*4882a593Smuzhiyun  *
489*4882a593Smuzhiyun  * \param modes  List list of context-mode structures to be searched.
490*4882a593Smuzhiyun  * \param vid    Visual ID to be found.
491*4882a593Smuzhiyun  * \returns A pointer to a context-mode in \c modes if \c vid was found in
492*4882a593Smuzhiyun  *          the list, or \c NULL if it was not.
493*4882a593Smuzhiyun  */
494*4882a593Smuzhiyun 
495*4882a593Smuzhiyun __GLcontextModes *
_gl_context_modes_find_visual(__GLcontextModes * modes,int vid)496*4882a593Smuzhiyun _gl_context_modes_find_visual(__GLcontextModes *modes, int vid)
497*4882a593Smuzhiyun {
498*4882a593Smuzhiyun     __GLcontextModes *m;
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun     for (m = modes; m != NULL; m = m->next)
501*4882a593Smuzhiyun         if (m->visualID == vid)
502*4882a593Smuzhiyun             return m;
503*4882a593Smuzhiyun 
504*4882a593Smuzhiyun     return NULL;
505*4882a593Smuzhiyun }
506*4882a593Smuzhiyun 
507*4882a593Smuzhiyun __GLcontextModes *
_gl_context_modes_find_fbconfig(__GLcontextModes * modes,int fbid)508*4882a593Smuzhiyun _gl_context_modes_find_fbconfig(__GLcontextModes *modes, int fbid)
509*4882a593Smuzhiyun {
510*4882a593Smuzhiyun     __GLcontextModes *m;
511*4882a593Smuzhiyun 
512*4882a593Smuzhiyun     for (m = modes; m != NULL; m = m->next)
513*4882a593Smuzhiyun         if (m->fbconfigID == fbid)
514*4882a593Smuzhiyun             return m;
515*4882a593Smuzhiyun 
516*4882a593Smuzhiyun     return NULL;
517*4882a593Smuzhiyun }
518*4882a593Smuzhiyun 
519*4882a593Smuzhiyun /**
520*4882a593Smuzhiyun  * Determine if two context-modes are the same.  This is intended to be used
521*4882a593Smuzhiyun  * by libGL implementations to compare to sets of driver generated FBconfigs.
522*4882a593Smuzhiyun  *
523*4882a593Smuzhiyun  * \param a  Context-mode to be compared.
524*4882a593Smuzhiyun  * \param b  Context-mode to be compared.
525*4882a593Smuzhiyun  * \returns \c GL_TRUE if the two context-modes are the same.  \c GL_FALSE is
526*4882a593Smuzhiyun  *          returned otherwise.
527*4882a593Smuzhiyun  */
528*4882a593Smuzhiyun GLboolean
_gl_context_modes_are_same(const __GLcontextModes * a,const __GLcontextModes * b)529*4882a593Smuzhiyun _gl_context_modes_are_same(const __GLcontextModes * a,
530*4882a593Smuzhiyun                            const __GLcontextModes * b)
531*4882a593Smuzhiyun {
532*4882a593Smuzhiyun     return ((a->rgbMode == b->rgbMode) &&
533*4882a593Smuzhiyun             (a->floatMode == b->floatMode) &&
534*4882a593Smuzhiyun             (a->colorIndexMode == b->colorIndexMode) &&
535*4882a593Smuzhiyun             (a->doubleBufferMode == b->doubleBufferMode) &&
536*4882a593Smuzhiyun             (a->stereoMode == b->stereoMode) &&
537*4882a593Smuzhiyun             (a->redBits == b->redBits) &&
538*4882a593Smuzhiyun             (a->greenBits == b->greenBits) &&
539*4882a593Smuzhiyun             (a->blueBits == b->blueBits) &&
540*4882a593Smuzhiyun             (a->alphaBits == b->alphaBits) &&
541*4882a593Smuzhiyun #if 0 /* For some reason these don't get set on the client-side in libGL. */
542*4882a593Smuzhiyun             (a->redMask == b->redMask) &&
543*4882a593Smuzhiyun             (a->greenMask == b->greenMask) &&
544*4882a593Smuzhiyun             (a->blueMask == b->blueMask) &&
545*4882a593Smuzhiyun             (a->alphaMask == b->alphaMask) &&
546*4882a593Smuzhiyun #endif
547*4882a593Smuzhiyun             (a->rgbBits == b->rgbBits) &&
548*4882a593Smuzhiyun             (a->indexBits == b->indexBits) &&
549*4882a593Smuzhiyun             (a->accumRedBits == b->accumRedBits) &&
550*4882a593Smuzhiyun             (a->accumGreenBits == b->accumGreenBits) &&
551*4882a593Smuzhiyun             (a->accumBlueBits == b->accumBlueBits) &&
552*4882a593Smuzhiyun             (a->accumAlphaBits == b->accumAlphaBits) &&
553*4882a593Smuzhiyun             (a->depthBits == b->depthBits) &&
554*4882a593Smuzhiyun             (a->stencilBits == b->stencilBits) &&
555*4882a593Smuzhiyun             (a->numAuxBuffers == b->numAuxBuffers) &&
556*4882a593Smuzhiyun             (a->level == b->level) &&
557*4882a593Smuzhiyun             (a->visualRating == b->visualRating) &&
558*4882a593Smuzhiyun 
559*4882a593Smuzhiyun             (a->transparentPixel == b->transparentPixel) &&
560*4882a593Smuzhiyun 
561*4882a593Smuzhiyun             ((a->transparentPixel != GLX_TRANSPARENT_RGB) ||
562*4882a593Smuzhiyun              ((a->transparentRed == b->transparentRed) &&
563*4882a593Smuzhiyun               (a->transparentGreen == b->transparentGreen) &&
564*4882a593Smuzhiyun               (a->transparentBlue == b->transparentBlue) &&
565*4882a593Smuzhiyun               (a->transparentAlpha == b->transparentAlpha))) &&
566*4882a593Smuzhiyun 
567*4882a593Smuzhiyun             ((a->transparentPixel != GLX_TRANSPARENT_INDEX) ||
568*4882a593Smuzhiyun              (a->transparentIndex == b->transparentIndex)) &&
569*4882a593Smuzhiyun 
570*4882a593Smuzhiyun             (a->sampleBuffers == b->sampleBuffers) &&
571*4882a593Smuzhiyun             (a->samples == b->samples) &&
572*4882a593Smuzhiyun             ((a->drawableType & b->drawableType) != 0) &&
573*4882a593Smuzhiyun             (a->renderType == b->renderType) &&
574*4882a593Smuzhiyun             (a->maxPbufferWidth == b->maxPbufferWidth) &&
575*4882a593Smuzhiyun             (a->maxPbufferHeight == b->maxPbufferHeight) &&
576*4882a593Smuzhiyun             (a->maxPbufferPixels == b->maxPbufferPixels) &&
577*4882a593Smuzhiyun             (a->optimalPbufferWidth == b->optimalPbufferWidth) &&
578*4882a593Smuzhiyun             (a->optimalPbufferHeight == b->optimalPbufferHeight) &&
579*4882a593Smuzhiyun             (a->swapMethod == b->swapMethod) &&
580*4882a593Smuzhiyun             (a->bindToTextureRgb == b->bindToTextureRgb) &&
581*4882a593Smuzhiyun             (a->bindToTextureRgba == b->bindToTextureRgba) &&
582*4882a593Smuzhiyun             (a->bindToMipmapTexture == b->bindToMipmapTexture) &&
583*4882a593Smuzhiyun             (a->bindToTextureTargets == b->bindToTextureTargets) &&
584*4882a593Smuzhiyun             (a->yInverted == b->yInverted));
585*4882a593Smuzhiyun }
586