~ubuntu-branches/ubuntu/feisty/xorg-server/feisty

« back to all changes in this revision

Viewing changes to lbx/lbxopts.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher, Timo Aaltonen
  • Date: 2007-02-26 09:36:38 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070226093638-z7nq1i01gcuujj06
Tags: 2:1.2.0-3ubuntu1
* Don't drop 42_build_int10_submodules.diff, it's useful
* 019_ubuntu_enable_composite.diff:
  - enable composite
* debian/control:
  - fixed Maintainer email
* debian/xserver-xorg-core.install:
  - list ioport, gtf, pcitweak and scanpci 
    and manpages for scanpci, gtf, pcitweak

[ Timo Aaltonen ]
* Merge with Debian, remaining changes:
  - debian/rules:
    + build using -fno-stack-protector
    + --with-os-vendor=Ubuntu
  - debian/control:
    + don't Conflict with xserver-xorg-video
  - refreshed and renamed patches
    102_ubuntu_sharevts_load_cpu.patch
    104_fedora_init_origins_fix.patch
    106_ubuntu_fpic_libxf86config.patch
    114_fedora_no_composite_in_xnest.patch
    121_only_switch_vt_when_active.diff
    124_fix-pdripriv_null_deref.patch
  - dropped for now:
    42_build_int10_submodules.diff - causes "some regression"
* dropped patches (comments from Michel Daenzer):
  - 107_fedora_dont_backfill_bg_none.patch
    "Breaks X semantics and thus can't go in upstream. Apps/toolkits
     need to be fixed not to use background none windows."
  - 108_fedora_gl_include_inferiors.patch
    "Breaks GLX semantics and should no longer be necessary now that
     the GLX compositing managers default to using the Composite
     Overlay Window."
  - 120_fedora_disable_offscreen_pixmaps.diff
    "Last time I looked at this, it was a gross hack to work around XAA
     deficiencies in offscreen pixmap handling, which makes the server
     die immediately when trying to use GLX_EXT_texture_from_pixmap
     with EXA, due to calling XAA functions without checking it's
     active or even loaded."
* debian/control:
  - set Conflicts: xkb-data (<< 0.9), since xkb-path is
    different from previous releases
* debian/patches/125_randr-version-supported.diff:
  - The server supports protocol 1.1, make sure we use it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Xorg: lbxopts.c,v 1.3 2000/08/17 19:53:31 cpqbld Exp $ */
2
 
/*
3
 
 * Copyright 1994 Network Computing Devices, Inc.
4
 
 *
5
 
 * Permission to use, copy, modify, distribute, and sell this software and
6
 
 * its documentation for any purpose is hereby granted without fee, provided
7
 
 * that the above copyright notice appear in all copies and that both that
8
 
 * copyright notice and this permission notice appear in supporting
9
 
 * documentation, and that the name Network Computing Devices, Inc. not be
10
 
 * used in advertising or publicity pertaining to distribution of this
11
 
 * software without specific, written prior permission.
12
 
 *
13
 
 * THIS SOFTWARE IS PROVIDED `AS-IS'.  NETWORK COMPUTING DEVICES, INC.,
14
 
 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
15
 
 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16
 
 * PARTICULAR PURPOSE, OR NONINFRINGEMENT.  IN NO EVENT SHALL NETWORK
17
 
 * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING
18
 
 * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA,
19
 
 * OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
20
 
 * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN
21
 
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
 
 *
23
 
 */
24
 
/* $XFree86: xc/programs/Xserver/lbx/lbxopts.c,v 1.5 2001/01/17 22:37:00 dawes Exp $ */
25
 
 
26
 
#ifdef HAVE_DIX_CONFIG_H
27
 
#include <dix-config.h>
28
 
#endif
29
 
 
30
 
#ifdef OPTDEBUG
31
 
#include <stdio.h>
32
 
#endif
33
 
#include <X11/X.h>
34
 
#include <X11/Xproto.h>
35
 
#include "misc.h"
36
 
#include "colormapst.h"
37
 
#include "propertyst.h"
38
 
#include "lbxserve.h"
39
 
#include <X11/extensions/lbxstr.h>
40
 
#include <X11/extensions/lbximage.h>
41
 
#include <X11/extensions/lbxopts.h>
42
 
