From 8847de46ecdd9b602875006e33a926e544c9ecf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Thu, 28 Oct 2021 10:12:32 +0200 Subject: [PATCH] dinput: Move user data format to struct dinput_device. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RĂ©mi Bernon Signed-off-by: Alexandre Julliard --- dlls/dinput/device.c | 45 ++++++++++++++++++------------------ dlls/dinput/device_private.h | 2 +- dlls/dinput/mouse.c | 6 ++--- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 5b96002ea4a..52a6e14ab8d 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -400,16 +400,14 @@ static void fill_DataFormat( void *out, DWORD size, const void *in, const DataFo } } -static void release_DataFormat( DataFormat *format ) +static void dinput_device_release_user_format( struct dinput_device *impl ) { - TRACE("Deleting DataFormat: %p\n", format); - - free( format->dt ); - format->dt = NULL; - free( format->offsets ); - format->offsets = NULL; - free( format->user_df ); - format->user_df = NULL; + free( impl->data_format.dt ); + impl->data_format.dt = NULL; + free( impl->data_format.offsets ); + impl->data_format.offsets = NULL; + free( impl->user_format ); + impl->user_format = NULL; } static inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx) @@ -441,8 +439,9 @@ LPDIOBJECTDATAFORMAT dataformat_to_odf_by_type(LPCDIDATAFORMAT df, int n, DWORD return NULL; } -static HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *format) +static HRESULT dinput_device_init_user_format( struct dinput_device *impl, const DIDATAFORMAT *asked_format ) { + DataFormat *format = &impl->data_format; DataTransform *dt; unsigned int i, j; int same = 1; @@ -456,8 +455,8 @@ static HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *forma if (!dt || !done) goto failed; if (!(format->offsets = malloc( format->wine_df->dwNumObjs * sizeof(int) ))) goto failed; - if (!(format->user_df = malloc( asked_format->dwSize ))) goto failed; - memcpy(format->user_df, asked_format, asked_format->dwSize); + if (!(impl->user_format = malloc( asked_format->dwSize ))) goto failed; + memcpy( impl->user_format, asked_format, asked_format->dwSize ); TRACE("Creating DataTransform :\n"); @@ -575,8 +574,8 @@ failed: format->dt = NULL; free( format->offsets ); format->offsets = NULL; - free( format->user_df ); - format->user_df = NULL; + free( impl->user_format ); + impl->user_format = NULL; return DIERR_OUTOFMEMORY; } @@ -863,7 +862,7 @@ static HRESULT WINAPI dinput_device_Acquire( IDirectInputDevice8W *iface ) EnterCriticalSection( &impl->crit ); if (impl->acquired) hr = DI_NOEFFECT; - else if (!impl->data_format.user_df) + else if (!impl->user_format) hr = DIERR_INVALIDPARAM; else if ((impl->dwCoopLevel & DISCL_FOREGROUND) && impl->win != GetForegroundWindow()) hr = DIERR_OTHERAPPHASPRIO; @@ -934,8 +933,8 @@ static HRESULT WINAPI dinput_device_SetDataFormat( IDirectInputDevice8W *iface, This->action_map = NULL; This->num_actions = 0; - release_DataFormat(&This->data_format); - res = create_DataFormat( format, &This->data_format ); + dinput_device_release_user_format( This ); + res = dinput_device_init_user_format( This, format ); LeaveCriticalSection(&This->crit); return res; @@ -1036,7 +1035,7 @@ void dinput_device_destroy( IDirectInputDevice8W *iface ) /* Free data format */ free( This->data_format.wine_df->rgodf ); free( This->data_format.wine_df ); - release_DataFormat(&This->data_format); + dinput_device_release_user_format( This ); /* Free action mapping */ free( This->action_map ); @@ -1387,11 +1386,11 @@ static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, co TRACE( "Axis mode: %s\n", value->dwData == DIPROPAXISMODE_ABS ? "absolute" : "relative" ); EnterCriticalSection( &impl->crit ); if (impl->acquired) hr = DIERR_ACQUIRED; - else if (!impl->data_format.user_df) hr = DI_OK; + else if (!impl->user_format) hr = DI_OK; else { - impl->data_format.user_df->dwFlags &= ~DIDFT_AXIS; - impl->data_format.user_df->dwFlags |= value->dwData == DIPROPAXISMODE_ABS ? DIDF_ABSAXIS : DIDF_RELAXIS; + impl->user_format->dwFlags &= ~DIDFT_AXIS; + impl->user_format->dwFlags |= value->dwData == DIPROPAXISMODE_ABS ? DIDF_ABSAXIS : DIDF_RELAXIS; hr = DI_OK; } LeaveCriticalSection( &impl->crit ); @@ -1531,12 +1530,12 @@ static HRESULT WINAPI dinput_device_GetDeviceState( IDirectInputDevice8W *iface, EnterCriticalSection( &impl->crit ); if (!impl->acquired) hr = DIERR_NOTACQUIRED; - else if (size != impl->data_format.user_df->dwDataSize) + else if (size != impl->user_format->dwDataSize) hr = DIERR_INVALIDPARAM; else { fill_DataFormat( data, size, impl->device_state, &impl->data_format ); - if (!(impl->data_format.user_df->dwFlags & DIDF_ABSAXIS)) + if (!(impl->user_format->dwFlags & DIDF_ABSAXIS)) impl->vtbl->enum_objects( iface, &filter, DIDFT_RELAXIS, reset_axis_data, impl->device_state ); hr = DI_OK; } diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 7ee0ef312c0..4420f59cc6d 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -44,7 +44,6 @@ typedef struct int *offsets; /* object offsets */ LPDIDATAFORMAT wine_df; /* wine internal data format */ - LPDIDATAFORMAT user_df; /* user defined data format */ } DataFormat; typedef struct @@ -103,6 +102,7 @@ struct dinput_device DWORD buffersize; /* size of the queue - set in 'SetProperty' */ DataFormat data_format; /* user data format and wine to user format converter */ + DIDATAFORMAT *user_format; /* Action mapping */ int num_actions; /* number of actions mapped */ diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 4e1762fbc50..628011c13e1 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -189,7 +189,7 @@ void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPA state->lX += rel.x; state->lY += rel.y; - if (impl->base.data_format.user_df->dwFlags & DIDF_ABSAXIS) + if (impl->base.user_format->dwFlags & DIDF_ABSAXIS) { pt.x = state->lX; pt.y = state->lY; @@ -269,7 +269,7 @@ int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam state->lX += pt.x = hook->pt.x - pt.x; state->lY += pt.y = hook->pt.y - pt.y; - if (impl->base.data_format.user_df->dwFlags & DIDF_ABSAXIS) + if (impl->base.user_format->dwFlags & DIDF_ABSAXIS) { pt1.x = state->lX; pt1.y = state->lY; @@ -409,7 +409,7 @@ static HRESULT mouse_acquire( IDirectInputDevice8W *iface ) /* Init the mouse state */ GetCursorPos( &point ); - if (impl->base.data_format.user_df->dwFlags & DIDF_ABSAXIS) + if (impl->base.user_format->dwFlags & DIDF_ABSAXIS) { state->lX = point.x; state->lY = point.y;