#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
#include <X11/extensions/shm.h>
#include "shmint.h"
#endif
typedef struct
{
pointer pbits;
int width;
} miScreenInitParmsRec, *miScreenInitParmsPtr;
Bool
miModifyPixmapHeader(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.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;
}
pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
return TRUE;
}
static Bool
miCloseScreen (int iScreen, ScreenPtr pScreen)
{
return ((*pScreen->DestroyPixmap)((PixmapPtr)pScreen->devPrivate));
}
Bool
miCreateScreenResources(ScreenPtr pScreen)
{
miScreenInitParmsPtr pScrInitParms;
pointer value;
pScrInitParms = (miScreenInitParmsPtr)pScreen->devPrivate;
if (pScrInitParms->width)
{
PixmapPtr pPixmap;
pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth, 0);
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;
}
free(pScreen->devPrivate);
pScreen->devPrivate = value;
return TRUE;
}
Bool
miScreenDevPrivateInit(ScreenPtr pScreen, int width, pointer pbits)
{
miScreenInitParmsPtr pScrInitParms;
pScrInitParms = malloc(sizeof(miScreenInitParmsRec));
if (!pScrInitParms)
return FALSE;
pScrInitParms->pbits = pbits;
pScrInitParms->width = width;
pScreen->devPrivate = (pointer)pScrInitParms;
return TRUE;
}
static PixmapPtr
miGetScreenPixmap(ScreenPtr pScreen)
{
return (PixmapPtr)(pScreen->devPrivate);
}
static void
miSetScreenPixmap(PixmapPtr pPix)
{
if (pPix)
pPix->drawable.pScreen->devPrivate = (pointer)pPix;
}
Bool
miScreenInit(
ScreenPtr pScreen,
pointer pbits,
int xsize, int ysize,
int dpix, int 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->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->MoveWindow = miMoveWindow;
pScreen->ResizeWindow = miSlideAndSizeWindow;
pScreen->GetLayerWindow = miGetLayerWindow;
pScreen->HandleExposures = miHandleValidateExposures;
pScreen->ReparentWindow = (ReparentWindowProcPtr) 0;
pScreen->ChangeBorderWidth = miChangeBorderWidth;
pScreen->SetShape = miSetShape;
pScreen->MarkUnrealizedWindow = miMarkUnrealizedWindow;
miSetZeroLineBias(pScreen, DEFAULTZEROLINEBIAS);
return miScreenDevPrivateInit(pScreen, width, pbits);
}
DevPrivateKeyRec miZeroLineScreenKeyRec;
void
miSetZeroLineBias(ScreenPtr pScreen, unsigned int bias)
{
if (!dixRegisterPrivateKey(&miZeroLineScreenKeyRec, PRIVATE_SCREEN, 0))
return;
dixSetPrivate(&pScreen->devPrivates, miZeroLineScreenKey,
(unsigned long *)(unsigned long)bias);
}