1 | /** @file
|
---|
2 | * VBoxService - Guest displays handling.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.alldomusa.eu.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
25 | */
|
---|
26 |
|
---|
27 | #include <iprt/errcore.h>
|
---|
28 |
|
---|
29 | #include <VBox/VBoxGuestLib.h>
|
---|
30 | #include "VBoxServiceInternal.h"
|
---|
31 | #include "VBoxServiceUtils.h"
|
---|
32 |
|
---|
33 |
|
---|
34 | /*********************************************************************************************************************************
|
---|
35 | * Global Variables *
|
---|
36 | *********************************************************************************************************************************/
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * @interface_method_impl{VBOXSERVICE,pfnInit}
|
---|
40 | */
|
---|
41 | static DECLCALLBACK(int) vgsvcDisplayConfigInit(void)
|
---|
42 | {
|
---|
43 | return VINF_SUCCESS;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * @interface_method_impl{VBOXSERVICE,pfnWorker}
|
---|
48 | */
|
---|
49 | DECLCALLBACK(int) vgsvcDisplayConfigWorker(bool volatile *pfShutdown)
|
---|
50 | {
|
---|
51 | int rc = VINF_SUCCESS;
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * Tell the control thread that it can continue spawning services.
|
---|
55 | */
|
---|
56 | RTThreadUserSignal(RTThreadSelf());
|
---|
57 | /*
|
---|
58 | * The Work Loop.
|
---|
59 | */
|
---|
60 |
|
---|
61 | rc = VbglR3CtlFilterMask(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 0);
|
---|
62 | VGSvcVerbose(2, "VbglR3CtlFilterMask set rc=%Rrc\n", rc);
|
---|
63 |
|
---|
64 | for (;;)
|
---|
65 | {
|
---|
66 | uint32_t fEvents = 0;
|
---|
67 |
|
---|
68 | rc = VbglR3AcquireGuestCaps(VMMDEV_GUEST_SUPPORTS_GRAPHICS, 0, false);
|
---|
69 | VGSvcVerbose(2, "VbglR3AcquireGuestCaps acquire VMMDEV_GUEST_SUPPORTS_GRAPHICS rc=%Rrc\n", rc);
|
---|
70 |
|
---|
71 | rc = VbglR3WaitEvent(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 1000 /*ms*/, &fEvents);
|
---|
72 | VGSvcVerbose(2, "VbglR3WaitEvent rc=%Rrc\n", rc);
|
---|
73 |
|
---|
74 | if (RT_SUCCESS(rc))
|
---|
75 | {
|
---|
76 | VMMDevDisplayDef aDisplays[64];
|
---|
77 | uint32_t cDisplays = RT_ELEMENTS(aDisplays);
|
---|
78 |
|
---|
79 | rc = VbglR3GetDisplayChangeRequestMulti(cDisplays, &cDisplays, &aDisplays[0], true);
|
---|
80 | VGSvcVerbose(2, "VbglR3GetDisplayChangeRequestMulti rc=%Rrc cDisplays=%d\n", rc, cDisplays);
|
---|
81 | if (cDisplays > 0)
|
---|
82 | {
|
---|
83 | VGSvcVerbose(2, "Display[0] (%dx%d)\n", aDisplays[0].cx, aDisplays[0].cy);
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | rc = VbglR3AcquireGuestCaps(0, VMMDEV_GUEST_SUPPORTS_GRAPHICS, false);
|
---|
88 | VGSvcVerbose(2, "VbglR3AcquireGuestCaps release VMMDEV_GUEST_SUPPORTS_GRAPHICS rc=%Rrc\n", rc);
|
---|
89 |
|
---|
90 | RTThreadSleep(1000);
|
---|
91 |
|
---|
92 | if (*pfShutdown)
|
---|
93 | break;
|
---|
94 | }
|
---|
95 |
|
---|
96 | rc = VbglR3CtlFilterMask(0, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
|
---|
97 | VGSvcVerbose(2, "VbglR3CtlFilterMask cleared rc=%Rrc\n", rc);
|
---|
98 |
|
---|
99 | return rc;
|
---|
100 | }
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * @interface_method_impl{VBOXSERVICE,pfnStop}
|
---|
104 | */
|
---|
105 | static DECLCALLBACK(void) vgsvcDisplayConfigStop(void)
|
---|
106 | {
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * @interface_method_impl{VBOXSERVICE,pfnTerm}
|
---|
111 | */
|
---|
112 | static DECLCALLBACK(void) vgsvcDisplayConfigTerm(void)
|
---|
113 | {
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * The 'displayconfig' service description.
|
---|
118 | */
|
---|
119 | VBOXSERVICE g_DisplayConfig =
|
---|
120 | {
|
---|
121 | /* pszName. */
|
---|
122 | "displayconfig",
|
---|
123 | /* pszDescription. */
|
---|
124 | "Display configuration",
|
---|
125 | /* pszUsage. */
|
---|
126 | NULL,
|
---|
127 | /* pszOptions. */
|
---|
128 | NULL,
|
---|
129 | /* methods */
|
---|
130 | VGSvcDefaultPreInit,
|
---|
131 | VGSvcDefaultOption,
|
---|
132 | vgsvcDisplayConfigInit,
|
---|
133 | vgsvcDisplayConfigWorker,
|
---|
134 | vgsvcDisplayConfigStop,
|
---|
135 | vgsvcDisplayConfigTerm
|
---|
136 | };
|
---|