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

📄 functions.c

📁 一个windows显示驱动的好程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************
 * 
 *  Toby Opferman
 *
 *  Example GDI DDI (Device Driver Interface) Driver Entry Point
 *
 *  This example is for educational purposes only.  I license this source
 *  out for use in learning how to write a device driver.
 *
 *  Copyright (c) 2005, All Rights Reserved  
 **********************************************************************/

#define __NTDDKCOMP__        
#define _MPPC_
#define _WIN32_WINNT 0x500


#include <stddef.h>
#include <stdarg.h>
#include <limits.h>
#include <windef.h>
#include <wingdi.h>
#include <math.h>
#include <winddi.h>
#include <devioctl.h>

#include <ntddvdeo.h>


#include "gdifuncs.h"

#define RESOLUTION_X      800
#define RESOLUTION_Y      600
#define COLOR_DEPTH_BYTES 4
#define COLOR_DEPTH_BITS  32




#define SYSTM_LOGFONT {16,7,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH | FF_DONTCARE,L"System"}
#define HELVE_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_STROKE_PRECIS,PROOF_QUALITY,VARIABLE_PITCH | FF_DONTCARE,L"MS Sans Serif"}
#define COURI_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_STROKE_PRECIS,PROOF_QUALITY,FIXED_PITCH | FF_DONTCARE, L"Courier"}


const DEVINFO gDevInfoFrameBuffer = {
    ( GCAPS_OPAQUERECT  |
     /* GCAPS_LAYERED     |    If you do not really support this you can have big problems */
      GCAPS_DITHERONREALIZE  |
      GCAPS_ALTERNATEFILL    |
      GCAPS_WINDINGFILL      |
      GCAPS_MONO_DITHER      |
      GCAPS_GRAY16           |
      GCAPS_COLOR_DITHER
                   ), /* Graphics capabilities         */
    SYSTM_LOGFONT,    /* Default font description */
    HELVE_LOGFONT,    /* ANSI variable font description   */
    COURI_LOGFONT,    /* ANSI fixed font description          */
    0,                /* Count of device fonts          */
    0,                /* Preferred DIB format          */
    8,                /* Width of color dither          */
    8,                /* Height of color dither   */
    0,                  /* Default palette to use for this device */
    GCAPS2_SYNCTIMER |
    GCAPS2_SYNCFLUSH
};


//#define ENGDEBUGPRINT
#define ENGDEBUGPRINT EngDebugPrint

 
/*********************************************************************
 * GdiExample_DrvEnablePDEV
 *
 *   This function will provide a description of the Physical Device.  The data
 *   returned is a user defined data context to be used as a handle for this
 *   display device.
 *
 *   The hDriver is a handle to the miniport driver associated with this display
 *   device.  This handle can be used to communicate to the miniport through APIs
 *   to send things like IOCTLs.
 *
 *********************************************************************/
