dri: Remove a few unused dri helper functions
[mesa.git] / src / mesa / drivers / dri / common / utils.c
1 /*
2 * (C) Copyright IBM Corporation 2002, 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 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file utils.c
27 * Utility functions for DRI drivers.
28 *
29 * \author Ian Romanick <idr@us.ibm.com>
30 */
31
32 #include <string.h>
33 #include <stdlib.h>
34 #include "main/mtypes.h"
35 #include "main/cpuinfo.h"
36 #include "main/extensions.h"
37 #include "utils.h"
38
39
40 /**
41 * Print message to \c stderr if the \c LIBGL_DEBUG environment variable
42 * is set.
43 *
44 * Is called from the drivers.
45 *
46 * \param f \c printf like format string.
47 */
48 void
49 __driUtilMessage(const char *f, ...)
50 {
51 va_list args;
52
53 if (getenv("LIBGL_DEBUG")) {
54 fprintf(stderr, "libGL: ");
55 va_start(args, f);
56 vfprintf(stderr, f, args);
57 va_end(args);
58 fprintf(stderr, "\n");
59 }
60 }
61
62
63 unsigned
64 driParseDebugString( const char * debug,
65 const struct dri_debug_control * control )
66 {
67 unsigned flag;
68
69
70 flag = 0;
71 if ( debug != NULL ) {
72 while( control->string != NULL ) {
73 if ( !strcmp( debug, "all" ) ||
74 strstr( debug, control->string ) != NULL ) {
75 flag |= control->flag;
76 }
77
78 control++;
79 }
80 }
81
82 return flag;
83 }
84
85
86
87 /**
88 * Create the \c GL_RENDERER string for DRI drivers.
89 *
90 * Almost all DRI drivers use a \c GL_RENDERER string of the form:
91 *
92 * "Mesa DRI <chip> <driver date> <AGP speed) <CPU information>"
93 *
94 * Using the supplied chip name, driver data, and AGP speed, this function
95 * creates the string.
96 *
97 * \param buffer Buffer to hold the \c GL_RENDERER string.
98 * \param hardware_name Name of the hardware.
99 * \param agp_mode AGP mode (speed).
100 *
101 * \returns
102 * The length of the string stored in \c buffer. This does \b not include
103 * the terminating \c NUL character.
104 */
105 unsigned
106 driGetRendererString( char * buffer, const char * hardware_name,
107 GLuint agp_mode )
108 {
109 unsigned offset;
110 char *cpu;
111
112 offset = sprintf( buffer, "Mesa DRI %s", hardware_name );
113
114 /* Append any AGP-specific information.
115 */
116 switch ( agp_mode ) {
117 case 1:
118 case 2:
119 case 4:
120 case 8:
121 offset += sprintf( & buffer[ offset ], " AGP %ux", agp_mode );
122 break;
123
124 default:
125 break;
126 }
127
128 /* Append any CPU-specific information.
129 */
130 cpu = _mesa_get_cpu_string();
131 if (cpu) {
132 offset += sprintf(buffer + offset, " %s", cpu);
133 free(cpu);
134 }
135
136 return offset;
137 }
138
139
140 /**
141 * Creates a set of \c struct gl_config that a driver will expose.
142 *
143 * A set of \c struct gl_config will be created based on the supplied
144 * parameters. The number of modes processed will be 2 *
145 * \c num_depth_stencil_bits * \c num_db_modes.
146 *
147 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
148 * \c db_modes, and \c visType into each \c struct gl_config element.
149 * However, the meanings of \c fb_format and \c fb_type require further
150 * explanation. The \c fb_format specifies which color components are in
151 * each pixel and what the default order is. For example, \c GL_RGB specifies
152 * that red, green, blue are available and red is in the "most significant"
153 * position and blue is in the "least significant". The \c fb_type specifies
154 * the bit sizes of each component and the actual ordering. For example, if
155 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
156 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
157 * the red value.
158 *
159 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
160 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
161 * \c struct gl_config structure is \b identical to the \c GL_RGBA or
162 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
163 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
164 * still uses 32-bits.
165 *
166 * If in doubt, look at the tables used in the function.
167 *
168 * \param ptr_to_modes Pointer to a pointer to a linked list of
169 * \c struct gl_config. Upon completion, a pointer to
170 * the next element to be process will be stored here.
171 * If the function fails and returns \c GL_FALSE, this
172 * value will be unmodified, but some elements in the
173 * linked list may be modified.
174 * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
175 * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
176 * \param fb_type Type of the pixels in the framebuffer. Currently only
177 * \c GL_UNSIGNED_SHORT_5_6_5,
178 * \c GL_UNSIGNED_SHORT_5_6_5_REV,
179 * \c GL_UNSIGNED_INT_8_8_8_8, and
180 * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
181 * \param depth_bits Array of depth buffer sizes to be exposed.
182 * \param stencil_bits Array of stencil buffer sizes to be exposed.
183 * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
184 * \c stencil_bits.
185 * \param db_modes Array of buffer swap modes. If an element has a
186 * value of \c GLX_NONE, then it represents a
187 * single-buffered mode. Other valid values are
188 * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
189 * \c GLX_SWAP_UNDEFINED_OML. See the
190 * GLX_OML_swap_method extension spec for more details.
191 * \param num_db_modes Number of entries in \c db_modes.
192 * \param msaa_samples Array of msaa sample count. 0 represents a visual
193 * without a multisample buffer.
194 * \param num_msaa_modes Number of entries in \c msaa_samples.
195 * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
196 * \c GLX_DIRECT_COLOR.
197 *
198 * \returns
199 * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
200 * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
201 * \c fb_type).
202 *
203 * \todo
204 * There is currently no way to support packed RGB modes (i.e., modes with
205 * exactly 3 bytes per pixel) or floating-point modes. This could probably
206 * be done by creating some new, private enums with clever names likes
207 * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
208 * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
209 */
210 __DRIconfig **
211 driCreateConfigs(GLenum fb_format, GLenum fb_type,
212 const uint8_t * depth_bits, const uint8_t * stencil_bits,
213 unsigned num_depth_stencil_bits,
214 const GLenum * db_modes, unsigned num_db_modes,
215 const uint8_t * msaa_samples, unsigned num_msaa_modes,
216 GLboolean enable_accum)
217 {
218 static const uint8_t bits_table[4][4] = {
219 /* R G B A */
220 { 3, 3, 2, 0 }, /* Any GL_UNSIGNED_BYTE_3_3_2 */
221 { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
222 { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
223 { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
224 };
225
226 static const uint32_t masks_table_rgb[6][4] = {
227 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
228 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
229 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
230 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
231 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8 */
232 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 } /* 8_8_8_8_REV */
233 };
234
235 static const uint32_t masks_table_rgba[6][4] = {
236 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
237 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
238 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
239 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
240 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8 */
241 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
242 };
243
244 static const uint32_t masks_table_bgr[6][4] = {
245 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
246 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
247 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
248 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
249 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8 */
250 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
251 };
252
253 static const uint32_t masks_table_bgra[6][4] = {
254 { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
255 { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
256 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
257 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
258 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8 */
259 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
260 };
261
262 static const uint8_t bytes_per_pixel[6] = {
263 1, /* 3_3_2 */
264 1, /* 2_3_3_REV */
265 2, /* 5_6_5 */
266 2, /* 5_6_5_REV */
267 4, /* 8_8_8_8 */
268 4 /* 8_8_8_8_REV */
269 };
270
271 const uint8_t * bits;
272 const uint32_t * masks;
273 int index;
274 __DRIconfig **configs, **c;
275 struct gl_config *modes;
276 unsigned i, j, k, h;
277 unsigned num_modes;
278 unsigned num_accum_bits = (enable_accum) ? 2 : 1;
279
280 switch ( fb_type ) {
281 case GL_UNSIGNED_BYTE_3_3_2:
282 index = 0;
283 break;
284 case GL_UNSIGNED_BYTE_2_3_3_REV:
285 index = 1;
286 break;
287 case GL_UNSIGNED_SHORT_5_6_5:
288 index = 2;
289 break;
290 case GL_UNSIGNED_SHORT_5_6_5_REV:
291 index = 3;
292 break;
293 case GL_UNSIGNED_INT_8_8_8_8:
294 index = 4;
295 break;
296 case GL_UNSIGNED_INT_8_8_8_8_REV:
297 index = 5;
298 break;
299 default:
300 fprintf( stderr, "[%s:%u] Unknown framebuffer type 0x%04x.\n",
301 __FUNCTION__, __LINE__, fb_type );
302 return NULL;
303 }
304
305
306 /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
307 * the _REV versions.
308 *
309 * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
310 */
311
312 switch ( fb_format ) {
313 case GL_RGB:
314 masks = masks_table_rgb[ index ];
315 break;
316
317 case GL_RGBA:
318 masks = masks_table_rgba[ index ];
319 break;
320
321 case GL_BGR:
322 masks = masks_table_bgr[ index ];
323 break;
324
325 case GL_BGRA:
326 masks = masks_table_bgra[ index ];
327 break;
328
329 default:
330 fprintf( stderr, "[%s:%u] Unknown framebuffer format 0x%04x.\n",
331 __FUNCTION__, __LINE__, fb_format );
332 return NULL;
333 }
334
335 switch ( bytes_per_pixel[ index ] ) {
336 case 1:
337 bits = bits_table[0];
338 break;
339 case 2:
340 bits = bits_table[1];
341 break;
342 default:
343 bits = ((fb_format == GL_RGB) || (fb_format == GL_BGR))
344 ? bits_table[2]
345 : bits_table[3];
346 break;
347 }
348
349 num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits * num_msaa_modes;
350 configs = calloc(1, (num_modes + 1) * sizeof *configs);
351 if (configs == NULL)
352 return NULL;
353
354 c = configs;
355 for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) {
356 for ( i = 0 ; i < num_db_modes ; i++ ) {
357 for ( h = 0 ; h < num_msaa_modes; h++ ) {
358 for ( j = 0 ; j < num_accum_bits ; j++ ) {
359 *c = malloc (sizeof **c);
360 modes = &(*c)->modes;
361 c++;
362
363 memset(modes, 0, sizeof *modes);
364 modes->redBits = bits[0];
365 modes->greenBits = bits[1];
366 modes->blueBits = bits[2];
367 modes->alphaBits = bits[3];
368 modes->redMask = masks[0];
369 modes->greenMask = masks[1];
370 modes->blueMask = masks[2];
371 modes->alphaMask = masks[3];
372 modes->rgbBits = modes->redBits + modes->greenBits
373 + modes->blueBits + modes->alphaBits;
374
375 modes->accumRedBits = 16 * j;
376 modes->accumGreenBits = 16 * j;
377 modes->accumBlueBits = 16 * j;
378 modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
379 modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
380
381 modes->stencilBits = stencil_bits[k];
382 modes->depthBits = depth_bits[k];
383
384 modes->transparentPixel = GLX_NONE;
385 modes->transparentRed = GLX_DONT_CARE;
386 modes->transparentGreen = GLX_DONT_CARE;
387 modes->transparentBlue = GLX_DONT_CARE;
388 modes->transparentAlpha = GLX_DONT_CARE;
389 modes->transparentIndex = GLX_DONT_CARE;
390 modes->rgbMode = GL_TRUE;
391
392 if ( db_modes[i] == GLX_NONE ) {
393 modes->doubleBufferMode = GL_FALSE;
394 }
395 else {
396 modes->doubleBufferMode = GL_TRUE;
397 modes->swapMethod = db_modes[i];
398 }
399
400 modes->samples = msaa_samples[h];
401 modes->sampleBuffers = modes->samples ? 1 : 0;
402
403
404 modes->haveAccumBuffer = ((modes->accumRedBits +
405 modes->accumGreenBits +
406 modes->accumBlueBits +
407 modes->accumAlphaBits) > 0);
408 modes->haveDepthBuffer = (modes->depthBits > 0);
409 modes->haveStencilBuffer = (modes->stencilBits > 0);
410
411 modes->bindToTextureRgb = GL_TRUE;
412 modes->bindToTextureRgba = GL_TRUE;
413 modes->bindToMipmapTexture = GL_FALSE;
414 modes->bindToTextureTargets =
415 __DRI_ATTRIB_TEXTURE_1D_BIT |
416 __DRI_ATTRIB_TEXTURE_2D_BIT |
417 __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT;
418
419 modes->sRGBCapable = GL_FALSE;
420 }
421 }
422 }
423 }
424 *c = NULL;
425
426 return configs;
427 }
428
429 __DRIconfig **driConcatConfigs(__DRIconfig **a,
430 __DRIconfig **b)
431 {
432 __DRIconfig **all;
433 int i, j, index;
434
435 i = 0;
436 while (a[i] != NULL)
437 i++;
438 j = 0;
439 while (b[j] != NULL)
440 j++;
441
442 all = malloc((i + j + 1) * sizeof *all);
443 index = 0;
444 for (i = 0; a[i] != NULL; i++)
445 all[index++] = a[i];
446 for (j = 0; b[j] != NULL; j++)
447 all[index++] = b[j];
448 all[index++] = NULL;
449
450 free(a);
451 free(b);
452
453 return all;
454 }
455
456 #define __ATTRIB(attrib, field) \
457 { attrib, offsetof(struct gl_config, field) }
458
459 static const struct { unsigned int attrib, offset; } attribMap[] = {
460 __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits),
461 __ATTRIB(__DRI_ATTRIB_LEVEL, level),
462 __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits),
463 __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits),
464 __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits),
465 __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits),
466 __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits),
467 __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits),
468 __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits),
469 __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits),
470 __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits),
471 __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits),
472 __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers),
473 __ATTRIB(__DRI_ATTRIB_SAMPLES, samples),
474 __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode),
475 __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode),
476 __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers),
477 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel),
478 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentPixel),
479 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed),
480 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen),
481 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue),
482 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha),
483 __ATTRIB(__DRI_ATTRIB_FLOAT_MODE, floatMode),
484 __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask),
485 __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask),
486 __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask),
487 __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask),
488 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth),
489 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight),
490 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels),
491 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth),
492 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight),
493 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod),
494 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb),
495 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba),
496 __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, bindToMipmapTexture),
497 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS, bindToTextureTargets),
498 __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),
499 __ATTRIB(__DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE, sRGBCapable),
500
501 /* The struct field doesn't matter here, these are handled by the
502 * switch in driGetConfigAttribIndex. We need them in the array
503 * so the iterator includes them though.*/
504 __ATTRIB(__DRI_ATTRIB_RENDER_TYPE, level),
505 __ATTRIB(__DRI_ATTRIB_CONFIG_CAVEAT, level),
506 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, level)
507 };
508
509 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
510
511
512 /**
513 * Return the value of a configuration attribute. The attribute is
514 * indicated by the index.
515 */
516 static int
517 driGetConfigAttribIndex(const __DRIconfig *config,
518 unsigned int index, unsigned int *value)
519 {
520 switch (attribMap[index].attrib) {
521 case __DRI_ATTRIB_RENDER_TYPE:
522 /* no support for color index mode */
523 *value = __DRI_ATTRIB_RGBA_BIT;
524 break;
525 case __DRI_ATTRIB_CONFIG_CAVEAT:
526 if (config->modes.visualRating == GLX_NON_CONFORMANT_CONFIG)
527 *value = __DRI_ATTRIB_NON_CONFORMANT_CONFIG;
528 else if (config->modes.visualRating == GLX_SLOW_CONFIG)
529 *value = __DRI_ATTRIB_SLOW_BIT;
530 else
531 *value = 0;
532 break;
533 case __DRI_ATTRIB_SWAP_METHOD:
534 /* XXX no return value??? */
535 break;
536
537 case __DRI_ATTRIB_FLOAT_MODE:
538 /* this field is not int-sized */
539 *value = config->modes.floatMode;
540 break;
541
542 default:
543 /* any other int-sized field */
544 *value = *(unsigned int *)
545 ((char *) &config->modes + attribMap[index].offset);
546
547 break;
548 }
549
550 return GL_TRUE;
551 }
552
553
554 /**
555 * Get the value of a configuration attribute.
556 * \param attrib the attribute (one of the _DRI_ATTRIB_x tokens)
557 * \param value returns the attribute's value
558 * \return 1 for success, 0 for failure
559 */
560 int
561 driGetConfigAttrib(const __DRIconfig *config,
562 unsigned int attrib, unsigned int *value)
563 {
564 int i;
565
566 for (i = 0; i < ARRAY_SIZE(attribMap); i++)
567 if (attribMap[i].attrib == attrib)
568 return driGetConfigAttribIndex(config, i, value);
569
570 return GL_FALSE;
571 }
572
573
574 /**
575 * Get a configuration attribute name and value, given an index.
576 * \param index which field of the __DRIconfig to query
577 * \param attrib returns the attribute name (one of the _DRI_ATTRIB_x tokens)
578 * \param value returns the attribute's value
579 * \return 1 for success, 0 for failure
580 */
581 int
582 driIndexConfigAttrib(const __DRIconfig *config, int index,
583 unsigned int *attrib, unsigned int *value)
584 {
585 if (index >= 0 && index < ARRAY_SIZE(attribMap)) {
586 *attrib = attribMap[index].attrib;
587 return driGetConfigAttribIndex(config, index, value);
588 }
589
590 return GL_FALSE;
591 }