1 | /* $Id$ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Video.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007 innotek GmbH
|
---|
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 |
|
---|
18 |
|
---|
19 | /*******************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *******************************************************************************/
|
---|
22 | #include <iprt/string.h>
|
---|
23 | #include <iprt/mem.h>
|
---|
24 | #include <iprt/assert.h>
|
---|
25 |
|
---|
26 | #include "VBGLR3Internal.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Enable or disable video acceleration.
|
---|
31 | *
|
---|
32 | * @returns VBox status code.
|
---|
33 | *
|
---|
34 | * @param fEnable Pass zero to disable, any other value to enable.
|
---|
35 | */
|
---|
36 | VBGLR3DECL(int) VbglR3VideoAccelEnable(bool fEnable)
|
---|
37 | {
|
---|
38 | VMMDevVideoAccelEnable Req;
|
---|
39 | vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelEnable);
|
---|
40 | Req.u32Enable = fEnable;
|
---|
41 | Req.cbRingBuffer = VBVA_RING_BUFFER_SIZE;
|
---|
42 | Req.fu32Status = 0;
|
---|
43 | return vbglR3GRPerform(&Req.header);
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Flush the video buffer.
|
---|
49 | *
|
---|
50 | * @returns VBox status code.
|
---|
51 | */
|
---|
52 | VBGLR3DECL(int) VbglR3VideoAccelFlush(void)
|
---|
53 | {
|
---|
54 | VMMDevVideoAccelFlush Req;
|
---|
55 | vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelFlush);
|
---|
56 | return vbglR3GRPerform(&Req.header);
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Send mouse pointer shape information to the host.
|
---|
62 | *
|
---|
63 | * @returns VBox status code.
|
---|
64 | *
|
---|
65 | * @param fFlags Mouse pointer flags.
|
---|
66 | * @param xHot X coordinate of hot spot.
|
---|
67 | * @param yHot Y coordinate of hot spot.
|
---|
68 | * @param cx Pointer width.
|
---|
69 | * @param cy Pointer height.
|
---|
70 | * @param pvImg Pointer to the image data (can be NULL).
|
---|
71 | * @param cbImg Size of the image data pointed to by pvImg.
|
---|
72 | */
|
---|
73 | VBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvImg, size_t cbImg)
|
---|
74 | {
|
---|
75 | VMMDevReqMousePointer *pReq;
|
---|
76 | int rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq, RT_OFFSETOF(VMMDevReqMousePointer, pointerData) + cbImg, VMMDevReq_SetPointerShape);
|
---|
77 | if (RT_SUCCESS(rc))
|
---|
78 | {
|
---|
79 | pReq->fFlags = fFlags;
|
---|
80 | pReq->xHot = xHot;
|
---|
81 | pReq->yHot = yHot;
|
---|
82 | pReq->width = cx;
|
---|
83 | pReq->height = cy;
|
---|
84 | if (pvImg)
|
---|
85 | memcpy(pReq->pointerData, pvImg, cbImg);
|
---|
86 |
|
---|
87 | rc = vbglR3GRPerform(&pReq->header);
|
---|
88 | vbglR3GRFree(&pReq->header);
|
---|
89 | if (RT_SUCCESS(rc))
|
---|
90 | rc = pReq->header.rc;
|
---|
91 | }
|
---|
92 | return rc;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Send mouse pointer shape information to the host.
|
---|
98 | * This version of the function accepts a request for clients that
|
---|
99 | * already allocate and manipulate the request structure directly.
|
---|
100 | *
|
---|
101 | * @returns VBox status code.
|
---|
102 | *
|
---|
103 | * @param pReq Pointer to the VMMDevReqMousePointer structure.
|
---|
104 | */
|
---|
105 | VBGLR3DECL(int) VbglR3SetPointerShapeReq(VMMDevReqMousePointer *pReq)
|
---|
106 | {
|
---|
107 | int rc = vbglR3GRPerform(&pReq->header);
|
---|
108 | if (RT_SUCCESS(rc))
|
---|
109 | rc = pReq->header.rc;
|
---|
110 | return rc;
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Query the last display change request.
|
---|
116 | *
|
---|
117 | * @returns iprt status value
|
---|
118 | * @param pcx Where to store the horizontal pixel resolution (0 = do not change).
|
---|
119 | * @param pcy Where to store the vertical pixel resolution (0 = do not change).
|
---|
120 | * @param pcBits Where to store the bits per pixel (0 = do not change).
|
---|
121 | * @param iDisplay Where to store the display number the request was for - 0 for the
|
---|
122 | * primary display, 1 for the first secondary, etc.
|
---|
123 | */
|
---|
124 | VBGLR3DECL(int) VbglR3GetLastDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits,
|
---|
125 | uint32_t *piDisplay)
|
---|
126 | {
|
---|
127 | VMMDevDisplayChangeRequest2 Req = { { 0 } };
|
---|
128 |
|
---|
129 | #ifndef VBOX_VBGLR3_XFREE86
|
---|
130 | AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
|
---|
131 | AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
|
---|
132 | AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
|
---|
133 | AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
|
---|
134 | #endif
|
---|
135 | vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
|
---|
136 | int rc = vbglR3GRPerform(&Req.header);
|
---|
137 | if (RT_SUCCESS(rc))
|
---|
138 | rc = Req.header.rc;
|
---|
139 | if (RT_SUCCESS(rc))
|
---|
140 | {
|
---|
141 | *pcx = Req.xres;
|
---|
142 | *pcy = Req.yres;
|
---|
143 | *pcBits = Req.bpp;
|
---|
144 | *piDisplay = Req.display;
|
---|
145 | }
|
---|
146 | return rc;
|
---|
147 | }
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Wait for a display change request event from the host. These events must have been
|
---|
151 | * activated previously using VbglR3CtlFilterMask.
|
---|
152 | *
|
---|
153 | * @returns IPRT status value
|
---|
154 | * @param pcx on success, where to return the requested display width. 0 means no
|
---|
155 | * change.
|
---|
156 | * @param pcy on success, where to return the requested display height. 0 means no
|
---|
157 | * change.
|
---|
158 | * @param pcBits on success, where to return the requested bits per pixel. 0 means no
|
---|
159 | * change.
|
---|
160 | * @param piDisplay on success, where to return the index of the display to be changed.
|
---|
161 | */
|
---|
162 | VBGLR3DECL(int) VbglR3DisplayChangeWaitEvent(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits,
|
---|
163 | uint32_t *piDisplay)
|
---|
164 | {
|
---|
165 | VBoxGuestWaitEventInfo waitEvent;
|
---|
166 | int rc;
|
---|
167 |
|
---|
168 | #ifndef VBOX_VBGLR3_XFREE86
|
---|
169 | AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
|
---|
170 | AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
|
---|
171 | AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
|
---|
172 | AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
|
---|
173 | #endif
|
---|
174 | waitEvent.u32TimeoutIn = RT_INDEFINITE_WAIT;
|
---|
175 | waitEvent.u32EventMaskIn = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
|
---|
176 | waitEvent.u32Result = VBOXGUEST_WAITEVENT_ERROR;
|
---|
177 | waitEvent.u32EventFlagsOut = 0;
|
---|
178 | rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
|
---|
179 | if (RT_SUCCESS(rc))
|
---|
180 | {
|
---|
181 | /* did we get the right event? */
|
---|
182 | if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
|
---|
183 | {
|
---|
184 | VMMDevDisplayChangeRequest2 Req = { { 0 } };
|
---|
185 | vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
|
---|
186 | Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
|
---|
187 | int rc = vbglR3GRPerform(&Req.header);
|
---|
188 | if (RT_SUCCESS(rc))
|
---|
189 | rc = Req.header.rc;
|
---|
190 | if (RT_SUCCESS(rc))
|
---|
191 | {
|
---|
192 | *pcx = Req.xres;
|
---|
193 | *pcy = Req.yres;
|
---|
194 | *pcBits = Req.bpp;
|
---|
195 | *piDisplay = Req.display;
|
---|
196 | }
|
---|
197 | }
|
---|
198 | else
|
---|
199 | rc = VERR_TRY_AGAIN;
|
---|
200 | }
|
---|
201 | return rc;
|
---|
202 | }
|
---|