VirtualBox

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

Last change on this file since 9996 was 9996, checked in by vboxsync, 17 years ago

Additions/common: fixed some error codes in VBoxGuestR3LibVideo.cpp

  • Property svn:eol-style set to native
File size: 10.5 KB
Line 
1/* $Id$ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Video.
4 */
5
6/*
7 * Copyright (C) 2007 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/string.h>
27#include <iprt/mem.h>
28#include <iprt/assert.h>
29#include <VBox/log.h>
30#include <VBox/HostServices/VBoxInfoSvc.h> /* For Save and RetrieveVideoMode */
31
32#include "VBGLR3Internal.h"
33
34
35/**
36 * Enable or disable video acceleration.
37 *
38 * @returns VBox status code.
39 *
40 * @param fEnable Pass zero to disable, any other value to enable.
41 */
42VBGLR3DECL(int) VbglR3VideoAccelEnable(bool fEnable)
43{
44 VMMDevVideoAccelEnable Req;
45 vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelEnable);
46 Req.u32Enable = fEnable;
47 Req.cbRingBuffer = VBVA_RING_BUFFER_SIZE;
48 Req.fu32Status = 0;
49 return vbglR3GRPerform(&Req.header);
50}
51
52
53/**
54 * Flush the video buffer.
55 *
56 * @returns VBox status code.
57 */
58VBGLR3DECL(int) VbglR3VideoAccelFlush(void)
59{
60 VMMDevVideoAccelFlush Req;
61 vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelFlush);
62 return vbglR3GRPerform(&Req.header);
63}
64
65
66/**
67 * Send mouse pointer shape information to the host.
68 *
69 * @returns VBox status code.
70 *
71 * @param fFlags Mouse pointer flags.
72 * @param xHot X coordinate of hot spot.
73 * @param yHot Y coordinate of hot spot.
74 * @param cx Pointer width.
75 * @param cy Pointer height.
76 * @param pvImg Pointer to the image data (can be NULL).
77 * @param cbImg Size of the image data pointed to by pvImg.
78 */
79VBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvImg, size_t cbImg)
80{
81 VMMDevReqMousePointer *pReq;
82 int rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq, RT_OFFSETOF(VMMDevReqMousePointer, pointerData) + cbImg, VMMDevReq_SetPointerShape);
83 if (RT_SUCCESS(rc))
84 {
85 pReq->fFlags = fFlags;
86 pReq->xHot = xHot;
87 pReq->yHot = yHot;
88 pReq->width = cx;
89 pReq->height = cy;
90 if (pvImg)
91 memcpy(pReq->pointerData, pvImg, cbImg);
92
93 rc = vbglR3GRPerform(&pReq->header);
94 vbglR3GRFree(&pReq->header);
95 if (RT_SUCCESS(rc))
96 rc = pReq->header.rc;
97 }
98 return rc;
99}
100
101
102/**
103 * Send mouse pointer shape information to the host.
104 * This version of the function accepts a request for clients that
105 * already allocate and manipulate the request structure directly.
106 *
107 * @returns VBox status code.
108 *
109 * @param pReq Pointer to the VMMDevReqMousePointer structure.
110 */
111VBGLR3DECL(int) VbglR3SetPointerShapeReq(VMMDevReqMousePointer *pReq)
112{
113 int rc = vbglR3GRPerform(&pReq->header);
114 if (RT_SUCCESS(rc))
115 rc = pReq->header.rc;
116 return rc;
117}
118
119
120/**
121 * Query the last display change request.
122 *
123 * @returns iprt status value
124 * @param pcx Where to store the horizontal pixel resolution (0 = do not change).
125 * @param pcy Where to store the vertical pixel resolution (0 = do not change).
126 * @param pcBits Where to store the bits per pixel (0 = do not change).
127 * @param iDisplay Where to store the display number the request was for - 0 for the
128 * primary display, 1 for the first secondary, etc.
129 */
130VBGLR3DECL(int) VbglR3GetLastDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay)
131{
132 VMMDevDisplayChangeRequest2 Req = { { 0 } };
133
134#ifndef VBOX_VBGLR3_XFREE86
135 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
136 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
137 AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
138 AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
139#endif
140vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
141 int rc = vbglR3GRPerform(&Req.header);
142 if (RT_SUCCESS(rc))
143 rc = Req.header.rc;
144 if (RT_SUCCESS(rc))
145 {
146 *pcx = Req.xres;
147 *pcy = Req.yres;
148 *pcBits = Req.bpp;
149 *piDisplay = Req.display;
150 }
151 return rc;
152}
153
154/**
155 * Wait for a display change request event from the host. These events must have been
156 * activated previously using VbglR3CtlFilterMask.
157 *
158 * @returns IPRT status value
159 * @param pcx On success, where to return the requested display width.
160 * 0 means no change.
161 * @param pcy On success, where to return the requested display height.
162 * 0 means no change.
163 * @param pcBits On success, where to return the requested bits per pixel.
164 * 0 means no change.
165 * @param piDisplay On success, where to return the index of the display to be changed.
166 */
167VBGLR3DECL(int) VbglR3DisplayChangeWaitEvent(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits, uint32_t *piDisplay)
168{
169 VBoxGuestWaitEventInfo waitEvent;
170 int rc;
171
172#ifndef VBOX_VBGLR3_XFREE86
173 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
174 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
175 AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
176 AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
177#endif
178 waitEvent.u32TimeoutIn = RT_INDEFINITE_WAIT;
179 waitEvent.u32EventMaskIn = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
180 waitEvent.u32Result = VBOXGUEST_WAITEVENT_ERROR;
181 waitEvent.u32EventFlagsOut = 0;
182 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
183 if (RT_SUCCESS(rc))
184 {
185 /* did we get the right event? */
186 if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
187 {
188 VMMDevDisplayChangeRequest2 Req = { { 0 } };
189 vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
190 Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
191 int rc = vbglR3GRPerform(&Req.header);
192 if (RT_SUCCESS(rc))
193 rc = Req.header.rc;
194 if (RT_SUCCESS(rc))
195 {
196 *pcx = Req.xres;
197 *pcy = Req.yres;
198 *pcBits = Req.bpp;
199 *piDisplay = Req.display;
200 }
201 }
202 else
203 rc = VERR_TRY_AGAIN;
204 }
205 return rc;
206}
207
208/**
209 * Query the host as to whether it likes a specific video mode.
210 *
211 * @returns the result of the query
212 * @param cx the width of the mode being queried
213 * @param cy the height of the mode being queried
214 * @param cBits the bpp of the mode being queried
215 */
216VBGLR3DECL(bool) VbglR3HostLikesVideoMode(uint32_t cx, uint32_t cy, uint32_t cBits)
217{
218 bool fRc = false;
219 int rc;
220 VMMDevVideoModeSupportedRequest req;
221
222 vmmdevInitRequest(&req.header, VMMDevReq_VideoModeSupported);
223 req.width = cx;
224 req.height = cy;
225 req.bpp = cBits;
226 req.fSupported = false;
227 rc = vbglR3GRPerform(&req.header);
228 if (RT_SUCCESS(rc) && RT_SUCCESS(req.header.rc))
229 fRc = req.fSupported;
230 else
231 LogRelFunc(("error querying video mode supported status from VMMDev."
232 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req.header.rc));
233 return fRc;
234}
235
236/**
237 * Save video mode parameters to the registry.
238 *
239 * @returns iprt status value
240 * @param pszName the name to save the mode parameters under
241 * @param cx mode width
242 * @param cy mode height
243 * @param cBits bits per pixel for the mode
244 */
245VBGLR3DECL(int) VbglR3SaveVideoMode(const char *pszName, uint32_t cx, uint32_t cy, uint32_t cBits)
246{
247 using namespace svcInfo;
248
249 char szModeName[KEY_MAX_LEN];
250 char szModeParms[KEY_MAX_VALUE_LEN];
251 uint32_t u32ClientId = 0;
252 RTStrPrintf(szModeName, sizeof(szModeName), "VideoMode/%s", pszName);
253 RTStrPrintf(szModeParms, sizeof(szModeParms), "%dx%dx%d", cx, cy, cBits);
254 int rc = VbglR3InfoSvcConnect(&u32ClientId);
255 if (RT_SUCCESS(rc))
256 rc = VbglR3InfoSvcWriteKey(u32ClientId, szModeName, szModeParms);
257 if (u32ClientId != 0)
258 VbglR3InfoSvcDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */
259 return rc;
260}
261
262
263/**
264 * Retrieve video mode parameters from the registry.
265 *
266 * @returns iprt status value
267 * @param pszName the name under which the mode parameters are saved
268 * @param pcx where to store the mode width
269 * @param pcy where to store the mode height
270 * @param pcBits where to store the bits per pixel for the mode
271 */
272VBGLR3DECL(int) VbglR3RetrieveVideoMode(const char *pszName, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits)
273{
274 using namespace svcInfo;
275
276 char szModeParms[KEY_MAX_VALUE_LEN];
277 char *pszNext;
278 uint32_t u32ClientId = 0;
279 uint32_t cx, cy, cBits;
280
281 int rc = VbglR3InfoSvcConnect(&u32ClientId);
282 if (RT_SUCCESS(rc))
283 {
284 char szModeName[KEY_MAX_LEN];
285 RTStrPrintf(szModeName, sizeof(szModeName), "VideoMode/%s", pszName);
286 rc = VbglR3InfoSvcReadKey(u32ClientId, szModeName, szModeParms,
287 sizeof(szModeParms), NULL); /** @todo add a VbglR3InfoSvcReadKeyF/FV that does the RTStrPrintf for you. */
288 }
289 if (RT_SUCCESS(rc))
290 /* Extract the width from the string */
291 rc = RTStrToUInt32Ex(szModeParms, &pszNext, 10, &cx);
292 if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
293 rc = VERR_PARSE_ERROR;
294 if (RT_SUCCESS(rc))
295 {
296 ++pszNext;
297 rc = RTStrToUInt32Ex(pszNext, &pszNext, 10, &cy);
298 }
299 if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
300 rc = VERR_PARSE_ERROR;
301 if (RT_SUCCESS(rc))
302 {
303 ++pszNext;
304 rc = RTStrToUInt32Full(pszNext, 10, &cBits);
305 }
306 if (rc != VINF_SUCCESS)
307 rc = VERR_PARSE_ERROR;
308 if (u32ClientId != 0)
309 VbglR3InfoSvcDisconnect(u32ClientId); /* Return value ignored, because what can we do anyway? */
310 if (RT_SUCCESS(rc))
311 {
312 *pcx = cx;
313 *pcy = cy;
314 *pcBits = cBits;
315 }
316 return rc;
317}
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