#include "lbxsrvopts.h"
43
 
#ifndef NO_ZLIB
44
 
#include <X11/extensions/lbxzlib.h>
45
 
#endif /* NO_ZLIB */
46
 
 
47
 
static int LbxProxyDeltaOpt ( LbxNegOptsPtr pno, unsigned char *popt, 
48
 
                              int optlen, unsigned char *preply );
49
 
static int LbxServerDeltaOpt ( LbxNegOptsPtr pno, unsigned char *popt, 
50
 
                               int optlen, unsigned char *preply );
51
 
static int LbxDeltaOpt ( unsigned char *popt, int optlen, 
52
 
                         unsigned char *preply, short *pn, short *pmaxlen );
53
 
static int LbxStreamCompOpt ( LbxNegOptsPtr pno, unsigned char *popt, 
54
 
                              int optlen, unsigned char *preply );
55
 
static int ZlibParse ( LbxNegOptsPtr pno, unsigned char *popt, int optlen, 
56
 
                       unsigned char *preply );
57
 
static int LbxMessageCompOpt ( LbxNegOptsPtr pno, unsigned char *popt, 
58
 
                               int optlen, unsigned char *preply );
59
 
static int LbxUseTagsOpt ( LbxNegOptsPtr pno, unsigned char *popt, 
60
 
                                  int optlen, unsigned char *preply );
61
 
static int LbxBitmapCompOpt ( LbxNegOptsPtr pno, unsigned char *popt, 
62
 
                                     int optlen, unsigned char *preply );
63
 
static int LbxPixmapCompOpt ( LbxNegOptsPtr pno, unsigned char *popt, 
64
 
                                     int optlen, unsigned char *preply );
65
 
static int MergeDepths ( int *depths, LbxPixmapCompMethod *method );
66
 
static int LbxCmapAllOpt ( LbxNegOptsPtr pno, unsigned char *popt, 
67
 
                                  int optlen, unsigned char *preply );
68
 
 
69
 
/*
70
 
 * List of LBX options we recognize and are willing to negotiate
71
 
 */
72
 
static struct _LbxOptionParser {
73
 
    CARD8       optcode;
74
 
    int         (*parser)(LbxNegOptsPtr, unsigned char *, 
75
 
                          int, unsigned char *);
76
 
} LbxOptions[] = {
77
 
    { LBX_OPT_DELTA_PROXY,      LbxProxyDeltaOpt },
78
 
    { LBX_OPT_DELTA_SERVER,     LbxServerDeltaOpt },
79
 
    { LBX_OPT_STREAM_COMP,      LbxStreamCompOpt },
80
 
    { LBX_OPT_BITMAP_COMP,      LbxBitmapCompOpt },
81
 
    { LBX_OPT_PIXMAP_COMP,      LbxPixmapCompOpt },
82
 
    { LBX_OPT_MSG_COMP,         LbxMessageCompOpt },
83
 
    { LBX_OPT_USE_TAGS,         LbxUseTagsOpt },
84
 
    { LBX_OPT_CMAP_ALL,         LbxCmapAllOpt }
85
 
};
86
 
 
87
 
#define LBX_N_OPTS      (sizeof(LbxOptions) / sizeof(struct _LbxOptionParser))
88
 
 
89
 
/*
90
 
 * Set option defaults
91
 
 */
92
 
void
93
 
LbxOptionInit(LbxNegOptsPtr pno)
94
 
{
95
 
    bzero(pno, sizeof(LbxNegOptsRec));
96
 
    pno->proxyDeltaN = pno->serverDeltaN = LBX_OPT_DELTA_NCACHE_DFLT;
97
 
    pno->proxyDeltaMaxLen = pno->serverDeltaMaxLen = LBX_OPT_DELTA_MSGLEN_DFLT;
98
 
    pno->squish = TRUE;
99
 
    pno->numBitmapCompMethods = 0;
100
 
    pno->bitmapCompMethods = NULL;
101
 
    pno->numPixmapCompMethods = 0;
102
 
    pno->pixmapCompMethods = NULL;
103
 
    pno->pixmapCompDepths = NULL;
104
 
    pno->useTags = TRUE;
105
 
}
106
 
 
107
 
int
108
 
