1 /* DO NOT EDIT - THIS FILE IS AUTOMATICALLY GENERATED */
3 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
4 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice including the dates of first publication and
14 * either this permission notice or a reference to
15 * http://oss.sgi.com/projects/FreeB/
16 * shall be included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Except as contained in this notice, the name of Silicon Graphics, Inc.
27 * shall not be used in advertising or otherwise to promote the sale, use or
28 * other dealings in this Software without prior written authorization from
29 * Silicon Graphics, Inc.
32 #ifdef HAVE_DMX_CONFIG_H
33 #include <dmx-config.h>
37 #include "dmxwindow.h"
38 #include "dmxpixmap.h"
42 #include "glxserver.h"
44 #include "g_disptab.h"
45 /* #include "g_disptab_EXT.h" */
49 #include "GL/glxproto.h"
52 #include "panoramiXsrv.h"
56 * GetReqSingle - this is the equivalent of GetReq macro
57 * from Xlibint.h but it does not set the reqType field (the opcode).
58 * this is because the GL single opcodes has different naming convension
59 * the other X opcodes (ie. X_GLsop_GetFloatv).
61 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
62 #define GetReqSingle(name, req) \
64 if ((dpy->bufptr + SIZEOF(x##name##Req)) > dpy->bufmax)\
66 req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
67 req->length = (SIZEOF(x##name##Req))>>2;\
68 dpy->bufptr += SIZEOF(x##name##Req);\
71 #else /* non-ANSI C uses empty comment instead of "##" for token concatenation */
72 #define GetReqSingle(name, req) \
74 if ((dpy->bufptr + SIZEOF(x/**/name/**/Req)) > dpy->bufmax)\
76 req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
77 req->length = (SIZEOF(x/**/name/**/Req))>>2;\
78 dpy->bufptr += SIZEOF(x/**/name/**/Req);\
82 #define X_GLXSingle 0 /* needed by GetReqExtra */
84 extern Display
*GetBackEndDisplay(__GLXclientState
* cl
, int s
);
85 extern int GetCurrentBackEndTag(__GLXclientState
* cl
, GLXContextTag tag
,
88 static int swap_vec_element_size
= 0;
91 SendSwappedReply(ClientPtr client
,
92 xGLXSingleReply
* reply
, char *buf
, int buf_size
)
94 __GLX_DECLARE_SWAP_VARIABLES
;
95 __GLX_SWAP_SHORT(&reply
->sequenceNumber
);
96 __GLX_SWAP_INT(&reply
->length
);
97 __GLX_SWAP_INT(&reply
->retval
);
98 __GLX_SWAP_INT(&reply
->size
);
100 if ((buf_size
== 0) && (swap_vec_element_size
> 0)) {
102 * the reply has single component - need to swap pad3
104 if (swap_vec_element_size
== 2) {
105 __GLX_SWAP_SHORT(&reply
->pad3
);
107 else if (swap_vec_element_size
== 4) {
108 __GLX_SWAP_INT(&reply
->pad3
);
109 __GLX_SWAP_INT(&reply
->pad4
); /* some requests use also pad4
110 * i.e GetConvolutionFilter
113 else if (swap_vec_element_size
== 8) {
114 __GLX_SWAP_DOUBLE(&reply
->pad3
);
117 else if ((buf_size
> 0) && (swap_vec_element_size
> 0)) {
119 * the reply has vector of elements which needs to be swapped
121 int vsize
= buf_size
/ swap_vec_element_size
;
125 for (i
= 0; i
< vsize
; i
++) {
126 if (swap_vec_element_size
== 2) {
129 else if (swap_vec_element_size
== 4) {
132 else if (swap_vec_element_size
== 8) {
133 __GLX_SWAP_DOUBLE(p
);
136 p
+= swap_vec_element_size
;
140 * swap pad words as well - for case that some single reply uses
143 __GLX_SWAP_INT(&reply
->pad3
);
144 __GLX_SWAP_INT(&reply
->pad4
);
145 __GLX_SWAP_INT(&reply
->pad5
);
146 __GLX_SWAP_INT(&reply
->pad6
);
150 WriteToClient(client
, sizeof(xGLXSingleReply
), reply
);
152 WriteToClient(client
, buf_size
, buf
);
157 __glXForwardSingleReq(__GLXclientState
* cl
, GLbyte
* pc
)
159 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
160 xGLXSingleReq
*be_req
;
167 glxc
= __glXLookupContextByTag(cl
, req
->contextTag
);
171 from_screen
= to_screen
= glxc
->pScreen
->myNum
;
174 if (!noPanoramiXExtension
) {
176 to_screen
= screenInfo
.numScreens
- 1;
180 pc
+= sz_xGLXSingleReq
;
181 buf_size
= (req
->length
<< 2) - sz_xGLXSingleReq
;
184 * just forward the request to back-end server(s)
186 for (s
= from_screen
; s
<= to_screen
; s
++) {
187 DMXScreenInfo
*dmxScreen
= &dmxScreens
[s
];
188 Display
*dpy
= GetBackEndDisplay(cl
, s
);
191 GetReqSingle(GLXSingle
, be_req
);
192 be_req
->reqType
= dmxScreen
->glxMajorOpcode
;
193 be_req
->glxCode
= req
->glxCode
;
194 be_req
->length
= req
->length
;
195 be_req
->contextTag
= GetCurrentBackEndTag(cl
, req
->contextTag
, s
);
197 _XSend(dpy
, (const char *) pc
, buf_size
);
201 if (req
->glxCode
== X_GLsop_Flush
) {
211 __glXForwardPipe0WithReply(__GLXclientState
* cl
, GLbyte
* pc
)
213 ClientPtr client
= cl
->client
;
214 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
215 xGLXSingleReq
*be_req
;
216 xGLXSingleReply reply
;
217 xGLXSingleReply be_reply
;
222 DMXScreenInfo
*dmxScreen
;
225 glxc
= __glXLookupContextByTag(cl
, req
->contextTag
);
227 return __glXBadContext
;
230 pc
+= sz_xGLXSingleReq
;
231 buf_size
= (req
->length
<< 2) - sz_xGLXSingleReq
;
233 dmxScreen
= &dmxScreens
[glxc
->pScreen
->myNum
];
234 dpy
= GetBackEndDisplay(cl
, glxc
->pScreen
->myNum
);
237 * send the request to the first back-end server
240 GetReqSingle(GLXSingle
, be_req
);
241 be_req
->reqType
= dmxScreen
->glxMajorOpcode
;
242 be_req
->glxCode
= req
->glxCode
;
243 be_req
->length
= req
->length
;
245 GetCurrentBackEndTag(cl
, req
->contextTag
, glxc
->pScreen
->myNum
);
247 _XSend(dpy
, (const char *) pc
, buf_size
);
250 * get the reply from the back-end server
252 _XReply(dpy
, (xReply
*) &be_reply
, 0, False
);
253 be_buf_size
= be_reply
.length
<< 2;
254 if (be_buf_size
> 0) {
255 be_buf
= (char *) malloc(be_buf_size
);
257 _XRead(dpy
, be_buf
, be_buf_size
);
260 /* Throw data on the floor */
261 _XEatDataWords(dpy
, be_reply
.length
);
270 * send the reply to the client
272 reply
= (xGLXSingleReply
) {
274 .sequenceNumber
= client
->sequence
,
275 .length
= be_reply
.length
,
276 .retval
= be_reply
.retval
,
277 .size
= be_reply
.size
,
278 .pad3
= be_reply
.pad3
,
279 .pad4
= be_reply
.pad4
282 if (client
->swapped
) {
283 SendSwappedReply(client
, &reply
, be_buf
, be_buf_size
);
286 WriteToClient(client
, sizeof(xGLXSingleReply
), &reply
);
288 WriteToClient(client
, be_buf_size
, be_buf
);
298 __glXForwardAllWithReply(__GLXclientState
* cl
, GLbyte
* pc
)
300 ClientPtr client
= cl
->client
;
301 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
302 xGLXSingleReq
*be_req
;
303 xGLXSingleReply reply
;
304 xGLXSingleReply be_reply
;
313 DMXScreenInfo
*dmxScreen
;
316 glxc
= __glXLookupContextByTag(cl
, req
->contextTag
);
320 from_screen
= to_screen
= glxc
->pScreen
->myNum
;
323 if (!noPanoramiXExtension
) {
325 to_screen
= screenInfo
.numScreens
- 1;
329 pc
+= sz_xGLXSingleReq
;
330 buf_size
= (req
->length
<< 2) - sz_xGLXSingleReq
;
333 * send the request to the first back-end server(s)
335 for (s
= to_screen
; s
>= from_screen
; s
--) {
336 dmxScreen
= &dmxScreens
[s
];
337 dpy
= GetBackEndDisplay(cl
, s
);
340 GetReqSingle(GLXSingle
, be_req
);
341 be_req
->reqType
= dmxScreen
->glxMajorOpcode
;
342 be_req
->glxCode
= req
->glxCode
;
343 be_req
->length
= req
->length
;
344 be_req
->contextTag
= GetCurrentBackEndTag(cl
, req
->contextTag
, s
);
346 _XSend(dpy
, (const char *) pc
, buf_size
);
349 * get the reply from the back-end server
351 _XReply(dpy
, (xReply
*) &be_reply
, 0, False
);
352 if (s
== from_screen
) {
353 /* Save data from last reply to send on to client */
354 be_buf_size
= be_reply
.length
<< 2;
355 if (be_buf_size
> 0) {
356 be_buf
= malloc(be_buf_size
);
358 _XRead(dpy
, be_buf
, be_buf_size
);
361 /* Throw data on the floor */
362 _XEatDataWords(dpy
, be_reply
.length
);
368 /* Just discard data from all replies before the last one */
369 if (be_reply
.length
> 0)
370 _XEatDataWords(dpy
, be_reply
.length
);
378 * send the reply to the client
380 reply
= (xGLXSingleReply
) {
382 .sequenceNumber
= client
->sequence
,
383 .length
= be_reply
.length
,
384 .retval
= be_reply
.retval
,
385 .size
= be_reply
.size
,
386 .pad3
= be_reply
.pad3
,
387 .pad4
= be_reply
.pad4
390 if (client
->swapped
) {
391 SendSwappedReply(client
, &reply
, be_buf
, be_buf_size
);
394 WriteToClient(client
, sizeof(xGLXSingleReply
), &reply
);
396 WriteToClient(client
, be_buf_size
, be_buf
);
406 __glXForwardSingleReqSwap(__GLXclientState
* cl
, GLbyte
* pc
)
408 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
410 __GLX_DECLARE_SWAP_VARIABLES
;
411 __GLX_DECLARE_SWAP_ARRAY_VARIABLES
;
413 __GLX_SWAP_SHORT(&req
->length
);
414 __GLX_SWAP_INT(&req
->contextTag
);
416 swap_vec_element_size
= 0;
419 * swap extra data in request - assuming all data
420 * (if available) are arrays of 4 bytes components !
422 if (req
->length
> sz_xGLXSingleReq
/ 4) {
423 int *data
= (int *) (req
+ 1);
424 int count
= req
->length
- sz_xGLXSingleReq
/ 4;
426 __GLX_SWAP_INT_ARRAY(data
, count
);
429 return (__glXForwardSingleReq(cl
, pc
));
433 __glXForwardPipe0WithReplySwap(__GLXclientState
* cl
, GLbyte
* pc
)
435 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
437 __GLX_DECLARE_SWAP_VARIABLES
;
438 __GLX_DECLARE_SWAP_ARRAY_VARIABLES
;
440 __GLX_SWAP_SHORT(&req
->length
);
441 __GLX_SWAP_INT(&req
->contextTag
);
443 swap_vec_element_size
= 0;
446 * swap extra data in request - assuming all data
447 * (if available) are arrays of 4 bytes components !
449 if (req
->length
> sz_xGLXSingleReq
/ 4) {
450 int *data
= (int *) (req
+ 1);
451 int count
= req
->length
- sz_xGLXSingleReq
/ 4;
453 __GLX_SWAP_INT_ARRAY(data
, count
);
456 return (__glXForwardPipe0WithReply(cl
, pc
));
460 __glXForwardPipe0WithReplySwapsv(__GLXclientState
* cl
, GLbyte
* pc
)
462 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
464 __GLX_DECLARE_SWAP_VARIABLES
;
465 __GLX_DECLARE_SWAP_ARRAY_VARIABLES
;
467 __GLX_SWAP_SHORT(&req
->length
);
468 __GLX_SWAP_INT(&req
->contextTag
);
470 swap_vec_element_size
= 2;
473 * swap extra data in request - assuming all data
474 * (if available) are arrays of 4 bytes components !
476 if (req
->length
> sz_xGLXSingleReq
/ 4) {
477 int *data
= (int *) (req
+ 1);
478 int count
= req
->length
- sz_xGLXSingleReq
/ 4;
480 __GLX_SWAP_INT_ARRAY(data
, count
);
483 return (__glXForwardPipe0WithReply(cl
, pc
));
487 __glXForwardPipe0WithReplySwapiv(__GLXclientState
* cl
, GLbyte
* pc
)
489 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
491 __GLX_DECLARE_SWAP_VARIABLES
;
492 __GLX_DECLARE_SWAP_ARRAY_VARIABLES
;
494 __GLX_SWAP_SHORT(&req
->length
);
495 __GLX_SWAP_INT(&req
->contextTag
);
497 swap_vec_element_size
= 4;
500 * swap extra data in request - assuming all data
501 * (if available) are arrays of 4 bytes components !
503 if (req
->length
> sz_xGLXSingleReq
/ 4) {
504 int *data
= (int *) (req
+ 1);
505 int count
= req
->length
- sz_xGLXSingleReq
/ 4;
507 __GLX_SWAP_INT_ARRAY(data
, count
);
510 return (__glXForwardPipe0WithReply(cl
, pc
));
514 __glXForwardPipe0WithReplySwapdv(__GLXclientState
* cl
, GLbyte
* pc
)
516 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
518 __GLX_DECLARE_SWAP_VARIABLES
;
519 __GLX_DECLARE_SWAP_ARRAY_VARIABLES
;
521 __GLX_SWAP_SHORT(&req
->length
);
522 __GLX_SWAP_INT(&req
->contextTag
);
524 swap_vec_element_size
= 8;
527 * swap extra data in request - assuming all data
528 * (if available) are arrays of 4 bytes components !
530 if (req
->length
> sz_xGLXSingleReq
/ 4) {
531 int *data
= (int *) (req
+ 1);
532 int count
= req
->length
- sz_xGLXSingleReq
/ 4;
534 __GLX_SWAP_INT_ARRAY(data
, count
);
537 return (__glXForwardPipe0WithReply(cl
, pc
));
541 __glXForwardAllWithReplySwap(__GLXclientState
* cl
, GLbyte
* pc
)
543 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
545 __GLX_DECLARE_SWAP_VARIABLES
;
546 __GLX_DECLARE_SWAP_ARRAY_VARIABLES
;
548 __GLX_SWAP_SHORT(&req
->length
);
549 __GLX_SWAP_INT(&req
->contextTag
);
551 swap_vec_element_size
= 0;
554 * swap extra data in request - assuming all data
555 * (if available) are arrays of 4 bytes components !
557 if (req
->length
> sz_xGLXSingleReq
/ 4) {
558 int *data
= (int *) (req
+ 1);
559 int count
= req
->length
- sz_xGLXSingleReq
/ 4;
561 __GLX_SWAP_INT_ARRAY(data
, count
);
564 return (__glXForwardAllWithReply(cl
, pc
));
568 __glXForwardAllWithReplySwapsv(__GLXclientState
* cl
, GLbyte
* pc
)
570 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
572 __GLX_DECLARE_SWAP_VARIABLES
;
573 __GLX_DECLARE_SWAP_ARRAY_VARIABLES
;
575 __GLX_SWAP_SHORT(&req
->length
);
576 __GLX_SWAP_INT(&req
->contextTag
);
578 swap_vec_element_size
= 2;
581 * swap extra data in request - assuming all data
582 * (if available) are arrays of 4 bytes components !
584 if (req
->length
> sz_xGLXSingleReq
/ 4) {
585 int *data
= (int *) (req
+ 1);
586 int count
= req
->length
- sz_xGLXSingleReq
/ 4;
588 __GLX_SWAP_INT_ARRAY(data
, count
);
591 return (__glXForwardAllWithReply(cl
, pc
));
595 __glXForwardAllWithReplySwapiv(__GLXclientState
* cl
, GLbyte
* pc
)
597 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
599 __GLX_DECLARE_SWAP_VARIABLES
;
600 __GLX_DECLARE_SWAP_ARRAY_VARIABLES
;
602 __GLX_SWAP_SHORT(&req
->length
);
603 __GLX_SWAP_INT(&req
->contextTag
);
605 swap_vec_element_size
= 4;
608 * swap extra data in request - assuming all data
609 * (if available) are arrays of 4 bytes components !
611 if (req
->length
> sz_xGLXSingleReq
/ 4) {
612 int *data
= (int *) (req
+ 1);
613 int count
= req
->length
- sz_xGLXSingleReq
/ 4;
615 __GLX_SWAP_INT_ARRAY(data
, count
);
618 return (__glXForwardAllWithReply(cl
, pc
));
622 __glXForwardAllWithReplySwapdv(__GLXclientState
* cl
, GLbyte
* pc
)
624 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
626 __GLX_DECLARE_SWAP_VARIABLES
;
627 __GLX_DECLARE_SWAP_ARRAY_VARIABLES
;
629 __GLX_SWAP_SHORT(&req
->length
);
630 __GLX_SWAP_INT(&req
->contextTag
);
632 swap_vec_element_size
= 8;
635 * swap extra data in request - assuming all data
636 * (if available) are arrays of 4 bytes components !
638 if (req
->length
> sz_xGLXSingleReq
/ 4) {
639 int *data
= (int *) (req
+ 1);
640 int count
= req
->length
- sz_xGLXSingleReq
/ 4;
642 __GLX_SWAP_INT_ARRAY(data
, count
);
645 return (__glXForwardAllWithReply(cl
, pc
));
649 __glReadPixels_size(GLenum format
, GLenum type
, GLint w
, GLint h
,
650 int *elementbits_return
, int *rowbytes_return
)
652 GLint elements
, esize
;
653 GLint rowsize
, padding
;
655 if (w
< 0 || h
< 0) {
660 case GL_STENCIL_INDEX
:
661 case GL_DEPTH_COMPONENT
:
671 case GL_LUMINANCE_ALPHA
:
687 ** According to the GLX protocol, each row must be padded to a multiple of
688 ** 4 bytes. 4 bytes also happens to be the default alignment in the pixel
689 ** store modes of the GL.
693 if (format
== GL_COLOR_INDEX
|| format
== GL_STENCIL_INDEX
) {
694 rowsize
= ((w
* elements
) + 7) / 8;
695 padding
= rowsize
% 4;
697 rowsize
+= 4 - padding
;
699 if (elementbits_return
)
700 *elementbits_return
= elements
;
702 *rowbytes_return
= rowsize
;
709 case GL_UNSIGNED_BYTE
:
712 case GL_UNSIGNED_BYTE_3_3_2
:
713 case GL_UNSIGNED_BYTE_2_3_3_REV
:
718 case GL_UNSIGNED_SHORT
:
721 case GL_UNSIGNED_SHORT_5_6_5
:
722 case GL_UNSIGNED_SHORT_5_6_5_REV
:
723 case GL_UNSIGNED_SHORT_4_4_4_4
:
724 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
725 case GL_UNSIGNED_SHORT_5_5_5_1
:
726 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
731 case GL_UNSIGNED_INT
:
735 case GL_UNSIGNED_INT_8_8_8_8
:
736 case GL_UNSIGNED_INT_8_8_8_8_REV
:
737 case GL_UNSIGNED_INT_10_10_10_2
:
738 case GL_UNSIGNED_INT_2_10_10_10_REV
:
745 rowsize
= w
* elements
* esize
;
746 padding
= rowsize
% 4;
748 rowsize
+= 4 - padding
;
751 if (elementbits_return
)
752 *elementbits_return
= esize
* elements
* 8;
754 *rowbytes_return
= rowsize
;
760 intersectRect(int x1
, int x2
, int y1
, int y2
,
761 int X1
, int X2
, int Y1
, int Y2
,
762 int *ix1
, int *ix2
, int *iy1
, int *iy2
)
764 int right
= (x2
< X2
? x2
: X2
);
765 int bottom
= (y2
< Y2
? y2
: Y2
);
766 int left
= (x1
> X1
? x1
: X1
);
767 int top
= (y1
> Y1
? y1
: Y1
);
768 int width
= right
- left
+ 1;
769 int height
= bottom
- top
+ 1;
771 if ((width
<= 0) || (height
<= 0)) {
772 *ix1
= *ix2
= *iy1
= *iy2
= 0;
780 return width
* height
;
786 __glXDisp_ReadPixels(__GLXclientState
* cl
, GLbyte
* pc
)
788 xGLXSingleReq
*req
= (xGLXSingleReq
*) pc
;
789 xGLXSingleReq
*be_req
;
790 xGLXReadPixelsReply reply
;
791 xGLXReadPixelsReply be_reply
;
794 GLsizei width
, height
;
796 GLboolean swapBytes
, lsbFirst
;
797 ClientPtr client
= cl
->client
;
809 __GLX_DECLARE_SWAP_VARIABLES
;
811 if (client
->swapped
) {
812 __GLX_SWAP_INT(&req
->contextTag
);
815 glxc
= __glXLookupContextByTag(cl
, req
->contextTag
);
819 from_screen
= to_screen
= glxc
->pScreen
->myNum
;
822 if (!noPanoramiXExtension
) {
824 to_screen
= screenInfo
.numScreens
- 1;
828 pc
+= sz_xGLXSingleReq
;
829 x
= *(GLint
*) (pc
+ 0);
830 y
= *(GLint
*) (pc
+ 4);
831 width
= *(GLsizei
*) (pc
+ 8);
832 height
= *(GLsizei
*) (pc
+ 12);
833 format
= *(GLenum
*) (pc
+ 16);
834 type
= *(GLenum
*) (pc
+ 20);
835 swapBytes
= *(GLboolean
*) (pc
+ 24);
836 lsbFirst
= *(GLboolean
*) (pc
+ 25);
838 if (client
->swapped
) {
841 __GLX_SWAP_INT(&width
);
842 __GLX_SWAP_INT(&height
);
843 __GLX_SWAP_INT(&format
);
844 __GLX_SWAP_INT(&type
);
845 swapBytes
= !swapBytes
;
849 __glReadPixels_size(format
, type
, width
, height
, &ebits
, &rowsize
);
851 buf
= (char *) malloc(buf_size
);
863 * Get the current drawable this context is bound to
865 pDraw
= __glXLookupDrawableByTag(cl
, req
->contextTag
);
866 win_x1
= pDraw
->x
+ x
;
867 win_x2
= win_x1
+ width
- 1;
868 win_y1
= (dmxGlobalHeight
- pDraw
->y
- pDraw
->height
) + y
;
869 win_y2
= win_y1
+ height
- 1;
870 if (pDraw
->type
!= DRAWABLE_WINDOW
) {
871 from_screen
= to_screen
= 0;
874 for (s
= from_screen
; s
<= to_screen
; s
++) {
875 DMXScreenInfo
*dmxScreen
= &dmxScreens
[s
];
876 Display
*dpy
= GetBackEndDisplay(cl
, s
);
877 int scr_x1
= dmxScreen
->rootXOrigin
;
878 int scr_x2
= dmxScreen
->rootXOrigin
+ dmxScreen
->scrnWidth
- 1;
879 int scr_y1
= dmxScreen
->rootYOrigin
;
880 int scr_y2
= dmxScreen
->rootYOrigin
+ dmxScreen
->scrnHeight
- 1;
881 int wx1
, wx2
, wy1
, wy2
;
886 * find the window portion that is on the current screen
888 if (pDraw
->type
== DRAWABLE_WINDOW
) {
889 npixels
= intersectRect(scr_x1
, scr_x2
, scr_y1
, scr_y2
,
890 win_x1
, win_x2
, win_y1
, win_y2
,
891 &wx1
, &wx2
, &wy1
, &wy2
);
898 npixels
= (wx2
- wx1
+ 1) * (wy2
- wy1
+ 1);
903 /* send the request to the back-end server */
905 GetReqExtra(GLXSingle
, __GLX_PAD(26), be_req
);
906 be_req
->reqType
= dmxScreen
->glxMajorOpcode
;
907 be_req
->glxCode
= X_GLsop_ReadPixels
;
909 GetCurrentBackEndTag(cl
, req
->contextTag
, s
);
910 be_pc
= ((GLbyte
*) (be_req
) + sz_xGLXSingleReq
);
913 sy
= wy1
- (dmxGlobalHeight
- pDraw
->y
- pDraw
->height
);
914 sw
= (wx2
- wx1
+ 1);
915 sh
= (wy2
- wy1
+ 1);
917 *(GLint
*) (be_pc
+ 0) = sx
; /* x */
918 *(GLint
*) (be_pc
+ 4) = sy
; /* y */
919 *(GLsizei
*) (be_pc
+ 8) = sw
; /* width */
920 *(GLsizei
*) (be_pc
+ 12) = sh
; /* height */
921 *(GLenum
*) (be_pc
+ 16) = format
;
922 *(GLenum
*) (be_pc
+ 20) = type
;
923 *(GLboolean
*) (be_pc
+ 24) = swapBytes
;
924 *(GLboolean
*) (be_pc
+ 25) = lsbFirst
;
926 _XReply(dpy
, (xReply
*) &be_reply
, 0, False
);
928 if (be_reply
.length
> 0) {
930 int be_buf_size
= be_reply
.length
<< 2;
932 be_buf
= (char *) malloc(be_buf_size
);
934 _XRead(dpy
, be_buf
, be_buf_size
);
936 /* copy pixels data to the right location of the */
938 if (type
!= GL_BITMAP
) {
939 int pbytes
= ebits
/ 8;
941 buf
+ (sy
- y
) * rowsize
+ (sx
- x
) * pbytes
;
943 int pad
= (pbytes
* sw
) % 4;
946 for (r
= 0; r
< sh
; r
++) {
947 memcpy(dst
, src
, pbytes
* sw
);
949 src
+= (pbytes
* sw
+ (pad
? 4 - pad
: 0));
953 /* this is a GL_BITMAP pixel type, should copy bits */
955 int src_rowsize
= bits_to_bytes(sw
* ebits
);
956 int src_pad
= src_rowsize
% 4;
959 src_rowsize
+= (4 - src_pad
);
962 for (r
= 0; r
< sh
; r
++) {
963 unsigned char dst_mask
= 0x80 >> (sx
% 8);
964 unsigned char src_mask
= 0x80;
966 buf
+ (sy
- y
+ r
) * rowsize
+ (sx
- x
) / 8;
967 char *src
= be_buf
+ r
* src_rowsize
;
970 for (b
= 0; b
< sw
* ebits
; b
++) {
971 if (*src
& src_mask
) {
999 /* Throw data on the floor */
1000 _XEatDataWords(dpy
, be_reply
.length
);
1009 } /* of npixels > 0 */
1013 } /* of if buf_size > 0 */
1015 reply
= (xGLXReadPixelsReply
) {
1017 .sequenceNumber
= client
->sequence
,
1018 .length
= buf_size
>> 2
1021 if (client
->swapped
) {
1022 __GLX_SWAP_SHORT(&reply
.sequenceNumber
);
1023 __GLX_SWAP_INT(&reply
.length
);
1026 WriteToClient(client
, sizeof(xGLXReadPixelsReply
), &reply
);
1028 WriteToClient(client
, buf_size
, buf
);
1036 __glXDispSwap_GetTexImage(__GLXclientState
* cl
, GLbyte
* pc
)
1038 __GLX_DECLARE_SWAP_VARIABLES
;
1041 lpc
+= sz_xGLXSingleReq
;
1042 __GLX_SWAP_INT(lpc
+ 0);
1043 __GLX_SWAP_INT(lpc
+ 4);
1044 __GLX_SWAP_INT(lpc
+ 8);
1045 __GLX_SWAP_INT(lpc
+ 12);
1047 /* reverse swapBytes */
1048 *(GLboolean
*) (lpc
+ 16) = !*(GLboolean
*) (lpc
+ 16);
1050 return (__glXForwardPipe0WithReplySwap(cl
, pc
));
1054 __glXDispSwap_GetColorTable(__GLXclientState
* cl
, GLbyte
* pc
)
1056 __GLX_DECLARE_SWAP_VARIABLES
;
1059 lpc
+= sz_xGLXSingleReq
;
1060 __GLX_SWAP_INT(lpc
+ 0);
1061 __GLX_SWAP_INT(lpc
+ 4);
1062 __GLX_SWAP_INT(lpc
+ 8);
1064 /* reverse swapBytes */
1065 *(GLboolean
*) (lpc
+ 12) = !*(GLboolean
*) (lpc
+ 12);
1067 return (__glXForwardPipe0WithReplySwap(cl
, pc
));