Commit cd050bf2 authored by Vitaliy Margolen's avatar Vitaliy Margolen Committed by Alexandre Julliard

dinput: Move transform and offsets structures into base device class.

parent 21be6a6c
......@@ -282,9 +282,12 @@ void fill_DataFormat(void *out, const void *in, DataFormat *df) {
void release_DataFormat(DataFormat * format)
{
TRACE("Deleting DataTransform :\n");
TRACE("Deleting DataFormat: %p\n", format);
HeapFree(GetProcessHeap(), 0, format->dt);
format->dt = NULL;
HeapFree(GetProcessHeap(), 0, format->offsets);
format->offsets = NULL;
}
/* Make all instances sequential */
......@@ -329,9 +332,8 @@ static void calculate_ids(LPDIDATAFORMAT df)
}
}
DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, int *offset)
HRESULT create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, DataFormat *format)
{
DataFormat *ret;
DataTransform *dt;
unsigned int i, j;
int same = 1;
......@@ -339,18 +341,18 @@ DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_
int index = 0;
DWORD next = 0;
ret = HeapAlloc(GetProcessHeap(), 0, sizeof(DataFormat));
done = HeapAlloc(GetProcessHeap(), 0, sizeof(int) * asked_format->dwNumObjs);
memset(done, 0, sizeof(int) * asked_format->dwNumObjs);
done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
if (!dt || !done) goto failed;
if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, wine_format->dwNumObjs * sizeof(int))))
goto failed;
TRACE("Creating DataTransform :\n");
for (i = 0; i < wine_format->dwNumObjs; i++) {
offset[i] = -1;
format->offsets[i] = -1;
for (j = 0; j < asked_format->dwNumObjs; j++) {
if (done[j] == 1)
continue;
......@@ -397,7 +399,7 @@ DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_
dt[index].size = sizeof(DWORD);
dt[index].offset_in = wine_format->rgodf[i].dwOfs;
dt[index].offset_out = asked_format->rgodf[j].dwOfs;
offset[i] = asked_format->rgodf[j].dwOfs;
format->offsets[i] = asked_format->rgodf[j].dwOfs;
dt[index].value = 0;
next = next + dt[index].size;
......@@ -437,20 +439,28 @@ DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_
}
}
ret->internal_format_size = wine_format->dwDataSize;
ret->size = index;
format->internal_format_size = wine_format->dwDataSize;
format->size = index;
if (same) {
ret->dt = NULL;
HeapFree(GetProcessHeap(), 0, dt);
} else {
ret->dt = dt;
dt = NULL;
}
format->dt = dt;
HeapFree(GetProcessHeap(), 0, done);
/* Last step - reset all instances of the new format */
calculate_ids(asked_format);
return ret;
return DI_OK;
failed:
HeapFree(GetProcessHeap(), 0, done);
HeapFree(GetProcessHeap(), 0, dt);
format->dt = NULL;
HeapFree(GetProcessHeap(), 0, format->offsets);
format->offsets = NULL;
return DIERR_OUTOFMEMORY;
}
/* find an object by it's offset in a data format */
......
......@@ -26,6 +26,23 @@
#include "winbase.h"
#include "dinput.h"
typedef struct
{
int size;
int offset_in;
int offset_out;
int value;
} DataTransform;
typedef struct
{
int size;
int internal_format_size;
DataTransform *dt;
int *offsets; /* object offsets */
} DataFormat;
/* Device implementation */
typedef struct IDirectInputDevice2AImpl IDirectInputDevice2AImpl;
struct IDirectInputDevice2AImpl
......@@ -44,23 +61,13 @@ struct IDirectInputDevice2AImpl
int queue_head; /* position to write new event into queue */
int queue_tail; /* next event to read from queue */
BOOL overflow; /* return DI_BUFFEROVERFLOW in 'GetDeviceData' */
DataFormat data_format; /* user data format and wine to user format converter */
};
/* Routines to do DataFormat / WineFormat conversions */
typedef struct {
int size;
int offset_in;
int offset_out;
int value;
} DataTransform;
typedef struct {
int size;
int internal_format_size;
DataTransform *dt;
} DataFormat;
extern void fill_DataFormat(void *out, const void *in, DataFormat *df) ;
extern DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, int *offset);
extern HRESULT create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, DataFormat *format);
extern void release_DataFormat(DataFormat *df) ;
extern void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq);
/* Helper functions to work with data format */
......
......@@ -103,8 +103,6 @@ struct JoystickImpl
int joyfd;
DIJOYSTATE2 js; /* wine data */
LPDIDATAFORMAT user_df; /* user defined format */
DataFormat *transform; /* wine to user format converter */
int *offsets; /* object offsets */
ObjProps *props;
char *name;
DIDEVCAPS devcaps;
......@@ -495,13 +493,9 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
newDevice->props[i].lSaturation = 0;
}
/* create an offsets array */
newDevice->offsets = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,c_dfDIJoystick2.dwNumObjs*sizeof(int));
if (newDevice->offsets == 0)
goto FAILED;
/* create the default transform filter */
newDevice->transform = create_DataFormat(&c_dfDIJoystick2, newDevice->user_df, newDevice->offsets);
hr = create_DataFormat(&c_dfDIJoystick2, newDevice->user_df, &newDevice->base.data_format);
if (hr != DI_OK) goto FAILED;
IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
......@@ -633,11 +627,8 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
/* Free the properties */
HeapFree(GetProcessHeap(), 0, This->props);
/* Free the offsets array */
HeapFree(GetProcessHeap(),0,This->offsets);
/* release the data transform filter */
release_DataFormat(This->transform);
release_DataFormat(&This->base.data_format);
This->base.crit.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&This->base.crit);
......@@ -697,7 +688,7 @@ static HRESULT WINAPI JoystickAImpl_SetDataFormat(
HeapFree(GetProcessHeap(),0,This->user_df);
HeapFree(GetProcessHeap(),0,This->user_df->rgodf);
HeapFree(GetProcessHeap(),0,This->props);
release_DataFormat(This->transform);
release_DataFormat(&This->base.data_format);
This->user_df = new_df;
CopyMemory(This->user_df, df, df->dwSize);
......@@ -710,9 +701,8 @@ static HRESULT WINAPI JoystickAImpl_SetDataFormat(
This->props[i].lDeadZone = 1000;
This->props[i].lSaturation = 0;
}
This->transform = create_DataFormat(&c_dfDIJoystick2, This->user_df, This->offsets);
return DI_OK;
if (create_DataFormat(&c_dfDIJoystick2, This->user_df, &This->base.data_format) == DI_OK)
return DI_OK;
FAILED:
WARN("out of memory\n");
......@@ -840,7 +830,7 @@ static void joy_polldev(JoystickImpl *This) {
TRACE("js_event: type 0x%x, number %d, value %d\n",
jse.type,jse.number,jse.value);
if (jse.type & JS_EVENT_BUTTON) {
int offset = This->offsets[jse.number + 12];
int offset = This->base.data_format.offsets[jse.number + 12];
int value = jse.value?0x80:0x00;
This->js.rgbButtons[jse.number] = value;
......@@ -848,7 +838,7 @@ static void joy_polldev(JoystickImpl *This) {
} else if (jse.type & JS_EVENT_AXIS) {
int number = This->axis_map[jse.number]; /* wine format object index */
if (number < 12) {
int offset = This->offsets[number];
int offset = This->base.data_format.offsets[number];
int index = offset_to_object(This->user_df, offset);
LONG value = map_axis(This, jse.value, index);
......@@ -940,7 +930,7 @@ static HRESULT WINAPI JoystickAImpl_GetDeviceState(
joy_polldev(This);
/* convert and copy data to user supplied buffer */
fill_DataFormat(ptr, &This->js, This->transform);
fill_DataFormat(ptr, &This->js, &This->base.data_format);
return DI_OK;
}
......@@ -1154,7 +1144,7 @@ static HRESULT WINAPI JoystickAImpl_EnumObjects(
ddoi.guidType = GUID_Unknown;
}
if (wine_obj < 8) {
user_offset = This->offsets[wine_obj]; /* get user offset from wine index */
user_offset = This->base.data_format.offsets[wine_obj]; /* get user offset from wine index */
user_object = offset_to_object(This->user_df, user_offset);
ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
......@@ -1163,7 +1153,7 @@ static HRESULT WINAPI JoystickAImpl_EnumObjects(
axes++;
} else {
if (pov[wine_obj - 8] < 2) {
user_offset = This->offsets[wine_obj]; /* get user offset from wine index */
user_offset = This->base.data_format.offsets[wine_obj]; /* get user offset from wine index */
user_object = offset_to_object(This->user_df, user_offset);
ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
......@@ -1188,7 +1178,7 @@ static HRESULT WINAPI JoystickAImpl_EnumObjects(
ddoi.guidType = GUID_Button;
for (i = 0; i < This->buttons; i++) {
user_offset = This->offsets[i + 12]; /* get user offset from wine index */
user_offset = This->base.data_format.offsets[i + 12]; /* get user offset from wine index */
user_object = offset_to_object(This->user_df, user_offset);
ddoi.guidType = GUID_Button;
ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
......
......@@ -137,8 +137,6 @@ struct JoystickImpl
int joyfd;
LPDIDATAFORMAT df;
DataFormat *transform; /* wine to user format converter */
int *offsets; /* object offsets */
DIJOYSTATE2 js;
/* Force feedback variables */
......@@ -404,15 +402,9 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm
goto FAILED;
CopyMemory(newDevice->df->rgodf,c_dfDIJoystick2.rgodf,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
/* create an offsets array */
newDevice->offsets = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,c_dfDIJoystick2.dwNumObjs*sizeof(int));
if (newDevice->offsets == 0)
goto FAILED;
/* create the default transform filter */
newDevice->transform = create_DataFormat(&c_dfDIJoystick2, newDevice->df, newDevice->offsets);
return newDevice;
if (create_DataFormat(&c_dfDIJoystick2, newDevice->df, &newDevice->base.data_format) == DI_OK)
return newDevice;
FAILED:
HeapFree(GetProcessHeap(),0,newDevice->df->rgodf);
......@@ -514,11 +506,8 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
HeapFree(GetProcessHeap(), 0, This->df->rgodf);
HeapFree(GetProcessHeap(), 0, This->df);
/* Free the offsets array */
HeapFree(GetProcessHeap(),0,This->offsets);
/* release the data transform filter */
release_DataFormat(This->transform);
release_DataFormat(&This->base.data_format);
DeleteCriticalSection(&This->base.crit);
......@@ -557,7 +546,7 @@ static HRESULT WINAPI JoystickAImpl_SetDataFormat(
HeapFree(GetProcessHeap(),0,This->df->rgodf);
HeapFree(GetProcessHeap(),0,This->df);
release_DataFormat(This->transform);
release_DataFormat(&This->base.data_format);
/* Store the new data format */
This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
......@@ -572,9 +561,7 @@ static HRESULT WINAPI JoystickAImpl_SetDataFormat(
}
memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
This->transform = create_DataFormat(&c_dfDIJoystick2, This->df, This->offsets);
return DI_OK;
return create_DataFormat(&c_dfDIJoystick2, This->df, &This->base.data_format);
}
/******************************************************************************
......@@ -744,7 +731,7 @@ lxinput_to_user_offset(JoystickImpl *This, int ie_type, int ie_code )
FIXME("Unhandled type(0x%02X)\n", ie_type);
return -1;
}
return This->offsets[offset];
return This->base.data_format.offsets[offset];
}
/* convert wine format offset to user format object index */
......@@ -892,7 +879,7 @@ static HRESULT WINAPI JoystickAImpl_GetDeviceState(
joy_polldev(This);
/* convert and copy data to user supplied buffer */
fill_DataFormat(ptr, &This->js, This->transform);
fill_DataFormat(ptr, &This->js, &This->base.data_format);
return DI_OK;
}
......
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