VirtualBox

Ignore:
Timestamp:
Oct 6, 2009 6:07:06 AM (15 years ago)
Author:
vboxsync
Message:

crOpenGL: update to wine 1.1.30

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/cubetexture.c

    r21731 r23571  
    5959    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    6060
     61    if (ref == 1)
     62    {
     63        IDirect3DDevice9Ex_AddRef(This->parentDevice);
     64        wined3d_mutex_lock();
     65        IWineD3DCubeTexture_AddRef(This->wineD3DCubeTexture);
     66        wined3d_mutex_unlock();
     67    }
     68
    6169    return ref;
    6270}
     
    7179        TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
    7280
    73         EnterCriticalSection(&d3d9_cs);
    74         IWineD3DCubeTexture_Destroy(This->wineD3DCubeTexture, D3D9CB_DestroySurface);
    7581        IDirect3DDevice9Ex_Release(This->parentDevice);
    76         LeaveCriticalSection(&d3d9_cs);
    77 
    78         HeapFree(GetProcessHeap(), 0, This);
     82        wined3d_mutex_lock();
     83        IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
     84        wined3d_mutex_unlock();
    7985    }
    8086    return ref;
     
    8894    TRACE("(%p) Relay\n" , This);
    8995
    90     EnterCriticalSection(&d3d9_cs);
     96    wined3d_mutex_lock();
    9197    hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
    9298    if (SUCCEEDED(hr))
     
    95101        IWineD3DDevice_Release(wined3d_device);
    96102    }
    97     LeaveCriticalSection(&d3d9_cs);
     103    wined3d_mutex_unlock();
     104
    98105    return hr;
    99106}
     
    104111    TRACE("(%p) Relay\n", This);
    105112
    106     EnterCriticalSection(&d3d9_cs);
     113    wined3d_mutex_lock();
    107114    hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
    108     LeaveCriticalSection(&d3d9_cs);
     115    wined3d_mutex_unlock();
     116
    109117    return hr;
    110118}
     
    115123    TRACE("(%p) Relay\n", This);
    116124
    117     EnterCriticalSection(&d3d9_cs);
     125    wined3d_mutex_lock();
    118126    hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
    119     LeaveCriticalSection(&d3d9_cs);
     127    wined3d_mutex_unlock();
     128
    120129    return hr;
    121130}
     
    126135    TRACE("(%p) Relay\n", This);
    127136
    128     EnterCriticalSection(&d3d9_cs);
     137    wined3d_mutex_lock();
    129138    hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
    130     LeaveCriticalSection(&d3d9_cs);
     139    wined3d_mutex_unlock();
     140
    131141    return hr;
    132142}
     
    137147    TRACE("(%p) Relay\n", This);
    138148
    139     EnterCriticalSection(&d3d9_cs);
     149    wined3d_mutex_lock();
    140150    ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
    141     LeaveCriticalSection(&d3d9_cs);
     151    wined3d_mutex_unlock();
     152
    142153    return ret;
    143154}
     
    148159    TRACE("(%p) Relay\n", This);
    149160
    150     EnterCriticalSection(&d3d9_cs);
     161    wined3d_mutex_lock();
    151162    ret = IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
    152     LeaveCriticalSection(&d3d9_cs);
     163    wined3d_mutex_unlock();
     164
    153165    return ret;
    154166}
     
    158170    TRACE("(%p) Relay\n", This);
    159171
    160     EnterCriticalSection(&d3d9_cs);
     172    wined3d_mutex_lock();
    161173    IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
    162     LeaveCriticalSection(&d3d9_cs);
     174    wined3d_mutex_unlock();
    163175}
    164176
     
    168180    TRACE("(%p) Relay\n", This);
    169181
    170     EnterCriticalSection(&d3d9_cs);
     182    wined3d_mutex_lock();
    171183    ret = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
    172     LeaveCriticalSection(&d3d9_cs);
     184    wined3d_mutex_unlock();
     185
    173186    return ret;
    174187}
     
    180193    TRACE("(%p) Relay\n", This);
    181194
    182     EnterCriticalSection(&d3d9_cs);
     195    wined3d_mutex_lock();
    183196    ret = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
    184     LeaveCriticalSection(&d3d9_cs);
     197    wined3d_mutex_unlock();
     198
    185199    return ret;
    186200}
     
    191205    TRACE("(%p) Relay\n", This);
    192206
    193     EnterCriticalSection(&d3d9_cs);
     207    wined3d_mutex_lock();
    194208    ret = IWineD3DCubeTexture_GetLOD(This->wineD3DCubeTexture);
    195     LeaveCriticalSection(&d3d9_cs);
     209    wined3d_mutex_unlock();
     210
    196211    return ret;
    197212}
     
    202217    TRACE("(%p) Relay\n", This);
    203218
    204     EnterCriticalSection(&d3d9_cs);
     219    wined3d_mutex_lock();
    205220    ret = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
    206     LeaveCriticalSection(&d3d9_cs);
     221    wined3d_mutex_unlock();
     222
    207223    return ret;
    208224}
     
    213229    TRACE("(%p) Relay\n", This);
    214230
    215     EnterCriticalSection(&d3d9_cs);
     231    wined3d_mutex_lock();
    216232    hr = IWineD3DCubeTexture_SetAutoGenFilterType(This->wineD3DCubeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
    217     LeaveCriticalSection(&d3d9_cs);
     233    wined3d_mutex_unlock();
     234
    218235    return hr;
    219236}
     
    224241    TRACE("(%p) Relay\n", This);
    225242
    226     EnterCriticalSection(&d3d9_cs);
     243    wined3d_mutex_lock();
    227244    ret = (D3DTEXTUREFILTERTYPE) IWineD3DCubeTexture_GetAutoGenFilterType(This->wineD3DCubeTexture);
    228     LeaveCriticalSection(&d3d9_cs);
     245    wined3d_mutex_unlock();
     246
    229247    return ret;
    230248}
     
    234252    TRACE("(%p) Relay\n", This);
    235253
    236     EnterCriticalSection(&d3d9_cs);
     254    wined3d_mutex_lock();
    237255    IWineD3DCubeTexture_GenerateMipSubLevels(This->wineD3DCubeTexture);
    238     LeaveCriticalSection(&d3d9_cs);
     256    wined3d_mutex_unlock();
    239257}
    240258
     
    247265    TRACE("(%p) Relay\n", This);
    248266
    249     EnterCriticalSection(&d3d9_cs);
     267    wined3d_mutex_lock();
    250268    hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
    251     LeaveCriticalSection(&d3d9_cs);
     269    wined3d_mutex_unlock();
    252270
    253271    if (SUCCEEDED(hr))
     
    273291    TRACE("(%p) Relay\n", This);
    274292
    275     EnterCriticalSection(&d3d9_cs);
     293    wined3d_mutex_lock();
    276294    hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
    277295    if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
     
    279297       IWineD3DCubeTexture_Release(mySurface);
    280298    }
    281     LeaveCriticalSection(&d3d9_cs);
     299    wined3d_mutex_unlock();
     300
    282301    return hrc;
    283302}
     
    288307    TRACE("(%p) Relay\n", This);
    289308
    290     EnterCriticalSection(&d3d9_cs);
     309    wined3d_mutex_lock();
    291310    hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
    292     LeaveCriticalSection(&d3d9_cs);
     311    wined3d_mutex_unlock();
     312
    293313    return hr;
    294314}
     
    299319    TRACE("(%p) Relay\n", This);
    300320
    301     EnterCriticalSection(&d3d9_cs);
     321    wined3d_mutex_lock();
    302322    hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
    303     LeaveCriticalSection(&d3d9_cs);
     323    wined3d_mutex_unlock();
     324
    304325    return hr;
    305326}
     
    310331    TRACE("(%p) Relay\n", This);
    311332
    312     EnterCriticalSection(&d3d9_cs);
     333    wined3d_mutex_lock();
    313334    hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
    314     LeaveCriticalSection(&d3d9_cs);
     335    wined3d_mutex_unlock();
     336
    315337    return hr;
    316338}
     
    346368};
    347369
    348 
    349 
    350 
    351 /* IDirect3DDevice9 IDirect3DCubeTexture9 Methods follow: */
    352 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateCubeTexture(LPDIRECT3DDEVICE9EX iface,
    353                                                         UINT EdgeLength, UINT Levels, DWORD Usage,
    354                                                         D3DFORMAT Format, D3DPOOL Pool,
    355                                                         IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) {
    356 
    357     IDirect3DCubeTexture9Impl *object;
    358     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    359     HRESULT hr = D3D_OK;
    360 
    361     TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)  Shared(%p)\n", This, EdgeLength, Levels, Usage, Format, Pool, pSharedHandle);
    362 
    363     /* Allocate the storage for the device */
    364     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
    365 
    366     if (NULL == object) {
    367         ERR("(%p) allocation of CubeTexture failed\n", This);
    368         return D3DERR_OUTOFVIDEOMEMORY;
    369     }
    370     object->lpVtbl = &Direct3DCubeTexture9_Vtbl;
    371     object->ref = 1;
    372     EnterCriticalSection(&d3d9_cs);
    373     hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage,
    374             wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture, (IUnknown *)object);
    375     LeaveCriticalSection(&d3d9_cs);
    376 
    377     if (hr != D3D_OK){
    378 
    379         /* free up object */
    380         WARN("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
    381         HeapFree(GetProcessHeap(), 0, object);
    382     } else {
    383         IDirect3DDevice9Ex_AddRef(iface);
    384         object->parentDevice = iface;
    385         *ppCubeTexture = (LPDIRECT3DCUBETEXTURE9) object;
    386         TRACE("(%p) : Created cube texture %p\n", This, object);
    387     }
    388 
    389     TRACE("(%p) returning %p\n",This, *ppCubeTexture);
    390     return hr;
    391 }
     370static void STDMETHODCALLTYPE cubetexture_wined3d_object_destroyed(void *parent)
     371{
     372    HeapFree(GetProcessHeap(), 0, parent);
     373}
     374
     375static const struct wined3d_parent_ops d3d9_cubetexture_wined3d_parent_ops =
     376{
     377    cubetexture_wined3d_object_destroyed,
     378};
     379
     380HRESULT cubetexture_init(IDirect3DCubeTexture9Impl *texture, IDirect3DDevice9Impl *device,
     381        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
     382{
     383    HRESULT hr;
     384
     385    texture->lpVtbl = &Direct3DCubeTexture9_Vtbl;
     386    texture->ref = 1;
     387
     388    wined3d_mutex_lock();
     389    hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length, levels, usage,
     390            wined3dformat_from_d3dformat(format), pool, &texture->wineD3DCubeTexture,
     391            (IUnknown *)texture, &d3d9_cubetexture_wined3d_parent_ops);
     392    wined3d_mutex_unlock();
     393    if (FAILED(hr))
     394    {
     395        WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
     396        return hr;
     397    }
     398
     399    texture->parentDevice = (IDirect3DDevice9Ex *)device;
     400    IDirect3DDevice9Ex_AddRef(texture->parentDevice);
     401
     402    return D3D_OK;
     403}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_main.c

    r16477 r23571  
    3535#include "d3d9_private.h"
    3636
    37 static CRITICAL_SECTION_DEBUG d3d9_cs_debug =
    38 {
    39     0, 0, &d3d9_cs,
    40     { &d3d9_cs_debug.ProcessLocksList,
    41     &d3d9_cs_debug.ProcessLocksList },
    42     0, 0, { (DWORD_PTR)(__FILE__ ": d3d9_cs") }
    43 };
    44 CRITICAL_SECTION d3d9_cs = { &d3d9_cs_debug, -1, 0, 0, 0, 0 };
    45 
    4637WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
    4738
     
    5748    object->lpVtbl = &Direct3D9_Vtbl;
    5849    object->ref = 1;
    59     EnterCriticalSection(&d3d9_cs);
     50
     51    wined3d_mutex_lock();
    6052    object->WineD3D = WineDirect3DCreate(9, (IUnknown *)object);
    61     LeaveCriticalSection(&d3d9_cs);
     53    wined3d_mutex_unlock();
    6254
    6355    TRACE("SDKVersion = %x, Created Direct3D object @ %p, WineObj @ %p\n", SDKVersion, object, object->WineD3D);
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h

    r19678 r23571  
    44 * Copyright 2002-2003 Jason Edmeades
    55 * Copyright 2002-2003 Raphael Junqueira
    6  * Copyright 2005 Oliver Stieber 
     6 * Copyright 2005 Oliver Stieber
    77 *
    88 * This library is free software; you can redistribute it and/or
     
    5151   Internal use
    5252   =========================================================================== */
    53 extern HRESULT vdecl_convert_fvf(
    54     DWORD FVF,
    55     D3DVERTEXELEMENT9** ppVertexElements);
    56 extern CRITICAL_SECTION d3d9_cs;
    57 D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format);
    58 WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format);
     53extern HRESULT vdecl_convert_fvf(DWORD FVF, D3DVERTEXELEMENT9 **ppVertexElements) DECLSPEC_HIDDEN;
     54D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format) DECLSPEC_HIDDEN;
     55WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_HIDDEN;
    5956
    6057/* ===========================================================================
     
    151148 * Predeclare the interface implementation structures
    152149 */
    153 extern const IDirect3D9ExVtbl Direct3D9_Vtbl;
     150extern const IDirect3D9ExVtbl Direct3D9_Vtbl DECLSPEC_HIDDEN;
    154151
    155152/*****************************************************************************
     
    169166} IDirect3D9Impl;
    170167
    171 void filter_caps(D3DCAPS9* pCaps);
     168void filter_caps(D3DCAPS9* pCaps) DECLSPEC_HIDDEN;
    172169
    173170/* ---------------- */
     
    178175 * Predeclare the interface implementation structures
    179176 */
    180 extern const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl;
    181 extern const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl;
     177extern const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl DECLSPEC_HIDDEN;
     178extern const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl DECLSPEC_HIDDEN;
    182179
    183180/*****************************************************************************
     
    205202
    206203/* IDirect3DDevice9: */
    207 extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain);
    208 extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain);
    209 extern UINT     WINAPI  IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9EX iface);
    210 extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle);
    211 extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVolumeTexture(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle);
    212 extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateCubeTexture(LPDIRECT3DDEVICE9EX iface, UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle);
    213 extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVertexBuffer(LPDIRECT3DDEVICE9EX iface, UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle);
    214 extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateIndexBuffer(LPDIRECT3DDEVICE9EX iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle);
    215 extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateStateBlock(LPDIRECT3DDEVICE9EX iface, D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppSB);
    216 extern HRESULT  WINAPI  IDirect3DDevice9Impl_BeginStateBlock(LPDIRECT3DDEVICE9EX iface);
    217 extern HRESULT  WINAPI  IDirect3DDevice9Impl_EndStateBlock(LPDIRECT3DDEVICE9EX iface, IDirect3DStateBlock9** ppSB);
    218 extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9EX iface, CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl);
    219 extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexDeclaration(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexDeclaration9* pDecl);
    220 extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexDeclaration(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexDeclaration9** ppDecl);
    221 extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader);
    222 extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader);
    223 extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9** ppShader);
    224 extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST float* pConstantData, UINT Vector4fCount);
    225 extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, float* pConstantData, UINT Vector4fCount);
    226 extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST int* pConstantData, UINT Vector4iCount);
    227 extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, int* pConstantData, UINT Vector4iCount);
    228 extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST BOOL* pConstantData, UINT BoolCount);
    229 extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, BOOL* pConstantData, UINT BoolCount);
    230 extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreatePixelShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader);
    231 extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9* pShader);
    232 extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9** ppShader);
    233 extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetPixelShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST float* pConstantData, UINT Vector4fCount);
    234 extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetPixelShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, float* pConstantData, UINT Vector4fCount);
    235 extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetPixelShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST int* pConstantData, UINT Vector4iCount);
    236 extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetPixelShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, int* pConstantData, UINT Vector4iCount);
    237 extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetPixelShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST BOOL* pConstantData, UINT BoolCount);
    238 extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetPixelShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, BOOL* pConstantData, UINT BoolCount);
    239 extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9EX iface, D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery);
     204extern HRESULT WINAPI IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
     205        D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DSwapChain9 **pSwapChain) DECLSPEC_HIDDEN;
     206extern HRESULT WINAPI IDirect3DDevice9Impl_GetSwapChain(IDirect3DDevice9Ex *iface,
     207        UINT iSwapChain, IDirect3DSwapChain9 **pSwapChain) DECLSPEC_HIDDEN;
     208extern UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(IDirect3DDevice9Ex *iface) DECLSPEC_HIDDEN;
     209extern HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface,
     210        D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9 **ppSB) DECLSPEC_HIDDEN;
     211extern HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface) DECLSPEC_HIDDEN;
     212extern HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface,
     213        IDirect3DStateBlock9 **ppSB) DECLSPEC_HIDDEN;
     214extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(IDirect3DDevice9Ex *iface,
     215        IDirect3DVertexDeclaration9 *pDecl) DECLSPEC_HIDDEN;
     216extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexDeclaration(IDirect3DDevice9Ex *iface,
     217        IDirect3DVertexDeclaration9 **ppDecl) DECLSPEC_HIDDEN;
     218extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(IDirect3DDevice9Ex *iface,
     219        IDirect3DVertexShader9 *pShader) DECLSPEC_HIDDEN;
     220extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(IDirect3DDevice9Ex *iface,
     221        IDirect3DVertexShader9 **ppShader) DECLSPEC_HIDDEN;
     222extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
     223        UINT StartRegister, const float *pConstantData, UINT Vector4fCount) DECLSPEC_HIDDEN;
     224extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
     225        UINT StartRegister, float *pConstantData, UINT Vector4fCount) DECLSPEC_HIDDEN;
     226extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
     227        UINT StartRegister, const int *pConstantData, UINT Vector4iCount) DECLSPEC_HIDDEN;
     228extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
     229        UINT StartRegister, int *pConstantData, UINT Vector4iCount) DECLSPEC_HIDDEN;
     230extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
     231        UINT StartRegister, const BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN;
     232extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
     233        UINT StartRegister, BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN;
     234extern HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex *iface,
     235        IDirect3DPixelShader9 *pShader) DECLSPEC_HIDDEN;
     236extern HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(IDirect3DDevice9Ex *iface,
     237        IDirect3DPixelShader9  **ppShader) DECLSPEC_HIDDEN;
     238extern HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
     239        UINT StartRegister, const float *pConstantData, UINT Vector4fCount) DECLSPEC_HIDDEN;
     240extern HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
     241        UINT StartRegister, float *pConstantData, UINT Vector4fCount) DECLSPEC_HIDDEN;
     242extern HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
     243        UINT StartRegister, const int *pConstantData, UINT Vector4iCount) DECLSPEC_HIDDEN;
     244extern HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
     245        UINT StartRegister, int *pConstantData, UINT Vector4iCount) DECLSPEC_HIDDEN;
     246extern HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
     247        UINT StartRegister, const BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN;
     248extern HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
     249        UINT StartRegister, BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN;
     250extern HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface,
     251        D3DQUERYTYPE Type, IDirect3DQuery9 **ppQuery) DECLSPEC_HIDDEN;
    240252
    241253
     
    247259 * IDirect3DVolume9 implementation structure
    248260 */
    249 extern const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl;
    250261typedef struct IDirect3DVolume9Impl
    251262{
     
    264275} IDirect3DVolume9Impl;
    265276
     277HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height,
     278        UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool) DECLSPEC_HIDDEN;
     279
    266280/* ------------------- */
    267281/* IDirect3DSwapChain9 */
     
    292306
    293307/*****************************************************************************
    294  * Predeclare the interface implementation structures
    295  */
    296 extern const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl;
    297 
    298 /*****************************************************************************
    299308 * IDirect3DSurface9 implementation structure
    300309 */
     
    317326    IUnknown                    *forwardReference;
    318327
    319     /* Flags an implicit surface */
    320     BOOL                        isImplicit;
     328    BOOL                        getdc_supported;
    321329} IDirect3DSurface9Impl;
     330
     331HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *device,
     332        UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
     333        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) DECLSPEC_HIDDEN;
    322334
    323335/* ---------------------- */
     
    343355} IDirect3DVertexBuffer9Impl;
    344356
     357HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
     358        UINT size, UINT usage, DWORD fvf, D3DPOOL pool) DECLSPEC_HIDDEN;
     359
    345360/* --------------------- */
    346361/* IDirect3DIndexBuffer9 */
     
    364379} IDirect3DIndexBuffer9Impl;
    365380
     381HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
     382        UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
     383
    366384/* --------------------- */
    367385/* IDirect3DBaseTexture9 */
     
    379397    /* IDirect3DResource9 fields */
    380398    IWineD3DBaseTexture    *wineD3DBaseTexture;
    381    
    382399} IDirect3DBaseTexture9Impl;
    383400
     
    402419}  IDirect3DCubeTexture9Impl;
    403420
     421HRESULT cubetexture_init(IDirect3DCubeTexture9Impl *texture, IDirect3DDevice9Impl *device,
     422        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
    404423
    405424/* ----------------- */
     
    423442} IDirect3DTexture9Impl;
    424443
     444HRESULT texture_init(IDirect3DTexture9Impl *texture, IDirect3DDevice9Impl *device,
     445        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
     446
    425447/* ----------------------- */
    426448/* IDirect3DVolumeTexture9 */
     
    442464    LPDIRECT3DDEVICE9EX       parentDevice;
    443465} IDirect3DVolumeTexture9Impl;
     466
     467HRESULT volumetexture_init(IDirect3DVolumeTexture9Impl *texture, IDirect3DDevice9Impl *device,
     468        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
    444469
    445470/* ----------------------- */
     
    486511} IDirect3DVertexDeclaration9Impl;
    487512
    488 void IDirect3DVertexDeclaration9Impl_Destroy(LPDIRECT3DVERTEXDECLARATION9 iface);
     513void IDirect3DVertexDeclaration9Impl_Destroy(LPDIRECT3DVERTEXDECLARATION9 iface) DECLSPEC_HIDDEN;
     514HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration,
     515        IDirect3DDevice9Impl *device, const D3DVERTEXELEMENT9 *elements) DECLSPEC_HIDDEN;
    489516
    490517/* ---------------------- */
     
    507534} IDirect3DVertexShader9Impl;
    508535
     536HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader,
     537        IDirect3DDevice9Impl *device, const DWORD *byte_code) DECLSPEC_HIDDEN;
     538
    509539#define D3D9_MAX_VERTEX_SHADER_CONSTANTF 256
     540#define D3D9_MAX_SIMULTANEOUS_RENDERTARGETS 4
    510541
    511542/* --------------------- */
     
    528559} IDirect3DPixelShader9Impl;
    529560
     561HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader,
     562        IDirect3DDevice9Impl *device, const DWORD *byte_code) DECLSPEC_HIDDEN;
     563
    530564/* --------------- */
    531565/* IDirect3DQuery9 */
     
    549583
    550584/* Callbacks */
    551 extern ULONG WINAPI D3D9CB_DestroySwapChain (IWineD3DSwapChain *pSwapChain);
    552 extern ULONG WINAPI D3D9CB_DestroyDepthStencilSurface (IWineD3DSurface *pSurface);
    553 extern ULONG WINAPI D3D9CB_DestroyRenderTarget (IWineD3DSurface *pSurface);
    554 extern ULONG WINAPI D3D9CB_DestroySurface(IWineD3DSurface *pSurface);
    555 extern ULONG WINAPI D3D9CB_DestroyVolume(IWineD3DVolume *pVolume);
     585extern ULONG WINAPI D3D9CB_DestroySwapChain (IWineD3DSwapChain *pSwapChain) DECLSPEC_HIDDEN;
    556586
    557587#endif /* __WINE_D3D9_PRIVATE_H */
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c

    r22496 r23571  
    4545    {
    4646        case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
    47         case WINED3DFMT_R8G8B8: return D3DFMT_R8G8B8;
    48         case WINED3DFMT_A8R8G8B8: return D3DFMT_A8R8G8B8;
    49         case WINED3DFMT_X8R8G8B8: return D3DFMT_X8R8G8B8;
    50         case WINED3DFMT_R5G6B5: return D3DFMT_R5G6B5;
    51         case WINED3DFMT_X1R5G5B5: return D3DFMT_X1R5G5B5;
    52         case WINED3DFMT_A1R5G5B5: return D3DFMT_A1R5G5B5;
    53         case WINED3DFMT_A4R4G4B4: return D3DFMT_A4R4G4B4;
    54         case WINED3DFMT_R3G3B2: return D3DFMT_R3G3B2;
     47        case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
     48        case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
     49        case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
     50        case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
     51        case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
     52        case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
     53        case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
     54        case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
    5555        case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
    56         case WINED3DFMT_A8R3G3B2: return D3DFMT_A8R3G3B2;
    57         case WINED3DFMT_X4R4G4B4: return D3DFMT_X4R4G4B4;
     56        case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
     57        case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
    5858        case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
    5959        case WINED3DFMT_R8G8B8A8_UNORM: return D3DFMT_A8B8G8R8;
    60         case WINED3DFMT_X8B8G8R8: return D3DFMT_X8B8G8R8;
     60        case WINED3DFMT_R8G8B8X8_UNORM: return D3DFMT_X8B8G8R8;
    6161        case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
    62         case WINED3DFMT_A2R10G10B10: return D3DFMT_A2R10G10B10;
     62        case WINED3DFMT_B10G10R10A2_UNORM: return D3DFMT_A2R10G10B10;
    6363        case WINED3DFMT_R16G16B16A16_UNORM: return D3DFMT_A16B16G16R16;
    64         case WINED3DFMT_A8P8: return D3DFMT_A8P8;
    65         case WINED3DFMT_P8: return D3DFMT_P8;
    66         case WINED3DFMT_L8: return D3DFMT_L8;
    67         case WINED3DFMT_A8L8: return D3DFMT_A8L8;
    68         case WINED3DFMT_A4L4: return D3DFMT_A4L4;
     64        case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
     65        case WINED3DFMT_P8_UINT: return D3DFMT_P8;
     66        case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
     67        case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
     68        case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
    6969        case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
    70         case WINED3DFMT_L6V5U5: return D3DFMT_L6V5U5;
    71         case WINED3DFMT_X8L8V8U8: return D3DFMT_X8L8V8U8;
     70        case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
     71        case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
    7272        case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
    7373        case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
    74         case WINED3DFMT_A2W10V10U10: return D3DFMT_A2W10V10U10;
     74        case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
    7575        case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
    76         case WINED3DFMT_D32: return D3DFMT_D32;
    77         case WINED3DFMT_D15S1: return D3DFMT_D15S1;
    78         case WINED3DFMT_D24S8: return D3DFMT_D24S8;
    79         case WINED3DFMT_D24X8: return D3DFMT_D24X8;
    80         case WINED3DFMT_D24X4S4: return D3DFMT_D24X4S4;
     76        case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
     77        case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
     78        case WINED3DFMT_S8_UINT_D24_UNORM: return D3DFMT_D24S8;
     79        case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
     80        case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
    8181        case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
    82         case WINED3DFMT_L16: return D3DFMT_L16;
    83         case WINED3DFMT_D32F_LOCKABLE: return D3DFMT_D32F_LOCKABLE;
    84         case WINED3DFMT_D24FS8: return D3DFMT_D24FS8;
     82        case WINED3DFMT_L16_UNORM: return D3DFMT_L16;
     83        case WINED3DFMT_D32_FLOAT: return D3DFMT_D32F_LOCKABLE;
     84        case WINED3DFMT_S8_UINT_D24_FLOAT: return D3DFMT_D24FS8;
    8585        case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
    8686        case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
     
    9393        case WINED3DFMT_R32G32_FLOAT: return D3DFMT_G32R32F;
    9494        case WINED3DFMT_R32G32B32A32_FLOAT: return D3DFMT_A32B32G32R32F;
    95         case WINED3DFMT_CxV8U8: return D3DFMT_CxV8U8;
     95        case WINED3DFMT_R8G8_SNORM_Cx: return D3DFMT_CxV8U8;
    9696        default:
    9797            FIXME("Unhandled WINED3DFORMAT %#x\n", format);
     
    110110    {
    111111        case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
    112         case D3DFMT_R8G8B8: return WINED3DFMT_R8G8B8;
    113         case D3DFMT_A8R8G8B8: return WINED3DFMT_A8R8G8B8;
    114         case D3DFMT_X8R8G8B8: return WINED3DFMT_X8R8G8B8;
    115         case D3DFMT_R5G6B5: return WINED3DFMT_R5G6B5;
    116         case D3DFMT_X1R5G5B5: return WINED3DFMT_X1R5G5B5;
    117         case D3DFMT_A1R5G5B5: return WINED3DFMT_A1R5G5B5;
    118         case D3DFMT_A4R4G4B4: return WINED3DFMT_A4R4G4B4;
    119         case D3DFMT_R3G3B2: return WINED3DFMT_R3G3B2;
     112        case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
     113        case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
     114        case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
     115        case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
     116        case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
     117        case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
     118        case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
     119        case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
    120120        case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
    121         case D3DFMT_A8R3G3B2: return WINED3DFMT_A8R3G3B2;
    122         case D3DFMT_X4R4G4B4: return WINED3DFMT_X4R4G4B4;
     121        case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
     122        case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
    123123        case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
    124124        case D3DFMT_A8B8G8R8: return WINED3DFMT_R8G8B8A8_UNORM;
    125         case D3DFMT_X8B8G8R8: return WINED3DFMT_X8B8G8R8;
     125        case D3DFMT_X8B8G8R8: return WINED3DFMT_R8G8B8X8_UNORM;
    126126        case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
    127         case D3DFMT_A2R10G10B10: return WINED3DFMT_A2R10G10B10;
     127        case D3DFMT_A2R10G10B10: return WINED3DFMT_B10G10R10A2_UNORM;
    128128        case D3DFMT_A16B16G16R16: return WINED3DFMT_R16G16B16A16_UNORM;
    129         case D3DFMT_A8P8: return WINED3DFMT_A8P8;
    130         case D3DFMT_P8: return WINED3DFMT_P8;
    131         case D3DFMT_L8: return WINED3DFMT_L8;
    132         case D3DFMT_A8L8: return WINED3DFMT_A8L8;
    133         case D3DFMT_A4L4: return WINED3DFMT_A4L4;
     129        case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
     130        case D3DFMT_P8: return WINED3DFMT_P8_UINT;
     131        case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
     132        case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
     133        case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
    134134        case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
    135         case D3DFMT_L6V5U5: return WINED3DFMT_L6V5U5;
    136         case D3DFMT_X8L8V8U8: return WINED3DFMT_X8L8V8U8;
     135        case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
     136        case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
    137137        case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
    138138        case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
    139         case D3DFMT_A2W10V10U10: return WINED3DFMT_A2W10V10U10;
     139        case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
    140140        case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
    141         case D3DFMT_D32: return WINED3DFMT_D32;
    142         case D3DFMT_D15S1: return WINED3DFMT_D15S1;
    143         case D3DFMT_D24S8: return WINED3DFMT_D24S8;
    144         case D3DFMT_D24X8: return WINED3DFMT_D24X8;
    145         case D3DFMT_D24X4S4: return WINED3DFMT_D24X4S4;
     141        case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
     142        case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
     143        case D3DFMT_D24S8: return WINED3DFMT_S8_UINT_D24_UNORM;
     144        case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
     145        case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
    146146        case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
    147         case D3DFMT_L16: return WINED3DFMT_L16;
    148         case D3DFMT_D32F_LOCKABLE: return WINED3DFMT_D32F_LOCKABLE;
    149         case D3DFMT_D24FS8: return WINED3DFMT_D24FS8;
     147        case D3DFMT_L16: return WINED3DFMT_L16_UNORM;
     148        case D3DFMT_D32F_LOCKABLE: return WINED3DFMT_D32_FLOAT;
     149        case D3DFMT_D24FS8: return WINED3DFMT_S8_UINT_D24_FLOAT;
    150150        case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
    151151        case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
     
    158158        case D3DFMT_G32R32F: return WINED3DFMT_R32G32_FLOAT;
    159159        case D3DFMT_A32B32G32R32F: return WINED3DFMT_R32G32B32A32_FLOAT;
    160         case D3DFMT_CxV8U8: return WINED3DFMT_CxV8U8;
     160        case D3DFMT_CxV8U8: return WINED3DFMT_R8G8_SNORM_Cx;
    161161        default:
    162162            FIXME("Unhandled D3DFORMAT %#x\n", format);
     
    258258      This->inDestruction = TRUE;
    259259
    260       EnterCriticalSection(&d3d9_cs);
     260      wined3d_mutex_lock();
    261261      for(i = 0; i < This->numConvertedDecls; i++) {
    262262          /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
     
    267267      HeapFree(GetProcessHeap(), 0, This->convertedDecls);
    268268
    269       IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroyDepthStencilSurface, D3D9CB_DestroySwapChain);
     269      IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroySwapChain);
    270270      IWineD3DDevice_Release(This->WineD3DDevice);
    271       LeaveCriticalSection(&d3d9_cs);
     271      wined3d_mutex_unlock();
     272
    272273      HeapFree(GetProcessHeap(), 0, This);
    273274    }
     
    281282    TRACE("(%p)\n", This);
    282283
    283     EnterCriticalSection(&d3d9_cs);
     284    wined3d_mutex_lock();
    284285    hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
    285     LeaveCriticalSection(&d3d9_cs);
     286    wined3d_mutex_unlock();
     287
    286288    if(hr == WINED3D_OK && This->notreset) {
    287289        TRACE("D3D9 Device is marked not reset\n");
     
    297299    TRACE("(%p) Relay\n", This);
    298300
    299     EnterCriticalSection(&d3d9_cs);
     301    wined3d_mutex_lock();
    300302    hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
    301     LeaveCriticalSection(&d3d9_cs);
     303    wined3d_mutex_unlock();
     304
    302305    return hr;
    303306}
     
    308311    TRACE("(%p) : Relay\n", This);
    309312
    310     EnterCriticalSection(&d3d9_cs);
     313    wined3d_mutex_lock();
    311314    hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
    312     LeaveCriticalSection(&d3d9_cs);
     315    wined3d_mutex_unlock();
     316
    313317    return hr;
    314318}
     
    325329    }
    326330
    327     EnterCriticalSection(&d3d9_cs);
     331    wined3d_mutex_lock();
    328332    hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
    329333    if (hr == D3D_OK && pWineD3D != NULL)
     
    336340    }
    337341    TRACE("(%p) returning %p\n", This, *ppD3D9);
    338     LeaveCriticalSection(&d3d9_cs);
     342    wined3d_mutex_unlock();
     343
    339344    return hr;
    340345}
     
    355360
    356361    memset(pCaps, 0, sizeof(*pCaps));
    357     EnterCriticalSection(&d3d9_cs);
     362
     363    wined3d_mutex_lock();
    358364    hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
    359     LeaveCriticalSection(&d3d9_cs);
     365    wined3d_mutex_unlock();
     366
    360367    WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
    361368    HeapFree(GetProcessHeap(), 0, pWineCaps);
     
    375382    TRACE("(%p) Relay\n", This);
    376383
    377     EnterCriticalSection(&d3d9_cs);
     384    wined3d_mutex_lock();
    378385    hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
    379     LeaveCriticalSection(&d3d9_cs);
     386    wined3d_mutex_unlock();
    380387
    381388    if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
     
    389396    TRACE("(%p) Relay\n", This);
    390397
    391     EnterCriticalSection(&d3d9_cs);
     398    wined3d_mutex_lock();
    392399    hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
    393     LeaveCriticalSection(&d3d9_cs);
     400    wined3d_mutex_unlock();
     401
    394402    return hr;
    395403}
     
    406414    }
    407415
    408     EnterCriticalSection(&d3d9_cs);
     416    wined3d_mutex_lock();
    409417    hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wineD3DSurface);
    410     LeaveCriticalSection(&d3d9_cs);
     418    wined3d_mutex_unlock();
     419
    411420    return hr;
    412421}
     
    416425    TRACE("(%p) Relay\n", This);
    417426
    418     EnterCriticalSection(&d3d9_cs);
     427    wined3d_mutex_lock();
    419428    IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
    420     LeaveCriticalSection(&d3d9_cs);
     429    wined3d_mutex_unlock();
    421430}
    422431
     
    426435    TRACE("(%p) Relay\n", This);
    427436
    428     EnterCriticalSection(&d3d9_cs);
     437    wined3d_mutex_lock();
    429438    ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
    430     LeaveCriticalSection(&d3d9_cs);
     439    wined3d_mutex_unlock();
     440
    431441    return ret;
    432442}
     
    507517     * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
    508518     */
    509     EnterCriticalSection(&d3d9_cs);
    510     IWineD3DDevice_SetIndices(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
     519    wined3d_mutex_lock();
     520    IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
    511521    for(i = 0; i < 16; i++) {
    512522        IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
     
    520530        WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
    521531        This->notreset = TRUE;
    522         LeaveCriticalSection(&d3d9_cs);
     532        wined3d_mutex_unlock();
     533
    523534        return WINED3DERR_INVALIDCALL;
    524535    }
     
    562573    }
    563574
    564     LeaveCriticalSection(&d3d9_cs);
     575    wined3d_mutex_unlock();
    565576
    566577    return hr;
     
    573584    TRACE("(%p) Relay\n", This);
    574585
    575     EnterCriticalSection(&d3d9_cs);
     586    wined3d_mutex_lock();
    576587    hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
    577     LeaveCriticalSection(&d3d9_cs);
     588    wined3d_mutex_unlock();
     589
    578590    return hr;
    579591 }
     
    586598    TRACE("(%p) Relay\n", This);
    587599
    588     EnterCriticalSection(&d3d9_cs);
     600    wined3d_mutex_lock();
    589601    rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
    590602    if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
     
    592604        IWineD3DSurface_Release(retSurface);
    593605    }
    594     LeaveCriticalSection(&d3d9_cs);
     606    wined3d_mutex_unlock();
     607
    595608    return rc;
    596609}
     
    600613    TRACE("(%p) Relay\n", This);
    601614
    602     EnterCriticalSection(&d3d9_cs);
     615    wined3d_mutex_lock();
    603616    hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
    604     LeaveCriticalSection(&d3d9_cs);
     617    wined3d_mutex_unlock();
     618
    605619    return hr;
    606620}
     
    611625    TRACE("(%p) Relay\n", This);
    612626
    613     EnterCriticalSection(&d3d9_cs);
     627    wined3d_mutex_lock();
    614628    hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
    615     LeaveCriticalSection(&d3d9_cs);
    616     return hr;
    617 }
    618 
    619 static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
    620    
     629    wined3d_mutex_unlock();
     630
     631    return hr;
     632}
     633
     634static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
     635        DWORD Flags, const D3DGAMMARAMP *pRamp)
     636{
    621637    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    622638    TRACE("(%p) Relay\n", This);
    623639
    624     EnterCriticalSection(&d3d9_cs);
    625640    /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
     641    wined3d_mutex_lock();
    626642    IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
    627     LeaveCriticalSection(&d3d9_cs);
     643    wined3d_mutex_unlock();
    628644}
    629645
     
    632648    TRACE("(%p) Relay\n", This);
    633649
    634     EnterCriticalSection(&d3d9_cs);
    635650    /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
     651    wined3d_mutex_lock();
    636652    IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
    637     LeaveCriticalSection(&d3d9_cs);
    638 }
    639 
     653    wined3d_mutex_unlock();
     654}
     655
     656static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *iface,
     657        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
     658        D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
     659{
     660    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     661    IDirect3DTexture9Impl *object;
     662    HRESULT hr;
     663
     664    TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
     665            iface, width, height, levels, usage, format, pool, texture, shared_handle);
     666
     667    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     668    if (!object)
     669    {
     670        ERR("Failed to allocate texture memory.\n");
     671        return D3DERR_OUTOFVIDEOMEMORY;
     672    }
     673
     674    hr = texture_init(object, This, width, height, levels, usage, format, pool);
     675    if (FAILED(hr))
     676    {
     677        WARN("Failed to initialize texture, hr %#x.\n", hr);
     678        HeapFree(GetProcessHeap(), 0, object);
     679        return hr;
     680    }
     681
     682    TRACE("Created texture %p.\n", object);
     683    *texture = (IDirect3DTexture9 *)object;
     684
     685    return D3D_OK;
     686}
     687
     688static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
     689        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
     690        D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
     691{
     692    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     693    IDirect3DVolumeTexture9Impl *object;
     694    HRESULT hr;
     695
     696    TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
     697            iface, width, height, depth, levels);
     698    TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
     699            usage, format, pool, texture, shared_handle);
     700
     701    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     702    if (!object)
     703    {
     704        ERR("Failed to allocate volume texture memory.\n");
     705        return D3DERR_OUTOFVIDEOMEMORY;
     706    }
     707
     708    hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
     709    if (FAILED(hr))
     710    {
     711        WARN("Failed to initialize volume texture, hr %#x.\n", hr);
     712        HeapFree(GetProcessHeap(), 0, object);
     713        return hr;
     714    }
     715
     716    TRACE("Created volume texture %p.\n", object);
     717    *texture = (IDirect3DVolumeTexture9 *)object;
     718
     719    return D3D_OK;
     720}
     721
     722static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex *iface,
     723        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
     724        IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
     725{
     726    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     727    IDirect3DCubeTexture9Impl *object;
     728    HRESULT hr;
     729
     730    TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
     731            iface, edge_length, levels, usage, format, pool, texture, shared_handle);
     732
     733    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     734    if (!object)
     735    {
     736        ERR("Failed to allocate cube texture memory.\n");
     737        return D3DERR_OUTOFVIDEOMEMORY;
     738    }
     739
     740    hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
     741    if (FAILED(hr))
     742    {
     743        WARN("Failed to initialize cube texture, hr %#x.\n", hr);
     744        HeapFree(GetProcessHeap(), 0, object);
     745        return hr;
     746    }
     747
     748    TRACE("Created cube texture %p.\n", object);
     749    *texture = (IDirect3DCubeTexture9 *)object;
     750
     751    return D3D_OK;
     752}
     753
     754static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
     755        DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer, HANDLE *shared_handle)
     756{
     757    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     758    IDirect3DVertexBuffer9Impl *object;
     759    HRESULT hr;
     760
     761    TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
     762            iface, size, usage, fvf, pool, buffer, shared_handle);
     763
     764    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     765    if (!object)
     766    {
     767        ERR("Failed to allocate buffer memory.\n");
     768        return D3DERR_OUTOFVIDEOMEMORY;
     769    }
     770
     771    hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
     772    if (FAILED(hr))
     773    {
     774        WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
     775        HeapFree(GetProcessHeap(), 0, object);
     776        return hr;
     777    }
     778
     779    TRACE("Created vertex buffer %p.\n", object);
     780    *buffer = (IDirect3DVertexBuffer9 *)object;
     781
     782    return D3D_OK;
     783}
     784
     785static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
     786        D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer, HANDLE *shared_handle)
     787{
     788    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     789    IDirect3DIndexBuffer9Impl *object;
     790    HRESULT hr;
     791
     792    TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
     793            iface, size, usage, format, pool, buffer, shared_handle);
     794
     795    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     796    if (!object)
     797    {
     798        ERR("Failed to allocate buffer memory.\n");
     799        return D3DERR_OUTOFVIDEOMEMORY;
     800    }
     801
     802    hr = indexbuffer_init(object, This, size, usage, format, pool);
     803    if (FAILED(hr))
     804    {
     805        WARN("Failed to initialize index buffer, hr %#x.\n", hr);
     806        HeapFree(GetProcessHeap(), 0, object);
     807        return hr;
     808    }
     809
     810    TRACE("Created index buffer %p.\n", object);
     811    *buffer = (IDirect3DIndexBuffer9 *)object;
     812
     813    return D3D_OK;
     814}
    640815
    641816static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
     
    643818        UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
    644819{
    645     HRESULT hrc;
     820    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    646821    IDirect3DSurface9Impl *object;
    647     IDirect3DDevice9Impl  *This = (IDirect3DDevice9Impl *)iface;
    648     TRACE("(%p) Relay\n", This);
    649    
    650     if(MultisampleQuality > 0){
    651         FIXME("MultisampleQuality set to %d, bstituting 0\n", MultisampleQuality);
    652     /*
    653     MultisampleQuality
    654  [in] Quality level. The valid range is between zero and one less than the level returned by pQualityLevels used by IDirect3D9::CheckDeviceMultiSampleType. Passing a larger value returns the error D3DERR_INVALIDCALL. The MultisampleQuality values of paired render targets, depth stencil surfaces, and the MultiSample type must all match.
    655  */
    656  
    657         MultisampleQuality=0;
    658     }
    659     /*FIXME: Check MAX bounds of MultisampleQuality*/
    660 
    661     /* Allocate the storage for the device */
     822    HRESULT hr;
     823
     824    TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
     825
    662826    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
    663     if (NULL == object) {
    664         FIXME("Allocation of memory failed\n");
     827    if (!object)
     828    {
     829        FIXME("Failed to allocate surface memory.\n");
    665830        return D3DERR_OUTOFVIDEOMEMORY;
    666831    }
    667832
    668     object->lpVtbl = &Direct3DSurface9_Vtbl;
    669     object->ref = 1;
    670 
    671     TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
    672 
    673     EnterCriticalSection(&d3d9_cs);
    674     hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
    675             Lockable, Discard, Level, &object->wineD3DSurface, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL)Pool,
    676             MultiSample, MultisampleQuality, SURFACE_OPENGL, (IUnknown *)object);
    677     LeaveCriticalSection(&d3d9_cs);
    678 
    679     if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
    680 
    681        /* free up object */
    682         FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
     833    hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
     834            Level, Usage, Pool, MultiSample, MultisampleQuality);
     835    if (FAILED(hr))
     836    {
     837        WARN("Failed to initialize surface, hr %#x.\n", hr);
    683838        HeapFree(GetProcessHeap(), 0, object);
    684     } else {
    685         IDirect3DDevice9Ex_AddRef(iface);
    686         object->parentDevice = iface;
    687         TRACE("(%p) : Created surface %p\n", This, object);
    688         *ppSurface = (LPDIRECT3DSURFACE9) object;
    689     }
    690     return hrc;
    691 }
    692 
    693 
    694 
    695 static HRESULT  WINAPI  IDirect3DDevice9Impl_CreateRenderTarget(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
    696                                                          D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
    697                                                          DWORD MultisampleQuality, BOOL Lockable,
    698                                                          IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
     839        return hr;
     840    }
     841
     842    TRACE("Created surface %p.\n", object);
     843    *ppSurface = (IDirect3DSurface9 *)object;
     844
     845    return D3D_OK;
     846}
     847
     848static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width, UINT Height,
     849        D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable,
     850        IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
     851{
    699852    HRESULT hr;
    700853    TRACE("Relay\n");
     
    725878    TRACE("(%p) Relay\n" , This);
    726879
    727     EnterCriticalSection(&d3d9_cs);
     880    wined3d_mutex_lock();
    728881    hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
    729     LeaveCriticalSection(&d3d9_cs);
     882    wined3d_mutex_unlock();
     883
    730884    return hr;
    731885}
     
    736890    TRACE("(%p) Relay\n" , This);
    737891
    738     EnterCriticalSection(&d3d9_cs);
     892    wined3d_mutex_lock();
    739893    hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice,  ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
    740     LeaveCriticalSection(&d3d9_cs);
     894    wined3d_mutex_unlock();
     895
    741896    return hr;
    742897}
     
    749904    TRACE("(%p)->(%p,%p)\n" , This, renderTarget, destSurface);
    750905
    751     EnterCriticalSection(&d3d9_cs);
     906    wined3d_mutex_lock();
    752907    hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
    753     LeaveCriticalSection(&d3d9_cs);
     908    wined3d_mutex_unlock();
     909
    754910    return hr;
    755911}
     
    761917    TRACE("(%p) Relay\n" , This);
    762918
    763     EnterCriticalSection(&d3d9_cs);
     919    wined3d_mutex_lock();
    764920    hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
    765     LeaveCriticalSection(&d3d9_cs);
     921    wined3d_mutex_unlock();
     922
    766923    return hr;
    767924}
     
    774931
    775932    TRACE("(%p)->(%p,%p,%p,%p,%d)\n" , This, src, pSourceRect, dst, pDestRect, Filter);
    776     EnterCriticalSection(&d3d9_cs);
     933
     934    wined3d_mutex_lock();
    777935    hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
    778     LeaveCriticalSection(&d3d9_cs);
     936    wined3d_mutex_unlock();
     937
    779938    return hr;
    780939}
     
    790949    TRACE("(%p) Relay\n" , This);
    791950
    792     EnterCriticalSection(&d3d9_cs);
     951    wined3d_mutex_lock();
     952
    793953    IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
    794954    usage = desc.usage;
     
    800960     */
    801961    if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != WINED3DPOOL_DEFAULT || restype != WINED3DRTYPE_SURFACE)) {
    802         LeaveCriticalSection(&d3d9_cs);
     962        wined3d_mutex_unlock();
    803963        WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
    804964        return D3DERR_INVALIDCALL;
     
    808968    /* Note: D3DRECT is compatible with WINED3DRECT */
    809969    hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
    810     LeaveCriticalSection(&d3d9_cs);
     970
     971    wined3d_mutex_unlock();
     972
    811973    return hr;
    812974}
     
    818980        FIXME("Attempting to create a managed offscreen plain surface\n");
    819981        return D3DERR_INVALIDCALL;
    820     }   
     982    }
    821983        /*
    822984        'Off-screen plain surfaces are always lockable, regardless of their pool types.'
     
    824986        D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
    825987        Why, their always lockable?
    826         should I change the usage to dynamic?       
     988        should I change the usage to dynamic?
    827989        */
    828990    hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
     
    8401002    TRACE("(%p) Relay\n" , This);
    8411003
    842     EnterCriticalSection(&d3d9_cs);
     1004    if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
     1005    {
     1006        WARN("Invalid index %u specified.\n", RenderTargetIndex);
     1007        return D3DERR_INVALIDCALL;
     1008    }
     1009
     1010    wined3d_mutex_lock();
    8431011    hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL);
    844     LeaveCriticalSection(&d3d9_cs);
     1012    wined3d_mutex_unlock();
     1013
    8451014    return hr;
    8461015}
     
    8571026    }
    8581027
    859     EnterCriticalSection(&d3d9_cs);
     1028    if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
     1029    {
     1030        WARN("Invalid index %u specified.\n", RenderTargetIndex);
     1031        return D3DERR_INVALIDCALL;
     1032    }
     1033
     1034    wined3d_mutex_lock();
     1035
    8601036    hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
    8611037
     
    8741050    }
    8751051
    876     LeaveCriticalSection(&d3d9_cs);
     1052    wined3d_mutex_unlock();
    8771053
    8781054    return hr;
     
    8861062    TRACE("(%p) Relay\n" , This);
    8871063
    888 
    889     EnterCriticalSection(&d3d9_cs);
     1064    pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
     1065
     1066    wined3d_mutex_lock();
    8901067    hr = IDirect3DDevice9_GetDepthStencilSurface(iface, &pOldSurface);
    8911068    if (D3D_OK==hr) {
     
    8991076        IDirect3DSurface9_AddRef(pZStencilSurface);
    9001077    }
    901     LeaveCriticalSection(&d3d9_cs);
     1078    wined3d_mutex_unlock();
     1079
    9021080    return hr;
    9031081}
     
    9131091    }
    9141092
    915     EnterCriticalSection(&d3d9_cs);
     1093    wined3d_mutex_lock();
    9161094    hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
    9171095    if (hr == WINED3D_OK) {
     
    9231101        *ppZStencilSurface = NULL;
    9241102    }
    925     LeaveCriticalSection(&d3d9_cs);
     1103    wined3d_mutex_unlock();
     1104
    9261105    return hr;
    9271106}
     
    9321111    TRACE("(%p) Relay\n" , This);
    9331112
    934     EnterCriticalSection(&d3d9_cs);
     1113    wined3d_mutex_lock();
    9351114    hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
    936     LeaveCriticalSection(&d3d9_cs);
     1115    wined3d_mutex_unlock();
     1116
    9371117    return hr;
    9381118}
     
    9431123    TRACE("(%p) Relay\n" , This);
    9441124
    945     EnterCriticalSection(&d3d9_cs);
     1125    wined3d_mutex_lock();
    9461126    hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
    947     LeaveCriticalSection(&d3d9_cs);
     1127    wined3d_mutex_unlock();
     1128
    9481129    return hr;
    9491130}
     
    9551136
    9561137    /* Note: D3DRECT is compatible with WINED3DRECT */
    957     EnterCriticalSection(&d3d9_cs);
     1138    wined3d_mutex_lock();
    9581139    hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
    959     LeaveCriticalSection(&d3d9_cs);
     1140    wined3d_mutex_unlock();
     1141
    9601142    return hr;
    9611143}
     
    9671149
    9681150    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
    969     EnterCriticalSection(&d3d9_cs);
     1151    wined3d_mutex_lock();
    9701152    hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
    971     LeaveCriticalSection(&d3d9_cs);
     1153    wined3d_mutex_unlock();
     1154
    9721155    return hr;
    9731156}
     
    9791162    TRACE("(%p) Relay\n" , This);
    9801163
    981     EnterCriticalSection(&d3d9_cs);
    9821164    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
     1165    wined3d_mutex_lock();
    9831166    hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
    984     LeaveCriticalSection(&d3d9_cs);
     1167    wined3d_mutex_unlock();
    9851168
    9861169    return hr;
     
    9931176
    9941177    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
    995     EnterCriticalSection(&d3d9_cs);
     1178    wined3d_mutex_lock();
    9961179    hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
    997     LeaveCriticalSection(&d3d9_cs);
     1180    wined3d_mutex_unlock();
     1181
    9981182    return hr;
    9991183}
     
    10051189
    10061190    /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
    1007     EnterCriticalSection(&d3d9_cs);
     1191    wined3d_mutex_lock();
    10081192    hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
    1009     LeaveCriticalSection(&d3d9_cs);
     1193    wined3d_mutex_unlock();
     1194
    10101195    return hr;
    10111196}
     
    10171202
    10181203    /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
    1019     EnterCriticalSection(&d3d9_cs);
     1204    wined3d_mutex_lock();
    10201205    hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
    1021     LeaveCriticalSection(&d3d9_cs);
     1206    wined3d_mutex_unlock();
     1207
    10221208    return hr;
    10231209}
     
    10291215
    10301216    /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
    1031     EnterCriticalSection(&d3d9_cs);
     1217    wined3d_mutex_lock();
    10321218    hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
    1033     LeaveCriticalSection(&d3d9_cs);
     1219    wined3d_mutex_unlock();
     1220
    10341221    return hr;
    10351222}
     
    10411228
    10421229    /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
    1043     EnterCriticalSection(&d3d9_cs);
     1230    wined3d_mutex_lock();
    10441231    hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
    1045     LeaveCriticalSection(&d3d9_cs);
     1232    wined3d_mutex_unlock();
     1233
    10461234    return hr;
    10471235}
     
    10531241
    10541242    /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
    1055     EnterCriticalSection(&d3d9_cs);
     1243    wined3d_mutex_lock();
    10561244    hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
    1057     LeaveCriticalSection(&d3d9_cs);
     1245    wined3d_mutex_unlock();
     1246
    10581247    return hr;
    10591248}
     
    10651254
    10661255    /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
    1067     EnterCriticalSection(&d3d9_cs);
     1256    wined3d_mutex_lock();
    10681257    hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
    1069     LeaveCriticalSection(&d3d9_cs);
     1258    wined3d_mutex_unlock();
     1259
    10701260    return hr;
    10711261}
     
    10761266    TRACE("(%p) Relay\n" , This);
    10771267
    1078     EnterCriticalSection(&d3d9_cs);
     1268    wined3d_mutex_lock();
    10791269    hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
    1080     LeaveCriticalSection(&d3d9_cs);
     1270    wined3d_mutex_unlock();
     1271
    10811272    return hr;
    10821273}
     
    10871278    TRACE("(%p) Relay\n" , This);
    10881279
    1089     EnterCriticalSection(&d3d9_cs);
     1280    wined3d_mutex_lock();
    10901281    hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
    1091     LeaveCriticalSection(&d3d9_cs);
     1282    wined3d_mutex_unlock();
     1283
    10921284    return hr;
    10931285}
     
    10981290    TRACE("(%p) Relay\n" , This);
    10991291
    1100     EnterCriticalSection(&d3d9_cs);
     1292    wined3d_mutex_lock();
    11011293    hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
    1102     LeaveCriticalSection(&d3d9_cs);
     1294    wined3d_mutex_unlock();
     1295
    11031296    return hr;
    11041297}
     
    11091302    TRACE("(%p) Relay\n" , This);
    11101303
    1111     EnterCriticalSection(&d3d9_cs);
     1304    wined3d_mutex_lock();
    11121305    hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
    1113     LeaveCriticalSection(&d3d9_cs);
     1306    wined3d_mutex_unlock();
     1307
    11141308    return hr;
    11151309}
     
    11201314    TRACE("(%p) Relay\n" , This);
    11211315
    1122     EnterCriticalSection(&d3d9_cs);
     1316    wined3d_mutex_lock();
    11231317    hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
    1124     LeaveCriticalSection(&d3d9_cs);
     1318    wined3d_mutex_unlock();
     1319
    11251320    return hr;
    11261321}
     
    11311326    TRACE("(%p) Relay\n" , This);
    11321327
    1133     EnterCriticalSection(&d3d9_cs);
     1328    wined3d_mutex_lock();
    11341329    hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
    1135     LeaveCriticalSection(&d3d9_cs);
     1330    wined3d_mutex_unlock();
     1331
    11361332    return hr;
    11371333}
     
    11421338    TRACE("(%p) Relay\n" , This);
    11431339
    1144     EnterCriticalSection(&d3d9_cs);
     1340    wined3d_mutex_lock();
    11451341    hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
    1146     LeaveCriticalSection(&d3d9_cs);
     1342    wined3d_mutex_unlock();
     1343
    11471344    return hr;
    11481345}
     
    11531350    TRACE("(%p) Relay\n" , This);
    11541351
    1155     EnterCriticalSection(&d3d9_cs);
     1352    wined3d_mutex_lock();
    11561353    hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
    1157     LeaveCriticalSection(&d3d9_cs);
     1354    wined3d_mutex_unlock();
     1355
    11581356    return hr;
    11591357}
     
    11701368    }
    11711369
    1172     EnterCriticalSection(&d3d9_cs);
     1370    wined3d_mutex_lock();
    11731371    rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
    11741372    if (SUCCEEDED(rc) && NULL != retTexture) {
     
    11811379        *ppTexture = NULL;
    11821380    }
    1183     LeaveCriticalSection(&d3d9_cs);
     1381    wined3d_mutex_unlock();
    11841382
    11851383    return rc;
     
    11911389    TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
    11921390
    1193     EnterCriticalSection(&d3d9_cs);
     1391    wined3d_mutex_lock();
    11941392    hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
    11951393                                   pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
    1196     LeaveCriticalSection(&d3d9_cs);
     1394    wined3d_mutex_unlock();
     1395
    11971396    return hr;
    11981397}
     
    12401439    TRACE("(%p) Relay\n" , This);
    12411440
    1242     EnterCriticalSection(&d3d9_cs);
     1441    wined3d_mutex_lock();
    12431442    hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
    1244     LeaveCriticalSection(&d3d9_cs);
     1443    wined3d_mutex_unlock();
     1444
    12451445    return hr;
    12461446}
     
    12511451    TRACE("(%p) Relay\n" , This);
    12521452
    1253     EnterCriticalSection(&d3d9_cs);
     1453    wined3d_mutex_lock();
    12541454    hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
    1255     LeaveCriticalSection(&d3d9_cs);
    1256     return hr;
    1257 }
    1258 
    1259 static HRESULT  WINAPI  IDirect3DDevice9Impl_GetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) {
    1260     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;   
    1261     HRESULT hr;
    1262     TRACE("(%p) Relay\n" , This);
    1263 
    1264     EnterCriticalSection(&d3d9_cs);
     1455    wined3d_mutex_unlock();
     1456
     1457    return hr;
     1458}
     1459
     1460static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
     1461        D3DSAMPLERSTATETYPE Type, DWORD *pValue)
     1462{
     1463    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     1464    HRESULT hr;
     1465    TRACE("(%p) Relay\n" , This);
     1466
     1467    wined3d_mutex_lock();
    12651468    hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
    1266     LeaveCriticalSection(&d3d9_cs);
     1469    wined3d_mutex_unlock();
     1470
    12671471    return hr;
    12681472}
     
    12731477    TRACE("(%p) Relay\n" , This);
    12741478
    1275     EnterCriticalSection(&d3d9_cs);
     1479    wined3d_mutex_lock();
    12761480    hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
    1277     LeaveCriticalSection(&d3d9_cs);
     1481    wined3d_mutex_unlock();
     1482
    12781483    return hr;
    12791484}
     
    12841489    TRACE("(%p) Relay\n" , This);
    12851490
    1286     EnterCriticalSection(&d3d9_cs);
     1491    wined3d_mutex_lock();
    12871492    hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
    1288     LeaveCriticalSection(&d3d9_cs);
    1289     return hr;
    1290 }
    1291 
    1292 static HRESULT  WINAPI  IDirect3DDevice9Impl_SetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
    1293     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;   
    1294     HRESULT hr;
    1295     TRACE("(%p) Relay\n" , This);
    1296 
    1297     EnterCriticalSection(&d3d9_cs);
     1493    wined3d_mutex_unlock();
     1494
     1495    return hr;
     1496}
     1497
     1498static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber,
     1499        const PALETTEENTRY *pEntries)
     1500{
     1501    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     1502    HRESULT hr;
     1503    TRACE("(%p) Relay\n" , This);
     1504
     1505    wined3d_mutex_lock();
    12981506    hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
    1299     LeaveCriticalSection(&d3d9_cs);
     1507    wined3d_mutex_unlock();
     1508
    13001509    return hr;
    13011510}
     
    13061515    TRACE("(%p) Relay\n" , This);
    13071516
    1308     EnterCriticalSection(&d3d9_cs);
     1517    wined3d_mutex_lock();
    13091518    hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
    1310     LeaveCriticalSection(&d3d9_cs);
     1519    wined3d_mutex_unlock();
     1520
    13111521    return hr;
    13121522}
     
    13171527    TRACE("(%p) Relay\n" , This);
    13181528
    1319     EnterCriticalSection(&d3d9_cs);
     1529    wined3d_mutex_lock();
    13201530    hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
    1321     LeaveCriticalSection(&d3d9_cs);
     1531    wined3d_mutex_unlock();
     1532
    13221533    return hr;
    13231534}
     
    13281539    TRACE("(%p) Relay\n" , This);
    13291540
    1330     EnterCriticalSection(&d3d9_cs);
     1541    wined3d_mutex_lock();
    13311542    hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
    1332     LeaveCriticalSection(&d3d9_cs);
     1543    wined3d_mutex_unlock();
     1544
    13331545    return hr;
    13341546}
     
    13391551    TRACE("(%p) Relay\n" , This);
    13401552
    1341     EnterCriticalSection(&d3d9_cs);
     1553    wined3d_mutex_lock();
    13421554    hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
    1343     LeaveCriticalSection(&d3d9_cs);
     1555    wined3d_mutex_unlock();
     1556
    13441557    return hr;
    13451558}
     
    13501563    TRACE("(%p) Relay\n" , This);
    13511564
    1352     EnterCriticalSection(&d3d9_cs);
     1565    wined3d_mutex_lock();
    13531566    hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
    1354     LeaveCriticalSection(&d3d9_cs);
     1567    wined3d_mutex_unlock();
     1568
    13551569    return hr;
    13561570}
     
    13611575    TRACE("(%p) Relay\n" , This);
    13621576
    1363     EnterCriticalSection(&d3d9_cs);
     1577    wined3d_mutex_lock();
    13641578    hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
    1365     LeaveCriticalSection(&d3d9_cs);
     1579    wined3d_mutex_unlock();
     1580
    13661581    return hr;
    13671582}
     
    13721587    TRACE("(%p) Relay\n" , This);
    13731588
    1374     EnterCriticalSection(&d3d9_cs);
     1589    wined3d_mutex_lock();
    13751590    ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
    1376     LeaveCriticalSection(&d3d9_cs);
     1591    wined3d_mutex_unlock();
     1592
    13771593    return ret;
    13781594}
     
    13831599    TRACE("(%p) Relay\n" , This);
    13841600
    1385     EnterCriticalSection(&d3d9_cs);
     1601    wined3d_mutex_lock();
    13861602    hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
    1387     LeaveCriticalSection(&d3d9_cs);
     1603    wined3d_mutex_unlock();
     1604
    13881605    return hr;
    13891606}
     
    13941611    TRACE("(%p) Relay\n" , This);
    13951612
    1396     EnterCriticalSection(&d3d9_cs);
     1613    wined3d_mutex_lock();
    13971614    ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
    1398     LeaveCriticalSection(&d3d9_cs);
     1615    wined3d_mutex_unlock();
     1616
    13991617    return ret;
    14001618}
    14011619
    1402 static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
    1403     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;   
    1404     HRESULT hr;
    1405     TRACE("(%p) Relay\n" , This);
    1406 
    1407     EnterCriticalSection(&d3d9_cs);
     1620static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
     1621        UINT StartVertex, UINT PrimitiveCount)
     1622{
     1623    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     1624    HRESULT hr;
     1625    TRACE("(%p) Relay\n" , This);
     1626
     1627    wined3d_mutex_lock();
    14081628    IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
    14091629    hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
    14101630            vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
    1411     LeaveCriticalSection(&d3d9_cs);
     1631    wined3d_mutex_unlock();
     1632
    14121633    return hr;
    14131634}
     
    14201641
    14211642    /* D3D8 passes the baseVertexIndex in SetIndices, and due to the stateblock functions wined3d has to work that way */
    1422     EnterCriticalSection(&d3d9_cs);
     1643    wined3d_mutex_lock();
    14231644    IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
    14241645    IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
    1425     hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, MinVertexIndex, NumVertices,
    1426             startIndex, vertex_count_from_primitive_count(PrimitiveType, primCount));
    1427     LeaveCriticalSection(&d3d9_cs);
    1428     return hr;
    1429 }
    1430 
    1431 static HRESULT  WINAPI  IDirect3DDevice9Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
    1432     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;   
    1433     HRESULT hr;
    1434     TRACE("(%p) Relay\n" , This);
    1435 
    1436     EnterCriticalSection(&d3d9_cs);
     1646    hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
     1647            vertex_count_from_primitive_count(PrimitiveType, primCount));
     1648    wined3d_mutex_unlock();
     1649
     1650    return hr;
     1651}
     1652
     1653static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
     1654        UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
     1655{
     1656    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     1657    HRESULT hr;
     1658    TRACE("(%p) Relay\n" , This);
     1659
     1660    wined3d_mutex_lock();
    14371661    IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
    14381662    hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
    14391663            vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
    14401664            pVertexStreamZeroData, VertexStreamZeroStride);
    1441     LeaveCriticalSection(&d3d9_cs);
     1665    wined3d_mutex_unlock();
     1666
    14421667    return hr;
    14431668}
     
    14501675    TRACE("(%p) Relay\n" , This);
    14511676
    1452     EnterCriticalSection(&d3d9_cs);
     1677    wined3d_mutex_lock();
    14531678    IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
    1454     hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, MinVertexIndex, NumVertexIndices,
     1679    hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
    14551680            vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
    14561681            wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
    1457     LeaveCriticalSection(&d3d9_cs);
     1682    wined3d_mutex_unlock();
     1683
    14581684    return hr;
    14591685}
     
    14661692    TRACE("(%p) Relay\n" , This);
    14671693
    1468     EnterCriticalSection(&d3d9_cs);
     1694    wined3d_mutex_lock();
    14691695    hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
    1470     LeaveCriticalSection(&d3d9_cs);
    1471     return hr;
     1696    wined3d_mutex_unlock();
     1697
     1698    return hr;
     1699}
     1700
     1701static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
     1702        const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
     1703{
     1704    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     1705    IDirect3DVertexDeclaration9Impl *object;
     1706    HRESULT hr;
     1707
     1708    TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
     1709
     1710    if (!declaration)
     1711    {
     1712        WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
     1713        return D3DERR_INVALIDCALL;
     1714    }
     1715
     1716    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     1717    if (!object)
     1718    {
     1719        ERR("Failed to allocate vertex declaration memory.\n");
     1720        return E_OUTOFMEMORY;
     1721    }
     1722
     1723    hr = vertexdeclaration_init(object, This, elements);
     1724    if (FAILED(hr))
     1725    {
     1726        WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
     1727        HeapFree(GetProcessHeap(), 0, object);
     1728        return hr;
     1729    }
     1730
     1731    TRACE("Created vertex declaration %p.\n", object);
     1732    *declaration = (IDirect3DVertexDeclaration9 *)object;
     1733
     1734    return D3D_OK;
    14721735}
    14731736
     
    15421805    }
    15431806
    1544     EnterCriticalSection(&d3d9_cs);
     1807    wined3d_mutex_lock();
    15451808    decl = getConvertedDecl(This, FVF);
    1546     LeaveCriticalSection(&d3d9_cs);
     1809    wined3d_mutex_unlock();
    15471810
    15481811    if (!decl)
     
    15881851}
    15891852
     1853static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex *iface,
     1854        const DWORD *byte_code, IDirect3DVertexShader9 **shader)
     1855{
     1856    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     1857    IDirect3DVertexShader9Impl *object;
     1858    HRESULT hr;
     1859
     1860    TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
     1861
     1862    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     1863    if (!object)
     1864    {
     1865        ERR("Failed to allocate vertex shader memory.\n");
     1866        return E_OUTOFMEMORY;
     1867    }
     1868
     1869    hr = vertexshader_init(object, This, byte_code);
     1870    if (FAILED(hr))
     1871    {
     1872        WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
     1873        HeapFree(GetProcessHeap(), 0, object);
     1874        return hr;
     1875    }
     1876
     1877    TRACE("Created vertex shader %p.\n", object);
     1878    *shader = (IDirect3DVertexShader9 *)object;
     1879
     1880    return D3D_OK;
     1881}
     1882
    15901883static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
    15911884    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     
    15931886    TRACE("(%p) Relay\n" , This);
    15941887
    1595     EnterCriticalSection(&d3d9_cs);
     1888    wined3d_mutex_lock();
    15961889    hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
    1597                                           pStreamData==NULL ? NULL:((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer,
    1598                                           OffsetInBytes, Stride);
    1599     LeaveCriticalSection(&d3d9_cs);
     1890            pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
     1891            OffsetInBytes, Stride);
     1892    wined3d_mutex_unlock();
     1893
    16001894    return hr;
    16011895}
     
    16121906    }
    16131907
    1614     EnterCriticalSection(&d3d9_cs);
     1908    wined3d_mutex_lock();
    16151909    rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
    16161910    if (rc == D3D_OK  && NULL != retStream) {
     
    16231917        *pStream = NULL;
    16241918    }
    1625     LeaveCriticalSection(&d3d9_cs);
     1919    wined3d_mutex_unlock();
    16261920
    16271921    return rc;
    16281922}
    16291923
    1630 static HRESULT  WINAPI  IDirect3DDevice9Impl_SetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT Divider) {
    1631     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;   
    1632     HRESULT hr;
    1633     TRACE("(%p) Relay\n" , This);
    1634 
    1635     EnterCriticalSection(&d3d9_cs);
     1924static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT StreamNumber,
     1925        UINT Divider)
     1926{
     1927    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     1928    HRESULT hr;
     1929    TRACE("(%p) Relay\n" , This);
     1930
     1931    wined3d_mutex_lock();
    16361932    hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
    1637     LeaveCriticalSection(&d3d9_cs);
     1933    wined3d_mutex_unlock();
     1934
    16381935    return hr;
    16391936}
     
    16441941    TRACE("(%p) Relay\n" , This);
    16451942
    1646     EnterCriticalSection(&d3d9_cs);
     1943    wined3d_mutex_lock();
    16471944    hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
    1648     LeaveCriticalSection(&d3d9_cs);
     1945    wined3d_mutex_unlock();
     1946
    16491947    return hr;
    16501948}
     
    16561954    TRACE("(%p) Relay\n", This);
    16571955
    1658     EnterCriticalSection(&d3d9_cs);
    1659     hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
     1956    wined3d_mutex_lock();
     1957    hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
    16601958            ib ? ib->wineD3DIndexBuffer : NULL,
    16611959            ib ? ib->format : WINED3DFMT_UNKNOWN);
    1662     LeaveCriticalSection(&d3d9_cs);
     1960    wined3d_mutex_unlock();
     1961
    16631962    return hr;
    16641963}
     
    16751974    }
    16761975
    1677     EnterCriticalSection(&d3d9_cs);
    1678     rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
     1976    wined3d_mutex_lock();
     1977    rc = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
    16791978    if (SUCCEEDED(rc) && retIndexData) {
    16801979        IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
     
    16841983        *ppIndexData = NULL;
    16851984    }
    1686     LeaveCriticalSection(&d3d9_cs);
     1985    wined3d_mutex_unlock();
     1986
    16871987    return rc;
    16881988}
    16891989
     1990static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface,
     1991        const DWORD *byte_code, IDirect3DPixelShader9 **shader)
     1992{
     1993    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     1994    IDirect3DPixelShader9Impl *object;
     1995    HRESULT hr;
     1996
     1997    TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
     1998
     1999    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     2000    if (!object)
     2001    {
     2002        FIXME("Failed to allocate pixel shader memory.\n");
     2003        return E_OUTOFMEMORY;
     2004    }
     2005
     2006    hr = pixelshader_init(object, This, byte_code);
     2007    if (FAILED(hr))
     2008    {
     2009        WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
     2010        HeapFree(GetProcessHeap(), 0, object);
     2011        return hr;
     2012    }
     2013
     2014    TRACE("Created pixel shader %p.\n", object);
     2015    *shader = (IDirect3DPixelShader9 *)object;
     2016
     2017    return D3D_OK;
     2018}
     2019
    16902020static HRESULT  WINAPI  IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
    16912021    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     
    16932023    TRACE("(%p) Relay\n", This);
    16942024
    1695     EnterCriticalSection(&d3d9_cs);
     2025    wined3d_mutex_lock();
    16962026    hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
    1697     LeaveCriticalSection(&d3d9_cs);
     2027    wined3d_mutex_unlock();
     2028
    16982029    return hr;
    16992030}
     
    17042035    TRACE("(%p) Relay\n", This);
    17052036
    1706     EnterCriticalSection(&d3d9_cs);
     2037    wined3d_mutex_lock();
    17072038    hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
    1708     LeaveCriticalSection(&d3d9_cs);
     2039    wined3d_mutex_unlock();
     2040
    17092041    return hr;
    17102042}
     
    17152047    TRACE("(%p) Relay\n", This);
    17162048
    1717     EnterCriticalSection(&d3d9_cs);
     2049    wined3d_mutex_lock();
    17182050    hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
    1719     LeaveCriticalSection(&d3d9_cs);
     2051    wined3d_mutex_unlock();
     2052
    17202053    return hr;
    17212054}
     
    19532286};
    19542287
    1955 ULONG WINAPI D3D9CB_DestroySurface(IWineD3DSurface *pSurface) {
    1956     IDirect3DSurface9Impl* surfaceParent;
    1957     TRACE("(%p) call back\n", pSurface);
    1958 
    1959     IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
    1960     /* GetParent's AddRef was forwarded to an object in destruction.
    1961      * Releasing it here again would cause an endless recursion. */
    1962     surfaceParent->forwardReference = NULL;
    1963     return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
    1964 }
    1965 
    19662288/* IWineD3DDeviceParent IUnknown methods */
    19672289
     
    20232345
    20242346    *surface = d3d_surface->wineD3DSurface;
     2347    IWineD3DSurface_AddRef(*surface);
     2348
    20252349    d3d_surface->container = superior;
    20262350    IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
    20272351    d3d_surface->parentDevice = NULL;
     2352
     2353    IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
    20282354    d3d_surface->forwardReference = superior;
    20292355
     
    20532379
    20542380    *surface = d3d_surface->wineD3DSurface;
     2381    IWineD3DSurface_AddRef(*surface);
     2382
    20552383    d3d_surface->container = superior;
    2056     d3d_surface->isImplicit = TRUE;
    20572384    /* Implicit surfaces are created with an refcount of 0 */
    20582385    IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
     
    20832410
    20842411    *surface = d3d_surface->wineD3DSurface;
     2412    IWineD3DSurface_AddRef(*surface);
    20852413    d3d_surface->container = (IUnknown *)This;
    2086     d3d_surface->isImplicit = TRUE;
    20872414    /* Implicit surfaces are created with an refcount of 0 */
    20882415    IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
     
    21112438    }
    21122439
    2113     object->lpVtbl = &Direct3DVolume9_Vtbl;
    2114     object->ref = 1;
    2115     hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage & WINED3DUSAGE_MASK,
    2116             format, pool, &object->wineD3DVolume, (IUnknown *)object);
     2440    hr = volume_init(object, This, width, height, depth, usage, format, pool);
    21172441    if (FAILED(hr))
    21182442    {
    2119         ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr);
     2443        WARN("Failed to initialize volume, hr %#x.\n", hr);
    21202444        HeapFree(GetProcessHeap(), 0, object);
    2121         *volume = NULL;
    21222445        return hr;
    21232446    }
    21242447
    21252448    *volume = object->wineD3DVolume;
     2449    IWineD3DVolume_AddRef(*volume);
     2450    IDirect3DVolume9_Release((IDirect3DVolume9 *)object);
     2451
    21262452    object->container = superior;
    21272453    object->forwardReference = superior;
    21282454
    2129     TRACE("(%p) Created volume %p\n", iface, *volume);
     2455    TRACE("(%p) Created volume %p\n", iface, object);
    21302456
    21312457    return hr;
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c

    r22496 r23571  
    7979
    8080    if (ref == 0) {
    81         EnterCriticalSection(&d3d9_cs);
     81        wined3d_mutex_lock();
    8282        IWineD3D_Release(This->WineD3D);
    83         LeaveCriticalSection(&d3d9_cs);
     83        wined3d_mutex_unlock();
     84
    8485        HeapFree(GetProcessHeap(), 0, This);
    8586    }
     
    9495    TRACE("(%p)->(%p)\n", This, pInitializeFunction);
    9596
    96     EnterCriticalSection(&d3d9_cs);
     97    wined3d_mutex_lock();
    9798    hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
    98     LeaveCriticalSection(&d3d9_cs);
     99    wined3d_mutex_unlock();
     100
    99101    return hr;
    100102}
     
    105107    TRACE("%p\n", This);
    106108
    107     EnterCriticalSection(&d3d9_cs);
     109    wined3d_mutex_lock();
    108110    hr = IWineD3D_GetAdapterCount(This->WineD3D);
    109     LeaveCriticalSection(&d3d9_cs);
     111    wined3d_mutex_unlock();
     112
    110113    return hr;
    111114}
     
    123126    adapter_id.device_name_size = sizeof(pIdentifier->DeviceName);
    124127
    125     EnterCriticalSection(&d3d9_cs);
     128    wined3d_mutex_lock();
    126129    hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
    127     LeaveCriticalSection(&d3d9_cs);
     130    wined3d_mutex_unlock();
    128131
    129132    pIdentifier->DriverVersion = adapter_id.driver_version;
     
    148151    }
    149152
    150     EnterCriticalSection(&d3d9_cs);
     153    wined3d_mutex_lock();
    151154    hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format));
    152     LeaveCriticalSection(&d3d9_cs);
     155    wined3d_mutex_unlock();
     156
    153157    return hr;
    154158}
     
    163167        return D3DERR_INVALIDCALL;
    164168
    165     EnterCriticalSection(&d3d9_cs);
     169    wined3d_mutex_lock();
    166170    hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format),
    167171            Mode, (WINED3DDISPLAYMODE *) pMode);
    168     LeaveCriticalSection(&d3d9_cs);
     172    wined3d_mutex_unlock();
    169173
    170174    if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
     
    177181    HRESULT hr;
    178182
    179     EnterCriticalSection(&d3d9_cs);
     183    wined3d_mutex_lock();
    180184    hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
    181     LeaveCriticalSection(&d3d9_cs);
     185    wined3d_mutex_unlock();
    182186
    183187    if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
     
    186190}
    187191
    188 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(LPDIRECT3D9EX iface,
    189                                               UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
    190                                               D3DFORMAT BackBufferFormat, BOOL Windowed) {
     192static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(IDirect3D9Ex *iface, UINT Adapter,
     193        D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed)
     194{
    191195    IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
    192196    HRESULT hr;
     
    194198          BackBufferFormat, Windowed ? "true" : "false");
    195199
    196     EnterCriticalSection(&d3d9_cs);
     200    wined3d_mutex_lock();
    197201    hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
    198202            wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
    199     LeaveCriticalSection(&d3d9_cs);
    200     return hr;
    201 }
    202 
    203 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(LPDIRECT3D9EX iface,
    204                                                   UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
    205                                                   DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
     203    wined3d_mutex_unlock();
     204
     205    return hr;
     206}
     207
     208static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(IDirect3D9Ex *iface, UINT Adapter, D3DDEVTYPE DeviceType,
     209        D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat)
     210{
    206211    IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
    207212    HRESULT hr;
     
    232237    }
    233238
    234     EnterCriticalSection(&d3d9_cs);
     239    wined3d_mutex_lock();
    235240    hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
    236241            Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
    237     LeaveCriticalSection(&d3d9_cs);
    238     return hr;
    239 }
    240 
    241 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(LPDIRECT3D9EX iface,
    242                                                            UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
    243                                                            BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
     242    wined3d_mutex_unlock();
     243
     244    return hr;
     245}
     246
     247static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(IDirect3D9Ex *iface, UINT Adapter,
     248        D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType,
     249        DWORD *pQualityLevels)
     250{
    244251    IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
    245252    HRESULT hr;
    246253    TRACE("%p\n", This);
    247254
    248     EnterCriticalSection(&d3d9_cs);
     255    wined3d_mutex_lock();
    249256    hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType,
    250257            wined3dformat_from_d3dformat(SurfaceFormat), Windowed, MultiSampleType, pQualityLevels);
    251     LeaveCriticalSection(&d3d9_cs);
    252     return hr;
    253 }
    254 
    255 static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(LPDIRECT3D9EX iface,
    256                                                        UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
    257                                                        D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
     258    wined3d_mutex_unlock();
     259
     260    return hr;
     261}
     262
     263static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(IDirect3D9Ex *iface, UINT Adapter,
     264        D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat)
     265{
    258266    IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
    259267    HRESULT hr;
    260268    TRACE("%p\n", This);
    261269
    262     EnterCriticalSection(&d3d9_cs);
     270    wined3d_mutex_lock();
    263271    hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType,
    264272            wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
    265273            wined3dformat_from_d3dformat(DepthStencilFormat));
    266     LeaveCriticalSection(&d3d9_cs);
     274    wined3d_mutex_unlock();
     275
    267276    return hr;
    268277}
     
    273282    TRACE("%p\n", This);
    274283
    275     EnterCriticalSection(&d3d9_cs);
     284    wined3d_mutex_lock();
    276285    hr = IWineD3D_CheckDeviceFormatConversion(This->WineD3D, Adapter, DeviceType,
    277286            wined3dformat_from_d3dformat(SourceFormat), wined3dformat_from_d3dformat(TargetFormat));
    278     LeaveCriticalSection(&d3d9_cs);
     287    wined3d_mutex_unlock();
     288
    279289    return hr;
    280290}
     
    337347
    338348    pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
     349    pCaps->NumSimultaneousRTs = min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS, pCaps->NumSimultaneousRTs);
    339350}
    340351
     
    354365    }
    355366    memset(pCaps, 0, sizeof(*pCaps));
    356     EnterCriticalSection(&d3d9_cs);
     367
     368    wined3d_mutex_lock();
    357369    hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
    358     LeaveCriticalSection(&d3d9_cs);
     370    wined3d_mutex_unlock();
     371
    359372    WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
    360373    HeapFree(GetProcessHeap(), 0, pWineCaps);
     
    374387    TRACE("%p\n", This);
    375388
    376     EnterCriticalSection(&d3d9_cs);
     389    wined3d_mutex_lock();
    377390    ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
    378     LeaveCriticalSection(&d3d9_cs);
     391    wined3d_mutex_unlock();
     392
    379393    return ret;
    380 }
    381 
    382 ULONG WINAPI D3D9CB_DestroyRenderTarget(IWineD3DSurface *pSurface) {
    383     IDirect3DSurface9Impl* surfaceParent;
    384     TRACE("(%p) call back\n", pSurface);
    385 
    386     IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
    387     surfaceParent->isImplicit = FALSE;
    388     /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
    389     return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
    390394}
    391395
     
    398402    /* Swap chain had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
    399403    return IDirect3DSwapChain9_Release((IDirect3DSwapChain9*) swapChainParent);
    400 }
    401 
    402 ULONG WINAPI D3D9CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface) {
    403     IDirect3DSurface9Impl* surfaceParent;
    404     TRACE("(%p) call back\n", pSurface);
    405 
    406     IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
    407     surfaceParent->isImplicit = FALSE;
    408     /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
    409     return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
    410404}
    411405
     
    442436
    443437    /* Allocate an associated WineD3DDevice object */
    444     EnterCriticalSection(&d3d9_cs);
     438    wined3d_mutex_lock();
    445439    hr = IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags,
    446440            (IUnknown *)object, (IWineD3DDeviceParent *)&object->device_parent_vtbl, &object->WineD3DDevice);
     
    448442        HeapFree(GetProcessHeap(), 0, object);
    449443        *ppReturnedDeviceInterface = NULL;
    450         LeaveCriticalSection(&d3d9_cs);
     444        wined3d_mutex_unlock();
     445
    451446        return hr;
    452447    }
     
    516511     */
    517512    object->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
    518     LeaveCriticalSection(&d3d9_cs);
     513    wined3d_mutex_unlock();
    519514
    520515    return hr;
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/indexbuffer.c

    r19678 r23571  
    5757    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5858
     59    if (ref == 1)
     60    {
     61        IDirect3DDevice9Ex_AddRef(This->parentDevice);
     62        wined3d_mutex_lock();
     63        IWineD3DBuffer_AddRef(This->wineD3DIndexBuffer);
     64        wined3d_mutex_unlock();
     65    }
     66
    5967    return ref;
    6068}
     
    6775
    6876    if (ref == 0) {
    69         EnterCriticalSection(&d3d9_cs);
     77        IDirect3DDevice9Ex_Release(This->parentDevice);
     78        wined3d_mutex_lock();
    7079        IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
    71         LeaveCriticalSection(&d3d9_cs);
    72         IDirect3DDevice9Ex_Release(This->parentDevice);
    73         HeapFree(GetProcessHeap(), 0, This);
     80        wined3d_mutex_unlock();
    7481    }
    7582    return ref;
     
    8390    TRACE("(%p) Relay\n", This);
    8491
    85     EnterCriticalSection(&d3d9_cs);
     92    wined3d_mutex_lock();
    8693    hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
    8794    if (SUCCEEDED(hr))
     
    9097        IWineD3DDevice_Release(wined3d_device);
    9198    }
    92     LeaveCriticalSection(&d3d9_cs);
     99    wined3d_mutex_unlock();
     100
    93101    return hr;
    94102}
     
    99107    TRACE("(%p) Relay\n", This);
    100108
    101     EnterCriticalSection(&d3d9_cs);
     109    wined3d_mutex_lock();
    102110    hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
    103     LeaveCriticalSection(&d3d9_cs);
     111    wined3d_mutex_unlock();
     112
    104113    return hr;
    105114}
     
    110119    TRACE("(%p) Relay\n", This);
    111120
    112     EnterCriticalSection(&d3d9_cs);
     121    wined3d_mutex_lock();
    113122    hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
    114     LeaveCriticalSection(&d3d9_cs);
     123    wined3d_mutex_unlock();
     124
    115125    return hr;
    116126}
     
    121131    TRACE("(%p) Relay\n", This);
    122132
    123     EnterCriticalSection(&d3d9_cs);
     133    wined3d_mutex_lock();
    124134    hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
    125     LeaveCriticalSection(&d3d9_cs);
     135    wined3d_mutex_unlock();
     136
    126137    return hr;
    127138}
     
    132143    TRACE("(%p) Relay\n", This);
    133144
    134     EnterCriticalSection(&d3d9_cs);
     145    wined3d_mutex_lock();
    135146    ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
    136     LeaveCriticalSection(&d3d9_cs);
     147    wined3d_mutex_unlock();
     148
    137149    return ret;
    138150}
     
    143155    TRACE("(%p) Relay\n", This);
    144156
    145     EnterCriticalSection(&d3d9_cs);
     157    wined3d_mutex_lock();
    146158    ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
    147     LeaveCriticalSection(&d3d9_cs);
     159    wined3d_mutex_unlock();
     160
    148161    return ret;
    149162}
     
    153166    TRACE("(%p) Relay\n", This);
    154167
    155     EnterCriticalSection(&d3d9_cs);
     168    wined3d_mutex_lock();
    156169    IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
    157     LeaveCriticalSection(&d3d9_cs);
     170    wined3d_mutex_unlock();
    158171}
    159172
     
    171184    TRACE("(%p) Relay\n", This);
    172185
    173     EnterCriticalSection(&d3d9_cs);
     186    wined3d_mutex_lock();
    174187    hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
    175     LeaveCriticalSection(&d3d9_cs);
     188    wined3d_mutex_unlock();
     189
    176190    return hr;
    177191}
     
    182196    TRACE("(%p) Relay\n", This);
    183197
    184     EnterCriticalSection(&d3d9_cs);
     198    wined3d_mutex_lock();
    185199    hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
    186     LeaveCriticalSection(&d3d9_cs);
     200    wined3d_mutex_unlock();
     201
    187202    return hr;
    188203}
     
    194209    TRACE("(%p) Relay\n", This);
    195210
    196     EnterCriticalSection(&d3d9_cs);
     211    wined3d_mutex_lock();
    197212    hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
    198     LeaveCriticalSection(&d3d9_cs);
     213    wined3d_mutex_unlock();
    199214
    200215    if (SUCCEEDED(hr)) {
     
    231246};
    232247
    233 
    234 /* IDirect3DDevice9 IDirect3DIndexBuffer9 Methods follow: */
    235 HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(LPDIRECT3DDEVICE9EX iface,
    236                               UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool,
    237                               IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) {
    238    
    239     IDirect3DIndexBuffer9Impl *object;
    240     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    241     HRESULT hrc = D3D_OK;
    242    
    243     TRACE("(%p) Relay\n", This);
    244     /* Allocate the storage for the device */
    245     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
    246     if (NULL == object) {
    247         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
    248         return D3DERR_OUTOFVIDEOMEMORY;
    249     }
    250 
    251     object->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
    252     object->ref = 1;
    253     object->format = wined3dformat_from_d3dformat(Format);
    254     TRACE("Calling wined3d create index buffer\n");
    255     EnterCriticalSection(&d3d9_cs);
    256     hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
    257             (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
    258     LeaveCriticalSection(&d3d9_cs);
    259     if (hrc != D3D_OK) {
    260 
    261         /* free up object */
    262         FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
    263         HeapFree(GetProcessHeap(), 0, object);
    264     } else {
    265         IDirect3DDevice9Ex_AddRef(iface);
    266         object->parentDevice = iface;
    267         *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER9) object;
    268         TRACE("(%p) : Created index buffer %p\n", This, object);
    269     }
    270     return hrc;
    271 }
     248static void STDMETHODCALLTYPE d3d9_indexbuffer_wined3d_object_destroyed(void *parent)
     249{
     250    HeapFree(GetProcessHeap(), 0, parent);
     251}
     252
     253static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops =
     254{
     255    d3d9_indexbuffer_wined3d_object_destroyed,
     256};
     257
     258HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
     259        UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
     260{
     261    HRESULT hr;
     262
     263    buffer->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
     264    buffer->ref = 1;
     265    buffer->format = wined3dformat_from_d3dformat(format);
     266
     267    wined3d_mutex_lock();
     268    hr = IWineD3DDevice_CreateIndexBuffer(device->WineD3DDevice, size,
     269            usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DIndexBuffer,
     270            (IUnknown *)buffer, &d3d9_indexbuffer_wined3d_parent_ops);
     271    wined3d_mutex_unlock();
     272    if (FAILED(hr))
     273    {
     274        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
     275        return hr;
     276    }
     277
     278    buffer->parentDevice = (IDirect3DDevice9Ex *)device;
     279    IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
     280
     281    return D3D_OK;
     282}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/pixelshader.c

    r20612 r23571  
    5656    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5757
     58    if (ref == 1)
     59    {
     60        IDirect3DDevice9Ex_AddRef(This->parentDevice);
     61        wined3d_mutex_lock();
     62        IWineD3DPixelShader_AddRef(This->wineD3DPixelShader);
     63        wined3d_mutex_unlock();
     64    }
     65
    5866    return ref;
    5967}
     
    6674
    6775    if (ref == 0) {
    68         EnterCriticalSection(&d3d9_cs);
     76        IDirect3DDevice9Ex_Release(This->parentDevice);
     77        wined3d_mutex_lock();
    6978        IWineD3DPixelShader_Release(This->wineD3DPixelShader);
    70         LeaveCriticalSection(&d3d9_cs);
    71         IDirect3DDevice9Ex_Release(This->parentDevice);
    72         HeapFree(GetProcessHeap(), 0, This);
     79        wined3d_mutex_unlock();
    7380    }
    7481    return ref;
     
    8289    TRACE("(%p) : Relay\n", This);
    8390
    84     EnterCriticalSection(&d3d9_cs);
     91    wined3d_mutex_lock();
    8592    IWineD3DPixelShader_GetDevice(This->wineD3DPixelShader, &myDevice);
    8693    IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
    8794    IWineD3DDevice_Release(myDevice);
    88     LeaveCriticalSection(&d3d9_cs);
     95    wined3d_mutex_unlock();
     96
    8997    TRACE("(%p) returning (%p)\n", This, *ppDevice);
    9098    return D3D_OK;
     
    96104    TRACE("(%p) Relay\n", This);
    97105
    98     EnterCriticalSection(&d3d9_cs);
     106    wined3d_mutex_lock();
    99107    hr = IWineD3DPixelShader_GetFunction(This->wineD3DPixelShader, pData, pSizeOfData);
    100     LeaveCriticalSection(&d3d9_cs);
     108    wined3d_mutex_unlock();
     109
    101110    return hr;
    102111}
     
    114123};
    115124
    116 
    117 /* IDirect3DDevice9 IDirect3DPixelShader9 Methods follow:  */
    118 HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) {
    119     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    120     IDirect3DPixelShader9Impl *object;
     125static void STDMETHODCALLTYPE d3d9_pixelshader_wined3d_object_destroyed(void *parent)
     126{
     127    HeapFree(GetProcessHeap(), 0, parent);
     128}
     129
     130static const struct wined3d_parent_ops d3d9_pixelshader_wined3d_parent_ops =
     131{
     132    d3d9_pixelshader_wined3d_object_destroyed,
     133};
     134
     135HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
     136{
     137    HRESULT hr;
     138
     139    shader->ref = 1;
     140    shader->lpVtbl = &Direct3DPixelShader9_Vtbl;
     141
     142    wined3d_mutex_lock();
     143    hr = IWineD3DDevice_CreatePixelShader(device->WineD3DDevice, byte_code,
     144            NULL, &shader->wineD3DPixelShader, (IUnknown *)shader,
     145            &d3d9_pixelshader_wined3d_parent_ops);
     146    wined3d_mutex_unlock();
     147    if (FAILED(hr))
     148    {
     149        WARN("Failed to created wined3d pixel shader, hr %#x.\n", hr);
     150        return hr;
     151    }
     152
     153    shader->parentDevice = (IDirect3DDevice9Ex *)device;
     154    IDirect3DDevice9Ex_AddRef(shader->parentDevice);
     155
     156    return D3D_OK;
     157}
     158
     159HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9* pShader) {
     160    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     161    IDirect3DPixelShader9Impl *shader = (IDirect3DPixelShader9Impl *)pShader;
     162    TRACE("(%p) Relay\n", This);
     163
     164    wined3d_mutex_lock();
     165    IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
     166    wined3d_mutex_unlock();
     167
     168    return D3D_OK;
     169}
     170
     171HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9** ppShader) {
     172    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     173    IWineD3DPixelShader *object;
     174
    121175    HRESULT hrc = D3D_OK;
    122 
    123     TRACE("(%p) Relay\n", This);
    124 
     176    TRACE("(%p) Relay\n", This);
    125177    if (ppShader == NULL) {
    126178        TRACE("(%p) Invalid call\n", This);
     
    128180    }
    129181
    130     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
    131 
    132     if (NULL == object) {
    133         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
    134         return E_OUTOFMEMORY;
    135     }
    136 
    137     object->ref    = 1;
    138     object->lpVtbl = &Direct3DPixelShader9_Vtbl;
    139     EnterCriticalSection(&d3d9_cs);
    140     hrc = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction, NULL,
    141             &object->wineD3DPixelShader, (IUnknown *)object);
    142     LeaveCriticalSection(&d3d9_cs);
    143     if (hrc != D3D_OK) {
    144 
    145         /* free up object */
    146         FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
    147         HeapFree(GetProcessHeap(), 0 , object);
    148     } else {
    149         IDirect3DDevice9Ex_AddRef(iface);
    150         object->parentDevice = iface;
    151         *ppShader = (IDirect3DPixelShader9*) object;
    152         TRACE("(%p) : Created pixel shader %p\n", This, object);
    153     }
    154 
    155     TRACE("(%p) : returning %p\n", This, *ppShader);
    156     return hrc;
    157 }
    158 
    159 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9* pShader) {
    160     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    161     IDirect3DPixelShader9Impl *shader = (IDirect3DPixelShader9Impl *)pShader;
    162     TRACE("(%p) Relay\n", This);
    163 
    164     EnterCriticalSection(&d3d9_cs);
    165     IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
    166     LeaveCriticalSection(&d3d9_cs);
    167     return D3D_OK;
    168 }
    169 
    170 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9** ppShader) {
    171     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    172     IWineD3DPixelShader *object;
    173 
    174     HRESULT hrc = D3D_OK;
    175     TRACE("(%p) Relay\n", This);
    176     if (ppShader == NULL) {
    177         TRACE("(%p) Invalid call\n", This);
    178         return D3DERR_INVALIDCALL;
    179     }
    180 
    181     EnterCriticalSection(&d3d9_cs);
     182    wined3d_mutex_lock();
    182183    hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
    183184    if (SUCCEEDED(hrc))
     
    197198        WARN("(%p) : Call to IWineD3DDevice_GetPixelShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
    198199    }
    199     LeaveCriticalSection(&d3d9_cs);
     200    wined3d_mutex_unlock();
    200201
    201202    TRACE("(%p) : returning %p\n", This, *ppShader);
     
    206207   IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    207208    HRESULT hr;
    208     TRACE("(%p) Relay\n", This);   
    209 
    210     EnterCriticalSection(&d3d9_cs);
     209    TRACE("(%p) Relay\n", This);
     210
     211    wined3d_mutex_lock();
    211212    hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
    212     LeaveCriticalSection(&d3d9_cs);
     213    wined3d_mutex_unlock();
     214
    213215    return hr;
    214216}
     
    220222    TRACE("(%p) Relay\n", This);
    221223
    222     EnterCriticalSection(&d3d9_cs);
     224    wined3d_mutex_lock();
    223225    hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
    224     LeaveCriticalSection(&d3d9_cs);
     226    wined3d_mutex_unlock();
    225227
    226228    return hr;
     
    232234    TRACE("(%p) Relay\n", This);
    233235
    234     EnterCriticalSection(&d3d9_cs);
     236    wined3d_mutex_lock();
    235237    hr = IWineD3DDevice_SetPixelShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
    236     LeaveCriticalSection(&d3d9_cs);
     238    wined3d_mutex_unlock();
     239
    237240    return hr;
    238241}
     
    243246    TRACE("(%p) Relay\n", This);
    244247
    245     EnterCriticalSection(&d3d9_cs);
     248    wined3d_mutex_lock();
    246249    hr = IWineD3DDevice_GetPixelShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
    247     LeaveCriticalSection(&d3d9_cs);
     250    wined3d_mutex_unlock();
     251
    248252    return hr;
    249253}
     
    254258    TRACE("(%p) Relay\n", This);
    255259
    256     EnterCriticalSection(&d3d9_cs);
     260    wined3d_mutex_lock();
    257261    hr = IWineD3DDevice_SetPixelShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
    258     LeaveCriticalSection(&d3d9_cs);
     262    wined3d_mutex_unlock();
     263
    259264    return hr;
    260265}
     
    265270    TRACE("(%p) Relay\n", This);
    266271
    267     EnterCriticalSection(&d3d9_cs);
     272    wined3d_mutex_lock();
    268273    hr = IWineD3DDevice_GetPixelShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
    269     LeaveCriticalSection(&d3d9_cs);
    270     return hr;
    271 }
     274    wined3d_mutex_unlock();
     275
     276    return hr;
     277}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/query.c

    r19678 r23571  
    6767
    6868    if (ref == 0) {
    69         EnterCriticalSection(&d3d9_cs);
     69        wined3d_mutex_lock();
    7070        IWineD3DQuery_Release(This->wineD3DQuery);
    71         LeaveCriticalSection(&d3d9_cs);
     71        wined3d_mutex_unlock();
     72
    7273        IDirect3DDevice9Ex_Release(This->parentDevice);
    7374        HeapFree(GetProcessHeap(), 0, This);
     
    8485    TRACE("(%p) Relay\n", This);
    8586
    86     EnterCriticalSection(&d3d9_cs);
     87    wined3d_mutex_lock();
    8788    hr = IWineD3DQuery_GetDevice(This->wineD3DQuery, &pDevice);
    8889    if(hr != D3D_OK){
     
    9293        IWineD3DDevice_Release(pDevice);
    9394    }
    94     LeaveCriticalSection(&d3d9_cs);
     95    wined3d_mutex_unlock();
     96
    9597    return hr;
    9698}
     
    101103    TRACE("(%p) Relay\n", This);
    102104
    103     EnterCriticalSection(&d3d9_cs);
     105    wined3d_mutex_lock();
    104106    hr = IWineD3DQuery_GetType(This->wineD3DQuery);
    105     LeaveCriticalSection(&d3d9_cs);
     107    wined3d_mutex_unlock();
     108
    106109    return hr;
    107110}
     
    112115    TRACE("(%p) Relay\n", This);
    113116
    114     EnterCriticalSection(&d3d9_cs);
     117    wined3d_mutex_lock();
    115118    ret = IWineD3DQuery_GetDataSize(This->wineD3DQuery);
    116     LeaveCriticalSection(&d3d9_cs);
     119    wined3d_mutex_unlock();
     120
    117121    return ret;
    118122}
     
    123127    TRACE("(%p) Relay\n", This);
    124128
    125     EnterCriticalSection(&d3d9_cs);
     129    wined3d_mutex_lock();
    126130    hr = IWineD3DQuery_Issue(This->wineD3DQuery, dwIssueFlags);
    127     LeaveCriticalSection(&d3d9_cs);
     131    wined3d_mutex_unlock();
     132
    128133    return hr;
    129134}
     
    134139    TRACE("(%p) Relay\n", This);
    135140
    136     EnterCriticalSection(&d3d9_cs);
     141    wined3d_mutex_lock();
    137142    hr = IWineD3DQuery_GetData(This->wineD3DQuery, pData, dwSize, dwGetDataFlags);
    138     LeaveCriticalSection(&d3d9_cs);
     143    wined3d_mutex_unlock();
     144
    139145    return hr;
    140146}
     
    164170    if (!ppQuery)
    165171    {
    166         EnterCriticalSection(&d3d9_cs);
     172        wined3d_mutex_lock();
    167173        hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, NULL, NULL);
    168         LeaveCriticalSection(&d3d9_cs);
     174        wined3d_mutex_unlock();
     175
    169176        return hr;
    170177    }
     
    179186    object->lpVtbl = &Direct3DQuery9_Vtbl;
    180187    object->ref = 1;
    181     EnterCriticalSection(&d3d9_cs);
     188
     189    wined3d_mutex_lock();
    182190    hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, &object->wineD3DQuery, (IUnknown *)object);
    183     LeaveCriticalSection(&d3d9_cs);
     191    wined3d_mutex_unlock();
    184192
    185193    if (FAILED(hr)) {
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/stateblock.c

    r19678 r23571  
    6767
    6868    if (ref == 0) {
    69         EnterCriticalSection(&d3d9_cs);
     69        wined3d_mutex_lock();
    7070        IWineD3DStateBlock_Release(This->wineD3DStateBlock);
    71         LeaveCriticalSection(&d3d9_cs);
     71        wined3d_mutex_unlock();
     72
    7273        IDirect3DDevice9Ex_Release(This->parentDevice);
    7374        HeapFree(GetProcessHeap(), 0, This);
     
    8384    TRACE("(%p) Relay\n", This);
    8485
    85     EnterCriticalSection(&d3d9_cs);
     86    wined3d_mutex_lock();
    8687    hr = IWineD3DStateBlock_GetDevice(This->wineD3DStateBlock, &wined3d_device);
    8788    if (SUCCEEDED(hr))
     
    9091        IWineD3DDevice_Release(wined3d_device);
    9192    }
    92     LeaveCriticalSection(&d3d9_cs);
     93    wined3d_mutex_unlock();
     94
    9395    return hr;
    9496}
     
    9799    IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
    98100    HRESULT hr;
    99     TRACE("(%p) Relay\n", This); 
    100 
    101     EnterCriticalSection(&d3d9_cs);
     101    TRACE("(%p) Relay\n", This);
     102
     103    wined3d_mutex_lock();
    102104    hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
    103     LeaveCriticalSection(&d3d9_cs);
     105    wined3d_mutex_unlock();
     106
    104107    return hr;
    105108}
     
    110113    TRACE("(%p) Relay\n", This);
    111114
    112     EnterCriticalSection(&d3d9_cs);
     115    wined3d_mutex_lock();
    113116    hr = IWineD3DStateBlock_Apply(This->wineD3DStateBlock);
    114     LeaveCriticalSection(&d3d9_cs);
     117    wined3d_mutex_unlock();
     118
    115119    return hr;
    116120}
     
    135139   IDirect3DStateBlock9Impl* object;
    136140   HRESULT hrc = D3D_OK;
    137    
     141
    138142   TRACE("(%p) Relay\n", This);
    139143
     
    143147       return D3DERR_INVALIDCALL;
    144148   }
    145    
     149
    146150   object  = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
    147151   if (NULL == object) return E_OUTOFMEMORY;
    148152   object->lpVtbl = &Direct3DStateBlock9_Vtbl;
    149153   object->ref = 1;
    150    
    151    EnterCriticalSection(&d3d9_cs);
     154
     155   wined3d_mutex_lock();
    152156   hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown*)object);
    153    LeaveCriticalSection(&d3d9_cs);
     157   wined3d_mutex_unlock();
     158
    154159   if(hrc != D3D_OK){
    155160       FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
     
    165170}
    166171
    167 HRESULT  WINAPI  IDirect3DDevice9Impl_BeginStateBlock(LPDIRECT3DDEVICE9EX iface) {
    168     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;   
    169     HRESULT hr;
    170     TRACE("(%p) Relay\n", This);
    171 
    172     EnterCriticalSection(&d3d9_cs);
     172HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
     173{
     174    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     175    HRESULT hr;
     176    TRACE("(%p) Relay\n", This);
     177
     178    wined3d_mutex_lock();
    173179    hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
    174     LeaveCriticalSection(&d3d9_cs);
    175     return hr;
    176 }
    177 
    178 HRESULT  WINAPI  IDirect3DDevice9Impl_EndStateBlock(LPDIRECT3DDEVICE9EX iface, IDirect3DStateBlock9** ppSB) {
    179     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;   
    180     HRESULT hr;
    181     IWineD3DStateBlock* wineD3DStateBlock;   
    182     IDirect3DStateBlock9Impl* object;
    183 
    184     TRACE("(%p) Relay\n", This);
    185    
     180    wined3d_mutex_unlock();
     181
     182    return hr;
     183}
     184
     185HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **ppSB)
     186{
     187    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     188    IWineD3DStateBlock *wineD3DStateBlock;
     189    IDirect3DStateBlock9Impl *object;
     190    HRESULT hr;
     191
     192    TRACE("(%p) Relay\n", This);
     193
    186194    /* Tell wineD3D to endstateblock before anything else (in case we run out
    187      * of memory later and cause locking problems)
    188      */
    189     EnterCriticalSection(&d3d9_cs);
     195     * of memory later and cause locking problems) */
     196    wined3d_mutex_lock();
    190197    hr=IWineD3DDevice_EndStateBlock(This->WineD3DDevice,&wineD3DStateBlock);
    191     LeaveCriticalSection(&d3d9_cs);
    192     if(hr!= D3D_OK){
     198    wined3d_mutex_unlock();
     199
     200    if (hr!= D3D_OK)
     201    {
    193202       WARN("IWineD3DDevice_EndStateBlock returned an error\n");
    194203       return hr;
    195     }   
     204    }
    196205    /* allocate a new IDirectD3DStateBlock */
    197     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock9Impl));     
     206    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
    198207    if (!object) return E_OUTOFMEMORY;
    199208    object->ref = 1;
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c

    r21731 r23571  
    6363        /* No container, handle our own refcounting */
    6464        ULONG ref = InterlockedIncrement(&This->ref);
    65         if(ref == 1 && This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
     65        if (ref == 1)
     66        {
     67            if (This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
     68            wined3d_mutex_lock();
     69            IWineD3DSurface_AddRef(This->wineD3DSurface);
     70            wined3d_mutex_unlock();
     71        }
    6672        TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    6773
     
    8793        if (ref == 0) {
    8894            if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
    89             if (!This->isImplicit) {
    90                 EnterCriticalSection(&d3d9_cs);
    91                 IWineD3DSurface_Release(This->wineD3DSurface);
    92                 LeaveCriticalSection(&d3d9_cs);
    93                 HeapFree(GetProcessHeap(), 0, This);
    94             }
     95            wined3d_mutex_lock();
     96            IWineD3DSurface_Release(This->wineD3DSurface);
     97            wined3d_mutex_unlock();
    9598        }
    9699
     
    106109    TRACE("(%p)->(%p)\n", This, ppDevice);
    107110
    108     EnterCriticalSection(&d3d9_cs);
     111    wined3d_mutex_lock();
    109112    hr = IWineD3DSurface_GetDevice(This->wineD3DSurface, &wined3d_device);
    110113    if (SUCCEEDED(hr))
     
    113116        IWineD3DDevice_Release(wined3d_device);
    114117    }
    115     LeaveCriticalSection(&d3d9_cs);
     118    wined3d_mutex_unlock();
     119
    116120    return hr;
    117121}
     
    122126    TRACE("(%p) Relay\n", This);
    123127
    124     EnterCriticalSection(&d3d9_cs);
     128    wined3d_mutex_lock();
    125129    hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
    126     LeaveCriticalSection(&d3d9_cs);
     130    wined3d_mutex_unlock();
     131
    127132    return hr;
    128133}
     
    133138    TRACE("(%p) Relay\n", This);
    134139
    135     EnterCriticalSection(&d3d9_cs);
     140    wined3d_mutex_lock();
    136141    hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
    137     LeaveCriticalSection(&d3d9_cs);
     142    wined3d_mutex_unlock();
     143
    138144    return hr;
    139145}
     
    144150    TRACE("(%p) Relay\n", This);
    145151
    146     EnterCriticalSection(&d3d9_cs);
     152    wined3d_mutex_lock();
    147153    hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
    148     LeaveCriticalSection(&d3d9_cs);
     154    wined3d_mutex_unlock();
     155
    149156    return hr;
    150157}
     
    155162    TRACE("(%p) Relay\n", This);
    156163
    157     EnterCriticalSection(&d3d9_cs);
     164    wined3d_mutex_lock();
    158165    hr = IWineD3DSurface_SetPriority(This->wineD3DSurface, PriorityNew);
    159     LeaveCriticalSection(&d3d9_cs);
     166    wined3d_mutex_unlock();
     167
    160168    return hr;
    161169}
     
    166174    TRACE("(%p) Relay\n", This);
    167175
    168     EnterCriticalSection(&d3d9_cs);
     176    wined3d_mutex_lock();
    169177    hr = IWineD3DSurface_GetPriority(This->wineD3DSurface);
    170     LeaveCriticalSection(&d3d9_cs);
     178    wined3d_mutex_unlock();
     179
    171180    return hr;
    172181}
     
    176185    TRACE("(%p) Relay\n", This);
    177186
    178     EnterCriticalSection(&d3d9_cs);
     187    wined3d_mutex_lock();
    179188    IWineD3DSurface_PreLoad(This->wineD3DSurface);
    180     LeaveCriticalSection(&d3d9_cs);
    181     return ;
     189    wined3d_mutex_unlock();
    182190}
    183191
     
    187195    TRACE("(%p) Relay\n", This);
    188196
    189     EnterCriticalSection(&d3d9_cs);
     197    wined3d_mutex_lock();
    190198    ret = IWineD3DSurface_GetType(This->wineD3DSurface);
    191     LeaveCriticalSection(&d3d9_cs);
     199    wined3d_mutex_unlock();
     200
    192201    return ret;
    193202}
     
    219228    TRACE("(%p) Relay\n", This);
    220229
    221     EnterCriticalSection(&d3d9_cs);
     230    wined3d_mutex_lock();
    222231    hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
    223     LeaveCriticalSection(&d3d9_cs);
     232    wined3d_mutex_unlock();
    224233
    225234    if (SUCCEEDED(hr))
     
    243252    TRACE("(%p) Relay\n", This);
    244253
    245     EnterCriticalSection(&d3d9_cs);
     254    wined3d_mutex_lock();
    246255    TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
    247256    hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
    248     LeaveCriticalSection(&d3d9_cs);
     257    wined3d_mutex_unlock();
     258
    249259    return hr;
    250260}
     
    255265    TRACE("(%p) Relay\n", This);
    256266
    257     EnterCriticalSection(&d3d9_cs);
     267    wined3d_mutex_lock();
    258268    hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
    259     LeaveCriticalSection(&d3d9_cs);
     269    wined3d_mutex_unlock();
     270
    260271    switch(hr)
    261272    {
     
    270281    TRACE("(%p) Relay\n", This);
    271282
    272     EnterCriticalSection(&d3d9_cs);
     283    if(!This->getdc_supported)
     284    {
     285        WARN("Surface does not support GetDC, returning D3DERR_INVALIDCALL\n");
     286        /* Don't touch the DC */
     287        return D3DERR_INVALIDCALL;
     288    }
     289
     290    wined3d_mutex_lock();
    273291    hr = IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
    274     LeaveCriticalSection(&d3d9_cs);
     292    wined3d_mutex_unlock();
     293
    275294    return hr;
    276295}
     
    281300    TRACE("(%p) Relay\n", This);
    282301
    283     EnterCriticalSection(&d3d9_cs);
     302    wined3d_mutex_lock();
    284303    hr = IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
    285     LeaveCriticalSection(&d3d9_cs);
     304    wined3d_mutex_unlock();
     305
    286306    switch(hr) {
    287307        case WINEDDERR_NODC:    return WINED3DERR_INVALIDCALL;
     
    290310}
    291311
    292 
    293 const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
     312static const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
    294313{
    295314    /* IUnknown */
     
    314333    IDirect3DSurface9Impl_ReleaseDC
    315334};
     335
     336static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
     337{
     338    HeapFree(GetProcessHeap(), 0, parent);
     339}
     340
     341static const struct wined3d_parent_ops d3d9_surface_wined3d_parent_ops =
     342{
     343    surface_wined3d_object_destroyed,
     344};
     345
     346HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *device,
     347        UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
     348        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
     349{
     350    HRESULT hr;
     351
     352    surface->lpVtbl = &Direct3DSurface9_Vtbl;
     353    surface->ref = 1;
     354
     355    switch (format)
     356    {
     357        case D3DFMT_A8R8G8B8:
     358        case D3DFMT_X8R8G8B8:
     359        case D3DFMT_R5G6B5:
     360        case D3DFMT_X1R5G5B5:
     361        case D3DFMT_A1R5G5B5:
     362        case D3DFMT_R8G8B8:
     363            surface->getdc_supported = TRUE;
     364            break;
     365
     366        default:
     367            surface->getdc_supported = FALSE;
     368            break;
     369    }
     370
     371    /* FIXME: Check MAX bounds of MultisampleQuality. */
     372    if (multisample_quality > 0)
     373    {
     374        FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality);
     375        multisample_quality = 0;
     376    }
     377
     378    wined3d_mutex_lock();
     379    hr = IWineD3DDevice_CreateSurface(device->WineD3DDevice, width, height, wined3dformat_from_d3dformat(format),
     380            lockable, discard, level, &surface->wineD3DSurface, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool,
     381            multisample_type, multisample_quality, SURFACE_OPENGL, (IUnknown *)surface,
     382            &d3d9_surface_wined3d_parent_ops);
     383    wined3d_mutex_unlock();
     384    if (FAILED(hr))
     385    {
     386        WARN("Failed to create wined3d surface, hr %#x.\n", hr);
     387        return hr;
     388    }
     389
     390    surface->parentDevice = (IDirect3DDevice9Ex *)device;
     391    IDirect3DDevice9Ex_AddRef(surface->parentDevice);
     392
     393    return D3D_OK;
     394}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/swapchain.c

    r19678 r23571  
    7272        if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
    7373        if (!This->isImplicit) {
    74             EnterCriticalSection(&d3d9_cs);
    75             IWineD3DSwapChain_Destroy(This->wineD3DSwapChain, D3D9CB_DestroyRenderTarget);
    76             LeaveCriticalSection(&d3d9_cs);
     74            wined3d_mutex_lock();
     75            IWineD3DSwapChain_Destroy(This->wineD3DSwapChain);
     76            wined3d_mutex_unlock();
     77
    7778            HeapFree(GetProcessHeap(), 0, This);
    7879        }
     
    8889    TRACE("(%p) Relay\n", This);
    8990
    90     EnterCriticalSection(&d3d9_cs);
     91    wined3d_mutex_lock();
    9192    hr = IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
    92     LeaveCriticalSection(&d3d9_cs);
     93    wined3d_mutex_unlock();
    9394
    9495    return hr;
     
    100101    TRACE("(%p) Relay\n", This);
    101102
    102     EnterCriticalSection(&d3d9_cs);
     103    wined3d_mutex_lock();
    103104    hr = IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain,  ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
    104     LeaveCriticalSection(&d3d9_cs);
     105    wined3d_mutex_unlock();
     106
    105107    return hr;
    106108}
     
    113115    TRACE("(%p) Relay\n", This);
    114116
    115     EnterCriticalSection(&d3d9_cs);
     117    wined3d_mutex_lock();
    116118    hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &mySurface);
    117119    if (hrc == D3D_OK && NULL != mySurface) {
     
    119121       IWineD3DSurface_Release(mySurface);
    120122    }
    121     LeaveCriticalSection(&d3d9_cs);
     123    wined3d_mutex_unlock();
     124
    122125    /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
    123126    return hrc;
     
    129132    TRACE("(%p) Relay\n", This);
    130133
    131     EnterCriticalSection(&d3d9_cs);
     134    wined3d_mutex_lock();
    132135    hr = IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
    133     LeaveCriticalSection(&d3d9_cs);
     136    wined3d_mutex_unlock();
     137
    134138    return hr;
    135139}
     
    140144    TRACE("(%p) Relay\n", This);
    141145
    142     EnterCriticalSection(&d3d9_cs);
     146    wined3d_mutex_lock();
    143147    hr = IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, (WINED3DDISPLAYMODE *) pMode);
    144     LeaveCriticalSection(&d3d9_cs);
     148    wined3d_mutex_unlock();
    145149
    146150    if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
     
    156160    TRACE("(%p) Relay\n", This);
    157161
    158     EnterCriticalSection(&d3d9_cs);
     162    wined3d_mutex_lock();
    159163    hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
    160164    if (hrc == D3D_OK && NULL != device) {
     
    162166       IWineD3DDevice_Release(device);
    163167    }
    164     LeaveCriticalSection(&d3d9_cs);
     168    wined3d_mutex_unlock();
     169
    165170    return hrc;
    166171}
     
    173178    TRACE("(%p)->(%p): Relay\n", This, pPresentationParameters);
    174179
    175     EnterCriticalSection(&d3d9_cs);
     180    wined3d_mutex_lock();
    176181    hr = IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, &winePresentParameters);
    177     LeaveCriticalSection(&d3d9_cs);
     182    wined3d_mutex_unlock();
    178183
    179184    pPresentationParameters->BackBufferWidth            = winePresentParameters.BackBufferWidth;
     
    250255    localParameters.AutoRestoreDisplayMode              = TRUE;
    251256
    252     EnterCriticalSection(&d3d9_cs);
     257    wined3d_mutex_lock();
    253258    hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
    254259            &object->wineD3DSwapChain, (IUnknown*)object, SURFACE_OPENGL);
    255     LeaveCriticalSection(&d3d9_cs);
     260    wined3d_mutex_unlock();
    256261
    257262    pPresentationParameters->BackBufferWidth            = localParameters.BackBufferWidth;
     
    290295    TRACE("(%p) Relay\n", This);
    291296
    292     EnterCriticalSection(&d3d9_cs);
     297    wined3d_mutex_lock();
    293298    hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
    294299    if (hrc == D3D_OK && NULL != swapchain) {
     
    298303        *pSwapChain = NULL;
    299304    }
    300     LeaveCriticalSection(&d3d9_cs);
     305    wined3d_mutex_unlock();
     306
    301307    return hrc;
    302308}
     
    307313    TRACE("(%p) Relay\n", This);
    308314
    309     EnterCriticalSection(&d3d9_cs);
     315    wined3d_mutex_lock();
    310316    ret = IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);
    311     LeaveCriticalSection(&d3d9_cs);
     317    wined3d_mutex_unlock();
     318
    312319    return ret;
    313320}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c

    r21731 r23571  
    5959    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    6060
     61    if (ref == 1)
     62    {
     63        IDirect3DDevice9Ex_AddRef(This->parentDevice);
     64        wined3d_mutex_lock();
     65        IWineD3DTexture_AddRef(This->wineD3DTexture);
     66        wined3d_mutex_unlock();
     67    }
     68
    6169    return ref;
    6270}
     
    6977
    7078    if (ref == 0) {
    71         EnterCriticalSection(&d3d9_cs);
    72         IWineD3DTexture_Destroy(This->wineD3DTexture, D3D9CB_DestroySurface);
    73         LeaveCriticalSection(&d3d9_cs);
    7479        IDirect3DDevice9Ex_Release(This->parentDevice);
    75         HeapFree(GetProcessHeap(), 0, This);
     80        wined3d_mutex_lock();
     81        IWineD3DTexture_Release(This->wineD3DTexture);
     82        wined3d_mutex_unlock();
    7683    }
    7784    return ref;
     
    8592    TRACE("(%p) Relay\n", This);
    8693
    87     EnterCriticalSection(&d3d9_cs);
     94    wined3d_mutex_lock();
    8895    hr = IWineD3DTexture_GetDevice(This->wineD3DTexture, &wined3d_device);
    8996    if (SUCCEEDED(hr))
     
    9299        IWineD3DDevice_Release(wined3d_device);
    93100    }
    94     LeaveCriticalSection(&d3d9_cs);
     101    wined3d_mutex_unlock();
     102
    95103    return hr;
    96104}
     
    101109    TRACE("(%p) Relay\n", This);
    102110
    103     EnterCriticalSection(&d3d9_cs);
     111    wined3d_mutex_lock();
    104112    hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
    105     LeaveCriticalSection(&d3d9_cs);
     113    wined3d_mutex_unlock();
     114
    106115    return hr;
    107116}
     
    112121    TRACE("(%p) Relay\n", This);
    113122
    114     EnterCriticalSection(&d3d9_cs);
     123    wined3d_mutex_lock();
    115124    hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
    116     LeaveCriticalSection(&d3d9_cs);
     125    wined3d_mutex_unlock();
     126
    117127    return hr;
    118128}
     
    123133    TRACE("(%p) Relay\n", This);
    124134
    125     EnterCriticalSection(&d3d9_cs);
     135    wined3d_mutex_lock();
    126136    hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
    127     LeaveCriticalSection(&d3d9_cs);
     137    wined3d_mutex_unlock();
     138
    128139    return hr;
    129140}
     
    134145    TRACE("(%p) Relay\n", This);
    135146
    136     EnterCriticalSection(&d3d9_cs);
     147    wined3d_mutex_lock();
    137148    ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
    138     LeaveCriticalSection(&d3d9_cs);
     149    wined3d_mutex_unlock();
     150
    139151    return ret;
    140152}
     
    145157    TRACE("(%p) Relay\n", This);
    146158
    147     EnterCriticalSection(&d3d9_cs);
     159    wined3d_mutex_lock();
    148160    ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
    149     LeaveCriticalSection(&d3d9_cs);
     161    wined3d_mutex_unlock();
     162
    150163    return ret;
    151164}
     
    155168    TRACE("(%p) Relay\n", This);
    156169
    157     EnterCriticalSection(&d3d9_cs);
     170    wined3d_mutex_lock();
    158171    IWineD3DTexture_PreLoad(This->wineD3DTexture);
    159     LeaveCriticalSection(&d3d9_cs);
     172    wined3d_mutex_unlock();
    160173}
    161174
     
    165178    TRACE("(%p) Relay\n", This);
    166179
    167     EnterCriticalSection(&d3d9_cs);
     180    wined3d_mutex_lock();
    168181    ret = IWineD3DTexture_GetType(This->wineD3DTexture);
    169     LeaveCriticalSection(&d3d9_cs);
     182    wined3d_mutex_unlock();
     183
    170184    return ret;
    171185}
     
    177191    TRACE("(%p) Relay\n", This);
    178192
    179     EnterCriticalSection(&d3d9_cs);
     193    wined3d_mutex_lock();
    180194    ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
    181     LeaveCriticalSection(&d3d9_cs);
     195    wined3d_mutex_unlock();
     196
    182197    return ret;
    183198}
     
    188203    TRACE("(%p) Relay\n", This);
    189204
    190     EnterCriticalSection(&d3d9_cs);
     205    wined3d_mutex_lock();
    191206    ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
    192     LeaveCriticalSection(&d3d9_cs);
     207    wined3d_mutex_unlock();
     208
    193209    return ret;
    194210}
     
    199215    TRACE("(%p) Relay\n", This);
    200216
    201     EnterCriticalSection(&d3d9_cs);
     217    wined3d_mutex_lock();
    202218    ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
    203     LeaveCriticalSection(&d3d9_cs);
     219    wined3d_mutex_unlock();
     220
    204221    return ret;
    205222}
     
    210227    TRACE("(%p) Relay\n", This);
    211228
    212     EnterCriticalSection(&d3d9_cs);
     229    wined3d_mutex_lock();
    213230    hr = IWineD3DTexture_SetAutoGenFilterType(This->wineD3DTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
    214     LeaveCriticalSection(&d3d9_cs);
     231    wined3d_mutex_unlock();
     232
    215233    return hr;
    216234}
     
    221239    TRACE("(%p) Relay\n", This);
    222240
    223     EnterCriticalSection(&d3d9_cs);
     241    wined3d_mutex_lock();
    224242    ret = (D3DTEXTUREFILTERTYPE) IWineD3DTexture_GetAutoGenFilterType(This->wineD3DTexture);
    225     LeaveCriticalSection(&d3d9_cs);
     243    wined3d_mutex_unlock();
     244
    226245    return ret;
    227246}
     
    231250    TRACE("(%p) Relay\n", This);
    232251
    233     EnterCriticalSection(&d3d9_cs);
     252    wined3d_mutex_lock();
    234253    IWineD3DTexture_GenerateMipSubLevels(This->wineD3DTexture);
    235     LeaveCriticalSection(&d3d9_cs);
     254    wined3d_mutex_unlock();
    236255}
    237256
     
    244263    TRACE("(%p) Relay\n", This);
    245264
    246     EnterCriticalSection(&d3d9_cs);
     265    wined3d_mutex_lock();
    247266    hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
    248     LeaveCriticalSection(&d3d9_cs);
     267    wined3d_mutex_unlock();
    249268
    250269    if (SUCCEEDED(hr))
     
    269288
    270289    TRACE("(%p) Relay\n", This);
    271     EnterCriticalSection(&d3d9_cs);
     290
     291    wined3d_mutex_lock();
    272292    hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
    273293    if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
     
    275295       IWineD3DSurface_Release(mySurface);
    276296    }
    277     LeaveCriticalSection(&d3d9_cs);
     297    wined3d_mutex_unlock();
     298
    278299    return hrc;
    279300}
     
    284305    TRACE("(%p) Relay\n", This);
    285306
    286     EnterCriticalSection(&d3d9_cs);
     307    wined3d_mutex_lock();
    287308    hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
    288     LeaveCriticalSection(&d3d9_cs);
     309    wined3d_mutex_unlock();
     310
    289311    return hr;
    290312}
     
    295317    TRACE("(%p) Relay\n", This);
    296318
    297     EnterCriticalSection(&d3d9_cs);
     319    wined3d_mutex_lock();
    298320    hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
    299     LeaveCriticalSection(&d3d9_cs);
     321    wined3d_mutex_unlock();
     322
    300323    return hr;
    301324}
     
    306329    TRACE("(%p) Relay\n", This);
    307330
    308     EnterCriticalSection(&d3d9_cs);
     331    wined3d_mutex_lock();
    309332    hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
    310     LeaveCriticalSection(&d3d9_cs);
     333    wined3d_mutex_unlock();
     334
    311335    return hr;
    312336}
     
    342366};
    343367
    344 
    345 /* IDirect3DDevice9 IDirect3DTexture9 Methods follow: */
    346 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
    347                                                     D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) {
    348     IDirect3DTexture9Impl *object;
    349     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    350     HRESULT hrc = D3D_OK;
    351    
    352     TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%#x), Pool(%d)\n", This, Width, Height, Levels, Usage, Format,  Pool);
    353 
    354     /* Allocate the storage for the device */
    355     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture9Impl));
    356 
    357     if (NULL == object) {
    358         ERR("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
    359         return D3DERR_OUTOFVIDEOMEMORY;
    360     }
    361 
    362     object->lpVtbl = &Direct3DTexture9_Vtbl;
    363     object->ref = 1;
    364     EnterCriticalSection(&d3d9_cs);
    365     hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
    366             wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, (IUnknown *)object);
    367     LeaveCriticalSection(&d3d9_cs);
    368     if (FAILED(hrc)) {
    369 
    370         /* free up object */
    371         WARN("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
    372         HeapFree(GetProcessHeap(), 0, object);
    373    } else {
    374         IDirect3DDevice9Ex_AddRef(iface);
    375         object->parentDevice = iface;
    376         *ppTexture= (LPDIRECT3DTEXTURE9) object;
    377         TRACE("(%p) Created Texture %p, %p\n", This, object, object->wineD3DTexture);
    378    }
    379 
    380    return hrc;
    381 }
     368static void STDMETHODCALLTYPE d3d9_texture_wined3d_object_destroyed(void *parent)
     369{
     370    HeapFree(GetProcessHeap(), 0, parent);
     371}
     372
     373static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops =
     374{
     375    d3d9_texture_wined3d_object_destroyed,
     376};
     377
     378HRESULT texture_init(IDirect3DTexture9Impl *texture, IDirect3DDevice9Impl *device,
     379        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
     380{
     381    HRESULT hr;
     382
     383    texture->lpVtbl = &Direct3DTexture9_Vtbl;
     384    texture->ref = 1;
     385
     386    wined3d_mutex_lock();
     387    hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
     388            usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
     389            &texture->wineD3DTexture, (IUnknown *)texture, &d3d9_texture_wined3d_parent_ops);
     390    wined3d_mutex_unlock();
     391    if (FAILED(hr))
     392    {
     393        WARN("Failed to create wined3d texture, hr %#x.\n", hr);
     394        return hr;
     395    }
     396
     397    texture->parentDevice = (IDirect3DDevice9Ex *)device;
     398    IDirect3DDevice9Ex_AddRef(texture->parentDevice);
     399
     400    return D3D_OK;
     401}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexbuffer.c

    r19678 r23571  
    5858    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5959
     60    if (ref == 1)
     61    {
     62        IDirect3DDevice9Ex_AddRef(This->parentDevice);
     63        wined3d_mutex_lock();
     64        IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer);
     65        wined3d_mutex_unlock();
     66    }
     67
    6068    return ref;
    6169}
     
    6876
    6977    if (ref == 0) {
    70         EnterCriticalSection(&d3d9_cs);
     78        IDirect3DDevice9Ex_Release(This->parentDevice);
     79        wined3d_mutex_lock();
    7180        IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
    72         LeaveCriticalSection(&d3d9_cs);
    73         IDirect3DDevice9Ex_Release(This->parentDevice);
    74         HeapFree(GetProcessHeap(), 0, This);
     81        wined3d_mutex_unlock();
    7582    }
    7683    return ref;
     
    8491    TRACE("(%p) Relay\n", This);
    8592
    86     EnterCriticalSection(&d3d9_cs);
     93    wined3d_mutex_lock();
    8794    hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
    8895    if (SUCCEEDED(hr))
     
    9198        IWineD3DDevice_Release(wined3d_device);
    9299    }
    93     LeaveCriticalSection(&d3d9_cs);
     100    wined3d_mutex_unlock();
     101
    94102    return hr;
    95103}
     
    101109    TRACE("(%p) Relay\n", This);
    102110
    103     EnterCriticalSection(&d3d9_cs);
     111    wined3d_mutex_lock();
    104112    hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
    105     LeaveCriticalSection(&d3d9_cs);
     113    wined3d_mutex_unlock();
    106114
    107115    return hr;
     
    113121    TRACE("(%p) Relay\n", This);
    114122
    115     EnterCriticalSection(&d3d9_cs);
     123    wined3d_mutex_lock();
    116124    hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
    117     LeaveCriticalSection(&d3d9_cs);
     125    wined3d_mutex_unlock();
     126
    118127    return hr;
    119128}
     
    124133    TRACE("(%p) Relay\n", This);
    125134
    126     EnterCriticalSection(&d3d9_cs);
     135    wined3d_mutex_lock();
    127136    hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
    128     LeaveCriticalSection(&d3d9_cs);
     137    wined3d_mutex_unlock();
     138
    129139    return hr;
    130140}
     
    135145    TRACE("(%p) Relay\n", This);
    136146
    137     EnterCriticalSection(&d3d9_cs);
     147    wined3d_mutex_lock();
    138148    hr = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
    139     LeaveCriticalSection(&d3d9_cs);
     149    wined3d_mutex_unlock();
     150
    140151    return hr;
    141152}
     
    146157    TRACE("(%p) Relay\n", This);
    147158
    148     EnterCriticalSection(&d3d9_cs);
     159    wined3d_mutex_lock();
    149160    hr = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
    150     LeaveCriticalSection(&d3d9_cs);
     161    wined3d_mutex_unlock();
     162
    151163    return hr;
    152164}
     
    156168    TRACE("(%p) Relay\n", This);
    157169
    158     EnterCriticalSection(&d3d9_cs);
     170    wined3d_mutex_lock();
    159171    IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
    160     LeaveCriticalSection(&d3d9_cs);
    161     return ;
     172    wined3d_mutex_unlock();
    162173}
    163174
     
    175186    TRACE("(%p) Relay\n", This);
    176187
    177     EnterCriticalSection(&d3d9_cs);
     188    wined3d_mutex_lock();
    178189    hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
    179     LeaveCriticalSection(&d3d9_cs);
     190    wined3d_mutex_unlock();
     191
    180192    return hr;
    181193}
     
    186198    TRACE("(%p) Relay\n", This);
    187199
    188     EnterCriticalSection(&d3d9_cs);
     200    wined3d_mutex_lock();
    189201    hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
    190     LeaveCriticalSection(&d3d9_cs);
     202    wined3d_mutex_unlock();
     203
    191204    return hr;
    192205}
     
    198211    TRACE("(%p) Relay\n", This);
    199212
    200     EnterCriticalSection(&d3d9_cs);
     213    wined3d_mutex_lock();
    201214    hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
    202     LeaveCriticalSection(&d3d9_cs);
     215    wined3d_mutex_unlock();
    203216
    204217    if (SUCCEEDED(hr)) {
     
    236249};
    237250
    238 
    239 /* IDirect3DDevice9 IDirect3DVertexBuffer9 Methods follow: */
    240 HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(LPDIRECT3DDEVICE9EX iface,
    241                                 UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool,
    242                                 IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) {
    243    
    244     IDirect3DVertexBuffer9Impl *object;
    245     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    246     HRESULT hrc = D3D_OK;
    247 
    248     /* Allocate the storage for the device */
    249     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer9Impl));
    250     if (NULL == object) {
    251         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
    252         return D3DERR_OUTOFVIDEOMEMORY;
    253     }
    254 
    255     object->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
    256     object->ref = 1;
    257     object->fvf = FVF;
    258     EnterCriticalSection(&d3d9_cs);
    259     hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK,
    260             0 /* fvf for ddraw only */, (WINED3DPOOL) Pool, &(object->wineD3DVertexBuffer), (IUnknown *)object);
    261     LeaveCriticalSection(&d3d9_cs);
    262    
    263     if (hrc != D3D_OK) {
    264 
    265         /* free up object */
    266         WARN("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
    267         HeapFree(GetProcessHeap(), 0, object);
    268     } else {
    269         IDirect3DDevice9Ex_AddRef(iface);
    270         object->parentDevice = iface;
    271         TRACE("(%p) : Created vertex buffer %p\n", This, object);
    272         *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER9) object;
    273     }
    274     return hrc;
    275 }
     251static void STDMETHODCALLTYPE d3d9_vertexbuffer_wined3d_object_destroyed(void *parent)
     252{
     253    HeapFree(GetProcessHeap(), 0, parent);
     254}
     255
     256static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops =
     257{
     258    d3d9_vertexbuffer_wined3d_object_destroyed,
     259};
     260
     261HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
     262        UINT size, UINT usage, DWORD fvf, D3DPOOL pool)
     263{
     264    HRESULT hr;
     265
     266    buffer->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
     267    buffer->ref = 1;
     268    buffer->fvf = fvf;
     269
     270    wined3d_mutex_lock();
     271    hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
     272            usage & WINED3DUSAGE_MASK, 0, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
     273            (IUnknown *)buffer, &d3d9_vertexbuffer_wined3d_parent_ops);
     274    wined3d_mutex_unlock();
     275    if (FAILED(hr))
     276    {
     277        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
     278        return hr;
     279    }
     280
     281    buffer->parentDevice = (IDirect3DDevice9Ex *)device;
     282    IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
     283
     284    return D3D_OK;
     285}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexdeclaration.c

    r19678 r23571  
    4646   {D3DDECLTYPE_FLOAT3,    WINED3DFMT_R32G32B32_FLOAT,    3, sizeof(float)},
    4747   {D3DDECLTYPE_FLOAT4,    WINED3DFMT_R32G32B32A32_FLOAT, 4, sizeof(float)},
    48    {D3DDECLTYPE_D3DCOLOR,  WINED3DFMT_A8R8G8B8,           4, sizeof(BYTE)},
     48   {D3DDECLTYPE_D3DCOLOR,  WINED3DFMT_B8G8R8A8_UNORM,     4, sizeof(BYTE)},
    4949   {D3DDECLTYPE_UBYTE4,    WINED3DFMT_R8G8B8A8_UINT,      4, sizeof(BYTE)},
    5050   {D3DDECLTYPE_SHORT2,    WINED3DFMT_R16G16_SINT,        2, sizeof(short int)},
     
    9797    /* convert the declaration */
    9898    elements = HeapAlloc(GetProcessHeap(), 0, size * sizeof(D3DVERTEXELEMENT9));
    99     if (!elements)
    100         return D3DERR_OUTOFVIDEOMEMORY;
     99    if (!elements) return D3DERR_OUTOFVIDEOMEMORY;
    101100
    102101    elements[size-1] = end_element;
     
    228227    if(ref == 1) {
    229228        IDirect3DDevice9Ex_AddRef(This->parentDevice);
     229        if (!This->convFVF)
     230        {
     231            wined3d_mutex_lock();
     232            IWineD3DVertexDeclaration_AddRef(This->wineD3DVertexDeclaration);
     233            wined3d_mutex_unlock();
     234        }
    230235    }
    231236
     
    240245        ERR("Destroying vdecl with ref != 0\n");
    241246    }
    242     EnterCriticalSection(&d3d9_cs);
     247
     248    wined3d_mutex_lock();
    243249    IWineD3DVertexDeclaration_Release(This->wineD3DVertexDeclaration);
    244     LeaveCriticalSection(&d3d9_cs);
    245     HeapFree(GetProcessHeap(), 0, This->elements);
    246     HeapFree(GetProcessHeap(), 0, This);
     250    wined3d_mutex_unlock();
    247251}
    248252
     
    254258
    255259    if (ref == 0) {
    256         IDirect3DDevice9Ex *parentDevice = This->parentDevice;
    257 
     260        IDirect3DDevice9Ex_Release(This->parentDevice);
    258261        if(!This->convFVF) {
    259             IDirect3DVertexDeclaration9Impl_Release(iface);
    260         }
    261         IDirect3DDevice9Ex_Release(parentDevice);
     262            IDirect3DVertexDeclaration9Impl_Destroy(iface);
     263        }
    262264    }
    263265    return ref;
     
    272274    TRACE("(%p) : Relay\n", iface);
    273275
    274     EnterCriticalSection(&d3d9_cs);
     276    wined3d_mutex_lock();
    275277    hr = IWineD3DVertexDeclaration_GetDevice(This->wineD3DVertexDeclaration, &myDevice);
    276278    if (hr == D3D_OK && myDevice != NULL) {
     
    278280        IWineD3DDevice_Release(myDevice);
    279281    }
    280     LeaveCriticalSection(&d3d9_cs);
     282    wined3d_mutex_unlock();
     283
    281284    return hr;
    282285}
     
    312315};
    313316
     317static void STDMETHODCALLTYPE d3d9_vertexdeclaration_wined3d_object_destroyed(void *parent)
     318{
     319    IDirect3DVertexDeclaration9Impl *declaration = parent;
     320    HeapFree(GetProcessHeap(), 0, declaration->elements);
     321    HeapFree(GetProcessHeap(), 0, declaration);
     322}
     323
     324static const struct wined3d_parent_ops d3d9_vertexdeclaration_wined3d_parent_ops =
     325{
     326    d3d9_vertexdeclaration_wined3d_object_destroyed,
     327};
     328
    314329static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9* d3d9_elements,
    315330        WINED3DVERTEXELEMENT **wined3d_elements, UINT *element_count)
     
    357372}
    358373
    359 /* IDirect3DDevice9 IDirect3DVertexDeclaration9 Methods follow: */
    360 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9EX iface, CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl) {
    361    
    362     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    363     IDirect3DVertexDeclaration9Impl *object = NULL;
    364     WINED3DVERTEXELEMENT* wined3d_elements;
     374HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration,
     375        IDirect3DDevice9Impl *device, const D3DVERTEXELEMENT9 *elements)
     376{
     377    WINED3DVERTEXELEMENT *wined3d_elements;
    365378    UINT wined3d_element_count;
    366379    UINT element_count;
    367380    HRESULT hr;
    368381
    369     TRACE("(%p) : Relay\n", iface);
    370     if (NULL == ppDecl) {
    371         WARN("(%p) : Caller passed NULL As ppDecl, returning D3DERR_INVALIDCALL\n",This);
    372         return D3DERR_INVALIDCALL;
    373     }
    374 
    375     hr = convert_to_wined3d_declaration(pVertexElements, &wined3d_elements, &wined3d_element_count);
     382    hr = convert_to_wined3d_declaration(elements, &wined3d_elements, &wined3d_element_count);
    376383    if (FAILED(hr))
    377384    {
    378         WARN("(%p) : Error parsing vertex declaration\n", This);
     385        WARN("Failed to create wined3d vertex declaration elements, hr %#x.\n", hr);
    379386        return hr;
    380387    }
    381388
    382     /* Allocate the storage for the device */
    383     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexDeclaration9Impl));
    384     if (NULL == object) {
     389    declaration->lpVtbl = &Direct3DVertexDeclaration9_Vtbl;
     390    declaration->ref = 1;
     391
     392    element_count = wined3d_element_count + 1;
     393    declaration->elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(*declaration->elements));
     394    if (!declaration->elements)
     395    {
    385396        HeapFree(GetProcessHeap(), 0, wined3d_elements);
    386         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
     397        ERR("Failed to allocate vertex declaration elements memory.\n");
    387398        return D3DERR_OUTOFVIDEOMEMORY;
    388399    }
    389 
    390     object->lpVtbl = &Direct3DVertexDeclaration9_Vtbl;
    391     object->ref = 0;
    392 
    393     element_count = wined3d_element_count + 1;
    394     object->elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(D3DVERTEXELEMENT9));
    395     if (!object->elements) {
    396         HeapFree(GetProcessHeap(), 0, wined3d_elements);
    397         HeapFree(GetProcessHeap(), 0, object);
    398         ERR("Memory allocation failed\n");
    399         return D3DERR_OUTOFVIDEOMEMORY;
    400     }
    401     CopyMemory(object->elements, pVertexElements, element_count * sizeof(D3DVERTEXELEMENT9));
    402     object->element_count = element_count;
    403 
    404     EnterCriticalSection(&d3d9_cs);
    405     hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wineD3DVertexDeclaration,
    406             (IUnknown *)object, wined3d_elements, wined3d_element_count);
    407     LeaveCriticalSection(&d3d9_cs);
    408 
     400    memcpy(declaration->elements, elements, element_count * sizeof(*elements));
     401    declaration->element_count = element_count;
     402
     403    wined3d_mutex_lock();
     404    hr = IWineD3DDevice_CreateVertexDeclaration(device->WineD3DDevice, &declaration->wineD3DVertexDeclaration,
     405            (IUnknown *)declaration, &d3d9_vertexdeclaration_wined3d_parent_ops,
     406            wined3d_elements, wined3d_element_count);
     407    wined3d_mutex_unlock();
    409408    HeapFree(GetProcessHeap(), 0, wined3d_elements);
    410 
    411     if (FAILED(hr)) {
    412 
    413         /* free up object */
    414         WARN("(%p) call to IWineD3DDevice_CreateVertexDeclaration failed\n", This);
    415         HeapFree(GetProcessHeap(), 0, object->elements);
    416         HeapFree(GetProcessHeap(), 0, object);
    417     } else {
    418         object->parentDevice = iface;
    419         *ppDecl = (LPDIRECT3DVERTEXDECLARATION9) object;
    420         IDirect3DVertexDeclaration9_AddRef(*ppDecl);
    421          TRACE("(%p) : Created vertex declaration %p\n", This, object);
    422     }
    423     return hr;
     409    if (FAILED(hr))
     410    {
     411        WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
     412        return hr;
     413    }
     414
     415    declaration->parentDevice = (IDirect3DDevice9Ex *)device;
     416    IDirect3DDevice9Ex_AddRef(declaration->parentDevice);
     417
     418    return D3D_OK;
    424419}
    425420
     
    431426    TRACE("(%p) : Relay\n", iface);
    432427
    433     EnterCriticalSection(&d3d9_cs);
     428    wined3d_mutex_lock();
    434429    hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, pDeclImpl == NULL ? NULL : pDeclImpl->wineD3DVertexDeclaration);
    435     LeaveCriticalSection(&d3d9_cs);
     430    wined3d_mutex_unlock();
     431
    436432    return hr;
    437433}
     
    449445
    450446    *ppDecl = NULL;
    451     EnterCriticalSection(&d3d9_cs);
     447
     448    wined3d_mutex_lock();
    452449    hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &pTest);
    453450    if (hr == D3D_OK && NULL != pTest) {
     
    457454        *ppDecl = NULL;
    458455    }
    459     LeaveCriticalSection(&d3d9_cs);
     456    wined3d_mutex_unlock();
     457
    460458    TRACE("(%p) : returning %p\n", This, *ppDecl);
    461459    return hr;
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexshader.c

    r20612 r23571  
    5656    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5757
     58    if (ref == 1)
     59    {
     60        IDirect3DDevice9Ex_AddRef(This->parentDevice);
     61        wined3d_mutex_lock();
     62        IWineD3DVertexShader_AddRef(This->wineD3DVertexShader);
     63        wined3d_mutex_unlock();
     64    }
     65
    5866    return ref;
    5967}
     
    6674
    6775    if (ref == 0) {
    68         EnterCriticalSection(&d3d9_cs);
     76        IDirect3DDevice9Ex_Release(This->parentDevice);
     77        wined3d_mutex_lock();
    6978        IWineD3DVertexShader_Release(This->wineD3DVertexShader);
    70         LeaveCriticalSection(&d3d9_cs);
    71         IDirect3DDevice9Ex_Release(This->parentDevice);
    72         HeapFree(GetProcessHeap(), 0, This);
     79        wined3d_mutex_unlock();
    7380    }
    7481    return ref;
     
    8289    TRACE("(%p) : Relay\n", This);
    8390
    84     EnterCriticalSection(&d3d9_cs);
     91    wined3d_mutex_lock();
    8592    hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice);
    8693    if (WINED3D_OK == hr && myDevice != NULL) {
     
    9097        *ppDevice = NULL;
    9198    }
    92     LeaveCriticalSection(&d3d9_cs);
     99    wined3d_mutex_unlock();
     100
    93101    TRACE("(%p) returning (%p)\n", This, *ppDevice);
    94102    return hr;
     
    100108    TRACE("(%p) : Relay\n", This);
    101109
    102     EnterCriticalSection(&d3d9_cs);
     110    wined3d_mutex_lock();
    103111    hr = IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData);
    104     LeaveCriticalSection(&d3d9_cs);
     112    wined3d_mutex_unlock();
     113
    105114    return hr;
    106115}
     
    118127};
    119128
    120 
    121 /* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
    122 HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
     129static void STDMETHODCALLTYPE d3d9_vertexshader_wined3d_object_destroyed(void *parent)
     130{
     131    HeapFree(GetProcessHeap(), 0, parent);
     132}
     133
     134static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops =
     135{
     136    d3d9_vertexshader_wined3d_object_destroyed,
     137};
     138
     139HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
     140{
     141    HRESULT hr;
     142
     143    shader->ref = 1;
     144    shader->lpVtbl = &Direct3DVertexShader9_Vtbl;
     145
     146    wined3d_mutex_lock();
     147    hr = IWineD3DDevice_CreateVertexShader(device->WineD3DDevice, byte_code,
     148            NULL /* output signature */, &shader->wineD3DVertexShader,
     149            (IUnknown *)shader, &d3d9_vertexshader_wined3d_parent_ops);
     150    wined3d_mutex_unlock();
     151    if (FAILED(hr))
     152    {
     153        WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
     154        return hr;
     155    }
     156
     157    shader->parentDevice = (IDirect3DDevice9Ex *)device;
     158    IDirect3DDevice9Ex_AddRef(shader->parentDevice);
     159
     160    return D3D_OK;
     161}
     162
     163HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader) {
    123164    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    124165    HRESULT hrc = D3D_OK;
    125     IDirect3DVertexShader9Impl *object;
    126 
    127     /* Setup a stub object for now */
    128     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
    129     TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
    130     if (NULL == object) {
    131         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
    132         return D3DERR_OUTOFVIDEOMEMORY;
    133     }
    134 
    135     object->ref = 1;
    136     object->lpVtbl = &Direct3DVertexShader9_Vtbl;
    137     EnterCriticalSection(&d3d9_cs);
    138     hrc= IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pFunction,
    139             NULL /* output signature */, &object->wineD3DVertexShader, (IUnknown *)object);
    140     LeaveCriticalSection(&d3d9_cs);
    141 
    142     if (FAILED(hrc)) {
    143 
    144         /* free up object */
    145         FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
    146         HeapFree(GetProcessHeap(), 0, object);
    147     }else{
    148         IDirect3DDevice9Ex_AddRef(iface);
    149         object->parentDevice = iface;
    150         *ppShader = (IDirect3DVertexShader9 *)object;
    151         TRACE("(%p) : Created vertex shader %p\n", This, object);
    152     }
    153 
    154     TRACE("(%p) : returning %p\n", This, *ppShader);
    155     return hrc;
    156 }
    157 
    158 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader) {
    159     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    160     HRESULT hrc = D3D_OK;
    161 
    162     TRACE("(%p) : Relay\n", This);
    163     EnterCriticalSection(&d3d9_cs);
     166
     167    TRACE("(%p) : Relay\n", This);
     168
     169    wined3d_mutex_lock();
    164170    hrc =  IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);
    165     LeaveCriticalSection(&d3d9_cs);
     171    wined3d_mutex_unlock();
    166172
    167173    TRACE("(%p) : returning hr(%u)\n", This, hrc);
     
    175181
    176182    TRACE("(%p) : Relay  device@%p\n", This, This->WineD3DDevice);
    177     EnterCriticalSection(&d3d9_cs);
     183
     184    wined3d_mutex_lock();
    178185    hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
    179186    if (SUCCEEDED(hrc))
     
    193200        WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
    194201    }
    195     LeaveCriticalSection(&d3d9_cs);
     202    wined3d_mutex_unlock();
     203
    196204    TRACE("(%p) : returning %p\n", This, *ppShader);
    197205    return hrc;
     
    209217    }
    210218
    211     EnterCriticalSection(&d3d9_cs);
     219    wined3d_mutex_lock();
    212220    hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
    213     LeaveCriticalSection(&d3d9_cs);
     221    wined3d_mutex_unlock();
     222
    214223    return hr;
    215224}
     
    226235
    227236    TRACE("(%p) : Relay\n", This);
    228     EnterCriticalSection(&d3d9_cs);
     237
     238    wined3d_mutex_lock();
    229239    hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
    230     LeaveCriticalSection(&d3d9_cs);
     240    wined3d_mutex_unlock();
     241
    231242    return hr;
    232243}
     
    237248    TRACE("(%p) : Relay\n", This);
    238249
    239     EnterCriticalSection(&d3d9_cs);
     250    wined3d_mutex_lock();
    240251    hr = IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
    241     LeaveCriticalSection(&d3d9_cs);
     252    wined3d_mutex_unlock();
     253
    242254    return hr;
    243255}
     
    248260    TRACE("(%p) : Relay\n", This);
    249261
    250     EnterCriticalSection(&d3d9_cs);
     262    wined3d_mutex_lock();
    251263    hr = IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
    252     LeaveCriticalSection(&d3d9_cs);
     264    wined3d_mutex_unlock();
     265
    253266    return hr;
    254267}
     
    259272    TRACE("(%p) : Relay\n", This);
    260273
    261     EnterCriticalSection(&d3d9_cs);
     274    wined3d_mutex_lock();
    262275    hr = IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
    263     LeaveCriticalSection(&d3d9_cs);
     276    wined3d_mutex_unlock();
     277
    264278    return hr;
    265279}
     
    270284    TRACE("(%p) : Relay\n", This);
    271285
    272     EnterCriticalSection(&d3d9_cs);
     286    wined3d_mutex_lock();
    273287    hr = IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
    274     LeaveCriticalSection(&d3d9_cs);
    275     return hr;
    276 }
     288    wined3d_mutex_unlock();
     289
     290    return hr;
     291}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volume.c

    r21731 r23571  
    6363        ULONG ref = InterlockedIncrement(&This->ref);
    6464        TRACE("(%p) : AddRef from %d\n", This, ref - 1);
     65
     66        if (ref == 1)
     67        {
     68            wined3d_mutex_lock();
     69            IWineD3DVolume_AddRef(This->wineD3DVolume);
     70            wined3d_mutex_unlock();
     71        }
     72
    6573        return ref;
    6674    }
     
    8290
    8391        if (ref == 0) {
    84             EnterCriticalSection(&d3d9_cs);
     92            wined3d_mutex_lock();
    8593            IWineD3DVolume_Release(This->wineD3DVolume);
    86             LeaveCriticalSection(&d3d9_cs);
    87             HeapFree(GetProcessHeap(), 0, This);
     94            wined3d_mutex_unlock();
    8895        }
    8996
     
    99106    TRACE("iface %p, ppDevice %p\n", iface, ppDevice);
    100107
    101     EnterCriticalSection(&d3d9_cs);
     108    wined3d_mutex_lock();
    102109
    103110    IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
     
    105112    IWineD3DDevice_Release(myDevice);
    106113
    107     LeaveCriticalSection(&d3d9_cs);
     114    wined3d_mutex_unlock();
    108115
    109116    return D3D_OK;
     
    116123    TRACE("(%p) Relay\n", This);
    117124
    118     EnterCriticalSection(&d3d9_cs);
     125    wined3d_mutex_lock();
    119126
    120127    hr = IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
    121128
    122     LeaveCriticalSection(&d3d9_cs);
     129    wined3d_mutex_unlock();
    123130
    124131    return hr;
     
    131138    TRACE("(%p) Relay\n", This);
    132139
    133     EnterCriticalSection(&d3d9_cs);
     140    wined3d_mutex_lock();
    134141
    135142    hr = IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
    136143
    137     LeaveCriticalSection(&d3d9_cs);
     144    wined3d_mutex_unlock();
    138145
    139146    return hr;
     
    146153    TRACE("(%p) Relay\n", This);
    147154
    148     EnterCriticalSection(&d3d9_cs);
     155    wined3d_mutex_lock();
    149156
    150157    hr = IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
    151158
    152     LeaveCriticalSection(&d3d9_cs);
     159    wined3d_mutex_unlock();
    153160
    154161    return hr;
     
    181188    TRACE("(%p) Relay\n", This);
    182189
    183     EnterCriticalSection(&d3d9_cs);
     190    wined3d_mutex_lock();
    184191
    185192    hr = IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
    186193
    187     LeaveCriticalSection(&d3d9_cs);
     194    wined3d_mutex_unlock();
    188195
    189196    if (SUCCEEDED(hr))
     
    207214    TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
    208215
    209     EnterCriticalSection(&d3d9_cs);
     216    wined3d_mutex_lock();
    210217
    211218    hr = IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *)pLockedVolume,
    212219            (const WINED3DBOX *)pBox, Flags);
    213220
    214     LeaveCriticalSection(&d3d9_cs);
     221    wined3d_mutex_unlock();
    215222
    216223    return hr;
     
    223230    TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
    224231
    225     EnterCriticalSection(&d3d9_cs);
     232    wined3d_mutex_lock();
    226233
    227234    hr = IWineD3DVolume_UnlockBox(This->wineD3DVolume);
    228235
    229     LeaveCriticalSection(&d3d9_cs);
    230 
    231     return hr;
    232 }
    233 
    234 const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
     236    wined3d_mutex_unlock();
     237
     238    return hr;
     239}
     240
     241static const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
    235242{
    236243    /* IUnknown */
     
    249256};
    250257
    251 ULONG WINAPI D3D9CB_DestroyVolume(IWineD3DVolume *pVolume) {
    252     IDirect3DVolume9Impl* volumeParent;
    253 
    254     IWineD3DVolume_GetParent(pVolume, (IUnknown **) &volumeParent);
    255     /* GetParent's AddRef was forwarded to an object in destruction.
    256      * Releasing it here again would cause an endless recursion. */
    257     volumeParent->forwardReference = NULL;
    258     return IDirect3DVolume9_Release((IDirect3DVolume9*) volumeParent);
    259 }
     258static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
     259{
     260    HeapFree(GetProcessHeap(), 0, parent);
     261}
     262
     263static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops =
     264{
     265    volume_wined3d_object_destroyed,
     266};
     267
     268HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height,
     269        UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool)
     270{
     271    HRESULT hr;
     272
     273    volume->lpVtbl = &Direct3DVolume9_Vtbl;
     274    volume->ref = 1;
     275
     276    hr = IWineD3DDevice_CreateVolume(device->WineD3DDevice, width, height, depth, usage & WINED3DUSAGE_MASK,
     277            format, pool, &volume->wineD3DVolume, (IUnknown *)volume, &d3d9_volume_wined3d_parent_ops);
     278    if (FAILED(hr))
     279    {
     280        WARN("Failed to create wined3d volume, hr %#x.\n", hr);
     281        return hr;
     282    }
     283
     284    return D3D_OK;
     285}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volumetexture.c

    r21731 r23571  
    5858    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5959
     60    if (ref == 1)
     61    {
     62        IDirect3DDevice9Ex_AddRef(This->parentDevice);
     63        wined3d_mutex_lock();
     64        IWineD3DVolumeTexture_AddRef(This->wineD3DVolumeTexture);
     65        wined3d_mutex_unlock();
     66    }
     67
    6068    return ref;
    6169}
     
    6876
    6977    if (ref == 0) {
    70         EnterCriticalSection(&d3d9_cs);
    71         IWineD3DVolumeTexture_Destroy(This->wineD3DVolumeTexture, D3D9CB_DestroyVolume);
    72         LeaveCriticalSection(&d3d9_cs);
    7378        IDirect3DDevice9Ex_Release(This->parentDevice);
    74         HeapFree(GetProcessHeap(), 0, This);
     79        wined3d_mutex_lock();
     80        IWineD3DVolumeTexture_Release(This->wineD3DVolumeTexture);
     81        wined3d_mutex_unlock();
    7582    }
    7683    return ref;
     
    8592    TRACE("(%p) Relay\n", This);
    8693
    87     EnterCriticalSection(&d3d9_cs);
     94    wined3d_mutex_lock();
    8895    hr = IWineD3DStateBlock_GetDevice(This->wineD3DVolumeTexture, &wined3d_device);
    8996    if (SUCCEEDED(hr))
     
    9299        IWineD3DDevice_Release(wined3d_device);
    93100    }
    94     LeaveCriticalSection(&d3d9_cs);
     101    wined3d_mutex_unlock();
    95102
    96103    return hr;
     
    103110    TRACE("(%p) Relay\n", This);
    104111
    105     EnterCriticalSection(&d3d9_cs);
     112    wined3d_mutex_lock();
    106113
    107114    hr = IWineD3DVolumeTexture_SetPrivateData(This->wineD3DVolumeTexture, refguid, pData, SizeOfData, Flags);
    108115
    109     LeaveCriticalSection(&d3d9_cs);
     116    wined3d_mutex_unlock();
    110117
    111118    return hr;
     
    118125    TRACE("(%p) Relay\n", This);
    119126
    120     EnterCriticalSection(&d3d9_cs);
     127    wined3d_mutex_lock();
    121128
    122129    hr = IWineD3DVolumeTexture_GetPrivateData(This->wineD3DVolumeTexture, refguid, pData, pSizeOfData);
    123130
    124     LeaveCriticalSection(&d3d9_cs);
     131    wined3d_mutex_unlock();
    125132
    126133    return hr;
     
    133140    TRACE("(%p) Relay\n", This);
    134141
    135     EnterCriticalSection(&d3d9_cs);
     142    wined3d_mutex_lock();
    136143
    137144    hr = IWineD3DVolumeTexture_FreePrivateData(This->wineD3DVolumeTexture, refguid);
    138145
    139     LeaveCriticalSection(&d3d9_cs);
     146    wined3d_mutex_unlock();
    140147
    141148    return hr;
     
    148155    TRACE("(%p) Relay\n", This);
    149156
    150     EnterCriticalSection(&d3d9_cs);
     157    wined3d_mutex_lock();
    151158
    152159    priority = IWineD3DVolumeTexture_SetPriority(This->wineD3DVolumeTexture, PriorityNew);
    153160
    154     LeaveCriticalSection(&d3d9_cs);
     161    wined3d_mutex_unlock();
    155162
    156163    return priority;
     
    163170    TRACE("(%p) Relay\n", This);
    164171
    165     EnterCriticalSection(&d3d9_cs);
     172    wined3d_mutex_lock();
    166173
    167174    priority = IWineD3DVolumeTexture_GetPriority(This->wineD3DVolumeTexture);
    168175
    169     LeaveCriticalSection(&d3d9_cs);
     176    wined3d_mutex_unlock();
    170177
    171178    return priority;
     
    177184    TRACE("(%p) Relay\n", This);
    178185
    179     EnterCriticalSection(&d3d9_cs);
     186    wined3d_mutex_lock();
    180187
    181188    IWineD3DVolumeTexture_PreLoad(This->wineD3DVolumeTexture);
    182189
    183     LeaveCriticalSection(&d3d9_cs);
     190    wined3d_mutex_unlock();
    184191}
    185192
     
    190197    TRACE("(%p) Relay\n", This);
    191198
    192     EnterCriticalSection(&d3d9_cs);
     199    wined3d_mutex_lock();
    193200
    194201    type = IWineD3DVolumeTexture_GetType(This->wineD3DVolumeTexture);
    195202
    196     LeaveCriticalSection(&d3d9_cs);
     203    wined3d_mutex_unlock();
    197204
    198205    return type;
     
    206213    TRACE("(%p) Relay\n", This);
    207214
    208     EnterCriticalSection(&d3d9_cs);
     215    wined3d_mutex_lock();
    209216
    210217    lod = IWineD3DVolumeTexture_SetLOD(This->wineD3DVolumeTexture, LODNew);
    211218
    212     LeaveCriticalSection(&d3d9_cs);
     219    wined3d_mutex_unlock();
    213220
    214221    return lod;
     
    221228    TRACE("(%p) Relay\n", This);
    222229
    223     EnterCriticalSection(&d3d9_cs);
     230    wined3d_mutex_lock();
    224231
    225232    lod = IWineD3DVolumeTexture_GetLOD(This->wineD3DVolumeTexture);
    226233
    227     LeaveCriticalSection(&d3d9_cs);
     234    wined3d_mutex_unlock();
    228235
    229236    return lod;
     
    236243    TRACE("(%p) Relay\n", This);
    237244
    238     EnterCriticalSection(&d3d9_cs);
     245    wined3d_mutex_lock();
    239246
    240247    level_count = IWineD3DVolumeTexture_GetLevelCount(This->wineD3DVolumeTexture);
    241248
    242     LeaveCriticalSection(&d3d9_cs);
     249    wined3d_mutex_unlock();
    243250
    244251    return level_count;
     
    251258    TRACE("(%p) Relay\n", This);
    252259
    253     EnterCriticalSection(&d3d9_cs);
     260    wined3d_mutex_lock();
    254261
    255262    hr = IWineD3DVolumeTexture_SetAutoGenFilterType(This->wineD3DVolumeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
    256263
    257     LeaveCriticalSection(&d3d9_cs);
     264    wined3d_mutex_unlock();
    258265
    259266    return hr;
     
    266273    TRACE("(%p) Relay\n", This);
    267274
    268     EnterCriticalSection(&d3d9_cs);
     275    wined3d_mutex_lock();
    269276
    270277    filter_type = (D3DTEXTUREFILTERTYPE)IWineD3DVolumeTexture_GetAutoGenFilterType(This->wineD3DVolumeTexture);
    271278
    272     LeaveCriticalSection(&d3d9_cs);
     279    wined3d_mutex_unlock();
    273280
    274281    return filter_type;
     
    280287    TRACE("(%p) Relay\n", This);
    281288
    282     EnterCriticalSection(&d3d9_cs);
     289    wined3d_mutex_lock();
    283290
    284291    IWineD3DVolumeTexture_GenerateMipSubLevels(This->wineD3DVolumeTexture);
    285292
    286     LeaveCriticalSection(&d3d9_cs);
     293    wined3d_mutex_unlock();
    287294}
    288295
     
    295302    TRACE("(%p) Relay\n", This);
    296303
    297     EnterCriticalSection(&d3d9_cs);
     304    wined3d_mutex_lock();
    298305
    299306    hr = IWineD3DVolumeTexture_GetLevelDesc(This->wineD3DVolumeTexture, Level, &wined3ddesc);
    300307
    301     LeaveCriticalSection(&d3d9_cs);
     308    wined3d_mutex_unlock();
    302309
    303310    if (SUCCEEDED(hr))
     
    322329    TRACE("(%p) Relay\n", This);
    323330
    324     EnterCriticalSection(&d3d9_cs);
     331    wined3d_mutex_lock();
    325332
    326333    hrc = IWineD3DVolumeTexture_GetVolumeLevel(This->wineD3DVolumeTexture, Level, &myVolume);
     
    330337    }
    331338
    332     LeaveCriticalSection(&d3d9_cs);
     339    wined3d_mutex_unlock();
    333340
    334341    return hrc;
     
    341348    TRACE("(%p) Relay %p %p %p %d\n", This, This->wineD3DVolumeTexture, pLockedVolume, pBox,Flags);
    342349
    343     EnterCriticalSection(&d3d9_cs);
     350    wined3d_mutex_lock();
    344351
    345352    hr = IWineD3DVolumeTexture_LockBox(This->wineD3DVolumeTexture, Level, (WINED3DLOCKED_BOX *)pLockedVolume,
    346353            (const WINED3DBOX *)pBox, Flags);
    347354
    348     LeaveCriticalSection(&d3d9_cs);
     355    wined3d_mutex_unlock();
    349356
    350357    return hr;
     
    357364    TRACE("(%p) Relay %p %d\n", This, This->wineD3DVolumeTexture, Level);
    358365
    359     EnterCriticalSection(&d3d9_cs);
     366    wined3d_mutex_lock();
    360367
    361368    hr = IWineD3DVolumeTexture_UnlockBox(This->wineD3DVolumeTexture, Level);
    362369
    363     LeaveCriticalSection(&d3d9_cs);
     370    wined3d_mutex_unlock();
    364371
    365372    return hr;
     
    372379    TRACE("(%p) Relay\n", This);
    373380
    374     EnterCriticalSection(&d3d9_cs);
     381    wined3d_mutex_lock();
    375382
    376383    hr = IWineD3DVolumeTexture_AddDirtyBox(This->wineD3DVolumeTexture, (CONST WINED3DBOX *)pDirtyBox);
    377384
    378     LeaveCriticalSection(&d3d9_cs);
     385    wined3d_mutex_unlock();
    379386
    380387    return hr;
     
    412419};
    413420
    414 
    415 /* IDirect3DDevice9 IDirect3DVolumeTexture9 Methods follow: */
    416 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVolumeTexture(LPDIRECT3DDEVICE9EX iface,
    417                                                           UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage,
    418                                                           D3DFORMAT Format, D3DPOOL Pool,
    419                                                           IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle) {
    420 
    421     IDirect3DVolumeTexture9Impl *object;
    422     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    423     HRESULT hrc = D3D_OK;
    424 
    425     TRACE("(%p) Relay\n", This);
    426 
    427     /* Allocate the storage for the device */
    428     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture9Impl));
    429     if (NULL == object) {
    430         ERR("(%p) allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n", This);
    431         return D3DERR_OUTOFVIDEOMEMORY;
    432     }
    433 
    434     object->lpVtbl = &Direct3DVolumeTexture9_Vtbl;
    435     object->ref = 1;
    436 
    437     EnterCriticalSection(&d3d9_cs);
    438 
    439     hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels,
    440             Usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(Format),
    441             Pool, &object->wineD3DVolumeTexture, (IUnknown *)object);
    442 
    443     LeaveCriticalSection(&d3d9_cs);
    444 
    445     if (hrc != D3D_OK) {
    446 
    447         /* free up object */
    448         WARN("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
    449         HeapFree(GetProcessHeap(), 0, object);
    450     } else {
    451         IDirect3DDevice9Ex_AddRef(iface);
    452         object->parentDevice = iface;
    453         *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE9) object;
    454         TRACE("(%p) : Created volume texture %p\n", This, object);
    455     }
    456     TRACE("(%p)  returning %p\n", This , *ppVolumeTexture);
    457     return hrc;
    458 }
     421static void STDMETHODCALLTYPE volumetexture_wined3d_object_destroyed(void *parent)
     422{
     423    HeapFree(GetProcessHeap(), 0, parent);
     424}
     425
     426static const struct wined3d_parent_ops d3d9_volumetexture_wined3d_parent_ops =
     427{
     428    volumetexture_wined3d_object_destroyed,
     429};
     430
     431HRESULT volumetexture_init(IDirect3DVolumeTexture9Impl *texture, IDirect3DDevice9Impl *device,
     432        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
     433{
     434    HRESULT hr;
     435
     436    texture->lpVtbl = &Direct3DVolumeTexture9_Vtbl;
     437    texture->ref = 1;
     438
     439    wined3d_mutex_lock();
     440    hr = IWineD3DDevice_CreateVolumeTexture(device->WineD3DDevice, width, height, depth, levels,
     441            usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
     442            &texture->wineD3DVolumeTexture, (IUnknown *)texture, &d3d9_volumetexture_wined3d_parent_ops);
     443    wined3d_mutex_unlock();
     444    if (FAILED(hr))
     445    {
     446        WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
     447        return hr;
     448    }
     449
     450    texture->parentDevice = (IDirect3DDevice9Ex *)device;
     451    IDirect3DDevice9Ex_AddRef(texture->parentDevice);
     452
     453    return D3D_OK;
     454}
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