DHPDEV GdiExample_DrvEnablePDEV(DEVMODEW *pdm, PWSTR pwszLogAddr, ULONG cPat, HSURF *phsurfPatterns, ULONG cjCaps, GDIINFO *pGdiInfo, ULONG cjDevInfo, DEVINFO *pDevInfo, HDEV hdev, PWSTR pwszDeviceName, HANDLE hDriver) 
{
    PDEVICE_DATA pDeviceData = NULL;
    
    ENGDEBUGPRINT(0, "GdiExample_DrvEnablePDEV Enter \r\n", NULL);

    pDeviceData = (PDEVICE_DATA) EngAllocMem(0, sizeof(DEVICE_DATA), FAKE_GFX_TAG);

    if(pDeviceData)
    {
        memset(pDeviceData, 0, sizeof(DEVICE_DATA));
        memset(pGdiInfo, 0, cjCaps);
        memset(pDevInfo, 0, cjDevInfo);

        {
            pGdiInfo->ulVersion    = 0x5000;
            pGdiInfo->ulTechnology = DT_RASDISPLAY;
            pGdiInfo->ulHorzSize   = 0;
            pGdiInfo->ulVertSize   = 0;
            pGdiInfo->ulHorzRes        = RESOLUTION_X;
            pGdiInfo->ulVertRes        = RESOLUTION_Y;
            pGdiInfo->ulPanningHorzRes = 0;
            pGdiInfo->ulPanningVertRes = 0;
            pGdiInfo->cBitsPixel       = 8;
            pGdiInfo->cPlanes          = 4;
            pGdiInfo->ulNumColors      = 20;
            pGdiInfo->ulVRefresh       = 1;       
            pGdiInfo->ulBltAlignment   = 1;     
            pGdiInfo->ulLogPixelsX = 96;
            pGdiInfo->ulLogPixelsY = 96;
            pGdiInfo->flTextCaps   = TC_RA_ABLE;
            pGdiInfo->flRaster     = 0;
            pGdiInfo->ulDACRed     = 8;
            pGdiInfo->ulDACGreen   = 8;
            pGdiInfo->ulDACBlue    = 8;
            pGdiInfo->ulAspectX    = 0x24; 
            pGdiInfo->ulNumPalReg  = 256;
            pGdiInfo->ulAspectY    = 0x24;
            pGdiInfo->ulAspectXY   = 0x33;
            pGdiInfo->xStyleStep   = 1;       
            pGdiInfo->yStyleStep   = 1;
            pGdiInfo->denStyleStep = 3;
            pGdiInfo->ptlPhysOffset.x = 0;
            pGdiInfo->ptlPhysOffset.y = 0;
            pGdiInfo->szlPhysSize.cx  = 0;
            pGdiInfo->szlPhysSize.cy  = 0;
            pGdiInfo->ciDevice.Red.x = 6700;
            pGdiInfo->ciDevice.Red.y = 3300;
            pGdiInfo->ciDevice.Red.Y = 0;
            pGdiInfo->ciDevice.Green.x = 2100;
            pGdiInfo->ciDevice.Green.y = 7100;
            pGdiInfo->ciDevice.Green.Y = 0;
            pGdiInfo->ciDevice.Blue.x = 1400;
            pGdiInfo->ciDevice.Blue.y = 800;
            pGdiInfo->ciDevice.Blue.Y = 0;
            pGdiInfo->ciDevice.AlignmentWhite.x = 3127;
            pGdiInfo->ciDevice.AlignmentWhite.y = 3290;
            pGdiInfo->ciDevice.AlignmentWhite.Y = 0;
            pGdiInfo->ciDevice.RedGamma = 20000;
            pGdiInfo->ciDevice.GreenGamma = 20000;
            pGdiInfo->ciDevice.BlueGamma = 20000;
            pGdiInfo->ciDevice.Cyan.x = 1750;
            pGdiInfo->ciDevice.Cyan.y = 3950;
            pGdiInfo->ciDevice.Cyan.Y = 0;
            pGdiInfo->ciDevice.Magenta.x = 4050;
            pGdiInfo->ciDevice.Magenta.y = 2050;
            pGdiInfo->ciDevice.Magenta.Y = 0;
            pGdiInfo->ciDevice.Yellow.x = 4400;
            pGdiInfo->ciDevice.Yellow.y = 5200;
            pGdiInfo->ciDevice.Yellow.Y = 0;
            pGdiInfo->ciDevice.MagentaInCyanDye = 0;
            pGdiInfo->ciDevice.YellowInCyanDye = 0;
            pGdiInfo->ciDevice.CyanInMagentaDye = 0;
            pGdiInfo->ciDevice.YellowInMagentaDye = 0;
            pGdiInfo->ciDevice.CyanInYellowDye = 0;
            pGdiInfo->ciDevice.MagentaInYellowDye = 0;
            pGdiInfo->ulDevicePelsDPI = 0; 
            pGdiInfo->ulPrimaryOrder = PRIMARY_ORDER_CBA;
            pGdiInfo->ulHTPatternSize = HT_PATSIZE_4x4_M;
            pGdiInfo->flHTFlags = HT_FLAG_ADDITIVE_PRIMS;
            pGdiInfo->ulHTOutputFormat = HT_FORMAT_32BPP;

            
            *pDevInfo = gDevInfoFrameBuffer;
            pDevInfo->iDitherFormat = BMF_32BPP;

        }

        pDeviceData->pVideoMemory = EngMapFile(L"\\??\\c:\\video.dat", RESOLUTION_X*RESOLUTION_Y*4, &pDeviceData->pMappedFile);

        pDeviceData->hDriver = hDriver;
        pDevInfo->hpalDefault = EngCreatePalette(PAL_BITFIELDS, 0, NULL, 0xFF0000, 0xFF00, 0xFF);
    }

    ENGDEBUGPRINT(0, "GdiExample_DrvEnablePDEV Exit \r\n", NULL);

    return (DHPDEV)pDeviceData;
}

/*********************************************************************
 * GdiExample_DrvCompletePDEV
 *
 *   This is called to complete the process of enabling the device.
 *   
 *
 *********************************************************************/
