From: Vyacheslav Cherkashin Date: Mon, 16 Jul 2018 16:55:37 +0000 (+0300) Subject: uihv: move the creation of the screenshot path X-Git-Tag: accepted/tizen/unified/20180724.154353~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0d8823d59334ab42544310c55f3542d75e443ebc;p=platform%2Fcore%2Fsystem%2Fswap-manager.git uihv: move the creation of the screenshot path Change-Id: Ibe7bd6e44cb85135c423a057a1b7a6ecf4d940df Signed-off-by: Vyacheslav Cherkashin --- diff --git a/ui_viewer/ui_viewer_data.c b/ui_viewer/ui_viewer_data.c index 2dda6c1..a12ce13 100644 --- a/ui_viewer/ui_viewer_data.c +++ b/ui_viewer/ui_viewer_data.c @@ -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) { diff --git a/ui_viewer/ui_viewer_data.h b/ui_viewer/ui_viewer_data.h index 2491c0c..822e443 100644 --- a/ui_viewer/ui_viewer_data.h +++ b/ui_viewer/ui_viewer_data.h @@ -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); diff --git a/ui_viewer/ui_viewer_screenshot.c b/ui_viewer/ui_viewer_screenshot.c index 9e624c5..f173ba6 100644 --- a/ui_viewer/ui_viewer_screenshot.c +++ b/ui_viewer/ui_viewer_screenshot.c @@ -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; } diff --git a/ui_viewer/ui_viewer_screenshot.h b/ui_viewer/ui_viewer_screenshot.h index 96a889c..20ec7e2 100644 --- a/ui_viewer/ui_viewer_screenshot.h +++ b/ui_viewer/ui_viewer_screenshot.h @@ -27,6 +27,10 @@ #ifndef _UI_VIEWER_SCREENSHOT_ #define _UI_VIEWER_SCREENSHOT_ +#include + +int ui_viewer_capture_screen(const char *screenshot_path, Evas_Object *obj); + void wayland_deinit(void); #endif /* _UI_VIEWER_SCREENSHOT_ */ diff --git a/ui_viewer/ui_viewer_utils.c b/ui_viewer/ui_viewer_utils.c index ad1b369..59ca801 100644 --- a/ui_viewer/ui_viewer_utils.c +++ b/ui_viewer/ui_viewer_utils.c @@ -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); diff --git a/ui_viewer/ui_viewer_utils.h b/ui_viewer/ui_viewer_utils.h index 056143b..9154e6f 100644 --- a/ui_viewer/ui_viewer_utils.h +++ b/ui_viewer/ui_viewer_utils.h @@ -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, ...);