VirtualBox

Ignore:
Timestamp:
Nov 21, 2012 7:28:05 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
82253
Message:

crOpenGL: host offscreen rendering to fix gnome-shell issues, repaint problems and more

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_presenter.cpp

    r43891 r43932  
    3232#include <iprt/mem.h>
    3333
    34 typedef DECLCALLBACK(int) FNCRDISPLAY_REGIONS_CHANGED(struct CR_PRESENTER *pPresenter);
    35 typedef FNCRDISPLAY_REGIONS_CHANGED *PFNCRDISPLAY_REGIONS_CHANGED;
    36 
    37 typedef DECLCALLBACK(int) FNCRDISPLAY_DRAW_ENTRY(struct CR_PRESENTER *pPresenter, struct CR_PRESENTER_ENTRY *pEntry, PCR_BLITTER pBlitter);
    38 typedef FNCRDISPLAY_DRAW_ENTRY *PFNCRDISPLAY_DRAW_ENTRY;
    39 
    40 typedef DECLCALLBACK(int) FNCRDISPLAY_DRAW_TEXTURE(struct CR_PRESENTER *pPresenter, PCR_BLITTER pBlitter,
    41                                             CR_BLITTER_TEXTURE *pTexture, const RTRECT *paSrcRects, const RTRECT *paDstRects, uint32_t cRects);
    42 typedef FNCRDISPLAY_DRAW_TEXTURE *PFNCRDISPLAY_DRAW_TEXTURE;
    43 
    44 
    4534#define CR_DISPLAY_RECTS_UNDEFINED UINT32_MAX
    4635
     
    212201}
    213202
    214 DECLCALLBACK(int) CrPtCbDrawEntrySingle(struct CR_PRESENTER *pPresenter, struct CR_PRESENTER_ENTRY *pEntry, PCR_BLITTER pBlitter)
    215 {
     203DECLCALLBACK(int) CrPtCbDrawEntrySingle(struct CR_PRESENTER *pPresenter, struct CR_PRESENTER_ENTRY *pEntry, PCR_BLITTER pBlitter, bool *pfAllEntriesDrawn)
     204{
     205    if (pfAllEntriesDrawn)
     206        *pfAllEntriesDrawn = false;
     207
    216208    int rc = crPtRectsCheckInit(pPresenter);
    217209    if (!RT_SUCCESS(rc))
     
    241233    struct CR_PRESENTER_ENTRY *pEntry = CR_PRESENTER_ENTRY_FROM_ENTRY(pCEntry);
    242234    PCR_BLITTER pBlitter = (PCR_BLITTER)pvVisitor;
    243     int rc = CrPtCbDrawEntrySingle(pPresenter, pEntry, pBlitter);
     235    bool fAllEntriesDrawn;
     236    int rc = CrPtCbDrawEntrySingle(pPresenter, pEntry, pBlitter, &fAllEntriesDrawn);
    244237    if (!RT_SUCCESS(rc))
    245238    {
    246239        crWarning("CrPtCbDrawEntrySingle failed, rc %d", rc);
    247240    }
    248     return true;
    249 }
    250 
    251 DECLCALLBACK(int) CrPtCbDrawEntryAll(struct CR_PRESENTER *pPresenter, struct CR_PRESENTER_ENTRY *pEntry, PCR_BLITTER pBlitter)
     241    return !fAllEntriesDrawn;
     242}
     243
     244DECLCALLBACK(int) CrPtCbDrawEntryAll(struct CR_PRESENTER *pPresenter, struct CR_PRESENTER_ENTRY *pEntry, PCR_BLITTER pBlitter, bool *pfAllEntriesDrawn)
    252245{
    253246    int rc = crPtRectsCheckInit(pPresenter);
     
    258251    }
    259252
    260     VBoxVrCompositorVisit(&pPresenter->Compositor, crPtDrawEntryAllCb, pPresenter);
     253    VBoxVrCompositorVisit(&pPresenter->Compositor, crPtDrawEntryAllCb, pBlitter);
     254
     255    if (pfAllEntriesDrawn)
     256        *pfAllEntriesDrawn = true;
    261257
    262258    return VINF_SUCCESS;
     
    289285}
    290286
     287static int crPtEntryRegionsSet(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, uint32_t cRegions, const RTRECT *paRegions, bool *pfChanged)
     288{
     289    bool fChanged;
     290    int rc = VBoxVrCompositorEntryRegionsSet(&pPresenter->Compositor, &pEntry->Ce, cRegions, paRegions, &fChanged);
     291    if (!RT_SUCCESS(rc))
     292    {
     293        crWarning("VBoxVrCompositorEntryRegionsSet failed, rc %d", rc);
     294        return rc;
     295    }
     296
     297    if (fChanged)
     298    {
     299        crPtRectsInvalidate(pPresenter);
     300        rc = pPresenter->pfnRegionsChanged(pPresenter);
     301        if (!RT_SUCCESS(rc))
     302        {
     303            crWarning("pfnRegionsChanged failed, rc %d", rc);
     304            return rc;
     305        }
     306    }
     307
     308    if (pfChanged)
     309        *pfChanged = fChanged;
     310    return VINF_SUCCESS;
     311}
     312
    291313static void crPtEntryPositionSet(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, const RTPOINT *pPos)
    292314{
    293     if (pEntry && pEntry->Pos.x != pPos->x || pEntry->Pos.y != pPos->y)
    294     {
    295         VBoxVrCompositorEntryRemove(&pPresenter->Compositor, &pEntry->Ce);
    296         crPtRectsInvalidate(pPresenter);
     315    if (pEntry && (pEntry->Pos.x != pPos->x || pEntry->Pos.y != pPos->y))
     316    {
     317        if (VBoxVrCompositorEntryIsInList(&pEntry->Ce))
     318        {
     319            VBoxVrCompositorEntryRemove(&pPresenter->Compositor, &pEntry->Ce);
     320            crPtRectsInvalidate(pPresenter);
     321        }
    297322        pEntry->Pos = *pPos;
    298323    }
    299324}
    300325
    301 int CrPtEntryPresent(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions, PCR_BLITTER pBlitter)
     326int CrPtPresentEntry(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, PCR_BLITTER pBlitter)
     327{
     328    int rc = CrBltEnter(pBlitter, cr_server.currentCtxInfo, cr_server.currentMural);
     329    if (!RT_SUCCESS(rc))
     330    {
     331        crWarning("CrBltEnter failed, rc %d", rc);
     332        return rc;
     333    }
     334
     335    rc = pPresenter->pfnDrawEntry(pPresenter, pEntry, pBlitter, NULL);
     336
     337    CrBltLeave(pBlitter);
     338
     339    if (!RT_SUCCESS(rc))
     340    {
     341        crWarning("pfnDraw failed, rc %d", rc);
     342        return rc;
     343    }
     344
     345    return VINF_SUCCESS;
     346}
     347
     348static DECLCALLBACK(bool) crPtPresentCb(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pCEntry, void *pvVisitor)
     349{
     350    struct CR_PRESENTER *pPresenter = CR_PRESENTER_FROM_COMPOSITOR(pCompositor);
     351    struct CR_PRESENTER_ENTRY *pEntry = CR_PRESENTER_ENTRY_FROM_ENTRY(pCEntry);
     352    PCR_BLITTER pBlitter = (PCR_BLITTER)pvVisitor;
     353    bool fAllDrawn = false;
     354    int rc = pPresenter->pfnDrawEntry(pPresenter, pEntry, pBlitter, &fAllDrawn);
     355    if (!RT_SUCCESS(rc))
     356    {
     357        crWarning("pfnDrawEntry failed, rc %d", rc);
     358    }
     359    return !fAllDrawn;
     360}
     361
     362int CrPtPresent(PCR_PRESENTER pPresenter, PCR_BLITTER pBlitter)
     363{
     364    int rc = CrBltEnter(pBlitter, cr_server.currentCtxInfo, cr_server.currentMural);
     365    if (!RT_SUCCESS(rc))
     366    {
     367        crWarning("CrBltEnter failed, rc %d", rc);
     368        return rc;
     369    }
     370
     371    VBoxVrCompositorVisit(&pPresenter->Compositor, crPtPresentCb, pBlitter);
     372
     373    CrBltLeave(pBlitter);
     374
     375    if (!RT_SUCCESS(rc))
     376    {
     377        crWarning("pfnDraw failed, rc %d", rc);
     378        return rc;
     379    }
     380
     381    return VINF_SUCCESS;
     382}
     383
     384int CrPtEntryRegionsAdd(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions)
    302385{
    303386    crPtEntryPositionSet(pPresenter, pEntry, pPos);
     
    310393    }
    311394
    312     if (!pEntry)
    313         return VINF_SUCCESS;
    314 
    315     rc = CrBltEnter(pBlitter, cr_server.currentCtxInfo, cr_server.currentMural);
    316     if (!RT_SUCCESS(rc))
    317     {
    318         crWarning("CrBltEnter failed, rc %d", rc);
    319         return rc;
    320     }
    321 
    322     rc = pPresenter->pfnDrawEntry(pPresenter, pEntry, pBlitter);
    323 
    324     CrBltLeave(pBlitter);
    325 
    326     if (!RT_SUCCESS(rc))
    327     {
    328         crWarning("pfnDrawEntry failed, rc %d", rc);
    329         return rc;
    330     }
     395    return VINF_SUCCESS;
     396}
     397
     398int CrPtEntryRegionsSet(PCR_PRESENTER pPresenter, PCR_PRESENTER_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions)
     399{
     400    crPtEntryPositionSet(pPresenter, pEntry, pPos);
     401
     402    int rc = crPtEntryRegionsSet(pPresenter, pEntry, cRegions, paRegions, NULL);
     403    if (!RT_SUCCESS(rc))
     404    {
     405        crWarning("crPtEntryRegionsAdd failed, rc %d", rc);
     406        return rc;
     407    }
     408
    331409    return VINF_SUCCESS;
    332410}
     
    429507int CrDpInit(PCR_DISPLAY pDisplay)
    430508{
    431     const GLint visBits = CR_RGB_BIT;
    432     int rc = CrPtInit(&pDisplay->Presenter, crDpCbRegionsChanged, CrPtCbDrawEntrySingle, crDpCbDrawTextureWindow);
     509    const GLint visBits = CR_RGB_BIT | CR_DOUBLE_BIT;
     510    int rc = CrPtInit(&pDisplay->Presenter, crDpCbRegionsChanged, CrPtCbDrawEntryAll, crDpCbDrawTextureWindow);
    433511    if (RT_SUCCESS(rc))
    434512    {
     
    455533}
    456534
    457 bool CrDpBlitterTest(PCR_DISPLAY pDisplay, PCR_BLITTER pBlitter)
    458 {
    459     CrBltMuralSetCurrent(pBlitter, &pDisplay->Mural);
     535int CrDpBlitterTestWithMural(PCR_BLITTER pBlitter, CRMuralInfo *pMural)
     536{
     537    CrBltMuralSetCurrent(pBlitter, pMural);
    460538    /* try to enter to make sure the blitter is initialized completely and to make sure we actually can do that */
    461539    int rc = CrBltEnter(pBlitter, cr_server.currentCtxInfo, cr_server.currentMural);
     
    463541    {
    464542        CrBltLeave(pBlitter);
    465         return true;
     543        return VINF_SUCCESS;
    466544    }
    467545    else
     
    469547        crWarning("CrBltEnter failed, rc %d", rc);
    470548    }
    471     return false;
     549    return rc;
     550}
     551
     552int CrDpBlitterTest(PCR_DISPLAY pDisplay, PCR_BLITTER pBlitter)
     553{
     554    return CrDpBlitterTestWithMural(pBlitter, &pDisplay->Mural);
    472555}
    473556
     
    482565}
    483566
    484 int CrDpPresentTexture(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions)
    485 {
    486     return CrPtEntryPresent(&pDisplay->Presenter, &pEntry->Pe, pPos, cRegions, paRegions, pDisplay->pBlitter);
     567int CrDpEntryRegionsSet(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions)
     568{
     569    return CrPtEntryRegionsSet(&pDisplay->Presenter, &pEntry->Pe, pPos, cRegions, paRegions);
     570}
     571
     572int CrDpEntryRegionsAdd(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry, const RTPOINT *pPos, uint32_t cRegions, const RTRECT *paRegions)
     573{
     574    return CrPtEntryRegionsAdd(&pDisplay->Presenter, &pEntry->Pe, pPos, cRegions, paRegions);
     575}
     576
     577int CrDpPresentEntry(PCR_DISPLAY pDisplay, PCR_DISPLAY_ENTRY pEntry)
     578{
     579    return CrPtPresentEntry(&pDisplay->Presenter, &pEntry->Pe, pDisplay->pBlitter);
    487580}
    488581
     
    582675#define CR_PRESENT_GET_FLAGS(_cfg) ((_cfg) >> CR_PRESENT_FLAGS_OFFSET)
    583676
    584 static uint8_t crServerCheckInitDisplayBlitter()
     677int crServerBlitterInit(PCR_BLITTER pBlitter, CRMuralInfo*pMural)
     678{
     679    int rc = CrBltInit(pBlitter, pMural);
     680    if (RT_SUCCESS(rc))
     681    {
     682        rc = CrDpBlitterTestWithMural(pBlitter, pMural);
     683        if (RT_SUCCESS(rc))
     684            return VINF_SUCCESS;
     685        else
     686            crWarning("CrDpBlitterTestWithMural failed, rc %d", rc);
     687        CrBltTerm(pBlitter);
     688    }
     689    else
     690        crWarning("CrBltInit failed, rc %d", rc);
     691    return rc;
     692}
     693
     694PCR_BLITTER crServerGetFBOPresentBlitter(CRMuralInfo*pMural)
     695{
     696    if (cr_server.fFBOModeBlitterInited > 0)
     697        return &cr_server.FBOModeBlitter;
     698    if (!cr_server.fFBOModeBlitterInited)
     699    {
     700        int rc = crServerBlitterInit(&cr_server.FBOModeBlitter, pMural);
     701        if (RT_SUCCESS(rc))
     702        {
     703            cr_server.fFBOModeBlitterInited = 1;
     704            return &cr_server.FBOModeBlitter;
     705        }
     706        crWarning("crServerBlitterInit failed rc %d", rc);
     707        cr_server.fFBOModeBlitterInited = -1;
     708    }
     709    return NULL;
     710}
     711
     712static int8_t crServerCheckInitDisplayBlitter()
    585713{
    586714    if (cr_server.fPresentBlitterInited)
     
    597725        {
    598726            CRMuralInfo*pMural = CrDpGetMural(&cr_server.aDispplays[0]);
    599             CRCreateInfo_t*pCreateInfo = CrDpGetMuralCreateInfo(&cr_server.aDispplays[0]);
    600             rc = CrBltInit(&cr_server.PresentBlitter, pMural, pCreateInfo->visualBits);
     727            rc = crServerBlitterInit(&cr_server.PresentBlitter, pMural);
    601728            if (RT_SUCCESS(rc))
    602729            {
    603                 if (CrDpBlitterTest(&cr_server.aDispplays[0], &cr_server.PresentBlitter))
    604                 {
    605                     CrDpBlitterSet(&cr_server.aDispplays[0], &cr_server.PresentBlitter);
    606                     ASMBitSet(cr_server.DisplaysInitMap, 0);
    607                     cr_server.fPresentBlitterInited = 1;
    608                     return 1;
    609                 }
    610                 else
    611                 {
    612                     crWarning("CrDpBlitterTest failed");
    613                 }
    614                 CrBltTerm(&cr_server.PresentBlitter);
     730                CrDpBlitterSet(&cr_server.aDispplays[0], &cr_server.PresentBlitter);
     731                CrDpResize(&cr_server.aDispplays[0],
     732                            cr_server.screen[0].w, cr_server.screen[0].h,
     733                            cr_server.screen[0].w, cr_server.screen[0].h);
     734                ASMBitSet(cr_server.DisplaysInitMap, 0);
     735                cr_server.fPresentBlitterInited = 1;
     736                return 1;
    615737            }
    616738            else
    617739            {
    618                 crWarning("CrBltInit failed, rc %d", rc);
     740                crWarning("crServerBlitterInit failed, rc %d", rc);
    619741            }
    620742            CrDpTerm(&cr_server.aDispplays[0]);
     
    638760{
    639761    return crServerCheckInitDisplayBlitter() > 0;
     762}
     763
     764PCR_DISPLAY crServerDisplayGetInitialized(uint32_t idScreen)
     765{
     766    if (ASMBitTest(cr_server.DisplaysInitMap, idScreen))
     767        return &cr_server.aDispplays[idScreen];
     768    return NULL;
    640769}
    641770
     
    662791        {
    663792            CrDpBlitterSet(&cr_server.aDispplays[idScreen], &cr_server.PresentBlitter);
     793            CrDpResize(&cr_server.aDispplays[idScreen],
     794                    cr_server.screen[idScreen].w, cr_server.screen[idScreen].h,
     795                    cr_server.screen[idScreen].w, cr_server.screen[idScreen].h);
    664796            ASMBitSet(cr_server.DisplaysInitMap, idScreen);
    665797            return &cr_server.aDispplays[idScreen];
     
    697829
    698830    RTPOINT Point = {xPos, yPos};
    699     int rc = CrDpPresentTexture(pDisplay, pEntry, &Point, (uint32_t)cRects, (const RTRECT*)pRects);
    700     if (!RT_SUCCESS(rc))
    701     {
    702         crWarning("CrDpPresentTexture Failed rc %d", rc);
    703     }
    704 }
     831    int rc = CrDpEntryRegionsAdd(pDisplay, pEntry, &Point, (uint32_t)cRects, (const RTRECT*)pRects);
     832    if (!RT_SUCCESS(rc))
     833    {
     834        crWarning("CrDpEntrySetRegions Failed rc %d", rc);
     835        return;
     836    }
     837
     838    rc = CrDpPresentEntry(pDisplay, pEntry);
     839    if (!RT_SUCCESS(rc))
     840    {
     841        crWarning("CrDpEntrySetRegions Failed rc %d", rc);
     842        return;
     843    }
     844}
Note: See TracChangeset for help on using the changeset viewer.

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