~gma500/emgd/trunk

« back to all changes in this revision

Viewing changes to xorg/xorg-server-1.7.6/hw/dmx/glxProxy/glxvisuals.c

  • Committer: José Bernardo Bandos
  • Date: 2010-08-28 16:04:10 UTC
  • Revision ID: jbs@jbs-laptop-20100828160410-nw5zohdn37oupdv2
First step to add emgd drivers from meego

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <assert.h>
36
 
#include "dmx.h"
37
 
#include "glxserver.h"
38
 
#include "glxutil.h"
39
 
#include "dmx_glxvisuals.h"
40
 
#include <stdlib.h>
41
 
 
42
 
static int                 numConfigs     = 0;
43
 
static __GLXvisualConfig  *visualConfigs  = NULL;
44
 
static void              **visualPrivates = NULL;
45
 
 
46
 
int glxVisualsMatch( __GLXvisualConfig *v1, __GLXvisualConfig *v2 )
47
 
{
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)         ) {
79
 
 
80
 
              return(1);
81
 
 
82
 
      }
83
 
 
84
 
      return(0);
85
 
 
86
 
}
87
 
 
88
 
VisualID glxMatchGLXVisualInConfigList( __GLXvisualConfig *pGlxVisual, __GLXvisualConfig *configs, int nconfigs )
89
 
{
90
 
    int i;
91
 
 
92
 
    for (i=0; i<nconfigs; i++) {
93
 
 
94
 
       if (glxVisualsMatch( pGlxVisual, &configs[i] )) {
95
 
 
96
 
          return( configs[i].vid );
97
 
 
98
 
       }
99
 
    }
100
 
 
101
 
    return(0);
102
 
}
103
 
 
104
 
VisualID glxMatchVisualInConfigList( ScreenPtr pScreen, VisualPtr pVisual, __GLXvisualConfig *configs, int nconfigs )
105
 
{
106
 
    __GLXscreenInfo *pGlxScreen;
107
 
    __GLXvisualConfig *pGlxVisual;
108
 
    int i;
109
 
 
110
 
    /* check that the glx extension has been initialized */
111
 
    if ( !__glXActiveScreens ) 
112
 
       return(0);
113
 
 
114
 
    pGlxScreen = &__glXActiveScreens[pScreen->myNum];
115
 
    pGlxVisual = pGlxScreen->pGlxVisual;
116
 
 
117
 
    /* find the glx visual info for pVisual */
118
 
    for (i = 0; i < pGlxScreen->numVisuals; i++, pGlxVisual++) {
119
 
        if (pGlxVisual->vid == pVisual->vid) {
120
 
            break;
121
 
        }
122
 
    }
123
 
    if (i == pGlxScreen->numVisuals) {
124
 
        /*
125
 
         * the visual is not supported by glx
126
 
         */
127
 
        return(0);
128
 
    }
129
 
 
130
 
    return( glxMatchGLXVisualInConfigList(pGlxVisual, configs, nconfigs) );
131
 
}
132
 
 
133
 
VisualPtr glxMatchVisual( ScreenPtr pScreen, VisualPtr pVisual, ScreenPtr pMatchScreen )
134
 
{
135
 
    __GLXscreenInfo *pGlxScreen2;
136
 
    int j;
137
 
    VisualID vid;
138
 
 
139
 
    /* check that the glx extension has been initialized */
140
 
    if ( !__glXActiveScreens ) 
141
 
       return NULL;
142
 
 
143
 
    pGlxScreen2 = &__glXActiveScreens[pMatchScreen->myNum];
144
 
 
145
 
    vid = glxMatchVisualInConfigList( pScreen, pVisual,
146
 
                                      pGlxScreen2->pGlxVisual,
147
 
                                      pGlxScreen2->numVisuals );
148
 
    if (vid) {
149
 
       /*
150
 
        * find the X visual of the matching glx visual
151
 
        */
152
 
       for (j=0; j<pMatchScreen->numVisuals; j++) {
153
 
          if (vid == pMatchScreen->visuals[j].vid) {
154
 
             return( &pMatchScreen->visuals[j] );
155
 
          }
156
 
       }
157
 
    }
158
 
 
159
 
    return(0);
160
 
}
161
 
 
162
 
void glxSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs,
163
 
                 void **privates)
164
 
{
165
 
    numConfigs = nconfigs;
166
 
    visualConfigs = configs;
167
 
    visualPrivates = privates;
168
 
}
169
 
 
170
 
static int count_bits(unsigned int n)
171
 
