fix(snapshot): fix memleak in lv_snapshot (#6147)
Signed-off-by: rongyichang <rongyichang@xiaomi.com>
This commit is contained in:
@@ -121,7 +121,7 @@ lv_result_t lv_snapshot_take_to_draw_buf(lv_obj_t * obj, lv_color_format_t cf, l
|
|||||||
|
|
||||||
while(layer.draw_task_head) {
|
while(layer.draw_task_head) {
|
||||||
lv_draw_dispatch_wait_for_request();
|
lv_draw_dispatch_wait_for_request();
|
||||||
lv_draw_dispatch_layer(NULL, &layer);
|
lv_draw_dispatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
disp_new->layer_head = layer_old;
|
disp_new->layer_head = layer_old;
|
||||||
|
|||||||
BIN
tests/ref_imgs/snapshot_2.png
Normal file
BIN
tests/ref_imgs/snapshot_2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "unity/unity.h"
|
#include "unity/unity.h"
|
||||||
|
|
||||||
#define NUM_SNAPSHOTS 1
|
#define NUM_SNAPSHOTS 10
|
||||||
|
|
||||||
void test_snapshot_should_not_leak_memory(void)
|
void test_snapshot_should_not_leak_memory(void)
|
||||||
{
|
{
|
||||||
@@ -34,6 +34,39 @@ void test_snapshot_should_not_leak_memory(void)
|
|||||||
TEST_ASSERT_EQUAL(initial_available_memory, final_available_memory);
|
TEST_ASSERT_EQUAL(initial_available_memory, final_available_memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_snapshot_with_transform_should_not_leak_memory(void)
|
||||||
|
{
|
||||||
|
uint32_t idx = 0;
|
||||||
|
size_t initial_available_memory = 0;
|
||||||
|
size_t final_available_memory = 0;
|
||||||
|
lv_mem_monitor_t monitor;
|
||||||
|
|
||||||
|
lv_draw_buf_t * snapshots[NUM_SNAPSHOTS] = {NULL};
|
||||||
|
lv_obj_t * label = lv_label_create(lv_screen_active());
|
||||||
|
lv_obj_center(label);
|
||||||
|
lv_obj_set_style_text_font(label, &lv_font_montserrat_28, 0);
|
||||||
|
lv_label_set_text(label, "Wubba lubba dub dub!");
|
||||||
|
lv_obj_set_style_transform_rotation(label, 450, 0);
|
||||||
|
|
||||||
|
lv_mem_monitor(&monitor);
|
||||||
|
initial_available_memory = monitor.free_size;
|
||||||
|
|
||||||
|
for(idx = 0; idx < NUM_SNAPSHOTS; idx++) {
|
||||||
|
snapshots[idx] = lv_snapshot_take(lv_screen_active(), LV_COLOR_FORMAT_NATIVE_WITH_ALPHA);
|
||||||
|
TEST_ASSERT_NOT_NULL(snapshots[idx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(idx = 0; idx < NUM_SNAPSHOTS; idx++) {
|
||||||
|
lv_draw_buf_destroy(snapshots[idx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_mem_monitor(&monitor);
|
||||||
|
final_available_memory = monitor.free_size;
|
||||||
|
lv_obj_delete(label);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(initial_available_memory, final_available_memory);
|
||||||
|
}
|
||||||
|
|
||||||
void test_snapshot_take_snapshot_immidiately_after_obj_create(void)
|
void test_snapshot_take_snapshot_immidiately_after_obj_create(void)
|
||||||
{
|
{
|
||||||
lv_obj_t * label = lv_label_create(lv_screen_active());
|
lv_obj_t * label = lv_label_create(lv_screen_active());
|
||||||
@@ -53,6 +86,29 @@ void test_snapshot_take_snapshot_immidiately_after_obj_create(void)
|
|||||||
lv_image_set_rotation(img_obj, 450);
|
lv_image_set_rotation(img_obj, 450);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_SCREENSHOT("snapshot_1.png");
|
TEST_ASSERT_EQUAL_SCREENSHOT("snapshot_1.png");
|
||||||
|
|
||||||
|
lv_obj_delete(img_obj);
|
||||||
|
lv_draw_buf_destroy(draw_dsc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_snapshot_take_snapshot_with_transform(void)
|
||||||
|
{
|
||||||
|
lv_obj_t * label = lv_label_create(lv_screen_active());
|
||||||
|
lv_obj_set_style_text_font(label, &lv_font_montserrat_28, 0);
|
||||||
|
lv_label_set_text(label, "Wubba lubba dub dub!");
|
||||||
|
lv_obj_set_style_transform_rotation(label, 450, 0);
|
||||||
|
|
||||||
|
lv_draw_buf_t * draw_dsc = lv_snapshot_take(lv_screen_active(), LV_COLOR_FORMAT_ARGB8888);
|
||||||
|
|
||||||
|
lv_obj_delete(label);
|
||||||
|
|
||||||
|
lv_obj_t * img_obj = lv_image_create(lv_screen_active());
|
||||||
|
lv_image_set_src(img_obj, draw_dsc);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_SCREENSHOT("snapshot_2.png");
|
||||||
|
|
||||||
|
lv_obj_delete(img_obj);
|
||||||
|
lv_draw_buf_destroy(draw_dsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /*LV_USE_SNAPSHOT*/
|
#else /*LV_USE_SNAPSHOT*/
|
||||||
@@ -62,6 +118,21 @@ void test_snapshot_should_not_leak_memory(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_snapshot_with_transform_should_not_leak_memory(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_snapshot_take_snapshot_immidiately_after_obj_create(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_snapshot_take_snapshot_with_transform(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user