2 * PROJECT: ReactOS VGA display driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/video/displays/vga/main/enable.c
11 static BOOL VGAInitialized
= FALSE
;
13 static DRVFN FuncList
[] =
15 /* Required Display driver fuctions */
16 {INDEX_DrvAssertMode
, (PFN
) DrvAssertMode
},
17 {INDEX_DrvCompletePDEV
, (PFN
) DrvCompletePDEV
},
18 {INDEX_DrvCopyBits
, (PFN
) DrvCopyBits
},
19 {INDEX_DrvDisablePDEV
, (PFN
) DrvDisablePDEV
},
20 {INDEX_DrvDisableSurface
, (PFN
) DrvDisableSurface
},
21 {INDEX_DrvEnablePDEV
, (PFN
) DrvEnablePDEV
},
22 {INDEX_DrvEnableSurface
, (PFN
) DrvEnableSurface
},
23 {INDEX_DrvGetModes
, (PFN
) DrvGetModes
},
24 {INDEX_DrvLineTo
, (PFN
) DrvLineTo
},
25 {INDEX_DrvPaint
, (PFN
) DrvPaint
},
26 {INDEX_DrvBitBlt
, (PFN
) DrvBitBlt
},
27 {INDEX_DrvTransparentBlt
, (PFN
) DrvTransparentBlt
},
28 {INDEX_DrvMovePointer
, (PFN
) DrvMovePointer
},
29 {INDEX_DrvSetPointerShape
, (PFN
) DrvSetPointerShape
},
32 /* Optional Display driver functions */
34 {INDEX_DescribePixelFormat
, (PFN
) VGADDIDescribePixelFormat
},
35 {INDEX_DrvDitherColor
, (PFN
) VGADDIDitherColor
},
36 {INDEX_DrvFillPath
, (PFN
) VGADDIFillPath
},
37 {INDEX_DrvGetTrueTypeFile
, (PFN
) VGADDIGetTrueTypeFile
},
38 {INDEX_DrvLoadFontFile
, (PFN
) VGADDILoadFontFile
},
39 {INDEX_DrvQueryFont
, (PFN
) VGADDIQueryFont
},
40 {INDEX_DrvQueryFontCaps
, (PFN
) VGADDIQueryFontCaps
},
41 {INDEX_DrvQueryFontData
, (PFN
) VGADDIQueryFontData
},
42 {INDEX_DrvQueryFontFile
, (PFN
) VGADDIQueryFontFile
},
43 {INDEX_DrvQueryFontTree
, (PFN
) VGADDIQueryFontTree
},
44 {INDEX_DrvQueryTrueTypeOutline
, (PFN
) VGADDIQueryTrueTypeOutline
},
45 {INDEX_DrvQueryTrueTypeTable
, (PFN
) VGADDIQueryTrueTypeTable
},
46 {INDEX_DrvRealizeBrush
, (PFN
) VGADDIRealizeBrush
},
47 {INDEX_DrvResetPDEV
, (PFN
) VGADDIResetPDEV
},
48 {INDEX_DrvSetPalette
, (PFN
) VGADDISetPalette
},
49 {INDEX_DrvSetPixelFormat
, (PFN
) VGADDISetPixelFormat
},
50 {INDEX_DrvStretchBlt
, (PFN
) VGADDIStretchBlt
},
51 {INDEX_DrvStrokePath
, (PFN
) VGADDIStrokePath
},
52 {INDEX_DrvSwapBuffers
, (PFN
) VGADDISwapBuffers
},
53 {INDEX_DrvTextOut
, (PFN
) VGADDITextOut
},
54 {INDEX_DrvUnloadFontFile
, (PFN
) VGADDIUnloadFontFile
},
58 static GDIINFO gaulCap
= {
59 GDI_DRIVER_VERSION
, // ulVersion
60 DT_RASDISPLAY
, // ulTechnology
63 0, // ulHorzRes (filled in at initialization)
64 0, // ulVertRes (filled in at initialization)
68 0, // flRaster (DDI reserved field)
70 96, // ulLogPixelsX (must be set to 96 according to MSDN)
71 96, // ulLogPixelsY (must be set to 96 according to MSDN)
73 TC_RA_ABLE
| TC_SCROLLBLT
, // flTextCaps
79 0x0024, // ulAspectX (one-to-one aspect ratio)
87 { 0, 0 }, // ptlPhysOffset
88 { 0, 0 }, // szlPhysSize
90 0, // ulNumPalReg (win3.1 16 color drivers say 0 too)
92 // These fields are for halftone initialization.
94 { // ciDevice, ColorInfo
95 { 6700, 3300, 0 }, // Red
96 { 2100, 7100, 0 }, // Green
97 { 1400, 800, 0 }, // Blue
98 { 1750, 3950, 0 }, // Cyan
99 { 4050, 2050, 0 }, // Magenta
100 { 4400, 5200, 0 }, // Yellow
101 { 3127, 3290, 0 }, // AlignmentWhite
108 0, // ulDevicePelsDPI
109 PRIMARY_ORDER_CBA
, // ulPrimaryOrder
110 HT_PATSIZE_4x4_M
, // ulHTPatternSize
111 HT_FORMAT_4BPP_IRGB
, // ulHTOutputFormat
112 HT_FLAG_ADDITIVE_PRIMS
, // flHTFlags
116 0, // ulPanningHorzRes
117 0, // ulPanningVertRes
119 0, // xPanningAlignment
120 0, // yPanningAlignment
127 0, // ulPhysicalPixelCharacteristics
128 0 // ulPhysicalPixelGamma
133 typedef struct _VGALOGPALETTE
137 PALETTEENTRY PaletteEntry
[16];
140 const VGALOGPALETTE VGApalette
=
143 0x400, // driver version
146 { 0x00, 0x00, 0x00, 0x00 }, // 0
147 { 0x80, 0x00, 0x00, 0x00 }, // 1
148 { 0x00, 0x80, 0x00, 0x00 }, // 2
149 { 0x80, 0x80, 0x00, 0x00 }, // 3
150 { 0x00, 0x00, 0x80, 0x00 }, // 4
151 { 0x80, 0x00, 0x80, 0x00 }, // 5
152 { 0x00, 0x80, 0x80, 0x00 }, // 6
153 { 0x80, 0x80, 0x80, 0x00 }, // 7
154 { 0xc0, 0xc0, 0xc0, 0x00 }, // 8
155 { 0xff, 0x00, 0x00, 0x00 }, // 9
156 { 0x00, 0xff, 0x00, 0x00 }, // 10
157 { 0xff, 0xff, 0x00, 0x00 }, // 11
158 { 0x00, 0x00, 0xff, 0x00 }, // 12
159 { 0xff, 0x00, 0xff, 0x00 }, // 13
160 { 0x00, 0xff, 0xff, 0x00 }, // 14
161 { 0xff, 0xff, 0xff, 0x00 } // 15
165 // Devinfo structure passed back to the engine in DrvEnablePDEV
167 #define SYSTM_LOGFONT {16,7,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH | FF_DONTCARE, L"System"}
168 #define HELVE_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_STROKE_PRECIS,PROOF_QUALITY,VARIABLE_PITCH | FF_DONTCARE, L"MS Sans Serif"}
169 #define COURI_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_STROKE_PRECIS,PROOF_QUALITY,FIXED_PITCH | FF_DONTCARE, L"Courier"}
173 (GCAPS_OPAQUERECT
| GCAPS_HORIZSTRIKE
| GCAPS_ALTERNATEFILL
| GCAPS_MONO_DITHER
| GCAPS_COLOR_DITHER
|
174 GCAPS_WINDINGFILL
| GCAPS_DITHERONREALIZE
175 ), // Graphics capabilities
177 SYSTM_LOGFONT
, // Default font description
178 HELVE_LOGFONT
, // ANSI variable font description
179 COURI_LOGFONT
, // ANSI fixed font description
180 0, // Count of device fonts
181 BMF_4BPP
, // preferred DIB format
182 8, // Width of color dither
183 8, // Height of color dither
184 NULL
, // Default palette to use for this device
189 DrvEnableDriver(IN ULONG EngineVersion
,
191 OUT PDRVENABLEDATA DriveEnableData
)
193 DPRINT("DrvEnableDriver called...\n");
197 VGADDI_InitializeOffScreenMem((SCREEN_X
* SCREEN_Y
) >> 3, 65536 - ((SCREEN_X
* SCREEN_Y
) >> 3));
199 DriveEnableData
->pdrvfn
= FuncList
;
200 DriveEnableData
->c
= sizeof(FuncList
) / sizeof(DRVFN
);
201 DriveEnableData
->iDriverVersion
= DDI_DRIVER_VERSION_NT4
;
208 // This function is called by the KMGDI at exit. It should cleanup.
215 DrvDisableDriver(VOID
)
220 // ----------------------------------------------- Driver Implementation
225 // This function is called after DrvEnableDriver to get information
226 // about the mode that is to be used. This function just returns
227 // information, and should not yet initialize the mode.
229 // IN DEVMODEW * DM Describes the mode requested
230 // IN LPWSTR LogAddress
231 // IN ULONG PatternCount number of patterns expected
232 // OUT HSURF * SurfPatterns array to contain pattern handles
233 // IN ULONG GDIInfoSize the size of the GDIInfo object passed in
234 // OUT ULONG * GDIInfo GDI Info object
235 // IN ULONG DevInfoSize the size of the DevInfo object passed in
236 // OUT ULONG * DevInfo Device Info object
237 // IN LPWSTR DevDataFile ignore
238 // IN LPWSTR DeviceName Device name
239 // IN HANDLE Driver handle to KM driver
241 // DHPDEV a handle to a DPev object
244 DrvEnablePDEV(IN DEVMODEW
*DM
,
245 IN LPWSTR LogAddress
,
246 IN ULONG PatternCount
,
247 OUT HSURF
*SurfPatterns
,
248 IN ULONG GDIInfoSize
,
250 IN ULONG DevInfoSize
,
251 OUT DEVINFO
*DevInfo
,
253 IN LPWSTR DeviceName
,
258 PDev
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(PDEV
), ALLOC_TAG
);
261 DPRINT1("EngAllocMem failed for PDEV\n");
264 PDev
->KMDriver
= Driver
;
265 DPRINT( "PDev: %x, Driver: %x\n", PDev
, PDev
->KMDriver
);
267 gaulCap
.ulHorzRes
= SCREEN_X
;
268 gaulCap
.ulVertRes
= SCREEN_Y
;
269 if (sizeof(GDIINFO
) < GDIInfoSize
)
270 GDIInfoSize
= sizeof(GDIINFO
);
271 memcpy(GDIInfo
, &gaulCap
, GDIInfoSize
);
272 DM
->dmBitsPerPel
= gaulCap
.cBitsPixel
* gaulCap
.cPlanes
;
273 DM
->dmPelsWidth
= gaulCap
.ulHorzRes
;
274 DM
->dmPelsHeight
= gaulCap
.ulVertRes
;
276 devinfoVGA
.hpalDefault
= EngCreatePalette(PAL_INDEXED
, 16, (ULONG
*) VGApalette
.PaletteEntry
, 0, 0, 0);
277 if (sizeof(DEVINFO
) < DevInfoSize
)
278 DevInfoSize
= sizeof(DEVINFO
);
279 memcpy(DevInfo
, &devinfoVGA
, DevInfoSize
);
281 return (DHPDEV
) PDev
;
287 // Called after initialization of PDEV is complete. Supplies
288 // a reference to the GDI handle for the PDEV.
291 DrvCompletePDEV(IN DHPDEV PDev
,
294 ((PPDEV
) PDev
)->GDIDevHandle
= Dev
; // Handle to the DC
299 DrvAssertMode(IN DHPDEV DPev
,
302 PPDEV ppdev
= (PPDEV
)DPev
;
303 ULONG returnedDataLength
;
307 /* Reenable our graphics mode */
308 if (!InitPointer(ppdev
))
310 /* Failed to set pointer */
316 if (!InitVGA(ppdev
, FALSE
))
318 /* Failed to initialize the VGA */
321 VGAInitialized
= TRUE
;
326 /* Go back to last known mode */
327 DPRINT( "ppdev: %x, KMDriver: %x", ppdev
, ppdev
->KMDriver
);
328 if (EngDeviceIoControl(ppdev
->KMDriver
, IOCTL_VIDEO_RESET_DEVICE
, NULL
, 0, NULL
, 0, &returnedDataLength
))
330 /* Failed to go back to mode */
333 VGAInitialized
= FALSE
;
340 DrvDisablePDEV(IN DHPDEV PDev
)
342 PPDEV ppdev
= (PPDEV
)PDev
;
344 /* EngDeletePalette(devinfoVGA.hpalDefault); */
345 if (ppdev
->pjPreallocSSBBuffer
)
346 EngFreeMem(ppdev
->pjPreallocSSBBuffer
);
348 if (ppdev
->pucDIB4ToVGAConvBuffer
)
349 EngFreeMem(ppdev
->pucDIB4ToVGAConvBuffer
);
351 DPRINT("Freeing PDEV\n");
357 DrvDisableSurface(IN DHPDEV PDev
)
359 PPDEV ppdev
= (PPDEV
)PDev
;
360 PDEVSURF pdsurf
= ppdev
->AssociatedSurf
;
362 DPRINT("KMDriver: %x\n", ppdev
->KMDriver
);
364 /* EngFreeMem(pdsurf->BankSelectInfo); */
366 if (pdsurf
->BankInfo
!= NULL
)
367 EngFreeMem(pdsurf
->BankInfo
);
368 if (pdsurf
->BankInfo2RW
!= NULL
)
369 EngFreeMem(pdsurf
->BankInfo2RW
);
370 if (pdsurf
->BankBufferPlane0
!= NULL
)
371 EngFreeMem(pdsurf
->BankBufferPlane0
);
372 if (ppdev
->pPointerAttributes
!= NULL
)
373 EngFreeMem(ppdev
->pPointerAttributes
);
375 /* free any pending saved screen bit blocks */
377 pSSB
= pdsurf
->ssbList
;
378 while (pSSB
!= (PSAVED_SCREEN_BITS
) NULL
)
380 /* Point to the next saved screen bits block */
381 pSSBNext
= (PSAVED_SCREEN_BITS
) pSSB
->pvNextSSB
;
383 /* Free the current block */
388 EngDeleteSurface((HSURF
) ppdev
->SurfHandle
);
389 /* EngFreeMem(pdsurf); */ /* free the surface */
394 InitSavedBits(IN PPDEV ppdev
)
396 if (!(ppdev
->fl
& DRIVER_OFFSCREEN_REFRESHED
))
399 /* set up rect to right of visible screen */
400 ppdev
->SavedBitsRight
.left
= ppdev
->sizeSurf
.cx
;
401 ppdev
->SavedBitsRight
.top
= 0;
402 ppdev
->SavedBitsRight
.right
= ppdev
->sizeMem
.cx
- PLANAR_PELS_PER_CPU_ADDRESS
;
403 ppdev
->SavedBitsRight
.bottom
= ppdev
->sizeSurf
.cy
;
405 if ((ppdev
->SavedBitsRight
.right
<= ppdev
->SavedBitsRight
.left
) ||
406 (ppdev
->SavedBitsRight
.bottom
<= ppdev
->SavedBitsRight
.top
))
408 ppdev
->SavedBitsRight
.left
= 0;
409 ppdev
->SavedBitsRight
.top
= 0;
410 ppdev
->SavedBitsRight
.right
= 0;
411 ppdev
->SavedBitsRight
.bottom
= 0;
414 /* set up rect below visible screen */
415 ppdev
->SavedBitsBottom
.left
= 0;
416 ppdev
->SavedBitsBottom
.top
= ppdev
->sizeSurf
.cy
;
417 ppdev
->SavedBitsBottom
.right
= ppdev
->sizeMem
.cx
- PLANAR_PELS_PER_CPU_ADDRESS
;
418 ppdev
->SavedBitsBottom
.bottom
= ppdev
->sizeMem
.cy
- ppdev
->NumScansUsedByPointer
;
420 if ((ppdev
->SavedBitsBottom
.right
<= ppdev
->SavedBitsBottom
.left
) ||
421 (ppdev
->SavedBitsBottom
.bottom
<= ppdev
->SavedBitsBottom
.top
))
423 ppdev
->SavedBitsBottom
.left
= 0;
424 ppdev
->SavedBitsBottom
.top
= 0;
425 ppdev
->SavedBitsBottom
.right
= 0;
426 ppdev
->SavedBitsBottom
.bottom
= 0;
429 ppdev
->BitsSaved
= FALSE
;
434 DrvEnableSurface(IN DHPDEV PDev
)
436 PPDEV ppdev
= (PPDEV
)PDev
;
441 DPRINT("DrvEnableSurface() called\n");
443 /* Initialize the VGA */
446 if (!InitVGA(ppdev
, TRUE
))
448 VGAInitialized
= TRUE
;
451 /* dhsurf is of type DEVSURF, which is the drivers specialized surface type */
452 dhsurf
= (DHSURF
)EngAllocMem(0, sizeof(DEVSURF
), ALLOC_TAG
);
453 if (dhsurf
== (DHSURF
) 0)
456 pdsurf
= (PDEVSURF
) dhsurf
;
457 pdsurf
->ident
= DEVSURF_IDENT
;
459 pdsurf
->Format
= BMF_PHYSDEVICE
;
460 pdsurf
->jReserved1
= 0;
461 pdsurf
->jReserved2
= 0;
462 pdsurf
->ppdev
= ppdev
;
463 pdsurf
->sizeSurf
.cx
= ppdev
->sizeSurf
.cx
;
464 pdsurf
->sizeSurf
.cy
= ppdev
->sizeSurf
.cy
;
465 pdsurf
->NextPlane
= 0;
466 pdsurf
->Scan0
= ppdev
->fbScreen
;
467 pdsurf
->BitmapStart
= ppdev
->fbScreen
;
468 pdsurf
->StartBmp
= ppdev
->fbScreen
;
469 pdsurf
->BankInfo
= NULL
;
470 pdsurf
->BankInfo2RW
= NULL
;
471 pdsurf
->BankBufferPlane0
= NULL
;
473 /* pdsurf->Conv = &ConvertBuffer[0]; */
475 if (!InitPointer(ppdev
))
477 DPRINT1("DrvEnablePDEV failed bInitPointer\n");
481 /* if (!SetUpBanking(pdsurf, ppdev))
483 DPRINT1("DrvEnablePDEV failed SetUpBanking\n");
485 } BANKING CODE UNIMPLEMENTED */
487 if ((hsurf
= EngCreateDeviceSurface(dhsurf
, ppdev
->sizeSurf
, BMF_4BPP
)) ==
490 /* Call to EngCreateDeviceSurface failed */
491 DPRINT("EngCreateDeviceSurface call failed\n");
495 InitSavedBits(ppdev
);
497 if (EngAssociateSurface(hsurf
, ppdev
->GDIDevHandle
, HOOK_BITBLT
| HOOK_PAINT
| HOOK_LINETO
| HOOK_COPYBITS
|
498 HOOK_TRANSPARENTBLT
))
500 DPRINT("Successfully associated surface\n");
501 ppdev
->SurfHandle
= hsurf
;
502 ppdev
->AssociatedSurf
= pdsurf
;
504 /* Set up an empty saved screen block list */
505 pdsurf
->ssbList
= NULL
;
509 DPRINT("EngAssociateSurface() failed\n");
510 EngDeleteSurface(hsurf
);
521 DrvGetModes(IN HANDLE Driver
,
528 DWORD OutputModes
= DataSize
/ (sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
529 PVIDEO_MODE_INFORMATION VideoModeInformation
, VideoTemp
;
531 NumModes
= getAvailableModes(Driver
,
532 (PVIDEO_MODE_INFORMATION
*) &VideoModeInformation
,
540 OutputSize
= NumModes
* (sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
545 VideoTemp
= VideoModeInformation
;
549 if (VideoTemp
->Length
!= 0)
551 if (OutputModes
== 0)
554 memset(DM
, 0, sizeof(DEVMODEW
));
555 memcpy(DM
->dmDeviceName
, DLL_NAME
, sizeof(DLL_NAME
));
557 DM
->dmSpecVersion
= DM_SPECVERSION
;
558 DM
->dmDriverVersion
= DM_SPECVERSION
;
559 DM
->dmSize
= sizeof(DEVMODEW
);
560 DM
->dmDriverExtra
= DRIVER_EXTRA_SIZE
;
561 DM
->dmBitsPerPel
= VideoTemp
->NumberOfPlanes
*
562 VideoTemp
->BitsPerPlane
;
563 DM
->dmPelsWidth
= VideoTemp
->VisScreenWidth
;
564 DM
->dmPelsHeight
= VideoTemp
->VisScreenHeight
;
565 DM
->dmDisplayFrequency
= VideoTemp
->Frequency
;
566 DM
->dmDisplayFlags
= 0;
568 DM
->dmFields
= DM_BITSPERPEL
|
571 DM_DISPLAYFREQUENCY
|
574 /* next DEVMODE entry */
577 DM
= (PDEVMODEW
) ( ((ULONG
)DM
) + sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
579 OutputSize
+= (sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
582 VideoTemp
= (PVIDEO_MODE_INFORMATION
)(((PUCHAR
)VideoTemp
) + ModeSize
);
584 } while (--NumModes
);
589 ULONG
DbgPrint(PCCH Format
,...)
592 va_start(ap
, Format
);
593 EngDebugPrint("VGADDI", (PCHAR
)Format
, ap
);