1706f2543Smrg/* 2706f2543Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3706f2543Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4706f2543Smrg * 5706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6706f2543Smrg * copy of this software and associated documentation files (the "Software"), 7706f2543Smrg * to deal in the Software without restriction, including without limitation 8706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the 10706f2543Smrg * Software is furnished to do so, subject to the following conditions: 11706f2543Smrg * 12706f2543Smrg * The above copyright notice including the dates of first publication and 13706f2543Smrg * either this permission notice or a reference to 14706f2543Smrg * http://oss.sgi.com/projects/FreeB/ 15706f2543Smrg * shall be included in all copies or substantial portions of the Software. 16706f2543Smrg * 17706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18706f2543Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20706f2543Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21706f2543Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22706f2543Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23706f2543Smrg * SOFTWARE. 24706f2543Smrg * 25706f2543Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc. 26706f2543Smrg * shall not be used in advertising or otherwise to promote the sale, use or 27706f2543Smrg * other dealings in this Software without prior written authorization from 28706f2543Smrg * Silicon Graphics, Inc. 29706f2543Smrg */ 30706f2543Smrg 31706f2543Smrg#ifdef HAVE_DMX_CONFIG_H 32706f2543Smrg#include <dmx-config.h> 33706f2543Smrg#endif 34706f2543Smrg 35706f2543Smrg#include "glxserver.h" 36706f2543Smrg#include "glxvisuals.h" 37706f2543Smrg 38706f2543Smrgint glxVisualsMatch( __GLXvisualConfig *v1, __GLXvisualConfig *v2 ) 39706f2543Smrg{ 40706f2543Smrg if ( (v1->class == v2->class) && 41706f2543Smrg (v1->rgba == v2->rgba) && 42706f2543Smrg (v1->redSize == v2->redSize) && 43706f2543Smrg (v1->greenSize == v2->greenSize) && 44706f2543Smrg (v1->blueSize == v2->blueSize) && 45706f2543Smrg (v1->alphaSize == v2->alphaSize) && 46706f2543Smrg (v1->redMask == v2->redMask) && 47706f2543Smrg (v1->greenMask == v2->greenMask) && 48706f2543Smrg (v1->blueMask == v2->blueMask) && 49706f2543Smrg (v1->alphaMask == v2->alphaMask) && 50706f2543Smrg (v1->accumRedSize == v2->accumRedSize) && 51706f2543Smrg (v1->accumGreenSize == v2->accumGreenSize) && 52706f2543Smrg (v1->accumBlueSize == v2->accumBlueSize) && 53706f2543Smrg (v1->accumAlphaSize == v2->accumAlphaSize) && 54706f2543Smrg (v1->doubleBuffer == v2->doubleBuffer) && 55706f2543Smrg (v1->stereo == v2->stereo) && 56706f2543Smrg (v1->bufferSize == v2->bufferSize) && 57706f2543Smrg (v1->depthSize == v2->depthSize) && 58706f2543Smrg (v1->stencilSize == v2->stencilSize) && 59706f2543Smrg (v1->auxBuffers == v2->auxBuffers) && 60706f2543Smrg (v1->level == v2->level) && 61706f2543Smrg (v1->visualRating == v2->visualRating) && 62706f2543Smrg (v1->transparentPixel == v2->transparentPixel) && 63706f2543Smrg (v1->transparentRed == v2->transparentRed) && 64706f2543Smrg (v1->transparentGreen == v2->transparentGreen) && 65706f2543Smrg (v1->transparentBlue == v2->transparentBlue) && 66706f2543Smrg (v1->transparentAlpha == v2->transparentAlpha) && 67706f2543Smrg (v1->transparentIndex == v2->transparentIndex) && 68706f2543Smrg (v1->multiSampleSize == v2->multiSampleSize) && 69706f2543Smrg (v1->nMultiSampleBuffers == v2->nMultiSampleBuffers) && 70706f2543Smrg (v1->visualSelectGroup == v2->visualSelectGroup) ) { 71706f2543Smrg 72706f2543Smrg return 1; 73706f2543Smrg 74706f2543Smrg } 75706f2543Smrg 76706f2543Smrg return 0; 77706f2543Smrg 78706f2543Smrg} 79706f2543Smrg 80706f2543SmrgVisualID glxMatchGLXVisualInConfigList( __GLXvisualConfig *pGlxVisual, __GLXvisualConfig *configs, int nconfigs ) 81706f2543Smrg{ 82706f2543Smrg int i; 83706f2543Smrg 84706f2543Smrg for (i=0; i<nconfigs; i++) { 85706f2543Smrg 86706f2543Smrg if (glxVisualsMatch( pGlxVisual, &configs[i] )) { 87706f2543Smrg 88706f2543Smrg return configs[i].vid; 89706f2543Smrg 90706f2543Smrg } 91706f2543Smrg } 92706f2543Smrg 93706f2543Smrg return 0; 94706f2543Smrg} 95706f2543Smrg 96706f2543SmrgVisualID glxMatchVisualInConfigList( ScreenPtr pScreen, VisualPtr pVisual, __GLXvisualConfig *configs, int nconfigs ) 97706f2543Smrg{ 98706f2543Smrg __GLXscreenInfo *pGlxScreen; 99706f2543Smrg __GLXvisualConfig *pGlxVisual; 100706f2543Smrg int i; 101706f2543Smrg 102706f2543Smrg /* check that the glx extension has been initialized */ 103706f2543Smrg if ( !__glXActiveScreens ) 104706f2543Smrg return 0; 105706f2543Smrg 106706f2543Smrg pGlxScreen = &__glXActiveScreens[pScreen->myNum]; 107706f2543Smrg pGlxVisual = pGlxScreen->pGlxVisual; 108706f2543Smrg 109706f2543Smrg /* find the glx visual info for pVisual */ 110706f2543Smrg for (i = 0; i < pGlxScreen->numVisuals; i++, pGlxVisual++) { 111706f2543Smrg if (pGlxVisual->vid == pVisual->vid) { 112706f2543Smrg break; 113706f2543Smrg } 114706f2543Smrg } 115706f2543Smrg if (i == pGlxScreen->numVisuals) { 116706f2543Smrg /* 117706f2543Smrg * the visual is not supported by glx 118706f2543Smrg */ 119706f2543Smrg return 0; 120706f2543Smrg } 121706f2543Smrg 122706f2543Smrg return( glxMatchGLXVisualInConfigList(pGlxVisual, configs, nconfigs) ); 123706f2543Smrg} 124706f2543Smrg 125706f2543SmrgVisualPtr glxMatchVisual( ScreenPtr pScreen, VisualPtr pVisual, ScreenPtr pMatchScreen ) 126706f2543Smrg{ 127706f2543Smrg __GLXscreenInfo *pGlxScreen2; 128706f2543Smrg int j; 129706f2543Smrg VisualID vid; 130706f2543Smrg 131706f2543Smrg /* check that the glx extension has been initialized */ 132706f2543Smrg if ( !__glXActiveScreens ) 133706f2543Smrg return NULL; 134706f2543Smrg 135706f2543Smrg pGlxScreen2 = &__glXActiveScreens[pMatchScreen->myNum]; 136706f2543Smrg 137706f2543Smrg vid = glxMatchVisualInConfigList( pScreen, pVisual, 138706f2543Smrg pGlxScreen2->pGlxVisual, 139706f2543Smrg pGlxScreen2->numVisuals ); 140706f2543Smrg if (vid) { 141706f2543Smrg /* 142706f2543Smrg * find the X visual of the matching glx visual 143706f2543Smrg */ 144706f2543Smrg for (j=0; j<pMatchScreen->numVisuals; j++) { 145706f2543Smrg if (vid == pMatchScreen->visuals[j].vid) { 146706f2543Smrg return &pMatchScreen->visuals[j]; 147706f2543Smrg } 148706f2543Smrg } 149706f2543Smrg } 150706f2543Smrg 151706f2543Smrg return 0; 152706f2543Smrg} 153