display: Relocate state to display-state-transition.c 76/297076/2
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 10 Aug 2023 02:57:13 +0000 (11:57 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 10 Aug 2023 03:52:12 +0000 (12:52 +0900)
The existing pm_cur_state/pm_old_state has renamed to current/previous.
Getter and setter on that current/previous state has moved accordingly.
However, those getter/setter name hasn't been changed as it will be
replaced with resource-manager soon.

Change-Id: Ib89c018bd1cf011c80bff4ec9922fa970931a1aa
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/display/display-state-transition.c
src/display/display.c

index 9281063..b3f9832 100644 (file)
 
 #define ALWAYS_ON_TIMEOUT              360000000
 
+/* display state */
+static enum deviced_display_state current = DEVICED_DISPLAY_STATE_START;
+static enum deviced_display_state previous = DEVICED_DISPLAY_STATE_START;
+
 static guint state_transition_timer_id;
 static unsigned int custom_normal_timeout = 0;
 static unsigned int custom_dim_timeout = 0;
@@ -58,6 +62,39 @@ static bool is_display_state_valid(enum deviced_display_state display_state)
        return (display_state >= DEVICED_DISPLAY_STATE_START && display_state < DEVICED_DISPLAY_STATE_END);
 }
 
+/**
+ * FIXME: All those getter/setter for current/previous will be changed to resource-manager.
+ *   - get_pm_cur_state()
+ *   - set_pm_cur_state()
+ *   - get_pm_old_state()
+ *   - set_pm_old_state()
+ */
+inline int get_pm_cur_state(void)
+{
+       return current;
+}
+
+inline void set_pm_cur_state(int state)
+{
+       if (!is_display_state_valid(state))
+               return;
+
+       current = state;
+}
+
+inline int get_pm_old_state(void)
+{
+       return previous;
+}
+
+inline void set_pm_old_state(int state)
+{
+       if (!is_display_state_valid(state))
+               return;
+
+       previous = state;
+}
+
 static bool is_device_event_type_valid(int event_type)
 {
        return (event_type >= EVENT_TIMEOUT && event_type < EVENT_END);
@@ -92,12 +129,12 @@ static void remove_state_transition(void)
 static gboolean state_transition_timeout_handler(void *data)
 {
        const char *state_name = NULL;
-       display_plugin_state_get_name(get_pm_cur_state(), &state_name);
+       display_plugin_state_get_name(current, &state_name);
        _I("Time out state %s", state_name);
 
        remove_state_transition();
 
-       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
+       display_state_transition_do_state_transition(current, EVENT_TIMEOUT);
        return G_SOURCE_REMOVE;
 }
 
@@ -112,21 +149,21 @@ int display_state_transition_reset_state_transition_timeout(int timeout)
        if (!display_plugin_config_get_timeout_enable(&timeout_enable) && (!timeout_enable))
                return -EPERM;
 
-       if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF)
+       if ((current == DEVICED_DISPLAY_STATE_OFF)
        && (syscommon_is_emulator() == true || timeout_sleep_support == false))
                return -EPERM;
 
-       _I("Reset timeout(%d ms) pm_cur_state(%d).", timeout, get_pm_cur_state());
+       _I("Reset timeout(%d ms) pm_cur_state(%d).", timeout, current);
        remove_state_transition();
 
-       if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
+       if (trans_table[current][EVENT_TIMEOUT] == current)
                return -EPERM;
 
        if (timeout > 0)
                state_transition_timer_id = g_timeout_add(timeout,
                        state_transition_timeout_handler, NULL);
        else if (timeout == 0)
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
+               display_state_transition_do_state_transition(current, EVENT_TIMEOUT);
 
        return 0;
 }
@@ -304,10 +341,10 @@ bool display_state_transition_is_possible_to_go_lcdoff(void)
        int hdmi_state;
        int dimming;
 
-       if (get_pm_old_state() != DEVICED_DISPLAY_STATE_ON)
+       if (previous != DEVICED_DISPLAY_STATE_ON)
                return false;
 
-       if (get_pm_cur_state() != DEVICED_DISPLAY_STATE_DIM)
+       if (current != DEVICED_DISPLAY_STATE_DIM)
                return false;
 
        display_plugin_config_get_dimming(&dimming);
@@ -354,12 +391,12 @@ int display_state_transition_do_state_transition(enum deviced_display_state stat
        if (display_plugin_state_is_there_default_trans(state))
                return display_plugin_state_do_default_trans(state, evt_type);
 
-       display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt_type);
+       display_state_transition_get_next_transition_display_state(current, &next_state, evt_type);
 
        /* check conditions */
-       ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state);
+       ret = display_state_transition_check_state_transition_condition(current, next_state);
        if (ret < 0) {
-               display_plugin_state_get_name(get_pm_cur_state(), &current_state_name);
+               display_plugin_state_get_name(current, &current_state_name);
                display_plugin_state_get_name(next_state, &next_state_name);
                /* There is a condition. */
                _I("%s locked. Trans to %s failed.", current_state_name, next_state_name);
@@ -367,27 +404,27 @@ int display_state_transition_do_state_transition(enum deviced_display_state stat
        }
 
        /* state transition */
-       set_pm_old_state(get_pm_cur_state());
-       set_pm_cur_state(next_state);
+       previous = current;
+       current = next_state;
 
        /* enter action */
-       if (display_state_transition_is_display_state_support_transition(get_pm_cur_state())) {
-               if (get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF)
+       if (display_state_transition_is_display_state_support_transition(current)) {
+               if (current == DEVICED_DISPLAY_STATE_OFF)
                        display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT);
 
-               if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_ON) || (get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF))
+               if ((current == DEVICED_DISPLAY_STATE_ON) || (current == DEVICED_DISPLAY_STATE_OFF))
                        if (set_custom_lcdon_timeout(0) == true)
                                display_state_transition_update_display_state_timeout_by_priority();
 
                if (display_state_transition_is_possible_to_go_lcdoff()) {
                        /* enter next state directly */
-                       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
+                       display_state_transition_do_state_transition(current, EVENT_TIMEOUT);
                } else {
-                       if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_SLEEP) &&
+                       if ((current == DEVICED_DISPLAY_STATE_SLEEP) &&
                        (syscommon_is_emulator() == true || timeout_sleep_support == false))
                                return 0;
 
-                       display_plugin_state_get_timeout(get_pm_cur_state(), &timeout);
+                       display_plugin_state_get_timeout(current, &timeout);
                        display_state_transition_do_state_action(timeout);
                }
        }
@@ -404,12 +441,12 @@ int display_state_transition_do_state_transition_by_input_poll_event(void)
                return -ECANCELED;
        }
 
-       if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF) || (get_pm_cur_state() == DEVICED_DISPLAY_STATE_SLEEP))
+       if ((current == DEVICED_DISPLAY_STATE_OFF) || (current == DEVICED_DISPLAY_STATE_SLEEP))
                _I("Input event signal at Display Off");
 
        time(&now);
-       if ((last_time != now) || (get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF) || (get_pm_cur_state() == DEVICED_DISPLAY_STATE_SLEEP)) {
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
+       if ((last_time != now) || (current == DEVICED_DISPLAY_STATE_OFF) || (current == DEVICED_DISPLAY_STATE_SLEEP)) {
+               display_state_transition_do_state_transition(current, EVENT_INPUT);
                last_time = now;
        }
 
@@ -445,7 +482,7 @@ int display_state_transition_do_state_action(int timeout)
        enum device_ops_status display_ops_status;
        int diff_time = 0;
 
-       if (!display_state_transition_is_display_state_support_transition(get_pm_cur_state()))
+       if (!display_state_transition_is_display_state_support_transition(current))
                return -EPERM;
 
        display_get_display_ops_status(&display_ops_status);
@@ -454,8 +491,8 @@ int display_state_transition_do_state_action(int timeout)
                return -EINVAL;
        }
 
