VirtualBox

Ignore:
Timestamp:
Oct 6, 2009 6:07:06 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
53228
Message:

crOpenGL: update to wine 1.1.30

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

Legend:

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

    r21731 r23571  
    5656    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5757
     58    if (ref == 1)
     59    {
     60        IUnknown_AddRef(This->parentDevice);
     61        wined3d_mutex_lock();
     62        IWineD3DCubeTexture_AddRef(This->wineD3DCubeTexture);
     63        wined3d_mutex_unlock();
     64    }
     65
    5866    return ref;
    5967}
     
    6775    if (ref == 0) {
    6876        TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
    69         EnterCriticalSection(&d3d8_cs);
    70         IWineD3DCubeTexture_Destroy(This->wineD3DCubeTexture, D3D8CB_DestroySurface);
    71         LeaveCriticalSection(&d3d8_cs);
     77
    7278        IUnknown_Release(This->parentDevice);
    73         HeapFree(GetProcessHeap(), 0, This);
     79        wined3d_mutex_lock();
     80        IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
     81        wined3d_mutex_unlock();
    7482    }
    7583    return ref;
     
    8391    TRACE("(%p) Relay\n" , This);
    8492
    85     EnterCriticalSection(&d3d8_cs);
     93    wined3d_mutex_lock();
    8694    hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
    8795    if (SUCCEEDED(hr))
     
    9098        IWineD3DDevice_Release(wined3d_device);
    9199    }
    92     LeaveCriticalSection(&d3d8_cs);
     100    wined3d_mutex_unlock();
     101
    93102    return hr;
    94103}
     
    99108    TRACE("(%p) Relay\n", This);
    100109
    101     EnterCriticalSection(&d3d8_cs);
     110    wined3d_mutex_lock();
    102111    hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
    103     LeaveCriticalSection(&d3d8_cs);
     112    wined3d_mutex_unlock();
     113
    104114    return hr;
    105115}
     
    110120    TRACE("(%p) Relay\n", This);
    111121
    112     EnterCriticalSection(&d3d8_cs);
     122    wined3d_mutex_lock();
    113123    hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
    114     LeaveCriticalSection(&d3d8_cs);
     124    wined3d_mutex_unlock();
     125
    115126    return hr;
    116127}
     
    121132    TRACE("(%p) Relay\n", This);
    122133
    123     EnterCriticalSection(&d3d8_cs);
     134    wined3d_mutex_lock();
    124135    hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
    125     LeaveCriticalSection(&d3d8_cs);
     136    wined3d_mutex_unlock();
     137
    126138    return hr;
    127139}
     
    132144    TRACE("(%p) Relay\n", This);
    133145
    134     EnterCriticalSection(&d3d8_cs);
     146    wined3d_mutex_lock();
    135147    ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
    136     LeaveCriticalSection(&d3d8_cs);
     148    wined3d_mutex_unlock();
     149
    137150    return ret;
    138151}
     
    143156    TRACE("(%p) Relay\n", This);
    144157
    145     EnterCriticalSection(&d3d8_cs);
     158    wined3d_mutex_lock();
    146159    ret =  IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
    147     LeaveCriticalSection(&d3d8_cs);
     160    wined3d_mutex_unlock();
     161
    148162    return ret;
    149163}
     
    153167    TRACE("(%p) Relay\n", This);
    154168
    155     EnterCriticalSection(&d3d8_cs);
     169    wined3d_mutex_lock();
    156170    IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
    157     LeaveCriticalSection(&d3d8_cs);
     171    wined3d_mutex_unlock();
    158172}
    159173
     
    163177    TRACE("(%p) Relay\n", This);
    164178
    165     EnterCriticalSection(&d3d8_cs);
     179    wined3d_mutex_lock();
    166180    type = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
    167     LeaveCriticalSection(&d3d8_cs);
     181    wined3d_mutex_unlock();
     182
    168183    return type;
    169184}
     
    175190    TRACE("(%p) Relay\n", This);
    176191
    177     EnterCriticalSection(&d3d8_cs);
     192    wined3d_mutex_lock();
    178193    lod = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
    179     LeaveCriticalSection(&d3d8_cs);
     194    wined3d_mutex_unlock();
     195
    180196    return lod;
    181197}
     
    186202    TRACE("(%p) Relay\n", This);
    187203
    188     EnterCriticalSection(&d3d8_cs);
     204    wined3d_mutex_lock();
    189205    lod = IWineD3DCubeTexture_GetLOD((LPDIRECT3DBASETEXTURE8) This);
    190     LeaveCriticalSection(&d3d8_cs);
     206    wined3d_mutex_unlock();
     207
    191208    return lod;
    192209}
     
    197214    TRACE("(%p) Relay\n", This);
    198215
    199     EnterCriticalSection(&d3d8_cs);
     216    wined3d_mutex_lock();
    200217    cnt = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
    201     LeaveCriticalSection(&d3d8_cs);
     218    wined3d_mutex_unlock();
     219
    202220    return cnt;
    203221}
     
    211229    TRACE("(%p) Relay\n", This);
    212230
    213     EnterCriticalSection(&d3d8_cs);
     231    wined3d_mutex_lock();
    214232    hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
    215     LeaveCriticalSection(&d3d8_cs);
     233    wined3d_mutex_unlock();
    216234
    217235    if (SUCCEEDED(hr))
     
    237255    TRACE("(%p) Relay\n", This);
    238256
    239     EnterCriticalSection(&d3d8_cs);
     257    wined3d_mutex_lock();
    240258    hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
    241259    if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
     
    243261       IWineD3DCubeTexture_Release(mySurface);
    244262    }
    245     LeaveCriticalSection(&d3d8_cs);
     263    wined3d_mutex_unlock();
     264
    246265    return hrc;
    247266}
     
    252271    TRACE("(%p) Relay\n", This);
    253272
    254     EnterCriticalSection(&d3d8_cs);
     273    wined3d_mutex_lock();
    255274    hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
    256     LeaveCriticalSection(&d3d8_cs);
     275    wined3d_mutex_unlock();
     276
    257277    return hr;
    258278}
     
    263283    TRACE("(%p) Relay\n", This);
    264284
    265     EnterCriticalSection(&d3d8_cs);
     285    wined3d_mutex_lock();
    266286    hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
    267     LeaveCriticalSection(&d3d8_cs);
     287    wined3d_mutex_unlock();
     288
    268289    return hr;
    269290}
     
    274295    TRACE("(%p) Relay\n", This);
    275296
    276     EnterCriticalSection(&d3d8_cs);
     297    wined3d_mutex_lock();
    277298    hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
    278     LeaveCriticalSection(&d3d8_cs);
    279     return hr;
    280 }
    281 
    282 
    283 const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
     299    wined3d_mutex_unlock();
     300
     301    return hr;
     302}
     303
     304static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
    284305{
    285306    /* IUnknown */
     
    307328    IDirect3DCubeTexture8Impl_AddDirtyRect
    308329};
     330
     331static void STDMETHODCALLTYPE d3d8_cubetexture_wined3d_object_destroyed(void *parent)
     332{
     333    HeapFree(GetProcessHeap(), 0, parent);
     334}
     335
     336static const struct wined3d_parent_ops d3d8_cubetexture_wined3d_parent_ops =
     337{
     338    d3d8_cubetexture_wined3d_object_destroyed,
     339};
     340
     341HRESULT cubetexture_init(IDirect3DCubeTexture8Impl *texture, IDirect3DDevice8Impl *device,
     342        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
     343{
     344    HRESULT hr;
     345
     346    texture->lpVtbl = &Direct3DCubeTexture8_Vtbl;
     347    texture->ref = 1;
     348
     349    wined3d_mutex_lock();
     350    hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length, levels, usage & WINED3DUSAGE_MASK,
     351            wined3dformat_from_d3dformat(format), pool, &texture->wineD3DCubeTexture,
     352            (IUnknown *)texture, &d3d8_cubetexture_wined3d_parent_ops);
     353    wined3d_mutex_unlock();
     354    if (FAILED(hr))
     355    {
     356        WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
     357        return hr;
     358    }
     359
     360    texture->parentDevice = (IDirect3DDevice8 *)device;
     361    IDirect3DDevice8_AddRef(texture->parentDevice);
     362
     363    return D3D_OK;
     364}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_main.c

    r16477 r23571  
    3434#include "wine/debug.h"
    3535
    36 static CRITICAL_SECTION_DEBUG d3d8_cs_debug =
    37 {
    38     0, 0, &d3d8_cs,
    39     { &d3d8_cs_debug.ProcessLocksList,
    40       &d3d8_cs_debug.ProcessLocksList },
    41     0, 0, { (DWORD_PTR)(__FILE__ ": d3d8_cs") }
    42 };
    43 CRITICAL_SECTION d3d8_cs = { &d3d8_cs_debug, -1, 0, 0, 0, 0 };
    44 
    4536WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
    4637
     
    5849    TRACE("SDKVersion = %x\n", SDKVersion);
    5950
    60     EnterCriticalSection(&d3d8_cs);
     51    wined3d_mutex_lock();
     52
    6153    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3D8Impl));
    6254
     
    6658
    6759    TRACE("Created Direct3D object @ %p, WineObj @ %p\n", object, object->WineD3D);
    68     LeaveCriticalSection(&d3d8_cs);
     60
     61    wined3d_mutex_unlock();
    6962
    7063    if (!object->WineD3D)
     
    8780
    8881/***********************************************************************
    89  *              ValidateVertexShader (D3D8.@)
     82 *              ValidateVertexShader (D3D8.@)
    9083 *
    9184 * I've seen reserved1 and reserved2 always passed as 0's
    92  * bool seems always passed as 0 or 1, but other values work as well....
     85 * bool seems always passed as 0 or 1, but other values work as well...
    9386 * toto       result?
    9487 */
    9588HRESULT WINAPI ValidateVertexShader(DWORD* vertexshader, DWORD* reserved1, DWORD* reserved2, BOOL bool, DWORD* toto)
    96 { 
     89{
    9790  HRESULT ret;
    9891  FIXME("(%p %p %p %d %p): stub\n", vertexshader, reserved1, reserved2, bool, toto);
     
    10699  switch(*vertexshader) {
    107100        case 0xFFFE0101:
    108         case 0xFFFE0100: 
     101        case 0xFFFE0100:
    109102            ret=S_OK;
    110103            break;
     
    118111
    119112/***********************************************************************
    120  *              ValidatePixelShader (D3D8.@)
     113 *              ValidatePixelShader (D3D8.@)
    121114 *
    122115 * PARAMS
     
    127120  HRESULT ret;
    128121  FIXME("(%p %p %d %p): stub\n", pixelshader, reserved1, bool, toto);
    129  
     122
    130123  if (!pixelshader)
    131124      return E_FAIL;
    132125
    133126  if (reserved1)
    134       return E_FAIL;   
     127      return E_FAIL;
    135128
    136129  switch(*pixelshader) {
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_private.h

    r22496 r23571  
    107107    _pD3D8Caps->MaxPixelShaderValue               = _pWineCaps->PixelShader1xMaxValue;
    108108
    109 void fixup_caps(WINED3DCAPS *pWineCaps);
     109void fixup_caps(WINED3DCAPS *pWineCaps) DECLSPEC_HIDDEN;
    110110
    111111/* Direct3D8 Interfaces: */
     
    132132typedef struct IDirect3DVertexShader8Impl IDirect3DVertexShader8Impl;
    133133
    134 /* Global critical section */
    135 extern CRITICAL_SECTION d3d8_cs;
    136 
    137134/* ===========================================================================
    138135    The interfaces themselves
     
    146143 * Predeclare the interface implementation structures
    147144 */
    148 extern const IDirect3D8Vtbl Direct3D8_Vtbl;
     145extern const IDirect3D8Vtbl Direct3D8_Vtbl DECLSPEC_HIDDEN;
    149146
    150147/*****************************************************************************
     
    168165 * Predeclare the interface implementation structures
    169166 */
    170 extern const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl;
    171 extern const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl;
     167extern const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl DECLSPEC_HIDDEN;
     168extern const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl DECLSPEC_HIDDEN;
    172169
    173170/*****************************************************************************
     
    231228 * IDirect3DVolume8 implementation structure
    232229 */
    233 extern const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl;
    234230struct IDirect3DVolume8Impl
    235231{
     
    247243    IUnknown                    *forwardReference;
    248244};
     245
     246HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, UINT width, UINT height,
     247        UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool) DECLSPEC_HIDDEN;
    249248
    250249/* ------------------- */
     
    255254 * Predeclare the interface implementation structures
    256255 */
    257 extern const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl;
     256extern const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl DECLSPEC_HIDDEN;
    258257
    259258/*****************************************************************************
     
    278277
    279278/*****************************************************************************
    280  * Predeclare the interface implementation structures
    281  */
    282 extern const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl;
    283 
    284 /*****************************************************************************
    285279 * IDirect3DSurface8 implementation structure
    286280 */
     
    302296    /* If set forward refcounting to this object */
    303297    IUnknown                    *forwardReference;
    304 
    305     /* Flags an implicit surface */
    306     BOOL                        isImplicit;
    307 };
     298};
     299
     300HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *device,
     301        UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
     302        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) DECLSPEC_HIDDEN;
    308303
    309304/* ------------------ */
     
    314309 * Predeclare the interface implementation structures
    315310 */
    316 extern const IDirect3DResource8Vtbl Direct3DResource8_Vtbl;
     311extern const IDirect3DResource8Vtbl Direct3DResource8_Vtbl DECLSPEC_HIDDEN;
    317312
    318313/*****************************************************************************
     
    334329
    335330/*****************************************************************************
    336  * Predeclare the interface implementation structures
    337  */
    338 extern const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl;
    339 
    340 /*****************************************************************************
    341331 * IDirect3DVertexBuffer8 implementation structure
    342332 */
     
    355345    DWORD                             fvf;
    356346};
     347
     348HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
     349        UINT size, DWORD usage, DWORD fvf, D3DPOOL pool) DECLSPEC_HIDDEN;
    357350
    358351/* --------------------- */
     
    361354
    362355/*****************************************************************************
    363  * Predeclare the interface implementation structures
    364  */
    365 extern const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl;
    366 
    367 /*****************************************************************************
    368356 * IDirect3DIndexBuffer8 implementation structure
    369357 */
     
    382370    WINED3DFORMAT                    format;
    383371};
     372
     373HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
     374        UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
    384375
    385376/* --------------------- */
     
    405396
    406397/*****************************************************************************
    407  * Predeclare the interface implementation structures
    408  */
    409 extern const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl;
    410 
    411 /*****************************************************************************
    412398 * IDirect3DCubeTexture8 implementation structure
    413399 */
     
    424410    LPDIRECT3DDEVICE8                parentDevice;
    425411};
     412
     413HRESULT cubetexture_init(IDirect3DCubeTexture8Impl *texture, IDirect3DDevice8Impl *device,
     414        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
    426415
    427416/* ----------------- */
     
    430419
    431420/*****************************************************************************
    432  * Predeclare the interface implementation structures
    433  */
    434 extern const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl;
    435 
    436 /*****************************************************************************
    437421 * IDirect3DTexture8 implementation structure
    438422 */
     
    449433    LPDIRECT3DDEVICE8            parentDevice;
    450434};
     435
     436HRESULT texture_init(IDirect3DTexture8Impl *texture, IDirect3DDevice8Impl *device,
     437        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
    451438
    452439/* ----------------------- */
     
    455442
    456443/*****************************************************************************
    457  * Predeclare the interface implementation structures
    458  */
    459 extern const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl;
    460 
    461 /*****************************************************************************
    462444 * IDirect3DVolumeTexture8 implementation structure
    463445 */
     
    474456    LPDIRECT3DDEVICE8                  parentDevice;
    475457};
     458
     459HRESULT volumetexture_init(IDirect3DVolumeTexture8Impl *texture, IDirect3DDevice8Impl *device,
     460        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
    476461
    477462/* ----------------------- */
     
    481466/* TODO: Generate a valid GUIDs */
    482467/* {83B073CE-6F30-11d9-C687-00046142C14F} */
    483 DEFINE_GUID(IID_IDirect3DStateBlock8, 
     468DEFINE_GUID(IID_IDirect3DStateBlock8,
    4844690x83b073ce, 0x6f30, 0x11d9, 0xc6, 0x87, 0x0, 0x4, 0x61, 0x42, 0xc1, 0x4f);
    485470
     
    523508 * Predeclare the interface implementation structures
    524509 */
    525 extern const IDirect3DStateBlock8Vtbl Direct3DStateBlock8_Vtbl;
     510extern const IDirect3DStateBlock8Vtbl Direct3DStateBlock8_Vtbl DECLSPEC_HIDDEN;
    526511
    527512/*****************************************************************************
     
    555540#define IDirect3DVertexDeclaration8_Release(p)             (p)->lpVtbl->Release(p)
    556541
    557 /*** Implementation ***/
    558 extern const IDirect3DVertexDeclaration8Vtbl Direct3DVertexDeclaration8_Vtbl;
    559 
    560542typedef struct {
    561543    const IDirect3DVertexDeclaration8Vtbl *lpVtbl;
     
    569551} IDirect3DVertexDeclaration8Impl;
    570552
     553HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
     554        IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle) DECLSPEC_HIDDEN;
     555HRESULT vertexdeclaration_init_fvf(IDirect3DVertexDeclaration8Impl *declaration,
     556        IDirect3DDevice8Impl *device, DWORD fvf) DECLSPEC_HIDDEN;
    571557
    572558/*****************************************************************************
     
    611597
    612598/*****************************************************************************
    613  * Predeclare the interface implementation structures
    614  */
    615 extern const IDirect3DVertexShader8Vtbl Direct3DVertexShader8_Vtbl;
    616 
    617 /*****************************************************************************
    618599 * IDirect3DVertexShader implementation structure
    619600 */
     
    627608};
    628609
     610HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Impl *device,
     611        const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage) DECLSPEC_HIDDEN;
     612
    629613#define D3D8_MAX_VERTEX_SHADER_CONSTANTF 256
    630 
    631 
    632 /* ------------------------ */
    633 /* IDirect3DPixelShaderImpl */
    634 /* ------------------------ */
    635 
    636 
    637 /*****************************************************************************
    638  * Predeclare the interface implementation structures
    639  */
    640 extern const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl;
    641614
    642615/*****************************************************************************
     
    650623    IWineD3DPixelShader             *wineD3DPixelShader;
    651624} IDirect3DPixelShader8Impl;
     625
     626HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl *device,
     627        const DWORD *byte_code, DWORD shader_handle) DECLSPEC_HIDDEN;
    652628
    653629/**
     
    656632 * to see how not defined it here
    657633 */
    658 D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format);
    659 WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format);
    660 void load_local_constants(const DWORD *d3d8_elements, IWineD3DVertexShader *wined3d_vertex_shader);
    661 UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size, WINED3DVERTEXELEMENT **wined3d_elements);
    662 size_t parse_token(const DWORD* pToken);
     634D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format) DECLSPEC_HIDDEN;
     635WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_HIDDEN;
     636void load_local_constants(const DWORD *d3d8_elements, IWineD3DVertexShader *wined3d_vertex_shader) DECLSPEC_HIDDEN;
     637UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size,
     638        WINED3DVERTEXELEMENT **wined3d_elements) DECLSPEC_HIDDEN;
     639size_t parse_token(const DWORD *pToken) DECLSPEC_HIDDEN;
    663640
    664641/* Callbacks */
    665 extern ULONG WINAPI D3D8CB_DestroySwapChain (IWineD3DSwapChain *pSwapChain);
    666 extern ULONG WINAPI D3D8CB_DestroyDepthStencilSurface (IWineD3DSurface *pSurface);
    667 extern ULONG WINAPI D3D8CB_DestroyRenderTarget (IWineD3DSurface *pSurface);
    668 extern ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface);
    669 extern ULONG WINAPI D3D8CB_DestroyVolume(IWineD3DVolume *pVolume);
     642extern ULONG WINAPI D3D8CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) DECLSPEC_HIDDEN;
    670643
    671644#endif /* __WINE_D3DX8_PRIVATE_H */
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/device.c

    r22496 r23571  
    5656    {
    5757        case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
    58         case WINED3DFMT_R8G8B8: return D3DFMT_R8G8B8;
    59         case WINED3DFMT_A8R8G8B8: return D3DFMT_A8R8G8B8;
    60         case WINED3DFMT_X8R8G8B8: return D3DFMT_X8R8G8B8;
    61         case WINED3DFMT_R5G6B5: return D3DFMT_R5G6B5;
    62         case WINED3DFMT_X1R5G5B5: return D3DFMT_X1R5G5B5;
    63         case WINED3DFMT_A1R5G5B5: return D3DFMT_A1R5G5B5;
    64         case WINED3DFMT_A4R4G4B4: return D3DFMT_A4R4G4B4;
    65         case WINED3DFMT_R3G3B2: return D3DFMT_R3G3B2;
     58        case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
     59        case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
     60        case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
     61        case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
     62        case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
     63        case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
     64        case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
     65        case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
    6666        case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
    67         case WINED3DFMT_A8R3G3B2: return D3DFMT_A8R3G3B2;
    68         case WINED3DFMT_X4R4G4B4: return D3DFMT_X4R4G4B4;
     67        case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
     68        case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
    6969        case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
    7070        case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
    71         case WINED3DFMT_A8P8: return D3DFMT_A8P8;
    72         case WINED3DFMT_P8: return D3DFMT_P8;
    73         case WINED3DFMT_L8: return D3DFMT_L8;
    74         case WINED3DFMT_A8L8: return D3DFMT_A8L8;
    75         case WINED3DFMT_A4L4: return D3DFMT_A4L4;
     71        case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
     72        case WINED3DFMT_P8_UINT: return D3DFMT_P8;
     73        case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
     74        case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
     75        case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
    7676        case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
    77         case WINED3DFMT_L6V5U5: return D3DFMT_L6V5U5;
    78         case WINED3DFMT_X8L8V8U8: return D3DFMT_X8L8V8U8;
     77        case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
     78        case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
    7979        case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
    8080        case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
    81         case WINED3DFMT_W11V11U10: return D3DFMT_W11V11U10;
    82         case WINED3DFMT_A2W10V10U10: return D3DFMT_A2W10V10U10;
     81        case WINED3DFMT_R10G11B11_SNORM: return D3DFMT_W11V11U10;
     82        case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
    8383        case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
    84         case WINED3DFMT_D32: return D3DFMT_D32;
    85         case WINED3DFMT_D15S1: return D3DFMT_D15S1;
    86         case WINED3DFMT_D24S8: return D3DFMT_D24S8;
    87         case WINED3DFMT_D24X8: return D3DFMT_D24X8;
    88         case WINED3DFMT_D24X4S4: return D3DFMT_D24X4S4;
     84        case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
     85        case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
     86        case WINED3DFMT_S8_UINT_D24_UNORM: return D3DFMT_D24S8;
     87        case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
     88        case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
    8989        case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
    9090        case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
     
    107107    {
    108108        case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
    109         case D3DFMT_R8G8B8: return WINED3DFMT_R8G8B8;
    110         case D3DFMT_A8R8G8B8: return WINED3DFMT_A8R8G8B8;
    111         case D3DFMT_X8R8G8B8: return WINED3DFMT_X8R8G8B8;
    112         case D3DFMT_R5G6B5: return WINED3DFMT_R5G6B5;
    113         case D3DFMT_X1R5G5B5: return WINED3DFMT_X1R5G5B5;
    114         case D3DFMT_A1R5G5B5: return WINED3DFMT_A1R5G5B5;
    115         case D3DFMT_A4R4G4B4: return WINED3DFMT_A4R4G4B4;
    116         case D3DFMT_R3G3B2: return WINED3DFMT_R3G3B2;
     109        case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
     110        case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
     111        case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
     112        case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
     113        case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
     114        case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
     115        case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
     116        case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
    117117        case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
    118         case D3DFMT_A8R3G3B2: return WINED3DFMT_A8R3G3B2;
    119         case D3DFMT_X4R4G4B4: return WINED3DFMT_X4R4G4B4;
     118        case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
     119        case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
    120120        case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
    121121        case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
    122         case D3DFMT_A8P8: return WINED3DFMT_A8P8;
    123         case D3DFMT_P8: return WINED3DFMT_P8;
    124         case D3DFMT_L8: return WINED3DFMT_L8;
    125         case D3DFMT_A8L8: return WINED3DFMT_A8L8;
    126         case D3DFMT_A4L4: return WINED3DFMT_A4L4;
     122        case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
     123        case D3DFMT_P8: return WINED3DFMT_P8_UINT;
     124        case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
     125        case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
     126        case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
    127127        case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
    128         case D3DFMT_L6V5U5: return WINED3DFMT_L6V5U5;
    129         case D3DFMT_X8L8V8U8: return WINED3DFMT_X8L8V8U8;
     128        case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
     129        case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
    130130        case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
    131131        case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
    132         case D3DFMT_W11V11U10: return WINED3DFMT_W11V11U10;
    133         case D3DFMT_A2W10V10U10: return WINED3DFMT_A2W10V10U10;
     132        case D3DFMT_W11V11U10: return WINED3DFMT_R10G11B11_SNORM;
     133        case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
    134134        case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
    135         case D3DFMT_D32: return WINED3DFMT_D32;
    136         case D3DFMT_D15S1: return WINED3DFMT_D15S1;
    137         case D3DFMT_D24S8: return WINED3DFMT_D24S8;
    138         case D3DFMT_D24X8: return WINED3DFMT_D24X8;
    139         case D3DFMT_D24X4S4: return WINED3DFMT_D24X4S4;
     135        case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
     136        case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
     137        case D3DFMT_D24S8: return WINED3DFMT_S8_UINT_D24_UNORM;
     138        case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
     139        case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
    140140        case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
    141141        case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
     
    309309
    310310        TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
    311         EnterCriticalSection(&d3d8_cs);
     311
     312        wined3d_mutex_lock();
     313
    312314        This->inDestruction = TRUE;
    313315
     
    317319        HeapFree(GetProcessHeap(), 0, This->decls);
    318320
    319         IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroyDepthStencilSurface, D3D8CB_DestroySwapChain);
     321        IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroySwapChain);
    320322        IWineD3DDevice_Release(This->WineD3DDevice);
    321323        HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
    322324        HeapFree(GetProcessHeap(), 0, This);
    323         LeaveCriticalSection(&d3d8_cs);
     325
     326        wined3d_mutex_unlock();
    324327    }
    325328    return ref;
     
    332335
    333336    TRACE("(%p) : Relay\n", This);
    334     EnterCriticalSection(&d3d8_cs);
     337
     338    wined3d_mutex_lock();
    335339    hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
    336     LeaveCriticalSection(&d3d8_cs);
     340    wined3d_mutex_unlock();
     341
    337342    return hr;
    338343}
     
    343348
    344349    TRACE("(%p) Relay\n", This);
    345     EnterCriticalSection(&d3d8_cs);
     350
     351    wined3d_mutex_lock();
    346352    hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
    347     LeaveCriticalSection(&d3d8_cs);
     353    wined3d_mutex_unlock();
     354
    348355    return hr;
    349356}
     
    354361
    355362    TRACE("(%p) : Relay bytes(%d)\n", This, Bytes);
    356     EnterCriticalSection(&d3d8_cs);
     363
     364    wined3d_mutex_lock();
    357365    hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
    358     LeaveCriticalSection(&d3d8_cs);
     366    wined3d_mutex_unlock();
     367
    359368    return hr;
    360369}
     
    371380    }
    372381
    373     EnterCriticalSection(&d3d8_cs);
     382    wined3d_mutex_lock();
    374383    hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
    375384    if (hr == D3D_OK && pWineD3D != NULL)
     
    381390        *ppD3D8 = NULL;
    382391    }
     392    wined3d_mutex_unlock();
     393
    383394    TRACE("(%p) returning %p\n",This , *ppD3D8);
    384     LeaveCriticalSection(&d3d8_cs);
    385395
    386396    return hr;
     
    401411    }
    402412
    403     EnterCriticalSection(&d3d8_cs);
     413    wined3d_mutex_lock();
    404414    hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
    405     LeaveCriticalSection(&d3d8_cs);
     415    wined3d_mutex_unlock();
     416
    406417    fixup_caps(pWineCaps);
    407418    WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
     
    417428    TRACE("(%p) Relay\n", This);
    418429
    419     EnterCriticalSection(&d3d8_cs);
     430    wined3d_mutex_lock();
    420431    hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
    421     LeaveCriticalSection(&d3d8_cs);
     432    wined3d_mutex_unlock();
    422433
    423434    if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
     
    431442    TRACE("(%p) Relay\n", This);
    432443
    433     EnterCriticalSection(&d3d8_cs);
     444    wined3d_mutex_lock();
    434445    hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
    435     LeaveCriticalSection(&d3d8_cs);
     446    wined3d_mutex_unlock();
     447
    436448    return hr;
    437449}
     
    447459    }
    448460
    449     EnterCriticalSection(&d3d8_cs);
     461    wined3d_mutex_lock();
    450462    hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
    451     LeaveCriticalSection(&d3d8_cs);
     463    wined3d_mutex_unlock();
     464
    452465    return hr;
    453466}
     
    457470    TRACE("(%p) Relay\n", This);
    458471
    459     EnterCriticalSection(&d3d8_cs);
     472    wined3d_mutex_lock();
    460473    IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
    461     LeaveCriticalSection(&d3d8_cs);
     474    wined3d_mutex_unlock();
    462475}
    463476
     
    467480    TRACE("(%p) Relay\n", This);
    468481
    469     EnterCriticalSection(&d3d8_cs);
     482    wined3d_mutex_lock();
    470483    ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
    471     LeaveCriticalSection(&d3d8_cs);
     484    wined3d_mutex_unlock();
     485
    472486    return ret;
    473487}
     
    512526    localParameters.AutoRestoreDisplayMode                      = TRUE;
    513527
    514     EnterCriticalSection(&d3d8_cs);
     528    wined3d_mutex_lock();
    515529    hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
    516530            &object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL);
    517     LeaveCriticalSection(&d3d8_cs);
     531    wined3d_mutex_unlock();
    518532
    519533    pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
     
    567581    localParameters.AutoRestoreDisplayMode                      = TRUE;
    568582
    569     EnterCriticalSection(&d3d8_cs);
     583    wined3d_mutex_lock();
    570584    hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
    571     LeaveCriticalSection(&d3d8_cs);
     585    wined3d_mutex_unlock();
    572586
    573587    pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
     
    593607    TRACE("(%p) Relay\n", This);
    594608
    595     EnterCriticalSection(&d3d8_cs);
     609    wined3d_mutex_lock();
    596610    hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
    597     LeaveCriticalSection(&d3d8_cs);
     611    wined3d_mutex_unlock();
     612
    598613    return hr;
    599614}
     
    606621    TRACE("(%p) Relay\n", This);
    607622
    608     EnterCriticalSection(&d3d8_cs);
     623    wined3d_mutex_lock();
    609624    rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
    610625    if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
     
    612627        IWineD3DSurface_Release(retSurface);
    613628    }
    614     LeaveCriticalSection(&d3d8_cs);
     629    wined3d_mutex_unlock();
     630
    615631    return rc;
    616632}
     
    621637    TRACE("(%p) Relay\n", This);
    622638
    623     EnterCriticalSection(&d3d8_cs);
     639    wined3d_mutex_lock();
    624640    hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
    625     LeaveCriticalSection(&d3d8_cs);
     641    wined3d_mutex_unlock();
     642
    626643    return hr;
    627644}
     
    632649
    633650    /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
    634     EnterCriticalSection(&d3d8_cs);
     651    wined3d_mutex_lock();
    635652    IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
    636     LeaveCriticalSection(&d3d8_cs);
     653    wined3d_mutex_unlock();
    637654}
    638655
     
    642659
    643660    /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
    644     EnterCriticalSection(&d3d8_cs);
     661    wined3d_mutex_lock();
    645662    IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
    646     LeaveCriticalSection(&d3d8_cs);
    647 }
    648 
    649 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
    650                                                     D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) {
     663    wined3d_mutex_unlock();
     664}
     665
     666static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8 *iface,
     667        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
     668        D3DPOOL pool, IDirect3DTexture8 **texture)
     669{
     670    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    651671    IDirect3DTexture8Impl *object;
    652     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    653     HRESULT hrc = D3D_OK;
    654 
    655     TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format,  Pool);
    656 
    657     /* Allocate the storage for the device */
    658     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
    659 
    660     if (NULL == object) {
    661         FIXME("Allocation of memory failed\n");
    662 /*        *ppTexture = NULL; */
     672    HRESULT hr;
     673
     674    TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
     675            iface, width, height, levels, usage, format, pool, texture);
     676
     677    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     678    if (!object)
     679    {
     680        ERR("Failed to allocate texture memory.\n");
    663681        return D3DERR_OUTOFVIDEOMEMORY;
    664682    }
    665683
    666     object->lpVtbl = &Direct3DTexture8_Vtbl;
    667     object->ref = 1;
    668     EnterCriticalSection(&d3d8_cs);
    669     hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
    670             wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, (IUnknown *)object);
    671     LeaveCriticalSection(&d3d8_cs);
    672 
    673     if (FAILED(hrc)) {
    674         /* free up object */
    675         FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
     684    hr = texture_init(object, This, width, height, levels, usage, format, pool);
     685    if (FAILED(hr))
     686    {
     687        WARN("Failed to initialize texture, hr %#x.\n", hr);
    676688        HeapFree(GetProcessHeap(), 0, object);
    677 /*      *ppTexture = NULL; */
    678    } else {
    679         IUnknown_AddRef(iface);
    680         object->parentDevice = iface;
    681         *ppTexture = (LPDIRECT3DTEXTURE8) object;
    682         TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);
    683    }
    684 
    685    return hrc;
    686 }
    687 
    688 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface,
    689                                                           UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage,
    690                                                           D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture) {
    691 
     689        return hr;
     690    }
     691
     692    TRACE("Created texture %p.\n", object);
     693    *texture = (IDirect3DTexture8 *)object;
     694
     695    return D3D_OK;
     696}
     697
     698static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
     699        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
     700        D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
     701{
     702    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    692703    IDirect3DVolumeTexture8Impl *object;
    693     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    694     HRESULT hrc = D3D_OK;
    695 
    696     TRACE("(%p) Relay\n", This);
    697 
    698     /* Allocate the storage for the device */
    699     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture8Impl));
    700     if (NULL == object) {
    701         FIXME("(%p) allocation of memory failed\n", This);
    702         *ppVolumeTexture = NULL;
     704    HRESULT hr;
     705
     706    TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
     707            iface, width, height, depth, levels, usage, format, pool, texture);
     708
     709    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     710    if (!object)
     711    {
     712        ERR("Failed to allocate volume texture memory.\n");
    703713        return D3DERR_OUTOFVIDEOMEMORY;
    704714    }
    705715
    706     object->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
    707     object->ref = 1;
    708     EnterCriticalSection(&d3d8_cs);
    709     hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels,
    710             Usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(Format),
    711             Pool, &object->wineD3DVolumeTexture, (IUnknown *)object);
    712     LeaveCriticalSection(&d3d8_cs);
    713 
    714     if (hrc != D3D_OK) {
    715 
    716         /* free up object */
    717         FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
     716    hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
     717    if (FAILED(hr))
     718    {
     719        WARN("Failed to initialize volume texture, hr %#x.\n", hr);
    718720        HeapFree(GetProcessHeap(), 0, object);
    719         *ppVolumeTexture = NULL;
    720     } else {
    721         IUnknown_AddRef(iface);
    722         object->parentDevice = iface;
    723         *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE8) object;
    724     }
    725     TRACE("(%p)  returning %p\n", This , *ppVolumeTexture);
    726     return hrc;
    727 }
    728 
    729 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage,
    730                                                         D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture) {
    731 
     721        return hr;
     722    }
     723
     724    TRACE("Created volume texture %p.\n", object);
     725    *texture = (IDirect3DVolumeTexture8 *)object;
     726
     727    return D3D_OK;
     728}
     729
     730static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
     731        UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
     732{
     733    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    732734    IDirect3DCubeTexture8Impl *object;
    733     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    734     HRESULT hr = D3D_OK;
    735 
    736     TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
    737 
    738     /* Allocate the storage for the device */
     735    HRESULT hr;
     736
     737    TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
     738            iface, edge_length, levels, usage, format, pool, texture);
     739
    739740    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
    740 
    741     if (NULL == object) {
    742         FIXME("(%p) allocation of CubeTexture failed\n", This);
    743         *ppCubeTexture = NULL;
     741    if (!object)
     742    {
     743        ERR("Failed to allocate cube texture memory.\n");
    744744        return D3DERR_OUTOFVIDEOMEMORY;
    745745    }
    746746
    747     object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
    748     object->ref = 1;
    749     EnterCriticalSection(&d3d8_cs);
    750     hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
    751             wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture, (IUnknown *)object);
    752     LeaveCriticalSection(&d3d8_cs);
    753 
    754     if (hr != D3D_OK){
    755 
    756         /* free up object */
    757         FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
     747    hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
     748    if (FAILED(hr))
     749    {
     750        WARN("Failed to initialize cube texture, hr %#x.\n", hr);
    758751        HeapFree(GetProcessHeap(), 0, object);
    759         *ppCubeTexture = NULL;
    760     } else {
    761         IUnknown_AddRef(iface);
    762         object->parentDevice = iface;
    763         *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
    764     }
    765 
    766     TRACE("(%p) returning %p\n",This, *ppCubeTexture);
    767     return hr;
    768 }
    769 
    770 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
     752        return hr;
     753    }
     754
     755    TRACE("Created cube texture %p.\n", object);
     756    *texture = (IDirect3DCubeTexture8 *)object;
     757
     758    return hr;
     759}
     760
     761static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
     762        DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
     763{
     764    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    771765    IDirect3DVertexBuffer8Impl *object;
    772     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    773     HRESULT hrc = D3D_OK;
    774 
    775     TRACE("(%p) Relay\n", This);
    776     /* Allocate the storage for the device */
    777     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
    778     if (NULL == object) {
    779         FIXME("Allocation of memory failed\n");
    780         *ppVertexBuffer = NULL;
     766    HRESULT hr;
     767
     768    TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
     769            iface, size, usage, fvf, pool, buffer);
     770
     771    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     772    if (!object)
     773    {
     774        ERR("Failed to allocate buffer memory.\n");
    781775        return D3DERR_OUTOFVIDEOMEMORY;
    782776    }
    783777
    784     object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
    785     object->ref = 1;
    786     EnterCriticalSection(&d3d8_cs);
    787     hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK,
    788             0 /* fvf for ddraw only */, (WINED3DPOOL)Pool, &object->wineD3DVertexBuffer, (IUnknown *)object);
    789     LeaveCriticalSection(&d3d8_cs);
    790     object->fvf = FVF;
    791 
    792     if (D3D_OK != hrc) {
    793 
    794         /* free up object */
    795         FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
     778    hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
     779    if (FAILED(hr))
     780    {
     781        WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
    796782        HeapFree(GetProcessHeap(), 0, object);
    797         *ppVertexBuffer = NULL;
    798     } else {
    799         IUnknown_AddRef(iface);
    800         object->parentDevice = iface;
    801         *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
    802     }
    803     return hrc;
    804 }
    805 
    806 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
     783        return hr;
     784    }
     785
     786    TRACE("Created vertex buffer %p.\n", object);
     787    *buffer = (IDirect3DVertexBuffer8 *)object;
     788
     789    return D3D_OK;
     790}
     791
     792static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
     793        D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
     794{
     795    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    807796    IDirect3DIndexBuffer8Impl *object;
    808     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    809     HRESULT hrc = D3D_OK;
    810 
    811     TRACE("(%p) Relay\n", This);
    812     /* Allocate the storage for the device */
     797    HRESULT hr;
     798
     799    TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
     800            iface, size, usage, format, pool, buffer);
     801
    813802    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
    814     if (NULL == object) {
    815         FIXME("Allocation of memory failed\n");
    816         *ppIndexBuffer = NULL;
     803    if (!object)
     804    {
     805        ERR("Failed to allocate buffer memory.\n");
    817806        return D3DERR_OUTOFVIDEOMEMORY;
    818807    }
    819808
    820     object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
    821     object->ref = 1;
    822     object->format = wined3dformat_from_d3dformat(Format);
    823     TRACE("Calling wined3d create index buffer\n");
    824     EnterCriticalSection(&d3d8_cs);
    825     hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
    826             (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
    827     LeaveCriticalSection(&d3d8_cs);
    828 
    829     if (D3D_OK != hrc) {
    830 
    831         /* free up object */
    832         FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
     809    hr = indexbuffer_init(object, This, size, usage, format, pool);
     810    if (FAILED(hr))
     811    {
     812        WARN("Failed to initialize index buffer, hr %#x.\n", hr);
    833813        HeapFree(GetProcessHeap(), 0, object);
    834         *ppIndexBuffer = NULL;
    835     } else {
    836         IUnknown_AddRef(iface);
    837         object->parentDevice = iface;
    838         *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
    839     }
    840     return hrc;
     814        return hr;
     815    }
     816
     817    TRACE("Created index buffer %p.\n", object);
     818    *buffer = (IDirect3DIndexBuffer8 *)object;
     819
     820    return D3D_OK;
    841821}
    842822
     
    845825        UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
    846826{
    847     HRESULT hrc;
     827    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    848828    IDirect3DSurface8Impl *object;
    849     IDirect3DDevice8Impl  *This = (IDirect3DDevice8Impl *)iface;
    850     TRACE("(%p) Relay\n", This);
    851 
    852     if(MultisampleQuality > 0){
    853         FIXME("MultisampleQuality set to %d, substituting 0\n" , MultisampleQuality);
    854         /*
    855         MultisampleQuality
    856         [in] Quality level. The valid range is between zero and one less than the level returned by pQualityLevels used by IDirect3D8::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.
    857         */
    858         MultisampleQuality=0;
    859     }
    860     /*FIXME: Check MAX bounds of MultisampleQuality*/
    861 
    862     /* Allocate the storage for the device */
     829    HRESULT hr;
     830
     831    TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
     832
    863833    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
    864     if (NULL == object) {
    865         FIXME("Allocation of memory failed\n");
    866         *ppSurface = NULL;
     834    if (!object)
     835    {
     836        FIXME("Failed to allocate surface memory.\n");
    867837        return D3DERR_OUTOFVIDEOMEMORY;
    868838    }
    869839
    870     object->lpVtbl = &Direct3DSurface8_Vtbl;
    871     object->ref = 1;
    872 
    873     TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
    874 
    875     EnterCriticalSection(&d3d8_cs);
    876     hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
    877             Lockable, Discard, Level, &object->wineD3DSurface, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL)Pool,
    878             MultiSample, MultisampleQuality, SURFACE_OPENGL, (IUnknown *)object);
    879     LeaveCriticalSection(&d3d8_cs);
    880     if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
    881        /* free up object */
    882         FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
     840    hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
     841            Level, Usage, Pool, MultiSample, MultisampleQuality);
     842    if (FAILED(hr))
     843    {
     844        WARN("Failed to initialize surface, hr %#x.\n", hr);
    883845        HeapFree(GetProcessHeap(), 0, object);
    884         *ppSurface = NULL;
    885     } else {
    886         IUnknown_AddRef(iface);
    887         object->parentDevice = iface;
    888         *ppSurface = (LPDIRECT3DSURFACE8) object;
    889     }
    890     return hrc;
     846        return hr;
     847    }
     848
     849    TRACE("Created surface %p.\n", object);
     850    *ppSurface = (IDirect3DSurface8 *)object;
     851
     852    return D3D_OK;
    891853}
    892854
     
    941903    /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
    942904
    943     EnterCriticalSection(&d3d8_cs);
     905    wined3d_mutex_lock();
    944906    IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
    945907    srcFormat = winedesc.format;
     
    956918    if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
    957919        WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
    958         LeaveCriticalSection(&d3d8_cs);
     920        wined3d_mutex_unlock();
    959921        return WINED3DERR_INVALIDCALL;
    960922    } else if (WINED3DFMT_UNKNOWN == destFormat) {
     
    980942        }
    981943    }
    982     LeaveCriticalSection(&d3d8_cs);
     944    wined3d_mutex_unlock();
    983945
    984946    return hr;
     
    990952    TRACE("(%p) Relay\n" , This);
    991953
    992     EnterCriticalSection(&d3d8_cs);
     954    wined3d_mutex_lock();
    993955    hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice,  ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
    994     LeaveCriticalSection(&d3d8_cs);
     956    wined3d_mutex_unlock();
     957
    995958    return hr;
    996959}
     
    1008971    }
    1009972
    1010     EnterCriticalSection(&d3d8_cs);
     973    wined3d_mutex_lock();
    1011974    hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
    1012     LeaveCriticalSection(&d3d8_cs);
     975    wined3d_mutex_unlock();
     976
    1013977    return hr;
    1014978}
     
    1022986    TRACE("(%p) Relay\n" , This);
    1023987
    1024     EnterCriticalSection(&d3d8_cs);
     988    wined3d_mutex_lock();
    1025989
    1026990    hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
     
    1034998    if (original_ds) IWineD3DSurface_Release(original_ds);
    1035999
    1036     LeaveCriticalSection(&d3d8_cs);
     1000    wined3d_mutex_unlock();
     1001
    10371002    return hr;
    10381003}
     
    10481013        return D3DERR_INVALIDCALL;
    10491014    }
    1050     EnterCriticalSection(&d3d8_cs);
     1015
     1016    wined3d_mutex_lock();
    10511017    hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
    10521018
     
    10581024        *ppRenderTarget = NULL;
    10591025    }
    1060     LeaveCriticalSection(&d3d8_cs);
     1026    wined3d_mutex_unlock();
    10611027
    10621028    return hr;
     
    10731039    }
    10741040
    1075     EnterCriticalSection(&d3d8_cs);
     1041    wined3d_mutex_lock();
    10761042    hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
    10771043    if (hr == WINED3D_OK) {
     
    10831049        *ppZStencilSurface = NULL;
    10841050    }
    1085     LeaveCriticalSection(&d3d8_cs);
     1051    wined3d_mutex_unlock();
    10861052
    10871053    return hr;
     
    10931059    TRACE("(%p) Relay\n" , This);
    10941060
    1095     EnterCriticalSection(&d3d8_cs);
     1061    wined3d_mutex_lock();
    10961062    hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
    1097     LeaveCriticalSection(&d3d8_cs);
     1063    wined3d_mutex_unlock();
     1064
    10981065    return hr;
    10991066}
     
    11041071    TRACE("(%p) Relay\n" , This);
    11051072
    1106     EnterCriticalSection(&d3d8_cs);
     1073    wined3d_mutex_lock();
    11071074    hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
    1108     LeaveCriticalSection(&d3d8_cs);
     1075    wined3d_mutex_unlock();
     1076
    11091077    return hr;
    11101078}
     
    11161084
    11171085    /* Note: D3DRECT is compatible with WINED3DRECT */
    1118     EnterCriticalSection(&d3d8_cs);
     1086    wined3d_mutex_lock();
    11191087    hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
    1120     LeaveCriticalSection(&d3d8_cs);
     1088    wined3d_mutex_unlock();
     1089
    11211090    return hr;
    11221091}
     
    11281097
    11291098    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
    1130     EnterCriticalSection(&d3d8_cs);
     1099    wined3d_mutex_lock();
    11311100    hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
    1132     LeaveCriticalSection(&d3d8_cs);
     1101    wined3d_mutex_unlock();
     1102
    11331103    return hr;
    11341104}
     
    11401110
    11411111    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
    1142     EnterCriticalSection(&d3d8_cs);
     1112    wined3d_mutex_lock();
    11431113    hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
    1144     LeaveCriticalSection(&d3d8_cs);
     1114    wined3d_mutex_unlock();
     1115
    11451116    return hr;
    11461117}
     
    11521123
    11531124    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
    1154     EnterCriticalSection(&d3d8_cs);
     1125    wined3d_mutex_lock();
    11551126    hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
    1156     LeaveCriticalSection(&d3d8_cs);
     1127    wined3d_mutex_unlock();
     1128
    11571129    return hr;
    11581130}
     
    11641136
    11651137    /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
    1166     EnterCriticalSection(&d3d8_cs);
     1138    wined3d_mutex_lock();
    11671139    hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
    1168     LeaveCriticalSection(&d3d8_cs);
     1140    wined3d_mutex_unlock();
     1141
    11691142    return hr;
    11701143}
     
    11761149
    11771150    /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
    1178     EnterCriticalSection(&d3d8_cs);
     1151    wined3d_mutex_lock();
    11791152    hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
    1180     LeaveCriticalSection(&d3d8_cs);
     1153    wined3d_mutex_unlock();
     1154
    11811155    return hr;
    11821156}
     
    11881162
    11891163    /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
    1190     EnterCriticalSection(&d3d8_cs);
     1164    wined3d_mutex_lock();
    11911165    hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
    1192     LeaveCriticalSection(&d3d8_cs);
     1166    wined3d_mutex_unlock();
     1167
    11931168    return hr;
    11941169}
     
    12001175
    12011176    /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
    1202     EnterCriticalSection(&d3d8_cs);
     1177    wined3d_mutex_lock();
    12031178    hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
    1204     LeaveCriticalSection(&d3d8_cs);
     1179    wined3d_mutex_unlock();
     1180
    12051181    return hr;
    12061182}
     
    12101186    HRESULT hr;
    12111187    TRACE("(%p) Relay\n" , This);
    1212  
     1188
    12131189    /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
    1214     EnterCriticalSection(&d3d8_cs);
     1190    wined3d_mutex_lock();
    12151191    hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
    1216     LeaveCriticalSection(&d3d8_cs);
     1192    wined3d_mutex_unlock();
     1193
    12171194    return hr;
    12181195}
     
    12241201
    12251202    /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
    1226     EnterCriticalSection(&d3d8_cs);
     1203    wined3d_mutex_lock();
    12271204    hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
    1228     LeaveCriticalSection(&d3d8_cs);
     1205    wined3d_mutex_unlock();
     1206
    12291207    return hr;
    12301208}
     
    12351213    TRACE("(%p) Relay\n" , This);
    12361214
    1237     EnterCriticalSection(&d3d8_cs);
     1215    wined3d_mutex_lock();
    12381216    hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
    1239     LeaveCriticalSection(&d3d8_cs);
     1217    wined3d_mutex_unlock();
     1218
    12401219    return hr;
    12411220}
     
    12461225    TRACE("(%p) Relay\n" , This);
    12471226
    1248     EnterCriticalSection(&d3d8_cs);
     1227    wined3d_mutex_lock();
    12491228    hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
    1250     LeaveCriticalSection(&d3d8_cs);
     1229    wined3d_mutex_unlock();
     1230
    12511231    return hr;
    12521232}
     
    12571237    TRACE("(%p) Relay\n" , This);
    12581238
    1259     EnterCriticalSection(&d3d8_cs);
     1239    wined3d_mutex_lock();
    12601240    hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
    1261     LeaveCriticalSection(&d3d8_cs);
     1241    wined3d_mutex_unlock();
     1242
    12621243    return hr;
    12631244}
     
    12681249    TRACE("(%p) Relay\n" , This);
    12691250
    1270     EnterCriticalSection(&d3d8_cs);
     1251    wined3d_mutex_lock();
    12711252    hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
    1272     LeaveCriticalSection(&d3d8_cs);
     1253    wined3d_mutex_unlock();
     1254
    12731255    return hr;
    12741256}
     
    12791261    TRACE("(%p) Relay\n" , This);
    12801262
    1281     EnterCriticalSection(&d3d8_cs);
     1263    wined3d_mutex_lock();
    12821264    hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
    1283     LeaveCriticalSection(&d3d8_cs);
     1265    wined3d_mutex_unlock();
     1266
    12841267    return hr;
    12851268}
     
    12901273    TRACE("(%p) Relay\n" , This);
    12911274
    1292     EnterCriticalSection(&d3d8_cs);
     1275    wined3d_mutex_lock();
    12931276    hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
    1294     LeaveCriticalSection(&d3d8_cs);
     1277    wined3d_mutex_unlock();
     1278
    12951279    return hr;
    12961280}
     
    13011285    TRACE("(%p)\n", This);
    13021286
    1303     EnterCriticalSection(&d3d8_cs);
     1287    wined3d_mutex_lock();
    13041288    hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
    1305     LeaveCriticalSection(&d3d8_cs);
     1289    wined3d_mutex_unlock();
     1290
    13061291    return hr;
    13071292}
     
    13181303     * of memory later and cause locking problems)
    13191304     */
    1320     EnterCriticalSection(&d3d8_cs);
     1305    wined3d_mutex_lock();
    13211306    hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
    13221307    if (hr != D3D_OK) {
    13231308        WARN("IWineD3DDevice_EndStateBlock returned an error\n");
    1324         LeaveCriticalSection(&d3d8_cs);
     1309        wined3d_mutex_unlock();
    13251310        return hr;
    13261311    }
     
    13341319
    13351320    *pToken = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
    1336     LeaveCriticalSection(&d3d8_cs);
     1321    wined3d_mutex_unlock();
    13371322
    13381323    if (*pToken == D3D8_INVALID_HANDLE)
     
    13561341    TRACE("(%p) %#x Relay\n", This, Token);
    13571342
    1358     EnterCriticalSection(&d3d8_cs);
     1343    wined3d_mutex_lock();
    13591344    pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
    13601345    if (!pSB)
    13611346    {
    13621347        WARN("Invalid handle (%#x) passed.\n", Token);
    1363         LeaveCriticalSection(&d3d8_cs);
     1348        wined3d_mutex_unlock();
    13641349        return D3DERR_INVALIDCALL;
    13651350    }
    13661351    hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
    1367     LeaveCriticalSection(&d3d8_cs);
     1352    wined3d_mutex_unlock();
     1353
    13681354    return hr;
    13691355}
     
    13761362    TRACE("(%p) %#x Relay\n", This, Token);
    13771363
    1378     EnterCriticalSection(&d3d8_cs);
     1364    wined3d_mutex_lock();
    13791365    pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
    13801366    if (!pSB)
    13811367    {
    13821368        WARN("Invalid handle (%#x) passed.\n", Token);
    1383         LeaveCriticalSection(&d3d8_cs);
     1369        wined3d_mutex_unlock();
    13841370        return D3DERR_INVALIDCALL;
    13851371    }
    13861372    hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
    1387     LeaveCriticalSection(&d3d8_cs);
     1373    wined3d_mutex_unlock();
     1374
    13881375    return hr;
    13891376}
     
    13951382    TRACE("(%p) Relay\n", This);
    13961383
    1397     EnterCriticalSection(&d3d8_cs);
     1384    wined3d_mutex_lock();
    13981385    pSB = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
    1399     LeaveCriticalSection(&d3d8_cs);
     1386    wined3d_mutex_unlock();
    14001387
    14011388    if (!pSB)
     
    14401427    object->ref = 1;
    14411428
    1442     EnterCriticalSection(&d3d8_cs);
     1429    wined3d_mutex_lock();
    14431430    hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
    14441431            &object->wineD3DStateBlock, (IUnknown *)object);
    14451432    if (FAILED(hr))
    14461433    {
    1447         LeaveCriticalSection(&d3d8_cs);
     1434        wined3d_mutex_unlock();
    14481435        ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
    14491436        HeapFree(GetProcessHeap(), 0, object);
     
    14521439
    14531440    *handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
    1454     LeaveCriticalSection(&d3d8_cs);
     1441    wined3d_mutex_unlock();
    14551442
    14561443    if (*handle == D3D8_INVALID_HANDLE)
     
    14721459    TRACE("(%p) Relay\n" , This);
    14731460/* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
    1474     EnterCriticalSection(&d3d8_cs);
     1461
     1462    wined3d_mutex_lock();
    14751463    hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
    1476     LeaveCriticalSection(&d3d8_cs);
     1464    wined3d_mutex_unlock();
     1465
    14771466    return hr;
    14781467}
     
    14831472    TRACE("(%p) Relay\n" , This);
    14841473
    1485     EnterCriticalSection(&d3d8_cs);
     1474    wined3d_mutex_lock();
    14861475    hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
    1487     LeaveCriticalSection(&d3d8_cs);
     1476    wined3d_mutex_unlock();
     1477
    14881478    return hr;
    14891479}
     
    14911481static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
    14921482    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    1493     IWineD3DBaseTexture *retTexture = NULL;
    1494     HRESULT rc = D3D_OK;
     1483    IWineD3DBaseTexture *retTexture;
     1484    HRESULT hr;
    14951485
    14961486    TRACE("(%p) Relay\n" , This);
     
    15001490    }
    15011491
    1502     EnterCriticalSection(&d3d8_cs);
    1503     rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
    1504     if (rc == D3D_OK && NULL != retTexture) {
     1492    wined3d_mutex_lock();
     1493    hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
     1494    if (FAILED(hr))
     1495    {
     1496        WARN("Failed to get texture for stage %u, hr %#x.\n", Stage, hr);
     1497        wined3d_mutex_unlock();
     1498        *ppTexture = NULL;
     1499        return hr;
     1500    }
     1501
     1502    if (retTexture)
     1503    {
    15051504        IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
    15061505        IWineD3DBaseTexture_Release(retTexture);
    1507     } else {
    1508         FIXME("Call to get texture  (%d) failed (%p)\n", Stage, retTexture);
     1506    }
     1507    else
     1508    {
    15091509        *ppTexture = NULL;
    15101510    }
    1511     LeaveCriticalSection(&d3d8_cs);
    1512 
    1513     return rc;
     1511    wined3d_mutex_unlock();
     1512
     1513    return D3D_OK;
    15141514}
    15151515
     
    15191519    TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
    15201520
    1521     EnterCriticalSection(&d3d8_cs);
     1521    wined3d_mutex_lock();
    15221522    hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
    15231523                                   pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
    1524     LeaveCriticalSection(&d3d8_cs);
     1524    wined3d_mutex_unlock();
     1525
    15251526    return hr;
    15261527}
     
    15701571    TRACE("(%p) Relay\n" , This);
    15711572
    1572     EnterCriticalSection(&d3d8_cs);
    1573 
     1573    wined3d_mutex_lock();
    15741574    if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
    15751575    else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
    1576 
    1577     LeaveCriticalSection(&d3d8_cs);
     1576    wined3d_mutex_unlock();
     1577
    15781578    return hr;
    15791579}
     
    15851585    TRACE("(%p) Relay\n" , This);
    15861586
    1587     EnterCriticalSection(&d3d8_cs);
    1588 
     1587    wined3d_mutex_lock();
    15891588    if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
    15901589    else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
    1591 
    1592     LeaveCriticalSection(&d3d8_cs);
     1590    wined3d_mutex_unlock();
     1591
    15931592    return hr;
    15941593}
     
    15991598    TRACE("(%p) Relay\n" , This);
    16001599
    1601     EnterCriticalSection(&d3d8_cs);
     1600    wined3d_mutex_lock();
    16021601    hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
    1603     LeaveCriticalSection(&d3d8_cs);
     1602    wined3d_mutex_unlock();
     1603
    16041604    return hr;
    16051605}
     
    16161616    TRACE("(%p) Relay\n" , This);
    16171617
    1618     EnterCriticalSection(&d3d8_cs);
     1618    wined3d_mutex_lock();
    16191619    hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
    1620     LeaveCriticalSection(&d3d8_cs);
     1620    wined3d_mutex_unlock();
     1621
    16211622    return hr;
    16221623}
     
    16271628    TRACE("(%p) Relay\n" , This);
    16281629
    1629     EnterCriticalSection(&d3d8_cs);
     1630    wined3d_mutex_lock();
    16301631    hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
    1631     LeaveCriticalSection(&d3d8_cs);
     1632    wined3d_mutex_unlock();
     1633
    16321634    return hr;
    16331635}
     
    16381640    TRACE("(%p) Relay\n" , This);
    16391641
    1640     EnterCriticalSection(&d3d8_cs);
     1642    wined3d_mutex_lock();
    16411643    hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
    1642     LeaveCriticalSection(&d3d8_cs);
     1644    wined3d_mutex_unlock();
     1645
    16431646    return hr;
    16441647}
     
    16491652    TRACE("(%p) Relay\n" , This);
    16501653
    1651     EnterCriticalSection(&d3d8_cs);
     1654    wined3d_mutex_lock();
    16521655    hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
    1653     LeaveCriticalSection(&d3d8_cs);
    1654     return hr;
    1655 }
    1656 
    1657 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
    1658     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    1659     HRESULT hr;
    1660     TRACE("(%p) Relay\n" , This);
    1661 
    1662     EnterCriticalSection(&d3d8_cs);
     1656    wined3d_mutex_unlock();
     1657
     1658    return hr;
     1659}
     1660
     1661static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface, D3DPRIMITIVETYPE PrimitiveType,
     1662        UINT StartVertex, UINT PrimitiveCount)
     1663{
     1664    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     1665    HRESULT hr;
     1666    TRACE("(%p) Relay\n" , This);
     1667
     1668    wined3d_mutex_lock();
    16631669    IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
    16641670    hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
    16651671            vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
    1666     LeaveCriticalSection(&d3d8_cs);
     1672    wined3d_mutex_unlock();
     1673
    16671674    return hr;
    16681675}
     
    16741681    TRACE("(%p) Relay\n" , This);
    16751682
    1676     EnterCriticalSection(&d3d8_cs);
     1683    wined3d_mutex_lock();
    16771684    IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
    1678     hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, MinVertexIndex, NumVertices,
    1679             startIndex, vertex_count_from_primitive_count(PrimitiveType, primCount));
    1680     LeaveCriticalSection(&d3d8_cs);
     1685    hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
     1686            vertex_count_from_primitive_count(PrimitiveType, primCount));
     1687    wined3d_mutex_unlock();
     1688
    16811689    return hr;
    16821690}
     
    16871695    TRACE("(%p) Relay\n" , This);
    16881696
    1689     EnterCriticalSection(&d3d8_cs);
     1697    wined3d_mutex_lock();
    16901698    IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
    16911699    hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
    16921700            vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
    16931701            pVertexStreamZeroData, VertexStreamZeroStride);
    1694     LeaveCriticalSection(&d3d8_cs);
     1702    wined3d_mutex_unlock();
     1703
    16951704    return hr;
    16961705}
     
    17041713    TRACE("(%p) Relay\n" , This);
    17051714
    1706     EnterCriticalSection(&d3d8_cs);
     1715    wined3d_mutex_lock();
    17071716    IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
    1708     hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, MinVertexIndex, NumVertexIndices,
     1717    hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
    17091718            vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
    17101719            wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
    1711     LeaveCriticalSection(&d3d8_cs);
     1720    wined3d_mutex_unlock();
     1721
    17121722    return hr;
    17131723}
     
    17191729    TRACE("(%p) Relay\n" , This);
    17201730
    1721     EnterCriticalSection(&d3d8_cs);
     1731    wined3d_mutex_lock();
    17221732    hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
    1723     LeaveCriticalSection(&d3d8_cs);
    1724     return hr;
    1725 }
    1726 
    1727 static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
    1728     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    1729     IDirect3DVertexDeclaration8Impl *object;
    1730     WINED3DVERTEXELEMENT *wined3d_elements;
    1731     UINT wined3d_element_count;
    1732     HRESULT hr = D3D_OK;
    1733 
    1734     TRACE("(%p) : declaration %p\n", This, declaration);
     1733    wined3d_mutex_unlock();
     1734
     1735    return hr;
     1736}
     1737
     1738static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *iface,
     1739        const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
     1740{
     1741    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     1742    IDirect3DVertexShader8Impl *object;
     1743    DWORD shader_handle;
     1744    DWORD handle;
     1745    HRESULT hr;
     1746
     1747    TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
     1748            iface, declaration, byte_code, shader, usage);
    17351749
    17361750    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
    1737     if (!object) {
    1738         ERR("Memory allocation failed\n");
    1739         *decl_ptr = NULL;
    1740         return D3DERR_OUTOFVIDEOMEMORY;
    1741     }
    1742 
    1743     object->ref_count = 1;
    1744     object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
    1745 
    1746     wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
    1747     object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
    1748     if (!object->elements) {
    1749         ERR("Memory allocation failed\n");
    1750         HeapFree(GetProcessHeap(), 0, wined3d_elements);
     1751    if (!object)
     1752    {
     1753        ERR("Failed to allocate vertex shader memory.\n");
     1754        *shader = 0;
     1755        return E_OUTOFMEMORY;
     1756    }
     1757
     1758    wined3d_mutex_lock();
     1759    handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
     1760    wined3d_mutex_unlock();
     1761    if (handle == D3D8_INVALID_HANDLE)
     1762    {
     1763        ERR("Failed to allocate vertex shader handle.\n");
    17511764        HeapFree(GetProcessHeap(), 0, object);
    1752         *decl_ptr = NULL;
    1753         return D3DERR_OUTOFVIDEOMEMORY;
    1754     }
    1755 
    1756     CopyMemory(object->elements, declaration, object->elements_size);
    1757 
    1758     EnterCriticalSection(&d3d8_cs);
    1759     hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
    1760             (IUnknown *)object, wined3d_elements, wined3d_element_count);
    1761     LeaveCriticalSection(&d3d8_cs);
    1762     HeapFree(GetProcessHeap(), 0, wined3d_elements);
    1763 
    1764     if (FAILED(hr)) {
    1765         ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
    1766         HeapFree(GetProcessHeap(), 0, object->elements);
     1765        *shader = 0;
     1766        return E_OUTOFMEMORY;
     1767    }
     1768
     1769    shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
     1770
     1771    hr = vertexshader_init(object, This, declaration, byte_code, shader_handle, usage);
     1772    if (FAILED(hr))
     1773    {
     1774        WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
     1775        wined3d_mutex_lock();
     1776        d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
     1777        wined3d_mutex_unlock();
    17671778        HeapFree(GetProcessHeap(), 0, object);
    1768     } else {
    1769         *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
    1770         TRACE("(%p) : Created vertex declaration %p\n", This, object);
    1771     }
    1772 
    1773     return hr;
    1774 }
    1775 
    1776 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
    1777     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    1778     HRESULT hrc = D3D_OK;
    1779     IDirect3DVertexShader8Impl *object;
    1780     const DWORD *token = pDeclaration;
    1781     DWORD handle;
    1782 
    1783     /* Test if the vertex declaration is valid */
    1784     while (D3DVSD_END() != *token) {
    1785         D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
    1786 
    1787         if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
    1788             DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
    1789             DWORD reg  = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
    1790 
    1791             if(reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !pFunction) {
    1792                 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
    1793                 return D3DERR_INVALIDCALL;
    1794             }
    1795         }
    1796         token += parse_token(token);
    1797     }
    1798 
    1799     /* Setup a stub object for now */
    1800     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
    1801     TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
    1802     if (NULL == object) {
    1803         FIXME("Allocation of memory failed\n");
    1804         *ppShader = 0;
    1805         return D3DERR_OUTOFVIDEOMEMORY;
    1806     }
    1807 
    1808     object->ref = 1;
    1809     object->lpVtbl = &Direct3DVertexShader8_Vtbl;
    1810 
    1811     hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
    1812     if (FAILED(hrc)) {
    1813         ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
    1814         HeapFree(GetProcessHeap(), 0, object);
    1815         *ppShader = 0;
    1816         return D3DERR_INVALIDCALL;
    1817     }
    1818 
    1819     EnterCriticalSection(&d3d8_cs);
    1820     handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
    1821     if (handle == D3D8_INVALID_HANDLE)
    1822     {
    1823         ERR("Failed to allocate shader handle\n");
    1824         LeaveCriticalSection(&d3d8_cs);
    1825         IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
    1826         HeapFree(GetProcessHeap(), 0, object);
    1827         *ppShader = 0;
    1828         return E_OUTOFMEMORY;
    1829     }
    1830     else
    1831     {
    1832         DWORD shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
    1833         *ppShader = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->shader_handle = shader_handle;
    1834     }
    1835 
    1836     if (pFunction)
    1837     {
    1838         /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
    1839         hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pFunction,
    1840                 NULL /* output signature */, &object->wineD3DVertexShader, (IUnknown *)object);
    1841 
    1842         if (FAILED(hrc))
    1843         {
    1844             /* free up object */
    1845             FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
    1846             d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
    1847             IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
    1848             HeapFree(GetProcessHeap(), 0, object);
    1849             *ppShader = 0;
    1850         }
    1851         else
    1852         {
    1853             load_local_constants(pDeclaration, object->wineD3DVertexShader);
    1854             TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
    1855         }
    1856     }
    1857 
    1858     LeaveCriticalSection(&d3d8_cs);
    1859 
    1860     return hrc;
     1779        *shader = 0;
     1780        return hr;
     1781    }
     1782
     1783    TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
     1784    *shader = shader_handle;
     1785
     1786    return D3D_OK;
    18611787}
    18621788
     
    18931819    }
    18941820
    1895     d3d8_declaration->ref_count = 1;
    1896     d3d8_declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
    1897     d3d8_declaration->elements = NULL;
    1898     d3d8_declaration->elements_size = 0;
    1899     d3d8_declaration->shader_handle = fvf;
    1900 
    1901     hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice,
    1902             &d3d8_declaration->wined3d_vertex_declaration, (IUnknown *)d3d8_declaration, fvf);
     1821    hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
    19031822    if (FAILED(hr))
    19041823    {
    1905         ERR("Failed to create wined3d vertex declaration.\n");
     1824        WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
    19061825        HeapFree(GetProcessHeap(), 0, d3d8_declaration);
    19071826        return NULL;
     
    19401859        TRACE("Setting FVF, %#x\n", pShader);
    19411860
    1942         EnterCriticalSection(&d3d8_cs);
     1861        wined3d_mutex_lock();
    19431862        IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
    19441863                IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
    19451864        IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
    1946         LeaveCriticalSection(&d3d8_cs);
     1865        wined3d_mutex_unlock();
     1866
    19471867        return D3D_OK;
    19481868    }
     
    19501870    TRACE("Setting shader\n");
    19511871
    1952     EnterCriticalSection(&d3d8_cs);
     1872    wined3d_mutex_lock();
    19531873    shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
    19541874    if (!shader)
    19551875    {
    19561876        WARN("Invalid handle (%#x) passed.\n", pShader);
    1957         LeaveCriticalSection(&d3d8_cs);
     1877        wined3d_mutex_unlock();
     1878
    19581879        return D3DERR_INVALIDCALL;
    19591880    }
     
    19621883            ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
    19631884    if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
    1964     LeaveCriticalSection(&d3d8_cs);
     1885    wined3d_mutex_unlock();
    19651886
    19661887    TRACE("Returning hr %#x\n", hr);
     
    19761897
    19771898    TRACE("(%p) : Relay  device@%p\n", This, This->WineD3DDevice);
    1978     EnterCriticalSection(&d3d8_cs);
    1979 
     1899
     1900    wined3d_mutex_lock();
    19801901    hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
    19811902    if (FAILED(hrc))
    19821903    {
    1983         LeaveCriticalSection(&d3d8_cs);
     1904        wined3d_mutex_unlock();
    19841905        WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
    19851906                This, hrc, This->WineD3DDevice);
     
    19891910    if (!wined3d_declaration)
    19901911    {
    1991         LeaveCriticalSection(&d3d8_cs);
     1912        wined3d_mutex_unlock();
    19921913        *ppShader = 0;
    19931914        return D3D_OK;
     
    19961917    hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
    19971918    IWineD3DVertexDeclaration_Release(wined3d_declaration);
    1998     LeaveCriticalSection(&d3d8_cs);
     1919    wined3d_mutex_unlock();
    19991920    if (SUCCEEDED(hrc))
    20001921    {
     
    20151936    TRACE("(%p) : pShader %#x\n", This, pShader);
    20161937
    2017     EnterCriticalSection(&d3d8_cs);
    2018 
     1938    wined3d_mutex_lock();
    20191939    shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
    20201940    if (!shader)
    20211941    {
    20221942        WARN("Invalid handle (%#x) passed.\n", pShader);
    2023         LeaveCriticalSection(&d3d8_cs);
     1943        wined3d_mutex_unlock();
     1944
    20241945        return D3DERR_INVALIDCALL;
    20251946    }
     
    20331954    }
    20341955
    2035     LeaveCriticalSection(&d3d8_cs);
     1956    wined3d_mutex_unlock();
    20361957
    20371958    if (IUnknown_Release((IUnknown *)shader))
     
    20541975    }
    20551976
    2056     EnterCriticalSection(&d3d8_cs);
     1977    wined3d_mutex_lock();
    20571978    hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
    2058     LeaveCriticalSection(&d3d8_cs);
     1979    wined3d_mutex_unlock();
     1980
    20591981    return hr;
    20601982}
     
    20711993    }
    20721994
    2073     EnterCriticalSection(&d3d8_cs);
     1995    wined3d_mutex_lock();
    20741996    hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
    2075     LeaveCriticalSection(&d3d8_cs);
     1997    wined3d_mutex_unlock();
     1998
    20761999    return hr;
    20772000}
     
    20842007    TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
    20852008
    2086     EnterCriticalSection(&d3d8_cs);
    2087 
     2009    wined3d_mutex_lock();
    20882010    shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
    2089     LeaveCriticalSection(&d3d8_cs);
     2011    wined3d_mutex_unlock();
     2012
    20902013    if (!shader)
    20912014    {
     
    21202043    TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
    21212044
    2122     EnterCriticalSection(&d3d8_cs);
    2123 
     2045    wined3d_mutex_lock();
    21242046    shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
    21252047    if (!shader)
    21262048    {
    21272049        WARN("Invalid handle (%#x) passed.\n", pVertexShader);
    2128         LeaveCriticalSection(&d3d8_cs);
     2050        wined3d_mutex_unlock();
     2051
    21292052        return D3DERR_INVALIDCALL;
    21302053    }
     
    21322055    if (!shader->wineD3DVertexShader)
    21332056    {
    2134         LeaveCriticalSection(&d3d8_cs);
     2057        wined3d_mutex_unlock();
    21352058        *pSizeOfData = 0;
    21362059        return D3D_OK;
     
    21382061
    21392062    hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
    2140 
    2141     LeaveCriticalSection(&d3d8_cs);
     2063    wined3d_mutex_unlock();
     2064
    21422065    return hr;
    21432066}
     
    21492072    TRACE("(%p) Relay\n", This);
    21502073
    2151     EnterCriticalSection(&d3d8_cs);
    21522074    /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
    21532075     * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
     
    21562078     * problem)
    21572079     */
     2080    wined3d_mutex_lock();
    21582081    IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
    2159     hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
     2082    hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
    21602083            ib ? ib->wineD3DIndexBuffer : NULL,
    21612084            ib ? ib->format : WINED3DFMT_UNKNOWN);
    2162     LeaveCriticalSection(&d3d8_cs);
     2085    wined3d_mutex_unlock();
     2086
    21632087    return hr;
    21642088}
     
    21752099    }
    21762100
    2177     EnterCriticalSection(&d3d8_cs);
    21782101    /* The case from UINT to INT is safe because d3d8 will never set negative values */
     2102    wined3d_mutex_lock();
    21792103    IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
    2180     rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
     2104    rc = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
    21812105    if (SUCCEEDED(rc) && retIndexData) {
    21822106        IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
     
    21862110        *ppIndexData = NULL;
    21872111    }
    2188     LeaveCriticalSection(&d3d8_cs);
     2112    wined3d_mutex_unlock();
    21892113
    21902114    return rc;
    21912115}
    2192 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
     2116
     2117static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
     2118        const DWORD *byte_code, DWORD *shader)
     2119{
    21932120    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
    21942121    IDirect3DPixelShader8Impl *object;
     2122    DWORD shader_handle;
    21952123    DWORD handle;
    21962124    HRESULT hr;
    21972125
    2198     TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
    2199 
    2200     if (NULL == ppShader) {
     2126    TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
     2127
     2128    if (!shader)
     2129    {
    22012130        TRACE("(%p) Invalid call\n", This);
    22022131        return D3DERR_INVALIDCALL;
     
    22062135    if (!object)
    22072136    {
    2208         ERR("Failed to allocate memmory.\n");
     2137        ERR("Failed to allocate pixel shader memmory.\n");
    22092138        return E_OUTOFMEMORY;
    22102139    }
    22112140
    2212     object->ref    = 1;
    2213     object->lpVtbl = &Direct3DPixelShader8_Vtbl;
    2214 
    2215     EnterCriticalSection(&d3d8_cs);
    2216     hr = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction,
    2217             NULL, &object->wineD3DPixelShader, (IUnknown *)object);
     2141    wined3d_mutex_lock();
     2142    handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
     2143    wined3d_mutex_unlock();
     2144    if (handle == D3D8_INVALID_HANDLE)
     2145    {
     2146        ERR("Failed to allocate pixel shader handle.\n");
     2147        HeapFree(GetProcessHeap(), 0, object);
     2148        return E_OUTOFMEMORY;
     2149    }
     2150
     2151    shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
     2152
     2153    hr = pixelshader_init(object, This, byte_code, shader_handle);
    22182154    if (FAILED(hr))
    22192155    {
    2220         LeaveCriticalSection(&d3d8_cs);
    2221         FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
    2222         HeapFree(GetProcessHeap(), 0 , object);
    2223         *ppShader = 0;
     2156        WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
     2157        wined3d_mutex_lock();
     2158        d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
     2159        wined3d_mutex_unlock();
     2160        HeapFree(GetProcessHeap(), 0, object);
     2161        *shader = 0;
    22242162        return hr;
    22252163    }
    22262164
    2227     handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
    2228     LeaveCriticalSection(&d3d8_cs);
    2229     if (handle == D3D8_INVALID_HANDLE)
    2230     {
    2231         ERR("Failed to allocate shader handle\n");
    2232         IDirect3DVertexShader8_Release((IUnknown *)object);
    2233         return E_OUTOFMEMORY;
    2234     }
    2235 
    2236     *ppShader = object->handle = handle + VS_HIGHESTFIXEDFXF + 1;
    2237     TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
    2238 
    2239     return hr;
     2165    TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
     2166    *shader = shader_handle;
     2167
     2168    return D3D_OK;
    22402169}
    22412170
     
    22472176    TRACE("(%p) : pShader %#x\n", This, pShader);
    22482177
    2249     EnterCriticalSection(&d3d8_cs);
     2178    wined3d_mutex_lock();
    22502179
    22512180    if (!pShader)
    22522181    {
    22532182        hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
    2254         LeaveCriticalSection(&d3d8_cs);
     2183        wined3d_mutex_unlock();
    22552184        return hr;
    22562185    }
     
    22602189    {
    22612190        WARN("Invalid handle (%#x) passed.\n", pShader);
    2262         LeaveCriticalSection(&d3d8_cs);
     2191        wined3d_mutex_unlock();
    22632192        return D3DERR_INVALIDCALL;
    22642193    }
     
    22662195    TRACE("(%p) : Setting shader %p\n", This, shader);
    22672196    hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
    2268     LeaveCriticalSection(&d3d8_cs);
     2197    wined3d_mutex_unlock();
     2198
    22692199    return hr;
    22702200}
     
    22812211    }
    22822212
    2283     EnterCriticalSection(&d3d8_cs);
     2213    wined3d_mutex_lock();
    22842214    hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
    22852215    if (D3D_OK == hrc && NULL != object) {
     
    22922222        *ppShader = 0;
    22932223    }
     2224    wined3d_mutex_unlock();
    22942225
    22952226    TRACE("(%p) : returning %#x\n", This, *ppShader);
    2296     LeaveCriticalSection(&d3d8_cs);
     2227
    22972228    return hrc;
    22982229}
     
    23052236    TRACE("(%p) : pShader %#x\n", This, pShader);
    23062237
    2307     EnterCriticalSection(&d3d8_cs);
     2238    wined3d_mutex_lock();
    23082239
    23092240    shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
     
    23112242    {
    23122243        WARN("Invalid handle (%#x) passed.\n", pShader);
    2313         LeaveCriticalSection(&d3d8_cs);
     2244        wined3d_mutex_unlock();
    23142245        return D3D_OK;
    23152246    }
     
    23232254    }
    23242255
    2325     LeaveCriticalSection(&d3d8_cs);
     2256    wined3d_mutex_unlock();
    23262257
    23272258    if (IUnknown_Release((IUnknown *)shader))
     
    23382269    TRACE("(%p) Relay\n", This);
    23392270
    2340     EnterCriticalSection(&d3d8_cs);
     2271    wined3d_mutex_lock();
    23412272    hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
    2342     LeaveCriticalSection(&d3d8_cs);
     2273    wined3d_mutex_unlock();
     2274
    23432275    return hr;
    23442276}
     
    23492281    TRACE("(%p) Relay\n", This);
    23502282
    2351     EnterCriticalSection(&d3d8_cs);
     2283    wined3d_mutex_lock();
    23522284    hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
    2353     LeaveCriticalSection(&d3d8_cs);
     2285    wined3d_mutex_unlock();
     2286
    23542287    return hr;
    23552288}
     
    23622295    TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
    23632296
    2364     EnterCriticalSection(&d3d8_cs);
     2297    wined3d_mutex_lock();
    23652298    shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
    23662299    if (!shader)
    23672300    {
    23682301        WARN("Invalid handle (%#x) passed.\n", pPixelShader);
    2369         LeaveCriticalSection(&d3d8_cs);
     2302        wined3d_mutex_unlock();
     2303
    23702304        return D3DERR_INVALIDCALL;
    23712305    }
    23722306
    23732307    hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
    2374     LeaveCriticalSection(&d3d8_cs);
     2308    wined3d_mutex_unlock();
     2309
    23752310    return hr;
    23762311}
     
    23812316    TRACE("(%p) Relay\n", This);
    23822317
    2383     EnterCriticalSection(&d3d8_cs);
     2318    wined3d_mutex_lock();
    23842319    hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
    2385     LeaveCriticalSection(&d3d8_cs);
     2320    wined3d_mutex_unlock();
     2321
    23862322    return hr;
    23872323}
     
    23922328    TRACE("(%p) Relay\n", This);
    23932329
    2394     EnterCriticalSection(&d3d8_cs);
     2330    wined3d_mutex_lock();
    23952331    hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
    2396     LeaveCriticalSection(&d3d8_cs);
     2332    wined3d_mutex_unlock();
     2333
    23972334    return hr;
    23982335}
     
    24032340    TRACE("(%p) Relay\n", This);
    24042341
    2405     EnterCriticalSection(&d3d8_cs);
     2342    wined3d_mutex_lock();
    24062343    hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
    2407     LeaveCriticalSection(&d3d8_cs);
     2344    wined3d_mutex_unlock();
     2345
    24082346    return hr;
    24092347}
     
    24142352    TRACE("(%p) Relay\n" , This);
    24152353
    2416     EnterCriticalSection(&d3d8_cs);
     2354    wined3d_mutex_lock();
    24172355    hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
    24182356                                        NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
    24192357                                        0/* Offset in bytes */, Stride);
    2420     LeaveCriticalSection(&d3d8_cs);
     2358    wined3d_mutex_unlock();
     2359
    24212360    return hr;
    24222361}
     
    24332372    }
    24342373
    2435     EnterCriticalSection(&d3d8_cs);
     2374    wined3d_mutex_lock();
    24362375    rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
    24372376    if (rc == D3D_OK  && NULL != retStream) {
     
    24442383        *pStream = NULL;
    24452384    }
    2446     LeaveCriticalSection(&d3d8_cs);
     2385    wined3d_mutex_unlock();
    24472386
    24482387    return rc;
     
    25512490};
    25522491
    2553 ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface) {
    2554     IDirect3DSurface8Impl* surfaceParent;
    2555     TRACE("(%p) call back\n", pSurface);
    2556 
    2557     IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
    2558     /* GetParent's AddRef was forwarded to an object in destruction.
    2559      * Releasing it here again would cause an endless recursion. */
    2560     surfaceParent->forwardReference = NULL;
    2561     return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);
    2562 }
    2563 
    25642492/* IWineD3DDeviceParent IUnknown methods */
    25652493
     
    26212549
    26222550    *surface = d3d_surface->wineD3DSurface;
     2551    IWineD3DSurface_AddRef(*surface);
     2552
    26232553    d3d_surface->container = superior;
    26242554    IUnknown_Release(d3d_surface->parentDevice);
    26252555    d3d_surface->parentDevice = NULL;
     2556
     2557    IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
    26262558    d3d_surface->forwardReference = superior;
    26272559
     
    26502582
    26512583    *surface = d3d_surface->wineD3DSurface;
     2584    IWineD3DSurface_AddRef(*surface);
     2585
    26522586    d3d_surface->container = (IUnknown *)This;
    2653     d3d_surface->isImplicit = TRUE;
    26542587    /* Implicit surfaces are created with an refcount of 0 */
    26552588    IUnknown_Release((IUnknown *)d3d_surface);
     
    26792612
    26802613    *surface = d3d_surface->wineD3DSurface;
     2614    IWineD3DSurface_AddRef(*surface);
     2615
    26812616    d3d_surface->container = (IUnknown *)This;
    2682     d3d_surface->isImplicit = TRUE;
    26832617    /* Implicit surfaces are created with an refcount of 0 */
    26842618    IUnknown_Release((IUnknown *)d3d_surface);
     
    27072641    }
    27082642
    2709     object->lpVtbl = &Direct3DVolume8_Vtbl;
    2710     object->ref = 1;
    2711     hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage,
    2712             format, pool, &object->wineD3DVolume, (IUnknown *)object);
     2643    hr = volume_init(object, This, width, height, depth, usage, format, pool);
    27132644    if (FAILED(hr))
    27142645    {
    2715         ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr);
     2646        WARN("Failed to initialize volume, hr %#x.\n", hr);
    27162647        HeapFree(GetProcessHeap(), 0, object);
    2717         *volume = NULL;
    27182648        return hr;
    27192649    }
    27202650
    27212651    *volume = object->wineD3DVolume;
     2652    IWineD3DVolume_AddRef(*volume);
     2653    IDirect3DVolume8_Release((IDirect3DVolume8 *)object);
     2654
    27222655    object->container = superior;
    27232656    object->forwardReference = superior;
    27242657
    2725     TRACE("(%p) Created volume %p\n", iface, *volume);
     2658    TRACE("(%p) Created volume %p\n", iface, object);
    27262659
    27272660    return hr;
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c

    r22496 r23571  
    8181    if (ref == 0) {
    8282        TRACE("Releasing wined3d %p\n", This->WineD3D);
    83         EnterCriticalSection(&d3d8_cs);
     83
     84        wined3d_mutex_lock();
    8485        IWineD3D_Release(This->WineD3D);
    85         LeaveCriticalSection(&d3d8_cs);
     86        wined3d_mutex_unlock();
     87
    8688        HeapFree(GetProcessHeap(), 0, This);
    8789    }
     
    9698    TRACE("(%p)->(%p)\n", This, pInitializeFunction);
    9799
    98     EnterCriticalSection(&d3d8_cs);
     100    wined3d_mutex_lock();
    99101    hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
    100     LeaveCriticalSection(&d3d8_cs);
     102    wined3d_mutex_unlock();
     103
    101104    return hr;
    102105}
     
    107110    TRACE("(%p)\n", This);
    108111
    109     EnterCriticalSection(&d3d8_cs);
     112    wined3d_mutex_lock();
    110113    hr = IWineD3D_GetAdapterCount(This->WineD3D);
    111     LeaveCriticalSection(&d3d8_cs);
     114    wined3d_mutex_unlock();
     115
    112116    return hr;
    113117}
     
    129133    adapter_id.device_name_size = 0; /* d3d9 only */
    130134
    131     EnterCriticalSection(&d3d8_cs);
     135    wined3d_mutex_lock();
    132136    hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
    133     LeaveCriticalSection(&d3d8_cs);
     137    wined3d_mutex_unlock();
    134138
    135139    pIdentifier->DriverVersion = adapter_id.driver_version;
     
    149153    TRACE("(%p)->(%d)\n", This, Adapter);
    150154
    151     EnterCriticalSection(&d3d8_cs);
     155    wined3d_mutex_lock();
    152156    hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, 0 /* format */);
    153     LeaveCriticalSection(&d3d8_cs);
     157    wined3d_mutex_unlock();
     158
    154159    return hr;
    155160}
     
    160165    TRACE("(%p)->(%d, %d, %p)\n", This, Adapter, Mode, pMode);
    161166
    162     EnterCriticalSection(&d3d8_cs);
     167    wined3d_mutex_lock();
    163168    hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN, Mode, (WINED3DDISPLAYMODE *) pMode);
    164     LeaveCriticalSection(&d3d8_cs);
     169    wined3d_mutex_unlock();
    165170
    166171    if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
     
    174179    TRACE("(%p)->(%d,%p)\n", This, Adapter, pMode);
    175180
    176     EnterCriticalSection(&d3d8_cs);
     181    wined3d_mutex_lock();
    177182    hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
    178     LeaveCriticalSection(&d3d8_cs);
     183    wined3d_mutex_unlock();
    179184
    180185    if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
     
    190195    TRACE("(%p)->(%d, %d, %d, %d, %s)\n", This, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed ? "true" : "false");
    191196
    192     EnterCriticalSection(&d3d8_cs);
     197    wined3d_mutex_lock();
    193198    hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
    194199            wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
    195     LeaveCriticalSection(&d3d8_cs);
     200    wined3d_mutex_unlock();
     201
    196202    return hr;
    197203}
     
    224230    }
    225231
    226     EnterCriticalSection(&d3d8_cs);
     232    wined3d_mutex_lock();
    227233    hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
    228234            Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
    229     LeaveCriticalSection(&d3d8_cs);
    230     return hr;
    231 }
    232 
    233 static HRESULT  WINAPI  IDirect3D8Impl_CheckDeviceMultiSampleType(LPDIRECT3D8 iface,
    234                                                            UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
    235                                                            BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType) {
     235    wined3d_mutex_unlock();
     236
     237    return hr;
     238}
     239
     240static HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType(IDirect3D8 *iface, UINT Adapter,
     241        D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType)
     242{
    236243    IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
    237244    HRESULT hr;
    238245    TRACE("(%p)-<(%d, %d, %d, %s, %d)\n", This, Adapter, DeviceType, SurfaceFormat, Windowed ? "true" : "false", MultiSampleType);
    239246
    240     EnterCriticalSection(&d3d8_cs);
     247    wined3d_mutex_lock();
    241248    hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType,
    242249            wined3dformat_from_d3dformat(SurfaceFormat), Windowed, (WINED3DMULTISAMPLE_TYPE) MultiSampleType, NULL);
    243     LeaveCriticalSection(&d3d8_cs);
    244     return hr;
    245 }
    246 
    247 static HRESULT  WINAPI  IDirect3D8Impl_CheckDepthStencilMatch(LPDIRECT3D8 iface,
    248                                                        UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
    249                                                        D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
     250    wined3d_mutex_unlock();
     251
     252    return hr;
     253}
     254
     255static HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch(IDirect3D8 *iface, UINT Adapter, D3DDEVTYPE DeviceType,
     256        D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat)
     257{
    250258    IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
    251259    HRESULT hr;
    252260    TRACE("(%p)-<(%d, %d, %d, %d, %d)\n", This, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
    253261
    254     EnterCriticalSection(&d3d8_cs);
     262    wined3d_mutex_lock();
    255263    hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType,
    256264            wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
    257265            wined3dformat_from_d3dformat(DepthStencilFormat));
    258     LeaveCriticalSection(&d3d8_cs);
     266    wined3d_mutex_unlock();
     267
    259268    return hr;
    260269}
     
    288297        return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
    289298    }
    290     EnterCriticalSection(&d3d8_cs);
     299
     300    wined3d_mutex_lock();
    291301    hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
    292     LeaveCriticalSection(&d3d8_cs);
     302    wined3d_mutex_unlock();
     303
    293304    fixup_caps(pWineCaps);
    294305    WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
     
    304315    TRACE("(%p)->(%d)\n", This, Adapter);
    305316
    306     EnterCriticalSection(&d3d8_cs);
     317    wined3d_mutex_lock();
    307318    ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
    308     LeaveCriticalSection(&d3d8_cs);
     319    wined3d_mutex_unlock();
     320
    309321    return ret;
    310 }
    311 
    312 ULONG WINAPI D3D8CB_DestroyRenderTarget(IWineD3DSurface *pSurface) {
    313     IDirect3DSurface8Impl* surfaceParent;
    314     TRACE("(%p) call back\n", pSurface);
    315 
    316     IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
    317     surfaceParent->isImplicit = FALSE;
    318     /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
    319     return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);
    320322}
    321323
     
    327329    IUnknown_Release(swapChainParent);
    328330    return IUnknown_Release(swapChainParent);
    329 }
    330 
    331 ULONG WINAPI D3D8CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface) {
    332     IDirect3DSurface8Impl* surfaceParent;
    333     TRACE("(%p) call back\n", pSurface);
    334 
    335     IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
    336     surfaceParent->isImplicit = FALSE;
    337     /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
    338     return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);
    339331}
    340332
     
    372364
    373365    /* Allocate an associated WineD3DDevice object */
    374     EnterCriticalSection(&d3d8_cs);
     366    wined3d_mutex_lock();
    375367    hr = IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags,
    376368            (IUnknown *)object, (IWineD3DDeviceParent *)&object->device_parent_vtbl, &object->WineD3DDevice);
     
    379371        HeapFree(GetProcessHeap(), 0, object);
    380372        *ppReturnedDeviceInterface = NULL;
    381         LeaveCriticalSection(&d3d8_cs);
     373        wined3d_mutex_unlock();
     374
    382375        return hr;
    383376    }
     
    406399
    407400    hr = IWineD3DDevice_Init3D(object->WineD3DDevice, &localParameters);
    408     LeaveCriticalSection(&d3d8_cs);
     401    wined3d_mutex_unlock();
    409402
    410403    pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
     
    432425    if(!object->decls) {
    433426        ERR("Out of memory\n");
    434         EnterCriticalSection(&d3d8_cs);
     427
     428        wined3d_mutex_lock();
    435429        IWineD3DDevice_Release(object->WineD3DDevice);
    436         LeaveCriticalSection(&d3d8_cs);
     430        wined3d_mutex_unlock();
     431
    437432        HeapFree(GetProcessHeap(), 0, object);
    438433        *ppReturnedDeviceInterface = NULL;
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/indexbuffer.c

    r19678 r23571  
    5656    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5757
     58    if (ref == 1)
     59    {
     60        IDirect3DDevice8_AddRef(This->parentDevice);
     61        wined3d_mutex_lock();
     62        IWineD3DBuffer_AddRef(This->wineD3DIndexBuffer);
     63        wined3d_mutex_unlock();
     64    }
     65
    5866    return ref;
    5967}
     
    6674
    6775    if (ref == 0) {
    68         EnterCriticalSection(&d3d8_cs);
     76        IDirect3DDevice8_Release(This->parentDevice);
     77        wined3d_mutex_lock();
    6978        IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
    70         LeaveCriticalSection(&d3d8_cs);
    71         IUnknown_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(&d3d8_cs);
     91    wined3d_mutex_lock();
    8592    hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
    8693    if (SUCCEEDED(hr))
     
    8996        IWineD3DDevice_Release(wined3d_device);
    9097    }
    91     LeaveCriticalSection(&d3d8_cs);
     98    wined3d_mutex_unlock();
     99
    92100    return hr;
    93101}
     
    98106    TRACE("(%p) Relay\n", This);
    99107
    100     EnterCriticalSection(&d3d8_cs);
     108    wined3d_mutex_lock();
    101109    hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
    102     LeaveCriticalSection(&d3d8_cs);
     110    wined3d_mutex_unlock();
     111
    103112    return hr;
    104113}
     
    109118    TRACE("(%p) Relay\n", This);
    110119
    111     EnterCriticalSection(&d3d8_cs);
     120    wined3d_mutex_lock();
    112121    hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
    113     LeaveCriticalSection(&d3d8_cs);
     122    wined3d_mutex_unlock();
     123
    114124    return hr;
    115125}
     
    120130    TRACE("(%p) Relay\n", This);
    121131
    122     EnterCriticalSection(&d3d8_cs);
     132    wined3d_mutex_lock();
    123133    hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
    124     LeaveCriticalSection(&d3d8_cs);
     134    wined3d_mutex_unlock();
     135
    125136    return hr;
    126137}
     
    131142    TRACE("(%p) Relay\n", This);
    132143
    133     EnterCriticalSection(&d3d8_cs);
     144    wined3d_mutex_lock();
    134145    ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
    135     LeaveCriticalSection(&d3d8_cs);
     146    wined3d_mutex_unlock();
     147
    136148    return ret;
    137149}
     
    142154    TRACE("(%p) Relay\n", This);
    143155
    144     EnterCriticalSection(&d3d8_cs);
     156    wined3d_mutex_lock();
    145157    ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
    146     LeaveCriticalSection(&d3d8_cs);
     158    wined3d_mutex_unlock();
     159
    147160    return ret;
    148161}
     
    152165    TRACE("(%p) Relay\n", This);
    153166
    154     EnterCriticalSection(&d3d8_cs);
     167    wined3d_mutex_lock();
    155168    IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
    156     LeaveCriticalSection(&d3d8_cs);
     169    wined3d_mutex_unlock();
    157170}
    158171
     
    170183    TRACE("(%p) Relay\n", This);
    171184
    172     EnterCriticalSection(&d3d8_cs);
     185    wined3d_mutex_lock();
    173186    hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
    174     LeaveCriticalSection(&d3d8_cs);
     187    wined3d_mutex_unlock();
     188
    175189    return hr;
    176190}
     
    181195    TRACE("(%p) Relay\n", This);
    182196
    183     EnterCriticalSection(&d3d8_cs);
     197    wined3d_mutex_lock();
    184198    hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
    185     LeaveCriticalSection(&d3d8_cs);
     199    wined3d_mutex_unlock();
     200
    186201    return hr;
    187202}
     
    193208    TRACE("(%p) Relay\n", This);
    194209
    195     EnterCriticalSection(&d3d8_cs);
     210    wined3d_mutex_lock();
    196211    hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
    197     LeaveCriticalSection(&d3d8_cs);
     212    wined3d_mutex_unlock();
    198213
    199214    if (SUCCEEDED(hr)) {
     
    208223}
    209224
    210 
    211 const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl =
     225static const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl =
    212226{
    213227    /* IUnknown */
     
    229243    IDirect3DIndexBuffer8Impl_GetDesc
    230244};
     245
     246static void STDMETHODCALLTYPE d3d8_indexbuffer_wined3d_object_destroyed(void *parent)
     247{
     248    HeapFree(GetProcessHeap(), 0, parent);
     249}
     250
     251static const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops =
     252{
     253    d3d8_indexbuffer_wined3d_object_destroyed,
     254};
     255
     256HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
     257        UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
     258{
     259    HRESULT hr;
     260
     261    buffer->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
     262    buffer->ref = 1;
     263    buffer->format = wined3dformat_from_d3dformat(format);
     264
     265    wined3d_mutex_lock();
     266    hr = IWineD3DDevice_CreateIndexBuffer(device->WineD3DDevice, size,
     267            usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DIndexBuffer,
     268            (IUnknown *)buffer, &d3d8_indexbuffer_wined3d_parent_ops);
     269    wined3d_mutex_unlock();
     270    if (FAILED(hr))
     271    {
     272        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
     273        return hr;
     274    }
     275
     276    buffer->parentDevice = (IDirect3DDevice8 *)device;
     277    IUnknown_AddRef(buffer->parentDevice);
     278
     279    return D3D_OK;
     280}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/pixelshader.c

    r19678 r23571  
    5656    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5757
     58    if (ref == 1)
     59    {
     60        wined3d_mutex_lock();
     61        IWineD3DPixelShader_AddRef(This->wineD3DPixelShader);
     62        wined3d_mutex_unlock();
     63    }
     64
    5865    return ref;
    5966}
     
    6673
    6774    if (ref == 0) {
    68         EnterCriticalSection(&d3d8_cs);
     75        wined3d_mutex_lock();
    6976        IWineD3DPixelShader_Release(This->wineD3DPixelShader);
    70         LeaveCriticalSection(&d3d8_cs);
    71         HeapFree(GetProcessHeap(), 0, This);
     77        wined3d_mutex_unlock();
    7278    }
    7379    return ref;
    7480}
    7581
    76 const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl =
     82static const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl =
    7783{
    7884    /* IUnknown */
     
    8187    IDirect3DPixelShader8Impl_Release,
    8288};
     89
     90static void STDMETHODCALLTYPE d3d8_pixelshader_wined3d_object_destroyed(void *parent)
     91{
     92    HeapFree(GetProcessHeap(), 0, parent);
     93}
     94
     95static const struct wined3d_parent_ops d3d8_pixelshader_wined3d_parent_ops =
     96{
     97    d3d8_pixelshader_wined3d_object_destroyed,
     98};
     99
     100HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl *device,
     101        const DWORD *byte_code, DWORD shader_handle)
     102{
     103    HRESULT hr;
     104
     105    shader->ref = 1;
     106    shader->lpVtbl = &Direct3DPixelShader8_Vtbl;
     107    shader->handle = shader_handle;
     108
     109    wined3d_mutex_lock();
     110    hr = IWineD3DDevice_CreatePixelShader(device->WineD3DDevice, byte_code,
     111            NULL, &shader->wineD3DPixelShader, (IUnknown *)shader,
     112            &d3d8_pixelshader_wined3d_parent_ops);
     113    wined3d_mutex_unlock();
     114    if (FAILED(hr))
     115    {
     116        WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
     117        return hr;
     118    }
     119
     120    return D3D_OK;
     121}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/stateblock.c

    r19678 r23571  
    6868
    6969    if (ref == 0) {
    70         EnterCriticalSection(&d3d8_cs);
     70        wined3d_mutex_lock();
    7171        IWineD3DStateBlock_Release(This->wineD3DStateBlock);
    72         LeaveCriticalSection(&d3d8_cs);
     72        wined3d_mutex_unlock();
     73
    7374        HeapFree(GetProcessHeap(), 0, This);
    7475    }
     
    8485    TRACE("(%p) Relay\n", This);
    8586
    86     EnterCriticalSection(&d3d8_cs);
    87 
     87    wined3d_mutex_lock();
    8888    hr = IWineD3DStateBlock_GetDevice(This->wineD3DStateBlock, &wined3d_device);
    8989    if (SUCCEEDED(hr))
     
    9292        IWineD3DDevice_Release(wined3d_device);
    9393    }
    94 
    95     LeaveCriticalSection(&d3d8_cs);
     94    wined3d_mutex_unlock();
    9695
    9796    return hr;
     
    104103    TRACE("(%p) Relay\n", This);
    105104
    106     EnterCriticalSection(&d3d8_cs);
    107 
     105    wined3d_mutex_lock();
    108106    hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
    109 
    110     LeaveCriticalSection(&d3d8_cs);
     107    wined3d_mutex_unlock();
    111108
    112109    return hr;
     
    119116    TRACE("(%p) Relay\n", This);
    120117
    121     EnterCriticalSection(&d3d8_cs);
    122 
     118    wined3d_mutex_lock();
    123119    hr = IWineD3DStateBlock_Apply(This->wineD3DStateBlock);
    124 
    125     LeaveCriticalSection(&d3d8_cs);
     120    wined3d_mutex_unlock();
    126121
    127122    return hr;
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/surface.c

    r21731 r23571  
    6262        /* No container, handle our own refcounting */
    6363        ULONG ref = InterlockedIncrement(&This->ref);
    64         if(ref == 1 && This->parentDevice) IUnknown_AddRef(This->parentDevice);
     64        if (ref == 1)
     65        {
     66            if (This->parentDevice) IUnknown_AddRef(This->parentDevice);
     67            wined3d_mutex_lock();
     68            IUnknown_AddRef(This->wineD3DSurface);
     69            wined3d_mutex_unlock();
     70        }
    6571        TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    6672        return ref;
     
    8591            if (This->parentDevice) IUnknown_Release(This->parentDevice);
    8692            /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */
    87             if (!This->isImplicit) {
    88                 EnterCriticalSection(&d3d8_cs);
    89                 IWineD3DSurface_Release(This->wineD3DSurface);
    90                 LeaveCriticalSection(&d3d8_cs);
    91                 HeapFree(GetProcessHeap(), 0, This);
    92             }
     93            wined3d_mutex_lock();
     94            IWineD3DSurface_Release(This->wineD3DSurface);
     95            wined3d_mutex_unlock();
    9396        }
    9497
     
    104107    TRACE("(%p)->(%p)\n", This, ppDevice);
    105108
    106     EnterCriticalSection(&d3d8_cs);
     109    wined3d_mutex_lock();
    107110    hr = IWineD3DSurface_GetDevice(This->wineD3DSurface, &wined3d_device);
    108111    if (SUCCEEDED(hr))
     
    111114        IWineD3DDevice_Release(wined3d_device);
    112115    }
    113     LeaveCriticalSection(&d3d8_cs);
     116    wined3d_mutex_unlock();
     117
    114118    return hr;
    115119}
     
    120124    TRACE("(%p) Relay\n", This);
    121125
    122     EnterCriticalSection(&d3d8_cs);
     126    wined3d_mutex_lock();
    123127    hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
    124     LeaveCriticalSection(&d3d8_cs);
     128    wined3d_mutex_unlock();
     129
    125130    return hr;
    126131}
     
    131136    TRACE("(%p) Relay\n", This);
    132137
    133     EnterCriticalSection(&d3d8_cs);
     138    wined3d_mutex_lock();
    134139    hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
    135     LeaveCriticalSection(&d3d8_cs);
     140    wined3d_mutex_unlock();
     141
    136142    return hr;
    137143}
     
    142148    TRACE("(%p) Relay\n", This);
    143149
    144     EnterCriticalSection(&d3d8_cs);
     150    wined3d_mutex_lock();
    145151    hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
    146     LeaveCriticalSection(&d3d8_cs);
     152    wined3d_mutex_unlock();
     153
    147154    return hr;
    148155}
     
    169176    TRACE("(%p) Relay\n", This);
    170177
    171     EnterCriticalSection(&d3d8_cs);
     178    wined3d_mutex_lock();
    172179    hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
    173     LeaveCriticalSection(&d3d8_cs);
     180    wined3d_mutex_unlock();
    174181
    175182    if (SUCCEEDED(hr))
     
    194201    TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
    195202
    196     EnterCriticalSection(&d3d8_cs);
     203    wined3d_mutex_lock();
    197204    if (pRect) {
    198205        D3DSURFACE_DESC desc;
     
    206213                || (pRect->bottom > desc.Height)) {
    207214            WARN("Trying to lock an invalid rectangle, returning D3DERR_INVALIDCALL\n");
    208             LeaveCriticalSection(&d3d8_cs);
     215            wined3d_mutex_unlock();
     216
    209217            return D3DERR_INVALIDCALL;
    210218        }
     
    212220
    213221    hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
    214     LeaveCriticalSection(&d3d8_cs);
     222    wined3d_mutex_unlock();
     223
    215224    return hr;
    216225}
     
    221230    TRACE("(%p) Relay\n", This);
    222231
    223     EnterCriticalSection(&d3d8_cs);
     232    wined3d_mutex_lock();
    224233    hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
    225     LeaveCriticalSection(&d3d8_cs);
     234    wined3d_mutex_unlock();
     235
    226236    switch(hr)
    227237    {
     
    231241}
    232242
    233 const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
     243static const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
    234244{
    235245    /* IUnknown */
     
    248258    IDirect3DSurface8Impl_UnlockRect
    249259};
     260
     261static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
     262{
     263    HeapFree(GetProcessHeap(), 0, parent);
     264}
     265
     266static const struct wined3d_parent_ops d3d8_surface_wined3d_parent_ops =
     267{
     268    surface_wined3d_object_destroyed,
     269};
     270
     271HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *device,
     272        UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
     273        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
     274{
     275    HRESULT hr;
     276
     277    surface->lpVtbl = &Direct3DSurface8_Vtbl;
     278    surface->ref = 1;
     279
     280    /* FIXME: Check MAX bounds of MultisampleQuality. */
     281    if (multisample_quality > 0)
     282    {
     283        FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality);
     284        multisample_quality = 0;
     285    }
     286
     287    wined3d_mutex_lock();
     288    hr = IWineD3DDevice_CreateSurface(device->WineD3DDevice, width, height, wined3dformat_from_d3dformat(format),
     289            lockable, discard, level, &surface->wineD3DSurface, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool,
     290            multisample_type, multisample_quality, SURFACE_OPENGL, (IUnknown *)surface,
     291            &d3d8_surface_wined3d_parent_ops);
     292    wined3d_mutex_unlock();
     293    if (FAILED(hr))
     294    {
     295        WARN("Failed to create wined3d surface, hr %#x.\n", hr);
     296        return hr;
     297    }
     298
     299    surface->parentDevice = (IDirect3DDevice8 *)device;
     300    IUnknown_AddRef(surface->parentDevice);
     301
     302    return D3D_OK;
     303}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/swapchain.c

    r16477 r23571  
    6666
    6767    if (ref == 0) {
    68         EnterCriticalSection(&d3d8_cs);
    69         IWineD3DSwapChain_Destroy(This->wineD3DSwapChain, D3D8CB_DestroyRenderTarget);
    70         LeaveCriticalSection(&d3d8_cs);
     68        wined3d_mutex_lock();
     69        IWineD3DSwapChain_Destroy(This->wineD3DSwapChain);
     70        wined3d_mutex_unlock();
     71
    7172        if (This->parentDevice) IUnknown_Release(This->parentDevice);
    7273        HeapFree(GetProcessHeap(), 0, This);
     
    8182    TRACE("(%p) Relay\n", This);
    8283
    83     EnterCriticalSection(&d3d8_cs);
     84    wined3d_mutex_lock();
    8485    hr = IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, 0);
    85     LeaveCriticalSection(&d3d8_cs);
     86    wined3d_mutex_unlock();
     87
    8688    return hr;
    8789}
     
    9496    TRACE("(%p) Relay\n", This);
    9597
    96     EnterCriticalSection(&d3d8_cs);
     98    wined3d_mutex_lock();
    9799    hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, (WINED3DBACKBUFFER_TYPE )Type, &mySurface);
    98100    if (hrc == D3D_OK && NULL != mySurface) {
     
    100102       IWineD3DSurface_Release(mySurface);
    101103    }
    102     LeaveCriticalSection(&d3d8_cs);
     104    wined3d_mutex_unlock();
     105
    103106    return hrc;
    104107}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/texture.c

    r21731 r23571  
    5757    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5858
     59    if (ref == 1)
     60    {
     61        IDirect3DDevice8_AddRef(This->parentDevice);
     62        wined3d_mutex_lock();
     63        IWineD3DTexture_AddRef(This->wineD3DTexture);
     64        wined3d_mutex_unlock();
     65    }
     66
    5967    return ref;
    6068}
     
    6775
    6876    if (ref == 0) {
    69         EnterCriticalSection(&d3d8_cs);
    70         IWineD3DTexture_Destroy(This->wineD3DTexture, D3D8CB_DestroySurface);
    71         LeaveCriticalSection(&d3d8_cs);
    72         IUnknown_Release(This->parentDevice);
    73         HeapFree(GetProcessHeap(), 0, This);
     77        IDirect3DDevice8_Release(This->parentDevice);
     78        wined3d_mutex_lock();
     79        IWineD3DTexture_Release(This->wineD3DTexture);
     80        wined3d_mutex_unlock();
    7481    }
    7582    return ref;
     
    8289    HRESULT hr;
    8390    TRACE("(%p) Relay\n", This);
    84     EnterCriticalSection(&d3d8_cs);
     91
     92    wined3d_mutex_lock();
    8593    hr = IWineD3DTexture_GetDevice(This->wineD3DTexture, &wined3d_device);
    8694    if (SUCCEEDED(hr))
     
    8997        IWineD3DDevice_Release(wined3d_device);
    9098    }
    91     LeaveCriticalSection(&d3d8_cs);
     99    wined3d_mutex_unlock();
     100
    92101    return hr;
    93102}
     
    98107    TRACE("(%p) Relay\n", This);
    99108
    100     EnterCriticalSection(&d3d8_cs);
     109    wined3d_mutex_lock();
    101110    hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
    102     LeaveCriticalSection(&d3d8_cs);
     111    wined3d_mutex_unlock();
     112
    103113    return hr;
    104114}
     
    109119    TRACE("(%p) Relay\n", This);
    110120
    111     EnterCriticalSection(&d3d8_cs);
     121    wined3d_mutex_lock();
    112122    hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
    113     LeaveCriticalSection(&d3d8_cs);
     123    wined3d_mutex_unlock();
     124
    114125    return hr;
    115126}
     
    120131    TRACE("(%p) Relay\n", This);
    121132
    122     EnterCriticalSection(&d3d8_cs);
     133    wined3d_mutex_lock();
    123134    hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
    124     LeaveCriticalSection(&d3d8_cs);
     135    wined3d_mutex_unlock();
     136
    125137    return hr;
    126138}
     
    131143    TRACE("(%p) Relay\n", This);
    132144
    133     EnterCriticalSection(&d3d8_cs);
     145    wined3d_mutex_lock();
    134146    ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
    135     LeaveCriticalSection(&d3d8_cs);
     147    wined3d_mutex_unlock();
     148
    136149    return ret;
    137150}
     
    142155    TRACE("(%p) Relay\n", This);
    143156
    144     EnterCriticalSection(&d3d8_cs);
     157    wined3d_mutex_lock();
    145158    ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
    146     LeaveCriticalSection(&d3d8_cs);
     159    wined3d_mutex_unlock();
     160
    147161    return ret;
    148162}
     
    152166    TRACE("(%p) Relay\n", This);
    153167
    154     EnterCriticalSection(&d3d8_cs);
     168    wined3d_mutex_lock();
    155169    IWineD3DTexture_PreLoad(This->wineD3DTexture);
    156     LeaveCriticalSection(&d3d8_cs);
     170    wined3d_mutex_unlock();
    157171}
    158172
     
    162176    TRACE("(%p) Relay\n", This);
    163177
    164     EnterCriticalSection(&d3d8_cs);
     178    wined3d_mutex_lock();
    165179    type = IWineD3DTexture_GetType(This->wineD3DTexture);
    166     LeaveCriticalSection(&d3d8_cs);
     180    wined3d_mutex_unlock();
     181
    167182    return type;
    168183}
     
    174189    TRACE("(%p) Relay\n", This);
    175190
    176     EnterCriticalSection(&d3d8_cs);
     191    wined3d_mutex_lock();
    177192    ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
    178     LeaveCriticalSection(&d3d8_cs);
     193    wined3d_mutex_unlock();
     194
    179195    return ret;
    180196}
     
    185201    TRACE("(%p) Relay\n", This);
    186202
    187     EnterCriticalSection(&d3d8_cs);
     203    wined3d_mutex_lock();
    188204    ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
    189     LeaveCriticalSection(&d3d8_cs);
     205    wined3d_mutex_unlock();
     206
    190207    return ret;
    191208}
     
    196213    TRACE("(%p) Relay\n", This);
    197214
    198     EnterCriticalSection(&d3d8_cs);
     215    wined3d_mutex_lock();
    199216    ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
    200     LeaveCriticalSection(&d3d8_cs);
     217    wined3d_mutex_unlock();
     218
    201219    return ret;
    202220}
     
    210228    TRACE("(%p) Relay\n", This);
    211229
    212     EnterCriticalSection(&d3d8_cs);
     230    wined3d_mutex_lock();
    213231    hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
    214     LeaveCriticalSection(&d3d8_cs);
     232    wined3d_mutex_unlock();
    215233
    216234    if (SUCCEEDED(hr))
     
    235253
    236254    TRACE("(%p) Relay\n", This);
    237     EnterCriticalSection(&d3d8_cs);
     255
     256    wined3d_mutex_lock();
    238257    hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
    239258    if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
     
    241260       IWineD3DSurface_Release(mySurface);
    242261    }
    243     LeaveCriticalSection(&d3d8_cs);
     262    wined3d_mutex_unlock();
     263
    244264    return hrc;
    245265}
     
    250270    TRACE("(%p) Relay\n", This);
    251271
    252     EnterCriticalSection(&d3d8_cs);
     272    wined3d_mutex_lock();
    253273    hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
    254     LeaveCriticalSection(&d3d8_cs);
     274    wined3d_mutex_unlock();
     275
    255276    return hr;
    256277}
     
    261282    TRACE("(%p) Relay\n", This);
    262283
    263     EnterCriticalSection(&d3d8_cs);
     284    wined3d_mutex_lock();
    264285    hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
    265     LeaveCriticalSection(&d3d8_cs);
     286    wined3d_mutex_unlock();
     287
    266288    return hr;
    267289}
     
    272294    TRACE("(%p) Relay\n", This);
    273295
    274     EnterCriticalSection(&d3d8_cs);
     296    wined3d_mutex_lock();
    275297    hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
    276     LeaveCriticalSection(&d3d8_cs);
    277     return hr;
    278 }
    279 
    280 const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
     298    wined3d_mutex_unlock();
     299
     300    return hr;
     301}
     302
     303static const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
    281304{
    282305    /* IUnknown */
     
    304327    IDirect3DTexture8Impl_AddDirtyRect
    305328};
     329
     330static void STDMETHODCALLTYPE d3d8_texture_wined3d_object_destroyed(void *parent)
     331{
     332    HeapFree(GetProcessHeap(), 0, parent);
     333}
     334
     335static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops =
     336{
     337    d3d8_texture_wined3d_object_destroyed,
     338};
     339
     340HRESULT texture_init(IDirect3DTexture8Impl *texture, IDirect3DDevice8Impl *device,
     341        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
     342{
     343    HRESULT hr;
     344
     345    texture->lpVtbl = &Direct3DTexture8_Vtbl;
     346    texture->ref = 1;
     347
     348    wined3d_mutex_lock();
     349    hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
     350            usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
     351            &texture->wineD3DTexture, (IUnknown *)texture, &d3d8_texture_wined3d_parent_ops);
     352    wined3d_mutex_unlock();
     353    if (FAILED(hr))
     354    {
     355        WARN("Failed to create wined3d texture, hr %#x.\n", hr);
     356        return hr;
     357    }
     358
     359    texture->parentDevice = (IDirect3DDevice8 *)device;
     360    IDirect3DDevice8_AddRef(texture->parentDevice);
     361
     362    return D3D_OK;
     363}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexbuffer.c

    r19678 r23571  
    5757    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5858
     59    if (ref == 1)
     60    {
     61        IDirect3DDevice8_AddRef(This->parentDevice);
     62        wined3d_mutex_lock();
     63        IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer);
     64        wined3d_mutex_unlock();
     65    }
     66
    5967    return ref;
    6068}
     
    6775
    6876    if (ref == 0) {
    69         EnterCriticalSection(&d3d8_cs);
     77        IDirect3DDevice8_Release(This->parentDevice);
     78        wined3d_mutex_lock();
    7079        IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
    71         LeaveCriticalSection(&d3d8_cs);
    72         IUnknown_Release(This->parentDevice);
    73         HeapFree(GetProcessHeap(), 0, This);
     80        wined3d_mutex_unlock();
    7481    }
    7582
     
    8491    TRACE("(%p) Relay\n", This);
    8592
    86     EnterCriticalSection(&d3d8_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(&d3d8_cs);
     100    wined3d_mutex_unlock();
     101
    94102    return hr;
    95103}
     
    100108    TRACE("(%p) Relay\n", This);
    101109
    102     EnterCriticalSection(&d3d8_cs);
     110    wined3d_mutex_lock();
    103111    hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
    104     LeaveCriticalSection(&d3d8_cs);
     112    wined3d_mutex_unlock();
     113
    105114    return hr;
    106115}
     
    111120    TRACE("(%p) Relay\n", This);
    112121
    113     EnterCriticalSection(&d3d8_cs);
     122    wined3d_mutex_lock();
    114123    hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
    115     LeaveCriticalSection(&d3d8_cs);
     124    wined3d_mutex_unlock();
     125
    116126    return hr;
    117127}
     
    122132    TRACE("(%p) Relay\n", This);
    123133
    124     EnterCriticalSection(&d3d8_cs);
     134    wined3d_mutex_lock();
    125135    hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
    126     LeaveCriticalSection(&d3d8_cs);
     136    wined3d_mutex_unlock();
     137
    127138    return hr;
    128139}
     
    133144    TRACE("(%p) Relay\n", This);
    134145
    135     EnterCriticalSection(&d3d8_cs);
     146    wined3d_mutex_lock();
    136147    ret = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
    137     LeaveCriticalSection(&d3d8_cs);
     148    wined3d_mutex_unlock();
     149
    138150    return ret;
    139151}
     
    144156    TRACE("(%p) Relay\n", This);
    145157
    146     EnterCriticalSection(&d3d8_cs);
     158    wined3d_mutex_lock();
    147159    ret = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
    148     LeaveCriticalSection(&d3d8_cs);
     160    wined3d_mutex_unlock();
     161
    149162    return ret;
    150163}
     
    154167    TRACE("(%p) Relay\n", This);
    155168
    156     EnterCriticalSection(&d3d8_cs);
     169    wined3d_mutex_lock();
    157170    IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
    158     LeaveCriticalSection(&d3d8_cs);
     171    wined3d_mutex_unlock();
    159172}
    160173
     
    172185    TRACE("(%p) Relay\n", This);
    173186
    174     EnterCriticalSection(&d3d8_cs);
     187    wined3d_mutex_lock();
    175188    hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
    176     LeaveCriticalSection(&d3d8_cs);
     189    wined3d_mutex_unlock();
     190
    177191    return hr;
    178192}
     
    183197    TRACE("(%p) Relay\n", This);
    184198
    185     EnterCriticalSection(&d3d8_cs);
     199    wined3d_mutex_lock();
    186200    hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
    187     LeaveCriticalSection(&d3d8_cs);
     201    wined3d_mutex_unlock();
     202
    188203    return hr;
    189204}
     
    195210    TRACE("(%p) Relay\n", This);
    196211
    197     EnterCriticalSection(&d3d8_cs);
     212    wined3d_mutex_lock();
    198213    hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
    199     LeaveCriticalSection(&d3d8_cs);
     214    wined3d_mutex_unlock();
    200215
    201216    if (SUCCEEDED(hr)) {
     
    211226}
    212227
    213 const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
     228static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
    214229{
    215230    /* IUnknown */
     
    231246    IDirect3DVertexBuffer8Impl_GetDesc
    232247};
     248
     249static void STDMETHODCALLTYPE d3d8_vertexbuffer_wined3d_object_destroyed(void *parent)
     250{
     251    HeapFree(GetProcessHeap(), 0, parent);
     252}
     253
     254static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops =
     255{
     256    d3d8_vertexbuffer_wined3d_object_destroyed,
     257};
     258
     259HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
     260        UINT size, DWORD usage, DWORD fvf, D3DPOOL pool)
     261{
     262    HRESULT hr;
     263
     264    buffer->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
     265    buffer->ref = 1;
     266    buffer->fvf = fvf;
     267
     268    wined3d_mutex_lock();
     269    hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
     270            usage & WINED3DUSAGE_MASK, 0, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
     271            (IUnknown *)buffer, &d3d8_vertexbuffer_wined3d_parent_ops);
     272    wined3d_mutex_unlock();
     273    if (FAILED(hr))
     274    {
     275        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
     276        return hr;
     277    }
     278
     279    buffer->parentDevice = (IDirect3DDevice8 *)device;
     280    IUnknown_AddRef(buffer->parentDevice);
     281
     282    return D3D_OK;
     283}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexdeclaration.c

    r19678 r23571  
    6060    TRACE("(%p) : AddRef increasing to %d\n", This, ref_count);
    6161
     62    if (ref_count == 1)
     63    {
     64        wined3d_mutex_lock();
     65        IWineD3DVertexDeclaration_AddRef(This->wined3d_vertex_declaration);
     66        wined3d_mutex_unlock();
     67    }
     68
    6269    return ref_count;
    6370}
     
    7178
    7279    if (!ref_count) {
    73         EnterCriticalSection(&d3d8_cs);
     80        wined3d_mutex_lock();
    7481        IWineD3DVertexDeclaration_Release(This->wined3d_vertex_declaration);
    75         LeaveCriticalSection(&d3d8_cs);
    76         HeapFree(GetProcessHeap(), 0, This->elements);
    77         HeapFree(GetProcessHeap(), 0, This);
     82        wined3d_mutex_unlock();
    7883    }
    7984
     
    265270    /*WINED3DDECLTYPE_FLOAT3*/    WINED3DFMT_R32G32B32_FLOAT,
    266271    /*WINED3DDECLTYPE_FLOAT4*/    WINED3DFMT_R32G32B32A32_FLOAT,
    267     /*WINED3DDECLTYPE_D3DCOLOR*/  WINED3DFMT_A8R8G8B8,
     272    /*WINED3DDECLTYPE_D3DCOLOR*/  WINED3DFMT_B8G8R8A8_UNORM,
    268273    /*WINED3DDECLTYPE_UBYTE4*/    WINED3DFMT_R8G8B8A8_UINT,
    269274    /*WINED3DDECLTYPE_SHORT2*/    WINED3DFMT_R16G16_SINT,
     
    361366}
    362367
    363 const IDirect3DVertexDeclaration8Vtbl Direct3DVertexDeclaration8_Vtbl =
     368static const IDirect3DVertexDeclaration8Vtbl Direct3DVertexDeclaration8_Vtbl =
    364369{
    365370    IDirect3DVertexDeclaration8Impl_QueryInterface,
     
    367372    IDirect3DVertexDeclaration8Impl_Release
    368373};
     374
     375static void STDMETHODCALLTYPE d3d8_vertexdeclaration_wined3d_object_destroyed(void *parent)
     376{
     377    IDirect3DVertexDeclaration8Impl *declaration = parent;
     378    HeapFree(GetProcessHeap(), 0, declaration->elements);
     379    HeapFree(GetProcessHeap(), 0, declaration);
     380}
     381
     382static const struct wined3d_parent_ops d3d8_vertexdeclaration_wined3d_parent_ops =
     383{
     384    d3d8_vertexdeclaration_wined3d_object_destroyed,
     385};
     386
     387HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
     388        IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle)
     389{
     390    WINED3DVERTEXELEMENT *wined3d_elements;
     391    UINT wined3d_element_count;
     392    HRESULT hr;
     393
     394    declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
     395    declaration->ref_count = 1;
     396    declaration->shader_handle = shader_handle;
     397
     398    wined3d_element_count = convert_to_wined3d_declaration(elements, &declaration->elements_size, &wined3d_elements);
     399    declaration->elements = HeapAlloc(GetProcessHeap(), 0, declaration->elements_size);
     400    if (!declaration->elements)
     401    {
     402        ERR("Failed to allocate vertex declaration elements memory.\n");
     403        HeapFree(GetProcessHeap(), 0, wined3d_elements);
     404        return E_OUTOFMEMORY;
     405    }
     406
     407    memcpy(declaration->elements, elements, declaration->elements_size);
     408
     409    wined3d_mutex_lock();
     410    hr = IWineD3DDevice_CreateVertexDeclaration(device->WineD3DDevice, &declaration->wined3d_vertex_declaration,
     411            (IUnknown *)declaration, &d3d8_vertexdeclaration_wined3d_parent_ops,
     412            wined3d_elements, wined3d_element_count);
     413    wined3d_mutex_unlock();
     414    HeapFree(GetProcessHeap(), 0, wined3d_elements);
     415    if (FAILED(hr))
     416    {
     417        WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
     418        HeapFree(GetProcessHeap(), 0, declaration->elements);
     419        return hr;
     420    }
     421
     422    return D3D_OK;
     423}
     424
     425HRESULT vertexdeclaration_init_fvf(IDirect3DVertexDeclaration8Impl *declaration,
     426        IDirect3DDevice8Impl *device, DWORD fvf)
     427{
     428    HRESULT hr;
     429
     430    declaration->ref_count = 1;
     431    declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
     432    declaration->elements = NULL;
     433    declaration->elements_size = 0;
     434    declaration->shader_handle = fvf;
     435
     436    hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(device->WineD3DDevice,
     437            &declaration->wined3d_vertex_declaration, (IUnknown *)declaration,
     438            &d3d8_vertexdeclaration_wined3d_parent_ops, fvf);
     439    if (FAILED(hr))
     440    {
     441        WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
     442        return hr;
     443    }
     444
     445    return D3D_OK;
     446}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexshader.c

    r19678 r23571  
    5656    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5757
     58    if (ref == 1 && This->wineD3DVertexShader)
     59    {
     60        wined3d_mutex_lock();
     61        IWineD3DVertexShader_AddRef(This->wineD3DVertexShader);
     62        wined3d_mutex_unlock();
     63    }
     64
    5865    return ref;
     66}
     67
     68static void STDMETHODCALLTYPE d3d8_vertexshader_wined3d_object_destroyed(void *parent)
     69{
     70    IDirect3DVertexShader8Impl *shader = parent;
     71    IDirect3DVertexDeclaration8_Release(shader->vertex_declaration);
     72    HeapFree(GetProcessHeap(), 0, shader);
    5973}
    6074
     
    6680
    6781    if (ref == 0) {
    68         IDirect3DVertexDeclaration8_Release(This->vertex_declaration);
    6982        if (This->wineD3DVertexShader)
    7083        {
    71             EnterCriticalSection(&d3d8_cs);
     84            wined3d_mutex_lock();
    7285            IWineD3DVertexShader_Release(This->wineD3DVertexShader);
    73             LeaveCriticalSection(&d3d8_cs);
     86            wined3d_mutex_unlock();
    7487        }
    75         HeapFree(GetProcessHeap(), 0, This);
     88        else
     89        {
     90            d3d8_vertexshader_wined3d_object_destroyed(This);
     91        }
    7692    }
    7793    return ref;
    7894}
    7995
    80 const IDirect3DVertexShader8Vtbl Direct3DVertexShader8_Vtbl =
     96static const IDirect3DVertexShader8Vtbl Direct3DVertexShader8_Vtbl =
    8197{
    8298    /* IUnknown */
     
    85101    IDirect3DVertexShader8Impl_Release,
    86102};
     103
     104static const struct wined3d_parent_ops d3d8_vertexshader_wined3d_parent_ops =
     105{
     106    d3d8_vertexshader_wined3d_object_destroyed,
     107};
     108
     109static HRESULT vertexshader_create_vertexdeclaration(IDirect3DDevice8Impl *device,
     110        const DWORD *declaration, DWORD shader_handle, IDirect3DVertexDeclaration8 **decl_ptr)
     111{
     112    IDirect3DVertexDeclaration8Impl *object;
     113    HRESULT hr;
     114
     115    TRACE("device %p, declaration %p, shader_handle %#x, decl_ptr %p.\n",
     116            device, declaration, shader_handle, decl_ptr);
     117
     118    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     119    if (!object) {
     120        ERR("Memory allocation failed\n");
     121        *decl_ptr = NULL;
     122        return D3DERR_OUTOFVIDEOMEMORY;
     123    }
     124
     125    hr = vertexdeclaration_init(object, device, declaration, shader_handle);
     126    if (FAILED(hr))
     127    {
     128        WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
     129        HeapFree(GetProcessHeap(), 0, object);
     130        return hr;
     131    }
     132
     133    TRACE("Created vertex declaration %p.\n", object);
     134    *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
     135
     136    return D3D_OK;
     137}
     138
     139HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Impl *device,
     140        const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage)
     141{
     142    const DWORD *token = declaration;
     143    HRESULT hr;
     144
     145    /* Test if the vertex declaration is valid */
     146    while (D3DVSD_END() != *token)
     147    {
     148        D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
     149
     150        if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000))
     151        {
     152            DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
     153            DWORD reg  = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
     154
     155            if (reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !byte_code)
     156            {
     157                WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
     158                return D3DERR_INVALIDCALL;
     159            }
     160        }
     161        token += parse_token(token);
     162    }
     163
     164    shader->ref = 1;
     165    shader->lpVtbl = &Direct3DVertexShader8_Vtbl;
     166
     167    hr = vertexshader_create_vertexdeclaration(device, declaration, shader_handle, &shader->vertex_declaration);
     168    if (FAILED(hr))
     169    {
     170        WARN("Failed to create vertex declaration, hr %#x.\n", hr);
     171        return hr;
     172    }
     173
     174    if (byte_code)
     175    {
     176        if (usage) FIXME("Usage %#x not implemented.\n", usage);
     177
     178        wined3d_mutex_lock();
     179        hr = IWineD3DDevice_CreateVertexShader(device->WineD3DDevice, byte_code,
     180                NULL /* output signature */, &shader->wineD3DVertexShader,
     181                (IUnknown *)shader, &d3d8_vertexshader_wined3d_parent_ops);
     182        wined3d_mutex_unlock();
     183        if (FAILED(hr))
     184        {
     185            WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
     186            IDirect3DVertexDeclaration8_Release(shader->vertex_declaration);
     187            return hr;
     188        }
     189
     190        load_local_constants(declaration, shader->wineD3DVertexShader);
     191    }
     192
     193    return D3D_OK;
     194}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volume.c

    r21731 r23571  
    6262        ULONG ref = InterlockedIncrement(&This->ref);
    6363        TRACE("(%p) : AddRef from %d\n", This, ref - 1);
     64
     65        if (ref == 1)
     66        {
     67            wined3d_mutex_lock();
     68            IWineD3DVolume_AddRef(This->wineD3DVolume);
     69            wined3d_mutex_unlock();
     70        }
     71
    6472        return ref;
    6573    }
     
    8290
    8391        if (ref == 0) {
    84             EnterCriticalSection(&d3d8_cs);
     92            wined3d_mutex_lock();
    8593            IWineD3DVolume_Release(This->wineD3DVolume);
    86             LeaveCriticalSection(&d3d8_cs);
    87             HeapFree(GetProcessHeap(), 0, This);
     94            wined3d_mutex_unlock();
    8895        }
    8996
     
    97104    IWineD3DDevice       *myDevice = NULL;
    98105
    99     EnterCriticalSection(&d3d8_cs);
     106    wined3d_mutex_lock();
    100107    IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
    101108    IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
    102109    IWineD3DDevice_Release(myDevice);
    103     LeaveCriticalSection(&d3d8_cs);
     110    wined3d_mutex_unlock();
     111
    104112    return D3D_OK;
    105113}
     
    110118    TRACE("(%p) Relay\n", This);
    111119
    112     EnterCriticalSection(&d3d8_cs);
     120    wined3d_mutex_lock();
    113121    hr = IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
    114     LeaveCriticalSection(&d3d8_cs);
     122    wined3d_mutex_unlock();
     123
    115124    return hr;
    116125}
     
    121130    TRACE("(%p) Relay\n", This);
    122131
    123     EnterCriticalSection(&d3d8_cs);
     132    wined3d_mutex_lock();
    124133    hr = IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
    125     LeaveCriticalSection(&d3d8_cs);
     134    wined3d_mutex_unlock();
     135
    126136    return hr;
    127137}
     
    132142    TRACE("(%p) Relay\n", This);
    133143
    134     EnterCriticalSection(&d3d8_cs);
     144    wined3d_mutex_lock();
    135145    hr = IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
    136     LeaveCriticalSection(&d3d8_cs);
     146    wined3d_mutex_unlock();
     147
    137148    return hr;
    138149}
     
    164175    TRACE("(%p) Relay\n", This);
    165176
    166     EnterCriticalSection(&d3d8_cs);
     177    wined3d_mutex_lock();
    167178    hr = IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
    168     LeaveCriticalSection(&d3d8_cs);
     179    wined3d_mutex_unlock();
    169180
    170181    if (SUCCEEDED(hr))
     
    188199    TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
    189200
    190     EnterCriticalSection(&d3d8_cs);
     201    wined3d_mutex_lock();
    191202    hr = IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *) pLockedVolume, (CONST WINED3DBOX *) pBox, Flags);
    192     LeaveCriticalSection(&d3d8_cs);
     203    wined3d_mutex_unlock();
     204
    193205    return hr;
    194206}
     
    199211    TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
    200212
    201     EnterCriticalSection(&d3d8_cs);
     213    wined3d_mutex_lock();
    202214    hr = IWineD3DVolume_UnlockBox(This->wineD3DVolume);
    203     LeaveCriticalSection(&d3d8_cs);
    204     return hr;
    205 }
    206 
    207 const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl =
     215    wined3d_mutex_unlock();
     216
     217    return hr;
     218}
     219
     220static const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl =
    208221{
    209222    /* IUnknown */
     
    222235};
    223236
    224 ULONG WINAPI D3D8CB_DestroyVolume(IWineD3DVolume *pVolume) {
    225     IDirect3DVolume8Impl* volumeParent;
    226 
    227     IWineD3DVolume_GetParent(pVolume, (IUnknown **) &volumeParent);
    228     /* GetParent's AddRef was forwarded to an object in destruction.
    229      * Releasing it here again would cause an endless recursion. */
    230     volumeParent->forwardReference = NULL;
    231     return IDirect3DVolume8_Release((IDirect3DVolume8*) volumeParent);
    232 }
     237static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
     238{
     239    HeapFree(GetProcessHeap(), 0, parent);
     240}
     241
     242static const struct wined3d_parent_ops d3d8_volume_wined3d_parent_ops =
     243{
     244    volume_wined3d_object_destroyed,
     245};
     246
     247HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, UINT width, UINT height,
     248        UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool)
     249{
     250    HRESULT hr;
     251
     252    volume->lpVtbl = &Direct3DVolume8_Vtbl;
     253    volume->ref = 1;
     254
     255    hr = IWineD3DDevice_CreateVolume(device->WineD3DDevice, width, height, depth, usage,
     256            format, pool, &volume->wineD3DVolume, (IUnknown *)volume, &d3d8_volume_wined3d_parent_ops);
     257    if (FAILED(hr))
     258    {
     259        WARN("Failed to create wined3d volume, hr %#x.\n", hr);
     260        return hr;
     261    }
     262
     263    return D3D_OK;
     264}
  • trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volumetexture.c

    r21731 r23571  
    5757    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
    5858
     59    if (ref == 1)
     60    {
     61        IDirect3DDevice8_AddRef(This->parentDevice);
     62        wined3d_mutex_lock();
     63        IWineD3DVolumeTexture_AddRef(This->wineD3DVolumeTexture);
     64        wined3d_mutex_unlock();
     65    }
     66
    5967    return ref;
    6068}
     
    6775
    6876    if (ref == 0) {
    69         EnterCriticalSection(&d3d8_cs);
    70         IWineD3DVolumeTexture_Destroy(This->wineD3DVolumeTexture, D3D8CB_DestroyVolume);
    71         LeaveCriticalSection(&d3d8_cs);
    7277        IUnknown_Release(This->parentDevice);
    73         HeapFree(GetProcessHeap(), 0, This);
     78        wined3d_mutex_lock();
     79        IWineD3DVolumeTexture_Release(This->wineD3DVolumeTexture);
     80        wined3d_mutex_unlock();
    7481    }
    7582    return ref;
     
    8390    TRACE("(%p) Relay\n", This);
    8491
    85     EnterCriticalSection(&d3d8_cs);
     92    wined3d_mutex_lock();
    8693    hr = IWineD3DVolumeTexture_GetDevice(This->wineD3DVolumeTexture, &wined3d_device);
    8794    if (SUCCEEDED(hr))
     
    9097        IWineD3DDevice_Release(wined3d_device);
    9198    }
    92     LeaveCriticalSection(&d3d8_cs);
     99    wined3d_mutex_unlock();
     100
    93101    return hr;
    94102}
     
    99107    TRACE("(%p) Relay\n", This);
    100108
    101     EnterCriticalSection(&d3d8_cs);
     109    wined3d_mutex_lock();
    102110    hr = IWineD3DVolumeTexture_SetPrivateData(This->wineD3DVolumeTexture, refguid, pData, SizeOfData, Flags);
    103     LeaveCriticalSection(&d3d8_cs);
     111    wined3d_mutex_unlock();
     112
    104113    return hr;
    105114}
     
    110119    TRACE("(%p) Relay\n", This);
    111120
    112     EnterCriticalSection(&d3d8_cs);
     121    wined3d_mutex_lock();
    113122    hr = IWineD3DVolumeTexture_GetPrivateData(This->wineD3DVolumeTexture, refguid, pData, pSizeOfData);
    114     LeaveCriticalSection(&d3d8_cs);
     123    wined3d_mutex_unlock();
     124
    115125    return hr;
    116126}
     
    121131    TRACE("(%p) Relay\n", This);
    122132
    123     EnterCriticalSection(&d3d8_cs);
     133    wined3d_mutex_lock();
    124134    hr = IWineD3DVolumeTexture_FreePrivateData(This->wineD3DVolumeTexture, refguid);
    125     LeaveCriticalSection(&d3d8_cs);
     135    wined3d_mutex_unlock();
     136
    126137    return hr;
    127138}
     
    132143    TRACE("(%p) Relay\n", This);
    133144
    134     EnterCriticalSection(&d3d8_cs);
     145    wined3d_mutex_lock();
    135146    ret = IWineD3DVolumeTexture_SetPriority(This->wineD3DVolumeTexture, PriorityNew);
    136     LeaveCriticalSection(&d3d8_cs);
     147    wined3d_mutex_unlock();
     148
    137149    return ret;
    138150}
     
    143155    TRACE("(%p) Relay\n", This);
    144156
    145     EnterCriticalSection(&d3d8_cs);
     157    wined3d_mutex_lock();
    146158    ret = IWineD3DVolumeTexture_GetPriority(This->wineD3DVolumeTexture);
    147     LeaveCriticalSection(&d3d8_cs);
     159    wined3d_mutex_unlock();
     160
    148161    return ret;
    149162}
     
    153166    TRACE("(%p) Relay\n", This);
    154167
    155     EnterCriticalSection(&d3d8_cs);
     168    wined3d_mutex_lock();
    156169    IWineD3DVolumeTexture_PreLoad(This->wineD3DVolumeTexture);
    157     LeaveCriticalSection(&d3d8_cs);
     170    wined3d_mutex_unlock();
    158171}
    159172
     
    163176    TRACE("(%p) Relay\n", This);
    164177
    165     EnterCriticalSection(&d3d8_cs);
     178    wined3d_mutex_lock();
    166179    type = IWineD3DVolumeTexture_GetType(This->wineD3DVolumeTexture);
    167     LeaveCriticalSection(&d3d8_cs);
     180    wined3d_mutex_unlock();
     181
    168182    return type;
    169183}
     
    175189    TRACE("(%p) Relay\n", This);
    176190
    177     EnterCriticalSection(&d3d8_cs);
     191    wined3d_mutex_lock();
    178192    ret = IWineD3DVolumeTexture_SetLOD(This->wineD3DVolumeTexture, LODNew);
    179     LeaveCriticalSection(&d3d8_cs);
     193    wined3d_mutex_unlock();
     194
    180195    return ret;
    181196}
     
    186201    TRACE("(%p) Relay\n", This);
    187202
    188     EnterCriticalSection(&d3d8_cs);
     203    wined3d_mutex_lock();
    189204    ret = IWineD3DVolumeTexture_GetLOD(This->wineD3DVolumeTexture);
    190     LeaveCriticalSection(&d3d8_cs);
     205    wined3d_mutex_unlock();
     206
    191207    return ret;
    192208}
     
    197213    TRACE("(%p) Relay\n", This);
    198214
    199     EnterCriticalSection(&d3d8_cs);
     215    wined3d_mutex_lock();
    200216    ret = IWineD3DVolumeTexture_GetLevelCount(This->wineD3DVolumeTexture);
    201     LeaveCriticalSection(&d3d8_cs);
     217    wined3d_mutex_unlock();
     218
    202219    return ret;
    203220}
     
    211228    TRACE("(%p) Relay\n", This);
    212229
    213     EnterCriticalSection(&d3d8_cs);
     230    wined3d_mutex_lock();
    214231    hr = IWineD3DVolumeTexture_GetLevelDesc(This->wineD3DVolumeTexture, Level, &wined3ddesc);
    215     LeaveCriticalSection(&d3d8_cs);
     232    wined3d_mutex_unlock();
    216233
    217234    if (SUCCEEDED(hr))
     
    237254    TRACE("(%p) Relay\n", This);
    238255
    239     EnterCriticalSection(&d3d8_cs);
     256    wined3d_mutex_lock();
    240257    hrc = IWineD3DVolumeTexture_GetVolumeLevel(This->wineD3DVolumeTexture, Level, &myVolume);
    241258    if (hrc == D3D_OK && NULL != ppVolumeLevel) {
     
    243260       IWineD3DVolumeTexture_Release(myVolume);
    244261    }
    245     LeaveCriticalSection(&d3d8_cs);
     262    wined3d_mutex_unlock();
     263
    246264    return hrc;
    247265}
     
    252270    TRACE("(%p) Relay %p %p %p %d\n", This, This->wineD3DVolumeTexture, pLockedVolume, pBox,Flags);
    253271
    254     EnterCriticalSection(&d3d8_cs);
     272    wined3d_mutex_lock();
    255273    hr = IWineD3DVolumeTexture_LockBox(This->wineD3DVolumeTexture, Level, (WINED3DLOCKED_BOX *) pLockedVolume, (CONST WINED3DBOX *) pBox, Flags);
    256     LeaveCriticalSection(&d3d8_cs);
     274    wined3d_mutex_unlock();
     275
    257276    return hr;
    258277}
     
    263282    TRACE("(%p) Relay %p %d\n", This, This->wineD3DVolumeTexture, Level);
    264283
    265     EnterCriticalSection(&d3d8_cs);
     284    wined3d_mutex_lock();
    266285    hr = IWineD3DVolumeTexture_UnlockBox(This->wineD3DVolumeTexture, Level);
    267     LeaveCriticalSection(&d3d8_cs);
     286    wined3d_mutex_unlock();
     287
    268288    return hr;
    269289}
     
    274294    TRACE("(%p) Relay\n", This);
    275295
    276     EnterCriticalSection(&d3d8_cs);
     296    wined3d_mutex_lock();
    277297    hr = IWineD3DVolumeTexture_AddDirtyBox(This->wineD3DVolumeTexture, (CONST WINED3DBOX *) pDirtyBox);
    278     LeaveCriticalSection(&d3d8_cs);
    279     return hr;
    280 }
    281 
    282 
    283 const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl =
     298    wined3d_mutex_unlock();
     299
     300    return hr;
     301}
     302
     303static const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl =
    284304{
    285305    /* IUnknown */
     
    307327    IDirect3DVolumeTexture8Impl_AddDirtyBox
    308328};
     329
     330static void STDMETHODCALLTYPE volumetexture_wined3d_object_destroyed(void *parent)
     331{
     332    HeapFree(GetProcessHeap(), 0, parent);
     333}
     334
     335static const struct wined3d_parent_ops d3d8_volumetexture_wined3d_parent_ops =
     336{
     337    volumetexture_wined3d_object_destroyed,
     338};
     339
     340HRESULT volumetexture_init(IDirect3DVolumeTexture8Impl *texture, IDirect3DDevice8Impl *device,
     341        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
     342{
     343    HRESULT hr;
     344
     345    texture->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
     346    texture->ref = 1;
     347
     348    wined3d_mutex_lock();
     349    hr = IWineD3DDevice_CreateVolumeTexture(device->WineD3DDevice, width, height, depth, levels,
     350            usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
     351            &texture->wineD3DVolumeTexture, (IUnknown *)texture, &d3d8_volumetexture_wined3d_parent_ops);
     352    wined3d_mutex_unlock();
     353    if (FAILED(hr))
     354    {
     355        WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
     356        return hr;
     357    }
     358
     359    texture->parentDevice = (IDirect3DDevice8 *)device;
     360    IDirect3DDevice8_AddRef(texture->parentDevice);
     361
     362    return D3D_OK;
     363}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette