xref: /OK3568_Linux_fs/external/xserver/hw/xnest/Pixmap.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun 
3*4882a593Smuzhiyun Copyright 1993 by Davor Matic
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun Permission to use, copy, modify, distribute, and sell this software
6*4882a593Smuzhiyun and its documentation for any purpose is hereby granted without fee,
7*4882a593Smuzhiyun provided that the above copyright notice appear in all copies and that
8*4882a593Smuzhiyun both that copyright notice and this permission notice appear in
9*4882a593Smuzhiyun supporting documentation.  Davor Matic makes no representations about
10*4882a593Smuzhiyun the suitability of this software for any purpose.  It is provided "as
11*4882a593Smuzhiyun is" without express or implied warranty.
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun */
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #ifdef HAVE_XNEST_CONFIG_H
16*4882a593Smuzhiyun #include <xnest-config.h>
17*4882a593Smuzhiyun #endif
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #include <X11/X.h>
20*4882a593Smuzhiyun #include <X11/Xproto.h>
21*4882a593Smuzhiyun #include "regionstr.h"
22*4882a593Smuzhiyun #include "pixmapstr.h"
23*4882a593Smuzhiyun #include "scrnintstr.h"
24*4882a593Smuzhiyun #include "gc.h"
25*4882a593Smuzhiyun #include "servermd.h"
26*4882a593Smuzhiyun #include "privates.h"
27*4882a593Smuzhiyun #include "mi.h"
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #include "Xnest.h"
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #include "Display.h"
32*4882a593Smuzhiyun #include "Screen.h"
33*4882a593Smuzhiyun #include "XNPixmap.h"
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun DevPrivateKeyRec xnestPixmapPrivateKeyRec;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun PixmapPtr
xnestCreatePixmap(ScreenPtr pScreen,int width,int height,int depth,unsigned usage_hint)38*4882a593Smuzhiyun xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
39*4882a593Smuzhiyun                   unsigned usage_hint)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun     PixmapPtr pPixmap;
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun     pPixmap = AllocatePixmap(pScreen, 0);
44*4882a593Smuzhiyun     if (!pPixmap)
45*4882a593Smuzhiyun         return NullPixmap;
46*4882a593Smuzhiyun     pPixmap->drawable.type = DRAWABLE_PIXMAP;
47*4882a593Smuzhiyun     pPixmap->drawable.class = 0;
48*4882a593Smuzhiyun     pPixmap->drawable.depth = depth;
49*4882a593Smuzhiyun     pPixmap->drawable.bitsPerPixel = depth;
50*4882a593Smuzhiyun     pPixmap->drawable.id = 0;
51*4882a593Smuzhiyun     pPixmap->drawable.x = 0;
52*4882a593Smuzhiyun     pPixmap->drawable.y = 0;
53*4882a593Smuzhiyun     pPixmap->drawable.width = width;
54*4882a593Smuzhiyun     pPixmap->drawable.height = height;
55*4882a593Smuzhiyun     pPixmap->drawable.pScreen = pScreen;
56*4882a593Smuzhiyun     pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
57*4882a593Smuzhiyun     pPixmap->refcnt = 1;
58*4882a593Smuzhiyun     pPixmap->devKind = PixmapBytePad(width, depth);
59*4882a593Smuzhiyun     pPixmap->usage_hint = usage_hint;
60*4882a593Smuzhiyun     if (width && height)
61*4882a593Smuzhiyun         xnestPixmapPriv(pPixmap)->pixmap =
62*4882a593Smuzhiyun             XCreatePixmap(xnestDisplay,
63*4882a593Smuzhiyun                           xnestDefaultWindows[pScreen->myNum],
64*4882a593Smuzhiyun                           width, height, depth);
65*4882a593Smuzhiyun     else
66*4882a593Smuzhiyun         xnestPixmapPriv(pPixmap)->pixmap = 0;
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun     return pPixmap;
69*4882a593Smuzhiyun }
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun Bool
xnestDestroyPixmap(PixmapPtr pPixmap)72*4882a593Smuzhiyun xnestDestroyPixmap(PixmapPtr pPixmap)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun     if (--pPixmap->refcnt)
75*4882a593Smuzhiyun         return TRUE;
76*4882a593Smuzhiyun     XFreePixmap(xnestDisplay, xnestPixmap(pPixmap));
77*4882a593Smuzhiyun     FreePixmap(pPixmap);
78*4882a593Smuzhiyun     return TRUE;
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun Bool
xnestModifyPixmapHeader(PixmapPtr pPixmap,int width,int height,int depth,int bitsPerPixel,int devKind,void * pPixData)82*4882a593Smuzhiyun xnestModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, int depth,
83*4882a593Smuzhiyun                         int bitsPerPixel, int devKind, void *pPixData)
84*4882a593Smuzhiyun {
85*4882a593Smuzhiyun   if(!xnestPixmapPriv(pPixmap)->pixmap && width > 0 && height > 0) {
86*4882a593Smuzhiyun     xnestPixmapPriv(pPixmap)->pixmap =
87*4882a593Smuzhiyun         XCreatePixmap(xnestDisplay,
88*4882a593Smuzhiyun                       xnestDefaultWindows[pPixmap->drawable.pScreen->myNum],
89*4882a593Smuzhiyun                       width, height, depth);
90*4882a593Smuzhiyun   }
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun   return miModifyPixmapHeader(pPixmap, width, height, depth,
93*4882a593Smuzhiyun                               bitsPerPixel, devKind, pPixData);
94*4882a593Smuzhiyun }
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun RegionPtr
xnestPixmapToRegion(PixmapPtr pPixmap)97*4882a593Smuzhiyun xnestPixmapToRegion(PixmapPtr pPixmap)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun     XImage *ximage;
100*4882a593Smuzhiyun     register RegionPtr pReg, pTmpReg;
101*4882a593Smuzhiyun     register int x, y;
102*4882a593Smuzhiyun     unsigned long previousPixel, currentPixel;
103*4882a593Smuzhiyun     BoxRec Box = { 0, 0, 0, 0 };
104*4882a593Smuzhiyun     Bool overlap;
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun     ximage = XGetImage(xnestDisplay, xnestPixmap(pPixmap), 0, 0,
107*4882a593Smuzhiyun                        pPixmap->drawable.width, pPixmap->drawable.height,
108*4882a593Smuzhiyun                        1, XYPixmap);
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun     pReg = RegionCreate(NULL, 1);
111*4882a593Smuzhiyun     pTmpReg = RegionCreate(NULL, 1);
112*4882a593Smuzhiyun     if (!pReg || !pTmpReg) {
113*4882a593Smuzhiyun         XDestroyImage(ximage);
114*4882a593Smuzhiyun         return NullRegion;
115*4882a593Smuzhiyun     }
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun     for (y = 0; y < pPixmap->drawable.height; y++) {
118*4882a593Smuzhiyun         Box.y1 = y;
119*4882a593Smuzhiyun         Box.y2 = y + 1;
120*4882a593Smuzhiyun         previousPixel = 0L;
121*4882a593Smuzhiyun         for (x = 0; x < pPixmap->drawable.width; x++) {
122*4882a593Smuzhiyun             currentPixel = XGetPixel(ximage, x, y);
123*4882a593Smuzhiyun             if (previousPixel != currentPixel) {
124*4882a593Smuzhiyun                 if (previousPixel == 0L) {
125*4882a593Smuzhiyun                     /* left edge */
126*4882a593Smuzhiyun                     Box.x1 = x;
127*4882a593Smuzhiyun                 }
128*4882a593Smuzhiyun                 else if (currentPixel == 0L) {
129*4882a593Smuzhiyun                     /* right edge */
130*4882a593Smuzhiyun                     Box.x2 = x;
131*4882a593Smuzhiyun                     RegionReset(pTmpReg, &Box);
132*4882a593Smuzhiyun                     RegionAppend(pReg, pTmpReg);
133*4882a593Smuzhiyun                 }
134*4882a593Smuzhiyun                 previousPixel = currentPixel;
135*4882a593Smuzhiyun             }
136*4882a593Smuzhiyun         }
137*4882a593Smuzhiyun         if (previousPixel != 0L) {
138*4882a593Smuzhiyun             /* right edge because of the end of pixmap */
139*4882a593Smuzhiyun             Box.x2 = pPixmap->drawable.width;
140*4882a593Smuzhiyun             RegionReset(pTmpReg, &Box);
141*4882a593Smuzhiyun             RegionAppend(pReg, pTmpReg);
142*4882a593Smuzhiyun         }
143*4882a593Smuzhiyun     }
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun     RegionDestroy(pTmpReg);
146*4882a593Smuzhiyun     XDestroyImage(ximage);
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun     RegionValidate(pReg, &overlap);
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun     return pReg;
151*4882a593Smuzhiyun }
152