VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/screen.c@ 34406

Last change on this file since 34406 was 33540, checked in by vboxsync, 14 years ago

*: spelling fixes, thanks Timeless!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.4 KB
Line 
1/******************************Module*Header*******************************\
2*
3 * Copyright (C) 2006-2007 Oracle Corporation
4 *
5 * This file is part of VirtualBox Open Source Edition (OSE), as
6 * available from http://www.virtualbox.org. This file is free software;
7 * you can redistribute it and/or modify it under the terms of the GNU
8 * General Public License (GPL) as published by the Free Software
9 * Foundation, in version 2 as it comes in the "COPYING" file of the
10 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
11 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
12*/
13/*
14* Based in part on Microsoft DDK sample code
15*
16* *******************
17* * GDI SAMPLE CODE *
18* *******************
19*
20* Module Name: screen.c
21*
22* Initializes the GDIINFO and DEVINFO structures for DrvEnablePDEV.
23*
24* Copyright (c) 1992-1998 Microsoft Corporation
25\**************************************************************************/
26
27#include "driver.h"
28
29#include <iprt/asm.h>
30#include <VBox/log.h>
31#include <VBox/HGSMI/HGSMI.h>
32#include <VBox/HGSMI/HGSMIChSetup.h>
33
34#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"}
35#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"}
36#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"}
37
38// This is the basic devinfo for a default driver. This is used as a base and customized based
39// on information passed back from the miniport driver.
40
41const DEVINFO gDevInfoFrameBuffer = {
42 ( GCAPS_OPAQUERECT
43#ifdef VBOX_WITH_DDRAW
44 | GCAPS_DIRECTDRAW
45#endif
46 | GCAPS_MONO_DITHER
47 ), /* Graphics capabilities */
48 SYSTM_LOGFONT, /* Default font description */
49 HELVE_LOGFONT, /* ANSI variable font description */
50 COURI_LOGFONT, /* ANSI fixed font description */
51 0, /* Count of device fonts */
52 0, /* Preferred DIB format */
53 8, /* Width of color dither */
54 8, /* Height of color dither */
55 0 /* Default palette to use for this device */
56};
57
58static void vboxInitVBoxVideo (PPDEV ppdev, const VIDEO_MEMORY_INFORMATION *pMemoryInformation)
59{
60 ULONG cbAvailable = 0;
61
62 DWORD returnedDataLength;
63
64 ULONG iDevice;
65 uint32_t u32DisplayInfoSize;
66 uint32_t u32MinVBVABufferSize;
67
68 QUERYHGSMIRESULT info;
69 RtlZeroMemory(&info, sizeof (info));
70
71 ppdev->bHGSMISupported = !EngDeviceIoControl(ppdev->hDriver,
72 IOCTL_VIDEO_QUERY_HGSMI_INFO,
73 NULL,
74 0,
75 &info,
76 sizeof(info),
77 &returnedDataLength);
78 if (ppdev->bHGSMISupported)
79 {
80 HGSMIQUERYCALLBACKS Callbacks;
81 DWORD err;
82 RtlZeroMemory(&Callbacks, sizeof(Callbacks));
83
84 iDevice = info.iDevice;
85 u32DisplayInfoSize = info.u32DisplayInfoSize;
86 u32MinVBVABufferSize = info.u32MinVBVABufferSize;
87
88 err = EngDeviceIoControl(ppdev->hDriver,
89 IOCTL_VIDEO_HGSMI_QUERY_CALLBACKS,
90 NULL,
91 0,
92 &Callbacks,
93 sizeof(Callbacks),
94 &returnedDataLength);
95 Assert(!err);
96 if(!err)
97 {
98 HGSMIQUERYCPORTPROCS PortProcs;
99 RtlZeroMemory(&PortProcs, sizeof(PortProcs));
100
101 ppdev->hMpHGSMI = Callbacks.hContext;
102 ppdev->pfnHGSMICommandComplete = Callbacks.pfnCompletionHandler;
103 ppdev->pfnHGSMIRequestCommands = Callbacks.pfnRequestCommandsHandler;
104
105 err = EngDeviceIoControl(ppdev->hDriver,
106 IOCTL_VIDEO_HGSMI_QUERY_PORTPROCS,
107 NULL,
108 0,
109 &PortProcs,
110 sizeof(PortProcs),
111 &returnedDataLength);
112 Assert(!err);
113 if(!err)
114 {
115 HGSMIHANDLERENABLE HandlerReg;
116 RtlZeroMemory(&HandlerReg, sizeof(HandlerReg));
117
118 ppdev->pVideoPortContext = PortProcs.pContext;
119 ppdev->VideoPortProcs = PortProcs.VideoPortProcs;
120
121 HandlerReg.u8Channel = HGSMI_CH_VBVA;
122 err = EngDeviceIoControl(ppdev->hDriver,
123 IOCTL_VIDEO_HGSMI_HANDLER_ENABLE,
124 &HandlerReg,
125 sizeof(HandlerReg),
126 NULL,
127 0,
128 &returnedDataLength);
129#ifdef DEBUG_misha
130 Assert(!err);
131#endif
132
133#ifdef VBOX_WITH_VIDEOHWACCEL
134 if (!err)
135 vboxVHWAInit(ppdev);
136#endif
137
138 /* this is not fatal, just means Video 2D acceleration will not be supported */
139 err = 0;
140 }
141 }
142
143 if(err)
144 {
145 ppdev->bHGSMISupported = FALSE;
146 }
147 }
148
149 if (ppdev->bHGSMISupported)
150 {
151 ppdev->iDevice = iDevice;
152
153 ppdev->layout.cbVRAM = pMemoryInformation->VideoRamLength;
154
155 ppdev->layout.offFrameBuffer = 0;
156 ppdev->layout.cbFrameBuffer = RT_ALIGN_32(pMemoryInformation->FrameBufferLength, 0x1000);
157
158 cbAvailable = ppdev->layout.cbVRAM - ppdev->layout.cbFrameBuffer;
159
160 if (cbAvailable <= u32DisplayInfoSize)
161 {
162 ppdev->bHGSMISupported = FALSE;
163 }
164 else
165 {
166 ppdev->layout.offDisplayInformation = ppdev->layout.cbVRAM - u32DisplayInfoSize;
167 ppdev->layout.cbDisplayInformation = u32DisplayInfoSize;
168
169 cbAvailable -= ppdev->layout.cbDisplayInformation;
170
171 /* Use minimum 64K and maximum the cbFrameBuffer for the VBVA buffer. */
172 for (ppdev->layout.cbVBVABuffer = ppdev->layout.cbFrameBuffer;
173 ppdev->layout.cbVBVABuffer >= u32MinVBVABufferSize;
174 ppdev->layout.cbVBVABuffer /= 2)
175 {
176 if (ppdev->layout.cbVBVABuffer < cbAvailable)
177 {
178 break;
179 }
180 }
181
182 if (ppdev->layout.cbVBVABuffer >= cbAvailable)
183 {
184 ppdev->bHGSMISupported = FALSE;
185 }
186 else
187 {
188 /* Now the offscreen heap followed by the VBVA buffer. */
189 ppdev->layout.offDDRAWHeap = ppdev->layout.offFrameBuffer + ppdev->layout.cbFrameBuffer;
190
191 cbAvailable -= ppdev->layout.cbVBVABuffer;
192 ppdev->layout.cbDDRAWHeap = cbAvailable;
193
194 ppdev->layout.offVBVABuffer = ppdev->layout.offDDRAWHeap + ppdev->layout.cbDDRAWHeap;
195 }
196 }
197 }
198
199 if (!ppdev->bHGSMISupported)
200 {
201 ppdev->iDevice = 0;
202
203 /* Setup a layout without both the VBVA buffer and the display information. */
204 ppdev->layout.cbVRAM = pMemoryInformation->VideoRamLength;
205
206 ppdev->layout.offFrameBuffer = 0;
207 ppdev->layout.cbFrameBuffer = RT_ALIGN_32(pMemoryInformation->FrameBufferLength, 0x1000);
208
209 ppdev->layout.offDDRAWHeap = ppdev->layout.offFrameBuffer + ppdev->layout.cbFrameBuffer;
210 ppdev->layout.cbDDRAWHeap = ppdev->layout.cbVRAM - ppdev->layout.offDDRAWHeap;
211
212 ppdev->layout.offVBVABuffer = ppdev->layout.offDDRAWHeap + ppdev->layout.cbDDRAWHeap;
213 ppdev->layout.cbVBVABuffer = 0;
214
215 ppdev->layout.offDisplayInformation = ppdev->layout.offVBVABuffer + ppdev->layout.cbVBVABuffer;
216 ppdev->layout.cbDisplayInformation = 0;
217 }
218 else
219 {
220 /* Setup HGSMI heap in the display information area. The area has some space reserved for
221 * HGSMI event flags in the beginning.
222 */
223 int rc = HGSMIHeapSetup (&ppdev->hgsmiDisplayHeap,
224 (uint8_t *)ppdev->pjScreen + ppdev->layout.offDisplayInformation + sizeof (HGSMIHOSTFLAGS),
225 ppdev->layout.cbDisplayInformation - sizeof (HGSMIHOSTFLAGS),
226 info.areaDisplay.offBase + ppdev->layout.offDisplayInformation + sizeof (HGSMIHOSTFLAGS),
227 false /*fOffsetBased*/);
228
229 DISPDBG((0, "VBoxDISP::vboxInitVBoxVideo: offBase 0x%x\n",
230 info.areaDisplay.offBase));
231
232 if (RT_FAILURE (rc))
233 {
234 DISPDBG((0, "VBoxDISP::vboxInitVBoxVideo: HGSMIHeapSetup failed rc = %d\n",
235 rc));
236
237 ppdev->bHGSMISupported = FALSE;
238 }
239 else
240 {
241 ppdev->IOPortGuestCommand = info.IOPortGuestCommand;
242 }
243 }
244
245 DISPDBG((0, "vboxInitVBoxVideo:\n"
246 " cbVRAM = 0x%X\n"
247 " offFrameBuffer = 0x%X\n"
248 " cbFrameBuffer = 0x%X\n"
249 " offDDRAWHeap = 0x%X\n"
250 " cbDDRAWHeap = 0x%X\n"
251 " offVBVABuffer = 0x%X\n"
252 " cbVBVABuffer = 0x%X\n"
253 " offDisplayInformation = 0x%X\n"
254 " cbDisplayInformation = 0x%X\n",
255 ppdev->layout.cbVRAM,
256 ppdev->layout.offFrameBuffer,
257 ppdev->layout.cbFrameBuffer,
258 ppdev->layout.offDDRAWHeap,
259 ppdev->layout.cbDDRAWHeap,
260 ppdev->layout.offVBVABuffer,
261 ppdev->layout.cbVBVABuffer,
262 ppdev->layout.offDisplayInformation,
263 ppdev->layout.cbDisplayInformation
264 ));
265}
266
267
268
269
270/******************************Public*Routine******************************\
271* bInitSURF
272*
273* Enables the surface. Maps the frame buffer into memory.
274*
275\**************************************************************************/
276
277BOOL bInitSURF(PPDEV ppdev, BOOL bFirst)
278{
279 DWORD returnedDataLength;
280 DWORD MaxWidth, MaxHeight;
281 VIDEO_MEMORY videoMemory;
282 VIDEO_MEMORY_INFORMATION videoMemoryInformation;
283 ULONG RemappingNeeded = 0;
284
285 //
286 // Set the current mode into the hardware.
287 //
288
289 if (EngDeviceIoControl(ppdev->hDriver,
290 IOCTL_VIDEO_SET_CURRENT_MODE,
291 &(ppdev->ulMode),
292 sizeof(ULONG),
293 &RemappingNeeded,
294 sizeof(ULONG),
295 &returnedDataLength))
296 {
297 DISPDBG((1, "DISP bInitSURF failed IOCTL_SET_MODE\n"));
298 return(FALSE);
299 }
300
301 //
302 // If this is the first time we enable the surface we need to map in the
303 // memory also.
304 //
305
306 if (bFirst || RemappingNeeded)
307 {
308 videoMemory.RequestedVirtualAddress = NULL;
309
310 if (EngDeviceIoControl(ppdev->hDriver,
311 IOCTL_VIDEO_MAP_VIDEO_MEMORY,
312 &videoMemory,
313 sizeof(VIDEO_MEMORY),
314 &videoMemoryInformation,
315 sizeof(VIDEO_MEMORY_INFORMATION),
316 &returnedDataLength))
317 {
318 DISPDBG((1, "DISP bInitSURF failed IOCTL_VIDEO_MAP\n"));
319 return(FALSE);
320 }
321
322 ppdev->pjScreen = (PBYTE)(videoMemoryInformation.FrameBufferBase);
323
324 if (videoMemoryInformation.FrameBufferBase !=
325 videoMemoryInformation.VideoRamBase)
326 {
327 DISPDBG((0, "VideoRamBase does not correspond to FrameBufferBase\n"));
328 }
329
330 //
331 // Make sure we can access this video memory
332 //
333
334 *(PULONG)(ppdev->pjScreen) = 0xaa55aa55;
335
336 if (*(PULONG)(ppdev->pjScreen) != 0xaa55aa55) {
337
338 DISPDBG((1, "Frame buffer memory is not accessible.\n"));
339 return(FALSE);
340 }
341
342 /* Clear VRAM to avoid distortions during the video mode change. */
343 RtlZeroMemory(ppdev->pjScreen,
344 ppdev->cyScreen * (ppdev->lDeltaScreen > 0? ppdev->lDeltaScreen: -ppdev->lDeltaScreen));
345
346 //
347 // Initialize the head of the offscreen list to NULL.
348 //
349
350 ppdev->pOffscreenList = NULL;
351
352 // It's a hardware pointer; set up pointer attributes.
353
354 MaxHeight = ppdev->PointerCapabilities.MaxHeight;
355
356 // Allocate space for two DIBs (data/mask) for the pointer. If this
357 // device supports a color Pointer, we will allocate a larger bitmap.
358 // If this is a color bitmap we allocate for the largest possible
359 // bitmap because we have no idea of what the pixel depth might be.
360
361 // Width rounded up to nearest byte multiple
362
363 if (!(ppdev->PointerCapabilities.Flags & VIDEO_MODE_COLOR_POINTER))
364 {
365 MaxWidth = (ppdev->PointerCapabilities.MaxWidth + 7) / 8;
366 }
367 else
368 {
369 MaxWidth = ppdev->PointerCapabilities.MaxWidth * sizeof(DWORD);
370 }
371
372 ppdev->cjPointerAttributes =
373 sizeof(VIDEO_POINTER_ATTRIBUTES) +
374 ((sizeof(UCHAR) * MaxWidth * MaxHeight) * 2);
375
376 ppdev->pPointerAttributes = (PVIDEO_POINTER_ATTRIBUTES)
377 EngAllocMem(0, ppdev->cjPointerAttributes, ALLOC_TAG);
378
379 if (ppdev->pPointerAttributes == NULL) {
380
381 DISPDBG((0, "bInitPointer EngAllocMem failed\n"));
382 return(FALSE);
383 }
384
385 ppdev->pPointerAttributes->Flags = ppdev->PointerCapabilities.Flags;
386 ppdev->pPointerAttributes->WidthInBytes = MaxWidth;
387 ppdev->pPointerAttributes->Width = ppdev->PointerCapabilities.MaxWidth;
388 ppdev->pPointerAttributes->Height = MaxHeight;
389 ppdev->pPointerAttributes->Column = 0;
390 ppdev->pPointerAttributes->Row = 0;
391 ppdev->pPointerAttributes->Enable = 0;
392
393 vboxInitVBoxVideo (ppdev, &videoMemoryInformation);
394
395 }
396
397
398 DISPDBG((1, "DISP bInitSURF: ppdev->ulBitCount %d\n", ppdev->ulBitCount));
399
400 if ( ppdev->ulBitCount == 16
401 || ppdev->ulBitCount == 24
402 || ppdev->ulBitCount == 32)
403 {
404 if (ppdev->bHGSMISupported)
405 {
406 /* Enable VBVA for this video mode. */
407 ppdev->bHGSMISupported = vboxVbvaEnable (ppdev);
408 LogRel(("VBoxDisp[%d]: VBVA %senabled\n", ppdev->iDevice, ppdev->bHGSMISupported? "": "not "));
409 }
410 }
411
412 DISPDBG((1, "DISP bInitSURF success\n"));
413
414 /* Inform the host about this screen layout. */
415 DISPDBG((1, "bInitSURF: %d,%d\n", ppdev->ptlDevOrg.x, ppdev->ptlDevOrg.y));
416 VBoxProcessDisplayInfo (ppdev);
417
418#ifdef VBOX_WITH_VIDEOHWACCEL
419 /* tells we can process host commands */
420 vboxVHWAEnable(ppdev);
421#endif
422
423 return(TRUE);
424}
425
426/******************************Public*Routine******************************\
427* vDisableSURF
428*
429* Disable the surface. Un-Maps the frame in memory.
430*
431\**************************************************************************/
432
433VOID vDisableSURF(PPDEV ppdev)
434{
435 DWORD returnedDataLength;
436 VIDEO_MEMORY videoMemory;
437
438 videoMemory.RequestedVirtualAddress = (PVOID) ppdev->pjScreen;
439
440 if (EngDeviceIoControl(ppdev->hDriver,
441 IOCTL_VIDEO_UNMAP_VIDEO_MEMORY,
442 &videoMemory,
443 sizeof(VIDEO_MEMORY),
444 NULL,
445 0,
446 &returnedDataLength))
447 {
448 DISPDBG((0, "DISP vDisableSURF failed IOCTL_VIDEO_UNMAP\n"));
449 }
450}
451
452
453/******************************Public*Routine******************************\
454* bInitPDEV
455*
456* Determine the mode we should be in based on the DEVMODE passed in.
457* Query mini-port to get information needed to fill in the DevInfo and the
458* GdiInfo .
459*
460\**************************************************************************/
461
462BOOL bInitPDEV(
463PPDEV ppdev,
464DEVMODEW *pDevMode,
465GDIINFO *pGdiInfo,
466DEVINFO *pDevInfo)
467{
468 ULONG cModes;
469 PVIDEO_MODE_INFORMATION pVideoBuffer, pVideoModeSelected, pVideoTemp;
470 VIDEO_COLOR_CAPABILITIES colorCapabilities;
471 ULONG ulTemp;
472 BOOL bSelectDefault;
473 ULONG cbModeSize;
474
475 //
476 // calls the miniport to get mode information.
477 //
478
479 cModes = getAvailableModes(ppdev->hDriver, &pVideoBuffer, &cbModeSize);
480
481 if (cModes == 0)
482 {
483 return(FALSE);
484 }
485
486 //
487 // Now see if the requested mode has a match in that table.
488 //
489
490 pVideoModeSelected = NULL;
491 pVideoTemp = pVideoBuffer;
492
493 if ((pDevMode->dmPelsWidth == 0) &&
494 (pDevMode->dmPelsHeight == 0) &&
495 (pDevMode->dmBitsPerPel == 0) &&
496 (pDevMode->dmDisplayFrequency == 0))
497 {
498 DISPDBG((2, "Default mode requested"));
499 bSelectDefault = TRUE;
500 }
501 else
502 {
503 DISPDBG((2, "Requested mode...\n"));
504 DISPDBG((2, " Screen width -- %li\n", pDevMode->dmPelsWidth));
505 DISPDBG((2, " Screen height -- %li\n", pDevMode->dmPelsHeight));
506 DISPDBG((2, " Bits per pel -- %li\n", pDevMode->dmBitsPerPel));
507 DISPDBG((2, " Frequency -- %li\n", pDevMode->dmDisplayFrequency));
508
509 bSelectDefault = FALSE;
510 }
511
512 while (cModes--)
513 {
514 if (pVideoTemp->Length != 0)
515 {
516 if (bSelectDefault ||
517 ((pVideoTemp->VisScreenWidth == pDevMode->dmPelsWidth) &&
518 (pVideoTemp->VisScreenHeight == pDevMode->dmPelsHeight) &&
519 (pVideoTemp->BitsPerPlane *
520 pVideoTemp->NumberOfPlanes == pDevMode->dmBitsPerPel) &&
521 (pVideoTemp->Frequency == pDevMode->dmDisplayFrequency)))
522 {
523 pVideoModeSelected = pVideoTemp;
524 DISPDBG((3, "Found a match\n")) ;
525 break;
526 }
527 }
528
529 pVideoTemp = (PVIDEO_MODE_INFORMATION)
530 (((PUCHAR)pVideoTemp) + cbModeSize);
531 }
532
533 //
534 // If no mode has been found, return an error
535 //
536
537 if (pVideoModeSelected == NULL)
538 {
539 EngFreeMem(pVideoBuffer);
540 DISPDBG((0,"DISP bInitPDEV failed - no valid modes\n"));
541 return(FALSE);
542 }
543
544 //
545 // Fill in the GDIINFO data structure with the information returned from
546 // the kernel driver.
547 //
548
549 ppdev->ulMode = pVideoModeSelected->ModeIndex;
550 ppdev->cxScreen = pVideoModeSelected->VisScreenWidth;
551 ppdev->cyScreen = pVideoModeSelected->VisScreenHeight;
552 ppdev->ulBitCount = pVideoModeSelected->BitsPerPlane *
553 pVideoModeSelected->NumberOfPlanes;
554 ppdev->lDeltaScreen = pVideoModeSelected->ScreenStride;
555
556 ppdev->flRed = pVideoModeSelected->RedMask;
557 ppdev->flGreen = pVideoModeSelected->GreenMask;
558 ppdev->flBlue = pVideoModeSelected->BlueMask;
559
560
561 if (g_bOnNT40)
562 {
563 DISPDBG((0,"DISP bInitPDEV pGdiInfo->ulVersion = %x\n", GDI_DRIVER_VERSION));
564 pGdiInfo->ulVersion = GDI_DRIVER_VERSION; /* 0x4000 -> NT4 */
565 }
566 else
567 {
568 DISPDBG((0,"DISP bInitPDEV pGdiInfo->ulVersion = %x\n", 0x5000));
569 pGdiInfo->ulVersion = 0x5000;
570 }
571
572 pGdiInfo->ulTechnology = DT_RASDISPLAY;
573 pGdiInfo->ulHorzSize = pVideoModeSelected->XMillimeter;
574 pGdiInfo->ulVertSize = pVideoModeSelected->YMillimeter;
575
576 pGdiInfo->ulHorzRes = ppdev->cxScreen;
577 pGdiInfo->ulVertRes = ppdev->cyScreen;
578 pGdiInfo->ulPanningHorzRes = ppdev->cxScreen;
579 pGdiInfo->ulPanningVertRes = ppdev->cyScreen;
580 pGdiInfo->cBitsPixel = pVideoModeSelected->BitsPerPlane;
581 pGdiInfo->cPlanes = pVideoModeSelected->NumberOfPlanes;
582 pGdiInfo->ulVRefresh = pVideoModeSelected->Frequency;
583 /* bit block transfers are accelerated */
584 pGdiInfo->ulBltAlignment = 0;
585
586 pGdiInfo->ulLogPixelsX = pDevMode->dmLogPixels;
587 pGdiInfo->ulLogPixelsY = pDevMode->dmLogPixels;
588
589#ifdef MIPS
590 if (ppdev->ulBitCount == 8)
591 pGdiInfo->flTextCaps = (TC_RA_ABLE | TC_SCROLLBLT);
592 else
593#endif
594 pGdiInfo->flTextCaps = TC_RA_ABLE;
595
596 pGdiInfo->flRaster = 0; // flRaster is reserved by DDI
597
598 pGdiInfo->ulDACRed = pVideoModeSelected->NumberRedBits;
599 pGdiInfo->ulDACGreen = pVideoModeSelected->NumberGreenBits;
600 pGdiInfo->ulDACBlue = pVideoModeSelected->NumberBlueBits;
601
602 pGdiInfo->ulAspectX = 0x24; // One-to-one aspect ratio
603 pGdiInfo->ulAspectY = 0x24;
604 pGdiInfo->ulAspectXY = 0x33;
605
606 pGdiInfo->xStyleStep = 1; // A style unit is 3 pels
607 pGdiInfo->yStyleStep = 1;
608 pGdiInfo->denStyleStep = 3;
609
610 pGdiInfo->ptlPhysOffset.x = 0;
611 pGdiInfo->ptlPhysOffset.y = 0;
612 pGdiInfo->szlPhysSize.cx = 0;
613 pGdiInfo->szlPhysSize.cy = 0;
614
615 // RGB and CMY color info.
616
617 //
618 // try to get it from the miniport.
619 // if the miniport doesn't support this feature, use defaults.
620 //
621
622 if (EngDeviceIoControl(ppdev->hDriver,
623 IOCTL_VIDEO_QUERY_COLOR_CAPABILITIES,
624 NULL,
625 0,
626 &colorCapabilities,
627 sizeof(VIDEO_COLOR_CAPABILITIES),
628 &ulTemp))
629 {
630
631 DISPDBG((2, "getcolorCapabilities failed \n"));
632
633 pGdiInfo->ciDevice.Red.x = 6700;
634 pGdiInfo->ciDevice.Red.y = 3300;
635 pGdiInfo->ciDevice.Red.Y = 0;
636 pGdiInfo->ciDevice.Green.x = 2100;
637 pGdiInfo->ciDevice.Green.y = 7100;
638 pGdiInfo->ciDevice.Green.Y = 0;
639 pGdiInfo->ciDevice.Blue.x = 1400;
640 pGdiInfo->ciDevice.Blue.y = 800;
641 pGdiInfo->ciDevice.Blue.Y = 0;
642 pGdiInfo->ciDevice.AlignmentWhite.x = 3127;
643 pGdiInfo->ciDevice.AlignmentWhite.y = 3290;
644 pGdiInfo->ciDevice.AlignmentWhite.Y = 0;
645
646 pGdiInfo->ciDevice.RedGamma = 20000;
647 pGdiInfo->ciDevice.GreenGamma = 20000;
648 pGdiInfo->ciDevice.BlueGamma = 20000;
649
650 }
651 else
652 {
653 pGdiInfo->ciDevice.Red.x = colorCapabilities.RedChromaticity_x;
654 pGdiInfo->ciDevice.Red.y = colorCapabilities.RedChromaticity_y;
655 pGdiInfo->ciDevice.Red.Y = 0;
656 pGdiInfo->ciDevice.Green.x = colorCapabilities.GreenChromaticity_x;
657 pGdiInfo->ciDevice.Green.y = colorCapabilities.GreenChromaticity_y;
658 pGdiInfo->ciDevice.Green.Y = 0;
659 pGdiInfo->ciDevice.Blue.x = colorCapabilities.BlueChromaticity_x;
660 pGdiInfo->ciDevice.Blue.y = colorCapabilities.BlueChromaticity_y;
661 pGdiInfo->ciDevice.Blue.Y = 0;
662 pGdiInfo->ciDevice.AlignmentWhite.x = colorCapabilities.WhiteChromaticity_x;
663 pGdiInfo->ciDevice.AlignmentWhite.y = colorCapabilities.WhiteChromaticity_y;
664 pGdiInfo->ciDevice.AlignmentWhite.Y = colorCapabilities.WhiteChromaticity_Y;
665
666 // if we have a color device store the three color gamma values,
667 // otherwise store the unique gamma value in all three.
668
669 if (colorCapabilities.AttributeFlags & VIDEO_DEVICE_COLOR)
670 {
671 pGdiInfo->ciDevice.RedGamma = colorCapabilities.RedGamma;
672 pGdiInfo->ciDevice.GreenGamma = colorCapabilities.GreenGamma;
673 pGdiInfo->ciDevice.BlueGamma = colorCapabilities.BlueGamma;
674 }
675 else
676 {
677 pGdiInfo->ciDevice.RedGamma = colorCapabilities.WhiteGamma;
678 pGdiInfo->ciDevice.GreenGamma = colorCapabilities.WhiteGamma;
679 pGdiInfo->ciDevice.BlueGamma = colorCapabilities.WhiteGamma;
680 }
681
682 };
683
684 pGdiInfo->ciDevice.Cyan.x = 0;
685 pGdiInfo->ciDevice.Cyan.y = 0;
686 pGdiInfo->ciDevice.Cyan.Y = 0;
687 pGdiInfo->ciDevice.Magenta.x = 0;
688 pGdiInfo->ciDevice.Magenta.y = 0;
689 pGdiInfo->ciDevice.Magenta.Y = 0;
690 pGdiInfo->ciDevice.Yellow.x = 0;
691 pGdiInfo->ciDevice.Yellow.y = 0;
692 pGdiInfo->ciDevice.Yellow.Y = 0;
693
694 // No dye correction for raster displays.
695
696 pGdiInfo->ciDevice.MagentaInCyanDye = 0;
697 pGdiInfo->ciDevice.YellowInCyanDye = 0;
698 pGdiInfo->ciDevice.CyanInMagentaDye = 0;
699 pGdiInfo->ciDevice.YellowInMagentaDye = 0;
700 pGdiInfo->ciDevice.CyanInYellowDye = 0;
701 pGdiInfo->ciDevice.MagentaInYellowDye = 0;
702
703 pGdiInfo->ulDevicePelsDPI = 0; // For printers only
704 pGdiInfo->ulPrimaryOrder = PRIMARY_ORDER_CBA;
705
706 // Note: this should be modified later to take into account the size
707 // of the display and the resolution.
708
709 pGdiInfo->ulHTPatternSize = HT_PATSIZE_4x4_M;
710
711 pGdiInfo->flHTFlags = HT_FLAG_ADDITIVE_PRIMS;
712
713 // Fill in the basic devinfo structure
714
715 *pDevInfo = gDevInfoFrameBuffer;
716
717 // Fill in the rest of the devinfo and GdiInfo structures.
718
719 if (ppdev->ulBitCount == 8)
720 {
721 // It is Palette Managed.
722
723 pGdiInfo->ulNumColors = 20;
724 pGdiInfo->ulNumPalReg = 1 << ppdev->ulBitCount;
725
726 pDevInfo->flGraphicsCaps |= (GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
727
728 pGdiInfo->ulHTOutputFormat = HT_FORMAT_8BPP;
729 pDevInfo->iDitherFormat = BMF_8BPP;
730
731 // Assuming palette is orthogonal - all colors are same size.
732
733 ppdev->cPaletteShift = 8 - pGdiInfo->ulDACRed;
734 }
735 else
736 {
737 pGdiInfo->ulNumColors = (ULONG) (-1);
738 pGdiInfo->ulNumPalReg = 0;
739
740 if (ppdev->ulBitCount == 16)
741 {
742 pGdiInfo->ulHTOutputFormat = HT_FORMAT_16BPP;
743 pDevInfo->iDitherFormat = BMF_16BPP;
744 }
745 else if (ppdev->ulBitCount == 24)
746 {
747 pGdiInfo->ulHTOutputFormat = HT_FORMAT_24BPP;
748 pDevInfo->iDitherFormat = BMF_24BPP;
749 }
750 else
751 {
752 pGdiInfo->ulHTOutputFormat = HT_FORMAT_32BPP;
753 pDevInfo->iDitherFormat = BMF_32BPP;
754 }
755 }
756
757 EngFreeMem(pVideoBuffer);
758
759 return(TRUE);
760}
761
762
763/******************************Public*Routine******************************\
764* getAvailableModes
765*
766* Calls the miniport to get the list of modes supported by the kernel driver,
767* and returns the list of modes supported by the display driver among those
768*
769* returns the number of entries in the videomode buffer.
770* 0 means no modes are supported by the miniport or that an error occurred.
771*
772* NOTE: the buffer must be freed up by the caller.
773*
774\**************************************************************************/
775
776DWORD getAvailableModes(
777HANDLE hDriver,
778PVIDEO_MODE_INFORMATION *modeInformation,
779DWORD *cbModeSize)
780{
781 ULONG ulTemp;
782 VIDEO_NUM_MODES modes;
783 PVIDEO_MODE_INFORMATION pVideoTemp;
784
785 //
786 // Get the number of modes supported by the mini-port
787 //
788
789 if (EngDeviceIoControl(hDriver,
790 IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES,
791 NULL,
792 0,
793 &modes,
794 sizeof(VIDEO_NUM_MODES),
795 &ulTemp))
796 {
797 DISPDBG((0, "getAvailableModes failed VIDEO_QUERY_NUM_AVAIL_MODES\n"));
798 return(0);
799 }
800
801 *cbModeSize = modes.ModeInformationLength;
802
803 //
804 // Allocate the buffer for the mini-port to write the modes in.
805 //
806
807 *modeInformation = (PVIDEO_MODE_INFORMATION)
808 EngAllocMem(0, modes.NumModes *
809 modes.ModeInformationLength, ALLOC_TAG);
810
811 if (*modeInformation == (PVIDEO_MODE_INFORMATION) NULL)
812 {
813 DISPDBG((0, "getAvailableModes failed EngAllocMem\n"));
814
815 return 0;
816 }
817
818 //
819 // Ask the mini-port to fill in the available modes.
820 //
821
822 if (EngDeviceIoControl(hDriver,
823 IOCTL_VIDEO_QUERY_AVAIL_MODES,
824 NULL,
825 0,
826 *modeInformation,
827 modes.NumModes * modes.ModeInformationLength,
828 &ulTemp))
829 {
830
831 DISPDBG((0, "getAvailableModes failed VIDEO_QUERY_AVAIL_MODES\n"));
832
833 EngFreeMem(*modeInformation);
834 *modeInformation = (PVIDEO_MODE_INFORMATION) NULL;
835
836 return(0);
837 }
838
839 //
840 // Now see which of these modes are supported by the display driver.
841 // As an internal mechanism, set the length to 0 for the modes we
842 // DO NOT support.
843 //
844
845 ulTemp = modes.NumModes;
846 pVideoTemp = *modeInformation;
847
848 //
849 // Mode is rejected if it is not one plane, or not graphics, or is not
850 // one of 8, 16 or 32 bits per pel.
851 //
852
853 while (ulTemp--)
854 {
855 if ((pVideoTemp->NumberOfPlanes != 1 ) ||
856 !(pVideoTemp->AttributeFlags & VIDEO_MODE_GRAPHICS) ||
857 (pVideoTemp->AttributeFlags & VIDEO_MODE_BANKED) ||
858 ((pVideoTemp->BitsPerPlane != 8) &&
859 (pVideoTemp->BitsPerPlane != 16) &&
860 (pVideoTemp->BitsPerPlane != 24) &&
861 (pVideoTemp->BitsPerPlane != 32)))
862 {
863 pVideoTemp->Length = 0;
864 }
865
866 pVideoTemp = (PVIDEO_MODE_INFORMATION)
867 (((PUCHAR)pVideoTemp) + modes.ModeInformationLength);
868 }
869
870 return modes.NumModes;
871
872}
873
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette