#ifdef HAVE_DMX_CONFIG_H
#include <dmx-config.h>
#endif
#include "dmx.h"
#include "dmxsync.h"
#include "dmxpixmap.h"
#include "pixmapstr.h"
#include "servermd.h"
Bool dmxInitPixmap(ScreenPtr pScreen)
{
if (!AllocatePixmapPrivate(pScreen, dmxPixPrivateIndex,
sizeof(dmxPixPrivRec)))
return FALSE;
return TRUE;
}
void dmxBECreatePixmap(PixmapPtr pPixmap)
{
ScreenPtr pScreen = pPixmap->drawable.pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pPixmap);
if (pPixPriv->pixmap)
return;
if (pPixmap->drawable.width && pPixmap->drawable.height) {
pPixPriv->pixmap = XCreatePixmap(dmxScreen->beDisplay,
dmxScreen->scrnWin,
pPixmap->drawable.width,
pPixmap->drawable.height,
pPixmap->drawable.depth);
dmxSync(dmxScreen, FALSE);
}
}
PixmapPtr dmxCreatePixmap(ScreenPtr pScreen, int width, int height, int depth)
{
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
PixmapPtr pPixmap;
int bpp;
dmxPixPrivPtr pPixPriv;
#if 0
DMX_UNWRAP(CreatePixmap, dmxScreen, pScreen);
if (pScreen->CreatePixmap)
ret = pScreen->CreatePixmap(pPixmap);
#endif
if (depth == 24) bpp = 32;
else bpp = depth;
pPixmap = AllocatePixmap(pScreen, 0);
if (!pPixmap)
return NullPixmap;
pPixmap->drawable.type = DRAWABLE_PIXMAP;
pPixmap->drawable.class = 0;
pPixmap->drawable.pScreen = pScreen;
pPixmap->drawable.depth = depth;
pPixmap->drawable.bitsPerPixel = bpp;
pPixmap->drawable.id = 0;
pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
pPixmap->drawable.x = 0;
pPixmap->drawable.y = 0;
pPixmap->drawable.width = width;
pPixmap->drawable.height = height;
pPixmap->devKind = PixmapBytePad(width, bpp);
pPixmap->refcnt = 1;
pPixPriv = DMX_GET_PIXMAP_PRIV(pPixmap);
pPixPriv->pixmap = (Pixmap)0;
pPixPriv->detachedImage = NULL;
if (dmxScreen->beDisplay) {
dmxBECreatePixmap(pPixmap);
}
#if 0
DMX_WRAP(CreatePixmap, dmxCreatePixmap, dmxScreen, pScreen);
#endif
return pPixmap;
}
Bool dmxBEFreePixmap(PixmapPtr pPixmap)
{
ScreenPtr pScreen = pPixmap->drawable.pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pPixmap);
if (pPixPriv->pixmap) {
XFreePixmap(dmxScreen->beDisplay, pPixPriv->pixmap);
pPixPriv->pixmap = (Pixmap)0;
return TRUE;
}
return FALSE;
}
Bool dmxDestroyPixmap(PixmapPtr pPixmap)
{
ScreenPtr pScreen = pPixmap->drawable.pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
Bool ret = TRUE;
#if 0
DMX_UNWRAP(DestroyPixmap, dmxScreen, pScreen);
#endif
if (--pPixmap->refcnt)
return TRUE;
if (dmxScreen->beDisplay) {
if (dmxBEFreePixmap(pPixmap)) {
dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pPixmap);
if (pPixPriv->detachedImage)
XDestroyImage(pPixPriv->detachedImage);
dmxSync(dmxScreen, FALSE);
}
}
xfree(pPixmap);
#if 0
if (pScreen->DestroyPixmap)
ret = pScreen->DestroyPixmap(pPixmap);
DMX_WRAP(DestroyPixmap, dmxDestroyPixmap, dmxScreen, pScreen);
#endif
return ret;
}
RegionPtr dmxBitmapToRegion(PixmapPtr pPixmap)
{
ScreenPtr pScreen = pPixmap->drawable.pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pPixmap);
XImage *ximage;
RegionPtr pReg, pTmpReg;
int x, y;
unsigned long previousPixel, currentPixel;
BoxRec Box;
Bool overlap;
if (!dmxScreen->beDisplay) {
pReg = REGION_CREATE(pScreen, NullBox, 1);
return pReg;
}
ximage = XGetImage(dmxScreen->beDisplay, pPixPriv->pixmap, 0, 0,
pPixmap->drawable.width, pPixmap->drawable.height,
1, XYPixmap);
pReg = REGION_CREATE(pScreen, NullBox, 1);
pTmpReg = REGION_CREATE(pScreen, NullBox, 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) {
Box.x1 = x;
} else if (currentPixel == 0L) {
Box.x2 = x;
REGION_RESET(pScreen, pTmpReg, &Box);
REGION_APPEND(pScreen, pReg, pTmpReg);
}
previousPixel = currentPixel;
}
}
if (previousPixel != 0L) {
Box.x2 = pPixmap->drawable.width;
REGION_RESET(pScreen, pTmpReg, &Box);
REGION_APPEND(pScreen, pReg, pTmpReg);
}
}
REGION_DESTROY(pScreen, pTmpReg);
XDestroyImage(ximage);
REGION_VALIDATE(pScreen, pReg, &overlap);
dmxSync(dmxScreen, FALSE);
return(pReg);
}