dmxvisual.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright 2002-2004 Red Hat Inc., Durham, North Carolina.
  3. *
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation on the rights to use, copy, modify, merge,
  10. * publish, distribute, sublicense, and/or sell copies of the Software,
  11. * and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial
  16. * portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
  22. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  23. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. */
  27. /*
  28. * Authors:
  29. * Kevin E. Martin <kem@redhat.com>
  30. *
  31. */
  32. /** \file
  33. * This file provides support for visuals. */
  34. #ifdef HAVE_DMX_CONFIG_H
  35. #include <dmx-config.h>
  36. #endif
  37. #include "dmx.h"
  38. #include "dmxvisual.h"
  39. #include "scrnintstr.h"
  40. #ifdef GLXEXT
  41. #include <GL/glxint.h>
  42. extern VisualID glxMatchVisualInConfigList(ScreenPtr pScreen,
  43. VisualPtr pVisual,
  44. __GLXvisualConfig * configs,
  45. int nconfigs);
  46. static Visual *
  47. dmxLookupGLXVisual(ScreenPtr pScreen, VisualPtr pVisual)
  48. {
  49. DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
  50. int j;
  51. VisualID vid;
  52. vid = glxMatchVisualInConfigList(pScreen, pVisual,
  53. dmxScreen->glxVisuals,
  54. dmxScreen->numGlxVisuals);
  55. if (vid) {
  56. /* Find the X visual of the matching GLX visual */
  57. for (j = 0; j < dmxScreen->beNumVisuals; j++)
  58. if (vid == dmxScreen->beVisuals[j].visualid)
  59. return dmxScreen->beVisuals[j].visual;
  60. }
  61. /* No matching visual found */
  62. return NULL;
  63. }
  64. #endif
  65. /** Return the visual that matched \a pVisual. */
  66. Visual *
  67. dmxLookupVisual(ScreenPtr pScreen, VisualPtr pVisual)
  68. {
  69. DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
  70. int i;
  71. #ifdef GLXEXT
  72. Visual *retval;
  73. #endif
  74. if (!dmxScreen->beDisplay)
  75. return NULL;
  76. #ifdef GLXEXT
  77. if ((retval = dmxLookupGLXVisual(pScreen, pVisual)))
  78. return retval;
  79. #endif
  80. for (i = 0; i < dmxScreen->beNumVisuals; i++) {
  81. if (pVisual->class == dmxScreen->beVisuals[i].class &&
  82. pVisual->bitsPerRGBValue == dmxScreen->beVisuals[i].bits_per_rgb &&
  83. pVisual->ColormapEntries == dmxScreen->beVisuals[i].colormap_size &&
  84. pVisual->nplanes == dmxScreen->beVisuals[i].depth &&
  85. pVisual->redMask == dmxScreen->beVisuals[i].red_mask &&
  86. pVisual->greenMask == dmxScreen->beVisuals[i].green_mask &&
  87. pVisual->blueMask == dmxScreen->beVisuals[i].blue_mask) {
  88. return dmxScreen->beVisuals[i].visual;
  89. }
  90. }
  91. return NULL;
  92. }
  93. /** Return the visual that matched the \a vid. */
  94. Visual *
  95. dmxLookupVisualFromID(ScreenPtr pScreen, VisualID vid)
  96. {
  97. Visual *visual;
  98. int i;
  99. if (!dmxScreens[pScreen->myNum].beDisplay)
  100. return NULL;
  101. for (i = 0; i < pScreen->numVisuals; i++) {
  102. if (pScreen->visuals[i].vid == vid) {
  103. visual = dmxLookupVisual(pScreen, &pScreen->visuals[i]);
  104. if (visual)
  105. return visual;
  106. }
  107. }
  108. return NULL;
  109. }
  110. /** Return the colormap for the \a visual. */
  111. Colormap
  112. dmxColormapFromDefaultVisual(ScreenPtr pScreen, Visual * visual)
  113. {
  114. DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
  115. int i;
  116. if (dmxScreen->beDisplay) {
  117. for (i = 0; i < dmxScreen->beNumDefColormaps; i++)
  118. if (visual == dmxScreen->beVisuals[i].visual)
  119. return dmxScreen->beDefColormaps[i];
  120. }
  121. return None;
  122. }