1 | /* $Id: display_base.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * Presenter API: display base class implementation.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2014-2019 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "server_presenter.h"
|
---|
20 |
|
---|
21 | CrFbDisplayBase::CrFbDisplayBase() :
|
---|
22 | mpContainer(NULL),
|
---|
23 | mpFb(NULL),
|
---|
24 | mcUpdates(0),
|
---|
25 | mhSlot(CRHTABLE_HANDLE_INVALID)
|
---|
26 | {
|
---|
27 | mFlags.u32Value = 0;
|
---|
28 | }
|
---|
29 |
|
---|
30 |
|
---|
31 | CrFbDisplayBase::~CrFbDisplayBase()
|
---|
32 | {
|
---|
33 | Assert(!mcUpdates);
|
---|
34 |
|
---|
35 | if (mpContainer)
|
---|
36 | mpContainer->remove(this);
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | bool CrFbDisplayBase::isComposite()
|
---|
41 | {
|
---|
42 | return false;
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | class CrFbDisplayComposite* CrFbDisplayBase::getContainer()
|
---|
47 | {
|
---|
48 | return mpContainer;
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | bool CrFbDisplayBase::isInList()
|
---|
53 | {
|
---|
54 | return !!mpContainer;
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | bool CrFbDisplayBase::isUpdating()
|
---|
59 | {
|
---|
60 | return !!mcUpdates;
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | int CrFbDisplayBase::setRegionsChanged()
|
---|
65 | {
|
---|
66 | if (!mcUpdates)
|
---|
67 | {
|
---|
68 | WARN(("err"));
|
---|
69 | return VERR_INVALID_STATE;
|
---|
70 | }
|
---|
71 |
|
---|
72 | mFlags.fRegionsShanged = 1;
|
---|
73 | return VINF_SUCCESS;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | int CrFbDisplayBase::setFramebuffer(struct CR_FRAMEBUFFER *pFb)
|
---|
78 | {
|
---|
79 | if (mcUpdates)
|
---|
80 | {
|
---|
81 | WARN(("trying to set framebuffer while update is in progress"));
|
---|
82 | return VERR_INVALID_STATE;
|
---|
83 | }
|
---|
84 |
|
---|
85 | if (mpFb == pFb)
|
---|
86 | return VINF_SUCCESS;
|
---|
87 |
|
---|
88 | int rc = setFramebufferBegin(pFb);
|
---|
89 | if (!RT_SUCCESS(rc))
|
---|
90 | {
|
---|
91 | WARN(("err"));
|
---|
92 | return rc;
|
---|
93 | }
|
---|
94 |
|
---|
95 | if (mpFb)
|
---|
96 | {
|
---|
97 | rc = fbCleanup();
|
---|
98 | if (!RT_SUCCESS(rc))
|
---|
99 | {
|
---|
100 | WARN(("err"));
|
---|
101 | setFramebufferEnd(pFb);
|
---|
102 | return rc;
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | mpFb = pFb;
|
---|
107 |
|
---|
108 | if (mpFb)
|
---|
109 | {
|
---|
110 | rc = fbSync();
|
---|
111 | if (!RT_SUCCESS(rc))
|
---|
112 | {
|
---|
113 | WARN(("err"));
|
---|
114 | setFramebufferEnd(pFb);
|
---|
115 | return rc;
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | setFramebufferEnd(pFb);
|
---|
120 | return VINF_SUCCESS;
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | struct CR_FRAMEBUFFER* CrFbDisplayBase::getFramebuffer()
|
---|
125 | {
|
---|
126 | return mpFb;
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | int CrFbDisplayBase::UpdateBegin(struct CR_FRAMEBUFFER *pFb)
|
---|
131 | {
|
---|
132 | ++mcUpdates;
|
---|
133 | Assert(!mFlags.fRegionsShanged || mcUpdates > 1);
|
---|
134 | return VINF_SUCCESS;
|
---|
135 | }
|
---|
136 |
|
---|
137 |
|
---|
138 | void CrFbDisplayBase::UpdateEnd(struct CR_FRAMEBUFFER *pFb)
|
---|
139 | {
|
---|
140 | --mcUpdates;
|
---|
141 | Assert(mcUpdates < UINT32_MAX/2);
|
---|
142 | if (!mcUpdates)
|
---|
143 | onUpdateEnd();
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | int CrFbDisplayBase::EntryCreated(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
|
---|
148 | {
|
---|
149 | if (!mcUpdates)
|
---|
150 | {
|
---|
151 | WARN(("err"));
|
---|
152 | return VERR_INVALID_STATE;
|
---|
153 | }
|
---|
154 | return VINF_SUCCESS;
|
---|
155 | }
|
---|
156 |
|
---|
157 |
|
---|
158 | int CrFbDisplayBase::EntryAdded(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
|
---|
159 | {
|
---|
160 | if (!mcUpdates)
|
---|
161 | {
|
---|
162 | WARN(("err"));
|
---|
163 | return VERR_INVALID_STATE;
|
---|
164 | }
|
---|
165 | mFlags.fRegionsShanged = 1;
|
---|
166 | return VINF_SUCCESS;
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | int CrFbDisplayBase::EntryReplaced(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hNewEntry,
|
---|
171 | HCR_FRAMEBUFFER_ENTRY hReplacedEntry)
|
---|
172 | {
|
---|
173 | if (!mcUpdates)
|
---|
174 | {
|
---|
175 | WARN(("err"));
|
---|
176 | return VERR_INVALID_STATE;
|
---|
177 | }
|
---|
178 | return VINF_SUCCESS;
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | int CrFbDisplayBase::EntryTexChanged(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
|
---|
183 | {
|
---|
184 | if (!mcUpdates)
|
---|
185 | {
|
---|
186 | WARN(("err"));
|
---|
187 | return VERR_INVALID_STATE;
|
---|
188 | }
|
---|
189 | return VINF_SUCCESS;
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | int CrFbDisplayBase::EntryRemoved(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
|
---|
194 | {
|
---|
195 | if (!mcUpdates)
|
---|
196 | {
|
---|
197 | WARN(("err"));
|
---|
198 | return VERR_INVALID_STATE;
|
---|
199 | }
|
---|
200 | mFlags.fRegionsShanged = 1;
|
---|
201 | return VINF_SUCCESS;
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 | int CrFbDisplayBase::EntryDestroyed(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
|
---|
206 | {
|
---|
207 | return VINF_SUCCESS;
|
---|
208 | }
|
---|
209 |
|
---|
210 |
|
---|
211 | int CrFbDisplayBase::EntryPosChanged(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
|
---|
212 | {
|
---|
213 | if (!mcUpdates)
|
---|
214 | {
|
---|
215 | WARN(("err"));
|
---|
216 | return VERR_INVALID_STATE;
|
---|
217 | }
|
---|
218 | mFlags.fRegionsShanged = 1;
|
---|
219 | return VINF_SUCCESS;
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 | int CrFbDisplayBase::RegionsChanged(struct CR_FRAMEBUFFER *pFb)
|
---|
224 | {
|
---|
225 | if (!mcUpdates)
|
---|
226 | {
|
---|
227 | WARN(("err"));
|
---|
228 | return VERR_INVALID_STATE;
|
---|
229 | }
|
---|
230 | mFlags.fRegionsShanged = 1;
|
---|
231 | return VINF_SUCCESS;
|
---|
232 | }
|
---|
233 |
|
---|
234 |
|
---|
235 | int CrFbDisplayBase::FramebufferChanged(struct CR_FRAMEBUFFER *pFb)
|
---|
236 | {
|
---|
237 | if (!mcUpdates)
|
---|
238 | {
|
---|
239 | WARN(("err"));
|
---|
240 | return VERR_INVALID_STATE;
|
---|
241 | }
|
---|
242 | return VINF_SUCCESS;
|
---|
243 | }
|
---|
244 |
|
---|
245 |
|
---|
246 | void CrFbDisplayBase::onUpdateEnd()
|
---|
247 | {
|
---|
248 | if (mFlags.fRegionsShanged)
|
---|
249 | {
|
---|
250 | mFlags.fRegionsShanged = 0;
|
---|
251 | if (getFramebuffer()) /*<-dont't do anything on cleanup*/
|
---|
252 | ueRegions();
|
---|
253 | }
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 | void CrFbDisplayBase::ueRegions()
|
---|
258 | {
|
---|
259 | }
|
---|
260 |
|
---|
261 |
|
---|
262 | DECLCALLBACK(bool) CrFbDisplayBase::entriesCreateCb(HCR_FRAMEBUFFER hFb, HCR_FRAMEBUFFER_ENTRY hEntry, void *pvContext)
|
---|
263 | {
|
---|
264 | int rc = ((ICrFbDisplay*)(pvContext))->EntryCreated(hFb, hEntry);
|
---|
265 | if (!RT_SUCCESS(rc))
|
---|
266 | {
|
---|
267 | WARN(("err"));
|
---|
268 | }
|
---|
269 | return true;
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | DECLCALLBACK(bool) CrFbDisplayBase::entriesDestroyCb(HCR_FRAMEBUFFER hFb, HCR_FRAMEBUFFER_ENTRY hEntry, void *pvContext)
|
---|
274 | {
|
---|
275 | int rc = ((ICrFbDisplay*)(pvContext))->EntryDestroyed(hFb, hEntry);
|
---|
276 | if (!RT_SUCCESS(rc))
|
---|
277 | {
|
---|
278 | WARN(("err"));
|
---|
279 | }
|
---|
280 | return true;
|
---|
281 | }
|
---|
282 |
|
---|
283 |
|
---|
284 | int CrFbDisplayBase::fbSynchAddAllEntries()
|
---|
285 | {
|
---|
286 | VBOXVR_SCR_COMPOSITOR_CONST_ITERATOR Iter;
|
---|
287 | const VBOXVR_SCR_COMPOSITOR_ENTRY *pEntry;
|
---|
288 |
|
---|
289 | CrVrScrCompositorConstIterInit(CrFbGetCompositor(mpFb), &Iter);
|
---|
290 | int rc = VINF_SUCCESS;
|
---|
291 |
|
---|
292 | CrFbVisitCreatedEntries(mpFb, entriesCreateCb, this);
|
---|
293 |
|
---|
294 | while ((pEntry = CrVrScrCompositorConstIterNext(&Iter)) != NULL)
|
---|
295 | {
|
---|
296 | HCR_FRAMEBUFFER_ENTRY hEntry = CrFbEntryFromCompositorEntry(pEntry);
|
---|
297 |
|
---|
298 | rc = EntryAdded(mpFb, hEntry);
|
---|
299 | if (!RT_SUCCESS(rc))
|
---|
300 | {
|
---|
301 | WARN(("err"));
|
---|
302 | EntryDestroyed(mpFb, hEntry);
|
---|
303 | break;
|
---|
304 | }
|
---|
305 | }
|
---|
306 |
|
---|
307 | return rc;
|
---|
308 | }
|
---|
309 |
|
---|
310 |
|
---|
311 | int CrFbDisplayBase::fbCleanupRemoveAllEntries()
|
---|
312 | {
|
---|
313 | VBOXVR_SCR_COMPOSITOR_CONST_ITERATOR Iter;
|
---|
314 | const VBOXVR_SCR_COMPOSITOR_ENTRY *pEntry;
|
---|
315 |
|
---|
316 | CrVrScrCompositorConstIterInit(CrFbGetCompositor(mpFb), &Iter);
|
---|
317 |
|
---|
318 | int rc = VINF_SUCCESS;
|
---|
319 |
|
---|
320 | while ((pEntry = CrVrScrCompositorConstIterNext(&Iter)) != NULL)
|
---|
321 | {
|
---|
322 | HCR_FRAMEBUFFER_ENTRY hEntry = CrFbEntryFromCompositorEntry(pEntry);
|
---|
323 | rc = EntryRemoved(mpFb, hEntry);
|
---|
324 | if (!RT_SUCCESS(rc))
|
---|
325 | {
|
---|
326 | WARN(("err"));
|
---|
327 | break;
|
---|
328 | }
|
---|
329 | }
|
---|
330 |
|
---|
331 | CrFbVisitCreatedEntries(mpFb, entriesDestroyCb, this);
|
---|
332 |
|
---|
333 | return rc;
|
---|
334 | }
|
---|
335 |
|
---|
336 |
|
---|
337 | int CrFbDisplayBase::setFramebufferBegin(struct CR_FRAMEBUFFER *pFb)
|
---|
338 | {
|
---|
339 | return UpdateBegin(pFb);
|
---|
340 | }
|
---|
341 |
|
---|
342 |
|
---|
343 | void CrFbDisplayBase::setFramebufferEnd(struct CR_FRAMEBUFFER *pFb)
|
---|
344 | {
|
---|
345 | UpdateEnd(pFb);
|
---|
346 | }
|
---|
347 |
|
---|
348 |
|
---|
349 | DECLCALLBACK(void) CrFbDisplayBase::slotEntryReleaseCB(HCR_FRAMEBUFFER hFb, HCR_FRAMEBUFFER_ENTRY hEntry, void *pvContext)
|
---|
350 | {
|
---|
351 | }
|
---|
352 |
|
---|
353 |
|
---|
354 | void CrFbDisplayBase::slotRelease()
|
---|
355 | {
|
---|
356 | Assert(mhSlot);
|
---|
357 | CrFbDDataReleaseSlot(mpFb, mhSlot, slotEntryReleaseCB, this);
|
---|
358 | }
|
---|
359 |
|
---|
360 |
|
---|
361 | int CrFbDisplayBase::fbCleanup()
|
---|
362 | {
|
---|
363 | if (mhSlot)
|
---|
364 | {
|
---|
365 | slotRelease();
|
---|
366 | mhSlot = 0;
|
---|
367 | }
|
---|
368 |
|
---|
369 | mpFb = NULL;
|
---|
370 | return VINF_SUCCESS;
|
---|
371 | }
|
---|
372 |
|
---|
373 |
|
---|
374 | int CrFbDisplayBase::fbSync()
|
---|
375 | {
|
---|
376 | return VINF_SUCCESS;
|
---|
377 | }
|
---|
378 |
|
---|
379 |
|
---|
380 | CRHTABLE_HANDLE CrFbDisplayBase::slotGet()
|
---|
381 | {
|
---|
382 | if (!mhSlot)
|
---|
383 | {
|
---|
384 | if (mpFb)
|
---|
385 | mhSlot = CrFbDDataAllocSlot(mpFb);
|
---|
386 | }
|
---|
387 |
|
---|
388 | return mhSlot;
|
---|
389 | }
|
---|
390 |
|
---|