dinput: Move critical section to the base device class.
This commit is contained in:
parent
f7eacd64d1
commit
0da0486cc3
|
@ -454,11 +454,14 @@ BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef)
|
|||
HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
|
||||
{
|
||||
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
|
||||
HRESULT res;
|
||||
|
||||
if (This->acquired) return S_FALSE;
|
||||
EnterCriticalSection(&This->crit);
|
||||
res = This->acquired ? S_FALSE : DI_OK;
|
||||
This->acquired = 1;
|
||||
LeaveCriticalSection(&This->crit);
|
||||
|
||||
return DI_OK;
|
||||
return res;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -468,11 +471,14 @@ HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
|
|||
HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
|
||||
{
|
||||
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
|
||||
HRESULT res;
|
||||
|
||||
if (!This->acquired) return DI_NOEFFECT;
|
||||
EnterCriticalSection(&This->crit);
|
||||
res = !This->acquired ? DI_NOEFFECT : DI_OK;
|
||||
This->acquired = 0;
|
||||
LeaveCriticalSection(&This->crit);
|
||||
|
||||
return DI_OK;
|
||||
return res;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -524,8 +530,10 @@ HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
|
|||
return DIERR_UNSUPPORTED;
|
||||
|
||||
/* Store the window which asks for the mouse */
|
||||
EnterCriticalSection(&This->crit);
|
||||
This->win = hwnd;
|
||||
This->dwCoopLevel = dwflags;
|
||||
LeaveCriticalSection(&This->crit);
|
||||
|
||||
return DI_OK;
|
||||
}
|
||||
|
@ -540,7 +548,9 @@ HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
|
|||
|
||||
TRACE("(%p) %p\n", This, event);
|
||||
|
||||
EnterCriticalSection(&This->crit);
|
||||
This->hEvent = event;
|
||||
LeaveCriticalSection(&This->crit);
|
||||
return DI_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ struct IDirectInputDevice2AImpl
|
|||
const void *lpVtbl;
|
||||
LONG ref;
|
||||
GUID guid;
|
||||
CRITICAL_SECTION crit;
|
||||
HANDLE hEvent;
|
||||
DWORD dwCoopLevel;
|
||||
HWND win;
|
||||
|
|
|
@ -115,7 +115,6 @@ struct JoystickImpl
|
|||
int axes;
|
||||
int buttons;
|
||||
POV povs[4];
|
||||
CRITICAL_SECTION crit;
|
||||
BOOL overflow;
|
||||
};
|
||||
|
||||
|
@ -500,6 +499,8 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
|
|||
newDevice->dinput = dinput;
|
||||
newDevice->overflow = FALSE;
|
||||
CopyMemory(&newDevice->base.guid, rguid, sizeof(*rguid));
|
||||
InitializeCriticalSection(&newDevice->base.crit);
|
||||
newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)"DINPUT_joystick";
|
||||
|
||||
/* setup_dinput_options may change these */
|
||||
newDevice->deadzone = 5000;
|
||||
|
@ -560,8 +561,6 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
|
|||
calculate_ids(newDevice);
|
||||
|
||||
IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
|
||||
InitializeCriticalSection(&(newDevice->crit));
|
||||
newDevice->crit.DebugInfo->Spare[0] = (DWORD_PTR)"DINPUT_Mouse";
|
||||
|
||||
newDevice->devcaps.dwSize = sizeof(newDevice->devcaps);
|
||||
newDevice->devcaps.dwFlags = DIDC_ATTACHED;
|
||||
|
@ -697,8 +696,8 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
|
|||
/* release the data transform filter */
|
||||
release_DataFormat(This->transform);
|
||||
|
||||
This->crit.DebugInfo->Spare[0] = 0;
|
||||
DeleteCriticalSection(&(This->crit));
|
||||
This->base.crit.DebugInfo->Spare[0] = 0;
|
||||
DeleteCriticalSection(&This->base.crit);
|
||||
IDirectInputDevice_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
|
||||
|
||||
HeapFree(GetProcessHeap(),0,This);
|
||||
|
@ -1040,7 +1039,7 @@ static HRESULT WINAPI JoystickAImpl_GetDeviceData(
|
|||
return DIERR_NOTACQUIRED;
|
||||
}
|
||||
|
||||
EnterCriticalSection(&(This->crit));
|
||||
EnterCriticalSection(&This->base.crit);
|
||||
|
||||
joy_polldev(This);
|
||||
|
||||
|
@ -1060,7 +1059,7 @@ static HRESULT WINAPI JoystickAImpl_GetDeviceData(
|
|||
} else {
|
||||
if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
|
||||
ERR("Wrong structure size !\n");
|
||||
LeaveCriticalSection(&(This->crit));
|
||||
LeaveCriticalSection(&This->base.crit);
|
||||
return DIERR_INVALIDPARAM;
|
||||
}
|
||||
|
||||
|
@ -1091,7 +1090,7 @@ static HRESULT WINAPI JoystickAImpl_GetDeviceData(
|
|||
if (!(flags & DIGDD_PEEK))
|
||||
This->queue_tail = nqtail;
|
||||
|
||||
LeaveCriticalSection(&(This->crit));
|
||||
LeaveCriticalSection(&This->base.crit);
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
|
|
@ -377,6 +377,7 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm
|
|||
newDevice->base.lpVtbl = jvt;
|
||||
newDevice->base.ref = 1;
|
||||
memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
|
||||
InitializeCriticalSection(&newDevice->base.crit);
|
||||
newDevice->joyfd = -1;
|
||||
newDevice->dinput = dinput;
|
||||
newDevice->joydev = joydev;
|
||||
|
@ -543,6 +544,8 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
|
|||
/* release the data transform filter */
|
||||
release_DataFormat(This->transform);
|
||||
|
||||
DeleteCriticalSection(&This->base.crit);
|
||||
|
||||
HeapFree(GetProcessHeap(),0,This);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@ struct SysKeyboardImpl
|
|||
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' */
|
||||
CRITICAL_SECTION crit;
|
||||
};
|
||||
|
||||
static SysKeyboardImpl* current_lock = NULL;
|
||||
|
@ -94,9 +93,9 @@ LRESULT CALLBACK KeyboardCallback( int code, WPARAM wparam, LPARAM lparam )
|
|||
DInputKeyState[dik_code] = new_diks;
|
||||
TRACE(" setting %02X to %02X\n", dik_code, DInputKeyState[dik_code]);
|
||||
|
||||
EnterCriticalSection(&This->crit);
|
||||
EnterCriticalSection(&This->base.crit);
|
||||
GEN_EVENT(dik_code, new_diks, hook->time, This->dinput->evsequence++);
|
||||
LeaveCriticalSection(&This->crit);
|
||||
LeaveCriticalSection(&This->base.crit);
|
||||
|
||||
if (This->base.hEvent) SetEvent(This->base.hEvent);
|
||||
|
||||
|
@ -203,7 +202,7 @@ static SysKeyboardImpl *alloc_device(REFGUID rguid, const void *kvt, IDirectInpu
|
|||
newDevice->base.ref = 1;
|
||||
memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
|
||||
newDevice->dinput = dinput;
|
||||
InitializeCriticalSection(&(newDevice->crit));
|
||||
InitializeCriticalSection(&newDevice->base.crit);
|
||||
|
||||
return newDevice;
|
||||
}
|
||||
|
@ -266,7 +265,7 @@ static ULONG WINAPI SysKeyboardAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
|
|||
/* Free the data queue */
|
||||
HeapFree(GetProcessHeap(), 0, This->data_queue);
|
||||
|
||||
DeleteCriticalSection(&(This->crit));
|
||||
DeleteCriticalSection(&This->base.crit);
|
||||
|
||||
HeapFree(GetProcessHeap(),0,This);
|
||||
return DI_OK;
|
||||
|
@ -348,7 +347,7 @@ static HRESULT WINAPI SysKeyboardAImpl_GetDeviceState(
|
|||
|
||||
MsgWaitForMultipleObjectsEx(0, NULL, 0, QS_ALLINPUT, 0);
|
||||
|
||||
EnterCriticalSection(&(This->crit));
|
||||
EnterCriticalSection(&This->base.crit);
|
||||
|
||||
if (TRACE_ON(dinput)) {
|
||||
int i;
|
||||
|
@ -360,7 +359,7 @@ static HRESULT WINAPI SysKeyboardAImpl_GetDeviceState(
|
|||
}
|
||||
|
||||
memcpy(ptr, DInputKeyState, WINE_DINPUT_KEYBOARD_MAX_KEYS);
|
||||
LeaveCriticalSection(&(This->crit));
|
||||
LeaveCriticalSection(&This->base.crit);
|
||||
|
||||
return DI_OK;
|
||||
}
|
||||
|
@ -387,7 +386,7 @@ static HRESULT WINAPI SysKeyboardAImpl_GetDeviceData(
|
|||
return DIERR_INVALIDPARAM;
|
||||
|
||||
MsgWaitForMultipleObjectsEx(0, NULL, 0, QS_ALLINPUT, 0);
|
||||
EnterCriticalSection(&This->crit);
|
||||
EnterCriticalSection(&This->base.crit);
|
||||
|
||||
len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0) +
|
||||
This->queue_head - This->queue_tail;
|
||||
|
@ -414,7 +413,7 @@ static HRESULT WINAPI SysKeyboardAImpl_GetDeviceData(
|
|||
This->overflow = FALSE;
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&This->crit);
|
||||
LeaveCriticalSection(&This->base.crit);
|
||||
|
||||
TRACE("Returning %d events queued\n", *entries);
|
||||
return ret;
|
||||
|
|
|
@ -133,7 +133,6 @@ struct SysMouseImpl
|
|||
* reach window borders (for e.g. shooters, "surface movement" games) */
|
||||
WARP_STATUS need_warp;
|
||||
DWORD last_warped;
|
||||
CRITICAL_SECTION crit;
|
||||
|
||||
/* This is for mouse reporting. */
|
||||
Wine_InternalMouseData m_state;
|
||||
|
@ -249,7 +248,7 @@ static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputIm
|
|||
newDevice->base.ref = 1;
|
||||
newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
|
||||
memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
|
||||
InitializeCriticalSection(&(newDevice->crit));
|
||||
InitializeCriticalSection(&newDevice->base.crit);
|
||||
|
||||
/* Per default, Wine uses its internal data format */
|
||||
newDevice->df = (DIDATAFORMAT *) &Wine_InternalMouseFormat;
|
||||
|
@ -329,7 +328,7 @@ static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
|
|||
|
||||
/* Free the data queue */
|
||||
HeapFree(GetProcessHeap(),0,This->data_queue);
|
||||
DeleteCriticalSection(&(This->crit));
|
||||
DeleteCriticalSection(&This->base.crit);
|
||||
|
||||
/* Free the DataFormat */
|
||||
if (This->df != &(Wine_InternalMouseFormat)) {
|
||||
|
@ -385,7 +384,7 @@ static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lpara
|
|||
|
||||
if (code != HC_ACTION) return CallNextHookEx( 0, code, wparam, lparam );
|
||||
|
||||
EnterCriticalSection(&(This->crit));
|
||||
EnterCriticalSection(&This->base.crit);
|
||||
dwCoop = This->base.dwCoopLevel;
|
||||
|
||||
if (wparam == WM_MOUSEMOVE) {
|
||||
|
@ -495,7 +494,7 @@ static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lpara
|
|||
/* Mouse moved -> send event if asked */
|
||||
if (This->base.hEvent) SetEvent(This->base.hEvent);
|
||||
|
||||
LeaveCriticalSection(&(This->crit));
|
||||
LeaveCriticalSection(&This->base.crit);
|
||||
|
||||
/* Ignore message */
|
||||
if (dwCoop & DISCL_EXCLUSIVE) return 1;
|
||||
|
@ -631,7 +630,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
|
|||
|
||||
if(This->base.acquired == 0) return DIERR_NOTACQUIRED;
|
||||
|
||||
EnterCriticalSection(&(This->crit));
|
||||
EnterCriticalSection(&This->base.crit);
|
||||
TRACE("(this=%p,0x%08x,%p):\n", This, len, ptr);
|
||||
TRACE("(X: %d - Y: %d - Z: %d L: %02x M: %02x R: %02x)\n",
|
||||
This->m_state.lX, This->m_state.lY, This->m_state.lZ,
|
||||
|
@ -651,7 +650,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
|
|||
if (This->need_warp == WARP_NEEDED && (GetCurrentTime() - This->last_warped > 10)) {
|
||||
if(!dinput_window_check(This))
|
||||
{
|
||||
LeaveCriticalSection(&(This->crit));
|
||||
LeaveCriticalSection(&This->base.crit);
|
||||
return DIERR_GENERIC;
|
||||
}
|
||||
TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
|
||||
|
@ -665,7 +664,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
|
|||
#endif
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&(This->crit));
|
||||
LeaveCriticalSection(&This->base.crit);
|
||||
|
||||
return DI_OK;
|
||||
}
|
||||
|
@ -692,7 +691,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
|
|||
return DIERR_NOTACQUIRED;
|
||||
}
|
||||
|
||||
EnterCriticalSection(&(This->crit));
|
||||
EnterCriticalSection(&This->base.crit);
|
||||
|
||||
len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
|
||||
+ (This->queue_head - This->queue_tail);
|
||||
|
@ -713,7 +712,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
|
|||
} else {
|
||||
if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
|
||||
ERR("Wrong structure size !\n");
|
||||
LeaveCriticalSection(&(This->crit));
|
||||
LeaveCriticalSection(&This->base.crit);
|
||||
return DIERR_INVALIDPARAM;
|
||||
}
|
||||
|
||||
|
@ -743,7 +742,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
|
|||
if (!(flags & DIGDD_PEEK))
|
||||
This->queue_tail = nqtail;
|
||||
|
||||
LeaveCriticalSection(&(This->crit));
|
||||
LeaveCriticalSection(&This->base.crit);
|
||||
|
||||
/* Check if we need to do a mouse warping */
|
||||
if (This->need_warp == WARP_NEEDED && (GetCurrentTime() - This->last_warped > 10)) {
|
||||
|
|
Loading…
Reference in New Issue