1 | /* $Id: VBoxDispDriver.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox XPDM Display driver interface functions
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include "VBoxDisp.h"
|
---|
19 | #include "VBoxDispMini.h"
|
---|
20 | #include "VBoxDispDDraw.h"
|
---|
21 | #include <iprt/initterm.h>
|
---|
22 |
|
---|
23 | /* Engine version we're running on, set in DrvEnableDriver */
|
---|
24 | static ULONG g_EngineVersionDDI = DDI_DRIVER_VERSION_NT4;
|
---|
25 |
|
---|
26 | /* Callback function supported by our driver, stored in index/address pairs (see winddi.h) */
|
---|
27 | /* NT4 version */
|
---|
28 | static DRVFN g_aDrvFnTableNT4[] =
|
---|
29 | {
|
---|
30 | /* Required functions */
|
---|
31 | {INDEX_DrvGetModes, (PFN) VBoxDispDrvGetModes },
|
---|
32 | {INDEX_DrvEnablePDEV, (PFN) VBoxDispDrvEnablePDEV },
|
---|
33 | {INDEX_DrvCompletePDEV, (PFN) VBoxDispDrvCompletePDEV },
|
---|
34 | {INDEX_DrvDisablePDEV, (PFN) VBoxDispDrvDisablePDEV },
|
---|
35 | {INDEX_DrvEnableSurface, (PFN) VBoxDispDrvEnableSurface },
|
---|
36 | {INDEX_DrvDisableSurface, (PFN) VBoxDispDrvDisableSurface },
|
---|
37 | {INDEX_DrvAssertMode, (PFN) VBoxDispDrvAssertMode },
|
---|
38 | /* Drawing commands */
|
---|
39 | {INDEX_DrvLineTo, (PFN) VBoxDispDrvLineTo },
|
---|
40 | {INDEX_DrvStrokePath, (PFN) VBoxDispDrvStrokePath },
|
---|
41 | {INDEX_DrvFillPath, (PFN) VBoxDispDrvFillPath },
|
---|
42 | {INDEX_DrvPaint, (PFN) VBoxDispDrvPaint },
|
---|
43 | {INDEX_DrvTextOut, (PFN) VBoxDispDrvTextOut },
|
---|
44 | {INDEX_DrvSaveScreenBits, (PFN) VBoxDispDrvSaveScreenBits },
|
---|
45 | /* BitBlt's*/
|
---|
46 | {INDEX_DrvBitBlt, (PFN) VBoxDispDrvBitBlt },
|
---|
47 | {INDEX_DrvStretchBlt, (PFN) VBoxDispDrvStretchBlt, },
|
---|
48 | {INDEX_DrvCopyBits, (PFN) VBoxDispDrvCopyBits },
|
---|
49 | /* Brush related */
|
---|
50 | {INDEX_DrvRealizeBrush, (PFN) VBoxDispDrvRealizeBrush },
|
---|
51 | {INDEX_DrvDitherColor, (PFN) VBoxDispDrvDitherColor },
|
---|
52 | /* Pointer related */
|
---|
53 | {INDEX_DrvSetPointerShape, (PFN) VBoxDispDrvSetPointerShape },
|
---|
54 | {INDEX_DrvMovePointer, (PFN) VBoxDispDrvMovePointer },
|
---|
55 | /* Misc */
|
---|
56 | {INDEX_DrvDisableDriver, (PFN) VBoxDispDrvDisableDriver },
|
---|
57 | {INDEX_DrvSetPalette, (PFN) VBoxDispDrvSetPalette },
|
---|
58 | {INDEX_DrvEscape, (PFN) VBoxDispDrvEscape },
|
---|
59 | #ifdef VBOX_WITH_DDRAW
|
---|
60 | {INDEX_DrvGetDirectDrawInfo, (PFN) VBoxDispDrvGetDirectDrawInfo},
|
---|
61 | {INDEX_DrvEnableDirectDraw, (PFN) VBoxDispDrvEnableDirectDraw },
|
---|
62 | {INDEX_DrvDisableDirectDraw, (PFN) VBoxDispDrvDisableDirectDraw},
|
---|
63 | #endif
|
---|
64 | /* g_aDrvFnTableNT4, NT4 specific */
|
---|
65 | {INDEX_DrvOffset, (PFN) VBoxDispDrvOffset } /*Obsolete*/
|
---|
66 | };
|
---|
67 |
|
---|
68 | /* WIN2K+ version */
|
---|
69 | static DRVFN g_aDrvFnTableNT5[] =
|
---|
70 | {
|
---|
71 | /* Required functions */
|
---|
72 | {INDEX_DrvGetModes, (PFN) VBoxDispDrvGetModes },
|
---|
73 | {INDEX_DrvEnablePDEV, (PFN) VBoxDispDrvEnablePDEV },
|
---|
74 | {INDEX_DrvCompletePDEV, (PFN) VBoxDispDrvCompletePDEV },
|
---|
75 | {INDEX_DrvDisablePDEV, (PFN) VBoxDispDrvDisablePDEV },
|
---|
76 | {INDEX_DrvEnableSurface, (PFN) VBoxDispDrvEnableSurface },
|
---|
77 | {INDEX_DrvDisableSurface, (PFN) VBoxDispDrvDisableSurface },
|
---|
78 | {INDEX_DrvAssertMode, (PFN) VBoxDispDrvAssertMode },
|
---|
79 | /* Drawing commands */
|
---|
80 | {INDEX_DrvLineTo, (PFN) VBoxDispDrvLineTo },
|
---|
81 | {INDEX_DrvStrokePath, (PFN) VBoxDispDrvStrokePath },
|
---|
82 | {INDEX_DrvFillPath, (PFN) VBoxDispDrvFillPath },
|
---|
83 | {INDEX_DrvPaint, (PFN) VBoxDispDrvPaint },
|
---|
84 | {INDEX_DrvTextOut, (PFN) VBoxDispDrvTextOut },
|
---|
85 | {INDEX_DrvSaveScreenBits, (PFN) VBoxDispDrvSaveScreenBits },
|
---|
86 | /* BitBlt's*/
|
---|
87 | {INDEX_DrvBitBlt, (PFN) VBoxDispDrvBitBlt },
|
---|
88 | {INDEX_DrvStretchBlt, (PFN) VBoxDispDrvStretchBlt, },
|
---|
89 | {INDEX_DrvCopyBits, (PFN) VBoxDispDrvCopyBits },
|
---|
90 | /* Brush related */
|
---|
91 | {INDEX_DrvRealizeBrush, (PFN) VBoxDispDrvRealizeBrush },
|
---|
92 | {INDEX_DrvDitherColor, (PFN) VBoxDispDrvDitherColor },
|
---|
93 | /* Pointer related */
|
---|
94 | {INDEX_DrvSetPointerShape, (PFN) VBoxDispDrvSetPointerShape },
|
---|
95 | {INDEX_DrvMovePointer, (PFN) VBoxDispDrvMovePointer },
|
---|
96 | /* Misc */
|
---|
97 | {INDEX_DrvDisableDriver, (PFN) VBoxDispDrvDisableDriver },
|
---|
98 | {INDEX_DrvSetPalette, (PFN) VBoxDispDrvSetPalette },
|
---|
99 | {INDEX_DrvEscape, (PFN) VBoxDispDrvEscape },
|
---|
100 | #ifdef VBOX_WITH_DDRAW
|
---|
101 | {INDEX_DrvGetDirectDrawInfo, (PFN) VBoxDispDrvGetDirectDrawInfo},
|
---|
102 | {INDEX_DrvEnableDirectDraw, (PFN) VBoxDispDrvEnableDirectDraw },
|
---|
103 | {INDEX_DrvDisableDirectDraw, (PFN) VBoxDispDrvDisableDirectDraw},
|
---|
104 | #endif
|
---|
105 | /* g_aDrvFnTableNT5, NT5 specific */
|
---|
106 | {INDEX_DrvNotify, (PFN) VBoxDispDrvNotify },
|
---|
107 | #ifdef VBOX_WITH_DDRAW
|
---|
108 | {INDEX_DrvDeriveSurface, (PFN) VBoxDispDrvDeriveSurface }
|
---|
109 | #endif
|
---|
110 | };
|
---|
111 |
|
---|
112 | #ifdef VBOX_WITH_CROGL
|
---|
113 | typedef struct
|
---|
114 | {
|
---|
115 | DWORD dwVersion;
|
---|
116 | DWORD dwDriverVersion;
|
---|
117 | WCHAR szDriverName[256];
|
---|
118 | } OPENGL_INFO, *POPENGL_INFO;
|
---|
119 | #endif
|
---|
120 |
|
---|
121 | RT_C_DECLS_BEGIN
|
---|
122 | ULONG __cdecl DbgPrint(PCH pszFormat, ...)
|
---|
123 | {
|
---|
124 | va_list args;
|
---|
125 | va_start(args, pszFormat);
|
---|
126 | RTLogBackdoorPrintfV(pszFormat, args);
|
---|
127 | va_end(args);
|
---|
128 |
|
---|
129 | return 0;
|
---|
130 | }
|
---|
131 | RT_C_DECLS_END
|
---|
132 |
|
---|
133 | VOID _wcsncpy(WCHAR *pwcd, WCHAR *pwcs, ULONG dstsize)
|
---|
134 | {
|
---|
135 | ULONG cnt=0;
|
---|
136 |
|
---|
137 | while (*pwcs!=*L"")
|
---|
138 | {
|
---|
139 | if (cnt>=dstsize)
|
---|
140 | {
|
---|
141 | break;
|
---|
142 | }
|
---|
143 |
|
---|
144 | *pwcd = *pwcs;
|
---|
145 |
|
---|
146 | pwcs++;
|
---|
147 | pwcd++;
|
---|
148 | cnt ++;
|
---|
149 | }
|
---|
150 |
|
---|
151 | if (cnt<dstsize)
|
---|
152 | {
|
---|
153 | memset(pwcd, 0, (dstsize-cnt) * sizeof(WCHAR));
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | #define VBOXDISPSETCIEC(_ciec, _x, _y, _lum) \
|
---|
158 | do { \
|
---|
159 | _ciec.x = _x; \
|
---|
160 | _ciec.y = _y; \
|
---|
161 | _ciec.Y = _lum; \
|
---|
162 | } while (0)
|
---|
163 |
|
---|
164 |
|
---|
165 | #define VBOXDISPMAKELOGFONTW(_font, _w, _h, _weight, _clip, _quality, _pitch, _name) \
|
---|
166 | do { \
|
---|
167 | _font.lfHeight = _w; \
|
---|
168 | _font.lfWidth = _h; \
|
---|
169 | _font.lfEscapement = 0; \
|
---|
170 | _font.lfOrientation = 0; \
|
---|
171 | _font.lfWeight = _weight; \
|
---|
172 | _font.lfItalic = 0; \
|
---|
173 | _font.lfUnderline = 0; \
|
---|
174 | _font.lfStrikeOut = 0; \
|
---|
175 | _font.lfCharSet = ANSI_CHARSET; \
|
---|
176 | _font.lfOutPrecision = OUT_DEFAULT_PRECIS; \
|
---|
177 | _font.lfClipPrecision = _clip; \
|
---|
178 | _font.lfQuality = _quality; \
|
---|
179 | _font.lfPitchAndFamily = (_pitch) | FF_DONTCARE; \
|
---|
180 | memset(_font.lfFaceName, 0, sizeof(_font.lfFaceName)); \
|
---|
181 | memcpy(_font.lfFaceName, _name, sizeof(_name)); \
|
---|
182 | } while (0)
|
---|
183 |
|
---|
184 | static int VBoxDispInitDevice(PVBOXDISPDEV pDev, DEVMODEW *pdm, GDIINFO *pGdiInfo, DEVINFO *pDevInfo)
|
---|
185 | {
|
---|
186 | VIDEO_MODE_INFORMATION *pModesTable = NULL, selectedMode;
|
---|
187 | ULONG cModes, i=0;
|
---|
188 | int rc;
|
---|
189 |
|
---|
190 | LOGF_ENTER();
|
---|
191 |
|
---|
192 | memset(&selectedMode, 0, sizeof(VIDEO_MODE_INFORMATION));
|
---|
193 |
|
---|
194 | /* Get a list of supported modes by both miniport and display driver */
|
---|
195 | rc = VBoxDispMPGetVideoModes(pDev->hDriver, &pModesTable, &cModes);
|
---|
196 | VBOX_WARNRC_RETRC(rc);
|
---|
197 |
|
---|
198 | /* Check if requested mode is available in the list */
|
---|
199 | if ((g_EngineVersionDDI < DDI_DRIVER_VERSION_NT5)
|
---|
200 | && (pdm->dmBitsPerPel==0)
|
---|
201 | && (pdm->dmPelsWidth==0)
|
---|
202 | && (pdm->dmPelsHeight==0)
|
---|
203 | && (pdm->dmDisplayFrequency==0))
|
---|
204 | {
|
---|
205 | /* Special case for NT4, just return default(first) mode */
|
---|
206 | memcpy(&selectedMode, &pModesTable[0], sizeof(VIDEO_MODE_INFORMATION));
|
---|
207 | }
|
---|
208 | else
|
---|
209 | {
|
---|
210 | for (; i<cModes; ++i)
|
---|
211 | {
|
---|
212 | if ((pdm->dmBitsPerPel == (pModesTable[i].BitsPerPlane * pModesTable[i].NumberOfPlanes))
|
---|
213 | && (pdm->dmPelsWidth == pModesTable[i].VisScreenWidth)
|
---|
214 | && (pdm->dmPelsHeight == pModesTable[i].VisScreenHeight)
|
---|
215 | && (pdm->dmDisplayFrequency == pModesTable[i].Frequency))
|
---|
216 | {
|
---|
217 | memcpy(&selectedMode, &pModesTable[i], sizeof(VIDEO_MODE_INFORMATION));
|
---|
218 | break;
|
---|
219 | }
|
---|
220 | }
|
---|
221 | }
|
---|
222 | EngFreeMem(pModesTable);
|
---|
223 |
|
---|
224 | if (i>=cModes)
|
---|
225 | {
|
---|
226 | WARN(("can't support requested mode %dx%d@%dbpp(%dHz)!",
|
---|
227 | pdm->dmPelsWidth, pdm->dmPelsHeight, pdm->dmBitsPerPel, pdm->dmDisplayFrequency));
|
---|
228 | return VERR_NOT_SUPPORTED;
|
---|
229 | }
|
---|
230 |
|
---|
231 | LOG(("match for requested mode %dx%d@%dbpp(%dHz)",
|
---|
232 | selectedMode.VisScreenWidth, selectedMode.VisScreenHeight, selectedMode.BitsPerPlane, selectedMode.Frequency));
|
---|
233 |
|
---|
234 | /* Update private device info with mode information */
|
---|
235 | pDev->mode.ulIndex = selectedMode.ModeIndex;
|
---|
236 | pDev->mode.ulWidth = selectedMode.VisScreenWidth;
|
---|
237 | pDev->mode.ulHeight = selectedMode.VisScreenHeight;
|
---|
238 | pDev->mode.ulBitsPerPel = selectedMode.BitsPerPlane * selectedMode.NumberOfPlanes;
|
---|
239 | pDev->mode.lScanlineStride = RT_ALIGN_32(selectedMode.ScreenStride, 4);
|
---|
240 | pDev->mode.flMaskR = selectedMode.RedMask;
|
---|
241 | pDev->mode.flMaskG = selectedMode.GreenMask;
|
---|
242 | pDev->mode.flMaskB = selectedMode.BlueMask;
|
---|
243 | pDev->mode.ulPaletteShift = (pDev->mode.ulBitsPerPel==8) ? (8-selectedMode.NumberRedBits) : 0;
|
---|
244 |
|
---|
245 | /* Fill GDIINFO structure */
|
---|
246 | memset(pGdiInfo, 0, sizeof(GDIINFO));
|
---|
247 |
|
---|
248 | pGdiInfo->ulVersion = (g_EngineVersionDDI<DDI_DRIVER_VERSION_NT5) ? GDI_DRIVER_VERSION:0x5000;
|
---|
249 | pGdiInfo->ulVersion |= VBOXDISPDRIVERVERSION;
|
---|
250 |
|
---|
251 | pGdiInfo->ulTechnology = DT_RASDISPLAY;
|
---|
252 |
|
---|
253 | pGdiInfo->ulHorzSize = selectedMode.XMillimeter;
|
---|
254 | pGdiInfo->ulVertSize = selectedMode.YMillimeter;
|
---|
255 |
|
---|
256 | pGdiInfo->ulHorzRes = pDev->mode.ulWidth;
|
---|
257 | pGdiInfo->ulVertRes = pDev->mode.ulHeight;
|
---|
258 |
|
---|
259 | pGdiInfo->cBitsPixel = pDev->mode.ulBitsPerPel;
|
---|
260 | pGdiInfo->cPlanes = selectedMode.NumberOfPlanes;
|
---|
261 |
|
---|
262 | pGdiInfo->ulNumColors = (pDev->mode.ulBitsPerPel==8) ? 20 : ((ULONG)(-1));
|
---|
263 |
|
---|
264 | pGdiInfo->ulLogPixelsX = pdm->dmLogPixels;
|
---|
265 | pGdiInfo->ulLogPixelsY = pdm->dmLogPixels;
|
---|
266 | if (pdm->dmLogPixels!=96)
|
---|
267 | {
|
---|
268 | WARN(("requested logical pixel res %d isn't 96", pdm->dmLogPixels));
|
---|
269 | }
|
---|
270 |
|
---|
271 | pGdiInfo->flTextCaps = TC_RA_ABLE;
|
---|
272 |
|
---|
273 | pGdiInfo->ulDACRed = selectedMode.NumberRedBits;
|
---|
274 | pGdiInfo->ulDACGreen = selectedMode.NumberGreenBits;
|
---|
275 | pGdiInfo->ulDACBlue = selectedMode.NumberBlueBits;
|
---|
276 |
|
---|
277 | pGdiInfo->ulAspectX = 0x24;
|
---|
278 | pGdiInfo->ulAspectY = 0x24;
|
---|
279 | /* note: ulAspectXY should be square root of sum of squares of x and y aspects */
|
---|
280 | pGdiInfo->ulAspectXY = 0x33;
|
---|
281 |
|
---|
282 | /* search for "styled cosmetic lines" on msdn for more info */
|
---|
283 | pGdiInfo->xStyleStep = 1;
|
---|
284 | pGdiInfo->yStyleStep = 1;
|
---|
285 | pGdiInfo->denStyleStep = 3;
|
---|
286 |
|
---|
287 | pGdiInfo->ulNumPalReg = (pDev->mode.ulBitsPerPel==8) ? (1<<pDev->mode.ulBitsPerPel) : 0;
|
---|
288 |
|
---|
289 | /** @todo might want to implement IOCTL_VIDEO_QUERY_COLOR_CAPABILITIES in miniport driver
|
---|
290 | * and query host for this info there
|
---|
291 | */
|
---|
292 | VBOXDISPSETCIEC(pGdiInfo->ciDevice.Red, 6700, 3300, 0);
|
---|
293 | VBOXDISPSETCIEC(pGdiInfo->ciDevice.Green, 2100, 7100, 0);
|
---|
294 | VBOXDISPSETCIEC(pGdiInfo->ciDevice.Blue, 1400, 800, 0);
|
---|
295 | VBOXDISPSETCIEC(pGdiInfo->ciDevice.AlignmentWhite, 3127, 3290, 0);
|
---|
296 | VBOXDISPSETCIEC(pGdiInfo->ciDevice.Cyan, 0, 0, 0);
|
---|
297 | VBOXDISPSETCIEC(pGdiInfo->ciDevice.Magenta, 0, 0, 0);
|
---|
298 | VBOXDISPSETCIEC(pGdiInfo->ciDevice.Yellow, 0, 0, 0);
|
---|
299 | pGdiInfo->ciDevice.RedGamma = 20000;
|
---|
300 | pGdiInfo->ciDevice.GreenGamma = 20000;
|
---|
301 | pGdiInfo->ciDevice.BlueGamma = 20000;
|
---|
302 |
|
---|
303 | pGdiInfo->ulPrimaryOrder = PRIMARY_ORDER_CBA;
|
---|
304 |
|
---|
305 | pGdiInfo->ulHTPatternSize = HT_PATSIZE_4x4_M;
|
---|
306 | switch (pDev->mode.ulBitsPerPel)
|
---|
307 | {
|
---|
308 | case 8:
|
---|
309 | {
|
---|
310 | pGdiInfo->ulHTOutputFormat = HT_FORMAT_8BPP;
|
---|
311 | break;
|
---|
312 | }
|
---|
313 | case 16:
|
---|
314 | {
|
---|
315 | pGdiInfo->ulHTOutputFormat = HT_FORMAT_16BPP;
|
---|
316 | break;
|
---|
317 | }
|
---|
318 | case 24:
|
---|
319 | {
|
---|
320 | pGdiInfo->ulHTOutputFormat = HT_FORMAT_24BPP;
|
---|
321 | break;
|
---|
322 | }
|
---|
323 | case 32:
|
---|
324 | {
|
---|
325 | pGdiInfo->ulHTOutputFormat = HT_FORMAT_32BPP;
|
---|
326 | break;
|
---|
327 | }
|
---|
328 | }
|
---|
329 | pGdiInfo->flHTFlags = HT_FLAG_ADDITIVE_PRIMS;
|
---|
330 |
|
---|
331 | pGdiInfo->ulVRefresh = selectedMode.Frequency;
|
---|
332 |
|
---|
333 | /* 0 means BitBlt's are accelerated by driver */
|
---|
334 | pGdiInfo->ulBltAlignment = 0;
|
---|
335 |
|
---|
336 | pGdiInfo->ulPhysicalPixelCharacteristics = PPC_UNDEFINED;
|
---|
337 | pGdiInfo->ulPhysicalPixelGamma = PPG_DEFAULT;
|
---|
338 |
|
---|
339 | /* Fill DEVINFO structure */
|
---|
340 | memset(pDevInfo, 0, sizeof(DEVINFO));
|
---|
341 |
|
---|
342 | pDevInfo->flGraphicsCaps = GCAPS_OPAQUERECT;
|
---|
343 | #ifdef VBOX_WITH_DDRAW
|
---|
344 | pDevInfo->flGraphicsCaps |= GCAPS_DIRECTDRAW;
|
---|
345 | #endif
|
---|
346 | VBOXDISPMAKELOGFONTW(pDevInfo->lfDefaultFont,
|
---|
347 | 16, 7, FW_BOLD, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, L"System");
|
---|
348 |
|
---|
349 | VBOXDISPMAKELOGFONTW(pDevInfo->lfAnsiVarFont,
|
---|
350 | 12, 9, FW_NORMAL, CLIP_STROKE_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, L"MS Sans Serif");
|
---|
351 |
|
---|
352 | VBOXDISPMAKELOGFONTW(pDevInfo->lfAnsiFixFont,
|
---|
353 | 12, 9, FW_NORMAL, CLIP_STROKE_PRECIS, PROOF_QUALITY, FIXED_PITCH, L"Courier");
|
---|
354 | pDevInfo->cFonts = 0;
|
---|
355 | pDevInfo->cxDither = 8;
|
---|
356 | pDevInfo->cyDither = 8;
|
---|
357 | pDevInfo->hpalDefault = 0;
|
---|
358 | pDevInfo->flGraphicsCaps2 = 0;
|
---|
359 |
|
---|
360 | switch (pDev->mode.ulBitsPerPel)
|
---|
361 | {
|
---|
362 | case 8:
|
---|
363 | {
|
---|
364 | pDevInfo->flGraphicsCaps |= GCAPS_PALMANAGED|GCAPS_COLOR_DITHER;
|
---|
365 | pDevInfo->iDitherFormat = BMF_8BPP;
|
---|
366 | break;
|
---|
367 | }
|
---|
368 | case 16:
|
---|
369 | {
|
---|
370 | pDevInfo->iDitherFormat = BMF_16BPP;
|
---|
371 | break;
|
---|
372 | }
|
---|
373 | case 24:
|
---|
374 | {
|
---|
375 | pDevInfo->iDitherFormat = BMF_24BPP;
|
---|
376 | break;
|
---|
377 | }
|
---|
378 | case 32:
|
---|
379 | {
|
---|
380 | pDevInfo->iDitherFormat = BMF_32BPP;
|
---|
381 | break;
|
---|
382 | }
|
---|
383 | }
|
---|
384 |
|
---|
385 | LOGF_LEAVE();
|
---|
386 | return rc;
|
---|
387 | }
|
---|
388 |
|
---|
389 | /* Display Driver entry point,
|
---|
390 | * Returns DDI version number and callbacks supported by driver.
|
---|
391 | */
|
---|
392 | BOOL DrvEnableDriver(ULONG iEngineVersion, ULONG cj, PDRVENABLEDATA pded)
|
---|
393 | {
|
---|
394 | /** @todo can't link with hal.lib
|
---|
395 | int irc = RTR0Init(0);
|
---|
396 | if (RT_FAILURE(irc))
|
---|
397 | {
|
---|
398 | LOGREL(("failed to init IPRT (rc=%#x)", irc));
|
---|
399 | return FALSE;
|
---|
400 | }
|
---|
401 | */
|
---|
402 |
|
---|
403 | LOGF(("iEngineVersion=%#08X, cj=%d", iEngineVersion, cj));
|
---|
404 |
|
---|
405 | g_EngineVersionDDI = iEngineVersion;
|
---|
406 |
|
---|
407 | /* Driver can't work if we can't fill atleast first 3 fields in passed PDRVENABLEDATA */
|
---|
408 | if (cj < (2*sizeof(ULONG)+sizeof(DRVFN*)))
|
---|
409 | {
|
---|
410 | WARN(("cj<%d, terminating\n", sizeof(DRVENABLEDATA)));
|
---|
411 | return FALSE;
|
---|
412 | }
|
---|
413 |
|
---|
414 | /* Report driver DDI version and appropriate callbacks table based on engine DDI */
|
---|
415 | if (iEngineVersion>=DDI_DRIVER_VERSION_NT5)
|
---|
416 | {
|
---|
417 | /* WIN2K and above */
|
---|
418 | pded->iDriverVersion = DDI_DRIVER_VERSION_NT5;
|
---|
419 | pded->pdrvfn = g_aDrvFnTableNT5;
|
---|
420 | pded->c = RT_ELEMENTS(g_aDrvFnTableNT5);
|
---|
421 | }
|
---|
422 | else
|
---|
423 | {
|
---|
424 | /* NT4_SP3 and below*/
|
---|
425 | pded->iDriverVersion = DDI_DRIVER_VERSION_NT4;
|
---|
426 | pded->pdrvfn = g_aDrvFnTableNT4;
|
---|
427 | pded->c = RT_ELEMENTS(g_aDrvFnTableNT4);
|
---|
428 | }
|
---|
429 |
|
---|
430 | LOGF_LEAVE();
|
---|
431 | return TRUE;
|
---|
432 | }
|
---|
433 |
|
---|
434 | /* Free all resources allocated in DrvEnableDriver */
|
---|
435 | VOID APIENTRY VBoxDispDrvDisableDriver()
|
---|
436 | {
|
---|
437 | LOGF_ENTER();
|
---|
438 |
|
---|
439 | /* Intentionally left blank */
|
---|
440 |
|
---|
441 | LOGF_LEAVE();
|
---|
442 | return;
|
---|
443 | }
|
---|
444 |
|
---|
445 | /* Returns video modes supported by our device/driver
|
---|
446 | * Note: If we fail here we'd be asked to enter 800x600@4bpp mode later in VBoxDispDrvEnablePDEV.
|
---|
447 | */
|
---|
448 | ULONG APIENTRY VBoxDispDrvGetModes(HANDLE hDriver, ULONG cjSize, DEVMODEW *pdm)
|
---|
449 | {
|
---|
450 | int rc;
|
---|
451 | VIDEO_MODE_INFORMATION *pModesTable;
|
---|
452 | ULONG cModes;
|
---|
453 | LOGF_ENTER();
|
---|
454 |
|
---|
455 | rc = VBoxDispMPGetVideoModes(hDriver, &pModesTable, &cModes);
|
---|
456 | VBOX_WARNRC_RETV(rc, 0);
|
---|
457 |
|
---|
458 | if (!pdm) /* return size of buffer required to store all supported modes */
|
---|
459 | {
|
---|
460 | EngFreeMem(pModesTable);
|
---|
461 | LOGF_LEAVE();
|
---|
462 | return cModes * sizeof(DEVMODEW);
|
---|
463 | }
|
---|
464 |
|
---|
465 | ULONG mode, cMaxNodes=cjSize/sizeof(DEVMODEW);
|
---|
466 |
|
---|
467 | for (mode=0; mode<cModes && mode<cMaxNodes; ++mode, ++pdm)
|
---|
468 | {
|
---|
469 | memset(pdm, 0, sizeof(DEVMODEW));
|
---|
470 | memcpy(pdm->dmDeviceName, VBOXDISP_DEVICE_NAME, sizeof(VBOXDISP_DEVICE_NAME));
|
---|
471 |
|
---|
472 | pdm->dmSpecVersion = DM_SPECVERSION;
|
---|
473 | pdm->dmDriverVersion = DM_SPECVERSION;
|
---|
474 | pdm->dmSize = sizeof(DEVMODEW);
|
---|
475 | pdm->dmDriverExtra = 0;
|
---|
476 |
|
---|
477 | pdm->dmBitsPerPel = pModesTable[mode].NumberOfPlanes*pModesTable[mode].BitsPerPlane;
|
---|
478 | pdm->dmPelsWidth = pModesTable[mode].VisScreenWidth;
|
---|
479 | pdm->dmPelsHeight = pModesTable[mode].VisScreenHeight;
|
---|
480 | pdm->dmDisplayFrequency = pModesTable[mode].Frequency;
|
---|
481 | pdm->dmDisplayFlags = 0;
|
---|
482 | pdm->dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFREQUENCY|DM_DISPLAYFLAGS;
|
---|
483 | }
|
---|
484 | EngFreeMem(pModesTable);
|
---|
485 |
|
---|
486 | LOG(("%d mode(s) reported", mode));
|
---|
487 |
|
---|
488 | LOGF_LEAVE();
|
---|
489 | return mode * sizeof(DEVMODEW);
|
---|
490 | }
|
---|
491 |
|
---|
492 | /* First function which is called after entry point, provides info about device to GDI.
|
---|
493 | * Returns pointer to our driver private info structure which would be passed by GDI to our other callbacks.
|
---|
494 | */
|
---|
495 | DHPDEV APIENTRY
|
---|
496 | VBoxDispDrvEnablePDEV(DEVMODEW *pdm, LPWSTR pwszLogAddress, ULONG cPat, HSURF *phsurfPatterns,
|
---|
497 | ULONG cjCaps, ULONG *pdevcaps,
|
---|
498 | ULONG cjDevInfo, DEVINFO *pdi,
|
---|
499 | HDEV hdev, PWSTR pwszDeviceName, HANDLE hDriver)
|
---|
500 | {
|
---|
501 | RT_NOREF(hdev);
|
---|
502 | PVBOXDISPDEV pDev = NULL;
|
---|
503 | GDIINFO gdiInfo;
|
---|
504 | DEVINFO devInfo;
|
---|
505 | int rc;
|
---|
506 |
|
---|
507 | /* Next 3 are only used for printer drivers */
|
---|
508 | NOREF(pwszLogAddress);
|
---|
509 | NOREF(cPat);
|
---|
510 | NOREF(phsurfPatterns);
|
---|
511 | NOREF(pwszDeviceName);
|
---|
512 |
|
---|
513 | LOGF_ENTER();
|
---|
514 |
|
---|
515 | pDev = (PVBOXDISPDEV) EngAllocMem(FL_ZERO_MEMORY, sizeof(VBOXDISPDEV), MEM_ALLOC_TAG);
|
---|
516 | if (!pDev)
|
---|
517 | {
|
---|
518 | WARN(("EngAllocMem failed!\n"));
|
---|
519 | return NULL;
|
---|
520 | }
|
---|
521 | pDev->hDriver = hDriver;
|
---|
522 |
|
---|
523 | ULONG ulRegistryFlags = 0;
|
---|
524 | rc = VBoxDispMPQueryRegistryFlags(hDriver, &ulRegistryFlags);
|
---|
525 | if (RT_SUCCESS(rc))
|
---|
526 | {
|
---|
527 | pDev->bBitmapCacheDisabled = (ulRegistryFlags & VBOXVIDEO_REGISTRY_FLAGS_DISABLE_BITMAP_CACHE) != 0;
|
---|
528 | LOG(("Bitmap cache %s", pDev->bBitmapCacheDisabled? "disabled": "enabled"));
|
---|
529 | }
|
---|
530 |
|
---|
531 | /* Initialize device structure and query miniport to fill device and gdi infos */
|
---|
532 | rc = VBoxDispInitDevice(pDev, pdm, &gdiInfo, &devInfo);
|
---|
533 | if (RT_FAILURE(rc))
|
---|
534 | {
|
---|
535 | VBOX_WARNRC(rc);
|
---|
536 | EngFreeMem(pDev);
|
---|
537 | return NULL;
|
---|
538 | }
|
---|
539 |
|
---|
540 | /* Initialize mouse pointer caps */
|
---|
541 | rc = VBoxDispInitPointerCaps(pDev, &devInfo);
|
---|
542 | if (RT_FAILURE(rc))
|
---|
543 | {
|
---|
544 | VBOX_WARNRC(rc);
|
---|
545 | }
|
---|
546 |
|
---|
547 | /* Initialize palette */
|
---|
548 | rc = VBoxDispInitPalette(pDev, &devInfo);
|
---|
549 | if (RT_FAILURE(rc))
|
---|
550 | {
|
---|
551 | VBOX_WARNRC(rc);
|
---|
552 | EngFreeMem(pDev);
|
---|
553 | return NULL;
|
---|
554 | }
|
---|
555 |
|
---|
556 | if(g_EngineVersionDDI >= DDI_DRIVER_VERSION_NT5)
|
---|
557 | {
|
---|
558 | devInfo.flGraphicsCaps2 |= GCAPS2_RESERVED1;
|
---|
559 | }
|
---|
560 |
|
---|
561 | /* Copy gathered info to supplied buffers */
|
---|
562 | memcpy(pdevcaps, &gdiInfo, min(sizeof(GDIINFO), cjCaps));
|
---|
563 | memcpy(pdi, &devInfo, min(sizeof(DEVINFO), cjDevInfo));
|
---|
564 |
|
---|
565 | LOGF_LEAVE();
|
---|
566 | return (DHPDEV)pDev;
|
---|
567 | }
|
---|
568 |
|
---|
569 | /* Called to provide us GDI handle for our device, which we should use later for GDI calls */
|
---|
570 | VOID APIENTRY VBoxDispDrvCompletePDEV(DHPDEV dhpdev, HDEV hdev)
|
---|
571 | {
|
---|
572 | LOGF_ENTER();
|
---|
573 |
|
---|
574 | ((PVBOXDISPDEV)dhpdev)->hDevGDI = hdev;
|
---|
575 |
|
---|
576 | LOGF_LEAVE();
|
---|
577 | }
|
---|
578 |
|
---|
579 | /* Called to free resources allocated for device in VBoxDispDrvEnablePDEV */
|
---|
580 | VOID APIENTRY VBoxDispDrvDisablePDEV(DHPDEV dhpdev)
|
---|
581 | {
|
---|
582 | LOGF_ENTER();
|
---|
583 |
|
---|
584 | VBoxDispDestroyPalette((PVBOXDISPDEV) dhpdev);
|
---|
585 |
|
---|
586 | EngFreeMem(dhpdev);
|
---|
587 |
|
---|
588 | LOGF_LEAVE();
|
---|
589 | }
|
---|
590 |
|
---|
591 | /* Called to create and associate surface with device */
|
---|
592 | HSURF APIENTRY VBoxDispDrvEnableSurface(DHPDEV dhpdev)
|
---|
593 | {
|
---|
594 | int rc;
|
---|
595 | PVBOXDISPDEV pDev = (PVBOXDISPDEV)dhpdev;
|
---|
596 |
|
---|
597 | LOGF_ENTER();
|
---|
598 |
|
---|
599 | /* Switch device to mode requested in VBoxDispDrvEnablePDEV */
|
---|
600 | rc = VBoxDispMPSetCurrentMode(pDev->hDriver, pDev->mode.ulIndex);
|
---|
601 | VBOX_WARNRC_RETV(rc, NULL);
|
---|
602 |
|
---|
603 | /* Map fb and vram */
|
---|
604 | rc = VBoxDispMPMapMemory(pDev, &pDev->memInfo);
|
---|
605 | VBOX_WARNRC_RETV(rc, NULL);
|
---|
606 |
|
---|
607 | /* Clear mapped memory, to avoid garbage while video mode is switching */
|
---|
608 | /** @todo VIDEO_MODE_NO_ZERO_MEMORY does nothing in miniport's IOCTL_VIDEO_SET_CURRENT_MODE*/
|
---|
609 | memset(pDev->memInfo.FrameBufferBase, 0, pDev->mode.ulHeight * abs(pDev->mode.lScanlineStride));
|
---|
610 |
|
---|
611 | /* Allocate memory for pointer attrs */
|
---|
612 | rc = VBoxDispInitPointerAttrs(pDev);
|
---|
613 | VBOX_WARNRC_RETV(rc, NULL);
|
---|
614 |
|
---|
615 | /* Init VBVA */
|
---|
616 | rc = VBoxDispVBVAInit(pDev);
|
---|
617 | VBOX_WARNRC_RETV(rc, NULL);
|
---|
618 |
|
---|
619 | /* Enable VBVA */
|
---|
620 | if (pDev->hgsmi.bSupported)
|
---|
621 | {
|
---|
622 | if (pDev->mode.ulBitsPerPel==16 || pDev->mode.ulBitsPerPel==24 || pDev->mode.ulBitsPerPel==32)
|
---|
623 | {
|
---|
624 | VBVABUFFER *pVBVA = (VBVABUFFER *)((uint8_t *)pDev->memInfo.VideoRamBase+pDev->layout.offVBVABuffer);
|
---|
625 | pDev->hgsmi.bSupported = VBoxVBVAEnable(&pDev->vbvaCtx, &pDev->hgsmi.ctx, pVBVA, -1);
|
---|
626 | LogRel(("VBoxDisp[%d]: VBVA %senabled\n", pDev->iDevice, pDev->hgsmi.bSupported? "":"not "));
|
---|
627 | }
|
---|
628 | }
|
---|
629 |
|
---|
630 | /* Inform host */
|
---|
631 | if (pDev->hgsmi.bSupported)
|
---|
632 | {
|
---|
633 | VBoxHGSMIProcessDisplayInfo(&pDev->hgsmi.ctx, pDev->iDevice, pDev->orgDev.x, pDev->orgDev.y,
|
---|
634 | 0, abs(pDev->mode.lScanlineStride), pDev->mode.ulWidth, pDev->mode.ulHeight,
|
---|
635 | (uint16_t)pDev->mode.ulBitsPerPel, VBVA_SCREEN_F_ACTIVE);
|
---|
636 | }
|
---|
637 |
|
---|
638 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
639 | VBoxDispVHWAEnable(pDev);
|
---|
640 | #endif
|
---|
641 |
|
---|
642 | /* Set device palette if needed */
|
---|
643 | if (pDev->mode.ulBitsPerPel == 8)
|
---|
644 | {
|
---|
645 | rc = VBoxDispSetPalette8BPP(pDev);
|
---|
646 | VBOX_WARNRC_RETV(rc, NULL);
|
---|
647 | }
|
---|
648 |
|
---|
649 | pDev->orgDisp.x = 0;
|
---|
650 | pDev->orgDisp.y = 0;
|
---|
651 |
|
---|
652 | /* Create GDI managed bitmap, which resides in our framebuffer memory */
|
---|
653 | ULONG iFormat;
|
---|
654 | SIZEL size;
|
---|
655 |
|
---|
656 | switch (pDev->mode.ulBitsPerPel)
|
---|
657 | {
|
---|
658 | case 8:
|
---|
659 | {
|
---|
660 | iFormat = BMF_8BPP;
|
---|
661 | break;
|
---|
662 | }
|
---|
663 | case 16:
|
---|
664 | {
|
---|
665 | iFormat = BMF_16BPP;
|
---|
666 | break;
|
---|
667 | }
|
---|
668 | case 24:
|
---|
669 | {
|
---|
670 | iFormat = BMF_24BPP;
|
---|
671 | break;
|
---|
672 | }
|
---|
673 | case 32:
|
---|
674 | {
|
---|
675 | iFormat = BMF_32BPP;
|
---|
676 | break;
|
---|
677 | }
|
---|
678 | default:
|
---|
679 | AssertMsgFailedReturn(("ulBitsPerPel=%#x\n", pDev->mode.ulBitsPerPel), NULL);
|
---|
680 | }
|
---|
681 |
|
---|
682 | size.cx = pDev->mode.ulWidth;
|
---|
683 | size.cy = pDev->mode.ulHeight;
|
---|
684 |
|
---|
685 | pDev->surface.hBitmap = EngCreateBitmap(size, pDev->mode.lScanlineStride, iFormat,
|
---|
686 | pDev->mode.lScanlineStride > 0 ? BMF_TOPDOWN:0,
|
---|
687 | pDev->memInfo.FrameBufferBase);
|
---|
688 | if (!pDev->surface.hBitmap)
|
---|
689 | {
|
---|
690 | WARN(("EngCreateBitmap failed!"));
|
---|
691 | return NULL;
|
---|
692 | }
|
---|
693 | pDev->surface.psoBitmap = EngLockSurface((HSURF)pDev->surface.hBitmap);
|
---|
694 |
|
---|
695 | /* Create device-managed surface */
|
---|
696 | pDev->surface.hSurface = EngCreateDeviceSurface((DHSURF)pDev, size, iFormat);
|
---|
697 | if (!pDev->surface.hSurface)
|
---|
698 | {
|
---|
699 | WARN(("EngCreateDeviceSurface failed!"));
|
---|
700 | VBoxDispDrvDisableSurface(dhpdev);
|
---|
701 | return NULL;
|
---|
702 | }
|
---|
703 |
|
---|
704 | FLONG flHooks = HOOK_BITBLT|HOOK_TEXTOUT|HOOK_FILLPATH|HOOK_COPYBITS|HOOK_STROKEPATH|HOOK_LINETO|
|
---|
705 | HOOK_PAINT|HOOK_STRETCHBLT;
|
---|
706 |
|
---|
707 | /* Associate created surface with our device */
|
---|
708 | if (!EngAssociateSurface(pDev->surface.hSurface, pDev->hDevGDI, flHooks))
|
---|
709 | {
|
---|
710 | WARN(("EngAssociateSurface failed!"));
|
---|
711 | VBoxDispDrvDisableSurface(dhpdev);
|
---|
712 | return NULL;
|
---|
713 | }
|
---|
714 |
|
---|
715 | pDev->surface.ulFormat = iFormat;
|
---|
716 | pDev->flDrawingHooks = flHooks;
|
---|
717 |
|
---|
718 | LOG(("Created surface %p for physical device %p", pDev->surface.hSurface, pDev));
|
---|
719 |
|
---|
720 | LOGF_LEAVE();
|
---|
721 | return pDev->surface.hSurface;
|
---|
722 | }
|
---|
723 |
|
---|
724 | VOID APIENTRY VBoxDispDrvDisableSurface(DHPDEV dhpdev)
|
---|
725 | {
|
---|
726 | PVBOXDISPDEV pDev = (PVBOXDISPDEV)dhpdev;
|
---|
727 | LOGF_ENTER();
|
---|
728 |
|
---|
729 | if (pDev->surface.hSurface)
|
---|
730 | {
|
---|
731 | EngDeleteSurface(pDev->surface.hSurface);
|
---|
732 | pDev->surface.hSurface = NULL;
|
---|
733 | }
|
---|
734 |
|
---|
735 | if (pDev->surface.psoBitmap)
|
---|
736 | {
|
---|
737 | Assert(pDev->surface.hBitmap);
|
---|
738 | EngUnlockSurface(pDev->surface.psoBitmap);
|
---|
739 | pDev->surface.psoBitmap = NULL;
|
---|
740 | }
|
---|
741 |
|
---|
742 | if (pDev->surface.hBitmap)
|
---|
743 | {
|
---|
744 | EngDeleteSurface((HSURF) pDev->surface.hBitmap);
|
---|
745 | pDev->surface.hBitmap = NULL;
|
---|
746 | }
|
---|
747 |
|
---|
748 | int rc;
|
---|
749 | rc = VBoxDispMPUnmapMemory(pDev);
|
---|
750 | VBOX_WARNRC(rc);
|
---|
751 |
|
---|
752 | LOGF_LEAVE();
|
---|
753 | }
|
---|
754 |
|
---|
755 | BOOL APIENTRY
|
---|
756 | VBoxDispDrvRealizeBrush(BRUSHOBJ *pbo, SURFOBJ *psoTarget, SURFOBJ *psoPattern, SURFOBJ *psoMask,
|
---|
757 | XLATEOBJ *pxlo, ULONG iHatch)
|
---|
758 | {
|
---|
759 | BOOL bRc = FALSE;
|
---|
760 | LOGF_ENTER();
|
---|
761 |
|
---|
762 | if (VBoxDispIsScreenSurface(psoTarget))
|
---|
763 | {
|
---|
764 | PVBOXDISPDEV pDev = (PVBOXDISPDEV)psoTarget->dhpdev;
|
---|
765 |
|
---|
766 | if (pDev->vbvaCtx.pVBVA && (pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_ENABLED))
|
---|
767 | {
|
---|
768 | if (pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents & VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET)
|
---|
769 | {
|
---|
770 | vrdpReset(pDev);
|
---|
771 | pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents &= ~VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
|
---|
772 | }
|
---|
773 |
|
---|
774 | if (pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_VRDP)
|
---|
775 | {
|
---|
776 | bRc = vrdpDrvRealizeBrush(pbo, psoTarget, psoPattern, psoMask, pxlo, iHatch);
|
---|
777 | }
|
---|
778 | }
|
---|
779 | }
|
---|
780 |
|
---|
781 | LOGF_LEAVE();
|
---|
782 | return bRc;
|
---|
783 | }
|
---|
784 |
|
---|
785 | ULONG APIENTRY VBoxDispDrvDitherColor(DHPDEV dhpdev, ULONG iMode, ULONG rgb, ULONG *pul)
|
---|
786 | {
|
---|
787 | RT_NOREF(dhpdev, iMode, rgb, pul);
|
---|
788 | ULONG rc;
|
---|
789 | LOGF_ENTER();
|
---|
790 |
|
---|
791 | /* There is no EngDitherColor on NT4, so take the easy path and tell the graphics
|
---|
792 | * engine to create a halftone approximation.
|
---|
793 | */
|
---|
794 | rc = DCR_HALFTONE;
|
---|
795 |
|
---|
796 | LOGF_LEAVE();
|
---|
797 | return rc;
|
---|
798 | }
|
---|
799 |
|
---|
800 | /* Called to reset device to default mode or to mode specified with dhpdev */
|
---|
801 | BOOL APIENTRY VBoxDispDrvAssertMode(DHPDEV dhpdev, BOOL bEnable)
|
---|
802 | {
|
---|
803 | PVBOXDISPDEV pDev = (PVBOXDISPDEV) dhpdev;
|
---|
804 | int rc;
|
---|
805 | LOGF_ENTER();
|
---|
806 |
|
---|
807 | if (!bEnable)
|
---|
808 | {
|
---|
809 | LOGF(("!bEnable"));
|
---|
810 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
811 | /* tells we can not process host commands any more and ensures that
|
---|
812 | * we've completed processing of the host VHWA commands
|
---|
813 | */
|
---|
814 | VBoxDispVHWADisable(pDev);
|
---|
815 | #endif
|
---|
816 |
|
---|
817 | /* disable VBVA */
|
---|
818 | if (pDev->hgsmi.bSupported)
|
---|
819 | {
|
---|
820 | VBoxVBVADisable(&pDev->vbvaCtx, &pDev->hgsmi.ctx, -1);
|
---|
821 | }
|
---|
822 |
|
---|
823 | /* reset the device to default mode */
|
---|
824 | rc = VBoxDispMPResetDevice(pDev->hDriver);
|
---|
825 | VBOX_WARNRC_RETV(rc, FALSE);
|
---|
826 | }
|
---|
827 | else
|
---|
828 | {
|
---|
829 | LOGF(("bEnable"));
|
---|
830 |
|
---|
831 | /* switch device to previous pDev mode */
|
---|
832 | rc = VBoxDispMPSetCurrentMode(pDev->hDriver, pDev->mode.ulIndex);
|
---|
833 | VBOX_WARNRC_RETV(rc, NULL);
|
---|
834 |
|
---|
835 | /* enable VBVA */
|
---|
836 | if (pDev->hgsmi.bSupported)
|
---|
837 | {
|
---|
838 | if (pDev->mode.ulBitsPerPel==16 || pDev->mode.ulBitsPerPel==24 || pDev->mode.ulBitsPerPel==32)
|
---|
839 | {
|
---|
840 | VBVABUFFER *pVBVA = (VBVABUFFER *)((uint8_t *)pDev->memInfo.VideoRamBase+pDev->layout.offVBVABuffer);
|
---|
841 | pDev->hgsmi.bSupported = VBoxVBVAEnable(&pDev->vbvaCtx, &pDev->hgsmi.ctx, pVBVA, -1);
|
---|
842 | LogRel(("VBoxDisp[%d]: VBVA %senabled\n", pDev->iDevice, pDev->hgsmi.bSupported? "":"not "));
|
---|
843 | }
|
---|
844 | }
|
---|
845 |
|
---|
846 | /* inform host */
|
---|
847 | if (pDev->hgsmi.bSupported)
|
---|
848 | {
|
---|
849 | VBoxHGSMIProcessDisplayInfo(&pDev->hgsmi.ctx, pDev->iDevice, pDev->orgDev.x, pDev->orgDev.y,
|
---|
850 | 0, abs(pDev->mode.lScanlineStride), pDev->mode.ulWidth, pDev->mode.ulHeight,
|
---|
851 | (uint16_t)pDev->mode.ulBitsPerPel, VBVA_SCREEN_F_ACTIVE);
|
---|
852 | }
|
---|
853 |
|
---|
854 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
855 | /* tells we can process host commands */
|
---|
856 | VBoxDispVHWAEnable(pDev);
|
---|
857 | #endif
|
---|
858 |
|
---|
859 | /* Associate back GDI bitmap residing in our framebuffer memory with GDI's handle to our device */
|
---|
860 | if (!EngAssociateSurface((HSURF)pDev->surface.hBitmap, pDev->hDevGDI, 0))
|
---|
861 | {
|
---|
862 | WARN(("EngAssociateSurface on bitmap failed"));
|
---|
863 | return FALSE;
|
---|
864 | }
|
---|
865 |
|
---|
866 | /* Associate device managed surface with GDI's handle to our device */
|
---|
867 | if (!EngAssociateSurface(pDev->surface.hSurface, pDev->hDevGDI, pDev->flDrawingHooks))
|
---|
868 | {
|
---|
869 | WARN(("EngAssociateSurface on surface failed"));
|
---|
870 | return FALSE;
|
---|
871 | }
|
---|
872 | }
|
---|
873 |
|
---|
874 | LOGF_LEAVE();
|
---|
875 | return TRUE;
|
---|
876 | }
|
---|
877 |
|
---|
878 | ULONG APIENTRY VBoxDispDrvEscape(SURFOBJ *pso, ULONG iEsc, ULONG cjIn, PVOID pvIn, ULONG cjOut, PVOID pvOut)
|
---|
879 | {
|
---|
880 | PVBOXDISPDEV pDev = (PVBOXDISPDEV)pso->dhpdev;
|
---|
881 | LOGF_ENTER();
|
---|
882 |
|
---|
883 | switch (iEsc)
|
---|
884 | {
|
---|
885 | #ifdef VBOX_WITH_CROGL
|
---|
886 | case OPENGL_GETINFO:
|
---|
887 | {
|
---|
888 | if (pvOut && cjOut >= sizeof(OPENGL_INFO))
|
---|
889 | {
|
---|
890 | POPENGL_INFO pInfo = (POPENGL_INFO)pvOut;
|
---|
891 |
|
---|
892 | pInfo->dwVersion = 2;
|
---|
893 | pInfo->dwDriverVersion = 1;
|
---|
894 | pInfo->szDriverName[0] = 'V';
|
---|
895 | pInfo->szDriverName[1] = 'B';
|
---|
896 | pInfo->szDriverName[2] = 'o';
|
---|
897 | pInfo->szDriverName[3] = 'x';
|
---|
898 | pInfo->szDriverName[4] = 'O';
|
---|
899 | pInfo->szDriverName[5] = 'G';
|
---|
900 | pInfo->szDriverName[6] = 'L';
|
---|
901 | pInfo->szDriverName[7] = 0;
|
---|
902 |
|
---|
903 | LOG(("OPENGL_GETINFO ok"));
|
---|
904 | return cjOut;
|
---|
905 | }
|
---|
906 | else
|
---|
907 | {
|
---|
908 | WARN(("OPENGL_GETINFO invalid parms"));
|
---|
909 | return 0;
|
---|
910 | }
|
---|
911 | }
|
---|
912 | case QUERYESCSUPPORT:
|
---|
913 | {
|
---|
914 | if (pvIn && cjIn == sizeof(DWORD))
|
---|
915 | {
|
---|
916 | DWORD nEscapeQuery = *(DWORD *)pvIn;
|
---|
917 |
|
---|
918 | if (nEscapeQuery==OPENGL_GETINFO)
|
---|
919 | {
|
---|
920 | LOG(("QUERYESCSUPPORT OPENGL_GETINFO"));
|
---|
921 | return 1;
|
---|
922 | }
|
---|
923 | else
|
---|
924 | {
|
---|
925 | LOG(("QUERYESCSUPPORT unsupported query %d", nEscapeQuery));
|
---|
926 | return 0;
|
---|
927 | }
|
---|
928 | }
|
---|
929 | else
|
---|
930 | {
|
---|
931 | WARN(("QUERYESCSUPPORT invalid parms"));
|
---|
932 | return 0;
|
---|
933 | }
|
---|
934 | }
|
---|
935 | #endif
|
---|
936 | case VBOXESC_ISVRDPACTIVE:
|
---|
937 | {
|
---|
938 | if (pDev && pDev->vbvaCtx.pVBVA && pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents&VBVA_F_MODE_VRDP)
|
---|
939 | {
|
---|
940 | LOGF(("VBOXESC_ISVRDPACTIVE: 1"));
|
---|
941 | return 1;
|
---|
942 | }
|
---|
943 | LOGF(("VBOXESC_ISVRDPACTIVE: 0"));
|
---|
944 | return 0;
|
---|
945 | }
|
---|
946 | case VBOXESC_SETVISIBLEREGION:
|
---|
947 | {
|
---|
948 | LOGF(("VBOXESC_SETVISIBLEREGION"));
|
---|
949 | LPRGNDATA lpRgnData = (LPRGNDATA)pvIn;
|
---|
950 | DWORD cRects;
|
---|
951 |
|
---|
952 | if ( cjIn >= sizeof(RGNDATAHEADER)
|
---|
953 | && pvIn
|
---|
954 | && lpRgnData->rdh.dwSize == sizeof(RGNDATAHEADER)
|
---|
955 | && lpRgnData->rdh.iType == RDH_RECTANGLES
|
---|
956 | && (cRects = lpRgnData->rdh.nCount) <= _1M
|
---|
957 | && cjIn == cRects * (uint64_t)sizeof(RECT) + sizeof(RGNDATAHEADER))
|
---|
958 | {
|
---|
959 | /** @todo this whole conversion thing could maybe be skipped
|
---|
960 | * since RTRECT matches the RECT layout. */
|
---|
961 | #if 0
|
---|
962 | AssertCompile(sizeof(RTRECT) == sizeof(RECT));
|
---|
963 | AssertCompileMembersSameSizeAndOffset(RTRECT, xLeft, RECT, left);
|
---|
964 | AssertCompileMembersSameSizeAndOffset(RTRECT, xBottom, RECT, bottom);
|
---|
965 | AssertCompileMembersSameSizeAndOffset(RTRECT, xRight, RECT, right);
|
---|
966 | AssertCompileMembersSameSizeAndOffset(RTRECT, xTop, RECT, top);
|
---|
967 |
|
---|
968 | rc = VBoxDispMPSetVisibleRegion(pDev->hDriver, (PRTRECT)&lpRgnData->Buffer[0], cRects);
|
---|
969 | VBOX_WARNRC(rc);
|
---|
970 | #else
|
---|
971 | DWORD i;
|
---|
972 | PRTRECT pRTRect;
|
---|
973 | int rc;
|
---|
974 | RECT *pRect = (RECT *)&lpRgnData->Buffer;
|
---|
975 |
|
---|
976 | pRTRect = (PRTRECT) EngAllocMem(0, cRects*sizeof(RTRECT), MEM_ALLOC_TAG);
|
---|
977 | if (!pRTRect)
|
---|
978 | {
|
---|
979 | WARN(("failed to allocate %d bytes", cRects*sizeof(RTRECT)));
|
---|
980 | break;
|
---|
981 | }
|
---|
982 |
|
---|
983 | for (i = 0; i < cRects; ++i)
|
---|
984 | {
|
---|
985 | LOG(("New visible rectangle (%d,%d) (%d,%d)",
|
---|
986 | pRect[i].left, pRect[i].bottom, pRect[i].right, pRect[i].top));
|
---|
987 | pRTRect[i].xLeft = pRect[i].left;
|
---|
988 | pRTRect[i].yBottom = pRect[i].bottom;
|
---|
989 | pRTRect[i].xRight = pRect[i].right;
|
---|
990 | pRTRect[i].yTop = pRect[i].top;
|
---|
991 | }
|
---|
992 |
|
---|
993 | rc = VBoxDispMPSetVisibleRegion(pDev->hDriver, pRTRect, cRects);
|
---|
994 | VBOX_WARNRC(rc);
|
---|
995 |
|
---|
996 | EngFreeMem(pRTRect);
|
---|
997 |
|
---|
998 | #endif
|
---|
999 | if (RT_SUCCESS(rc))
|
---|
1000 | {
|
---|
1001 | LOGF_LEAVE();
|
---|
1002 | return 1;
|
---|
1003 | }
|
---|
1004 | }
|
---|
1005 | else
|
---|
1006 | {
|
---|
1007 | if (pvIn)
|
---|
1008 | {
|
---|
1009 | WARN(("check failed rdh.dwSize=%x iType=%d size=%d expected size=%d",
|
---|
1010 | lpRgnData->rdh.dwSize, lpRgnData->rdh.iType, cjIn,
|
---|
1011 | lpRgnData->rdh.nCount * sizeof(RECT) + sizeof(RGNDATAHEADER)));
|
---|
1012 | }
|
---|
1013 | }
|
---|
1014 | break;
|
---|
1015 | }
|
---|
1016 | case VBOXESC_ISANYX:
|
---|
1017 | {
|
---|
1018 | if (pvOut && cjOut == sizeof(DWORD))
|
---|
1019 | {
|
---|
1020 | DWORD cbReturned;
|
---|
1021 | DWORD dwrc = EngDeviceIoControl(pDev->hDriver, IOCTL_VIDEO_VBOX_ISANYX, NULL, 0,
|
---|
1022 | pvOut, sizeof (uint32_t), &cbReturned);
|
---|
1023 | if (dwrc == NO_ERROR && cbReturned == sizeof (uint32_t))
|
---|
1024 | return 1;
|
---|
1025 | WARN(("EngDeviceIoControl failed, dwrc(%d), cbReturned(%d)", dwrc, cbReturned));
|
---|
1026 | return 0;
|
---|
1027 | }
|
---|
1028 | else
|
---|
1029 | {
|
---|
1030 | WARN(("VBOXESC_ISANYX invalid parms"));
|
---|
1031 | return 0;
|
---|
1032 | }
|
---|
1033 | break;
|
---|
1034 | }
|
---|
1035 | default:
|
---|
1036 | {
|
---|
1037 | LOG(("unsupported iEsc %#x", iEsc));
|
---|
1038 | }
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | LOGF_LEAVE();
|
---|
1042 | return 0;
|
---|
1043 | }
|
---|
1044 |
|
---|
1045 | #define FB_OFFSET(_dev, _x, _y) ((_y)*pDev->mode.lScanlineStride) + ((_x)*((pDev->mode.ulBitsPerPel+1)/8))
|
---|
1046 | /* Obsolete, NT4 specific. Called to set display offset in virtual desktop */
|
---|
1047 | BOOL APIENTRY VBoxDispDrvOffset(SURFOBJ* pso, LONG x, LONG y, FLONG flReserved)
|
---|
1048 | {
|
---|
1049 | RT_NOREF(flReserved);
|
---|
1050 | PVBOXDISPDEV pDev = (PVBOXDISPDEV)pso->dhpdev;
|
---|
1051 | LOGF(("%x %x %x\n", x, y, flReserved));
|
---|
1052 |
|
---|
1053 | pDev->memInfo.FrameBufferBase = ((BYTE*)pDev->memInfo.VideoRamBase) + pDev->layout.offFramebuffer
|
---|
1054 | - FB_OFFSET(pDev, x, y);
|
---|
1055 |
|
---|
1056 | pDev->orgDisp.x = x;
|
---|
1057 | pDev->orgDisp.y = y;
|
---|
1058 |
|
---|
1059 | LOGF_LEAVE();
|
---|
1060 | return TRUE;
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | /* Called to notify driver about various events */
|
---|
1064 | VOID APIENTRY VBoxDispDrvNotify(SURFOBJ *pso, ULONG iType, PVOID pvData)
|
---|
1065 | {
|
---|
1066 | PVBOXDISPDEV pDev = (PVBOXDISPDEV)pso->dhpdev;
|
---|
1067 | LOGF_ENTER();
|
---|
1068 |
|
---|
1069 | switch (iType)
|
---|
1070 | {
|
---|
1071 | case DN_DEVICE_ORIGIN:
|
---|
1072 | {
|
---|
1073 | /*device origin in dualview*/
|
---|
1074 | POINTL *pOrg = (POINTL *)pvData;
|
---|
1075 | if (pOrg)
|
---|
1076 | {
|
---|
1077 | LOG(("DN_DEVICE_ORIGIN (pso=%p, pDev[%d]=%p) old=%d,%d new=%d,%d",
|
---|
1078 | pso, pDev->iDevice, pDev, pDev->orgDev.x, pDev->orgDev.y, pOrg->x, pOrg->y));
|
---|
1079 | if (pDev->orgDev.x!=pOrg->x || pDev->orgDev.y!=pOrg->y)
|
---|
1080 | {
|
---|
1081 | pDev->orgDev = *pOrg;
|
---|
1082 |
|
---|
1083 | /* Inform host about display change */
|
---|
1084 | VBoxHGSMIProcessDisplayInfo(&pDev->hgsmi.ctx, pDev->iDevice, pDev->orgDev.x, pDev->orgDev.y,
|
---|
1085 | 0, abs(pDev->mode.lScanlineStride),
|
---|
1086 | pDev->mode.ulWidth, pDev->mode.ulHeight,
|
---|
1087 | (uint16_t)pDev->mode.ulBitsPerPel, VBVA_SCREEN_F_ACTIVE);
|
---|
1088 | }
|
---|
1089 | }
|
---|
1090 | else
|
---|
1091 | {
|
---|
1092 | WARN(("DN_DEVICE_ORIGIN pvData==NULL"));
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | break;
|
---|
1096 | }
|
---|
1097 | case DN_DRAWING_BEGIN:
|
---|
1098 | {
|
---|
1099 | /*first drawing op is about to happen for this device*/
|
---|
1100 | LOG(("DN_DRAWING_BEGIN (pso=%p, pDev[%d]=%p)", pso, pDev->iDevice, pDev));
|
---|
1101 | break;
|
---|
1102 | }
|
---|
1103 | default:
|
---|
1104 | {
|
---|
1105 | LOG(("unknown iType=%#x", iType));
|
---|
1106 | }
|
---|
1107 | }
|
---|
1108 |
|
---|
1109 | LOGF_LEAVE();
|
---|
1110 | return;
|
---|
1111 | }
|
---|