1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (c) 2009-2012 Apple Inc. All rights reserved.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person
5*4882a593Smuzhiyun * obtaining a copy of this software and associated documentation files
6*4882a593Smuzhiyun * (the "Software"), to deal in the Software without restriction,
7*4882a593Smuzhiyun * including without limitation the rights to use, copy, modify, merge,
8*4882a593Smuzhiyun * publish, distribute, sublicense, and/or sell copies of the Software,
9*4882a593Smuzhiyun * and to permit persons to whom the Software is furnished to do so,
10*4882a593Smuzhiyun * subject to the following conditions:
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be
13*4882a593Smuzhiyun * included in all copies or substantial portions of the Software.
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16*4882a593Smuzhiyun * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18*4882a593Smuzhiyun * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
19*4882a593Smuzhiyun * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20*4882a593Smuzhiyun * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21*4882a593Smuzhiyun * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22*4882a593Smuzhiyun * DEALINGS IN THE SOFTWARE.
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * Except as contained in this notice, the name(s) of the above
25*4882a593Smuzhiyun * copyright holders shall not be used in advertising or otherwise to
26*4882a593Smuzhiyun * promote the sale, use or other dealings in this Software without
27*4882a593Smuzhiyun * prior written authorization.
28*4882a593Smuzhiyun */
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
31*4882a593Smuzhiyun #include <dix-config.h>
32*4882a593Smuzhiyun #endif
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #include <stddef.h>
35*4882a593Smuzhiyun #include "mi.h"
36*4882a593Smuzhiyun #include "scrnintstr.h"
37*4882a593Smuzhiyun #include "gcstruct.h"
38*4882a593Smuzhiyun #include "pixmapstr.h"
39*4882a593Smuzhiyun #include "windowstr.h"
40*4882a593Smuzhiyun #include "dixfontstr.h"
41*4882a593Smuzhiyun #include "mivalidate.h"
42*4882a593Smuzhiyun #include "driWrap.h"
43*4882a593Smuzhiyun #include "dri.h"
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun #include <OpenGL/OpenGL.h>
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun typedef struct {
48*4882a593Smuzhiyun GCOps const *originalOps;
49*4882a593Smuzhiyun } DRIGCRec;
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun typedef struct {
52*4882a593Smuzhiyun GCOps *originalOps;
53*4882a593Smuzhiyun CreateGCProcPtr CreateGC;
54*4882a593Smuzhiyun } DRIWrapScreenRec;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun typedef struct {
57*4882a593Smuzhiyun Bool didSave;
58*4882a593Smuzhiyun int devKind;
59*4882a593Smuzhiyun DevUnion devPrivate;
60*4882a593Smuzhiyun } DRISavedDrawableState;
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun static DevPrivateKeyRec driGCKeyRec;
63*4882a593Smuzhiyun #define driGCKey (&driGCKeyRec)
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun static DevPrivateKeyRec driWrapScreenKeyRec;
66*4882a593Smuzhiyun #define driWrapScreenKey (&driWrapScreenKeyRec)
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun static GCOps driGCOps;
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun #define wrap(priv, real, member, func) { \
71*4882a593Smuzhiyun priv->member = real->member; \
72*4882a593Smuzhiyun real->member = func; \
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun #define unwrap(priv, real, member) { \
76*4882a593Smuzhiyun real->member = priv->member; \
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun static DRIGCRec *
DRIGetGCPriv(GCPtr pGC)80*4882a593Smuzhiyun DRIGetGCPriv(GCPtr pGC)
81*4882a593Smuzhiyun {
82*4882a593Smuzhiyun return dixLookupPrivate(&pGC->devPrivates, driGCKey);
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun static void
DRIUnwrapGC(GCPtr pGC)86*4882a593Smuzhiyun DRIUnwrapGC(GCPtr pGC)
87*4882a593Smuzhiyun {
88*4882a593Smuzhiyun DRIGCRec *pGCPriv = DRIGetGCPriv(pGC);
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun pGC->ops = pGCPriv->originalOps;
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun static void
DRIWrapGC(GCPtr pGC)94*4882a593Smuzhiyun DRIWrapGC(GCPtr pGC)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun pGC->ops = &driGCOps;
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun static void
DRISurfaceSetDrawable(DrawablePtr pDraw,DRISavedDrawableState * saved)100*4882a593Smuzhiyun DRISurfaceSetDrawable(DrawablePtr pDraw,
101*4882a593Smuzhiyun DRISavedDrawableState *saved)
102*4882a593Smuzhiyun {
103*4882a593Smuzhiyun saved->didSave = FALSE;
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun if (pDraw->type == DRAWABLE_PIXMAP) {
106*4882a593Smuzhiyun int pitch, width, height, bpp;
107*4882a593Smuzhiyun void *buffer;
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun if (DRIGetPixmapData(pDraw, &width, &height, &pitch, &bpp,
110*4882a593Smuzhiyun &buffer)) {
111*4882a593Smuzhiyun PixmapPtr pPix = (PixmapPtr)pDraw;
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun saved->devKind = pPix->devKind;
114*4882a593Smuzhiyun saved->devPrivate.ptr = pPix->devPrivate.ptr;
115*4882a593Smuzhiyun saved->didSave = TRUE;
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun pPix->devKind = pitch;
118*4882a593Smuzhiyun pPix->devPrivate.ptr = buffer;
119*4882a593Smuzhiyun }
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun static void
DRISurfaceRestoreDrawable(DrawablePtr pDraw,DRISavedDrawableState * saved)124*4882a593Smuzhiyun DRISurfaceRestoreDrawable(DrawablePtr pDraw,
125*4882a593Smuzhiyun DRISavedDrawableState *saved)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun PixmapPtr pPix = (PixmapPtr)pDraw;
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun if (!saved->didSave)
130*4882a593Smuzhiyun return;
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun pPix->devKind = saved->devKind;
133*4882a593Smuzhiyun pPix->devPrivate.ptr = saved->devPrivate.ptr;
134*4882a593Smuzhiyun }
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun static void
DRIFillSpans(DrawablePtr dst,GCPtr pGC,int nInit,DDXPointPtr pptInit,int * pwidthInit,int sorted)137*4882a593Smuzhiyun DRIFillSpans(DrawablePtr dst, GCPtr pGC, int nInit,
138*4882a593Smuzhiyun DDXPointPtr pptInit, int *pwidthInit,
139*4882a593Smuzhiyun int sorted)
140*4882a593Smuzhiyun {
141*4882a593Smuzhiyun DRISavedDrawableState saved;
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun DRIUnwrapGC(pGC);
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun pGC->ops->FillSpans(dst, pGC, nInit, pptInit, pwidthInit, sorted);
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun DRIWrapGC(pGC);
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
152*4882a593Smuzhiyun }
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun static void
DRISetSpans(DrawablePtr dst,GCPtr pGC,char * pSrc,DDXPointPtr pptInit,int * pwidthInit,int nspans,int sorted)155*4882a593Smuzhiyun DRISetSpans(DrawablePtr dst, GCPtr pGC, char *pSrc,
156*4882a593Smuzhiyun DDXPointPtr pptInit, int *pwidthInit,
157*4882a593Smuzhiyun int nspans, int sorted)
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun DRISavedDrawableState saved;
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun DRIUnwrapGC(pGC);
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun pGC->ops->SetSpans(dst, pGC, pSrc, pptInit, pwidthInit, nspans, sorted);
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun DRIWrapGC(pGC);
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
170*4882a593Smuzhiyun }
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun static void
DRIPutImage(DrawablePtr dst,GCPtr pGC,int depth,int x,int y,int w,int h,int leftPad,int format,char * pBits)173*4882a593Smuzhiyun DRIPutImage(DrawablePtr dst, GCPtr pGC,
174*4882a593Smuzhiyun int depth, int x, int y, int w, int h,
175*4882a593Smuzhiyun int leftPad, int format, char *pBits)
176*4882a593Smuzhiyun {
177*4882a593Smuzhiyun DRISavedDrawableState saved;
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun DRIUnwrapGC(pGC);
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun pGC->ops->PutImage(dst, pGC, depth, x, y, w, h, leftPad, format, pBits);
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun DRIWrapGC(pGC);
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun static RegionPtr
DRICopyArea(DrawablePtr pSrc,DrawablePtr dst,GCPtr pGC,int srcx,int srcy,int w,int h,int dstx,int dsty)191*4882a593Smuzhiyun DRICopyArea(DrawablePtr pSrc, DrawablePtr dst, GCPtr pGC,
192*4882a593Smuzhiyun int srcx, int srcy, int w, int h,
193*4882a593Smuzhiyun int dstx, int dsty)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun RegionPtr pReg;
196*4882a593Smuzhiyun DRISavedDrawableState pSrcSaved, dstSaved;
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun DRISurfaceSetDrawable(pSrc, &pSrcSaved);
199*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &dstSaved);
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun DRIUnwrapGC(pGC);
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun pReg = pGC->ops->CopyArea(pSrc, dst, pGC, srcx, srcy, w, h, dstx, dsty);
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun DRIWrapGC(pGC);
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun DRISurfaceRestoreDrawable(pSrc, &pSrcSaved);
208*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &dstSaved);
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun return pReg;
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun static RegionPtr
DRICopyPlane(DrawablePtr pSrc,DrawablePtr dst,GCPtr pGC,int srcx,int srcy,int w,int h,int dstx,int dsty,unsigned long plane)214*4882a593Smuzhiyun DRICopyPlane(DrawablePtr pSrc, DrawablePtr dst,
215*4882a593Smuzhiyun GCPtr pGC, int srcx, int srcy,
216*4882a593Smuzhiyun int w, int h, int dstx, int dsty,
217*4882a593Smuzhiyun unsigned long plane)
218*4882a593Smuzhiyun {
219*4882a593Smuzhiyun RegionPtr pReg;
220*4882a593Smuzhiyun DRISavedDrawableState pSrcSaved, dstSaved;
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun DRISurfaceSetDrawable(pSrc, &pSrcSaved);
223*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &dstSaved);
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun DRIUnwrapGC(pGC);
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun pReg = pGC->ops->CopyPlane(pSrc, dst, pGC, srcx, srcy, w, h, dstx, dsty,
228*4882a593Smuzhiyun plane);
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun DRIWrapGC(pGC);
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun DRISurfaceRestoreDrawable(pSrc, &pSrcSaved);
233*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &dstSaved);
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun return pReg;
236*4882a593Smuzhiyun }
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun static void
DRIPolyPoint(DrawablePtr dst,GCPtr pGC,int mode,int npt,DDXPointPtr pptInit)239*4882a593Smuzhiyun DRIPolyPoint(DrawablePtr dst, GCPtr pGC,
240*4882a593Smuzhiyun int mode, int npt, DDXPointPtr pptInit)
241*4882a593Smuzhiyun {
242*4882a593Smuzhiyun DRISavedDrawableState saved;
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun DRIUnwrapGC(pGC);
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun pGC->ops->PolyPoint(dst, pGC, mode, npt, pptInit);
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun DRIWrapGC(pGC);
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun static void
DRIPolylines(DrawablePtr dst,GCPtr pGC,int mode,int npt,DDXPointPtr pptInit)256*4882a593Smuzhiyun DRIPolylines(DrawablePtr dst, GCPtr pGC,
257*4882a593Smuzhiyun int mode, int npt, DDXPointPtr pptInit)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun DRISavedDrawableState saved;
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun DRIUnwrapGC(pGC);
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun pGC->ops->Polylines(dst, pGC, mode, npt, pptInit);
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun DRIWrapGC(pGC);
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun static void
DRIPolySegment(DrawablePtr dst,GCPtr pGC,int nseg,xSegment * pSeg)273*4882a593Smuzhiyun DRIPolySegment(DrawablePtr dst, GCPtr pGC,
274*4882a593Smuzhiyun int nseg, xSegment *pSeg)
275*4882a593Smuzhiyun {
276*4882a593Smuzhiyun DRISavedDrawableState saved;
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun DRIUnwrapGC(pGC);
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun pGC->ops->PolySegment(dst, pGC, nseg, pSeg);
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun DRIWrapGC(pGC);
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
287*4882a593Smuzhiyun }
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun static void
DRIPolyRectangle(DrawablePtr dst,GCPtr pGC,int nRects,xRectangle * pRects)290*4882a593Smuzhiyun DRIPolyRectangle(DrawablePtr dst, GCPtr pGC,
291*4882a593Smuzhiyun int nRects, xRectangle *pRects)
292*4882a593Smuzhiyun {
293*4882a593Smuzhiyun DRISavedDrawableState saved;
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun DRIUnwrapGC(pGC);
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun pGC->ops->PolyRectangle(dst, pGC, nRects, pRects);
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun DRIWrapGC(pGC);
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
304*4882a593Smuzhiyun }
305*4882a593Smuzhiyun static void
DRIPolyArc(DrawablePtr dst,GCPtr pGC,int narcs,xArc * parcs)306*4882a593Smuzhiyun DRIPolyArc(DrawablePtr dst, GCPtr pGC, int narcs, xArc *parcs)
307*4882a593Smuzhiyun {
308*4882a593Smuzhiyun DRISavedDrawableState saved;
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun DRIUnwrapGC(pGC);
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun pGC->ops->PolyArc(dst, pGC, narcs, parcs);
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun DRIWrapGC(pGC);
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
319*4882a593Smuzhiyun }
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun static void
DRIFillPolygon(DrawablePtr dst,GCPtr pGC,int shape,int mode,int count,DDXPointPtr pptInit)322*4882a593Smuzhiyun DRIFillPolygon(DrawablePtr dst, GCPtr pGC,
323*4882a593Smuzhiyun int shape, int mode, int count,
324*4882a593Smuzhiyun DDXPointPtr pptInit)
325*4882a593Smuzhiyun {
326*4882a593Smuzhiyun DRISavedDrawableState saved;
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun DRIUnwrapGC(pGC);
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun pGC->ops->FillPolygon(dst, pGC, shape, mode, count, pptInit);
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun DRIWrapGC(pGC);
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
337*4882a593Smuzhiyun }
338*4882a593Smuzhiyun
339*4882a593Smuzhiyun static void
DRIPolyFillRect(DrawablePtr dst,GCPtr pGC,int nRectsInit,xRectangle * pRectsInit)340*4882a593Smuzhiyun DRIPolyFillRect(DrawablePtr dst, GCPtr pGC,
341*4882a593Smuzhiyun int nRectsInit, xRectangle *pRectsInit)
342*4882a593Smuzhiyun {
343*4882a593Smuzhiyun DRISavedDrawableState saved;
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun DRIUnwrapGC(pGC);
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun pGC->ops->PolyFillRect(dst, pGC, nRectsInit, pRectsInit);
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun DRIWrapGC(pGC);
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
354*4882a593Smuzhiyun }
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun static void
DRIPolyFillArc(DrawablePtr dst,GCPtr pGC,int narcsInit,xArc * parcsInit)357*4882a593Smuzhiyun DRIPolyFillArc(DrawablePtr dst, GCPtr pGC,
358*4882a593Smuzhiyun int narcsInit, xArc *parcsInit)
359*4882a593Smuzhiyun {
360*4882a593Smuzhiyun DRISavedDrawableState saved;
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun DRIUnwrapGC(pGC);
365*4882a593Smuzhiyun
366*4882a593Smuzhiyun pGC->ops->PolyFillArc(dst, pGC, narcsInit, parcsInit);
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun DRIWrapGC(pGC);
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun static int
DRIPolyText8(DrawablePtr dst,GCPtr pGC,int x,int y,int count,char * chars)374*4882a593Smuzhiyun DRIPolyText8(DrawablePtr dst, GCPtr pGC,
375*4882a593Smuzhiyun int x, int y, int count, char *chars)
376*4882a593Smuzhiyun {
377*4882a593Smuzhiyun int ret;
378*4882a593Smuzhiyun DRISavedDrawableState saved;
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun DRIUnwrapGC(pGC);
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun ret = pGC->ops->PolyText8(dst, pGC, x, y, count, chars);
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun DRIWrapGC(pGC);
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun return ret;
391*4882a593Smuzhiyun }
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun static int
DRIPolyText16(DrawablePtr dst,GCPtr pGC,int x,int y,int count,unsigned short * chars)394*4882a593Smuzhiyun DRIPolyText16(DrawablePtr dst, GCPtr pGC,
395*4882a593Smuzhiyun int x, int y, int count, unsigned short *chars)
396*4882a593Smuzhiyun {
397*4882a593Smuzhiyun int ret;
398*4882a593Smuzhiyun DRISavedDrawableState saved;
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun DRIUnwrapGC(pGC);
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun ret = pGC->ops->PolyText16(dst, pGC, x, y, count, chars);
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun DRIWrapGC(pGC);
407*4882a593Smuzhiyun
408*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun return ret;
411*4882a593Smuzhiyun }
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun static void
DRIImageText8(DrawablePtr dst,GCPtr pGC,int x,int y,int count,char * chars)414*4882a593Smuzhiyun DRIImageText8(DrawablePtr dst, GCPtr pGC,
415*4882a593Smuzhiyun int x, int y, int count, char *chars)
416*4882a593Smuzhiyun {
417*4882a593Smuzhiyun DRISavedDrawableState saved;
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun DRIUnwrapGC(pGC);
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun pGC->ops->ImageText8(dst, pGC, x, y, count, chars);
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun DRIWrapGC(pGC);
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
428*4882a593Smuzhiyun }
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun static void
DRIImageText16(DrawablePtr dst,GCPtr pGC,int x,int y,int count,unsigned short * chars)431*4882a593Smuzhiyun DRIImageText16(DrawablePtr dst, GCPtr pGC,
432*4882a593Smuzhiyun int x, int y, int count, unsigned short *chars)
433*4882a593Smuzhiyun {
434*4882a593Smuzhiyun DRISavedDrawableState saved;
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun DRIUnwrapGC(pGC);
439*4882a593Smuzhiyun
440*4882a593Smuzhiyun pGC->ops->ImageText16(dst, pGC, x, y, count, chars);
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun DRIWrapGC(pGC);
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
445*4882a593Smuzhiyun }
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun static void
DRIImageGlyphBlt(DrawablePtr dst,GCPtr pGC,int x,int y,unsigned int nglyphInit,CharInfoPtr * ppciInit,void * unused)448*4882a593Smuzhiyun DRIImageGlyphBlt(DrawablePtr dst, GCPtr pGC,
449*4882a593Smuzhiyun int x, int y, unsigned int nglyphInit,
450*4882a593Smuzhiyun CharInfoPtr *ppciInit, void *unused)
451*4882a593Smuzhiyun {
452*4882a593Smuzhiyun DRISavedDrawableState saved;
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun DRIUnwrapGC(pGC);
457*4882a593Smuzhiyun
458*4882a593Smuzhiyun pGC->ops->ImageGlyphBlt(dst, pGC, x, y, nglyphInit, ppciInit, unused);
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun DRIWrapGC(pGC);
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
463*4882a593Smuzhiyun }
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun static void
DRIPolyGlyphBlt(DrawablePtr dst,GCPtr pGC,int x,int y,unsigned int nglyph,CharInfoPtr * ppci,void * pglyphBase)466*4882a593Smuzhiyun DRIPolyGlyphBlt(DrawablePtr dst, GCPtr pGC,
467*4882a593Smuzhiyun int x, int y, unsigned int nglyph,
468*4882a593Smuzhiyun CharInfoPtr *ppci, void *pglyphBase)
469*4882a593Smuzhiyun {
470*4882a593Smuzhiyun DRISavedDrawableState saved;
471*4882a593Smuzhiyun
472*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &saved);
473*4882a593Smuzhiyun
474*4882a593Smuzhiyun DRIUnwrapGC(pGC);
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun pGC->ops->PolyGlyphBlt(dst, pGC, x, y, nglyph, ppci, pglyphBase);
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun DRIWrapGC(pGC);
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &saved);
481*4882a593Smuzhiyun }
482*4882a593Smuzhiyun
483*4882a593Smuzhiyun static void
DRIPushPixels(GCPtr pGC,PixmapPtr pBitMap,DrawablePtr dst,int dx,int dy,int xOrg,int yOrg)484*4882a593Smuzhiyun DRIPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr dst,
485*4882a593Smuzhiyun int dx, int dy, int xOrg, int yOrg)
486*4882a593Smuzhiyun {
487*4882a593Smuzhiyun DRISavedDrawableState bitMapSaved, dstSaved;
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun DRISurfaceSetDrawable(&pBitMap->drawable, &bitMapSaved);
490*4882a593Smuzhiyun DRISurfaceSetDrawable(dst, &dstSaved);
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun DRIUnwrapGC(pGC);
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun pGC->ops->PushPixels(pGC, pBitMap, dst, dx, dy, xOrg, yOrg);
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun DRIWrapGC(pGC);
497*4882a593Smuzhiyun
498*4882a593Smuzhiyun DRISurfaceRestoreDrawable(&pBitMap->drawable, &bitMapSaved);
499*4882a593Smuzhiyun DRISurfaceRestoreDrawable(dst, &dstSaved);
500*4882a593Smuzhiyun }
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun static GCOps driGCOps = {
503*4882a593Smuzhiyun DRIFillSpans,
504*4882a593Smuzhiyun DRISetSpans,
505*4882a593Smuzhiyun DRIPutImage,
506*4882a593Smuzhiyun DRICopyArea,
507*4882a593Smuzhiyun DRICopyPlane,
508*4882a593Smuzhiyun DRIPolyPoint,
509*4882a593Smuzhiyun DRIPolylines,
510*4882a593Smuzhiyun DRIPolySegment,
511*4882a593Smuzhiyun DRIPolyRectangle,
512*4882a593Smuzhiyun DRIPolyArc,
513*4882a593Smuzhiyun DRIFillPolygon,
514*4882a593Smuzhiyun DRIPolyFillRect,
515*4882a593Smuzhiyun DRIPolyFillArc,
516*4882a593Smuzhiyun DRIPolyText8,
517*4882a593Smuzhiyun DRIPolyText16,
518*4882a593Smuzhiyun DRIImageText8,
519*4882a593Smuzhiyun DRIImageText16,
520*4882a593Smuzhiyun DRIImageGlyphBlt,
521*4882a593Smuzhiyun DRIPolyGlyphBlt,
522*4882a593Smuzhiyun DRIPushPixels
523*4882a593Smuzhiyun };
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun static Bool
DRICreateGC(GCPtr pGC)526*4882a593Smuzhiyun DRICreateGC(GCPtr pGC)
527*4882a593Smuzhiyun {
528*4882a593Smuzhiyun ScreenPtr pScreen = pGC->pScreen;
529*4882a593Smuzhiyun DRIWrapScreenRec *pScreenPriv;
530*4882a593Smuzhiyun DRIGCRec *pGCPriv;
531*4882a593Smuzhiyun Bool ret;
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, driWrapScreenKey);
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun pGCPriv = DRIGetGCPriv(pGC);
536*4882a593Smuzhiyun
537*4882a593Smuzhiyun unwrap(pScreenPriv, pScreen, CreateGC);
538*4882a593Smuzhiyun ret = pScreen->CreateGC(pGC);
539*4882a593Smuzhiyun
540*4882a593Smuzhiyun if (ret) {
541*4882a593Smuzhiyun pGCPriv->originalOps = pGC->ops;
542*4882a593Smuzhiyun pGC->ops = &driGCOps;
543*4882a593Smuzhiyun }
544*4882a593Smuzhiyun
545*4882a593Smuzhiyun wrap(pScreenPriv, pScreen, CreateGC, DRICreateGC);
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun return ret;
548*4882a593Smuzhiyun }
549*4882a593Smuzhiyun
550*4882a593Smuzhiyun /* Return false if an error occurred. */
551*4882a593Smuzhiyun Bool
DRIWrapInit(ScreenPtr pScreen)552*4882a593Smuzhiyun DRIWrapInit(ScreenPtr pScreen)
553*4882a593Smuzhiyun {
554*4882a593Smuzhiyun DRIWrapScreenRec *pScreenPriv;
555*4882a593Smuzhiyun
556*4882a593Smuzhiyun if (!dixRegisterPrivateKey(&driGCKeyRec, PRIVATE_GC, sizeof(DRIGCRec)))
557*4882a593Smuzhiyun return FALSE;
558*4882a593Smuzhiyun
559*4882a593Smuzhiyun if (!dixRegisterPrivateKey(&driWrapScreenKeyRec, PRIVATE_SCREEN,
560*4882a593Smuzhiyun sizeof(DRIWrapScreenRec)))
561*4882a593Smuzhiyun return FALSE;
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun pScreenPriv = dixGetPrivateAddr(&pScreen->devPrivates,
564*4882a593Smuzhiyun &driWrapScreenKeyRec);
565*4882a593Smuzhiyun pScreenPriv->CreateGC = pScreen->CreateGC;
566*4882a593Smuzhiyun pScreen->CreateGC = DRICreateGC;
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun return TRUE;
569*4882a593Smuzhiyun }
570