VirtualBox

Changeset 41057 in vbox


Ignore:
Timestamp:
Apr 25, 2012 7:34:43 PM (13 years ago)
Author:
vboxsync
Message:

crOpenGL: fix gl resource leaking (server part)

Location:
trunk/src/VBox/GuestHost/OpenGL
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_bits.h

    r15532 r41057  
    6565}
    6666
     67static INLINE int CHECKBIT( const unsigned int *b, const unsigned int bit )
     68{
     69    unsigned int node32 = bit >> 5;
     70    unsigned int node = bit & 0x1f;
     71
     72    return !!(b[node32] & (1 < node));
     73}
     74
     75static INLINE void CLEARBIT( unsigned int *b, const unsigned int bit )
     76{
     77    unsigned int node32 = bit >> 5;
     78    unsigned int node = bit & 0x1f;
     79
     80    b[node32] &=  ~(1 << node);
     81}
     82
     83static INLINE void SETBIT( unsigned int *b, const unsigned int bit )
     84{
     85    unsigned int node32 = bit >> 5;
     86    unsigned int node = bit & 0x1f;
     87
     88    b[node32] |=  (1 << node);
     89}
     90
     91static INLINE int HASBITS( const unsigned int *b )
     92{
     93    int j;
     94
     95    for (j=0;j<CR_MAX_BITARRAY;j++)
     96        if (b[j])
     97            return 1;
     98
     99    return 0;
     100}
     101
     102static INLINE void CLEARBITS( unsigned int *b )
     103{
     104    int j;
     105
     106    for (j=0;j<CR_MAX_BITARRAY;j++)
     107        b[j] = 0;
     108}
     109
     110
    67111#ifdef __cplusplus
    68112}
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h

    r40691 r41057  
    116116} CRSharedState;
    117117
     118#define CR_STATE_SHAREDOBJ_USAGE_INIT(_pObj) (CLEARBITS((_pObj)->ctxUsage))
     119#define CR_STATE_SHAREDOBJ_USAGE_SET(_pObj, _pCtx) (SETBIT((_pObj)->ctxUsage, (_pCtx)->id))
     120#define CR_STATE_SHAREDOBJ_USAGE_CLEAR(_pObj, _pCtx) (CLEARBIT((_pObj)->ctxUsage, (_pCtx)->id))
     121#define CR_STATE_SHAREDOBJ_USAGE_IS_USED(_pObj) (HASBITS((_pObj)->ctxUsage))
    118122
    119123/**
     
    231235typedef FNCRSTATE_CONTEXT_GET *PFNCRSTATE_CONTEXT_GET;
    232236DECLEXPORT(int32_t) crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM);
    233 DECLEXPORT(void)    crStateFreeShared(CRSharedState *s);
     237DECLEXPORT(void)    crStateFreeShared(CRContext *pContext, CRSharedState *s);
    234238#endif
    235239
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_server.h

    r40691 r41057  
    3131#endif
    3232
    33 #define SHCROGL_SSM_VERSION 28
     33#define SHCROGL_SSM_VERSION 29
    3434
    3535#define CR_MAX_WINDOWS 100
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_bufferobject.h

    r34107 r41057  
    4242        CRbitvalue dirty[CR_MAX_BITARRAY];  /* dirty data or state */
    4343        GLintptrARB dirtyStart, dirtyLength; /* dirty region */
     44#ifndef IN_GUEST
     45    /* bitfield representing the object usage. 1 means the object is used by the context with the given bitid */
     46    CRbitvalue             ctxUsage[CR_MAX_BITARRAY];
     47#endif
    4448} CRBufferObject;
    4549
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_framebuffer.h

    r39815 r41057  
    4949#ifdef IN_GUEST
    5050    GLenum                  status;
     51#else
     52    /* bitfield representing the object usage. 1 means the object is used by the context with the given bitid */
     53    CRbitvalue             ctxUsage[CR_MAX_BITARRAY];
    5154#endif
    5255} CRFramebufferObject;
     
    5760    GLenum   internalformat;
    5861    GLuint   redBits, greenBits, blueBits, alphaBits, depthBits, stencilBits;
     62#ifndef IN_GUEST
     63    /* bitfield representing the object usage. 1 means the object is used by the context with the given bitid */
     64    CRbitvalue             ctxUsage[CR_MAX_BITARRAY];
     65#endif
    5966} CRRenderbufferObject;
    6067
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_texture.h

    r34107 r41057  
    9797    CRbitvalue             imageBit[CR_MAX_BITARRAY];
    9898    CRbitvalue             paramsBit[CR_MAX_TEXTURE_UNITS][CR_MAX_BITARRAY];
     99#ifndef IN_GUEST
     100    /* bitfield representing the object usage. 1 means the object is used by the context with the given bitid */
     101    CRbitvalue             ctxUsage[CR_MAX_BITARRAY];
     102#endif
    99103} CRTextureObj;
    100104
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_bufferobject.c

    r38394 r41057  
    2323        b->access = GL_READ_WRITE_ARB;
    2424        b->bResyncOnRead = GL_FALSE;
     25#ifndef IN_GUEST
     26        CR_STATE_SHAREDOBJ_USAGE_INIT(b);
     27#endif
    2528    }
    2629    return b;
     
    189192            crHashtableAdd( g->shared->buffersTable, buffer, newObj );
    190193        }
     194
     195#ifndef IN_GUEST
     196        CR_STATE_SHAREDOBJ_USAGE_SET(newObj, g);
     197#endif
    191198    }
    192199
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_framebuffer.c

    r39834 r41057  
    9898            fbo->renderbuffer->internalformat = GL_RGBA;
    9999            crHashtableAdd(g->shared->rbTable, renderbuffer, fbo->renderbuffer);
    100         }
     100#ifndef IN_GUEST
     101        CR_STATE_SHAREDOBJ_USAGE_INIT(fbo->renderbuffer);
     102#endif
     103        }
     104#ifndef IN_GUEST
     105        CR_STATE_SHAREDOBJ_USAGE_SET(fbo->renderbuffer, g);
     106#endif
     107
    101108    }
    102109    else fbo->renderbuffer = NULL;
     
    295302            crStateInitFrameBuffer(pFBO);
    296303            crHashtableAdd(g->shared->fbTable, framebuffer, pFBO);
    297         }
     304#ifndef IN_GUEST
     305            CR_STATE_SHAREDOBJ_USAGE_INIT(pFBO);
     306#endif
     307        }
     308
     309#ifndef IN_GUEST
     310        CR_STATE_SHAREDOBJ_USAGE_SET(pFBO, g);
     311#endif
    298312    }
    299313
     
    458472    CRSTATE_FBO_CHECKERR(textarget!=GL_TEXTURE_1D, GL_INVALID_OPERATION, "textarget");
    459473
     474#ifndef IN_GUEST
     475    CR_STATE_SHAREDOBJ_USAGE_SET(tobj, g);
     476#endif
     477
    460478    crStateInitFBOAttachmentPoint(ap);
    461479    ap->type = GL_TEXTURE;
     
    483501
    484502    CRSTATE_FBO_CHECKERR(GL_TEXTURE_1D==textarget || GL_TEXTURE_3D==textarget, GL_INVALID_OPERATION, "textarget");
     503
     504#ifndef IN_GUEST
     505    CR_STATE_SHAREDOBJ_USAGE_SET(tobj, g);
     506#endif
    485507
    486508    crStateInitFBOAttachmentPoint(ap);
     
    514536    CRSTATE_FBO_CHECKERR(zoffset>(g->limits.max3DTextureSize-1), GL_INVALID_VALUE, "zoffset too big");
    515537    CRSTATE_FBO_CHECKERR(textarget!=GL_TEXTURE_3D, GL_INVALID_OPERATION, "textarget");
     538
     539#ifndef IN_GUEST
     540    CR_STATE_SHAREDOBJ_USAGE_SET(tobj, g);
     541#endif
    516542
    517543    crStateInitFBOAttachmentPoint(ap);
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_init.c

    r40691 r41057  
    6161}
    6262
     63#ifndef IN_GUEST
     64typedef struct CR_STATE_RELEASEOBJ
     65{
     66    CRContext *pCtx;
     67    CRSharedState *s;
     68} CR_STATE_RELEASEOBJ, *PCR_STATE_RELEASEOBJ;
     69
     70static void ReleaseTextureCallback(unsigned long key, void *data1, void *data2)
     71{
     72    PCR_STATE_RELEASEOBJ pData = (PCR_STATE_RELEASEOBJ)data2;
     73    CRTextureObj *pObj = (CRTextureObj *)data1;
     74    CR_STATE_SHAREDOBJ_USAGE_CLEAR(pObj, pData->pCtx);
     75    if (!CR_STATE_SHAREDOBJ_USAGE_IS_USED(pObj))
     76        crHashtableDelete(pData->s->textureTable, key, DeleteTextureCallback);
     77}
     78
     79static void ReleaseBufferObjectCallback(unsigned long key, void *data1, void *data2)
     80{
     81    PCR_STATE_RELEASEOBJ pData = (PCR_STATE_RELEASEOBJ)data2;
     82    CRBufferObject *pObj = (CRBufferObject *)data1;
     83    CR_STATE_SHAREDOBJ_USAGE_CLEAR(pObj, pData->pCtx);
     84    if (!CR_STATE_SHAREDOBJ_USAGE_IS_USED(pObj))
     85        crHashtableDelete(pData->s->buffersTable, key, crStateFreeBufferObject);
     86}
     87
     88static void ReleaseFBOCallback(unsigned long key, void *data1, void *data2)
     89{
     90    PCR_STATE_RELEASEOBJ pData = (PCR_STATE_RELEASEOBJ)data2;
     91    CRFramebufferObject *pObj = (CRFramebufferObject *)data1;
     92    CR_STATE_SHAREDOBJ_USAGE_CLEAR(pObj, pData->pCtx);
     93    if (!CR_STATE_SHAREDOBJ_USAGE_IS_USED(pObj))
     94        crHashtableDelete(pData->s->fbTable, key, crStateFreeFBO);
     95}
     96
     97static void ReleaseRBOCallback(unsigned long key, void *data1, void *data2)
     98{
     99    PCR_STATE_RELEASEOBJ pData = (PCR_STATE_RELEASEOBJ)data2;
     100    CRRenderbufferObject *pObj = (CRRenderbufferObject *)data1;
     101    CR_STATE_SHAREDOBJ_USAGE_CLEAR(pObj, pData->pCtx);
     102    if (!CR_STATE_SHAREDOBJ_USAGE_IS_USED(pObj))
     103        crHashtableDelete(pData->s->rbTable, key, crStateFreeRBO);
     104}
     105#endif
    63106/**
    64107 * Decrement shared state's refcount and delete when it hits zero.
    65108 */
    66109DECLEXPORT(void)
    67 crStateFreeShared(CRSharedState *s)
     110crStateFreeShared(CRContext *pContext, CRSharedState *s)
    68111{
    69112    s->refCount--;
     
    80123        crFree(s);
    81124    }
     125#ifndef IN_GUEST
     126    else
     127    {
     128        /* evaluate usage bits*/
     129        CR_STATE_RELEASEOBJ CbData;
     130        CbData.pCtx = pContext;
     131        CbData.s = s;
     132        crHashtableWalk(s->textureTable, ReleaseTextureCallback, &CbData);
     133        crHashtableWalk(s->buffersTable, ReleaseBufferObjectCallback , &CbData);
     134        crHashtableWalk(s->fbTable, ReleaseFBOCallback, &CbData);
     135        crHashtableWalk(s->rbTable, ReleaseRBOCallback, &CbData);
     136    }
     137#endif
    82138}
    83139
     
    103159        else
    104160        {
    105             crStateFreeShared(pCtx->shared);
     161            crStateFreeShared(pCtx, pCtx->shared);
    106162            pCtx->shared = gSharedState;
    107163            gSharedState->refCount++;
     
    125181            pCtx->shared = crStateAllocShared();
    126182            pCtx->shared->id = pCtx->id;
    127             crStateFreeShared(gSharedState);
     183            crStateFreeShared(pCtx, gSharedState);
    128184        }
    129185    }
     
    285341    crStateTextureDestroy( ctx );
    286342    crStateTransformDestroy( ctx );
    287     crStateFreeShared(ctx->shared);
     343    crStateFreeShared(ctx, ctx->shared);
    288344    crStateFramebufferObjectDestroy(ctx);
    289345    crStateGLSLDestroy(ctx);
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_snapshot.c

    r40691 r41057  
    14981498            CRASSERT(pContext->shared->refCount==1);
    14991499            bLoadShared = GL_FALSE;
    1500             crStateFreeShared(pContext->shared);
     1500            crStateFreeShared(pContext, pContext->shared);
    15011501            pContext->shared = NULL;
    15021502            pTmpContext->shared->refCount++;
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_texture.c

    r40124 r41057  
    250250        RESET(tobj->paramsBit[i], ctx->bitid);
    251251    }
     252
     253#ifndef IN_GUEST
     254    CR_STATE_SHAREDOBJ_USAGE_INIT(tobj);
     255    CR_STATE_SHAREDOBJ_USAGE_SET(tobj, ctx);
     256#endif
    252257}
    253258
     
    901906        tobj = crStateTextureAllocate_t(g, texture);
    902907    }
     908
     909#ifndef IN_GUEST
     910    CR_STATE_SHAREDOBJ_USAGE_SET(tobj, g);
     911#endif
    903912
    904913    /* Check the targets */
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