3 Copyright 1993 by Davor Matic
5 Permission to use, copy, modify, distribute, and sell this software
6 and its documentation for any purpose is hereby granted without fee,
7 provided that the above copyright notice appear in all copies and that
8 both that copyright notice and this permission notice appear in
9 supporting documentation. Davor Matic makes no representations about
10 the suitability of this software for any purpose. It is provided "as
11 is" without express or implied warranty.
15 #ifdef HAVE_XNEST_CONFIG_H
16 #include <xnest-config.h>
20 #include <X11/Xproto.h>
21 #include "regionstr.h"
22 #include "pixmapstr.h"
23 #include "scrnintstr.h"
35 DevPrivateKeyRec xnestPixmapPrivateKeyRec
;
38 xnestCreatePixmap(ScreenPtr pScreen
, int width
, int height
, int depth
,
43 pPixmap
= AllocatePixmap(pScreen
, 0);
46 pPixmap
->drawable
.type
= DRAWABLE_PIXMAP
;
47 pPixmap
->drawable
.class = 0;
48 pPixmap
->drawable
.depth
= depth
;
49 pPixmap
->drawable
.bitsPerPixel
= depth
;
50 pPixmap
->drawable
.id
= 0;
51 pPixmap
->drawable
.x
= 0;
52 pPixmap
->drawable
.y
= 0;
53 pPixmap
->drawable
.width
= width
;
54 pPixmap
->drawable
.height
= height
;
55 pPixmap
->drawable
.pScreen
= pScreen
;
56 pPixmap
->drawable
.serialNumber
= NEXT_SERIAL_NUMBER
;
58 pPixmap
->devKind
= PixmapBytePad(width
, depth
);
59 pPixmap
->usage_hint
= usage_hint
;
61 xnestPixmapPriv(pPixmap
)->pixmap
=
62 XCreatePixmap(xnestDisplay
,
63 xnestDefaultWindows
[pScreen
->myNum
],
64 width
, height
, depth
);
66 xnestPixmapPriv(pPixmap
)->pixmap
= 0;
72 xnestDestroyPixmap(PixmapPtr pPixmap
)
74 if (--pPixmap
->refcnt
)
76 XFreePixmap(xnestDisplay
, xnestPixmap(pPixmap
));
82 xnestModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
, int depth
,
83 int bitsPerPixel
, int devKind
, pointer pPixData
)
85 if(!xnestPixmapPriv(pPixmap
)->pixmap
&& width
> 0 && height
> 0) {
86 xnestPixmapPriv(pPixmap
)->pixmap
=
87 XCreatePixmap(xnestDisplay
,
88 xnestDefaultWindows
[pPixmap
->drawable
.pScreen
->myNum
],
89 width
, height
, depth
);
92 return miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
93 bitsPerPixel
, devKind
, pPixData
);
97 xnestPixmapToRegion(PixmapPtr pPixmap
)
100 register RegionPtr pReg
, pTmpReg
;
102 unsigned long previousPixel
, currentPixel
;
103 BoxRec Box
= { 0, 0, 0, 0 };
106 ximage
= XGetImage(xnestDisplay
, xnestPixmap(pPixmap
), 0, 0,
107 pPixmap
->drawable
.width
, pPixmap
->drawable
.height
,
110 pReg
= RegionCreate(NULL
, 1);
111 pTmpReg
= RegionCreate(NULL
, 1);
112 if (!pReg
|| !pTmpReg
) {
113 XDestroyImage(ximage
);
117 for (y
= 0; y
< pPixmap
->drawable
.height
; y
++) {
121 for (x
= 0; x
< pPixmap
->drawable
.width
; x
++) {
122 currentPixel
= XGetPixel(ximage
, x
, y
);
123 if (previousPixel
!= currentPixel
) {
124 if (previousPixel
== 0L) {
128 else if (currentPixel
== 0L) {
131 RegionReset(pTmpReg
, &Box
);
132 RegionAppend(pReg
, pTmpReg
);
134 previousPixel
= currentPixel
;
137 if (previousPixel
!= 0L) {
138 /* right edge because of the end of pixmap */
139 Box
.x2
= pPixmap
->drawable
.width
;
140 RegionReset(pTmpReg
, &Box
);
141 RegionAppend(pReg
, pTmpReg
);
145 RegionDestroy(pTmpReg
);
146 XDestroyImage(ximage
);
148 RegionValidate(pReg
, &overlap
);