105b261ecSmrg/*
205b261ecSmrg * Copyright © 2003 Keith Packard
305b261ecSmrg *
405b261ecSmrg * Permission to use, copy, modify, distribute, and sell this software and its
505b261ecSmrg * documentation for any purpose is hereby granted without fee, provided that
605b261ecSmrg * the above copyright notice appear in all copies and that both that
705b261ecSmrg * copyright notice and this permission notice appear in supporting
805b261ecSmrg * documentation, and that the name of Keith Packard not be used in
905b261ecSmrg * advertising or publicity pertaining to distribution of the software without
1005b261ecSmrg * specific, written prior permission.  Keith Packard makes no
1105b261ecSmrg * representations about the suitability of this software for any purpose.  It
1205b261ecSmrg * is provided "as is" without express or implied warranty.
1305b261ecSmrg *
1405b261ecSmrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1505b261ecSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1605b261ecSmrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1705b261ecSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1805b261ecSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1905b261ecSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2005b261ecSmrg * PERFORMANCE OF THIS SOFTWARE.
2105b261ecSmrg */
2205b261ecSmrg
2305b261ecSmrg#ifdef HAVE_DIX_CONFIG_H
2405b261ecSmrg#include <dix-config.h>
2505b261ecSmrg#endif
2605b261ecSmrg
2705b261ecSmrg#include "xfixesint.h"
2805b261ecSmrg#include "scrnintstr.h"
2905b261ecSmrg#include <picturestr.h>
3035c4bbdfSmrg
3105b261ecSmrg#include <regionstr.h>
3205b261ecSmrg#include <gcstruct.h>
3305b261ecSmrg#include <window.h>
3405b261ecSmrg
356747b715SmrgRESTYPE RegionResType;
3605b261ecSmrg
3705b261ecSmrgstatic int
3835c4bbdfSmrgRegionResFree(void *data, XID id)
3905b261ecSmrg{
4035c4bbdfSmrg    RegionPtr pRegion = (RegionPtr) data;
4105b261ecSmrg
426747b715Smrg    RegionDestroy(pRegion);
4305b261ecSmrg    return Success;
4405b261ecSmrg}
4505b261ecSmrg
4605b261ecSmrgRegionPtr
4735c4bbdfSmrgXFixesRegionCopy(RegionPtr pRegion)
4805b261ecSmrg{
4935c4bbdfSmrg    RegionPtr pNew = RegionCreate(RegionExtents(pRegion),
5035c4bbdfSmrg                                  RegionNumRects(pRegion));
5135c4bbdfSmrg
5205b261ecSmrg    if (!pNew)
5335c4bbdfSmrg        return 0;
5435c4bbdfSmrg    if (!RegionCopy(pNew, pRegion)) {
5535c4bbdfSmrg        RegionDestroy(pNew);
5635c4bbdfSmrg        return 0;
5705b261ecSmrg    }
5805b261ecSmrg    return pNew;
5905b261ecSmrg}
6005b261ecSmrg
6105b261ecSmrgBool
6235c4bbdfSmrgXFixesRegionInit(void)
6305b261ecSmrg{
646747b715Smrg    RegionResType = CreateNewResourceType(RegionResFree, "XFixesRegion");
656747b715Smrg
666747b715Smrg    return RegionResType != 0;
6705b261ecSmrg}
6805b261ecSmrg
6905b261ecSmrgint
7035c4bbdfSmrgProcXFixesCreateRegion(ClientPtr client)
7105b261ecSmrg{
7235c4bbdfSmrg    int things;
7335c4bbdfSmrg    RegionPtr pRegion;
7435c4bbdfSmrg
7535c4bbdfSmrg    REQUEST(xXFixesCreateRegionReq);
7635c4bbdfSmrg
7705b261ecSmrg    REQUEST_AT_LEAST_SIZE(xXFixesCreateRegionReq);
7835c4bbdfSmrg    LEGAL_NEW_RESOURCE(stuff->region, client);
7935c4bbdfSmrg
8035c4bbdfSmrg    things = (client->req_len << 2) - sizeof(xXFixesCreateRegionReq);
8105b261ecSmrg    if (things & 4)
8235c4bbdfSmrg        return BadLength;
8305b261ecSmrg    things >>= 3;
8405b261ecSmrg
856747b715Smrg    pRegion = RegionFromRects(things, (xRectangle *) (stuff + 1), CT_UNSORTED);
8605b261ecSmrg    if (!pRegion)
8735c4bbdfSmrg        return BadAlloc;
8835c4bbdfSmrg    if (!AddResource(stuff->region, RegionResType, (void *) pRegion))
8935c4bbdfSmrg        return BadAlloc;
9035c4bbdfSmrg
916747b715Smrg    return Success;
9205b261ecSmrg}
9305b261ecSmrg
947e31ba66Smrgint _X_COLD
9535c4bbdfSmrgSProcXFixesCreateRegion(ClientPtr client)
9605b261ecSmrg{
9705b261ecSmrg    REQUEST(xXFixesCreateRegionReq);
9835c4bbdfSmrg
9935c4bbdfSmrg    swaps(&stuff->length);
10005b261ecSmrg    REQUEST_AT_LEAST_SIZE(xXFixesCreateRegionReq);
10135c4bbdfSmrg    swapl(&stuff->region);
10205b261ecSmrg    SwapRestS(stuff);
10305b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
10405b261ecSmrg}
10505b261ecSmrg
10605b261ecSmrgint
10735c4bbdfSmrgProcXFixesCreateRegionFromBitmap(ClientPtr client)
10805b261ecSmrg{
10935c4bbdfSmrg    RegionPtr pRegion;
11035c4bbdfSmrg    PixmapPtr pPixmap;
1114642e01fSmrg    int rc;
11205b261ecSmrg
11335c4bbdfSmrg    REQUEST(xXFixesCreateRegionFromBitmapReq);
11405b261ecSmrg
11535c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesCreateRegionFromBitmapReq);
11635c4bbdfSmrg    LEGAL_NEW_RESOURCE(stuff->region, client);
11735c4bbdfSmrg
11835c4bbdfSmrg    rc = dixLookupResourceByType((void **) &pPixmap, stuff->bitmap, RT_PIXMAP,
11935c4bbdfSmrg                                 client, DixReadAccess);
12035c4bbdfSmrg    if (rc != Success) {
12135c4bbdfSmrg        client->errorValue = stuff->bitmap;
12235c4bbdfSmrg        return rc;
12305b261ecSmrg    }
12405b261ecSmrg    if (pPixmap->drawable.depth != 1)
12535c4bbdfSmrg        return BadMatch;
12605b261ecSmrg
1276747b715Smrg    pRegion = BitmapToRegion(pPixmap->drawable.pScreen, pPixmap);
12805b261ecSmrg
12905b261ecSmrg    if (!pRegion)
13035c4bbdfSmrg        return BadAlloc;
13135c4bbdfSmrg
13235c4bbdfSmrg    if (!AddResource(stuff->region, RegionResType, (void *) pRegion))
13335c4bbdfSmrg        return BadAlloc;
13435c4bbdfSmrg
1356747b715Smrg    return Success;
13605b261ecSmrg}
13705b261ecSmrg
1387e31ba66Smrgint _X_COLD
13935c4bbdfSmrgSProcXFixesCreateRegionFromBitmap(ClientPtr client)
14005b261ecSmrg{
14135c4bbdfSmrg    REQUEST(xXFixesCreateRegionFromBitmapReq);
14205b261ecSmrg
14335c4bbdfSmrg    swaps(&stuff->length);
14435c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesCreateRegionFromBitmapReq);
14535c4bbdfSmrg    swapl(&stuff->region);
14635c4bbdfSmrg    swapl(&stuff->bitmap);
14705b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
14805b261ecSmrg}
14905b261ecSmrg
15005b261ecSmrgint
15135c4bbdfSmrgProcXFixesCreateRegionFromWindow(ClientPtr client)
15205b261ecSmrg{
15335c4bbdfSmrg    RegionPtr pRegion;
15435c4bbdfSmrg    Bool copy = TRUE;
15535c4bbdfSmrg    WindowPtr pWin;
1564642e01fSmrg    int rc;
15735c4bbdfSmrg
15835c4bbdfSmrg    REQUEST(xXFixesCreateRegionFromWindowReq);
15935c4bbdfSmrg
16035c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesCreateRegionFromWindowReq);
16135c4bbdfSmrg    LEGAL_NEW_RESOURCE(stuff->region, client);
16235c4bbdfSmrg    rc = dixLookupResourceByType((void **) &pWin, stuff->window, RT_WINDOW,
16335c4bbdfSmrg                                 client, DixGetAttrAccess);
16435c4bbdfSmrg    if (rc != Success) {
16535c4bbdfSmrg        client->errorValue = stuff->window;
16635c4bbdfSmrg        return rc;
16705b261ecSmrg    }
16805b261ecSmrg    switch (stuff->kind) {
16905b261ecSmrg    case WindowRegionBounding:
17035c4bbdfSmrg        pRegion = wBoundingShape(pWin);
17135c4bbdfSmrg        if (!pRegion) {
17235c4bbdfSmrg            pRegion = CreateBoundingShape(pWin);
17335c4bbdfSmrg            copy = FALSE;
17435c4bbdfSmrg        }
17535c4bbdfSmrg        break;
17605b261ecSmrg    case WindowRegionClip:
17735c4bbdfSmrg        pRegion = wClipShape(pWin);
17835c4bbdfSmrg        if (!pRegion) {
17935c4bbdfSmrg            pRegion = CreateClipShape(pWin);
18035c4bbdfSmrg            copy = FALSE;
18135c4bbdfSmrg        }
18235c4bbdfSmrg        break;
18305b261ecSmrg    default:
18435c4bbdfSmrg        client->errorValue = stuff->kind;
18535c4bbdfSmrg        return BadValue;
18605b261ecSmrg    }
18705b261ecSmrg    if (copy && pRegion)
18835c4bbdfSmrg        pRegion = XFixesRegionCopy(pRegion);
18905b261ecSmrg    if (!pRegion)
19035c4bbdfSmrg        return BadAlloc;
19135c4bbdfSmrg    if (!AddResource(stuff->region, RegionResType, (void *) pRegion))
19235c4bbdfSmrg        return BadAlloc;
19335c4bbdfSmrg
1946747b715Smrg    return Success;
19505b261ecSmrg}
19605b261ecSmrg
1977e31ba66Smrgint _X_COLD
19835c4bbdfSmrgSProcXFixesCreateRegionFromWindow(ClientPtr client)
19905b261ecSmrg{
20035c4bbdfSmrg    REQUEST(xXFixesCreateRegionFromWindowReq);
20105b261ecSmrg
20235c4bbdfSmrg    swaps(&stuff->length);
20335c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesCreateRegionFromWindowReq);
20435c4bbdfSmrg    swapl(&stuff->region);
20535c4bbdfSmrg    swapl(&stuff->window);
20605b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
20705b261ecSmrg}
20805b261ecSmrg
20905b261ecSmrgint
21035c4bbdfSmrgProcXFixesCreateRegionFromGC(ClientPtr client)
21105b261ecSmrg{
21235c4bbdfSmrg    RegionPtr pRegion, pClip;
21335c4bbdfSmrg    GCPtr pGC;
21435c4bbdfSmrg    int rc;
21505b261ecSmrg
21635c4bbdfSmrg    REQUEST(xXFixesCreateRegionFromGCReq);
21735c4bbdfSmrg
21835c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesCreateRegionFromGCReq);
21935c4bbdfSmrg    LEGAL_NEW_RESOURCE(stuff->region, client);
22005b261ecSmrg
2214642e01fSmrg    rc = dixLookupGC(&pGC, stuff->gc, client, DixGetAttrAccess);
22205b261ecSmrg    if (rc != Success)
22335c4bbdfSmrg        return rc;
22435c4bbdfSmrg
22535c4bbdfSmrg    if (pGC->clientClip) {
22635c4bbdfSmrg        pClip = (RegionPtr) pGC->clientClip;
22735c4bbdfSmrg        pRegion = XFixesRegionCopy(pClip);
22835c4bbdfSmrg        if (!pRegion)
22935c4bbdfSmrg            return BadAlloc;
23035c4bbdfSmrg    } else {
23135c4bbdfSmrg        return BadMatch;
23205b261ecSmrg    }
23335c4bbdfSmrg
23435c4bbdfSmrg    if (!AddResource(stuff->region, RegionResType, (void *) pRegion))
23535c4bbdfSmrg        return BadAlloc;
23635c4bbdfSmrg
2376747b715Smrg    return Success;
23805b261ecSmrg}
23905b261ecSmrg
2407e31ba66Smrgint _X_COLD
24135c4bbdfSmrgSProcXFixesCreateRegionFromGC(ClientPtr client)
24205b261ecSmrg{
24335c4bbdfSmrg    REQUEST(xXFixesCreateRegionFromGCReq);
24405b261ecSmrg
24535c4bbdfSmrg    swaps(&stuff->length);
24635c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesCreateRegionFromGCReq);
24735c4bbdfSmrg    swapl(&stuff->region);
24835c4bbdfSmrg    swapl(&stuff->gc);
24905b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
25005b261ecSmrg}
25105b261ecSmrg
25205b261ecSmrgint
25335c4bbdfSmrgProcXFixesCreateRegionFromPicture(ClientPtr client)
25405b261ecSmrg{
25535c4bbdfSmrg    RegionPtr pRegion;
25635c4bbdfSmrg    PicturePtr pPicture;
25735c4bbdfSmrg
25835c4bbdfSmrg    REQUEST(xXFixesCreateRegionFromPictureReq);
25905b261ecSmrg
26035c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesCreateRegionFromPictureReq);
26135c4bbdfSmrg    LEGAL_NEW_RESOURCE(stuff->region, client);
26205b261ecSmrg
2636747b715Smrg    VERIFY_PICTURE(pPicture, stuff->picture, client, DixGetAttrAccess);
26435c4bbdfSmrg
26535c4bbdfSmrg    if (!pPicture->pDrawable)
26635c4bbdfSmrg        return RenderErrBase + BadPicture;
26735c4bbdfSmrg
26835c4bbdfSmrg    if (pPicture->clientClip) {
26935c4bbdfSmrg        pRegion = XFixesRegionCopy((RegionPtr) pPicture->clientClip);
27035c4bbdfSmrg        if (!pRegion)
27135c4bbdfSmrg            return BadAlloc;
27235c4bbdfSmrg    } else {
27335c4bbdfSmrg        return BadMatch;
27405b261ecSmrg    }
27535c4bbdfSmrg
27635c4bbdfSmrg    if (!AddResource(stuff->region, RegionResType, (void *) pRegion))
27735c4bbdfSmrg        return BadAlloc;
27835c4bbdfSmrg
2796747b715Smrg    return Success;
28005b261ecSmrg}
28105b261ecSmrg
2827e31ba66Smrgint _X_COLD
28335c4bbdfSmrgSProcXFixesCreateRegionFromPicture(ClientPtr client)
28405b261ecSmrg{
28535c4bbdfSmrg    REQUEST(xXFixesCreateRegionFromPictureReq);
28605b261ecSmrg
28735c4bbdfSmrg    swaps(&stuff->length);
28835c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesCreateRegionFromPictureReq);
28935c4bbdfSmrg    swapl(&stuff->region);
29035c4bbdfSmrg    swapl(&stuff->picture);
29105b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
29205b261ecSmrg}
29305b261ecSmrg
29405b261ecSmrgint
29535c4bbdfSmrgProcXFixesDestroyRegion(ClientPtr client)
29605b261ecSmrg{
29735c4bbdfSmrg    REQUEST(xXFixesDestroyRegionReq);
29835c4bbdfSmrg    RegionPtr pRegion;
29905b261ecSmrg
30005b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesDestroyRegionReq);
30105b261ecSmrg    VERIFY_REGION(pRegion, stuff->region, client, DixWriteAccess);
30235c4bbdfSmrg    FreeResource(stuff->region, RT_NONE);
3036747b715Smrg    return Success;
30405b261ecSmrg}
30505b261ecSmrg
3067e31ba66Smrgint _X_COLD
30735c4bbdfSmrgSProcXFixesDestroyRegion(ClientPtr client)
30805b261ecSmrg{
30935c4bbdfSmrg    REQUEST(xXFixesDestroyRegionReq);
31005b261ecSmrg
31135c4bbdfSmrg    swaps(&stuff->length);
31205b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesDestroyRegionReq);
31335c4bbdfSmrg    swapl(&stuff->region);
31405b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
31505b261ecSmrg}
31605b261ecSmrg
31705b261ecSmrgint
31835c4bbdfSmrgProcXFixesSetRegion(ClientPtr client)
31905b261ecSmrg{
32035c4bbdfSmrg    int things;
32135c4bbdfSmrg    RegionPtr pRegion, pNew;
32235c4bbdfSmrg
32335c4bbdfSmrg    REQUEST(xXFixesSetRegionReq);
32405b261ecSmrg
32505b261ecSmrg    REQUEST_AT_LEAST_SIZE(xXFixesSetRegionReq);
32605b261ecSmrg    VERIFY_REGION(pRegion, stuff->region, client, DixWriteAccess);
32735c4bbdfSmrg
32835c4bbdfSmrg    things = (client->req_len << 2) - sizeof(xXFixesCreateRegionReq);
32905b261ecSmrg    if (things & 4)
33035c4bbdfSmrg        return BadLength;
33105b261ecSmrg    things >>= 3;
33205b261ecSmrg
3336747b715Smrg    pNew = RegionFromRects(things, (xRectangle *) (stuff + 1), CT_UNSORTED);
33405b261ecSmrg    if (!pNew)
33535c4bbdfSmrg        return BadAlloc;
33635c4bbdfSmrg    if (!RegionCopy(pRegion, pNew)) {
33735c4bbdfSmrg        RegionDestroy(pNew);
33835c4bbdfSmrg        return BadAlloc;
33905b261ecSmrg    }
3406747b715Smrg    RegionDestroy(pNew);
3416747b715Smrg    return Success;
34205b261ecSmrg}
34305b261ecSmrg
3447e31ba66Smrgint _X_COLD
34535c4bbdfSmrgSProcXFixesSetRegion(ClientPtr client)
34605b261ecSmrg{
34735c4bbdfSmrg    REQUEST(xXFixesSetRegionReq);
34805b261ecSmrg
34935c4bbdfSmrg    swaps(&stuff->length);
35005b261ecSmrg    REQUEST_AT_LEAST_SIZE(xXFixesSetRegionReq);
35135c4bbdfSmrg    swapl(&stuff->region);
35205b261ecSmrg    SwapRestS(stuff);
35305b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
35405b261ecSmrg}
35505b261ecSmrg
35605b261ecSmrgint
35735c4bbdfSmrgProcXFixesCopyRegion(ClientPtr client)
35805b261ecSmrg{
35935c4bbdfSmrg    RegionPtr pSource, pDestination;
36035c4bbdfSmrg
36135c4bbdfSmrg    REQUEST(xXFixesCopyRegionReq);
3626e78d31fSmrg    REQUEST_SIZE_MATCH(xXFixesCopyRegionReq);
36335c4bbdfSmrg
36405b261ecSmrg    VERIFY_REGION(pSource, stuff->source, client, DixReadAccess);
36505b261ecSmrg    VERIFY_REGION(pDestination, stuff->destination, client, DixWriteAccess);
36635c4bbdfSmrg
3676747b715Smrg    if (!RegionCopy(pDestination, pSource))
36835c4bbdfSmrg        return BadAlloc;
36905b261ecSmrg
3706747b715Smrg    return Success;
37105b261ecSmrg}
37205b261ecSmrg
3737e31ba66Smrgint _X_COLD
37435c4bbdfSmrgSProcXFixesCopyRegion(ClientPtr client)
37505b261ecSmrg{
37635c4bbdfSmrg    REQUEST(xXFixesCopyRegionReq);
37705b261ecSmrg
37835c4bbdfSmrg    swaps(&stuff->length);
3796e78d31fSmrg    REQUEST_SIZE_MATCH(xXFixesCopyRegionReq);
38035c4bbdfSmrg    swapl(&stuff->source);
38135c4bbdfSmrg    swapl(&stuff->destination);
38205b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
38305b261ecSmrg}
38405b261ecSmrg
38505b261ecSmrgint
38635c4bbdfSmrgProcXFixesCombineRegion(ClientPtr client)
38705b261ecSmrg{
38835c4bbdfSmrg    RegionPtr pSource1, pSource2, pDestination;
38905b261ecSmrg
39035c4bbdfSmrg    REQUEST(xXFixesCombineRegionReq);
39135c4bbdfSmrg
39235c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesCombineRegionReq);
39305b261ecSmrg    VERIFY_REGION(pSource1, stuff->source1, client, DixReadAccess);
39405b261ecSmrg    VERIFY_REGION(pSource2, stuff->source2, client, DixReadAccess);
39505b261ecSmrg    VERIFY_REGION(pDestination, stuff->destination, client, DixWriteAccess);
39635c4bbdfSmrg
39705b261ecSmrg    switch (stuff->xfixesReqType) {
39805b261ecSmrg    case X_XFixesUnionRegion:
39935c4bbdfSmrg        if (!RegionUnion(pDestination, pSource1, pSource2))
40035c4bbdfSmrg            return BadAlloc;
40135c4bbdfSmrg        break;
40205b261ecSmrg    case X_XFixesIntersectRegion:
40335c4bbdfSmrg        if (!RegionIntersect(pDestination, pSource1, pSource2))
40435c4bbdfSmrg            return BadAlloc;
40535c4bbdfSmrg        break;
40605b261ecSmrg    case X_XFixesSubtractRegion:
40735c4bbdfSmrg        if (!RegionSubtract(pDestination, pSource1, pSource2))
40835c4bbdfSmrg            return BadAlloc;
40935c4bbdfSmrg        break;
41005b261ecSmrg    }
41135c4bbdfSmrg
4126747b715Smrg    return Success;
41305b261ecSmrg}
41405b261ecSmrg
4157e31ba66Smrgint _X_COLD
41635c4bbdfSmrgSProcXFixesCombineRegion(ClientPtr client)
41705b261ecSmrg{
41835c4bbdfSmrg    REQUEST(xXFixesCombineRegionReq);
41905b261ecSmrg
42035c4bbdfSmrg    swaps(&stuff->length);
42135c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesCombineRegionReq);
42235c4bbdfSmrg    swapl(&stuff->source1);
42335c4bbdfSmrg    swapl(&stuff->source2);
42435c4bbdfSmrg    swapl(&stuff->destination);
42505b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
42605b261ecSmrg}
42705b261ecSmrg
42805b261ecSmrgint
42935c4bbdfSmrgProcXFixesInvertRegion(ClientPtr client)
43005b261ecSmrg{
43135c4bbdfSmrg    RegionPtr pSource, pDestination;
43235c4bbdfSmrg    BoxRec bounds;
43335c4bbdfSmrg
43405b261ecSmrg    REQUEST(xXFixesInvertRegionReq);
43505b261ecSmrg
43605b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesInvertRegionReq);
43705b261ecSmrg    VERIFY_REGION(pSource, stuff->source, client, DixReadAccess);
43805b261ecSmrg    VERIFY_REGION(pDestination, stuff->destination, client, DixWriteAccess);
43905b261ecSmrg
44005b261ecSmrg    /* Compute bounds, limit to 16 bits */
44105b261ecSmrg    bounds.x1 = stuff->x;
44205b261ecSmrg    bounds.y1 = stuff->y;
44305b261ecSmrg    if ((int) stuff->x + (int) stuff->width > MAXSHORT)
44435c4bbdfSmrg        bounds.x2 = MAXSHORT;
44505b261ecSmrg    else
44635c4bbdfSmrg        bounds.x2 = stuff->x + stuff->width;
44735c4bbdfSmrg
44805b261ecSmrg    if ((int) stuff->y + (int) stuff->height > MAXSHORT)
44935c4bbdfSmrg        bounds.y2 = MAXSHORT;
45005b261ecSmrg    else
45135c4bbdfSmrg        bounds.y2 = stuff->y + stuff->height;
45205b261ecSmrg
4536747b715Smrg    if (!RegionInverse(pDestination, pSource, &bounds))
45435c4bbdfSmrg        return BadAlloc;
45505b261ecSmrg
4566747b715Smrg    return Success;
45705b261ecSmrg}
45805b261ecSmrg
4597e31ba66Smrgint _X_COLD
46035c4bbdfSmrgSProcXFixesInvertRegion(ClientPtr client)
46105b261ecSmrg{
46205b261ecSmrg    REQUEST(xXFixesInvertRegionReq);
46305b261ecSmrg
46435c4bbdfSmrg    swaps(&stuff->length);
46505b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesInvertRegionReq);
46635c4bbdfSmrg    swapl(&stuff->source);
46735c4bbdfSmrg    swaps(&stuff->x);
46835c4bbdfSmrg    swaps(&stuff->y);
46935c4bbdfSmrg    swaps(&stuff->width);
47035c4bbdfSmrg    swaps(&stuff->height);
47135c4bbdfSmrg    swapl(&stuff->destination);
47205b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
47305b261ecSmrg}
47405b261ecSmrg
47505b261ecSmrgint
47635c4bbdfSmrgProcXFixesTranslateRegion(ClientPtr client)
47705b261ecSmrg{
47835c4bbdfSmrg    RegionPtr pRegion;
47935c4bbdfSmrg
48005b261ecSmrg    REQUEST(xXFixesTranslateRegionReq);
48105b261ecSmrg
48205b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesTranslateRegionReq);
48305b261ecSmrg    VERIFY_REGION(pRegion, stuff->region, client, DixWriteAccess);
48405b261ecSmrg
4856747b715Smrg    RegionTranslate(pRegion, stuff->dx, stuff->dy);
4866747b715Smrg    return Success;
48705b261ecSmrg}
48805b261ecSmrg
4897e31ba66Smrgint _X_COLD
49035c4bbdfSmrgSProcXFixesTranslateRegion(ClientPtr client)
49105b261ecSmrg{
49205b261ecSmrg    REQUEST(xXFixesTranslateRegionReq);
49305b261ecSmrg
49435c4bbdfSmrg    swaps(&stuff->length);
49505b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesTranslateRegionReq);
49635c4bbdfSmrg    swapl(&stuff->region);
49735c4bbdfSmrg    swaps(&stuff->dx);
49835c4bbdfSmrg    swaps(&stuff->dy);
49905b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
50005b261ecSmrg}
50105b261ecSmrg
50205b261ecSmrgint
50335c4bbdfSmrgProcXFixesRegionExtents(ClientPtr client)
50405b261ecSmrg{
50535c4bbdfSmrg    RegionPtr pSource, pDestination;
50635c4bbdfSmrg
50705b261ecSmrg    REQUEST(xXFixesRegionExtentsReq);
50805b261ecSmrg
50905b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesRegionExtentsReq);
51005b261ecSmrg    VERIFY_REGION(pSource, stuff->source, client, DixReadAccess);
51105b261ecSmrg    VERIFY_REGION(pDestination, stuff->destination, client, DixWriteAccess);
51205b261ecSmrg
5136747b715Smrg    RegionReset(pDestination, RegionExtents(pSource));
51405b261ecSmrg
5156747b715Smrg    return Success;
51605b261ecSmrg}
51705b261ecSmrg
5187e31ba66Smrgint _X_COLD
51935c4bbdfSmrgSProcXFixesRegionExtents(ClientPtr client)
52005b261ecSmrg{
52105b261ecSmrg    REQUEST(xXFixesRegionExtentsReq);
52235c4bbdfSmrg
52335c4bbdfSmrg    swaps(&stuff->length);
52405b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesRegionExtentsReq);
52535c4bbdfSmrg    swapl(&stuff->source);
52635c4bbdfSmrg    swapl(&stuff->destination);
52705b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
52805b261ecSmrg}
52905b261ecSmrg
53005b261ecSmrgint
53135c4bbdfSmrgProcXFixesFetchRegion(ClientPtr client)
53205b261ecSmrg{
53335c4bbdfSmrg    RegionPtr pRegion;
53405b261ecSmrg    xXFixesFetchRegionReply *reply;
53535c4bbdfSmrg    xRectangle *pRect;
53635c4bbdfSmrg    BoxPtr pExtent;
53735c4bbdfSmrg    BoxPtr pBox;
53835c4bbdfSmrg    int i, nBox;
53935c4bbdfSmrg
54005b261ecSmrg    REQUEST(xXFixesFetchRegionReq);
54105b261ecSmrg
54205b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesFetchRegionReq);
54305b261ecSmrg    VERIFY_REGION(pRegion, stuff->region, client, DixReadAccess);
54405b261ecSmrg
5456747b715Smrg    pExtent = RegionExtents(pRegion);
54635c4bbdfSmrg    pBox = RegionRects(pRegion);
54735c4bbdfSmrg    nBox = RegionNumRects(pRegion);
54835c4bbdfSmrg
54935c4bbdfSmrg    reply = calloc(sizeof(xXFixesFetchRegionReply) + nBox * sizeof(xRectangle),
55035c4bbdfSmrg                   1);
55105b261ecSmrg    if (!reply)
55235c4bbdfSmrg        return BadAlloc;
55305b261ecSmrg    reply->type = X_Reply;
55405b261ecSmrg    reply->sequenceNumber = client->sequence;
55505b261ecSmrg    reply->length = nBox << 1;
55605b261ecSmrg    reply->x = pExtent->x1;
55705b261ecSmrg    reply->y = pExtent->y1;
55805b261ecSmrg    reply->width = pExtent->x2 - pExtent->x1;
55905b261ecSmrg    reply->height = pExtent->y2 - pExtent->y1;
56005b261ecSmrg
56105b261ecSmrg    pRect = (xRectangle *) (reply + 1);
56235c4bbdfSmrg    for (i = 0; i < nBox; i++) {
56335c4bbdfSmrg        pRect[i].x = pBox[i].x1;
56435c4bbdfSmrg        pRect[i].y = pBox[i].y1;
56535c4bbdfSmrg        pRect[i].width = pBox[i].x2 - pBox[i].x1;
56635c4bbdfSmrg        pRect[i].height = pBox[i].y2 - pBox[i].y1;
56705b261ecSmrg    }
56835c4bbdfSmrg    if (client->swapped) {
56935c4bbdfSmrg        swaps(&reply->sequenceNumber);
57035c4bbdfSmrg        swapl(&reply->length);
57135c4bbdfSmrg        swaps(&reply->x);
57235c4bbdfSmrg        swaps(&reply->y);
57335c4bbdfSmrg        swaps(&reply->width);
57435c4bbdfSmrg        swaps(&reply->height);
57535c4bbdfSmrg        SwapShorts((INT16 *) pRect, nBox * 4);
57605b261ecSmrg    }
57735c4bbdfSmrg    WriteToClient(client, sizeof(xXFixesFetchRegionReply) +
57835c4bbdfSmrg                         nBox * sizeof(xRectangle), (char *) reply);
5796747b715Smrg    free(reply);
5806747b715Smrg    return Success;
58105b261ecSmrg}
58205b261ecSmrg
5837e31ba66Smrgint _X_COLD
58435c4bbdfSmrgSProcXFixesFetchRegion(ClientPtr client)
58505b261ecSmrg{
58605b261ecSmrg    REQUEST(xXFixesFetchRegionReq);
58705b261ecSmrg
58835c4bbdfSmrg    swaps(&stuff->length);
58905b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesFetchRegionReq);
59035c4bbdfSmrg    swapl(&stuff->region);
59105b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
59205b261ecSmrg}
59305b261ecSmrg
59405b261ecSmrgint
59535c4bbdfSmrgProcXFixesSetGCClipRegion(ClientPtr client)
59605b261ecSmrg{
59735c4bbdfSmrg    GCPtr pGC;
59835c4bbdfSmrg    RegionPtr pRegion;
59935c4bbdfSmrg    ChangeGCVal vals[2];
60035c4bbdfSmrg    int rc;
60135c4bbdfSmrg
60205b261ecSmrg    REQUEST(xXFixesSetGCClipRegionReq);
60305b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesSetGCClipRegionReq);
60405b261ecSmrg
6054642e01fSmrg    rc = dixLookupGC(&pGC, stuff->gc, client, DixSetAttrAccess);
60605b261ecSmrg    if (rc != Success)
60735c4bbdfSmrg        return rc;
60805b261ecSmrg
60935c4bbdfSmrg    VERIFY_REGION_OR_NONE(pRegion, stuff->region, client, DixReadAccess);
61005b261ecSmrg
61135c4bbdfSmrg    if (pRegion) {
61235c4bbdfSmrg        pRegion = XFixesRegionCopy(pRegion);
61335c4bbdfSmrg        if (!pRegion)
61435c4bbdfSmrg            return BadAlloc;
61505b261ecSmrg    }
61635c4bbdfSmrg
6176747b715Smrg    vals[0].val = stuff->xOrigin;
6186747b715Smrg    vals[1].val = stuff->yOrigin;
61935c4bbdfSmrg    ChangeGC(NullClient, pGC, GCClipXOrigin | GCClipYOrigin, vals);
62035c4bbdfSmrg    (*pGC->funcs->ChangeClip) (pGC, pRegion ? CT_REGION : CT_NONE,
62135c4bbdfSmrg                               (void *) pRegion, 0);
62205b261ecSmrg
6236747b715Smrg    return Success;
62405b261ecSmrg}
62505b261ecSmrg
6267e31ba66Smrgint _X_COLD
62735c4bbdfSmrgSProcXFixesSetGCClipRegion(ClientPtr client)
62805b261ecSmrg{
62905b261ecSmrg    REQUEST(xXFixesSetGCClipRegionReq);
63005b261ecSmrg
63135c4bbdfSmrg    swaps(&stuff->length);
63205b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesSetGCClipRegionReq);
63335c4bbdfSmrg    swapl(&stuff->gc);
63435c4bbdfSmrg    swapl(&stuff->region);
63535c4bbdfSmrg    swaps(&stuff->xOrigin);
63635c4bbdfSmrg    swaps(&stuff->yOrigin);
63705b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
63805b261ecSmrg}
63905b261ecSmrg
64035c4bbdfSmrgtypedef RegionPtr (*CreateDftPtr) (WindowPtr pWin);
64105b261ecSmrg
64205b261ecSmrgint
64335c4bbdfSmrgProcXFixesSetWindowShapeRegion(ClientPtr client)
64405b261ecSmrg{
64535c4bbdfSmrg    WindowPtr pWin;
64635c4bbdfSmrg    RegionPtr pRegion;
64735c4bbdfSmrg    RegionPtr *pDestRegion;
6484642e01fSmrg    int rc;
64935c4bbdfSmrg
65005b261ecSmrg    REQUEST(xXFixesSetWindowShapeRegionReq);
65105b261ecSmrg
65205b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesSetWindowShapeRegionReq);
65335c4bbdfSmrg    rc = dixLookupResourceByType((void **) &pWin, stuff->dest, RT_WINDOW,
65435c4bbdfSmrg                                 client, DixSetAttrAccess);
65535c4bbdfSmrg    if (rc != Success) {
65635c4bbdfSmrg        client->errorValue = stuff->dest;
65735c4bbdfSmrg        return rc;
65805b261ecSmrg    }
65905b261ecSmrg    VERIFY_REGION_OR_NONE(pRegion, stuff->region, client, DixWriteAccess);
66005b261ecSmrg    switch (stuff->destKind) {
66105b261ecSmrg    case ShapeBounding:
66205b261ecSmrg    case ShapeClip:
66305b261ecSmrg    case ShapeInput:
66435c4bbdfSmrg        break;
66505b261ecSmrg    default:
66635c4bbdfSmrg        client->errorValue = stuff->destKind;
66735c4bbdfSmrg        return BadValue;
66805b261ecSmrg    }
66935c4bbdfSmrg    if (pRegion) {
67035c4bbdfSmrg        pRegion = XFixesRegionCopy(pRegion);
67135c4bbdfSmrg        if (!pRegion)
67235c4bbdfSmrg            return BadAlloc;
67335c4bbdfSmrg        if (!pWin->optional)
67435c4bbdfSmrg            MakeWindowOptional(pWin);
67535c4bbdfSmrg        switch (stuff->destKind) {
67635c4bbdfSmrg        default:
67735c4bbdfSmrg        case ShapeBounding:
67835c4bbdfSmrg            pDestRegion = &pWin->optional->boundingShape;
67935c4bbdfSmrg            break;
68035c4bbdfSmrg        case ShapeClip:
68135c4bbdfSmrg            pDestRegion = &pWin->optional->clipShape;
68235c4bbdfSmrg            break;
68335c4bbdfSmrg        case ShapeInput:
68435c4bbdfSmrg            pDestRegion = &pWin->optional->inputShape;
68535c4bbdfSmrg            break;
68635c4bbdfSmrg        }
68735c4bbdfSmrg        if (stuff->xOff || stuff->yOff)
68835c4bbdfSmrg            RegionTranslate(pRegion, stuff->xOff, stuff->yOff);
68905b261ecSmrg    }
69035c4bbdfSmrg    else {
69135c4bbdfSmrg        if (pWin->optional) {
69235c4bbdfSmrg            switch (stuff->destKind) {
69335c4bbdfSmrg            default:
69435c4bbdfSmrg            case ShapeBounding:
69535c4bbdfSmrg                pDestRegion = &pWin->optional->boundingShape;
69635c4bbdfSmrg                break;
69735c4bbdfSmrg            case ShapeClip:
69835c4bbdfSmrg                pDestRegion = &pWin->optional->clipShape;
69935c4bbdfSmrg                break;
70035c4bbdfSmrg            case ShapeInput:
70135c4bbdfSmrg                pDestRegion = &pWin->optional->inputShape;
70235c4bbdfSmrg                break;
70335c4bbdfSmrg            }
70435c4bbdfSmrg        }
70535c4bbdfSmrg        else
70635c4bbdfSmrg            pDestRegion = &pRegion;     /* a NULL region pointer */
70705b261ecSmrg    }
70805b261ecSmrg    if (*pDestRegion)
70935c4bbdfSmrg        RegionDestroy(*pDestRegion);
71005b261ecSmrg    *pDestRegion = pRegion;
7116747b715Smrg    (*pWin->drawable.pScreen->SetShape) (pWin, stuff->destKind);
71235c4bbdfSmrg    SendShapeNotify(pWin, stuff->destKind);
7136747b715Smrg    return Success;
71405b261ecSmrg}
71505b261ecSmrg
7167e31ba66Smrgint _X_COLD
71735c4bbdfSmrgSProcXFixesSetWindowShapeRegion(ClientPtr client)
71805b261ecSmrg{
71905b261ecSmrg    REQUEST(xXFixesSetWindowShapeRegionReq);
72005b261ecSmrg
72135c4bbdfSmrg    swaps(&stuff->length);
72205b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesSetWindowShapeRegionReq);
72335c4bbdfSmrg    swapl(&stuff->dest);
72435c4bbdfSmrg    swaps(&stuff->xOff);
72535c4bbdfSmrg    swaps(&stuff->yOff);
72635c4bbdfSmrg    swapl(&stuff->region);
72705b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
72805b261ecSmrg}
72905b261ecSmrg
73005b261ecSmrgint
73135c4bbdfSmrgProcXFixesSetPictureClipRegion(ClientPtr client)
73205b261ecSmrg{
73335c4bbdfSmrg    PicturePtr pPicture;
73435c4bbdfSmrg    RegionPtr pRegion;
73535c4bbdfSmrg
73605b261ecSmrg    REQUEST(xXFixesSetPictureClipRegionReq);
73735c4bbdfSmrg
73835c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesSetPictureClipRegionReq);
7396747b715Smrg    VERIFY_PICTURE(pPicture, stuff->picture, client, DixSetAttrAccess);
74005b261ecSmrg    VERIFY_REGION_OR_NONE(pRegion, stuff->region, client, DixReadAccess);
74135c4bbdfSmrg
74235c4bbdfSmrg    if (!pPicture->pDrawable)
74335c4bbdfSmrg        return RenderErrBase + BadPicture;
74435c4bbdfSmrg
74535c4bbdfSmrg    return SetPictureClipRegion(pPicture, stuff->xOrigin, stuff->yOrigin,
74635c4bbdfSmrg                                pRegion);
74705b261ecSmrg}
74805b261ecSmrg
7497e31ba66Smrgint _X_COLD
75035c4bbdfSmrgSProcXFixesSetPictureClipRegion(ClientPtr client)
75105b261ecSmrg{
75205b261ecSmrg    REQUEST(xXFixesSetPictureClipRegionReq);
75335c4bbdfSmrg
75435c4bbdfSmrg    swaps(&stuff->length);
75535c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesSetPictureClipRegionReq);
75635c4bbdfSmrg    swapl(&stuff->picture);
75735c4bbdfSmrg    swapl(&stuff->region);
75835c4bbdfSmrg    swaps(&stuff->xOrigin);
75935c4bbdfSmrg    swaps(&stuff->yOrigin);
76005b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
76105b261ecSmrg}
76205b261ecSmrg
76305b261ecSmrgint
76435c4bbdfSmrgProcXFixesExpandRegion(ClientPtr client)
76505b261ecSmrg{
76635c4bbdfSmrg    RegionPtr pSource, pDestination;
76705b261ecSmrg
76835c4bbdfSmrg    REQUEST(xXFixesExpandRegionReq);
76935c4bbdfSmrg    BoxPtr pTmp;
77035c4bbdfSmrg    BoxPtr pSrc;
77135c4bbdfSmrg    int nBoxes;
77235c4bbdfSmrg    int i;
77335c4bbdfSmrg
77435c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesExpandRegionReq);
77505b261ecSmrg    VERIFY_REGION(pSource, stuff->source, client, DixReadAccess);
77605b261ecSmrg    VERIFY_REGION(pDestination, stuff->destination, client, DixWriteAccess);
77735c4bbdfSmrg
7786747b715Smrg    nBoxes = RegionNumRects(pSource);
7796747b715Smrg    pSrc = RegionRects(pSource);
78035c4bbdfSmrg    if (nBoxes) {
78135c4bbdfSmrg        pTmp = xallocarray(nBoxes, sizeof(BoxRec));
78235c4bbdfSmrg        if (!pTmp)
78335c4bbdfSmrg            return BadAlloc;
78435c4bbdfSmrg        for (i = 0; i < nBoxes; i++) {
78535c4bbdfSmrg            pTmp[i].x1 = pSrc[i].x1 - stuff->left;
78635c4bbdfSmrg            pTmp[i].x2 = pSrc[i].x2 + stuff->right;
78735c4bbdfSmrg            pTmp[i].y1 = pSrc[i].y1 - stuff->top;
78835c4bbdfSmrg            pTmp[i].y2 = pSrc[i].y2 + stuff->bottom;
78935c4bbdfSmrg        }
79035c4bbdfSmrg        RegionEmpty(pDestination);
79135c4bbdfSmrg        for (i = 0; i < nBoxes; i++) {
79235c4bbdfSmrg            RegionRec r;
79335c4bbdfSmrg
79435c4bbdfSmrg            RegionInit(&r, &pTmp[i], 0);
79535c4bbdfSmrg            RegionUnion(pDestination, pDestination, &r);
79635c4bbdfSmrg        }
79735c4bbdfSmrg        free(pTmp);
79805b261ecSmrg    }
7996747b715Smrg    return Success;
80005b261ecSmrg}
80105b261ecSmrg
8027e31ba66Smrgint _X_COLD
80335c4bbdfSmrgSProcXFixesExpandRegion(ClientPtr client)
80405b261ecSmrg{
80535c4bbdfSmrg    REQUEST(xXFixesExpandRegionReq);
80605b261ecSmrg
80735c4bbdfSmrg    swaps(&stuff->length);
80835c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesExpandRegionReq);
80935c4bbdfSmrg    swapl(&stuff->source);
81035c4bbdfSmrg    swapl(&stuff->destination);
81135c4bbdfSmrg    swaps(&stuff->left);
81235c4bbdfSmrg    swaps(&stuff->right);
81335c4bbdfSmrg    swaps(&stuff->top);
81435c4bbdfSmrg    swaps(&stuff->bottom);
81505b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
81605b261ecSmrg}
81705b261ecSmrg
8189ace9065Smrg#ifdef PANORAMIX
8199ace9065Smrg#include "panoramiX.h"
8209ace9065Smrg#include "panoramiXsrv.h"
8219ace9065Smrg
8229ace9065Smrgint
82335c4bbdfSmrgPanoramiXFixesSetGCClipRegion(ClientPtr client)
8249ace9065Smrg{
8259ace9065Smrg    REQUEST(xXFixesSetGCClipRegionReq);
82635c4bbdfSmrg    int result = Success, j;
82735c4bbdfSmrg    PanoramiXRes *gc;
82835c4bbdfSmrg
8299ace9065Smrg    REQUEST_SIZE_MATCH(xXFixesSetGCClipRegionReq);
8309ace9065Smrg
83135c4bbdfSmrg    if ((result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC,
83235c4bbdfSmrg                                          client, DixWriteAccess))) {
83335c4bbdfSmrg        client->errorValue = stuff->gc;
83435c4bbdfSmrg        return result;
8359ace9065Smrg    }
8369ace9065Smrg
8379ace9065Smrg    FOR_NSCREENS_BACKWARD(j) {
8389ace9065Smrg        stuff->gc = gc->info[j].id;
8399ace9065Smrg        result = (*PanoramiXSaveXFixesVector[X_XFixesSetGCClipRegion]) (client);
84035c4bbdfSmrg        if (result != Success)
84135c4bbdfSmrg            break;
8429ace9065Smrg    }
8439ace9065Smrg
8449ace9065Smrg    return result;
8459ace9065Smrg}
8469ace9065Smrg
8479ace9065Smrgint
84835c4bbdfSmrgPanoramiXFixesSetWindowShapeRegion(ClientPtr client)
8499ace9065Smrg{
85035c4bbdfSmrg    int result = Success, j;
85135c4bbdfSmrg    PanoramiXRes *win;
85235c4bbdfSmrg    RegionPtr reg = NULL;
85335c4bbdfSmrg
8549ace9065Smrg    REQUEST(xXFixesSetWindowShapeRegionReq);
8559ace9065Smrg
8569ace9065Smrg    REQUEST_SIZE_MATCH(xXFixesSetWindowShapeRegionReq);
8579ace9065Smrg
85835c4bbdfSmrg    if ((result = dixLookupResourceByType((void **) &win, stuff->dest,
85935c4bbdfSmrg                                          XRT_WINDOW, client,
86035c4bbdfSmrg                                          DixWriteAccess))) {
86135c4bbdfSmrg        client->errorValue = stuff->dest;
86235c4bbdfSmrg        return result;
8639ace9065Smrg    }
8649ace9065Smrg
86535c4bbdfSmrg    if (win->u.win.root)
86635c4bbdfSmrg        VERIFY_REGION_OR_NONE(reg, stuff->region, client, DixReadAccess);
86735c4bbdfSmrg
8689ace9065Smrg    FOR_NSCREENS_FORWARD(j) {
86935c4bbdfSmrg        ScreenPtr screen = screenInfo.screens[j];
87035c4bbdfSmrg        stuff->dest = win->info[j].id;
87135c4bbdfSmrg
87235c4bbdfSmrg        if (reg)
87335c4bbdfSmrg            RegionTranslate(reg, -screen->x, -screen->y);
87435c4bbdfSmrg
87535c4bbdfSmrg        result =
87635c4bbdfSmrg            (*PanoramiXSaveXFixesVector[X_XFixesSetWindowShapeRegion]) (client);
87735c4bbdfSmrg
87835c4bbdfSmrg        if (reg)
87935c4bbdfSmrg            RegionTranslate(reg, screen->x, screen->y);
88035c4bbdfSmrg
88135c4bbdfSmrg        if (result != Success)
88235c4bbdfSmrg            break;
8839ace9065Smrg    }
8849ace9065Smrg
8859ace9065Smrg    return result;
8869ace9065Smrg}
8879ace9065Smrg
8889ace9065Smrgint
88935c4bbdfSmrgPanoramiXFixesSetPictureClipRegion(ClientPtr client)
8909ace9065Smrg{
8919ace9065Smrg    REQUEST(xXFixesSetPictureClipRegionReq);
89235c4bbdfSmrg    int result = Success, j;
89335c4bbdfSmrg    PanoramiXRes *pict;
89435c4bbdfSmrg    RegionPtr reg = NULL;
8959ace9065Smrg
89635c4bbdfSmrg    REQUEST_SIZE_MATCH(xXFixesSetPictureClipRegionReq);
8979ace9065Smrg
89835c4bbdfSmrg    if ((result = dixLookupResourceByType((void **) &pict, stuff->picture,
89935c4bbdfSmrg                                          XRT_PICTURE, client,
90035c4bbdfSmrg                                          DixWriteAccess))) {
90135c4bbdfSmrg        client->errorValue = stuff->picture;
90235c4bbdfSmrg        return result;
9039ace9065Smrg    }
9049ace9065Smrg
90535c4bbdfSmrg    if (pict->u.pict.root)
90635c4bbdfSmrg        VERIFY_REGION_OR_NONE(reg, stuff->region, client, DixReadAccess);
90735c4bbdfSmrg
9089ace9065Smrg    FOR_NSCREENS_BACKWARD(j) {
90935c4bbdfSmrg        ScreenPtr screen = screenInfo.screens[j];
9109ace9065Smrg        stuff->picture = pict->info[j].id;
91135c4bbdfSmrg
91235c4bbdfSmrg        if (reg)
91335c4bbdfSmrg            RegionTranslate(reg, -screen->x, -screen->y);
91435c4bbdfSmrg
91535c4bbdfSmrg        result =
91635c4bbdfSmrg            (*PanoramiXSaveXFixesVector[X_XFixesSetPictureClipRegion]) (client);
91735c4bbdfSmrg
91835c4bbdfSmrg        if (reg)
91935c4bbdfSmrg            RegionTranslate(reg, screen->x, screen->y);
92035c4bbdfSmrg
92135c4bbdfSmrg        if (result != Success)
92235c4bbdfSmrg            break;
9239ace9065Smrg    }
9249ace9065Smrg
9259ace9065Smrg    return result;
9269ace9065Smrg}
9279ace9065Smrg
9289ace9065Smrg#endif
929