1706f2543Smrg/* DO NOT EDIT - THIS FILE IS AUTOMATICALLY GENERATED */ 2706f2543Smrg/* 3706f2543Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 4706f2543Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 5706f2543Smrg * 6706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7706f2543Smrg * copy of this software and associated documentation files (the "Software"), 8706f2543Smrg * to deal in the Software without restriction, including without limitation 9706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the 11706f2543Smrg * Software is furnished to do so, subject to the following conditions: 12706f2543Smrg * 13706f2543Smrg * The above copyright notice including the dates of first publication and 14706f2543Smrg * either this permission notice or a reference to 15706f2543Smrg * http://oss.sgi.com/projects/FreeB/ 16706f2543Smrg * shall be included in all copies or substantial portions of the Software. 17706f2543Smrg * 18706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19706f2543Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21706f2543Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22706f2543Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 23706f2543Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24706f2543Smrg * SOFTWARE. 25706f2543Smrg * 26706f2543Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc. 27706f2543Smrg * shall not be used in advertising or otherwise to promote the sale, use or 28706f2543Smrg * other dealings in this Software without prior written authorization from 29706f2543Smrg * Silicon Graphics, Inc. 30706f2543Smrg */ 31706f2543Smrg 32706f2543Smrg#ifdef HAVE_DMX_CONFIG_H 33706f2543Smrg#include <dmx-config.h> 34706f2543Smrg#endif 35706f2543Smrg 36706f2543Smrg#include "dmx.h" 37706f2543Smrg#include "dmxwindow.h" 38706f2543Smrg#include "dmxpixmap.h" 39706f2543Smrg#include "dmxfont.h" 40706f2543Smrg#include "dmxcb.h" 41706f2543Smrg 42706f2543Smrg#include "glxserver.h" 43706f2543Smrg#include "glxext.h" 44706f2543Smrg#include "g_disptab.h" 45706f2543Smrg/* #include "g_disptab_EXT.h" */ 46706f2543Smrg#include "unpack.h" 47706f2543Smrg#include "glxutil.h" 48706f2543Smrg 49706f2543Smrg#include "GL/glxproto.h" 50706f2543Smrg 51706f2543Smrg#ifdef PANORAMIX 52706f2543Smrg#include "panoramiXsrv.h" 53706f2543Smrg#endif 54706f2543Smrg 55706f2543Smrg/* 56706f2543Smrg * GetReqSingle - this is the equivalent of GetReq macro 57706f2543Smrg * from Xlibint.h but it does not set the reqType field (the opcode). 58706f2543Smrg * this is because the GL single opcodes has different naming convension 59706f2543Smrg * the other X opcodes (ie. X_GLsop_GetFloatv). 60706f2543Smrg */ 61706f2543Smrg#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) 62706f2543Smrg#define GetReqSingle(name, req) \ 63706f2543Smrg WORD64ALIGN\ 64706f2543Smrg if ((dpy->bufptr + SIZEOF(x##name##Req)) > dpy->bufmax)\ 65706f2543Smrg _XFlush(dpy);\ 66706f2543Smrg req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\ 67706f2543Smrg req->length = (SIZEOF(x##name##Req))>>2;\ 68706f2543Smrg dpy->bufptr += SIZEOF(x##name##Req);\ 69706f2543Smrg dpy->request++ 70706f2543Smrg 71706f2543Smrg#else /* non-ANSI C uses empty comment instead of "##" for token concatenation */ 72706f2543Smrg#define GetReqSingle(name, req) \ 73706f2543Smrg WORD64ALIGN\ 74706f2543Smrg if ((dpy->bufptr + SIZEOF(x/**/name/**/Req)) > dpy->bufmax)\ 75706f2543Smrg _XFlush(dpy);\ 76706f2543Smrg req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\ 77706f2543Smrg req->length = (SIZEOF(x/**/name/**/Req))>>2;\ 78706f2543Smrg dpy->bufptr += SIZEOF(x/**/name/**/Req);\ 79706f2543Smrg dpy->request++ 80706f2543Smrg#endif 81706f2543Smrg 82706f2543Smrg#define X_GLXSingle 0 /* needed by GetReqExtra */ 83706f2543Smrg 84706f2543Smrgextern Display *GetBackEndDisplay( __GLXclientState *cl, int s ); 85706f2543Smrgextern int GetCurrentBackEndTag(__GLXclientState *cl, GLXContextTag tag, int s); 86706f2543Smrg 87706f2543Smrgstatic int swap_vec_element_size = 0; 88706f2543Smrg 89706f2543Smrgstatic void SendSwappedReply( ClientPtr client, 90706f2543Smrg xGLXSingleReply *reply, 91706f2543Smrg char *buf, 92706f2543Smrg int buf_size ) 93706f2543Smrg{ 94706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 95706f2543Smrg __GLX_SWAP_SHORT(&reply->sequenceNumber); 96706f2543Smrg __GLX_SWAP_INT(&reply->length); 97706f2543Smrg __GLX_SWAP_INT(&reply->retval); 98706f2543Smrg __GLX_SWAP_INT(&reply->size); 99706f2543Smrg 100706f2543Smrg if ( (buf_size == 0) && (swap_vec_element_size > 0) ) { 101706f2543Smrg /* 102706f2543Smrg * the reply has single component - need to swap pad3 103706f2543Smrg */ 104706f2543Smrg if (swap_vec_element_size == 2) { 105706f2543Smrg __GLX_SWAP_SHORT(&reply->pad3); 106706f2543Smrg } 107706f2543Smrg else if (swap_vec_element_size == 4) { 108706f2543Smrg __GLX_SWAP_INT(&reply->pad3); 109706f2543Smrg __GLX_SWAP_INT(&reply->pad4); /* some requests use also pad4 110706f2543Smrg * i.e GetConvolutionFilter 111706f2543Smrg */ 112706f2543Smrg } 113706f2543Smrg else if (swap_vec_element_size == 8) { 114706f2543Smrg __GLX_SWAP_DOUBLE(&reply->pad3); 115706f2543Smrg } 116706f2543Smrg } 117706f2543Smrg else if ( (buf_size > 0) && (swap_vec_element_size > 0) ) { 118706f2543Smrg /* 119706f2543Smrg * the reply has vector of elements which needs to be swapped 120706f2543Smrg */ 121706f2543Smrg int vsize = buf_size / swap_vec_element_size; 122706f2543Smrg char *p = buf; 123706f2543Smrg int i; 124706f2543Smrg 125706f2543Smrg for (i=0; i<vsize; i++) { 126706f2543Smrg if (swap_vec_element_size == 2) { 127706f2543Smrg __GLX_SWAP_SHORT(p); 128706f2543Smrg } 129706f2543Smrg else if (swap_vec_element_size == 4) { 130706f2543Smrg __GLX_SWAP_INT(p); 131706f2543Smrg } 132706f2543Smrg else if (swap_vec_element_size == 8) { 133706f2543Smrg __GLX_SWAP_DOUBLE(p); 134706f2543Smrg } 135706f2543Smrg 136706f2543Smrg p += swap_vec_element_size; 137706f2543Smrg } 138706f2543Smrg 139706f2543Smrg /* 140706f2543Smrg * swap pad words as well - for case that some single reply uses 141706f2543Smrg * them as well 142706f2543Smrg */ 143706f2543Smrg __GLX_SWAP_INT(&reply->pad3); 144706f2543Smrg __GLX_SWAP_INT(&reply->pad4); 145706f2543Smrg __GLX_SWAP_INT(&reply->pad5); 146706f2543Smrg __GLX_SWAP_INT(&reply->pad6); 147706f2543Smrg 148706f2543Smrg } 149706f2543Smrg 150706f2543Smrg WriteToClient(client, sizeof(xGLXSingleReply),(char *)reply); 151706f2543Smrg if (buf_size > 0) 152706f2543Smrg WriteToClient(client, buf_size, (char *)buf); 153706f2543Smrg 154706f2543Smrg} 155706f2543Smrg 156706f2543Smrgint __glXForwardSingleReq( __GLXclientState *cl, GLbyte *pc ) 157706f2543Smrg{ 158706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 159706f2543Smrg xGLXSingleReq *be_req; 160706f2543Smrg __GLXcontext *glxc; 161706f2543Smrg int from_screen = 0; 162706f2543Smrg int to_screen = 0; 163706f2543Smrg int buf_size; 164706f2543Smrg int s; 165706f2543Smrg 166706f2543Smrg glxc = __glXLookupContextByTag(cl, req->contextTag); 167706f2543Smrg if (!glxc) { 168706f2543Smrg return 0; 169706f2543Smrg } 170706f2543Smrg from_screen = to_screen = glxc->pScreen->myNum; 171706f2543Smrg 172706f2543Smrg#ifdef PANORAMIX 173706f2543Smrg if (!noPanoramiXExtension) { 174706f2543Smrg from_screen = 0; 175706f2543Smrg to_screen = screenInfo.numScreens - 1; 176706f2543Smrg } 177706f2543Smrg#endif 178706f2543Smrg 179706f2543Smrg pc += sz_xGLXSingleReq; 180706f2543Smrg buf_size = (req->length << 2) - sz_xGLXSingleReq; 181706f2543Smrg 182706f2543Smrg /* 183706f2543Smrg * just forward the request to back-end server(s) 184706f2543Smrg */ 185706f2543Smrg for (s=from_screen; s<=to_screen; s++) { 186706f2543Smrg DMXScreenInfo *dmxScreen = &dmxScreens[s]; 187706f2543Smrg Display *dpy = GetBackEndDisplay(cl,s); 188706f2543Smrg 189706f2543Smrg LockDisplay(dpy); 190706f2543Smrg GetReqSingle(GLXSingle,be_req); 191706f2543Smrg be_req->reqType = dmxScreen->glxMajorOpcode; 192706f2543Smrg be_req->glxCode = req->glxCode; 193706f2543Smrg be_req->length = req->length; 194706f2543Smrg be_req->contextTag = GetCurrentBackEndTag(cl,req->contextTag,s); 195706f2543Smrg if (buf_size > 0) 196706f2543Smrg _XSend(dpy, (const char *)pc, buf_size); 197706f2543Smrg UnlockDisplay(dpy); 198706f2543Smrg SyncHandle(); 199706f2543Smrg 200706f2543Smrg if (req->glxCode == X_GLsop_Flush) { 201706f2543Smrg XFlush(dpy); 202706f2543Smrg } 203706f2543Smrg 204706f2543Smrg } 205706f2543Smrg 206706f2543Smrg return Success; 207706f2543Smrg} 208706f2543Smrg 209706f2543Smrgint __glXForwardPipe0WithReply( __GLXclientState *cl, GLbyte *pc ) 210706f2543Smrg{ 211706f2543Smrg ClientPtr client = cl->client; 212706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 213706f2543Smrg xGLXSingleReq *be_req; 214706f2543Smrg xGLXSingleReply reply; 215706f2543Smrg xGLXSingleReply be_reply; 216706f2543Smrg __GLXcontext *glxc; 217706f2543Smrg int buf_size; 218706f2543Smrg char *be_buf = NULL; 219706f2543Smrg int be_buf_size; 220706f2543Smrg DMXScreenInfo *dmxScreen; 221706f2543Smrg Display *dpy; 222706f2543Smrg 223706f2543Smrg glxc = __glXLookupContextByTag(cl, req->contextTag); 224706f2543Smrg if (!glxc) { 225706f2543Smrg return __glXBadContext; 226706f2543Smrg } 227706f2543Smrg 228706f2543Smrg pc += sz_xGLXSingleReq; 229706f2543Smrg buf_size = (req->length << 2) - sz_xGLXSingleReq; 230706f2543Smrg 231706f2543Smrg dmxScreen = &dmxScreens[glxc->pScreen->myNum]; 232706f2543Smrg dpy = GetBackEndDisplay(cl, glxc->pScreen->myNum); 233706f2543Smrg 234706f2543Smrg /* 235706f2543Smrg * send the request to the first back-end server 236706f2543Smrg */ 237706f2543Smrg LockDisplay(dpy); 238706f2543Smrg GetReqSingle(GLXSingle,be_req); 239706f2543Smrg be_req->reqType = dmxScreen->glxMajorOpcode; 240706f2543Smrg be_req->glxCode = req->glxCode; 241706f2543Smrg be_req->length = req->length; 242706f2543Smrg be_req->contextTag = GetCurrentBackEndTag(cl,req->contextTag,glxc->pScreen->myNum); 243706f2543Smrg if (buf_size > 0) 244706f2543Smrg _XSend(dpy, (const char *)pc, buf_size); 245706f2543Smrg 246706f2543Smrg /* 247706f2543Smrg * get the reply from the back-end server 248706f2543Smrg */ 249706f2543Smrg _XReply(dpy, (xReply*) &be_reply, 0, False); 250706f2543Smrg be_buf_size = be_reply.length << 2; 251706f2543Smrg if (be_buf_size > 0) { 252706f2543Smrg be_buf = (char *)malloc( be_buf_size ); 253706f2543Smrg if (be_buf) { 254706f2543Smrg _XRead(dpy, be_buf, be_buf_size); 255706f2543Smrg } 256706f2543Smrg else { 257706f2543Smrg /* Throw data on the floor */ 258706f2543Smrg _XEatData(dpy, be_buf_size); 259706f2543Smrg return BadAlloc; 260706f2543Smrg } 261706f2543Smrg } 262706f2543Smrg 263706f2543Smrg UnlockDisplay(dpy); 264706f2543Smrg SyncHandle(); 265706f2543Smrg 266706f2543Smrg /* 267706f2543Smrg * send the reply to the client 268706f2543Smrg */ 269706f2543Smrg reply.type = X_Reply; 270706f2543Smrg reply.sequenceNumber = client->sequence; 271706f2543Smrg reply.length = be_reply.length; 272706f2543Smrg reply.retval = be_reply.retval; 273706f2543Smrg reply.size = be_reply.size; 274706f2543Smrg reply.pad3 = be_reply.pad3; 275706f2543Smrg reply.pad4 = be_reply.pad4; 276706f2543Smrg 277706f2543Smrg if (client->swapped) { 278706f2543Smrg SendSwappedReply( client, &reply, be_buf, be_buf_size ); 279706f2543Smrg } 280706f2543Smrg else { 281706f2543Smrg WriteToClient(client, sizeof(xGLXSingleReply),(char *)&reply); 282706f2543Smrg if (be_buf_size > 0) 283706f2543Smrg WriteToClient(client, be_buf_size, (char *)be_buf); 284706f2543Smrg } 285706f2543Smrg 286706f2543Smrg if (be_buf_size > 0) free(be_buf); 287706f2543Smrg 288706f2543Smrg return Success; 289706f2543Smrg} 290706f2543Smrg 291706f2543Smrgint __glXForwardAllWithReply( __GLXclientState *cl, GLbyte *pc ) 292706f2543Smrg{ 293706f2543Smrg ClientPtr client = cl->client; 294706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 295706f2543Smrg xGLXSingleReq *be_req; 296706f2543Smrg xGLXSingleReply reply; 297706f2543Smrg xGLXSingleReply be_reply; 298706f2543Smrg __GLXcontext *glxc; 299706f2543Smrg int buf_size; 300706f2543Smrg char *be_buf = NULL; 301706f2543Smrg int be_buf_size = 0; 302706f2543Smrg int from_screen = 0; 303706f2543Smrg int to_screen = 0; 304706f2543Smrg int s; 305706f2543Smrg 306706f2543Smrg DMXScreenInfo *dmxScreen; 307706f2543Smrg Display *dpy; 308706f2543Smrg 309706f2543Smrg glxc = __glXLookupContextByTag(cl, req->contextTag); 310706f2543Smrg if (!glxc) { 311706f2543Smrg return 0; 312706f2543Smrg } 313706f2543Smrg from_screen = to_screen = glxc->pScreen->myNum; 314706f2543Smrg 315706f2543Smrg#ifdef PANORAMIX 316706f2543Smrg if (!noPanoramiXExtension) { 317706f2543Smrg from_screen = 0; 318706f2543Smrg to_screen = screenInfo.numScreens - 1; 319706f2543Smrg } 320706f2543Smrg#endif 321706f2543Smrg 322706f2543Smrg pc += sz_xGLXSingleReq; 323706f2543Smrg buf_size = (req->length << 2) - sz_xGLXSingleReq; 324706f2543Smrg 325706f2543Smrg /* 326706f2543Smrg * send the request to the first back-end server(s) 327706f2543Smrg */ 328706f2543Smrg for (s=to_screen; s>=from_screen; s--) { 329706f2543Smrg dmxScreen = &dmxScreens[s]; 330706f2543Smrg dpy = GetBackEndDisplay(cl,s); 331706f2543Smrg 332706f2543Smrg LockDisplay(dpy); 333706f2543Smrg GetReqSingle(GLXSingle,be_req); 334706f2543Smrg be_req->reqType = dmxScreen->glxMajorOpcode; 335706f2543Smrg be_req->glxCode = req->glxCode; 336706f2543Smrg be_req->length = req->length; 337706f2543Smrg be_req->contextTag = GetCurrentBackEndTag(cl,req->contextTag,s); 338706f2543Smrg if (buf_size > 0) 339706f2543Smrg _XSend(dpy, (const char *)pc, buf_size); 340706f2543Smrg 341706f2543Smrg /* 342706f2543Smrg * get the reply from the back-end server 343706f2543Smrg */ 344706f2543Smrg _XReply(dpy, (xReply*) &be_reply, 0, False); 345706f2543Smrg be_buf_size = be_reply.length << 2; 346706f2543Smrg if (be_buf_size > 0) { 347706f2543Smrg be_buf = (char *)malloc( be_buf_size ); 348706f2543Smrg if (be_buf) { 349706f2543Smrg _XRead(dpy, be_buf, be_buf_size); 350706f2543Smrg } 351706f2543Smrg else { 352706f2543Smrg /* Throw data on the floor */ 353706f2543Smrg _XEatData(dpy, be_buf_size); 354706f2543Smrg return BadAlloc; 355706f2543Smrg } 356706f2543Smrg } 357706f2543Smrg 358706f2543Smrg UnlockDisplay(dpy); 359706f2543Smrg SyncHandle(); 360706f2543Smrg 361706f2543Smrg if (s > from_screen && be_buf_size > 0) { 362706f2543Smrg free(be_buf); 363706f2543Smrg } 364706f2543Smrg } 365706f2543Smrg 366706f2543Smrg /* 367706f2543Smrg * send the reply to the client 368706f2543Smrg */ 369706f2543Smrg reply.type = X_Reply; 370706f2543Smrg reply.sequenceNumber = client->sequence; 371706f2543Smrg reply.length = be_reply.length; 372706f2543Smrg reply.retval = be_reply.retval; 373706f2543Smrg reply.size = be_reply.size; 374706f2543Smrg reply.pad3 = be_reply.pad3; 375706f2543Smrg reply.pad4 = be_reply.pad4; 376706f2543Smrg 377706f2543Smrg if (client->swapped) { 378706f2543Smrg SendSwappedReply( client, &reply, be_buf, be_buf_size ); 379706f2543Smrg } 380706f2543Smrg else { 381706f2543Smrg WriteToClient(client, sizeof(xGLXSingleReply),(char *)&reply); 382706f2543Smrg if (be_buf_size > 0) 383706f2543Smrg WriteToClient(client, be_buf_size, (char *)be_buf); 384706f2543Smrg } 385706f2543Smrg 386706f2543Smrg if (be_buf_size > 0) free(be_buf); 387706f2543Smrg 388706f2543Smrg return Success; 389706f2543Smrg} 390706f2543Smrg 391706f2543Smrgint __glXForwardSingleReqSwap( __GLXclientState *cl, GLbyte *pc ) 392706f2543Smrg{ 393706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 394706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 395706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 396706f2543Smrg 397706f2543Smrg __GLX_SWAP_SHORT(&req->length); 398706f2543Smrg __GLX_SWAP_INT(&req->contextTag); 399706f2543Smrg 400706f2543Smrg swap_vec_element_size = 0; 401706f2543Smrg 402706f2543Smrg /* 403706f2543Smrg * swap extra data in request - assuming all data 404706f2543Smrg * (if available) are arrays of 4 bytes components ! 405706f2543Smrg */ 406706f2543Smrg if (req->length > sz_xGLXSingleReq/4) { 407706f2543Smrg int *data = (int *)(req+1); 408706f2543Smrg int count = req->length - sz_xGLXSingleReq/4; 409706f2543Smrg __GLX_SWAP_INT_ARRAY(data, count ); 410706f2543Smrg } 411706f2543Smrg 412706f2543Smrg return( __glXForwardSingleReq( cl, pc ) ); 413706f2543Smrg} 414706f2543Smrg 415706f2543Smrgint __glXForwardPipe0WithReplySwap( __GLXclientState *cl, GLbyte *pc ) 416706f2543Smrg{ 417706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 418706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 419706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 420706f2543Smrg 421706f2543Smrg __GLX_SWAP_SHORT(&req->length); 422706f2543Smrg __GLX_SWAP_INT(&req->contextTag); 423706f2543Smrg 424706f2543Smrg swap_vec_element_size = 0; 425706f2543Smrg 426706f2543Smrg /* 427706f2543Smrg * swap extra data in request - assuming all data 428706f2543Smrg * (if available) are arrays of 4 bytes components ! 429706f2543Smrg */ 430706f2543Smrg if (req->length > sz_xGLXSingleReq/4) { 431706f2543Smrg int *data = (int *)(req+1); 432706f2543Smrg int count = req->length - sz_xGLXSingleReq/4; 433706f2543Smrg __GLX_SWAP_INT_ARRAY(data, count ); 434706f2543Smrg } 435706f2543Smrg 436706f2543Smrg return( __glXForwardPipe0WithReply( cl, pc ) ); 437706f2543Smrg} 438706f2543Smrg 439706f2543Smrgint __glXForwardPipe0WithReplySwapsv( __GLXclientState *cl, GLbyte *pc ) 440706f2543Smrg{ 441706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 442706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 443706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 444706f2543Smrg 445706f2543Smrg __GLX_SWAP_SHORT(&req->length); 446706f2543Smrg __GLX_SWAP_INT(&req->contextTag); 447706f2543Smrg 448706f2543Smrg swap_vec_element_size = 2; 449706f2543Smrg 450706f2543Smrg /* 451706f2543Smrg * swap extra data in request - assuming all data 452706f2543Smrg * (if available) are arrays of 4 bytes components ! 453706f2543Smrg */ 454706f2543Smrg if (req->length > sz_xGLXSingleReq/4) { 455706f2543Smrg int *data = (int *)(req+1); 456706f2543Smrg int count = req->length - sz_xGLXSingleReq/4; 457706f2543Smrg __GLX_SWAP_INT_ARRAY(data, count ); 458706f2543Smrg } 459706f2543Smrg 460706f2543Smrg 461706f2543Smrg return( __glXForwardPipe0WithReply( cl, pc ) ); 462706f2543Smrg} 463706f2543Smrg 464706f2543Smrgint __glXForwardPipe0WithReplySwapiv( __GLXclientState *cl, GLbyte *pc ) 465706f2543Smrg{ 466706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 467706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 468706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 469706f2543Smrg 470706f2543Smrg __GLX_SWAP_SHORT(&req->length); 471706f2543Smrg __GLX_SWAP_INT(&req->contextTag); 472706f2543Smrg 473706f2543Smrg swap_vec_element_size = 4; 474706f2543Smrg 475706f2543Smrg /* 476706f2543Smrg * swap extra data in request - assuming all data 477706f2543Smrg * (if available) are arrays of 4 bytes components ! 478706f2543Smrg */ 479706f2543Smrg if (req->length > sz_xGLXSingleReq/4) { 480706f2543Smrg int *data = (int *)(req+1); 481706f2543Smrg int count = req->length - sz_xGLXSingleReq/4; 482706f2543Smrg __GLX_SWAP_INT_ARRAY(data, count ); 483706f2543Smrg } 484706f2543Smrg 485706f2543Smrg 486706f2543Smrg return( __glXForwardPipe0WithReply( cl, pc ) ); 487706f2543Smrg} 488706f2543Smrg 489706f2543Smrgint __glXForwardPipe0WithReplySwapdv( __GLXclientState *cl, GLbyte *pc ) 490706f2543Smrg{ 491706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 492706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 493706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 494706f2543Smrg 495706f2543Smrg __GLX_SWAP_SHORT(&req->length); 496706f2543Smrg __GLX_SWAP_INT(&req->contextTag); 497706f2543Smrg 498706f2543Smrg swap_vec_element_size = 8; 499706f2543Smrg 500706f2543Smrg /* 501706f2543Smrg * swap extra data in request - assuming all data 502706f2543Smrg * (if available) are arrays of 4 bytes components ! 503706f2543Smrg */ 504706f2543Smrg if (req->length > sz_xGLXSingleReq/4) { 505706f2543Smrg int *data = (int *)(req+1); 506706f2543Smrg int count = req->length - sz_xGLXSingleReq/4; 507706f2543Smrg __GLX_SWAP_INT_ARRAY(data, count ); 508706f2543Smrg } 509706f2543Smrg 510706f2543Smrg 511706f2543Smrg return( __glXForwardPipe0WithReply( cl, pc ) ); 512706f2543Smrg} 513706f2543Smrg 514706f2543Smrgint __glXForwardAllWithReplySwap( __GLXclientState *cl, GLbyte *pc ) 515706f2543Smrg{ 516706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 517706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 518706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 519706f2543Smrg 520706f2543Smrg __GLX_SWAP_SHORT(&req->length); 521706f2543Smrg __GLX_SWAP_INT(&req->contextTag); 522706f2543Smrg 523706f2543Smrg swap_vec_element_size = 0; 524706f2543Smrg 525706f2543Smrg /* 526706f2543Smrg * swap extra data in request - assuming all data 527706f2543Smrg * (if available) are arrays of 4 bytes components ! 528706f2543Smrg */ 529706f2543Smrg if (req->length > sz_xGLXSingleReq/4) { 530706f2543Smrg int *data = (int *)(req+1); 531706f2543Smrg int count = req->length - sz_xGLXSingleReq/4; 532706f2543Smrg __GLX_SWAP_INT_ARRAY(data, count ); 533706f2543Smrg } 534706f2543Smrg 535706f2543Smrg 536706f2543Smrg return( __glXForwardAllWithReply( cl, pc ) ); 537706f2543Smrg} 538706f2543Smrg 539706f2543Smrgint __glXForwardAllWithReplySwapsv( __GLXclientState *cl, GLbyte *pc ) 540706f2543Smrg{ 541706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 542706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 543706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 544706f2543Smrg 545706f2543Smrg __GLX_SWAP_SHORT(&req->length); 546706f2543Smrg __GLX_SWAP_INT(&req->contextTag); 547706f2543Smrg 548706f2543Smrg swap_vec_element_size = 2; 549706f2543Smrg 550706f2543Smrg /* 551706f2543Smrg * swap extra data in request - assuming all data 552706f2543Smrg * (if available) are arrays of 4 bytes components ! 553706f2543Smrg */ 554706f2543Smrg if (req->length > sz_xGLXSingleReq/4) { 555706f2543Smrg int *data = (int *)(req+1); 556706f2543Smrg int count = req->length - sz_xGLXSingleReq/4; 557706f2543Smrg __GLX_SWAP_INT_ARRAY(data, count ); 558706f2543Smrg } 559706f2543Smrg 560706f2543Smrg 561706f2543Smrg return( __glXForwardAllWithReply( cl, pc ) ); 562706f2543Smrg} 563706f2543Smrg 564706f2543Smrgint __glXForwardAllWithReplySwapiv( __GLXclientState *cl, GLbyte *pc ) 565706f2543Smrg{ 566706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 567706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 568706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 569706f2543Smrg 570706f2543Smrg __GLX_SWAP_SHORT(&req->length); 571706f2543Smrg __GLX_SWAP_INT(&req->contextTag); 572706f2543Smrg 573706f2543Smrg swap_vec_element_size = 4; 574706f2543Smrg 575706f2543Smrg /* 576706f2543Smrg * swap extra data in request - assuming all data 577706f2543Smrg * (if available) are arrays of 4 bytes components ! 578706f2543Smrg */ 579706f2543Smrg if (req->length > sz_xGLXSingleReq/4) { 580706f2543Smrg int *data = (int *)(req+1); 581706f2543Smrg int count = req->length - sz_xGLXSingleReq/4; 582706f2543Smrg __GLX_SWAP_INT_ARRAY(data, count ); 583706f2543Smrg } 584706f2543Smrg 585706f2543Smrg 586706f2543Smrg return( __glXForwardAllWithReply( cl, pc ) ); 587706f2543Smrg} 588706f2543Smrg 589706f2543Smrgint __glXForwardAllWithReplySwapdv( __GLXclientState *cl, GLbyte *pc ) 590706f2543Smrg{ 591706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 592706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 593706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 594706f2543Smrg 595706f2543Smrg __GLX_SWAP_SHORT(&req->length); 596706f2543Smrg __GLX_SWAP_INT(&req->contextTag); 597706f2543Smrg 598706f2543Smrg swap_vec_element_size = 8; 599706f2543Smrg 600706f2543Smrg /* 601706f2543Smrg * swap extra data in request - assuming all data 602706f2543Smrg * (if available) are arrays of 4 bytes components ! 603706f2543Smrg */ 604706f2543Smrg if (req->length > sz_xGLXSingleReq/4) { 605706f2543Smrg int *data = (int *)(req+1); 606706f2543Smrg int count = req->length - sz_xGLXSingleReq/4; 607706f2543Smrg __GLX_SWAP_INT_ARRAY(data, count ); 608706f2543Smrg } 609706f2543Smrg 610706f2543Smrg 611706f2543Smrg return( __glXForwardAllWithReply( cl, pc ) ); 612706f2543Smrg} 613706f2543Smrg 614706f2543Smrgstatic GLint __glReadPixels_size(GLenum format, GLenum type, GLint w, GLint h, 615706f2543Smrg int *elementbits_return, int *rowbytes_return ) 616706f2543Smrg{ 617706f2543Smrg GLint elements, esize; 618706f2543Smrg GLint rowsize, padding; 619706f2543Smrg 620706f2543Smrg if (w < 0 || h < 0) { 621706f2543Smrg return -1; 622706f2543Smrg } 623706f2543Smrg switch (format) { 624706f2543Smrg case GL_COLOR_INDEX: 625706f2543Smrg case GL_STENCIL_INDEX: 626706f2543Smrg case GL_DEPTH_COMPONENT: 627706f2543Smrg elements = 1; 628706f2543Smrg break; 629706f2543Smrg case GL_RED: 630706f2543Smrg case GL_GREEN: 631706f2543Smrg case GL_BLUE: 632706f2543Smrg case GL_ALPHA: 633706f2543Smrg case GL_LUMINANCE: 634706f2543Smrg elements = 1; 635706f2543Smrg break; 636706f2543Smrg case GL_LUMINANCE_ALPHA: 637706f2543Smrg elements = 2; 638706f2543Smrg break; 639706f2543Smrg case GL_RGB: 640706f2543Smrg case GL_BGR: 641706f2543Smrg elements = 3; 642706f2543Smrg break; 643706f2543Smrg case GL_RGBA: 644706f2543Smrg case GL_BGRA: 645706f2543Smrg case GL_ABGR_EXT: 646706f2543Smrg elements = 4; 647706f2543Smrg break; 648706f2543Smrg default: 649706f2543Smrg return -1; 650706f2543Smrg } 651706f2543Smrg /* 652706f2543Smrg ** According to the GLX protocol, each row must be padded to a multiple of 653706f2543Smrg ** 4 bytes. 4 bytes also happens to be the default alignment in the pixel 654706f2543Smrg ** store modes of the GL. 655706f2543Smrg */ 656706f2543Smrg switch (type) { 657706f2543Smrg case GL_BITMAP: 658706f2543Smrg if (format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX) { 659706f2543Smrg rowsize = ((w * elements)+7)/8; 660706f2543Smrg padding = rowsize % 4; 661706f2543Smrg if (padding) { 662706f2543Smrg rowsize += 4 - padding; 663706f2543Smrg } 664706f2543Smrg if (elementbits_return) *elementbits_return = elements; 665706f2543Smrg if (rowbytes_return) *rowbytes_return = rowsize; 666706f2543Smrg return rowsize * h; 667706f2543Smrg } else { 668706f2543Smrg return -1; 669706f2543Smrg } 670706f2543Smrg case GL_BYTE: 671706f2543Smrg case GL_UNSIGNED_BYTE: 672706f2543Smrg esize = 1; 673706f2543Smrg break; 674706f2543Smrg case GL_UNSIGNED_BYTE_3_3_2: 675706f2543Smrg case GL_UNSIGNED_BYTE_2_3_3_REV: 676706f2543Smrg esize = 1; 677706f2543Smrg elements = 1; 678706f2543Smrg break; 679706f2543Smrg case GL_SHORT: 680706f2543Smrg case GL_UNSIGNED_SHORT: 681706f2543Smrg esize = 2; 682706f2543Smrg break; 683706f2543Smrg case GL_UNSIGNED_SHORT_5_6_5: 684706f2543Smrg case GL_UNSIGNED_SHORT_5_6_5_REV: 685706f2543Smrg case GL_UNSIGNED_SHORT_4_4_4_4: 686706f2543Smrg case GL_UNSIGNED_SHORT_4_4_4_4_REV: 687706f2543Smrg case GL_UNSIGNED_SHORT_5_5_5_1: 688706f2543Smrg case GL_UNSIGNED_SHORT_1_5_5_5_REV: 689706f2543Smrg esize = 2; 690706f2543Smrg elements = 1; 691706f2543Smrg break; 692706f2543Smrg case GL_INT: 693706f2543Smrg case GL_UNSIGNED_INT: 694706f2543Smrg case GL_FLOAT: 695706f2543Smrg esize = 4; 696706f2543Smrg break; 697706f2543Smrg case GL_UNSIGNED_INT_8_8_8_8: 698706f2543Smrg case GL_UNSIGNED_INT_8_8_8_8_REV: 699706f2543Smrg case GL_UNSIGNED_INT_10_10_10_2: 700706f2543Smrg case GL_UNSIGNED_INT_2_10_10_10_REV: 701706f2543Smrg esize = 4; 702706f2543Smrg elements = 1; 703706f2543Smrg break; 704706f2543Smrg default: 705706f2543Smrg return -1; 706706f2543Smrg } 707706f2543Smrg rowsize = w * elements * esize; 708706f2543Smrg padding = rowsize % 4; 709706f2543Smrg if (padding) { 710706f2543Smrg rowsize += 4 - padding; 711706f2543Smrg } 712706f2543Smrg 713706f2543Smrg if (elementbits_return) *elementbits_return = esize*elements*8; 714706f2543Smrg if (rowbytes_return) *rowbytes_return = rowsize; 715706f2543Smrg 716706f2543Smrg return rowsize * h; 717706f2543Smrg} 718706f2543Smrg 719706f2543Smrgstatic int intersectRect( int x1, int x2, int y1, int y2, 720706f2543Smrg int X1, int X2, int Y1, int Y2, 721706f2543Smrg int *ix1, int *ix2, int *iy1, int *iy2 ) 722706f2543Smrg{ 723706f2543Smrg int right = (x2 < X2 ? x2 : X2); 724706f2543Smrg int bottom = (y2 < Y2 ? y2 : Y2); 725706f2543Smrg int left = (x1 > X1 ? x1 : X1); 726706f2543Smrg int top = (y1 > Y1 ? y1 : Y1); 727706f2543Smrg int width = right - left + 1; 728706f2543Smrg int height = bottom - top + 1; 729706f2543Smrg 730706f2543Smrg if ( (width <= 0) || (height <= 0) ) { 731706f2543Smrg *ix1 = *ix2 = *iy1 = *iy2 = 0; 732706f2543Smrg return 0; 733706f2543Smrg } 734706f2543Smrg else { 735706f2543Smrg *ix1 = left; 736706f2543Smrg *ix2 = right; 737706f2543Smrg *iy1 = top; 738706f2543Smrg *iy2 = bottom; 739706f2543Smrg return width * height; 740706f2543Smrg } 741706f2543Smrg 742706f2543Smrg} 743706f2543Smrg 744706f2543Smrgint __glXDisp_ReadPixels(__GLXclientState *cl, GLbyte *pc) 745706f2543Smrg{ 746706f2543Smrg xGLXSingleReq *req = (xGLXSingleReq *)pc; 747706f2543Smrg xGLXSingleReq *be_req; 748706f2543Smrg xGLXReadPixelsReply reply; 749706f2543Smrg xGLXReadPixelsReply be_reply; 750706f2543Smrg GLbyte *be_pc; 751706f2543Smrg GLint x,y; 752706f2543Smrg GLsizei width, height; 753706f2543Smrg GLenum format, type; 754706f2543Smrg GLboolean swapBytes, lsbFirst; 755706f2543Smrg ClientPtr client = cl->client; 756706f2543Smrg DrawablePtr pDraw; 757706f2543Smrg __GLXcontext *glxc; 758706f2543Smrg int from_screen = 0; 759706f2543Smrg int to_screen = 0; 760706f2543Smrg char *buf; 761706f2543Smrg int buf_size; 762706f2543Smrg int s; 763706f2543Smrg int win_x1, win_x2; 764706f2543Smrg int win_y1, win_y2; 765706f2543Smrg int ebits, rowsize; 766706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 767706f2543Smrg 768706f2543Smrg if (client->swapped) { 769706f2543Smrg __GLX_SWAP_INT(&req->contextTag); 770706f2543Smrg } 771706f2543Smrg 772706f2543Smrg glxc = __glXLookupContextByTag(cl, req->contextTag); 773706f2543Smrg if (!glxc) { 774706f2543Smrg return 0; 775706f2543Smrg } 776706f2543Smrg from_screen = to_screen = glxc->pScreen->myNum; 777706f2543Smrg 778706f2543Smrg#ifdef PANORAMIX 779706f2543Smrg if (!noPanoramiXExtension) { 780706f2543Smrg from_screen = 0; 781706f2543Smrg to_screen = screenInfo.numScreens - 1; 782706f2543Smrg } 783706f2543Smrg#endif 784706f2543Smrg 785706f2543Smrg pc += sz_xGLXSingleReq; 786706f2543Smrg x = *(GLint *)(pc + 0); 787706f2543Smrg y = *(GLint *)(pc + 4); 788706f2543Smrg width = *(GLsizei *)(pc + 8); 789706f2543Smrg height = *(GLsizei *)(pc + 12); 790706f2543Smrg format = *(GLenum *)(pc + 16); 791706f2543Smrg type = *(GLenum *)(pc + 20); 792706f2543Smrg swapBytes = *(GLboolean *)(pc + 24); 793706f2543Smrg lsbFirst = *(GLboolean *)(pc + 25); 794706f2543Smrg 795706f2543Smrg if (client->swapped) { 796706f2543Smrg __GLX_SWAP_INT(&x); 797706f2543Smrg __GLX_SWAP_INT(&y); 798706f2543Smrg __GLX_SWAP_INT(&width); 799706f2543Smrg __GLX_SWAP_INT(&height); 800706f2543Smrg __GLX_SWAP_INT(&format); 801706f2543Smrg __GLX_SWAP_INT(&type); 802706f2543Smrg swapBytes = !swapBytes; 803706f2543Smrg } 804706f2543Smrg 805706f2543Smrg buf_size = __glReadPixels_size(format,type,width,height, &ebits, &rowsize); 806706f2543Smrg if (buf_size > 0) { 807706f2543Smrg buf = (char *) malloc( buf_size ); 808706f2543Smrg if ( !buf ) { 809706f2543Smrg return BadAlloc; 810706f2543Smrg } 811706f2543Smrg } 812706f2543Smrg else { 813706f2543Smrg buf_size = 0; 814706f2543Smrg buf = NULL; 815706f2543Smrg } 816706f2543Smrg 817706f2543Smrg if (buf_size > 0) { 818706f2543Smrg /* 819706f2543Smrg * Get the current drawable this context is bound to 820706f2543Smrg */ 821706f2543Smrg pDraw = __glXLookupDrawableByTag( cl, req->contextTag ); 822706f2543Smrg win_x1 = pDraw->x + x; 823706f2543Smrg win_x2 = win_x1 + width - 1; 824706f2543Smrg win_y1 = (dmxGlobalHeight - pDraw->y - pDraw->height) + y; 825706f2543Smrg win_y2 = win_y1 + height - 1; 826706f2543Smrg if (pDraw->type != DRAWABLE_WINDOW) { 827706f2543Smrg from_screen = to_screen = 0; 828706f2543Smrg } 829706f2543Smrg 830706f2543Smrg for (s=from_screen; s<=to_screen; s++) { 831706f2543Smrg DMXScreenInfo *dmxScreen = &dmxScreens[s]; 832706f2543Smrg Display *dpy = GetBackEndDisplay(cl,s); 833706f2543Smrg int scr_x1 = dmxScreen->rootXOrigin; 834706f2543Smrg int scr_x2 = dmxScreen->rootXOrigin + dmxScreen->scrnWidth - 1; 835706f2543Smrg int scr_y1 = dmxScreen->rootYOrigin; 836706f2543Smrg int scr_y2 = dmxScreen->rootYOrigin + dmxScreen->scrnHeight - 1; 837706f2543Smrg int wx1, wx2, wy1, wy2; 838706f2543Smrg int sx, sy, sw, sh; 839706f2543Smrg int npixels; 840706f2543Smrg 841706f2543Smrg /* 842706f2543Smrg * find the window portion that is on the current screen 843706f2543Smrg */ 844706f2543Smrg if (pDraw->type == DRAWABLE_WINDOW) { 845706f2543Smrg npixels = intersectRect( scr_x1, scr_x2, scr_y1, scr_y2, 846706f2543Smrg win_x1, win_x2, win_y1, win_y2, 847706f2543Smrg &wx1, &wx2, &wy1, &wy2 ); 848706f2543Smrg } 849706f2543Smrg else { 850706f2543Smrg wx1 = win_x1; 851706f2543Smrg wx2 = win_x2; 852706f2543Smrg wy1 = win_y1; 853706f2543Smrg wy2 = win_y2; 854706f2543Smrg npixels = (wx2-wx1+1) * (wy2-wy1+1); 855706f2543Smrg } 856706f2543Smrg 857706f2543Smrg if (npixels > 0) { 858706f2543Smrg 859706f2543Smrg /* send the request to the back-end server */ 860706f2543Smrg LockDisplay(dpy); 861706f2543Smrg GetReqExtra(GLXSingle,__GLX_PAD(26),be_req); 862706f2543Smrg be_req->reqType = dmxScreen->glxMajorOpcode; 863706f2543Smrg be_req->glxCode = X_GLsop_ReadPixels; 864706f2543Smrg be_req->contextTag = GetCurrentBackEndTag(cl,req->contextTag,s); 865706f2543Smrg be_pc = ((GLbyte *)(be_req) + sz_xGLXSingleReq); 866706f2543Smrg 867706f2543Smrg sx = wx1 - pDraw->x; 868706f2543Smrg sy = wy1 - (dmxGlobalHeight - pDraw->y - pDraw->height); 869706f2543Smrg sw = (wx2-wx1+1); 870706f2543Smrg sh = (wy2-wy1+1); 871706f2543Smrg 872706f2543Smrg *(GLint *)(be_pc + 0) = sx; /* x */ 873706f2543Smrg *(GLint *)(be_pc + 4) = sy; /* y */ 874706f2543Smrg *(GLsizei *)(be_pc + 8) = sw; /* width */ 875706f2543Smrg *(GLsizei *)(be_pc + 12) = sh; /* height */ 876706f2543Smrg *(GLenum *)(be_pc + 16) = format; 877706f2543Smrg *(GLenum *)(be_pc + 20) = type; 878706f2543Smrg *(GLboolean *)(be_pc + 24) = swapBytes; 879706f2543Smrg *(GLboolean *)(be_pc + 25) = lsbFirst; 880706f2543Smrg 881706f2543Smrg _XReply(dpy, (xReply*) &be_reply, 0, False); 882706f2543Smrg 883706f2543Smrg if (be_reply.length > 0) { 884706f2543Smrg char *be_buf; 885706f2543Smrg int be_buf_size = be_reply.length << 2; 886706f2543Smrg 887706f2543Smrg be_buf = (char *) malloc( be_buf_size ); 888706f2543Smrg if (be_buf) { 889706f2543Smrg _XRead(dpy, be_buf, be_buf_size); 890706f2543Smrg 891706f2543Smrg /* copy pixels data to the right location of the */ 892706f2543Smrg /* reply buffer */ 893706f2543Smrg if ( type != GL_BITMAP ) { 894706f2543Smrg int pbytes = ebits / 8; 895706f2543Smrg char *dst = buf + (sy-y)*rowsize + (sx-x)*pbytes; 896706f2543Smrg char *src = be_buf; 897706f2543Smrg int pad = (pbytes * sw) % 4; 898706f2543Smrg int r; 899706f2543Smrg 900706f2543Smrg for (r=0; r<sh; r++) { 901706f2543Smrg memcpy( dst, src, pbytes*sw ); 902706f2543Smrg dst += rowsize; 903706f2543Smrg src += (pbytes*sw + (pad ? 4-pad : 0) ); 904706f2543Smrg } 905706f2543Smrg } 906706f2543Smrg else { 907706f2543Smrg /* this is a GL_BITMAP pixel type, should copy bits */ 908706f2543Smrg int r; 909706f2543Smrg int src_rowsize = bits_to_bytes(sw * ebits); 910706f2543Smrg int src_pad = src_rowsize % 4; 911706f2543Smrg if ( src_pad ) { 912706f2543Smrg src_rowsize += (4 - src_pad); 913706f2543Smrg } 914706f2543Smrg 915706f2543Smrg for (r=0; r<sh; r++) { 916706f2543Smrg unsigned char dst_mask = 0x80 >> (sx % 8); 917706f2543Smrg unsigned char src_mask = 0x80; 918706f2543Smrg char *dst = buf + (sy-y+r)*rowsize + (sx-x)/8; 919706f2543Smrg char *src = be_buf + r*src_rowsize; 920706f2543Smrg int b; 921706f2543Smrg 922706f2543Smrg for (b=0; b<sw*ebits; b++) { 923706f2543Smrg if ( *src & src_mask ) { 924706f2543Smrg *dst |= dst_mask; 925706f2543Smrg } 926706f2543Smrg else { 927706f2543Smrg *dst &= ~dst_mask; 928706f2543Smrg } 929706f2543Smrg 930706f2543Smrg if (dst_mask > 1) dst_mask >>= 1; 931706f2543Smrg else { 932706f2543Smrg dst_mask = 0x80; 933706f2543Smrg dst++; 934706f2543Smrg } 935706f2543Smrg 936706f2543Smrg if (src_mask > 1) src_mask >>= 1; 937706f2543Smrg else { 938706f2543Smrg src_mask = 0x80; 939706f2543Smrg src++; 940706f2543Smrg } 941706f2543Smrg } 942706f2543Smrg } 943706f2543Smrg 944706f2543Smrg } 945706f2543Smrg 946706f2543Smrg free( be_buf ); 947706f2543Smrg } 948706f2543Smrg else { 949706f2543Smrg /* Throw data on the floor */ 950706f2543Smrg _XEatData(dpy, be_buf_size); 951706f2543Smrg free( buf ); 952706f2543Smrg return BadAlloc; 953706f2543Smrg } 954706f2543Smrg } 955706f2543Smrg 956706f2543Smrg UnlockDisplay(dpy); 957706f2543Smrg SyncHandle(); 958706f2543Smrg 959706f2543Smrg } /* of npixels > 0 */ 960706f2543Smrg 961706f2543Smrg } /* of for loop */ 962706f2543Smrg 963706f2543Smrg } /* of if buf_size > 0 */ 964706f2543Smrg 965706f2543Smrg reply.type = X_Reply; 966706f2543Smrg reply.sequenceNumber = client->sequence; 967706f2543Smrg reply.length = buf_size >> 2; 968706f2543Smrg 969706f2543Smrg if (client->swapped) { 970706f2543Smrg __GLX_SWAP_SHORT(&reply.sequenceNumber); 971706f2543Smrg __GLX_SWAP_INT(&reply.length); 972706f2543Smrg } 973706f2543Smrg 974706f2543Smrg WriteToClient(client, sizeof(xGLXReadPixelsReply),(char *)&reply); 975706f2543Smrg if (buf_size > 0) { 976706f2543Smrg WriteToClient(client, buf_size, (char *)buf); 977706f2543Smrg free( buf ); 978706f2543Smrg } 979706f2543Smrg 980706f2543Smrg return Success; 981706f2543Smrg} 982706f2543Smrg 983706f2543Smrgint __glXDispSwap_GetTexImage(__GLXclientState *cl, GLbyte *pc) 984706f2543Smrg{ 985706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 986706f2543Smrg GLbyte *lpc = pc; 987706f2543Smrg 988706f2543Smrg lpc += sz_xGLXSingleReq; 989706f2543Smrg __GLX_SWAP_INT(lpc+0); 990706f2543Smrg __GLX_SWAP_INT(lpc+4); 991706f2543Smrg __GLX_SWAP_INT(lpc+8); 992706f2543Smrg __GLX_SWAP_INT(lpc+12); 993706f2543Smrg 994706f2543Smrg /* reverse swapBytes */ 995706f2543Smrg *(GLboolean *)(lpc + 16) = ! *(GLboolean *)(lpc + 16); 996706f2543Smrg 997706f2543Smrg return( __glXForwardPipe0WithReplySwap( cl, pc ) ); 998706f2543Smrg} 999706f2543Smrg 1000706f2543Smrgint __glXDispSwap_GetColorTable(__GLXclientState *cl, GLbyte *pc) 1001706f2543Smrg{ 1002706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 1003706f2543Smrg GLbyte *lpc = pc; 1004706f2543Smrg 1005706f2543Smrg lpc += sz_xGLXSingleReq; 1006706f2543Smrg __GLX_SWAP_INT(lpc+0); 1007706f2543Smrg __GLX_SWAP_INT(lpc+4); 1008706f2543Smrg __GLX_SWAP_INT(lpc+8); 1009706f2543Smrg 1010706f2543Smrg /* reverse swapBytes */ 1011706f2543Smrg *(GLboolean *)(lpc + 12) = ! *(GLboolean *)(lpc + 12); 1012706f2543Smrg 1013706f2543Smrg return( __glXForwardPipe0WithReplySwap( cl, pc ) ); 1014706f2543Smrg} 1015706f2543Smrg 1016706f2543Smrg 1017