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#include "glxserver.h" 32#include "glxutil.h" 33#include <GL/glxtokens.h> 34#include <g_disptab.h> 35#include <pixmapstr.h> 36#include <windowstr.h> 37#include "unpack.h" 38#include "glxcmds.h" 39#include "glxext.h" 40#include "glxvendor.h" 41 42extern int glxIsExtensionSupported( char *ext ); 43 44int __glXSwapGetFBConfigsSGIX(__GLXclientState *cl, GLbyte *pc); 45 46/************************************************************************/ 47 48/* 49** Byteswapping versions of GLX commands. In most cases they just swap 50** the incoming arguments and then call the unswapped routine. For commands 51** that have replies, a separate swapping routine for the reply is provided; 52** it is called at the end of the unswapped routine. 53*/ 54 55int __glXSwapCreateContext(__GLXclientState *cl, GLbyte *pc) 56{ 57 xGLXCreateContextReq *req = (xGLXCreateContextReq *) pc; 58 __GLX_DECLARE_SWAP_VARIABLES; 59 60 __GLX_SWAP_SHORT(&req->length); 61 __GLX_SWAP_INT(&req->context); 62 __GLX_SWAP_INT(&req->visual); 63 __GLX_SWAP_INT(&req->screen); 64 __GLX_SWAP_INT(&req->shareList); 65 66 return __glXCreateContext(cl, pc); 67} 68 69int __glXSwapCreateNewContext(__GLXclientState *cl, GLbyte *pc) 70{ 71 xGLXCreateNewContextReq *req = (xGLXCreateNewContextReq *) pc; 72 __GLX_DECLARE_SWAP_VARIABLES; 73 74 __GLX_SWAP_SHORT(&req->length); 75 __GLX_SWAP_INT(&req->context); 76 __GLX_SWAP_INT(&req->fbconfig); 77 __GLX_SWAP_INT(&req->screen); 78 __GLX_SWAP_INT(&req->shareList); 79 80 return __glXCreateNewContext(cl, pc); 81} 82 83int __glXSwapCreateContextWithConfigSGIX(__GLXclientState *cl, GLbyte *pc) 84{ 85 xGLXCreateContextWithConfigSGIXReq *req = (xGLXCreateContextWithConfigSGIXReq *) pc; 86 __GLX_DECLARE_SWAP_VARIABLES; 87 88 __GLX_SWAP_SHORT(&req->length); 89 __GLX_SWAP_INT(&req->context); 90 __GLX_SWAP_INT(&req->fbconfig); 91 __GLX_SWAP_INT(&req->screen); 92 __GLX_SWAP_INT(&req->shareList); 93 94 return __glXCreateContextWithConfigSGIX(cl, pc); 95} 96 97int __glXSwapQueryMaxSwapBarriersSGIX(__GLXclientState *cl, GLbyte *pc) 98{ 99 xGLXQueryMaxSwapBarriersSGIXReq *req = 100 (xGLXQueryMaxSwapBarriersSGIXReq *)pc; 101 __GLX_DECLARE_SWAP_VARIABLES; 102 103 __GLX_SWAP_SHORT(&req->length); 104 __GLX_SWAP_INT(&req->screen); 105 106 return __glXQueryMaxSwapBarriersSGIX(cl, pc); 107} 108 109int __glXSwapBindSwapBarrierSGIX(__GLXclientState *cl, GLbyte *pc) 110{ 111 xGLXBindSwapBarrierSGIXReq *req = (xGLXBindSwapBarrierSGIXReq *)pc; 112 __GLX_DECLARE_SWAP_VARIABLES; 113 114 __GLX_SWAP_SHORT(&req->length); 115 __GLX_SWAP_INT(&req->drawable); 116 __GLX_SWAP_INT(&req->barrier); 117 118 return __glXBindSwapBarrierSGIX(cl, pc); 119} 120 121int __glXSwapJoinSwapGroupSGIX(__GLXclientState *cl, GLbyte *pc) 122{ 123 xGLXJoinSwapGroupSGIXReq *req = (xGLXJoinSwapGroupSGIXReq *)pc; 124 __GLX_DECLARE_SWAP_VARIABLES; 125 126 __GLX_SWAP_SHORT(&req->length); 127 __GLX_SWAP_INT(&req->drawable); 128 __GLX_SWAP_INT(&req->member); 129 130 return __glXJoinSwapGroupSGIX(cl, pc); 131} 132 133int __glXSwapDestroyContext(__GLXclientState *cl, GLbyte *pc) 134{ 135 xGLXDestroyContextReq *req = (xGLXDestroyContextReq *) pc; 136 __GLX_DECLARE_SWAP_VARIABLES; 137 138 __GLX_SWAP_SHORT(&req->length); 139 __GLX_SWAP_INT(&req->context); 140 141 return __glXDestroyContext(cl, pc); 142} 143 144int __glXSwapMakeCurrent(__GLXclientState *cl, GLbyte *pc) 145{ 146 xGLXMakeCurrentReq *req = (xGLXMakeCurrentReq *) pc; 147 __GLX_DECLARE_SWAP_VARIABLES; 148 149 __GLX_SWAP_SHORT(&req->length); 150 __GLX_SWAP_INT(&req->drawable); 151 __GLX_SWAP_INT(&req->context); 152 __GLX_SWAP_INT(&req->oldContextTag); 153 154 return __glXMakeCurrent(cl, pc); 155} 156 157int __glXSwapMakeContextCurrent(__GLXclientState *cl, GLbyte *pc) 158{ 159 xGLXMakeContextCurrentReq *req = (xGLXMakeContextCurrentReq *) pc; 160 __GLX_DECLARE_SWAP_VARIABLES; 161 162 __GLX_SWAP_SHORT(&req->length); 163 __GLX_SWAP_INT(&req->drawable); 164 __GLX_SWAP_INT(&req->readdrawable); 165 __GLX_SWAP_INT(&req->context); 166 __GLX_SWAP_INT(&req->oldContextTag); 167 168 return __glXMakeContextCurrent(cl, pc); 169} 170 171int __glXSwapMakeCurrentReadSGI(__GLXclientState *cl, GLbyte *pc) 172{ 173 xGLXMakeCurrentReadSGIReq *req = (xGLXMakeCurrentReadSGIReq *) pc; 174 __GLX_DECLARE_SWAP_VARIABLES; 175 176 __GLX_SWAP_SHORT(&req->length); 177 __GLX_SWAP_INT(&req->drawable); 178 __GLX_SWAP_INT(&req->readable); 179 __GLX_SWAP_INT(&req->context); 180 __GLX_SWAP_INT(&req->oldContextTag); 181 182 return __glXMakeCurrentReadSGI(cl, pc); 183} 184 185int __glXSwapIsDirect(__GLXclientState *cl, GLbyte *pc) 186{ 187 xGLXIsDirectReq *req = (xGLXIsDirectReq *) pc; 188 __GLX_DECLARE_SWAP_VARIABLES; 189 190 __GLX_SWAP_SHORT(&req->length); 191 __GLX_SWAP_INT(&req->context); 192 193 return __glXIsDirect(cl, pc); 194} 195 196int __glXSwapQueryVersion(__GLXclientState *cl, GLbyte *pc) 197{ 198 xGLXQueryVersionReq *req = (xGLXQueryVersionReq *) pc; 199 __GLX_DECLARE_SWAP_VARIABLES; 200 201 __GLX_SWAP_SHORT(&req->length); 202 __GLX_SWAP_INT(&req->majorVersion); 203 __GLX_SWAP_INT(&req->minorVersion); 204 205 return __glXQueryVersion(cl, pc); 206} 207 208int __glXSwapWaitGL(__GLXclientState *cl, GLbyte *pc) 209{ 210 xGLXWaitGLReq *req = (xGLXWaitGLReq *) pc; 211 __GLX_DECLARE_SWAP_VARIABLES; 212 213 __GLX_SWAP_SHORT(&req->length); 214 __GLX_SWAP_INT(&req->contextTag); 215 216 return __glXWaitGL(cl, pc); 217} 218 219int __glXSwapWaitX(__GLXclientState *cl, GLbyte *pc) 220{ 221 xGLXWaitXReq *req = (xGLXWaitXReq *) pc; 222 __GLX_DECLARE_SWAP_VARIABLES; 223 224 __GLX_SWAP_SHORT(&req->length); 225 __GLX_SWAP_INT(&req->contextTag); 226 227 return __glXWaitX(cl, pc); 228} 229 230int __glXSwapCopyContext(__GLXclientState *cl, GLbyte *pc) 231{ 232 xGLXCopyContextReq *req = (xGLXCopyContextReq *) pc; 233 __GLX_DECLARE_SWAP_VARIABLES; 234 235 __GLX_SWAP_SHORT(&req->length); 236 __GLX_SWAP_INT(&req->source); 237 __GLX_SWAP_INT(&req->dest); 238 __GLX_SWAP_INT(&req->mask); 239 240 return __glXCopyContext(cl, pc); 241} 242 243int __glXSwapGetVisualConfigs(__GLXclientState *cl, GLbyte *pc) 244{ 245 ClientPtr client = cl->client; 246 xGLXGetVisualConfigsReq *req = (xGLXGetVisualConfigsReq *) pc; 247 xGLXGetVisualConfigsReply reply; 248 __GLXscreenInfo *pGlxScreen; 249 __GLXvisualConfig *pGlxVisual; 250 CARD32 buf[__GLX_TOTAL_CONFIG]; 251 unsigned int screen; 252 int i, p; 253 __GLX_DECLARE_SWAP_VARIABLES; 254 __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 255 256 __GLX_SWAP_INT(&req->screen); 257 screen = req->screen; 258 if (screen >= screenInfo.numScreens) { 259 /* The client library must send a valid screen number. */ 260 client->errorValue = screen; 261 return BadValue; 262 } 263 pGlxScreen = &__glXActiveScreens[screen]; 264 265 reply.numVisuals = pGlxScreen->numGLXVisuals; 266 reply.numProps = __GLX_TOTAL_CONFIG; 267 reply.length = (pGlxScreen->numGLXVisuals * __GLX_SIZE_CARD32 * 268 __GLX_TOTAL_CONFIG) >> 2; 269 reply.type = X_Reply; 270 reply.sequenceNumber = client->sequence; 271 272 __GLX_SWAP_SHORT(&reply.sequenceNumber); 273 __GLX_SWAP_INT(&reply.length); 274 __GLX_SWAP_INT(&reply.numVisuals); 275 __GLX_SWAP_INT(&reply.numProps); 276 WriteToClient(client, sz_xGLXGetVisualConfigsReply, (char *)&reply); 277 278 for (i=0; i < pGlxScreen->numVisuals; i++) { 279 pGlxVisual = &pGlxScreen->pGlxVisual[i]; 280 if (!pGlxScreen->isGLXvis[i] || pGlxVisual->vid == 0) { 281 /* not a usable visual */ 282 continue; 283 } 284 p = 0; 285 buf[p++] = pGlxVisual->vid; 286 buf[p++] = pGlxVisual->class; 287 buf[p++] = pGlxVisual->rgba; 288 289 buf[p++] = pGlxVisual->redSize; 290 buf[p++] = pGlxVisual->greenSize; 291 buf[p++] = pGlxVisual->blueSize; 292 buf[p++] = pGlxVisual->alphaSize; 293 buf[p++] = pGlxVisual->accumRedSize; 294 buf[p++] = pGlxVisual->accumGreenSize; 295 buf[p++] = pGlxVisual->accumBlueSize; 296 buf[p++] = pGlxVisual->accumAlphaSize; 297 298 buf[p++] = pGlxVisual->doubleBuffer; 299 buf[p++] = pGlxVisual->stereo; 300 301 buf[p++] = pGlxVisual->bufferSize; 302 buf[p++] = pGlxVisual->depthSize; 303 buf[p++] = pGlxVisual->stencilSize; 304 buf[p++] = pGlxVisual->auxBuffers; 305 buf[p++] = pGlxVisual->level; 306 /* 307 ** Add token/value pairs for extensions. 308 */ 309 buf[p++] = GLX_VISUAL_CAVEAT_EXT; 310 buf[p++] = pGlxVisual->visualRating; 311 buf[p++] = GLX_TRANSPARENT_TYPE_EXT; 312 buf[p++] = pGlxVisual->transparentPixel; 313 buf[p++] = GLX_TRANSPARENT_RED_VALUE_EXT; 314 buf[p++] = pGlxVisual->transparentRed; 315 buf[p++] = GLX_TRANSPARENT_GREEN_VALUE_EXT; 316 buf[p++] = pGlxVisual->transparentGreen; 317 buf[p++] = GLX_TRANSPARENT_BLUE_VALUE_EXT; 318 buf[p++] = pGlxVisual->transparentBlue; 319 buf[p++] = GLX_TRANSPARENT_ALPHA_VALUE_EXT; 320 buf[p++] = pGlxVisual->transparentAlpha; 321 buf[p++] = GLX_TRANSPARENT_INDEX_VALUE_EXT; 322 buf[p++] = pGlxVisual->transparentIndex; 323 324 __GLX_SWAP_INT_ARRAY(buf, __GLX_TOTAL_CONFIG); 325 WriteToClient(client, __GLX_SIZE_CARD32 * __GLX_TOTAL_CONFIG, 326 (char *)buf); 327 } 328 return Success; 329} 330 331int __glXSwapCreateGLXPixmap(__GLXclientState *cl, GLbyte *pc) 332{ 333 xGLXCreateGLXPixmapReq *req = (xGLXCreateGLXPixmapReq *) pc; 334 __GLX_DECLARE_SWAP_VARIABLES; 335 336 __GLX_SWAP_SHORT(&req->length); 337 __GLX_SWAP_INT(&req->screen); 338 __GLX_SWAP_INT(&req->visual); 339 __GLX_SWAP_INT(&req->pixmap); 340 __GLX_SWAP_INT(&req->glxpixmap); 341 342 return __glXCreateGLXPixmap(cl, pc); 343} 344 345int __glXSwapCreatePixmap(__GLXclientState *cl, GLbyte *pc) 346{ 347 xGLXCreatePixmapReq *req = (xGLXCreatePixmapReq *) pc; 348 __GLX_DECLARE_SWAP_VARIABLES; 349 350 __GLX_SWAP_SHORT(&req->length); 351 __GLX_SWAP_INT(&req->screen); 352 __GLX_SWAP_INT(&req->fbconfig); 353 __GLX_SWAP_INT(&req->pixmap); 354 __GLX_SWAP_INT(&req->glxpixmap); 355 __GLX_SWAP_INT(&req->numAttribs); 356 357 return __glXCreatePixmap(cl, pc); 358} 359 360int __glXSwapDestroyGLXPixmap(__GLXclientState *cl, GLbyte *pc) 361{ 362 xGLXDestroyGLXPixmapReq *req = (xGLXDestroyGLXPixmapReq *) pc; 363 __GLX_DECLARE_SWAP_VARIABLES; 364 365 __GLX_SWAP_SHORT(&req->length); 366 __GLX_SWAP_INT(&req->glxpixmap); 367 368 return __glXDestroyGLXPixmap(cl, pc); 369} 370 371int __glXSwapSwapBuffers(__GLXclientState *cl, GLbyte *pc) 372{ 373 xGLXSwapBuffersReq *req = (xGLXSwapBuffersReq *) pc; 374 __GLX_DECLARE_SWAP_VARIABLES; 375 376 __GLX_SWAP_SHORT(&req->length); 377 __GLX_SWAP_INT(&req->contextTag); 378 __GLX_SWAP_INT(&req->drawable); 379 380 return __glXSwapBuffers(cl, pc); 381} 382 383int __glXSwapUseXFont(__GLXclientState *cl, GLbyte *pc) 384{ 385 xGLXUseXFontReq *req = (xGLXUseXFontReq *) pc; 386 __GLX_DECLARE_SWAP_VARIABLES; 387 388 __GLX_SWAP_SHORT(&req->length); 389 __GLX_SWAP_INT(&req->contextTag); 390 __GLX_SWAP_INT(&req->font); 391 __GLX_SWAP_INT(&req->first); 392 __GLX_SWAP_INT(&req->count); 393 __GLX_SWAP_INT(&req->listBase); 394 395 return __glXUseXFont(cl, pc); 396} 397 398 399int __glXSwapQueryExtensionsString(__GLXclientState *cl, GLbyte *pc) 400{ 401 xGLXQueryExtensionsStringReq *req = NULL; 402 __GLX_DECLARE_SWAP_VARIABLES; 403 404 __GLX_SWAP_SHORT(&req->length); 405 __GLX_SWAP_INT(&req->screen); 406 407 return __glXQueryExtensionsString(cl, pc); 408} 409 410int __glXSwapQueryServerString(__GLXclientState *cl, GLbyte *pc) 411{ 412 xGLXQueryServerStringReq *req = (xGLXQueryServerStringReq *)pc; 413 __GLX_DECLARE_SWAP_VARIABLES; 414 415 __GLX_SWAP_SHORT(&req->length); 416 __GLX_SWAP_INT(&req->screen); 417 __GLX_SWAP_INT(&req->name); 418 419 return __glXQueryServerString(cl, pc); 420} 421 422int __glXSwapClientInfo(__GLXclientState *cl, GLbyte *pc) 423{ 424 xGLXClientInfoReq *req = (xGLXClientInfoReq *)pc; 425 __GLX_DECLARE_SWAP_VARIABLES; 426 427 __GLX_SWAP_SHORT(&req->length); 428 __GLX_SWAP_INT(&req->major); 429 __GLX_SWAP_INT(&req->minor); 430 __GLX_SWAP_INT(&req->numbytes); 431 432 return __glXClientInfo(cl, pc); 433} 434 435int __glXSwapQueryContextInfoEXT(__GLXclientState *cl, char *pc) 436{ 437 xGLXQueryContextInfoEXTReq *req = (xGLXQueryContextInfoEXTReq *) pc; 438 __GLX_DECLARE_SWAP_VARIABLES; 439 440 __GLX_SWAP_SHORT(&req->length); 441 __GLX_SWAP_INT(&req->context); 442 443 return __glXQueryContextInfoEXT(cl, (GLbyte *)pc); 444} 445 446/************************************************************************/ 447 448/* 449** Swap replies. 450*/ 451 452void __glXSwapMakeCurrentReply(ClientPtr client, xGLXMakeCurrentReadSGIReply *reply) 453{ 454 __GLX_DECLARE_SWAP_VARIABLES; 455 __GLX_SWAP_SHORT(&reply->sequenceNumber); 456 __GLX_SWAP_INT(&reply->length); 457 __GLX_SWAP_INT(&reply->contextTag); 458 __GLX_SWAP_INT(&reply->writeVid); 459 __GLX_SWAP_INT(&reply->writeType); 460 __GLX_SWAP_INT(&reply->readVid); 461 __GLX_SWAP_INT(&reply->readType); 462 WriteToClient(client, sz_xGLXMakeCurrentReadSGIReply, (char *)reply); 463} 464 465void __glXSwapIsDirectReply(ClientPtr client, xGLXIsDirectReply *reply) 466{ 467 __GLX_DECLARE_SWAP_VARIABLES; 468 __GLX_SWAP_SHORT(&reply->sequenceNumber); 469 __GLX_SWAP_INT(&reply->length); 470 WriteToClient(client, sz_xGLXIsDirectReply, (char *)reply); 471} 472 473void __glXSwapQueryVersionReply(ClientPtr client, xGLXQueryVersionReply *reply) 474{ 475 __GLX_DECLARE_SWAP_VARIABLES; 476 __GLX_SWAP_SHORT(&reply->sequenceNumber); 477 __GLX_SWAP_INT(&reply->length); 478 __GLX_SWAP_INT(&reply->majorVersion); 479 __GLX_SWAP_INT(&reply->minorVersion); 480 WriteToClient(client, sz_xGLXQueryVersionReply, (char *)reply); 481} 482 483void glxSwapQueryExtensionsStringReply(ClientPtr client, 484 xGLXQueryExtensionsStringReply *reply, char *buf) 485{ 486 int length = reply->length; 487 __GLX_DECLARE_SWAP_VARIABLES; 488 __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 489 __GLX_SWAP_SHORT(&reply->sequenceNumber); 490 __GLX_SWAP_INT(&reply->length); 491 __GLX_SWAP_INT(&reply->n); 492 WriteToClient(client, sz_xGLXQueryExtensionsStringReply, (char *)reply); 493 __GLX_SWAP_INT_ARRAY((int *)buf, length); 494 WriteToClient(client, length << 2, buf); 495} 496 497void glxSwapQueryServerStringReply(ClientPtr client, 498 xGLXQueryServerStringReply *reply, char *buf) 499{ 500 int length = reply->length; 501 __GLX_DECLARE_SWAP_VARIABLES; 502 __GLX_SWAP_SHORT(&reply->sequenceNumber); 503 __GLX_SWAP_INT(&reply->length); 504 __GLX_SWAP_INT(&reply->n); 505 WriteToClient(client, sz_xGLXQueryServerStringReply, (char *)reply); 506 /** no swap is needed for an array of chars **/ 507 /* __GLX_SWAP_INT_ARRAY((int *)buf, length); */ 508 WriteToClient(client, length << 2, buf); 509} 510 511void __glXSwapQueryContextInfoEXTReply(ClientPtr client, xGLXQueryContextInfoEXTReply *reply, int *buf) 512{ 513 int length = reply->length; 514 __GLX_DECLARE_SWAP_VARIABLES; 515 __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 516 __GLX_SWAP_SHORT(&reply->sequenceNumber); 517 __GLX_SWAP_INT(&reply->length); 518 __GLX_SWAP_INT(&reply->n); 519 WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, (char *)reply); 520 __GLX_SWAP_INT_ARRAY((int *)buf, length); 521 WriteToClient(client, length << 2, (char *)buf); 522} 523 524 525void __glXSwapQueryContextReply(ClientPtr client, 526 xGLXQueryContextReply *reply, int *buf) 527{ 528 int length = reply->length; 529 __GLX_DECLARE_SWAP_VARIABLES; 530 __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 531 __GLX_SWAP_SHORT(&reply->sequenceNumber); 532 __GLX_SWAP_INT(&reply->length); 533 __GLX_SWAP_INT(&reply->n); 534 WriteToClient(client, sz_xGLXQueryContextReply, (char *)reply); 535 __GLX_SWAP_INT_ARRAY((int *)buf, length); 536 WriteToClient(client, length << 2, (char *)buf); 537} 538 539void __glXSwapGetDrawableAttributesReply(ClientPtr client, 540 xGLXGetDrawableAttributesReply *reply, int *buf) 541{ 542 __GLX_DECLARE_SWAP_VARIABLES; 543 __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 544 __GLX_SWAP_SHORT(&reply->sequenceNumber); 545 __GLX_SWAP_INT(&reply->length); 546 __GLX_SWAP_INT(&reply->numAttribs); 547 __GLX_SWAP_INT_ARRAY( buf, reply->length ); 548 WriteToClient(client, sz_xGLXGetDrawableAttributesReply, (char *)reply); 549 WriteToClient(client, reply->length << 2, (char *)buf); 550} 551 552void __glXSwapQueryMaxSwapBarriersSGIXReply(ClientPtr client, xGLXQueryMaxSwapBarriersSGIXReply *reply) 553{ 554 __GLX_DECLARE_SWAP_VARIABLES; 555 __GLX_SWAP_SHORT(&reply->sequenceNumber); 556 __GLX_SWAP_INT(&reply->length); 557 __GLX_SWAP_INT(&reply->max); 558 WriteToClient(client, sz_xGLXQueryMaxSwapBarriersSGIXReply, (char *)reply); 559} 560 561/************************************************************************/ 562 563/* 564** Render and Renderlarge are not in the GLX API. They are used by the GLX 565** client library to send batches of GL rendering commands. 566*/ 567 568int __glXSwapRender(__GLXclientState *cl, GLbyte *pc) 569{ 570 xGLXRenderReq *req; 571 int left; 572 __GLXrenderHeader *hdr; 573 ClientPtr client = cl->client; 574 __GLX_DECLARE_SWAP_VARIABLES; 575 __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 576 577 /* 578 ** NOTE: much of this code also appears in the nonswapping version of this 579 ** routine, __glXRender(). Any changes made here should also be 580 ** duplicated there. 581 */ 582 583 req = (xGLXRenderReq *) pc; 584 __GLX_SWAP_SHORT(&req->length); 585 __GLX_SWAP_INT(&req->contextTag); 586 587 pc += sz_xGLXRenderReq; 588 left = (req->length << 2) - sz_xGLXRenderReq; 589 while (left > 0) { 590 void (* proc)(GLbyte *); 591 CARD16 opcode; 592 593 /* 594 ** Verify that the header length and the overall length agree. 595 ** Also, each command must be word aligned. 596 */ 597 hdr = (__GLXrenderHeader *) pc; 598 __GLX_SWAP_SHORT(&hdr->length); 599 __GLX_SWAP_SHORT(&hdr->opcode); 600 601 /* 602 * call the command procedure to swap any arguments 603 */ 604 opcode = hdr->opcode; 605 if ( (opcode >= __GLX_MIN_RENDER_OPCODE) && 606 (opcode <= __GLX_MAX_RENDER_OPCODE) ) { 607 proc = __glXSwapRenderTable[opcode]; 608#if __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT 609 } else if ( (opcode >= __GLX_MIN_RENDER_OPCODE_EXT) && 610 (opcode <= __GLX_MAX_RENDER_OPCODE_EXT) ) { 611 int index = opcode - __GLX_MIN_RENDER_OPCODE_EXT; 612 __GLXRenderSwapInfo *info = &__glXSwapRenderTable_EXT[index]; 613 if (info->swapfunc) { 614 proc = info->swapfunc; 615 } 616 else { 617 proc = NULL; 618 if (info->elem_size == 4 && info->nelems > 0) { 619 __GLX_SWAP_INT_ARRAY( (int *)(pc + __GLX_RENDER_HDR_SIZE), 620 info->nelems ); 621 } 622 else if (info->elem_size == 2 && info->nelems > 0) { 623 __GLX_SWAP_SHORT_ARRAY( (short *)(pc + __GLX_RENDER_HDR_SIZE), 624 info->nelems ); 625 } 626 else if (info->elem_size == 8 && info->nelems > 0) { 627 __GLX_SWAP_DOUBLE_ARRAY( (double *)(pc + __GLX_RENDER_HDR_SIZE), 628 info->nelems ); 629 } 630 } 631#endif /* __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT */ 632 } else { 633 client->errorValue = 0; 634 return __glXBadRenderRequest; 635 } 636 637 if (proc != NULL) 638 (*proc)(pc + __GLX_RENDER_HDR_SIZE); 639 640 /* 641 * proceed to the next command 642 */ 643 pc += hdr->length; 644 left -= hdr->length; 645 } 646 647 return __glXRender( cl, (GLbyte *)req ); 648} 649 650/* 651** Execute a large rendering request (one that spans multiple X requests). 652*/ 653int __glXSwapRenderLarge(__GLXclientState *cl, GLbyte *pc) 654{ 655 ClientPtr client = cl->client; 656 xGLXRenderLargeReq *req; 657 __GLXrenderLargeHeader *hdr; 658 __GLX_DECLARE_SWAP_VARIABLES; 659 __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 660 661 req = (xGLXRenderLargeReq *) pc; 662 __GLX_SWAP_SHORT(&req->length); 663 __GLX_SWAP_INT(&req->contextTag); 664 __GLX_SWAP_INT(&req->dataBytes); 665 __GLX_SWAP_SHORT(&req->requestNumber); 666 __GLX_SWAP_SHORT(&req->requestTotal); 667 668 pc += sz_xGLXRenderLargeReq; 669 670 if (req->requestNumber == 1) { 671 void (* proc)(GLbyte *) = NULL; 672 __GLXRenderSwapInfo *info = NULL; 673 CARD16 opcode; 674 675 hdr = (__GLXrenderLargeHeader *) pc; 676 __GLX_SWAP_INT(&hdr->length); 677 __GLX_SWAP_INT(&hdr->opcode); 678 679 /* 680 * call the command procedure to swap any arguments 681 * Note that we are assuming that all arguments that needs to be 682 * swaped are on the first req only ! 683 */ 684 opcode = hdr->opcode; 685 if ( (opcode >= __GLX_MIN_RENDER_OPCODE) && 686 (opcode <= __GLX_MAX_RENDER_OPCODE) ) { 687 proc = __glXSwapRenderTable[opcode]; 688#if __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT 689 } else if ( (opcode >= __GLX_MIN_RENDER_OPCODE_EXT) && 690 (opcode <= __GLX_MAX_RENDER_OPCODE_EXT) ) { 691 int index = opcode - __GLX_MIN_RENDER_OPCODE_EXT; 692 info = &__glXSwapRenderTable_EXT[index]; 693 if (info->swapfunc) { 694 proc = info->swapfunc; 695 } 696#endif /* __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT */ 697 } else { 698 client->errorValue = 0; 699 cl->largeCmdRequestsTotal = 0; 700 return __glXBadLargeRequest; 701 } 702 703 /* 704 ** Make enough space in the buffer, then copy the entire request. 705 */ 706 if (cl->largeCmdBufSize < hdr->length) { 707 if (!cl->largeCmdBuf) { 708 cl->largeCmdBuf = (GLbyte *) malloc(hdr->length); 709 } else { 710 cl->largeCmdBuf = (GLbyte *) realloc(cl->largeCmdBuf, hdr->length); 711 } 712 if (!cl->largeCmdBuf) { 713 cl->largeCmdRequestsTotal = 0; 714 return BadAlloc; 715 } 716 cl->largeCmdBufSize = hdr->length; 717 } 718 memcpy(cl->largeCmdBuf, pc, req->dataBytes); 719 720 cl->largeCmdBytesSoFar = req->dataBytes; 721 cl->largeCmdBytesTotal = hdr->length; 722 cl->largeCmdRequestsSoFar = 1; 723 cl->largeCmdRequestsTotal = req->requestTotal; 724 cl->largeCmdRequestsSwapProc = proc; 725 cl->largeCmdMaxReqDataSize = req->dataBytes; 726 cl->largeCmdRequestsSwap_info = info; 727 728 return Success; 729 730 731 } 732 else if (req->requestNumber < cl->largeCmdRequestsTotal) { 733 /* 734 * This is not the first nor last request - just copy the data 735 */ 736 if ( cl->largeCmdBytesSoFar + req->dataBytes > cl->largeCmdBytesTotal) { 737 cl->largeCmdRequestsTotal = 0; 738 return __glXBadLargeRequest; 739 } 740 741 memcpy(cl->largeCmdBuf + cl->largeCmdBytesSoFar, 742 pc, req->dataBytes); 743 744 cl->largeCmdBytesSoFar += req->dataBytes; 745 746 if (req->dataBytes > cl->largeCmdMaxReqDataSize) 747 cl->largeCmdMaxReqDataSize = req->dataBytes; 748 749 return Success; 750 } 751 else if (req->requestNumber == cl->largeCmdRequestsTotal) { 752 /* 753 * this is the last request 754 * copy the remainder bytes, call the procedure to swap any 755 * needed data, and then call to transfer the command to all 756 * back-end servers 757 */ 758 if ( cl->largeCmdBytesSoFar + req->dataBytes > cl->largeCmdBytesTotal) { 759 cl->largeCmdRequestsTotal = 0; 760 return __glXBadLargeRequest; 761 } 762 763 memcpy(cl->largeCmdBuf + cl->largeCmdBytesSoFar, 764 pc, req->dataBytes); 765 766 cl->largeCmdBytesSoFar += req->dataBytes; 767 768 if (req->dataBytes > cl->largeCmdMaxReqDataSize) 769 cl->largeCmdMaxReqDataSize = req->dataBytes; 770 771 if (cl->largeCmdRequestsSwapProc != NULL) { 772 (*cl->largeCmdRequestsSwapProc)(cl->largeCmdBuf + __GLX_RENDER_LARGE_HDR_SIZE); 773 } 774 else if (cl->largeCmdRequestsSwap_info && 775 cl->largeCmdRequestsSwap_info->nelems > 0) { 776 if (cl->largeCmdRequestsSwap_info->elem_size == 4) { 777 __GLX_SWAP_INT_ARRAY( (int *)(pc + __GLX_RENDER_LARGE_HDR_SIZE), 778 cl->largeCmdRequestsSwap_info->nelems ); 779 } 780 else if (cl->largeCmdRequestsSwap_info->elem_size == 2) { 781 __GLX_SWAP_SHORT_ARRAY( (short *)(pc + __GLX_RENDER_LARGE_HDR_SIZE), 782 cl->largeCmdRequestsSwap_info->nelems ); 783 } 784 else if (cl->largeCmdRequestsSwap_info->elem_size == 8) { 785 __GLX_SWAP_DOUBLE_ARRAY( (double *)(pc + __GLX_RENDER_LARGE_HDR_SIZE), 786 cl->largeCmdRequestsSwap_info->nelems ); 787 } 788 } 789 790 cl->largeCmdRequestsTotal = 0; 791 return( __glXSendLargeCommand(cl, req->contextTag) ); 792 793 } 794 else { 795 cl->largeCmdRequestsTotal = 0; 796 return __glXBadLargeRequest; 797 } 798 799} 800 801/************************************************************************/ 802 803/* 804** No support is provided for the vendor-private requests other than 805** allocating these entry points in the dispatch table. 806*/ 807 808int __glXSwapVendorPrivate(__GLXclientState *cl, GLbyte *pc) 809{ 810 xGLXVendorPrivateReq *req; 811 CARD32 vendorCode; 812 813 __GLX_DECLARE_SWAP_VARIABLES; 814 815 req = (xGLXVendorPrivateReq *) pc; 816 vendorCode = req->vendorCode; 817 __GLX_SWAP_INT(&vendorCode); 818 819 820 switch( vendorCode ) { 821 822 case X_GLvop_DeleteTexturesEXT: 823 return __glXVForwardSingleReqSwap( cl, pc ); 824 break; 825 826 case X_GLXvop_SwapIntervalSGI: 827 if (glxIsExtensionSupported("SGI_swap_control")) { 828 return __glXVForwardSingleReqSwap( cl, pc ); 829 } 830 else { 831 return Success; 832 } 833 break; 834 835#if 0 /* glx 1.3 */ 836 case X_GLXvop_CreateGLXVideoSourceSGIX: 837 break; 838 case X_GLXvop_DestroyGLXVideoSourceSGIX: 839 break; 840 case X_GLXvop_CreateGLXPixmapWithConfigSGIX: 841 break; 842 case X_GLXvop_DestroyGLXPbufferSGIX: 843 break; 844 case X_GLXvop_ChangeDrawableAttributesSGIX: 845 break; 846#endif 847 848 case X_GLXvop_JoinSwapGroupSGIX: 849 return __glXSwapJoinSwapGroupSGIX( cl, pc ); 850 break; 851 852 case X_GLXvop_BindSwapBarrierSGIX: 853 return __glXSwapBindSwapBarrierSGIX( cl, pc ); 854 break; 855 856 case X_GLXvop_CreateContextWithConfigSGIX: 857 return __glXSwapCreateContextWithConfigSGIX( cl, pc ); 858 break; 859 860 default: 861 /* 862 ** unsupported private request 863 */ 864 cl->client->errorValue = req->vendorCode; 865 return __glXUnsupportedPrivateRequest; 866 } 867 868} 869 870int __glXSwapVendorPrivateWithReply(__GLXclientState *cl, GLbyte *pc) 871{ 872 xGLXVendorPrivateWithReplyReq *req; 873 CARD32 vendorCode; 874 875 __GLX_DECLARE_SWAP_VARIABLES; 876 877 req = (xGLXVendorPrivateWithReplyReq *) pc; 878 vendorCode = req->vendorCode; 879 __GLX_SWAP_INT(&vendorCode); 880 881 switch( vendorCode ) { 882 883 case X_GLvop_GetConvolutionFilterEXT: 884 case X_GLvop_GetSeparableFilterEXT: 885 case X_GLvop_GetHistogramEXT: 886 case X_GLvop_GetMinmaxEXT: 887 return( __glXNoSuchSingleOpcode(cl, pc) ); 888 break; 889 890 case X_GLvop_GetConvolutionParameterfvEXT: 891 case X_GLvop_GetConvolutionParameterivEXT: 892 case X_GLvop_GetHistogramParameterivEXT: 893 case X_GLvop_GetMinmaxParameterfvEXT: 894 case X_GLvop_GetMinmaxParameterivEXT: 895 case X_GLvop_GenTexturesEXT: 896 return( __glXVForwardAllWithReplySwapiv(cl, pc) ); 897 break; 898 899 case X_GLvop_AreTexturesResidentEXT: 900 case X_GLvop_IsTextureEXT: 901 return( __glXVForwardPipe0WithReplySwap(cl, pc) ); 902 break; 903 904#if 0 /* glx1.3 */ 905 case X_GLvop_GetDetailTexFuncSGIS: 906 case X_GLvop_GetSharpenTexFuncSGIS: 907 case X_GLvop_GetColorTableSGI: 908 case X_GLvop_GetColorTableParameterfvSGI: 909 case X_GLvop_GetColorTableParameterivSGI: 910 case X_GLvop_GetTexFilterFuncSGIS: 911 case X_GLvop_GetInstrumentsSGIX: 912 case X_GLvop_InstrumentsBufferSGIX: 913 case X_GLvop_PollInstrumentsSGIX: 914 case X_GLvop_FlushRasterSGIX: 915 case X_GLXvop_CreateGLXPbufferSGIX: 916 case X_GLXvop_GetDrawableAttributesSGIX: 917 case X_GLXvop_QueryHyperpipeNetworkSGIX: 918 case X_GLXvop_QueryHyperpipeConfigSGIX: 919 case X_GLXvop_HyperpipeConfigSGIX: 920 case X_GLXvop_DestroyHyperpipeConfigSGIX: 921#endif 922 case X_GLXvop_QueryMaxSwapBarriersSGIX: 923 return( __glXSwapQueryMaxSwapBarriersSGIX(cl, pc) ); 924 break; 925 926 case X_GLXvop_GetFBConfigsSGIX: 927 return( __glXSwapGetFBConfigsSGIX(cl, pc) ); 928 break; 929 930 case X_GLXvop_MakeCurrentReadSGI: 931 return( __glXSwapMakeCurrentReadSGI(cl, pc) ); 932 break; 933 934 case X_GLXvop_QueryContextInfoEXT: 935 return( __glXSwapQueryContextInfoEXT(cl,(char *)pc) ); 936 break; 937 938 default: 939 /* 940 ** unsupported private request 941 */ 942 cl->client->errorValue = req->vendorCode; 943 return __glXUnsupportedPrivateRequest; 944 } 945 946} 947 948int __glXSwapGetFBConfigs(__GLXclientState *cl, GLbyte *pc) 949{ 950 xGLXGetFBConfigsReq *req = (xGLXGetFBConfigsReq *) pc; 951 __GLX_DECLARE_SWAP_VARIABLES; 952 953 __GLX_SWAP_SHORT(&req->length); 954 __GLX_SWAP_INT(&req->screen); 955 956 return __glXGetFBConfigs(cl, pc); 957} 958 959int __glXSwapGetFBConfigsSGIX(__GLXclientState *cl, GLbyte *pc) 960{ 961 xGLXGetFBConfigsSGIXReq *req = (xGLXGetFBConfigsSGIXReq *)pc; 962 xGLXGetFBConfigsReq new_req; 963 964 new_req.reqType = req->reqType; 965 new_req.glxCode = req->glxCode; 966 new_req.length = req->length; 967 new_req.screen = req->screen; 968 969 return( __glXSwapGetFBConfigs( cl, (GLbyte *)&new_req ) ); 970} 971 972int __glXSwapCreateWindow(__GLXclientState *cl, GLbyte *pc) 973{ 974 xGLXCreateWindowReq *req = (xGLXCreateWindowReq *) pc; 975 __GLX_DECLARE_SWAP_VARIABLES; 976 977 __GLX_SWAP_SHORT(&req->length); 978 __GLX_SWAP_INT(&req->screen); 979 __GLX_SWAP_INT(&req->fbconfig); 980 __GLX_SWAP_INT(&req->window); 981 __GLX_SWAP_INT(&req->glxwindow); 982 __GLX_SWAP_INT(&req->numAttribs); 983 984 return( __glXCreateWindow( cl, (GLbyte *)pc ) ); 985} 986 987int __glXSwapDestroyWindow(__GLXclientState *cl, GLbyte *pc) 988{ 989 xGLXDestroyWindowReq *req = (xGLXDestroyWindowReq *) pc; 990 __GLX_DECLARE_SWAP_VARIABLES; 991 992 __GLX_SWAP_SHORT(&req->length); 993 __GLX_SWAP_INT(&req->glxwindow); 994 995 return( __glXDestroyWindow( cl, (GLbyte *)pc ) ); 996} 997 998int __glXSwapQueryContext(__GLXclientState *cl, GLbyte *pc) 999{ 1000 xGLXQueryContextReq *req = (xGLXQueryContextReq *)pc; 1001 1002 __GLX_DECLARE_SWAP_VARIABLES; 1003 1004 __GLX_SWAP_SHORT(&req->length); 1005 __GLX_SWAP_INT(&req->context); 1006 1007 return( __glXQueryContext(cl, (GLbyte *)pc) ); 1008 1009} 1010 1011int __glXSwapCreatePbuffer(__GLXclientState *cl, GLbyte *pc) 1012{ 1013 xGLXCreatePbufferReq *req = (xGLXCreatePbufferReq *)pc; 1014 int nattr = req->numAttribs; 1015 __GLX_DECLARE_SWAP_VARIABLES; 1016 __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 1017 1018 __GLX_SWAP_SHORT(&req->length); 1019 __GLX_SWAP_INT(&req->screen); 1020 __GLX_SWAP_INT(&req->fbconfig); 1021 __GLX_SWAP_INT(&req->pbuffer); 1022 __GLX_SWAP_INT(&req->numAttribs); 1023 __GLX_SWAP_INT_ARRAY( (int *)(req+1), nattr*2 ); 1024 1025 return( __glXCreatePbuffer( cl, pc ) ); 1026} 1027 1028int __glXSwapDestroyPbuffer(__GLXclientState *cl, GLbyte *pc) 1029{ 1030 xGLXDestroyPbufferReq *req = (xGLXDestroyPbufferReq *) pc; 1031 __GLX_DECLARE_SWAP_VARIABLES; 1032 1033 __GLX_SWAP_SHORT(&req->length); 1034 __GLX_SWAP_INT(&req->pbuffer); 1035 1036 return( __glXDestroyPbuffer( cl, (GLbyte *)pc ) ); 1037} 1038 1039int __glXSwapGetDrawableAttributes(__GLXclientState *cl, GLbyte *pc) 1040{ 1041 xGLXGetDrawableAttributesReq *req = (xGLXGetDrawableAttributesReq *)pc; 1042 __GLX_DECLARE_SWAP_VARIABLES; 1043 1044 __GLX_SWAP_SHORT(&req->length); 1045 __GLX_SWAP_INT(&req->drawable); 1046 1047 return( __glXGetDrawableAttributes(cl, pc) ); 1048} 1049 1050int __glXSwapChangeDrawableAttributes(__GLXclientState *cl, GLbyte *pc) 1051{ 1052 xGLXChangeDrawableAttributesReq *req = (xGLXChangeDrawableAttributesReq *)pc; 1053 __GLX_DECLARE_SWAP_VARIABLES; 1054 __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 1055 1056 __GLX_SWAP_SHORT(&req->length); 1057 __GLX_SWAP_INT(&req->drawable); 1058 __GLX_SWAP_INT(&req->numAttribs); 1059 __GLX_SWAP_INT_ARRAY( (int *)(req+1), req->numAttribs * 2 ); 1060 1061 return( __glXChangeDrawableAttributes(cl, pc) ); 1062} 1063