LbxOptionParse(LbxNegOptsPtr  pno,
109
 
               unsigned char *popt,
110
 
               int            optlen,
111
 
               unsigned char *preply)
112
 
{
113
 
    int           i;
114
 
    int           nopts = *popt++;
115
 
    unsigned char *pout = preply;
116
 
 
117
 
    for (i = 0; i < nopts; i++) {
118
 
        int j;
119
 
        int len;
120
 
        int hdrlen;
121
 
        int replylen;
122
 
 
123
 
        LBX_OPT_DECODE_LEN(popt + 1, len, hdrlen);
124
 
        if (len < ++hdrlen || len > optlen) {
125
 
#ifdef OPTDEBUG
126
 
            fprintf(stderr, "bad option length, len = %d, hdrlen = %d, optlen = %d\n", len, hdrlen, optlen);
127
 
#endif
128
 
            return -1;
129
 
        }
130
 
 
131
 
        for (j = 0; j < LBX_N_OPTS; j++) {
132
 
            if (popt[0] == LbxOptions[j].optcode) {
133
 
                replylen = (*LbxOptions[j].parser)(pno,
134
 
                                                   popt + hdrlen,
135
 
                                                   len - hdrlen,
136
 
                                                   pout + LBX_OPT_SMALLHDR_LEN);
137
 
                if (replylen < 0)
138
 
                    return -1;
139
 
                else if (replylen > 0) {
140
 
                    /*
141
 
                     * None of the current options require big headers,
142
 
                     * so this works for now.
143
 
                     */
144
 
                    *pout++ = i;
145
 
                    *pout++ = LBX_OPT_SMALLHDR_LEN + replylen;
146
 
                    pout += replylen;
147
 
                    pno->nopts++;
148
 
                }
149
 
                break;
150
 
            }
151
 
        }
152
 
 
153
 
        optlen -= len;
154
 
        popt += len;
155
 
    }
156
 
 
157
 
    return (pout - preply);
158
 
}
159
 
 
160
 
static int
161
 
LbxProxyDeltaOpt(LbxNegOptsPtr  pno,
162
 
                 unsigned char *popt,
163
 
                 int            optlen,
164
 
                 unsigned char *preply)
165
 
{
166
 
    return LbxDeltaOpt(popt, optlen, preply,
167
 
                       &pno->proxyDeltaN, &pno->proxyDeltaMaxLen);
168
 
}
169
 
 
170
 
static int
171
 
LbxServerDeltaOpt(LbxNegOptsPtr  pno,
172
 
                  unsigned char *popt,
173
 
                  int            optlen,
174
 
                  unsigned char *preply)
175
 
{
176
 
    return LbxDeltaOpt(popt, optlen, preply,
177
 
                       &pno->serverDeltaN, &pno->serverDeltaMaxLen);
178
 
}
179
 
 
180
 
static int
181
 
LbxDeltaOpt(unsigned char *popt,
182
 
            int            optlen,
183
 
            unsigned char *preply,
184
 
            short         *pn,
185
 
            short         *pmaxlen)
186
 
{
187
 
    short         n;
188
 
    short         maxlen;
189
 
 
190
 
    /*
191
 
     * If there's more data than we expect, we just ignore it.
192
 
     */
193
 
    if (optlen < LBX_OPT_DELTA_REQLEN) {
194
 
#ifdef OPTDEBUG
195
 
        fprintf(stderr, "bad delta option length = %d\n", optlen);
196
 
#endif
197
 
        return -1;
198
 
    }
199
 
 
200
 
    /*
201
 
     * Accept whatever value the proxy prefers, so skip the
202
 
     * min/max offerings.  Note that the max message len value is
203
 
     * encoded as the number of 4-byte values.
204
 
     */
205
 
    popt += 2;
206
 
    n = *popt++;
207
 
    popt += 2;
208
 
    maxlen = *popt++;
209
 
    if ((maxlen <<= 2) == 0)
210
 
        n = 0;
211
 
    else if (maxlen < 32) {
212
 
#ifdef OPTDEBUG
213
 
        fprintf(stderr, "bad delta max msg length %d\n", maxlen);
214
 
#endif
215
 
        return -1;
216
 
     }
217
 
 
218
 
    /*
219
 
     * Put the response in the reply buffer
220
 
     */
221
 
    *preply++ = n;
222
 
    *preply++ = maxlen >> 2;
223
 
 
224
 
    *pn = n;
225
 
    *pmaxlen = maxlen;
226
 
 
227
 
    return LBX_OPT_DELTA_REPLYLEN;
228
 
}
229
 
 
230
 
 
231
 
