VirtualBox

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

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

Host 3D: Presentation framework: do not re-create 3D window on framebuffer sync (restored behavior prior to r96693); create 3D window on CrFbWindow class instance creation.

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