|
|
1.1 root 1: /******************************Module*Header*******************************\
2: * Module Name: screen.c
3: *
4: * Initializes the GDIINFO and DEVINFO structures for DrvEnablePDEV.
5: *
6: * Copyright (c) 1992 Microsoft Corporation
7: \**************************************************************************/
8:
9: #include "driver.h"
10:
11: #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"}
12: #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"}
13: #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"}
14:
15: // This is the basic devinfo for a default driver. This is used as a base and customized based
16: // on information passed back from the miniport driver.
17:
18: const DEVINFO gDevInfoFrameBuffer = {
19: GCAPS_OPAQUERECT | GCAPS_MONO_DITHER, /* Graphics capabilities */
20: SYSTM_LOGFONT, /* Default font description */
21: HELVE_LOGFONT, /* ANSI variable font description */
22: COURI_LOGFONT, /* ANSI fixed font description */
23: 0, /* Count of device fonts */
24: 0, /* Preferred DIB format */
25: 8, /* Width of color dither */
26: 8, /* Height of color dither */
27: 0 /* Default palette to use for this device */
28: };
29:
30: /******************************Public*Routine******************************\
31: * bInitSURF
32: *
33: * Enables the surface. Maps the frame buffer into memory.
34: *
35: \**************************************************************************/
36:
37: BOOL bInitSURF(PPDEV ppdev, BOOL bFirst)
38: {
39:
40: VIDEO_MEMORY VideoMemory;
41: VIDEO_MEMORY_INFORMATION VideoMemoryInfo;
42: DWORD ReturnedDataLength;
43: DWORD XGAPixelOp;
44:
45: VIDEO_XGA_COPROCESSOR_INFORMATION CoProcessorInfo;
46:
47: if (!DeviceIoControl(ppdev->hDriver,
48: IOCTL_VIDEO_SET_CURRENT_MODE,
49: &ppdev->ulMode, // input buffer
50: sizeof(VIDEO_MODE),
51: NULL,
52: 0,
53: &ReturnedDataLength,
54: NULL)) {
55:
56: RIP("XGA.DLL: Initialization error-Set mode\n");
57:
58: }
59:
60: if (bFirst) {
61:
62: VideoMemory.RequestedVirtualAddress = NULL;
63:
64: if (!DeviceIoControl(ppdev->hDriver,
65: IOCTL_VIDEO_MAP_VIDEO_MEMORY,
66: (PVOID) &VideoMemory, // input buffer
67: sizeof (VIDEO_MEMORY),
68: (PVOID) &VideoMemoryInfo, // output buffer
69: sizeof (VideoMemoryInfo),
70: &ReturnedDataLength,
71: NULL)) {
72:
73: RIP("XGA.DLL: Initialization error-Map buffer address\n");
74:
75: }
76:
77: ppdev->pjScreen = VideoMemoryInfo.FrameBufferBase;
78: ppdev->ulScreenSize = VideoMemoryInfo.FrameBufferLength;
79: ppdev->ulVideoMemorySize = VideoMemoryInfo.VideoRamLength;
80:
81: if (!DeviceIoControl(ppdev->hDriver,
82: IOCTL_VIDEO_XGA_MAP_COPROCESSOR,
83: NULL, // input buffer
84: 0,
85: &CoProcessorInfo, // output buffer
86: sizeof (VIDEO_XGA_COPROCESSOR_INFORMATION),
87: &ReturnedDataLength,
88: NULL)) {
89:
90: RIP("XGA.DLL: Initialization error-Map Coprocessor buffer address\n");
91:
92: }
93:
94: // Set the globals, we will need these almost everywhere.
95:
96: ppdev->pXgaCpRegs = CoProcessorInfo.CoProcessorVirtualAddress;
97: ppdev->ulPhysFrameBuffer = (ULONG) CoProcessorInfo.PhysicalVideoMemoryAddress;
98: ppdev->ulXgaIoRegsBase = CoProcessorInfo.XgaIoRegisterBaseAddress;
99:
100: // Set the coprocessor defaults (Target pel map).
101: // The conventions for this driver will have the Target
102: // Pel map as map A.
103:
104: ppdev->pXgaCpRegs->XGAPixelMapIndex = PEL_MAP_A;
105: ppdev->pXgaCpRegs->XGAPixMapBasePtr = ppdev->ulPhysFrameBuffer;
106: ppdev->pXgaCpRegs->XGAPixMapWidth = (USHORT) ppdev->cxScreen - 1;
107: ppdev->pXgaCpRegs->XGAPixMapHeight = (USHORT) ppdev->cyScreen - 1;
108: ppdev->pXgaCpRegs->XGAPixMapFormat = PEL_MAP_FORMAT;
109:
110: ppdev->pXgaCpRegs->XGADestColCompCond = CCCC_FALSE;
111: ppdev->pXgaCpRegs->XGAPixelBitMask = 0xFF;
112:
113: //
114: // Init the XGA memory manager.
115: //
116:
117: bCpMmInitHeap(ppdev);
118:
119: //
120: // Determine if the coprocessor is working properly.
121: // Try a solid fill; if it fails, then disable all accelerations.
122: //
123:
124: ppdev->pXgaCpRegs->XGAOpDim1 = 1;
125: ppdev->pXgaCpRegs->XGAOpDim2 = 1;
126:
127: ppdev->pXgaCpRegs->XGADestMapX = 0;
128: ppdev->pXgaCpRegs->XGADestMapY = 0;
129:
130: ppdev->pXgaCpRegs->XGAForeGrMix = XGA_S;
131: ppdev->pXgaCpRegs->XGABackGrMix = XGA_S;
132:
133: ppdev->pXgaCpRegs->XGAForeGrColorReg = 0x55;
134:
135: //
136: // Now build the Pel Operation Register Op Code;
137: //
138:
139: XGAPixelOp = BS_BACK_COLOR | FS_FORE_COLOR | STEP_PX_BLT |
140: SRC_PEL_MAP_A | DST_PEL_MAP_A | PATT_FOREGROUND;
141:
142: ppdev->pXgaCpRegs->XGAPixelOp = XGAPixelOp;
143:
144: //
145: // Wait for the coprocessor.
146: //
147:
148: vWaitForCoProcessor(ppdev, 10) ;
149:
150: //
151: // Read the byte back to see if it was blit to the screen properly.
152: // BUGBUG !!!
153: // This is to allow the driver to treat the hardware as a frame buffer
154: // in the case where the IBM hardware is broken !
155: //
156:
157: if (*(ppdev->pjScreen) == 0x55) {
158:
159: //
160: // private flag used for determining driver capabilities.
161: //
162:
163:
164: ppdev->ulfAccelerations_debug = CACHED_FONTS;
165: ppdev->ulfBlitAccelerations_debug = SCRN_TO_SCRN_CPY | SOLID_PATTERN;
166:
167: } else {
168:
169: //
170: // !!! Turn off all accelerations for broken hardware !
171: //
172:
173: ppdev->ulfAccelerations_debug = 0;
174: ppdev->ulfBlitAccelerations_debug = 0;
175:
176: }
177: }
178:
179: return(TRUE);
180: }
181:
182: /******************************Public*Routine******************************\
183: * vDisableSURF
184: *
185: * Disable the surface. Un-Maps the frame in memory.
186: *
187: \**************************************************************************/
188:
189: VOID vDisableSURF(PPDEV ppdev)
190: {
191: DWORD returnedDataLength;
192: VIDEO_MEMORY videoMemory;
193:
194: videoMemory.RequestedVirtualAddress = (PVOID) ppdev->pjScreen;
195:
196: if (!DeviceIoControl(ppdev->hDriver,
197: IOCTL_VIDEO_UNMAP_VIDEO_MEMORY,
198: &videoMemory,
199: sizeof(VIDEO_MEMORY),
200: NULL,
201: 0,
202: &returnedDataLength,
203: NULL))
204: {
205: DISPDBG((0, "DISP vDisableSURF failed IOCTL_VIDEO_UNMAP\n"));
206: }
207: }
208:
209: /******************************Public*Routine******************************\
210: * bInitPDEV
211: *
212: * Determine the mode we should be in based on the DEVMODE passed in.
213: * Query mini-port to get information needed to fill in the DevInfo and the
214: * GdiInfo .
215: *
216: \**************************************************************************/
217:
218: BOOL bInitPDEV(
219: PPDEV ppdev,
220: DEVMODEW *pDevMode,
221: GDIINFO *pGdiInfo,
222: DEVINFO *pDevInfo)
223: {
224: ULONG cModes;
225: PVIDEO_MODE_INFORMATION pVideoBuffer, pVideoModeSelected, pVideoTemp;
226: VIDEO_COLOR_CAPABILITIES colorCapabilities;
227: ULONG ulTemp;
228: BOOL bSelectDefault;
229: ULONG cbModeSize;
230:
231: //
232: // calls the miniport to get mode information.
233: //
234:
235: cModes = getAvailableModes(ppdev->hDriver, &pVideoBuffer, &cbModeSize);
236:
237: if (cModes == 0)
238: {
239: return(FALSE);
240: }
241:
242: //
243: // Determine if we are looking for a default mode.
244: //
245:
246: if ( ((pDevMode->dmPelsWidth) ||
247: (pDevMode->dmPelsHeight) ||
248: (pDevMode->dmBitsPerPel) ||
249: (pDevMode->dmDisplayFlags) ||
250: (pDevMode->dmDisplayFrequency)) == 0)
251: {
252: bSelectDefault = TRUE;
253: }
254: else
255: {
256: bSelectDefault = FALSE;
257: }
258:
259: //
260: // Now see if the requested mode has a match in that table.
261: //
262:
263: pVideoModeSelected = NULL;
264: pVideoTemp = pVideoBuffer;
265:
266: while (cModes--)
267: {
268: if (pVideoTemp->Length != 0)
269: {
270: if (bSelectDefault ||
271: ((pVideoTemp->VisScreenWidth == pDevMode->dmPelsWidth) &&
272: (pVideoTemp->VisScreenHeight == pDevMode->dmPelsHeight) &&
273: (pVideoTemp->BitsPerPlane *
274: pVideoTemp->NumberOfPlanes == pDevMode->dmBitsPerPel) &&
275: ((pVideoTemp->Frequency == pDevMode->dmDisplayFrequency) ||
276: (pDevMode->dmDisplayFrequency == 0)) &&
277: (((pVideoTemp->AttributeFlags &
278: VIDEO_MODE_INTERLACED) ? 1:0) ==
279: ((pDevMode->dmDisplayFlags & DM_INTERLACED) ? 1:0)) ) )
280:
281: {
282: pVideoModeSelected = pVideoTemp;
283: DISPDBG((3, "XGA: Found a match\n"));
284: break;
285: }
286: }
287:
288: pVideoTemp = (PVIDEO_MODE_INFORMATION)
289: (((PUCHAR)pVideoTemp) + cbModeSize);
290: }
291:
292: //
293: // If no mode has been found, return an error
294: //
295:
296: if (pVideoModeSelected == NULL)
297: {
298: LocalFree(pVideoBuffer);
299: return(FALSE);
300: }
301:
302: //
303: // Fill in the GDIINFO data structure with the information returned from
304: // the kernel driver.
305: //
306:
307: ppdev->ulMode = pVideoModeSelected->ModeIndex;
308: ppdev->cxScreen = pVideoModeSelected->VisScreenWidth;
309: ppdev->cyScreen = pVideoModeSelected->VisScreenHeight;
310: ppdev->ulBitCount = pVideoModeSelected->BitsPerPlane *
311: pVideoModeSelected->NumberOfPlanes;
312: ppdev->lDeltaScreen = pVideoModeSelected->ScreenStride;
313:
314: ppdev->flRed = pVideoModeSelected->RedMask;
315: ppdev->flGreen = pVideoModeSelected->GreenMask;
316: ppdev->flBlue = pVideoModeSelected->BlueMask;
317:
318:
319: pGdiInfo->ulVersion = 0x1000; // Our driver is verion 1.000
320: pGdiInfo->ulTechnology = DT_RASDISPLAY;
321: pGdiInfo->ulHorzSize = pVideoModeSelected->XMillimeter;
322: pGdiInfo->ulVertSize = pVideoModeSelected->YMillimeter;
323:
324: pGdiInfo->ulHorzRes = ppdev->cxScreen;
325: pGdiInfo->ulVertRes = ppdev->cyScreen;
326: pGdiInfo->cBitsPixel = pVideoModeSelected->BitsPerPlane;
327: pGdiInfo->cPlanes = pVideoModeSelected->NumberOfPlanes;
328:
329: pGdiInfo->ulLogPixelsX = 96;
330: pGdiInfo->ulLogPixelsY = 96;
331:
332: pGdiInfo->flTextCaps = TC_RA_ABLE;
333: pGdiInfo->flRaster = 0; // DDI reserves flRaster
334:
335: pGdiInfo->ulDACRed = pVideoModeSelected->NumberRedBits;
336: pGdiInfo->ulDACGreen = pVideoModeSelected->NumberGreenBits;
337: pGdiInfo->ulDACBlue = pVideoModeSelected->NumberBlueBits;
338:
339: pGdiInfo->ulAspectX = 0x24; // One-to-one aspect ratio
340: pGdiInfo->ulAspectY = 0x24;
341: pGdiInfo->ulAspectXY = 0x33;
342:
343: pGdiInfo->xStyleStep = 1; // A style unit is 3 pels
344: pGdiInfo->yStyleStep = 1;
345: pGdiInfo->denStyleStep = 3;
346:
347: pGdiInfo->ptlPhysOffset.x = 0;
348: pGdiInfo->ptlPhysOffset.y = 0;
349: pGdiInfo->szlPhysSize.cx = 0;
350: pGdiInfo->szlPhysSize.cy = 0;
351:
352: // RGB and CMY color info.
353:
354: // try to get it from the miniport.
355: // if the miniport doesn ot support this feature, use defaults.
356:
357: if (!DeviceIoControl(ppdev->hDriver,
358: IOCTL_VIDEO_QUERY_COLOR_CAPABILITIES,
359: NULL,
360: 0,
361: &colorCapabilities,
362: sizeof(VIDEO_COLOR_CAPABILITIES),
363: &ulTemp,
364: NULL))
365: {
366: DISPDBG((1, "XGA DISP getcolorCapabilities failed \n"));
367:
368: pGdiInfo->ciDevice.Red.x = 6700;
369: pGdiInfo->ciDevice.Red.y = 3300;
370: pGdiInfo->ciDevice.Red.Y = 0;
371: pGdiInfo->ciDevice.Green.x = 2100;
372: pGdiInfo->ciDevice.Green.y = 7100;
373: pGdiInfo->ciDevice.Green.Y = 0;
374: pGdiInfo->ciDevice.Blue.x = 1400;
375: pGdiInfo->ciDevice.Blue.y = 800;
376: pGdiInfo->ciDevice.Blue.Y = 0;
377: pGdiInfo->ciDevice.AlignmentWhite.x = 3127;
378: pGdiInfo->ciDevice.AlignmentWhite.y = 3290;
379: pGdiInfo->ciDevice.AlignmentWhite.Y = 0;
380:
381: pGdiInfo->ciDevice.RedGamma = 20000;
382: pGdiInfo->ciDevice.GreenGamma = 20000;
383: pGdiInfo->ciDevice.BlueGamma = 20000;
384:
385: }
386: else
387: {
388:
389: pGdiInfo->ciDevice.Red.x = colorCapabilities.RedChromaticity_x;
390: pGdiInfo->ciDevice.Red.y = colorCapabilities.RedChromaticity_y;
391: pGdiInfo->ciDevice.Red.Y = 0;
392: pGdiInfo->ciDevice.Green.x = colorCapabilities.GreenChromaticity_x;
393: pGdiInfo->ciDevice.Green.y = colorCapabilities.GreenChromaticity_y;
394: pGdiInfo->ciDevice.Green.Y = 0;
395: pGdiInfo->ciDevice.Blue.x = colorCapabilities.BlueChromaticity_x;
396: pGdiInfo->ciDevice.Blue.y = colorCapabilities.BlueChromaticity_y;
397: pGdiInfo->ciDevice.Blue.Y = 0;
398: pGdiInfo->ciDevice.AlignmentWhite.x = colorCapabilities.WhiteChromaticity_x;
399: pGdiInfo->ciDevice.AlignmentWhite.y = colorCapabilities.WhiteChromaticity_y;
400: pGdiInfo->ciDevice.AlignmentWhite.Y = colorCapabilities.WhiteChromaticity_Y;
401:
402: // if we have a color device store the three color gamma values,
403: // otherwise store the unique gamma value in all three.
404:
405: if (colorCapabilities.AttributeFlags & VIDEO_DEVICE_COLOR)
406: {
407: pGdiInfo->ciDevice.RedGamma = colorCapabilities.RedGamma;
408: pGdiInfo->ciDevice.GreenGamma = colorCapabilities.GreenGamma;
409: pGdiInfo->ciDevice.BlueGamma = colorCapabilities.BlueGamma;
410: }
411: else
412: {
413: pGdiInfo->ciDevice.RedGamma = colorCapabilities.WhiteGamma;
414: pGdiInfo->ciDevice.GreenGamma = colorCapabilities.WhiteGamma;
415: pGdiInfo->ciDevice.BlueGamma = colorCapabilities.WhiteGamma;
416: }
417:
418: };
419:
420: pGdiInfo->ciDevice.Cyan.x = 0;
421: pGdiInfo->ciDevice.Cyan.y = 0;
422: pGdiInfo->ciDevice.Cyan.Y = 0;
423: pGdiInfo->ciDevice.Magenta.x = 0;
424: pGdiInfo->ciDevice.Magenta.y = 0;
425: pGdiInfo->ciDevice.Magenta.Y = 0;
426: pGdiInfo->ciDevice.Yellow.x = 0;
427: pGdiInfo->ciDevice.Yellow.y = 0;
428: pGdiInfo->ciDevice.Yellow.Y = 0;
429:
430: // No dye correction for raster displays.
431:
432: pGdiInfo->ciDevice.MagentaInCyanDye = 0;
433: pGdiInfo->ciDevice.YellowInCyanDye = 0;
434: pGdiInfo->ciDevice.CyanInMagentaDye = 0;
435: pGdiInfo->ciDevice.YellowInMagentaDye = 0;
436: pGdiInfo->ciDevice.CyanInYellowDye = 0;
437: pGdiInfo->ciDevice.MagentaInYellowDye = 0;
438:
439: pGdiInfo->ulDevicePelsDPI = 0; // For printers only
440: pGdiInfo->ulPrimaryOrder = PRIMARY_ORDER_CBA;
441:
442: // BUGBUG this should be modified to take into account the size
443: // of the display and the resolution.
444:
445: pGdiInfo->ulHTPatternSize = HT_PATSIZE_4x4_M;
446:
447: pGdiInfo->flHTFlags = HT_FLAG_ADDITIVE_PRIMS;
448:
449: // Fill in the basic devinfo structure
450:
451: *pDevInfo = gDevInfoFrameBuffer;
452:
453: // Fill in the rest of the devinfo and GdiInfo structures.
454:
455: if (ppdev->ulBitCount == 8)
456: {
457:
458: // BUGBUG check if we have a palette managed device.
459: // BUGBUG why is ulNumColors set to 20 ?
460:
461: // It is Palette Managed.
462:
463: pGdiInfo->ulNumColors = 20;
464: pGdiInfo->ulNumPalReg = 1 << ppdev->ulBitCount;
465:
466: pGdiInfo->flRaster |= RC_PALETTE;
467: pGdiInfo->ulHTOutputFormat = HT_FORMAT_8BPP;
468:
469: pDevInfo->iDitherFormat = BMF_8BPP;
470: pDevInfo->flGraphicsCaps |= (GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
471:
472: }
473: else
474: {
475: pGdiInfo->ulNumColors = 1 << ppdev->ulBitCount;
476: pGdiInfo->ulNumPalReg = 0;
477:
478: pDevInfo->iDitherFormat = BMF_16BPP;
479: pGdiInfo->ulHTOutputFormat = HT_FORMAT_16BPP;
480: }
481:
482: LocalFree(pVideoBuffer);
483:
484: return(TRUE);
485: }
486:
487:
488: /******************************Public*Routine******************************\
489: * getAvailableModes
490: *
491: * Calls the miniport to get the list of modes supported by the kernel driver,
492: * and returns the list of modes supported by the diplay driver among those
493: *
494: * returns the number of entries in the videomode buffer.
495: * 0 means no modes are supported by the miniport or that an error occured.
496: *
497: * NOTE: the buffer must be freed up by the caller.
498: *
499: \**************************************************************************/
500:
501: DWORD getAvailableModes(
502: HANDLE hDriver,
503: PVIDEO_MODE_INFORMATION *modeInformation,
504: DWORD *cbModeSize)
505: {
506: ULONG ulTemp;
507: VIDEO_NUM_MODES modes;
508: PVIDEO_MODE_INFORMATION pVideoTemp;
509:
510: //
511: // Get the number of modes supported by the mini-port
512: //
513:
514: if (!DeviceIoControl(hDriver,
515: IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES,
516: NULL,
517: 0,
518: &modes,
519: sizeof(VIDEO_NUM_MODES),
520: &ulTemp,
521: NULL))
522: {
523: DISPDBG((0, "xga.dll getAvailableModes failed VIDEO_QUERY_NUM_AVAIL_MODES\n"));
524: return(0);
525: }
526:
527: *cbModeSize = modes.ModeInformationLength;
528:
529: //
530: // Allocate the buffer for the mini-port to write the modes in.
531: //
532:
533: *modeInformation = (PVIDEO_MODE_INFORMATION)
534: LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT,
535: modes.NumModes *
536: modes.ModeInformationLength);
537:
538: if (*modeInformation == (PVIDEO_MODE_INFORMATION) NULL)
539: {
540: DISPDBG((0, "xga.dll getAvailableModes failed LocalAlloc\n"));
541:
542: return 0;
543: }
544:
545: //
546: // Ask the mini-port to fill in the available modes.
547: //
548:
549: if (!DeviceIoControl(hDriver,
550: IOCTL_VIDEO_QUERY_AVAIL_MODES,
551: NULL,
552: 0,
553: *modeInformation,
554: modes.NumModes * modes.ModeInformationLength,
555: &ulTemp,
556: NULL))
557: {
558:
559: DISPDBG((0, "xga.dll getAvailableModes failed VIDEO_QUERY_AVAIL_MODES\n"));
560:
561: LocalFree(*modeInformation);
562: *modeInformation = (PVIDEO_MODE_INFORMATION) NULL;
563:
564: return(0);
565: }
566:
567: //
568: // Now see which of these modes are supported by the display driver.
569: // As an internal mechanism, set the length to 0 for the modes we
570: // DO NOT support.
571: //
572:
573: ulTemp = modes.NumModes;
574: pVideoTemp = *modeInformation;
575:
576: //
577: // Mode is rejected if it is not one plane, or not graphics, or is not
578: // one of 8 bits per pel.
579: //
580:
581: while (ulTemp--)
582: {
583: if ((pVideoTemp->NumberOfPlanes != 1 ) ||
584: !(pVideoTemp->AttributeFlags & VIDEO_MODE_GRAPHICS) ||
585: (pVideoTemp->BitsPerPlane != 8))
586: {
587: pVideoTemp->Length = 0;
588: }
589:
590: pVideoTemp = (PVIDEO_MODE_INFORMATION)
591: (((PUCHAR)pVideoTemp) + modes.ModeInformationLength);
592: }
593:
594: return modes.NumModes;
595:
596: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.