2
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
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:
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.
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
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.
31
#ifdef HAVE_DMX_CONFIG_H
32
#include <dmx-config.h>
37
#include "glxserver.h"
39
#include "dmx_glxvisuals.h"
42
static int numConfigs = 0;
43
static __GLXvisualConfig *visualConfigs = NULL;
44
static void **visualPrivates = NULL;
46
int glxVisualsMatch( __GLXvisualConfig *v1, __GLXvisualConfig *v2 )
48
if ( (v1->class == v2->class) &&
49
(v1->rgba == v2->rgba) &&
50
(v1->redSize == v2->redSize) &&
51
(v1->greenSize == v2->greenSize) &&
52
(v1->blueSize == v2->blueSize) &&
53
(v1->alphaSize == v2->alphaSize) &&
54
(v1->redMask == v2->redMask) &&
55
(v1->greenMask == v2->greenMask) &&
56
(v1->blueMask == v2->blueMask) &&
57
(v1->alphaMask == v2->alphaMask) &&
58
(v1->accumRedSize == v2->accumRedSize) &&
59
(v1->accumGreenSize == v2->accumGreenSize) &&
60
(v1->accumBlueSize == v2->accumBlueSize) &&
61
(v1->accumAlphaSize == v2->accumAlphaSize) &&
62
(v1->doubleBuffer == v2->doubleBuffer) &&
63
(v1->stereo == v2->stereo) &&
64
(v1->bufferSize == v2->bufferSize) &&
65
(v1->depthSize == v2->depthSize) &&
66
(v1->stencilSize == v2->stencilSize) &&
67
(v1->auxBuffers == v2->auxBuffers) &&
68
(v1->level == v2->level) &&
69
(v1->visualRating == v2->visualRating) &&
70
(v1->transparentPixel == v2->transparentPixel) &&
71
(v1->transparentRed == v2->transparentRed) &&
72
(v1->transparentGreen == v2->transparentGreen) &&
73
(v1->transparentBlue == v2->transparentBlue) &&
74
(v1->transparentAlpha == v2->transparentAlpha) &&
75
(v1->transparentIndex == v2->transparentIndex) &&
76
(v1->multiSampleSize == v2->multiSampleSize) &&
77
(v1->nMultiSampleBuffers == v2->nMultiSampleBuffers) &&
78
(v1->visualSelectGroup == v2->visualSelectGroup) ) {
88
VisualID glxMatchGLXVisualInConfigList( __GLXvisualConfig *pGlxVisual, __GLXvisualConfig *configs, int nconfigs )
92
for (i=0; i<nconfigs; i++) {
94
if (glxVisualsMatch( pGlxVisual, &configs[i] )) {
96
return( configs[i].vid );
104
VisualID glxMatchVisualInConfigList( ScreenPtr pScreen, VisualPtr pVisual, __GLXvisualConfig *configs, int nconfigs )
106
__GLXscreenInfo *pGlxScreen;
107
__GLXvisualConfig *pGlxVisual;
110
/* check that the glx extension has been initialized */
111
if ( !__glXActiveScreens )
114
pGlxScreen = &__glXActiveScreens[pScreen->myNum];
115
pGlxVisual = pGlxScreen->pGlxVisual;
117
/* find the glx visual info for pVisual */
118
for (i = 0; i < pGlxScreen->numVisuals; i++, pGlxVisual++) {
119
if (pGlxVisual->vid == pVisual->vid) {
123
if (i == pGlxScreen->numVisuals) {
125
* the visual is not supported by glx
130
return( glxMatchGLXVisualInConfigList(pGlxVisual, configs, nconfigs) );
133
VisualPtr glxMatchVisual( ScreenPtr pScreen, VisualPtr pVisual, ScreenPtr pMatchScreen )
135
__GLXscreenInfo *pGlxScreen2;
139
/* check that the glx extension has been initialized */
140
if ( !__glXActiveScreens )
143
pGlxScreen2 = &__glXActiveScreens[pMatchScreen->myNum];
145
vid = glxMatchVisualInConfigList( pScreen, pVisual,
146
pGlxScreen2->pGlxVisual,
147
pGlxScreen2->numVisuals );
150
* find the X visual of the matching glx visual
152
for (j=0; j<pMatchScreen->numVisuals; j++) {
153
if (vid == pMatchScreen->visuals[j].vid) {
154
return( &pMatchScreen->visuals[j] );
162
void glxSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs,
165
numConfigs = nconfigs;
166
visualConfigs = configs;
167
visualPrivates = privates;
170
static int count_bits(unsigned int n)
181
static VisualID FindClosestVisual( VisualPtr pVisual, int rootDepth,
182
DepthPtr pdepth, int ndepths,
183
VisualPtr pNewVisual, int numNewVisuals)
189
* find the first visual with the same or deeper depth
192
for (d=0; d<ndepths; d++) {
193
if (pdepth[d].depth >= rootDepth) {
194
for (v=0; v<pdepth[d].numVids; v++) {
196
/* find the new visual structure */
198
while( pdepth[d].vids[v] != vis->vid ) vis++;
200
if (vis->class == pVisual->class) {
201
return( pdepth[d].vids[v] );
209
* try to look for the same class only.
211
for (d=0; d<ndepths; d++) {
212
for (v=0; v<pdepth[d].numVids; v++) {
214
/* find the new visual structure */
216
while( pdepth[d].vids[v] != vis->vid ) vis++;
218
if (vis->class == pVisual->class) {
219
return( pdepth[d].vids[v] );
225
* if not found - just take the first visual
227
return( pdepth[0].vids[0] );
230
Bool glxInitVisuals(int *nvisualp, VisualPtr *visualp,
231
VisualID *defaultVisp,
232
int ndepth, DepthPtr pdepth,
237
int numVisuals = *nvisualp;
240
VisualPtr pVisual = *visualp;
241
VisualPtr pVisualNew = NULL;
242
VisualID *orig_vid = NULL;
243
__GLXvisualConfig *glXVisualPtr = NULL;
244
__GLXvisualConfig *pNewVisualConfigs = NULL;
245
void **glXVisualPriv;
246
dmxGlxVisualPrivate **pNewVisualPriv;
253
numNewConfigs = numConfigs;
257
MAXSCREENSALLOC(__glXActiveScreens);
258
if (!__glXActiveScreens)
261
/* Alloc space for the list of new GLX visuals */
262
pNewVisualConfigs = (__GLXvisualConfig *)
263
__glXMalloc(numNewConfigs * sizeof(__GLXvisualConfig));
264
if (!pNewVisualConfigs) {
268
/* Alloc space for the list of new GLX visual privates */
269
pNewVisualPriv = (dmxGlxVisualPrivate **) __glXMalloc(numNewConfigs * sizeof(dmxGlxVisualPrivate *));
270
if (!pNewVisualPriv) {
271
__glXFree(pNewVisualConfigs);
275
/* copy driver's visual config info */
276
for (i = 0; i < numConfigs; i++) {
277
pNewVisualConfigs[i] = visualConfigs[i];
278
pNewVisualPriv[i] = (dmxGlxVisualPrivate *)visualPrivates[i];
282
/* FIXME: This is a hack to workaround a hang in xtest caused by a
283
* mismatch between what the front end (i.e., DMX) server calculates
284
* for the visual configs and what the back-end servers have.
287
int numTCRGBconfigs = 0;
288
int numDCRGBconfigs = 0;
293
for (i = 0; i < numNewConfigs; i++) {
294
if (pNewVisualConfigs[i].rgba) {
295
if (pNewVisualConfigs[i].class == TrueColor)
304
/* Count the total number of visuals to compute */
306
for (i = 0; i < numVisuals; i++) {
308
(pVisual[i].class == TrueColor) ? numTCRGBconfigs :
309
(pVisual[i].class == DirectColor) ? numDCRGBconfigs :
314
/* Count the number of RGB and CI visual configs */
317
for (i = 0; i < numNewConfigs; i++) {
318
if (pNewVisualConfigs[i].rgba)
324
/* Count the total number of visuals to compute */
326
for (i = 0; i < numVisuals; i++) {
328
(pVisual[i].class == TrueColor || pVisual[i].class == DirectColor)
329
? numRGBconfigs : numCIconfigs;
333
/* Reset variables for use with the next screen/driver's visual configs */
334
visualConfigs = NULL;
337
/* Alloc temp space for the list of orig VisualIDs for each new visual */
338
orig_vid = (VisualID *)__glXMalloc(numNewVisuals * sizeof(VisualID));
340
__glXFree(pNewVisualPriv);
341
__glXFree(pNewVisualConfigs);
345
/* Alloc space for the list of glXVisuals */
346
glXVisualPtr = (__GLXvisualConfig *)__glXMalloc(numNewVisuals *
347
sizeof(__GLXvisualConfig));
350
__glXFree(pNewVisualPriv);
351
__glXFree(pNewVisualConfigs);
355
/* Alloc space for the list of glXVisualPrivates */
356
glXVisualPriv = (void **)__glXMalloc(numNewVisuals * sizeof(void *));
357
if (!glXVisualPriv) {
358
__glXFree(glXVisualPtr);
360
__glXFree(pNewVisualPriv);
361
__glXFree(pNewVisualConfigs);
365
/* Alloc space for the new list of the X server's visuals */
366
pVisualNew = (VisualPtr)__glXMalloc(numNewVisuals * sizeof(VisualRec));
368
__glXFree(glXVisualPriv);
369
__glXFree(glXVisualPtr);
371
__glXFree(pNewVisualPriv);
372
__glXFree(pNewVisualConfigs);
376
isGLXvis = (GLint *) __glXMalloc(numNewVisuals * sizeof(GLint));
378
__glXFree(glXVisualPriv);
379
__glXFree(glXVisualPtr);
381
__glXFree(pNewVisualPriv);
382
__glXFree(pNewVisualConfigs);
383
__glXFree(pVisualNew);
387
/* Initialize the new visuals */
388
found_default = FALSE;
389
for (i = j = 0; i < numVisuals; i++) {
391
for (k = 0; k < numNewConfigs; k++) {
397
/* find the depth of the new visual config */
398
new_depth = pNewVisualPriv[k]->x_visual_depth;
400
/* find the depth of the original visual */
403
while( (depth==0) && (d < ndepth) ) {
405
while( (depth==0) && (v < pdepth[d].numVids) ) {
406
if (pdepth[d].vids[v] == pVisual[i].vid) {
407
depth = pdepth[d].depth;
414
/* check that the visual has the same class and depth
417
if ( pVisual[i].class != pNewVisualPriv[k]->x_visual_class ||
418
(depth != new_depth) )
421
/* Initialize the new visual */
422
pVisualNew[j] = pVisual[i];
423
pVisualNew[j].vid = FakeClientID(0);
425
/* Check for the default visual */
426
if (!found_default && pVisual[i].vid == *defaultVisp) {
427
*defaultVisp = pVisualNew[j].vid;
428
found_default = TRUE;
431
/* Save the old VisualID */
432
orig_vid[j] = pVisual[i].vid;
434
/* Initialize the glXVisual */
435
glXVisualPtr[j] = pNewVisualConfigs[k];
436
glXVisualPtr[j].vid = pVisualNew[j].vid;
439
* If the class is -1, then assume the X visual information
440
* is identical to what GLX needs, and take them from the X
441
* visual. NOTE: if class != -1, then all other fields MUST
444
if (glXVisualPtr[j].class == -1) {
445
glXVisualPtr[j].class = pVisual[i].class;
446
glXVisualPtr[j].redSize = count_bits(pVisual[i].redMask);
447
glXVisualPtr[j].greenSize = count_bits(pVisual[i].greenMask);
448
glXVisualPtr[j].blueSize = count_bits(pVisual[i].blueMask);
449
glXVisualPtr[j].alphaSize = glXVisualPtr[j].alphaSize;
450
glXVisualPtr[j].redMask = pVisual[i].redMask;
451
glXVisualPtr[j].greenMask = pVisual[i].greenMask;
452
glXVisualPtr[j].blueMask = pVisual[i].blueMask;
453
glXVisualPtr[j].alphaMask = glXVisualPtr[j].alphaMask;
454
glXVisualPtr[j].bufferSize = rootDepth;
457
/* Save the device-dependent private for this visual */
458
glXVisualPriv[j] = pNewVisualPriv[k];
460
isGLXvis[j] = glxMatchGLXVisualInConfigList( &glXVisualPtr[j],
461
dmxScreens[screenInfo.numScreens-1].glxVisuals,
462
dmxScreens[screenInfo.numScreens-1].numGlxVisuals );
463
if (isGLXvis[j]) numGLXvis++;
469
assert(j <= numNewVisuals);
470
numNewVisuals = j; /* correct number of new visuals */
472
/* Save the GLX visuals in the screen structure */
473
__glXActiveScreens[screenInfo.numScreens-1].numVisuals = numNewVisuals;
474
__glXActiveScreens[screenInfo.numScreens-1].numGLXVisuals = numGLXvis;
475
__glXActiveScreens[screenInfo.numScreens-1].isGLXvis = isGLXvis;
476
__glXActiveScreens[screenInfo.numScreens-1].pGlxVisual = glXVisualPtr;
479
/* Set up depth's VisualIDs */
480
for (i = 0; i < ndepth; i++) {
482
VisualID *pVids = NULL;
485
/* Count the new number of VisualIDs at this depth */
486
for (j = 0; j < pdepth[i].numVids; j++)
487
for (k = 0; k < numNewVisuals; k++)
488
if (pdepth[i].vids[j] == orig_vid[k])
491
/* Allocate a new list of VisualIDs for this depth */
492
pVids = (VisualID *)__glXMalloc(numVids * sizeof(VisualID));
494
/* Initialize the new list of VisualIDs for this depth */
495
for (j = 0; j < pdepth[i].numVids; j++)
496
for (k = 0; k < numNewVisuals; k++)
497
if (pdepth[i].vids[j] == orig_vid[k])
498
pVids[n++] = pVisualNew[k].vid;
500
/* Update this depth's list of VisualIDs */
501
__glXFree(pdepth[i].vids);
502
pdepth[i].vids = pVids;
503
pdepth[i].numVids = numVids;
507
* if the default visual was rejected - need to choose new
510
if ( !found_default ) {
512
for (i=0; i<numVisuals; i++)
513
if (pVisual[i].vid == *defaultVisp)
516
if (i < numVisuals) {
517
*defaultVisp = FindClosestVisual( &pVisual[i], rootDepth, pdepth, ndepth, pVisualNew, numNewVisuals );
521
/* Update the X server's visuals */
522
*nvisualp = numNewVisuals;
523
*visualp = pVisualNew;
525
/* Free the old list of the X server's visuals */
528
/* Clean up temporary allocations */
530
__glXFree(pNewVisualPriv);
531
__glXFree(pNewVisualConfigs);
533
/* Free the private list created by DDX HW driver */
535
xfree(visualPrivates);
536
visualPrivates = NULL;