2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * GDI Driver support routines
22 * (mostly swiped from Wine)
26 #undef WIN32_LEAN_AND_MEAN
27 #define WIN32_NO_PEHDR
29 #include <ddk/ntddk.h>
31 #include <win32k/driver.h>
32 #include <win32k/misc.h>
34 #include <ddk/winddi.h>
35 #include <ddk/ntapi.h>
36 #include <rosrtl/string.h>
37 #include <include/tags.h>
42 typedef struct _GRAPHICS_DRIVER
45 PGD_ENABLEDRIVER EnableDriver
;
47 struct _GRAPHICS_DRIVER
*Next
;
48 } GRAPHICS_DRIVER
, *PGRAPHICS_DRIVER
;
50 static PGRAPHICS_DRIVER DriverList
;
51 static PGRAPHICS_DRIVER GenericDriver
= 0;
53 BOOL
DRIVER_RegisterDriver(LPCWSTR Name
, PGD_ENABLEDRIVER EnableDriver
)
55 PGRAPHICS_DRIVER Driver
= ExAllocatePoolWithTag(PagedPool
, sizeof(*Driver
), TAG_DRIVER
);
56 DPRINT( "DRIVER_RegisterDriver( Name: %S )\n", Name
);
57 if (!Driver
) return FALSE
;
58 Driver
->ReferenceCount
= 0;
59 Driver
->EnableDriver
= EnableDriver
;
62 Driver
->Name
= ExAllocatePoolWithTag(PagedPool
,
63 (wcslen(Name
) + 1) * sizeof(WCHAR
),
65 wcscpy(Driver
->Name
, Name
);
66 Driver
->Next
= DriverList
;
71 if (GenericDriver
!= NULL
)
77 GenericDriver
= Driver
;
81 PGD_ENABLEDRIVER
DRIVER_FindDDIDriver(LPCWSTR Name
)
83 static WCHAR DefaultPath
[] = L
"\\SystemRoot\\System32\\";
84 static WCHAR DefaultExtension
[] = L
".DLL";
85 SYSTEM_LOAD_IMAGE GdiDriverInfo
;
86 GRAPHICS_DRIVER
*Driver
= DriverList
;
90 BOOL PathSeparatorFound
;
95 PathSeparatorFound
= FALSE
;
99 if (L
'\\' == *p
|| L
'/' == *p
)
101 PathSeparatorFound
= TRUE
;
111 Size
= (wcslen(Name
) + 1) * sizeof(WCHAR
);
112 if (! PathSeparatorFound
)
114 Size
+= sizeof(DefaultPath
) - sizeof(WCHAR
);
118 Size
+= sizeof(DefaultExtension
) - sizeof(WCHAR
);
120 FullName
= ExAllocatePoolWithTag(PagedPool
, Size
, TAG_DRIVER
);
121 if (NULL
== FullName
)
123 DPRINT1("Out of memory\n");
126 if (PathSeparatorFound
)
132 wcscpy(FullName
, DefaultPath
);
134 wcscat(FullName
, Name
);
137 wcscat(FullName
, DefaultExtension
);
140 /* First see if the driver hasn't already been loaded */
141 while (Driver
&& FullName
)
143 if (!_wcsicmp( Driver
->Name
, FullName
))
145 return Driver
->EnableDriver
;
147 Driver
= Driver
->Next
;
150 /* If not, then load it */
151 RtlInitUnicodeString (&GdiDriverInfo
.ModuleName
, (LPWSTR
)FullName
);
152 Status
= ZwSetSystemInformation (SystemLoadImage
, &GdiDriverInfo
, sizeof(SYSTEM_LOAD_IMAGE
));
153 ExFreePool(FullName
);
154 if (!NT_SUCCESS(Status
)) return NULL
;
156 DRIVER_RegisterDriver( L
"DISPLAY", GdiDriverInfo
.EntryPoint
);
157 return (PGD_ENABLEDRIVER
)GdiDriverInfo
.EntryPoint
;
160 #define BEGIN_FUNCTION_MAP() \
162 for (i = 0; i < DED->c; i++) \
164 switch(DED->pdrvfn[i].iFunc) \
167 #define DRIVER_FUNCTION(function) \
168 case INDEX_Drv##function: \
169 *(PVOID*)&DF->function = DED->pdrvfn[i].pfn; \
172 #define END_FUNCTION_MAP() \
174 DPRINT1("Unsupported DDI function 0x%x\n", DED->pdrvfn[i].iFunc); \
179 BOOL
DRIVER_BuildDDIFunctions(PDRVENABLEDATA DED
,
180 PDRIVER_FUNCTIONS DF
)
182 BEGIN_FUNCTION_MAP();
184 DRIVER_FUNCTION(EnablePDEV
);
185 DRIVER_FUNCTION(CompletePDEV
);
186 DRIVER_FUNCTION(DisablePDEV
);
187 DRIVER_FUNCTION(EnableSurface
);
188 DRIVER_FUNCTION(DisableSurface
);
189 DRIVER_FUNCTION(AssertMode
);
190 DRIVER_FUNCTION(ResetPDEV
);
191 DRIVER_FUNCTION(CreateDeviceBitmap
);
192 DRIVER_FUNCTION(DeleteDeviceBitmap
);
193 DRIVER_FUNCTION(RealizeBrush
);
194 DRIVER_FUNCTION(DitherColor
);
195 DRIVER_FUNCTION(StrokePath
);
196 DRIVER_FUNCTION(FillPath
);
197 DRIVER_FUNCTION(StrokeAndFillPath
);
198 DRIVER_FUNCTION(Paint
);
199 DRIVER_FUNCTION(BitBlt
);
200 DRIVER_FUNCTION(TransparentBlt
);
201 DRIVER_FUNCTION(CopyBits
);
202 DRIVER_FUNCTION(StretchBlt
);
203 DRIVER_FUNCTION(SetPalette
);
204 DRIVER_FUNCTION(TextOut
);
205 DRIVER_FUNCTION(Escape
);
206 DRIVER_FUNCTION(DrawEscape
);
207 DRIVER_FUNCTION(QueryFont
);
208 DRIVER_FUNCTION(QueryFontTree
);
209 DRIVER_FUNCTION(QueryFontData
);
210 DRIVER_FUNCTION(SetPointerShape
);
211 DRIVER_FUNCTION(MovePointer
);
212 DRIVER_FUNCTION(LineTo
);
213 DRIVER_FUNCTION(SendPage
);
214 DRIVER_FUNCTION(StartPage
);
215 DRIVER_FUNCTION(EndDoc
);
216 DRIVER_FUNCTION(StartDoc
);
217 DRIVER_FUNCTION(GetGlyphMode
);
218 DRIVER_FUNCTION(Synchronize
);
219 DRIVER_FUNCTION(SaveScreenBits
);
220 DRIVER_FUNCTION(GetModes
);
221 DRIVER_FUNCTION(Free
);
222 DRIVER_FUNCTION(DestroyFont
);
223 DRIVER_FUNCTION(QueryFontCaps
);
224 DRIVER_FUNCTION(LoadFontFile
);
225 DRIVER_FUNCTION(UnloadFontFile
);
226 DRIVER_FUNCTION(FontManagement
);
227 DRIVER_FUNCTION(QueryTrueTypeTable
);
228 DRIVER_FUNCTION(QueryTrueTypeOutline
);
229 DRIVER_FUNCTION(GetTrueTypeFile
);
230 DRIVER_FUNCTION(QueryFontFile
);
231 DRIVER_FUNCTION(QueryAdvanceWidths
);
232 DRIVER_FUNCTION(SetPixelFormat
);
233 DRIVER_FUNCTION(DescribePixelFormat
);
234 DRIVER_FUNCTION(SwapBuffers
);
235 DRIVER_FUNCTION(StartBanding
);
236 DRIVER_FUNCTION(NextBand
);
237 DRIVER_FUNCTION(GetDirectDrawInfo
);
238 DRIVER_FUNCTION(EnableDirectDraw
);
239 DRIVER_FUNCTION(DisableDirectDraw
);
240 DRIVER_FUNCTION(QuerySpoolType
);
241 DRIVER_FUNCTION(GradientFill
);
248 typedef LONG VP_STATUS
;
249 typedef VP_STATUS (STDCALL
*PMP_DRIVERENTRY
)(PVOID
, PVOID
);
251 PFILE_OBJECT
DRIVER_FindMPDriver(ULONG DisplayNumber
)
253 OBJECT_ATTRIBUTES ObjectAttributes
;
254 WCHAR DeviceNameBuffer
[20];
255 UNICODE_STRING DeviceName
;
256 IO_STATUS_BLOCK Iosb
;
257 HANDLE DisplayHandle
;
259 PFILE_OBJECT VideoFileObject
;
261 swprintf(DeviceNameBuffer
, L
"\\??\\DISPLAY%d", DisplayNumber
+ 1);
262 RtlInitUnicodeString(&DeviceName
, DeviceNameBuffer
);
263 InitializeObjectAttributes(&ObjectAttributes
,
268 Status
= ZwOpenFile(&DisplayHandle
,
273 FILE_SYNCHRONOUS_IO_ALERT
);
274 if (NT_SUCCESS(Status
))
276 Status
= ObReferenceObjectByHandle(DisplayHandle
,
277 FILE_READ_DATA
| FILE_WRITE_DATA
,
280 (PVOID
*)&VideoFileObject
,
282 ZwClose(DisplayHandle
);
285 if (!NT_SUCCESS(Status
))
287 DPRINT1("Unable to connect to miniport (Status %lx)\n", Status
);
288 DPRINT1("Perhaps the miniport wasn't loaded?\n");
292 return VideoFileObject
;
296 BOOL
DRIVER_UnregisterDriver(LPCWSTR Name
)
298 PGRAPHICS_DRIVER Driver
= NULL
;
302 if (DriverList
!= NULL
)
304 if (!_wcsicmp(DriverList
->Name
, Name
))
307 DriverList
= DriverList
->Next
;
312 while (Driver
->Next
&& _wcsicmp(Driver
->Name
, Name
))
314 Driver
= Driver
->Next
;
321 if (GenericDriver
!= NULL
)
323 Driver
= GenericDriver
;
324 GenericDriver
= NULL
;
330 ExFreePool(Driver
->Name
);
341 INT
DRIVER_ReferenceDriver (LPCWSTR Name
)
343 GRAPHICS_DRIVER
*Driver
= DriverList
;
345 while (Driver
&& Name
)
347 DPRINT( "Comparing %S to %S\n", Driver
->Name
, Name
);
348 if (!_wcsicmp( Driver
->Name
, Name
))
350 return ++Driver
->ReferenceCount
;
352 Driver
= Driver
->Next
;
354 DPRINT( "Driver %S not found to reference, generic count: %d\n", Name
, GenericDriver
->ReferenceCount
);
355 assert( GenericDriver
!= 0 );
356 return ++GenericDriver
->ReferenceCount
;
359 INT
DRIVER_UnreferenceDriver (LPCWSTR Name
)
361 GRAPHICS_DRIVER
*Driver
= DriverList
;
363 while (Driver
&& Name
)
365 DPRINT( "Comparing %S to %S\n", Driver
->Name
, Name
);
366 if (!_wcsicmp( Driver
->Name
, Name
))
368 return --Driver
->ReferenceCount
;
370 Driver
= Driver
->Next
;
372 DPRINT( "Driver '%S' not found to dereference, generic count: %d\n", Name
, GenericDriver
->ReferenceCount
);
373 assert( GenericDriver
!= 0 );
374 return --GenericDriver
->ReferenceCount
;