30 #ifdef SDL_USE_LIBUDEV 32 #include <linux/input.h> 36 static const char* SDL_UDEV_LIBS[] = {
"libudev.so.1",
"libudev.so.0" };
38 #define _THIS SDL_UDEV_PrivateData *_this 41 static SDL_bool SDL_UDEV_load_sym(
const char *fn,
void **
addr);
42 static int SDL_UDEV_load_syms(
void);
43 static SDL_bool SDL_UDEV_hotplug_update_available(
void);
44 static void device_event(SDL_UDEV_deviceevent
type,
struct udev_device *dev);
47 SDL_UDEV_load_sym(
const char *fn,
void **
addr)
59 SDL_UDEV_load_syms(
void)
62 #define SDL_UDEV_SYM(x) \ 63 if (!SDL_UDEV_load_sym(#x, (void **) (char *) & _this->x)) return -1 65 SDL_UDEV_SYM(udev_device_get_action);
66 SDL_UDEV_SYM(udev_device_get_devnode);
67 SDL_UDEV_SYM(udev_device_get_subsystem);
68 SDL_UDEV_SYM(udev_device_get_parent_with_subsystem_devtype);
69 SDL_UDEV_SYM(udev_device_get_property_value);
70 SDL_UDEV_SYM(udev_device_get_sysattr_value);
71 SDL_UDEV_SYM(udev_device_new_from_syspath);
72 SDL_UDEV_SYM(udev_device_unref);
73 SDL_UDEV_SYM(udev_enumerate_add_match_property);
74 SDL_UDEV_SYM(udev_enumerate_add_match_subsystem);
75 SDL_UDEV_SYM(udev_enumerate_get_list_entry);
76 SDL_UDEV_SYM(udev_enumerate_new);
77 SDL_UDEV_SYM(udev_enumerate_scan_devices);
78 SDL_UDEV_SYM(udev_enumerate_unref);
79 SDL_UDEV_SYM(udev_list_entry_get_name);
80 SDL_UDEV_SYM(udev_list_entry_get_next);
81 SDL_UDEV_SYM(udev_monitor_enable_receiving);
82 SDL_UDEV_SYM(udev_monitor_filter_add_match_subsystem_devtype);
83 SDL_UDEV_SYM(udev_monitor_get_fd);
84 SDL_UDEV_SYM(udev_monitor_new_from_netlink);
85 SDL_UDEV_SYM(udev_monitor_receive_device);
86 SDL_UDEV_SYM(udev_monitor_unref);
87 SDL_UDEV_SYM(udev_new);
88 SDL_UDEV_SYM(udev_unref);
89 SDL_UDEV_SYM(udev_device_new_from_devnum);
90 SDL_UDEV_SYM(udev_device_get_devnum);
97 SDL_UDEV_hotplug_update_available(
void)
100 const int fd =
_this->udev_monitor_get_fd(
_this->udev_mon);
108 if ((select(fd+1, &fds,
NULL,
NULL, &tv) > 0) && (FD_ISSET(fd, &fds))) {
127 retval = SDL_UDEV_LoadLibrary();
143 _this->udev_mon =
_this->udev_monitor_new_from_netlink(
_this->udev,
"udev");
146 return SDL_SetError(
"udev_monitor_new_from_netlink() failed");
149 _this->udev_monitor_filter_add_match_subsystem_devtype(
_this->udev_mon,
"input",
NULL);
150 _this->udev_monitor_filter_add_match_subsystem_devtype(
_this->udev_mon,
"sound",
NULL);
151 _this->udev_monitor_enable_receiving(
_this->udev_mon);
158 _this->ref_count += 1;
166 SDL_UDEV_CallbackList *item;
172 _this->ref_count -= 1;
174 if (
_this->ref_count < 1) {
192 SDL_UDEV_UnloadLibrary();
201 struct udev_enumerate *enumerate =
NULL;
202 struct udev_list_entry *devs =
NULL;
203 struct udev_list_entry *item =
NULL;
209 enumerate =
_this->udev_enumerate_new(
_this->udev);
210 if (enumerate ==
NULL) {
216 _this->udev_enumerate_add_match_subsystem(enumerate,
"input");
217 _this->udev_enumerate_add_match_subsystem(enumerate,
"sound");
219 _this->udev_enumerate_scan_devices(enumerate);
220 devs =
_this->udev_enumerate_get_list_entry(enumerate);
221 for (item = devs; item; item =
_this->udev_list_entry_get_next(item)) {
222 const char *
path =
_this->udev_list_entry_get_name(item);
223 struct udev_device *dev =
_this->udev_device_new_from_syspath(
_this->udev, path);
225 device_event(SDL_UDEV_DEVICEADDED, dev);
226 _this->udev_device_unref(dev);
230 _this->udev_enumerate_unref(enumerate);
235 SDL_UDEV_UnloadLibrary(
void)
248 SDL_UDEV_LoadLibrary(
void)
261 retval = SDL_UDEV_load_syms();
263 SDL_UDEV_UnloadLibrary();
280 #define BITS_PER_LONG (sizeof(unsigned long) * 8) 281 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) 282 #define OFF(x) ((x)%BITS_PER_LONG) 283 #define BIT(x) (1UL<<OFF(x)) 284 #define LONG(x) ((x)/BITS_PER_LONG) 285 #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1) 287 static void get_caps(
struct udev_device *dev,
struct udev_device *pdev,
const char *attr,
unsigned long *bitmask,
size_t bitmask_len)
295 SDL_memset(bitmask, 0, bitmask_len*
sizeof(*bitmask));
296 value =
_this->udev_device_get_sysattr_value(pdev, attr);
305 if (i < bitmask_len) {
312 if (i < bitmask_len) {
318 guess_device_class(
struct udev_device *dev)
321 struct udev_device *pdev;
322 unsigned long bitmask_ev[NBITS(EV_MAX)];
323 unsigned long bitmask_abs[NBITS(ABS_MAX)];
324 unsigned long bitmask_key[NBITS(KEY_MAX)];
325 unsigned long bitmask_rel[NBITS(REL_MAX)];
326 unsigned long keyboard_mask;
331 while (pdev && !
_this->udev_device_get_sysattr_value(pdev,
"capabilities/ev")) {
332 pdev =
_this->udev_device_get_parent_with_subsystem_devtype(pdev,
"input",
NULL);
338 get_caps(dev, pdev,
"capabilities/ev", bitmask_ev,
SDL_arraysize(bitmask_ev));
339 get_caps(dev, pdev,
"capabilities/abs", bitmask_abs,
SDL_arraysize(bitmask_abs));
340 get_caps(dev, pdev,
"capabilities/rel", bitmask_rel,
SDL_arraysize(bitmask_rel));
341 get_caps(dev, pdev,
"capabilities/key", bitmask_key,
SDL_arraysize(bitmask_key));
343 if (test_bit(EV_ABS, bitmask_ev) &&
344 test_bit(ABS_X, bitmask_abs) && test_bit(ABS_Y, bitmask_abs)) {
345 if (test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key)) {
347 }
else if (test_bit(BTN_TOOL_FINGER, bitmask_key) && !test_bit(BTN_TOOL_PEN, bitmask_key)) {
349 }
else if (test_bit(BTN_MOUSE, bitmask_key)) {
350 devclass |= SDL_UDEV_DEVICE_MOUSE;
351 }
else if (test_bit(BTN_TOUCH, bitmask_key)) {
354 devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
357 if (test_bit(BTN_TRIGGER, bitmask_key) ||
358 test_bit(BTN_A, bitmask_key) ||
359 test_bit(BTN_1, bitmask_key) ||
360 test_bit(ABS_RX, bitmask_abs) ||
361 test_bit(ABS_RY, bitmask_abs) ||
362 test_bit(ABS_RZ, bitmask_abs) ||
363 test_bit(ABS_THROTTLE, bitmask_abs) ||
364 test_bit(ABS_RUDDER, bitmask_abs) ||
365 test_bit(ABS_WHEEL, bitmask_abs) ||
366 test_bit(ABS_GAS, bitmask_abs) ||
367 test_bit(ABS_BRAKE, bitmask_abs)) {
368 devclass |= SDL_UDEV_DEVICE_JOYSTICK;
372 if (test_bit(EV_REL, bitmask_ev) &&
373 test_bit(REL_X, bitmask_rel) && test_bit(REL_Y, bitmask_rel) &&
374 test_bit(BTN_MOUSE, bitmask_key)) {
375 devclass |= SDL_UDEV_DEVICE_MOUSE;
380 keyboard_mask = 0xFFFFFFFE;
381 if ((bitmask_key[0] & keyboard_mask) != 0)
382 devclass |= SDL_UDEV_DEVICE_KEYBOARD;
388 device_event(SDL_UDEV_deviceevent
type,
struct udev_device *dev)
390 const char *subsystem;
394 SDL_UDEV_CallbackList *item;
396 path =
_this->udev_device_get_devnode(dev);
401 subsystem =
_this->udev_device_get_subsystem(dev);
403 devclass = SDL_UDEV_DEVICE_SOUND;
404 }
else if (
SDL_strcmp(subsystem,
"input") == 0) {
407 val =
_this->udev_device_get_property_value(dev,
"ID_INPUT_JOYSTICK");
409 devclass |= SDL_UDEV_DEVICE_JOYSTICK;
412 val =
_this->udev_device_get_property_value(dev,
"ID_INPUT_MOUSE");
414 devclass |= SDL_UDEV_DEVICE_MOUSE;
417 val =
_this->udev_device_get_property_value(dev,
"ID_INPUT_TOUCHSCREEN");
419 devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
428 val =
_this->udev_device_get_property_value(dev,
"ID_INPUT_KEY");
430 devclass |= SDL_UDEV_DEVICE_KEYBOARD;
435 val =
_this->udev_device_get_property_value(dev,
"ID_CLASS");
438 devclass = SDL_UDEV_DEVICE_JOYSTICK;
440 devclass = SDL_UDEV_DEVICE_MOUSE;
442 devclass = SDL_UDEV_DEVICE_KEYBOARD;
448 devclass = guess_device_class(dev);
456 for (item =
_this->first; item !=
NULL; item = item->next) {
457 item->callback(type, devclass, path);
464 struct udev_device *dev =
NULL;
471 while (SDL_UDEV_hotplug_update_available()) {
472 dev =
_this->udev_monitor_receive_device(
_this->udev_mon);
476 action =
_this->udev_device_get_action(dev);
482 device_event(SDL_UDEV_DEVICEADDED, dev);
483 }
else if (
SDL_strcmp(action,
"remove") == 0) {
484 device_event(SDL_UDEV_DEVICEREMOVED, dev);
487 _this->udev_device_unref(dev);
492 SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
494 SDL_UDEV_CallbackList *item;
495 item = (SDL_UDEV_CallbackList *)
SDL_calloc(1,
sizeof (SDL_UDEV_CallbackList));
505 _this->last->next = item;
513 SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
515 SDL_UDEV_CallbackList *item;
516 SDL_UDEV_CallbackList *prev =
NULL;
518 for (item =
_this->first; item !=
NULL; item = item->next) {
520 if (item->callback == cb) {
522 prev->next = item->next;
525 _this->first = item->next;
527 if (item ==
_this->last) {
static SDL_VideoDevice * _this
GLuint GLuint GLsizei GLenum type
void * SDL_calloc(size_t nmemb, size_t size)
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]
#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