Changeset 53601 in vbox for trunk/src/VBox/GuestHost/OpenGL/util/blitter.cpp
- Timestamp:
- Dec 22, 2014 12:13:45 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/OpenGL/util/blitter.cpp
r51524 r53601 1 1 /* $Id$ */ 2 3 2 /** @file 4 3 * Blitter API implementation 5 4 */ 5 6 6 /* 7 * Copyright (C) 2013 Oracle Corporation7 * Copyright (C) 2013-2014 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 #include "cr_blitter.h" 18 #include "cr_spu.h" 19 #include "chromium.h" 20 #include "cr_error.h" 21 #include "cr_net.h" 22 #include "cr_rand.h" 23 #include "cr_mem.h" 24 #include "cr_string.h" 25 #include "cr_bmpscale.h" 17 18 19 /******************************************************************************* 20 * Header Files * 21 *******************************************************************************/ 22 #ifdef IN_VMSVGA3D 23 # include <OpenGL/OpenGL.h> 24 # include "../include/cr_blitter.h" 25 # include <iprt/assert.h> 26 # define WARN AssertMsgFailed 27 # define CRASSERT Assert 28 DECLINLINE(void) crWarning(const char *format, ... ) {} 29 #else 30 # include "cr_blitter.h" 31 # include "cr_spu.h" 32 # include "chromium.h" 33 # include "cr_error.h" 34 # include "cr_net.h" 35 # include "cr_rand.h" 36 # include "cr_mem.h" 37 # include "cr_string.h" 38 # include "cr_bmpscale.h" 39 #endif 26 40 27 41 #include <iprt/cdefs.h> 28 42 #include <iprt/types.h> 29 43 #include <iprt/mem.h> 44 45 30 46 31 47 static void crMClrFillMem(uint32_t *pu32Dst, int32_t cbDstPitch, uint32_t width, uint32_t height, uint32_t u32Color) … … 145 161 } 146 162 163 #ifndef IN_VMSVGA3D 164 147 165 void CrMBltImgRectScaled(const CR_BLITTER_IMG *pSrc, const RTPOINT *pPos, bool fSrcInvert, const RTRECT *pCopyRect, float strX, float strY, CR_BLITTER_IMG *pDst) 148 166 { … … 259 277 } 260 278 261 /* @param pCtxBase - contains the blitter context info. Its value is treated differently depending on the fCreateNewCtx value 262 * @param fCreateNewCtx - if true - the pCtxBase must NOT be NULL. its visualBits is used as a visual bits info for the new context, 263 * its id field is used to specified the shared context id to be used for blitter context. 264 * The id can be null to specify no shared context is needed 265 * if false - if pCtxBase is NOT null AND its id field is NOT null - 266 * specified the blitter context to be used 267 * blitter treats it as if it has default ogl state. 268 * otherwise - 269 * the blitter works in a "no-context" mode, i.e. a caller is responsible 270 * to making a proper context current before calling the blitter. 271 * Note that BltEnter/Leave MUST still be called, but the proper context 272 * must be set before doing BltEnter, and ResoreContext info is ignored in that case. 273 * Also note that blitter caches the current window info, and assumes the current context's values are preserved 274 * wrt that window before the calls, so if one uses different contexts for one blitter, 275 * the blitter current window values must be explicitly reset by doing CrBltMuralSetCurrentInfo(pBlitter, NULL) 276 * @param fForceDrawBlt - if true - forces the blitter to always use glDrawXxx-based blits even if GL_EXT_framebuffer_blit. 277 * This is needed because BlitFramebufferEXT is known to be often buggy, and glDrawXxx-based blits appear to be more reliable 279 #endif /* !IN_VMSVGA3D */ 280 281 282 /** 283 * 284 * @param pBlitter The blitter to initialize. 285 * @param pCtxBase Contains the blitter context info. Its value is 286 * treated differently depending on the fCreateNewCtx 287 * value. 288 * @param fCreateNewCtx If true, then @a pCtxBase must NOT be NULL. Its 289 * visualBits is used as a visual bits info for the new 290 * context, its id field is used to specified the 291 * shared context id to be used for blitter context. 292 * The id can be null to specify no shared context is 293 * needed 294 * 295 * If false and @a pCtxBase is NOT null AND its id 296 * field is NOT null, then specified the blitter 297 * context to be used blitter treats it as if it has 298 * default ogl state. 299 * 300 * Otherwise, the blitter works in a "no-context" mode, 301 * i.e. the§ caller is responsible for making a proper 302 * context current before calling the blitter. Note 303 * that BltEnter/Leave MUST still be called, but the 304 * proper context must be set before doing BltEnter, 305 * and ResoreContext info is ignored in that case. Also 306 * note that the blitter caches the current window 307 * info, and assumes the current context's values are 308 * preserved wrt that window before the calls, so if 309 * one uses different contexts for one blitter, the 310 * blitter current window values must be explicitly 311 * reset by doing CrBltMuralSetCurrentInfo(pBlitter, 312 * NULL). 313 * @param fForceDrawBlt If true this forces the blitter to always use 314 * glDrawXxx-based blits even if 315 * GL_EXT_framebuffer_blit. This is needed because 316 * BlitFramebufferEXT is often known to be buggy, and 317 * glDrawXxx-based blits appear to be more reliable. 318 * @param pShaders 319 * @param pDispatch 278 320 */ 279 VBOXBLITTERDECL(int) CrBltInit(PCR_BLITTER pBlitter, const CR_BLITTER_CONTEXT *pCtxBase, bool fCreateNewCtx, bool fForceDrawBlt, const CR_GLSL_CACHE *pShaders, SPUDispatchTable *pDispatch) 321 VBOXBLITTERDECL(int) CrBltInit(PCR_BLITTER pBlitter, const CR_BLITTER_CONTEXT *pCtxBase, 322 bool fCreateNewCtx, bool fForceDrawBlt, const CR_GLSL_CACHE *pShaders, 323 SPUDispatchTable *pDispatch) 280 324 { 281 325 if (pCtxBase && pCtxBase->Base.id < 0) … … 291 335 } 292 336 293 memset(pBlitter, 0, sizeof (*pBlitter));337 RT_ZERO(*pBlitter); 294 338 295 339 pBlitter->pDispatch = pDispatch; … … 301 345 if (fCreateNewCtx) 302 346 { 347 #ifdef IN_VMSVGA3D 348 /** @todo IN_VMSVGA3D */ 349 pBlitter->CtxInfo.Base.id = 0; 350 #else 303 351 pBlitter->CtxInfo.Base.id = pDispatch->CreateContext("", pCtxBase->Base.visualBits, pCtxBase->Base.id); 352 #endif 304 353 if (!pBlitter->CtxInfo.Base.id) 305 354 { 306 memset(pBlitter, 0, sizeof (*pBlitter));355 RT_ZERO(*pBlitter); 307 356 crWarning("CreateContext failed!"); 308 357 return VERR_GENERAL_FAILURE; … … 352 401 void CrBltTerm(PCR_BLITTER pBlitter) 353 402 { 403 #ifdef IN_VMSVGA3D 404 /** @todo IN_VMSVGA3D */ 405 #else 354 406 if (pBlitter->Flags.CtxCreated) 355 407 pBlitter->pDispatch->DestroyContext(pBlitter->CtxInfo.Base.id); 408 #endif 356 409 memset(pBlitter, 0, sizeof (*pBlitter)); 357 410 } … … 381 434 if (!CrBltIsEntered(pBlitter)) 382 435 return VINF_SUCCESS; 383 else if (!pBlitter->CtxInfo.Base.id) 436 437 if (!pBlitter->CtxInfo.Base.id) 384 438 { 385 439 WARN(("setting current mural for entered no-context blitter")); … … 389 443 WARN(("changing mural for entered blitter, is is somewhat expected?")); 390 444 445 #ifdef IN_VMSVGA3D 446 /** @todo IN_VMSVGA3D */ 447 #else 391 448 pBlitter->pDispatch->Flush(); 392 449 393 450 pBlitter->pDispatch->MakeCurrent(pMural->Base.id, pBlitter->i32MakeCurrentUserData, pBlitter->CtxInfo.Base.id); 394 395 return VINF_SUCCESS; 396 } 451 #endif 452 453 return VINF_SUCCESS; 454 } 455 456 457 #ifndef IN_VMSVGA3D 397 458 398 459 static DECLCALLBACK(int) crBltBlitTexBufImplFbo(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const RTRECTSIZE *pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags) … … 598 659 } 599 660 600 static void *crBltBufGet(PCR_BLITTER_BUFFER pBuffer, GLuint cbBuffer)661 static void *crBltBufGet(PCR_BLITTER_BUFFER pBuffer, GLuint cbBuffer) 601 662 { 602 663 if (pBuffer->cbBuffer < cbBuffer) … … 624 685 } 625 686 687 #endif /* !IN_VMSVGA3D */ 688 689 626 690 static void crBltCheckSetupViewport(PCR_BLITTER pBlitter, const RTRECTSIZE *pDstSize, bool fFBODraw) 627 691 { 628 692 bool fUpdateViewport = pBlitter->Flags.CurrentMuralChanged; 629 if ( pBlitter->CurrentSetSize.cx != pDstSize->cx630 693 if ( pBlitter->CurrentSetSize.cx != pDstSize->cx 694 || pBlitter->CurrentSetSize.cy != pDstSize->cy) 631 695 { 632 696 pBlitter->CurrentSetSize = *pDstSize; 697 #ifdef IN_VMSVGA3D 698 /** @todo IN_VMSVGA3D */ 699 #else 633 700 pBlitter->pDispatch->MatrixMode(GL_PROJECTION); 634 701 pBlitter->pDispatch->LoadIdentity(); 635 702 pBlitter->pDispatch->Ortho(0, pDstSize->cx, 0, pDstSize->cy, -1, 1); 703 #endif 636 704 fUpdateViewport = true; 637 705 } … … 639 707 if (fUpdateViewport) 640 708 { 709 #ifdef IN_VMSVGA3D 710 /** @todo IN_VMSVGA3D */ 711 #else 641 712 pBlitter->pDispatch->Viewport(0, 0, pBlitter->CurrentSetSize.cx, pBlitter->CurrentSetSize.cy); 713 #endif 642 714 pBlitter->Flags.CurrentMuralChanged = 0; 643 715 } … … 645 717 pBlitter->Flags.LastWasFBODraw = fFBODraw; 646 718 } 719 720 721 #ifndef IN_VMSVGA3D 647 722 648 723 static DECLCALLBACK(int) crBltBlitTexBufImplDraw2D(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRect, const RTRECTSIZE *pDstSize, const RTRECT *paDstRect, uint32_t cRects, uint32_t fFlags) … … 777 852 } 778 853 854 #endif /* !IN_VMSVGA3D */ 855 856 779 857 void CrBltLeave(PCR_BLITTER pBlitter) 780 858 { … … 788 866 return; 789 867 868 #ifdef IN_VMSVGA3D 869 /** @todo IN_VMSVGA3D */ 870 #else 790 871 if (pBlitter->Flags.SupportsFBO) 791 872 { … … 799 880 if (pBlitter->CtxInfo.Base.id) 800 881 pBlitter->pDispatch->MakeCurrent(0, 0, 0); 882 #endif 801 883 } 802 884 … … 814 896 if (pBlitter->CurrentMural.Base.id) /* <- pBlitter->CurrentMural.Base.id can be null if the blitter is in a "no-context" mode (see comments to BltInit for detail)*/ 815 897 { 898 #ifdef IN_VMSVGA3D 899 /** @todo IN_VMSVGA3D */ 900 #else 816 901 pBlitter->pDispatch->MakeCurrent(pBlitter->CurrentMural.Base.id, pBlitter->i32MakeCurrentUserData, pBlitter->CtxInfo.Base.id); 902 #endif 817 903 } 818 904 … … 820 906 return VINF_SUCCESS; 821 907 908 #ifdef IN_VMSVGA3D 909 /** @todo IN_VMSVGA3D */ 910 int rc = VINF_SUCCESS; 911 #else 822 912 int rc = crBltInitOnMakeCurent(pBlitter); 913 #endif 823 914 if (RT_SUCCESS(rc)) 824 915 { … … 832 923 } 833 924 925 834 926 static void crBltBlitTexBuf(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *paSrcRects, GLenum enmDstBuff, const RTRECTSIZE *pDstSize, const RTRECT *paDstRects, uint32_t cRects, uint32_t fFlags) 835 927 { 928 #ifdef IN_VMSVGA3D 929 /** @todo IN_VMSVGA3D */ 930 #else 836 931 pBlitter->pDispatch->DrawBuffer(enmDstBuff); 837 932 … … 842 937 else 843 938 { 844 int rc = pBlitter->Flags.ShadersGloal ? 845 CrGlslProgUseNoAlpha(pBlitter->pGlslCache, pSrc->target) 846 : 847 CrGlslProgUseGenNoAlpha(&pBlitter->LocalGlslCache, pSrc->target); 939 int rc = pBlitter->Flags.ShadersGloal 940 ? CrGlslProgUseNoAlpha(pBlitter->pGlslCache, pSrc->target) 941 : CrGlslProgUseGenNoAlpha(&pBlitter->LocalGlslCache, pSrc->target); 848 942 849 943 if (!RT_SUCCESS(rc)) … … 862 956 CrGlslProgClear(pBlitter->pGlslCache); 863 957 } 958 #endif 864 959 } 865 960 … … 880 975 RTRECTSIZE DstSize = {pBlitter->CurrentMural.width, pBlitter->CurrentMural.height}; 881 976 977 #ifdef IN_VMSVGA3D 978 /** @todo IN_VMSVGA3D */ 979 #else 882 980 pBlitter->pDispatch->BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0); 981 #endif 883 982 884 983 crBltBlitTexBuf(pBlitter, pSrc, paSrcRects, fBb ? GL_BACK : GL_FRONT, &DstSize, paDstRects, cRects, fFlags); 885 984 } 985 986 987 #ifndef IN_VMSVGA3D 886 988 887 989 void CrBltBlitTexTex(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *pSrcRect, const VBOXVR_TEXTURE *pDst, const RTRECT *pDstRect, uint32_t cRects, uint32_t fFlags) … … 1322 1424 } 1323 1425 1426 #endif /* !IN_VMSVGA3D */ 1427 1324 1428 VBOXBLITTERDECL(bool) CrGlslNeedsCleanup(const CR_GLSL_CACHE *pCache) 1325 1429 { … … 1331 1435 if (pCache->uNoAlpha2DProg) 1332 1436 { 1437 #ifdef IN_VMSVGA3D 1438 /** @todo IN_VMSVGA3D */ 1439 #else 1333 1440 pCache->pDispatch->DeleteProgram(pCache->uNoAlpha2DProg); 1441 #endif 1334 1442 pCache->uNoAlpha2DProg = 0; 1335 1443 } … … 1337 1445 if (pCache->uNoAlpha2DRectProg) 1338 1446 { 1447 #ifdef IN_VMSVGA3D 1448 /** @todo IN_VMSVGA3D */ 1449 #else 1339 1450 pCache->pDispatch->DeleteProgram(pCache->uNoAlpha2DRectProg); 1451 #endif 1340 1452 pCache->uNoAlpha2DRectProg = 0; 1341 1453 } … … 1352 1464 } 1353 1465 1466 #ifndef IN_VMSVGA3D 1354 1467 1355 1468 /*TdBlt*/ … … 1418 1531 } 1419 1532 1533 #endif /* !IN_VMSVGA3D */ 1534 1535 1420 1536 void crTdBltImgRelease(PCR_TEXDATA pTex) 1421 1537 { … … 1441 1557 1442 1558 Assert(CrBltIsEntered(pBlitter)); 1559 #ifdef IN_VMSVGA3D 1560 /** @todo IN_VMSVGA3D */ 1561 #else 1443 1562 pBlitter->pDispatch->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pTex->idPBO); 1444 1563 pBlitter->pDispatch->UnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB); 1445 1564 pBlitter->pDispatch->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); 1565 #endif 1446 1566 } 1447 1567 else … … 1453 1573 pTex->Img.pvData = NULL; 1454 1574 } 1575 1576 1577 #ifndef IN_VMSVGA3D 1455 1578 1456 1579 int crTdBltImgAcquire(PCR_TEXDATA pTex, GLenum enmFormat, bool fInverted) … … 1521 1644 } 1522 1645 1646 #endif /* !IN_VMSVGA3D */ 1647 1648 1523 1649 /* release the texture data, the data remains cached in the CR_TEXDATA object until it is discarded with CrTdBltDataInvalidateNe or CrTdBltDataCleanup */ 1524 1650 VBOXBLITTERDECL(int) CrTdBltDataRelease(PCR_TEXDATA pTex) … … 1620 1746 { 1621 1747 Assert(CrBltIsEntered(pBlitter)); 1748 #ifdef IN_VMSVGA3D 1749 /** @todo IN_VMSVGA3D */ 1750 #else 1622 1751 pBlitter->pDispatch->DeleteBuffersARB(1, &pTex->idPBO); 1752 #endif 1623 1753 pTex->idPBO = 0; 1624 1754 } … … 1627 1757 { 1628 1758 Assert(CrBltIsEntered(pBlitter)); 1759 #ifdef IN_VMSVGA3D 1760 /** @todo IN_VMSVGA3D */ 1761 #else 1629 1762 pBlitter->pDispatch->DeleteTextures(1, &pTex->idInvertTex); 1763 #endif 1630 1764 pTex->idInvertTex = 0; 1631 1765 } … … 1670 1804 return VINF_SUCCESS; 1671 1805 } 1806 1807 1808 #ifndef IN_VMSVGA3D 1672 1809 1673 1810 /* acquire the texture data, returns the cached data in case it is cached. … … 1981 2118 pTex->pScaledCache = NULL; 1982 2119 } 2120 2121 #endif /* !IN_VMSVGA3D */ 2122
Note:
See TracChangeset
for help on using the changeset viewer.