[PATCH 7/8] d3d11: Introduce d3d_sampler_state_create() helper function.
Józef Kucia
jkucia at codeweavers.com
Thu Jul 20 07:11:03 CDT 2017
Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
dlls/d3d11/d3d11_private.h | 4 ++--
dlls/d3d11/device.c | 50 ++++++-------------------------------------
dlls/d3d11/state.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 60 insertions(+), 47 deletions(-)
diff --git a/dlls/d3d11/d3d11_private.h b/dlls/d3d11/d3d11_private.h
index b2cb29f5f9..4d9f34ea42 100644
--- a/dlls/d3d11/d3d11_private.h
+++ b/dlls/d3d11/d3d11_private.h
@@ -465,8 +465,8 @@ struct d3d_sampler_state
ID3D11Device *device;
};
-HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_device *device,
- const D3D11_SAMPLER_DESC *desc) DECLSPEC_HIDDEN;
+HRESULT d3d_sampler_state_create(struct d3d_device *device, const D3D11_SAMPLER_DESC *desc,
+ struct d3d_sampler_state **state) DECLSPEC_HIDDEN;
struct d3d_sampler_state *unsafe_impl_from_ID3D11SamplerState(ID3D11SamplerState *iface) DECLSPEC_HIDDEN;
struct d3d_sampler_state *unsafe_impl_from_ID3D10SamplerState(ID3D10SamplerState *iface) DECLSPEC_HIDDEN;
diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index b756517b38..14e21f9280 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -3051,51 +3051,14 @@ static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *i
const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
{
struct d3d_device *device = impl_from_ID3D11Device(iface);
- D3D11_SAMPLER_DESC normalized_desc;
struct d3d_sampler_state *object;
- struct wine_rb_entry *entry;
HRESULT hr;
TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
- if (!desc)
- return E_INVALIDARG;
-
- normalized_desc = *desc;
- if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(normalized_desc.Filter))
- normalized_desc.MaxAnisotropy = 0;
- if (!D3D11_DECODE_IS_COMPARISON_FILTER(normalized_desc.Filter))
- normalized_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
- if (normalized_desc.AddressU != D3D11_TEXTURE_ADDRESS_BORDER
- && normalized_desc.AddressV != D3D11_TEXTURE_ADDRESS_BORDER
- && normalized_desc.AddressW != D3D11_TEXTURE_ADDRESS_BORDER)
- memset(&normalized_desc.BorderColor, 0, sizeof(normalized_desc.BorderColor));
-
- wined3d_mutex_lock();
- if ((entry = wine_rb_get(&device->sampler_states, &normalized_desc)))
- {
- object = WINE_RB_ENTRY_VALUE(entry, struct d3d_sampler_state, entry);
-
- TRACE("Returning existing sampler state %p.\n", object);
- *sampler_state = &object->ID3D11SamplerState_iface;
- ID3D11SamplerState_AddRef(*sampler_state);
- wined3d_mutex_unlock();
-
- return S_OK;
- }
- wined3d_mutex_unlock();
-
- if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
- return E_OUTOFMEMORY;
-
- if (FAILED(hr = d3d_sampler_state_init(object, device, &normalized_desc)))
- {
- WARN("Failed to initialize sampler state, hr %#x.\n", hr);
- HeapFree(GetProcessHeap(), 0, object);
+ if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
return hr;
- }
- TRACE("Created sampler state %p.\n", object);
*sampler_state = &object->ID3D11SamplerState_iface;
return S_OK;
@@ -5330,18 +5293,17 @@ static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *
const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
{
struct d3d_device *device = impl_from_ID3D10Device(iface);
- ID3D11SamplerState *d3d11_sampler_state;
+ struct d3d_sampler_state *object;
HRESULT hr;
TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
- if (FAILED(hr = d3d11_device_CreateSamplerState(&device->ID3D11Device_iface,
- (const D3D11_SAMPLER_DESC *)desc, &d3d11_sampler_state)))
+ if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
return hr;
- hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState, (void **)sampler_state);
- ID3D11SamplerState_Release(d3d11_sampler_state);
- return hr;
+ *sampler_state = &object->ID3D10SamplerState_iface;
+
+ return S_OK;
}
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
diff --git a/dlls/d3d11/state.c b/dlls/d3d11/state.c
index 87fed6f822..64fae134e7 100644
--- a/dlls/d3d11/state.c
+++ b/dlls/d3d11/state.c
@@ -1432,7 +1432,7 @@ static enum wined3d_cmp_func wined3d_cmp_func_from_d3d11(D3D11_COMPARISON_FUNC f
return (enum wined3d_cmp_func)f;
}
-HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_device *device,
+static HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_device *device,
const D3D11_SAMPLER_DESC *desc)
{
struct wined3d_sampler_desc wined3d_desc;
@@ -1488,6 +1488,57 @@ HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_devic
return S_OK;
}
+HRESULT d3d_sampler_state_create(struct d3d_device *device, const D3D11_SAMPLER_DESC *desc,
+ struct d3d_sampler_state **state)
+{
+ D3D11_SAMPLER_DESC normalized_desc;
+ struct d3d_sampler_state *object;
+ struct wine_rb_entry *entry;
+ HRESULT hr;
+
+ if (!desc)
+ return E_INVALIDARG;
+
+ normalized_desc = *desc;
+ if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(normalized_desc.Filter))
+ normalized_desc.MaxAnisotropy = 0;
+ if (!D3D11_DECODE_IS_COMPARISON_FILTER(normalized_desc.Filter))
+ normalized_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
+ if (normalized_desc.AddressU != D3D11_TEXTURE_ADDRESS_BORDER
+ && normalized_desc.AddressV != D3D11_TEXTURE_ADDRESS_BORDER
+ && normalized_desc.AddressW != D3D11_TEXTURE_ADDRESS_BORDER)
+ memset(&normalized_desc.BorderColor, 0, sizeof(normalized_desc.BorderColor));
+
+ wined3d_mutex_lock();
+ if ((entry = wine_rb_get(&device->sampler_states, &normalized_desc)))
+ {
+ object = WINE_RB_ENTRY_VALUE(entry, struct d3d_sampler_state, entry);
+
+ TRACE("Returning existing sampler state %p.\n", object);
+ ID3D11SamplerState_AddRef(&object->ID3D11SamplerState_iface);
+ *state = object;
+ wined3d_mutex_unlock();
+
+ return S_OK;
+ }
+ wined3d_mutex_unlock();
+
+ if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+ return E_OUTOFMEMORY;
+
+ if (FAILED(hr = d3d_sampler_state_init(object, device, &normalized_desc)))
+ {
+ WARN("Failed to initialize sampler state, hr %#x.\n", hr);
+ HeapFree(GetProcessHeap(), 0, object);
+ return hr;
+ }
+
+ TRACE("Created sampler state %p.\n", object);
+ *state = object;
+
+ return S_OK;
+}
+
struct d3d_sampler_state *unsafe_impl_from_ID3D11SamplerState(ID3D11SamplerState *iface)
{
if (!iface)
--
2.13.0
More information about the wine-patches
mailing list