VirtualBox

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

Last change on this file since 19711 was 19711, checked in by vboxsync, 16 years ago

HGSMI: host->guest command processing working

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

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