VirtualBox

Changeset 39602 in vbox for trunk/src/VBox/Additions/WINNT


Ignore:
Timestamp:
Dec 14, 2011 11:12:17 AM (13 years ago)
Author:
vboxsync
Message:

wine/XPDM: 1. Additional swapchain creation fixes 2. De-libwine'ize wined3d 3. Single context per swapchain 4. wine & crOgl current context sync fixes 5. Proper Get/ReleaseDC handling

Location:
trunk/src/VBox/Additions/WINNT/Graphics/Wine
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/Makefile.kmk

    r39570 r39602  
    129129    LIB_TO_DATADIR=\"\" \
    130130    BIN_TO_DATADIR=\"\"
    131 wined3d_DEFS.x86     = __i386__
    132131if "$(KBUILD_TYPE)" != "debug" || defined(VBOX_WINE_NO_DEBUG_MSGS)
    133132 wined3d_DEFS        += WINE_NO_DEBUG_MSGS
    134133endif
    135 wined3d_DEFS.amd64   += VBOX_WINE_WITHOUT_LIBWINE
    136 wined3d_INCS.x86     := $(PATH_SUB_CURRENT)/include
    137 wined3d_INCS.amd64   := vbox/libWineStub/include
     134wined3d_DEFS         += VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
     135wined3d_DEFS         += VBOX_WINE_WITHOUT_LIBWINE
     136wined3d_INCS         := vbox/libWineStub/include
    138137wined3d_SOURCES      := \
    139138    wined3d/arb_program_shader.c \
     
    171170    wined3d/volumetexture.c \
    172171    wined3d/wined3d_main.c \
     172    wined3d/vboxext.c \
     173    vbox/libWineStub/debug.c \
    173174    wined3d/wined3d.def
    174 wined3d_SOURCES.amd64 = vbox/libWineStub/debug.c
    175 wined3d_LIBS.x86      = \
    176     $(PATH_STAGE_LIB)/libWine$(VBOX_SUFF_LIB)
    177 wined3d_SDKS.amd64    = WINDDKWLH
     175wined3d_SDKS          = WINDDKWLH
    178176ifdef VBOX_WINE_WITH_IPRT
    179177wined3d_LIBS         += \
     
    191189endif
    192190wined3dwddm_INCS           = vbox/libWineStub/include
    193 wined3dwddm_INCS.x86       = $(NO_SUCH_VARIABLE)
    194 wined3dwddm_LIBS.x86       = $(NO_SUCH_VARIABLE)
    195 wined3dwddm_DEFS           = $(subst __i386__,,$(wined3d_DEFS)) VBOX_WITH_WDDM VBOX_WINE_WITHOUT_LIBWINE
    196 wined3dwddm_DEFS.x86       = $(NO_SUCH_VARIABLE)
    197 wined3dwddm_SOURCES        = $(subst wined3d.def,wined3dwddm.def,$(wined3d_SOURCES)) vbox/libWineStub/debug.c wined3d/vboxext.c vbox/VBoxDbgGl.c
    198 wined3dwddm_SOURCES.x86    = $(NO_SUCH_VARIABLE)
    199 wined3dwddm_SOURCES.amd64  = $(NO_SUCH_VARIABLE)
    200 wined3dwddm_SDKS           = WINDDKWLH
    201 wined3dwddm_SDKS.amd64     = $(NO_SUCH_VARIABLE)
    202 #VBOX_WINE_WITH_IPRT is used for debugging currently to enable Assert & stuff
    203 #ifdef VBOX_WINE_WITH_IPRT
    204 #wined3dwddm_LIBS          += \
    205                                                         $(VBOX_LIB_IPRT_GUEST_R3) \
    206                                                         $(VBOX_LIB_VBGL_R3)
    207 #wined3dwddm_DEFS          += VBOX_WINE_WITH_IPRT
    208 #endif
    209 wined3dwddm_DEFS          += VBOX_WINE_WITH_SINGLE_CONTEXT
     191wined3dwddm_DEFS           = $(subst VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT,,$(wined3d_DEFS))
     192wined3dwddm_DEFS          += VBOX_WITH_WDDM VBOX_WINE_WITH_SINGLE_CONTEXT
     193wined3dwddm_SOURCES        = $(subst wined3d.def,wined3dwddm.def,$(wined3d_SOURCES)) vbox/VBoxDbgGl.c
    210194
    211195DLLS.amd64 += wined3dwddm-x86
     
    230214    LIB_TO_DATADIR=\"\" \
    231215    BIN_TO_DATADIR=\"\"
    232 VBoxD3D8_DEFS.x86 = __i386__
    233216if "$(KBUILD_TYPE)" != "debug" || defined(VBOX_WINE_NO_DEBUG_MSGS)
    234217 VBoxD3D8_DEFS       += WINE_NO_DEBUG_MSGS
    235218endif
    236 VBoxD3D8_DEFS.amd64   += VBOX_WINE_WITHOUT_LIBWINE
    237 VBoxD3D8_INCS.x86     := $(PATH_SUB_CURRENT)/include
    238 VBoxD3D8_INCS.amd64   := vbox/libWineStub/include
    239 VBoxD3D8_SOURCES      := \
     219VBoxD3D8_DEFS        += VBOX_WINE_WITHOUT_LIBWINE
     220VBoxD3D8_INCS        := vbox/libWineStub/include
     221VBoxD3D8_SOURCES     := \
    240222    d3d8/cubetexture.c \
    241223    d3d8/d3d8_main.c \
     
    252234    d3d8/volume.c \
    253235    d3d8/volumetexture.c \
     236    vbox/libWineStub/debug.c \
    254237    d3d8/d3d8.def
    255 VBoxD3D8_LIBS.x86 = \
    256     $(PATH_STAGE_LIB)/libWine$(VBOX_SUFF_LIB)
    257 VBoxD3D8_LIBS     = \
     238VBoxD3D8_LIBS         = \
    258239    $(PATH_STAGE_LIB)/wined3d$(VBOX_SUFF_LIB)
    259 VBoxD3D8_SOURCES.amd64 = vbox/libWineStub/debug.c
    260 VBoxD3D8_SDKS.amd64    = WINDDKWLH
     240VBoxD3D8_SDKS         = WINDDKWLH
    261241ifdef VBOX_WINE_WITH_IPRT
    262242VBoxD3D8_LIBS         += \
     
    277257    LIB_TO_DATADIR=\"\" \
    278258    BIN_TO_DATADIR=\"\"
    279 VBoxD3D9_DEFS.x86 = __i386__
    280259if "$(KBUILD_TYPE)" != "debug" || defined(VBOX_WINE_NO_DEBUG_MSGS)
    281  VBoxD3D9_DEFS       += WINE_NO_DEBUG_MSGS
    282 endif
    283 VBoxD3D9_DEFS.amd64   += VBOX_WINE_WITHOUT_LIBWINE
    284 VBoxD3D9_INCS.x86     := $(PATH_SUB_CURRENT)/include
    285 VBoxD3D9_INCS.amd64   := vbox/libWineStub/include
     260 VBoxD3D9_DEFS        += WINE_NO_DEBUG_MSGS
     261endif
     262VBoxD3D9_DEFS         += VBOX_WINE_WITHOUT_LIBWINE
     263VBoxD3D9_INCS         := vbox/libWineStub/include
    286264VBoxD3D9_SOURCES      := \
    287265    d3d9/cubetexture.c \
     
    300278    d3d9/vertexshader.c \
    301279    d3d9/volume.c \
    302     d3d9/volumetexture.c
    303 
    304 VBoxD3D9_SOURCES.x86      = \
    305         d3d9/d3d9.def
    306 VBoxD3D9_SOURCES.amd64    = \
    307         vbox/libWineStub/debug.c \
    308         d3d9/d3d9xpdm.def
    309 VBoxD3D9_LIBS.x86         = \
    310     $(PATH_STAGE_LIB)/libWine$(VBOX_SUFF_LIB)
     280    d3d9/volumetexture.c \
     281    vbox/libWineStub/debug.c \
     282    d3d9/d3d9xpdm.def
    311283VBoxD3D9_LIBS             = \
    312284    $(PATH_STAGE_LIB)/wined3d$(VBOX_SUFF_LIB)
    313 VBoxD3D9_SDKS.amd64    = WINDDKWLH
     285VBoxD3D9_SDKS             = WINDDKWLH
    314286ifdef VBOX_WINE_WITH_IPRT
    315287VBoxD3D9_LIBS         += \
     
    327299endif
    328300VBoxD3D9wddm_INCS           = vbox/libWineStub/include
    329 VBoxD3D9wddm_INCS.x86       = $(NO_SUCH_VARIABLE)
    330 VBoxD3D9wddm_DEFS.x86       = $(NO_SUCH_VARIABLE)
    331 VBoxD3D9wddm_DEFS          += $(subst __i386__,,$(VBoxD3D9_DEFS)) VBOX_WITH_WDDM VBOX_WINE_WITHOUT_LIBWINE IN_VBOXWINEEX
    332 VBoxD3D9wddm_SOURCES        = $(VBoxD3D9_SOURCES) d3d9/d3d9wddm.def vbox/libWineStub/debug.c
    333 VBoxD3D9wddm_SOURCES.x86    = $(NO_SUCH_VARIABLE)
    334 VBoxD3D9wddm_SOURCES.amd64  = $(NO_SUCH_VARIABLE)
     301VBoxD3D9wddm_DEFS          += $(VBoxD3D9_DEFS) VBOX_WITH_WDDM VBOX_WINE_WITHOUT_LIBWINE IN_VBOXWINEEX
     302VBoxD3D9wddm_SOURCES        = $(subst d3d9xpdm.def,d3d9wddm.def,$(VBoxD3D9_SOURCES))
    335303VBoxD3D9wddm_LIBS           = $(subst $(PATH_STAGE_LIB)/wined3d$(VBOX_SUFF_LIB),$(PATH_STAGE_LIB)/wined3dwddm$(VBOX_SUFF_LIB),$(VBoxD3D9_LIBS))
    336 VBoxD3D9wddm_LIBS.x86       = $(NO_SUCH_VARIABLE)
    337 VBoxD3D9wddm_SDKS           = WINDDKWLH
    338 VBoxD3D9wddm_SDKS.amd64     = $(NO_SUCH_VARIABLE)
    339304#ifdef VBOX_WINE_WITH_IPRT
    340305#VBoxD3D9wddm_LIBS          += \
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c

    r39570 r39602  
    478478    return ret;
    479479}
    480 #ifdef VBOX_WITH_WDDM
     480
    481481static HRESULT IDirect3DDevice9Impl_DoCreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
    482482        D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
    483 #else
    484 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
    485         D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
    486 #endif
    487483{
    488484    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     
    514510}
    515511
    516 #ifdef VBOX_WITH_WDDM
    517512static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
    518513        D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
     
    541536    return D3D_OK;
    542537}
    543 #endif
    544538
    545539static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data) {
     
    31113105    local_parameters.PresentationInterval = present_parameters->PresentationInterval;
    31123106
    3113 #ifdef VBOX_WITH_WDDM
    31143107    hr = IDirect3DDevice9Impl_DoCreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
    31153108            &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
    3116 #else
    3117     hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex *)This,
    3118             &local_parameters, (IDirect3DSwapChain9 **)&d3d_swapchain);
    3119 #endif
    31203109    if (FAILED(hr))
    31213110    {
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c

    r39570 r39602  
    434434    /* fixup caps  */
    435435#ifdef VBOX_WITH_WDDM
     436    /* needed for Windows Media Player to work properly */
     437    pCaps->Caps |= D3DCAPS_READ_SCANLINE;
    436438    pCaps->Caps2 |= 0x00080000 /*D3DCAPS2_CANRENDERWINDOWED*/;
    437439    pCaps->Caps2 |= D3DCAPS2_CANSHARERESOURCE;
     
    482484#endif
    483485
    484     /* needed for Windows Media Player to work properly */
    485     pCaps->Caps |= D3DCAPS_READ_SCANLINE;
    486 
    487486    TRACE("(%p) returning %p\n", This, pCaps);
    488487
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h

    r38982 r39602  
    73957395        ) = 0;
    73967396
     7397    virtual HRESULT STDMETHODCALLTYPE AddSwapChain(
     7398        IWineD3DSwapChain *swapchain) = 0;
     7399
     7400    virtual HRESULT STDMETHODCALLTYPE RemoveSwapChain(
     7401        IWineD3DSwapChain *swapchain) = 0;
     7402
    73977403#ifdef VBOX_WITH_WDDM
    73987404    virtual HRESULT STDMETHODCALLTYPE Flush(
    73997405        ) = 0;
    7400 
    7401     virtual HRESULT STDMETHODCALLTYPE AddSwapChain(
    7402         IWineD3DSwapChain *swapchain) = 0;
    7403 
    7404     virtual HRESULT STDMETHODCALLTYPE RemoveSwapChain(
    7405         IWineD3DSwapChain *swapchain) = 0;
    74067406#endif
    74077407};
     
    81708170        IWineD3DDevice* This);
    81718171
     8172    HRESULT (STDMETHODCALLTYPE *AddSwapChain)(
     8173        IWineD3DDevice* This,
     8174        IWineD3DSwapChain *swapchain);
     8175
     8176    HRESULT (STDMETHODCALLTYPE *RemoveSwapChain)(
     8177        IWineD3DDevice* This,
     8178        IWineD3DSwapChain *swapchain);
     8179
    81728180#ifdef VBOX_WITH_WDDM
    81738181    HRESULT (STDMETHODCALLTYPE *Flush)(
    81748182        IWineD3DDevice* This);
    8175 
    8176     HRESULT (STDMETHODCALLTYPE *AddSwapChain)(
    8177         IWineD3DDevice* This,
    8178         IWineD3DSwapChain *swapchain);
    8179 
    8180     HRESULT (STDMETHODCALLTYPE *RemoveSwapChain)(
    8181         IWineD3DDevice* This,
    8182         IWineD3DSwapChain *swapchain);
    81838183#endif
    81848184
     
    83428342#define IWineD3DDevice_AcquireFocusWindow(This,window) (This)->lpVtbl->AcquireFocusWindow(This,window)
    83438343#define IWineD3DDevice_ReleaseFocusWindow(This) (This)->lpVtbl->ReleaseFocusWindow(This)
     8344#define IWineD3DDevice_AddSwapChain(This,swapchain) (This)->lpVtbl->AddSwapChain(This,swapchain)
     8345#define IWineD3DDevice_RemoveSwapChain(This,swapchain) (This)->lpVtbl->RemoveSwapChain(This,swapchain)
    83448346#ifdef VBOX_WITH_WDDM
    83458347#define IWineD3DDevice_Flush(This) (This)->lpVtbl->Flush(This)
    8346 #define IWineD3DDevice_AddSwapChain(This,swapchain) (This)->lpVtbl->AddSwapChain(This,swapchain)
    8347 #define IWineD3DDevice_RemoveSwapChain(This,swapchain) (This)->lpVtbl->RemoveSwapChain(This,swapchain)
    83488348#endif
    83498349#endif
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/libWineStub/include/wine/debug.h

    r39570 r39602  
    121121#ifndef WINE_NO_DEBUG_MSGS
    122122# define __WINE_GET_DEBUGGING_WARN(dbch)  ((dbch)->flags & (1 << __WINE_DBCL_WARN))
    123 # if 0// && defined(VBOX_WITH_WDDM) && defined(DEBUG_misha)
     123# if 0// && defined(DEBUG_misha)
    124124#  define __WINE_GET_DEBUGGING_FIXME(dbch) (RT_BREAKPOINT(), ((dbch)->flags & (1 << __WINE_DBCL_FIXME)))
    125125# else
     
    128128#else
    129129# define __WINE_GET_DEBUGGING_WARN(dbch)  0
    130 # if 0 && defined(VBOX_WITH_WDDM) && defined(DEBUG_misha)
     130# if 0 && defined(DEBUG_misha)
    131131#  define __WINE_GET_DEBUGGING_FIXME(dbch) (RT_BREAKPOINT(), 0)
    132132# else
     
    136136
    137137/* define error macro regardless of what is configured */
    138 #if defined(VBOX_WITH_WDDM) && defined(DEBUG_misha)
     138#if defined(DEBUG_misha)
    139139#define __WINE_GET_DEBUGGING_ERR(dbch)  (RT_BREAKPOINT(), ((dbch)->flags & (1 << __WINE_DBCL_ERR)))
    140140#else
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/libWineStub/include/wine/wined3d.h

    r38982 r39602  
    73937393        ) = 0;
    73947394
     7395    virtual HRESULT STDMETHODCALLTYPE AddSwapChain(
     7396        IWineD3DSwapChain *swapchain) = 0;
     7397
     7398    virtual HRESULT STDMETHODCALLTYPE RemoveSwapChain(
     7399        IWineD3DSwapChain *swapchain) = 0;
     7400
    73957401#ifdef VBOX_WITH_WDDM
    73967402    virtual HRESULT STDMETHODCALLTYPE Flush(
    73977403        ) = 0;
    7398 
    7399     virtual HRESULT STDMETHODCALLTYPE AddSwapChain(
    7400         IWineD3DSwapChain *swapchain) = 0;
    7401 
    7402     virtual HRESULT STDMETHODCALLTYPE RemoveSwapChain(
    7403         IWineD3DSwapChain *swapchain) = 0;
    74047404#endif
    74057405};
     
    81688168        IWineD3DDevice* This);
    81698169
     8170    HRESULT (STDMETHODCALLTYPE *AddSwapChain)(
     8171        IWineD3DDevice* This,
     8172        IWineD3DSwapChain *swapchain);
     8173
     8174    HRESULT (STDMETHODCALLTYPE *RemoveSwapChain)(
     8175        IWineD3DDevice* This,
     8176        IWineD3DSwapChain *swapchain);
     8177
    81708178#ifdef VBOX_WITH_WDDM
    81718179    HRESULT (STDMETHODCALLTYPE *Flush)(
    81728180        IWineD3DDevice* This);
    8173 
    8174     HRESULT (STDMETHODCALLTYPE *AddSwapChain)(
    8175         IWineD3DDevice* This,
    8176         IWineD3DSwapChain *swapchain);
    8177 
    8178     HRESULT (STDMETHODCALLTYPE *RemoveSwapChain)(
    8179         IWineD3DDevice* This,
    8180         IWineD3DSwapChain *swapchain);
    81818181#endif
    81828182
     
    83408340#define IWineD3DDevice_AcquireFocusWindow(This,window) (This)->lpVtbl->AcquireFocusWindow(This,window)
    83418341#define IWineD3DDevice_ReleaseFocusWindow(This) (This)->lpVtbl->ReleaseFocusWindow(This)
     8342#define IWineD3DDevice_AddSwapChain(This,swapchain) (This)->lpVtbl->AddSwapChain(This,swapchain)
     8343#define IWineD3DDevice_RemoveSwapChain(This,swapchain) (This)->lpVtbl->RemoveSwapChain(This,swapchain)
    83428344#ifdef VBOX_WITH_WDDM
    83438345#define IWineD3DDevice_Flush(This) (This)->lpVtbl->Flush(This)
    8344 #define IWineD3DDevice_AddSwapChain(This,swapchain) (This)->lpVtbl->AddSwapChain(This,swapchain)
    8345 #define IWineD3DDevice_RemoveSwapChain(This,swapchain) (This)->lpVtbl->RemoveSwapChain(This,swapchain)
    83468346#endif
    83478347#endif
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c

    r39501 r39602  
    4242static DWORD wined3d_context_tls_idx;
    4343
     44#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
     45# define vboxGetCurrentContext() VBoxTlsRefGetCurrent(struct wined3d_context, wined3d_context_tls_idx)
     46# define vboxSetCurrentContext(_ctx) VBoxTlsRefSetCurrent(struct wined3d_context, wined3d_context_tls_idx, (_ctx))
     47#endif
     48
    4449/* FBO helper functions */
    4550
     
    808813    if (context->valid)
    809814    {
    810         if (!ReleaseDC(context->win_handle, context->hdc))
     815        if (!VBoxExtReleaseDC(context->win_handle, context->hdc))
    811816        {
    812817            ERR("Failed to release device context %p, last error %#x.\n",
     
    817822
    818823    context->win_handle = context->swapchain->win_handle;
    819     if (!(context->hdc = GetDC(context->win_handle)))
     824    if (!(context->hdc = VBoxExtGetDC(context->win_handle)))
    820825    {
    821826        ERR("Failed to get a device context for window %p.\n", context->win_handle);
     
    10511056#ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
    10521057# ifndef VBOX_WITH_WDDM
    1053     ReleaseDC(context->win_handle, context->hdc);
     1058    VBoxExtReleaseDC(context->win_handle, context->hdc);
    10541059# else
    10551060    VBoxExtReleaseDC(context->win_handle, context->hdc);
     
    10731078}
    10741079
    1075 #ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
     1080#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    10761081static struct wined3d_context *context_get_current_ex(DWORD adjustTid)
    10771082{
    1078     struct wined3d_context *ctx = TlsGetValue(wined3d_context_tls_idx);
     1083    struct wined3d_context *ctx = vboxGetCurrentContext();
    10791084    if (!adjustTid)
    10801085        return ctx;
     
    10931098struct wined3d_context *context_get_current(void)
    10941099{
    1095 #ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
     1100#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    10961101    return TlsGetValue(wined3d_context_tls_idx);
    10971102#else
     
    11041109BOOL context_set_current(struct wined3d_context *ctx)
    11051110{
    1106 #ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
     1111#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    11071112    struct wined3d_context *old = context_get_current_ex(0);
    11081113    DWORD tid = GetCurrentThreadId();
     
    11121117    if (old == ctx)
    11131118    {
    1114 #ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
     1119#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    11151120        if (ctx && ctx->tid != tid)
    11161121        {
     
    11271132    if (old)
    11281133    {
    1129 #ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
     1134#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    11301135        old->tid = 0;
    1131 #endif
     1136        old->current = 0;
     1137#else
    11321138        if (old->destroyed)
    11331139        {
     
    11401146            old->current = 0;
    11411147        }
     1148#endif
    11421149    }
    11431150
     
    11511158            ERR("Failed to make GL context %p current on device context %p, last error %#x.\n",
    11521159                    ctx->glCtx, ctx->currentSwapchain->hDC, err);
    1153             TlsSetValue(wined3d_context_tls_idx, NULL);
     1160            vboxSetCurrentContext(NULL);
    11541161            return FALSE;
    11551162        }
     
    11611168            ERR("Failed to make GL context %p current on device context %p, last error %#x.\n",
    11621169                    ctx->glCtx, ctx->hdc, err);
    1163             TlsSetValue(wined3d_context_tls_idx, NULL);
     1170            vboxSetCurrentContext(NULL);
    11641171            return FALSE;
    11651172        }
     
    11741181            DWORD err = GetLastError();
    11751182            ERR("Failed to clear current GL context, last error %#x.\n", err);
    1176             TlsSetValue(wined3d_context_tls_idx, NULL);
     1183            vboxSetCurrentContext(NULL);
    11771184            return FALSE;
    11781185        }
    11791186    }
    11801187
    1181 #ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
     1188#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    11821189    return TlsSetValue(wined3d_context_tls_idx, ctx);
    11831190#else
    1184     if (TlsSetValue(wined3d_context_tls_idx, ctx))
    1185     {
    1186         if (ctx)
    1187         {
    1188             ctx->tid = tid;
    1189         }
    1190         return TRUE;
    1191     }
    1192     else
    1193     {
    1194         DWORD err = GetLastError();
    1195         ERR("Failed to set tls value, last error %#x.\n", err);
    1196     }
    1197     return FALSE;
    1198 #endif
    1199 }
     1191    vboxSetCurrentContext(ctx);
     1192    if (ctx)
     1193        ctx->tid = tid;
     1194    return TRUE;
     1195#endif
     1196}
     1197
     1198#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
     1199void context_clear_on_thread_detach()
     1200{
     1201    /* In theory, we should do context_set_current(NULL) here,
     1202     * but since it may result in calling a context dtor, it should be done under wined3d lock.
     1203     * We can not acquire a wined3d lock here since this routine is called in a DllMain context
     1204     * and this would result in a lock order violation, which may result in a deadlock.
     1205     * In other words, wined3d may internally call Win32 API functions which result in
     1206     * a DLL lock acquisition while holding wined3d lock.
     1207     * So lock order should always be "wined3d lock" -> "dll lock".
     1208     *
     1209     * This is why we do the following:
     1210     * */
     1211
     1212    /* 1. get the current context w/o adjusting its thread id, etc. */
     1213    struct wined3d_context *old = context_get_current_ex(0);
     1214    if (!old)
     1215        return;
     1216
     1217    /* there is a currently assigned context,
     1218     * 2. now increase its ref count to ensure its dtor routine is not called while making set_current(NULL).
     1219     * This is needed since dtor can only be run with a wined3d lock held */
     1220    VBoxTlsRefAddRef(old);
     1221
     1222    /* 3. now we can call context_set_current(NULL) */
     1223    context_set_current(NULL);
     1224
     1225    /* 4. to avoid possible deadlocks we make an asynchronous call to a worker thread to make
     1226     * wined3d lock - context release - wined3d unlock from there. */
     1227    VBoxExtReleaseContextAsync(old);
     1228}
     1229#endif
    12001230
    12011231void context_release(struct wined3d_context *context)
     
    12201250                    context->restore_ctx, context->restore_dc, err);
    12211251        }
    1222 #ifdef VBOX_WITH_WDDM
    12231252        else
    12241253        {
     
    12281257            if (current_context && current_context->glCtx != context->restore_ctx)
    12291258            {
     1259#ifdef VBOX_WITH_WDDM
    12301260                IWineD3DDeviceImpl *device = context->device;
     1261#else
     1262                IWineD3DDeviceImpl *device = context->swapchain->device;
     1263#endif
    12311264                UINT i = 0;
    12321265                for (; i < device->numContexts; ++i)
     
    12461279            }
    12471280        }
    1248 #endif
    12491281
    12501282        context->restore_ctx = NULL;
     
    14691501}
    14701502
     1503#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
     1504static DECLCALLBACK(void) context_tls_dtor(void* pvCtx)
     1505{
     1506    struct wined3d_context * context = (struct wined3d_context *)pvCtx;
     1507    context_destroy_gl_resources(context);
     1508    HeapFree(GetProcessHeap(), 0, context);
     1509}
     1510#endif
    14711511
    14721512/*****************************************************************************
     
    15071547    }
    15081548
     1549#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
     1550    VBoxTlsRefInit(ret, context_tls_dtor);
     1551#endif
     1552
    15091553    if (!(hdc =
    15101554#ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
    15111555            swapchain->hDC
    15121556#else
    1513             GetDC(swapchain->win_handle)
     1557            VBoxExtGetDC(swapchain->win_handle)
    15141558#endif
    15151559            )
     
    16351679#endif
    16361680    ret->current_rt = (IWineD3DSurface *)target;
    1637 #ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
     1681#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    16381682    ret->tid = GetCurrentThreadId();
    16391683#endif
     
    17851829    }
    17861830
    1787 #ifdef VBOX_WITH_WDDM
     1831    /* for WDDM case this is used for shared resource handling
     1832     *
     1833     * for XPDM this is needed to at least support texture sharing between device contexts.
     1834     * this is a kinda hack, but it is needed since our ogl driver currently does not support ShareLists */
    17881835    GL_EXTCALL(glChromiumParameteriCR(GL_SHARE_CONTEXT_RESOURCES_CR, GL_TRUE));
     1836#if defined(VBOX_WITH_WDDM) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    17891837    GL_EXTCALL(glChromiumParameteriCR(GL_FLUSH_ON_THREAD_SWITCH_CR,  GL_TRUE));
    17901838#endif
    1791 
    17921839    LEAVE_GL();
    17931840
     
    18861933    }
    18871934#else
     1935# ifdef VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
     1936#  error "Port Me!"
     1937# endif
    18881938    context = device->numContexts ? device->contexts[0] : NULL;
    18891939#endif
     
    19251975void context_destroy(IWineD3DDeviceImpl *This, struct wined3d_context *context)
    19261976{
     1977#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    19271978    BOOL destroy;
     1979#endif
    19281980
    19291981    TRACE("Destroying ctx %p\n", context);
    19301982
     1983#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    19311984    if (context->tid == GetCurrentThreadId() || !context->current)
    19321985    {
     
    19401993        destroy = FALSE;
    19411994    }
     1995#endif
    19421996
    19431997    HeapFree(GetProcessHeap(), 0, context->vshader_const_dirty);
    19441998    HeapFree(GetProcessHeap(), 0, context->pshader_const_dirty);
    19451999    device_context_remove(This, context);
     2000#ifndef VBOX_WITH_WDDM
     2001    context->swapchain = NULL;
     2002#endif
     2003#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    19462004    if (destroy) HeapFree(GetProcessHeap(), 0, context);
    1947 #ifndef VBOX_WITH_WDDM
    1948     else context->swapchain = NULL;
     2005#else
     2006    VBoxTlsRefRelease(context);
    19492007#endif
    19502008}
     
    21862244 *****************************************************************************/
    21872245static struct wined3d_context *findThreadContextForSwapChain(IWineD3DSwapChain *swapchain
    2188 #ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
     2246#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    21892247        , DWORD tid
    21902248#endif
     
    22012259    for (i = 0; i < device->numContexts; ++i)
    22022260    {
     2261#  ifdef VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
     2262#   error "port me!"
     2263#  endif
    22032264        if (device->contexts[i]->tid == tid)
    22042265            return device->contexts[i];
     
    22062267# else
    22072268    for(i = 0; i < ((IWineD3DSwapChainImpl *) swapchain)->num_contexts; i++) {
     2269#  ifdef VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
     2270        if(VBoxTlsRefIsFunctional(((IWineD3DSwapChainImpl *) swapchain)->context[i])) {
     2271#  else
    22082272        if(((IWineD3DSwapChainImpl *) swapchain)->context[i]->tid == tid) {
     2273#  endif
    22092274            return ((IWineD3DSwapChainImpl *) swapchain)->context[i];
    22102275        }
     
    22342299    IWineD3DSwapChain *swapchain = NULL;
    22352300    struct wined3d_context *current_context = context_get_current();
    2236 #ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
     2301#ifndef VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
    22372302    DWORD tid = GetCurrentThreadId();
    22382303#endif
    22392304    struct wined3d_context *context;
    22402305
    2241     if (current_context && current_context->destroyed) current_context = NULL;
     2306    if (current_context
     2307#ifndef VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
     2308            && current_context->destroyed
     2309#else
     2310            && !VBoxTlsRefIsFunctional(current_context)
     2311#endif
     2312            ) current_context = NULL;
    22422313
    22432314    if (!target)
     
    22872358
    22882359        context = findThreadContextForSwapChain(swapchain
    2289 #ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
     2360#ifndef VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
    22902361                , tid
    22912362#endif
     
    23152386#ifdef VBOX_WITH_WDDM /* tmp work-around */
    23162387            context = findThreadContextForSwapChain(This->swapchains[This->NumberOfSwapChains-1]
    2317 # ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
     2388# ifndef VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
    23182389                                                                     , tid
    23192390# endif
    23202391                                                                     );
    23212392#else
    2322             context = findThreadContextForSwapChain(This->swapchains[0], tid);
     2393            context = findThreadContextForSwapChain(This->swapchains[0]
     2394# ifndef VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
     2395                                                                     , tid
     2396# endif
     2397                    );
    23232398#endif
    23242399        }
     
    23552430
    23562431
    2357     if (context && context->destroyed)
     2432    if (context && !VBoxTlsRefIsFunctional(context))
    23582433    {
    23592434        ERR("context is destroyed");
     
    27532828    context_setup_target(device, context, target);
    27542829    context_enter(context);
    2755     if (!context->valid) return context;
     2830    if (!context->valid)
     2831    {
     2832        ERR("context_acquire failed to get a valid context!");
     2833        return context;
     2834    }
    27562835
    27572836    if (context != current_context)
     
    27922871    }
    27932872
     2873#ifdef DEBUG
     2874    Assert(context->tid == GetCurrentThreadId());
     2875#endif
     2876
    27942877    context_apply_state(context, device, usage);
    27952878
     2879#ifdef DEBUG
     2880    Assert(context->tid == GetCurrentThreadId());
     2881#endif
     2882
    27962883    return context;
    27972884}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c

    r38982 r39602  
    69226922}
    69236923
     6924static HRESULT WINAPI IWineD3DDeviceImpl_AddSwapChain(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain)
     6925{
     6926    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
     6927    VOID *pvNewBuf = HeapReAlloc(GetProcessHeap(), 0, This->swapchains, (This->NumberOfSwapChains + 1) * sizeof(IWineD3DSwapChain *));
     6928    if(!pvNewBuf) {
     6929        ERR("Out of memory!\n");
     6930        return E_OUTOFMEMORY;
     6931    }
     6932    This->swapchains = (IWineD3DSwapChain **)pvNewBuf;
     6933    This->swapchains[This->NumberOfSwapChains] = swapchain;
     6934    ++This->NumberOfSwapChains;
     6935    return WINED3D_OK;
     6936}
     6937
     6938static HRESULT WINAPI IWineD3DDeviceImpl_RemoveSwapChain(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain)
     6939{
     6940    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
     6941    int i;
     6942    for (i = 0; i < This->NumberOfSwapChains; ++i)
     6943    {
     6944        if (This->swapchains[i] == swapchain)
     6945        {
     6946            break;
     6947        }
     6948    }
     6949
     6950    if (i == This->NumberOfSwapChains)
     6951    {
     6952        WARN("swapchain 0x%p is not part of device 0x%p\n", swapchain, iface);
     6953        return E_INVALIDARG;
     6954    }
     6955
     6956    --This->NumberOfSwapChains;
     6957    if (This->NumberOfSwapChains)
     6958    {
     6959        IWineD3DSwapChain **pvNewBuf = (IWineD3DSwapChain **)HeapAlloc(GetProcessHeap(), 0, (This->NumberOfSwapChains) * sizeof(IWineD3DSwapChain *));
     6960        if(!pvNewBuf) {
     6961            ERR("Out of memory!\n");
     6962            return E_OUTOFMEMORY;
     6963        }
     6964        if (i) {
     6965            memcpy (pvNewBuf, This->swapchains, i*sizeof(IWineD3DSwapChain *));
     6966        }
     6967        if (i < This->NumberOfSwapChains) {
     6968            memcpy (pvNewBuf + i, This->swapchains +i+1, (This->NumberOfSwapChains - i)*sizeof(IWineD3DSwapChain *));
     6969        }
     6970
     6971        This->swapchains = pvNewBuf;
     6972    }
     6973    else
     6974    {
     6975        while (This->numContexts)
     6976        {
     6977            context_destroy(This, This->contexts[0]);
     6978        }
     6979    }
     6980    return WINED3D_OK;
     6981}
     6982
    69246983#ifdef VBOX_WITH_WDDM
    69256984static HRESULT WINAPI IWineD3DDeviceImpl_Flush(IWineD3DDevice *iface)
     
    69487007        {
    69497008            WARN("Invalid context, skipping flush.\n");
    6950         }
    6951     }
    6952     return WINED3D_OK;
    6953 }
    6954 
    6955 static HRESULT WINAPI IWineD3DDeviceImpl_AddSwapChain(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain)
    6956 {
    6957     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
    6958     VOID *pvNewBuf = HeapReAlloc(GetProcessHeap(), 0, This->swapchains, (This->NumberOfSwapChains + 1) * sizeof(IWineD3DSwapChain *));
    6959     if(!pvNewBuf) {
    6960         ERR("Out of memory!\n");
    6961         return E_OUTOFMEMORY;
    6962     }
    6963     This->swapchains = (IWineD3DSwapChain **)pvNewBuf;
    6964     This->swapchains[This->NumberOfSwapChains] = swapchain;
    6965     ++This->NumberOfSwapChains;
    6966     return WINED3D_OK;
    6967 }
    6968 
    6969 static HRESULT WINAPI IWineD3DDeviceImpl_RemoveSwapChain(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain)
    6970 {
    6971     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
    6972     int i;
    6973     for (i = 0; i < This->NumberOfSwapChains; ++i)
    6974     {
    6975         if (This->swapchains[i] == swapchain)
    6976         {
    6977             break;
    6978         }
    6979     }
    6980 
    6981     if (i == This->NumberOfSwapChains)
    6982     {
    6983         WARN("swapchain 0x%p is not part of device 0x%p\n", swapchain, iface);
    6984         return E_INVALIDARG;
    6985     }
    6986 
    6987     --This->NumberOfSwapChains;
    6988     if (This->NumberOfSwapChains)
    6989     {
    6990         IWineD3DSwapChain **pvNewBuf = (IWineD3DSwapChain **)HeapAlloc(GetProcessHeap(), 0, (This->NumberOfSwapChains) * sizeof(IWineD3DSwapChain *));
    6991         if(!pvNewBuf) {
    6992             ERR("Out of memory!\n");
    6993             return E_OUTOFMEMORY;
    6994         }
    6995         if (i) {
    6996             memcpy (pvNewBuf, This->swapchains, i*sizeof(IWineD3DSwapChain *));
    6997         }
    6998         if (i < This->NumberOfSwapChains) {
    6999             memcpy (pvNewBuf + i, This->swapchains +i+1, (This->NumberOfSwapChains - i)*sizeof(IWineD3DSwapChain *));
    7000         }
    7001 
    7002         This->swapchains = pvNewBuf;
    7003     }
    7004     else
    7005     {
    7006         while (This->numContexts)
    7007         {
    7008             context_destroy(This, This->contexts[0]);
    70097009        }
    70107010    }
     
    71657165    IWineD3DDeviceImpl_AcquireFocusWindow,
    71667166    IWineD3DDeviceImpl_ReleaseFocusWindow,
     7167    /* VBox extensions */
     7168    IWineD3DDeviceImpl_AddSwapChain,
     7169    IWineD3DDeviceImpl_RemoveSwapChain,
    71677170#ifdef VBOX_WITH_WDDM
    71687171    /* VBox WDDM extensions */
    71697172    IWineD3DDeviceImpl_Flush,
    7170     IWineD3DDeviceImpl_AddSwapChain,
    7171     IWineD3DDeviceImpl_RemoveSwapChain,
    71727173#endif
    71737174};
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c

    r38112 r39602  
    22082208    gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
    22092209
    2210 #ifdef VBOX_WITH_WDDM
    22112210    gl_info->supported[VBOX_SHARED_CONTEXTS] = TRUE;
    2212 #endif
    22132211
    22142212    while (*GL_Extensions)
     
    29122910            if (DevModeW.dmFields&DM_DISPLAYFLAGS)
    29132911            {
    2914 #if defined(RT_ARCH_AMD64) && !defined(VBOX_WITH_WDDM)
     2912#if 0 //defined(RT_ARCH_AMD64) && !defined(VBOX_WITH_WDDM)
    29152913# ifndef DM_INTERLACED
    29162914#  define DM_INTERLACED 0x00000002
     
    29312929            if (DevModeW.dmFields&DM_DISPLAYORIENTATION)
    29322930            {
    2933 #if defined(RT_ARCH_AMD64) && !defined(VBOX_WITH_WDDM)
     2931#if 0 //defined(RT_ARCH_AMD64) && !defined(VBOX_WITH_WDDM)
    29342932                switch (DevModeW.dmDisplayOrientation)
    29352933#else
     
    29502948                        break;
    29512949                    default:
    2952 #if defined(RT_ARCH_AMD64) && !defined(VBOX_WITH_WDDM)
     2950#if 0 //defined(RT_ARCH_AMD64) && !defined(VBOX_WITH_WDDM)
    29532951                        WARN("Unexpected display orientation %#x", DevModeW.dmDisplayOrientation);
    29542952#else
     
    52055203#ifdef USE_WIN32_OPENGL
    52065204#define USE_GL_FUNC(pfn) pfn = (void*)GetProcAddress(mod_gl, #pfn);
    5207 #ifdef VBOX_WITH_WDDM
     5205#if defined(VBOX_WITH_WDDM) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    52085206        BOOL (APIENTRY *pDrvValidateVersion)(DWORD) DECLSPEC_HIDDEN;
    52095207#ifdef VBOX_WDDM_WOW64
     
    52195217            goto nogl_adapter;
    52205218        }
    5221 #ifdef VBOX_WITH_WDDM
     5219#if defined(VBOX_WITH_WDDM) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    52225220        /* init properly */
    52235221        pDrvValidateVersion = (void*)GetProcAddress(mod_gl, "DrvValidateVersion");
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c

    r37760 r39602  
    4040#include "wine/port.h"
    4141#include "wined3d_private.h"
     42
     43#include <float.h>
    4244
    4345WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c

    r39486 r39602  
    139139        This->backBuffer = NULL;
    140140    }
    141 #ifndef VBOX_WITH_WDDM
     141#if 0
    142142    for (i = 0; i < This->num_contexts; ++i)
    143143    {
     
    146146#else
    147147
     148#ifdef VBOX_WITH_WDDM
    148149    if (This->presentRt)
    149150    {
     
    153154        This->presentRt = NULL;
    154155    }
     156#endif
     157
    155158    IWineD3DDevice_RemoveSwapChain((IWineD3DDevice*)This->device, (IWineD3DSwapChain*)This);
    156159    if (!This->device->NumberOfSwapChains)
     
    479482    pwglSwapLayerBuffers(context->currentSwapchain->hDC, WGL_SWAP_MAIN_PLANE);
    480483#else
     484# ifdef VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
     485    pwglSwapLayerBuffers(context->hdc, WGL_SWAP_MAIN_PLANE);
     486# else
    481487    SwapBuffers(context->hdc); /* TODO: cycle through the swapchain buffers */
     488# endif
    482489#endif
    483490
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vboxext.c

    r39257 r39602  
    1515 */
    1616#include "config.h"
     17#include "wine/port.h"
    1718#include "wined3d_private.h"
    1819#include "vboxext.h"
     
    2324typedef FNVBOXEXTWORKERCB *PFNVBOXEXTWORKERCB;
    2425
    25 HRESULT VBoxExtDwSubmitProc(PFNVBOXEXTWORKERCB pfnCb, void *pvCb);
     26HRESULT VBoxExtDwSubmitProcSync(PFNVBOXEXTWORKERCB pfnCb, void *pvCb);
     27HRESULT VBoxExtDwSubmitProcAsync(PFNVBOXEXTWORKERCB pfnCb, void *pvCb);
    2628
    2729/*******************************/
    28 #if defined(VBOX_WDDM_WOW64)
     30#ifdef VBOX_WITH_WDDM
     31# if defined(VBOX_WDDM_WOW64)
    2932# define VBOXEXT_WINE_MODULE_NAME "wined3dwddm-x86.dll"
     33# else
     34# define VBOXEXT_WINE_MODULE_NAME "wined3dwddm.dll"
     35# endif
    3036#else
    31 # define VBOXEXT_WINE_MODULE_NAME "wined3dwddm.dll"
     37/* both 32bit and 64bit versions of xpdm wine libs are named identically */
     38# define VBOXEXT_WINE_MODULE_NAME "wined3d.dll"
    3239#endif
    3340
     
    6168static VBOXEXT_GLOBAL g_VBoxExtGlobal;
    6269
    63 #define WM_VBOXEXT_CALLPROC (WM_APP+1)
     70#define WM_VBOXEXT_CALLPROC  (WM_APP+1)
     71#define WM_VBOXEXT_INIT_QUIT (WM_APP+2)
    6472
    6573typedef struct VBOXEXT_CALLPROC
     
    103111                pData->pfnCb(pData->pvCb);
    104112                SetEvent(pWorker->hEvent);
     113                break;
     114            }
     115            case WM_VBOXEXT_INIT_QUIT:
     116            case WM_CLOSE:
     117            {
     118                PostQuitMessage(0);
    105119                break;
    106120            }
     
    165179HRESULT VBoxExtWorkerDestroy(PVBOXEXT_WORKER pWorker)
    166180{
    167     BOOL bResult = PostThreadMessage(pWorker->idThread, WM_QUIT, 0, 0);
     181    BOOL bResult = PostThreadMessage(pWorker->idThread, WM_VBOXEXT_INIT_QUIT, 0, 0);
    168182    DWORD dwErr;
    169183    if (!bResult)
     
    191205}
    192206
    193 static HRESULT vboxExtWorkerSubmit(VBOXEXT_WORKER *pWorker, UINT Msg, LPARAM lParam)
     207static HRESULT vboxExtWorkerSubmit(VBOXEXT_WORKER *pWorker, UINT Msg, LPARAM lParam, BOOL fSync)
    194208{
    195209    HRESULT hr = E_FAIL;
     
    201215    if (bResult)
    202216    {
    203         DWORD dwErr = WaitForSingleObject(pWorker->hEvent, INFINITE);
    204         if (dwErr == WAIT_OBJECT_0)
    205         {
     217        if (fSync)
     218        {
     219            DWORD dwErr = WaitForSingleObject(pWorker->hEvent, INFINITE);
     220            if (dwErr == WAIT_OBJECT_0)
     221            {
     222                hr = S_OK;
     223            }
     224            else
     225            {
     226                ERR("WaitForSingleObject returned (%d)", dwErr);
     227            }
     228        }
     229        else
    206230            hr = S_OK;
    207         }
    208         else
    209         {
    210             ERR("WaitForSingleObject returned (%d)", dwErr);
    211         }
    212231    }
    213232    else
     
    221240}
    222241
    223 HRESULT VBoxExtWorkerSubmitProc(PVBOXEXT_WORKER pWorker, PFNVBOXEXTWORKERCB pfnCb, void *pvCb)
     242HRESULT VBoxExtWorkerSubmitProcSync(PVBOXEXT_WORKER pWorker, PFNVBOXEXTWORKERCB pfnCb, void *pvCb)
    224243{
    225244    VBOXEXT_CALLPROC Ctx;
    226245    Ctx.pfnCb = pfnCb;
    227246    Ctx.pvCb = pvCb;
    228     return vboxExtWorkerSubmit(pWorker, WM_VBOXEXT_CALLPROC, (LPARAM)&Ctx);
    229 }
     247    return vboxExtWorkerSubmit(pWorker, WM_VBOXEXT_CALLPROC, (LPARAM)&Ctx, TRUE);
     248}
     249
     250static DECLCALLBACK(void) vboxExtWorkerSubmitProcAsyncWorker(void *pvUser)
     251{
     252    PVBOXEXT_CALLPROC pCallInfo = (PVBOXEXT_CALLPROC)pvUser;
     253    pCallInfo[1].pfnCb(pCallInfo[1].pvCb);
     254    HeapFree(GetProcessHeap(), 0, pCallInfo);
     255}
     256
     257HRESULT VBoxExtWorkerSubmitProcAsync(PVBOXEXT_WORKER pWorker, PFNVBOXEXTWORKERCB pfnCb, void *pvCb)
     258{
     259    HRESULT hr;
     260    PVBOXEXT_CALLPROC pCallInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (VBOXEXT_CALLPROC) * 2);
     261    if (!pCallInfo)
     262    {
     263        ERR("HeapAlloc failed\n");
     264        return E_OUTOFMEMORY;
     265    }
     266    pCallInfo[0].pfnCb = vboxExtWorkerSubmitProcAsyncWorker;
     267    pCallInfo[0].pvCb = pCallInfo;
     268    pCallInfo[1].pfnCb = pfnCb;
     269    pCallInfo[1].pvCb = pvCb;
     270    hr = vboxExtWorkerSubmit(pWorker, WM_VBOXEXT_CALLPROC, (LPARAM)pCallInfo, FALSE);
     271    if (FAILED(hr))
     272    {
     273        ERR("vboxExtWorkerSubmit failed, hr 0x%x\n", hr);
     274        HeapFree(GetProcessHeap(), 0, pCallInfo);
     275        return hr;
     276    }
     277    return S_OK;
     278}
     279
    230280
    231281static HRESULT vboxExtInit()
     
    295345}
    296346
    297 HRESULT VBoxExtDwSubmitProc(PFNVBOXEXTWORKERCB pfnCb, void *pvCb)
    298 {
    299     return VBoxExtWorkerSubmitProc(&g_VBoxExtGlobal.Worker, pfnCb, pvCb);
    300 }
    301 
     347HRESULT VBoxExtDwSubmitProcSync(PFNVBOXEXTWORKERCB pfnCb, void *pvCb)
     348{
     349    return VBoxExtWorkerSubmitProcSync(&g_VBoxExtGlobal.Worker, pfnCb, pvCb);
     350}
     351
     352HRESULT VBoxExtDwSubmitProcAsync(PFNVBOXEXTWORKERCB pfnCb, void *pvCb)
     353{
     354    return VBoxExtWorkerSubmitProcAsync(&g_VBoxExtGlobal.Worker, pfnCb, pvCb);
     355}
     356
     357#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
     358# ifndef VBOX_WITH_WDDM
    302359typedef struct VBOXEXT_GETDC_CB
    303360{
     
    324381    pData->ret = ReleaseDC(pData->hWnd, pData->hDC);
    325382}
    326 #if 0
     383
    327384HDC VBoxExtGetDC(HWND hWnd)
    328385{
    329 #ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
    330386    HRESULT hr;
    331387    VBOXEXT_GETDC_CB Data = {0};
     
    333389    Data.hDC = NULL;
    334390
    335     hr = VBoxExtDwSubmitProc(vboxExtGetDCWorker, &Data);
     391    hr = VBoxExtDwSubmitProcSync(vboxExtGetDCWorker, &Data);
    336392    if (FAILED(hr))
    337393    {
    338         ERR("VBoxExtDwSubmitProc feiled, hr (0x%x)\n", hr);
     394        ERR("VBoxExtDwSubmitProcSync feiled, hr (0x%x)\n", hr);
    339395        return NULL;
    340396    }
    341397
    342398    return Data.hDC;
    343 #else
    344     return GetDC(hWnd);
    345 #endif
    346399}
    347400
    348401int VBoxExtReleaseDC(HWND hWnd, HDC hDC)
    349402{
    350 #ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
    351403    HRESULT hr;
    352404    VBOXEXT_RELEASEDC_CB Data = {0};
     
    355407    Data.ret = 0;
    356408
    357     hr = VBoxExtDwSubmitProc(vboxExtReleaseDCWorker, &Data);
     409    hr = VBoxExtDwSubmitProcSync(vboxExtReleaseDCWorker, &Data);
    358410    if (FAILED(hr))
    359411    {
    360         ERR("VBoxExtDwSubmitProc feiled, hr (0x%x)\n", hr);
     412        ERR("VBoxExtDwSubmitProcSync feiled, hr (0x%x)\n", hr);
    361413        return -1;
    362414    }
    363415
    364416    return Data.ret;
    365 #else
    366     return ReleaseDC(hWnd, hDC);
    367 #endif
    368 }
    369 #endif
     417}
     418# endif /* #ifndef VBOX_WITH_WDDM */
     419
     420static DECLCALLBACK(void) vboxExtReleaseContextWorker(void *pvUser)
     421{
     422    struct wined3d_context *context = (struct wined3d_context *)pvUser;
     423    wined3d_mutex_lock();
     424    VBoxTlsRefRelease(context);
     425    wined3d_mutex_unlock();
     426}
     427
     428void VBoxExtReleaseContextAsync(struct wined3d_context *context)
     429{
     430    HRESULT hr;
     431
     432    hr = VBoxExtDwSubmitProcAsync(vboxExtReleaseContextWorker, context);
     433    if (FAILED(hr))
     434    {
     435        ERR("VBoxExtDwSubmitProcAsync feiled, hr (0x%x)\n", hr);
     436        return;
     437    }
     438}
     439
     440#endif /* #if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT) */
    370441
    371442/* window creation API */
     
    507578    Info.hWnd = hWnd;
    508579    Info.hDC = hDC;
    509     hr = VBoxExtDwSubmitProc(vboxExtWndDestroyWorker, &Info);
     580    hr = VBoxExtDwSubmitProcSync(vboxExtWndDestroyWorker, &Info);
    510581    Assert(hr == S_OK);
    511582    if (hr == S_OK)
     
    524595    Info.width = width;
    525596    Info.height = height;
    526     hr = VBoxExtDwSubmitProc(vboxExtWndCreateWorker, &Info);
     597    hr = VBoxExtDwSubmitProcSync(vboxExtWndCreateWorker, &Info);
    527598    Assert(hr == S_OK);
    528599    if (hr == S_OK)
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vboxext.h

    r38363 r39602  
    1717#define ___VBOXEXT_H__
    1818
    19 #include <windows.h>
     19#ifdef VBOX_WINE_WITHOUT_LIBWINE
     20# include <windows.h>
     21#endif
    2022#include <iprt/cdefs.h>
    21 
    2223
    2324HRESULT VBoxExtCheckInit();
    2425HRESULT VBoxExtCheckTerm();
    25 #if 0
     26#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
     27# ifndef VBOX_WITH_WDDM
    2628/* Windows destroys HDC created by a given thread when the thread is terminated
    2729 * this leads to a mess-up in Wine & Chromium code in some situations, e.g.
     
    3032HDC VBoxExtGetDC(HWND hWnd);
    3133int VBoxExtReleaseDC(HWND hWnd, HDC hDC);
     34# endif
     35/* We need to do a VBoxTlsRefRelease for the current thread context on thread exit to avoid memory leaking
     36 * Calling VBoxTlsRefRelease may result in a call to context dtor callback, which is supposed to be run under wined3d lock.
     37 * We can not acquire a wined3d lock in DllMain since this would result in a lock order violation, which may result in a deadlock.
     38 * In other words, wined3d may internally call Win32 API functions which result in a DLL lock acquisition while holding wined3d lock.
     39 * So lock order should always be "wined3d lock" -> "dll lock".
     40 * To avoid possible deadlocks we make an asynchronous call to a worker thread to make a context release from there. */
     41void VBoxExtReleaseContextAsync(struct wined3d_context *context);
    3242#endif
    3343
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h

    r38565 r39602  
    18451845    WGL_WINE_PIXEL_FORMAT_PASSTHROUGH,
    18461846
    1847 #ifdef VBOX_WITH_WDDM
    18481847    VBOX_SHARED_CONTEXTS,
    1849 #endif
     1848
    18501849    /* Internally used */
    18511850    WINE_NORMALIZED_TEXRECT,
     
    37753774        const PIXELFORMATDESCRIPTOR *ppfd);
    37763775
    3777 #ifdef VBOX_WITH_WDDM
    37783776#define GL_SHARE_CONTEXT_RESOURCES_CR 0x8B27
    37793777#define GL_FLUSH_ON_THREAD_SWITCH_CR  0x8B28
     
    37843782                glChromiumParameteriCR,                VBOX_SHARED_CONTEXTS,            NULL) \
    37853783
    3786 #else
    3787 # define VBOXWDDM_GL_EXT_FUNCS_GEN
    3788 #endif
    37893784
    37903785#define GL_EXT_FUNCS_GEN \
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_main.c

    r39570 r39602  
    9696    HRESULT hr;
    9797
    98 #ifdef VBOX_WITH_WDDM
    9998    hr = VBoxExtCheckInit();
    10099    if (FAILED(hr))
     
    103102        return NULL;
    104103    }
    105 #endif
    106104
    107105    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     
    109107    {
    110108        ERR("Failed to allocate wined3d object memory.\n");
    111 #ifdef VBOX_WITH_WDDM
    112109        VBoxExtCheckTerm();
    113 #endif
    114110        return NULL;
    115111    }
     
    151147}
    152148
    153 #ifdef VBOX_WITH_WDDM
    154 void WINAPI wined3d_mutex_init(void)
     149static void WINAPI wined3d_mutex_init(void)
    155150{
    156151    InitializeCriticalSection(&wined3d_cs);
    157152}
    158153
    159 void WINAPI wined3d_mutex_term(void)
     154static void WINAPI wined3d_mutex_term(void)
    160155{
    161156    DeleteCriticalSection(&wined3d_cs);
    162157}
    163 #endif
    164158
    165159static BOOL wined3d_dll_init(HINSTANCE hInstDLL)
     
    174168    WNDCLASSA wc;
    175169
    176 #ifdef VBOX_WITH_WDDM
    177170    wined3d_mutex_init();
    178 #endif
    179171
    180172    wined3d_context_tls_idx = TlsAlloc();
     
    183175        DWORD err = GetLastError();
    184176        ERR("Failed to allocate context TLS index, err %#x.\n", err);
    185 #ifdef VBOX_WITH_WDDM
     177
    186178        wined3d_mutex_term();
    187 #endif
    188179        return FALSE;
    189180    }
     
    212203            ERR("Failed to free context TLS index, err %#x.\n", err);
    213204        }
    214 #ifdef VBOX_WITH_WDDM
     205
    215206        wined3d_mutex_term();
    216 #endif
     207
    217208        return FALSE;
    218209    }
     
    413404    UnregisterClassA(WINED3D_OPENGL_WINDOW_CLASS_NAME, hInstDLL);
    414405
    415 #ifdef VBOX_WITH_WDDM
    416406    wined3d_mutex_term();
    417 #endif
    418407
    419408    return TRUE;
     
    544533        case DLL_THREAD_DETACH:
    545534        {
     535#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
     536            context_clear_on_thread_detach();
     537#else
    546538            if (!context_set_current(NULL))
    547539            {
    548540                ERR("Failed to clear current context.\n");
    549541            }
     542#endif
    550543            return TRUE;
    551544        }
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h

    r39130 r39602  
    5151#include "wine/debug.h"
    5252#include "wine/unicode.h"
    53 #ifdef VBOX_WITH_WDDM
    54 # include "vboxext.h"
    55 #endif
    56 
    5753
    5854#ifndef VBOX_WINE_WITHOUT_LIBWINE
     
    6460#include "wine/rbtree.h"
    6561
     62#include "vboxext.h"
     63
    6664#ifdef VBOX_WITH_WDDM
    6765# include "vboxsharedrc.h"
     66#endif
     67
     68#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
     69# define VBoxTlsRefGetImpl(_tls) (TlsGetValue((DWORD)(_tls)))
     70# define VBoxTlsRefSetImpl(_tls, _val) (TlsSetValue((DWORD)(_tls), (_val)))
     71# define VBoxTlsRefAssertImpl Assert
     72# include <VBox/VBoxVideo3D.h>
    6873#endif
    6974
     
    11211126    WORD num_untracked_materials : 2;   /* Max value 2 */
    11221127    WORD current : 1;
     1128#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
    11231129    WORD destroyed : 1;
     1130#endif
    11241131    WORD valid : 1;
    11251132    BYTE texShaderBumpMap;              /* MAX_TEXTURES, 8 */
     
    11421149    HDC                     hdc;
    11431150#endif
     1151
     1152#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
     1153    VBOXTLSREFDATA
     1154#endif
     1155
    11441156    int pixel_format;
    11451157    GLint                   aux_buffers;
     
    12881300void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN;
    12891301void context_surface_update(struct wined3d_context *context, IWineD3DSurfaceImpl *surface) DECLSPEC_HIDDEN;
    1290 
     1302#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
     1303void context_clear_on_thread_detach();
     1304#endif
    12911305/* Macros for doing basic GPU detection based on opengl capabilities */
    12921306#define WINE_D3D6_CAPABLE(gl_info) (gl_info->supported[ARB_MULTITEXTURE])
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