VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

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