VirtualBox

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

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

Host 3D: Chromium server: Presentation framework: move classes into separate files for better code reading (to be continued).

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