static struct _LbxStreamCompParser {
232
 
    int         typelen;
233
 
    char        *type;
234
 
    int         (*parser)(LbxNegOptsPtr, unsigned char *, 
235
 
                          int, unsigned char *);
236
 
} LbxStreamComp[] = {
237
 
#ifndef NO_ZLIB
238
 
    { ZLIB_STRCOMP_OPT_LEN,     ZLIB_STRCOMP_OPT,       ZlibParse },
239
 
#endif /* NO_ZLIB */
240
 
};
241
 
 
242
 
#define LBX_N_STRCOMP   \
243
 
    (sizeof(LbxStreamComp) / sizeof(struct _LbxStreamCompParser))
244
 
 
245
 
static int
246
 
LbxStreamCompOpt(LbxNegOptsPtr  pno,
247
 
                 unsigned char *popt,
248
 
                 int            optlen,
249
 
                 unsigned char *preply)
250
 
{
251
 
    int           i;
252
 
    int           typelen;
253
 
    int           nopts = *popt++;
254
 
 
255
 
    for (i = 0; i < nopts; i++) {
256
 
        int j;
257
 
        int len;
258
 
        int lensize;
259
 
        int replylen;
260
 
 
261
 
        typelen = popt[0];
262
 
        for (j = 0; j < LBX_N_STRCOMP; j++) {
263
 
            if (typelen == LbxStreamComp[j].typelen &&
264
 
                !strncmp((char *) popt + 1, LbxStreamComp[j].type, typelen))
265
 
                break;
266
 
        }
267
 
 
268
 
        popt += 1 + typelen;
269
 
        optlen -= 1 + typelen;
270
 
        LBX_OPT_DECODE_LEN(popt, len, lensize);
271
 
 
272
 
        if (j < LBX_N_STRCOMP) {
273
 
            if (len > optlen)
274
 
                return -1;
275
 
            replylen = (*LbxStreamComp[j].parser)(pno,
276
 
                                                  popt + lensize,
277
 
                                                  len - lensize,
278
 
                                                  preply + 1);
279
 
            if (replylen == -1)
280
 
                return -1;
281
 
            else if (replylen >= 0) {
282
 
                *preply = i;
283
 
                return replylen + 1;
284
 
            }
285
 
        }
286
 
 
287
 
        optlen -= len;
288
 
        popt += len;
289
 
    }
290
 
 
291
 
    return 0;
292
 
}
293
 
 
294
 
 
295
 
static int
296
 
ZlibParse(LbxNegOptsPtr   pno,
297
 
          unsigned char  *popt,
298
 
          int             optlen,
299
 
          unsigned char  *preply)
300
 
{
301
 
    int level;          /* compression level */
302
 
 
303
 
    if (*popt++ != 1)   /* length should be 1 */
304
 
        return (-1);
305
 
 
306
 
    level = *popt;
307
 
    if (level < 1 || level > 9)
308
 
        return (-1);
309
 
 
310
 
    pno->streamOpts.streamCompInit =
311
 
        (LbxStreamCompHandle (*)(int, pointer))ZlibInit;
312
 
    pno->streamOpts.streamCompArg = (pointer)(long)level;
313
 
    pno->streamOpts.streamCompStuffInput = ZlibStuffInput;
314
 
    pno->streamOpts.streamCompInputAvail = ZlibInputAvail;
315
 
    pno->streamOpts.streamCompFlush = ZlibFlush;
316
 
    pno->streamOpts.streamCompRead = ZlibRead;
317
 
    pno->streamOpts.streamCompWriteV = ZlibWriteV;
318
 
    pno->streamOpts.streamCompOn = ZlibCompressOn;
319
 
    pno->streamOpts.streamCompOff = ZlibCompressOff;
320
 
    pno->streamOpts.streamCompFreeHandle =
321
 
        (void (*)(LbxStreamCompHandle))ZlibFree;
322
 
 
323
 
    return (0);
324
 
}
325
 
 
326
 
static int
327
 