-       if (get_pm_cur_state() != DEVICED_DISPLAY_STATE_SLEEP) {
-               if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_ON)) {
+       if (current != DEVICED_DISPLAY_STATE_SLEEP) {
+               if ((current == DEVICED_DISPLAY_STATE_ON)) {
                        if (display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(&diff_time) == 0) {
                                timeout -= diff_time;
                        }
@@ -464,16 +501,16 @@ int display_state_transition_do_state_action(int timeout)
                /* set timer with current state timeout */
                display_state_transition_reset_state_transition_timeout(timeout);
 
-               if (get_pm_cur_state() == DEVICED_DISPLAY_STATE_ON) {
+               if (current == DEVICED_DISPLAY_STATE_ON) {
                        time(&last_update_time);
                        last_timeout = timeout;
                } else {
-                       display_plugin_state_get_name(get_pm_cur_state(), &state_name);
+                       display_plugin_state_get_name(current, &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() != DEVICED_DISPLAY_STATE_SLEEP)) {
+       if ((current != previous) && (current != DEVICED_DISPLAY_STATE_SLEEP)) {
                int wakeup_reason = 0;
 
                syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
@@ -482,26 +519,26 @@ int display_state_transition_do_state_action(int timeout)
                        DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
                        DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, wakeup_reason, 0);
 
-               set_setting_pmstate(get_pm_cur_state());
-               pm_cur_state = get_pm_cur_state();
+               set_setting_pmstate(current);
+               pm_cur_state = current;
                syscommon_notifier_emit_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state);
        }
 
-       if ((get_pm_old_state() == DEVICED_DISPLAY_STATE_ON) && (get_pm_cur_state() != DEVICED_DISPLAY_STATE_ON)) {
+       if ((previous == DEVICED_DISPLAY_STATE_ON) && (current != DEVICED_DISPLAY_STATE_ON)) {
                time(&now);
                diff = difftime(now, last_update_time);
-               display_plugin_state_get_name(get_pm_cur_state(), &state_name);
+               display_plugin_state_get_name(current, &state_name);
                _I("DEVICED_DISPLAY_STATE_ON is changed to %s (timeout=%d ms diff=%.0f s).",
                        state_name, last_timeout, diff);
        }
 
-       switch (get_pm_cur_state()) {
+       switch (current) {
        case DEVICED_DISPLAY_STATE_ON:
                /*
                 * normal state : backlight on and restore
                 * the previous brightness
                 */
-               if (get_pm_old_state() == DEVICED_DISPLAY_STATE_DIM)
+               if (previous == DEVICED_DISPLAY_STATE_DIM)
                        display_backlight_update_by_default_brightness();
 
                if (display_panel_get_dpms_cached_state() != DPMS_ON)
@@ -510,19 +547,19 @@ int display_state_transition_do_state_action(int timeout)
 
        case DEVICED_DISPLAY_STATE_DIM:
                display_backlight_get_custom_status(&custom_status);
-               if ((get_pm_old_state() == DEVICED_DISPLAY_STATE_ON) && custom_status) {
+               if ((previous == DEVICED_DISPLAY_STATE_ON) && 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() == DEVICED_DISPLAY_STATE_OFF) || (get_pm_old_state() == DEVICED_DISPLAY_STATE_SLEEP))
+               if ((previous == DEVICED_DISPLAY_STATE_OFF) || (previous == DEVICED_DISPLAY_STATE_SLEEP))
                        display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE);
                break;
 
        case DEVICED_DISPLAY_STATE_OFF:
-               if ((get_pm_old_state() != DEVICED_DISPLAY_STATE_SLEEP) && (get_pm_old_state() != DEVICED_DISPLAY_STATE_OFF)) {
+               if ((previous != DEVICED_DISPLAY_STATE_SLEEP) && (previous != DEVICED_DISPLAY_STATE_OFF)) {
                        /* 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);
@@ -554,13 +591,15 @@ int display_state_transition_do_state_action(int timeout)
                        }
                }
                goto go_suspend;
+       default: /* DEVICED_DISPLAY_STATE_START */
+               return 0;
        }
 
        return 0;
 
 go_suspend:
 #ifdef ENABLE_PM_LOG
-       pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
+       pm_history_save(PM_LOG_SLEEP, current);
 #endif
        syscommon_resman_set_resource_attr_uint64_4(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
                DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
@@ -572,7 +611,7 @@ go_suspend:
 go_lcd_off:
        if (!pm_get_power_lock_support()) {
                /* Resume !! */
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE);
+               display_state_transition_do_state_transition(current, EVENT_DEVICE);
        }
        return 0;
 }
@@ -582,10 +621,10 @@ void display_state_transition_do_proc_change_state_action(enum deviced_display_s
 {
        int state_timeout = 0;
 
-       set_pm_old_state(get_pm_cur_state());
-       set_pm_cur_state(next);
+       previous = current;
+       current = next;
 
-       display_plugin_state_get_timeout(get_pm_cur_state(), &state_timeout);
+       display_plugin_state_get_timeout(current, &state_timeout);
 
        if (timeout < 0)
                display_state_transition_do_state_action(state_timeout);
index 9732016..d445138 100644 (file)
@@ -43,8 +43,6 @@
 #define DELAYED_INIT_WATING_TIME       60000   /* 1 minute */
 
 static const struct device_ops *display_plugin_device_ops;
-static int pm_cur_state;
-static int pm_old_state;
 static unsigned int pm_status_flag;
 static enum display_init_direction_e g_display_init_direction;
 static bool g_display_hal_backend_available = false;
@@ -53,26 +51,6 @@ static enum device_ops_status display_ops_status = DEVICE_OPS_STATUS_UNINIT;
 
 extern void init_save_userlock(void);
 
-inline int get_pm_cur_state(void)
-{
-       return pm_cur_state;
-}
-
-inline void set_pm_cur_state(int cur_state)
-{
-       pm_cur_state = cur_state;
-}
-
-inline int get_pm_old_state(void)
-{
-       return pm_old_state;
-}
-
-inline void set_pm_old_state(int old_state)
-{
-       pm_old_state = old_state;
-}
-
 inline unsigned int get_pm_status_flag(void)
 {
        return pm_status_flag;