VirtualBox

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

Last change on this file since 31384 was 31384, checked in by vboxsync, 15 years ago

X11 additions: fixed unresolved symbols for Xorg < 7.0

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 10.3 KB
Line 
1/* $Id: VBoxGuestR3LibVideo.cpp 31384 2010-08-05 09:18:11Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Video.
4 */
5
6/*
7 * Copyright (C) 2007-2009 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#include <iprt/mem.h>
33#include <iprt/string.h>
34#include <VBox/log.h>
35#include <VBox/HostServices/GuestPropertySvc.h> /* For Save and RetrieveVideoMode */
36
37#include "VBGLR3Internal.h"
38
39#ifdef VBOX_VBGLR3_XFREE86
40/* Rather than try to resolve all the header file conflicts, I will just
41 prototype what we need here. */
42extern "C" void* xf86memcpy(void*,const void*,xf86size_t);
43# undef memcpy
44# define memcpy xf86memcpy
45#endif /* VBOX_VBGLR3_XFREE86 */
46
47#define VIDEO_PROP_PREFIX "/VirtualBox/GuestAdd/Vbgl/Video/"
48
49/**
50 * Enable or disable video acceleration.
51 *
52 * @returns VBox status code.
53 *
54 * @param fEnable Pass zero to disable, any other value to enable.
55 */
56VBGLR3DECL(int) VbglR3VideoAccelEnable(bool fEnable)
57{
58 VMMDevVideoAccelEnable Req;
59 vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelEnable);
60 Req.u32Enable = fEnable;
61 Req.cbRingBuffer = VBVA_RING_BUFFER_SIZE;
62 Req.fu32Status = 0;
63 return vbglR3GRPerform(&Req.header);
64}
65
66
67/**
68 * Flush the video buffer.
69 *
70 * @returns VBox status code.
71 */
72VBGLR3DECL(int) VbglR3VideoAccelFlush(void)
73{
74 VMMDevVideoAccelFlush Req;
75 vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelFlush);
76 return vbglR3GRPerform(&Req.header);
77}
78
79
80/**
81 * Send mouse pointer shape information to the host.
82 *
83 * @returns VBox status code.
84 *
85 * @param fFlags Mouse pointer flags.
86 * @param xHot X coordinate of hot spot.
87 * @param yHot Y coordinate of hot spot.
88 * @param cx Pointer width.
89 * @param cy Pointer height.
90 * @param pvImg Pointer to the image data (can be NULL).
91 * @param cbImg Size of the image data pointed to by pvImg.
92 */
93VBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvImg, size_t cbImg)
94{
95 VMMDevReqMousePointer *pReq;
96 int rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq, RT_OFFSETOF(VMMDevReqMousePointer, pointerData) + cbImg, VMMDevReq_SetPointerShape);
97 if (RT_SUCCESS(rc))
98 {
99 pReq->fFlags = fFlags;
100 pReq->xHot = xHot;
101 pReq->yHot = yHot;
102 pReq->width = cx;
103 pReq->height = cy;
104 if (pvImg)
105 memcpy(pReq->pointerData, pvImg, cbImg);
106
107 rc = vbglR3GRPerform(&pReq->header);
108 vbglR3GRFree(&pReq->header);
109 if (RT_SUCCESS(rc))
110 rc = pReq->header.rc;
111 }
112 return rc;
113}
114
115
116/**
117 * Send mouse pointer shape information to the host.
118 * This version of the function accepts a request for clients that
119 * already allocate and manipulate the request structure directly.
120 *
121 * @returns VBox status code.
122 *
123 * @param pReq Pointer to the VMMDevReqMousePointer structure.
124 */
125VBGLR3DECL(int) VbglR3SetPointerShapeReq(VMMDevReqMousePointer *pReq)
126{
127 int rc = vbglR3GRPerform(&pReq->header);
128 if (RT_SUCCESS(rc))
129 rc = pReq->header.rc;
130 return rc;
131}
132
133
134/**
135 * Query the last display change request sent from the host to the guest.
136 *
137 * @returns iprt status value
138 * @param pcx Where to store the horizontal pixel resolution
139 * requested (a value of zero means do not change).
140 * @param pcy Where to store the vertical pixel resolution
141 * requested (a value of zero means do not change).
142 * @param pcBits Where to store the bits per pixel requested (a value
143 * of zero means do not change).
144 * @param iDisplay Where to store the display number the request was for
145 * - 0 for the primary display, 1 for the first
146 * secondary display, etc.
147 * @param fAck whether or not to acknowlege the newest request sent by
148 * the host. If this is set, the function will return the
149 * most recent host request, otherwise it will return the
150 * last request to be acknowleged.
151 *
152 */
153VBGLR3DECL(int) VbglR3GetDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay, bool fAck)
154{
155 VMMDevDisplayChangeRequest2 Req;
156
157 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
158 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
159 AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
160 AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
161 RT_ZERO(Req);
162 vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
163 if (fAck)
164 Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
165 int rc = vbglR3GRPerform(&Req.header);
166 if (RT_SUCCESS(rc))
167 rc = Req.header.rc;
168 if (RT_SUCCESS(rc))
169 {
170 *pcx = Req.xres;
171 *pcy = Req.yres;
172 *pcBits = Req.bpp;
173 *piDisplay = Req.display;
174 }
175 return rc;
176}
177
178
179/**
180 * Query the host as to whether it likes a specific video mode.
181 *
182 * @returns the result of the query
183 * @param cx the width of the mode being queried
184 * @param cy the height of the mode being queried
185 * @param cBits the bpp of the mode being queried
186 */
187VBGLR3DECL(bool) VbglR3HostLikesVideoMode(uint32_t cx, uint32_t cy, uint32_t cBits)
188{
189 bool fRc = true; /* If for some reason we can't contact the host then
190 * we like everything. */
191 int rc;
192 VMMDevVideoModeSupportedRequest req;
193
194 vmmdevInitRequest(&req.header, VMMDevReq_VideoModeSupported);
195 req.width = cx;
196 req.height = cy;
197 req.bpp = cBits;
198 req.fSupported = true;
199 rc = vbglR3GRPerform(&req.header);
200 if (RT_SUCCESS(rc) && RT_SUCCESS(req.header.rc))
201 fRc = req.fSupported;
202 return fRc;
203}
204
205/**
206 * Save video mode parameters to the registry.
207 *
208 * @returns iprt status value
209 * @param pszName the name to save the mode parameters under
210 * @param cx mode width
211 * @param cy mode height
212 * @param cBits bits per pixel for the mode
213 */
214VBGLR3DECL(int) VbglR3SaveVideoMode(const char *pszName, uint32_t cx, uint32_t cy, uint32_t cBits)
215{
216#if defined(VBOX_WITH_GUEST_PROPS)
217 using namespace guestProp;
218
219 char szModeName[MAX_NAME_LEN];
220 char szModeParms[MAX_VALUE_LEN];
221 uint32_t u32ClientId = 0;
222 RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName);
223 RTStrPrintf(szModeParms, sizeof(szModeParms), "%dx%dx%d", cx, cy, cBits);
224 int rc = VbglR3GuestPropConnect(&u32ClientId);
225 if (RT_SUCCESS(rc))
226 rc = VbglR3GuestPropWriteValue(u32ClientId, szModeName, szModeParms);
227 if (u32ClientId != 0)
228 VbglR3GuestPropDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */
229 return rc;
230#else /* !VBOX_WITH_GUEST_PROPS */
231 return VERR_NOT_IMPLEMENTED;
232#endif /* !VBOX_WITH_GUEST_PROPS */
233}
234
235
236/**
237 * Retrieve video mode parameters from the guest property store.
238 *
239 * @returns iprt status value
240 * @param pszName the name under which the mode parameters are saved
241 * @param pcx where to store the mode width
242 * @param pcy where to store the mode height
243 * @param pcBits where to store the bits per pixel for the mode
244 */
245VBGLR3DECL(int) VbglR3RetrieveVideoMode(const char *pszName, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits)
246{
247#if defined(VBOX_WITH_GUEST_PROPS)
248 using namespace guestProp;
249
250/*
251 * First we retreive the video mode which is saved as a string in the
252 * guest property store.
253 */
254 /* The buffer for VbglR3GuestPropReadValue. If this is too small then
255 * something is wrong with the data stored in the property. */
256 char szModeParms[1024];
257 uint32_t u32ClientId = 0;
258 uint32_t cx, cy, cBits;
259
260 int rc = VbglR3GuestPropConnect(&u32ClientId);
261 if (RT_SUCCESS(rc))
262 {
263 char szModeName[MAX_NAME_LEN];
264 RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName);
265 /** @todo add a VbglR3GuestPropReadValueF/FV that does the RTStrPrintf for you. */
266 rc = VbglR3GuestPropReadValue(u32ClientId, szModeName, szModeParms,
267 sizeof(szModeParms), NULL);
268 }
269
270/*
271 * Now we convert the string returned to numeric values.
272 */
273 char *pszNext;
274 if (RT_SUCCESS(rc))
275 /* Extract the width from the string */
276 rc = RTStrToUInt32Ex(szModeParms, &pszNext, 10, &cx);
277 if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
278 rc = VERR_PARSE_ERROR;
279 if (RT_SUCCESS(rc))
280 {
281 /* Extract the height from the string */
282 ++pszNext;
283 rc = RTStrToUInt32Ex(pszNext, &pszNext, 10, &cy);
284 }
285 if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
286 rc = VERR_PARSE_ERROR;
287 if (RT_SUCCESS(rc))
288 {
289 /* Extract the bpp from the string */
290 ++pszNext;
291 rc = RTStrToUInt32Full(pszNext, 10, &cBits);
292 }
293 if (rc != VINF_SUCCESS)
294 rc = VERR_PARSE_ERROR;
295
296/*
297 * And clean up and return the values if we successfully obtained them.
298 */
299 if (u32ClientId != 0)
300 VbglR3GuestPropDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */
301 if (RT_SUCCESS(rc))
302 {
303 *pcx = cx;
304 *pcy = cy;
305 *pcBits = cBits;
306 }
307 return rc;
308#else /* !VBOX_WITH_GUEST_PROPS */
309 return VERR_NOT_IMPLEMENTED;
310#endif /* !VBOX_WITH_GUEST_PROPS */
311}
Note: See TracBrowser for help on using the repository browser.

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