VirtualBox

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

Last change on this file since 76225 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1/* $Id: VBoxGuestR3LibSeamless.cpp 69500 2017-10-28 15:14:05Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Seamless mode.
4 */
5
6/*
7 * Copyright (C) 2007-2017 Oracle Corporation
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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/assert.h>
32#include <iprt/string.h>
33
34#include <VBox/log.h>
35
36#include "VBoxGuestR3LibInternal.h"
37
38#ifdef VBOX_VBGLR3_XFREE86
39/* Rather than try to resolve all the header file conflicts, I will just
40 prototype what we need here. */
41extern "C" void* xf86memcpy(void*,const void*,xf86size_t);
42# undef memcpy
43# define memcpy xf86memcpy
44#endif /* VBOX_VBGLR3_XFREE86 */
45
46/**
47 * Tell the host that we support (or no longer support) seamless mode.
48 *
49 * @returns IPRT status value
50 * @param fState whether or not we support seamless mode
51 */
52VBGLR3DECL(int) VbglR3SeamlessSetCap(bool fState)
53{
54 if (fState)
55 return VbglR3SetGuestCaps(VMMDEV_GUEST_SUPPORTS_SEAMLESS, 0);
56 return VbglR3SetGuestCaps(0, VMMDEV_GUEST_SUPPORTS_SEAMLESS);
57}
58
59/**
60 * Wait for a seamless mode change event.
61 *
62 * @returns IPRT status value.
63 * @param[out] pMode On success, the seamless mode to switch into (i.e.
64 * disabled, visible region or host window).
65 */
66VBGLR3DECL(int) VbglR3SeamlessWaitEvent(VMMDevSeamlessMode *pMode)
67{
68 uint32_t fEvent = 0;
69 int rc;
70
71 AssertPtrReturn(pMode, VERR_INVALID_PARAMETER);
72 rc = VbglR3WaitEvent(VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST, RT_INDEFINITE_WAIT, &fEvent);
73 if (RT_SUCCESS(rc))
74 {
75 /* did we get the right event? */
76 if (fEvent & VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
77 {
78 VMMDevSeamlessChangeRequest seamlessChangeRequest;
79
80 /* get the seamless change request */
81 vmmdevInitRequest(&seamlessChangeRequest.header, VMMDevReq_GetSeamlessChangeRequest);
82 seamlessChangeRequest.mode = (VMMDevSeamlessMode)-1;
83 seamlessChangeRequest.eventAck = VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST;
84 rc = vbglR3GRPerform(&seamlessChangeRequest.header);
85 if (RT_SUCCESS(rc))
86 {
87 *pMode = seamlessChangeRequest.mode;
88 return VINF_SUCCESS;
89 }
90 }
91 else
92 rc = VERR_TRY_AGAIN;
93 }
94 else if ( rc == VERR_INTERRUPTED
95 || rc == VERR_TIMEOUT /* just in case */)
96 rc = VERR_TRY_AGAIN;
97 return rc;
98}
99
100/**
101 * Request the last seamless mode switch from the host again.
102 *
103 * @returns IPRT status value.
104 * @param[out] pMode On success, the seamless mode that was switched
105 * into (i.e. disabled, visible region or host window).
106 */
107VBGLR3DECL(int) VbglR3SeamlessGetLastEvent(VMMDevSeamlessMode *pMode)
108{
109 VMMDevSeamlessChangeRequest seamlessChangeRequest;
110 int rc;
111
112 AssertPtrReturn(pMode, VERR_INVALID_PARAMETER);
113
114 /* get the seamless change request */
115 vmmdevInitRequest(&seamlessChangeRequest.header, VMMDevReq_GetSeamlessChangeRequest);
116 seamlessChangeRequest.mode = (VMMDevSeamlessMode)-1;
117 seamlessChangeRequest.eventAck = VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST;
118 rc = vbglR3GRPerform(&seamlessChangeRequest.header);
119 if (RT_SUCCESS(rc))
120 {
121 *pMode = seamlessChangeRequest.mode;
122 return VINF_SUCCESS;
123 }
124 return rc;
125}
126
127/**
128 * Inform the host about the visible region
129 *
130 * @returns IPRT status code
131 * @param cRects number of rectangles in the list of visible rectangles
132 * @param pRects list of visible rectangles on the guest display
133 *
134 * @todo A scatter-gather version of vbglR3GRPerform would be nice, so that we don't have
135 * to copy our rectangle and header data into a single structure and perform an
136 * additional allocation.
137 * @todo Would that really gain us much, given that the rectangles may not
138 * be grouped at all, or in the format we need? Keeping the memory
139 * for our "single structure" around (re-alloc-ing it if necessary)
140 * sounds like a simpler optimisation if we need it.
141 */
142VBGLR3DECL(int) VbglR3SeamlessSendRects(uint32_t cRects, PRTRECT pRects)
143{
144 VMMDevVideoSetVisibleRegion *pReq;
145 int rc;
146
147 AssertReturn(pRects || cRects == 0, VERR_INVALID_PARAMETER);
148 AssertMsgReturn(cRects <= _1M, ("%u\n", cRects), VERR_OUT_OF_RANGE);
149
150 rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq,
151 sizeof(VMMDevVideoSetVisibleRegion)
152 + cRects * sizeof(RTRECT)
153 - sizeof(RTRECT),
154 VMMDevReq_VideoSetVisibleRegion);
155 if (RT_SUCCESS(rc))
156 {
157 pReq->cRect = cRects;
158 if (cRects)
159 memcpy(&pReq->Rect, pRects, cRects * sizeof(RTRECT));
160 /* This will fail harmlessly for cRect == 0 and older host code */
161 rc = vbglR3GRPerform(&pReq->header);
162 LogFunc(("Visible region request returned %Rrc, internal %Rrc.\n",
163 rc, pReq->header.rc));
164 if (RT_SUCCESS(rc))
165 rc = pReq->header.rc;
166 vbglR3GRFree(&pReq->header);
167 }
168 LogFunc(("Sending %u rectangles to the host: %Rrc\n", cRects, rc));
169 return rc;
170}
171
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