ReactOS  0.4.15-dev-1377-ga59cecd
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 
14 static 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 
46 ULONG iEngineVersion,
47 ULONG cj,
48 PDRVENABLEDATA pded)
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 
86 DEVMODEW *pDevmode, // Pointer to DEVMODE
87 PWSTR pwszLogAddress, // Logical address
88 ULONG cPatterns, // number of patterns
89 HSURF *ahsurfPatterns, // return standard patterns
90 ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
91 ULONG *pGdiInfo, // Pointer to GdiInfo structure
92 ULONG cjDevInfo, // Length of following PDEVINFO structure
93 DEVINFO *pDevInfo, // physical device information structure
94 HDEV hdev, // HDEV, used for callbacks
95 PWSTR pwszDeviceName, // DeviceName - not used
96 HANDLE hDriver) // Handle to base driver
97 {
98  GDIINFO GdiInfo;
99  DEVINFO DevInfo;
100  PPDEV 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 == (PPDEV) NULL)
110  {
111  RIP("DISP DrvEnablePDEV failed EngAllocMem\n");
112  return((DHPDEV) 0);
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.
157 error_free:
158  EngFreeMem(ppdev);
159  return((DHPDEV) 0);
160 }
161 
162 /******************************Public*Routine******************************\
163 * DrvCompletePDEV
164 *
165 * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
166 *
167 \**************************************************************************/
168 
170 DHPDEV dhpdev,
171 HDEV 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 
185 DHPDEV 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 
201 DHPDEV 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(FALSE);
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(FALSE);
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 == (HSURF) 0)
255  {
256  RIP("DISP DrvEnableSurface failed EngCreateDeviceSurface\n");
257  return(FALSE);
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(FALSE);
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 
288 DHPDEV dhpdev)
289 {
290  EngDeleteSurface(((PPDEV) dhpdev)->hsurfEng);
291  vDisableSURF((PPDEV) dhpdev);
292  ((PPDEV) dhpdev)->hsurfEng = (HSURF) 0;
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 
303 DHPDEV dhpdev,
304 BOOL bEnable)
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 
376 ULONG cjSize,
377 DEVMODEW *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 |
448  DM_PELSWIDTH |
449  DM_PELSHEIGHT |
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 BMF_24BPP
Definition: winddi.h:359
HSURF hsurfEng
Definition: driver.h:26
_In_ ULONG cj
Definition: winddi.h:3540
struct _devicemodeW * LPDEVMODEW
#define INDEX_DrvCompletePDEV
Definition: winddi.h:417
typedef DHPDEV(APIENTRY FN_DrvEnablePDEV)(_In_ DEVMODEW *pdm
#define BMF_32BPP
Definition: winddi.h:360
ENGAPI BOOL APIENTRY EngDeleteSurface(_In_ _Post_ptr_invalid_ HSURF hsurf)
Definition: surface.c:564
ULONG NTAPI DrvGetModes(HANDLE hDriver, ULONG cjSize, DEVMODEW *pdm)
Definition: enable.c:374
DWORD dmFields
Definition: wingdi.h:1621
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define DRIVER_EXTRA_SIZE
Definition: driver.h:71
#define INDEX_DrvGetModes
Definition: winddi.h:457
#define EngFreeMem
Definition: polytest.cpp:56
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: retypes.h:3
HSURF NTAPI DrvEnableSurface(DHPDEV dhpdev)
Definition: enable.c:200
#define INDEX_DrvEnablePDEV
Definition: winddi.h:416
BOOL NTAPI DrvAssertMode(DHPDEV dhpdev, BOOL bEnable)
Definition: enable.c:302
#define DLL_NAME
Definition: driver.h:73
#define HOOKS_BMF16BPP
Definition: enable.c:32
#define HOOKS_BMF32BPP
Definition: enable.c:36
VOID APIENTRY DrvDisablePDEV(IN DHPDEV dhpdev)
Definition: enable.c:150
WORD dmDriverExtra
Definition: wingdi.h:1620
#define RIP(x)
Definition: debug.h:24
VOID NTAPI vDisablePalette(PPDEV)
Definition: palette.c:65
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:468
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3553
#define IOCTL_VIDEO_RESET_DEVICE
Definition: ntddvdeo.h:137
DWORD dmBitsPerPel
Definition: wingdi.h:1646
_In_ SIZEL sizl
Definition: winddi.h:3467
#define DM_PELSWIDTH
Definition: wingdi.h:1268
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ALLOC_TAG
Definition: btrfs_drv.h:91
ULONG cyScreen
Definition: driver.h:30
struct _VIDEO_MODE_INFORMATION * PVIDEO_MODE_INFORMATION
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
HANDLE hDriver
Definition: framebuf.h:35
BOOL NTAPI bInitPaletteInfo(PPDEV, DEVINFO *)
Definition: palette.c:50
#define INDEX_DrvAssertMode
Definition: winddi.h:421
unsigned long FLONG
Definition: ntbasedef.h:367
#define BMF_16BPP
Definition: winddi.h:358
BOOL APIENTRY DrvEnableDriver(ULONG iEngineVersion, ULONG cj, PDRVENABLEDATA pded)
Definition: enable.c:50
WORD dmSpecVersion
Definition: wingdi.h:1617
typedef HSURF(APIENTRY FN_DrvEnableSurface)(_In_ DHPDEV dhpdev)
#define DDI_DRIVER_VERSION_NT4
Definition: winddi.h:535
HDEV hdevEng
Definition: driver.h:25
ULONG ulBitCount
Definition: driver.h:42
WORD dmSize
Definition: wingdi.h:1619
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: xlate.c:10
DRVFN * pdrvfn
Definition: winddi.h:544
_In_ LPWSTR pwszLogAddress
Definition: winddi.h:3548
WCHAR dmDeviceName[CCHDEVICENAME]
Definition: wingdi.h:1616
DWORD dmPelsWidth
Definition: wingdi.h:1647
#define DISPDBG(arg)
Definition: debug.h:23
#define MS_NOTSYSTEMMEMORY
Definition: winddi.h:2129
FN_DrvSetPalette DrvSetPalette
#define HOOK_SYNCHRONIZE
Definition: winddi.h:1431
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
LONG flHooks
Definition: driver.h:51
struct _PDEV * PPDEV
VOID NTAPI vDisableSURF(PPDEV)
Definition: screen.c:172
#define INDEX_DrvSetPointerShape
Definition: winddi.h:445
Definition: framebuf.h:33
#define HOOKS_BMF8BPP
Definition: enable.c:30
#define DM_SPECVERSION
Definition: wingdi.h:1242
DWORD NTAPI getAvailableModes(HANDLE, PVIDEO_MODE_INFORMATION *, DWORD *)
Definition: screen.c:507
#define INDEX_DrvSetPalette
Definition: winddi.h:438
#define DM_DISPLAYFREQUENCY
Definition: wingdi.h:1271
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define INDEX_DrvDisableSurface
Definition: winddi.h:420
FN_DrvMovePointer DrvMovePointer
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR pwszDeviceName
Definition: winddi.h:3553
DHPDEV APIENTRY DrvEnablePDEV(IN DEVMODEW *pdm, IN LPWSTR pwszLogAddress, IN ULONG cPat, OUT HSURF *phsurfPatterns, IN ULONG cjCaps, OUT ULONG *pdevcaps, IN ULONG cjDevInfo, OUT DEVINFO *pdi, IN HDEV hdev, IN LPWSTR pwszDeviceName, IN HANDLE hDriver)
Definition: enable.c:78
#define INDEX_DrvEnableSurface
Definition: winddi.h:419
DWORD dmDisplayFrequency
Definition: wingdi.h:1653
FN_DrvSetPointerShape DrvSetPointerShape
BOOLEAN(* PFN)(PARGS)
Definition: parse.h:47
_In_ BOOL bEnable
Definition: winddi.h:3426
VOID APIENTRY DrvCompletePDEV(IN DHPDEV dhpdev, IN HDEV hdev)
Definition: enable.c:132
PBYTE pjScreen
Definition: driver.h:28
BOOL NTAPI bInit256ColorPalette(PPDEV)
Definition: palette.c:193
#define DM_PELSHEIGHT
Definition: wingdi.h:1269
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG cjDevInfo
Definition: winddi.h:3553
ULONG iDriverVersion
Definition: winddi.h:542
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
#define HOOKS_BMF24BPP
Definition: enable.c:34
#define INDEX_DrvDisablePDEV
Definition: winddi.h:418
#define INDEX_DrvMovePointer
Definition: winddi.h:446
DWORD dmPelsHeight
Definition: wingdi.h:1648
_Must_inspect_result_ ENGAPI HSURF APIENTRY EngCreateDeviceSurface(_In_ DHSURF dhsurf, _In_ SIZEL sizl, _In_ ULONG iFormatCompat)
Definition: surface.c:388
unsigned int ULONG
Definition: retypes.h:1
BOOL NTAPI bInitPointer(PPDEV, DEVINFO *)
Definition: pointer.c:400
_In_ ULONG cjSize
Definition: winddi.h:3634
BOOL NTAPI bInitSURF(PPDEV, BOOL)
Definition: screen.c:43
BOOL NTAPI bInitPDEV(PPDEV, PDEVMODEW, GDIINFO *, DEVINFO *)
static DRVFN gadrvfn[]
Definition: enable.c:14
#define DM_BITSPERPEL
Definition: wingdi.h:1267
struct _devicemodeW DEVMODEW
WORD dmDriverVersion
Definition: wingdi.h:1618
DWORD dmDisplayFlags
Definition: wingdi.h:1650
#define memset(x, y, z)
Definition: compat.h:39
VOID NTAPI DrvDisableSurface(DHPDEV dhpdev)
Definition: enable.c:287
BYTE * PBYTE
Definition: pedump.c:66
Definition: winddi.h:529
ULONG cxScreen
Definition: driver.h:29
_In_ HDEV hdev
Definition: winddi.h:3449
#define DM_DISPLAYFLAGS
Definition: wingdi.h:1270