{
172
 
   int bits = 0;
173
 
 
174
 
   while (n > 0) {
175
 
      if (n & 1) bits++;
176
 
      n >>= 1;
177
 
   }
178
 
   return bits;
179
 
}
180
 
 
181
 
static VisualID FindClosestVisual( VisualPtr pVisual, int rootDepth, 
182
 
                                   DepthPtr pdepth, int ndepths,
183
 
                                   VisualPtr pNewVisual, int numNewVisuals)
184
 
{
185
 
   int d, v;
186
 
   VisualPtr vis;
187
 
 
188
 
   /*
189
 
    * find the first visual with the same or deeper depth
190
 
    * of the same class.
191
 
    */
192
 
   for (d=0; d<ndepths; d++) {
193
 
      if (pdepth[d].depth >= rootDepth) {
194
 
         for (v=0; v<pdepth[d].numVids; v++) {
195
 
 
196
 
            /* find the new visual structure */
197
 
            vis = pNewVisual;
198
 
            while( pdepth[d].vids[v] != vis->vid ) vis++;
199
 
 
200
 
            if (vis->class == pVisual->class) {
201
 
               return( pdepth[d].vids[v] );
202
 
            }
203
 
         }
204
 
      }
205
 
   }
206
 
 
207
 
   /*
208
 
    * did not find any.
209
 
    * try to look for the same class only.
210
 
    */
211
 
   for (d=0; d<ndepths; d++) {
212
 
      for (v=0; v<pdepth[d].numVids; v++) {
213
 
 
214
 
         /* find the new visual structure */
215
 
         vis = pNewVisual;
216
 
         while( pdepth[d].vids[v] != vis->vid ) vis++;
217
 
 
218
 
         if (vis->class == pVisual->class) {
219
 
            return( pdepth[d].vids[v] );
220
 
         }
221
 
      }
222
 
   }
223
 
 
224
 
   /*
225
 
    * if not found - just take the first visual
226
 
    */
227
 
   return( pdepth[0].vids[0] );
228
 
}
229
 
 
230
 
Bool glxInitVisuals(int *nvisualp, VisualPtr *visualp,
231
 
                         VisualID *defaultVisp,
232
 
                         int ndepth, DepthPtr pdepth,
233
 
                         int rootDepth)
234
 
{
235
 
    int numRGBconfigs;
236
 
    int numCIconfigs;
237
 
    int numVisuals = *nvisualp;
238
 
    int numNewVisuals;
239
 
    int numNewConfigs;
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;
247
 
    int found_default;
248
 
    int i, j, k;
249
 
    int numGLXvis = 0;
250
 
    GLint *isGLXvis;
251
 
 
252
 
    if (numConfigs > 0)
253
 
        numNewConfigs = numConfigs;
254
 
    else
255
 
        return False;
256
 
 
257
 
    MAXSCREENSALLOC(__glXActiveScreens);
258
 
    if (!__glXActiveScreens)
259
 
        return False;
260
 
 
261
 
    /* Alloc space for the list of new GLX visuals */
262
 
    pNewVisualConfigs = (__GLXvisualConfig *)
263
 
                     __glXMalloc(numNewConfigs * sizeof(__GLXvisualConfig));
264
 
    if (!pNewVisualConfigs) {
265
 
        return FALSE;
266
 
    }
267
 
 
268
 
    /* Alloc space for the list of new GLX visual privates */
269
 
    pNewVisualPriv = (dmxGlxVisualPrivate **) __glXMalloc(numNewConfigs * sizeof(dmxGlxVisualPrivate *));
270
 
    if (!pNewVisualPriv) {
271
 
        __glXFree(pNewVisualConfigs);
272
 
        return FALSE;
273
 
    }
274
 
 
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];
279
 
    }
280
 
 
281
 
#if 1
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.
285
 
     */
286
 
    {
287
 
        int numTCRGBconfigs = 0;
288
 
        int numDCRGBconfigs = 0;
289
 
 
290
 
        numRGBconfigs = 0;
291
 
        numCIconfigs = 0;
292
 
 
293
 
        for (i = 0; i < numNewConfigs; i++) {
294
 
            if (pNewVisualConfigs[i].rgba) {
295
 
                if (pNewVisualConfigs[i].class == TrueColor)
296
 
                    numTCRGBconfigs++;
297
 
                else
298
 
                    numDCRGBconfigs++;
299
 
                numRGBconfigs++;
300
 
            } else
301
 
                numCIconfigs++;
302
 
        }
303
 
 
304
 
        /* Count the total number of visuals to compute */
305
 
        numNewVisuals = 0;
306
 
        for (i = 0; i < numVisuals; i++) {
307
 
            numNewVisuals +=
308
 
                (pVisual[i].class == TrueColor)   ? numTCRGBconfigs :
309
 
                (pVisual[i].class == DirectColor) ? numDCRGBconfigs :
310
 
                                                    numCIconfigs;
311
 
        }
312
 
    }