void GdiExample_DrvCompletePDEV(DHPDEV  dhpdev, HDEV  hdev)
{
    PDEVICE_DATA pDeviceData = (PDEVICE_DATA)dhpdev;
    ENGDEBUGPRINT(0, "GdiExample_DrvCompletePDEV Enter \r\n", NULL);

    pDeviceData->hdev = hdev;

    ENGDEBUGPRINT(0, "GdiExample_DrvCompletePDEV Exit \r\n", NULL);
}


/*********************************************************************
 * GdiExample_DrvAssertMode
 *
 *    This API sets the display mode of the device to the original mode
 *    which was used during initialization or the default mode of the hardware.
 *
 *********************************************************************/
BOOL GdiExample_DrvAssertMode(DHPDEV  dhpdev,BOOL  bEnable)
{

    ENGDEBUGPRINT(0, "GdiExample_DrvAssertMode\r\n", NULL);

    /*
     * We do nothing here
     */
    return TRUE;
}

/*********************************************************************
 * GdiExample_DrvDisablePDEV
 *
 *   This is called to disable the PDEV we created.
 *   
 *
 *********************************************************************/
void GdiExample_DrvDisablePDEV(DHPDEV  dhpdev)
{
    PDEVICE_DATA pDeviceData = (PDEVICE_DATA)dhpdev;
    UINT dwBytesReturned = 0;

    ENGDEBUGPRINT(0, "GdiExample_DrvDisablePDEV\r\n", NULL);

    if(pDeviceData->pMappedFile)
    {
       EngUnmapFile(pDeviceData->pMappedFile);
    }

    EngFreeMem(dhpdev);
}


/*********************************************************************
 * GdiExample_DrvEscape
 *
 *    This is the equivlent of an "IOCTL" for a display driver but instead
 *    of an "IOCTL" you have "ESCAPE CODES".  This is how you can communicate
 *    to this display driver in a device DEPENDENT manner instead of INDEPENDENT.
 *
 *    To call into this interface from user mode you use the "ExtEscape" API.
 *
 *********************************************************************/
ULONG GdiExample_DrvEscape(SURFOBJ *pso, ULONG iEsc, ULONG  cjIn, PVOID  pvIn, ULONG cjOut, PVOID pvOut)
{
    ENGDEBUGPRINT(0, "GdiExample_DrvEscape\r\n", NULL);
    return 0;
}



/*********************************************************************
 * GdiExample_DrvGetModes
 *
 *    This API is used to enumerate display modes.
 *
 *    This driver only supports 800x600x32
 *
 *********************************************************************/
ULONG GdiExample_DrvGetModes(HANDLE hDriver, ULONG cjSize, DEVMODEW *pdm)
{
   ULONG ulBytesWritten = 0, ulBytesNeeded = sizeof(DEVMODEW);
   ULONG ulReturnValue;
   ENGDEBUGPRINT(0, "GdiExample_DrvGetModes\r\n", NULL);
   if(pdm == NULL)
   {
       ulReturnValue =  ulBytesNeeded;
   }
   else
   {
       

       ulBytesWritten = sizeof(DEVMODEW);

       memset(pdm, 0, sizeof(DEVMODEW));
       memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));

       pdm->dmSpecVersion   = DM_SPECVERSION;
       pdm->dmDriverVersion = DM_SPECVERSION;

       pdm->dmDriverExtra      = 0;
       pdm->dmSize             = sizeof(DEVMODEW);
       pdm->dmBitsPerPel       = 32;
       pdm->dmPelsWidth        = RESOLUTION_X;
       pdm->dmPelsHeight       = RESOLUTION_Y;
       pdm->dmDisplayFrequency = 75;

       pdm->dmDisplayFlags     = 0;
       
       pdm->dmPanningWidth     = pdm->dmPelsWidth;
       pdm->dmPanningHeight    = pdm->dmPelsHeight;

       pdm->dmFields           = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY;

       ulReturnValue = ulBytesWritten;

   }

   return ulReturnValue;
}


/*********************************************************************
 * GdiExample_DrvResetPDEV
 *
 *    This API is used to pass state information from one PDEV
 *    instance to another.
 *
 *********************************************************************/
BOOL GdiExample_DrvResetPDEV(DHPDEV  dhpdevOld, DHPDEV  dhpdevNew)
{
    ENGDEBUGPRINT(0, "GdiExample_DrvResetPDEV\r\n", NULL);

    return FALSE;
}




/*********************************************************************
 * GdiExample_DrvEnableSurface
 *
 *  This API is used to enable the physical device surface.  
 *

⌨️ 快捷键说明

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