14642e01fSmrg#ifdef HAVE_DIX_CONFIG_H 24642e01fSmrg#include <dix-config.h> 34642e01fSmrg#endif 44642e01fSmrg 54642e01fSmrg#ifndef __GLX_unpack_h__ 64642e01fSmrg#define __GLX_unpack_h__ 74642e01fSmrg 84642e01fSmrg/* 94642e01fSmrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 104642e01fSmrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 114642e01fSmrg * 124642e01fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 134642e01fSmrg * copy of this software and associated documentation files (the "Software"), 144642e01fSmrg * to deal in the Software without restriction, including without limitation 154642e01fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 164642e01fSmrg * and/or sell copies of the Software, and to permit persons to whom the 174642e01fSmrg * Software is furnished to do so, subject to the following conditions: 184642e01fSmrg * 194642e01fSmrg * The above copyright notice including the dates of first publication and 204642e01fSmrg * either this permission notice or a reference to 214642e01fSmrg * http://oss.sgi.com/projects/FreeB/ 224642e01fSmrg * shall be included in all copies or substantial portions of the Software. 234642e01fSmrg * 244642e01fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 254642e01fSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 264642e01fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 274642e01fSmrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 284642e01fSmrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 294642e01fSmrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 304642e01fSmrg * SOFTWARE. 314642e01fSmrg * 324642e01fSmrg * Except as contained in this notice, the name of Silicon Graphics, Inc. 334642e01fSmrg * shall not be used in advertising or otherwise to promote the sale, use or 344642e01fSmrg * other dealings in this Software without prior written authorization from 354642e01fSmrg * Silicon Graphics, Inc. 364642e01fSmrg */ 374642e01fSmrg 384642e01fSmrg#define __GLX_PAD(s) (((s)+3) & (GLuint)~3) 394642e01fSmrg 404642e01fSmrg/* 414642e01fSmrg** Fetch the context-id out of a SingleReq request pointed to by pc. 424642e01fSmrg*/ 434642e01fSmrg#define __GLX_GET_SINGLE_CONTEXT_TAG(pc) (((xGLXSingleReq*)pc)->contextTag) 444642e01fSmrg#define __GLX_GET_VENDPRIV_CONTEXT_TAG(pc) (((xGLXVendorPrivateReq*)pc)->contextTag) 454642e01fSmrg 464642e01fSmrg/* 474642e01fSmrg** Fetch a double from potentially unaligned memory. 484642e01fSmrg*/ 494642e01fSmrg#ifdef __GLX_ALIGN64 509ace9065Smrg#define __GLX_MEM_COPY(dst,src,n) memmove(dst,src,n) 514642e01fSmrg#define __GLX_GET_DOUBLE(dst,src) __GLX_MEM_COPY(&dst,src,8) 524642e01fSmrg#else 534642e01fSmrg#define __GLX_GET_DOUBLE(dst,src) (dst) = *((GLdouble*)(src)) 544642e01fSmrg#endif 554642e01fSmrg 564642e01fSmrg#define __GLX_BEGIN_REPLY(size) \ 577e31ba66Smrg reply.length = __GLX_PAD(size) >> 2; \ 587e31ba66Smrg reply.type = X_Reply; \ 597e31ba66Smrg reply.sequenceNumber = client->sequence; 604642e01fSmrg 614642e01fSmrg#define __GLX_SEND_HEADER() \ 627e31ba66Smrg WriteToClient (client, sz_xGLXSingleReply, &reply); 634642e01fSmrg 644642e01fSmrg#define __GLX_PUT_RETVAL(a) \ 657e31ba66Smrg reply.retval = (a); 66f7df2e56Smrg 674642e01fSmrg#define __GLX_PUT_SIZE(a) \ 687e31ba66Smrg reply.size = (a); 694642e01fSmrg 704642e01fSmrg/* 714642e01fSmrg** Get a buffer to hold returned data, with the given alignment. If we have 724642e01fSmrg** to realloc, allocate size+align, in case the pointer has to be bumped for 734642e01fSmrg** alignment. The answerBuffer should already be aligned. 744642e01fSmrg** 754642e01fSmrg** NOTE: the cast (long)res below assumes a long is large enough to hold a 764642e01fSmrg** pointer. 774642e01fSmrg*/ 784642e01fSmrg#define __GLX_GET_ANSWER_BUFFER(res,cl,size,align) \ 790b0d8713Smrg if (size < 0) return BadLength; \ 800b0d8713Smrg else if ((size) > sizeof(answerBuffer)) { \ 814642e01fSmrg int bump; \ 824642e01fSmrg if ((cl)->returnBufSize < (size)+(align)) { \ 836747b715Smrg (cl)->returnBuf = (GLbyte*)realloc((cl)->returnBuf, \ 844642e01fSmrg (size)+(align)); \ 854642e01fSmrg if (!(cl)->returnBuf) { \ 864642e01fSmrg return BadAlloc; \ 874642e01fSmrg } \ 884642e01fSmrg (cl)->returnBufSize = (size)+(align); \ 894642e01fSmrg } \ 904642e01fSmrg res = (char*)cl->returnBuf; \ 914642e01fSmrg bump = (long)(res) % (align); \ 924642e01fSmrg if (bump) res += (align) - (bump); \ 934642e01fSmrg } else { \ 944642e01fSmrg res = (char *)answerBuffer; \ 954642e01fSmrg } 964642e01fSmrg 974642e01fSmrg#define __GLX_SEND_BYTE_ARRAY(len) \ 98f7df2e56Smrg WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), answer) 994642e01fSmrg 1004642e01fSmrg#define __GLX_SEND_SHORT_ARRAY(len) \ 101f7df2e56Smrg WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), answer) 102f7df2e56Smrg 1034642e01fSmrg#define __GLX_SEND_INT_ARRAY(len) \ 104f7df2e56Smrg WriteToClient(client, (len)*__GLX_SIZE_INT32, answer) 105f7df2e56Smrg 1064642e01fSmrg#define __GLX_SEND_FLOAT_ARRAY(len) \ 107f7df2e56Smrg WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, answer) 1084642e01fSmrg 109f7df2e56Smrg#define __GLX_SEND_DOUBLE_ARRAY(len) \ 110f7df2e56Smrg WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, answer) 1114642e01fSmrg 1124642e01fSmrg#define __GLX_SEND_VOID_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len) 1134642e01fSmrg#define __GLX_SEND_UBYTE_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len) 1144642e01fSmrg#define __GLX_SEND_USHORT_ARRAY(len) __GLX_SEND_SHORT_ARRAY(len) 1154642e01fSmrg#define __GLX_SEND_UINT_ARRAY(len) __GLX_SEND_INT_ARRAY(len) 1164642e01fSmrg 1174642e01fSmrg/* 1184642e01fSmrg** PERFORMANCE NOTE: 1194642e01fSmrg** Machine dependent optimizations abound here; these swapping macros can 1204642e01fSmrg** conceivably be replaced with routines that do the job faster. 1214642e01fSmrg*/ 1224642e01fSmrg#define __GLX_DECLARE_SWAP_VARIABLES \ 1234642e01fSmrg GLbyte sw 1244642e01fSmrg 1254642e01fSmrg#define __GLX_DECLARE_SWAP_ARRAY_VARIABLES \ 1264642e01fSmrg GLbyte *swapPC; \ 1274642e01fSmrg GLbyte *swapEnd 1284642e01fSmrg 1294642e01fSmrg#define __GLX_SWAP_INT(pc) \ 1304642e01fSmrg sw = ((GLbyte *)(pc))[0]; \ 1314642e01fSmrg ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \ 1324642e01fSmrg ((GLbyte *)(pc))[3] = sw; \ 1334642e01fSmrg sw = ((GLbyte *)(pc))[1]; \ 1344642e01fSmrg ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \ 135f7df2e56Smrg ((GLbyte *)(pc))[2] = sw; 1364642e01fSmrg 1374642e01fSmrg#define __GLX_SWAP_SHORT(pc) \ 1384642e01fSmrg sw = ((GLbyte *)(pc))[0]; \ 1394642e01fSmrg ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[1]; \ 140f7df2e56Smrg ((GLbyte *)(pc))[1] = sw; 1414642e01fSmrg 1424642e01fSmrg#define __GLX_SWAP_DOUBLE(pc) \ 1434642e01fSmrg sw = ((GLbyte *)(pc))[0]; \ 1444642e01fSmrg ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[7]; \ 1454642e01fSmrg ((GLbyte *)(pc))[7] = sw; \ 1464642e01fSmrg sw = ((GLbyte *)(pc))[1]; \ 1474642e01fSmrg ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[6]; \ 1484642e01fSmrg ((GLbyte *)(pc))[6] = sw; \ 1494642e01fSmrg sw = ((GLbyte *)(pc))[2]; \ 1504642e01fSmrg ((GLbyte *)(pc))[2] = ((GLbyte *)(pc))[5]; \ 1514642e01fSmrg ((GLbyte *)(pc))[5] = sw; \ 1524642e01fSmrg sw = ((GLbyte *)(pc))[3]; \ 1534642e01fSmrg ((GLbyte *)(pc))[3] = ((GLbyte *)(pc))[4]; \ 154f7df2e56Smrg ((GLbyte *)(pc))[4] = sw; 1554642e01fSmrg 1564642e01fSmrg#define __GLX_SWAP_FLOAT(pc) \ 1574642e01fSmrg sw = ((GLbyte *)(pc))[0]; \ 1584642e01fSmrg ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \ 1594642e01fSmrg ((GLbyte *)(pc))[3] = sw; \ 1604642e01fSmrg sw = ((GLbyte *)(pc))[1]; \ 1614642e01fSmrg ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \ 162f7df2e56Smrg ((GLbyte *)(pc))[2] = sw; 1634642e01fSmrg 1644642e01fSmrg#define __GLX_SWAP_INT_ARRAY(pc, count) \ 1654642e01fSmrg swapPC = ((GLbyte *)(pc)); \ 1664642e01fSmrg swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT32;\ 1674642e01fSmrg while (swapPC < swapEnd) { \ 1684642e01fSmrg __GLX_SWAP_INT(swapPC); \ 1694642e01fSmrg swapPC += __GLX_SIZE_INT32; \ 1704642e01fSmrg } 171f7df2e56Smrg 1724642e01fSmrg#define __GLX_SWAP_SHORT_ARRAY(pc, count) \ 1734642e01fSmrg swapPC = ((GLbyte *)(pc)); \ 1744642e01fSmrg swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT16;\ 1754642e01fSmrg while (swapPC < swapEnd) { \ 1764642e01fSmrg __GLX_SWAP_SHORT(swapPC); \ 1774642e01fSmrg swapPC += __GLX_SIZE_INT16; \ 1784642e01fSmrg } 179f7df2e56Smrg 1804642e01fSmrg#define __GLX_SWAP_DOUBLE_ARRAY(pc, count) \ 1814642e01fSmrg swapPC = ((GLbyte *)(pc)); \ 1824642e01fSmrg swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT64;\ 1834642e01fSmrg while (swapPC < swapEnd) { \ 1844642e01fSmrg __GLX_SWAP_DOUBLE(swapPC); \ 1854642e01fSmrg swapPC += __GLX_SIZE_FLOAT64; \ 1864642e01fSmrg } 187f7df2e56Smrg 1884642e01fSmrg#define __GLX_SWAP_FLOAT_ARRAY(pc, count) \ 1894642e01fSmrg swapPC = ((GLbyte *)(pc)); \ 1904642e01fSmrg swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT32;\ 1914642e01fSmrg while (swapPC < swapEnd) { \ 1924642e01fSmrg __GLX_SWAP_FLOAT(swapPC); \ 1934642e01fSmrg swapPC += __GLX_SIZE_FLOAT32; \ 1944642e01fSmrg } 1954642e01fSmrg 1964642e01fSmrg#define __GLX_SWAP_REPLY_HEADER() \ 1977e31ba66Smrg __GLX_SWAP_SHORT(&reply.sequenceNumber); \ 1987e31ba66Smrg __GLX_SWAP_INT(&reply.length); 1994642e01fSmrg 2004642e01fSmrg#define __GLX_SWAP_REPLY_RETVAL() \ 2017e31ba66Smrg __GLX_SWAP_INT(&reply.retval) 2024642e01fSmrg 2034642e01fSmrg#define __GLX_SWAP_REPLY_SIZE() \ 2047e31ba66Smrg __GLX_SWAP_INT(&reply.size) 2054642e01fSmrg 206f7df2e56Smrg#endif /* !__GLX_unpack_h__ */ 207