1 /* $Id: driver.c,v 1.13 2000/07/07 01:18:04 phreak Exp $
3 * GDI Driver support routines
4 * (mostly swiped from Wine)
8 #undef WIN32_LEAN_AND_MEAN
11 #include <ddk/ntddk.h>
13 #include <win32k/driver.h>
15 #include "../../ntoskrnl/include/internal/module.h"
16 #include <ddk/winddi.h>
17 #include <ddk/ntddvid.h>
22 typedef struct _GRAPHICS_DRIVER
25 PGD_ENABLEDRIVER EnableDriver
;
27 struct _GRAPHICS_DRIVER
*Next
;
28 } GRAPHICS_DRIVER
, *PGRAPHICS_DRIVER
;
30 static PGRAPHICS_DRIVER DriverList
;
31 static PGRAPHICS_DRIVER GenericDriver
= 0;
33 BOOL
DRIVER_RegisterDriver(LPCWSTR Name
, PGD_ENABLEDRIVER EnableDriver
)
35 PGRAPHICS_DRIVER Driver
= ExAllocatePool(NonPagedPool
, sizeof(*Driver
));
36 DPRINT( "DRIVER_RegisterDriver( Name: %S )\n", Name
);
41 Driver
->ReferenceCount
= 0;
42 Driver
->EnableDriver
= EnableDriver
;
45 Driver
->Name
= ExAllocatePool(PagedPool
,
46 (wcslen(Name
) + 1) * sizeof(WCHAR
));
47 wcscpy(Driver
->Name
, Name
);
48 Driver
->Next
= DriverList
;
53 if (GenericDriver
!= NULL
)
60 GenericDriver
= Driver
;
64 PGD_ENABLEDRIVER
DRIVER_FindDDIDriver(LPCWSTR Name
)
66 UNICODE_STRING DriverNameW
;
67 PMODULE_OBJECT ModuleObject
;
68 GRAPHICS_DRIVER
*Driver
= DriverList
;
70 /* First see if the driver hasn't already been loaded */
71 while (Driver
&& Name
)
73 if (!_wcsicmp( Driver
->Name
, Name
))
75 return Driver
->EnableDriver
;
77 Driver
= Driver
->Next
;
80 /* If not, then load it */
81 RtlInitUnicodeString (&DriverNameW
, Name
);
83 ModuleObject
= EngLoadImage(&DriverNameW
);
84 DRIVER_RegisterDriver( L
"DISPLAY", ModuleObject
->EntryPoint
);
85 return (PGD_ENABLEDRIVER
)ModuleObject
->EntryPoint
;
88 BOOL
DRIVER_BuildDDIFunctions(PDRVENABLEDATA DED
,
93 for (i
=0; i
<DED
->c
; i
++)
95 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvEnablePDEV
) DF
->EnablePDev
= (PGD_ENABLEPDEV
)DED
->pdrvfn
[i
].pfn
;
96 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvCompletePDEV
) DF
->CompletePDev
= (PGD_COMPLETEPDEV
)DED
->pdrvfn
[i
].pfn
;
97 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvDisablePDEV
) DF
->DisablePDev
= (PGD_DISABLEPDEV
)DED
->pdrvfn
[i
].pfn
;
98 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvEnableSurface
) DF
->EnableSurface
= (PGD_ENABLESURFACE
)DED
->pdrvfn
[i
].pfn
;
99 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvDisableSurface
) DF
->DisableSurface
= (PGD_DISABLESURFACE
)DED
->pdrvfn
[i
].pfn
;
100 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvAssertMode
) DF
->AssertMode
= (PGD_ASSERTMODE
)DED
->pdrvfn
[i
].pfn
;
101 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvResetPDEV
) DF
->ResetPDev
= (PGD_RESETPDEV
)DED
->pdrvfn
[i
].pfn
;
102 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvCreateDeviceBitmap
)
103 DF
->CreateDeviceBitmap
= (PGD_CREATEDEVICEBITMAP
)DED
->pdrvfn
[i
].pfn
;
104 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvDeleteDeviceBitmap
)
105 DF
->DeleteDeviceBitmap
= (PGD_DELETEDEVICEBITMAP
)DED
->pdrvfn
[i
].pfn
;
106 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvRealizeBrush
) DF
->RealizeBrush
= (PGD_REALIZEBRUSH
)DED
->pdrvfn
[i
].pfn
;
107 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvDitherColor
) DF
->DitherColor
= (PGD_DITHERCOLOR
)DED
->pdrvfn
[i
].pfn
;
108 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvStrokePath
) DF
->StrokePath
= (PGD_STROKEPATH
)DED
->pdrvfn
[i
].pfn
;
109 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvFillPath
) DF
->FillPath
= (PGD_FILLPATH
)DED
->pdrvfn
[i
].pfn
;
110 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvStrokeAndFillPath
)
111 DF
->StrokeAndFillPath
= (PGD_STROKEANDFILLPATH
)DED
->pdrvfn
[i
].pfn
;
112 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvPaint
) DF
->Paint
= (PGD_PAINT
)DED
->pdrvfn
[i
].pfn
;
113 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvBitBlt
) DF
->BitBlt
= (PGD_BITBLT
)DED
->pdrvfn
[i
].pfn
;
114 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvCopyBits
) DF
->CopyBits
= (PGD_COPYBITS
)DED
->pdrvfn
[i
].pfn
;
115 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvStretchBlt
) DF
->StretchBlt
= (PGD_STRETCHBLT
)DED
->pdrvfn
[i
].pfn
;
116 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvSetPalette
) DF
->SetPalette
= (PGD_SETPALETTE
)DED
->pdrvfn
[i
].pfn
;
117 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvTextOut
) DF
->TextOut
= (PGD_TEXTOUT
)DED
->pdrvfn
[i
].pfn
;
118 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvEscape
) DF
->Escape
= (PGD_ESCAPE
)DED
->pdrvfn
[i
].pfn
;
119 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvDrawEscape
) DF
->DrawEscape
= (PGD_DRAWESCAPE
)DED
->pdrvfn
[i
].pfn
;
120 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvQueryFont
) DF
->QueryFont
= (PGD_QUERYFONT
)DED
->pdrvfn
[i
].pfn
;
121 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvQueryFontTree
) DF
->QueryFontTree
= (PGD_QUERYFONTTREE
)DED
->pdrvfn
[i
].pfn
;
122 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvQueryFontData
) DF
->QueryFontData
= (PGD_QUERYFONTDATA
)DED
->pdrvfn
[i
].pfn
;
123 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvSetPointerShape
) DF
->SetPointerShape
= (PGD_SETPOINTERSHAPE
)DED
->pdrvfn
[i
].pfn
;
124 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvMovePointer
) DF
->MovePointer
= (PGD_MOVEPOINTER
)DED
->pdrvfn
[i
].pfn
;
125 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvLineTo
) DF
->LineTo
= (PGD_LINETO
)DED
->pdrvfn
[i
].pfn
;
126 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvSendPage
) DF
->SendPage
= (PGD_SENDPAGE
)DED
->pdrvfn
[i
].pfn
;
127 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvStartPage
) DF
->StartPage
= (PGD_STARTPAGE
)DED
->pdrvfn
[i
].pfn
;
128 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvEndDoc
) DF
->EndDoc
= (PGD_ENDDOC
)DED
->pdrvfn
[i
].pfn
;
129 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvStartDoc
) DF
->StartDoc
= (PGD_STARTDOC
)DED
->pdrvfn
[i
].pfn
;
130 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvGetGlyphMode
) DF
->GetGlyphMode
= (PGD_GETGLYPHMODE
)DED
->pdrvfn
[i
].pfn
;
131 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvSynchronize
) DF
->Synchronize
= (PGD_SYNCHRONIZE
)DED
->pdrvfn
[i
].pfn
;
132 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvSaveScreenBits
) DF
->SaveScreenBits
= (PGD_SAVESCREENBITS
)DED
->pdrvfn
[i
].pfn
;
133 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvGetModes
) DF
->GetModes
= (PGD_GETMODES
)DED
->pdrvfn
[i
].pfn
;
134 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvFree
) DF
->Free
= (PGD_FREE
)DED
->pdrvfn
[i
].pfn
;
135 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvDestroyFont
) DF
->DestroyFont
= (PGD_DESTROYFONT
)DED
->pdrvfn
[i
].pfn
;
136 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvQueryFontCaps
) DF
->QueryFontCaps
= (PGD_LOADFONTFILE
)DED
->pdrvfn
[i
].pfn
;
137 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvLoadFontFile
) DF
->LoadFontFile
= (PGD_LOADFONTFILE
)DED
->pdrvfn
[i
].pfn
;
138 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvUnloadFontFile
) DF
->UnloadFontFile
= (PGD_UNLOADFONTFILE
)DED
->pdrvfn
[i
].pfn
;
139 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvFontManagement
) DF
->FontManagement
= (PGD_FONTMANAGEMENT
)DED
->pdrvfn
[i
].pfn
;
140 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvQueryTrueTypeTable
)
141 DF
->QueryTrueTypeTable
= (PGD_QUERYTRUETYPETABLE
)DED
->pdrvfn
[i
].pfn
;
142 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvQueryTrueTypeOutline
)
143 DF
->QueryTrueTypeOutline
= (PGD_QUERYTRUETYPEOUTLINE
)DED
->pdrvfn
[i
].pfn
;
144 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvGetTrueTypeFile
) DF
->GetTrueTypeFile
= (PGD_GETTRUETYPEFILE
)DED
->pdrvfn
[i
].pfn
;
145 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvQueryFontFile
) DF
->QueryFontFile
= (PGD_QUERYFONTFILE
)DED
->pdrvfn
[i
].pfn
;
146 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvQueryAdvanceWidths
)
147 DF
->QueryAdvanceWidths
= (PGD_QUERYADVANCEWIDTHS
)DED
->pdrvfn
[i
].pfn
;
148 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvSetPixelFormat
) DF
->SetPixelFormat
= (PGD_SETPIXELFORMAT
)DED
->pdrvfn
[i
].pfn
;
149 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvDescribePixelFormat
)
150 DF
->DescribePixelFormat
= (PGD_DESCRIBEPIXELFORMAT
)DED
->pdrvfn
[i
].pfn
;
151 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvSwapBuffers
) DF
->SwapBuffers
= (PGD_SWAPBUFFERS
)DED
->pdrvfn
[i
].pfn
;
152 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvStartBanding
) DF
->StartBanding
= (PGD_STARTBANDING
)DED
->pdrvfn
[i
].pfn
;
153 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvNextBand
) DF
->NextBand
= (PGD_NEXTBAND
)DED
->pdrvfn
[i
].pfn
;
155 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvGetDirectDrawInfo
) DF
->GETDIRECTDRAWINFO
= (PGD_
)DED
->pdrvfn
[i
].pfn
;
156 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvEnableDirectDraw
) DF
->ENABLEDIRECTDRAW
= (PGD_
)DED
->pdrvfn
[i
].pfn
;
157 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvDisableDirectDraw
) DF
->DISABLEDIRECTDRAW
= (PGD_
)DED
->pdrvfn
[i
].pfn
;
159 if(DED
->pdrvfn
[i
].iFunc
== INDEX_DrvQuerySpoolType
) DF
->QuerySpoolType
= (PGD_QUERYSPOOLTYPE
)DED
->pdrvfn
[i
].pfn
;
165 typedef VP_STATUS (*PMP_DRIVERENTRY
)(PVOID
, PVOID
);
167 HANDLE
DRIVER_FindMPDriver(LPCWSTR Name
)
169 UNICODE_STRING DriverNameW
;
170 PMODULE_OBJECT ModuleObject
;
174 UNICODE_STRING DeviceName
;
176 OBJECT_ATTRIBUTES ObjectAttributes
;
178 PDRIVER_OBJECT DriverObject
;
179 PMP_DRIVERENTRY PMP_DriverEntry
;
182 RtlInitUnicodeString (&DriverNameW
, L
"\\??\\C:\\reactos\\system32\\drivers\\vgamp.sys");
183 ModuleObject
= EngLoadImage(&DriverNameW
);
188 lName
= ExAllocatePool(NonPagedPool
, wcslen(Name
) * sizeof(WCHAR
) +
190 wcscpy(lName
, L
"\\??\\");
191 if (!wcscmp (Name
, L
"DISPLAY"))
193 /* FIXME: Read this information from the registry ??? */
194 wcscat(lName
, L
"DISPLAY1");
203 lName
= ExAllocatePool(NonPagedPool
, wcslen(Name
) * sizeof(WCHAR
));
208 DriverObject
= ExAllocatePool(NonPagedPool
,sizeof(DRIVER_OBJECT
));
209 if (DriverObject
== NULL
)
213 memset(DriverObject
, 0, sizeof(DRIVER_OBJECT
));
215 // We pass the DriverObject to the Miniport driver, which passes it to the VideoPort driver
216 // The VideoPort driver then creates the Device Object
218 PMP_DriverEntry
= ModuleObject
->EntryPoint
;
219 PMP_DriverEntry(DriverObject
, NULL
);
224 BOOL
DRIVER_UnregisterDriver(LPCWSTR Name
)
226 PGRAPHICS_DRIVER Driver
= NULL
;
230 if (DriverList
!= NULL
)
232 if (!_wcsicmp(DriverList
->Name
, Name
))
235 DriverList
= DriverList
->Next
;
240 while (Driver
->Next
&& _wcsicmp(Driver
->Name
, Name
))
242 Driver
= Driver
->Next
;
249 if (GenericDriver
!= NULL
)
251 Driver
= GenericDriver
;
252 GenericDriver
= NULL
;
258 ExFreePool(Driver
->Name
);
269 INT
DRIVER_ReferenceDriver (LPCWSTR Name
)
271 GRAPHICS_DRIVER
*Driver
= DriverList
;
273 while (Driver
&& Name
)
275 DPRINT( "Comparting %S to %S\n", Driver
->Name
, Name
);
276 if (!_wcsicmp( Driver
->Name
, Name
))
278 return ++Driver
->ReferenceCount
;
280 Driver
= Driver
->Next
;
282 DPRINT( "Driver %S not found to reference, generic count: %d\n", Name
, GenericDriver
->ReferenceCount
);
283 assert( GenericDriver
!= 0 );
284 return ++GenericDriver
->ReferenceCount
;
287 INT
DRIVER_UnreferenceDriver (LPCWSTR Name
)
289 GRAPHICS_DRIVER
*Driver
= DriverList
;
291 while (Driver
&& Name
)
293 DPRINT( "Comparting %S to %S\n", Driver
->Name
, Name
);
294 if (!_wcsicmp( Driver
->Name
, Name
))
296 return --Driver
->ReferenceCount
;
298 Driver
= Driver
->Next
;
300 DPRINT( "Driver '%S' not found to dereference, generic count: %d\n", Name
, GenericDriver
->ReferenceCount
);
301 assert( GenericDriver
!= 0 );
302 return --GenericDriver
->ReferenceCount
;