1 /* DO NOT EDIT - THIS FILE IS AUTOMATICALLY GENERATED */
2 /*
3  * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
4  * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5  *
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:
12  *
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.
17  *
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
24  * SOFTWARE.
25  *
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.
30  */
31 
32 #ifdef HAVE_DMX_CONFIG_H
33 #include <dmx-config.h>
34 #endif
35 
36 #include "dmx.h"
37 #include "dmxwindow.h"
38 #include "dmxpixmap.h"
39 #include "dmxfont.h"
40 
41 #include "glxserver.h"
42 #include "glxext.h"
43 #include "g_disptab.h"
44 /* #include "g_disptab_EXT.h" */
45 #include "unpack.h"
46 #include "glxutil.h"
47 #include "glxcmds.h"
48 #include "glxvendor.h"
49 
50 #include "GL/glxproto.h"
51 
52 #ifdef PANORAMIX
53 #include "panoramiXsrv.h"
54 #endif
55 
56 /*
57  * GetReqVendorPrivate - this is the equivalent of GetReq macro
58  *    from Xlibint.h but it does not set the reqType field (the opcode).
59  *    this is because the GL single opcodes has different naming convension
60  *    the other X opcodes (ie. X_GLsop_GetFloatv).
61  */
62 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
63 #define GetReqVendorPrivate(name, req) \
64         WORD64ALIGN\
65 	if ((dpy->bufptr + SIZEOF(x##name##Req)) > dpy->bufmax)\
66 		_XFlush(dpy);\
67 	req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
68 	req->length = (SIZEOF(x##name##Req))>>2;\
69 	dpy->bufptr += SIZEOF(x##name##Req);\
70 	dpy->request++
71 
72 #else                           /* non-ANSI C uses empty comment instead of "##" for token concatenation */
73 #define GetReqVendorPrivate(name, req) \
74         WORD64ALIGN\
75 	if ((dpy->bufptr + SIZEOF(x/**/name/**/Req)) > dpy->bufmax)\
76 		_XFlush(dpy);\
77 	req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
78 	req->length = (SIZEOF(x/**/name/**/Req))>>2;\
79 	dpy->bufptr += SIZEOF(x/**/name/**/Req);\
80 	dpy->request++
81 #endif
82 
83 static int swap_vec_element_size = 0;
84 
85 static void
SendSwappedReply(ClientPtr client,xGLXVendorPrivReply * reply,char * buf,int buf_size)86 SendSwappedReply(ClientPtr client,
87                  xGLXVendorPrivReply * reply, char *buf, int buf_size)
88 {
89     __GLX_DECLARE_SWAP_VARIABLES;
90     __GLX_SWAP_SHORT(&reply->sequenceNumber);
91     __GLX_SWAP_INT(&reply->length);
92     __GLX_SWAP_INT(&reply->retval);
93     __GLX_SWAP_INT(&reply->size);
94 
95     if ((buf_size == 0) && (swap_vec_element_size > 0)) {
96         /*
97          * the reply has single component - need to swap pad3
98          */
99         if (swap_vec_element_size == 2) {
100             __GLX_SWAP_SHORT(&reply->pad3);
101         }
102         else if (swap_vec_element_size == 4) {
103             __GLX_SWAP_INT(&reply->pad3);
104             __GLX_SWAP_INT(&reply->pad4);
105         }
106         else if (swap_vec_element_size == 8) {
107             __GLX_SWAP_DOUBLE(&reply->pad3);
108         }
109     }
110     else if ((buf_size > 0) && (swap_vec_element_size > 0)) {
111         /*
112          * the reply has vector of elements which needs to be swapped
113          */
114         int vsize = buf_size / swap_vec_element_size;
115         char *p = buf;
116         int i;
117 
118         for (i = 0; i < vsize; i++) {
119             if (swap_vec_element_size == 2) {
120                 __GLX_SWAP_SHORT(p);
121             }
122             else if (swap_vec_element_size == 4) {
123                 __GLX_SWAP_INT(p);
124             }
125             else if (swap_vec_element_size == 8) {
126                 __GLX_SWAP_DOUBLE(p);
127             }
128 
129             p += swap_vec_element_size;
130         }
131 
132         __GLX_SWAP_INT(&reply->pad3);
133         __GLX_SWAP_INT(&reply->pad4);
134         __GLX_SWAP_INT(&reply->pad5);
135         __GLX_SWAP_INT(&reply->pad6);
136 
137     }
138 
139     WriteToClient(client, sizeof(xGLXVendorPrivReply), reply);
140     if (buf_size > 0)
141         WriteToClient(client, buf_size, buf);
142 
143 }
144 
145 int
__glXVForwardSingleReq(__GLXclientState * cl,GLbyte * pc)146 __glXVForwardSingleReq(__GLXclientState * cl, GLbyte * pc)
147 {
148     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
149     xGLXVendorPrivateReq *be_req;
150     __GLXcontext *glxc;
151     int from_screen = 0;
152     int to_screen = 0;
153     int buf_size;
154     int s;
155 
156     glxc = __glXLookupContextByTag(cl, req->contextTag);
157     if (!glxc) {
158         return 0;
159     }
160     from_screen = to_screen = glxc->pScreen->myNum;
161 
162 #ifdef PANORAMIX
163     if (!noPanoramiXExtension) {
164         from_screen = 0;
165         to_screen = screenInfo.numScreens - 1;
166     }
167 #endif
168 
169     pc += sz_xGLXVendorPrivateReq;
170     buf_size = (req->length << 2) - sz_xGLXVendorPrivateReq;
171 
172     /*
173      * just forward the request to back-end server(s)
174      */
175     for (s = from_screen; s <= to_screen; s++) {
176         DMXScreenInfo *dmxScreen = &dmxScreens[s];
177         Display *dpy = GetBackEndDisplay(cl, s);
178 
179         LockDisplay(dpy);
180         GetReqVendorPrivate(GLXVendorPrivate, be_req);
181         be_req->reqType = dmxScreen->glxMajorOpcode;
182         be_req->glxCode = req->glxCode;
183         be_req->length = req->length;
184         be_req->vendorCode = req->vendorCode;
185         be_req->contextTag = GetCurrentBackEndTag(cl, req->contextTag, s);
186         if (buf_size > 0)
187             _XSend(dpy, (const char *) pc, buf_size);
188         UnlockDisplay(dpy);
189         SyncHandle();
190     }
191 
192     return Success;
193 }
194 
195 int
__glXVForwardPipe0WithReply(__GLXclientState * cl,GLbyte * pc)196 __glXVForwardPipe0WithReply(__GLXclientState * cl, GLbyte * pc)
197 {
198     ClientPtr client = cl->client;
199     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
200     xGLXVendorPrivateReq *be_req;
201     xGLXVendorPrivReply reply;
202     xGLXVendorPrivReply be_reply;
203     __GLXcontext *glxc;
204     int buf_size;
205     char *be_buf = NULL;
206     int be_buf_size;
207     DMXScreenInfo *dmxScreen;
208     Display *dpy;
209 
210     glxc = __glXLookupContextByTag(cl, req->contextTag);
211     if (!glxc) {
212         return __glXBadContext;
213     }
214 
215     pc += sz_xGLXVendorPrivateReq;
216     buf_size = (req->length << 2) - sz_xGLXVendorPrivateReq;
217 
218     dmxScreen = &dmxScreens[glxc->pScreen->myNum];
219     dpy = GetBackEndDisplay(cl, glxc->pScreen->myNum);
220 
221     /*
222      * send the request to the first back-end server
223      */
224     LockDisplay(dpy);
225     GetReqVendorPrivate(GLXVendorPrivate, be_req);
226     be_req->reqType = dmxScreen->glxMajorOpcode;
227     be_req->glxCode = req->glxCode;
228     be_req->length = req->length;
229     be_req->vendorCode = req->vendorCode;
230     be_req->contextTag =
231         GetCurrentBackEndTag(cl, req->contextTag, glxc->pScreen->myNum);
232     if (buf_size > 0)
233         _XSend(dpy, (const char *) pc, buf_size);
234 
235     /*
236      * get the reply from the back-end server
237      */
238     _XReply(dpy, (xReply *) &be_reply, 0, False);
239     be_buf_size = be_reply.length << 2;
240     if (be_buf_size > 0) {
241         be_buf = (char *) malloc(be_buf_size);
242         if (be_buf) {
243             _XRead(dpy, be_buf, be_buf_size);
244         }
245         else {
246             /* Throw data on the floor */
247             _XEatDataWords(dpy, be_reply.length);
248             return BadAlloc;
249         }
250     }
251 
252     UnlockDisplay(dpy);
253     SyncHandle();
254 
255     /*
256      * send the reply to the client
257      */
258     memcpy(&reply, &be_reply, sz_xGLXVendorPrivReply);
259     reply.type = X_Reply;
260     reply.sequenceNumber = client->sequence;
261 
262     if (client->swapped) {
263         SendSwappedReply(client, &reply, be_buf, be_buf_size);
264     }
265     else {
266         WriteToClient(client, sizeof(xGLXVendorPrivReply), &reply);
267         if (be_buf_size > 0)
268             WriteToClient(client, be_buf_size, be_buf);
269     }
270 
271     if (be_buf_size > 0)
272         free(be_buf);
273 
274     return Success;
275 }
276 
277 int
__glXVForwardAllWithReply(__GLXclientState * cl,GLbyte * pc)278 __glXVForwardAllWithReply(__GLXclientState * cl, GLbyte * pc)
279 {
280     ClientPtr client = cl->client;
281     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
282     xGLXVendorPrivateReq *be_req;
283     xGLXVendorPrivReply reply;
284     xGLXVendorPrivReply be_reply;
285     __GLXcontext *glxc;
286     int buf_size;
287     char *be_buf = NULL;
288     int be_buf_size = 0;
289     int from_screen = 0;
290     int to_screen = 0;
291     int s;
292 
293     DMXScreenInfo *dmxScreen;
294     Display *dpy;
295 
296     glxc = __glXLookupContextByTag(cl, req->contextTag);
297     if (!glxc) {
298         return 0;
299     }
300     from_screen = to_screen = glxc->pScreen->myNum;
301 
302 #ifdef PANORAMIX
303     if (!noPanoramiXExtension) {
304         from_screen = 0;
305         to_screen = screenInfo.numScreens - 1;
306     }
307 #endif
308 
309     pc += sz_xGLXVendorPrivateReq;
310     buf_size = (req->length << 2) - sz_xGLXVendorPrivateReq;
311 
312     /*
313      * send the request to the first back-end server(s)
314      */
315     for (s = to_screen; s >= from_screen; s--) {
316         dmxScreen = &dmxScreens[s];
317         dpy = GetBackEndDisplay(cl, s);
318 
319         LockDisplay(dpy);
320         GetReqVendorPrivate(GLXVendorPrivate, be_req);
321         be_req->reqType = dmxScreen->glxMajorOpcode;
322         be_req->glxCode = req->glxCode;
323         be_req->length = req->length;
324         be_req->vendorCode = req->vendorCode;
325         be_req->contextTag = GetCurrentBackEndTag(cl, req->contextTag, s);
326         if (buf_size > 0)
327             _XSend(dpy, (const char *) pc, buf_size);
328 
329         /*
330          * get the reply from the back-end server
331          */
332         _XReply(dpy, (xReply *) &be_reply, 0, False);
333         if (s == from_screen) {
334             /* Save data from last reply to send on to client */
335             be_buf_size = be_reply.length << 2;
336             if (be_buf_size > 0) {
337                 be_buf = malloc(be_buf_size);
338                 if (be_buf) {
339                     _XRead(dpy, be_buf, be_buf_size);
340                 }
341                 else {
342                     /* Throw data on the floor */
343                     _XEatDataWords(dpy, be_reply.length);
344                     return BadAlloc;
345                 }
346             }
347         }
348         else {
349             /* Just discard data from all replies before the last one */
350             if (be_reply.length > 0)
351                 _XEatDataWords(dpy, be_reply.length);
352         }
353 
354         UnlockDisplay(dpy);
355         SyncHandle();
356     }
357 
358     /*
359      * send the reply to the client
360      */
361     memcpy(&reply, &be_reply, sz_xGLXVendorPrivReply);
362     reply.type = X_Reply;
363     reply.sequenceNumber = client->sequence;
364 
365     if (client->swapped) {
366         SendSwappedReply(client, &reply, be_buf, be_buf_size);
367     }
368     else {
369         WriteToClient(client, sizeof(xGLXVendorPrivReply), &reply);
370         if (be_buf_size > 0)
371             WriteToClient(client, be_buf_size, be_buf);
372     }
373 
374     if (be_buf_size > 0)
375         free(be_buf);
376 
377     return Success;
378 }
379 
380 int
__glXVForwardSingleReqSwap(__GLXclientState * cl,GLbyte * pc)381 __glXVForwardSingleReqSwap(__GLXclientState * cl, GLbyte * pc)
382 {
383     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
384 
385     __GLX_DECLARE_SWAP_VARIABLES;
386 
387     __GLX_SWAP_SHORT(&req->length);
388     __GLX_SWAP_INT(&req->vendorCode);
389     __GLX_SWAP_INT(&req->contextTag);
390 
391     swap_vec_element_size = 0;
392 
393     return (__glXVForwardSingleReq(cl, pc));
394 }
395 
396 int
__glXVForwardPipe0WithReplySwap(__GLXclientState * cl,GLbyte * pc)397 __glXVForwardPipe0WithReplySwap(__GLXclientState * cl, GLbyte * pc)
398 {
399     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
400 
401     __GLX_DECLARE_SWAP_VARIABLES;
402     __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
403 
404     __GLX_SWAP_SHORT(&req->length);
405     __GLX_SWAP_INT(&req->vendorCode);
406     __GLX_SWAP_INT(&req->contextTag);
407 
408     swap_vec_element_size = 0;
409 
410     /*
411      * swap extra data in request - assuming all data
412      * (if available) are arrays of 4 bytes components !
413      */
414     if (req->length > sz_xGLXVendorPrivateReq / 4) {
415         int *data = (int *) (req + 1);
416         int count = req->length - sz_xGLXVendorPrivateReq / 4;
417 
418         __GLX_SWAP_INT_ARRAY(data, count);
419     }
420 
421     return (__glXVForwardPipe0WithReply(cl, pc));
422 }
423 
424 int
__glXVForwardPipe0WithReplySwapsv(__GLXclientState * cl,GLbyte * pc)425 __glXVForwardPipe0WithReplySwapsv(__GLXclientState * cl, GLbyte * pc)
426 {
427     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
428 
429     __GLX_DECLARE_SWAP_VARIABLES;
430     __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
431 
432     __GLX_SWAP_SHORT(&req->length);
433     __GLX_SWAP_INT(&req->vendorCode);
434     __GLX_SWAP_INT(&req->contextTag);
435 
436     swap_vec_element_size = 2;
437 
438     /*
439      * swap extra data in request - assuming all data
440      * (if available) are arrays of 4 bytes components !
441      */
442     if (req->length > sz_xGLXVendorPrivateReq / 4) {
443         int *data = (int *) (req + 1);
444         int count = req->length - sz_xGLXVendorPrivateReq / 4;
445 
446         __GLX_SWAP_INT_ARRAY(data, count);
447     }
448 
449     return (__glXVForwardPipe0WithReply(cl, pc));
450 }
451 
452 int
__glXVForwardPipe0WithReplySwapiv(__GLXclientState * cl,GLbyte * pc)453 __glXVForwardPipe0WithReplySwapiv(__GLXclientState * cl, GLbyte * pc)
454 {
455     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
456 
457     __GLX_DECLARE_SWAP_VARIABLES;
458     __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
459 
460     __GLX_SWAP_SHORT(&req->length);
461     __GLX_SWAP_INT(&req->vendorCode);
462     __GLX_SWAP_INT(&req->contextTag);
463 
464     swap_vec_element_size = 4;
465 
466     /*
467      * swap extra data in request - assuming all data
468      * (if available) are arrays of 4 bytes components !
469      */
470     if (req->length > sz_xGLXVendorPrivateReq / 4) {
471         int *data = (int *) (req + 1);
472         int count = req->length - sz_xGLXVendorPrivateReq / 4;
473 
474         __GLX_SWAP_INT_ARRAY(data, count);
475     }
476 
477     return (__glXVForwardPipe0WithReply(cl, pc));
478 }
479 
480 int
__glXVForwardPipe0WithReplySwapdv(__GLXclientState * cl,GLbyte * pc)481 __glXVForwardPipe0WithReplySwapdv(__GLXclientState * cl, GLbyte * pc)
482 {
483     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
484 
485     __GLX_DECLARE_SWAP_VARIABLES;
486     __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
487 
488     __GLX_SWAP_SHORT(&req->length);
489     __GLX_SWAP_INT(&req->vendorCode);
490     __GLX_SWAP_INT(&req->contextTag);
491 
492     swap_vec_element_size = 8;
493 
494     /*
495      * swap extra data in request - assuming all data
496      * (if available) are arrays of 4 bytes components !
497      */
498     if (req->length > sz_xGLXVendorPrivateReq / 4) {
499         int *data = (int *) (req + 1);
500         int count = req->length - sz_xGLXVendorPrivateReq / 4;
501 
502         __GLX_SWAP_INT_ARRAY(data, count);
503     }
504 
505     return (__glXVForwardPipe0WithReply(cl, pc));
506 }
507 
508 int
__glXVForwardAllWithReplySwap(__GLXclientState * cl,GLbyte * pc)509 __glXVForwardAllWithReplySwap(__GLXclientState * cl, GLbyte * pc)
510 {
511     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
512 
513     __GLX_DECLARE_SWAP_VARIABLES;
514     __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
515 
516     __GLX_SWAP_SHORT(&req->length);
517     __GLX_SWAP_INT(&req->vendorCode);
518     __GLX_SWAP_INT(&req->contextTag);
519 
520     swap_vec_element_size = 0;
521 
522     /*
523      * swap extra data in request - assuming all data
524      * (if available) are arrays of 4 bytes components !
525      */
526     if (req->length > sz_xGLXVendorPrivateReq / 4) {
527         int *data = (int *) (req + 1);
528         int count = req->length - sz_xGLXVendorPrivateReq / 4;
529 
530         __GLX_SWAP_INT_ARRAY(data, count);
531     }
532 
533     return (__glXVForwardAllWithReply(cl, pc));
534 }
535 
536 int
__glXVForwardAllWithReplySwapsv(__GLXclientState * cl,GLbyte * pc)537 __glXVForwardAllWithReplySwapsv(__GLXclientState * cl, GLbyte * pc)
538 {
539     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
540 
541     __GLX_DECLARE_SWAP_VARIABLES;
542     __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
543 
544     __GLX_SWAP_SHORT(&req->length);
545     __GLX_SWAP_INT(&req->vendorCode);
546     __GLX_SWAP_INT(&req->contextTag);
547 
548     swap_vec_element_size = 2;
549 
550     /*
551      * swap extra data in request - assuming all data
552      * (if available) are arrays of 4 bytes components !
553      */
554     if (req->length > sz_xGLXVendorPrivateReq / 4) {
555         int *data = (int *) (req + 1);
556         int count = req->length - sz_xGLXVendorPrivateReq / 4;
557 
558         __GLX_SWAP_INT_ARRAY(data, count);
559     }
560 
561     return (__glXVForwardAllWithReply(cl, pc));
562 }
563 
564 int
__glXVForwardAllWithReplySwapiv(__GLXclientState * cl,GLbyte * pc)565 __glXVForwardAllWithReplySwapiv(__GLXclientState * cl, GLbyte * pc)
566 {
567     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
568 
569     __GLX_DECLARE_SWAP_VARIABLES;
570     __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
571 
572     __GLX_SWAP_SHORT(&req->length);
573     __GLX_SWAP_INT(&req->vendorCode);
574     __GLX_SWAP_INT(&req->contextTag);
575 
576     swap_vec_element_size = 4;
577 
578     /*
579      * swap extra data in request - assuming all data
580      * (if available) are arrays of 4 bytes components !
581      */
582     if (req->length > sz_xGLXVendorPrivateReq / 4) {
583         int *data = (int *) (req + 1);
584         int count = req->length - sz_xGLXVendorPrivateReq / 4;
585 
586         __GLX_SWAP_INT_ARRAY(data, count);
587     }
588 
589     return (__glXVForwardAllWithReply(cl, pc));
590 }
591 
592 int
__glXVForwardAllWithReplySwapdv(__GLXclientState * cl,GLbyte * pc)593 __glXVForwardAllWithReplySwapdv(__GLXclientState * cl, GLbyte * pc)
594 {
595     xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
596 
597     __GLX_DECLARE_SWAP_VARIABLES;
598     __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
599 
600     __GLX_SWAP_SHORT(&req->length);
601     __GLX_SWAP_INT(&req->vendorCode);
602     __GLX_SWAP_INT(&req->contextTag);
603 
604     swap_vec_element_size = 8;
605 
606     /*
607      * swap extra data in request - assuming all data
608      * (if available) are arrays of 4 bytes components !
609      */
610     if (req->length > sz_xGLXVendorPrivateReq / 4) {
611         int *data = (int *) (req + 1);
612         int count = req->length - sz_xGLXVendorPrivateReq / 4;
613 
614         __GLX_SWAP_INT_ARRAY(data, count);
615     }
616 
617     return (__glXVForwardAllWithReply(cl, pc));
618 }
619