21 #include "../../SDL_internal.h"
23 #if SDL_JOYSTICK_DINPUT || SDL_JOYSTICK_XINPUT
41 #include "../SDL_sysjoystick.h"
42 #include "../../thread/SDL_systhread.h"
43 #include "../../core/windows/SDL_windows.h"
44 #if !defined(__WINRT__)
54 #include "../../haptic/windows/SDL_dinputhaptic_c.h"
55 #include "../../haptic/windows/SDL_xinputhaptic_c.h"
58 #ifndef DEVICE_NOTIFY_WINDOW_HANDLE
59 #define DEVICE_NOTIFY_WINDOW_HANDLE 0x00000000
77 } SDL_DeviceNotificationData;
80 SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *
data)
85 SDL_CreateDeviceNotification(SDL_DeviceNotificationData *
data)
100 HRESULT coinitialized;
104 } SDL_DeviceNotificationData;
106 #define IDT_SDL_DEVICE_CHANGE_TIMER_1 1200
107 #define IDT_SDL_DEVICE_CHANGE_TIMER_2 1201
110 static LRESULT CALLBACK
111 SDL_PrivateJoystickDetectProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
114 case WM_DEVICECHANGE:
116 case DBT_DEVICEARRIVAL:
117 case DBT_DEVICEREMOVECOMPLETE:
118 if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
120 SetTimer(hwnd, IDT_SDL_DEVICE_CHANGE_TIMER_1, 300,
NULL);
121 SetTimer(hwnd, IDT_SDL_DEVICE_CHANGE_TIMER_2, 2000,
NULL);
127 if (wParam == IDT_SDL_DEVICE_CHANGE_TIMER_1 ||
128 wParam == IDT_SDL_DEVICE_CHANGE_TIMER_2) {
129 KillTimer(hwnd, wParam);
136 #if SDL_JOYSTICK_RAWINPUT
139 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
144 SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *
data)
146 #if SDL_JOYSTICK_RAWINPUT
151 UnregisterDeviceNotification(
data->hNotify);
153 if (
data->messageWindow)
154 DestroyWindow(
data->messageWindow);
156 UnregisterClass(
data->wincl.lpszClassName,
data->wincl.hInstance);
164 SDL_CreateDeviceNotification(SDL_DeviceNotificationData *
data)
166 DEV_BROADCAST_DEVICEINTERFACE dbh;
167 GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2L, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };
173 data->wincl.hInstance = GetModuleHandle(
NULL);
174 data->wincl.lpszClassName = L
"Message";
175 data->wincl.lpfnWndProc = SDL_PrivateJoystickDetectProc;
176 data->wincl.cbSize =
sizeof (WNDCLASSEX);
178 if (!RegisterClassEx(&
data->wincl)) {
179 WIN_SetError(
"Failed to create register class for joystick autodetect");
180 SDL_CleanupDeviceNotification(
data);
184 data->messageWindow = (HWND)CreateWindowEx(0, L
"Message",
NULL, 0, 0, 0, 0, 0, HWND_MESSAGE,
NULL,
NULL,
NULL);
185 if (!
data->messageWindow) {
186 WIN_SetError(
"Failed to create message window for joystick autodetect");
187 SDL_CleanupDeviceNotification(
data);
192 dbh.dbcc_size =
sizeof(dbh);
193 dbh.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
194 dbh.dbcc_classguid = GUID_DEVINTERFACE_HID;
196 data->hNotify = RegisterDeviceNotification(
data->messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE);
197 if (!
data->hNotify) {
198 WIN_SetError(
"Failed to create notify device for joystick autodetect");
199 SDL_CleanupDeviceNotification(
data);
203 #if SDL_JOYSTICK_RAWINPUT
215 if (!
data->messageWindow) {
220 while (lastret > 0 && s_bWindowsDeviceChanged ==
SDL_FALSE) {
221 lastret = GetMessage(&msg,
NULL, 0, 0);
223 TranslateMessage(&msg);
224 DispatchMessage(&msg);
233 static SDL_DeviceNotificationData s_notification_data;
237 SDL_JoystickThread(
void *_data)
239 #if SDL_JOYSTICK_XINPUT
240 SDL_bool bOpenedXInputDevices[XUSER_MAX_COUNT];
244 if (SDL_CreateDeviceNotification(&s_notification_data) < 0) {
249 while (s_bJoystickThreadQuit ==
SDL_FALSE) {
250 if (SDL_WaitForDeviceNotification(&s_notification_data, s_mutexJoyStickEnum) ==
SDL_FALSE) {
251 #if SDL_JOYSTICK_XINPUT
257 for (userId = 0; userId < XUSER_MAX_COUNT; userId++) {
258 XINPUT_CAPABILITIES capabilities;
259 const DWORD
result = XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities);
261 if (bOpenedXInputDevices[userId] != available) {
263 bOpenedXInputDevices[userId] = available;
275 SDL_CleanupDeviceNotification(&s_notification_data);
282 SDL_StartJoystickThread(
void)
285 if (!s_mutexJoyStickEnum) {
290 if (!s_condJoystickThread) {
296 if (!s_joystickThread) {
303 SDL_StopJoystickThread(
void)
305 if (!s_joystickThread) {
319 s_condJoystickThread =
NULL;
322 s_mutexJoyStickEnum =
NULL;
324 s_joystickThread =
NULL;
335 static void WINDOWS_JoystickDetect(
void);
336 static void WINDOWS_JoystickQuit(
void);
343 WINDOWS_JoystickInit(
void)
346 WINDOWS_JoystickQuit();
351 WINDOWS_JoystickQuit();
357 WINDOWS_JoystickDetect();
360 if (s_bJoystickThread) {
361 if (SDL_StartJoystickThread() < 0) {
365 if (SDL_CreateDeviceNotification(&s_notification_data) < 0) {
374 WINDOWS_JoystickGetCount(
void)
388 WINDOWS_JoystickDetect(
void)
390 int device_index = 0;
394 if (!s_bWindowsDeviceChanged) {
398 if (s_mutexJoyStickEnum) {
413 if (s_mutexJoyStickEnum) {
421 #if SDL_HAPTIC_XINPUT
425 #if SDL_HAPTIC_DINPUT
432 pListNext = pCurList->
pNext;
435 pCurList = pListNext;
438 for (device_index = 0, pCurList =
SYS_Joystick; pCurList; ++device_index, pCurList = pCurList->
pNext) {
439 if (pCurList->send_add_event) {
440 if (pCurList->bXInputDevice) {
441 #if SDL_HAPTIC_XINPUT
445 #if SDL_HAPTIC_DINPUT
459 WINDOWS_JoystickGetDeviceName(
int device_index)
467 return device->joystickname;
471 WINDOWS_JoystickGetDevicePlayerIndex(
int device_index)
479 return device->bXInputDevice ? (
int)
device->XInputUserId : -1;
483 WINDOWS_JoystickSetDevicePlayerIndex(
int device_index,
int player_index)
489 WINDOWS_JoystickGetDeviceGUID(
int device_index)
502 WINDOWS_JoystickGetDeviceInstanceID(
int device_index)
510 return device->nInstanceID;
519 WINDOWS_JoystickOpen(SDL_Joystick *
joystick,
int device_index)
537 if (
device->bXInputDevice) {
545 WINDOWS_JoystickRumble(SDL_Joystick *
joystick,
Uint16 low_frequency_rumble,
Uint16 high_frequency_rumble)
547 if (
joystick->hwdata->bXInputDevice) {
555 WINDOWS_JoystickRumbleTriggers(SDL_Joystick *
joystick,
Uint16 left_rumble,
Uint16 right_rumble)
561 WINDOWS_JoystickHasLED(SDL_Joystick *
joystick)
579 WINDOWS_JoystickUpdate(SDL_Joystick *
joystick)
585 if (
joystick->hwdata->bXInputDevice) {
594 WINDOWS_JoystickClose(SDL_Joystick *
joystick)
596 if (
joystick->hwdata->bXInputDevice) {
607 WINDOWS_JoystickQuit(
void)
619 if (s_bJoystickThread) {
620 SDL_StopJoystickThread();
622 SDL_CleanupDeviceNotification(&s_notification_data);
639 WINDOWS_JoystickInit,
640 WINDOWS_JoystickGetCount,
641 WINDOWS_JoystickDetect,
642 WINDOWS_JoystickGetDeviceName,
643 WINDOWS_JoystickGetDevicePlayerIndex,
644 WINDOWS_JoystickSetDevicePlayerIndex,
645 WINDOWS_JoystickGetDeviceGUID,
646 WINDOWS_JoystickGetDeviceInstanceID,
647 WINDOWS_JoystickOpen,
648 WINDOWS_JoystickRumble,
649 WINDOWS_JoystickRumbleTriggers,
650 WINDOWS_JoystickHasLED,
651 WINDOWS_JoystickSetLED,
652 WINDOWS_JoystickSetSensorsEnabled,
653 WINDOWS_JoystickUpdate,
654 WINDOWS_JoystickClose,
655 WINDOWS_JoystickQuit,
656 WINDOWS_JoystickGetGamepadMapping
#define SDL_CondBroadcast
#define SDL_CondWaitTimeout
#define SDL_GetHintBoolean
#define SDL_OutOfMemory()
#define SDL_Unsupported()
#define SDL_HINT_JOYSTICK_THREAD
A variable controlling whether a separate thread should be used for handling joystick detection and r...
void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
void SDL_PrivateJoystickAdded(SDL_JoystickID device_instance)
SDL_JoystickID SDL_GetNextJoystickInstanceID()
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLenum GLenum GLsizei const GLuint GLboolean enabled
SDL_JoystickDriver SDL_WINDOWS_JoystickDriver
SDL_Thread * SDL_CreateThreadInternal(int(*fn)(void *), const char *name, const size_t stacksize, void *data)
HRESULT WIN_CoInitialize(void)
void WIN_CoUninitialize(void)
int WIN_SetError(const char *prefix)
void WINDOWS_AddJoystickDevice(JoyStick_DeviceData *device)
JoyStick_DeviceData * SYS_Joystick
static SDL_AudioDeviceID device
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF base if bpp PF set rept prefetch_distance PF set OFFSET endr endif endm macro preload_leading_step2 base if bpp ifc DST PF PF else if bpp lsl PF PF lsl PF PF lsl PF PF PF else PF lsl PF lsl PF lsl PF endif SIZE macro preload_middle scratch_holds_offset if bpp if else PF PF endif endif endif endm macro preload_trailing base if bpp if bpp *pix_per_block PF PF lsl PF PF PF PF PF else PF lsl PF lsl PF PF PF PF PF base if bpp if narrow_case &&bpp<=dst_w_bpp) PF bic, WK0, base, #31 PF pld,[WK0] PF add, WK1, base, X, LSL #bpp_shift PF sub, WK1, WK1, #1 PF bic, WK1, WK1, #31 PF cmp, WK1, WK0 PF beq, 90f PF pld,[WK1]90:.else PF bic, WK0, base, #31 PF pld,[WK0] PF add, WK1, base, X, lsl #bpp_shift PF sub, WK1, WK1, #1 PF bic, WK1, WK1, #31 PF cmp, WK1, WK0 PF beq, 92f91:PF add, WK0, WK0, #32 PF cmp, WK0, WK1 PF pld,[WK0] PF bne, 91b92:.endif .endif.endm.macro conditional_process1_helper cond, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx process_head cond, numbytes, firstreg, unaligned_src, unaligned_mask, 0 .if decrementx sub &cond X, X, #8 *numbytes/dst_w_bpp .endif process_tail cond, numbytes, firstreg .if !((flags) &FLAG_PROCESS_DOES_STORE) pixst cond, numbytes, firstreg, DST .endif.endm.macro conditional_process1 cond, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx .if(flags) &FLAG_BRANCH_OVER .ifc cond, mi bpl 100f .endif .ifc cond, cs bcc 100f .endif .ifc cond, ne beq 100f .endif conditional_process1_helper, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx100:.else conditional_process1_helper cond, process_head, process_tail, numbytes, firstreg, unaligned_src, unaligned_mask, decrementx .endif.endm.macro conditional_process2 test, cond1, cond2, process_head, process_tail, numbytes1, numbytes2, firstreg1, firstreg2, unaligned_src, unaligned_mask, decrementx .if(flags) &(FLAG_DST_READWRITE|FLAG_BRANCH_OVER|FLAG_PROCESS_CORRUPTS_PSR|FLAG_PROCESS_DOES_STORE) test conditional_process1 cond1, process_head, process_tail, numbytes1, firstreg1, unaligned_src, unaligned_mask, decrementx .if(flags) &FLAG_PROCESS_CORRUPTS_PSR test .endif conditional_process1 cond2, process_head, process_tail, numbytes2, firstreg2, unaligned_src, unaligned_mask, decrementx .else test process_head cond1, numbytes1, firstreg1, unaligned_src, unaligned_mask, 0 process_head cond2, numbytes2, firstreg2, unaligned_src, unaligned_mask, 0 .if decrementx sub &cond1 X, X, #8 *numbytes1/dst_w_bpp sub &cond2 X, X, #8 *numbytes2/dst_w_bpp .endif process_tail cond1, numbytes1, firstreg1 process_tail cond2, numbytes2, firstreg2 pixst cond1, numbytes1, firstreg1, DST pixst cond2, numbytes2, firstreg2, DST .endif.endm.macro test_bits_1_0_ptr .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 movs SCRATCH, X, lsl #32-1 .else movs SCRATCH, WK0, lsl #32-1 .endif.endm.macro test_bits_3_2_ptr .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 movs SCRATCH, X, lsl #32-3 .else movs SCRATCH, WK0, lsl #32-3 .endif.endm.macro leading_15bytes process_head, process_tail .set DECREMENT_X, 1 .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 .set DECREMENT_X, 0 sub X, X, WK0, lsr #dst_bpp_shift str X,[sp, #LINE_SAVED_REG_COUNT *4] mov X, WK0 .endif .if dst_w_bpp==8 conditional_process2 test_bits_1_0_ptr, mi, cs, process_head, process_tail, 1, 2, 1, 2, 1, 1, DECREMENT_X .elseif dst_w_bpp==16 test_bits_1_0_ptr conditional_process1 cs, process_head, process_tail, 2, 2, 1, 1, DECREMENT_X .endif conditional_process2 test_bits_3_2_ptr, mi, cs, process_head, process_tail, 4, 8, 1, 2, 1, 1, DECREMENT_X .if(flags) &FLAG_PROCESS_CORRUPTS_WK0 ldr X,[sp, #LINE_SAVED_REG_COUNT *4] .endif.endm.macro test_bits_3_2_pix movs SCRATCH, X, lsl #dst_bpp_shift+32-3.endm.macro test_bits_1_0_pix .if dst_w_bpp==8 movs SCRATCH, X, lsl #dst_bpp_shift+32-1 .else movs SCRATCH, X, lsr #1 .endif.endm.macro trailing_15bytes process_head, process_tail, unaligned_src, unaligned_mask conditional_process2 test_bits_3_2_pix, cs, mi, process_head, process_tail, 8, 4, 0, 2, unaligned_src, unaligned_mask, 0 .if dst_w_bpp==16 test_bits_1_0_pix conditional_process1 cs, process_head, process_tail, 2, 0, unaligned_src, unaligned_mask, 0 .elseif dst_w_bpp==8 conditional_process2 test_bits_1_0_pix, cs, mi, process_head, process_tail, 2, 1, 0, 1, unaligned_src, unaligned_mask, 0 .endif.endm.macro wide_case_inner_loop process_head, process_tail, unaligned_src, unaligned_mask, dst_alignment110:.set SUBBLOCK, 0 .rept pix_per_block *dst_w_bpp/128 process_head, 16, 0, unaligned_src, unaligned_mask, 1 .if(src_bpp > 0) &&(mask_bpp==0) &&((flags) &FLAG_PROCESS_PRESERVES_SCRATCH) preload_middle src_bpp, SRC, 1 .elseif(src_bpp==0) &&(mask_bpp > 0) &&((flags) &FLAG_PROCESS_PRESERVES_SCRATCH) preload_middle mask_bpp, MASK, 1 .else preload_middle src_bpp, SRC, 0 preload_middle mask_bpp, MASK, 0 .endif .if(dst_r_bpp > 0) &&((SUBBLOCK % 2)==0) &&(((flags) &FLAG_NO_PRELOAD_DST)==0) PF pld,[DST, #32 *prefetch_distance - dst_alignment] .endif process_tail, 16, 0 .if !((flags) &FLAG_PROCESS_DOES_STORE) pixst, 16, 0, DST .endif .set SUBBLOCK, SUBBLOCK+1 .endr subs X, X, #pix_per_block bhs 110b.endm.macro wide_case_inner_loop_and_trailing_pixels process_head, process_tail, process_inner_loop, exit_label, unaligned_src, unaligned_mask .if dst_r_bpp > tst bne process_inner_loop DST_PRELOAD_BIAS endif preload_trailing SRC preload_trailing MASK DST endif add medium_case_inner_loop_and_trailing_pixels unaligned_mask endm macro medium_case_inner_loop_and_trailing_pixels unused
DIDEVICEINSTANCE dxdevice
struct JoyStick_DeviceData * pNext
SDL_JoystickID nInstanceID
static SDL_Joystick * joystick