#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <X11/X.h>
#include "servermd.h"
#include "misc.h"
#include "mi.h"
#include "scrnintstr.h"
#include "pixmapstr.h"
#include "dix.h"
#include "miline.h"
#ifdef MITSHM
#define _XSHM_SERVER_
#include <X11/extensions/XShm.h>
#endif
typedef struct
{
pointer pbits;
int width;
} miScreenInitParmsRec, *miScreenInitParmsPtr;
_X_EXPORT Bool
miModifyPixmapHeader(pPixmap, width, height, depth, bitsPerPixel, devKind,
pPixData)
PixmapPtr pPixmap;
int width;
int height;
int depth;
int bitsPerPixel;
int devKind;
pointer pPixData;
{
if (!pPixmap)
return FALSE;
if ((width > 0) && (height > 0) && (depth > 0) && (bitsPerPixel > 0) &&
(devKind > 0) && pPixData) {
pPixmap->drawable.depth = depth;
pPixmap->drawable.bitsPerPixel = bitsPerPixel;
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 = devKind;
pPixmap->refcnt = 1;
pPixmap->devPrivate.ptr = pPixData;
} else {
if (width > 0)
pPixmap->drawable.width = width;
if (height > 0)
pPixmap->drawable.height = height;
if (depth > 0)
pPixmap->drawable.depth = depth;
if (bitsPerPixel > 0)
pPixmap->drawable.bitsPerPixel = bitsPerPixel;
else if ((bitsPerPixel < 0) && (depth > 0))
pPixmap->drawable.bitsPerPixel = BitsPerPixel(depth);
if (devKind > 0)
pPixmap->devKind = devKind;
else if ((devKind < 0) && ((width > 0) || (depth > 0)))
pPixmap->devKind = PixmapBytePad(pPixmap->drawable.width,
pPixmap->drawable.depth);
if (pPixData)
pPixmap->devPrivate.ptr = pPixData;
}
return TRUE;
}
static Bool
miCloseScreen (int iScreen, ScreenPtr pScreen)
{
return ((*pScreen->DestroyPixmap)((PixmapPtr)pScreen->devPrivate));
}
_X_EXPORT Bool
miCreateScreenResources(pScreen)
ScreenPtr pScreen;
{
miScreenInitParmsPtr pScrInitParms;
pointer value;
pScrInitParms = (miScreenInitParmsPtr)pScreen->devPrivate;
if (pScrInitParms->width)
{
PixmapPtr pPixmap;
pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth);
if (!pPixmap)
return FALSE;
if (!(*pScreen->ModifyPixmapHeader)(pPixmap, pScreen->width,
pScreen->height, pScreen->rootDepth,
BitsPerPixel(pScreen->rootDepth),
PixmapBytePad(pScrInitParms->width, pScreen->rootDepth),
pScrInitParms->pbits))
return FALSE;
value = (pointer)pPixmap;
}
else
{
value = pScrInitParms->pbits;
}
xfree(pScreen->devPrivate);
pScreen->devPrivate = value;
return TRUE;
}
Bool
miScreenDevPrivateInit(pScreen, width, pbits)
ScreenPtr pScreen;
int width;
pointer pbits;
{
miScreenInitParmsPtr pScrInitParms;
pScrInitParms = (miScreenInitParmsPtr)xalloc(sizeof(miScreenInitParmsRec));
if (!pScrInitParms)
return FALSE;
pScrInitParms->pbits = pbits;
pScrInitParms->width = width;
pScreen->devPrivate = (pointer)pScrInitParms;
return TRUE;
}
_X_EXPORT Bool
miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
rootDepth, numDepths, depths, rootVisual, numVisuals, visuals)
ScreenPtr pScreen;
pointer pbits;
int xsize, ysize;
int dpix, dpiy;
int width;
int rootDepth;
int numDepths;
DepthRec *depths;
VisualID rootVisual;
int numVisuals;
VisualRec *visuals;
{
pScreen->width = xsize;
pScreen->height = ysize;
pScreen->mmWidth = (xsize * 254 + dpix * 5) / (dpix * 10);
pScreen->mmHeight = (ysize * 254 + dpiy * 5) / (dpiy * 10);
pScreen->numDepths = numDepths;
pScreen->rootDepth = rootDepth;
pScreen->allowedDepths = depths;
pScreen->rootVisual = rootVisual;
pScreen->minInstalledCmaps = 1;
pScreen->maxInstalledCmaps = 1;
pScreen->backingStoreSupport = NotUseful;
pScreen->saveUnderSupport = NotUseful;
pScreen->ModifyPixmapHeader = miModifyPixmapHeader;
pScreen->CreateScreenResources = miCreateScreenResources;
pScreen->GetScreenPixmap = miGetScreenPixmap;
pScreen->SetScreenPixmap = miSetScreenPixmap;
pScreen->numVisuals = numVisuals;
pScreen->visuals = visuals;
if (width)
{
#ifdef MITSHM
ShmRegisterFbFuncs(pScreen);
#endif
pScreen->CloseScreen = miCloseScreen;
}
pScreen->PointerNonInterestBox = (PointerNonInterestBoxProcPtr) 0;
pScreen->SourceValidate = (SourceValidateProcPtr) 0;
pScreen->ValidateTree = miValidateTree;
pScreen->PostValidateTree = (PostValidateTreeProcPtr) 0;
pScreen->WindowExposures = miWindowExposures;
pScreen->ClearToBackground = miClearToBackground;
pScreen->ClipNotify = (ClipNotifyProcPtr) 0;
pScreen->RestackWindow = (RestackWindowProcPtr) 0;
pScreen->SendGraphicsExpose = miSendGraphicsExpose;
pScreen->BlockHandler = (ScreenBlockHandlerProcPtr)NoopDDA;
pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr)NoopDDA;
pScreen->blockData = (pointer)0;
pScreen->wakeupData = (pointer)0;
pScreen->MarkWindow = miMarkWindow;
pScreen->MarkOverlappedWindows = miMarkOverlappedWindows;
pScreen->ChangeSaveUnder = miChangeSaveUnder;
pScreen->PostChangeSaveUnder = miPostChangeSaveUnder;
pScreen->MoveWindow = miMoveWindow;
pScreen->ResizeWindow = miSlideAndSizeWindow;
pScreen->GetLayerWindow = miGetLayerWindow;
pScreen->HandleExposures = miHandleValidateExposures;
pScreen->ReparentWindow = (ReparentWindowProcPtr) 0;
pScreen->ChangeBorderWidth = miChangeBorderWidth;
#ifdef SHAPE
pScreen->SetShape = miSetShape;
#endif
pScreen->MarkUnrealizedWindow = miMarkUnrealizedWindow;
pScreen->SaveDoomedAreas = 0;
pScreen->RestoreAreas = 0;
pScreen->ExposeCopy = 0;
pScreen->TranslateBackingStore = 0;
pScreen->ClearBackingStore = 0;
pScreen->DrawGuarantee = 0;
miSetZeroLineBias(pScreen, DEFAULTZEROLINEBIAS);
return miScreenDevPrivateInit(pScreen, width, pbits);
}
_X_EXPORT int
miAllocateGCPrivateIndex()
{
static int privateIndex = -1;
static unsigned long miGeneration = 0;
if (miGeneration != serverGeneration)
{
privateIndex = AllocateGCPrivateIndex();
miGeneration = serverGeneration;
}
return privateIndex;
}
_X_EXPORT int miZeroLineScreenIndex;
static unsigned int miZeroLineGeneration = 0;
_X_EXPORT void
miSetZeroLineBias(pScreen, bias)
ScreenPtr pScreen;
unsigned int bias;
{
if (miZeroLineGeneration != serverGeneration)
{
miZeroLineScreenIndex = AllocateScreenPrivateIndex();
miZeroLineGeneration = serverGeneration;
}
if (miZeroLineScreenIndex >= 0)
pScreen->devPrivates[miZeroLineScreenIndex].uval = bias;
}
_X_EXPORT PixmapPtr
miGetScreenPixmap(pScreen)
ScreenPtr pScreen;
{
return (PixmapPtr)(pScreen->devPrivate);
}
_X_EXPORT void
miSetScreenPixmap(pPix)
PixmapPtr pPix;
{
if (pPix)
pPix->drawable.pScreen->devPrivate = (pointer)pPix;
}