1 | /* $Id: display_window_rootvr.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * Presenter API: CrFbDisplayWindowRootVr class implementation -- display seamless content (visible regions).
|
---|
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 |
|
---|
22 | CrFbDisplayWindowRootVr::CrFbDisplayWindowRootVr(const RTRECT *pViewportRect, uint64_t parentId) :
|
---|
23 | CrFbDisplayWindow(pViewportRect, parentId)
|
---|
24 | {
|
---|
25 | CrVrScrCompositorInit(&mCompositor, NULL);
|
---|
26 | }
|
---|
27 |
|
---|
28 |
|
---|
29 | int CrFbDisplayWindowRootVr::EntryCreated(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
|
---|
30 | {
|
---|
31 | int rc = CrFbDisplayWindow::EntryCreated(pFb, hEntry);
|
---|
32 | if (!RT_SUCCESS(rc))
|
---|
33 | {
|
---|
34 | WARN(("err"));
|
---|
35 | return rc;
|
---|
36 | }
|
---|
37 |
|
---|
38 | Assert(!CrFbDDataEntryGet(hEntry, slotGet()));
|
---|
39 |
|
---|
40 | const VBOXVR_SCR_COMPOSITOR_ENTRY* pSrcEntry = CrFbEntryGetCompositorEntry(hEntry);
|
---|
41 | VBOXVR_SCR_COMPOSITOR_ENTRY *pMyEntry = entryAlloc();
|
---|
42 | CrVrScrCompositorEntryInit(pMyEntry, CrVrScrCompositorEntryRectGet(pSrcEntry), CrVrScrCompositorEntryTexGet(pSrcEntry), NULL);
|
---|
43 | CrVrScrCompositorEntryFlagsSet(pMyEntry, CrVrScrCompositorEntryFlagsGet(pSrcEntry));
|
---|
44 | rc = CrFbDDataEntryPut(hEntry, slotGet(), pMyEntry);
|
---|
45 | if (!RT_SUCCESS(rc))
|
---|
46 | {
|
---|
47 | WARN(("CrFbDDataEntryPut failed rc %d", rc));
|
---|
48 | entryFree(pMyEntry);
|
---|
49 | return rc;
|
---|
50 | }
|
---|
51 |
|
---|
52 | return VINF_SUCCESS;
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | int CrFbDisplayWindowRootVr::EntryAdded(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
|
---|
57 | {
|
---|
58 | int rc = CrFbDisplayWindow::EntryAdded(pFb, hEntry);
|
---|
59 | if (!RT_SUCCESS(rc))
|
---|
60 | {
|
---|
61 | WARN(("err"));
|
---|
62 | return rc;
|
---|
63 | }
|
---|
64 |
|
---|
65 | const VBOXVR_SCR_COMPOSITOR_ENTRY* pSrcEntry = CrFbEntryGetCompositorEntry(hEntry);
|
---|
66 | VBOXVR_SCR_COMPOSITOR_ENTRY *pMyEntry = (VBOXVR_SCR_COMPOSITOR_ENTRY*)CrFbDDataEntryGet(hEntry, slotGet());
|
---|
67 | Assert(pMyEntry);
|
---|
68 | CrVrScrCompositorEntryTexSet(pMyEntry, CrVrScrCompositorEntryTexGet(pSrcEntry));
|
---|
69 |
|
---|
70 | return VINF_SUCCESS;
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | int CrFbDisplayWindowRootVr::EntryReplaced(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hNewEntry, HCR_FRAMEBUFFER_ENTRY hReplacedEntry)
|
---|
75 | {
|
---|
76 | int rc = CrFbDisplayWindow::EntryReplaced(pFb, hNewEntry, hReplacedEntry);
|
---|
77 | if (!RT_SUCCESS(rc))
|
---|
78 | {
|
---|
79 | WARN(("err"));
|
---|
80 | return rc;
|
---|
81 | }
|
---|
82 |
|
---|
83 | const VBOXVR_SCR_COMPOSITOR_ENTRY* pSrcNewEntry = CrFbEntryGetCompositorEntry(hNewEntry);
|
---|
84 | VBOXVR_SCR_COMPOSITOR_ENTRY *pMyEntry = (VBOXVR_SCR_COMPOSITOR_ENTRY*)CrFbDDataEntryGet(hNewEntry, slotGet());
|
---|
85 | CrVrScrCompositorEntryTexSet(pMyEntry, CrVrScrCompositorEntryTexGet(pSrcNewEntry));
|
---|
86 |
|
---|
87 | return VINF_SUCCESS;
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | int CrFbDisplayWindowRootVr::EntryTexChanged(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
|
---|
92 | {
|
---|
93 | int rc = CrFbDisplayWindow::EntryTexChanged(pFb, hEntry);
|
---|
94 | if (!RT_SUCCESS(rc))
|
---|
95 | {
|
---|
96 | WARN(("err"));
|
---|
97 | return rc;
|
---|
98 | }
|
---|
99 |
|
---|
100 | const VBOXVR_SCR_COMPOSITOR_ENTRY* pSrcEntry = CrFbEntryGetCompositorEntry(hEntry);
|
---|
101 | VBOXVR_SCR_COMPOSITOR_ENTRY *pMyEntry = (VBOXVR_SCR_COMPOSITOR_ENTRY*)CrFbDDataEntryGet(hEntry, slotGet());
|
---|
102 | CrVrScrCompositorEntryTexSet(pMyEntry, CrVrScrCompositorEntryTexGet(pSrcEntry));
|
---|
103 |
|
---|
104 | return VINF_SUCCESS;
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 | int CrFbDisplayWindowRootVr::EntryRemoved(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
|
---|
109 | {
|
---|
110 | int rc = CrFbDisplayWindow::EntryRemoved(pFb, hEntry);
|
---|
111 | if (!RT_SUCCESS(rc))
|
---|
112 | {
|
---|
113 | WARN(("err"));
|
---|
114 | return rc;
|
---|
115 | }
|
---|
116 |
|
---|
117 | VBOXVR_SCR_COMPOSITOR_ENTRY *pMyEntry = (VBOXVR_SCR_COMPOSITOR_ENTRY*)CrFbDDataEntryGet(hEntry, slotGet());
|
---|
118 | rc = CrVrScrCompositorEntryRegionsSet(&mCompositor, pMyEntry, NULL, 0, NULL, false, NULL);
|
---|
119 | if (!RT_SUCCESS(rc))
|
---|
120 | {
|
---|
121 | WARN(("err"));
|
---|
122 | return rc;
|
---|
123 | }
|
---|
124 |
|
---|
125 | return VINF_SUCCESS;
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | int CrFbDisplayWindowRootVr::EntryDestroyed(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
|
---|
130 | {
|
---|
131 | int rc = CrFbDisplayWindow::EntryDestroyed(pFb, hEntry);
|
---|
132 | if (!RT_SUCCESS(rc))
|
---|
133 | {
|
---|
134 | WARN(("err"));
|
---|
135 | return rc;
|
---|
136 | }
|
---|
137 |
|
---|
138 | const VBOXVR_SCR_COMPOSITOR_ENTRY* pSrcEntry = CrFbEntryGetCompositorEntry(hEntry);
|
---|
139 | VBOXVR_SCR_COMPOSITOR_ENTRY *pMyEntry = (VBOXVR_SCR_COMPOSITOR_ENTRY*)CrFbDDataEntryGet(hEntry, slotGet());
|
---|
140 | CrVrScrCompositorEntryCleanup(pMyEntry);
|
---|
141 | entryFree(pMyEntry);
|
---|
142 |
|
---|
143 | return VINF_SUCCESS;
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | int CrFbDisplayWindowRootVr::setViewportRect(const RTRECT *pViewportRect)
|
---|
148 | {
|
---|
149 | int rc = CrFbDisplayWindow::setViewportRect(pViewportRect);
|
---|
150 | if (!RT_SUCCESS(rc))
|
---|
151 | {
|
---|
152 | WARN(("err"));
|
---|
153 | return rc;
|
---|
154 | }
|
---|
155 |
|
---|
156 | rc = setRegionsChanged();
|
---|
157 | if (!RT_SUCCESS(rc))
|
---|
158 | {
|
---|
159 | WARN(("err"));
|
---|
160 | return rc;
|
---|
161 | }
|
---|
162 |
|
---|
163 | return VINF_SUCCESS;
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | int CrFbDisplayWindowRootVr::windowSetCompositor(bool fSet)
|
---|
168 | {
|
---|
169 | if (fSet)
|
---|
170 | return getWindow()->SetCompositor(&mCompositor);
|
---|
171 | return getWindow()->SetCompositor(NULL);
|
---|
172 | }
|
---|
173 |
|
---|
174 |
|
---|
175 | void CrFbDisplayWindowRootVr::ueRegions()
|
---|
176 | {
|
---|
177 | synchCompositorRegions();
|
---|
178 | }
|
---|
179 |
|
---|
180 |
|
---|
181 | int CrFbDisplayWindowRootVr::compositorMarkUpdated()
|
---|
182 | {
|
---|
183 | CrVrScrCompositorClear(&mCompositor);
|
---|
184 |
|
---|
185 | int rc = CrVrScrCompositorRectSet(&mCompositor, CrVrScrCompositorRectGet(CrFbGetCompositor(getFramebuffer())), NULL);
|
---|
186 | if (!RT_SUCCESS(rc))
|
---|
187 | {
|
---|
188 | WARN(("err"));
|
---|
189 | return rc;
|
---|
190 | }
|
---|
191 |
|
---|
192 | rc = setRegionsChanged();
|
---|
193 | if (!RT_SUCCESS(rc))
|
---|
194 | {
|
---|
195 | WARN(("screenChanged failed %d", rc));
|
---|
196 | return rc;
|
---|
197 | }
|
---|
198 |
|
---|
199 | return VINF_SUCCESS;
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | int CrFbDisplayWindowRootVr::screenChanged()
|
---|
204 | {
|
---|
205 | int rc = compositorMarkUpdated();
|
---|
206 | if (!RT_SUCCESS(rc))
|
---|
207 | {
|
---|
208 | WARN(("err"));
|
---|
209 | return rc;
|
---|
210 | }
|
---|
211 |
|
---|
212 | rc = CrFbDisplayWindow::screenChanged();
|
---|
213 | if (!RT_SUCCESS(rc))
|
---|
214 | {
|
---|
215 | WARN(("screenChanged failed %d", rc));
|
---|
216 | return rc;
|
---|
217 | }
|
---|
218 |
|
---|
219 | return VINF_SUCCESS;
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 | const struct RTRECT* CrFbDisplayWindowRootVr::getRect()
|
---|
224 | {
|
---|
225 | return CrVrScrCompositorRectGet(&mCompositor);
|
---|
226 | }
|
---|
227 |
|
---|
228 | int CrFbDisplayWindowRootVr::fbCleanup()
|
---|
229 | {
|
---|
230 | int rc = clearCompositor();
|
---|
231 | if (!RT_SUCCESS(rc))
|
---|
232 | {
|
---|
233 | WARN(("err"));
|
---|
234 | return rc;
|
---|
235 | }
|
---|
236 |
|
---|
237 | return CrFbDisplayWindow::fbCleanup();
|
---|
238 | }
|
---|
239 |
|
---|
240 |
|
---|
241 | int CrFbDisplayWindowRootVr::fbSync()
|
---|
242 | {
|
---|
243 | int rc = synchCompositor();
|
---|
244 | if (!RT_SUCCESS(rc))
|
---|
245 | {
|
---|
246 | WARN(("err"));
|
---|
247 | return rc;
|
---|
248 | }
|
---|
249 |
|
---|
250 | return CrFbDisplayWindow::fbSync();
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | VBOXVR_SCR_COMPOSITOR_ENTRY* CrFbDisplayWindowRootVr::entryAlloc()
|
---|
255 | {
|
---|
256 | #ifndef VBOXVDBG_MEMCACHE_DISABLE
|
---|
257 | return (VBOXVR_SCR_COMPOSITOR_ENTRY*)RTMemCacheAlloc(g_CrPresenter.CEntryLookasideList);
|
---|
258 | #else
|
---|
259 | return (VBOXVR_SCR_COMPOSITOR_ENTRY*)RTMemAlloc(sizeof (VBOXVR_SCR_COMPOSITOR_ENTRY));
|
---|
260 | #endif
|
---|
261 | }
|
---|
262 |
|
---|
263 |
|
---|
264 | void CrFbDisplayWindowRootVr::entryFree(VBOXVR_SCR_COMPOSITOR_ENTRY* pEntry)
|
---|
265 | {
|
---|
266 | Assert(!CrVrScrCompositorEntryIsUsed(pEntry));
|
---|
267 | #ifndef VBOXVDBG_MEMCACHE_DISABLE
|
---|
268 | RTMemCacheFree(g_CrPresenter.CEntryLookasideList, pEntry);
|
---|
269 | #else
|
---|
270 | RTMemFree(pEntry);
|
---|
271 | #endif
|
---|
272 | }
|
---|
273 |
|
---|
274 |
|
---|
275 | int CrFbDisplayWindowRootVr::synchCompositorRegions()
|
---|
276 | {
|
---|
277 | int rc;
|
---|
278 |
|
---|
279 | rootVrTranslateForPos();
|
---|
280 |
|
---|
281 | /* ensure the rootvr compositor does not hold any data,
|
---|
282 | * i.e. cleanup all rootvr entries data */
|
---|
283 | CrVrScrCompositorClear(&mCompositor);
|
---|
284 |
|
---|
285 | rc = CrVrScrCompositorIntersectedList(CrFbGetCompositor(getFramebuffer()), &cr_server.RootVr, &mCompositor, rootVrGetCEntry, this, NULL);
|
---|
286 | if (!RT_SUCCESS(rc))
|
---|
287 | {
|
---|
288 | WARN(("CrVrScrCompositorIntersectedList failed, rc %d", rc));
|
---|
289 | return rc;
|
---|
290 | }
|
---|
291 |
|
---|
292 | return getWindow()->SetVisibleRegionsChanged();
|
---|
293 | }
|
---|
294 |
|
---|
295 |
|
---|
296 | int CrFbDisplayWindowRootVr::synchCompositor()
|
---|
297 | {
|
---|
298 | int rc = compositorMarkUpdated();
|
---|
299 | if (!RT_SUCCESS(rc))
|
---|
300 | {
|
---|
301 | WARN(("compositorMarkUpdated failed, rc %d", rc));
|
---|
302 | return rc;
|
---|
303 | }
|
---|
304 |
|
---|
305 | rc = fbSynchAddAllEntries();
|
---|
306 | if (!RT_SUCCESS(rc))
|
---|
307 | {
|
---|
308 | WARN(("fbSynchAddAllEntries failed, rc %d", rc));
|
---|
309 | return rc;
|
---|
310 | }
|
---|
311 |
|
---|
312 | return rc;
|
---|
313 | }
|
---|
314 |
|
---|
315 |
|
---|
316 | int CrFbDisplayWindowRootVr::clearCompositor()
|
---|
317 | {
|
---|
318 | return fbCleanupRemoveAllEntries();
|
---|
319 | }
|
---|
320 |
|
---|
321 |
|
---|
322 | void CrFbDisplayWindowRootVr::rootVrTranslateForPos()
|
---|
323 | {
|
---|
324 | const RTRECT *pRect = getViewportRect();
|
---|
325 | const struct VBVAINFOSCREEN* pScreen = CrFbGetScreenInfo(getFramebuffer());
|
---|
326 | int32_t x = pScreen->i32OriginX;
|
---|
327 | int32_t y = pScreen->i32OriginY;
|
---|
328 | int32_t dx = cr_server.RootVrCurPoint.x - x;
|
---|
329 | int32_t dy = cr_server.RootVrCurPoint.y - y;
|
---|
330 |
|
---|
331 | cr_server.RootVrCurPoint.x = x;
|
---|
332 | cr_server.RootVrCurPoint.y = y;
|
---|
333 |
|
---|
334 | VBoxVrListTranslate(&cr_server.RootVr, dx, dy);
|
---|
335 | }
|
---|
336 |
|
---|
337 |
|
---|
338 | DECLCALLBACK(VBOXVR_SCR_COMPOSITOR_ENTRY*) CrFbDisplayWindowRootVr::rootVrGetCEntry(const VBOXVR_SCR_COMPOSITOR_ENTRY*pEntry, void *pvContext)
|
---|
339 | {
|
---|
340 | CrFbDisplayWindowRootVr *pThis = (CrFbDisplayWindowRootVr*)pvContext;
|
---|
341 | HCR_FRAMEBUFFER_ENTRY hEntry = CrFbEntryFromCompositorEntry(pEntry);
|
---|
342 | VBOXVR_SCR_COMPOSITOR_ENTRY *pMyEntry = (VBOXVR_SCR_COMPOSITOR_ENTRY*)CrFbDDataEntryGet(hEntry, pThis->slotGet());
|
---|
343 | Assert(!CrVrScrCompositorEntryIsUsed(pMyEntry));
|
---|
344 | CrVrScrCompositorEntryRectSet(&pThis->mCompositor, pMyEntry, CrVrScrCompositorEntryRectGet(pEntry));
|
---|
345 | return pMyEntry;
|
---|
346 | }
|
---|
347 |
|
---|