1706f2543Smrg/*****************************************************************
2706f2543SmrgCopyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
3706f2543SmrgPermission is hereby granted, free of charge, to any person obtaining a copy
4706f2543Smrgof this software and associated documentation files (the "Software"), to deal
5706f2543Smrgin the Software without restriction, including without limitation the rights
6706f2543Smrgto use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7706f2543Smrgcopies of the Software.
8706f2543Smrg
9706f2543SmrgThe above copyright notice and this permission notice shall be included in
10706f2543Smrgall copies or substantial portions of the Software.
11706f2543Smrg
12706f2543SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13706f2543SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14706f2543SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
15706f2543SmrgDIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
16706f2543SmrgBUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
17706f2543SmrgWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
18706f2543SmrgIN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19706f2543Smrg
20706f2543SmrgExcept as contained in this notice, the name of Digital Equipment Corporation
21706f2543Smrgshall not be used in advertising or otherwise to promote the sale, use or other
22706f2543Smrgdealings in this Software without prior written authorization from Digital
23706f2543SmrgEquipment Corporation.
24706f2543Smrg******************************************************************/
25706f2543Smrg
26706f2543Smrg/* Massively rewritten by Mark Vojkovich <markv@valinux.com> */
27706f2543Smrg
28706f2543Smrg
29706f2543Smrg#ifdef HAVE_DIX_CONFIG_H
30706f2543Smrg#include <dix-config.h>
31706f2543Smrg#endif
32706f2543Smrg
33706f2543Smrg#include <stdio.h>
34706f2543Smrg#include <X11/X.h>
35706f2543Smrg#include <X11/Xproto.h>
36706f2543Smrg#include "windowstr.h"
37706f2543Smrg#include "dixfontstr.h"
38706f2543Smrg#include "gcstruct.h"
39706f2543Smrg#include "colormapst.h"
40706f2543Smrg#include "scrnintstr.h"
41706f2543Smrg#include "opaque.h"
42706f2543Smrg#include "inputstr.h"
43706f2543Smrg#include "migc.h"
44706f2543Smrg#include "misc.h"
45706f2543Smrg#include "dixstruct.h"
46706f2543Smrg#include "panoramiX.h"
47706f2543Smrg#include "panoramiXsrv.h"
48706f2543Smrg#include "resource.h"
49706f2543Smrg#include "panoramiXh.h"
50706f2543Smrg
51706f2543Smrg#define XINERAMA_IMAGE_BUFSIZE (256*1024)
52706f2543Smrg#define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \
53706f2543Smrg                              CWDontPropagate | CWOverrideRedirect | CWCursor )
54706f2543Smrg
55706f2543Smrgint PanoramiXCreateWindow(ClientPtr client)
56706f2543Smrg{
57706f2543Smrg    PanoramiXRes *parent, *newWin;
58706f2543Smrg    PanoramiXRes *backPix = NULL;
59706f2543Smrg    PanoramiXRes *bordPix = NULL;
60706f2543Smrg    PanoramiXRes *cmap    = NULL;
61706f2543Smrg    REQUEST(xCreateWindowReq);
62706f2543Smrg    int pback_offset = 0, pbord_offset = 0, cmap_offset = 0;
63706f2543Smrg    int result, len, j;
64706f2543Smrg    int orig_x, orig_y;
65706f2543Smrg    XID orig_visual, tmp;
66706f2543Smrg    Bool parentIsRoot;
67706f2543Smrg
68706f2543Smrg    REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
69706f2543Smrg
70706f2543Smrg    len = client->req_len - bytes_to_int32(sizeof(xCreateWindowReq));
71706f2543Smrg    if (Ones(stuff->mask) != len)
72706f2543Smrg        return BadLength;
73706f2543Smrg
74706f2543Smrg    result = dixLookupResourceByType((pointer *)&parent, stuff->parent,
75706f2543Smrg				     XRT_WINDOW, client, DixWriteAccess);
76706f2543Smrg    if (result != Success)
77706f2543Smrg        return result;
78706f2543Smrg
79706f2543Smrg    if(stuff->class == CopyFromParent)
80706f2543Smrg	stuff->class = parent->u.win.class;
81706f2543Smrg
82706f2543Smrg    if((stuff->class == InputOnly) && (stuff->mask & (~INPUTONLY_LEGAL_MASK)))
83706f2543Smrg        return BadMatch;
84706f2543Smrg
85706f2543Smrg    if ((Mask)stuff->mask & CWBackPixmap) {
86706f2543Smrg	pback_offset = Ones((Mask)stuff->mask & (CWBackPixmap - 1));
87706f2543Smrg	tmp = *((CARD32 *) &stuff[1] + pback_offset);
88706f2543Smrg	if ((tmp != None) && (tmp != ParentRelative)) {
89706f2543Smrg	    result = dixLookupResourceByType((pointer *)&backPix, tmp,
90706f2543Smrg					     XRT_PIXMAP, client, DixReadAccess);
91706f2543Smrg	    if (result != Success)
92706f2543Smrg		return result;
93706f2543Smrg	}
94706f2543Smrg    }
95706f2543Smrg    if ((Mask)stuff->mask & CWBorderPixmap) {
96706f2543Smrg	pbord_offset = Ones((Mask)stuff->mask & (CWBorderPixmap - 1));
97706f2543Smrg	tmp = *((CARD32 *) &stuff[1] + pbord_offset);
98706f2543Smrg	if (tmp != CopyFromParent) {
99706f2543Smrg	    result = dixLookupResourceByType((pointer *)&bordPix, tmp,
100706f2543Smrg					     XRT_PIXMAP, client, DixReadAccess);
101706f2543Smrg	    if (result != Success)
102706f2543Smrg		return result;
103706f2543Smrg	}
104706f2543Smrg    }
105706f2543Smrg    if ((Mask)stuff->mask & CWColormap) {
106706f2543Smrg	cmap_offset = Ones((Mask)stuff->mask & (CWColormap - 1));
107706f2543Smrg	tmp = *((CARD32 *) &stuff[1] + cmap_offset);
108706f2543Smrg	if ((tmp != CopyFromParent) && (tmp != None)) {
109706f2543Smrg	    result = dixLookupResourceByType((pointer *)&cmap, tmp,
110706f2543Smrg					     XRT_COLORMAP, client, DixReadAccess);
111706f2543Smrg	    if (result != Success)
112706f2543Smrg		return result;
113706f2543Smrg	}
114706f2543Smrg    }
115706f2543Smrg
116706f2543Smrg    if(!(newWin = malloc(sizeof(PanoramiXRes))))
117706f2543Smrg        return BadAlloc;
118706f2543Smrg
119706f2543Smrg    newWin->type = XRT_WINDOW;
120706f2543Smrg    newWin->u.win.visibility = VisibilityNotViewable;
121706f2543Smrg    newWin->u.win.class = stuff->class;
122706f2543Smrg    newWin->u.win.root = FALSE;
123706f2543Smrg    newWin->info[0].id = stuff->wid;
124706f2543Smrg    for(j = 1; j < PanoramiXNumScreens; j++)
125706f2543Smrg        newWin->info[j].id = FakeClientID(client->index);
126706f2543Smrg
127706f2543Smrg    if (stuff->class == InputOnly)
128706f2543Smrg	stuff->visual = CopyFromParent;
129706f2543Smrg    orig_visual = stuff->visual;
130706f2543Smrg    orig_x = stuff->x;
131706f2543Smrg    orig_y = stuff->y;
132706f2543Smrg    parentIsRoot = (stuff->parent == screenInfo.screens[0]->root->drawable.id) ||
133706f2543Smrg                   (stuff->parent == screenInfo.screens[0]->screensaver.wid);
134706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
135706f2543Smrg        stuff->wid = newWin->info[j].id;
136706f2543Smrg        stuff->parent = parent->info[j].id;
137706f2543Smrg	if (parentIsRoot) {
138706f2543Smrg	    stuff->x = orig_x - screenInfo.screens[j]->x;
139706f2543Smrg	    stuff->y = orig_y - screenInfo.screens[j]->y;
140706f2543Smrg	}
141706f2543Smrg	if (backPix)
142706f2543Smrg	    *((CARD32 *) &stuff[1] + pback_offset) = backPix->info[j].id;
143706f2543Smrg	if (bordPix)
144706f2543Smrg	    *((CARD32 *) &stuff[1] + pbord_offset) = bordPix->info[j].id;
145706f2543Smrg	if (cmap)
146706f2543Smrg	    *((CARD32 *) &stuff[1] + cmap_offset) = cmap->info[j].id;
147706f2543Smrg	if ( orig_visual != CopyFromParent )
148706f2543Smrg	    stuff->visual = PanoramiXTranslateVisualID(j, orig_visual);
149706f2543Smrg        result = (*SavedProcVector[X_CreateWindow])(client);
150706f2543Smrg        if(result != Success) break;
151706f2543Smrg    }
152706f2543Smrg
153706f2543Smrg    if (result == Success)
154706f2543Smrg        AddResource(newWin->info[0].id, XRT_WINDOW, newWin);
155706f2543Smrg    else
156706f2543Smrg        free(newWin);
157706f2543Smrg
158706f2543Smrg    return result;
159706f2543Smrg}
160706f2543Smrg
161706f2543Smrg
162706f2543Smrgint PanoramiXChangeWindowAttributes(ClientPtr client)
163706f2543Smrg{
164706f2543Smrg    PanoramiXRes *win;
165706f2543Smrg    PanoramiXRes *backPix = NULL;
166706f2543Smrg    PanoramiXRes *bordPix = NULL;
167706f2543Smrg    PanoramiXRes *cmap    = NULL;
168706f2543Smrg    REQUEST(xChangeWindowAttributesReq);
169706f2543Smrg    int pback_offset = 0, pbord_offset = 0, cmap_offset = 0;
170706f2543Smrg    int result, len, j;
171706f2543Smrg    XID tmp;
172706f2543Smrg
173706f2543Smrg    REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
174706f2543Smrg
175706f2543Smrg    len = client->req_len - bytes_to_int32(sizeof(xChangeWindowAttributesReq));
176706f2543Smrg    if (Ones(stuff->valueMask) != len)
177706f2543Smrg        return BadLength;
178706f2543Smrg
179706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->window,
180706f2543Smrg				     XRT_WINDOW, client, DixWriteAccess);
181706f2543Smrg    if (result != Success)
182706f2543Smrg        return result;
183706f2543Smrg
184706f2543Smrg    if((win->u.win.class == InputOnly) &&
185706f2543Smrg       (stuff->valueMask & (~INPUTONLY_LEGAL_MASK)))
186706f2543Smrg        return BadMatch;
187706f2543Smrg
188706f2543Smrg    if ((Mask)stuff->valueMask & CWBackPixmap) {
189706f2543Smrg	pback_offset = Ones((Mask)stuff->valueMask & (CWBackPixmap - 1));
190706f2543Smrg	tmp = *((CARD32 *) &stuff[1] + pback_offset);
191706f2543Smrg	if ((tmp != None) && (tmp != ParentRelative)) {
192706f2543Smrg	    result = dixLookupResourceByType((pointer *)&backPix, tmp,
193706f2543Smrg					     XRT_PIXMAP, client, DixReadAccess);
194706f2543Smrg	    if (result != Success)
195706f2543Smrg		return result;
196706f2543Smrg	}
197706f2543Smrg    }
198706f2543Smrg    if ((Mask)stuff->valueMask & CWBorderPixmap) {
199706f2543Smrg	pbord_offset = Ones((Mask)stuff->valueMask & (CWBorderPixmap - 1));
200706f2543Smrg	tmp = *((CARD32 *) &stuff[1] + pbord_offset);
201706f2543Smrg	if (tmp != CopyFromParent) {
202706f2543Smrg	    result = dixLookupResourceByType((pointer *)&bordPix, tmp,
203706f2543Smrg					     XRT_PIXMAP, client, DixReadAccess);
204706f2543Smrg	    if (result != Success)
205706f2543Smrg		return result;
206706f2543Smrg	}
207706f2543Smrg    }
208706f2543Smrg    if ((Mask)stuff->valueMask & CWColormap) {
209706f2543Smrg	cmap_offset = Ones((Mask)stuff->valueMask & (CWColormap - 1));
210706f2543Smrg	tmp = *((CARD32 *) &stuff[1] + cmap_offset);
211706f2543Smrg	if ((tmp != CopyFromParent) && (tmp != None)) {
212706f2543Smrg	    result = dixLookupResourceByType((pointer *)&cmap, tmp,
213706f2543Smrg					     XRT_COLORMAP, client, DixReadAccess);
214706f2543Smrg	    if (result != Success)
215706f2543Smrg		return result;
216706f2543Smrg	}
217706f2543Smrg    }
218706f2543Smrg
219706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
220706f2543Smrg        stuff->window = win->info[j].id;
221706f2543Smrg	if (backPix)
222706f2543Smrg	    *((CARD32 *) &stuff[1] + pback_offset) = backPix->info[j].id;
223706f2543Smrg	if (bordPix)
224706f2543Smrg	    *((CARD32 *) &stuff[1] + pbord_offset) = bordPix->info[j].id;
225706f2543Smrg	if (cmap)
226706f2543Smrg	    *((CARD32 *) &stuff[1] + cmap_offset) = cmap->info[j].id;
227706f2543Smrg        result = (*SavedProcVector[X_ChangeWindowAttributes])(client);
228706f2543Smrg    }
229706f2543Smrg
230706f2543Smrg    return result;
231706f2543Smrg}
232706f2543Smrg
233706f2543Smrg
234706f2543Smrgint PanoramiXDestroyWindow(ClientPtr client)
235706f2543Smrg{
236706f2543Smrg    PanoramiXRes *win;
237706f2543Smrg    int         result, j;
238706f2543Smrg    REQUEST(xResourceReq);
239706f2543Smrg
240706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
241706f2543Smrg
242706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->id, XRT_WINDOW,
243706f2543Smrg				     client, DixDestroyAccess);
244706f2543Smrg    if (result != Success)
245706f2543Smrg	return result;
246706f2543Smrg
247706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
248706f2543Smrg	stuff->id = win->info[j].id;
249706f2543Smrg	result = (*SavedProcVector[X_DestroyWindow])(client);
250706f2543Smrg        if(result != Success) break;
251706f2543Smrg    }
252706f2543Smrg
253706f2543Smrg    /* Since ProcDestroyWindow is using FreeResource, it will free
254706f2543Smrg	our resource for us on the last pass through the loop above */
255706f2543Smrg
256706f2543Smrg    return result;
257706f2543Smrg}
258706f2543Smrg
259706f2543Smrg
260706f2543Smrgint PanoramiXDestroySubwindows(ClientPtr client)
261706f2543Smrg{
262706f2543Smrg    PanoramiXRes *win;
263706f2543Smrg    int         result, j;
264706f2543Smrg    REQUEST(xResourceReq);
265706f2543Smrg
266706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
267706f2543Smrg
268706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->id, XRT_WINDOW,
269706f2543Smrg				     client, DixDestroyAccess);
270706f2543Smrg    if (result != Success)
271706f2543Smrg	return result;
272706f2543Smrg
273706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
274706f2543Smrg	stuff->id = win->info[j].id;
275706f2543Smrg	result = (*SavedProcVector[X_DestroySubwindows])(client);
276706f2543Smrg        if(result != Success) break;
277706f2543Smrg    }
278706f2543Smrg
279706f2543Smrg    /* DestroySubwindows is using FreeResource which will free
280706f2543Smrg	our resources for us on the last pass through the loop above */
281706f2543Smrg
282706f2543Smrg    return result;
283706f2543Smrg}
284706f2543Smrg
285706f2543Smrg
286706f2543Smrgint PanoramiXChangeSaveSet(ClientPtr client)
287706f2543Smrg{
288706f2543Smrg    PanoramiXRes *win;
289706f2543Smrg    int         result, j;
290706f2543Smrg    REQUEST(xChangeSaveSetReq);
291706f2543Smrg
292706f2543Smrg    REQUEST_SIZE_MATCH(xChangeSaveSetReq);
293706f2543Smrg
294706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->window,
295706f2543Smrg				     XRT_WINDOW, client, DixReadAccess);
296706f2543Smrg    if (result != Success)
297706f2543Smrg	return result;
298706f2543Smrg
299706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
300706f2543Smrg	stuff->window = win->info[j].id;
301706f2543Smrg	result = (*SavedProcVector[X_ChangeSaveSet])(client);
302706f2543Smrg        if(result != Success) break;
303706f2543Smrg    }
304706f2543Smrg
305706f2543Smrg    return result;
306706f2543Smrg}
307706f2543Smrg
308706f2543Smrg
309706f2543Smrgint PanoramiXReparentWindow(ClientPtr client)
310706f2543Smrg{
311706f2543Smrg    PanoramiXRes *win, *parent;
312706f2543Smrg    int         result, j;
313706f2543Smrg    int		x, y;
314706f2543Smrg    Bool	parentIsRoot;
315706f2543Smrg    REQUEST(xReparentWindowReq);
316706f2543Smrg
317706f2543Smrg    REQUEST_SIZE_MATCH(xReparentWindowReq);
318706f2543Smrg
319706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->window,
320706f2543Smrg				     XRT_WINDOW, client, DixWriteAccess);
321706f2543Smrg    if (result != Success)
322706f2543Smrg	return result;
323706f2543Smrg
324706f2543Smrg    result = dixLookupResourceByType((pointer *)&parent, stuff->parent,
325706f2543Smrg				     XRT_WINDOW, client, DixWriteAccess);
326706f2543Smrg    if (result != Success)
327706f2543Smrg	return result;
328706f2543Smrg
329706f2543Smrg    x = stuff->x;
330706f2543Smrg    y = stuff->y;
331706f2543Smrg    parentIsRoot = (stuff->parent == screenInfo.screens[0]->root->drawable.id) ||
332706f2543Smrg                   (stuff->parent == screenInfo.screens[0]->screensaver.wid);
333706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
334706f2543Smrg	stuff->window = win->info[j].id;
335706f2543Smrg	stuff->parent = parent->info[j].id;
336706f2543Smrg	if(parentIsRoot) {
337706f2543Smrg	    stuff->x = x - screenInfo.screens[j]->x;
338706f2543Smrg	    stuff->y = y - screenInfo.screens[j]->y;
339706f2543Smrg	}
340706f2543Smrg	result = (*SavedProcVector[X_ReparentWindow])(client);
341706f2543Smrg        if(result != Success) break;
342706f2543Smrg    }
343706f2543Smrg
344706f2543Smrg    return result;
345706f2543Smrg}
346706f2543Smrg
347706f2543Smrg
348706f2543Smrgint PanoramiXMapWindow(ClientPtr client)
349706f2543Smrg{
350706f2543Smrg    PanoramiXRes *win;
351706f2543Smrg    int         result, j;
352706f2543Smrg    REQUEST(xResourceReq);
353706f2543Smrg
354706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
355706f2543Smrg
356706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->id,
357706f2543Smrg				     XRT_WINDOW, client, DixReadAccess);
358706f2543Smrg    if (result != Success)
359706f2543Smrg	return result;
360706f2543Smrg
361706f2543Smrg    FOR_NSCREENS_FORWARD(j) {
362706f2543Smrg	stuff->id = win->info[j].id;
363706f2543Smrg	result = (*SavedProcVector[X_MapWindow])(client);
364706f2543Smrg        if(result != Success) break;
365706f2543Smrg    }
366706f2543Smrg
367706f2543Smrg    return result;
368706f2543Smrg}
369706f2543Smrg
370706f2543Smrg
371706f2543Smrgint PanoramiXMapSubwindows(ClientPtr client)
372706f2543Smrg{
373706f2543Smrg    PanoramiXRes *win;
374706f2543Smrg    int         result, j;
375706f2543Smrg    REQUEST(xResourceReq);
376706f2543Smrg
377706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
378706f2543Smrg
379706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->id,
380706f2543Smrg				     XRT_WINDOW, client, DixReadAccess);
381706f2543Smrg    if (result != Success)
382706f2543Smrg	return result;
383706f2543Smrg
384706f2543Smrg    FOR_NSCREENS_FORWARD(j) {
385706f2543Smrg	stuff->id = win->info[j].id;
386706f2543Smrg	result = (*SavedProcVector[X_MapSubwindows])(client);
387706f2543Smrg        if(result != Success) break;
388706f2543Smrg    }
389706f2543Smrg
390706f2543Smrg    return result;
391706f2543Smrg}
392706f2543Smrg
393706f2543Smrg
394706f2543Smrgint PanoramiXUnmapWindow(ClientPtr client)
395706f2543Smrg{
396706f2543Smrg    PanoramiXRes *win;
397706f2543Smrg    int         result, j;
398706f2543Smrg    REQUEST(xResourceReq);
399706f2543Smrg
400706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
401706f2543Smrg
402706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->id,
403706f2543Smrg				     XRT_WINDOW, client, DixReadAccess);
404706f2543Smrg    if (result != Success)
405706f2543Smrg	return result;
406706f2543Smrg
407706f2543Smrg    FOR_NSCREENS_FORWARD(j) {
408706f2543Smrg	stuff->id = win->info[j].id;
409706f2543Smrg	result = (*SavedProcVector[X_UnmapWindow])(client);
410706f2543Smrg        if(result != Success) break;
411706f2543Smrg    }
412706f2543Smrg
413706f2543Smrg    return result;
414706f2543Smrg}
415706f2543Smrg
416706f2543Smrg
417706f2543Smrgint PanoramiXUnmapSubwindows(ClientPtr client)
418706f2543Smrg{
419706f2543Smrg    PanoramiXRes *win;
420706f2543Smrg    int         result, j;
421706f2543Smrg    REQUEST(xResourceReq);
422706f2543Smrg
423706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
424706f2543Smrg
425706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->id,
426706f2543Smrg				     XRT_WINDOW, client, DixReadAccess);
427706f2543Smrg    if (result != Success)
428706f2543Smrg	return result;
429706f2543Smrg
430706f2543Smrg    FOR_NSCREENS_FORWARD(j) {
431706f2543Smrg	stuff->id = win->info[j].id;
432706f2543Smrg	result = (*SavedProcVector[X_UnmapSubwindows])(client);
433706f2543Smrg        if(result != Success) break;
434706f2543Smrg    }
435706f2543Smrg
436706f2543Smrg    return result;
437706f2543Smrg}
438706f2543Smrg
439706f2543Smrg
440706f2543Smrgint PanoramiXConfigureWindow(ClientPtr client)
441706f2543Smrg{
442706f2543Smrg    PanoramiXRes *win;
443706f2543Smrg    PanoramiXRes *sib = NULL;
444706f2543Smrg    WindowPtr   pWin;
445706f2543Smrg    int         result, j, len, sib_offset = 0, x = 0, y = 0;
446706f2543Smrg    int		x_offset = -1;
447706f2543Smrg    int		y_offset = -1;
448706f2543Smrg    REQUEST(xConfigureWindowReq);
449706f2543Smrg
450706f2543Smrg    REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
451706f2543Smrg
452706f2543Smrg    len = client->req_len - bytes_to_int32(sizeof(xConfigureWindowReq));
453706f2543Smrg    if (Ones(stuff->mask) != len)
454706f2543Smrg        return BadLength;
455706f2543Smrg
456706f2543Smrg    /* because we need the parent */
457706f2543Smrg    result = dixLookupResourceByType((pointer *)&pWin, stuff->window,
458706f2543Smrg				     RT_WINDOW, client, DixWriteAccess);
459706f2543Smrg    if (result != Success)
460706f2543Smrg	return result;
461706f2543Smrg
462706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->window,
463706f2543Smrg				     XRT_WINDOW, client, DixWriteAccess);
464706f2543Smrg    if (result != Success)
465706f2543Smrg	return result;
466706f2543Smrg
467706f2543Smrg    if ((Mask)stuff->mask & CWSibling) {
468706f2543Smrg	XID tmp;
469706f2543Smrg	sib_offset = Ones((Mask)stuff->mask & (CWSibling - 1));
470706f2543Smrg	if ((tmp = *((CARD32 *) &stuff[1] + sib_offset))) {
471706f2543Smrg	    result = dixLookupResourceByType((pointer *)&sib, tmp, XRT_WINDOW,
472706f2543Smrg					     client, DixReadAccess);
473706f2543Smrg	    if (result != Success)
474706f2543Smrg		return result;
475706f2543Smrg	}
476706f2543Smrg    }
477706f2543Smrg
478706f2543Smrg    if(pWin->parent && ((pWin->parent == screenInfo.screens[0]->root) ||
479706f2543Smrg                        (pWin->parent->drawable.id == screenInfo.screens[0]->screensaver.wid)))
480706f2543Smrg    {
481706f2543Smrg	if ((Mask)stuff->mask & CWX) {
482706f2543Smrg	    x_offset = 0;
483706f2543Smrg	    x = *((CARD32 *)&stuff[1]);
484706f2543Smrg	}
485706f2543Smrg	if ((Mask)stuff->mask & CWY) {
486706f2543Smrg	    y_offset = (x_offset == -1) ? 0 : 1;
487706f2543Smrg	    y = *((CARD32 *) &stuff[1] + y_offset);
488706f2543Smrg	}
489706f2543Smrg    }
490706f2543Smrg
491706f2543Smrg    /* have to go forward or you get expose events before
492706f2543Smrg	ConfigureNotify events */
493706f2543Smrg    FOR_NSCREENS_FORWARD(j) {
494706f2543Smrg	stuff->window = win->info[j].id;
495706f2543Smrg	if(sib)
496706f2543Smrg	    *((CARD32 *) &stuff[1] + sib_offset) = sib->info[j].id;
497706f2543Smrg	if(x_offset >= 0)
498706f2543Smrg	    *((CARD32 *) &stuff[1] + x_offset) = x - screenInfo.screens[j]->x;
499706f2543Smrg	if(y_offset >= 0)
500706f2543Smrg	    *((CARD32 *) &stuff[1] + y_offset) = y - screenInfo.screens[j]->y;
501706f2543Smrg	result = (*SavedProcVector[X_ConfigureWindow])(client);
502706f2543Smrg        if(result != Success) break;
503706f2543Smrg    }
504706f2543Smrg
505706f2543Smrg    return result;
506706f2543Smrg}
507706f2543Smrg
508706f2543Smrg
509706f2543Smrgint PanoramiXCirculateWindow(ClientPtr client)
510706f2543Smrg{
511706f2543Smrg    PanoramiXRes *win;
512706f2543Smrg    int         result, j;
513706f2543Smrg    REQUEST(xCirculateWindowReq);
514706f2543Smrg
515706f2543Smrg    REQUEST_SIZE_MATCH(xCirculateWindowReq);
516706f2543Smrg
517706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->window,
518706f2543Smrg				     XRT_WINDOW, client, DixWriteAccess);
519706f2543Smrg    if (result != Success)
520706f2543Smrg	return result;
521706f2543Smrg
522706f2543Smrg    FOR_NSCREENS_FORWARD(j) {
523706f2543Smrg	stuff->window = win->info[j].id;
524706f2543Smrg	result = (*SavedProcVector[X_CirculateWindow])(client);
525706f2543Smrg        if(result != Success) break;
526706f2543Smrg    }
527706f2543Smrg
528706f2543Smrg    return result;
529706f2543Smrg}
530706f2543Smrg
531706f2543Smrg
532706f2543Smrgint PanoramiXGetGeometry(ClientPtr client)
533706f2543Smrg{
534706f2543Smrg    xGetGeometryReply 	 rep;
535706f2543Smrg    DrawablePtr pDraw;
536706f2543Smrg    int rc;
537706f2543Smrg    REQUEST(xResourceReq);
538706f2543Smrg
539706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
540706f2543Smrg    rc = dixLookupDrawable(&pDraw, stuff->id, client, M_ANY, DixGetAttrAccess);
541706f2543Smrg    if (rc != Success)
542706f2543Smrg	return rc;
543706f2543Smrg
544706f2543Smrg    rep.type = X_Reply;
545706f2543Smrg    rep.length = 0;
546706f2543Smrg    rep.sequenceNumber = client->sequence;
547706f2543Smrg    rep.root = screenInfo.screens[0]->root->drawable.id;
548706f2543Smrg    rep.depth = pDraw->depth;
549706f2543Smrg    rep.width = pDraw->width;
550706f2543Smrg    rep.height = pDraw->height;
551706f2543Smrg    rep.x = rep.y = rep.borderWidth = 0;
552706f2543Smrg
553706f2543Smrg    if (stuff->id == rep.root) {
554706f2543Smrg	xWindowRoot *root  = (xWindowRoot *)
555706f2543Smrg				    (ConnectionInfo + connBlockScreenStart);
556706f2543Smrg
557706f2543Smrg	rep.width = root->pixWidth;
558706f2543Smrg	rep.height = root->pixHeight;
559706f2543Smrg    } else
560706f2543Smrg    if (WindowDrawable(pDraw->type))
561706f2543Smrg    {
562706f2543Smrg        WindowPtr pWin = (WindowPtr)pDraw;
563706f2543Smrg	rep.x = pWin->origin.x - wBorderWidth (pWin);
564706f2543Smrg	rep.y = pWin->origin.y - wBorderWidth (pWin);
565706f2543Smrg	if((pWin->parent == screenInfo.screens[0]->root) ||
566706f2543Smrg           (pWin->parent->drawable.id == screenInfo.screens[0]->screensaver.wid))
567706f2543Smrg        {
568706f2543Smrg	   rep.x += screenInfo.screens[0]->x;
569706f2543Smrg	   rep.y += screenInfo.screens[0]->y;
570706f2543Smrg	}
571706f2543Smrg	rep.borderWidth = pWin->borderWidth;
572706f2543Smrg    }
573706f2543Smrg
574706f2543Smrg    WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep);
575706f2543Smrg    return Success;
576706f2543Smrg}
577706f2543Smrg
578706f2543Smrgint PanoramiXTranslateCoords(ClientPtr client)
579706f2543Smrg{
580706f2543Smrg    INT16 x, y;
581706f2543Smrg    REQUEST(xTranslateCoordsReq);
582706f2543Smrg    int rc;
583706f2543Smrg    WindowPtr pWin, pDst;
584706f2543Smrg    xTranslateCoordsReply rep;
585706f2543Smrg
586706f2543Smrg    REQUEST_SIZE_MATCH(xTranslateCoordsReq);
587706f2543Smrg    rc = dixLookupWindow(&pWin, stuff->srcWid, client, DixReadAccess);
588706f2543Smrg    if (rc != Success)
589706f2543Smrg        return rc;
590706f2543Smrg    rc = dixLookupWindow(&pDst, stuff->dstWid, client, DixReadAccess);
591706f2543Smrg    if (rc != Success)
592706f2543Smrg        return rc;
593706f2543Smrg    rep.type = X_Reply;
594706f2543Smrg    rep.length = 0;
595706f2543Smrg    rep.sequenceNumber = client->sequence;
596706f2543Smrg    rep.sameScreen = xTrue;
597706f2543Smrg    rep.child = None;
598706f2543Smrg
599706f2543Smrg    if((pWin == screenInfo.screens[0]->root) ||
600706f2543Smrg       (pWin->drawable.id == screenInfo.screens[0]->screensaver.wid))
601706f2543Smrg    {
602706f2543Smrg	x = stuff->srcX - screenInfo.screens[0]->x;
603706f2543Smrg	y = stuff->srcY - screenInfo.screens[0]->y;
604706f2543Smrg    } else {
605706f2543Smrg	x = pWin->drawable.x + stuff->srcX;
606706f2543Smrg	y = pWin->drawable.y + stuff->srcY;
607706f2543Smrg    }
608706f2543Smrg    pWin = pDst->firstChild;
609706f2543Smrg    while (pWin) {
610706f2543Smrg	    BoxRec  box;
611706f2543Smrg	    if ((pWin->mapped) &&
612706f2543Smrg		(x >= pWin->drawable.x - wBorderWidth (pWin)) &&
613706f2543Smrg		(x < pWin->drawable.x + (int)pWin->drawable.width +
614706f2543Smrg		 wBorderWidth (pWin)) &&
615706f2543Smrg		(y >= pWin->drawable.y - wBorderWidth (pWin)) &&
616706f2543Smrg		(y < pWin->drawable.y + (int)pWin->drawable.height +
617706f2543Smrg		 wBorderWidth (pWin))
618706f2543Smrg		/* When a window is shaped, a further check
619706f2543Smrg		 * is made to see if the point is inside
620706f2543Smrg		 * borderSize
621706f2543Smrg		 */
622706f2543Smrg		&& (!wBoundingShape(pWin) ||
623706f2543Smrg		    RegionContainsPoint(wBoundingShape(pWin),
624706f2543Smrg					x - pWin->drawable.x,
625706f2543Smrg					y - pWin->drawable.y, &box))
626706f2543Smrg		)
627706f2543Smrg            {
628706f2543Smrg		rep.child = pWin->drawable.id;
629706f2543Smrg		pWin = (WindowPtr) NULL;
630706f2543Smrg	    }
631706f2543Smrg	    else
632706f2543Smrg		pWin = pWin->nextSib;
633706f2543Smrg    }
634706f2543Smrg    rep.dstX = x - pDst->drawable.x;
635706f2543Smrg    rep.dstY = y - pDst->drawable.y;
636706f2543Smrg    if((pDst == screenInfo.screens[0]->root) ||
637706f2543Smrg       (pDst->drawable.id == screenInfo.screens[0]->screensaver.wid))
638706f2543Smrg    {
639706f2543Smrg	rep.dstX += screenInfo.screens[0]->x;
640706f2543Smrg	rep.dstY += screenInfo.screens[0]->y;
641706f2543Smrg    }
642706f2543Smrg
643706f2543Smrg    WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep);
644706f2543Smrg    return Success;
645706f2543Smrg}
646706f2543Smrg
647706f2543Smrgint PanoramiXCreatePixmap(ClientPtr client)
648706f2543Smrg{
649706f2543Smrg    PanoramiXRes *refDraw, *newPix;
650706f2543Smrg    int result, j;
651706f2543Smrg    REQUEST(xCreatePixmapReq);
652706f2543Smrg
653706f2543Smrg    REQUEST_SIZE_MATCH(xCreatePixmapReq);
654706f2543Smrg    client->errorValue = stuff->pid;
655706f2543Smrg
656706f2543Smrg    result = dixLookupResourceByClass((pointer *)&refDraw, stuff->drawable,
657706f2543Smrg				      XRC_DRAWABLE, client, DixReadAccess);
658706f2543Smrg    if (result != Success)
659706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
660706f2543Smrg
661706f2543Smrg    if(!(newPix = malloc(sizeof(PanoramiXRes))))
662706f2543Smrg	return BadAlloc;
663706f2543Smrg
664706f2543Smrg    newPix->type = XRT_PIXMAP;
665706f2543Smrg    newPix->u.pix.shared = FALSE;
666706f2543Smrg    newPix->info[0].id = stuff->pid;
667706f2543Smrg    for(j = 1; j < PanoramiXNumScreens; j++)
668706f2543Smrg	newPix->info[j].id = FakeClientID(client->index);
669706f2543Smrg
670706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
671706f2543Smrg	stuff->pid = newPix->info[j].id;
672706f2543Smrg	stuff->drawable = refDraw->info[j].id;
673706f2543Smrg	result = (*SavedProcVector[X_CreatePixmap])(client);
674706f2543Smrg	if(result != Success) break;
675706f2543Smrg    }
676706f2543Smrg
677706f2543Smrg    if (result == Success)
678706f2543Smrg	AddResource(newPix->info[0].id, XRT_PIXMAP, newPix);
679706f2543Smrg    else
680706f2543Smrg	free(newPix);
681706f2543Smrg
682706f2543Smrg    return result;
683706f2543Smrg}
684706f2543Smrg
685706f2543Smrg
686706f2543Smrgint PanoramiXFreePixmap(ClientPtr client)
687706f2543Smrg{
688706f2543Smrg    PanoramiXRes *pix;
689706f2543Smrg    int         result, j;
690706f2543Smrg    REQUEST(xResourceReq);
691706f2543Smrg
692706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
693706f2543Smrg
694706f2543Smrg    client->errorValue = stuff->id;
695706f2543Smrg
696706f2543Smrg    result = dixLookupResourceByType((pointer *)&pix, stuff->id, XRT_PIXMAP,
697706f2543Smrg				     client, DixDestroyAccess);
698706f2543Smrg    if (result != Success)
699706f2543Smrg	return result;
700706f2543Smrg
701706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
702706f2543Smrg	stuff->id = pix->info[j].id;
703706f2543Smrg	result = (*SavedProcVector[X_FreePixmap])(client);
704706f2543Smrg	if(result != Success) break;
705706f2543Smrg    }
706706f2543Smrg
707706f2543Smrg    /* Since ProcFreePixmap is using FreeResource, it will free
708706f2543Smrg	our resource for us on the last pass through the loop above */
709706f2543Smrg
710706f2543Smrg    return result;
711706f2543Smrg}
712706f2543Smrg
713706f2543Smrg
714706f2543Smrgint PanoramiXCreateGC(ClientPtr client)
715706f2543Smrg{
716706f2543Smrg    PanoramiXRes *refDraw;
717706f2543Smrg    PanoramiXRes *newGC;
718706f2543Smrg    PanoramiXRes *stip = NULL;
719706f2543Smrg    PanoramiXRes *tile = NULL;
720706f2543Smrg    PanoramiXRes *clip = NULL;
721706f2543Smrg    REQUEST(xCreateGCReq);
722706f2543Smrg    int tile_offset = 0, stip_offset = 0, clip_offset = 0;
723706f2543Smrg    int result, len, j;
724706f2543Smrg    XID tmp;
725706f2543Smrg
726706f2543Smrg    REQUEST_AT_LEAST_SIZE(xCreateGCReq);
727706f2543Smrg
728706f2543Smrg    client->errorValue = stuff->gc;
729706f2543Smrg    len = client->req_len - bytes_to_int32(sizeof(xCreateGCReq));
730706f2543Smrg    if (Ones(stuff->mask) != len)
731706f2543Smrg        return BadLength;
732706f2543Smrg
733706f2543Smrg    result = dixLookupResourceByClass((pointer *)&refDraw, stuff->drawable,
734706f2543Smrg				      XRC_DRAWABLE, client, DixReadAccess);
735706f2543Smrg    if (result != Success)
736706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
737706f2543Smrg
738706f2543Smrg    if ((Mask)stuff->mask & GCTile) {
739706f2543Smrg	tile_offset = Ones((Mask)stuff->mask & (GCTile - 1));
740706f2543Smrg	if ((tmp = *((CARD32 *) &stuff[1] + tile_offset))) {
741706f2543Smrg	    result = dixLookupResourceByType((pointer *)&tile, tmp, XRT_PIXMAP,
742706f2543Smrg					     client, DixReadAccess);
743706f2543Smrg	    if (result != Success)
744706f2543Smrg		return result;
745706f2543Smrg	}
746706f2543Smrg    }
747706f2543Smrg    if ((Mask)stuff->mask & GCStipple) {
748706f2543Smrg	stip_offset = Ones((Mask)stuff->mask & (GCStipple - 1));
749706f2543Smrg	if ((tmp = *((CARD32 *) &stuff[1] + stip_offset))) {
750706f2543Smrg	    result = dixLookupResourceByType((pointer *)&stip, tmp, XRT_PIXMAP,
751706f2543Smrg					     client, DixReadAccess);
752706f2543Smrg	    if (result != Success)
753706f2543Smrg		return result;
754706f2543Smrg	}
755706f2543Smrg    }
756706f2543Smrg    if ((Mask)stuff->mask & GCClipMask) {
757706f2543Smrg	clip_offset = Ones((Mask)stuff->mask & (GCClipMask - 1));
758706f2543Smrg	if ((tmp = *((CARD32 *) &stuff[1] + clip_offset))) {
759706f2543Smrg	    result = dixLookupResourceByType((pointer *)&clip, tmp, XRT_PIXMAP,
760706f2543Smrg					     client, DixReadAccess);
761706f2543Smrg	    if (result != Success)
762706f2543Smrg		return result;
763706f2543Smrg	}
764706f2543Smrg    }
765706f2543Smrg
766706f2543Smrg    if(!(newGC = malloc(sizeof(PanoramiXRes))))
767706f2543Smrg        return BadAlloc;
768706f2543Smrg
769706f2543Smrg    newGC->type = XRT_GC;
770706f2543Smrg    newGC->info[0].id = stuff->gc;
771706f2543Smrg    for(j = 1; j < PanoramiXNumScreens; j++)
772706f2543Smrg        newGC->info[j].id = FakeClientID(client->index);
773706f2543Smrg
774706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
775706f2543Smrg        stuff->gc = newGC->info[j].id;
776706f2543Smrg        stuff->drawable = refDraw->info[j].id;
777706f2543Smrg	if (tile)
778706f2543Smrg	    *((CARD32 *) &stuff[1] + tile_offset) = tile->info[j].id;
779706f2543Smrg	if (stip)
780706f2543Smrg	    *((CARD32 *) &stuff[1] + stip_offset) = stip->info[j].id;
781706f2543Smrg	if (clip)
782706f2543Smrg	    *((CARD32 *) &stuff[1] + clip_offset) = clip->info[j].id;
783706f2543Smrg        result = (*SavedProcVector[X_CreateGC])(client);
784706f2543Smrg        if(result != Success) break;
785706f2543Smrg    }
786706f2543Smrg
787706f2543Smrg    if (result == Success)
788706f2543Smrg        AddResource(newGC->info[0].id, XRT_GC, newGC);
789706f2543Smrg    else
790706f2543Smrg        free(newGC);
791706f2543Smrg
792706f2543Smrg    return result;
793706f2543Smrg}
794706f2543Smrg
795706f2543Smrgint PanoramiXChangeGC(ClientPtr client)
796706f2543Smrg{
797706f2543Smrg    PanoramiXRes *gc;
798706f2543Smrg    PanoramiXRes *stip = NULL;
799706f2543Smrg    PanoramiXRes *tile = NULL;
800706f2543Smrg    PanoramiXRes *clip = NULL;
801706f2543Smrg    REQUEST(xChangeGCReq);
802706f2543Smrg    int tile_offset = 0, stip_offset = 0, clip_offset = 0;
803706f2543Smrg    int result, len, j;
804706f2543Smrg    XID tmp;
805706f2543Smrg
806706f2543Smrg    REQUEST_AT_LEAST_SIZE(xChangeGCReq);
807706f2543Smrg
808706f2543Smrg    len = client->req_len - bytes_to_int32(sizeof(xChangeGCReq));
809706f2543Smrg    if (Ones(stuff->mask) != len)
810706f2543Smrg        return BadLength;
811706f2543Smrg
812706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
813706f2543Smrg				     client, DixReadAccess);
814706f2543Smrg    if (result != Success)
815706f2543Smrg	return result;
816706f2543Smrg
817706f2543Smrg    if ((Mask)stuff->mask & GCTile) {
818706f2543Smrg	tile_offset = Ones((Mask)stuff->mask & (GCTile - 1));
819706f2543Smrg	if ((tmp = *((CARD32 *) &stuff[1] + tile_offset))) {
820706f2543Smrg	    result = dixLookupResourceByType((pointer *)&tile, tmp, XRT_PIXMAP,
821706f2543Smrg					     client, DixReadAccess);
822706f2543Smrg	    if (result != Success)
823706f2543Smrg		return result;
824706f2543Smrg	}
825706f2543Smrg    }
826706f2543Smrg    if ((Mask)stuff->mask & GCStipple) {
827706f2543Smrg	stip_offset = Ones((Mask)stuff->mask & (GCStipple - 1));
828706f2543Smrg	if ((tmp = *((CARD32 *) &stuff[1] + stip_offset))) {
829706f2543Smrg	    result = dixLookupResourceByType((pointer *)&stip, tmp, XRT_PIXMAP,
830706f2543Smrg					     client, DixReadAccess);
831706f2543Smrg	    if (result != Success)
832706f2543Smrg		return result;
833706f2543Smrg	}
834706f2543Smrg    }
835706f2543Smrg    if ((Mask)stuff->mask & GCClipMask) {
836706f2543Smrg	clip_offset = Ones((Mask)stuff->mask & (GCClipMask - 1));
837706f2543Smrg	if ((tmp = *((CARD32 *) &stuff[1] + clip_offset))) {
838706f2543Smrg	    result = dixLookupResourceByType((pointer *)&clip, tmp, XRT_PIXMAP,
839706f2543Smrg					     client, DixReadAccess);
840706f2543Smrg	    if (result != Success)
841706f2543Smrg		return result;
842706f2543Smrg	}
843706f2543Smrg    }
844706f2543Smrg
845706f2543Smrg
846706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
847706f2543Smrg        stuff->gc = gc->info[j].id;
848706f2543Smrg	if (tile)
849706f2543Smrg	    *((CARD32 *) &stuff[1] + tile_offset) = tile->info[j].id;
850706f2543Smrg	if (stip)
851706f2543Smrg	    *((CARD32 *) &stuff[1] + stip_offset) = stip->info[j].id;
852706f2543Smrg	if (clip)
853706f2543Smrg	    *((CARD32 *) &stuff[1] + clip_offset) = clip->info[j].id;
854706f2543Smrg        result = (*SavedProcVector[X_ChangeGC])(client);
855706f2543Smrg        if(result != Success) break;
856706f2543Smrg    }
857706f2543Smrg
858706f2543Smrg    return result;
859706f2543Smrg}
860706f2543Smrg
861706f2543Smrg
862706f2543Smrgint PanoramiXCopyGC(ClientPtr client)
863706f2543Smrg{
864706f2543Smrg    PanoramiXRes *srcGC, *dstGC;
865706f2543Smrg    int         result, j;
866706f2543Smrg    REQUEST(xCopyGCReq);
867706f2543Smrg
868706f2543Smrg    REQUEST_SIZE_MATCH(xCopyGCReq);
869706f2543Smrg
870706f2543Smrg    result = dixLookupResourceByType((pointer *)&srcGC, stuff->srcGC, XRT_GC,
871706f2543Smrg				     client, DixReadAccess);
872706f2543Smrg    if (result != Success)
873706f2543Smrg	return result;
874706f2543Smrg
875706f2543Smrg    result = dixLookupResourceByType((pointer *)&dstGC, stuff->dstGC, XRT_GC,
876706f2543Smrg				     client, DixWriteAccess);
877706f2543Smrg    if (result != Success)
878706f2543Smrg	return result;
879706f2543Smrg
880706f2543Smrg    FOR_NSCREENS(j) {
881706f2543Smrg	stuff->srcGC = srcGC->info[j].id;
882706f2543Smrg	stuff->dstGC = dstGC->info[j].id;
883706f2543Smrg	result = (*SavedProcVector[X_CopyGC])(client);
884706f2543Smrg        if(result != Success) break;
885706f2543Smrg    }
886706f2543Smrg
887706f2543Smrg    return result;
888706f2543Smrg}
889706f2543Smrg
890706f2543Smrg
891706f2543Smrgint PanoramiXSetDashes(ClientPtr client)
892706f2543Smrg{
893706f2543Smrg    PanoramiXRes *gc;
894706f2543Smrg    int         result, j;
895706f2543Smrg    REQUEST(xSetDashesReq);
896706f2543Smrg
897706f2543Smrg    REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes);
898706f2543Smrg
899706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
900706f2543Smrg				     client, DixWriteAccess);
901706f2543Smrg    if (result != Success)
902706f2543Smrg	return result;
903706f2543Smrg
904706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
905706f2543Smrg	stuff->gc = gc->info[j].id;
906706f2543Smrg	result = (*SavedProcVector[X_SetDashes])(client);
907706f2543Smrg        if(result != Success) break;
908706f2543Smrg    }
909706f2543Smrg
910706f2543Smrg    return result;
911706f2543Smrg}
912706f2543Smrg
913706f2543Smrg
914706f2543Smrgint PanoramiXSetClipRectangles(ClientPtr client)
915706f2543Smrg{
916706f2543Smrg    PanoramiXRes *gc;
917706f2543Smrg    int         result, j;
918706f2543Smrg    REQUEST(xSetClipRectanglesReq);
919706f2543Smrg
920706f2543Smrg    REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq);
921706f2543Smrg
922706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
923706f2543Smrg				     client, DixWriteAccess);
924706f2543Smrg    if (result != Success)
925706f2543Smrg	return result;
926706f2543Smrg
927706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
928706f2543Smrg	stuff->gc = gc->info[j].id;
929706f2543Smrg	result = (*SavedProcVector[X_SetClipRectangles])(client);
930706f2543Smrg        if(result != Success) break;
931706f2543Smrg    }
932706f2543Smrg
933706f2543Smrg    return result;
934706f2543Smrg}
935706f2543Smrg
936706f2543Smrg
937706f2543Smrgint PanoramiXFreeGC(ClientPtr client)
938706f2543Smrg{
939706f2543Smrg    PanoramiXRes *gc;
940706f2543Smrg    int         result, j;
941706f2543Smrg    REQUEST(xResourceReq);
942706f2543Smrg
943706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
944706f2543Smrg
945706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->id, XRT_GC,
946706f2543Smrg				     client, DixDestroyAccess);
947706f2543Smrg    if (result != Success)
948706f2543Smrg	return result;
949706f2543Smrg
950706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
951706f2543Smrg	stuff->id = gc->info[j].id;
952706f2543Smrg	result = (*SavedProcVector[X_FreeGC])(client);
953706f2543Smrg	if(result != Success) break;
954706f2543Smrg    }
955706f2543Smrg
956706f2543Smrg    /* Since ProcFreeGC is using FreeResource, it will free
957706f2543Smrg	our resource for us on the last pass through the loop above */
958706f2543Smrg
959706f2543Smrg    return result;
960706f2543Smrg}
961706f2543Smrg
962706f2543Smrg
963706f2543Smrgint PanoramiXClearToBackground(ClientPtr client)
964706f2543Smrg{
965706f2543Smrg    PanoramiXRes *win;
966706f2543Smrg    int         result, j, x, y;
967706f2543Smrg    Bool	isRoot;
968706f2543Smrg    REQUEST(xClearAreaReq);
969706f2543Smrg
970706f2543Smrg    REQUEST_SIZE_MATCH(xClearAreaReq);
971706f2543Smrg
972706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->window,
973706f2543Smrg				     XRT_WINDOW, client, DixWriteAccess);
974706f2543Smrg    if (result != Success)
975706f2543Smrg	return result;
976706f2543Smrg
977706f2543Smrg    x = stuff->x;
978706f2543Smrg    y = stuff->y;
979706f2543Smrg    isRoot = win->u.win.root;
980706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
981706f2543Smrg	stuff->window = win->info[j].id;
982706f2543Smrg	if(isRoot) {
983706f2543Smrg	    stuff->x = x - screenInfo.screens[j]->x;
984706f2543Smrg	    stuff->y = y - screenInfo.screens[j]->y;
985706f2543Smrg	}
986706f2543Smrg	result = (*SavedProcVector[X_ClearArea])(client);
987706f2543Smrg	if(result != Success) break;
988706f2543Smrg    }
989706f2543Smrg
990706f2543Smrg    return result;
991706f2543Smrg}
992706f2543Smrg
993706f2543Smrg
994706f2543Smrg/*
995706f2543Smrg    For Window to Pixmap copies you're screwed since each screen's
996706f2543Smrg    pixmap will look like what it sees on its screen.  Unless the
997706f2543Smrg    screens overlap and the window lies on each, the two copies
998706f2543Smrg    will be out of sync.  To remedy this we do a GetImage and PutImage
999706f2543Smrg    in place of the copy.  Doing this as a single Image isn't quite
1000706f2543Smrg    correct since it will include the obscured areas but we will
1001706f2543Smrg    have to fix this later. (MArk).
1002706f2543Smrg*/
1003706f2543Smrg
1004706f2543Smrgint PanoramiXCopyArea(ClientPtr client)
1005706f2543Smrg{
1006706f2543Smrg    int			j, result, srcx, srcy, dstx, dsty;
1007706f2543Smrg    PanoramiXRes	*gc, *src, *dst;
1008706f2543Smrg    Bool		srcIsRoot = FALSE;
1009706f2543Smrg    Bool		dstIsRoot = FALSE;
1010706f2543Smrg    Bool		srcShared, dstShared;
1011706f2543Smrg    REQUEST(xCopyAreaReq);
1012706f2543Smrg
1013706f2543Smrg    REQUEST_SIZE_MATCH(xCopyAreaReq);
1014706f2543Smrg
1015706f2543Smrg    result = dixLookupResourceByClass((pointer *)&src, stuff->srcDrawable,
1016706f2543Smrg				      XRC_DRAWABLE, client, DixReadAccess);
1017706f2543Smrg    if (result != Success)
1018706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1019706f2543Smrg
1020706f2543Smrg    srcShared = IS_SHARED_PIXMAP(src);
1021706f2543Smrg
1022706f2543Smrg    result = dixLookupResourceByClass((pointer *)&dst, stuff->dstDrawable,
1023706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1024706f2543Smrg    if (result != Success)
1025706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1026706f2543Smrg
1027706f2543Smrg    dstShared = IS_SHARED_PIXMAP(dst);
1028706f2543Smrg
1029706f2543Smrg    if(dstShared && srcShared)
1030706f2543Smrg	return (* SavedProcVector[X_CopyArea])(client);
1031706f2543Smrg
1032706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1033706f2543Smrg				     client, DixReadAccess);
1034706f2543Smrg    if (result != Success)
1035706f2543Smrg	return result;
1036706f2543Smrg
1037706f2543Smrg    if((dst->type == XRT_WINDOW) && dst->u.win.root)
1038706f2543Smrg	dstIsRoot = TRUE;
1039706f2543Smrg    if((src->type == XRT_WINDOW) && src->u.win.root)
1040706f2543Smrg	srcIsRoot = TRUE;
1041706f2543Smrg
1042706f2543Smrg    srcx = stuff->srcX; srcy = stuff->srcY;
1043706f2543Smrg    dstx = stuff->dstX; dsty = stuff->dstY;
1044706f2543Smrg    if((dst->type == XRT_PIXMAP) && (src->type == XRT_WINDOW)) {
1045706f2543Smrg	DrawablePtr drawables[MAXSCREENS];
1046706f2543Smrg	DrawablePtr pDst;
1047706f2543Smrg	GCPtr pGC;
1048706f2543Smrg        char *data;
1049706f2543Smrg	int pitch, rc;
1050706f2543Smrg
1051706f2543Smrg	FOR_NSCREENS(j) {
1052706f2543Smrg	    rc = dixLookupDrawable(drawables+j, src->info[j].id, client, 0,
1053706f2543Smrg				   DixGetAttrAccess);
1054706f2543Smrg	    if (rc != Success)
1055706f2543Smrg		return rc;
1056706f2543Smrg	}
1057706f2543Smrg
1058706f2543Smrg	pitch = PixmapBytePad(stuff->width, drawables[0]->depth);
1059706f2543Smrg	if(!(data = calloc(1, stuff->height * pitch)))
1060706f2543Smrg	    return BadAlloc;
1061706f2543Smrg
1062706f2543Smrg	XineramaGetImageData(drawables, srcx, srcy,
1063706f2543Smrg		stuff->width, stuff->height, ZPixmap, ~0, data, pitch,
1064706f2543Smrg		srcIsRoot);
1065706f2543Smrg
1066706f2543Smrg	FOR_NSCREENS_BACKWARD(j) {
1067706f2543Smrg	    stuff->gc = gc->info[j].id;
1068706f2543Smrg	    VALIDATE_DRAWABLE_AND_GC(dst->info[j].id, pDst, DixWriteAccess);
1069706f2543Smrg	    if(drawables[0]->depth != pDst->depth) {
1070706f2543Smrg		client->errorValue = stuff->dstDrawable;
1071706f2543Smrg		free(data);
1072706f2543Smrg		return BadMatch;
1073706f2543Smrg	    }
1074706f2543Smrg
1075706f2543Smrg	    (*pGC->ops->PutImage) (pDst, pGC, pDst->depth, dstx, dsty,
1076706f2543Smrg				   stuff->width, stuff->height,
1077706f2543Smrg				   0, ZPixmap, data);
1078706f2543Smrg
1079706f2543Smrg	    if(dstShared) break;
1080706f2543Smrg	}
1081706f2543Smrg
1082706f2543Smrg	free(data);
1083706f2543Smrg    } else {
1084706f2543Smrg	DrawablePtr pDst = NULL, pSrc = NULL;
1085706f2543Smrg	GCPtr pGC = NULL;
1086706f2543Smrg	RegionRec totalReg;
1087706f2543Smrg	int rc;
1088706f2543Smrg
1089706f2543Smrg	RegionNull(&totalReg);
1090706f2543Smrg	FOR_NSCREENS_BACKWARD(j) {
1091706f2543Smrg	    RegionPtr pRgn;
1092706f2543Smrg	    stuff->dstDrawable = dst->info[j].id;
1093706f2543Smrg	    stuff->srcDrawable = src->info[j].id;
1094706f2543Smrg	    stuff->gc          = gc->info[j].id;
1095706f2543Smrg 	    if (srcIsRoot) {
1096706f2543Smrg		stuff->srcX = srcx - screenInfo.screens[j]->x;
1097706f2543Smrg		stuff->srcY = srcy - screenInfo.screens[j]->y;
1098706f2543Smrg	    }
1099706f2543Smrg 	    if (dstIsRoot) {
1100706f2543Smrg		stuff->dstX = dstx - screenInfo.screens[j]->x;
1101706f2543Smrg		stuff->dstY = dsty - screenInfo.screens[j]->y;
1102706f2543Smrg	    }
1103706f2543Smrg
1104706f2543Smrg	    VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, DixWriteAccess);
1105706f2543Smrg
1106706f2543Smrg	    if (stuff->dstDrawable != stuff->srcDrawable) {
1107706f2543Smrg		rc = dixLookupDrawable(&pSrc, stuff->srcDrawable, client, 0,
1108706f2543Smrg				       DixReadAccess);
1109706f2543Smrg		if (rc != Success)
1110706f2543Smrg		    return rc;
1111706f2543Smrg
1112706f2543Smrg		if ((pDst->pScreen != pSrc->pScreen) ||
1113706f2543Smrg		    (pDst->depth != pSrc->depth)) {
1114706f2543Smrg			client->errorValue = stuff->dstDrawable;
1115706f2543Smrg			return BadMatch;
1116706f2543Smrg   		}
1117706f2543Smrg 	    } else
1118706f2543Smrg		pSrc = pDst;
1119706f2543Smrg
1120706f2543Smrg	    pRgn = (*pGC->ops->CopyArea)(pSrc, pDst, pGC,
1121706f2543Smrg				stuff->srcX, stuff->srcY,
1122706f2543Smrg				stuff->width, stuff->height,
1123706f2543Smrg				stuff->dstX, stuff->dstY);
1124706f2543Smrg	    if(pGC->graphicsExposures && pRgn) {
1125706f2543Smrg	       if(srcIsRoot) {
1126706f2543Smrg		   RegionTranslate(pRgn,
1127706f2543Smrg			    screenInfo.screens[j]->x, screenInfo.screens[j]->y);
1128706f2543Smrg	       }
1129706f2543Smrg	       RegionAppend(&totalReg, pRgn);
1130706f2543Smrg	       RegionDestroy(pRgn);
1131706f2543Smrg	    }
1132706f2543Smrg
1133706f2543Smrg	    if(dstShared)
1134706f2543Smrg		break;
1135706f2543Smrg	}
1136706f2543Smrg
1137706f2543Smrg	if(pGC->graphicsExposures) {
1138706f2543Smrg	    Bool overlap;
1139706f2543Smrg	    RegionValidate(&totalReg, &overlap);
1140706f2543Smrg	    (*pDst->pScreen->SendGraphicsExpose)(
1141706f2543Smrg		client, &totalReg, stuff->dstDrawable, X_CopyArea, 0);
1142706f2543Smrg	    RegionUninit(&totalReg);
1143706f2543Smrg	}
1144706f2543Smrg    }
1145706f2543Smrg
1146706f2543Smrg    return Success;
1147706f2543Smrg}
1148706f2543Smrg
1149706f2543Smrg
1150706f2543Smrgint PanoramiXCopyPlane(ClientPtr client)
1151706f2543Smrg{
1152706f2543Smrg    int			j, srcx, srcy, dstx, dsty, rc;
1153706f2543Smrg    PanoramiXRes	*gc, *src, *dst;
1154706f2543Smrg    Bool		srcIsRoot = FALSE;
1155706f2543Smrg    Bool		dstIsRoot = FALSE;
1156706f2543Smrg    Bool		srcShared, dstShared;
1157706f2543Smrg    DrawablePtr 	psrcDraw, pdstDraw = NULL;
1158706f2543Smrg    GCPtr 		pGC = NULL;
1159706f2543Smrg    RegionRec		totalReg;
1160706f2543Smrg    REQUEST(xCopyPlaneReq);
1161706f2543Smrg
1162706f2543Smrg    REQUEST_SIZE_MATCH(xCopyPlaneReq);
1163706f2543Smrg
1164706f2543Smrg    rc = dixLookupResourceByClass((pointer *)&src, stuff->srcDrawable,
1165706f2543Smrg				  XRC_DRAWABLE, client, DixReadAccess);
1166706f2543Smrg    if (rc != Success)
1167706f2543Smrg	return (rc == BadValue) ? BadDrawable : rc;
1168706f2543Smrg
1169706f2543Smrg    srcShared = IS_SHARED_PIXMAP(src);
1170706f2543Smrg
1171706f2543Smrg    rc = dixLookupResourceByClass((pointer *)&dst, stuff->dstDrawable,
1172706f2543Smrg				  XRC_DRAWABLE, client, DixWriteAccess);
1173706f2543Smrg    if (rc != Success)
1174706f2543Smrg	return (rc == BadValue) ? BadDrawable : rc;
1175706f2543Smrg
1176706f2543Smrg    dstShared = IS_SHARED_PIXMAP(dst);
1177706f2543Smrg
1178706f2543Smrg    if(dstShared && srcShared)
1179706f2543Smrg	return (* SavedProcVector[X_CopyPlane])(client);
1180706f2543Smrg
1181706f2543Smrg    rc = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1182706f2543Smrg				 client, DixReadAccess);
1183706f2543Smrg    if (rc != Success)
1184706f2543Smrg	return rc;
1185706f2543Smrg
1186706f2543Smrg    if((dst->type == XRT_WINDOW) && dst->u.win.root)
1187706f2543Smrg	dstIsRoot = TRUE;
1188706f2543Smrg    if((src->type == XRT_WINDOW) && src->u.win.root)
1189706f2543Smrg	srcIsRoot = TRUE;
1190706f2543Smrg
1191706f2543Smrg    srcx = stuff->srcX; srcy = stuff->srcY;
1192706f2543Smrg    dstx = stuff->dstX; dsty = stuff->dstY;
1193706f2543Smrg
1194706f2543Smrg    RegionNull(&totalReg);
1195706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
1196706f2543Smrg	RegionPtr pRgn;
1197706f2543Smrg	stuff->dstDrawable = dst->info[j].id;
1198706f2543Smrg	stuff->srcDrawable = src->info[j].id;
1199706f2543Smrg	stuff->gc          = gc->info[j].id;
1200706f2543Smrg	if (srcIsRoot) {
1201706f2543Smrg	    stuff->srcX = srcx - screenInfo.screens[j]->x;
1202706f2543Smrg	    stuff->srcY = srcy - screenInfo.screens[j]->y;
1203706f2543Smrg	}
1204706f2543Smrg	if (dstIsRoot) {
1205706f2543Smrg	    stuff->dstX = dstx - screenInfo.screens[j]->x;
1206706f2543Smrg	    stuff->dstY = dsty - screenInfo.screens[j]->y;
1207706f2543Smrg	}
1208706f2543Smrg
1209706f2543Smrg	VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, DixWriteAccess);
1210706f2543Smrg	if (stuff->dstDrawable != stuff->srcDrawable) {
1211706f2543Smrg	    rc = dixLookupDrawable(&psrcDraw, stuff->srcDrawable, client, 0,
1212706f2543Smrg				   DixReadAccess);
1213706f2543Smrg	    if (rc != Success)
1214706f2543Smrg		return rc;
1215706f2543Smrg
1216706f2543Smrg            if (pdstDraw->pScreen != psrcDraw->pScreen) {
1217706f2543Smrg		client->errorValue = stuff->dstDrawable;
1218706f2543Smrg		return BadMatch;
1219706f2543Smrg	    }
1220706f2543Smrg	} else
1221706f2543Smrg	    psrcDraw = pdstDraw;
1222706f2543Smrg
1223706f2543Smrg	if(stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) ||
1224706f2543Smrg		(stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) {
1225706f2543Smrg	    client->errorValue = stuff->bitPlane;
1226706f2543Smrg	    return BadValue;
1227706f2543Smrg	}
1228706f2543Smrg
1229706f2543Smrg	pRgn = (*pGC->ops->CopyPlane)(psrcDraw, pdstDraw, pGC,
1230706f2543Smrg				stuff->srcX, stuff->srcY,
1231706f2543Smrg				stuff->width, stuff->height,
1232706f2543Smrg				stuff->dstX, stuff->dstY, stuff->bitPlane);
1233706f2543Smrg	if(pGC->graphicsExposures && pRgn) {
1234706f2543Smrg	    RegionAppend(&totalReg, pRgn);
1235706f2543Smrg	    RegionDestroy(pRgn);
1236706f2543Smrg	}
1237706f2543Smrg
1238706f2543Smrg	if(dstShared)
1239706f2543Smrg	    break;
1240706f2543Smrg    }
1241706f2543Smrg
1242706f2543Smrg    if(pGC->graphicsExposures) {
1243706f2543Smrg	Bool overlap;
1244706f2543Smrg	RegionValidate(&totalReg, &overlap);
1245706f2543Smrg	(*pdstDraw->pScreen->SendGraphicsExpose)(
1246706f2543Smrg		client, &totalReg, stuff->dstDrawable, X_CopyPlane, 0);
1247706f2543Smrg	RegionUninit(&totalReg);
1248706f2543Smrg    }
1249706f2543Smrg
1250706f2543Smrg    return Success;
1251706f2543Smrg}
1252706f2543Smrg
1253706f2543Smrg
1254706f2543Smrgint PanoramiXPolyPoint(ClientPtr client)
1255706f2543Smrg{
1256706f2543Smrg    PanoramiXRes *gc, *draw;
1257706f2543Smrg    int 	  result, npoint, j;
1258706f2543Smrg    xPoint 	  *origPts;
1259706f2543Smrg    Bool	  isRoot;
1260706f2543Smrg    REQUEST(xPolyPointReq);
1261706f2543Smrg
1262706f2543Smrg    REQUEST_AT_LEAST_SIZE(xPolyPointReq);
1263706f2543Smrg
1264706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1265706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1266706f2543Smrg    if (result != Success)
1267706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1268706f2543Smrg
1269706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
1270706f2543Smrg	return (*SavedProcVector[X_PolyPoint])(client);
1271706f2543Smrg
1272706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1273706f2543Smrg				     client, DixReadAccess);
1274706f2543Smrg    if (result != Success)
1275706f2543Smrg	return result;
1276706f2543Smrg
1277706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
1278706f2543Smrg    npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq));
1279706f2543Smrg    if (npoint > 0) {
1280706f2543Smrg        origPts = malloc(npoint * sizeof(xPoint));
1281706f2543Smrg        memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
1282706f2543Smrg        FOR_NSCREENS_FORWARD(j){
1283706f2543Smrg
1284706f2543Smrg            if(j) memcpy(&stuff[1], origPts, npoint * sizeof(xPoint));
1285706f2543Smrg
1286706f2543Smrg            if (isRoot) {
1287706f2543Smrg                int x_off = screenInfo.screens[j]->x;
1288706f2543Smrg                int y_off = screenInfo.screens[j]->y;
1289706f2543Smrg
1290706f2543Smrg		if(x_off || y_off) {
1291706f2543Smrg                    xPoint *pnts = (xPoint*)&stuff[1];
1292706f2543Smrg		    int i = (stuff->coordMode==CoordModePrevious) ? 1 : npoint;
1293706f2543Smrg
1294706f2543Smrg		    while(i--) {
1295706f2543Smrg			pnts->x -= x_off;
1296706f2543Smrg			pnts->y -= y_off;
1297706f2543Smrg			pnts++;
1298706f2543Smrg                    }
1299706f2543Smrg		}
1300706f2543Smrg            }
1301706f2543Smrg
1302706f2543Smrg	    stuff->drawable = draw->info[j].id;
1303706f2543Smrg	    stuff->gc = gc->info[j].id;
1304706f2543Smrg	    result = (* SavedProcVector[X_PolyPoint])(client);
1305706f2543Smrg	    if(result != Success) break;
1306706f2543Smrg        }
1307706f2543Smrg        free(origPts);
1308706f2543Smrg        return result;
1309706f2543Smrg    } else
1310706f2543Smrg	return Success;
1311706f2543Smrg}
1312706f2543Smrg
1313706f2543Smrg
1314706f2543Smrgint PanoramiXPolyLine(ClientPtr client)
1315706f2543Smrg{
1316706f2543Smrg    PanoramiXRes *gc, *draw;
1317706f2543Smrg    int 	  result, npoint, j;
1318706f2543Smrg    xPoint 	  *origPts;
1319706f2543Smrg    Bool	  isRoot;
1320706f2543Smrg    REQUEST(xPolyLineReq);
1321706f2543Smrg
1322706f2543Smrg    REQUEST_AT_LEAST_SIZE(xPolyLineReq);
1323706f2543Smrg
1324706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1325706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1326706f2543Smrg    if (result != Success)
1327706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1328706f2543Smrg
1329706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
1330706f2543Smrg	return (*SavedProcVector[X_PolyLine])(client);
1331706f2543Smrg
1332706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1333706f2543Smrg				     client, DixReadAccess);
1334706f2543Smrg    if (result != Success)
1335706f2543Smrg	return result;
1336706f2543Smrg
1337706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
1338706f2543Smrg    npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq));
1339706f2543Smrg    if (npoint > 0){
1340706f2543Smrg        origPts = malloc(npoint * sizeof(xPoint));
1341706f2543Smrg        memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
1342706f2543Smrg        FOR_NSCREENS_FORWARD(j){
1343706f2543Smrg
1344706f2543Smrg            if(j) memcpy(&stuff[1], origPts, npoint * sizeof(xPoint));
1345706f2543Smrg
1346706f2543Smrg            if (isRoot) {
1347706f2543Smrg                int x_off = screenInfo.screens[j]->x;
1348706f2543Smrg                int y_off = screenInfo.screens[j]->y;
1349706f2543Smrg
1350706f2543Smrg		if(x_off || y_off) {
1351706f2543Smrg		    xPoint *pnts = (xPoint*)&stuff[1];
1352706f2543Smrg		    int i = (stuff->coordMode==CoordModePrevious) ? 1 : npoint;
1353706f2543Smrg
1354706f2543Smrg		    while(i--) {
1355706f2543Smrg			pnts->x -= x_off;
1356706f2543Smrg			pnts->y -= y_off;
1357706f2543Smrg			pnts++;
1358706f2543Smrg		    }
1359706f2543Smrg		}
1360706f2543Smrg            }
1361706f2543Smrg
1362706f2543Smrg	    stuff->drawable = draw->info[j].id;
1363706f2543Smrg	    stuff->gc = gc->info[j].id;
1364706f2543Smrg	    result = (* SavedProcVector[X_PolyLine])(client);
1365706f2543Smrg	    if(result != Success) break;
1366706f2543Smrg        }
1367706f2543Smrg        free(origPts);
1368706f2543Smrg        return result;
1369706f2543Smrg   } else
1370706f2543Smrg	return Success;
1371706f2543Smrg}
1372706f2543Smrg
1373706f2543Smrg
1374706f2543Smrgint PanoramiXPolySegment(ClientPtr client)
1375706f2543Smrg{
1376706f2543Smrg    int		  result, nsegs, i, j;
1377706f2543Smrg    PanoramiXRes *gc, *draw;
1378706f2543Smrg    xSegment 	  *origSegs;
1379706f2543Smrg    Bool	  isRoot;
1380706f2543Smrg    REQUEST(xPolySegmentReq);
1381706f2543Smrg
1382706f2543Smrg    REQUEST_AT_LEAST_SIZE(xPolySegmentReq);
1383706f2543Smrg
1384706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1385706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1386706f2543Smrg    if (result != Success)
1387706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1388706f2543Smrg
1389706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
1390706f2543Smrg	return (*SavedProcVector[X_PolySegment])(client);
1391706f2543Smrg
1392706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1393706f2543Smrg				     client, DixReadAccess);
1394706f2543Smrg    if (result != Success)
1395706f2543Smrg	return result;
1396706f2543Smrg
1397706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
1398706f2543Smrg
1399706f2543Smrg    nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq);
1400706f2543Smrg    if(nsegs & 4) return BadLength;
1401706f2543Smrg    nsegs >>= 3;
1402706f2543Smrg    if (nsegs > 0) {
1403706f2543Smrg	origSegs = malloc(nsegs * sizeof(xSegment));
1404706f2543Smrg        memcpy((char *) origSegs, (char *) &stuff[1], nsegs * sizeof(xSegment));
1405706f2543Smrg        FOR_NSCREENS_FORWARD(j){
1406706f2543Smrg
1407706f2543Smrg            if(j) memcpy(&stuff[1], origSegs, nsegs * sizeof(xSegment));
1408706f2543Smrg
1409706f2543Smrg            if (isRoot) {
1410706f2543Smrg                int x_off = screenInfo.screens[j]->x;
1411706f2543Smrg                int y_off = screenInfo.screens[j]->y;
1412706f2543Smrg
1413706f2543Smrg		if(x_off || y_off) {
1414706f2543Smrg		    xSegment *segs = (xSegment*)&stuff[1];
1415706f2543Smrg
1416706f2543Smrg		    for (i = nsegs; i--; segs++) {
1417706f2543Smrg			segs->x1 -= x_off;
1418706f2543Smrg			segs->x2 -= x_off;
1419706f2543Smrg			segs->y1 -= y_off;
1420706f2543Smrg			segs->y2 -= y_off;
1421706f2543Smrg		    }
1422706f2543Smrg		}
1423706f2543Smrg            }
1424706f2543Smrg
1425706f2543Smrg	    stuff->drawable = draw->info[j].id;
1426706f2543Smrg	    stuff->gc = gc->info[j].id;
1427706f2543Smrg	    result = (* SavedProcVector[X_PolySegment])(client);
1428706f2543Smrg	    if(result != Success) break;
1429706f2543Smrg    	}
1430706f2543Smrg	free(origSegs);
1431706f2543Smrg	return result;
1432706f2543Smrg    } else
1433706f2543Smrg	  return Success;
1434706f2543Smrg}
1435706f2543Smrg
1436706f2543Smrg
1437706f2543Smrgint PanoramiXPolyRectangle(ClientPtr client)
1438706f2543Smrg{
1439706f2543Smrg    int 	  result, nrects, i, j;
1440706f2543Smrg    PanoramiXRes *gc, *draw;
1441706f2543Smrg    Bool	  isRoot;
1442706f2543Smrg    xRectangle 	  *origRecs;
1443706f2543Smrg    REQUEST(xPolyRectangleReq);
1444706f2543Smrg
1445706f2543Smrg    REQUEST_AT_LEAST_SIZE(xPolyRectangleReq);
1446706f2543Smrg
1447706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1448706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1449706f2543Smrg    if (result != Success)
1450706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1451706f2543Smrg
1452706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
1453706f2543Smrg	return (*SavedProcVector[X_PolyRectangle])(client);
1454706f2543Smrg
1455706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1456706f2543Smrg				     client, DixReadAccess);
1457706f2543Smrg    if (result != Success)
1458706f2543Smrg	return result;
1459706f2543Smrg
1460706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
1461706f2543Smrg
1462706f2543Smrg    nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq);
1463706f2543Smrg    if(nrects & 4) return BadLength;
1464706f2543Smrg    nrects >>= 3;
1465706f2543Smrg    if (nrects > 0){
1466706f2543Smrg	origRecs = malloc(nrects * sizeof(xRectangle));
1467706f2543Smrg	memcpy((char *)origRecs,(char *)&stuff[1],nrects * sizeof(xRectangle));
1468706f2543Smrg        FOR_NSCREENS_FORWARD(j){
1469706f2543Smrg
1470706f2543Smrg            if(j) memcpy(&stuff[1], origRecs, nrects * sizeof(xRectangle));
1471706f2543Smrg
1472706f2543Smrg	    if (isRoot) {
1473706f2543Smrg		int x_off = screenInfo.screens[j]->x;
1474706f2543Smrg		int y_off = screenInfo.screens[j]->y;
1475706f2543Smrg
1476706f2543Smrg
1477706f2543Smrg		if(x_off || y_off) {
1478706f2543Smrg	    	    xRectangle *rects = (xRectangle *) &stuff[1];
1479706f2543Smrg
1480706f2543Smrg		    for (i = nrects; i--; rects++) {
1481706f2543Smrg			rects->x -= x_off;
1482706f2543Smrg			rects->y -= y_off;
1483706f2543Smrg		    }
1484706f2543Smrg		}
1485706f2543Smrg	    }
1486706f2543Smrg
1487706f2543Smrg	    stuff->drawable = draw->info[j].id;
1488706f2543Smrg	    stuff->gc = gc->info[j].id;
1489706f2543Smrg	    result = (* SavedProcVector[X_PolyRectangle])(client);
1490706f2543Smrg	    if(result != Success) break;
1491706f2543Smrg	}
1492706f2543Smrg	free(origRecs);
1493706f2543Smrg	return result;
1494706f2543Smrg    } else
1495706f2543Smrg       return Success;
1496706f2543Smrg}
1497706f2543Smrg
1498706f2543Smrg
1499706f2543Smrgint PanoramiXPolyArc(ClientPtr client)
1500706f2543Smrg{
1501706f2543Smrg    int 	  result, narcs, i, j;
1502706f2543Smrg    PanoramiXRes *gc, *draw;
1503706f2543Smrg    Bool	  isRoot;
1504706f2543Smrg    xArc	  *origArcs;
1505706f2543Smrg    REQUEST(xPolyArcReq);
1506706f2543Smrg
1507706f2543Smrg    REQUEST_AT_LEAST_SIZE(xPolyArcReq);
1508706f2543Smrg
1509706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1510706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1511706f2543Smrg    if (result != Success)
1512706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1513706f2543Smrg
1514706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
1515706f2543Smrg	return (*SavedProcVector[X_PolyArc])(client);
1516706f2543Smrg
1517706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1518706f2543Smrg				     client, DixReadAccess);
1519706f2543Smrg    if (result != Success)
1520706f2543Smrg	return result;
1521706f2543Smrg
1522706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
1523706f2543Smrg
1524706f2543Smrg    narcs = (client->req_len << 2) - sizeof(xPolyArcReq);
1525706f2543Smrg    if(narcs % sizeof(xArc)) return BadLength;
1526706f2543Smrg    narcs /= sizeof(xArc);
1527706f2543Smrg    if (narcs > 0){
1528706f2543Smrg	origArcs = malloc(narcs * sizeof(xArc));
1529706f2543Smrg	memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc));
1530706f2543Smrg        FOR_NSCREENS_FORWARD(j){
1531706f2543Smrg
1532706f2543Smrg            if(j) memcpy(&stuff[1], origArcs, narcs * sizeof(xArc));
1533706f2543Smrg
1534706f2543Smrg	    if (isRoot) {
1535706f2543Smrg		int x_off = screenInfo.screens[j]->x;
1536706f2543Smrg		int y_off = screenInfo.screens[j]->y;
1537706f2543Smrg
1538706f2543Smrg		if(x_off || y_off) {
1539706f2543Smrg		    xArc *arcs = (xArc *) &stuff[1];
1540706f2543Smrg
1541706f2543Smrg		    for (i = narcs; i--; arcs++) {
1542706f2543Smrg			arcs->x -= x_off;
1543706f2543Smrg			arcs->y -= y_off;
1544706f2543Smrg		    }
1545706f2543Smrg		}
1546706f2543Smrg            }
1547706f2543Smrg	    stuff->drawable = draw->info[j].id;
1548706f2543Smrg	    stuff->gc = gc->info[j].id;
1549706f2543Smrg	    result = (* SavedProcVector[X_PolyArc])(client);
1550706f2543Smrg	    if(result != Success) break;
1551706f2543Smrg        }
1552706f2543Smrg	free(origArcs);
1553706f2543Smrg	return result;
1554706f2543Smrg    } else
1555706f2543Smrg       return Success;
1556706f2543Smrg}
1557706f2543Smrg
1558706f2543Smrg
1559706f2543Smrgint PanoramiXFillPoly(ClientPtr client)
1560706f2543Smrg{
1561706f2543Smrg    int 	  result, count, j;
1562706f2543Smrg    PanoramiXRes *gc, *draw;
1563706f2543Smrg    Bool	  isRoot;
1564706f2543Smrg    DDXPointPtr	  locPts;
1565706f2543Smrg    REQUEST(xFillPolyReq);
1566706f2543Smrg
1567706f2543Smrg    REQUEST_AT_LEAST_SIZE(xFillPolyReq);
1568706f2543Smrg
1569706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1570706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1571706f2543Smrg    if (result != Success)
1572706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1573706f2543Smrg
1574706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
1575706f2543Smrg	return (*SavedProcVector[X_FillPoly])(client);
1576706f2543Smrg
1577706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1578706f2543Smrg				     client, DixReadAccess);
1579706f2543Smrg    if (result != Success)
1580706f2543Smrg	return result;
1581706f2543Smrg
1582706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
1583706f2543Smrg
1584706f2543Smrg    count = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq));
1585706f2543Smrg    if (count > 0){
1586706f2543Smrg	locPts = malloc(count * sizeof(DDXPointRec));
1587706f2543Smrg	memcpy((char *)locPts, (char *)&stuff[1], count * sizeof(DDXPointRec));
1588706f2543Smrg        FOR_NSCREENS_FORWARD(j){
1589706f2543Smrg
1590706f2543Smrg	    if(j) memcpy(&stuff[1], locPts, count * sizeof(DDXPointRec));
1591706f2543Smrg
1592706f2543Smrg	    if (isRoot) {
1593706f2543Smrg		int x_off = screenInfo.screens[j]->x;
1594706f2543Smrg		int y_off = screenInfo.screens[j]->y;
1595706f2543Smrg
1596706f2543Smrg		if(x_off || y_off) {
1597706f2543Smrg		    DDXPointPtr pnts = (DDXPointPtr)&stuff[1];
1598706f2543Smrg		    int i = (stuff->coordMode==CoordModePrevious) ? 1 : count;
1599706f2543Smrg
1600706f2543Smrg		    while(i--) {
1601706f2543Smrg			pnts->x -= x_off;
1602706f2543Smrg			pnts->y -= y_off;
1603706f2543Smrg			pnts++;
1604706f2543Smrg		    }
1605706f2543Smrg		}
1606706f2543Smrg	    }
1607706f2543Smrg
1608706f2543Smrg	    stuff->drawable = draw->info[j].id;
1609706f2543Smrg	    stuff->gc = gc->info[j].id;
1610706f2543Smrg	    result = (* SavedProcVector[X_FillPoly])(client);
1611706f2543Smrg	    if(result != Success) break;
1612706f2543Smrg	}
1613706f2543Smrg	free(locPts);
1614706f2543Smrg	return result;
1615706f2543Smrg    } else
1616706f2543Smrg       return Success;
1617706f2543Smrg}
1618706f2543Smrg
1619706f2543Smrg
1620706f2543Smrgint PanoramiXPolyFillRectangle(ClientPtr client)
1621706f2543Smrg{
1622706f2543Smrg    int 	  result, things, i, j;
1623706f2543Smrg    PanoramiXRes *gc, *draw;
1624706f2543Smrg    Bool	  isRoot;
1625706f2543Smrg    xRectangle	  *origRects;
1626706f2543Smrg    REQUEST(xPolyFillRectangleReq);
1627706f2543Smrg
1628706f2543Smrg    REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq);
1629706f2543Smrg
1630706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1631706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1632706f2543Smrg    if (result != Success)
1633706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1634706f2543Smrg
1635706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
1636706f2543Smrg	return (*SavedProcVector[X_PolyFillRectangle])(client);
1637706f2543Smrg
1638706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1639706f2543Smrg				     client, DixReadAccess);
1640706f2543Smrg    if (result != Success)
1641706f2543Smrg	return result;
1642706f2543Smrg
1643706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
1644706f2543Smrg
1645706f2543Smrg    things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq);
1646706f2543Smrg    if(things & 4) return BadLength;
1647706f2543Smrg    things >>= 3;
1648706f2543Smrg    if (things > 0){
1649706f2543Smrg	origRects = malloc(things * sizeof(xRectangle));
1650706f2543Smrg	memcpy((char*)origRects,(char*)&stuff[1], things * sizeof(xRectangle));
1651706f2543Smrg        FOR_NSCREENS_FORWARD(j){
1652706f2543Smrg
1653706f2543Smrg	    if(j) memcpy(&stuff[1], origRects, things * sizeof(xRectangle));
1654706f2543Smrg
1655706f2543Smrg	    if (isRoot) {
1656706f2543Smrg		int x_off = screenInfo.screens[j]->x;
1657706f2543Smrg		int y_off = screenInfo.screens[j]->y;
1658706f2543Smrg
1659706f2543Smrg		if(x_off || y_off) {
1660706f2543Smrg		    xRectangle *rects = (xRectangle *) &stuff[1];
1661706f2543Smrg
1662706f2543Smrg		    for (i = things; i--; rects++) {
1663706f2543Smrg			rects->x -= x_off;
1664706f2543Smrg			rects->y -= y_off;
1665706f2543Smrg		    }
1666706f2543Smrg		}
1667706f2543Smrg	    }
1668706f2543Smrg
1669706f2543Smrg	    stuff->drawable = draw->info[j].id;
1670706f2543Smrg	    stuff->gc = gc->info[j].id;
1671706f2543Smrg	    result = (* SavedProcVector[X_PolyFillRectangle])(client);
1672706f2543Smrg	    if(result != Success) break;
1673706f2543Smrg	}
1674706f2543Smrg	free(origRects);
1675706f2543Smrg	return result;
1676706f2543Smrg    } else
1677706f2543Smrg       return Success;
1678706f2543Smrg}
1679706f2543Smrg
1680706f2543Smrg
1681706f2543Smrgint PanoramiXPolyFillArc(ClientPtr client)
1682706f2543Smrg{
1683706f2543Smrg    PanoramiXRes *gc, *draw;
1684706f2543Smrg    Bool	  isRoot;
1685706f2543Smrg    int 	  result, narcs, i, j;
1686706f2543Smrg    xArc	  *origArcs;
1687706f2543Smrg    REQUEST(xPolyFillArcReq);
1688706f2543Smrg
1689706f2543Smrg    REQUEST_AT_LEAST_SIZE(xPolyFillArcReq);
1690706f2543Smrg
1691706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1692706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1693706f2543Smrg    if (result != Success)
1694706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1695706f2543Smrg
1696706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
1697706f2543Smrg	return (*SavedProcVector[X_PolyFillArc])(client);
1698706f2543Smrg
1699706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1700706f2543Smrg				     client, DixReadAccess);
1701706f2543Smrg    if (result != Success)
1702706f2543Smrg	return result;
1703706f2543Smrg
1704706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
1705706f2543Smrg
1706706f2543Smrg    narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq);
1707706f2543Smrg    if (narcs % sizeof(xArc)) return BadLength;
1708706f2543Smrg    narcs /= sizeof(xArc);
1709706f2543Smrg    if (narcs > 0) {
1710706f2543Smrg	origArcs = malloc(narcs * sizeof(xArc));
1711706f2543Smrg	memcpy((char *) origArcs, (char *)&stuff[1], narcs * sizeof(xArc));
1712706f2543Smrg        FOR_NSCREENS_FORWARD(j){
1713706f2543Smrg
1714706f2543Smrg	    if(j) memcpy(&stuff[1], origArcs, narcs * sizeof(xArc));
1715706f2543Smrg
1716706f2543Smrg	    if (isRoot) {
1717706f2543Smrg		int x_off = screenInfo.screens[j]->x;
1718706f2543Smrg		int y_off = screenInfo.screens[j]->y;
1719706f2543Smrg
1720706f2543Smrg		if(x_off || y_off) {
1721706f2543Smrg		    xArc *arcs = (xArc *) &stuff[1];
1722706f2543Smrg
1723706f2543Smrg		    for (i = narcs; i--; arcs++) {
1724706f2543Smrg			arcs->x -= x_off;
1725706f2543Smrg			arcs->y -= y_off;
1726706f2543Smrg		    }
1727706f2543Smrg		}
1728706f2543Smrg	    }
1729706f2543Smrg
1730706f2543Smrg	    stuff->drawable = draw->info[j].id;
1731706f2543Smrg	    stuff->gc = gc->info[j].id;
1732706f2543Smrg	    result = (* SavedProcVector[X_PolyFillArc])(client);
1733706f2543Smrg	    if(result != Success) break;
1734706f2543Smrg	}
1735706f2543Smrg	free(origArcs);
1736706f2543Smrg	return result;
1737706f2543Smrg    } else
1738706f2543Smrg       return Success;
1739706f2543Smrg}
1740706f2543Smrg
1741706f2543Smrg
1742706f2543Smrgint PanoramiXPutImage(ClientPtr client)
1743706f2543Smrg{
1744706f2543Smrg    PanoramiXRes *gc, *draw;
1745706f2543Smrg    Bool	  isRoot;
1746706f2543Smrg    int		  j, result, orig_x, orig_y;
1747706f2543Smrg    REQUEST(xPutImageReq);
1748706f2543Smrg
1749706f2543Smrg    REQUEST_AT_LEAST_SIZE(xPutImageReq);
1750706f2543Smrg
1751706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1752706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1753706f2543Smrg    if (result != Success)
1754706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1755706f2543Smrg
1756706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
1757706f2543Smrg	return (*SavedProcVector[X_PutImage])(client);
1758706f2543Smrg
1759706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1760706f2543Smrg				     client, DixReadAccess);
1761706f2543Smrg    if (result != Success)
1762706f2543Smrg	return result;
1763706f2543Smrg
1764706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
1765706f2543Smrg
1766706f2543Smrg    orig_x = stuff->dstX;
1767706f2543Smrg    orig_y = stuff->dstY;
1768706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
1769706f2543Smrg	if (isRoot) {
1770706f2543Smrg	  stuff->dstX = orig_x - screenInfo.screens[j]->x;
1771706f2543Smrg	  stuff->dstY = orig_y - screenInfo.screens[j]->y;
1772706f2543Smrg	}
1773706f2543Smrg	stuff->drawable = draw->info[j].id;
1774706f2543Smrg	stuff->gc = gc->info[j].id;
1775706f2543Smrg	result = (* SavedProcVector[X_PutImage])(client);
1776706f2543Smrg	if(result != Success) break;
1777706f2543Smrg    }
1778706f2543Smrg    return result;
1779706f2543Smrg}
1780706f2543Smrg
1781706f2543Smrg
1782706f2543Smrgint PanoramiXGetImage(ClientPtr client)
1783706f2543Smrg{
1784706f2543Smrg    DrawablePtr 	drawables[MAXSCREENS];
1785706f2543Smrg    DrawablePtr 	pDraw;
1786706f2543Smrg    PanoramiXRes	*draw;
1787706f2543Smrg    xGetImageReply	xgi;
1788706f2543Smrg    Bool		isRoot;
1789706f2543Smrg    char		*pBuf;
1790706f2543Smrg    int         	i, x, y, w, h, format, rc;
1791706f2543Smrg    Mask		plane = 0, planemask;
1792706f2543Smrg    int			linesDone, nlines, linesPerBuf;
1793706f2543Smrg    long		widthBytesLine, length;
1794706f2543Smrg
1795706f2543Smrg    REQUEST(xGetImageReq);
1796706f2543Smrg
1797706f2543Smrg    REQUEST_SIZE_MATCH(xGetImageReq);
1798706f2543Smrg
1799706f2543Smrg    if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) {
1800706f2543Smrg	client->errorValue = stuff->format;
1801706f2543Smrg        return BadValue;
1802706f2543Smrg    }
1803706f2543Smrg
1804706f2543Smrg    rc = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1805706f2543Smrg				  XRC_DRAWABLE, client, DixWriteAccess);
1806706f2543Smrg    if (rc != Success)
1807706f2543Smrg	return (rc == BadValue) ? BadDrawable : rc;
1808706f2543Smrg
1809706f2543Smrg    if(draw->type == XRT_PIXMAP)
1810706f2543Smrg	return (*SavedProcVector[X_GetImage])(client);
1811706f2543Smrg
1812706f2543Smrg    rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0,
1813706f2543Smrg			   DixReadAccess);
1814706f2543Smrg    if (rc != Success)
1815706f2543Smrg	return rc;
1816706f2543Smrg
1817706f2543Smrg    if(!((WindowPtr)pDraw)->realized)
1818706f2543Smrg	return BadMatch;
1819706f2543Smrg
1820706f2543Smrg    x = stuff->x;
1821706f2543Smrg    y = stuff->y;
1822706f2543Smrg    w = stuff->width;
1823706f2543Smrg    h = stuff->height;
1824706f2543Smrg    format = stuff->format;
1825706f2543Smrg    planemask = stuff->planeMask;
1826706f2543Smrg
1827706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
1828706f2543Smrg
1829706f2543Smrg    if(isRoot) {
1830706f2543Smrg      if( /* check for being onscreen */
1831706f2543Smrg	x < 0 || x + w > PanoramiXPixWidth ||
1832706f2543Smrg	y < 0 || y + h > PanoramiXPixHeight )
1833706f2543Smrg	    return BadMatch;
1834706f2543Smrg    } else {
1835706f2543Smrg      if( /* check for being onscreen */
1836706f2543Smrg	screenInfo.screens[0]->x + pDraw->x + x < 0 ||
1837706f2543Smrg	screenInfo.screens[0]->x + pDraw->x + x + w > PanoramiXPixWidth ||
1838706f2543Smrg	screenInfo.screens[0]->y + pDraw->y + y < 0 ||
1839706f2543Smrg	screenInfo.screens[0]->y + pDraw->y + y + h > PanoramiXPixHeight ||
1840706f2543Smrg	 /* check for being inside of border */
1841706f2543Smrg       	x < - wBorderWidth((WindowPtr)pDraw) ||
1842706f2543Smrg	x + w > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width ||
1843706f2543Smrg	y < -wBorderWidth((WindowPtr)pDraw) ||
1844706f2543Smrg	y + h > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height)
1845706f2543Smrg	    return BadMatch;
1846706f2543Smrg    }
1847706f2543Smrg
1848706f2543Smrg    drawables[0] = pDraw;
1849706f2543Smrg    for(i = 1; i < PanoramiXNumScreens; i++) {
1850706f2543Smrg	rc = dixLookupDrawable(drawables+i, draw->info[i].id, client, 0,
1851706f2543Smrg			       DixGetAttrAccess);
1852706f2543Smrg	if (rc != Success)
1853706f2543Smrg	    return rc;
1854706f2543Smrg    }
1855706f2543Smrg
1856706f2543Smrg    xgi.visual = wVisual (((WindowPtr) pDraw));
1857706f2543Smrg    xgi.type = X_Reply;
1858706f2543Smrg    xgi.sequenceNumber = client->sequence;
1859706f2543Smrg    xgi.depth = pDraw->depth;
1860706f2543Smrg    if(format == ZPixmap) {
1861706f2543Smrg	widthBytesLine = PixmapBytePad(w, pDraw->depth);
1862706f2543Smrg	length = widthBytesLine * h;
1863706f2543Smrg
1864706f2543Smrg
1865706f2543Smrg    } else {
1866706f2543Smrg	widthBytesLine = BitmapBytePad(w);
1867706f2543Smrg	plane = ((Mask)1) << (pDraw->depth - 1);
1868706f2543Smrg	/* only planes asked for */
1869706f2543Smrg	length = widthBytesLine * h *
1870706f2543Smrg		 Ones(planemask & (plane | (plane - 1)));
1871706f2543Smrg
1872706f2543Smrg    }
1873706f2543Smrg
1874706f2543Smrg    xgi.length = bytes_to_int32(length);
1875706f2543Smrg
1876706f2543Smrg    if (widthBytesLine == 0 || h == 0)
1877706f2543Smrg	linesPerBuf = 0;
1878706f2543Smrg    else if (widthBytesLine >= XINERAMA_IMAGE_BUFSIZE)
1879706f2543Smrg	linesPerBuf = 1;
1880706f2543Smrg    else {
1881706f2543Smrg	linesPerBuf = XINERAMA_IMAGE_BUFSIZE / widthBytesLine;
1882706f2543Smrg	if (linesPerBuf > h)
1883706f2543Smrg	    linesPerBuf = h;
1884706f2543Smrg    }
1885706f2543Smrg    length = linesPerBuf * widthBytesLine;
1886706f2543Smrg    if(!(pBuf = malloc(length)))
1887706f2543Smrg	return BadAlloc;
1888706f2543Smrg
1889706f2543Smrg    WriteReplyToClient(client, sizeof (xGetImageReply), &xgi);
1890706f2543Smrg
1891706f2543Smrg    if (linesPerBuf == 0) {
1892706f2543Smrg	/* nothing to do */
1893706f2543Smrg    }
1894706f2543Smrg    else if (format == ZPixmap) {
1895706f2543Smrg        linesDone = 0;
1896706f2543Smrg        while (h - linesDone > 0) {
1897706f2543Smrg	    nlines = min(linesPerBuf, h - linesDone);
1898706f2543Smrg
1899706f2543Smrg	    if(pDraw->depth == 1)
1900706f2543Smrg		memset(pBuf, 0, nlines * widthBytesLine);
1901706f2543Smrg
1902706f2543Smrg	    XineramaGetImageData(drawables, x, y + linesDone, w, nlines,
1903706f2543Smrg			format, planemask, pBuf, widthBytesLine, isRoot);
1904706f2543Smrg
1905706f2543Smrg		(void)WriteToClient(client,
1906706f2543Smrg				    (int)(nlines * widthBytesLine),
1907706f2543Smrg				    pBuf);
1908706f2543Smrg	    linesDone += nlines;
1909706f2543Smrg        }
1910706f2543Smrg    } else { /* XYPixmap */
1911706f2543Smrg        for (; plane; plane >>= 1) {
1912706f2543Smrg	    if (planemask & plane) {
1913706f2543Smrg	        linesDone = 0;
1914706f2543Smrg	        while (h - linesDone > 0) {
1915706f2543Smrg		    nlines = min(linesPerBuf, h - linesDone);
1916706f2543Smrg
1917706f2543Smrg		    memset(pBuf, 0, nlines * widthBytesLine);
1918706f2543Smrg
1919706f2543Smrg		    XineramaGetImageData(drawables, x, y + linesDone, w,
1920706f2543Smrg					nlines, format, plane, pBuf,
1921706f2543Smrg					widthBytesLine, isRoot);
1922706f2543Smrg
1923706f2543Smrg		    (void)WriteToClient(client,
1924706f2543Smrg				    (int)(nlines * widthBytesLine),
1925706f2543Smrg				    pBuf);
1926706f2543Smrg
1927706f2543Smrg		    linesDone += nlines;
1928706f2543Smrg		}
1929706f2543Smrg            }
1930706f2543Smrg	}
1931706f2543Smrg    }
1932706f2543Smrg    free(pBuf);
1933706f2543Smrg    return Success;
1934706f2543Smrg}
1935706f2543Smrg
1936706f2543Smrg
1937706f2543Smrg/* The text stuff should be rewritten so that duplication happens
1938706f2543Smrg   at the GlyphBlt level.  That is, loading the font and getting
1939706f2543Smrg   the glyphs should only happen once */
1940706f2543Smrg
1941706f2543Smrgint
1942706f2543SmrgPanoramiXPolyText8(ClientPtr client)
1943706f2543Smrg{
1944706f2543Smrg    PanoramiXRes *gc, *draw;
1945706f2543Smrg    Bool	  isRoot;
1946706f2543Smrg    int 	  result, j;
1947706f2543Smrg    int	 	  orig_x, orig_y;
1948706f2543Smrg    REQUEST(xPolyTextReq);
1949706f2543Smrg
1950706f2543Smrg    REQUEST_AT_LEAST_SIZE(xPolyTextReq);
1951706f2543Smrg
1952706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1953706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1954706f2543Smrg    if (result != Success)
1955706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1956706f2543Smrg
1957706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
1958706f2543Smrg	return (*SavedProcVector[X_PolyText8])(client);
1959706f2543Smrg
1960706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
1961706f2543Smrg				     client, DixReadAccess);
1962706f2543Smrg    if (result != Success)
1963706f2543Smrg	return result;
1964706f2543Smrg
1965706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
1966706f2543Smrg
1967706f2543Smrg    orig_x = stuff->x;
1968706f2543Smrg    orig_y = stuff->y;
1969706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
1970706f2543Smrg	stuff->drawable = draw->info[j].id;
1971706f2543Smrg	stuff->gc = gc->info[j].id;
1972706f2543Smrg	if (isRoot) {
1973706f2543Smrg	    stuff->x = orig_x - screenInfo.screens[j]->x;
1974706f2543Smrg	    stuff->y = orig_y - screenInfo.screens[j]->y;
1975706f2543Smrg	}
1976706f2543Smrg	result = (*SavedProcVector[X_PolyText8])(client);
1977706f2543Smrg	if(result != Success) break;
1978706f2543Smrg    }
1979706f2543Smrg    return result;
1980706f2543Smrg}
1981706f2543Smrg
1982706f2543Smrgint
1983706f2543SmrgPanoramiXPolyText16(ClientPtr client)
1984706f2543Smrg{
1985706f2543Smrg    PanoramiXRes *gc, *draw;
1986706f2543Smrg    Bool	  isRoot;
1987706f2543Smrg    int 	  result, j;
1988706f2543Smrg    int	 	  orig_x, orig_y;
1989706f2543Smrg    REQUEST(xPolyTextReq);
1990706f2543Smrg
1991706f2543Smrg    REQUEST_AT_LEAST_SIZE(xPolyTextReq);
1992706f2543Smrg
1993706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
1994706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
1995706f2543Smrg    if (result != Success)
1996706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
1997706f2543Smrg
1998706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
1999706f2543Smrg	return (*SavedProcVector[X_PolyText16])(client);
2000706f2543Smrg
2001706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
2002706f2543Smrg				     client, DixReadAccess);
2003706f2543Smrg    if (result != Success)
2004706f2543Smrg	return result;
2005706f2543Smrg
2006706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
2007706f2543Smrg
2008706f2543Smrg    orig_x = stuff->x;
2009706f2543Smrg    orig_y = stuff->y;
2010706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2011706f2543Smrg	stuff->drawable = draw->info[j].id;
2012706f2543Smrg	stuff->gc = gc->info[j].id;
2013706f2543Smrg	if (isRoot) {
2014706f2543Smrg	    stuff->x = orig_x - screenInfo.screens[j]->x;
2015706f2543Smrg	    stuff->y = orig_y - screenInfo.screens[j]->y;
2016706f2543Smrg	}
2017706f2543Smrg	result = (*SavedProcVector[X_PolyText16])(client);
2018706f2543Smrg	if(result != Success) break;
2019706f2543Smrg    }
2020706f2543Smrg    return result;
2021706f2543Smrg}
2022706f2543Smrg
2023706f2543Smrg
2024706f2543Smrgint PanoramiXImageText8(ClientPtr client)
2025706f2543Smrg{
2026706f2543Smrg    int 	  result, j;
2027706f2543Smrg    PanoramiXRes *gc, *draw;
2028706f2543Smrg    Bool	  isRoot;
2029706f2543Smrg    int		  orig_x, orig_y;
2030706f2543Smrg    REQUEST(xImageTextReq);
2031706f2543Smrg
2032706f2543Smrg    REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars);
2033706f2543Smrg
2034706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
2035706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
2036706f2543Smrg    if (result != Success)
2037706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
2038706f2543Smrg
2039706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
2040706f2543Smrg	return (*SavedProcVector[X_ImageText8])(client);
2041706f2543Smrg
2042706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
2043706f2543Smrg				     client, DixReadAccess);
2044706f2543Smrg    if (result != Success)
2045706f2543Smrg	return result;
2046706f2543Smrg
2047706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
2048706f2543Smrg
2049706f2543Smrg    orig_x = stuff->x;
2050706f2543Smrg    orig_y = stuff->y;
2051706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2052706f2543Smrg	stuff->drawable = draw->info[j].id;
2053706f2543Smrg	stuff->gc = gc->info[j].id;
2054706f2543Smrg	if (isRoot) {
2055706f2543Smrg	    stuff->x = orig_x - screenInfo.screens[j]->x;
2056706f2543Smrg	    stuff->y = orig_y - screenInfo.screens[j]->y;
2057706f2543Smrg	}
2058706f2543Smrg	result = (*SavedProcVector[X_ImageText8])(client);
2059706f2543Smrg	if(result != Success) break;
2060706f2543Smrg    }
2061706f2543Smrg    return result;
2062706f2543Smrg}
2063706f2543Smrg
2064706f2543Smrg
2065706f2543Smrgint PanoramiXImageText16(ClientPtr client)
2066706f2543Smrg{
2067706f2543Smrg    int 	  result, j;
2068706f2543Smrg    PanoramiXRes *gc, *draw;
2069706f2543Smrg    Bool	  isRoot;
2070706f2543Smrg    int		  orig_x, orig_y;
2071706f2543Smrg    REQUEST(xImageTextReq);
2072706f2543Smrg
2073706f2543Smrg    REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1);
2074706f2543Smrg
2075706f2543Smrg    result = dixLookupResourceByClass((pointer *)&draw, stuff->drawable,
2076706f2543Smrg				      XRC_DRAWABLE, client, DixWriteAccess);
2077706f2543Smrg    if (result != Success)
2078706f2543Smrg	return (result == BadValue) ? BadDrawable : result;
2079706f2543Smrg
2080706f2543Smrg    if(IS_SHARED_PIXMAP(draw))
2081706f2543Smrg	return (*SavedProcVector[X_ImageText16])(client);
2082706f2543Smrg
2083706f2543Smrg    result = dixLookupResourceByType((pointer *)&gc, stuff->gc, XRT_GC,
2084706f2543Smrg				     client, DixReadAccess);
2085706f2543Smrg    if (result != Success)
2086706f2543Smrg	return result;
2087706f2543Smrg
2088706f2543Smrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
2089706f2543Smrg
2090706f2543Smrg    orig_x = stuff->x;
2091706f2543Smrg    orig_y = stuff->y;
2092706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2093706f2543Smrg	stuff->drawable = draw->info[j].id;
2094706f2543Smrg	stuff->gc = gc->info[j].id;
2095706f2543Smrg	if (isRoot) {
2096706f2543Smrg	    stuff->x = orig_x - screenInfo.screens[j]->x;
2097706f2543Smrg	    stuff->y = orig_y - screenInfo.screens[j]->y;
2098706f2543Smrg	}
2099706f2543Smrg	result = (*SavedProcVector[X_ImageText16])(client);
2100706f2543Smrg	if(result != Success) break;
2101706f2543Smrg    }
2102706f2543Smrg    return result;
2103706f2543Smrg}
2104706f2543Smrg
2105706f2543Smrg
2106706f2543Smrg
2107706f2543Smrgint PanoramiXCreateColormap(ClientPtr client)
2108706f2543Smrg{
2109706f2543Smrg    PanoramiXRes	*win, *newCmap;
2110706f2543Smrg    int 		result, j, orig_visual;
2111706f2543Smrg    REQUEST(xCreateColormapReq);
2112706f2543Smrg
2113706f2543Smrg    REQUEST_SIZE_MATCH(xCreateColormapReq);
2114706f2543Smrg
2115706f2543Smrg    result = dixLookupResourceByType((pointer *)&win, stuff->window,
2116706f2543Smrg				     XRT_WINDOW, client, DixReadAccess);
2117706f2543Smrg    if (result != Success)
2118706f2543Smrg	return result;
2119706f2543Smrg
2120706f2543Smrg    if(!(newCmap = malloc(sizeof(PanoramiXRes))))
2121706f2543Smrg        return BadAlloc;
2122706f2543Smrg
2123706f2543Smrg    newCmap->type = XRT_COLORMAP;
2124706f2543Smrg    newCmap->info[0].id = stuff->mid;
2125706f2543Smrg    for(j = 1; j < PanoramiXNumScreens; j++)
2126706f2543Smrg        newCmap->info[j].id = FakeClientID(client->index);
2127706f2543Smrg
2128706f2543Smrg    orig_visual = stuff->visual;
2129706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2130706f2543Smrg	stuff->mid = newCmap->info[j].id;
2131706f2543Smrg	stuff->window = win->info[j].id;
2132706f2543Smrg	stuff->visual = PanoramiXTranslateVisualID(j, orig_visual);
2133706f2543Smrg	result = (* SavedProcVector[X_CreateColormap])(client);
2134706f2543Smrg	if(result != Success) break;
2135706f2543Smrg    }
2136706f2543Smrg
2137706f2543Smrg    if (result == Success)
2138706f2543Smrg        AddResource(newCmap->info[0].id, XRT_COLORMAP, newCmap);
2139706f2543Smrg    else
2140706f2543Smrg        free(newCmap);
2141706f2543Smrg
2142706f2543Smrg    return result;
2143706f2543Smrg}
2144706f2543Smrg
2145706f2543Smrg
2146706f2543Smrgint PanoramiXFreeColormap(ClientPtr client)
2147706f2543Smrg{
2148706f2543Smrg    PanoramiXRes *cmap;
2149706f2543Smrg    int          result, j;
2150706f2543Smrg    REQUEST(xResourceReq);
2151706f2543Smrg
2152706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
2153706f2543Smrg
2154706f2543Smrg    client->errorValue = stuff->id;
2155706f2543Smrg
2156706f2543Smrg    result = dixLookupResourceByType((pointer *)&cmap, stuff->id, XRT_COLORMAP,
2157706f2543Smrg				     client, DixDestroyAccess);
2158706f2543Smrg    if (result != Success)
2159706f2543Smrg        return result;
2160706f2543Smrg
2161706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
2162706f2543Smrg        stuff->id = cmap->info[j].id;
2163706f2543Smrg        result = (* SavedProcVector[X_FreeColormap])(client);
2164706f2543Smrg	if(result != Success) break;
2165706f2543Smrg    }
2166706f2543Smrg
2167706f2543Smrg    /* Since ProcFreeColormap is using FreeResource, it will free
2168706f2543Smrg	our resource for us on the last pass through the loop above */
2169706f2543Smrg
2170706f2543Smrg    return result;
2171706f2543Smrg}
2172706f2543Smrg
2173706f2543Smrg
2174706f2543Smrgint
2175706f2543SmrgPanoramiXCopyColormapAndFree(ClientPtr client)
2176706f2543Smrg{
2177706f2543Smrg    PanoramiXRes *cmap, *newCmap;
2178706f2543Smrg    int          result, j;
2179706f2543Smrg    REQUEST(xCopyColormapAndFreeReq);
2180706f2543Smrg
2181706f2543Smrg    REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq);
2182706f2543Smrg
2183706f2543Smrg    client->errorValue = stuff->srcCmap;
2184706f2543Smrg
2185706f2543Smrg    result = dixLookupResourceByType((pointer *)&cmap, stuff->srcCmap,
2186706f2543Smrg				     XRT_COLORMAP, client,
2187706f2543Smrg				     DixReadAccess | DixWriteAccess);
2188706f2543Smrg    if (result != Success)
2189706f2543Smrg        return result;
2190706f2543Smrg
2191706f2543Smrg    if(!(newCmap = malloc(sizeof(PanoramiXRes))))
2192706f2543Smrg        return BadAlloc;
2193706f2543Smrg
2194706f2543Smrg    newCmap->type = XRT_COLORMAP;
2195706f2543Smrg    newCmap->info[0].id = stuff->mid;
2196706f2543Smrg    for(j = 1; j < PanoramiXNumScreens; j++)
2197706f2543Smrg        newCmap->info[j].id = FakeClientID(client->index);
2198706f2543Smrg
2199706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2200706f2543Smrg        stuff->srcCmap = cmap->info[j].id;
2201706f2543Smrg	stuff->mid = newCmap->info[j].id;
2202706f2543Smrg        result = (* SavedProcVector[X_CopyColormapAndFree])(client);
2203706f2543Smrg	if(result != Success) break;
2204706f2543Smrg    }
2205706f2543Smrg
2206706f2543Smrg    if (result == Success)
2207706f2543Smrg        AddResource(newCmap->info[0].id, XRT_COLORMAP, newCmap);
2208706f2543Smrg    else
2209706f2543Smrg        free(newCmap);
2210706f2543Smrg
2211706f2543Smrg    return result;
2212706f2543Smrg}
2213706f2543Smrg
2214706f2543Smrg
2215706f2543Smrgint PanoramiXInstallColormap(ClientPtr client)
2216706f2543Smrg{
2217706f2543Smrg    REQUEST(xResourceReq);
2218706f2543Smrg    int 	result, j;
2219706f2543Smrg    PanoramiXRes *cmap;
2220706f2543Smrg
2221706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
2222706f2543Smrg
2223706f2543Smrg    client->errorValue = stuff->id;
2224706f2543Smrg
2225706f2543Smrg    result = dixLookupResourceByType((pointer *)&cmap, stuff->id, XRT_COLORMAP,
2226706f2543Smrg				     client, DixReadAccess);
2227706f2543Smrg    if (result != Success)
2228706f2543Smrg        return result;
2229706f2543Smrg
2230706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2231706f2543Smrg	stuff->id = cmap->info[j].id;
2232706f2543Smrg	result = (* SavedProcVector[X_InstallColormap])(client);
2233706f2543Smrg	if(result != Success) break;
2234706f2543Smrg    }
2235706f2543Smrg    return result;
2236706f2543Smrg}
2237706f2543Smrg
2238706f2543Smrg
2239706f2543Smrgint PanoramiXUninstallColormap(ClientPtr client)
2240706f2543Smrg{
2241706f2543Smrg    REQUEST(xResourceReq);
2242706f2543Smrg    int 	result, j;
2243706f2543Smrg    PanoramiXRes *cmap;
2244706f2543Smrg
2245706f2543Smrg    REQUEST_SIZE_MATCH(xResourceReq);
2246706f2543Smrg
2247706f2543Smrg    client->errorValue = stuff->id;
2248706f2543Smrg
2249706f2543Smrg    result = dixLookupResourceByType((pointer *)&cmap, stuff->id, XRT_COLORMAP,
2250706f2543Smrg				     client, DixReadAccess);
2251706f2543Smrg    if (result != Success)
2252706f2543Smrg        return result;
2253706f2543Smrg
2254706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
2255706f2543Smrg	stuff->id = cmap->info[j].id;
2256706f2543Smrg	result = (* SavedProcVector[X_UninstallColormap])(client);
2257706f2543Smrg	if(result != Success) break;
2258706f2543Smrg    }
2259706f2543Smrg    return result;
2260706f2543Smrg}
2261706f2543Smrg
2262706f2543Smrg
2263706f2543Smrgint PanoramiXAllocColor(ClientPtr client)
2264706f2543Smrg{
2265706f2543Smrg    int           result, j;
2266706f2543Smrg    PanoramiXRes *cmap;
2267706f2543Smrg    REQUEST(xAllocColorReq);
2268706f2543Smrg
2269706f2543Smrg    REQUEST_SIZE_MATCH(xAllocColorReq);
2270706f2543Smrg
2271706f2543Smrg    client->errorValue = stuff->cmap;
2272706f2543Smrg
2273706f2543Smrg    result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap,
2274706f2543Smrg				     XRT_COLORMAP, client, DixWriteAccess);
2275706f2543Smrg    if (result != Success)
2276706f2543Smrg        return result;
2277706f2543Smrg
2278706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2279706f2543Smrg	stuff->cmap = cmap->info[j].id;
2280706f2543Smrg	result = (* SavedProcVector[X_AllocColor])(client);
2281706f2543Smrg	if(result != Success) break;
2282706f2543Smrg    }
2283706f2543Smrg    return result;
2284706f2543Smrg}
2285706f2543Smrg
2286706f2543Smrg
2287706f2543Smrgint PanoramiXAllocNamedColor(ClientPtr client)
2288706f2543Smrg{
2289706f2543Smrg    int           result, j;
2290706f2543Smrg    PanoramiXRes  *cmap;
2291706f2543Smrg    REQUEST(xAllocNamedColorReq);
2292706f2543Smrg
2293706f2543Smrg    REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes);
2294706f2543Smrg
2295706f2543Smrg    client->errorValue = stuff->cmap;
2296706f2543Smrg
2297706f2543Smrg    result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap,
2298706f2543Smrg				     XRT_COLORMAP, client, DixWriteAccess);
2299706f2543Smrg    if (result != Success)
2300706f2543Smrg        return result;
2301706f2543Smrg
2302706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2303706f2543Smrg        stuff->cmap = cmap->info[j].id;
2304706f2543Smrg        result = (* SavedProcVector[X_AllocNamedColor])(client);
2305706f2543Smrg	if(result != Success) break;
2306706f2543Smrg    }
2307706f2543Smrg    return result;
2308706f2543Smrg}
2309706f2543Smrg
2310706f2543Smrg
2311706f2543Smrgint PanoramiXAllocColorCells(ClientPtr client)
2312706f2543Smrg{
2313706f2543Smrg    int           result, j;
2314706f2543Smrg    PanoramiXRes  *cmap;
2315706f2543Smrg    REQUEST(xAllocColorCellsReq);
2316706f2543Smrg
2317706f2543Smrg    REQUEST_SIZE_MATCH(xAllocColorCellsReq);
2318706f2543Smrg
2319706f2543Smrg    client->errorValue = stuff->cmap;
2320706f2543Smrg
2321706f2543Smrg    result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap,
2322706f2543Smrg				     XRT_COLORMAP, client, DixWriteAccess);
2323706f2543Smrg    if (result != Success)
2324706f2543Smrg        return result;
2325706f2543Smrg
2326706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2327706f2543Smrg	stuff->cmap = cmap->info[j].id;
2328706f2543Smrg	result = (* SavedProcVector[X_AllocColorCells])(client);
2329706f2543Smrg	if(result != Success) break;
2330706f2543Smrg    }
2331706f2543Smrg    return result;
2332706f2543Smrg}
2333706f2543Smrg
2334706f2543Smrg
2335706f2543Smrgint PanoramiXAllocColorPlanes(ClientPtr client)
2336706f2543Smrg{
2337706f2543Smrg    int           result, j;
2338706f2543Smrg    PanoramiXRes  *cmap;
2339706f2543Smrg    REQUEST(xAllocColorPlanesReq);
2340706f2543Smrg
2341706f2543Smrg    REQUEST_SIZE_MATCH(xAllocColorPlanesReq);
2342706f2543Smrg
2343706f2543Smrg    client->errorValue = stuff->cmap;
2344706f2543Smrg
2345706f2543Smrg    result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap,
2346706f2543Smrg				     XRT_COLORMAP, client, DixWriteAccess);
2347706f2543Smrg    if (result != Success)
2348706f2543Smrg        return result;
2349706f2543Smrg
2350706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2351706f2543Smrg	stuff->cmap = cmap->info[j].id;
2352706f2543Smrg	result = (* SavedProcVector[X_AllocColorPlanes])(client);
2353706f2543Smrg	if(result != Success) break;
2354706f2543Smrg    }
2355706f2543Smrg    return result;
2356706f2543Smrg}
2357706f2543Smrg
2358706f2543Smrg
2359706f2543Smrg
2360706f2543Smrgint PanoramiXFreeColors(ClientPtr client)
2361706f2543Smrg{
2362706f2543Smrg    int           result, j;
2363706f2543Smrg    PanoramiXRes  *cmap;
2364706f2543Smrg    REQUEST(xFreeColorsReq);
2365706f2543Smrg
2366706f2543Smrg    REQUEST_AT_LEAST_SIZE(xFreeColorsReq);
2367706f2543Smrg
2368706f2543Smrg    client->errorValue = stuff->cmap;
2369706f2543Smrg
2370706f2543Smrg    result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap,
2371706f2543Smrg				     XRT_COLORMAP, client, DixWriteAccess);
2372706f2543Smrg    if (result != Success)
2373706f2543Smrg        return result;
2374706f2543Smrg
2375706f2543Smrg    FOR_NSCREENS_BACKWARD(j) {
2376706f2543Smrg        stuff->cmap = cmap->info[j].id;
2377706f2543Smrg        result = (* SavedProcVector[X_FreeColors])(client);
2378706f2543Smrg    }
2379706f2543Smrg    return result;
2380706f2543Smrg}
2381706f2543Smrg
2382706f2543Smrg
2383706f2543Smrgint PanoramiXStoreColors(ClientPtr client)
2384706f2543Smrg{
2385706f2543Smrg    int           result, j;
2386706f2543Smrg    PanoramiXRes  *cmap;
2387706f2543Smrg    REQUEST(xStoreColorsReq);
2388706f2543Smrg
2389706f2543Smrg    REQUEST_AT_LEAST_SIZE(xStoreColorsReq);
2390706f2543Smrg
2391706f2543Smrg    client->errorValue = stuff->cmap;
2392706f2543Smrg
2393706f2543Smrg    result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap,
2394706f2543Smrg				     XRT_COLORMAP, client, DixWriteAccess);
2395706f2543Smrg    if (result != Success)
2396706f2543Smrg        return result;
2397706f2543Smrg
2398706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2399706f2543Smrg	stuff->cmap = cmap->info[j].id;
2400706f2543Smrg	result = (* SavedProcVector[X_StoreColors])(client);
2401706f2543Smrg	if(result != Success) break;
2402706f2543Smrg    }
2403706f2543Smrg    return result;
2404706f2543Smrg}
2405706f2543Smrg
2406706f2543Smrg
2407706f2543Smrgint PanoramiXStoreNamedColor(ClientPtr client)
2408706f2543Smrg{
2409706f2543Smrg    int           result, j;
2410706f2543Smrg    PanoramiXRes  *cmap;
2411706f2543Smrg    REQUEST(xStoreNamedColorReq);
2412706f2543Smrg
2413706f2543Smrg    REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes);
2414706f2543Smrg
2415706f2543Smrg    client->errorValue = stuff->cmap;
2416706f2543Smrg
2417706f2543Smrg    result = dixLookupResourceByType((pointer *)&cmap, stuff->cmap,
2418706f2543Smrg				     XRT_COLORMAP, client, DixWriteAccess);
2419706f2543Smrg    if (result != Success)
2420706f2543Smrg        return result;
2421706f2543Smrg
2422706f2543Smrg    FOR_NSCREENS_BACKWARD(j){
2423706f2543Smrg	stuff->cmap = cmap->info[j].id;
2424706f2543Smrg	result = (* SavedProcVector[X_StoreNamedColor])(client);
2425706f2543Smrg	if(result != Success) break;
2426706f2543Smrg    }
2427706f2543Smrg    return result;
2428706f2543Smrg}
2429