VirtualBox

Ignore:
Timestamp:
Mar 1, 2010 1:20:27 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
58193
Message:

crOpenGL: fix flickering when opengl context is used with multiply windows

Location:
trunk/src/VBox/Additions/common/crOpenGL
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/crOpenGL/context.c

    r26545 r26909  
    220220    winInfo->spuWindow = -1;
    221221    winInfo->mapped = -1; /* don't know */
     222    winInfo->pOwner = NULL;
    222223#ifndef WINDOWS
    223224    crHashtableAdd(stub.windowTable, (unsigned int) drawable, winInfo);
     
    271272    context->visBits = visBits;
    272273    context->currentDrawable = NULL;
    273     context->pOwnWindow = NULL;
    274274    crStrncpy(context->dpyName, dpyName, MAX_DPY_NAME);
    275275    context->dpyName[MAX_DPY_NAME-1] = 0;
     
    790790}
    791791
    792 static void stubCtxCheckCurrentDrawableCB(unsigned long key, void *data1, void *data2)
    793 {
    794     ContextInfo *pCtx = (ContextInfo *) data1;
    795     CtxCheckCurrentDrawableParams_t *pParams = (CtxCheckCurrentDrawableParams_t *) data2;
    796 
    797     if (pCtx->currentDrawable == pParams->window)
     792static void stubWindowCheckOwnerCB(unsigned long key, void *data1, void *data2)
     793{
     794    WindowInfo *pWindow = (WindowInfo *) data1;
     795    ContextInfo *pCtx = (ContextInfo *) data2;
     796
     797    if (pWindow->pOwner == pCtx)
    798798    {
    799         pParams->windowInUse = GL_TRUE;
     799#ifdef WINDOWS
     800            /* Note: can't use WindowFromDC(context->pOwnWindow->drawable) here
     801               because GL context is already released from DC and actual guest window
     802               could be destroyed.
     803             */
     804            crWindowDestroy((GLint)pWindow->hWnd);
     805#else
     806            crWindowDestroy((GLint)pWindow->drawable);
     807#endif
    800808    }
    801809}
     
    851859                /*crDebug("(1)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/
    852860                window->spuWindow = stub.spu->dispatch_table.WindowCreate( window->dpyName, context->visBits );
    853                 CRASSERT(!context->pOwnWindow);
    854                 context->pOwnWindow = window;
    855861            }
    856862        }
     
    896902        CRASSERT(context->spuContext >= 0);
    897903
    898         if (context->currentDrawable && context->currentDrawable != window)
    899             crWarning("Rebinding context %p to a different window", context);
     904        /*if (context->currentDrawable && context->currentDrawable != window)
     905            crDebug("Rebinding context %p to a different window", context);*/
    900906
    901907        if (window->type == NATIVE) {
     
    908914                /*crDebug("(2)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/
    909915                window->spuWindow = stub.spu->dispatch_table.WindowCreate( window->dpyName, context->visBits );
    910                 if (context->pOwnWindow)
     916                if (context->currentDrawable && context->currentDrawable->type==CHROMIUM
     917                    && context->currentDrawable->pOwner==context)
    911918                {
    912                     WindowInfo *pOwnWindow = context->pOwnWindow;
    913                     CtxCheckCurrentDrawableParams_t params;
    914 
    915                     context->pOwnWindow = NULL;
    916                     context->currentDrawable=NULL;
    917 
    918                     params.window = pOwnWindow;
    919                     params.windowInUse = GL_FALSE;
    920 
    921                     crHashtableWalk(stub.contextTable, stubCtxCheckCurrentDrawableCB, &params);
    922 
    923                     if (!params.windowInUse)
    924                     {
    925919#ifdef WINDOWS
    926                         crWindowDestroy((GLint)pOwnWindow->hWnd);
     920                        if (!WindowFromDC(context->currentDrawable->drawable))
     921                        {
     922                            crWindowDestroy((GLint)context->currentDrawable->hWnd);
     923                        }
    927924#else
    928                         crWindowDestroy((GLint)pOwnWindow->drawable);
    929 #endif
    930                     }
     925                        Window root;
     926                        int x, y;
     927                        unsigned int border, depth, w, h;
     928
     929                        if (!XGetGeometry(context->currentDrawable->dpy, context->currentDrawable->drawable, &root, &x, &y, &w, &h, &border, &depth))
     930                        {
     931                            crWindowDestroy((GLint)context->currentDrawable->drawable);
     932                        }
     933#endif
     934                   
    931935                }
    932                 context->pOwnWindow = window;
    933936            }
    934937
     
    943946
    944947    window->type = context->type;
     948    window->pOwner = context;
    945949    context->currentDrawable = window;
    946950    stub.currentContext = context;
     
    10021006}
    10031007
    1004 
    1005 
    10061008void
    10071009stubDestroyContext( unsigned long contextId )
     
    10291031        CRASSERT(context->spuContext >= 0);
    10301032        stub.spu->dispatch_table.DestroyContext( context->spuContext );
    1031         if (context->pOwnWindow)
    1032         {
    1033             /* Note: can't use WindowFromDC(context->pOwnWindow->drawable) here
    1034                because GL context is already released from DC and actual guest window
    1035                could be destroyed.
    1036              */
    1037 #ifdef WINDOWS
    1038             crWindowDestroy((GLint)context->pOwnWindow->hWnd);
    1039 #else
    1040             crWindowDestroy((GLint)context->pOwnWindow->drawable);
    1041 #endif
    1042         }
     1033        crHashtableWalk(stub.windowTable, stubWindowCheckOwnerCB, context);
    10431034    }
    10441035
  • trunk/src/VBox/Additions/common/crOpenGL/load.c

    r26117 r26909  
    8080static ScissorFunc_t origScissor;
    8181
    82 static void stubCheckWindowState(void)
    83 {
    84     WindowInfo *window;
     82static void stubCheckWindowState(WindowInfo *window)
     83{
    8584    bool bForceUpdate = false;
    86 
    87     CRASSERT(stub.trackWindowSize || stub.trackWindowPos);
    88 
    89     if (!stub.currentContext)
    90         return;
    91 
    92     window = stub.currentContext->currentDrawable;
    9385
    9486#ifdef WINDOWS
     
    129121}
    130122
     123static bool stubSystemWindowExist(WindowInfo *pWindow)
     124{
     125#ifdef WINDOWS
     126    if (!WindowFromDC(pWindow->drawable))
     127    {
     128        return false;
     129    }
     130#else
     131    Window root;
     132    int x, y;
     133    unsigned int border, depth, w, h;
     134
     135    if (!XGetGeometry(pWindow->dpy, pWindow->drawable, &root, &x, &y, &w, &h, &border, &depth))
     136    {
     137        return false;
     138    }
     139#endif
     140
     141    return true;
     142}
     143
     144static void stubCheckWindowsCB(unsigned long key, void *data1, void *data2)
     145{
     146    WindowInfo *pWindow = (WindowInfo *) data1;
     147    ContextInfo *pCtx = (ContextInfo *) data2;
     148
     149    if (pWindow == pCtx->currentDrawable
     150        || pWindow->type!=CHROMIUM
     151        || pWindow->pOwner!=pCtx)
     152    {
     153        return;
     154    }
     155
     156    if (!stubSystemWindowExist(pWindow))
     157    {
     158#ifdef WINDOWS
     159        crWindowDestroy((GLint)pWindow->hWnd);
     160#else
     161        crWindowDestroy((GLint)pWindow->drawable);
     162#endif
     163        return;
     164    }
     165
     166    stubCheckWindowState(pWindow);
     167}
     168
     169static void stubCheckWindowsState(void)
     170{
     171    CRASSERT(stub.trackWindowSize || stub.trackWindowPos);
     172
     173    if (!stub.currentContext)
     174        return;
     175
     176    stubCheckWindowState(stub.currentContext->currentDrawable);
     177
     178    crHashtableWalk(stub.windowTable, stubCheckWindowsCB, stub.currentContext);
     179}
     180
    131181
    132182/**
     
    137187static void SPU_APIENTRY trapClear(GLbitfield mask)
    138188{
    139     stubCheckWindowState();
     189    stubCheckWindowsState();
    140190    /* call the original SPU glClear function */
    141191    origClear(mask);
     
    148198static void SPU_APIENTRY trapViewport(GLint x, GLint y, GLsizei w, GLsizei h)
    149199{
    150     stubCheckWindowState();
     200    stubCheckWindowsState();
    151201    /* call the original SPU glViewport function */
    152202    if (!stub.viewportHack)
     
    167217static void SPU_APIENTRY trapSwapBuffers(GLint window, GLint flags)
    168218{
    169     stubCheckWindowState();
     219    stubCheckWindowsState();
    170220    origSwapBuffers(window, flags);
    171221}
     
    173223static void SPU_APIENTRY trapDrawBuffer(GLenum buf)
    174224{
    175     stubCheckWindowState();
     225    stubCheckWindowsState();
    176226    origDrawBuffer(buf);
    177227}
  • trunk/src/VBox/Additions/common/crOpenGL/stub.h

    r25383 r26909  
    9292    GLint visBits;
    9393    WindowInfo *currentDrawable;
    94     WindowInfo *pOwnWindow; /* window created by first call to MakeCurrent with this context */
     94
    9595#ifdef WINDOWS
    9696    HGLRC hglrc;
     
    137137    ContextType type;
    138138    GLint spuWindow;       /* returned by head SPU's WindowCreate() */
     139    ContextInfo *pOwner;     /* ctx which created this window */
    139140    GLboolean mapped;
    140141#ifdef WINDOWS
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