From: Andrey Kazmin Date: Tue, 15 Sep 2020 12:49:28 +0000 (+0300) Subject: Fixed thread unsafe evas utilization in sreenshot capture X-Git-Tag: accepted/tizen/6.0/unified/20201030.113010^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_6.0_hotfix;p=platform%2Fcore%2Fsystem%2Fswap-probe.git Fixed thread unsafe evas utilization in sreenshot capture Change-Id: I8d4e548852ed6d5891c184203ba61fb7aa396c23 Signed-off-by: Andrey Kazmin --- diff --git a/probe_screenshot/dacapture_wayland.c b/probe_screenshot/dacapture_wayland.c index b54c20d..588d1e3 100755 --- a/probe_screenshot/dacapture_wayland.c +++ b/probe_screenshot/dacapture_wayland.c @@ -323,10 +323,18 @@ static void destroy_canvas(Evas* canvas) __evas_free_p(canvas); } -static int __save_to_png(const char *path, unsigned char *buf, - int width, int height) +struct save_to_png_args { + const char *path; + unsigned char *buf; + int width; + int height; +}; + +static void* __save_to_png(void *data) { - int ret = -1, err; + struct save_to_png_args *png_args = data; + int *ret = malloc(sizeof(int)); + int err; Evas *ev = NULL; Evas_Object *img; @@ -366,10 +374,11 @@ static int __save_to_png(const char *path, unsigned char *buf, rtld_default_set_once(__evas_object_image_add_p, "evas_object_image_add"); - ev = create_canvas(width, height); + *ret = -1; + ev = create_canvas(png_args->width, png_args->height); if (unlikely(ev == NULL)) { PRINTERR("failed to create canvas"); - return -1; + return (void *)ret; } // make image buffer @@ -381,27 +390,27 @@ static int __save_to_png(const char *path, unsigned char *buf, //image buffer set __evas_object_image_data_set_p(img, NULL); - __evas_object_image_size_set_p(img, width, height); - __evas_object_image_data_set_p(img, buf); + __evas_object_image_size_set_p(img, png_args->width, png_args->height); + __evas_object_image_data_set_p(img, png_args->buf); // resize image - if (height > MAX_HEIGHT) { - width = width * MAX_HEIGHT / height; - height = MAX_HEIGHT; - __evas_object_resize_p(img, width, height); - __evas_object_image_fill_set_p(img, 0, 0, width, height); + if (png_args->height > MAX_HEIGHT) { + png_args->width = png_args->width * MAX_HEIGHT / png_args->height; + png_args->height = MAX_HEIGHT; + __evas_object_resize_p(img, png_args->width, png_args->height); + __evas_object_image_fill_set_p(img, 0, 0, png_args->width, png_args->height); } - __evas_object_image_data_update_add_p(img, 0, 0, width, height); + __evas_object_image_data_update_add_p(img, 0, 0, png_args->width, png_args->height); //save image to png file - err = __evas_object_image_save_p(img, path, NULL, "compress=5"); + err = __evas_object_image_save_p(img, png_args->path, NULL, "compress=5"); if (err != 0) - ret = 0; + *ret = 0; out_canvas: destroy_canvas(ev); - return ret; + return (void *)ret; } static struct efl_data *__edata = NULL; @@ -534,6 +543,13 @@ static int __capture_screnshot_wayland(const char *path) static int checked4padding; static int padding; int width, height; + struct save_to_png_args *png_args; + int *ret_ptr; + + static void* (*__ecore_main_loop_thread_safe_call_sync_p)(Ecore_Data_Cb callback, + void *data); + rtld_default_set_once(__ecore_main_loop_thread_safe_call_sync_p, + "ecore_main_loop_thread_safe_call_sync"); data = __wayland_init(); if (!data) { @@ -605,8 +621,17 @@ static int __capture_screnshot_wayland(const char *path) } } - ret = __save_to_png(path, tsuri.planes[plane_idx].ptr, - width, height); + png_args = malloc(sizeof(struct save_to_png_args)); + png_args->path = (char *)path; + png_args->buf = tsuri.planes[plane_idx].ptr; + png_args->width = width; + png_args->height = height; + + ret_ptr = (int *)__ecore_main_loop_thread_safe_call_sync_p(__save_to_png, png_args); + ret = *ret_ptr; + + free(png_args); + free(ret_ptr); wrong_padding: tbm_surface_unmap(t_surface);