Path: blob/master/utils/xorg-deps/xf86-video-dummy/v0.3.8/src/dummy_dga.c
1013 views
#ifdef HAVE_CONFIG_H1#include "config.h"2#endif34#include "xf86.h"5#include "xf86_OSproc.h"6#include "dgaproc.h"7#include "dummy.h"89static Bool DUMMY_OpenFramebuffer(ScrnInfoPtr, char **, unsigned char **,10int *, int *, int *);11static Bool DUMMY_SetMode(ScrnInfoPtr, DGAModePtr);12static int DUMMY_GetViewport(ScrnInfoPtr);13static void DUMMY_SetViewport(ScrnInfoPtr, int, int, int);1415static16DGAFunctionRec DUMMYDGAFuncs = {17DUMMY_OpenFramebuffer,18NULL,19DUMMY_SetMode,20DUMMY_SetViewport,21DUMMY_GetViewport,22NULL,23NULL,24NULL,25#if 026DUMMY_BlitTransRect27#else28NULL29#endif30};3132Bool33DUMMYDGAInit(ScreenPtr pScreen)34{35ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);36DUMMYPtr pDUMMY = DUMMYPTR(pScrn);37DGAModePtr modes = NULL, newmodes = NULL, currentMode;38DisplayModePtr pMode, firstMode;39int Bpp = pScrn->bitsPerPixel >> 3;40int num = 0, imlines, pixlines;4142imlines = (pScrn->videoRam * 1024) /43(pScrn->displayWidth * (pScrn->bitsPerPixel >> 3));4445pixlines = imlines;4647pMode = firstMode = pScrn->modes;4849while(pMode) {5051newmodes = realloc(modes, (num + 1) * sizeof(DGAModeRec));5253if(!newmodes) {54free(modes);55return FALSE;56}57modes = newmodes;5859currentMode = modes + num;60num++;6162currentMode->mode = pMode;63currentMode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE;64if(pMode->Flags & V_DBLSCAN)65currentMode->flags |= DGA_DOUBLESCAN;66if(pMode->Flags & V_INTERLACE)67currentMode->flags |= DGA_INTERLACED;68currentMode->byteOrder = pScrn->imageByteOrder;69currentMode->depth = pScrn->depth;70currentMode->bitsPerPixel = pScrn->bitsPerPixel;71currentMode->red_mask = pScrn->mask.red;72currentMode->green_mask = pScrn->mask.green;73currentMode->blue_mask = pScrn->mask.blue;74currentMode->visualClass = (Bpp == 1) ? PseudoColor : TrueColor;75currentMode->viewportWidth = pMode->HDisplay;76currentMode->viewportHeight = pMode->VDisplay;77currentMode->xViewportStep = 1;78currentMode->yViewportStep = 1;79currentMode->viewportFlags = DGA_FLIP_RETRACE;80currentMode->offset = 0;81currentMode->address = (unsigned char *)pDUMMY->FBBase;8283currentMode->bytesPerScanline =84((pScrn->displayWidth * Bpp) + 3) & ~3L;85currentMode->imageWidth = pScrn->displayWidth;86currentMode->imageHeight = imlines;87currentMode->pixmapWidth = currentMode->imageWidth;88currentMode->pixmapHeight = pixlines;89currentMode->maxViewportX = currentMode->imageWidth -90currentMode->viewportWidth;91currentMode->maxViewportY = currentMode->imageHeight -92currentMode->viewportHeight;9394pMode = pMode->next;95if(pMode == firstMode)96break;97}9899pDUMMY->numDGAModes = num;100pDUMMY->DGAModes = modes;101102return DGAInit(pScreen, &DUMMYDGAFuncs, modes, num);103}104105static DisplayModePtr DUMMYSavedDGAModes[MAXSCREENS];106107static Bool108DUMMY_SetMode(109ScrnInfoPtr pScrn,110DGAModePtr pMode111){112int index = pScrn->pScreen->myNum;113DUMMYPtr pDUMMY = DUMMYPTR(pScrn);114115if(!pMode) { /* restore the original mode */116if(pDUMMY->DGAactive) {117pScrn->currentMode = DUMMYSavedDGAModes[index];118DUMMYSwitchMode(SWITCH_MODE_ARGS(pScrn, pScrn->currentMode));119DUMMYAdjustFrame(ADJUST_FRAME_ARGS(pScrn, 0, 0));120pDUMMY->DGAactive = FALSE;121}122} else {123if(!pDUMMY->DGAactive) { /* save the old parameters */124DUMMYSavedDGAModes[index] = pScrn->currentMode;125pDUMMY->DGAactive = TRUE;126}127128DUMMYSwitchMode(SWITCH_MODE_ARGS(pScrn, pMode->mode));129}130131return TRUE;132}133134static int135DUMMY_GetViewport(136ScrnInfoPtr pScrn137){138DUMMYPtr pDUMMY = DUMMYPTR(pScrn);139140return pDUMMY->DGAViewportStatus;141}142143static void144DUMMY_SetViewport(145ScrnInfoPtr pScrn,146int x, int y,147int flags148){149DUMMYPtr pDUMMY = DUMMYPTR(pScrn);150151DUMMYAdjustFrame(ADJUST_FRAME_ARGS(pScrn, x, y));152pDUMMY->DGAViewportStatus = 0;153}154155156static Bool157DUMMY_OpenFramebuffer(158ScrnInfoPtr pScrn,159char **name,160unsigned char **mem,161int *size,162int *offset,163int *flags164){165DUMMYPtr pDUMMY = DUMMYPTR(pScrn);166167*name = NULL; /* no special device */168*mem = (unsigned char*)pDUMMY->FBBase;169*size = pScrn->videoRam * 1024;170*offset = 0;171*flags = DGA_NEED_ROOT;172173return TRUE;174}175176177