VirtualBox

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

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

brc->fRc.

  • Property svn:eol-style set to native
File size: 7.6 KB
Line 
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#include <VBox/log.h>
26
27#include "VBGLR3Internal.h"
28
29
30/**
31 * Enable or disable video acceleration.
32 *
33 * @returns VBox status code.
34 *
35 * @param fEnable Pass zero to disable, any other value to enable.
36 */
37VBGLR3DECL(int) VbglR3VideoAccelEnable(bool fEnable)
38{
39 VMMDevVideoAccelEnable Req;
40 vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelEnable);
41 Req.u32Enable = fEnable;
42 Req.cbRingBuffer = VBVA_RING_BUFFER_SIZE;
43 Req.fu32Status = 0;
44 return vbglR3GRPerform(&Req.header);
45}
46
47
48/**
49 * Flush the video buffer.
50 *
51 * @returns VBox status code.
52 */
53VBGLR3DECL(int) VbglR3VideoAccelFlush(void)
54{
55 VMMDevVideoAccelFlush Req;
56 vmmdevInitRequest(&Req.header, VMMDevReq_VideoAccelFlush);
57 return vbglR3GRPerform(&Req.header);
58}
59
60
61/**
62 * Send mouse pointer shape information to the host.
63 *
64 * @returns VBox status code.
65 *
66 * @param fFlags Mouse pointer flags.
67 * @param xHot X coordinate of hot spot.
68 * @param yHot Y coordinate of hot spot.
69 * @param cx Pointer width.
70 * @param cy Pointer height.
71 * @param pvImg Pointer to the image data (can be NULL).
72 * @param cbImg Size of the image data pointed to by pvImg.
73 */
74VBGLR3DECL(int) VbglR3SetPointerShape(uint32_t fFlags, uint32_t xHot, uint32_t yHot, uint32_t cx, uint32_t cy, const void *pvImg, size_t cbImg)
75{
76 VMMDevReqMousePointer *pReq;
77 int rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq, RT_OFFSETOF(VMMDevReqMousePointer, pointerData) + cbImg, VMMDevReq_SetPointerShape);
78 if (RT_SUCCESS(rc))
79 {
80 pReq->fFlags = fFlags;
81 pReq->xHot = xHot;
82 pReq->yHot = yHot;
83 pReq->width = cx;
84 pReq->height = cy;
85 if (pvImg)
86 memcpy(pReq->pointerData, pvImg, cbImg);
87
88 rc = vbglR3GRPerform(&pReq->header);
89 vbglR3GRFree(&pReq->header);
90 if (RT_SUCCESS(rc))
91 rc = pReq->header.rc;
92 }
93 return rc;
94}
95
96
97/**
98 * Send mouse pointer shape information to the host.
99 * This version of the function accepts a request for clients that
100 * already allocate and manipulate the request structure directly.
101 *
102 * @returns VBox status code.
103 *
104 * @param pReq Pointer to the VMMDevReqMousePointer structure.
105 */
106VBGLR3DECL(int) VbglR3SetPointerShapeReq(VMMDevReqMousePointer *pReq)
107{
108 int rc = vbglR3GRPerform(&pReq->header);
109 if (RT_SUCCESS(rc))
110 rc = pReq->header.rc;
111 return rc;
112}
113
114
115/**
116 * Query the last display change request.
117 *
118 * @returns iprt status value
119 * @param pcx Where to store the horizontal pixel resolution (0 = do not change).
120 * @param pcy Where to store the vertical pixel resolution (0 = do not change).
121 * @param pcBits Where to store the bits per pixel (0 = do not change).
122 * @param iDisplay Where to store the display number the request was for - 0 for the
123 * primary display, 1 for the first secondary, etc.
124 */
125VBGLR3DECL(int) VbglR3GetLastDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits,
126 uint32_t *piDisplay)
127{
128 VMMDevDisplayChangeRequest2 Req = { { 0 } };
129
130#ifndef VBOX_VBGLR3_XFREE86
131 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
132 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
133 AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
134 AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
135#endif
136vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
137 int rc = vbglR3GRPerform(&Req.header);
138 if (RT_SUCCESS(rc))
139 rc = Req.header.rc;
140 if (RT_SUCCESS(rc))
141 {
142 *pcx = Req.xres;
143 *pcy = Req.yres;
144 *pcBits = Req.bpp;
145 *piDisplay = Req.display;
146 }
147 return rc;
148}
149
150/**
151 * Wait for a display change request event from the host. These events must have been
152 * activated previously using VbglR3CtlFilterMask.
153 *
154 * @returns IPRT status value
155 * @param pcx on success, where to return the requested display width. 0 means no
156 * change.
157 * @param pcy on success, where to return the requested display height. 0 means no
158 * change.
159 * @param pcBits on success, where to return the requested bits per pixel. 0 means no
160 * change.
161 * @param piDisplay on success, where to return the index of the display to be changed.
162 */
163VBGLR3DECL(int) VbglR3DisplayChangeWaitEvent(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits,
164 uint32_t *piDisplay)
165{
166 VBoxGuestWaitEventInfo waitEvent;
167 int rc;
168
169#ifndef VBOX_VBGLR3_XFREE86
170 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
171 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
172 AssertPtrReturn(pcBits, VERR_INVALID_PARAMETER);
173 AssertPtrReturn(piDisplay, VERR_INVALID_PARAMETER);
174#endif
175 waitEvent.u32TimeoutIn = RT_INDEFINITE_WAIT;
176 waitEvent.u32EventMaskIn = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
177 waitEvent.u32Result = VBOXGUEST_WAITEVENT_ERROR;
178 waitEvent.u32EventFlagsOut = 0;
179 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
180 if (RT_SUCCESS(rc))
181 {
182 /* did we get the right event? */
183 if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
184 {
185 VMMDevDisplayChangeRequest2 Req = { { 0 } };
186 vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
187 Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
188 int rc = vbglR3GRPerform(&Req.header);
189 if (RT_SUCCESS(rc))
190 rc = Req.header.rc;
191 if (RT_SUCCESS(rc))
192 {
193 *pcx = Req.xres;
194 *pcy = Req.yres;
195 *pcBits = Req.bpp;
196 *piDisplay = Req.display;
197 }
198 }
199 else
200 rc = VERR_TRY_AGAIN;
201 }
202 return rc;
203}
204
205/**
206 * Query the host as to whether it likes a specific video mode.
207 *
208 * @returns the result of the query
209 * @param cx the width of the mode being queried
210 * @param cy the height of the mode being queried
211 * @param cBits the bpp of the mode being queried
212 */
213VBGLR3DECL(bool) VbglR3HostLikesVideoMode(uint32_t cx, uint32_t cy,
214 uint32_t cBits)
215{
216 bool fRc = false;
217 int rc;
218 VMMDevVideoModeSupportedRequest req;
219
220 vmmdevInitRequest(&req.header, VMMDevReq_VideoModeSupported);
221 req.width = cx;
222 req.height = cy;
223 req.bpp = cBits;
224 req.fSupported = false;
225 rc = vbglR3GRPerform(&req.header);
226 if (RT_SUCCESS(rc) && RT_SUCCESS(req.header.rc))
227 fRc = req.fSupported;
228 else
229 LogRelFunc(("error querying video mode supported status from VMMDev."
230 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req.header.rc));
231 return fRc;
232}
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