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