VirtualBox

Changeset 52560 in vbox


Ignore:
Timestamp:
Sep 1, 2014 6:44:22 PM (10 years ago)
Author:
vboxsync
Message:

crOpenGL: window reference

Location:
trunk/src/VBox/HostServices/SharedOpenGL/render
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.c

    r52494 r52560  
    316316}
    317317
     318WindowInfo* renderspuWinCreate(GLint visBits, GLint id)
     319{
     320    WindowInfo* window = (WindowInfo *)crAlloc(sizeof (*window));
     321    if (!window)
     322    {
     323        crWarning("crAlloc failed");
     324        return NULL;
     325    }
     326
     327    if (!renderspuWinInit(window, NULL, visBits, id))
     328    {
     329        crWarning("renderspuWinInit failed");
     330        crFree(window);
     331        return NULL;
     332    }
     333
     334    return window;
     335}
     336
     337void renderspuWinTermOnShutdown(WindowInfo *window)
     338{
     339    renderspuVBoxCompositorSet(window, NULL);
     340    renderspuVBoxPresentBlitterCleanup(window);
     341    renderspu_SystemDestroyWindow( window );
     342    window->BltInfo.Base.id = -1;
     343}
     344
     345static void renderspuCheckCurrentCtxWindowCB(unsigned long key, void *data1, void *data2)
     346{
     347    ContextInfo *pCtx = (ContextInfo *) data1;
     348    WindowInfo *pWindow = data2;
     349    (void) key;
     350
     351    if (pCtx->currentWindow==pWindow)
     352    {
     353        WindowInfo* pDummy = renderspuGetDummyWindow(pCtx->BltInfo.Base.visualBits);
     354        if (pDummy)
     355        {
     356            renderspuPerformMakeCurrent(pDummy, 0, pCtx);
     357        }
     358        else
     359        {
     360            crWarning("failed to get dummy window");
     361            renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, pCtx->BltInfo.Base.id);
     362        }
     363    }
     364}
     365
     366void renderspuWinTerm( WindowInfo *window )
     367{
     368    if (!renderspuWinIsTermed(window))
     369    {
     370
     371    GET_CONTEXT(pOldCtx);
     372    WindowInfo * pOldWindow = pOldCtx ? pOldCtx->currentWindow : NULL;
     373    CRASSERT(!pOldCtx == !pOldWindow);
     374    /* ensure no concurrent draws can take place */
     375    renderspuWinTermOnShutdown(window);
     376    /* check if this window is bound to some ctx. Note: window pointer is already freed here */
     377    crHashtableWalk(render_spu.contextTable, renderspuCheckCurrentCtxWindowCB, window);
     378    /* restore current context */
     379    {
     380        GET_CONTEXT(pNewCtx);
     381        WindowInfo * pNewWindow = pNewCtx ? pNewCtx->currentWindow : NULL;
     382        CRASSERT(!pNewCtx == !pNewWindow);
     383
     384        if (pOldWindow == window)
     385            renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, CR_RENDER_DEFAULT_CONTEXT_ID);
     386        else if (pNewCtx != pOldCtx || pOldWindow != pNewWindow)
     387        {
     388            if (pOldCtx)
     389                renderspuPerformMakeCurrent(pOldWindow, 0, pOldCtx);
     390            else
     391                renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, CR_RENDER_DEFAULT_CONTEXT_ID);
     392        }
     393    }
     394
     395    }
     396}
     397
     398void renderspuWinCleanup(WindowInfo *window)
     399{
     400    renderspuWinTerm( window );
     401    RTCritSectDelete(&window->CompositorLock);
     402}
     403
     404void renderspuWinDestroy(WindowInfo *window)
     405{
     406    renderspuWinCleanup(window);
     407    crFree(window);
     408}
     409
    318410WindowInfo* renderspuGetDummyWindow(GLint visBits)
    319411{
     
    321413    if (!window)
    322414    {
    323         window = (WindowInfo *)crAlloc(sizeof (*window));
     415        window = renderspuWinCreate(visBits, -1);
    324416        if (!window)
    325417        {
    326             crWarning("crAlloc failed");
    327             return NULL;
    328         }
    329 
    330         if (!renderspuWindowInit(window, NULL, visBits, -1))
    331         {
    332             crWarning("renderspuWindowInit failed");
    333             crFree(window);
     418            WARN(("renderspuWinCreate failed"));
    334419            return NULL;
    335420        }
     
    446531}
    447532
    448 GLboolean renderspuWindowInitWithVisual( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id )
     533GLboolean renderspuWinInitWithVisual( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id )
    449534{
    450535    crMemset(window, 0, sizeof (*window));
     
    494579    window->visible = !!showIt;
    495580
     581    window->cRefs = 1;
     582
    496583    CRASSERT(window->visual == visual);
    497584    return GL_TRUE;
     
    501588 * Window functions
    502589 */
    503 GLboolean renderspuWindowInit(WindowInfo *pWindow, const char *dpyName, GLint visBits, GLint id)
     590GLboolean renderspuWinInit(WindowInfo *pWindow, const char *dpyName, GLint visBits, GLint id)
    504591{
    505592    VisualInfo *visual;
     
    521608    */
    522609    /* Have GLX/WGL/AGL create the window */
    523     if (!renderspuWindowInitWithVisual( pWindow, visual, 0, id ))
     610    if (!renderspuWinInitWithVisual( pWindow, visual, 0, id ))
    524611    {
    525612        crWarning( "Render SPU: Couldn't create a window, renderspu_SystemCreateWindow failed" );
     
    553640
    554641    /* Allocate WindowInfo */
    555     window = (WindowInfo *) crCalloc(sizeof(WindowInfo));
     642    window = renderspuWinCreate(visBits, id);
     643
    556644    if (!window)
    557645    {
    558         crWarning( "Render SPU: Couldn't create a window" );
    559         return -1;
    560     }
    561    
    562     if (!renderspuWindowInit(window, dpyName, visBits, id))
    563     {
    564         crWarning("renderspuWindowInit failed");
     646        crWarning("renderspuWinCreate failed");
    565647        crFree(window);
    566648        return -1;
     
    577659}
    578660
    579 static void renderspuCheckCurrentCtxWindowCB(unsigned long key, void *data1, void *data2)
    580 {
    581     ContextInfo *pCtx = (ContextInfo *) data1;
    582     WindowInfo *pWindow = data2;
    583     (void) key;
    584 
    585     if (pCtx->currentWindow==pWindow)
    586     {
    587         WindowInfo* pDummy = renderspuGetDummyWindow(pCtx->BltInfo.Base.visualBits);
    588         if (pDummy)
    589         {
    590             renderspuPerformMakeCurrent(pDummy, 0, pCtx);
    591         }
    592         else
    593         {
    594             crWarning("failed to get dummy window");
    595             renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, pCtx->BltInfo.Base.id);
    596         }
    597     }
    598 }
    599 
    600 void renderspuWindowTermBase( WindowInfo *window )
    601 {
    602     renderspuVBoxCompositorSet(window, NULL);
    603     renderspuVBoxPresentBlitterCleanup(window);
    604     renderspu_SystemDestroyWindow( window );
    605     RTCritSectDelete(&window->CompositorLock);
    606 }
    607 
    608 void renderspuWindowTerm( WindowInfo *window )
    609 {
    610     GET_CONTEXT(pOldCtx);
    611     WindowInfo * pOldWindow = pOldCtx ? pOldCtx->currentWindow : NULL;
    612     CRASSERT(!pOldCtx == !pOldWindow);
    613     /* ensure no concurrent draws can take place */
    614     renderspuWindowTermBase(window);
    615     /* check if this window is bound to some ctx. Note: window pointer is already freed here */
    616     crHashtableWalk(render_spu.contextTable, renderspuCheckCurrentCtxWindowCB, window);
    617     /* restore current context */
    618     {
    619         GET_CONTEXT(pNewCtx);
    620         WindowInfo * pNewWindow = pNewCtx ? pNewCtx->currentWindow : NULL;
    621         CRASSERT(!pNewCtx == !pNewWindow);
    622 
    623         if (pOldWindow == window)
    624             renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, CR_RENDER_DEFAULT_CONTEXT_ID);
    625         else if (pNewCtx != pOldCtx || pOldWindow != pNewWindow)
    626         {
    627             if (pOldCtx)
    628                 renderspuPerformMakeCurrent(pOldWindow, 0, pOldCtx);
    629             else
    630                 renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, CR_RENDER_DEFAULT_CONTEXT_ID);
    631         }
    632     }
     661void renderspuWinReleaseCb(void*pvWindow)
     662{
     663    renderspuWinRelease((WindowInfo*)pvWindow);
    633664}
    634665
     
    647678    if (window) {
    648679        crDebug("Render SPU: Destroy window (%d)", win);
    649         renderspuWindowTerm( window );
     680        /* since os-specific backend can hold its own reference to the window object (e.g. on OSX),
     681         * we need to explicitly issue a window destroy command
     682         * this ensures the backend will eventually release the reference,
     683         * the window object itself will remain valid until its ref count reaches zero */
     684        renderspuWinTerm( window );
    650685
    651686        /* remove window info from hash table, and free it */
    652         crHashtableDelete(render_spu.windowTable, win, crFree);
     687        crHashtableDelete(render_spu.windowTable, win, renderspuWinReleaseCb);
    653688
    654689    }
  • trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.h

    r52429 r52560  
    9898
    9999    VisualInfo *visual;
     100
     101    volatile uint32_t cRefs;
     102
    100103    GLboolean mapPending;
    101104    GLboolean visible;
     
    432435extern PCR_BLITTER renderspuVBoxPresentBlitterGetAndEnter( WindowInfo *window, int32_t i32MakeCurrentUserData, bool fRedraw );
    433436extern PCR_BLITTER renderspuVBoxPresentBlitterEnsureCreated( WindowInfo *window, int32_t i32MakeCurrentUserData );
    434 void renderspuWindowTermBase( WindowInfo *window );
    435 extern void renderspuWindowTerm( WindowInfo *window );
     437WindowInfo* renderspuWinCreate(GLint visBits, GLint id);
     438void renderspuWinTermOnShutdown(WindowInfo *window);
     439void renderspuWinTerm( WindowInfo *window );
     440void renderspuWinCleanup(WindowInfo *window);
     441void renderspuWinDestroy(WindowInfo *window);
     442GLboolean renderspuWinInitWithVisual( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id );
     443GLboolean renderspuWinInit(WindowInfo *pWindow, const char *dpyName, GLint visBits, GLint id);
     444
     445DECLINLINE(void) renderspuWinRetain(WindowInfo *window)
     446{
     447    ASMAtomicIncU32(&window->cRefs);
     448}
     449
     450DECLINLINE(bool) renderspuWinIsTermed(WindowInfo *window)
     451{
     452    return window->BltInfo.Base.id < 0;
     453}
     454
     455DECLINLINE(void) renderspuWinRelease(WindowInfo *window)
     456{
     457    uint32_t cRefs = ASMAtomicDecU32(&window->cRefs);
     458    if (!cRefs)
     459    {
     460        renderspuWinDestroy(window);
     461    }
     462}
     463
    436464extern WindowInfo* renderspuGetDummyWindow(GLint visBits);
    437465extern void renderspuPerformMakeCurrent(WindowInfo *window, GLint nativeWindow, ContextInfo *context);
    438 extern GLboolean renderspuWindowInit(WindowInfo *pWindow, const char *dpyName, GLint visBits, GLint id);
    439 extern GLboolean renderspuWindowInitWithVisual( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id );
    440466extern GLboolean renderspuInitVisual(VisualInfo *pVisInfo, const char *displayName, GLbitfield visAttribs);
    441467extern void renderspuVBoxCompositorBlit ( const struct VBOXVR_SCR_COMPOSITOR * pCompositor, PCR_BLITTER pBlitter);
  • trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m

    r52532 r52560  
    14131413        [self performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
    14141414    }
     1415   
     1416    renderspuWinRelease(m_pWinInfo);
     1417   
    14151418    DEBUG_FUNC_LEAVE();
    14161419}
     
    24792482    /* make sure all tasks are run, to preserve the order */
    24802483    [pRunner runTasksSyncIfPossible];
     2484   
     2485    renderspuWinRetain(pWinInfo);
    24812486
    24822487    if (renderspuCalloutAvailable())
     
    25012506#endif
    25022507    }
     2508   
     2509    if (!*ppView)
     2510        renderspuWinRelease(pWinInfo);
    25032511   
    25042512    [pPool release];
  • trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_glx.c

    r52261 r52560  
    448448            if (bRc)
    449449            {
    450                 bRc = renderspuWindowInitWithVisual(&render_spu.WinCmdWindow, &render_spu.WinCmdVisual, GL_FALSE, CR_RENDER_WINCMD_ID);
     450                bRc = renderspuWinInitWithVisual(&render_spu.WinCmdWindow, &render_spu.WinCmdVisual, GL_FALSE, CR_RENDER_WINCMD_ID);
    451451                if (bRc)
    452452                {
     
    458458                else
    459459                {
    460                     crError("renderspuWindowInitWithVisual failed");
     460                    crError("renderspuWinInitWithVisual failed");
    461461                }
    462462                /* there is no visual destroy impl currently
     
    486486    /* the window is not in the table, this will just ensure the key is freed */
    487487    crHashtableDelete(render_spu.windowTable, CR_RENDER_WINCMD_ID, NULL);
    488     renderspuWindowTerm(&render_spu.WinCmdWindow);
     488    renderspuWinCleanup(&render_spu.WinCmdWindow);
    489489    crFreeHashtable(render_spu.pWinToInfoTable, NULL);
    490490    /* we do not have visual destroy functionality
  • trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_init.c

    r51064 r52560  
    428428{
    429429    WindowInfo *window = (WindowInfo *) data;
    430     renderspuWindowTermBase(window);
    431     crFree(window);
     430    renderspuWinTermOnShutdown(window);
     431    renderspuWinRelease(window);
    432432}
    433433
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