1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
|
/* $Xorg: options.c,v 1.4 2001/02/09 02:05:31 xorgcvs Exp $ */
/*
Copyright 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
/*
* Copyright 1994 Network Computing Devices, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name Network Computing Devices, Inc. not be
* used in advertising or publicity pertaining to distribution of this
* software without specific, written prior permission.
*
* THIS SOFTWARE IS PROVIDED `AS-IS'. NETWORK COMPUTING DEVICES, INC.,
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
* LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL NETWORK
* COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING
* SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA,
* OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
* WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
/* $XFree86: xc/programs/lbxproxy/di/options.c,v 1.7 2001/12/14 20:00:51 dawes Exp $ */
#include <stdio.h>
#include "X.h"
#include "misc.h"
#include "XLbx.h"
#include "lbxopts.h"
#include "proxyopts.h"
#include "lbximage.h"
#include "util.h"
#include "colormap.h"
#ifndef NO_ZLIB
#include "lbxzlib.h"
#endif /* NO_ZLIB */
#include "wire.h"
static int LbxDeltaReply();
static int LbxProxyDeltaReq();
static int LbxServerDeltaReq();
static int LbxStreamCompReq();
static int LbxBitmapCompReq();
static int LbxPixmapCompReq();
static int LbxSquishReq();
static int LbxUseTagsReq();
static int LbxCmapAllReq();
static int LbxProxyDeltaReply();
static int LbxServerDeltaReply();
static int LbxStreamCompReply();
static int LbxBitmapCompReply();
static int LbxPixmapCompReply();
static int LbxSquishReply();
static int LbxUseTagsReply();
static int LbxCmapAllReply();
static int OptZlibReq();
static int OptZlibReply();
#define OPT_INDEX_STREAM_COMP 2
/*
* Local variables that get set when the command line options
* are parsed.
*/
static Bool called_LbxNoComp;
static Bool called_LbxNoDelta;
static void
InitializeOptionsList (server, idx, optcode, negotiate, req, reply)
XServerPtr server;
int idx;
CARD8 optcode;
Bool negotiate;
int (*req)();
int (*reply)();
{
server->LbxOptions[idx].optcode = optcode;
server->LbxOptions[idx].negotiate = negotiate;
server->LbxOptions[idx].req = req;
server->LbxOptions[idx].reply = reply;
}
static void
InitializeDeltaOptions (server)
XServerPtr server;
{
server->proxyDeltaOpt.minN = 0;
server->proxyDeltaOpt.maxN = 0xff;
server->proxyDeltaOpt.prefN = LBX_OPT_DELTA_NCACHE_DFLT;
server->proxyDeltaOpt.minMaxMsgLen = LBX_OPT_DELTA_MSGLEN_MIN >> 2;
server->proxyDeltaOpt.maxMaxMsgLen = 0xff;
server->proxyDeltaOpt.prefMaxMsgLen = LBX_OPT_DELTA_MSGLEN_DFLT >> 2;
server->serverDeltaOpt.minN = 0;
server->serverDeltaOpt.maxN = 0xff;
server->serverDeltaOpt.prefN = LBX_OPT_DELTA_NCACHE_DFLT;
server->serverDeltaOpt.minMaxMsgLen = LBX_OPT_DELTA_MSGLEN_MIN >> 2;
server->serverDeltaOpt.maxMaxMsgLen = 0xff;
server->serverDeltaOpt.prefMaxMsgLen = LBX_OPT_DELTA_MSGLEN_DFLT >> 2;
}
static void
InitializeStreamComp (server)
XServerPtr server;
{
server->LbxStreamComp[0].typelen = ZLIB_STRCOMP_OPT_LEN;
server->LbxStreamComp[0].type = ZLIB_STRCOMP_OPT;
server->LbxStreamComp[0].req = OptZlibReq;
server->LbxStreamComp[0].reply = OptZlibReply;
}
static void
InitializeBitmapCompMethod (server)
XServerPtr server;
{
/* compression method name */
server->LbxBitmapCompMethods[0].methodName = "XC-FaxG42D";
/* inited */
server->LbxBitmapCompMethods[0].inited = 0;
/* method opcode - to be filled on reply */
server->LbxBitmapCompMethods[0].methodOpCode= -1;
/* init function */
server->LbxBitmapCompMethods[0].compInit = NULL;
/* encode function */
server->LbxBitmapCompMethods[0].compFunc = LbxImageEncodeFaxG42D;
/* decode function */
server->LbxBitmapCompMethods[0].decompFunc = LbxImageDecodeFaxG42D;
}
/*ARGSUSED*/
static void
InitializePixmapCompMethod (server)
XServerPtr server;
{
/*
* Currently, we don't support any pixmap compression algorithms
* because regular stream compression does much better than PackBits.
* If we want to plug in a better pixmap image compression algorithm,
* it would go here.
*/
#define NUM_PIXMAP_METHODS 0
}
static void
InitializeCmpaAllMethods (server)
XServerPtr server;
{
/* colormap allocation method name */
server->LbxCmapAllMethods[0].methodName = "XC-CMAP";
/* rgb resolver */
server->LbxCmapAllMethods[0].resolver = ResolveColor;
/* allocator */
server->LbxCmapAllMethods[0].findfree = FindFreePixel;
/* matcher */
server->LbxCmapAllMethods[0].findbest = FindBestPixel;
}
void
LbxOptInit(server)
XServerPtr server;
{
bzero((char *)&server->lbxNegOpt, sizeof(LbxNegOptsRec));
server->lbxNegOpt.proxyDeltaN = LBX_OPT_DELTA_NCACHE_DFLT;
server->lbxNegOpt.proxyDeltaMaxLen = LBX_OPT_DELTA_MSGLEN_DFLT;
server->lbxNegOpt.serverDeltaN = LBX_OPT_DELTA_NCACHE_DFLT;
server->lbxNegOpt.serverDeltaMaxLen = LBX_OPT_DELTA_MSGLEN_DFLT;
server->lbxNegOpt.numBitmapCompMethods = 0;
server->lbxNegOpt.bitmapCompMethods = NULL;
server->lbxNegOpt.numPixmapCompMethods = 0;
server->lbxNegOpt.pixmapCompMethods = NULL;
server->lbxNegOpt.squish = TRUE;
server->lbxNegOpt.useTags = TRUE;
/*
* Fill in the server's LbxOptions array.
*/
InitializeOptionsList (server, 0, LBX_OPT_DELTA_PROXY, TRUE,
LbxProxyDeltaReq, LbxProxyDeltaReply);
InitializeOptionsList (server, 1, LBX_OPT_DELTA_SERVER, TRUE,
LbxServerDeltaReq, LbxServerDeltaReply);
InitializeOptionsList (server, 2, LBX_OPT_STREAM_COMP, TRUE,
LbxStreamCompReq, LbxStreamCompReply);
InitializeOptionsList (server, 3, LBX_OPT_BITMAP_COMP, TRUE,
LbxBitmapCompReq, LbxBitmapCompReply);
InitializeOptionsList (server, 4, LBX_OPT_PIXMAP_COMP, TRUE,
LbxPixmapCompReq, LbxPixmapCompReply);
InitializeOptionsList (server, 5, LBX_OPT_MSG_COMP, TRUE,
LbxSquishReq, LbxSquishReply);
InitializeOptionsList (server, 6, LBX_OPT_USE_TAGS, TRUE,
LbxUseTagsReq, LbxUseTagsReply);
InitializeOptionsList (server, 7, LBX_OPT_CMAP_ALL, TRUE,
LbxCmapAllReq, LbxCmapAllReply);
InitializeDeltaOptions (server);
InitializeStreamComp (server);
InitializeBitmapCompMethod (server);
InitializePixmapCompMethod (server);
InitializeCmpaAllMethods (server);
/*
* Now update this server's LbxOptions that were set when
* command line was parsed.
*/
if (called_LbxNoComp)
server->LbxOptions[OPT_INDEX_STREAM_COMP].negotiate = FALSE;
if (called_LbxNoDelta) {
server->proxyDeltaOpt.prefN = 0;
server->serverDeltaOpt.prefN = 0;
}
}
int
LbxOptBuildReq(server, buf)
XServerPtr server;
register char *buf;
{
int i;
char *bufstart = buf;
char *pnopts = buf++;
server->optcount = 0;
for (i = 0; i < (sizeof(server->LbxOptions) / sizeof (LbxOptionsListRec));
i++) {
int reqlen;
if (server->LbxOptions[i].negotiate) {
reqlen = (*server->LbxOptions[i].req) (server,
buf + LBX_OPT_SMALLHDR_LEN);
*buf++ = server->LbxOptions[i].optcode;
*buf++ = LBX_OPT_SMALLHDR_LEN + reqlen;
buf += reqlen;
server->optlist[server->optcount++] = i;
}
}
*pnopts = server->optcount;
return (buf - bufstart);
}
int
LbxOptParseReply(server, nopts, preply, replylen)
XServerPtr server;
int nopts;
unsigned char *preply;
int replylen;
{
int i;
for (i = 0; i < nopts; i++) {
int len;
int hdrlen;
int result;
int optindex = *preply;
if (optindex >= server->optcount)
return -1;
LBX_OPT_DECODE_LEN(preply + 1, len, hdrlen);
if (len < ++hdrlen || len > replylen) {
#ifdef OPTDEBUG
fprintf(stderr, "bad length, len = %d, hdrlen = %d, optlen = %d\n",
len, hdrlen, replylen);
#endif
return -1;
}
result = (*server->LbxOptions[server->optlist[optindex]].reply) (server,
preply + hdrlen, len - hdrlen);
if (result < 0)
return -1;
preply += len;
replylen -= len;
}
return 0;
}
void
LbxNoDelta()
{
/*
* All we can do now is to flag that this was called
* since the associated server structure may not be
* initialized.
*/
called_LbxNoDelta = TRUE;
}
static int
LbxProxyDeltaReq(server, buf)
XServerPtr server;
unsigned char *buf;
{
memcpy(buf, (char *)&server->proxyDeltaOpt, sizeof(LbxDeltaOptionsRec));
return LBX_OPT_DELTA_REQLEN;
}
static int
LbxServerDeltaReq(server, buf)
XServerPtr server;
unsigned char *buf;
{
memcpy(buf, (char *)&server->serverDeltaOpt, sizeof(LbxDeltaOptionsRec));
return LBX_OPT_DELTA_REQLEN;
}
static int
LbxProxyDeltaReply(server, preply, replylen)
XServerPtr server;
unsigned char *preply;
int replylen;
{
return LbxDeltaReply(preply,
replylen,
&server->lbxNegOpt.proxyDeltaN,
&server->lbxNegOpt.proxyDeltaMaxLen);
}
static int
LbxServerDeltaReply(server, preply, replylen)
XServerPtr server;
unsigned char *preply;
int replylen;
{
return LbxDeltaReply(preply,
replylen,
&server->lbxNegOpt.serverDeltaN,
&server->lbxNegOpt.serverDeltaMaxLen);
}
static int
LbxDeltaReply(preply, replylen, pn, pmaxlen)
unsigned char *preply;
int replylen;
short *pn;
short *pmaxlen;
{
if (replylen < 2)
return -1;
*pn = *preply++;
*pmaxlen = *preply;
if ((*pmaxlen <<= 2) == 0)
*pn = 0;
else if (*pmaxlen < 32) {
#ifdef DEBUG
printf("bad delta max msg length %d\n", *pmaxlen);
#endif
return -1;
}
return 0;
}
void
LbxNoComp()
{
/*
* All we can do now is to flag that this was called
* since the associated server structure may not be
* initialized.
*/
called_LbxNoComp = TRUE;
}
static int
LbxStreamCompReq(server, buf)
XServerPtr server;
unsigned char *buf;
{
int i;
int reqlen;
int LBX_N_STRCOMP;
LBX_N_STRCOMP = sizeof (server->LbxStreamComp) /
sizeof (LbxStreamCompRec);
*buf++ = LBX_N_STRCOMP;
reqlen = 1;
for (i = 0; i < LBX_N_STRCOMP; i++) {
int optdatalen;
int typelen = server->LbxStreamComp[i].typelen;
*buf++ = typelen;
memcpy(buf, server->LbxStreamComp[i].type, typelen);
buf += typelen;
reqlen += 1 + typelen;
optdatalen = (*server->LbxStreamComp[i].req) (server, buf + 1);
*buf = optdatalen + 1;
buf += optdatalen + 1;
reqlen += optdatalen + 1;
}
return reqlen;
}
static int
LbxStreamCompReply(server, preply, replylen)
XServerPtr server;
unsigned char *preply;
int replylen;
{
int optindex;
int LBX_N_STRCOMP;
LBX_N_STRCOMP = sizeof(server->LbxStreamComp) /
sizeof (LbxStreamCompRec);
if (replylen < 1 || (optindex = *preply) >= LBX_N_STRCOMP)
return -1;
return (*server->LbxStreamComp[optindex].reply) (server,
preply + 1,
replylen - 1);
}
extern int zlevel;
/*ARGSUSED*/
static int
OptZlibReq(server, buf)
XServerPtr server;
unsigned char *buf;
{
*buf++ = 1; /* len */
*buf = zlevel;
return (2);
}
extern LbxStreamCompHandle ZlibInit();
extern int ZlibStuffInput(), ZlibInputAvail(), ZlibFlush(),
ZlibRead(), ZlibWriteV();
extern void ZlibCompressOn(), ZlibCompressOff(), ZlibFree();
/*ARGSUSED*/
static int
OptZlibReply(server, preply, replylen)
XServerPtr server;
unsigned char *preply;
int replylen;
{
server->lbxNegOpt.streamOpts.streamCompInit =
(LbxStreamCompHandle (*)(int, pointer))ZlibInit;
server->lbxNegOpt.streamOpts.streamCompArg = (pointer)(long) zlevel;
server->lbxNegOpt.streamOpts.streamCompStuffInput = ZlibStuffInput;
server->lbxNegOpt.streamOpts.streamCompInputAvail = ZlibInputAvail;
server->lbxNegOpt.streamOpts.streamCompFlush = ZlibFlush;
server->lbxNegOpt.streamOpts.streamCompRead = ZlibRead;
server->lbxNegOpt.streamOpts.streamCompWriteV = ZlibWriteV;
server->lbxNegOpt.streamOpts.streamCompOn = ZlibCompressOn;
server->lbxNegOpt.streamOpts.streamCompOff = ZlibCompressOff;
server->lbxNegOpt.streamOpts.streamCompFreeHandle =
(void (*)(LbxStreamCompHandle))ZlibFree;
return 0;
}
Bool lbxDoSquishing = TRUE;
/*ARGSUSED*/
static int
LbxSquishReq(server, buf)
XServerPtr server;
unsigned char *buf;
{
*buf = lbxDoSquishing;
return 1;
}
static int
LbxSquishReply(server, preply, replylen)
XServerPtr server;
unsigned char *preply;
int replylen;
{
if (replylen < 1)
return -1;
server->lbxNegOpt.squish = *preply;
return 0;
}
Bool lbxUseTags = TRUE;
/*ARGSUSED*/
static int
LbxUseTagsReq(server, buf)
XServerPtr server;
unsigned char *buf;
{
*buf = lbxUseTags;
return 1;
}
static int
LbxUseTagsReply(server, preply, replylen)
XServerPtr server;
unsigned char *preply;
int replylen;
{
if (replylen < 1)
return -1;
server->lbxNegOpt.useTags = *preply;
return 0;
}
/*
* Option negotiation for image compression
*/
static int
LbxBitmapCompReq (server, buf)
XServerPtr server;
unsigned char *buf;
{
unsigned char *bufStart = buf;
int i;
int NUM_BITMAP_METHODS;
NUM_BITMAP_METHODS = sizeof(server->LbxBitmapCompMethods) /
sizeof (LbxBitmapCompMethod);
*buf++ = NUM_BITMAP_METHODS;
for (i = 0; i < NUM_BITMAP_METHODS; i++)
{
int len = strlen (server->LbxBitmapCompMethods[i].methodName);
*buf++ = len;
memcpy (buf, server->LbxBitmapCompMethods[i].methodName, len);
buf += len;
}
return (buf - bufStart);
}
/*ARGSUSED*/
static int
LbxBitmapCompReply (server, preply, replylen)
XServerPtr server;
unsigned char *preply;
int replylen;
{
int count = *preply++;
int i;
server->lbxNegOpt.numBitmapCompMethods = count;
if (count > 0)
{
server->lbxNegOpt.bitmapCompMethods = (char *) xalloc (count);
if (server->lbxNegOpt.bitmapCompMethods == NULL)
{
server->lbxNegOpt.numBitmapCompMethods = 0;
return -1;
}
}
for (i = 0; i < count; i++)
{
int index = *preply++;
server->lbxNegOpt.bitmapCompMethods[i] = index;
server->LbxBitmapCompMethods[index].methodOpCode = *preply++;
}
return 0;
}
static int
LbxPixmapCompReq (server, buf)
XServerPtr server;
unsigned char *buf;
{
unsigned char *bufStart = buf;
int i, j;
*buf++ = NUM_PIXMAP_METHODS;
for (i = 0; i < NUM_PIXMAP_METHODS; i++)
{
int len = strlen (server->LbxPixmapCompMethods[i].methodName);
*buf++ = len;
memcpy (buf, server->LbxPixmapCompMethods[i].methodName, len);
buf += len;
*buf++ = server->LbxPixmapCompMethods[i].formatMask;
*buf++ = server->LbxPixmapCompMethods[i].depthCount;
for (j = 0; j < server->LbxPixmapCompMethods[i].depthCount; j++)
*buf++ = server->LbxPixmapCompMethods[i].depths[j];
}
return (buf - bufStart);
}
/*ARGSUSED*/
static int
LbxPixmapCompReply (server, preply, replylen)
XServerPtr server;
unsigned char *preply;
int replylen;
{
int count = *preply++;
int i, j;
server->lbxNegOpt.numPixmapCompMethods = count;
if (count > 0)
{
server->lbxNegOpt.pixmapCompMethods = (char *) xalloc (count);
if (server->lbxNegOpt.pixmapCompMethods == NULL)
{
server->lbxNegOpt.numPixmapCompMethods = 0;
return -1;
}
}
for (i = 0; i < count; i++)
{
int index = *preply++;
server->lbxNegOpt.pixmapCompMethods[i] = index;
server->LbxPixmapCompMethods[index].methodOpCode = *preply++;
server->LbxPixmapCompMethods[index].formatMask = *preply++;
server->LbxPixmapCompMethods[index].depthCount = *preply++;
for (j = 0; j < server->LbxPixmapCompMethods[index].depthCount; j++)
server->LbxPixmapCompMethods[index].depths[j] = *preply++;
}
return 0;
}
LbxBitmapCompMethod *
LbxLookupBitmapCompMethod (server, methodOpCode)
XServerPtr server;
int methodOpCode;
{
int i;
for (i = 0; i < server->lbxNegOpt.numBitmapCompMethods; i++)
{
LbxBitmapCompMethod *method;
method = &server->LbxBitmapCompMethods[server->lbxNegOpt.bitmapCompMethods[i]];
if (method->methodOpCode == methodOpCode)
return (method);
}
return (NULL);
}
LbxPixmapCompMethod *
LbxLookupPixmapCompMethod (server, methodOpCode)
XServerPtr server;
int methodOpCode;
{
int i;
for (i = 0; i < server->lbxNegOpt.numPixmapCompMethods; i++)
{
LbxPixmapCompMethod *method;
method = &server->LbxPixmapCompMethods[server->lbxNegOpt.pixmapCompMethods[i]];
if (method->methodOpCode == methodOpCode)
return (method);
}
return (NULL);
}
LbxBitmapCompMethod *
LbxFindPreferredBitmapCompMethod (server)
XServerPtr server;
{
if (server->lbxNegOpt.numBitmapCompMethods == 0)
return NULL;
else
return (&server->LbxBitmapCompMethods[server->lbxNegOpt.bitmapCompMethods[0]]);
}
LbxPixmapCompMethod *
LbxFindPreferredPixmapCompMethod (server, format, depth)
XServerPtr server;
int format;
int depth;
{
if (server->lbxNegOpt.numPixmapCompMethods == 0)
return NULL;
else
{
LbxPixmapCompMethod *method;
int i, j;
for (i = 0; i < server->lbxNegOpt.numPixmapCompMethods; i++)
{
method = &server->LbxPixmapCompMethods[server->lbxNegOpt.pixmapCompMethods[i]];
if ((method->formatMask & (1 << format)))
{
for (j = 0; j < method->depthCount; j++)
if (depth == method->depths[j])
return method;
}
}
return NULL;
}
}
/*
* Colormap methods
*/
static int
LbxCmapAllReq (server, buf)
XServerPtr server;
unsigned char *buf;
{
unsigned char *bufStart = buf;
int i;
int NUM_CMAP_METHODS;
NUM_CMAP_METHODS = sizeof (server->LbxCmapAllMethods) /
sizeof (LbxCmapAllMethod);
*buf++ = NUM_CMAP_METHODS;
for (i = 0; i < NUM_CMAP_METHODS; i++)
{
int len = strlen (server->LbxCmapAllMethods[i].methodName);
*buf++ = len;
memcpy (buf, server->LbxCmapAllMethods[i].methodName, len);
buf += len;
}
return (buf - bufStart);
}
static int
LbxCmapAllReply(server, preply, replylen)
XServerPtr server;
unsigned char *preply;
int replylen;
{
int NUM_CMAP_METHODS;
NUM_CMAP_METHODS = sizeof (server->LbxCmapAllMethods) /
sizeof (LbxCmapAllMethod);
if (replylen < 1)
return -1;
if (*preply < NUM_CMAP_METHODS) {
LbxResolveColor = server->LbxCmapAllMethods[*preply].resolver;
LbxFindFreePixel = server->LbxCmapAllMethods[*preply].findfree;
LbxFindBestPixel = server->LbxCmapAllMethods[*preply].findbest;
}
return 0;
}
|