xserver-multidpi/hw/xnest/Pixmap.c
Keith Packard 2dc138922b Rename region macros to eliminate screen argument
This is a combination of a huge mechanical patch and a few small
fixups required to finish the job. They were reviewed separately, but
because the server does not build without both pieces, I've merged
them together at this time.

The mechanical changes were performed by running the included
'fix-region' script over the whole tree:

$ git ls-files | grep -v '^fix-' | xargs ./fix-region

And then, the white space errors in the resulting patch were fixed
using the provided fix-patch-whitespace script.

$ sh ./fix-patch-whitespace

Thanks to Jamey Sharp for the mighty fine sed-generating sed script.

The hand-done changes involve removing functions from dix/region.c
that duplicate inline functions in include/regionstr.h, along with
their declarations in regionstr.h, mi.h and mispans.h.

Reviewed-by: Jamey Sharp <jamey@minilop.net>
Signed-off-by: Keith Packard <keithp@keithp.com>
2010-06-05 18:59:00 -07:00

142 lines
3.5 KiB
C

/*
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.
*/
#ifdef HAVE_XNEST_CONFIG_H
#include <xnest-config.h>
#endif
#include <X11/X.h>
#include <X11/Xproto.h>
#include "regionstr.h"
#include "pixmapstr.h"
#include "scrnintstr.h"
#include "regionstr.h"
#include "gc.h"
#include "servermd.h"
#include "privates.h"
#include "mi.h"
#include "Xnest.h"
#include "Display.h"
#include "Screen.h"
#include "XNPixmap.h"
static int xnestPixmapPrivateKeyIndex;
DevPrivateKey xnestPixmapPrivateKey = &xnestPixmapPrivateKeyIndex;
PixmapPtr
xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
unsigned usage_hint)
{
PixmapPtr pPixmap;
pPixmap = AllocatePixmap(pScreen, sizeof(xnestPrivPixmap));
if (!pPixmap)
return NullPixmap;
pPixmap->drawable.type = DRAWABLE_PIXMAP;
pPixmap->drawable.class = 0;
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);
pPixmap->usage_hint = usage_hint;
dixSetPrivate(&pPixmap->devPrivates, xnestPixmapPrivateKey,
(char *)pPixmap + pScreen->totalPixmapSize);
if (width && height)
xnestPixmapPriv(pPixmap)->pixmap =
XCreatePixmap(xnestDisplay,
xnestDefaultWindows[pScreen->myNum],
width, height, depth);
else
xnestPixmapPriv(pPixmap)->pixmap = 0;
return pPixmap;
}
Bool
xnestDestroyPixmap(PixmapPtr pPixmap)
{
if(--pPixmap->refcnt)
return TRUE;
XFreePixmap(xnestDisplay, xnestPixmap(pPixmap));
dixFreePrivates(pPixmap->devPrivates);
free(pPixmap);
return TRUE;
}
RegionPtr
xnestPixmapToRegion(PixmapPtr pPixmap)
{
XImage *ximage;
register RegionPtr pReg, pTmpReg;
register int x, y;
unsigned long previousPixel, currentPixel;
BoxRec Box = { 0, 0, 0, 0 };
Bool overlap;
ximage = XGetImage(xnestDisplay, xnestPixmap(pPixmap), 0, 0,
pPixmap->drawable.width, pPixmap->drawable.height,
1, XYPixmap);
pReg = RegionCreate(NULL, 1);
pTmpReg = RegionCreate(NULL, 1);
if(!pReg || !pTmpReg) {
XDestroyImage(ximage);
return NullRegion;
}
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;
RegionReset(pTmpReg, &Box);
RegionAppend(pReg, pTmpReg);
}
previousPixel = currentPixel;
}
}
if (previousPixel != 0L) {
/* right edge because of the end of pixmap */
Box.x2 = pPixmap->drawable.width;
RegionReset(pTmpReg, &Box);
RegionAppend(pReg, pTmpReg);
}
}
RegionDestroy(pTmpReg);
XDestroyImage(ximage);
RegionValidate(pReg, &overlap);
return(pReg);
}