LbxMessageCompOpt(LbxNegOptsPtr  pno,
328
 
                  unsigned char *popt,
329
 
                  int            optlen,
330
 
                  unsigned char *preply)
331
 
{
332
 
 
333
 
    if (optlen == 0) {
334
 
#ifdef OPTDEBUG
335
 
        fprintf(stderr, "bad message-comp option length specified %d\n", optlen);
336
 
#endif
337
 
        return -1;
338
 
    }
339
 
 
340
 
    pno->squish = *preply = *popt;
341
 
    return 1;
342
 
}
343
 
 
344
 
 
345
 
static int
346
 
LbxUseTagsOpt(LbxNegOptsPtr  pno,
347
 
              unsigned char *popt,
348
 
              int            optlen,
349
 
              unsigned char *preply)
350
 
{
351
 
 
352
 
    if (optlen == 0) {
353
 
#ifdef OPTDEBUG
354
 
        fprintf(stderr, "bad use-tags option length specified %d\n", optlen);
355
 
#endif
356
 
        return -1;
357
 
    }
358
 
 
359
 
    pno->useTags = *preply = *popt;
360
 
    return 1;
361
 
}
362
 
 
363
 
 
364
 
/*
365
 
 * Option negotiation for image compression
366
 
 */
367
 
 
368
 
LbxBitmapCompMethod
369
 
LbxBitmapCompMethods [] = {
370
 
  {
371
 
    "XC-FaxG42D",               /* compression method name */
372
 
    0,                          /* inited */
373
 
    2,                          /* method opcode */
374
 
    NULL,                       /* init function */
375
 
    LbxImageEncodeFaxG42D,      /* encode function */
376
 
    LbxImageDecodeFaxG42D       /* decode function */
377
 
  }
378
 
};
379
 
 
380
 
#define NUM_BITMAP_METHODS \
381
 
        (sizeof (LbxBitmapCompMethods) / sizeof (LbxBitmapCompMethod))
382
 
 
383
 
 
384
 
#if 1
385
 
/*
386
 
 * Currently, we don't support any pixmap compression algorithms
387
 
 * because regular stream compression does much better than PackBits.
388
 
 * If we want to plug in a better pixmap image compression algorithm,
389
 
 * it would go here.
390
 
 */
391
 
 
392
 
#define NUM_PIXMAP_METHODS 0
393
 
LbxPixmapCompMethod LbxPixmapCompMethods [1]; /* dummy */
394
 
 
395
 
#else
396
 
 
397
 
LbxPixmapCompMethod
398
 
LbxPixmapCompMethods [] = {
399
 
  {
400
 
    "XC-PackBits",              /* compression method name */
401
 
    1 << ZPixmap,               /* formats supported */
402
 
    1, {8},                     /* depths supported */
403
 
    0,                          /* inited */
404
 
    1,                          /* method opcode */
405
 
    NULL,                       /* init function */
406
 
    LbxImageEncodePackBits,     /* encode function */
407
 
    LbxImageDecodePackBits      /* decode function */
408
 
  }
409
 
};
410
 
 
411
 
#define NUM_PIXMAP_METHODS \
412
 
        (sizeof (LbxPixmapCompMethods) / sizeof (LbxPixmapCompMethod))
413
 
#endif
414
 
 
415
 
 
416
 
static int
417
 
LbxImageCompOpt (Bool            pixmap,
418
 
                 LbxNegOptsPtr   pno,
419
 
                 unsigned char  *popt,
420
 
                 int             optlen,
421
 
                 unsigned char  *preply)
422
 
 
423
 
