aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/elementary/test_evas_snapshot.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-03-28 16:09:34 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-04-14 11:26:44 +0900
commitc53f1526f11113d52aefcf7d9ac0f70846fd60fe (patch)
treee50abe0f636fbbac1f1c65688182d11f02aceb89 /src/bin/elementary/test_evas_snapshot.c
parentevas gl: Make sure a deleted image can't be the target (diff)
downloadefl-c53f1526f11113d52aefcf7d9ac0f70846fd60fe.tar.gz
evas: Make save() work on snapshots
This make save() work on snapshot objects, provided the call is done from inside render_post. Also, this saves the filtered output of an image, rather than its source pixels. Any call to save() on a filtered image must be done from post-render as well. Fixes https://phab.enlightenment.org/T2102 @feature
Diffstat (limited to 'src/bin/elementary/test_evas_snapshot.c')
-rw-r--r--src/bin/elementary/test_evas_snapshot.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/bin/elementary/test_evas_snapshot.c b/src/bin/elementary/test_evas_snapshot.c
index 13e045804c..845c95c62d 100644
--- a/src/bin/elementary/test_evas_snapshot.c
+++ b/src/bin/elementary/test_evas_snapshot.c
@@ -54,6 +54,35 @@ _anim_toggle(void *data, const Efl_Event *ev EINA_UNUSED)
}
static void
+_render_post(void *data, const Efl_Event *ev)
+{
+ Eo *snap = data;
+
+ efl_event_callback_del(ev->object, EFL_CANVAS_EVENT_RENDER_POST, _render_post, data);
+ efl_file_save(snap, eina_slstr_printf("%s/snap-efl.png", eina_environment_tmp_get()), NULL, NULL);
+}
+
+static void
+_save_image(void *data, const Efl_Event *ev EINA_UNUSED)
+{
+ Eo *win = data;
+ Eo *snap;
+ int w, h;
+
+ // Save is available only during render_post
+ snap = efl_key_wref_get(win, "snap");
+ efl_event_callback_add(win, EFL_CANVAS_EVENT_RENDER_POST, _render_post, snap);
+
+ // Force a render in order to ensure post_render is called. EO API provides
+ // no way to do manual render, so we add a damage to the snapshot object.
+ // This is a special case handled by snapshot for the purpose of taking
+ // screenshots like this. This is useful only if the button click has no
+ // animation on screen and there is no spinning wheel either.
+ efl_gfx_size_get(snap, &w, &h);
+ efl_gfx_buffer_update_add(snap, 0, 0, w, h);
+}
+
+static void
_radius_set(void *data, const Efl_Event *ev)
{
char buf[128];
@@ -76,7 +105,7 @@ _close(void *data, const Efl_Event *ev EINA_UNUSED)
void
test_evas_snapshot(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
- Eo *win, *grid, *o, *snap;
+ Eo *win, *grid, *o, *snap, *box;
const char *path;
win = efl_add(EFL_UI_WIN_STANDARD_CLASS, NULL,
@@ -141,19 +170,32 @@ test_evas_snapshot(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *e
efl_event_callback_add(efl_added, ELM_SLIDER_EVENT_CHANGED, _radius_set, win),
efl_gfx_visible_set(efl_added, 1));
+ box = efl_add(EFL_UI_BOX_CLASS, win,
+ efl_gfx_size_hint_align_set(efl_added, -1.0, -1.0),
+ efl_pack_grid(grid, efl_added, 0, GRID_SIZE + 1, GRID_SIZE, 1),
+ efl_gfx_visible_set(efl_added, 1));
+
efl_add(ELM_BUTTON_CLASS, win,
efl_text_set(efl_added, "Toggle animation"),
efl_gfx_size_hint_align_set(efl_added, -1.0, -1.0),
efl_gfx_size_hint_weight_set(efl_added, 1.0, 0.0),
- efl_pack_grid(grid, efl_added, 0, GRID_SIZE + 1, (GRID_SIZE + 1) / 2, 1),
+ efl_pack(box, efl_added),
efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED, _anim_toggle, win),
efl_gfx_visible_set(efl_added, 1));
efl_add(ELM_BUTTON_CLASS, win,
+ efl_text_set(efl_added, "Save to file"),
+ efl_gfx_size_hint_align_set(efl_added, -1.0, -1.0),
+ efl_gfx_size_hint_weight_set(efl_added, 1.0, 0.0),
+ efl_pack(box, efl_added),
+ efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED, _save_image, win),
+ efl_gfx_visible_set(efl_added, 1));
+
+ efl_add(ELM_BUTTON_CLASS, win,
efl_text_set(efl_added, "Close"),
efl_gfx_size_hint_align_set(efl_added, -1.0, -1.0),
efl_gfx_size_hint_weight_set(efl_added, 1.0, 0.0),
- efl_pack_grid(grid, efl_added, (GRID_SIZE + 1) / 2, GRID_SIZE + 1, (GRID_SIZE + 1) / 2, 1),
+ efl_pack(box, efl_added),
efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED, _close, win),
efl_gfx_visible_set(efl_added, 1));