VirtualBox

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

Last change on this file since 54834 was 54834, checked in by vboxsync, 10 years ago

Frontend,SharedOpenGL: 3D notification without safearray.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1/* $Id: display_window.cpp 54834 2015-03-18 15:08:46Z vboxsync $ */
2
3/** @file
4 * Presenter API: CrFbDisplayWindow class implementation -- display content into host GUI window.
5 */
6
7/*
8 * Copyright (C) 2014 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(~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 CrFbWindow * pOld = mpWindow;
235 if (mpWindow)
236 windowDetach();
237
238 mpWindow = pNewWindow;
239 if (pNewWindow)
240 windowSync();
241
242 return mpWindow;
243}
244
245
246int CrFbDisplayWindow::reparent(uint64_t parentId)
247{
248 if (!isUpdating())
249 {
250 WARN(("not updating!"));
251 return VERR_INVALID_STATE;
252 }
253
254 crDebug("CrFbDisplayWindow: change parent from %p to %p.", mParentId, parentId);
255
256 mParentId = parentId;
257 int rc = VINF_SUCCESS;
258
259 if (isActive() && mpWindow)
260 {
261 rc = mpWindow->Reparent(parentId);
262 if (!RT_SUCCESS(rc))
263 WARN(("window reparent failed"));
264
265 mFlags.fNeForce = 1;
266 }
267
268 return rc;
269}
270
271
272bool CrFbDisplayWindow::isVisible()
273{
274 HCR_FRAMEBUFFER hFb = getFramebuffer();
275 if (!hFb)
276 return false;
277 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(hFb);
278 return !CrVrScrCompositorIsEmpty(pCompositor);
279}
280
281
282int CrFbDisplayWindow::winVisibilityChanged()
283{
284 HCR_FRAMEBUFFER hFb = getFramebuffer();
285 if (!hFb || !CrFbIsEnabled(hFb))
286 {
287 Assert(!mpWindow || !mpWindow->IsVisivle());
288 return VINF_SUCCESS;
289 }
290
291 int rc = VINF_SUCCESS;
292
293 if (mpWindow)
294 {
295 rc = mpWindow->UpdateBegin();
296 if (RT_SUCCESS(rc))
297 {
298 rc = mpWindow->SetVisible(!g_CrPresenter.fWindowsForceHidden);
299 if (!RT_SUCCESS(rc))
300 WARN(("SetVisible failed, rc %d", rc));
301
302 mpWindow->UpdateEnd();
303 }
304 else
305 WARN(("UpdateBegin failed, rc %d", rc));
306 }
307
308 return rc;
309}
310
311
312CrFbWindow* CrFbDisplayWindow::getWindow()
313{
314 return mpWindow;
315}
316
317
318void CrFbDisplayWindow::onUpdateEnd()
319{
320 CrFbDisplayBase::onUpdateEnd();
321 bool fVisible = isVisible();
322 if (mFlags.fNeVisible != fVisible || mFlags.fNeForce)
323 {
324 crVBoxServerNotifyEvent(mu32Screen,
325 fVisible? VBOX3D_NOTIFY_EVENT_TYPE_3DDATA_VISIBLE:
326 VBOX3D_NOTIFY_EVENT_TYPE_3DDATA_HIDDEN,
327 NULL, 0);
328 mFlags.fNeVisible = fVisible;
329 mFlags.fNeForce = 0;
330 }
331}
332
333
334void CrFbDisplayWindow::ueRegions()
335{
336 if (mpWindow)
337 mpWindow->SetVisibleRegionsChanged();
338}
339
340
341int CrFbDisplayWindow::screenChanged()
342{
343 if (!isUpdating())
344 {
345 WARN(("not updating!"));
346 return VERR_INVALID_STATE;
347 }
348
349 int rc = windowDimensionsSync();
350 if (!RT_SUCCESS(rc))
351 {
352 WARN(("windowDimensionsSync failed rc %d", rc));
353 return rc;
354 }
355
356 return VINF_SUCCESS;
357}
358
359
360int CrFbDisplayWindow::windowSetCompositor(bool fSet)
361{
362 if (!mpWindow)
363 return VINF_SUCCESS;
364
365 if (fSet)
366 {
367 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(getFramebuffer());
368 return mpWindow->SetCompositor(pCompositor);
369 }
370 return mpWindow->SetCompositor(NULL);
371}
372
373
374int CrFbDisplayWindow::windowCleanup()
375{
376 if (!mpWindow)
377 return VINF_SUCCESS;
378
379 int rc = mpWindow->UpdateBegin();
380 if (!RT_SUCCESS(rc))
381 {
382 WARN(("err"));
383 return rc;
384 }
385
386 rc = windowDimensionsSync(true);
387 if (!RT_SUCCESS(rc))
388 {
389 WARN(("err"));
390 mpWindow->UpdateEnd();
391 return rc;
392 }
393
394 rc = windowSetCompositor(false);
395 if (!RT_SUCCESS(rc))
396 {
397 WARN(("err"));
398 mpWindow->UpdateEnd();
399 return rc;
400 }
401
402 mpWindow->UpdateEnd();
403
404 return VINF_SUCCESS;
405}
406
407
408int CrFbDisplayWindow::fbCleanup()
409{
410 int rc = windowCleanup();
411 if (!RT_SUCCESS(rc))
412 {
413 WARN(("windowCleanup failed"));
414 return rc;
415 }
416 return CrFbDisplayBase::fbCleanup();
417}
418
419
420bool CrFbDisplayWindow::isActive()
421{
422 HCR_FRAMEBUFFER hFb = getFramebuffer();
423 return hFb && CrFbIsEnabled(hFb);
424}
425
426
427int CrFbDisplayWindow::windowDimensionsSync(bool fForceCleanup)
428{
429 int rc = VINF_SUCCESS;
430
431 if (!mpWindow)
432 return VINF_SUCCESS;
433
434 //HCR_FRAMEBUFFER hFb = getFramebuffer();
435 if (!fForceCleanup && isActive())
436 {
437 const RTRECT* pRect = getRect();
438
439 if (mpWindow->GetParentId() != mParentId)
440 {
441 rc = mpWindow->Reparent(mParentId);
442 if (!RT_SUCCESS(rc))
443 {
444 WARN(("err"));
445 return rc;
446 }
447 }
448
449 rc = mpWindow->SetPosition(pRect->xLeft - mViewportRect.xLeft, pRect->yTop - mViewportRect.yTop);
450 if (!RT_SUCCESS(rc))
451 {
452 WARN(("err"));
453 return rc;
454 }
455
456 setRegionsChanged();
457
458 rc = mpWindow->SetSize((uint32_t)(pRect->xRight - pRect->xLeft), (uint32_t)(pRect->yBottom - pRect->yTop));
459 if (!RT_SUCCESS(rc))
460 {
461 WARN(("err"));
462 return rc;
463 }
464
465 rc = mpWindow->SetVisible(!g_CrPresenter.fWindowsForceHidden);
466 if (!RT_SUCCESS(rc))
467 {
468 WARN(("err"));
469 return rc;
470 }
471 }
472 else
473 {
474 rc = mpWindow->SetVisible(false);
475 if (!RT_SUCCESS(rc))
476 {
477 WARN(("err"));
478 return rc;
479 }
480#if 0
481 rc = mpWindow->Reparent(mDefaultParentId);
482 if (!RT_SUCCESS(rc))
483 {
484 WARN(("err"));
485 return rc;
486 }
487#endif
488 }
489
490 return rc;
491}
492
493
494int CrFbDisplayWindow::windowSync()
495{
496 if (!mpWindow)
497 return VINF_SUCCESS;
498
499 int rc = mpWindow->UpdateBegin();
500 if (!RT_SUCCESS(rc))
501 {
502 WARN(("err"));
503 return rc;
504 }
505
506 rc = windowSetCompositor(true);
507 if (!RT_SUCCESS(rc))
508 {
509 WARN(("err"));
510 mpWindow->UpdateEnd();
511 return rc;
512 }
513
514 rc = windowDimensionsSync();
515 if (!RT_SUCCESS(rc))
516 {
517 WARN(("err"));
518 mpWindow->UpdateEnd();
519 return rc;
520 }
521
522 mpWindow->UpdateEnd();
523
524 return rc;
525}
526
527
528int CrFbDisplayWindow::fbSync()
529{
530 int rc = CrFbDisplayBase::fbSync();
531 if (!RT_SUCCESS(rc))
532 {
533 WARN(("err"));
534 return rc;
535 }
536
537 HCR_FRAMEBUFFER hFb = getFramebuffer();
538
539 mu32Screen = CrFbGetScreenInfo(hFb)->u32ViewIndex;
540
541 rc = windowSync();
542 if (!RT_SUCCESS(rc))
543 {
544 WARN(("windowSync failed %d", rc));
545 return rc;
546 }
547
548 if (CrFbHas3DData(hFb))
549 {
550 if (mpWindow && mpWindow->GetParentId())
551 {
552 rc = mpWindow->Create();
553 if (!RT_SUCCESS(rc))
554 {
555 WARN(("err"));
556 return rc;
557 }
558 }
559 }
560
561 return VINF_SUCCESS;
562}
563
564
565const struct RTRECT* CrFbDisplayWindow::getRect()
566{
567 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(getFramebuffer());
568 return CrVrScrCompositorRectGet(pCompositor);
569}
570
Note: See TracBrowser for help on using the repository browser.

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