VirtualBox

Ignore:
Timestamp:
Feb 28, 2013 10:48:15 AM (12 years ago)
Author:
vboxsync
Message:

crOpenGL: redraw impl for X11/glx hosts; enable offscreen rendering for X11/glx hosts

File:
1 edited

Legend:

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

    r44813 r44860  
    8080}
    8181
     82GLboolean renderspuInitVisual(VisualInfo *pVisInfo, const char *displayName, GLbitfield visAttribs)
     83{
     84    pVisInfo->displayName = crStrdup(displayName);
     85    pVisInfo->visAttribs = visAttribs;
     86    return renderspu_SystemInitVisual(pVisInfo);
     87}
    8288
    8389/*
     
    117123    /* create a new visual */
    118124    i = render_spu.numVisuals;
    119     render_spu.visuals[i].displayName = crStrdup(displayName);
    120     render_spu.visuals[i].visAttribs = visAttribs;
    121     if (renderspu_SystemInitVisual(&(render_spu.visuals[i]))) {
     125    if (renderspuInitVisual(&(render_spu.visuals[i]), displayName, visAttribs)) {
    122126        render_spu.numVisuals++;
    123127        return &(render_spu.visuals[i]);
     
    315319}
    316320
    317 
    318 /*
    319  * Window functions
    320  */
    321 
    322 GLint renderspuWindowCreateEx( const char *dpyName, GLint visBits, GLint id )
    323 {
    324     WindowInfo *window;
    325     VisualInfo *visual;
    326     GLboolean showIt;
    327 
    328     if (id <= 0)
    329     {
    330         id = (GLint)crHashtableAllocKeys(render_spu.windowTable, 1);
    331         if (id <= 0)
    332         {
    333             crWarning("failed to allocate window id");
    334             return -1;
    335         }
    336     }
    337     else
    338     {
    339         if (crHashtableIsKeyUsed(render_spu.windowTable, id))
    340         {
    341             crWarning("the specified window key %d is in use", id);
    342             return -1;
    343         }
    344     }
    345 
    346 
    347     if (!dpyName || crStrlen(render_spu.display_string) > 0)
    348         dpyName = render_spu.display_string;
    349 
    350     visual = renderspuFindVisual( dpyName, visBits );
    351     if (!visual)
    352     {
    353         crWarning( "Render SPU: Couldn't create a window, renderspuFindVisual returned NULL" );
    354         return -1;
    355     }
    356 
    357     /* Allocate WindowInfo */
    358     window = (WindowInfo *) crCalloc(sizeof(WindowInfo));
    359     if (!window)
    360     {
    361         crWarning( "Render SPU: Couldn't create a window" );
    362         return -1;
    363     }
    364 
     321GLboolean renderspuWindowInit( WindowInfo *window, VisualInfo *visual, GLboolean showIt, GLint id )
     322{
    365323    RTCritSectInit(&window->CompositorLock);
    366324    window->pCompositor = NULL;
    367325
    368     crHashtableAdd(render_spu.windowTable, id, window);
    369326    window->BltInfo.Base.id = id;
    370327
     
    373330    window->BltInfo.width  = render_spu.defaultWidth;
    374331    window->BltInfo.height = render_spu.defaultHeight;
    375 
    376     if (render_spu.force_hidden_wdn_create
    377             || ((render_spu.render_to_app_window || render_spu.render_to_crut_window) && !crGetenv("CRNEWSERVER")))
    378         showIt = 0;
    379     else
    380         showIt = window->BltInfo.Base.id != CR_RENDER_DEFAULT_WINDOW_ID;
    381332
    382333    /* Set window->title, replacing %i with the window ID number */
     
    399350        }
    400351    }
    401 
     352       
     353    window->BltInfo.Base.visualBits = visual->visAttribs;
     354   
     355   
    402356    /*
    403357    crDebug("Render SPU: Creating window (visBits=0x%x, id=%d)", visBits, window->BltInfo.Base.id);
     
    406360    if (!renderspu_SystemVBoxCreateWindow( visual, showIt, window ))
    407361    {
     362        crWarning( "Render SPU: Couldn't create a window, renderspu_SystemCreateWindow failed" );
     363        return GL_FALSE;
     364    }
     365
     366    CRASSERT(window->visual == visual);
     367    return GL_TRUE;
     368}
     369
     370/*
     371 * Window functions
     372 */
     373
     374GLint renderspuWindowCreateEx( const char *dpyName, GLint visBits, GLint id )
     375{
     376    WindowInfo *window;
     377    VisualInfo *visual;
     378    GLboolean showIt;
     379
     380    if (id <= 0)
     381    {
     382        id = (GLint)crHashtableAllocKeys(render_spu.windowTable, 1);
     383        if (id <= 0)
     384        {
     385            crWarning("failed to allocate window id");
     386            return -1;
     387        }
     388    }
     389    else
     390    {
     391        if (crHashtableIsKeyUsed(render_spu.windowTable, id))
     392        {
     393            crWarning("the specified window key %d is in use", id);
     394            return -1;
     395        }
     396    }
     397
     398
     399    if (!dpyName || crStrlen(render_spu.display_string) > 0)
     400        dpyName = render_spu.display_string;
     401
     402    visual = renderspuFindVisual( dpyName, visBits );
     403    if (!visual)
     404    {
     405        crWarning( "Render SPU: Couldn't create a window, renderspuFindVisual returned NULL" );
     406        return -1;
     407    }
     408
     409    /* Allocate WindowInfo */
     410    window = (WindowInfo *) crCalloc(sizeof(WindowInfo));
     411    if (!window)
     412    {
     413        crWarning( "Render SPU: Couldn't create a window" );
     414        return -1;
     415    }
     416   
     417    crHashtableAdd(render_spu.windowTable, id, window);
     418
     419    if (render_spu.force_hidden_wdn_create
     420            || ((render_spu.render_to_app_window || render_spu.render_to_crut_window) && !crGetenv("CRNEWSERVER")))
     421        showIt = 0;
     422    else
     423        showIt = window->BltInfo.Base.id != CR_RENDER_DEFAULT_WINDOW_ID;
     424
     425
     426    /*
     427    crDebug("Render SPU: Creating window (visBits=0x%x, id=%d)", visBits, window->BltInfo.Base.id);
     428    */
     429    /* Have GLX/WGL/AGL create the window */
     430    if (!renderspuWindowInit( window, visual, showIt, id ))
     431    {
    408432        crFree(window);
    409433        crWarning( "Render SPU: Couldn't create a window, renderspu_SystemCreateWindow failed" );
    410434        return -1;
    411435    }
    412 
    413     CRASSERT(window->visual == visual);
    414 
    415     window->BltInfo.Base.visualBits = visual->visAttribs;
    416 
     436   
    417437    return window->BltInfo.Base.id;
    418438}
     
    437457}
    438458
     459void renderspuWindowTerm( WindowInfo *window )
     460{
     461    GET_CONTEXT(pOldCtx);
     462    /* ensure no concurrent draws can take place */
     463    renderspuVBoxCompositorSet(window, NULL);
     464    renderspu_SystemDestroyWindow( window );
     465    RTCritSectDelete(&window->CompositorLock);
     466    /* check if this window is bound to some ctx. Note: window pointer is already freed here */
     467    crHashtableWalk(render_spu.contextTable, renderspuCheckCurrentCtxWindowCB, window);
     468    /* restore current context */
     469    {
     470        GET_CONTEXT(pNewCtx);
     471        if (pNewCtx!=pOldCtx)
     472        {
     473            renderspuMakeCurrent(pOldCtx&&pOldCtx->currentWindow ? pOldCtx->currentWindow->BltInfo.Base.id:CR_RENDER_DEFAULT_WINDOW_ID, 0,
     474                                     pOldCtx ? pOldCtx->BltInfo.Base.id:CR_RENDER_DEFAULT_CONTEXT_ID);
     475        }
     476    }
     477}
     478
    439479void
    440480RENDER_APIENTRY renderspuWindowDestroy( GLint win )
    441481{
    442482    WindowInfo *window;
    443     GET_CONTEXT(pOldCtx);
    444483
    445484    CRASSERT(win >= 0);
     
    452491    if (window) {
    453492        crDebug("Render SPU: Destroy window (%d)", win);
    454         renderspu_SystemDestroyWindow( window );
    455 
    456         RTCritSectDelete(&window->CompositorLock);
    457         window->pCompositor = NULL;
     493        renderspuWindowTerm( window );
    458494
    459495        /* remove window info from hash table, and free it */
    460496        crHashtableDelete(render_spu.windowTable, win, crFree);
    461497
    462         /* check if this window is bound to some ctx. Note: window pointer is already freed here */
    463         crHashtableWalk(render_spu.contextTable, renderspuCheckCurrentCtxWindowCB, window);
    464 
    465         /* restore current context */
    466         {
    467             GET_CONTEXT(pNewCtx);
    468             if (pNewCtx!=pOldCtx)
    469             {
    470                 renderspuMakeCurrent(pOldCtx&&pOldCtx->currentWindow ? pOldCtx->currentWindow->BltInfo.Base.id:CR_RENDER_DEFAULT_WINDOW_ID, 0,
    471                                      pOldCtx ? pOldCtx->BltInfo.Base.id:CR_RENDER_DEFAULT_CONTEXT_ID);
    472             }
    473         }
    474498    }
    475499    else {
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