VirtualBox

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

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

crOpenGL: bugfixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.7 KB
Line 
1/* $Id: server_muralfbo.cpp 50149 2014-01-21 18:18:36Z 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 int rc;
198 Tex.width = mural->width;
199 Tex.height = mural->height;
200 Tex.hwid = mural->aidColorTexs[i];
201 Tex.target = GL_TEXTURE_2D;
202
203 pData->apTexDatas[i] = CrFbTexDataCreate(&Tex);
204 }
205
206 rc = CrFbEntryCreateForTexData(hFb, pData->apTexDatas[CR_SERVER_FBO_FB_IDX(mural)], 0, &pData->hFbEntry);
207 if (!RT_SUCCESS(rc))
208 {
209 WARN(("CrFbEntryCreateForTexData failed rc %d", rc));
210 }
211 }
212 else
213 {
214 CRASSERT(pData->hFb == hFb);
215 }
216
217 rc = CrFbUpdateBegin(hFb);
218 if (!RT_SUCCESS(rc))
219 {
220 WARN(("CrFbUpdateBegin failed rc %d", rc));
221 return rc;
222 }
223
224 rc = CrFbEntryRegionsSet(hFb, pData->hFbEntry, &Pos, cRegions, pRegions, true);
225 if (!RT_SUCCESS(rc))
226 {
227 WARN(("CrFbEntryRegionsSet failed rc %d", rc));
228 }
229
230 CrFbUpdateEnd(hFb);
231
232 const struct VBOXVR_SCR_COMPOSITOR_ENTRY* pCEntry = CrFbEntryGetCompositorEntry(pData->hFbEntry);
233 if (CrVrScrCompositorEntryIsUsed(pCEntry))
234 *ppData = pData;
235
236 return rc;
237}
238
239static void crServerRedirMuralFbSync(CRMuralInfo *mural)
240{
241 uint32_t i;
242 uint32_t cUsedFBs = 0;
243 HCR_FRAMEBUFFER ahUsedFbs[CR_MAX_GUEST_MONITORS];
244 HCR_FRAMEBUFFER hFb;
245
246 for (i = 0; i < mural->cUsedFBDatas; ++i)
247 {
248 CR_FBDATA *pData = mural->apUsedFBDatas[i];
249 int rc = CrFbUpdateBegin(pData->hFb);
250 if (RT_SUCCESS(rc))
251 {
252 ahUsedFbs[cUsedFBs] = pData->hFb;
253 CrFbEntryRegionsSet(pData->hFb, pData->hFbEntry, NULL, 0, NULL, false);
254 ++cUsedFBs;
255 }
256 else
257 WARN(("CrFbUpdateBegin failed rc %d", rc));
258 }
259 mural->cUsedFBDatas = 0;
260
261 if (!mural->width
262 || !mural->height
263 || !mural->bVisible
264 )
265 goto end;
266
267 CRASSERT(mural->fRedirected);
268
269 for (hFb = CrPMgrFbGetFirstEnabled();
270 hFb;
271 hFb = CrPMgrFbGetNextEnabled(hFb))
272 {
273 CR_FBDATA *pData = NULL;
274 int rc = crServerRedirMuralDbSyncFb(mural, hFb, &pData);
275 if (!RT_SUCCESS(rc))
276 {
277 WARN(("crServerRedirMuralDbSyncFb failed %d", rc));
278 continue;
279 }
280
281 if (!pData)
282 continue;
283
284 mural->apUsedFBDatas[mural->cUsedFBDatas] = pData;
285 ++mural->cUsedFBDatas;
286 }
287
288end:
289
290 for (i = 0; i < cUsedFBs; ++i)
291 {
292 CrFbUpdateEnd(ahUsedFbs[i]);
293 }
294}
295
296static void crVBoxServerMuralFbCleanCB(unsigned long key, void *data1, void *data2)
297{
298 CRMuralInfo *pMI = (CRMuralInfo*) data1;
299 HCR_FRAMEBUFFER hFb = (HCR_FRAMEBUFFER)data2;
300 uint32_t i;
301 for (i = 0; i < pMI->cUsedFBDatas; ++i)
302 {
303 CR_FBDATA *pData = pMI->apUsedFBDatas[i];
304 if (hFb != pData->hFb)
305 continue;
306
307 CrFbEntryRegionsSet(pData->hFb, pData->hFbEntry, NULL, 0, NULL, false);
308 break;
309 }
310}
311
312static void crVBoxServerMuralFbSetCB(unsigned long key, void *data1, void *data2)
313{
314 CRMuralInfo *pMI = (CRMuralInfo*) data1;
315 HCR_FRAMEBUFFER hFb = (HCR_FRAMEBUFFER)data2;
316 uint32_t i;
317 CR_FBDATA *pData = NULL;
318 bool fFbWasUsed = false;
319
320 Assert(hFb);
321
322 if (!pMI->fRedirected)
323 {
324 Assert(!pMI->cUsedFBDatas);
325 return;
326 }
327
328 for (i = 0; i < pMI->cUsedFBDatas; ++i)
329 {
330 CR_FBDATA *pData = pMI->apUsedFBDatas[i];
331 if (hFb != pData->hFb)
332 continue;
333
334 fFbWasUsed = true;
335 break;
336 }
337
338 if (CrFbIsEnabled(hFb))
339 {
340 int rc = crServerRedirMuralDbSyncFb(pMI, hFb, &pData);
341 if (!RT_SUCCESS(rc))
342 {
343 WARN(("crServerRedirMuralDbSyncFb failed %d", rc));
344 pData = NULL;
345 }
346 }
347
348 if (pData)
349 {
350 if (!fFbWasUsed)
351 {
352 uint32_t idScreen = CrFbGetScreenInfo(hFb)->u32ViewIndex;
353 for (i = 0; i < pMI->cUsedFBDatas; ++i)
354 {
355 CR_FBDATA *pData = pMI->apUsedFBDatas[i];
356 uint32_t idCurScreen = CrFbGetScreenInfo(pData->hFb)->u32ViewIndex;
357 if (idCurScreen > idScreen)
358 break;
359
360 Assert(idCurScreen != idScreen);
361 }
362
363 for (int j = pMI->cUsedFBDatas; j > i; --j)
364 {
365 pMI->apUsedFBDatas[j] = pMI->apUsedFBDatas[j-1];
366 }
367
368 pMI->apUsedFBDatas[i] = pData;
369 ++pMI->cUsedFBDatas;
370 }
371 /* else - nothing to do */
372 }
373 else
374 {
375 if (fFbWasUsed)
376 {
377 for (int j = i; j < pMI->cUsedFBDatas - 1; ++j)
378 {
379 pMI->apUsedFBDatas[j] = pMI->apUsedFBDatas[j+1];
380 }
381 --pMI->cUsedFBDatas;
382 }
383 /* else - nothing to do */
384 }
385}
386
387void crVBoxServerMuralFbResizeEnd(HCR_FRAMEBUFFER hFb)
388{
389 crHashtableWalk(cr_server.muralTable, crVBoxServerMuralFbSetCB, hFb);
390}
391
392void crVBoxServerMuralFbResizeBegin(HCR_FRAMEBUFFER hFb)
393{
394 crHashtableWalk(cr_server.muralTable, crVBoxServerMuralFbCleanCB, hFb);
395}
396
397
398static int crVBoxServerResizeScreen(const struct VBVAINFOSCREEN *pScreen, void *pvVRAM)
399{
400 int rc;
401 HCR_FRAMEBUFFER hFb = CrPMgrFbGet(pScreen->u32ViewIndex);
402 if (!hFb)
403 {
404 WARN(("CrPMgrFbGet failed"));
405 return VERR_INVALID_PARAMETER;
406 }
407
408 rc = CrFbUpdateBegin(hFb);
409 if (!RT_SUCCESS(rc))
410 {
411 WARN(("CrFbUpdateBegin failed %d", rc));
412 return rc;
413 }
414
415 crVBoxServerMuralFbResizeBegin(hFb);
416
417 rc = CrFbResize(hFb, pScreen, pvVRAM);
418 if (!RT_SUCCESS(rc))
419 {
420 WARN(("CrFbResize failed %d", rc));
421 }
422
423 crVBoxServerMuralFbResizeEnd(hFb);
424
425 CrFbUpdateEnd(hFb);
426
427 CrPMgrNotifyResize(hFb);
428
429 return rc;
430}
431
432DECLEXPORT(int) crVBoxServerNotifyResize(uint32_t idScreen)
433{
434 struct VBVAINFOSCREEN Screen;
435 void *pvVRAM;
436
437 int rc = cr_server.CltInfo.pfnDmGet(cr_server.CltInfo.hClient, idScreen, &Screen, &pvVRAM);
438 if (!RT_SUCCESS(rc))
439 {
440 WARN(("err"));
441 return rc;
442 }
443
444 rc = crVBoxServerResizeScreen(&Screen, pvVRAM);
445 if (!RT_SUCCESS(rc))
446 {
447 WARN(("err"));
448 return rc;
449 }
450
451 return VINF_SUCCESS;
452}
453
454void crServerRedirMuralFBO(CRMuralInfo *mural, bool fEnabled)
455{
456 if (!mural->fRedirected == !fEnabled)
457 {
458 return;
459 }
460
461 if (!mural->CreateInfo.externalID)
462 {
463 WARN(("trying to change redir setting for internal mural %d", mural->spuWindow));
464 return;
465 }
466
467 if (fEnabled)
468 {
469 if (!crServerSupportRedirMuralFBO())
470 {
471 WARN(("FBO not supported, can't redirect window output"));
472 return;
473 }
474
475 if (mural->aidFBOs[0]==0)
476 {
477 crServerCreateMuralFBO(mural);
478 }
479
480 if (cr_server.curClient && cr_server.curClient->currentMural == mural)
481 {
482 if (!crStateGetCurrent()->framebufferobject.drawFB)
483 {
484 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, mural->iCurDrawBuffer));
485 }
486 if (!crStateGetCurrent()->framebufferobject.readFB)
487 {
488 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, mural->iCurReadBuffer));
489 }
490
491 crStateGetCurrent()->buffer.width = 0;
492 crStateGetCurrent()->buffer.height = 0;
493 }
494 }
495 else
496 {
497 if (cr_server.curClient && cr_server.curClient->currentMural == mural)
498 {
499 if (!crStateGetCurrent()->framebufferobject.drawFB)
500 {
501 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
502 }
503 if (!crStateGetCurrent()->framebufferobject.readFB)
504 {
505 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, 0);
506 }
507
508 crStateGetCurrent()->buffer.width = mural->width;
509 crStateGetCurrent()->buffer.height = mural->height;
510 }
511 }
512
513 mural->fRedirected = !!fEnabled;
514}
515
516static void crServerCreateMuralFBO(CRMuralInfo *mural)
517{
518 CRContext *ctx = crStateGetCurrent();
519 GLuint uid, i;
520 GLenum status;
521 SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
522 CRContextInfo *pMuralContextInfo;
523
524 CRASSERT(mural->aidFBOs[0]==0);
525 CRASSERT(mural->aidFBOs[1]==0);
526
527 pMuralContextInfo = cr_server.currentCtxInfo;
528 if (!pMuralContextInfo)
529 {
530 /* happens on saved state load */
531 CRASSERT(cr_server.MainContextInfo.SpuContext);
532 pMuralContextInfo = &cr_server.MainContextInfo;
533 cr_server.head_spu->dispatch_table.MakeCurrent(mural->spuWindow, 0, cr_server.MainContextInfo.SpuContext);
534 }
535
536 if (pMuralContextInfo->CreateInfo.visualBits != mural->CreateInfo.visualBits)
537 {
538 WARN(("mural visual bits do not match with current context visual bits!"));
539 }
540
541 mural->cBuffers = 2;
542 mural->iBbBuffer = 0;
543 /*Color texture*/
544
545 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
546 {
547 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
548 }
549
550 for (i = 0; i < mural->cBuffers; ++i)
551 {
552 gl->GenTextures(1, &mural->aidColorTexs[i]);
553 gl->BindTexture(GL_TEXTURE_2D, mural->aidColorTexs[i]);
554 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
555 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
556 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
557 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
558 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mural->width, mural->height,
559 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
560 }
561
562 /*Depth&Stencil*/
563 gl->GenRenderbuffersEXT(1, &mural->idDepthStencilRB);
564 gl->BindRenderbufferEXT(GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
565 gl->RenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT,
566 mural->width, mural->height);
567
568 /*FBO*/
569 for (i = 0; i < mural->cBuffers; ++i)
570 {
571 gl->GenFramebuffersEXT(1, &mural->aidFBOs[i]);
572 gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mural->aidFBOs[i]);
573
574 gl->FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
575 GL_TEXTURE_2D, mural->aidColorTexs[i], 0);
576 gl->FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
577 GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
578 gl->FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
579 GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
580
581 status = gl->CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
582 if (status!=GL_FRAMEBUFFER_COMPLETE_EXT)
583 {
584 WARN(("FBO status(0x%x) isn't complete", status));
585 }
586 }
587
588 mural->iCurDrawBuffer = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.drawBuffer);
589 mural->iCurReadBuffer = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.readBuffer);
590
591 mural->fboWidth = mural->width;
592 mural->fboHeight = mural->height;
593
594 mural->iCurDrawBuffer = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.drawBuffer);
595 mural->iCurReadBuffer = crServerMuralFBOIdxFromBufferName(mural, ctx->buffer.readBuffer);
596
597 /*Restore gl state*/
598 uid = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->hwid;
599 gl->BindTexture(GL_TEXTURE_2D, uid);
600
601 uid = ctx->framebufferobject.renderbuffer ? ctx->framebufferobject.renderbuffer->hwid:0;
602 gl->BindRenderbufferEXT(GL_RENDERBUFFER_EXT, uid);
603
604 uid = ctx->framebufferobject.drawFB ? ctx->framebufferobject.drawFB->hwid:0;
605 gl->BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, uid);
606
607 uid = ctx->framebufferobject.readFB ? ctx->framebufferobject.readFB->hwid:0;
608 gl->BindFramebufferEXT(GL_READ_FRAMEBUFFER, uid);
609
610 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
611 {
612 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, ctx->bufferobject.unpackBuffer->hwid);
613 }
614
615 if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
616 {
617 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
618 }
619 else
620 {
621 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
622 }
623
624 CRASSERT(mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)]);
625}
626
627void crServerDeleteMuralFBO(CRMuralInfo *mural)
628{
629 if (mural->aidFBOs[0]!=0)
630 {
631 GLuint i;
632 for (i = 0; i < mural->cBuffers; ++i)
633 {
634 cr_server.head_spu->dispatch_table.DeleteTextures(1, &mural->aidColorTexs[i]);
635 mural->aidColorTexs[i] = 0;
636 }
637
638 cr_server.head_spu->dispatch_table.DeleteRenderbuffersEXT(1, &mural->idDepthStencilRB);
639 mural->idDepthStencilRB = 0;
640
641 for (i = 0; i < mural->cBuffers; ++i)
642 {
643 cr_server.head_spu->dispatch_table.DeleteFramebuffersEXT(1, &mural->aidFBOs[i]);
644 mural->aidFBOs[i] = 0;
645 }
646 }
647
648 mural->cBuffers = 0;
649}
650
651#define MIN(a, b) ((a) < (b) ? (a) : (b))
652#define MAX(a, b) ((a) > (b) ? (a) : (b))
653
654static GLboolean crServerIntersectRect(CRrecti *a, CRrecti *b, CRrecti *rect)
655{
656 CRASSERT(a && b && rect);
657
658 rect->x1 = MAX(a->x1, b->x1);
659 rect->x2 = MIN(a->x2, b->x2);
660 rect->y1 = MAX(a->y1, b->y1);
661 rect->y2 = MIN(a->y2, b->y2);
662
663 return (rect->x2>rect->x1) && (rect->y2>rect->y1);
664}
665
666static void crServerCopySubImage(char *pDst, char* pSrc, CRrecti *pRect, int srcWidth, int srcHeight)
667{
668 int i;
669 int dstrowsize = 4*(pRect->x2-pRect->x1);
670 int srcrowsize = 4*srcWidth;
671 int height = pRect->y2-pRect->y1;
672
673 pSrc += 4*pRect->x1 + srcrowsize*(srcHeight-1-pRect->y1);
674
675 for (i=0; i<height; ++i)
676 {
677 crMemcpy(pDst, pSrc, dstrowsize);
678
679 pSrc -= srcrowsize;
680 pDst += dstrowsize;
681 }
682}
683
684DECLEXPORT(void) crServerVBoxCompositionSetEnableStateGlobal(GLboolean fEnable)
685{
686}
687
688void crServerPresentFBO(CRMuralInfo *mural)
689{
690 uint32_t i;
691 for (i = 0; i < mural->cUsedFBDatas; ++i)
692 {
693 CR_FBDATA *pData = mural->apUsedFBDatas[i];
694 int rc = CrFbUpdateBegin(pData->hFb);
695 if (RT_SUCCESS(rc))
696 {
697 CrFbEntryTexDataUpdate(pData->hFb, pData->hFbEntry, pData->apTexDatas[CR_SERVER_FBO_FB_IDX(mural)]);
698 CrFbUpdateEnd(pData->hFb);
699 }
700 else
701 WARN(("CrFbUpdateBegin failed rc %d", rc));
702 }
703}
704
705GLboolean crServerIsRedirectedToFBO()
706{
707#ifdef DEBUG_misha
708 Assert(cr_server.curClient);
709 if (cr_server.curClient)
710 {
711 Assert(cr_server.curClient->currentMural == cr_server.currentMural);
712 Assert(cr_server.curClient->currentCtxInfo == cr_server.currentCtxInfo);
713 }
714#endif
715 return cr_server.curClient
716 && cr_server.curClient->currentMural
717 && cr_server.curClient->currentMural->fRedirected;
718}
719
720GLint crServerMuralFBOIdxFromBufferName(CRMuralInfo *mural, GLenum buffer)
721{
722 switch (buffer)
723 {
724 case GL_FRONT:
725 case GL_FRONT_LEFT:
726 case GL_FRONT_RIGHT:
727 return CR_SERVER_FBO_FB_IDX(mural);
728 case GL_BACK:
729 case GL_BACK_LEFT:
730 case GL_BACK_RIGHT:
731 return CR_SERVER_FBO_BB_IDX(mural);
732 case GL_NONE:
733 case GL_AUX0:
734 case GL_AUX1:
735 case GL_AUX2:
736 case GL_AUX3:
737 case GL_LEFT:
738 case GL_RIGHT:
739 case GL_FRONT_AND_BACK:
740 return -1;
741 default:
742 WARN(("crServerMuralFBOIdxFromBufferName: invalid buffer passed 0x%x", buffer));
743 return -2;
744 }
745}
746
747void crServerMuralFBOSwapBuffers(CRMuralInfo *mural)
748{
749 CRContext *ctx = crStateGetCurrent();
750 GLuint iOldCurDrawBuffer = mural->iCurDrawBuffer;
751 GLuint iOldCurReadBuffer = mural->iCurReadBuffer;
752 mural->iBbBuffer = ((mural->iBbBuffer + 1) % (mural->cBuffers));
753 if (mural->iCurDrawBuffer >= 0)
754 mural->iCurDrawBuffer = ((mural->iCurDrawBuffer + 1) % (mural->cBuffers));
755 if (mural->iCurReadBuffer >= 0)
756 mural->iCurReadBuffer = ((mural->iCurReadBuffer + 1) % (mural->cBuffers));
757 Assert(iOldCurDrawBuffer != mural->iCurDrawBuffer || mural->cBuffers == 1 || mural->iCurDrawBuffer < 0);
758 Assert(iOldCurReadBuffer != mural->iCurReadBuffer || mural->cBuffers == 1 || mural->iCurReadBuffer < 0);
759 if (!ctx->framebufferobject.drawFB && iOldCurDrawBuffer != mural->iCurDrawBuffer)
760 {
761 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, mural->iCurDrawBuffer));
762 }
763 if (!ctx->framebufferobject.readFB && iOldCurReadBuffer != mural->iCurReadBuffer)
764 {
765 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, mural->iCurReadBuffer));
766 }
767 Assert(mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)]);
768}
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