From: Youngjae Cho Date: Thu, 12 Dec 2019 08:23:51 +0000 (+0900) Subject: Refactoring display-dpms X-Git-Tag: accepted/tizen/unified/20191219.143625~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F06%2F220006%2F5;p=platform%2Fcore%2Fsystem%2Fdeviced.git Refactoring display-dpms - Separate initialization from dpms_is_available() to init_dpms(). - Integrate dpms exit sequence into exit_dpms() for poweroff. - Delete pointer 'wl_glib_data' and use pointer 'info' instead, which are practically same. - Fix usage of disconnect_interface_with_dpms() considering GSource finalize. Change-Id: I7579b7338ee263b4c991cc8a055cefc0eb392f02 Signed-off-by: Youngjae Cho --- diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 4a3e570..a9f332a 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -2640,11 +2640,11 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static gboolean lcd_on_wm_ready(gpointer data) +static gboolean delayed_init_dpms(gpointer data) { int timeout; - if (!check_wm_ready()) + if (!init_dpms()) return G_SOURCE_CONTINUE; switch (pm_cur_state) { @@ -2666,11 +2666,11 @@ static gboolean lcd_on_wm_ready(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_wm_ready(void) +static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); if (id == 0) - _E("Failed to add wm_ready timeout."); + _E("Failed to add init_dpms timeout."); } /** @@ -2750,7 +2750,6 @@ static void display_init(void *data) int ret, i; unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; - bool wm_ready; _I("Start power manager."); @@ -2821,11 +2820,11 @@ static void display_init(void *data) /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ - wm_ready = check_wm_ready(); - if (wm_ready) + // wm_ready = check_wm_ready(); + if (init_dpms()) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); else - add_timer_for_wm_ready(); + add_timer_for_init_dpms(); if (display_conf.lcd_always_on) { _I("LCD always on."); diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 0c4c453..4064ee2 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -1023,8 +1023,7 @@ int exit_sysfs(void) backlight_update(); - g_main_loop_unref(dpms_loop); - g_main_context_unref(dpms_context); + exit_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 14663cb..9d514d8 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -2650,11 +2650,11 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static gboolean lcd_on_wm_ready(gpointer data) +static gboolean delayed_init_dpms(gpointer data) { int timeout; - if (!check_wm_ready()) + if (!init_dpms()) return G_SOURCE_CONTINUE; switch (pm_cur_state) { @@ -2676,11 +2676,11 @@ static gboolean lcd_on_wm_ready(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_wm_ready(void) +static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); if (id == 0) - _E("Failed to add wm_ready timeout."); + _E("Failed to add init_dpms timeout."); } /** @@ -2760,7 +2760,6 @@ static void display_init(void *data) int ret, i; unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; - bool wm_ready; _I("Start power manager."); @@ -2831,11 +2830,11 @@ static void display_init(void *data) /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ - wm_ready = check_wm_ready(); - if (wm_ready) + // wm_ready = check_wm_ready(); + if (init_dpms()) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); else - add_timer_for_wm_ready(); + add_timer_for_init_dpms(); if (display_conf.lcd_always_on) { _I("LCD always on."); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 0c4c453..4064ee2 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -1023,8 +1023,7 @@ int exit_sysfs(void) backlight_update(); - g_main_loop_unref(dpms_loop); - g_main_context_unref(dpms_context); + exit_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index d493b9f..32c0fed 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -2637,11 +2637,11 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static gboolean lcd_on_wm_ready(gpointer data) +static gboolean delayed_init_dpms(gpointer data) { int timeout; - if (!check_wm_ready()) + if (!init_dpms()) return G_SOURCE_CONTINUE; switch (pm_cur_state) { @@ -2663,11 +2663,11 @@ static gboolean lcd_on_wm_ready(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_wm_ready(void) +static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); if (id == 0) - _E("Failed to add wm_ready timeout."); + _E("Failed to add init_dpms timeout."); } /** @@ -2747,7 +2747,6 @@ static void display_init(void *data) int ret, i; unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; - bool wm_ready; _I("Start power manager."); @@ -2818,11 +2817,11 @@ static void display_init(void *data) /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ - wm_ready = check_wm_ready(); - if (wm_ready) + // wm_ready = check_wm_ready(); + if (init_dpms()) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); else - add_timer_for_wm_ready(); + add_timer_for_init_dpms(); if (display_conf.lcd_always_on) { _I("LCD always on."); diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 0c4c453..4064ee2 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -1023,8 +1023,7 @@ int exit_sysfs(void) backlight_update(); - g_main_loop_unref(dpms_loop); - g_main_context_unref(dpms_context); + exit_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 1f0f345..4a20902 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -2667,11 +2667,11 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static gboolean lcd_on_wm_ready(gpointer data) +static gboolean delayed_init_dpms(gpointer data) { int timeout; - if (!check_wm_ready()) + if (!init_dpms()) return G_SOURCE_CONTINUE; switch (pm_cur_state) { @@ -2693,11 +2693,11 @@ static gboolean lcd_on_wm_ready(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_wm_ready(void) +static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); if (id == 0) - _E("Failed to add wm_ready timeout."); + _E("Failed to add init_dpms timeout."); } /** @@ -2777,7 +2777,6 @@ static void display_init(void *data) int ret, i; unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; - bool wm_ready; _I("Start power manager."); @@ -2848,11 +2847,11 @@ static void display_init(void *data) /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ - wm_ready = check_wm_ready(); - if (wm_ready) + // wm_ready = check_wm_ready(); + if (init_dpms()) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); else - add_timer_for_wm_ready(); + add_timer_for_init_dpms(); if (display_conf.lcd_always_on) { _I("LCD always on."); diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 9b5d656..eb6414d 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -1026,8 +1026,7 @@ int exit_sysfs(void) backlight_update(); - g_main_loop_unref(dpms_loop); - g_main_context_unref(dpms_context); + exit_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index bba880c..fb7659b 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -27,6 +27,7 @@ #include "core/log.h" #include "display/util.h" +#include "display/display-dpms.h" #define DPMS_GET_TIMEOUT 10 /* milisecond */ @@ -43,14 +44,13 @@ typedef struct { uint32_t dpms_mode; } wl_glib_info; -wl_glib_info *info = NULL; +static wl_glib_info *info = NULL; -bool wm_is_ready; +static bool wm_is_ready; static bool dpms_connected; -static GSource *wl_glib_data = NULL; -GMainLoop *dpms_loop; -GMainContext *dpms_context; +static GMainLoop *dpms_loop; +static GMainContext *dpms_context; static bool dpms_get_state_done; static void dpms_handle_set_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) @@ -77,7 +77,7 @@ static gboolean dpms_loop_quit(void *data) return G_SOURCE_REMOVE; } -void disconnect_interface_with_dpms(void) +static void disconnect_interface_with_dpms(wl_glib_info *info) { if (!dpms_connected) return; @@ -108,12 +108,6 @@ void disconnect_interface_with_dpms(void) wl_display_disconnect(info->wl_disp); info->wl_disp= NULL; } - - if (wl_glib_data) { - g_source_destroy(wl_glib_data); - g_source_unref(wl_glib_data); - wl_glib_data = NULL; - } } static const struct tizen_dpms_manager_listener dpms_listener = { @@ -134,17 +128,21 @@ static void handle_global(void *data, struct wl_registry *registry, info->wl_output= wl_registry_bind(registry, name, &wl_output_interface, 2); if (!info->wl_output) { _E("Failed to bind registry."); - disconnect_interface_with_dpms(); + g_source_destroy((GSource *)info); + exit_dpms(); + return; } _D("Get wl_output."); } else if (strcmp(interface, "tizen_dpms_manager") == 0) { info->tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1); if (!info->tz_dpms_mng) { _E("Failed to bind registry."); - disconnect_interface_with_dpms(); - } else - tizen_dpms_manager_add_listener(info->tz_dpms_mng, &dpms_listener, info); + g_source_destroy((GSource *)info); + exit_dpms(); + return; + } + tizen_dpms_manager_add_listener(info->tz_dpms_mng, &dpms_listener, info); _D("Get dpms manager."); } } @@ -327,9 +325,8 @@ wl_glib_client_finalize(GSource *source) _E("Source is NULL."); return; } - info = (wl_glib_info *)source; - disconnect_interface_with_dpms(); + disconnect_interface_with_dpms((wl_glib_info *)source); return; } @@ -340,7 +337,7 @@ static GSourceFuncs wl_glib_client_funcs = { .finalize = wl_glib_client_finalize, }; -GSource* wl_glib_client_init(void) +static bool wl_glib_client_init(void) { int ret; @@ -362,9 +359,6 @@ GSource* wl_glib_client_init(void) goto err; } - dpms_context = g_main_context_new(); - dpms_loop = g_main_loop_new(dpms_context, false); - info->gfd.events = G_IO_IN | G_IO_ERR; info->gfd.revents = 0; @@ -372,18 +366,16 @@ GSource* wl_glib_client_init(void) g_source_attach(&info->gsource, dpms_context); g_source_unref(&info->gsource); - return &info->gsource; + return true; err: - if (info) { - disconnect_interface_with_dpms(); + if (info) g_source_unref(&info->gsource); - } - return NULL; + return false; } -bool check_wm_ready(void) +static bool check_wm_ready(void) { if (access("/run/.wm_ready", F_OK) == 0) { _I("Window manager is ready."); @@ -395,17 +387,6 @@ bool check_wm_ready(void) return false; } -bool connect_interface_with_dpms(void) -{ - wl_glib_data = wl_glib_client_init(); - if (!wl_glib_data) { - _E("Failed to init client."); - return false; - } - - return true; -} - static bool dpms_is_available(void) { /* Check window manager */ @@ -414,14 +395,7 @@ static bool dpms_is_available(void) return false; } - /* Try to connect interface with dpms, because window manager is ready */ - if (!dpms_connected) { - _D("call connect_interface_with_dpms()"); - dpms_connected = connect_interface_with_dpms(); - return dpms_connected; - } - - return true; + return dpms_connected; } void dpms_set_state(int on) @@ -475,3 +449,41 @@ int dpms_get_state(void) else return -ETIMEDOUT; } + +bool init_dpms(void) +{ + if (dpms_connected) + return true; + + if (!check_wm_ready()) + return false; + + _I("Init dpms."); + dpms_context = g_main_context_new(); + dpms_loop = g_main_loop_new(dpms_context, false); + + dpms_connected = wl_glib_client_init(); + if (!dpms_connected) { + g_main_loop_unref(dpms_loop); + dpms_loop = NULL; + + g_main_context_unref(dpms_context); + dpms_context = NULL; + } + + return dpms_connected; +} + +void exit_dpms(void) +{ + _I("Exit dpms."); + if (dpms_loop) { + g_main_loop_unref(dpms_loop); + dpms_loop = NULL; + } + + if (dpms_context) { + g_main_context_unref(dpms_context); + dpms_context = NULL; + } +} diff --git a/src/display/display-dpms.h b/src/display/display-dpms.h index 15b401d..6c401be 100644 --- a/src/display/display-dpms.h +++ b/src/display/display-dpms.h @@ -19,13 +19,8 @@ #ifndef __DISPLAY_DPMS_H__ #define __DISPLAY_DPMS_H__ -bool check_wm_ready(void); -bool dpms_is_available(void); -bool connect_interface_with_dpms(void); -void disconnect_interface_with_dpms(void); void dpms_set_state(int on); int dpms_get_state(void); - -extern GMainLoop *dpms_loop; -extern GMainContext *dpms_context; +bool init_dpms(void); +void exit_dpms(void); #endif /* __DISPLAY_DPMS_H__ */