313
 
#else
314
 
    /* Count the number of RGB and CI visual configs */
315
 
    numRGBconfigs = 0;
316
 
    numCIconfigs = 0;
317
 
    for (i = 0; i < numNewConfigs; i++) {
318
 
        if (pNewVisualConfigs[i].rgba)
319
 
            numRGBconfigs++;
320
 
        else
321
 
            numCIconfigs++;
322
 
    }
323
 
 
324
 
    /* Count the total number of visuals to compute */
325
 
    numNewVisuals = 0;
326
 
    for (i = 0; i < numVisuals; i++) {
327
 
        numNewVisuals +=
328
 
            (pVisual[i].class == TrueColor || pVisual[i].class == DirectColor)
329
 
            ? numRGBconfigs : numCIconfigs;
330
 
    }
331
 
#endif
332
 
 
333
 
    /* Reset variables for use with the next screen/driver's visual configs */
334
 
    visualConfigs = NULL;
335
 
    numConfigs = 0;
336
 
 
337
 
    /* Alloc temp space for the list of orig VisualIDs for each new visual */
338
 
    orig_vid = (VisualID *)__glXMalloc(numNewVisuals * sizeof(VisualID));
339
 
    if (!orig_vid) {
340
 
        __glXFree(pNewVisualPriv);
341
 
        __glXFree(pNewVisualConfigs);
342
 
        return FALSE;
343
 
    }
344
 
 
345
 
    /* Alloc space for the list of glXVisuals */
346
 
    glXVisualPtr = (__GLXvisualConfig *)__glXMalloc(numNewVisuals *
347
 
                                                    sizeof(__GLXvisualConfig));
348
 
    if (!glXVisualPtr) {
349
 
        __glXFree(orig_vid);
350
 
        __glXFree(pNewVisualPriv);
351
 
        __glXFree(pNewVisualConfigs);
352
 
        return FALSE;
353
 
    }
354
 
 
355
 
    /* Alloc space for the list of glXVisualPrivates */
356
 
    glXVisualPriv = (void **)__glXMalloc(numNewVisuals * sizeof(void *));
357
 
    if (!glXVisualPriv) {
358
 
        __glXFree(glXVisualPtr);
359
 
        __glXFree(orig_vid);
360
 
        __glXFree(pNewVisualPriv);
361
 
        __glXFree(pNewVisualConfigs);
362
 
        return FALSE;
363
 
    }
364
 
 
365
 
    /* Alloc space for the new list of the X server's visuals */
366
 
    pVisualNew = (VisualPtr)__glXMalloc(numNewVisuals * sizeof(VisualRec));
367
 
    if (!pVisualNew) {
368
 
        __glXFree(glXVisualPriv);
369
 
        __glXFree(glXVisualPtr);
370
 
        __glXFree(orig_vid);
371
 
        __glXFree(pNewVisualPriv);
372
 
        __glXFree(pNewVisualConfigs);
373
 
        return FALSE;
374
 
    }
375
 
 
376
 
    isGLXvis = (GLint *) __glXMalloc(numNewVisuals * sizeof(GLint));
377
 
    if (!isGLXvis) {
378
 
        __glXFree(glXVisualPriv);
379
 
        __glXFree(glXVisualPtr);
380
 
        __glXFree(orig_vid);
381
 
        __glXFree(pNewVisualPriv);
382
 
        __glXFree(pNewVisualConfigs);
383
 
        __glXFree(pVisualNew);
384
 
        return FALSE;
385
 
    }
386
 
 
387
 
    /* Initialize the new visuals */
388
 
    found_default = FALSE;
