⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enable.c

📁 Using mirror driver as filter driver in capture desktop screen operation allow system run faster tha
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************Module*Header*******************************\
*
*                           *******************
*                           * GDI SAMPLE CODE *
*                           *******************
*
* Module Name: enable.c
*
* This module contains the functions that enable and disable the
* driver, the pdev, and the surface.
*
* Copyright (c) 1992-1998 Microsoft Corporation
\**************************************************************************/
#define DBG 1
#define SHARE_MEM 1

#include "driver.h"

#if SHARE_MEM

#endif
// The driver function table with all function index/address pairs

static DRVFN gadrvfn[] =
{
    {   INDEX_DrvEnablePDEV,            (PFN) DrvEnablePDEV         },
    {   INDEX_DrvCompletePDEV,          (PFN) DrvCompletePDEV       },
    {   INDEX_DrvDisablePDEV,           (PFN) DrvDisablePDEV        },
    {   INDEX_DrvEnableSurface,         (PFN) DrvEnableSurface      },
    {   INDEX_DrvDisableSurface,        (PFN) DrvDisableSurface     },
    {   INDEX_DrvAssertMode,            (PFN) DrvAssertMode         },
    {   INDEX_DrvNotify,                (PFN) DrvNotify             },
    {   INDEX_DrvCreateDeviceBitmap,    (PFN) DrvCreateDeviceBitmap },
    {   INDEX_DrvDeleteDeviceBitmap,    (PFN) DrvDeleteDeviceBitmap },
    {   INDEX_DrvTextOut,               (PFN) DrvTextOut            },
    {   INDEX_DrvBitBlt,                (PFN) DrvBitBlt             },
    {   INDEX_DrvCopyBits,              (PFN) DrvCopyBits           },
    {   INDEX_DrvStrokePath,            (PFN) DrvStrokePath         },
    {   INDEX_DrvLineTo,                (PFN) DrvLineTo             },
    {   INDEX_DrvFillPath,              (PFN) DrvFillPath           },
    {   INDEX_DrvStrokeAndFillPath,     (PFN) DrvStrokeAndFillPath  },
    {   INDEX_DrvStretchBlt,            (PFN) DrvStretchBlt         },
    {   INDEX_DrvAlphaBlend,            (PFN) DrvAlphaBlend         },
    {   INDEX_DrvTransparentBlt,        (PFN) DrvTransparentBlt     },
    {   INDEX_DrvGradientFill,          (PFN) DrvGradientFill       },
    {   INDEX_DrvPlgBlt,                (PFN) DrvPlgBlt             },
    {   INDEX_DrvStretchBltROP,         (PFN) DrvStretchBltROP      },
#if (NTDDI_VERSION >= NTDDI_VISTA)
    {   INDEX_DrvRenderHint,            (PFN) DrvRenderHint         },
#endif
    {   INDEX_DrvEscape,                (PFN) DrvEscape             }
};

//
// always hook these routines to ensure the mirrored driver
// is called for our surfaces
//

#define flGlobalHooks   HOOK_BITBLT|HOOK_TEXTOUT|HOOK_COPYBITS|HOOK_STROKEPATH|HOOK_LINETO|HOOK_FILLPATH|HOOK_STROKEANDFILLPATH|HOOK_STRETCHBLT|HOOK_ALPHABLEND|HOOK_TRANSPARENTBLT|HOOK_GRADIENTFILL|HOOK_PLGBLT|HOOK_STRETCHBLTROP

// Define the functions you want to hook for 8/16/24/32 pel formats

#define HOOKS_BMF8BPP 0

#define HOOKS_BMF16BPP 0

#define HOOKS_BMF24BPP 0

#define HOOKS_BMF32BPP 0

/******************************Public*Routine******************************\
* DrvEnableDriver
*
* Enables the driver by retrieving the drivers function table and version.
*
\**************************************************************************/

