mirror of
https://github.com/lvgl/lvgl.git
synced 2025-02-04 07:13:00 +08:00
feat(sdl): free resources automatically on display removal (#4294)
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
This commit is contained in:
parent
03a9828a56
commit
0ef7dc0ae3
@ -158,6 +158,8 @@ void lv_disp_remove(lv_disp_t * disp)
|
|||||||
bool was_default = false;
|
bool was_default = false;
|
||||||
if(disp == lv_disp_get_default()) was_default = true;
|
if(disp == lv_disp_get_default()) was_default = true;
|
||||||
|
|
||||||
|
lv_disp_send_event(disp, LV_EVENT_DELETE, NULL);
|
||||||
|
|
||||||
/*Detach the input devices*/
|
/*Detach the input devices*/
|
||||||
lv_indev_t * indev;
|
lv_indev_t * indev;
|
||||||
indev = lv_indev_get_next(NULL);
|
indev = lv_indev_get_next(NULL);
|
||||||
|
@ -39,6 +39,7 @@ static void window_update(lv_disp_t * disp);
|
|||||||
static void clean_up(lv_disp_t * disp);
|
static void clean_up(lv_disp_t * disp);
|
||||||
static void texture_resize(lv_disp_t * disp);
|
static void texture_resize(lv_disp_t * disp);
|
||||||
static void sdl_event_handler(lv_timer_t * t);
|
static void sdl_event_handler(lv_timer_t * t);
|
||||||
|
static void release_disp_cb(lv_event_t * e);
|
||||||
|
|
||||||
/***********************
|
/***********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
@ -89,6 +90,7 @@ lv_disp_t * lv_sdl_window_create(lv_coord_t hor_res, lv_coord_t ver_res)
|
|||||||
lv_free(dsc);
|
lv_free(dsc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
lv_disp_add_event(disp, release_disp_cb, LV_EVENT_DELETE, disp);
|
||||||
lv_disp_set_driver_data(disp, dsc);
|
lv_disp_set_driver_data(disp, dsc);
|
||||||
window_create(disp);
|
window_create(disp);
|
||||||
|
|
||||||
@ -141,6 +143,15 @@ void lv_sdl_window_set_title(lv_disp_t * disp, const char * title)
|
|||||||
SDL_SetWindowTitle(dsc->window, title);
|
SDL_SetWindowTitle(dsc->window, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lv_sdl_quit()
|
||||||
|
{
|
||||||
|
if(inited) {
|
||||||
|
SDL_Quit();
|
||||||
|
lv_timer_del(event_handler_timer);
|
||||||
|
inited = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
@ -236,7 +247,6 @@ static void clean_up(lv_disp_t * disp)
|
|||||||
SDL_DestroyWindow(dsc->window);
|
SDL_DestroyWindow(dsc->window);
|
||||||
|
|
||||||
lv_free(dsc);
|
lv_free(dsc);
|
||||||
lv_disp_remove(disp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_create(lv_disp_t * disp)
|
static void window_create(lv_disp_t * disp)
|
||||||
@ -335,4 +345,10 @@ static int tick_thread(void * ptr)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void release_disp_cb(lv_event_t * e)
|
||||||
|
{
|
||||||
|
lv_disp_t * disp = (lv_disp_t *) lv_event_get_user_data(e);
|
||||||
|
clean_up(disp);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /*LV_USE_SDL*/
|
#endif /*LV_USE_SDL*/
|
||||||
|
@ -41,6 +41,8 @@ lv_disp_t * _lv_sdl_get_disp_from_win_id(uint32_t win_id);
|
|||||||
|
|
||||||
void lv_sdl_window_set_title(lv_disp_t * disp, const char * title);
|
void lv_sdl_window_set_title(lv_disp_t * disp, const char * title);
|
||||||
|
|
||||||
|
void lv_sdl_quit();
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
**********************/
|
**********************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user