1 /* $Id: driver.c,v 1.6 1999/12/09 02:45:05 rex Exp $
3 * GDI Driver support routines
4 * (mostly swiped from Wine)
8 #undef WIN32_LEAN_AND_MEAN
11 #include <win32k/driver.h>
15 #include <internal/debug.h>
17 typedef struct _GRAPHICS_DRIVER
20 PGD_ENABLEDRIVER EnableDriver
;
22 struct _GRAPHICS_DRIVER
*Next
;
23 } GRAPHICS_DRIVER
, *PGRAPHICS_DRIVER
;
25 static PGRAPHICS_DRIVER DriverList
;
26 static PGRAPHICS_DRIVER GenericDriver
;
28 BOOL
DRIVER_RegisterDriver(LPCWSTR Name
, PGD_ENABLEDRIVER EnableDriver
)
30 PGRAPHICS_DRIVER Driver
= ExAllocatePool(NonPagedPool
, sizeof(*Driver
));
35 Driver
->ReferenceCount
= 0;
36 Driver
->EnableDriver
= EnableDriver
;
39 Driver
->Name
= ExAllocatePool(NonPagedPool
,
40 (wcslen(Name
) + 1) * sizeof(WCHAR
));
41 wcscpy(Driver
->Name
, Name
);
42 Driver
->Next
= DriverList
;
47 if (GenericDriver
!= NULL
)
55 GenericDriver
= Driver
;
59 PGD_ENABLEDRIVER
DRIVER_FindDDIDriver(LPCWSTR Name
)
61 GRAPHICS_DRIVER
*Driver
= DriverList
;
63 while (Driver
&& Name
)
65 if (!_wcsicmp( Driver
->Name
, Name
))
67 return Driver
->EnableDriver
;
69 Driver
= Driver
->Next
;
72 return GenericDriver
? GenericDriver
->EnableDriver
: NULL
;
75 BOOL
DRIVER_BuildDDIFunctions(PDRVENABLEDATA DED
,
81 HANDLE
DRIVER_FindMPDriver(LPCWSTR Name
)
86 UNICODE_STRING DeviceName
;
87 OBJECT_ATTRIBUTES ObjectAttributes
;
91 lName
= ExAllocatePool(NonPagedPool
, wcslen(Name
) * sizeof(WCHAR
) +
93 wcscpy(lName
, L
"\\Devices\\");
98 lName
= ExAllocatePool(NonPagedPool
, wcslen(Name
) * sizeof(WCHAR
));
102 RtlInitUnicodeString(&DeviceName
, lName
);
103 InitializeObjectAttributes(&ObjectAttributes
,
108 Status
= ZwOpenFile(&DriverHandle
,
113 FILE_SYNCHRONOUS_IO_ALERT
);
114 if (!NT_SUCCESS(Status
))
116 DbgPrint("Failed to open display device\n");
117 DbgPrint("%08lx\n", Status
);
134 BOOL
DRIVER_UnregisterDriver(LPCWSTR Name
)
136 PGRAPHICS_DRIVER Driver
= NULL
;
140 if (DriverList
!= NULL
)
142 if (!_wcsicmp(DriverList
->Name
, Name
))
145 DriverList
= DriverList
->Next
;
150 while (Driver
->Next
&& _wcsicmp(Driver
->Name
, Name
))
152 Driver
= Driver
->Next
;
159 if (GenericDriver
!= NULL
)
161 Driver
= GenericDriver
;
162 GenericDriver
= NULL
;
168 ExFreePool(Driver
->Name
);
179 INT
DRIVER_ReferenceDriver (LPCWSTR Name
)
181 GRAPHICS_DRIVER
*Driver
= DriverList
;
183 while (Driver
&& Name
)
185 if (!_wcsicmp( Driver
->Name
, Name
))
187 return ++Driver
->ReferenceCount
;
189 Driver
= Driver
->Next
;
192 return GenericDriver
? ++GenericDriver
->ReferenceCount
: 0;
195 INT
DRIVER_UnreferenceDriver (LPCWSTR Name
)
197 GRAPHICS_DRIVER
*Driver
= DriverList
;
199 while (Driver
&& Name
)
201 if (!_wcsicmp( Driver
->Name
, Name
))
203 return --Driver
->ReferenceCount
;
205 Driver
= Driver
->Next
;
208 return GenericDriver
? --GenericDriver
->ReferenceCount
: 0;