1 | /* $Id: VBoxMPVidModes.cpp 44040 2012-12-05 13:56:15Z 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 (
|
---|
349 | #ifdef VBOX_WDDM_MINIPORT
|
---|
350 | /* 1024x768 resolution is a minimal resolutions for win8 to make most metro apps run.
|
---|
351 | * For small host display resolutions, host will dislike the mode 1024x768 and above
|
---|
352 | * if the framebuffer window requires scrolling to fit the guest resolution.
|
---|
353 | * So add 1024x768 resolution for win8 guest to allow user switch to it */
|
---|
354 | (VBoxQueryWinVersion() != WIN8 || resolutionMatrix[resIndex].xRes != 1024 || resolutionMatrix[resIndex].yRes != 768) &&
|
---|
355 | #endif
|
---|
356 | !VBoxLikesVideoMode(iDisplay, resolutionMatrix[resIndex].xRes, resolutionMatrix[resIndex].yRes - yOffset, bitsPerPixel))
|
---|
357 | {
|
---|
358 | /* host doesn't like this mode */
|
---|
359 | continue;
|
---|
360 | }
|
---|
361 |
|
---|
362 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, resolutionMatrix[resIndex].xRes, resolutionMatrix[resIndex].yRes, bitsPerPixel))
|
---|
363 | {
|
---|
364 | /* guest does not like this mode */
|
---|
365 | continue;
|
---|
366 | }
|
---|
367 |
|
---|
368 | /* Sanity check, we shouldn't ever get here */
|
---|
369 | if (iMode >= tableSize)
|
---|
370 | {
|
---|
371 | WARN(("video modes table overflow!"));
|
---|
372 | break;
|
---|
373 | }
|
---|
374 |
|
---|
375 | VBoxFillVidModeInfo(&pModesTable[iMode], resolutionMatrix[resIndex].xRes, resolutionMatrix[resIndex].yRes, bitsPerPixel, iMode+1, yOffset);
|
---|
376 | ++iMode;
|
---|
377 | ++cAdded;
|
---|
378 | }
|
---|
379 | }
|
---|
380 |
|
---|
381 | /* Check registry for manually added modes, up to 128 entries is supported
|
---|
382 | * Give up on the first error encountered.
|
---|
383 | */
|
---|
384 | VBOXMPCMNREGISTRY Registry;
|
---|
385 | int fPrefSet=0;
|
---|
386 | VP_STATUS rc;
|
---|
387 |
|
---|
388 | rc = VBoxMPCmnRegInit(pExt, &Registry);
|
---|
389 | VBOXMP_WARN_VPS(rc);
|
---|
390 |
|
---|
391 | for (int curKey=0; curKey<128; curKey++)
|
---|
392 | {
|
---|
393 | if (iMode>=tableSize)
|
---|
394 | {
|
---|
395 | WARN(("ignoring possible custom mode(s), table is full!"));
|
---|
396 | break;
|
---|
397 | }
|
---|
398 |
|
---|
399 | wchar_t keyname[24];
|
---|
400 | uint32_t xres, yres, bpp = 0;
|
---|
401 |
|
---|
402 | swprintf(keyname, L"CustomMode%dWidth", curKey);
|
---|
403 | rc = VBoxMPCmnRegQueryDword(Registry, keyname, &xres);
|
---|
404 | VBOXMP_CHECK_VPS_BREAK(rc);
|
---|
405 |
|
---|
406 | swprintf(keyname, L"CustomMode%dHeight", curKey);
|
---|
407 | rc = VBoxMPCmnRegQueryDword(Registry, keyname, &yres);
|
---|
408 | VBOXMP_CHECK_VPS_BREAK(rc);
|
---|
409 |
|
---|
410 | swprintf(keyname, L"CustomMode%dBPP", curKey);
|
---|
411 | rc = VBoxMPCmnRegQueryDword(Registry, keyname, &bpp);
|
---|
412 | VBOXMP_CHECK_VPS_BREAK(rc);
|
---|
413 |
|
---|
414 | LOG(("got custom mode[%u]=%ux%u:%u", curKey, xres, yres, bpp));
|
---|
415 |
|
---|
416 | /* round down width to be a multiple of 8 if necessary */
|
---|
417 | if (!pExt->fAnyX)
|
---|
418 | {
|
---|
419 | xres &= 0xFFF8;
|
---|
420 | }
|
---|
421 |
|
---|
422 | if ( (xres > (1 << 16))
|
---|
423 | || (yres > (1 << 16))
|
---|
424 | || ( (bpp != 16)
|
---|
425 | && (bpp != 24)
|
---|
426 | && (bpp != 32)))
|
---|
427 | {
|
---|
428 | /* incorrect values */
|
---|
429 | break;
|
---|
430 | }
|
---|
431 |
|
---|
432 | /* does it fit within our VRAM? */
|
---|
433 | if (xres * yres * (bpp / 8) > vramSize)
|
---|
434 | {
|
---|
435 | /* we don't have enough VRAM for this mode */
|
---|
436 | break;
|
---|
437 | }
|
---|
438 |
|
---|
439 | if (!VBoxLikesVideoMode(iDisplay, xres, yres, bpp))
|
---|
440 | {
|
---|
441 | /* host doesn't like this mode */
|
---|
442 | break;
|
---|
443 | }
|
---|
444 |
|
---|
445 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, xres, yres, bpp))
|
---|
446 | {
|
---|
447 | /* guest does not like this mode */
|
---|
448 | continue;
|
---|
449 | }
|
---|
450 |
|
---|
451 | LOG(("adding video mode from registry."));
|
---|
452 |
|
---|
453 | VBoxFillVidModeInfo(&pModesTable[iMode], xres, yres, bpp, iMode+1, yOffset);
|
---|
454 |
|
---|
455 | if (!fPrefSet)
|
---|
456 | {
|
---|
457 | fPrefSet = 1;
|
---|
458 | iPrefIdx = iMode;
|
---|
459 | }
|
---|
460 | #ifdef VBOX_WDDM_MINIPORT
|
---|
461 | /*check if the same mode has been added to the table already*/
|
---|
462 | int foundIdx = VBoxMPFindVideoMode(pModesTable, iMode, &pModesTable[iMode]);
|
---|
463 |
|
---|
464 | if (foundIdx>=0)
|
---|
465 | {
|
---|
466 | if (iPrefIdx==iMode)
|
---|
467 | {
|
---|
468 | iPrefIdx=foundIdx;
|
---|
469 | }
|
---|
470 | }
|
---|
471 | else
|
---|
472 | #endif
|
---|
473 | {
|
---|
474 | ++iMode;
|
---|
475 | }
|
---|
476 | }
|
---|
477 |
|
---|
478 | rc = VBoxMPCmnRegFini(Registry);
|
---|
479 | VBOXMP_WARN_VPS(rc);
|
---|
480 |
|
---|
481 | if (pPrefModeIdx)
|
---|
482 | {
|
---|
483 | *pPrefModeIdx = iPrefIdx;
|
---|
484 | }
|
---|
485 |
|
---|
486 | return iMode;
|
---|
487 | }
|
---|
488 |
|
---|
489 | /* Returns if we're in the first mode change, ie doesn't have valid video mode set yet */
|
---|
490 | static BOOLEAN VBoxMPIsStartingUp(PVBOXMP_DEVEXT pExt, uint32_t iDisplay)
|
---|
491 | {
|
---|
492 | #ifdef VBOX_XPDM_MINIPORT
|
---|
493 | return (pExt->CurrentMode == 0);
|
---|
494 | #elif defined(VBOX_WDDM_WIN8)
|
---|
495 | return FALSE;
|
---|
496 | #else /* VBOX_WDDM_MINIPORT && !VBOX_WDDM_MINIPORT */
|
---|
497 | return (!VBoxCommonFromDeviceExt(pExt)->cDisplays
|
---|
498 | || !pExt->aSources[iDisplay].pPrimaryAllocation);
|
---|
499 | #endif
|
---|
500 | }
|
---|
501 |
|
---|
502 | /* Updates missing video mode params with current values,
|
---|
503 | * Checks if resulting mode is liked by the host and fits into VRAM.
|
---|
504 | * Returns TRUE if resulting mode could be used.
|
---|
505 | */
|
---|
506 | static BOOLEAN
|
---|
507 | VBoxMPValidateVideoModeParams(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, uint32_t &xres, uint32_t &yres, uint32_t &bpp)
|
---|
508 | {
|
---|
509 | /* Make sure all important video mode values are set */
|
---|
510 | if (VBoxMPIsStartingUp(pExt, iDisplay))
|
---|
511 | {
|
---|
512 | /* Use stored custom values only if nothing was read from host. */
|
---|
513 | xres = xres ? xres:g_CustomVideoModes[iDisplay].VisScreenWidth;
|
---|
514 | yres = yres ? yres:g_CustomVideoModes[iDisplay].VisScreenHeight;
|
---|
515 | bpp = bpp ? bpp :g_CustomVideoModes[iDisplay].BitsPerPlane;
|
---|
516 | }
|
---|
517 | else
|
---|
518 | {
|
---|
519 | /* Use current values for field which weren't read from host. */
|
---|
520 | #ifdef VBOX_XPDM_MINIPORT
|
---|
521 | xres = xres ? xres:pExt->CurrentModeWidth;
|
---|
522 | yres = yres ? yres:pExt->CurrentModeHeight;
|
---|
523 | bpp = bpp ? bpp :pExt->CurrentModeBPP;
|
---|
524 | #else
|
---|
525 | PVBOXWDDM_ALLOC_DATA pAllocData = pExt->aSources[iDisplay].pPrimaryAllocation ?
|
---|
526 | &pExt->aSources[iDisplay].pPrimaryAllocation->AllocData
|
---|
527 | : &pExt->aSources[iDisplay].AllocData;
|
---|
528 | xres = xres ? xres:pAllocData->SurfDesc.width;
|
---|
529 | yres = yres ? yres:pAllocData->SurfDesc.height;
|
---|
530 | bpp = bpp ? bpp :pAllocData->SurfDesc.bpp;
|
---|
531 | #endif
|
---|
532 | }
|
---|
533 |
|
---|
534 | /* Round down width to be a multiple of 8 if necessary */
|
---|
535 | if (!pExt->fAnyX)
|
---|
536 | {
|
---|
537 | xres &= 0xFFF8;
|
---|
538 | }
|
---|
539 |
|
---|
540 | /* We always need bpp to be set */
|
---|
541 | if (!bpp)
|
---|
542 | {
|
---|
543 | bpp=32;
|
---|
544 | }
|
---|
545 |
|
---|
546 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, xres, yres, bpp))
|
---|
547 | {
|
---|
548 | WARN_NOBP(("GUEST does not like special mode %dx%d:%d for display %d", xres, yres, bpp, iDisplay));
|
---|
549 | return FALSE;
|
---|
550 | }
|
---|
551 |
|
---|
552 | /* Check if host likes this mode */
|
---|
553 | if (!VBoxLikesVideoMode(iDisplay, xres, yres, bpp))
|
---|
554 | {
|
---|
555 | WARN_NOBP(("HOST does not like special mode %dx%d:%d for display %d", xres, yres, bpp, iDisplay));
|
---|
556 | return FALSE;
|
---|
557 | }
|
---|
558 |
|
---|
559 | #ifdef VBOX_XPDM_MINIPORT
|
---|
560 | ULONG vramSize = pExt->pPrimary->u.primary.ulMaxFrameBufferSize;
|
---|
561 | #else
|
---|
562 | ULONG vramSize = vboxWddmVramCpuVisibleSegmentSize(pExt);
|
---|
563 | vramSize /= pExt->u.primary.commonInfo.cDisplays;
|
---|
564 | # ifdef VBOX_WDDM_WIN8
|
---|
565 | if (!g_VBoxDisplayOnly)
|
---|
566 | # endif
|
---|
567 | {
|
---|
568 | /* at least two surfaces will be needed: primary & shadow */
|
---|
569 | vramSize /= 2;
|
---|
570 | }
|
---|
571 | #endif
|
---|
572 |
|
---|
573 | /* Check that values are valid and mode fits into VRAM */
|
---|
574 | if (!xres || !yres
|
---|
575 | || !((bpp == 16)
|
---|
576 | #ifdef VBOX_WITH_8BPP_MODES
|
---|
577 | || (bpp == 8)
|
---|
578 | #endif
|
---|
579 | || (bpp == 24)
|
---|
580 | || (bpp == 32)))
|
---|
581 | {
|
---|
582 | LOG(("invalid params for special mode %dx%d:%d", xres, yres, bpp));
|
---|
583 | return FALSE;
|
---|
584 | }
|
---|
585 |
|
---|
586 |
|
---|
587 |
|
---|
588 | if ((xres * yres * (bpp / 8) >= vramSize))
|
---|
589 | {
|
---|
590 | /* Store values of last reported release log message to avoid log flooding. */
|
---|
591 | static uint32_t s_xresNoVRAM=0, s_yresNoVRAM=0, s_bppNoVRAM=0;
|
---|
592 |
|
---|
593 | LOG(("not enough VRAM for video mode %dx%dx%dbpp. Available: %d bytes. Required: more than %d bytes.",
|
---|
594 | xres, yres, bpp, vramSize, xres * yres * (bpp / 8)));
|
---|
595 |
|
---|
596 | s_xresNoVRAM = xres;
|
---|
597 | s_yresNoVRAM = yres;
|
---|
598 | s_bppNoVRAM = bpp;
|
---|
599 |
|
---|
600 | return FALSE;
|
---|
601 | }
|
---|
602 |
|
---|
603 | return TRUE;
|
---|
604 | }
|
---|
605 |
|
---|
606 | /* Checks if there's a pending video mode change hint,
|
---|
607 | * and fills pPendingMode with associated info.
|
---|
608 | * returns TRUE if there's a pending change. Otherwise returns FALSE.
|
---|
609 | */
|
---|
610 | static BOOLEAN
|
---|
611 | VBoxMPCheckPendingVideoMode(PVBOXMP_DEVEXT pExt, PVIDEO_MODE_INFORMATION pPendingMode)
|
---|
612 | {
|
---|
613 | uint32_t xres=0, yres=0, bpp=0, display=0;
|
---|
614 |
|
---|
615 | /* Check if there's a pending display change request for this display */
|
---|
616 | if (VBoxQueryDisplayRequest(&xres, &yres, &bpp, &display) && (xres || yres || bpp))
|
---|
617 | {
|
---|
618 | if (display>RT_ELEMENTS(g_CustomVideoModes))
|
---|
619 | {
|
---|
620 | /*display = RT_ELEMENTS(g_CustomVideoModes) - 1;*/
|
---|
621 | WARN(("VBoxQueryDisplayRequest returned invalid display number %d", display));
|
---|
622 | return FALSE;
|
---|
623 | }
|
---|
624 | }
|
---|
625 | else
|
---|
626 | {
|
---|
627 | LOG(("no pending request"));
|
---|
628 | return FALSE;
|
---|
629 | }
|
---|
630 |
|
---|
631 | /* Correct video mode params and check if host likes it */
|
---|
632 | if (VBoxMPValidateVideoModeParams(pExt, display, xres, yres, bpp))
|
---|
633 | {
|
---|
634 | VBoxFillVidModeInfo(pPendingMode, xres, yres, bpp, display, 0);
|
---|
635 | return TRUE;
|
---|
636 | }
|
---|
637 |
|
---|
638 | return FALSE;
|
---|
639 | }
|
---|
640 |
|
---|
641 | /* Save custom mode info to registry */
|
---|
642 | static void VBoxMPRegSaveModeInfo(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, PVIDEO_MODE_INFORMATION pMode)
|
---|
643 | {
|
---|
644 | VBOXMPCMNREGISTRY Registry;
|
---|
645 | VP_STATUS rc;
|
---|
646 |
|
---|
647 | rc = VBoxMPCmnRegInit(pExt, &Registry);
|
---|
648 | VBOXMP_WARN_VPS(rc);
|
---|
649 |
|
---|
650 | if (iDisplay==0)
|
---|
651 | {
|
---|
652 | /*First name without a suffix*/
|
---|
653 | rc = VBoxMPCmnRegSetDword(Registry, L"CustomXRes", pMode->VisScreenWidth);
|
---|
654 | VBOXMP_WARN_VPS(rc);
|
---|
655 | rc = VBoxMPCmnRegSetDword(Registry, L"CustomYRes", pMode->VisScreenHeight);
|
---|
656 | VBOXMP_WARN_VPS(rc);
|
---|
657 | rc = VBoxMPCmnRegSetDword(Registry, L"CustomBPP", pMode->BitsPerPlane);
|
---|
658 | VBOXMP_WARN_VPS(rc);
|
---|
659 | }
|
---|
660 | else
|
---|
661 | {
|
---|
662 | wchar_t keyname[32];
|
---|
663 | swprintf(keyname, L"CustomXRes%d", iDisplay);
|
---|
664 | rc = VBoxMPCmnRegSetDword(Registry, keyname, pMode->VisScreenWidth);
|
---|
665 | VBOXMP_WARN_VPS(rc);
|
---|
666 | swprintf(keyname, L"CustomYRes%d", iDisplay);
|
---|
667 | rc = VBoxMPCmnRegSetDword(Registry, keyname, pMode->VisScreenHeight);
|
---|
668 | VBOXMP_WARN_VPS(rc);
|
---|
669 | swprintf(keyname, L"CustomBPP%d", iDisplay);
|
---|
670 | rc = VBoxMPCmnRegSetDword(Registry, keyname, pMode->BitsPerPlane);
|
---|
671 | VBOXMP_WARN_VPS(rc);
|
---|
672 | }
|
---|
673 |
|
---|
674 | rc = VBoxMPCmnRegFini(Registry);
|
---|
675 | VBOXMP_WARN_VPS(rc);
|
---|
676 | }
|
---|
677 |
|
---|
678 | #ifdef VBOX_XPDM_MINIPORT
|
---|
679 | VIDEO_MODE_INFORMATION* VBoxMPXpdmCurrentVideoMode(PVBOXMP_DEVEXT pExt)
|
---|
680 | {
|
---|
681 | return VBoxMPCmnGetVideoModeInfo(pExt->CurrentMode - 1);
|
---|
682 | }
|
---|
683 |
|
---|
684 | ULONG VBoxMPXpdmGetVideoModesCount()
|
---|
685 | {
|
---|
686 | return g_NumVideoModes;
|
---|
687 | }
|
---|
688 |
|
---|
689 | /* Makes a table of video modes consisting of:
|
---|
690 | * Default modes
|
---|
691 | * Custom modes manually added to registry
|
---|
692 | * Custom modes for all displays (either from a display change hint or stored in registry)
|
---|
693 | * 2 special modes, for a pending display change for this adapter. See comments below.
|
---|
694 | */
|
---|
695 | void VBoxMPXpdmBuildVideoModesTable(PVBOXMP_DEVEXT pExt)
|
---|
696 | {
|
---|
697 | uint32_t cStandartModes, cCustomModes;
|
---|
698 | BOOLEAN bPending, bHaveSpecial;
|
---|
699 | VIDEO_MODE_INFORMATION specialMode;
|
---|
700 |
|
---|
701 | /* Fill table with standart modes and ones manually added to registry */
|
---|
702 | cStandartModes = VBoxMPFillModesTable(pExt, pExt->iDevice, g_VideoModes, RT_ELEMENTS(g_VideoModes), NULL);
|
---|
703 |
|
---|
704 | /* Add custom modes for all displays to the table */
|
---|
705 | cCustomModes = VBoxCommonFromDeviceExt(pExt)->cDisplays;
|
---|
706 | for (uint32_t i=0; i<cCustomModes; i++)
|
---|
707 | {
|
---|
708 | memcpy(&g_VideoModes[cStandartModes+i], &g_CustomVideoModes[i], sizeof(VIDEO_MODE_INFORMATION));
|
---|
709 | g_VideoModes[cStandartModes+i].ModeIndex = cStandartModes+i+1;
|
---|
710 | }
|
---|
711 |
|
---|
712 | /* Check if host wants us to switch video mode and it's for this adapter */
|
---|
713 | bPending = VBoxMPCheckPendingVideoMode(pExt, &specialMode);
|
---|
714 | bHaveSpecial = bPending && (pExt->iDevice == specialMode.ModeIndex);
|
---|
715 |
|
---|
716 | /* Check the startup case */
|
---|
717 | if (!bHaveSpecial && VBoxMPIsStartingUp(pExt, pExt->iDevice))
|
---|
718 | {
|
---|
719 | uint32_t xres=0, yres=0, bpp=0;
|
---|
720 | /* Check if we could make valid mode from values stored to registry */
|
---|
721 | if (VBoxMPValidateVideoModeParams(pExt, pExt->iDevice, xres, yres, bpp))
|
---|
722 | {
|
---|
723 | VBoxFillVidModeInfo(&specialMode, xres, yres, bpp, 0, 0);
|
---|
724 | bHaveSpecial = TRUE;
|
---|
725 | }
|
---|
726 | }
|
---|
727 |
|
---|
728 | /* Update number of modes */
|
---|
729 | g_NumVideoModes = cStandartModes + cCustomModes;
|
---|
730 |
|
---|
731 | if (!bHaveSpecial)
|
---|
732 | {
|
---|
733 | /* Just add 2 dummy modes to maintain table size. */
|
---|
734 | memcpy(&g_VideoModes[g_NumVideoModes], &g_VideoModes[2], sizeof(VIDEO_MODE_INFORMATION));
|
---|
735 | g_VideoModes[g_NumVideoModes].ModeIndex = g_NumVideoModes+1;
|
---|
736 | g_NumVideoModes++;
|
---|
737 | memcpy(&g_VideoModes[g_NumVideoModes], &g_VideoModes[2], sizeof(VIDEO_MODE_INFORMATION));
|
---|
738 | g_VideoModes[g_NumVideoModes].ModeIndex = g_NumVideoModes+1;
|
---|
739 | g_NumVideoModes++;
|
---|
740 | }
|
---|
741 | else
|
---|
742 | {
|
---|
743 | /* We need to alternate mode index entry for a pending mode change,
|
---|
744 | * else windows will ignore actual mode change call.
|
---|
745 | * Only alternate index if one of mode parameters changed and
|
---|
746 | * regardless of conditions always add 2 entries to the table.
|
---|
747 | */
|
---|
748 | static int s_InvocationCounter=0;
|
---|
749 | BOOLEAN bAlternativeIndex = FALSE;
|
---|
750 |
|
---|
751 | static uint32_t s_Prev_xres=0;
|
---|
752 | static uint32_t s_Prev_yres=0;
|
---|
753 | static uint32_t s_Prev_bpp=0;
|
---|
754 | BOOLEAN bChanged = (s_Prev_xres!=specialMode.VisScreenWidth
|
---|
755 | || s_Prev_yres!=specialMode.VisScreenHeight
|
---|
756 | || s_Prev_bpp!=specialMode.BitsPerPlane);
|
---|
757 | if (bChanged)
|
---|
758 | {
|
---|
759 | s_Prev_xres = specialMode.VisScreenWidth;
|
---|
760 | s_Prev_yres = specialMode.VisScreenHeight;
|
---|
761 | s_Prev_bpp = specialMode.BitsPerPlane;
|
---|
762 | }
|
---|
763 |
|
---|
764 | /* Make sure there's no other mode in the table with same parameters,
|
---|
765 | * because we need windows to pick up a new video mode index otherwise
|
---|
766 | * actual mode change wouldn't happen.
|
---|
767 | */
|
---|
768 | int iFoundIdx;
|
---|
769 | uint32_t uiStart=0;
|
---|
770 |
|
---|
771 | while (0 <= (iFoundIdx = VBoxMPFindVideoMode(&g_VideoModes[uiStart], g_NumVideoModes-uiStart, &specialMode)))
|
---|
772 | {
|
---|
773 | memcpy(&g_VideoModes[uiStart+iFoundIdx], &g_VideoModes[2], sizeof(VIDEO_MODE_INFORMATION));
|
---|
774 | g_VideoModes[uiStart+iFoundIdx].ModeIndex = uiStart+iFoundIdx+1;
|
---|
775 | uiStart += iFoundIdx+1;
|
---|
776 | }
|
---|
777 |
|
---|
778 | /* Check if we need to alternate the index */
|
---|
779 | if (!VBoxMPIsStartingUp(pExt, pExt->iDevice))
|
---|
780 | {
|
---|
781 | if (bChanged)
|
---|
782 | {
|
---|
783 | s_InvocationCounter++;
|
---|
784 | }
|
---|
785 |
|
---|
786 | if (s_InvocationCounter % 2)
|
---|
787 | {
|
---|
788 | bAlternativeIndex = TRUE;
|
---|
789 | memcpy(&g_VideoModes[g_NumVideoModes], &g_VideoModes[2], sizeof(VIDEO_MODE_INFORMATION));
|
---|
790 | g_VideoModes[g_NumVideoModes].ModeIndex = g_NumVideoModes+1;
|
---|
791 | ++g_NumVideoModes;
|
---|
792 | }
|
---|
793 | }
|
---|
794 |
|
---|
795 | LOG(("add special mode[%d] %dx%d:%d for display %d (bChanged=%d, bAlretnativeIndex=%d)",
|
---|
796 | g_NumVideoModes, specialMode.VisScreenWidth, specialMode.VisScreenHeight, specialMode.BitsPerPlane,
|
---|
797 | pExt->iDevice, bChanged, bAlternativeIndex));
|
---|
798 |
|
---|
799 | /* Add special mode to the table
|
---|
800 | * Note: Y offset isn't used for a host-supplied modes
|
---|
801 | */
|
---|
802 | specialMode.ModeIndex = g_NumVideoModes+1;
|
---|
803 | memcpy(&g_VideoModes[g_NumVideoModes], &specialMode, sizeof(VIDEO_MODE_INFORMATION));
|
---|
804 | ++g_NumVideoModes;
|
---|
805 |
|
---|
806 | /* Save special mode in the custom modes table */
|
---|
807 | memcpy(&g_CustomVideoModes[pExt->iDevice], &specialMode, sizeof(VIDEO_MODE_INFORMATION));
|
---|
808 |
|
---|
809 |
|
---|
810 | /* Make sure we've added 2nd mode if necessary to maintain table size */
|
---|
811 | if (VBoxMPIsStartingUp(pExt, pExt->iDevice))
|
---|
812 | {
|
---|
813 | memcpy(&g_VideoModes[g_NumVideoModes], &g_VideoModes[g_NumVideoModes-1], sizeof(VIDEO_MODE_INFORMATION));
|
---|
814 | g_VideoModes[g_NumVideoModes].ModeIndex = g_NumVideoModes+1;
|
---|
815 | ++g_NumVideoModes;
|
---|
816 | }
|
---|
817 | else if (!bAlternativeIndex)
|
---|
818 | {
|
---|
819 | memcpy(&g_VideoModes[g_NumVideoModes], &g_VideoModes[2], sizeof(VIDEO_MODE_INFORMATION));
|
---|
820 | g_VideoModes[g_NumVideoModes].ModeIndex = g_NumVideoModes+1;
|
---|
821 | ++g_NumVideoModes;
|
---|
822 | }
|
---|
823 |
|
---|
824 | /* Save special mode info to registry */
|
---|
825 | VBoxMPRegSaveModeInfo(pExt, pExt->iDevice, &specialMode);
|
---|
826 | }
|
---|
827 |
|
---|
828 | #if defined(LOG_ENABLED)
|
---|
829 | do
|
---|
830 | {
|
---|
831 | LOG(("Filled %d modes", g_NumVideoModes));
|
---|
832 |
|
---|
833 | for (uint32_t i=0; i<g_NumVideoModes; ++i)
|
---|
834 | {
|
---|
835 | LOG(("Mode[%2d]: %4dx%4d:%2d (idx=%d)",
|
---|
836 | i, g_VideoModes[i].VisScreenWidth, g_VideoModes[i].VisScreenHeight,
|
---|
837 | g_VideoModes[i].BitsPerPlane, g_VideoModes[i].ModeIndex));
|
---|
838 | }
|
---|
839 | } while (0);
|
---|
840 | #endif
|
---|
841 | }
|
---|
842 | #endif /*VBOX_XPDM_MINIPORT*/
|
---|
843 |
|
---|
844 | #ifdef VBOX_WDDM_MINIPORT
|
---|
845 | static VBOXWDDM_VIDEOMODES_INFO g_aVBoxVideoModeInfos[VBOX_VIDEO_MAX_SCREENS] = {0};
|
---|
846 |
|
---|
847 | bool VBoxWddmFillMode(PVBOXMP_DEVEXT pExt, uint32_t iDisplay, VIDEO_MODE_INFORMATION *pInfo, D3DDDIFORMAT enmFormat, ULONG w, ULONG h)
|
---|
848 | {
|
---|
849 | switch (enmFormat)
|
---|
850 | {
|
---|
851 | case D3DDDIFMT_A8R8G8B8:
|
---|
852 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 32))
|
---|
853 | {
|
---|
854 | WARN(("unsupported mode info for format(%d)", enmFormat));
|
---|
855 | return false;
|
---|
856 | }
|
---|
857 | VBoxFillVidModeInfo(pInfo, w, h, 32, 0, 0);
|
---|
858 | return true;
|
---|
859 | case D3DDDIFMT_R8G8B8:
|
---|
860 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 24))
|
---|
861 | {
|
---|
862 | WARN(("unsupported mode info for format(%d)", enmFormat));
|
---|
863 | return false;
|
---|
864 | }
|
---|
865 | VBoxFillVidModeInfo(pInfo, w, h, 24, 0, 0);
|
---|
866 | return true;
|
---|
867 | case D3DDDIFMT_R5G6B5:
|
---|
868 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 16))
|
---|
869 | {
|
---|
870 | WARN(("unsupported mode info for format(%d)", enmFormat));
|
---|
871 | return false;
|
---|
872 | }
|
---|
873 | VBoxFillVidModeInfo(pInfo, w, h, 16, 0, 0);
|
---|
874 | return true;
|
---|
875 | case D3DDDIFMT_P8:
|
---|
876 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, iDisplay, w, h, 8))
|
---|
877 | {
|
---|
878 | WARN(("unsupported mode info for format(%d)", enmFormat));
|
---|
879 | return false;
|
---|
880 | }
|
---|
881 | VBoxFillVidModeInfo(pInfo, w, h, 8, 0, 0);
|
---|
882 | return true;
|
---|
883 | default:
|
---|
884 | WARN(("unsupported enmFormat(%d)", enmFormat));
|
---|
885 | AssertBreakpoint();
|
---|
886 | break;
|
---|
887 | }
|
---|
888 |
|
---|
889 | return false;
|
---|
890 | }
|
---|
891 |
|
---|
892 | static void
|
---|
893 | VBoxWddmBuildResolutionTable(PVIDEO_MODE_INFORMATION pModesTable, size_t tableSize, int iPreferredMode,
|
---|
894 | SIZE *pResolutions, uint32_t * pcResolutions, int *piPreferredResolution)
|
---|
895 | {
|
---|
896 | uint32_t cResolutionsArray = *pcResolutions;
|
---|
897 | uint32_t cResolutions = 0;
|
---|
898 |
|
---|
899 | *piPreferredResolution = -1;
|
---|
900 |
|
---|
901 | for (uint32_t i=0; i<tableSize; ++i)
|
---|
902 | {
|
---|
903 | PVIDEO_MODE_INFORMATION pMode = &pModesTable[i];
|
---|
904 | int iResolution = -1;
|
---|
905 |
|
---|
906 | for (uint32_t j=0; j<cResolutions; ++j)
|
---|
907 | {
|
---|
908 | if (pResolutions[j].cx == pMode->VisScreenWidth
|
---|
909 | && pResolutions[j].cy == pMode->VisScreenHeight)
|
---|
910 | {
|
---|
911 | iResolution = j;
|
---|
912 | break;
|
---|
913 | }
|
---|
914 | }
|
---|
915 |
|
---|
916 | if (iResolution < 0)
|
---|
917 | {
|
---|
918 | if (cResolutions == cResolutionsArray)
|
---|
919 | {
|
---|
920 | WARN(("table overflow!"));
|
---|
921 | break;
|
---|
922 | }
|
---|
923 |
|
---|
924 | iResolution = cResolutions;
|
---|
925 | pResolutions[cResolutions].cx = pMode->VisScreenWidth;
|
---|
926 | pResolutions[cResolutions].cy = pMode->VisScreenHeight;
|
---|
927 | ++cResolutions;
|
---|
928 | }
|
---|
929 |
|
---|
930 | Assert(iResolution >= 0);
|
---|
931 | if (i == iPreferredMode)
|
---|
932 | {
|
---|
933 | Assert(*piPreferredResolution == -1);
|
---|
934 | *piPreferredResolution = iResolution;
|
---|
935 | }
|
---|
936 | }
|
---|
937 |
|
---|
938 | *pcResolutions = cResolutions;
|
---|
939 | Assert(*piPreferredResolution >= 0);
|
---|
940 | }
|
---|
941 |
|
---|
942 | static void VBoxWddmBuildResolutionTableForModes(PVBOXWDDM_VIDEOMODES_INFO pModes)
|
---|
943 | {
|
---|
944 | pModes->cResolutions = RT_ELEMENTS(pModes->aResolutions);
|
---|
945 | VBoxWddmBuildResolutionTable(pModes->aModes, pModes->cModes, pModes->iPreferredMode,
|
---|
946 | (SIZE*)((void*)pModes->aResolutions), &pModes->cResolutions, &pModes->iPreferredResolution);
|
---|
947 | Assert(pModes->aResolutions[pModes->iPreferredResolution].cx == pModes->aModes[pModes->iPreferredMode].VisScreenWidth
|
---|
948 | && pModes->aResolutions[pModes->iPreferredResolution].cy == pModes->aModes[pModes->iPreferredMode].VisScreenHeight);
|
---|
949 | }
|
---|
950 |
|
---|
951 | AssertCompile(sizeof (SIZE) == sizeof (D3DKMDT_2DREGION));
|
---|
952 | AssertCompile(RT_OFFSETOF(SIZE, cx) == RT_OFFSETOF(D3DKMDT_2DREGION, cx));
|
---|
953 | AssertCompile(RT_OFFSETOF(SIZE, cy) == RT_OFFSETOF(D3DKMDT_2DREGION, cy));
|
---|
954 | static void
|
---|
955 | VBoxWddmBuildVideoModesInfo(PVBOXMP_DEVEXT pExt, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId,
|
---|
956 | PVBOXWDDM_VIDEOMODES_INFO pModes, VIDEO_MODE_INFORMATION *paAddlModes,
|
---|
957 | UINT cAddlModes)
|
---|
958 | {
|
---|
959 | pModes->cResolutions = RT_ELEMENTS(pModes->aResolutions);
|
---|
960 |
|
---|
961 | /* Add default modes and ones read from registry. */
|
---|
962 | pModes->cModes = VBoxMPFillModesTable(pExt, VidPnTargetId, pModes->aModes, RT_ELEMENTS(pModes->aModes), &pModes->iPreferredMode);
|
---|
963 | Assert(pModes->cModes<=RT_ELEMENTS(pModes->aModes));
|
---|
964 |
|
---|
965 | /* Check if there's a pending display change request for this adapter */
|
---|
966 | VIDEO_MODE_INFORMATION specialMode;
|
---|
967 | if (VBoxMPCheckPendingVideoMode(pExt, &specialMode) && (specialMode.ModeIndex==VidPnTargetId))
|
---|
968 | {
|
---|
969 | /*Minor hack, ModeIndex!=0 Means this mode has been validated already and not just read from registry */
|
---|
970 | specialMode.ModeIndex = 1;
|
---|
971 | memcpy(&g_CustomVideoModes[VidPnTargetId], &specialMode, sizeof(VIDEO_MODE_INFORMATION));
|
---|
972 |
|
---|
973 | /* Save mode to registry */
|
---|
974 | VBoxMPRegSaveModeInfo(pExt, VidPnTargetId, &specialMode);
|
---|
975 | }
|
---|
976 |
|
---|
977 | /* Validate the mode which has been read from registry */
|
---|
978 | if (!g_CustomVideoModes[VidPnTargetId].ModeIndex)
|
---|
979 | {
|
---|
980 | uint32_t xres, yres, bpp;
|
---|
981 |
|
---|
982 | xres = g_CustomVideoModes[VidPnTargetId].VisScreenWidth;
|
---|
983 | yres = g_CustomVideoModes[VidPnTargetId].VisScreenHeight;
|
---|
984 | bpp = g_CustomVideoModes[VidPnTargetId].BitsPerPlane;
|
---|
985 |
|
---|
986 | if (VBoxMPValidateVideoModeParams(pExt, VidPnTargetId, xres, yres, bpp))
|
---|
987 | {
|
---|
988 | VBoxFillVidModeInfo(&g_CustomVideoModes[VidPnTargetId], xres, yres, bpp, 1/*index*/, 0);
|
---|
989 | Assert(g_CustomVideoModes[VidPnTargetId].ModeIndex == 1);
|
---|
990 | }
|
---|
991 | }
|
---|
992 |
|
---|
993 | /* Add custom mode to the table */
|
---|
994 | if (g_CustomVideoModes[VidPnTargetId].ModeIndex)
|
---|
995 | {
|
---|
996 | if (RT_ELEMENTS(pModes->aModes) > pModes->cModes)
|
---|
997 | {
|
---|
998 | g_CustomVideoModes[VidPnTargetId].ModeIndex = pModes->cModes;
|
---|
999 | pModes->aModes[pModes->cModes] = g_CustomVideoModes[VidPnTargetId];
|
---|
1000 |
|
---|
1001 | /* Check if we already have this mode in the table */
|
---|
1002 | int foundIdx;
|
---|
1003 | if ((foundIdx=VBoxMPFindVideoMode(pModes->aModes, pModes->cModes, &pModes->aModes[pModes->cModes]))>=0)
|
---|
1004 | {
|
---|
1005 | pModes->iPreferredMode = foundIdx;
|
---|
1006 | }
|
---|
1007 | else
|
---|
1008 | {
|
---|
1009 | pModes->iPreferredMode = pModes->cModes;
|
---|
1010 | ++pModes->cModes;
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 | /* Add other bpp modes for this custom resolution */
|
---|
1014 | #ifdef VBOX_WITH_8BPP_MODES
|
---|
1015 | UINT bpp=8;
|
---|
1016 | #else
|
---|
1017 | UINT bpp=16;
|
---|
1018 | #endif
|
---|
1019 | for (; bpp<=32; bpp+=8)
|
---|
1020 | {
|
---|
1021 | if (RT_ELEMENTS(pModes->aModes) == pModes->cModes)
|
---|
1022 | {
|
---|
1023 | WARN(("table full, can't add other bpp for specail mode!"));
|
---|
1024 | #ifdef DEBUG_misha
|
---|
1025 | /* this is definitely something we do not expect */
|
---|
1026 | AssertFailed();
|
---|
1027 | #endif
|
---|
1028 | break;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | AssertRelease(RT_ELEMENTS(pModes->aModes) > pModes->cModes); /* if not - the driver state is screwed up, @todo: better do KeBugCheckEx here */
|
---|
1032 |
|
---|
1033 | if (pModes->aModes[pModes->iPreferredMode].BitsPerPlane == bpp)
|
---|
1034 | continue;
|
---|
1035 |
|
---|
1036 | if (!VBoxMPValidateVideoModeParamsGuest(pExt, VidPnTargetId,
|
---|
1037 | pModes->aModes[pModes->iPreferredMode].VisScreenWidth,
|
---|
1038 | pModes->aModes[pModes->iPreferredMode].VisScreenHeight,
|
---|
1039 | bpp))
|
---|
1040 | continue;
|
---|
1041 |
|
---|
1042 | VBoxFillVidModeInfo(&pModes->aModes[pModes->cModes],
|
---|
1043 | pModes->aModes[pModes->iPreferredMode].VisScreenWidth,
|
---|
1044 | pModes->aModes[pModes->iPreferredMode].VisScreenHeight,
|
---|
1045 | bpp, pModes->cModes, 0);
|
---|
1046 | if (VBoxMPFindVideoMode(pModes->aModes, pModes->cModes, &pModes->aModes[pModes->cModes]) < 0)
|
---|
1047 | {
|
---|
1048 | ++pModes->cModes;
|
---|
1049 | }
|
---|
1050 | }
|
---|
1051 | }
|
---|
1052 | else
|
---|
1053 | {
|
---|
1054 | AssertRelease(RT_ELEMENTS(pModes->aModes) == pModes->cModes); /* if not - the driver state is screwed up, @todo: better do KeBugCheckEx here */
|
---|
1055 | WARN(("table full, can't add video mode for a host request!"));
|
---|
1056 | #ifdef DEBUG_misha
|
---|
1057 | /* this is definitely something we do not expect */
|
---|
1058 | AssertFailed();
|
---|
1059 | #endif
|
---|
1060 | }
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | /* Check and Add additional modes passed in paAddlModes */
|
---|
1064 | for (UINT i=0; i<cAddlModes; ++i)
|
---|
1065 | {
|
---|
1066 | if (RT_ELEMENTS(pModes->aModes) == pModes->cModes)
|
---|
1067 | {
|
---|
1068 | WARN(("table full, can't add addl modes!"));
|
---|
1069 | #ifdef DEBUG_misha
|
---|
1070 | /* this is definitely something we do not expect */
|
---|
1071 | AssertFailed();
|
---|
1072 | #endif
|
---|
1073 | break;
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | AssertRelease(RT_ELEMENTS(pModes->aModes) > pModes->cModes); /* if not - the driver state is screwed up, @todo: better do KeBugCheckEx here */
|
---|
1077 |
|
---|
1078 | if (!pExt->fAnyX)
|
---|
1079 | {
|
---|
1080 | paAddlModes[i].VisScreenWidth &= 0xFFF8;
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | if (VBoxLikesVideoMode(VidPnTargetId, paAddlModes[i].VisScreenWidth, paAddlModes[i].VisScreenHeight, paAddlModes[i].BitsPerPlane))
|
---|
1084 | {
|
---|
1085 | int foundIdx;
|
---|
1086 | if ((foundIdx=VBoxMPFindVideoMode(pModes->aModes, pModes->cModes, &paAddlModes[i]))>=0)
|
---|
1087 | {
|
---|
1088 | pModes->iPreferredMode = foundIdx;
|
---|
1089 | }
|
---|
1090 | else
|
---|
1091 | {
|
---|
1092 | memcpy(&pModes->aModes[pModes->cModes], &paAddlModes[i], sizeof(VIDEO_MODE_INFORMATION));
|
---|
1093 | pModes->aModes[pModes->cModes].ModeIndex = pModes->cModes;
|
---|
1094 | ++pModes->cModes;
|
---|
1095 | }
|
---|
1096 | }
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | /* Build resolution table */
|
---|
1100 | VBoxWddmBuildResolutionTableForModes(pModes);
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | void VBoxWddmInvalidateVideoModesInfo(PVBOXMP_DEVEXT pExt, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId)
|
---|
1104 | {
|
---|
1105 | if (VidPnTargetId != D3DDDI_ID_ALL)
|
---|
1106 | {
|
---|
1107 | if (VidPnTargetId >= RT_ELEMENTS(g_aVBoxVideoModeInfos))
|
---|
1108 | {
|
---|
1109 | WARN(("VidPnTargetId (%d) must be less than (%d)", VidPnTargetId, RT_ELEMENTS(g_aVBoxVideoModeInfos)));
|
---|
1110 | return;
|
---|
1111 | }
|
---|
1112 | LOG(("invalidating videomede info for screen %d", VidPnTargetId));
|
---|
1113 | g_aVBoxVideoModeInfos[VidPnTargetId].cModes = 0;
|
---|
1114 | return;
|
---|
1115 | }
|
---|
1116 |
|
---|
1117 | LOG(("invalidating ALL videomede infos"));
|
---|
1118 |
|
---|
1119 | for (UINT i = 0; i < RT_ELEMENTS(g_aVBoxVideoModeInfos); ++i)
|
---|
1120 | {
|
---|
1121 | g_aVBoxVideoModeInfos[i].cModes = 0;
|
---|
1122 | }
|
---|
1123 | }
|
---|
1124 |
|
---|
1125 | void VBoxWddmInvalidateAllVideoModesInfos(PVBOXMP_DEVEXT pExt)
|
---|
1126 | {
|
---|
1127 | VBoxWddmInvalidateVideoModesInfo(pExt, D3DDDI_ID_ALL);
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | PVBOXWDDM_VIDEOMODES_INFO VBoxWddmUpdateVideoModesInfoByMask(PVBOXMP_DEVEXT pExt, uint8_t *pScreenIdMask)
|
---|
1131 | {
|
---|
1132 | for (int i = 0; i < VBoxCommonFromDeviceExt(pExt)->cDisplays; ++i)
|
---|
1133 | {
|
---|
1134 | if (ASMBitTest(pScreenIdMask, i))
|
---|
1135 | VBoxWddmInvalidateVideoModesInfo(pExt, i);
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | /* ensure we have all the rest populated */
|
---|
1139 | VBoxWddmGetAllVideoModesInfos(pExt);
|
---|
1140 | return g_aVBoxVideoModeInfos;
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | PVBOXWDDM_VIDEOMODES_INFO VBoxWddmUpdateAllVideoModesInfos(PVBOXMP_DEVEXT pExt)
|
---|
1144 | {
|
---|
1145 | VBoxWddmInvalidateAllVideoModesInfos(pExt);
|
---|
1146 |
|
---|
1147 | /* ensure we have all the rest populated */
|
---|
1148 | VBoxWddmGetAllVideoModesInfos(pExt);
|
---|
1149 | return g_aVBoxVideoModeInfos;
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 | void VBoxWddmAdjustMode(PVBOXMP_DEVEXT pExt, PVBOXWDDM_ADJUSTVIDEOMODE pMode)
|
---|
1153 | {
|
---|
1154 | pMode->fFlags = 0;
|
---|
1155 |
|
---|
1156 | if (pMode->Mode.Id >= (UINT)VBoxCommonFromDeviceExt(pExt)->cDisplays)
|
---|
1157 | {
|
---|
1158 | WARN(("invalid screen id (%d)", pMode->Mode.Id));
|
---|
1159 | pMode->fFlags = VBOXWDDM_ADJUSTVIDEOMODE_F_INVALISCREENID;
|
---|
1160 | return;
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | PVBOXWDDM_TARGET pTarget = &pExt->aTargets[pMode->Mode.Id];
|
---|
1164 | /* @todo: this info should go from the target actually */
|
---|
1165 | PVBOXWDDM_SOURCE pSource = &pExt->aSources[pMode->Mode.Id];
|
---|
1166 | if (pTarget->HeightVisible /* <- active */
|
---|
1167 | && pSource->AllocData.SurfDesc.width == pMode->Mode.Width
|
---|
1168 | && pSource->AllocData.SurfDesc.height == pMode->Mode.Height
|
---|
1169 | && pSource->AllocData.SurfDesc.bpp == pMode->Mode.BitsPerPixel)
|
---|
1170 | {
|
---|
1171 | pMode->fFlags = VBOXWDDM_ADJUSTVIDEOMODE_F_CURRENT;
|
---|
1172 | return;
|
---|
1173 | }
|
---|
1174 |
|
---|
1175 | UINT newWidth = pMode->Mode.Width;
|
---|
1176 | UINT newHeight = pMode->Mode.Height;
|
---|
1177 | UINT newBpp = pMode->Mode.BitsPerPixel;
|
---|
1178 |
|
---|
1179 | if (!VBoxMPValidateVideoModeParams(pExt, pMode->Mode.Id, newWidth, newHeight, newBpp))
|
---|
1180 | {
|
---|
1181 | PVBOXWDDM_SOURCE pSource = &pExt->aSources[pMode->Mode.Id];
|
---|
1182 | pMode->fFlags = VBOXWDDM_ADJUSTVIDEOMODE_F_UNSUPPORTED;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | if (pMode->Mode.Width != newWidth
|
---|
1186 | || pMode->Mode.Height != newHeight
|
---|
1187 | || pMode->Mode.BitsPerPixel != newBpp)
|
---|
1188 | {
|
---|
1189 | pMode->fFlags |= VBOXWDDM_ADJUSTVIDEOMODE_F_ADJUSTED;
|
---|
1190 | pMode->Mode.Width = newWidth;
|
---|
1191 | pMode->Mode.Height = newHeight;
|
---|
1192 | pMode->Mode.BitsPerPixel = newBpp;
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | if (pTarget->HeightVisible /* <- active */
|
---|
1196 | && pSource->AllocData.SurfDesc.width == pMode->Mode.Width
|
---|
1197 | && pSource->AllocData.SurfDesc.height == pMode->Mode.Height
|
---|
1198 | && pSource->AllocData.SurfDesc.bpp == pMode->Mode.BitsPerPixel)
|
---|
1199 | {
|
---|
1200 | pMode->fFlags |= VBOXWDDM_ADJUSTVIDEOMODE_F_CURRENT;
|
---|
1201 | if (pMode->fFlags & VBOXWDDM_ADJUSTVIDEOMODE_F_UNSUPPORTED)
|
---|
1202 | {
|
---|
1203 | WARN(("current mode is reported as unsupported, cleaning the unsupported flag"));
|
---|
1204 | pMode->fFlags &= ~VBOXWDDM_ADJUSTVIDEOMODE_F_UNSUPPORTED;
|
---|
1205 | }
|
---|
1206 | }
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 | void VBoxWddmAdjustModes(PVBOXMP_DEVEXT pExt, uint32_t cModes, PVBOXWDDM_ADJUSTVIDEOMODE aModes)
|
---|
1210 | {
|
---|
1211 | for (UINT i = 0; i < cModes; ++i)
|
---|
1212 | {
|
---|
1213 | PVBOXWDDM_ADJUSTVIDEOMODE pMode = &aModes[i];
|
---|
1214 | VBoxWddmAdjustMode(pExt, pMode);
|
---|
1215 | }
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | NTSTATUS VBoxWddmGetModesForResolution(VIDEO_MODE_INFORMATION *pAllModes, uint32_t cAllModes, int iSearchPreferredMode,
|
---|
1219 | const D3DKMDT_2DREGION *pResolution, VIDEO_MODE_INFORMATION * pModes, uint32_t cModes, uint32_t *pcModes, int32_t *piPreferrableMode)
|
---|
1220 | {
|
---|
1221 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
1222 | uint32_t cFound = 0;
|
---|
1223 | int iFoundPreferrableMode = -1;
|
---|
1224 | for (uint32_t i = 0; i < cAllModes; ++i)
|
---|
1225 | {
|
---|
1226 | VIDEO_MODE_INFORMATION *pCur = &pAllModes[i];
|
---|
1227 | if (pResolution->cx == pCur->VisScreenWidth
|
---|
1228 | && pResolution->cy == pCur->VisScreenHeight)
|
---|
1229 | {
|
---|
1230 | if (pModes && cModes > cFound)
|
---|
1231 | memcpy(&pModes[cFound], pCur, sizeof(VIDEO_MODE_INFORMATION));
|
---|
1232 | else
|
---|
1233 | Status = STATUS_BUFFER_TOO_SMALL;
|
---|
1234 |
|
---|
1235 | if (i == iSearchPreferredMode)
|
---|
1236 | iFoundPreferrableMode = cFound;
|
---|
1237 |
|
---|
1238 | ++cFound;
|
---|
1239 | }
|
---|
1240 | }
|
---|
1241 |
|
---|
1242 | Assert(iFoundPreferrableMode < 0 || cFound > (uint32_t)iFoundPreferrableMode);
|
---|
1243 |
|
---|
1244 | *pcModes = cFound;
|
---|
1245 | if (piPreferrableMode)
|
---|
1246 | *piPreferrableMode = iFoundPreferrableMode;
|
---|
1247 |
|
---|
1248 | return Status;
|
---|
1249 | }
|
---|
1250 |
|
---|
1251 | static PVBOXWDDM_VIDEOMODES_INFO vboxWddmGetVideoModesInfoInternal(PVBOXMP_DEVEXT pExt, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId)
|
---|
1252 | {
|
---|
1253 | Assert(VidPnTargetId < (D3DDDI_VIDEO_PRESENT_TARGET_ID)VBoxCommonFromDeviceExt(pExt)->cDisplays);
|
---|
1254 | if (VidPnTargetId >= (D3DDDI_VIDEO_PRESENT_TARGET_ID)VBoxCommonFromDeviceExt(pExt)->cDisplays)
|
---|
1255 | {
|
---|
1256 | WARN(("video mode info for invalid screen (%d) requested", VidPnTargetId));
|
---|
1257 | return NULL;
|
---|
1258 | }
|
---|
1259 |
|
---|
1260 | PVBOXWDDM_VIDEOMODES_INFO pInfo = &g_aVBoxVideoModeInfos[VidPnTargetId];
|
---|
1261 |
|
---|
1262 | if (!pInfo->cModes)
|
---|
1263 | {
|
---|
1264 | VBoxWddmBuildVideoModesInfo(pExt, VidPnTargetId, pInfo, NULL, 0);
|
---|
1265 | Assert(pInfo->cModes);
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | return pInfo;
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | static VOID vboxWddmAddVideoModes(PVBOXMP_DEVEXT pExt, PVBOXWDDM_VIDEOMODES_INFO pDstInfo, PVBOXWDDM_VIDEOMODES_INFO pSrcInfo)
|
---|
1272 | {
|
---|
1273 | for (int i = 0; i < (int)pSrcInfo->cModes; ++i)
|
---|
1274 | {
|
---|
1275 | int foundIdx = VBoxMPFindVideoMode(pDstInfo->aModes, pDstInfo->cModes, &pSrcInfo->aModes[i]);
|
---|
1276 | if (foundIdx >= 0)
|
---|
1277 | continue;
|
---|
1278 |
|
---|
1279 | Assert(0);
|
---|
1280 | pDstInfo->aModes[pDstInfo->cModes] = pSrcInfo->aModes[i];
|
---|
1281 | ++pDstInfo->cModes;
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | VBoxWddmBuildResolutionTableForModes(pDstInfo);
|
---|
1285 | }
|
---|
1286 |
|
---|
1287 | PVBOXWDDM_VIDEOMODES_INFO VBoxWddmGetAllVideoModesInfos(PVBOXMP_DEVEXT pExt)
|
---|
1288 | {
|
---|
1289 | /* ensure all modes are initialized */
|
---|
1290 | for (int i = 0; i < VBoxCommonFromDeviceExt(pExt)->cDisplays; ++i)
|
---|
1291 | {
|
---|
1292 | vboxWddmGetVideoModesInfoInternal(pExt, (D3DDDI_VIDEO_PRESENT_TARGET_ID)i);
|
---|
1293 | }
|
---|
1294 |
|
---|
1295 | return g_aVBoxVideoModeInfos;
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | PVBOXWDDM_VIDEOMODES_INFO VBoxWddmGetVideoModesInfo(PVBOXMP_DEVEXT pExt, D3DDDI_VIDEO_PRESENT_TARGET_ID VidPnTargetId)
|
---|
1299 | {
|
---|
1300 | return &VBoxWddmGetAllVideoModesInfos(pExt)[VidPnTargetId];
|
---|
1301 | }
|
---|
1302 |
|
---|
1303 | #endif /*VBOX_WDDM_MINIPORT*/
|
---|