From: giwoong.kim Date: Mon, 17 Sep 2012 07:49:17 +0000 (+0900) Subject: [Title] notify the touch driver to accept events in mloop X-Git-Tag: TizenStudio_2.0_p2.3~1311 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21996e215eb19f2cd23fa1e5b4f86c4975427250;p=sdk%2Femulator%2Fqemu.git [Title] notify the touch driver to accept events in mloop [Type] feature [Module] Emulator / touch [Priority] major [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- diff --git a/input.c b/input.c index 8087d76..ad57eb4 100644 --- a/input.c +++ b/input.c @@ -189,7 +189,7 @@ void kbd_mouse_event(int dx, int dy, int dz, int buttons_state) /* if mouse event is wheelup ,wheeldown or move then go to ps2 mouse event(index == 0) */ if((buttons_state > 3 && entry->index == 0)) { - INFO("input device: %s, event: %d\n", entry->qemu_put_mouse_event_name, buttons_state); + //INFO("input device: %s, event: %d\n", entry->qemu_put_mouse_event_name, buttons_state); buttons_state = 0; mouse_event = entry->qemu_put_mouse_event; mouse_event_opaque = entry->qemu_put_mouse_event_opaque; @@ -201,7 +201,7 @@ void kbd_mouse_event(int dx, int dy, int dz, int buttons_state) entry = QTAILQ_FIRST(&mouse_handlers); mouse_event = entry->qemu_put_mouse_event; mouse_event_opaque = entry->qemu_put_mouse_event_opaque; - INFO("input device: %s, event: %d\n", entry->qemu_put_mouse_event_name, buttons_state); + //INFO("input device: %s, event: %d\n", entry->qemu_put_mouse_event_name, buttons_state); } #else entry = QTAILQ_FIRST(&mouse_handlers); diff --git a/tizen/src/hw/maru_virtio_touchscreen.c b/tizen/src/hw/maru_virtio_touchscreen.c index f79e34e..dfd4ed3 100644 --- a/tizen/src/hw/maru_virtio_touchscreen.c +++ b/tizen/src/hw/maru_virtio_touchscreen.c @@ -31,13 +31,14 @@ #include "console.h" #include "maru_virtio_touchscreen.h" #include "maru_device_ids.h" +#include "mloop_event.h" #include "debug_ch.h" MULTI_DEBUG_CHANNEL(qemu, touchscreen); #define DEVICE_NAME "virtio-touchscreen" -#define MAX_TOUCH_EVENT_CNT 128 +#define MAX_TOUCH_EVENT_CNT 16 /* This structure must match the kernel definitions */ typedef struct EmulTouchEvent { @@ -71,25 +72,21 @@ typedef struct TouchscreenState TouchscreenState *ts; -// lock for between communication thread and IO thread -//static pthread_mutex_t event_mutex = PTHREAD_MUTEX_INITIALIZER; +/* lock for between communication thread and IO thread */ +static pthread_mutex_t event_mutex = PTHREAD_MUTEX_INITIALIZER; void virtio_touchscreen_event(void *opaque, int x, int y, int z, int buttons_state) { TouchEventEntry *entry = NULL; - TouchscreenState *ts = opaque; - VirtQueueElement elem; - //pthread_mutex_lock(&event_mutex); + pthread_mutex_lock(&event_mutex); -#if 0 if (queue_cnt >= MAX_TOUCH_EVENT_CNT) { pthread_mutex_unlock(&event_mutex); INFO("full touch event queue, lose event\n", queue_cnt); return; } -#endif entry = &(_events_buf[ringbuf_cnt % MAX_TOUCH_EVENT_CNT]); ringbuf_cnt++; @@ -101,15 +98,11 @@ void virtio_touchscreen_event(void *opaque, int x, int y, int z, int buttons_sta entry->touch.z = z; entry->touch.state = buttons_state; - //QTAILQ_INSERT_TAIL(&events_queue, entry, node); + QTAILQ_INSERT_TAIL(&events_queue, entry, node); - /* virtio */ - virtqueue_pop(ts->vq, &elem); - memcpy(elem.in_sg[0].iov_base, &(entry->touch), sizeof(EmulTouchEvent)); - virtqueue_push(ts->vq, &elem, 0); - virtio_notify(&(ts->vdev), ts->vq); + pthread_mutex_unlock(&event_mutex); - //pthread_mutex_unlock(&event_mutex); + mloop_evcmd_touch(); INFO("touch event (%d) : x=%d, y=%d, z=%d, state=%d\n", entry->index, entry->touch.x, entry->touch.y, entry->touch.z, entry->touch.state); @@ -140,6 +133,34 @@ static void maru_virtio_touchscreen_handle(VirtIODevice *vdev, VirtQueue *vq) } +void maru_virtio_touchscreen_notify(void) +{ + TouchEventEntry *entry = NULL; + VirtQueueElement elem; + + INFO("maru_virtio_touchscreen_notify\n"); + + /* get from virtio queue */ + virtqueue_pop(ts->vq, &elem); + + pthread_mutex_lock(&event_mutex); + + /* get from host event queue */ + entry = QTAILQ_FIRST(&events_queue); + /* copy host event into virtio queue */ + memcpy(elem.in_sg[0].iov_base, &(entry->touch), sizeof(EmulTouchEvent)); + /* remove host event */ + QTAILQ_REMOVE(&events_queue, entry, node); + queue_cnt--; + + pthread_mutex_unlock(&event_mutex); + + /* put into virtio queue */ + virtqueue_push(ts->vq, &elem, 0); + /* notify to guest */ + virtio_notify(&(ts->vdev), ts->vq); +} + static uint32_t virtio_touchscreen_get_features(VirtIODevice *vdev, uint32_t request_features) { // TODO: diff --git a/tizen/src/hw/maru_virtio_touchscreen.h b/tizen/src/hw/maru_virtio_touchscreen.h index 3a2c123..536f0f1 100644 --- a/tizen/src/hw/maru_virtio_touchscreen.h +++ b/tizen/src/hw/maru_virtio_touchscreen.h @@ -33,6 +33,7 @@ #include "virtio.h" void virtio_touchscreen_event(void *opaque, int x, int y, int z, int buttons_state); +void maru_virtio_touchscreen_notify(void); #endif /* MARU_TOUCHSCREEN_H_ */ diff --git a/tizen/src/mloop_event.c b/tizen/src/mloop_event.c index 3d4570e..aadb33a 100644 --- a/tizen/src/mloop_event.c +++ b/tizen/src/mloop_event.c @@ -67,9 +67,11 @@ struct mloop_evpack { #define MLOOP_EVTYPE_USB_DEL 2 #define MLOOP_EVTYPE_INTR_UP 3 #define MLOOP_EVTYPE_INTR_DOWN 4 -#define MLLOP_EVTYPE_HWKEY 5 +#define MLOOP_EVTYPE_HWKEY 5 +#define MLOOP_EVTYPE_TOUCH 6 -static struct mloop_evsock mloop = {-1,0,0}; + +static struct mloop_evsock mloop = {-1, 0, 0}; static int mloop_evsock_create(struct mloop_evsock *ev) { @@ -241,8 +243,8 @@ static void mloop_evhandle_intr_down(long data) static void mloop_evhandle_hwkey(struct mloop_evpack* pack) { - int event_type; - int keycode; + int event_type = 0; + int keycode = 0; memcpy(&event_type, pack->data, sizeof(int)); memcpy(&keycode, pack->data + sizeof(int), sizeof(int)); @@ -260,6 +262,11 @@ static void mloop_evhandle_hwkey(struct mloop_evpack* pack) } } +static void mloop_evhandle_touch(struct mloop_evpack* pack) +{ + maru_virtio_touchscreen_notify(); +} + static void mloop_evcb_recv(struct mloop_evsock *ev) { struct mloop_evpack pack; @@ -297,9 +304,12 @@ static void mloop_evcb_recv(struct mloop_evsock *ev) case MLOOP_EVTYPE_INTR_DOWN: mloop_evhandle_intr_down(ntohl(*(long*)&pack.data[0])); break; - case MLLOP_EVTYPE_HWKEY: + case MLOOP_EVTYPE_HWKEY: mloop_evhandle_hwkey(&pack); break; + case MLOOP_EVTYPE_TOUCH: + mloop_evhandle_touch(&pack); + break; default: break; } @@ -387,7 +397,7 @@ void mloop_evcmd_hwkey(int event_type, int keycode) { struct mloop_evpack pack; - pack.type = htons(MLLOP_EVTYPE_HWKEY); + pack.type = htons(MLOOP_EVTYPE_HWKEY); pack.size = htons(5 + 8); //TODO: ? memcpy(pack.data, &event_type, sizeof(int)); @@ -397,3 +407,13 @@ void mloop_evcmd_hwkey(int event_type, int keycode) mloop_evsock_send(&mloop, &pack); } +void mloop_evcmd_touch(void) +{ + struct mloop_evpack pack; + memset(&pack, 0, sizeof(struct mloop_evpack)); + + pack.type = htons(MLOOP_EVTYPE_TOUCH); + pack.size = htons(5); + mloop_evsock_send(&mloop, &pack); +} + diff --git a/tizen/src/mloop_event.h b/tizen/src/mloop_event.h index ce0ff3e..7fb8434 100644 --- a/tizen/src/mloop_event.h +++ b/tizen/src/mloop_event.h @@ -47,6 +47,7 @@ void mloop_evcmd_raise_intr(void *irq); void mloop_evcmd_lower_intr(void *irq); void mloop_evcmd_hwkey(int event_type, int keycode); +void mloop_evcmd_touch(void); #ifdef __cplusplus }