[PATCH 4/5] dinput: Factor all GetDeviceState implementations together.
Rémi Bernon
rbernon at codeweavers.com
Wed Oct 20 03:41:09 CDT 2021
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/dinput/device.c | 35 +++++++++++++++++++++++++++++++++++
dlls/dinput/device_private.h | 1 +
dlls/dinput/joystick_hid.c | 18 +-----------------
dlls/dinput/keyboard.c | 31 +------------------------------
dlls/dinput/mouse.c | 35 +----------------------------------
5 files changed, 39 insertions(+), 81 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index c31166b8248..7845e992b2a 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -1522,6 +1522,41 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo( IDirectInputDevice8W *ifa
return DI_OK;
}
+static BOOL CALLBACK reset_axis_data( const DIDEVICEOBJECTINSTANCEW *instance, void *data )
+{
+ *(ULONG *)((char *)data + instance->dwOfs) = 0;
+ return DIENUM_CONTINUE;
+}
+
+HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceState( IDirectInputDevice8W *iface, DWORD size, void *data )
+{
+ IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface );
+ DIPROPHEADER filter =
+ {
+ .dwSize = sizeof(filter),
+ .dwHeaderSize = sizeof(filter),
+ .dwHow = DIPH_DEVICE,
+ .dwObj = 0,
+ };
+ HRESULT hr = DI_OK;
+
+ TRACE( "iface %p, size %u, data %p.\n", iface, size, data );
+
+ if (!data) return DIERR_INVALIDPARAM;
+ if (size != impl->data_format.user_df->dwDataSize) return DIERR_INVALIDPARAM;
+
+ IDirectInputDevice2_Poll( iface );
+
+ EnterCriticalSection( &impl->crit );
+ if (!impl->acquired) hr = DIERR_NOTACQUIRED;
+ else fill_DataFormat( data, size, impl->device_state, &impl->data_format );
+ if (!(impl->data_format.user_df->dwFlags & DIDF_ABSAXIS))
+ impl->vtbl->enum_objects( iface, &filter, DIDFT_RELAXIS, reset_axis_data, impl->device_state );
+ LeaveCriticalSection( &impl->crit );
+
+ return hr;
+}
+
HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD dodsize,
LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
{
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h
index 92b0320520b..d918403ef67 100644
--- a/dlls/dinput/device_private.h
+++ b/dlls/dinput/device_private.h
@@ -157,6 +157,7 @@ extern HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(LPDIRECTINPUTDEVICE
LPDIDEVICEOBJECTINSTANCEW pdidoi,
DWORD dwObj,
DWORD dwHow) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceState( IDirectInputDevice8W *iface, DWORD len, void *ptr );
extern HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
LPDWORD entries, DWORD flags) DECLSPEC_HIDDEN;
extern HRESULT WINAPI IDirectInputDevice2WImpl_RunControlPanel(LPDIRECTINPUTDEVICE8W iface, HWND hwndOwner, DWORD dwFlags) DECLSPEC_HIDDEN;
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c
index 798243d85fc..6dc44c5731e 100644
--- a/dlls/dinput/joystick_hid.c
+++ b/dlls/dinput/joystick_hid.c
@@ -818,22 +818,6 @@ static HRESULT hid_joystick_internal_unacquire( IDirectInputDevice8W *iface )
return DI_OK;
}
-static HRESULT WINAPI hid_joystick_GetDeviceState( IDirectInputDevice8W *iface, DWORD len, void *ptr )
-{
- struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface );
- HRESULT hr = DI_OK;
-
- if (!ptr) return DIERR_INVALIDPARAM;
- if (len != impl->base.data_format.user_df->dwDataSize) return DIERR_INVALIDPARAM;
-
- EnterCriticalSection( &impl->base.crit );
- if (!impl->base.acquired) hr = DIERR_NOTACQUIRED;
- else fill_DataFormat( ptr, len, impl->base.device_state, &impl->base.data_format );
- LeaveCriticalSection( &impl->base.crit );
-
- return hr;
-}
-
static HRESULT hid_joystick_effect_create( struct hid_joystick *joystick, IDirectInputEffect **out );
static HRESULT WINAPI hid_joystick_CreateEffect( IDirectInputDevice8W *iface, const GUID *guid,
@@ -1175,7 +1159,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl =
IDirectInputDevice2WImpl_SetProperty,
IDirectInputDevice2WImpl_Acquire,
IDirectInputDevice2WImpl_Unacquire,
- hid_joystick_GetDeviceState,
+ IDirectInputDevice2WImpl_GetDeviceState,
IDirectInputDevice2WImpl_GetDeviceData,
IDirectInputDevice2WImpl_SetDataFormat,
IDirectInputDevice2WImpl_SetEventNotification,
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index a8f831e7597..75a2079f5fe 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -241,35 +241,6 @@ const struct dinput_device keyboard_device = {
keyboarddev_create_device
};
-static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr)
-{
- SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
- DWORD i;
-
- TRACE("(%p)->(%d,%p)\n", This, len, ptr);
-
- if (!This->base.acquired) return DIERR_NOTACQUIRED;
-
- if (len != This->base.data_format.user_df->dwDataSize )
- return DIERR_INVALIDPARAM;
-
- check_dinput_events();
-
- EnterCriticalSection(&This->base.crit);
-
- if (TRACE_ON(dinput))
- {
- TRACE( "pressed keys:" );
- for (i = 0; i < len; i++) if (This->base.device_state[i]) TRACE( " %02x", i );
- TRACE( "\n" );
- }
-
- fill_DataFormat( ptr, len, This->base.device_state, &This->base.data_format );
- LeaveCriticalSection(&This->base.crit);
-
- return DI_OK;
-}
-
static HRESULT keyboard_internal_poll( IDirectInputDevice8W *iface )
{
check_dinput_events();
@@ -379,7 +350,7 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt =
IDirectInputDevice2WImpl_SetProperty,
IDirectInputDevice2WImpl_Acquire,
IDirectInputDevice2WImpl_Unacquire,
- SysKeyboardWImpl_GetDeviceState,
+ IDirectInputDevice2WImpl_GetDeviceState,
IDirectInputDevice2WImpl_GetDeviceData,
IDirectInputDevice2WImpl_SetDataFormat,
IDirectInputDevice2WImpl_SetEventNotification,
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index 7b8402b2bf5..69feb259d60 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -442,39 +442,6 @@ static void warp_check( SysMouseImpl* This, BOOL force )
}
}
-/******************************************************************************
- * GetDeviceState : returns the "state" of the mouse.
- *
- * For the moment, only the "standard" return structure (DIMOUSESTATE) is
- * supported.
- */
-static HRESULT WINAPI SysMouseWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr)
-{
- SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
- DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)This->base.device_state;
- TRACE("(%p)->(%u,%p)\n", This, len, ptr);
-
- if(This->base.acquired == 0) return DIERR_NOTACQUIRED;
-
- check_dinput_events();
-
- EnterCriticalSection(&This->base.crit);
-
- /* Copy the current mouse state */
- fill_DataFormat( ptr, len, state, &This->base.data_format );
-
- /* Initialize the buffer when in relative mode */
- if (!(This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS))
- {
- state->lX = 0;
- state->lY = 0;
- state->lZ = 0;
- }
- LeaveCriticalSection(&This->base.crit);
-
- return DI_OK;
-}
-
static HRESULT mouse_internal_poll( IDirectInputDevice8W *iface )
{
SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface );
@@ -696,7 +663,7 @@ static const IDirectInputDevice8WVtbl SysMouseWvt =
IDirectInputDevice2WImpl_SetProperty,
IDirectInputDevice2WImpl_Acquire,
IDirectInputDevice2WImpl_Unacquire,
- SysMouseWImpl_GetDeviceState,
+ IDirectInputDevice2WImpl_GetDeviceState,
IDirectInputDevice2WImpl_GetDeviceData,
IDirectInputDevice2WImpl_SetDataFormat,
IDirectInputDevice2WImpl_SetEventNotification,
--
2.33.0
More information about the wine-devel
mailing list