VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/presenter/display_window.cpp@ 78875

Last change on this file since 78875 was 78263, checked in by vboxsync, 6 years ago

Config.kmk,GuestHost\OpenGL,HostServices\SharedOpenGL: Fix a bunch of compiler warnings and enable them again

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/* $Id: display_window.cpp 78263 2019-04-23 18:41:06Z vboxsync $ */
2
3/** @file
4 * Presenter API: CrFbDisplayWindow class implementation -- display content into host GUI window.
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
21CrFbDisplayWindow::CrFbDisplayWindow(const RTRECT *pViewportRect, uint64_t parentId) :
22 mpWindow(NULL),
23 mViewportRect(*pViewportRect),
24 mu32Screen(~UINT32_C(0)),
25 mParentId(parentId)
26{
27 mFlags.u32Value = 0;
28}
29
30
31CrFbDisplayWindow::~CrFbDisplayWindow()
32{
33 if (mpWindow)
34 delete mpWindow;
35}
36
37
38int CrFbDisplayWindow::UpdateBegin(struct CR_FRAMEBUFFER *pFb)
39{
40 int rc = mpWindow ? mpWindow->UpdateBegin() : VINF_SUCCESS;
41 if (RT_SUCCESS(rc))
42 {
43 rc = CrFbDisplayBase::UpdateBegin(pFb);
44 if (RT_SUCCESS(rc))
45 return VINF_SUCCESS;
46 else
47 {
48 WARN(("err"));
49 if (mpWindow)
50 mpWindow->UpdateEnd();
51 }
52 }
53 else
54 WARN(("err"));
55
56 return rc;
57}
58
59
60void CrFbDisplayWindow::UpdateEnd(struct CR_FRAMEBUFFER *pFb)
61{
62 CrFbDisplayBase::UpdateEnd(pFb);
63
64 if (mpWindow)
65 mpWindow->UpdateEnd();
66}
67
68
69int CrFbDisplayWindow::RegionsChanged(struct CR_FRAMEBUFFER *pFb)
70{
71 int rc = CrFbDisplayBase::RegionsChanged(pFb);
72 if (!RT_SUCCESS(rc))
73 {
74 WARN(("err"));
75 return rc;
76 }
77
78 if (mpWindow && mpWindow->GetParentId())
79 {
80 rc = mpWindow->Create();
81 if (!RT_SUCCESS(rc))
82 {
83 WARN(("err"));
84 return rc;
85 }
86 }
87
88 return VINF_SUCCESS;
89}
90
91
92int CrFbDisplayWindow::EntryCreated(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
93{
94 int rc = CrFbDisplayBase::EntryCreated(pFb, hEntry);
95 if (!RT_SUCCESS(rc))
96 {
97 WARN(("err"));
98 return rc;
99 }
100
101 if (mpWindow && mpWindow->GetParentId())
102 {
103 rc = mpWindow->Create();
104 if (!RT_SUCCESS(rc))
105 {
106 WARN(("err"));
107 return rc;
108 }
109 }
110
111 return VINF_SUCCESS;
112}
113
114
115int CrFbDisplayWindow::EntryReplaced(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hNewEntry, HCR_FRAMEBUFFER_ENTRY hReplacedEntry)
116{
117 int rc = CrFbDisplayBase::EntryReplaced(pFb, hNewEntry, hReplacedEntry);
118 if (!RT_SUCCESS(rc))
119 {
120 WARN(("err"));
121 return rc;
122 }
123
124 if (mpWindow && mpWindow->GetParentId())
125 {
126 rc = mpWindow->Create();
127 if (!RT_SUCCESS(rc))
128 {
129 WARN(("err"));
130 return rc;
131 }
132 }
133
134 return VINF_SUCCESS;
135}
136
137
138int CrFbDisplayWindow::EntryTexChanged(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
139{
140 int rc = CrFbDisplayBase::EntryTexChanged(pFb, hEntry);
141 if (!RT_SUCCESS(rc))
142 {
143 WARN(("err"));
144 return rc;
145 }
146
147 if (mpWindow && mpWindow->GetParentId())
148 {
149 rc = mpWindow->Create();
150 if (!RT_SUCCESS(rc))
151 {
152 WARN(("err"));
153 return rc;
154 }
155 }
156
157 return VINF_SUCCESS;
158}
159
160
161int CrFbDisplayWindow::FramebufferChanged(struct CR_FRAMEBUFFER *pFb)
162{
163 int rc = CrFbDisplayBase::FramebufferChanged(pFb);
164 if (!RT_SUCCESS(rc))
165 {
166 WARN(("err"));
167 return rc;
168 }
169
170 return screenChanged();
171}
172
173
174const RTRECT* CrFbDisplayWindow::getViewportRect()
175{
176 return &mViewportRect;
177}
178
179
180int CrFbDisplayWindow::setViewportRect(const RTRECT *pViewportRect)
181{
182 if (!isUpdating())
183 {
184 WARN(("not updating!"));
185 return VERR_INVALID_STATE;
186 }
187
188 // always call SetPosition to ensure window is adjustep properly
189 // if (pViewportRect->xLeft != mViewportRect.xLeft || pViewportRect->yTop != mViewportRect.yTop)
190 if (mpWindow)
191 {
192 const RTRECT* pRect = getRect();
193 int rc = mpWindow->SetPosition(pRect->xLeft - pViewportRect->xLeft, pRect->yTop - pViewportRect->yTop);
194 if (!RT_SUCCESS(rc))
195 {
196 WARN(("SetPosition failed"));
197 return rc;
198 }
199 }
200
201 mViewportRect = *pViewportRect;
202
203 return VINF_SUCCESS;
204}
205
206
207CrFbWindow * CrFbDisplayWindow::windowDetach(bool fCleanup)
208{
209 if (isUpdating())
210 {
211 WARN(("updating!"));
212 return NULL;
213 }
214
215 CrFbWindow * pWindow = mpWindow;
216 if (mpWindow)
217 {
218 if (fCleanup)
219 windowCleanup();
220 mpWindow = NULL;
221 }
222 return pWindow;
223}
224
225
226CrFbWindow * CrFbDisplayWindow::windowAttach(CrFbWindow * pNewWindow)
227{
228 if (isUpdating())
229 {
230 WARN(("updating!"));
231 return NULL;
232 }
233
234 if (mpWindow)
235 windowDetach();
236
237 mpWindow = pNewWindow;
238 if (pNewWindow)
239 windowSync();
240
241 return mpWindow;
242}
243
244
245int CrFbDisplayWindow::reparent(uint64_t parentId)
246{
247 if (!isUpdating())
248 {
249 WARN(("not updating!"));
250 return VERR_INVALID_STATE;
251 }
252
253 crDebug("CrFbDisplayWindow: change parent from %p to %p.", mParentId, parentId);
254
255 mParentId = parentId;
256 int rc = VINF_SUCCESS;
257
258 /* Force notify Render SPU about parent window ID change in order to prevent
259 * crashes when it tries to access already deallocated parent window.
260 * Previously, we also used isActive() here, however it might become FALSE for the case
261 * when VM Window goes fullscreen mode and back. */
262 if ( /* isActive() && */ mpWindow)
263 {
264 rc = mpWindow->Reparent(parentId);
265 if (!RT_SUCCESS(rc))
266 WARN(("window reparent failed"));
267
268 mFlags.fNeForce = 1;
269 }
270
271 return rc;
272}
273
274
275bool CrFbDisplayWindow::isVisible()
276{
277 HCR_FRAMEBUFFER hFb = getFramebuffer();
278 if (!hFb)
279 return false;
280 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(hFb);
281 return !CrVrScrCompositorIsEmpty(pCompositor);
282}
283
284
285int CrFbDisplayWindow::winVisibilityChanged()
286{
287 HCR_FRAMEBUFFER hFb = getFramebuffer();
288 if (!hFb || !CrFbIsEnabled(hFb))
289 {
290 Assert(!mpWindow || !mpWindow->IsVisivle());
291 return VINF_SUCCESS;
292 }
293
294 int rc = VINF_SUCCESS;
295
296 if (mpWindow)
297 {
298 rc = mpWindow->UpdateBegin();
299 if (RT_SUCCESS(rc))
300 {
301 rc = mpWindow->SetVisible(!g_CrPresenter.fWindowsForceHidden);
302 if (!RT_SUCCESS(rc))
303 WARN(("SetVisible failed, rc %d", rc));
304
305 mpWindow->UpdateEnd();
306 }
307 else
308 WARN(("UpdateBegin failed, rc %d", rc));
309 }
310
311 return rc;
312}
313
314
315CrFbWindow* CrFbDisplayWindow::getWindow()
316{
317 return mpWindow;
318}
319
320
321void CrFbDisplayWindow::onUpdateEnd()
322{
323 CrFbDisplayBase::onUpdateEnd();
324 bool fVisible = isVisible();
325 if (RT_BOOL(mFlags.fNeVisible) != fVisible || mFlags.fNeForce)
326 {
327 crVBoxServerNotifyEvent(mu32Screen,
328 fVisible? VBOX3D_NOTIFY_EVENT_TYPE_3DDATA_VISIBLE:
329 VBOX3D_NOTIFY_EVENT_TYPE_3DDATA_HIDDEN,
330 NULL, 0);
331 mFlags.fNeVisible = fVisible;
332 mFlags.fNeForce = 0;
333 }
334}
335
336
337void CrFbDisplayWindow::ueRegions()
338{
339 if (mpWindow)
340 mpWindow->SetVisibleRegionsChanged();
341}
342
343
344int CrFbDisplayWindow::screenChanged()
345{
346 if (!isUpdating())
347 {
348 WARN(("not updating!"));
349 return VERR_INVALID_STATE;
350 }
351
352 int rc = windowDimensionsSync();
353 if (!RT_SUCCESS(rc))
354 {
355 WARN(("windowDimensionsSync failed rc %d", rc));
356 return rc;
357 }
358
359 return VINF_SUCCESS;
360}
361
362
363int CrFbDisplayWindow::windowSetCompositor(bool fSet)
364{
365 if (!mpWindow)
366 return VINF_SUCCESS;
367
368 if (fSet)
369 {
370 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(getFramebuffer());
371 return mpWindow->SetCompositor(pCompositor);
372 }
373 return mpWindow->SetCompositor(NULL);
374}
375
376
377int CrFbDisplayWindow::windowCleanup()
378{
379 if (!mpWindow)
380 return VINF_SUCCESS;
381
382 int rc = mpWindow->UpdateBegin();
383 if (!RT_SUCCESS(rc))
384 {
385 WARN(("err"));
386 return rc;
387 }
388
389 rc = windowDimensionsSync(true);
390 if (!RT_SUCCESS(rc))
391 {
392 WARN(("err"));
393 mpWindow->UpdateEnd();
394 return rc;
395 }
396
397 rc = windowSetCompositor(false);
398 if (!RT_SUCCESS(rc))
399 {
400 WARN(("err"));
401 mpWindow->UpdateEnd();
402 return rc;
403 }
404
405 mpWindow->UpdateEnd();
406
407 return VINF_SUCCESS;
408}
409
410
411int CrFbDisplayWindow::fbCleanup()
412{
413 int rc = windowCleanup();
414 if (!RT_SUCCESS(rc))
415 {
416 WARN(("windowCleanup failed"));
417 return rc;
418 }
419 return CrFbDisplayBase::fbCleanup();
420}
421
422
423bool CrFbDisplayWindow::isActive()
424{
425 HCR_FRAMEBUFFER hFb = getFramebuffer();
426 return hFb && CrFbIsEnabled(hFb);
427}
428
429
430int CrFbDisplayWindow::windowDimensionsSync(bool fForceCleanup)
431{
432 int rc = VINF_SUCCESS;
433
434 if (!mpWindow)
435 return VINF_SUCCESS;
436
437 //HCR_FRAMEBUFFER hFb = getFramebuffer();
438 if (!fForceCleanup && isActive())
439 {
440 const RTRECT* pRect = getRect();
441
442 if (mpWindow->GetParentId() != mParentId)
443 {
444 rc = mpWindow->Reparent(mParentId);
445 if (!RT_SUCCESS(rc))
446 {
447 WARN(("err"));
448 return rc;
449 }
450 }
451
452 rc = mpWindow->SetPosition(pRect->xLeft - mViewportRect.xLeft, pRect->yTop - mViewportRect.yTop);
453 if (!RT_SUCCESS(rc))
454 {
455 WARN(("err"));
456 return rc;
457 }
458
459 setRegionsChanged();
460
461 rc = mpWindow->SetSize((uint32_t)(pRect->xRight - pRect->xLeft), (uint32_t)(pRect->yBottom - pRect->yTop));
462 if (!RT_SUCCESS(rc))
463 {
464 WARN(("err"));
465 return rc;
466 }
467
468 rc = mpWindow->SetVisible(!g_CrPresenter.fWindowsForceHidden);
469 if (!RT_SUCCESS(rc))
470 {
471 WARN(("err"));
472 return rc;
473 }
474 }
475 else
476 {
477 rc = mpWindow->SetVisible(false);
478 if (!RT_SUCCESS(rc))
479 {
480 WARN(("err"));
481 return rc;
482 }
483#if 0
484 rc = mpWindow->Reparent(mDefaultParentId);
485 if (!RT_SUCCESS(rc))
486 {
487 WARN(("err"));
488 return rc;
489 }
490#endif
491 }
492
493 return rc;
494}
495
496
497int CrFbDisplayWindow::windowSync()
498{
499 if (!mpWindow)
500 return VINF_SUCCESS;
501
502 int rc = mpWindow->UpdateBegin();
503 if (!RT_SUCCESS(rc))
504 {
505 WARN(("err"));
506 return rc;
507 }
508
509 rc = windowSetCompositor(true);
510 if (!RT_SUCCESS(rc))
511 {
512 WARN(("err"));
513 mpWindow->UpdateEnd();
514 return rc;
515 }
516
517 rc = windowDimensionsSync();
518 if (!RT_SUCCESS(rc))
519 {
520 WARN(("err"));
521 mpWindow->UpdateEnd();
522 return rc;
523 }
524
525 mpWindow->UpdateEnd();
526
527 return rc;
528}
529
530
531int CrFbDisplayWindow::fbSync()
532{
533 int rc = CrFbDisplayBase::fbSync();
534 if (!RT_SUCCESS(rc))
535 {
536 WARN(("err"));
537 return rc;
538 }
539
540 HCR_FRAMEBUFFER hFb = getFramebuffer();
541
542 mu32Screen = CrFbGetScreenInfo(hFb)->u32ViewIndex;
543
544 rc = windowSync();
545 if (!RT_SUCCESS(rc))
546 {
547 WARN(("windowSync failed %d", rc));
548 return rc;
549 }
550
551 if (CrFbHas3DData(hFb))
552 {
553 if (mpWindow && mpWindow->GetParentId())
554 {
555 rc = mpWindow->Create();
556 if (!RT_SUCCESS(rc))
557 {
558 WARN(("err"));
559 return rc;
560 }
561 }
562 }
563
564 return VINF_SUCCESS;
565}
566
567
568const struct RTRECT* CrFbDisplayWindow::getRect()
569{
570 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(getFramebuffer());
571 return CrVrScrCompositorRectGet(pCompositor);
572}
573
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette