1 | /* $Id: VBoxGuestR3LibVideo.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Video.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include "VBoxGuestR3LibInternal.h"
|
---|
42 |
|
---|
43 | #include <VBox/log.h>
|
---|
44 | #include <VBox/HostServices/GuestPropertySvc.h> /* For Save and RetrieveVideoMode */
|
---|
45 | #include <iprt/assert.h>
|
---|
46 | #include <iprt/mem.h>
|
---|
47 | #include <iprt/string.h>
|
---|
48 |
|
---|
49 | #ifdef VBOX_VBGLR3_XFREE86
|
---|
50 | /* Rather than try to resolve all the header file conflicts, I will just
|
---|
51 | prototype what we need here. */
|
---|
52 | extern "C" void* xf86memcpy(void*,const void*,xf86size_t);
|
---|
53 | # undef memcpy
|
---|
54 | # define memcpy xf86memcpy
|
---|
55 | extern "C" void* xf86memset(const void*,int,xf86size_t);
|
---|
56 | # undef memset
|
---|
57 | # define memset xf86memset
|
---|
58 | #endif /* VBOX_VBGLR3_XFREE86 */
|
---|
59 |
|
---|
60 |
|
---|
61 | /*********************************************************************************************************************************
|
---|
62 | * Defined Constants And Macros *
|
---|
63 | *********************************************************************************************************************************/
|
---|
64 | #define VIDEO_PROP_PREFIX "/VirtualBox/GuestAdd/Vbgl/Video/"
|
---|
65 |
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Enable or disable video acceleration.
|
---|
69 | *
|
---|
70 | * @returns VBox status code.
|
---|
71 | *
|
---|
72 | * @param fEnable Pass zero to disable, any other value to enable.
|
---|
73 | */
|
---|
74 | VBGLR3DECL(int) VbglR3VideoAccelEnable(bool fEnable)
|
---|
75 | {
|
---|
76 | VMMDevVideoAccelEnable Req;
|
---|
77 | vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelEnable);
|
---|
78 | Req.u32Enable = fEnable;
|
---|
79 | Req.cbRingBuffer = VMMDEV_VBVA_RING_BUFFER_SIZE;
|
---|
80 | Req.fu32Status = 0;
|
---|
81 | return vbglR3GRPerform(&Req.header);
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Flush the video buffer.
|
---|
87 | *
|
---|
88 | * @returns VBox status code.
|
---|
89 | */
|
---|
90 | VBGLR3DECL(int) VbglR3VideoAccelFlush(void)
|
---|
91 | {
|
---|
92 | VMMDevVideoAccelFlush Req;
|
---|
93 | vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelFlush);
|
---|
94 | return vbglR3GRPerform(&Req.header);
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Send mouse pointer shape information to the host.
|
---|
100 | *
|
---|
101 | * @returns VBox status code.
|
---|
102 | *
|
---|
103 | * @param fFlags Mouse pointer flags.
|
---|
104 | * @param xHot X coordinate of hot spot.
|
---|
105 | * @param yHot Y coordinate of hot spot.
|
---|
106 | * @param cx Pointer width.
|
---|
107 | * @param cy Pointer height.
|
---|
108 | * @param pvImg Pointer to the image data (can be NULL).
|
---|
109 | * @param cbImg Size of the image data pointed to by pvImg.
|
---|
110 | */
|
---|
111 | VBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy,
|
---|
112 | const void *pvImg, size_t cbImg)
|
---|
113 | {
|
---|
114 | VMMDevReqMousePointer *pReq;
|
---|
115 | size_t cbReq = vmmdevGetMousePointerReqSize(cx, cy);
|
---|
116 | AssertReturn( !pvImg
|
---|
117 | || cbReq == RT_UOFFSETOF(VMMDevReqMousePointer, pointerData) + cbImg,
|
---|
118 | VERR_INVALID_PARAMETER);
|
---|
119 | int rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq, cbReq, VMMDevReq_SetPointerShape);
|
---|
120 | if (RT_SUCCESS(rc))
|
---|
121 | {
|
---|
122 | pReq->fFlags = fFlags;
|
---|
123 | pReq->xHot = xHot;
|
---|
124 | pReq->yHot = yHot;
|
---|
125 | pReq->width = cx;
|
---|
126 | pReq->height = cy;
|
---|
127 | if (pvImg)
|
---|
128 | memcpy(pReq->pointerData, pvImg, cbImg);
|
---|
129 |
|
---|
130 | rc = vbglR3GRPerform(&pReq->header);
|
---|
131 | if (RT_SUCCESS(rc))
|
---|
132 | rc = pReq->header.rc;
|
---|
133 | vbglR3GRFree(&pReq->header);
|
---|
134 | }
|
---|
135 | return rc;
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Send mouse pointer shape information to the host.
|
---|
141 | * This version of the function accepts a request for clients that
|
---|
142 | * already allocate and manipulate the request structure directly.
|
---|
143 | *
|
---|
144 | * @returns VBox status code.
|
---|
145 | *
|
---|
146 | * @param pReq Pointer to the VMMDevReqMousePointer structure.
|
---|
147 | */
|
---|
148 | VBGLR3DECL(int) VbglR3SetPointerShapeReq(VMMDevReqMousePointer *pReq)
|
---|
149 | {
|
---|
150 | int rc = vbglR3GRPerform(&pReq->header);
|
---|
151 | if (RT_SUCCESS(rc))
|
---|
152 | rc = pReq->header.rc;
|
---|
153 | return rc;
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Query the last display change request sent from the host to the guest.
|
---|
159 | *
|
---|
160 | * @returns iprt status value
|
---|
161 | * @param pcx Where to store the horizontal pixel resolution
|
---|
162 | * @param pcy Where to store the vertical pixel resolution
|
---|
163 | * requested (a value of zero means do not change).
|
---|
164 | * @param pcBits Where to store the bits per pixel requested (a value
|
---|
165 | * of zero means do not change).
|
---|
166 | * @param piDisplay Where to store the display number the request was for
|
---|
167 | * - 0 for the primary display, 1 for the first
|
---|
168 | * secondary display, etc.
|
---|
169 | * @param fAck whether or not to acknowledge the newest request sent by
|
---|
170 | * the host. If this is set, the function will return the
|
---|
171 | * most recent host request, otherwise it will return the
|
---|
172 | * last request to be acknowledged.
|
---|
173 | *
|
---|
174 | */
|
---|
175 | static int getDisplayChangeRequest2(uint32_t *pcx, uint32_t *pcy,
|
---|
176 | uint32_t *pcBits, uint32_t *piDisplay,
|
---|
177 | bool fAck)
|
---|
178 | {
|
---|
179 | VMMDevDisplayChangeRequest2 Req;
|
---|
180 |
|
---|
181 | AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
|
---|
182 | AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
|
---|
183 | AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
|
---|
184 | AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
|
---|
185 | RT_ZERO(Req);
|
---|
186 | vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
|
---|
187 | if (fAck)
|
---|
188 | Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
|
---|
189 | int rc = vbglR3GRPerform(&Req.header);
|
---|
190 | if (RT_SUCCESS(rc))
|
---|
191 | rc = Req.header.rc;
|
---|
192 | if (RT_SUCCESS(rc))
|
---|
193 | {
|
---|
194 | *pcx = Req.xres;
|
---|
195 | *pcy = Req.yres;
|
---|
196 | *pcBits = Req.bpp;
|
---|
197 | *piDisplay = Req.display;
|
---|
198 | }
|
---|
199 | return rc;
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * Query the last display change request sent from the host to the guest.
|
---|
205 | *
|
---|
206 | * @returns iprt status value
|
---|
207 | * @param pcx Where to store the horizontal pixel resolution
|
---|
208 | * requested (a value of zero means do not change).
|
---|
209 | * @param pcy Where to store the vertical pixel resolution
|
---|
210 | * requested (a value of zero means do not change).
|
---|
211 | * @param pcBits Where to store the bits per pixel requested (a value
|
---|
212 | * of zero means do not change).
|
---|
213 | * @param piDisplay Where to store the display number the request was for
|
---|
214 | * - 0 for the primary display, 1 for the first
|
---|
215 | * secondary display, etc.
|
---|
216 | * @param fAck whether or not to acknowledge the newest request sent by
|
---|
217 | * the host. If this is set, the function will return the
|
---|
218 | * most recent host request, otherwise it will return the
|
---|
219 | * last request to be acknowledged.
|
---|
220 | *
|
---|
221 | * @param pdx New horizontal position of the secondary monitor.
|
---|
222 | * Optional.
|
---|
223 | * @param pdy New vertical position of the secondary monitor.
|
---|
224 | * Optional.
|
---|
225 | * @param pfEnabled Secondary monitor is enabled or not. Optional.
|
---|
226 | * @param pfChangeOrigin Whether the mode hint retrieved included
|
---|
227 | * information about origin/display offset inside the
|
---|
228 | * frame-buffer. Optional.
|
---|
229 | *
|
---|
230 | */
|
---|
231 | VBGLR3DECL(int) VbglR3GetDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy,
|
---|
232 | uint32_t *pcBits,
|
---|
233 | uint32_t *piDisplay,
|
---|
234 | uint32_t *pdx, uint32_t *pdy,
|
---|
235 | bool *pfEnabled,
|
---|
236 | bool *pfChangeOrigin,
|
---|
237 | bool fAck)
|
---|
238 | {
|
---|
239 | VMMDevDisplayChangeRequestEx Req;
|
---|
240 | int rc = VINF_SUCCESS;
|
---|
241 |
|
---|
242 | AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
|
---|
243 | AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
|
---|
244 | AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
|
---|
245 | AssertPtrNullReturn(pdx, VERR_INVALID_PARAMETER);
|
---|
246 | AssertPtrNullReturn(pdy, VERR_INVALID_PARAMETER);
|
---|
247 | AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
|
---|
248 | AssertPtrNullReturn(pfEnabled, VERR_INVALID_PARAMETER);
|
---|
249 | AssertPtrNullReturn(pfChangeOrigin, VERR_INVALID_PARAMETER);
|
---|
250 |
|
---|
251 | RT_ZERO(Req);
|
---|
252 | rc = vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequestEx);
|
---|
253 | AssertRCReturn(rc, rc);
|
---|
254 | if (fAck)
|
---|
255 | Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
|
---|
256 | rc = vbglR3GRPerform(&Req.header);
|
---|
257 | if (RT_SUCCESS(rc))
|
---|
258 | rc = Req.header.rc;
|
---|
259 | if (RT_SUCCESS(rc))
|
---|
260 | {
|
---|
261 | *pcx = Req.xres;
|
---|
262 | *pcy = Req.yres;
|
---|
263 | *pcBits = Req.bpp;
|
---|
264 | *piDisplay = Req.display;
|
---|
265 | if (pdx)
|
---|
266 | *pdx = Req.cxOrigin;
|
---|
267 | if (pdy)
|
---|
268 | *pdy = Req.cyOrigin;
|
---|
269 | if (pfEnabled)
|
---|
270 | *pfEnabled = Req.fEnabled;
|
---|
271 | if (pfChangeOrigin)
|
---|
272 | *pfChangeOrigin = Req.fChangeOrigin;
|
---|
273 | return VINF_SUCCESS;
|
---|
274 | }
|
---|
275 |
|
---|
276 | /* NEEDS TESTING: test below with current Additions on VBox 4.1 or older. */
|
---|
277 | /** @todo Can we find some standard grep-able string for "NEEDS TESTING"? */
|
---|
278 | if (rc == VERR_NOT_IMPLEMENTED) /* Fall back to the old API. */
|
---|
279 | {
|
---|
280 | if (pfEnabled)
|
---|
281 | *pfEnabled = true;
|
---|
282 | if (pfChangeOrigin)
|
---|
283 | *pfChangeOrigin = false;
|
---|
284 | return getDisplayChangeRequest2(pcx, pcy, pcBits, piDisplay, fAck);
|
---|
285 | }
|
---|
286 | return rc;
|
---|
287 | }
|
---|
288 |
|
---|
289 |
|
---|
290 | /**
|
---|
291 | * Query the last display change request sent from the host to the guest.
|
---|
292 | *
|
---|
293 | * @returns iprt status value
|
---|
294 | * @param cDisplaysIn How many elements in the paDisplays array.
|
---|
295 | * @param pcDisplaysOut How many elements were returned.
|
---|
296 | * @param paDisplays Display information.
|
---|
297 | * @param fAck Whether or not to acknowledge the newest request sent by
|
---|
298 | * the host. If this is set, the function will return the
|
---|
299 | * most recent host request, otherwise it will return the
|
---|
300 | * last request to be acknowledged.
|
---|
301 | */
|
---|
302 | VBGLR3DECL(int) VbglR3GetDisplayChangeRequestMulti(uint32_t cDisplaysIn,
|
---|
303 | uint32_t *pcDisplaysOut,
|
---|
304 | VMMDevDisplayDef *paDisplays,
|
---|
305 | bool fAck)
|
---|
306 | {
|
---|
307 | VMMDevDisplayChangeRequestMulti *pReq;
|
---|
308 | size_t cbDisplays;
|
---|
309 | size_t cbAlloc;
|
---|
310 | int rc = VINF_SUCCESS;
|
---|
311 |
|
---|
312 | AssertReturn(cDisplaysIn > 0 && cDisplaysIn <= 64 /* VBOX_VIDEO_MAX_SCREENS */, VERR_INVALID_PARAMETER);
|
---|
313 | AssertPtrReturn(pcDisplaysOut, VERR_INVALID_PARAMETER);
|
---|
314 | AssertPtrReturn(paDisplays, VERR_INVALID_PARAMETER);
|
---|
315 |
|
---|
316 | cbDisplays = cDisplaysIn * sizeof(VMMDevDisplayDef);
|
---|
317 | cbAlloc = RT_UOFFSETOF(VMMDevDisplayChangeRequestMulti, aDisplays) + cbDisplays;
|
---|
318 | pReq = (VMMDevDisplayChangeRequestMulti *)RTMemTmpAlloc(cbAlloc);
|
---|
319 | AssertPtrReturn(pReq, VERR_NO_MEMORY);
|
---|
320 |
|
---|
321 | memset(pReq, 0, cbAlloc);
|
---|
322 | rc = vmmdevInitRequest(&pReq->header, VMMDevReq_GetDisplayChangeRequestMulti);
|
---|
323 | AssertRCReturnStmt(rc, RTMemTmpFree(pReq), rc);
|
---|
324 |
|
---|
325 | pReq->header.size += (uint32_t)cbDisplays;
|
---|
326 | pReq->cDisplays = cDisplaysIn;
|
---|
327 | if (fAck)
|
---|
328 | pReq->eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
|
---|
329 |
|
---|
330 | rc = vbglR3GRPerform(&pReq->header);
|
---|
331 | AssertRCReturnStmt(rc, RTMemTmpFree(pReq), rc);
|
---|
332 |
|
---|
333 | rc = pReq->header.rc;
|
---|
334 | if (RT_SUCCESS(rc))
|
---|
335 | {
|
---|
336 | memcpy(paDisplays, pReq->aDisplays, pReq->cDisplays * sizeof(VMMDevDisplayDef));
|
---|
337 | *pcDisplaysOut = pReq->cDisplays;
|
---|
338 | }
|
---|
339 |
|
---|
340 | RTMemTmpFree(pReq);
|
---|
341 | return rc;
|
---|
342 | }
|
---|
343 |
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * Query the host as to whether it likes a specific video mode.
|
---|
347 | *
|
---|
348 | * @returns the result of the query
|
---|
349 | * @param cx the width of the mode being queried
|
---|
350 | * @param cy the height of the mode being queried
|
---|
351 | * @param cBits the bpp of the mode being queried
|
---|
352 | */
|
---|
353 | VBGLR3DECL(bool) VbglR3HostLikesVideoMode(uint32_t cx, uint32_t cy, uint32_t cBits)
|
---|
354 | {
|
---|
355 | bool fRc = true; /* If for some reason we can't contact the host then
|
---|
356 | * we like everything. */
|
---|
357 | int rc;
|
---|
358 | VMMDevVideoModeSupportedRequest req;
|
---|
359 |
|
---|
360 | vmmdevInitRequest(&req.header, VMMDevReq_VideoModeSupported);
|
---|
361 | req.width = cx;
|
---|
362 | req.height = cy;
|
---|
363 | req.bpp = cBits;
|
---|
364 | req.fSupported = true;
|
---|
365 | rc = vbglR3GRPerform(&req.header);
|
---|
366 | if (RT_SUCCESS(rc) && RT_SUCCESS(req.header.rc))
|
---|
367 | fRc = req.fSupported;
|
---|
368 | return fRc;
|
---|
369 | }
|
---|
370 |
|
---|
371 | /**
|
---|
372 | * Get the highest screen number for which there is a saved video mode or "0"
|
---|
373 | * if there are no saved modes.
|
---|
374 | *
|
---|
375 | * @returns iprt status value
|
---|
376 | * @returns VERR_NOT_SUPPORTED if the guest property service is not available.
|
---|
377 | * @param pcScreen where to store the virtual screen number
|
---|
378 | */
|
---|
379 | VBGLR3DECL(int) VbglR3VideoModeGetHighestSavedScreen(unsigned *pcScreen)
|
---|
380 | {
|
---|
381 | #if defined(VBOX_WITH_GUEST_PROPS)
|
---|
382 | int rc;
|
---|
383 | HGCMCLIENTID idClient = 0;
|
---|
384 | PVBGLR3GUESTPROPENUM pHandle = NULL;
|
---|
385 | const char *pszName = NULL;
|
---|
386 | unsigned cHighestScreen = 0;
|
---|
387 |
|
---|
388 | /* Validate input. */
|
---|
389 | AssertPtrReturn(pcScreen, VERR_INVALID_POINTER);
|
---|
390 |
|
---|
391 | /* Query the data. */
|
---|
392 | rc = VbglR3GuestPropConnect(&idClient);
|
---|
393 | if (RT_SUCCESS(rc))
|
---|
394 | {
|
---|
395 | const char *pszPattern = VIDEO_PROP_PREFIX"*";
|
---|
396 | rc = VbglR3GuestPropEnum(idClient, &pszPattern, 1, &pHandle, &pszName, NULL, NULL, NULL);
|
---|
397 | int rc2 = VbglR3GuestPropDisconnect(idClient);
|
---|
398 | if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
|
---|
399 | rc = rc2;
|
---|
400 | }
|
---|
401 |
|
---|
402 | /* Process the data. */
|
---|
403 | while (RT_SUCCESS(rc) && pszName != NULL)
|
---|
404 | {
|
---|
405 | uint32_t cScreen;
|
---|
406 |
|
---|
407 | rc = RTStrToUInt32Full(pszName + sizeof(VIDEO_PROP_PREFIX) - 1, 10, &cScreen);
|
---|
408 | if (RT_SUCCESS(rc)) /* There may be similar properties with text. */
|
---|
409 | cHighestScreen = RT_MAX(cHighestScreen, cScreen);
|
---|
410 | rc = VbglR3GuestPropEnumNext(pHandle, &pszName, NULL, NULL, NULL);
|
---|
411 | }
|
---|
412 |
|
---|
413 | VbglR3GuestPropEnumFree(pHandle);
|
---|
414 |
|
---|
415 | /* Return result. */
|
---|
416 | if (RT_SUCCESS(rc))
|
---|
417 | *pcScreen = cHighestScreen;
|
---|
418 | return rc;
|
---|
419 | #else /* !VBOX_WITH_GUEST_PROPS */
|
---|
420 | RT_NOREF(pcScreen);
|
---|
421 | return VERR_NOT_SUPPORTED;
|
---|
422 | #endif /* !VBOX_WITH_GUEST_PROPS */
|
---|
423 | }
|
---|
424 |
|
---|
425 | /**
|
---|
426 | * Save video mode parameters to the guest property store.
|
---|
427 | *
|
---|
428 | * @returns iprt status value
|
---|
429 | * @param idScreen The virtual screen number.
|
---|
430 | * @param cx mode width
|
---|
431 | * @param cy mode height
|
---|
432 | * @param cBits bits per pixel for the mode
|
---|
433 | * @param x virtual screen X offset
|
---|
434 | * @param y virtual screen Y offset
|
---|
435 | * @param fEnabled is this virtual screen enabled?
|
---|
436 | */
|
---|
437 | VBGLR3DECL(int) VbglR3SaveVideoMode(unsigned idScreen, unsigned cx, unsigned cy, unsigned cBits,
|
---|
438 | unsigned x, unsigned y, bool fEnabled)
|
---|
439 | {
|
---|
440 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
441 | unsigned cHighestScreen = 0;
|
---|
442 | int rc = VbglR3VideoModeGetHighestSavedScreen(&cHighestScreen);
|
---|
443 | if (RT_SUCCESS(rc))
|
---|
444 | {
|
---|
445 | HGCMCLIENTID idClient = 0;
|
---|
446 | rc = VbglR3GuestPropConnect(&idClient);
|
---|
447 | if (RT_SUCCESS(rc))
|
---|
448 | {
|
---|
449 | int rc2;
|
---|
450 | char szModeName[GUEST_PROP_MAX_NAME_LEN];
|
---|
451 | char szModeParms[GUEST_PROP_MAX_VALUE_LEN];
|
---|
452 | RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX "%u", idScreen);
|
---|
453 | RTStrPrintf(szModeParms, sizeof(szModeParms), "%ux%ux%u,%ux%u,%u", cx, cy, cBits, x, y, (unsigned) fEnabled);
|
---|
454 |
|
---|
455 | rc = VbglR3GuestPropWriteValue(idClient, szModeName, szModeParms);
|
---|
456 | /* Write out the mode using the legacy name too, in case the user
|
---|
457 | * re-installs older Additions. */
|
---|
458 | if (idScreen == 0)
|
---|
459 | {
|
---|
460 | RTStrPrintf(szModeParms, sizeof(szModeParms), "%ux%ux%u", cx, cy, cBits);
|
---|
461 | VbglR3GuestPropWriteValue(idClient, VIDEO_PROP_PREFIX "SavedMode", szModeParms);
|
---|
462 | }
|
---|
463 |
|
---|
464 | rc2 = VbglR3GuestPropDisconnect(idClient);
|
---|
465 | if (rc != VINF_PERMISSION_DENIED)
|
---|
466 | {
|
---|
467 | if (RT_SUCCESS(rc))
|
---|
468 | rc = rc2;
|
---|
469 | if (RT_SUCCESS(rc))
|
---|
470 | {
|
---|
471 | /* Sanity check 1. We do not try to make allowance for someone else
|
---|
472 | * changing saved settings at the same time as us. */
|
---|
473 | bool fEnabled2 = false;
|
---|
474 | unsigned cx2 = 0;
|
---|
475 | unsigned cy2 = 0;
|
---|
476 | unsigned cBits2 = 0;
|
---|
477 | unsigned x2 = 0;
|
---|
478 | unsigned y2 = 0;
|
---|
479 | rc = VbglR3RetrieveVideoMode(idScreen, &cx2, &cy2, &cBits2, &x2, &y2, &fEnabled2);
|
---|
480 | if ( RT_SUCCESS(rc)
|
---|
481 | && (cx != cx2 || cy != cy2 || cBits != cBits2 || x != x2 || y != y2 || fEnabled != fEnabled2))
|
---|
482 | rc = VERR_WRITE_ERROR;
|
---|
483 | /* Sanity check 2. Same comment. */
|
---|
484 | else if (RT_SUCCESS(rc))
|
---|
485 | {
|
---|
486 | unsigned cHighestScreen2 = 0;
|
---|
487 | rc = VbglR3VideoModeGetHighestSavedScreen(&cHighestScreen2);
|
---|
488 | if (RT_SUCCESS(rc))
|
---|
489 | if (cHighestScreen2 != RT_MAX(cHighestScreen, idScreen))
|
---|
490 | rc = VERR_INTERNAL_ERROR;
|
---|
491 | }
|
---|
492 | }
|
---|
493 | }
|
---|
494 | }
|
---|
495 | }
|
---|
496 | return rc;
|
---|
497 | #else /* !VBOX_WITH_GUEST_PROPS */
|
---|
498 | RT_NOREF(idScreen, cx, cy, cBits, x, y, fEnabled);
|
---|
499 | return VERR_NOT_SUPPORTED;
|
---|
500 | #endif /* !VBOX_WITH_GUEST_PROPS */
|
---|
501 | }
|
---|
502 |
|
---|
503 |
|
---|
504 | /**
|
---|
505 | * Retrieve video mode parameters from the guest property store.
|
---|
506 | *
|
---|
507 | * @returns iprt status value
|
---|
508 | * @param idScreen The virtual screen number.
|
---|
509 | * @param pcx where to store the mode width
|
---|
510 | * @param pcy where to store the mode height
|
---|
511 | * @param pcBits where to store the bits per pixel for the mode
|
---|
512 | * @param px where to store the virtual screen X offset
|
---|
513 | * @param py where to store the virtual screen Y offset
|
---|
514 | * @param pfEnabled where to store whether this virtual screen is enabled
|
---|
515 | */
|
---|
516 | VBGLR3DECL(int) VbglR3RetrieveVideoMode(unsigned idScreen,
|
---|
517 | unsigned *pcx, unsigned *pcy,
|
---|
518 | unsigned *pcBits,
|
---|
519 | unsigned *px, unsigned *py,
|
---|
520 | bool *pfEnabled)
|
---|
521 | {
|
---|
522 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
523 | /*
|
---|
524 | * First we retrieve the video mode which is saved as a string in the
|
---|
525 | * guest property store.
|
---|
526 | */
|
---|
527 | HGCMCLIENTID idClient = 0;
|
---|
528 | int rc = VbglR3GuestPropConnect(&idClient);
|
---|
529 | if (RT_SUCCESS(rc))
|
---|
530 | {
|
---|
531 | int rc2;
|
---|
532 | /* The buffer for VbglR3GuestPropReadValue. If this is too small then
|
---|
533 | * something is wrong with the data stored in the property. */
|
---|
534 | char szModeParms[1024];
|
---|
535 | char szModeName[GUEST_PROP_MAX_NAME_LEN]; /** @todo add a VbglR3GuestPropReadValueF/FV that does the RTStrPrintf for you. */
|
---|
536 | RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX "%u", idScreen);
|
---|
537 | rc = VbglR3GuestPropReadValue(idClient, szModeName, szModeParms, sizeof(szModeParms), NULL);
|
---|
538 | /* Try legacy single screen name. */
|
---|
539 | if (rc == VERR_NOT_FOUND && idScreen == 0)
|
---|
540 | rc = VbglR3GuestPropReadValue(idClient,
|
---|
541 | VIDEO_PROP_PREFIX"SavedMode",
|
---|
542 | szModeParms, sizeof(szModeParms),
|
---|
543 | NULL);
|
---|
544 | rc2 = VbglR3GuestPropDisconnect(idClient);
|
---|
545 | if (RT_SUCCESS(rc))
|
---|
546 | rc = rc2;
|
---|
547 |
|
---|
548 | /*
|
---|
549 | * Now we convert the string returned to numeric values.
|
---|
550 | */
|
---|
551 | if (RT_SUCCESS(rc))
|
---|
552 | {
|
---|
553 | /* Mandatory chunk: 640x480x32 */
|
---|
554 | char *pszNext;
|
---|
555 | uint32_t cx = 0;
|
---|
556 | rc = VERR_PARSE_ERROR;
|
---|
557 | rc2 = RTStrToUInt32Ex(szModeParms, &pszNext, 10, &cx);
|
---|
558 | if (rc2 == VWRN_TRAILING_CHARS && *pszNext == 'x')
|
---|
559 | {
|
---|
560 | uint32_t cy = 0;
|
---|
561 | rc2 = RTStrToUInt32Ex(pszNext + 1, &pszNext, 10, &cy);
|
---|
562 | if (rc2 == VWRN_TRAILING_CHARS && *pszNext == 'x')
|
---|
563 | {
|
---|
564 | uint8_t cBits = 0;
|
---|
565 | rc2 = RTStrToUInt8Ex(pszNext + 1, &pszNext, 10, &cBits);
|
---|
566 | if (rc2 == VINF_SUCCESS || rc2 == VWRN_TRAILING_CHARS)
|
---|
567 | {
|
---|
568 | /* Optional chunk: ,32x64,1 (we fail if this is partially there) */
|
---|
569 | uint32_t x = 0;
|
---|
570 | uint32_t y = 0;
|
---|
571 | uint8_t fEnabled = 1;
|
---|
572 | if (rc2 == VINF_SUCCESS)
|
---|
573 | rc = VINF_SUCCESS;
|
---|
574 | else if (*pszNext == ',')
|
---|
575 | {
|
---|
576 | rc2 = RTStrToUInt32Ex(pszNext + 1, &pszNext, 10, &x);
|
---|
577 | if (rc2 == VWRN_TRAILING_CHARS && *pszNext == 'x')
|
---|
578 | {
|
---|
579 | rc2 = RTStrToUInt32Ex(pszNext + 1, &pszNext, 10, &y);
|
---|
580 | if (rc2 == VWRN_TRAILING_CHARS && *pszNext == ',')
|
---|
581 | {
|
---|
582 | rc2 = RTStrToUInt8Ex(pszNext + 1, &pszNext, 10, &fEnabled);
|
---|
583 | if (rc2 == VINF_SUCCESS)
|
---|
584 | rc = VINF_SUCCESS;
|
---|
585 | }
|
---|
586 | }
|
---|
587 | }
|
---|
588 |
|
---|
589 | /*
|
---|
590 | * Set result if successful.
|
---|
591 | */
|
---|
592 | if (rc == VINF_SUCCESS)
|
---|
593 | {
|
---|
594 | if (pcx)
|
---|
595 | *pcx = cx;
|
---|
596 | if (pcy)
|
---|
597 | *pcy = cy;
|
---|
598 | if (pcBits)
|
---|
599 | *pcBits = cBits;
|
---|
600 | if (px)
|
---|
601 | *px = x;
|
---|
602 | if (py)
|
---|
603 | *py = y;
|
---|
604 | if (pfEnabled)
|
---|
605 | *pfEnabled = RT_BOOL(fEnabled);
|
---|
606 | }
|
---|
607 | }
|
---|
608 | }
|
---|
609 | }
|
---|
610 | }
|
---|
611 | }
|
---|
612 |
|
---|
613 | return rc;
|
---|
614 | #else /* !VBOX_WITH_GUEST_PROPS */
|
---|
615 | RT_NOREF(idScreen, pcx, pcy, pcBits, px, py, pfEnabled);
|
---|
616 | return VERR_NOT_SUPPORTED;
|
---|
617 | #endif /* !VBOX_WITH_GUEST_PROPS */
|
---|
618 | }
|
---|