VirtualBox

Changeset 42518 in vbox


Ignore:
Timestamp:
Aug 1, 2012 4:54:38 PM (12 years ago)
Author:
vboxsync
Message:

crOpenGL/wddm: context-connection and other fixes

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/VBoxVideo3D.h

    r39847 r42518  
    111111#define VBoxTlsRefGetCurrent(_t, _Tsd) ((_t*) VBoxTlsRefGetImpl((_Tsd)))
    112112
     113#define VBoxTlsRefGetCurrentFunctional(_val, _t, _Tsd) do { \
     114       _t * cur = VBoxTlsRefGetCurrent(_t, _Tsd); \
     115       if (!cur || VBoxTlsRefIsFunctional(cur)) { \
     116           (_val) = cur; \
     117       } else { \
     118           VBoxTlsRefSetCurrent(_t, _Tsd, NULL); \
     119           (_val) = NULL; \
     120       } \
     121   } while (0)
     122
    113123#define VBoxTlsRefSetCurrent(_t, _Tsd, _p) do { \
    114124        _t * oldCur = VBoxTlsRefGetCurrent(_t, _Tsd); \
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp

    r42501 r42518  
    66216621    if (VBOXDISPMODE_IS_3D(pAdapter))
    66226622    {
    6623 //    Assert(!pDevice->cScreens);
    6624         /* destroy the device first, since destroying PVBOXWDDMDISP_SWAPCHAIN would result in a device window termination */
     6623        vboxWddmSwapchainDestroyAll(pDevice);
     6624        /* ensure the device is destroyed in any way.
     6625         * Release may not work in case of some leaking, which will leave the crOgl context refering the destroyed VBOXUHGSMI */
    66256626        if (pDevice->pDevice9If)
    6626         {
    6627             pDevice->pDevice9If->Release();
    6628         }
    6629         vboxWddmSwapchainDestroyAll(pDevice);
     6627            pDevice->pAdapter->D3D.pfnVBoxWineExD3DDev9Term((IDirect3DDevice9Ex *)pDevice->pDevice9If);
    66306628    }
    66316629
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp

    r42285 r42518  
    8080        }
    8181
     82        pD3D->pfnVBoxWineExD3DDev9Term = (PFNVBOXWINEEXD3DDEV9_TERM)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Term");
     83        if (!pD3D->pfnVBoxWineExD3DDev9Term)
     84        {
     85            WARN(("no VBoxWineExD3DDev9Term"));
     86            break;
     87        }
     88
    8289        pD3D->pfnVBoxWineExD3DRc9SetShRcState = (PFNVBOXWINEEXD3DRC9_SETSHRCSTATE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DRc9SetShRcState");
    8390        if (!pD3D->pfnVBoxWineExD3DRc9SetShRcState)
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.h

    r41637 r42518  
    6363    PFNVBOXWINEEXD3DDEV9_UPDATE pfnVBoxWineExD3DDev9Update;
    6464
     65    PFNVBOXWINEEXD3DDEV9_TERM pfnVBoxWineExD3DDev9Term;
     66
    6567    PFNVBOXWINEEXD3DRC9_SETSHRCSTATE pfnVBoxWineExD3DRc9SetShRcState;
    6668
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9wddm.def

    r40388 r42518  
    1616  VBoxWineExD3DDev9CreateCubeTexture
    1717  VBoxWineExD3DDev9Update
     18  VBoxWineExD3DDev9Term
    1819  VBoxWineExD3DSwapchain9Present
    1920  VBoxWineExD3DRc9SetShRcState
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c

    r42499 r42518  
    260260}
    261261
     262static ULONG IDirect3DDevice9Impl_Term(IDirect3DDevice9Impl *This)
     263{
     264    ULONG wined3dDevRefs = 0;
     265    unsigned i;
     266    This->inDestruction = TRUE;
     267
     268    wined3d_mutex_lock();
     269    for(i = 0; i < This->numConvertedDecls; i++) {
     270        /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
     271         * device
     272         */
     273        IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
     274    }
     275    HeapFree(GetProcessHeap(), 0, This->convertedDecls);
     276
     277    IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroySwapChain);
     278#ifndef VBOX_WITH_WDDM
     279    IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
     280#endif
     281    wined3dDevRefs = IWineD3DDevice_Release(This->WineD3DDevice);
     282    wined3d_mutex_unlock();
     283
     284    HeapFree(GetProcessHeap(), 0, This);
     285    return wined3dDevRefs;
     286}
     287
    262288static ULONG WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
    263289    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     
    270296
    271297    if (ref == 0) {
    272       unsigned i;
    273       This->inDestruction = TRUE;
    274 
    275       wined3d_mutex_lock();
    276       for(i = 0; i < This->numConvertedDecls; i++) {
    277           /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
    278            * device
    279            */
    280           IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
    281       }
    282       HeapFree(GetProcessHeap(), 0, This->convertedDecls);
    283 
    284       IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroySwapChain);
    285 #ifndef VBOX_WITH_WDDM
    286       IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
    287 #endif
    288       IWineD3DDevice_Release(This->WineD3DDevice);
    289       wined3d_mutex_unlock();
    290 
    291       HeapFree(GetProcessHeap(), 0, This);
     298        IDirect3DDevice9Impl_Term(This);
    292299    }
    293300    return ref;
     
    822829    IDirect3DDevice9_AddRef(iface);
    823830    *outIface = iface;
     831    return D3D_OK;
     832}
     833
     834VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9Term(IDirect3DDevice9Ex *iface)
     835{
     836    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     837    IWineD3DDevice *WineD3DDevice = This->WineD3DDevice;
     838    ULONG wined3dRefs;
     839    if (This->ref != 1)
     840    {
     841        ERR("unexpected ref count %d, destroying in anyway", This->ref);
     842    }
     843    wined3dRefs = IDirect3DDevice9Impl_Term(This);
     844    if (wined3dRefs)
     845    {
     846        ERR("unexpected wined3dRefs %d, destroying in anyway", wined3dRefs);
     847        while (IWineD3DDevice_Release(WineD3DDevice)) {}
     848    }
    824849    return D3D_OK;
    825850}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/VBoxWineEx.h

    r42499 r42518  
    5353typedef FNVBOXWINEEXD3DDEV9_UPDATE *PFNVBOXWINEEXD3DDEV9_UPDATE;
    5454
     55typedef VBOXWINEEX_DECL(HRESULT) FNVBOXWINEEXD3DDEV9_TERM(IDirect3DDevice9Ex *iface);
     56typedef FNVBOXWINEEXD3DDEV9_TERM *PFNVBOXWINEEXD3DDEV9_TERM;
     57
    5558typedef VBOXWINEEX_DECL(HRESULT) FNVBOXWINEEXD3DRC9_SETSHRCSTATE(IDirect3DResource9 *iface, VBOXWINEEX_SHRC_STATE enmState);
    5659typedef FNVBOXWINEEXD3DRC9_SETSHRCSTATE *PFNVBOXWINEEXD3DRC9_SETSHRCSTATE;
     
    8083                                                    IDirect3DDevice9Ex **outIface); /* update device parameters */
    8184
     85VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9Term(IDirect3DDevice9Ex *iface);
     86
    8287VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DRc9SetShRcState(IDirect3DResource9 *iface, VBOXWINEEX_SHRC_STATE enmState);
    8388
  • trunk/src/VBox/Additions/common/crOpenGL/context.c

    r42499 r42518  
    8888}
    8989
     90void stubForcedFlush(GLint con)
     91{
     92#if 0
     93    GLint buffer;
     94    stub.spu->dispatch_table.GetIntegerv(GL_DRAW_BUFFER, &buffer);
     95    stub.spu->dispatch_table.DrawBuffer(GL_FRONT);
     96    stub.spu->dispatch_table.Flush();
     97    stub.spu->dispatch_table.DrawBuffer(buffer);
     98#else
     99    if (con)
     100    {
     101        stub.spu->dispatch_table.VBoxConFlush(con);
     102    }
     103    else
     104    {
     105        stub.spu->dispatch_table.Flush();
     106    }
     107#endif
     108}
     109
     110static void stubWindowCleanupForContextsCB(unsigned long key, void *data1, void *data2)
     111{
     112    ContextInfo *context = (ContextInfo *) data1;
     113
     114    CRASSERT(context);
     115
     116    if (context->currentDrawable == data2)
     117        context->currentDrawable = NULL;
     118}
     119
     120void stubDestroyWindow( GLint con, GLint window )
     121{
     122    WindowInfo *winInfo = (WindowInfo *)
     123        crHashtableSearch(stub.windowTable, (unsigned int) window);
     124    if (winInfo && winInfo->type == CHROMIUM && stub.spu)
     125    {
     126        crHashtableLock(stub.windowTable);
     127
     128        stub.spu->dispatch_table.VBoxWindowDestroy(con, winInfo->spuWindow );
     129
     130#ifdef WINDOWS
     131        if (winInfo->hVisibleRegion != INVALID_HANDLE_VALUE)
     132        {
     133            DeleteObject(winInfo->hVisibleRegion);
     134        }
     135#elif defined(GLX)
     136        if (winInfo->pVisibleRegions)
     137        {
     138            XFree(winInfo->pVisibleRegions);
     139        }
     140# ifdef CR_NEWWINTRACK
     141        if (winInfo->syncDpy)
     142        {
     143            XCloseDisplay(winInfo->syncDpy);
     144        }
     145# endif
     146#endif
     147        stubForcedFlush(con);
     148
     149        crHashtableWalk(stub.contextTable, stubWindowCleanupForContextsCB, winInfo);
     150
     151        crHashtableDelete(stub.windowTable, window, crFree);
     152
     153        crHashtableUnlock(stub.windowTable);
     154    }
     155}
    90156
    91157/**
     
    333399
    334400static void
     401stubContextFree( ContextInfo *context )
     402{
     403    crMemZero(context, sizeof(ContextInfo));  /* just to be safe */
     404    crFree(context);
     405}
     406
     407static void
    335408stubDestroyContextLocked( ContextInfo *context )
    336409{
     
    367440#endif
    368441
    369     crMemZero(context, sizeof(ContextInfo));  /* just to be safe */
    370     crHashtableDelete(stub.contextTable, contextId, crFree);
     442    crHashtableDelete(stub.contextTable, contextId, NULL);
    371443}
    372444
     
    374446static DECLCALLBACK(void) stubContextDtor(void*pvContext)
    375447{
    376     crHashtableLock(stub.windowTable);
    377     crHashtableLock(stub.contextTable);
    378     stubDestroyContextLocked((ContextInfo*)pvContext);
    379     crHashtableUnlock(stub.contextTable);
    380     crHashtableUnlock(stub.windowTable);
     448    stubContextFree((ContextInfo*)pvContext);
    381449}
    382450#endif
     
    10151083               could be destroyed.
    10161084             */
    1017             crWindowDestroy((GLint)pWindow->hWnd);
     1085            stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->hWnd);
    10181086#else
    1019             crWindowDestroy((GLint)pWindow->drawable);
     1087            stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->drawable);
    10201088#endif
    10211089    }
     
    11671235                        if (context->currentDrawable->hWnd!=WindowFromDC(context->currentDrawable->drawable))
    11681236                        {
    1169                             crWindowDestroy((GLint)context->currentDrawable->hWnd);
     1237                            stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->hWnd);
    11701238                        }
    11711239#else
     
    11771245                        if (!XGetGeometry(context->currentDrawable->dpy, context->currentDrawable->drawable, &root, &x, &y, &w, &h, &border, &depth))
    11781246                        {
    1179                             crWindowDestroy((GLint)context->currentDrawable->drawable);
     1247                            stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->drawable);
    11801248                        }
    11811249                        XUNLOCK(context->currentDrawable->dpy);
     
    11961264    window->type = context->type;
    11971265    window->pOwner = context;
    1198 #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
    1199     window->spuConnection = context->spuConnection;
    1200 #endif
    12011266    context->currentDrawable = window;
    12021267    stubSetCurrentContext(context);
     
    12861351    CRASSERT(context);
    12871352
     1353    CRASSERT(0);
     1354    stubDestroyContextLocked(context);
     1355
    12881356#ifdef CHROMIUM_THREADSAFE
    12891357    if (stubGetCurrentContext() == context) {
     
    12911359    }
    12921360
     1361    VBoxTlsRefMarkDestroy(context);
    12931362    VBoxTlsRefRelease(context);
    12941363#else
    1295     stubDestroyContextLocked(context);
    1296 
    12971364    if (stubGetCurrentContext() == context) {
    12981365        stubSetCurrentContext(NULL);
    12991366    }
     1367    stubContextFree(context);
    13001368#endif
    13011369    crHashtableUnlock(stub.contextTable);
  • trunk/src/VBox/Additions/common/crOpenGL/load.c

    r42499 r42518  
    190190    {
    191191#ifdef WINDOWS
    192         crWindowDestroy((GLint)pWindow->hWnd);
     192        stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->hWnd);
    193193#else
    194         crWindowDestroy((GLint)pWindow->drawable);
     194        stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->drawable);
    195195#endif
    196196        return;
     
    843843    if (!stubSystemWindowExist(pWindow))
    844844    {
    845         crWindowDestroy((GLint)pWindow->hWnd);
     845        stubDestroyWindow(0, (GLint)pWindow->hWnd);
    846846        return;
    847847    }
     
    991991    {
    992992#ifdef WINDOWS
    993         crWindowDestroy((GLint)pWindow->hWnd);
     993        stubDestroyWindow(0, (GLint)pWindow->hWnd);
    994994#else
    995         crWindowDestroy((GLint)pWindow->drawable);
     995        stubDestroyWindow(0, (GLint)pWindow->drawable);
    996996#endif
    997997        /*No need to flush here as crWindowDestroy does it*/
  • trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c

    r42499 r42518  
    160160    if (CRPACKSPU_IS_WDDM_CRHGSMI())
    161161    {
    162         ThreadInfo *thread;
    163         CRPackContext * curPacker = crPackGetContext();
    164         if (!con)
    165         {
    166             crError("connection expected!!");
     162        GET_THREAD(thread);
     163        if (con)
     164        {
     165            CRPackContext * curPacker = crPackGetContext();
     166            CRASSERT(!thread || !thread->bInjectThread);
     167            thread = GET_THREAD_VAL_ID(con);
     168            crPackSetContext(thread->packer);
     169            crPackWindowDestroy(window);
     170            if (curPacker != thread->packer)
     171                crPackSetContext(curPacker);
    167172            return;
    168173        }
    169         thread = GET_THREAD_VAL_ID(con);
    170         crPackSetContext(thread->packer);
    171         crPackWindowDestroy(window);
    172         if (curPacker != thread->packer)
    173             crPackSetContext(curPacker);
    174         return;
     174        CRASSERT(thread);
     175        CRASSERT(thread->bInjectThread);
    175176    }
    176177    crPackWindowDestroy(window);
  • trunk/src/VBox/Additions/common/crOpenGL/stub.c

    r42500 r42518  
    1010#include "stub.h"
    1111#include <iprt/thread.h>
    12 
    13 static void crForcedFlush(
    14 #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
    15         GLint con
    16 #endif
    17         )
    18 {
    19 #if 0
    20     GLint buffer;
    21     stub.spu->dispatch_table.GetIntegerv(GL_DRAW_BUFFER, &buffer);
    22     stub.spu->dispatch_table.DrawBuffer(GL_FRONT);
    23     stub.spu->dispatch_table.Flush();
    24     stub.spu->dispatch_table.DrawBuffer(buffer);
    25 #else
    26 #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
    27     if (con)
    28     {
    29         stub.spu->dispatch_table.VBoxConFlush(con);
    30     }
    31     else
    32 #endif
    33     {
    34         stub.spu->dispatch_table.Flush();
    35     }
    36 #endif
    37 }
    3812
    3913#ifdef GLX
     
    142116}
    143117
    144 static void stubWindowCleanupForContextsCB(unsigned long key, void *data1, void *data2)
    145 {
    146     ContextInfo *context = (ContextInfo *) data1;
    147 
    148     CRASSERT(context);
    149 
    150     if (context->currentDrawable == data2)
    151         context->currentDrawable = NULL;
    152 }
    153 
    154118void APIENTRY crWindowDestroy( GLint window )
    155119{
    156     WindowInfo *winInfo = (WindowInfo *)
    157         crHashtableSearch(stub.windowTable, (unsigned int) window);
    158     if (winInfo && winInfo->type == CHROMIUM && stub.spu)
    159     {
    160         crHashtableLock(stub.windowTable);
    161 
    162         stub.spu->dispatch_table.VBoxWindowDestroy(
    163 #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
    164                 winInfo->spuConnection,
    165 #else
    166                 0,
    167 #endif
    168                 winInfo->spuWindow );
    169 
    170 #ifdef WINDOWS
    171         if (winInfo->hVisibleRegion != INVALID_HANDLE_VALUE)
    172         {
    173             DeleteObject(winInfo->hVisibleRegion);
    174         }
    175 #elif defined(GLX)
    176         if (winInfo->pVisibleRegions)
    177         {
    178             XFree(winInfo->pVisibleRegions);
    179         }
    180 # ifdef CR_NEWWINTRACK
    181         if (winInfo->syncDpy)
    182         {
    183             XCloseDisplay(winInfo->syncDpy);
    184         }
    185 # endif
    186 #endif
    187         crForcedFlush(
    188 #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
    189                 winInfo->spuConnection
    190 #endif
    191                 );
    192 
    193 #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
    194         winInfo->spuConnection = 0;
    195 #endif
    196         crHashtableWalk(stub.contextTable, stubWindowCleanupForContextsCB, winInfo);
    197 
    198         crHashtableDelete(stub.windowTable, window, crFree);
    199 
    200         crHashtableUnlock(stub.windowTable);
    201     }
     120    stubDestroyWindow( 0, window );
    202121}
    203122
     
    415334                if (stubUpdateWindowGeometry(winInfo, GL_FALSE) || changed)
    416335                {
    417                     crForcedFlush();
     336                    stubForcedFlush(0);
    418337                }
    419338                break;
     
    429348                if (stub.trackWindowVisibleRgn && stubUpdateWindowVisibileRegions(winInfo))
    430349                {
    431                     crForcedFlush();
     350                    stubForcedFlush(0);
    432351                }
    433352                break;
     
    439358                {
    440359                    crDebug("Visibility info updated due to unknown hooked message (%d)", pMsgInfo->message);
    441                     crForcedFlush();
     360                    stubForcedFlush(0);
    442361                }
    443362                break;
  • trunk/src/VBox/Additions/common/crOpenGL/stub.h

    r42499 r42518  
    170170    ContextInfo *pOwner;     /* ctx which created this window */
    171171    GLboolean mapped;
    172 #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
    173     GLint spuConnection;
    174 #endif
    175172#ifdef WINDOWS
    176173    HDC      drawable;
     
    289286extern CRtsd g_stubCurrentContextTSD;
    290287
    291 # define stubGetCurrentContext() VBoxTlsRefGetCurrent(ContextInfo, &g_stubCurrentContextTSD)
     288DECLINLINE(ContextInfo*) stubGetCurrentContext()
     289{
     290    ContextInfo* ctx;
     291    VBoxTlsRefGetCurrentFunctional(ctx, ContextInfo, &g_stubCurrentContextTSD);
     292    return ctx;
     293}
    292294# define stubSetCurrentContext(_ctx) VBoxTlsRefSetCurrent(ContextInfo, &g_stubCurrentContextTSD, _ctx)
    293295#else
     
    345347extern GLboolean stubMakeCurrent( WindowInfo *window, ContextInfo *context );
    346348extern GLint stubNewWindow( const char *dpyName, GLint visBits );
     349extern void stubDestroyWindow( GLint con, GLint window );
    347350extern void stubSwapBuffers(WindowInfo *window, GLint flags);
    348351extern void stubGetWindowGeometry(WindowInfo *win, int *x, int *y, unsigned int *w, unsigned int *h);
     
    351354extern bool stubInit(void);
    352355
     356extern void stubForcedFlush(GLint con);
    353357extern void APIENTRY stub_GetChromiumParametervCR( GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid *values );
    354358
    355359extern void APIENTRY glBoundsInfoCR(const CRrecti *, const GLbyte *, GLint, GLint);
    356360
     361#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
     362# define CR_CTX_CON(_pCtx) ((_pCtx)->spuConnection)
     363#else
     364# define CR_CTX_CON(_pCtx) (0)
     365#endif
     366
    357367#endif /* CR_STUB_H */
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