{
424
 
    unsigned char *preplyStart = preply;
425
 
    int numMethods = *popt++;
426
 
    unsigned char *myIndices, *hisIndices;
427
 
    unsigned int *retFormats = NULL;
428
 
    int **retDepths = NULL;
429
 
    int replyCount = 0;
430
 
    int status, i, j;
431
 
 
432
 
    if (numMethods == 0)
433
 
    {
434
 
        if (pixmap)
435
 
            pno->numPixmapCompMethods = 0;
436
 
        else
437
 
            pno->numBitmapCompMethods = 0;
438
 
 
439
 
        *preply++ = 0;
440
 
        return (1);
441
 
    }
442
 
 
443
 
    myIndices = (unsigned char *) xalloc (numMethods);
444
 
    hisIndices = (unsigned char *) xalloc (numMethods);
445
 
 
446
 
    if (!myIndices || !hisIndices)
447
 
    {
448
 
        if (myIndices)
449
 
            xfree (myIndices);
450
 
        if (hisIndices)
451
 
            xfree (hisIndices);
452
 
        return -1;
453
 
    }
454
 
 
455
 
    if (pixmap)
456
 
    {
457
 
        retFormats = (unsigned *) xalloc (numMethods);
458
 
        retDepths = (int **) xalloc (numMethods * sizeof (int *));
459
 
 
460
 
        if (!retFormats || !retDepths)
461
 
        {
462
 
            if (retFormats)
463
 
                xfree (retFormats);
464
 
            if (retDepths)
465
 
                xfree (retDepths);
466
 
            xfree (myIndices);
467
 
            xfree (hisIndices);
468
 
            return -1;
469
 
        }
470
 
    }
471
 
 
472
 
    /*
473
 
     * For each method in the list sent by the proxy, see if the server
474
 
     * supports this method.  If YES, update the following lists:
475
 
     *
476
 
     * myIndices[] is a list of indices into the server's
477
 
     * LbxBit[Pix]mapCompMethods table.
478
 
     *
479
 
     * hisIndices[] is a list of indices into the list of
480
 
     * method names sent by the proxy.
481
 
     *
482
 
     * retFormats[] indicates for each pixmap compression method,
483
 
     * the pixmap formats supported.
484
 
     *
485
 
     * retDepths[] indicates for each pixmap compression method,
486
 
     * the pixmap depths supported.
487
 
     */
488
 
 
489
 
    for (i = 0; i < numMethods; i++)
490
 
    {
491
 
        unsigned int formatMask = 0, newFormatMask = 0;
492
 
        int depthCount, *depths = NULL, len;
493
 
        int freeDepths;
494
 
        char *methodName;
495
 
 
496
 
        freeDepths = 0;
497
 
        len = *popt++;
498
 
        methodName = (char *) popt;
499
 
        popt += len;
500
 
 
501
 
        if (pixmap)
502
 
        {
503
 
            formatMask = *popt++;
504
 
            depthCount = *popt++;
505
 
            depths = (int *) xalloc ((depthCount + 1) * sizeof (int));
506
 
            freeDepths = 1;
507
 
            depths[0] = depthCount;
508
 
            for (j = 1; j <= depthCount; j++)
509
 
                depths[j] = *popt++;
510
 
        }
511
 
 
512
 
        for (j = 0;
513
 
            j < (pixmap ? NUM_PIXMAP_METHODS : NUM_BITMAP_METHODS); j++)
514
 
        {
515
 
 
516
 
            status = strncmp (methodName,
517
 
                (pixmap ? LbxPixmapCompMethods[j].methodName :
518
 
                          LbxBitmapCompMethods[j].methodName),
519
 
                len);
520
 
 
521
 
            if (status == 0 && pixmap)
522
 
            {
523
 
                newFormatMask =
524
 
                    formatMask & LbxPixmapCompMethods[j].formatMask;
525
 
 
526
 
                depthCount = MergeDepths (depths, &LbxPixmapCompMethods[j]);
527
 
                
528
 
                if (newFormatMask == 0 || depthCount == 0)
529
 
                    status = 1;
530
 
            }
531
 
 
532
 
            if (status == 0)
533
 
            {
534
 
                myIndices[replyCount] = j;
535
 
                hisIndices[replyCount] = i;
536
 
 
537
 
                if (pixmap)
538
 
                {
539
 
                    retFormats[replyCount] = newFormatMask;
540
 
                    retDepths[replyCount] = depths;
541
 
                    freeDepths = 0;
542
 
                }
543
 
 
544
 
                replyCount++;
545
 
                break;
546
 
            }
547
 
        }
548
 
 
549
 
        if (freeDepths)
550
 
            xfree (depths);
551
 
    }
552
 
 
553
 
    *preply++ = replyCount;
554
 
 
555
 
    /*
556
 
     * Sort the lists by LBX server preference (increasing myIndices[] vals)
557
 
     */
558
 
 
559
 
    for (i = 0; i <= replyCount - 2; i++)
560
 
        for (j = replyCount - 1; j >= i; j--)
561
 
            if (myIndices[j - 1] > myIndices[j])
562
 
            {
563
 
                char temp1 = myIndices[j - 1];
564
 
                char temp2 = hisIndices[j - 1];
565
 
 
566
 
                myIndices[j - 1] = myIndices[j];
567
 
                myIndices[j] = temp1;
568
 
 
569
 
                hisIndices[j - 1] = hisIndices[j];
570
 
                hisIndices[j] = temp2;
571
 
 
572
 
                if (pixmap)
573
 
                {
574
 
                    unsigned temp3 = retFormats[j - 1];
575
 
                    int *temp4 = retDepths[j - 1];
576
 
 
577
 
                    retFormats[j - 1] = retFormats[j];
578
 
                    retFormats[j] = temp3;
579
 
 
580
 
                    retDepths[j - 1] = retDepths[j];
581
 
                    retDepths[j] = temp4;
582
 
                }
583
 
            }
584
 
 
585
 
    /*
586
 
     * For each method supported, return to the proxy an index into
587
 
     * the list sent by the proxy, the opcode to be used for the method,
588
 
     * the pixmap formats supported, and the list of depths supported.
589
 
     */
590
 
 
591
 
    for (i = 0; i < replyCount; i++)
592
 
    {
593
 
        *preply++ = hisIndices[i];
594
 
 
595
 
        if (pixmap)
596
 
        {
597
 
            int left;
598
 
            *preply++ = LbxPixmapCompMethods[myIndices[i]].methodOpCode;
599
 
            *preply++ = retFormats[i];
600
 
            *preply++ = left = retDepths[i][0];
601
 
            j = 1;
602
 
            while (left > 0)
603
 
            {
604
 
                *preply++ = retDepths[i][j];
605
 
                left--;
606
 
            }
607
 
        }
608
 
        else
609
 
        {
610
 
            *preply++ = LbxBitmapCompMethods[myIndices[i]].methodOpCode;
611
 
        }
612
 
    }
613
 
 
614
 
    if (pixmap)
615
 
    {
616
 
        pno->numPixmapCompMethods = replyCount;
617
 
        pno->pixmapCompMethods = myIndices;
618
 
        pno->pixmapCompDepths = retDepths;
619
 
    }
620
 
    else
621
 
    {
622
 
        pno->numBitmapCompMethods = replyCount;
623
 
        pno->bitmapCompMethods = myIndices;
624
 
    }
625
 
 
626
 
    if (hisIndices)
627
 
        xfree (hisIndices);
628
 
 
629
 
    if (pixmap)
630
 
    {
631
 
        if (retFormats)
632
 
            xfree (retFormats);
633
 
    }
634
 
 
635
 
    return (preply - preplyStart);
636
 
}
637
 
 
638
 
 
639
 
 
640
 
static int
641
 
LbxBitmapCompOpt (LbxNegOptsPtr   pno,
642
 
                  unsigned char  *popt,
643
 
                  int             optlen,
644
 
                  unsigned char  *preply)
645
 
 
646
 
{
647
 
    return (LbxImageCompOpt (0 /* bitmap */, pno, popt, optlen, preply));
648
 
}
649
 
 
650
 
 
651
 
static int
652
 
LbxPixmapCompOpt (LbxNegOptsPtr   pno,
653
 
                  unsigned char  *popt,
654
 
                  int             optlen,
655
 
                  unsigned char  *preply)
656
 
 
657
 
{
658
 
    return (LbxImageCompOpt (1 /* Pixmap */, pno, popt, optlen, preply));
659
 
}
660
 
 
661
 
 
662
 
LbxBitmapCompMethod *
663
 
LbxSrvrLookupBitmapCompMethod (LbxProxyPtr proxy,
664
 
                               int methodOpCode)
665
 
 
666
 
{
667
 
    int i;
668
 
 
669
 
    for (i = 0; i < proxy->numBitmapCompMethods; i++)
670
 
    {
671
 
        LbxBitmapCompMethod *method;
672
 
 
673
 
        method = &LbxBitmapCompMethods[proxy->bitmapCompMethods[i]];
674
 
 
675
 
        if (method->methodOpCode == methodOpCode)
676
 
            return (method);
677
 
    }
678
 
 
679
 
    return (NULL);
680
 
}
681
 
 
682
 
 
683
 
