uihv: move the creation of the screenshot path 66/184366/1
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 16 Jul 2018 16:55:37 +0000 (19:55 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 17 Jul 2018 09:00:24 +0000 (12:00 +0300)
Change-Id: Ibe7bd6e44cb85135c423a057a1b7a6ecf4d940df
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
ui_viewer/ui_viewer_data.c
ui_viewer/ui_viewer_data.h
ui_viewer/ui_viewer_screenshot.c
ui_viewer/ui_viewer_screenshot.h
ui_viewer/ui_viewer_utils.c
ui_viewer/ui_viewer_utils.h

index 2dda6c1..a12ce13 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "ui_viewer_lib.h"
 #include "ui_viewer_utils.h"
+#include "ui_viewer_screenshot.h"
 #include "ui_viewer_data.h"
 
 static pthread_mutex_t request_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -1929,13 +1930,11 @@ Eina_Bool _get_shot_in_bg(Evas_Object *obj)
 
        return can_shot_in_bg;
 }
-enum ErrorCode ui_obj_screenshot(Evas_Object *obj, char *path)
+enum ErrorCode ui_obj_screenshot(Evas_Object *obj, const char *path)
 {
        enum ErrorCode err_code = ERR_NO;
        Eina_Bool exists;
 
-       path[0] = '\0';
-
        pthread_mutex_lock(&request_lock);
        exists = _get_obj_exists(obj);
        if (!exists) {
index 2491c0c..822e443 100644 (file)
@@ -510,7 +510,7 @@ typedef struct _win_prop_t {
 char *pack_string(char *to, const char *str);
 void pack_ui_obj_info_list(int file, enum rendering_option_t rendering,
                            Eina_Bool *cancelled);
-enum ErrorCode ui_obj_screenshot(Evas_Object *obj, char *path);
+enum ErrorCode ui_obj_screenshot(Evas_Object *obj, const char *path);
 enum hierarchy_status_t get_hierarchy_status(void);
 void set_hierarchy_status(enum hierarchy_status_t status);
 
index 9e624c5..f173ba6 100644 (file)
@@ -50,7 +50,6 @@
 
 #define MAX_PATH_LENGTH                256
 
-static int screenshotIndex = 0;
 static pthread_mutex_t captureScreenLock = PTHREAD_MUTEX_INITIALIZER;
 
 struct efl_data {
@@ -424,18 +423,15 @@ fail_tbm_client:
 
        return buf;
 }
-static int capture_object(char *screenshot_path, int width, int height,
+static int capture_object(const char *screenshot_path, int width, int height,
                          Evas_Object *obj, const char *type_name)
 {
-       char dstpath[MAX_PATH_LENGTH];
        Evas_Object *img;
        Evas *canvas, *sub_canvas;
        Ecore_Evas *ee, *sub_ee;
        int ret = 0;
        char *image_data = NULL;
 
-       screenshotIndex++;
-
        canvas = evas_object_evas_get(obj);
        ee = ecore_evas_ecore_evas_get(canvas);
        img = ecore_evas_object_image_new(ee);
@@ -488,12 +484,7 @@ static int capture_object(char *screenshot_path, int width, int height,
 finish:
        ecore_evas_manual_render(sub_ee);
 
-       snprintf(dstpath, sizeof(dstpath), TMP_DIR "/%d_%d.png", _getpid(),
-                screenshotIndex);
-
-       if (evas_object_image_save(img, dstpath, NULL, "compress=5") != 0) {
-               strncpy(screenshot_path, dstpath, MAX_PATH_LENGTH);
-       } else {
+       if (!evas_object_image_save(img, screenshot_path, NULL, "compress=5")) {
                ui_viewer_log("ERROR: capture_object : can't save image\n");
                ret = -1;
        }
@@ -504,7 +495,7 @@ finish:
        return ret;
 }
 
-int ui_viewer_capture_screen(char *screenshot_path, Evas_Object *obj)
+int ui_viewer_capture_screen(const char *screenshot_path, Evas_Object *obj)
 {
        int view_w, view_h;
        int obj_x, obj_y, obj_w, obj_h;
@@ -512,12 +503,6 @@ int ui_viewer_capture_screen(char *screenshot_path, Evas_Object *obj)
        Evas *evas;
        char type_name[MAX_PATH_LENGTH];
 
-       if (!screenshot_path) {
-               ui_viewer_log("ui_viewer_capture_screen: no screenshot path\n");
-               ret = -1;
-               return ret;
-       }
-
        pthread_mutex_lock(&captureScreenLock);
 
        evas = evas_object_evas_get(obj);
@@ -579,9 +564,6 @@ int ui_viewer_capture_screen(char *screenshot_path, Evas_Object *obj)
                                     type_name);
        }
 
-       if (ret)
-               screenshot_path[0] = '\0';
-
        pthread_mutex_unlock(&captureScreenLock);
        return ret;
 }
index 96a889c..20ec7e2 100644 (file)
 #ifndef _UI_VIEWER_SCREENSHOT_
 #define _UI_VIEWER_SCREENSHOT_
 
+#include <Eina.h>
+
+int ui_viewer_capture_screen(const char *screenshot_path, Evas_Object *obj);
+
 void wayland_deinit(void);
 
 #endif /* _UI_VIEWER_SCREENSHOT_ */
index ad1b369..59ca801 100644 (file)
@@ -58,7 +58,7 @@ void reset_pid_tid()
 }
 
 // return current process id
-pid_t _getpid()
+static pid_t _getpid()
 {
        if (gPid == -1)
                gPid = getpid();
@@ -66,7 +66,7 @@ pid_t _getpid()
 }
 
 // return current thread id
-pid_t _gettid()
+static pid_t _gettid()
 {
        if(gTid == -1)
                gTid = syscall(__NR_gettid);    // syscall is very expensive
@@ -529,12 +529,36 @@ static void screenshot_send_to_socket_error(enum ErrorCode err)
        msg_send(APP_MSG_GET_UI_SCREENSHOT, buf, sizeof(buf));
 }
 
+static bool make_screenshot_path(char *buf, size_t size)
+{
+       static int index = 0;
+       int n;
+
+       __atomic_fetch_add(&index, 1, __ATOMIC_SEQ_CST);
+       n = snprintf(buf, size, TMP_DIR "/ui_screenshot_%d_%d.png",
+                    _getpid(), index);
+       if (n < 0) {
+               PRINTERR("Cannot create path, an output error occurred");
+               return false;
+       } else if ((size_t)n >= size) {
+               PRINTERR("Cannot create path, buffer is very small");
+               return false;
+       }
+
+       return true;
+}
+
 bool print_log_ui_obj_screenshot(Evas_Object *obj)
 {
        int ret = -1;
        enum ErrorCode err;
        char path[PATH_MAX];
 
+       if (!make_screenshot_path(path, sizeof(path))) {
+               PRINTERR("Cannot create screenshot path");
+               return false;
+       }
+
        err = ui_obj_screenshot(obj, path);
        if (err == ERR_NO) {
                ret = screenshot_send_to_socket(path);
index 056143b..9154e6f 100644 (file)
@@ -72,8 +72,6 @@ typedef struct {
 } info_t;
 
 void reset_pid_tid();
-pid_t _getpid();
-pid_t _gettid();
 char * _strncpy(char *dest, const char *src, size_t n);
 bool print_log_fmt(int msgType, const char *func_name, int line, ...);
 bool print_log_str(int msgType, char *st);
@@ -84,8 +82,6 @@ bool print_log_ui_obj_screenshot(Evas_Object *obj);
 bool printLog(log_t* log, int msgType);
 void raise_app_window(void);
 
-int ui_viewer_capture_screen(char *screenshot_path, Evas_Object *obj);
-
 void ui_viewer_clean_log(void);
 void ui_viewer_log(const char *format, ...);