BOOL DrvEnableDriver(
ULONG iEngineVersion,
ULONG cj,
PDRVENABLEDATA pded)
{
// Engine Version is passed down so future drivers can support previous
// engine versions.  A next generation driver can support both the old
// and new engine conventions if told what version of engine it is
// working with.  For the first version the driver does nothing with it.

    iEngineVersion;

    DISPDBG((0,"DrvEnableDriver:\n"));

// Fill in as much as we can.

    if (cj >= sizeof(DRVENABLEDATA))
        pded->pdrvfn = gadrvfn;

    if (cj >= (sizeof(ULONG) * 2))
        pded->c = sizeof(gadrvfn) / sizeof(DRVFN);

// DDI version this driver was targeted for is passed back to engine.
// Future graphic's engine may break calls down to old driver format.

    if (cj >= sizeof(ULONG))
	// DDI_DRIVER_VERSION is now out-dated. See winddi.h
	// DDI_DRIVER_VERSION_NT4 is equivalent to the old DDI_DRIVER_VERSION
        pded->iDriverVersion = DDI_DRIVER_VERSION_NT4;

    return(TRUE);
}

/******************************Public*Routine******************************\
* DrvEnablePDEV
*
* DDI function, Enables the Physical Device.
*
* Return Value: device handle to pdev.
*
\**************************************************************************/

DHPDEV
DrvEnablePDEV(
    __in     DEVMODEW   *pDevmode,                // Pointer to DEVMODE
    __in_opt PWSTR       pwszLogAddress,          // Logical address
    __in     ULONG       cPatterns,               // number of patterns
    __in_opt HSURF      *ahsurfPatterns,          // return standard patterns
    __in     ULONG       cjGdiInfo,               // Length of memory pointed to by pGdiInfo
    __out_bcount(cjGdiInfo)  ULONG    *pGdiInfo,  // Pointer to GdiInfo structure
    __in     ULONG       cjDevInfo,               // Length of following PDEVINFO structure
    __out_bcount(cjDevInfo)  DEVINFO  *pDevInfo,  // physical device information structure
    __in_opt HDEV        hdev,                    // HDEV, used for callbacks
    __in_opt PWSTR       pwszDeviceName,          // DeviceName - not used
    __in     HANDLE      hDriver                  // Handle to base driver
    )
{
    GDIINFO GdiInfo;
    DEVINFO DevInfo;
    PPDEV   ppdev = (PPDEV) NULL;

    DISPDBG((0,"DrvEnablePDEV:\n"));

    UNREFERENCED_PARAMETER(pwszLogAddress);
    UNREFERENCED_PARAMETER(cPatterns);
    UNREFERENCED_PARAMETER(ahsurfPatterns);
    UNREFERENCED_PARAMETER(hdev);
    UNREFERENCED_PARAMETER(pwszDeviceName);

    // Allocate a physical device structure.

    ppdev = (PPDEV) EngAllocMem(FL_ZERO_MEMORY, sizeof(PDEV), ALLOC_TAG);

    if (ppdev == (PPDEV) NULL)
    {
        RIP("DISP DrvEnablePDEV failed EngAllocMem\n");
        return((DHPDEV) 0);
    }

    // Save the screen handle in the PDEV.

    ppdev->hDriver = hDriver;

    // Get the current screen mode information.  Set up device caps and devinfo.

    if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
    {
        DISPDBG((0,"DISP DrvEnablePDEV failed\n"));
        goto error_free;
    }
    
    // Copy the devinfo into the engine buffer.

    // memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
    if (sizeof(DEVINFO) > cjDevInfo)
    {
        DISPDBG((0,"DISP DrvEnablePDEV failed: insufficient pDevInfo memory\n"));
        goto error_free;
    }
	RtlCopyMemory(pDevInfo, &DevInfo, sizeof(DEVINFO));

    // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
    // pdev.

    //memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
    if (sizeof(GDIINFO) > cjGdiInfo)
    {
        DISPDBG((0,"DISP DrvEnablePDEV failed: insufficient pDevInfo memory\n"));
        goto error_free;
    }
	RtlCopyMemory(pGdiInfo, &GdiInfo, sizeof(GDIINFO));
	
while(1)
{
	ppdev->pVideoMemory = EngMapFile(
		L"\\??\\c:\\mirror1.dat",
		1024*768*4,
		&ppdev->hMem);
	if(ppdev->hMem){
		DISPDBG((1,"EngMapFile OK:\n"));
	}
	break;
}
    return((DHPDEV) ppdev);

    // Error case for failure.
error_free:
    EngFreeMem(ppdev);
    return((DHPDEV) 0);
}

/******************************Public*Routine******************************\
* DrvCompletePDEV
*
* Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
*
\**************************************************************************/