LbxPixmapCompMethod *
684
 
LbxSrvrLookupPixmapCompMethod (LbxProxyPtr proxy,
685
 
                               int methodOpCode)
686
 
 
687
 
{
688
 
    int i;
689
 
 
690
 
    for (i = 0; i < proxy->numPixmapCompMethods; i++)
691
 
    {
692
 
        LbxPixmapCompMethod *method;
693
 
 
694
 
        method = &LbxPixmapCompMethods[proxy->pixmapCompMethods[i]];
695
 
 
696
 
        if (method->methodOpCode == methodOpCode)
697
 
            return (method);
698
 
    }
699
 
 
700
 
    return (NULL);
701
 
}
702
 
 
703
 
 
704
 
LbxBitmapCompMethod *
705
 
LbxSrvrFindPreferredBitmapCompMethod (LbxProxyPtr proxy)
706
 
 
707
 
{
708
 
    if (proxy->numBitmapCompMethods == 0)
709
 
        return NULL;
710
 
    else
711
 
        return (&LbxBitmapCompMethods[proxy->bitmapCompMethods[0]]);
712
 
}
713
 
 
714
 
 
715
 
 
716
 
LbxPixmapCompMethod *
717
 
LbxSrvrFindPreferredPixmapCompMethod (LbxProxyPtr proxy,
718
 
                                      int format,
719
 
                                      int depth)
720
 
 
721
 
{
722
 
    if (proxy->numPixmapCompMethods == 0)
723
 
        return NULL;
724
 
    else
725
 
    {
726
 
        LbxPixmapCompMethod *method;
727
 
        int i, j;
728
 
 
729
 
        for (i = 0; i < proxy->numPixmapCompMethods; i++)
730
 
        {
731
 
            method = &LbxPixmapCompMethods[proxy->pixmapCompMethods[i]];
732
 
 
733
 
            if ((method->formatMask & (1 << format)))
734
 
            {
735
 
                int n = proxy->pixmapCompDepths[i][0];
736
 
                j = 1;
737
 
                while (n > 0)
738
 
                {
739
 
                    if (depth == proxy->pixmapCompDepths[i][j])
740
 
                        return method;
741
 
                    else
742
 
                        n--;
743
 
                }
744
 
            }
745
 
        }
746
 
 
747
 
        return NULL;
748
 
    }
749
 
}
750
 
 
751
 
 
752
 
static int 
753
 
MergeDepths (int *depths,
754
 
             LbxPixmapCompMethod *method)
755
 
 
756
 
{
757
 
    int i, j, count;
758
 
    int temp[LBX_MAX_DEPTHS + 1];
759
 
 
760
 
    temp[0] = count = 0;
761
 
 
762
 
    for (i = 1; i <= depths[0]; i++)
763
 
    {
764
 
        for (j = 0; j < method->depthCount; j++)
765
 
            if (method->depths[j] == depths[i])
766
 
            {
767
 
                temp[0]++;
768
 
                temp[++count] = depths[i];
769
 
                break;
770
 
            }
771
 
    }
772
 
 
773
 
    memcpy (depths, temp, (count + 1) * sizeof (int));
774
 
 
775
 
    return (count);
776
 
}
777
 
 
778
 
 
779
 
#define LbxCmapAllMethod "XC-CMAP"
780
 
 
781
 
static int
782
 
LbxCmapAllOpt (LbxNegOptsPtr   pno,
783
 
               unsigned char  *popt,
784
 
               int             optlen,
785
 
               unsigned char  *preply)
786
 
 
787
 
{
788
 
    int numMethods = *popt++;
789
 
    int i;
790
 
 
791
 
    for (i = 0; i < numMethods; i++)
792
 
    {
793
 
        int len;
794
 
        char *methodName;
795
 
 
796
 
        len = *popt++;
797
 
        methodName = (char *) popt;
798
 
        popt += len;
799
 
        if (!strncmp(methodName, LbxCmapAllMethod, len))
800
 
            break;
801
 
    }
802
 
    if (i >= numMethods)
803
 
        i = 0; /* assume first one is proxy's favorite */
804
 
    *preply = i;
805
 
    return 1;
806
 
}