1 | /** $Id: VBoxGuestR3LibSeamless.cpp 6780 2008-02-04 10:51:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Seamless mode.
|
---|
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/assert.h>
|
---|
23 | #include <iprt/string.h>
|
---|
24 |
|
---|
25 | #include <VBox/VBoxGuest.h>
|
---|
26 | #include <VBox/VBoxDev.h>
|
---|
27 | #include <VBox/log.h>
|
---|
28 |
|
---|
29 | #include "VBGLR3Internal.h"
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Tell the host that we support (or no longer support) seamless mode.
|
---|
33 | *
|
---|
34 | * @returns IPRT status value
|
---|
35 | * @param fState whether or not we support seamless mode
|
---|
36 | *
|
---|
37 | * @todo Currently this will trample over any other capabilities the guest may have.
|
---|
38 | * This will have to be fixed when more capabilities are added at the latest.
|
---|
39 | */
|
---|
40 | VBGLR3DECL(int) VbglR3SeamlessSetCap(bool fState)
|
---|
41 | {
|
---|
42 | VMMDevReqGuestCapabilities vmmreqGuestCaps;
|
---|
43 | int rc = VINF_SUCCESS;
|
---|
44 |
|
---|
45 | memset(&vmmreqGuestCaps, 0, sizeof(vmmreqGuestCaps));
|
---|
46 | vmmdevInitRequest(&vmmreqGuestCaps.header, VMMDevReq_ReportGuestCapabilities);
|
---|
47 | vmmreqGuestCaps.caps = fState ? VMMDEV_GUEST_SUPPORTS_SEAMLESS : 0;
|
---|
48 | rc = vbglR3GRPerform(&vmmreqGuestCaps.header);
|
---|
49 | #ifdef DEBUG
|
---|
50 | if (RT_SUCCESS(rc))
|
---|
51 | LogRel(("Successfully set the seamless capability on the host.\n"));
|
---|
52 | else
|
---|
53 | LogRel(("Failed to set the seamless capability on the host, rc = %Rrc.\n", rc));
|
---|
54 | #endif
|
---|
55 | return rc;
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Wait for a seamless mode change event.
|
---|
60 | *
|
---|
61 | * @returns IPRT status value
|
---|
62 | * @retval pMode on success, the seamless mode to switch into (i.e. disabled, visible region
|
---|
63 | * or host window)
|
---|
64 | */
|
---|
65 | VBGLR3DECL(int) VbglR3SeamlessWaitEvent(VMMDevSeamlessMode *pMode)
|
---|
66 | {
|
---|
67 | VBoxGuestWaitEventInfo waitEvent;
|
---|
68 | int rc;
|
---|
69 |
|
---|
70 | AssertPtrReturn(pMode, VERR_INVALID_PARAMETER);
|
---|
71 | waitEvent.u32TimeoutIn = RT_INDEFINITE_WAIT;
|
---|
72 | waitEvent.u32EventMaskIn = VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST;
|
---|
73 | rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent));
|
---|
74 | if (RT_SUCCESS(rc))
|
---|
75 | {
|
---|
76 | /* did we get the right event? */
|
---|
77 | if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
|
---|
78 | {
|
---|
79 | VMMDevSeamlessChangeRequest seamlessChangeRequest;
|
---|
80 |
|
---|
81 | /* get the seamless change request */
|
---|
82 | vmmdevInitRequest(&seamlessChangeRequest.header, VMMDevReq_GetSeamlessChangeRequest);
|
---|
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 | return rc;
|
---|
95 | }
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Inform the host about the visible region
|
---|
99 | *
|
---|
100 | * @returns IPRT status code
|
---|
101 | * @param cRects number of rectangles in the list of visible rectangles
|
---|
102 | * @param pRects list of visible rectangles on the guest display
|
---|
103 | *
|
---|
104 | * @todo A scatter-gather version of vbglR3GRPerform would be nice, so that we don't have
|
---|
105 | * to copy our rectangle and header data into a single structure and perform an
|
---|
106 | * additional allocation.
|
---|
107 | */
|
---|
108 | VBGLR3DECL(int) VbglR3SeamlessSendRects(uint32_t cRects, PRTRECT pRects)
|
---|
109 | {
|
---|
110 | VMMDevVideoSetVisibleRegion *pReq;
|
---|
111 | int rc;
|
---|
112 |
|
---|
113 | if (0 == cRects)
|
---|
114 | return VINF_SUCCESS;
|
---|
115 | rc = vbglR3GRAlloc((VMMDevRequestHeader **)&pReq,
|
---|
116 | sizeof(VMMDevVideoSetVisibleRegion) + (cRects - 1) * sizeof(RTRECT),
|
---|
117 | VMMDevReq_VideoSetVisibleRegion);
|
---|
118 | if (RT_SUCCESS(rc))
|
---|
119 | {
|
---|
120 | pReq->cRect = cRects;
|
---|
121 | memcpy(&pReq->Rect, pRects, cRects * sizeof(RTRECT));
|
---|
122 | rc = vbglR3GRPerform(&pReq->header);
|
---|
123 | vbglR3GRFree(&pReq->header);
|
---|
124 | if (RT_SUCCESS(rc))
|
---|
125 | {
|
---|
126 | if (RT_SUCCESS(pReq->header.rc))
|
---|
127 | return VINF_SUCCESS;
|
---|
128 | rc = pReq->header.rc;
|
---|
129 | }
|
---|
130 | }
|
---|
131 | return rc;
|
---|
132 | }
|
---|
133 |
|
---|