VirtualBox

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

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

Additions/common: added a call to wait for a display change request from the host

  • Property svn:eol-style set to native
File size: 6.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
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 */
36VBGLR3DECL(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 */
52VBGLR3DECL(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 */
73VBGLR3DECL(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 */
105VBGLR3DECL(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 fEventAck Flag that the request is an acknowlegement for the
122 * VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST.
123 * Values:
124 * 0 - just querying,
125 * VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST - event acknowledged.
126 * @param iDisplay 0 for primary display, 1 for the first secondary, etc.
127 */
128VBGLR3DECL(int) VbglR3GetDisplayChangeRequest(uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits,
129 uint32_t fEventAck, uint32_t iDisplay)
130{
131 VMMDevDisplayChangeRequest2 Req;
132 vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
133 Req.xres = 0;
134 Req.yres = 0;
135 Req.bpp = 0;
136 Req.eventAck = fEventAck;
137 Req.display = iDisplay;
138 int rc = vbglR3GRPerform(&Req.header);
139 if (RT_SUCCESS(rc))
140 rc = Req.header.rc;
141 if (RT_SUCCESS(rc))
142 {
143 *pcx = Req.xres;
144 *pcy = Req.yres;
145 *pcBits = Req.bpp;
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 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
178 if (RT_SUCCESS(rc))
179 {
180 /* did we get the right event? */
181 if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
182 {
183 VMMDevDisplayChangeRequest2 Req = { { 0 } };
184 vmmdevInitRequest(&Req.header, VMMDevReq_GetDisplayChangeRequest2);
185 Req.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
186 int rc = vbglR3GRPerform(&Req.header);
187 if (RT_SUCCESS(rc))
188 rc = Req.header.rc;
189 if (RT_SUCCESS(rc))
190 {
191 *pcx = Req.xres;
192 *pcy = Req.yres;
193 *pcBits = Req.bpp;
194 *piDisplay = Req.display;
195 }
196 }
197 else
198 rc = VERR_TRY_AGAIN;
199 }
200 return rc;
201}
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