1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS kernel 4 * PURPOSE: Native driver for dxg implementation 5 * FILE: win32ss/reactx/dxg/main.c 6 * PROGRAMER: Magnus olsen (magnus@greatlord.com) 7 * REVISION HISTORY: 8 * 15/10-2007 Magnus Olsen 9 */ 10 11 #include <dxg_int.h> 12 #include "dxg_driver.h" 13 14 LONG gcDummyPageRefCnt = 0; 15 HSEMAPHORE ghsemDummyPage = NULL; 16 VOID *gpDummyPage = NULL; 17 PEPROCESS gpepSession = NULL; 18 PLARGE_INTEGER gpLockShortDelay = NULL; 19 20 DXENG_FUNCTIONS gpEngFuncs; 21 22 const ULONG gcDxgFuncs = DXG_INDEX_DxDdIoctl + 1; 23 24 25 NTSTATUS NTAPI 26 DriverEntry(IN PVOID Context1, 27 IN PVOID Context2) 28 { 29 return 0; 30 } 31 32 NTSTATUS 33 APIENTRY 34 DxDdStartupDxGraphics (ULONG SizeEngDrv, 35 PDRVENABLEDATA pDxEngDrv, 36 ULONG SizeDxgDrv, 37 PDRVENABLEDATA pDxgDrv, 38 PULONG DirectDrawContext, 39 PEPROCESS Proc ) 40 { 41 42 PDRVFN drv_func; 43 PFN *peng_funcs; 44 UINT i; 45 46 /* Test see if the data is vaild we got from win32k.sys */ 47 if ((SizeEngDrv != sizeof(DRVENABLEDATA)) || 48 (SizeDxgDrv != sizeof(DRVENABLEDATA))) 49 { 50 return STATUS_BUFFER_TOO_SMALL; 51 } 52 53 /* rest static value */ 54 gpDummyPage = NULL; 55 gcDummyPageRefCnt = 0; 56 ghsemDummyPage = NULL; 57 58 /* 59 * Setup internal driver functions list we got from dxg driver functions list 60 */ 61 pDxgDrv->iDriverVersion = 0x80000; /* Note 12/1-2004 : DirectX 8 ? */ 62 pDxgDrv->c = gcDxgFuncs; 63 pDxgDrv->pdrvfn = gaDxgFuncs; 64 65 /* check how many driver functions and fail if the value does not match */ 66 if (pDxEngDrv->c != DXENG_INDEX_DxEngLoadImage + 1) 67 { 68 return STATUS_INTERNAL_ERROR; 69 } 70 71 /* 72 * Check if all drv functions are sorted right 73 * and if it really are exported 74 */ 75 76 peng_funcs = (PFN*)&gpEngFuncs; 77 78 for (i = 1; i < DXENG_INDEX_DxEngLoadImage + 1; i++) 79 { 80 drv_func = &pDxEngDrv->pdrvfn[i]; 81 82 if ((drv_func->iFunc != i) || 83 (drv_func->pfn == NULL)) 84 { 85 return STATUS_INTERNAL_ERROR; 86 } 87 88 peng_funcs[i] = drv_func->pfn; 89 } 90 91 /* Note 12/1-2004 : Why is this set to 0x618 */ 92 *DirectDrawContext = 0x618; 93 94 if (DdHmgCreate()) 95 { 96 ghsemDummyPage = EngCreateSemaphore(); 97 98 if (ghsemDummyPage) 99 { 100 gpepSession = Proc; 101 return STATUS_SUCCESS; 102 } 103 } 104 105 DdHmgDestroy(); 106 107 if (ghsemDummyPage) 108 { 109 EngDeleteSemaphore(ghsemDummyPage); 110 ghsemDummyPage = 0; 111 } 112 113 return STATUS_NO_MEMORY; 114 } 115 116 NTSTATUS 117 APIENTRY 118 DxDdCleanupDxGraphics(VOID) 119 { 120 DdHmgDestroy(); 121 122 if (ghsemDummyPage != 0 ) 123 { 124 if (gpDummyPage != 0 ) 125 { 126 ExFreePoolWithTag(gpDummyPage,0); 127 gpDummyPage = NULL; 128 gcDummyPageRefCnt = 0; 129 } 130 EngDeleteSemaphore(ghsemDummyPage); 131 ghsemDummyPage = 0; 132 } 133 134 return 0; 135 } 136