#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;
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) {
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);
#define MAX_PATH_LENGTH 256
-static int screenshotIndex = 0;
static pthread_mutex_t captureScreenLock = PTHREAD_MUTEX_INITIALIZER;
struct efl_data {
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);
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;
}
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;
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);
type_name);
}
- if (ret)
- screenshot_path[0] = '\0';
-
pthread_mutex_unlock(&captureScreenLock);
return ret;
}
#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_ */
}
// return current process id
-pid_t _getpid()
+static pid_t _getpid()
{
if (gPid == -1)
gPid = getpid();
}
// return current thread id
-pid_t _gettid()
+static pid_t _gettid()
{
if(gTid == -1)
gTid = syscall(__NR_gettid); // syscall is very expensive
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);
} 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);
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, ...);