2003-11-14 16:54:54 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 1993 by Davor Matic
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
and its documentation for any purpose is hereby granted without fee,
|
|
|
|
provided that the above copyright notice appear in all copies and that
|
|
|
|
both that copyright notice and this permission notice appear in
|
|
|
|
supporting documentation. Davor Matic makes no representations about
|
|
|
|
the suitability of this software for any purpose. It is provided "as
|
|
|
|
is" without express or implied warranty.
|
|
|
|
|
|
|
|
*/
|
2003-11-14 17:49:22 +01:00
|
|
|
|
2005-07-14 05:36:44 +02:00
|
|
|
#ifdef HAVE_XNEST_CONFIG_H
|
|
|
|
#include <xnest-config.h>
|
|
|
|
#endif
|
|
|
|
|
2005-04-20 14:25:48 +02:00
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
2003-11-25 20:29:01 +01:00
|
|
|
#include "regionstr.h"
|
2003-11-14 16:54:54 +01:00
|
|
|
#include "pixmapstr.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include "regionstr.h"
|
|
|
|
#include "gc.h"
|
|
|
|
#include "servermd.h"
|
2007-04-05 20:18:05 +02:00
|
|
|
#include "privates.h"
|
2003-11-14 16:54:54 +01:00
|
|
|
#include "mi.h"
|
|
|
|
|
|
|
|
#include "Xnest.h"
|
|
|
|
|
|
|
|
#include "Display.h"
|
|
|
|
#include "Screen.h"
|
2003-11-14 17:49:22 +01:00
|
|
|
#include "XNPixmap.h"
|
|
|
|
|
2010-04-27 02:22:21 +02:00
|
|
|
DevPrivateKeyRec xnestPixmapPrivateKeyRec;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
PixmapPtr
|
2007-10-31 22:15:35 +01:00
|
|
|
xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
|
2011-01-21 00:37:45 +01:00
|
|
|
unsigned class)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
PixmapPtr pPixmap;
|
|
|
|
|
2010-04-27 02:22:21 +02:00
|
|
|
pPixmap = AllocatePixmap(pScreen, 0);
|
2003-11-14 16:54:54 +01:00
|
|
|
if (!pPixmap)
|
|
|
|
return NullPixmap;
|
|
|
|
pPixmap->drawable.type = DRAWABLE_PIXMAP;
|
2011-01-21 00:37:45 +01:00
|
|
|
pPixmap->drawable.class = class;
|
2003-11-14 16:54:54 +01:00
|
|
|
pPixmap->drawable.depth = depth;
|
|
|
|
pPixmap->drawable.bitsPerPixel = depth;
|
|
|
|
pPixmap->drawable.id = 0;
|
|
|
|
pPixmap->drawable.x = 0;
|
|
|
|
pPixmap->drawable.y = 0;
|
|
|
|
pPixmap->drawable.width = width;
|
|
|
|
pPixmap->drawable.height = height;
|
|
|
|
pPixmap->drawable.pScreen = pScreen;
|
|
|
|
pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
|
|
|
|
pPixmap->refcnt = 1;
|
|
|
|
pPixmap->devKind = PixmapBytePad(width, depth);
|
|
|
|
if (width && height)
|
|
|
|
xnestPixmapPriv(pPixmap)->pixmap =
|
|
|
|
XCreatePixmap(xnestDisplay,
|
|
|
|
xnestDefaultWindows[pScreen->myNum],
|
|
|
|
width, height, depth);
|
|
|
|
else
|
|
|
|
xnestPixmapPriv(pPixmap)->pixmap = 0;
|
|
|
|
|
|
|
|
return pPixmap;
|
|
|
|
}
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
Bool
|
|
|
|
xnestDestroyPixmap(PixmapPtr pPixmap)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
if(--pPixmap->refcnt)
|
|
|
|
return TRUE;
|
|
|
|
XFreePixmap(xnestDisplay, xnestPixmap(pPixmap));
|
2010-04-27 02:22:21 +02:00
|
|
|
FreePixmap(pPixmap);
|
2003-11-14 16:54:54 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
RegionPtr
|
|
|
|
xnestPixmapToRegion(PixmapPtr pPixmap)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
XImage *ximage;
|
|
|
|
register RegionPtr pReg, pTmpReg;
|
|
|
|
register int x, y;
|
|
|
|
unsigned long previousPixel, currentPixel;
|
2008-11-25 06:53:55 +01:00
|
|
|
BoxRec Box = { 0, 0, 0, 0 };
|
2003-11-14 16:54:54 +01:00
|
|
|
Bool overlap;
|
|
|
|
|
|
|
|
ximage = XGetImage(xnestDisplay, xnestPixmap(pPixmap), 0, 0,
|
|
|
|
pPixmap->drawable.width, pPixmap->drawable.height,
|
|
|
|
1, XYPixmap);
|
|
|
|
|
2010-05-22 00:05:48 +02:00
|
|
|
pReg = RegionCreate(NULL, 1);
|
|
|
|
pTmpReg = RegionCreate(NULL, 1);
|
2006-04-03 03:51:54 +02:00
|
|
|
if(!pReg || !pTmpReg) {
|
|
|
|
XDestroyImage(ximage);
|
|
|
|
return NullRegion;
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
for (y = 0; y < pPixmap->drawable.height; y++) {
|
|
|
|
Box.y1 = y;
|
|
|
|
Box.y2 = y + 1;
|
|
|
|
previousPixel = 0L;
|
|
|
|
for (x = 0; x < pPixmap->drawable.width; x++) {
|
|
|
|
currentPixel = XGetPixel(ximage, x, y);
|
|
|
|
if (previousPixel != currentPixel) {
|
|
|
|
if (previousPixel == 0L) {
|
|
|
|
/* left edge */
|
|
|
|
Box.x1 = x;
|
|
|
|
}
|
|
|
|
else if (currentPixel == 0L) {
|
|
|
|
/* right edge */
|
|
|
|
Box.x2 = x;
|
2010-05-22 00:05:48 +02:00
|
|
|
RegionReset(pTmpReg, &Box);
|
|
|
|
RegionAppend(pReg, pTmpReg);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
previousPixel = currentPixel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (previousPixel != 0L) {
|
|
|
|
/* right edge because of the end of pixmap */
|
|
|
|
Box.x2 = pPixmap->drawable.width;
|
2010-05-22 00:05:48 +02:00
|
|
|
RegionReset(pTmpReg, &Box);
|
|
|
|
RegionAppend(pReg, pTmpReg);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-22 00:05:48 +02:00
|
|
|
RegionDestroy(pTmpReg);
|
2003-11-14 16:54:54 +01:00
|
|
|
XDestroyImage(ximage);
|
|
|
|
|
2010-05-22 00:05:48 +02:00
|
|
|
RegionValidate(pReg, &overlap);
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2010-06-06 16:18:40 +02:00
|
|
|
return pReg;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|