1/*
2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. 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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
29 */
30
31#ifdef HAVE_DMX_CONFIG_H
32#include <dmx-config.h>
33#endif
34
35#include "glxserver.h"
36#include "glxvisuals.h"
37
38int glxVisualsMatch( __GLXvisualConfig *v1, __GLXvisualConfig *v2 )
39{
40      if ( (v1->class == v2->class) &&
41           (v1->rgba == v2->rgba) &&
42	   (v1->redSize == v2->redSize) &&
43	   (v1->greenSize == v2->greenSize) &&
44	   (v1->blueSize == v2->blueSize) &&
45	   (v1->alphaSize == v2->alphaSize) &&
46	   (v1->redMask == v2->redMask) &&
47	   (v1->greenMask == v2->greenMask) &&
48	   (v1->blueMask == v2->blueMask) &&
49	   (v1->alphaMask == v2->alphaMask) &&
50	   (v1->accumRedSize == v2->accumRedSize) &&
51	   (v1->accumGreenSize == v2->accumGreenSize) &&
52	   (v1->accumBlueSize == v2->accumBlueSize) &&
53	   (v1->accumAlphaSize == v2->accumAlphaSize) &&
54	   (v1->doubleBuffer == v2->doubleBuffer) &&
55	   (v1->stereo == v2->stereo) &&
56	   (v1->bufferSize == v2->bufferSize) &&
57	   (v1->depthSize == v2->depthSize) &&
58	   (v1->stencilSize == v2->stencilSize) &&
59	   (v1->auxBuffers == v2->auxBuffers) &&
60	   (v1->level == v2->level) &&
61	   (v1->visualRating == v2->visualRating) &&
62	   (v1->transparentPixel == v2->transparentPixel) &&
63	   (v1->transparentRed == v2->transparentRed) &&
64	   (v1->transparentGreen == v2->transparentGreen) &&
65	   (v1->transparentBlue == v2->transparentBlue) &&
66	   (v1->transparentAlpha == v2->transparentAlpha) &&
67	   (v1->transparentIndex == v2->transparentIndex) &&
68	   (v1->multiSampleSize == v2->multiSampleSize) &&
69	   (v1->nMultiSampleBuffers == v2->nMultiSampleBuffers) &&
70	   (v1->visualSelectGroup == v2->visualSelectGroup)         ) {
71
72	      return 1;
73
74      }
75
76      return 0;
77
78}
79
80VisualID glxMatchGLXVisualInConfigList( __GLXvisualConfig *pGlxVisual, __GLXvisualConfig *configs, int nconfigs )
81{
82    int i;
83
84    for (i=0; i<nconfigs; i++) {
85
86       if (glxVisualsMatch( pGlxVisual, &configs[i] )) {
87
88	  return configs[i].vid;
89
90       }
91    }
92
93    return 0;
94}
95
96VisualID glxMatchVisualInConfigList( ScreenPtr pScreen, VisualPtr pVisual, __GLXvisualConfig *configs, int nconfigs )
97{
98    __GLXscreenInfo *pGlxScreen;
99    __GLXvisualConfig *pGlxVisual;
100    int i;
101
102    /* check that the glx extension has been initialized */
103    if ( !__glXActiveScreens )
104       return 0;
105
106    pGlxScreen = &__glXActiveScreens[pScreen->myNum];
107    pGlxVisual = pGlxScreen->pGlxVisual;
108
109    /* find the glx visual info for pVisual */
110    for (i = 0; i < pGlxScreen->numVisuals; i++, pGlxVisual++) {
111	if (pGlxVisual->vid == pVisual->vid) {
112	    break;
113	}
114    }
115    if (i == pGlxScreen->numVisuals) {
116	/*
117	 * the visual is not supported by glx
118	 */
119        return 0;
120    }
121
122    return( glxMatchGLXVisualInConfigList(pGlxVisual, configs, nconfigs) );
123}
124
125VisualPtr glxMatchVisual( ScreenPtr pScreen, VisualPtr pVisual, ScreenPtr pMatchScreen )
126{
127    __GLXscreenInfo *pGlxScreen2;
128    int j;
129    VisualID vid;
130
131    /* check that the glx extension has been initialized */
132    if ( !__glXActiveScreens )
133       return NULL;
134
135    pGlxScreen2 = &__glXActiveScreens[pMatchScreen->myNum];
136
137    vid = glxMatchVisualInConfigList( pScreen, pVisual,
138                                      pGlxScreen2->pGlxVisual,
139				      pGlxScreen2->numVisuals );
140    if (vid) {
141       /*
142    	* find the X visual of the matching glx visual
143	*/
144       for (j=0; j<pMatchScreen->numVisuals; j++) {
145	  if (vid == pMatchScreen->visuals[j].vid) {
146	     return &pMatchScreen->visuals[j];
147	  }
148       }
149    }
150
151    return 0;
152}
153