ReactOS 0.4.15-dev-6068-g8061a6f
enable.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Framebuffer Display Driver
3 * LICENSE: Microsoft NT4 DDK Sample Code License
4 * FILE: win32ss/drivers/displays/framebuf_new/enable.c
5 * PURPOSE: Main Driver Initialization and PDEV Enabling
6 * PROGRAMMERS: Copyright (c) 1992-1995 Microsoft Corporation
7 * ReactOS Portable Systems Group
8 */
9
10#include "driver.h"
11
12// The driver function table with all function index/address pairs
13
14static DRVFN gadrvfn[] =
15{
26};
27
28// Define the functions you want to hook for 8/16/24/32 pel formats
29
30#define HOOKS_BMF8BPP 0
31
32#define HOOKS_BMF16BPP 0
33
34#define HOOKS_BMF24BPP 0
35
36#define HOOKS_BMF32BPP 0
37
38/******************************Public*Routine******************************\
39* DrvEnableDriver
40*
41* Enables the driver by retrieving the drivers function table and version.
42*
43\**************************************************************************/
44
46ULONG iEngineVersion,
47ULONG cj,
49{
50// Engine Version is passed down so future drivers can support previous
51// engine versions. A next generation driver can support both the old
52// and new engine conventions if told what version of engine it is
53// working with. For the first version the driver does nothing with it.
54// eVb: 1.1 [DDK Change] - Remove bogus statement
55 //iEngineVersion;
56// eVb: 1.1 [END]
57// Fill in as much as we can.
58
59 if (cj >= sizeof(DRVENABLEDATA))
60 pded->pdrvfn = gadrvfn;
61
62 if (cj >= (sizeof(ULONG) * 2))
63 pded->c = sizeof(gadrvfn) / sizeof(DRVFN);
64
65// DDI version this driver was targeted for is passed back to engine.
66// Future graphic's engine may break calls down to old driver format.
67
68 if (cj >= sizeof(ULONG))
69// eVb: 1.2 [DDK Change] - Use DDI_DRIVER_VERSION_NT4 instead of DDI_DRIVER_VERSION
71// eVb: 1.2 [END]
72
73 return TRUE;
74}
75
76/******************************Public*Routine******************************\
77* DrvEnablePDEV
78*
79* DDI function, Enables the Physical Device.
80*
81* Return Value: device handle to pdev.
82*
83\**************************************************************************/
84
86DEVMODEW *pDevmode, // Pointer to DEVMODE
87PWSTR pwszLogAddress, // Logical address
88ULONG cPatterns, // number of patterns
89HSURF *ahsurfPatterns, // return standard patterns
90ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
91ULONG *pGdiInfo, // Pointer to GdiInfo structure
92ULONG cjDevInfo, // Length of following PDEVINFO structure
93DEVINFO *pDevInfo, // physical device information structure
94HDEV hdev, // HDEV, used for callbacks
95PWSTR pwszDeviceName, // DeviceName - not used
96HANDLE hDriver) // Handle to base driver
97{
98 GDIINFO GdiInfo;
99 DEVINFO DevInfo;
100 PPDEV ppdev = NULL;
101
104
105 // Allocate a physical device structure.
106
107 ppdev = (PPDEV) EngAllocMem(0, sizeof(PDEV), ALLOC_TAG);
108
109 if (ppdev == NULL)
110 {
111 RIP("DISP DrvEnablePDEV failed EngAllocMem\n");
112 return NULL;
113 }
114
115 memset(ppdev, 0, sizeof(PDEV));
116
117 // Save the screen handle in the PDEV.
118
119 ppdev->hDriver = hDriver;
120
121 // Get the current screen mode information. Set up device caps and devinfo.
122
123 if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
124 {
125 DISPDBG((0,"DISP DrvEnablePDEV failed\n"));
126 goto error_free;
127 }
128
129 // Initialize the cursor information.
130
131 if (!bInitPointer(ppdev, &DevInfo))
132 {
133 // Not a fatal error...
134 DISPDBG((0, "DrvEnablePDEV failed bInitPointer\n"));
135 }
136
137 // Initialize palette information.
138
139 if (!bInitPaletteInfo(ppdev, &DevInfo))
140 {
141 RIP("DrvEnablePDEV failed bInitPalette\n");
142 goto error_free;
143 }
144
145 // Copy the devinfo into the engine buffer.
146
147 memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
148
149 // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
150 // pdev.
151
152 memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
153
154 return (DHPDEV)ppdev;
155
156 // Error case for failure.
157error_free:
158 EngFreeMem(ppdev);
159 return NULL;
160}
161
162/******************************Public*Routine******************************\
163* DrvCompletePDEV
164*
165* Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
166*
167\**************************************************************************/
168
170DHPDEV dhpdev,
171HDEV hdev)
172{
173 ((PPDEV) dhpdev)->hdevEng = hdev;
174}
175
176/******************************Public*Routine******************************\
177* DrvDisablePDEV
178*
179* Release the resources allocated in DrvEnablePDEV. If a surface has been
180* enabled DrvDisableSurface will have already been called.
181*
182\**************************************************************************/
183
185DHPDEV dhpdev)
186{
187 vDisablePalette((PPDEV) dhpdev);
188 EngFreeMem(dhpdev);
189}
190
191/******************************Public*Routine******************************\
192* DrvEnableSurface
193*
194* Enable the surface for the device. Hook the calls this driver supports.
195*
196* Return: Handle to the surface if successful, 0 for failure.
197*
198\**************************************************************************/
199
201DHPDEV dhpdev)
202{
203 PPDEV ppdev;
204 HSURF hsurf;
205 SIZEL sizl;
206 ULONG ulBitmapType;
207 FLONG flHooks;
208
209 // Create engine bitmap around frame buffer.
210
211 ppdev = (PPDEV) dhpdev;
212
213 if (!bInitSURF(ppdev, TRUE))
214 {
215 RIP("DISP DrvEnableSurface failed bInitSURF\n");
216 return NULL;
217 }
218
219 sizl.cx = ppdev->cxScreen;
220 sizl.cy = ppdev->cyScreen;
221
222 if (ppdev->ulBitCount == 8)
223 {
224 if (!bInit256ColorPalette(ppdev)) {
225 RIP("DISP DrvEnableSurface failed to init the 8bpp palette\n");
226 return NULL;
227 }
228 ulBitmapType = BMF_8BPP;
229 flHooks = HOOKS_BMF8BPP;
230 }
231 else if (ppdev->ulBitCount == 16)
232 {
233 ulBitmapType = BMF_16BPP;
234 flHooks = HOOKS_BMF16BPP;
235 }
236 else if (ppdev->ulBitCount == 24)
237 {
238 ulBitmapType = BMF_24BPP;
239 flHooks = HOOKS_BMF24BPP;
240 }
241 else
242 {
243 ulBitmapType = BMF_32BPP;
244 flHooks = HOOKS_BMF32BPP;
245 }
246// eVb: 1.3 [DDK Change] - Support new VGA Miniport behavior w.r.t updated framebuffer remapping
247 ppdev->flHooks = flHooks;
248// eVb: 1.3 [END]
249// eVb: 1.4 [DDK Change] - Use EngCreateDeviceSurface instead of EngCreateBitmap
250 hsurf = (HSURF)EngCreateDeviceSurface((DHSURF)ppdev,
251 sizl,
252 ulBitmapType);
253
254 if (hsurf == NULL)
255 {
256 RIP("DISP DrvEnableSurface failed EngCreateDeviceSurface\n");
257 return NULL;
258 }
259// eVb: 1.4 [END]
260
261// eVb: 1.5 [DDK Change] - Use EngModifySurface instead of EngAssociateSurface
262 if ( !EngModifySurface(hsurf,
263 ppdev->hdevEng,
264 ppdev->flHooks | HOOK_SYNCHRONIZE,
266 (DHSURF)ppdev,
267 ppdev->pjScreen,
268 ppdev->lDeltaScreen,
269 NULL))
270 {
271 RIP("DISP DrvEnableSurface failed EngModifySurface\n");
272 return NULL;
273 }
274// eVb: 1.5 [END]
275 ppdev->hsurfEng = hsurf;
276
277 return hsurf;
278}
279
280/******************************Public*Routine******************************\
281* DrvDisableSurface
282*
283* Free resources allocated by DrvEnableSurface. Release the surface.
284*
285\**************************************************************************/
286
288DHPDEV dhpdev)
289{
290 EngDeleteSurface(((PPDEV) dhpdev)->hsurfEng);
291 vDisableSURF((PPDEV) dhpdev);
292 ((PPDEV) dhpdev)->hsurfEng = NULL;
293}
294
295/******************************Public*Routine******************************\
296* DrvAssertMode
297*
298* This asks the device to reset itself to the mode of the pdev passed in.
299*
300\**************************************************************************/
301
303DHPDEV dhpdev,
305{
306 PPDEV ppdev = (PPDEV) dhpdev;
307 ULONG ulReturn;
308 PBYTE pjScreen;
309
310 if (bEnable)
311 {
312 //
313 // The screen must be reenabled, reinitialize the device to clean state.
314 //
315// eVb: 1.6 [DDK Change] - Support new VGA Miniport behavior w.r.t updated framebuffer remapping
316 pjScreen = ppdev->pjScreen;
317
318 if (!bInitSURF(ppdev, FALSE))
319 {
320 DISPDBG((0, "DISP DrvAssertMode failed bInitSURF\n"));
321 return FALSE;
322 }
323
324 if (pjScreen != ppdev->pjScreen) {
325
326 if ( !EngModifySurface(ppdev->hsurfEng,
327 ppdev->hdevEng,
328 ppdev->flHooks | HOOK_SYNCHRONIZE,
330 (DHSURF)ppdev,
331 ppdev->pjScreen,
332 ppdev->lDeltaScreen,
333 NULL))
334 {
335 DISPDBG((0, "DISP DrvAssertMode failed EngModifySurface\n"));
336 return FALSE;
337 }
338 }
339// eVb: 1.6 [END]
340 return TRUE;
341 }
342 else
343 {
344 //
345 // We must give up the display.
346 // Call the kernel driver to reset the device to a known state.
347 //
348
349 if (EngDeviceIoControl(ppdev->hDriver,
351 NULL,
352 0,
353 NULL,
354 0,
355 &ulReturn))
356 {
357 RIP("DISP DrvAssertMode failed IOCTL");
358 return FALSE;
359 }
360 else
361 {
362 return TRUE;
363 }
364 }
365}
366
367/******************************Public*Routine******************************\
368* DrvGetModes
369*
370* Returns the list of available modes for the device.
371*
372\**************************************************************************/
373
377DEVMODEW *pdm)
378
379{
380
381 DWORD cModes;
382 DWORD cbOutputSize;
383 PVIDEO_MODE_INFORMATION pVideoModeInformation, pVideoTemp;
384 DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
385 DWORD cbModeSize;
386
387 DISPDBG((3, "DrvGetModes\n"));
388
389 cModes = getAvailableModes(hDriver,
390 (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
391 &cbModeSize);
392
393 if (cModes == 0)
394 {
395 DISPDBG((0, "DrvGetModes failed to get mode information"));
396 return 0;
397 }
398
399 if (pdm == NULL)
400 {
401 cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
402 }
403 else
404 {
405 //
406 // Now copy the information for the supported modes back into the output
407 // buffer
408 //
409
410 cbOutputSize = 0;
411
412 pVideoTemp = pVideoModeInformation;
413
414 do
415 {
416 if (pVideoTemp->Length != 0)
417 {
418 if (cOutputModes == 0)
419 {
420 break;
421 }
422
423 //
424 // Zero the entire structure to start off with.
425 //
426
427 memset(pdm, 0, sizeof(DEVMODEW));
428
429 //
430 // Set the name of the device to the name of the DLL.
431 //
432
433 memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
434
437 pdm->dmSize = sizeof(DEVMODEW);
439
440 pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
441 pVideoTemp->BitsPerPlane;
442 pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
443 pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
444 pdm->dmDisplayFrequency = pVideoTemp->Frequency;
445 pdm->dmDisplayFlags = 0;
446
447 pdm->dmFields = DM_BITSPERPEL |
452
453 //
454 // Go to the next DEVMODE entry in the buffer.
455 //
456
457 cOutputModes--;
458
459 pdm = (LPDEVMODEW) ( ((ULONG_PTR)pdm) + sizeof(DEVMODEW) +
461
462 cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
463
464 }
465
466 pVideoTemp = (PVIDEO_MODE_INFORMATION)
467 (((PUCHAR)pVideoTemp) + cbModeSize);
468
469 } while (--cModes);
470 }
471
472 EngFreeMem(pVideoModeInformation);
473
474 return cbOutputSize;
475
476}
#define ALLOC_TAG
Definition: btrfs_drv.h:87
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _PDEV * PPDEV
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55
unsigned long FLONG
Definition: ntbasedef.h:366
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
struct _VIDEO_MODE_INFORMATION * PVIDEO_MODE_INFORMATION
#define IOCTL_VIDEO_RESET_DEVICE
Definition: ntddvdeo.h:137
BYTE * PBYTE
Definition: pedump.c:66
#define EngFreeMem
Definition: polytest.cpp:56
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
#define memset(x, y, z)
Definition: compat.h:39
Definition: winddi.h:529
Definition: framebuf.h:34
LONG flHooks
Definition: driver.h:51
HSURF hsurfEng
Definition: driver.h:26
PBYTE pjScreen
Definition: driver.h:28
HDEV hdevEng
Definition: driver.h:25
ULONG ulBitCount
Definition: driver.h:42
HANDLE hDriver
Definition: framebuf.h:35
LONG lDeltaScreen
Definition: driver.h:32
ULONG cyScreen
Definition: driver.h:30
ULONG cxScreen
Definition: driver.h:29
DWORD dmBitsPerPel
Definition: wingdi.h:1647
WCHAR dmDeviceName[CCHDEVICENAME]
Definition: wingdi.h:1617
DWORD dmFields
Definition: wingdi.h:1622
DWORD dmPelsWidth
Definition: wingdi.h:1648
WORD dmDriverExtra
Definition: wingdi.h:1621
WORD dmSpecVersion
Definition: wingdi.h:1618
DWORD dmDisplayFlags
Definition: wingdi.h:1651
DWORD dmPelsHeight
Definition: wingdi.h:1649
DWORD dmDisplayFrequency
Definition: wingdi.h:1654
WORD dmSize
Definition: wingdi.h:1620
WORD dmDriverVersion
Definition: wingdi.h:1619
ULONG iDriverVersion
Definition: winddi.h:542
DRVFN * pdrvfn
Definition: winddi.h:544
uint16_t * PWSTR
Definition: typedefs.h:56
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define RIP(x)
Definition: debug.h:24
#define DISPDBG(arg)
Definition: debug.h:23
#define DLL_NAME
Definition: driver.h:73
BOOL NTAPI bInit256ColorPalette(PPDEV)
Definition: palette.c:193
VOID NTAPI vDisableSURF(PPDEV)
Definition: screen.c:172
BOOL NTAPI bInitPointer(PPDEV, DEVINFO *)
Definition: pointer.c:400
BOOL NTAPI bInitPaletteInfo(PPDEV, DEVINFO *)
Definition: palette.c:50
#define DRIVER_EXTRA_SIZE
Definition: driver.h:71
DWORD NTAPI getAvailableModes(HANDLE, PVIDEO_MODE_INFORMATION *, DWORD *)
Definition: screen.c:507
BOOL NTAPI bInitSURF(PPDEV, BOOL)
Definition: screen.c:43
BOOL NTAPI bInitPDEV(PPDEV, PDEVMODEW, GDIINFO *, DEVINFO *)
VOID NTAPI vDisablePalette(PPDEV)
Definition: palette.c:65
static DRVFN gadrvfn[]
Definition: enable.c:14
#define HOOKS_BMF32BPP
Definition: enable.c:36
#define HOOKS_BMF8BPP
Definition: enable.c:30
#define HOOKS_BMF16BPP
Definition: enable.c:32
#define HOOKS_BMF24BPP
Definition: enable.c:34
#define INDEX_DrvSetPointerShape
Definition: winddi.h:445
#define BMF_16BPP
Definition: winddi.h:358
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG cjDevInfo
Definition: winddi.h:3553
#define BMF_8BPP
Definition: winddi.h:357
#define DDI_DRIVER_VERSION_NT4
Definition: winddi.h:535
LONG_PTR(APIENTRY * PFN)()
Definition: winddi.h:133
typedef DHPDEV(APIENTRY FN_DrvEnablePDEV)(_In_ DEVMODEW *pdm
ENGAPI BOOL APIENTRY EngDeleteSurface(_In_ _Post_ptr_invalid_ HSURF hsurf)
Definition: surface.c:567
FN_DrvSetPalette DrvSetPalette
#define INDEX_DrvDisableSurface
Definition: winddi.h:420
#define INDEX_DrvMovePointer
Definition: winddi.h:446
ENGAPI BOOL APIENTRY EngModifySurface(_In_ HSURF hsurf, _In_ HDEV hdev, _In_ FLONG flHooks, _In_ FLONG flSurface, _In_ DHSURF dhsurf, _In_ PVOID pvScan0, _In_ LONG lDelta, _Reserved_ PVOID pvReserved)
Definition: surface.c:471
_In_ HDEV hdev
Definition: winddi.h:3449
_In_ LPWSTR pwszLogAddress
Definition: winddi.h:3548
FN_DrvSetPointerShape DrvSetPointerShape
#define MS_NOTSYSTEMMEMORY
Definition: winddi.h:2129
FN_DrvGetModes DrvGetModes
#define INDEX_DrvCompletePDEV
Definition: winddi.h:417
_Must_inspect_result_ ENGAPI HSURF APIENTRY EngCreateDeviceSurface(_In_ DHSURF dhsurf, _In_ SIZEL sizl, _In_ ULONG iFormatCompat)
Definition: surface.c:391
#define INDEX_DrvSetPalette
Definition: winddi.h:438
_In_ ULONG cj
Definition: winddi.h:3540
#define BMF_24BPP
Definition: winddi.h:359
FN_DrvEnableSurface DrvEnableSurface
#define INDEX_DrvEnablePDEV
Definition: winddi.h:416
#define BMF_32BPP
Definition: winddi.h:360
FN_DrvMovePointer DrvMovePointer
typedef HSURF(APIENTRY FN_DrvEnableSurface)(_In_ DHPDEV dhpdev)
FN_DrvCompletePDEV DrvCompletePDEV
#define INDEX_DrvAssertMode
Definition: winddi.h:421
_In_ ULONG cjSize
Definition: winddi.h:3634
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR pwszDeviceName
Definition: winddi.h:3556
_In_ BOOL bEnable
Definition: winddi.h:3426
#define HOOK_SYNCHRONIZE
Definition: winddi.h:1431
FN_DrvEnablePDEV DrvEnablePDEV
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3557
FN_DrvEnableDriver DrvEnableDriver
FN_DrvAssertMode DrvAssertMode
FN_DrvDisableSurface DrvDisableSurface
FN_DrvDisablePDEV DrvDisablePDEV
_In_ SIZEL sizl
Definition: winddi.h:3467
#define INDEX_DrvEnableSurface
Definition: winddi.h:419
#define INDEX_DrvDisablePDEV
Definition: winddi.h:418
#define INDEX_DrvGetModes
Definition: winddi.h:457
#define DM_DISPLAYFREQUENCY
Definition: wingdi.h:1272
#define DM_PELSWIDTH
Definition: wingdi.h:1269
struct _devicemodeW * LPDEVMODEW
struct _devicemodeW DEVMODEW
#define DM_BITSPERPEL
Definition: wingdi.h:1268
#define DM_SPECVERSION
Definition: wingdi.h:1243
#define DM_PELSHEIGHT
Definition: wingdi.h:1270
#define DM_DISPLAYFLAGS
Definition: wingdi.h:1271