VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/presenter/display_vrdp.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: 9.8 KB
Line 
1/* $Id: display_vrdp.cpp 53145 2014-10-26 16:13:36Z vboxsync $ */
2
3/** @file
4 * Presenter API: display window root 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
21
22CrFbDisplayVrdp::CrFbDisplayVrdp()
23{
24 memset(&mPos, 0, sizeof (mPos));
25}
26
27
28int CrFbDisplayVrdp::EntryCreated(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
29{
30 int rc = CrFbDisplayBase::EntryCreated(pFb, hEntry);
31 if (!RT_SUCCESS(rc))
32 {
33 WARN(("EntryAdded failed rc %d", rc));
34 return rc;
35 }
36
37 Assert(!CrFbDDataEntryGet(hEntry, slotGet()));
38 rc = vrdpCreate(pFb, hEntry);
39 if (!RT_SUCCESS(rc))
40 {
41 WARN(("vrdpCreate failed rc %d", rc));
42 return rc;
43 }
44
45 return VINF_SUCCESS;
46}
47
48
49int CrFbDisplayVrdp::EntryReplaced(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hNewEntry, HCR_FRAMEBUFFER_ENTRY hReplacedEntry)
50{
51 int rc = CrFbDisplayBase::EntryReplaced(pFb, hNewEntry, hReplacedEntry);
52 if (!RT_SUCCESS(rc))
53 {
54 WARN(("err"));
55 return rc;
56 }
57
58 const VBOXVR_SCR_COMPOSITOR_ENTRY* pReplacedEntry = CrFbEntryGetCompositorEntry(hReplacedEntry);
59 CR_TEXDATA *pReplacedTex = CrVrScrCompositorEntryTexGet(pReplacedEntry);
60 const VBOXVR_SCR_COMPOSITOR_ENTRY* pNewEntry = CrFbEntryGetCompositorEntry(hNewEntry);
61 CR_TEXDATA *pNewTex = CrVrScrCompositorEntryTexGet(pNewEntry);
62
63 CrTdBltDataInvalidateNe(pReplacedTex);
64
65 rc = CrTdBltEnter(pNewTex);
66 if (RT_SUCCESS(rc))
67 {
68 rc = vrdpFrame(hNewEntry);
69 CrTdBltLeave(pNewTex);
70 }
71 else
72 WARN(("CrTdBltEnter failed %d", rc));
73
74 return rc;
75}
76
77
78int CrFbDisplayVrdp::EntryTexChanged(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
79{
80 int rc = CrFbDisplayBase::EntryTexChanged(pFb, hEntry);
81 if (!RT_SUCCESS(rc))
82 {
83 WARN(("err"));
84 return rc;
85 }
86
87 const VBOXVR_SCR_COMPOSITOR_ENTRY* pEntry = CrFbEntryGetCompositorEntry(hEntry);
88 CR_TEXDATA *pTex = CrVrScrCompositorEntryTexGet(pEntry);
89
90 rc = CrTdBltEnter(pTex);
91 if (RT_SUCCESS(rc))
92 {
93 rc = vrdpFrame(hEntry);
94 CrTdBltLeave(pTex);
95 }
96 else
97 WARN(("CrTdBltEnter failed %d", rc));
98
99 return rc;
100}
101
102
103int CrFbDisplayVrdp::EntryRemoved(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
104{
105 int rc = CrFbDisplayBase::EntryRemoved(pFb, hEntry);
106 if (!RT_SUCCESS(rc))
107 {
108 WARN(("err"));
109 return rc;
110 }
111
112 const VBOXVR_SCR_COMPOSITOR_ENTRY* pEntry = CrFbEntryGetCompositorEntry(hEntry);
113 CR_TEXDATA *pTex = CrVrScrCompositorEntryTexGet(pEntry);
114 CrTdBltDataInvalidateNe(pTex);
115
116 return vrdpRegions(pFb, hEntry);
117}
118
119
120int CrFbDisplayVrdp::EntryDestroyed(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
121{
122 int rc = CrFbDisplayBase::EntryDestroyed(pFb, hEntry);
123 if (!RT_SUCCESS(rc))
124 {
125 WARN(("err"));
126 return rc;
127 }
128
129 vrdpDestroy(hEntry);
130 return VINF_SUCCESS;
131}
132
133
134int CrFbDisplayVrdp::EntryPosChanged(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
135{
136 int rc = CrFbDisplayBase::EntryPosChanged(pFb, hEntry);
137 if (!RT_SUCCESS(rc))
138 {
139 WARN(("err"));
140 return rc;
141 }
142
143 vrdpGeometry(hEntry);
144
145 return VINF_SUCCESS;
146}
147
148
149int CrFbDisplayVrdp::RegionsChanged(struct CR_FRAMEBUFFER *pFb)
150{
151 int rc = CrFbDisplayBase::RegionsChanged(pFb);
152 if (!RT_SUCCESS(rc))
153 {
154 WARN(("err"));
155 return rc;
156 }
157
158 return vrdpRegionsAll(pFb);
159}
160
161
162int CrFbDisplayVrdp::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 syncPos();
172
173 rc = vrdpSyncEntryAll(pFb);
174 if (!RT_SUCCESS(rc))
175 {
176 WARN(("err"));
177 return rc;
178 }
179
180 return vrdpRegionsAll(pFb);
181}
182
183
184void CrFbDisplayVrdp::syncPos()
185{
186 const struct VBVAINFOSCREEN* pScreenInfo = CrFbGetScreenInfo(getFramebuffer());
187 mPos.x = pScreenInfo->i32OriginX;
188 mPos.y = pScreenInfo->i32OriginY;
189}
190
191int CrFbDisplayVrdp::fbCleanup()
192{
193 int rc = fbCleanupRemoveAllEntries();
194 if (!RT_SUCCESS(rc))
195 {
196 WARN(("err"));
197 return rc;
198 }
199
200 return CrFbDisplayBase::fbCleanup();
201}
202
203
204int CrFbDisplayVrdp::fbSync()
205{
206 syncPos();
207
208 int rc = fbSynchAddAllEntries();
209 if (!RT_SUCCESS(rc))
210 {
211 WARN(("err"));
212 return rc;
213 }
214
215 return CrFbDisplayBase::fbSync();
216}
217
218
219void CrFbDisplayVrdp::vrdpDestroy(HCR_FRAMEBUFFER_ENTRY hEntry)
220{
221 void *pVrdp = CrFbDDataEntryGet(hEntry, slotGet());
222 cr_server.outputRedirect.CROREnd(pVrdp);
223}
224
225
226void CrFbDisplayVrdp::vrdpGeometry(HCR_FRAMEBUFFER_ENTRY hEntry)
227{
228 void *pVrdp = CrFbDDataEntryGet(hEntry, slotGet());
229 const VBOXVR_SCR_COMPOSITOR_ENTRY* pEntry = CrFbEntryGetCompositorEntry(hEntry);
230
231 cr_server.outputRedirect.CRORGeometry(
232 pVrdp,
233 mPos.x + CrVrScrCompositorEntryRectGet(pEntry)->xLeft,
234 mPos.y + CrVrScrCompositorEntryRectGet(pEntry)->yTop,
235 CrVrScrCompositorEntryTexGet(pEntry)->Tex.width,
236 CrVrScrCompositorEntryTexGet(pEntry)->Tex.height);
237}
238
239
240int CrFbDisplayVrdp::vrdpRegions(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
241{
242 void *pVrdp = CrFbDDataEntryGet(hEntry, slotGet());
243 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(pFb);
244 const VBOXVR_SCR_COMPOSITOR_ENTRY* pEntry = CrFbEntryGetCompositorEntry(hEntry);
245 uint32_t cRects;
246 const RTRECT *pRects;
247
248 int rc = CrVrScrCompositorEntryRegionsGet(pCompositor, pEntry, &cRects, &pRects, NULL, NULL);
249 if (!RT_SUCCESS(rc))
250 {
251 WARN(("CrVrScrCompositorEntryRegionsGet failed, rc %d", rc));
252 return rc;
253 }
254
255 cr_server.outputRedirect.CRORVisibleRegion(pVrdp, cRects, pRects);
256 return VINF_SUCCESS;
257}
258
259
260int CrFbDisplayVrdp::vrdpFrame(HCR_FRAMEBUFFER_ENTRY hEntry)
261{
262 void *pVrdp = CrFbDDataEntryGet(hEntry, slotGet());
263 const VBOXVR_SCR_COMPOSITOR_ENTRY* pEntry = CrFbEntryGetCompositorEntry(hEntry);
264 CR_TEXDATA *pTex = CrVrScrCompositorEntryTexGet(pEntry);
265 const CR_BLITTER_IMG *pImg;
266 CrTdBltDataInvalidateNe(pTex);
267
268 int rc = CrTdBltDataAcquire(pTex, GL_BGRA, !!(CrVrScrCompositorEntryFlagsGet(pEntry) & CRBLT_F_INVERT_SRC_YCOORDS), &pImg);
269 if (!RT_SUCCESS(rc))
270 {
271 WARN(("CrTdBltDataAcquire failed rc %d", rc));
272 return rc;
273 }
274
275 cr_server.outputRedirect.CRORFrame(pVrdp, pImg->pvData, pImg->cbData);
276 CrTdBltDataRelease(pTex);
277 return VINF_SUCCESS;
278}
279
280
281int CrFbDisplayVrdp::vrdpRegionsAll(struct CR_FRAMEBUFFER *pFb)
282{
283 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(pFb);
284 VBOXVR_SCR_COMPOSITOR_CONST_ITERATOR Iter;
285 CrVrScrCompositorConstIterInit(pCompositor, &Iter);
286 const VBOXVR_SCR_COMPOSITOR_ENTRY *pEntry;
287 while ((pEntry = CrVrScrCompositorConstIterNext(&Iter)) != NULL)
288 {
289 HCR_FRAMEBUFFER_ENTRY hEntry = CrFbEntryFromCompositorEntry(pEntry);
290 vrdpRegions(pFb, hEntry);
291 }
292
293 return VINF_SUCCESS;
294}
295
296
297int CrFbDisplayVrdp::vrdpSynchEntry(struct CR_FRAMEBUFFER *pFb, HCR_FRAMEBUFFER_ENTRY hEntry)
298{
299 vrdpGeometry(hEntry);
300
301 return vrdpRegions(pFb, hEntry);;
302}
303
304
305int CrFbDisplayVrdp::vrdpSyncEntryAll(struct CR_FRAMEBUFFER *pFb)
306{
307 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(pFb);
308 VBOXVR_SCR_COMPOSITOR_CONST_ITERATOR Iter;
309 CrVrScrCompositorConstIterInit(pCompositor, &Iter);
310 const VBOXVR_SCR_COMPOSITOR_ENTRY *pEntry;
311 while ((pEntry = CrVrScrCompositorConstIterNext(&Iter)) != NULL)
312 {
313 HCR_FRAMEBUFFER_ENTRY hEntry = CrFbEntryFromCompositorEntry(pEntry);
314 int rc = vrdpSynchEntry(pFb, hEntry);
315 if (!RT_SUCCESS(rc))
316 {
317 WARN(("vrdpSynchEntry failed rc %d", rc));
318 return rc;
319 }
320 }
321
322 return VINF_SUCCESS;
323}
324
325
326int CrFbDisplayVrdp::vrdpCreate(HCR_FRAMEBUFFER hFb, HCR_FRAMEBUFFER_ENTRY hEntry)
327{
328 void *pVrdp;
329
330 /* Query supported formats. */
331 uint32_t cbFormats = 4096;
332 char *pachFormats = (char *)crAlloc(cbFormats);
333
334 if (!pachFormats)
335 {
336 WARN(("crAlloc failed"));
337 return VERR_NO_MEMORY;
338 }
339
340 int rc = cr_server.outputRedirect.CRORContextProperty(cr_server.outputRedirect.pvContext,
341 0 /* H3DOR_PROP_FORMATS */, // @todo from a header
342 pachFormats, cbFormats, &cbFormats);
343 if (RT_SUCCESS(rc))
344 {
345 if (RTStrStr(pachFormats, "H3DOR_FMT_RGBA_TOPDOWN"))
346 {
347 cr_server.outputRedirect.CRORBegin(
348 cr_server.outputRedirect.pvContext,
349 &pVrdp,
350 "H3DOR_FMT_RGBA_TOPDOWN"); // @todo from a header
351
352 if (pVrdp)
353 {
354 rc = CrFbDDataEntryPut(hEntry, slotGet(), pVrdp);
355 if (RT_SUCCESS(rc))
356 {
357 vrdpGeometry(hEntry);
358 vrdpRegions(hFb, hEntry);
359 //vrdpFrame(hEntry);
360 return VINF_SUCCESS;
361 }
362 else
363 WARN(("CrFbDDataEntryPut failed rc %d", rc));
364
365 cr_server.outputRedirect.CROREnd(pVrdp);
366 }
367 else
368 {
369 WARN(("CRORBegin failed"));
370 rc = VERR_GENERAL_FAILURE;
371 }
372 }
373 }
374 else
375 WARN(("CRORContextProperty failed rc %d", rc));
376
377 crFree(pachFormats);
378
379 return rc;
380}
381
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