xref: /OK3568_Linux_fs/external/xserver/hw/dmx/glxProxy/glxcmds.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3*4882a593Smuzhiyun  * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
6*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
7*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
8*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
10*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * The above copyright notice including the dates of first publication and
13*4882a593Smuzhiyun  * either this permission notice or a reference to
14*4882a593Smuzhiyun  * http://oss.sgi.com/projects/FreeB/
15*4882a593Smuzhiyun  * shall be included in all copies or substantial portions of the Software.
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18*4882a593Smuzhiyun  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20*4882a593Smuzhiyun  * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21*4882a593Smuzhiyun  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22*4882a593Smuzhiyun  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23*4882a593Smuzhiyun  * SOFTWARE.
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * Except as contained in this notice, the name of Silicon Graphics, Inc.
26*4882a593Smuzhiyun  * shall not be used in advertising or otherwise to promote the sale, use or
27*4882a593Smuzhiyun  * other dealings in this Software without prior written authorization from
28*4882a593Smuzhiyun  * Silicon Graphics, Inc.
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #ifdef HAVE_DMX_CONFIG_H
32*4882a593Smuzhiyun #include <dmx-config.h>
33*4882a593Smuzhiyun #endif
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #include "dmx.h"
36*4882a593Smuzhiyun #include "dmxwindow.h"
37*4882a593Smuzhiyun #include "dmxpixmap.h"
38*4882a593Smuzhiyun #include "dmxfont.h"
39*4882a593Smuzhiyun #include "dmxsync.h"
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #include "glxserver.h"
42*4882a593Smuzhiyun #include "g_disptab.h"
43*4882a593Smuzhiyun #include <pixmapstr.h>
44*4882a593Smuzhiyun #include <windowstr.h>
45*4882a593Smuzhiyun #include "glxutil.h"
46*4882a593Smuzhiyun #include "glxext.h"
47*4882a593Smuzhiyun #include "unpack.h"
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun #include "GL/glxproto.h"
50*4882a593Smuzhiyun #include "glxvendor.h"
51*4882a593Smuzhiyun #include "glxvisuals.h"
52*4882a593Smuzhiyun #include "glxswap.h"
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #include "glxcmds.h"
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #ifdef PANORAMIX
57*4882a593Smuzhiyun #include "panoramiXsrv.h"
58*4882a593Smuzhiyun #endif
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun extern __GLXFBConfig **__glXFBConfigs;
61*4882a593Smuzhiyun extern int __glXNumFBConfigs;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun extern int __glXGetFBConfigsSGIX(__GLXclientState * cl, GLbyte * pc);
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun #define BE_TO_CLIENT_ERROR(x) \
66*4882a593Smuzhiyun            ( (x) >= __glXerrorBase ? \
67*4882a593Smuzhiyun              (x) - dmxScreen->glxErrorBase + __glXerrorBase \
68*4882a593Smuzhiyun 	     : (x) )
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun static __GLXFBConfig *
glxLookupFBConfig(GLXFBConfigID id)71*4882a593Smuzhiyun glxLookupFBConfig(GLXFBConfigID id)
72*4882a593Smuzhiyun {
73*4882a593Smuzhiyun     int i, j;
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun     for (i = 0, j = 0; i < __glXNumFBConfigs;
76*4882a593Smuzhiyun          i++, j += (__glXNumActiveScreens + 1)) {
77*4882a593Smuzhiyun         if (__glXFBConfigs[j]->id == id)
78*4882a593Smuzhiyun             return __glXFBConfigs[j];
79*4882a593Smuzhiyun     }
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun     return NULL;
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun static __GLXFBConfig *
glxLookupFBConfigByVID(VisualID vid)85*4882a593Smuzhiyun glxLookupFBConfigByVID(VisualID vid)
86*4882a593Smuzhiyun {
87*4882a593Smuzhiyun     int i, j;
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun     for (i = 0, j = 0; i < __glXNumFBConfigs;
90*4882a593Smuzhiyun          i++, j += (__glXNumActiveScreens + 1)) {
91*4882a593Smuzhiyun         if (__glXFBConfigs[j]->associatedVisualId == vid)
92*4882a593Smuzhiyun             return __glXFBConfigs[j];
93*4882a593Smuzhiyun     }
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun     return NULL;
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun static __GLXFBConfig *
glxLookupBackEndFBConfig(GLXFBConfigID id,int screen)99*4882a593Smuzhiyun glxLookupBackEndFBConfig(GLXFBConfigID id, int screen)
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun     int i;
102*4882a593Smuzhiyun     int j;
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun     for (i = 0, j = 0; i < __glXNumFBConfigs;
105*4882a593Smuzhiyun          i++, j += (__glXNumActiveScreens + 1)) {
106*4882a593Smuzhiyun         if (__glXFBConfigs[j]->id == id)
107*4882a593Smuzhiyun             return __glXFBConfigs[j + screen + 1];
108*4882a593Smuzhiyun     }
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun     return NULL;
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun Display *
GetBackEndDisplay(__GLXclientState * cl,int s)115*4882a593Smuzhiyun GetBackEndDisplay(__GLXclientState * cl, int s)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun     if (!cl->be_displays[s]) {
118*4882a593Smuzhiyun         cl->be_displays[s] =
119*4882a593Smuzhiyun             XOpenDisplay(DisplayString(dmxScreens[s].beDisplay));
120*4882a593Smuzhiyun     }
121*4882a593Smuzhiyun     return cl->be_displays[s];
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun /**
125*4882a593Smuzhiyun  * Convert the render type bits from fbconfig into context render type.
126*4882a593Smuzhiyun  */
127*4882a593Smuzhiyun static int
renderTypeBitsToRenderTypeEnum(int fbRenderType)128*4882a593Smuzhiyun renderTypeBitsToRenderTypeEnum(int fbRenderType)
129*4882a593Smuzhiyun {
130*4882a593Smuzhiyun     if (fbRenderType & GLX_RGBA_BIT)
131*4882a593Smuzhiyun         return GLX_RGBA_TYPE;
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun     if (fbRenderType & GLX_COLOR_INDEX_BIT)
134*4882a593Smuzhiyun         return  GLX_COLOR_INDEX_TYPE;
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun     if (fbRenderType & GLX_RGBA_FLOAT_BIT_ARB)
137*4882a593Smuzhiyun         return GLX_RGBA_FLOAT_TYPE_ARB;
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun     if (fbRenderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT)
140*4882a593Smuzhiyun         return GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun     /* There's no recognized renderType in the config */
143*4882a593Smuzhiyun     return GLX_RGBA_TYPE;
144*4882a593Smuzhiyun }
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun /*
147*4882a593Smuzhiyun ** Create a GL context with the given properties.
148*4882a593Smuzhiyun */
149*4882a593Smuzhiyun static int
CreateContext(__GLXclientState * cl,GLXContextID gcId,VisualID vid,GLXFBConfigID fbconfigId,int screen,GLXContextID shareList,int isDirect)150*4882a593Smuzhiyun CreateContext(__GLXclientState * cl,
151*4882a593Smuzhiyun               GLXContextID gcId,
152*4882a593Smuzhiyun               VisualID vid, GLXFBConfigID fbconfigId,
153*4882a593Smuzhiyun               int screen, GLXContextID shareList, int isDirect)
154*4882a593Smuzhiyun {
155*4882a593Smuzhiyun     ClientPtr client = cl->client;
156*4882a593Smuzhiyun     xGLXCreateContextReq *be_req;
157*4882a593Smuzhiyun     xGLXCreateNewContextReq *be_new_req;
158*4882a593Smuzhiyun     VisualPtr pVisual;
159*4882a593Smuzhiyun     ScreenPtr pScreen;
160*4882a593Smuzhiyun     __GLXcontext *glxc, *shareglxc;
161*4882a593Smuzhiyun     __GLXvisualConfig *pGlxVisual;
162*4882a593Smuzhiyun     __GLXscreenInfo *pGlxScreen;
163*4882a593Smuzhiyun     VisualID visual = vid;
164*4882a593Smuzhiyun     GLint i;
165*4882a593Smuzhiyun     int from_screen = screen;
166*4882a593Smuzhiyun     int to_screen = screen;
167*4882a593Smuzhiyun     DMXScreenInfo *dmxScreen;
168*4882a593Smuzhiyun     VisualID be_vid = 0;
169*4882a593Smuzhiyun     GLXFBConfigID be_fbconfigId = 0;
170*4882a593Smuzhiyun     int num_be_screens;
171*4882a593Smuzhiyun     Display *dpy;
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun     /*
174*4882a593Smuzhiyun      ** Check if screen exists.
175*4882a593Smuzhiyun      */
176*4882a593Smuzhiyun     if (screen >= screenInfo.numScreens) {
177*4882a593Smuzhiyun         client->errorValue = screen;
178*4882a593Smuzhiyun         return BadValue;
179*4882a593Smuzhiyun     }
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun #ifdef PANORAMIX
182*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
183*4882a593Smuzhiyun         from_screen = 0;
184*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
185*4882a593Smuzhiyun     }
186*4882a593Smuzhiyun #endif
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun     /*
189*4882a593Smuzhiyun      ** Find the display list space that we want to share.
190*4882a593Smuzhiyun      **
191*4882a593Smuzhiyun      */
192*4882a593Smuzhiyun     if (shareList == None) {
193*4882a593Smuzhiyun         shareglxc = NULL;
194*4882a593Smuzhiyun     }
195*4882a593Smuzhiyun     else {
196*4882a593Smuzhiyun         dixLookupResourceByType((void **) &shareglxc, shareList,
197*4882a593Smuzhiyun                                 __glXContextRes, NullClient, DixUnknownAccess);
198*4882a593Smuzhiyun         if (!shareglxc) {
199*4882a593Smuzhiyun             client->errorValue = shareList;
200*4882a593Smuzhiyun             return __glXBadContext;
201*4882a593Smuzhiyun         }
202*4882a593Smuzhiyun     }
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun     /*
205*4882a593Smuzhiyun      ** Allocate memory for the new context
206*4882a593Smuzhiyun      */
207*4882a593Smuzhiyun     glxc = calloc(1, sizeof(__GLXcontext));
208*4882a593Smuzhiyun     if (!glxc) {
209*4882a593Smuzhiyun         return BadAlloc;
210*4882a593Smuzhiyun     }
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun     pScreen = screenInfo.screens[screen];
213*4882a593Smuzhiyun     pGlxScreen = &__glXActiveScreens[screen];
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun     if (fbconfigId != None) {
216*4882a593Smuzhiyun         glxc->pFBConfig = glxLookupFBConfig(fbconfigId);
217*4882a593Smuzhiyun         if (!glxc->pFBConfig) {
218*4882a593Smuzhiyun             client->errorValue = fbconfigId;
219*4882a593Smuzhiyun             free(glxc);
220*4882a593Smuzhiyun             return BadValue;
221*4882a593Smuzhiyun         }
222*4882a593Smuzhiyun         visual = glxc->pFBConfig->associatedVisualId;
223*4882a593Smuzhiyun     }
224*4882a593Smuzhiyun     else {
225*4882a593Smuzhiyun         glxc->pFBConfig = NULL;
226*4882a593Smuzhiyun     }
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun     if (visual != None) {
229*4882a593Smuzhiyun         /*
230*4882a593Smuzhiyun          ** Check if the visual ID is valid for this screen.
231*4882a593Smuzhiyun          */
232*4882a593Smuzhiyun         pVisual = pScreen->visuals;
233*4882a593Smuzhiyun         for (i = 0; i < pScreen->numVisuals; i++, pVisual++) {
234*4882a593Smuzhiyun             if (pVisual->vid == visual) {
235*4882a593Smuzhiyun                 break;
236*4882a593Smuzhiyun             }
237*4882a593Smuzhiyun         }
238*4882a593Smuzhiyun         if (i == pScreen->numVisuals) {
239*4882a593Smuzhiyun             client->errorValue = visual;
240*4882a593Smuzhiyun             free(glxc);
241*4882a593Smuzhiyun             return BadValue;
242*4882a593Smuzhiyun         }
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun         pGlxVisual = pGlxScreen->pGlxVisual;
245*4882a593Smuzhiyun         for (i = 0; i < pGlxScreen->numVisuals; i++, pGlxVisual++) {
246*4882a593Smuzhiyun             if (pGlxVisual->vid == visual) {
247*4882a593Smuzhiyun                 break;
248*4882a593Smuzhiyun             }
249*4882a593Smuzhiyun         }
250*4882a593Smuzhiyun         if (i == pGlxScreen->numVisuals) {
251*4882a593Smuzhiyun             /*
252*4882a593Smuzhiyun              ** Visual not support on this screen by this OpenGL implementation.
253*4882a593Smuzhiyun              */
254*4882a593Smuzhiyun             client->errorValue = visual;
255*4882a593Smuzhiyun             free(glxc);
256*4882a593Smuzhiyun             return BadValue;
257*4882a593Smuzhiyun         }
258*4882a593Smuzhiyun 
259*4882a593Smuzhiyun         if (glxc->pFBConfig == NULL) {
260*4882a593Smuzhiyun             glxc->pFBConfig = glxLookupFBConfigByVID(visual);
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun             if (glxc->pFBConfig == NULL) {
263*4882a593Smuzhiyun                 /*
264*4882a593Smuzhiyun                  * visual does not have an FBConfig ???
265*4882a593Smuzhiyun                  client->errorValue = visual;
266*4882a593Smuzhiyun                  free( glxc );
267*4882a593Smuzhiyun                  return BadValue;
268*4882a593Smuzhiyun                  */
269*4882a593Smuzhiyun             }
270*4882a593Smuzhiyun         }
271*4882a593Smuzhiyun     }
272*4882a593Smuzhiyun     else {
273*4882a593Smuzhiyun         pVisual = NULL;
274*4882a593Smuzhiyun         pGlxVisual = NULL;
275*4882a593Smuzhiyun     }
276*4882a593Smuzhiyun 
277*4882a593Smuzhiyun     glxc->pScreen = pScreen;
278*4882a593Smuzhiyun     glxc->pGlxScreen = pGlxScreen;
279*4882a593Smuzhiyun     glxc->pVisual = pVisual;
280*4882a593Smuzhiyun     glxc->pGlxVisual = pGlxVisual;
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun     /*
283*4882a593Smuzhiyun      * allocate memory for back-end servers info
284*4882a593Smuzhiyun      */
285*4882a593Smuzhiyun     num_be_screens = to_screen - from_screen + 1;
286*4882a593Smuzhiyun     glxc->real_ids = xallocarray(num_be_screens, sizeof(XID));
287*4882a593Smuzhiyun     if (!glxc->real_ids) {
288*4882a593Smuzhiyun         return BadAlloc;
289*4882a593Smuzhiyun     }
290*4882a593Smuzhiyun     glxc->real_vids = xallocarray(num_be_screens, sizeof(XID));
291*4882a593Smuzhiyun     if (!glxc->real_vids) {
292*4882a593Smuzhiyun         return BadAlloc;
293*4882a593Smuzhiyun     }
294*4882a593Smuzhiyun 
295*4882a593Smuzhiyun     for (screen = from_screen; screen <= to_screen; screen++) {
296*4882a593Smuzhiyun         int sent = 0;
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun         pScreen = screenInfo.screens[screen];
299*4882a593Smuzhiyun         pGlxScreen = &__glXActiveScreens[screen];
300*4882a593Smuzhiyun         dmxScreen = &dmxScreens[screen];
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun         if (glxc->pFBConfig) {
303*4882a593Smuzhiyun             __GLXFBConfig *beFBConfig =
304*4882a593Smuzhiyun                 glxLookupBackEndFBConfig(glxc->pFBConfig->id,
305*4882a593Smuzhiyun                                          screen);
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun             be_fbconfigId = beFBConfig->id;
308*4882a593Smuzhiyun         }
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun         if (pGlxVisual) {
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun             be_vid = glxMatchGLXVisualInConfigList(pGlxVisual,
313*4882a593Smuzhiyun                                                    dmxScreen->glxVisuals,
314*4882a593Smuzhiyun                                                    dmxScreen->numGlxVisuals);
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun             if (!be_vid) {
317*4882a593Smuzhiyun                 /* visual is not supported on the back-end server */
318*4882a593Smuzhiyun                 free(glxc->real_ids);
319*4882a593Smuzhiyun                 free(glxc->real_vids);
320*4882a593Smuzhiyun                 free(glxc);
321*4882a593Smuzhiyun                 return BadValue;
322*4882a593Smuzhiyun             }
323*4882a593Smuzhiyun         }
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun         glxc->real_ids[screen - from_screen] =
326*4882a593Smuzhiyun             XAllocID(GetBackEndDisplay(cl, screen));
327*4882a593Smuzhiyun 
328*4882a593Smuzhiyun         /* send the create context request to the back-end server */
329*4882a593Smuzhiyun         dpy = GetBackEndDisplay(cl, screen);
330*4882a593Smuzhiyun         if (glxc->pFBConfig) {
331*4882a593Smuzhiyun             /* For a specific visual, multiple render types (i.e., both RGB
332*4882a593Smuzhiyun              * and COLOR INDEX) can be accessible. The only parameter to
333*4882a593Smuzhiyun              * choose the renderType should be the class of the colormap,
334*4882a593Smuzhiyun              * since the first classes do not support RGB mode (only COLOR
335*4882a593Smuzhiyun              * INDEX), and TrueColor and DirectColor do not support COLOR
336*4882a593Smuzhiyun              * INDEX.
337*4882a593Smuzhiyun              */
338*4882a593Smuzhiyun             int renderType = GLX_RGBA_TYPE;
339*4882a593Smuzhiyun 
340*4882a593Smuzhiyun             if (pVisual) {
341*4882a593Smuzhiyun                 switch (pVisual->class) {
342*4882a593Smuzhiyun                 case PseudoColor:
343*4882a593Smuzhiyun                 case StaticColor:
344*4882a593Smuzhiyun                 case GrayScale:
345*4882a593Smuzhiyun                 case StaticGray:
346*4882a593Smuzhiyun                     renderType = GLX_COLOR_INDEX_TYPE;
347*4882a593Smuzhiyun                     break;
348*4882a593Smuzhiyun                 case TrueColor:
349*4882a593Smuzhiyun                 case DirectColor:
350*4882a593Smuzhiyun                 default:
351*4882a593Smuzhiyun                     renderType = GLX_RGBA_TYPE;
352*4882a593Smuzhiyun                     break;
353*4882a593Smuzhiyun                 }
354*4882a593Smuzhiyun             } else {
355*4882a593Smuzhiyun                 renderType =
356*4882a593Smuzhiyun                     renderTypeBitsToRenderTypeEnum(glxc->pFBConfig->renderType);
357*4882a593Smuzhiyun             }
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun             if (__GLX_IS_VERSION_SUPPORTED(1, 3)) {
360*4882a593Smuzhiyun                 LockDisplay(dpy);
361*4882a593Smuzhiyun                 GetReq(GLXCreateNewContext, be_new_req);
362*4882a593Smuzhiyun                 be_new_req->reqType = dmxScreen->glxMajorOpcode;
363*4882a593Smuzhiyun                 be_new_req->glxCode = X_GLXCreateNewContext;
364*4882a593Smuzhiyun                 be_new_req->context =
365*4882a593Smuzhiyun                     (unsigned int) glxc->real_ids[screen - from_screen];
366*4882a593Smuzhiyun                 be_new_req->fbconfig = (unsigned int) be_fbconfigId;
367*4882a593Smuzhiyun                 be_new_req->screen = DefaultScreen(dpy);
368*4882a593Smuzhiyun                 be_new_req->renderType = renderType;
369*4882a593Smuzhiyun 
370*4882a593Smuzhiyun                 be_new_req->shareList =
371*4882a593Smuzhiyun                     (shareglxc ? shareglxc->real_ids[screen - from_screen] : 0);
372*4882a593Smuzhiyun                 be_new_req->isDirect = 0;
373*4882a593Smuzhiyun                 UnlockDisplay(dpy);
374*4882a593Smuzhiyun                 glxc->real_vids[screen - from_screen] = be_fbconfigId;
375*4882a593Smuzhiyun                 sent = 1;
376*4882a593Smuzhiyun             }
377*4882a593Smuzhiyun             else if (glxIsExtensionSupported("GLX_SGIX_fbconfig")) {
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun                 xGLXCreateContextWithConfigSGIXReq *ext_req;
380*4882a593Smuzhiyun                 xGLXVendorPrivateReq *vpreq;
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun                 LockDisplay(dpy);
383*4882a593Smuzhiyun                 GetReqExtra(GLXVendorPrivate,
384*4882a593Smuzhiyun                             sz_xGLXCreateContextWithConfigSGIXReq -
385*4882a593Smuzhiyun                             sz_xGLXVendorPrivateReq, vpreq);
386*4882a593Smuzhiyun                 ext_req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
387*4882a593Smuzhiyun                 ext_req->reqType = dmxScreen->glxMajorOpcode;
388*4882a593Smuzhiyun                 ext_req->glxCode = X_GLXVendorPrivate;
389*4882a593Smuzhiyun                 ext_req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
390*4882a593Smuzhiyun                 ext_req->context =
391*4882a593Smuzhiyun                     (unsigned int) glxc->real_ids[screen - from_screen];
392*4882a593Smuzhiyun                 ext_req->fbconfig = (unsigned int) be_fbconfigId;
393*4882a593Smuzhiyun                 ext_req->screen = DefaultScreen(dpy);
394*4882a593Smuzhiyun                 ext_req->renderType = renderType;
395*4882a593Smuzhiyun                 ext_req->shareList =
396*4882a593Smuzhiyun                     (shareglxc ? shareglxc->real_ids[screen - from_screen] : 0);
397*4882a593Smuzhiyun                 ext_req->isDirect = 0;
398*4882a593Smuzhiyun                 UnlockDisplay(dpy);
399*4882a593Smuzhiyun                 glxc->real_vids[screen - from_screen] = be_fbconfigId;
400*4882a593Smuzhiyun                 sent = 1;
401*4882a593Smuzhiyun             }
402*4882a593Smuzhiyun         }
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun         if (!sent) {
405*4882a593Smuzhiyun             LockDisplay(dpy);
406*4882a593Smuzhiyun             GetReq(GLXCreateContext, be_req);
407*4882a593Smuzhiyun             be_req->reqType = dmxScreen->glxMajorOpcode;
408*4882a593Smuzhiyun             be_req->glxCode = X_GLXCreateContext;
409*4882a593Smuzhiyun             be_req->context =
410*4882a593Smuzhiyun                 (unsigned int) glxc->real_ids[screen - from_screen];
411*4882a593Smuzhiyun             be_req->visual = (unsigned int) be_vid;
412*4882a593Smuzhiyun             be_req->screen = DefaultScreen(dpy);
413*4882a593Smuzhiyun             be_req->shareList =
414*4882a593Smuzhiyun                 (shareglxc ? shareglxc->real_ids[screen - from_screen] : 0);
415*4882a593Smuzhiyun             be_req->isDirect = 0;
416*4882a593Smuzhiyun             UnlockDisplay(dpy);
417*4882a593Smuzhiyun             glxc->real_vids[screen - from_screen] = be_vid;
418*4882a593Smuzhiyun         }
419*4882a593Smuzhiyun         SyncHandle();
420*4882a593Smuzhiyun 
421*4882a593Smuzhiyun     }
422*4882a593Smuzhiyun 
423*4882a593Smuzhiyun     /*
424*4882a593Smuzhiyun      ** Register this context as a resource.
425*4882a593Smuzhiyun      */
426*4882a593Smuzhiyun     if (!AddResource(gcId, __glXContextRes, (void *) glxc)) {
427*4882a593Smuzhiyun         free(glxc->real_ids);
428*4882a593Smuzhiyun         free(glxc->real_vids);
429*4882a593Smuzhiyun         free(glxc);
430*4882a593Smuzhiyun         client->errorValue = gcId;
431*4882a593Smuzhiyun         return BadAlloc;
432*4882a593Smuzhiyun     }
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun     /*
435*4882a593Smuzhiyun      ** Finally, now that everything is working, setup the rest of the
436*4882a593Smuzhiyun      ** context.
437*4882a593Smuzhiyun      */
438*4882a593Smuzhiyun     glxc->id = gcId;
439*4882a593Smuzhiyun     glxc->share_id = shareList;
440*4882a593Smuzhiyun     glxc->idExists = GL_TRUE;
441*4882a593Smuzhiyun     glxc->isCurrent = GL_FALSE;
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun     return Success;
444*4882a593Smuzhiyun }
445*4882a593Smuzhiyun 
446*4882a593Smuzhiyun int
__glXCreateContext(__GLXclientState * cl,GLbyte * pc)447*4882a593Smuzhiyun __glXCreateContext(__GLXclientState * cl, GLbyte * pc)
448*4882a593Smuzhiyun {
449*4882a593Smuzhiyun     xGLXCreateContextReq *req = (xGLXCreateContextReq *) pc;
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun     return (CreateContext(cl, req->context, req->visual, None,
452*4882a593Smuzhiyun                           req->screen, req->shareList, req->isDirect));
453*4882a593Smuzhiyun 
454*4882a593Smuzhiyun }
455*4882a593Smuzhiyun 
456*4882a593Smuzhiyun int
__glXCreateNewContext(__GLXclientState * cl,GLbyte * pc)457*4882a593Smuzhiyun __glXCreateNewContext(__GLXclientState * cl, GLbyte * pc)
458*4882a593Smuzhiyun {
459*4882a593Smuzhiyun     xGLXCreateNewContextReq *req = (xGLXCreateNewContextReq *) pc;
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun     return (CreateContext(cl, req->context, None, req->fbconfig,
462*4882a593Smuzhiyun                           req->screen, req->shareList, req->isDirect));
463*4882a593Smuzhiyun 
464*4882a593Smuzhiyun }
465*4882a593Smuzhiyun 
466*4882a593Smuzhiyun int
__glXCreateContextWithConfigSGIX(__GLXclientState * cl,GLbyte * pc)467*4882a593Smuzhiyun __glXCreateContextWithConfigSGIX(__GLXclientState * cl, GLbyte * pc)
468*4882a593Smuzhiyun {
469*4882a593Smuzhiyun     xGLXCreateContextWithConfigSGIXReq *req =
470*4882a593Smuzhiyun         (xGLXCreateContextWithConfigSGIXReq *) pc;
471*4882a593Smuzhiyun 
472*4882a593Smuzhiyun     return (CreateContext(cl, req->context, None, req->fbconfig,
473*4882a593Smuzhiyun                           req->screen, req->shareList, req->isDirect));
474*4882a593Smuzhiyun 
475*4882a593Smuzhiyun }
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun int
__glXQueryMaxSwapBarriersSGIX(__GLXclientState * cl,GLbyte * pc)478*4882a593Smuzhiyun __glXQueryMaxSwapBarriersSGIX(__GLXclientState * cl, GLbyte * pc)
479*4882a593Smuzhiyun {
480*4882a593Smuzhiyun     ClientPtr client = cl->client;
481*4882a593Smuzhiyun     xGLXQueryMaxSwapBarriersSGIXReq *req =
482*4882a593Smuzhiyun         (xGLXQueryMaxSwapBarriersSGIXReq *) pc;
483*4882a593Smuzhiyun     xGLXQueryMaxSwapBarriersSGIXReply reply = {
484*4882a593Smuzhiyun         .type = X_Reply,
485*4882a593Smuzhiyun         .sequenceNumber = client->sequence,
486*4882a593Smuzhiyun         .length = 0,
487*4882a593Smuzhiyun         .max = QueryMaxSwapBarriersSGIX(req->screen)
488*4882a593Smuzhiyun     };
489*4882a593Smuzhiyun 
490*4882a593Smuzhiyun     if (client->swapped) {
491*4882a593Smuzhiyun         __glXSwapQueryMaxSwapBarriersSGIXReply(client, &reply);
492*4882a593Smuzhiyun     }
493*4882a593Smuzhiyun     else {
494*4882a593Smuzhiyun         WriteToClient(client, sz_xGLXQueryMaxSwapBarriersSGIXReply, &reply);
495*4882a593Smuzhiyun     }
496*4882a593Smuzhiyun 
497*4882a593Smuzhiyun     return Success;
498*4882a593Smuzhiyun }
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun int
__glXBindSwapBarrierSGIX(__GLXclientState * cl,GLbyte * pc)501*4882a593Smuzhiyun __glXBindSwapBarrierSGIX(__GLXclientState * cl, GLbyte * pc)
502*4882a593Smuzhiyun {
503*4882a593Smuzhiyun     ClientPtr client = cl->client;
504*4882a593Smuzhiyun     xGLXBindSwapBarrierSGIXReq *req = (xGLXBindSwapBarrierSGIXReq *) pc;
505*4882a593Smuzhiyun     DrawablePtr pDraw;
506*4882a593Smuzhiyun     __GLXpixmap *pGlxPixmap = NULL;
507*4882a593Smuzhiyun     __glXWindow *pGlxWindow = NULL;
508*4882a593Smuzhiyun     int rc;
509*4882a593Smuzhiyun 
510*4882a593Smuzhiyun     rc = dixLookupDrawable(&pDraw, req->drawable, client, 0, DixGetAttrAccess);
511*4882a593Smuzhiyun     if (rc != Success) {
512*4882a593Smuzhiyun         dixLookupResourceByType((void **) &pGlxPixmap, req->drawable,
513*4882a593Smuzhiyun                                 __glXPixmapRes, NullClient, DixUnknownAccess);
514*4882a593Smuzhiyun         if (pGlxPixmap)
515*4882a593Smuzhiyun             pDraw = pGlxPixmap->pDraw;
516*4882a593Smuzhiyun     }
517*4882a593Smuzhiyun 
518*4882a593Smuzhiyun     if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1, 3)) {
519*4882a593Smuzhiyun         dixLookupResourceByType((void **) &pGlxWindow, req->drawable,
520*4882a593Smuzhiyun                                 __glXWindowRes, NullClient, DixUnknownAccess);
521*4882a593Smuzhiyun         if (pGlxWindow)
522*4882a593Smuzhiyun             pDraw = pGlxWindow->pDraw;
523*4882a593Smuzhiyun     }
524*4882a593Smuzhiyun 
525*4882a593Smuzhiyun     if (!pDraw) {
526*4882a593Smuzhiyun         client->errorValue = req->drawable;
527*4882a593Smuzhiyun         return __glXBadDrawable;
528*4882a593Smuzhiyun     }
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun     return BindSwapBarrierSGIX(pDraw, req->barrier);
531*4882a593Smuzhiyun }
532*4882a593Smuzhiyun 
533*4882a593Smuzhiyun int
__glXJoinSwapGroupSGIX(__GLXclientState * cl,GLbyte * pc)534*4882a593Smuzhiyun __glXJoinSwapGroupSGIX(__GLXclientState * cl, GLbyte * pc)
535*4882a593Smuzhiyun {
536*4882a593Smuzhiyun     ClientPtr client = cl->client;
537*4882a593Smuzhiyun     xGLXJoinSwapGroupSGIXReq *req = (xGLXJoinSwapGroupSGIXReq *) pc;
538*4882a593Smuzhiyun     DrawablePtr pDraw, pMember = NULL;
539*4882a593Smuzhiyun     __GLXpixmap *pGlxPixmap = NULL;
540*4882a593Smuzhiyun     __glXWindow *pGlxWindow = NULL;
541*4882a593Smuzhiyun     int rc;
542*4882a593Smuzhiyun 
543*4882a593Smuzhiyun     rc = dixLookupDrawable(&pDraw, req->drawable, client, 0, DixManageAccess);
544*4882a593Smuzhiyun     if (rc != Success) {
545*4882a593Smuzhiyun         dixLookupResourceByType((void **) &pGlxPixmap, req->drawable,
546*4882a593Smuzhiyun                                 __glXPixmapRes, NullClient, DixUnknownAccess);
547*4882a593Smuzhiyun         if (pGlxPixmap)
548*4882a593Smuzhiyun             pDraw = pGlxPixmap->pDraw;
549*4882a593Smuzhiyun     }
550*4882a593Smuzhiyun 
551*4882a593Smuzhiyun     if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1, 3)) {
552*4882a593Smuzhiyun         dixLookupResourceByType((void **) &pGlxWindow, req->drawable,
553*4882a593Smuzhiyun                                 __glXWindowRes, NullClient, DixUnknownAccess);
554*4882a593Smuzhiyun         if (pGlxWindow)
555*4882a593Smuzhiyun             pDraw = pGlxWindow->pDraw;
556*4882a593Smuzhiyun     }
557*4882a593Smuzhiyun 
558*4882a593Smuzhiyun     if (!pDraw) {
559*4882a593Smuzhiyun         client->errorValue = req->drawable;
560*4882a593Smuzhiyun         return __glXBadDrawable;
561*4882a593Smuzhiyun     }
562*4882a593Smuzhiyun 
563*4882a593Smuzhiyun     if (req->member != None) {
564*4882a593Smuzhiyun         rc = dixLookupDrawable(&pMember, req->member, client, 0,
565*4882a593Smuzhiyun                                DixGetAttrAccess);
566*4882a593Smuzhiyun         if (rc != Success) {
567*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxPixmap, req->member,
568*4882a593Smuzhiyun                                     __glXPixmapRes, NullClient,
569*4882a593Smuzhiyun                                     DixUnknownAccess);
570*4882a593Smuzhiyun             if (pGlxPixmap)
571*4882a593Smuzhiyun                 pMember = pGlxPixmap->pDraw;
572*4882a593Smuzhiyun         }
573*4882a593Smuzhiyun 
574*4882a593Smuzhiyun         if (!pMember && __GLX_IS_VERSION_SUPPORTED(1, 3)) {
575*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxWindow, req->member,
576*4882a593Smuzhiyun                                     __glXWindowRes, NullClient,
577*4882a593Smuzhiyun                                     DixUnknownAccess);
578*4882a593Smuzhiyun             if (pGlxWindow)
579*4882a593Smuzhiyun                 pMember = pGlxWindow->pDraw;
580*4882a593Smuzhiyun         }
581*4882a593Smuzhiyun 
582*4882a593Smuzhiyun         if (!pMember) {
583*4882a593Smuzhiyun             client->errorValue = req->member;
584*4882a593Smuzhiyun             return __glXBadDrawable;
585*4882a593Smuzhiyun         }
586*4882a593Smuzhiyun     }
587*4882a593Smuzhiyun 
588*4882a593Smuzhiyun     return JoinSwapGroupSGIX(pDraw, pMember);
589*4882a593Smuzhiyun }
590*4882a593Smuzhiyun 
591*4882a593Smuzhiyun /*
592*4882a593Smuzhiyun ** Destroy a GL context as an X resource.
593*4882a593Smuzhiyun */
594*4882a593Smuzhiyun int
__glXDestroyContext(__GLXclientState * cl,GLbyte * pc)595*4882a593Smuzhiyun __glXDestroyContext(__GLXclientState * cl, GLbyte * pc)
596*4882a593Smuzhiyun {
597*4882a593Smuzhiyun     ClientPtr client = cl->client;
598*4882a593Smuzhiyun     xGLXDestroyContextReq *req = (xGLXDestroyContextReq *) pc;
599*4882a593Smuzhiyun     xGLXDestroyContextReq *be_req;
600*4882a593Smuzhiyun     GLXContextID gcId = req->context;
601*4882a593Smuzhiyun     __GLXcontext *glxc;
602*4882a593Smuzhiyun     int from_screen = 0;
603*4882a593Smuzhiyun     int to_screen = 0;
604*4882a593Smuzhiyun     int s;
605*4882a593Smuzhiyun 
606*4882a593Smuzhiyun     dixLookupResourceByType((void **) &glxc, gcId, __glXContextRes,
607*4882a593Smuzhiyun                             NullClient, DixUnknownAccess);
608*4882a593Smuzhiyun     if (glxc) {
609*4882a593Smuzhiyun         /*
610*4882a593Smuzhiyun          ** Just free the resource; don't actually destroy the context,
611*4882a593Smuzhiyun          ** because it might be in use.  The
612*4882a593Smuzhiyun          ** destroy method will be called by the resource destruction routine
613*4882a593Smuzhiyun          ** if necessary.
614*4882a593Smuzhiyun          */
615*4882a593Smuzhiyun         FreeResourceByType(gcId, __glXContextRes, FALSE);
616*4882a593Smuzhiyun 
617*4882a593Smuzhiyun         from_screen = to_screen = glxc->pScreen->myNum;
618*4882a593Smuzhiyun 
619*4882a593Smuzhiyun     }
620*4882a593Smuzhiyun     else {
621*4882a593Smuzhiyun         client->errorValue = gcId;
622*4882a593Smuzhiyun         return __glXBadContext;
623*4882a593Smuzhiyun     }
624*4882a593Smuzhiyun 
625*4882a593Smuzhiyun #ifdef PANORAMIX
626*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
627*4882a593Smuzhiyun         from_screen = 0;
628*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
629*4882a593Smuzhiyun     }
630*4882a593Smuzhiyun #endif
631*4882a593Smuzhiyun 
632*4882a593Smuzhiyun     /*
633*4882a593Smuzhiyun      * send DestroyContext request to all back-end servers
634*4882a593Smuzhiyun      */
635*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
636*4882a593Smuzhiyun         DMXScreenInfo *dmxScreen = &dmxScreens[s];
637*4882a593Smuzhiyun         Display *dpy = GetBackEndDisplay(cl, s);
638*4882a593Smuzhiyun 
639*4882a593Smuzhiyun         LockDisplay(dpy);
640*4882a593Smuzhiyun         GetReq(GLXDestroyContext, be_req);
641*4882a593Smuzhiyun         be_req->reqType = dmxScreen->glxMajorOpcode;
642*4882a593Smuzhiyun         be_req->glxCode = X_GLXDestroyContext;
643*4882a593Smuzhiyun         be_req->context = glxc->real_ids[s - from_screen];
644*4882a593Smuzhiyun         UnlockDisplay(dpy);
645*4882a593Smuzhiyun         SyncHandle();
646*4882a593Smuzhiyun     }
647*4882a593Smuzhiyun 
648*4882a593Smuzhiyun     return Success;
649*4882a593Smuzhiyun }
650*4882a593Smuzhiyun 
651*4882a593Smuzhiyun /*****************************************************************************/
652*4882a593Smuzhiyun 
653*4882a593Smuzhiyun /*
654*4882a593Smuzhiyun ** For each client, the server keeps a table of all the contexts that are
655*4882a593Smuzhiyun ** current for that client (each thread of a client may have its own current
656*4882a593Smuzhiyun ** context).  These routines add, change, and lookup contexts in the table.
657*4882a593Smuzhiyun */
658*4882a593Smuzhiyun 
659*4882a593Smuzhiyun /*
660*4882a593Smuzhiyun ** Add a current context, and return the tag that will be used to refer to it.
661*4882a593Smuzhiyun */
662*4882a593Smuzhiyun static int
AddCurrentContext(__GLXclientState * cl,__GLXcontext * glxc,DrawablePtr pDraw)663*4882a593Smuzhiyun AddCurrentContext(__GLXclientState * cl, __GLXcontext * glxc, DrawablePtr pDraw)
664*4882a593Smuzhiyun {
665*4882a593Smuzhiyun     int i;
666*4882a593Smuzhiyun     int num = cl->numCurrentContexts;
667*4882a593Smuzhiyun     __GLXcontext **table = cl->currentContexts;
668*4882a593Smuzhiyun 
669*4882a593Smuzhiyun     if (!glxc)
670*4882a593Smuzhiyun         return -1;
671*4882a593Smuzhiyun 
672*4882a593Smuzhiyun     /*
673*4882a593Smuzhiyun      ** Try to find an empty slot and use it.
674*4882a593Smuzhiyun      */
675*4882a593Smuzhiyun     for (i = 0; i < num; i++) {
676*4882a593Smuzhiyun         if (!table[i]) {
677*4882a593Smuzhiyun             table[i] = glxc;
678*4882a593Smuzhiyun             return i + 1;
679*4882a593Smuzhiyun         }
680*4882a593Smuzhiyun     }
681*4882a593Smuzhiyun     /*
682*4882a593Smuzhiyun      ** Didn't find a free slot, so we'll have to grow the table.
683*4882a593Smuzhiyun      */
684*4882a593Smuzhiyun     if (!num) {
685*4882a593Smuzhiyun         table = (__GLXcontext **) malloc(sizeof(__GLXcontext *));
686*4882a593Smuzhiyun         cl->currentDrawables = (DrawablePtr *) malloc(sizeof(DrawablePtr));
687*4882a593Smuzhiyun         cl->be_currentCTag = xallocarray(screenInfo.numScreens,
688*4882a593Smuzhiyun                                          sizeof(GLXContextTag));
689*4882a593Smuzhiyun     }
690*4882a593Smuzhiyun     else {
691*4882a593Smuzhiyun         table = reallocarray(table, num + 1, sizeof(__GLXcontext *));
692*4882a593Smuzhiyun         cl->currentDrawables = reallocarray(cl->currentDrawables, num + 1,
693*4882a593Smuzhiyun                                             sizeof(DrawablePtr));
694*4882a593Smuzhiyun         cl->be_currentCTag = reallocarray(cl->be_currentCTag,
695*4882a593Smuzhiyun                                           (num + 1) * screenInfo.numScreens,
696*4882a593Smuzhiyun                                           sizeof(GLXContextTag));
697*4882a593Smuzhiyun     }
698*4882a593Smuzhiyun     table[num] = glxc;
699*4882a593Smuzhiyun     cl->currentDrawables[num] = pDraw;
700*4882a593Smuzhiyun     cl->currentContexts = table;
701*4882a593Smuzhiyun     cl->numCurrentContexts++;
702*4882a593Smuzhiyun 
703*4882a593Smuzhiyun     memset(cl->be_currentCTag + num * screenInfo.numScreens, 0,
704*4882a593Smuzhiyun            screenInfo.numScreens * sizeof(GLXContextTag));
705*4882a593Smuzhiyun 
706*4882a593Smuzhiyun     return num + 1;
707*4882a593Smuzhiyun }
708*4882a593Smuzhiyun 
709*4882a593Smuzhiyun /*
710*4882a593Smuzhiyun ** Given a tag, change the current context for the corresponding entry.
711*4882a593Smuzhiyun */
712*4882a593Smuzhiyun static void
ChangeCurrentContext(__GLXclientState * cl,__GLXcontext * glxc,GLXContextTag tag)713*4882a593Smuzhiyun ChangeCurrentContext(__GLXclientState * cl, __GLXcontext * glxc,
714*4882a593Smuzhiyun                      GLXContextTag tag)
715*4882a593Smuzhiyun {
716*4882a593Smuzhiyun     __GLXcontext **table = cl->currentContexts;
717*4882a593Smuzhiyun 
718*4882a593Smuzhiyun     table[tag - 1] = glxc;
719*4882a593Smuzhiyun }
720*4882a593Smuzhiyun 
721*4882a593Smuzhiyun /*
722*4882a593Smuzhiyun ** Given a tag, and back-end screen number, retrives the current back-end
723*4882a593Smuzhiyun ** tag.
724*4882a593Smuzhiyun */
725*4882a593Smuzhiyun int
GetCurrentBackEndTag(__GLXclientState * cl,GLXContextTag tag,int s)726*4882a593Smuzhiyun GetCurrentBackEndTag(__GLXclientState * cl, GLXContextTag tag, int s)
727*4882a593Smuzhiyun {
728*4882a593Smuzhiyun     if (tag > 0) {
729*4882a593Smuzhiyun         return (cl->be_currentCTag[(tag - 1) * screenInfo.numScreens + s]);
730*4882a593Smuzhiyun     }
731*4882a593Smuzhiyun     else {
732*4882a593Smuzhiyun         return 0;
733*4882a593Smuzhiyun     }
734*4882a593Smuzhiyun }
735*4882a593Smuzhiyun 
736*4882a593Smuzhiyun /*
737*4882a593Smuzhiyun ** Given a tag, and back-end screen number, sets the current back-end
738*4882a593Smuzhiyun ** tag.
739*4882a593Smuzhiyun */
740*4882a593Smuzhiyun static void
SetCurrentBackEndTag(__GLXclientState * cl,GLXContextTag tag,int s,GLXContextTag be_tag)741*4882a593Smuzhiyun SetCurrentBackEndTag(__GLXclientState * cl, GLXContextTag tag, int s,
742*4882a593Smuzhiyun                      GLXContextTag be_tag)
743*4882a593Smuzhiyun {
744*4882a593Smuzhiyun     if (tag > 0) {
745*4882a593Smuzhiyun         cl->be_currentCTag[(tag - 1) * screenInfo.numScreens + s] = be_tag;
746*4882a593Smuzhiyun     }
747*4882a593Smuzhiyun }
748*4882a593Smuzhiyun 
749*4882a593Smuzhiyun /*
750*4882a593Smuzhiyun ** For this implementation we have chosen to simply use the index of the
751*4882a593Smuzhiyun ** context's entry in the table as the context tag.  A tag must be greater
752*4882a593Smuzhiyun ** than 0.
753*4882a593Smuzhiyun */
754*4882a593Smuzhiyun __GLXcontext *
__glXLookupContextByTag(__GLXclientState * cl,GLXContextTag tag)755*4882a593Smuzhiyun __glXLookupContextByTag(__GLXclientState * cl, GLXContextTag tag)
756*4882a593Smuzhiyun {
757*4882a593Smuzhiyun     int num = cl->numCurrentContexts;
758*4882a593Smuzhiyun 
759*4882a593Smuzhiyun     if (tag < 1 || tag > num) {
760*4882a593Smuzhiyun         return 0;
761*4882a593Smuzhiyun     }
762*4882a593Smuzhiyun     else {
763*4882a593Smuzhiyun         return cl->currentContexts[tag - 1];
764*4882a593Smuzhiyun     }
765*4882a593Smuzhiyun }
766*4882a593Smuzhiyun 
767*4882a593Smuzhiyun DrawablePtr
__glXLookupDrawableByTag(__GLXclientState * cl,GLXContextTag tag)768*4882a593Smuzhiyun __glXLookupDrawableByTag(__GLXclientState * cl, GLXContextTag tag)
769*4882a593Smuzhiyun {
770*4882a593Smuzhiyun     int num = cl->numCurrentContexts;
771*4882a593Smuzhiyun 
772*4882a593Smuzhiyun     if (tag < 1 || tag > num) {
773*4882a593Smuzhiyun         return 0;
774*4882a593Smuzhiyun     }
775*4882a593Smuzhiyun     else {
776*4882a593Smuzhiyun         return cl->currentDrawables[tag - 1];
777*4882a593Smuzhiyun     }
778*4882a593Smuzhiyun }
779*4882a593Smuzhiyun 
780*4882a593Smuzhiyun /*****************************************************************************/
781*4882a593Smuzhiyun 
782*4882a593Smuzhiyun static void
StopUsingContext(__GLXcontext * glxc)783*4882a593Smuzhiyun StopUsingContext(__GLXcontext * glxc)
784*4882a593Smuzhiyun {
785*4882a593Smuzhiyun     if (glxc) {
786*4882a593Smuzhiyun         if (glxc == __glXLastContext) {
787*4882a593Smuzhiyun             /* Tell server GL library */
788*4882a593Smuzhiyun             __glXLastContext = 0;
789*4882a593Smuzhiyun         }
790*4882a593Smuzhiyun         glxc->isCurrent = GL_FALSE;
791*4882a593Smuzhiyun         if (!glxc->idExists) {
792*4882a593Smuzhiyun             __glXFreeContext(glxc);
793*4882a593Smuzhiyun         }
794*4882a593Smuzhiyun     }
795*4882a593Smuzhiyun }
796*4882a593Smuzhiyun 
797*4882a593Smuzhiyun static void
StartUsingContext(__GLXclientState * cl,__GLXcontext * glxc)798*4882a593Smuzhiyun StartUsingContext(__GLXclientState * cl, __GLXcontext * glxc)
799*4882a593Smuzhiyun {
800*4882a593Smuzhiyun     glxc->isCurrent = GL_TRUE;
801*4882a593Smuzhiyun }
802*4882a593Smuzhiyun 
803*4882a593Smuzhiyun /*****************************************************************************/
804*4882a593Smuzhiyun /*
805*4882a593Smuzhiyun ** Make an OpenGL context and drawable current.
806*4882a593Smuzhiyun */
807*4882a593Smuzhiyun static int
MakeCurrent(__GLXclientState * cl,GLXDrawable drawable,GLXDrawable readdrawable,GLXContextID context,GLXContextTag oldContextTag)808*4882a593Smuzhiyun MakeCurrent(__GLXclientState * cl,
809*4882a593Smuzhiyun             GLXDrawable drawable,
810*4882a593Smuzhiyun             GLXDrawable readdrawable,
811*4882a593Smuzhiyun             GLXContextID context, GLXContextTag oldContextTag)
812*4882a593Smuzhiyun {
813*4882a593Smuzhiyun     ClientPtr client = cl->client;
814*4882a593Smuzhiyun     DrawablePtr pDraw = NULL;
815*4882a593Smuzhiyun     DrawablePtr pReadDraw = NULL;
816*4882a593Smuzhiyun     xGLXMakeCurrentReadSGIReply new_reply = {
817*4882a593Smuzhiyun         .type = X_Reply,
818*4882a593Smuzhiyun         .sequenceNumber = client->sequence,
819*4882a593Smuzhiyun         .length = 0
820*4882a593Smuzhiyun     };
821*4882a593Smuzhiyun     xGLXMakeCurrentReq *be_req;
822*4882a593Smuzhiyun     xGLXMakeCurrentReply be_reply;
823*4882a593Smuzhiyun     xGLXMakeContextCurrentReq *be_new_req;
824*4882a593Smuzhiyun     xGLXMakeContextCurrentReply be_new_reply;
825*4882a593Smuzhiyun     GLXDrawable drawId = drawable;
826*4882a593Smuzhiyun     GLXDrawable readId = readdrawable;
827*4882a593Smuzhiyun     GLXContextID contextId = context;
828*4882a593Smuzhiyun     __GLXpixmap *pGlxPixmap = 0;
829*4882a593Smuzhiyun     __GLXpixmap *pReadGlxPixmap = 0;
830*4882a593Smuzhiyun     __GLXcontext *glxc, *prevglxc;
831*4882a593Smuzhiyun     GLXContextTag tag = oldContextTag;
832*4882a593Smuzhiyun     WindowPtr pWin = NULL;
833*4882a593Smuzhiyun     WindowPtr pReadWin = NULL;
834*4882a593Smuzhiyun     __glXWindow *pGlxWindow = NULL;
835*4882a593Smuzhiyun     __glXWindow *pGlxReadWindow = NULL;
836*4882a593Smuzhiyun     __glXPbuffer *pGlxPbuffer = NULL;
837*4882a593Smuzhiyun     __glXPbuffer *pGlxReadPbuffer = NULL;
838*4882a593Smuzhiyun 
839*4882a593Smuzhiyun #ifdef PANORAMIX
840*4882a593Smuzhiyun     PanoramiXRes *pXinDraw = NULL;
841*4882a593Smuzhiyun     PanoramiXRes *pXinReadDraw = NULL;
842*4882a593Smuzhiyun #endif
843*4882a593Smuzhiyun     int from_screen = 0;
844*4882a593Smuzhiyun     int to_screen = 0;
845*4882a593Smuzhiyun     int s, rc;
846*4882a593Smuzhiyun 
847*4882a593Smuzhiyun     /*
848*4882a593Smuzhiyun      ** If one is None and the other isn't, it's a bad match.
849*4882a593Smuzhiyun      */
850*4882a593Smuzhiyun     if ((drawId == None && contextId != None) ||
851*4882a593Smuzhiyun         (drawId != None && contextId == None)) {
852*4882a593Smuzhiyun         return BadMatch;
853*4882a593Smuzhiyun     }
854*4882a593Smuzhiyun 
855*4882a593Smuzhiyun     /*
856*4882a593Smuzhiyun      ** Lookup old context.  If we have one, it must be in a usable state.
857*4882a593Smuzhiyun      */
858*4882a593Smuzhiyun     if (tag != 0) {
859*4882a593Smuzhiyun         prevglxc = __glXLookupContextByTag(cl, tag);
860*4882a593Smuzhiyun         if (!prevglxc) {
861*4882a593Smuzhiyun             /*
862*4882a593Smuzhiyun              ** Tag for previous context is invalid.
863*4882a593Smuzhiyun              */
864*4882a593Smuzhiyun             return __glXBadContextTag;
865*4882a593Smuzhiyun         }
866*4882a593Smuzhiyun     }
867*4882a593Smuzhiyun     else {
868*4882a593Smuzhiyun         prevglxc = 0;
869*4882a593Smuzhiyun     }
870*4882a593Smuzhiyun 
871*4882a593Smuzhiyun     /*
872*4882a593Smuzhiyun      ** Lookup new context.  It must not be current for someone else.
873*4882a593Smuzhiyun      */
874*4882a593Smuzhiyun     if (contextId != None) {
875*4882a593Smuzhiyun         dixLookupResourceByType((void **) &glxc, contextId, __glXContextRes,
876*4882a593Smuzhiyun                                 NullClient, DixUnknownAccess);
877*4882a593Smuzhiyun         if (!glxc) {
878*4882a593Smuzhiyun             client->errorValue = contextId;
879*4882a593Smuzhiyun             return __glXBadContext;
880*4882a593Smuzhiyun         }
881*4882a593Smuzhiyun         if ((glxc != prevglxc) && glxc->isCurrent) {
882*4882a593Smuzhiyun             /* Context is current to somebody else */
883*4882a593Smuzhiyun             return BadAccess;
884*4882a593Smuzhiyun         }
885*4882a593Smuzhiyun     }
886*4882a593Smuzhiyun     else {
887*4882a593Smuzhiyun         /* Switching to no context.  Ignore new drawable. */
888*4882a593Smuzhiyun         glxc = 0;
889*4882a593Smuzhiyun     }
890*4882a593Smuzhiyun 
891*4882a593Smuzhiyun     if (drawId != None) {
892*4882a593Smuzhiyun         rc = dixLookupDrawable(&pDraw, drawId, client, 0, DixWriteAccess);
893*4882a593Smuzhiyun         if (rc == Success) {
894*4882a593Smuzhiyun             if (pDraw->type == DRAWABLE_WINDOW) {
895*4882a593Smuzhiyun                 /*
896*4882a593Smuzhiyun                  ** Drawable is an X Window.
897*4882a593Smuzhiyun                  */
898*4882a593Smuzhiyun                 VisualID vid;
899*4882a593Smuzhiyun 
900*4882a593Smuzhiyun                 pWin = (WindowPtr) pDraw;
901*4882a593Smuzhiyun                 vid = wVisual(pWin);
902*4882a593Smuzhiyun 
903*4882a593Smuzhiyun                 new_reply.writeVid =
904*4882a593Smuzhiyun                     (glxc->pFBConfig ? glxc->pFBConfig->id : vid);
905*4882a593Smuzhiyun                 new_reply.writeType = GLX_WINDOW_TYPE;
906*4882a593Smuzhiyun 
907*4882a593Smuzhiyun                 /*
908*4882a593Smuzhiyun                  ** Check if window and context are similar.
909*4882a593Smuzhiyun                  */
910*4882a593Smuzhiyun                 if ((vid != glxc->pVisual->vid) ||
911*4882a593Smuzhiyun                     (pWin->drawable.pScreen != glxc->pScreen)) {
912*4882a593Smuzhiyun                     client->errorValue = drawId;
913*4882a593Smuzhiyun                     return BadMatch;
914*4882a593Smuzhiyun                 }
915*4882a593Smuzhiyun 
916*4882a593Smuzhiyun                 from_screen = to_screen = pWin->drawable.pScreen->myNum;
917*4882a593Smuzhiyun 
918*4882a593Smuzhiyun             }
919*4882a593Smuzhiyun             else {
920*4882a593Smuzhiyun                 /*
921*4882a593Smuzhiyun                  ** An X Pixmap is not allowed as a parameter (a GLX Pixmap
922*4882a593Smuzhiyun                  ** is, but it must first be created with glxCreateGLXPixmap).
923*4882a593Smuzhiyun                  */
924*4882a593Smuzhiyun                 client->errorValue = drawId;
925*4882a593Smuzhiyun                 return __glXBadDrawable;
926*4882a593Smuzhiyun             }
927*4882a593Smuzhiyun         }
928*4882a593Smuzhiyun 
929*4882a593Smuzhiyun         if (!pDraw) {
930*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxPixmap, drawId,
931*4882a593Smuzhiyun                                     __glXPixmapRes, NullClient,
932*4882a593Smuzhiyun                                     DixUnknownAccess);
933*4882a593Smuzhiyun             if (pGlxPixmap) {
934*4882a593Smuzhiyun                 /*
935*4882a593Smuzhiyun                  ** Check if pixmap and context are similar.
936*4882a593Smuzhiyun                  */
937*4882a593Smuzhiyun                 if (pGlxPixmap->pScreen != glxc->pScreen ||
938*4882a593Smuzhiyun                     pGlxPixmap->pGlxVisual != glxc->pGlxVisual) {
939*4882a593Smuzhiyun                     client->errorValue = drawId;
940*4882a593Smuzhiyun                     return BadMatch;
941*4882a593Smuzhiyun                 }
942*4882a593Smuzhiyun                 pDraw = pGlxPixmap->pDraw;
943*4882a593Smuzhiyun 
944*4882a593Smuzhiyun                 new_reply.writeVid = (glxc->pFBConfig ? glxc->pFBConfig->id :
945*4882a593Smuzhiyun                                       pGlxPixmap->pGlxVisual->vid);
946*4882a593Smuzhiyun 
947*4882a593Smuzhiyun                 new_reply.writeType = GLX_PIXMAP_TYPE;
948*4882a593Smuzhiyun 
949*4882a593Smuzhiyun                 from_screen = to_screen = pGlxPixmap->pScreen->myNum;
950*4882a593Smuzhiyun 
951*4882a593Smuzhiyun             }
952*4882a593Smuzhiyun         }
953*4882a593Smuzhiyun 
954*4882a593Smuzhiyun         if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1, 3)) {
955*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxWindow, drawId,
956*4882a593Smuzhiyun                                     __glXWindowRes, NullClient,
957*4882a593Smuzhiyun                                     DixUnknownAccess);
958*4882a593Smuzhiyun             if (pGlxWindow) {
959*4882a593Smuzhiyun                 /*
960*4882a593Smuzhiyun                  ** Drawable is a GLXWindow.
961*4882a593Smuzhiyun                  **
962*4882a593Smuzhiyun                  ** Check if GLX window and context are similar.
963*4882a593Smuzhiyun                  */
964*4882a593Smuzhiyun                 if (pGlxWindow->pScreen != glxc->pScreen ||
965*4882a593Smuzhiyun                     pGlxWindow->pGlxFBConfig != glxc->pFBConfig) {
966*4882a593Smuzhiyun                     client->errorValue = drawId;
967*4882a593Smuzhiyun                     return BadMatch;
968*4882a593Smuzhiyun                 }
969*4882a593Smuzhiyun 
970*4882a593Smuzhiyun                 pDraw = pGlxWindow->pDraw;
971*4882a593Smuzhiyun                 new_reply.writeVid = pGlxWindow->pGlxFBConfig->id;
972*4882a593Smuzhiyun                 new_reply.writeType = GLX_GLXWINDOW_TYPE;
973*4882a593Smuzhiyun             }
974*4882a593Smuzhiyun 
975*4882a593Smuzhiyun         }
976*4882a593Smuzhiyun 
977*4882a593Smuzhiyun         if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1, 3)) {
978*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxPbuffer, drawId,
979*4882a593Smuzhiyun                                     __glXPbufferRes, NullClient,
980*4882a593Smuzhiyun                                     DixUnknownAccess);
981*4882a593Smuzhiyun             if (pGlxPbuffer) {
982*4882a593Smuzhiyun                 if (pGlxPbuffer->pScreen != glxc->pScreen ||
983*4882a593Smuzhiyun                     pGlxPbuffer->pFBConfig != glxc->pFBConfig) {
984*4882a593Smuzhiyun                     client->errorValue = drawId;
985*4882a593Smuzhiyun                     return BadMatch;
986*4882a593Smuzhiyun                 }
987*4882a593Smuzhiyun 
988*4882a593Smuzhiyun                 pDraw = (DrawablePtr) pGlxPbuffer;
989*4882a593Smuzhiyun                 new_reply.writeVid = pGlxPbuffer->pFBConfig->id;
990*4882a593Smuzhiyun                 new_reply.writeType = GLX_PBUFFER_TYPE;
991*4882a593Smuzhiyun             }
992*4882a593Smuzhiyun         }
993*4882a593Smuzhiyun 
994*4882a593Smuzhiyun         if (!pDraw) {
995*4882a593Smuzhiyun             /*
996*4882a593Smuzhiyun              ** Drawable is not a Window , GLXWindow or a GLXPixmap.
997*4882a593Smuzhiyun              */
998*4882a593Smuzhiyun             client->errorValue = drawId;
999*4882a593Smuzhiyun             return __glXBadDrawable;
1000*4882a593Smuzhiyun         }
1001*4882a593Smuzhiyun 
1002*4882a593Smuzhiyun     }
1003*4882a593Smuzhiyun     else {
1004*4882a593Smuzhiyun         pDraw = 0;
1005*4882a593Smuzhiyun     }
1006*4882a593Smuzhiyun 
1007*4882a593Smuzhiyun     if (readId != None && readId != drawId) {
1008*4882a593Smuzhiyun         rc = dixLookupDrawable(&pReadDraw, readId, client, 0, DixReadAccess);
1009*4882a593Smuzhiyun         if (rc == Success) {
1010*4882a593Smuzhiyun             if (pReadDraw->type == DRAWABLE_WINDOW) {
1011*4882a593Smuzhiyun                 /*
1012*4882a593Smuzhiyun                  ** Drawable is an X Window.
1013*4882a593Smuzhiyun                  */
1014*4882a593Smuzhiyun                 VisualID vid;
1015*4882a593Smuzhiyun 
1016*4882a593Smuzhiyun                 pReadWin = (WindowPtr) pDraw;
1017*4882a593Smuzhiyun                 vid = wVisual(pReadWin);
1018*4882a593Smuzhiyun 
1019*4882a593Smuzhiyun                 new_reply.readVid =
1020*4882a593Smuzhiyun                     (glxc->pFBConfig ? glxc->pFBConfig->id : vid);
1021*4882a593Smuzhiyun                 new_reply.readType = GLX_WINDOW_TYPE;
1022*4882a593Smuzhiyun 
1023*4882a593Smuzhiyun                 /*
1024*4882a593Smuzhiyun                  ** Check if window and context are similar.
1025*4882a593Smuzhiyun                  */
1026*4882a593Smuzhiyun                 if ((vid != glxc->pVisual->vid) ||
1027*4882a593Smuzhiyun                     (pReadWin->drawable.pScreen != glxc->pScreen)) {
1028*4882a593Smuzhiyun                     client->errorValue = readId;
1029*4882a593Smuzhiyun                     return BadMatch;
1030*4882a593Smuzhiyun                 }
1031*4882a593Smuzhiyun 
1032*4882a593Smuzhiyun             }
1033*4882a593Smuzhiyun             else {
1034*4882a593Smuzhiyun 
1035*4882a593Smuzhiyun                 /*
1036*4882a593Smuzhiyun                  ** An X Pixmap is not allowed as a parameter (a GLX Pixmap
1037*4882a593Smuzhiyun                  ** is, but it must first be created with glxCreateGLXPixmap).
1038*4882a593Smuzhiyun                  */
1039*4882a593Smuzhiyun                 client->errorValue = readId;
1040*4882a593Smuzhiyun                 return __glXBadDrawable;
1041*4882a593Smuzhiyun             }
1042*4882a593Smuzhiyun         }
1043*4882a593Smuzhiyun 
1044*4882a593Smuzhiyun         if (!pReadDraw) {
1045*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pReadGlxPixmap, readId,
1046*4882a593Smuzhiyun                                     __glXPixmapRes, NullClient,
1047*4882a593Smuzhiyun                                     DixUnknownAccess);
1048*4882a593Smuzhiyun             if (pReadGlxPixmap) {
1049*4882a593Smuzhiyun                 /*
1050*4882a593Smuzhiyun                  ** Check if pixmap and context are similar.
1051*4882a593Smuzhiyun                  */
1052*4882a593Smuzhiyun                 if (pReadGlxPixmap->pScreen != glxc->pScreen ||
1053*4882a593Smuzhiyun                     pReadGlxPixmap->pGlxVisual != glxc->pGlxVisual) {
1054*4882a593Smuzhiyun                     client->errorValue = readId;
1055*4882a593Smuzhiyun                     return BadMatch;
1056*4882a593Smuzhiyun                 }
1057*4882a593Smuzhiyun                 pReadDraw = pReadGlxPixmap->pDraw;
1058*4882a593Smuzhiyun 
1059*4882a593Smuzhiyun                 new_reply.readVid = (glxc->pFBConfig ? glxc->pFBConfig->id :
1060*4882a593Smuzhiyun                                      pReadGlxPixmap->pGlxVisual->vid);
1061*4882a593Smuzhiyun                 new_reply.readType = GLX_PIXMAP_TYPE;
1062*4882a593Smuzhiyun 
1063*4882a593Smuzhiyun             }
1064*4882a593Smuzhiyun         }
1065*4882a593Smuzhiyun 
1066*4882a593Smuzhiyun         if (!pReadDraw && __GLX_IS_VERSION_SUPPORTED(1, 3)) {
1067*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxReadWindow, readId,
1068*4882a593Smuzhiyun                                     __glXWindowRes, NullClient,
1069*4882a593Smuzhiyun                                     DixUnknownAccess);
1070*4882a593Smuzhiyun             if (pGlxReadWindow) {
1071*4882a593Smuzhiyun                 /*
1072*4882a593Smuzhiyun                  ** Drawable is a GLXWindow.
1073*4882a593Smuzhiyun                  **
1074*4882a593Smuzhiyun                  ** Check if GLX window and context are similar.
1075*4882a593Smuzhiyun                  */
1076*4882a593Smuzhiyun                 if (pGlxReadWindow->pScreen != glxc->pScreen ||
1077*4882a593Smuzhiyun                     pGlxReadWindow->pGlxFBConfig != glxc->pFBConfig) {
1078*4882a593Smuzhiyun                     client->errorValue = readId;
1079*4882a593Smuzhiyun                     return BadMatch;
1080*4882a593Smuzhiyun                 }
1081*4882a593Smuzhiyun 
1082*4882a593Smuzhiyun                 pReadDraw = pGlxReadWindow->pDraw;
1083*4882a593Smuzhiyun                 new_reply.readVid = pGlxReadWindow->pGlxFBConfig->id;
1084*4882a593Smuzhiyun                 new_reply.readType = GLX_GLXWINDOW_TYPE;
1085*4882a593Smuzhiyun             }
1086*4882a593Smuzhiyun         }
1087*4882a593Smuzhiyun 
1088*4882a593Smuzhiyun         if (!pReadDraw && __GLX_IS_VERSION_SUPPORTED(1, 3)) {
1089*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxReadPbuffer, readId,
1090*4882a593Smuzhiyun                                     __glXPbufferRes, NullClient,
1091*4882a593Smuzhiyun                                     DixUnknownAccess);
1092*4882a593Smuzhiyun             if (pGlxReadPbuffer) {
1093*4882a593Smuzhiyun                 if (pGlxReadPbuffer->pScreen != glxc->pScreen ||
1094*4882a593Smuzhiyun                     pGlxReadPbuffer->pFBConfig != glxc->pFBConfig) {
1095*4882a593Smuzhiyun                     client->errorValue = drawId;
1096*4882a593Smuzhiyun                     return BadMatch;
1097*4882a593Smuzhiyun                 }
1098*4882a593Smuzhiyun 
1099*4882a593Smuzhiyun                 pReadDraw = (DrawablePtr) pGlxReadPbuffer;
1100*4882a593Smuzhiyun                 new_reply.readVid = pGlxReadPbuffer->pFBConfig->id;
1101*4882a593Smuzhiyun                 new_reply.readType = GLX_PBUFFER_TYPE;
1102*4882a593Smuzhiyun             }
1103*4882a593Smuzhiyun         }
1104*4882a593Smuzhiyun 
1105*4882a593Smuzhiyun         if (!pReadDraw) {
1106*4882a593Smuzhiyun             /*
1107*4882a593Smuzhiyun              ** Drawable is neither a Window nor a GLXPixmap.
1108*4882a593Smuzhiyun              */
1109*4882a593Smuzhiyun             client->errorValue = readId;
1110*4882a593Smuzhiyun             return __glXBadDrawable;
1111*4882a593Smuzhiyun         }
1112*4882a593Smuzhiyun 
1113*4882a593Smuzhiyun     }
1114*4882a593Smuzhiyun     else {
1115*4882a593Smuzhiyun         pReadDraw = pDraw;
1116*4882a593Smuzhiyun         pReadGlxPixmap = pGlxPixmap;
1117*4882a593Smuzhiyun         pReadWin = pWin;
1118*4882a593Smuzhiyun         new_reply.readVid = new_reply.writeVid;
1119*4882a593Smuzhiyun         new_reply.readType = new_reply.writeType;
1120*4882a593Smuzhiyun     }
1121*4882a593Smuzhiyun 
1122*4882a593Smuzhiyun     if (prevglxc) {
1123*4882a593Smuzhiyun 
1124*4882a593Smuzhiyun         if (prevglxc->pGlxPixmap) {
1125*4882a593Smuzhiyun             /*
1126*4882a593Smuzhiyun              ** The previous drawable was a glx pixmap, release it.
1127*4882a593Smuzhiyun              */
1128*4882a593Smuzhiyun             prevglxc->pGlxPixmap->refcnt--;
1129*4882a593Smuzhiyun             __glXFreeGLXPixmap(prevglxc->pGlxPixmap);
1130*4882a593Smuzhiyun             prevglxc->pGlxPixmap = 0;
1131*4882a593Smuzhiyun         }
1132*4882a593Smuzhiyun 
1133*4882a593Smuzhiyun         if (prevglxc->pGlxReadPixmap) {
1134*4882a593Smuzhiyun             /*
1135*4882a593Smuzhiyun              ** The previous drawable was a glx pixmap, release it.
1136*4882a593Smuzhiyun              */
1137*4882a593Smuzhiyun             prevglxc->pGlxReadPixmap->refcnt--;
1138*4882a593Smuzhiyun             __glXFreeGLXPixmap(prevglxc->pGlxReadPixmap);
1139*4882a593Smuzhiyun             prevglxc->pGlxReadPixmap = 0;
1140*4882a593Smuzhiyun         }
1141*4882a593Smuzhiyun 
1142*4882a593Smuzhiyun         if (prevglxc->pGlxWindow) {
1143*4882a593Smuzhiyun             /*
1144*4882a593Smuzhiyun              ** The previous drawable was a glx window, release it.
1145*4882a593Smuzhiyun              */
1146*4882a593Smuzhiyun             prevglxc->pGlxWindow->refcnt--;
1147*4882a593Smuzhiyun             __glXFreeGLXWindow(prevglxc->pGlxWindow);
1148*4882a593Smuzhiyun             prevglxc->pGlxWindow = 0;
1149*4882a593Smuzhiyun         }
1150*4882a593Smuzhiyun 
1151*4882a593Smuzhiyun         if (prevglxc->pGlxReadWindow) {
1152*4882a593Smuzhiyun             /*
1153*4882a593Smuzhiyun              ** The previous drawable was a glx window, release it.
1154*4882a593Smuzhiyun              */
1155*4882a593Smuzhiyun             prevglxc->pGlxReadWindow->refcnt--;
1156*4882a593Smuzhiyun             __glXFreeGLXWindow(prevglxc->pGlxReadWindow);
1157*4882a593Smuzhiyun             prevglxc->pGlxReadWindow = 0;
1158*4882a593Smuzhiyun         }
1159*4882a593Smuzhiyun 
1160*4882a593Smuzhiyun         if (prevglxc->pGlxPbuffer) {
1161*4882a593Smuzhiyun             /*
1162*4882a593Smuzhiyun              ** The previous drawable was a glx Pbuffer, release it.
1163*4882a593Smuzhiyun              */
1164*4882a593Smuzhiyun             prevglxc->pGlxPbuffer->refcnt--;
1165*4882a593Smuzhiyun             __glXFreeGLXPbuffer(prevglxc->pGlxPbuffer);
1166*4882a593Smuzhiyun             prevglxc->pGlxPbuffer = 0;
1167*4882a593Smuzhiyun         }
1168*4882a593Smuzhiyun 
1169*4882a593Smuzhiyun         if (prevglxc->pGlxReadPbuffer) {
1170*4882a593Smuzhiyun             /*
1171*4882a593Smuzhiyun              ** The previous drawable was a glx Pbuffer, release it.
1172*4882a593Smuzhiyun              */
1173*4882a593Smuzhiyun             prevglxc->pGlxReadPbuffer->refcnt--;
1174*4882a593Smuzhiyun             __glXFreeGLXPbuffer(prevglxc->pGlxReadPbuffer);
1175*4882a593Smuzhiyun             prevglxc->pGlxReadPbuffer = 0;
1176*4882a593Smuzhiyun         }
1177*4882a593Smuzhiyun 
1178*4882a593Smuzhiyun         ChangeCurrentContext(cl, glxc, tag);
1179*4882a593Smuzhiyun         ChangeCurrentContext(cl, glxc, tag);
1180*4882a593Smuzhiyun         StopUsingContext(prevglxc);
1181*4882a593Smuzhiyun     }
1182*4882a593Smuzhiyun     else {
1183*4882a593Smuzhiyun         tag = AddCurrentContext(cl, glxc, pDraw);
1184*4882a593Smuzhiyun     }
1185*4882a593Smuzhiyun     if (glxc) {
1186*4882a593Smuzhiyun 
1187*4882a593Smuzhiyun         glxc->pGlxPixmap = pGlxPixmap;
1188*4882a593Smuzhiyun         glxc->pGlxReadPixmap = pReadGlxPixmap;
1189*4882a593Smuzhiyun         glxc->pGlxWindow = pGlxWindow;
1190*4882a593Smuzhiyun         glxc->pGlxReadWindow = pGlxReadWindow;
1191*4882a593Smuzhiyun         glxc->pGlxPbuffer = pGlxPbuffer;
1192*4882a593Smuzhiyun         glxc->pGlxReadPbuffer = pGlxReadPbuffer;
1193*4882a593Smuzhiyun 
1194*4882a593Smuzhiyun         if (pGlxPixmap) {
1195*4882a593Smuzhiyun             pGlxPixmap->refcnt++;
1196*4882a593Smuzhiyun         }
1197*4882a593Smuzhiyun 
1198*4882a593Smuzhiyun         if (pReadGlxPixmap) {
1199*4882a593Smuzhiyun             pReadGlxPixmap->refcnt++;
1200*4882a593Smuzhiyun         }
1201*4882a593Smuzhiyun 
1202*4882a593Smuzhiyun         if (pGlxWindow) {
1203*4882a593Smuzhiyun             pGlxWindow->refcnt++;
1204*4882a593Smuzhiyun         }
1205*4882a593Smuzhiyun 
1206*4882a593Smuzhiyun         if (pGlxReadWindow) {
1207*4882a593Smuzhiyun             pGlxReadWindow->refcnt++;
1208*4882a593Smuzhiyun         }
1209*4882a593Smuzhiyun 
1210*4882a593Smuzhiyun         if (pGlxPbuffer) {
1211*4882a593Smuzhiyun             pGlxPbuffer->refcnt++;
1212*4882a593Smuzhiyun         }
1213*4882a593Smuzhiyun 
1214*4882a593Smuzhiyun         if (pGlxReadPbuffer) {
1215*4882a593Smuzhiyun             pGlxReadPbuffer->refcnt++;
1216*4882a593Smuzhiyun         }
1217*4882a593Smuzhiyun 
1218*4882a593Smuzhiyun         StartUsingContext(cl, glxc);
1219*4882a593Smuzhiyun         new_reply.contextTag = tag;
1220*4882a593Smuzhiyun     }
1221*4882a593Smuzhiyun     else {
1222*4882a593Smuzhiyun         new_reply.contextTag = 0;
1223*4882a593Smuzhiyun     }
1224*4882a593Smuzhiyun 
1225*4882a593Smuzhiyun #ifdef PANORAMIX
1226*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
1227*4882a593Smuzhiyun         from_screen = 0;
1228*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
1229*4882a593Smuzhiyun 
1230*4882a593Smuzhiyun         if (pDraw && new_reply.writeType != GLX_PBUFFER_TYPE) {
1231*4882a593Smuzhiyun             dixLookupResourceByClass((void **) &pXinDraw,
1232*4882a593Smuzhiyun                                      pDraw->id, XRC_DRAWABLE,
1233*4882a593Smuzhiyun                                      client, DixReadAccess);
1234*4882a593Smuzhiyun         }
1235*4882a593Smuzhiyun 
1236*4882a593Smuzhiyun         if (pReadDraw && pReadDraw != pDraw &&
1237*4882a593Smuzhiyun             new_reply.readType != GLX_PBUFFER_TYPE) {
1238*4882a593Smuzhiyun             dixLookupResourceByClass((void **) &pXinReadDraw,
1239*4882a593Smuzhiyun                                      pReadDraw->id, XRC_DRAWABLE,
1240*4882a593Smuzhiyun                                      client, DixReadAccess);
1241*4882a593Smuzhiyun         }
1242*4882a593Smuzhiyun         else {
1243*4882a593Smuzhiyun             pXinReadDraw = pXinDraw;
1244*4882a593Smuzhiyun         }
1245*4882a593Smuzhiyun     }
1246*4882a593Smuzhiyun #endif
1247*4882a593Smuzhiyun 
1248*4882a593Smuzhiyun     /* send the MakeCurrent request to all required
1249*4882a593Smuzhiyun      * back-end servers.
1250*4882a593Smuzhiyun      */
1251*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
1252*4882a593Smuzhiyun         DMXScreenInfo *dmxScreen = &dmxScreens[s];
1253*4882a593Smuzhiyun         Display *dpy = GetBackEndDisplay(cl, s);
1254*4882a593Smuzhiyun         unsigned int be_draw = None;
1255*4882a593Smuzhiyun         unsigned int be_read_draw = None;
1256*4882a593Smuzhiyun 
1257*4882a593Smuzhiyun         if (pGlxPixmap) {
1258*4882a593Smuzhiyun             be_draw = pGlxPixmap->be_xids[s];
1259*4882a593Smuzhiyun         }
1260*4882a593Smuzhiyun         else if (pGlxPbuffer) {
1261*4882a593Smuzhiyun             be_draw = pGlxPbuffer->be_xids[s];
1262*4882a593Smuzhiyun         }
1263*4882a593Smuzhiyun #ifdef PANORAMIX
1264*4882a593Smuzhiyun         else if (pXinDraw) {
1265*4882a593Smuzhiyun             dixLookupWindow(&pWin, pXinDraw->info[s].id, client, DixReadAccess);
1266*4882a593Smuzhiyun         }
1267*4882a593Smuzhiyun #endif
1268*4882a593Smuzhiyun         else if (pGlxWindow) {
1269*4882a593Smuzhiyun             pWin = (WindowPtr) pGlxWindow->pDraw;
1270*4882a593Smuzhiyun         }
1271*4882a593Smuzhiyun 
1272*4882a593Smuzhiyun         if (pWin && be_draw == None) {
1273*4882a593Smuzhiyun             be_draw = (unsigned int) (DMX_GET_WINDOW_PRIV(pWin))->window;
1274*4882a593Smuzhiyun             if (!be_draw) {
1275*4882a593Smuzhiyun                 /* it might be that the window did not created yet on the */
1276*4882a593Smuzhiyun                 /* back-end server (lazy window creation option), force   */
1277*4882a593Smuzhiyun                 /* creation of the window */
1278*4882a593Smuzhiyun                 dmxCreateAndRealizeWindow(pWin, TRUE);
1279*4882a593Smuzhiyun                 be_draw = (unsigned int) (DMX_GET_WINDOW_PRIV(pWin))->window;
1280*4882a593Smuzhiyun             }
1281*4882a593Smuzhiyun         }
1282*4882a593Smuzhiyun 
1283*4882a593Smuzhiyun         /*
1284*4882a593Smuzhiyun          * Before sending the MakeCurrent request - sync the
1285*4882a593Smuzhiyun          * X11 connection to the back-end servers to make sure
1286*4882a593Smuzhiyun          * that drawable is already created
1287*4882a593Smuzhiyun          */
1288*4882a593Smuzhiyun         dmxSync(dmxScreen, 1);
1289*4882a593Smuzhiyun 
1290*4882a593Smuzhiyun         if (drawId == readId) {
1291*4882a593Smuzhiyun             LockDisplay(dpy);
1292*4882a593Smuzhiyun             GetReq(GLXMakeCurrent, be_req);
1293*4882a593Smuzhiyun             be_req->reqType = dmxScreen->glxMajorOpcode;
1294*4882a593Smuzhiyun             be_req->glxCode = X_GLXMakeCurrent;
1295*4882a593Smuzhiyun             be_req->drawable = be_draw;
1296*4882a593Smuzhiyun             be_req->context =
1297*4882a593Smuzhiyun                 (unsigned int) (glxc ? glxc->real_ids[s - from_screen] : 0);
1298*4882a593Smuzhiyun             be_req->oldContextTag = GetCurrentBackEndTag(cl, tag, s);
1299*4882a593Smuzhiyun             if (!_XReply(dpy, (xReply *) &be_reply, 0, False)) {
1300*4882a593Smuzhiyun 
1301*4882a593Smuzhiyun                 /* The make current failed */
1302*4882a593Smuzhiyun                 UnlockDisplay(dpy);
1303*4882a593Smuzhiyun                 SyncHandle();
1304*4882a593Smuzhiyun                 return (BE_TO_CLIENT_ERROR(dmxLastErrorEvent.error_code));
1305*4882a593Smuzhiyun             }
1306*4882a593Smuzhiyun 
1307*4882a593Smuzhiyun             UnlockDisplay(dpy);
1308*4882a593Smuzhiyun             SyncHandle();
1309*4882a593Smuzhiyun 
1310*4882a593Smuzhiyun             SetCurrentBackEndTag(cl, tag, s, be_reply.contextTag);
1311*4882a593Smuzhiyun         }
1312*4882a593Smuzhiyun         else {
1313*4882a593Smuzhiyun 
1314*4882a593Smuzhiyun             if (pReadGlxPixmap) {
1315*4882a593Smuzhiyun                 be_read_draw = pReadGlxPixmap->be_xids[s];
1316*4882a593Smuzhiyun             }
1317*4882a593Smuzhiyun             else if (pGlxReadPbuffer) {
1318*4882a593Smuzhiyun                 be_read_draw = pGlxReadPbuffer->be_xids[s];
1319*4882a593Smuzhiyun             }
1320*4882a593Smuzhiyun #ifdef PANORAMIX
1321*4882a593Smuzhiyun             else if (pXinReadDraw) {
1322*4882a593Smuzhiyun                 dixLookupWindow(&pReadWin, pXinReadDraw->info[s].id, client,
1323*4882a593Smuzhiyun                                 DixReadAccess);
1324*4882a593Smuzhiyun             }
1325*4882a593Smuzhiyun #endif
1326*4882a593Smuzhiyun             else if (pGlxReadWindow) {
1327*4882a593Smuzhiyun                 pReadWin = (WindowPtr) pGlxReadWindow->pDraw;
1328*4882a593Smuzhiyun             }
1329*4882a593Smuzhiyun 
1330*4882a593Smuzhiyun             if (pReadWin && be_read_draw == None) {
1331*4882a593Smuzhiyun                 be_read_draw =
1332*4882a593Smuzhiyun                     (unsigned int) (DMX_GET_WINDOW_PRIV(pReadWin))->window;
1333*4882a593Smuzhiyun                 if (!be_read_draw) {
1334*4882a593Smuzhiyun                     /* it might be that the window did not created yet on the */
1335*4882a593Smuzhiyun                     /* back-end server (lazy window creation option), force   */
1336*4882a593Smuzhiyun                     /* creation of the window */
1337*4882a593Smuzhiyun                     dmxCreateAndRealizeWindow(pReadWin, TRUE);
1338*4882a593Smuzhiyun                     be_read_draw =
1339*4882a593Smuzhiyun                         (unsigned int) (DMX_GET_WINDOW_PRIV(pReadWin))->window;
1340*4882a593Smuzhiyun                     dmxSync(dmxScreen, 1);
1341*4882a593Smuzhiyun                 }
1342*4882a593Smuzhiyun             }
1343*4882a593Smuzhiyun 
1344*4882a593Smuzhiyun             if (__GLX_IS_VERSION_SUPPORTED(1, 3)) {
1345*4882a593Smuzhiyun                 LockDisplay(dpy);
1346*4882a593Smuzhiyun                 GetReq(GLXMakeContextCurrent, be_new_req);
1347*4882a593Smuzhiyun                 be_new_req->reqType = dmxScreen->glxMajorOpcode;
1348*4882a593Smuzhiyun                 be_new_req->glxCode = X_GLXMakeContextCurrent;
1349*4882a593Smuzhiyun                 be_new_req->drawable = be_draw;
1350*4882a593Smuzhiyun                 be_new_req->readdrawable = be_read_draw;
1351*4882a593Smuzhiyun                 be_new_req->context =
1352*4882a593Smuzhiyun                     (unsigned int) (glxc ? glxc->real_ids[s - from_screen] : 0);
1353*4882a593Smuzhiyun                 be_new_req->oldContextTag = GetCurrentBackEndTag(cl, tag, s);
1354*4882a593Smuzhiyun                 if (!_XReply(dpy, (xReply *) &be_new_reply, 0, False)) {
1355*4882a593Smuzhiyun 
1356*4882a593Smuzhiyun                     /* The make current failed */
1357*4882a593Smuzhiyun                     UnlockDisplay(dpy);
1358*4882a593Smuzhiyun                     SyncHandle();
1359*4882a593Smuzhiyun                     return (BE_TO_CLIENT_ERROR(dmxLastErrorEvent.error_code));
1360*4882a593Smuzhiyun                 }
1361*4882a593Smuzhiyun 
1362*4882a593Smuzhiyun                 UnlockDisplay(dpy);
1363*4882a593Smuzhiyun                 SyncHandle();
1364*4882a593Smuzhiyun 
1365*4882a593Smuzhiyun                 SetCurrentBackEndTag(cl, tag, s, be_new_reply.contextTag);
1366*4882a593Smuzhiyun             }
1367*4882a593Smuzhiyun             else if (glxIsExtensionSupported("GLX_SGI_make_current_read")) {
1368*4882a593Smuzhiyun                 xGLXMakeCurrentReadSGIReq *ext_req;
1369*4882a593Smuzhiyun                 xGLXVendorPrivateWithReplyReq *vpreq;
1370*4882a593Smuzhiyun                 xGLXMakeCurrentReadSGIReply ext_reply;
1371*4882a593Smuzhiyun 
1372*4882a593Smuzhiyun                 LockDisplay(dpy);
1373*4882a593Smuzhiyun                 GetReqExtra(GLXVendorPrivateWithReply,
1374*4882a593Smuzhiyun                             sz_xGLXMakeCurrentReadSGIReq -
1375*4882a593Smuzhiyun                             sz_xGLXVendorPrivateWithReplyReq, vpreq);
1376*4882a593Smuzhiyun                 ext_req = (xGLXMakeCurrentReadSGIReq *) vpreq;
1377*4882a593Smuzhiyun                 ext_req->reqType = dmxScreen->glxMajorOpcode;
1378*4882a593Smuzhiyun                 ext_req->glxCode = X_GLXVendorPrivateWithReply;
1379*4882a593Smuzhiyun                 ext_req->vendorCode = X_GLXvop_MakeCurrentReadSGI;
1380*4882a593Smuzhiyun                 ext_req->drawable = be_draw;
1381*4882a593Smuzhiyun                 ext_req->readable = be_read_draw;
1382*4882a593Smuzhiyun                 ext_req->context =
1383*4882a593Smuzhiyun                     (unsigned int) (glxc ? glxc->real_ids[s - from_screen] : 0);
1384*4882a593Smuzhiyun                 ext_req->oldContextTag = GetCurrentBackEndTag(cl, tag, s);
1385*4882a593Smuzhiyun                 if (!_XReply(dpy, (xReply *) &ext_reply, 0, False)) {
1386*4882a593Smuzhiyun 
1387*4882a593Smuzhiyun                     /* The make current failed */
1388*4882a593Smuzhiyun                     UnlockDisplay(dpy);
1389*4882a593Smuzhiyun                     SyncHandle();
1390*4882a593Smuzhiyun                     return (BE_TO_CLIENT_ERROR(dmxLastErrorEvent.error_code));
1391*4882a593Smuzhiyun                 }
1392*4882a593Smuzhiyun 
1393*4882a593Smuzhiyun                 UnlockDisplay(dpy);
1394*4882a593Smuzhiyun                 SyncHandle();
1395*4882a593Smuzhiyun 
1396*4882a593Smuzhiyun                 SetCurrentBackEndTag(cl, tag, s, ext_reply.contextTag);
1397*4882a593Smuzhiyun 
1398*4882a593Smuzhiyun             }
1399*4882a593Smuzhiyun             else {
1400*4882a593Smuzhiyun                 return BadMatch;
1401*4882a593Smuzhiyun             }
1402*4882a593Smuzhiyun         }
1403*4882a593Smuzhiyun 
1404*4882a593Smuzhiyun         XFlush(dpy);
1405*4882a593Smuzhiyun     }
1406*4882a593Smuzhiyun 
1407*4882a593Smuzhiyun     if (client->swapped) {
1408*4882a593Smuzhiyun         __glXSwapMakeCurrentReply(client, &new_reply);
1409*4882a593Smuzhiyun     }
1410*4882a593Smuzhiyun     else {
1411*4882a593Smuzhiyun         WriteToClient(client, sz_xGLXMakeContextCurrentReply, &new_reply);
1412*4882a593Smuzhiyun     }
1413*4882a593Smuzhiyun 
1414*4882a593Smuzhiyun     return Success;
1415*4882a593Smuzhiyun }
1416*4882a593Smuzhiyun 
1417*4882a593Smuzhiyun int
__glXMakeCurrent(__GLXclientState * cl,GLbyte * pc)1418*4882a593Smuzhiyun __glXMakeCurrent(__GLXclientState * cl, GLbyte * pc)
1419*4882a593Smuzhiyun {
1420*4882a593Smuzhiyun     xGLXMakeCurrentReq *req = (xGLXMakeCurrentReq *) pc;
1421*4882a593Smuzhiyun 
1422*4882a593Smuzhiyun     return (MakeCurrent(cl, req->drawable, req->drawable,
1423*4882a593Smuzhiyun                         req->context, req->oldContextTag));
1424*4882a593Smuzhiyun }
1425*4882a593Smuzhiyun 
1426*4882a593Smuzhiyun int
__glXMakeContextCurrent(__GLXclientState * cl,GLbyte * pc)1427*4882a593Smuzhiyun __glXMakeContextCurrent(__GLXclientState * cl, GLbyte * pc)
1428*4882a593Smuzhiyun {
1429*4882a593Smuzhiyun     xGLXMakeContextCurrentReq *req = (xGLXMakeContextCurrentReq *) pc;
1430*4882a593Smuzhiyun 
1431*4882a593Smuzhiyun     return (MakeCurrent(cl, req->drawable, req->readdrawable,
1432*4882a593Smuzhiyun                         req->context, req->oldContextTag));
1433*4882a593Smuzhiyun }
1434*4882a593Smuzhiyun 
1435*4882a593Smuzhiyun int
__glXMakeCurrentReadSGI(__GLXclientState * cl,GLbyte * pc)1436*4882a593Smuzhiyun __glXMakeCurrentReadSGI(__GLXclientState * cl, GLbyte * pc)
1437*4882a593Smuzhiyun {
1438*4882a593Smuzhiyun     xGLXMakeCurrentReadSGIReq *req = (xGLXMakeCurrentReadSGIReq *) pc;
1439*4882a593Smuzhiyun 
1440*4882a593Smuzhiyun     return (MakeCurrent(cl, req->drawable, req->readable,
1441*4882a593Smuzhiyun                         req->context, req->oldContextTag));
1442*4882a593Smuzhiyun }
1443*4882a593Smuzhiyun 
1444*4882a593Smuzhiyun int
__glXIsDirect(__GLXclientState * cl,GLbyte * pc)1445*4882a593Smuzhiyun __glXIsDirect(__GLXclientState * cl, GLbyte * pc)
1446*4882a593Smuzhiyun {
1447*4882a593Smuzhiyun     ClientPtr client = cl->client;
1448*4882a593Smuzhiyun     xGLXIsDirectReq *req = (xGLXIsDirectReq *) pc;
1449*4882a593Smuzhiyun     xGLXIsDirectReply reply;
1450*4882a593Smuzhiyun     __GLXcontext *glxc;
1451*4882a593Smuzhiyun 
1452*4882a593Smuzhiyun     /*
1453*4882a593Smuzhiyun      ** Find the GL context.
1454*4882a593Smuzhiyun      */
1455*4882a593Smuzhiyun     dixLookupResourceByType((void **) &glxc, req->context, __glXContextRes,
1456*4882a593Smuzhiyun                             NullClient, DixUnknownAccess);
1457*4882a593Smuzhiyun     if (!glxc) {
1458*4882a593Smuzhiyun         client->errorValue = req->context;
1459*4882a593Smuzhiyun         return __glXBadContext;
1460*4882a593Smuzhiyun     }
1461*4882a593Smuzhiyun 
1462*4882a593Smuzhiyun     reply = (xGLXIsDirectReply) {
1463*4882a593Smuzhiyun         .type = X_Reply,
1464*4882a593Smuzhiyun         .sequenceNumber = client->sequence,
1465*4882a593Smuzhiyun         .length = 0,
1466*4882a593Smuzhiyun         .isDirect = 0
1467*4882a593Smuzhiyun     };
1468*4882a593Smuzhiyun 
1469*4882a593Smuzhiyun     if (client->swapped) {
1470*4882a593Smuzhiyun         __glXSwapIsDirectReply(client, &reply);
1471*4882a593Smuzhiyun     }
1472*4882a593Smuzhiyun     else {
1473*4882a593Smuzhiyun         WriteToClient(client, sz_xGLXIsDirectReply, &reply);
1474*4882a593Smuzhiyun     }
1475*4882a593Smuzhiyun 
1476*4882a593Smuzhiyun     return Success;
1477*4882a593Smuzhiyun }
1478*4882a593Smuzhiyun 
1479*4882a593Smuzhiyun int
__glXQueryVersion(__GLXclientState * cl,GLbyte * pc)1480*4882a593Smuzhiyun __glXQueryVersion(__GLXclientState * cl, GLbyte * pc)
1481*4882a593Smuzhiyun {
1482*4882a593Smuzhiyun     ClientPtr client = cl->client;
1483*4882a593Smuzhiyun 
1484*4882a593Smuzhiyun /*    xGLXQueryVersionReq *req = (xGLXQueryVersionReq *) pc; */
1485*4882a593Smuzhiyun 
1486*4882a593Smuzhiyun     xGLXQueryVersionReply reply = {
1487*4882a593Smuzhiyun         .type = X_Reply,
1488*4882a593Smuzhiyun         .sequenceNumber = client->sequence,
1489*4882a593Smuzhiyun         .length = 0,
1490*4882a593Smuzhiyun     /*
1491*4882a593Smuzhiyun      ** Server should take into consideration the version numbers sent by the
1492*4882a593Smuzhiyun      ** client if it wants to work with older clients; however, in this
1493*4882a593Smuzhiyun      ** implementation the server just returns its version number.
1494*4882a593Smuzhiyun      */
1495*4882a593Smuzhiyun         .majorVersion = __glXVersionMajor,
1496*4882a593Smuzhiyun         .minorVersion = __glXVersionMinor
1497*4882a593Smuzhiyun     };
1498*4882a593Smuzhiyun 
1499*4882a593Smuzhiyun     if (client->swapped) {
1500*4882a593Smuzhiyun         __glXSwapQueryVersionReply(client, &reply);
1501*4882a593Smuzhiyun     }
1502*4882a593Smuzhiyun     else {
1503*4882a593Smuzhiyun         WriteToClient(client, sz_xGLXQueryVersionReply, &reply);
1504*4882a593Smuzhiyun     }
1505*4882a593Smuzhiyun     return Success;
1506*4882a593Smuzhiyun }
1507*4882a593Smuzhiyun 
1508*4882a593Smuzhiyun int
__glXWaitGL(__GLXclientState * cl,GLbyte * pc)1509*4882a593Smuzhiyun __glXWaitGL(__GLXclientState * cl, GLbyte * pc)
1510*4882a593Smuzhiyun {
1511*4882a593Smuzhiyun     xGLXWaitGLReq *req = (xGLXWaitGLReq *) pc;
1512*4882a593Smuzhiyun     xGLXWaitGLReq *be_req = (xGLXWaitGLReq *) pc;
1513*4882a593Smuzhiyun     int from_screen = 0;
1514*4882a593Smuzhiyun     int to_screen = 0;
1515*4882a593Smuzhiyun     int s;
1516*4882a593Smuzhiyun     __GLXcontext *glxc = NULL;
1517*4882a593Smuzhiyun 
1518*4882a593Smuzhiyun     if (req->contextTag != 0) {
1519*4882a593Smuzhiyun         glxc = __glXLookupContextByTag(cl, req->contextTag);
1520*4882a593Smuzhiyun         if (glxc) {
1521*4882a593Smuzhiyun             from_screen = to_screen = glxc->pScreen->myNum;
1522*4882a593Smuzhiyun         }
1523*4882a593Smuzhiyun     }
1524*4882a593Smuzhiyun 
1525*4882a593Smuzhiyun #ifdef PANORAMIX
1526*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
1527*4882a593Smuzhiyun         from_screen = 0;
1528*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
1529*4882a593Smuzhiyun     }
1530*4882a593Smuzhiyun #endif
1531*4882a593Smuzhiyun 
1532*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
1533*4882a593Smuzhiyun         DMXScreenInfo *dmxScreen = &dmxScreens[s];
1534*4882a593Smuzhiyun         Display *dpy = GetBackEndDisplay(cl, s);
1535*4882a593Smuzhiyun 
1536*4882a593Smuzhiyun         LockDisplay(dpy);
1537*4882a593Smuzhiyun         GetReq(GLXWaitGL, be_req);
1538*4882a593Smuzhiyun         be_req->reqType = dmxScreen->glxMajorOpcode;
1539*4882a593Smuzhiyun         be_req->glxCode = X_GLXWaitGL;
1540*4882a593Smuzhiyun         be_req->contextTag =
1541*4882a593Smuzhiyun             (glxc ? GetCurrentBackEndTag(cl, req->contextTag, s) : 0);
1542*4882a593Smuzhiyun         UnlockDisplay(dpy);
1543*4882a593Smuzhiyun         SyncHandle();
1544*4882a593Smuzhiyun 
1545*4882a593Smuzhiyun         XSync(dpy, False);
1546*4882a593Smuzhiyun     }
1547*4882a593Smuzhiyun 
1548*4882a593Smuzhiyun     return Success;
1549*4882a593Smuzhiyun }
1550*4882a593Smuzhiyun 
1551*4882a593Smuzhiyun int
__glXWaitX(__GLXclientState * cl,GLbyte * pc)1552*4882a593Smuzhiyun __glXWaitX(__GLXclientState * cl, GLbyte * pc)
1553*4882a593Smuzhiyun {
1554*4882a593Smuzhiyun     xGLXWaitXReq *req = (xGLXWaitXReq *) pc;
1555*4882a593Smuzhiyun     xGLXWaitXReq *be_req;
1556*4882a593Smuzhiyun     int from_screen = 0;
1557*4882a593Smuzhiyun     int to_screen = 0;
1558*4882a593Smuzhiyun     int s;
1559*4882a593Smuzhiyun     __GLXcontext *glxc = NULL;
1560*4882a593Smuzhiyun 
1561*4882a593Smuzhiyun     if (req->contextTag != 0) {
1562*4882a593Smuzhiyun         glxc = __glXLookupContextByTag(cl, req->contextTag);
1563*4882a593Smuzhiyun         if (glxc) {
1564*4882a593Smuzhiyun             from_screen = to_screen = glxc->pScreen->myNum;
1565*4882a593Smuzhiyun         }
1566*4882a593Smuzhiyun     }
1567*4882a593Smuzhiyun 
1568*4882a593Smuzhiyun #ifdef PANORAMIX
1569*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
1570*4882a593Smuzhiyun         from_screen = 0;
1571*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
1572*4882a593Smuzhiyun     }
1573*4882a593Smuzhiyun #endif
1574*4882a593Smuzhiyun 
1575*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
1576*4882a593Smuzhiyun         DMXScreenInfo *dmxScreen = &dmxScreens[s];
1577*4882a593Smuzhiyun         Display *dpy = GetBackEndDisplay(cl, s);
1578*4882a593Smuzhiyun 
1579*4882a593Smuzhiyun         dmxSync(dmxScreen, 1);
1580*4882a593Smuzhiyun 
1581*4882a593Smuzhiyun         LockDisplay(dpy);
1582*4882a593Smuzhiyun         GetReq(GLXWaitX, be_req);
1583*4882a593Smuzhiyun         be_req->reqType = dmxScreen->glxMajorOpcode;
1584*4882a593Smuzhiyun         be_req->glxCode = X_GLXWaitX;
1585*4882a593Smuzhiyun         be_req->contextTag =
1586*4882a593Smuzhiyun             (glxc ? GetCurrentBackEndTag(cl, req->contextTag, s) : 0);
1587*4882a593Smuzhiyun         UnlockDisplay(dpy);
1588*4882a593Smuzhiyun         SyncHandle();
1589*4882a593Smuzhiyun 
1590*4882a593Smuzhiyun         XFlush(dpy);
1591*4882a593Smuzhiyun     }
1592*4882a593Smuzhiyun 
1593*4882a593Smuzhiyun     return Success;
1594*4882a593Smuzhiyun }
1595*4882a593Smuzhiyun 
1596*4882a593Smuzhiyun int
__glXCopyContext(__GLXclientState * cl,GLbyte * pc)1597*4882a593Smuzhiyun __glXCopyContext(__GLXclientState * cl, GLbyte * pc)
1598*4882a593Smuzhiyun {
1599*4882a593Smuzhiyun     ClientPtr client = cl->client;
1600*4882a593Smuzhiyun     xGLXCopyContextReq *be_req;
1601*4882a593Smuzhiyun     xGLXCopyContextReq *req = (xGLXCopyContextReq *) pc;
1602*4882a593Smuzhiyun     GLXContextID source = req->source;
1603*4882a593Smuzhiyun     GLXContextID dest = req->dest;
1604*4882a593Smuzhiyun     GLXContextTag tag = req->contextTag;
1605*4882a593Smuzhiyun     unsigned long mask = req->mask;
1606*4882a593Smuzhiyun     __GLXcontext *src, *dst;
1607*4882a593Smuzhiyun     int s;
1608*4882a593Smuzhiyun     int from_screen = 0;
1609*4882a593Smuzhiyun     int to_screen = 0;
1610*4882a593Smuzhiyun 
1611*4882a593Smuzhiyun     /*
1612*4882a593Smuzhiyun      ** Check that each context exists.
1613*4882a593Smuzhiyun      */
1614*4882a593Smuzhiyun     dixLookupResourceByType((void **) &src, source, __glXContextRes,
1615*4882a593Smuzhiyun                             NullClient, DixUnknownAccess);
1616*4882a593Smuzhiyun     if (!src) {
1617*4882a593Smuzhiyun         client->errorValue = source;
1618*4882a593Smuzhiyun         return __glXBadContext;
1619*4882a593Smuzhiyun     }
1620*4882a593Smuzhiyun     dixLookupResourceByType((void **) &dst, dest, __glXContextRes,
1621*4882a593Smuzhiyun                             NullClient, DixUnknownAccess);
1622*4882a593Smuzhiyun     if (!dst) {
1623*4882a593Smuzhiyun         client->errorValue = dest;
1624*4882a593Smuzhiyun         return __glXBadContext;
1625*4882a593Smuzhiyun     }
1626*4882a593Smuzhiyun 
1627*4882a593Smuzhiyun     /*
1628*4882a593Smuzhiyun      ** They must be in the same address space, and same screen.
1629*4882a593Smuzhiyun      */
1630*4882a593Smuzhiyun     if (src->pGlxScreen != dst->pGlxScreen) {
1631*4882a593Smuzhiyun         client->errorValue = source;
1632*4882a593Smuzhiyun         return BadMatch;
1633*4882a593Smuzhiyun     }
1634*4882a593Smuzhiyun 
1635*4882a593Smuzhiyun     /*
1636*4882a593Smuzhiyun      ** The destination context must not be current for any client.
1637*4882a593Smuzhiyun      */
1638*4882a593Smuzhiyun     if (dst->isCurrent) {
1639*4882a593Smuzhiyun         client->errorValue = dest;
1640*4882a593Smuzhiyun         return BadAccess;
1641*4882a593Smuzhiyun     }
1642*4882a593Smuzhiyun 
1643*4882a593Smuzhiyun     if (tag) {
1644*4882a593Smuzhiyun         __GLXcontext *tagcx = __glXLookupContextByTag(cl, tag);
1645*4882a593Smuzhiyun 
1646*4882a593Smuzhiyun         if (!tagcx) {
1647*4882a593Smuzhiyun             return __glXBadContextTag;
1648*4882a593Smuzhiyun         }
1649*4882a593Smuzhiyun         if (tagcx != src) {
1650*4882a593Smuzhiyun             /*
1651*4882a593Smuzhiyun              ** This would be caused by a faulty implementation of the client
1652*4882a593Smuzhiyun              ** library.
1653*4882a593Smuzhiyun              */
1654*4882a593Smuzhiyun             return BadMatch;
1655*4882a593Smuzhiyun         }
1656*4882a593Smuzhiyun     }
1657*4882a593Smuzhiyun 
1658*4882a593Smuzhiyun     from_screen = to_screen = src->pScreen->myNum;
1659*4882a593Smuzhiyun 
1660*4882a593Smuzhiyun #ifdef PANORAMIX
1661*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
1662*4882a593Smuzhiyun         from_screen = 0;
1663*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
1664*4882a593Smuzhiyun     }
1665*4882a593Smuzhiyun #endif
1666*4882a593Smuzhiyun 
1667*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
1668*4882a593Smuzhiyun         DMXScreenInfo *dmxScreen = &dmxScreens[s];
1669*4882a593Smuzhiyun         Display *dpy = GetBackEndDisplay(cl, s);
1670*4882a593Smuzhiyun 
1671*4882a593Smuzhiyun         LockDisplay(dpy);
1672*4882a593Smuzhiyun         GetReq(GLXCopyContext, be_req);
1673*4882a593Smuzhiyun         be_req->reqType = dmxScreen->glxMajorOpcode;
1674*4882a593Smuzhiyun         be_req->glxCode = X_GLXCopyContext;
1675*4882a593Smuzhiyun         be_req->source = (unsigned int) src->real_ids[s - from_screen];
1676*4882a593Smuzhiyun         be_req->dest = (unsigned int) dst->real_ids[s - from_screen];
1677*4882a593Smuzhiyun         be_req->mask = mask;
1678*4882a593Smuzhiyun         be_req->contextTag =
1679*4882a593Smuzhiyun             (tag ? GetCurrentBackEndTag(cl, req->contextTag, s) : 0);
1680*4882a593Smuzhiyun         UnlockDisplay(dpy);
1681*4882a593Smuzhiyun         SyncHandle();
1682*4882a593Smuzhiyun     }
1683*4882a593Smuzhiyun 
1684*4882a593Smuzhiyun     return Success;
1685*4882a593Smuzhiyun }
1686*4882a593Smuzhiyun 
1687*4882a593Smuzhiyun int
__glXGetVisualConfigs(__GLXclientState * cl,GLbyte * pc)1688*4882a593Smuzhiyun __glXGetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
1689*4882a593Smuzhiyun {
1690*4882a593Smuzhiyun     ClientPtr client = cl->client;
1691*4882a593Smuzhiyun     xGLXGetVisualConfigsReq *req = (xGLXGetVisualConfigsReq *) pc;
1692*4882a593Smuzhiyun     xGLXGetVisualConfigsReply reply;
1693*4882a593Smuzhiyun     __GLXscreenInfo *pGlxScreen;
1694*4882a593Smuzhiyun     __GLXvisualConfig *pGlxVisual;
1695*4882a593Smuzhiyun     CARD32 buf[__GLX_TOTAL_CONFIG];
1696*4882a593Smuzhiyun     unsigned int screen;
1697*4882a593Smuzhiyun     int i, p;
1698*4882a593Smuzhiyun 
1699*4882a593Smuzhiyun     screen = req->screen;
1700*4882a593Smuzhiyun     if (screen >= screenInfo.numScreens) {
1701*4882a593Smuzhiyun         /* The client library must send a valid screen number. */
1702*4882a593Smuzhiyun         client->errorValue = screen;
1703*4882a593Smuzhiyun         return BadValue;
1704*4882a593Smuzhiyun     }
1705*4882a593Smuzhiyun     pGlxScreen = &__glXActiveScreens[screen];
1706*4882a593Smuzhiyun 
1707*4882a593Smuzhiyun     reply = (xGLXGetVisualConfigsReply) {
1708*4882a593Smuzhiyun         .type = X_Reply,
1709*4882a593Smuzhiyun         .sequenceNumber = client->sequence,
1710*4882a593Smuzhiyun         .numVisuals = pGlxScreen->numGLXVisuals,
1711*4882a593Smuzhiyun         .numProps = __GLX_TOTAL_CONFIG,
1712*4882a593Smuzhiyun         .length = (pGlxScreen->numGLXVisuals * __GLX_SIZE_CARD32 *
1713*4882a593Smuzhiyun                     __GLX_TOTAL_CONFIG) >> 2
1714*4882a593Smuzhiyun     };
1715*4882a593Smuzhiyun 
1716*4882a593Smuzhiyun     WriteToClient(client, sz_xGLXGetVisualConfigsReply, &reply);
1717*4882a593Smuzhiyun 
1718*4882a593Smuzhiyun     for (i = 0; i < pGlxScreen->numVisuals; i++) {
1719*4882a593Smuzhiyun         pGlxVisual = &pGlxScreen->pGlxVisual[i];
1720*4882a593Smuzhiyun         if (!pGlxScreen->isGLXvis[i] || pGlxVisual->vid == 0) {
1721*4882a593Smuzhiyun             /* not a usable visual */
1722*4882a593Smuzhiyun             continue;
1723*4882a593Smuzhiyun         }
1724*4882a593Smuzhiyun         p = 0;
1725*4882a593Smuzhiyun         buf[p++] = pGlxVisual->vid;
1726*4882a593Smuzhiyun         buf[p++] = pGlxVisual->class;
1727*4882a593Smuzhiyun         buf[p++] = pGlxVisual->rgba;
1728*4882a593Smuzhiyun 
1729*4882a593Smuzhiyun         buf[p++] = pGlxVisual->redSize;
1730*4882a593Smuzhiyun         buf[p++] = pGlxVisual->greenSize;
1731*4882a593Smuzhiyun         buf[p++] = pGlxVisual->blueSize;
1732*4882a593Smuzhiyun         buf[p++] = pGlxVisual->alphaSize;
1733*4882a593Smuzhiyun         buf[p++] = pGlxVisual->accumRedSize;
1734*4882a593Smuzhiyun         buf[p++] = pGlxVisual->accumGreenSize;
1735*4882a593Smuzhiyun         buf[p++] = pGlxVisual->accumBlueSize;
1736*4882a593Smuzhiyun         buf[p++] = pGlxVisual->accumAlphaSize;
1737*4882a593Smuzhiyun 
1738*4882a593Smuzhiyun         buf[p++] = pGlxVisual->doubleBuffer;
1739*4882a593Smuzhiyun         buf[p++] = pGlxVisual->stereo;
1740*4882a593Smuzhiyun 
1741*4882a593Smuzhiyun         buf[p++] = pGlxVisual->bufferSize;
1742*4882a593Smuzhiyun         buf[p++] = pGlxVisual->depthSize;
1743*4882a593Smuzhiyun         buf[p++] = pGlxVisual->stencilSize;
1744*4882a593Smuzhiyun         buf[p++] = pGlxVisual->auxBuffers;
1745*4882a593Smuzhiyun         buf[p++] = pGlxVisual->level;
1746*4882a593Smuzhiyun         /*
1747*4882a593Smuzhiyun          ** Add token/value pairs for extensions.
1748*4882a593Smuzhiyun          */
1749*4882a593Smuzhiyun         buf[p++] = GLX_VISUAL_CAVEAT_EXT;
1750*4882a593Smuzhiyun         buf[p++] = pGlxVisual->visualRating;
1751*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_TYPE_EXT;
1752*4882a593Smuzhiyun         buf[p++] = pGlxVisual->transparentPixel;
1753*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_RED_VALUE_EXT;
1754*4882a593Smuzhiyun         buf[p++] = pGlxVisual->transparentRed;
1755*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_GREEN_VALUE_EXT;
1756*4882a593Smuzhiyun         buf[p++] = pGlxVisual->transparentGreen;
1757*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_BLUE_VALUE_EXT;
1758*4882a593Smuzhiyun         buf[p++] = pGlxVisual->transparentBlue;
1759*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_ALPHA_VALUE_EXT;
1760*4882a593Smuzhiyun         buf[p++] = pGlxVisual->transparentAlpha;
1761*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_INDEX_VALUE_EXT;
1762*4882a593Smuzhiyun         buf[p++] = pGlxVisual->transparentIndex;
1763*4882a593Smuzhiyun         buf[p++] = GLX_SAMPLES_SGIS;
1764*4882a593Smuzhiyun         buf[p++] = pGlxVisual->multiSampleSize;
1765*4882a593Smuzhiyun         buf[p++] = GLX_SAMPLE_BUFFERS_SGIS;
1766*4882a593Smuzhiyun         buf[p++] = pGlxVisual->nMultiSampleBuffers;
1767*4882a593Smuzhiyun         buf[p++] = GLX_VISUAL_SELECT_GROUP_SGIX;
1768*4882a593Smuzhiyun         buf[p++] = pGlxVisual->visualSelectGroup;
1769*4882a593Smuzhiyun 
1770*4882a593Smuzhiyun         WriteToClient(client, __GLX_SIZE_CARD32 * __GLX_TOTAL_CONFIG, buf);
1771*4882a593Smuzhiyun     }
1772*4882a593Smuzhiyun     return Success;
1773*4882a593Smuzhiyun }
1774*4882a593Smuzhiyun 
1775*4882a593Smuzhiyun /*
1776*4882a593Smuzhiyun ** Create a GLX Pixmap from an X Pixmap.
1777*4882a593Smuzhiyun */
1778*4882a593Smuzhiyun static int
CreateGLXPixmap(__GLXclientState * cl,VisualID visual,GLXFBConfigID fbconfigId,int screenNum,XID pixmapId,XID glxpixmapId)1779*4882a593Smuzhiyun CreateGLXPixmap(__GLXclientState * cl,
1780*4882a593Smuzhiyun                 VisualID visual, GLXFBConfigID fbconfigId,
1781*4882a593Smuzhiyun                 int screenNum, XID pixmapId, XID glxpixmapId)
1782*4882a593Smuzhiyun {
1783*4882a593Smuzhiyun     ClientPtr client = cl->client;
1784*4882a593Smuzhiyun     xGLXCreateGLXPixmapReq *be_req;
1785*4882a593Smuzhiyun     xGLXCreatePixmapReq *be_new_req;
1786*4882a593Smuzhiyun     DrawablePtr pDraw;
1787*4882a593Smuzhiyun     ScreenPtr pScreen;
1788*4882a593Smuzhiyun     VisualPtr pVisual;
1789*4882a593Smuzhiyun     __GLXpixmap *pGlxPixmap;
1790*4882a593Smuzhiyun     __GLXscreenInfo *pGlxScreen;
1791*4882a593Smuzhiyun     __GLXvisualConfig *pGlxVisual;
1792*4882a593Smuzhiyun     __GLXFBConfig *pFBConfig;
1793*4882a593Smuzhiyun     int i, s, rc;
1794*4882a593Smuzhiyun     int from_screen, to_screen;
1795*4882a593Smuzhiyun 
1796*4882a593Smuzhiyun #ifdef PANORAMIX
1797*4882a593Smuzhiyun     PanoramiXRes *pXinDraw = NULL;
1798*4882a593Smuzhiyun #endif
1799*4882a593Smuzhiyun 
1800*4882a593Smuzhiyun     rc = dixLookupDrawable(&pDraw, pixmapId, client, M_DRAWABLE_PIXMAP,
1801*4882a593Smuzhiyun                            DixAddAccess);
1802*4882a593Smuzhiyun     if (rc != Success)
1803*4882a593Smuzhiyun         return rc;
1804*4882a593Smuzhiyun 
1805*4882a593Smuzhiyun     /*
1806*4882a593Smuzhiyun      ** Check if screen of visual matches screen of pixmap.
1807*4882a593Smuzhiyun      */
1808*4882a593Smuzhiyun     pScreen = pDraw->pScreen;
1809*4882a593Smuzhiyun     if (screenNum != pScreen->myNum) {
1810*4882a593Smuzhiyun         return BadMatch;
1811*4882a593Smuzhiyun     }
1812*4882a593Smuzhiyun 
1813*4882a593Smuzhiyun     if (fbconfigId == 0 && visual == 0) {
1814*4882a593Smuzhiyun         return BadValue;
1815*4882a593Smuzhiyun     }
1816*4882a593Smuzhiyun 
1817*4882a593Smuzhiyun     if (fbconfigId != None) {
1818*4882a593Smuzhiyun         pFBConfig = glxLookupFBConfig(fbconfigId);
1819*4882a593Smuzhiyun         if (!pFBConfig) {
1820*4882a593Smuzhiyun             client->errorValue = fbconfigId;
1821*4882a593Smuzhiyun             return BadValue;
1822*4882a593Smuzhiyun         }
1823*4882a593Smuzhiyun         visual = pFBConfig->associatedVisualId;
1824*4882a593Smuzhiyun     }
1825*4882a593Smuzhiyun     else {
1826*4882a593Smuzhiyun         pFBConfig = NULL;
1827*4882a593Smuzhiyun     }
1828*4882a593Smuzhiyun 
1829*4882a593Smuzhiyun     if (visual != None) {
1830*4882a593Smuzhiyun         /*
1831*4882a593Smuzhiyun          ** Find the VisualRec for this visual.
1832*4882a593Smuzhiyun          */
1833*4882a593Smuzhiyun         pVisual = pScreen->visuals;
1834*4882a593Smuzhiyun         for (i = 0; i < pScreen->numVisuals; i++, pVisual++) {
1835*4882a593Smuzhiyun             if (pVisual->vid == visual) {
1836*4882a593Smuzhiyun                 break;
1837*4882a593Smuzhiyun             }
1838*4882a593Smuzhiyun         }
1839*4882a593Smuzhiyun         if (i == pScreen->numVisuals) {
1840*4882a593Smuzhiyun             client->errorValue = visual;
1841*4882a593Smuzhiyun             return BadValue;
1842*4882a593Smuzhiyun         }
1843*4882a593Smuzhiyun         /*
1844*4882a593Smuzhiyun          ** Check if depth of visual matches depth of pixmap.
1845*4882a593Smuzhiyun          */
1846*4882a593Smuzhiyun         if (pVisual->nplanes != pDraw->depth) {
1847*4882a593Smuzhiyun             client->errorValue = visual;
1848*4882a593Smuzhiyun             return BadMatch;
1849*4882a593Smuzhiyun         }
1850*4882a593Smuzhiyun 
1851*4882a593Smuzhiyun         /*
1852*4882a593Smuzhiyun          ** Get configuration of the visual.
1853*4882a593Smuzhiyun          */
1854*4882a593Smuzhiyun         pGlxScreen = &__glXActiveScreens[screenNum];
1855*4882a593Smuzhiyun         pGlxVisual = pGlxScreen->pGlxVisual;
1856*4882a593Smuzhiyun         for (i = 0; i < pGlxScreen->numVisuals; i++, pGlxVisual++) {
1857*4882a593Smuzhiyun             if (pGlxVisual->vid == visual) {
1858*4882a593Smuzhiyun                 break;
1859*4882a593Smuzhiyun             }
1860*4882a593Smuzhiyun         }
1861*4882a593Smuzhiyun         if (i == pGlxScreen->numVisuals) {
1862*4882a593Smuzhiyun             /*
1863*4882a593Smuzhiyun              ** Visual not support on this screen by this OpenGL implementation.
1864*4882a593Smuzhiyun              */
1865*4882a593Smuzhiyun             client->errorValue = visual;
1866*4882a593Smuzhiyun             return BadValue;
1867*4882a593Smuzhiyun         }
1868*4882a593Smuzhiyun 
1869*4882a593Smuzhiyun         /* find the FBConfig for that visual (if any) */
1870*4882a593Smuzhiyun         if (pFBConfig == NULL) {
1871*4882a593Smuzhiyun             pFBConfig = glxLookupFBConfigByVID(visual);
1872*4882a593Smuzhiyun 
1873*4882a593Smuzhiyun             if (pFBConfig == NULL) {
1874*4882a593Smuzhiyun                 /*
1875*4882a593Smuzhiyun                  * visual does not have an FBConfig ???
1876*4882a593Smuzhiyun                  client->errorValue = visual;
1877*4882a593Smuzhiyun                  return BadValue;
1878*4882a593Smuzhiyun                  */
1879*4882a593Smuzhiyun             }
1880*4882a593Smuzhiyun         }
1881*4882a593Smuzhiyun     }
1882*4882a593Smuzhiyun     else {
1883*4882a593Smuzhiyun         pVisual = NULL;
1884*4882a593Smuzhiyun         pGlxVisual = NULL;
1885*4882a593Smuzhiyun         pGlxScreen = &__glXActiveScreens[pDraw->pScreen->myNum];
1886*4882a593Smuzhiyun     }
1887*4882a593Smuzhiyun 
1888*4882a593Smuzhiyun     pGlxPixmap = (__GLXpixmap *) malloc(sizeof(__GLXpixmap));
1889*4882a593Smuzhiyun     if (!pGlxPixmap) {
1890*4882a593Smuzhiyun         return BadAlloc;
1891*4882a593Smuzhiyun     }
1892*4882a593Smuzhiyun     pGlxPixmap->be_xids = xallocarray(screenInfo.numScreens, sizeof(XID));
1893*4882a593Smuzhiyun     if (!pGlxPixmap->be_xids) {
1894*4882a593Smuzhiyun         free(pGlxPixmap);
1895*4882a593Smuzhiyun         return BadAlloc;
1896*4882a593Smuzhiyun     }
1897*4882a593Smuzhiyun 
1898*4882a593Smuzhiyun     pGlxPixmap->pDraw = pDraw;
1899*4882a593Smuzhiyun     pGlxPixmap->pGlxScreen = pGlxScreen;
1900*4882a593Smuzhiyun     pGlxPixmap->pGlxVisual = pGlxVisual;
1901*4882a593Smuzhiyun     pGlxPixmap->pFBConfig = pFBConfig;
1902*4882a593Smuzhiyun     pGlxPixmap->pScreen = pScreen;
1903*4882a593Smuzhiyun     pGlxPixmap->idExists = True;
1904*4882a593Smuzhiyun     pGlxPixmap->refcnt = 0;
1905*4882a593Smuzhiyun 
1906*4882a593Smuzhiyun     /*
1907*4882a593Smuzhiyun      ** Bump the ref count on the X pixmap so it won't disappear.
1908*4882a593Smuzhiyun      */
1909*4882a593Smuzhiyun     ((PixmapPtr) pDraw)->refcnt++;
1910*4882a593Smuzhiyun 
1911*4882a593Smuzhiyun     /*
1912*4882a593Smuzhiyun      * send the request to the back-end server(s)
1913*4882a593Smuzhiyun      */
1914*4882a593Smuzhiyun     from_screen = to_screen = screenNum;
1915*4882a593Smuzhiyun #ifdef PANORAMIX
1916*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
1917*4882a593Smuzhiyun         from_screen = 0;
1918*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
1919*4882a593Smuzhiyun 
1920*4882a593Smuzhiyun         dixLookupResourceByClass((void **) &pXinDraw,
1921*4882a593Smuzhiyun                                  pDraw->id, XRC_DRAWABLE,
1922*4882a593Smuzhiyun                                  client, DixReadAccess);
1923*4882a593Smuzhiyun     }
1924*4882a593Smuzhiyun #endif
1925*4882a593Smuzhiyun 
1926*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
1927*4882a593Smuzhiyun 
1928*4882a593Smuzhiyun         DMXScreenInfo *dmxScreen = &dmxScreens[s];
1929*4882a593Smuzhiyun         Display *dpy = GetBackEndDisplay(cl, s);
1930*4882a593Smuzhiyun         Pixmap be_pixmap;
1931*4882a593Smuzhiyun         DrawablePtr pRealDraw = pDraw;
1932*4882a593Smuzhiyun 
1933*4882a593Smuzhiyun #ifdef PANORAMIX
1934*4882a593Smuzhiyun         if (pXinDraw) {
1935*4882a593Smuzhiyun             dixLookupDrawable(&pRealDraw, pXinDraw->info[s].id, client, 0,
1936*4882a593Smuzhiyun                               DixAddAccess);
1937*4882a593Smuzhiyun         }
1938*4882a593Smuzhiyun #endif
1939*4882a593Smuzhiyun 
1940*4882a593Smuzhiyun         be_pixmap = (DMX_GET_PIXMAP_PRIV((PixmapPtr) pRealDraw))->pixmap;
1941*4882a593Smuzhiyun 
1942*4882a593Smuzhiyun         /* make sure pixmap already created on back-end */
1943*4882a593Smuzhiyun         dmxSync(dmxScreen, 1);
1944*4882a593Smuzhiyun 
1945*4882a593Smuzhiyun         if (pFBConfig && __GLX_IS_VERSION_SUPPORTED(1, 3)) {
1946*4882a593Smuzhiyun             __GLXFBConfig *be_FBConfig =
1947*4882a593Smuzhiyun                 glxLookupBackEndFBConfig(pFBConfig->id, s);
1948*4882a593Smuzhiyun 
1949*4882a593Smuzhiyun             LockDisplay(dpy);
1950*4882a593Smuzhiyun             pGlxPixmap->be_xids[s] = XAllocID(dpy);
1951*4882a593Smuzhiyun             GetReq(GLXCreatePixmap, be_new_req);
1952*4882a593Smuzhiyun             be_new_req->reqType = dmxScreen->glxMajorOpcode;
1953*4882a593Smuzhiyun             be_new_req->glxCode = X_GLXCreatePixmap;
1954*4882a593Smuzhiyun             be_new_req->screen = DefaultScreen(dpy);
1955*4882a593Smuzhiyun             be_new_req->fbconfig = be_FBConfig->id;
1956*4882a593Smuzhiyun             be_new_req->pixmap = (unsigned int) be_pixmap;
1957*4882a593Smuzhiyun             be_new_req->glxpixmap = (unsigned int) pGlxPixmap->be_xids[s];
1958*4882a593Smuzhiyun             be_new_req->numAttribs = 0;
1959*4882a593Smuzhiyun             UnlockDisplay(dpy);
1960*4882a593Smuzhiyun             SyncHandle();
1961*4882a593Smuzhiyun         }
1962*4882a593Smuzhiyun         else if (pFBConfig && glxIsExtensionSupported("GLX_SGIX_fbconfig")) {
1963*4882a593Smuzhiyun             __GLXFBConfig *be_FBConfig =
1964*4882a593Smuzhiyun                 glxLookupBackEndFBConfig(pFBConfig->id, s);
1965*4882a593Smuzhiyun             xGLXCreateGLXPixmapWithConfigSGIXReq *ext_req;
1966*4882a593Smuzhiyun             xGLXVendorPrivateReq *vpreq;
1967*4882a593Smuzhiyun 
1968*4882a593Smuzhiyun             LockDisplay(dpy);
1969*4882a593Smuzhiyun             pGlxPixmap->be_xids[s] = XAllocID(dpy);
1970*4882a593Smuzhiyun             GetReqExtra(GLXVendorPrivate,
1971*4882a593Smuzhiyun                         sz_xGLXCreateGLXPixmapWithConfigSGIXReq -
1972*4882a593Smuzhiyun                         sz_xGLXVendorPrivateReq, vpreq);
1973*4882a593Smuzhiyun             ext_req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq;
1974*4882a593Smuzhiyun             ext_req->reqType = dmxScreen->glxMajorOpcode;
1975*4882a593Smuzhiyun             ext_req->glxCode = X_GLXVendorPrivate;
1976*4882a593Smuzhiyun             ext_req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
1977*4882a593Smuzhiyun             ext_req->screen = DefaultScreen(dpy);
1978*4882a593Smuzhiyun             ext_req->fbconfig = be_FBConfig->id;
1979*4882a593Smuzhiyun             ext_req->pixmap = (unsigned int) be_pixmap;
1980*4882a593Smuzhiyun             ext_req->glxpixmap = (unsigned int) pGlxPixmap->be_xids[s];
1981*4882a593Smuzhiyun             UnlockDisplay(dpy);
1982*4882a593Smuzhiyun             SyncHandle();
1983*4882a593Smuzhiyun         }
1984*4882a593Smuzhiyun         else if (pGlxVisual) {
1985*4882a593Smuzhiyun             LockDisplay(dpy);
1986*4882a593Smuzhiyun             pGlxPixmap->be_xids[s] = XAllocID(dpy);
1987*4882a593Smuzhiyun             GetReq(GLXCreateGLXPixmap, be_req);
1988*4882a593Smuzhiyun             be_req->reqType = dmxScreen->glxMajorOpcode;
1989*4882a593Smuzhiyun             be_req->glxCode = X_GLXCreateGLXPixmap;
1990*4882a593Smuzhiyun             be_req->screen = DefaultScreen(dpy);
1991*4882a593Smuzhiyun             be_req->visual =
1992*4882a593Smuzhiyun                 (unsigned int) glxMatchGLXVisualInConfigList(pGlxVisual,
1993*4882a593Smuzhiyun                                                              dmxScreen->
1994*4882a593Smuzhiyun                                                              glxVisuals,
1995*4882a593Smuzhiyun                                                              dmxScreen->
1996*4882a593Smuzhiyun                                                              numGlxVisuals);
1997*4882a593Smuzhiyun             be_req->pixmap = (unsigned int) be_pixmap;
1998*4882a593Smuzhiyun             be_req->glxpixmap = (unsigned int) pGlxPixmap->be_xids[s];
1999*4882a593Smuzhiyun             UnlockDisplay(dpy);
2000*4882a593Smuzhiyun             SyncHandle();
2001*4882a593Smuzhiyun         }
2002*4882a593Smuzhiyun         else {
2003*4882a593Smuzhiyun             client->errorValue = (visual ? visual : fbconfigId);
2004*4882a593Smuzhiyun             free(pGlxPixmap->be_xids);
2005*4882a593Smuzhiyun             free(pGlxPixmap);
2006*4882a593Smuzhiyun             return BadValue;
2007*4882a593Smuzhiyun         }
2008*4882a593Smuzhiyun 
2009*4882a593Smuzhiyun         XFlush(dpy);
2010*4882a593Smuzhiyun     }
2011*4882a593Smuzhiyun 
2012*4882a593Smuzhiyun     if (!(AddResource(glxpixmapId, __glXPixmapRes, pGlxPixmap)))
2013*4882a593Smuzhiyun         return BadAlloc;
2014*4882a593Smuzhiyun 
2015*4882a593Smuzhiyun     return Success;
2016*4882a593Smuzhiyun }
2017*4882a593Smuzhiyun 
2018*4882a593Smuzhiyun int
__glXCreateGLXPixmap(__GLXclientState * cl,GLbyte * pc)2019*4882a593Smuzhiyun __glXCreateGLXPixmap(__GLXclientState * cl, GLbyte * pc)
2020*4882a593Smuzhiyun {
2021*4882a593Smuzhiyun     xGLXCreateGLXPixmapReq *req = (xGLXCreateGLXPixmapReq *) pc;
2022*4882a593Smuzhiyun 
2023*4882a593Smuzhiyun     return (CreateGLXPixmap(cl, req->visual, None,
2024*4882a593Smuzhiyun                             req->screen, req->pixmap, req->glxpixmap));
2025*4882a593Smuzhiyun }
2026*4882a593Smuzhiyun 
2027*4882a593Smuzhiyun int
__glXCreatePixmap(__GLXclientState * cl,GLbyte * pc)2028*4882a593Smuzhiyun __glXCreatePixmap(__GLXclientState * cl, GLbyte * pc)
2029*4882a593Smuzhiyun {
2030*4882a593Smuzhiyun     xGLXCreatePixmapReq *req = (xGLXCreatePixmapReq *) pc;
2031*4882a593Smuzhiyun 
2032*4882a593Smuzhiyun     return (CreateGLXPixmap(cl, None, req->fbconfig,
2033*4882a593Smuzhiyun                             req->screen, req->pixmap, req->glxpixmap));
2034*4882a593Smuzhiyun }
2035*4882a593Smuzhiyun 
2036*4882a593Smuzhiyun int
__glXDestroyGLXPixmap(__GLXclientState * cl,GLbyte * pc)2037*4882a593Smuzhiyun __glXDestroyGLXPixmap(__GLXclientState * cl, GLbyte * pc)
2038*4882a593Smuzhiyun {
2039*4882a593Smuzhiyun     ClientPtr client = cl->client;
2040*4882a593Smuzhiyun     xGLXDestroyGLXPixmapReq *req = (xGLXDestroyGLXPixmapReq *) pc;
2041*4882a593Smuzhiyun     XID glxpixmap = req->glxpixmap;
2042*4882a593Smuzhiyun     __GLXpixmap *pGlxPixmap;
2043*4882a593Smuzhiyun     int s;
2044*4882a593Smuzhiyun     int from_screen, to_screen;
2045*4882a593Smuzhiyun 
2046*4882a593Smuzhiyun     /*
2047*4882a593Smuzhiyun      ** Check if it's a valid GLX pixmap.
2048*4882a593Smuzhiyun      */
2049*4882a593Smuzhiyun     dixLookupResourceByType((void **) &pGlxPixmap, glxpixmap,
2050*4882a593Smuzhiyun                             __glXPixmapRes, NullClient, DixUnknownAccess);
2051*4882a593Smuzhiyun     if (!pGlxPixmap) {
2052*4882a593Smuzhiyun         client->errorValue = glxpixmap;
2053*4882a593Smuzhiyun         return __glXBadPixmap;
2054*4882a593Smuzhiyun     }
2055*4882a593Smuzhiyun     FreeResource(glxpixmap, FALSE);
2056*4882a593Smuzhiyun 
2057*4882a593Smuzhiyun     /*
2058*4882a593Smuzhiyun      * destroy the pixmap on the back-end server(s).
2059*4882a593Smuzhiyun      */
2060*4882a593Smuzhiyun     from_screen = to_screen = pGlxPixmap->pDraw->pScreen->myNum;
2061*4882a593Smuzhiyun #ifdef PANORAMIX
2062*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
2063*4882a593Smuzhiyun         from_screen = 0;
2064*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
2065*4882a593Smuzhiyun     }
2066*4882a593Smuzhiyun #endif
2067*4882a593Smuzhiyun 
2068*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
2069*4882a593Smuzhiyun         DMXScreenInfo *dmxScreen = &dmxScreens[s];
2070*4882a593Smuzhiyun         Display *dpy = GetBackEndDisplay(cl, s);
2071*4882a593Smuzhiyun 
2072*4882a593Smuzhiyun         /* make sure pixmap exist in back-end */
2073*4882a593Smuzhiyun         dmxSync(dmxScreen, 1);
2074*4882a593Smuzhiyun 
2075*4882a593Smuzhiyun         LockDisplay(dpy);
2076*4882a593Smuzhiyun         GetReq(GLXDestroyGLXPixmap, req);
2077*4882a593Smuzhiyun         req->reqType = dmxScreen->glxMajorOpcode;
2078*4882a593Smuzhiyun         req->glxCode = X_GLXDestroyGLXPixmap;
2079*4882a593Smuzhiyun         req->glxpixmap = (unsigned int) pGlxPixmap->be_xids[s];
2080*4882a593Smuzhiyun         UnlockDisplay(dpy);
2081*4882a593Smuzhiyun         SyncHandle();
2082*4882a593Smuzhiyun     }
2083*4882a593Smuzhiyun 
2084*4882a593Smuzhiyun     return Success;
2085*4882a593Smuzhiyun }
2086*4882a593Smuzhiyun 
2087*4882a593Smuzhiyun /*****************************************************************************/
2088*4882a593Smuzhiyun 
2089*4882a593Smuzhiyun /*
2090*4882a593Smuzhiyun ** NOTE: There is no portable implementation for swap buffers as of
2091*4882a593Smuzhiyun ** this time that is of value.  Consequently, this code must be
2092*4882a593Smuzhiyun ** implemented by somebody other than SGI.
2093*4882a593Smuzhiyun */
2094*4882a593Smuzhiyun int
__glXDoSwapBuffers(__GLXclientState * cl,XID drawId,GLXContextTag tag)2095*4882a593Smuzhiyun __glXDoSwapBuffers(__GLXclientState * cl, XID drawId, GLXContextTag tag)
2096*4882a593Smuzhiyun {
2097*4882a593Smuzhiyun     ClientPtr client = cl->client;
2098*4882a593Smuzhiyun     DrawablePtr pDraw;
2099*4882a593Smuzhiyun     xGLXSwapBuffersReq *be_req;
2100*4882a593Smuzhiyun     WindowPtr pWin = NULL;
2101*4882a593Smuzhiyun     __GLXpixmap *pGlxPixmap = NULL;
2102*4882a593Smuzhiyun     __GLXcontext *glxc = NULL;
2103*4882a593Smuzhiyun 
2104*4882a593Smuzhiyun #ifdef PANORAMIX
2105*4882a593Smuzhiyun     PanoramiXRes *pXinDraw = NULL;
2106*4882a593Smuzhiyun #endif
2107*4882a593Smuzhiyun     __glXWindow *pGlxWindow = NULL;
2108*4882a593Smuzhiyun     int from_screen = 0;
2109*4882a593Smuzhiyun     int to_screen = 0;
2110*4882a593Smuzhiyun     int s, rc;
2111*4882a593Smuzhiyun 
2112*4882a593Smuzhiyun     /*
2113*4882a593Smuzhiyun      ** Check that the GLX drawable is valid.
2114*4882a593Smuzhiyun      */
2115*4882a593Smuzhiyun     rc = dixLookupDrawable(&pDraw, drawId, client, 0, DixWriteAccess);
2116*4882a593Smuzhiyun     if (rc == Success) {
2117*4882a593Smuzhiyun         from_screen = to_screen = pDraw->pScreen->myNum;
2118*4882a593Smuzhiyun 
2119*4882a593Smuzhiyun         if (pDraw->type == DRAWABLE_WINDOW) {
2120*4882a593Smuzhiyun             /*
2121*4882a593Smuzhiyun              ** Drawable is an X window.
2122*4882a593Smuzhiyun              */
2123*4882a593Smuzhiyun             pWin = (WindowPtr) pDraw;
2124*4882a593Smuzhiyun         }
2125*4882a593Smuzhiyun         else {
2126*4882a593Smuzhiyun             /*
2127*4882a593Smuzhiyun              ** Drawable is an X pixmap, which is not allowed.
2128*4882a593Smuzhiyun              */
2129*4882a593Smuzhiyun             client->errorValue = drawId;
2130*4882a593Smuzhiyun             return __glXBadDrawable;
2131*4882a593Smuzhiyun         }
2132*4882a593Smuzhiyun     }
2133*4882a593Smuzhiyun 
2134*4882a593Smuzhiyun     if (!pDraw) {
2135*4882a593Smuzhiyun         dixLookupResourceByType((void **) &pGlxPixmap, drawId,
2136*4882a593Smuzhiyun                                 __glXPixmapRes, NullClient, DixUnknownAccess);
2137*4882a593Smuzhiyun         if (pGlxPixmap) {
2138*4882a593Smuzhiyun             /*
2139*4882a593Smuzhiyun              ** Drawable is a GLX pixmap.
2140*4882a593Smuzhiyun              */
2141*4882a593Smuzhiyun             pDraw = pGlxPixmap->pDraw;
2142*4882a593Smuzhiyun             from_screen = to_screen = pGlxPixmap->pScreen->myNum;
2143*4882a593Smuzhiyun         }
2144*4882a593Smuzhiyun     }
2145*4882a593Smuzhiyun 
2146*4882a593Smuzhiyun     if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1, 3)) {
2147*4882a593Smuzhiyun         dixLookupResourceByType((void **) &pGlxWindow, drawId,
2148*4882a593Smuzhiyun                                 __glXWindowRes, NullClient, DixUnknownAccess);
2149*4882a593Smuzhiyun         if (pGlxWindow) {
2150*4882a593Smuzhiyun             /*
2151*4882a593Smuzhiyun              ** Drawable is a GLXWindow.
2152*4882a593Smuzhiyun              */
2153*4882a593Smuzhiyun             pDraw = pGlxWindow->pDraw;
2154*4882a593Smuzhiyun             from_screen = to_screen = pGlxWindow->pScreen->myNum;
2155*4882a593Smuzhiyun         }
2156*4882a593Smuzhiyun     }
2157*4882a593Smuzhiyun 
2158*4882a593Smuzhiyun     if (!pDraw) {
2159*4882a593Smuzhiyun         /*
2160*4882a593Smuzhiyun          ** Drawable is neither a X window nor a GLX pixmap.
2161*4882a593Smuzhiyun          */
2162*4882a593Smuzhiyun         client->errorValue = drawId;
2163*4882a593Smuzhiyun         return __glXBadDrawable;
2164*4882a593Smuzhiyun     }
2165*4882a593Smuzhiyun 
2166*4882a593Smuzhiyun     if (tag) {
2167*4882a593Smuzhiyun         glxc = __glXLookupContextByTag(cl, tag);
2168*4882a593Smuzhiyun         if (!glxc) {
2169*4882a593Smuzhiyun             return __glXBadContextTag;
2170*4882a593Smuzhiyun         }
2171*4882a593Smuzhiyun     }
2172*4882a593Smuzhiyun 
2173*4882a593Smuzhiyun #ifdef PANORAMIX
2174*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
2175*4882a593Smuzhiyun         from_screen = 0;
2176*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
2177*4882a593Smuzhiyun         dixLookupResourceByClass((void **) &pXinDraw,
2178*4882a593Smuzhiyun                                  pDraw->id, XRC_DRAWABLE,
2179*4882a593Smuzhiyun                                  client, DixReadAccess);
2180*4882a593Smuzhiyun     }
2181*4882a593Smuzhiyun #endif
2182*4882a593Smuzhiyun 
2183*4882a593Smuzhiyun     /* If requested, send a glFinish to all back-end servers before swapping. */
2184*4882a593Smuzhiyun     if (dmxGLXFinishSwap) {
2185*4882a593Smuzhiyun         for (s = from_screen; s <= to_screen; s++) {
2186*4882a593Smuzhiyun             Display *dpy = GetBackEndDisplay(cl, s);
2187*4882a593Smuzhiyun             DMXScreenInfo *dmxScreen = &dmxScreens[s];
2188*4882a593Smuzhiyun             xGLXSingleReq *finishReq;
2189*4882a593Smuzhiyun             xGLXSingleReply reply;
2190*4882a593Smuzhiyun 
2191*4882a593Smuzhiyun #define X_GLXSingle 0           /* needed by GetReq below */
2192*4882a593Smuzhiyun 
2193*4882a593Smuzhiyun             LockDisplay(dpy);
2194*4882a593Smuzhiyun             GetReq(GLXSingle, finishReq);
2195*4882a593Smuzhiyun             finishReq->reqType = dmxScreen->glxMajorOpcode;
2196*4882a593Smuzhiyun             finishReq->glxCode = X_GLsop_Finish;
2197*4882a593Smuzhiyun             finishReq->contextTag =
2198*4882a593Smuzhiyun                 (tag ? GetCurrentBackEndTag(cl, tag, s) : 0);
2199*4882a593Smuzhiyun             (void) _XReply(dpy, (xReply *) &reply, 0, False);
2200*4882a593Smuzhiyun             UnlockDisplay(dpy);
2201*4882a593Smuzhiyun             SyncHandle();
2202*4882a593Smuzhiyun         }
2203*4882a593Smuzhiyun     }
2204*4882a593Smuzhiyun 
2205*4882a593Smuzhiyun     /* If requested, send an XSync to all back-end servers before swapping. */
2206*4882a593Smuzhiyun     if (dmxGLXSyncSwap) {
2207*4882a593Smuzhiyun         for (s = from_screen; s <= to_screen; s++)
2208*4882a593Smuzhiyun             XSync(GetBackEndDisplay(cl, s), False);
2209*4882a593Smuzhiyun     }
2210*4882a593Smuzhiyun 
2211*4882a593Smuzhiyun     /* send the SwapBuffers request to all back-end servers */
2212*4882a593Smuzhiyun 
2213*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
2214*4882a593Smuzhiyun         DMXScreenInfo *dmxScreen = &dmxScreens[s];
2215*4882a593Smuzhiyun         Display *dpy = GetBackEndDisplay(cl, s);
2216*4882a593Smuzhiyun         unsigned int be_draw = 0;
2217*4882a593Smuzhiyun 
2218*4882a593Smuzhiyun         if (pGlxPixmap) {
2219*4882a593Smuzhiyun             be_draw = (unsigned int) pGlxPixmap->be_xids[s];
2220*4882a593Smuzhiyun         }
2221*4882a593Smuzhiyun #ifdef PANORAMIX
2222*4882a593Smuzhiyun         else if (pXinDraw) {
2223*4882a593Smuzhiyun             dixLookupWindow(&pWin, pXinDraw->info[s].id, client, DixReadAccess);
2224*4882a593Smuzhiyun         }
2225*4882a593Smuzhiyun #endif
2226*4882a593Smuzhiyun         else if (pGlxWindow) {
2227*4882a593Smuzhiyun             pWin = (WindowPtr) pGlxWindow->pDraw;
2228*4882a593Smuzhiyun         }
2229*4882a593Smuzhiyun 
2230*4882a593Smuzhiyun         if (pWin && !be_draw) {
2231*4882a593Smuzhiyun             be_draw = (unsigned int) (DMX_GET_WINDOW_PRIV(pWin))->window;
2232*4882a593Smuzhiyun             if (!be_draw) {
2233*4882a593Smuzhiyun                 /* it might be that the window did not created yet on the */
2234*4882a593Smuzhiyun                 /* back-end server (lazy window creation option), force   */
2235*4882a593Smuzhiyun                 /* creation of the window */
2236*4882a593Smuzhiyun                 dmxCreateAndRealizeWindow(pWin, TRUE);
2237*4882a593Smuzhiyun                 be_draw = (unsigned int) (DMX_GET_WINDOW_PRIV(pWin))->window;
2238*4882a593Smuzhiyun             }
2239*4882a593Smuzhiyun         }
2240*4882a593Smuzhiyun 
2241*4882a593Smuzhiyun         dmxSync(dmxScreen, 1);
2242*4882a593Smuzhiyun 
2243*4882a593Smuzhiyun         LockDisplay(dpy);
2244*4882a593Smuzhiyun         GetReq(GLXSwapBuffers, be_req);
2245*4882a593Smuzhiyun         be_req->reqType = dmxScreen->glxMajorOpcode;
2246*4882a593Smuzhiyun         be_req->glxCode = X_GLXSwapBuffers;
2247*4882a593Smuzhiyun         be_req->drawable = be_draw;
2248*4882a593Smuzhiyun         be_req->contextTag = (tag ? GetCurrentBackEndTag(cl, tag, s) : 0);
2249*4882a593Smuzhiyun         UnlockDisplay(dpy);
2250*4882a593Smuzhiyun         SyncHandle();
2251*4882a593Smuzhiyun         XFlush(dpy);
2252*4882a593Smuzhiyun     }
2253*4882a593Smuzhiyun 
2254*4882a593Smuzhiyun     return Success;
2255*4882a593Smuzhiyun }
2256*4882a593Smuzhiyun 
2257*4882a593Smuzhiyun int
__glXSwapBuffers(__GLXclientState * cl,GLbyte * pc)2258*4882a593Smuzhiyun __glXSwapBuffers(__GLXclientState * cl, GLbyte * pc)
2259*4882a593Smuzhiyun {
2260*4882a593Smuzhiyun     ClientPtr client = cl->client;
2261*4882a593Smuzhiyun     DrawablePtr pDraw;
2262*4882a593Smuzhiyun     xGLXSwapBuffersReq *req = (xGLXSwapBuffersReq *) pc;
2263*4882a593Smuzhiyun     GLXContextTag tag = req->contextTag;
2264*4882a593Smuzhiyun     XID drawId = req->drawable;
2265*4882a593Smuzhiyun     __GLXpixmap *pGlxPixmap = NULL;
2266*4882a593Smuzhiyun     __GLXcontext *glxc = NULL;
2267*4882a593Smuzhiyun     __glXWindow *pGlxWindow = NULL;
2268*4882a593Smuzhiyun     int rc;
2269*4882a593Smuzhiyun 
2270*4882a593Smuzhiyun     /*
2271*4882a593Smuzhiyun      ** Check that the GLX drawable is valid.
2272*4882a593Smuzhiyun      */
2273*4882a593Smuzhiyun     rc = dixLookupDrawable(&pDraw, drawId, client, 0, DixWriteAccess);
2274*4882a593Smuzhiyun     if (rc == Success) {
2275*4882a593Smuzhiyun         if (pDraw->type != DRAWABLE_WINDOW) {
2276*4882a593Smuzhiyun             /*
2277*4882a593Smuzhiyun              ** Drawable is an X pixmap, which is not allowed.
2278*4882a593Smuzhiyun              */
2279*4882a593Smuzhiyun             client->errorValue = drawId;
2280*4882a593Smuzhiyun             return __glXBadDrawable;
2281*4882a593Smuzhiyun         }
2282*4882a593Smuzhiyun     }
2283*4882a593Smuzhiyun 
2284*4882a593Smuzhiyun     if (!pDraw) {
2285*4882a593Smuzhiyun         dixLookupResourceByType((void **) &pGlxPixmap, drawId,
2286*4882a593Smuzhiyun                                 __glXPixmapRes, NullClient, DixUnknownAccess);
2287*4882a593Smuzhiyun         if (pGlxPixmap) {
2288*4882a593Smuzhiyun             /*
2289*4882a593Smuzhiyun              ** Drawable is a GLX pixmap.
2290*4882a593Smuzhiyun              */
2291*4882a593Smuzhiyun             pDraw = pGlxPixmap->pDraw;
2292*4882a593Smuzhiyun         }
2293*4882a593Smuzhiyun     }
2294*4882a593Smuzhiyun 
2295*4882a593Smuzhiyun     if (!pDraw && __GLX_IS_VERSION_SUPPORTED(1, 3)) {
2296*4882a593Smuzhiyun         dixLookupResourceByType((void **) &pGlxWindow, drawId,
2297*4882a593Smuzhiyun                                 __glXWindowRes, NullClient, DixUnknownAccess);
2298*4882a593Smuzhiyun         if (pGlxWindow) {
2299*4882a593Smuzhiyun             /*
2300*4882a593Smuzhiyun              ** Drawable is a GLXWindow.
2301*4882a593Smuzhiyun              */
2302*4882a593Smuzhiyun             pDraw = pGlxWindow->pDraw;
2303*4882a593Smuzhiyun         }
2304*4882a593Smuzhiyun     }
2305*4882a593Smuzhiyun 
2306*4882a593Smuzhiyun     if (!pDraw) {
2307*4882a593Smuzhiyun         /*
2308*4882a593Smuzhiyun          ** Drawable is neither a X window nor a GLX pixmap.
2309*4882a593Smuzhiyun          */
2310*4882a593Smuzhiyun         client->errorValue = drawId;
2311*4882a593Smuzhiyun         return __glXBadDrawable;
2312*4882a593Smuzhiyun     }
2313*4882a593Smuzhiyun 
2314*4882a593Smuzhiyun     if (tag) {
2315*4882a593Smuzhiyun         glxc = __glXLookupContextByTag(cl, tag);
2316*4882a593Smuzhiyun         if (!glxc) {
2317*4882a593Smuzhiyun             return __glXBadContextTag;
2318*4882a593Smuzhiyun         }
2319*4882a593Smuzhiyun     }
2320*4882a593Smuzhiyun 
2321*4882a593Smuzhiyun     if (pDraw &&
2322*4882a593Smuzhiyun         pDraw->type == DRAWABLE_WINDOW &&
2323*4882a593Smuzhiyun         DMX_GET_WINDOW_PRIV((WindowPtr) pDraw)->swapGroup) {
2324*4882a593Smuzhiyun         return SGSwapBuffers(cl, drawId, tag, pDraw);
2325*4882a593Smuzhiyun     }
2326*4882a593Smuzhiyun 
2327*4882a593Smuzhiyun     return __glXDoSwapBuffers(cl, drawId, tag);
2328*4882a593Smuzhiyun }
2329*4882a593Smuzhiyun 
2330*4882a593Smuzhiyun /************************************************************************/
2331*4882a593Smuzhiyun 
2332*4882a593Smuzhiyun /*
2333*4882a593Smuzhiyun ** Render and Renderlarge are not in the GLX API.  They are used by the GLX
2334*4882a593Smuzhiyun ** client library to send batches of GL rendering commands.
2335*4882a593Smuzhiyun */
2336*4882a593Smuzhiyun 
2337*4882a593Smuzhiyun /*
2338*4882a593Smuzhiyun ** Execute all the drawing commands in a request.
2339*4882a593Smuzhiyun */
2340*4882a593Smuzhiyun int
__glXRender(__GLXclientState * cl,GLbyte * pc)2341*4882a593Smuzhiyun __glXRender(__GLXclientState * cl, GLbyte * pc)
2342*4882a593Smuzhiyun {
2343*4882a593Smuzhiyun     xGLXRenderReq *req;
2344*4882a593Smuzhiyun     xGLXRenderReq *be_req;
2345*4882a593Smuzhiyun     int size;
2346*4882a593Smuzhiyun     __GLXcontext *glxc;
2347*4882a593Smuzhiyun     int from_screen = 0;
2348*4882a593Smuzhiyun     int to_screen = 0;
2349*4882a593Smuzhiyun     int s;
2350*4882a593Smuzhiyun 
2351*4882a593Smuzhiyun     /*
2352*4882a593Smuzhiyun      ** NOTE: much of this code also appears in the byteswapping version of this
2353*4882a593Smuzhiyun      ** routine, __glXSwapRender().  Any changes made here should also be
2354*4882a593Smuzhiyun      ** duplicated there.
2355*4882a593Smuzhiyun      */
2356*4882a593Smuzhiyun 
2357*4882a593Smuzhiyun     req = (xGLXRenderReq *) pc;
2358*4882a593Smuzhiyun 
2359*4882a593Smuzhiyun     glxc = __glXLookupContextByTag(cl, req->contextTag);
2360*4882a593Smuzhiyun     if (!glxc) {
2361*4882a593Smuzhiyun         return 0;
2362*4882a593Smuzhiyun     }
2363*4882a593Smuzhiyun     from_screen = to_screen = glxc->pScreen->myNum;
2364*4882a593Smuzhiyun 
2365*4882a593Smuzhiyun #ifdef PANORAMIX
2366*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
2367*4882a593Smuzhiyun         from_screen = 0;
2368*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
2369*4882a593Smuzhiyun     }
2370*4882a593Smuzhiyun #endif
2371*4882a593Smuzhiyun 
2372*4882a593Smuzhiyun     pc += sz_xGLXRenderReq;
2373*4882a593Smuzhiyun     size = (req->length << 2) - sz_xGLXRenderReq;
2374*4882a593Smuzhiyun 
2375*4882a593Smuzhiyun     /*
2376*4882a593Smuzhiyun      * just forward the request to back-end server(s)
2377*4882a593Smuzhiyun      */
2378*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
2379*4882a593Smuzhiyun         DMXScreenInfo *dmxScreen = &dmxScreens[s];
2380*4882a593Smuzhiyun         Display *dpy = GetBackEndDisplay(cl, s);
2381*4882a593Smuzhiyun 
2382*4882a593Smuzhiyun         LockDisplay(dpy);
2383*4882a593Smuzhiyun         GetReq(GLXRender, be_req);
2384*4882a593Smuzhiyun         be_req->reqType = dmxScreen->glxMajorOpcode;
2385*4882a593Smuzhiyun         be_req->glxCode = X_GLXRender;
2386*4882a593Smuzhiyun         be_req->length = req->length;
2387*4882a593Smuzhiyun         be_req->contextTag = GetCurrentBackEndTag(cl, req->contextTag, s);
2388*4882a593Smuzhiyun         _XSend(dpy, (const char *) pc, size);
2389*4882a593Smuzhiyun         UnlockDisplay(dpy);
2390*4882a593Smuzhiyun         SyncHandle();
2391*4882a593Smuzhiyun     }
2392*4882a593Smuzhiyun 
2393*4882a593Smuzhiyun     return Success;
2394*4882a593Smuzhiyun }
2395*4882a593Smuzhiyun 
2396*4882a593Smuzhiyun /*
2397*4882a593Smuzhiyun ** Execute a large rendering request (one that spans multiple X requests).
2398*4882a593Smuzhiyun */
2399*4882a593Smuzhiyun int
__glXRenderLarge(__GLXclientState * cl,GLbyte * pc)2400*4882a593Smuzhiyun __glXRenderLarge(__GLXclientState * cl, GLbyte * pc)
2401*4882a593Smuzhiyun {
2402*4882a593Smuzhiyun     xGLXRenderLargeReq *req;
2403*4882a593Smuzhiyun     xGLXRenderLargeReq *be_req;
2404*4882a593Smuzhiyun     __GLXcontext *glxc;
2405*4882a593Smuzhiyun     int from_screen = 0;
2406*4882a593Smuzhiyun     int to_screen = 0;
2407*4882a593Smuzhiyun     int s;
2408*4882a593Smuzhiyun 
2409*4882a593Smuzhiyun     /*
2410*4882a593Smuzhiyun      ** NOTE: much of this code also appears in the byteswapping version of this
2411*4882a593Smuzhiyun      ** routine, __glXSwapRenderLarge().  Any changes made here should also be
2412*4882a593Smuzhiyun      ** duplicated there.
2413*4882a593Smuzhiyun      */
2414*4882a593Smuzhiyun 
2415*4882a593Smuzhiyun     req = (xGLXRenderLargeReq *) pc;
2416*4882a593Smuzhiyun     glxc = __glXLookupContextByTag(cl, req->contextTag);
2417*4882a593Smuzhiyun     if (!glxc) {
2418*4882a593Smuzhiyun         return 0;
2419*4882a593Smuzhiyun     }
2420*4882a593Smuzhiyun     from_screen = to_screen = glxc->pScreen->myNum;
2421*4882a593Smuzhiyun 
2422*4882a593Smuzhiyun #ifdef PANORAMIX
2423*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
2424*4882a593Smuzhiyun         from_screen = 0;
2425*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
2426*4882a593Smuzhiyun     }
2427*4882a593Smuzhiyun #endif
2428*4882a593Smuzhiyun 
2429*4882a593Smuzhiyun     pc += sz_xGLXRenderLargeReq;
2430*4882a593Smuzhiyun 
2431*4882a593Smuzhiyun     /*
2432*4882a593Smuzhiyun      * just forward the request to back-end server(s)
2433*4882a593Smuzhiyun      */
2434*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
2435*4882a593Smuzhiyun         DMXScreenInfo *dmxScreen = &dmxScreens[s];
2436*4882a593Smuzhiyun         Display *dpy = GetBackEndDisplay(cl, s);
2437*4882a593Smuzhiyun 
2438*4882a593Smuzhiyun         GetReq(GLXRenderLarge, be_req);
2439*4882a593Smuzhiyun         be_req->reqType = dmxScreen->glxMajorOpcode;
2440*4882a593Smuzhiyun         be_req->glxCode = X_GLXRenderLarge;
2441*4882a593Smuzhiyun         be_req->contextTag = GetCurrentBackEndTag(cl, req->contextTag, s);
2442*4882a593Smuzhiyun         be_req->length = req->length;
2443*4882a593Smuzhiyun         be_req->requestNumber = req->requestNumber;
2444*4882a593Smuzhiyun         be_req->requestTotal = req->requestTotal;
2445*4882a593Smuzhiyun         be_req->dataBytes = req->dataBytes;
2446*4882a593Smuzhiyun         Data(dpy, (const char *) pc, req->dataBytes);
2447*4882a593Smuzhiyun         UnlockDisplay(dpy);
2448*4882a593Smuzhiyun         SyncHandle();
2449*4882a593Smuzhiyun 
2450*4882a593Smuzhiyun     }
2451*4882a593Smuzhiyun 
2452*4882a593Smuzhiyun     return Success;
2453*4882a593Smuzhiyun }
2454*4882a593Smuzhiyun 
2455*4882a593Smuzhiyun /************************************************************************/
2456*4882a593Smuzhiyun 
2457*4882a593Smuzhiyun int
__glXVendorPrivate(__GLXclientState * cl,GLbyte * pc)2458*4882a593Smuzhiyun __glXVendorPrivate(__GLXclientState * cl, GLbyte * pc)
2459*4882a593Smuzhiyun {
2460*4882a593Smuzhiyun     xGLXVendorPrivateReq *req;
2461*4882a593Smuzhiyun 
2462*4882a593Smuzhiyun     req = (xGLXVendorPrivateReq *) pc;
2463*4882a593Smuzhiyun 
2464*4882a593Smuzhiyun     switch (req->vendorCode) {
2465*4882a593Smuzhiyun 
2466*4882a593Smuzhiyun     case X_GLvop_DeleteTexturesEXT:
2467*4882a593Smuzhiyun         return __glXVForwardSingleReq(cl, pc);
2468*4882a593Smuzhiyun         break;
2469*4882a593Smuzhiyun 
2470*4882a593Smuzhiyun     case X_GLXvop_SwapIntervalSGI:
2471*4882a593Smuzhiyun         if (glxIsExtensionSupported("SGI_swap_control")) {
2472*4882a593Smuzhiyun             return __glXVForwardSingleReq(cl, pc);
2473*4882a593Smuzhiyun         }
2474*4882a593Smuzhiyun         else {
2475*4882a593Smuzhiyun             return Success;
2476*4882a593Smuzhiyun         }
2477*4882a593Smuzhiyun         break;
2478*4882a593Smuzhiyun 
2479*4882a593Smuzhiyun #if 0                           /* glx 1.3 */
2480*4882a593Smuzhiyun     case X_GLXvop_CreateGLXVideoSourceSGIX:
2481*4882a593Smuzhiyun         break;
2482*4882a593Smuzhiyun     case X_GLXvop_DestroyGLXVideoSourceSGIX:
2483*4882a593Smuzhiyun         break;
2484*4882a593Smuzhiyun     case X_GLXvop_CreateGLXPixmapWithConfigSGIX:
2485*4882a593Smuzhiyun         break;
2486*4882a593Smuzhiyun     case X_GLXvop_DestroyGLXPbufferSGIX:
2487*4882a593Smuzhiyun         break;
2488*4882a593Smuzhiyun     case X_GLXvop_ChangeDrawableAttributesSGIX:
2489*4882a593Smuzhiyun         break;
2490*4882a593Smuzhiyun #endif
2491*4882a593Smuzhiyun 
2492*4882a593Smuzhiyun     case X_GLXvop_BindSwapBarrierSGIX:
2493*4882a593Smuzhiyun         return __glXBindSwapBarrierSGIX(cl, pc);
2494*4882a593Smuzhiyun         break;
2495*4882a593Smuzhiyun 
2496*4882a593Smuzhiyun     case X_GLXvop_JoinSwapGroupSGIX:
2497*4882a593Smuzhiyun         return __glXJoinSwapGroupSGIX(cl, pc);
2498*4882a593Smuzhiyun         break;
2499*4882a593Smuzhiyun 
2500*4882a593Smuzhiyun     case X_GLXvop_CreateContextWithConfigSGIX:
2501*4882a593Smuzhiyun         return __glXCreateContextWithConfigSGIX(cl, pc);
2502*4882a593Smuzhiyun         break;
2503*4882a593Smuzhiyun 
2504*4882a593Smuzhiyun     default:
2505*4882a593Smuzhiyun         /*
2506*4882a593Smuzhiyun          ** unsupported private request
2507*4882a593Smuzhiyun          */
2508*4882a593Smuzhiyun         cl->client->errorValue = req->vendorCode;
2509*4882a593Smuzhiyun         return __glXUnsupportedPrivateRequest;
2510*4882a593Smuzhiyun     }
2511*4882a593Smuzhiyun 
2512*4882a593Smuzhiyun     cl->client->errorValue = req->vendorCode;
2513*4882a593Smuzhiyun     return __glXUnsupportedPrivateRequest;
2514*4882a593Smuzhiyun 
2515*4882a593Smuzhiyun }
2516*4882a593Smuzhiyun 
2517*4882a593Smuzhiyun int
__glXVendorPrivateWithReply(__GLXclientState * cl,GLbyte * pc)2518*4882a593Smuzhiyun __glXVendorPrivateWithReply(__GLXclientState * cl, GLbyte * pc)
2519*4882a593Smuzhiyun {
2520*4882a593Smuzhiyun     xGLXVendorPrivateWithReplyReq *req;
2521*4882a593Smuzhiyun 
2522*4882a593Smuzhiyun     req = (xGLXVendorPrivateWithReplyReq *) pc;
2523*4882a593Smuzhiyun 
2524*4882a593Smuzhiyun     switch (req->vendorCode) {
2525*4882a593Smuzhiyun 
2526*4882a593Smuzhiyun     case X_GLvop_GetConvolutionFilterEXT:
2527*4882a593Smuzhiyun     case X_GLvop_GetConvolutionParameterfvEXT:
2528*4882a593Smuzhiyun     case X_GLvop_GetConvolutionParameterivEXT:
2529*4882a593Smuzhiyun     case X_GLvop_GetSeparableFilterEXT:
2530*4882a593Smuzhiyun     case X_GLvop_GetHistogramEXT:
2531*4882a593Smuzhiyun     case X_GLvop_GetHistogramParameterivEXT:
2532*4882a593Smuzhiyun     case X_GLvop_GetMinmaxEXT:
2533*4882a593Smuzhiyun     case X_GLvop_GetMinmaxParameterfvEXT:
2534*4882a593Smuzhiyun     case X_GLvop_GetMinmaxParameterivEXT:
2535*4882a593Smuzhiyun     case X_GLvop_AreTexturesResidentEXT:
2536*4882a593Smuzhiyun     case X_GLvop_IsTextureEXT:
2537*4882a593Smuzhiyun         return (__glXVForwardPipe0WithReply(cl, pc));
2538*4882a593Smuzhiyun         break;
2539*4882a593Smuzhiyun 
2540*4882a593Smuzhiyun     case X_GLvop_GenTexturesEXT:
2541*4882a593Smuzhiyun         return (__glXVForwardAllWithReply(cl, pc));
2542*4882a593Smuzhiyun         break;
2543*4882a593Smuzhiyun 
2544*4882a593Smuzhiyun #if 0                           /* glx1.3 */
2545*4882a593Smuzhiyun     case X_GLvop_GetDetailTexFuncSGIS:
2546*4882a593Smuzhiyun     case X_GLvop_GetSharpenTexFuncSGIS:
2547*4882a593Smuzhiyun     case X_GLvop_GetColorTableSGI:
2548*4882a593Smuzhiyun     case X_GLvop_GetColorTableParameterfvSGI:
2549*4882a593Smuzhiyun     case X_GLvop_GetColorTableParameterivSGI:
2550*4882a593Smuzhiyun     case X_GLvop_GetTexFilterFuncSGIS:
2551*4882a593Smuzhiyun     case X_GLvop_GetInstrumentsSGIX:
2552*4882a593Smuzhiyun     case X_GLvop_InstrumentsBufferSGIX:
2553*4882a593Smuzhiyun     case X_GLvop_PollInstrumentsSGIX:
2554*4882a593Smuzhiyun     case X_GLvop_FlushRasterSGIX:
2555*4882a593Smuzhiyun     case X_GLXvop_CreateGLXPbufferSGIX:
2556*4882a593Smuzhiyun     case X_GLXvop_GetDrawableAttributesSGIX:
2557*4882a593Smuzhiyun     case X_GLXvop_QueryHyperpipeNetworkSGIX:
2558*4882a593Smuzhiyun     case X_GLXvop_QueryHyperpipeConfigSGIX:
2559*4882a593Smuzhiyun     case X_GLXvop_HyperpipeConfigSGIX:
2560*4882a593Smuzhiyun     case X_GLXvop_DestroyHyperpipeConfigSGIX:
2561*4882a593Smuzhiyun #endif
2562*4882a593Smuzhiyun     case X_GLXvop_QueryMaxSwapBarriersSGIX:
2563*4882a593Smuzhiyun         return (__glXQueryMaxSwapBarriersSGIX(cl, pc));
2564*4882a593Smuzhiyun         break;
2565*4882a593Smuzhiyun 
2566*4882a593Smuzhiyun     case X_GLXvop_GetFBConfigsSGIX:
2567*4882a593Smuzhiyun         return (__glXGetFBConfigsSGIX(cl, pc));
2568*4882a593Smuzhiyun         break;
2569*4882a593Smuzhiyun 
2570*4882a593Smuzhiyun     case X_GLXvop_MakeCurrentReadSGI:
2571*4882a593Smuzhiyun         return (__glXMakeCurrentReadSGI(cl, pc));
2572*4882a593Smuzhiyun         break;
2573*4882a593Smuzhiyun 
2574*4882a593Smuzhiyun     case X_GLXvop_QueryContextInfoEXT:
2575*4882a593Smuzhiyun         return (__glXQueryContextInfoEXT(cl, pc));
2576*4882a593Smuzhiyun         break;
2577*4882a593Smuzhiyun 
2578*4882a593Smuzhiyun     default:
2579*4882a593Smuzhiyun         /*
2580*4882a593Smuzhiyun          ** unsupported private request
2581*4882a593Smuzhiyun          */
2582*4882a593Smuzhiyun         cl->client->errorValue = req->vendorCode;
2583*4882a593Smuzhiyun         return __glXUnsupportedPrivateRequest;
2584*4882a593Smuzhiyun     }
2585*4882a593Smuzhiyun 
2586*4882a593Smuzhiyun }
2587*4882a593Smuzhiyun 
2588*4882a593Smuzhiyun int
__glXQueryExtensionsString(__GLXclientState * cl,GLbyte * pc)2589*4882a593Smuzhiyun __glXQueryExtensionsString(__GLXclientState * cl, GLbyte * pc)
2590*4882a593Smuzhiyun {
2591*4882a593Smuzhiyun     ClientPtr client = cl->client;
2592*4882a593Smuzhiyun     xGLXQueryExtensionsStringReq *req = (xGLXQueryExtensionsStringReq *) pc;
2593*4882a593Smuzhiyun     xGLXQueryExtensionsStringReply reply;
2594*4882a593Smuzhiyun     GLint screen;
2595*4882a593Smuzhiyun     size_t length;
2596*4882a593Smuzhiyun     int len, numbytes;
2597*4882a593Smuzhiyun     char *be_buf;
2598*4882a593Smuzhiyun 
2599*4882a593Smuzhiyun #ifdef FWD_QUERY_REQ
2600*4882a593Smuzhiyun     xGLXQueryExtensionsStringReq *be_req;
2601*4882a593Smuzhiyun     xGLXQueryExtensionsStringReply be_reply;
2602*4882a593Smuzhiyun     DMXScreenInfo *dmxScreen;
2603*4882a593Smuzhiyun     Display *dpy;
2604*4882a593Smuzhiyun #endif
2605*4882a593Smuzhiyun 
2606*4882a593Smuzhiyun     screen = req->screen;
2607*4882a593Smuzhiyun 
2608*4882a593Smuzhiyun     /*
2609*4882a593Smuzhiyun      ** Check if screen exists.
2610*4882a593Smuzhiyun      */
2611*4882a593Smuzhiyun     if ((screen < 0) || (screen >= screenInfo.numScreens)) {
2612*4882a593Smuzhiyun         client->errorValue = screen;
2613*4882a593Smuzhiyun         return BadValue;
2614*4882a593Smuzhiyun     }
2615*4882a593Smuzhiyun 
2616*4882a593Smuzhiyun #ifdef FWD_QUERY_REQ
2617*4882a593Smuzhiyun     dmxScreen = &dmxScreens[screen];
2618*4882a593Smuzhiyun 
2619*4882a593Smuzhiyun     /* Send the glXQueryServerString request */
2620*4882a593Smuzhiyun     dpy = GetBackEndDisplay(cl, screen);
2621*4882a593Smuzhiyun     LockDisplay(dpy);
2622*4882a593Smuzhiyun     GetReq(GLXQueryExtensionsString, be_req);
2623*4882a593Smuzhiyun     be_req->reqType = dmxScreen->glxMajorOpcode;
2624*4882a593Smuzhiyun     be_req->glxCode = X_GLXQueryServerString;
2625*4882a593Smuzhiyun     be_req->screen = DefaultScreen(dpy);
2626*4882a593Smuzhiyun     _XReply(dpy, (xReply *) &be_reply, 0, False);
2627*4882a593Smuzhiyun     len = (int) be_reply.length;
2628*4882a593Smuzhiyun     numbytes = (int) be_reply.n;
2629*4882a593Smuzhiyun     be_buf = (char *) malloc(numbytes);
2630*4882a593Smuzhiyun     if (!be_buf) {
2631*4882a593Smuzhiyun         /* Throw data on the floor */
2632*4882a593Smuzhiyun         _XEatDataWords(dpy, len);
2633*4882a593Smuzhiyun     }
2634*4882a593Smuzhiyun     else {
2635*4882a593Smuzhiyun         _XReadPad(dpy, (char *) be_buf, numbytes);
2636*4882a593Smuzhiyun     }
2637*4882a593Smuzhiyun     UnlockDisplay(dpy);
2638*4882a593Smuzhiyun     SyncHandle();
2639*4882a593Smuzhiyun 
2640*4882a593Smuzhiyun #else
2641*4882a593Smuzhiyun 
2642*4882a593Smuzhiyun     be_buf = __glXGetServerString(GLX_EXTENSIONS);
2643*4882a593Smuzhiyun     numbytes = strlen(be_buf) + 1;
2644*4882a593Smuzhiyun     len = __GLX_PAD(numbytes) >> 2;
2645*4882a593Smuzhiyun 
2646*4882a593Smuzhiyun #endif
2647*4882a593Smuzhiyun 
2648*4882a593Smuzhiyun     length = len;
2649*4882a593Smuzhiyun     reply = (xGLXQueryExtensionsStringReply) {
2650*4882a593Smuzhiyun         .type = X_Reply,
2651*4882a593Smuzhiyun         .sequenceNumber = client->sequence,
2652*4882a593Smuzhiyun         .length = len,
2653*4882a593Smuzhiyun         .n = numbytes
2654*4882a593Smuzhiyun     };
2655*4882a593Smuzhiyun 
2656*4882a593Smuzhiyun     if (client->swapped) {
2657*4882a593Smuzhiyun         glxSwapQueryExtensionsStringReply(client, &reply, be_buf);
2658*4882a593Smuzhiyun     }
2659*4882a593Smuzhiyun     else {
2660*4882a593Smuzhiyun         WriteToClient(client, sz_xGLXQueryExtensionsStringReply, &reply);
2661*4882a593Smuzhiyun         WriteToClient(client, (int) (length << 2), be_buf);
2662*4882a593Smuzhiyun     }
2663*4882a593Smuzhiyun 
2664*4882a593Smuzhiyun     return Success;
2665*4882a593Smuzhiyun }
2666*4882a593Smuzhiyun 
2667*4882a593Smuzhiyun int
__glXQueryServerString(__GLXclientState * cl,GLbyte * pc)2668*4882a593Smuzhiyun __glXQueryServerString(__GLXclientState * cl, GLbyte * pc)
2669*4882a593Smuzhiyun {
2670*4882a593Smuzhiyun     ClientPtr client = cl->client;
2671*4882a593Smuzhiyun     xGLXQueryServerStringReq *req = (xGLXQueryServerStringReq *) pc;
2672*4882a593Smuzhiyun     xGLXQueryServerStringReply reply;
2673*4882a593Smuzhiyun     int name;
2674*4882a593Smuzhiyun     GLint screen;
2675*4882a593Smuzhiyun     size_t length;
2676*4882a593Smuzhiyun     int len, numbytes;
2677*4882a593Smuzhiyun     char *be_buf;
2678*4882a593Smuzhiyun 
2679*4882a593Smuzhiyun #ifdef FWD_QUERY_REQ
2680*4882a593Smuzhiyun     xGLXQueryServerStringReq *be_req;
2681*4882a593Smuzhiyun     xGLXQueryServerStringReply be_reply;
2682*4882a593Smuzhiyun     DMXScreenInfo *dmxScreen;
2683*4882a593Smuzhiyun     Display *dpy;
2684*4882a593Smuzhiyun #endif
2685*4882a593Smuzhiyun 
2686*4882a593Smuzhiyun     name = req->name;
2687*4882a593Smuzhiyun     screen = req->screen;
2688*4882a593Smuzhiyun     /*
2689*4882a593Smuzhiyun      ** Check if screen exists.
2690*4882a593Smuzhiyun      */
2691*4882a593Smuzhiyun     if ((screen < 0) || (screen >= screenInfo.numScreens)) {
2692*4882a593Smuzhiyun         client->errorValue = screen;
2693*4882a593Smuzhiyun         return BadValue;
2694*4882a593Smuzhiyun     }
2695*4882a593Smuzhiyun 
2696*4882a593Smuzhiyun #ifdef FWD_QUERY_REQ
2697*4882a593Smuzhiyun     dmxScreen = &dmxScreens[screen];
2698*4882a593Smuzhiyun 
2699*4882a593Smuzhiyun     /* Send the glXQueryServerString request */
2700*4882a593Smuzhiyun     dpy = GetBackEndDisplay(cl, screen);
2701*4882a593Smuzhiyun     LockDisplay(dpy);
2702*4882a593Smuzhiyun     GetReq(GLXQueryServerString, be_req);
2703*4882a593Smuzhiyun     be_req->reqType = dmxScreen->glxMajorOpcode;
2704*4882a593Smuzhiyun     be_req->glxCode = X_GLXQueryServerString;
2705*4882a593Smuzhiyun     be_req->screen = DefaultScreen(dpy);
2706*4882a593Smuzhiyun     be_req->name = name;
2707*4882a593Smuzhiyun     _XReply(dpy, (xReply *) &be_reply, 0, False);
2708*4882a593Smuzhiyun     len = (int) be_reply.length;
2709*4882a593Smuzhiyun     numbytes = (int) be_reply.n;
2710*4882a593Smuzhiyun     be_buf = (char *) malloc(numbytes);
2711*4882a593Smuzhiyun     if (!be_buf) {
2712*4882a593Smuzhiyun         /* Throw data on the floor */
2713*4882a593Smuzhiyun         _XEatDataWords(dpy, len);
2714*4882a593Smuzhiyun     }
2715*4882a593Smuzhiyun     else {
2716*4882a593Smuzhiyun         _XReadPad(dpy, (char *) be_buf, numbytes);
2717*4882a593Smuzhiyun     }
2718*4882a593Smuzhiyun     UnlockDisplay(dpy);
2719*4882a593Smuzhiyun     SyncHandle();
2720*4882a593Smuzhiyun 
2721*4882a593Smuzhiyun #else
2722*4882a593Smuzhiyun     be_buf = __glXGetServerString(name);
2723*4882a593Smuzhiyun     numbytes = strlen(be_buf) + 1;
2724*4882a593Smuzhiyun     len = __GLX_PAD(numbytes) >> 2;
2725*4882a593Smuzhiyun #endif
2726*4882a593Smuzhiyun 
2727*4882a593Smuzhiyun     length = len;
2728*4882a593Smuzhiyun     reply = (xGLXQueryServerStringReply) {
2729*4882a593Smuzhiyun         .type = X_Reply,
2730*4882a593Smuzhiyun         .sequenceNumber = client->sequence,
2731*4882a593Smuzhiyun         .length = length,
2732*4882a593Smuzhiyun         .n = numbytes
2733*4882a593Smuzhiyun     };
2734*4882a593Smuzhiyun 
2735*4882a593Smuzhiyun     if (client->swapped) {
2736*4882a593Smuzhiyun         glxSwapQueryServerStringReply(client, &reply, be_buf);
2737*4882a593Smuzhiyun     }
2738*4882a593Smuzhiyun     else {
2739*4882a593Smuzhiyun         WriteToClient(client, sz_xGLXQueryServerStringReply, &reply);
2740*4882a593Smuzhiyun         WriteToClient(client, (int) (length << 2), be_buf);
2741*4882a593Smuzhiyun     }
2742*4882a593Smuzhiyun 
2743*4882a593Smuzhiyun     return Success;
2744*4882a593Smuzhiyun }
2745*4882a593Smuzhiyun 
2746*4882a593Smuzhiyun int
__glXClientInfo(__GLXclientState * cl,GLbyte * pc)2747*4882a593Smuzhiyun __glXClientInfo(__GLXclientState * cl, GLbyte * pc)
2748*4882a593Smuzhiyun {
2749*4882a593Smuzhiyun     xGLXClientInfoReq *req = (xGLXClientInfoReq *) pc;
2750*4882a593Smuzhiyun     xGLXClientInfoReq *be_req;
2751*4882a593Smuzhiyun     const char *buf;
2752*4882a593Smuzhiyun     int from_screen = 0;
2753*4882a593Smuzhiyun     int to_screen = 0;
2754*4882a593Smuzhiyun     int s;
2755*4882a593Smuzhiyun 
2756*4882a593Smuzhiyun     free(cl->GLClientextensions);
2757*4882a593Smuzhiyun     buf = (const char *) (req + 1);
2758*4882a593Smuzhiyun     cl->GLClientextensions = strdup(buf);
2759*4882a593Smuzhiyun 
2760*4882a593Smuzhiyun     to_screen = screenInfo.numScreens - 1;
2761*4882a593Smuzhiyun 
2762*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
2763*4882a593Smuzhiyun         DMXScreenInfo *dmxScreen = &dmxScreens[s];
2764*4882a593Smuzhiyun         Display *dpy = GetBackEndDisplay(cl, s);
2765*4882a593Smuzhiyun 
2766*4882a593Smuzhiyun         LockDisplay(dpy);
2767*4882a593Smuzhiyun         GetReq(GLXClientInfo, be_req);
2768*4882a593Smuzhiyun         be_req->reqType = dmxScreen->glxMajorOpcode;
2769*4882a593Smuzhiyun         be_req->glxCode = X_GLXClientInfo;
2770*4882a593Smuzhiyun         be_req->major = req->major;
2771*4882a593Smuzhiyun         be_req->minor = req->minor;
2772*4882a593Smuzhiyun         be_req->length = req->length;
2773*4882a593Smuzhiyun         be_req->numbytes = req->numbytes;
2774*4882a593Smuzhiyun         Data(dpy, buf, req->numbytes);
2775*4882a593Smuzhiyun 
2776*4882a593Smuzhiyun         UnlockDisplay(dpy);
2777*4882a593Smuzhiyun         SyncHandle();
2778*4882a593Smuzhiyun     }
2779*4882a593Smuzhiyun 
2780*4882a593Smuzhiyun     return Success;
2781*4882a593Smuzhiyun }
2782*4882a593Smuzhiyun 
2783*4882a593Smuzhiyun int
__glXUseXFont(__GLXclientState * cl,GLbyte * pc)2784*4882a593Smuzhiyun __glXUseXFont(__GLXclientState * cl, GLbyte * pc)
2785*4882a593Smuzhiyun {
2786*4882a593Smuzhiyun     ClientPtr client = cl->client;
2787*4882a593Smuzhiyun     xGLXUseXFontReq *req;
2788*4882a593Smuzhiyun     xGLXUseXFontReq *be_req;
2789*4882a593Smuzhiyun     FontPtr pFont;
2790*4882a593Smuzhiyun     __GLXcontext *glxc = NULL;
2791*4882a593Smuzhiyun     int from_screen = 0;
2792*4882a593Smuzhiyun     int to_screen = 0;
2793*4882a593Smuzhiyun     int s;
2794*4882a593Smuzhiyun     dmxFontPrivPtr pFontPriv;
2795*4882a593Smuzhiyun     DMXScreenInfo *dmxScreen;
2796*4882a593Smuzhiyun     Display *dpy;
2797*4882a593Smuzhiyun 
2798*4882a593Smuzhiyun     req = (xGLXUseXFontReq *) pc;
2799*4882a593Smuzhiyun 
2800*4882a593Smuzhiyun     if (req->contextTag != 0) {
2801*4882a593Smuzhiyun         glxc = __glXLookupContextByTag(cl, req->contextTag);
2802*4882a593Smuzhiyun         if (glxc) {
2803*4882a593Smuzhiyun             from_screen = to_screen = glxc->pScreen->myNum;
2804*4882a593Smuzhiyun         }
2805*4882a593Smuzhiyun     }
2806*4882a593Smuzhiyun 
2807*4882a593Smuzhiyun     /*
2808*4882a593Smuzhiyun      ** Font can actually be either the ID of a font or the ID of a GC
2809*4882a593Smuzhiyun      ** containing a font.
2810*4882a593Smuzhiyun      */
2811*4882a593Smuzhiyun     dixLookupResourceByType((void **) &pFont, req->font, RT_FONT,
2812*4882a593Smuzhiyun                             NullClient, DixUnknownAccess);
2813*4882a593Smuzhiyun     if (!pFont) {
2814*4882a593Smuzhiyun         GC *pGC;
2815*4882a593Smuzhiyun 
2816*4882a593Smuzhiyun         dixLookupResourceByType((void **) &pGC, req->font,
2817*4882a593Smuzhiyun                                 RT_GC, NullClient, DixUnknownAccess);
2818*4882a593Smuzhiyun         if (!pGC) {
2819*4882a593Smuzhiyun             client->errorValue = req->font;
2820*4882a593Smuzhiyun             return BadFont;
2821*4882a593Smuzhiyun         }
2822*4882a593Smuzhiyun         pFont = pGC->font;
2823*4882a593Smuzhiyun     }
2824*4882a593Smuzhiyun 
2825*4882a593Smuzhiyun     pFontPriv = FontGetPrivate(pFont, dmxFontPrivateIndex);
2826*4882a593Smuzhiyun 
2827*4882a593Smuzhiyun #ifdef PANORAMIX
2828*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
2829*4882a593Smuzhiyun         from_screen = 0;
2830*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
2831*4882a593Smuzhiyun     }
2832*4882a593Smuzhiyun #endif
2833*4882a593Smuzhiyun 
2834*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
2835*4882a593Smuzhiyun         dmxScreen = &dmxScreens[s];
2836*4882a593Smuzhiyun         dpy = GetBackEndDisplay(cl, s);
2837*4882a593Smuzhiyun 
2838*4882a593Smuzhiyun         dmxSync(dmxScreen, 1);
2839*4882a593Smuzhiyun 
2840*4882a593Smuzhiyun         LockDisplay(dpy);
2841*4882a593Smuzhiyun         GetReq(GLXUseXFont, be_req);
2842*4882a593Smuzhiyun         be_req->reqType = dmxScreen->glxMajorOpcode;
2843*4882a593Smuzhiyun         be_req->glxCode = X_GLXUseXFont;
2844*4882a593Smuzhiyun         be_req->contextTag =
2845*4882a593Smuzhiyun             (glxc ? GetCurrentBackEndTag(cl, req->contextTag, s) : 0);
2846*4882a593Smuzhiyun         be_req->font = pFontPriv->font[s]->fid;
2847*4882a593Smuzhiyun         be_req->first = req->first;
2848*4882a593Smuzhiyun         be_req->count = req->count;
2849*4882a593Smuzhiyun         be_req->listBase = req->listBase;
2850*4882a593Smuzhiyun         UnlockDisplay(dpy);
2851*4882a593Smuzhiyun         SyncHandle();
2852*4882a593Smuzhiyun 
2853*4882a593Smuzhiyun         XSync(dpy, False);
2854*4882a593Smuzhiyun     }
2855*4882a593Smuzhiyun 
2856*4882a593Smuzhiyun     return Success;
2857*4882a593Smuzhiyun }
2858*4882a593Smuzhiyun 
2859*4882a593Smuzhiyun /*
2860*4882a593Smuzhiyun  * start GLX 1.3 here
2861*4882a593Smuzhiyun  */
2862*4882a593Smuzhiyun 
2863*4882a593Smuzhiyun int
__glXGetFBConfigs(__GLXclientState * cl,GLbyte * pc)2864*4882a593Smuzhiyun __glXGetFBConfigs(__GLXclientState * cl, GLbyte * pc)
2865*4882a593Smuzhiyun {
2866*4882a593Smuzhiyun     ClientPtr client = cl->client;
2867*4882a593Smuzhiyun     xGLXGetFBConfigsReq *req = (xGLXGetFBConfigsReq *) pc;
2868*4882a593Smuzhiyun     xGLXGetFBConfigsReply reply;
2869*4882a593Smuzhiyun     __GLXFBConfig *pFBConfig;
2870*4882a593Smuzhiyun     CARD32 buf[2 * __GLX_TOTAL_FBCONFIG_PROPS];
2871*4882a593Smuzhiyun     int numAttribs = __GLX_TOTAL_FBCONFIG_PROPS;
2872*4882a593Smuzhiyun     unsigned int screen = req->screen;
2873*4882a593Smuzhiyun     int numFBConfigs, i, p;
2874*4882a593Smuzhiyun     __GLXscreenInfo *pGlxScreen;
2875*4882a593Smuzhiyun 
2876*4882a593Smuzhiyun     if (screen >= screenInfo.numScreens) {
2877*4882a593Smuzhiyun         /* The client library must send a valid screen number. */
2878*4882a593Smuzhiyun         client->errorValue = screen;
2879*4882a593Smuzhiyun         return BadValue;
2880*4882a593Smuzhiyun     }
2881*4882a593Smuzhiyun 
2882*4882a593Smuzhiyun     pGlxScreen = &__glXActiveScreens[screen];
2883*4882a593Smuzhiyun     numFBConfigs = __glXNumFBConfigs;
2884*4882a593Smuzhiyun 
2885*4882a593Smuzhiyun     reply = (xGLXGetFBConfigsReply) {
2886*4882a593Smuzhiyun         .type = X_Reply,
2887*4882a593Smuzhiyun         .sequenceNumber = client->sequence,
2888*4882a593Smuzhiyun         .length = (numFBConfigs * 2 * numAttribs * __GLX_SIZE_CARD32) >> 2,
2889*4882a593Smuzhiyun         .numFBConfigs = numFBConfigs,
2890*4882a593Smuzhiyun         .numAttribs = numAttribs
2891*4882a593Smuzhiyun     };
2892*4882a593Smuzhiyun 
2893*4882a593Smuzhiyun     if (client->swapped) {
2894*4882a593Smuzhiyun         __GLX_DECLARE_SWAP_VARIABLES;
2895*4882a593Smuzhiyun         __GLX_SWAP_SHORT(&reply.sequenceNumber);
2896*4882a593Smuzhiyun         __GLX_SWAP_INT(&reply.length);
2897*4882a593Smuzhiyun         __GLX_SWAP_INT(&reply.numFBConfigs);
2898*4882a593Smuzhiyun         __GLX_SWAP_INT(&reply.numAttribs);
2899*4882a593Smuzhiyun     }
2900*4882a593Smuzhiyun     WriteToClient(client, sz_xGLXGetFBConfigsReply, &reply);
2901*4882a593Smuzhiyun 
2902*4882a593Smuzhiyun     for (i = 0; i < numFBConfigs; i++) {
2903*4882a593Smuzhiyun         int associatedVisualId = 0;
2904*4882a593Smuzhiyun         int drawableTypeIndex;
2905*4882a593Smuzhiyun 
2906*4882a593Smuzhiyun         pFBConfig = __glXFBConfigs[i * (screenInfo.numScreens + 1)];
2907*4882a593Smuzhiyun 
2908*4882a593Smuzhiyun         p = 0;
2909*4882a593Smuzhiyun         /* core attributes */
2910*4882a593Smuzhiyun         buf[p++] = GLX_FBCONFIG_ID;
2911*4882a593Smuzhiyun         buf[p++] = pFBConfig->id;
2912*4882a593Smuzhiyun         buf[p++] = GLX_BUFFER_SIZE;
2913*4882a593Smuzhiyun         buf[p++] = pFBConfig->indexBits;
2914*4882a593Smuzhiyun         buf[p++] = GLX_LEVEL;
2915*4882a593Smuzhiyun         buf[p++] = pFBConfig->level;
2916*4882a593Smuzhiyun         buf[p++] = GLX_DOUBLEBUFFER;
2917*4882a593Smuzhiyun         buf[p++] = pFBConfig->doubleBufferMode;
2918*4882a593Smuzhiyun         buf[p++] = GLX_STEREO;
2919*4882a593Smuzhiyun         buf[p++] = pFBConfig->stereoMode;
2920*4882a593Smuzhiyun         buf[p++] = GLX_AUX_BUFFERS;
2921*4882a593Smuzhiyun         buf[p++] = pFBConfig->maxAuxBuffers;
2922*4882a593Smuzhiyun         buf[p++] = GLX_RED_SIZE;
2923*4882a593Smuzhiyun         buf[p++] = pFBConfig->redBits;
2924*4882a593Smuzhiyun         buf[p++] = GLX_GREEN_SIZE;
2925*4882a593Smuzhiyun         buf[p++] = pFBConfig->greenBits;
2926*4882a593Smuzhiyun         buf[p++] = GLX_BLUE_SIZE;
2927*4882a593Smuzhiyun         buf[p++] = pFBConfig->blueBits;
2928*4882a593Smuzhiyun         buf[p++] = GLX_ALPHA_SIZE;
2929*4882a593Smuzhiyun         buf[p++] = pFBConfig->alphaBits;
2930*4882a593Smuzhiyun         buf[p++] = GLX_DEPTH_SIZE;
2931*4882a593Smuzhiyun         buf[p++] = pFBConfig->depthBits;
2932*4882a593Smuzhiyun         buf[p++] = GLX_STENCIL_SIZE;
2933*4882a593Smuzhiyun         buf[p++] = pFBConfig->stencilBits;
2934*4882a593Smuzhiyun         buf[p++] = GLX_ACCUM_RED_SIZE;
2935*4882a593Smuzhiyun         buf[p++] = pFBConfig->accumRedBits;
2936*4882a593Smuzhiyun         buf[p++] = GLX_ACCUM_GREEN_SIZE;
2937*4882a593Smuzhiyun         buf[p++] = pFBConfig->accumGreenBits;
2938*4882a593Smuzhiyun         buf[p++] = GLX_ACCUM_BLUE_SIZE;
2939*4882a593Smuzhiyun         buf[p++] = pFBConfig->accumBlueBits;
2940*4882a593Smuzhiyun         buf[p++] = GLX_ACCUM_ALPHA_SIZE;
2941*4882a593Smuzhiyun         buf[p++] = pFBConfig->accumAlphaBits;
2942*4882a593Smuzhiyun         buf[p++] = GLX_RENDER_TYPE;
2943*4882a593Smuzhiyun         buf[p++] = pFBConfig->renderType;
2944*4882a593Smuzhiyun         buf[p++] = GLX_DRAWABLE_TYPE;
2945*4882a593Smuzhiyun         drawableTypeIndex = p;
2946*4882a593Smuzhiyun         buf[p++] = pFBConfig->drawableType;
2947*4882a593Smuzhiyun         buf[p++] = GLX_X_VISUAL_TYPE;
2948*4882a593Smuzhiyun         buf[p++] = pFBConfig->visualType;
2949*4882a593Smuzhiyun         buf[p++] = GLX_CONFIG_CAVEAT;
2950*4882a593Smuzhiyun         buf[p++] = pFBConfig->visualCaveat;
2951*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_TYPE;
2952*4882a593Smuzhiyun         buf[p++] = pFBConfig->transparentType;
2953*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_RED_VALUE;
2954*4882a593Smuzhiyun         buf[p++] = pFBConfig->transparentRed;
2955*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_GREEN_VALUE;
2956*4882a593Smuzhiyun         buf[p++] = pFBConfig->transparentGreen;
2957*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_BLUE_VALUE;
2958*4882a593Smuzhiyun         buf[p++] = pFBConfig->transparentBlue;
2959*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_ALPHA_VALUE;
2960*4882a593Smuzhiyun         buf[p++] = pFBConfig->transparentAlpha;
2961*4882a593Smuzhiyun         buf[p++] = GLX_TRANSPARENT_INDEX_VALUE;
2962*4882a593Smuzhiyun         buf[p++] = pFBConfig->transparentIndex;
2963*4882a593Smuzhiyun         buf[p++] = GLX_MAX_PBUFFER_WIDTH;
2964*4882a593Smuzhiyun         buf[p++] = pFBConfig->maxPbufferWidth;
2965*4882a593Smuzhiyun         buf[p++] = GLX_MAX_PBUFFER_HEIGHT;
2966*4882a593Smuzhiyun         buf[p++] = pFBConfig->maxPbufferHeight;
2967*4882a593Smuzhiyun         buf[p++] = GLX_MAX_PBUFFER_PIXELS;
2968*4882a593Smuzhiyun         buf[p++] = pFBConfig->maxPbufferPixels;
2969*4882a593Smuzhiyun 
2970*4882a593Smuzhiyun         /*
2971*4882a593Smuzhiyun          * find the visual of the back-end server and match a visual
2972*4882a593Smuzhiyun          * on the proxy.
2973*4882a593Smuzhiyun          * do only once - if a visual is not yet associated.
2974*4882a593Smuzhiyun          */
2975*4882a593Smuzhiyun         if (pFBConfig->associatedVisualId == (unsigned int) -1) {
2976*4882a593Smuzhiyun             DMXScreenInfo *dmxScreen = &dmxScreens[screen];
2977*4882a593Smuzhiyun             __GLXFBConfig *be_pFBConfig =
2978*4882a593Smuzhiyun                 __glXFBConfigs[i * (screenInfo.numScreens + 1) + screen + 1];
2979*4882a593Smuzhiyun             __GLXvisualConfig *pGlxVisual = NULL;
2980*4882a593Smuzhiyun             int v;
2981*4882a593Smuzhiyun             int found = 0;
2982*4882a593Smuzhiyun 
2983*4882a593Smuzhiyun             for (v = 0; v < dmxScreen->numGlxVisuals; v++) {
2984*4882a593Smuzhiyun                 if (dmxScreen->glxVisuals[v].vid ==
2985*4882a593Smuzhiyun                     be_pFBConfig->associatedVisualId) {
2986*4882a593Smuzhiyun                     pGlxVisual = &dmxScreen->glxVisuals[v];
2987*4882a593Smuzhiyun                     break;
2988*4882a593Smuzhiyun                 }
2989*4882a593Smuzhiyun             }
2990*4882a593Smuzhiyun 
2991*4882a593Smuzhiyun             if (pGlxVisual) {
2992*4882a593Smuzhiyun                 for (v = 0; v < pGlxScreen->numVisuals; v++) {
2993*4882a593Smuzhiyun                     if (glxVisualsMatch(&pGlxScreen->pGlxVisual[v], pGlxVisual)) {
2994*4882a593Smuzhiyun                         associatedVisualId = pGlxScreen->pGlxVisual[v].vid;
2995*4882a593Smuzhiyun                         found = 1;
2996*4882a593Smuzhiyun                         break;
2997*4882a593Smuzhiyun                     }
2998*4882a593Smuzhiyun                 }
2999*4882a593Smuzhiyun             }
3000*4882a593Smuzhiyun 
3001*4882a593Smuzhiyun             if (!found) {
3002*4882a593Smuzhiyun                 associatedVisualId = 0;
3003*4882a593Smuzhiyun                 pFBConfig->drawableType &= ~(GLX_WINDOW_BIT);
3004*4882a593Smuzhiyun                 buf[drawableTypeIndex] = pFBConfig->drawableType;
3005*4882a593Smuzhiyun             }
3006*4882a593Smuzhiyun #ifdef PANORAMIX
3007*4882a593Smuzhiyun             else if (!noPanoramiXExtension) {
3008*4882a593Smuzhiyun                 /* convert the associated visualId to the panoramix one */
3009*4882a593Smuzhiyun                 pFBConfig->associatedVisualId =
3010*4882a593Smuzhiyun                     PanoramiXTranslateVisualID(screen, v);
3011*4882a593Smuzhiyun             }
3012*4882a593Smuzhiyun #endif
3013*4882a593Smuzhiyun         }
3014*4882a593Smuzhiyun         else {
3015*4882a593Smuzhiyun             associatedVisualId = pFBConfig->associatedVisualId;
3016*4882a593Smuzhiyun         }
3017*4882a593Smuzhiyun 
3018*4882a593Smuzhiyun         buf[p++] = GLX_VISUAL_ID;
3019*4882a593Smuzhiyun         buf[p++] = associatedVisualId;
3020*4882a593Smuzhiyun 
3021*4882a593Smuzhiyun         /* SGIS_multisample attributes */
3022*4882a593Smuzhiyun         buf[p++] = GLX_SAMPLES_SGIS;
3023*4882a593Smuzhiyun         buf[p++] = pFBConfig->multiSampleSize;
3024*4882a593Smuzhiyun         buf[p++] = GLX_SAMPLE_BUFFERS_SGIS;
3025*4882a593Smuzhiyun         buf[p++] = pFBConfig->nMultiSampleBuffers;
3026*4882a593Smuzhiyun 
3027*4882a593Smuzhiyun         /* SGIX_pbuffer specific attributes */
3028*4882a593Smuzhiyun         buf[p++] = GLX_OPTIMAL_PBUFFER_WIDTH_SGIX;
3029*4882a593Smuzhiyun         buf[p++] = pFBConfig->optimalPbufferWidth;
3030*4882a593Smuzhiyun         buf[p++] = GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX;
3031*4882a593Smuzhiyun         buf[p++] = pFBConfig->optimalPbufferHeight;
3032*4882a593Smuzhiyun 
3033*4882a593Smuzhiyun         buf[p++] = GLX_VISUAL_SELECT_GROUP_SGIX;
3034*4882a593Smuzhiyun         buf[p++] = pFBConfig->visualSelectGroup;
3035*4882a593Smuzhiyun 
3036*4882a593Smuzhiyun         if (client->swapped) {
3037*4882a593Smuzhiyun             __GLX_DECLARE_SWAP_VARIABLES;
3038*4882a593Smuzhiyun             __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
3039*4882a593Smuzhiyun             __GLX_SWAP_INT_ARRAY((int *) buf, 2 * numAttribs);
3040*4882a593Smuzhiyun         }
3041*4882a593Smuzhiyun         WriteToClient(client, 2 * numAttribs * __GLX_SIZE_CARD32, buf);
3042*4882a593Smuzhiyun     }
3043*4882a593Smuzhiyun     return Success;
3044*4882a593Smuzhiyun }
3045*4882a593Smuzhiyun 
3046*4882a593Smuzhiyun int
__glXGetFBConfigsSGIX(__GLXclientState * cl,GLbyte * pc)3047*4882a593Smuzhiyun __glXGetFBConfigsSGIX(__GLXclientState * cl, GLbyte * pc)
3048*4882a593Smuzhiyun {
3049*4882a593Smuzhiyun     xGLXGetFBConfigsSGIXReq *req = (xGLXGetFBConfigsSGIXReq *) pc;
3050*4882a593Smuzhiyun     xGLXGetFBConfigsReq new_req;
3051*4882a593Smuzhiyun 
3052*4882a593Smuzhiyun     new_req.reqType = req->reqType;
3053*4882a593Smuzhiyun     new_req.glxCode = req->glxCode;
3054*4882a593Smuzhiyun     new_req.length = req->length;
3055*4882a593Smuzhiyun     new_req.screen = req->screen;
3056*4882a593Smuzhiyun 
3057*4882a593Smuzhiyun     return (__glXGetFBConfigs(cl, (GLbyte *) &new_req));
3058*4882a593Smuzhiyun }
3059*4882a593Smuzhiyun 
3060*4882a593Smuzhiyun int
__glXCreateWindow(__GLXclientState * cl,GLbyte * pc)3061*4882a593Smuzhiyun __glXCreateWindow(__GLXclientState * cl, GLbyte * pc)
3062*4882a593Smuzhiyun {
3063*4882a593Smuzhiyun     ClientPtr client = cl->client;
3064*4882a593Smuzhiyun     xGLXCreateWindowReq *req = (xGLXCreateWindowReq *) pc;
3065*4882a593Smuzhiyun     int screen = req->screen;
3066*4882a593Smuzhiyun     GLXFBConfigID fbconfigId = req->fbconfig;
3067*4882a593Smuzhiyun     XID windowId = req->window;
3068*4882a593Smuzhiyun     XID glxwindowId = req->glxwindow;
3069*4882a593Smuzhiyun     DrawablePtr pDraw;
3070*4882a593Smuzhiyun     ScreenPtr pScreen;
3071*4882a593Smuzhiyun     __glXWindow *pGlxWindow;
3072*4882a593Smuzhiyun     __GLXFBConfig *pGlxFBConfig = NULL;
3073*4882a593Smuzhiyun     VisualPtr pVisual;
3074*4882a593Smuzhiyun     VisualID visId;
3075*4882a593Smuzhiyun     int i, rc;
3076*4882a593Smuzhiyun     void *val;
3077*4882a593Smuzhiyun 
3078*4882a593Smuzhiyun     /*
3079*4882a593Smuzhiyun      ** Check if windowId is valid
3080*4882a593Smuzhiyun      */
3081*4882a593Smuzhiyun     rc = dixLookupDrawable(&pDraw, windowId, client, M_DRAWABLE_WINDOW,
3082*4882a593Smuzhiyun                            DixAddAccess);
3083*4882a593Smuzhiyun     if (rc != Success)
3084*4882a593Smuzhiyun         return rc;
3085*4882a593Smuzhiyun 
3086*4882a593Smuzhiyun     /*
3087*4882a593Smuzhiyun      ** Check if screen of window matches screen of fbconfig.
3088*4882a593Smuzhiyun      */
3089*4882a593Smuzhiyun     pScreen = pDraw->pScreen;
3090*4882a593Smuzhiyun     if (screen != pScreen->myNum) {
3091*4882a593Smuzhiyun         return BadMatch;
3092*4882a593Smuzhiyun     }
3093*4882a593Smuzhiyun 
3094*4882a593Smuzhiyun     /*
3095*4882a593Smuzhiyun      ** Find the FBConfigRec for this fbconfigid.
3096*4882a593Smuzhiyun      */
3097*4882a593Smuzhiyun     if (!(pGlxFBConfig = glxLookupFBConfig(fbconfigId))) {
3098*4882a593Smuzhiyun         client->errorValue = fbconfigId;
3099*4882a593Smuzhiyun         return __glXBadFBConfig;
3100*4882a593Smuzhiyun     }
3101*4882a593Smuzhiyun     visId = pGlxFBConfig->associatedVisualId;
3102*4882a593Smuzhiyun 
3103*4882a593Smuzhiyun     /*
3104*4882a593Smuzhiyun      ** Check if the fbconfig supports rendering to windows
3105*4882a593Smuzhiyun      */
3106*4882a593Smuzhiyun     if (!(pGlxFBConfig->drawableType & GLX_WINDOW_BIT)) {
3107*4882a593Smuzhiyun         return BadMatch;
3108*4882a593Smuzhiyun     }
3109*4882a593Smuzhiyun 
3110*4882a593Smuzhiyun     if (visId != None) {
3111*4882a593Smuzhiyun         /*
3112*4882a593Smuzhiyun          ** Check if the visual ID is valid for this screen.
3113*4882a593Smuzhiyun          */
3114*4882a593Smuzhiyun         pVisual = pScreen->visuals;
3115*4882a593Smuzhiyun         for (i = 0; i < pScreen->numVisuals; i++, pVisual++) {
3116*4882a593Smuzhiyun             if (pVisual->vid == visId) {
3117*4882a593Smuzhiyun                 break;
3118*4882a593Smuzhiyun             }
3119*4882a593Smuzhiyun         }
3120*4882a593Smuzhiyun         if (i == pScreen->numVisuals) {
3121*4882a593Smuzhiyun             client->errorValue = visId;
3122*4882a593Smuzhiyun             return BadValue;
3123*4882a593Smuzhiyun         }
3124*4882a593Smuzhiyun 
3125*4882a593Smuzhiyun         /*
3126*4882a593Smuzhiyun          ** Check if color buffer depth of fbconfig matches depth
3127*4882a593Smuzhiyun          ** of window.
3128*4882a593Smuzhiyun          */
3129*4882a593Smuzhiyun         if (pVisual->nplanes != pDraw->depth) {
3130*4882a593Smuzhiyun             return BadMatch;
3131*4882a593Smuzhiyun         }
3132*4882a593Smuzhiyun     }
3133*4882a593Smuzhiyun     else
3134*4882a593Smuzhiyun         /*
3135*4882a593Smuzhiyun          ** The window was created with no visual that corresponds
3136*4882a593Smuzhiyun          ** to fbconfig
3137*4882a593Smuzhiyun          */
3138*4882a593Smuzhiyun         return BadMatch;
3139*4882a593Smuzhiyun 
3140*4882a593Smuzhiyun     /*
3141*4882a593Smuzhiyun      ** Check if there is already a fbconfig associated with this window
3142*4882a593Smuzhiyun      */
3143*4882a593Smuzhiyun     if (Success == dixLookupResourceByType(&val,
3144*4882a593Smuzhiyun                                            glxwindowId, __glXWindowRes,
3145*4882a593Smuzhiyun                                            NullClient, DixUnknownAccess)) {
3146*4882a593Smuzhiyun         client->errorValue = glxwindowId;
3147*4882a593Smuzhiyun         return BadAlloc;
3148*4882a593Smuzhiyun     }
3149*4882a593Smuzhiyun 
3150*4882a593Smuzhiyun     pGlxWindow = (__glXWindow *) malloc(sizeof(__glXWindow));
3151*4882a593Smuzhiyun     if (!pGlxWindow) {
3152*4882a593Smuzhiyun         return BadAlloc;
3153*4882a593Smuzhiyun     }
3154*4882a593Smuzhiyun 
3155*4882a593Smuzhiyun     /*
3156*4882a593Smuzhiyun      ** Register this GLX window as a resource
3157*4882a593Smuzhiyun      */
3158*4882a593Smuzhiyun     if (!(AddResource(glxwindowId, __glXWindowRes, pGlxWindow))) {
3159*4882a593Smuzhiyun         return BadAlloc;
3160*4882a593Smuzhiyun     }
3161*4882a593Smuzhiyun 
3162*4882a593Smuzhiyun     pGlxWindow->pDraw = pDraw;
3163*4882a593Smuzhiyun     pGlxWindow->type = GLX_GLXWINDOW_TYPE;
3164*4882a593Smuzhiyun     pGlxWindow->idExists = True;
3165*4882a593Smuzhiyun     pGlxWindow->refcnt = 0;
3166*4882a593Smuzhiyun     pGlxWindow->pGlxFBConfig = pGlxFBConfig;
3167*4882a593Smuzhiyun     pGlxWindow->pScreen = pScreen;
3168*4882a593Smuzhiyun 
3169*4882a593Smuzhiyun     return Success;
3170*4882a593Smuzhiyun }
3171*4882a593Smuzhiyun 
3172*4882a593Smuzhiyun int
__glXDestroyWindow(__GLXclientState * cl,GLbyte * pc)3173*4882a593Smuzhiyun __glXDestroyWindow(__GLXclientState * cl, GLbyte * pc)
3174*4882a593Smuzhiyun {
3175*4882a593Smuzhiyun     ClientPtr client = cl->client;
3176*4882a593Smuzhiyun     xGLXDestroyWindowReq *req = (xGLXDestroyWindowReq *) pc;
3177*4882a593Smuzhiyun     XID glxwindow = req->glxwindow;
3178*4882a593Smuzhiyun     void *val;
3179*4882a593Smuzhiyun 
3180*4882a593Smuzhiyun     /*
3181*4882a593Smuzhiyun      ** Check if it's a valid GLX window.
3182*4882a593Smuzhiyun      */
3183*4882a593Smuzhiyun     if (Success != dixLookupResourceByType(&val,
3184*4882a593Smuzhiyun                                            glxwindow, __glXWindowRes,
3185*4882a593Smuzhiyun                                            NullClient, DixUnknownAccess)) {
3186*4882a593Smuzhiyun         client->errorValue = glxwindow;
3187*4882a593Smuzhiyun         return __glXBadDrawable;
3188*4882a593Smuzhiyun     }
3189*4882a593Smuzhiyun     /*
3190*4882a593Smuzhiyun      ** The glx window destructor will check whether it's current before
3191*4882a593Smuzhiyun      ** freeing anything.
3192*4882a593Smuzhiyun      */
3193*4882a593Smuzhiyun     FreeResource(glxwindow, RT_NONE);
3194*4882a593Smuzhiyun 
3195*4882a593Smuzhiyun     return Success;
3196*4882a593Smuzhiyun }
3197*4882a593Smuzhiyun 
3198*4882a593Smuzhiyun int
__glXQueryContext(__GLXclientState * cl,GLbyte * pc)3199*4882a593Smuzhiyun __glXQueryContext(__GLXclientState * cl, GLbyte * pc)
3200*4882a593Smuzhiyun {
3201*4882a593Smuzhiyun     ClientPtr client = cl->client;
3202*4882a593Smuzhiyun     __GLXcontext *ctx;
3203*4882a593Smuzhiyun     xGLXQueryContextReq *req;
3204*4882a593Smuzhiyun     xGLXQueryContextReply reply;
3205*4882a593Smuzhiyun     int nProps;
3206*4882a593Smuzhiyun     int *sendBuf, *pSendBuf;
3207*4882a593Smuzhiyun     int nReplyBytes;
3208*4882a593Smuzhiyun 
3209*4882a593Smuzhiyun     req = (xGLXQueryContextReq *) pc;
3210*4882a593Smuzhiyun     dixLookupResourceByType((void **) &ctx, req->context, __glXContextRes,
3211*4882a593Smuzhiyun                             NullClient, DixUnknownAccess);
3212*4882a593Smuzhiyun     if (!ctx) {
3213*4882a593Smuzhiyun         client->errorValue = req->context;
3214*4882a593Smuzhiyun         return __glXBadContext;
3215*4882a593Smuzhiyun     }
3216*4882a593Smuzhiyun 
3217*4882a593Smuzhiyun     nProps = 3;
3218*4882a593Smuzhiyun 
3219*4882a593Smuzhiyun     reply = (xGLXQueryContextReply) {
3220*4882a593Smuzhiyun         .type = X_Reply,
3221*4882a593Smuzhiyun         .sequenceNumber = client->sequence,
3222*4882a593Smuzhiyun         .length = nProps << 1,
3223*4882a593Smuzhiyun         .n = nProps
3224*4882a593Smuzhiyun     };
3225*4882a593Smuzhiyun 
3226*4882a593Smuzhiyun     nReplyBytes = reply.length << 2;
3227*4882a593Smuzhiyun     sendBuf = (int *) malloc(nReplyBytes);
3228*4882a593Smuzhiyun     pSendBuf = sendBuf;
3229*4882a593Smuzhiyun     *pSendBuf++ = GLX_FBCONFIG_ID;
3230*4882a593Smuzhiyun     *pSendBuf++ = (int) (ctx->pFBConfig->id);
3231*4882a593Smuzhiyun     *pSendBuf++ = GLX_RENDER_TYPE;
3232*4882a593Smuzhiyun     *pSendBuf++ = renderTypeBitsToRenderTypeEnum(ctx->pFBConfig->renderType);
3233*4882a593Smuzhiyun     *pSendBuf++ = GLX_SCREEN;
3234*4882a593Smuzhiyun     *pSendBuf++ = (int) (ctx->pScreen->myNum);
3235*4882a593Smuzhiyun 
3236*4882a593Smuzhiyun     if (client->swapped) {
3237*4882a593Smuzhiyun         __glXSwapQueryContextReply(client, &reply, sendBuf);
3238*4882a593Smuzhiyun     }
3239*4882a593Smuzhiyun     else {
3240*4882a593Smuzhiyun         WriteToClient(client, sz_xGLXQueryContextReply, &reply);
3241*4882a593Smuzhiyun         WriteToClient(client, nReplyBytes, sendBuf);
3242*4882a593Smuzhiyun     }
3243*4882a593Smuzhiyun     free((char *) sendBuf);
3244*4882a593Smuzhiyun 
3245*4882a593Smuzhiyun     return Success;
3246*4882a593Smuzhiyun }
3247*4882a593Smuzhiyun 
3248*4882a593Smuzhiyun int
__glXQueryContextInfoEXT(__GLXclientState * cl,GLbyte * pc)3249*4882a593Smuzhiyun __glXQueryContextInfoEXT(__GLXclientState * cl, GLbyte * pc)
3250*4882a593Smuzhiyun {
3251*4882a593Smuzhiyun     ClientPtr client = cl->client;
3252*4882a593Smuzhiyun     __GLXcontext *ctx;
3253*4882a593Smuzhiyun     xGLXQueryContextInfoEXTReq *req;
3254*4882a593Smuzhiyun     xGLXQueryContextInfoEXTReply reply;
3255*4882a593Smuzhiyun     int nProps;
3256*4882a593Smuzhiyun     int *sendBuf, *pSendBuf;
3257*4882a593Smuzhiyun     int nReplyBytes;
3258*4882a593Smuzhiyun 
3259*4882a593Smuzhiyun     req = (xGLXQueryContextInfoEXTReq *) pc;
3260*4882a593Smuzhiyun     dixLookupResourceByType((void **) &ctx,
3261*4882a593Smuzhiyun                             req->context, __glXContextRes,
3262*4882a593Smuzhiyun                             client, DixReadAccess);
3263*4882a593Smuzhiyun 
3264*4882a593Smuzhiyun     if (!ctx) {
3265*4882a593Smuzhiyun         client->errorValue = req->context;
3266*4882a593Smuzhiyun         return __glXBadContext;
3267*4882a593Smuzhiyun     }
3268*4882a593Smuzhiyun 
3269*4882a593Smuzhiyun     nProps = 4;
3270*4882a593Smuzhiyun 
3271*4882a593Smuzhiyun     reply = (xGLXQueryContextInfoEXTReply) {
3272*4882a593Smuzhiyun         .type = X_Reply,
3273*4882a593Smuzhiyun         .sequenceNumber = client->sequence,
3274*4882a593Smuzhiyun         .length = nProps << 1,
3275*4882a593Smuzhiyun         .n = nProps
3276*4882a593Smuzhiyun     };
3277*4882a593Smuzhiyun 
3278*4882a593Smuzhiyun     nReplyBytes = reply.length << 2;
3279*4882a593Smuzhiyun     sendBuf = (int *) malloc(nReplyBytes);
3280*4882a593Smuzhiyun     pSendBuf = sendBuf;
3281*4882a593Smuzhiyun     *pSendBuf++ = GLX_SHARE_CONTEXT_EXT;
3282*4882a593Smuzhiyun     *pSendBuf++ = (int) (ctx->share_id);
3283*4882a593Smuzhiyun     *pSendBuf++ = GLX_VISUAL_ID_EXT;
3284*4882a593Smuzhiyun     *pSendBuf++ = (int) (ctx->pVisual ? ctx->pVisual->vid : 0);
3285*4882a593Smuzhiyun     *pSendBuf++ = GLX_SCREEN_EXT;
3286*4882a593Smuzhiyun     *pSendBuf++ = (int) (ctx->pScreen->myNum);
3287*4882a593Smuzhiyun     *pSendBuf++ = GLX_FBCONFIG_ID;
3288*4882a593Smuzhiyun     *pSendBuf++ = (int) (ctx->pFBConfig ? ctx->pFBConfig->id : 0);
3289*4882a593Smuzhiyun 
3290*4882a593Smuzhiyun     if (client->swapped) {
3291*4882a593Smuzhiyun         __glXSwapQueryContextInfoEXTReply(client, &reply, sendBuf);
3292*4882a593Smuzhiyun     }
3293*4882a593Smuzhiyun     else {
3294*4882a593Smuzhiyun         WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, &reply);
3295*4882a593Smuzhiyun         WriteToClient(client, nReplyBytes, sendBuf);
3296*4882a593Smuzhiyun     }
3297*4882a593Smuzhiyun     free((char *) sendBuf);
3298*4882a593Smuzhiyun 
3299*4882a593Smuzhiyun     return Success;
3300*4882a593Smuzhiyun }
3301*4882a593Smuzhiyun 
3302*4882a593Smuzhiyun int
__glXCreatePbuffer(__GLXclientState * cl,GLbyte * pc)3303*4882a593Smuzhiyun __glXCreatePbuffer(__GLXclientState * cl, GLbyte * pc)
3304*4882a593Smuzhiyun {
3305*4882a593Smuzhiyun     ClientPtr client = cl->client;
3306*4882a593Smuzhiyun     xGLXCreatePbufferReq *req = (xGLXCreatePbufferReq *) pc;
3307*4882a593Smuzhiyun     xGLXCreatePbufferReq *be_req;
3308*4882a593Smuzhiyun     int screen = req->screen;
3309*4882a593Smuzhiyun     GLXFBConfigID fbconfigId = req->fbconfig;
3310*4882a593Smuzhiyun     GLXPbuffer pbuffer = req->pbuffer;
3311*4882a593Smuzhiyun     __glXPbuffer *pGlxPbuffer;
3312*4882a593Smuzhiyun     int numAttribs = req->numAttribs;
3313*4882a593Smuzhiyun     int *attr;
3314*4882a593Smuzhiyun     ScreenPtr pScreen;
3315*4882a593Smuzhiyun     __GLXFBConfig *pGlxFBConfig;
3316*4882a593Smuzhiyun     __GLXFBConfig *be_pGlxFBConfig;
3317*4882a593Smuzhiyun     XID be_xid;
3318*4882a593Smuzhiyun     Display *dpy;
3319*4882a593Smuzhiyun     DMXScreenInfo *dmxScreen;
3320*4882a593Smuzhiyun     int s;
3321*4882a593Smuzhiyun     int from_screen, to_screen;
3322*4882a593Smuzhiyun 
3323*4882a593Smuzhiyun     /*
3324*4882a593Smuzhiyun      ** Look up screen and FBConfig.
3325*4882a593Smuzhiyun      */
3326*4882a593Smuzhiyun     if (screen >= screenInfo.numScreens) {
3327*4882a593Smuzhiyun         /* The client library must send a valid screen number. */
3328*4882a593Smuzhiyun         client->errorValue = screen;
3329*4882a593Smuzhiyun         return BadValue;
3330*4882a593Smuzhiyun     }
3331*4882a593Smuzhiyun     pScreen = screenInfo.screens[screen];
3332*4882a593Smuzhiyun 
3333*4882a593Smuzhiyun     /*
3334*4882a593Smuzhiyun      ** Find the FBConfigRec for this fbconfigid.
3335*4882a593Smuzhiyun      */
3336*4882a593Smuzhiyun     if (!(pGlxFBConfig = glxLookupFBConfig(fbconfigId))) {
3337*4882a593Smuzhiyun         client->errorValue = fbconfigId;
3338*4882a593Smuzhiyun         return __glXBadFBConfig;
3339*4882a593Smuzhiyun     }
3340*4882a593Smuzhiyun 
3341*4882a593Smuzhiyun     /*
3342*4882a593Smuzhiyun      ** Create the GLX part of the Pbuffer.
3343*4882a593Smuzhiyun      */
3344*4882a593Smuzhiyun     pGlxPbuffer = (__glXPbuffer *) malloc(sizeof(__glXPbuffer));
3345*4882a593Smuzhiyun     if (!pGlxPbuffer) {
3346*4882a593Smuzhiyun         return BadAlloc;
3347*4882a593Smuzhiyun     }
3348*4882a593Smuzhiyun 
3349*4882a593Smuzhiyun     pGlxPbuffer->be_xids = xallocarray(screenInfo.numScreens, sizeof(XID));
3350*4882a593Smuzhiyun     if (!pGlxPbuffer->be_xids) {
3351*4882a593Smuzhiyun         free(pGlxPbuffer);
3352*4882a593Smuzhiyun         return BadAlloc;
3353*4882a593Smuzhiyun     }
3354*4882a593Smuzhiyun 
3355*4882a593Smuzhiyun     /*
3356*4882a593Smuzhiyun      * Allocate an XID on the back-end server(s) and send him the request
3357*4882a593Smuzhiyun      */
3358*4882a593Smuzhiyun     from_screen = to_screen = screen;
3359*4882a593Smuzhiyun #ifdef PANORAMIX
3360*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
3361*4882a593Smuzhiyun         from_screen = 0;
3362*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
3363*4882a593Smuzhiyun     }
3364*4882a593Smuzhiyun #endif
3365*4882a593Smuzhiyun 
3366*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
3367*4882a593Smuzhiyun         dpy = GetBackEndDisplay(cl, s);
3368*4882a593Smuzhiyun         be_xid = XAllocID(dpy);
3369*4882a593Smuzhiyun         dmxScreen = &dmxScreens[s];
3370*4882a593Smuzhiyun         be_pGlxFBConfig = glxLookupBackEndFBConfig(pGlxFBConfig->id, s);
3371*4882a593Smuzhiyun 
3372*4882a593Smuzhiyun         attr = (int *) (req + 1);
3373*4882a593Smuzhiyun 
3374*4882a593Smuzhiyun         LockDisplay(dpy);
3375*4882a593Smuzhiyun         GetReqExtra(GLXCreatePbuffer, 2 * numAttribs * __GLX_SIZE_CARD32,
3376*4882a593Smuzhiyun                     be_req);
3377*4882a593Smuzhiyun         be_req->reqType = dmxScreen->glxMajorOpcode;
3378*4882a593Smuzhiyun         be_req->glxCode = X_GLXCreatePbuffer;
3379*4882a593Smuzhiyun         be_req->screen = be_pGlxFBConfig->screen;
3380*4882a593Smuzhiyun         be_req->fbconfig = be_pGlxFBConfig->id;
3381*4882a593Smuzhiyun         be_req->pbuffer = be_xid;
3382*4882a593Smuzhiyun         be_req->numAttribs = numAttribs;
3383*4882a593Smuzhiyun 
3384*4882a593Smuzhiyun         /* Send attributes */
3385*4882a593Smuzhiyun         if (attr != NULL) {
3386*4882a593Smuzhiyun             CARD32 *pca = (CARD32 *) (be_req + 1);
3387*4882a593Smuzhiyun 
3388*4882a593Smuzhiyun             while (numAttribs-- > 0) {
3389*4882a593Smuzhiyun                 *pca++ = *attr++;        /* token */
3390*4882a593Smuzhiyun                 *pca++ = *attr++;        /* value */
3391*4882a593Smuzhiyun             }
3392*4882a593Smuzhiyun         }
3393*4882a593Smuzhiyun 
3394*4882a593Smuzhiyun         UnlockDisplay(dpy);
3395*4882a593Smuzhiyun         SyncHandle();
3396*4882a593Smuzhiyun 
3397*4882a593Smuzhiyun         pGlxPbuffer->be_xids[s] = be_xid;
3398*4882a593Smuzhiyun     }
3399*4882a593Smuzhiyun 
3400*4882a593Smuzhiyun     pGlxPbuffer->idExists = True;
3401*4882a593Smuzhiyun     pGlxPbuffer->refcnt = 0;
3402*4882a593Smuzhiyun     pGlxPbuffer->pFBConfig = pGlxFBConfig;
3403*4882a593Smuzhiyun     pGlxPbuffer->pScreen = pScreen;
3404*4882a593Smuzhiyun 
3405*4882a593Smuzhiyun     /*
3406*4882a593Smuzhiyun      ** Register the resource.
3407*4882a593Smuzhiyun      */
3408*4882a593Smuzhiyun     if (!(AddResource(pbuffer, __glXPbufferRes, pGlxPbuffer))) {
3409*4882a593Smuzhiyun         return BadAlloc;
3410*4882a593Smuzhiyun     }
3411*4882a593Smuzhiyun 
3412*4882a593Smuzhiyun     return Success;
3413*4882a593Smuzhiyun 
3414*4882a593Smuzhiyun }
3415*4882a593Smuzhiyun 
3416*4882a593Smuzhiyun int
__glXDestroyPbuffer(__GLXclientState * cl,GLbyte * pc)3417*4882a593Smuzhiyun __glXDestroyPbuffer(__GLXclientState * cl, GLbyte * pc)
3418*4882a593Smuzhiyun {
3419*4882a593Smuzhiyun     ClientPtr client = cl->client;
3420*4882a593Smuzhiyun     xGLXDestroyPbufferReq *req = (xGLXDestroyPbufferReq *) pc;
3421*4882a593Smuzhiyun     xGLXDestroyPbufferReq *be_req;
3422*4882a593Smuzhiyun     GLXPbuffer pbuffer = req->pbuffer;
3423*4882a593Smuzhiyun     Display *dpy;
3424*4882a593Smuzhiyun     int screen;
3425*4882a593Smuzhiyun     DMXScreenInfo *dmxScreen;
3426*4882a593Smuzhiyun     __glXPbuffer *pGlxPbuffer;
3427*4882a593Smuzhiyun     int s;
3428*4882a593Smuzhiyun     int from_screen, to_screen;
3429*4882a593Smuzhiyun 
3430*4882a593Smuzhiyun     /*
3431*4882a593Smuzhiyun      ** Check if it's a valid Pbuffer
3432*4882a593Smuzhiyun      */
3433*4882a593Smuzhiyun     dixLookupResourceByType((void **) &pGlxPbuffer, pbuffer,
3434*4882a593Smuzhiyun                             __glXPbufferRes, NullClient, DixUnknownAccess);
3435*4882a593Smuzhiyun     if (!pGlxPbuffer) {
3436*4882a593Smuzhiyun         client->errorValue = pbuffer;
3437*4882a593Smuzhiyun         return __glXBadPbuffer;
3438*4882a593Smuzhiyun     }
3439*4882a593Smuzhiyun 
3440*4882a593Smuzhiyun     screen = pGlxPbuffer->pScreen->myNum;
3441*4882a593Smuzhiyun 
3442*4882a593Smuzhiyun     from_screen = to_screen = screen;
3443*4882a593Smuzhiyun #ifdef PANORAMIX
3444*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
3445*4882a593Smuzhiyun         from_screen = 0;
3446*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
3447*4882a593Smuzhiyun     }
3448*4882a593Smuzhiyun #endif
3449*4882a593Smuzhiyun 
3450*4882a593Smuzhiyun     for (s = from_screen; s <= to_screen; s++) {
3451*4882a593Smuzhiyun         dpy = GetBackEndDisplay(cl, s);
3452*4882a593Smuzhiyun         dmxScreen = &dmxScreens[s];
3453*4882a593Smuzhiyun 
3454*4882a593Smuzhiyun         /* send the destroy request to the back-end server */
3455*4882a593Smuzhiyun         LockDisplay(dpy);
3456*4882a593Smuzhiyun         GetReq(GLXDestroyPbuffer, be_req);
3457*4882a593Smuzhiyun         be_req->reqType = dmxScreen->glxMajorOpcode;
3458*4882a593Smuzhiyun         be_req->glxCode = X_GLXDestroyPbuffer;
3459*4882a593Smuzhiyun         be_req->pbuffer = pGlxPbuffer->be_xids[s];
3460*4882a593Smuzhiyun         UnlockDisplay(dpy);
3461*4882a593Smuzhiyun         SyncHandle();
3462*4882a593Smuzhiyun     }
3463*4882a593Smuzhiyun 
3464*4882a593Smuzhiyun     FreeResource(pbuffer, RT_NONE);
3465*4882a593Smuzhiyun 
3466*4882a593Smuzhiyun     return Success;
3467*4882a593Smuzhiyun }
3468*4882a593Smuzhiyun 
3469*4882a593Smuzhiyun int
__glXGetDrawableAttributes(__GLXclientState * cl,GLbyte * pc)3470*4882a593Smuzhiyun __glXGetDrawableAttributes(__GLXclientState * cl, GLbyte * pc)
3471*4882a593Smuzhiyun {
3472*4882a593Smuzhiyun     xGLXGetDrawableAttributesReq *req = (xGLXGetDrawableAttributesReq *) pc;
3473*4882a593Smuzhiyun     xGLXGetDrawableAttributesReq *be_req;
3474*4882a593Smuzhiyun     xGLXGetDrawableAttributesReply reply;
3475*4882a593Smuzhiyun     ClientPtr client = cl->client;
3476*4882a593Smuzhiyun     GLXDrawable drawId = req->drawable;
3477*4882a593Smuzhiyun     GLXDrawable be_drawable = 0;
3478*4882a593Smuzhiyun     DrawablePtr pDraw = NULL;
3479*4882a593Smuzhiyun     Display *dpy;
3480*4882a593Smuzhiyun     int screen, rc;
3481*4882a593Smuzhiyun     DMXScreenInfo *dmxScreen;
3482*4882a593Smuzhiyun     CARD32 *attribs = NULL;
3483*4882a593Smuzhiyun     int attribs_size = 0;
3484*4882a593Smuzhiyun 
3485*4882a593Smuzhiyun #ifdef PANORAMIX
3486*4882a593Smuzhiyun     PanoramiXRes *pXinDraw = NULL;
3487*4882a593Smuzhiyun #endif
3488*4882a593Smuzhiyun 
3489*4882a593Smuzhiyun     if (drawId != None) {
3490*4882a593Smuzhiyun         rc = dixLookupDrawable(&pDraw, drawId, client, 0, DixGetAttrAccess);
3491*4882a593Smuzhiyun         if (rc == Success && pDraw->type == DRAWABLE_WINDOW) {
3492*4882a593Smuzhiyun             WindowPtr pWin = (WindowPtr) pDraw;
3493*4882a593Smuzhiyun 
3494*4882a593Smuzhiyun             be_drawable = 0;
3495*4882a593Smuzhiyun             screen = pWin->drawable.pScreen->myNum;
3496*4882a593Smuzhiyun         }
3497*4882a593Smuzhiyun         else {
3498*4882a593Smuzhiyun             /*
3499*4882a593Smuzhiyun              ** Drawable is not a Window , GLXWindow or a GLXPixmap.
3500*4882a593Smuzhiyun              */
3501*4882a593Smuzhiyun             client->errorValue = drawId;
3502*4882a593Smuzhiyun             return __glXBadDrawable;
3503*4882a593Smuzhiyun         }
3504*4882a593Smuzhiyun 
3505*4882a593Smuzhiyun         if (!pDraw) {
3506*4882a593Smuzhiyun             __GLXpixmap *pGlxPixmap;
3507*4882a593Smuzhiyun 
3508*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxPixmap,
3509*4882a593Smuzhiyun                                     drawId, __glXPixmapRes,
3510*4882a593Smuzhiyun                                     NullClient, DixUnknownAccess);
3511*4882a593Smuzhiyun             if (pGlxPixmap) {
3512*4882a593Smuzhiyun                 pDraw = pGlxPixmap->pDraw;
3513*4882a593Smuzhiyun                 screen = pGlxPixmap->pScreen->myNum;
3514*4882a593Smuzhiyun                 be_drawable = pGlxPixmap->be_xids[screen];
3515*4882a593Smuzhiyun             }
3516*4882a593Smuzhiyun         }
3517*4882a593Smuzhiyun 
3518*4882a593Smuzhiyun         if (!pDraw) {
3519*4882a593Smuzhiyun             __glXWindow *pGlxWindow;
3520*4882a593Smuzhiyun 
3521*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxWindow,
3522*4882a593Smuzhiyun                                     drawId, __glXWindowRes,
3523*4882a593Smuzhiyun                                     NullClient, DixUnknownAccess);
3524*4882a593Smuzhiyun             if (pGlxWindow) {
3525*4882a593Smuzhiyun                 pDraw = pGlxWindow->pDraw;
3526*4882a593Smuzhiyun                 screen = pGlxWindow->pScreen->myNum;
3527*4882a593Smuzhiyun                 be_drawable = 0;
3528*4882a593Smuzhiyun             }
3529*4882a593Smuzhiyun         }
3530*4882a593Smuzhiyun 
3531*4882a593Smuzhiyun         if (!pDraw) {
3532*4882a593Smuzhiyun             __glXPbuffer *pGlxPbuffer;
3533*4882a593Smuzhiyun 
3534*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxPbuffer,
3535*4882a593Smuzhiyun                                     drawId, __glXPbufferRes,
3536*4882a593Smuzhiyun                                     NullClient, DixUnknownAccess);
3537*4882a593Smuzhiyun             if (pGlxPbuffer) {
3538*4882a593Smuzhiyun                 pDraw = (DrawablePtr) pGlxPbuffer;
3539*4882a593Smuzhiyun                 screen = pGlxPbuffer->pScreen->myNum;
3540*4882a593Smuzhiyun                 be_drawable = pGlxPbuffer->be_xids[screen];
3541*4882a593Smuzhiyun             }
3542*4882a593Smuzhiyun         }
3543*4882a593Smuzhiyun     }
3544*4882a593Smuzhiyun 
3545*4882a593Smuzhiyun     if (!pDraw) {
3546*4882a593Smuzhiyun         /*
3547*4882a593Smuzhiyun          ** Drawable is not a Window , GLXWindow or a GLXPixmap.
3548*4882a593Smuzhiyun          */
3549*4882a593Smuzhiyun         client->errorValue = drawId;
3550*4882a593Smuzhiyun         return __glXBadDrawable;
3551*4882a593Smuzhiyun     }
3552*4882a593Smuzhiyun 
3553*4882a593Smuzhiyun     /* if the drawable is a window or GLXWindow -
3554*4882a593Smuzhiyun      * we need to find the base id on the back-end server
3555*4882a593Smuzhiyun      */
3556*4882a593Smuzhiyun     if (!be_drawable) {
3557*4882a593Smuzhiyun         WindowPtr pWin = (WindowPtr) pDraw;
3558*4882a593Smuzhiyun 
3559*4882a593Smuzhiyun #ifdef PANORAMIX
3560*4882a593Smuzhiyun         if (!noPanoramiXExtension) {
3561*4882a593Smuzhiyun             if (Success != dixLookupResourceByClass((void **) &pXinDraw,
3562*4882a593Smuzhiyun                                                     pDraw->id, XRC_DRAWABLE,
3563*4882a593Smuzhiyun                                                     client, DixReadAccess)) {
3564*4882a593Smuzhiyun                 client->errorValue = drawId;
3565*4882a593Smuzhiyun                 return __glXBadDrawable;
3566*4882a593Smuzhiyun             }
3567*4882a593Smuzhiyun 
3568*4882a593Smuzhiyun             dixLookupWindow(&pWin, pXinDraw->info[screen].id, client,
3569*4882a593Smuzhiyun                             DixReadAccess);
3570*4882a593Smuzhiyun         }
3571*4882a593Smuzhiyun #endif
3572*4882a593Smuzhiyun 
3573*4882a593Smuzhiyun         if (pWin) {
3574*4882a593Smuzhiyun             be_drawable = (unsigned int) (DMX_GET_WINDOW_PRIV(pWin))->window;
3575*4882a593Smuzhiyun             if (!be_drawable) {
3576*4882a593Smuzhiyun                 /* it might be that the window did not created yet on the */
3577*4882a593Smuzhiyun                 /* back-end server (lazy window creation option), force   */
3578*4882a593Smuzhiyun                 /* creation of the window */
3579*4882a593Smuzhiyun                 dmxCreateAndRealizeWindow(pWin, TRUE);
3580*4882a593Smuzhiyun                 be_drawable =
3581*4882a593Smuzhiyun                     (unsigned int) (DMX_GET_WINDOW_PRIV(pWin))->window;
3582*4882a593Smuzhiyun             }
3583*4882a593Smuzhiyun         }
3584*4882a593Smuzhiyun         else {
3585*4882a593Smuzhiyun             client->errorValue = drawId;
3586*4882a593Smuzhiyun             return __glXBadDrawable;
3587*4882a593Smuzhiyun         }
3588*4882a593Smuzhiyun     }
3589*4882a593Smuzhiyun 
3590*4882a593Smuzhiyun     /* send the request to the back-end server */
3591*4882a593Smuzhiyun     dpy = GetBackEndDisplay(cl, screen);
3592*4882a593Smuzhiyun     dmxScreen = &dmxScreens[screen];
3593*4882a593Smuzhiyun 
3594*4882a593Smuzhiyun     /* make sure drawable exists on back-end */
3595*4882a593Smuzhiyun     dmxSync(dmxScreen, 1);
3596*4882a593Smuzhiyun 
3597*4882a593Smuzhiyun     LockDisplay(dpy);
3598*4882a593Smuzhiyun     GetReq(GLXGetDrawableAttributes, be_req);
3599*4882a593Smuzhiyun     be_req->reqType = dmxScreen->glxMajorOpcode;
3600*4882a593Smuzhiyun     be_req->glxCode = X_GLXGetDrawableAttributes;
3601*4882a593Smuzhiyun     be_req->drawable = be_drawable;
3602*4882a593Smuzhiyun     be_req->length = req->length;
3603*4882a593Smuzhiyun     if (!_XReply(dpy, (xReply *) &reply, 0, False)) {
3604*4882a593Smuzhiyun         UnlockDisplay(dpy);
3605*4882a593Smuzhiyun         SyncHandle();
3606*4882a593Smuzhiyun         return (BE_TO_CLIENT_ERROR(dmxLastErrorEvent.error_code));
3607*4882a593Smuzhiyun     }
3608*4882a593Smuzhiyun 
3609*4882a593Smuzhiyun     if (reply.numAttribs) {
3610*4882a593Smuzhiyun         attribs = xallocarray(reply.numAttribs, 2 * __GLX_SIZE_CARD32);
3611*4882a593Smuzhiyun         if (attribs == NULL) {
3612*4882a593Smuzhiyun             UnlockDisplay(dpy);
3613*4882a593Smuzhiyun             SyncHandle();
3614*4882a593Smuzhiyun             return BadAlloc;
3615*4882a593Smuzhiyun         }
3616*4882a593Smuzhiyun         attribs_size = 2 * reply.numAttribs * __GLX_SIZE_CARD32;
3617*4882a593Smuzhiyun 
3618*4882a593Smuzhiyun         _XRead(dpy, (char *) attribs, attribs_size);
3619*4882a593Smuzhiyun     }
3620*4882a593Smuzhiyun 
3621*4882a593Smuzhiyun     UnlockDisplay(dpy);
3622*4882a593Smuzhiyun     SyncHandle();
3623*4882a593Smuzhiyun 
3624*4882a593Smuzhiyun     /* send the reply back to the client */
3625*4882a593Smuzhiyun     reply.sequenceNumber = client->sequence;
3626*4882a593Smuzhiyun     if (client->swapped) {
3627*4882a593Smuzhiyun         __glXSwapGetDrawableAttributesReply(client, &reply, (int *) attribs);
3628*4882a593Smuzhiyun     }
3629*4882a593Smuzhiyun     else {
3630*4882a593Smuzhiyun         WriteToClient(client, sz_xGLXGetDrawableAttributesReply, &reply);
3631*4882a593Smuzhiyun         WriteToClient(client, attribs_size, attribs);
3632*4882a593Smuzhiyun     }
3633*4882a593Smuzhiyun 
3634*4882a593Smuzhiyun     free(attribs);
3635*4882a593Smuzhiyun 
3636*4882a593Smuzhiyun     return Success;
3637*4882a593Smuzhiyun }
3638*4882a593Smuzhiyun 
3639*4882a593Smuzhiyun int
__glXChangeDrawableAttributes(__GLXclientState * cl,GLbyte * pc)3640*4882a593Smuzhiyun __glXChangeDrawableAttributes(__GLXclientState * cl, GLbyte * pc)
3641*4882a593Smuzhiyun {
3642*4882a593Smuzhiyun     xGLXChangeDrawableAttributesReq *req =
3643*4882a593Smuzhiyun         (xGLXChangeDrawableAttributesReq *) pc;
3644*4882a593Smuzhiyun     xGLXChangeDrawableAttributesReq *be_req;
3645*4882a593Smuzhiyun     ClientPtr client = cl->client;
3646*4882a593Smuzhiyun     GLXDrawable drawId = req->drawable;
3647*4882a593Smuzhiyun     GLXDrawable be_drawable = 0;
3648*4882a593Smuzhiyun     DrawablePtr pDraw = NULL;
3649*4882a593Smuzhiyun     Display *dpy;
3650*4882a593Smuzhiyun     int screen, rc;
3651*4882a593Smuzhiyun     DMXScreenInfo *dmxScreen;
3652*4882a593Smuzhiyun 
3653*4882a593Smuzhiyun     if (drawId != None) {
3654*4882a593Smuzhiyun         rc = dixLookupDrawable(&pDraw, drawId, client, 0, DixSetAttrAccess);
3655*4882a593Smuzhiyun         if (rc == Success && pDraw->type == DRAWABLE_WINDOW) {
3656*4882a593Smuzhiyun             be_drawable = 0;
3657*4882a593Smuzhiyun             screen = pDraw->pScreen->myNum;
3658*4882a593Smuzhiyun         }
3659*4882a593Smuzhiyun         else {
3660*4882a593Smuzhiyun             /*
3661*4882a593Smuzhiyun              ** Drawable is not a Window , GLXWindow or a GLXPixmap.
3662*4882a593Smuzhiyun              */
3663*4882a593Smuzhiyun             client->errorValue = drawId;
3664*4882a593Smuzhiyun             return __glXBadDrawable;
3665*4882a593Smuzhiyun         }
3666*4882a593Smuzhiyun 
3667*4882a593Smuzhiyun         if (!pDraw) {
3668*4882a593Smuzhiyun             __GLXpixmap *pGlxPixmap;
3669*4882a593Smuzhiyun 
3670*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxPixmap,
3671*4882a593Smuzhiyun                                     drawId, __glXPixmapRes,
3672*4882a593Smuzhiyun                                     NullClient, DixUnknownAccess);
3673*4882a593Smuzhiyun             if (pGlxPixmap) {
3674*4882a593Smuzhiyun                 pDraw = pGlxPixmap->pDraw;
3675*4882a593Smuzhiyun                 screen = pGlxPixmap->pScreen->myNum;
3676*4882a593Smuzhiyun                 be_drawable = pGlxPixmap->be_xids[screen];
3677*4882a593Smuzhiyun             }
3678*4882a593Smuzhiyun         }
3679*4882a593Smuzhiyun 
3680*4882a593Smuzhiyun         if (!pDraw) {
3681*4882a593Smuzhiyun             __glXWindow *pGlxWindow;
3682*4882a593Smuzhiyun 
3683*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxWindow,
3684*4882a593Smuzhiyun                                     drawId, __glXWindowRes,
3685*4882a593Smuzhiyun                                     NullClient, DixUnknownAccess);
3686*4882a593Smuzhiyun             if (pGlxWindow) {
3687*4882a593Smuzhiyun                 pDraw = pGlxWindow->pDraw;
3688*4882a593Smuzhiyun                 screen = pGlxWindow->pScreen->myNum;
3689*4882a593Smuzhiyun                 be_drawable = 0;
3690*4882a593Smuzhiyun             }
3691*4882a593Smuzhiyun         }
3692*4882a593Smuzhiyun 
3693*4882a593Smuzhiyun         if (!pDraw) {
3694*4882a593Smuzhiyun             __glXPbuffer *pGlxPbuffer;
3695*4882a593Smuzhiyun 
3696*4882a593Smuzhiyun             dixLookupResourceByType((void **) &pGlxPbuffer,
3697*4882a593Smuzhiyun                                     drawId, __glXPbufferRes,
3698*4882a593Smuzhiyun                                     NullClient, DixUnknownAccess);
3699*4882a593Smuzhiyun             if (pGlxPbuffer) {
3700*4882a593Smuzhiyun                 pDraw = (DrawablePtr) pGlxPbuffer;
3701*4882a593Smuzhiyun                 screen = pGlxPbuffer->pScreen->myNum;
3702*4882a593Smuzhiyun                 be_drawable = pGlxPbuffer->be_xids[screen];
3703*4882a593Smuzhiyun             }
3704*4882a593Smuzhiyun         }
3705*4882a593Smuzhiyun     }
3706*4882a593Smuzhiyun 
3707*4882a593Smuzhiyun     if (!pDraw) {
3708*4882a593Smuzhiyun         /*
3709*4882a593Smuzhiyun          ** Drawable is not a Window , GLXWindow or a GLXPixmap.
3710*4882a593Smuzhiyun          */
3711*4882a593Smuzhiyun         client->errorValue = drawId;
3712*4882a593Smuzhiyun         return __glXBadDrawable;
3713*4882a593Smuzhiyun     }
3714*4882a593Smuzhiyun 
3715*4882a593Smuzhiyun     /* if the drawable is a window or GLXWindow -
3716*4882a593Smuzhiyun      * we need to find the base id on the back-end server
3717*4882a593Smuzhiyun      */
3718*4882a593Smuzhiyun     if (!be_drawable) {
3719*4882a593Smuzhiyun         WindowPtr pWin = (WindowPtr) pDraw;
3720*4882a593Smuzhiyun 
3721*4882a593Smuzhiyun #ifdef PANORAMIX
3722*4882a593Smuzhiyun         if (!noPanoramiXExtension) {
3723*4882a593Smuzhiyun             PanoramiXRes *pXinDraw;
3724*4882a593Smuzhiyun 
3725*4882a593Smuzhiyun             if (Success != dixLookupResourceByClass((void **) &pXinDraw,
3726*4882a593Smuzhiyun                                                     pDraw->id, XRC_DRAWABLE,
3727*4882a593Smuzhiyun                                                     client, DixReadAccess)) {
3728*4882a593Smuzhiyun                 client->errorValue = drawId;
3729*4882a593Smuzhiyun                 return __glXBadDrawable;
3730*4882a593Smuzhiyun             }
3731*4882a593Smuzhiyun 
3732*4882a593Smuzhiyun             dixLookupWindow(&pWin, pXinDraw->info[screen].id, client,
3733*4882a593Smuzhiyun                             DixReadAccess);
3734*4882a593Smuzhiyun         }
3735*4882a593Smuzhiyun #endif
3736*4882a593Smuzhiyun 
3737*4882a593Smuzhiyun         if (pWin) {
3738*4882a593Smuzhiyun             be_drawable = (unsigned int) (DMX_GET_WINDOW_PRIV(pWin))->window;
3739*4882a593Smuzhiyun             if (!be_drawable) {
3740*4882a593Smuzhiyun                 /* it might be that the window did not created yet on the */
3741*4882a593Smuzhiyun                 /* back-end server (lazy window creation option), force   */
3742*4882a593Smuzhiyun                 /* creation of the window */
3743*4882a593Smuzhiyun                 dmxCreateAndRealizeWindow(pWin, TRUE);
3744*4882a593Smuzhiyun                 be_drawable =
3745*4882a593Smuzhiyun                     (unsigned int) (DMX_GET_WINDOW_PRIV(pWin))->window;
3746*4882a593Smuzhiyun             }
3747*4882a593Smuzhiyun         }
3748*4882a593Smuzhiyun         else {
3749*4882a593Smuzhiyun             client->errorValue = drawId;
3750*4882a593Smuzhiyun             return __glXBadDrawable;
3751*4882a593Smuzhiyun         }
3752*4882a593Smuzhiyun     }
3753*4882a593Smuzhiyun 
3754*4882a593Smuzhiyun     /* send the request to the back-end server */
3755*4882a593Smuzhiyun     dpy = GetBackEndDisplay(cl, screen);
3756*4882a593Smuzhiyun     dmxScreen = &dmxScreens[screen];
3757*4882a593Smuzhiyun 
3758*4882a593Smuzhiyun     /* make sure drawable exists on back-end */
3759*4882a593Smuzhiyun     dmxSync(dmxScreen, 1);
3760*4882a593Smuzhiyun 
3761*4882a593Smuzhiyun     LockDisplay(dpy);
3762*4882a593Smuzhiyun     GetReqExtra(GLXChangeDrawableAttributes,
3763*4882a593Smuzhiyun                 2 * req->numAttribs * __GLX_SIZE_CARD32, be_req);
3764*4882a593Smuzhiyun     be_req->reqType = dmxScreen->glxMajorOpcode;
3765*4882a593Smuzhiyun     be_req->glxCode = X_GLXChangeDrawableAttributes;
3766*4882a593Smuzhiyun     be_req->drawable = be_drawable;
3767*4882a593Smuzhiyun     be_req->numAttribs = req->numAttribs;
3768*4882a593Smuzhiyun     be_req->length = req->length;
3769*4882a593Smuzhiyun 
3770*4882a593Smuzhiyun     UnlockDisplay(dpy);
3771*4882a593Smuzhiyun     SyncHandle();
3772*4882a593Smuzhiyun 
3773*4882a593Smuzhiyun     return Success;
3774*4882a593Smuzhiyun }
3775*4882a593Smuzhiyun 
3776*4882a593Smuzhiyun int
__glXSendLargeCommand(__GLXclientState * cl,GLXContextTag contextTag)3777*4882a593Smuzhiyun __glXSendLargeCommand(__GLXclientState * cl, GLXContextTag contextTag)
3778*4882a593Smuzhiyun {
3779*4882a593Smuzhiyun     ClientPtr client = cl->client;
3780*4882a593Smuzhiyun     xGLXRenderLargeReq *req;
3781*4882a593Smuzhiyun     GLint maxSize, amount;
3782*4882a593Smuzhiyun     GLint totalRequests, requestNumber;
3783*4882a593Smuzhiyun     GLint dataLen;
3784*4882a593Smuzhiyun     GLbyte *data;
3785*4882a593Smuzhiyun     __GLXcontext *glxc;
3786*4882a593Smuzhiyun     int s;
3787*4882a593Smuzhiyun     int from_screen, to_screen;
3788*4882a593Smuzhiyun 
3789*4882a593Smuzhiyun     maxSize = cl->largeCmdMaxReqDataSize - (GLint) sizeof(xGLXRenderLargeReq);
3790*4882a593Smuzhiyun     dataLen = cl->largeCmdBytesTotal;
3791*4882a593Smuzhiyun     totalRequests = (dataLen / maxSize);
3792*4882a593Smuzhiyun     if (dataLen % maxSize)
3793*4882a593Smuzhiyun         totalRequests++;
3794*4882a593Smuzhiyun 
3795*4882a593Smuzhiyun     glxc = __glXLookupContextByTag(cl, contextTag);
3796*4882a593Smuzhiyun     if (!glxc) {
3797*4882a593Smuzhiyun         client->errorValue = contextTag;
3798*4882a593Smuzhiyun         return __glXBadContext;
3799*4882a593Smuzhiyun     }
3800*4882a593Smuzhiyun     from_screen = to_screen = glxc->pScreen->myNum;
3801*4882a593Smuzhiyun 
3802*4882a593Smuzhiyun #ifdef PANORAMIX
3803*4882a593Smuzhiyun     if (!noPanoramiXExtension) {
3804*4882a593Smuzhiyun         from_screen = 0;
3805*4882a593Smuzhiyun         to_screen = screenInfo.numScreens - 1;
3806*4882a593Smuzhiyun     }
3807*4882a593Smuzhiyun #endif
3808*4882a593Smuzhiyun 
3809*4882a593Smuzhiyun     /*
3810*4882a593Smuzhiyun      ** Send enough requests until the whole array is sent.
3811*4882a593Smuzhiyun      */
3812*4882a593Smuzhiyun     requestNumber = 1;
3813*4882a593Smuzhiyun     data = cl->largeCmdBuf;
3814*4882a593Smuzhiyun     while (dataLen > 0) {
3815*4882a593Smuzhiyun         amount = dataLen;
3816*4882a593Smuzhiyun         if (amount > maxSize) {
3817*4882a593Smuzhiyun             amount = maxSize;
3818*4882a593Smuzhiyun         }
3819*4882a593Smuzhiyun 
3820*4882a593Smuzhiyun         for (s = from_screen; s <= to_screen; s++) {
3821*4882a593Smuzhiyun 
3822*4882a593Smuzhiyun             Display *dpy = GetBackEndDisplay(cl, s);
3823*4882a593Smuzhiyun             DMXScreenInfo *dmxScreen = &dmxScreens[s];
3824*4882a593Smuzhiyun 
3825*4882a593Smuzhiyun             LockDisplay(dpy);
3826*4882a593Smuzhiyun             GetReq(GLXRenderLarge, req);
3827*4882a593Smuzhiyun             req->reqType = dmxScreen->glxMajorOpcode;
3828*4882a593Smuzhiyun             req->glxCode = X_GLXRenderLarge;
3829*4882a593Smuzhiyun             req->contextTag = GetCurrentBackEndTag(cl, contextTag, s);
3830*4882a593Smuzhiyun             req->length += (amount + 3) >> 2;
3831*4882a593Smuzhiyun             req->requestNumber = requestNumber++;
3832*4882a593Smuzhiyun             req->requestTotal = totalRequests;
3833*4882a593Smuzhiyun             req->dataBytes = amount;
3834*4882a593Smuzhiyun             Data(dpy, ((const char *) data), amount);
3835*4882a593Smuzhiyun             dataLen -= amount;
3836*4882a593Smuzhiyun             data = ((GLbyte *) data) + amount;
3837*4882a593Smuzhiyun             UnlockDisplay(dpy);
3838*4882a593Smuzhiyun             SyncHandle();
3839*4882a593Smuzhiyun         }
3840*4882a593Smuzhiyun     }
3841*4882a593Smuzhiyun 
3842*4882a593Smuzhiyun     return Success;
3843*4882a593Smuzhiyun }
3844