jpeg pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=096af26dd6e2101043bed0e3a9d570b1a0c3c18d
commit 096af26dd6e2101043bed0e3a9d570b1a0c3c18d Author: Jean-Philippe Andre <[email protected]> Date: Fri Feb 10 15:26:53 2017 +0900 elm_test: Add a test case for evas snapshot This showcases the object (not a widget) and will be the basis for a necessary optimization patch. --- src/Makefile_Elementary.am | 1 + src/bin/elementary/test.c | 2 + src/bin/elementary/test_evas_snapshot.c | 136 ++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am index 0f6973c..f7f0016 100644 --- a/src/Makefile_Elementary.am +++ b/src/Makefile_Elementary.am @@ -763,6 +763,7 @@ bin/elementary/test_entry_anchor.c \ bin/elementary/test_entry_anchor2.c \ bin/elementary/test_events.c \ bin/elementary/test_evas_mask.c \ +bin/elementary/test_evas_snapshot.c \ bin/elementary/test_external.c \ bin/elementary/test_fileselector_button.c \ bin/elementary/test_fileselector.c \ diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c index eaac07b..be0797d 100644 --- a/src/bin/elementary/test.c +++ b/src/bin/elementary/test.c @@ -307,6 +307,7 @@ void test_efl_ui_text(void *data, Evas_Object *obj, void *event_info); void test_efl_ui_text_label(void *data, Evas_Object *obj, void *event_info); void test_evas_mask(void *data, Edje_Object *obj, void *event_info); void test_gfx_filters(void *data, Evas_Object *obj, void *event_info); +void test_evas_snapshot(void *data, Evas_Object *obj, void *event_info); Evas_Object *win, *tbx; // TODO: refactoring void *tt; @@ -1022,6 +1023,7 @@ add_tests: //------------------------------// ADD_TEST(NULL, "Evas", "Masking", test_evas_mask); ADD_TEST(NULL, "Evas", "Gfx Filters", test_gfx_filters); + ADD_TEST(NULL, "Evas", "Snapshot", test_evas_snapshot); //------------------------------// ADD_TEST(NULL, "Widgets Disable/Enable", "Box", test_box_disable); diff --git a/src/bin/elementary/test_evas_snapshot.c b/src/bin/elementary/test_evas_snapshot.c new file mode 100644 index 0000000..8389b61 --- /dev/null +++ b/src/bin/elementary/test_evas_snapshot.c @@ -0,0 +1,136 @@ +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" +#endif +#include <Elementary.h> + +#define GRID_SIZE 10 + +static const char *images[] = { "plant_01.jpg", "rock_01.jpg", + "rock_02.jpg", "sky_01.jpg", "sky_04.jpg", + "wood_01.jpg", "fire.gif" }; + +static const int rnd[] = { + 3, 86, 81, 36, 38, 8, 65, 53, 93, 40, 71, 74, 90, 95, 88, 4, 96, 73, 14, 52, + 83, 77, 51, 13, 79, 15, 59, 99, 100, 31, 27, 24, 97, 34, 28, 58, 84, 92, 18, + 50, 22, 62, 12, 7, 17, 56, 2, 47, 75, 85, 42, 89, 80, 57, 44, 49, 5, 45, 54, + 68, 76, 70, 11, 69, 64, 30, 55, 29, 39, 60, 82, 63, 94, 43, 19, 26, 35, 21, + 67, 91, 46, 72, 33, 87, 10, 9, 41, 66, 37, 32, 78, 20, 23, 48, 6, 1, 25, 16, + 61, 98, +}; + +static const char *filter = + "padding_set {0}" + "fill { color = '#0123' }" + "blur { 5 }" + "print ('Evaluating filter: ' .. input.width .. 'x' .. input.height)" + ; + +static inline Eo * +_image_create(Eo *win, const char *path) +{ + return efl_add(EFL_UI_IMAGE_CLASS, win, + efl_file_set(efl_added, path, NULL), + efl_gfx_size_hint_align_set(efl_added, -1.0, -1.0), + efl_gfx_size_hint_weight_set(efl_added, 1.0, 1.0), + efl_gfx_size_hint_min_set(efl_added, 20, 20), + efl_gfx_visible_set(efl_added, 1)); +} + +static void +_anim_toggle(void *data, const Efl_Event *ev EINA_UNUSED) +{ + Eina_Iterator *it; + Eo *win = data; + Eo *grid, *o; + + grid = efl_key_wref_get(win, "grid"); + it = efl_content_iterate(grid); + EINA_ITERATOR_FOREACH(it, o) + { + if (efl_player_playable_get(o)) + efl_player_play_set(o, !efl_player_play_get(o)); + } + eina_iterator_free(it); +} + +static void +_close(void *data, const Efl_Event *ev EINA_UNUSED) +{ + Eo *win = data; + + efl_del(win); +} + +void +test_evas_snapshot(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Eo *win, *grid, *o, *snap; + const char *path; + + win = efl_add(EFL_UI_WIN_STANDARD_CLASS, NULL, + efl_text_set(efl_added, "Evas Snapshot"), + efl_ui_win_autodel_set(efl_added, 1)); + + grid = efl_add(EFL_UI_GRID_CLASS, win, + efl_pack_padding_set(efl_added, 5, 5, 1), + efl_gfx_size_hint_align_set(efl_added, -1.0, -1.0), + efl_gfx_size_hint_weight_set(efl_added, 1.0, 1.0)); + efl_content_set(win, grid); + + // Objects below the snapshot + for (int c = 0; c < GRID_SIZE; c++) + for (int r = 0; r < GRID_SIZE; r++) + { + int id = rnd[((r * GRID_SIZE) + c) % EINA_C_ARRAY_LENGTH(rnd)] + % EINA_C_ARRAY_LENGTH(images); + + path = eina_slstr_printf("%s/images/%s", elm_app_data_dir_get(), images[id]); + o = _image_create(win, path); + efl_pack_grid(grid, o, r, c, 1, 1); + if (efl_player_playable_get(o)) + efl_player_play_set(o, 1); + } + + // Snapshot + snap = efl_add(EFL_CANVAS_SNAPSHOT_CLASS, win, + efl_gfx_filter_program_set(efl_added, filter, "filter"), + efl_gfx_size_hint_align_set(efl_added, -1.0, -1.0), + efl_gfx_size_hint_weight_set(efl_added, 1.0, 1.0), + efl_pack_grid(grid, efl_added, 1, 1, GRID_SIZE - 2, GRID_SIZE - 2), + efl_gfx_visible_set(efl_added, 1)); + + + // Objects above snapshot + o = elm_progressbar_add(win); + elm_object_style_set(o, "wheel"); + evas_object_size_hint_weight_set(o, 0.0, 0.0); + evas_object_size_hint_align_set(o, 0.5, 0.5); + elm_progressbar_pulse_set(o, EINA_TRUE); + elm_progressbar_pulse(o, EINA_TRUE); + evas_object_show(o); + efl_pack_grid(grid, o, 0, 0, GRID_SIZE, GRID_SIZE); + + // Controls + 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, (GRID_SIZE + 1) / 2, 1), + 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, "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, (GRID_SIZE + 1) / 2, 1), + efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED, _close, win), + efl_gfx_visible_set(efl_added, 1)); + + efl_key_wref_set(win, "snap", snap); + efl_key_wref_set(win, "grid", grid); + efl_gfx_size_set(win, 400, 400); + efl_gfx_visible_set(win, 1); + + +} --