VOID DrvCompletePDEV(
DHPDEV dhpdev,
HDEV  hdev)
{
    DISPDBG((1,"DrvCompletePDEV:\n"));
    ((PPDEV) dhpdev)->hdevEng = hdev;
}

/******************************Public*Routine******************************\
* DrvDisablePDEV
*
* Release the resources allocated in DrvEnablePDEV.  If a surface has been
* enabled DrvDisableSurface will have already been called.
*
\**************************************************************************/

VOID DrvDisablePDEV(
DHPDEV dhpdev)
{
   PPDEV ppdev = (PPDEV) dhpdev;

   DISPDBG((1,"DrvDisablePDEV:\n"));
   
   EngDeletePalette(ppdev->hpalDefault);

   EngFreeMem(dhpdev);
   
while(1)
{
	if(ppdev->hMem)
		EngUnmapFile(ppdev->hMem);
	break;
}

}

/******************************Public*Routine******************************\
* DrvEnableSurface
*
* Enable the surface for the device.  Hook the calls this driver supports.
*
* Return: Handle to the surface if successful, 0 for failure.
*
\**************************************************************************/

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

    // Create engine bitmap around frame buffer.

    DISPDBG((0,"DrvEnableSurface:\n"));

    ppdev = (PPDEV) dhpdev;

    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;
    }
    else if (ppdev->ulBitCount == 24)
    {
        ulBitmapType = BMF_24BPP;
        flHooks = HOOKS_BMF24BPP;
    }
    else
    {
        ulBitmapType = BMF_32BPP;
        flHooks = HOOKS_BMF32BPP;
    }
    
    flHooks |= flGlobalHooks;

    mirrorsize = (ULONG)(sizeof(MIRRSURF) + 
                         ppdev->lDeltaScreen * sizl.cy);
    
    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)
    {
        RIP("DISP DrvEnableSurface failed EngCreateDeviceSurface\n");
        return(FALSE);
    }
#if SHARE_MEM
while(1)
{

	int bytesPerPixel;
	switch(ulBitmapType)
	{
	case BMF_16BPP:
	bytesPerPixel = 2;
	break;
	case BMF_24BPP:
	bytesPerPixel = 3;
	break;
	case BMF_32BPP:
	bytesPerPixel = 4;
	break;
	}
/*	
	DISPDBG((1,"ppdev->cxScreen %d:\n",ppdev->cxScreen));
	DISPDBG((1,"ppdev->cyScreen %d:\n",ppdev->cyScreen));
	DISPDBG((1,"bytesPerPixel %d:\n",bytesPerPixel));
	ppdev->pVideoMemory = EngMapFile(
		L"\\??\\c:\\mirror1.dat",
		ppdev->cxScreen*ppdev->cyScreen*bytesPerPixel,
		&ppdev->hMem);
	if(ppdev->hMem){
		DISPDBG((1,"EngMapFile OK:\n"));
	}
	else
		DISPDBG((1,"EngMapFile FAILED:\n"));
*/
	if(ppdev->hMem)
	{
		if(
		EngModifySurface(
			hsurf, 	//OK EngCreateDeviceSurface
			ppdev->hdevEng, 	//OK hdev 
			flHooks, 			// just hook value,
			0, 					//the same
			dhsurf,	 //dhsurf
			ppdev->pVideoMemory, 		// oh, my fault
			ppdev->cxScreen*bytesPerPixel, //ok lun
			NULL))
			DISPDBG((1,"EngModifySurface OK:\n"));
		else{
			DISPDBG((1,"EngModifySurface FAILED:\n"));
			RIP("DISP DrvEnableSurface failed EngAssociateSurface\n");
			EngDeleteSurface(hsurf);
			return(FALSE);
		}
			
	}
		
	break;
}
#else
	if (!EngAssociateSurface(hsurf, ppdev->hdevEng, flHooks))
    {
        RIP("DISP DrvEnableSurface failed EngAssociateSurface\n");
        EngDeleteSurface(hsurf);
        return(FALSE);
    }
#endif

    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;

#if SHARE_MEM
/*
while(1){
	UNICODE_STRING fileNameUnicodeString;
	OBJECT_ATTRIBUTES objectAttributes;
	HANDLE hFileHandle=NULL;
	NTSTATUS rc;
	PVOID uBaseAddress = NULL; 
	ULONG ViewSize = 0;
	int size = mirrorsize;
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -