From fa5526cc95a294753e9d07b1a6f65bda3af0a910 Mon Sep 17 00:00:00 2001 From: MinJeong Kim Date: Wed, 8 Apr 2020 15:08:26 +0900 Subject: [PATCH] e_comp/e_info : added image filter - currently support blur, grayscale, inverse_color - set a image filter using winfo -filter option Change-Id: Ida1707534d04ca440dc4eb32230ff563e224bcb2 Signed-off-by: MinJeong Kim --- src/bin/e_comp.c | 25 +++++++++++++ src/bin/e_comp.h | 14 +++++++ src/bin/e_comp_object.c | 35 ++++++++++++++++++ src/bin/e_comp_object.h | 2 + src/bin/e_info_client.c | 69 ++++++++++++++++++++++++++++++++++- src/bin/e_info_server.c | 67 ++++++++++++++++++++++++++++++++++ src/bin/e_info_shared_types.h | 13 +++++++ 7 files changed, 224 insertions(+), 1 deletion(-) diff --git a/src/bin/e_comp.c b/src/bin/e_comp.c index 3187e4f2e9..29ee0e6797 100644 --- a/src/bin/e_comp.c +++ b/src/bin/e_comp.c @@ -1426,3 +1426,28 @@ e_comp_util_client_is_fullscreen(const E_Client *ec) (!ec->argb) && (!ec->shaped) ); } + +E_API Eina_Bool +e_comp_image_filter_set(E_Comp_Image_Filter filter) +{ + E_Client *ec; + + if (e_comp->image_filter == filter) return EINA_TRUE; + E_CLIENT_FOREACH(ec) + { + e_comp_object_image_filter_set(ec->frame, filter); + e_comp_object_damage(ec->frame, 0, 0, ec->w, ec->h); + e_comp_object_dirty(ec->frame); + e_comp_object_render(ec->frame); + } + + e_comp->image_filter = filter; + return EINA_FALSE; +} + +E_API E_Comp_Image_Filter +e_comp_image_filter_get(void) +{ + return e_comp->image_filter; +} + diff --git a/src/bin/e_comp.h b/src/bin/e_comp.h index 50dd68120d..aa5d553a0d 100644 --- a/src/bin/e_comp.h +++ b/src/bin/e_comp.h @@ -44,6 +44,15 @@ typedef enum _E_Layer E_LAYER_MAX = 32767 // EVAS_LAYER_MAX } E_Layer; +typedef enum _E_Comp_Image_Filter +{ + E_COMP_IMAGE_FILTER_NONE = 0, + E_COMP_IMAGE_FILTER_BLUR, + E_COMP_IMAGE_FILTER_GRAYSCALE, + E_COMP_IMAGE_FILTER_INVERSE, +} E_Comp_Image_Filter; + + #else # ifndef E_COMP_H # define E_COMP_H @@ -181,6 +190,8 @@ struct _E_Comp int norender; void (*func_memory_dump) (void); + + E_Comp_Image_Filter image_filter; }; struct _E_Comp_Connected_Client_Info @@ -252,5 +263,8 @@ E_API void e_comp_client_override_add(E_Client *ec); E_API void e_comp_client_override_del(E_Client *ec); E_API Eina_List *e_comp_vis_ec_list_get(E_Zone *zone); // visible ec list sorted by z order +E_API Eina_Bool e_comp_image_filter_set(E_Comp_Image_Filter filter); +E_API E_Comp_Image_Filter e_comp_image_filter_get(void); + #endif #endif diff --git a/src/bin/e_comp_object.c b/src/bin/e_comp_object.c index 64369661b9..1ef45d0ef2 100644 --- a/src/bin/e_comp_object.c +++ b/src/bin/e_comp_object.c @@ -2189,6 +2189,10 @@ _e_comp_intercept_show_helper(E_Comp_Object *cw) evas_object_move(cw->smart_obj, ec->x, ec->y); evas_object_resize(cw->smart_obj, ec->w, ec->h); e_comp_object_frame_theme_set(cw->smart_obj, E_COMP_OBJECT_FRAME_RESHADOW); + + if (e_comp->image_filter != E_COMP_IMAGE_FILTER_NONE) + e_comp_object_image_filter_set(cw->smart_obj, e_comp->image_filter); + cw->real_hid = 0; evas_object_show(cw->smart_obj); @@ -2264,6 +2268,8 @@ _e_comp_intercept_show_helper(E_Comp_Object *cw) cw->real_hid = 0; /* force comp theming in case it didn't happen already */ e_comp_object_frame_theme_set(cw->smart_obj, E_COMP_OBJECT_FRAME_RESHADOW); + if (e_comp->image_filter != E_COMP_IMAGE_FILTER_NONE) + e_comp_object_image_filter_set(cw->smart_obj, e_comp->image_filter); } /* only do the show if show is allowed */ @@ -5977,3 +5983,32 @@ e_comp_object_native_usable_get(Evas_Object *obj) return EINA_FALSE; } + +E_API Eina_Bool +e_comp_object_image_filter_set(Evas_Object *obj, E_Comp_Image_Filter filter) +{ + API_ENTRY EINA_FALSE; + EINA_SAFETY_ON_NULL_RETURN_VAL(cw->ec, EINA_FALSE); + + if ((!cw->ec) || (!cw->ec->comp_data) || (e_object_is_del(E_OBJECT(cw->ec)))) + return EINA_FALSE; + + switch (filter) + { + case E_COMP_IMAGE_FILTER_BLUR: + efl_gfx_filter_program_set(cw->obj, "blur (20) padding_set (0)", "image_filter"); + break; + case E_COMP_IMAGE_FILTER_GRAYSCALE: + efl_gfx_filter_program_set(cw->obj, "grayscale ()", "image_filter"); + break; + case E_COMP_IMAGE_FILTER_INVERSE: + efl_gfx_filter_program_set(cw->obj, "inverse_color ()", "image_filter"); + break; + case E_COMP_IMAGE_FILTER_NONE: + default: + efl_gfx_filter_program_set(cw->obj, NULL, "image_filter"); + break; + } + + return EINA_TRUE; +} diff --git a/src/bin/e_comp_object.h b/src/bin/e_comp_object.h index 2a0ac375dd..a04babaeaa 100644 --- a/src/bin/e_comp_object.h +++ b/src/bin/e_comp_object.h @@ -190,6 +190,8 @@ E_API void e_comp_object_map_update(Evas_Object *obj); EINTERN Eina_Bool e_comp_object_render_trace_set(Evas_Object *obj, Eina_Bool set); E_API Eina_Bool e_comp_object_native_usable_get(Evas_Object *obj); + +E_API Eina_Bool e_comp_object_image_filter_set(Evas_Object *obj, E_Comp_Image_Filter filter); #endif #endif diff --git a/src/bin/e_info_client.c b/src/bin/e_info_client.c index 7988d60995..67bdcb9d19 100644 --- a/src/bin/e_info_client.c +++ b/src/bin/e_info_client.c @@ -5635,7 +5635,68 @@ _e_info_client_proc_keygen(int argc, char **argv) return; } +static void +_e_info_client_cb_filter(const Eldbus_Message *msg) +{ + const char *name = NULL, *text = NULL; + Eina_Bool res; + const char *reply; + + res = eldbus_message_error_get(msg, &name, &text); + EINA_SAFETY_ON_TRUE_GOTO(res, finish); + + res = eldbus_message_arguments_get(msg, "s", &reply); + printf("%s\n", reply); + +finish: + if ((name) || (text)) + { + printf("errname:%s errmsg:%s\n", name, text); + } +} +static void +_e_info_client_proc_apply_filter(int argc, char **argv) +{ + Eina_Bool res = EINA_FALSE; + int onoff = -1; + + if (argc == 2) + { + //print current filter + res = _e_info_client_eldbus_message_with_args("filter", + _e_info_client_cb_filter, + "is", + -1, + "info"); + if (!res) printf("Error occured while sending message\n\n"); + return; + } + else if (argc == 4) + { + EINA_SAFETY_ON_FALSE_GOTO((!strcmp(argv[2], "blur")) || + (!strcmp(argv[2], "grayscale")) || + (!strcmp(argv[2], "inverse_color")), usage); + EINA_SAFETY_ON_FALSE_GOTO((!strcmp(argv[3], "on")) || + (!strcmp(argv[3], "off")) || + (!strcmp(argv[3], "1")) || + (!strcmp(argv[3], "0")), usage); + + if (!strcmp(argv[3], "on") || !strcmp(argv[3], "1")) onoff = 1; + else onoff = 0; + + res = _e_info_client_eldbus_message_with_args("filter", + _e_info_client_cb_filter, + "is", + onoff, + argv[2]); + if (!res) printf("Error occured while sending message\n\n"); + return; + } + +usage: + printf("Usage: %s", USAGE_FILTER); +} typedef struct _ProcInfo { @@ -5827,7 +5888,7 @@ static ProcInfo procs_to_execute[] = "[print] [set ]", "Print or Set key repeat info", _e_info_client_proc_key_repeat - }, + }, { "punch", "[on/off] [x++] [,,,]", "HWC should be disabled first with \"-hwc\" option. Punch a UI framebuffer [on/off].", @@ -5974,6 +6035,12 @@ static ProcInfo procs_to_execute[] = "Recording the screen", /* Description */ _e_info_client_proc_screen_record /* func */ }, + { + "filter", + USAGE_FILTER, + "apply filter option to windows", + _e_info_client_proc_apply_filter + }, }; ProcInfo procs_to_input[] = diff --git a/src/bin/e_info_server.c b/src/bin/e_info_server.c index e09874c735..ca96673813 100644 --- a/src/bin/e_info_server.c +++ b/src/bin/e_info_server.c @@ -6332,6 +6332,72 @@ _e_info_server_cb_keygen(const Eldbus_Service_Interface *iface EINA_UNUSED, cons return reply; } +static Eldbus_Message * +_e_info_server_cb_filter(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg) +{ + Eldbus_Message *reply; + int onoff = -1; + const char *filter_name = NULL; + char msg_to_client[125] = {0}; + + if (!eldbus_message_arguments_get(msg, "is", &onoff, &filter_name)) + { + return eldbus_message_error_new(msg, GET_CALL_MSG_ARG_ERR, + "filetr: failed to get arguments from method call message"); + } + reply = eldbus_message_method_return_new(msg); + + if (onoff == -1) + { + char current_filter[15] = {0}; + //return current filter mode + switch (e_comp->image_filter) + { + case E_COMP_IMAGE_FILTER_BLUR: + snprintf(current_filter, sizeof(current_filter), "blur"); + break; + case E_COMP_IMAGE_FILTER_GRAYSCALE: + snprintf(current_filter, sizeof(current_filter), "grayscale"); + break; + case E_COMP_IMAGE_FILTER_INVERSE: + snprintf(current_filter, sizeof(current_filter), "inverse_color"); + break; + default: + snprintf(current_filter, sizeof(current_filter), "none"); + break; + } + + snprintf(msg_to_client, sizeof(msg_to_client), + "Current filter : %s\n", current_filter); + } + else if (onoff == 0) + { + e_comp_image_filter_set(E_COMP_IMAGE_FILTER_NONE); + snprintf(msg_to_client, sizeof(msg_to_client), + "Filter has been unset.\n"); + } + else + { + if (!strcmp(filter_name, "blur")) + e_comp_image_filter_set(E_COMP_IMAGE_FILTER_BLUR); + else if (!strcmp(filter_name, "grayscale")) + e_comp_image_filter_set(E_COMP_IMAGE_FILTER_GRAYSCALE); + else if (!strcmp(filter_name, "inverse_color")) + e_comp_image_filter_set(E_COMP_IMAGE_FILTER_INVERSE); + else + snprintf(msg_to_client, sizeof(msg_to_client), + "Filter %s is NOT supported!\n", + filter_name); + + snprintf(msg_to_client, sizeof(msg_to_client), + "Filter %s is set!\n", filter_name); + } + + eldbus_message_arguments_append(reply, "s", msg_to_client); + + return reply; +} + //{ "method_name", arguments_from_client, return_values_to_client, _method_cb, ELDBUS_METHOD_FLAG }, static const Eldbus_Method methods[] = { { "get_window_info", NULL, ELDBUS_ARGS({"iiiiisiiiiia("VALUE_TYPE_FOR_TOPVWINS")", "array of ec"}), _e_info_server_cb_window_info_get, 0 }, @@ -6407,6 +6473,7 @@ static const Eldbus_Method methods[] = { { "init_device", ELDBUS_ARGS({"us", "device information"}), ELDBUS_ARGS({"s", "result message"}), _e_info_server_cb_init_device, 0}, { "deinit_device", NULL, NULL, _e_info_server_cb_deinit_device, 0}, { "keygen", ELDBUS_ARGS({"sii", "key information"}), ELDBUS_ARGS({"s", "result message"}), _e_info_server_cb_keygen, 0}, + { "filter", ELDBUS_ARGS({"is", "on(1)/off(0), filter name"}), ELDBUS_ARGS({"s", "result of request"}), _e_info_server_cb_filter, 0}, { NULL, NULL, NULL, NULL, 0 } }; diff --git a/src/bin/e_info_shared_types.h b/src/bin/e_info_shared_types.h index f1a1ed4a4f..257854102b 100644 --- a/src/bin/e_info_shared_types.h +++ b/src/bin/e_info_shared_types.h @@ -294,4 +294,17 @@ typedef enum #define E_INFO_INPUT_RESULT_NONE "None" +/* -------------------------------------------------------------------------- */ +/* FILTER */ +/* -------------------------------------------------------------------------- */ +#define USAGE_FILTER \ + "-filter ( blur | grayscale | inverse ) ( on | off)\n" \ + "Example:\n" \ + "\twinfo -filter blur on\n" \ + "\twinfo -filter blur off\n" \ + "\twinfo -filter grayscale on\n" \ + "\twinfo -filter grayscale off\n" \ + "\twinfo -filter inverse_color on\n" \ + "\twinfo -filter inverse_color off\n" + #endif /* end of _E_INFO_SHARED_TYPES_ */ -- 2.34.1