diff --git a/dlls/d3d11/d3d11_private.h b/dlls/d3d11/d3d11_private.h index 1be17021adb..56ba56067bb 100644 --- a/dlls/d3d11/d3d11_private.h +++ b/dlls/d3d11/d3d11_private.h @@ -327,9 +327,10 @@ HRESULT d3d_rasterizer_state_init(struct d3d_rasterizer_state *state, struct d3d const D3D11_RASTERIZER_DESC *desc) DECLSPEC_HIDDEN; struct d3d_rasterizer_state *unsafe_impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface) DECLSPEC_HIDDEN; -/* ID3D10SamplerState */ +/* ID3D11SamplerState, ID3D10SamplerState */ struct d3d_sampler_state { + ID3D11SamplerState ID3D11SamplerState_iface; ID3D10SamplerState ID3D10SamplerState_iface; LONG refcount; @@ -337,7 +338,7 @@ struct d3d_sampler_state struct wined3d_sampler *wined3d_sampler; D3D10_SAMPLER_DESC desc; struct wine_rb_entry entry; - ID3D10Device1 *device; + ID3D11Device *device; }; HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_device *device, diff --git a/dlls/d3d11/state.c b/dlls/d3d11/state.c index 3b52374dcaf..f98949580ca 100644 --- a/dlls/d3d11/state.c +++ b/dlls/d3d11/state.c @@ -867,6 +867,140 @@ struct d3d_rasterizer_state *unsafe_impl_from_ID3D10RasterizerState(ID3D10Raster return impl_from_ID3D10RasterizerState(iface); } +/* ID3D11SampleState methods */ + +static inline struct d3d_sampler_state *impl_from_ID3D11SamplerState(ID3D11SamplerState *iface) +{ + return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D11SamplerState_iface); +} + +static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_QueryInterface(ID3D11SamplerState *iface, + REFIID riid, void **object) +{ + struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface); + + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); + + if (IsEqualGUID(riid, &IID_ID3D11SamplerState) + || IsEqualGUID(riid, &IID_ID3D11DeviceChild) + || IsEqualGUID(riid, &IID_IUnknown)) + { + ID3D11SamplerState_AddRef(iface); + *object = iface; + return S_OK; + } + + if (IsEqualGUID(riid, &IID_ID3D10SamplerState) + || IsEqualGUID(riid, &IID_ID3D10DeviceChild)) + { + ID3D10SamplerState_AddRef(&state->ID3D10SamplerState_iface); + *object = &state->ID3D10SamplerState_iface; + return S_OK; + } + + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid)); + + *object = NULL; + return E_NOINTERFACE; +} + +static ULONG STDMETHODCALLTYPE d3d11_sampler_state_AddRef(ID3D11SamplerState *iface) +{ + struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface); + ULONG refcount = InterlockedIncrement(&state->refcount); + + TRACE("%p increasing refcount to %u.\n", state, refcount); + + return refcount; +} + +static ULONG STDMETHODCALLTYPE d3d11_sampler_state_Release(ID3D11SamplerState *iface) +{ + struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface); + ULONG refcount = InterlockedDecrement(&state->refcount); + + TRACE("%p decreasing refcount to %u.\n", state, refcount); + + if (!refcount) + { + struct d3d_device *device = impl_from_ID3D11Device(state->device); + + wined3d_mutex_lock(); + wined3d_sampler_decref(state->wined3d_sampler); + wine_rb_remove(&device->sampler_states, &state->desc); + ID3D11Device_Release(state->device); + wined3d_private_store_cleanup(&state->private_store); + wined3d_mutex_unlock(); + HeapFree(GetProcessHeap(), 0, state); + } + + return refcount; +} + +static void STDMETHODCALLTYPE d3d11_sampler_state_GetDevice(ID3D11SamplerState *iface, + ID3D11Device **device) +{ + struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface); + + TRACE("iface %p, device %p.\n", iface, device); + + *device = state->device; + ID3D11Device_AddRef(*device); +} + +static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_GetPrivateData(ID3D11SamplerState *iface, + REFGUID guid, UINT *data_size, void *data) +{ + struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface); + + TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data); + + return d3d_get_private_data(&state->private_store, guid, data_size, data); +} + +static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateData(ID3D11SamplerState *iface, + REFGUID guid, UINT data_size, const void *data) +{ + struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface); + + TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data); + + return d3d_set_private_data(&state->private_store, guid, data_size, data); +} + +static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateDataInterface(ID3D11SamplerState *iface, + REFGUID guid, const IUnknown *data) +{ + struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface); + + TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data); + + return d3d_set_private_data_interface(&state->private_store, guid, data); +} + +static void STDMETHODCALLTYPE d3d11_sampler_state_GetDesc(ID3D11SamplerState *iface, + D3D11_SAMPLER_DESC *desc) +{ + FIXME("iface %p, desc %p stub!\n", iface, desc); +} + +static const struct ID3D11SamplerStateVtbl d3d11_sampler_state_vtbl = +{ + /* IUnknown methods */ + d3d11_sampler_state_QueryInterface, + d3d11_sampler_state_AddRef, + d3d11_sampler_state_Release, + /* ID3D11DeviceChild methods */ + d3d11_sampler_state_GetDevice, + d3d11_sampler_state_GetPrivateData, + d3d11_sampler_state_SetPrivateData, + d3d11_sampler_state_SetPrivateDataInterface, + /* ID3D11SamplerState methods */ + d3d11_sampler_state_GetDesc, +}; + +/* ID3D10SamplerState methods */ + static inline struct d3d_sampler_state *impl_from_ID3D10SamplerState(ID3D10SamplerState *iface) { return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D10SamplerState_iface); @@ -877,54 +1011,29 @@ static inline struct d3d_sampler_state *impl_from_ID3D10SamplerState(ID3D10Sampl static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_QueryInterface(ID3D10SamplerState *iface, REFIID riid, void **object) { + struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface); + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); - if (IsEqualGUID(riid, &IID_ID3D10SamplerState) - || IsEqualGUID(riid, &IID_ID3D10DeviceChild) - || IsEqualGUID(riid, &IID_IUnknown)) - { - IUnknown_AddRef(iface); - *object = iface; - return S_OK; - } - - WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid)); - - *object = NULL; - return E_NOINTERFACE; + return d3d11_sampler_state_QueryInterface(&state->ID3D11SamplerState_iface, riid, object); } static ULONG STDMETHODCALLTYPE d3d10_sampler_state_AddRef(ID3D10SamplerState *iface) { - struct d3d_sampler_state *This = impl_from_ID3D10SamplerState(iface); - ULONG refcount = InterlockedIncrement(&This->refcount); + struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface); - TRACE("%p increasing refcount to %u.\n", This, refcount); + TRACE("iface %p.\n", iface); - return refcount; + return d3d11_sampler_state_AddRef(&state->ID3D11SamplerState_iface); } static ULONG STDMETHODCALLTYPE d3d10_sampler_state_Release(ID3D10SamplerState *iface) { struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface); - ULONG refcount = InterlockedDecrement(&state->refcount); - TRACE("%p decreasing refcount to %u.\n", state, refcount); + TRACE("iface %p.\n", iface); - if (!refcount) - { - struct d3d_device *device = impl_from_ID3D10Device(state->device); - - wined3d_mutex_lock(); - wined3d_sampler_decref(state->wined3d_sampler); - wine_rb_remove(&device->sampler_states, &state->desc); - ID3D10Device1_Release(state->device); - wined3d_private_store_cleanup(&state->private_store); - wined3d_mutex_unlock(); - HeapFree(GetProcessHeap(), 0, state); - } - - return refcount; + return d3d11_sampler_state_Release(&state->ID3D11SamplerState_iface); } /* ID3D10DeviceChild methods */ @@ -935,8 +1044,7 @@ static void STDMETHODCALLTYPE d3d10_sampler_state_GetDevice(ID3D10SamplerState * TRACE("iface %p, device %p.\n", iface, device); - *device = (ID3D10Device *)state->device; - ID3D10Device_AddRef(*device); + ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device); } static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_GetPrivateData(ID3D10SamplerState *iface, @@ -1040,6 +1148,7 @@ HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_devic struct wined3d_sampler_desc wined3d_desc; HRESULT hr; + state->ID3D11SamplerState_iface.lpVtbl = &d3d11_sampler_state_vtbl; state->ID3D10SamplerState_iface.lpVtbl = &d3d10_sampler_state_vtbl; state->refcount = 1; wined3d_mutex_lock(); @@ -1079,8 +1188,8 @@ HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_devic } wined3d_mutex_unlock(); - state->device = &device->ID3D10Device1_iface; - ID3D10Device1_AddRef(state->device); + state->device = &device->ID3D11Device_iface; + ID3D11Device_AddRef(state->device); return S_OK; }