1 | /* $Id: VBoxDisplay.cpp 68550 2017-08-31 12:09:41Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxDisplayService, Haiku Guest Additions, implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2016 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 |
|
---|
18 | /*
|
---|
19 | * This code is based on:
|
---|
20 | *
|
---|
21 | * VirtualBox Guest Additions for Haiku.
|
---|
22 | * Copyright (c) 2011 Mike Smith <[email protected]>
|
---|
23 | * François Revol <[email protected]>
|
---|
24 | *
|
---|
25 | * Permission is hereby granted, free of charge, to any person
|
---|
26 | * obtaining a copy of this software and associated documentation
|
---|
27 | * files (the "Software"), to deal in the Software without
|
---|
28 | * restriction, including without limitation the rights to use,
|
---|
29 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
30 | * copies of the Software, and to permit persons to whom the
|
---|
31 | * Software is furnished to do so, subject to the following
|
---|
32 | * conditions:
|
---|
33 | *
|
---|
34 | * The above copyright notice and this permission notice shall be
|
---|
35 | * included in all copies or substantial portions of the Software.
|
---|
36 | *
|
---|
37 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
38 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
39 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
40 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
41 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
42 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
43 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
44 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
45 | */
|
---|
46 |
|
---|
47 | #include <stdio.h>
|
---|
48 | #include <stdlib.h>
|
---|
49 | #include <new>
|
---|
50 | #include <DataIO.h>
|
---|
51 | #include <Message.h>
|
---|
52 | #include <TranslationUtils.h>
|
---|
53 | #include <TranslatorFormats.h>
|
---|
54 | #include <TranslatorRoster.h>
|
---|
55 | #include <String.h>
|
---|
56 |
|
---|
57 | #include "VBoxGuestApplication.h"
|
---|
58 | #include "VBoxDisplay.h"
|
---|
59 | #include <VBoxGuestInternal.h>
|
---|
60 | #include "../VBoxVideo/common/VBoxVideo_common.h"
|
---|
61 |
|
---|
62 | #include <iprt/mem.h>
|
---|
63 | #include <VBox/log.h>
|
---|
64 |
|
---|
65 | #ifdef DEBUG_ramshankar
|
---|
66 | # undef Log
|
---|
67 | # define Log(x) printf x
|
---|
68 | # undef LogRel
|
---|
69 | # define LogRel(x) printf x
|
---|
70 | # undef LogRelFlowFunc
|
---|
71 | # define LogRelFlowFunc(x) printf x
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | VBoxDisplayService::VBoxDisplayService()
|
---|
75 | : BHandler("VBoxDisplayService"),
|
---|
76 | fClientId(-1),
|
---|
77 | fServiceThreadID(-1),
|
---|
78 | fExiting(false),
|
---|
79 | fScreen(B_MAIN_SCREEN_ID)
|
---|
80 | {
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | VBoxDisplayService::~VBoxDisplayService()
|
---|
85 | {
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | void VBoxDisplayService::Start()
|
---|
90 | {
|
---|
91 | status_t err;
|
---|
92 | err = fServiceThreadID = spawn_thread(_ServiceThreadNub, "VBoxDisplayService", B_NORMAL_PRIORITY, this);
|
---|
93 | if (err >= B_OK)
|
---|
94 | resume_thread(fServiceThreadID);
|
---|
95 | else
|
---|
96 | LogRel(("VBoxDisplayService: Error starting service thread: %s\n", strerror(err)));
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | void VBoxDisplayService::MessageReceived(BMessage *message)
|
---|
101 | {
|
---|
102 | if (message->what == B_QUIT_REQUESTED)
|
---|
103 | fExiting = true;
|
---|
104 | else
|
---|
105 | BHandler::MessageReceived(message);
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | status_t VBoxDisplayService::_ServiceThreadNub(void *_this)
|
---|
110 | {
|
---|
111 | VBoxDisplayService *service = (VBoxDisplayService *)_this;
|
---|
112 | return service->_ServiceThread();
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | status_t VBoxDisplayService::_ServiceThread()
|
---|
117 | {
|
---|
118 | LogFlow(("VBoxDisplayService::_ServiceThread"));
|
---|
119 |
|
---|
120 | VbglR3CtlFilterMask(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 0);
|
---|
121 | VbglR3SetGuestCaps(VMMDEV_GUEST_SUPPORTS_GRAPHICS, 0);
|
---|
122 | for (;;)
|
---|
123 | {
|
---|
124 | uint32_t events;
|
---|
125 | int rc = VbglR3WaitEvent(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 5000, &events);
|
---|
126 | if ( rc == VERR_TIMEOUT
|
---|
127 | || rc == VERR_INTERRUPTED)
|
---|
128 | continue;
|
---|
129 |
|
---|
130 | if (RT_SUCCESS(rc))
|
---|
131 | {
|
---|
132 | uint32_t cx, cy, cBits, iDisplay;
|
---|
133 | int rc2 = VbglR3GetDisplayChangeRequest(&cx, &cy, &cBits, &iDisplay, NULL, NULL, NULL, NULL, true);
|
---|
134 | LogFlow(("rc2=%d screen %d size changed (%d, %d, %d)\n", rc2, iDisplay, cx, cy, cBits));
|
---|
135 |
|
---|
136 | if (RT_SUCCESS(rc2))
|
---|
137 | {
|
---|
138 | display_mode mode;
|
---|
139 | fScreen.GetMode(&mode);
|
---|
140 | if (cBits == 0)
|
---|
141 | cBits = get_depth_for_color_space(mode.space);
|
---|
142 |
|
---|
143 | mode.timing.h_display = cx;
|
---|
144 | mode.timing.v_display = cy;
|
---|
145 | mode.space = get_color_space_for_depth(cBits);
|
---|
146 | mode.virtual_width = cx;
|
---|
147 | mode.virtual_height = cy;
|
---|
148 |
|
---|
149 | /*= {
|
---|
150 | {0, cx, 0, 0, cBits * cx / 8, cy, 0, 0, cBits * cy / 8, 0},
|
---|
151 | get_color_space_for_depth(cBits),
|
---|
152 | cx, cy, 0, 0, 0
|
---|
153 | };*/
|
---|
154 |
|
---|
155 | fScreen.SetMode(&mode, false);
|
---|
156 | }
|
---|
157 | }
|
---|
158 | else
|
---|
159 | fExiting = true;
|
---|
160 |
|
---|
161 | LogFlow(("processed host event rc = %d\n", rc));
|
---|
162 | if (fExiting)
|
---|
163 | break;
|
---|
164 | }
|
---|
165 | return 0;
|
---|
166 | }
|
---|
167 |
|
---|