VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibSeamless.cpp

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/* $Id: VBoxGuestR3LibSeamless.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Seamless mode.
4 */
5
6/*
7 * Copyright (C) 2007-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/assert.h>
42#include <iprt/errcore.h>
43#include <iprt/string.h>
44
45#include <VBox/log.h>
46
47#include "VBoxGuestR3LibInternal.h"
48
49#ifdef VBOX_VBGLR3_XFREE86
50/* Rather than try to resolve all the header file conflicts, I will just
51 prototype what we need here. */
52extern "C" void* xf86memcpy(void*,const void*,xf86size_t);
53# undef memcpy
54# define memcpy xf86memcpy
55#endif /* VBOX_VBGLR3_XFREE86 */
56
57/**
58 * Tell the host that we support (or no longer support) seamless mode.
59 *
60 * @returns IPRT status value
61 * @param fState whether or not we support seamless mode
62 */
63VBGLR3DECL(int) VbglR3SeamlessSetCap(bool fState)
64{
65 if (fState)
66 return VbglR3SetGuestCaps(VMMDEV_GUEST_SUPPORTS_SEAMLESS, 0);
67 return VbglR3SetGuestCaps(0, VMMDEV_GUEST_SUPPORTS_SEAMLESS);
68}
69
70/**
71 * Wait for a seamless mode change event.
72 *
73 * @returns IPRT status value.
74 * @param[out] pMode On success, the seamless mode to switch into (i.e.
75 * disabled, visible region or host window).
76 */
77VBGLR3DECL(int) VbglR3SeamlessWaitEvent(VMMDevSeamlessMode *pMode)
78{
79 AssertPtrReturn(pMode, VERR_INVALID_POINTER);
80
81 /** @todo r=andy The (similar / duplicate) Windows code does similar waiting. Merge / fix this. */
82 uint32_t fEvent = 0;
83 int rc = VbglR3WaitEvent(VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST, 1000 /* ms */, &fEvent);
84 if (RT_SUCCESS(rc))
85 {
86 /* did we get the right event? */
87 if (fEvent & VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
88 {
89 VMMDevSeamlessChangeRequest seamlessChangeRequest;
90
91 /* get the seamless change request */
92 vmmdevInitRequest(&seamlessChangeRequest.header, VMMDevReq_GetSeamlessChangeRequest);
93 seamlessChangeRequest.mode = (VMMDevSeamlessMode)-1;
94 seamlessChangeRequest.eventAck = VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST;
95 rc = vbglR3GRPerform(&seamlessChangeRequest.header);
96 if (RT_SUCCESS(rc))
97 {
98 *pMode = seamlessChangeRequest.mode;
99 return VINF_SUCCESS;
100 }
101 }
102 else
103 rc = VERR_TRY_AGAIN;
104 }
105 else if ( rc == VERR_INTERRUPTED
106 || rc == VERR_TIMEOUT /* just in case */)
107 rc = VERR_TRY_AGAIN;
108 return rc;
109}
110
111/**
112 * Request the last seamless mode switch from the host again.
113 *
114 * @returns IPRT status value.
115 * @param[out] pMode On success, the seamless mode that was switched
116 * into (i.e. disabled, visible region or host window).
117 */
118VBGLR3DECL(int) VbglR3SeamlessGetLastEvent(VMMDevSeamlessMode *pMode)
119{
120 VMMDevSeamlessChangeRequest seamlessChangeRequest;
121 int rc;
122
123 AssertPtrReturn(pMode, VERR_INVALID_PARAMETER);
124
125 /* get the seamless change request */
126 vmmdevInitRequest(&seamlessChangeRequest.header, VMMDevReq_GetSeamlessChangeRequest);
127 seamlessChangeRequest.mode = (VMMDevSeamlessMode)-1;
128 seamlessChangeRequest.eventAck = VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST;
129 rc = vbglR3GRPerform(&seamlessChangeRequest.header);
130 if (RT_SUCCESS(rc))
131 {
132 *pMode = seamlessChangeRequest.mode;
133 return VINF_SUCCESS;
134 }
135 return rc;
136}
137
138/**
139 * Inform the host about the visible region
140 *
141 * @returns IPRT status code
142 * @param cRects number of rectangles in the list of visible rectangles
143 * @param pRects list of visible rectangles on the guest display
144 *
145 * @todo A scatter-gather version of vbglR3GRPerform would be nice, so that we don't have
146 * to copy our rectangle and header data into a single structure and perform an
147 * additional allocation.
148 * @todo Would that really gain us much, given that the rectangles may not
149 * be grouped at all, or in the format we need? Keeping the memory
150 * for our "single structure" around (re-alloc-ing it if necessary)
151 * sounds like a simpler optimisation if we need it.
152 */
153VBGLR3DECL(int) VbglR3SeamlessSendRects(uint32_t cRects, PRTRECT pRects)
154{
155 VMMDevVideoSetVisibleRegion *pReq;
156 int rc;
157
158 AssertReturn(pRects || cRects == 0, VERR_INVALID_PARAMETER);
159 AssertMsgReturn(cRects <= _1M, ("%u\n", cRects), VERR_OUT_OF_RANGE);
160
161 rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq,
162 sizeof(VMMDevVideoSetVisibleRegion)
163 + cRects * sizeof(RTRECT)
164 - sizeof(RTRECT),
165 VMMDevReq_VideoSetVisibleRegion);
166 if (RT_SUCCESS(rc))
167 {
168 pReq->cRect = cRects;
169 if (cRects)
170 memcpy(&pReq->Rect, pRects, cRects * sizeof(RTRECT));
171 /* This will fail harmlessly for cRect == 0 and older host code */
172 rc = vbglR3GRPerform(&pReq->header);
173 LogFunc(("Visible region request returned %Rrc, internal %Rrc.\n",
174 rc, pReq->header.rc));
175 if (RT_SUCCESS(rc))
176 rc = pReq->header.rc;
177 vbglR3GRFree(&pReq->header);
178 }
179 LogFunc(("Sending %u rectangles to the host: %Rrc\n", cRects, rc));
180 return rc;
181}
182
183VBGLR3DECL(int) VbglR3SeamlessSendMonitorPositions(uint32_t cPositions, PRTPOINT pPositions)
184{
185 if (!pPositions || cPositions <= 0)
186 return VERR_INVALID_PARAMETER;
187
188 VMMDevVideoUpdateMonitorPositions *pReq;
189 int rc;
190
191 rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq,
192 sizeof(VMMDevVideoUpdateMonitorPositions)
193 + (cPositions - 1) * sizeof(RTPOINT),
194 VMMDevReq_VideoUpdateMonitorPositions);
195 if (RT_SUCCESS(rc))
196 {
197 pReq->cPositions = cPositions;
198 if (cPositions)
199 memcpy(&pReq->aPositions, pPositions, cPositions * sizeof(RTPOINT));
200 rc = vbglR3GRPerform(&pReq->header);
201 LogFunc(("Monitor position update request returned %Rrc, internal %Rrc.\n",
202 rc, pReq->header.rc));
203 if (RT_SUCCESS(rc))
204 rc = pReq->header.rc;
205 vbglR3GRFree(&pReq->header);
206 }
207 LogFunc(("Sending monitor positions (%u of them) to the host: %Rrc\n", cPositions, rc));
208 return rc;
209}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use