105b261ecSmrg/*****************************************************************
205b261ecSmrgCopyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
305b261ecSmrgPermission is hereby granted, free of charge, to any person obtaining a copy
405b261ecSmrgof this software and associated documentation files (the "Software"), to deal
505b261ecSmrgin the Software without restriction, including without limitation the rights
605b261ecSmrgto use, copy, modify, merge, publish, distribute, sublicense, and/or sell
705b261ecSmrgcopies of the Software.
805b261ecSmrg
905b261ecSmrgThe above copyright notice and this permission notice shall be included in
1005b261ecSmrgall copies or substantial portions of the Software.
1105b261ecSmrg
1205b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1305b261ecSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1405b261ecSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1505b261ecSmrgDIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
1605b261ecSmrgBUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
1705b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
1805b261ecSmrgIN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1905b261ecSmrg
2005b261ecSmrgExcept as contained in this notice, the name of Digital Equipment Corporation
2105b261ecSmrgshall not be used in advertising or otherwise to promote the sale, use or other
2205b261ecSmrgdealings in this Software without prior written authorization from Digital
2305b261ecSmrgEquipment Corporation.
2405b261ecSmrg******************************************************************/
2505b261ecSmrg
2605b261ecSmrg/* Massively rewritten by Mark Vojkovich <markv@valinux.com> */
2705b261ecSmrg
2805b261ecSmrg#ifdef HAVE_DIX_CONFIG_H
2905b261ecSmrg#include <dix-config.h>
3005b261ecSmrg#endif
3105b261ecSmrg
3205b261ecSmrg#include <stdio.h>
3305b261ecSmrg#include <X11/X.h>
3405b261ecSmrg#include <X11/Xproto.h>
3505b261ecSmrg#include "windowstr.h"
3605b261ecSmrg#include "dixfontstr.h"
3705b261ecSmrg#include "gcstruct.h"
3805b261ecSmrg#include "colormapst.h"
3905b261ecSmrg#include "scrnintstr.h"
4005b261ecSmrg#include "opaque.h"
4105b261ecSmrg#include "inputstr.h"
4205b261ecSmrg#include "migc.h"
4305b261ecSmrg#include "misc.h"
4405b261ecSmrg#include "dixstruct.h"
4505b261ecSmrg#include "panoramiX.h"
4605b261ecSmrg#include "panoramiXsrv.h"
4705b261ecSmrg#include "resource.h"
4805b261ecSmrg#include "panoramiXh.h"
4905b261ecSmrg
5005b261ecSmrg#define XINERAMA_IMAGE_BUFSIZE (256*1024)
5105b261ecSmrg#define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \
5205b261ecSmrg                              CWDontPropagate | CWOverrideRedirect | CWCursor )
5305b261ecSmrg
5435c4bbdfSmrgint
5535c4bbdfSmrgPanoramiXCreateWindow(ClientPtr client)
5605b261ecSmrg{
5705b261ecSmrg    PanoramiXRes *parent, *newWin;
5805b261ecSmrg    PanoramiXRes *backPix = NULL;
5905b261ecSmrg    PanoramiXRes *bordPix = NULL;
6035c4bbdfSmrg    PanoramiXRes *cmap = NULL;
6135c4bbdfSmrg
6205b261ecSmrg    REQUEST(xCreateWindowReq);
6305b261ecSmrg    int pback_offset = 0, pbord_offset = 0, cmap_offset = 0;
646747b715Smrg    int result, len, j;
6505b261ecSmrg    int orig_x, orig_y;
6605b261ecSmrg    XID orig_visual, tmp;
6705b261ecSmrg    Bool parentIsRoot;
6805b261ecSmrg
6905b261ecSmrg    REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
7035c4bbdfSmrg
716747b715Smrg    len = client->req_len - bytes_to_int32(sizeof(xCreateWindowReq));
7205b261ecSmrg    if (Ones(stuff->mask) != len)
7305b261ecSmrg        return BadLength;
7405b261ecSmrg
7535c4bbdfSmrg    result = dixLookupResourceByType((void **) &parent, stuff->parent,
7635c4bbdfSmrg                                     XRT_WINDOW, client, DixWriteAccess);
776747b715Smrg    if (result != Success)
786747b715Smrg        return result;
7905b261ecSmrg
8035c4bbdfSmrg    if (stuff->class == CopyFromParent)
8135c4bbdfSmrg        stuff->class = parent->u.win.class;
8205b261ecSmrg
8335c4bbdfSmrg    if ((stuff->class == InputOnly) && (stuff->mask & (~INPUTONLY_LEGAL_MASK)))
8405b261ecSmrg        return BadMatch;
8505b261ecSmrg
8635c4bbdfSmrg    if ((Mask) stuff->mask & CWBackPixmap) {
8735c4bbdfSmrg        pback_offset = Ones((Mask) stuff->mask & (CWBackPixmap - 1));
8835c4bbdfSmrg        tmp = *((CARD32 *) &stuff[1] + pback_offset);
8935c4bbdfSmrg        if ((tmp != None) && (tmp != ParentRelative)) {
9035c4bbdfSmrg            result = dixLookupResourceByType((void **) &backPix, tmp,
9135c4bbdfSmrg                                             XRT_PIXMAP, client, DixReadAccess);
9235c4bbdfSmrg            if (result != Success)
9335c4bbdfSmrg                return result;
9435c4bbdfSmrg        }
9535c4bbdfSmrg    }
9635c4bbdfSmrg    if ((Mask) stuff->mask & CWBorderPixmap) {
9735c4bbdfSmrg        pbord_offset = Ones((Mask) stuff->mask & (CWBorderPixmap - 1));
9835c4bbdfSmrg        tmp = *((CARD32 *) &stuff[1] + pbord_offset);
9935c4bbdfSmrg        if (tmp != CopyFromParent) {
10035c4bbdfSmrg            result = dixLookupResourceByType((void **) &bordPix, tmp,
10135c4bbdfSmrg                                             XRT_PIXMAP, client, DixReadAccess);
10235c4bbdfSmrg            if (result != Success)
10335c4bbdfSmrg                return result;
10435c4bbdfSmrg        }
10535c4bbdfSmrg    }
10635c4bbdfSmrg    if ((Mask) stuff->mask & CWColormap) {
10735c4bbdfSmrg        cmap_offset = Ones((Mask) stuff->mask & (CWColormap - 1));
10835c4bbdfSmrg        tmp = *((CARD32 *) &stuff[1] + cmap_offset);
10935c4bbdfSmrg        if (tmp != CopyFromParent) {
11035c4bbdfSmrg            result = dixLookupResourceByType((void **) &cmap, tmp,
11135c4bbdfSmrg                                             XRT_COLORMAP, client,
11235c4bbdfSmrg                                             DixReadAccess);
11335c4bbdfSmrg            if (result != Success)
11435c4bbdfSmrg                return result;
11535c4bbdfSmrg        }
11635c4bbdfSmrg    }
11735c4bbdfSmrg
11835c4bbdfSmrg    if (!(newWin = malloc(sizeof(PanoramiXRes))))
11905b261ecSmrg        return BadAlloc;
12005b261ecSmrg
12105b261ecSmrg    newWin->type = XRT_WINDOW;
12205b261ecSmrg    newWin->u.win.visibility = VisibilityNotViewable;
12305b261ecSmrg    newWin->u.win.class = stuff->class;
12405b261ecSmrg    newWin->u.win.root = FALSE;
12535c4bbdfSmrg    panoramix_setup_ids(newWin, client, stuff->wid);
12605b261ecSmrg
12705b261ecSmrg    if (stuff->class == InputOnly)
12835c4bbdfSmrg        stuff->visual = CopyFromParent;
12905b261ecSmrg    orig_visual = stuff->visual;
13005b261ecSmrg    orig_x = stuff->x;
13105b261ecSmrg    orig_y = stuff->y;
13235c4bbdfSmrg    parentIsRoot = (stuff->parent == screenInfo.screens[0]->root->drawable.id)
13335c4bbdfSmrg        || (stuff->parent == screenInfo.screens[0]->screensaver.wid);
13405b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
13505b261ecSmrg        stuff->wid = newWin->info[j].id;
13605b261ecSmrg        stuff->parent = parent->info[j].id;
13735c4bbdfSmrg        if (parentIsRoot) {
13835c4bbdfSmrg            stuff->x = orig_x - screenInfo.screens[j]->x;
13935c4bbdfSmrg            stuff->y = orig_y - screenInfo.screens[j]->y;
14035c4bbdfSmrg        }
14135c4bbdfSmrg        if (backPix)
14235c4bbdfSmrg            *((CARD32 *) &stuff[1] + pback_offset) = backPix->info[j].id;
14335c4bbdfSmrg        if (bordPix)
14435c4bbdfSmrg            *((CARD32 *) &stuff[1] + pbord_offset) = bordPix->info[j].id;
14535c4bbdfSmrg        if (cmap)
14635c4bbdfSmrg            *((CARD32 *) &stuff[1] + cmap_offset) = cmap->info[j].id;
14735c4bbdfSmrg        if (orig_visual != CopyFromParent)
14835c4bbdfSmrg            stuff->visual = PanoramiXTranslateVisualID(j, orig_visual);
14935c4bbdfSmrg        result = (*SavedProcVector[X_CreateWindow]) (client);
15035c4bbdfSmrg        if (result != Success)
15135c4bbdfSmrg            break;
15205b261ecSmrg    }
15305b261ecSmrg
15405b261ecSmrg    if (result == Success)
15505b261ecSmrg        AddResource(newWin->info[0].id, XRT_WINDOW, newWin);
15635c4bbdfSmrg    else
1576747b715Smrg        free(newWin);
15805b261ecSmrg
1596747b715Smrg    return result;
16005b261ecSmrg}
16105b261ecSmrg
16235c4bbdfSmrgint
16335c4bbdfSmrgPanoramiXChangeWindowAttributes(ClientPtr client)
16405b261ecSmrg{
16505b261ecSmrg    PanoramiXRes *win;
16605b261ecSmrg    PanoramiXRes *backPix = NULL;
16705b261ecSmrg    PanoramiXRes *bordPix = NULL;
16835c4bbdfSmrg    PanoramiXRes *cmap = NULL;
16935c4bbdfSmrg
17005b261ecSmrg    REQUEST(xChangeWindowAttributesReq);
17105b261ecSmrg    int pback_offset = 0, pbord_offset = 0, cmap_offset = 0;
1726747b715Smrg    int result, len, j;
17305b261ecSmrg    XID tmp;
17405b261ecSmrg
17505b261ecSmrg    REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
17635c4bbdfSmrg
1776747b715Smrg    len = client->req_len - bytes_to_int32(sizeof(xChangeWindowAttributesReq));
17805b261ecSmrg    if (Ones(stuff->valueMask) != len)
17905b261ecSmrg        return BadLength;
18005b261ecSmrg
18135c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->window,
18235c4bbdfSmrg                                     XRT_WINDOW, client, DixWriteAccess);
1836747b715Smrg    if (result != Success)
1846747b715Smrg        return result;
18505b261ecSmrg
18635c4bbdfSmrg    if ((win->u.win.class == InputOnly) &&
18735c4bbdfSmrg        (stuff->valueMask & (~INPUTONLY_LEGAL_MASK)))
18805b261ecSmrg        return BadMatch;
18905b261ecSmrg
19035c4bbdfSmrg    if ((Mask) stuff->valueMask & CWBackPixmap) {
19135c4bbdfSmrg        pback_offset = Ones((Mask) stuff->valueMask & (CWBackPixmap - 1));
19235c4bbdfSmrg        tmp = *((CARD32 *) &stuff[1] + pback_offset);
19335c4bbdfSmrg        if ((tmp != None) && (tmp != ParentRelative)) {
19435c4bbdfSmrg            result = dixLookupResourceByType((void **) &backPix, tmp,
19535c4bbdfSmrg                                             XRT_PIXMAP, client, DixReadAccess);
19635c4bbdfSmrg            if (result != Success)
19735c4bbdfSmrg                return result;
19835c4bbdfSmrg        }
19935c4bbdfSmrg    }
20035c4bbdfSmrg    if ((Mask) stuff->valueMask & CWBorderPixmap) {
20135c4bbdfSmrg        pbord_offset = Ones((Mask) stuff->valueMask & (CWBorderPixmap - 1));
20235c4bbdfSmrg        tmp = *((CARD32 *) &stuff[1] + pbord_offset);
20335c4bbdfSmrg        if (tmp != CopyFromParent) {
20435c4bbdfSmrg            result = dixLookupResourceByType((void **) &bordPix, tmp,
20535c4bbdfSmrg                                             XRT_PIXMAP, client, DixReadAccess);
20635c4bbdfSmrg            if (result != Success)
20735c4bbdfSmrg                return result;
20835c4bbdfSmrg        }
20935c4bbdfSmrg    }
21035c4bbdfSmrg    if ((Mask) stuff->valueMask & CWColormap) {
21135c4bbdfSmrg        cmap_offset = Ones((Mask) stuff->valueMask & (CWColormap - 1));
21235c4bbdfSmrg        tmp = *((CARD32 *) &stuff[1] + cmap_offset);
21335c4bbdfSmrg        if (tmp != CopyFromParent) {
21435c4bbdfSmrg            result = dixLookupResourceByType((void **) &cmap, tmp,
21535c4bbdfSmrg                                             XRT_COLORMAP, client,
21635c4bbdfSmrg                                             DixReadAccess);
21735c4bbdfSmrg            if (result != Success)
21835c4bbdfSmrg                return result;
21935c4bbdfSmrg        }
22005b261ecSmrg    }
22105b261ecSmrg
22205b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
22305b261ecSmrg        stuff->window = win->info[j].id;
22435c4bbdfSmrg        if (backPix)
22535c4bbdfSmrg            *((CARD32 *) &stuff[1] + pback_offset) = backPix->info[j].id;
22635c4bbdfSmrg        if (bordPix)
22735c4bbdfSmrg            *((CARD32 *) &stuff[1] + pbord_offset) = bordPix->info[j].id;
22835c4bbdfSmrg        if (cmap)
22935c4bbdfSmrg            *((CARD32 *) &stuff[1] + cmap_offset) = cmap->info[j].id;
23035c4bbdfSmrg        result = (*SavedProcVector[X_ChangeWindowAttributes]) (client);
23105b261ecSmrg    }
23205b261ecSmrg
2336747b715Smrg    return result;
23405b261ecSmrg}
23505b261ecSmrg
23635c4bbdfSmrgint
23735c4bbdfSmrgPanoramiXDestroyWindow(ClientPtr client)
23805b261ecSmrg{
23905b261ecSmrg    PanoramiXRes *win;
24035c4bbdfSmrg    int result, j;
24135c4bbdfSmrg
24205b261ecSmrg    REQUEST(xResourceReq);
24305b261ecSmrg
24405b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
24505b261ecSmrg
24635c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->id, XRT_WINDOW,
24735c4bbdfSmrg                                     client, DixDestroyAccess);
2486747b715Smrg    if (result != Success)
24935c4bbdfSmrg        return result;
25005b261ecSmrg
25105b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
25235c4bbdfSmrg        stuff->id = win->info[j].id;
25335c4bbdfSmrg        result = (*SavedProcVector[X_DestroyWindow]) (client);
25435c4bbdfSmrg        if (result != Success)
25535c4bbdfSmrg            break;
25605b261ecSmrg    }
25705b261ecSmrg
25805b261ecSmrg    /* Since ProcDestroyWindow is using FreeResource, it will free
25935c4bbdfSmrg       our resource for us on the last pass through the loop above */
26035c4bbdfSmrg
2616747b715Smrg    return result;
26205b261ecSmrg}
26305b261ecSmrg
26435c4bbdfSmrgint
26535c4bbdfSmrgPanoramiXDestroySubwindows(ClientPtr client)
26605b261ecSmrg{
26705b261ecSmrg    PanoramiXRes *win;
26835c4bbdfSmrg    int result, j;
26935c4bbdfSmrg
27005b261ecSmrg    REQUEST(xResourceReq);
27105b261ecSmrg
27205b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
27305b261ecSmrg
27435c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->id, XRT_WINDOW,
27535c4bbdfSmrg                                     client, DixDestroyAccess);
2766747b715Smrg    if (result != Success)
27735c4bbdfSmrg        return result;
27805b261ecSmrg
27905b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
28035c4bbdfSmrg        stuff->id = win->info[j].id;
28135c4bbdfSmrg        result = (*SavedProcVector[X_DestroySubwindows]) (client);
28235c4bbdfSmrg        if (result != Success)
28335c4bbdfSmrg            break;
28405b261ecSmrg    }
28505b261ecSmrg
28605b261ecSmrg    /* DestroySubwindows is using FreeResource which will free
28735c4bbdfSmrg       our resources for us on the last pass through the loop above */
28805b261ecSmrg
2896747b715Smrg    return result;
29005b261ecSmrg}
29105b261ecSmrg
29235c4bbdfSmrgint
29335c4bbdfSmrgPanoramiXChangeSaveSet(ClientPtr client)
29405b261ecSmrg{
29505b261ecSmrg    PanoramiXRes *win;
29635c4bbdfSmrg    int result, j;
29735c4bbdfSmrg
29805b261ecSmrg    REQUEST(xChangeSaveSetReq);
29905b261ecSmrg
30005b261ecSmrg    REQUEST_SIZE_MATCH(xChangeSaveSetReq);
30105b261ecSmrg
30235c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->window,
30335c4bbdfSmrg                                     XRT_WINDOW, client, DixReadAccess);
3046747b715Smrg    if (result != Success)
30535c4bbdfSmrg        return result;
30605b261ecSmrg
30705b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
30835c4bbdfSmrg        stuff->window = win->info[j].id;
30935c4bbdfSmrg        result = (*SavedProcVector[X_ChangeSaveSet]) (client);
31035c4bbdfSmrg        if (result != Success)
31135c4bbdfSmrg            break;
31205b261ecSmrg    }
31305b261ecSmrg
3146747b715Smrg    return result;
31505b261ecSmrg}
31605b261ecSmrg
31735c4bbdfSmrgint
31835c4bbdfSmrgPanoramiXReparentWindow(ClientPtr client)
31905b261ecSmrg{
32005b261ecSmrg    PanoramiXRes *win, *parent;
32135c4bbdfSmrg    int result, j;
32235c4bbdfSmrg    int x, y;
32335c4bbdfSmrg    Bool parentIsRoot;
32435c4bbdfSmrg
32505b261ecSmrg    REQUEST(xReparentWindowReq);
32605b261ecSmrg
32705b261ecSmrg    REQUEST_SIZE_MATCH(xReparentWindowReq);
32805b261ecSmrg
32935c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->window,
33035c4bbdfSmrg                                     XRT_WINDOW, client, DixWriteAccess);
3316747b715Smrg    if (result != Success)
33235c4bbdfSmrg        return result;
33305b261ecSmrg
33435c4bbdfSmrg    result = dixLookupResourceByType((void **) &parent, stuff->parent,
33535c4bbdfSmrg                                     XRT_WINDOW, client, DixWriteAccess);
3366747b715Smrg    if (result != Success)
33735c4bbdfSmrg        return result;
33805b261ecSmrg
33905b261ecSmrg    x = stuff->x;
34005b261ecSmrg    y = stuff->y;
34135c4bbdfSmrg    parentIsRoot = (stuff->parent == screenInfo.screens[0]->root->drawable.id)
34235c4bbdfSmrg        || (stuff->parent == screenInfo.screens[0]->screensaver.wid);
34305b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
34435c4bbdfSmrg        stuff->window = win->info[j].id;
34535c4bbdfSmrg        stuff->parent = parent->info[j].id;
34635c4bbdfSmrg        if (parentIsRoot) {
34735c4bbdfSmrg            stuff->x = x - screenInfo.screens[j]->x;
34835c4bbdfSmrg            stuff->y = y - screenInfo.screens[j]->y;
34935c4bbdfSmrg        }
35035c4bbdfSmrg        result = (*SavedProcVector[X_ReparentWindow]) (client);
35135c4bbdfSmrg        if (result != Success)
35235c4bbdfSmrg            break;
35305b261ecSmrg    }
35405b261ecSmrg
3556747b715Smrg    return result;
35605b261ecSmrg}
35705b261ecSmrg
35835c4bbdfSmrgint
35935c4bbdfSmrgPanoramiXMapWindow(ClientPtr client)
36005b261ecSmrg{
36105b261ecSmrg    PanoramiXRes *win;
36235c4bbdfSmrg    int result, j;
36335c4bbdfSmrg
36405b261ecSmrg    REQUEST(xResourceReq);
36505b261ecSmrg
36605b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
36705b261ecSmrg
36835c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->id,
36935c4bbdfSmrg                                     XRT_WINDOW, client, DixReadAccess);
3706747b715Smrg    if (result != Success)
37135c4bbdfSmrg        return result;
37205b261ecSmrg
37305b261ecSmrg    FOR_NSCREENS_FORWARD(j) {
37435c4bbdfSmrg        stuff->id = win->info[j].id;
37535c4bbdfSmrg        result = (*SavedProcVector[X_MapWindow]) (client);
37635c4bbdfSmrg        if (result != Success)
37735c4bbdfSmrg            break;
37805b261ecSmrg    }
37905b261ecSmrg
3806747b715Smrg    return result;
38105b261ecSmrg}
38205b261ecSmrg
38335c4bbdfSmrgint
38435c4bbdfSmrgPanoramiXMapSubwindows(ClientPtr client)
38505b261ecSmrg{
38605b261ecSmrg    PanoramiXRes *win;
38735c4bbdfSmrg    int result, j;
38835c4bbdfSmrg
38905b261ecSmrg    REQUEST(xResourceReq);
39005b261ecSmrg
39105b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
39205b261ecSmrg
39335c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->id,
39435c4bbdfSmrg                                     XRT_WINDOW, client, DixReadAccess);
3956747b715Smrg    if (result != Success)
39635c4bbdfSmrg        return result;
39705b261ecSmrg
39805b261ecSmrg    FOR_NSCREENS_FORWARD(j) {
39935c4bbdfSmrg        stuff->id = win->info[j].id;
40035c4bbdfSmrg        result = (*SavedProcVector[X_MapSubwindows]) (client);
40135c4bbdfSmrg        if (result != Success)
40235c4bbdfSmrg            break;
40305b261ecSmrg    }
40405b261ecSmrg
4056747b715Smrg    return result;
40605b261ecSmrg}
40705b261ecSmrg
40835c4bbdfSmrgint
40935c4bbdfSmrgPanoramiXUnmapWindow(ClientPtr client)
41005b261ecSmrg{
41105b261ecSmrg    PanoramiXRes *win;
41235c4bbdfSmrg    int result, j;
41335c4bbdfSmrg
41405b261ecSmrg    REQUEST(xResourceReq);
41505b261ecSmrg
41605b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
41705b261ecSmrg
41835c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->id,
41935c4bbdfSmrg                                     XRT_WINDOW, client, DixReadAccess);
4206747b715Smrg    if (result != Success)
42135c4bbdfSmrg        return result;
42205b261ecSmrg
42305b261ecSmrg    FOR_NSCREENS_FORWARD(j) {
42435c4bbdfSmrg        stuff->id = win->info[j].id;
42535c4bbdfSmrg        result = (*SavedProcVector[X_UnmapWindow]) (client);
42635c4bbdfSmrg        if (result != Success)
42735c4bbdfSmrg            break;
42805b261ecSmrg    }
42905b261ecSmrg
4306747b715Smrg    return result;
43105b261ecSmrg}
43205b261ecSmrg
43335c4bbdfSmrgint
43435c4bbdfSmrgPanoramiXUnmapSubwindows(ClientPtr client)
43505b261ecSmrg{
43605b261ecSmrg    PanoramiXRes *win;
43735c4bbdfSmrg    int result, j;
43835c4bbdfSmrg
43905b261ecSmrg    REQUEST(xResourceReq);
44005b261ecSmrg
44105b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
44205b261ecSmrg
44335c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->id,
44435c4bbdfSmrg                                     XRT_WINDOW, client, DixReadAccess);
4456747b715Smrg    if (result != Success)
44635c4bbdfSmrg        return result;
44705b261ecSmrg
44805b261ecSmrg    FOR_NSCREENS_FORWARD(j) {
44935c4bbdfSmrg        stuff->id = win->info[j].id;
45035c4bbdfSmrg        result = (*SavedProcVector[X_UnmapSubwindows]) (client);
45135c4bbdfSmrg        if (result != Success)
45235c4bbdfSmrg            break;
45305b261ecSmrg    }
45405b261ecSmrg
4556747b715Smrg    return result;
45605b261ecSmrg}
45705b261ecSmrg
45835c4bbdfSmrgint
45935c4bbdfSmrgPanoramiXConfigureWindow(ClientPtr client)
46005b261ecSmrg{
46105b261ecSmrg    PanoramiXRes *win;
46205b261ecSmrg    PanoramiXRes *sib = NULL;
46335c4bbdfSmrg    WindowPtr pWin;
46435c4bbdfSmrg    int result, j, len, sib_offset = 0, x = 0, y = 0;
46535c4bbdfSmrg    int x_offset = -1;
46635c4bbdfSmrg    int y_offset = -1;
46735c4bbdfSmrg
46805b261ecSmrg    REQUEST(xConfigureWindowReq);
46905b261ecSmrg
47005b261ecSmrg    REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
47105b261ecSmrg
4726747b715Smrg    len = client->req_len - bytes_to_int32(sizeof(xConfigureWindowReq));
47305b261ecSmrg    if (Ones(stuff->mask) != len)
47405b261ecSmrg        return BadLength;
47505b261ecSmrg
47605b261ecSmrg    /* because we need the parent */
47735c4bbdfSmrg    result = dixLookupResourceByType((void **) &pWin, stuff->window,
47835c4bbdfSmrg                                     RT_WINDOW, client, DixWriteAccess);
47935c4bbdfSmrg    if (result != Success)
48035c4bbdfSmrg        return result;
48135c4bbdfSmrg
48235c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->window,
48335c4bbdfSmrg                                     XRT_WINDOW, client, DixWriteAccess);
48435c4bbdfSmrg    if (result != Success)
48535c4bbdfSmrg        return result;
48635c4bbdfSmrg
48735c4bbdfSmrg    if ((Mask) stuff->mask & CWSibling) {
48835c4bbdfSmrg        XID tmp;
48935c4bbdfSmrg
49035c4bbdfSmrg        sib_offset = Ones((Mask) stuff->mask & (CWSibling - 1));
49135c4bbdfSmrg        if ((tmp = *((CARD32 *) &stuff[1] + sib_offset))) {
49235c4bbdfSmrg            result = dixLookupResourceByType((void **) &sib, tmp, XRT_WINDOW,
49335c4bbdfSmrg                                             client, DixReadAccess);
49435c4bbdfSmrg            if (result != Success)
49535c4bbdfSmrg                return result;
49635c4bbdfSmrg        }
49735c4bbdfSmrg    }
49835c4bbdfSmrg
49935c4bbdfSmrg    if (pWin->parent && ((pWin->parent == screenInfo.screens[0]->root) ||
50035c4bbdfSmrg                         (pWin->parent->drawable.id ==
50135c4bbdfSmrg                          screenInfo.screens[0]->screensaver.wid))) {
50235c4bbdfSmrg        if ((Mask) stuff->mask & CWX) {
50335c4bbdfSmrg            x_offset = 0;
50435c4bbdfSmrg            x = *((CARD32 *) &stuff[1]);
50535c4bbdfSmrg        }
50635c4bbdfSmrg        if ((Mask) stuff->mask & CWY) {
50735c4bbdfSmrg            y_offset = (x_offset == -1) ? 0 : 1;
50835c4bbdfSmrg            y = *((CARD32 *) &stuff[1] + y_offset);
50935c4bbdfSmrg        }
51035c4bbdfSmrg    }
51135c4bbdfSmrg
51235c4bbdfSmrg    /* have to go forward or you get expose events before
51335c4bbdfSmrg       ConfigureNotify events */
51405b261ecSmrg    FOR_NSCREENS_FORWARD(j) {
51535c4bbdfSmrg        stuff->window = win->info[j].id;
51635c4bbdfSmrg        if (sib)
51735c4bbdfSmrg            *((CARD32 *) &stuff[1] + sib_offset) = sib->info[j].id;
51835c4bbdfSmrg        if (x_offset >= 0)
51935c4bbdfSmrg            *((CARD32 *) &stuff[1] + x_offset) = x - screenInfo.screens[j]->x;
52035c4bbdfSmrg        if (y_offset >= 0)
52135c4bbdfSmrg            *((CARD32 *) &stuff[1] + y_offset) = y - screenInfo.screens[j]->y;
52235c4bbdfSmrg        result = (*SavedProcVector[X_ConfigureWindow]) (client);
52335c4bbdfSmrg        if (result != Success)
52435c4bbdfSmrg            break;
52505b261ecSmrg    }
52605b261ecSmrg
5276747b715Smrg    return result;
52805b261ecSmrg}
52905b261ecSmrg
53035c4bbdfSmrgint
53135c4bbdfSmrgPanoramiXCirculateWindow(ClientPtr client)
53205b261ecSmrg{
53305b261ecSmrg    PanoramiXRes *win;
53435c4bbdfSmrg    int result, j;
53535c4bbdfSmrg
53605b261ecSmrg    REQUEST(xCirculateWindowReq);
53705b261ecSmrg
53805b261ecSmrg    REQUEST_SIZE_MATCH(xCirculateWindowReq);
53905b261ecSmrg
54035c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->window,
54135c4bbdfSmrg                                     XRT_WINDOW, client, DixWriteAccess);
5426747b715Smrg    if (result != Success)
54335c4bbdfSmrg        return result;
54405b261ecSmrg
54505b261ecSmrg    FOR_NSCREENS_FORWARD(j) {
54635c4bbdfSmrg        stuff->window = win->info[j].id;
54735c4bbdfSmrg        result = (*SavedProcVector[X_CirculateWindow]) (client);
54835c4bbdfSmrg        if (result != Success)
54935c4bbdfSmrg            break;
55005b261ecSmrg    }
55105b261ecSmrg
5526747b715Smrg    return result;
55305b261ecSmrg}
55405b261ecSmrg
55535c4bbdfSmrgint
55635c4bbdfSmrgPanoramiXGetGeometry(ClientPtr client)
55705b261ecSmrg{
55835c4bbdfSmrg    xGetGeometryReply rep;
55905b261ecSmrg    DrawablePtr pDraw;
56005b261ecSmrg    int rc;
56135c4bbdfSmrg
56205b261ecSmrg    REQUEST(xResourceReq);
56305b261ecSmrg
56405b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
5654642e01fSmrg    rc = dixLookupDrawable(&pDraw, stuff->id, client, M_ANY, DixGetAttrAccess);
56605b261ecSmrg    if (rc != Success)
56735c4bbdfSmrg        return rc;
56805b261ecSmrg
56935c4bbdfSmrg    rep = (xGetGeometryReply) {
57035c4bbdfSmrg        .type = X_Reply,
57135c4bbdfSmrg        .sequenceNumber = client->sequence,
57235c4bbdfSmrg        .length = 0,
57335c4bbdfSmrg        .root = screenInfo.screens[0]->root->drawable.id,
57435c4bbdfSmrg        .depth = pDraw->depth,
57535c4bbdfSmrg        .width = pDraw->width,
57635c4bbdfSmrg        .height = pDraw->height,
57735c4bbdfSmrg        .x = 0,
57835c4bbdfSmrg        .y = 0,
57935c4bbdfSmrg        .borderWidth = 0
58035c4bbdfSmrg    };
58105b261ecSmrg
58205b261ecSmrg    if (stuff->id == rep.root) {
58335c4bbdfSmrg        xWindowRoot *root = (xWindowRoot *)
58435c4bbdfSmrg            (ConnectionInfo + connBlockScreenStart);
58535c4bbdfSmrg
58635c4bbdfSmrg        rep.width = root->pixWidth;
58735c4bbdfSmrg        rep.height = root->pixHeight;
58835c4bbdfSmrg    }
58935c4bbdfSmrg    else if (WindowDrawable(pDraw->type)) {
59035c4bbdfSmrg        WindowPtr pWin = (WindowPtr) pDraw;
59135c4bbdfSmrg
59235c4bbdfSmrg        rep.x = pWin->origin.x - wBorderWidth(pWin);
59335c4bbdfSmrg        rep.y = pWin->origin.y - wBorderWidth(pWin);
59435c4bbdfSmrg        if ((pWin->parent == screenInfo.screens[0]->root) ||
59535c4bbdfSmrg            (pWin->parent->drawable.id ==
59635c4bbdfSmrg             screenInfo.screens[0]->screensaver.wid)) {
59735c4bbdfSmrg            rep.x += screenInfo.screens[0]->x;
59835c4bbdfSmrg            rep.y += screenInfo.screens[0]->y;
59935c4bbdfSmrg        }
60035c4bbdfSmrg        rep.borderWidth = pWin->borderWidth;
60105b261ecSmrg    }
60205b261ecSmrg
60305b261ecSmrg    WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep);
6046747b715Smrg    return Success;
60505b261ecSmrg}
60605b261ecSmrg
60735c4bbdfSmrgint
60835c4bbdfSmrgPanoramiXTranslateCoords(ClientPtr client)
60905b261ecSmrg{
61005b261ecSmrg    INT16 x, y;
61135c4bbdfSmrg
61205b261ecSmrg    REQUEST(xTranslateCoordsReq);
61305b261ecSmrg    int rc;
61405b261ecSmrg    WindowPtr pWin, pDst;
61505b261ecSmrg    xTranslateCoordsReply rep;
61605b261ecSmrg
61705b261ecSmrg    REQUEST_SIZE_MATCH(xTranslateCoordsReq);
61805b261ecSmrg    rc = dixLookupWindow(&pWin, stuff->srcWid, client, DixReadAccess);
61905b261ecSmrg    if (rc != Success)
62005b261ecSmrg        return rc;
62105b261ecSmrg    rc = dixLookupWindow(&pDst, stuff->dstWid, client, DixReadAccess);
62205b261ecSmrg    if (rc != Success)
62305b261ecSmrg        return rc;
62435c4bbdfSmrg    rep = (xTranslateCoordsReply) {
62535c4bbdfSmrg        .type = X_Reply,
62635c4bbdfSmrg        .sequenceNumber = client->sequence,
62735c4bbdfSmrg        .length = 0,
62835c4bbdfSmrg        .sameScreen = xTrue,
62935c4bbdfSmrg        .child = None
63035c4bbdfSmrg    };
63135c4bbdfSmrg
63235c4bbdfSmrg    if ((pWin == screenInfo.screens[0]->root) ||
63335c4bbdfSmrg        (pWin->drawable.id == screenInfo.screens[0]->screensaver.wid)) {
63435c4bbdfSmrg        x = stuff->srcX - screenInfo.screens[0]->x;
63535c4bbdfSmrg        y = stuff->srcY - screenInfo.screens[0]->y;
63635c4bbdfSmrg    }
63735c4bbdfSmrg    else {
63835c4bbdfSmrg        x = pWin->drawable.x + stuff->srcX;
63935c4bbdfSmrg        y = pWin->drawable.y + stuff->srcY;
64005b261ecSmrg    }
64105b261ecSmrg    pWin = pDst->firstChild;
64205b261ecSmrg    while (pWin) {
64335c4bbdfSmrg        BoxRec box;
64435c4bbdfSmrg
64535c4bbdfSmrg        if ((pWin->mapped) &&
64635c4bbdfSmrg            (x >= pWin->drawable.x - wBorderWidth(pWin)) &&
64735c4bbdfSmrg            (x < pWin->drawable.x + (int) pWin->drawable.width +
64835c4bbdfSmrg             wBorderWidth(pWin)) &&
64935c4bbdfSmrg            (y >= pWin->drawable.y - wBorderWidth(pWin)) &&
65035c4bbdfSmrg            (y < pWin->drawable.y + (int) pWin->drawable.height +
65135c4bbdfSmrg             wBorderWidth(pWin))
65235c4bbdfSmrg            /* When a window is shaped, a further check
65335c4bbdfSmrg             * is made to see if the point is inside
65435c4bbdfSmrg             * borderSize
65535c4bbdfSmrg             */
65635c4bbdfSmrg            && (!wBoundingShape(pWin) ||
65735c4bbdfSmrg                RegionContainsPoint(wBoundingShape(pWin),
65835c4bbdfSmrg                                    x - pWin->drawable.x,
65935c4bbdfSmrg                                    y - pWin->drawable.y, &box))
66035c4bbdfSmrg            ) {
66135c4bbdfSmrg            rep.child = pWin->drawable.id;
66235c4bbdfSmrg            pWin = (WindowPtr) NULL;
66335c4bbdfSmrg        }
66435c4bbdfSmrg        else
66535c4bbdfSmrg            pWin = pWin->nextSib;
66605b261ecSmrg    }
66705b261ecSmrg    rep.dstX = x - pDst->drawable.x;
66805b261ecSmrg    rep.dstY = y - pDst->drawable.y;
66935c4bbdfSmrg    if ((pDst == screenInfo.screens[0]->root) ||
67035c4bbdfSmrg        (pDst->drawable.id == screenInfo.screens[0]->screensaver.wid)) {
67135c4bbdfSmrg        rep.dstX += screenInfo.screens[0]->x;
67235c4bbdfSmrg        rep.dstY += screenInfo.screens[0]->y;
67305b261ecSmrg    }
67405b261ecSmrg
67505b261ecSmrg    WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep);
6766747b715Smrg    return Success;
67705b261ecSmrg}
67805b261ecSmrg
67935c4bbdfSmrgint
68035c4bbdfSmrgPanoramiXCreatePixmap(ClientPtr client)
68105b261ecSmrg{
68205b261ecSmrg    PanoramiXRes *refDraw, *newPix;
6836747b715Smrg    int result, j;
68435c4bbdfSmrg
68505b261ecSmrg    REQUEST(xCreatePixmapReq);
68605b261ecSmrg
68705b261ecSmrg    REQUEST_SIZE_MATCH(xCreatePixmapReq);
68805b261ecSmrg    client->errorValue = stuff->pid;
68905b261ecSmrg
69035c4bbdfSmrg    result = dixLookupResourceByClass((void **) &refDraw, stuff->drawable,
69135c4bbdfSmrg                                      XRC_DRAWABLE, client, DixReadAccess);
6926747b715Smrg    if (result != Success)
69335c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
69405b261ecSmrg
69535c4bbdfSmrg    if (!(newPix = malloc(sizeof(PanoramiXRes))))
69635c4bbdfSmrg        return BadAlloc;
69705b261ecSmrg
69805b261ecSmrg    newPix->type = XRT_PIXMAP;
69905b261ecSmrg    newPix->u.pix.shared = FALSE;
70035c4bbdfSmrg    panoramix_setup_ids(newPix, client, stuff->pid);
70135c4bbdfSmrg
70205b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
70335c4bbdfSmrg        stuff->pid = newPix->info[j].id;
70435c4bbdfSmrg        stuff->drawable = refDraw->info[j].id;
70535c4bbdfSmrg        result = (*SavedProcVector[X_CreatePixmap]) (client);
70635c4bbdfSmrg        if (result != Success)
70735c4bbdfSmrg            break;
70805b261ecSmrg    }
70905b261ecSmrg
71005b261ecSmrg    if (result == Success)
71135c4bbdfSmrg        AddResource(newPix->info[0].id, XRT_PIXMAP, newPix);
71235c4bbdfSmrg    else
71335c4bbdfSmrg        free(newPix);
71405b261ecSmrg
7156747b715Smrg    return result;
71605b261ecSmrg}
71705b261ecSmrg
71835c4bbdfSmrgint
71935c4bbdfSmrgPanoramiXFreePixmap(ClientPtr client)
72005b261ecSmrg{
72105b261ecSmrg    PanoramiXRes *pix;
72235c4bbdfSmrg    int result, j;
72335c4bbdfSmrg
72405b261ecSmrg    REQUEST(xResourceReq);
72505b261ecSmrg
72605b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
72705b261ecSmrg
72805b261ecSmrg    client->errorValue = stuff->id;
72905b261ecSmrg
73035c4bbdfSmrg    result = dixLookupResourceByType((void **) &pix, stuff->id, XRT_PIXMAP,
73135c4bbdfSmrg                                     client, DixDestroyAccess);
7326747b715Smrg    if (result != Success)
73335c4bbdfSmrg        return result;
73405b261ecSmrg
73505b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
73635c4bbdfSmrg        stuff->id = pix->info[j].id;
73735c4bbdfSmrg        result = (*SavedProcVector[X_FreePixmap]) (client);
73835c4bbdfSmrg        if (result != Success)
73935c4bbdfSmrg            break;
74005b261ecSmrg    }
74105b261ecSmrg
74205b261ecSmrg    /* Since ProcFreePixmap is using FreeResource, it will free
74335c4bbdfSmrg       our resource for us on the last pass through the loop above */
74435c4bbdfSmrg
7456747b715Smrg    return result;
74605b261ecSmrg}
74705b261ecSmrg
74835c4bbdfSmrgint
74935c4bbdfSmrgPanoramiXCreateGC(ClientPtr client)
75005b261ecSmrg{
75105b261ecSmrg    PanoramiXRes *refDraw;
75205b261ecSmrg    PanoramiXRes *newGC;
75305b261ecSmrg    PanoramiXRes *stip = NULL;
75405b261ecSmrg    PanoramiXRes *tile = NULL;
75505b261ecSmrg    PanoramiXRes *clip = NULL;
75635c4bbdfSmrg
75705b261ecSmrg    REQUEST(xCreateGCReq);
75805b261ecSmrg    int tile_offset = 0, stip_offset = 0, clip_offset = 0;
7596747b715Smrg    int result, len, j;
76005b261ecSmrg    XID tmp;
76105b261ecSmrg
76205b261ecSmrg    REQUEST_AT_LEAST_SIZE(xCreateGCReq);
76335c4bbdfSmrg
76405b261ecSmrg    client->errorValue = stuff->gc;
7656747b715Smrg    len = client->req_len - bytes_to_int32(sizeof(xCreateGCReq));
76605b261ecSmrg    if (Ones(stuff->mask) != len)
76705b261ecSmrg        return BadLength;
76805b261ecSmrg
76935c4bbdfSmrg    result = dixLookupResourceByClass((void **) &refDraw, stuff->drawable,
77035c4bbdfSmrg                                      XRC_DRAWABLE, client, DixReadAccess);
77135c4bbdfSmrg    if (result != Success)
77235c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
77335c4bbdfSmrg
77435c4bbdfSmrg    if ((Mask) stuff->mask & GCTile) {
77535c4bbdfSmrg        tile_offset = Ones((Mask) stuff->mask & (GCTile - 1));
77635c4bbdfSmrg        if ((tmp = *((CARD32 *) &stuff[1] + tile_offset))) {
77735c4bbdfSmrg            result = dixLookupResourceByType((void **) &tile, tmp, XRT_PIXMAP,
77835c4bbdfSmrg                                             client, DixReadAccess);
77935c4bbdfSmrg            if (result != Success)
78035c4bbdfSmrg                return result;
78135c4bbdfSmrg        }
78235c4bbdfSmrg    }
78335c4bbdfSmrg    if ((Mask) stuff->mask & GCStipple) {
78435c4bbdfSmrg        stip_offset = Ones((Mask) stuff->mask & (GCStipple - 1));
78535c4bbdfSmrg        if ((tmp = *((CARD32 *) &stuff[1] + stip_offset))) {
78635c4bbdfSmrg            result = dixLookupResourceByType((void **) &stip, tmp, XRT_PIXMAP,
78735c4bbdfSmrg                                             client, DixReadAccess);
78835c4bbdfSmrg            if (result != Success)
78935c4bbdfSmrg                return result;
79035c4bbdfSmrg        }
79135c4bbdfSmrg    }
79235c4bbdfSmrg    if ((Mask) stuff->mask & GCClipMask) {
79335c4bbdfSmrg        clip_offset = Ones((Mask) stuff->mask & (GCClipMask - 1));
79435c4bbdfSmrg        if ((tmp = *((CARD32 *) &stuff[1] + clip_offset))) {
79535c4bbdfSmrg            result = dixLookupResourceByType((void **) &clip, tmp, XRT_PIXMAP,
79635c4bbdfSmrg                                             client, DixReadAccess);
79735c4bbdfSmrg            if (result != Success)
79835c4bbdfSmrg                return result;
79935c4bbdfSmrg        }
80035c4bbdfSmrg    }
80135c4bbdfSmrg
80235c4bbdfSmrg    if (!(newGC = malloc(sizeof(PanoramiXRes))))
80305b261ecSmrg        return BadAlloc;
80405b261ecSmrg
80505b261ecSmrg    newGC->type = XRT_GC;
80635c4bbdfSmrg    panoramix_setup_ids(newGC, client, stuff->gc);
80705b261ecSmrg
80805b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
80905b261ecSmrg        stuff->gc = newGC->info[j].id;
81005b261ecSmrg        stuff->drawable = refDraw->info[j].id;
81135c4bbdfSmrg        if (tile)
81235c4bbdfSmrg            *((CARD32 *) &stuff[1] + tile_offset) = tile->info[j].id;
81335c4bbdfSmrg        if (stip)
81435c4bbdfSmrg            *((CARD32 *) &stuff[1] + stip_offset) = stip->info[j].id;
81535c4bbdfSmrg        if (clip)
81635c4bbdfSmrg            *((CARD32 *) &stuff[1] + clip_offset) = clip->info[j].id;
81735c4bbdfSmrg        result = (*SavedProcVector[X_CreateGC]) (client);
81835c4bbdfSmrg        if (result != Success)
81935c4bbdfSmrg            break;
82005b261ecSmrg    }
82105b261ecSmrg
82205b261ecSmrg    if (result == Success)
82305b261ecSmrg        AddResource(newGC->info[0].id, XRT_GC, newGC);
82435c4bbdfSmrg    else
8256747b715Smrg        free(newGC);
82605b261ecSmrg
8276747b715Smrg    return result;
82805b261ecSmrg}
82905b261ecSmrg
83035c4bbdfSmrgint
83135c4bbdfSmrgPanoramiXChangeGC(ClientPtr client)
83205b261ecSmrg{
83305b261ecSmrg    PanoramiXRes *gc;
83405b261ecSmrg    PanoramiXRes *stip = NULL;
83505b261ecSmrg    PanoramiXRes *tile = NULL;
83605b261ecSmrg    PanoramiXRes *clip = NULL;
83735c4bbdfSmrg
83805b261ecSmrg    REQUEST(xChangeGCReq);
83905b261ecSmrg    int tile_offset = 0, stip_offset = 0, clip_offset = 0;
8406747b715Smrg    int result, len, j;
84105b261ecSmrg    XID tmp;
84205b261ecSmrg
84305b261ecSmrg    REQUEST_AT_LEAST_SIZE(xChangeGCReq);
84435c4bbdfSmrg
8456747b715Smrg    len = client->req_len - bytes_to_int32(sizeof(xChangeGCReq));
84605b261ecSmrg    if (Ones(stuff->mask) != len)
84705b261ecSmrg        return BadLength;
84805b261ecSmrg
84935c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
85035c4bbdfSmrg                                     client, DixReadAccess);
8516747b715Smrg    if (result != Success)
85235c4bbdfSmrg        return result;
85305b261ecSmrg
85435c4bbdfSmrg    if ((Mask) stuff->mask & GCTile) {
85535c4bbdfSmrg        tile_offset = Ones((Mask) stuff->mask & (GCTile - 1));
85635c4bbdfSmrg        if ((tmp = *((CARD32 *) &stuff[1] + tile_offset))) {
85735c4bbdfSmrg            result = dixLookupResourceByType((void **) &tile, tmp, XRT_PIXMAP,
85835c4bbdfSmrg                                             client, DixReadAccess);
85935c4bbdfSmrg            if (result != Success)
86035c4bbdfSmrg                return result;
86135c4bbdfSmrg        }
86205b261ecSmrg    }
86335c4bbdfSmrg    if ((Mask) stuff->mask & GCStipple) {
86435c4bbdfSmrg        stip_offset = Ones((Mask) stuff->mask & (GCStipple - 1));
86535c4bbdfSmrg        if ((tmp = *((CARD32 *) &stuff[1] + stip_offset))) {
86635c4bbdfSmrg            result = dixLookupResourceByType((void **) &stip, tmp, XRT_PIXMAP,
86735c4bbdfSmrg                                             client, DixReadAccess);
86835c4bbdfSmrg            if (result != Success)
86935c4bbdfSmrg                return result;
87035c4bbdfSmrg        }
87105b261ecSmrg    }
87235c4bbdfSmrg    if ((Mask) stuff->mask & GCClipMask) {
87335c4bbdfSmrg        clip_offset = Ones((Mask) stuff->mask & (GCClipMask - 1));
87435c4bbdfSmrg        if ((tmp = *((CARD32 *) &stuff[1] + clip_offset))) {
87535c4bbdfSmrg            result = dixLookupResourceByType((void **) &clip, tmp, XRT_PIXMAP,
87635c4bbdfSmrg                                             client, DixReadAccess);
87735c4bbdfSmrg            if (result != Success)
87835c4bbdfSmrg                return result;
87935c4bbdfSmrg        }
88005b261ecSmrg    }
88105b261ecSmrg
88205b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
88305b261ecSmrg        stuff->gc = gc->info[j].id;
88435c4bbdfSmrg        if (tile)
88535c4bbdfSmrg            *((CARD32 *) &stuff[1] + tile_offset) = tile->info[j].id;
88635c4bbdfSmrg        if (stip)
88735c4bbdfSmrg            *((CARD32 *) &stuff[1] + stip_offset) = stip->info[j].id;
88835c4bbdfSmrg        if (clip)
88935c4bbdfSmrg            *((CARD32 *) &stuff[1] + clip_offset) = clip->info[j].id;
89035c4bbdfSmrg        result = (*SavedProcVector[X_ChangeGC]) (client);
89135c4bbdfSmrg        if (result != Success)
89235c4bbdfSmrg            break;
89305b261ecSmrg    }
89405b261ecSmrg
8956747b715Smrg    return result;
89605b261ecSmrg}
89705b261ecSmrg
89835c4bbdfSmrgint
89935c4bbdfSmrgPanoramiXCopyGC(ClientPtr client)
90005b261ecSmrg{
90105b261ecSmrg    PanoramiXRes *srcGC, *dstGC;
90235c4bbdfSmrg    int result, j;
90335c4bbdfSmrg
90405b261ecSmrg    REQUEST(xCopyGCReq);
90505b261ecSmrg
90605b261ecSmrg    REQUEST_SIZE_MATCH(xCopyGCReq);
90705b261ecSmrg
90835c4bbdfSmrg    result = dixLookupResourceByType((void **) &srcGC, stuff->srcGC, XRT_GC,
90935c4bbdfSmrg                                     client, DixReadAccess);
9106747b715Smrg    if (result != Success)
91135c4bbdfSmrg        return result;
91205b261ecSmrg
91335c4bbdfSmrg    result = dixLookupResourceByType((void **) &dstGC, stuff->dstGC, XRT_GC,
91435c4bbdfSmrg                                     client, DixWriteAccess);
9156747b715Smrg    if (result != Success)
91635c4bbdfSmrg        return result;
91705b261ecSmrg
91805b261ecSmrg    FOR_NSCREENS(j) {
91935c4bbdfSmrg        stuff->srcGC = srcGC->info[j].id;
92035c4bbdfSmrg        stuff->dstGC = dstGC->info[j].id;
92135c4bbdfSmrg        result = (*SavedProcVector[X_CopyGC]) (client);
92235c4bbdfSmrg        if (result != Success)
92335c4bbdfSmrg            break;
92405b261ecSmrg    }
92505b261ecSmrg
9266747b715Smrg    return result;
92705b261ecSmrg}
92805b261ecSmrg
92935c4bbdfSmrgint
93035c4bbdfSmrgPanoramiXSetDashes(ClientPtr client)
93105b261ecSmrg{
93205b261ecSmrg    PanoramiXRes *gc;
93335c4bbdfSmrg    int result, j;
93435c4bbdfSmrg
93505b261ecSmrg    REQUEST(xSetDashesReq);
93605b261ecSmrg
93705b261ecSmrg    REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes);
93805b261ecSmrg
93935c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
94035c4bbdfSmrg                                     client, DixWriteAccess);
9416747b715Smrg    if (result != Success)
94235c4bbdfSmrg        return result;
94305b261ecSmrg
94405b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
94535c4bbdfSmrg        stuff->gc = gc->info[j].id;
94635c4bbdfSmrg        result = (*SavedProcVector[X_SetDashes]) (client);
94735c4bbdfSmrg        if (result != Success)
94835c4bbdfSmrg            break;
94905b261ecSmrg    }
95005b261ecSmrg
9516747b715Smrg    return result;
95205b261ecSmrg}
95305b261ecSmrg
95435c4bbdfSmrgint
95535c4bbdfSmrgPanoramiXSetClipRectangles(ClientPtr client)
95605b261ecSmrg{
95705b261ecSmrg    PanoramiXRes *gc;
95835c4bbdfSmrg    int result, j;
95935c4bbdfSmrg
96005b261ecSmrg    REQUEST(xSetClipRectanglesReq);
96105b261ecSmrg
96205b261ecSmrg    REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq);
96305b261ecSmrg
96435c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
96535c4bbdfSmrg                                     client, DixWriteAccess);
9666747b715Smrg    if (result != Success)
96735c4bbdfSmrg        return result;
96805b261ecSmrg
96905b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
97035c4bbdfSmrg        stuff->gc = gc->info[j].id;
97135c4bbdfSmrg        result = (*SavedProcVector[X_SetClipRectangles]) (client);
97235c4bbdfSmrg        if (result != Success)
97335c4bbdfSmrg            break;
97405b261ecSmrg    }
97505b261ecSmrg
9766747b715Smrg    return result;
97705b261ecSmrg}
97805b261ecSmrg
97935c4bbdfSmrgint
98035c4bbdfSmrgPanoramiXFreeGC(ClientPtr client)
98105b261ecSmrg{
98205b261ecSmrg    PanoramiXRes *gc;
98335c4bbdfSmrg    int result, j;
98435c4bbdfSmrg
98505b261ecSmrg    REQUEST(xResourceReq);
98605b261ecSmrg
98705b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
98805b261ecSmrg
98935c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->id, XRT_GC,
99035c4bbdfSmrg                                     client, DixDestroyAccess);
9916747b715Smrg    if (result != Success)
99235c4bbdfSmrg        return result;
99305b261ecSmrg
99405b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
99535c4bbdfSmrg        stuff->id = gc->info[j].id;
99635c4bbdfSmrg        result = (*SavedProcVector[X_FreeGC]) (client);
99735c4bbdfSmrg        if (result != Success)
99835c4bbdfSmrg            break;
99905b261ecSmrg    }
100005b261ecSmrg
100105b261ecSmrg    /* Since ProcFreeGC is using FreeResource, it will free
100235c4bbdfSmrg       our resource for us on the last pass through the loop above */
100335c4bbdfSmrg
10046747b715Smrg    return result;
100505b261ecSmrg}
100605b261ecSmrg
100735c4bbdfSmrgint
100835c4bbdfSmrgPanoramiXClearToBackground(ClientPtr client)
100905b261ecSmrg{
101005b261ecSmrg    PanoramiXRes *win;
101135c4bbdfSmrg    int result, j, x, y;
101235c4bbdfSmrg    Bool isRoot;
101335c4bbdfSmrg
101405b261ecSmrg    REQUEST(xClearAreaReq);
101505b261ecSmrg
101605b261ecSmrg    REQUEST_SIZE_MATCH(xClearAreaReq);
101705b261ecSmrg
101835c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->window,
101935c4bbdfSmrg                                     XRT_WINDOW, client, DixWriteAccess);
10206747b715Smrg    if (result != Success)
102135c4bbdfSmrg        return result;
102205b261ecSmrg
102305b261ecSmrg    x = stuff->x;
102405b261ecSmrg    y = stuff->y;
102505b261ecSmrg    isRoot = win->u.win.root;
102605b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
102735c4bbdfSmrg        stuff->window = win->info[j].id;
102835c4bbdfSmrg        if (isRoot) {
102935c4bbdfSmrg            stuff->x = x - screenInfo.screens[j]->x;
103035c4bbdfSmrg            stuff->y = y - screenInfo.screens[j]->y;
103135c4bbdfSmrg        }
103235c4bbdfSmrg        result = (*SavedProcVector[X_ClearArea]) (client);
103335c4bbdfSmrg        if (result != Success)
103435c4bbdfSmrg            break;
103535c4bbdfSmrg    }
103635c4bbdfSmrg
10376747b715Smrg    return result;
103805b261ecSmrg}
103905b261ecSmrg
104035c4bbdfSmrg/*
104105b261ecSmrg    For Window to Pixmap copies you're screwed since each screen's
104205b261ecSmrg    pixmap will look like what it sees on its screen.  Unless the
104305b261ecSmrg    screens overlap and the window lies on each, the two copies
104405b261ecSmrg    will be out of sync.  To remedy this we do a GetImage and PutImage
104505b261ecSmrg    in place of the copy.  Doing this as a single Image isn't quite
104605b261ecSmrg    correct since it will include the obscured areas but we will
104705b261ecSmrg    have to fix this later. (MArk).
104805b261ecSmrg*/
104905b261ecSmrg
105035c4bbdfSmrgint
105135c4bbdfSmrgPanoramiXCopyArea(ClientPtr client)
105205b261ecSmrg{
10531b5d61b8Smrg    int j, result, srcx, srcy, dstx, dsty, width, height;
105435c4bbdfSmrg    PanoramiXRes *gc, *src, *dst;
105535c4bbdfSmrg    Bool srcIsRoot = FALSE;
105635c4bbdfSmrg    Bool dstIsRoot = FALSE;
105735c4bbdfSmrg    Bool srcShared, dstShared;
105835c4bbdfSmrg
105905b261ecSmrg    REQUEST(xCopyAreaReq);
106005b261ecSmrg
106105b261ecSmrg    REQUEST_SIZE_MATCH(xCopyAreaReq);
106205b261ecSmrg
106335c4bbdfSmrg    result = dixLookupResourceByClass((void **) &src, stuff->srcDrawable,
106435c4bbdfSmrg                                      XRC_DRAWABLE, client, DixReadAccess);
10656747b715Smrg    if (result != Success)
106635c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
106705b261ecSmrg
106805b261ecSmrg    srcShared = IS_SHARED_PIXMAP(src);
106905b261ecSmrg
107035c4bbdfSmrg    result = dixLookupResourceByClass((void **) &dst, stuff->dstDrawable,
107135c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
10726747b715Smrg    if (result != Success)
107335c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
107405b261ecSmrg
107505b261ecSmrg    dstShared = IS_SHARED_PIXMAP(dst);
107605b261ecSmrg
107735c4bbdfSmrg    if (dstShared && srcShared)
107835c4bbdfSmrg        return (*SavedProcVector[X_CopyArea]) (client);
107905b261ecSmrg
108035c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
108135c4bbdfSmrg                                     client, DixReadAccess);
10826747b715Smrg    if (result != Success)
108335c4bbdfSmrg        return result;
108405b261ecSmrg
108535c4bbdfSmrg    if ((dst->type == XRT_WINDOW) && dst->u.win.root)
108635c4bbdfSmrg        dstIsRoot = TRUE;
108735c4bbdfSmrg    if ((src->type == XRT_WINDOW) && src->u.win.root)
108835c4bbdfSmrg        srcIsRoot = TRUE;
108935c4bbdfSmrg
109035c4bbdfSmrg    srcx = stuff->srcX;
109135c4bbdfSmrg    srcy = stuff->srcY;
109235c4bbdfSmrg    dstx = stuff->dstX;
109335c4bbdfSmrg    dsty = stuff->dstY;
10941b5d61b8Smrg    width = stuff->width;
10951b5d61b8Smrg    height = stuff->height;
109635c4bbdfSmrg    if ((dst->type == XRT_PIXMAP) && (src->type == XRT_WINDOW)) {
109735c4bbdfSmrg        DrawablePtr drawables[MAXSCREENS];
109835c4bbdfSmrg        DrawablePtr pDst;
109935c4bbdfSmrg        GCPtr pGC;
110005b261ecSmrg        char *data;
110135c4bbdfSmrg        int pitch, rc;
110235c4bbdfSmrg
110335c4bbdfSmrg        FOR_NSCREENS(j) {
110435c4bbdfSmrg            rc = dixLookupDrawable(drawables + j, src->info[j].id, client, 0,
110535c4bbdfSmrg                                   DixGetAttrAccess);
110635c4bbdfSmrg            if (rc != Success)
110735c4bbdfSmrg                return rc;
110825da500fSmrg            drawables[j]->pScreen->SourceValidate(drawables[j], 0, 0,
110925da500fSmrg                                                  drawables[j]->width,
111025da500fSmrg                                                  drawables[j]->height,
111125da500fSmrg                                                  IncludeInferiors);
111235c4bbdfSmrg        }
111335c4bbdfSmrg
11141b5d61b8Smrg        pitch = PixmapBytePad(width, drawables[0]->depth);
11151b5d61b8Smrg        if (!(data = calloc(height, pitch)))
111635c4bbdfSmrg            return BadAlloc;
111735c4bbdfSmrg
11181b5d61b8Smrg        XineramaGetImageData(drawables, srcx, srcy, width, height, ZPixmap, ~0,
11191b5d61b8Smrg                             data, pitch, srcIsRoot);
112035c4bbdfSmrg
112135c4bbdfSmrg        FOR_NSCREENS_BACKWARD(j) {
112235c4bbdfSmrg            stuff->gc = gc->info[j].id;
112335c4bbdfSmrg            VALIDATE_DRAWABLE_AND_GC(dst->info[j].id, pDst, DixWriteAccess);
112435c4bbdfSmrg            if (drawables[0]->depth != pDst->depth) {
112535c4bbdfSmrg                client->errorValue = stuff->dstDrawable;
112635c4bbdfSmrg                free(data);
112735c4bbdfSmrg                return BadMatch;
112835c4bbdfSmrg            }
112935c4bbdfSmrg
113035c4bbdfSmrg            (*pGC->ops->PutImage) (pDst, pGC, pDst->depth, dstx, dsty,
11311b5d61b8Smrg                                   width, height, 0, ZPixmap, data);
113235c4bbdfSmrg            if (dstShared)
113335c4bbdfSmrg                break;
113435c4bbdfSmrg        }
113535c4bbdfSmrg        free(data);
11361b5d61b8Smrg
11371b5d61b8Smrg        if (pGC->graphicsExposures) {
11381b5d61b8Smrg            RegionRec rgn;
11391b5d61b8Smrg            int dx, dy;
11401b5d61b8Smrg            BoxRec sourceBox;
11411b5d61b8Smrg
11421b5d61b8Smrg            dx = drawables[0]->x;
11431b5d61b8Smrg            dy = drawables[0]->y;
11441b5d61b8Smrg            if (srcIsRoot) {
11451b5d61b8Smrg                dx += screenInfo.screens[0]->x;
11461b5d61b8Smrg                dy += screenInfo.screens[0]->y;
11471b5d61b8Smrg            }
11481b5d61b8Smrg
11491b5d61b8Smrg            sourceBox.x1 = min(srcx + dx, 0);
11501b5d61b8Smrg            sourceBox.y1 = min(srcy + dy, 0);
11511b5d61b8Smrg            sourceBox.x2 = max(sourceBox.x1 + width, 32767);
11521b5d61b8Smrg            sourceBox.y2 = max(sourceBox.y1 + height, 32767);
11531b5d61b8Smrg
11541b5d61b8Smrg            RegionInit(&rgn, &sourceBox, 1);
11551b5d61b8Smrg
11561b5d61b8Smrg            /* subtract the (screen-space) clips of the source drawables */
11571b5d61b8Smrg            FOR_NSCREENS(j) {
11581b5d61b8Smrg                ScreenPtr screen = screenInfo.screens[j];
11591b5d61b8Smrg                RegionPtr sd;
11601b5d61b8Smrg
11611b5d61b8Smrg                if (pGC->subWindowMode == IncludeInferiors)
11621b5d61b8Smrg                    sd = NotClippedByChildren((WindowPtr)drawables[j]);
11631b5d61b8Smrg                else
11641b5d61b8Smrg                    sd = &((WindowPtr)drawables[j])->clipList;
11651b5d61b8Smrg
11661b5d61b8Smrg                if (srcIsRoot)
11671b5d61b8Smrg                    RegionTranslate(&rgn, -screen->x, -screen->y);
11681b5d61b8Smrg
11691b5d61b8Smrg                RegionSubtract(&rgn, &rgn, sd);
11701b5d61b8Smrg
11711b5d61b8Smrg                if (srcIsRoot)
11721b5d61b8Smrg                    RegionTranslate(&rgn, screen->x, screen->y);
11731b5d61b8Smrg
11741b5d61b8Smrg                if (pGC->subWindowMode == IncludeInferiors)
11751b5d61b8Smrg                    RegionDestroy(sd);
11761b5d61b8Smrg            }
11771b5d61b8Smrg
11781b5d61b8Smrg            /* -dx/-dy to get back to dest-relative, plus request offsets */
11791b5d61b8Smrg            RegionTranslate(&rgn, -dx + dstx, -dy + dsty);
11801b5d61b8Smrg
11811b5d61b8Smrg            /* intersect with gc clip; just one screen is fine because pixmap */
11821b5d61b8Smrg            RegionIntersect(&rgn, &rgn, pGC->pCompositeClip);
11831b5d61b8Smrg
11841b5d61b8Smrg            /* and expose */
11851b5d61b8Smrg            SendGraphicsExpose(client, &rgn, dst->info[0].id, X_CopyArea, 0);
11861b5d61b8Smrg            RegionUninit(&rgn);
11871b5d61b8Smrg        }
118835c4bbdfSmrg    }
118935c4bbdfSmrg    else {
119035c4bbdfSmrg        DrawablePtr pDst = NULL, pSrc = NULL;
119135c4bbdfSmrg        GCPtr pGC = NULL;
119235c4bbdfSmrg        RegionRec totalReg;
119335c4bbdfSmrg        int rc;
119435c4bbdfSmrg
119535c4bbdfSmrg        RegionNull(&totalReg);
119635c4bbdfSmrg        FOR_NSCREENS_BACKWARD(j) {
119735c4bbdfSmrg            RegionPtr pRgn;
119835c4bbdfSmrg
119935c4bbdfSmrg            stuff->dstDrawable = dst->info[j].id;
120035c4bbdfSmrg            stuff->srcDrawable = src->info[j].id;
120135c4bbdfSmrg            stuff->gc = gc->info[j].id;
120235c4bbdfSmrg            if (srcIsRoot) {
120335c4bbdfSmrg                stuff->srcX = srcx - screenInfo.screens[j]->x;
120435c4bbdfSmrg                stuff->srcY = srcy - screenInfo.screens[j]->y;
120535c4bbdfSmrg            }
120635c4bbdfSmrg            if (dstIsRoot) {
120735c4bbdfSmrg                stuff->dstX = dstx - screenInfo.screens[j]->x;
120835c4bbdfSmrg                stuff->dstY = dsty - screenInfo.screens[j]->y;
120935c4bbdfSmrg            }
121035c4bbdfSmrg
121135c4bbdfSmrg            VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, DixWriteAccess);
121235c4bbdfSmrg
121335c4bbdfSmrg            if (stuff->dstDrawable != stuff->srcDrawable) {
121435c4bbdfSmrg                rc = dixLookupDrawable(&pSrc, stuff->srcDrawable, client, 0,
121535c4bbdfSmrg                                       DixReadAccess);
121635c4bbdfSmrg                if (rc != Success)
121735c4bbdfSmrg                    return rc;
121835c4bbdfSmrg
121935c4bbdfSmrg                if ((pDst->pScreen != pSrc->pScreen) ||
122035c4bbdfSmrg                    (pDst->depth != pSrc->depth)) {
122135c4bbdfSmrg                    client->errorValue = stuff->dstDrawable;
122235c4bbdfSmrg                    return BadMatch;
122335c4bbdfSmrg                }
122435c4bbdfSmrg            }
122535c4bbdfSmrg            else
122635c4bbdfSmrg                pSrc = pDst;
122735c4bbdfSmrg
122835c4bbdfSmrg            pRgn = (*pGC->ops->CopyArea) (pSrc, pDst, pGC,
122935c4bbdfSmrg                                          stuff->srcX, stuff->srcY,
123035c4bbdfSmrg                                          stuff->width, stuff->height,
123135c4bbdfSmrg                                          stuff->dstX, stuff->dstY);
123235c4bbdfSmrg            if (pGC->graphicsExposures && pRgn) {
123335c4bbdfSmrg                if (srcIsRoot) {
123435c4bbdfSmrg                    RegionTranslate(pRgn,
123535c4bbdfSmrg                                    screenInfo.screens[j]->x,
123635c4bbdfSmrg                                    screenInfo.screens[j]->y);
123735c4bbdfSmrg                }
123835c4bbdfSmrg                RegionAppend(&totalReg, pRgn);
123935c4bbdfSmrg                RegionDestroy(pRgn);
124035c4bbdfSmrg            }
124135c4bbdfSmrg
124235c4bbdfSmrg            if (dstShared)
124335c4bbdfSmrg                break;
124435c4bbdfSmrg        }
124535c4bbdfSmrg
124635c4bbdfSmrg        if (pGC->graphicsExposures) {
124735c4bbdfSmrg            Bool overlap;
124835c4bbdfSmrg
124935c4bbdfSmrg            RegionValidate(&totalReg, &overlap);
125035c4bbdfSmrg            SendGraphicsExpose(client, &totalReg, stuff->dstDrawable,
125135c4bbdfSmrg                               X_CopyArea, 0);
125235c4bbdfSmrg            RegionUninit(&totalReg);
125335c4bbdfSmrg        }
125405b261ecSmrg    }
125505b261ecSmrg
12566747b715Smrg    return Success;
125705b261ecSmrg}
125805b261ecSmrg
125935c4bbdfSmrgint
126035c4bbdfSmrgPanoramiXCopyPlane(ClientPtr client)
126105b261ecSmrg{
126235c4bbdfSmrg    int j, srcx, srcy, dstx, dsty, rc;
126335c4bbdfSmrg    PanoramiXRes *gc, *src, *dst;
126435c4bbdfSmrg    Bool srcIsRoot = FALSE;
126535c4bbdfSmrg    Bool dstIsRoot = FALSE;
126635c4bbdfSmrg    Bool srcShared, dstShared;
126735c4bbdfSmrg    DrawablePtr psrcDraw, pdstDraw = NULL;
126835c4bbdfSmrg    GCPtr pGC = NULL;
126935c4bbdfSmrg    RegionRec totalReg;
127035c4bbdfSmrg
127105b261ecSmrg    REQUEST(xCopyPlaneReq);
127205b261ecSmrg
127305b261ecSmrg    REQUEST_SIZE_MATCH(xCopyPlaneReq);
127405b261ecSmrg
127535c4bbdfSmrg    rc = dixLookupResourceByClass((void **) &src, stuff->srcDrawable,
127635c4bbdfSmrg                                  XRC_DRAWABLE, client, DixReadAccess);
12776747b715Smrg    if (rc != Success)
127835c4bbdfSmrg        return (rc == BadValue) ? BadDrawable : rc;
127905b261ecSmrg
128005b261ecSmrg    srcShared = IS_SHARED_PIXMAP(src);
128105b261ecSmrg
128235c4bbdfSmrg    rc = dixLookupResourceByClass((void **) &dst, stuff->dstDrawable,
128335c4bbdfSmrg                                  XRC_DRAWABLE, client, DixWriteAccess);
12846747b715Smrg    if (rc != Success)
128535c4bbdfSmrg        return (rc == BadValue) ? BadDrawable : rc;
128605b261ecSmrg
128705b261ecSmrg    dstShared = IS_SHARED_PIXMAP(dst);
128805b261ecSmrg
128935c4bbdfSmrg    if (dstShared && srcShared)
129035c4bbdfSmrg        return (*SavedProcVector[X_CopyPlane]) (client);
129105b261ecSmrg
129235c4bbdfSmrg    rc = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
129335c4bbdfSmrg                                 client, DixReadAccess);
12946747b715Smrg    if (rc != Success)
129535c4bbdfSmrg        return rc;
129635c4bbdfSmrg
129735c4bbdfSmrg    if ((dst->type == XRT_WINDOW) && dst->u.win.root)
129835c4bbdfSmrg        dstIsRoot = TRUE;
129935c4bbdfSmrg    if ((src->type == XRT_WINDOW) && src->u.win.root)
130035c4bbdfSmrg        srcIsRoot = TRUE;
130105b261ecSmrg
130235c4bbdfSmrg    srcx = stuff->srcX;
130335c4bbdfSmrg    srcy = stuff->srcY;
130435c4bbdfSmrg    dstx = stuff->dstX;
130535c4bbdfSmrg    dsty = stuff->dstY;
130605b261ecSmrg
13076747b715Smrg    RegionNull(&totalReg);
130805b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
130935c4bbdfSmrg        RegionPtr pRgn;
131035c4bbdfSmrg
131135c4bbdfSmrg        stuff->dstDrawable = dst->info[j].id;
131235c4bbdfSmrg        stuff->srcDrawable = src->info[j].id;
131335c4bbdfSmrg        stuff->gc = gc->info[j].id;
131435c4bbdfSmrg        if (srcIsRoot) {
131535c4bbdfSmrg            stuff->srcX = srcx - screenInfo.screens[j]->x;
131635c4bbdfSmrg            stuff->srcY = srcy - screenInfo.screens[j]->y;
131735c4bbdfSmrg        }
131835c4bbdfSmrg        if (dstIsRoot) {
131935c4bbdfSmrg            stuff->dstX = dstx - screenInfo.screens[j]->x;
132035c4bbdfSmrg            stuff->dstY = dsty - screenInfo.screens[j]->y;
132135c4bbdfSmrg        }
132235c4bbdfSmrg
132335c4bbdfSmrg        VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, DixWriteAccess);
132435c4bbdfSmrg        if (stuff->dstDrawable != stuff->srcDrawable) {
132535c4bbdfSmrg            rc = dixLookupDrawable(&psrcDraw, stuff->srcDrawable, client, 0,
132635c4bbdfSmrg                                   DixReadAccess);
132735c4bbdfSmrg            if (rc != Success)
132835c4bbdfSmrg                return rc;
132905b261ecSmrg
133005b261ecSmrg            if (pdstDraw->pScreen != psrcDraw->pScreen) {
133135c4bbdfSmrg                client->errorValue = stuff->dstDrawable;
133235c4bbdfSmrg                return BadMatch;
133335c4bbdfSmrg            }
133435c4bbdfSmrg        }
133535c4bbdfSmrg        else
133635c4bbdfSmrg            psrcDraw = pdstDraw;
133735c4bbdfSmrg
133835c4bbdfSmrg        if (stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) ||
133935c4bbdfSmrg            (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) {
134035c4bbdfSmrg            client->errorValue = stuff->bitPlane;
134135c4bbdfSmrg            return BadValue;
134235c4bbdfSmrg        }
134335c4bbdfSmrg
134435c4bbdfSmrg        pRgn = (*pGC->ops->CopyPlane) (psrcDraw, pdstDraw, pGC,
134535c4bbdfSmrg                                       stuff->srcX, stuff->srcY,
134635c4bbdfSmrg                                       stuff->width, stuff->height,
134735c4bbdfSmrg                                       stuff->dstX, stuff->dstY,
134835c4bbdfSmrg                                       stuff->bitPlane);
134935c4bbdfSmrg        if (pGC->graphicsExposures && pRgn) {
135035c4bbdfSmrg            RegionAppend(&totalReg, pRgn);
135135c4bbdfSmrg            RegionDestroy(pRgn);
135235c4bbdfSmrg        }
135335c4bbdfSmrg
135435c4bbdfSmrg        if (dstShared)
135535c4bbdfSmrg            break;
135635c4bbdfSmrg    }
135735c4bbdfSmrg
135835c4bbdfSmrg    if (pGC->graphicsExposures) {
135935c4bbdfSmrg        Bool overlap;
136035c4bbdfSmrg
136135c4bbdfSmrg        RegionValidate(&totalReg, &overlap);
136235c4bbdfSmrg        SendGraphicsExpose(client, &totalReg, stuff->dstDrawable,
136335c4bbdfSmrg                           X_CopyPlane, 0);
136435c4bbdfSmrg        RegionUninit(&totalReg);
136505b261ecSmrg    }
136605b261ecSmrg
13676747b715Smrg    return Success;
136805b261ecSmrg}
136905b261ecSmrg
137035c4bbdfSmrgint
137135c4bbdfSmrgPanoramiXPolyPoint(ClientPtr client)
137205b261ecSmrg{
137305b261ecSmrg    PanoramiXRes *gc, *draw;
137435c4bbdfSmrg    int result, npoint, j;
137535c4bbdfSmrg    xPoint *origPts;
137635c4bbdfSmrg    Bool isRoot;
137735c4bbdfSmrg
137805b261ecSmrg    REQUEST(xPolyPointReq);
137905b261ecSmrg
138005b261ecSmrg    REQUEST_AT_LEAST_SIZE(xPolyPointReq);
138105b261ecSmrg
138235c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
138335c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
13846747b715Smrg    if (result != Success)
138535c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
138605b261ecSmrg
138735c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
138835c4bbdfSmrg        return (*SavedProcVector[X_PolyPoint]) (client);
138905b261ecSmrg
139035c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
139135c4bbdfSmrg                                     client, DixReadAccess);
13926747b715Smrg    if (result != Success)
139335c4bbdfSmrg        return result;
139405b261ecSmrg
139505b261ecSmrg    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
13966747b715Smrg    npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq));
139705b261ecSmrg    if (npoint > 0) {
139835c4bbdfSmrg        origPts = xallocarray(npoint, sizeof(xPoint));
139905b261ecSmrg        memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
140035c4bbdfSmrg        FOR_NSCREENS_FORWARD(j) {
140105b261ecSmrg
140235c4bbdfSmrg            if (j)
140335c4bbdfSmrg                memcpy(&stuff[1], origPts, npoint * sizeof(xPoint));
140405b261ecSmrg
140505b261ecSmrg            if (isRoot) {
14066747b715Smrg                int x_off = screenInfo.screens[j]->x;
14076747b715Smrg                int y_off = screenInfo.screens[j]->y;
140805b261ecSmrg
140935c4bbdfSmrg                if (x_off || y_off) {
141035c4bbdfSmrg                    xPoint *pnts = (xPoint *) &stuff[1];
141135c4bbdfSmrg                    int i =
141235c4bbdfSmrg                        (stuff->coordMode == CoordModePrevious) ? 1 : npoint;
141305b261ecSmrg
141435c4bbdfSmrg                    while (i--) {
141535c4bbdfSmrg                        pnts->x -= x_off;
141635c4bbdfSmrg                        pnts->y -= y_off;
141735c4bbdfSmrg                        pnts++;
141805b261ecSmrg                    }
141935c4bbdfSmrg                }
142005b261ecSmrg            }
142105b261ecSmrg
142235c4bbdfSmrg            stuff->drawable = draw->info[j].id;
142335c4bbdfSmrg            stuff->gc = gc->info[j].id;
142435c4bbdfSmrg            result = (*SavedProcVector[X_PolyPoint]) (client);
142535c4bbdfSmrg            if (result != Success)
142635c4bbdfSmrg                break;
142705b261ecSmrg        }
14286747b715Smrg        free(origPts);
14296747b715Smrg        return result;
143035c4bbdfSmrg    }
143135c4bbdfSmrg    else
143235c4bbdfSmrg        return Success;
143305b261ecSmrg}
143405b261ecSmrg
143535c4bbdfSmrgint
143635c4bbdfSmrgPanoramiXPolyLine(ClientPtr client)
143705b261ecSmrg{
143805b261ecSmrg    PanoramiXRes *gc, *draw;
143935c4bbdfSmrg    int result, npoint, j;
144035c4bbdfSmrg    xPoint *origPts;
144135c4bbdfSmrg    Bool isRoot;
144235c4bbdfSmrg
144305b261ecSmrg    REQUEST(xPolyLineReq);
144405b261ecSmrg
144505b261ecSmrg    REQUEST_AT_LEAST_SIZE(xPolyLineReq);
144605b261ecSmrg
144735c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
144835c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
14496747b715Smrg    if (result != Success)
145035c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
145105b261ecSmrg
145235c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
145335c4bbdfSmrg        return (*SavedProcVector[X_PolyLine]) (client);
145405b261ecSmrg
145535c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
145635c4bbdfSmrg                                     client, DixReadAccess);
14576747b715Smrg    if (result != Success)
145835c4bbdfSmrg        return result;
145905b261ecSmrg
146035c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
14616747b715Smrg    npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq));
146235c4bbdfSmrg    if (npoint > 0) {
146335c4bbdfSmrg        origPts = xallocarray(npoint, sizeof(xPoint));
146405b261ecSmrg        memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
146535c4bbdfSmrg        FOR_NSCREENS_FORWARD(j) {
146605b261ecSmrg
146735c4bbdfSmrg            if (j)
146835c4bbdfSmrg                memcpy(&stuff[1], origPts, npoint * sizeof(xPoint));
146905b261ecSmrg
147005b261ecSmrg            if (isRoot) {
14716747b715Smrg                int x_off = screenInfo.screens[j]->x;
14726747b715Smrg                int y_off = screenInfo.screens[j]->y;
147305b261ecSmrg
147435c4bbdfSmrg                if (x_off || y_off) {
147535c4bbdfSmrg                    xPoint *pnts = (xPoint *) &stuff[1];
147635c4bbdfSmrg                    int i =
147735c4bbdfSmrg                        (stuff->coordMode == CoordModePrevious) ? 1 : npoint;
147805b261ecSmrg
147935c4bbdfSmrg                    while (i--) {
148035c4bbdfSmrg                        pnts->x -= x_off;
148135c4bbdfSmrg                        pnts->y -= y_off;
148235c4bbdfSmrg                        pnts++;
148335c4bbdfSmrg                    }
148435c4bbdfSmrg                }
148505b261ecSmrg            }
148605b261ecSmrg
148735c4bbdfSmrg            stuff->drawable = draw->info[j].id;
148835c4bbdfSmrg            stuff->gc = gc->info[j].id;
148935c4bbdfSmrg            result = (*SavedProcVector[X_PolyLine]) (client);
149035c4bbdfSmrg            if (result != Success)
149135c4bbdfSmrg                break;
149205b261ecSmrg        }
14936747b715Smrg        free(origPts);
14946747b715Smrg        return result;
149535c4bbdfSmrg    }
149635c4bbdfSmrg    else
149735c4bbdfSmrg        return Success;
149805b261ecSmrg}
149905b261ecSmrg
150035c4bbdfSmrgint
150135c4bbdfSmrgPanoramiXPolySegment(ClientPtr client)
150205b261ecSmrg{
150335c4bbdfSmrg    int result, nsegs, i, j;
150405b261ecSmrg    PanoramiXRes *gc, *draw;
150535c4bbdfSmrg    xSegment *origSegs;
150635c4bbdfSmrg    Bool isRoot;
150735c4bbdfSmrg
150805b261ecSmrg    REQUEST(xPolySegmentReq);
150905b261ecSmrg
151005b261ecSmrg    REQUEST_AT_LEAST_SIZE(xPolySegmentReq);
151105b261ecSmrg
151235c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
151335c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
15146747b715Smrg    if (result != Success)
151535c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
151605b261ecSmrg
151735c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
151835c4bbdfSmrg        return (*SavedProcVector[X_PolySegment]) (client);
151905b261ecSmrg
152035c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
152135c4bbdfSmrg                                     client, DixReadAccess);
15226747b715Smrg    if (result != Success)
152335c4bbdfSmrg        return result;
152405b261ecSmrg
152535c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
152605b261ecSmrg
152705b261ecSmrg    nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq);
152835c4bbdfSmrg    if (nsegs & 4)
152935c4bbdfSmrg        return BadLength;
153005b261ecSmrg    nsegs >>= 3;
153105b261ecSmrg    if (nsegs > 0) {
153235c4bbdfSmrg        origSegs = xallocarray(nsegs, sizeof(xSegment));
153305b261ecSmrg        memcpy((char *) origSegs, (char *) &stuff[1], nsegs * sizeof(xSegment));
153435c4bbdfSmrg        FOR_NSCREENS_FORWARD(j) {
153505b261ecSmrg
153635c4bbdfSmrg            if (j)
153735c4bbdfSmrg                memcpy(&stuff[1], origSegs, nsegs * sizeof(xSegment));
153805b261ecSmrg
153905b261ecSmrg            if (isRoot) {
15406747b715Smrg                int x_off = screenInfo.screens[j]->x;
15416747b715Smrg                int y_off = screenInfo.screens[j]->y;
154205b261ecSmrg
154335c4bbdfSmrg                if (x_off || y_off) {
154435c4bbdfSmrg                    xSegment *segs = (xSegment *) &stuff[1];
154505b261ecSmrg
154635c4bbdfSmrg                    for (i = nsegs; i--; segs++) {
154735c4bbdfSmrg                        segs->x1 -= x_off;
154835c4bbdfSmrg                        segs->x2 -= x_off;
154935c4bbdfSmrg                        segs->y1 -= y_off;
155035c4bbdfSmrg                        segs->y2 -= y_off;
155135c4bbdfSmrg                    }
155235c4bbdfSmrg                }
155305b261ecSmrg            }
155405b261ecSmrg
155535c4bbdfSmrg            stuff->drawable = draw->info[j].id;
155635c4bbdfSmrg            stuff->gc = gc->info[j].id;
155735c4bbdfSmrg            result = (*SavedProcVector[X_PolySegment]) (client);
155835c4bbdfSmrg            if (result != Success)
155935c4bbdfSmrg                break;
156035c4bbdfSmrg        }
156135c4bbdfSmrg        free(origSegs);
156235c4bbdfSmrg        return result;
156335c4bbdfSmrg    }
156435c4bbdfSmrg    else
156535c4bbdfSmrg        return Success;
156605b261ecSmrg}
156705b261ecSmrg
156835c4bbdfSmrgint
156935c4bbdfSmrgPanoramiXPolyRectangle(ClientPtr client)
157005b261ecSmrg{
157135c4bbdfSmrg    int result, nrects, i, j;
157205b261ecSmrg    PanoramiXRes *gc, *draw;
157335c4bbdfSmrg    Bool isRoot;
157435c4bbdfSmrg    xRectangle *origRecs;
157535c4bbdfSmrg
157605b261ecSmrg    REQUEST(xPolyRectangleReq);
157705b261ecSmrg
157805b261ecSmrg    REQUEST_AT_LEAST_SIZE(xPolyRectangleReq);
157905b261ecSmrg
158035c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
158135c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
15826747b715Smrg    if (result != Success)
158335c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
158405b261ecSmrg
158535c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
158635c4bbdfSmrg        return (*SavedProcVector[X_PolyRectangle]) (client);
158705b261ecSmrg
158835c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
158935c4bbdfSmrg                                     client, DixReadAccess);
15906747b715Smrg    if (result != Success)
159135c4bbdfSmrg        return result;
159205b261ecSmrg
159335c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
159405b261ecSmrg
159505b261ecSmrg    nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq);
159635c4bbdfSmrg    if (nrects & 4)
159735c4bbdfSmrg        return BadLength;
159805b261ecSmrg    nrects >>= 3;
159935c4bbdfSmrg    if (nrects > 0) {
160035c4bbdfSmrg        origRecs = xallocarray(nrects, sizeof(xRectangle));
160135c4bbdfSmrg        memcpy((char *) origRecs, (char *) &stuff[1],
160235c4bbdfSmrg               nrects * sizeof(xRectangle));
160335c4bbdfSmrg        FOR_NSCREENS_FORWARD(j) {
160435c4bbdfSmrg
160535c4bbdfSmrg            if (j)
160635c4bbdfSmrg                memcpy(&stuff[1], origRecs, nrects * sizeof(xRectangle));
160705b261ecSmrg
160835c4bbdfSmrg            if (isRoot) {
160935c4bbdfSmrg                int x_off = screenInfo.screens[j]->x;
161035c4bbdfSmrg                int y_off = screenInfo.screens[j]->y;
161105b261ecSmrg
161235c4bbdfSmrg                if (x_off || y_off) {
161335c4bbdfSmrg                    xRectangle *rects = (xRectangle *) &stuff[1];
161435c4bbdfSmrg
161535c4bbdfSmrg                    for (i = nrects; i--; rects++) {
161635c4bbdfSmrg                        rects->x -= x_off;
161735c4bbdfSmrg                        rects->y -= y_off;
161835c4bbdfSmrg                    }
161935c4bbdfSmrg                }
162035c4bbdfSmrg            }
162135c4bbdfSmrg
162235c4bbdfSmrg            stuff->drawable = draw->info[j].id;
162335c4bbdfSmrg            stuff->gc = gc->info[j].id;
162435c4bbdfSmrg            result = (*SavedProcVector[X_PolyRectangle]) (client);
162535c4bbdfSmrg            if (result != Success)
162635c4bbdfSmrg                break;
162735c4bbdfSmrg        }
162835c4bbdfSmrg        free(origRecs);
162935c4bbdfSmrg        return result;
163035c4bbdfSmrg    }
163135c4bbdfSmrg    else
163235c4bbdfSmrg        return Success;
163335c4bbdfSmrg}
163435c4bbdfSmrg
163535c4bbdfSmrgint
163635c4bbdfSmrgPanoramiXPolyArc(ClientPtr client)
163705b261ecSmrg{
163835c4bbdfSmrg    int result, narcs, i, j;
163905b261ecSmrg    PanoramiXRes *gc, *draw;
164035c4bbdfSmrg    Bool isRoot;
164135c4bbdfSmrg    xArc *origArcs;
164235c4bbdfSmrg
164305b261ecSmrg    REQUEST(xPolyArcReq);
164405b261ecSmrg
164505b261ecSmrg    REQUEST_AT_LEAST_SIZE(xPolyArcReq);
164605b261ecSmrg
164735c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
164835c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
16496747b715Smrg    if (result != Success)
165035c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
165105b261ecSmrg
165235c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
165335c4bbdfSmrg        return (*SavedProcVector[X_PolyArc]) (client);
165405b261ecSmrg
165535c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
165635c4bbdfSmrg                                     client, DixReadAccess);
16576747b715Smrg    if (result != Success)
165835c4bbdfSmrg        return result;
165905b261ecSmrg
166035c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
166105b261ecSmrg
166205b261ecSmrg    narcs = (client->req_len << 2) - sizeof(xPolyArcReq);
166335c4bbdfSmrg    if (narcs % sizeof(xArc))
166435c4bbdfSmrg        return BadLength;
166505b261ecSmrg    narcs /= sizeof(xArc);
166635c4bbdfSmrg    if (narcs > 0) {
166735c4bbdfSmrg        origArcs = xallocarray(narcs, sizeof(xArc));
166835c4bbdfSmrg        memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc));
166935c4bbdfSmrg        FOR_NSCREENS_FORWARD(j) {
167035c4bbdfSmrg
167135c4bbdfSmrg            if (j)
167235c4bbdfSmrg                memcpy(&stuff[1], origArcs, narcs * sizeof(xArc));
167335c4bbdfSmrg
167435c4bbdfSmrg            if (isRoot) {
167535c4bbdfSmrg                int x_off = screenInfo.screens[j]->x;
167635c4bbdfSmrg                int y_off = screenInfo.screens[j]->y;
167735c4bbdfSmrg
167835c4bbdfSmrg                if (x_off || y_off) {
167935c4bbdfSmrg                    xArc *arcs = (xArc *) &stuff[1];
168035c4bbdfSmrg
168135c4bbdfSmrg                    for (i = narcs; i--; arcs++) {
168235c4bbdfSmrg                        arcs->x -= x_off;
168335c4bbdfSmrg                        arcs->y -= y_off;
168435c4bbdfSmrg                    }
168535c4bbdfSmrg                }
168605b261ecSmrg            }
168735c4bbdfSmrg            stuff->drawable = draw->info[j].id;
168835c4bbdfSmrg            stuff->gc = gc->info[j].id;
168935c4bbdfSmrg            result = (*SavedProcVector[X_PolyArc]) (client);
169035c4bbdfSmrg            if (result != Success)
169135c4bbdfSmrg                break;
169205b261ecSmrg        }
169335c4bbdfSmrg        free(origArcs);
169435c4bbdfSmrg        return result;
169535c4bbdfSmrg    }
169635c4bbdfSmrg    else
169735c4bbdfSmrg        return Success;
169805b261ecSmrg}
169905b261ecSmrg
170035c4bbdfSmrgint
170135c4bbdfSmrgPanoramiXFillPoly(ClientPtr client)
170205b261ecSmrg{
170335c4bbdfSmrg    int result, count, j;
170405b261ecSmrg    PanoramiXRes *gc, *draw;
170535c4bbdfSmrg    Bool isRoot;
170635c4bbdfSmrg    DDXPointPtr locPts;
170735c4bbdfSmrg
170805b261ecSmrg    REQUEST(xFillPolyReq);
170905b261ecSmrg
171005b261ecSmrg    REQUEST_AT_LEAST_SIZE(xFillPolyReq);
171105b261ecSmrg
171235c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
171335c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
17146747b715Smrg    if (result != Success)
171535c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
171605b261ecSmrg
171735c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
171835c4bbdfSmrg        return (*SavedProcVector[X_FillPoly]) (client);
171905b261ecSmrg
172035c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
172135c4bbdfSmrg                                     client, DixReadAccess);
17226747b715Smrg    if (result != Success)
172335c4bbdfSmrg        return result;
172405b261ecSmrg
172535c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
172605b261ecSmrg
17276747b715Smrg    count = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq));
172835c4bbdfSmrg    if (count > 0) {
172935c4bbdfSmrg        locPts = xallocarray(count, sizeof(DDXPointRec));
173035c4bbdfSmrg        memcpy((char *) locPts, (char *) &stuff[1],
173135c4bbdfSmrg               count * sizeof(DDXPointRec));
173235c4bbdfSmrg        FOR_NSCREENS_FORWARD(j) {
173335c4bbdfSmrg
173435c4bbdfSmrg            if (j)
173535c4bbdfSmrg                memcpy(&stuff[1], locPts, count * sizeof(DDXPointRec));
173635c4bbdfSmrg
173735c4bbdfSmrg            if (isRoot) {
173835c4bbdfSmrg                int x_off = screenInfo.screens[j]->x;
173935c4bbdfSmrg                int y_off = screenInfo.screens[j]->y;
174005b261ecSmrg
174135c4bbdfSmrg                if (x_off || y_off) {
174235c4bbdfSmrg                    DDXPointPtr pnts = (DDXPointPtr) &stuff[1];
174335c4bbdfSmrg                    int i = (stuff->coordMode == CoordModePrevious) ? 1 : count;
174435c4bbdfSmrg
174535c4bbdfSmrg                    while (i--) {
174635c4bbdfSmrg                        pnts->x -= x_off;
174735c4bbdfSmrg                        pnts->y -= y_off;
174835c4bbdfSmrg                        pnts++;
174935c4bbdfSmrg                    }
175035c4bbdfSmrg                }
175135c4bbdfSmrg            }
175235c4bbdfSmrg
175335c4bbdfSmrg            stuff->drawable = draw->info[j].id;
175435c4bbdfSmrg            stuff->gc = gc->info[j].id;
175535c4bbdfSmrg            result = (*SavedProcVector[X_FillPoly]) (client);
175635c4bbdfSmrg            if (result != Success)
175735c4bbdfSmrg                break;
175835c4bbdfSmrg        }
175935c4bbdfSmrg        free(locPts);
176035c4bbdfSmrg        return result;
176135c4bbdfSmrg    }
176235c4bbdfSmrg    else
176335c4bbdfSmrg        return Success;
176435c4bbdfSmrg}
176505b261ecSmrg
176635c4bbdfSmrgint
176735c4bbdfSmrgPanoramiXPolyFillRectangle(ClientPtr client)
176805b261ecSmrg{
176935c4bbdfSmrg    int result, things, i, j;
177005b261ecSmrg    PanoramiXRes *gc, *draw;
177135c4bbdfSmrg    Bool isRoot;
177235c4bbdfSmrg    xRectangle *origRects;
177335c4bbdfSmrg
177405b261ecSmrg    REQUEST(xPolyFillRectangleReq);
177505b261ecSmrg
177605b261ecSmrg    REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq);
177705b261ecSmrg
177835c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
177935c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
17806747b715Smrg    if (result != Success)
178135c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
178205b261ecSmrg
178335c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
178435c4bbdfSmrg        return (*SavedProcVector[X_PolyFillRectangle]) (client);
178505b261ecSmrg
178635c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
178735c4bbdfSmrg                                     client, DixReadAccess);
17886747b715Smrg    if (result != Success)
178935c4bbdfSmrg        return result;
179005b261ecSmrg
179135c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
179205b261ecSmrg
179305b261ecSmrg    things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq);
179435c4bbdfSmrg    if (things & 4)
179535c4bbdfSmrg        return BadLength;
179605b261ecSmrg    things >>= 3;
179735c4bbdfSmrg    if (things > 0) {
179835c4bbdfSmrg        origRects = xallocarray(things, sizeof(xRectangle));
179935c4bbdfSmrg        memcpy((char *) origRects, (char *) &stuff[1],
180035c4bbdfSmrg               things * sizeof(xRectangle));
180135c4bbdfSmrg        FOR_NSCREENS_FORWARD(j) {
180235c4bbdfSmrg
180335c4bbdfSmrg            if (j)
180435c4bbdfSmrg                memcpy(&stuff[1], origRects, things * sizeof(xRectangle));
180505b261ecSmrg
180635c4bbdfSmrg            if (isRoot) {
180735c4bbdfSmrg                int x_off = screenInfo.screens[j]->x;
180835c4bbdfSmrg                int y_off = screenInfo.screens[j]->y;
180935c4bbdfSmrg
181035c4bbdfSmrg                if (x_off || y_off) {
181135c4bbdfSmrg                    xRectangle *rects = (xRectangle *) &stuff[1];
181235c4bbdfSmrg
181335c4bbdfSmrg                    for (i = things; i--; rects++) {
181435c4bbdfSmrg                        rects->x -= x_off;
181535c4bbdfSmrg                        rects->y -= y_off;
181635c4bbdfSmrg                    }
181735c4bbdfSmrg                }
181835c4bbdfSmrg            }
181905b261ecSmrg
182035c4bbdfSmrg            stuff->drawable = draw->info[j].id;
182135c4bbdfSmrg            stuff->gc = gc->info[j].id;
182235c4bbdfSmrg            result = (*SavedProcVector[X_PolyFillRectangle]) (client);
182335c4bbdfSmrg            if (result != Success)
182435c4bbdfSmrg                break;
182535c4bbdfSmrg        }
182635c4bbdfSmrg        free(origRects);
182735c4bbdfSmrg        return result;
182835c4bbdfSmrg    }
182935c4bbdfSmrg    else
183035c4bbdfSmrg        return Success;
183135c4bbdfSmrg}
183235c4bbdfSmrg
183335c4bbdfSmrgint
183435c4bbdfSmrgPanoramiXPolyFillArc(ClientPtr client)
183505b261ecSmrg{
183605b261ecSmrg    PanoramiXRes *gc, *draw;
183735c4bbdfSmrg    Bool isRoot;
183835c4bbdfSmrg    int result, narcs, i, j;
183935c4bbdfSmrg    xArc *origArcs;
184035c4bbdfSmrg
184105b261ecSmrg    REQUEST(xPolyFillArcReq);
184205b261ecSmrg
184305b261ecSmrg    REQUEST_AT_LEAST_SIZE(xPolyFillArcReq);
184405b261ecSmrg
184535c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
184635c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
18476747b715Smrg    if (result != Success)
184835c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
184905b261ecSmrg
185035c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
185135c4bbdfSmrg        return (*SavedProcVector[X_PolyFillArc]) (client);
185205b261ecSmrg
185335c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
185435c4bbdfSmrg                                     client, DixReadAccess);
18556747b715Smrg    if (result != Success)
185635c4bbdfSmrg        return result;
185705b261ecSmrg
185835c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
185905b261ecSmrg
186005b261ecSmrg    narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq);
186135c4bbdfSmrg    if (narcs % sizeof(xArc))
186235c4bbdfSmrg        return BadLength;
186305b261ecSmrg    narcs /= sizeof(xArc);
186405b261ecSmrg    if (narcs > 0) {
186535c4bbdfSmrg        origArcs = xallocarray(narcs, sizeof(xArc));
186635c4bbdfSmrg        memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc));
186735c4bbdfSmrg        FOR_NSCREENS_FORWARD(j) {
186835c4bbdfSmrg
186935c4bbdfSmrg            if (j)
187035c4bbdfSmrg                memcpy(&stuff[1], origArcs, narcs * sizeof(xArc));
187135c4bbdfSmrg
187235c4bbdfSmrg            if (isRoot) {
187335c4bbdfSmrg                int x_off = screenInfo.screens[j]->x;
187435c4bbdfSmrg                int y_off = screenInfo.screens[j]->y;
187505b261ecSmrg
187635c4bbdfSmrg                if (x_off || y_off) {
187735c4bbdfSmrg                    xArc *arcs = (xArc *) &stuff[1];
187835c4bbdfSmrg
187935c4bbdfSmrg                    for (i = narcs; i--; arcs++) {
188035c4bbdfSmrg                        arcs->x -= x_off;
188135c4bbdfSmrg                        arcs->y -= y_off;
188235c4bbdfSmrg                    }
188335c4bbdfSmrg                }
188435c4bbdfSmrg            }
188505b261ecSmrg
188635c4bbdfSmrg            stuff->drawable = draw->info[j].id;
188735c4bbdfSmrg            stuff->gc = gc->info[j].id;
188835c4bbdfSmrg            result = (*SavedProcVector[X_PolyFillArc]) (client);
188935c4bbdfSmrg            if (result != Success)
189035c4bbdfSmrg                break;
189135c4bbdfSmrg        }
189235c4bbdfSmrg        free(origArcs);
189335c4bbdfSmrg        return result;
189435c4bbdfSmrg    }
189535c4bbdfSmrg    else
189635c4bbdfSmrg        return Success;
189735c4bbdfSmrg}
189835c4bbdfSmrg
189935c4bbdfSmrgint
190035c4bbdfSmrgPanoramiXPutImage(ClientPtr client)
190105b261ecSmrg{
190205b261ecSmrg    PanoramiXRes *gc, *draw;
190335c4bbdfSmrg    Bool isRoot;
190435c4bbdfSmrg    int j, result, orig_x, orig_y;
190535c4bbdfSmrg
190605b261ecSmrg    REQUEST(xPutImageReq);
190705b261ecSmrg
190805b261ecSmrg    REQUEST_AT_LEAST_SIZE(xPutImageReq);
190905b261ecSmrg
191035c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
191135c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
19126747b715Smrg    if (result != Success)
191335c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
191405b261ecSmrg
191535c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
191635c4bbdfSmrg        return (*SavedProcVector[X_PutImage]) (client);
191705b261ecSmrg
191835c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
191935c4bbdfSmrg                                     client, DixReadAccess);
19206747b715Smrg    if (result != Success)
192135c4bbdfSmrg        return result;
192205b261ecSmrg
192335c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
192405b261ecSmrg
192505b261ecSmrg    orig_x = stuff->dstX;
192605b261ecSmrg    orig_y = stuff->dstY;
192735c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
192835c4bbdfSmrg        if (isRoot) {
192935c4bbdfSmrg            stuff->dstX = orig_x - screenInfo.screens[j]->x;
193035c4bbdfSmrg            stuff->dstY = orig_y - screenInfo.screens[j]->y;
193135c4bbdfSmrg        }
193235c4bbdfSmrg        stuff->drawable = draw->info[j].id;
193335c4bbdfSmrg        stuff->gc = gc->info[j].id;
193435c4bbdfSmrg        result = (*SavedProcVector[X_PutImage]) (client);
193535c4bbdfSmrg        if (result != Success)
193635c4bbdfSmrg            break;
193705b261ecSmrg    }
19386747b715Smrg    return result;
193905b261ecSmrg}
194005b261ecSmrg
194135c4bbdfSmrgint
194235c4bbdfSmrgPanoramiXGetImage(ClientPtr client)
194305b261ecSmrg{
194435c4bbdfSmrg    DrawablePtr drawables[MAXSCREENS];
194535c4bbdfSmrg    DrawablePtr pDraw;
194635c4bbdfSmrg    PanoramiXRes *draw;
194735c4bbdfSmrg    xGetImageReply xgi;
194835c4bbdfSmrg    Bool isRoot;
194935c4bbdfSmrg    char *pBuf;
195035c4bbdfSmrg    int i, x, y, w, h, format, rc;
195135c4bbdfSmrg    Mask plane = 0, planemask;
195235c4bbdfSmrg    int linesDone, nlines, linesPerBuf;
195335c4bbdfSmrg    long widthBytesLine, length;
195405b261ecSmrg
195505b261ecSmrg    REQUEST(xGetImageReq);
195605b261ecSmrg
195705b261ecSmrg    REQUEST_SIZE_MATCH(xGetImageReq);
195805b261ecSmrg
195905b261ecSmrg    if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) {
196035c4bbdfSmrg        client->errorValue = stuff->format;
19616747b715Smrg        return BadValue;
196205b261ecSmrg    }
196305b261ecSmrg
196435c4bbdfSmrg    rc = dixLookupResourceByClass((void **) &draw, stuff->drawable,
196535c4bbdfSmrg                                  XRC_DRAWABLE, client, DixReadAccess);
19666747b715Smrg    if (rc != Success)
196735c4bbdfSmrg        return (rc == BadValue) ? BadDrawable : rc;
196805b261ecSmrg
196935c4bbdfSmrg    if (draw->type == XRT_PIXMAP)
197035c4bbdfSmrg        return (*SavedProcVector[X_GetImage]) (client);
197105b261ecSmrg
197235c4bbdfSmrg    rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixReadAccess);
197305b261ecSmrg    if (rc != Success)
197435c4bbdfSmrg        return rc;
197505b261ecSmrg
197635c4bbdfSmrg    if (!((WindowPtr) pDraw)->realized)
197735c4bbdfSmrg        return BadMatch;
197805b261ecSmrg
197905b261ecSmrg    x = stuff->x;
198005b261ecSmrg    y = stuff->y;
198105b261ecSmrg    w = stuff->width;
198205b261ecSmrg    h = stuff->height;
198305b261ecSmrg    format = stuff->format;
198405b261ecSmrg    planemask = stuff->planeMask;
198505b261ecSmrg
198635c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
198705b261ecSmrg
198835c4bbdfSmrg    if (isRoot) {
198935c4bbdfSmrg        /* check for being onscreen */
199035c4bbdfSmrg        if (x < 0 || x + w > PanoramiXPixWidth ||
199135c4bbdfSmrg            y < 0 || y + h > PanoramiXPixHeight)
199235c4bbdfSmrg            return BadMatch;
199335c4bbdfSmrg    }
199435c4bbdfSmrg    else {
199535c4bbdfSmrg        /* check for being onscreen and inside of border */
199635c4bbdfSmrg        if (screenInfo.screens[0]->x + pDraw->x + x < 0 ||
199735c4bbdfSmrg            screenInfo.screens[0]->x + pDraw->x + x + w > PanoramiXPixWidth ||
199835c4bbdfSmrg            screenInfo.screens[0]->y + pDraw->y + y < 0 ||
199935c4bbdfSmrg            screenInfo.screens[0]->y + pDraw->y + y + h > PanoramiXPixHeight ||
200035c4bbdfSmrg            x < -wBorderWidth((WindowPtr) pDraw) ||
200135c4bbdfSmrg            x + w > wBorderWidth((WindowPtr) pDraw) + (int) pDraw->width ||
200235c4bbdfSmrg            y < -wBorderWidth((WindowPtr) pDraw) ||
200335c4bbdfSmrg            y + h > wBorderWidth((WindowPtr) pDraw) + (int) pDraw->height)
200435c4bbdfSmrg            return BadMatch;
200505b261ecSmrg    }
200605b261ecSmrg
200705b261ecSmrg    drawables[0] = pDraw;
200835c4bbdfSmrg    FOR_NSCREENS_FORWARD_SKIP(i) {
200935c4bbdfSmrg        rc = dixLookupDrawable(drawables + i, draw->info[i].id, client, 0,
201035c4bbdfSmrg                               DixGetAttrAccess);
201135c4bbdfSmrg        if (rc != Success)
201235c4bbdfSmrg            return rc;
201305b261ecSmrg    }
201425da500fSmrg    FOR_NSCREENS_FORWARD(i) {
201525da500fSmrg        drawables[i]->pScreen->SourceValidate(drawables[i], 0, 0,
201625da500fSmrg                                              drawables[i]->width,
201725da500fSmrg                                              drawables[i]->height,
201825da500fSmrg                                              IncludeInferiors);
201925da500fSmrg    }
202005b261ecSmrg
202135c4bbdfSmrg    xgi = (xGetImageReply) {
202235c4bbdfSmrg        .type = X_Reply,
202335c4bbdfSmrg        .sequenceNumber = client->sequence,
202435c4bbdfSmrg        .visual = wVisual(((WindowPtr) pDraw)),
202535c4bbdfSmrg        .depth = pDraw->depth
202635c4bbdfSmrg    };
202735c4bbdfSmrg    if (format == ZPixmap) {
202835c4bbdfSmrg        widthBytesLine = PixmapBytePad(w, pDraw->depth);
202935c4bbdfSmrg        length = widthBytesLine * h;
203005b261ecSmrg
203135c4bbdfSmrg    }
203235c4bbdfSmrg    else {
203335c4bbdfSmrg        widthBytesLine = BitmapBytePad(w);
203435c4bbdfSmrg        plane = ((Mask) 1) << (pDraw->depth - 1);
203535c4bbdfSmrg        /* only planes asked for */
203635c4bbdfSmrg        length = widthBytesLine * h * Ones(planemask & (plane | (plane - 1)));
203705b261ecSmrg
203805b261ecSmrg    }
203905b261ecSmrg
20406747b715Smrg    xgi.length = bytes_to_int32(length);
204105b261ecSmrg
204205b261ecSmrg    if (widthBytesLine == 0 || h == 0)
204335c4bbdfSmrg        linesPerBuf = 0;
204405b261ecSmrg    else if (widthBytesLine >= XINERAMA_IMAGE_BUFSIZE)
204535c4bbdfSmrg        linesPerBuf = 1;
204605b261ecSmrg    else {
204735c4bbdfSmrg        linesPerBuf = XINERAMA_IMAGE_BUFSIZE / widthBytesLine;
204835c4bbdfSmrg        if (linesPerBuf > h)
204935c4bbdfSmrg            linesPerBuf = h;
205005b261ecSmrg    }
205135c4bbdfSmrg    if (!(pBuf = xallocarray(linesPerBuf, widthBytesLine)))
205235c4bbdfSmrg        return BadAlloc;
205305b261ecSmrg
205435c4bbdfSmrg    WriteReplyToClient(client, sizeof(xGetImageReply), &xgi);
205505b261ecSmrg
205605b261ecSmrg    if (linesPerBuf == 0) {
205735c4bbdfSmrg        /* nothing to do */
205805b261ecSmrg    }
205905b261ecSmrg    else if (format == ZPixmap) {
206005b261ecSmrg        linesDone = 0;
206105b261ecSmrg        while (h - linesDone > 0) {
206235c4bbdfSmrg            nlines = min(linesPerBuf, h - linesDone);
206305b261ecSmrg
206435c4bbdfSmrg            if (pDraw->depth == 1)
206535c4bbdfSmrg                memset(pBuf, 0, nlines * widthBytesLine);
206605b261ecSmrg
206735c4bbdfSmrg            XineramaGetImageData(drawables, x, y + linesDone, w, nlines,
206835c4bbdfSmrg                                 format, planemask, pBuf, widthBytesLine,
206935c4bbdfSmrg                                 isRoot);
207005b261ecSmrg
207135c4bbdfSmrg            WriteToClient(client, (int) (nlines * widthBytesLine), pBuf);
207235c4bbdfSmrg            linesDone += nlines;
207305b261ecSmrg        }
207435c4bbdfSmrg    }
207535c4bbdfSmrg    else {                      /* XYPixmap */
207605b261ecSmrg        for (; plane; plane >>= 1) {
207735c4bbdfSmrg            if (planemask & plane) {
207835c4bbdfSmrg                linesDone = 0;
207935c4bbdfSmrg                while (h - linesDone > 0) {
208035c4bbdfSmrg                    nlines = min(linesPerBuf, h - linesDone);
208105b261ecSmrg
208235c4bbdfSmrg                    memset(pBuf, 0, nlines * widthBytesLine);
208305b261ecSmrg
208435c4bbdfSmrg                    XineramaGetImageData(drawables, x, y + linesDone, w,
208535c4bbdfSmrg                                         nlines, format, plane, pBuf,
208635c4bbdfSmrg                                         widthBytesLine, isRoot);
208705b261ecSmrg
208835c4bbdfSmrg                    WriteToClient(client, (int)(nlines * widthBytesLine), pBuf);
208905b261ecSmrg
209035c4bbdfSmrg                    linesDone += nlines;
209135c4bbdfSmrg                }
209205b261ecSmrg            }
209335c4bbdfSmrg        }
209405b261ecSmrg    }
20956747b715Smrg    free(pBuf);
20966747b715Smrg    return Success;
209705b261ecSmrg}
209805b261ecSmrg
209905b261ecSmrg/* The text stuff should be rewritten so that duplication happens
210005b261ecSmrg   at the GlyphBlt level.  That is, loading the font and getting
210105b261ecSmrg   the glyphs should only happen once */
210205b261ecSmrg
210335c4bbdfSmrgint
210405b261ecSmrgPanoramiXPolyText8(ClientPtr client)
210505b261ecSmrg{
210605b261ecSmrg    PanoramiXRes *gc, *draw;
210735c4bbdfSmrg    Bool isRoot;
210835c4bbdfSmrg    int result, j;
210935c4bbdfSmrg    int orig_x, orig_y;
211035c4bbdfSmrg
211105b261ecSmrg    REQUEST(xPolyTextReq);
211205b261ecSmrg
211305b261ecSmrg    REQUEST_AT_LEAST_SIZE(xPolyTextReq);
211405b261ecSmrg
211535c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
211635c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
21176747b715Smrg    if (result != Success)
211835c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
211905b261ecSmrg
212035c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
212135c4bbdfSmrg        return (*SavedProcVector[X_PolyText8]) (client);
212205b261ecSmrg
212335c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
212435c4bbdfSmrg                                     client, DixReadAccess);
21256747b715Smrg    if (result != Success)
212635c4bbdfSmrg        return result;
212705b261ecSmrg
212835c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
212905b261ecSmrg
213005b261ecSmrg    orig_x = stuff->x;
213105b261ecSmrg    orig_y = stuff->y;
213235c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
213335c4bbdfSmrg        stuff->drawable = draw->info[j].id;
213435c4bbdfSmrg        stuff->gc = gc->info[j].id;
213535c4bbdfSmrg        if (isRoot) {
213635c4bbdfSmrg            stuff->x = orig_x - screenInfo.screens[j]->x;
213735c4bbdfSmrg            stuff->y = orig_y - screenInfo.screens[j]->y;
213835c4bbdfSmrg        }
213935c4bbdfSmrg        result = (*SavedProcVector[X_PolyText8]) (client);
214035c4bbdfSmrg        if (result != Success)
214135c4bbdfSmrg            break;
214205b261ecSmrg    }
21436747b715Smrg    return result;
214405b261ecSmrg}
214505b261ecSmrg
214635c4bbdfSmrgint
214705b261ecSmrgPanoramiXPolyText16(ClientPtr client)
214805b261ecSmrg{
214905b261ecSmrg    PanoramiXRes *gc, *draw;
215035c4bbdfSmrg    Bool isRoot;
215135c4bbdfSmrg    int result, j;
215235c4bbdfSmrg    int orig_x, orig_y;
215335c4bbdfSmrg
215405b261ecSmrg    REQUEST(xPolyTextReq);
215505b261ecSmrg
215605b261ecSmrg    REQUEST_AT_LEAST_SIZE(xPolyTextReq);
215705b261ecSmrg
215835c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
215935c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
21606747b715Smrg    if (result != Success)
216135c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
216205b261ecSmrg
216335c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
216435c4bbdfSmrg        return (*SavedProcVector[X_PolyText16]) (client);
216505b261ecSmrg
216635c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
216735c4bbdfSmrg                                     client, DixReadAccess);
21686747b715Smrg    if (result != Success)
216935c4bbdfSmrg        return result;
217005b261ecSmrg
217135c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
217205b261ecSmrg
217305b261ecSmrg    orig_x = stuff->x;
217405b261ecSmrg    orig_y = stuff->y;
217535c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
217635c4bbdfSmrg        stuff->drawable = draw->info[j].id;
217735c4bbdfSmrg        stuff->gc = gc->info[j].id;
217835c4bbdfSmrg        if (isRoot) {
217935c4bbdfSmrg            stuff->x = orig_x - screenInfo.screens[j]->x;
218035c4bbdfSmrg            stuff->y = orig_y - screenInfo.screens[j]->y;
218135c4bbdfSmrg        }
218235c4bbdfSmrg        result = (*SavedProcVector[X_PolyText16]) (client);
218335c4bbdfSmrg        if (result != Success)
218435c4bbdfSmrg            break;
218505b261ecSmrg    }
21866747b715Smrg    return result;
218705b261ecSmrg}
218805b261ecSmrg
218935c4bbdfSmrgint
219035c4bbdfSmrgPanoramiXImageText8(ClientPtr client)
219105b261ecSmrg{
219235c4bbdfSmrg    int result, j;
219305b261ecSmrg    PanoramiXRes *gc, *draw;
219435c4bbdfSmrg    Bool isRoot;
219535c4bbdfSmrg    int orig_x, orig_y;
219635c4bbdfSmrg
219705b261ecSmrg    REQUEST(xImageTextReq);
219805b261ecSmrg
219905b261ecSmrg    REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars);
220005b261ecSmrg
220135c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
220235c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
22036747b715Smrg    if (result != Success)
220435c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
220505b261ecSmrg
220635c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
220735c4bbdfSmrg        return (*SavedProcVector[X_ImageText8]) (client);
220805b261ecSmrg
220935c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
221035c4bbdfSmrg                                     client, DixReadAccess);
22116747b715Smrg    if (result != Success)
221235c4bbdfSmrg        return result;
221305b261ecSmrg
221435c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
221505b261ecSmrg
221605b261ecSmrg    orig_x = stuff->x;
221705b261ecSmrg    orig_y = stuff->y;
221835c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
221935c4bbdfSmrg        stuff->drawable = draw->info[j].id;
222035c4bbdfSmrg        stuff->gc = gc->info[j].id;
222135c4bbdfSmrg        if (isRoot) {
222235c4bbdfSmrg            stuff->x = orig_x - screenInfo.screens[j]->x;
222335c4bbdfSmrg            stuff->y = orig_y - screenInfo.screens[j]->y;
222435c4bbdfSmrg        }
222535c4bbdfSmrg        result = (*SavedProcVector[X_ImageText8]) (client);
222635c4bbdfSmrg        if (result != Success)
222735c4bbdfSmrg            break;
222805b261ecSmrg    }
22296747b715Smrg    return result;
223005b261ecSmrg}
223105b261ecSmrg
223235c4bbdfSmrgint
223335c4bbdfSmrgPanoramiXImageText16(ClientPtr client)
223405b261ecSmrg{
223535c4bbdfSmrg    int result, j;
223605b261ecSmrg    PanoramiXRes *gc, *draw;
223735c4bbdfSmrg    Bool isRoot;
223835c4bbdfSmrg    int orig_x, orig_y;
223935c4bbdfSmrg
224005b261ecSmrg    REQUEST(xImageTextReq);
224105b261ecSmrg
224205b261ecSmrg    REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1);
224305b261ecSmrg
224435c4bbdfSmrg    result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
224535c4bbdfSmrg                                      XRC_DRAWABLE, client, DixWriteAccess);
22466747b715Smrg    if (result != Success)
224735c4bbdfSmrg        return (result == BadValue) ? BadDrawable : result;
224805b261ecSmrg
224935c4bbdfSmrg    if (IS_SHARED_PIXMAP(draw))
225035c4bbdfSmrg        return (*SavedProcVector[X_ImageText16]) (client);
225105b261ecSmrg
225235c4bbdfSmrg    result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
225335c4bbdfSmrg                                     client, DixReadAccess);
22546747b715Smrg    if (result != Success)
225535c4bbdfSmrg        return result;
225605b261ecSmrg
225735c4bbdfSmrg    isRoot = IS_ROOT_DRAWABLE(draw);
225805b261ecSmrg
225905b261ecSmrg    orig_x = stuff->x;
226005b261ecSmrg    orig_y = stuff->y;
226135c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
226235c4bbdfSmrg        stuff->drawable = draw->info[j].id;
226335c4bbdfSmrg        stuff->gc = gc->info[j].id;
226435c4bbdfSmrg        if (isRoot) {
226535c4bbdfSmrg            stuff->x = orig_x - screenInfo.screens[j]->x;
226635c4bbdfSmrg            stuff->y = orig_y - screenInfo.screens[j]->y;
226735c4bbdfSmrg        }
226835c4bbdfSmrg        result = (*SavedProcVector[X_ImageText16]) (client);
226935c4bbdfSmrg        if (result != Success)
227035c4bbdfSmrg            break;
227105b261ecSmrg    }
22726747b715Smrg    return result;
227305b261ecSmrg}
227405b261ecSmrg
227535c4bbdfSmrgint
227635c4bbdfSmrgPanoramiXCreateColormap(ClientPtr client)
227705b261ecSmrg{
227835c4bbdfSmrg    PanoramiXRes *win, *newCmap;
227935c4bbdfSmrg    int result, j, orig_visual;
228035c4bbdfSmrg
228105b261ecSmrg    REQUEST(xCreateColormapReq);
228205b261ecSmrg
228305b261ecSmrg    REQUEST_SIZE_MATCH(xCreateColormapReq);
228405b261ecSmrg
228535c4bbdfSmrg    result = dixLookupResourceByType((void **) &win, stuff->window,
228635c4bbdfSmrg                                     XRT_WINDOW, client, DixReadAccess);
22876747b715Smrg    if (result != Success)
228835c4bbdfSmrg        return result;
228905b261ecSmrg
229035c4bbdfSmrg    if (!(newCmap = malloc(sizeof(PanoramiXRes))))
229105b261ecSmrg        return BadAlloc;
229205b261ecSmrg
229305b261ecSmrg    newCmap->type = XRT_COLORMAP;
229435c4bbdfSmrg    panoramix_setup_ids(newCmap, client, stuff->mid);
229505b261ecSmrg
229605b261ecSmrg    orig_visual = stuff->visual;
229735c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
229835c4bbdfSmrg        stuff->mid = newCmap->info[j].id;
229935c4bbdfSmrg        stuff->window = win->info[j].id;
230035c4bbdfSmrg        stuff->visual = PanoramiXTranslateVisualID(j, orig_visual);
230135c4bbdfSmrg        result = (*SavedProcVector[X_CreateColormap]) (client);
230235c4bbdfSmrg        if (result != Success)
230335c4bbdfSmrg            break;
230435c4bbdfSmrg    }
230535c4bbdfSmrg
230605b261ecSmrg    if (result == Success)
230705b261ecSmrg        AddResource(newCmap->info[0].id, XRT_COLORMAP, newCmap);
230835c4bbdfSmrg    else
23096747b715Smrg        free(newCmap);
231005b261ecSmrg
23116747b715Smrg    return result;
231205b261ecSmrg}
231305b261ecSmrg
231435c4bbdfSmrgint
231535c4bbdfSmrgPanoramiXFreeColormap(ClientPtr client)
231605b261ecSmrg{
231705b261ecSmrg    PanoramiXRes *cmap;
231835c4bbdfSmrg    int result, j;
231935c4bbdfSmrg
232005b261ecSmrg    REQUEST(xResourceReq);
232105b261ecSmrg
232205b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
232305b261ecSmrg
232405b261ecSmrg    client->errorValue = stuff->id;
232505b261ecSmrg
232635c4bbdfSmrg    result = dixLookupResourceByType((void **) &cmap, stuff->id, XRT_COLORMAP,
232735c4bbdfSmrg                                     client, DixDestroyAccess);
23286747b715Smrg    if (result != Success)
23296747b715Smrg        return result;
233005b261ecSmrg
233105b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
233205b261ecSmrg        stuff->id = cmap->info[j].id;
233335c4bbdfSmrg        result = (*SavedProcVector[X_FreeColormap]) (client);
233435c4bbdfSmrg        if (result != Success)
233535c4bbdfSmrg            break;
233605b261ecSmrg    }
233705b261ecSmrg
233805b261ecSmrg    /* Since ProcFreeColormap is using FreeResource, it will free
233935c4bbdfSmrg       our resource for us on the last pass through the loop above */
234005b261ecSmrg
23416747b715Smrg    return result;
234205b261ecSmrg}
234305b261ecSmrg
234405b261ecSmrgint
234505b261ecSmrgPanoramiXCopyColormapAndFree(ClientPtr client)
234605b261ecSmrg{
234705b261ecSmrg    PanoramiXRes *cmap, *newCmap;
234835c4bbdfSmrg    int result, j;
234935c4bbdfSmrg
235005b261ecSmrg    REQUEST(xCopyColormapAndFreeReq);
235105b261ecSmrg
235205b261ecSmrg    REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq);
235305b261ecSmrg
235405b261ecSmrg    client->errorValue = stuff->srcCmap;
235505b261ecSmrg
235635c4bbdfSmrg    result = dixLookupResourceByType((void **) &cmap, stuff->srcCmap,
235735c4bbdfSmrg                                     XRT_COLORMAP, client,
235835c4bbdfSmrg                                     DixReadAccess | DixWriteAccess);
23596747b715Smrg    if (result != Success)
23606747b715Smrg        return result;
236105b261ecSmrg
236235c4bbdfSmrg    if (!(newCmap = malloc(sizeof(PanoramiXRes))))
236305b261ecSmrg        return BadAlloc;
236405b261ecSmrg
236505b261ecSmrg    newCmap->type = XRT_COLORMAP;
236635c4bbdfSmrg    panoramix_setup_ids(newCmap, client, stuff->mid);
236705b261ecSmrg
236835c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
236905b261ecSmrg        stuff->srcCmap = cmap->info[j].id;
237035c4bbdfSmrg        stuff->mid = newCmap->info[j].id;
237135c4bbdfSmrg        result = (*SavedProcVector[X_CopyColormapAndFree]) (client);
237235c4bbdfSmrg        if (result != Success)
237335c4bbdfSmrg            break;
237405b261ecSmrg    }
237505b261ecSmrg
237605b261ecSmrg    if (result == Success)
237705b261ecSmrg        AddResource(newCmap->info[0].id, XRT_COLORMAP, newCmap);
237835c4bbdfSmrg    else
23796747b715Smrg        free(newCmap);
238005b261ecSmrg
23816747b715Smrg    return result;
238205b261ecSmrg}
238305b261ecSmrg
238435c4bbdfSmrgint
238535c4bbdfSmrgPanoramiXInstallColormap(ClientPtr client)
238605b261ecSmrg{
238705b261ecSmrg    REQUEST(xResourceReq);
238835c4bbdfSmrg    int result, j;
238905b261ecSmrg    PanoramiXRes *cmap;
239005b261ecSmrg
239105b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
239205b261ecSmrg
239305b261ecSmrg    client->errorValue = stuff->id;
239405b261ecSmrg
239535c4bbdfSmrg    result = dixLookupResourceByType((void **) &cmap, stuff->id, XRT_COLORMAP,
239635c4bbdfSmrg                                     client, DixReadAccess);
23976747b715Smrg    if (result != Success)
23986747b715Smrg        return result;
239905b261ecSmrg
240035c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
240135c4bbdfSmrg        stuff->id = cmap->info[j].id;
240235c4bbdfSmrg        result = (*SavedProcVector[X_InstallColormap]) (client);
240335c4bbdfSmrg        if (result != Success)
240435c4bbdfSmrg            break;
240505b261ecSmrg    }
24066747b715Smrg    return result;
240705b261ecSmrg}
240805b261ecSmrg
240935c4bbdfSmrgint
241035c4bbdfSmrgPanoramiXUninstallColormap(ClientPtr client)
241105b261ecSmrg{
241205b261ecSmrg    REQUEST(xResourceReq);
241335c4bbdfSmrg    int result, j;
241405b261ecSmrg    PanoramiXRes *cmap;
241505b261ecSmrg
241605b261ecSmrg    REQUEST_SIZE_MATCH(xResourceReq);
241735c4bbdfSmrg
241805b261ecSmrg    client->errorValue = stuff->id;
241905b261ecSmrg
242035c4bbdfSmrg    result = dixLookupResourceByType((void **) &cmap, stuff->id, XRT_COLORMAP,
242135c4bbdfSmrg                                     client, DixReadAccess);
24226747b715Smrg    if (result != Success)
24236747b715Smrg        return result;
242405b261ecSmrg
242505b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
242635c4bbdfSmrg        stuff->id = cmap->info[j].id;
242735c4bbdfSmrg        result = (*SavedProcVector[X_UninstallColormap]) (client);
242835c4bbdfSmrg        if (result != Success)
242935c4bbdfSmrg            break;
243005b261ecSmrg    }
24316747b715Smrg    return result;
243205b261ecSmrg}
243305b261ecSmrg
243435c4bbdfSmrgint
243535c4bbdfSmrgPanoramiXAllocColor(ClientPtr client)
243605b261ecSmrg{
243735c4bbdfSmrg    int result, j;
243805b261ecSmrg    PanoramiXRes *cmap;
243935c4bbdfSmrg
244005b261ecSmrg    REQUEST(xAllocColorReq);
244105b261ecSmrg
244205b261ecSmrg    REQUEST_SIZE_MATCH(xAllocColorReq);
244305b261ecSmrg
244405b261ecSmrg    client->errorValue = stuff->cmap;
244505b261ecSmrg
244635c4bbdfSmrg    result = dixLookupResourceByType((void **) &cmap, stuff->cmap,
244735c4bbdfSmrg                                     XRT_COLORMAP, client, DixWriteAccess);
24486747b715Smrg    if (result != Success)
24496747b715Smrg        return result;
245005b261ecSmrg
245135c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
245235c4bbdfSmrg        stuff->cmap = cmap->info[j].id;
245335c4bbdfSmrg        result = (*SavedProcVector[X_AllocColor]) (client);
245435c4bbdfSmrg        if (result != Success)
245535c4bbdfSmrg            break;
245605b261ecSmrg    }
24576747b715Smrg    return result;
245805b261ecSmrg}
245905b261ecSmrg
246035c4bbdfSmrgint
246135c4bbdfSmrgPanoramiXAllocNamedColor(ClientPtr client)
246205b261ecSmrg{
246335c4bbdfSmrg    int result, j;
246435c4bbdfSmrg    PanoramiXRes *cmap;
246535c4bbdfSmrg
246605b261ecSmrg    REQUEST(xAllocNamedColorReq);
246705b261ecSmrg
246805b261ecSmrg    REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes);
246905b261ecSmrg
247005b261ecSmrg    client->errorValue = stuff->cmap;
247105b261ecSmrg
247235c4bbdfSmrg    result = dixLookupResourceByType((void **) &cmap, stuff->cmap,
247335c4bbdfSmrg                                     XRT_COLORMAP, client, DixWriteAccess);
24746747b715Smrg    if (result != Success)
24756747b715Smrg        return result;
247605b261ecSmrg
247735c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
247805b261ecSmrg        stuff->cmap = cmap->info[j].id;
247935c4bbdfSmrg        result = (*SavedProcVector[X_AllocNamedColor]) (client);
248035c4bbdfSmrg        if (result != Success)
248135c4bbdfSmrg            break;
248205b261ecSmrg    }
24836747b715Smrg    return result;
248405b261ecSmrg}
248505b261ecSmrg
248635c4bbdfSmrgint
248735c4bbdfSmrgPanoramiXAllocColorCells(ClientPtr client)
248805b261ecSmrg{
248935c4bbdfSmrg    int result, j;
249035c4bbdfSmrg    PanoramiXRes *cmap;
249135c4bbdfSmrg
249205b261ecSmrg    REQUEST(xAllocColorCellsReq);
249305b261ecSmrg
249405b261ecSmrg    REQUEST_SIZE_MATCH(xAllocColorCellsReq);
249505b261ecSmrg
249605b261ecSmrg    client->errorValue = stuff->cmap;
249705b261ecSmrg
249835c4bbdfSmrg    result = dixLookupResourceByType((void **) &cmap, stuff->cmap,
249935c4bbdfSmrg                                     XRT_COLORMAP, client, DixWriteAccess);
25006747b715Smrg    if (result != Success)
25016747b715Smrg        return result;
250235c4bbdfSmrg
250335c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
250435c4bbdfSmrg        stuff->cmap = cmap->info[j].id;
250535c4bbdfSmrg        result = (*SavedProcVector[X_AllocColorCells]) (client);
250635c4bbdfSmrg        if (result != Success)
250735c4bbdfSmrg            break;
250805b261ecSmrg    }
25096747b715Smrg    return result;
251005b261ecSmrg}
251105b261ecSmrg
251235c4bbdfSmrgint
251335c4bbdfSmrgPanoramiXAllocColorPlanes(ClientPtr client)
251405b261ecSmrg{
251535c4bbdfSmrg    int result, j;
251635c4bbdfSmrg    PanoramiXRes *cmap;
251735c4bbdfSmrg
251805b261ecSmrg    REQUEST(xAllocColorPlanesReq);
251905b261ecSmrg
252005b261ecSmrg    REQUEST_SIZE_MATCH(xAllocColorPlanesReq);
252105b261ecSmrg
252205b261ecSmrg    client->errorValue = stuff->cmap;
252305b261ecSmrg
252435c4bbdfSmrg    result = dixLookupResourceByType((void **) &cmap, stuff->cmap,
252535c4bbdfSmrg                                     XRT_COLORMAP, client, DixWriteAccess);
25266747b715Smrg    if (result != Success)
25276747b715Smrg        return result;
252835c4bbdfSmrg
252935c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
253035c4bbdfSmrg        stuff->cmap = cmap->info[j].id;
253135c4bbdfSmrg        result = (*SavedProcVector[X_AllocColorPlanes]) (client);
253235c4bbdfSmrg        if (result != Success)
253335c4bbdfSmrg            break;
253405b261ecSmrg    }
25356747b715Smrg    return result;
253605b261ecSmrg}
253705b261ecSmrg
253835c4bbdfSmrgint
253935c4bbdfSmrgPanoramiXFreeColors(ClientPtr client)
254005b261ecSmrg{
254135c4bbdfSmrg    int result, j;
254235c4bbdfSmrg    PanoramiXRes *cmap;
254335c4bbdfSmrg
254405b261ecSmrg    REQUEST(xFreeColorsReq);
254505b261ecSmrg
254605b261ecSmrg    REQUEST_AT_LEAST_SIZE(xFreeColorsReq);
254705b261ecSmrg
254805b261ecSmrg    client->errorValue = stuff->cmap;
254905b261ecSmrg
255035c4bbdfSmrg    result = dixLookupResourceByType((void **) &cmap, stuff->cmap,
255135c4bbdfSmrg                                     XRT_COLORMAP, client, DixWriteAccess);
25526747b715Smrg    if (result != Success)
25536747b715Smrg        return result;
255405b261ecSmrg
255505b261ecSmrg    FOR_NSCREENS_BACKWARD(j) {
255605b261ecSmrg        stuff->cmap = cmap->info[j].id;
255735c4bbdfSmrg        result = (*SavedProcVector[X_FreeColors]) (client);
255805b261ecSmrg    }
25596747b715Smrg    return result;
256005b261ecSmrg}
256105b261ecSmrg
256235c4bbdfSmrgint
256335c4bbdfSmrgPanoramiXStoreColors(ClientPtr client)
256405b261ecSmrg{
256535c4bbdfSmrg    int result, j;
256635c4bbdfSmrg    PanoramiXRes *cmap;
256735c4bbdfSmrg
256805b261ecSmrg    REQUEST(xStoreColorsReq);
256905b261ecSmrg
257005b261ecSmrg    REQUEST_AT_LEAST_SIZE(xStoreColorsReq);
257105b261ecSmrg
257205b261ecSmrg    client->errorValue = stuff->cmap;
257305b261ecSmrg
257435c4bbdfSmrg    result = dixLookupResourceByType((void **) &cmap, stuff->cmap,
257535c4bbdfSmrg                                     XRT_COLORMAP, client, DixWriteAccess);
25766747b715Smrg    if (result != Success)
25776747b715Smrg        return result;
257805b261ecSmrg
257935c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
258035c4bbdfSmrg        stuff->cmap = cmap->info[j].id;
258135c4bbdfSmrg        result = (*SavedProcVector[X_StoreColors]) (client);
258235c4bbdfSmrg        if (result != Success)
258335c4bbdfSmrg            break;
258405b261ecSmrg    }
25856747b715Smrg    return result;
258605b261ecSmrg}
258705b261ecSmrg
258835c4bbdfSmrgint
258935c4bbdfSmrgPanoramiXStoreNamedColor(ClientPtr client)
259005b261ecSmrg{
259135c4bbdfSmrg    int result, j;
259235c4bbdfSmrg    PanoramiXRes *cmap;
259335c4bbdfSmrg
259405b261ecSmrg    REQUEST(xStoreNamedColorReq);
259505b261ecSmrg
259605b261ecSmrg    REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes);
259705b261ecSmrg
259805b261ecSmrg    client->errorValue = stuff->cmap;
259905b261ecSmrg
260035c4bbdfSmrg    result = dixLookupResourceByType((void **) &cmap, stuff->cmap,
260135c4bbdfSmrg                                     XRT_COLORMAP, client, DixWriteAccess);
26026747b715Smrg    if (result != Success)
26036747b715Smrg        return result;
260405b261ecSmrg
260535c4bbdfSmrg    FOR_NSCREENS_BACKWARD(j) {
260635c4bbdfSmrg        stuff->cmap = cmap->info[j].id;
260735c4bbdfSmrg        result = (*SavedProcVector[X_StoreNamedColor]) (client);
260835c4bbdfSmrg        if (result != Success)
260935c4bbdfSmrg            break;
261005b261ecSmrg    }
26116747b715Smrg    return result;
261205b261ecSmrg}
2613