mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-28 13:36:27 +08:00
fix(indev_gesture): fix memory leak when deleting indev (#8814)
Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com> Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
+3
-20
@@ -81,7 +81,6 @@ static void indev_gesture(lv_indev_t * indev);
|
|||||||
static bool indev_reset_check(lv_indev_t * indev);
|
static bool indev_reset_check(lv_indev_t * indev);
|
||||||
static void indev_read_core(lv_indev_t * indev, lv_indev_data_t * data);
|
static void indev_read_core(lv_indev_t * indev, lv_indev_data_t * data);
|
||||||
static void indev_reset_core(lv_indev_t * indev, lv_obj_t * obj);
|
static void indev_reset_core(lv_indev_t * indev, lv_obj_t * obj);
|
||||||
static void indev_init_gesture_recognizers(lv_indev_t * indev);
|
|
||||||
static lv_result_t send_event(lv_event_code_t code, void * param);
|
static lv_result_t send_event(lv_event_code_t code, void * param);
|
||||||
|
|
||||||
static void indev_scroll_throw_anim_start(lv_indev_t * indev);
|
static void indev_scroll_throw_anim_start(lv_indev_t * indev);
|
||||||
@@ -143,7 +142,9 @@ lv_indev_t * lv_indev_create(void)
|
|||||||
indev->gesture_min_velocity = LV_INDEV_DEF_GESTURE_MIN_VELOCITY;
|
indev->gesture_min_velocity = LV_INDEV_DEF_GESTURE_MIN_VELOCITY;
|
||||||
indev->rotary_sensitivity = LV_INDEV_DEF_ROTARY_SENSITIVITY;
|
indev->rotary_sensitivity = LV_INDEV_DEF_ROTARY_SENSITIVITY;
|
||||||
|
|
||||||
indev_init_gesture_recognizers(indev);
|
#if LV_USE_GESTURE_RECOGNITION
|
||||||
|
lv_indev_gesture_init(indev);
|
||||||
|
#endif
|
||||||
|
|
||||||
return indev;
|
return indev;
|
||||||
}
|
}
|
||||||
@@ -1912,21 +1913,3 @@ static void indev_scroll_throw_anim_start(lv_indev_t * indev)
|
|||||||
|
|
||||||
indev->scroll_throw_anim = lv_anim_start(&a);
|
indev->scroll_throw_anim = lv_anim_start(&a);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize this indev's recognizers. It specify their recognizer function
|
|
||||||
* @param indev pointer to the indev containing the recognizers to initialize
|
|
||||||
*/
|
|
||||||
static void indev_init_gesture_recognizers(lv_indev_t * indev)
|
|
||||||
{
|
|
||||||
#if LV_USE_GESTURE_RECOGNITION
|
|
||||||
indev->recognizers[LV_INDEV_GESTURE_NONE].recog_fn = NULL;
|
|
||||||
indev->recognizers[LV_INDEV_GESTURE_PINCH].recog_fn = lv_indev_gesture_detect_pinch;
|
|
||||||
indev->recognizers[LV_INDEV_GESTURE_ROTATE].recog_fn = lv_indev_gesture_detect_rotation;
|
|
||||||
indev->recognizers[LV_INDEV_GESTURE_TWO_FINGERS_SWIPE].recog_fn = lv_indev_gesture_detect_two_fingers_swipe;
|
|
||||||
indev->recognizers[LV_INDEV_GESTURE_SCROLL].recog_fn = NULL;
|
|
||||||
indev->recognizers[LV_INDEV_GESTURE_SWIPE].recog_fn = NULL;
|
|
||||||
#else
|
|
||||||
LV_UNUSED(indev);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ static lv_indev_gesture_recognizer_t * lv_indev_get_gesture_recognizer(lv_event_
|
|||||||
lv_indev_gesture_type_t type);
|
lv_indev_gesture_type_t type);
|
||||||
static lv_dir_t calculate_swipe_dir(lv_indev_gesture_recognizer_t * recognizer);
|
static lv_dir_t calculate_swipe_dir(lv_indev_gesture_recognizer_t * recognizer);
|
||||||
static lv_indev_gesture_type_t get_first_recognized_or_ended_gesture(lv_indev_t * indev);
|
static lv_indev_gesture_type_t get_first_recognized_or_ended_gesture(lv_indev_t * indev);
|
||||||
|
static void indev_delete_event_cb(lv_event_t * e);
|
||||||
|
|
||||||
/********************
|
/********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
@@ -66,6 +67,19 @@ static lv_indev_gesture_type_t get_first_recognized_or_ended_gesture(lv_indev_t
|
|||||||
* GLOBAL FUNCTIONS
|
* GLOBAL FUNCTIONS
|
||||||
********************/
|
********************/
|
||||||
|
|
||||||
|
void lv_indev_gesture_init(lv_indev_t * indev)
|
||||||
|
{
|
||||||
|
LV_ASSERT_NULL(indev);
|
||||||
|
indev->recognizers[LV_INDEV_GESTURE_NONE].recog_fn = NULL;
|
||||||
|
indev->recognizers[LV_INDEV_GESTURE_PINCH].recog_fn = lv_indev_gesture_detect_pinch;
|
||||||
|
indev->recognizers[LV_INDEV_GESTURE_ROTATE].recog_fn = lv_indev_gesture_detect_rotation;
|
||||||
|
indev->recognizers[LV_INDEV_GESTURE_TWO_FINGERS_SWIPE].recog_fn = lv_indev_gesture_detect_two_fingers_swipe;
|
||||||
|
indev->recognizers[LV_INDEV_GESTURE_SCROLL].recog_fn = NULL;
|
||||||
|
indev->recognizers[LV_INDEV_GESTURE_SWIPE].recog_fn = NULL;
|
||||||
|
|
||||||
|
lv_indev_add_event_cb(indev, indev_delete_event_cb, LV_EVENT_DELETE, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void lv_indev_set_pinch_up_threshold(lv_indev_t * indev, float threshold)
|
void lv_indev_set_pinch_up_threshold(lv_indev_t * indev, float threshold)
|
||||||
{
|
{
|
||||||
/* A up threshold MUST always be bigger than 1 */
|
/* A up threshold MUST always be bigger than 1 */
|
||||||
@@ -946,5 +960,22 @@ static lv_indev_gesture_type_t get_first_recognized_or_ended_gesture(lv_indev_t
|
|||||||
return LV_INDEV_GESTURE_NONE;
|
return LV_INDEV_GESTURE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void indev_delete_event_cb(lv_event_t * e)
|
||||||
|
{
|
||||||
|
lv_indev_t * indev = lv_event_get_current_target(e);
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < LV_INDEV_GESTURE_CNT; i++) {
|
||||||
|
if(indev->recognizers[i].info) {
|
||||||
|
lv_free(indev->recognizers[i].info);
|
||||||
|
indev->recognizers[i].info = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(indev->recognizers[i].config) {
|
||||||
|
lv_free(indev->recognizers[i].config);
|
||||||
|
indev->recognizers[i].config = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* LV_USE_GESTURE_RECOGNITION */
|
#endif /* LV_USE_GESTURE_RECOGNITION */
|
||||||
|
|||||||
@@ -84,6 +84,11 @@ struct lv_indev_gesture_recognizer {
|
|||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize this indev's recognizers. It specifies their recognizer functions
|
||||||
|
* @param indev pointer to the indev containing the recognizers to initialize
|
||||||
|
*/
|
||||||
|
void lv_indev_gesture_init(lv_indev_t * indev);
|
||||||
|
|
||||||
/* PINCH Gesture */
|
/* PINCH Gesture */
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,21 @@ void lv_test_indev_gesture_create(void)
|
|||||||
lv_indev_set_read_cb(_state.gesture_indev, lv_test_gesture_read_cb);
|
lv_indev_set_read_cb(_state.gesture_indev, lv_test_gesture_read_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lv_test_indev_gesture_delete(void)
|
||||||
|
{
|
||||||
|
if(_state.gesture_indev) {
|
||||||
|
lv_indev_delete(_state.gesture_indev);
|
||||||
|
_state.gesture_indev = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_state.touch_data) {
|
||||||
|
lv_free(_state.touch_data);
|
||||||
|
_state.touch_data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
_state.max_touch_cnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
lv_indev_t * lv_test_indev_get_gesture_indev(lv_indev_type_t type)
|
lv_indev_t * lv_test_indev_get_gesture_indev(lv_indev_type_t type)
|
||||||
{
|
{
|
||||||
switch(type) {
|
switch(type) {
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
void lv_test_indev_gesture_create(void);
|
void lv_test_indev_gesture_create(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the touch (pointer) indevs.
|
||||||
|
*/
|
||||||
|
void lv_test_indev_gesture_delete(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get one of the indev created in `lv_test_indev_gesture_create`
|
* Get one of the indev created in `lv_test_indev_gesture_create`
|
||||||
* @param type type of the indev to get
|
* @param type type of the indev to get
|
||||||
|
|||||||
Reference in New Issue
Block a user