From: Yunhee Seo Date: Wed, 14 Jun 2023 01:54:25 +0000 (+0900) Subject: display: Relocate default_action() X-Git-Tag: accepted/tizen/unified/dev/20230726.115933~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1089fa81a7e399893bbed57dddec5043293a5f57;p=platform%2Fcore%2Fsystem%2Fdeviced.git display: Relocate default_action() For relocating default_action(), there are some changes. 1. Add device_ops_status getter/setter temporarily. 2. Add lcd on time update and calculation functions. 3. Remove state action functions from the display-plugin. -> Since default_action() has relocated, these functions no longer need to exist. New functions in the display - void display_set_display_ops_status(enum device_ops_status dev_ops_status); - int display_get_display_ops_status(enum device_ops_status *dev_ops_status); -> device_ops_status is set during the display init, probe, exit... New functions in the display-panel - void display_panel_update_lcd_on_timeval(void); - int display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(int *diff_time); -> These functions update lcd_on time and caculate the time difference between lcd_on_direct and do_state_action. New function in the display-state-transition - int display_state_transition_do_state_action(int timeout); -> This function is usually called after the display state changed. It handles the rest of the work for changed display state. Change-Id: If6ccd5f5cbcae21ed87db473596bdc3c71ddb86f Signed-off-by: Yunhee Seo --- diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 6d0393a..484832f 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -100,21 +100,17 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; -static struct timeval lcdon_tv; - -/* default transition, action fuctions */ -static int default_action(int timeout); static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", NULL, default_action, NULL, NULL }, - { S_LCDDIM, "S_LCDDIM", NULL, default_action, NULL, NULL }, - { S_LCDOFF, "S_LCDOFF", NULL, default_action, NULL, NULL }, + { S_NORMAL, "S_NORMAL", NULL, NULL, NULL, NULL }, + { S_LCDDIM, "S_LCDDIM", NULL, NULL, NULL, NULL }, + { S_LCDOFF, "S_LCDOFF", NULL, NULL, NULL, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, - { S_SLEEP, "S_SLEEP", NULL, default_action, NULL, NULL }, + { S_SLEEP, "S_SLEEP", NULL, NULL, NULL, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; @@ -131,11 +127,6 @@ static struct state states[S_END] = { #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 300 /* milli second */ -#define DIFF_TIMEVAL_MS(a, b) \ - (((a.tv_sec * 1000000 + a.tv_usec) - \ - (b.tv_sec * 1000000 + b.tv_usec)) \ - / 1000) - static struct display_config display_conf = { .lock_wait_time = LOCK_SCREEN_WATING_TIME, .longpress_interval = LONG_PRESS_INTERVAL, @@ -215,20 +206,12 @@ void lcd_on_direct(enum device_flags flags) set_pm_cur_state(S_NORMAL); _D("lcd is on directly"); - gettimeofday(&lcdon_tv, NULL); + display_panel_update_lcd_on_timeval(); display_panel_lcd_on_procedure(LCD_NORMAL, flags); update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } -static inline bool check_lcd_is_on(void) -{ - if (display_panel_get_dpms_cached_state() != DPMS_ON) - return false; - - return true; -} - static gboolean timer_refresh_cb(gpointer data) { struct state *st; @@ -238,8 +221,7 @@ static gboolean timer_refresh_cb(gpointer data) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -251,7 +233,7 @@ int custom_lcdon(int timeout) if (timeout <= 0) return -EINVAL; - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_GESTURE); _I("Custom lcd on timeout(%d ms).", timeout); @@ -263,9 +245,7 @@ int custom_lcdon(int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); g_idle_add(timer_refresh_cb, NULL); @@ -307,9 +287,7 @@ int custom_lcdoff(enum device_flags flag) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -336,7 +314,7 @@ int display_on_by_reason(const char *reason, int timeout) return -EINVAL; } - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(flag); _I("platform lcd on by %s (%d ms)", reason, timeout); @@ -348,9 +326,7 @@ int display_on_by_reason(const char *reason, int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -392,9 +368,7 @@ int display_off_by_reason(const char *reason) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -408,12 +382,11 @@ static void default_proc_change_state_action(enum state_t next, int timeout) st = &states[get_pm_cur_state()]; - if (st && st->action) { - if (timeout < 0) - st->action(st->timeout); - else - st->action(timeout); - } + if (timeout < 0) + display_state_transition_do_state_action(st->timeout); + else + display_state_transition_do_state_action(timeout); + } static int default_proc_change_state(unsigned int cond, pid_t pid) @@ -425,7 +398,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) switch (next) { case S_NORMAL: - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_EVENT); update_display_locktime(LOCK_SCREEN_CONTROL_TIMEOUT); default_proc_change_state_action(next, -1); @@ -617,136 +590,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -/* default enter action function */ -static int default_action(int timeout) -{ - int wakeup_count = -1, pm_cur_state; - time_t now; - double diff; - static time_t last_update_time = 0; - static int last_timeout = 0; - struct timeval now_tv; - bool custom_status; - int brightness; - bool lcd_paneloff_mode = false; - - if (status != DEVICE_OPS_STATUS_START) { - _E("Display is not started."); - return -EINVAL; - } - - if (get_pm_cur_state() != S_SLEEP) { - if ((get_pm_cur_state() == S_NORMAL) && - lcdon_tv.tv_sec != 0) { - gettimeofday(&now_tv, NULL); - timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); - lcdon_tv.tv_sec = 0; - } - /* set timer with current state timeout */ - display_state_transition_reset_state_transition_timeout(timeout); - - if (get_pm_cur_state() == S_NORMAL) { - time(&last_update_time); - last_timeout = timeout; - } else { - _I("Timout set: %s state %d ms", - states[get_pm_cur_state()].name, timeout); - } - } - - if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { - power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, - power_get_wakeup_reason(), NULL); - set_setting_pmstate(get_pm_cur_state()); - pm_cur_state = get_pm_cur_state(); - device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); - } - - if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { - time(&now); - diff = difftime(now, last_update_time); - _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", - states[get_pm_cur_state()].name, last_timeout, diff); - } - - switch (get_pm_cur_state()) { - case S_NORMAL: - /* - * normal state : backlight on and restore - * the previous brightness - */ - if (get_pm_old_state() == S_LCDDIM) - display_backlight_update_by_default_brightness(); - - if (check_lcd_is_on() == false) - display_panel_lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); - break; - - case S_LCDDIM: - display_backlight_get_custom_status(&custom_status); - if ((get_pm_old_state() == S_NORMAL) && custom_status) { - display_backlight_get_brightness(&brightness); - display_backlight_set_custom_brightness(brightness); - } - /* lcd dim state : dim the brightness */ - display_backlight_set_brightness_by_dim_brightness(); - - if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE); - break; - - case S_LCDOFF: - if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { - /* lcd off state : turn off the backlight */ - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - } - - display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); - if (display_panel_get_dpms_cached_state() == DPMS_ON - || lcd_paneloff_mode) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - break; - - case S_SLEEP: - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - - if (!pm_get_power_lock_support()) { - /* sleep state : set system mode to SUSPEND */ - if (get_wakeup_count(&wakeup_count) < 0) - _E("Wakeup count read error."); - - if (wakeup_count < 0) { - _I("Wakup Event. Can not enter suspend mode."); - goto go_lcd_off; - } - - if (set_wakeup_count(wakeup_count) < 0) { - _E("Wakeup count write error."); - goto go_lcd_off; - } - } - goto go_suspend; - } - - return 0; - -go_suspend: -#ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); -#endif - power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); - return 0; - -go_lcd_off: - if (!pm_get_power_lock_support()) { - /* Resume !! */ - display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); - } - return 0; -} - static void default_saving_mode(int onoff) { if (onoff) @@ -763,6 +606,7 @@ int poll_callback(int condition, PMMsg *data) static time_t last_t; time_t now; + display_get_display_ops_status(&status); if (status != DEVICE_OPS_STATUS_START) { _E("Display logic is not started."); return -ECANCELED; @@ -1354,7 +1198,7 @@ static void display_init(void *data) if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - status = DEVICE_OPS_STATUS_START; + display_set_display_ops_status(DEVICE_OPS_STATUS_START); if (display_conf.timeout_enable) { timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ @@ -1376,7 +1220,7 @@ static void display_exit(void *data) { int i = INIT_END; - status = DEVICE_OPS_STATUS_STOP; + display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); /* Set current state to S_NORMAL */ set_pm_cur_state(S_NORMAL); @@ -1434,6 +1278,7 @@ static int display_start(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_START) return -EALREADY; @@ -1457,6 +1302,7 @@ static int display_stop(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_STOP) return -EALREADY; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index f7732c4..b6f15f0 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -102,21 +102,17 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; -static struct timeval lcdon_tv; - -/* default transition, action fuctions */ -static int default_action(int timeout); static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", NULL, default_action, NULL, NULL }, - { S_LCDDIM, "S_LCDDIM", NULL, default_action, NULL, NULL }, - { S_LCDOFF, "S_LCDOFF", NULL, default_action, NULL, NULL }, + { S_NORMAL, "S_NORMAL", NULL, NULL, NULL, NULL }, + { S_LCDDIM, "S_LCDDIM", NULL, NULL, NULL, NULL }, + { S_LCDOFF, "S_LCDOFF", NULL, NULL, NULL, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, - { S_SLEEP, "S_SLEEP", NULL, default_action, NULL, NULL }, + { S_SLEEP, "S_SLEEP", NULL, NULL, NULL, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; @@ -133,11 +129,6 @@ static struct state states[S_END] = { #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 300 /* milli second */ -#define DIFF_TIMEVAL_MS(a, b) \ - (((a.tv_sec * 1000000 + a.tv_usec) - \ - (b.tv_sec * 1000000 + b.tv_usec)) \ - / 1000) - static struct display_config display_conf = { .lock_wait_time = LOCK_SCREEN_WATING_TIME, .longpress_interval = LONG_PRESS_INTERVAL, @@ -222,20 +213,12 @@ void lcd_on_direct(enum device_flags flags) set_pm_cur_state(S_NORMAL); _D("lcd is on directly"); - gettimeofday(&lcdon_tv, NULL); + display_panel_update_lcd_on_timeval(); display_panel_lcd_on_procedure(LCD_NORMAL, flags); update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } -static inline bool check_lcd_is_on(void) -{ - if (display_panel_get_dpms_cached_state() != DPMS_ON) - return false; - - return true; -} - static gboolean timer_refresh_cb(gpointer data) { struct state *st; @@ -245,8 +228,7 @@ static gboolean timer_refresh_cb(gpointer data) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -258,7 +240,7 @@ int custom_lcdon(int timeout) if (timeout <= 0) return -EINVAL; - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_GESTURE); _I("Custom lcd on timeout(%d ms).", timeout); @@ -270,9 +252,7 @@ int custom_lcdon(int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); g_idle_add(timer_refresh_cb, NULL); @@ -314,9 +294,7 @@ int custom_lcdoff(enum device_flags flag) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -343,7 +321,7 @@ int display_on_by_reason(const char *reason, int timeout) return -EINVAL; } - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(flag); _I("platform lcd on by %s (%d ms)", reason, timeout); @@ -355,9 +333,7 @@ int display_on_by_reason(const char *reason, int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -399,9 +375,7 @@ int display_off_by_reason(const char *reason) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -415,12 +389,10 @@ static void default_proc_change_state_action(enum state_t next, int timeout) st = &states[get_pm_cur_state()]; - if (st && st->action) { - if (timeout < 0) - st->action(st->timeout); - else - st->action(timeout); - } + if (timeout < 0) + display_state_transition_do_state_action(st->timeout); + else + display_state_transition_do_state_action(timeout); } static int default_proc_change_state(unsigned int cond, pid_t pid) @@ -432,7 +404,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) switch (next) { case S_NORMAL: - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_EVENT); update_display_locktime(LOCK_SCREEN_CONTROL_TIMEOUT); default_proc_change_state_action(next, -1); @@ -627,136 +599,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -/* default enter action function */ -static int default_action(int timeout) -{ - int wakeup_count = -1, pm_cur_state; - time_t now; - double diff; - static time_t last_update_time = 0; - static int last_timeout = 0; - struct timeval now_tv; - bool custom_status; - int brightness; - bool lcd_paneloff_mode = false; - - if (status != DEVICE_OPS_STATUS_START) { - _E("Display is not started."); - return -EINVAL; - } - - if (get_pm_cur_state() != S_SLEEP) { - if ((get_pm_cur_state() == S_NORMAL) && - lcdon_tv.tv_sec != 0) { - gettimeofday(&now_tv, NULL); - timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); - lcdon_tv.tv_sec = 0; - } - /* set timer with current state timeout */ - display_state_transition_reset_state_transition_timeout(timeout); - - if (get_pm_cur_state() == S_NORMAL) { - time(&last_update_time); - last_timeout = timeout; - } else { - _I("Timout set: %s state %d ms", - states[get_pm_cur_state()].name, timeout); - } - } - - if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { - power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, - power_get_wakeup_reason(), NULL); - set_setting_pmstate(get_pm_cur_state()); - pm_cur_state = get_pm_cur_state(); - device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); - } - - if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { - time(&now); - diff = difftime(now, last_update_time); - _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", - states[get_pm_cur_state()].name, last_timeout, diff); - } - - switch (get_pm_cur_state()) { - case S_NORMAL: - /* - * normal state : backlight on and restore - * the previous brightness - */ - if (get_pm_old_state() == S_LCDDIM) - display_backlight_update_by_default_brightness(); - - if (check_lcd_is_on() == false) - display_panel_lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); - break; - - case S_LCDDIM: - display_backlight_get_custom_status(&custom_status); - if ((get_pm_old_state() == S_NORMAL) && custom_status) { - display_backlight_get_brightness(&brightness); - display_backlight_set_custom_brightness(brightness); - } - /* lcd dim state : dim the brightness */ - display_backlight_set_brightness_by_dim_brightness(); - - if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE); - break; - - case S_LCDOFF: - if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { - /* lcd off state : turn off the backlight */ - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - } - - display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); - if (display_panel_get_dpms_cached_state() == DPMS_ON - || lcd_paneloff_mode) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - break; - - case S_SLEEP: - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - - if (!pm_get_power_lock_support()) { - /* sleep state : set system mode to SUSPEND */ - if (get_wakeup_count(&wakeup_count) < 0) - _E("Wakeup count read error."); - - if (wakeup_count < 0) { - _I("Wakup Event. Can not enter suspend mode."); - goto go_lcd_off; - } - - if (set_wakeup_count(wakeup_count) < 0) { - _E("Wakeup count write error."); - goto go_lcd_off; - } - } - goto go_suspend; - } - - return 0; - -go_suspend: -#ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); -#endif - power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); - return 0; - -go_lcd_off: - if (!pm_get_power_lock_support()) { - /* Resume !! */ - display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); - } - return 0; -} - static void default_saving_mode(int onoff) { if (onoff) @@ -773,6 +615,7 @@ int poll_callback(int condition, PMMsg *data) static time_t last_t; time_t now; + display_get_display_ops_status(&status); if (status != DEVICE_OPS_STATUS_START) { _E("Display logic is not started."); return -ECANCELED; @@ -1360,7 +1203,7 @@ static void display_init(void *data) if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - status = DEVICE_OPS_STATUS_START; + display_set_display_ops_status(DEVICE_OPS_STATUS_START); if (display_conf.timeout_enable) { timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ @@ -1382,7 +1225,7 @@ static void display_exit(void *data) { int i = INIT_END; - status = DEVICE_OPS_STATUS_STOP; + display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); /* Set current state to S_NORMAL */ set_pm_cur_state(S_NORMAL); @@ -1445,6 +1288,7 @@ static int display_start(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_START) return -EALREADY; @@ -1468,6 +1312,7 @@ static int display_stop(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_STOP) return -EALREADY; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index e53409e..8397009 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -100,21 +100,17 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; -static struct timeval lcdon_tv; - -/* default transition, action fuctions */ -static int default_action(int timeout); static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", NULL, default_action, NULL, NULL }, - { S_LCDDIM, "S_LCDDIM", NULL, default_action, NULL, NULL }, - { S_LCDOFF, "S_LCDOFF", NULL, default_action, NULL, NULL }, + { S_NORMAL, "S_NORMAL", NULL, NULL, NULL, NULL }, + { S_LCDDIM, "S_LCDDIM", NULL, NULL, NULL, NULL }, + { S_LCDOFF, "S_LCDOFF", NULL, NULL, NULL, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, - { S_SLEEP, "S_SLEEP", NULL, default_action, NULL, NULL }, + { S_SLEEP, "S_SLEEP", NULL, NULL, NULL, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; @@ -131,11 +127,6 @@ static struct state states[S_END] = { #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 300 /* milli second */ -#define DIFF_TIMEVAL_MS(a, b) \ - (((a.tv_sec * 1000000 + a.tv_usec) - \ - (b.tv_sec * 1000000 + b.tv_usec)) \ - / 1000) - static struct display_config display_conf = { .lock_wait_time = LOCK_SCREEN_WATING_TIME, .longpress_interval = LONG_PRESS_INTERVAL, @@ -215,20 +206,12 @@ void lcd_on_direct(enum device_flags flags) set_pm_cur_state(S_NORMAL); _D("lcd is on directly"); - gettimeofday(&lcdon_tv, NULL); + display_panel_update_lcd_on_timeval(); display_panel_lcd_on_procedure(LCD_NORMAL, flags); update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } -static inline bool check_lcd_is_on(void) -{ - if (display_panel_get_dpms_cached_state() != DPMS_ON) - return false; - - return true; -} - static gboolean timer_refresh_cb(gpointer data) { struct state *st; @@ -238,8 +221,7 @@ static gboolean timer_refresh_cb(gpointer data) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -251,7 +233,7 @@ int custom_lcdon(int timeout) if (timeout <= 0) return -EINVAL; - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_GESTURE); _I("Custom lcd on timeout(%d ms).", timeout); @@ -263,9 +245,7 @@ int custom_lcdon(int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); g_idle_add(timer_refresh_cb, NULL); @@ -307,9 +287,7 @@ int custom_lcdoff(enum device_flags flag) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -336,7 +314,7 @@ int display_on_by_reason(const char *reason, int timeout) return -EINVAL; } - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(flag); _I("platform lcd on by %s (%d ms)", reason, timeout); @@ -348,9 +326,7 @@ int display_on_by_reason(const char *reason, int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -392,9 +368,7 @@ int display_off_by_reason(const char *reason) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -408,12 +382,10 @@ static void default_proc_change_state_action(enum state_t next, int timeout) st = &states[get_pm_cur_state()]; - if (st && st->action) { - if (timeout < 0) - st->action(st->timeout); - else - st->action(timeout); - } + if (timeout < 0) + display_state_transition_do_state_action(st->timeout); + else + display_state_transition_do_state_action(timeout); } static int default_proc_change_state(unsigned int cond, pid_t pid) @@ -425,7 +397,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) switch (next) { case S_NORMAL: - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_EVENT); update_display_locktime(LOCK_SCREEN_CONTROL_TIMEOUT); default_proc_change_state_action(next, -1); @@ -617,136 +589,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -/* default enter action function */ -static int default_action(int timeout) -{ - int wakeup_count = -1, pm_cur_state; - time_t now; - double diff; - static time_t last_update_time = 0; - static int last_timeout = 0; - struct timeval now_tv; - bool custom_status; - int brightness; - bool lcd_paneloff_mode = false; - - if (status != DEVICE_OPS_STATUS_START) { - _E("Display is not started."); - return -EINVAL; - } - - if (get_pm_cur_state() != S_SLEEP) { - if ((get_pm_cur_state() == S_NORMAL) && - lcdon_tv.tv_sec != 0) { - gettimeofday(&now_tv, NULL); - timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); - lcdon_tv.tv_sec = 0; - } - /* set timer with current state timeout */ - display_state_transition_reset_state_transition_timeout(timeout); - - if (get_pm_cur_state() == S_NORMAL) { - time(&last_update_time); - last_timeout = timeout; - } else { - _I("Timout set: %s state %d ms", - states[get_pm_cur_state()].name, timeout); - } - } - - if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { - power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, - power_get_wakeup_reason(), NULL); - set_setting_pmstate(get_pm_cur_state()); - pm_cur_state = get_pm_cur_state(); - device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); - } - - if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { - time(&now); - diff = difftime(now, last_update_time); - _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", - states[get_pm_cur_state()].name, last_timeout, diff); - } - - switch (get_pm_cur_state()) { - case S_NORMAL: - /* - * normal state : backlight on and restore - * the previous brightness - */ - if (get_pm_old_state() == S_LCDDIM) - display_backlight_update_by_default_brightness(); - - if (check_lcd_is_on() == false) - display_panel_lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); - break; - - case S_LCDDIM: - display_backlight_get_custom_status(&custom_status); - if ((get_pm_old_state() == S_NORMAL) && custom_status) { - display_backlight_get_brightness(&brightness); - display_backlight_set_custom_brightness(brightness); - } - /* lcd dim state : dim the brightness */ - display_backlight_set_brightness_by_dim_brightness(); - - if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE); - break; - - case S_LCDOFF: - if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { - /* lcd off state : turn off the backlight */ - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - } - - display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); - if (display_panel_get_dpms_cached_state() == DPMS_ON - || lcd_paneloff_mode) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - break; - - case S_SLEEP: - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - - if (!pm_get_power_lock_support()) { - /* sleep state : set system mode to SUSPEND */ - if (get_wakeup_count(&wakeup_count) < 0) - _E("Wakeup count read error."); - - if (wakeup_count < 0) { - _I("Wakup Event. Can not enter suspend mode."); - goto go_lcd_off; - } - - if (set_wakeup_count(wakeup_count) < 0) { - _E("Wakeup count write error."); - goto go_lcd_off; - } - } - goto go_suspend; - } - - return 0; - -go_suspend: -#ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); -#endif - power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); - return 0; - -go_lcd_off: - if (!pm_get_power_lock_support()) { - /* Resume !! */ - display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); - } - return 0; -} - static void default_saving_mode(int onoff) { if (onoff) @@ -763,6 +605,7 @@ int poll_callback(int condition, PMMsg *data) static time_t last_t; time_t now; + display_get_display_ops_status(&status); if (status != DEVICE_OPS_STATUS_START) { _E("Display logic is not started."); return -ECANCELED; @@ -1351,7 +1194,7 @@ static void display_init(void *data) if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - status = DEVICE_OPS_STATUS_START; + display_set_display_ops_status(DEVICE_OPS_STATUS_START); if (display_conf.timeout_enable) { timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ @@ -1373,7 +1216,7 @@ static void display_exit(void *data) { int i = INIT_END; - status = DEVICE_OPS_STATUS_STOP; + display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); /* Set current state to S_NORMAL */ set_pm_cur_state(S_NORMAL); @@ -1431,6 +1274,7 @@ static int display_start(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_START) return -EALREADY; @@ -1454,6 +1298,7 @@ static int display_stop(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_STOP) return -EALREADY; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 2aadae3..ee2c0a5 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -113,7 +113,6 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; static guint transit_timer; -static struct timeval lcdon_tv; /* * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial * state because it should be sent from previous state at booting time. @@ -150,11 +149,6 @@ static struct state states[S_END] = { #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 300 /* milli second */ -#define DIFF_TIMEVAL_MS(a, b) \ - (((a.tv_sec * 1000000 + a.tv_usec) - \ - (b.tv_sec * 1000000 + b.tv_usec)) \ - / 1000) - #define FORCE_RELEASE_LOCK_INTERVAL 5 /* seconds */ static struct display_config display_conf = { @@ -429,7 +423,7 @@ void lcd_on_direct(enum device_flags flags) set_pm_cur_state(S_NORMAL); _D("lcd is on directly"); - gettimeofday(&lcdon_tv, NULL); + display_panel_update_lcd_on_timeval(); lcd_on_procedure(LCD_NORMAL, flags); update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); @@ -932,11 +926,12 @@ static int default_action(int timeout) double diff; static time_t last_update_time = 0; static int last_timeout = 0; - struct timeval now_tv; bool custom_status; int brightness; bool lcd_paneloff_mode = false; + int diff_time = 0; + display_get_display_ops_status(&status); if (status != DEVICE_OPS_STATUS_START) { _E("Display is not started."); return -EINVAL; @@ -951,11 +946,10 @@ static int default_action(int timeout) } if (get_pm_cur_state() != S_SLEEP) { - if ((get_pm_cur_state() == S_NORMAL) && - lcdon_tv.tv_sec != 0) { - gettimeofday(&now_tv, NULL); - timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); - lcdon_tv.tv_sec = 0; + if ((get_pm_cur_state() == S_NORMAL)) { + if (display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(&diff_time) == 0) { + timeout -= diff_time; + } } /* set timer with current state timeout */ display_state_transition_reset_state_transition_timeout(timeout); @@ -1081,6 +1075,7 @@ int poll_callback(int condition, PMMsg *data) static time_t last_t; time_t now; + display_get_display_ops_status(&status); if (status != DEVICE_OPS_STATUS_START) { _E("Display logic is not started."); return -ECANCELED; @@ -1699,7 +1694,7 @@ static void display_init(void *data) if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - status = DEVICE_OPS_STATUS_START; + display_set_display_ops_status(DEVICE_OPS_STATUS_START); if (display_conf.timeout_enable) { timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ @@ -1721,7 +1716,7 @@ static void display_exit(void *data) { int i = INIT_END; - status = DEVICE_OPS_STATUS_STOP; + display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); /* Set current state to S_NORMAL */ set_pm_cur_state(S_NORMAL); @@ -1784,6 +1779,7 @@ static int display_start(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_START) return -EALREADY; @@ -1807,6 +1803,7 @@ static int display_stop(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_STOP) return -EALREADY; diff --git a/src/display/display-panel.c b/src/display/display-panel.c index 2c94538..813bedb 100644 --- a/src/display/display-panel.c +++ b/src/display/display-panel.c @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "shared/log.h" #include "power/power-suspend.h" @@ -34,9 +35,15 @@ #define LCD_PHASED_MIN_BRIGHTNESS 1 #define LCD_PHASED_CHANGE_STEP 5 +#define DIFF_TIMEVAL_MS(a, b) \ + (((a.tv_sec * 1000000 + a.tv_usec) - \ + (b.tv_sec * 1000000 + b.tv_usec)) \ + / 1000) + static int dpms_running_state = DPMS_SETTING_DONE; static bool lcd_paneloff_mode = false; static bool lcd_on_broadcasted = true; +static struct timeval lcd_on_timeval; /* FIXME: This function is for temporary use, should be fixed after plugin refactoring */ int display_panel_set_dpms_state(int dpms_on, enum device_flags flags) @@ -304,6 +311,28 @@ bool display_panel_is_lcd_on_state_broadcasted(void) return lcd_on_broadcasted; } +/* FIXME: lcd on time calculation should be discussed, because it is only for lcd_on_direct routine */ +void display_panel_update_lcd_on_timeval(void) +{ + gettimeofday(&lcd_on_timeval, NULL); +} + +int display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(int *diff_time) +{ + struct timeval now_timeval; + + if (!diff_time) + return -EINVAL; + + if (lcd_on_timeval.tv_sec != 0) { + gettimeofday(&now_timeval, NULL); + *diff_time = DIFF_TIMEVAL_MS(now_timeval, lcd_on_timeval); + return 0; + } + + return -1; +} + /* FIXME: This function is deprecated, should be fixed after plugin refactoring */ void display_panel_set_dpms_running_state(int val) { diff --git a/src/display/display-panel.h b/src/display/display-panel.h index 862fc35..e6bb4c6 100644 --- a/src/display/display-panel.h +++ b/src/display/display-panel.h @@ -35,6 +35,8 @@ void display_panel_get_lcd_paneloff_mode(bool *on); void display_panel_lcd_on_procedure(int state, enum device_flags flag); void display_panel_lcd_off_procedure(enum device_flags flag); bool display_panel_is_lcd_on_state_broadcasted(void); +void display_panel_update_lcd_on_timeval(void); +int display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(int *diff_time); /* Deprecated functions */ int display_panel_set_image_effect(enum display_image_effect effect); int display_panel_get_image_effect(enum display_image_effect *effect); diff --git a/src/display/display-plugin.c b/src/display/display-plugin.c index d588965..c46b17b 100644 --- a/src/display/display-plugin.c +++ b/src/display/display-plugin.c @@ -168,23 +168,6 @@ bool display_plugin_state_is_there_default_trans(enum state_t state) return false; } -int display_plugin_state_do_default_action(enum state_t state, int timeout) -{ - if (g_display_plugin.display_states[state] && g_display_plugin.display_states[state]->action) - return g_display_plugin.display_states[state]->action(timeout); - - return -EOPNOTSUPP; -} - -/* FIXME: default_action/default_trans naming should be changed after state transition functions are relocated */ -bool display_plugin_state_is_there_default_action(enum state_t state) -{ - if (g_display_plugin.display_states[state] && g_display_plugin.display_states[state]->action) - return true; - - return false; -} - int display_plugin_state_get_name(enum state_t state, const char **state_name) { if (!state_name) diff --git a/src/display/display-plugin.h b/src/display/display-plugin.h index d66dcac..9b256f4 100644 --- a/src/display/display-plugin.h +++ b/src/display/display-plugin.h @@ -98,8 +98,6 @@ int display_plugin_backlight_transit_brightness(int start, int end, int step); /* FIXME: function names will be redefined */ int display_plugin_state_do_default_trans(enum state_t state, int evt); bool display_plugin_state_is_there_default_trans(enum state_t state); -int display_plugin_state_do_default_action(enum state_t state, int timeout); -bool display_plugin_state_is_there_default_action(enum state_t state); int display_plugin_state_get_name(enum state_t state, const char **state_name); int display_plugin_state_set_timeout(enum state_t state, int state_timeout); int display_plugin_state_get_timeout(enum state_t state, int *state_timeout); diff --git a/src/display/display-state-transition.c b/src/display/display-state-transition.c index c7a5dff..1518b46 100644 --- a/src/display/display-state-transition.c +++ b/src/display/display-state-transition.c @@ -21,14 +21,15 @@ * @brief This file has functions related to display state transition */ +#include "shared/log.h" #include "core/udev.h" #include "device-interface.h" #include "display-state-transition.h" #include "display-lock.h" #include "display-plugin.h" #include "extcon/extcon.h" +#include "power/power.h" #include "power/power-suspend.h" -#include "shared/log.h" #define ALWAYS_ON_TIMEOUT 360000000 @@ -381,7 +382,7 @@ int display_state_transition_do_state_transition(enum state_t state, int evt_typ set_pm_cur_state(next_state); /* enter action */ - if (display_plugin_state_is_there_default_action(get_pm_cur_state())) { + if (display_state_transition_is_display_state_support_transition(get_pm_cur_state())) { if (get_pm_cur_state() == S_LCDOFF) display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); @@ -398,8 +399,145 @@ int display_state_transition_do_state_transition(enum state_t state, int evt_typ return 0; display_plugin_state_get_timeout(get_pm_cur_state(), &timeout); - display_plugin_state_do_default_action(get_pm_cur_state(), timeout); + display_state_transition_do_state_action(timeout); + } + } + return 0; +} + +/* FIXME: diff time calculation, set_wakeup_count should be discussed again later */ +int display_state_transition_do_state_action(int timeout) +{ + int wakeup_count = -1, pm_cur_state; + time_t now; + double diff = 0; + static time_t last_update_time = 0; + static int last_timeout = 0; + bool custom_status; + int brightness; + bool lcd_paneloff_mode = false; + const char* state_name; + enum device_ops_status display_ops_status; + int diff_time = 0; + + if (!display_state_transition_is_display_state_support_transition(get_pm_cur_state())) + return -EPERM; + + display_get_display_ops_status(&display_ops_status); + if (display_ops_status != DEVICE_OPS_STATUS_START) { + _E("Display is not started."); + return -EINVAL; + } + + if (get_pm_cur_state() != S_SLEEP) { + if ((get_pm_cur_state() == S_NORMAL)) { + if (display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(&diff_time) == 0) { + timeout -= diff_time; + } + } + + /* set timer with current state timeout */ + display_state_transition_reset_state_transition_timeout(timeout); + + if (get_pm_cur_state() == S_NORMAL) { + time(&last_update_time); + last_timeout = timeout; + } else { + display_plugin_state_get_name(get_pm_cur_state(), &state_name); + _I("Timout set: %s state %d ms", state_name, timeout); + } + } + + if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { + power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, + power_get_wakeup_reason(), NULL); + set_setting_pmstate(get_pm_cur_state()); + pm_cur_state = get_pm_cur_state(); + device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); + } + + if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { + time(&now); + diff = difftime(now, last_update_time); + display_plugin_state_get_name(get_pm_cur_state(), &state_name); + _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", + state_name, last_timeout, diff); + } + + switch (get_pm_cur_state()) { + case S_NORMAL: + /* + * normal state : backlight on and restore + * the previous brightness + */ + if (get_pm_old_state() == S_LCDDIM) + display_backlight_update_by_default_brightness(); + + if (display_panel_get_dpms_cached_state() != DPMS_ON) + display_panel_lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); + break; + + case S_LCDDIM: + display_backlight_get_custom_status(&custom_status); + if ((get_pm_old_state() == S_NORMAL) && custom_status) { + display_backlight_get_brightness(&brightness); + display_backlight_set_custom_brightness(brightness); + } + /* lcd dim state : dim the brightness */ + display_backlight_set_brightness_by_dim_brightness(); + + if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) + display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE); + break; + + case S_LCDOFF: + if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { + /* lcd off state : turn off the backlight */ + if (display_panel_get_dpms_cached_state() == DPMS_ON) + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } + + display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); + if (display_panel_get_dpms_cached_state() == DPMS_ON + || lcd_paneloff_mode) + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + break; + + case S_SLEEP: + if (display_panel_get_dpms_cached_state() == DPMS_ON) + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + + if (!pm_get_power_lock_support()) { + /* sleep state : set system mode to SUSPEND */ + if (get_wakeup_count(&wakeup_count) < 0) + _E("Wakeup count read error."); + + if (wakeup_count < 0) { + _I("Wakup Event. Can not enter suspend mode."); + goto go_lcd_off; + } + + if (set_wakeup_count(wakeup_count) < 0) { + _E("Wakeup count write error."); + goto go_lcd_off; + } + } + goto go_suspend; + } + + return 0; + +go_suspend: +#ifdef ENABLE_PM_LOG + pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); +#endif + power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); + return 0; + +go_lcd_off: + if (!pm_get_power_lock_support()) { + /* Resume !! */ + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); } return 0; } \ No newline at end of file diff --git a/src/display/display-state-transition.h b/src/display/display-state-transition.h index eeead2f..9182243 100644 --- a/src/display/display-state-transition.h +++ b/src/display/display-state-transition.h @@ -42,5 +42,6 @@ int display_state_transition_update_lcdoff_reason(int source); bool display_state_transition_is_possible_to_go_lcdoff(void); int display_state_transition_do_state_transition(enum state_t state, int evt_type); bool display_state_transition_is_display_state_support_transition(enum state_t state); +int display_state_transition_do_state_action(int timeout); #endif /* __DISPLAY_STATE_TRANSITION_H__ */ \ No newline at end of file diff --git a/src/display/display.c b/src/display/display.c index 0fe45c8..3418711 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -33,6 +33,7 @@ static unsigned int pm_status_flag; static enum display_init_direction_e g_display_init_direction; static bool g_display_hal_backend_available; static GList *display_dependent_device_ops; +static enum device_ops_status display_ops_status = DEVICE_OPS_STATUS_UNINIT; inline int get_pm_cur_state(void) { @@ -192,6 +193,23 @@ int display_initialize_display_state_timeout_from_setting(void) return 0; } +/** FIXME: display_ops_status getter/setter will be removed after plugin-core separation + This work should be proceeded in the display core +*/ +void display_set_display_ops_status(enum device_ops_status dev_ops_status) +{ + display_ops_status = dev_ops_status; +} + +int display_get_display_ops_status(enum device_ops_status *dev_ops_status) +{ + if (!dev_ops_status) + return -EINVAL; + + *dev_ops_status = display_ops_status; + return 0; +} + static int display_probe(void *data) { display_plugin_device_ops = find_device("display-plugin"); diff --git a/src/display/display.h b/src/display/display.h index 42b0096..d54fd31 100644 --- a/src/display/display.h +++ b/src/display/display.h @@ -57,5 +57,7 @@ void display_register_dependent_device(const struct device_ops *ops); void display_unregister_dependent_device(void); bool display_dimstay_check(void); int display_initialize_display_state_timeout_from_setting(void); +void display_set_display_ops_status(enum device_ops_status dev_ops_status); +int display_get_display_ops_status(enum device_ops_status *dev_ops_status); #endif //__DISPLAY_H__