Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

utils.c 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  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. * \file utils.c
  26. * Utility functions for DRI drivers.
  27. *
  28. * \author Ian Romanick <idr@us.ibm.com>
  29. */
  30. #include <string.h>
  31. #include <stdlib.h>
  32. #include "main/mtypes.h"
  33. #include "main/cpuinfo.h"
  34. #include "main/extensions.h"
  35. #include "utils.h"
  36. unsigned
  37. driParseDebugString( const char * debug,
  38. const struct dri_debug_control * control )
  39. {
  40. unsigned flag;
  41. flag = 0;
  42. if ( debug != NULL ) {
  43. while( control->string != NULL ) {
  44. if ( !strcmp( debug, "all" ) ||
  45. strstr( debug, control->string ) != NULL ) {
  46. flag |= control->flag;
  47. }
  48. control++;
  49. }
  50. }
  51. return flag;
  52. }
  53. /**
  54. * Create the \c GL_RENDERER string for DRI drivers.
  55. *
  56. * Almost all DRI drivers use a \c GL_RENDERER string of the form:
  57. *
  58. * "Mesa DRI <chip> <driver date> <AGP speed) <CPU information>"
  59. *
  60. * Using the supplied chip name, driver data, and AGP speed, this function
  61. * creates the string.
  62. *
  63. * \param buffer Buffer to hold the \c GL_RENDERER string.
  64. * \param hardware_name Name of the hardware.
  65. * \param driver_date Driver date.
  66. * \param agp_mode AGP mode (speed).
  67. *
  68. * \returns
  69. * The length of the string stored in \c buffer. This does \b not include
  70. * the terminating \c NUL character.
  71. */
  72. unsigned
  73. driGetRendererString( char * buffer, const char * hardware_name,
  74. const char * driver_date, GLuint agp_mode )
  75. {
  76. unsigned offset;
  77. char *cpu;
  78. offset = sprintf( buffer, "Mesa DRI %s %s", hardware_name, driver_date );
  79. /* Append any AGP-specific information.
  80. */
  81. switch ( agp_mode ) {
  82. case 1:
  83. case 2:
  84. case 4:
  85. case 8:
  86. offset += sprintf( & buffer[ offset ], " AGP %ux", agp_mode );
  87. break;
  88. default:
  89. break;
  90. }
  91. /* Append any CPU-specific information.
  92. */
  93. cpu = _mesa_get_cpu_string();
  94. if (cpu) {
  95. offset += sprintf(buffer + offset, " %s", cpu);
  96. free(cpu);
  97. }
  98. return offset;
  99. }
  100. #define need_GL_ARB_draw_buffers
  101. #define need_GL_ARB_multisample
  102. #define need_GL_ARB_texture_compression
  103. #define need_GL_ARB_transpose_matrix
  104. #define need_GL_ARB_vertex_buffer_object
  105. #define need_GL_ARB_window_pos
  106. #define need_GL_EXT_compiled_vertex_array
  107. #define need_GL_EXT_multi_draw_arrays
  108. #define need_GL_EXT_polygon_offset
  109. #define need_GL_EXT_texture_object
  110. #define need_GL_EXT_vertex_array
  111. #define need_GL_IBM_multimode_draw_arrays
  112. #define need_GL_MESA_window_pos
  113. /* These are needed in *all* drivers because Mesa internally implements
  114. * certain functionality in terms of functions provided by these extensions.
  115. * For example, glBlendFunc is implemented by calling glBlendFuncSeparateEXT.
  116. */
  117. #define need_GL_EXT_blend_func_separate
  118. #define need_GL_NV_vertex_program
  119. #include "main/remap_helper.h"
  120. static const struct dri_extension all_mesa_extensions[] = {
  121. { "GL_ARB_draw_buffers", GL_ARB_draw_buffers_functions },
  122. { "GL_ARB_multisample", GL_ARB_multisample_functions },
  123. { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions },
  124. { "GL_ARB_transpose_matrix", GL_ARB_transpose_matrix_functions },
  125. { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions},
  126. { "GL_ARB_window_pos", GL_ARB_window_pos_functions },
  127. { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions },
  128. { "GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions },
  129. { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions },
  130. { "GL_EXT_polygon_offset", GL_EXT_polygon_offset_functions },
  131. { "GL_EXT_texture_object", GL_EXT_texture_object_functions },
  132. { "GL_EXT_vertex_array", GL_EXT_vertex_array_functions },
  133. { "GL_IBM_multimode_draw_arrays", GL_IBM_multimode_draw_arrays_functions },
  134. { "GL_MESA_window_pos", GL_MESA_window_pos_functions },
  135. { "GL_NV_vertex_program", GL_NV_vertex_program_functions },
  136. { NULL, NULL }
  137. };
  138. /**
  139. * Enable and map extensions supported by the driver.
  140. *
  141. * When ctx is NULL, extensions are not enabled, but their functions
  142. * are still mapped. When extensions_to_enable is NULL, all static
  143. * functions known to mesa core are mapped.
  144. *
  145. * \bug
  146. * ARB_imaging isn't handled properly. In Mesa, enabling ARB_imaging also
  147. * enables all the sub-extensions that are folded into it. This means that
  148. * we need to add entry-points (via \c driInitSingleExtension) for those
  149. * new functions here.
  150. */
  151. void driInitExtensions( GLcontext * ctx,
  152. const struct dri_extension * extensions_to_enable,
  153. GLboolean enable_imaging )
  154. {
  155. static int first_time = 1;
  156. unsigned i;
  157. if ( first_time ) {
  158. first_time = 0;
  159. driInitExtensions( NULL, all_mesa_extensions, GL_FALSE );
  160. }
  161. if ( (ctx != NULL) && enable_imaging ) {
  162. _mesa_enable_imaging_extensions( ctx );
  163. }
  164. /* The caller is too lazy to list any extension */
  165. if ( extensions_to_enable == NULL ) {
  166. /* Map the static functions. Together with those mapped by remap
  167. * table, this should cover everything mesa core knows.
  168. */
  169. _mesa_map_static_functions();
  170. return;
  171. }
  172. for ( i = 0 ; extensions_to_enable[i].name != NULL ; i++ ) {
  173. driInitSingleExtension( ctx, & extensions_to_enable[i] );
  174. }
  175. }
  176. /**
  177. * Enable and map functions for a single extension
  178. *
  179. * \param ctx Context where extension is to be enabled.
  180. * \param ext Extension that is to be enabled.
  181. *
  182. * \sa driInitExtensions, _mesa_enable_extension, _mesa_map_function_array
  183. */
  184. void driInitSingleExtension( GLcontext * ctx,
  185. const struct dri_extension * ext )
  186. {
  187. if ( ext->functions != NULL ) {
  188. _mesa_map_function_array(ext->functions);
  189. }
  190. if ( ctx != NULL ) {
  191. _mesa_enable_extension( ctx, ext->name );
  192. }
  193. }
  194. /**
  195. * Utility function used by drivers to test the verions of other components.
  196. *
  197. * If one of the version requirements is not met, a message is logged using
  198. * \c __driUtilMessage.
  199. *
  200. * \param driver_name Name of the driver. Used in error messages.
  201. * \param driActual Actual DRI version supplied __driCreateNewScreen.
  202. * \param driExpected Minimum DRI version required by the driver.
  203. * \param ddxActual Actual DDX version supplied __driCreateNewScreen.
  204. * \param ddxExpected Minimum DDX minor and range of DDX major version required by the driver.
  205. * \param drmActual Actual DRM version supplied __driCreateNewScreen.
  206. * \param drmExpected Minimum DRM version required by the driver.
  207. *
  208. * \returns \c GL_TRUE if all version requirements are met. Otherwise,
  209. * \c GL_FALSE is returned.
  210. *
  211. * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions2, __driUtilMessage
  212. *
  213. * \todo
  214. * Now that the old \c driCheckDriDdxDrmVersions function is gone, this
  215. * function and \c driCheckDriDdxDrmVersions2 should be renamed.
  216. */
  217. GLboolean
  218. driCheckDriDdxDrmVersions3(const char * driver_name,
  219. const __DRIversion * driActual,
  220. const __DRIversion * driExpected,
  221. const __DRIversion * ddxActual,
  222. const __DRIutilversion2 * ddxExpected,
  223. const __DRIversion * drmActual,
  224. const __DRIversion * drmExpected)
  225. {
  226. static const char format[] = "%s DRI driver expected %s version %d.%d.x "
  227. "but got version %d.%d.%d\n";
  228. static const char format2[] = "%s DRI driver expected %s version %d-%d.%d.x "
  229. "but got version %d.%d.%d\n";
  230. /* Check the DRI version */
  231. if ( (driActual->major != driExpected->major)
  232. || (driActual->minor < driExpected->minor) ) {
  233. fprintf(stderr, format, driver_name, "DRI",
  234. driExpected->major, driExpected->minor,
  235. driActual->major, driActual->minor, driActual->patch);
  236. return GL_FALSE;
  237. }
  238. /* Check that the DDX driver version is compatible */
  239. if ( (ddxActual->major < ddxExpected->major_min)
  240. || (ddxActual->major > ddxExpected->major_max)
  241. || (ddxActual->minor < ddxExpected->minor) ) {
  242. fprintf(stderr, format2, driver_name, "DDX",
  243. ddxExpected->major_min, ddxExpected->major_max, ddxExpected->minor,
  244. ddxActual->major, ddxActual->minor, ddxActual->patch);
  245. return GL_FALSE;
  246. }
  247. /* Check that the DRM driver version is compatible */
  248. if ( (drmActual->major != drmExpected->major)
  249. || (drmActual->minor < drmExpected->minor) ) {
  250. fprintf(stderr, format, driver_name, "DRM",
  251. drmExpected->major, drmExpected->minor,
  252. drmActual->major, drmActual->minor, drmActual->patch);
  253. return GL_FALSE;
  254. }
  255. return GL_TRUE;
  256. }
  257. GLboolean
  258. driCheckDriDdxDrmVersions2(const char * driver_name,
  259. const __DRIversion * driActual,
  260. const __DRIversion * driExpected,
  261. const __DRIversion * ddxActual,
  262. const __DRIversion * ddxExpected,
  263. const __DRIversion * drmActual,
  264. const __DRIversion * drmExpected)
  265. {
  266. __DRIutilversion2 ddx_expected;
  267. ddx_expected.major_min = ddxExpected->major;
  268. ddx_expected.major_max = ddxExpected->major;
  269. ddx_expected.minor = ddxExpected->minor;
  270. ddx_expected.patch = ddxExpected->patch;
  271. return driCheckDriDdxDrmVersions3(driver_name, driActual,
  272. driExpected, ddxActual, & ddx_expected,
  273. drmActual, drmExpected);
  274. }
  275. GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
  276. GLint *x, GLint *y,
  277. GLsizei *width, GLsizei *height )
  278. {
  279. /* left clipping */
  280. if (*x < buffer->_Xmin) {
  281. *width -= (buffer->_Xmin - *x);
  282. *x = buffer->_Xmin;
  283. }
  284. /* right clipping */
  285. if (*x + *width > buffer->_Xmax)
  286. *width -= (*x + *width - buffer->_Xmax - 1);
  287. if (*width <= 0)
  288. return GL_FALSE;
  289. /* bottom clipping */
  290. if (*y < buffer->_Ymin) {
  291. *height -= (buffer->_Ymin - *y);
  292. *y = buffer->_Ymin;
  293. }
  294. /* top clipping */
  295. if (*y + *height > buffer->_Ymax)
  296. *height -= (*y + *height - buffer->_Ymax - 1);
  297. if (*height <= 0)
  298. return GL_FALSE;
  299. return GL_TRUE;
  300. }
  301. /**
  302. * Creates a set of \c __GLcontextModes that a driver will expose.
  303. *
  304. * A set of \c __GLcontextModes will be created based on the supplied
  305. * parameters. The number of modes processed will be 2 *
  306. * \c num_depth_stencil_bits * \c num_db_modes.
  307. *
  308. * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
  309. * \c db_modes, and \c visType into each \c __GLcontextModes element.
  310. * However, the meanings of \c fb_format and \c fb_type require further
  311. * explanation. The \c fb_format specifies which color components are in
  312. * each pixel and what the default order is. For example, \c GL_RGB specifies
  313. * that red, green, blue are available and red is in the "most significant"
  314. * position and blue is in the "least significant". The \c fb_type specifies
  315. * the bit sizes of each component and the actual ordering. For example, if
  316. * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
  317. * are the blue value, bits [10:5] are the green value, and bits [4:0] are
  318. * the red value.
  319. *
  320. * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
  321. * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
  322. * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
  323. * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
  324. * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
  325. * still uses 32-bits.
  326. *
  327. * If in doubt, look at the tables used in the function.
  328. *
  329. * \param ptr_to_modes Pointer to a pointer to a linked list of
  330. * \c __GLcontextModes. Upon completion, a pointer to
  331. * the next element to be process will be stored here.
  332. * If the function fails and returns \c GL_FALSE, this
  333. * value will be unmodified, but some elements in the
  334. * linked list may be modified.
  335. * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
  336. * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
  337. * \param fb_type Type of the pixels in the framebuffer. Currently only
  338. * \c GL_UNSIGNED_SHORT_5_6_5,
  339. * \c GL_UNSIGNED_SHORT_5_6_5_REV,
  340. * \c GL_UNSIGNED_INT_8_8_8_8, and
  341. * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
  342. * \param depth_bits Array of depth buffer sizes to be exposed.
  343. * \param stencil_bits Array of stencil buffer sizes to be exposed.
  344. * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
  345. * \c stencil_bits.
  346. * \param db_modes Array of buffer swap modes. If an element has a
  347. * value of \c GLX_NONE, then it represents a
  348. * single-buffered mode. Other valid values are
  349. * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
  350. * \c GLX_SWAP_UNDEFINED_OML. See the
  351. * GLX_OML_swap_method extension spec for more details.
  352. * \param num_db_modes Number of entries in \c db_modes.
  353. * \param msaa_samples Array of msaa sample count. 0 represents a visual
  354. * without a multisample buffer.
  355. * \param num_msaa_modes Number of entries in \c msaa_samples.
  356. * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
  357. * \c GLX_DIRECT_COLOR.
  358. *
  359. * \returns
  360. * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
  361. * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
  362. * \c fb_type).
  363. *
  364. * \todo
  365. * There is currently no way to support packed RGB modes (i.e., modes with
  366. * exactly 3 bytes per pixel) or floating-point modes. This could probably
  367. * be done by creating some new, private enums with clever names likes
  368. * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
  369. * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
  370. */
  371. __DRIconfig **
  372. driCreateConfigs(GLenum fb_format, GLenum fb_type,
  373. const uint8_t * depth_bits, const uint8_t * stencil_bits,
  374. unsigned num_depth_stencil_bits,
  375. const GLenum * db_modes, unsigned num_db_modes,
  376. const uint8_t * msaa_samples, unsigned num_msaa_modes,
  377. GLboolean enable_accum)
  378. {
  379. static const uint8_t bits_table[4][4] = {
  380. /* R G B A */
  381. { 3, 3, 2, 0 }, /* Any GL_UNSIGNED_BYTE_3_3_2 */
  382. { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
  383. { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
  384. { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
  385. };
  386. static const uint32_t masks_table_rgb[6][4] = {
  387. { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
  388. { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
  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. { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 } /* 8_8_8_8_REV */
  393. };
  394. static const uint32_t masks_table_rgba[6][4] = {
  395. { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */
  396. { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */
  397. { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */
  398. { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */
  399. { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8 */
  400. { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
  401. };
  402. static const uint32_t masks_table_bgr[6][4] = {
  403. { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
  404. { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
  405. { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
  406. { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
  407. { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8 */
  408. { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
  409. };
  410. static const uint32_t masks_table_bgra[6][4] = {
  411. { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */
  412. { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */
  413. { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */
  414. { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */
  415. { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8 */
  416. { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
  417. };
  418. static const uint8_t bytes_per_pixel[6] = {
  419. 1, /* 3_3_2 */
  420. 1, /* 2_3_3_REV */
  421. 2, /* 5_6_5 */
  422. 2, /* 5_6_5_REV */
  423. 4, /* 8_8_8_8 */
  424. 4 /* 8_8_8_8_REV */
  425. };
  426. const uint8_t * bits;
  427. const uint32_t * masks;
  428. int index;
  429. __DRIconfig **configs, **c;
  430. __GLcontextModes *modes;
  431. unsigned i, j, k, h;
  432. unsigned num_modes;
  433. unsigned num_accum_bits = (enable_accum) ? 2 : 1;
  434. switch ( fb_type ) {
  435. case GL_UNSIGNED_BYTE_3_3_2:
  436. index = 0;
  437. break;
  438. case GL_UNSIGNED_BYTE_2_3_3_REV:
  439. index = 1;
  440. break;
  441. case GL_UNSIGNED_SHORT_5_6_5:
  442. index = 2;
  443. break;
  444. case GL_UNSIGNED_SHORT_5_6_5_REV:
  445. index = 3;
  446. break;
  447. case GL_UNSIGNED_INT_8_8_8_8:
  448. index = 4;
  449. break;
  450. case GL_UNSIGNED_INT_8_8_8_8_REV:
  451. index = 5;
  452. break;
  453. default:
  454. fprintf( stderr, "[%s:%u] Unknown framebuffer type 0x%04x.\n",
  455. __FUNCTION__, __LINE__, fb_type );
  456. return NULL;
  457. }
  458. /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
  459. * the _REV versions.
  460. *
  461. * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
  462. */
  463. switch ( fb_format ) {
  464. case GL_RGB:
  465. masks = masks_table_rgb[ index ];
  466. break;
  467. case GL_RGBA:
  468. masks = masks_table_rgba[ index ];
  469. break;
  470. case GL_BGR:
  471. masks = masks_table_bgr[ index ];
  472. break;
  473. case GL_BGRA:
  474. masks = masks_table_bgra[ index ];
  475. break;
  476. default:
  477. fprintf( stderr, "[%s:%u] Unknown framebuffer format 0x%04x.\n",
  478. __FUNCTION__, __LINE__, fb_format );
  479. return NULL;
  480. }
  481. switch ( bytes_per_pixel[ index ] ) {
  482. case 1:
  483. bits = bits_table[0];
  484. break;
  485. case 2:
  486. bits = bits_table[1];
  487. break;
  488. default:
  489. bits = ((fb_format == GL_RGB) || (fb_format == GL_BGR))
  490. ? bits_table[2]
  491. : bits_table[3];
  492. break;
  493. }
  494. num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits * num_msaa_modes;
  495. configs = calloc(1, (num_modes + 1) * sizeof *configs);
  496. if (configs == NULL)
  497. return NULL;
  498. c = configs;
  499. for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) {
  500. for ( i = 0 ; i < num_db_modes ; i++ ) {
  501. for ( h = 0 ; h < num_msaa_modes; h++ ) {
  502. for ( j = 0 ; j < num_accum_bits ; j++ ) {
  503. *c = malloc (sizeof **c);
  504. modes = &(*c)->modes;
  505. c++;
  506. memset(modes, 0, sizeof *modes);
  507. modes->redBits = bits[0];
  508. modes->greenBits = bits[1];
  509. modes->blueBits = bits[2];
  510. modes->alphaBits = bits[3];
  511. modes->redMask = masks[0];
  512. modes->greenMask = masks[1];
  513. modes->blueMask = masks[2];
  514. modes->alphaMask = masks[3];
  515. modes->rgbBits = modes->redBits + modes->greenBits
  516. + modes->blueBits + modes->alphaBits;
  517. modes->accumRedBits = 16 * j;
  518. modes->accumGreenBits = 16 * j;
  519. modes->accumBlueBits = 16 * j;
  520. modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
  521. modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
  522. modes->stencilBits = stencil_bits[k];
  523. modes->depthBits = depth_bits[k];
  524. modes->transparentPixel = GLX_NONE;
  525. modes->transparentRed = GLX_DONT_CARE;
  526. modes->transparentGreen = GLX_DONT_CARE;
  527. modes->transparentBlue = GLX_DONT_CARE;
  528. modes->transparentAlpha = GLX_DONT_CARE;
  529. modes->transparentIndex = GLX_DONT_CARE;
  530. modes->visualType = GLX_DONT_CARE;
  531. modes->renderType = GLX_RGBA_BIT;
  532. modes->drawableType = GLX_WINDOW_BIT;
  533. modes->rgbMode = GL_TRUE;
  534. if ( db_modes[i] == GLX_NONE ) {
  535. modes->doubleBufferMode = GL_FALSE;
  536. }
  537. else {
  538. modes->doubleBufferMode = GL_TRUE;
  539. modes->swapMethod = db_modes[i];
  540. }
  541. modes->samples = msaa_samples[h];
  542. modes->sampleBuffers = modes->samples ? 1 : 0;
  543. modes->haveAccumBuffer = ((modes->accumRedBits +
  544. modes->accumGreenBits +
  545. modes->accumBlueBits +
  546. modes->accumAlphaBits) > 0);
  547. modes->haveDepthBuffer = (modes->depthBits > 0);
  548. modes->haveStencilBuffer = (modes->stencilBits > 0);
  549. modes->bindToTextureRgb = GL_TRUE;
  550. modes->bindToTextureRgba = GL_TRUE;
  551. modes->bindToMipmapTexture = GL_FALSE;
  552. modes->bindToTextureTargets =
  553. __DRI_ATTRIB_TEXTURE_1D_BIT |
  554. __DRI_ATTRIB_TEXTURE_2D_BIT |
  555. __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT;
  556. }
  557. }
  558. }
  559. }
  560. *c = NULL;
  561. return configs;
  562. }
  563. __DRIconfig **driConcatConfigs(__DRIconfig **a,
  564. __DRIconfig **b)
  565. {
  566. __DRIconfig **all;
  567. int i, j, index;
  568. i = 0;
  569. while (a[i] != NULL)
  570. i++;
  571. j = 0;
  572. while (b[j] != NULL)
  573. j++;
  574. all = malloc((i + j + 1) * sizeof *all);
  575. index = 0;
  576. for (i = 0; a[i] != NULL; i++)
  577. all[index++] = a[i];
  578. for (j = 0; b[j] != NULL; j++)
  579. all[index++] = b[j];
  580. all[index++] = NULL;
  581. free(a);
  582. free(b);
  583. return all;
  584. }
  585. #define __ATTRIB(attrib, field) \
  586. { attrib, offsetof(__GLcontextModes, field) }
  587. static const struct { unsigned int attrib, offset; } attribMap[] = {
  588. __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits),
  589. __ATTRIB(__DRI_ATTRIB_LEVEL, level),
  590. __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits),
  591. __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits),
  592. __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits),
  593. __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits),
  594. __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits),
  595. __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits),
  596. __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits),
  597. __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits),
  598. __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits),
  599. __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits),
  600. __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers),
  601. __ATTRIB(__DRI_ATTRIB_SAMPLES, samples),
  602. __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode),
  603. __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode),
  604. __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers),
  605. __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel),
  606. __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentPixel),
  607. __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed),
  608. __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen),
  609. __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue),
  610. __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha),
  611. __ATTRIB(__DRI_ATTRIB_FLOAT_MODE, floatMode),
  612. __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask),
  613. __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask),
  614. __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask),
  615. __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask),
  616. __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth),
  617. __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight),
  618. __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels),
  619. __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth),
  620. __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight),
  621. __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod),
  622. __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb),
  623. __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba),
  624. __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, bindToMipmapTexture),
  625. __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS, bindToTextureTargets),
  626. __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),
  627. /* The struct field doesn't matter here, these are handled by the
  628. * switch in driGetConfigAttribIndex. We need them in the array
  629. * so the iterator includes them though.*/
  630. __ATTRIB(__DRI_ATTRIB_RENDER_TYPE, level),
  631. __ATTRIB(__DRI_ATTRIB_CONFIG_CAVEAT, level),
  632. __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, level)
  633. };
  634. #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
  635. static int
  636. driGetConfigAttribIndex(const __DRIconfig *config,
  637. unsigned int index, unsigned int *value)
  638. {
  639. switch (attribMap[index].attrib) {
  640. case __DRI_ATTRIB_RENDER_TYPE:
  641. *value = __DRI_ATTRIB_RGBA_BIT;
  642. break;
  643. case __DRI_ATTRIB_CONFIG_CAVEAT:
  644. if (config->modes.visualRating == GLX_NON_CONFORMANT_CONFIG)
  645. *value = __DRI_ATTRIB_NON_CONFORMANT_CONFIG;
  646. else if (config->modes.visualRating == GLX_SLOW_CONFIG)
  647. *value = __DRI_ATTRIB_SLOW_BIT;
  648. else
  649. *value = 0;
  650. break;
  651. case __DRI_ATTRIB_SWAP_METHOD:
  652. break;
  653. case __DRI_ATTRIB_FLOAT_MODE:
  654. *value = config->modes.floatMode;
  655. break;
  656. default:
  657. *value = *(unsigned int *)
  658. ((char *) &config->modes + attribMap[index].offset);
  659. break;
  660. }
  661. return GL_TRUE;
  662. }
  663. int
  664. driGetConfigAttrib(const __DRIconfig *config,
  665. unsigned int attrib, unsigned int *value)
  666. {
  667. int i;
  668. for (i = 0; i < ARRAY_SIZE(attribMap); i++)
  669. if (attribMap[i].attrib == attrib)
  670. return driGetConfigAttribIndex(config, i, value);
  671. return GL_FALSE;
  672. }
  673. int
  674. driIndexConfigAttrib(const __DRIconfig *config, int index,
  675. unsigned int *attrib, unsigned int *value)
  676. {
  677. if (index >= 0 && index < ARRAY_SIZE(attribMap)) {
  678. *attrib = attribMap[index].attrib;
  679. return driGetConfigAttribIndex(config, index, value);
  680. }
  681. return GL_FALSE;
  682. }