VirtualBox

Ignore:
Timestamp:
Jan 20, 2009 10:00:38 AM (16 years ago)
Author:
vboxsync
Message:

crOpenGL: fix guest app crashes with vertexarrays for multithreaded apps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Graphics/crOpenGL/array/arrayspu.c

    r16036 r16074  
    1313ArraySPU array_spu;
    1414
     15#ifdef CHROMIUM_THREADSAFE
     16CRmutex _ArrayMutex;
     17#endif
     18
    1519static void ARRAYSPU_APIENTRY arrayspu_ArrayElement( GLint index )
    1620{
    17     const CRClientState *c = &(array_spu.ctx->client);
     21    const CRClientState *c = &(crStateGetCurrent()->client);
    1822    const CRVertexArrays *array = &(c->array);
    19     const GLboolean vpEnabled = array_spu.ctx->program.vpEnabled;
     23    const GLboolean vpEnabled = crStateGetCurrent()->program.vpEnabled;
    2024    unsigned char *p;
    2125    unsigned int unit, attr;
     
    103107
    104108    /* Now do conventional arrays, unless overriden by generic arrays above */
    105     for (unit = 0 ; unit < array_spu.ctx->limits.maxTextureUnits ; unit++)
     109    for (unit = 0 ; unit < crStateGetCurrent()->limits.maxTextureUnits ; unit++)
    106110    {
    107111        if (array->t[unit].enabled && !(vpEnabled && array->a[VERT_ATTRIB_TEX0+unit].enabled))
     
    450454    GLubyte *p = (GLubyte *)indices;
    451455#ifdef CR_ARB_vertex_buffer_object
    452     CRBufferObject *elementsBuffer = array_spu.ctx->bufferobject.elementsBuffer;
     456    CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
    453457#endif
    454458
     
    622626{
    623627     if (cap == GL_VERTEX_PROGRAM_NV) {
    624             array_spu.ctx->program.vpEnabled = GL_TRUE;
     628            crStateGetCurrent()->program.vpEnabled = GL_TRUE;
    625629     }
    626630     array_spu.child.Enable(cap);
     
    631635{
    632636     if (cap == GL_VERTEX_PROGRAM_NV) {
    633             array_spu.ctx->program.vpEnabled = GL_FALSE;
     637            crStateGetCurrent()->program.vpEnabled = GL_FALSE;
    634638     }
    635639     array_spu.child.Disable(cap);
     
    754758}
    755759
     760static GLint ARRAYSPU_APIENTRY
     761arrayspu_CreateContext( const char *dpyName, GLint visual, GLint shareCtx )
     762{
     763    GLint ctx, slot;
     764
     765#ifdef CHROMIUM_THREADSAFE
     766    crLockMutex(&_ArrayMutex);
     767#endif
     768
     769    ctx = array_spu.child.CreateContext(dpyName, visual, shareCtx);
     770
     771    /* find an empty context slot */
     772    for (slot = 0; slot < array_spu.numContexts; slot++) {
     773        if (!array_spu.context[slot].clientState) {
     774            /* found empty slot */
     775            break;
     776        }
     777    }
     778    if (slot == array_spu.numContexts) {
     779        array_spu.numContexts++;
     780    }
     781
     782    array_spu.context[slot].clientState = crStateCreateContext(NULL, visual, NULL);
     783    array_spu.context[slot].clientCtx = ctx;
     784#ifdef CR_ARB_vertex_buffer_object
     785    array_spu.context[slot].clientState->bufferobject.retainBufferData = GL_TRUE;
     786#endif
     787
     788#ifdef CHROMIUM_THREADSAFE
     789    crUnlockMutex(&_ArrayMutex);
     790#endif
     791
     792    return ctx;
     793}
     794
     795static void ARRAYSPU_APIENTRY
     796arrayspu_MakeCurrent( GLint window, GLint nativeWindow, GLint ctx )
     797{
     798#ifdef CHROMIUM_THREADSAFE
     799    crLockMutex(&_ArrayMutex);
     800#endif
     801    array_spu.child.MakeCurrent(window, nativeWindow, ctx);
     802
     803    if (ctx) {
     804        int slot;
     805
     806        for (slot=0; slot<array_spu.numContexts; ++slot)
     807            if (array_spu.context[slot].clientCtx == ctx) break;
     808        CRASSERT(slot < array_spu.numContexts);
     809
     810        crStateMakeCurrent(array_spu.context[slot].clientState);
     811    }
     812    else
     813    {
     814        crStateMakeCurrent(NULL);
     815    }
     816
     817#ifdef CHROMIUM_THREADSAFE
     818    crUnlockMutex(&_ArrayMutex);
     819#endif
     820}
     821
     822static void ARRAYSPU_APIENTRY
     823arrayspu_DestroyContext( GLint ctx )
     824{
     825#ifdef CHROMIUM_THREADSAFE
     826    crLockMutex(&_ArrayMutex);
     827#endif
     828    array_spu.child.DestroyContext(ctx);
     829
     830    if (ctx) {
     831        int slot;
     832
     833        for (slot=0; slot<array_spu.numContexts; ++slot)
     834            if (array_spu.context[slot].clientCtx == ctx) break;
     835        CRASSERT(slot < array_spu.numContexts);
     836
     837        crStateDestroyContext(array_spu.context[slot].clientState);
     838
     839        array_spu.context[slot].clientState = NULL;
     840        array_spu.context[slot].clientCtx = 0;
     841    }
     842
     843#ifdef CHROMIUM_THREADSAFE
     844    crUnlockMutex(&_ArrayMutex);
     845#endif
     846}
    756847
    757848SPUNamedFunctionTable _cr_array_table[] = {
     
    793884    { "GetBufferPointervARB", (SPUGenericFunction) arrayspu_GetBufferPointervARB},
    794885    { "InterleavedArrays", (SPUGenericFunction) arrayspu_InterleavedArrays},
     886    { "CreateContext", (SPUGenericFunction) arrayspu_CreateContext},
     887    { "MakeCurrent", (SPUGenericFunction) arrayspu_MakeCurrent},
     888    { "DestroyContext", (SPUGenericFunction) arrayspu_DestroyContext},
    795889    { NULL, NULL }
    796890};
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