VirtualBox

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

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

Additions/XFree86/vboxvideo: eliminate some problematic symbols

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 10.4 KB
Line 
1/* $Id: VBoxGuestR3LibVideo.cpp 31409 2010-08-05 13:47:41Z 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#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 int rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq, RT_OFFSETOF(VMMDevReqMousePointer, pointerData) + cbImg, VMMDevReq_SetPointerShape);
102 if (RT_SUCCESS(rc))
103 {
104 pReq->fFlags = fFlags;
105 pReq->xHot = xHot;
106 pReq->yHot = yHot;
107 pReq->width = cx;
108 pReq->height = cy;
109 if (pvImg)
110 memcpy(pReq->pointerData, pvImg, cbImg);
111
112 rc = vbglR3GRPerform(&pReq->header);
113 vbglR3GRFree(&pReq->header);
114 if (RT_SUCCESS(rc))
115 rc = pReq->header.rc;
116 }
117 return rc;
118}
119
120
121/**
122 * Send mouse pointer shape information to the host.
123 * This version of the function accepts a request for clients that
124 * already allocate and manipulate the request structure directly.
125 *
126 * @returns VBox status code.
127 *
128 * @param pReq Pointer to the VMMDevReqMousePointer structure.
129 */
130VBGLR3DECL(int) VbglR3SetPointerShapeReq(VMMDevReqMousePointer *pReq)
131{
132 int rc = vbglR3GRPerform(&pReq->header);
133 if (RT_SUCCESS(rc))
134 rc = pReq->header.rc;
135 return rc;
136}
137
138
139/**
140 * Query the last display change request sent from the host to the guest.
141 *
142 * @returns iprt status value
143 * @param pcx Where to store the horizontal pixel resolution
144 * requested (a value of zero means do not change).
145 * @param pcy Where to store the vertical pixel resolution
146 * requested (a value of zero means do not change).
147 * @param pcBits Where to store the bits per pixel requested (a value
148 * of zero means do not change).
149 * @param iDisplay Where to store the display number the request was for
150 * - 0 for the primary display, 1 for the first
151 * secondary display, etc.
152 * @param fAck whether or not to acknowlege the newest request sent by
153 * the host. If this is set, the function will return the
154 * most recent host request, otherwise it will return the
155 * last request to be acknowleged.
156 *
157 */
158VBGLR3DECL(int) VbglR3GetDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay, bool fAck)
159{
160 VMMDevDisplayChangeRequest2 Req;
161
162 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
163 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
164 AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
165 AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
166 RT_ZERO(Req);
167 vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
168 if (fAck)
169 Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
170 int rc = vbglR3GRPerform(&Req.header);
171 if (RT_SUCCESS(rc))
172 rc = Req.header.rc;
173 if (RT_SUCCESS(rc))
174 {
175 *pcx = Req.xres;
176 *pcy = Req.yres;
177 *pcBits = Req.bpp;
178 *piDisplay = Req.display;
179 }
180 return rc;
181}
182
183
184/**
185 * Query the host as to whether it likes a specific video mode.
186 *
187 * @returns the result of the query
188 * @param cx the width of the mode being queried
189 * @param cy the height of the mode being queried
190 * @param cBits the bpp of the mode being queried
191 */
192VBGLR3DECL(bool) VbglR3HostLikesVideoMode(uint32_t cx, uint32_t cy, uint32_t cBits)
193{
194 bool fRc = true; /* If for some reason we can't contact the host then
195 * we like everything. */
196 int rc;
197 VMMDevVideoModeSupportedRequest req;
198
199 vmmdevInitRequest(&req.header, VMMDevReq_VideoModeSupported);
200 req.width = cx;
201 req.height = cy;
202 req.bpp = cBits;
203 req.fSupported = true;
204 rc = vbglR3GRPerform(&req.header);
205 if (RT_SUCCESS(rc) && RT_SUCCESS(req.header.rc))
206 fRc = req.fSupported;
207 return fRc;
208}
209
210/**
211 * Save video mode parameters to the registry.
212 *
213 * @returns iprt status value
214 * @param pszName the name to save the mode parameters under
215 * @param cx mode width
216 * @param cy mode height
217 * @param cBits bits per pixel for the mode
218 */
219VBGLR3DECL(int) VbglR3SaveVideoMode(const char *pszName, uint32_t cx, uint32_t cy, uint32_t cBits)
220{
221#if defined(VBOX_WITH_GUEST_PROPS)
222 using namespace guestProp;
223
224 char szModeName[MAX_NAME_LEN];
225 char szModeParms[MAX_VALUE_LEN];
226 uint32_t u32ClientId = 0;
227 RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName);
228 RTStrPrintf(szModeParms, sizeof(szModeParms), "%dx%dx%d", cx, cy, cBits);
229 int rc = VbglR3GuestPropConnect(&u32ClientId);
230 if (RT_SUCCESS(rc))
231 rc = VbglR3GuestPropWriteValue(u32ClientId, szModeName, szModeParms);
232 if (u32ClientId != 0)
233 VbglR3GuestPropDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */
234 return rc;
235#else /* !VBOX_WITH_GUEST_PROPS */
236 return VERR_NOT_IMPLEMENTED;
237#endif /* !VBOX_WITH_GUEST_PROPS */
238}
239
240
241/**
242 * Retrieve video mode parameters from the guest property store.
243 *
244 * @returns iprt status value
245 * @param pszName the name under which the mode parameters are saved
246 * @param pcx where to store the mode width
247 * @param pcy where to store the mode height
248 * @param pcBits where to store the bits per pixel for the mode
249 */
250VBGLR3DECL(int) VbglR3RetrieveVideoMode(const char *pszName, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits)
251{
252#if defined(VBOX_WITH_GUEST_PROPS)
253 using namespace guestProp;
254
255/*
256 * First we retreive the video mode which is saved as a string in the
257 * guest property store.
258 */
259 /* The buffer for VbglR3GuestPropReadValue. If this is too small then
260 * something is wrong with the data stored in the property. */
261 char szModeParms[1024];
262 uint32_t u32ClientId = 0;
263 uint32_t cx, cy, cBits;
264
265 int rc = VbglR3GuestPropConnect(&u32ClientId);
266 if (RT_SUCCESS(rc))
267 {
268 char szModeName[MAX_NAME_LEN];
269 RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName);
270 /** @todo add a VbglR3GuestPropReadValueF/FV that does the RTStrPrintf for you. */
271 rc = VbglR3GuestPropReadValue(u32ClientId, szModeName, szModeParms,
272 sizeof(szModeParms), NULL);
273 }
274
275/*
276 * Now we convert the string returned to numeric values.
277 */
278 char *pszNext;
279 if (RT_SUCCESS(rc))
280 /* Extract the width from the string */
281 rc = RTStrToUInt32Ex(szModeParms, &pszNext, 10, &cx);
282 if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
283 rc = VERR_PARSE_ERROR;
284 if (RT_SUCCESS(rc))
285 {
286 /* Extract the height from the string */
287 ++pszNext;
288 rc = RTStrToUInt32Ex(pszNext, &pszNext, 10, &cy);
289 }
290 if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
291 rc = VERR_PARSE_ERROR;
292 if (RT_SUCCESS(rc))
293 {
294 /* Extract the bpp from the string */
295 ++pszNext;
296 rc = RTStrToUInt32Full(pszNext, 10, &cBits);
297 }
298 if (rc != VINF_SUCCESS)
299 rc = VERR_PARSE_ERROR;
300
301/*
302 * And clean up and return the values if we successfully obtained them.
303 */
304 if (u32ClientId != 0)
305 VbglR3GuestPropDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */
306 if (RT_SUCCESS(rc))
307 {
308 *pcx = cx;
309 *pcy = cy;
310 *pcBits = cBits;
311 }
312 return rc;
313#else /* !VBOX_WITH_GUEST_PROPS */
314 return VERR_NOT_IMPLEMENTED;
315#endif /* !VBOX_WITH_GUEST_PROPS */
316}
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