VirtualBox

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

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

Host 3D: Chromium server: drop non-functional code.

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