summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@yahoo.com>2017-03-10 15:27:06 +0200
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2017-03-13 23:21:19 +0200
commit7127027bf012d61e4e693841618bdedfd835a2d3 (patch)
tree3b54ff392954c8796fce5605813f3724c96ead75
parent47fb160084ecb425f11273735a10475c622cee22 (diff)
Support timestamped screenshots
-rw-r--r--edebug.pc.in2
-rw-r--r--src/lib/CMakeLists.txt1
-rw-r--r--src/lib/Evas_Debug.h45
-rw-r--r--src/lib/evas_debug.c133
4 files changed, 155 insertions, 26 deletions
diff --git a/edebug.pc.in b/edebug.pc.in
index e1eb189..3f14181 100644
--- a/edebug.pc.in
+++ b/edebug.pc.in
@@ -6,7 +6,7 @@ includedir=@includedir@
6Name: libedebug 6Name: libedebug
7Description: Library to store debug modules used in EFL 7Description: Library to store debug modules used in EFL
8Version: @PNGLIB_VERSION@ 8Version: @PNGLIB_VERSION@
9Libs: -L${libdir} -leolian_debug -leo_debug 9Libs: -L${libdir} -leolian_debug -leo_debug -levas_debug
10Libs.private: @LIBS@ 10Libs.private: @LIBS@
11Cflags: -I${includedir} 11Cflags: -I${includedir}
12 12
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 0379b8f..79398e1 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -35,6 +35,7 @@ target_link_libraries(evas_debug
35 35
36#INSTALL(FILES Eolian_Debug.h DESTINATION include/edebug) 36#INSTALL(FILES Eolian_Debug.h DESTINATION include/edebug)
37INSTALL(FILES Eo_Debug.h DESTINATION include/edebug) 37INSTALL(FILES Eo_Debug.h DESTINATION include/edebug)
38INSTALL(FILES Evas_Debug.h DESTINATION include/edebug)
38 39
39INSTALL(TARGETS eo_debug LIBRARY DESTINATION lib) 40INSTALL(TARGETS eo_debug LIBRARY DESTINATION lib)
40INSTALL(TARGETS eolian_debug LIBRARY DESTINATION lib) 41INSTALL(TARGETS eolian_debug LIBRARY DESTINATION lib)
diff --git a/src/lib/Evas_Debug.h b/src/lib/Evas_Debug.h
new file mode 100644
index 0000000..1304ef5
--- /dev/null
+++ b/src/lib/Evas_Debug.h
@@ -0,0 +1,45 @@
1#ifndef _EVAS_DEBUG_H
2#define _EVAS_DEBUG_H
3
4#include <Evas.h>
5
6#ifdef EAPI
7# undef EAPI
8#endif
9
10#ifdef _WIN32
11# ifdef DEBUG_BUILD
12# ifdef DLL_EXPORT
13# define EAPI __declspec(dllexport)
14# else
15# define EAPI
16# endif /* ! DLL_EXPORT */
17# else
18# define EAPI __declspec(dllimport)
19# endif /* ! DEBUG_BUILD */
20#else
21# ifdef __GNUC__
22# if __GNUC__ >= 4
23# define EAPI __attribute__ ((visibility("default")))
24# else
25# define EAPI
26# endif
27# else
28# define EAPI
29# endif
30#endif /* ! _WIN32 */
31
32typedef struct
33{
34 int w;
35 int h;
36 char *img;
37 struct tm time;
38 Eo *menu_item;
39} Evas_Debug_Screenshot;
40
41EAPI Evas_Debug_Screenshot *
42evas_debug_screenshot_decode(char *buffer, unsigned int size, uint64_t *obj);
43
44#endif
45
diff --git a/src/lib/evas_debug.c b/src/lib/evas_debug.c
index 5708333..9543b93 100644
--- a/src/lib/evas_debug.c
+++ b/src/lib/evas_debug.c
@@ -1,34 +1,22 @@
1#include <Eina.h> 1#include <Eina.h>
2#include <Ecore.h> 2#include <Ecore.h>
3#include <Ecore_X.h>
3#include <Evas.h> 4#include <Evas.h>
4#include <Elementary.h> 5#include <Elementary.h>
5 6
6#ifdef EAPI 7#include "Evas_Debug.h"
7# undef EAPI
8#endif
9
10#ifdef _WIN32
11# ifdef DEBUG_BUILD
12# ifdef DLL_EXPORT
13# define EAPI __declspec(dllexport)
14# else
15# define EAPI
16# endif /* ! DLL_EXPORT */
17# else
18# define EAPI __declspec(dllimport)
19# endif /* ! DEBUG_BUILD */
20#else
21# ifdef __GNUC__
22# if __GNUC__ >= 4
23# define EAPI __attribute__ ((visibility("default")))
24# else
25# define EAPI
26# endif
27# else
28# define EAPI
29# endif
30#endif /* ! _WIN32 */
31 8
9#define STORE(_buf, pval, sz) \
10{ \
11 memcpy(_buf, pval, sz); \
12 _buf += sz; \
13}
14
15#define EXTRACT(_buf, pval, sz) \
16{ \
17 memcpy(pval, _buf, sz); \
18 _buf += sz; \
19}
32enum { 20enum {
33 HIGHLIGHT_R = 255, 21 HIGHLIGHT_R = 255,
34 HIGHLIGHT_G = 128, 22 HIGHLIGHT_G = 128,
@@ -37,6 +25,7 @@ enum {
37}; 25};
38 26
39static int _obj_highlight_op = EINA_DEBUG_OPCODE_INVALID; 27static int _obj_highlight_op = EINA_DEBUG_OPCODE_INVALID;
28static int _win_screenshot_op = EINA_DEBUG_OPCODE_INVALID;
40 29
41/* Highlight functions. */ 30/* Highlight functions. */
42static Eina_Bool 31static Eina_Bool
@@ -116,9 +105,103 @@ _obj_highlight_cb(Eina_Debug_Session *session EINA_UNUSED, int srcid EINA_UNUSED
116 return EINA_DEBUG_OK; 105 return EINA_DEBUG_OK;
117} 106}
118 107
108EAPI Evas_Debug_Screenshot *
109evas_debug_screenshot_decode(char *buffer, unsigned int size, uint64_t *obj)
110{
111 Evas_Debug_Screenshot *s = NULL;
112 struct tm *t = NULL;
113 int w, h;
114 unsigned int hdr_size = sizeof(uint64_t) + sizeof(struct tm) + 2 * sizeof(int);
115 if (size < hdr_size) return NULL;
116 EXTRACT(buffer, obj, sizeof(uint64_t));
117 t = (struct tm *)buffer;
118 buffer += sizeof(struct tm);
119 EXTRACT(buffer, &w, sizeof(int));
120 EXTRACT(buffer, &h, sizeof(int));
121 size -= hdr_size;
122 if (size != (w * h * sizeof(int))) return NULL;
123
124 s = calloc(1, sizeof(*s));
125 s->w = w;
126 s->h = h;
127 memcpy(&s->time, t, sizeof(struct tm));
128 s->img = malloc(size);
129 memcpy(s->img, buffer, size);
130 return s;
131}
132
133static Eina_Debug_Error
134_win_screenshot_cb(Eina_Debug_Session *session, int srcid, void *buffer, int size)
135{
136 struct tm *t = NULL;
137 time_t now = time(NULL);
138 uint64_t ptr64 = 0;
139 Ecore_Evas *ee = NULL;
140 Ecore_X_Image *img;
141 Ecore_X_Window_Attributes att;
142 unsigned char *img_src;
143 unsigned char *resp = NULL, *tmp;
144 int bpl = 0, rows = 0, bpp = 0;
145 int w, h;
146 unsigned int hdr_size = sizeof(uint64_t) + sizeof(struct tm) + 2 * sizeof(int);
147
148 if (size <= 0) return EINA_DEBUG_ERROR;
149 memcpy(&ptr64, buffer, sizeof(ptr64));
150 Eo *e = (Eo *)ptr64;
151 if (!efl_isa(e, EVAS_CANVAS_CLASS)) goto end;
152
153 ee = ecore_evas_ecore_evas_get(e);
154 if (!ee) goto end;
155
156 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(ee);
157
158 if (!win)
159 {
160 printf("Can't grab window.\n");
161 goto end;
162 }
163
164 t = localtime(&now);
165 t->tm_zone = NULL;
166
167 memset(&att, 0, sizeof(Ecore_X_Window_Attributes));
168 ecore_x_window_attributes_get(win, &att);
169 w = att.w;
170 h = att.h;
171 img = ecore_x_image_new(w, h, att.visual, att.depth);
172 ecore_x_image_get(img, win, 0, 0, 0, 0, w, h);
173 img_src = ecore_x_image_data_get(img, &bpl, &rows, &bpp);
174 resp = tmp = malloc(hdr_size + (w * h * sizeof(int)));
175 STORE(tmp, &ptr64, sizeof(ptr64));
176 STORE(tmp, t, sizeof(struct tm));
177 STORE(tmp, &w, sizeof(int));
178 STORE(tmp, &h, sizeof(int));
179 if (!ecore_x_image_is_argb32_get(img))
180 { /* Fill resp buffer with image convert */
181 ecore_x_image_to_argb_convert(img_src, bpp, bpl, att.colormap, att.visual,
182 0, 0, w, h, (unsigned int *)tmp,
183 (w * sizeof(int)), 0, 0);
184 }
185 else
186 { /* Fill resp buffer by copy */
187 memcpy(tmp, img_src, (w * h * sizeof(int)));
188 }
189
190 /* resp now holds window bitmap */
191 ecore_x_image_free(img);
192
193 eina_debug_session_send(session, srcid, _win_screenshot_op, resp,
194 hdr_size + (w * h * sizeof(int)));
195
196end:
197 if (resp) free(resp);
198 return EINA_DEBUG_OK;
199}
200
119static const Eina_Debug_Opcode _debug_ops[] = 201static const Eina_Debug_Opcode _debug_ops[] =
120{ 202{
121 {"Evas/object/highlight", &_obj_highlight_op, &_obj_highlight_cb}, 203 {"Evas/object/highlight", &_obj_highlight_op, &_obj_highlight_cb},
204 {"Evas/window/screenshot", &_win_screenshot_op, &_win_screenshot_cb},
122 {NULL, NULL, NULL} 205 {NULL, NULL, NULL}
123}; 206};
124 207