2 * (C) Copyright IBM Corporation 2002, 2004
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:
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
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.
25 * Ian Romanick <idr@us.ibm.com>
32 #include "extensions.h"
35 #if !defined( DRI_NEW_INTERFACE_ONLY )
36 #include "xf86dri.h" /* For XF86DRIQueryVersion prototype. */
39 #if defined(USE_X86_ASM)
40 #include "x86/common_x86_asm.h"
44 driParseDebugString( const char * debug
,
45 const struct dri_debug_control
* control
)
51 if ( debug
!= NULL
) {
52 while( control
->string
!= NULL
) {
53 if ( !strcmp( debug
, "all" ) ||
54 strstr( debug
, control
->string
) != NULL
) {
55 flag
|= control
->flag
;
69 driGetRendererString( char * buffer
, const char * hardware_name
,
70 const char * driver_date
, GLuint agp_mode
)
75 char * tdnow_str
= "";
81 offset
= sprintf( buffer
, "Mesa DRI %s %s", hardware_name
, driver_date
);
83 /* Append any AGP-specific information.
90 offset
+= sprintf( & buffer
[ offset
], " AGP %ux", agp_mode
);
97 /* Append any CPU-specific information.
100 if ( _mesa_x86_cpu_features
) {
105 mmx_str
= (cpu_has_mmxext
) ? "/MMX+" : "/MMX";
108 # ifdef USE_3DNOW_ASM
109 if ( cpu_has_3dnow
) {
110 tdnow_str
= (cpu_has_3dnowext
) ? "/3DNow!+" : "/3DNow!";
115 sse_str
= (cpu_has_xmm2
) ? "/SSE2" : "/SSE";
119 offset
+= sprintf( & buffer
[ offset
], "%s%s%s%s",
120 x86_str
, mmx_str
, tdnow_str
, sse_str
);
122 #elif defined(USE_SPARC_ASM)
124 offset
+= sprintf( & buffer
[ offset
], " Sparc" );
134 void driInitExtensions( GLcontext
* ctx
,
135 const char * const extensions_to_enable
[],
136 GLboolean enable_imaging
)
140 if ( enable_imaging
) {
141 _mesa_enable_imaging_extensions( ctx
);
144 for ( i
= 0 ; extensions_to_enable
[i
] != NULL
; i
++ ) {
145 _mesa_enable_extension( ctx
, extensions_to_enable
[i
] );
152 #ifndef DRI_NEW_INTERFACE_ONLY
154 * Utility function used by drivers to test the verions of other components.
157 * All drivers using the new interface should use \c driCheckDriDdxVersions2
158 * instead. This function is implemented using a call that is not available
159 * to drivers using the new interface. Furthermore, the information gained
160 * by this call (the DRI and DDX version information) is already provided to
161 * the driver via the new interface.
164 driCheckDriDdxDrmVersions(__DRIscreenPrivate
*sPriv
,
165 const char * driver_name
,
166 int dri_major
, int dri_minor
,
167 int ddx_major
, int ddx_minor
,
168 int drm_major
, int drm_minor
)
170 static const char format
[] = "%s DRI driver expected %s version %d.%d.x "
171 "but got version %d.%d.%d";
172 int major
, minor
, patch
;
174 /* Check the DRI version */
175 if (XF86DRIQueryVersion(sPriv
->display
, &major
, &minor
, &patch
)) {
176 if (major
!= dri_major
|| minor
< dri_minor
) {
177 __driUtilMessage(format
, driver_name
, "DRI", dri_major
, dri_minor
,
178 major
, minor
, patch
);
183 /* Check that the DDX driver version is compatible */
184 if (sPriv
->ddxMajor
!= ddx_major
|| sPriv
->ddxMinor
< ddx_minor
) {
185 __driUtilMessage(format
, driver_name
, "DDX", ddx_major
, ddx_minor
,
186 sPriv
->ddxMajor
, sPriv
->ddxMinor
, sPriv
->ddxPatch
);
190 /* Check that the DRM driver version is compatible */
191 if (sPriv
->drmMajor
!= drm_major
|| sPriv
->drmMinor
< drm_minor
) {
192 __driUtilMessage(format
, driver_name
, "DRM", drm_major
, drm_minor
,
193 sPriv
->drmMajor
, sPriv
->drmMinor
, sPriv
->drmPatch
);
199 #endif /* DRI_NEW_INTERFACE_ONLY */
202 * Utility function used by drivers to test the verions of other components.
204 * If one of the version requirements is not met, a message is logged using
205 * \c __driUtilMessage.
207 * \param driver_name Name of the driver. Used in error messages.
208 * \param driActual Actual DRI version supplied __driCreateNewScreen.
209 * \param driExpected Minimum DRI version required by the driver.
210 * \param ddxActual Actual DDX version supplied __driCreateNewScreen.
211 * \param ddxExpected Minimum DDX version required by the driver.
212 * \param drmActual Actual DRM version supplied __driCreateNewScreen.
213 * \param drmExpected Minimum DRM version required by the driver.
215 * \returns \c GL_TRUE if all version requirements are met. Otherwise,
216 * \c GL_FALSE is returned.
218 * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions, __driUtilMessage
221 driCheckDriDdxDrmVersions2(const char * driver_name
,
222 const __DRIversion
* driActual
,
223 const __DRIversion
* driExpected
,
224 const __DRIversion
* ddxActual
,
225 const __DRIversion
* ddxExpected
,
226 const __DRIversion
* drmActual
,
227 const __DRIversion
* drmExpected
)
229 static const char format
[] = "%s DRI driver expected %s version %d.%d.x "
230 "but got version %d.%d.%d";
233 /* Check the DRI version */
234 if ( (driActual
->major
!= driExpected
->major
)
235 || (driActual
->minor
< driExpected
->minor
) ) {
236 __driUtilMessage(format
, driver_name
, "DRI",
237 driExpected
->major
, driExpected
->minor
,
238 driActual
->major
, driActual
->minor
, driActual
->patch
);
242 /* Check that the DDX driver version is compatible */
243 if ( (ddxActual
->major
!= ddxExpected
->major
)
244 || (ddxActual
->minor
< ddxExpected
->minor
) ) {
245 __driUtilMessage(format
, driver_name
, "DDX",
246 ddxExpected
->major
, ddxExpected
->minor
,
247 ddxActual
->major
, ddxActual
->minor
, ddxActual
->patch
);
251 /* Check that the DRM driver version is compatible */
252 if ( (drmActual
->major
!= drmExpected
->major
)
253 || (drmActual
->minor
< drmExpected
->minor
) ) {
254 __driUtilMessage(format
, driver_name
, "DRM",
255 drmExpected
->major
, drmExpected
->minor
,
256 drmActual
->major
, drmActual
->minor
, drmActual
->patch
);
264 GLboolean
driClipRectToFramebuffer( const GLframebuffer
*buffer
,
266 GLsizei
*width
, GLsizei
*height
)
269 if (*x
< buffer
->_Xmin
) {
270 *width
-= (buffer
->_Xmin
- *x
);
275 if (*x
+ *width
> buffer
->_Xmax
)
276 *width
-= (*x
+ *width
- buffer
->_Xmax
- 1);
281 /* bottom clipping */
282 if (*y
< buffer
->_Ymin
) {
283 *height
-= (buffer
->_Ymin
- *y
);
288 if (*y
+ *height
> buffer
->_Ymax
)
289 *height
-= (*y
+ *height
- buffer
->_Ymax
- 1);
300 * Creates a set of \c __GLcontextModes that a driver will expose.
302 * A set of \c __GLcontextModes will be created based on the supplied
303 * parameters. The number of modes processed will be 2 *
304 * \c num_depth_stencil_bits * \c num_db_modes.
306 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
307 * \c db_modes, and \c visType into each \c __GLcontextModes element.
308 * However, the meanings of \c fb_format and \c fb_type require further
309 * explanation. The \c fb_format specifies which color components are in
310 * each pixel and what the default order is. For example, \c GL_RGB specifies
311 * that red, green, blue are available and red is in the "most significant"
312 * position and blue is in the "least significant". The \c fb_type specifies
313 * the bit sizes of each component and the actual ordering. For example, if
314 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
315 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
318 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
319 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
320 * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
321 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
322 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
323 * still uses 32-bits.
325 * If in doubt, look at the tables used in the function.
327 * \param ptr_to_modes Pointer to a pointer to a linked list of
328 * \c __GLcontextModes. Upon completion, a pointer to
329 * the next element to be process will be stored here.
330 * If the function fails and returns \c GL_FALSE, this
331 * value will be unmodified, but some elements in the
332 * linked list may be modified.
333 * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
334 * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
335 * \param fb_type Type of the pixels in the framebuffer. Currently only
336 * \c GL_UNSIGNED_SHORT_5_6_5,
337 * \c GL_UNSIGNED_SHORT_5_6_5_REV,
338 * \c GL_UNSIGNED_INT_8_8_8_8, and
339 * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
340 * \param depth_bits Array of depth buffer sizes to be exposed.
341 * \param stencil_bits Array of stencil buffer sizes to be exposed.
342 * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
344 * \param db_modes Array of buffer swap modes. If an element has a
345 * value of \c GLX_NONE, then it represents a
346 * single-buffered mode. Other valid values are
347 * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
348 * \c GLX_SWAP_UNDEFINED_OML. See the
349 * GLX_OML_swap_method extension spec for more details.
350 * \param num_db_modes Number of entries in \c db_modes.
351 * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
352 * \c GLX_DIRECT_COLOR.
355 * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
356 * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
360 * There is currently no way to support packed RGB modes (i.e., modes with
361 * exactly 3 bytes per pixel) or floating-point modes. This could probably
362 * be done by creating some new, private enums with clever names likes
363 * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
364 * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
367 driFillInModes( __GLcontextModes
** ptr_to_modes
,
368 GLenum fb_format
, GLenum fb_type
,
369 const uint8_t * depth_bits
, const uint8_t * stencil_bits
,
370 unsigned num_depth_stencil_bits
,
371 const GLenum
* db_modes
, unsigned num_db_modes
,
374 static const uint8_t bits_table
[3][4] = {
376 { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
377 { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
378 { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
381 /* The following arrays are all indexed by the fb_type masked with 0x07.
382 * Given the four supported fb_type values, this results in valid array
383 * indices of 3, 4, 5, and 7.
385 static const uint32_t masks_table_rgb
[8][4] = {
386 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
387 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
388 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
389 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
390 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
391 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8 */
392 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
393 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 } /* 8_8_8_8_REV */
396 static const uint32_t masks_table_rgba
[8][4] = {
397 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
398 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
399 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
400 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
401 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
402 { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8 */
403 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
404 { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
407 static const uint32_t masks_table_bgr
[8][4] = {
408 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
409 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
410 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
411 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
412 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
413 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8 */
414 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
415 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
418 static const uint32_t masks_table_bgra
[8][4] = {
419 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
420 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
421 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
422 { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
423 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
424 { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8 */
425 { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
426 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
429 static const uint8_t bytes_per_pixel
[8] = {
430 0, 0, 0, 2, 2, 4, 0, 4
433 const uint8_t * bits
;
434 const uint32_t * masks
;
435 const int index
= fb_type
& 0x07;
436 __GLcontextModes
* modes
= *ptr_to_modes
;
442 if ( bytes_per_pixel
[ index
] == 0 ) {
443 fprintf( stderr
, "[%s:%u] Framebuffer type 0x%04x has 0 bytes per pixel.\n",
444 __func__
, __LINE__
, fb_type
);
449 /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
452 * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
455 switch ( fb_format
) {
457 bits
= (bytes_per_pixel
[ index
] == 2)
458 ? bits_table
[0] : bits_table
[1];
459 masks
= masks_table_rgb
[ index
];
463 bits
= (bytes_per_pixel
[ index
] == 2)
464 ? bits_table
[0] : bits_table
[2];
465 masks
= masks_table_rgba
[ index
];
469 bits
= (bytes_per_pixel
[ index
] == 2)
470 ? bits_table
[0] : bits_table
[1];
471 masks
= masks_table_bgr
[ index
];
475 bits
= (bytes_per_pixel
[ index
] == 2)
476 ? bits_table
[0] : bits_table
[2];
477 masks
= masks_table_bgra
[ index
];
481 fprintf( stderr
, "[%s:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.\n",
482 __func__
, __LINE__
, fb_format
);
487 for ( k
= 0 ; k
< num_depth_stencil_bits
; k
++ ) {
488 for ( i
= 0 ; i
< num_db_modes
; i
++ ) {
489 for ( j
= 0 ; j
< 2 ; j
++ ) {
491 modes
->redBits
= bits
[0];
492 modes
->greenBits
= bits
[1];
493 modes
->blueBits
= bits
[2];
494 modes
->alphaBits
= bits
[3];
495 modes
->redMask
= masks
[0];
496 modes
->greenMask
= masks
[1];
497 modes
->blueMask
= masks
[2];
498 modes
->alphaMask
= masks
[3];
499 modes
->rgbBits
= modes
->redBits
+ modes
->greenBits
500 + modes
->blueBits
+ modes
->alphaBits
;
502 modes
->accumRedBits
= 16 * j
;
503 modes
->accumGreenBits
= 16 * j
;
504 modes
->accumBlueBits
= 16 * j
;
505 modes
->accumAlphaBits
= (masks
[3] != 0) ? 16 * j
: 0;
506 modes
->visualRating
= (j
== 0) ? GLX_NONE
: GLX_SLOW_CONFIG
;
508 modes
->stencilBits
= stencil_bits
[k
];
509 modes
->depthBits
= depth_bits
[k
];
511 modes
->visualType
= visType
;
512 modes
->renderType
= GLX_RGBA_BIT
;
513 modes
->drawableType
= GLX_WINDOW_BIT
;
514 modes
->rgbMode
= GL_TRUE
;
516 if ( db_modes
[i
] == GLX_NONE
) {
517 modes
->doubleBufferMode
= GL_FALSE
;
520 modes
->doubleBufferMode
= GL_TRUE
;
521 modes
->swapMethod
= db_modes
[i
];
529 *ptr_to_modes
= modes
;