VirtualBox

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

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

Host 3D: Chromium server: Presentation framework: drop unused code.

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