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