30 #ifdef SDL_USE_LIBUDEV 32 #include <linux/input.h> 37 #include "../unix/SDL_poll.h" 39 static const char *SDL_UDEV_LIBS[] = {
"libudev.so.1",
"libudev.so.0" };
41 #define _THIS SDL_UDEV_PrivateData *_this 44 static SDL_bool SDL_UDEV_load_sym(
const char *fn,
void **
addr);
45 static int SDL_UDEV_load_syms(
void);
46 static SDL_bool SDL_UDEV_hotplug_update_available(
void);
47 static void device_event(SDL_UDEV_deviceevent
type,
struct udev_device *dev);
50 SDL_UDEV_load_sym(
const char *fn,
void **
addr)
62 SDL_UDEV_load_syms(
void)
65 #define SDL_UDEV_SYM(x) \ 66 if (!SDL_UDEV_load_sym(#x, (void **) (char *) & _this->syms.x)) return -1 68 SDL_UDEV_SYM(udev_device_get_action);
69 SDL_UDEV_SYM(udev_device_get_devnode);
70 SDL_UDEV_SYM(udev_device_get_subsystem);
71 SDL_UDEV_SYM(udev_device_get_parent_with_subsystem_devtype);
72 SDL_UDEV_SYM(udev_device_get_property_value);
73 SDL_UDEV_SYM(udev_device_get_sysattr_value);
74 SDL_UDEV_SYM(udev_device_new_from_syspath);
75 SDL_UDEV_SYM(udev_device_unref);
76 SDL_UDEV_SYM(udev_enumerate_add_match_property);
77 SDL_UDEV_SYM(udev_enumerate_add_match_subsystem);
78 SDL_UDEV_SYM(udev_enumerate_get_list_entry);
79 SDL_UDEV_SYM(udev_enumerate_new);
80 SDL_UDEV_SYM(udev_enumerate_scan_devices);
81 SDL_UDEV_SYM(udev_enumerate_unref);
82 SDL_UDEV_SYM(udev_list_entry_get_name);
83 SDL_UDEV_SYM(udev_list_entry_get_next);
84 SDL_UDEV_SYM(udev_monitor_enable_receiving);
85 SDL_UDEV_SYM(udev_monitor_filter_add_match_subsystem_devtype);
86 SDL_UDEV_SYM(udev_monitor_get_fd);
87 SDL_UDEV_SYM(udev_monitor_new_from_netlink);
88 SDL_UDEV_SYM(udev_monitor_receive_device);
89 SDL_UDEV_SYM(udev_monitor_unref);
90 SDL_UDEV_SYM(udev_new);
91 SDL_UDEV_SYM(udev_unref);
92 SDL_UDEV_SYM(udev_device_new_from_devnum);
93 SDL_UDEV_SYM(udev_device_get_devnum);
100 SDL_UDEV_hotplug_update_available(
void)
103 const int fd =
_this->syms.udev_monitor_get_fd(
_this->udev_mon);
123 retval = SDL_UDEV_LoadLibrary();
139 _this->udev_mon =
_this->syms.udev_monitor_new_from_netlink(
_this->udev,
"udev");
142 return SDL_SetError(
"udev_monitor_new_from_netlink() failed");
145 _this->syms.udev_monitor_filter_add_match_subsystem_devtype(
_this->udev_mon,
"input",
NULL);
146 _this->syms.udev_monitor_filter_add_match_subsystem_devtype(
_this->udev_mon,
"sound",
NULL);
147 _this->syms.udev_monitor_enable_receiving(
_this->udev_mon);
154 _this->ref_count += 1;
162 SDL_UDEV_CallbackList *item;
168 _this->ref_count -= 1;
170 if (
_this->ref_count < 1) {
173 _this->syms.udev_monitor_unref(
_this->udev_mon);
188 SDL_UDEV_UnloadLibrary();
197 struct udev_enumerate *enumerate =
NULL;
198 struct udev_list_entry *devs =
NULL;
199 struct udev_list_entry *item =
NULL;
205 enumerate =
_this->syms.udev_enumerate_new(
_this->udev);
206 if (enumerate ==
NULL) {
212 _this->syms.udev_enumerate_add_match_subsystem(enumerate,
"input");
213 _this->syms.udev_enumerate_add_match_subsystem(enumerate,
"sound");
215 _this->syms.udev_enumerate_scan_devices(enumerate);
216 devs =
_this->syms.udev_enumerate_get_list_entry(enumerate);
217 for (item = devs; item; item =
_this->syms.udev_list_entry_get_next(item)) {
218 const char *
path =
_this->syms.udev_list_entry_get_name(item);
219 struct udev_device *dev =
_this->syms.udev_device_new_from_syspath(
_this->udev, path);
221 device_event(SDL_UDEV_DEVICEADDED, dev);
222 _this->syms.udev_device_unref(dev);
226 _this->syms.udev_enumerate_unref(enumerate);
231 SDL_UDEV_UnloadLibrary(
void)
244 SDL_UDEV_LoadLibrary(
void)
253 if (SDL_UDEV_load_syms() == 0) {
257 #ifdef SDL_UDEV_DYNAMIC 262 retval = SDL_UDEV_load_syms();
264 SDL_UDEV_UnloadLibrary();
274 retval = SDL_UDEV_load_syms();
276 SDL_UDEV_UnloadLibrary();
293 #define BITS_PER_LONG (sizeof(unsigned long) * 8) 294 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) 295 #define OFF(x) ((x)%BITS_PER_LONG) 296 #define LONG(x) ((x)/BITS_PER_LONG) 297 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1) 299 static void get_caps(
struct udev_device *dev,
struct udev_device *pdev,
const char *attr,
unsigned long *bitmask,
size_t bitmask_len)
307 SDL_memset(bitmask, 0, bitmask_len*
sizeof(*bitmask));
308 value =
_this->syms.udev_device_get_sysattr_value(pdev, attr);
317 if (i < bitmask_len) {
324 if (i < bitmask_len) {
330 guess_device_class(
struct udev_device *dev)
333 struct udev_device *pdev;
334 unsigned long bitmask_ev[NBITS(EV_MAX)];
335 unsigned long bitmask_abs[NBITS(ABS_MAX)];
336 unsigned long bitmask_key[NBITS(KEY_MAX)];
337 unsigned long bitmask_rel[NBITS(REL_MAX)];
338 unsigned long keyboard_mask;
343 while (pdev && !
_this->syms.udev_device_get_sysattr_value(pdev,
"capabilities/ev")) {
344 pdev =
_this->syms.udev_device_get_parent_with_subsystem_devtype(pdev,
"input",
NULL);
350 get_caps(dev, pdev,
"capabilities/ev", bitmask_ev,
SDL_arraysize(bitmask_ev));
351 get_caps(dev, pdev,
"capabilities/abs", bitmask_abs,
SDL_arraysize(bitmask_abs));
352 get_caps(dev, pdev,
"capabilities/rel", bitmask_rel,
SDL_arraysize(bitmask_rel));
353 get_caps(dev, pdev,
"capabilities/key", bitmask_key,
SDL_arraysize(bitmask_key));
355 if (test_bit(EV_ABS, bitmask_ev) &&
356 test_bit(ABS_X, bitmask_abs) && test_bit(ABS_Y, bitmask_abs)) {
357 if (test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key)) {
359 }
else if (test_bit(BTN_TOOL_FINGER, bitmask_key) && !test_bit(BTN_TOOL_PEN, bitmask_key)) {
361 }
else if (test_bit(BTN_MOUSE, bitmask_key)) {
362 devclass |= SDL_UDEV_DEVICE_MOUSE;
363 }
else if (test_bit(BTN_TOUCH, bitmask_key)) {
366 devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
369 if (test_bit(BTN_TRIGGER, bitmask_key) ||
370 test_bit(BTN_A, bitmask_key) ||
371 test_bit(BTN_1, bitmask_key) ||
372 test_bit(ABS_RX, bitmask_abs) ||
373 test_bit(ABS_RY, bitmask_abs) ||
374 test_bit(ABS_RZ, bitmask_abs) ||
375 test_bit(ABS_THROTTLE, bitmask_abs) ||
376 test_bit(ABS_RUDDER, bitmask_abs) ||
377 test_bit(ABS_WHEEL, bitmask_abs) ||
378 test_bit(ABS_GAS, bitmask_abs) ||
379 test_bit(ABS_BRAKE, bitmask_abs)) {
380 devclass |= SDL_UDEV_DEVICE_JOYSTICK;
384 if (test_bit(EV_REL, bitmask_ev) &&
385 test_bit(REL_X, bitmask_rel) && test_bit(REL_Y, bitmask_rel) &&
386 test_bit(BTN_MOUSE, bitmask_key)) {
387 devclass |= SDL_UDEV_DEVICE_MOUSE;
392 keyboard_mask = 0xFFFFFFFE;
393 if ((bitmask_key[0] & keyboard_mask) != 0)
394 devclass |= SDL_UDEV_DEVICE_KEYBOARD;
400 device_event(SDL_UDEV_deviceevent
type,
struct udev_device *dev)
402 const char *subsystem;
406 SDL_UDEV_CallbackList *item;
408 path =
_this->syms.udev_device_get_devnode(dev);
413 subsystem =
_this->syms.udev_device_get_subsystem(dev);
415 devclass = SDL_UDEV_DEVICE_SOUND;
416 }
else if (
SDL_strcmp(subsystem,
"input") == 0) {
419 val =
_this->syms.udev_device_get_property_value(dev,
"ID_INPUT_JOYSTICK");
421 devclass |= SDL_UDEV_DEVICE_JOYSTICK;
424 val =
_this->syms.udev_device_get_property_value(dev,
"ID_INPUT_MOUSE");
426 devclass |= SDL_UDEV_DEVICE_MOUSE;
429 val =
_this->syms.udev_device_get_property_value(dev,
"ID_INPUT_TOUCHSCREEN");
431 devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
440 val =
_this->syms.udev_device_get_property_value(dev,
"ID_INPUT_KEY");
442 devclass |= SDL_UDEV_DEVICE_KEYBOARD;
447 val =
_this->syms.udev_device_get_property_value(dev,
"ID_CLASS");
450 devclass = SDL_UDEV_DEVICE_JOYSTICK;
452 devclass = SDL_UDEV_DEVICE_MOUSE;
454 devclass = SDL_UDEV_DEVICE_KEYBOARD;
460 devclass = guess_device_class(dev);
468 for (item =
_this->first; item !=
NULL; item = item->next) {
469 item->callback(type, devclass, path);
476 struct udev_device *dev =
NULL;
483 while (SDL_UDEV_hotplug_update_available()) {
484 dev =
_this->syms.udev_monitor_receive_device(
_this->udev_mon);
488 action =
_this->syms.udev_device_get_action(dev);
494 device_event(SDL_UDEV_DEVICEADDED, dev);
495 }
else if (
SDL_strcmp(action,
"remove") == 0) {
496 device_event(SDL_UDEV_DEVICEREMOVED, dev);
499 _this->syms.udev_device_unref(dev);
504 SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
506 SDL_UDEV_CallbackList *item;
507 item = (SDL_UDEV_CallbackList *)
SDL_calloc(1,
sizeof (SDL_UDEV_CallbackList));
517 _this->last->next = item;
525 SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
527 SDL_UDEV_CallbackList *item;
528 SDL_UDEV_CallbackList *prev =
NULL;
530 for (item =
_this->first; item !=
NULL; item = item->next) {
532 if (item->callback == cb) {
534 prev->next = item->next;
537 _this->first = item->next;
539 if (item ==
_this->last) {
550 const SDL_UDEV_Symbols *
551 SDL_UDEV_GetUdevSyms(
void)
553 if (SDL_UDEV_Init() < 0) {
562 SDL_UDEV_ReleaseUdevSyms(
void)
int SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
static SDL_VideoDevice * _this
GLsizei const GLfloat * value
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
#define SDL_assert(condition)
#define SDL_OutOfMemory()
static char text[MAX_TEXT_LENGTH]
GLuint GLuint GLsizei GLenum type
#define SDL_arraysize(array)
GLsizei const GLchar *const * path
void * SDL_LoadFunction(void *handle, const char *name)
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 DST endif subs bhs tst beq exit_label trailing_15bytes unaligned_mask endm macro narrow_case_inner_loop_and_trailing_pixels unaligned_mask tst conditional_process1 trailing_15bytes unaligned_mask endm macro switch_on_alignment action