Commit 8d791496 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dinput: Introduce direct_input_device_alloc helper.

To factor out device allocation and initialization. Signed-off-by: 's avatarRémi Bernon <rbernon@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent ad8e3727
......@@ -1703,3 +1703,23 @@ HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface
return DI_OK;
}
HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8WVtbl *vtblw,
const IDirectInputDevice8AVtbl *vtbla, const GUID *guid,
IDirectInputImpl *dinput, void **out )
{
IDirectInputDeviceImpl *This;
if (!(This = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ))) return DIERR_OUTOFMEMORY;
This->IDirectInputDevice8A_iface.lpVtbl = vtbla;
This->IDirectInputDevice8W_iface.lpVtbl = vtblw;
This->ref = 1;
This->guid = *guid;
InitializeCriticalSection( &This->crit );
This->dinput = dinput;
IDirectInput_AddRef( &dinput->IDirectInput7A_iface );
*out = This;
return DI_OK;
}
......@@ -86,6 +86,10 @@ struct IDirectInputDeviceImpl
ActionMap *action_map; /* array of mappings */
};
extern HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8WVtbl *vtblw,
const IDirectInputDevice8AVtbl *vtbla, const GUID *guid,
IDirectInputImpl *dinput, void **out ) DECLSPEC_HIDDEN;
extern BOOL get_app_key(HKEY*, HKEY*) DECLSPEC_HIDDEN;
extern DWORD get_config_key(HKEY, HKEY, const char*, char*, DWORD) DECLSPEC_HIDDEN;
......
......@@ -462,8 +462,9 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
TRACE( "%s %p %p %hu\n", debugstr_guid( rguid ), dinput, out, index );
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
if (!newDevice) return DIERR_OUTOFMEMORY;
if (FAILED(hr = direct_input_device_alloc( sizeof(JoystickImpl), &JoystickWvt, &JoystickAvt, rguid, dinput, (void **)&newDevice )))
return hr;
newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
newDevice->joydev = &joystick_devices[index];
newDevice->joyfd = -1;
......@@ -481,14 +482,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
newDevice->generic.devcaps.dwButtons = 128;
}
newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt;
newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt;
newDevice->generic.base.ref = 1;
newDevice->generic.base.dinput = dinput;
newDevice->generic.base.guid = *rguid;
InitializeCriticalSection(&newDevice->generic.base.crit);
newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
/* setup_dinput_options may change these */
newDevice->generic.deadzone = 0;
......@@ -537,8 +530,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
newDevice->generic.props[i].lSaturation = 0;
}
IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface);
newDevice->generic.devcaps.dwSize = sizeof(newDevice->generic.devcaps);
newDevice->generic.devcaps.dwFlags = DIDC_ATTACHED;
......
......@@ -451,15 +451,12 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
int i, idx = 0;
int default_axis_map[WINE_JOYSTICK_MAX_AXES + WINE_JOYSTICK_MAX_POVS*2];
DIDEVICEINSTANCEW ddi;
HRESULT hr;
newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl));
if (!newDevice) return DIERR_OUTOFMEMORY;
if (FAILED(hr = direct_input_device_alloc( sizeof(JoystickImpl), &JoystickWvt, &JoystickAvt, rguid, dinput, (void **)&newDevice )))
return hr;
newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt;
newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt;
newDevice->generic.base.ref = 1;
newDevice->generic.base.guid = *rguid;
newDevice->generic.base.dinput = dinput;
newDevice->generic.joy_polldev = joy_polldev;
newDevice->joyfd = -1;
newDevice->joydev = &joydevs[index];
......@@ -473,8 +470,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
enabled. */
newDevice->ff_autocenter = 1;
newDevice->ff_gain = 0xFFFF;
InitializeCriticalSection(&newDevice->generic.base.crit);
newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
/* Count number of available axes - supported Axis & POVs */
for (i = 0; i < ABS_MAX; i++)
......@@ -582,8 +577,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
if (newDevice->joydev->has_ff)
newDevice->generic.devcaps.dwFlags |= DIDC_FORCEFEEDBACK;
IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface);
*out = newDevice;
return DI_OK;
......
......@@ -1120,8 +1120,9 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
TRACE( "%s %p %p %hu\n", debugstr_guid( rguid ), dinput, out, index );
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
if (!newDevice) return DIERR_OUTOFMEMORY;
if (FAILED(hr = direct_input_device_alloc( sizeof(JoystickImpl), &JoystickWvt, &JoystickAvt, rguid, dinput, (void **)&newDevice )))
return hr;
newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
newDevice->id = index;
......@@ -1183,14 +1184,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
newDevice->generic.devcaps.dwButtons = 128;
}
newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt;
newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt;
newDevice->generic.base.ref = 1;
newDevice->generic.base.dinput = dinput;
newDevice->generic.base.guid = *rguid;
InitializeCriticalSection(&newDevice->generic.base.crit);
newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
/* Create copy of default data format */
if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED;
memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
......@@ -1262,8 +1255,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
/* initialize default properties */
get_osx_device_elements_props(newDevice);
IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface);
newDevice->generic.devcaps.dwSize = sizeof(newDevice->generic.devcaps);
newDevice->generic.devcaps.dwFlags |= DIDC_ATTACHED;
if (newDevice->generic.base.dinput->dwVersion >= 0x0800)
......
......@@ -245,17 +245,12 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboar
SysKeyboardImpl* newDevice;
LPDIDATAFORMAT df = NULL;
int i, idx = 0;
HRESULT hr;
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboardImpl));
if (!newDevice) return DIERR_OUTOFMEMORY;
newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysKeyboardAvt;
newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysKeyboardWvt;
newDevice->base.ref = 1;
memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
newDevice->base.dinput = dinput;
InitializeCriticalSection(&newDevice->base.crit);
if (FAILED(hr = direct_input_device_alloc( sizeof(SysKeyboardImpl), &SysKeyboardWvt, &SysKeyboardAvt, rguid, dinput, (void **)&newDevice )))
return hr;
newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysKeyboardImpl*->base.crit");
newDevice->subtype = get_keyboard_subtype();
/* Create copy of default data format */
......@@ -278,7 +273,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboar
df->dwNumObjs = idx;
newDevice->base.data_format.wine_df = df;
IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface);
*out = newDevice;
return DI_OK;
......
......@@ -191,18 +191,13 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseIm
unsigned i;
char buffer[20];
HKEY hkey, appkey;
HRESULT hr;
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl));
if (!newDevice) return DIERR_OUTOFMEMORY;
if (FAILED(hr = direct_input_device_alloc( sizeof(SysMouseImpl), &SysMouseWvt, &SysMouseAvt, rguid, dinput, (void **)&newDevice )))
return hr;
newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysMouseAvt;
newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysMouseWvt;
newDevice->base.ref = 1;
newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
newDevice->base.guid = *rguid;
InitializeCriticalSection(&newDevice->base.crit);
newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
newDevice->base.dinput = dinput;
get_app_key(&hkey, &appkey);
if (!get_config_key(hkey, appkey, "MouseWarpOverride", buffer, sizeof(buffer)))
......@@ -229,8 +224,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseIm
df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
newDevice->base.data_format.wine_df = df;
IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface);
if (dinput->dwVersion >= 0x0800)
{
newDevice->base.use_raw_input = TRUE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment