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 |
|
---|
31 | #include "VBGLR3Internal.h"
|
---|
32 |
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Enable or disable video acceleration.
|
---|
36 | *
|
---|
37 | * @returns VBox status code.
|
---|
38 | *
|
---|
39 | * @param fEnable Pass zero to disable, any other value to enable.
|
---|
40 | */
|
---|
41 | VBGLR3DECL(int) VbglR3VideoAccelEnable(bool fEnable)
|
---|
42 | {
|
---|
43 | VMMDevVideoAccelEnable Req;
|
---|
44 | vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelEnable);
|
---|
45 | Req.u32Enable = fEnable;
|
---|
46 | Req.cbRingBuffer = VBVA_RING_BUFFER_SIZE;
|
---|
47 | Req.fu32Status = 0;
|
---|
48 | return vbglR3GRPerform(&Req.header);
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Flush the video buffer.
|
---|
54 | *
|
---|
55 | * @returns VBox status code.
|
---|
56 | */
|
---|
57 | VBGLR3DECL(int) VbglR3VideoAccelFlush(void)
|
---|
58 | {
|
---|
59 | VMMDevVideoAccelFlush Req;
|
---|
60 | vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelFlush);
|
---|
61 | return vbglR3GRPerform(&Req.header);
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Send mouse pointer shape information to the host.
|
---|
67 | *
|
---|
68 | * @returns VBox status code.
|
---|
69 | *
|
---|
70 | * @param fFlags Mouse pointer flags.
|
---|
71 | * @param xHot X coordinate of hot spot.
|
---|
72 | * @param yHot Y coordinate of hot spot.
|
---|
73 | * @param cx Pointer width.
|
---|
74 | * @param cy Pointer height.
|
---|
75 | * @param pvImg Pointer to the image data (can be NULL).
|
---|
76 | * @param cbImg Size of the image data pointed to by pvImg.
|
---|
77 | */
|
---|
78 | VBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvImg, size_t cbImg)
|
---|
79 | {
|
---|
80 | VMMDevReqMousePointer *pReq;
|
---|
81 | int rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq, RT_OFFSETOF(VMMDevReqMousePointer, pointerData) + cbImg, VMMDevReq_SetPointerShape);
|
---|
82 | if (RT_SUCCESS(rc))
|
---|
83 | {
|
---|
84 | pReq->fFlags = fFlags;
|
---|
85 | pReq->xHot = xHot;
|
---|
86 | pReq->yHot = yHot;
|
---|
87 | pReq->width = cx;
|
---|
88 | pReq->height = cy;
|
---|
89 | if (pvImg)
|
---|
90 | memcpy(pReq->pointerData, pvImg, cbImg);
|
---|
91 |
|
---|
92 | rc = vbglR3GRPerform(&pReq->header);
|
---|
93 | vbglR3GRFree(&pReq->header);
|
---|
94 | if (RT_SUCCESS(rc))
|
---|
95 | rc = pReq->header.rc;
|
---|
96 | }
|
---|
97 | return rc;
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Send mouse pointer shape information to the host.
|
---|
103 | * This version of the function accepts a request for clients that
|
---|
104 | * already allocate and manipulate the request structure directly.
|
---|
105 | *
|
---|
106 | * @returns VBox status code.
|
---|
107 | *
|
---|
108 | * @param pReq Pointer to the VMMDevReqMousePointer structure.
|
---|
109 | */
|
---|
110 | VBGLR3DECL(int) VbglR3SetPointerShapeReq(VMMDevReqMousePointer *pReq)
|
---|
111 | {
|
---|
112 | int rc = vbglR3GRPerform(&pReq->header);
|
---|
113 | if (RT_SUCCESS(rc))
|
---|
114 | rc = pReq->header.rc;
|
---|
115 | return rc;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Query the last display change request.
|
---|
121 | *
|
---|
122 | * @returns iprt status value
|
---|
123 | * @param pcx Where to store the horizontal pixel resolution (0 = do not change).
|
---|
124 | * @param pcy Where to store the vertical pixel resolution (0 = do not change).
|
---|
125 | * @param pcBits Where to store the bits per pixel (0 = do not change).
|
---|
126 | * @param iDisplay Where to store the display number the request was for - 0 for the
|
---|
127 | * primary display, 1 for the first secondary, etc.
|
---|
128 | */
|
---|
129 | VBGLR3DECL(int) VbglR3GetLastDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits,
|
---|
130 | 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
|
---|
140 | vmmdevInitRequest(&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. 0 means no
|
---|
160 | * change.
|
---|
161 | * @param pcy on success, where to return the requested display height. 0 means no
|
---|
162 | * change.
|
---|
163 | * @param pcBits on success, where to return the requested bits per pixel. 0 means no
|
---|
164 | * change.
|
---|
165 | * @param piDisplay on success, where to return the index of the display to be changed.
|
---|
166 | */
|
---|
167 | VBGLR3DECL(int) VbglR3DisplayChangeWaitEvent(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits,
|
---|
168 | uint32_t *piDisplay)
|
---|
169 | {
|
---|
170 | VBoxGuestWaitEventInfo waitEvent;
|
---|
171 | int rc;
|
---|
172 |
|
---|
173 | #ifndef VBOX_VBGLR3_XFREE86
|
---|
174 | AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
|
---|
175 | AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
|
---|
176 | AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
|
---|
177 | AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
|
---|
178 | #endif
|
---|
179 | waitEvent.u32TimeoutIn = RT_INDEFINITE_WAIT;
|
---|
180 | waitEvent.u32EventMaskIn = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
|
---|
181 | waitEvent.u32Result = VBOXGUEST_WAITEVENT_ERROR;
|
---|
182 | waitEvent.u32EventFlagsOut = 0;
|
---|
183 | rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
|
---|
184 | if (RT_SUCCESS(rc))
|
---|
185 | {
|
---|
186 | /* did we get the right event? */
|
---|
187 | if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
|
---|
188 | {
|
---|
189 | VMMDevDisplayChangeRequest2 Req = { { 0 } };
|
---|
190 | vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
|
---|
191 | Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
|
---|
192 | int rc = vbglR3GRPerform(&Req.header);
|
---|
193 | if (RT_SUCCESS(rc))
|
---|
194 | rc = Req.header.rc;
|
---|
195 | if (RT_SUCCESS(rc))
|
---|
196 | {
|
---|
197 | *pcx = Req.xres;
|
---|
198 | *pcy = Req.yres;
|
---|
199 | *pcBits = Req.bpp;
|
---|
200 | *piDisplay = Req.display;
|
---|
201 | }
|
---|
202 | }
|
---|
203 | else
|
---|
204 | rc = VERR_TRY_AGAIN;
|
---|
205 | }
|
---|
206 | return rc;
|
---|
207 | }
|
---|
208 |
|
---|
209 | /**
|
---|
210 | * Query the host as to whether it likes a specific video mode.
|
---|
211 | *
|
---|
212 | * @returns the result of the query
|
---|
213 | * @param cx the width of the mode being queried
|
---|
214 | * @param cy the height of the mode being queried
|
---|
215 | * @param cBits the bpp of the mode being queried
|
---|
216 | */
|
---|
217 | VBGLR3DECL(bool) VbglR3HostLikesVideoMode(uint32_t cx, uint32_t cy,
|
---|
218 | uint32_t cBits)
|
---|
219 | {
|
---|
220 | bool fRc = false;
|
---|
221 | int rc;
|
---|
222 | VMMDevVideoModeSupportedRequest req;
|
---|
223 |
|
---|
224 | vmmdevInitRequest(&req.header, VMMDevReq_VideoModeSupported);
|
---|
225 | req.width = cx;
|
---|
226 | req.height = cy;
|
---|
227 | req.bpp = cBits;
|
---|
228 | req.fSupported = false;
|
---|
229 | rc = vbglR3GRPerform(&req.header);
|
---|
230 | if (RT_SUCCESS(rc) && RT_SUCCESS(req.header.rc))
|
---|
231 | fRc = req.fSupported;
|
---|
232 | else
|
---|
233 | LogRelFunc(("error querying video mode supported status from VMMDev."
|
---|
234 | "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req.header.rc));
|
---|
235 | return fRc;
|
---|
236 | }
|
---|
237 |
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Report the maximum resolution that we currently support to the host.
|
---|
241 | *
|
---|
242 | * @returns iprt status value
|
---|
243 | * @param u32Width the maximum horizontal resolution
|
---|
244 | * @param u32Height the maximum vertical resolution
|
---|
245 | */
|
---|
246 | VBGLR3DECL(int) VbglR3ReportMaxGuestResolution(uint32_t u32Width, uint32_t u32Height)
|
---|
247 | {
|
---|
248 | int rc = VERR_UNRESOLVED_ERROR;
|
---|
249 | VMMDevReqGuestResolution req;
|
---|
250 |
|
---|
251 | vmmdevInitRequest(&req.header, VMMDevReq_SetMaxGuestResolution);
|
---|
252 | req.u32MaxWidth = u32Width;
|
---|
253 | req.u32MaxHeight = u32Height;
|
---|
254 | rc = vbglR3GRPerform(&req.header);
|
---|
255 | if (!RT_SUCCESS(rc) || !RT_SUCCESS(req.header.rc))
|
---|
256 | LogRelFunc(("error reporting maximum supported resolution to VMMDev. "
|
---|
257 | "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req.header.rc));
|
---|
258 | if (RT_SUCCESS(rc))
|
---|
259 | rc = req.header.rc;
|
---|
260 | return rc;
|
---|
261 | }
|
---|