Commit 80a35fb4 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dinput: Always allocate and initialize the object_properties.

parent f2094069
......@@ -1077,18 +1077,12 @@ struct get_object_property_params
static BOOL get_object_property( struct dinput_device *device, UINT index, struct hid_value_caps *caps,
const DIDEVICEOBJECTINSTANCEW *instance, void *data )
{
static const struct object_properties default_properties =
{
.range_min = DIPROPRANGE_NOMIN,
.range_max = DIPROPRANGE_NOMAX,
.granularity = 1,
};
struct get_object_property_params *params = data;
struct dinput_device *impl = impl_from_IDirectInputDevice8W( params->iface );
const struct object_properties *properties = NULL;
const struct object_properties *properties;
if (!impl->object_properties) properties = &default_properties;
else properties = impl->object_properties + instance->dwOfs / sizeof(LONG);
if (index == -1) return DIENUM_STOP;
properties = impl->object_properties + index;
switch (params->property)
{
......@@ -1257,10 +1251,10 @@ static BOOL set_object_property( struct dinput_device *device, UINT index, struc
{
struct set_object_property_params *params = data;
struct dinput_device *impl = impl_from_IDirectInputDevice8W( params->iface );
struct object_properties *properties = NULL;
struct object_properties *properties;
if (!impl->object_properties) return DIENUM_STOP;
properties = impl->object_properties + instance->dwOfs / sizeof(LONG);
if (index == -1) return DIENUM_STOP;
properties = impl->object_properties + index;
switch (params->property)
{
......@@ -1300,13 +1294,15 @@ static BOOL reset_object_value( struct dinput_device *impl, UINT index, struct h
struct object_properties *properties;
LONG tmp = -1;
if (!impl->object_properties) return DIENUM_STOP;
properties = impl->object_properties + instance->dwOfs / sizeof(LONG);
if (index == -1) return DIENUM_STOP;
properties = impl->object_properties + index;
if (instance->dwType & DIDFT_AXIS)
{
if (!properties->range_min) tmp = properties->range_max / 2;
else tmp = round( (properties->range_min + properties->range_max) / 2.0 );
LONG range_min = 0, range_max = 0xfffe;
if (properties->range_min != DIPROPRANGE_NOMIN) range_min = properties->range_min;
if (properties->range_max != DIPROPRANGE_NOMAX) range_max = properties->range_max;
tmp = round( (range_min + range_max) / 2.0 );
}
*(LONG *)(impl->device_state + instance->dwOfs) = tmp;
......@@ -2211,6 +2207,12 @@ static BOOL enum_objects_count( struct dinput_device *impl, UINT index, struct h
static BOOL enum_objects_init( struct dinput_device *impl, UINT index, struct hid_value_caps *caps,
const DIDEVICEOBJECTINSTANCEW *instance, void *data )
{
static const struct object_properties default_properties =
{
.range_min = DIPROPRANGE_NOMIN,
.range_max = DIPROPRANGE_NOMAX,
.granularity = 1,
};
DIDATAFORMAT *format = &impl->device_format;
DIOBJECTDATAFORMAT *object_format;
......@@ -2223,8 +2225,8 @@ static BOOL enum_objects_init( struct dinput_device *impl, UINT index, struct hi
object_format->dwType = instance->dwType;
object_format->dwFlags = instance->dwFlags;
if (impl->object_properties && (instance->dwType & (DIDFT_AXIS | DIDFT_POV)))
reset_object_value( impl, index, caps, instance, NULL );
impl->object_properties[index] = default_properties;
if (instance->dwType & (DIDFT_AXIS | DIDFT_POV)) reset_object_value( impl, index, caps, instance, NULL );
return DIENUM_CONTINUE;
}
......@@ -2239,8 +2241,8 @@ HRESULT dinput_device_init_device_format( IDirectInputDevice8W *iface )
};
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
DIDATAFORMAT *format = &impl->device_format;
ULONG i, size;
HRESULT hr;
ULONG i;
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_ALL, enum_objects_count, NULL );
if (FAILED(hr)) return hr;
......@@ -2251,8 +2253,8 @@ HRESULT dinput_device_init_device_format( IDirectInputDevice8W *iface )
return DIERR_OUTOFMEMORY;
}
size = format->dwNumObjs * sizeof(*format->rgodf);
if (!(format->rgodf = calloc( 1, size ))) return DIERR_OUTOFMEMORY;
if (!(impl->object_properties = calloc( format->dwNumObjs, sizeof(*impl->object_properties) ))) return DIERR_OUTOFMEMORY;
if (!(format->rgodf = calloc( format->dwNumObjs, sizeof(*format->rgodf) ))) return DIERR_OUTOFMEMORY;
format->dwSize = sizeof(*format);
format->dwObjSize = sizeof(*format->rgodf);
......
......@@ -1176,14 +1176,17 @@ static BOOL read_device_state_value( struct dinput_device *device, UINT index, s
const DIDEVICEOBJECTINSTANCEW *instance, void *data )
{
struct hid_joystick *impl = CONTAINING_RECORD( device, struct hid_joystick, base );
struct object_properties *properties = impl->base.object_properties + instance->dwOfs / sizeof(LONG);
IDirectInputDevice8W *iface = &impl->base.IDirectInputDevice8W_iface;
ULONG logical_value, report_len = impl->caps.InputReportByteLength;
struct parse_device_state_params *params = data;
char *report_buf = impl->input_report_buf;
struct object_properties *properties;
LONG old_value, value;
NTSTATUS status;
if (index == -1) return DIENUM_STOP;
properties = device->object_properties + index;
if (instance->wReportId != impl->base.device_state_report_id) return DIENUM_CONTINUE;
status = HidP_GetUsageValue( HidP_Input, instance->wUsagePage, 0, instance->wUsage,
......@@ -1645,14 +1648,19 @@ HRESULT hid_joystick_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *in
static BOOL init_object_properties( struct dinput_device *device, UINT index, struct hid_value_caps *caps,
const DIDEVICEOBJECTINSTANCEW *instance, void *data )
{
struct object_properties *properties = device->object_properties + instance->dwOfs / sizeof(LONG);
struct object_properties *properties;
LONG tmp;
if (index == -1) return DIENUM_STOP;
properties = device->object_properties + index;
properties->bit_size = caps->bit_size;
properties->physical_min = caps->physical_min;
properties->physical_max = caps->physical_max;
properties->logical_min = caps->logical_min;
properties->logical_max = caps->logical_max;
properties->range_min = 0;
properties->range_max = 0;
if (instance->dwType & DIDFT_AXIS) properties->range_max = 65535;
else
......@@ -1988,8 +1996,6 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi
},
};
HIDD_ATTRIBUTES attrs = {.Size = sizeof(attrs)};
struct object_properties *object_properties;
struct hid_preparsed_data *preparsed;
struct hid_joystick *impl = NULL;
USAGE_AND_PAGE *usages;
char *buffer;
......@@ -2081,13 +2087,8 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi
impl->base.caps.dwFFDriverVersion = 1;
}
preparsed = (struct hid_preparsed_data *)impl->preparsed;
size = preparsed->input_caps_count * sizeof(struct object_properties);
if (!(object_properties = calloc( 1, size ))) goto failed;
impl->base.object_properties = object_properties;
enum_objects( impl, &filter, DIDFT_AXIS | DIDFT_POV, init_object_properties, NULL );
if (FAILED(hr = dinput_device_init_device_format( &impl->base.IDirectInputDevice8W_iface ))) goto failed;
enum_objects( impl, &filter, DIDFT_AXIS | DIDFT_POV, init_object_properties, NULL );
*out = &impl->base.IDirectInputDevice8W_iface;
return DI_OK;
......
......@@ -85,20 +85,16 @@ HRESULT mouse_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance,
return DI_OK;
}
static BOOL CALLBACK init_object_properties( const DIDEVICEOBJECTINSTANCEW *instance, void *data )
static BOOL init_object_properties( struct dinput_device *device, UINT index, struct hid_value_caps *caps,
const DIDEVICEOBJECTINSTANCEW *instance, void *data )
{
struct mouse *impl = (struct mouse *)data;
struct object_properties *properties = impl->base.object_properties + instance->dwOfs / sizeof(LONG);
struct object_properties *properties;
properties->range_min = DIPROPRANGE_NOMIN;
properties->range_max = DIPROPRANGE_NOMAX;
if (index == -1) return DIENUM_STOP;
properties = device->object_properties + index;
/* The z-axis (wheel) has a different granularity */
if (instance->dwOfs == DIMOFS_Z)
properties->granularity = WHEEL_DELTA;
else
properties->granularity = 1;
if (instance->dwOfs == DIMOFS_Z) properties->granularity = WHEEL_DELTA;
return DIENUM_CONTINUE;
}
......@@ -510,6 +506,12 @@ static HRESULT mouse_enum_objects( IDirectInputDevice8W *iface, const DIPROPHEAD
HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInputDevice8W **out )
{
static const DIPROPHEADER filter =
{
.dwSize = sizeof(filter),
.dwHeaderSize = sizeof(filter),
.dwHow = DIPH_DEVICE,
};
struct mouse *impl;
HKEY hkey, appkey;
WCHAR buffer[20];
......@@ -531,16 +533,8 @@ HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInp
impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
if (dinput->dwVersion >= 0x0800) impl->base.use_raw_input = TRUE;
/* One object_properties per axis */
impl->base.object_properties = calloc( 3, sizeof(struct object_properties) );
if (!impl->base.object_properties)
{
IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface );
return E_OUTOFMEMORY;
}
IDirectInputDevice8_EnumObjects( &impl->base.IDirectInputDevice8W_iface, init_object_properties, impl, DIDFT_RELAXIS );
if (FAILED(hr = dinput_device_init_device_format( &impl->base.IDirectInputDevice8W_iface ))) goto failed;
mouse_enum_objects( &impl->base.IDirectInputDevice8W_iface, &filter, DIDFT_AXIS, init_object_properties, NULL );
get_app_key(&hkey, &appkey);
if (!get_config_key( hkey, appkey, L"MouseWarpOverride", buffer, sizeof(buffer) ))
......
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