16747b715Smrg/*
235c4bbdfSmrg * Copyright (c) 2009-2012 Apple Inc. All rights reserved.
335c4bbdfSmrg *
435c4bbdfSmrg * Permission is hereby granted, free of charge, to any person
535c4bbdfSmrg * obtaining a copy of this software and associated documentation files
635c4bbdfSmrg * (the "Software"), to deal in the Software without restriction,
735c4bbdfSmrg * including without limitation the rights to use, copy, modify, merge,
835c4bbdfSmrg * publish, distribute, sublicense, and/or sell copies of the Software,
935c4bbdfSmrg * and to permit persons to whom the Software is furnished to do so,
1035c4bbdfSmrg * subject to the following conditions:
1135c4bbdfSmrg *
1235c4bbdfSmrg * The above copyright notice and this permission notice shall be
1335c4bbdfSmrg * included in all copies or substantial portions of the Software.
1435c4bbdfSmrg *
1535c4bbdfSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1635c4bbdfSmrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1735c4bbdfSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1835c4bbdfSmrg * NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
1935c4bbdfSmrg * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
2035c4bbdfSmrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2135c4bbdfSmrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2235c4bbdfSmrg * DEALINGS IN THE SOFTWARE.
2335c4bbdfSmrg *
2435c4bbdfSmrg * Except as contained in this notice, the name(s) of the above
2535c4bbdfSmrg * copyright holders shall not be used in advertising or otherwise to
2635c4bbdfSmrg * promote the sale, use or other dealings in this Software without
2735c4bbdfSmrg * prior written authorization.
2835c4bbdfSmrg */
2935c4bbdfSmrg
306747b715Smrg#ifdef HAVE_DIX_CONFIG_H
316747b715Smrg#include <dix-config.h>
326747b715Smrg#endif
336747b715Smrg
346747b715Smrg#include <stddef.h>
356747b715Smrg#include "mi.h"
366747b715Smrg#include "scrnintstr.h"
376747b715Smrg#include "gcstruct.h"
386747b715Smrg#include "pixmapstr.h"
396747b715Smrg#include "windowstr.h"
406747b715Smrg#include "dixfontstr.h"
416747b715Smrg#include "mivalidate.h"
426747b715Smrg#include "driWrap.h"
436747b715Smrg#include "dri.h"
446747b715Smrg
456747b715Smrg#include <OpenGL/OpenGL.h>
466747b715Smrg
476747b715Smrgtypedef struct {
48c8548ba8Smrg    GCOps const *originalOps;
496747b715Smrg} DRIGCRec;
506747b715Smrg
516747b715Smrgtypedef struct {
526747b715Smrg    GCOps *originalOps;
536747b715Smrg    CreateGCProcPtr CreateGC;
546747b715Smrg} DRIWrapScreenRec;
556747b715Smrg
566747b715Smrgtypedef struct {
576747b715Smrg    Bool didSave;
586747b715Smrg    int devKind;
596747b715Smrg    DevUnion devPrivate;
606747b715Smrg} DRISavedDrawableState;
616747b715Smrg
626747b715Smrgstatic DevPrivateKeyRec driGCKeyRec;
636747b715Smrg#define driGCKey (&driGCKeyRec)
646747b715Smrg
656747b715Smrgstatic DevPrivateKeyRec driWrapScreenKeyRec;
666747b715Smrg#define driWrapScreenKey (&driWrapScreenKeyRec)
676747b715Smrg
686747b715Smrgstatic GCOps driGCOps;
696747b715Smrg
706747b715Smrg#define wrap(priv, real, member, func) { \
7135c4bbdfSmrg        priv->member = real->member; \
7235c4bbdfSmrg        real->member = func; \
7335c4bbdfSmrg}
746747b715Smrg
7535c4bbdfSmrg#define unwrap(priv, real, member)     { \
7635c4bbdfSmrg        real->member = priv->member; \
7735c4bbdfSmrg}
786747b715Smrg
796747b715Smrgstatic DRIGCRec *
8035c4bbdfSmrgDRIGetGCPriv(GCPtr pGC)
8135c4bbdfSmrg{
826747b715Smrg    return dixLookupPrivate(&pGC->devPrivates, driGCKey);
836747b715Smrg}
846747b715Smrg
856747b715Smrgstatic void
8635c4bbdfSmrgDRIUnwrapGC(GCPtr pGC)
8735c4bbdfSmrg{
886747b715Smrg    DRIGCRec *pGCPriv = DRIGetGCPriv(pGC);
896747b715Smrg
906747b715Smrg    pGC->ops = pGCPriv->originalOps;
916747b715Smrg}
926747b715Smrg
9335c4bbdfSmrgstatic void
9435c4bbdfSmrgDRIWrapGC(GCPtr pGC)
9535c4bbdfSmrg{
969ace9065Smrg    pGC->ops = &driGCOps;
976747b715Smrg}
986747b715Smrg
996747b715Smrgstatic void
10035c4bbdfSmrgDRISurfaceSetDrawable(DrawablePtr pDraw,
10135c4bbdfSmrg                      DRISavedDrawableState *saved)
10235c4bbdfSmrg{
1036747b715Smrg    saved->didSave = FALSE;
1046747b715Smrg
10535c4bbdfSmrg    if (pDraw->type == DRAWABLE_PIXMAP) {
10635c4bbdfSmrg        int pitch, width, height, bpp;
10735c4bbdfSmrg        void *buffer;
10835c4bbdfSmrg
10935c4bbdfSmrg        if (DRIGetPixmapData(pDraw, &width, &height, &pitch, &bpp,
11035c4bbdfSmrg                             &buffer)) {
11135c4bbdfSmrg            PixmapPtr pPix = (PixmapPtr)pDraw;
1126747b715Smrg
11335c4bbdfSmrg            saved->devKind = pPix->devKind;
11435c4bbdfSmrg            saved->devPrivate.ptr = pPix->devPrivate.ptr;
11535c4bbdfSmrg            saved->didSave = TRUE;
1166747b715Smrg
11735c4bbdfSmrg            pPix->devKind = pitch;
11835c4bbdfSmrg            pPix->devPrivate.ptr = buffer;
11935c4bbdfSmrg        }
1206747b715Smrg    }
1216747b715Smrg}
1226747b715Smrg
1236747b715Smrgstatic void
1246747b715SmrgDRISurfaceRestoreDrawable(DrawablePtr pDraw,
12535c4bbdfSmrg                          DRISavedDrawableState *saved)
12635c4bbdfSmrg{
1276747b715Smrg    PixmapPtr pPix = (PixmapPtr)pDraw;
1286747b715Smrg
12935c4bbdfSmrg    if (!saved->didSave)
13035c4bbdfSmrg        return;
1316747b715Smrg
1326747b715Smrg    pPix->devKind = saved->devKind;
1336747b715Smrg    pPix->devPrivate.ptr = saved->devPrivate.ptr;
1346747b715Smrg}
1356747b715Smrg
1366747b715Smrgstatic void
1376747b715SmrgDRIFillSpans(DrawablePtr dst, GCPtr pGC, int nInit,
13835c4bbdfSmrg             DDXPointPtr pptInit, int *pwidthInit,
13935c4bbdfSmrg             int sorted)
14035c4bbdfSmrg{
1416747b715Smrg    DRISavedDrawableState saved;
1426747b715Smrg
1436747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
1446747b715Smrg
1456747b715Smrg    DRIUnwrapGC(pGC);
1466747b715Smrg
1476747b715Smrg    pGC->ops->FillSpans(dst, pGC, nInit, pptInit, pwidthInit, sorted);
14835c4bbdfSmrg
1496747b715Smrg    DRIWrapGC(pGC);
15035c4bbdfSmrg
1516747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
1526747b715Smrg}
1536747b715Smrg
1546747b715Smrgstatic void
1556747b715SmrgDRISetSpans(DrawablePtr dst, GCPtr pGC, char *pSrc,
15635c4bbdfSmrg            DDXPointPtr pptInit, int *pwidthInit,
15735c4bbdfSmrg            int nspans, int sorted)
15835c4bbdfSmrg{
1596747b715Smrg    DRISavedDrawableState saved;
16035c4bbdfSmrg
1616747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
1626747b715Smrg
1636747b715Smrg    DRIUnwrapGC(pGC);
16435c4bbdfSmrg
1656747b715Smrg    pGC->ops->SetSpans(dst, pGC, pSrc, pptInit, pwidthInit, nspans, sorted);
1666747b715Smrg
1676747b715Smrg    DRIWrapGC(pGC);
16835c4bbdfSmrg
1696747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
1706747b715Smrg}
1716747b715Smrg
1726747b715Smrgstatic void
1736747b715SmrgDRIPutImage(DrawablePtr dst, GCPtr pGC,
17435c4bbdfSmrg            int depth, int x, int y, int w, int h,
17535c4bbdfSmrg            int leftPad, int format, char *pBits)
17635c4bbdfSmrg{
1776747b715Smrg    DRISavedDrawableState saved;
1786747b715Smrg
1796747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
1806747b715Smrg
1816747b715Smrg    DRIUnwrapGC(pGC);
1826747b715Smrg
1836747b715Smrg    pGC->ops->PutImage(dst, pGC, depth, x, y, w, h, leftPad, format, pBits);
18435c4bbdfSmrg
1856747b715Smrg    DRIWrapGC(pGC);
1866747b715Smrg
1876747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
1886747b715Smrg}
1896747b715Smrg
1906747b715Smrgstatic RegionPtr
1916747b715SmrgDRICopyArea(DrawablePtr pSrc, DrawablePtr dst, GCPtr pGC,
19235c4bbdfSmrg            int srcx, int srcy, int w, int h,
19335c4bbdfSmrg            int dstx, int dsty)
19435c4bbdfSmrg{
1956747b715Smrg    RegionPtr pReg;
1966747b715Smrg    DRISavedDrawableState pSrcSaved, dstSaved;
19735c4bbdfSmrg
1986747b715Smrg    DRISurfaceSetDrawable(pSrc, &pSrcSaved);
1996747b715Smrg    DRISurfaceSetDrawable(dst, &dstSaved);
20035c4bbdfSmrg
2016747b715Smrg    DRIUnwrapGC(pGC);
2026747b715Smrg
2036747b715Smrg    pReg = pGC->ops->CopyArea(pSrc, dst, pGC, srcx, srcy, w, h, dstx, dsty);
2046747b715Smrg
2056747b715Smrg    DRIWrapGC(pGC);
2066747b715Smrg
2076747b715Smrg    DRISurfaceRestoreDrawable(pSrc, &pSrcSaved);
20835c4bbdfSmrg    DRISurfaceRestoreDrawable(dst, &dstSaved);
2096747b715Smrg
2106747b715Smrg    return pReg;
2116747b715Smrg}
2126747b715Smrg
2136747b715Smrgstatic RegionPtr
2146747b715SmrgDRICopyPlane(DrawablePtr pSrc, DrawablePtr dst,
21535c4bbdfSmrg             GCPtr pGC, int srcx, int srcy,
21635c4bbdfSmrg             int w, int h, int dstx, int dsty,
21735c4bbdfSmrg             unsigned long plane)
21835c4bbdfSmrg{
2196747b715Smrg    RegionPtr pReg;
2206747b715Smrg    DRISavedDrawableState pSrcSaved, dstSaved;
2216747b715Smrg
2226747b715Smrg    DRISurfaceSetDrawable(pSrc, &pSrcSaved);
2236747b715Smrg    DRISurfaceSetDrawable(dst, &dstSaved);
2246747b715Smrg
2256747b715Smrg    DRIUnwrapGC(pGC);
22635c4bbdfSmrg
2276747b715Smrg    pReg = pGC->ops->CopyPlane(pSrc, dst, pGC, srcx, srcy, w, h, dstx, dsty,
22835c4bbdfSmrg                               plane);
22935c4bbdfSmrg
2306747b715Smrg    DRIWrapGC(pGC);
2316747b715Smrg
2326747b715Smrg    DRISurfaceRestoreDrawable(pSrc, &pSrcSaved);
2336747b715Smrg    DRISurfaceRestoreDrawable(dst, &dstSaved);
2346747b715Smrg
2356747b715Smrg    return pReg;
2366747b715Smrg}
2376747b715Smrg
2386747b715Smrgstatic void
2396747b715SmrgDRIPolyPoint(DrawablePtr dst, GCPtr pGC,
24035c4bbdfSmrg             int mode, int npt, DDXPointPtr pptInit)
24135c4bbdfSmrg{
2426747b715Smrg    DRISavedDrawableState saved;
24335c4bbdfSmrg
2446747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
24535c4bbdfSmrg
2466747b715Smrg    DRIUnwrapGC(pGC);
24735c4bbdfSmrg
2486747b715Smrg    pGC->ops->PolyPoint(dst, pGC, mode, npt, pptInit);
2496747b715Smrg
2506747b715Smrg    DRIWrapGC(pGC);
2516747b715Smrg
2526747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
2536747b715Smrg}
2546747b715Smrg
2556747b715Smrgstatic void
2566747b715SmrgDRIPolylines(DrawablePtr dst, GCPtr pGC,
25735c4bbdfSmrg             int mode, int npt, DDXPointPtr pptInit)
25835c4bbdfSmrg{
2596747b715Smrg    DRISavedDrawableState saved;
26035c4bbdfSmrg
2616747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
2626747b715Smrg
2636747b715Smrg    DRIUnwrapGC(pGC);
26435c4bbdfSmrg
2656747b715Smrg    pGC->ops->Polylines(dst, pGC, mode, npt, pptInit);
2666747b715Smrg
2676747b715Smrg    DRIWrapGC(pGC);
26835c4bbdfSmrg
2696747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
2706747b715Smrg}
2716747b715Smrg
2726747b715Smrgstatic void
2736747b715SmrgDRIPolySegment(DrawablePtr dst, GCPtr pGC,
27435c4bbdfSmrg               int nseg, xSegment *pSeg)
27535c4bbdfSmrg{
2766747b715Smrg    DRISavedDrawableState saved;
27735c4bbdfSmrg
2786747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
2796747b715Smrg
2806747b715Smrg    DRIUnwrapGC(pGC);
2816747b715Smrg
2826747b715Smrg    pGC->ops->PolySegment(dst, pGC, nseg, pSeg);
28335c4bbdfSmrg
2846747b715Smrg    DRIWrapGC(pGC);
2856747b715Smrg
2866747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
2876747b715Smrg}
2886747b715Smrg
2896747b715Smrgstatic void
2906747b715SmrgDRIPolyRectangle(DrawablePtr dst, GCPtr pGC,
29135c4bbdfSmrg                 int nRects, xRectangle *pRects)
29235c4bbdfSmrg{
2936747b715Smrg    DRISavedDrawableState saved;
29435c4bbdfSmrg
2956747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
29635c4bbdfSmrg
2976747b715Smrg    DRIUnwrapGC(pGC);
29835c4bbdfSmrg
2996747b715Smrg    pGC->ops->PolyRectangle(dst, pGC, nRects, pRects);
30035c4bbdfSmrg
3016747b715Smrg    DRIWrapGC(pGC);
3026747b715Smrg
3036747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
3046747b715Smrg}
3056747b715Smrgstatic void
30635c4bbdfSmrgDRIPolyArc(DrawablePtr dst, GCPtr pGC, int narcs, xArc *parcs)
30735c4bbdfSmrg{
3086747b715Smrg    DRISavedDrawableState saved;
30935c4bbdfSmrg
3106747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
3116747b715Smrg
3126747b715Smrg    DRIUnwrapGC(pGC);
31335c4bbdfSmrg
3146747b715Smrg    pGC->ops->PolyArc(dst, pGC, narcs, parcs);
3156747b715Smrg
3166747b715Smrg    DRIWrapGC(pGC);
31735c4bbdfSmrg
3186747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
3196747b715Smrg}
3206747b715Smrg
3216747b715Smrgstatic void
3226747b715SmrgDRIFillPolygon(DrawablePtr dst, GCPtr pGC,
32335c4bbdfSmrg               int shape, int mode, int count,
32435c4bbdfSmrg               DDXPointPtr pptInit)
32535c4bbdfSmrg{
3266747b715Smrg    DRISavedDrawableState saved;
32735c4bbdfSmrg
3286747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
32935c4bbdfSmrg
3306747b715Smrg    DRIUnwrapGC(pGC);
33135c4bbdfSmrg
3326747b715Smrg    pGC->ops->FillPolygon(dst, pGC, shape, mode, count, pptInit);
3336747b715Smrg
3346747b715Smrg    DRIWrapGC(pGC);
3356747b715Smrg
3366747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
3376747b715Smrg}
3386747b715Smrg
3396747b715Smrgstatic void
3406747b715SmrgDRIPolyFillRect(DrawablePtr dst, GCPtr pGC,
34135c4bbdfSmrg                int nRectsInit, xRectangle *pRectsInit)
34235c4bbdfSmrg{
3436747b715Smrg    DRISavedDrawableState saved;
34435c4bbdfSmrg
3456747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
3466747b715Smrg
3476747b715Smrg    DRIUnwrapGC(pGC);
3486747b715Smrg
3496747b715Smrg    pGC->ops->PolyFillRect(dst, pGC, nRectsInit, pRectsInit);
35035c4bbdfSmrg
3516747b715Smrg    DRIWrapGC(pGC);
3526747b715Smrg
3536747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
3546747b715Smrg}
3556747b715Smrg
3566747b715Smrgstatic void
3576747b715SmrgDRIPolyFillArc(DrawablePtr dst, GCPtr pGC,
35835c4bbdfSmrg               int narcsInit, xArc *parcsInit)
35935c4bbdfSmrg{
3606747b715Smrg    DRISavedDrawableState saved;
36135c4bbdfSmrg
3626747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
3636747b715Smrg
3646747b715Smrg    DRIUnwrapGC(pGC);
3656747b715Smrg
3666747b715Smrg    pGC->ops->PolyFillArc(dst, pGC, narcsInit, parcsInit);
36735c4bbdfSmrg
3686747b715Smrg    DRIWrapGC(pGC);
3696747b715Smrg
3706747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
3716747b715Smrg}
3726747b715Smrg
3736747b715Smrgstatic int
3746747b715SmrgDRIPolyText8(DrawablePtr dst, GCPtr pGC,
37535c4bbdfSmrg             int x, int y, int count, char *chars)
37635c4bbdfSmrg{
3776747b715Smrg    int ret;
3786747b715Smrg    DRISavedDrawableState saved;
37935c4bbdfSmrg
3806747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
3816747b715Smrg
3826747b715Smrg    DRIUnwrapGC(pGC);
38335c4bbdfSmrg
3846747b715Smrg    ret = pGC->ops->PolyText8(dst, pGC, x, y, count, chars);
38535c4bbdfSmrg
3866747b715Smrg    DRIWrapGC(pGC);
38735c4bbdfSmrg
3886747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
3896747b715Smrg
3906747b715Smrg    return ret;
3916747b715Smrg}
3926747b715Smrg
3936747b715Smrgstatic int
3946747b715SmrgDRIPolyText16(DrawablePtr dst, GCPtr pGC,
39535c4bbdfSmrg              int x, int y, int count, unsigned short *chars)
39635c4bbdfSmrg{
3976747b715Smrg    int ret;
3986747b715Smrg    DRISavedDrawableState saved;
39935c4bbdfSmrg
4006747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
4016747b715Smrg
4026747b715Smrg    DRIUnwrapGC(pGC);
40335c4bbdfSmrg
4046747b715Smrg    ret = pGC->ops->PolyText16(dst, pGC, x, y, count, chars);
4056747b715Smrg
4066747b715Smrg    DRIWrapGC(pGC);
40735c4bbdfSmrg
4086747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
4096747b715Smrg
4106747b715Smrg    return ret;
4116747b715Smrg}
4126747b715Smrg
4136747b715Smrgstatic void
4146747b715SmrgDRIImageText8(DrawablePtr dst, GCPtr pGC,
41535c4bbdfSmrg              int x, int y, int count, char *chars)
41635c4bbdfSmrg{
4176747b715Smrg    DRISavedDrawableState saved;
41835c4bbdfSmrg
4196747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
4206747b715Smrg
4216747b715Smrg    DRIUnwrapGC(pGC);
42235c4bbdfSmrg
4236747b715Smrg    pGC->ops->ImageText8(dst, pGC, x, y, count, chars);
4246747b715Smrg
4256747b715Smrg    DRIWrapGC(pGC);
42635c4bbdfSmrg
4276747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
4286747b715Smrg}
4296747b715Smrg
4306747b715Smrgstatic void
4316747b715SmrgDRIImageText16(DrawablePtr dst, GCPtr pGC,
43235c4bbdfSmrg               int x, int y, int count, unsigned short *chars)
43335c4bbdfSmrg{
4346747b715Smrg    DRISavedDrawableState saved;
43535c4bbdfSmrg
4366747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
4376747b715Smrg
4386747b715Smrg    DRIUnwrapGC(pGC);
4396747b715Smrg
4406747b715Smrg    pGC->ops->ImageText16(dst, pGC, x, y, count, chars);
44135c4bbdfSmrg
4426747b715Smrg    DRIWrapGC(pGC);
4436747b715Smrg
4446747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
4456747b715Smrg}
4466747b715Smrg
4476747b715Smrgstatic void
4486747b715SmrgDRIImageGlyphBlt(DrawablePtr dst, GCPtr pGC,
44935c4bbdfSmrg                 int x, int y, unsigned int nglyphInit,
45035c4bbdfSmrg                 CharInfoPtr *ppciInit, void *unused)
45135c4bbdfSmrg{
4526747b715Smrg    DRISavedDrawableState saved;
45335c4bbdfSmrg
4546747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
4556747b715Smrg
4566747b715Smrg    DRIUnwrapGC(pGC);
4576747b715Smrg
4586747b715Smrg    pGC->ops->ImageGlyphBlt(dst, pGC, x, y, nglyphInit, ppciInit, unused);
45935c4bbdfSmrg
4606747b715Smrg    DRIWrapGC(pGC);
4616747b715Smrg
4626747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
4636747b715Smrg}
4646747b715Smrg
46535c4bbdfSmrgstatic void
46635c4bbdfSmrgDRIPolyGlyphBlt(DrawablePtr dst, GCPtr pGC,
46735c4bbdfSmrg                int x, int y, unsigned int nglyph,
46835c4bbdfSmrg                CharInfoPtr *ppci, void *pglyphBase)
46935c4bbdfSmrg{
4706747b715Smrg    DRISavedDrawableState saved;
47135c4bbdfSmrg
4726747b715Smrg    DRISurfaceSetDrawable(dst, &saved);
4736747b715Smrg
4746747b715Smrg    DRIUnwrapGC(pGC);
4756747b715Smrg
4766747b715Smrg    pGC->ops->PolyGlyphBlt(dst, pGC, x, y, nglyph, ppci, pglyphBase);
47735c4bbdfSmrg
4786747b715Smrg    DRIWrapGC(pGC);
4796747b715Smrg
4806747b715Smrg    DRISurfaceRestoreDrawable(dst, &saved);
4816747b715Smrg}
4826747b715Smrg
4836747b715Smrgstatic void
4846747b715SmrgDRIPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr dst,
48535c4bbdfSmrg              int dx, int dy, int xOrg, int yOrg)
48635c4bbdfSmrg{
4876747b715Smrg    DRISavedDrawableState bitMapSaved, dstSaved;
48835c4bbdfSmrg
4896747b715Smrg    DRISurfaceSetDrawable(&pBitMap->drawable, &bitMapSaved);
4906747b715Smrg    DRISurfaceSetDrawable(dst, &dstSaved);
4916747b715Smrg
4926747b715Smrg    DRIUnwrapGC(pGC);
4936747b715Smrg
4946747b715Smrg    pGC->ops->PushPixels(pGC, pBitMap, dst, dx, dy, xOrg, yOrg);
49535c4bbdfSmrg
4966747b715Smrg    DRIWrapGC(pGC);
4976747b715Smrg
4986747b715Smrg    DRISurfaceRestoreDrawable(&pBitMap->drawable, &bitMapSaved);
4996747b715Smrg    DRISurfaceRestoreDrawable(dst, &dstSaved);
5006747b715Smrg}
5016747b715Smrg
5026747b715Smrgstatic GCOps driGCOps = {
5036747b715Smrg    DRIFillSpans,
5046747b715Smrg    DRISetSpans,
5056747b715Smrg    DRIPutImage,
5066747b715Smrg    DRICopyArea,
5076747b715Smrg    DRICopyPlane,
5086747b715Smrg    DRIPolyPoint,
5096747b715Smrg    DRIPolylines,
5106747b715Smrg    DRIPolySegment,
5116747b715Smrg    DRIPolyRectangle,
5126747b715Smrg    DRIPolyArc,
5136747b715Smrg    DRIFillPolygon,
5146747b715Smrg    DRIPolyFillRect,
5156747b715Smrg    DRIPolyFillArc,
5166747b715Smrg    DRIPolyText8,
5176747b715Smrg    DRIPolyText16,
5186747b715Smrg    DRIImageText8,
5196747b715Smrg    DRIImageText16,
5206747b715Smrg    DRIImageGlyphBlt,
5216747b715Smrg    DRIPolyGlyphBlt,
5226747b715Smrg    DRIPushPixels
5236747b715Smrg};
5246747b715Smrg
5256747b715Smrgstatic Bool
52635c4bbdfSmrgDRICreateGC(GCPtr pGC)
52735c4bbdfSmrg{
5286747b715Smrg    ScreenPtr pScreen = pGC->pScreen;
5296747b715Smrg    DRIWrapScreenRec *pScreenPriv;
5306747b715Smrg    DRIGCRec *pGCPriv;
5316747b715Smrg    Bool ret;
5326747b715Smrg
5336747b715Smrg    pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, driWrapScreenKey);
53435c4bbdfSmrg
5356747b715Smrg    pGCPriv = DRIGetGCPriv(pGC);
5366747b715Smrg
5376747b715Smrg    unwrap(pScreenPriv, pScreen, CreateGC);
5386747b715Smrg    ret = pScreen->CreateGC(pGC);
5396747b715Smrg
54035c4bbdfSmrg    if (ret) {
54135c4bbdfSmrg        pGCPriv->originalOps = pGC->ops;
54235c4bbdfSmrg        pGC->ops = &driGCOps;
5436747b715Smrg    }
5446747b715Smrg
5456747b715Smrg    wrap(pScreenPriv, pScreen, CreateGC, DRICreateGC);
54635c4bbdfSmrg
5476747b715Smrg    return ret;
5486747b715Smrg}
5496747b715Smrg
5506747b715Smrg/* Return false if an error occurred. */
55135c4bbdfSmrgBool
55235c4bbdfSmrgDRIWrapInit(ScreenPtr pScreen)
55335c4bbdfSmrg{
5546747b715Smrg    DRIWrapScreenRec *pScreenPriv;
5556747b715Smrg
55635c4bbdfSmrg    if (!dixRegisterPrivateKey(&driGCKeyRec, PRIVATE_GC, sizeof(DRIGCRec)))
55735c4bbdfSmrg        return FALSE;
5586747b715Smrg
55935c4bbdfSmrg    if (!dixRegisterPrivateKey(&driWrapScreenKeyRec, PRIVATE_SCREEN,
56035c4bbdfSmrg                               sizeof(DRIWrapScreenRec)))
56135c4bbdfSmrg        return FALSE;
5626747b715Smrg
56335c4bbdfSmrg    pScreenPriv = dixGetPrivateAddr(&pScreen->devPrivates,
56435c4bbdfSmrg                                    &driWrapScreenKeyRec);
5656747b715Smrg    pScreenPriv->CreateGC = pScreen->CreateGC;
5666747b715Smrg    pScreen->CreateGC = DRICreateGC;
56735c4bbdfSmrg
5686747b715Smrg    return TRUE;
5696747b715Smrg}
570