extension_string.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * (C) Copyright IBM Corporation 2002-2006
  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. * THE COPYRIGHT HOLDERS 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 extension_string.c
  26. * Routines to manage the GLX extension string and GLX version for AIGLX
  27. * drivers. This code is loosely based on src/glx/x11/glxextensions.c from
  28. * Mesa.
  29. *
  30. * \author Ian Romanick <idr@us.ibm.com>
  31. */
  32. #include <string.h>
  33. #include "extension_string.h"
  34. #define SET_BIT(m,b) (m[ (b) / 8 ] |= (1U << ((b) % 8)))
  35. #define CLR_BIT(m,b) (m[ (b) / 8 ] &= ~(1U << ((b) % 8)))
  36. #define IS_SET(m,b) ((m[ (b) / 8 ] & (1U << ((b) % 8))) != 0)
  37. #define CONCAT(a,b) a ## b
  38. #define GLX(n) "GLX_" # n, 4 + sizeof( # n ) - 1, CONCAT(n,_bit)
  39. #define VER(a,b) a, b
  40. #define Y 1
  41. #define N 0
  42. #define EXT_ENABLED(bit,supported) (IS_SET(supported, bit))
  43. struct extension_info {
  44. const char *const name;
  45. unsigned name_len;
  46. unsigned char bit;
  47. /**
  48. * This is the lowest version of GLX that "requires" this extension.
  49. * For example, GLX 1.3 requires SGIX_fbconfig, SGIX_pbuffer, and
  50. * SGI_make_current_read. If the extension is not required by any known
  51. * version of GLX, use 0, 0.
  52. */
  53. unsigned char version_major;
  54. unsigned char version_minor;
  55. /**
  56. * Is driver support forced by the ABI?
  57. */
  58. unsigned char driver_support;
  59. };
  60. /**
  61. * List of known GLX Extensions.
  62. * The last Y/N switch informs whether the support of this extension is always enabled.
  63. */
  64. static const struct extension_info known_glx_extensions[] = {
  65. /* GLX_ARB_get_proc_address is implemented on the client. */
  66. /* *INDENT-OFF* */
  67. { GLX(ARB_create_context), VER(0,0), N, },
  68. { GLX(ARB_create_context_profile), VER(0,0), N, },
  69. { GLX(ARB_create_context_robustness), VER(0,0), N, },
  70. { GLX(ARB_fbconfig_float), VER(0,0), N, },
  71. { GLX(ARB_framebuffer_sRGB), VER(0,0), N, },
  72. { GLX(ARB_multisample), VER(1,4), Y, },
  73. { GLX(EXT_create_context_es2_profile), VER(0,0), N, },
  74. { GLX(EXT_framebuffer_sRGB), VER(0,0), N, },
  75. { GLX(EXT_import_context), VER(0,0), Y, },
  76. { GLX(EXT_texture_from_pixmap), VER(0,0), Y, },
  77. { GLX(EXT_visual_info), VER(0,0), Y, },
  78. { GLX(EXT_visual_rating), VER(0,0), Y, },
  79. { GLX(MESA_copy_sub_buffer), VER(0,0), N, },
  80. { GLX(OML_swap_method), VER(0,0), Y, },
  81. { GLX(SGI_make_current_read), VER(1,3), N, },
  82. { GLX(SGI_swap_control), VER(0,0), N, },
  83. { GLX(SGIS_multisample), VER(0,0), Y, },
  84. { GLX(SGIX_fbconfig), VER(1,3), Y, },
  85. { GLX(SGIX_pbuffer), VER(1,3), Y, },
  86. { GLX(SGIX_visual_select_group), VER(0,0), Y, },
  87. { GLX(INTEL_swap_event), VER(0,0), N, },
  88. { NULL }
  89. /* *INDENT-ON* */
  90. };
  91. /**
  92. * Create a GLX extension string for a set of enable bits.
  93. *
  94. * Creates a GLX extension string for the set of bit in \c enable_bits. This
  95. * string is then stored in \c buffer if buffer is not \c NULL. This allows
  96. * two-pass operation. On the first pass the caller passes \c NULL for
  97. * \c buffer, and the function determines how much space is required to store
  98. * the extension string. The caller allocates the buffer and calls the
  99. * function again.
  100. *
  101. * \param enable_bits Bits representing the enabled extensions.
  102. * \param buffer Buffer to store the extension string. May be \c NULL.
  103. *
  104. * \return
  105. * The number of characters in \c buffer that were written to. If \c buffer
  106. * is \c NULL, this is the size of buffer that must be allocated by the
  107. * caller.
  108. */
  109. int
  110. __glXGetExtensionString(const unsigned char *enable_bits, char *buffer)
  111. {
  112. unsigned i;
  113. int length = 0;
  114. for (i = 0; known_glx_extensions[i].name != NULL; i++) {
  115. const unsigned bit = known_glx_extensions[i].bit;
  116. const size_t len = known_glx_extensions[i].name_len;
  117. if (EXT_ENABLED(bit, enable_bits)) {
  118. if (buffer != NULL) {
  119. (void) memcpy(&buffer[length], known_glx_extensions[i].name,
  120. len);
  121. buffer[length + len + 0] = ' ';
  122. buffer[length + len + 1] = '\0';
  123. }
  124. length += len + 1;
  125. }
  126. }
  127. return length + 1;
  128. }
  129. void
  130. __glXEnableExtension(unsigned char *enable_bits, const char *ext)
  131. {
  132. const size_t ext_name_len = strlen(ext);
  133. unsigned i;
  134. for (i = 0; known_glx_extensions[i].name != NULL; i++) {
  135. if ((ext_name_len == known_glx_extensions[i].name_len)
  136. && (memcmp(ext, known_glx_extensions[i].name, ext_name_len) == 0)) {
  137. SET_BIT(enable_bits, known_glx_extensions[i].bit);
  138. break;
  139. }
  140. }
  141. }
  142. void
  143. __glXInitExtensionEnableBits(unsigned char *enable_bits)
  144. {
  145. unsigned i;
  146. (void) memset(enable_bits, 0, __GLX_EXT_BYTES);
  147. for (i = 0; known_glx_extensions[i].name != NULL; i++) {
  148. if (known_glx_extensions[i].driver_support) {
  149. SET_BIT(enable_bits, known_glx_extensions[i].bit);
  150. }
  151. }
  152. }