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
= {
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
122 typedef struct _VGALOGPALETTE
126 PALETTEENTRY PaletteEntry
[16];
129 const VGALOGPALETTE VGApalette
=
132 0x400, // driver version
135 { 0x00, 0x00, 0x00, 0x00 }, // 0
136 { 0x80, 0x00, 0x00, 0x00 }, // 1
137 { 0x00, 0x80, 0x00, 0x00 }, // 2
138 { 0x80, 0x80, 0x00, 0x00 }, // 3
139 { 0x00, 0x00, 0x80, 0x00 }, // 4
140 { 0x80, 0x00, 0x80, 0x00 }, // 5
141 { 0x00, 0x80, 0x80, 0x00 }, // 6
142 { 0x80, 0x80, 0x80, 0x00 }, // 7
143 { 0xc0, 0xc0, 0xc0, 0x00 }, // 8
144 { 0xff, 0x00, 0x00, 0x00 }, // 9
145 { 0x00, 0xff, 0x00, 0x00 }, // 10
146 { 0xff, 0xff, 0x00, 0x00 }, // 11
147 { 0x00, 0x00, 0xff, 0x00 }, // 12
148 { 0xff, 0x00, 0xff, 0x00 }, // 13
149 { 0x00, 0xff, 0xff, 0x00 }, // 14
150 { 0xff, 0xff, 0xff, 0x00 } // 15
154 // Devinfo structure passed back to the engine in DrvEnablePDEV
156 #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"}
157 #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"}
158 #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"}
162 (GCAPS_OPAQUERECT
| GCAPS_HORIZSTRIKE
| GCAPS_ALTERNATEFILL
| GCAPS_MONO_DITHER
| GCAPS_COLOR_DITHER
|
163 GCAPS_WINDINGFILL
| GCAPS_DITHERONREALIZE
164 ), // Graphics capabilities
166 SYSTM_LOGFONT
, // Default font description
167 HELVE_LOGFONT
, // ANSI variable font description
168 COURI_LOGFONT
, // ANSI fixed font description
169 0, // Count of device fonts
170 BMF_4BPP
, // preferred DIB format
171 8, // Width of color dither
172 8, // Height of color dither
173 0 // Default palette to use for this device
177 DrvEnableDriver(IN ULONG EngineVersion
,
179 OUT PDRVENABLEDATA DriveEnableData
)
181 DPRINT("DrvEnableDriver called...\n");
185 VGADDI_InitializeOffScreenMem((SCREEN_X
* SCREEN_Y
) >> 3, 65536 - ((SCREEN_X
* SCREEN_Y
) >> 3));
187 DriveEnableData
->pdrvfn
= FuncList
;
188 DriveEnableData
->c
= sizeof(FuncList
) / sizeof(DRVFN
);
189 DriveEnableData
->iDriverVersion
= DDI_DRIVER_VERSION_NT4
;
196 // This function is called by the KMGDI at exit. It should cleanup.
203 DrvDisableDriver(VOID
)
208 // ----------------------------------------------- Driver Implementation
213 // This function is called after DrvEnableDriver to get information
214 // about the mode that is to be used. This function just returns
215 // information, and should not yet initialize the mode.
217 // IN DEVMODEW * DM Describes the mode requested
218 // IN LPWSTR LogAddress
219 // IN ULONG PatternCount number of patterns expected
220 // OUT HSURF * SurfPatterns array to contain pattern handles
221 // IN ULONG GDIInfoSize the size of the GDIInfo object passed in
222 // OUT ULONG * GDIInfo GDI Info object
223 // IN ULONG DevInfoSize the size of the DevInfo object passed in
224 // OUT ULONG * DevInfo Device Info object
225 // IN LPWSTR DevDataFile ignore
226 // IN LPWSTR DeviceName Device name
227 // IN HANDLE Driver handle to KM driver
229 // DHPDEV a handle to a DPev object
232 DrvEnablePDEV(IN DEVMODEW
*DM
,
233 IN LPWSTR LogAddress
,
234 IN ULONG PatternCount
,
235 OUT HSURF
*SurfPatterns
,
236 IN ULONG GDIInfoSize
,
238 IN ULONG DevInfoSize
,
239 OUT DEVINFO
*DevInfo
,
241 IN LPWSTR DeviceName
,
246 PDev
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(PDEV
), ALLOC_TAG
);
249 DPRINT1("EngAllocMem failed for PDEV\n");
252 PDev
->KMDriver
= Driver
;
253 DPRINT( "PDev: %x, Driver: %x\n", PDev
, PDev
->KMDriver
);
255 gaulCap
.ulHorzRes
= SCREEN_X
;
256 gaulCap
.ulVertRes
= SCREEN_Y
;
257 if (sizeof(GDIINFO
) < GDIInfoSize
)
258 GDIInfoSize
= sizeof(GDIINFO
);
259 memcpy(GDIInfo
, &gaulCap
, GDIInfoSize
);
260 DM
->dmBitsPerPel
= gaulCap
.cBitsPixel
* gaulCap
.cPlanes
;
261 DM
->dmPelsWidth
= gaulCap
.ulHorzRes
;
262 DM
->dmPelsHeight
= gaulCap
.ulVertRes
;
264 devinfoVGA
.hpalDefault
= EngCreatePalette(PAL_INDEXED
, 16, (ULONG
*) VGApalette
.PaletteEntry
, 0, 0, 0);
265 if (sizeof(DEVINFO
) < DevInfoSize
)
266 DevInfoSize
= sizeof(DEVINFO
);
267 memcpy(DevInfo
, &devinfoVGA
, DevInfoSize
);
269 return (DHPDEV
) PDev
;
275 // Called after initialization of PDEV is complete. Supplies
276 // a reference to the GDI handle for the PDEV.
279 DrvCompletePDEV(IN DHPDEV PDev
,
282 ((PPDEV
) PDev
)->GDIDevHandle
= Dev
; // Handle to the DC
287 DrvAssertMode(IN DHPDEV DPev
,
290 PPDEV ppdev
= (PPDEV
)DPev
;
291 ULONG returnedDataLength
;
295 /* Reenable our graphics mode */
296 if (!InitPointer(ppdev
))
298 /* Failed to set pointer */
304 if (!InitVGA(ppdev
, FALSE
))
306 /* Failed to initialize the VGA */
309 VGAInitialized
= TRUE
;
314 /* Go back to last known mode */
315 DPRINT( "ppdev: %x, KMDriver: %x", ppdev
, ppdev
->KMDriver
);
316 if (EngDeviceIoControl(ppdev
->KMDriver
, IOCTL_VIDEO_RESET_DEVICE
, NULL
, 0, NULL
, 0, &returnedDataLength
))
318 /* Failed to go back to mode */
321 VGAInitialized
= FALSE
;
328 DrvDisablePDEV(IN DHPDEV PDev
)
330 PPDEV ppdev
= (PPDEV
)PDev
;
332 /* EngDeletePalette(devinfoVGA.hpalDefault); */
333 if (ppdev
->pjPreallocSSBBuffer
)
334 EngFreeMem(ppdev
->pjPreallocSSBBuffer
);
336 if (ppdev
->pucDIB4ToVGAConvBuffer
)
337 EngFreeMem(ppdev
->pucDIB4ToVGAConvBuffer
);
339 DPRINT("Freeing PDEV\n");
345 DrvDisableSurface(IN DHPDEV PDev
)
347 PPDEV ppdev
= (PPDEV
)PDev
;
348 PDEVSURF pdsurf
= ppdev
->AssociatedSurf
;
350 DPRINT("KMDriver: %x\n", ppdev
->KMDriver
);
352 /* EngFreeMem(pdsurf->BankSelectInfo); */
354 if (pdsurf
->BankInfo
!= NULL
)
355 EngFreeMem(pdsurf
->BankInfo
);
356 if (pdsurf
->BankInfo2RW
!= NULL
)
357 EngFreeMem(pdsurf
->BankInfo2RW
);
358 if (pdsurf
->BankBufferPlane0
!= NULL
)
359 EngFreeMem(pdsurf
->BankBufferPlane0
);
360 if (ppdev
->pPointerAttributes
!= NULL
)
361 EngFreeMem(ppdev
->pPointerAttributes
);
363 /* free any pending saved screen bit blocks */
365 pSSB
= pdsurf
->ssbList
;
366 while (pSSB
!= (PSAVED_SCREEN_BITS
) NULL
)
368 /* Point to the next saved screen bits block */
369 pSSBNext
= (PSAVED_SCREEN_BITS
) pSSB
->pvNextSSB
;
371 /* Free the current block */
376 EngDeleteSurface((HSURF
) ppdev
->SurfHandle
);
377 /* EngFreeMem(pdsurf); */ /* free the surface */
382 InitSavedBits(IN PPDEV ppdev
)
384 if (!(ppdev
->fl
& DRIVER_OFFSCREEN_REFRESHED
))
387 /* set up rect to right of visible screen */
388 ppdev
->SavedBitsRight
.left
= ppdev
->sizeSurf
.cx
;
389 ppdev
->SavedBitsRight
.top
= 0;
390 ppdev
->SavedBitsRight
.right
= ppdev
->sizeMem
.cx
- PLANAR_PELS_PER_CPU_ADDRESS
;
391 ppdev
->SavedBitsRight
.bottom
= ppdev
->sizeSurf
.cy
;
393 if ((ppdev
->SavedBitsRight
.right
<= ppdev
->SavedBitsRight
.left
) ||
394 (ppdev
->SavedBitsRight
.bottom
<= ppdev
->SavedBitsRight
.top
))
396 ppdev
->SavedBitsRight
.left
= 0;
397 ppdev
->SavedBitsRight
.top
= 0;
398 ppdev
->SavedBitsRight
.right
= 0;
399 ppdev
->SavedBitsRight
.bottom
= 0;
402 /* set up rect below visible screen */
403 ppdev
->SavedBitsBottom
.left
= 0;
404 ppdev
->SavedBitsBottom
.top
= ppdev
->sizeSurf
.cy
;
405 ppdev
->SavedBitsBottom
.right
= ppdev
->sizeMem
.cx
- PLANAR_PELS_PER_CPU_ADDRESS
;
406 ppdev
->SavedBitsBottom
.bottom
= ppdev
->sizeMem
.cy
- ppdev
->NumScansUsedByPointer
;
408 if ((ppdev
->SavedBitsBottom
.right
<= ppdev
->SavedBitsBottom
.left
) ||
409 (ppdev
->SavedBitsBottom
.bottom
<= ppdev
->SavedBitsBottom
.top
))
411 ppdev
->SavedBitsBottom
.left
= 0;
412 ppdev
->SavedBitsBottom
.top
= 0;
413 ppdev
->SavedBitsBottom
.right
= 0;
414 ppdev
->SavedBitsBottom
.bottom
= 0;
417 ppdev
->BitsSaved
= FALSE
;
422 DrvEnableSurface(IN DHPDEV PDev
)
424 PPDEV ppdev
= (PPDEV
)PDev
;
429 DPRINT("DrvEnableSurface() called\n");
431 /* Initialize the VGA */
434 if (!InitVGA(ppdev
, TRUE
))
436 VGAInitialized
= TRUE
;
439 /* dhsurf is of type DEVSURF, which is the drivers specialized surface type */
440 dhsurf
= (DHSURF
)EngAllocMem(0, sizeof(DEVSURF
), ALLOC_TAG
);
441 if (dhsurf
== (DHSURF
) 0)
444 pdsurf
= (PDEVSURF
) dhsurf
;
445 pdsurf
->ident
= DEVSURF_IDENT
;
447 pdsurf
->Format
= BMF_PHYSDEVICE
;
448 pdsurf
->jReserved1
= 0;
449 pdsurf
->jReserved2
= 0;
450 pdsurf
->ppdev
= ppdev
;
451 pdsurf
->sizeSurf
.cx
= ppdev
->sizeSurf
.cx
;
452 pdsurf
->sizeSurf
.cy
= ppdev
->sizeSurf
.cy
;
453 pdsurf
->NextPlane
= 0;
454 pdsurf
->Scan0
= ppdev
->fbScreen
;
455 pdsurf
->BitmapStart
= ppdev
->fbScreen
;
456 pdsurf
->StartBmp
= ppdev
->fbScreen
;
457 pdsurf
->BankInfo
= NULL
;
458 pdsurf
->BankInfo2RW
= NULL
;
459 pdsurf
->BankBufferPlane0
= NULL
;
461 /* pdsurf->Conv = &ConvertBuffer[0]; */
463 if (!InitPointer(ppdev
))
465 DPRINT1("DrvEnablePDEV failed bInitPointer\n");
469 /* if (!SetUpBanking(pdsurf, ppdev))
471 DPRINT1("DrvEnablePDEV failed SetUpBanking\n");
473 } BANKING CODE UNIMPLEMENTED */
475 if ((hsurf
= EngCreateDeviceSurface(dhsurf
, ppdev
->sizeSurf
, BMF_4BPP
)) ==
478 /* Call to EngCreateDeviceSurface failed */
479 DPRINT("EngCreateDeviceSurface call failed\n");
483 InitSavedBits(ppdev
);
485 if (EngAssociateSurface(hsurf
, ppdev
->GDIDevHandle
, HOOK_BITBLT
| HOOK_PAINT
| HOOK_LINETO
| HOOK_COPYBITS
|
486 HOOK_TRANSPARENTBLT
))
488 DPRINT("Successfully associated surface\n");
489 ppdev
->SurfHandle
= hsurf
;
490 ppdev
->AssociatedSurf
= pdsurf
;
492 /* Set up an empty saved screen block list */
493 pdsurf
->ssbList
= NULL
;
497 DPRINT("EngAssociateSurface() failed\n");
498 EngDeleteSurface(hsurf
);
509 DrvGetModes(IN HANDLE Driver
,
516 DWORD OutputModes
= DataSize
/ (sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
517 PVIDEO_MODE_INFORMATION VideoModeInformation
, VideoTemp
;
519 NumModes
= getAvailableModes(Driver
,
520 (PVIDEO_MODE_INFORMATION
*) &VideoModeInformation
,
528 OutputSize
= NumModes
* (sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
533 VideoTemp
= VideoModeInformation
;
537 if (VideoTemp
->Length
!= 0)
539 if (OutputModes
== 0)
542 memset(DM
, 0, sizeof(DEVMODEW
));
543 memcpy(DM
->dmDeviceName
, DLL_NAME
, sizeof(DLL_NAME
));
545 DM
->dmSpecVersion
= DM_SPECVERSION
;
546 DM
->dmDriverVersion
= DM_SPECVERSION
;
547 DM
->dmSize
= sizeof(DEVMODEW
);
548 DM
->dmDriverExtra
= DRIVER_EXTRA_SIZE
;
549 DM
->dmBitsPerPel
= VideoTemp
->NumberOfPlanes
*
550 VideoTemp
->BitsPerPlane
;
551 DM
->dmPelsWidth
= VideoTemp
->VisScreenWidth
;
552 DM
->dmPelsHeight
= VideoTemp
->VisScreenHeight
;
553 DM
->dmDisplayFrequency
= VideoTemp
->Frequency
;
554 DM
->dmDisplayFlags
= 0;
556 DM
->dmFields
= DM_BITSPERPEL
|
559 DM_DISPLAYFREQUENCY
|
562 /* next DEVMODE entry */
565 DM
= (PDEVMODEW
) ( ((ULONG
)DM
) + sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
567 OutputSize
+= (sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
570 VideoTemp
= (PVIDEO_MODE_INFORMATION
)(((PUCHAR
)VideoTemp
) + ModeSize
);
572 } while (--NumModes
);
577 ULONG
DbgPrint(PCCH Format
,...)
580 va_start(ap
, Format
);
581 EngDebugPrint("VGADDI", (PCHAR
)Format
, ap
);