[WIN32SS][FONT] Fix font metrics (#713)
[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: 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 ULONG peng_funcs;
44 PULONG peng_func;
45
46 UINT i;
47
48 /* Test see if the data is vaild we got from win32k.sys */
49 if ((SizeEngDrv != sizeof(DRVENABLEDATA)) ||
50 (SizeDxgDrv != sizeof(DRVENABLEDATA)))
51 {
52 return STATUS_BUFFER_TOO_SMALL;
53 }
54
55 /* rest static value */
56 gpDummyPage = NULL;
57 gcDummyPageRefCnt = 0;
58 ghsemDummyPage = NULL;
59
60 /*
61 * Setup internal driver functions list we got from dxg driver functions list
62 */
63 pDxgDrv->iDriverVersion = 0x80000; /* Note 12/1-2004 : DirectX 8 ? */
64 pDxgDrv->c = gcDxgFuncs;
65 pDxgDrv->pdrvfn = gaDxgFuncs;
66
67 /* check how many driver functions and fail if the value does not match */
68 if (pDxEngDrv->c != DXENG_INDEX_DxEngLoadImage + 1)
69 {
70 return STATUS_INTERNAL_ERROR;
71 }
72
73 /*
74 * Check if all drv functions are sorted right
75 * and if it really are exported
76 */
77
78 peng_funcs = (ULONG)&gpEngFuncs;
79
80 for (i=1 ; i < DXENG_INDEX_DxEngLoadImage + 1; i++)
81 {
82 drv_func = &pDxEngDrv->pdrvfn[i];
83
84 if ((drv_func->iFunc != i) ||
85 (drv_func->pfn == NULL))
86 {
87 return STATUS_INTERNAL_ERROR;
88 }
89 peng_func = (PULONG)(peng_funcs+(i * sizeof(ULONG)));
90 *peng_func = (ULONG)drv_func->pfn;
91 }
92
93 /* Note 12/1-2004 : Why is this set to 0x618 */
94 *DirectDrawContext = 0x618;
95
96 if (DdHmgCreate())
97 {
98 ghsemDummyPage = EngCreateSemaphore();
99
100 if (ghsemDummyPage)
101 {
102 gpepSession = Proc;
103 return STATUS_SUCCESS;
104 }
105 }
106
107 DdHmgDestroy();
108
109 if (ghsemDummyPage)
110 {
111 EngDeleteSemaphore(ghsemDummyPage);
112 ghsemDummyPage = 0;
113 }
114
115 return STATUS_NO_MEMORY;
116 }
117
118 NTSTATUS
119 APIENTRY
120 DxDdCleanupDxGraphics(VOID)
121 {
122 DdHmgDestroy();
123
124 if (ghsemDummyPage != 0 )
125 {
126 if (gpDummyPage != 0 )
127 {
128 ExFreePoolWithTag(gpDummyPage,0);
129 gpDummyPage = NULL;
130 gcDummyPageRefCnt = 0;
131 }
132 EngDeleteSemaphore(ghsemDummyPage);
133 ghsemDummyPage = 0;
134 }
135
136 return 0;
137 }