VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_muralfbo.cpp@ 50625

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

crOpenGL: misc bugfixes and cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.9 KB
Line 
1/* $Id: server_muralfbo.cpp 50625 2014-02-27 10:34:19Z vboxsync $ */
2
3/** @file
4 * VBox crOpenGL: Window to FBO redirect support.
5 */
6
7/*
8 * Copyright (C) 2010-2013 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.h"
20#include "cr_string.h"
21#include "cr_mem.h"
22#include "cr_vreg.h"
23#include "render/renderspu.h"
24
25static void crServerRedirMuralFbSync(CRMuralInfo *mural);
26
27void crServerCheckMuralGeometry(CRMuralInfo *mural)
28{
29 if (!mural->CreateInfo.externalID)
30 return;
31
32 CRASSERT(mural->spuWindow);
33 CRASSERT(mural->spuWindow != CR_RENDER_DEFAULT_WINDOW_ID);
34
35 if (!mural->width || !mural->height
36 || mural->fboWidth != mural->width
37 || mural->fboHeight != mural->height)
38 {
39 crServerRedirMuralFbClear(mural);
40 crServerRedirMuralFBO(mural, false);
41 crServerDeleteMuralFBO(mural);
42 }
43
44 if (!mural->width || !mural->height)
45 return;
46
47 crServerRedirMuralFBO(mural, true);
48 crServerRedirMuralFbSync(mural);
49}
50
51static void crServerCheckMuralGeometryCB(unsigned long key, void *data1, void *data2)
52{
53 CRMuralInfo *pMI = (CRMuralInfo*) data1;
54
55 if (!pMI->fRedirected || pMI == data2)
56 return;
57
58 crServerCheckMuralGeometry(pMI);
59}
60
61
62void crServerCheckAllMuralGeometry(CRMuralInfo *pMI)
63{
64 CR_FBMAP Map;
65 int rc = CrPMgrHlpGlblUpdateBegin(&Map);
66 if (!RT_SUCCESS(rc))
67 {
68 WARN(("CrPMgrHlpGlblUpdateBegin failed %d", rc));
69 return;
70 }
71
72 crHashtableWalk(cr_server.muralTable, crServerCheckMuralGeometryCB, pMI);
73
74 if (pMI)
75 crServerCheckMuralGeometry(pMI);
76
77 CrPMgrHlpGlblUpdateEnd(&Map);
78}
79
80GLboolean crServerSupportRedirMuralFBO(void)
81{
82 static GLboolean fInited = GL_FALSE;
83 static GLboolean fSupported = GL_FALSE;
84 if (!fInited)
85 {
86 const GLubyte* pExt = cr_server.head_spu->dispatch_table.GetString(GL_REAL_EXTENSIONS);
87
88 fSupported = ( NULL!=crStrstr((const char*)pExt, "GL_ARB_framebuffer_object")
89 || NULL!=crStrstr((const char*)pExt, "GL_EXT_framebuffer_object"))
90 && NULL!=crStrstr((const char*)pExt, "GL_ARB_texture_non_power_of_two");
91 fInited = GL_TRUE;
92 }
93 return fSupported;
94}
95
96static void crServerCreateMuralFBO(CRMuralInfo *mural);
97
98void crServerRedirMuralFbClear(CRMuralInfo *mural)
99{
100 uint32_t i;
101 for (i = 0; i < mural->cUsedFBDatas; ++i)
102 {
103 CR_FBDATA *pData = mural->apUsedFBDatas[i];
104 int rc = CrFbUpdateBegin(pData->hFb);
105 if (RT_SUCCESS(rc))
106 {
107 CrFbEntryRegionsSet(pData->hFb, pData->hFbEntry, NULL, 0, NULL, false);
108 CrFbUpdateEnd(pData->hFb);
109 }
110 else
111 WARN(("CrFbUpdateBegin failed rc %d", rc));
112 }
113 mural->cUsedFBDatas = 0;
114
115 for (i = 0; i < cr_server.screenCount; ++i)
116 {
117 GLuint j;
118 CR_FBDATA *pData = &mural->aFBDatas[i];
119 if (!pData->hFb)
120 continue;
121
122 CrFbEntryRelease(pData->hFb, pData->hFbEntry);
123 pData->hFbEntry = NULL;
124
125 for (j = 0; j < mural->cBuffers; ++j)
126 {
127 CrTdRelease(pData->apTexDatas[j]);
128 pData->apTexDatas[j] = NULL;
129 }
130
131 pData->hFb = NULL;
132 }
133}
134
135static int crServerRedirMuralDbSyncFb(CRMuralInfo *mural, HCR_FRAMEBUFFER hFb, CR_FBDATA **ppData)
136{
137 CR_FBDATA *pData;
138 const struct VBVAINFOSCREEN* pScreenInfo = CrFbGetScreenInfo(hFb);
139 const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(hFb);
140 RTRECT FbRect = *CrVrScrCompositorRectGet(pCompositor);
141 RTRECT DefaultRegionsRect;
142 const RTRECT * pRegions;
143 uint32_t cRegions;
144 RTPOINT Pos;
145 RTRECT MuralRect;
146 int rc;
147
148 CRASSERT(mural->fRedirected);
149
150 *ppData = NULL;
151
152 if (!mural->bVisible)
153 return VINF_SUCCESS;
154
155 MuralRect.xLeft = mural->gX;
156 MuralRect.yTop = mural->gY;
157 MuralRect.xRight = MuralRect.xLeft + mural->width;
158 MuralRect.yBottom = MuralRect.yTop + mural->height;
159
160 Pos.x = mural->gX - pScreenInfo->i32OriginX;
161 Pos.y = mural->gY - pScreenInfo->i32OriginY;
162
163 VBoxRectTranslate(&FbRect, pScreenInfo->i32OriginX, pScreenInfo->i32OriginY);
164
165 VBoxRectIntersect(&FbRect, &MuralRect);
166
167 if (VBoxRectIsZero(&FbRect))
168 return VINF_SUCCESS;
169
170 if (mural->bReceivedRects)
171 {
172 pRegions = (const RTRECT*)mural->pVisibleRects;
173 cRegions = mural->cVisibleRects;
174 }
175 else
176 {
177 DefaultRegionsRect.xLeft = 0;
178 DefaultRegionsRect.yTop = 0;
179 DefaultRegionsRect.xRight = mural->width;
180 DefaultRegionsRect.yBottom = mural->height;
181 pRegions = &DefaultRegionsRect;
182 cRegions = 1;
183 }
184
185 if (!cRegions)
186 return VINF_SUCCESS;
187
188 pData = &mural->aFBDatas[pScreenInfo->u32ViewIndex];
189
190 if (!pData->hFb)
191 {
192 pData->hFb = hFb;
193
194 for (uint32_t i = 0; i < mural->cBuffers; ++i)
195 {
196 VBOXVR_TEXTURE Tex;
197 Tex.width = mural->width;
198 Tex.height = mural->height;
199 Tex.hwid = mural->aidColorTexs[i];
200 Tex.target = GL_TEXTURE_2D;
201
202 pData->apTexDatas[i] = CrFbTexDataCreate(&Tex);
203 }
204
205 rc = CrFbEntryCreateForTexData(hFb, pData->apTexDatas[CR_SERVER_FBO_FB_IDX(mural)], 0, &pData->hFbEntry);
206 if (!RT_SUCCESS(rc))
207 {
208 WARN(("CrFbEntryCreateForTexData failed rc %d", rc));
209 }
210 }
211 else
212 {
213 CRASSERT(pData->hFb == hFb);
214 }
215
216 rc = CrFbUpdateBegin(hFb);
217 if (!RT_SUCCESS(rc))
218 {
219 WARN(("CrFbUpdateBegin failed rc %d", rc));
220 return rc;
221 }
222
223 rc = CrFbEntryRegionsSet(hFb, pData->hFbEntry, &Pos, cRegions, pRegions, true);
224 if (!RT_SUCCESS(rc))
225 {
226 WARN(("CrFbEntryRegionsSet failed rc %d", rc));
227 }
228
229 CrFbUpdateEnd(hFb);
230
231 const struct VBOXVR_SCR_COMPOSITOR_ENTRY* pCEntry = CrFbEntryGetCompositorEntry(pData->hFbEntry);
232 if (CrVrScrCompositorEntryIsUsed(pCEntry))
233 *ppData = pData;
234
235 return rc;
236}
237
238static void crServerRedirMuralFbSync(CRMuralInfo *mural)
239{
240 uint32_t i;
241 uint32_t cUsedFBs = 0;
242 HCR_FRAMEBUFFER ahUsedFbs[CR_MAX_GUEST_MONITORS];
243 HCR_FRAMEBUFFER hFb;
244
245 for (i = 0; i < mural->cUsedFBDatas; ++i)
246 {
247 CR_FBDATA *pData = mural->apUsedFBDatas[i];
248 int rc = CrFbUpdateBegin(pData->hFb);
249 if (RT_SUCCESS(rc))
250 {
251 ahUsedFbs[cUsedFBs] = pData->hFb;
252 CrFbEntryRegionsSet(pData->hFb, pData->hFbEntry, NULL, 0, NULL, false);
253 ++cUsedFBs;
254 }
255 else
256 WARN(("CrFbUpdateBegin failed rc %d", rc));
257 }
258 mural->cUsedFBDatas = 0;
259
260 if (!mural->width
261 || !mural->height
262 || !mural->bVisible
263 )
264 goto end;
265
266 CRASSERT(mural->fRedirected);
267
268 for (hFb = CrPMgrFbGetFirstEnabled();
269 hFb;
270 hFb = CrPMgrFbGetNextEnabled(hFb))
271 {
272 CR_FBDATA *pData = NULL;
273 int rc = crServerRedirMuralDbSyncFb(mural, hFb, &pData);
274 if (!RT_SUCCESS(rc))
275 {
276 WARN(("crServerRedirMuralDbSyncFb failed %d", rc));
277 continue;
278 }
279
280 if (!pData)
281 continue;
282
283 mural->apUsedFBDatas[mural->cUsedFBDatas] = pData;
284 ++mural->cUsedFBDatas;
285 }
286
287end:
288
289 for (i = 0; i < cUsedFBs; ++i)
290 {
291 CrFbUpdateEnd(ahUsedFbs[i]);
292 }
293}
294
295static void crVBoxServerMuralFbCleanCB(unsigned long key, void *data1, void *data2)
296{
297 CRMuralInfo *pMI = (CRMuralInfo*) data1;
298 HCR_FRAMEBUFFER hFb = (HCR_FRAMEBUFFER)data2;
299 uint32_t i;
300 for (i = 0; i < pMI->cUsedFBDatas; ++i)
301 {
302 CR_FBDATA *pData = pMI->apUsedFBDatas[i];
303 if (hFb != pData->hFb)
304 continue;
305
306 CrFbEntryRegionsSet(pData->hFb, pData->hFbEntry, NULL, 0, NULL, false);
307 break;
308 }
309}
310
311static void crVBoxServerMuralFbSetCB(unsigned long key, void *data1, void *data2)
312{
313 CRMuralInfo *pMI = (CRMuralInfo*) data1;
314 HCR_FRAMEBUFFER hFb = (HCR_FRAMEBUFFER)data2;
315 uint32_t i;
316 CR_FBDATA *pData = NULL;
317 bool fFbWasUsed = false;
318
319 Assert(hFb);
320
321 if (!pMI->fRedirected)
322 {
323 Assert(!pMI->cUsedFBDatas);
324 return;
325 }
326
327 for (i = 0; i < pMI->cUsedFBDatas; ++i)
328 {
329 CR_FBDATA *pData = pMI->apUsedFBDatas[i];
330 if (hFb != pData->hFb)
331 continue;
332
333 fFbWasUsed = true;
334 break;
335 }
336
337 if (CrFbIsEnabled(hFb))
338 {
339 int rc = crServerRedirMuralDbSyncFb(pMI, hFb, &pData);
340 if (!RT_SUCCESS(rc))
341 {
342 WARN(("crServerRedirMuralDbSyncFb failed %d", rc));
343 pData = NULL;
344 }
345 }
346
347 if (pData)
348 {
349 if (!fFbWasUsed)
350 {
351 uint32_t idScreen = CrFbGetScreenInfo(hFb)->u32ViewIndex;
352 for (i = 0; i < pMI->cUsedFBDatas; ++i)
353 {
354 CR_FBDATA *pData = pMI->apUsedFBDatas[i];
355 uint32_t idCurScreen = CrFbGetScreenInfo(pData->hFb)->u32ViewIndex;
356 if (idCurScreen > idScreen)
357 break;
358
359 Assert(idCurScreen != idScreen);
360 }
361
362 for (int j = pMI->cUsedFBDatas; j > i; --j)
363 {
364 pMI->apUsedFBDatas[j] = pMI->apUsedFBDatas[j-1];
365 }
366
367 pMI->apUsedFBDatas[i] = pData;
368 ++pMI->cUsedFBDatas;
369 }
370 /* else - nothing to do */
371 }
372 else
373 {
374 if (fFbWasUsed)
375 {
376 for (int j = i; j < pMI->cUsedFBDatas - 1; ++j)
377 {
378 pMI->apUsedFBDatas[j] = pMI->apUsedFBDatas[j+1];
379 }
380 --pMI->cUsedFBDatas;
381 }
382 /* else - nothing to do */
383 }
384}
385
386void crVBoxServerMuralFbResizeEnd(HCR_FRAMEBUFFER hFb)
387{
388 crHashtableWalk(cr_server.muralTable, crVBoxServerMuralFbSetCB, hFb);
389}
390
391void crVBoxServerMuralFbResizeBegin(HCR_FRAMEBUFFER hFb)
392{
393 crHashtableWalk(cr_server.muralTable, crVBoxServerMuralFbCleanCB, hFb);
394}
395
396
397static int crVBoxServerResizeScreen(const struct VBVAINFOSCREEN *pScreen, void *pvVRAM)
398{
399 int rc;
400 HCR_FRAMEBUFFER hFb = CrPMgrFbGet(pScreen->u32ViewIndex);
401 if (!hFb)
402 {
403 WARN(("CrPMgrFbGet failed"));
404 return VERR_INVALID_PARAMETER;
405 }
406
407 rc = CrFbUpdateBegin(hFb);
408 if (!RT_SUCCESS(rc))
409 {
410 WARN(("CrFbUpdateBegin failed %d", rc));
411 return rc;
412 }
413
414 crVBoxServerMuralFbResizeBegin(hFb);
415
416 rc = CrFbResize(hFb, pScreen, pvVRAM);
417 if (!RT_SUCCESS(rc))
418 {
419 WARN(("CrFbResize failed %d", rc));
420 }
421
422 crVBoxServerMuralFbResizeEnd(hFb);
423
424 CrFbUpdateEnd(hFb);
425
426 CrPMgrNotifyResize(hFb);
427
428 return rc;
429}
430
431DECLEXPORT(int) crVBoxServerNotifyResize(const struct VBVAINFOSCREEN *pScreen, void *pvVRAM)
432{
433 int rc = crVBoxServerResizeScreen(pScreen, pvVRAM);
434 if (!RT_SUCCESS(rc))
435 {
436 WARN(("err"));
437 return rc;
438 }
439
440 return VINF_SUCCESS;
441}
442
443void crServerRedirMuralFBO(CRMuralInfo *mural, bool fEnabled)
444{
445 if (!mural->fRedirected == !fEnabled)
446 {
447 return;
448 }
449
450 if (!mural->CreateInfo.externalID)
451 {
452 WARN(("trying to change redir setting for internal mural %d", mural->spuWindow));
453 return;
454 }
455
456 if (fEnabled)
457 {
458 if (!crServerSupportRedirMuralFBO())
459 {
460 WARN(("FBO not supported, can't redirect window output"));
461 return;
462 }
463
464 if (mural->aidFBOs[0]==0)
465 {
466 crServerCreateMuralFBO(mural);
467 }
468
469 if (cr_server.curClient && cr_server.curClient->currentMural == mural)
470 {
471 if (!crStateGetCurrent()->framebufferobject.drawFB)
472 {
473 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, mural->iCurDrawBuffer));
474 }
475 if (!crStateGetCurrent()->framebufferobject.readFB)
476 {
477 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, mural->iCurReadBuffer));
478 }
479
480 crStateGetCurrent()->buffer.width = 0;
481 crStateGetCurrent()->buffer.height = 0;
482 }
483 }
484 else
485 {
486 if (cr_server.curClient && cr_server.curClient->currentMural == mural)
487 {
488 if (!crStateGetCurrent()->framebufferobject.drawFB)
489 {
490 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
491 }
492 if (!crStateGetCurrent()->framebufferobject.readFB)
493 {
494 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, 0);
495 }
496
497 crStateGetCurrent()->buffer.width = mural->width;
498 crStateGetCurrent()->buffer.height = mural->height;
499 }
500 }
501
502 mural->fRedirected = !!fEnabled;
503}
504
505static void crServerCreateMuralFBO(CRMuralInfo *mural)
506{
507 CRContext *ctx = crStateGetCurrent();
508 GLuint uid, i;
509 GLenum status;
510 SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
511 CRContextInfo *pMuralContextInfo;
512
513 CRASSERT(mural->aidFBOs[0]==0);
514 CRASSERT(mural->aidFBOs[1]==0);
515
516 pMuralContextInfo = cr_server.currentCtxInfo;
517 if (!pMuralContextInfo)
518 {
519 /* happens on saved state load */
520 CRASSERT(cr_server.MainContextInfo.SpuContext);
521 pMuralContextInfo = &cr_server.MainContextInfo;
522 cr_server.head_spu->dispatch_table.MakeCurrent(mural->spuWindow, 0, cr_server.MainContextInfo.SpuContext);
523 }
524
525 if (pMuralContextInfo->CreateInfo.realVisualBits != mural->CreateInfo.realVisualBits)
526 {
527 WARN(("mural visual bits do not match with current context visual bits!"));
528 }
529
530 mural->cBuffers = 2;
531 mural->iBbBuffer = 0;
532 /*Color texture*/
533
534 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
535 {
536 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
537 }
538
539 for (i = 0; i < mural->cBuffers; ++i)
540 {
541 gl->GenTextures(1, &mural->aidColorTexs[i]);
542 gl->BindTexture(GL_TEXTURE_2D, mural->aidColorTexs[i]);
543 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
544 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
545 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
546 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
547 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mural->width, mural->height,
548 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
549 }
550
551 /*Depth&Stencil*/
552 gl->GenRenderbuffersEXT(1, &mural->idDepthStencilRB);
553 gl->BindRenderbufferEXT(GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
554 gl->RenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT,
555 mural->width, mural->height);
556
557 /*FBO*/
558 for (i = 0; i < mural->cBuffers; ++i)
559 {
560 gl->GenFramebuffersEXT(1, &mural->aidFBOs[i]);
561 gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mural->aidFBOs[i]);
562
563 gl->FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
564 GL_TEXTURE_2D, mural->aidColorTexs[i], 0);
565 gl->FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
566 GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
567 gl->FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
568 GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
569
570 status = gl->CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
571 if (status!=GL_FRAMEBUFFER_COMPLETE_EXT)
572 {
573 WARN(("FBO status(0x%x) isn't complete", status));
574 }
575 }
576
577 mural->iCurDrawBuffer = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.drawBuffer);
578 mural->iCurReadBuffer = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.readBuffer);
579
580 mural->fboWidth = mural->width;
581 mural->fboHeight = mural->height;
582
583 mural->iCurDrawBuffer = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.drawBuffer);
584 mural->iCurReadBuffer = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.readBuffer);
585
586 /*Restore gl state*/
587 uid = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->hwid;
588 gl->BindTexture(GL_TEXTURE_2D, uid);
589
590 uid = ctx->framebufferobject.renderbuffer ? ctx->framebufferobject.renderbuffer->hwid:0;
591 gl->BindRenderbufferEXT(GL_RENDERBUFFER_EXT, uid);
592
593 uid = ctx->framebufferobject.drawFB ? ctx->framebufferobject.drawFB->hwid:0;
594 gl->BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, uid);
595
596 uid = ctx->framebufferobject.readFB ? ctx->framebufferobject.readFB->hwid:0;
597 gl->BindFramebufferEXT(GL_READ_FRAMEBUFFER, uid);
598
599 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
600 {
601 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, ctx->bufferobject.unpackBuffer->hwid);
602 }
603
604 if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
605 {
606 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
607 }
608 else
609 {
610 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
611 }
612
613 CRASSERT(mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)]);
614}
615
616void crServerDeleteMuralFBO(CRMuralInfo *mural)
617{
618 if (mural->aidFBOs[0]!=0)
619 {
620 GLuint i;
621 for (i = 0; i < mural->cBuffers; ++i)
622 {
623 cr_server.head_spu->dispatch_table.DeleteTextures(1, &mural->aidColorTexs[i]);
624 mural->aidColorTexs[i] = 0;
625 }
626
627 cr_server.head_spu->dispatch_table.DeleteRenderbuffersEXT(1, &mural->idDepthStencilRB);
628 mural->idDepthStencilRB = 0;
629
630 for (i = 0; i < mural->cBuffers; ++i)
631 {
632 cr_server.head_spu->dispatch_table.DeleteFramebuffersEXT(1, &mural->aidFBOs[i]);
633 mural->aidFBOs[i] = 0;
634 }
635 }
636
637 mural->cBuffers = 0;
638}
639
640#define MIN(a, b) ((a) < (b) ? (a) : (b))
641#define MAX(a, b) ((a) > (b) ? (a) : (b))
642
643static GLboolean crServerIntersectRect(CRrecti *a, CRrecti *b, CRrecti *rect)
644{
645 CRASSERT(a && b && rect);
646
647 rect->x1 = MAX(a->x1, b->x1);
648 rect->x2 = MIN(a->x2, b->x2);
649 rect->y1 = MAX(a->y1, b->y1);
650 rect->y2 = MIN(a->y2, b->y2);
651
652 return (rect->x2>rect->x1) && (rect->y2>rect->y1);
653}
654
655DECLEXPORT(void) crServerVBoxCompositionSetEnableStateGlobal(GLboolean fEnable)
656{
657}
658
659DECLEXPORT(void) crServerVBoxScreenshotRelease(CR_SCREENSHOT *pScreenshot)
660{
661 if (pScreenshot->fDataAllocated)
662 {
663 RTMemFree(pScreenshot->Img.pvData);
664 pScreenshot->fDataAllocated = 0;
665 }
666}
667
668DECLEXPORT(int) crServerVBoxScreenshotGet(uint32_t u32Screen, uint32_t width, uint32_t height, uint32_t pitch, void *pvBuffer, CR_SCREENSHOT *pScreenshot)
669{
670 HCR_FRAMEBUFFER hFb = CrPMgrFbGetEnabled(u32Screen);
671 if (!hFb)
672 return VERR_INVALID_STATE;
673
674 const VBVAINFOSCREEN *pScreen = CrFbGetScreenInfo(hFb);
675
676 if (!width)
677 width = pScreen->u32Width;
678 if (!height)
679 height = pScreen->u32Height;
680 if (!pitch)
681 pitch = pScreen->u32LineSize;
682
683 if (CrFbHas3DData(hFb)
684 || pScreen->u32Width != width
685 || pScreen->u32Height != height
686 || pScreen->u32LineSize != pitch
687 || pScreen->u16BitsPerPixel != 32)
688 {
689 RTRECT Rect;
690
691 pScreenshot->Img.cbData = pScreen->u32LineSize * pScreen->u32Height;
692 if (!pvBuffer)
693 {
694 pScreenshot->Img.pvData = RTMemAlloc(pScreenshot->Img.cbData);
695 if (!pScreenshot->Img.pvData)
696 {
697 WARN(("RTMemAlloc failed"));
698 return VERR_NO_MEMORY;
699 }
700 pScreenshot->fDataAllocated = 1;
701 }
702 else
703 {
704 pScreenshot->Img.pvData = pvBuffer;
705 pScreenshot->fDataAllocated = 0;
706 }
707
708 pScreenshot->Img.enmFormat = GL_BGRA;
709 pScreenshot->Img.width = width;
710 pScreenshot->Img.height = height;
711 pScreenshot->Img.bpp = 32;
712 pScreenshot->Img.pitch = pitch;
713 Rect.xLeft = 0;
714 Rect.yTop = 0;
715 Rect.xRight = pScreen->u32Width;
716 Rect.yBottom = pScreen->u32Height;
717 int rc = CrFbBltGetContents(hFb, &Rect, 1, &Rect, &pScreenshot->Img);
718 if (!RT_SUCCESS(rc))
719 {
720 WARN(("CrFbBltGetContents failed %d", rc));
721 crServerVBoxScreenshotRelease(pScreenshot);
722 return rc;
723 }
724 }
725 else
726 {
727 pScreenshot->Img.cbData = pScreen->u32LineSize * pScreen->u32Height;
728 if (!pvBuffer)
729 pScreenshot->Img.pvData = CrFbGetVRAM(hFb);
730 else
731 {
732 pScreenshot->Img.pvData = pvBuffer;
733 memcpy(pvBuffer, CrFbGetVRAM(hFb), pScreenshot->Img.cbData);
734 }
735 pScreenshot->Img.enmFormat = GL_BGRA;
736 pScreenshot->Img.width = pScreen->u32Width;
737 pScreenshot->Img.height = pScreen->u32Height;
738 pScreenshot->Img.bpp = pScreen->u16BitsPerPixel;
739 pScreenshot->Img.pitch = pScreen->u32LineSize;
740
741 pScreenshot->fDataAllocated = 0;
742 }
743
744 pScreenshot->u32Screen = u32Screen;
745
746 return VINF_SUCCESS;
747}
748
749extern DECLEXPORT(int) crServerVBoxWindowsShow(bool fShow)
750{
751 return CrPMgrModeWinVisible(fShow);
752}
753
754void crServerPresentFBO(CRMuralInfo *mural)
755{
756 uint32_t i;
757 for (i = 0; i < mural->cUsedFBDatas; ++i)
758 {
759 CR_FBDATA *pData = mural->apUsedFBDatas[i];
760 int rc = CrFbUpdateBegin(pData->hFb);
761 if (RT_SUCCESS(rc))
762 {
763 CrFbEntryTexDataUpdate(pData->hFb, pData->hFbEntry, pData->apTexDatas[CR_SERVER_FBO_FB_IDX(mural)]);
764 CrFbUpdateEnd(pData->hFb);
765 }
766 else
767 WARN(("CrFbUpdateBegin failed rc %d", rc));
768 }
769}
770
771GLboolean crServerIsRedirectedToFBO()
772{
773#ifdef DEBUG_misha
774 Assert(cr_server.curClient);
775 if (cr_server.curClient)
776 {
777 Assert(cr_server.curClient->currentMural == cr_server.currentMural);
778 Assert(cr_server.curClient->currentCtxInfo == cr_server.currentCtxInfo);
779 }
780#endif
781 return cr_server.curClient
782 && cr_server.curClient->currentMural
783 && cr_server.curClient->currentMural->fRedirected;
784}
785
786GLint crServerMuralFBOIdxFromBufferName(CRMuralInfo *mural, GLenum buffer)
787{
788 switch (buffer)
789 {
790 case GL_FRONT:
791 case GL_FRONT_LEFT:
792 case GL_FRONT_RIGHT:
793 return CR_SERVER_FBO_FB_IDX(mural);
794 case GL_BACK:
795 case GL_BACK_LEFT:
796 case GL_BACK_RIGHT:
797 return CR_SERVER_FBO_BB_IDX(mural);
798 case GL_NONE:
799 case GL_AUX0:
800 case GL_AUX1:
801 case GL_AUX2:
802 case GL_AUX3:
803 case GL_LEFT:
804 case GL_RIGHT:
805 case GL_FRONT_AND_BACK:
806 return -1;
807 default:
808 WARN(("crServerMuralFBOIdxFromBufferName: invalid buffer passed 0x%x", buffer));
809 return -2;
810 }
811}
812
813void crServerMuralFBOSwapBuffers(CRMuralInfo *mural)
814{
815 CRContext *ctx = crStateGetCurrent();
816 GLuint iOldCurDrawBuffer = mural->iCurDrawBuffer;
817 GLuint iOldCurReadBuffer = mural->iCurReadBuffer;
818 mural->iBbBuffer = ((mural->iBbBuffer + 1) % (mural->cBuffers));
819 if (mural->iCurDrawBuffer >= 0)
820 mural->iCurDrawBuffer = ((mural->iCurDrawBuffer + 1) % (mural->cBuffers));
821 if (mural->iCurReadBuffer >= 0)
822 mural->iCurReadBuffer = ((mural->iCurReadBuffer + 1) % (mural->cBuffers));
823 Assert(iOldCurDrawBuffer != mural->iCurDrawBuffer || mural->cBuffers == 1 || mural->iCurDrawBuffer < 0);
824 Assert(iOldCurReadBuffer != mural->iCurReadBuffer || mural->cBuffers == 1 || mural->iCurReadBuffer < 0);
825 if (!ctx->framebufferobject.drawFB && iOldCurDrawBuffer != mural->iCurDrawBuffer)
826 {
827 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, mural->iCurDrawBuffer));
828 }
829 if (!ctx->framebufferobject.readFB && iOldCurReadBuffer != mural->iCurReadBuffer)
830 {
831 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, mural->iCurReadBuffer));
832 }
833 Assert(mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)]);
834}
835
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