|
|
1.1 root 1: /******************************Module*Header*******************************\
2: * Module Name: enable.c
3: *
4: * This module contains the functions that enable and disable the
5: * driver, the pdev, and the surface.
6: *
7: \**************************************************************************/
8:
9: // #define DFB_ENABLED 1
10:
11: #include "driver.h"
12:
13: #ifdef DFB_ENABLED
14:
15: BOOL DrvDFBTextOut(
16: SURFOBJ *pso,
17: STROBJ *pstro,
18: FONTOBJ *pfo,
19: CLIPOBJ *pco,
20: RECTL *prclExtra,
21: RECTL *prclOpaque,
22: BRUSHOBJ *pboFore,
23: BRUSHOBJ *pboOpaque,
24: POINTL *pptlOrg,
25: MIX mix);
26:
27: #endif
28:
29: // The driver function table with all function index/address pairs
30:
31: static DRVFN gadrvfn[] =
32: {
33: { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
34: { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
35: { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
36: { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
37: { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
38: { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
39: { INDEX_DrvSetPalette, (PFN) DrvSetPalette },
40: { INDEX_DrvMovePointer, (PFN) DrvMovePointer },
41: { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape },
42: { INDEX_DrvDitherColor, (PFN) DrvDitherColor },
43: #ifdef DFB_ENABLED
44: { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap },
45: { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap },
46: { INDEX_DrvStrokePath, (PFN) DrvStrokePath },
47: { INDEX_DrvCopyBits, (PFN) DrvCopyBits },
48: { INDEX_DrvTextOut, (PFN) DrvDFBTextOut },
49: #else
50: #ifdef MIPS
51: { INDEX_DrvTextOut, (PFN) DrvTextOut },
52: #endif
53: #endif
54: { INDEX_DrvGetModes, (PFN) DrvGetModes }
55: };
56:
57: // Define the functions you want to hook for 8/16/24/32 pel formats
58:
59: #ifdef MIPS
60: #define HOOKS_BMF8BPP HOOK_TEXTOUT
61: #else
62: #define HOOKS_BMF8BPP 0
63: #endif
64:
65: #define HOOKS_BMF16BPP 0
66:
67: #define HOOKS_BMF24BPP 0
68:
69: #define HOOKS_BMF32BPP 0
70:
71: /******************************Public*Routine******************************\
72: * DrvEnableDriver
73: *
74: * Enables the driver by retrieving the drivers function table and version.
75: *
76: \**************************************************************************/
77:
78: BOOL DrvEnableDriver(
79: ULONG iEngineVersion,
80: ULONG cj,
81: PDRVENABLEDATA pded)
82: {
83: // Engine Version is passed down so future drivers can support previous
84: // engine versions. A next generation driver can support both the old
85: // and new engine conventions if told what version of engine it is
86: // working with. For the first version the driver does nothing with it.
87:
88: iEngineVersion;
89:
90: // Fill in as much as we can.
91:
92: if (cj >= sizeof(DRVENABLEDATA))
93: pded->pdrvfn = gadrvfn;
94:
95: if (cj >= (sizeof(ULONG) * 2))
96: pded->c = sizeof(gadrvfn) / sizeof(DRVFN);
97:
98: // DDI version this driver was targeted for is passed back to engine.
99: // Future graphic's engine may break calls down to old driver format.
100:
101: if (cj >= sizeof(ULONG))
102: pded->iDriverVersion = DDI_DRIVER_VERSION;
103:
104: return(TRUE);
105: }
106:
107: /******************************Public*Routine******************************\
108: * DrvDisableDriver
109: *
110: * Tells the driver it is being disabled. Release any resources allocated in
111: * DrvEnableDriver.
112: *
113: \**************************************************************************/
114:
115: VOID DrvDisableDriver(VOID)
116: {
117: return;
118: }
119:
120: /******************************Public*Routine******************************\
121: * DrvEnablePDEV
122: *
123: * DDI function, Enables the Physical Device.
124: *
125: * Return Value: device handle to pdev.
126: *
127: \**************************************************************************/
128:
129: DHPDEV DrvEnablePDEV(
130: DEVMODEW *pDevmode, // Pointer to DEVMODE
131: PWSTR pwszLogAddress, // Logical address
132: ULONG cPatterns, // number of patterns
133: HSURF *ahsurfPatterns, // return standard patterns
134: ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
135: ULONG *pGdiInfo, // Pointer to GdiInfo structure
136: ULONG cjDevInfo, // Length of following PDEVINFO structure
137: DEVINFO *pDevInfo, // physical device information structure
138: PWSTR pwszDataFile, // DataFile - not used
139: PWSTR pwszDeviceName, // DeviceName - not used
140: HANDLE hDriver) // Handle to base driver
141: {
142: GDIINFO GdiInfo;
143: DEVINFO DevInfo;
144: PPDEV ppdev = (PPDEV) NULL;
145:
146: UNREFERENCED_PARAMETER(pwszLogAddress);
147: UNREFERENCED_PARAMETER(pwszDataFile);
148: UNREFERENCED_PARAMETER(pwszDeviceName);
149:
150: // Allocate a physical device structure.
151:
152: ppdev = (PPDEV) LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, sizeof(PDEV));
153:
154: if (ppdev == (PPDEV) NULL)
155: {
156: RIP("DISP DrvEnablePDEV failed LocalAlloc\n");
157: return((DHPDEV) 0);
158: }
159:
160: // Save the screen handle in the PDEV.
161:
162: ppdev->hDriver = hDriver;
163:
164: // Get the current screen mode information. Set up device caps and devinfo.
165:
166: if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
167: {
168: DISPDBG((1,"DISP DrvEnablePDEV failed\n"));
169: goto error_free;
170: }
171:
172: // Initialize the cursor information.
173:
174: if (!bInitPointer(ppdev, &DevInfo))
175: {
176: // Not a fatal error...
177: DISPDBG((0, "DISP DrvEnableSurface failed bInitPointer\n"));
178: }
179:
180: // Initialize palette information.
181:
182: if (!bInitPaletteInfo(ppdev, &DevInfo))
183: {
184: RIP("DISP DrvEnableSurface failed bInitPalette\n");
185: goto error_free;
186: }
187:
188: // Initialize device standard patterns.
189:
190: if (!bInitPatterns(ppdev, min(cPatterns, HS_DDI_MAX)))
191: {
192: RIP("DISP DrvEnablePDEV failed bInitPatterns\n");
193: vDisablePatterns(ppdev);
194: vDisablePalette(ppdev);
195: goto error_free;
196: }
197:
198: // Copy the devinfo into the engine buffer.
199:
200: memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
201:
202: // Set the ahsurfPatterns array to handles each of the standard
203: // patterns that were just created.
204:
205: memcpy((PVOID)ahsurfPatterns, ppdev->ahbmPat, ppdev->cPatterns*sizeof(HBITMAP));
206:
207: // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
208: // pdev.
209:
210: memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
211:
212: return((DHPDEV) ppdev);
213:
214: // Error case for failure.
215: error_free:
216: LocalFree(ppdev);
217: RIP("DISP DrvEnablePDEV failed\n");
218: return((DHPDEV) 0);
219: }
220:
221: /******************************Public*Routine******************************\
222: * DrvCompletePDEV
223: *
224: * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
225: *
226: \**************************************************************************/
227:
228: VOID DrvCompletePDEV(
229: DHPDEV dhpdev,
230: HDEV hdev)
231: {
232: ((PPDEV) dhpdev)->hdevEng = hdev;
233: }
234:
235: /******************************Public*Routine******************************\
236: * DrvDisablePDEV
237: *
238: * Release the resources allocated in DrvEnablePDEV. If a surface has been
239: * enabled DrvDisableSurface will have already been called.
240: *
241: \**************************************************************************/
242:
243: VOID DrvDisablePDEV(
244: DHPDEV dhpdev)
245: {
246: vDisablePalette((PPDEV) dhpdev);
247: vDisablePatterns((PPDEV) dhpdev);
248: LocalFree(dhpdev);
249: }
250:
251: /******************************Public*Routine******************************\
252: * DrvEnableSurface
253: *
254: * Enable the surface for the device. Hook the calls this driver supports.
255: *
256: * Return: Handle to the surface if successful, 0 for failure.
257: *
258: \**************************************************************************/
259:
260: HSURF DrvEnableSurface(
261: DHPDEV dhpdev)
262: {
263: PPDEV ppdev;
264: HSURF hsurf;
265: SIZEL sizl;
266: ULONG ulBitmapType;
267: FLONG flHooks;
268:
269: // Create engine bitmap around frame buffer.
270:
271: ppdev = (PPDEV) dhpdev;
272:
273: if (!bInitSURF(ppdev, TRUE))
274: {
275: RIP("DISP DrvEnableSurface failed bInitSURF\n");
276: return(FALSE);
277: }
278:
279: sizl.cx = ppdev->cxScreen;
280: sizl.cy = ppdev->cyScreen;
281:
282: if (ppdev->ulBitCount == 8)
283: {
284: if (!bInit256ColorPalette(ppdev)) {
285: RIP("DISP DrvEnableSurface failed to init the 8bpp palette\n");
286: return(FALSE);
287: }
288: ulBitmapType = BMF_8BPP;
289: flHooks = HOOKS_BMF8BPP;
290: }
291: else if (ppdev->ulBitCount == 16)
292: {
293: ulBitmapType = BMF_16BPP;
294: flHooks = HOOKS_BMF16BPP;
295: }
296: else if (ppdev->ulBitCount == 24)
297: {
298: ulBitmapType = BMF_24BPP;
299: flHooks = HOOKS_BMF24BPP;
300: }
301: else
302: {
303: ulBitmapType = BMF_32BPP;
304: flHooks = HOOKS_BMF32BPP;
305: }
306:
307: hsurf = (HSURF) EngCreateBitmap(sizl,
308: ppdev->lDeltaScreen,
309: ulBitmapType,
310: (ppdev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0,
311: (PVOID) (ppdev->pjScreen));
312:
313: if (hsurf == (HSURF) 0)
314: {
315: RIP("DISP DrvEnableSurface failed EngCreateBitmap\n");
316: return(FALSE);
317: }
318:
319: if (!EngAssociateSurface(hsurf, ppdev->hdevEng, flHooks))
320: {
321: RIP("DISP DrvEnableSurface failed EngAssociateSurface\n");
322: EngDeleteSurface(hsurf);
323: return(FALSE);
324: }
325:
326: ppdev->hsurfEng = hsurf;
327:
328: return(hsurf);
329: }
330:
331: /******************************Public*Routine******************************\
332: * DrvDisableSurface
333: *
334: * Free resources allocated by DrvEnableSurface. Release the surface.
335: *
336: \**************************************************************************/
337:
338: VOID DrvDisableSurface(
339: DHPDEV dhpdev)
340: {
341: EngDeleteSurface(((PPDEV) dhpdev)->hsurfEng);
342: vDisableSURF((PPDEV) dhpdev);
343: ((PPDEV) dhpdev)->hsurfEng = (HSURF) 0;
344: }
345:
346: /******************************Public*Routine******************************\
347: * DrvAssertMode
348: *
349: * This asks the device to reset itself to the mode of the pdev passed in.
350: *
351: \**************************************************************************/
352:
353: VOID DrvAssertMode(
354: DHPDEV dhpdev,
355: BOOL bEnable)
356: {
357: PPDEV ppdev = (PPDEV) dhpdev;
358: ULONG ulReturn;
359:
360: if (bEnable)
361: {
362: // The screen must be reenabled, reinitialize the device to clean state.
363:
364: bInitSURF(ppdev, FALSE);
365: }
366: else
367: {
368: // We must give up the display.
369: // Call the kernel driver to reset the device to a known state.
370:
371: if (!DeviceIoControl(ppdev->hDriver,
372: IOCTL_VIDEO_RESET_DEVICE,
373: NULL,
374: 0,
375: NULL,
376: 0,
377: &ulReturn,
378: NULL))
379: {
380: RIP("DISP DrvAssertMode failed IOCTL");
381: }
382: }
383:
384: return;
385: }
386:
387: /******************************Public*Routine******************************\
388: * DrvGetModes
389: *
390: * Returns the list of available modes for the device.
391: *
392: \**************************************************************************/
393:
394: ULONG DrvGetModes(
395: HANDLE hDriver,
396: ULONG cjSize,
397: DEVMODEW *pdm)
398:
399: {
400:
401: DWORD cModes;
402: DWORD cbOutputSize;
403: PVIDEO_MODE_INFORMATION pVideoModeInformation, pVideoTemp;
404: DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
405: DWORD cbModeSize;
406:
407: DISPDBG((3, "Framebuf.dll:DrvGetModes\n"));
408:
409: cModes = getAvailableModes(hDriver,
410: (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
411: &cbModeSize);
412:
413: if (cModes == 0)
414: {
415: DISPDBG((0, "FRAMEBUF DISP DrvGetModes failed to get mode information"));
416: return 0;
417: }
418:
419: if (pdm == NULL)
420: {
421: cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
422: }
423: else
424: {
425: //
426: // Now copy the information for the supported modes back into the output
427: // buffer
428: //
429:
430: cbOutputSize = 0;
431:
432: pVideoTemp = pVideoModeInformation;
433:
434: do
435: {
436: if (pVideoTemp->Length != 0)
437: {
438: if (cOutputModes == 0)
439: {
440: break;
441: }
442:
443: //
444: // Zero the entire structure to start off with.
445: //
446:
447: memset(pdm, 0, sizeof(DEVMODEW));
448:
449: //
450: // Set the name of the device to the name of the DLL.
451: //
452:
453: memcpy(&(pdm->dmDeviceName), L"framebuf", sizeof(L"framebuf"));
454:
455: pdm->dmSpecVersion = DM_SPECVERSION;
456: pdm->dmDriverVersion = DM_SPECVERSION;
457:
458: //
459: // We currently do not support Extra information in the driver
460: //
461:
462: pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
463:
464: pdm->dmSize = sizeof(DEVMODEW);
465: pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
466: pVideoTemp->BitsPerPlane;
467: pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
468: pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
469: pdm->dmDisplayFrequency = pVideoTemp->Frequency;
470:
471: if (pVideoTemp->AttributeFlags & VIDEO_MODE_INTERLACED)
472: {
473: pdm->dmDisplayFlags |= DM_INTERLACED;
474: }
475:
476: //
477: // Go to the next DEVMODE entry in the buffer.
478: //
479:
480: cOutputModes--;
481:
482: pdm = (LPDEVMODEW) ( ((ULONG)pdm) + sizeof(DEVMODEW) +
483: DRIVER_EXTRA_SIZE);
484:
485: cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
486:
487: }
488:
489: pVideoTemp = (PVIDEO_MODE_INFORMATION)
490: (((PUCHAR)pVideoTemp) + cbModeSize);
491:
492: } while (--cModes);
493: }
494:
495: LocalFree(pVideoModeInformation);
496:
497: return cbOutputSize;
498:
499: }
500:
501: #ifdef DFB_ENABLED
502:
503: /*----------------------------------------------------------------------------
504:
505: Test DFB implementation. Note to get much better performance drawing to
506: bitmaps we should hook DrvBitBlt, DrvPaint and pass back to their Eng
507: counter parts. We don't now to test our simulations better.
508:
509: */
510:
511: ULONG gulCount = 0;
512: BOOL bPrintDelete = FALSE;
513:
514: HBITMAP DrvCreateDeviceBitmap (DHPDEV dhpdev, SIZEL sizl, ULONG iFormat)
515: {
516: HBITMAP hbmEngine;
517: PPDEV pDevice = (PPDEV)dhpdev;
518:
519: hbmEngine = EngCreateBitmap(sizl,0,iFormat,BMF_TOPDOWN,0);
520:
521: if (hbmEngine)
522: {
523: if (EngAssociateSurface((HSURF) hbmEngine, pDevice->hdevEng, 0))
524: {
525: HBITMAP hbmDevice;
526: SURFOBJ *psoTemp;
527:
528: if (psoTemp = EngLockSurface((HSURF) hbmEngine))
529: {
530: hbmDevice = EngCreateDeviceBitmap((DHSURF) psoTemp,sizl,iFormat);
531:
532: if (hbmDevice)
533: {
534: if (EngAssociateSurface((HSURF) hbmDevice,pDevice->hdevEng,
535: HOOK_COPYBITS | HOOK_TEXTOUT | HOOK_STROKEPATH ))
536: {
537: gulCount++;
538: return(hbmDevice);
539: }
540:
541: EngDeleteSurface((HSURF) hbmDevice);
542: }
543:
544: EngUnlockSurface(psoTemp);
545: }
546: }
547:
548: EngDeleteSurface((HSURF) hbmEngine);
549: }
550:
551: return(0);
552: }
553:
554: VOID DrvDeleteDeviceBitmap(DHSURF dhsurf)
555: {
556: HSURF hsurf = (HSURF) ((SURFOBJ *) dhsurf)->hsurf;
557:
558: EngUnlockSurface((SURFOBJ *) dhsurf);
559:
560: if (!EngDeleteSurface(hsurf))
561: DISPDBG((0, "FRAMEBUF failed EngDeleteSurface"));
562:
563: gulCount--;
564:
565: if (bPrintDelete)
566: DISPDBG((0, "DrvDelete %lu", gulCount));
567: }
568:
569: BOOL DrvStrokePath(
570: SURFOBJ *pso,
571: PATHOBJ *ppo,
572: CLIPOBJ *pco,
573: XFORMOBJ *pxo,
574: BRUSHOBJ *pbo,
575: POINTL *pptlBrushOrg,
576: LINEATTRS *plineattrs,
577: MIX mix)
578: {
579: return(EngStrokePath((SURFOBJ *) pso->dhsurf,
580: ppo,
581: pco,
582: pxo,
583: pbo,
584: pptlBrushOrg,
585: plineattrs,
586: mix));
587: }
588:
589: BOOL DrvDFBTextOut(
590: SURFOBJ *pso,
591: STROBJ *pstro,
592: FONTOBJ *pfo,
593: CLIPOBJ *pco,
594: RECTL *prclExtra,
595: RECTL *prclOpaque,
596: BRUSHOBJ *pboFore,
597: BRUSHOBJ *pboOpaque,
598: POINTL *pptlOrg,
599: MIX mix)
600: {
601: if (pso->iType == STYPE_DEVBITMAP)
602: {
603: return(EngTextOut((SURFOBJ *) pso->dhsurf,
604: pstro,
605: pfo,
606: pco,
607: prclExtra,
608: prclOpaque,
609: pboFore,
610: pboOpaque,
611: pptlOrg,
612: mix));
613: }
614: else
615: {
616: #ifdef MIPS
617: return(DrvTextOut(pso,
618: pstro,
619: pfo,
620: pco,
621: prclExtra,
622: prclOpaque,
623: pboFore,
624: pboOpaque,
625: pptlOrg,
626: mix));
627: #else
628: return(EngTextOut(pso,
629: pstro,
630: pfo,
631: pco,
632: prclExtra,
633: prclOpaque,
634: pboFore,
635: pboOpaque,
636: pptlOrg,
637: mix));
638: #endif
639: }
640: }
641:
642: BOOL DrvCopyBits(
643: SURFOBJ *psoTrg,
644: SURFOBJ *psoSrc,
645: CLIPOBJ *pco,
646: XLATEOBJ *pxlo,
647: RECTL *prclTrg,
648: POINTL *pptlSrc)
649: {
650: SURFOBJ *psoT;
651: SURFOBJ *psoS;
652:
653: if (psoTrg->iType == STYPE_DEVBITMAP)
654: psoT = (SURFOBJ *) psoTrg->dhsurf;
655: else
656: psoT = psoTrg;
657:
658: if (psoSrc->iType == STYPE_DEVBITMAP)
659: psoS = (SURFOBJ *) psoSrc->dhsurf;
660: else
661: psoS = psoSrc;
662:
663: return(EngCopyBits(psoT,
664: psoS,
665: pco,
666: pxlo,
667: prclTrg,
668: pptlSrc));
669: }
670:
671: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.