VirtualBox

Ignore:
Timestamp:
Dec 22, 2014 12:13:45 PM (10 years ago)
Author:
vboxsync
Message:

Preps for replacing DevVGA-SVGA3d-cocoa.m with renderspu_cocoa_helper.m, i.e. sharing the objective-C OpenGL wrappers between the two 3D solutions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/util/blitter.cpp

    r51524 r53601  
    11/* $Id$ */
    2 
    32/** @file
    43 * Blitter API implementation
    54 */
     5
    66/*
    7  * Copyright (C) 2013 Oracle Corporation
     7 * Copyright (C) 2013-2014 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1515 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
    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
     28DECLINLINE(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
    2640
    2741#include <iprt/cdefs.h>
    2842#include <iprt/types.h>
    2943#include <iprt/mem.h>
     44
     45
    3046
    3147static void crMClrFillMem(uint32_t *pu32Dst, int32_t cbDstPitch, uint32_t width, uint32_t height, uint32_t u32Color)
     
    145161}
    146162
     163#ifndef IN_VMSVGA3D
     164
    147165void CrMBltImgRectScaled(const CR_BLITTER_IMG *pSrc, const RTPOINT *pPos, bool fSrcInvert, const RTRECT *pCopyRect, float strX, float strY, CR_BLITTER_IMG *pDst)
    148166{
     
    259277}
    260278
    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
    278320 */
    279 VBOXBLITTERDECL(int) CrBltInit(PCR_BLITTER pBlitter, const CR_BLITTER_CONTEXT *pCtxBase, bool fCreateNewCtx, bool fForceDrawBlt, const CR_GLSL_CACHE *pShaders, SPUDispatchTable *pDispatch)
     321VBOXBLITTERDECL(int) CrBltInit(PCR_BLITTER pBlitter, const CR_BLITTER_CONTEXT *pCtxBase,
     322                               bool fCreateNewCtx, bool fForceDrawBlt, const CR_GLSL_CACHE *pShaders,
     323                               SPUDispatchTable *pDispatch)
    280324{
    281325    if (pCtxBase && pCtxBase->Base.id < 0)
     
    291335    }
    292336
    293     memset(pBlitter, 0, sizeof (*pBlitter));
     337    RT_ZERO(*pBlitter);
    294338
    295339    pBlitter->pDispatch = pDispatch;
     
    301345    if (fCreateNewCtx)
    302346    {
     347#ifdef IN_VMSVGA3D
     348        /** @todo IN_VMSVGA3D */
     349        pBlitter->CtxInfo.Base.id = 0;
     350#else
    303351        pBlitter->CtxInfo.Base.id = pDispatch->CreateContext("", pCtxBase->Base.visualBits, pCtxBase->Base.id);
     352#endif
    304353        if (!pBlitter->CtxInfo.Base.id)
    305354        {
    306             memset(pBlitter, 0, sizeof (*pBlitter));
     355            RT_ZERO(*pBlitter);
    307356            crWarning("CreateContext failed!");
    308357            return VERR_GENERAL_FAILURE;
     
    352401void CrBltTerm(PCR_BLITTER pBlitter)
    353402{
     403#ifdef IN_VMSVGA3D
     404    /** @todo IN_VMSVGA3D */
     405#else
    354406    if (pBlitter->Flags.CtxCreated)
    355407        pBlitter->pDispatch->DestroyContext(pBlitter->CtxInfo.Base.id);
     408#endif
    356409    memset(pBlitter, 0, sizeof (*pBlitter));
    357410}
     
    381434    if (!CrBltIsEntered(pBlitter))
    382435        return VINF_SUCCESS;
    383     else if (!pBlitter->CtxInfo.Base.id)
     436
     437    if (!pBlitter->CtxInfo.Base.id)
    384438    {
    385439        WARN(("setting current mural for entered no-context blitter"));
     
    389443    WARN(("changing mural for entered blitter, is is somewhat expected?"));
    390444
     445#ifdef IN_VMSVGA3D
     446    /** @todo IN_VMSVGA3D */
     447#else
    391448    pBlitter->pDispatch->Flush();
    392449
    393450    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
    397458
    398459static 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)
     
    598659}
    599660
    600 static void* crBltBufGet(PCR_BLITTER_BUFFER pBuffer, GLuint cbBuffer)
     661static void *crBltBufGet(PCR_BLITTER_BUFFER pBuffer, GLuint cbBuffer)
    601662{
    602663    if (pBuffer->cbBuffer < cbBuffer)
     
    624685}
    625686
     687#endif /* !IN_VMSVGA3D */
     688
     689
    626690static void crBltCheckSetupViewport(PCR_BLITTER pBlitter, const RTRECTSIZE *pDstSize, bool fFBODraw)
    627691{
    628692    bool fUpdateViewport = pBlitter->Flags.CurrentMuralChanged;
    629     if (pBlitter->CurrentSetSize.cx != pDstSize->cx
    630             || pBlitter->CurrentSetSize.cy != pDstSize->cy)
     693    if (   pBlitter->CurrentSetSize.cx != pDstSize->cx
     694        || pBlitter->CurrentSetSize.cy != pDstSize->cy)
    631695    {
    632696        pBlitter->CurrentSetSize = *pDstSize;
     697#ifdef IN_VMSVGA3D
     698        /** @todo IN_VMSVGA3D */
     699#else
    633700        pBlitter->pDispatch->MatrixMode(GL_PROJECTION);
    634701        pBlitter->pDispatch->LoadIdentity();
    635702        pBlitter->pDispatch->Ortho(0, pDstSize->cx, 0, pDstSize->cy, -1, 1);
     703#endif
    636704        fUpdateViewport = true;
    637705    }
     
    639707    if (fUpdateViewport)
    640708    {
     709#ifdef IN_VMSVGA3D
     710        /** @todo IN_VMSVGA3D */
     711#else
    641712        pBlitter->pDispatch->Viewport(0, 0, pBlitter->CurrentSetSize.cx, pBlitter->CurrentSetSize.cy);
     713#endif
    642714        pBlitter->Flags.CurrentMuralChanged = 0;
    643715    }
     
    645717    pBlitter->Flags.LastWasFBODraw = fFBODraw;
    646718}
     719
     720
     721#ifndef IN_VMSVGA3D
    647722
    648723static 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)
     
    777852}
    778853
     854#endif /* !IN_VMSVGA3D */
     855
     856
    779857void CrBltLeave(PCR_BLITTER pBlitter)
    780858{
     
    788866        return;
    789867
     868#ifdef IN_VMSVGA3D
     869    /** @todo IN_VMSVGA3D */
     870#else
    790871    if (pBlitter->Flags.SupportsFBO)
    791872    {
     
    799880    if (pBlitter->CtxInfo.Base.id)
    800881        pBlitter->pDispatch->MakeCurrent(0, 0, 0);
     882#endif
    801883}
    802884
     
    814896    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)*/
    815897    {
     898#ifdef IN_VMSVGA3D
     899    /** @todo IN_VMSVGA3D */
     900#else
    816901        pBlitter->pDispatch->MakeCurrent(pBlitter->CurrentMural.Base.id, pBlitter->i32MakeCurrentUserData, pBlitter->CtxInfo.Base.id);
     902#endif
    817903    }
    818904
     
    820906        return VINF_SUCCESS;
    821907
     908#ifdef IN_VMSVGA3D
     909    /** @todo IN_VMSVGA3D */
     910    int rc = VINF_SUCCESS;
     911#else
    822912    int rc = crBltInitOnMakeCurent(pBlitter);
     913#endif
    823914    if (RT_SUCCESS(rc))
    824915    {
     
    832923}
    833924
     925
    834926static 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)
    835927{
     928#ifdef IN_VMSVGA3D
     929    /** @todo IN_VMSVGA3D */
     930#else
    836931    pBlitter->pDispatch->DrawBuffer(enmDstBuff);
    837932
     
    842937    else
    843938    {
    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);
    848942
    849943        if (!RT_SUCCESS(rc))
     
    862956        CrGlslProgClear(pBlitter->pGlslCache);
    863957    }
     958#endif
    864959}
    865960
     
    880975    RTRECTSIZE DstSize = {pBlitter->CurrentMural.width, pBlitter->CurrentMural.height};
    881976
     977#ifdef IN_VMSVGA3D
     978    /** @todo IN_VMSVGA3D */
     979#else
    882980    pBlitter->pDispatch->BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
     981#endif
    883982
    884983    crBltBlitTexBuf(pBlitter, pSrc, paSrcRects, fBb ? GL_BACK : GL_FRONT, &DstSize, paDstRects, cRects, fFlags);
    885984}
     985
     986
     987#ifndef IN_VMSVGA3D
    886988
    887989void CrBltBlitTexTex(PCR_BLITTER pBlitter, const VBOXVR_TEXTURE *pSrc, const RTRECT *pSrcRect, const VBOXVR_TEXTURE *pDst, const RTRECT *pDstRect, uint32_t cRects, uint32_t fFlags)
     
    13221424}
    13231425
     1426#endif /* !IN_VMSVGA3D */
     1427
    13241428VBOXBLITTERDECL(bool) CrGlslNeedsCleanup(const CR_GLSL_CACHE *pCache)
    13251429{
     
    13311435    if (pCache->uNoAlpha2DProg)
    13321436    {
     1437#ifdef IN_VMSVGA3D
     1438        /** @todo IN_VMSVGA3D */
     1439#else
    13331440        pCache->pDispatch->DeleteProgram(pCache->uNoAlpha2DProg);
     1441#endif
    13341442        pCache->uNoAlpha2DProg = 0;
    13351443    }
     
    13371445    if (pCache->uNoAlpha2DRectProg)
    13381446    {
     1447#ifdef IN_VMSVGA3D
     1448        /** @todo IN_VMSVGA3D */
     1449#else
    13391450        pCache->pDispatch->DeleteProgram(pCache->uNoAlpha2DRectProg);
     1451#endif
    13401452        pCache->uNoAlpha2DRectProg = 0;
    13411453    }
     
    13521464}
    13531465
     1466#ifndef IN_VMSVGA3D
    13541467
    13551468/*TdBlt*/
     
    14181531}
    14191532
     1533#endif /* !IN_VMSVGA3D */
     1534
     1535
    14201536void crTdBltImgRelease(PCR_TEXDATA pTex)
    14211537{
     
    14411557
    14421558        Assert(CrBltIsEntered(pBlitter));
     1559#ifdef IN_VMSVGA3D
     1560        /** @todo IN_VMSVGA3D */
     1561#else
    14431562        pBlitter->pDispatch->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pTex->idPBO);
    14441563        pBlitter->pDispatch->UnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
    14451564        pBlitter->pDispatch->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
     1565#endif
    14461566    }
    14471567    else
     
    14531573    pTex->Img.pvData = NULL;
    14541574}
     1575
     1576
     1577#ifndef IN_VMSVGA3D
    14551578
    14561579int crTdBltImgAcquire(PCR_TEXDATA pTex, GLenum enmFormat, bool fInverted)
     
    15211644}
    15221645
     1646#endif /* !IN_VMSVGA3D */
     1647
     1648
    15231649/* release the texture data, the data remains cached in the CR_TEXDATA object until it is discarded with CrTdBltDataInvalidateNe or CrTdBltDataCleanup */
    15241650VBOXBLITTERDECL(int) CrTdBltDataRelease(PCR_TEXDATA pTex)
     
    16201746    {
    16211747        Assert(CrBltIsEntered(pBlitter));
     1748#ifdef IN_VMSVGA3D
     1749        /** @todo IN_VMSVGA3D */
     1750#else
    16221751        pBlitter->pDispatch->DeleteBuffersARB(1, &pTex->idPBO);
     1752#endif
    16231753        pTex->idPBO = 0;
    16241754    }
     
    16271757    {
    16281758        Assert(CrBltIsEntered(pBlitter));
     1759#ifdef IN_VMSVGA3D
     1760        /** @todo IN_VMSVGA3D */
     1761#else
    16291762        pBlitter->pDispatch->DeleteTextures(1, &pTex->idInvertTex);
     1763#endif
    16301764        pTex->idInvertTex = 0;
    16311765    }
     
    16701804    return VINF_SUCCESS;
    16711805}
     1806
     1807
     1808#ifndef IN_VMSVGA3D
    16721809
    16731810/* acquire the texture data, returns the cached data in case it is cached.
     
    19812118    pTex->pScaledCache = NULL;
    19822119}
     2120
     2121#endif /* !IN_VMSVGA3D */
     2122
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette