VirtualBox

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

Last change on this file since 53814 was 53262, checked in by vboxsync, 11 years ago

Revert r96781, r96707 and r96693 since these commits affect 3D overlay window badly on Windows host.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.3 KB
Line 
1/* $Id: display_window.cpp 53262 2014-11-07 13:06:25Z 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.215389.xyz. 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, VBOX3D_NOTIFY_EVENT_TYPE_VISIBLE_3DDATA, &fVisible, sizeof(fVisible));
325 mFlags.fNeVisible = fVisible;
326 mFlags.fNeForce = 0;
327 }
328}
329
330
331void CrFbDisplayWindow::ueRegions()
332{
333 if (mpWindow)
334 mpWindow->SetVisibleRegionsChanged();
335}
336
337
338int CrFbDisplayWindow::screenChanged()
339{
340 if (!isUpdating())
341 {
342 WARN(("not updating!"));
343 return VERR_INVALID_STATE;
344 }
345
346 int rc = windowDimensionsSync();
347 if (!RT_SUCCESS(rc))
348 {
349 WARN(("windowDimensionsSync failed rc %d", rc));
350 return rc;
351 }
352
353 return VINF_SUCCESS;
354}
355
356
357int CrFbDisplayWindow::windowSetCompositor(bool fSet)
358{
359 if (!mpWindow)
360 return VINF_SUCCESS;
361
362 if (fSet)
363 {
364 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(getFramebuffer());
365 return mpWindow->SetCompositor(pCompositor);
366 }
367 return mpWindow->SetCompositor(NULL);
368}
369
370
371int CrFbDisplayWindow::windowCleanup()
372{
373 if (!mpWindow)
374 return VINF_SUCCESS;
375
376 int rc = mpWindow->UpdateBegin();
377 if (!RT_SUCCESS(rc))
378 {
379 WARN(("err"));
380 return rc;
381 }
382
383 rc = windowDimensionsSync(true);
384 if (!RT_SUCCESS(rc))
385 {
386 WARN(("err"));
387 mpWindow->UpdateEnd();
388 return rc;
389 }
390
391 rc = windowSetCompositor(false);
392 if (!RT_SUCCESS(rc))
393 {
394 WARN(("err"));
395 mpWindow->UpdateEnd();
396 return rc;
397 }
398
399 mpWindow->UpdateEnd();
400
401 return VINF_SUCCESS;
402}
403
404
405int CrFbDisplayWindow::fbCleanup()
406{
407 int rc = windowCleanup();
408 if (!RT_SUCCESS(rc))
409 {
410 WARN(("windowCleanup failed"));
411 return rc;
412 }
413 return CrFbDisplayBase::fbCleanup();
414}
415
416
417bool CrFbDisplayWindow::isActive()
418{
419 HCR_FRAMEBUFFER hFb = getFramebuffer();
420 return hFb && CrFbIsEnabled(hFb);
421}
422
423
424int CrFbDisplayWindow::windowDimensionsSync(bool fForceCleanup)
425{
426 int rc = VINF_SUCCESS;
427
428 if (!mpWindow)
429 return VINF_SUCCESS;
430
431 //HCR_FRAMEBUFFER hFb = getFramebuffer();
432 if (!fForceCleanup && isActive())
433 {
434 const RTRECT* pRect = getRect();
435
436 if (mpWindow->GetParentId() != mParentId)
437 {
438 rc = mpWindow->Reparent(mParentId);
439 if (!RT_SUCCESS(rc))
440 {
441 WARN(("err"));
442 return rc;
443 }
444 }
445
446 rc = mpWindow->SetPosition(pRect->xLeft - mViewportRect.xLeft, pRect->yTop - mViewportRect.yTop);
447 if (!RT_SUCCESS(rc))
448 {
449 WARN(("err"));
450 return rc;
451 }
452
453 setRegionsChanged();
454
455 rc = mpWindow->SetSize((uint32_t)(pRect->xRight - pRect->xLeft), (uint32_t)(pRect->yBottom - pRect->yTop));
456 if (!RT_SUCCESS(rc))
457 {
458 WARN(("err"));
459 return rc;
460 }
461
462 rc = mpWindow->SetVisible(!g_CrPresenter.fWindowsForceHidden);
463 if (!RT_SUCCESS(rc))
464 {
465 WARN(("err"));
466 return rc;
467 }
468 }
469 else
470 {
471 rc = mpWindow->SetVisible(false);
472 if (!RT_SUCCESS(rc))
473 {
474 WARN(("err"));
475 return rc;
476 }
477#if 0
478 rc = mpWindow->Reparent(mDefaultParentId);
479 if (!RT_SUCCESS(rc))
480 {
481 WARN(("err"));
482 return rc;
483 }
484#endif
485 }
486
487 return rc;
488}
489
490
491int CrFbDisplayWindow::windowSync()
492{
493 if (!mpWindow)
494 return VINF_SUCCESS;
495
496 int rc = mpWindow->UpdateBegin();
497 if (!RT_SUCCESS(rc))
498 {
499 WARN(("err"));
500 return rc;
501 }
502
503 rc = windowSetCompositor(true);
504 if (!RT_SUCCESS(rc))
505 {
506 WARN(("err"));
507 mpWindow->UpdateEnd();
508 return rc;
509 }
510
511 rc = windowDimensionsSync();
512 if (!RT_SUCCESS(rc))
513 {
514 WARN(("err"));
515 mpWindow->UpdateEnd();
516 return rc;
517 }
518
519 mpWindow->UpdateEnd();
520
521 return rc;
522}
523
524
525int CrFbDisplayWindow::fbSync()
526{
527 int rc = CrFbDisplayBase::fbSync();
528 if (!RT_SUCCESS(rc))
529 {
530 WARN(("err"));
531 return rc;
532 }
533
534 HCR_FRAMEBUFFER hFb = getFramebuffer();
535
536 mu32Screen = CrFbGetScreenInfo(hFb)->u32ViewIndex;
537
538 rc = windowSync();
539 if (!RT_SUCCESS(rc))
540 {
541 WARN(("windowSync failed %d", rc));
542 return rc;
543 }
544
545 if (CrFbHas3DData(hFb))
546 {
547 if (mpWindow && mpWindow->GetParentId())
548 {
549 rc = mpWindow->Create();
550 if (!RT_SUCCESS(rc))
551 {
552 WARN(("err"));
553 return rc;
554 }
555 }
556 }
557
558 return VINF_SUCCESS;
559}
560
561
562const struct RTRECT* CrFbDisplayWindow::getRect()
563{
564 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(getFramebuffer());
565 return CrVrScrCompositorRectGet(pCompositor);
566}
567
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