VirtualBox

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

Last change on this file since 25062 was 25062, checked in by vboxsync, 15 years ago

HGSMI,DevVGA: Use the offset based heap for the hostHeap (resides in VRAM). New staved state version for DevVGA for indicating this change.

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