hidclass.sys: Move build_preparsed_data before parse_descriptor.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-08-09 10:32:42 +02:00 committed by Alexandre Julliard
parent 9ef00c9353
commit e15916cf1d
1 changed files with 58 additions and 58 deletions

View File

@ -391,6 +391,64 @@ static void free_parser_state( struct hid_parser_state *state )
free( state );
}
static WINE_HIDP_PREPARSED_DATA *build_preparsed_data( struct hid_parser_state *state )
{
WINE_HIDP_PREPARSED_DATA *data;
struct hid_value_caps *caps;
DWORD i, button, filler, caps_len, size;
caps_len = state->caps.NumberInputValueCaps + state->caps.NumberOutputValueCaps +
state->caps.NumberFeatureValueCaps + state->caps.NumberLinkCollectionNodes;
size = FIELD_OFFSET( WINE_HIDP_PREPARSED_DATA, value_caps[caps_len] );
if (!(data = calloc( 1, size ))) return NULL;
data->magic = HID_MAGIC;
data->dwSize = size;
data->caps = state->caps;
data->value_caps_count[HidP_Input] = state->caps.NumberInputValueCaps;
data->value_caps_count[HidP_Output] = state->caps.NumberOutputValueCaps;
data->value_caps_count[HidP_Feature] = state->caps.NumberFeatureValueCaps;
/* fixup value vs button vs filler counts */
caps = HID_INPUT_VALUE_CAPS( data );
memcpy( caps, state->values[0], data->caps.NumberInputValueCaps * sizeof(*caps) );
for (i = 0, button = 0, filler = 0; i < data->caps.NumberInputValueCaps; ++i)
{
if (!caps[i].usage_min && !caps[i].usage_max) filler++;
else if (HID_VALUE_CAPS_IS_BUTTON( caps + i )) button++;
}
data->caps.NumberInputButtonCaps = button;
data->caps.NumberInputValueCaps -= filler + button;
caps = HID_OUTPUT_VALUE_CAPS( data );
memcpy( caps, state->values[1], data->caps.NumberOutputValueCaps * sizeof(*caps) );
for (i = 0, button = 0, filler = 0; i < data->caps.NumberOutputValueCaps; ++i)
{
if (!caps[i].usage_min && !caps[i].usage_max) filler++;
else if (HID_VALUE_CAPS_IS_BUTTON( caps + i )) button++;
}
caps += data->caps.NumberOutputValueCaps;
data->caps.NumberOutputButtonCaps = button;
data->caps.NumberOutputValueCaps -= filler + button;
caps = HID_FEATURE_VALUE_CAPS( data );
memcpy( caps, state->values[2], data->caps.NumberFeatureValueCaps * sizeof(*caps) );
for (i = 0, button = 0, filler = 0; i < data->caps.NumberFeatureValueCaps; ++i)
{
if (!caps[i].usage_min && !caps[i].usage_max) filler++;
else if (HID_VALUE_CAPS_IS_BUTTON( caps + i )) button++;
}
caps += data->caps.NumberFeatureValueCaps;
data->caps.NumberFeatureButtonCaps = button;
data->caps.NumberFeatureValueCaps -= filler + button;
caps = HID_COLLECTION_VALUE_CAPS( data );
memcpy( caps, state->collections, data->caps.NumberLinkCollectionNodes * sizeof(*caps) );
return data;
}
static int parse_descriptor( BYTE *descriptor, unsigned int index, unsigned int length,
struct hid_parser_state *state )
{
@ -525,64 +583,6 @@ static int parse_descriptor( BYTE *descriptor, unsigned int index, unsigned int
return i;
}
static WINE_HIDP_PREPARSED_DATA *build_preparsed_data( struct hid_parser_state *state )
{
WINE_HIDP_PREPARSED_DATA *data;
struct hid_value_caps *caps;
DWORD i, button, filler, caps_len, size;
caps_len = state->caps.NumberInputValueCaps + state->caps.NumberOutputValueCaps +
state->caps.NumberFeatureValueCaps + state->caps.NumberLinkCollectionNodes;
size = FIELD_OFFSET( WINE_HIDP_PREPARSED_DATA, value_caps[caps_len] );
if (!(data = calloc(1, size))) return NULL;
data->magic = HID_MAGIC;
data->dwSize = size;
data->caps = state->caps;
data->value_caps_count[HidP_Input] = state->caps.NumberInputValueCaps;
data->value_caps_count[HidP_Output] = state->caps.NumberOutputValueCaps;
data->value_caps_count[HidP_Feature] = state->caps.NumberFeatureValueCaps;
/* fixup value vs button vs filler counts */
caps = HID_INPUT_VALUE_CAPS( data );
memcpy( caps, state->values[0], data->caps.NumberInputValueCaps * sizeof(*caps) );
for (i = 0, button = 0, filler = 0; i < data->caps.NumberInputValueCaps; ++i)
{
if (!caps[i].usage_min && !caps[i].usage_max) filler++;
else if (HID_VALUE_CAPS_IS_BUTTON( caps + i )) button++;
}
data->caps.NumberInputButtonCaps = button;
data->caps.NumberInputValueCaps -= filler + button;
caps = HID_OUTPUT_VALUE_CAPS( data );
memcpy( caps, state->values[1], data->caps.NumberOutputValueCaps * sizeof(*caps) );
for (i = 0, button = 0, filler = 0; i < data->caps.NumberOutputValueCaps; ++i)
{
if (!caps[i].usage_min && !caps[i].usage_max) filler++;
else if (HID_VALUE_CAPS_IS_BUTTON( caps + i )) button++;
}
caps += data->caps.NumberOutputValueCaps;
data->caps.NumberOutputButtonCaps = button;
data->caps.NumberOutputValueCaps -= filler + button;
caps = HID_FEATURE_VALUE_CAPS( data );
memcpy( caps, state->values[2], data->caps.NumberFeatureValueCaps * sizeof(*caps) );
for (i = 0, button = 0, filler = 0; i < data->caps.NumberFeatureValueCaps; ++i)
{
if (!caps[i].usage_min && !caps[i].usage_max) filler++;
else if (HID_VALUE_CAPS_IS_BUTTON( caps + i )) button++;
}
caps += data->caps.NumberFeatureValueCaps;
data->caps.NumberFeatureButtonCaps = button;
data->caps.NumberFeatureValueCaps -= filler + button;
caps = HID_COLLECTION_VALUE_CAPS( data );
memcpy( caps, state->collections, data->caps.NumberLinkCollectionNodes * sizeof(*caps) );
return data;
}
WINE_HIDP_PREPARSED_DATA* ParseDescriptor(BYTE *descriptor, unsigned int length)
{
WINE_HIDP_PREPARSED_DATA *data = NULL;