I am writing a mirror driver to share the video memory with user-mode
applications, here is my idea:
1. In DrvEnablePDEV, create a mapped file (such as c:\mirror.dat) for
video memory by function EngMapFile, and store the mapped memory in the
point pVideoMemory of PPDEV. The map will be unmapped and the file will
be deleted in DrvDisablePDEV
2. In DrvEnableSurface, modify the surface with EngModifySurface.
The source code for DrvEnableSurface looks like:

HSURF DrvEnableSurface(
DHPDEV dhpdev)
{
PPDEV ppdev;
HSURF hsurf;
SIZEL sizl;
ULONG ulBitmapType;
FLONG flHooks;
ULONG mirrorsize;
MIRRSURF *mirrsurf;
DHSURF dhsurf;
LONG lDelta=0;

// Create engine bitmap around frame buffer.


ppdev = (PPDEV) dhpdev;

DISPDBG((0,"DISP
DrvEnableSurface:(%d,%d,%d)\n",ppdev->cxScreen,ppdev->cyScreen,ppdev->ulBitCount));

ppdev->ptlOrg.x = 0;
ppdev->ptlOrg.y = 0;

sizl.cx = ppdev->cxScreen;
sizl.cy = ppdev->cyScreen;

if (ppdev->ulBitCount == 16)
{
ulBitmapType = BMF_16BPP;
flHooks = HOOKS_BMF16BPP;
lDelta = ALIGNEDWIDTH(2 * sizl.cx);
}
else if (ppdev->ulBitCount == 24)
{
ulBitmapType = BMF_24BPP;
flHooks = HOOKS_BMF24BPP;
lDelta = ALIGNEDWIDTH(3 * sizl.cx);
}
else if(ppdev->ulBitCount==32)
{
ulBitmapType = BMF_32BPP;
flHooks = HOOKS_BMF32BPP;
lDelta = ALIGNEDWIDTH(4 * sizl.cx);
} else
return FALSE;

flHooks |= flGlobalHooks;

mirrorsize = (ULONG)(sizeof(MIRRSURF) +
lDelta * sizl.cy);

DISPDBG((0,"DISP DrvEnableSurface:
MirrorSize:%d,lDelta:%d,pVideoMemory:%lx",mirrorsize,lDelta,
ppdev->pVideoMemory));
mirrsurf = (MIRRSURF *) EngAllocMem(FL_ZERO_MEMORY,
mirrorsize,
0x4D495252);
if (!mirrsurf) {
RIP("DISP DrvEnableSurface failed EngAllocMem\n");
return(FALSE);
}

dhsurf = (DHSURF) mirrsurf;

hsurf = EngCreateDeviceSurface(dhsurf,
sizl,
ulBitmapType);

if (hsurf == (HSURF) 0)
{
DISPDBG((0,"DISP DrvEnableSurface failed
EngCreateDeviceSurface\n"));
return(FALSE);
}

if (!EngAssociateSurface(hsurf, ppdev->hdevEng, flHooks))
{
DISPDBG((0,"DISP DrvEnableSurface failed
EngAssociateSurface\n"));
EngDeleteSurface(hsurf);
return(FALSE);
}

if(!EngModifySurface(hsurf, ppdev->hdevEng, flHooks, 0,
(DHSURF)dhsurf,
ppdev->pVideoMemory, lDelta, NULL))
{
DISPDBG((0,"DISP DrvEnableSurface failed
EngModifySurface\n"));
EngDeleteSurface(hsurf);
return(FALSE);
}

ppdev->hsurfEng = (HSURF) hsurf;
ppdev->pvTmpBuffer = (PVOID) dhsurf;

mirrsurf->cx = ppdev->cxScreen;
mirrsurf->cy = ppdev->cyScreen;
mirrsurf->lDelta = ppdev->lDeltaScreen;
mirrsurf->ulBitCount = ppdev->ulBitCount;
mirrsurf->bIsScreen = TRUE;

return(hsurf);
}

The mapped file will always be filled with Zero, so the image from the
mapped file will be black. Can any one tell me what's wrong with the
source code?

Thanks in advance

Jarvis Bao



--
jarvisbao
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------