VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibVideo.cpp@ 50041

Last change on this file since 50041 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 13.3 KB
Line 
1/* $Id: VBoxGuestR3LibVideo.cpp 44528 2013-02-04 14:27:54Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Video.
4 */
5
6/*
7 * Copyright (C) 2007-2012 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/assert.h>
32#ifndef VBOX_VBGLR3_XFREE86
33# include <iprt/mem.h>
34#endif
35#include <iprt/string.h>
36#include <VBox/log.h>
37#include <VBox/HostServices/GuestPropertySvc.h> /* For Save and RetrieveVideoMode */
38
39#include "VBGLR3Internal.h"
40
41#ifdef VBOX_VBGLR3_XFREE86
42/* Rather than try to resolve all the header file conflicts, I will just
43 prototype what we need here. */
44extern "C" void* xf86memcpy(void*,const void*,xf86size_t);
45# undef memcpy
46# define memcpy xf86memcpy
47extern "C" void* xf86memset(const void*,int,xf86size_t);
48# undef memset
49# define memset xf86memset
50#endif /* VBOX_VBGLR3_XFREE86 */
51
52#define VIDEO_PROP_PREFIX "/VirtualBox/GuestAdd/Vbgl/Video/"
53
54/**
55 * Enable or disable video acceleration.
56 *
57 * @returns VBox status code.
58 *
59 * @param fEnable Pass zero to disable, any other value to enable.
60 */
61VBGLR3DECL(int) VbglR3VideoAccelEnable(bool fEnable)
62{
63 VMMDevVideoAccelEnable Req;
64 vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelEnable);
65 Req.u32Enable = fEnable;
66 Req.cbRingBuffer = VBVA_RING_BUFFER_SIZE;
67 Req.fu32Status = 0;
68 return vbglR3GRPerform(&Req.header);
69}
70
71
72/**
73 * Flush the video buffer.
74 *
75 * @returns VBox status code.
76 */
77VBGLR3DECL(int) VbglR3VideoAccelFlush(void)
78{
79 VMMDevVideoAccelFlush Req;
80 vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelFlush);
81 return vbglR3GRPerform(&Req.header);
82}
83
84
85/**
86 * Send mouse pointer shape information to the host.
87 *
88 * @returns VBox status code.
89 *
90 * @param fFlags Mouse pointer flags.
91 * @param xHot X coordinate of hot spot.
92 * @param yHot Y coordinate of hot spot.
93 * @param cx Pointer width.
94 * @param cy Pointer height.
95 * @param pvImg Pointer to the image data (can be NULL).
96 * @param cbImg Size of the image data pointed to by pvImg.
97 */
98VBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvImg, size_t cbImg)
99{
100 VMMDevReqMousePointer *pReq;
101 size_t cbReq = vmmdevGetMousePointerReqSize(cx, cy);
102 AssertReturn( !pvImg
103 || cbReq == RT_OFFSETOF(VMMDevReqMousePointer, pointerData) + cbImg,
104 VERR_INVALID_PARAMETER);
105 int rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq, cbReq,
106 VMMDevReq_SetPointerShape);
107 if (RT_SUCCESS(rc))
108 {
109 pReq->fFlags = fFlags;
110 pReq->xHot = xHot;
111 pReq->yHot = yHot;
112 pReq->width = cx;
113 pReq->height = cy;
114 if (pvImg)
115 memcpy(pReq->pointerData, pvImg, cbImg);
116
117 rc = vbglR3GRPerform(&pReq->header);
118 if (RT_SUCCESS(rc))
119 rc = pReq->header.rc;
120 vbglR3GRFree(&pReq->header);
121 }
122 return rc;
123}
124
125
126/**
127 * Send mouse pointer shape information to the host.
128 * This version of the function accepts a request for clients that
129 * already allocate and manipulate the request structure directly.
130 *
131 * @returns VBox status code.
132 *
133 * @param pReq Pointer to the VMMDevReqMousePointer structure.
134 */
135VBGLR3DECL(int) VbglR3SetPointerShapeReq(VMMDevReqMousePointer *pReq)
136{
137 int rc = vbglR3GRPerform(&pReq->header);
138 if (RT_SUCCESS(rc))
139 rc = pReq->header.rc;
140 return rc;
141}
142/**
143 * Query the last display change request sent from the host to the guest.
144 *
145 * @returns iprt status value
146 * @param pcx Where to store the horizontal pixel resolution
147 * requested (a value of zero means do not change).
148 * @param pcy Where to store the vertical pixel resolution
149 * requested (a value of zero means do not change).
150 * @param pcBits Where to store the bits per pixel requested (a value
151 * of zero means do not change).
152 * @param iDisplay Where to store the display number the request was for
153 * - 0 for the primary display, 1 for the first
154 * secondary display, etc.
155 * @param fAck whether or not to acknowledge the newest request sent by
156 * the host. If this is set, the function will return the
157 * most recent host request, otherwise it will return the
158 * last request to be acknowledged.
159 *
160 * @param pcOriginX New horizontal position of the secondary monitor.
161 * @param pcOriginY New vertical position of the secondary monitor.
162 * param pfEnabled Secondary monitor is enabled or not.
163 *
164 */
165VBGLR3DECL(int) VbglR3GetDisplayChangeRequestEx(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits,
166 uint32_t *piDisplay, uint32_t *pcOriginX, uint32_t *pcOriginY,
167 bool *pfEnabled, bool fAck)
168{
169 VMMDevDisplayChangeRequestEx Req;
170 int rc = VINF_SUCCESS;
171 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
172 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
173 AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
174 AssertPtrReturn(pcOriginX, VERR_INVALID_PARAMETER);
175 AssertPtrReturn(pcOriginY, VERR_INVALID_PARAMETER);
176 AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
177 AssertPtrReturn(pfEnabled, VERR_INVALID_PARAMETER);
178 RT_ZERO(Req);
179 rc = vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequestEx);
180 if (RT_FAILURE(rc))
181 {
182 LogRelFlowFunc(("DisplayChangeRequest Extended not supported. Can't Init the Req.\n"));
183 return rc;
184 }
185
186 if (fAck)
187 Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
188 rc = vbglR3GRPerform(&Req.header);
189 if (RT_SUCCESS(rc))
190 rc = Req.header.rc;
191 if (RT_SUCCESS(rc))
192 {
193 *pcx = Req.xres;
194 *pcy = Req.yres;
195 *pcBits = Req.bpp;
196 *piDisplay = Req.display;
197 *pcOriginX = Req.cxOrigin;
198 *pcOriginY = Req.cyOrigin;
199 *pfEnabled = Req.fEnabled;
200 LogRel(("VbglR3GetDisplayChangeRequestEx: pcx=%d pcy=%d display=%d orgX=%d orgY=%d and Enabled=%d\n",
201 *pcx, *pcy, *piDisplay, *pcOriginX, *pcOriginY, *pfEnabled));
202 }
203 return rc;
204}
205
206
207/**
208 * Query the last display change request sent from the host to the guest.
209 *
210 * @returns iprt status value
211 * @param pcx Where to store the horizontal pixel resolution
212 * @param pcy Where to store the vertical pixel resolution
213 * requested (a value of zero means do not change).
214 * @param pcBits Where to store the bits per pixel requested (a value
215 * of zero means do not change).
216 * @param iDisplay Where to store the display number the request was for
217 * - 0 for the primary display, 1 for the first
218 * secondary display, etc.
219 * @param fAck whether or not to acknowledge the newest request sent by
220 * the host. If this is set, the function will return the
221 * most recent host request, otherwise it will return the
222 * last request to be acknowledged.
223 *
224 */
225VBGLR3DECL(int) VbglR3GetDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay, bool fAck)
226{
227 VMMDevDisplayChangeRequest2 Req;
228
229 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
230 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
231 AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
232 AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
233 RT_ZERO(Req);
234 vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
235 if (fAck)
236 Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
237 int rc = vbglR3GRPerform(&Req.header);
238 if (RT_SUCCESS(rc))
239 rc = Req.header.rc;
240 if (RT_SUCCESS(rc))
241 {
242 *pcx = Req.xres;
243 *pcy = Req.yres;
244 *pcBits = Req.bpp;
245 *piDisplay = Req.display;
246 }
247 return rc;
248}
249
250
251/**
252 * Query the host as to whether it likes a specific video mode.
253 *
254 * @returns the result of the query
255 * @param cx the width of the mode being queried
256 * @param cy the height of the mode being queried
257 * @param cBits the bpp of the mode being queried
258 */
259VBGLR3DECL(bool) VbglR3HostLikesVideoMode(uint32_t cx, uint32_t cy, uint32_t cBits)
260{
261 bool fRc = true; /* If for some reason we can't contact the host then
262 * we like everything. */
263 int rc;
264 VMMDevVideoModeSupportedRequest req;
265
266 vmmdevInitRequest(&req.header, VMMDevReq_VideoModeSupported);
267 req.width = cx;
268 req.height = cy;
269 req.bpp = cBits;
270 req.fSupported = true;
271 rc = vbglR3GRPerform(&req.header);
272 if (RT_SUCCESS(rc) && RT_SUCCESS(req.header.rc))
273 fRc = req.fSupported;
274 return fRc;
275}
276
277/**
278 * Save video mode parameters to the registry.
279 *
280 * @returns iprt status value
281 * @param pszName the name to save the mode parameters under
282 * @param cx mode width
283 * @param cy mode height
284 * @param cBits bits per pixel for the mode
285 */
286VBGLR3DECL(int) VbglR3SaveVideoMode(const char *pszName, uint32_t cx, uint32_t cy, uint32_t cBits)
287{
288#if defined(VBOX_WITH_GUEST_PROPS)
289 using namespace guestProp;
290
291 char szModeName[MAX_NAME_LEN];
292 char szModeParms[MAX_VALUE_LEN];
293 uint32_t u32ClientId = 0;
294 RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName);
295 RTStrPrintf(szModeParms, sizeof(szModeParms), "%dx%dx%d", cx, cy, cBits);
296 int rc = VbglR3GuestPropConnect(&u32ClientId);
297 if (RT_SUCCESS(rc))
298 rc = VbglR3GuestPropWriteValue(u32ClientId, szModeName, szModeParms);
299 if (u32ClientId != 0)
300 VbglR3GuestPropDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */
301 return rc;
302#else /* !VBOX_WITH_GUEST_PROPS */
303 return VERR_NOT_IMPLEMENTED;
304#endif /* !VBOX_WITH_GUEST_PROPS */
305}
306
307
308/**
309 * Retrieve video mode parameters from the guest property store.
310 *
311 * @returns iprt status value
312 * @param pszName the name under which the mode parameters are saved
313 * @param pcx where to store the mode width
314 * @param pcy where to store the mode height
315 * @param pcBits where to store the bits per pixel for the mode
316 */
317VBGLR3DECL(int) VbglR3RetrieveVideoMode(const char *pszName, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits)
318{
319#if defined(VBOX_WITH_GUEST_PROPS)
320 using namespace guestProp;
321
322/*
323 * First we retrieve the video mode which is saved as a string in the
324 * guest property store.
325 */
326 /* The buffer for VbglR3GuestPropReadValue. If this is too small then
327 * something is wrong with the data stored in the property. */
328 char szModeParms[1024];
329 uint32_t u32ClientId = 0;
330 uint32_t cx, cy, cBits;
331
332 int rc = VbglR3GuestPropConnect(&u32ClientId);
333 if (RT_SUCCESS(rc))
334 {
335 char szModeName[MAX_NAME_LEN];
336 RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName);
337 /** @todo add a VbglR3GuestPropReadValueF/FV that does the RTStrPrintf for you. */
338 rc = VbglR3GuestPropReadValue(u32ClientId, szModeName, szModeParms,
339 sizeof(szModeParms), NULL);
340 }
341
342/*
343 * Now we convert the string returned to numeric values.
344 */
345 char *pszNext;
346 if (RT_SUCCESS(rc))
347 /* Extract the width from the string */
348 rc = RTStrToUInt32Ex(szModeParms, &pszNext, 10, &cx);
349 if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
350 rc = VERR_PARSE_ERROR;
351 if (RT_SUCCESS(rc))
352 {
353 /* Extract the height from the string */
354 ++pszNext;
355 rc = RTStrToUInt32Ex(pszNext, &pszNext, 10, &cy);
356 }
357 if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
358 rc = VERR_PARSE_ERROR;
359 if (RT_SUCCESS(rc))
360 {
361 /* Extract the bpp from the string */
362 ++pszNext;
363 rc = RTStrToUInt32Full(pszNext, 10, &cBits);
364 }
365 if (rc != VINF_SUCCESS)
366 rc = VERR_PARSE_ERROR;
367
368/*
369 * And clean up and return the values if we successfully obtained them.
370 */
371 if (u32ClientId != 0)
372 VbglR3GuestPropDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */
373 if (RT_SUCCESS(rc))
374 {
375 *pcx = cx;
376 *pcy = cy;
377 *pcBits = cBits;
378 }
379 return rc;
380#else /* !VBOX_WITH_GUEST_PROPS */
381 return VERR_NOT_IMPLEMENTED;
382#endif /* !VBOX_WITH_GUEST_PROPS */
383}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette