1 | /* $Id: VBoxMPVidModes.cpp 38112 2011-07-22 13:26:19Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox Miniport video modes related functions
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2011 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "VBoxMPCommon.h"
|
---|
20 |
|
---|
21 | #if _MSC_VER >= 1400 /* bird: MS fixed swprintf to be standard-conforming... */
|
---|
22 | #define _INC_SWPRINTF_INL_
|
---|
23 | extern "C" int __cdecl swprintf(wchar_t *, const wchar_t *, ...);
|
---|
24 | #endif
|
---|
25 | #include <wchar.h>
|
---|
26 |
|
---|
27 | #ifdef VBOX_WITH_WDDM
|
---|
28 | # define VBOX_WITHOUT_24BPP_MODES
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | /* Custom video modes which are being read from registry at driver startup. */
|
---|
32 | static VIDEO_MODE_INFORMATION g_CustomVideoModes[64] = { 0 };
|
---|
33 |
|
---|
34 | /* Standart video modes list.
|
---|
35 | * Additional space is reserved for custom video modes for 64 guest monitors.
|
---|
36 | * The custom video mode index is alternating and 2 indexes are reserved for the last custom mode.
|
---|
37 | */
|
---|
38 | static VIDEO_MODE_INFORMATION g_VideoModes[VBOXMP_MAX_VIDEO_MODES + 64 + 2] = { 0 };
|
---|
39 |
|
---|
40 | /* Number of available video modes, set by VBoxMPCmnBuildVideoModesTable. */
|
---|
41 | static uint32_t g_NumVideoModes = 0;
|
---|
42 |
|
---|
43 | static BOOLEAN
|
---|
44 | VBoxMPValidateVideoModeParamsGuest(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, uint32_t xres, uint32_t yres, uint32_t bpp)
|
---|
45 | {
|
---|
46 | switch (bpp)
|
---|
47 | {
|
---|
48 | case 32:
|
---|
49 | break;
|
---|
50 | case 24:
|
---|
51 | #ifdef VBOX_WITHOUT_24BPP_MODES
|
---|
52 | return FALSE;
|
---|
53 | #else
|
---|
54 | break;
|
---|
55 | #endif
|
---|
56 | case 16:
|
---|
57 | break;
|
---|
58 | case 8:
|
---|
59 | #ifndef VBOX_WITH_8BPP_MODES
|
---|
60 | return FALSE;
|
---|
61 | #else
|
---|
62 | break;
|
---|
63 | #endif
|
---|
64 | default:
|
---|
65 | WARN(("Unexpected bpp (%d)", bpp));
|
---|
66 | return FALSE;
|
---|
67 | }
|
---|
68 | return TRUE;
|
---|
69 | }
|
---|
70 |
|
---|
71 | /* Fills given video mode BPP related fields */
|
---|
72 | static void
|
---|
73 | VBoxFillVidModeBPP(VIDEO_MODE_INFORMATION *pMode, ULONG bitsR, ULONG bitsG, ULONG bitsB,
|
---|
74 | ULONG maskR, ULONG maskG, ULONG maskB)
|
---|
75 | {
|
---|
76 | pMode->NumberRedBits = bitsR;
|
---|
77 | pMode->NumberGreenBits = bitsG;
|
---|
78 | pMode->NumberBlueBits = bitsB;
|
---|
79 | pMode->RedMask = maskR;
|
---|
80 | pMode->GreenMask = maskG;
|
---|
81 | pMode->BlueMask = maskB;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /* Fills given video mode structure */
|
---|
85 | static void
|
---|
86 | VBoxFillVidModeInfo(VIDEO_MODE_INFORMATION *pMode, ULONG xres, ULONG yres, ULONG bpp, ULONG index, ULONG yoffset)
|
---|
87 | {
|
---|
88 | LOGF(("%dx%d:%d (idx=%d, yoffset=%d)", xres, yres, bpp, index, yoffset));
|
---|
89 |
|
---|
90 | memset(pMode, 0, sizeof(VIDEO_MODE_INFORMATION));
|
---|
91 |
|
---|
92 | /*Common entries*/
|
---|
93 | pMode->Length = sizeof(VIDEO_MODE_INFORMATION);
|
---|
94 | pMode->ModeIndex = index;
|
---|
95 | pMode->VisScreenWidth = xres;
|
---|
96 | pMode->VisScreenHeight = yres - yoffset;
|
---|
97 | pMode->ScreenStride = xres * ((bpp + 7) / 8);
|
---|
98 | pMode->NumberOfPlanes = 1;
|
---|
99 | pMode->BitsPerPlane = bpp;
|
---|
100 | pMode->Frequency = 60;
|
---|
101 | pMode->XMillimeter = 320;
|
---|
102 | pMode->YMillimeter = 240;
|
---|
103 | pMode->VideoMemoryBitmapWidth = xres;
|
---|
104 | pMode->VideoMemoryBitmapHeight = yres - yoffset;
|
---|
105 | pMode->DriverSpecificAttributeFlags = 0;
|
---|
106 | pMode->AttributeFlags = VIDEO_MODE_GRAPHICS | VIDEO_MODE_COLOR | VIDEO_MODE_NO_OFF_SCREEN;
|
---|
107 |
|
---|
108 | /*BPP related entries*/
|
---|
109 | switch (bpp)
|
---|
110 | {
|
---|
111 | #ifdef VBOX_WITH_8BPP_MODES
|
---|
112 | case 8:
|
---|
113 | VBoxFillVidModeBPP(pMode, 6, 6, 6, 0, 0, 0);
|
---|
114 |
|
---|
115 | pMode->AttributeFlags |= VIDEO_MODE_PALETTE_DRIVEN | VIDEO_MODE_MANAGED_PALETTE;
|
---|
116 | break;
|
---|
117 | #endif
|
---|
118 | case 16:
|
---|
119 | VBoxFillVidModeBPP(pMode, 5, 6, 5, 0xF800, 0x7E0, 0x1F);
|
---|
120 | break;
|
---|
121 | case 24:
|
---|
122 | case 32:
|
---|
123 | VBoxFillVidModeBPP(pMode, 8, 8, 8, 0xFF0000, 0xFF00, 0xFF);
|
---|
124 | break;
|
---|
125 | default:
|
---|
126 | Assert(0);
|
---|
127 | break;
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | void VBoxMPCmnInitCustomVideoModes(PVBOXMP_DEVEXT pExt)
|
---|
132 | {
|
---|
133 | VBOXMPCMNREGISTRY Registry;
|
---|
134 | VP_STATUS rc;
|
---|
135 | int iMode;
|
---|
136 |
|
---|
137 | LOGF_ENTER();
|
---|
138 |
|
---|
139 | rc = VBoxMPCmnRegInit(pExt, &Registry);
|
---|
140 | VBOXMP_WARN_VPS(rc);
|
---|
141 |
|
---|
142 | /* Initialize all custom modes to the 800x600x32 */
|
---|
143 | VBoxFillVidModeInfo(&g_CustomVideoModes[0], 800, 600, 32, 0, 0);
|
---|
144 | for (iMode=1; iMode<RT_ELEMENTS(g_CustomVideoModes); ++iMode)
|
---|
145 | {
|
---|
146 | g_CustomVideoModes[iMode] = g_CustomVideoModes[0];
|
---|
147 | }
|
---|
148 |
|
---|
149 | /* Read stored custom resolution info from registry */
|
---|
150 | for (iMode=0; iMode<VBoxCommonFromDeviceExt(pExt)->cDisplays; ++iMode)
|
---|
151 | {
|
---|
152 | uint32_t CustomXRes = 0, CustomYRes = 0, CustomBPP = 0;
|
---|
153 |
|
---|
154 | if (iMode==0)
|
---|
155 | {
|
---|
156 | /*First name without a suffix*/
|
---|
157 | rc = VBoxMPCmnRegQueryDword(Registry, L"CustomXRes", &CustomXRes);
|
---|
158 | VBOXMP_WARN_VPS_NOBP(rc);
|
---|
159 | rc = VBoxMPCmnRegQueryDword(Registry, L"CustomYRes", &CustomYRes);
|
---|
160 | VBOXMP_WARN_VPS_NOBP(rc);
|
---|
161 | rc = VBoxMPCmnRegQueryDword(Registry, L"CustomBPP", &CustomBPP);
|
---|
162 | VBOXMP_WARN_VPS_NOBP(rc);
|
---|
163 | }
|
---|
164 | else
|
---|
165 | {
|
---|
166 | wchar_t keyname[32];
|
---|
167 | swprintf(keyname, L"CustomXRes%d", iMode);
|
---|
168 | rc = VBoxMPCmnRegQueryDword(Registry, keyname, &CustomXRes);
|
---|
169 | VBOXMP_WARN_VPS_NOBP(rc);
|
---|
170 | swprintf(keyname, L"CustomYRes%d", iMode);
|
---|
171 | rc = VBoxMPCmnRegQueryDword(Registry, keyname, &CustomYRes);
|
---|
172 | VBOXMP_WARN_VPS_NOBP(rc);
|
---|
173 | swprintf(keyname, L"CustomBPP%d", iMode);
|
---|
174 | rc = VBoxMPCmnRegQueryDword(Registry, keyname, &CustomBPP);
|
---|
175 | VBOXMP_WARN_VPS_NOBP(rc);
|
---|
176 | }
|
---|
177 |
|
---|
178 | LOG(("got stored custom resolution[%d] %dx%dx%d", iMode, CustomXRes, CustomYRes, CustomBPP));
|
---|
179 |
|
---|
180 | if (CustomXRes || CustomYRes || CustomBPP)
|
---|
181 | {
|
---|
182 | if (CustomXRes == 0)
|
---|
183 | {
|
---|
184 | CustomXRes = g_CustomVideoModes[iMode].VisScreenWidth;
|
---|
185 | }
|
---|
186 | if (CustomYRes == 0)
|
---|
187 | {
|
---|
188 | CustomYRes = g_CustomVideoModes[iMode].VisScreenHeight;
|
---|
189 | }
|
---|
190 | if (CustomBPP == 0)
|
---|
191 | {
|
---|
192 | CustomBPP = g_CustomVideoModes[iMode].BitsPerPlane;
|
---|
193 | }
|
---|
194 |
|
---|
195 | if (VBoxMPValidateVideoModeParamsGuest(pExt, iMode, CustomXRes, CustomYRes, CustomBPP))
|
---|
196 | {
|
---|
197 | VBoxFillVidModeInfo(&g_CustomVideoModes[iMode], CustomXRes, CustomYRes, CustomBPP, 0, 0);
|
---|
198 | }
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | rc = VBoxMPCmnRegFini(Registry);
|
---|
203 | VBOXMP_WARN_VPS(rc);
|
---|
204 | LOGF_LEAVE();
|
---|
205 | }
|
---|
206 |
|
---|
207 | VIDEO_MODE_INFORMATION *VBoxMPCmnGetCustomVideoModeInfo(ULONG ulIndex)
|
---|
208 | {
|
---|
209 | return (ulIndex<RT_ELEMENTS(g_CustomVideoModes)) ? &g_CustomVideoModes[ulIndex] : NULL;
|
---|
210 | }
|
---|
211 |
|
---|
212 | VIDEO_MODE_INFORMATION* VBoxMPCmnGetVideoModeInfo(ULONG ulIndex)
|
---|
213 | {
|
---|
214 | return (ulIndex<RT_ELEMENTS(g_VideoModes)) ? &g_VideoModes[ulIndex] : NULL;
|
---|
215 | }
|
---|
216 |
|
---|
217 | static bool VBoxMPVideoModesMatch(const PVIDEO_MODE_INFORMATION pMode1, const PVIDEO_MODE_INFORMATION pMode2)
|
---|
218 | {
|
---|
219 | return pMode1->VisScreenHeight == pMode2->VisScreenHeight
|
---|
220 | && pMode1->VisScreenWidth == pMode2->VisScreenWidth
|
---|
221 | && pMode1->BitsPerPlane == pMode2->BitsPerPlane;
|
---|
222 | }
|
---|
223 |
|
---|
224 | static int
|
---|
225 | VBoxMPFindVideoMode(const PVIDEO_MODE_INFORMATION pModesTable, int cModes, const PVIDEO_MODE_INFORMATION pMode)
|
---|
226 | {
|
---|
227 | for (int i = 0; i < cModes; ++i)
|
---|
228 | {
|
---|
229 | if (VBoxMPVideoModesMatch(pMode, &pModesTable[i]))
|
---|
230 | {
|
---|
231 | return i;
|
---|
232 | }
|
---|
233 | }
|
---|
234 | return -1;
|
---|
235 | }
|
---|
236 |
|
---|
237 | /* Helper function to dynamically build our table of standard video
|
---|
238 | * modes. We take the amount of VRAM and create modes with standard
|
---|
239 | * geometries until we've either reached the maximum number of modes
|
---|
240 | * or the available VRAM does not allow for additional modes.
|
---|
241 | * We also check registry for manually added video modes.
|
---|
242 | * Returns number of modes added to the table.
|
---|
243 | */
|
---|
244 | static uint32_t
|
---|
245 | VBoxMPFillModesTable(PVBOXMP_DEVEXT pExt, int iDisplay, PVIDEO_MODE_INFORMATION pModesTable, size_t tableSize,
|
---|
246 | int32_t *pPrefModeIdx)
|
---|
247 | {
|
---|
248 | /* the resolution matrix */
|
---|
249 | struct
|
---|
250 | {
|
---|
251 | uint16_t xRes;
|
---|
252 | uint16_t yRes;
|
---|
253 | } resolutionMatrix[] =
|
---|
254 | {
|
---|
255 | /* standard modes */
|
---|
256 | { 640, 480 },
|
---|
257 | { 800, 600 },
|
---|
258 | { 1024, 768 },
|
---|
259 | { 1152, 864 },
|
---|
260 | { 1280, 960 },
|
---|
261 | { 1280, 1024 },
|
---|
262 | { 1400, 1050 },
|
---|
263 | { 1600, 1200 },
|
---|
264 | { 1920, 1440 },
|
---|
265 | #ifndef VBOX_WITH_WDDM
|
---|
266 | /* multi screen modes with 1280x1024 */
|
---|
267 | { 2560, 1024 },
|
---|
268 | { 3840, 1024 },
|
---|
269 | { 5120, 1024 },
|
---|
270 | /* multi screen modes with 1600x1200 */
|
---|
271 | { 3200, 1200 },
|
---|
272 | { 4800, 1200 },
|
---|
273 | { 6400, 1200 },
|
---|
274 | #endif
|
---|
275 | };
|
---|
276 |
|
---|
277 | #ifdef VBOX_XPDM_MINIPORT
|
---|
278 | ULONG vramSize = pExt->pPrimary->u.primary.ulMaxFrameBufferSize;
|
---|
279 | #else
|
---|
280 | ULONG vramSize = vboxWddmVramCpuVisibleSegmentSize(pExt);
|
---|
281 | /* at least two surfaces will be needed: primary & shadow */
|
---|
282 | vramSize /= 2 * pExt->u.primary.commonInfo.cDisplays;
|
---|
283 | #endif
|
---|
284 |
|
---|
285 | uint32_t iMode=0, iPrefIdx=0;
|
---|
286 | /* there are 4 color depths: 8, 16, 24 and 32bpp and we reserve 50% of the modes for other sources */
|
---|
287 | size_t maxModesPerColorDepth = VBOXMP_MAX_VIDEO_MODES / 2 / 4;
|
---|
288 |
|
---|
289 | /* Always add 800x600 video modes. Windows XP+ needs at least 800x600 resolution
|
---|
290 | * and fallbacks to 800x600x4bpp VGA mode if the driver did not report suitable modes.
|
---|
291 | * This resolution could be rejected by a low resolution host (netbooks, etc).
|
---|
292 | */
|
---|
293 | #ifdef VBOX_WITH_8BPP_MODES
|
---|
294 | int bytesPerPixel=1;
|
---|
295 | #else
|
---|
296 | int bytesPerPixel=2;
|
---|
297 | #endif
|
---|
298 | for (; bytesPerPixel<=4; bytesPerPixel++)
|
---|
299 | {
|
---|
300 | int bitsPerPixel = 8*bytesPerPixel;
|
---|
301 |
|
---|
302 | if (800*600*bytesPerPixel > (LONG)vramSize)
|
---|
303 | {
|
---|
304 | /* we don't have enough VRAM for this mode */
|
---|
305 | continue;
|
---|
306 | }
|
---|
307 |
|
---|
308 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iMode, 800, 600, bitsPerPixel))
|
---|
309 | continue;
|
---|
310 |
|
---|
311 | VBoxFillVidModeInfo(&pModesTable[iMode], 800, 600, bitsPerPixel, iMode+1, 0);
|
---|
312 |
|
---|
313 | if (32==bitsPerPixel)
|
---|
314 | {
|
---|
315 | iPrefIdx = iMode;
|
---|
316 | }
|
---|
317 | ++iMode;
|
---|
318 | }
|
---|
319 |
|
---|
320 | /* Query yoffset from the host */
|
---|
321 | ULONG yOffset = VBoxGetHeightReduction();
|
---|
322 |
|
---|
323 | /* Iterate through our static resolution table and add supported video modes for different bpp's */
|
---|
324 | #ifdef VBOX_WITH_8BPP_MODES
|
---|
325 | bytesPerPixel=1;
|
---|
326 | #else
|
---|
327 | bytesPerPixel=2;
|
---|
328 | #endif
|
---|
329 | for (; bytesPerPixel<=4; bytesPerPixel++)
|
---|
330 | {
|
---|
331 | int bitsPerPixel = 8*bytesPerPixel;
|
---|
332 | size_t cAdded, resIndex;
|
---|
333 |
|
---|
334 | for (cAdded=0, resIndex=0; resIndex<RT_ELEMENTS(resolutionMatrix) && cAdded<maxModesPerColorDepth; resIndex++)
|
---|
335 | {
|
---|
336 | if (resolutionMatrix[resIndex].xRes * resolutionMatrix[resIndex].yRes * bytesPerPixel > (LONG)vramSize)
|
---|
337 | {
|
---|
338 | /* we don't have enough VRAM for this mode */
|
---|
339 | continue;
|
---|
340 | }
|
---|
341 |
|
---|
342 | if (yOffset == 0 && resolutionMatrix[resIndex].xRes == 800 && resolutionMatrix[resIndex].yRes == 600)
|
---|
343 | {
|
---|
344 | /* this mode was already added */
|
---|
345 | continue;
|
---|
346 | }
|
---|
347 |
|
---|
348 | if (!VBoxLikesVideoMode(iDisplay, resolutionMatrix[resIndex].xRes, resolutionMatrix[resIndex].yRes - yOffset, bitsPerPixel))
|
---|
349 | {
|
---|
350 | /* host doesn't like this mode */
|
---|
351 | continue;
|
---|
352 | }
|
---|
353 |
|
---|
354 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, resolutionMatrix[resIndex].xRes, resolutionMatrix[resIndex].yRes, bitsPerPixel))
|
---|
355 | {
|
---|
356 | /* guest does not like this mode */
|
---|
357 | continue;
|
---|
358 | }
|
---|
359 |
|
---|
360 | /* Sanity check, we shouldn't ever get here */
|
---|
361 | if (iMode >= tableSize)
|
---|
362 | {
|
---|
363 | WARN(("video modes table overflow!"));
|
---|
364 | break;
|
---|
365 | }
|
---|
366 |
|
---|
367 | VBoxFillVidModeInfo(&pModesTable[iMode], resolutionMatrix[resIndex].xRes, resolutionMatrix[resIndex].yRes, bitsPerPixel, iMode+1, yOffset);
|
---|
368 | ++iMode;
|
---|
369 | ++cAdded;
|
---|
370 | }
|
---|
371 | }
|
---|
372 |
|
---|
373 | /* Check registry for manually added modes, up to 128 entries is supported
|
---|
374 | * Give up on the first error encountered.
|
---|
375 | */
|
---|
376 | VBOXMPCMNREGISTRY Registry;
|
---|
377 | int fPrefSet=0;
|
---|
378 | VP_STATUS rc;
|
---|
379 |
|
---|
380 | rc = VBoxMPCmnRegInit(pExt, &Registry);
|
---|
381 | VBOXMP_WARN_VPS(rc);
|
---|
382 |
|
---|
383 | for (int curKey=0; curKey<128; curKey++)
|
---|
384 | {
|
---|
385 | if (iMode>=tableSize)
|
---|
386 | {
|
---|
387 | WARN(("ignoring possible custom mode(s), table is full!"));
|
---|
388 | break;
|
---|
389 | }
|
---|
390 |
|
---|
391 | wchar_t keyname[24];
|
---|
392 | uint32_t xres, yres, bpp = 0;
|
---|
393 |
|
---|
394 | swprintf(keyname, L"CustomMode%dWidth", curKey);
|
---|
395 | rc = VBoxMPCmnRegQueryDword(Registry, keyname, &xres);
|
---|
396 | VBOXMP_CHECK_VPS_BREAK(rc);
|
---|
397 |
|
---|
398 | swprintf(keyname, L"CustomMode%dHeight", curKey);
|
---|
399 | rc = VBoxMPCmnRegQueryDword(Registry, keyname, &yres);
|
---|
400 | VBOXMP_CHECK_VPS_BREAK(rc);
|
---|
401 |
|
---|
402 | swprintf(keyname, L"CustomMode%dBPP", curKey);
|
---|
403 | rc = VBoxMPCmnRegQueryDword(Registry, keyname, &bpp);
|
---|
404 | VBOXMP_CHECK_VPS_BREAK(rc);
|
---|
405 |
|
---|
406 | LOG(("got custom mode[%u]=%ux%u:%u", curKey, xres, yres, bpp));
|
---|
407 |
|
---|
408 | /* round down width to be a multiple of 8 if necessary */
|
---|
409 | if (!pExt->fAnyX)
|
---|
410 | {
|
---|
411 | xres &= 0xFFF8;
|
---|
412 | }
|
---|
413 |
|
---|
414 | if ( (xres > (1 << 16))
|
---|
415 | || (yres > (1 << 16))
|
---|
416 | || ( (bpp != 16)
|
---|
417 | && (bpp != 24)
|
---|
418 | && (bpp != 32)))
|
---|
419 | {
|
---|
420 | /* incorrect values */
|
---|
421 | break;
|
---|
422 | }
|
---|
423 |
|
---|
424 | /* does it fit within our VRAM? */
|
---|
425 | if (xres * yres * (bpp / 8) > vramSize)
|
---|
426 | {
|
---|
427 | /* we don't have enough VRAM for this mode */
|
---|
428 | break;
|
---|
429 | }
|
---|
430 |
|
---|
431 | if (!VBoxLikesVideoMode(iDisplay, xres, yres, bpp))
|
---|
432 | {
|
---|
433 | /* host doesn't like this mode */
|
---|
434 | break;
|
---|
435 | }
|
---|
436 |
|
---|
437 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, xres, yres, bpp))
|
---|
438 | {
|
---|
439 | /* guest does not like this mode */
|
---|
440 | continue;
|
---|
441 | }
|
---|
442 |
|
---|
443 | LOG(("adding video mode from registry."));
|
---|
444 |
|
---|
445 | VBoxFillVidModeInfo(&pModesTable[iMode], xres, yres, bpp, iMode+1, yOffset);
|
---|
446 |
|
---|
447 | if (!fPrefSet)
|
---|
448 | {
|
---|
449 | fPrefSet = 1;
|
---|
450 | iPrefIdx = iMode;
|
---|
451 | }
|
---|
452 | #ifdef VBOX_WDDM_MINIPORT
|
---|
453 | /*check if the same mode has been added to the table already*/
|
---|
454 | int foundIdx = VBoxMPFindVideoMode(pModesTable, iMode, &pModesTable[iMode]);
|
---|
455 |
|
---|
456 | if (foundIdx>=0)
|
---|
457 | {
|
---|
458 | if (iPrefIdx==iMode)
|
---|
459 | {
|
---|
460 | iPrefIdx=foundIdx;
|
---|
461 | }
|
---|
462 | }
|
---|
463 | else
|
---|
464 | #endif
|
---|
465 | {
|
---|
466 | ++iMode;
|
---|
467 | }
|
---|
468 | }
|
---|
469 |
|
---|
470 | rc = VBoxMPCmnRegFini(Registry);
|
---|
471 | VBOXMP_WARN_VPS(rc);
|
---|
472 |
|
---|
473 | if (pPrefModeIdx)
|
---|
474 | {
|
---|
475 | *pPrefModeIdx = iPrefIdx;
|
---|
476 | }
|
---|
477 |
|
---|
478 | return iMode;
|
---|
479 | }
|
---|
480 |
|
---|
481 | /* Returns if we're in the first mode change, ie doesn't have valid video mode set yet */
|
---|
482 | static BOOLEAN VBoxMPIsStartingUp(PVBOXMP_DEVEXT pExt, uint32_t iDisplay)
|
---|
483 | {
|
---|
484 | #ifdef VBOX_XPDM_MINIPORT
|
---|
485 | return (pExt->CurrentMode == 0);
|
---|
486 | #else
|
---|
487 | return (!VBoxCommonFromDeviceExt(pExt)->cDisplays || !pExt->aSources[iDisplay].pPrimaryAllocation);
|
---|
488 | #endif
|
---|
489 | }
|
---|
490 |
|
---|
491 | /* Updates missing video mode params with current values,
|
---|
492 | * Checks if resulting mode is liked by the host and fits into VRAM.
|
---|
493 | * Returns TRUE if resulting mode could be used.
|
---|
494 | */
|
---|
495 | static BOOLEAN
|
---|
496 | VBoxMPValidateVideoModeParams(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, uint32_t &xres, uint32_t &yres, uint32_t &bpp)
|
---|
497 | {
|
---|
498 | /* Make sure all important video mode values are set */
|
---|
499 | if (VBoxMPIsStartingUp(pExt, iDisplay))
|
---|
500 | {
|
---|
501 | /* Use stored custom values only if nothing was read from host. */
|
---|
502 | xres = xres ? xres:g_CustomVideoModes[iDisplay].VisScreenWidth;
|
---|
503 | yres = yres ? yres:g_CustomVideoModes[iDisplay].VisScreenHeight;
|
---|
504 | bpp = bpp ? bpp :g_CustomVideoModes[iDisplay].BitsPerPlane;
|
---|
505 | }
|
---|
506 | else
|
---|
507 | {
|
---|
508 | /* Use current values for field which weren't read from host. */
|
---|
509 | #ifdef VBOX_XPDM_MINIPORT
|
---|
510 | xres = xres ? xres:pExt->CurrentModeWidth;
|
---|
511 | yres = yres ? yres:pExt->CurrentModeHeight;
|
---|
512 | bpp = bpp ? bpp :pExt->CurrentModeBPP;
|
---|
513 | #else
|
---|
514 | xres = xres ? xres:pExt->aSources[iDisplay].pPrimaryAllocation->SurfDesc.width;
|
---|
515 | yres = yres ? yres:pExt->aSources[iDisplay].pPrimaryAllocation->SurfDesc.height;
|
---|
516 | bpp = bpp ? bpp :pExt->aSources[iDisplay].pPrimaryAllocation->SurfDesc.bpp;
|
---|
517 | #endif
|
---|
518 | }
|
---|
519 |
|
---|
520 | /* Round down width to be a multiple of 8 if necessary */
|
---|
521 | if (!pExt->fAnyX)
|
---|
522 | {
|
---|
523 | xres &= 0xFFF8;
|
---|
524 | }
|
---|
525 |
|
---|
526 | /* We always need bpp to be set */
|
---|
527 | if (!bpp)
|
---|
528 | {
|
---|
529 | bpp=32;
|
---|
530 | }
|
---|
531 |
|
---|
532 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, xres, yres, bpp))
|
---|
533 | return FALSE;
|
---|
534 |
|
---|
535 | /* Check if host likes this mode */
|
---|
536 | if (!VBoxLikesVideoMode(iDisplay, xres, yres, bpp))
|
---|
537 | {
|
---|
538 | WARN(("host does not like special mode %dx%d:%d for display %d", xres, yres, bpp, iDisplay));
|
---|
539 | return FALSE;
|
---|
540 | }
|
---|
541 |
|
---|
542 | #ifdef VBOX_XPDM_MINIPORT
|
---|
543 | ULONG vramSize = pExt->pPrimary->u.primary.ulMaxFrameBufferSize;
|
---|
544 | #else
|
---|
545 | ULONG vramSize = vboxWddmVramCpuVisibleSegmentSize(pExt);
|
---|
546 | /* at least two surfaces will be needed: primary & shadow */
|
---|
547 | vramSize /= 2 * pExt->u.primary.commonInfo.cDisplays;
|
---|
548 | #endif
|
---|
549 |
|
---|
550 | /* Check that values are valid and mode fits into VRAM */
|
---|
551 | if (!xres || !yres
|
---|
552 | || !((bpp == 16)
|
---|
553 | #ifdef VBOX_WITH_8BPP_MODES
|
---|
554 | || (bpp == 8)
|
---|
555 | #endif
|
---|
556 | || (bpp == 24)
|
---|
557 | || (bpp == 32)))
|
---|
558 | {
|
---|
559 | LOG(("invalid params for special mode %dx%d:%d", xres, yres, bpp));
|
---|
560 | return FALSE;
|
---|
561 | }
|
---|
562 |
|
---|
563 |
|
---|
564 |
|
---|
565 | if ((xres * yres * (bpp / 8) >= vramSize))
|
---|
566 | {
|
---|
567 | /* Store values of last reported release log message to avoid log flooding. */
|
---|
568 | static uint32_t s_xresNoVRAM=0, s_yresNoVRAM=0, s_bppNoVRAM=0;
|
---|
569 |
|
---|
570 | LOG(("not enough VRAM for video mode %dx%dx%dbpp. Available: %d bytes. Required: more than %d bytes.",
|
---|
571 | xres, yres, bpp, vramSize, xres * yres * (bpp / 8)));
|
---|
572 |
|
---|
573 | s_xresNoVRAM = xres;
|
---|
574 | s_yresNoVRAM = yres;
|
---|
575 | s_bppNoVRAM = bpp;
|
---|
576 |
|
---|
577 | return FALSE;
|
---|
578 | }
|
---|
579 |
|
---|
580 | return TRUE;
|
---|
581 | }
|
---|
582 |
|
---|
583 | /* Checks if there's a pending video mode change hint,
|
---|
584 | * and fills pPendingMode with associated info.
|
---|
585 | * returns TRUE if there's a pending change. Otherwise returns FALSE.
|
---|
586 | */
|
---|
587 | static BOOLEAN
|
---|
588 | VBoxMPCheckPendingVideoMode(PVBOXMP_DEVEXT pExt, PVIDEO_MODE_INFORMATION pPendingMode)
|
---|
589 | {
|
---|
590 | uint32_t xres=0, yres=0, bpp=0, display=0;
|
---|
591 |
|
---|
592 | /* Check if there's a pending display change request for this display */
|
---|
593 | if (VBoxQueryDisplayRequest(&xres, &yres, &bpp, &display) && (xres || yres || bpp))
|
---|
594 | {
|
---|
595 | if (display>RT_ELEMENTS(g_CustomVideoModes))
|
---|
596 | {
|
---|
597 | /*display = RT_ELEMENTS(g_CustomVideoModes) - 1;*/
|
---|
598 | return FALSE;
|
---|
599 | }
|
---|
600 | }
|
---|
601 | else
|
---|
602 | {
|
---|
603 | return FALSE;
|
---|
604 | }
|
---|
605 |
|
---|
606 | /* Correct video mode params and check if host likes it */
|
---|
607 | if (VBoxMPValidateVideoModeParams(pExt, display, xres, yres, bpp))
|
---|
608 | {
|
---|
609 | VBoxFillVidModeInfo(pPendingMode, xres, yres, bpp, display, 0);
|
---|
610 | return TRUE;
|
---|
611 | }
|
---|
612 |
|
---|
613 | return FALSE;
|
---|
614 | }
|
---|
615 |
|
---|
616 | /* Save custom mode info to registry */
|
---|
617 | static void VBoxMPRegSaveModeInfo(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, PVIDEO_MODE_INFORMATION pMode)
|
---|
618 | {
|
---|
619 | VBOXMPCMNREGISTRY Registry;
|
---|
620 | VP_STATUS rc;
|
---|
621 |
|
---|
622 | rc = VBoxMPCmnRegInit(pExt, &Registry);
|
---|
623 | VBOXMP_WARN_VPS(rc);
|
---|
624 |
|
---|
625 | if (iDisplay==0)
|
---|
626 | {
|
---|
627 | /*First name without a suffix*/
|
---|
628 | rc = VBoxMPCmnRegSetDword(Registry, L"CustomXRes", pMode->VisScreenWidth);
|
---|
629 | VBOXMP_WARN_VPS(rc);
|
---|
630 | rc = VBoxMPCmnRegSetDword(Registry, L"CustomYRes", pMode->VisScreenHeight);
|
---|
631 | VBOXMP_WARN_VPS(rc);
|
---|
632 | rc = VBoxMPCmnRegSetDword(Registry, L"CustomBPP", pMode->BitsPerPlane);
|
---|
633 | VBOXMP_WARN_VPS(rc);
|
---|
634 | }
|
---|
635 | else
|
---|
636 | {
|
---|
637 | wchar_t keyname[32];
|
---|
638 | swprintf(keyname, L"CustomXRes%d", iDisplay);
|
---|
639 | rc = VBoxMPCmnRegSetDword(Registry, keyname, pMode->VisScreenWidth);
|
---|
640 | VBOXMP_WARN_VPS(rc);
|
---|
641 | swprintf(keyname, L"CustomYRes%d", iDisplay);
|
---|
642 | rc = VBoxMPCmnRegSetDword(Registry, keyname, pMode->VisScreenHeight);
|
---|
643 | VBOXMP_WARN_VPS(rc);
|
---|
644 | swprintf(keyname, L"CustomBPP%d", iDisplay);
|
---|
645 | rc = VBoxMPCmnRegSetDword(Registry, keyname, pMode->BitsPerPlane);
|
---|
646 | VBOXMP_WARN_VPS(rc);
|
---|
647 | }
|
---|
648 |
|
---|
649 | rc = VBoxMPCmnRegFini(Registry);
|
---|
650 | VBOXMP_WARN_VPS(rc);
|
---|
651 | }
|
---|
652 |
|
---|
653 | #ifdef VBOX_XPDM_MINIPORT
|
---|
654 | VIDEO_MODE_INFORMATION* VBoxMPXpdmCurrentVideoMode(PVBOXMP_DEVEXT pExt)
|
---|
655 | {
|
---|
656 | return VBoxMPCmnGetVideoModeInfo(pExt->CurrentMode - 1);
|
---|
657 | }
|
---|
658 |
|
---|
659 | ULONG VBoxMPXpdmGetVideoModesCount()
|
---|
660 | {
|
---|
661 | return g_NumVideoModes;
|
---|
662 | }
|
---|
663 |
|
---|
664 | /* Makes a table of video modes consisting of:
|
---|
665 | * Default modes
|
---|
666 | * Custom modes manually added to registry
|
---|
667 | * Custom modes for all displays (either from a display change hint or stored in registry)
|
---|
668 | * 2 special modes, for a pending display change for this adapter. See comments below.
|
---|
669 | */
|
---|
670 | void VBoxMPXpdmBuildVideoModesTable(PVBOXMP_DEVEXT pExt)
|
---|
671 | {
|
---|
672 | uint32_t cStandartModes, cCustomModes;
|
---|
673 | BOOLEAN bPending, bHaveSpecial;
|
---|
674 | VIDEO_MODE_INFORMATION specialMode;
|
---|
675 |
|
---|
676 | /* Fill table with standart modes and ones manually added to registry */
|
---|
677 | cStandartModes = VBoxMPFillModesTable(pExt, pExt->iDevice, g_VideoModes, RT_ELEMENTS(g_VideoModes), NULL);
|
---|
678 |
|
---|
679 | /* Add custom modes for all displays to the table */
|
---|
680 | cCustomModes = VBoxCommonFromDeviceExt(pExt)->cDisplays;
|
---|
681 | for (uint32_t i=0; i<cCustomModes; i++)
|
---|
682 | {
|
---|
683 | memcpy(&g_VideoModes[cStandartModes+i], &g_CustomVideoModes[i], sizeof(VIDEO_MODE_INFORMATION));
|
---|
684 | g_VideoModes[cStandartModes+i].ModeIndex = cStandartModes+i+1;
|
---|
685 | }
|
---|
686 |
|
---|
687 | /* Check if host wants us to switch video mode and it's for this adapter */
|
---|
688 | bPending = VBoxMPCheckPendingVideoMode(pExt, &specialMode);
|
---|
689 | bHaveSpecial = bPending && (pExt->iDevice == specialMode.ModeIndex);
|
---|
690 |
|
---|
691 | /* Check the startup case */
|
---|
692 | if (!bHaveSpecial && VBoxMPIsStartingUp(pExt, pExt->iDevice))
|
---|
693 | {
|
---|
694 | uint32_t xres=0, yres=0, bpp=0;
|
---|
695 | /* Check if we could make valid mode from values stored to registry */
|
---|
696 | if (VBoxMPValidateVideoModeParams(pExt, pExt->iDevice, xres, yres, bpp))
|
---|
697 | {
|
---|
698 | VBoxFillVidModeInfo(&specialMode, xres, yres, bpp, 0, 0);
|
---|
699 | bHaveSpecial = TRUE;
|
---|
700 | }
|
---|
701 | }
|
---|
702 |
|
---|
703 | /* Update number of modes */
|
---|
704 | g_NumVideoModes = cStandartModes + cCustomModes;
|
---|
705 |
|
---|
706 | if (!bHaveSpecial)
|
---|
707 | {
|
---|
708 | /* Just add 2 dummy modes to maintain table size. */
|
---|
709 | memcpy(&g_VideoModes[g_NumVideoModes], &g_VideoModes[2], sizeof(VIDEO_MODE_INFORMATION));
|
---|
710 | g_VideoModes[g_NumVideoModes].ModeIndex = g_NumVideoModes+1;
|
---|
711 | g_NumVideoModes++;
|
---|
712 | memcpy(&g_VideoModes[g_NumVideoModes], &g_VideoModes[2], sizeof(VIDEO_MODE_INFORMATION));
|
---|
713 | g_VideoModes[g_NumVideoModes].ModeIndex = g_NumVideoModes+1;
|
---|
714 | g_NumVideoModes++;
|
---|
715 | }
|
---|
716 | else
|
---|
717 | {
|
---|
718 | /* We need to alternate mode index entry for a pending mode change,
|
---|
719 | * else windows will ignore actual mode change call.
|
---|
720 | * Only alternate index if one of mode parameters changed and
|
---|
721 | * regardless of conditions always add 2 entries to the table.
|
---|
722 | */
|
---|
723 | static int s_InvocationCounter=0;
|
---|
724 | BOOLEAN bAlternativeIndex = FALSE;
|
---|
725 |
|
---|
726 | static uint32_t s_Prev_xres=0;
|
---|
727 | static uint32_t s_Prev_yres=0;
|
---|
728 | static uint32_t s_Prev_bpp=0;
|
---|
729 | BOOLEAN bChanged = (s_Prev_xres!=specialMode.VisScreenWidth
|
---|
730 | || s_Prev_yres!=specialMode.VisScreenHeight
|
---|
731 | || s_Prev_bpp!=specialMode.BitsPerPlane);
|
---|
732 | if (bChanged)
|
---|
733 | {
|
---|
734 | s_Prev_xres = specialMode.VisScreenWidth;
|
---|
735 | s_Prev_yres = specialMode.VisScreenHeight;
|
---|
736 | s_Prev_bpp = specialMode.BitsPerPlane;
|
---|
737 | }
|
---|
738 |
|
---|
739 | /* Make sure there's no other mode in the table with same parameters,
|
---|
740 | * because we need windows to pick up a new video mode index otherwise
|
---|
741 | * actual mode change wouldn't happen.
|
---|
742 | */
|
---|
743 | int iFoundIdx;
|
---|
744 | uint32_t uiStart=0;
|
---|
745 |
|
---|
746 | while (0 <= (iFoundIdx = VBoxMPFindVideoMode(&g_VideoModes[uiStart], g_NumVideoModes-uiStart, &specialMode)))
|
---|
747 | {
|
---|
748 | memcpy(&g_VideoModes[uiStart+iFoundIdx], &g_VideoModes[2], sizeof(VIDEO_MODE_INFORMATION));
|
---|
749 | g_VideoModes[uiStart+iFoundIdx].ModeIndex = uiStart+iFoundIdx+1;
|
---|
750 | uiStart += iFoundIdx+1;
|
---|
751 | }
|
---|
752 |
|
---|
753 | /* Check if we need to alternate the index */
|
---|
754 | if (!VBoxMPIsStartingUp(pExt, pExt->iDevice))
|
---|
755 | {
|
---|
756 | if (bChanged)
|
---|
757 | {
|
---|
758 | s_InvocationCounter++;
|
---|
759 | }
|
---|
760 |
|
---|
761 | if (s_InvocationCounter % 2)
|
---|
762 | {
|
---|
763 | bAlternativeIndex = TRUE;
|
---|
764 | memcpy(&g_VideoModes[g_NumVideoModes], &g_VideoModes[2], sizeof(VIDEO_MODE_INFORMATION));
|
---|
765 | g_VideoModes[g_NumVideoModes].ModeIndex = g_NumVideoModes+1;
|
---|
766 | ++g_NumVideoModes;
|
---|
767 | }
|
---|
768 | }
|
---|
769 |
|
---|
770 | LOG(("add special mode[%d] %dx%d:%d for display %d (bChanged=%d, bAlretnativeIndex=%d)",
|
---|
771 | g_NumVideoModes, specialMode.VisScreenWidth, specialMode.VisScreenHeight, specialMode.BitsPerPlane,
|
---|
772 | pExt->iDevice, bChanged, bAlternativeIndex));
|
---|
773 |
|
---|
774 | /* Add special mode to the table
|
---|
775 | * Note: Y offset isn't used for a host-supplied modes
|
---|
776 | */
|
---|
777 | specialMode.ModeIndex = g_NumVideoModes+1;
|
---|
778 | memcpy(&g_VideoModes[g_NumVideoModes], &specialMode, sizeof(VIDEO_MODE_INFORMATION));
|
---|
779 | ++g_NumVideoModes;
|
---|
780 |
|
---|
781 | /* Save special mode in the custom modes table */
|
---|
782 | memcpy(&g_CustomVideoModes[pExt->iDevice], &specialMode, sizeof(VIDEO_MODE_INFORMATION));
|
---|
783 |
|
---|
784 |
|
---|
785 | /* Make sure we've added 2nd mode if necessary to maintain table size */
|
---|
786 | if (VBoxMPIsStartingUp(pExt, pExt->iDevice))
|
---|
787 | {
|
---|
788 | memcpy(&g_VideoModes[g_NumVideoModes], &g_VideoModes[g_NumVideoModes-1], sizeof(VIDEO_MODE_INFORMATION));
|
---|
789 | g_VideoModes[g_NumVideoModes].ModeIndex = g_NumVideoModes+1;
|
---|
790 | ++g_NumVideoModes;
|
---|
791 | }
|
---|
792 | else if (!bAlternativeIndex)
|
---|
793 | {
|
---|
794 | memcpy(&g_VideoModes[g_NumVideoModes], &g_VideoModes[2], sizeof(VIDEO_MODE_INFORMATION));
|
---|
795 | g_VideoModes[g_NumVideoModes].ModeIndex = g_NumVideoModes+1;
|
---|
796 | ++g_NumVideoModes;
|
---|
797 | }
|
---|
798 |
|
---|
799 | /* Save special mode info to registry */
|
---|
800 | VBoxMPRegSaveModeInfo(pExt, pExt->iDevice, &specialMode);
|
---|
801 | }
|
---|
802 |
|
---|
803 | #if defined(LOG_ENABLED)
|
---|
804 | do
|
---|
805 | {
|
---|
806 | LOG(("Filled %d modes", g_NumVideoModes));
|
---|
807 |
|
---|
808 | for (uint32_t i=0; i<g_NumVideoModes; ++i)
|
---|
809 | {
|
---|
810 | LOG(("Mode[%2d]: %4dx%4d:%2d (idx=%d)",
|
---|
811 | i, g_VideoModes[i].VisScreenWidth, g_VideoModes[i].VisScreenHeight,
|
---|
812 | g_VideoModes[i].BitsPerPlane, g_VideoModes[i].ModeIndex));
|
---|
813 | }
|
---|
814 | } while (0);
|
---|
815 | #endif
|
---|
816 | }
|
---|
817 | #endif /*VBOX_XPDM_MINIPORT*/
|
---|
818 |
|
---|
819 | #ifdef VBOX_WDDM_MINIPORT
|
---|
820 | static VBOXWDDM_VIDEOMODES_INFO g_aVBoxVideoModeInfos[VBOX_VIDEO_MAX_SCREENS] = {0};
|
---|
821 |
|
---|
822 | bool VBoxWddmFillMode(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, VIDEO_MODE_INFORMATION *pInfo, D3DDDIFORMAT enmFormat, ULONG w, ULONG h)
|
---|
823 | {
|
---|
824 | switch (enmFormat)
|
---|
825 | {
|
---|
826 | case D3DDDIFMT_A8R8G8B8:
|
---|
827 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 32))
|
---|
828 | {
|
---|
829 | WARN(("unsupported mode info for format(%d)", enmFormat));
|
---|
830 | return false;
|
---|
831 | }
|
---|
832 | VBoxFillVidModeInfo(pInfo, w, h, 32, 0, 0);
|
---|
833 | return true;
|
---|
834 | case D3DDDIFMT_R8G8B8:
|
---|
835 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 24))
|
---|
836 | {
|
---|
837 | WARN(("unsupported mode info for format(%d)", enmFormat));
|
---|
838 | return false;
|
---|
839 | }
|
---|
840 | VBoxFillVidModeInfo(pInfo, w, h, 24, 0, 0);
|
---|
841 | return true;
|
---|
842 | case D3DDDIFMT_R5G6B5:
|
---|
843 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 16))
|
---|
844 | {
|
---|
845 | WARN(("unsupported mode info for format(%d)", enmFormat));
|
---|
846 | return false;
|
---|
847 | }
|
---|
848 | VBoxFillVidModeInfo(pInfo, w, h, 16, 0, 0);
|
---|
849 | return true;
|
---|
850 | case D3DDDIFMT_P8:
|
---|
851 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 8))
|
---|
852 | {
|
---|
853 | WARN(("unsupported mode info for format(%d)", enmFormat));
|
---|
854 | return false;
|
---|
855 | }
|
---|
856 | VBoxFillVidModeInfo(pInfo, w, h, 8, 0, 0);
|
---|
857 | return true;
|
---|
858 | default:
|
---|
859 | WARN(("unsupported enmFormat(%d)", enmFormat));
|
---|
860 | AssertBreakpoint();
|
---|
861 | break;
|
---|
862 | }
|
---|
863 |
|
---|
864 | return false;
|
---|
865 | }
|
---|
866 |
|
---|
867 | static void
|
---|
868 | VBoxWddmBuildResolutionTable(PVIDEO_MODE_INFORMATION pModesTable, size_t tableSize, int iPreferredMode,
|
---|
869 | SIZE *pResolutions, uint32_t * pcResolutions, int *piPreferredResolution)
|
---|
870 | {
|
---|
871 | uint32_t cResolutionsArray = *pcResolutions;
|
---|
872 | uint32_t cResolutions = 0;
|
---|
873 |
|
---|
874 | *piPreferredResolution = -1;
|
---|
875 |
|
---|
876 | for (uint32_t i=0; i<tableSize; ++i)
|
---|
877 | {
|
---|
878 | PVIDEO_MODE_INFORMATION pMode = &pModesTable[i];
|
---|
879 | int iResolution = -1;
|
---|
880 |
|
---|
881 | for (uint32_t j=0; j<cResolutions; ++j)
|
---|
882 | {
|
---|
883 | if (pResolutions[j].cx == pMode->VisScreenWidth
|
---|
884 | && pResolutions[j].cy == pMode->VisScreenHeight)
|
---|
885 | {
|
---|
886 | iResolution = j;
|
---|
887 | break;
|
---|
888 | }
|
---|
889 | }
|
---|
890 |
|
---|
891 | if (iResolution < 0)
|
---|
892 | {
|
---|
893 | if (cResolutions == cResolutionsArray)
|
---|
894 | {
|
---|
895 | WARN(("table overflow!"));
|
---|
896 | break;
|
---|
897 | }
|
---|
898 |
|
---|
899 | iResolution = cResolutions;
|
---|
900 | pResolutions[cResolutions].cx = pMode->VisScreenWidth;
|
---|
901 | pResolutions[cResolutions].cy = pMode->VisScreenHeight;
|
---|
902 | ++cResolutions;
|
---|
903 | }
|
---|
904 |
|
---|
905 | Assert(iResolution >= 0);
|
---|
906 | if (i == iPreferredMode)
|
---|
907 | {
|
---|
908 | Assert(*piPreferredResolution == -1);
|
---|
909 | *piPreferredResolution = iResolution;
|
---|
910 | }
|
---|
911 | }
|
---|
912 |
|
---|
913 | *pcResolutions = cResolutions;
|
---|
914 | Assert(*piPreferredResolution >= 0);
|
---|
915 | }
|
---|
916 |
|
---|
917 | static void VBoxWddmBuildResolutionTableForModes(PVBOXWDDM_VIDEOMODES_INFO pModes)
|
---|
918 | {
|
---|
919 | pModes->cResolutions = RT_ELEMENTS(pModes->aResolutions);
|
---|
920 | VBoxWddmBuildResolutionTable(pModes->aModes, pModes->cModes, pModes->iPreferredMode,
|
---|
921 | (SIZE*)((void*)pModes->aResolutions), &pModes->cResolutions, &pModes->iPreferredResolution);
|
---|
922 | Assert(pModes->aResolutions[pModes->iPreferredResolution].cx == pModes->aModes[pModes->iPreferredMode].VisScreenWidth
|
---|
923 | && pModes->aResolutions[pModes->iPreferredResolution].cy == pModes->aModes[pModes->iPreferredMode].VisScreenHeight);
|
---|
924 | }
|
---|
925 |
|
---|
926 | AssertCompile(sizeof (SIZE) == sizeof (D3DKMDT_2DREGION));
|
---|
927 | AssertCompile(RT_OFFSETOF(SIZE, cx) == RT_OFFSETOF(D3DKMDT_2DREGION, cx));
|
---|
928 | AssertCompile(RT_OFFSETOF(SIZE, cy) == RT_OFFSETOF(D3DKMDT_2DREGION, cy));
|
---|
929 | static void
|
---|
930 | VBoxWddmBuildVideoModesInfo(PVBOXMP_DEVEXT pExt, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId,
|
---|
931 | PVBOXWDDM_VIDEOMODES_INFO pModes, VIDEO_MODE_INFORMATION *paAddlModes,
|
---|
932 | UINT cAddlModes)
|
---|
933 | {
|
---|
934 | pModes->cResolutions = RT_ELEMENTS(pModes->aResolutions);
|
---|
935 |
|
---|
936 | /* Add default modes and ones read from registry. */
|
---|
937 | pModes->cModes = VBoxMPFillModesTable(pExt, VidPnTargetId, pModes->aModes, RT_ELEMENTS(pModes->aModes), &pModes->iPreferredMode);
|
---|
938 | Assert(pModes->cModes<=RT_ELEMENTS(pModes->aModes));
|
---|
939 |
|
---|
940 | /* Check if there's a pending display change request for this adapter */
|
---|
941 | VIDEO_MODE_INFORMATION specialMode;
|
---|
942 | if (VBoxMPCheckPendingVideoMode(pExt, &specialMode) && (specialMode.ModeIndex==VidPnTargetId))
|
---|
943 | {
|
---|
944 | /*Minor hack, ModeIndex!=0 Means this mode has been validated already and not just read from registry */
|
---|
945 | specialMode.ModeIndex = 1;
|
---|
946 | memcpy(&g_CustomVideoModes[VidPnTargetId], &specialMode, sizeof(VIDEO_MODE_INFORMATION));
|
---|
947 |
|
---|
948 | /* Save mode to registry */
|
---|
949 | VBoxMPRegSaveModeInfo(pExt, VidPnTargetId, &specialMode);
|
---|
950 | }
|
---|
951 |
|
---|
952 | /* Validate the mode which has been read from registry */
|
---|
953 | if (!g_CustomVideoModes[VidPnTargetId].ModeIndex)
|
---|
954 | {
|
---|
955 | uint32_t xres, yres, bpp;
|
---|
956 |
|
---|
957 | xres = g_CustomVideoModes[VidPnTargetId].VisScreenWidth;
|
---|
958 | yres = g_CustomVideoModes[VidPnTargetId].VisScreenHeight;
|
---|
959 | bpp = g_CustomVideoModes[VidPnTargetId].BitsPerPlane;
|
---|
960 |
|
---|
961 | if (VBoxMPValidateVideoModeParams(pExt, VidPnTargetId, xres, yres, bpp))
|
---|
962 | {
|
---|
963 | VBoxFillVidModeInfo(&g_CustomVideoModes[VidPnTargetId], xres, yres, bpp, 1/*index*/, 0);
|
---|
964 | Assert(g_CustomVideoModes[VidPnTargetId].ModeIndex == 1);
|
---|
965 | }
|
---|
966 | }
|
---|
967 |
|
---|
968 | /* Add custom mode to the table */
|
---|
969 | if (g_CustomVideoModes[VidPnTargetId].ModeIndex)
|
---|
970 | {
|
---|
971 | if (RT_ELEMENTS(pModes->aModes) > pModes->cModes)
|
---|
972 | {
|
---|
973 | g_CustomVideoModes[VidPnTargetId].ModeIndex = pModes->cModes;
|
---|
974 | pModes->aModes[pModes->cModes] = g_CustomVideoModes[VidPnTargetId];
|
---|
975 |
|
---|
976 | /* Check if we already have this mode in the table */
|
---|
977 | int foundIdx;
|
---|
978 | if ((foundIdx=VBoxMPFindVideoMode(pModes->aModes, pModes->cModes, &pModes->aModes[pModes->cModes]))>=0)
|
---|
979 | {
|
---|
980 | pModes->iPreferredMode = foundIdx;
|
---|
981 | }
|
---|
982 | else
|
---|
983 | {
|
---|
984 | pModes->iPreferredMode = pModes->cModes;
|
---|
985 | ++pModes->cModes;
|
---|
986 | }
|
---|
987 |
|
---|
988 | /* Add other bpp modes for this custom resolution */
|
---|
989 | #ifdef VBOX_WITH_8BPP_MODES
|
---|
990 | UINT bpp=8;
|
---|
991 | #else
|
---|
992 | UINT bpp=16;
|
---|
993 | #endif
|
---|
994 | for (; bpp<=32; bpp+=8)
|
---|
995 | {
|
---|
996 | if (RT_ELEMENTS(pModes->aModes) == pModes->cModes)
|
---|
997 | {
|
---|
998 | WARN(("table full, can't add other bpp for specail mode!"));
|
---|
999 | #ifdef DEBUG_misha
|
---|
1000 | /* this is definitely something we do not expect */
|
---|
1001 | AssertFailed();
|
---|
1002 | #endif
|
---|
1003 | break;
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | AssertRelease(RT_ELEMENTS(pModes->aModes) > pModes->cModes); /* if not - the driver state is screwed up, @todo: better do KeBugCheckEx here */
|
---|
1007 |
|
---|
1008 | if (pModes->aModes[pModes->iPreferredMode].BitsPerPlane == bpp)
|
---|
1009 | continue;
|
---|
1010 |
|
---|
1011 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, VidPnTargetId,
|
---|
1012 | pModes->aModes[pModes->iPreferredMode].VisScreenWidth,
|
---|
1013 | pModes->aModes[pModes->iPreferredMode].VisScreenHeight,
|
---|
1014 | bpp))
|
---|
1015 | continue;
|
---|
1016 |
|
---|
1017 | VBoxFillVidModeInfo(&pModes->aModes[pModes->cModes],
|
---|
1018 | pModes->aModes[pModes->iPreferredMode].VisScreenWidth,
|
---|
1019 | pModes->aModes[pModes->iPreferredMode].VisScreenHeight,
|
---|
1020 | bpp, pModes->cModes, 0);
|
---|
1021 | if (VBoxMPFindVideoMode(pModes->aModes, pModes->cModes, &pModes->aModes[pModes->cModes]) < 0)
|
---|
1022 | {
|
---|
1023 | ++pModes->cModes;
|
---|
1024 | }
|
---|
1025 | }
|
---|
1026 | }
|
---|
1027 | else
|
---|
1028 | {
|
---|
1029 | AssertRelease(RT_ELEMENTS(pModes->aModes) == pModes->cModes); /* if not - the driver state is screwed up, @todo: better do KeBugCheckEx here */
|
---|
1030 | WARN(("table full, can't add video mode for a host request!"));
|
---|
1031 | #ifdef DEBUG_misha
|
---|
1032 | /* this is definitely something we do not expect */
|
---|
1033 | AssertFailed();
|
---|
1034 | #endif
|
---|
1035 | }
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | /* Check and Add additional modes passed in paAddlModes */
|
---|
1039 | for (UINT i=0; i<cAddlModes; ++i)
|
---|
1040 | {
|
---|
1041 | if (RT_ELEMENTS(pModes->aModes) == pModes->cModes)
|
---|
1042 | {
|
---|
1043 | WARN(("table full, can't add addl modes!"));
|
---|
1044 | #ifdef DEBUG_misha
|
---|
1045 | /* this is definitely something we do not expect */
|
---|
1046 | AssertFailed();
|
---|
1047 | #endif
|
---|
1048 | break;
|
---|
1049 | }
|
---|
1050 |
|
---|
1051 | AssertRelease(RT_ELEMENTS(pModes->aModes) > pModes->cModes); /* if not - the driver state is screwed up, @todo: better do KeBugCheckEx here */
|
---|
1052 |
|
---|
1053 | if (!pExt->fAnyX)
|
---|
1054 | {
|
---|
1055 | paAddlModes[i].VisScreenWidth &= 0xFFF8;
|
---|
1056 | }
|
---|
1057 |
|
---|
1058 | if (VBoxLikesVideoMode(VidPnTargetId, paAddlModes[i].VisScreenWidth, paAddlModes[i].VisScreenHeight, paAddlModes[i].BitsPerPlane))
|
---|
1059 | {
|
---|
1060 | int foundIdx;
|
---|
1061 | if ((foundIdx=VBoxMPFindVideoMode(pModes->aModes, pModes->cModes, &paAddlModes[i]))>=0)
|
---|
1062 | {
|
---|
1063 | pModes->iPreferredMode = foundIdx;
|
---|
1064 | }
|
---|
1065 | else
|
---|
1066 | {
|
---|
1067 | memcpy(&pModes->aModes[pModes->cModes], &paAddlModes[i], sizeof(VIDEO_MODE_INFORMATION));
|
---|
1068 | pModes->aModes[pModes->cModes].ModeIndex = pModes->cModes;
|
---|
1069 | ++pModes->cModes;
|
---|
1070 | }
|
---|
1071 | }
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 | /* Build resolution table */
|
---|
1075 | VBoxWddmBuildResolutionTableForModes(pModes);
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | void VBoxWddmInvalidateVideoModesInfo(PVBOXMP_DEVEXT pExt)
|
---|
1079 | {
|
---|
1080 | for (UINT i = 0; i < RT_ELEMENTS(g_aVBoxVideoModeInfos); ++i)
|
---|
1081 | {
|
---|
1082 | g_aVBoxVideoModeInfos[i].cModes = 0;
|
---|
1083 | }
|
---|
1084 | }
|
---|
1085 |
|
---|
1086 | PVBOXWDDM_VIDEOMODES_INFO VBoxWddmUpdateVideoModesInfo(PVBOXMP_DEVEXT pExt, PVBOXWDDM_RECOMMENDVIDPN pVidPnInfo)
|
---|
1087 | {
|
---|
1088 | VBoxWddmInvalidateVideoModesInfo(pExt);
|
---|
1089 |
|
---|
1090 | if (pVidPnInfo)
|
---|
1091 | {
|
---|
1092 | for (UINT i = 0; i < pVidPnInfo->cScreenInfos; ++i)
|
---|
1093 | {
|
---|
1094 | PVBOXWDDM_RECOMMENDVIDPN_SCREEN_INFO pScreenInfo = &pVidPnInfo->aScreenInfos[i];
|
---|
1095 | Assert(pScreenInfo->Id < (DWORD)VBoxCommonFromDeviceExt(pExt)->cDisplays);
|
---|
1096 | if (pScreenInfo->Id < (DWORD)VBoxCommonFromDeviceExt(pExt)->cDisplays)
|
---|
1097 | {
|
---|
1098 | PVBOXWDDM_VIDEOMODES_INFO pInfo = &g_aVBoxVideoModeInfos[pScreenInfo->Id];
|
---|
1099 | VIDEO_MODE_INFORMATION ModeInfo = {0};
|
---|
1100 | D3DDDIFORMAT enmFormat;
|
---|
1101 | switch (pScreenInfo->BitsPerPixel)
|
---|
1102 | {
|
---|
1103 | case 32:
|
---|
1104 | enmFormat = D3DDDIFMT_A8R8G8B8;
|
---|
1105 | break;
|
---|
1106 | case 24:
|
---|
1107 | enmFormat = D3DDDIFMT_R8G8B8;
|
---|
1108 | break;
|
---|
1109 | case 16:
|
---|
1110 | enmFormat = D3DDDIFMT_R5G6B5;
|
---|
1111 | break;
|
---|
1112 | case 8:
|
---|
1113 | enmFormat = D3DDDIFMT_P8;
|
---|
1114 | break;
|
---|
1115 | default:
|
---|
1116 | Assert(0);
|
---|
1117 | enmFormat = D3DDDIFMT_UNKNOWN;
|
---|
1118 | break;
|
---|
1119 | }
|
---|
1120 | if (enmFormat != D3DDDIFMT_UNKNOWN)
|
---|
1121 | {
|
---|
1122 | if (VBoxWddmFillMode(pExt, pScreenInfo->Id, &ModeInfo, enmFormat, pScreenInfo->Width, pScreenInfo->Height))
|
---|
1123 | {
|
---|
1124 | VBoxWddmBuildVideoModesInfo(pExt, pScreenInfo->Id, pInfo, &ModeInfo, 1);
|
---|
1125 | }
|
---|
1126 | else
|
---|
1127 | {
|
---|
1128 | Assert(0);
|
---|
1129 | }
|
---|
1130 | }
|
---|
1131 | }
|
---|
1132 | }
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | /* ensure we have all the rest populated */
|
---|
1136 | VBoxWddmGetAllVideoModesInfos(pExt);
|
---|
1137 | return g_aVBoxVideoModeInfos;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | NTSTATUS VBoxWddmGetModesForResolution(VIDEO_MODE_INFORMATION *pAllModes, uint32_t cAllModes, int iSearchPreferredMode,
|
---|
1141 | const D3DKMDT_2DREGION *pResolution, VIDEO_MODE_INFORMATION * pModes, uint32_t cModes, uint32_t *pcModes, int32_t *piPreferrableMode)
|
---|
1142 | {
|
---|
1143 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
1144 | uint32_t cFound = 0;
|
---|
1145 | int iFoundPreferrableMode = -1;
|
---|
1146 | for (uint32_t i = 0; i < cAllModes; ++i)
|
---|
1147 | {
|
---|
1148 | VIDEO_MODE_INFORMATION *pCur = &pAllModes[i];
|
---|
1149 | if (pResolution->cx == pCur->VisScreenWidth
|
---|
1150 | && pResolution->cy == pCur->VisScreenHeight)
|
---|
1151 | {
|
---|
1152 | if (pModes && cModes > cFound)
|
---|
1153 | memcpy(&pModes[cFound], pCur, sizeof(VIDEO_MODE_INFORMATION));
|
---|
1154 | else
|
---|
1155 | Status = STATUS_BUFFER_TOO_SMALL;
|
---|
1156 |
|
---|
1157 | if (i == iSearchPreferredMode)
|
---|
1158 | iFoundPreferrableMode = cFound;
|
---|
1159 |
|
---|
1160 | ++cFound;
|
---|
1161 | }
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | Assert(iFoundPreferrableMode < 0 || cFound > (uint32_t)iFoundPreferrableMode);
|
---|
1165 |
|
---|
1166 | *pcModes = cFound;
|
---|
1167 | if (piPreferrableMode)
|
---|
1168 | *piPreferrableMode = iFoundPreferrableMode;
|
---|
1169 |
|
---|
1170 | return Status;
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | static PVBOXWDDM_VIDEOMODES_INFO vboxWddmGetVideoModesInfoInternal(PVBOXMP_DEVEXT pExt, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId)
|
---|
1174 | {
|
---|
1175 | Assert(VidPnTargetId < (D3DDDI_VIDEO_PRESENT_TARGET_ID)VBoxCommonFromDeviceExt(pExt)->cDisplays);
|
---|
1176 | if (VidPnTargetId >= (D3DDDI_VIDEO_PRESENT_TARGET_ID)VBoxCommonFromDeviceExt(pExt)->cDisplays)
|
---|
1177 | {
|
---|
1178 | return NULL;
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 | PVBOXWDDM_VIDEOMODES_INFO pInfo = &g_aVBoxVideoModeInfos[VidPnTargetId];
|
---|
1182 |
|
---|
1183 | if (!pInfo->cModes)
|
---|
1184 | {
|
---|
1185 | VBoxWddmBuildVideoModesInfo(pExt, VidPnTargetId, pInfo, NULL, 0);
|
---|
1186 | Assert(pInfo->cModes);
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | return pInfo;
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | static VOID vboxWddmAddVideoModes(PVBOXMP_DEVEXT pExt, PVBOXWDDM_VIDEOMODES_INFO pDstInfo, PVBOXWDDM_VIDEOMODES_INFO pSrcInfo)
|
---|
1193 | {
|
---|
1194 | for (int i = 0; i < (int)pSrcInfo->cModes; ++i)
|
---|
1195 | {
|
---|
1196 | int foundIdx = VBoxMPFindVideoMode(pDstInfo->aModes, pDstInfo->cModes, &pSrcInfo->aModes[i]);
|
---|
1197 | if (foundIdx >= 0)
|
---|
1198 | continue;
|
---|
1199 |
|
---|
1200 | Assert(0);
|
---|
1201 | pDstInfo->aModes[pDstInfo->cModes] = pSrcInfo->aModes[i];
|
---|
1202 | ++pDstInfo->cModes;
|
---|
1203 | }
|
---|
1204 |
|
---|
1205 | VBoxWddmBuildResolutionTableForModes(pDstInfo);
|
---|
1206 | }
|
---|
1207 |
|
---|
1208 | PVBOXWDDM_VIDEOMODES_INFO VBoxWddmGetAllVideoModesInfos(PVBOXMP_DEVEXT pExt)
|
---|
1209 | {
|
---|
1210 | /* ensure all modes are initialized */
|
---|
1211 | for (int i = 0; i < VBoxCommonFromDeviceExt(pExt)->cDisplays; ++i)
|
---|
1212 | {
|
---|
1213 | vboxWddmGetVideoModesInfoInternal(pExt, (D3DDDI_VIDEO_PRESENT_TARGET_ID)i);
|
---|
1214 | }
|
---|
1215 |
|
---|
1216 | return g_aVBoxVideoModeInfos;
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 | PVBOXWDDM_VIDEOMODES_INFO VBoxWddmGetVideoModesInfo(PVBOXMP_DEVEXT pExt, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId)
|
---|
1220 | {
|
---|
1221 | return &VBoxWddmGetAllVideoModesInfos(pExt)[VidPnTargetId];
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | #endif /*VBOX_WDDM_MINIPORT*/
|
---|