xserver

xserver with xephyr scale patch
git clone https://git.neptards.moe/u3shit/xserver.git
Log | Files | Refs | README | LICENSE

unpack.h (7014B)


      1 #ifdef HAVE_DIX_CONFIG_H
      2 #include <dix-config.h>
      3 #endif
      4 
      5 #ifndef __GLX_unpack_h__
      6 #define __GLX_unpack_h__
      7 
      8 /*
      9  * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
     10  * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
     11  *
     12  * Permission is hereby granted, free of charge, to any person obtaining a
     13  * copy of this software and associated documentation files (the "Software"),
     14  * to deal in the Software without restriction, including without limitation
     15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     16  * and/or sell copies of the Software, and to permit persons to whom the
     17  * Software is furnished to do so, subject to the following conditions:
     18  *
     19  * The above copyright notice including the dates of first publication and
     20  * either this permission notice or a reference to
     21  * http://oss.sgi.com/projects/FreeB/
     22  * shall be included in all copies or substantial portions of the Software.
     23  *
     24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     25  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
     27  * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
     28  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
     29  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     30  * SOFTWARE.
     31  *
     32  * Except as contained in this notice, the name of Silicon Graphics, Inc.
     33  * shall not be used in advertising or otherwise to promote the sale, use or
     34  * other dealings in this Software without prior written authorization from
     35  * Silicon Graphics, Inc.
     36  */
     37 
     38 #define __GLX_PAD(s) (((s)+3) & (GLuint)~3)
     39 
     40 /*
     41 ** Fetch the context-id out of a SingleReq request pointed to by pc.
     42 */
     43 #define __GLX_GET_SINGLE_CONTEXT_TAG(pc) (((xGLXSingleReq*)pc)->contextTag)
     44 #define __GLX_GET_VENDPRIV_CONTEXT_TAG(pc) (((xGLXVendorPrivateReq*)pc)->contextTag)
     45 
     46 /*
     47 ** Fetch a double from potentially unaligned memory.
     48 */
     49 #ifdef __GLX_ALIGN64
     50 #define __GLX_MEM_COPY(dst,src,n)	memmove(dst,src,n)
     51 #define __GLX_GET_DOUBLE(dst,src)	__GLX_MEM_COPY(&dst,src,8)
     52 #else
     53 #define __GLX_GET_DOUBLE(dst,src)	(dst) = *((GLdouble*)(src))
     54 #endif
     55 
     56 #define __GLX_BEGIN_REPLY(size) \
     57 	reply.length = __GLX_PAD(size) >> 2;	\
     58 	reply.type = X_Reply; 			\
     59 	reply.sequenceNumber = client->sequence;
     60 
     61 #define __GLX_SEND_HEADER() \
     62 	WriteToClient (client, sz_xGLXSingleReply, &reply);
     63 
     64 #define __GLX_PUT_RETVAL(a) \
     65 	reply.retval = (a);
     66 
     67 #define __GLX_PUT_SIZE(a) \
     68 	reply.size = (a);
     69 
     70 /*
     71 ** Get a buffer to hold returned data, with the given alignment.  If we have
     72 ** to realloc, allocate size+align, in case the pointer has to be bumped for
     73 ** alignment.  The answerBuffer should already be aligned.
     74 **
     75 ** NOTE: the cast (long)res below assumes a long is large enough to hold a
     76 ** pointer.
     77 */
     78 #define __GLX_GET_ANSWER_BUFFER(res,cl,size,align)			 \
     79     if (size < 0) return BadLength;                                      \
     80     else if ((size) > sizeof(answerBuffer)) {				 \
     81 	int bump;							 \
     82 	if ((cl)->returnBufSize < (size)+(align)) {			 \
     83 	    (cl)->returnBuf = (GLbyte*)realloc((cl)->returnBuf,	 	 \
     84 						(size)+(align));         \
     85 	    if (!(cl)->returnBuf) {					 \
     86 		return BadAlloc;					 \
     87 	    }								 \
     88 	    (cl)->returnBufSize = (size)+(align);			 \
     89 	}								 \
     90 	res = (char*)cl->returnBuf;					 \
     91 	bump = (long)(res) % (align);					 \
     92 	if (bump) res += (align) - (bump);				 \
     93     } else {								 \
     94 	res = (char *)answerBuffer;					 \
     95     }
     96 
     97 #define __GLX_SEND_BYTE_ARRAY(len) \
     98 	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), answer)
     99 
    100 #define __GLX_SEND_SHORT_ARRAY(len) \
    101 	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), answer)
    102 
    103 #define __GLX_SEND_INT_ARRAY(len) \
    104 	WriteToClient(client, (len)*__GLX_SIZE_INT32, answer)
    105 
    106 #define __GLX_SEND_FLOAT_ARRAY(len) \
    107 	WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, answer)
    108 
    109 #define __GLX_SEND_DOUBLE_ARRAY(len) \
    110 	WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, answer)
    111 
    112 #define __GLX_SEND_VOID_ARRAY(len)  __GLX_SEND_BYTE_ARRAY(len)
    113 #define __GLX_SEND_UBYTE_ARRAY(len)  __GLX_SEND_BYTE_ARRAY(len)
    114 #define __GLX_SEND_USHORT_ARRAY(len) __GLX_SEND_SHORT_ARRAY(len)
    115 #define __GLX_SEND_UINT_ARRAY(len)  __GLX_SEND_INT_ARRAY(len)
    116 
    117 /*
    118 ** PERFORMANCE NOTE:
    119 ** Machine dependent optimizations abound here; these swapping macros can
    120 ** conceivably be replaced with routines that do the job faster.
    121 */
    122 #define __GLX_DECLARE_SWAP_VARIABLES \
    123 	GLbyte sw
    124 
    125 #define __GLX_DECLARE_SWAP_ARRAY_VARIABLES \
    126   	GLbyte *swapPC;		\
    127   	GLbyte *swapEnd
    128 
    129 #define __GLX_SWAP_INT(pc) 			\
    130   	sw = ((GLbyte *)(pc))[0]; 		\
    131   	((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; 	\
    132   	((GLbyte *)(pc))[3] = sw; 		\
    133   	sw = ((GLbyte *)(pc))[1]; 		\
    134   	((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; 	\
    135   	((GLbyte *)(pc))[2] = sw;
    136 
    137 #define __GLX_SWAP_SHORT(pc) \
    138   	sw = ((GLbyte *)(pc))[0]; 		\
    139   	((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[1]; 	\
    140   	((GLbyte *)(pc))[1] = sw;
    141 
    142 #define __GLX_SWAP_DOUBLE(pc) \
    143   	sw = ((GLbyte *)(pc))[0]; 		\
    144   	((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[7]; 	\
    145   	((GLbyte *)(pc))[7] = sw; 		\
    146   	sw = ((GLbyte *)(pc))[1]; 		\
    147   	((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[6]; 	\
    148   	((GLbyte *)(pc))[6] = sw;			\
    149   	sw = ((GLbyte *)(pc))[2]; 		\
    150   	((GLbyte *)(pc))[2] = ((GLbyte *)(pc))[5]; 	\
    151   	((GLbyte *)(pc))[5] = sw;			\
    152   	sw = ((GLbyte *)(pc))[3]; 		\
    153   	((GLbyte *)(pc))[3] = ((GLbyte *)(pc))[4]; 	\
    154   	((GLbyte *)(pc))[4] = sw;
    155 
    156 #define __GLX_SWAP_FLOAT(pc) \
    157   	sw = ((GLbyte *)(pc))[0]; 		\
    158   	((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; 	\
    159   	((GLbyte *)(pc))[3] = sw; 		\
    160   	sw = ((GLbyte *)(pc))[1]; 		\
    161   	((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; 	\
    162   	((GLbyte *)(pc))[2] = sw;
    163 
    164 #define __GLX_SWAP_INT_ARRAY(pc, count) \
    165   	swapPC = ((GLbyte *)(pc));		\
    166   	swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT32;\
    167   	while (swapPC < swapEnd) {		\
    168 	    __GLX_SWAP_INT(swapPC);		\
    169 	    swapPC += __GLX_SIZE_INT32;		\
    170 	}
    171 
    172 #define __GLX_SWAP_SHORT_ARRAY(pc, count) \
    173   	swapPC = ((GLbyte *)(pc));		\
    174   	swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT16;\
    175   	while (swapPC < swapEnd) {		\
    176 	    __GLX_SWAP_SHORT(swapPC);		\
    177 	    swapPC += __GLX_SIZE_INT16;		\
    178 	}
    179 
    180 #define __GLX_SWAP_DOUBLE_ARRAY(pc, count) \
    181   	swapPC = ((GLbyte *)(pc));		\
    182   	swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT64;\
    183   	while (swapPC < swapEnd) {		\
    184 	    __GLX_SWAP_DOUBLE(swapPC);		\
    185 	    swapPC += __GLX_SIZE_FLOAT64;	\
    186 	}
    187 
    188 #define __GLX_SWAP_FLOAT_ARRAY(pc, count) \
    189   	swapPC = ((GLbyte *)(pc));		\
    190   	swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT32;\
    191   	while (swapPC < swapEnd) {		\
    192 	    __GLX_SWAP_FLOAT(swapPC);		\
    193 	    swapPC += __GLX_SIZE_FLOAT32;	\
    194 	}
    195 
    196 #define __GLX_SWAP_REPLY_HEADER() \
    197 	__GLX_SWAP_SHORT(&reply.sequenceNumber); \
    198 	__GLX_SWAP_INT(&reply.length);
    199 
    200 #define __GLX_SWAP_REPLY_RETVAL() \
    201 	__GLX_SWAP_INT(&reply.retval)
    202 
    203 #define __GLX_SWAP_REPLY_SIZE() \
    204 	__GLX_SWAP_INT(&reply.size)
    205 
    206 #endif                          /* !__GLX_unpack_h__ */