VirtualBox

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

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

Additions/x11 and common: simplify requests for getting video mode hints and introduce a generic wait event request

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