389
 
    for (i = j = 0; i < numVisuals; i++) {
390
 
 
391
 
        for (k = 0; k < numNewConfigs; k++) {
392
 
 
393
 
            int new_depth;
394
 
            int depth;
395
 
            int d,v;
396
 
 
397
 
            /* find the depth of the new visual config */
398
 
            new_depth = pNewVisualPriv[k]->x_visual_depth;
399
 
 
400
 
            /* find the depth of the original visual */
401
 
            depth = 0;
402
 
            d = 0;
403
 
            while( (depth==0) && (d < ndepth) ) {
404
 
               v = 0;
405
 
               while( (depth==0) && (v < pdepth[d].numVids) ) {
406
 
                  if (pdepth[d].vids[v] ==  pVisual[i].vid) {
407
 
                     depth = pdepth[d].depth;
408
 
                  }
409
 
                  v++;
410
 
               }
411
 
               d++;
412
 
            }
413
 
 
414
 
            /* check that the visual has the same class and depth 
415
 
             * as the new config
416
 
             */
417
 
            if ( pVisual[i].class != pNewVisualPriv[k]->x_visual_class ||
418
 
                  (depth != new_depth) )
419
 
                continue;
420
 
 
421
 
            /* Initialize the new visual */
422
 
            pVisualNew[j] = pVisual[i];
423
 
            pVisualNew[j].vid = FakeClientID(0);
424
 
 
425
 
            /* Check for the default visual */
426
 
            if (!found_default && pVisual[i].vid == *defaultVisp) {
427
 
                *defaultVisp = pVisualNew[j].vid;
428
 
                found_default = TRUE;
429
 
            }
430
 
 
431
 
            /* Save the old VisualID */
432
 
            orig_vid[j] = pVisual[i].vid;
433
 
 
434
 
            /* Initialize the glXVisual */
435
 
            glXVisualPtr[j] = pNewVisualConfigs[k];
436
 
            glXVisualPtr[j].vid = pVisualNew[j].vid;
437
 
 
438
 
            /*
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
442
 
             * be initialized.
443
 
             */
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;
455
 
            }
456
 
 
457
 
            /* Save the device-dependent private for this visual */
458
 
            glXVisualPriv[j] = pNewVisualPriv[k];
459
 
 
460
 
            isGLXvis[j] = glxMatchGLXVisualInConfigList( &glXVisualPtr[j], 
461
 
                                   dmxScreens[screenInfo.numScreens-1].glxVisuals,
462
 
                                   dmxScreens[screenInfo.numScreens-1].numGlxVisuals );
463
 
            if (isGLXvis[j]) numGLXvis++;
464
 
 
465
 
            j++;
466
 
        }
467
 
    }
468
 
 
469
 
    assert(j <= numNewVisuals);
470
 
    numNewVisuals = j;   /* correct number of new visuals */
471
 
 
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;
477
 
 
478
 
 
479
 
    /* Set up depth's VisualIDs */
480
 
    for (i = 0; i < ndepth; i++) {
481
 
        int numVids = 0;
482
 
        VisualID *pVids = NULL;
483
 
        int k, n = 0;
484
 
 
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])
489
 
                    numVids++;
490
 
 
491
 
        /* Allocate a new list of VisualIDs for this depth */
492
 
        pVids = (VisualID *)__glXMalloc(numVids * sizeof(VisualID));
493
 
 
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;
499
 
 
500
 
        /* Update this depth's list of VisualIDs */
501
 
        __glXFree(pdepth[i].vids);
502
 
        pdepth[i].vids = pVids;
503
 
        pdepth[i].numVids = numVids;
504
 
    }
505
 
 
506
 
    /*
507
 
     * if the default visual was rejected - need to choose new
508
 
     * default visual !
509
 
     */ 
510
 
    if ( !found_default ) {
511
 
 
512
 
       for (i=0; i<numVisuals; i++)
513
 
          if (pVisual[i].vid == *defaultVisp)
514
 
             break;
515
 
 
516
 
       if (i < numVisuals) {
517
 
          *defaultVisp = FindClosestVisual( &pVisual[i], rootDepth, pdepth, ndepth, pVisualNew, numNewVisuals );
518
 
       }
519
 
    }
520
 
 
521
 
    /* Update the X server's visuals */
522
 
    *nvisualp = numNewVisuals;
523
 
    *visualp = pVisualNew;
524
 
 
525
 
    /* Free the old list of the X server's visuals */
526
 
    __glXFree(pVisual);
527
 
 
528
 
    /* Clean up temporary allocations */
529
 
    __glXFree(orig_vid);
530
 
    __glXFree(pNewVisualPriv);
531
 
    __glXFree(pNewVisualConfigs);
532
 
 
533
 
    /* Free the private list created by DDX HW driver */
534
 
    if (visualPrivates)
535
 
        xfree(visualPrivates);
536
 
    visualPrivates = NULL;
537
 
 
538
 
    return TRUE;
539
 
}