Fixed thread unsafe evas utilization in sreenshot capture 45/246445/1 accepted/tizen_5.5_unified_mobile_hotfix tizen_5.5_mobile_hotfix accepted/tizen/5.5/unified/mobile/hotfix/20201103.003337 accepted/tizen/5.5/unified/mobile/hotfix/20201103.003341 submit/tizen_5.5_mobile_hotfix/20201030.062847 submit/tizen_5.5_mobile_hotfix/20201031.003713
authorAndrey Kazmin <a.kazmin@partner.samsung.com>
Tue, 15 Sep 2020 12:49:28 +0000 (15:49 +0300)
committerDongkyun Son <dongkyun.s@samsung.com>
Thu, 29 Oct 2020 10:42:43 +0000 (10:42 +0000)
Change-Id: I8d4e548852ed6d5891c184203ba61fb7aa396c23
Signed-off-by: Andrey Kazmin <a.kazmin@partner.samsung.com>
(cherry picked from commit b996e05470f9c1d7b6160a7b504a690feffe70ad)

probe_screenshot/dacapture_wayland.c

index b54c20d..588d1e3 100755 (executable)
@@ -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);