6 * $Date: 2004/11/27 00:46:24 $
10 #include "../vgaddi.h"
11 #include "../vgavideo/vgavideo.h"
15 #define DBG_PREFIX "VGADDI: "
17 static BOOL VGAInitialized
= FALSE
;
21 /* Required Display driver fuctions */
22 {INDEX_DrvAssertMode
, (PFN
) DrvAssertMode
},
23 {INDEX_DrvCompletePDEV
, (PFN
) DrvCompletePDEV
},
24 {INDEX_DrvCopyBits
, (PFN
) DrvCopyBits
},
25 {INDEX_DrvDisablePDEV
, (PFN
) DrvDisablePDEV
},
26 {INDEX_DrvDisableSurface
, (PFN
) DrvDisableSurface
},
27 {INDEX_DrvEnablePDEV
, (PFN
) DrvEnablePDEV
},
28 {INDEX_DrvEnableSurface
, (PFN
) DrvEnableSurface
},
29 {INDEX_DrvGetModes
, (PFN
) DrvGetModes
},
30 {INDEX_DrvLineTo
, (PFN
) DrvLineTo
},
31 {INDEX_DrvPaint
, (PFN
) DrvPaint
},
32 {INDEX_DrvBitBlt
, (PFN
) DrvBitBlt
},
33 {INDEX_DrvTransparentBlt
, (PFN
) DrvTransparentBlt
},
34 {INDEX_DrvMovePointer
, (PFN
) DrvMovePointer
},
35 {INDEX_DrvSetPointerShape
, (PFN
) DrvSetPointerShape
},
38 /* Optional Display driver functions */
40 {INDEX_DescribePixelFormat
, (PFN
) VGADDIDescribePixelFormat
},
41 {INDEX_DrvDitherColor
, (PFN
) VGADDIDitherColor
},
42 {INDEX_DrvFillPath
, (PFN
) VGADDIFillPath
},
43 {INDEX_DrvGetTrueTypeFile
, (PFN
) VGADDIGetTrueTypeFile
},
44 {INDEX_DrvLoadFontFile
, (PFN
) VGADDILoadFontFile
},
45 {INDEX_DrvQueryFont
, (PFN
) VGADDIQueryFont
},
46 {INDEX_DrvQueryFontCaps
, (PFN
) VGADDIQueryFontCaps
},
47 {INDEX_DrvQueryFontData
, (PFN
) VGADDIQueryFontData
},
48 {INDEX_DrvQueryFontFile
, (PFN
) VGADDIQueryFontFile
},
49 {INDEX_DrvQueryFontTree
, (PFN
) VGADDIQueryFontTree
},
50 {INDEX_DrvQueryTrueTypeOutline
, (PFN
) VGADDIQueryTrueTypeOutline
},
51 {INDEX_DrvQueryTrueTypeTable
, (PFN
) VGADDIQueryTrueTypeTable
},
52 {INDEX_DrvRealizeBrush
, (PFN
) VGADDIRealizeBrush
},
53 {INDEX_DrvResetPDEV
, (PFN
) VGADDIResetPDEV
},
54 {INDEX_DrvSetPalette
, (PFN
) VGADDISetPalette
},
55 {INDEX_DrvSetPixelFormat
, (PFN
) VGADDISetPixelFormat
},
56 {INDEX_DrvStretchBlt
, (PFN
) VGADDIStretchBlt
},
57 {INDEX_DrvStrokePath
, (PFN
) VGADDIStrokePath
},
58 {INDEX_DrvSwapBuffers
, (PFN
) VGADDISwapBuffers
},
59 {INDEX_DrvTextOut
, (PFN
) VGADDITextOut
},
60 {INDEX_DrvUnloadFontFile
, (PFN
) VGADDIUnloadFontFile
},
66 DT_RASDISPLAY
, // ulTechnology
69 0, // ulHorzRes (filled in at initialization)
70 0, // ulVertRes (filled in at initialization)
74 0, // flRaster (DDI reserved field)
76 96, // ulLogPixelsX (must be set to 96 according to MSDN)
77 96, // ulLogPixelsY (must be set to 96 according to MSDN)
79 TC_RA_ABLE
| TC_SCROLLBLT
, // flTextCaps
85 0x0024, // ulAspectX (one-to-one aspect ratio)
93 { 0, 0 }, // ptlPhysOffset
94 { 0, 0 }, // szlPhysSize
96 0, // ulNumPalReg (win3.1 16 color drivers say 0 too)
98 // These fields are for halftone initialization.
100 { // ciDevice, ColorInfo
101 { 6700, 3300, 0 }, // Red
102 { 2100, 7100, 0 }, // Green
103 { 1400, 800, 0 }, // Blue
104 { 1750, 3950, 0 }, // Cyan
105 { 4050, 2050, 0 }, // Magenta
106 { 4400, 5200, 0 }, // Yellow
107 { 3127, 3290, 0 }, // AlignmentWhite
114 0, // ulDevicePelsDPI
115 PRIMARY_ORDER_CBA
, // ulPrimaryOrder
116 HT_PATSIZE_4x4_M
, // ulHTPatternSize
117 HT_FORMAT_4BPP_IRGB
, // ulHTOutputFormat
118 HT_FLAG_ADDITIVE_PRIMS
, // flHTFlags
122 0, // ulPanningHorzRes
123 0, // ulPanningVertRes
128 typedef struct _VGALOGPALETTE
132 PALETTEENTRY PaletteEntry
[16];
135 const VGALOGPALETTE VGApalette
=
138 0x400, // driver version
141 { 0x00, 0x00, 0x00, 0x00 }, // 0
142 { 0x80, 0x00, 0x00, 0x00 }, // 1
143 { 0x00, 0x80, 0x00, 0x00 }, // 2
144 { 0x80, 0x80, 0x00, 0x00 }, // 3
145 { 0x00, 0x00, 0x80, 0x00 }, // 4
146 { 0x80, 0x00, 0x80, 0x00 }, // 5
147 { 0x00, 0x80, 0x80, 0x00 }, // 6
148 { 0x80, 0x80, 0x80, 0x00 }, // 7
149 { 0xc0, 0xc0, 0xc0, 0x00 }, // 8
150 { 0xff, 0x00, 0x00, 0x00 }, // 9
151 { 0x00, 0xff, 0x00, 0x00 }, // 10
152 { 0xff, 0xff, 0x00, 0x00 }, // 11
153 { 0x00, 0x00, 0xff, 0x00 }, // 12
154 { 0xff, 0x00, 0xff, 0x00 }, // 13
155 { 0x00, 0xff, 0xff, 0x00 }, // 14
156 { 0xff, 0xff, 0xff, 0x00 } // 15
160 // Devinfo structure passed back to the engine in DrvEnablePDEV
162 #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"}
163 #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"}
164 #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"}
168 (GCAPS_OPAQUERECT
| GCAPS_HORIZSTRIKE
| GCAPS_ALTERNATEFILL
| GCAPS_MONO_DITHER
| GCAPS_COLOR_DITHER
|
169 GCAPS_WINDINGFILL
| GCAPS_DITHERONREALIZE
170 ), // Graphics capabilities
172 SYSTM_LOGFONT
, // Default font description
173 HELVE_LOGFONT
, // ANSI variable font description
174 COURI_LOGFONT
, // ANSI fixed font description
175 0, // Count of device fonts
176 BMF_4BPP
, // preferred DIB format
177 8, // Width of color dither
178 8, // Height of color dither
179 0 // Default palette to use for this device
184 DrvEnableDriver(IN ULONG EngineVersion
,
186 OUT PDRVENABLEDATA DriveEnableData
)
188 /* EngDebugPrint("VGADDI", "DrvEnableDriver called...\n", 0); */
192 VGADDI_InitializeOffScreenMem((640 * 480) >> 3, 65536 - ((640 * 480) >> 3));
194 DriveEnableData
->pdrvfn
= FuncList
;
195 DriveEnableData
->c
= sizeof(FuncList
) / sizeof(DRVFN
);
196 DriveEnableData
->iDriverVersion
= DDI_DRIVER_VERSION_NT4
;
203 // This function is called by the KMGDI at exit. It should cleanup.
210 DrvDisableDriver(VOID
)
215 // ----------------------------------------------- Driver Implementation
220 // This function is called after DrvEnableDriver to get information
221 // about the mode that is to be used. This function just returns
222 // information, and should not yet initialize the mode.
224 // IN DEVMODEW * DM Describes the mode requested
225 // IN LPWSTR LogAddress
226 // IN ULONG PatternCount number of patterns expected
227 // OUT HSURF * SurfPatterns array to contain pattern handles
228 // IN ULONG GDIInfoSize the size of the GDIInfo object passed in
229 // OUT ULONG * GDIInfo GDI Info object
230 // IN ULONG DevInfoSize the size of the DevInfo object passed in
231 // OUT ULONG * DevInfo Device Info object
232 // IN LPWSTR DevDataFile ignore
233 // IN LPWSTR DeviceName Device name
234 // IN HANDLE Driver handle to KM driver
236 // DHPDEV a handle to a DPev object
239 DrvEnablePDEV(IN DEVMODEW
*DM
,
240 IN LPWSTR LogAddress
,
241 IN ULONG PatternCount
,
242 OUT HSURF
*SurfPatterns
,
243 IN ULONG GDIInfoSize
,
245 IN ULONG DevInfoSize
,
246 OUT DEVINFO
*DevInfo
,
248 IN LPWSTR DeviceName
,
253 PDev
= EngAllocMem(FL_ZERO_MEMORY
, sizeof(PDEV
), ALLOC_TAG
);
256 EngDebugPrint(DBG_PREFIX
, "EngAllocMem failed for PDEV\n", 0);
259 PDev
->KMDriver
= Driver
;
260 DPRINT( "PDev: %x, Driver: %x\n", PDev
, PDev
->KMDriver
);
261 PDev
->xyCursor
.x
= 320;
262 PDev
->xyCursor
.y
= 240;
263 PDev
->ptlExtent
.x
= 0;
264 PDev
->ptlExtent
.y
= 0;
266 PDev
->flCursor
= CURSOR_DOWN
;
268 gaulCap
.ulHorzRes
= 640;
269 gaulCap
.ulVertRes
= 480;
270 if (sizeof(GDIINFO
) < GDIInfoSize
)
272 GDIInfoSize
= sizeof(GDIINFO
);
274 memcpy(GDIInfo
, &gaulCap
, GDIInfoSize
);
276 devinfoVGA
.hpalDefault
= EngCreatePalette(PAL_INDEXED
, 16, (ULONG
*) VGApalette
.PaletteEntry
, 0, 0, 0);
277 if (sizeof(DEVINFO
) < DevInfoSize
)
279 DevInfoSize
= sizeof(DEVINFO
);
281 memcpy(DevInfo
, &devinfoVGA
, DevInfoSize
);
283 return (DHPDEV
) PDev
;
289 // Called after initialization of PDEV is complete. Supplies
290 // a reference to the GDI handle for the PDEV.
293 DrvCompletePDEV(IN DHPDEV PDev
,
296 ((PPDEV
) PDev
)->GDIDevHandle
= Dev
; // Handle to the DC
301 DrvAssertMode(IN DHPDEV DPev
,
304 PPDEV ppdev
= (PPDEV
)DPev
;
305 ULONG returnedDataLength
;
309 // Reenable our graphics mode
311 if (!InitPointer(ppdev
))
313 // Failed to set pointer
319 if (!InitVGA(ppdev
, FALSE
))
321 // Failed to initialize the VGA
324 VGAInitialized
= TRUE
;
327 // Go back to last known mode
328 DPRINT( "ppdev: %x, KMDriver: %x", ppdev
, ppdev
->KMDriver
);
329 if (EngDeviceIoControl(ppdev
->KMDriver
, IOCTL_VIDEO_RESET_DEVICE
, NULL
, 0, NULL
, 0, &returnedDataLength
))
331 // Failed to go back to mode
334 VGAInitialized
= FALSE
;
341 DrvDisablePDEV(IN DHPDEV PDev
)
343 PPDEV ppdev
= (PPDEV
)PDev
;
345 // EngDeletePalette(devinfoVGA.hpalDefault);
346 if (ppdev
->pjPreallocSSBBuffer
!= NULL
)
348 EngFreeMem(ppdev
->pjPreallocSSBBuffer
);
351 if (ppdev
->pucDIB4ToVGAConvBuffer
!= NULL
)
353 EngFreeMem(ppdev
->pucDIB4ToVGAConvBuffer
);
355 DPRINT( "Freeing PDEV\n" );
361 DrvDisableSurface(IN DHPDEV PDev
)
363 PPDEV ppdev
= (PPDEV
)PDev
;
364 PDEVSURF pdsurf
= ppdev
->AssociatedSurf
;
366 DPRINT( "KMDriver: %x\n", ppdev
->KMDriver
);
368 // EngFreeMem(pdsurf->BankSelectInfo);
370 if (pdsurf
->BankInfo
!= NULL
) {
371 EngFreeMem(pdsurf
->BankInfo
);
374 if (pdsurf
->BankInfo2RW
!= NULL
) {
375 EngFreeMem(pdsurf
->BankInfo2RW
);
378 if (pdsurf
->BankBufferPlane0
!= NULL
) {
379 EngFreeMem(pdsurf
->BankBufferPlane0
);
382 if (ppdev
->pPointerAttributes
!= NULL
) {
383 EngFreeMem(ppdev
->pPointerAttributes
);
386 // free any pending saved screen bit blocks
388 pSSB
= pdsurf
->ssbList
;
389 while (pSSB
!= (PSAVED_SCREEN_BITS
) NULL
) {
391 // Point to the next saved screen bits block
392 pSSBNext
= (PSAVED_SCREEN_BITS
) pSSB
->pvNextSSB
;
394 // Free the current block
399 EngDeleteSurface((HSURF
) ppdev
->SurfHandle
);
400 // EngFreeMem(pdsurf); // free the surface
405 InitSavedBits(PPDEV ppdev
)
407 if (!(ppdev
->fl
& DRIVER_OFFSCREEN_REFRESHED
))
412 // set up rect to right of visible screen
413 ppdev
->SavedBitsRight
.left
= ppdev
->sizeSurf
.cx
;
414 ppdev
->SavedBitsRight
.top
= 0;
415 ppdev
->SavedBitsRight
.right
= ppdev
->sizeMem
.cx
-PLANAR_PELS_PER_CPU_ADDRESS
;
416 ppdev
->SavedBitsRight
.bottom
= ppdev
->sizeSurf
.cy
;
418 if ((ppdev
->SavedBitsRight
.right
<= ppdev
->SavedBitsRight
.left
) ||
419 (ppdev
->SavedBitsRight
.bottom
<= ppdev
->SavedBitsRight
.top
))
421 ppdev
->SavedBitsRight
.left
= 0;
422 ppdev
->SavedBitsRight
.top
= 0;
423 ppdev
->SavedBitsRight
.right
= 0;
424 ppdev
->SavedBitsRight
.bottom
= 0;
427 // set up rect below visible screen
428 ppdev
->SavedBitsBottom
.left
= 0;
429 ppdev
->SavedBitsBottom
.top
= ppdev
->sizeSurf
.cy
;
430 ppdev
->SavedBitsBottom
.right
= ppdev
->sizeMem
.cx
-PLANAR_PELS_PER_CPU_ADDRESS
;
431 ppdev
->SavedBitsBottom
.bottom
= ppdev
->sizeMem
.cy
- ppdev
->NumScansUsedByPointer
;
433 if ((ppdev
->SavedBitsBottom
.right
<= ppdev
->SavedBitsBottom
.left
) ||
434 (ppdev
->SavedBitsBottom
.bottom
<= ppdev
->SavedBitsBottom
.top
))
436 ppdev
->SavedBitsBottom
.left
= 0;
437 ppdev
->SavedBitsBottom
.top
= 0;
438 ppdev
->SavedBitsBottom
.right
= 0;
439 ppdev
->SavedBitsBottom
.bottom
= 0;
442 ppdev
->BitsSaved
= FALSE
;
449 DrvEnableSurface(IN DHPDEV PDev
)
451 PPDEV ppdev
= (PPDEV
)PDev
;
456 DPRINT("DrvEnableSurface() called\n");
458 // Initialize the VGA
461 if (!InitVGA(ppdev
, TRUE
))
465 VGAInitialized
= TRUE
;
468 // dhsurf is of type DEVSURF, which is the drivers specialized surface type
469 dhsurf
= (DHSURF
)EngAllocMem(0, sizeof(DEVSURF
), ALLOC_TAG
);
470 if (dhsurf
== (DHSURF
) 0)
475 pdsurf
= (PDEVSURF
) dhsurf
;
476 pdsurf
->ident
= DEVSURF_IDENT
;
478 pdsurf
->Format
= BMF_PHYSDEVICE
;
479 pdsurf
->jReserved1
= 0;
480 pdsurf
->jReserved2
= 0;
481 pdsurf
->ppdev
= ppdev
;
482 pdsurf
->sizeSurf
.cx
= ppdev
->sizeSurf
.cx
;
483 pdsurf
->sizeSurf
.cy
= ppdev
->sizeSurf
.cy
;
484 pdsurf
->NextPlane
= 0;
485 pdsurf
->Scan0
= ppdev
->fbScreen
;
486 pdsurf
->BitmapStart
= ppdev
->fbScreen
;
487 pdsurf
->StartBmp
= ppdev
->fbScreen
;
488 pdsurf
->BankInfo
= NULL
;
489 pdsurf
->BankInfo2RW
= NULL
;
490 pdsurf
->BankBufferPlane0
= NULL
;
492 /* pdsurf->Conv = &ConvertBuffer[0]; */
494 if (!InitPointer(ppdev
)) {
495 DbgPrint("DrvEnablePDEV failed bInitPointer\n");
499 /* if (!SetUpBanking(pdsurf, ppdev)) {
500 DISPDBG((0, "DrvEnablePDEV failed SetUpBanking\n"));
502 } BANKING CODE UNIMPLEMENTED */
504 if ((hsurf
= EngCreateDeviceSurface(dhsurf
, ppdev
->sizeSurf
, BMF_4BPP
)) ==
507 // Call to EngCreateDeviceSurface failed
508 EngDebugPrint("VGADDI:", "EngCreateDeviceSurface call failed\n", 0);
512 InitSavedBits(ppdev
);
514 if (EngAssociateSurface(hsurf
, ppdev
->GDIDevHandle
, HOOK_BITBLT
| HOOK_PAINT
| HOOK_LINETO
| HOOK_COPYBITS
|
515 HOOK_TRANSPARENTBLT
))
517 /* EngDebugPrint("VGADDI:", "Successfully associated surface\n", 0); */
518 ppdev
->SurfHandle
= hsurf
;
519 ppdev
->AssociatedSurf
= pdsurf
;
521 // Set up an empty saved screen block list
522 pdsurf
->ssbList
= NULL
;
526 DPRINT( "EngAssociateSurface() failed\n" );
527 EngDeleteSurface(hsurf
);
538 DrvGetModes(IN HANDLE Driver
,
545 DWORD OutputModes
= DataSize
/ (sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
546 PVIDEO_MODE_INFORMATION VideoModeInformation
, VideoTemp
;
548 NumModes
= getAvailableModes(Driver
,
549 (PVIDEO_MODE_INFORMATION
*) &VideoModeInformation
,
559 OutputSize
= NumModes
* (sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
563 VideoTemp
= VideoModeInformation
;
567 if (VideoTemp
->Length
!= 0)
569 if (OutputModes
== 0)
574 memset(DM
, 0, sizeof(DEVMODEW
));
575 memcpy(DM
->dmDeviceName
, DLL_NAME
, sizeof(DLL_NAME
));
577 DM
->dmSpecVersion
= DM_SPECVERSION
;
578 DM
->dmDriverVersion
= DM_SPECVERSION
;
579 DM
->dmSize
= sizeof(DEVMODEW
);
580 DM
->dmDriverExtra
= DRIVER_EXTRA_SIZE
;
581 DM
->dmBitsPerPel
= VideoTemp
->NumberOfPlanes
*
582 VideoTemp
->BitsPerPlane
;
583 DM
->dmPelsWidth
= VideoTemp
->VisScreenWidth
;
584 DM
->dmPelsHeight
= VideoTemp
->VisScreenHeight
;
585 DM
->dmDisplayFrequency
= VideoTemp
->Frequency
;
586 DM
->dmDisplayFlags
= 0;
588 DM
->dmFields
= DM_BITSPERPEL
|
591 DM_DISPLAYFREQUENCY
|
594 // next DEVMODE entry
597 DM
= (PDEVMODEW
) ( ((ULONG
)DM
) + sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
599 OutputSize
+= (sizeof(DEVMODEW
) + DRIVER_EXTRA_SIZE
);
602 VideoTemp
= (PVIDEO_MODE_INFORMATION
)(((PUCHAR
)VideoTemp
) + ModeSize
);
604 } while (--NumModes
);