VirtualBox

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

Last change on this file since 96407 was 96407, checked in by vboxsync, 22 months ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
RevLine 
[21211]1/* $Id: VBoxGuestR3LibSeamless.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
[5824]2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Seamless mode.
4 */
5
6/*
[96407]7 * Copyright (C) 2007-2022 Oracle and/or its affiliates.
[5824]8 *
[96407]9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
[8155]11 *
[96407]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 *
[26425]25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
[96407]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
[26425]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.
[96407]33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
[5824]35 */
36
37
[57358]38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
[5824]41#include <iprt/assert.h>
[76474]42#include <iprt/errcore.h>
[5888]43#include <iprt/string.h>
[5824]44
[5871]45#include <VBox/log.h>
[5824]46
[68650]47#include "VBoxGuestR3LibInternal.h"
[5824]48
[31384]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 */
[21211]56
[5824]57/**
58 * Tell the host that we support (or no longer support) seamless mode.
59 *
60 * @returns IPRT status value
[5888]61 * @param fState whether or not we support seamless mode
[5824]62 */
[5888]63VBGLR3DECL(int) VbglR3SeamlessSetCap(bool fState)
[5824]64{
[24968]65 if (fState)
66 return VbglR3SetGuestCaps(VMMDEV_GUEST_SUPPORTS_SEAMLESS, 0);
67 return VbglR3SetGuestCaps(0, VMMDEV_GUEST_SUPPORTS_SEAMLESS);
[5824]68}
69
70/**
71 * Wait for a seamless mode change event.
72 *
[27318]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).
[5824]76 */
77VBGLR3DECL(int) VbglR3SeamlessWaitEvent(VMMDevSeamlessMode *pMode)
78{
[86870]79 AssertPtrReturn(pMode, VERR_INVALID_POINTER);
80
81 /** @todo r=andy The (similar / duplicate) Windows code does similar waiting. Merge / fix this. */
[68550]82 uint32_t fEvent = 0;
[90052]83 int rc = VbglR3WaitEvent(VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST, 1000 /* ms */, &fEvent);
[5824]84 if (RT_SUCCESS(rc))
85 {
86 /* did we get the right event? */
[68550]87 if (fEvent & VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
[5824]88 {
89 VMMDevSeamlessChangeRequest seamlessChangeRequest;
90
91 /* get the seamless change request */
92 vmmdevInitRequest(&seamlessChangeRequest.header, VMMDevReq_GetSeamlessChangeRequest);
[27318]93 seamlessChangeRequest.mode = (VMMDevSeamlessMode)-1;
[5824]94 seamlessChangeRequest.eventAck = VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST;
[6470]95 rc = vbglR3GRPerform(&seamlessChangeRequest.header);
[5824]96 if (RT_SUCCESS(rc))
97 {
98 *pMode = seamlessChangeRequest.mode;
99 return VINF_SUCCESS;
100 }
101 }
102 else
103 rc = VERR_TRY_AGAIN;
104 }
[68550]105 else if ( rc == VERR_INTERRUPTED
106 || rc == VERR_TIMEOUT /* just in case */)
107 rc = VERR_TRY_AGAIN;
[5824]108 return rc;
109}
110
111/**
[27309]112 * Request the last seamless mode switch from the host again.
113 *
[27318]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).
[27309]117 */
118VBGLR3DECL(int) VbglR3SeamlessGetLastEvent(VMMDevSeamlessMode *pMode)
119{
[27318]120 VMMDevSeamlessChangeRequest seamlessChangeRequest;
[27309]121 int rc;
122
123 AssertPtrReturn(pMode, VERR_INVALID_PARAMETER);
124
125 /* get the seamless change request */
126 vmmdevInitRequest(&seamlessChangeRequest.header, VMMDevReq_GetSeamlessChangeRequest);
[27318]127 seamlessChangeRequest.mode = (VMMDevSeamlessMode)-1;
[27309]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/**
[5824]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 *
[6470]145 * @todo A scatter-gather version of vbglR3GRPerform would be nice, so that we don't have
[5824]146 * to copy our rectangle and header data into a single structure and perform an
147 * additional allocation.
[37174]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.
[5824]152 */
153VBGLR3DECL(int) VbglR3SeamlessSendRects(uint32_t cRects, PRTRECT pRects)
154{
[6497]155 VMMDevVideoSetVisibleRegion *pReq;
[5824]156 int rc;
157
[37384]158 AssertReturn(pRects || cRects == 0, VERR_INVALID_PARAMETER);
159 AssertMsgReturn(cRects <= _1M, ("%u\n", cRects), VERR_OUT_OF_RANGE);
[37378]160
[6497]161 rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq,
[37174]162 sizeof(VMMDevVideoSetVisibleRegion)
[37384]163 + cRects * sizeof(RTRECT)
164 - sizeof(RTRECT),
[5888]165 VMMDevReq_VideoSetVisibleRegion);
[5824]166 if (RT_SUCCESS(rc))
167 {
[6497]168 pReq->cRect = cRects;
[37174]169 if (cRects)
170 memcpy(&pReq->Rect, pRects, cRects * sizeof(RTRECT));
171 /* This will fail harmlessly for cRect == 0 and older host code */
[6497]172 rc = vbglR3GRPerform(&pReq->header);
[37174]173 LogFunc(("Visible region request returned %Rrc, internal %Rrc.\n",
174 rc, pReq->header.rc));
[5824]175 if (RT_SUCCESS(rc))
[6497]176 rc = pReq->header.rc;
[7367]177 vbglR3GRFree(&pReq->header);
[5824]178 }
[37174]179 LogFunc(("Sending %u rectangles to the host: %Rrc\n", cRects, rc));
[5824]180 return rc;
181}
[5888]182
[83142]183VBGLR3DECL(int) VbglR3SeamlessSendMonitorPositions(uint32_t cPositions, PRTPOINT pPositions)
184{
[83246]185 if (!pPositions || cPositions <= 0)
186 return VERR_INVALID_PARAMETER;
187
[83142]188 VMMDevVideoUpdateMonitorPositions *pReq;
189 int rc;
190
191 rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq,
192 sizeof(VMMDevVideoUpdateMonitorPositions)
[83246]193 + (cPositions - 1) * sizeof(RTPOINT),
[83142]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