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/* 29 * Authors: 30 * Kevin E. Martin <kem@redhat.com> 31 * 32 */ 33 34/** \file 35 * This file provides support for visuals. */ 36 37#ifdef HAVE_DMX_CONFIG_H 38#include <dmx-config.h> 39#endif 40 41#include "dmx.h" 42#include "dmxvisual.h" 43 44#include "scrnintstr.h" 45 46#ifdef GLXEXT 47 48#include <GL/glxint.h> 49 50extern VisualID glxMatchVisualInConfigList(ScreenPtr pScreen, 51 VisualPtr pVisual, 52 __GLXvisualConfig *configs, 53 int nconfigs); 54 55static Visual *dmxLookupGLXVisual(ScreenPtr pScreen, VisualPtr pVisual) 56{ 57 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum]; 58 int j; 59 VisualID vid; 60 61 vid = glxMatchVisualInConfigList(pScreen, pVisual, 62 dmxScreen->glxVisuals, 63 dmxScreen->numGlxVisuals); 64 if (vid) { 65 /* Find the X visual of the matching GLX visual */ 66 for (j = 0; j < dmxScreen->beNumVisuals; j++) 67 if (vid == dmxScreen->beVisuals[j].visualid) 68 return dmxScreen->beVisuals[j].visual; 69 } 70 71 /* No matching visual found */ 72 return NULL; 73} 74#endif 75 76/** Return the visual that matched \a pVisual. */ 77Visual *dmxLookupVisual(ScreenPtr pScreen, VisualPtr pVisual) 78{ 79 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum]; 80 int i; 81#ifdef GLXEXT 82 Visual *retval; 83#endif 84 85 if (!dmxScreen->beDisplay) 86 return NULL; 87 88#ifdef GLXEXT 89 if ((retval = dmxLookupGLXVisual(pScreen, pVisual))) 90 return retval; 91#endif 92 93 for (i = 0; i < dmxScreen->beNumVisuals; i++) { 94 if (pVisual->class == dmxScreen->beVisuals[i].class && 95 pVisual->bitsPerRGBValue == dmxScreen->beVisuals[i].bits_per_rgb && 96 pVisual->ColormapEntries == dmxScreen->beVisuals[i].colormap_size && 97 pVisual->nplanes == dmxScreen->beVisuals[i].depth && 98 pVisual->redMask == dmxScreen->beVisuals[i].red_mask && 99 pVisual->greenMask == dmxScreen->beVisuals[i].green_mask && 100 pVisual->blueMask == dmxScreen->beVisuals[i].blue_mask) { 101 return dmxScreen->beVisuals[i].visual; 102 } 103 } 104 105 return NULL; 106} 107 108/** Return the visual that matched the \a vid. */ 109Visual *dmxLookupVisualFromID(ScreenPtr pScreen, VisualID vid) 110{ 111 Visual *visual; 112 int i; 113 114 if (!dmxScreens[pScreen->myNum].beDisplay) 115 return NULL; 116 117 for (i = 0; i < pScreen->numVisuals; i++) { 118 if (pScreen->visuals[i].vid == vid) { 119 visual = dmxLookupVisual(pScreen, &pScreen->visuals[i]); 120 if (visual) return visual; 121 } 122 } 123 124 return NULL; 125} 126 127/** Return the colormap for the \a visual. */ 128Colormap dmxColormapFromDefaultVisual(ScreenPtr pScreen, Visual *visual) 129{ 130 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum]; 131 int i; 132 133 if (dmxScreen->beDisplay) { 134 for (i = 0; i < dmxScreen->beNumDefColormaps; i++) 135 if (visual == dmxScreen->beVisuals[i].visual) 136 return dmxScreen->beDefColormaps[i]; 137 } 138 139 return None; 140} 141