From f54afe89cc6099024dc1850a14b90b81e34cfd61 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Wed, 6 Aug 2014 00:04:11 +0900 Subject: [PATCH] elm - add apis to deal with accel perference this deals with an issue brought up today on irc - seemingly rage asking for accel is causing segvs in vbox with its gl accel subsystem - the only way to disable this is an env var, and this is unfriendly, so make config gui and stuff to mess with accel preference to fix this. --- legacy/elementary/src/bin/config.c | 191 +++++++++------------------------ legacy/elementary/src/lib/elm_config.c | 38 ++++++- legacy/elementary/src/lib/elm_config.h | 50 +++++++++ legacy/elementary/src/lib/elm_priv.h | 2 + legacy/elementary/src/lib/elm_win.c | 37 ++++++- 5 files changed, 174 insertions(+), 144 deletions(-) diff --git a/legacy/elementary/src/bin/config.c b/legacy/elementary/src/bin/config.c index 8bc51f7..43d8ea0 100644 --- a/legacy/elementary/src/bin/config.c +++ b/legacy/elementary/src/bin/config.c @@ -1304,25 +1304,6 @@ _config_all_changed(void *data, } static void -_engine_use(void *data, - Evas_Object *obj EINA_UNUSED, - void *event_info EINA_UNUSED) -{ - Evas_Object *li; - const char *selection; - - li = data; - selection = elm_object_item_data_get(elm_list_selected_item_get(li)); - - if (!strcmp(elm_config_engine_get(), selection)) - return; - - elm_config_engine_set(selection); - elm_config_all_flush(); - elm_config_save(); /* make sure new engine has its data dir */ -} - -static void _profile_use(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) @@ -2629,14 +2610,6 @@ _status_config_fonts(Evas_Object *win, } static void -_engines_list_item_del_cb(void *data, - Evas_Object *obj EINA_UNUSED, - void *event_info EINA_UNUSED) -{ - free(data); -} - -static void _profiles_list_item_del_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) @@ -3377,148 +3350,86 @@ _status_config_scrolling(Evas_Object *win, elm_naviframe_item_simple_push(naviframe, sc); } -static char * -_engine_name_prettify(const char *engine) +static void +_cb_accel(void *data, Evas_Object *obj EINA_UNUSED, void *info EINA_UNUSED) { - char *ret, *ptr; - - ret = strdup(engine); - ret[0] -= 0x20; - - while ((ptr = strpbrk(ret, "_"))) - { - *ptr = ' '; - } + const char *val = data; + const char *ss = elm_config_accel_preference_get(); - return ret; -} - -/* FIXME! ideally, we would trim elm_config.c's _elm_engines list at - build time, making a getter for is as in ecore-evas. */ -static Eina_Bool -_elm_engine_supported(const char *engine) -{ - const char *engines[] = { - "software_x11", - "fb", - "directfb", - "software_16_x11", - "software_8_x11", - "xrender_x11", - "opengl_x11", - "software_gdi", - "sdl", - "software_16_sdl", - "opengl_sdl", - "ews", - "opengl_cocoa", - "psl1ght", - "wayland_shm", - "wayland_egl", - NULL - }; - - unsigned int i; - - for (i = 0; engines[i]; i++) + if ((!ss) || (ss && (strcasecmp(ss, val)))) { -#define ENGINE_COMPARE(name) (!strcmp(engines[i], name)) - if (ENGINE_COMPARE(engine)) - return EINA_TRUE; -#undef ENGINE_COMPARE + elm_config_accel_preference_set(val); + elm_config_all_flush(); + elm_config_save(); } - - return EINA_FALSE; } static void -_engines_list_fill(Evas_Object *l_widget, - Eina_List *e_names) +_cb_accel_override(void *data EINA_UNUSED, Evas_Object *obj, void *info EINA_UNUSED) { - const char *engine, *cur_engine; - void *sel_it = NULL; - Eina_List *l; - - if (!e_names) - return; - - cur_engine = elm_config_engine_get(); + Eina_Bool val = elm_check_state_get(obj); + Eina_Bool sb = elm_config_accel_preference_override_get(); - EINA_LIST_FOREACH(e_names, l, engine) + if (val != sb) { - const char *label; - Elm_Object_Item *list_it; - - if (!_elm_engine_supported(engine)) - continue; - - label = _engine_name_prettify(engine); - - list_it = elm_list_item_append(l_widget, label, NULL, NULL, NULL, - strdup(engine)); - elm_object_item_del_cb_set(list_it, _engines_list_item_del_cb); - free((void *)label); - - if (!strcmp(cur_engine, engine)) - sel_it = list_it; + elm_config_accel_preference_override_set(val); + elm_config_all_flush(); + elm_config_save(); } - - if (sel_it) elm_list_item_selected_set(sel_it, EINA_TRUE); - elm_list_go(l_widget); } static void _status_config_rendering(Evas_Object *win, Evas_Object *naviframe) { - Evas_Object *li, *bx, *fr, *sp, *pd, *bt; - Eina_List *engines; + Evas_Object *li, *bx, *ck; + Elm_Object_Item *it; bx = elm_box_add(win); evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL); - fr = elm_frame_add(win); - elm_object_text_set(fr, "Available Engines"); - evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_box_pack_end(bx, fr); - evas_object_show(fr); - li = elm_list_add(win); - elm_object_content_set(fr, li); evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL); - - engines = ecore_evas_engines_get(); - _engines_list_fill(li, engines); - ecore_evas_engines_free(engines); - + elm_box_pack_end(bx, li); evas_object_show(li); - evas_object_data_set(win, "engines_list", li); - ///////////////////////////////////////////// - sp = elm_separator_add(win); - elm_separator_horizontal_set(sp, EINA_TRUE); - evas_object_size_hint_weight_set(sp, EVAS_HINT_EXPAND, 0.0); - evas_object_size_hint_align_set(sp, EVAS_HINT_FILL, 0.5); - elm_box_pack_end(bx, sp); - evas_object_show(sp); + it = elm_list_item_append(li, "No Acceleration", NULL, NULL, + _cb_accel, "none"); + if (!elm_config_accel_preference_get() || + (!strcasecmp(elm_config_accel_preference_get(), "none"))) + elm_list_item_selected_set(it, EINA_TRUE); + + it = elm_list_item_append(li, "OpenGL / OpenGL-ES", NULL, NULL, + _cb_accel, "gl"); + if (elm_config_accel_preference_get() && + ((!strcasecmp(elm_config_accel_preference_get(), "gl")) || + (!strcasecmp(elm_config_accel_preference_get(), "opengl")))) + elm_list_item_selected_set(it, EINA_TRUE); + + it = elm_list_item_append(li, "3D (any 3D hardware)", NULL, NULL, + _cb_accel, "3d"); + if (elm_config_accel_preference_get() && + (!strcasecmp(elm_config_accel_preference_get(), "3d"))) + elm_list_item_selected_set(it, EINA_TRUE); + + it = elm_list_item_append(li, "Hardware (any hardware)", NULL, NULL, + _cb_accel, "hw"); + if (elm_config_accel_preference_get() && + ((!strcasecmp(elm_config_accel_preference_get(), "hw")) || + (!strcasecmp(elm_config_accel_preference_get(), "hardware")) || + (!strcasecmp(elm_config_accel_preference_get(), "accel")))) + elm_list_item_selected_set(it, EINA_TRUE); - pd = elm_frame_add(win); - elm_object_style_set(pd, "pad_medium"); - evas_object_size_hint_weight_set(pd, 0.0, 0.0); - evas_object_size_hint_align_set(pd, 0.5, 0.5); - elm_box_pack_end(bx, pd); - evas_object_show(pd); + elm_list_go(li); - bt = elm_button_add(win); - evas_object_smart_callback_add(bt, "clicked", _engine_use, li); - elm_object_text_set(bt, "Use Engine"); - evas_object_size_hint_weight_set(bt, 0.0, 0.0); - evas_object_size_hint_align_set(bt, 0.5, 0.5); - elm_object_content_set(pd, bt); - evas_object_show(bt); + CHECK_ADD("Override Preferred Acceleration", + "Force any application requesting
" + "acceleration to use the system
" + "configured acceleration as above", + _cb_accel_override, NULL); + elm_check_state_set(ck, elm_config_accel_preference_override_get()); evas_object_data_set(win, "rendering", bx); elm_naviframe_item_simple_push(naviframe, bx); diff --git a/legacy/elementary/src/lib/elm_config.c b/legacy/elementary/src/lib/elm_config.c index 96430ce..c90d3ca 100644 --- a/legacy/elementary/src/lib/elm_config.c +++ b/legacy/elementary/src/lib/elm_config.c @@ -480,6 +480,8 @@ _desc_init(void) #define D _config_edd ELM_CONFIG_VAL(D, T, config_version, T_INT); ELM_CONFIG_VAL(D, T, engine, T_STRING); + ELM_CONFIG_VAL(D, T, accel, T_STRING); + ELM_CONFIG_VAL(D, T, accel_override, T_UCHAR); ELM_CONFIG_VAL(D, T, vsync, T_UCHAR); ELM_CONFIG_VAL(D, T, thumbscroll_enable, T_UCHAR); ELM_CONFIG_VAL(D, T, thumbscroll_threshold, T_INT); @@ -1311,6 +1313,7 @@ _config_free(Elm_Config *cfg) eina_stringshare_del(fontdir); } eina_stringshare_del(cfg->engine); + eina_stringshare_del(cfg->accel); EINA_LIST_FREE(cfg->font_overlays, fo) { eina_stringshare_del(fo->text_class); @@ -1501,6 +1504,8 @@ _config_load(void) _elm_config = ELM_NEW(Elm_Config); _elm_config->config_version = ELM_CONFIG_VERSION; _elm_config->engine = eina_stringshare_add(DEFAULT_ENGINE); + _elm_config->accel = NULL; + _elm_config->accel_override = 0; _elm_config->vsync = 0; _elm_config->thumbscroll_enable = EINA_TRUE; _elm_config->thumbscroll_threshold = 24; @@ -2681,6 +2686,30 @@ elm_config_cache_edje_collection_cache_size_set(int size) } EAPI Eina_Bool +elm_config_vsync_get(void) +{ + return _elm_config->vsync; +} + +EAPI void +elm_config_vsync_set(Eina_Bool enabled) +{ + _elm_config->vsync = enabled; +} + +EAPI Eina_Bool +elm_config_accel_preference_override_get(void) +{ + return _elm_config->accel_override; +} + +EAPI void +elm_config_accel_preference_override_set(Eina_Bool enabled) +{ + _elm_config->accel_override = enabled; +} + +EAPI Eina_Bool elm_config_focus_highlight_enabled_get(void) { return _elm_config->focus_highlight_enable; @@ -3362,17 +3391,22 @@ elm_config_preferred_engine_set(const char *engine) EAPI const char * elm_config_accel_preference_get(void) { - return _elm_accel_preference; + if (_elm_accel_preference) return _elm_accel_preference; + return _elm_config->accel; } EAPI void elm_config_accel_preference_set(const char *pref) { if (pref) - eina_stringshare_replace(&(_elm_accel_preference), pref); + { + eina_stringshare_replace(&(_elm_accel_preference), pref); + eina_stringshare_replace(&(_elm_config->accel), pref); + } else { ELM_SAFE_FREE(_elm_accel_preference, eina_stringshare_del); + ELM_SAFE_FREE(_elm_config->accel, eina_stringshare_del); } } diff --git a/legacy/elementary/src/lib/elm_config.h b/legacy/elementary/src/lib/elm_config.h index 7cf9a59..fcce7e1 100644 --- a/legacy/elementary/src/lib/elm_config.h +++ b/legacy/elementary/src/lib/elm_config.h @@ -1197,6 +1197,56 @@ EAPI int elm_config_cache_edje_collection_cache_size_get(void); EAPI void elm_config_cache_edje_collection_cache_size_set(int size); /** + * Get the configured vsync flag + * + * This gets the globally configured vsync flag that asks some backend + * engines to use vsync display if possible. + * + * @return If vsync is enabled + * + * @since 1.11 + */ +EAPI Eina_Bool elm_config_vsync_get(void); + +/** + * Set the configured vsync flag + * + * This sets the globally configured vsync flag that asks some backend + * engines to use vsync display if possible. + * + * @param enabled This should be EINA_TRUE if enabled, or EINA_FALSE if not. + * + * @since 1.11 + */ +EAPI void elm_config_vsync_set(Eina_Bool enabled); + +/** + * Get the acceleration override preference flag + * + * This gets the acceleration override preference. This is a flag that + * has the global system acceleration preference configureation forcibly + * override whatever acceleration preference the application may want. + * + * @return If acceleration override is enabled + * + * @since 1.11 + */ +EAPI Eina_Bool elm_config_accel_preference_override_get(void); + +/** + * Set the acceleration override preference flag + * + * This sets the acceleration override preference. This is a flag that + * has the global system acceleration preference configureation forcibly + * override whatever acceleration preference the application may want. + * + * @param enabled This should be EINA_TRUE if enabled, or EINA_FALSE if not. + * + * @since 1.11 + */ +EAPI void elm_config_accel_preference_override_set(Eina_Bool enabled); + +/** * Get the enable status of the focus highlight * * This gets whether the highlight on focused objects is enabled or not diff --git a/legacy/elementary/src/lib/elm_priv.h b/legacy/elementary/src/lib/elm_priv.h index c8d3e97..4ea9591 100644 --- a/legacy/elementary/src/lib/elm_priv.h +++ b/legacy/elementary/src/lib/elm_priv.h @@ -182,6 +182,8 @@ struct _Elm_Config { int config_version; const char *engine; + const char *accel; + unsigned char accel_override; unsigned char vsync; unsigned char thumbscroll_enable; int thumbscroll_threshold; diff --git a/legacy/elementary/src/lib/elm_win.c b/legacy/elementary/src/lib/elm_win.c index 77696de..1a29b69 100644 --- a/legacy/elementary/src/lib/elm_win.c +++ b/legacy/elementary/src/lib/elm_win.c @@ -2932,8 +2932,11 @@ _accel_is_gl(void) { const char *env = NULL; const char *str; - - str = _elm_accel_preference; + + if (_elm_config->accel) str = _elm_config->accel; + if (_elm_accel_preference) str = _elm_accel_preference; + if ((_elm_config->accel_override) && (_elm_config->accel)) + str = _elm_config->accel; env = getenv("ELM_ACCEL"); if (env) str = env; if ((str) && @@ -3077,6 +3080,36 @@ _elm_win_constructor(Eo *obj, Elm_Win_Data *sd, const char *name, Elm_Win_Type t enginelist[0] = ENGINE_GET(); enginelist[1] = NULL; } + else if (getenv("DISPLAY")) + { + if (_accel_is_gl()) + { + enginelist[0] = ELM_OPENGL_X11; + enginelist[1] = ELM_SOFTWARE_X11; + enginelist[2] = NULL; + } + else + { + enginelist[0] = ELM_SOFTWARE_X11; + enginelist[1] = ELM_OPENGL_X11; + enginelist[2] = NULL; + } + } + else if (getenv("WAYLAND_DISPLAY")) + { + if (_accel_is_gl()) + { + enginelist[0] = ELM_WAYLAND_EGL; + enginelist[1] = ELM_WAYLAND_SHM; + enginelist[2] = NULL; + } + else + { + enginelist[0] = ELM_WAYLAND_SHM; + enginelist[1] = ELM_WAYLAND_EGL; + enginelist[2] = NULL; + } + } else { if (_accel_is_gl()) -- 2.7.4